]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/config/tc-arm.c
* gas/arm/neon-vmov-bad.d: New file.
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994-2013 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
141 /* Variables that we set while parsing command-line options. Once all
142 options have been read we re-process these values to set the real
143 assembly flags. */
144 static const arm_feature_set *legacy_cpu = NULL;
145 static const arm_feature_set *legacy_fpu = NULL;
146
147 static const arm_feature_set *mcpu_cpu_opt = NULL;
148 static const arm_feature_set *mcpu_fpu_opt = NULL;
149 static const arm_feature_set *march_cpu_opt = NULL;
150 static const arm_feature_set *march_fpu_opt = NULL;
151 static const arm_feature_set *mfpu_opt = NULL;
152 static const arm_feature_set *object_arch = NULL;
153
154 /* Constants for known architecture features. */
155 static const arm_feature_set fpu_default = FPU_DEFAULT;
156 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
157 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
158 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
159 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
160 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
161 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
162 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
163 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
164
165 #ifdef CPU_DEFAULT
166 static const arm_feature_set cpu_default = CPU_DEFAULT;
167 #endif
168
169 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
170 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
171 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
172 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
173 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
174 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
175 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
176 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
177 static const arm_feature_set arm_ext_v4t_5 =
178 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
179 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
180 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
181 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
182 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
183 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
184 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
185 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
186 static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
187 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
188 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
189 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
190 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
191 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
192 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
193 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
194 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
195 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
196 static const arm_feature_set arm_ext_v8 = ARM_FEATURE (ARM_EXT_V8, 0);
197 static const arm_feature_set arm_ext_m =
198 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
199 static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
200 static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
201 static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
202 static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
203 static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
204
205 static const arm_feature_set arm_arch_any = ARM_ANY;
206 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
209 static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
210
211 static const arm_feature_set arm_cext_iwmmxt2 =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
213 static const arm_feature_set arm_cext_iwmmxt =
214 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
215 static const arm_feature_set arm_cext_xscale =
216 ARM_FEATURE (0, ARM_CEXT_XSCALE);
217 static const arm_feature_set arm_cext_maverick =
218 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
219 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
220 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
221 static const arm_feature_set fpu_vfp_ext_v1xd =
222 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
223 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
224 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
225 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
226 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
227 static const arm_feature_set fpu_vfp_ext_d32 =
228 ARM_FEATURE (0, FPU_VFP_EXT_D32);
229 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
230 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
231 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
232 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
233 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
234 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
235 static const arm_feature_set fpu_vfp_ext_armv8 =
236 ARM_FEATURE (0, FPU_VFP_EXT_ARMV8);
237 static const arm_feature_set fpu_neon_ext_armv8 =
238 ARM_FEATURE (0, FPU_NEON_EXT_ARMV8);
239 static const arm_feature_set fpu_crypto_ext_armv8 =
240 ARM_FEATURE (0, FPU_CRYPTO_EXT_ARMV8);
241
242 static int mfloat_abi_opt = -1;
243 /* Record user cpu selection for object attributes. */
244 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
245 /* Must be long enough to hold any of the names in arm_cpus. */
246 static char selected_cpu_name[16];
247
248 /* Return if no cpu was selected on command-line. */
249 static bfd_boolean
250 no_cpu_selected (void)
251 {
252 return selected_cpu.core == arm_arch_none.core
253 && selected_cpu.coproc == arm_arch_none.coproc;
254 }
255
256 #ifdef OBJ_ELF
257 # ifdef EABI_DEFAULT
258 static int meabi_flags = EABI_DEFAULT;
259 # else
260 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
261 # endif
262
263 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
264
265 bfd_boolean
266 arm_is_eabi (void)
267 {
268 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
269 }
270 #endif
271
272 #ifdef OBJ_ELF
273 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
274 symbolS * GOT_symbol;
275 #endif
276
277 /* 0: assemble for ARM,
278 1: assemble for Thumb,
279 2: assemble for Thumb even though target CPU does not support thumb
280 instructions. */
281 static int thumb_mode = 0;
282 /* A value distinct from the possible values for thumb_mode that we
283 can use to record whether thumb_mode has been copied into the
284 tc_frag_data field of a frag. */
285 #define MODE_RECORDED (1 << 4)
286
287 /* Specifies the intrinsic IT insn behavior mode. */
288 enum implicit_it_mode
289 {
290 IMPLICIT_IT_MODE_NEVER = 0x00,
291 IMPLICIT_IT_MODE_ARM = 0x01,
292 IMPLICIT_IT_MODE_THUMB = 0x02,
293 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
294 };
295 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
296
297 /* If unified_syntax is true, we are processing the new unified
298 ARM/Thumb syntax. Important differences from the old ARM mode:
299
300 - Immediate operands do not require a # prefix.
301 - Conditional affixes always appear at the end of the
302 instruction. (For backward compatibility, those instructions
303 that formerly had them in the middle, continue to accept them
304 there.)
305 - The IT instruction may appear, and if it does is validated
306 against subsequent conditional affixes. It does not generate
307 machine code.
308
309 Important differences from the old Thumb mode:
310
311 - Immediate operands do not require a # prefix.
312 - Most of the V6T2 instructions are only available in unified mode.
313 - The .N and .W suffixes are recognized and honored (it is an error
314 if they cannot be honored).
315 - All instructions set the flags if and only if they have an 's' affix.
316 - Conditional affixes may be used. They are validated against
317 preceding IT instructions. Unlike ARM mode, you cannot use a
318 conditional affix except in the scope of an IT instruction. */
319
320 static bfd_boolean unified_syntax = FALSE;
321
322 /* An immediate operand can start with #, and ld*, st*, pld operands
323 can contain [ and ]. We need to tell APP not to elide whitespace
324 before a [, which can appear as the first operand for pld. */
325 const char arm_symbol_chars[] = "#[]";
326
327 enum neon_el_type
328 {
329 NT_invtype,
330 NT_untyped,
331 NT_integer,
332 NT_float,
333 NT_poly,
334 NT_signed,
335 NT_unsigned
336 };
337
338 struct neon_type_el
339 {
340 enum neon_el_type type;
341 unsigned size;
342 };
343
344 #define NEON_MAX_TYPE_ELS 4
345
346 struct neon_type
347 {
348 struct neon_type_el el[NEON_MAX_TYPE_ELS];
349 unsigned elems;
350 };
351
352 enum it_instruction_type
353 {
354 OUTSIDE_IT_INSN,
355 INSIDE_IT_INSN,
356 INSIDE_IT_LAST_INSN,
357 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
358 if inside, should be the last one. */
359 NEUTRAL_IT_INSN, /* This could be either inside or outside,
360 i.e. BKPT and NOP. */
361 IT_INSN /* The IT insn has been parsed. */
362 };
363
364 /* The maximum number of operands we need. */
365 #define ARM_IT_MAX_OPERANDS 6
366
367 struct arm_it
368 {
369 const char * error;
370 unsigned long instruction;
371 int size;
372 int size_req;
373 int cond;
374 /* "uncond_value" is set to the value in place of the conditional field in
375 unconditional versions of the instruction, or -1 if nothing is
376 appropriate. */
377 int uncond_value;
378 struct neon_type vectype;
379 /* This does not indicate an actual NEON instruction, only that
380 the mnemonic accepts neon-style type suffixes. */
381 int is_neon;
382 /* Set to the opcode if the instruction needs relaxation.
383 Zero if the instruction is not relaxed. */
384 unsigned long relax;
385 struct
386 {
387 bfd_reloc_code_real_type type;
388 expressionS exp;
389 int pc_rel;
390 } reloc;
391
392 enum it_instruction_type it_insn_type;
393
394 struct
395 {
396 unsigned reg;
397 signed int imm;
398 struct neon_type_el vectype;
399 unsigned present : 1; /* Operand present. */
400 unsigned isreg : 1; /* Operand was a register. */
401 unsigned immisreg : 1; /* .imm field is a second register. */
402 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
403 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
404 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
405 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
406 instructions. This allows us to disambiguate ARM <-> vector insns. */
407 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
408 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
409 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
410 unsigned issingle : 1; /* Operand is VFP single-precision register. */
411 unsigned hasreloc : 1; /* Operand has relocation suffix. */
412 unsigned writeback : 1; /* Operand has trailing ! */
413 unsigned preind : 1; /* Preindexed address. */
414 unsigned postind : 1; /* Postindexed address. */
415 unsigned negative : 1; /* Index register was negated. */
416 unsigned shifted : 1; /* Shift applied to operation. */
417 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
418 } operands[ARM_IT_MAX_OPERANDS];
419 };
420
421 static struct arm_it inst;
422
423 #define NUM_FLOAT_VALS 8
424
425 const char * fp_const[] =
426 {
427 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
428 };
429
430 /* Number of littlenums required to hold an extended precision number. */
431 #define MAX_LITTLENUMS 6
432
433 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
434
435 #define FAIL (-1)
436 #define SUCCESS (0)
437
438 #define SUFF_S 1
439 #define SUFF_D 2
440 #define SUFF_E 3
441 #define SUFF_P 4
442
443 #define CP_T_X 0x00008000
444 #define CP_T_Y 0x00400000
445
446 #define CONDS_BIT 0x00100000
447 #define LOAD_BIT 0x00100000
448
449 #define DOUBLE_LOAD_FLAG 0x00000001
450
451 struct asm_cond
452 {
453 const char * template_name;
454 unsigned long value;
455 };
456
457 #define COND_ALWAYS 0xE
458
459 struct asm_psr
460 {
461 const char * template_name;
462 unsigned long field;
463 };
464
465 struct asm_barrier_opt
466 {
467 const char * template_name;
468 unsigned long value;
469 const arm_feature_set arch;
470 };
471
472 /* The bit that distinguishes CPSR and SPSR. */
473 #define SPSR_BIT (1 << 22)
474
475 /* The individual PSR flag bits. */
476 #define PSR_c (1 << 16)
477 #define PSR_x (1 << 17)
478 #define PSR_s (1 << 18)
479 #define PSR_f (1 << 19)
480
481 struct reloc_entry
482 {
483 char * name;
484 bfd_reloc_code_real_type reloc;
485 };
486
487 enum vfp_reg_pos
488 {
489 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
490 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
491 };
492
493 enum vfp_ldstm_type
494 {
495 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
496 };
497
498 /* Bits for DEFINED field in neon_typed_alias. */
499 #define NTA_HASTYPE 1
500 #define NTA_HASINDEX 2
501
502 struct neon_typed_alias
503 {
504 unsigned char defined;
505 unsigned char index;
506 struct neon_type_el eltype;
507 };
508
509 /* ARM register categories. This includes coprocessor numbers and various
510 architecture extensions' registers. */
511 enum arm_reg_type
512 {
513 REG_TYPE_RN,
514 REG_TYPE_CP,
515 REG_TYPE_CN,
516 REG_TYPE_FN,
517 REG_TYPE_VFS,
518 REG_TYPE_VFD,
519 REG_TYPE_NQ,
520 REG_TYPE_VFSD,
521 REG_TYPE_NDQ,
522 REG_TYPE_NSDQ,
523 REG_TYPE_VFC,
524 REG_TYPE_MVF,
525 REG_TYPE_MVD,
526 REG_TYPE_MVFX,
527 REG_TYPE_MVDX,
528 REG_TYPE_MVAX,
529 REG_TYPE_DSPSC,
530 REG_TYPE_MMXWR,
531 REG_TYPE_MMXWC,
532 REG_TYPE_MMXWCG,
533 REG_TYPE_XSCALE,
534 REG_TYPE_RNB
535 };
536
537 /* Structure for a hash table entry for a register.
538 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
539 information which states whether a vector type or index is specified (for a
540 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
541 struct reg_entry
542 {
543 const char * name;
544 unsigned int number;
545 unsigned char type;
546 unsigned char builtin;
547 struct neon_typed_alias * neon;
548 };
549
550 /* Diagnostics used when we don't get a register of the expected type. */
551 const char * const reg_expected_msgs[] =
552 {
553 N_("ARM register expected"),
554 N_("bad or missing co-processor number"),
555 N_("co-processor register expected"),
556 N_("FPA register expected"),
557 N_("VFP single precision register expected"),
558 N_("VFP/Neon double precision register expected"),
559 N_("Neon quad precision register expected"),
560 N_("VFP single or double precision register expected"),
561 N_("Neon double or quad precision register expected"),
562 N_("VFP single, double or Neon quad precision register expected"),
563 N_("VFP system register expected"),
564 N_("Maverick MVF register expected"),
565 N_("Maverick MVD register expected"),
566 N_("Maverick MVFX register expected"),
567 N_("Maverick MVDX register expected"),
568 N_("Maverick MVAX register expected"),
569 N_("Maverick DSPSC register expected"),
570 N_("iWMMXt data register expected"),
571 N_("iWMMXt control register expected"),
572 N_("iWMMXt scalar register expected"),
573 N_("XScale accumulator register expected"),
574 };
575
576 /* Some well known registers that we refer to directly elsewhere. */
577 #define REG_R12 12
578 #define REG_SP 13
579 #define REG_LR 14
580 #define REG_PC 15
581
582 /* ARM instructions take 4bytes in the object file, Thumb instructions
583 take 2: */
584 #define INSN_SIZE 4
585
586 struct asm_opcode
587 {
588 /* Basic string to match. */
589 const char * template_name;
590
591 /* Parameters to instruction. */
592 unsigned int operands[8];
593
594 /* Conditional tag - see opcode_lookup. */
595 unsigned int tag : 4;
596
597 /* Basic instruction code. */
598 unsigned int avalue : 28;
599
600 /* Thumb-format instruction code. */
601 unsigned int tvalue;
602
603 /* Which architecture variant provides this instruction. */
604 const arm_feature_set * avariant;
605 const arm_feature_set * tvariant;
606
607 /* Function to call to encode instruction in ARM format. */
608 void (* aencode) (void);
609
610 /* Function to call to encode instruction in Thumb format. */
611 void (* tencode) (void);
612 };
613
614 /* Defines for various bits that we will want to toggle. */
615 #define INST_IMMEDIATE 0x02000000
616 #define OFFSET_REG 0x02000000
617 #define HWOFFSET_IMM 0x00400000
618 #define SHIFT_BY_REG 0x00000010
619 #define PRE_INDEX 0x01000000
620 #define INDEX_UP 0x00800000
621 #define WRITE_BACK 0x00200000
622 #define LDM_TYPE_2_OR_3 0x00400000
623 #define CPSI_MMOD 0x00020000
624
625 #define LITERAL_MASK 0xf000f000
626 #define OPCODE_MASK 0xfe1fffff
627 #define V4_STR_BIT 0x00000020
628
629 #define T2_SUBS_PC_LR 0xf3de8f00
630
631 #define DATA_OP_SHIFT 21
632
633 #define T2_OPCODE_MASK 0xfe1fffff
634 #define T2_DATA_OP_SHIFT 21
635
636 #define A_COND_MASK 0xf0000000
637 #define A_PUSH_POP_OP_MASK 0x0fff0000
638
639 /* Opcodes for pushing/poping registers to/from the stack. */
640 #define A1_OPCODE_PUSH 0x092d0000
641 #define A2_OPCODE_PUSH 0x052d0004
642 #define A2_OPCODE_POP 0x049d0004
643
644 /* Codes to distinguish the arithmetic instructions. */
645 #define OPCODE_AND 0
646 #define OPCODE_EOR 1
647 #define OPCODE_SUB 2
648 #define OPCODE_RSB 3
649 #define OPCODE_ADD 4
650 #define OPCODE_ADC 5
651 #define OPCODE_SBC 6
652 #define OPCODE_RSC 7
653 #define OPCODE_TST 8
654 #define OPCODE_TEQ 9
655 #define OPCODE_CMP 10
656 #define OPCODE_CMN 11
657 #define OPCODE_ORR 12
658 #define OPCODE_MOV 13
659 #define OPCODE_BIC 14
660 #define OPCODE_MVN 15
661
662 #define T2_OPCODE_AND 0
663 #define T2_OPCODE_BIC 1
664 #define T2_OPCODE_ORR 2
665 #define T2_OPCODE_ORN 3
666 #define T2_OPCODE_EOR 4
667 #define T2_OPCODE_ADD 8
668 #define T2_OPCODE_ADC 10
669 #define T2_OPCODE_SBC 11
670 #define T2_OPCODE_SUB 13
671 #define T2_OPCODE_RSB 14
672
673 #define T_OPCODE_MUL 0x4340
674 #define T_OPCODE_TST 0x4200
675 #define T_OPCODE_CMN 0x42c0
676 #define T_OPCODE_NEG 0x4240
677 #define T_OPCODE_MVN 0x43c0
678
679 #define T_OPCODE_ADD_R3 0x1800
680 #define T_OPCODE_SUB_R3 0x1a00
681 #define T_OPCODE_ADD_HI 0x4400
682 #define T_OPCODE_ADD_ST 0xb000
683 #define T_OPCODE_SUB_ST 0xb080
684 #define T_OPCODE_ADD_SP 0xa800
685 #define T_OPCODE_ADD_PC 0xa000
686 #define T_OPCODE_ADD_I8 0x3000
687 #define T_OPCODE_SUB_I8 0x3800
688 #define T_OPCODE_ADD_I3 0x1c00
689 #define T_OPCODE_SUB_I3 0x1e00
690
691 #define T_OPCODE_ASR_R 0x4100
692 #define T_OPCODE_LSL_R 0x4080
693 #define T_OPCODE_LSR_R 0x40c0
694 #define T_OPCODE_ROR_R 0x41c0
695 #define T_OPCODE_ASR_I 0x1000
696 #define T_OPCODE_LSL_I 0x0000
697 #define T_OPCODE_LSR_I 0x0800
698
699 #define T_OPCODE_MOV_I8 0x2000
700 #define T_OPCODE_CMP_I8 0x2800
701 #define T_OPCODE_CMP_LR 0x4280
702 #define T_OPCODE_MOV_HR 0x4600
703 #define T_OPCODE_CMP_HR 0x4500
704
705 #define T_OPCODE_LDR_PC 0x4800
706 #define T_OPCODE_LDR_SP 0x9800
707 #define T_OPCODE_STR_SP 0x9000
708 #define T_OPCODE_LDR_IW 0x6800
709 #define T_OPCODE_STR_IW 0x6000
710 #define T_OPCODE_LDR_IH 0x8800
711 #define T_OPCODE_STR_IH 0x8000
712 #define T_OPCODE_LDR_IB 0x7800
713 #define T_OPCODE_STR_IB 0x7000
714 #define T_OPCODE_LDR_RW 0x5800
715 #define T_OPCODE_STR_RW 0x5000
716 #define T_OPCODE_LDR_RH 0x5a00
717 #define T_OPCODE_STR_RH 0x5200
718 #define T_OPCODE_LDR_RB 0x5c00
719 #define T_OPCODE_STR_RB 0x5400
720
721 #define T_OPCODE_PUSH 0xb400
722 #define T_OPCODE_POP 0xbc00
723
724 #define T_OPCODE_BRANCH 0xe000
725
726 #define THUMB_SIZE 2 /* Size of thumb instruction. */
727 #define THUMB_PP_PC_LR 0x0100
728 #define THUMB_LOAD_BIT 0x0800
729 #define THUMB2_LOAD_BIT 0x00100000
730
731 #define BAD_ARGS _("bad arguments to instruction")
732 #define BAD_SP _("r13 not allowed here")
733 #define BAD_PC _("r15 not allowed here")
734 #define BAD_COND _("instruction cannot be conditional")
735 #define BAD_OVERLAP _("registers may not be the same")
736 #define BAD_HIREG _("lo register required")
737 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
738 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
739 #define BAD_BRANCH _("branch must be last instruction in IT block")
740 #define BAD_NOT_IT _("instruction not allowed in IT block")
741 #define BAD_FPU _("selected FPU does not support instruction")
742 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
743 #define BAD_IT_COND _("incorrect condition in IT block")
744 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
745 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
746 #define BAD_PC_ADDRESSING \
747 _("cannot use register index with PC-relative addressing")
748 #define BAD_PC_WRITEBACK \
749 _("cannot use writeback with PC-relative addressing")
750 #define BAD_RANGE _("branch out of range")
751
752 static struct hash_control * arm_ops_hsh;
753 static struct hash_control * arm_cond_hsh;
754 static struct hash_control * arm_shift_hsh;
755 static struct hash_control * arm_psr_hsh;
756 static struct hash_control * arm_v7m_psr_hsh;
757 static struct hash_control * arm_reg_hsh;
758 static struct hash_control * arm_reloc_hsh;
759 static struct hash_control * arm_barrier_opt_hsh;
760
761 /* Stuff needed to resolve the label ambiguity
762 As:
763 ...
764 label: <insn>
765 may differ from:
766 ...
767 label:
768 <insn> */
769
770 symbolS * last_label_seen;
771 static int label_is_thumb_function_name = FALSE;
772
773 /* Literal pool structure. Held on a per-section
774 and per-sub-section basis. */
775
776 #define MAX_LITERAL_POOL_SIZE 1024
777 typedef struct literal_pool
778 {
779 expressionS literals [MAX_LITERAL_POOL_SIZE];
780 unsigned int next_free_entry;
781 unsigned int id;
782 symbolS * symbol;
783 segT section;
784 subsegT sub_section;
785 #ifdef OBJ_ELF
786 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
787 #endif
788 struct literal_pool * next;
789 } literal_pool;
790
791 /* Pointer to a linked list of literal pools. */
792 literal_pool * list_of_pools = NULL;
793
794 #ifdef OBJ_ELF
795 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
796 #else
797 static struct current_it now_it;
798 #endif
799
800 static inline int
801 now_it_compatible (int cond)
802 {
803 return (cond & ~1) == (now_it.cc & ~1);
804 }
805
806 static inline int
807 conditional_insn (void)
808 {
809 return inst.cond != COND_ALWAYS;
810 }
811
812 static int in_it_block (void);
813
814 static int handle_it_state (void);
815
816 static void force_automatic_it_block_close (void);
817
818 static void it_fsm_post_encode (void);
819
820 #define set_it_insn_type(type) \
821 do \
822 { \
823 inst.it_insn_type = type; \
824 if (handle_it_state () == FAIL) \
825 return; \
826 } \
827 while (0)
828
829 #define set_it_insn_type_nonvoid(type, failret) \
830 do \
831 { \
832 inst.it_insn_type = type; \
833 if (handle_it_state () == FAIL) \
834 return failret; \
835 } \
836 while(0)
837
838 #define set_it_insn_type_last() \
839 do \
840 { \
841 if (inst.cond == COND_ALWAYS) \
842 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
843 else \
844 set_it_insn_type (INSIDE_IT_LAST_INSN); \
845 } \
846 while (0)
847
848 /* Pure syntax. */
849
850 /* This array holds the chars that always start a comment. If the
851 pre-processor is disabled, these aren't very useful. */
852 const char comment_chars[] = "@";
853
854 /* This array holds the chars that only start a comment at the beginning of
855 a line. If the line seems to have the form '# 123 filename'
856 .line and .file directives will appear in the pre-processed output. */
857 /* Note that input_file.c hand checks for '#' at the beginning of the
858 first line of the input file. This is because the compiler outputs
859 #NO_APP at the beginning of its output. */
860 /* Also note that comments like this one will always work. */
861 const char line_comment_chars[] = "#";
862
863 const char line_separator_chars[] = ";";
864
865 /* Chars that can be used to separate mant
866 from exp in floating point numbers. */
867 const char EXP_CHARS[] = "eE";
868
869 /* Chars that mean this number is a floating point constant. */
870 /* As in 0f12.456 */
871 /* or 0d1.2345e12 */
872
873 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
874
875 /* Prefix characters that indicate the start of an immediate
876 value. */
877 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
878
879 /* Separator character handling. */
880
881 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
882
883 static inline int
884 skip_past_char (char ** str, char c)
885 {
886 /* PR gas/14987: Allow for whitespace before the expected character. */
887 skip_whitespace (*str);
888
889 if (**str == c)
890 {
891 (*str)++;
892 return SUCCESS;
893 }
894 else
895 return FAIL;
896 }
897
898 #define skip_past_comma(str) skip_past_char (str, ',')
899
900 /* Arithmetic expressions (possibly involving symbols). */
901
902 /* Return TRUE if anything in the expression is a bignum. */
903
904 static int
905 walk_no_bignums (symbolS * sp)
906 {
907 if (symbol_get_value_expression (sp)->X_op == O_big)
908 return 1;
909
910 if (symbol_get_value_expression (sp)->X_add_symbol)
911 {
912 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
913 || (symbol_get_value_expression (sp)->X_op_symbol
914 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
915 }
916
917 return 0;
918 }
919
920 static int in_my_get_expression = 0;
921
922 /* Third argument to my_get_expression. */
923 #define GE_NO_PREFIX 0
924 #define GE_IMM_PREFIX 1
925 #define GE_OPT_PREFIX 2
926 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
927 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
928 #define GE_OPT_PREFIX_BIG 3
929
930 static int
931 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
932 {
933 char * save_in;
934 segT seg;
935
936 /* In unified syntax, all prefixes are optional. */
937 if (unified_syntax)
938 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
939 : GE_OPT_PREFIX;
940
941 switch (prefix_mode)
942 {
943 case GE_NO_PREFIX: break;
944 case GE_IMM_PREFIX:
945 if (!is_immediate_prefix (**str))
946 {
947 inst.error = _("immediate expression requires a # prefix");
948 return FAIL;
949 }
950 (*str)++;
951 break;
952 case GE_OPT_PREFIX:
953 case GE_OPT_PREFIX_BIG:
954 if (is_immediate_prefix (**str))
955 (*str)++;
956 break;
957 default: abort ();
958 }
959
960 memset (ep, 0, sizeof (expressionS));
961
962 save_in = input_line_pointer;
963 input_line_pointer = *str;
964 in_my_get_expression = 1;
965 seg = expression (ep);
966 in_my_get_expression = 0;
967
968 if (ep->X_op == O_illegal || ep->X_op == O_absent)
969 {
970 /* We found a bad or missing expression in md_operand(). */
971 *str = input_line_pointer;
972 input_line_pointer = save_in;
973 if (inst.error == NULL)
974 inst.error = (ep->X_op == O_absent
975 ? _("missing expression") :_("bad expression"));
976 return 1;
977 }
978
979 #ifdef OBJ_AOUT
980 if (seg != absolute_section
981 && seg != text_section
982 && seg != data_section
983 && seg != bss_section
984 && seg != undefined_section)
985 {
986 inst.error = _("bad segment");
987 *str = input_line_pointer;
988 input_line_pointer = save_in;
989 return 1;
990 }
991 #else
992 (void) seg;
993 #endif
994
995 /* Get rid of any bignums now, so that we don't generate an error for which
996 we can't establish a line number later on. Big numbers are never valid
997 in instructions, which is where this routine is always called. */
998 if (prefix_mode != GE_OPT_PREFIX_BIG
999 && (ep->X_op == O_big
1000 || (ep->X_add_symbol
1001 && (walk_no_bignums (ep->X_add_symbol)
1002 || (ep->X_op_symbol
1003 && walk_no_bignums (ep->X_op_symbol))))))
1004 {
1005 inst.error = _("invalid constant");
1006 *str = input_line_pointer;
1007 input_line_pointer = save_in;
1008 return 1;
1009 }
1010
1011 *str = input_line_pointer;
1012 input_line_pointer = save_in;
1013 return 0;
1014 }
1015
1016 /* Turn a string in input_line_pointer into a floating point constant
1017 of type TYPE, and store the appropriate bytes in *LITP. The number
1018 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1019 returned, or NULL on OK.
1020
1021 Note that fp constants aren't represent in the normal way on the ARM.
1022 In big endian mode, things are as expected. However, in little endian
1023 mode fp constants are big-endian word-wise, and little-endian byte-wise
1024 within the words. For example, (double) 1.1 in big endian mode is
1025 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1026 the byte sequence 99 99 f1 3f 9a 99 99 99.
1027
1028 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1029
1030 char *
1031 md_atof (int type, char * litP, int * sizeP)
1032 {
1033 int prec;
1034 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1035 char *t;
1036 int i;
1037
1038 switch (type)
1039 {
1040 case 'f':
1041 case 'F':
1042 case 's':
1043 case 'S':
1044 prec = 2;
1045 break;
1046
1047 case 'd':
1048 case 'D':
1049 case 'r':
1050 case 'R':
1051 prec = 4;
1052 break;
1053
1054 case 'x':
1055 case 'X':
1056 prec = 5;
1057 break;
1058
1059 case 'p':
1060 case 'P':
1061 prec = 5;
1062 break;
1063
1064 default:
1065 *sizeP = 0;
1066 return _("Unrecognized or unsupported floating point constant");
1067 }
1068
1069 t = atof_ieee (input_line_pointer, type, words);
1070 if (t)
1071 input_line_pointer = t;
1072 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1073
1074 if (target_big_endian)
1075 {
1076 for (i = 0; i < prec; i++)
1077 {
1078 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1079 litP += sizeof (LITTLENUM_TYPE);
1080 }
1081 }
1082 else
1083 {
1084 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1085 for (i = prec - 1; i >= 0; i--)
1086 {
1087 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1088 litP += sizeof (LITTLENUM_TYPE);
1089 }
1090 else
1091 /* For a 4 byte float the order of elements in `words' is 1 0.
1092 For an 8 byte float the order is 1 0 3 2. */
1093 for (i = 0; i < prec; i += 2)
1094 {
1095 md_number_to_chars (litP, (valueT) words[i + 1],
1096 sizeof (LITTLENUM_TYPE));
1097 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1098 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1099 litP += 2 * sizeof (LITTLENUM_TYPE);
1100 }
1101 }
1102
1103 return NULL;
1104 }
1105
1106 /* We handle all bad expressions here, so that we can report the faulty
1107 instruction in the error message. */
1108 void
1109 md_operand (expressionS * exp)
1110 {
1111 if (in_my_get_expression)
1112 exp->X_op = O_illegal;
1113 }
1114
1115 /* Immediate values. */
1116
1117 /* Generic immediate-value read function for use in directives.
1118 Accepts anything that 'expression' can fold to a constant.
1119 *val receives the number. */
1120 #ifdef OBJ_ELF
1121 static int
1122 immediate_for_directive (int *val)
1123 {
1124 expressionS exp;
1125 exp.X_op = O_illegal;
1126
1127 if (is_immediate_prefix (*input_line_pointer))
1128 {
1129 input_line_pointer++;
1130 expression (&exp);
1131 }
1132
1133 if (exp.X_op != O_constant)
1134 {
1135 as_bad (_("expected #constant"));
1136 ignore_rest_of_line ();
1137 return FAIL;
1138 }
1139 *val = exp.X_add_number;
1140 return SUCCESS;
1141 }
1142 #endif
1143
1144 /* Register parsing. */
1145
1146 /* Generic register parser. CCP points to what should be the
1147 beginning of a register name. If it is indeed a valid register
1148 name, advance CCP over it and return the reg_entry structure;
1149 otherwise return NULL. Does not issue diagnostics. */
1150
1151 static struct reg_entry *
1152 arm_reg_parse_multi (char **ccp)
1153 {
1154 char *start = *ccp;
1155 char *p;
1156 struct reg_entry *reg;
1157
1158 #ifdef REGISTER_PREFIX
1159 if (*start != REGISTER_PREFIX)
1160 return NULL;
1161 start++;
1162 #endif
1163 #ifdef OPTIONAL_REGISTER_PREFIX
1164 if (*start == OPTIONAL_REGISTER_PREFIX)
1165 start++;
1166 #endif
1167
1168 p = start;
1169 if (!ISALPHA (*p) || !is_name_beginner (*p))
1170 return NULL;
1171
1172 do
1173 p++;
1174 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1175
1176 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1177
1178 if (!reg)
1179 return NULL;
1180
1181 *ccp = p;
1182 return reg;
1183 }
1184
1185 static int
1186 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1187 enum arm_reg_type type)
1188 {
1189 /* Alternative syntaxes are accepted for a few register classes. */
1190 switch (type)
1191 {
1192 case REG_TYPE_MVF:
1193 case REG_TYPE_MVD:
1194 case REG_TYPE_MVFX:
1195 case REG_TYPE_MVDX:
1196 /* Generic coprocessor register names are allowed for these. */
1197 if (reg && reg->type == REG_TYPE_CN)
1198 return reg->number;
1199 break;
1200
1201 case REG_TYPE_CP:
1202 /* For backward compatibility, a bare number is valid here. */
1203 {
1204 unsigned long processor = strtoul (start, ccp, 10);
1205 if (*ccp != start && processor <= 15)
1206 return processor;
1207 }
1208
1209 case REG_TYPE_MMXWC:
1210 /* WC includes WCG. ??? I'm not sure this is true for all
1211 instructions that take WC registers. */
1212 if (reg && reg->type == REG_TYPE_MMXWCG)
1213 return reg->number;
1214 break;
1215
1216 default:
1217 break;
1218 }
1219
1220 return FAIL;
1221 }
1222
1223 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1224 return value is the register number or FAIL. */
1225
1226 static int
1227 arm_reg_parse (char **ccp, enum arm_reg_type type)
1228 {
1229 char *start = *ccp;
1230 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1231 int ret;
1232
1233 /* Do not allow a scalar (reg+index) to parse as a register. */
1234 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1235 return FAIL;
1236
1237 if (reg && reg->type == type)
1238 return reg->number;
1239
1240 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1241 return ret;
1242
1243 *ccp = start;
1244 return FAIL;
1245 }
1246
1247 /* Parse a Neon type specifier. *STR should point at the leading '.'
1248 character. Does no verification at this stage that the type fits the opcode
1249 properly. E.g.,
1250
1251 .i32.i32.s16
1252 .s32.f32
1253 .u16
1254
1255 Can all be legally parsed by this function.
1256
1257 Fills in neon_type struct pointer with parsed information, and updates STR
1258 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1259 type, FAIL if not. */
1260
1261 static int
1262 parse_neon_type (struct neon_type *type, char **str)
1263 {
1264 char *ptr = *str;
1265
1266 if (type)
1267 type->elems = 0;
1268
1269 while (type->elems < NEON_MAX_TYPE_ELS)
1270 {
1271 enum neon_el_type thistype = NT_untyped;
1272 unsigned thissize = -1u;
1273
1274 if (*ptr != '.')
1275 break;
1276
1277 ptr++;
1278
1279 /* Just a size without an explicit type. */
1280 if (ISDIGIT (*ptr))
1281 goto parsesize;
1282
1283 switch (TOLOWER (*ptr))
1284 {
1285 case 'i': thistype = NT_integer; break;
1286 case 'f': thistype = NT_float; break;
1287 case 'p': thistype = NT_poly; break;
1288 case 's': thistype = NT_signed; break;
1289 case 'u': thistype = NT_unsigned; break;
1290 case 'd':
1291 thistype = NT_float;
1292 thissize = 64;
1293 ptr++;
1294 goto done;
1295 default:
1296 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1297 return FAIL;
1298 }
1299
1300 ptr++;
1301
1302 /* .f is an abbreviation for .f32. */
1303 if (thistype == NT_float && !ISDIGIT (*ptr))
1304 thissize = 32;
1305 else
1306 {
1307 parsesize:
1308 thissize = strtoul (ptr, &ptr, 10);
1309
1310 if (thissize != 8 && thissize != 16 && thissize != 32
1311 && thissize != 64)
1312 {
1313 as_bad (_("bad size %d in type specifier"), thissize);
1314 return FAIL;
1315 }
1316 }
1317
1318 done:
1319 if (type)
1320 {
1321 type->el[type->elems].type = thistype;
1322 type->el[type->elems].size = thissize;
1323 type->elems++;
1324 }
1325 }
1326
1327 /* Empty/missing type is not a successful parse. */
1328 if (type->elems == 0)
1329 return FAIL;
1330
1331 *str = ptr;
1332
1333 return SUCCESS;
1334 }
1335
1336 /* Errors may be set multiple times during parsing or bit encoding
1337 (particularly in the Neon bits), but usually the earliest error which is set
1338 will be the most meaningful. Avoid overwriting it with later (cascading)
1339 errors by calling this function. */
1340
1341 static void
1342 first_error (const char *err)
1343 {
1344 if (!inst.error)
1345 inst.error = err;
1346 }
1347
1348 /* Parse a single type, e.g. ".s32", leading period included. */
1349 static int
1350 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1351 {
1352 char *str = *ccp;
1353 struct neon_type optype;
1354
1355 if (*str == '.')
1356 {
1357 if (parse_neon_type (&optype, &str) == SUCCESS)
1358 {
1359 if (optype.elems == 1)
1360 *vectype = optype.el[0];
1361 else
1362 {
1363 first_error (_("only one type should be specified for operand"));
1364 return FAIL;
1365 }
1366 }
1367 else
1368 {
1369 first_error (_("vector type expected"));
1370 return FAIL;
1371 }
1372 }
1373 else
1374 return FAIL;
1375
1376 *ccp = str;
1377
1378 return SUCCESS;
1379 }
1380
1381 /* Special meanings for indices (which have a range of 0-7), which will fit into
1382 a 4-bit integer. */
1383
1384 #define NEON_ALL_LANES 15
1385 #define NEON_INTERLEAVE_LANES 14
1386
1387 /* Parse either a register or a scalar, with an optional type. Return the
1388 register number, and optionally fill in the actual type of the register
1389 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1390 type/index information in *TYPEINFO. */
1391
1392 static int
1393 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1394 enum arm_reg_type *rtype,
1395 struct neon_typed_alias *typeinfo)
1396 {
1397 char *str = *ccp;
1398 struct reg_entry *reg = arm_reg_parse_multi (&str);
1399 struct neon_typed_alias atype;
1400 struct neon_type_el parsetype;
1401
1402 atype.defined = 0;
1403 atype.index = -1;
1404 atype.eltype.type = NT_invtype;
1405 atype.eltype.size = -1;
1406
1407 /* Try alternate syntax for some types of register. Note these are mutually
1408 exclusive with the Neon syntax extensions. */
1409 if (reg == NULL)
1410 {
1411 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1412 if (altreg != FAIL)
1413 *ccp = str;
1414 if (typeinfo)
1415 *typeinfo = atype;
1416 return altreg;
1417 }
1418
1419 /* Undo polymorphism when a set of register types may be accepted. */
1420 if ((type == REG_TYPE_NDQ
1421 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1422 || (type == REG_TYPE_VFSD
1423 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1424 || (type == REG_TYPE_NSDQ
1425 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1426 || reg->type == REG_TYPE_NQ))
1427 || (type == REG_TYPE_MMXWC
1428 && (reg->type == REG_TYPE_MMXWCG)))
1429 type = (enum arm_reg_type) reg->type;
1430
1431 if (type != reg->type)
1432 return FAIL;
1433
1434 if (reg->neon)
1435 atype = *reg->neon;
1436
1437 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1438 {
1439 if ((atype.defined & NTA_HASTYPE) != 0)
1440 {
1441 first_error (_("can't redefine type for operand"));
1442 return FAIL;
1443 }
1444 atype.defined |= NTA_HASTYPE;
1445 atype.eltype = parsetype;
1446 }
1447
1448 if (skip_past_char (&str, '[') == SUCCESS)
1449 {
1450 if (type != REG_TYPE_VFD)
1451 {
1452 first_error (_("only D registers may be indexed"));
1453 return FAIL;
1454 }
1455
1456 if ((atype.defined & NTA_HASINDEX) != 0)
1457 {
1458 first_error (_("can't change index for operand"));
1459 return FAIL;
1460 }
1461
1462 atype.defined |= NTA_HASINDEX;
1463
1464 if (skip_past_char (&str, ']') == SUCCESS)
1465 atype.index = NEON_ALL_LANES;
1466 else
1467 {
1468 expressionS exp;
1469
1470 my_get_expression (&exp, &str, GE_NO_PREFIX);
1471
1472 if (exp.X_op != O_constant)
1473 {
1474 first_error (_("constant expression required"));
1475 return FAIL;
1476 }
1477
1478 if (skip_past_char (&str, ']') == FAIL)
1479 return FAIL;
1480
1481 atype.index = exp.X_add_number;
1482 }
1483 }
1484
1485 if (typeinfo)
1486 *typeinfo = atype;
1487
1488 if (rtype)
1489 *rtype = type;
1490
1491 *ccp = str;
1492
1493 return reg->number;
1494 }
1495
1496 /* Like arm_reg_parse, but allow allow the following extra features:
1497 - If RTYPE is non-zero, return the (possibly restricted) type of the
1498 register (e.g. Neon double or quad reg when either has been requested).
1499 - If this is a Neon vector type with additional type information, fill
1500 in the struct pointed to by VECTYPE (if non-NULL).
1501 This function will fault on encountering a scalar. */
1502
1503 static int
1504 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1505 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1506 {
1507 struct neon_typed_alias atype;
1508 char *str = *ccp;
1509 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1510
1511 if (reg == FAIL)
1512 return FAIL;
1513
1514 /* Do not allow regname(... to parse as a register. */
1515 if (*str == '(')
1516 return FAIL;
1517
1518 /* Do not allow a scalar (reg+index) to parse as a register. */
1519 if ((atype.defined & NTA_HASINDEX) != 0)
1520 {
1521 first_error (_("register operand expected, but got scalar"));
1522 return FAIL;
1523 }
1524
1525 if (vectype)
1526 *vectype = atype.eltype;
1527
1528 *ccp = str;
1529
1530 return reg;
1531 }
1532
1533 #define NEON_SCALAR_REG(X) ((X) >> 4)
1534 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1535
1536 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1537 have enough information to be able to do a good job bounds-checking. So, we
1538 just do easy checks here, and do further checks later. */
1539
1540 static int
1541 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1542 {
1543 int reg;
1544 char *str = *ccp;
1545 struct neon_typed_alias atype;
1546
1547 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1548
1549 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1550 return FAIL;
1551
1552 if (atype.index == NEON_ALL_LANES)
1553 {
1554 first_error (_("scalar must have an index"));
1555 return FAIL;
1556 }
1557 else if (atype.index >= 64 / elsize)
1558 {
1559 first_error (_("scalar index out of range"));
1560 return FAIL;
1561 }
1562
1563 if (type)
1564 *type = atype.eltype;
1565
1566 *ccp = str;
1567
1568 return reg * 16 + atype.index;
1569 }
1570
1571 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1572
1573 static long
1574 parse_reg_list (char ** strp)
1575 {
1576 char * str = * strp;
1577 long range = 0;
1578 int another_range;
1579
1580 /* We come back here if we get ranges concatenated by '+' or '|'. */
1581 do
1582 {
1583 another_range = 0;
1584
1585 if (*str == '{')
1586 {
1587 int in_range = 0;
1588 int cur_reg = -1;
1589
1590 str++;
1591 do
1592 {
1593 int reg;
1594
1595 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1596 {
1597 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1598 return FAIL;
1599 }
1600
1601 if (in_range)
1602 {
1603 int i;
1604
1605 if (reg <= cur_reg)
1606 {
1607 first_error (_("bad range in register list"));
1608 return FAIL;
1609 }
1610
1611 for (i = cur_reg + 1; i < reg; i++)
1612 {
1613 if (range & (1 << i))
1614 as_tsktsk
1615 (_("Warning: duplicated register (r%d) in register list"),
1616 i);
1617 else
1618 range |= 1 << i;
1619 }
1620 in_range = 0;
1621 }
1622
1623 if (range & (1 << reg))
1624 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1625 reg);
1626 else if (reg <= cur_reg)
1627 as_tsktsk (_("Warning: register range not in ascending order"));
1628
1629 range |= 1 << reg;
1630 cur_reg = reg;
1631 }
1632 while (skip_past_comma (&str) != FAIL
1633 || (in_range = 1, *str++ == '-'));
1634 str--;
1635
1636 if (*str++ != '}')
1637 {
1638 first_error (_("missing `}'"));
1639 return FAIL;
1640 }
1641 }
1642 else
1643 {
1644 expressionS exp;
1645
1646 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1647 return FAIL;
1648
1649 if (exp.X_op == O_constant)
1650 {
1651 if (exp.X_add_number
1652 != (exp.X_add_number & 0x0000ffff))
1653 {
1654 inst.error = _("invalid register mask");
1655 return FAIL;
1656 }
1657
1658 if ((range & exp.X_add_number) != 0)
1659 {
1660 int regno = range & exp.X_add_number;
1661
1662 regno &= -regno;
1663 regno = (1 << regno) - 1;
1664 as_tsktsk
1665 (_("Warning: duplicated register (r%d) in register list"),
1666 regno);
1667 }
1668
1669 range |= exp.X_add_number;
1670 }
1671 else
1672 {
1673 if (inst.reloc.type != 0)
1674 {
1675 inst.error = _("expression too complex");
1676 return FAIL;
1677 }
1678
1679 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1680 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1681 inst.reloc.pc_rel = 0;
1682 }
1683 }
1684
1685 if (*str == '|' || *str == '+')
1686 {
1687 str++;
1688 another_range = 1;
1689 }
1690 }
1691 while (another_range);
1692
1693 *strp = str;
1694 return range;
1695 }
1696
1697 /* Types of registers in a list. */
1698
1699 enum reg_list_els
1700 {
1701 REGLIST_VFP_S,
1702 REGLIST_VFP_D,
1703 REGLIST_NEON_D
1704 };
1705
1706 /* Parse a VFP register list. If the string is invalid return FAIL.
1707 Otherwise return the number of registers, and set PBASE to the first
1708 register. Parses registers of type ETYPE.
1709 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1710 - Q registers can be used to specify pairs of D registers
1711 - { } can be omitted from around a singleton register list
1712 FIXME: This is not implemented, as it would require backtracking in
1713 some cases, e.g.:
1714 vtbl.8 d3,d4,d5
1715 This could be done (the meaning isn't really ambiguous), but doesn't
1716 fit in well with the current parsing framework.
1717 - 32 D registers may be used (also true for VFPv3).
1718 FIXME: Types are ignored in these register lists, which is probably a
1719 bug. */
1720
1721 static int
1722 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1723 {
1724 char *str = *ccp;
1725 int base_reg;
1726 int new_base;
1727 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1728 int max_regs = 0;
1729 int count = 0;
1730 int warned = 0;
1731 unsigned long mask = 0;
1732 int i;
1733
1734 if (*str != '{')
1735 {
1736 inst.error = _("expecting {");
1737 return FAIL;
1738 }
1739
1740 str++;
1741
1742 switch (etype)
1743 {
1744 case REGLIST_VFP_S:
1745 regtype = REG_TYPE_VFS;
1746 max_regs = 32;
1747 break;
1748
1749 case REGLIST_VFP_D:
1750 regtype = REG_TYPE_VFD;
1751 break;
1752
1753 case REGLIST_NEON_D:
1754 regtype = REG_TYPE_NDQ;
1755 break;
1756 }
1757
1758 if (etype != REGLIST_VFP_S)
1759 {
1760 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1761 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1762 {
1763 max_regs = 32;
1764 if (thumb_mode)
1765 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1766 fpu_vfp_ext_d32);
1767 else
1768 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1769 fpu_vfp_ext_d32);
1770 }
1771 else
1772 max_regs = 16;
1773 }
1774
1775 base_reg = max_regs;
1776
1777 do
1778 {
1779 int setmask = 1, addregs = 1;
1780
1781 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1782
1783 if (new_base == FAIL)
1784 {
1785 first_error (_(reg_expected_msgs[regtype]));
1786 return FAIL;
1787 }
1788
1789 if (new_base >= max_regs)
1790 {
1791 first_error (_("register out of range in list"));
1792 return FAIL;
1793 }
1794
1795 /* Note: a value of 2 * n is returned for the register Q<n>. */
1796 if (regtype == REG_TYPE_NQ)
1797 {
1798 setmask = 3;
1799 addregs = 2;
1800 }
1801
1802 if (new_base < base_reg)
1803 base_reg = new_base;
1804
1805 if (mask & (setmask << new_base))
1806 {
1807 first_error (_("invalid register list"));
1808 return FAIL;
1809 }
1810
1811 if ((mask >> new_base) != 0 && ! warned)
1812 {
1813 as_tsktsk (_("register list not in ascending order"));
1814 warned = 1;
1815 }
1816
1817 mask |= setmask << new_base;
1818 count += addregs;
1819
1820 if (*str == '-') /* We have the start of a range expression */
1821 {
1822 int high_range;
1823
1824 str++;
1825
1826 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1827 == FAIL)
1828 {
1829 inst.error = gettext (reg_expected_msgs[regtype]);
1830 return FAIL;
1831 }
1832
1833 if (high_range >= max_regs)
1834 {
1835 first_error (_("register out of range in list"));
1836 return FAIL;
1837 }
1838
1839 if (regtype == REG_TYPE_NQ)
1840 high_range = high_range + 1;
1841
1842 if (high_range <= new_base)
1843 {
1844 inst.error = _("register range not in ascending order");
1845 return FAIL;
1846 }
1847
1848 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1849 {
1850 if (mask & (setmask << new_base))
1851 {
1852 inst.error = _("invalid register list");
1853 return FAIL;
1854 }
1855
1856 mask |= setmask << new_base;
1857 count += addregs;
1858 }
1859 }
1860 }
1861 while (skip_past_comma (&str) != FAIL);
1862
1863 str++;
1864
1865 /* Sanity check -- should have raised a parse error above. */
1866 if (count == 0 || count > max_regs)
1867 abort ();
1868
1869 *pbase = base_reg;
1870
1871 /* Final test -- the registers must be consecutive. */
1872 mask >>= base_reg;
1873 for (i = 0; i < count; i++)
1874 {
1875 if ((mask & (1u << i)) == 0)
1876 {
1877 inst.error = _("non-contiguous register range");
1878 return FAIL;
1879 }
1880 }
1881
1882 *ccp = str;
1883
1884 return count;
1885 }
1886
1887 /* True if two alias types are the same. */
1888
1889 static bfd_boolean
1890 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1891 {
1892 if (!a && !b)
1893 return TRUE;
1894
1895 if (!a || !b)
1896 return FALSE;
1897
1898 if (a->defined != b->defined)
1899 return FALSE;
1900
1901 if ((a->defined & NTA_HASTYPE) != 0
1902 && (a->eltype.type != b->eltype.type
1903 || a->eltype.size != b->eltype.size))
1904 return FALSE;
1905
1906 if ((a->defined & NTA_HASINDEX) != 0
1907 && (a->index != b->index))
1908 return FALSE;
1909
1910 return TRUE;
1911 }
1912
1913 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1914 The base register is put in *PBASE.
1915 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1916 the return value.
1917 The register stride (minus one) is put in bit 4 of the return value.
1918 Bits [6:5] encode the list length (minus one).
1919 The type of the list elements is put in *ELTYPE, if non-NULL. */
1920
1921 #define NEON_LANE(X) ((X) & 0xf)
1922 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1923 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1924
1925 static int
1926 parse_neon_el_struct_list (char **str, unsigned *pbase,
1927 struct neon_type_el *eltype)
1928 {
1929 char *ptr = *str;
1930 int base_reg = -1;
1931 int reg_incr = -1;
1932 int count = 0;
1933 int lane = -1;
1934 int leading_brace = 0;
1935 enum arm_reg_type rtype = REG_TYPE_NDQ;
1936 const char *const incr_error = _("register stride must be 1 or 2");
1937 const char *const type_error = _("mismatched element/structure types in list");
1938 struct neon_typed_alias firsttype;
1939
1940 if (skip_past_char (&ptr, '{') == SUCCESS)
1941 leading_brace = 1;
1942
1943 do
1944 {
1945 struct neon_typed_alias atype;
1946 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1947
1948 if (getreg == FAIL)
1949 {
1950 first_error (_(reg_expected_msgs[rtype]));
1951 return FAIL;
1952 }
1953
1954 if (base_reg == -1)
1955 {
1956 base_reg = getreg;
1957 if (rtype == REG_TYPE_NQ)
1958 {
1959 reg_incr = 1;
1960 }
1961 firsttype = atype;
1962 }
1963 else if (reg_incr == -1)
1964 {
1965 reg_incr = getreg - base_reg;
1966 if (reg_incr < 1 || reg_incr > 2)
1967 {
1968 first_error (_(incr_error));
1969 return FAIL;
1970 }
1971 }
1972 else if (getreg != base_reg + reg_incr * count)
1973 {
1974 first_error (_(incr_error));
1975 return FAIL;
1976 }
1977
1978 if (! neon_alias_types_same (&atype, &firsttype))
1979 {
1980 first_error (_(type_error));
1981 return FAIL;
1982 }
1983
1984 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1985 modes. */
1986 if (ptr[0] == '-')
1987 {
1988 struct neon_typed_alias htype;
1989 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1990 if (lane == -1)
1991 lane = NEON_INTERLEAVE_LANES;
1992 else if (lane != NEON_INTERLEAVE_LANES)
1993 {
1994 first_error (_(type_error));
1995 return FAIL;
1996 }
1997 if (reg_incr == -1)
1998 reg_incr = 1;
1999 else if (reg_incr != 1)
2000 {
2001 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2002 return FAIL;
2003 }
2004 ptr++;
2005 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2006 if (hireg == FAIL)
2007 {
2008 first_error (_(reg_expected_msgs[rtype]));
2009 return FAIL;
2010 }
2011 if (! neon_alias_types_same (&htype, &firsttype))
2012 {
2013 first_error (_(type_error));
2014 return FAIL;
2015 }
2016 count += hireg + dregs - getreg;
2017 continue;
2018 }
2019
2020 /* If we're using Q registers, we can't use [] or [n] syntax. */
2021 if (rtype == REG_TYPE_NQ)
2022 {
2023 count += 2;
2024 continue;
2025 }
2026
2027 if ((atype.defined & NTA_HASINDEX) != 0)
2028 {
2029 if (lane == -1)
2030 lane = atype.index;
2031 else if (lane != atype.index)
2032 {
2033 first_error (_(type_error));
2034 return FAIL;
2035 }
2036 }
2037 else if (lane == -1)
2038 lane = NEON_INTERLEAVE_LANES;
2039 else if (lane != NEON_INTERLEAVE_LANES)
2040 {
2041 first_error (_(type_error));
2042 return FAIL;
2043 }
2044 count++;
2045 }
2046 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2047
2048 /* No lane set by [x]. We must be interleaving structures. */
2049 if (lane == -1)
2050 lane = NEON_INTERLEAVE_LANES;
2051
2052 /* Sanity check. */
2053 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2054 || (count > 1 && reg_incr == -1))
2055 {
2056 first_error (_("error parsing element/structure list"));
2057 return FAIL;
2058 }
2059
2060 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2061 {
2062 first_error (_("expected }"));
2063 return FAIL;
2064 }
2065
2066 if (reg_incr == -1)
2067 reg_incr = 1;
2068
2069 if (eltype)
2070 *eltype = firsttype.eltype;
2071
2072 *pbase = base_reg;
2073 *str = ptr;
2074
2075 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2076 }
2077
2078 /* Parse an explicit relocation suffix on an expression. This is
2079 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2080 arm_reloc_hsh contains no entries, so this function can only
2081 succeed if there is no () after the word. Returns -1 on error,
2082 BFD_RELOC_UNUSED if there wasn't any suffix. */
2083
2084 static int
2085 parse_reloc (char **str)
2086 {
2087 struct reloc_entry *r;
2088 char *p, *q;
2089
2090 if (**str != '(')
2091 return BFD_RELOC_UNUSED;
2092
2093 p = *str + 1;
2094 q = p;
2095
2096 while (*q && *q != ')' && *q != ',')
2097 q++;
2098 if (*q != ')')
2099 return -1;
2100
2101 if ((r = (struct reloc_entry *)
2102 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2103 return -1;
2104
2105 *str = q + 1;
2106 return r->reloc;
2107 }
2108
2109 /* Directives: register aliases. */
2110
2111 static struct reg_entry *
2112 insert_reg_alias (char *str, unsigned number, int type)
2113 {
2114 struct reg_entry *new_reg;
2115 const char *name;
2116
2117 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2118 {
2119 if (new_reg->builtin)
2120 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2121
2122 /* Only warn about a redefinition if it's not defined as the
2123 same register. */
2124 else if (new_reg->number != number || new_reg->type != type)
2125 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2126
2127 return NULL;
2128 }
2129
2130 name = xstrdup (str);
2131 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2132
2133 new_reg->name = name;
2134 new_reg->number = number;
2135 new_reg->type = type;
2136 new_reg->builtin = FALSE;
2137 new_reg->neon = NULL;
2138
2139 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2140 abort ();
2141
2142 return new_reg;
2143 }
2144
2145 static void
2146 insert_neon_reg_alias (char *str, int number, int type,
2147 struct neon_typed_alias *atype)
2148 {
2149 struct reg_entry *reg = insert_reg_alias (str, number, type);
2150
2151 if (!reg)
2152 {
2153 first_error (_("attempt to redefine typed alias"));
2154 return;
2155 }
2156
2157 if (atype)
2158 {
2159 reg->neon = (struct neon_typed_alias *)
2160 xmalloc (sizeof (struct neon_typed_alias));
2161 *reg->neon = *atype;
2162 }
2163 }
2164
2165 /* Look for the .req directive. This is of the form:
2166
2167 new_register_name .req existing_register_name
2168
2169 If we find one, or if it looks sufficiently like one that we want to
2170 handle any error here, return TRUE. Otherwise return FALSE. */
2171
2172 static bfd_boolean
2173 create_register_alias (char * newname, char *p)
2174 {
2175 struct reg_entry *old;
2176 char *oldname, *nbuf;
2177 size_t nlen;
2178
2179 /* The input scrubber ensures that whitespace after the mnemonic is
2180 collapsed to single spaces. */
2181 oldname = p;
2182 if (strncmp (oldname, " .req ", 6) != 0)
2183 return FALSE;
2184
2185 oldname += 6;
2186 if (*oldname == '\0')
2187 return FALSE;
2188
2189 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2190 if (!old)
2191 {
2192 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2193 return TRUE;
2194 }
2195
2196 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2197 the desired alias name, and p points to its end. If not, then
2198 the desired alias name is in the global original_case_string. */
2199 #ifdef TC_CASE_SENSITIVE
2200 nlen = p - newname;
2201 #else
2202 newname = original_case_string;
2203 nlen = strlen (newname);
2204 #endif
2205
2206 nbuf = (char *) alloca (nlen + 1);
2207 memcpy (nbuf, newname, nlen);
2208 nbuf[nlen] = '\0';
2209
2210 /* Create aliases under the new name as stated; an all-lowercase
2211 version of the new name; and an all-uppercase version of the new
2212 name. */
2213 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2214 {
2215 for (p = nbuf; *p; p++)
2216 *p = TOUPPER (*p);
2217
2218 if (strncmp (nbuf, newname, nlen))
2219 {
2220 /* If this attempt to create an additional alias fails, do not bother
2221 trying to create the all-lower case alias. We will fail and issue
2222 a second, duplicate error message. This situation arises when the
2223 programmer does something like:
2224 foo .req r0
2225 Foo .req r1
2226 The second .req creates the "Foo" alias but then fails to create
2227 the artificial FOO alias because it has already been created by the
2228 first .req. */
2229 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2230 return TRUE;
2231 }
2232
2233 for (p = nbuf; *p; p++)
2234 *p = TOLOWER (*p);
2235
2236 if (strncmp (nbuf, newname, nlen))
2237 insert_reg_alias (nbuf, old->number, old->type);
2238 }
2239
2240 return TRUE;
2241 }
2242
2243 /* Create a Neon typed/indexed register alias using directives, e.g.:
2244 X .dn d5.s32[1]
2245 Y .qn 6.s16
2246 Z .dn d7
2247 T .dn Z[0]
2248 These typed registers can be used instead of the types specified after the
2249 Neon mnemonic, so long as all operands given have types. Types can also be
2250 specified directly, e.g.:
2251 vadd d0.s32, d1.s32, d2.s32 */
2252
2253 static bfd_boolean
2254 create_neon_reg_alias (char *newname, char *p)
2255 {
2256 enum arm_reg_type basetype;
2257 struct reg_entry *basereg;
2258 struct reg_entry mybasereg;
2259 struct neon_type ntype;
2260 struct neon_typed_alias typeinfo;
2261 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2262 int namelen;
2263
2264 typeinfo.defined = 0;
2265 typeinfo.eltype.type = NT_invtype;
2266 typeinfo.eltype.size = -1;
2267 typeinfo.index = -1;
2268
2269 nameend = p;
2270
2271 if (strncmp (p, " .dn ", 5) == 0)
2272 basetype = REG_TYPE_VFD;
2273 else if (strncmp (p, " .qn ", 5) == 0)
2274 basetype = REG_TYPE_NQ;
2275 else
2276 return FALSE;
2277
2278 p += 5;
2279
2280 if (*p == '\0')
2281 return FALSE;
2282
2283 basereg = arm_reg_parse_multi (&p);
2284
2285 if (basereg && basereg->type != basetype)
2286 {
2287 as_bad (_("bad type for register"));
2288 return FALSE;
2289 }
2290
2291 if (basereg == NULL)
2292 {
2293 expressionS exp;
2294 /* Try parsing as an integer. */
2295 my_get_expression (&exp, &p, GE_NO_PREFIX);
2296 if (exp.X_op != O_constant)
2297 {
2298 as_bad (_("expression must be constant"));
2299 return FALSE;
2300 }
2301 basereg = &mybasereg;
2302 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2303 : exp.X_add_number;
2304 basereg->neon = 0;
2305 }
2306
2307 if (basereg->neon)
2308 typeinfo = *basereg->neon;
2309
2310 if (parse_neon_type (&ntype, &p) == SUCCESS)
2311 {
2312 /* We got a type. */
2313 if (typeinfo.defined & NTA_HASTYPE)
2314 {
2315 as_bad (_("can't redefine the type of a register alias"));
2316 return FALSE;
2317 }
2318
2319 typeinfo.defined |= NTA_HASTYPE;
2320 if (ntype.elems != 1)
2321 {
2322 as_bad (_("you must specify a single type only"));
2323 return FALSE;
2324 }
2325 typeinfo.eltype = ntype.el[0];
2326 }
2327
2328 if (skip_past_char (&p, '[') == SUCCESS)
2329 {
2330 expressionS exp;
2331 /* We got a scalar index. */
2332
2333 if (typeinfo.defined & NTA_HASINDEX)
2334 {
2335 as_bad (_("can't redefine the index of a scalar alias"));
2336 return FALSE;
2337 }
2338
2339 my_get_expression (&exp, &p, GE_NO_PREFIX);
2340
2341 if (exp.X_op != O_constant)
2342 {
2343 as_bad (_("scalar index must be constant"));
2344 return FALSE;
2345 }
2346
2347 typeinfo.defined |= NTA_HASINDEX;
2348 typeinfo.index = exp.X_add_number;
2349
2350 if (skip_past_char (&p, ']') == FAIL)
2351 {
2352 as_bad (_("expecting ]"));
2353 return FALSE;
2354 }
2355 }
2356
2357 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2358 the desired alias name, and p points to its end. If not, then
2359 the desired alias name is in the global original_case_string. */
2360 #ifdef TC_CASE_SENSITIVE
2361 namelen = nameend - newname;
2362 #else
2363 newname = original_case_string;
2364 namelen = strlen (newname);
2365 #endif
2366
2367 namebuf = (char *) alloca (namelen + 1);
2368 strncpy (namebuf, newname, namelen);
2369 namebuf[namelen] = '\0';
2370
2371 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2372 typeinfo.defined != 0 ? &typeinfo : NULL);
2373
2374 /* Insert name in all uppercase. */
2375 for (p = namebuf; *p; p++)
2376 *p = TOUPPER (*p);
2377
2378 if (strncmp (namebuf, newname, namelen))
2379 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2380 typeinfo.defined != 0 ? &typeinfo : NULL);
2381
2382 /* Insert name in all lowercase. */
2383 for (p = namebuf; *p; p++)
2384 *p = TOLOWER (*p);
2385
2386 if (strncmp (namebuf, newname, namelen))
2387 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2388 typeinfo.defined != 0 ? &typeinfo : NULL);
2389
2390 return TRUE;
2391 }
2392
2393 /* Should never be called, as .req goes between the alias and the
2394 register name, not at the beginning of the line. */
2395
2396 static void
2397 s_req (int a ATTRIBUTE_UNUSED)
2398 {
2399 as_bad (_("invalid syntax for .req directive"));
2400 }
2401
2402 static void
2403 s_dn (int a ATTRIBUTE_UNUSED)
2404 {
2405 as_bad (_("invalid syntax for .dn directive"));
2406 }
2407
2408 static void
2409 s_qn (int a ATTRIBUTE_UNUSED)
2410 {
2411 as_bad (_("invalid syntax for .qn directive"));
2412 }
2413
2414 /* The .unreq directive deletes an alias which was previously defined
2415 by .req. For example:
2416
2417 my_alias .req r11
2418 .unreq my_alias */
2419
2420 static void
2421 s_unreq (int a ATTRIBUTE_UNUSED)
2422 {
2423 char * name;
2424 char saved_char;
2425
2426 name = input_line_pointer;
2427
2428 while (*input_line_pointer != 0
2429 && *input_line_pointer != ' '
2430 && *input_line_pointer != '\n')
2431 ++input_line_pointer;
2432
2433 saved_char = *input_line_pointer;
2434 *input_line_pointer = 0;
2435
2436 if (!*name)
2437 as_bad (_("invalid syntax for .unreq directive"));
2438 else
2439 {
2440 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2441 name);
2442
2443 if (!reg)
2444 as_bad (_("unknown register alias '%s'"), name);
2445 else if (reg->builtin)
2446 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2447 name);
2448 else
2449 {
2450 char * p;
2451 char * nbuf;
2452
2453 hash_delete (arm_reg_hsh, name, FALSE);
2454 free ((char *) reg->name);
2455 if (reg->neon)
2456 free (reg->neon);
2457 free (reg);
2458
2459 /* Also locate the all upper case and all lower case versions.
2460 Do not complain if we cannot find one or the other as it
2461 was probably deleted above. */
2462
2463 nbuf = strdup (name);
2464 for (p = nbuf; *p; p++)
2465 *p = TOUPPER (*p);
2466 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2467 if (reg)
2468 {
2469 hash_delete (arm_reg_hsh, nbuf, FALSE);
2470 free ((char *) reg->name);
2471 if (reg->neon)
2472 free (reg->neon);
2473 free (reg);
2474 }
2475
2476 for (p = nbuf; *p; p++)
2477 *p = TOLOWER (*p);
2478 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2479 if (reg)
2480 {
2481 hash_delete (arm_reg_hsh, nbuf, FALSE);
2482 free ((char *) reg->name);
2483 if (reg->neon)
2484 free (reg->neon);
2485 free (reg);
2486 }
2487
2488 free (nbuf);
2489 }
2490 }
2491
2492 *input_line_pointer = saved_char;
2493 demand_empty_rest_of_line ();
2494 }
2495
2496 /* Directives: Instruction set selection. */
2497
2498 #ifdef OBJ_ELF
2499 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2500 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2501 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2502 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2503
2504 /* Create a new mapping symbol for the transition to STATE. */
2505
2506 static void
2507 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2508 {
2509 symbolS * symbolP;
2510 const char * symname;
2511 int type;
2512
2513 switch (state)
2514 {
2515 case MAP_DATA:
2516 symname = "$d";
2517 type = BSF_NO_FLAGS;
2518 break;
2519 case MAP_ARM:
2520 symname = "$a";
2521 type = BSF_NO_FLAGS;
2522 break;
2523 case MAP_THUMB:
2524 symname = "$t";
2525 type = BSF_NO_FLAGS;
2526 break;
2527 default:
2528 abort ();
2529 }
2530
2531 symbolP = symbol_new (symname, now_seg, value, frag);
2532 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2533
2534 switch (state)
2535 {
2536 case MAP_ARM:
2537 THUMB_SET_FUNC (symbolP, 0);
2538 ARM_SET_THUMB (symbolP, 0);
2539 ARM_SET_INTERWORK (symbolP, support_interwork);
2540 break;
2541
2542 case MAP_THUMB:
2543 THUMB_SET_FUNC (symbolP, 1);
2544 ARM_SET_THUMB (symbolP, 1);
2545 ARM_SET_INTERWORK (symbolP, support_interwork);
2546 break;
2547
2548 case MAP_DATA:
2549 default:
2550 break;
2551 }
2552
2553 /* Save the mapping symbols for future reference. Also check that
2554 we do not place two mapping symbols at the same offset within a
2555 frag. We'll handle overlap between frags in
2556 check_mapping_symbols.
2557
2558 If .fill or other data filling directive generates zero sized data,
2559 the mapping symbol for the following code will have the same value
2560 as the one generated for the data filling directive. In this case,
2561 we replace the old symbol with the new one at the same address. */
2562 if (value == 0)
2563 {
2564 if (frag->tc_frag_data.first_map != NULL)
2565 {
2566 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2567 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2568 }
2569 frag->tc_frag_data.first_map = symbolP;
2570 }
2571 if (frag->tc_frag_data.last_map != NULL)
2572 {
2573 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2574 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2575 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2576 }
2577 frag->tc_frag_data.last_map = symbolP;
2578 }
2579
2580 /* We must sometimes convert a region marked as code to data during
2581 code alignment, if an odd number of bytes have to be padded. The
2582 code mapping symbol is pushed to an aligned address. */
2583
2584 static void
2585 insert_data_mapping_symbol (enum mstate state,
2586 valueT value, fragS *frag, offsetT bytes)
2587 {
2588 /* If there was already a mapping symbol, remove it. */
2589 if (frag->tc_frag_data.last_map != NULL
2590 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2591 {
2592 symbolS *symp = frag->tc_frag_data.last_map;
2593
2594 if (value == 0)
2595 {
2596 know (frag->tc_frag_data.first_map == symp);
2597 frag->tc_frag_data.first_map = NULL;
2598 }
2599 frag->tc_frag_data.last_map = NULL;
2600 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2601 }
2602
2603 make_mapping_symbol (MAP_DATA, value, frag);
2604 make_mapping_symbol (state, value + bytes, frag);
2605 }
2606
2607 static void mapping_state_2 (enum mstate state, int max_chars);
2608
2609 /* Set the mapping state to STATE. Only call this when about to
2610 emit some STATE bytes to the file. */
2611
2612 void
2613 mapping_state (enum mstate state)
2614 {
2615 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2616
2617 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2618
2619 if (mapstate == state)
2620 /* The mapping symbol has already been emitted.
2621 There is nothing else to do. */
2622 return;
2623
2624 if (state == MAP_ARM || state == MAP_THUMB)
2625 /* PR gas/12931
2626 All ARM instructions require 4-byte alignment.
2627 (Almost) all Thumb instructions require 2-byte alignment.
2628
2629 When emitting instructions into any section, mark the section
2630 appropriately.
2631
2632 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2633 but themselves require 2-byte alignment; this applies to some
2634 PC- relative forms. However, these cases will invovle implicit
2635 literal pool generation or an explicit .align >=2, both of
2636 which will cause the section to me marked with sufficient
2637 alignment. Thus, we don't handle those cases here. */
2638 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2639
2640 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2641 /* This case will be evaluated later in the next else. */
2642 return;
2643 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2644 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2645 {
2646 /* Only add the symbol if the offset is > 0:
2647 if we're at the first frag, check it's size > 0;
2648 if we're not at the first frag, then for sure
2649 the offset is > 0. */
2650 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2651 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2652
2653 if (add_symbol)
2654 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2655 }
2656
2657 mapping_state_2 (state, 0);
2658 #undef TRANSITION
2659 }
2660
2661 /* Same as mapping_state, but MAX_CHARS bytes have already been
2662 allocated. Put the mapping symbol that far back. */
2663
2664 static void
2665 mapping_state_2 (enum mstate state, int max_chars)
2666 {
2667 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2668
2669 if (!SEG_NORMAL (now_seg))
2670 return;
2671
2672 if (mapstate == state)
2673 /* The mapping symbol has already been emitted.
2674 There is nothing else to do. */
2675 return;
2676
2677 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2678 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2679 }
2680 #else
2681 #define mapping_state(x) ((void)0)
2682 #define mapping_state_2(x, y) ((void)0)
2683 #endif
2684
2685 /* Find the real, Thumb encoded start of a Thumb function. */
2686
2687 #ifdef OBJ_COFF
2688 static symbolS *
2689 find_real_start (symbolS * symbolP)
2690 {
2691 char * real_start;
2692 const char * name = S_GET_NAME (symbolP);
2693 symbolS * new_target;
2694
2695 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2696 #define STUB_NAME ".real_start_of"
2697
2698 if (name == NULL)
2699 abort ();
2700
2701 /* The compiler may generate BL instructions to local labels because
2702 it needs to perform a branch to a far away location. These labels
2703 do not have a corresponding ".real_start_of" label. We check
2704 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2705 the ".real_start_of" convention for nonlocal branches. */
2706 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2707 return symbolP;
2708
2709 real_start = ACONCAT ((STUB_NAME, name, NULL));
2710 new_target = symbol_find (real_start);
2711
2712 if (new_target == NULL)
2713 {
2714 as_warn (_("Failed to find real start of function: %s\n"), name);
2715 new_target = symbolP;
2716 }
2717
2718 return new_target;
2719 }
2720 #endif
2721
2722 static void
2723 opcode_select (int width)
2724 {
2725 switch (width)
2726 {
2727 case 16:
2728 if (! thumb_mode)
2729 {
2730 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2731 as_bad (_("selected processor does not support THUMB opcodes"));
2732
2733 thumb_mode = 1;
2734 /* No need to force the alignment, since we will have been
2735 coming from ARM mode, which is word-aligned. */
2736 record_alignment (now_seg, 1);
2737 }
2738 break;
2739
2740 case 32:
2741 if (thumb_mode)
2742 {
2743 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2744 as_bad (_("selected processor does not support ARM opcodes"));
2745
2746 thumb_mode = 0;
2747
2748 if (!need_pass_2)
2749 frag_align (2, 0, 0);
2750
2751 record_alignment (now_seg, 1);
2752 }
2753 break;
2754
2755 default:
2756 as_bad (_("invalid instruction size selected (%d)"), width);
2757 }
2758 }
2759
2760 static void
2761 s_arm (int ignore ATTRIBUTE_UNUSED)
2762 {
2763 opcode_select (32);
2764 demand_empty_rest_of_line ();
2765 }
2766
2767 static void
2768 s_thumb (int ignore ATTRIBUTE_UNUSED)
2769 {
2770 opcode_select (16);
2771 demand_empty_rest_of_line ();
2772 }
2773
2774 static void
2775 s_code (int unused ATTRIBUTE_UNUSED)
2776 {
2777 int temp;
2778
2779 temp = get_absolute_expression ();
2780 switch (temp)
2781 {
2782 case 16:
2783 case 32:
2784 opcode_select (temp);
2785 break;
2786
2787 default:
2788 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2789 }
2790 }
2791
2792 static void
2793 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2794 {
2795 /* If we are not already in thumb mode go into it, EVEN if
2796 the target processor does not support thumb instructions.
2797 This is used by gcc/config/arm/lib1funcs.asm for example
2798 to compile interworking support functions even if the
2799 target processor should not support interworking. */
2800 if (! thumb_mode)
2801 {
2802 thumb_mode = 2;
2803 record_alignment (now_seg, 1);
2804 }
2805
2806 demand_empty_rest_of_line ();
2807 }
2808
2809 static void
2810 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2811 {
2812 s_thumb (0);
2813
2814 /* The following label is the name/address of the start of a Thumb function.
2815 We need to know this for the interworking support. */
2816 label_is_thumb_function_name = TRUE;
2817 }
2818
2819 /* Perform a .set directive, but also mark the alias as
2820 being a thumb function. */
2821
2822 static void
2823 s_thumb_set (int equiv)
2824 {
2825 /* XXX the following is a duplicate of the code for s_set() in read.c
2826 We cannot just call that code as we need to get at the symbol that
2827 is created. */
2828 char * name;
2829 char delim;
2830 char * end_name;
2831 symbolS * symbolP;
2832
2833 /* Especial apologies for the random logic:
2834 This just grew, and could be parsed much more simply!
2835 Dean - in haste. */
2836 name = input_line_pointer;
2837 delim = get_symbol_end ();
2838 end_name = input_line_pointer;
2839 *end_name = delim;
2840
2841 if (*input_line_pointer != ',')
2842 {
2843 *end_name = 0;
2844 as_bad (_("expected comma after name \"%s\""), name);
2845 *end_name = delim;
2846 ignore_rest_of_line ();
2847 return;
2848 }
2849
2850 input_line_pointer++;
2851 *end_name = 0;
2852
2853 if (name[0] == '.' && name[1] == '\0')
2854 {
2855 /* XXX - this should not happen to .thumb_set. */
2856 abort ();
2857 }
2858
2859 if ((symbolP = symbol_find (name)) == NULL
2860 && (symbolP = md_undefined_symbol (name)) == NULL)
2861 {
2862 #ifndef NO_LISTING
2863 /* When doing symbol listings, play games with dummy fragments living
2864 outside the normal fragment chain to record the file and line info
2865 for this symbol. */
2866 if (listing & LISTING_SYMBOLS)
2867 {
2868 extern struct list_info_struct * listing_tail;
2869 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2870
2871 memset (dummy_frag, 0, sizeof (fragS));
2872 dummy_frag->fr_type = rs_fill;
2873 dummy_frag->line = listing_tail;
2874 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2875 dummy_frag->fr_symbol = symbolP;
2876 }
2877 else
2878 #endif
2879 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2880
2881 #ifdef OBJ_COFF
2882 /* "set" symbols are local unless otherwise specified. */
2883 SF_SET_LOCAL (symbolP);
2884 #endif /* OBJ_COFF */
2885 } /* Make a new symbol. */
2886
2887 symbol_table_insert (symbolP);
2888
2889 * end_name = delim;
2890
2891 if (equiv
2892 && S_IS_DEFINED (symbolP)
2893 && S_GET_SEGMENT (symbolP) != reg_section)
2894 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2895
2896 pseudo_set (symbolP);
2897
2898 demand_empty_rest_of_line ();
2899
2900 /* XXX Now we come to the Thumb specific bit of code. */
2901
2902 THUMB_SET_FUNC (symbolP, 1);
2903 ARM_SET_THUMB (symbolP, 1);
2904 #if defined OBJ_ELF || defined OBJ_COFF
2905 ARM_SET_INTERWORK (symbolP, support_interwork);
2906 #endif
2907 }
2908
2909 /* Directives: Mode selection. */
2910
2911 /* .syntax [unified|divided] - choose the new unified syntax
2912 (same for Arm and Thumb encoding, modulo slight differences in what
2913 can be represented) or the old divergent syntax for each mode. */
2914 static void
2915 s_syntax (int unused ATTRIBUTE_UNUSED)
2916 {
2917 char *name, delim;
2918
2919 name = input_line_pointer;
2920 delim = get_symbol_end ();
2921
2922 if (!strcasecmp (name, "unified"))
2923 unified_syntax = TRUE;
2924 else if (!strcasecmp (name, "divided"))
2925 unified_syntax = FALSE;
2926 else
2927 {
2928 as_bad (_("unrecognized syntax mode \"%s\""), name);
2929 return;
2930 }
2931 *input_line_pointer = delim;
2932 demand_empty_rest_of_line ();
2933 }
2934
2935 /* Directives: sectioning and alignment. */
2936
2937 /* Same as s_align_ptwo but align 0 => align 2. */
2938
2939 static void
2940 s_align (int unused ATTRIBUTE_UNUSED)
2941 {
2942 int temp;
2943 bfd_boolean fill_p;
2944 long temp_fill;
2945 long max_alignment = 15;
2946
2947 temp = get_absolute_expression ();
2948 if (temp > max_alignment)
2949 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2950 else if (temp < 0)
2951 {
2952 as_bad (_("alignment negative. 0 assumed."));
2953 temp = 0;
2954 }
2955
2956 if (*input_line_pointer == ',')
2957 {
2958 input_line_pointer++;
2959 temp_fill = get_absolute_expression ();
2960 fill_p = TRUE;
2961 }
2962 else
2963 {
2964 fill_p = FALSE;
2965 temp_fill = 0;
2966 }
2967
2968 if (!temp)
2969 temp = 2;
2970
2971 /* Only make a frag if we HAVE to. */
2972 if (temp && !need_pass_2)
2973 {
2974 if (!fill_p && subseg_text_p (now_seg))
2975 frag_align_code (temp, 0);
2976 else
2977 frag_align (temp, (int) temp_fill, 0);
2978 }
2979 demand_empty_rest_of_line ();
2980
2981 record_alignment (now_seg, temp);
2982 }
2983
2984 static void
2985 s_bss (int ignore ATTRIBUTE_UNUSED)
2986 {
2987 /* We don't support putting frags in the BSS segment, we fake it by
2988 marking in_bss, then looking at s_skip for clues. */
2989 subseg_set (bss_section, 0);
2990 demand_empty_rest_of_line ();
2991
2992 #ifdef md_elf_section_change_hook
2993 md_elf_section_change_hook ();
2994 #endif
2995 }
2996
2997 static void
2998 s_even (int ignore ATTRIBUTE_UNUSED)
2999 {
3000 /* Never make frag if expect extra pass. */
3001 if (!need_pass_2)
3002 frag_align (1, 0, 0);
3003
3004 record_alignment (now_seg, 1);
3005
3006 demand_empty_rest_of_line ();
3007 }
3008
3009 /* Directives: Literal pools. */
3010
3011 static literal_pool *
3012 find_literal_pool (void)
3013 {
3014 literal_pool * pool;
3015
3016 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3017 {
3018 if (pool->section == now_seg
3019 && pool->sub_section == now_subseg)
3020 break;
3021 }
3022
3023 return pool;
3024 }
3025
3026 static literal_pool *
3027 find_or_make_literal_pool (void)
3028 {
3029 /* Next literal pool ID number. */
3030 static unsigned int latest_pool_num = 1;
3031 literal_pool * pool;
3032
3033 pool = find_literal_pool ();
3034
3035 if (pool == NULL)
3036 {
3037 /* Create a new pool. */
3038 pool = (literal_pool *) xmalloc (sizeof (* pool));
3039 if (! pool)
3040 return NULL;
3041
3042 pool->next_free_entry = 0;
3043 pool->section = now_seg;
3044 pool->sub_section = now_subseg;
3045 pool->next = list_of_pools;
3046 pool->symbol = NULL;
3047
3048 /* Add it to the list. */
3049 list_of_pools = pool;
3050 }
3051
3052 /* New pools, and emptied pools, will have a NULL symbol. */
3053 if (pool->symbol == NULL)
3054 {
3055 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3056 (valueT) 0, &zero_address_frag);
3057 pool->id = latest_pool_num ++;
3058 }
3059
3060 /* Done. */
3061 return pool;
3062 }
3063
3064 /* Add the literal in the global 'inst'
3065 structure to the relevant literal pool. */
3066
3067 static int
3068 add_to_lit_pool (void)
3069 {
3070 literal_pool * pool;
3071 unsigned int entry;
3072
3073 pool = find_or_make_literal_pool ();
3074
3075 /* Check if this literal value is already in the pool. */
3076 for (entry = 0; entry < pool->next_free_entry; entry ++)
3077 {
3078 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3079 && (inst.reloc.exp.X_op == O_constant)
3080 && (pool->literals[entry].X_add_number
3081 == inst.reloc.exp.X_add_number)
3082 && (pool->literals[entry].X_unsigned
3083 == inst.reloc.exp.X_unsigned))
3084 break;
3085
3086 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3087 && (inst.reloc.exp.X_op == O_symbol)
3088 && (pool->literals[entry].X_add_number
3089 == inst.reloc.exp.X_add_number)
3090 && (pool->literals[entry].X_add_symbol
3091 == inst.reloc.exp.X_add_symbol)
3092 && (pool->literals[entry].X_op_symbol
3093 == inst.reloc.exp.X_op_symbol))
3094 break;
3095 }
3096
3097 /* Do we need to create a new entry? */
3098 if (entry == pool->next_free_entry)
3099 {
3100 if (entry >= MAX_LITERAL_POOL_SIZE)
3101 {
3102 inst.error = _("literal pool overflow");
3103 return FAIL;
3104 }
3105
3106 pool->literals[entry] = inst.reloc.exp;
3107 #ifdef OBJ_ELF
3108 /* PR ld/12974: Record the location of the first source line to reference
3109 this entry in the literal pool. If it turns out during linking that the
3110 symbol does not exist we will be able to give an accurate line number for
3111 the (first use of the) missing reference. */
3112 if (debug_type == DEBUG_DWARF2)
3113 dwarf2_where (pool->locs + entry);
3114 #endif
3115 pool->next_free_entry += 1;
3116 }
3117
3118 inst.reloc.exp.X_op = O_symbol;
3119 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3120 inst.reloc.exp.X_add_symbol = pool->symbol;
3121
3122 return SUCCESS;
3123 }
3124
3125 /* Can't use symbol_new here, so have to create a symbol and then at
3126 a later date assign it a value. Thats what these functions do. */
3127
3128 static void
3129 symbol_locate (symbolS * symbolP,
3130 const char * name, /* It is copied, the caller can modify. */
3131 segT segment, /* Segment identifier (SEG_<something>). */
3132 valueT valu, /* Symbol value. */
3133 fragS * frag) /* Associated fragment. */
3134 {
3135 unsigned int name_length;
3136 char * preserved_copy_of_name;
3137
3138 name_length = strlen (name) + 1; /* +1 for \0. */
3139 obstack_grow (&notes, name, name_length);
3140 preserved_copy_of_name = (char *) obstack_finish (&notes);
3141
3142 #ifdef tc_canonicalize_symbol_name
3143 preserved_copy_of_name =
3144 tc_canonicalize_symbol_name (preserved_copy_of_name);
3145 #endif
3146
3147 S_SET_NAME (symbolP, preserved_copy_of_name);
3148
3149 S_SET_SEGMENT (symbolP, segment);
3150 S_SET_VALUE (symbolP, valu);
3151 symbol_clear_list_pointers (symbolP);
3152
3153 symbol_set_frag (symbolP, frag);
3154
3155 /* Link to end of symbol chain. */
3156 {
3157 extern int symbol_table_frozen;
3158
3159 if (symbol_table_frozen)
3160 abort ();
3161 }
3162
3163 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3164
3165 obj_symbol_new_hook (symbolP);
3166
3167 #ifdef tc_symbol_new_hook
3168 tc_symbol_new_hook (symbolP);
3169 #endif
3170
3171 #ifdef DEBUG_SYMS
3172 verify_symbol_chain (symbol_rootP, symbol_lastP);
3173 #endif /* DEBUG_SYMS */
3174 }
3175
3176
3177 static void
3178 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3179 {
3180 unsigned int entry;
3181 literal_pool * pool;
3182 char sym_name[20];
3183
3184 pool = find_literal_pool ();
3185 if (pool == NULL
3186 || pool->symbol == NULL
3187 || pool->next_free_entry == 0)
3188 return;
3189
3190 mapping_state (MAP_DATA);
3191
3192 /* Align pool as you have word accesses.
3193 Only make a frag if we have to. */
3194 if (!need_pass_2)
3195 frag_align (2, 0, 0);
3196
3197 record_alignment (now_seg, 2);
3198
3199 sprintf (sym_name, "$$lit_\002%x", pool->id);
3200
3201 symbol_locate (pool->symbol, sym_name, now_seg,
3202 (valueT) frag_now_fix (), frag_now);
3203 symbol_table_insert (pool->symbol);
3204
3205 ARM_SET_THUMB (pool->symbol, thumb_mode);
3206
3207 #if defined OBJ_COFF || defined OBJ_ELF
3208 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3209 #endif
3210
3211 for (entry = 0; entry < pool->next_free_entry; entry ++)
3212 {
3213 #ifdef OBJ_ELF
3214 if (debug_type == DEBUG_DWARF2)
3215 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3216 #endif
3217 /* First output the expression in the instruction to the pool. */
3218 emit_expr (&(pool->literals[entry]), 4); /* .word */
3219 }
3220
3221 /* Mark the pool as empty. */
3222 pool->next_free_entry = 0;
3223 pool->symbol = NULL;
3224 }
3225
3226 #ifdef OBJ_ELF
3227 /* Forward declarations for functions below, in the MD interface
3228 section. */
3229 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3230 static valueT create_unwind_entry (int);
3231 static void start_unwind_section (const segT, int);
3232 static void add_unwind_opcode (valueT, int);
3233 static void flush_pending_unwind (void);
3234
3235 /* Directives: Data. */
3236
3237 static void
3238 s_arm_elf_cons (int nbytes)
3239 {
3240 expressionS exp;
3241
3242 #ifdef md_flush_pending_output
3243 md_flush_pending_output ();
3244 #endif
3245
3246 if (is_it_end_of_statement ())
3247 {
3248 demand_empty_rest_of_line ();
3249 return;
3250 }
3251
3252 #ifdef md_cons_align
3253 md_cons_align (nbytes);
3254 #endif
3255
3256 mapping_state (MAP_DATA);
3257 do
3258 {
3259 int reloc;
3260 char *base = input_line_pointer;
3261
3262 expression (& exp);
3263
3264 if (exp.X_op != O_symbol)
3265 emit_expr (&exp, (unsigned int) nbytes);
3266 else
3267 {
3268 char *before_reloc = input_line_pointer;
3269 reloc = parse_reloc (&input_line_pointer);
3270 if (reloc == -1)
3271 {
3272 as_bad (_("unrecognized relocation suffix"));
3273 ignore_rest_of_line ();
3274 return;
3275 }
3276 else if (reloc == BFD_RELOC_UNUSED)
3277 emit_expr (&exp, (unsigned int) nbytes);
3278 else
3279 {
3280 reloc_howto_type *howto = (reloc_howto_type *)
3281 bfd_reloc_type_lookup (stdoutput,
3282 (bfd_reloc_code_real_type) reloc);
3283 int size = bfd_get_reloc_size (howto);
3284
3285 if (reloc == BFD_RELOC_ARM_PLT32)
3286 {
3287 as_bad (_("(plt) is only valid on branch targets"));
3288 reloc = BFD_RELOC_UNUSED;
3289 size = 0;
3290 }
3291
3292 if (size > nbytes)
3293 as_bad (_("%s relocations do not fit in %d bytes"),
3294 howto->name, nbytes);
3295 else
3296 {
3297 /* We've parsed an expression stopping at O_symbol.
3298 But there may be more expression left now that we
3299 have parsed the relocation marker. Parse it again.
3300 XXX Surely there is a cleaner way to do this. */
3301 char *p = input_line_pointer;
3302 int offset;
3303 char *save_buf = (char *) alloca (input_line_pointer - base);
3304 memcpy (save_buf, base, input_line_pointer - base);
3305 memmove (base + (input_line_pointer - before_reloc),
3306 base, before_reloc - base);
3307
3308 input_line_pointer = base + (input_line_pointer-before_reloc);
3309 expression (&exp);
3310 memcpy (base, save_buf, p - base);
3311
3312 offset = nbytes - size;
3313 p = frag_more ((int) nbytes);
3314 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3315 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3316 }
3317 }
3318 }
3319 }
3320 while (*input_line_pointer++ == ',');
3321
3322 /* Put terminator back into stream. */
3323 input_line_pointer --;
3324 demand_empty_rest_of_line ();
3325 }
3326
3327 /* Emit an expression containing a 32-bit thumb instruction.
3328 Implementation based on put_thumb32_insn. */
3329
3330 static void
3331 emit_thumb32_expr (expressionS * exp)
3332 {
3333 expressionS exp_high = *exp;
3334
3335 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3336 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3337 exp->X_add_number &= 0xffff;
3338 emit_expr (exp, (unsigned int) THUMB_SIZE);
3339 }
3340
3341 /* Guess the instruction size based on the opcode. */
3342
3343 static int
3344 thumb_insn_size (int opcode)
3345 {
3346 if ((unsigned int) opcode < 0xe800u)
3347 return 2;
3348 else if ((unsigned int) opcode >= 0xe8000000u)
3349 return 4;
3350 else
3351 return 0;
3352 }
3353
3354 static bfd_boolean
3355 emit_insn (expressionS *exp, int nbytes)
3356 {
3357 int size = 0;
3358
3359 if (exp->X_op == O_constant)
3360 {
3361 size = nbytes;
3362
3363 if (size == 0)
3364 size = thumb_insn_size (exp->X_add_number);
3365
3366 if (size != 0)
3367 {
3368 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3369 {
3370 as_bad (_(".inst.n operand too big. "\
3371 "Use .inst.w instead"));
3372 size = 0;
3373 }
3374 else
3375 {
3376 if (now_it.state == AUTOMATIC_IT_BLOCK)
3377 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3378 else
3379 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3380
3381 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3382 emit_thumb32_expr (exp);
3383 else
3384 emit_expr (exp, (unsigned int) size);
3385
3386 it_fsm_post_encode ();
3387 }
3388 }
3389 else
3390 as_bad (_("cannot determine Thumb instruction size. " \
3391 "Use .inst.n/.inst.w instead"));
3392 }
3393 else
3394 as_bad (_("constant expression required"));
3395
3396 return (size != 0);
3397 }
3398
3399 /* Like s_arm_elf_cons but do not use md_cons_align and
3400 set the mapping state to MAP_ARM/MAP_THUMB. */
3401
3402 static void
3403 s_arm_elf_inst (int nbytes)
3404 {
3405 if (is_it_end_of_statement ())
3406 {
3407 demand_empty_rest_of_line ();
3408 return;
3409 }
3410
3411 /* Calling mapping_state () here will not change ARM/THUMB,
3412 but will ensure not to be in DATA state. */
3413
3414 if (thumb_mode)
3415 mapping_state (MAP_THUMB);
3416 else
3417 {
3418 if (nbytes != 0)
3419 {
3420 as_bad (_("width suffixes are invalid in ARM mode"));
3421 ignore_rest_of_line ();
3422 return;
3423 }
3424
3425 nbytes = 4;
3426
3427 mapping_state (MAP_ARM);
3428 }
3429
3430 do
3431 {
3432 expressionS exp;
3433
3434 expression (& exp);
3435
3436 if (! emit_insn (& exp, nbytes))
3437 {
3438 ignore_rest_of_line ();
3439 return;
3440 }
3441 }
3442 while (*input_line_pointer++ == ',');
3443
3444 /* Put terminator back into stream. */
3445 input_line_pointer --;
3446 demand_empty_rest_of_line ();
3447 }
3448
3449 /* Parse a .rel31 directive. */
3450
3451 static void
3452 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3453 {
3454 expressionS exp;
3455 char *p;
3456 valueT highbit;
3457
3458 highbit = 0;
3459 if (*input_line_pointer == '1')
3460 highbit = 0x80000000;
3461 else if (*input_line_pointer != '0')
3462 as_bad (_("expected 0 or 1"));
3463
3464 input_line_pointer++;
3465 if (*input_line_pointer != ',')
3466 as_bad (_("missing comma"));
3467 input_line_pointer++;
3468
3469 #ifdef md_flush_pending_output
3470 md_flush_pending_output ();
3471 #endif
3472
3473 #ifdef md_cons_align
3474 md_cons_align (4);
3475 #endif
3476
3477 mapping_state (MAP_DATA);
3478
3479 expression (&exp);
3480
3481 p = frag_more (4);
3482 md_number_to_chars (p, highbit, 4);
3483 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3484 BFD_RELOC_ARM_PREL31);
3485
3486 demand_empty_rest_of_line ();
3487 }
3488
3489 /* Directives: AEABI stack-unwind tables. */
3490
3491 /* Parse an unwind_fnstart directive. Simply records the current location. */
3492
3493 static void
3494 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3495 {
3496 demand_empty_rest_of_line ();
3497 if (unwind.proc_start)
3498 {
3499 as_bad (_("duplicate .fnstart directive"));
3500 return;
3501 }
3502
3503 /* Mark the start of the function. */
3504 unwind.proc_start = expr_build_dot ();
3505
3506 /* Reset the rest of the unwind info. */
3507 unwind.opcode_count = 0;
3508 unwind.table_entry = NULL;
3509 unwind.personality_routine = NULL;
3510 unwind.personality_index = -1;
3511 unwind.frame_size = 0;
3512 unwind.fp_offset = 0;
3513 unwind.fp_reg = REG_SP;
3514 unwind.fp_used = 0;
3515 unwind.sp_restored = 0;
3516 }
3517
3518
3519 /* Parse a handlerdata directive. Creates the exception handling table entry
3520 for the function. */
3521
3522 static void
3523 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3524 {
3525 demand_empty_rest_of_line ();
3526 if (!unwind.proc_start)
3527 as_bad (MISSING_FNSTART);
3528
3529 if (unwind.table_entry)
3530 as_bad (_("duplicate .handlerdata directive"));
3531
3532 create_unwind_entry (1);
3533 }
3534
3535 /* Parse an unwind_fnend directive. Generates the index table entry. */
3536
3537 static void
3538 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3539 {
3540 long where;
3541 char *ptr;
3542 valueT val;
3543 unsigned int marked_pr_dependency;
3544
3545 demand_empty_rest_of_line ();
3546
3547 if (!unwind.proc_start)
3548 {
3549 as_bad (_(".fnend directive without .fnstart"));
3550 return;
3551 }
3552
3553 /* Add eh table entry. */
3554 if (unwind.table_entry == NULL)
3555 val = create_unwind_entry (0);
3556 else
3557 val = 0;
3558
3559 /* Add index table entry. This is two words. */
3560 start_unwind_section (unwind.saved_seg, 1);
3561 frag_align (2, 0, 0);
3562 record_alignment (now_seg, 2);
3563
3564 ptr = frag_more (8);
3565 memset (ptr, 0, 8);
3566 where = frag_now_fix () - 8;
3567
3568 /* Self relative offset of the function start. */
3569 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3570 BFD_RELOC_ARM_PREL31);
3571
3572 /* Indicate dependency on EHABI-defined personality routines to the
3573 linker, if it hasn't been done already. */
3574 marked_pr_dependency
3575 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3576 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3577 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3578 {
3579 static const char *const name[] =
3580 {
3581 "__aeabi_unwind_cpp_pr0",
3582 "__aeabi_unwind_cpp_pr1",
3583 "__aeabi_unwind_cpp_pr2"
3584 };
3585 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3586 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3587 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3588 |= 1 << unwind.personality_index;
3589 }
3590
3591 if (val)
3592 /* Inline exception table entry. */
3593 md_number_to_chars (ptr + 4, val, 4);
3594 else
3595 /* Self relative offset of the table entry. */
3596 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3597 BFD_RELOC_ARM_PREL31);
3598
3599 /* Restore the original section. */
3600 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3601
3602 unwind.proc_start = NULL;
3603 }
3604
3605
3606 /* Parse an unwind_cantunwind directive. */
3607
3608 static void
3609 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3610 {
3611 demand_empty_rest_of_line ();
3612 if (!unwind.proc_start)
3613 as_bad (MISSING_FNSTART);
3614
3615 if (unwind.personality_routine || unwind.personality_index != -1)
3616 as_bad (_("personality routine specified for cantunwind frame"));
3617
3618 unwind.personality_index = -2;
3619 }
3620
3621
3622 /* Parse a personalityindex directive. */
3623
3624 static void
3625 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3626 {
3627 expressionS exp;
3628
3629 if (!unwind.proc_start)
3630 as_bad (MISSING_FNSTART);
3631
3632 if (unwind.personality_routine || unwind.personality_index != -1)
3633 as_bad (_("duplicate .personalityindex directive"));
3634
3635 expression (&exp);
3636
3637 if (exp.X_op != O_constant
3638 || exp.X_add_number < 0 || exp.X_add_number > 15)
3639 {
3640 as_bad (_("bad personality routine number"));
3641 ignore_rest_of_line ();
3642 return;
3643 }
3644
3645 unwind.personality_index = exp.X_add_number;
3646
3647 demand_empty_rest_of_line ();
3648 }
3649
3650
3651 /* Parse a personality directive. */
3652
3653 static void
3654 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3655 {
3656 char *name, *p, c;
3657
3658 if (!unwind.proc_start)
3659 as_bad (MISSING_FNSTART);
3660
3661 if (unwind.personality_routine || unwind.personality_index != -1)
3662 as_bad (_("duplicate .personality directive"));
3663
3664 name = input_line_pointer;
3665 c = get_symbol_end ();
3666 p = input_line_pointer;
3667 unwind.personality_routine = symbol_find_or_make (name);
3668 *p = c;
3669 demand_empty_rest_of_line ();
3670 }
3671
3672
3673 /* Parse a directive saving core registers. */
3674
3675 static void
3676 s_arm_unwind_save_core (void)
3677 {
3678 valueT op;
3679 long range;
3680 int n;
3681
3682 range = parse_reg_list (&input_line_pointer);
3683 if (range == FAIL)
3684 {
3685 as_bad (_("expected register list"));
3686 ignore_rest_of_line ();
3687 return;
3688 }
3689
3690 demand_empty_rest_of_line ();
3691
3692 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3693 into .unwind_save {..., sp...}. We aren't bothered about the value of
3694 ip because it is clobbered by calls. */
3695 if (unwind.sp_restored && unwind.fp_reg == 12
3696 && (range & 0x3000) == 0x1000)
3697 {
3698 unwind.opcode_count--;
3699 unwind.sp_restored = 0;
3700 range = (range | 0x2000) & ~0x1000;
3701 unwind.pending_offset = 0;
3702 }
3703
3704 /* Pop r4-r15. */
3705 if (range & 0xfff0)
3706 {
3707 /* See if we can use the short opcodes. These pop a block of up to 8
3708 registers starting with r4, plus maybe r14. */
3709 for (n = 0; n < 8; n++)
3710 {
3711 /* Break at the first non-saved register. */
3712 if ((range & (1 << (n + 4))) == 0)
3713 break;
3714 }
3715 /* See if there are any other bits set. */
3716 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3717 {
3718 /* Use the long form. */
3719 op = 0x8000 | ((range >> 4) & 0xfff);
3720 add_unwind_opcode (op, 2);
3721 }
3722 else
3723 {
3724 /* Use the short form. */
3725 if (range & 0x4000)
3726 op = 0xa8; /* Pop r14. */
3727 else
3728 op = 0xa0; /* Do not pop r14. */
3729 op |= (n - 1);
3730 add_unwind_opcode (op, 1);
3731 }
3732 }
3733
3734 /* Pop r0-r3. */
3735 if (range & 0xf)
3736 {
3737 op = 0xb100 | (range & 0xf);
3738 add_unwind_opcode (op, 2);
3739 }
3740
3741 /* Record the number of bytes pushed. */
3742 for (n = 0; n < 16; n++)
3743 {
3744 if (range & (1 << n))
3745 unwind.frame_size += 4;
3746 }
3747 }
3748
3749
3750 /* Parse a directive saving FPA registers. */
3751
3752 static void
3753 s_arm_unwind_save_fpa (int reg)
3754 {
3755 expressionS exp;
3756 int num_regs;
3757 valueT op;
3758
3759 /* Get Number of registers to transfer. */
3760 if (skip_past_comma (&input_line_pointer) != FAIL)
3761 expression (&exp);
3762 else
3763 exp.X_op = O_illegal;
3764
3765 if (exp.X_op != O_constant)
3766 {
3767 as_bad (_("expected , <constant>"));
3768 ignore_rest_of_line ();
3769 return;
3770 }
3771
3772 num_regs = exp.X_add_number;
3773
3774 if (num_regs < 1 || num_regs > 4)
3775 {
3776 as_bad (_("number of registers must be in the range [1:4]"));
3777 ignore_rest_of_line ();
3778 return;
3779 }
3780
3781 demand_empty_rest_of_line ();
3782
3783 if (reg == 4)
3784 {
3785 /* Short form. */
3786 op = 0xb4 | (num_regs - 1);
3787 add_unwind_opcode (op, 1);
3788 }
3789 else
3790 {
3791 /* Long form. */
3792 op = 0xc800 | (reg << 4) | (num_regs - 1);
3793 add_unwind_opcode (op, 2);
3794 }
3795 unwind.frame_size += num_regs * 12;
3796 }
3797
3798
3799 /* Parse a directive saving VFP registers for ARMv6 and above. */
3800
3801 static void
3802 s_arm_unwind_save_vfp_armv6 (void)
3803 {
3804 int count;
3805 unsigned int start;
3806 valueT op;
3807 int num_vfpv3_regs = 0;
3808 int num_regs_below_16;
3809
3810 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3811 if (count == FAIL)
3812 {
3813 as_bad (_("expected register list"));
3814 ignore_rest_of_line ();
3815 return;
3816 }
3817
3818 demand_empty_rest_of_line ();
3819
3820 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3821 than FSTMX/FLDMX-style ones). */
3822
3823 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3824 if (start >= 16)
3825 num_vfpv3_regs = count;
3826 else if (start + count > 16)
3827 num_vfpv3_regs = start + count - 16;
3828
3829 if (num_vfpv3_regs > 0)
3830 {
3831 int start_offset = start > 16 ? start - 16 : 0;
3832 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3833 add_unwind_opcode (op, 2);
3834 }
3835
3836 /* Generate opcode for registers numbered in the range 0 .. 15. */
3837 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3838 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3839 if (num_regs_below_16 > 0)
3840 {
3841 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3842 add_unwind_opcode (op, 2);
3843 }
3844
3845 unwind.frame_size += count * 8;
3846 }
3847
3848
3849 /* Parse a directive saving VFP registers for pre-ARMv6. */
3850
3851 static void
3852 s_arm_unwind_save_vfp (void)
3853 {
3854 int count;
3855 unsigned int reg;
3856 valueT op;
3857
3858 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3859 if (count == FAIL)
3860 {
3861 as_bad (_("expected register list"));
3862 ignore_rest_of_line ();
3863 return;
3864 }
3865
3866 demand_empty_rest_of_line ();
3867
3868 if (reg == 8)
3869 {
3870 /* Short form. */
3871 op = 0xb8 | (count - 1);
3872 add_unwind_opcode (op, 1);
3873 }
3874 else
3875 {
3876 /* Long form. */
3877 op = 0xb300 | (reg << 4) | (count - 1);
3878 add_unwind_opcode (op, 2);
3879 }
3880 unwind.frame_size += count * 8 + 4;
3881 }
3882
3883
3884 /* Parse a directive saving iWMMXt data registers. */
3885
3886 static void
3887 s_arm_unwind_save_mmxwr (void)
3888 {
3889 int reg;
3890 int hi_reg;
3891 int i;
3892 unsigned mask = 0;
3893 valueT op;
3894
3895 if (*input_line_pointer == '{')
3896 input_line_pointer++;
3897
3898 do
3899 {
3900 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3901
3902 if (reg == FAIL)
3903 {
3904 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3905 goto error;
3906 }
3907
3908 if (mask >> reg)
3909 as_tsktsk (_("register list not in ascending order"));
3910 mask |= 1 << reg;
3911
3912 if (*input_line_pointer == '-')
3913 {
3914 input_line_pointer++;
3915 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3916 if (hi_reg == FAIL)
3917 {
3918 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3919 goto error;
3920 }
3921 else if (reg >= hi_reg)
3922 {
3923 as_bad (_("bad register range"));
3924 goto error;
3925 }
3926 for (; reg < hi_reg; reg++)
3927 mask |= 1 << reg;
3928 }
3929 }
3930 while (skip_past_comma (&input_line_pointer) != FAIL);
3931
3932 if (*input_line_pointer == '}')
3933 input_line_pointer++;
3934
3935 demand_empty_rest_of_line ();
3936
3937 /* Generate any deferred opcodes because we're going to be looking at
3938 the list. */
3939 flush_pending_unwind ();
3940
3941 for (i = 0; i < 16; i++)
3942 {
3943 if (mask & (1 << i))
3944 unwind.frame_size += 8;
3945 }
3946
3947 /* Attempt to combine with a previous opcode. We do this because gcc
3948 likes to output separate unwind directives for a single block of
3949 registers. */
3950 if (unwind.opcode_count > 0)
3951 {
3952 i = unwind.opcodes[unwind.opcode_count - 1];
3953 if ((i & 0xf8) == 0xc0)
3954 {
3955 i &= 7;
3956 /* Only merge if the blocks are contiguous. */
3957 if (i < 6)
3958 {
3959 if ((mask & 0xfe00) == (1 << 9))
3960 {
3961 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3962 unwind.opcode_count--;
3963 }
3964 }
3965 else if (i == 6 && unwind.opcode_count >= 2)
3966 {
3967 i = unwind.opcodes[unwind.opcode_count - 2];
3968 reg = i >> 4;
3969 i &= 0xf;
3970
3971 op = 0xffff << (reg - 1);
3972 if (reg > 0
3973 && ((mask & op) == (1u << (reg - 1))))
3974 {
3975 op = (1 << (reg + i + 1)) - 1;
3976 op &= ~((1 << reg) - 1);
3977 mask |= op;
3978 unwind.opcode_count -= 2;
3979 }
3980 }
3981 }
3982 }
3983
3984 hi_reg = 15;
3985 /* We want to generate opcodes in the order the registers have been
3986 saved, ie. descending order. */
3987 for (reg = 15; reg >= -1; reg--)
3988 {
3989 /* Save registers in blocks. */
3990 if (reg < 0
3991 || !(mask & (1 << reg)))
3992 {
3993 /* We found an unsaved reg. Generate opcodes to save the
3994 preceding block. */
3995 if (reg != hi_reg)
3996 {
3997 if (reg == 9)
3998 {
3999 /* Short form. */
4000 op = 0xc0 | (hi_reg - 10);
4001 add_unwind_opcode (op, 1);
4002 }
4003 else
4004 {
4005 /* Long form. */
4006 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4007 add_unwind_opcode (op, 2);
4008 }
4009 }
4010 hi_reg = reg - 1;
4011 }
4012 }
4013
4014 return;
4015 error:
4016 ignore_rest_of_line ();
4017 }
4018
4019 static void
4020 s_arm_unwind_save_mmxwcg (void)
4021 {
4022 int reg;
4023 int hi_reg;
4024 unsigned mask = 0;
4025 valueT op;
4026
4027 if (*input_line_pointer == '{')
4028 input_line_pointer++;
4029
4030 do
4031 {
4032 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4033
4034 if (reg == FAIL)
4035 {
4036 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4037 goto error;
4038 }
4039
4040 reg -= 8;
4041 if (mask >> reg)
4042 as_tsktsk (_("register list not in ascending order"));
4043 mask |= 1 << reg;
4044
4045 if (*input_line_pointer == '-')
4046 {
4047 input_line_pointer++;
4048 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4049 if (hi_reg == FAIL)
4050 {
4051 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4052 goto error;
4053 }
4054 else if (reg >= hi_reg)
4055 {
4056 as_bad (_("bad register range"));
4057 goto error;
4058 }
4059 for (; reg < hi_reg; reg++)
4060 mask |= 1 << reg;
4061 }
4062 }
4063 while (skip_past_comma (&input_line_pointer) != FAIL);
4064
4065 if (*input_line_pointer == '}')
4066 input_line_pointer++;
4067
4068 demand_empty_rest_of_line ();
4069
4070 /* Generate any deferred opcodes because we're going to be looking at
4071 the list. */
4072 flush_pending_unwind ();
4073
4074 for (reg = 0; reg < 16; reg++)
4075 {
4076 if (mask & (1 << reg))
4077 unwind.frame_size += 4;
4078 }
4079 op = 0xc700 | mask;
4080 add_unwind_opcode (op, 2);
4081 return;
4082 error:
4083 ignore_rest_of_line ();
4084 }
4085
4086
4087 /* Parse an unwind_save directive.
4088 If the argument is non-zero, this is a .vsave directive. */
4089
4090 static void
4091 s_arm_unwind_save (int arch_v6)
4092 {
4093 char *peek;
4094 struct reg_entry *reg;
4095 bfd_boolean had_brace = FALSE;
4096
4097 if (!unwind.proc_start)
4098 as_bad (MISSING_FNSTART);
4099
4100 /* Figure out what sort of save we have. */
4101 peek = input_line_pointer;
4102
4103 if (*peek == '{')
4104 {
4105 had_brace = TRUE;
4106 peek++;
4107 }
4108
4109 reg = arm_reg_parse_multi (&peek);
4110
4111 if (!reg)
4112 {
4113 as_bad (_("register expected"));
4114 ignore_rest_of_line ();
4115 return;
4116 }
4117
4118 switch (reg->type)
4119 {
4120 case REG_TYPE_FN:
4121 if (had_brace)
4122 {
4123 as_bad (_("FPA .unwind_save does not take a register list"));
4124 ignore_rest_of_line ();
4125 return;
4126 }
4127 input_line_pointer = peek;
4128 s_arm_unwind_save_fpa (reg->number);
4129 return;
4130
4131 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4132 case REG_TYPE_VFD:
4133 if (arch_v6)
4134 s_arm_unwind_save_vfp_armv6 ();
4135 else
4136 s_arm_unwind_save_vfp ();
4137 return;
4138 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4139 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4140
4141 default:
4142 as_bad (_(".unwind_save does not support this kind of register"));
4143 ignore_rest_of_line ();
4144 }
4145 }
4146
4147
4148 /* Parse an unwind_movsp directive. */
4149
4150 static void
4151 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4152 {
4153 int reg;
4154 valueT op;
4155 int offset;
4156
4157 if (!unwind.proc_start)
4158 as_bad (MISSING_FNSTART);
4159
4160 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4161 if (reg == FAIL)
4162 {
4163 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4164 ignore_rest_of_line ();
4165 return;
4166 }
4167
4168 /* Optional constant. */
4169 if (skip_past_comma (&input_line_pointer) != FAIL)
4170 {
4171 if (immediate_for_directive (&offset) == FAIL)
4172 return;
4173 }
4174 else
4175 offset = 0;
4176
4177 demand_empty_rest_of_line ();
4178
4179 if (reg == REG_SP || reg == REG_PC)
4180 {
4181 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4182 return;
4183 }
4184
4185 if (unwind.fp_reg != REG_SP)
4186 as_bad (_("unexpected .unwind_movsp directive"));
4187
4188 /* Generate opcode to restore the value. */
4189 op = 0x90 | reg;
4190 add_unwind_opcode (op, 1);
4191
4192 /* Record the information for later. */
4193 unwind.fp_reg = reg;
4194 unwind.fp_offset = unwind.frame_size - offset;
4195 unwind.sp_restored = 1;
4196 }
4197
4198 /* Parse an unwind_pad directive. */
4199
4200 static void
4201 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4202 {
4203 int offset;
4204
4205 if (!unwind.proc_start)
4206 as_bad (MISSING_FNSTART);
4207
4208 if (immediate_for_directive (&offset) == FAIL)
4209 return;
4210
4211 if (offset & 3)
4212 {
4213 as_bad (_("stack increment must be multiple of 4"));
4214 ignore_rest_of_line ();
4215 return;
4216 }
4217
4218 /* Don't generate any opcodes, just record the details for later. */
4219 unwind.frame_size += offset;
4220 unwind.pending_offset += offset;
4221
4222 demand_empty_rest_of_line ();
4223 }
4224
4225 /* Parse an unwind_setfp directive. */
4226
4227 static void
4228 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4229 {
4230 int sp_reg;
4231 int fp_reg;
4232 int offset;
4233
4234 if (!unwind.proc_start)
4235 as_bad (MISSING_FNSTART);
4236
4237 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4238 if (skip_past_comma (&input_line_pointer) == FAIL)
4239 sp_reg = FAIL;
4240 else
4241 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4242
4243 if (fp_reg == FAIL || sp_reg == FAIL)
4244 {
4245 as_bad (_("expected <reg>, <reg>"));
4246 ignore_rest_of_line ();
4247 return;
4248 }
4249
4250 /* Optional constant. */
4251 if (skip_past_comma (&input_line_pointer) != FAIL)
4252 {
4253 if (immediate_for_directive (&offset) == FAIL)
4254 return;
4255 }
4256 else
4257 offset = 0;
4258
4259 demand_empty_rest_of_line ();
4260
4261 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4262 {
4263 as_bad (_("register must be either sp or set by a previous"
4264 "unwind_movsp directive"));
4265 return;
4266 }
4267
4268 /* Don't generate any opcodes, just record the information for later. */
4269 unwind.fp_reg = fp_reg;
4270 unwind.fp_used = 1;
4271 if (sp_reg == REG_SP)
4272 unwind.fp_offset = unwind.frame_size - offset;
4273 else
4274 unwind.fp_offset -= offset;
4275 }
4276
4277 /* Parse an unwind_raw directive. */
4278
4279 static void
4280 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4281 {
4282 expressionS exp;
4283 /* This is an arbitrary limit. */
4284 unsigned char op[16];
4285 int count;
4286
4287 if (!unwind.proc_start)
4288 as_bad (MISSING_FNSTART);
4289
4290 expression (&exp);
4291 if (exp.X_op == O_constant
4292 && skip_past_comma (&input_line_pointer) != FAIL)
4293 {
4294 unwind.frame_size += exp.X_add_number;
4295 expression (&exp);
4296 }
4297 else
4298 exp.X_op = O_illegal;
4299
4300 if (exp.X_op != O_constant)
4301 {
4302 as_bad (_("expected <offset>, <opcode>"));
4303 ignore_rest_of_line ();
4304 return;
4305 }
4306
4307 count = 0;
4308
4309 /* Parse the opcode. */
4310 for (;;)
4311 {
4312 if (count >= 16)
4313 {
4314 as_bad (_("unwind opcode too long"));
4315 ignore_rest_of_line ();
4316 }
4317 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4318 {
4319 as_bad (_("invalid unwind opcode"));
4320 ignore_rest_of_line ();
4321 return;
4322 }
4323 op[count++] = exp.X_add_number;
4324
4325 /* Parse the next byte. */
4326 if (skip_past_comma (&input_line_pointer) == FAIL)
4327 break;
4328
4329 expression (&exp);
4330 }
4331
4332 /* Add the opcode bytes in reverse order. */
4333 while (count--)
4334 add_unwind_opcode (op[count], 1);
4335
4336 demand_empty_rest_of_line ();
4337 }
4338
4339
4340 /* Parse a .eabi_attribute directive. */
4341
4342 static void
4343 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4344 {
4345 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4346
4347 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4348 attributes_set_explicitly[tag] = 1;
4349 }
4350
4351 /* Emit a tls fix for the symbol. */
4352
4353 static void
4354 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4355 {
4356 char *p;
4357 expressionS exp;
4358 #ifdef md_flush_pending_output
4359 md_flush_pending_output ();
4360 #endif
4361
4362 #ifdef md_cons_align
4363 md_cons_align (4);
4364 #endif
4365
4366 /* Since we're just labelling the code, there's no need to define a
4367 mapping symbol. */
4368 expression (&exp);
4369 p = obstack_next_free (&frchain_now->frch_obstack);
4370 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4371 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4372 : BFD_RELOC_ARM_TLS_DESCSEQ);
4373 }
4374 #endif /* OBJ_ELF */
4375
4376 static void s_arm_arch (int);
4377 static void s_arm_object_arch (int);
4378 static void s_arm_cpu (int);
4379 static void s_arm_fpu (int);
4380 static void s_arm_arch_extension (int);
4381
4382 #ifdef TE_PE
4383
4384 static void
4385 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4386 {
4387 expressionS exp;
4388
4389 do
4390 {
4391 expression (&exp);
4392 if (exp.X_op == O_symbol)
4393 exp.X_op = O_secrel;
4394
4395 emit_expr (&exp, 4);
4396 }
4397 while (*input_line_pointer++ == ',');
4398
4399 input_line_pointer--;
4400 demand_empty_rest_of_line ();
4401 }
4402 #endif /* TE_PE */
4403
4404 /* This table describes all the machine specific pseudo-ops the assembler
4405 has to support. The fields are:
4406 pseudo-op name without dot
4407 function to call to execute this pseudo-op
4408 Integer arg to pass to the function. */
4409
4410 const pseudo_typeS md_pseudo_table[] =
4411 {
4412 /* Never called because '.req' does not start a line. */
4413 { "req", s_req, 0 },
4414 /* Following two are likewise never called. */
4415 { "dn", s_dn, 0 },
4416 { "qn", s_qn, 0 },
4417 { "unreq", s_unreq, 0 },
4418 { "bss", s_bss, 0 },
4419 { "align", s_align, 0 },
4420 { "arm", s_arm, 0 },
4421 { "thumb", s_thumb, 0 },
4422 { "code", s_code, 0 },
4423 { "force_thumb", s_force_thumb, 0 },
4424 { "thumb_func", s_thumb_func, 0 },
4425 { "thumb_set", s_thumb_set, 0 },
4426 { "even", s_even, 0 },
4427 { "ltorg", s_ltorg, 0 },
4428 { "pool", s_ltorg, 0 },
4429 { "syntax", s_syntax, 0 },
4430 { "cpu", s_arm_cpu, 0 },
4431 { "arch", s_arm_arch, 0 },
4432 { "object_arch", s_arm_object_arch, 0 },
4433 { "fpu", s_arm_fpu, 0 },
4434 { "arch_extension", s_arm_arch_extension, 0 },
4435 #ifdef OBJ_ELF
4436 { "word", s_arm_elf_cons, 4 },
4437 { "long", s_arm_elf_cons, 4 },
4438 { "inst.n", s_arm_elf_inst, 2 },
4439 { "inst.w", s_arm_elf_inst, 4 },
4440 { "inst", s_arm_elf_inst, 0 },
4441 { "rel31", s_arm_rel31, 0 },
4442 { "fnstart", s_arm_unwind_fnstart, 0 },
4443 { "fnend", s_arm_unwind_fnend, 0 },
4444 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4445 { "personality", s_arm_unwind_personality, 0 },
4446 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4447 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4448 { "save", s_arm_unwind_save, 0 },
4449 { "vsave", s_arm_unwind_save, 1 },
4450 { "movsp", s_arm_unwind_movsp, 0 },
4451 { "pad", s_arm_unwind_pad, 0 },
4452 { "setfp", s_arm_unwind_setfp, 0 },
4453 { "unwind_raw", s_arm_unwind_raw, 0 },
4454 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4455 { "tlsdescseq", s_arm_tls_descseq, 0 },
4456 #else
4457 { "word", cons, 4},
4458
4459 /* These are used for dwarf. */
4460 {"2byte", cons, 2},
4461 {"4byte", cons, 4},
4462 {"8byte", cons, 8},
4463 /* These are used for dwarf2. */
4464 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4465 { "loc", dwarf2_directive_loc, 0 },
4466 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4467 #endif
4468 { "extend", float_cons, 'x' },
4469 { "ldouble", float_cons, 'x' },
4470 { "packed", float_cons, 'p' },
4471 #ifdef TE_PE
4472 {"secrel32", pe_directive_secrel, 0},
4473 #endif
4474 { 0, 0, 0 }
4475 };
4476 \f
4477 /* Parser functions used exclusively in instruction operands. */
4478
4479 /* Generic immediate-value read function for use in insn parsing.
4480 STR points to the beginning of the immediate (the leading #);
4481 VAL receives the value; if the value is outside [MIN, MAX]
4482 issue an error. PREFIX_OPT is true if the immediate prefix is
4483 optional. */
4484
4485 static int
4486 parse_immediate (char **str, int *val, int min, int max,
4487 bfd_boolean prefix_opt)
4488 {
4489 expressionS exp;
4490 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4491 if (exp.X_op != O_constant)
4492 {
4493 inst.error = _("constant expression required");
4494 return FAIL;
4495 }
4496
4497 if (exp.X_add_number < min || exp.X_add_number > max)
4498 {
4499 inst.error = _("immediate value out of range");
4500 return FAIL;
4501 }
4502
4503 *val = exp.X_add_number;
4504 return SUCCESS;
4505 }
4506
4507 /* Less-generic immediate-value read function with the possibility of loading a
4508 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4509 instructions. Puts the result directly in inst.operands[i]. */
4510
4511 static int
4512 parse_big_immediate (char **str, int i)
4513 {
4514 expressionS exp;
4515 char *ptr = *str;
4516
4517 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4518
4519 if (exp.X_op == O_constant)
4520 {
4521 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4522 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4523 O_constant. We have to be careful not to break compilation for
4524 32-bit X_add_number, though. */
4525 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4526 {
4527 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4528 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4529 inst.operands[i].regisimm = 1;
4530 }
4531 }
4532 else if (exp.X_op == O_big
4533 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
4534 {
4535 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4536
4537 /* Bignums have their least significant bits in
4538 generic_bignum[0]. Make sure we put 32 bits in imm and
4539 32 bits in reg, in a (hopefully) portable way. */
4540 gas_assert (parts != 0);
4541
4542 /* Make sure that the number is not too big.
4543 PR 11972: Bignums can now be sign-extended to the
4544 size of a .octa so check that the out of range bits
4545 are all zero or all one. */
4546 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4547 {
4548 LITTLENUM_TYPE m = -1;
4549
4550 if (generic_bignum[parts * 2] != 0
4551 && generic_bignum[parts * 2] != m)
4552 return FAIL;
4553
4554 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4555 if (generic_bignum[j] != generic_bignum[j-1])
4556 return FAIL;
4557 }
4558
4559 inst.operands[i].imm = 0;
4560 for (j = 0; j < parts; j++, idx++)
4561 inst.operands[i].imm |= generic_bignum[idx]
4562 << (LITTLENUM_NUMBER_OF_BITS * j);
4563 inst.operands[i].reg = 0;
4564 for (j = 0; j < parts; j++, idx++)
4565 inst.operands[i].reg |= generic_bignum[idx]
4566 << (LITTLENUM_NUMBER_OF_BITS * j);
4567 inst.operands[i].regisimm = 1;
4568 }
4569 else
4570 return FAIL;
4571
4572 *str = ptr;
4573
4574 return SUCCESS;
4575 }
4576
4577 /* Returns the pseudo-register number of an FPA immediate constant,
4578 or FAIL if there isn't a valid constant here. */
4579
4580 static int
4581 parse_fpa_immediate (char ** str)
4582 {
4583 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4584 char * save_in;
4585 expressionS exp;
4586 int i;
4587 int j;
4588
4589 /* First try and match exact strings, this is to guarantee
4590 that some formats will work even for cross assembly. */
4591
4592 for (i = 0; fp_const[i]; i++)
4593 {
4594 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4595 {
4596 char *start = *str;
4597
4598 *str += strlen (fp_const[i]);
4599 if (is_end_of_line[(unsigned char) **str])
4600 return i + 8;
4601 *str = start;
4602 }
4603 }
4604
4605 /* Just because we didn't get a match doesn't mean that the constant
4606 isn't valid, just that it is in a format that we don't
4607 automatically recognize. Try parsing it with the standard
4608 expression routines. */
4609
4610 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4611
4612 /* Look for a raw floating point number. */
4613 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4614 && is_end_of_line[(unsigned char) *save_in])
4615 {
4616 for (i = 0; i < NUM_FLOAT_VALS; i++)
4617 {
4618 for (j = 0; j < MAX_LITTLENUMS; j++)
4619 {
4620 if (words[j] != fp_values[i][j])
4621 break;
4622 }
4623
4624 if (j == MAX_LITTLENUMS)
4625 {
4626 *str = save_in;
4627 return i + 8;
4628 }
4629 }
4630 }
4631
4632 /* Try and parse a more complex expression, this will probably fail
4633 unless the code uses a floating point prefix (eg "0f"). */
4634 save_in = input_line_pointer;
4635 input_line_pointer = *str;
4636 if (expression (&exp) == absolute_section
4637 && exp.X_op == O_big
4638 && exp.X_add_number < 0)
4639 {
4640 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4641 Ditto for 15. */
4642 if (gen_to_words (words, 5, (long) 15) == 0)
4643 {
4644 for (i = 0; i < NUM_FLOAT_VALS; i++)
4645 {
4646 for (j = 0; j < MAX_LITTLENUMS; j++)
4647 {
4648 if (words[j] != fp_values[i][j])
4649 break;
4650 }
4651
4652 if (j == MAX_LITTLENUMS)
4653 {
4654 *str = input_line_pointer;
4655 input_line_pointer = save_in;
4656 return i + 8;
4657 }
4658 }
4659 }
4660 }
4661
4662 *str = input_line_pointer;
4663 input_line_pointer = save_in;
4664 inst.error = _("invalid FPA immediate expression");
4665 return FAIL;
4666 }
4667
4668 /* Returns 1 if a number has "quarter-precision" float format
4669 0baBbbbbbc defgh000 00000000 00000000. */
4670
4671 static int
4672 is_quarter_float (unsigned imm)
4673 {
4674 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4675 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4676 }
4677
4678 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4679 0baBbbbbbc defgh000 00000000 00000000.
4680 The zero and minus-zero cases need special handling, since they can't be
4681 encoded in the "quarter-precision" float format, but can nonetheless be
4682 loaded as integer constants. */
4683
4684 static unsigned
4685 parse_qfloat_immediate (char **ccp, int *immed)
4686 {
4687 char *str = *ccp;
4688 char *fpnum;
4689 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4690 int found_fpchar = 0;
4691
4692 skip_past_char (&str, '#');
4693
4694 /* We must not accidentally parse an integer as a floating-point number. Make
4695 sure that the value we parse is not an integer by checking for special
4696 characters '.' or 'e'.
4697 FIXME: This is a horrible hack, but doing better is tricky because type
4698 information isn't in a very usable state at parse time. */
4699 fpnum = str;
4700 skip_whitespace (fpnum);
4701
4702 if (strncmp (fpnum, "0x", 2) == 0)
4703 return FAIL;
4704 else
4705 {
4706 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4707 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4708 {
4709 found_fpchar = 1;
4710 break;
4711 }
4712
4713 if (!found_fpchar)
4714 return FAIL;
4715 }
4716
4717 if ((str = atof_ieee (str, 's', words)) != NULL)
4718 {
4719 unsigned fpword = 0;
4720 int i;
4721
4722 /* Our FP word must be 32 bits (single-precision FP). */
4723 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4724 {
4725 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4726 fpword |= words[i];
4727 }
4728
4729 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4730 *immed = fpword;
4731 else
4732 return FAIL;
4733
4734 *ccp = str;
4735
4736 return SUCCESS;
4737 }
4738
4739 return FAIL;
4740 }
4741
4742 /* Shift operands. */
4743 enum shift_kind
4744 {
4745 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4746 };
4747
4748 struct asm_shift_name
4749 {
4750 const char *name;
4751 enum shift_kind kind;
4752 };
4753
4754 /* Third argument to parse_shift. */
4755 enum parse_shift_mode
4756 {
4757 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4758 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4759 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4760 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4761 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4762 };
4763
4764 /* Parse a <shift> specifier on an ARM data processing instruction.
4765 This has three forms:
4766
4767 (LSL|LSR|ASL|ASR|ROR) Rs
4768 (LSL|LSR|ASL|ASR|ROR) #imm
4769 RRX
4770
4771 Note that ASL is assimilated to LSL in the instruction encoding, and
4772 RRX to ROR #0 (which cannot be written as such). */
4773
4774 static int
4775 parse_shift (char **str, int i, enum parse_shift_mode mode)
4776 {
4777 const struct asm_shift_name *shift_name;
4778 enum shift_kind shift;
4779 char *s = *str;
4780 char *p = s;
4781 int reg;
4782
4783 for (p = *str; ISALPHA (*p); p++)
4784 ;
4785
4786 if (p == *str)
4787 {
4788 inst.error = _("shift expression expected");
4789 return FAIL;
4790 }
4791
4792 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4793 p - *str);
4794
4795 if (shift_name == NULL)
4796 {
4797 inst.error = _("shift expression expected");
4798 return FAIL;
4799 }
4800
4801 shift = shift_name->kind;
4802
4803 switch (mode)
4804 {
4805 case NO_SHIFT_RESTRICT:
4806 case SHIFT_IMMEDIATE: break;
4807
4808 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4809 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4810 {
4811 inst.error = _("'LSL' or 'ASR' required");
4812 return FAIL;
4813 }
4814 break;
4815
4816 case SHIFT_LSL_IMMEDIATE:
4817 if (shift != SHIFT_LSL)
4818 {
4819 inst.error = _("'LSL' required");
4820 return FAIL;
4821 }
4822 break;
4823
4824 case SHIFT_ASR_IMMEDIATE:
4825 if (shift != SHIFT_ASR)
4826 {
4827 inst.error = _("'ASR' required");
4828 return FAIL;
4829 }
4830 break;
4831
4832 default: abort ();
4833 }
4834
4835 if (shift != SHIFT_RRX)
4836 {
4837 /* Whitespace can appear here if the next thing is a bare digit. */
4838 skip_whitespace (p);
4839
4840 if (mode == NO_SHIFT_RESTRICT
4841 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4842 {
4843 inst.operands[i].imm = reg;
4844 inst.operands[i].immisreg = 1;
4845 }
4846 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4847 return FAIL;
4848 }
4849 inst.operands[i].shift_kind = shift;
4850 inst.operands[i].shifted = 1;
4851 *str = p;
4852 return SUCCESS;
4853 }
4854
4855 /* Parse a <shifter_operand> for an ARM data processing instruction:
4856
4857 #<immediate>
4858 #<immediate>, <rotate>
4859 <Rm>
4860 <Rm>, <shift>
4861
4862 where <shift> is defined by parse_shift above, and <rotate> is a
4863 multiple of 2 between 0 and 30. Validation of immediate operands
4864 is deferred to md_apply_fix. */
4865
4866 static int
4867 parse_shifter_operand (char **str, int i)
4868 {
4869 int value;
4870 expressionS exp;
4871
4872 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4873 {
4874 inst.operands[i].reg = value;
4875 inst.operands[i].isreg = 1;
4876
4877 /* parse_shift will override this if appropriate */
4878 inst.reloc.exp.X_op = O_constant;
4879 inst.reloc.exp.X_add_number = 0;
4880
4881 if (skip_past_comma (str) == FAIL)
4882 return SUCCESS;
4883
4884 /* Shift operation on register. */
4885 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4886 }
4887
4888 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4889 return FAIL;
4890
4891 if (skip_past_comma (str) == SUCCESS)
4892 {
4893 /* #x, y -- ie explicit rotation by Y. */
4894 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4895 return FAIL;
4896
4897 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4898 {
4899 inst.error = _("constant expression expected");
4900 return FAIL;
4901 }
4902
4903 value = exp.X_add_number;
4904 if (value < 0 || value > 30 || value % 2 != 0)
4905 {
4906 inst.error = _("invalid rotation");
4907 return FAIL;
4908 }
4909 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4910 {
4911 inst.error = _("invalid constant");
4912 return FAIL;
4913 }
4914
4915 /* Encode as specified. */
4916 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4917 return SUCCESS;
4918 }
4919
4920 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4921 inst.reloc.pc_rel = 0;
4922 return SUCCESS;
4923 }
4924
4925 /* Group relocation information. Each entry in the table contains the
4926 textual name of the relocation as may appear in assembler source
4927 and must end with a colon.
4928 Along with this textual name are the relocation codes to be used if
4929 the corresponding instruction is an ALU instruction (ADD or SUB only),
4930 an LDR, an LDRS, or an LDC. */
4931
4932 struct group_reloc_table_entry
4933 {
4934 const char *name;
4935 int alu_code;
4936 int ldr_code;
4937 int ldrs_code;
4938 int ldc_code;
4939 };
4940
4941 typedef enum
4942 {
4943 /* Varieties of non-ALU group relocation. */
4944
4945 GROUP_LDR,
4946 GROUP_LDRS,
4947 GROUP_LDC
4948 } group_reloc_type;
4949
4950 static struct group_reloc_table_entry group_reloc_table[] =
4951 { /* Program counter relative: */
4952 { "pc_g0_nc",
4953 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4954 0, /* LDR */
4955 0, /* LDRS */
4956 0 }, /* LDC */
4957 { "pc_g0",
4958 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4959 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4960 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4961 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4962 { "pc_g1_nc",
4963 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4964 0, /* LDR */
4965 0, /* LDRS */
4966 0 }, /* LDC */
4967 { "pc_g1",
4968 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4969 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4970 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4971 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4972 { "pc_g2",
4973 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4974 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4975 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4976 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4977 /* Section base relative */
4978 { "sb_g0_nc",
4979 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4980 0, /* LDR */
4981 0, /* LDRS */
4982 0 }, /* LDC */
4983 { "sb_g0",
4984 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4985 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4986 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4987 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4988 { "sb_g1_nc",
4989 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4990 0, /* LDR */
4991 0, /* LDRS */
4992 0 }, /* LDC */
4993 { "sb_g1",
4994 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4995 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4996 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4997 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4998 { "sb_g2",
4999 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5000 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5001 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5002 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5003
5004 /* Given the address of a pointer pointing to the textual name of a group
5005 relocation as may appear in assembler source, attempt to find its details
5006 in group_reloc_table. The pointer will be updated to the character after
5007 the trailing colon. On failure, FAIL will be returned; SUCCESS
5008 otherwise. On success, *entry will be updated to point at the relevant
5009 group_reloc_table entry. */
5010
5011 static int
5012 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5013 {
5014 unsigned int i;
5015 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5016 {
5017 int length = strlen (group_reloc_table[i].name);
5018
5019 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5020 && (*str)[length] == ':')
5021 {
5022 *out = &group_reloc_table[i];
5023 *str += (length + 1);
5024 return SUCCESS;
5025 }
5026 }
5027
5028 return FAIL;
5029 }
5030
5031 /* Parse a <shifter_operand> for an ARM data processing instruction
5032 (as for parse_shifter_operand) where group relocations are allowed:
5033
5034 #<immediate>
5035 #<immediate>, <rotate>
5036 #:<group_reloc>:<expression>
5037 <Rm>
5038 <Rm>, <shift>
5039
5040 where <group_reloc> is one of the strings defined in group_reloc_table.
5041 The hashes are optional.
5042
5043 Everything else is as for parse_shifter_operand. */
5044
5045 static parse_operand_result
5046 parse_shifter_operand_group_reloc (char **str, int i)
5047 {
5048 /* Determine if we have the sequence of characters #: or just :
5049 coming next. If we do, then we check for a group relocation.
5050 If we don't, punt the whole lot to parse_shifter_operand. */
5051
5052 if (((*str)[0] == '#' && (*str)[1] == ':')
5053 || (*str)[0] == ':')
5054 {
5055 struct group_reloc_table_entry *entry;
5056
5057 if ((*str)[0] == '#')
5058 (*str) += 2;
5059 else
5060 (*str)++;
5061
5062 /* Try to parse a group relocation. Anything else is an error. */
5063 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5064 {
5065 inst.error = _("unknown group relocation");
5066 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5067 }
5068
5069 /* We now have the group relocation table entry corresponding to
5070 the name in the assembler source. Next, we parse the expression. */
5071 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5072 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5073
5074 /* Record the relocation type (always the ALU variant here). */
5075 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5076 gas_assert (inst.reloc.type != 0);
5077
5078 return PARSE_OPERAND_SUCCESS;
5079 }
5080 else
5081 return parse_shifter_operand (str, i) == SUCCESS
5082 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5083
5084 /* Never reached. */
5085 }
5086
5087 /* Parse a Neon alignment expression. Information is written to
5088 inst.operands[i]. We assume the initial ':' has been skipped.
5089
5090 align .imm = align << 8, .immisalign=1, .preind=0 */
5091 static parse_operand_result
5092 parse_neon_alignment (char **str, int i)
5093 {
5094 char *p = *str;
5095 expressionS exp;
5096
5097 my_get_expression (&exp, &p, GE_NO_PREFIX);
5098
5099 if (exp.X_op != O_constant)
5100 {
5101 inst.error = _("alignment must be constant");
5102 return PARSE_OPERAND_FAIL;
5103 }
5104
5105 inst.operands[i].imm = exp.X_add_number << 8;
5106 inst.operands[i].immisalign = 1;
5107 /* Alignments are not pre-indexes. */
5108 inst.operands[i].preind = 0;
5109
5110 *str = p;
5111 return PARSE_OPERAND_SUCCESS;
5112 }
5113
5114 /* Parse all forms of an ARM address expression. Information is written
5115 to inst.operands[i] and/or inst.reloc.
5116
5117 Preindexed addressing (.preind=1):
5118
5119 [Rn, #offset] .reg=Rn .reloc.exp=offset
5120 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5121 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5122 .shift_kind=shift .reloc.exp=shift_imm
5123
5124 These three may have a trailing ! which causes .writeback to be set also.
5125
5126 Postindexed addressing (.postind=1, .writeback=1):
5127
5128 [Rn], #offset .reg=Rn .reloc.exp=offset
5129 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5130 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5131 .shift_kind=shift .reloc.exp=shift_imm
5132
5133 Unindexed addressing (.preind=0, .postind=0):
5134
5135 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5136
5137 Other:
5138
5139 [Rn]{!} shorthand for [Rn,#0]{!}
5140 =immediate .isreg=0 .reloc.exp=immediate
5141 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5142
5143 It is the caller's responsibility to check for addressing modes not
5144 supported by the instruction, and to set inst.reloc.type. */
5145
5146 static parse_operand_result
5147 parse_address_main (char **str, int i, int group_relocations,
5148 group_reloc_type group_type)
5149 {
5150 char *p = *str;
5151 int reg;
5152
5153 if (skip_past_char (&p, '[') == FAIL)
5154 {
5155 if (skip_past_char (&p, '=') == FAIL)
5156 {
5157 /* Bare address - translate to PC-relative offset. */
5158 inst.reloc.pc_rel = 1;
5159 inst.operands[i].reg = REG_PC;
5160 inst.operands[i].isreg = 1;
5161 inst.operands[i].preind = 1;
5162 }
5163 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5164
5165 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5166 return PARSE_OPERAND_FAIL;
5167
5168 *str = p;
5169 return PARSE_OPERAND_SUCCESS;
5170 }
5171
5172 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5173 skip_whitespace (p);
5174
5175 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5176 {
5177 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5178 return PARSE_OPERAND_FAIL;
5179 }
5180 inst.operands[i].reg = reg;
5181 inst.operands[i].isreg = 1;
5182
5183 if (skip_past_comma (&p) == SUCCESS)
5184 {
5185 inst.operands[i].preind = 1;
5186
5187 if (*p == '+') p++;
5188 else if (*p == '-') p++, inst.operands[i].negative = 1;
5189
5190 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5191 {
5192 inst.operands[i].imm = reg;
5193 inst.operands[i].immisreg = 1;
5194
5195 if (skip_past_comma (&p) == SUCCESS)
5196 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5197 return PARSE_OPERAND_FAIL;
5198 }
5199 else if (skip_past_char (&p, ':') == SUCCESS)
5200 {
5201 /* FIXME: '@' should be used here, but it's filtered out by generic
5202 code before we get to see it here. This may be subject to
5203 change. */
5204 parse_operand_result result = parse_neon_alignment (&p, i);
5205
5206 if (result != PARSE_OPERAND_SUCCESS)
5207 return result;
5208 }
5209 else
5210 {
5211 if (inst.operands[i].negative)
5212 {
5213 inst.operands[i].negative = 0;
5214 p--;
5215 }
5216
5217 if (group_relocations
5218 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5219 {
5220 struct group_reloc_table_entry *entry;
5221
5222 /* Skip over the #: or : sequence. */
5223 if (*p == '#')
5224 p += 2;
5225 else
5226 p++;
5227
5228 /* Try to parse a group relocation. Anything else is an
5229 error. */
5230 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5231 {
5232 inst.error = _("unknown group relocation");
5233 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5234 }
5235
5236 /* We now have the group relocation table entry corresponding to
5237 the name in the assembler source. Next, we parse the
5238 expression. */
5239 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5240 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5241
5242 /* Record the relocation type. */
5243 switch (group_type)
5244 {
5245 case GROUP_LDR:
5246 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5247 break;
5248
5249 case GROUP_LDRS:
5250 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5251 break;
5252
5253 case GROUP_LDC:
5254 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5255 break;
5256
5257 default:
5258 gas_assert (0);
5259 }
5260
5261 if (inst.reloc.type == 0)
5262 {
5263 inst.error = _("this group relocation is not allowed on this instruction");
5264 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5265 }
5266 }
5267 else
5268 {
5269 char *q = p;
5270 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5271 return PARSE_OPERAND_FAIL;
5272 /* If the offset is 0, find out if it's a +0 or -0. */
5273 if (inst.reloc.exp.X_op == O_constant
5274 && inst.reloc.exp.X_add_number == 0)
5275 {
5276 skip_whitespace (q);
5277 if (*q == '#')
5278 {
5279 q++;
5280 skip_whitespace (q);
5281 }
5282 if (*q == '-')
5283 inst.operands[i].negative = 1;
5284 }
5285 }
5286 }
5287 }
5288 else if (skip_past_char (&p, ':') == SUCCESS)
5289 {
5290 /* FIXME: '@' should be used here, but it's filtered out by generic code
5291 before we get to see it here. This may be subject to change. */
5292 parse_operand_result result = parse_neon_alignment (&p, i);
5293
5294 if (result != PARSE_OPERAND_SUCCESS)
5295 return result;
5296 }
5297
5298 if (skip_past_char (&p, ']') == FAIL)
5299 {
5300 inst.error = _("']' expected");
5301 return PARSE_OPERAND_FAIL;
5302 }
5303
5304 if (skip_past_char (&p, '!') == SUCCESS)
5305 inst.operands[i].writeback = 1;
5306
5307 else if (skip_past_comma (&p) == SUCCESS)
5308 {
5309 if (skip_past_char (&p, '{') == SUCCESS)
5310 {
5311 /* [Rn], {expr} - unindexed, with option */
5312 if (parse_immediate (&p, &inst.operands[i].imm,
5313 0, 255, TRUE) == FAIL)
5314 return PARSE_OPERAND_FAIL;
5315
5316 if (skip_past_char (&p, '}') == FAIL)
5317 {
5318 inst.error = _("'}' expected at end of 'option' field");
5319 return PARSE_OPERAND_FAIL;
5320 }
5321 if (inst.operands[i].preind)
5322 {
5323 inst.error = _("cannot combine index with option");
5324 return PARSE_OPERAND_FAIL;
5325 }
5326 *str = p;
5327 return PARSE_OPERAND_SUCCESS;
5328 }
5329 else
5330 {
5331 inst.operands[i].postind = 1;
5332 inst.operands[i].writeback = 1;
5333
5334 if (inst.operands[i].preind)
5335 {
5336 inst.error = _("cannot combine pre- and post-indexing");
5337 return PARSE_OPERAND_FAIL;
5338 }
5339
5340 if (*p == '+') p++;
5341 else if (*p == '-') p++, inst.operands[i].negative = 1;
5342
5343 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5344 {
5345 /* We might be using the immediate for alignment already. If we
5346 are, OR the register number into the low-order bits. */
5347 if (inst.operands[i].immisalign)
5348 inst.operands[i].imm |= reg;
5349 else
5350 inst.operands[i].imm = reg;
5351 inst.operands[i].immisreg = 1;
5352
5353 if (skip_past_comma (&p) == SUCCESS)
5354 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5355 return PARSE_OPERAND_FAIL;
5356 }
5357 else
5358 {
5359 char *q = p;
5360 if (inst.operands[i].negative)
5361 {
5362 inst.operands[i].negative = 0;
5363 p--;
5364 }
5365 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5366 return PARSE_OPERAND_FAIL;
5367 /* If the offset is 0, find out if it's a +0 or -0. */
5368 if (inst.reloc.exp.X_op == O_constant
5369 && inst.reloc.exp.X_add_number == 0)
5370 {
5371 skip_whitespace (q);
5372 if (*q == '#')
5373 {
5374 q++;
5375 skip_whitespace (q);
5376 }
5377 if (*q == '-')
5378 inst.operands[i].negative = 1;
5379 }
5380 }
5381 }
5382 }
5383
5384 /* If at this point neither .preind nor .postind is set, we have a
5385 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5386 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5387 {
5388 inst.operands[i].preind = 1;
5389 inst.reloc.exp.X_op = O_constant;
5390 inst.reloc.exp.X_add_number = 0;
5391 }
5392 *str = p;
5393 return PARSE_OPERAND_SUCCESS;
5394 }
5395
5396 static int
5397 parse_address (char **str, int i)
5398 {
5399 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5400 ? SUCCESS : FAIL;
5401 }
5402
5403 static parse_operand_result
5404 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5405 {
5406 return parse_address_main (str, i, 1, type);
5407 }
5408
5409 /* Parse an operand for a MOVW or MOVT instruction. */
5410 static int
5411 parse_half (char **str)
5412 {
5413 char * p;
5414
5415 p = *str;
5416 skip_past_char (&p, '#');
5417 if (strncasecmp (p, ":lower16:", 9) == 0)
5418 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5419 else if (strncasecmp (p, ":upper16:", 9) == 0)
5420 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5421
5422 if (inst.reloc.type != BFD_RELOC_UNUSED)
5423 {
5424 p += 9;
5425 skip_whitespace (p);
5426 }
5427
5428 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5429 return FAIL;
5430
5431 if (inst.reloc.type == BFD_RELOC_UNUSED)
5432 {
5433 if (inst.reloc.exp.X_op != O_constant)
5434 {
5435 inst.error = _("constant expression expected");
5436 return FAIL;
5437 }
5438 if (inst.reloc.exp.X_add_number < 0
5439 || inst.reloc.exp.X_add_number > 0xffff)
5440 {
5441 inst.error = _("immediate value out of range");
5442 return FAIL;
5443 }
5444 }
5445 *str = p;
5446 return SUCCESS;
5447 }
5448
5449 /* Miscellaneous. */
5450
5451 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5452 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5453 static int
5454 parse_psr (char **str, bfd_boolean lhs)
5455 {
5456 char *p;
5457 unsigned long psr_field;
5458 const struct asm_psr *psr;
5459 char *start;
5460 bfd_boolean is_apsr = FALSE;
5461 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5462
5463 /* PR gas/12698: If the user has specified -march=all then m_profile will
5464 be TRUE, but we want to ignore it in this case as we are building for any
5465 CPU type, including non-m variants. */
5466 if (selected_cpu.core == arm_arch_any.core)
5467 m_profile = FALSE;
5468
5469 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5470 feature for ease of use and backwards compatibility. */
5471 p = *str;
5472 if (strncasecmp (p, "SPSR", 4) == 0)
5473 {
5474 if (m_profile)
5475 goto unsupported_psr;
5476
5477 psr_field = SPSR_BIT;
5478 }
5479 else if (strncasecmp (p, "CPSR", 4) == 0)
5480 {
5481 if (m_profile)
5482 goto unsupported_psr;
5483
5484 psr_field = 0;
5485 }
5486 else if (strncasecmp (p, "APSR", 4) == 0)
5487 {
5488 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5489 and ARMv7-R architecture CPUs. */
5490 is_apsr = TRUE;
5491 psr_field = 0;
5492 }
5493 else if (m_profile)
5494 {
5495 start = p;
5496 do
5497 p++;
5498 while (ISALNUM (*p) || *p == '_');
5499
5500 if (strncasecmp (start, "iapsr", 5) == 0
5501 || strncasecmp (start, "eapsr", 5) == 0
5502 || strncasecmp (start, "xpsr", 4) == 0
5503 || strncasecmp (start, "psr", 3) == 0)
5504 p = start + strcspn (start, "rR") + 1;
5505
5506 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5507 p - start);
5508
5509 if (!psr)
5510 return FAIL;
5511
5512 /* If APSR is being written, a bitfield may be specified. Note that
5513 APSR itself is handled above. */
5514 if (psr->field <= 3)
5515 {
5516 psr_field = psr->field;
5517 is_apsr = TRUE;
5518 goto check_suffix;
5519 }
5520
5521 *str = p;
5522 /* M-profile MSR instructions have the mask field set to "10", except
5523 *PSR variants which modify APSR, which may use a different mask (and
5524 have been handled already). Do that by setting the PSR_f field
5525 here. */
5526 return psr->field | (lhs ? PSR_f : 0);
5527 }
5528 else
5529 goto unsupported_psr;
5530
5531 p += 4;
5532 check_suffix:
5533 if (*p == '_')
5534 {
5535 /* A suffix follows. */
5536 p++;
5537 start = p;
5538
5539 do
5540 p++;
5541 while (ISALNUM (*p) || *p == '_');
5542
5543 if (is_apsr)
5544 {
5545 /* APSR uses a notation for bits, rather than fields. */
5546 unsigned int nzcvq_bits = 0;
5547 unsigned int g_bit = 0;
5548 char *bit;
5549
5550 for (bit = start; bit != p; bit++)
5551 {
5552 switch (TOLOWER (*bit))
5553 {
5554 case 'n':
5555 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5556 break;
5557
5558 case 'z':
5559 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5560 break;
5561
5562 case 'c':
5563 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5564 break;
5565
5566 case 'v':
5567 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5568 break;
5569
5570 case 'q':
5571 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5572 break;
5573
5574 case 'g':
5575 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5576 break;
5577
5578 default:
5579 inst.error = _("unexpected bit specified after APSR");
5580 return FAIL;
5581 }
5582 }
5583
5584 if (nzcvq_bits == 0x1f)
5585 psr_field |= PSR_f;
5586
5587 if (g_bit == 0x1)
5588 {
5589 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5590 {
5591 inst.error = _("selected processor does not "
5592 "support DSP extension");
5593 return FAIL;
5594 }
5595
5596 psr_field |= PSR_s;
5597 }
5598
5599 if ((nzcvq_bits & 0x20) != 0
5600 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5601 || (g_bit & 0x2) != 0)
5602 {
5603 inst.error = _("bad bitmask specified after APSR");
5604 return FAIL;
5605 }
5606 }
5607 else
5608 {
5609 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5610 p - start);
5611 if (!psr)
5612 goto error;
5613
5614 psr_field |= psr->field;
5615 }
5616 }
5617 else
5618 {
5619 if (ISALNUM (*p))
5620 goto error; /* Garbage after "[CS]PSR". */
5621
5622 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5623 is deprecated, but allow it anyway. */
5624 if (is_apsr && lhs)
5625 {
5626 psr_field |= PSR_f;
5627 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5628 "deprecated"));
5629 }
5630 else if (!m_profile)
5631 /* These bits are never right for M-profile devices: don't set them
5632 (only code paths which read/write APSR reach here). */
5633 psr_field |= (PSR_c | PSR_f);
5634 }
5635 *str = p;
5636 return psr_field;
5637
5638 unsupported_psr:
5639 inst.error = _("selected processor does not support requested special "
5640 "purpose register");
5641 return FAIL;
5642
5643 error:
5644 inst.error = _("flag for {c}psr instruction expected");
5645 return FAIL;
5646 }
5647
5648 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5649 value suitable for splatting into the AIF field of the instruction. */
5650
5651 static int
5652 parse_cps_flags (char **str)
5653 {
5654 int val = 0;
5655 int saw_a_flag = 0;
5656 char *s = *str;
5657
5658 for (;;)
5659 switch (*s++)
5660 {
5661 case '\0': case ',':
5662 goto done;
5663
5664 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5665 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5666 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5667
5668 default:
5669 inst.error = _("unrecognized CPS flag");
5670 return FAIL;
5671 }
5672
5673 done:
5674 if (saw_a_flag == 0)
5675 {
5676 inst.error = _("missing CPS flags");
5677 return FAIL;
5678 }
5679
5680 *str = s - 1;
5681 return val;
5682 }
5683
5684 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5685 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5686
5687 static int
5688 parse_endian_specifier (char **str)
5689 {
5690 int little_endian;
5691 char *s = *str;
5692
5693 if (strncasecmp (s, "BE", 2))
5694 little_endian = 0;
5695 else if (strncasecmp (s, "LE", 2))
5696 little_endian = 1;
5697 else
5698 {
5699 inst.error = _("valid endian specifiers are be or le");
5700 return FAIL;
5701 }
5702
5703 if (ISALNUM (s[2]) || s[2] == '_')
5704 {
5705 inst.error = _("valid endian specifiers are be or le");
5706 return FAIL;
5707 }
5708
5709 *str = s + 2;
5710 return little_endian;
5711 }
5712
5713 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5714 value suitable for poking into the rotate field of an sxt or sxta
5715 instruction, or FAIL on error. */
5716
5717 static int
5718 parse_ror (char **str)
5719 {
5720 int rot;
5721 char *s = *str;
5722
5723 if (strncasecmp (s, "ROR", 3) == 0)
5724 s += 3;
5725 else
5726 {
5727 inst.error = _("missing rotation field after comma");
5728 return FAIL;
5729 }
5730
5731 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5732 return FAIL;
5733
5734 switch (rot)
5735 {
5736 case 0: *str = s; return 0x0;
5737 case 8: *str = s; return 0x1;
5738 case 16: *str = s; return 0x2;
5739 case 24: *str = s; return 0x3;
5740
5741 default:
5742 inst.error = _("rotation can only be 0, 8, 16, or 24");
5743 return FAIL;
5744 }
5745 }
5746
5747 /* Parse a conditional code (from conds[] below). The value returned is in the
5748 range 0 .. 14, or FAIL. */
5749 static int
5750 parse_cond (char **str)
5751 {
5752 char *q;
5753 const struct asm_cond *c;
5754 int n;
5755 /* Condition codes are always 2 characters, so matching up to
5756 3 characters is sufficient. */
5757 char cond[3];
5758
5759 q = *str;
5760 n = 0;
5761 while (ISALPHA (*q) && n < 3)
5762 {
5763 cond[n] = TOLOWER (*q);
5764 q++;
5765 n++;
5766 }
5767
5768 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5769 if (!c)
5770 {
5771 inst.error = _("condition required");
5772 return FAIL;
5773 }
5774
5775 *str = q;
5776 return c->value;
5777 }
5778
5779 /* If the given feature available in the selected CPU, mark it as used.
5780 Returns TRUE iff feature is available. */
5781 static bfd_boolean
5782 mark_feature_used (const arm_feature_set *feature)
5783 {
5784 /* Ensure the option is valid on the current architecture. */
5785 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
5786 return FALSE;
5787
5788 /* Add the appropriate architecture feature for the barrier option used.
5789 */
5790 if (thumb_mode)
5791 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
5792 else
5793 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
5794
5795 return TRUE;
5796 }
5797
5798 /* Parse an option for a barrier instruction. Returns the encoding for the
5799 option, or FAIL. */
5800 static int
5801 parse_barrier (char **str)
5802 {
5803 char *p, *q;
5804 const struct asm_barrier_opt *o;
5805
5806 p = q = *str;
5807 while (ISALPHA (*q))
5808 q++;
5809
5810 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5811 q - p);
5812 if (!o)
5813 return FAIL;
5814
5815 if (!mark_feature_used (&o->arch))
5816 return FAIL;
5817
5818 *str = q;
5819 return o->value;
5820 }
5821
5822 /* Parse the operands of a table branch instruction. Similar to a memory
5823 operand. */
5824 static int
5825 parse_tb (char **str)
5826 {
5827 char * p = *str;
5828 int reg;
5829
5830 if (skip_past_char (&p, '[') == FAIL)
5831 {
5832 inst.error = _("'[' expected");
5833 return FAIL;
5834 }
5835
5836 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5837 {
5838 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5839 return FAIL;
5840 }
5841 inst.operands[0].reg = reg;
5842
5843 if (skip_past_comma (&p) == FAIL)
5844 {
5845 inst.error = _("',' expected");
5846 return FAIL;
5847 }
5848
5849 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5850 {
5851 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5852 return FAIL;
5853 }
5854 inst.operands[0].imm = reg;
5855
5856 if (skip_past_comma (&p) == SUCCESS)
5857 {
5858 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5859 return FAIL;
5860 if (inst.reloc.exp.X_add_number != 1)
5861 {
5862 inst.error = _("invalid shift");
5863 return FAIL;
5864 }
5865 inst.operands[0].shifted = 1;
5866 }
5867
5868 if (skip_past_char (&p, ']') == FAIL)
5869 {
5870 inst.error = _("']' expected");
5871 return FAIL;
5872 }
5873 *str = p;
5874 return SUCCESS;
5875 }
5876
5877 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5878 information on the types the operands can take and how they are encoded.
5879 Up to four operands may be read; this function handles setting the
5880 ".present" field for each read operand itself.
5881 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5882 else returns FAIL. */
5883
5884 static int
5885 parse_neon_mov (char **str, int *which_operand)
5886 {
5887 int i = *which_operand, val;
5888 enum arm_reg_type rtype;
5889 char *ptr = *str;
5890 struct neon_type_el optype;
5891
5892 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5893 {
5894 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5895 inst.operands[i].reg = val;
5896 inst.operands[i].isscalar = 1;
5897 inst.operands[i].vectype = optype;
5898 inst.operands[i++].present = 1;
5899
5900 if (skip_past_comma (&ptr) == FAIL)
5901 goto wanted_comma;
5902
5903 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5904 goto wanted_arm;
5905
5906 inst.operands[i].reg = val;
5907 inst.operands[i].isreg = 1;
5908 inst.operands[i].present = 1;
5909 }
5910 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5911 != FAIL)
5912 {
5913 /* Cases 0, 1, 2, 3, 5 (D only). */
5914 if (skip_past_comma (&ptr) == FAIL)
5915 goto wanted_comma;
5916
5917 inst.operands[i].reg = val;
5918 inst.operands[i].isreg = 1;
5919 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5920 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5921 inst.operands[i].isvec = 1;
5922 inst.operands[i].vectype = optype;
5923 inst.operands[i++].present = 1;
5924
5925 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5926 {
5927 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5928 Case 13: VMOV <Sd>, <Rm> */
5929 inst.operands[i].reg = val;
5930 inst.operands[i].isreg = 1;
5931 inst.operands[i].present = 1;
5932
5933 if (rtype == REG_TYPE_NQ)
5934 {
5935 first_error (_("can't use Neon quad register here"));
5936 return FAIL;
5937 }
5938 else if (rtype != REG_TYPE_VFS)
5939 {
5940 i++;
5941 if (skip_past_comma (&ptr) == FAIL)
5942 goto wanted_comma;
5943 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5944 goto wanted_arm;
5945 inst.operands[i].reg = val;
5946 inst.operands[i].isreg = 1;
5947 inst.operands[i].present = 1;
5948 }
5949 }
5950 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5951 &optype)) != FAIL)
5952 {
5953 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5954 Case 1: VMOV<c><q> <Dd>, <Dm>
5955 Case 8: VMOV.F32 <Sd>, <Sm>
5956 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5957
5958 inst.operands[i].reg = val;
5959 inst.operands[i].isreg = 1;
5960 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5961 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5962 inst.operands[i].isvec = 1;
5963 inst.operands[i].vectype = optype;
5964 inst.operands[i].present = 1;
5965
5966 if (skip_past_comma (&ptr) == SUCCESS)
5967 {
5968 /* Case 15. */
5969 i++;
5970
5971 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5972 goto wanted_arm;
5973
5974 inst.operands[i].reg = val;
5975 inst.operands[i].isreg = 1;
5976 inst.operands[i++].present = 1;
5977
5978 if (skip_past_comma (&ptr) == FAIL)
5979 goto wanted_comma;
5980
5981 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5982 goto wanted_arm;
5983
5984 inst.operands[i].reg = val;
5985 inst.operands[i].isreg = 1;
5986 inst.operands[i].present = 1;
5987 }
5988 }
5989 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5990 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5991 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5992 Case 10: VMOV.F32 <Sd>, #<imm>
5993 Case 11: VMOV.F64 <Dd>, #<imm> */
5994 inst.operands[i].immisfloat = 1;
5995 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5996 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5997 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5998 ;
5999 else
6000 {
6001 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6002 return FAIL;
6003 }
6004 }
6005 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6006 {
6007 /* Cases 6, 7. */
6008 inst.operands[i].reg = val;
6009 inst.operands[i].isreg = 1;
6010 inst.operands[i++].present = 1;
6011
6012 if (skip_past_comma (&ptr) == FAIL)
6013 goto wanted_comma;
6014
6015 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6016 {
6017 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6018 inst.operands[i].reg = val;
6019 inst.operands[i].isscalar = 1;
6020 inst.operands[i].present = 1;
6021 inst.operands[i].vectype = optype;
6022 }
6023 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6024 {
6025 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6026 inst.operands[i].reg = val;
6027 inst.operands[i].isreg = 1;
6028 inst.operands[i++].present = 1;
6029
6030 if (skip_past_comma (&ptr) == FAIL)
6031 goto wanted_comma;
6032
6033 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6034 == FAIL)
6035 {
6036 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6037 return FAIL;
6038 }
6039
6040 inst.operands[i].reg = val;
6041 inst.operands[i].isreg = 1;
6042 inst.operands[i].isvec = 1;
6043 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6044 inst.operands[i].vectype = optype;
6045 inst.operands[i].present = 1;
6046
6047 if (rtype == REG_TYPE_VFS)
6048 {
6049 /* Case 14. */
6050 i++;
6051 if (skip_past_comma (&ptr) == FAIL)
6052 goto wanted_comma;
6053 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6054 &optype)) == FAIL)
6055 {
6056 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6057 return FAIL;
6058 }
6059 inst.operands[i].reg = val;
6060 inst.operands[i].isreg = 1;
6061 inst.operands[i].isvec = 1;
6062 inst.operands[i].issingle = 1;
6063 inst.operands[i].vectype = optype;
6064 inst.operands[i].present = 1;
6065 }
6066 }
6067 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6068 != FAIL)
6069 {
6070 /* Case 13. */
6071 inst.operands[i].reg = val;
6072 inst.operands[i].isreg = 1;
6073 inst.operands[i].isvec = 1;
6074 inst.operands[i].issingle = 1;
6075 inst.operands[i].vectype = optype;
6076 inst.operands[i].present = 1;
6077 }
6078 }
6079 else
6080 {
6081 first_error (_("parse error"));
6082 return FAIL;
6083 }
6084
6085 /* Successfully parsed the operands. Update args. */
6086 *which_operand = i;
6087 *str = ptr;
6088 return SUCCESS;
6089
6090 wanted_comma:
6091 first_error (_("expected comma"));
6092 return FAIL;
6093
6094 wanted_arm:
6095 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6096 return FAIL;
6097 }
6098
6099 /* Use this macro when the operand constraints are different
6100 for ARM and THUMB (e.g. ldrd). */
6101 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6102 ((arm_operand) | ((thumb_operand) << 16))
6103
6104 /* Matcher codes for parse_operands. */
6105 enum operand_parse_code
6106 {
6107 OP_stop, /* end of line */
6108
6109 OP_RR, /* ARM register */
6110 OP_RRnpc, /* ARM register, not r15 */
6111 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6112 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6113 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6114 optional trailing ! */
6115 OP_RRw, /* ARM register, not r15, optional trailing ! */
6116 OP_RCP, /* Coprocessor number */
6117 OP_RCN, /* Coprocessor register */
6118 OP_RF, /* FPA register */
6119 OP_RVS, /* VFP single precision register */
6120 OP_RVD, /* VFP double precision register (0..15) */
6121 OP_RND, /* Neon double precision register (0..31) */
6122 OP_RNQ, /* Neon quad precision register */
6123 OP_RVSD, /* VFP single or double precision register */
6124 OP_RNDQ, /* Neon double or quad precision register */
6125 OP_RNSDQ, /* Neon single, double or quad precision register */
6126 OP_RNSC, /* Neon scalar D[X] */
6127 OP_RVC, /* VFP control register */
6128 OP_RMF, /* Maverick F register */
6129 OP_RMD, /* Maverick D register */
6130 OP_RMFX, /* Maverick FX register */
6131 OP_RMDX, /* Maverick DX register */
6132 OP_RMAX, /* Maverick AX register */
6133 OP_RMDS, /* Maverick DSPSC register */
6134 OP_RIWR, /* iWMMXt wR register */
6135 OP_RIWC, /* iWMMXt wC register */
6136 OP_RIWG, /* iWMMXt wCG register */
6137 OP_RXA, /* XScale accumulator register */
6138
6139 OP_REGLST, /* ARM register list */
6140 OP_VRSLST, /* VFP single-precision register list */
6141 OP_VRDLST, /* VFP double-precision register list */
6142 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6143 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6144 OP_NSTRLST, /* Neon element/structure list */
6145
6146 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6147 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6148 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6149 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6150 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6151 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6152 OP_VMOV, /* Neon VMOV operands. */
6153 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6154 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6155 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6156
6157 OP_I0, /* immediate zero */
6158 OP_I7, /* immediate value 0 .. 7 */
6159 OP_I15, /* 0 .. 15 */
6160 OP_I16, /* 1 .. 16 */
6161 OP_I16z, /* 0 .. 16 */
6162 OP_I31, /* 0 .. 31 */
6163 OP_I31w, /* 0 .. 31, optional trailing ! */
6164 OP_I32, /* 1 .. 32 */
6165 OP_I32z, /* 0 .. 32 */
6166 OP_I63, /* 0 .. 63 */
6167 OP_I63s, /* -64 .. 63 */
6168 OP_I64, /* 1 .. 64 */
6169 OP_I64z, /* 0 .. 64 */
6170 OP_I255, /* 0 .. 255 */
6171
6172 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6173 OP_I7b, /* 0 .. 7 */
6174 OP_I15b, /* 0 .. 15 */
6175 OP_I31b, /* 0 .. 31 */
6176
6177 OP_SH, /* shifter operand */
6178 OP_SHG, /* shifter operand with possible group relocation */
6179 OP_ADDR, /* Memory address expression (any mode) */
6180 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6181 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6182 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6183 OP_EXP, /* arbitrary expression */
6184 OP_EXPi, /* same, with optional immediate prefix */
6185 OP_EXPr, /* same, with optional relocation suffix */
6186 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6187
6188 OP_CPSF, /* CPS flags */
6189 OP_ENDI, /* Endianness specifier */
6190 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6191 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6192 OP_COND, /* conditional code */
6193 OP_TB, /* Table branch. */
6194
6195 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6196
6197 OP_RRnpc_I0, /* ARM register or literal 0 */
6198 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6199 OP_RR_EXi, /* ARM register or expression with imm prefix */
6200 OP_RF_IF, /* FPA register or immediate */
6201 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6202 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6203
6204 /* Optional operands. */
6205 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6206 OP_oI31b, /* 0 .. 31 */
6207 OP_oI32b, /* 1 .. 32 */
6208 OP_oI32z, /* 0 .. 32 */
6209 OP_oIffffb, /* 0 .. 65535 */
6210 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6211
6212 OP_oRR, /* ARM register */
6213 OP_oRRnpc, /* ARM register, not the PC */
6214 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6215 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6216 OP_oRND, /* Optional Neon double precision register */
6217 OP_oRNQ, /* Optional Neon quad precision register */
6218 OP_oRNDQ, /* Optional Neon double or quad precision register */
6219 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6220 OP_oSHll, /* LSL immediate */
6221 OP_oSHar, /* ASR immediate */
6222 OP_oSHllar, /* LSL or ASR immediate */
6223 OP_oROR, /* ROR 0/8/16/24 */
6224 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6225
6226 /* Some pre-defined mixed (ARM/THUMB) operands. */
6227 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6228 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6229 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6230
6231 OP_FIRST_OPTIONAL = OP_oI7b
6232 };
6233
6234 /* Generic instruction operand parser. This does no encoding and no
6235 semantic validation; it merely squirrels values away in the inst
6236 structure. Returns SUCCESS or FAIL depending on whether the
6237 specified grammar matched. */
6238 static int
6239 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6240 {
6241 unsigned const int *upat = pattern;
6242 char *backtrack_pos = 0;
6243 const char *backtrack_error = 0;
6244 int i, val = 0, backtrack_index = 0;
6245 enum arm_reg_type rtype;
6246 parse_operand_result result;
6247 unsigned int op_parse_code;
6248
6249 #define po_char_or_fail(chr) \
6250 do \
6251 { \
6252 if (skip_past_char (&str, chr) == FAIL) \
6253 goto bad_args; \
6254 } \
6255 while (0)
6256
6257 #define po_reg_or_fail(regtype) \
6258 do \
6259 { \
6260 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6261 & inst.operands[i].vectype); \
6262 if (val == FAIL) \
6263 { \
6264 first_error (_(reg_expected_msgs[regtype])); \
6265 goto failure; \
6266 } \
6267 inst.operands[i].reg = val; \
6268 inst.operands[i].isreg = 1; \
6269 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6270 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6271 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6272 || rtype == REG_TYPE_VFD \
6273 || rtype == REG_TYPE_NQ); \
6274 } \
6275 while (0)
6276
6277 #define po_reg_or_goto(regtype, label) \
6278 do \
6279 { \
6280 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6281 & inst.operands[i].vectype); \
6282 if (val == FAIL) \
6283 goto label; \
6284 \
6285 inst.operands[i].reg = val; \
6286 inst.operands[i].isreg = 1; \
6287 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6288 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6289 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6290 || rtype == REG_TYPE_VFD \
6291 || rtype == REG_TYPE_NQ); \
6292 } \
6293 while (0)
6294
6295 #define po_imm_or_fail(min, max, popt) \
6296 do \
6297 { \
6298 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6299 goto failure; \
6300 inst.operands[i].imm = val; \
6301 } \
6302 while (0)
6303
6304 #define po_scalar_or_goto(elsz, label) \
6305 do \
6306 { \
6307 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6308 if (val == FAIL) \
6309 goto label; \
6310 inst.operands[i].reg = val; \
6311 inst.operands[i].isscalar = 1; \
6312 } \
6313 while (0)
6314
6315 #define po_misc_or_fail(expr) \
6316 do \
6317 { \
6318 if (expr) \
6319 goto failure; \
6320 } \
6321 while (0)
6322
6323 #define po_misc_or_fail_no_backtrack(expr) \
6324 do \
6325 { \
6326 result = expr; \
6327 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6328 backtrack_pos = 0; \
6329 if (result != PARSE_OPERAND_SUCCESS) \
6330 goto failure; \
6331 } \
6332 while (0)
6333
6334 #define po_barrier_or_imm(str) \
6335 do \
6336 { \
6337 val = parse_barrier (&str); \
6338 if (val == FAIL) \
6339 { \
6340 if (ISALPHA (*str)) \
6341 goto failure; \
6342 else \
6343 goto immediate; \
6344 } \
6345 else \
6346 { \
6347 if ((inst.instruction & 0xf0) == 0x60 \
6348 && val != 0xf) \
6349 { \
6350 /* ISB can only take SY as an option. */ \
6351 inst.error = _("invalid barrier type"); \
6352 goto failure; \
6353 } \
6354 } \
6355 } \
6356 while (0)
6357
6358 skip_whitespace (str);
6359
6360 for (i = 0; upat[i] != OP_stop; i++)
6361 {
6362 op_parse_code = upat[i];
6363 if (op_parse_code >= 1<<16)
6364 op_parse_code = thumb ? (op_parse_code >> 16)
6365 : (op_parse_code & ((1<<16)-1));
6366
6367 if (op_parse_code >= OP_FIRST_OPTIONAL)
6368 {
6369 /* Remember where we are in case we need to backtrack. */
6370 gas_assert (!backtrack_pos);
6371 backtrack_pos = str;
6372 backtrack_error = inst.error;
6373 backtrack_index = i;
6374 }
6375
6376 if (i > 0 && (i > 1 || inst.operands[0].present))
6377 po_char_or_fail (',');
6378
6379 switch (op_parse_code)
6380 {
6381 /* Registers */
6382 case OP_oRRnpc:
6383 case OP_oRRnpcsp:
6384 case OP_RRnpc:
6385 case OP_RRnpcsp:
6386 case OP_oRR:
6387 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6388 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6389 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6390 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6391 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6392 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6393 case OP_oRND:
6394 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6395 case OP_RVC:
6396 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6397 break;
6398 /* Also accept generic coprocessor regs for unknown registers. */
6399 coproc_reg:
6400 po_reg_or_fail (REG_TYPE_CN);
6401 break;
6402 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6403 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6404 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6405 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6406 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6407 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6408 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6409 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6410 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6411 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6412 case OP_oRNQ:
6413 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6414 case OP_oRNDQ:
6415 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6416 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6417 case OP_oRNSDQ:
6418 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6419
6420 /* Neon scalar. Using an element size of 8 means that some invalid
6421 scalars are accepted here, so deal with those in later code. */
6422 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6423
6424 case OP_RNDQ_I0:
6425 {
6426 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6427 break;
6428 try_imm0:
6429 po_imm_or_fail (0, 0, TRUE);
6430 }
6431 break;
6432
6433 case OP_RVSD_I0:
6434 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6435 break;
6436
6437 case OP_RR_RNSC:
6438 {
6439 po_scalar_or_goto (8, try_rr);
6440 break;
6441 try_rr:
6442 po_reg_or_fail (REG_TYPE_RN);
6443 }
6444 break;
6445
6446 case OP_RNSDQ_RNSC:
6447 {
6448 po_scalar_or_goto (8, try_nsdq);
6449 break;
6450 try_nsdq:
6451 po_reg_or_fail (REG_TYPE_NSDQ);
6452 }
6453 break;
6454
6455 case OP_RNDQ_RNSC:
6456 {
6457 po_scalar_or_goto (8, try_ndq);
6458 break;
6459 try_ndq:
6460 po_reg_or_fail (REG_TYPE_NDQ);
6461 }
6462 break;
6463
6464 case OP_RND_RNSC:
6465 {
6466 po_scalar_or_goto (8, try_vfd);
6467 break;
6468 try_vfd:
6469 po_reg_or_fail (REG_TYPE_VFD);
6470 }
6471 break;
6472
6473 case OP_VMOV:
6474 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6475 not careful then bad things might happen. */
6476 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6477 break;
6478
6479 case OP_RNDQ_Ibig:
6480 {
6481 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6482 break;
6483 try_immbig:
6484 /* There's a possibility of getting a 64-bit immediate here, so
6485 we need special handling. */
6486 if (parse_big_immediate (&str, i) == FAIL)
6487 {
6488 inst.error = _("immediate value is out of range");
6489 goto failure;
6490 }
6491 }
6492 break;
6493
6494 case OP_RNDQ_I63b:
6495 {
6496 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6497 break;
6498 try_shimm:
6499 po_imm_or_fail (0, 63, TRUE);
6500 }
6501 break;
6502
6503 case OP_RRnpcb:
6504 po_char_or_fail ('[');
6505 po_reg_or_fail (REG_TYPE_RN);
6506 po_char_or_fail (']');
6507 break;
6508
6509 case OP_RRnpctw:
6510 case OP_RRw:
6511 case OP_oRRw:
6512 po_reg_or_fail (REG_TYPE_RN);
6513 if (skip_past_char (&str, '!') == SUCCESS)
6514 inst.operands[i].writeback = 1;
6515 break;
6516
6517 /* Immediates */
6518 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6519 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6520 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6521 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6522 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6523 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6524 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6525 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6526 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6527 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6528 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6529 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6530
6531 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6532 case OP_oI7b:
6533 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6534 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6535 case OP_oI31b:
6536 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6537 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6538 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6539 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6540
6541 /* Immediate variants */
6542 case OP_oI255c:
6543 po_char_or_fail ('{');
6544 po_imm_or_fail (0, 255, TRUE);
6545 po_char_or_fail ('}');
6546 break;
6547
6548 case OP_I31w:
6549 /* The expression parser chokes on a trailing !, so we have
6550 to find it first and zap it. */
6551 {
6552 char *s = str;
6553 while (*s && *s != ',')
6554 s++;
6555 if (s[-1] == '!')
6556 {
6557 s[-1] = '\0';
6558 inst.operands[i].writeback = 1;
6559 }
6560 po_imm_or_fail (0, 31, TRUE);
6561 if (str == s - 1)
6562 str = s;
6563 }
6564 break;
6565
6566 /* Expressions */
6567 case OP_EXPi: EXPi:
6568 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6569 GE_OPT_PREFIX));
6570 break;
6571
6572 case OP_EXP:
6573 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6574 GE_NO_PREFIX));
6575 break;
6576
6577 case OP_EXPr: EXPr:
6578 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6579 GE_NO_PREFIX));
6580 if (inst.reloc.exp.X_op == O_symbol)
6581 {
6582 val = parse_reloc (&str);
6583 if (val == -1)
6584 {
6585 inst.error = _("unrecognized relocation suffix");
6586 goto failure;
6587 }
6588 else if (val != BFD_RELOC_UNUSED)
6589 {
6590 inst.operands[i].imm = val;
6591 inst.operands[i].hasreloc = 1;
6592 }
6593 }
6594 break;
6595
6596 /* Operand for MOVW or MOVT. */
6597 case OP_HALF:
6598 po_misc_or_fail (parse_half (&str));
6599 break;
6600
6601 /* Register or expression. */
6602 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6603 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6604
6605 /* Register or immediate. */
6606 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6607 I0: po_imm_or_fail (0, 0, FALSE); break;
6608
6609 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6610 IF:
6611 if (!is_immediate_prefix (*str))
6612 goto bad_args;
6613 str++;
6614 val = parse_fpa_immediate (&str);
6615 if (val == FAIL)
6616 goto failure;
6617 /* FPA immediates are encoded as registers 8-15.
6618 parse_fpa_immediate has already applied the offset. */
6619 inst.operands[i].reg = val;
6620 inst.operands[i].isreg = 1;
6621 break;
6622
6623 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6624 I32z: po_imm_or_fail (0, 32, FALSE); break;
6625
6626 /* Two kinds of register. */
6627 case OP_RIWR_RIWC:
6628 {
6629 struct reg_entry *rege = arm_reg_parse_multi (&str);
6630 if (!rege
6631 || (rege->type != REG_TYPE_MMXWR
6632 && rege->type != REG_TYPE_MMXWC
6633 && rege->type != REG_TYPE_MMXWCG))
6634 {
6635 inst.error = _("iWMMXt data or control register expected");
6636 goto failure;
6637 }
6638 inst.operands[i].reg = rege->number;
6639 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6640 }
6641 break;
6642
6643 case OP_RIWC_RIWG:
6644 {
6645 struct reg_entry *rege = arm_reg_parse_multi (&str);
6646 if (!rege
6647 || (rege->type != REG_TYPE_MMXWC
6648 && rege->type != REG_TYPE_MMXWCG))
6649 {
6650 inst.error = _("iWMMXt control register expected");
6651 goto failure;
6652 }
6653 inst.operands[i].reg = rege->number;
6654 inst.operands[i].isreg = 1;
6655 }
6656 break;
6657
6658 /* Misc */
6659 case OP_CPSF: val = parse_cps_flags (&str); break;
6660 case OP_ENDI: val = parse_endian_specifier (&str); break;
6661 case OP_oROR: val = parse_ror (&str); break;
6662 case OP_COND: val = parse_cond (&str); break;
6663 case OP_oBARRIER_I15:
6664 po_barrier_or_imm (str); break;
6665 immediate:
6666 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6667 goto failure;
6668 break;
6669
6670 case OP_wPSR:
6671 case OP_rPSR:
6672 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6673 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6674 {
6675 inst.error = _("Banked registers are not available with this "
6676 "architecture.");
6677 goto failure;
6678 }
6679 break;
6680 try_psr:
6681 val = parse_psr (&str, op_parse_code == OP_wPSR);
6682 break;
6683
6684 case OP_APSR_RR:
6685 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6686 break;
6687 try_apsr:
6688 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6689 instruction). */
6690 if (strncasecmp (str, "APSR_", 5) == 0)
6691 {
6692 unsigned found = 0;
6693 str += 5;
6694 while (found < 15)
6695 switch (*str++)
6696 {
6697 case 'c': found = (found & 1) ? 16 : found | 1; break;
6698 case 'n': found = (found & 2) ? 16 : found | 2; break;
6699 case 'z': found = (found & 4) ? 16 : found | 4; break;
6700 case 'v': found = (found & 8) ? 16 : found | 8; break;
6701 default: found = 16;
6702 }
6703 if (found != 15)
6704 goto failure;
6705 inst.operands[i].isvec = 1;
6706 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6707 inst.operands[i].reg = REG_PC;
6708 }
6709 else
6710 goto failure;
6711 break;
6712
6713 case OP_TB:
6714 po_misc_or_fail (parse_tb (&str));
6715 break;
6716
6717 /* Register lists. */
6718 case OP_REGLST:
6719 val = parse_reg_list (&str);
6720 if (*str == '^')
6721 {
6722 inst.operands[1].writeback = 1;
6723 str++;
6724 }
6725 break;
6726
6727 case OP_VRSLST:
6728 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6729 break;
6730
6731 case OP_VRDLST:
6732 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6733 break;
6734
6735 case OP_VRSDLST:
6736 /* Allow Q registers too. */
6737 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6738 REGLIST_NEON_D);
6739 if (val == FAIL)
6740 {
6741 inst.error = NULL;
6742 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6743 REGLIST_VFP_S);
6744 inst.operands[i].issingle = 1;
6745 }
6746 break;
6747
6748 case OP_NRDLST:
6749 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6750 REGLIST_NEON_D);
6751 break;
6752
6753 case OP_NSTRLST:
6754 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6755 &inst.operands[i].vectype);
6756 break;
6757
6758 /* Addressing modes */
6759 case OP_ADDR:
6760 po_misc_or_fail (parse_address (&str, i));
6761 break;
6762
6763 case OP_ADDRGLDR:
6764 po_misc_or_fail_no_backtrack (
6765 parse_address_group_reloc (&str, i, GROUP_LDR));
6766 break;
6767
6768 case OP_ADDRGLDRS:
6769 po_misc_or_fail_no_backtrack (
6770 parse_address_group_reloc (&str, i, GROUP_LDRS));
6771 break;
6772
6773 case OP_ADDRGLDC:
6774 po_misc_or_fail_no_backtrack (
6775 parse_address_group_reloc (&str, i, GROUP_LDC));
6776 break;
6777
6778 case OP_SH:
6779 po_misc_or_fail (parse_shifter_operand (&str, i));
6780 break;
6781
6782 case OP_SHG:
6783 po_misc_or_fail_no_backtrack (
6784 parse_shifter_operand_group_reloc (&str, i));
6785 break;
6786
6787 case OP_oSHll:
6788 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6789 break;
6790
6791 case OP_oSHar:
6792 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6793 break;
6794
6795 case OP_oSHllar:
6796 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6797 break;
6798
6799 default:
6800 as_fatal (_("unhandled operand code %d"), op_parse_code);
6801 }
6802
6803 /* Various value-based sanity checks and shared operations. We
6804 do not signal immediate failures for the register constraints;
6805 this allows a syntax error to take precedence. */
6806 switch (op_parse_code)
6807 {
6808 case OP_oRRnpc:
6809 case OP_RRnpc:
6810 case OP_RRnpcb:
6811 case OP_RRw:
6812 case OP_oRRw:
6813 case OP_RRnpc_I0:
6814 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6815 inst.error = BAD_PC;
6816 break;
6817
6818 case OP_oRRnpcsp:
6819 case OP_RRnpcsp:
6820 if (inst.operands[i].isreg)
6821 {
6822 if (inst.operands[i].reg == REG_PC)
6823 inst.error = BAD_PC;
6824 else if (inst.operands[i].reg == REG_SP)
6825 inst.error = BAD_SP;
6826 }
6827 break;
6828
6829 case OP_RRnpctw:
6830 if (inst.operands[i].isreg
6831 && inst.operands[i].reg == REG_PC
6832 && (inst.operands[i].writeback || thumb))
6833 inst.error = BAD_PC;
6834 break;
6835
6836 case OP_CPSF:
6837 case OP_ENDI:
6838 case OP_oROR:
6839 case OP_wPSR:
6840 case OP_rPSR:
6841 case OP_COND:
6842 case OP_oBARRIER_I15:
6843 case OP_REGLST:
6844 case OP_VRSLST:
6845 case OP_VRDLST:
6846 case OP_VRSDLST:
6847 case OP_NRDLST:
6848 case OP_NSTRLST:
6849 if (val == FAIL)
6850 goto failure;
6851 inst.operands[i].imm = val;
6852 break;
6853
6854 default:
6855 break;
6856 }
6857
6858 /* If we get here, this operand was successfully parsed. */
6859 inst.operands[i].present = 1;
6860 continue;
6861
6862 bad_args:
6863 inst.error = BAD_ARGS;
6864
6865 failure:
6866 if (!backtrack_pos)
6867 {
6868 /* The parse routine should already have set inst.error, but set a
6869 default here just in case. */
6870 if (!inst.error)
6871 inst.error = _("syntax error");
6872 return FAIL;
6873 }
6874
6875 /* Do not backtrack over a trailing optional argument that
6876 absorbed some text. We will only fail again, with the
6877 'garbage following instruction' error message, which is
6878 probably less helpful than the current one. */
6879 if (backtrack_index == i && backtrack_pos != str
6880 && upat[i+1] == OP_stop)
6881 {
6882 if (!inst.error)
6883 inst.error = _("syntax error");
6884 return FAIL;
6885 }
6886
6887 /* Try again, skipping the optional argument at backtrack_pos. */
6888 str = backtrack_pos;
6889 inst.error = backtrack_error;
6890 inst.operands[backtrack_index].present = 0;
6891 i = backtrack_index;
6892 backtrack_pos = 0;
6893 }
6894
6895 /* Check that we have parsed all the arguments. */
6896 if (*str != '\0' && !inst.error)
6897 inst.error = _("garbage following instruction");
6898
6899 return inst.error ? FAIL : SUCCESS;
6900 }
6901
6902 #undef po_char_or_fail
6903 #undef po_reg_or_fail
6904 #undef po_reg_or_goto
6905 #undef po_imm_or_fail
6906 #undef po_scalar_or_fail
6907 #undef po_barrier_or_imm
6908
6909 /* Shorthand macro for instruction encoding functions issuing errors. */
6910 #define constraint(expr, err) \
6911 do \
6912 { \
6913 if (expr) \
6914 { \
6915 inst.error = err; \
6916 return; \
6917 } \
6918 } \
6919 while (0)
6920
6921 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6922 instructions are unpredictable if these registers are used. This
6923 is the BadReg predicate in ARM's Thumb-2 documentation. */
6924 #define reject_bad_reg(reg) \
6925 do \
6926 if (reg == REG_SP || reg == REG_PC) \
6927 { \
6928 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6929 return; \
6930 } \
6931 while (0)
6932
6933 /* If REG is R13 (the stack pointer), warn that its use is
6934 deprecated. */
6935 #define warn_deprecated_sp(reg) \
6936 do \
6937 if (warn_on_deprecated && reg == REG_SP) \
6938 as_warn (_("use of r13 is deprecated")); \
6939 while (0)
6940
6941 /* Functions for operand encoding. ARM, then Thumb. */
6942
6943 #define rotate_left(v, n) (v << n | v >> (32 - n))
6944
6945 /* If VAL can be encoded in the immediate field of an ARM instruction,
6946 return the encoded form. Otherwise, return FAIL. */
6947
6948 static unsigned int
6949 encode_arm_immediate (unsigned int val)
6950 {
6951 unsigned int a, i;
6952
6953 for (i = 0; i < 32; i += 2)
6954 if ((a = rotate_left (val, i)) <= 0xff)
6955 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6956
6957 return FAIL;
6958 }
6959
6960 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6961 return the encoded form. Otherwise, return FAIL. */
6962 static unsigned int
6963 encode_thumb32_immediate (unsigned int val)
6964 {
6965 unsigned int a, i;
6966
6967 if (val <= 0xff)
6968 return val;
6969
6970 for (i = 1; i <= 24; i++)
6971 {
6972 a = val >> i;
6973 if ((val & ~(0xff << i)) == 0)
6974 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6975 }
6976
6977 a = val & 0xff;
6978 if (val == ((a << 16) | a))
6979 return 0x100 | a;
6980 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6981 return 0x300 | a;
6982
6983 a = val & 0xff00;
6984 if (val == ((a << 16) | a))
6985 return 0x200 | (a >> 8);
6986
6987 return FAIL;
6988 }
6989 /* Encode a VFP SP or DP register number into inst.instruction. */
6990
6991 static void
6992 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6993 {
6994 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6995 && reg > 15)
6996 {
6997 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6998 {
6999 if (thumb_mode)
7000 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7001 fpu_vfp_ext_d32);
7002 else
7003 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7004 fpu_vfp_ext_d32);
7005 }
7006 else
7007 {
7008 first_error (_("D register out of range for selected VFP version"));
7009 return;
7010 }
7011 }
7012
7013 switch (pos)
7014 {
7015 case VFP_REG_Sd:
7016 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7017 break;
7018
7019 case VFP_REG_Sn:
7020 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7021 break;
7022
7023 case VFP_REG_Sm:
7024 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7025 break;
7026
7027 case VFP_REG_Dd:
7028 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7029 break;
7030
7031 case VFP_REG_Dn:
7032 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7033 break;
7034
7035 case VFP_REG_Dm:
7036 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7037 break;
7038
7039 default:
7040 abort ();
7041 }
7042 }
7043
7044 /* Encode a <shift> in an ARM-format instruction. The immediate,
7045 if any, is handled by md_apply_fix. */
7046 static void
7047 encode_arm_shift (int i)
7048 {
7049 if (inst.operands[i].shift_kind == SHIFT_RRX)
7050 inst.instruction |= SHIFT_ROR << 5;
7051 else
7052 {
7053 inst.instruction |= inst.operands[i].shift_kind << 5;
7054 if (inst.operands[i].immisreg)
7055 {
7056 inst.instruction |= SHIFT_BY_REG;
7057 inst.instruction |= inst.operands[i].imm << 8;
7058 }
7059 else
7060 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7061 }
7062 }
7063
7064 static void
7065 encode_arm_shifter_operand (int i)
7066 {
7067 if (inst.operands[i].isreg)
7068 {
7069 inst.instruction |= inst.operands[i].reg;
7070 encode_arm_shift (i);
7071 }
7072 else
7073 {
7074 inst.instruction |= INST_IMMEDIATE;
7075 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7076 inst.instruction |= inst.operands[i].imm;
7077 }
7078 }
7079
7080 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7081 static void
7082 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7083 {
7084 /* PR 14260:
7085 Generate an error if the operand is not a register. */
7086 constraint (!inst.operands[i].isreg,
7087 _("Instruction does not support =N addresses"));
7088
7089 inst.instruction |= inst.operands[i].reg << 16;
7090
7091 if (inst.operands[i].preind)
7092 {
7093 if (is_t)
7094 {
7095 inst.error = _("instruction does not accept preindexed addressing");
7096 return;
7097 }
7098 inst.instruction |= PRE_INDEX;
7099 if (inst.operands[i].writeback)
7100 inst.instruction |= WRITE_BACK;
7101
7102 }
7103 else if (inst.operands[i].postind)
7104 {
7105 gas_assert (inst.operands[i].writeback);
7106 if (is_t)
7107 inst.instruction |= WRITE_BACK;
7108 }
7109 else /* unindexed - only for coprocessor */
7110 {
7111 inst.error = _("instruction does not accept unindexed addressing");
7112 return;
7113 }
7114
7115 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7116 && (((inst.instruction & 0x000f0000) >> 16)
7117 == ((inst.instruction & 0x0000f000) >> 12)))
7118 as_warn ((inst.instruction & LOAD_BIT)
7119 ? _("destination register same as write-back base")
7120 : _("source register same as write-back base"));
7121 }
7122
7123 /* inst.operands[i] was set up by parse_address. Encode it into an
7124 ARM-format mode 2 load or store instruction. If is_t is true,
7125 reject forms that cannot be used with a T instruction (i.e. not
7126 post-indexed). */
7127 static void
7128 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7129 {
7130 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7131
7132 encode_arm_addr_mode_common (i, is_t);
7133
7134 if (inst.operands[i].immisreg)
7135 {
7136 constraint ((inst.operands[i].imm == REG_PC
7137 || (is_pc && inst.operands[i].writeback)),
7138 BAD_PC_ADDRESSING);
7139 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7140 inst.instruction |= inst.operands[i].imm;
7141 if (!inst.operands[i].negative)
7142 inst.instruction |= INDEX_UP;
7143 if (inst.operands[i].shifted)
7144 {
7145 if (inst.operands[i].shift_kind == SHIFT_RRX)
7146 inst.instruction |= SHIFT_ROR << 5;
7147 else
7148 {
7149 inst.instruction |= inst.operands[i].shift_kind << 5;
7150 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7151 }
7152 }
7153 }
7154 else /* immediate offset in inst.reloc */
7155 {
7156 if (is_pc && !inst.reloc.pc_rel)
7157 {
7158 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7159
7160 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7161 cannot use PC in addressing.
7162 PC cannot be used in writeback addressing, either. */
7163 constraint ((is_t || inst.operands[i].writeback),
7164 BAD_PC_ADDRESSING);
7165
7166 /* Use of PC in str is deprecated for ARMv7. */
7167 if (warn_on_deprecated
7168 && !is_load
7169 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7170 as_warn (_("use of PC in this instruction is deprecated"));
7171 }
7172
7173 if (inst.reloc.type == BFD_RELOC_UNUSED)
7174 {
7175 /* Prefer + for zero encoded value. */
7176 if (!inst.operands[i].negative)
7177 inst.instruction |= INDEX_UP;
7178 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7179 }
7180 }
7181 }
7182
7183 /* inst.operands[i] was set up by parse_address. Encode it into an
7184 ARM-format mode 3 load or store instruction. Reject forms that
7185 cannot be used with such instructions. If is_t is true, reject
7186 forms that cannot be used with a T instruction (i.e. not
7187 post-indexed). */
7188 static void
7189 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7190 {
7191 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7192 {
7193 inst.error = _("instruction does not accept scaled register index");
7194 return;
7195 }
7196
7197 encode_arm_addr_mode_common (i, is_t);
7198
7199 if (inst.operands[i].immisreg)
7200 {
7201 constraint ((inst.operands[i].imm == REG_PC
7202 || inst.operands[i].reg == REG_PC),
7203 BAD_PC_ADDRESSING);
7204 inst.instruction |= inst.operands[i].imm;
7205 if (!inst.operands[i].negative)
7206 inst.instruction |= INDEX_UP;
7207 }
7208 else /* immediate offset in inst.reloc */
7209 {
7210 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7211 && inst.operands[i].writeback),
7212 BAD_PC_WRITEBACK);
7213 inst.instruction |= HWOFFSET_IMM;
7214 if (inst.reloc.type == BFD_RELOC_UNUSED)
7215 {
7216 /* Prefer + for zero encoded value. */
7217 if (!inst.operands[i].negative)
7218 inst.instruction |= INDEX_UP;
7219
7220 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7221 }
7222 }
7223 }
7224
7225 /* inst.operands[i] was set up by parse_address. Encode it into an
7226 ARM-format instruction. Reject all forms which cannot be encoded
7227 into a coprocessor load/store instruction. If wb_ok is false,
7228 reject use of writeback; if unind_ok is false, reject use of
7229 unindexed addressing. If reloc_override is not 0, use it instead
7230 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7231 (in which case it is preserved). */
7232
7233 static int
7234 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7235 {
7236 inst.instruction |= inst.operands[i].reg << 16;
7237
7238 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
7239
7240 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
7241 {
7242 gas_assert (!inst.operands[i].writeback);
7243 if (!unind_ok)
7244 {
7245 inst.error = _("instruction does not support unindexed addressing");
7246 return FAIL;
7247 }
7248 inst.instruction |= inst.operands[i].imm;
7249 inst.instruction |= INDEX_UP;
7250 return SUCCESS;
7251 }
7252
7253 if (inst.operands[i].preind)
7254 inst.instruction |= PRE_INDEX;
7255
7256 if (inst.operands[i].writeback)
7257 {
7258 if (inst.operands[i].reg == REG_PC)
7259 {
7260 inst.error = _("pc may not be used with write-back");
7261 return FAIL;
7262 }
7263 if (!wb_ok)
7264 {
7265 inst.error = _("instruction does not support writeback");
7266 return FAIL;
7267 }
7268 inst.instruction |= WRITE_BACK;
7269 }
7270
7271 if (reloc_override)
7272 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
7273 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7274 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7275 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7276 {
7277 if (thumb_mode)
7278 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7279 else
7280 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7281 }
7282
7283 /* Prefer + for zero encoded value. */
7284 if (!inst.operands[i].negative)
7285 inst.instruction |= INDEX_UP;
7286
7287 return SUCCESS;
7288 }
7289
7290 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7291 Determine whether it can be performed with a move instruction; if
7292 it can, convert inst.instruction to that move instruction and
7293 return TRUE; if it can't, convert inst.instruction to a literal-pool
7294 load and return FALSE. If this is not a valid thing to do in the
7295 current context, set inst.error and return TRUE.
7296
7297 inst.operands[i] describes the destination register. */
7298
7299 static bfd_boolean
7300 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7301 {
7302 unsigned long tbit;
7303
7304 if (thumb_p)
7305 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7306 else
7307 tbit = LOAD_BIT;
7308
7309 if ((inst.instruction & tbit) == 0)
7310 {
7311 inst.error = _("invalid pseudo operation");
7312 return TRUE;
7313 }
7314 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
7315 {
7316 inst.error = _("constant expression expected");
7317 return TRUE;
7318 }
7319 if (inst.reloc.exp.X_op == O_constant)
7320 {
7321 if (thumb_p)
7322 {
7323 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7324 {
7325 /* This can be done with a mov(1) instruction. */
7326 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7327 inst.instruction |= inst.reloc.exp.X_add_number;
7328 return TRUE;
7329 }
7330 }
7331 else
7332 {
7333 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7334 if (value != FAIL)
7335 {
7336 /* This can be done with a mov instruction. */
7337 inst.instruction &= LITERAL_MASK;
7338 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7339 inst.instruction |= value & 0xfff;
7340 return TRUE;
7341 }
7342
7343 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7344 if (value != FAIL)
7345 {
7346 /* This can be done with a mvn instruction. */
7347 inst.instruction &= LITERAL_MASK;
7348 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7349 inst.instruction |= value & 0xfff;
7350 return TRUE;
7351 }
7352 }
7353 }
7354
7355 if (add_to_lit_pool () == FAIL)
7356 {
7357 inst.error = _("literal pool insertion failed");
7358 return TRUE;
7359 }
7360 inst.operands[1].reg = REG_PC;
7361 inst.operands[1].isreg = 1;
7362 inst.operands[1].preind = 1;
7363 inst.reloc.pc_rel = 1;
7364 inst.reloc.type = (thumb_p
7365 ? BFD_RELOC_ARM_THUMB_OFFSET
7366 : (mode_3
7367 ? BFD_RELOC_ARM_HWLITERAL
7368 : BFD_RELOC_ARM_LITERAL));
7369 return FALSE;
7370 }
7371
7372 /* Functions for instruction encoding, sorted by sub-architecture.
7373 First some generics; their names are taken from the conventional
7374 bit positions for register arguments in ARM format instructions. */
7375
7376 static void
7377 do_noargs (void)
7378 {
7379 }
7380
7381 static void
7382 do_rd (void)
7383 {
7384 inst.instruction |= inst.operands[0].reg << 12;
7385 }
7386
7387 static void
7388 do_rd_rm (void)
7389 {
7390 inst.instruction |= inst.operands[0].reg << 12;
7391 inst.instruction |= inst.operands[1].reg;
7392 }
7393
7394 static void
7395 do_rm_rn (void)
7396 {
7397 inst.instruction |= inst.operands[0].reg;
7398 inst.instruction |= inst.operands[1].reg << 16;
7399 }
7400
7401 static void
7402 do_rd_rn (void)
7403 {
7404 inst.instruction |= inst.operands[0].reg << 12;
7405 inst.instruction |= inst.operands[1].reg << 16;
7406 }
7407
7408 static void
7409 do_rn_rd (void)
7410 {
7411 inst.instruction |= inst.operands[0].reg << 16;
7412 inst.instruction |= inst.operands[1].reg << 12;
7413 }
7414
7415 static bfd_boolean
7416 check_obsolete (const arm_feature_set *feature, const char *msg)
7417 {
7418 if (ARM_CPU_IS_ANY (cpu_variant))
7419 {
7420 as_warn ("%s", msg);
7421 return TRUE;
7422 }
7423 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
7424 {
7425 as_bad ("%s", msg);
7426 return TRUE;
7427 }
7428
7429 return FALSE;
7430 }
7431
7432 static void
7433 do_rd_rm_rn (void)
7434 {
7435 unsigned Rn = inst.operands[2].reg;
7436 /* Enforce restrictions on SWP instruction. */
7437 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7438 {
7439 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7440 _("Rn must not overlap other operands"));
7441
7442 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
7443 */
7444 if (!check_obsolete (&arm_ext_v8,
7445 _("swp{b} use is obsoleted for ARMv8 and later"))
7446 && warn_on_deprecated
7447 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
7448 as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
7449 }
7450
7451 inst.instruction |= inst.operands[0].reg << 12;
7452 inst.instruction |= inst.operands[1].reg;
7453 inst.instruction |= Rn << 16;
7454 }
7455
7456 static void
7457 do_rd_rn_rm (void)
7458 {
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= inst.operands[1].reg << 16;
7461 inst.instruction |= inst.operands[2].reg;
7462 }
7463
7464 static void
7465 do_rm_rd_rn (void)
7466 {
7467 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7468 constraint (((inst.reloc.exp.X_op != O_constant
7469 && inst.reloc.exp.X_op != O_illegal)
7470 || inst.reloc.exp.X_add_number != 0),
7471 BAD_ADDR_MODE);
7472 inst.instruction |= inst.operands[0].reg;
7473 inst.instruction |= inst.operands[1].reg << 12;
7474 inst.instruction |= inst.operands[2].reg << 16;
7475 }
7476
7477 static void
7478 do_imm0 (void)
7479 {
7480 inst.instruction |= inst.operands[0].imm;
7481 }
7482
7483 static void
7484 do_rd_cpaddr (void)
7485 {
7486 inst.instruction |= inst.operands[0].reg << 12;
7487 encode_arm_cp_address (1, TRUE, TRUE, 0);
7488 }
7489
7490 /* ARM instructions, in alphabetical order by function name (except
7491 that wrapper functions appear immediately after the function they
7492 wrap). */
7493
7494 /* This is a pseudo-op of the form "adr rd, label" to be converted
7495 into a relative address of the form "add rd, pc, #label-.-8". */
7496
7497 static void
7498 do_adr (void)
7499 {
7500 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7501
7502 /* Frag hacking will turn this into a sub instruction if the offset turns
7503 out to be negative. */
7504 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7505 inst.reloc.pc_rel = 1;
7506 inst.reloc.exp.X_add_number -= 8;
7507 }
7508
7509 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7510 into a relative address of the form:
7511 add rd, pc, #low(label-.-8)"
7512 add rd, rd, #high(label-.-8)" */
7513
7514 static void
7515 do_adrl (void)
7516 {
7517 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7518
7519 /* Frag hacking will turn this into a sub instruction if the offset turns
7520 out to be negative. */
7521 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7522 inst.reloc.pc_rel = 1;
7523 inst.size = INSN_SIZE * 2;
7524 inst.reloc.exp.X_add_number -= 8;
7525 }
7526
7527 static void
7528 do_arit (void)
7529 {
7530 if (!inst.operands[1].present)
7531 inst.operands[1].reg = inst.operands[0].reg;
7532 inst.instruction |= inst.operands[0].reg << 12;
7533 inst.instruction |= inst.operands[1].reg << 16;
7534 encode_arm_shifter_operand (2);
7535 }
7536
7537 static void
7538 do_barrier (void)
7539 {
7540 if (inst.operands[0].present)
7541 {
7542 constraint ((inst.instruction & 0xf0) != 0x40
7543 && inst.operands[0].imm > 0xf
7544 && inst.operands[0].imm < 0x0,
7545 _("bad barrier type"));
7546 inst.instruction |= inst.operands[0].imm;
7547 }
7548 else
7549 inst.instruction |= 0xf;
7550 }
7551
7552 static void
7553 do_bfc (void)
7554 {
7555 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7556 constraint (msb > 32, _("bit-field extends past end of register"));
7557 /* The instruction encoding stores the LSB and MSB,
7558 not the LSB and width. */
7559 inst.instruction |= inst.operands[0].reg << 12;
7560 inst.instruction |= inst.operands[1].imm << 7;
7561 inst.instruction |= (msb - 1) << 16;
7562 }
7563
7564 static void
7565 do_bfi (void)
7566 {
7567 unsigned int msb;
7568
7569 /* #0 in second position is alternative syntax for bfc, which is
7570 the same instruction but with REG_PC in the Rm field. */
7571 if (!inst.operands[1].isreg)
7572 inst.operands[1].reg = REG_PC;
7573
7574 msb = inst.operands[2].imm + inst.operands[3].imm;
7575 constraint (msb > 32, _("bit-field extends past end of register"));
7576 /* The instruction encoding stores the LSB and MSB,
7577 not the LSB and width. */
7578 inst.instruction |= inst.operands[0].reg << 12;
7579 inst.instruction |= inst.operands[1].reg;
7580 inst.instruction |= inst.operands[2].imm << 7;
7581 inst.instruction |= (msb - 1) << 16;
7582 }
7583
7584 static void
7585 do_bfx (void)
7586 {
7587 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7588 _("bit-field extends past end of register"));
7589 inst.instruction |= inst.operands[0].reg << 12;
7590 inst.instruction |= inst.operands[1].reg;
7591 inst.instruction |= inst.operands[2].imm << 7;
7592 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7593 }
7594
7595 /* ARM V5 breakpoint instruction (argument parse)
7596 BKPT <16 bit unsigned immediate>
7597 Instruction is not conditional.
7598 The bit pattern given in insns[] has the COND_ALWAYS condition,
7599 and it is an error if the caller tried to override that. */
7600
7601 static void
7602 do_bkpt (void)
7603 {
7604 /* Top 12 of 16 bits to bits 19:8. */
7605 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7606
7607 /* Bottom 4 of 16 bits to bits 3:0. */
7608 inst.instruction |= inst.operands[0].imm & 0xf;
7609 }
7610
7611 static void
7612 encode_branch (int default_reloc)
7613 {
7614 if (inst.operands[0].hasreloc)
7615 {
7616 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7617 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7618 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7619 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7620 ? BFD_RELOC_ARM_PLT32
7621 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
7622 }
7623 else
7624 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7625 inst.reloc.pc_rel = 1;
7626 }
7627
7628 static void
7629 do_branch (void)
7630 {
7631 #ifdef OBJ_ELF
7632 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7633 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7634 else
7635 #endif
7636 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7637 }
7638
7639 static void
7640 do_bl (void)
7641 {
7642 #ifdef OBJ_ELF
7643 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7644 {
7645 if (inst.cond == COND_ALWAYS)
7646 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7647 else
7648 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7649 }
7650 else
7651 #endif
7652 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7653 }
7654
7655 /* ARM V5 branch-link-exchange instruction (argument parse)
7656 BLX <target_addr> ie BLX(1)
7657 BLX{<condition>} <Rm> ie BLX(2)
7658 Unfortunately, there are two different opcodes for this mnemonic.
7659 So, the insns[].value is not used, and the code here zaps values
7660 into inst.instruction.
7661 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7662
7663 static void
7664 do_blx (void)
7665 {
7666 if (inst.operands[0].isreg)
7667 {
7668 /* Arg is a register; the opcode provided by insns[] is correct.
7669 It is not illegal to do "blx pc", just useless. */
7670 if (inst.operands[0].reg == REG_PC)
7671 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7672
7673 inst.instruction |= inst.operands[0].reg;
7674 }
7675 else
7676 {
7677 /* Arg is an address; this instruction cannot be executed
7678 conditionally, and the opcode must be adjusted.
7679 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7680 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7681 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7682 inst.instruction = 0xfa000000;
7683 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7684 }
7685 }
7686
7687 static void
7688 do_bx (void)
7689 {
7690 bfd_boolean want_reloc;
7691
7692 if (inst.operands[0].reg == REG_PC)
7693 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7694
7695 inst.instruction |= inst.operands[0].reg;
7696 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7697 it is for ARMv4t or earlier. */
7698 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7699 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7700 want_reloc = TRUE;
7701
7702 #ifdef OBJ_ELF
7703 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7704 #endif
7705 want_reloc = FALSE;
7706
7707 if (want_reloc)
7708 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7709 }
7710
7711
7712 /* ARM v5TEJ. Jump to Jazelle code. */
7713
7714 static void
7715 do_bxj (void)
7716 {
7717 if (inst.operands[0].reg == REG_PC)
7718 as_tsktsk (_("use of r15 in bxj is not really useful"));
7719
7720 inst.instruction |= inst.operands[0].reg;
7721 }
7722
7723 /* Co-processor data operation:
7724 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7725 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7726 static void
7727 do_cdp (void)
7728 {
7729 inst.instruction |= inst.operands[0].reg << 8;
7730 inst.instruction |= inst.operands[1].imm << 20;
7731 inst.instruction |= inst.operands[2].reg << 12;
7732 inst.instruction |= inst.operands[3].reg << 16;
7733 inst.instruction |= inst.operands[4].reg;
7734 inst.instruction |= inst.operands[5].imm << 5;
7735 }
7736
7737 static void
7738 do_cmp (void)
7739 {
7740 inst.instruction |= inst.operands[0].reg << 16;
7741 encode_arm_shifter_operand (1);
7742 }
7743
7744 /* Transfer between coprocessor and ARM registers.
7745 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7746 MRC2
7747 MCR{cond}
7748 MCR2
7749
7750 No special properties. */
7751
7752 struct deprecated_coproc_regs_s
7753 {
7754 unsigned cp;
7755 int opc1;
7756 unsigned crn;
7757 unsigned crm;
7758 int opc2;
7759 arm_feature_set deprecated;
7760 arm_feature_set obsoleted;
7761 const char *dep_msg;
7762 const char *obs_msg;
7763 };
7764
7765 #define DEPR_ACCESS_V8 \
7766 N_("This coprocessor register access is deprecated in ARMv8")
7767
7768 /* Table of all deprecated coprocessor registers. */
7769 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
7770 {
7771 {15, 0, 7, 10, 5, /* CP15DMB. */
7772 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7773 DEPR_ACCESS_V8, NULL},
7774 {15, 0, 7, 10, 4, /* CP15DSB. */
7775 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7776 DEPR_ACCESS_V8, NULL},
7777 {15, 0, 7, 5, 4, /* CP15ISB. */
7778 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7779 DEPR_ACCESS_V8, NULL},
7780 {14, 6, 1, 0, 0, /* TEEHBR. */
7781 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7782 DEPR_ACCESS_V8, NULL},
7783 {14, 6, 0, 0, 0, /* TEECR. */
7784 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7785 DEPR_ACCESS_V8, NULL},
7786 };
7787
7788 #undef DEPR_ACCESS_V8
7789
7790 static const size_t deprecated_coproc_reg_count =
7791 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
7792
7793 static void
7794 do_co_reg (void)
7795 {
7796 unsigned Rd;
7797 size_t i;
7798
7799 Rd = inst.operands[2].reg;
7800 if (thumb_mode)
7801 {
7802 if (inst.instruction == 0xee000010
7803 || inst.instruction == 0xfe000010)
7804 /* MCR, MCR2 */
7805 reject_bad_reg (Rd);
7806 else
7807 /* MRC, MRC2 */
7808 constraint (Rd == REG_SP, BAD_SP);
7809 }
7810 else
7811 {
7812 /* MCR */
7813 if (inst.instruction == 0xe000010)
7814 constraint (Rd == REG_PC, BAD_PC);
7815 }
7816
7817 for (i = 0; i < deprecated_coproc_reg_count; ++i)
7818 {
7819 const struct deprecated_coproc_regs_s *r =
7820 deprecated_coproc_regs + i;
7821
7822 if (inst.operands[0].reg == r->cp
7823 && inst.operands[1].imm == r->opc1
7824 && inst.operands[3].reg == r->crn
7825 && inst.operands[4].reg == r->crm
7826 && inst.operands[5].imm == r->opc2)
7827 {
7828 if (!check_obsolete (&r->obsoleted, r->obs_msg)
7829 && warn_on_deprecated
7830 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
7831 as_warn ("%s", r->dep_msg);
7832 }
7833 }
7834
7835 inst.instruction |= inst.operands[0].reg << 8;
7836 inst.instruction |= inst.operands[1].imm << 21;
7837 inst.instruction |= Rd << 12;
7838 inst.instruction |= inst.operands[3].reg << 16;
7839 inst.instruction |= inst.operands[4].reg;
7840 inst.instruction |= inst.operands[5].imm << 5;
7841 }
7842
7843 /* Transfer between coprocessor register and pair of ARM registers.
7844 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7845 MCRR2
7846 MRRC{cond}
7847 MRRC2
7848
7849 Two XScale instructions are special cases of these:
7850
7851 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7852 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7853
7854 Result unpredictable if Rd or Rn is R15. */
7855
7856 static void
7857 do_co_reg2c (void)
7858 {
7859 unsigned Rd, Rn;
7860
7861 Rd = inst.operands[2].reg;
7862 Rn = inst.operands[3].reg;
7863
7864 if (thumb_mode)
7865 {
7866 reject_bad_reg (Rd);
7867 reject_bad_reg (Rn);
7868 }
7869 else
7870 {
7871 constraint (Rd == REG_PC, BAD_PC);
7872 constraint (Rn == REG_PC, BAD_PC);
7873 }
7874
7875 inst.instruction |= inst.operands[0].reg << 8;
7876 inst.instruction |= inst.operands[1].imm << 4;
7877 inst.instruction |= Rd << 12;
7878 inst.instruction |= Rn << 16;
7879 inst.instruction |= inst.operands[4].reg;
7880 }
7881
7882 static void
7883 do_cpsi (void)
7884 {
7885 inst.instruction |= inst.operands[0].imm << 6;
7886 if (inst.operands[1].present)
7887 {
7888 inst.instruction |= CPSI_MMOD;
7889 inst.instruction |= inst.operands[1].imm;
7890 }
7891 }
7892
7893 static void
7894 do_dbg (void)
7895 {
7896 inst.instruction |= inst.operands[0].imm;
7897 }
7898
7899 static void
7900 do_div (void)
7901 {
7902 unsigned Rd, Rn, Rm;
7903
7904 Rd = inst.operands[0].reg;
7905 Rn = (inst.operands[1].present
7906 ? inst.operands[1].reg : Rd);
7907 Rm = inst.operands[2].reg;
7908
7909 constraint ((Rd == REG_PC), BAD_PC);
7910 constraint ((Rn == REG_PC), BAD_PC);
7911 constraint ((Rm == REG_PC), BAD_PC);
7912
7913 inst.instruction |= Rd << 16;
7914 inst.instruction |= Rn << 0;
7915 inst.instruction |= Rm << 8;
7916 }
7917
7918 static void
7919 do_it (void)
7920 {
7921 /* There is no IT instruction in ARM mode. We
7922 process it to do the validation as if in
7923 thumb mode, just in case the code gets
7924 assembled for thumb using the unified syntax. */
7925
7926 inst.size = 0;
7927 if (unified_syntax)
7928 {
7929 set_it_insn_type (IT_INSN);
7930 now_it.mask = (inst.instruction & 0xf) | 0x10;
7931 now_it.cc = inst.operands[0].imm;
7932 }
7933 }
7934
7935 /* If there is only one register in the register list,
7936 then return its register number. Otherwise return -1. */
7937 static int
7938 only_one_reg_in_list (int range)
7939 {
7940 int i = ffs (range) - 1;
7941 return (i > 15 || range != (1 << i)) ? -1 : i;
7942 }
7943
7944 static void
7945 encode_ldmstm(int from_push_pop_mnem)
7946 {
7947 int base_reg = inst.operands[0].reg;
7948 int range = inst.operands[1].imm;
7949 int one_reg;
7950
7951 inst.instruction |= base_reg << 16;
7952 inst.instruction |= range;
7953
7954 if (inst.operands[1].writeback)
7955 inst.instruction |= LDM_TYPE_2_OR_3;
7956
7957 if (inst.operands[0].writeback)
7958 {
7959 inst.instruction |= WRITE_BACK;
7960 /* Check for unpredictable uses of writeback. */
7961 if (inst.instruction & LOAD_BIT)
7962 {
7963 /* Not allowed in LDM type 2. */
7964 if ((inst.instruction & LDM_TYPE_2_OR_3)
7965 && ((range & (1 << REG_PC)) == 0))
7966 as_warn (_("writeback of base register is UNPREDICTABLE"));
7967 /* Only allowed if base reg not in list for other types. */
7968 else if (range & (1 << base_reg))
7969 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7970 }
7971 else /* STM. */
7972 {
7973 /* Not allowed for type 2. */
7974 if (inst.instruction & LDM_TYPE_2_OR_3)
7975 as_warn (_("writeback of base register is UNPREDICTABLE"));
7976 /* Only allowed if base reg not in list, or first in list. */
7977 else if ((range & (1 << base_reg))
7978 && (range & ((1 << base_reg) - 1)))
7979 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7980 }
7981 }
7982
7983 /* If PUSH/POP has only one register, then use the A2 encoding. */
7984 one_reg = only_one_reg_in_list (range);
7985 if (from_push_pop_mnem && one_reg >= 0)
7986 {
7987 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
7988
7989 inst.instruction &= A_COND_MASK;
7990 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
7991 inst.instruction |= one_reg << 12;
7992 }
7993 }
7994
7995 static void
7996 do_ldmstm (void)
7997 {
7998 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
7999 }
8000
8001 /* ARMv5TE load-consecutive (argument parse)
8002 Mode is like LDRH.
8003
8004 LDRccD R, mode
8005 STRccD R, mode. */
8006
8007 static void
8008 do_ldrd (void)
8009 {
8010 constraint (inst.operands[0].reg % 2 != 0,
8011 _("first transfer register must be even"));
8012 constraint (inst.operands[1].present
8013 && inst.operands[1].reg != inst.operands[0].reg + 1,
8014 _("can only transfer two consecutive registers"));
8015 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8016 constraint (!inst.operands[2].isreg, _("'[' expected"));
8017
8018 if (!inst.operands[1].present)
8019 inst.operands[1].reg = inst.operands[0].reg + 1;
8020
8021 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8022 register and the first register written; we have to diagnose
8023 overlap between the base and the second register written here. */
8024
8025 if (inst.operands[2].reg == inst.operands[1].reg
8026 && (inst.operands[2].writeback || inst.operands[2].postind))
8027 as_warn (_("base register written back, and overlaps "
8028 "second transfer register"));
8029
8030 if (!(inst.instruction & V4_STR_BIT))
8031 {
8032 /* For an index-register load, the index register must not overlap the
8033 destination (even if not write-back). */
8034 if (inst.operands[2].immisreg
8035 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8036 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8037 as_warn (_("index register overlaps transfer register"));
8038 }
8039 inst.instruction |= inst.operands[0].reg << 12;
8040 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
8041 }
8042
8043 static void
8044 do_ldrex (void)
8045 {
8046 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8047 || inst.operands[1].postind || inst.operands[1].writeback
8048 || inst.operands[1].immisreg || inst.operands[1].shifted
8049 || inst.operands[1].negative
8050 /* This can arise if the programmer has written
8051 strex rN, rM, foo
8052 or if they have mistakenly used a register name as the last
8053 operand, eg:
8054 strex rN, rM, rX
8055 It is very difficult to distinguish between these two cases
8056 because "rX" might actually be a label. ie the register
8057 name has been occluded by a symbol of the same name. So we
8058 just generate a general 'bad addressing mode' type error
8059 message and leave it up to the programmer to discover the
8060 true cause and fix their mistake. */
8061 || (inst.operands[1].reg == REG_PC),
8062 BAD_ADDR_MODE);
8063
8064 constraint (inst.reloc.exp.X_op != O_constant
8065 || inst.reloc.exp.X_add_number != 0,
8066 _("offset must be zero in ARM encoding"));
8067
8068 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8069
8070 inst.instruction |= inst.operands[0].reg << 12;
8071 inst.instruction |= inst.operands[1].reg << 16;
8072 inst.reloc.type = BFD_RELOC_UNUSED;
8073 }
8074
8075 static void
8076 do_ldrexd (void)
8077 {
8078 constraint (inst.operands[0].reg % 2 != 0,
8079 _("even register required"));
8080 constraint (inst.operands[1].present
8081 && inst.operands[1].reg != inst.operands[0].reg + 1,
8082 _("can only load two consecutive registers"));
8083 /* If op 1 were present and equal to PC, this function wouldn't
8084 have been called in the first place. */
8085 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8086
8087 inst.instruction |= inst.operands[0].reg << 12;
8088 inst.instruction |= inst.operands[2].reg << 16;
8089 }
8090
8091 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8092 which is not a multiple of four is UNPREDICTABLE. */
8093 static void
8094 check_ldr_r15_aligned (void)
8095 {
8096 constraint (!(inst.operands[1].immisreg)
8097 && (inst.operands[0].reg == REG_PC
8098 && inst.operands[1].reg == REG_PC
8099 && (inst.reloc.exp.X_add_number & 0x3)),
8100 _("ldr to register 15 must be 4-byte alligned"));
8101 }
8102
8103 static void
8104 do_ldst (void)
8105 {
8106 inst.instruction |= inst.operands[0].reg << 12;
8107 if (!inst.operands[1].isreg)
8108 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
8109 return;
8110 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
8111 check_ldr_r15_aligned ();
8112 }
8113
8114 static void
8115 do_ldstt (void)
8116 {
8117 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8118 reject [Rn,...]. */
8119 if (inst.operands[1].preind)
8120 {
8121 constraint (inst.reloc.exp.X_op != O_constant
8122 || inst.reloc.exp.X_add_number != 0,
8123 _("this instruction requires a post-indexed address"));
8124
8125 inst.operands[1].preind = 0;
8126 inst.operands[1].postind = 1;
8127 inst.operands[1].writeback = 1;
8128 }
8129 inst.instruction |= inst.operands[0].reg << 12;
8130 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8131 }
8132
8133 /* Halfword and signed-byte load/store operations. */
8134
8135 static void
8136 do_ldstv4 (void)
8137 {
8138 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8139 inst.instruction |= inst.operands[0].reg << 12;
8140 if (!inst.operands[1].isreg)
8141 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
8142 return;
8143 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
8144 }
8145
8146 static void
8147 do_ldsttv4 (void)
8148 {
8149 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8150 reject [Rn,...]. */
8151 if (inst.operands[1].preind)
8152 {
8153 constraint (inst.reloc.exp.X_op != O_constant
8154 || inst.reloc.exp.X_add_number != 0,
8155 _("this instruction requires a post-indexed address"));
8156
8157 inst.operands[1].preind = 0;
8158 inst.operands[1].postind = 1;
8159 inst.operands[1].writeback = 1;
8160 }
8161 inst.instruction |= inst.operands[0].reg << 12;
8162 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8163 }
8164
8165 /* Co-processor register load/store.
8166 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8167 static void
8168 do_lstc (void)
8169 {
8170 inst.instruction |= inst.operands[0].reg << 8;
8171 inst.instruction |= inst.operands[1].reg << 12;
8172 encode_arm_cp_address (2, TRUE, TRUE, 0);
8173 }
8174
8175 static void
8176 do_mlas (void)
8177 {
8178 /* This restriction does not apply to mls (nor to mla in v6 or later). */
8179 if (inst.operands[0].reg == inst.operands[1].reg
8180 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
8181 && !(inst.instruction & 0x00400000))
8182 as_tsktsk (_("Rd and Rm should be different in mla"));
8183
8184 inst.instruction |= inst.operands[0].reg << 16;
8185 inst.instruction |= inst.operands[1].reg;
8186 inst.instruction |= inst.operands[2].reg << 8;
8187 inst.instruction |= inst.operands[3].reg << 12;
8188 }
8189
8190 static void
8191 do_mov (void)
8192 {
8193 inst.instruction |= inst.operands[0].reg << 12;
8194 encode_arm_shifter_operand (1);
8195 }
8196
8197 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8198 static void
8199 do_mov16 (void)
8200 {
8201 bfd_vma imm;
8202 bfd_boolean top;
8203
8204 top = (inst.instruction & 0x00400000) != 0;
8205 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8206 _(":lower16: not allowed this instruction"));
8207 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8208 _(":upper16: not allowed instruction"));
8209 inst.instruction |= inst.operands[0].reg << 12;
8210 if (inst.reloc.type == BFD_RELOC_UNUSED)
8211 {
8212 imm = inst.reloc.exp.X_add_number;
8213 /* The value is in two pieces: 0:11, 16:19. */
8214 inst.instruction |= (imm & 0x00000fff);
8215 inst.instruction |= (imm & 0x0000f000) << 4;
8216 }
8217 }
8218
8219 static void do_vfp_nsyn_opcode (const char *);
8220
8221 static int
8222 do_vfp_nsyn_mrs (void)
8223 {
8224 if (inst.operands[0].isvec)
8225 {
8226 if (inst.operands[1].reg != 1)
8227 first_error (_("operand 1 must be FPSCR"));
8228 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8229 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8230 do_vfp_nsyn_opcode ("fmstat");
8231 }
8232 else if (inst.operands[1].isvec)
8233 do_vfp_nsyn_opcode ("fmrx");
8234 else
8235 return FAIL;
8236
8237 return SUCCESS;
8238 }
8239
8240 static int
8241 do_vfp_nsyn_msr (void)
8242 {
8243 if (inst.operands[0].isvec)
8244 do_vfp_nsyn_opcode ("fmxr");
8245 else
8246 return FAIL;
8247
8248 return SUCCESS;
8249 }
8250
8251 static void
8252 do_vmrs (void)
8253 {
8254 unsigned Rt = inst.operands[0].reg;
8255
8256 if (thumb_mode && inst.operands[0].reg == REG_SP)
8257 {
8258 inst.error = BAD_SP;
8259 return;
8260 }
8261
8262 /* APSR_ sets isvec. All other refs to PC are illegal. */
8263 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8264 {
8265 inst.error = BAD_PC;
8266 return;
8267 }
8268
8269 switch (inst.operands[1].reg)
8270 {
8271 case 0: /* FPSID */
8272 case 1: /* FPSCR */
8273 case 6: /* MVFR1 */
8274 case 7: /* MVFR0 */
8275 case 8: /* FPEXC */
8276 inst.instruction |= (inst.operands[1].reg << 16);
8277 break;
8278 default:
8279 first_error (_("operand 1 must be a VFP extension System Register"));
8280 }
8281
8282 inst.instruction |= (Rt << 12);
8283 }
8284
8285 static void
8286 do_vmsr (void)
8287 {
8288 unsigned Rt = inst.operands[1].reg;
8289
8290 if (thumb_mode)
8291 reject_bad_reg (Rt);
8292 else if (Rt == REG_PC)
8293 {
8294 inst.error = BAD_PC;
8295 return;
8296 }
8297
8298 switch (inst.operands[0].reg)
8299 {
8300 case 0: /* FPSID */
8301 case 1: /* FPSCR */
8302 case 8: /* FPEXC */
8303 inst.instruction |= (inst.operands[0].reg << 16);
8304 break;
8305 default:
8306 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8307 }
8308
8309 inst.instruction |= (Rt << 12);
8310 }
8311
8312 static void
8313 do_mrs (void)
8314 {
8315 unsigned br;
8316
8317 if (do_vfp_nsyn_mrs () == SUCCESS)
8318 return;
8319
8320 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8321 inst.instruction |= inst.operands[0].reg << 12;
8322
8323 if (inst.operands[1].isreg)
8324 {
8325 br = inst.operands[1].reg;
8326 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8327 as_bad (_("bad register for mrs"));
8328 }
8329 else
8330 {
8331 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8332 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8333 != (PSR_c|PSR_f),
8334 _("'APSR', 'CPSR' or 'SPSR' expected"));
8335 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8336 }
8337
8338 inst.instruction |= br;
8339 }
8340
8341 /* Two possible forms:
8342 "{C|S}PSR_<field>, Rm",
8343 "{C|S}PSR_f, #expression". */
8344
8345 static void
8346 do_msr (void)
8347 {
8348 if (do_vfp_nsyn_msr () == SUCCESS)
8349 return;
8350
8351 inst.instruction |= inst.operands[0].imm;
8352 if (inst.operands[1].isreg)
8353 inst.instruction |= inst.operands[1].reg;
8354 else
8355 {
8356 inst.instruction |= INST_IMMEDIATE;
8357 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8358 inst.reloc.pc_rel = 0;
8359 }
8360 }
8361
8362 static void
8363 do_mul (void)
8364 {
8365 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8366
8367 if (!inst.operands[2].present)
8368 inst.operands[2].reg = inst.operands[0].reg;
8369 inst.instruction |= inst.operands[0].reg << 16;
8370 inst.instruction |= inst.operands[1].reg;
8371 inst.instruction |= inst.operands[2].reg << 8;
8372
8373 if (inst.operands[0].reg == inst.operands[1].reg
8374 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8375 as_tsktsk (_("Rd and Rm should be different in mul"));
8376 }
8377
8378 /* Long Multiply Parser
8379 UMULL RdLo, RdHi, Rm, Rs
8380 SMULL RdLo, RdHi, Rm, Rs
8381 UMLAL RdLo, RdHi, Rm, Rs
8382 SMLAL RdLo, RdHi, Rm, Rs. */
8383
8384 static void
8385 do_mull (void)
8386 {
8387 inst.instruction |= inst.operands[0].reg << 12;
8388 inst.instruction |= inst.operands[1].reg << 16;
8389 inst.instruction |= inst.operands[2].reg;
8390 inst.instruction |= inst.operands[3].reg << 8;
8391
8392 /* rdhi and rdlo must be different. */
8393 if (inst.operands[0].reg == inst.operands[1].reg)
8394 as_tsktsk (_("rdhi and rdlo must be different"));
8395
8396 /* rdhi, rdlo and rm must all be different before armv6. */
8397 if ((inst.operands[0].reg == inst.operands[2].reg
8398 || inst.operands[1].reg == inst.operands[2].reg)
8399 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8400 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8401 }
8402
8403 static void
8404 do_nop (void)
8405 {
8406 if (inst.operands[0].present
8407 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
8408 {
8409 /* Architectural NOP hints are CPSR sets with no bits selected. */
8410 inst.instruction &= 0xf0000000;
8411 inst.instruction |= 0x0320f000;
8412 if (inst.operands[0].present)
8413 inst.instruction |= inst.operands[0].imm;
8414 }
8415 }
8416
8417 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8418 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8419 Condition defaults to COND_ALWAYS.
8420 Error if Rd, Rn or Rm are R15. */
8421
8422 static void
8423 do_pkhbt (void)
8424 {
8425 inst.instruction |= inst.operands[0].reg << 12;
8426 inst.instruction |= inst.operands[1].reg << 16;
8427 inst.instruction |= inst.operands[2].reg;
8428 if (inst.operands[3].present)
8429 encode_arm_shift (3);
8430 }
8431
8432 /* ARM V6 PKHTB (Argument Parse). */
8433
8434 static void
8435 do_pkhtb (void)
8436 {
8437 if (!inst.operands[3].present)
8438 {
8439 /* If the shift specifier is omitted, turn the instruction
8440 into pkhbt rd, rm, rn. */
8441 inst.instruction &= 0xfff00010;
8442 inst.instruction |= inst.operands[0].reg << 12;
8443 inst.instruction |= inst.operands[1].reg;
8444 inst.instruction |= inst.operands[2].reg << 16;
8445 }
8446 else
8447 {
8448 inst.instruction |= inst.operands[0].reg << 12;
8449 inst.instruction |= inst.operands[1].reg << 16;
8450 inst.instruction |= inst.operands[2].reg;
8451 encode_arm_shift (3);
8452 }
8453 }
8454
8455 /* ARMv5TE: Preload-Cache
8456 MP Extensions: Preload for write
8457
8458 PLD(W) <addr_mode>
8459
8460 Syntactically, like LDR with B=1, W=0, L=1. */
8461
8462 static void
8463 do_pld (void)
8464 {
8465 constraint (!inst.operands[0].isreg,
8466 _("'[' expected after PLD mnemonic"));
8467 constraint (inst.operands[0].postind,
8468 _("post-indexed expression used in preload instruction"));
8469 constraint (inst.operands[0].writeback,
8470 _("writeback used in preload instruction"));
8471 constraint (!inst.operands[0].preind,
8472 _("unindexed addressing used in preload instruction"));
8473 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8474 }
8475
8476 /* ARMv7: PLI <addr_mode> */
8477 static void
8478 do_pli (void)
8479 {
8480 constraint (!inst.operands[0].isreg,
8481 _("'[' expected after PLI mnemonic"));
8482 constraint (inst.operands[0].postind,
8483 _("post-indexed expression used in preload instruction"));
8484 constraint (inst.operands[0].writeback,
8485 _("writeback used in preload instruction"));
8486 constraint (!inst.operands[0].preind,
8487 _("unindexed addressing used in preload instruction"));
8488 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8489 inst.instruction &= ~PRE_INDEX;
8490 }
8491
8492 static void
8493 do_push_pop (void)
8494 {
8495 inst.operands[1] = inst.operands[0];
8496 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8497 inst.operands[0].isreg = 1;
8498 inst.operands[0].writeback = 1;
8499 inst.operands[0].reg = REG_SP;
8500 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
8501 }
8502
8503 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8504 word at the specified address and the following word
8505 respectively.
8506 Unconditionally executed.
8507 Error if Rn is R15. */
8508
8509 static void
8510 do_rfe (void)
8511 {
8512 inst.instruction |= inst.operands[0].reg << 16;
8513 if (inst.operands[0].writeback)
8514 inst.instruction |= WRITE_BACK;
8515 }
8516
8517 /* ARM V6 ssat (argument parse). */
8518
8519 static void
8520 do_ssat (void)
8521 {
8522 inst.instruction |= inst.operands[0].reg << 12;
8523 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8524 inst.instruction |= inst.operands[2].reg;
8525
8526 if (inst.operands[3].present)
8527 encode_arm_shift (3);
8528 }
8529
8530 /* ARM V6 usat (argument parse). */
8531
8532 static void
8533 do_usat (void)
8534 {
8535 inst.instruction |= inst.operands[0].reg << 12;
8536 inst.instruction |= inst.operands[1].imm << 16;
8537 inst.instruction |= inst.operands[2].reg;
8538
8539 if (inst.operands[3].present)
8540 encode_arm_shift (3);
8541 }
8542
8543 /* ARM V6 ssat16 (argument parse). */
8544
8545 static void
8546 do_ssat16 (void)
8547 {
8548 inst.instruction |= inst.operands[0].reg << 12;
8549 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8550 inst.instruction |= inst.operands[2].reg;
8551 }
8552
8553 static void
8554 do_usat16 (void)
8555 {
8556 inst.instruction |= inst.operands[0].reg << 12;
8557 inst.instruction |= inst.operands[1].imm << 16;
8558 inst.instruction |= inst.operands[2].reg;
8559 }
8560
8561 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8562 preserving the other bits.
8563
8564 setend <endian_specifier>, where <endian_specifier> is either
8565 BE or LE. */
8566
8567 static void
8568 do_setend (void)
8569 {
8570 if (warn_on_deprecated
8571 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8572 as_warn (_("setend use is deprecated for ARMv8"));
8573
8574 if (inst.operands[0].imm)
8575 inst.instruction |= 0x200;
8576 }
8577
8578 static void
8579 do_shift (void)
8580 {
8581 unsigned int Rm = (inst.operands[1].present
8582 ? inst.operands[1].reg
8583 : inst.operands[0].reg);
8584
8585 inst.instruction |= inst.operands[0].reg << 12;
8586 inst.instruction |= Rm;
8587 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8588 {
8589 inst.instruction |= inst.operands[2].reg << 8;
8590 inst.instruction |= SHIFT_BY_REG;
8591 /* PR 12854: Error on extraneous shifts. */
8592 constraint (inst.operands[2].shifted,
8593 _("extraneous shift as part of operand to shift insn"));
8594 }
8595 else
8596 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8597 }
8598
8599 static void
8600 do_smc (void)
8601 {
8602 inst.reloc.type = BFD_RELOC_ARM_SMC;
8603 inst.reloc.pc_rel = 0;
8604 }
8605
8606 static void
8607 do_hvc (void)
8608 {
8609 inst.reloc.type = BFD_RELOC_ARM_HVC;
8610 inst.reloc.pc_rel = 0;
8611 }
8612
8613 static void
8614 do_swi (void)
8615 {
8616 inst.reloc.type = BFD_RELOC_ARM_SWI;
8617 inst.reloc.pc_rel = 0;
8618 }
8619
8620 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8621 SMLAxy{cond} Rd,Rm,Rs,Rn
8622 SMLAWy{cond} Rd,Rm,Rs,Rn
8623 Error if any register is R15. */
8624
8625 static void
8626 do_smla (void)
8627 {
8628 inst.instruction |= inst.operands[0].reg << 16;
8629 inst.instruction |= inst.operands[1].reg;
8630 inst.instruction |= inst.operands[2].reg << 8;
8631 inst.instruction |= inst.operands[3].reg << 12;
8632 }
8633
8634 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8635 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8636 Error if any register is R15.
8637 Warning if Rdlo == Rdhi. */
8638
8639 static void
8640 do_smlal (void)
8641 {
8642 inst.instruction |= inst.operands[0].reg << 12;
8643 inst.instruction |= inst.operands[1].reg << 16;
8644 inst.instruction |= inst.operands[2].reg;
8645 inst.instruction |= inst.operands[3].reg << 8;
8646
8647 if (inst.operands[0].reg == inst.operands[1].reg)
8648 as_tsktsk (_("rdhi and rdlo must be different"));
8649 }
8650
8651 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8652 SMULxy{cond} Rd,Rm,Rs
8653 Error if any register is R15. */
8654
8655 static void
8656 do_smul (void)
8657 {
8658 inst.instruction |= inst.operands[0].reg << 16;
8659 inst.instruction |= inst.operands[1].reg;
8660 inst.instruction |= inst.operands[2].reg << 8;
8661 }
8662
8663 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8664 the same for both ARM and Thumb-2. */
8665
8666 static void
8667 do_srs (void)
8668 {
8669 int reg;
8670
8671 if (inst.operands[0].present)
8672 {
8673 reg = inst.operands[0].reg;
8674 constraint (reg != REG_SP, _("SRS base register must be r13"));
8675 }
8676 else
8677 reg = REG_SP;
8678
8679 inst.instruction |= reg << 16;
8680 inst.instruction |= inst.operands[1].imm;
8681 if (inst.operands[0].writeback || inst.operands[1].writeback)
8682 inst.instruction |= WRITE_BACK;
8683 }
8684
8685 /* ARM V6 strex (argument parse). */
8686
8687 static void
8688 do_strex (void)
8689 {
8690 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8691 || inst.operands[2].postind || inst.operands[2].writeback
8692 || inst.operands[2].immisreg || inst.operands[2].shifted
8693 || inst.operands[2].negative
8694 /* See comment in do_ldrex(). */
8695 || (inst.operands[2].reg == REG_PC),
8696 BAD_ADDR_MODE);
8697
8698 constraint (inst.operands[0].reg == inst.operands[1].reg
8699 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8700
8701 constraint (inst.reloc.exp.X_op != O_constant
8702 || inst.reloc.exp.X_add_number != 0,
8703 _("offset must be zero in ARM encoding"));
8704
8705 inst.instruction |= inst.operands[0].reg << 12;
8706 inst.instruction |= inst.operands[1].reg;
8707 inst.instruction |= inst.operands[2].reg << 16;
8708 inst.reloc.type = BFD_RELOC_UNUSED;
8709 }
8710
8711 static void
8712 do_t_strexbh (void)
8713 {
8714 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8715 || inst.operands[2].postind || inst.operands[2].writeback
8716 || inst.operands[2].immisreg || inst.operands[2].shifted
8717 || inst.operands[2].negative,
8718 BAD_ADDR_MODE);
8719
8720 constraint (inst.operands[0].reg == inst.operands[1].reg
8721 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8722
8723 do_rm_rd_rn ();
8724 }
8725
8726 static void
8727 do_strexd (void)
8728 {
8729 constraint (inst.operands[1].reg % 2 != 0,
8730 _("even register required"));
8731 constraint (inst.operands[2].present
8732 && inst.operands[2].reg != inst.operands[1].reg + 1,
8733 _("can only store two consecutive registers"));
8734 /* If op 2 were present and equal to PC, this function wouldn't
8735 have been called in the first place. */
8736 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8737
8738 constraint (inst.operands[0].reg == inst.operands[1].reg
8739 || inst.operands[0].reg == inst.operands[1].reg + 1
8740 || inst.operands[0].reg == inst.operands[3].reg,
8741 BAD_OVERLAP);
8742
8743 inst.instruction |= inst.operands[0].reg << 12;
8744 inst.instruction |= inst.operands[1].reg;
8745 inst.instruction |= inst.operands[3].reg << 16;
8746 }
8747
8748 /* ARM V8 STRL. */
8749 static void
8750 do_stlex (void)
8751 {
8752 constraint (inst.operands[0].reg == inst.operands[1].reg
8753 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8754
8755 do_rd_rm_rn ();
8756 }
8757
8758 static void
8759 do_t_stlex (void)
8760 {
8761 constraint (inst.operands[0].reg == inst.operands[1].reg
8762 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8763
8764 do_rm_rd_rn ();
8765 }
8766
8767 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8768 extends it to 32-bits, and adds the result to a value in another
8769 register. You can specify a rotation by 0, 8, 16, or 24 bits
8770 before extracting the 16-bit value.
8771 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8772 Condition defaults to COND_ALWAYS.
8773 Error if any register uses R15. */
8774
8775 static void
8776 do_sxtah (void)
8777 {
8778 inst.instruction |= inst.operands[0].reg << 12;
8779 inst.instruction |= inst.operands[1].reg << 16;
8780 inst.instruction |= inst.operands[2].reg;
8781 inst.instruction |= inst.operands[3].imm << 10;
8782 }
8783
8784 /* ARM V6 SXTH.
8785
8786 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8787 Condition defaults to COND_ALWAYS.
8788 Error if any register uses R15. */
8789
8790 static void
8791 do_sxth (void)
8792 {
8793 inst.instruction |= inst.operands[0].reg << 12;
8794 inst.instruction |= inst.operands[1].reg;
8795 inst.instruction |= inst.operands[2].imm << 10;
8796 }
8797 \f
8798 /* VFP instructions. In a logical order: SP variant first, monad
8799 before dyad, arithmetic then move then load/store. */
8800
8801 static void
8802 do_vfp_sp_monadic (void)
8803 {
8804 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8805 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8806 }
8807
8808 static void
8809 do_vfp_sp_dyadic (void)
8810 {
8811 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8812 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8813 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8814 }
8815
8816 static void
8817 do_vfp_sp_compare_z (void)
8818 {
8819 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8820 }
8821
8822 static void
8823 do_vfp_dp_sp_cvt (void)
8824 {
8825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8826 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8827 }
8828
8829 static void
8830 do_vfp_sp_dp_cvt (void)
8831 {
8832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8833 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8834 }
8835
8836 static void
8837 do_vfp_reg_from_sp (void)
8838 {
8839 inst.instruction |= inst.operands[0].reg << 12;
8840 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8841 }
8842
8843 static void
8844 do_vfp_reg2_from_sp2 (void)
8845 {
8846 constraint (inst.operands[2].imm != 2,
8847 _("only two consecutive VFP SP registers allowed here"));
8848 inst.instruction |= inst.operands[0].reg << 12;
8849 inst.instruction |= inst.operands[1].reg << 16;
8850 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8851 }
8852
8853 static void
8854 do_vfp_sp_from_reg (void)
8855 {
8856 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8857 inst.instruction |= inst.operands[1].reg << 12;
8858 }
8859
8860 static void
8861 do_vfp_sp2_from_reg2 (void)
8862 {
8863 constraint (inst.operands[0].imm != 2,
8864 _("only two consecutive VFP SP registers allowed here"));
8865 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8866 inst.instruction |= inst.operands[1].reg << 12;
8867 inst.instruction |= inst.operands[2].reg << 16;
8868 }
8869
8870 static void
8871 do_vfp_sp_ldst (void)
8872 {
8873 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8874 encode_arm_cp_address (1, FALSE, TRUE, 0);
8875 }
8876
8877 static void
8878 do_vfp_dp_ldst (void)
8879 {
8880 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8881 encode_arm_cp_address (1, FALSE, TRUE, 0);
8882 }
8883
8884
8885 static void
8886 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8887 {
8888 if (inst.operands[0].writeback)
8889 inst.instruction |= WRITE_BACK;
8890 else
8891 constraint (ldstm_type != VFP_LDSTMIA,
8892 _("this addressing mode requires base-register writeback"));
8893 inst.instruction |= inst.operands[0].reg << 16;
8894 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8895 inst.instruction |= inst.operands[1].imm;
8896 }
8897
8898 static void
8899 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8900 {
8901 int count;
8902
8903 if (inst.operands[0].writeback)
8904 inst.instruction |= WRITE_BACK;
8905 else
8906 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8907 _("this addressing mode requires base-register writeback"));
8908
8909 inst.instruction |= inst.operands[0].reg << 16;
8910 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8911
8912 count = inst.operands[1].imm << 1;
8913 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8914 count += 1;
8915
8916 inst.instruction |= count;
8917 }
8918
8919 static void
8920 do_vfp_sp_ldstmia (void)
8921 {
8922 vfp_sp_ldstm (VFP_LDSTMIA);
8923 }
8924
8925 static void
8926 do_vfp_sp_ldstmdb (void)
8927 {
8928 vfp_sp_ldstm (VFP_LDSTMDB);
8929 }
8930
8931 static void
8932 do_vfp_dp_ldstmia (void)
8933 {
8934 vfp_dp_ldstm (VFP_LDSTMIA);
8935 }
8936
8937 static void
8938 do_vfp_dp_ldstmdb (void)
8939 {
8940 vfp_dp_ldstm (VFP_LDSTMDB);
8941 }
8942
8943 static void
8944 do_vfp_xp_ldstmia (void)
8945 {
8946 vfp_dp_ldstm (VFP_LDSTMIAX);
8947 }
8948
8949 static void
8950 do_vfp_xp_ldstmdb (void)
8951 {
8952 vfp_dp_ldstm (VFP_LDSTMDBX);
8953 }
8954
8955 static void
8956 do_vfp_dp_rd_rm (void)
8957 {
8958 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8959 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8960 }
8961
8962 static void
8963 do_vfp_dp_rn_rd (void)
8964 {
8965 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8966 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8967 }
8968
8969 static void
8970 do_vfp_dp_rd_rn (void)
8971 {
8972 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8973 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8974 }
8975
8976 static void
8977 do_vfp_dp_rd_rn_rm (void)
8978 {
8979 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8980 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8981 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8982 }
8983
8984 static void
8985 do_vfp_dp_rd (void)
8986 {
8987 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8988 }
8989
8990 static void
8991 do_vfp_dp_rm_rd_rn (void)
8992 {
8993 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8994 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8995 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8996 }
8997
8998 /* VFPv3 instructions. */
8999 static void
9000 do_vfp_sp_const (void)
9001 {
9002 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9003 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9004 inst.instruction |= (inst.operands[1].imm & 0x0f);
9005 }
9006
9007 static void
9008 do_vfp_dp_const (void)
9009 {
9010 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9011 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9012 inst.instruction |= (inst.operands[1].imm & 0x0f);
9013 }
9014
9015 static void
9016 vfp_conv (int srcsize)
9017 {
9018 int immbits = srcsize - inst.operands[1].imm;
9019
9020 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9021 {
9022 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
9023 i.e. immbits must be in range 0 - 16. */
9024 inst.error = _("immediate value out of range, expected range [0, 16]");
9025 return;
9026 }
9027 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
9028 {
9029 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
9030 i.e. immbits must be in range 0 - 31. */
9031 inst.error = _("immediate value out of range, expected range [1, 32]");
9032 return;
9033 }
9034
9035 inst.instruction |= (immbits & 1) << 5;
9036 inst.instruction |= (immbits >> 1);
9037 }
9038
9039 static void
9040 do_vfp_sp_conv_16 (void)
9041 {
9042 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9043 vfp_conv (16);
9044 }
9045
9046 static void
9047 do_vfp_dp_conv_16 (void)
9048 {
9049 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9050 vfp_conv (16);
9051 }
9052
9053 static void
9054 do_vfp_sp_conv_32 (void)
9055 {
9056 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9057 vfp_conv (32);
9058 }
9059
9060 static void
9061 do_vfp_dp_conv_32 (void)
9062 {
9063 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9064 vfp_conv (32);
9065 }
9066 \f
9067 /* FPA instructions. Also in a logical order. */
9068
9069 static void
9070 do_fpa_cmp (void)
9071 {
9072 inst.instruction |= inst.operands[0].reg << 16;
9073 inst.instruction |= inst.operands[1].reg;
9074 }
9075
9076 static void
9077 do_fpa_ldmstm (void)
9078 {
9079 inst.instruction |= inst.operands[0].reg << 12;
9080 switch (inst.operands[1].imm)
9081 {
9082 case 1: inst.instruction |= CP_T_X; break;
9083 case 2: inst.instruction |= CP_T_Y; break;
9084 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9085 case 4: break;
9086 default: abort ();
9087 }
9088
9089 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9090 {
9091 /* The instruction specified "ea" or "fd", so we can only accept
9092 [Rn]{!}. The instruction does not really support stacking or
9093 unstacking, so we have to emulate these by setting appropriate
9094 bits and offsets. */
9095 constraint (inst.reloc.exp.X_op != O_constant
9096 || inst.reloc.exp.X_add_number != 0,
9097 _("this instruction does not support indexing"));
9098
9099 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9100 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
9101
9102 if (!(inst.instruction & INDEX_UP))
9103 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
9104
9105 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9106 {
9107 inst.operands[2].preind = 0;
9108 inst.operands[2].postind = 1;
9109 }
9110 }
9111
9112 encode_arm_cp_address (2, TRUE, TRUE, 0);
9113 }
9114 \f
9115 /* iWMMXt instructions: strictly in alphabetical order. */
9116
9117 static void
9118 do_iwmmxt_tandorc (void)
9119 {
9120 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9121 }
9122
9123 static void
9124 do_iwmmxt_textrc (void)
9125 {
9126 inst.instruction |= inst.operands[0].reg << 12;
9127 inst.instruction |= inst.operands[1].imm;
9128 }
9129
9130 static void
9131 do_iwmmxt_textrm (void)
9132 {
9133 inst.instruction |= inst.operands[0].reg << 12;
9134 inst.instruction |= inst.operands[1].reg << 16;
9135 inst.instruction |= inst.operands[2].imm;
9136 }
9137
9138 static void
9139 do_iwmmxt_tinsr (void)
9140 {
9141 inst.instruction |= inst.operands[0].reg << 16;
9142 inst.instruction |= inst.operands[1].reg << 12;
9143 inst.instruction |= inst.operands[2].imm;
9144 }
9145
9146 static void
9147 do_iwmmxt_tmia (void)
9148 {
9149 inst.instruction |= inst.operands[0].reg << 5;
9150 inst.instruction |= inst.operands[1].reg;
9151 inst.instruction |= inst.operands[2].reg << 12;
9152 }
9153
9154 static void
9155 do_iwmmxt_waligni (void)
9156 {
9157 inst.instruction |= inst.operands[0].reg << 12;
9158 inst.instruction |= inst.operands[1].reg << 16;
9159 inst.instruction |= inst.operands[2].reg;
9160 inst.instruction |= inst.operands[3].imm << 20;
9161 }
9162
9163 static void
9164 do_iwmmxt_wmerge (void)
9165 {
9166 inst.instruction |= inst.operands[0].reg << 12;
9167 inst.instruction |= inst.operands[1].reg << 16;
9168 inst.instruction |= inst.operands[2].reg;
9169 inst.instruction |= inst.operands[3].imm << 21;
9170 }
9171
9172 static void
9173 do_iwmmxt_wmov (void)
9174 {
9175 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9176 inst.instruction |= inst.operands[0].reg << 12;
9177 inst.instruction |= inst.operands[1].reg << 16;
9178 inst.instruction |= inst.operands[1].reg;
9179 }
9180
9181 static void
9182 do_iwmmxt_wldstbh (void)
9183 {
9184 int reloc;
9185 inst.instruction |= inst.operands[0].reg << 12;
9186 if (thumb_mode)
9187 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9188 else
9189 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9190 encode_arm_cp_address (1, TRUE, FALSE, reloc);
9191 }
9192
9193 static void
9194 do_iwmmxt_wldstw (void)
9195 {
9196 /* RIWR_RIWC clears .isreg for a control register. */
9197 if (!inst.operands[0].isreg)
9198 {
9199 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9200 inst.instruction |= 0xf0000000;
9201 }
9202
9203 inst.instruction |= inst.operands[0].reg << 12;
9204 encode_arm_cp_address (1, TRUE, TRUE, 0);
9205 }
9206
9207 static void
9208 do_iwmmxt_wldstd (void)
9209 {
9210 inst.instruction |= inst.operands[0].reg << 12;
9211 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9212 && inst.operands[1].immisreg)
9213 {
9214 inst.instruction &= ~0x1a000ff;
9215 inst.instruction |= (0xf << 28);
9216 if (inst.operands[1].preind)
9217 inst.instruction |= PRE_INDEX;
9218 if (!inst.operands[1].negative)
9219 inst.instruction |= INDEX_UP;
9220 if (inst.operands[1].writeback)
9221 inst.instruction |= WRITE_BACK;
9222 inst.instruction |= inst.operands[1].reg << 16;
9223 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9224 inst.instruction |= inst.operands[1].imm;
9225 }
9226 else
9227 encode_arm_cp_address (1, TRUE, FALSE, 0);
9228 }
9229
9230 static void
9231 do_iwmmxt_wshufh (void)
9232 {
9233 inst.instruction |= inst.operands[0].reg << 12;
9234 inst.instruction |= inst.operands[1].reg << 16;
9235 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9236 inst.instruction |= (inst.operands[2].imm & 0x0f);
9237 }
9238
9239 static void
9240 do_iwmmxt_wzero (void)
9241 {
9242 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9243 inst.instruction |= inst.operands[0].reg;
9244 inst.instruction |= inst.operands[0].reg << 12;
9245 inst.instruction |= inst.operands[0].reg << 16;
9246 }
9247
9248 static void
9249 do_iwmmxt_wrwrwr_or_imm5 (void)
9250 {
9251 if (inst.operands[2].isreg)
9252 do_rd_rn_rm ();
9253 else {
9254 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9255 _("immediate operand requires iWMMXt2"));
9256 do_rd_rn ();
9257 if (inst.operands[2].imm == 0)
9258 {
9259 switch ((inst.instruction >> 20) & 0xf)
9260 {
9261 case 4:
9262 case 5:
9263 case 6:
9264 case 7:
9265 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9266 inst.operands[2].imm = 16;
9267 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9268 break;
9269 case 8:
9270 case 9:
9271 case 10:
9272 case 11:
9273 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9274 inst.operands[2].imm = 32;
9275 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9276 break;
9277 case 12:
9278 case 13:
9279 case 14:
9280 case 15:
9281 {
9282 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9283 unsigned long wrn;
9284 wrn = (inst.instruction >> 16) & 0xf;
9285 inst.instruction &= 0xff0fff0f;
9286 inst.instruction |= wrn;
9287 /* Bail out here; the instruction is now assembled. */
9288 return;
9289 }
9290 }
9291 }
9292 /* Map 32 -> 0, etc. */
9293 inst.operands[2].imm &= 0x1f;
9294 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9295 }
9296 }
9297 \f
9298 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9299 operations first, then control, shift, and load/store. */
9300
9301 /* Insns like "foo X,Y,Z". */
9302
9303 static void
9304 do_mav_triple (void)
9305 {
9306 inst.instruction |= inst.operands[0].reg << 16;
9307 inst.instruction |= inst.operands[1].reg;
9308 inst.instruction |= inst.operands[2].reg << 12;
9309 }
9310
9311 /* Insns like "foo W,X,Y,Z".
9312 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
9313
9314 static void
9315 do_mav_quad (void)
9316 {
9317 inst.instruction |= inst.operands[0].reg << 5;
9318 inst.instruction |= inst.operands[1].reg << 12;
9319 inst.instruction |= inst.operands[2].reg << 16;
9320 inst.instruction |= inst.operands[3].reg;
9321 }
9322
9323 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9324 static void
9325 do_mav_dspsc (void)
9326 {
9327 inst.instruction |= inst.operands[1].reg << 12;
9328 }
9329
9330 /* Maverick shift immediate instructions.
9331 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9332 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
9333
9334 static void
9335 do_mav_shift (void)
9336 {
9337 int imm = inst.operands[2].imm;
9338
9339 inst.instruction |= inst.operands[0].reg << 12;
9340 inst.instruction |= inst.operands[1].reg << 16;
9341
9342 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9343 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9344 Bit 4 should be 0. */
9345 imm = (imm & 0xf) | ((imm & 0x70) << 1);
9346
9347 inst.instruction |= imm;
9348 }
9349 \f
9350 /* XScale instructions. Also sorted arithmetic before move. */
9351
9352 /* Xscale multiply-accumulate (argument parse)
9353 MIAcc acc0,Rm,Rs
9354 MIAPHcc acc0,Rm,Rs
9355 MIAxycc acc0,Rm,Rs. */
9356
9357 static void
9358 do_xsc_mia (void)
9359 {
9360 inst.instruction |= inst.operands[1].reg;
9361 inst.instruction |= inst.operands[2].reg << 12;
9362 }
9363
9364 /* Xscale move-accumulator-register (argument parse)
9365
9366 MARcc acc0,RdLo,RdHi. */
9367
9368 static void
9369 do_xsc_mar (void)
9370 {
9371 inst.instruction |= inst.operands[1].reg << 12;
9372 inst.instruction |= inst.operands[2].reg << 16;
9373 }
9374
9375 /* Xscale move-register-accumulator (argument parse)
9376
9377 MRAcc RdLo,RdHi,acc0. */
9378
9379 static void
9380 do_xsc_mra (void)
9381 {
9382 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9383 inst.instruction |= inst.operands[0].reg << 12;
9384 inst.instruction |= inst.operands[1].reg << 16;
9385 }
9386 \f
9387 /* Encoding functions relevant only to Thumb. */
9388
9389 /* inst.operands[i] is a shifted-register operand; encode
9390 it into inst.instruction in the format used by Thumb32. */
9391
9392 static void
9393 encode_thumb32_shifted_operand (int i)
9394 {
9395 unsigned int value = inst.reloc.exp.X_add_number;
9396 unsigned int shift = inst.operands[i].shift_kind;
9397
9398 constraint (inst.operands[i].immisreg,
9399 _("shift by register not allowed in thumb mode"));
9400 inst.instruction |= inst.operands[i].reg;
9401 if (shift == SHIFT_RRX)
9402 inst.instruction |= SHIFT_ROR << 4;
9403 else
9404 {
9405 constraint (inst.reloc.exp.X_op != O_constant,
9406 _("expression too complex"));
9407
9408 constraint (value > 32
9409 || (value == 32 && (shift == SHIFT_LSL
9410 || shift == SHIFT_ROR)),
9411 _("shift expression is too large"));
9412
9413 if (value == 0)
9414 shift = SHIFT_LSL;
9415 else if (value == 32)
9416 value = 0;
9417
9418 inst.instruction |= shift << 4;
9419 inst.instruction |= (value & 0x1c) << 10;
9420 inst.instruction |= (value & 0x03) << 6;
9421 }
9422 }
9423
9424
9425 /* inst.operands[i] was set up by parse_address. Encode it into a
9426 Thumb32 format load or store instruction. Reject forms that cannot
9427 be used with such instructions. If is_t is true, reject forms that
9428 cannot be used with a T instruction; if is_d is true, reject forms
9429 that cannot be used with a D instruction. If it is a store insn,
9430 reject PC in Rn. */
9431
9432 static void
9433 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9434 {
9435 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
9436
9437 constraint (!inst.operands[i].isreg,
9438 _("Instruction does not support =N addresses"));
9439
9440 inst.instruction |= inst.operands[i].reg << 16;
9441 if (inst.operands[i].immisreg)
9442 {
9443 constraint (is_pc, BAD_PC_ADDRESSING);
9444 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9445 constraint (inst.operands[i].negative,
9446 _("Thumb does not support negative register indexing"));
9447 constraint (inst.operands[i].postind,
9448 _("Thumb does not support register post-indexing"));
9449 constraint (inst.operands[i].writeback,
9450 _("Thumb does not support register indexing with writeback"));
9451 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9452 _("Thumb supports only LSL in shifted register indexing"));
9453
9454 inst.instruction |= inst.operands[i].imm;
9455 if (inst.operands[i].shifted)
9456 {
9457 constraint (inst.reloc.exp.X_op != O_constant,
9458 _("expression too complex"));
9459 constraint (inst.reloc.exp.X_add_number < 0
9460 || inst.reloc.exp.X_add_number > 3,
9461 _("shift out of range"));
9462 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9463 }
9464 inst.reloc.type = BFD_RELOC_UNUSED;
9465 }
9466 else if (inst.operands[i].preind)
9467 {
9468 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
9469 constraint (is_t && inst.operands[i].writeback,
9470 _("cannot use writeback with this instruction"));
9471 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9472 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
9473
9474 if (is_d)
9475 {
9476 inst.instruction |= 0x01000000;
9477 if (inst.operands[i].writeback)
9478 inst.instruction |= 0x00200000;
9479 }
9480 else
9481 {
9482 inst.instruction |= 0x00000c00;
9483 if (inst.operands[i].writeback)
9484 inst.instruction |= 0x00000100;
9485 }
9486 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9487 }
9488 else if (inst.operands[i].postind)
9489 {
9490 gas_assert (inst.operands[i].writeback);
9491 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9492 constraint (is_t, _("cannot use post-indexing with this instruction"));
9493
9494 if (is_d)
9495 inst.instruction |= 0x00200000;
9496 else
9497 inst.instruction |= 0x00000900;
9498 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9499 }
9500 else /* unindexed - only for coprocessor */
9501 inst.error = _("instruction does not accept unindexed addressing");
9502 }
9503
9504 /* Table of Thumb instructions which exist in both 16- and 32-bit
9505 encodings (the latter only in post-V6T2 cores). The index is the
9506 value used in the insns table below. When there is more than one
9507 possible 16-bit encoding for the instruction, this table always
9508 holds variant (1).
9509 Also contains several pseudo-instructions used during relaxation. */
9510 #define T16_32_TAB \
9511 X(_adc, 4140, eb400000), \
9512 X(_adcs, 4140, eb500000), \
9513 X(_add, 1c00, eb000000), \
9514 X(_adds, 1c00, eb100000), \
9515 X(_addi, 0000, f1000000), \
9516 X(_addis, 0000, f1100000), \
9517 X(_add_pc,000f, f20f0000), \
9518 X(_add_sp,000d, f10d0000), \
9519 X(_adr, 000f, f20f0000), \
9520 X(_and, 4000, ea000000), \
9521 X(_ands, 4000, ea100000), \
9522 X(_asr, 1000, fa40f000), \
9523 X(_asrs, 1000, fa50f000), \
9524 X(_b, e000, f000b000), \
9525 X(_bcond, d000, f0008000), \
9526 X(_bic, 4380, ea200000), \
9527 X(_bics, 4380, ea300000), \
9528 X(_cmn, 42c0, eb100f00), \
9529 X(_cmp, 2800, ebb00f00), \
9530 X(_cpsie, b660, f3af8400), \
9531 X(_cpsid, b670, f3af8600), \
9532 X(_cpy, 4600, ea4f0000), \
9533 X(_dec_sp,80dd, f1ad0d00), \
9534 X(_eor, 4040, ea800000), \
9535 X(_eors, 4040, ea900000), \
9536 X(_inc_sp,00dd, f10d0d00), \
9537 X(_ldmia, c800, e8900000), \
9538 X(_ldr, 6800, f8500000), \
9539 X(_ldrb, 7800, f8100000), \
9540 X(_ldrh, 8800, f8300000), \
9541 X(_ldrsb, 5600, f9100000), \
9542 X(_ldrsh, 5e00, f9300000), \
9543 X(_ldr_pc,4800, f85f0000), \
9544 X(_ldr_pc2,4800, f85f0000), \
9545 X(_ldr_sp,9800, f85d0000), \
9546 X(_lsl, 0000, fa00f000), \
9547 X(_lsls, 0000, fa10f000), \
9548 X(_lsr, 0800, fa20f000), \
9549 X(_lsrs, 0800, fa30f000), \
9550 X(_mov, 2000, ea4f0000), \
9551 X(_movs, 2000, ea5f0000), \
9552 X(_mul, 4340, fb00f000), \
9553 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9554 X(_mvn, 43c0, ea6f0000), \
9555 X(_mvns, 43c0, ea7f0000), \
9556 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9557 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9558 X(_orr, 4300, ea400000), \
9559 X(_orrs, 4300, ea500000), \
9560 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9561 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9562 X(_rev, ba00, fa90f080), \
9563 X(_rev16, ba40, fa90f090), \
9564 X(_revsh, bac0, fa90f0b0), \
9565 X(_ror, 41c0, fa60f000), \
9566 X(_rors, 41c0, fa70f000), \
9567 X(_sbc, 4180, eb600000), \
9568 X(_sbcs, 4180, eb700000), \
9569 X(_stmia, c000, e8800000), \
9570 X(_str, 6000, f8400000), \
9571 X(_strb, 7000, f8000000), \
9572 X(_strh, 8000, f8200000), \
9573 X(_str_sp,9000, f84d0000), \
9574 X(_sub, 1e00, eba00000), \
9575 X(_subs, 1e00, ebb00000), \
9576 X(_subi, 8000, f1a00000), \
9577 X(_subis, 8000, f1b00000), \
9578 X(_sxtb, b240, fa4ff080), \
9579 X(_sxth, b200, fa0ff080), \
9580 X(_tst, 4200, ea100f00), \
9581 X(_uxtb, b2c0, fa5ff080), \
9582 X(_uxth, b280, fa1ff080), \
9583 X(_nop, bf00, f3af8000), \
9584 X(_yield, bf10, f3af8001), \
9585 X(_wfe, bf20, f3af8002), \
9586 X(_wfi, bf30, f3af8003), \
9587 X(_sev, bf40, f3af8004), \
9588 X(_sevl, bf50, f3af8005)
9589
9590 /* To catch errors in encoding functions, the codes are all offset by
9591 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9592 as 16-bit instructions. */
9593 #define X(a,b,c) T_MNEM##a
9594 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9595 #undef X
9596
9597 #define X(a,b,c) 0x##b
9598 static const unsigned short thumb_op16[] = { T16_32_TAB };
9599 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9600 #undef X
9601
9602 #define X(a,b,c) 0x##c
9603 static const unsigned int thumb_op32[] = { T16_32_TAB };
9604 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9605 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9606 #undef X
9607 #undef T16_32_TAB
9608
9609 /* Thumb instruction encoders, in alphabetical order. */
9610
9611 /* ADDW or SUBW. */
9612
9613 static void
9614 do_t_add_sub_w (void)
9615 {
9616 int Rd, Rn;
9617
9618 Rd = inst.operands[0].reg;
9619 Rn = inst.operands[1].reg;
9620
9621 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9622 is the SP-{plus,minus}-immediate form of the instruction. */
9623 if (Rn == REG_SP)
9624 constraint (Rd == REG_PC, BAD_PC);
9625 else
9626 reject_bad_reg (Rd);
9627
9628 inst.instruction |= (Rn << 16) | (Rd << 8);
9629 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9630 }
9631
9632 /* Parse an add or subtract instruction. We get here with inst.instruction
9633 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9634
9635 static void
9636 do_t_add_sub (void)
9637 {
9638 int Rd, Rs, Rn;
9639
9640 Rd = inst.operands[0].reg;
9641 Rs = (inst.operands[1].present
9642 ? inst.operands[1].reg /* Rd, Rs, foo */
9643 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9644
9645 if (Rd == REG_PC)
9646 set_it_insn_type_last ();
9647
9648 if (unified_syntax)
9649 {
9650 bfd_boolean flags;
9651 bfd_boolean narrow;
9652 int opcode;
9653
9654 flags = (inst.instruction == T_MNEM_adds
9655 || inst.instruction == T_MNEM_subs);
9656 if (flags)
9657 narrow = !in_it_block ();
9658 else
9659 narrow = in_it_block ();
9660 if (!inst.operands[2].isreg)
9661 {
9662 int add;
9663
9664 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9665
9666 add = (inst.instruction == T_MNEM_add
9667 || inst.instruction == T_MNEM_adds);
9668 opcode = 0;
9669 if (inst.size_req != 4)
9670 {
9671 /* Attempt to use a narrow opcode, with relaxation if
9672 appropriate. */
9673 if (Rd == REG_SP && Rs == REG_SP && !flags)
9674 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9675 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9676 opcode = T_MNEM_add_sp;
9677 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9678 opcode = T_MNEM_add_pc;
9679 else if (Rd <= 7 && Rs <= 7 && narrow)
9680 {
9681 if (flags)
9682 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9683 else
9684 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9685 }
9686 if (opcode)
9687 {
9688 inst.instruction = THUMB_OP16(opcode);
9689 inst.instruction |= (Rd << 4) | Rs;
9690 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9691 if (inst.size_req != 2)
9692 inst.relax = opcode;
9693 }
9694 else
9695 constraint (inst.size_req == 2, BAD_HIREG);
9696 }
9697 if (inst.size_req == 4
9698 || (inst.size_req != 2 && !opcode))
9699 {
9700 if (Rd == REG_PC)
9701 {
9702 constraint (add, BAD_PC);
9703 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9704 _("only SUBS PC, LR, #const allowed"));
9705 constraint (inst.reloc.exp.X_op != O_constant,
9706 _("expression too complex"));
9707 constraint (inst.reloc.exp.X_add_number < 0
9708 || inst.reloc.exp.X_add_number > 0xff,
9709 _("immediate value out of range"));
9710 inst.instruction = T2_SUBS_PC_LR
9711 | inst.reloc.exp.X_add_number;
9712 inst.reloc.type = BFD_RELOC_UNUSED;
9713 return;
9714 }
9715 else if (Rs == REG_PC)
9716 {
9717 /* Always use addw/subw. */
9718 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9719 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9720 }
9721 else
9722 {
9723 inst.instruction = THUMB_OP32 (inst.instruction);
9724 inst.instruction = (inst.instruction & 0xe1ffffff)
9725 | 0x10000000;
9726 if (flags)
9727 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9728 else
9729 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9730 }
9731 inst.instruction |= Rd << 8;
9732 inst.instruction |= Rs << 16;
9733 }
9734 }
9735 else
9736 {
9737 unsigned int value = inst.reloc.exp.X_add_number;
9738 unsigned int shift = inst.operands[2].shift_kind;
9739
9740 Rn = inst.operands[2].reg;
9741 /* See if we can do this with a 16-bit instruction. */
9742 if (!inst.operands[2].shifted && inst.size_req != 4)
9743 {
9744 if (Rd > 7 || Rs > 7 || Rn > 7)
9745 narrow = FALSE;
9746
9747 if (narrow)
9748 {
9749 inst.instruction = ((inst.instruction == T_MNEM_adds
9750 || inst.instruction == T_MNEM_add)
9751 ? T_OPCODE_ADD_R3
9752 : T_OPCODE_SUB_R3);
9753 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9754 return;
9755 }
9756
9757 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9758 {
9759 /* Thumb-1 cores (except v6-M) require at least one high
9760 register in a narrow non flag setting add. */
9761 if (Rd > 7 || Rn > 7
9762 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9763 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9764 {
9765 if (Rd == Rn)
9766 {
9767 Rn = Rs;
9768 Rs = Rd;
9769 }
9770 inst.instruction = T_OPCODE_ADD_HI;
9771 inst.instruction |= (Rd & 8) << 4;
9772 inst.instruction |= (Rd & 7);
9773 inst.instruction |= Rn << 3;
9774 return;
9775 }
9776 }
9777 }
9778
9779 constraint (Rd == REG_PC, BAD_PC);
9780 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9781 constraint (Rs == REG_PC, BAD_PC);
9782 reject_bad_reg (Rn);
9783
9784 /* If we get here, it can't be done in 16 bits. */
9785 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9786 _("shift must be constant"));
9787 inst.instruction = THUMB_OP32 (inst.instruction);
9788 inst.instruction |= Rd << 8;
9789 inst.instruction |= Rs << 16;
9790 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9791 _("shift value over 3 not allowed in thumb mode"));
9792 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9793 _("only LSL shift allowed in thumb mode"));
9794 encode_thumb32_shifted_operand (2);
9795 }
9796 }
9797 else
9798 {
9799 constraint (inst.instruction == T_MNEM_adds
9800 || inst.instruction == T_MNEM_subs,
9801 BAD_THUMB32);
9802
9803 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9804 {
9805 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9806 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9807 BAD_HIREG);
9808
9809 inst.instruction = (inst.instruction == T_MNEM_add
9810 ? 0x0000 : 0x8000);
9811 inst.instruction |= (Rd << 4) | Rs;
9812 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9813 return;
9814 }
9815
9816 Rn = inst.operands[2].reg;
9817 constraint (inst.operands[2].shifted, _("unshifted register required"));
9818
9819 /* We now have Rd, Rs, and Rn set to registers. */
9820 if (Rd > 7 || Rs > 7 || Rn > 7)
9821 {
9822 /* Can't do this for SUB. */
9823 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9824 inst.instruction = T_OPCODE_ADD_HI;
9825 inst.instruction |= (Rd & 8) << 4;
9826 inst.instruction |= (Rd & 7);
9827 if (Rs == Rd)
9828 inst.instruction |= Rn << 3;
9829 else if (Rn == Rd)
9830 inst.instruction |= Rs << 3;
9831 else
9832 constraint (1, _("dest must overlap one source register"));
9833 }
9834 else
9835 {
9836 inst.instruction = (inst.instruction == T_MNEM_add
9837 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9838 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9839 }
9840 }
9841 }
9842
9843 static void
9844 do_t_adr (void)
9845 {
9846 unsigned Rd;
9847
9848 Rd = inst.operands[0].reg;
9849 reject_bad_reg (Rd);
9850
9851 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9852 {
9853 /* Defer to section relaxation. */
9854 inst.relax = inst.instruction;
9855 inst.instruction = THUMB_OP16 (inst.instruction);
9856 inst.instruction |= Rd << 4;
9857 }
9858 else if (unified_syntax && inst.size_req != 2)
9859 {
9860 /* Generate a 32-bit opcode. */
9861 inst.instruction = THUMB_OP32 (inst.instruction);
9862 inst.instruction |= Rd << 8;
9863 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9864 inst.reloc.pc_rel = 1;
9865 }
9866 else
9867 {
9868 /* Generate a 16-bit opcode. */
9869 inst.instruction = THUMB_OP16 (inst.instruction);
9870 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9871 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9872 inst.reloc.pc_rel = 1;
9873
9874 inst.instruction |= Rd << 4;
9875 }
9876 }
9877
9878 /* Arithmetic instructions for which there is just one 16-bit
9879 instruction encoding, and it allows only two low registers.
9880 For maximal compatibility with ARM syntax, we allow three register
9881 operands even when Thumb-32 instructions are not available, as long
9882 as the first two are identical. For instance, both "sbc r0,r1" and
9883 "sbc r0,r0,r1" are allowed. */
9884 static void
9885 do_t_arit3 (void)
9886 {
9887 int Rd, Rs, Rn;
9888
9889 Rd = inst.operands[0].reg;
9890 Rs = (inst.operands[1].present
9891 ? inst.operands[1].reg /* Rd, Rs, foo */
9892 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9893 Rn = inst.operands[2].reg;
9894
9895 reject_bad_reg (Rd);
9896 reject_bad_reg (Rs);
9897 if (inst.operands[2].isreg)
9898 reject_bad_reg (Rn);
9899
9900 if (unified_syntax)
9901 {
9902 if (!inst.operands[2].isreg)
9903 {
9904 /* For an immediate, we always generate a 32-bit opcode;
9905 section relaxation will shrink it later if possible. */
9906 inst.instruction = THUMB_OP32 (inst.instruction);
9907 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9908 inst.instruction |= Rd << 8;
9909 inst.instruction |= Rs << 16;
9910 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9911 }
9912 else
9913 {
9914 bfd_boolean narrow;
9915
9916 /* See if we can do this with a 16-bit instruction. */
9917 if (THUMB_SETS_FLAGS (inst.instruction))
9918 narrow = !in_it_block ();
9919 else
9920 narrow = in_it_block ();
9921
9922 if (Rd > 7 || Rn > 7 || Rs > 7)
9923 narrow = FALSE;
9924 if (inst.operands[2].shifted)
9925 narrow = FALSE;
9926 if (inst.size_req == 4)
9927 narrow = FALSE;
9928
9929 if (narrow
9930 && Rd == Rs)
9931 {
9932 inst.instruction = THUMB_OP16 (inst.instruction);
9933 inst.instruction |= Rd;
9934 inst.instruction |= Rn << 3;
9935 return;
9936 }
9937
9938 /* If we get here, it can't be done in 16 bits. */
9939 constraint (inst.operands[2].shifted
9940 && inst.operands[2].immisreg,
9941 _("shift must be constant"));
9942 inst.instruction = THUMB_OP32 (inst.instruction);
9943 inst.instruction |= Rd << 8;
9944 inst.instruction |= Rs << 16;
9945 encode_thumb32_shifted_operand (2);
9946 }
9947 }
9948 else
9949 {
9950 /* On its face this is a lie - the instruction does set the
9951 flags. However, the only supported mnemonic in this mode
9952 says it doesn't. */
9953 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9954
9955 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9956 _("unshifted register required"));
9957 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9958 constraint (Rd != Rs,
9959 _("dest and source1 must be the same register"));
9960
9961 inst.instruction = THUMB_OP16 (inst.instruction);
9962 inst.instruction |= Rd;
9963 inst.instruction |= Rn << 3;
9964 }
9965 }
9966
9967 /* Similarly, but for instructions where the arithmetic operation is
9968 commutative, so we can allow either of them to be different from
9969 the destination operand in a 16-bit instruction. For instance, all
9970 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9971 accepted. */
9972 static void
9973 do_t_arit3c (void)
9974 {
9975 int Rd, Rs, Rn;
9976
9977 Rd = inst.operands[0].reg;
9978 Rs = (inst.operands[1].present
9979 ? inst.operands[1].reg /* Rd, Rs, foo */
9980 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9981 Rn = inst.operands[2].reg;
9982
9983 reject_bad_reg (Rd);
9984 reject_bad_reg (Rs);
9985 if (inst.operands[2].isreg)
9986 reject_bad_reg (Rn);
9987
9988 if (unified_syntax)
9989 {
9990 if (!inst.operands[2].isreg)
9991 {
9992 /* For an immediate, we always generate a 32-bit opcode;
9993 section relaxation will shrink it later if possible. */
9994 inst.instruction = THUMB_OP32 (inst.instruction);
9995 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9996 inst.instruction |= Rd << 8;
9997 inst.instruction |= Rs << 16;
9998 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9999 }
10000 else
10001 {
10002 bfd_boolean narrow;
10003
10004 /* See if we can do this with a 16-bit instruction. */
10005 if (THUMB_SETS_FLAGS (inst.instruction))
10006 narrow = !in_it_block ();
10007 else
10008 narrow = in_it_block ();
10009
10010 if (Rd > 7 || Rn > 7 || Rs > 7)
10011 narrow = FALSE;
10012 if (inst.operands[2].shifted)
10013 narrow = FALSE;
10014 if (inst.size_req == 4)
10015 narrow = FALSE;
10016
10017 if (narrow)
10018 {
10019 if (Rd == Rs)
10020 {
10021 inst.instruction = THUMB_OP16 (inst.instruction);
10022 inst.instruction |= Rd;
10023 inst.instruction |= Rn << 3;
10024 return;
10025 }
10026 if (Rd == Rn)
10027 {
10028 inst.instruction = THUMB_OP16 (inst.instruction);
10029 inst.instruction |= Rd;
10030 inst.instruction |= Rs << 3;
10031 return;
10032 }
10033 }
10034
10035 /* If we get here, it can't be done in 16 bits. */
10036 constraint (inst.operands[2].shifted
10037 && inst.operands[2].immisreg,
10038 _("shift must be constant"));
10039 inst.instruction = THUMB_OP32 (inst.instruction);
10040 inst.instruction |= Rd << 8;
10041 inst.instruction |= Rs << 16;
10042 encode_thumb32_shifted_operand (2);
10043 }
10044 }
10045 else
10046 {
10047 /* On its face this is a lie - the instruction does set the
10048 flags. However, the only supported mnemonic in this mode
10049 says it doesn't. */
10050 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10051
10052 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10053 _("unshifted register required"));
10054 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10055
10056 inst.instruction = THUMB_OP16 (inst.instruction);
10057 inst.instruction |= Rd;
10058
10059 if (Rd == Rs)
10060 inst.instruction |= Rn << 3;
10061 else if (Rd == Rn)
10062 inst.instruction |= Rs << 3;
10063 else
10064 constraint (1, _("dest must overlap one source register"));
10065 }
10066 }
10067
10068 static void
10069 do_t_barrier (void)
10070 {
10071 if (inst.operands[0].present)
10072 {
10073 constraint ((inst.instruction & 0xf0) != 0x40
10074 && inst.operands[0].imm > 0xf
10075 && inst.operands[0].imm < 0x0,
10076 _("bad barrier type"));
10077 inst.instruction |= inst.operands[0].imm;
10078 }
10079 else
10080 inst.instruction |= 0xf;
10081 }
10082
10083 static void
10084 do_t_bfc (void)
10085 {
10086 unsigned Rd;
10087 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10088 constraint (msb > 32, _("bit-field extends past end of register"));
10089 /* The instruction encoding stores the LSB and MSB,
10090 not the LSB and width. */
10091 Rd = inst.operands[0].reg;
10092 reject_bad_reg (Rd);
10093 inst.instruction |= Rd << 8;
10094 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10095 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10096 inst.instruction |= msb - 1;
10097 }
10098
10099 static void
10100 do_t_bfi (void)
10101 {
10102 int Rd, Rn;
10103 unsigned int msb;
10104
10105 Rd = inst.operands[0].reg;
10106 reject_bad_reg (Rd);
10107
10108 /* #0 in second position is alternative syntax for bfc, which is
10109 the same instruction but with REG_PC in the Rm field. */
10110 if (!inst.operands[1].isreg)
10111 Rn = REG_PC;
10112 else
10113 {
10114 Rn = inst.operands[1].reg;
10115 reject_bad_reg (Rn);
10116 }
10117
10118 msb = inst.operands[2].imm + inst.operands[3].imm;
10119 constraint (msb > 32, _("bit-field extends past end of register"));
10120 /* The instruction encoding stores the LSB and MSB,
10121 not the LSB and width. */
10122 inst.instruction |= Rd << 8;
10123 inst.instruction |= Rn << 16;
10124 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10125 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10126 inst.instruction |= msb - 1;
10127 }
10128
10129 static void
10130 do_t_bfx (void)
10131 {
10132 unsigned Rd, Rn;
10133
10134 Rd = inst.operands[0].reg;
10135 Rn = inst.operands[1].reg;
10136
10137 reject_bad_reg (Rd);
10138 reject_bad_reg (Rn);
10139
10140 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10141 _("bit-field extends past end of register"));
10142 inst.instruction |= Rd << 8;
10143 inst.instruction |= Rn << 16;
10144 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10145 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10146 inst.instruction |= inst.operands[3].imm - 1;
10147 }
10148
10149 /* ARM V5 Thumb BLX (argument parse)
10150 BLX <target_addr> which is BLX(1)
10151 BLX <Rm> which is BLX(2)
10152 Unfortunately, there are two different opcodes for this mnemonic.
10153 So, the insns[].value is not used, and the code here zaps values
10154 into inst.instruction.
10155
10156 ??? How to take advantage of the additional two bits of displacement
10157 available in Thumb32 mode? Need new relocation? */
10158
10159 static void
10160 do_t_blx (void)
10161 {
10162 set_it_insn_type_last ();
10163
10164 if (inst.operands[0].isreg)
10165 {
10166 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10167 /* We have a register, so this is BLX(2). */
10168 inst.instruction |= inst.operands[0].reg << 3;
10169 }
10170 else
10171 {
10172 /* No register. This must be BLX(1). */
10173 inst.instruction = 0xf000e800;
10174 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
10175 }
10176 }
10177
10178 static void
10179 do_t_branch (void)
10180 {
10181 int opcode;
10182 int cond;
10183 int reloc;
10184
10185 cond = inst.cond;
10186 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10187
10188 if (in_it_block ())
10189 {
10190 /* Conditional branches inside IT blocks are encoded as unconditional
10191 branches. */
10192 cond = COND_ALWAYS;
10193 }
10194 else
10195 cond = inst.cond;
10196
10197 if (cond != COND_ALWAYS)
10198 opcode = T_MNEM_bcond;
10199 else
10200 opcode = inst.instruction;
10201
10202 if (unified_syntax
10203 && (inst.size_req == 4
10204 || (inst.size_req != 2
10205 && (inst.operands[0].hasreloc
10206 || inst.reloc.exp.X_op == O_constant))))
10207 {
10208 inst.instruction = THUMB_OP32(opcode);
10209 if (cond == COND_ALWAYS)
10210 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
10211 else
10212 {
10213 gas_assert (cond != 0xF);
10214 inst.instruction |= cond << 22;
10215 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
10216 }
10217 }
10218 else
10219 {
10220 inst.instruction = THUMB_OP16(opcode);
10221 if (cond == COND_ALWAYS)
10222 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
10223 else
10224 {
10225 inst.instruction |= cond << 8;
10226 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
10227 }
10228 /* Allow section relaxation. */
10229 if (unified_syntax && inst.size_req != 2)
10230 inst.relax = opcode;
10231 }
10232 inst.reloc.type = reloc;
10233 inst.reloc.pc_rel = 1;
10234 }
10235
10236 /* Actually do the work for Thumb state bkpt and hlt. The only difference
10237 between the two is the maximum immediate allowed - which is passed in
10238 RANGE. */
10239 static void
10240 do_t_bkpt_hlt1 (int range)
10241 {
10242 constraint (inst.cond != COND_ALWAYS,
10243 _("instruction is always unconditional"));
10244 if (inst.operands[0].present)
10245 {
10246 constraint (inst.operands[0].imm > range,
10247 _("immediate value out of range"));
10248 inst.instruction |= inst.operands[0].imm;
10249 }
10250
10251 set_it_insn_type (NEUTRAL_IT_INSN);
10252 }
10253
10254 static void
10255 do_t_hlt (void)
10256 {
10257 do_t_bkpt_hlt1 (63);
10258 }
10259
10260 static void
10261 do_t_bkpt (void)
10262 {
10263 do_t_bkpt_hlt1 (255);
10264 }
10265
10266 static void
10267 do_t_branch23 (void)
10268 {
10269 set_it_insn_type_last ();
10270 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
10271
10272 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10273 this file. We used to simply ignore the PLT reloc type here --
10274 the branch encoding is now needed to deal with TLSCALL relocs.
10275 So if we see a PLT reloc now, put it back to how it used to be to
10276 keep the preexisting behaviour. */
10277 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10278 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
10279
10280 #if defined(OBJ_COFF)
10281 /* If the destination of the branch is a defined symbol which does not have
10282 the THUMB_FUNC attribute, then we must be calling a function which has
10283 the (interfacearm) attribute. We look for the Thumb entry point to that
10284 function and change the branch to refer to that function instead. */
10285 if ( inst.reloc.exp.X_op == O_symbol
10286 && inst.reloc.exp.X_add_symbol != NULL
10287 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10288 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10289 inst.reloc.exp.X_add_symbol =
10290 find_real_start (inst.reloc.exp.X_add_symbol);
10291 #endif
10292 }
10293
10294 static void
10295 do_t_bx (void)
10296 {
10297 set_it_insn_type_last ();
10298 inst.instruction |= inst.operands[0].reg << 3;
10299 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10300 should cause the alignment to be checked once it is known. This is
10301 because BX PC only works if the instruction is word aligned. */
10302 }
10303
10304 static void
10305 do_t_bxj (void)
10306 {
10307 int Rm;
10308
10309 set_it_insn_type_last ();
10310 Rm = inst.operands[0].reg;
10311 reject_bad_reg (Rm);
10312 inst.instruction |= Rm << 16;
10313 }
10314
10315 static void
10316 do_t_clz (void)
10317 {
10318 unsigned Rd;
10319 unsigned Rm;
10320
10321 Rd = inst.operands[0].reg;
10322 Rm = inst.operands[1].reg;
10323
10324 reject_bad_reg (Rd);
10325 reject_bad_reg (Rm);
10326
10327 inst.instruction |= Rd << 8;
10328 inst.instruction |= Rm << 16;
10329 inst.instruction |= Rm;
10330 }
10331
10332 static void
10333 do_t_cps (void)
10334 {
10335 set_it_insn_type (OUTSIDE_IT_INSN);
10336 inst.instruction |= inst.operands[0].imm;
10337 }
10338
10339 static void
10340 do_t_cpsi (void)
10341 {
10342 set_it_insn_type (OUTSIDE_IT_INSN);
10343 if (unified_syntax
10344 && (inst.operands[1].present || inst.size_req == 4)
10345 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
10346 {
10347 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10348 inst.instruction = 0xf3af8000;
10349 inst.instruction |= imod << 9;
10350 inst.instruction |= inst.operands[0].imm << 5;
10351 if (inst.operands[1].present)
10352 inst.instruction |= 0x100 | inst.operands[1].imm;
10353 }
10354 else
10355 {
10356 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10357 && (inst.operands[0].imm & 4),
10358 _("selected processor does not support 'A' form "
10359 "of this instruction"));
10360 constraint (inst.operands[1].present || inst.size_req == 4,
10361 _("Thumb does not support the 2-argument "
10362 "form of this instruction"));
10363 inst.instruction |= inst.operands[0].imm;
10364 }
10365 }
10366
10367 /* THUMB CPY instruction (argument parse). */
10368
10369 static void
10370 do_t_cpy (void)
10371 {
10372 if (inst.size_req == 4)
10373 {
10374 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10375 inst.instruction |= inst.operands[0].reg << 8;
10376 inst.instruction |= inst.operands[1].reg;
10377 }
10378 else
10379 {
10380 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10381 inst.instruction |= (inst.operands[0].reg & 0x7);
10382 inst.instruction |= inst.operands[1].reg << 3;
10383 }
10384 }
10385
10386 static void
10387 do_t_cbz (void)
10388 {
10389 set_it_insn_type (OUTSIDE_IT_INSN);
10390 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10391 inst.instruction |= inst.operands[0].reg;
10392 inst.reloc.pc_rel = 1;
10393 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10394 }
10395
10396 static void
10397 do_t_dbg (void)
10398 {
10399 inst.instruction |= inst.operands[0].imm;
10400 }
10401
10402 static void
10403 do_t_div (void)
10404 {
10405 unsigned Rd, Rn, Rm;
10406
10407 Rd = inst.operands[0].reg;
10408 Rn = (inst.operands[1].present
10409 ? inst.operands[1].reg : Rd);
10410 Rm = inst.operands[2].reg;
10411
10412 reject_bad_reg (Rd);
10413 reject_bad_reg (Rn);
10414 reject_bad_reg (Rm);
10415
10416 inst.instruction |= Rd << 8;
10417 inst.instruction |= Rn << 16;
10418 inst.instruction |= Rm;
10419 }
10420
10421 static void
10422 do_t_hint (void)
10423 {
10424 if (unified_syntax && inst.size_req == 4)
10425 inst.instruction = THUMB_OP32 (inst.instruction);
10426 else
10427 inst.instruction = THUMB_OP16 (inst.instruction);
10428 }
10429
10430 static void
10431 do_t_it (void)
10432 {
10433 unsigned int cond = inst.operands[0].imm;
10434
10435 set_it_insn_type (IT_INSN);
10436 now_it.mask = (inst.instruction & 0xf) | 0x10;
10437 now_it.cc = cond;
10438 now_it.warn_deprecated = FALSE;
10439
10440 /* If the condition is a negative condition, invert the mask. */
10441 if ((cond & 0x1) == 0x0)
10442 {
10443 unsigned int mask = inst.instruction & 0x000f;
10444
10445 if ((mask & 0x7) == 0)
10446 {
10447 /* No conversion needed. */
10448 now_it.block_length = 1;
10449 }
10450 else if ((mask & 0x3) == 0)
10451 {
10452 mask ^= 0x8;
10453 now_it.block_length = 2;
10454 }
10455 else if ((mask & 0x1) == 0)
10456 {
10457 mask ^= 0xC;
10458 now_it.block_length = 3;
10459 }
10460 else
10461 {
10462 mask ^= 0xE;
10463 now_it.block_length = 4;
10464 }
10465
10466 inst.instruction &= 0xfff0;
10467 inst.instruction |= mask;
10468 }
10469
10470 inst.instruction |= cond << 4;
10471 }
10472
10473 /* Helper function used for both push/pop and ldm/stm. */
10474 static void
10475 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10476 {
10477 bfd_boolean load;
10478
10479 load = (inst.instruction & (1 << 20)) != 0;
10480
10481 if (mask & (1 << 13))
10482 inst.error = _("SP not allowed in register list");
10483
10484 if ((mask & (1 << base)) != 0
10485 && writeback)
10486 inst.error = _("having the base register in the register list when "
10487 "using write back is UNPREDICTABLE");
10488
10489 if (load)
10490 {
10491 if (mask & (1 << 15))
10492 {
10493 if (mask & (1 << 14))
10494 inst.error = _("LR and PC should not both be in register list");
10495 else
10496 set_it_insn_type_last ();
10497 }
10498 }
10499 else
10500 {
10501 if (mask & (1 << 15))
10502 inst.error = _("PC not allowed in register list");
10503 }
10504
10505 if ((mask & (mask - 1)) == 0)
10506 {
10507 /* Single register transfers implemented as str/ldr. */
10508 if (writeback)
10509 {
10510 if (inst.instruction & (1 << 23))
10511 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10512 else
10513 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10514 }
10515 else
10516 {
10517 if (inst.instruction & (1 << 23))
10518 inst.instruction = 0x00800000; /* ia -> [base] */
10519 else
10520 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10521 }
10522
10523 inst.instruction |= 0xf8400000;
10524 if (load)
10525 inst.instruction |= 0x00100000;
10526
10527 mask = ffs (mask) - 1;
10528 mask <<= 12;
10529 }
10530 else if (writeback)
10531 inst.instruction |= WRITE_BACK;
10532
10533 inst.instruction |= mask;
10534 inst.instruction |= base << 16;
10535 }
10536
10537 static void
10538 do_t_ldmstm (void)
10539 {
10540 /* This really doesn't seem worth it. */
10541 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10542 _("expression too complex"));
10543 constraint (inst.operands[1].writeback,
10544 _("Thumb load/store multiple does not support {reglist}^"));
10545
10546 if (unified_syntax)
10547 {
10548 bfd_boolean narrow;
10549 unsigned mask;
10550
10551 narrow = FALSE;
10552 /* See if we can use a 16-bit instruction. */
10553 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10554 && inst.size_req != 4
10555 && !(inst.operands[1].imm & ~0xff))
10556 {
10557 mask = 1 << inst.operands[0].reg;
10558
10559 if (inst.operands[0].reg <= 7)
10560 {
10561 if (inst.instruction == T_MNEM_stmia
10562 ? inst.operands[0].writeback
10563 : (inst.operands[0].writeback
10564 == !(inst.operands[1].imm & mask)))
10565 {
10566 if (inst.instruction == T_MNEM_stmia
10567 && (inst.operands[1].imm & mask)
10568 && (inst.operands[1].imm & (mask - 1)))
10569 as_warn (_("value stored for r%d is UNKNOWN"),
10570 inst.operands[0].reg);
10571
10572 inst.instruction = THUMB_OP16 (inst.instruction);
10573 inst.instruction |= inst.operands[0].reg << 8;
10574 inst.instruction |= inst.operands[1].imm;
10575 narrow = TRUE;
10576 }
10577 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10578 {
10579 /* This means 1 register in reg list one of 3 situations:
10580 1. Instruction is stmia, but without writeback.
10581 2. lmdia without writeback, but with Rn not in
10582 reglist.
10583 3. ldmia with writeback, but with Rn in reglist.
10584 Case 3 is UNPREDICTABLE behaviour, so we handle
10585 case 1 and 2 which can be converted into a 16-bit
10586 str or ldr. The SP cases are handled below. */
10587 unsigned long opcode;
10588 /* First, record an error for Case 3. */
10589 if (inst.operands[1].imm & mask
10590 && inst.operands[0].writeback)
10591 inst.error =
10592 _("having the base register in the register list when "
10593 "using write back is UNPREDICTABLE");
10594
10595 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10596 : T_MNEM_ldr);
10597 inst.instruction = THUMB_OP16 (opcode);
10598 inst.instruction |= inst.operands[0].reg << 3;
10599 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10600 narrow = TRUE;
10601 }
10602 }
10603 else if (inst.operands[0] .reg == REG_SP)
10604 {
10605 if (inst.operands[0].writeback)
10606 {
10607 inst.instruction =
10608 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10609 ? T_MNEM_push : T_MNEM_pop);
10610 inst.instruction |= inst.operands[1].imm;
10611 narrow = TRUE;
10612 }
10613 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10614 {
10615 inst.instruction =
10616 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10617 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10618 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10619 narrow = TRUE;
10620 }
10621 }
10622 }
10623
10624 if (!narrow)
10625 {
10626 if (inst.instruction < 0xffff)
10627 inst.instruction = THUMB_OP32 (inst.instruction);
10628
10629 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10630 inst.operands[0].writeback);
10631 }
10632 }
10633 else
10634 {
10635 constraint (inst.operands[0].reg > 7
10636 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
10637 constraint (inst.instruction != T_MNEM_ldmia
10638 && inst.instruction != T_MNEM_stmia,
10639 _("Thumb-2 instruction only valid in unified syntax"));
10640 if (inst.instruction == T_MNEM_stmia)
10641 {
10642 if (!inst.operands[0].writeback)
10643 as_warn (_("this instruction will write back the base register"));
10644 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10645 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
10646 as_warn (_("value stored for r%d is UNKNOWN"),
10647 inst.operands[0].reg);
10648 }
10649 else
10650 {
10651 if (!inst.operands[0].writeback
10652 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10653 as_warn (_("this instruction will write back the base register"));
10654 else if (inst.operands[0].writeback
10655 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10656 as_warn (_("this instruction will not write back the base register"));
10657 }
10658
10659 inst.instruction = THUMB_OP16 (inst.instruction);
10660 inst.instruction |= inst.operands[0].reg << 8;
10661 inst.instruction |= inst.operands[1].imm;
10662 }
10663 }
10664
10665 static void
10666 do_t_ldrex (void)
10667 {
10668 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10669 || inst.operands[1].postind || inst.operands[1].writeback
10670 || inst.operands[1].immisreg || inst.operands[1].shifted
10671 || inst.operands[1].negative,
10672 BAD_ADDR_MODE);
10673
10674 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10675
10676 inst.instruction |= inst.operands[0].reg << 12;
10677 inst.instruction |= inst.operands[1].reg << 16;
10678 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10679 }
10680
10681 static void
10682 do_t_ldrexd (void)
10683 {
10684 if (!inst.operands[1].present)
10685 {
10686 constraint (inst.operands[0].reg == REG_LR,
10687 _("r14 not allowed as first register "
10688 "when second register is omitted"));
10689 inst.operands[1].reg = inst.operands[0].reg + 1;
10690 }
10691 constraint (inst.operands[0].reg == inst.operands[1].reg,
10692 BAD_OVERLAP);
10693
10694 inst.instruction |= inst.operands[0].reg << 12;
10695 inst.instruction |= inst.operands[1].reg << 8;
10696 inst.instruction |= inst.operands[2].reg << 16;
10697 }
10698
10699 static void
10700 do_t_ldst (void)
10701 {
10702 unsigned long opcode;
10703 int Rn;
10704
10705 if (inst.operands[0].isreg
10706 && !inst.operands[0].preind
10707 && inst.operands[0].reg == REG_PC)
10708 set_it_insn_type_last ();
10709
10710 opcode = inst.instruction;
10711 if (unified_syntax)
10712 {
10713 if (!inst.operands[1].isreg)
10714 {
10715 if (opcode <= 0xffff)
10716 inst.instruction = THUMB_OP32 (opcode);
10717 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10718 return;
10719 }
10720 if (inst.operands[1].isreg
10721 && !inst.operands[1].writeback
10722 && !inst.operands[1].shifted && !inst.operands[1].postind
10723 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10724 && opcode <= 0xffff
10725 && inst.size_req != 4)
10726 {
10727 /* Insn may have a 16-bit form. */
10728 Rn = inst.operands[1].reg;
10729 if (inst.operands[1].immisreg)
10730 {
10731 inst.instruction = THUMB_OP16 (opcode);
10732 /* [Rn, Rik] */
10733 if (Rn <= 7 && inst.operands[1].imm <= 7)
10734 goto op16;
10735 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10736 reject_bad_reg (inst.operands[1].imm);
10737 }
10738 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10739 && opcode != T_MNEM_ldrsb)
10740 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10741 || (Rn == REG_SP && opcode == T_MNEM_str))
10742 {
10743 /* [Rn, #const] */
10744 if (Rn > 7)
10745 {
10746 if (Rn == REG_PC)
10747 {
10748 if (inst.reloc.pc_rel)
10749 opcode = T_MNEM_ldr_pc2;
10750 else
10751 opcode = T_MNEM_ldr_pc;
10752 }
10753 else
10754 {
10755 if (opcode == T_MNEM_ldr)
10756 opcode = T_MNEM_ldr_sp;
10757 else
10758 opcode = T_MNEM_str_sp;
10759 }
10760 inst.instruction = inst.operands[0].reg << 8;
10761 }
10762 else
10763 {
10764 inst.instruction = inst.operands[0].reg;
10765 inst.instruction |= inst.operands[1].reg << 3;
10766 }
10767 inst.instruction |= THUMB_OP16 (opcode);
10768 if (inst.size_req == 2)
10769 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10770 else
10771 inst.relax = opcode;
10772 return;
10773 }
10774 }
10775 /* Definitely a 32-bit variant. */
10776
10777 /* Warning for Erratum 752419. */
10778 if (opcode == T_MNEM_ldr
10779 && inst.operands[0].reg == REG_SP
10780 && inst.operands[1].writeback == 1
10781 && !inst.operands[1].immisreg)
10782 {
10783 if (no_cpu_selected ()
10784 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10785 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10786 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10787 as_warn (_("This instruction may be unpredictable "
10788 "if executed on M-profile cores "
10789 "with interrupts enabled."));
10790 }
10791
10792 /* Do some validations regarding addressing modes. */
10793 if (inst.operands[1].immisreg)
10794 reject_bad_reg (inst.operands[1].imm);
10795
10796 constraint (inst.operands[1].writeback == 1
10797 && inst.operands[0].reg == inst.operands[1].reg,
10798 BAD_OVERLAP);
10799
10800 inst.instruction = THUMB_OP32 (opcode);
10801 inst.instruction |= inst.operands[0].reg << 12;
10802 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10803 check_ldr_r15_aligned ();
10804 return;
10805 }
10806
10807 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10808
10809 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10810 {
10811 /* Only [Rn,Rm] is acceptable. */
10812 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10813 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10814 || inst.operands[1].postind || inst.operands[1].shifted
10815 || inst.operands[1].negative,
10816 _("Thumb does not support this addressing mode"));
10817 inst.instruction = THUMB_OP16 (inst.instruction);
10818 goto op16;
10819 }
10820
10821 inst.instruction = THUMB_OP16 (inst.instruction);
10822 if (!inst.operands[1].isreg)
10823 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10824 return;
10825
10826 constraint (!inst.operands[1].preind
10827 || inst.operands[1].shifted
10828 || inst.operands[1].writeback,
10829 _("Thumb does not support this addressing mode"));
10830 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10831 {
10832 constraint (inst.instruction & 0x0600,
10833 _("byte or halfword not valid for base register"));
10834 constraint (inst.operands[1].reg == REG_PC
10835 && !(inst.instruction & THUMB_LOAD_BIT),
10836 _("r15 based store not allowed"));
10837 constraint (inst.operands[1].immisreg,
10838 _("invalid base register for register offset"));
10839
10840 if (inst.operands[1].reg == REG_PC)
10841 inst.instruction = T_OPCODE_LDR_PC;
10842 else if (inst.instruction & THUMB_LOAD_BIT)
10843 inst.instruction = T_OPCODE_LDR_SP;
10844 else
10845 inst.instruction = T_OPCODE_STR_SP;
10846
10847 inst.instruction |= inst.operands[0].reg << 8;
10848 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10849 return;
10850 }
10851
10852 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10853 if (!inst.operands[1].immisreg)
10854 {
10855 /* Immediate offset. */
10856 inst.instruction |= inst.operands[0].reg;
10857 inst.instruction |= inst.operands[1].reg << 3;
10858 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10859 return;
10860 }
10861
10862 /* Register offset. */
10863 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10864 constraint (inst.operands[1].negative,
10865 _("Thumb does not support this addressing mode"));
10866
10867 op16:
10868 switch (inst.instruction)
10869 {
10870 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10871 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10872 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10873 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10874 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10875 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10876 case 0x5600 /* ldrsb */:
10877 case 0x5e00 /* ldrsh */: break;
10878 default: abort ();
10879 }
10880
10881 inst.instruction |= inst.operands[0].reg;
10882 inst.instruction |= inst.operands[1].reg << 3;
10883 inst.instruction |= inst.operands[1].imm << 6;
10884 }
10885
10886 static void
10887 do_t_ldstd (void)
10888 {
10889 if (!inst.operands[1].present)
10890 {
10891 inst.operands[1].reg = inst.operands[0].reg + 1;
10892 constraint (inst.operands[0].reg == REG_LR,
10893 _("r14 not allowed here"));
10894 constraint (inst.operands[0].reg == REG_R12,
10895 _("r12 not allowed here"));
10896 }
10897
10898 if (inst.operands[2].writeback
10899 && (inst.operands[0].reg == inst.operands[2].reg
10900 || inst.operands[1].reg == inst.operands[2].reg))
10901 as_warn (_("base register written back, and overlaps "
10902 "one of transfer registers"));
10903
10904 inst.instruction |= inst.operands[0].reg << 12;
10905 inst.instruction |= inst.operands[1].reg << 8;
10906 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10907 }
10908
10909 static void
10910 do_t_ldstt (void)
10911 {
10912 inst.instruction |= inst.operands[0].reg << 12;
10913 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10914 }
10915
10916 static void
10917 do_t_mla (void)
10918 {
10919 unsigned Rd, Rn, Rm, Ra;
10920
10921 Rd = inst.operands[0].reg;
10922 Rn = inst.operands[1].reg;
10923 Rm = inst.operands[2].reg;
10924 Ra = inst.operands[3].reg;
10925
10926 reject_bad_reg (Rd);
10927 reject_bad_reg (Rn);
10928 reject_bad_reg (Rm);
10929 reject_bad_reg (Ra);
10930
10931 inst.instruction |= Rd << 8;
10932 inst.instruction |= Rn << 16;
10933 inst.instruction |= Rm;
10934 inst.instruction |= Ra << 12;
10935 }
10936
10937 static void
10938 do_t_mlal (void)
10939 {
10940 unsigned RdLo, RdHi, Rn, Rm;
10941
10942 RdLo = inst.operands[0].reg;
10943 RdHi = inst.operands[1].reg;
10944 Rn = inst.operands[2].reg;
10945 Rm = inst.operands[3].reg;
10946
10947 reject_bad_reg (RdLo);
10948 reject_bad_reg (RdHi);
10949 reject_bad_reg (Rn);
10950 reject_bad_reg (Rm);
10951
10952 inst.instruction |= RdLo << 12;
10953 inst.instruction |= RdHi << 8;
10954 inst.instruction |= Rn << 16;
10955 inst.instruction |= Rm;
10956 }
10957
10958 static void
10959 do_t_mov_cmp (void)
10960 {
10961 unsigned Rn, Rm;
10962
10963 Rn = inst.operands[0].reg;
10964 Rm = inst.operands[1].reg;
10965
10966 if (Rn == REG_PC)
10967 set_it_insn_type_last ();
10968
10969 if (unified_syntax)
10970 {
10971 int r0off = (inst.instruction == T_MNEM_mov
10972 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10973 unsigned long opcode;
10974 bfd_boolean narrow;
10975 bfd_boolean low_regs;
10976
10977 low_regs = (Rn <= 7 && Rm <= 7);
10978 opcode = inst.instruction;
10979 if (in_it_block ())
10980 narrow = opcode != T_MNEM_movs;
10981 else
10982 narrow = opcode != T_MNEM_movs || low_regs;
10983 if (inst.size_req == 4
10984 || inst.operands[1].shifted)
10985 narrow = FALSE;
10986
10987 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10988 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10989 && !inst.operands[1].shifted
10990 && Rn == REG_PC
10991 && Rm == REG_LR)
10992 {
10993 inst.instruction = T2_SUBS_PC_LR;
10994 return;
10995 }
10996
10997 if (opcode == T_MNEM_cmp)
10998 {
10999 constraint (Rn == REG_PC, BAD_PC);
11000 if (narrow)
11001 {
11002 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11003 but valid. */
11004 warn_deprecated_sp (Rm);
11005 /* R15 was documented as a valid choice for Rm in ARMv6,
11006 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11007 tools reject R15, so we do too. */
11008 constraint (Rm == REG_PC, BAD_PC);
11009 }
11010 else
11011 reject_bad_reg (Rm);
11012 }
11013 else if (opcode == T_MNEM_mov
11014 || opcode == T_MNEM_movs)
11015 {
11016 if (inst.operands[1].isreg)
11017 {
11018 if (opcode == T_MNEM_movs)
11019 {
11020 reject_bad_reg (Rn);
11021 reject_bad_reg (Rm);
11022 }
11023 else if (narrow)
11024 {
11025 /* This is mov.n. */
11026 if ((Rn == REG_SP || Rn == REG_PC)
11027 && (Rm == REG_SP || Rm == REG_PC))
11028 {
11029 as_warn (_("Use of r%u as a source register is "
11030 "deprecated when r%u is the destination "
11031 "register."), Rm, Rn);
11032 }
11033 }
11034 else
11035 {
11036 /* This is mov.w. */
11037 constraint (Rn == REG_PC, BAD_PC);
11038 constraint (Rm == REG_PC, BAD_PC);
11039 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11040 }
11041 }
11042 else
11043 reject_bad_reg (Rn);
11044 }
11045
11046 if (!inst.operands[1].isreg)
11047 {
11048 /* Immediate operand. */
11049 if (!in_it_block () && opcode == T_MNEM_mov)
11050 narrow = 0;
11051 if (low_regs && narrow)
11052 {
11053 inst.instruction = THUMB_OP16 (opcode);
11054 inst.instruction |= Rn << 8;
11055 if (inst.size_req == 2)
11056 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11057 else
11058 inst.relax = opcode;
11059 }
11060 else
11061 {
11062 inst.instruction = THUMB_OP32 (inst.instruction);
11063 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11064 inst.instruction |= Rn << r0off;
11065 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11066 }
11067 }
11068 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11069 && (inst.instruction == T_MNEM_mov
11070 || inst.instruction == T_MNEM_movs))
11071 {
11072 /* Register shifts are encoded as separate shift instructions. */
11073 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11074
11075 if (in_it_block ())
11076 narrow = !flags;
11077 else
11078 narrow = flags;
11079
11080 if (inst.size_req == 4)
11081 narrow = FALSE;
11082
11083 if (!low_regs || inst.operands[1].imm > 7)
11084 narrow = FALSE;
11085
11086 if (Rn != Rm)
11087 narrow = FALSE;
11088
11089 switch (inst.operands[1].shift_kind)
11090 {
11091 case SHIFT_LSL:
11092 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11093 break;
11094 case SHIFT_ASR:
11095 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11096 break;
11097 case SHIFT_LSR:
11098 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11099 break;
11100 case SHIFT_ROR:
11101 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11102 break;
11103 default:
11104 abort ();
11105 }
11106
11107 inst.instruction = opcode;
11108 if (narrow)
11109 {
11110 inst.instruction |= Rn;
11111 inst.instruction |= inst.operands[1].imm << 3;
11112 }
11113 else
11114 {
11115 if (flags)
11116 inst.instruction |= CONDS_BIT;
11117
11118 inst.instruction |= Rn << 8;
11119 inst.instruction |= Rm << 16;
11120 inst.instruction |= inst.operands[1].imm;
11121 }
11122 }
11123 else if (!narrow)
11124 {
11125 /* Some mov with immediate shift have narrow variants.
11126 Register shifts are handled above. */
11127 if (low_regs && inst.operands[1].shifted
11128 && (inst.instruction == T_MNEM_mov
11129 || inst.instruction == T_MNEM_movs))
11130 {
11131 if (in_it_block ())
11132 narrow = (inst.instruction == T_MNEM_mov);
11133 else
11134 narrow = (inst.instruction == T_MNEM_movs);
11135 }
11136
11137 if (narrow)
11138 {
11139 switch (inst.operands[1].shift_kind)
11140 {
11141 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11142 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11143 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11144 default: narrow = FALSE; break;
11145 }
11146 }
11147
11148 if (narrow)
11149 {
11150 inst.instruction |= Rn;
11151 inst.instruction |= Rm << 3;
11152 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11153 }
11154 else
11155 {
11156 inst.instruction = THUMB_OP32 (inst.instruction);
11157 inst.instruction |= Rn << r0off;
11158 encode_thumb32_shifted_operand (1);
11159 }
11160 }
11161 else
11162 switch (inst.instruction)
11163 {
11164 case T_MNEM_mov:
11165 /* In v4t or v5t a move of two lowregs produces unpredictable
11166 results. Don't allow this. */
11167 if (low_regs)
11168 {
11169 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11170 "MOV Rd, Rs with two low registers is not "
11171 "permitted on this architecture");
11172 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
11173 arm_ext_v6);
11174 }
11175
11176 inst.instruction = T_OPCODE_MOV_HR;
11177 inst.instruction |= (Rn & 0x8) << 4;
11178 inst.instruction |= (Rn & 0x7);
11179 inst.instruction |= Rm << 3;
11180 break;
11181
11182 case T_MNEM_movs:
11183 /* We know we have low registers at this point.
11184 Generate LSLS Rd, Rs, #0. */
11185 inst.instruction = T_OPCODE_LSL_I;
11186 inst.instruction |= Rn;
11187 inst.instruction |= Rm << 3;
11188 break;
11189
11190 case T_MNEM_cmp:
11191 if (low_regs)
11192 {
11193 inst.instruction = T_OPCODE_CMP_LR;
11194 inst.instruction |= Rn;
11195 inst.instruction |= Rm << 3;
11196 }
11197 else
11198 {
11199 inst.instruction = T_OPCODE_CMP_HR;
11200 inst.instruction |= (Rn & 0x8) << 4;
11201 inst.instruction |= (Rn & 0x7);
11202 inst.instruction |= Rm << 3;
11203 }
11204 break;
11205 }
11206 return;
11207 }
11208
11209 inst.instruction = THUMB_OP16 (inst.instruction);
11210
11211 /* PR 10443: Do not silently ignore shifted operands. */
11212 constraint (inst.operands[1].shifted,
11213 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11214
11215 if (inst.operands[1].isreg)
11216 {
11217 if (Rn < 8 && Rm < 8)
11218 {
11219 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11220 since a MOV instruction produces unpredictable results. */
11221 if (inst.instruction == T_OPCODE_MOV_I8)
11222 inst.instruction = T_OPCODE_ADD_I3;
11223 else
11224 inst.instruction = T_OPCODE_CMP_LR;
11225
11226 inst.instruction |= Rn;
11227 inst.instruction |= Rm << 3;
11228 }
11229 else
11230 {
11231 if (inst.instruction == T_OPCODE_MOV_I8)
11232 inst.instruction = T_OPCODE_MOV_HR;
11233 else
11234 inst.instruction = T_OPCODE_CMP_HR;
11235 do_t_cpy ();
11236 }
11237 }
11238 else
11239 {
11240 constraint (Rn > 7,
11241 _("only lo regs allowed with immediate"));
11242 inst.instruction |= Rn << 8;
11243 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11244 }
11245 }
11246
11247 static void
11248 do_t_mov16 (void)
11249 {
11250 unsigned Rd;
11251 bfd_vma imm;
11252 bfd_boolean top;
11253
11254 top = (inst.instruction & 0x00800000) != 0;
11255 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11256 {
11257 constraint (top, _(":lower16: not allowed this instruction"));
11258 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11259 }
11260 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11261 {
11262 constraint (!top, _(":upper16: not allowed this instruction"));
11263 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11264 }
11265
11266 Rd = inst.operands[0].reg;
11267 reject_bad_reg (Rd);
11268
11269 inst.instruction |= Rd << 8;
11270 if (inst.reloc.type == BFD_RELOC_UNUSED)
11271 {
11272 imm = inst.reloc.exp.X_add_number;
11273 inst.instruction |= (imm & 0xf000) << 4;
11274 inst.instruction |= (imm & 0x0800) << 15;
11275 inst.instruction |= (imm & 0x0700) << 4;
11276 inst.instruction |= (imm & 0x00ff);
11277 }
11278 }
11279
11280 static void
11281 do_t_mvn_tst (void)
11282 {
11283 unsigned Rn, Rm;
11284
11285 Rn = inst.operands[0].reg;
11286 Rm = inst.operands[1].reg;
11287
11288 if (inst.instruction == T_MNEM_cmp
11289 || inst.instruction == T_MNEM_cmn)
11290 constraint (Rn == REG_PC, BAD_PC);
11291 else
11292 reject_bad_reg (Rn);
11293 reject_bad_reg (Rm);
11294
11295 if (unified_syntax)
11296 {
11297 int r0off = (inst.instruction == T_MNEM_mvn
11298 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
11299 bfd_boolean narrow;
11300
11301 if (inst.size_req == 4
11302 || inst.instruction > 0xffff
11303 || inst.operands[1].shifted
11304 || Rn > 7 || Rm > 7)
11305 narrow = FALSE;
11306 else if (inst.instruction == T_MNEM_cmn)
11307 narrow = TRUE;
11308 else if (THUMB_SETS_FLAGS (inst.instruction))
11309 narrow = !in_it_block ();
11310 else
11311 narrow = in_it_block ();
11312
11313 if (!inst.operands[1].isreg)
11314 {
11315 /* For an immediate, we always generate a 32-bit opcode;
11316 section relaxation will shrink it later if possible. */
11317 if (inst.instruction < 0xffff)
11318 inst.instruction = THUMB_OP32 (inst.instruction);
11319 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11320 inst.instruction |= Rn << r0off;
11321 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11322 }
11323 else
11324 {
11325 /* See if we can do this with a 16-bit instruction. */
11326 if (narrow)
11327 {
11328 inst.instruction = THUMB_OP16 (inst.instruction);
11329 inst.instruction |= Rn;
11330 inst.instruction |= Rm << 3;
11331 }
11332 else
11333 {
11334 constraint (inst.operands[1].shifted
11335 && inst.operands[1].immisreg,
11336 _("shift must be constant"));
11337 if (inst.instruction < 0xffff)
11338 inst.instruction = THUMB_OP32 (inst.instruction);
11339 inst.instruction |= Rn << r0off;
11340 encode_thumb32_shifted_operand (1);
11341 }
11342 }
11343 }
11344 else
11345 {
11346 constraint (inst.instruction > 0xffff
11347 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11348 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11349 _("unshifted register required"));
11350 constraint (Rn > 7 || Rm > 7,
11351 BAD_HIREG);
11352
11353 inst.instruction = THUMB_OP16 (inst.instruction);
11354 inst.instruction |= Rn;
11355 inst.instruction |= Rm << 3;
11356 }
11357 }
11358
11359 static void
11360 do_t_mrs (void)
11361 {
11362 unsigned Rd;
11363
11364 if (do_vfp_nsyn_mrs () == SUCCESS)
11365 return;
11366
11367 Rd = inst.operands[0].reg;
11368 reject_bad_reg (Rd);
11369 inst.instruction |= Rd << 8;
11370
11371 if (inst.operands[1].isreg)
11372 {
11373 unsigned br = inst.operands[1].reg;
11374 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11375 as_bad (_("bad register for mrs"));
11376
11377 inst.instruction |= br & (0xf << 16);
11378 inst.instruction |= (br & 0x300) >> 4;
11379 inst.instruction |= (br & SPSR_BIT) >> 2;
11380 }
11381 else
11382 {
11383 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11384
11385 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11386 {
11387 /* PR gas/12698: The constraint is only applied for m_profile.
11388 If the user has specified -march=all, we want to ignore it as
11389 we are building for any CPU type, including non-m variants. */
11390 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11391 constraint ((flags != 0) && m_profile, _("selected processor does "
11392 "not support requested special purpose register"));
11393 }
11394 else
11395 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11396 devices). */
11397 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11398 _("'APSR', 'CPSR' or 'SPSR' expected"));
11399
11400 inst.instruction |= (flags & SPSR_BIT) >> 2;
11401 inst.instruction |= inst.operands[1].imm & 0xff;
11402 inst.instruction |= 0xf0000;
11403 }
11404 }
11405
11406 static void
11407 do_t_msr (void)
11408 {
11409 int flags;
11410 unsigned Rn;
11411
11412 if (do_vfp_nsyn_msr () == SUCCESS)
11413 return;
11414
11415 constraint (!inst.operands[1].isreg,
11416 _("Thumb encoding does not support an immediate here"));
11417
11418 if (inst.operands[0].isreg)
11419 flags = (int)(inst.operands[0].reg);
11420 else
11421 flags = inst.operands[0].imm;
11422
11423 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11424 {
11425 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11426
11427 /* PR gas/12698: The constraint is only applied for m_profile.
11428 If the user has specified -march=all, we want to ignore it as
11429 we are building for any CPU type, including non-m variants. */
11430 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11431 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11432 && (bits & ~(PSR_s | PSR_f)) != 0)
11433 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11434 && bits != PSR_f)) && m_profile,
11435 _("selected processor does not support requested special "
11436 "purpose register"));
11437 }
11438 else
11439 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11440 "requested special purpose register"));
11441
11442 Rn = inst.operands[1].reg;
11443 reject_bad_reg (Rn);
11444
11445 inst.instruction |= (flags & SPSR_BIT) >> 2;
11446 inst.instruction |= (flags & 0xf0000) >> 8;
11447 inst.instruction |= (flags & 0x300) >> 4;
11448 inst.instruction |= (flags & 0xff);
11449 inst.instruction |= Rn << 16;
11450 }
11451
11452 static void
11453 do_t_mul (void)
11454 {
11455 bfd_boolean narrow;
11456 unsigned Rd, Rn, Rm;
11457
11458 if (!inst.operands[2].present)
11459 inst.operands[2].reg = inst.operands[0].reg;
11460
11461 Rd = inst.operands[0].reg;
11462 Rn = inst.operands[1].reg;
11463 Rm = inst.operands[2].reg;
11464
11465 if (unified_syntax)
11466 {
11467 if (inst.size_req == 4
11468 || (Rd != Rn
11469 && Rd != Rm)
11470 || Rn > 7
11471 || Rm > 7)
11472 narrow = FALSE;
11473 else if (inst.instruction == T_MNEM_muls)
11474 narrow = !in_it_block ();
11475 else
11476 narrow = in_it_block ();
11477 }
11478 else
11479 {
11480 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
11481 constraint (Rn > 7 || Rm > 7,
11482 BAD_HIREG);
11483 narrow = TRUE;
11484 }
11485
11486 if (narrow)
11487 {
11488 /* 16-bit MULS/Conditional MUL. */
11489 inst.instruction = THUMB_OP16 (inst.instruction);
11490 inst.instruction |= Rd;
11491
11492 if (Rd == Rn)
11493 inst.instruction |= Rm << 3;
11494 else if (Rd == Rm)
11495 inst.instruction |= Rn << 3;
11496 else
11497 constraint (1, _("dest must overlap one source register"));
11498 }
11499 else
11500 {
11501 constraint (inst.instruction != T_MNEM_mul,
11502 _("Thumb-2 MUL must not set flags"));
11503 /* 32-bit MUL. */
11504 inst.instruction = THUMB_OP32 (inst.instruction);
11505 inst.instruction |= Rd << 8;
11506 inst.instruction |= Rn << 16;
11507 inst.instruction |= Rm << 0;
11508
11509 reject_bad_reg (Rd);
11510 reject_bad_reg (Rn);
11511 reject_bad_reg (Rm);
11512 }
11513 }
11514
11515 static void
11516 do_t_mull (void)
11517 {
11518 unsigned RdLo, RdHi, Rn, Rm;
11519
11520 RdLo = inst.operands[0].reg;
11521 RdHi = inst.operands[1].reg;
11522 Rn = inst.operands[2].reg;
11523 Rm = inst.operands[3].reg;
11524
11525 reject_bad_reg (RdLo);
11526 reject_bad_reg (RdHi);
11527 reject_bad_reg (Rn);
11528 reject_bad_reg (Rm);
11529
11530 inst.instruction |= RdLo << 12;
11531 inst.instruction |= RdHi << 8;
11532 inst.instruction |= Rn << 16;
11533 inst.instruction |= Rm;
11534
11535 if (RdLo == RdHi)
11536 as_tsktsk (_("rdhi and rdlo must be different"));
11537 }
11538
11539 static void
11540 do_t_nop (void)
11541 {
11542 set_it_insn_type (NEUTRAL_IT_INSN);
11543
11544 if (unified_syntax)
11545 {
11546 if (inst.size_req == 4 || inst.operands[0].imm > 15)
11547 {
11548 inst.instruction = THUMB_OP32 (inst.instruction);
11549 inst.instruction |= inst.operands[0].imm;
11550 }
11551 else
11552 {
11553 /* PR9722: Check for Thumb2 availability before
11554 generating a thumb2 nop instruction. */
11555 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
11556 {
11557 inst.instruction = THUMB_OP16 (inst.instruction);
11558 inst.instruction |= inst.operands[0].imm << 4;
11559 }
11560 else
11561 inst.instruction = 0x46c0;
11562 }
11563 }
11564 else
11565 {
11566 constraint (inst.operands[0].present,
11567 _("Thumb does not support NOP with hints"));
11568 inst.instruction = 0x46c0;
11569 }
11570 }
11571
11572 static void
11573 do_t_neg (void)
11574 {
11575 if (unified_syntax)
11576 {
11577 bfd_boolean narrow;
11578
11579 if (THUMB_SETS_FLAGS (inst.instruction))
11580 narrow = !in_it_block ();
11581 else
11582 narrow = in_it_block ();
11583 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11584 narrow = FALSE;
11585 if (inst.size_req == 4)
11586 narrow = FALSE;
11587
11588 if (!narrow)
11589 {
11590 inst.instruction = THUMB_OP32 (inst.instruction);
11591 inst.instruction |= inst.operands[0].reg << 8;
11592 inst.instruction |= inst.operands[1].reg << 16;
11593 }
11594 else
11595 {
11596 inst.instruction = THUMB_OP16 (inst.instruction);
11597 inst.instruction |= inst.operands[0].reg;
11598 inst.instruction |= inst.operands[1].reg << 3;
11599 }
11600 }
11601 else
11602 {
11603 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11604 BAD_HIREG);
11605 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11606
11607 inst.instruction = THUMB_OP16 (inst.instruction);
11608 inst.instruction |= inst.operands[0].reg;
11609 inst.instruction |= inst.operands[1].reg << 3;
11610 }
11611 }
11612
11613 static void
11614 do_t_orn (void)
11615 {
11616 unsigned Rd, Rn;
11617
11618 Rd = inst.operands[0].reg;
11619 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11620
11621 reject_bad_reg (Rd);
11622 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11623 reject_bad_reg (Rn);
11624
11625 inst.instruction |= Rd << 8;
11626 inst.instruction |= Rn << 16;
11627
11628 if (!inst.operands[2].isreg)
11629 {
11630 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11631 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11632 }
11633 else
11634 {
11635 unsigned Rm;
11636
11637 Rm = inst.operands[2].reg;
11638 reject_bad_reg (Rm);
11639
11640 constraint (inst.operands[2].shifted
11641 && inst.operands[2].immisreg,
11642 _("shift must be constant"));
11643 encode_thumb32_shifted_operand (2);
11644 }
11645 }
11646
11647 static void
11648 do_t_pkhbt (void)
11649 {
11650 unsigned Rd, Rn, Rm;
11651
11652 Rd = inst.operands[0].reg;
11653 Rn = inst.operands[1].reg;
11654 Rm = inst.operands[2].reg;
11655
11656 reject_bad_reg (Rd);
11657 reject_bad_reg (Rn);
11658 reject_bad_reg (Rm);
11659
11660 inst.instruction |= Rd << 8;
11661 inst.instruction |= Rn << 16;
11662 inst.instruction |= Rm;
11663 if (inst.operands[3].present)
11664 {
11665 unsigned int val = inst.reloc.exp.X_add_number;
11666 constraint (inst.reloc.exp.X_op != O_constant,
11667 _("expression too complex"));
11668 inst.instruction |= (val & 0x1c) << 10;
11669 inst.instruction |= (val & 0x03) << 6;
11670 }
11671 }
11672
11673 static void
11674 do_t_pkhtb (void)
11675 {
11676 if (!inst.operands[3].present)
11677 {
11678 unsigned Rtmp;
11679
11680 inst.instruction &= ~0x00000020;
11681
11682 /* PR 10168. Swap the Rm and Rn registers. */
11683 Rtmp = inst.operands[1].reg;
11684 inst.operands[1].reg = inst.operands[2].reg;
11685 inst.operands[2].reg = Rtmp;
11686 }
11687 do_t_pkhbt ();
11688 }
11689
11690 static void
11691 do_t_pld (void)
11692 {
11693 if (inst.operands[0].immisreg)
11694 reject_bad_reg (inst.operands[0].imm);
11695
11696 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11697 }
11698
11699 static void
11700 do_t_push_pop (void)
11701 {
11702 unsigned mask;
11703
11704 constraint (inst.operands[0].writeback,
11705 _("push/pop do not support {reglist}^"));
11706 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11707 _("expression too complex"));
11708
11709 mask = inst.operands[0].imm;
11710 if ((mask & ~0xff) == 0)
11711 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
11712 else if ((inst.instruction == T_MNEM_push
11713 && (mask & ~0xff) == 1 << REG_LR)
11714 || (inst.instruction == T_MNEM_pop
11715 && (mask & ~0xff) == 1 << REG_PC))
11716 {
11717 inst.instruction = THUMB_OP16 (inst.instruction);
11718 inst.instruction |= THUMB_PP_PC_LR;
11719 inst.instruction |= mask & 0xff;
11720 }
11721 else if (unified_syntax)
11722 {
11723 inst.instruction = THUMB_OP32 (inst.instruction);
11724 encode_thumb2_ldmstm (13, mask, TRUE);
11725 }
11726 else
11727 {
11728 inst.error = _("invalid register list to push/pop instruction");
11729 return;
11730 }
11731 }
11732
11733 static void
11734 do_t_rbit (void)
11735 {
11736 unsigned Rd, Rm;
11737
11738 Rd = inst.operands[0].reg;
11739 Rm = inst.operands[1].reg;
11740
11741 reject_bad_reg (Rd);
11742 reject_bad_reg (Rm);
11743
11744 inst.instruction |= Rd << 8;
11745 inst.instruction |= Rm << 16;
11746 inst.instruction |= Rm;
11747 }
11748
11749 static void
11750 do_t_rev (void)
11751 {
11752 unsigned Rd, Rm;
11753
11754 Rd = inst.operands[0].reg;
11755 Rm = inst.operands[1].reg;
11756
11757 reject_bad_reg (Rd);
11758 reject_bad_reg (Rm);
11759
11760 if (Rd <= 7 && Rm <= 7
11761 && inst.size_req != 4)
11762 {
11763 inst.instruction = THUMB_OP16 (inst.instruction);
11764 inst.instruction |= Rd;
11765 inst.instruction |= Rm << 3;
11766 }
11767 else if (unified_syntax)
11768 {
11769 inst.instruction = THUMB_OP32 (inst.instruction);
11770 inst.instruction |= Rd << 8;
11771 inst.instruction |= Rm << 16;
11772 inst.instruction |= Rm;
11773 }
11774 else
11775 inst.error = BAD_HIREG;
11776 }
11777
11778 static void
11779 do_t_rrx (void)
11780 {
11781 unsigned Rd, Rm;
11782
11783 Rd = inst.operands[0].reg;
11784 Rm = inst.operands[1].reg;
11785
11786 reject_bad_reg (Rd);
11787 reject_bad_reg (Rm);
11788
11789 inst.instruction |= Rd << 8;
11790 inst.instruction |= Rm;
11791 }
11792
11793 static void
11794 do_t_rsb (void)
11795 {
11796 unsigned Rd, Rs;
11797
11798 Rd = inst.operands[0].reg;
11799 Rs = (inst.operands[1].present
11800 ? inst.operands[1].reg /* Rd, Rs, foo */
11801 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11802
11803 reject_bad_reg (Rd);
11804 reject_bad_reg (Rs);
11805 if (inst.operands[2].isreg)
11806 reject_bad_reg (inst.operands[2].reg);
11807
11808 inst.instruction |= Rd << 8;
11809 inst.instruction |= Rs << 16;
11810 if (!inst.operands[2].isreg)
11811 {
11812 bfd_boolean narrow;
11813
11814 if ((inst.instruction & 0x00100000) != 0)
11815 narrow = !in_it_block ();
11816 else
11817 narrow = in_it_block ();
11818
11819 if (Rd > 7 || Rs > 7)
11820 narrow = FALSE;
11821
11822 if (inst.size_req == 4 || !unified_syntax)
11823 narrow = FALSE;
11824
11825 if (inst.reloc.exp.X_op != O_constant
11826 || inst.reloc.exp.X_add_number != 0)
11827 narrow = FALSE;
11828
11829 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11830 relaxation, but it doesn't seem worth the hassle. */
11831 if (narrow)
11832 {
11833 inst.reloc.type = BFD_RELOC_UNUSED;
11834 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11835 inst.instruction |= Rs << 3;
11836 inst.instruction |= Rd;
11837 }
11838 else
11839 {
11840 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11841 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11842 }
11843 }
11844 else
11845 encode_thumb32_shifted_operand (2);
11846 }
11847
11848 static void
11849 do_t_setend (void)
11850 {
11851 if (warn_on_deprecated
11852 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11853 as_warn (_("setend use is deprecated for ARMv8"));
11854
11855 set_it_insn_type (OUTSIDE_IT_INSN);
11856 if (inst.operands[0].imm)
11857 inst.instruction |= 0x8;
11858 }
11859
11860 static void
11861 do_t_shift (void)
11862 {
11863 if (!inst.operands[1].present)
11864 inst.operands[1].reg = inst.operands[0].reg;
11865
11866 if (unified_syntax)
11867 {
11868 bfd_boolean narrow;
11869 int shift_kind;
11870
11871 switch (inst.instruction)
11872 {
11873 case T_MNEM_asr:
11874 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11875 case T_MNEM_lsl:
11876 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11877 case T_MNEM_lsr:
11878 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11879 case T_MNEM_ror:
11880 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11881 default: abort ();
11882 }
11883
11884 if (THUMB_SETS_FLAGS (inst.instruction))
11885 narrow = !in_it_block ();
11886 else
11887 narrow = in_it_block ();
11888 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11889 narrow = FALSE;
11890 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11891 narrow = FALSE;
11892 if (inst.operands[2].isreg
11893 && (inst.operands[1].reg != inst.operands[0].reg
11894 || inst.operands[2].reg > 7))
11895 narrow = FALSE;
11896 if (inst.size_req == 4)
11897 narrow = FALSE;
11898
11899 reject_bad_reg (inst.operands[0].reg);
11900 reject_bad_reg (inst.operands[1].reg);
11901
11902 if (!narrow)
11903 {
11904 if (inst.operands[2].isreg)
11905 {
11906 reject_bad_reg (inst.operands[2].reg);
11907 inst.instruction = THUMB_OP32 (inst.instruction);
11908 inst.instruction |= inst.operands[0].reg << 8;
11909 inst.instruction |= inst.operands[1].reg << 16;
11910 inst.instruction |= inst.operands[2].reg;
11911
11912 /* PR 12854: Error on extraneous shifts. */
11913 constraint (inst.operands[2].shifted,
11914 _("extraneous shift as part of operand to shift insn"));
11915 }
11916 else
11917 {
11918 inst.operands[1].shifted = 1;
11919 inst.operands[1].shift_kind = shift_kind;
11920 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11921 ? T_MNEM_movs : T_MNEM_mov);
11922 inst.instruction |= inst.operands[0].reg << 8;
11923 encode_thumb32_shifted_operand (1);
11924 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11925 inst.reloc.type = BFD_RELOC_UNUSED;
11926 }
11927 }
11928 else
11929 {
11930 if (inst.operands[2].isreg)
11931 {
11932 switch (shift_kind)
11933 {
11934 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11935 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11936 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11937 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11938 default: abort ();
11939 }
11940
11941 inst.instruction |= inst.operands[0].reg;
11942 inst.instruction |= inst.operands[2].reg << 3;
11943
11944 /* PR 12854: Error on extraneous shifts. */
11945 constraint (inst.operands[2].shifted,
11946 _("extraneous shift as part of operand to shift insn"));
11947 }
11948 else
11949 {
11950 switch (shift_kind)
11951 {
11952 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11953 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11954 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11955 default: abort ();
11956 }
11957 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11958 inst.instruction |= inst.operands[0].reg;
11959 inst.instruction |= inst.operands[1].reg << 3;
11960 }
11961 }
11962 }
11963 else
11964 {
11965 constraint (inst.operands[0].reg > 7
11966 || inst.operands[1].reg > 7, BAD_HIREG);
11967 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11968
11969 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11970 {
11971 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11972 constraint (inst.operands[0].reg != inst.operands[1].reg,
11973 _("source1 and dest must be same register"));
11974
11975 switch (inst.instruction)
11976 {
11977 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11978 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11979 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11980 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11981 default: abort ();
11982 }
11983
11984 inst.instruction |= inst.operands[0].reg;
11985 inst.instruction |= inst.operands[2].reg << 3;
11986
11987 /* PR 12854: Error on extraneous shifts. */
11988 constraint (inst.operands[2].shifted,
11989 _("extraneous shift as part of operand to shift insn"));
11990 }
11991 else
11992 {
11993 switch (inst.instruction)
11994 {
11995 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11996 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11997 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11998 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11999 default: abort ();
12000 }
12001 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12002 inst.instruction |= inst.operands[0].reg;
12003 inst.instruction |= inst.operands[1].reg << 3;
12004 }
12005 }
12006 }
12007
12008 static void
12009 do_t_simd (void)
12010 {
12011 unsigned Rd, Rn, Rm;
12012
12013 Rd = inst.operands[0].reg;
12014 Rn = inst.operands[1].reg;
12015 Rm = inst.operands[2].reg;
12016
12017 reject_bad_reg (Rd);
12018 reject_bad_reg (Rn);
12019 reject_bad_reg (Rm);
12020
12021 inst.instruction |= Rd << 8;
12022 inst.instruction |= Rn << 16;
12023 inst.instruction |= Rm;
12024 }
12025
12026 static void
12027 do_t_simd2 (void)
12028 {
12029 unsigned Rd, Rn, Rm;
12030
12031 Rd = inst.operands[0].reg;
12032 Rm = inst.operands[1].reg;
12033 Rn = inst.operands[2].reg;
12034
12035 reject_bad_reg (Rd);
12036 reject_bad_reg (Rn);
12037 reject_bad_reg (Rm);
12038
12039 inst.instruction |= Rd << 8;
12040 inst.instruction |= Rn << 16;
12041 inst.instruction |= Rm;
12042 }
12043
12044 static void
12045 do_t_smc (void)
12046 {
12047 unsigned int value = inst.reloc.exp.X_add_number;
12048 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12049 _("SMC is not permitted on this architecture"));
12050 constraint (inst.reloc.exp.X_op != O_constant,
12051 _("expression too complex"));
12052 inst.reloc.type = BFD_RELOC_UNUSED;
12053 inst.instruction |= (value & 0xf000) >> 12;
12054 inst.instruction |= (value & 0x0ff0);
12055 inst.instruction |= (value & 0x000f) << 16;
12056 }
12057
12058 static void
12059 do_t_hvc (void)
12060 {
12061 unsigned int value = inst.reloc.exp.X_add_number;
12062
12063 inst.reloc.type = BFD_RELOC_UNUSED;
12064 inst.instruction |= (value & 0x0fff);
12065 inst.instruction |= (value & 0xf000) << 4;
12066 }
12067
12068 static void
12069 do_t_ssat_usat (int bias)
12070 {
12071 unsigned Rd, Rn;
12072
12073 Rd = inst.operands[0].reg;
12074 Rn = inst.operands[2].reg;
12075
12076 reject_bad_reg (Rd);
12077 reject_bad_reg (Rn);
12078
12079 inst.instruction |= Rd << 8;
12080 inst.instruction |= inst.operands[1].imm - bias;
12081 inst.instruction |= Rn << 16;
12082
12083 if (inst.operands[3].present)
12084 {
12085 offsetT shift_amount = inst.reloc.exp.X_add_number;
12086
12087 inst.reloc.type = BFD_RELOC_UNUSED;
12088
12089 constraint (inst.reloc.exp.X_op != O_constant,
12090 _("expression too complex"));
12091
12092 if (shift_amount != 0)
12093 {
12094 constraint (shift_amount > 31,
12095 _("shift expression is too large"));
12096
12097 if (inst.operands[3].shift_kind == SHIFT_ASR)
12098 inst.instruction |= 0x00200000; /* sh bit. */
12099
12100 inst.instruction |= (shift_amount & 0x1c) << 10;
12101 inst.instruction |= (shift_amount & 0x03) << 6;
12102 }
12103 }
12104 }
12105
12106 static void
12107 do_t_ssat (void)
12108 {
12109 do_t_ssat_usat (1);
12110 }
12111
12112 static void
12113 do_t_ssat16 (void)
12114 {
12115 unsigned Rd, Rn;
12116
12117 Rd = inst.operands[0].reg;
12118 Rn = inst.operands[2].reg;
12119
12120 reject_bad_reg (Rd);
12121 reject_bad_reg (Rn);
12122
12123 inst.instruction |= Rd << 8;
12124 inst.instruction |= inst.operands[1].imm - 1;
12125 inst.instruction |= Rn << 16;
12126 }
12127
12128 static void
12129 do_t_strex (void)
12130 {
12131 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12132 || inst.operands[2].postind || inst.operands[2].writeback
12133 || inst.operands[2].immisreg || inst.operands[2].shifted
12134 || inst.operands[2].negative,
12135 BAD_ADDR_MODE);
12136
12137 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12138
12139 inst.instruction |= inst.operands[0].reg << 8;
12140 inst.instruction |= inst.operands[1].reg << 12;
12141 inst.instruction |= inst.operands[2].reg << 16;
12142 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
12143 }
12144
12145 static void
12146 do_t_strexd (void)
12147 {
12148 if (!inst.operands[2].present)
12149 inst.operands[2].reg = inst.operands[1].reg + 1;
12150
12151 constraint (inst.operands[0].reg == inst.operands[1].reg
12152 || inst.operands[0].reg == inst.operands[2].reg
12153 || inst.operands[0].reg == inst.operands[3].reg,
12154 BAD_OVERLAP);
12155
12156 inst.instruction |= inst.operands[0].reg;
12157 inst.instruction |= inst.operands[1].reg << 12;
12158 inst.instruction |= inst.operands[2].reg << 8;
12159 inst.instruction |= inst.operands[3].reg << 16;
12160 }
12161
12162 static void
12163 do_t_sxtah (void)
12164 {
12165 unsigned Rd, Rn, Rm;
12166
12167 Rd = inst.operands[0].reg;
12168 Rn = inst.operands[1].reg;
12169 Rm = inst.operands[2].reg;
12170
12171 reject_bad_reg (Rd);
12172 reject_bad_reg (Rn);
12173 reject_bad_reg (Rm);
12174
12175 inst.instruction |= Rd << 8;
12176 inst.instruction |= Rn << 16;
12177 inst.instruction |= Rm;
12178 inst.instruction |= inst.operands[3].imm << 4;
12179 }
12180
12181 static void
12182 do_t_sxth (void)
12183 {
12184 unsigned Rd, Rm;
12185
12186 Rd = inst.operands[0].reg;
12187 Rm = inst.operands[1].reg;
12188
12189 reject_bad_reg (Rd);
12190 reject_bad_reg (Rm);
12191
12192 if (inst.instruction <= 0xffff
12193 && inst.size_req != 4
12194 && Rd <= 7 && Rm <= 7
12195 && (!inst.operands[2].present || inst.operands[2].imm == 0))
12196 {
12197 inst.instruction = THUMB_OP16 (inst.instruction);
12198 inst.instruction |= Rd;
12199 inst.instruction |= Rm << 3;
12200 }
12201 else if (unified_syntax)
12202 {
12203 if (inst.instruction <= 0xffff)
12204 inst.instruction = THUMB_OP32 (inst.instruction);
12205 inst.instruction |= Rd << 8;
12206 inst.instruction |= Rm;
12207 inst.instruction |= inst.operands[2].imm << 4;
12208 }
12209 else
12210 {
12211 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12212 _("Thumb encoding does not support rotation"));
12213 constraint (1, BAD_HIREG);
12214 }
12215 }
12216
12217 static void
12218 do_t_swi (void)
12219 {
12220 /* We have to do the following check manually as ARM_EXT_OS only applies
12221 to ARM_EXT_V6M. */
12222 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12223 {
12224 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12225 /* This only applies to the v6m howver, not later architectures. */
12226 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
12227 as_bad (_("SVC is not permitted on this architecture"));
12228 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12229 }
12230
12231 inst.reloc.type = BFD_RELOC_ARM_SWI;
12232 }
12233
12234 static void
12235 do_t_tb (void)
12236 {
12237 unsigned Rn, Rm;
12238 int half;
12239
12240 half = (inst.instruction & 0x10) != 0;
12241 set_it_insn_type_last ();
12242 constraint (inst.operands[0].immisreg,
12243 _("instruction requires register index"));
12244
12245 Rn = inst.operands[0].reg;
12246 Rm = inst.operands[0].imm;
12247
12248 constraint (Rn == REG_SP, BAD_SP);
12249 reject_bad_reg (Rm);
12250
12251 constraint (!half && inst.operands[0].shifted,
12252 _("instruction does not allow shifted index"));
12253 inst.instruction |= (Rn << 16) | Rm;
12254 }
12255
12256 static void
12257 do_t_usat (void)
12258 {
12259 do_t_ssat_usat (0);
12260 }
12261
12262 static void
12263 do_t_usat16 (void)
12264 {
12265 unsigned Rd, Rn;
12266
12267 Rd = inst.operands[0].reg;
12268 Rn = inst.operands[2].reg;
12269
12270 reject_bad_reg (Rd);
12271 reject_bad_reg (Rn);
12272
12273 inst.instruction |= Rd << 8;
12274 inst.instruction |= inst.operands[1].imm;
12275 inst.instruction |= Rn << 16;
12276 }
12277
12278 /* Neon instruction encoder helpers. */
12279
12280 /* Encodings for the different types for various Neon opcodes. */
12281
12282 /* An "invalid" code for the following tables. */
12283 #define N_INV -1u
12284
12285 struct neon_tab_entry
12286 {
12287 unsigned integer;
12288 unsigned float_or_poly;
12289 unsigned scalar_or_imm;
12290 };
12291
12292 /* Map overloaded Neon opcodes to their respective encodings. */
12293 #define NEON_ENC_TAB \
12294 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12295 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12296 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12297 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12298 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12299 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12300 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12301 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12302 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12303 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12304 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12305 /* Register variants of the following two instructions are encoded as
12306 vcge / vcgt with the operands reversed. */ \
12307 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12308 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
12309 X(vfma, N_INV, 0x0000c10, N_INV), \
12310 X(vfms, N_INV, 0x0200c10, N_INV), \
12311 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12312 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12313 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12314 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12315 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12316 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12317 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12318 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12319 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12320 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12321 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12322 X(vshl, 0x0000400, N_INV, 0x0800510), \
12323 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12324 X(vand, 0x0000110, N_INV, 0x0800030), \
12325 X(vbic, 0x0100110, N_INV, 0x0800030), \
12326 X(veor, 0x1000110, N_INV, N_INV), \
12327 X(vorn, 0x0300110, N_INV, 0x0800010), \
12328 X(vorr, 0x0200110, N_INV, 0x0800010), \
12329 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12330 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12331 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12332 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12333 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12334 X(vst1, 0x0000000, 0x0800000, N_INV), \
12335 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12336 X(vst2, 0x0000100, 0x0800100, N_INV), \
12337 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12338 X(vst3, 0x0000200, 0x0800200, N_INV), \
12339 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12340 X(vst4, 0x0000300, 0x0800300, N_INV), \
12341 X(vmovn, 0x1b20200, N_INV, N_INV), \
12342 X(vtrn, 0x1b20080, N_INV, N_INV), \
12343 X(vqmovn, 0x1b20200, N_INV, N_INV), \
12344 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12345 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
12346 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12347 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
12348 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12349 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
12350 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12351 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12352 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12353 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
12354 X(vseleq, 0xe000a00, N_INV, N_INV), \
12355 X(vselvs, 0xe100a00, N_INV, N_INV), \
12356 X(vselge, 0xe200a00, N_INV, N_INV), \
12357 X(vselgt, 0xe300a00, N_INV, N_INV), \
12358 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
12359 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
12360 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
12361 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
12362 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
12363 X(aes, 0x3b00300, N_INV, N_INV), \
12364 X(sha3op, 0x2000c00, N_INV, N_INV), \
12365 X(sha1h, 0x3b902c0, N_INV, N_INV), \
12366 X(sha2op, 0x3ba0380, N_INV, N_INV)
12367
12368 enum neon_opc
12369 {
12370 #define X(OPC,I,F,S) N_MNEM_##OPC
12371 NEON_ENC_TAB
12372 #undef X
12373 };
12374
12375 static const struct neon_tab_entry neon_enc_tab[] =
12376 {
12377 #define X(OPC,I,F,S) { (I), (F), (S) }
12378 NEON_ENC_TAB
12379 #undef X
12380 };
12381
12382 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
12383 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12384 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12385 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12386 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12387 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12388 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12389 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12390 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12391 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12392 #define NEON_ENC_SINGLE_(X) \
12393 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
12394 #define NEON_ENC_DOUBLE_(X) \
12395 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
12396 #define NEON_ENC_FPV8_(X) \
12397 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
12398
12399 #define NEON_ENCODE(type, inst) \
12400 do \
12401 { \
12402 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12403 inst.is_neon = 1; \
12404 } \
12405 while (0)
12406
12407 #define check_neon_suffixes \
12408 do \
12409 { \
12410 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12411 { \
12412 as_bad (_("invalid neon suffix for non neon instruction")); \
12413 return; \
12414 } \
12415 } \
12416 while (0)
12417
12418 /* Define shapes for instruction operands. The following mnemonic characters
12419 are used in this table:
12420
12421 F - VFP S<n> register
12422 D - Neon D<n> register
12423 Q - Neon Q<n> register
12424 I - Immediate
12425 S - Scalar
12426 R - ARM register
12427 L - D<n> register list
12428
12429 This table is used to generate various data:
12430 - enumerations of the form NS_DDR to be used as arguments to
12431 neon_select_shape.
12432 - a table classifying shapes into single, double, quad, mixed.
12433 - a table used to drive neon_select_shape. */
12434
12435 #define NEON_SHAPE_DEF \
12436 X(3, (D, D, D), DOUBLE), \
12437 X(3, (Q, Q, Q), QUAD), \
12438 X(3, (D, D, I), DOUBLE), \
12439 X(3, (Q, Q, I), QUAD), \
12440 X(3, (D, D, S), DOUBLE), \
12441 X(3, (Q, Q, S), QUAD), \
12442 X(2, (D, D), DOUBLE), \
12443 X(2, (Q, Q), QUAD), \
12444 X(2, (D, S), DOUBLE), \
12445 X(2, (Q, S), QUAD), \
12446 X(2, (D, R), DOUBLE), \
12447 X(2, (Q, R), QUAD), \
12448 X(2, (D, I), DOUBLE), \
12449 X(2, (Q, I), QUAD), \
12450 X(3, (D, L, D), DOUBLE), \
12451 X(2, (D, Q), MIXED), \
12452 X(2, (Q, D), MIXED), \
12453 X(3, (D, Q, I), MIXED), \
12454 X(3, (Q, D, I), MIXED), \
12455 X(3, (Q, D, D), MIXED), \
12456 X(3, (D, Q, Q), MIXED), \
12457 X(3, (Q, Q, D), MIXED), \
12458 X(3, (Q, D, S), MIXED), \
12459 X(3, (D, Q, S), MIXED), \
12460 X(4, (D, D, D, I), DOUBLE), \
12461 X(4, (Q, Q, Q, I), QUAD), \
12462 X(2, (F, F), SINGLE), \
12463 X(3, (F, F, F), SINGLE), \
12464 X(2, (F, I), SINGLE), \
12465 X(2, (F, D), MIXED), \
12466 X(2, (D, F), MIXED), \
12467 X(3, (F, F, I), MIXED), \
12468 X(4, (R, R, F, F), SINGLE), \
12469 X(4, (F, F, R, R), SINGLE), \
12470 X(3, (D, R, R), DOUBLE), \
12471 X(3, (R, R, D), DOUBLE), \
12472 X(2, (S, R), SINGLE), \
12473 X(2, (R, S), SINGLE), \
12474 X(2, (F, R), SINGLE), \
12475 X(2, (R, F), SINGLE)
12476
12477 #define S2(A,B) NS_##A##B
12478 #define S3(A,B,C) NS_##A##B##C
12479 #define S4(A,B,C,D) NS_##A##B##C##D
12480
12481 #define X(N, L, C) S##N L
12482
12483 enum neon_shape
12484 {
12485 NEON_SHAPE_DEF,
12486 NS_NULL
12487 };
12488
12489 #undef X
12490 #undef S2
12491 #undef S3
12492 #undef S4
12493
12494 enum neon_shape_class
12495 {
12496 SC_SINGLE,
12497 SC_DOUBLE,
12498 SC_QUAD,
12499 SC_MIXED
12500 };
12501
12502 #define X(N, L, C) SC_##C
12503
12504 static enum neon_shape_class neon_shape_class[] =
12505 {
12506 NEON_SHAPE_DEF
12507 };
12508
12509 #undef X
12510
12511 enum neon_shape_el
12512 {
12513 SE_F,
12514 SE_D,
12515 SE_Q,
12516 SE_I,
12517 SE_S,
12518 SE_R,
12519 SE_L
12520 };
12521
12522 /* Register widths of above. */
12523 static unsigned neon_shape_el_size[] =
12524 {
12525 32,
12526 64,
12527 128,
12528 0,
12529 32,
12530 32,
12531 0
12532 };
12533
12534 struct neon_shape_info
12535 {
12536 unsigned els;
12537 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12538 };
12539
12540 #define S2(A,B) { SE_##A, SE_##B }
12541 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12542 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12543
12544 #define X(N, L, C) { N, S##N L }
12545
12546 static struct neon_shape_info neon_shape_tab[] =
12547 {
12548 NEON_SHAPE_DEF
12549 };
12550
12551 #undef X
12552 #undef S2
12553 #undef S3
12554 #undef S4
12555
12556 /* Bit masks used in type checking given instructions.
12557 'N_EQK' means the type must be the same as (or based on in some way) the key
12558 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12559 set, various other bits can be set as well in order to modify the meaning of
12560 the type constraint. */
12561
12562 enum neon_type_mask
12563 {
12564 N_S8 = 0x0000001,
12565 N_S16 = 0x0000002,
12566 N_S32 = 0x0000004,
12567 N_S64 = 0x0000008,
12568 N_U8 = 0x0000010,
12569 N_U16 = 0x0000020,
12570 N_U32 = 0x0000040,
12571 N_U64 = 0x0000080,
12572 N_I8 = 0x0000100,
12573 N_I16 = 0x0000200,
12574 N_I32 = 0x0000400,
12575 N_I64 = 0x0000800,
12576 N_8 = 0x0001000,
12577 N_16 = 0x0002000,
12578 N_32 = 0x0004000,
12579 N_64 = 0x0008000,
12580 N_P8 = 0x0010000,
12581 N_P16 = 0x0020000,
12582 N_F16 = 0x0040000,
12583 N_F32 = 0x0080000,
12584 N_F64 = 0x0100000,
12585 N_P64 = 0x0200000,
12586 N_KEY = 0x1000000, /* Key element (main type specifier). */
12587 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
12588 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
12589 N_UNT = 0x8000000, /* Must be explicitly untyped. */
12590 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12591 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12592 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12593 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12594 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12595 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12596 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
12597 N_UTYP = 0,
12598 N_MAX_NONSPECIAL = N_P64
12599 };
12600
12601 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12602
12603 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12604 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12605 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12606 #define N_SUF_32 (N_SU_32 | N_F32)
12607 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12608 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12609
12610 /* Pass this as the first type argument to neon_check_type to ignore types
12611 altogether. */
12612 #define N_IGNORE_TYPE (N_KEY | N_EQK)
12613
12614 /* Select a "shape" for the current instruction (describing register types or
12615 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12616 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12617 function of operand parsing, so this function doesn't need to be called.
12618 Shapes should be listed in order of decreasing length. */
12619
12620 static enum neon_shape
12621 neon_select_shape (enum neon_shape shape, ...)
12622 {
12623 va_list ap;
12624 enum neon_shape first_shape = shape;
12625
12626 /* Fix missing optional operands. FIXME: we don't know at this point how
12627 many arguments we should have, so this makes the assumption that we have
12628 > 1. This is true of all current Neon opcodes, I think, but may not be
12629 true in the future. */
12630 if (!inst.operands[1].present)
12631 inst.operands[1] = inst.operands[0];
12632
12633 va_start (ap, shape);
12634
12635 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
12636 {
12637 unsigned j;
12638 int matches = 1;
12639
12640 for (j = 0; j < neon_shape_tab[shape].els; j++)
12641 {
12642 if (!inst.operands[j].present)
12643 {
12644 matches = 0;
12645 break;
12646 }
12647
12648 switch (neon_shape_tab[shape].el[j])
12649 {
12650 case SE_F:
12651 if (!(inst.operands[j].isreg
12652 && inst.operands[j].isvec
12653 && inst.operands[j].issingle
12654 && !inst.operands[j].isquad))
12655 matches = 0;
12656 break;
12657
12658 case SE_D:
12659 if (!(inst.operands[j].isreg
12660 && inst.operands[j].isvec
12661 && !inst.operands[j].isquad
12662 && !inst.operands[j].issingle))
12663 matches = 0;
12664 break;
12665
12666 case SE_R:
12667 if (!(inst.operands[j].isreg
12668 && !inst.operands[j].isvec))
12669 matches = 0;
12670 break;
12671
12672 case SE_Q:
12673 if (!(inst.operands[j].isreg
12674 && inst.operands[j].isvec
12675 && inst.operands[j].isquad
12676 && !inst.operands[j].issingle))
12677 matches = 0;
12678 break;
12679
12680 case SE_I:
12681 if (!(!inst.operands[j].isreg
12682 && !inst.operands[j].isscalar))
12683 matches = 0;
12684 break;
12685
12686 case SE_S:
12687 if (!(!inst.operands[j].isreg
12688 && inst.operands[j].isscalar))
12689 matches = 0;
12690 break;
12691
12692 case SE_L:
12693 break;
12694 }
12695 if (!matches)
12696 break;
12697 }
12698 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12699 /* We've matched all the entries in the shape table, and we don't
12700 have any left over operands which have not been matched. */
12701 break;
12702 }
12703
12704 va_end (ap);
12705
12706 if (shape == NS_NULL && first_shape != NS_NULL)
12707 first_error (_("invalid instruction shape"));
12708
12709 return shape;
12710 }
12711
12712 /* True if SHAPE is predominantly a quadword operation (most of the time, this
12713 means the Q bit should be set). */
12714
12715 static int
12716 neon_quad (enum neon_shape shape)
12717 {
12718 return neon_shape_class[shape] == SC_QUAD;
12719 }
12720
12721 static void
12722 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12723 unsigned *g_size)
12724 {
12725 /* Allow modification to be made to types which are constrained to be
12726 based on the key element, based on bits set alongside N_EQK. */
12727 if ((typebits & N_EQK) != 0)
12728 {
12729 if ((typebits & N_HLF) != 0)
12730 *g_size /= 2;
12731 else if ((typebits & N_DBL) != 0)
12732 *g_size *= 2;
12733 if ((typebits & N_SGN) != 0)
12734 *g_type = NT_signed;
12735 else if ((typebits & N_UNS) != 0)
12736 *g_type = NT_unsigned;
12737 else if ((typebits & N_INT) != 0)
12738 *g_type = NT_integer;
12739 else if ((typebits & N_FLT) != 0)
12740 *g_type = NT_float;
12741 else if ((typebits & N_SIZ) != 0)
12742 *g_type = NT_untyped;
12743 }
12744 }
12745
12746 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12747 operand type, i.e. the single type specified in a Neon instruction when it
12748 is the only one given. */
12749
12750 static struct neon_type_el
12751 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12752 {
12753 struct neon_type_el dest = *key;
12754
12755 gas_assert ((thisarg & N_EQK) != 0);
12756
12757 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12758
12759 return dest;
12760 }
12761
12762 /* Convert Neon type and size into compact bitmask representation. */
12763
12764 static enum neon_type_mask
12765 type_chk_of_el_type (enum neon_el_type type, unsigned size)
12766 {
12767 switch (type)
12768 {
12769 case NT_untyped:
12770 switch (size)
12771 {
12772 case 8: return N_8;
12773 case 16: return N_16;
12774 case 32: return N_32;
12775 case 64: return N_64;
12776 default: ;
12777 }
12778 break;
12779
12780 case NT_integer:
12781 switch (size)
12782 {
12783 case 8: return N_I8;
12784 case 16: return N_I16;
12785 case 32: return N_I32;
12786 case 64: return N_I64;
12787 default: ;
12788 }
12789 break;
12790
12791 case NT_float:
12792 switch (size)
12793 {
12794 case 16: return N_F16;
12795 case 32: return N_F32;
12796 case 64: return N_F64;
12797 default: ;
12798 }
12799 break;
12800
12801 case NT_poly:
12802 switch (size)
12803 {
12804 case 8: return N_P8;
12805 case 16: return N_P16;
12806 case 64: return N_P64;
12807 default: ;
12808 }
12809 break;
12810
12811 case NT_signed:
12812 switch (size)
12813 {
12814 case 8: return N_S8;
12815 case 16: return N_S16;
12816 case 32: return N_S32;
12817 case 64: return N_S64;
12818 default: ;
12819 }
12820 break;
12821
12822 case NT_unsigned:
12823 switch (size)
12824 {
12825 case 8: return N_U8;
12826 case 16: return N_U16;
12827 case 32: return N_U32;
12828 case 64: return N_U64;
12829 default: ;
12830 }
12831 break;
12832
12833 default: ;
12834 }
12835
12836 return N_UTYP;
12837 }
12838
12839 /* Convert compact Neon bitmask type representation to a type and size. Only
12840 handles the case where a single bit is set in the mask. */
12841
12842 static int
12843 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12844 enum neon_type_mask mask)
12845 {
12846 if ((mask & N_EQK) != 0)
12847 return FAIL;
12848
12849 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12850 *size = 8;
12851 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
12852 *size = 16;
12853 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12854 *size = 32;
12855 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
12856 *size = 64;
12857 else
12858 return FAIL;
12859
12860 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12861 *type = NT_signed;
12862 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12863 *type = NT_unsigned;
12864 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12865 *type = NT_integer;
12866 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12867 *type = NT_untyped;
12868 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
12869 *type = NT_poly;
12870 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
12871 *type = NT_float;
12872 else
12873 return FAIL;
12874
12875 return SUCCESS;
12876 }
12877
12878 /* Modify a bitmask of allowed types. This is only needed for type
12879 relaxation. */
12880
12881 static unsigned
12882 modify_types_allowed (unsigned allowed, unsigned mods)
12883 {
12884 unsigned size;
12885 enum neon_el_type type;
12886 unsigned destmask;
12887 int i;
12888
12889 destmask = 0;
12890
12891 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12892 {
12893 if (el_type_of_type_chk (&type, &size,
12894 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12895 {
12896 neon_modify_type_size (mods, &type, &size);
12897 destmask |= type_chk_of_el_type (type, size);
12898 }
12899 }
12900
12901 return destmask;
12902 }
12903
12904 /* Check type and return type classification.
12905 The manual states (paraphrase): If one datatype is given, it indicates the
12906 type given in:
12907 - the second operand, if there is one
12908 - the operand, if there is no second operand
12909 - the result, if there are no operands.
12910 This isn't quite good enough though, so we use a concept of a "key" datatype
12911 which is set on a per-instruction basis, which is the one which matters when
12912 only one data type is written.
12913 Note: this function has side-effects (e.g. filling in missing operands). All
12914 Neon instructions should call it before performing bit encoding. */
12915
12916 static struct neon_type_el
12917 neon_check_type (unsigned els, enum neon_shape ns, ...)
12918 {
12919 va_list ap;
12920 unsigned i, pass, key_el = 0;
12921 unsigned types[NEON_MAX_TYPE_ELS];
12922 enum neon_el_type k_type = NT_invtype;
12923 unsigned k_size = -1u;
12924 struct neon_type_el badtype = {NT_invtype, -1};
12925 unsigned key_allowed = 0;
12926
12927 /* Optional registers in Neon instructions are always (not) in operand 1.
12928 Fill in the missing operand here, if it was omitted. */
12929 if (els > 1 && !inst.operands[1].present)
12930 inst.operands[1] = inst.operands[0];
12931
12932 /* Suck up all the varargs. */
12933 va_start (ap, ns);
12934 for (i = 0; i < els; i++)
12935 {
12936 unsigned thisarg = va_arg (ap, unsigned);
12937 if (thisarg == N_IGNORE_TYPE)
12938 {
12939 va_end (ap);
12940 return badtype;
12941 }
12942 types[i] = thisarg;
12943 if ((thisarg & N_KEY) != 0)
12944 key_el = i;
12945 }
12946 va_end (ap);
12947
12948 if (inst.vectype.elems > 0)
12949 for (i = 0; i < els; i++)
12950 if (inst.operands[i].vectype.type != NT_invtype)
12951 {
12952 first_error (_("types specified in both the mnemonic and operands"));
12953 return badtype;
12954 }
12955
12956 /* Duplicate inst.vectype elements here as necessary.
12957 FIXME: No idea if this is exactly the same as the ARM assembler,
12958 particularly when an insn takes one register and one non-register
12959 operand. */
12960 if (inst.vectype.elems == 1 && els > 1)
12961 {
12962 unsigned j;
12963 inst.vectype.elems = els;
12964 inst.vectype.el[key_el] = inst.vectype.el[0];
12965 for (j = 0; j < els; j++)
12966 if (j != key_el)
12967 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12968 types[j]);
12969 }
12970 else if (inst.vectype.elems == 0 && els > 0)
12971 {
12972 unsigned j;
12973 /* No types were given after the mnemonic, so look for types specified
12974 after each operand. We allow some flexibility here; as long as the
12975 "key" operand has a type, we can infer the others. */
12976 for (j = 0; j < els; j++)
12977 if (inst.operands[j].vectype.type != NT_invtype)
12978 inst.vectype.el[j] = inst.operands[j].vectype;
12979
12980 if (inst.operands[key_el].vectype.type != NT_invtype)
12981 {
12982 for (j = 0; j < els; j++)
12983 if (inst.operands[j].vectype.type == NT_invtype)
12984 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12985 types[j]);
12986 }
12987 else
12988 {
12989 first_error (_("operand types can't be inferred"));
12990 return badtype;
12991 }
12992 }
12993 else if (inst.vectype.elems != els)
12994 {
12995 first_error (_("type specifier has the wrong number of parts"));
12996 return badtype;
12997 }
12998
12999 for (pass = 0; pass < 2; pass++)
13000 {
13001 for (i = 0; i < els; i++)
13002 {
13003 unsigned thisarg = types[i];
13004 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13005 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13006 enum neon_el_type g_type = inst.vectype.el[i].type;
13007 unsigned g_size = inst.vectype.el[i].size;
13008
13009 /* Decay more-specific signed & unsigned types to sign-insensitive
13010 integer types if sign-specific variants are unavailable. */
13011 if ((g_type == NT_signed || g_type == NT_unsigned)
13012 && (types_allowed & N_SU_ALL) == 0)
13013 g_type = NT_integer;
13014
13015 /* If only untyped args are allowed, decay any more specific types to
13016 them. Some instructions only care about signs for some element
13017 sizes, so handle that properly. */
13018 if (((types_allowed & N_UNT) == 0)
13019 && ((g_size == 8 && (types_allowed & N_8) != 0)
13020 || (g_size == 16 && (types_allowed & N_16) != 0)
13021 || (g_size == 32 && (types_allowed & N_32) != 0)
13022 || (g_size == 64 && (types_allowed & N_64) != 0)))
13023 g_type = NT_untyped;
13024
13025 if (pass == 0)
13026 {
13027 if ((thisarg & N_KEY) != 0)
13028 {
13029 k_type = g_type;
13030 k_size = g_size;
13031 key_allowed = thisarg & ~N_KEY;
13032 }
13033 }
13034 else
13035 {
13036 if ((thisarg & N_VFP) != 0)
13037 {
13038 enum neon_shape_el regshape;
13039 unsigned regwidth, match;
13040
13041 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13042 if (ns == NS_NULL)
13043 {
13044 first_error (_("invalid instruction shape"));
13045 return badtype;
13046 }
13047 regshape = neon_shape_tab[ns].el[i];
13048 regwidth = neon_shape_el_size[regshape];
13049
13050 /* In VFP mode, operands must match register widths. If we
13051 have a key operand, use its width, else use the width of
13052 the current operand. */
13053 if (k_size != -1u)
13054 match = k_size;
13055 else
13056 match = g_size;
13057
13058 if (regwidth != match)
13059 {
13060 first_error (_("operand size must match register width"));
13061 return badtype;
13062 }
13063 }
13064
13065 if ((thisarg & N_EQK) == 0)
13066 {
13067 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13068
13069 if ((given_type & types_allowed) == 0)
13070 {
13071 first_error (_("bad type in Neon instruction"));
13072 return badtype;
13073 }
13074 }
13075 else
13076 {
13077 enum neon_el_type mod_k_type = k_type;
13078 unsigned mod_k_size = k_size;
13079 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13080 if (g_type != mod_k_type || g_size != mod_k_size)
13081 {
13082 first_error (_("inconsistent types in Neon instruction"));
13083 return badtype;
13084 }
13085 }
13086 }
13087 }
13088 }
13089
13090 return inst.vectype.el[key_el];
13091 }
13092
13093 /* Neon-style VFP instruction forwarding. */
13094
13095 /* Thumb VFP instructions have 0xE in the condition field. */
13096
13097 static void
13098 do_vfp_cond_or_thumb (void)
13099 {
13100 inst.is_neon = 1;
13101
13102 if (thumb_mode)
13103 inst.instruction |= 0xe0000000;
13104 else
13105 inst.instruction |= inst.cond << 28;
13106 }
13107
13108 /* Look up and encode a simple mnemonic, for use as a helper function for the
13109 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13110 etc. It is assumed that operand parsing has already been done, and that the
13111 operands are in the form expected by the given opcode (this isn't necessarily
13112 the same as the form in which they were parsed, hence some massaging must
13113 take place before this function is called).
13114 Checks current arch version against that in the looked-up opcode. */
13115
13116 static void
13117 do_vfp_nsyn_opcode (const char *opname)
13118 {
13119 const struct asm_opcode *opcode;
13120
13121 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
13122
13123 if (!opcode)
13124 abort ();
13125
13126 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
13127 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13128 _(BAD_FPU));
13129
13130 inst.is_neon = 1;
13131
13132 if (thumb_mode)
13133 {
13134 inst.instruction = opcode->tvalue;
13135 opcode->tencode ();
13136 }
13137 else
13138 {
13139 inst.instruction = (inst.cond << 28) | opcode->avalue;
13140 opcode->aencode ();
13141 }
13142 }
13143
13144 static void
13145 do_vfp_nsyn_add_sub (enum neon_shape rs)
13146 {
13147 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13148
13149 if (rs == NS_FFF)
13150 {
13151 if (is_add)
13152 do_vfp_nsyn_opcode ("fadds");
13153 else
13154 do_vfp_nsyn_opcode ("fsubs");
13155 }
13156 else
13157 {
13158 if (is_add)
13159 do_vfp_nsyn_opcode ("faddd");
13160 else
13161 do_vfp_nsyn_opcode ("fsubd");
13162 }
13163 }
13164
13165 /* Check operand types to see if this is a VFP instruction, and if so call
13166 PFN (). */
13167
13168 static int
13169 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13170 {
13171 enum neon_shape rs;
13172 struct neon_type_el et;
13173
13174 switch (args)
13175 {
13176 case 2:
13177 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13178 et = neon_check_type (2, rs,
13179 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13180 break;
13181
13182 case 3:
13183 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13184 et = neon_check_type (3, rs,
13185 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13186 break;
13187
13188 default:
13189 abort ();
13190 }
13191
13192 if (et.type != NT_invtype)
13193 {
13194 pfn (rs);
13195 return SUCCESS;
13196 }
13197
13198 inst.error = NULL;
13199 return FAIL;
13200 }
13201
13202 static void
13203 do_vfp_nsyn_mla_mls (enum neon_shape rs)
13204 {
13205 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
13206
13207 if (rs == NS_FFF)
13208 {
13209 if (is_mla)
13210 do_vfp_nsyn_opcode ("fmacs");
13211 else
13212 do_vfp_nsyn_opcode ("fnmacs");
13213 }
13214 else
13215 {
13216 if (is_mla)
13217 do_vfp_nsyn_opcode ("fmacd");
13218 else
13219 do_vfp_nsyn_opcode ("fnmacd");
13220 }
13221 }
13222
13223 static void
13224 do_vfp_nsyn_fma_fms (enum neon_shape rs)
13225 {
13226 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13227
13228 if (rs == NS_FFF)
13229 {
13230 if (is_fma)
13231 do_vfp_nsyn_opcode ("ffmas");
13232 else
13233 do_vfp_nsyn_opcode ("ffnmas");
13234 }
13235 else
13236 {
13237 if (is_fma)
13238 do_vfp_nsyn_opcode ("ffmad");
13239 else
13240 do_vfp_nsyn_opcode ("ffnmad");
13241 }
13242 }
13243
13244 static void
13245 do_vfp_nsyn_mul (enum neon_shape rs)
13246 {
13247 if (rs == NS_FFF)
13248 do_vfp_nsyn_opcode ("fmuls");
13249 else
13250 do_vfp_nsyn_opcode ("fmuld");
13251 }
13252
13253 static void
13254 do_vfp_nsyn_abs_neg (enum neon_shape rs)
13255 {
13256 int is_neg = (inst.instruction & 0x80) != 0;
13257 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13258
13259 if (rs == NS_FF)
13260 {
13261 if (is_neg)
13262 do_vfp_nsyn_opcode ("fnegs");
13263 else
13264 do_vfp_nsyn_opcode ("fabss");
13265 }
13266 else
13267 {
13268 if (is_neg)
13269 do_vfp_nsyn_opcode ("fnegd");
13270 else
13271 do_vfp_nsyn_opcode ("fabsd");
13272 }
13273 }
13274
13275 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13276 insns belong to Neon, and are handled elsewhere. */
13277
13278 static void
13279 do_vfp_nsyn_ldm_stm (int is_dbmode)
13280 {
13281 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13282 if (is_ldm)
13283 {
13284 if (is_dbmode)
13285 do_vfp_nsyn_opcode ("fldmdbs");
13286 else
13287 do_vfp_nsyn_opcode ("fldmias");
13288 }
13289 else
13290 {
13291 if (is_dbmode)
13292 do_vfp_nsyn_opcode ("fstmdbs");
13293 else
13294 do_vfp_nsyn_opcode ("fstmias");
13295 }
13296 }
13297
13298 static void
13299 do_vfp_nsyn_sqrt (void)
13300 {
13301 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13302 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13303
13304 if (rs == NS_FF)
13305 do_vfp_nsyn_opcode ("fsqrts");
13306 else
13307 do_vfp_nsyn_opcode ("fsqrtd");
13308 }
13309
13310 static void
13311 do_vfp_nsyn_div (void)
13312 {
13313 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13314 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13315 N_F32 | N_F64 | N_KEY | N_VFP);
13316
13317 if (rs == NS_FFF)
13318 do_vfp_nsyn_opcode ("fdivs");
13319 else
13320 do_vfp_nsyn_opcode ("fdivd");
13321 }
13322
13323 static void
13324 do_vfp_nsyn_nmul (void)
13325 {
13326 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13327 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13328 N_F32 | N_F64 | N_KEY | N_VFP);
13329
13330 if (rs == NS_FFF)
13331 {
13332 NEON_ENCODE (SINGLE, inst);
13333 do_vfp_sp_dyadic ();
13334 }
13335 else
13336 {
13337 NEON_ENCODE (DOUBLE, inst);
13338 do_vfp_dp_rd_rn_rm ();
13339 }
13340 do_vfp_cond_or_thumb ();
13341 }
13342
13343 static void
13344 do_vfp_nsyn_cmp (void)
13345 {
13346 if (inst.operands[1].isreg)
13347 {
13348 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13349 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13350
13351 if (rs == NS_FF)
13352 {
13353 NEON_ENCODE (SINGLE, inst);
13354 do_vfp_sp_monadic ();
13355 }
13356 else
13357 {
13358 NEON_ENCODE (DOUBLE, inst);
13359 do_vfp_dp_rd_rm ();
13360 }
13361 }
13362 else
13363 {
13364 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13365 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13366
13367 switch (inst.instruction & 0x0fffffff)
13368 {
13369 case N_MNEM_vcmp:
13370 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13371 break;
13372 case N_MNEM_vcmpe:
13373 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13374 break;
13375 default:
13376 abort ();
13377 }
13378
13379 if (rs == NS_FI)
13380 {
13381 NEON_ENCODE (SINGLE, inst);
13382 do_vfp_sp_compare_z ();
13383 }
13384 else
13385 {
13386 NEON_ENCODE (DOUBLE, inst);
13387 do_vfp_dp_rd ();
13388 }
13389 }
13390 do_vfp_cond_or_thumb ();
13391 }
13392
13393 static void
13394 nsyn_insert_sp (void)
13395 {
13396 inst.operands[1] = inst.operands[0];
13397 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
13398 inst.operands[0].reg = REG_SP;
13399 inst.operands[0].isreg = 1;
13400 inst.operands[0].writeback = 1;
13401 inst.operands[0].present = 1;
13402 }
13403
13404 static void
13405 do_vfp_nsyn_push (void)
13406 {
13407 nsyn_insert_sp ();
13408 if (inst.operands[1].issingle)
13409 do_vfp_nsyn_opcode ("fstmdbs");
13410 else
13411 do_vfp_nsyn_opcode ("fstmdbd");
13412 }
13413
13414 static void
13415 do_vfp_nsyn_pop (void)
13416 {
13417 nsyn_insert_sp ();
13418 if (inst.operands[1].issingle)
13419 do_vfp_nsyn_opcode ("fldmias");
13420 else
13421 do_vfp_nsyn_opcode ("fldmiad");
13422 }
13423
13424 /* Fix up Neon data-processing instructions, ORing in the correct bits for
13425 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13426
13427 static void
13428 neon_dp_fixup (struct arm_it* insn)
13429 {
13430 unsigned int i = insn->instruction;
13431 insn->is_neon = 1;
13432
13433 if (thumb_mode)
13434 {
13435 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13436 if (i & (1 << 24))
13437 i |= 1 << 28;
13438
13439 i &= ~(1 << 24);
13440
13441 i |= 0xef000000;
13442 }
13443 else
13444 i |= 0xf2000000;
13445
13446 insn->instruction = i;
13447 }
13448
13449 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13450 (0, 1, 2, 3). */
13451
13452 static unsigned
13453 neon_logbits (unsigned x)
13454 {
13455 return ffs (x) - 4;
13456 }
13457
13458 #define LOW4(R) ((R) & 0xf)
13459 #define HI1(R) (((R) >> 4) & 1)
13460
13461 /* Encode insns with bit pattern:
13462
13463 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13464 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
13465
13466 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13467 different meaning for some instruction. */
13468
13469 static void
13470 neon_three_same (int isquad, int ubit, int size)
13471 {
13472 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13473 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13474 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13475 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13476 inst.instruction |= LOW4 (inst.operands[2].reg);
13477 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13478 inst.instruction |= (isquad != 0) << 6;
13479 inst.instruction |= (ubit != 0) << 24;
13480 if (size != -1)
13481 inst.instruction |= neon_logbits (size) << 20;
13482
13483 neon_dp_fixup (&inst);
13484 }
13485
13486 /* Encode instructions of the form:
13487
13488 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13489 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
13490
13491 Don't write size if SIZE == -1. */
13492
13493 static void
13494 neon_two_same (int qbit, int ubit, int size)
13495 {
13496 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13497 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13498 inst.instruction |= LOW4 (inst.operands[1].reg);
13499 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13500 inst.instruction |= (qbit != 0) << 6;
13501 inst.instruction |= (ubit != 0) << 24;
13502
13503 if (size != -1)
13504 inst.instruction |= neon_logbits (size) << 18;
13505
13506 neon_dp_fixup (&inst);
13507 }
13508
13509 /* Neon instruction encoders, in approximate order of appearance. */
13510
13511 static void
13512 do_neon_dyadic_i_su (void)
13513 {
13514 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13515 struct neon_type_el et = neon_check_type (3, rs,
13516 N_EQK, N_EQK, N_SU_32 | N_KEY);
13517 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13518 }
13519
13520 static void
13521 do_neon_dyadic_i64_su (void)
13522 {
13523 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13524 struct neon_type_el et = neon_check_type (3, rs,
13525 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13526 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13527 }
13528
13529 static void
13530 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13531 unsigned immbits)
13532 {
13533 unsigned size = et.size >> 3;
13534 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13535 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13536 inst.instruction |= LOW4 (inst.operands[1].reg);
13537 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13538 inst.instruction |= (isquad != 0) << 6;
13539 inst.instruction |= immbits << 16;
13540 inst.instruction |= (size >> 3) << 7;
13541 inst.instruction |= (size & 0x7) << 19;
13542 if (write_ubit)
13543 inst.instruction |= (uval != 0) << 24;
13544
13545 neon_dp_fixup (&inst);
13546 }
13547
13548 static void
13549 do_neon_shl_imm (void)
13550 {
13551 if (!inst.operands[2].isreg)
13552 {
13553 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13554 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
13555 NEON_ENCODE (IMMED, inst);
13556 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
13557 }
13558 else
13559 {
13560 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13561 struct neon_type_el et = neon_check_type (3, rs,
13562 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13563 unsigned int tmp;
13564
13565 /* VSHL/VQSHL 3-register variants have syntax such as:
13566 vshl.xx Dd, Dm, Dn
13567 whereas other 3-register operations encoded by neon_three_same have
13568 syntax like:
13569 vadd.xx Dd, Dn, Dm
13570 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13571 here. */
13572 tmp = inst.operands[2].reg;
13573 inst.operands[2].reg = inst.operands[1].reg;
13574 inst.operands[1].reg = tmp;
13575 NEON_ENCODE (INTEGER, inst);
13576 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13577 }
13578 }
13579
13580 static void
13581 do_neon_qshl_imm (void)
13582 {
13583 if (!inst.operands[2].isreg)
13584 {
13585 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13586 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13587
13588 NEON_ENCODE (IMMED, inst);
13589 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13590 inst.operands[2].imm);
13591 }
13592 else
13593 {
13594 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13595 struct neon_type_el et = neon_check_type (3, rs,
13596 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13597 unsigned int tmp;
13598
13599 /* See note in do_neon_shl_imm. */
13600 tmp = inst.operands[2].reg;
13601 inst.operands[2].reg = inst.operands[1].reg;
13602 inst.operands[1].reg = tmp;
13603 NEON_ENCODE (INTEGER, inst);
13604 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13605 }
13606 }
13607
13608 static void
13609 do_neon_rshl (void)
13610 {
13611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13612 struct neon_type_el et = neon_check_type (3, rs,
13613 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13614 unsigned int tmp;
13615
13616 tmp = inst.operands[2].reg;
13617 inst.operands[2].reg = inst.operands[1].reg;
13618 inst.operands[1].reg = tmp;
13619 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13620 }
13621
13622 static int
13623 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13624 {
13625 /* Handle .I8 pseudo-instructions. */
13626 if (size == 8)
13627 {
13628 /* Unfortunately, this will make everything apart from zero out-of-range.
13629 FIXME is this the intended semantics? There doesn't seem much point in
13630 accepting .I8 if so. */
13631 immediate |= immediate << 8;
13632 size = 16;
13633 }
13634
13635 if (size >= 32)
13636 {
13637 if (immediate == (immediate & 0x000000ff))
13638 {
13639 *immbits = immediate;
13640 return 0x1;
13641 }
13642 else if (immediate == (immediate & 0x0000ff00))
13643 {
13644 *immbits = immediate >> 8;
13645 return 0x3;
13646 }
13647 else if (immediate == (immediate & 0x00ff0000))
13648 {
13649 *immbits = immediate >> 16;
13650 return 0x5;
13651 }
13652 else if (immediate == (immediate & 0xff000000))
13653 {
13654 *immbits = immediate >> 24;
13655 return 0x7;
13656 }
13657 if ((immediate & 0xffff) != (immediate >> 16))
13658 goto bad_immediate;
13659 immediate &= 0xffff;
13660 }
13661
13662 if (immediate == (immediate & 0x000000ff))
13663 {
13664 *immbits = immediate;
13665 return 0x9;
13666 }
13667 else if (immediate == (immediate & 0x0000ff00))
13668 {
13669 *immbits = immediate >> 8;
13670 return 0xb;
13671 }
13672
13673 bad_immediate:
13674 first_error (_("immediate value out of range"));
13675 return FAIL;
13676 }
13677
13678 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13679 A, B, C, D. */
13680
13681 static int
13682 neon_bits_same_in_bytes (unsigned imm)
13683 {
13684 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13685 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13686 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13687 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13688 }
13689
13690 /* For immediate of above form, return 0bABCD. */
13691
13692 static unsigned
13693 neon_squash_bits (unsigned imm)
13694 {
13695 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13696 | ((imm & 0x01000000) >> 21);
13697 }
13698
13699 /* Compress quarter-float representation to 0b...000 abcdefgh. */
13700
13701 static unsigned
13702 neon_qfloat_bits (unsigned imm)
13703 {
13704 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
13705 }
13706
13707 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13708 the instruction. *OP is passed as the initial value of the op field, and
13709 may be set to a different value depending on the constant (i.e.
13710 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
13711 MVN). If the immediate looks like a repeated pattern then also
13712 try smaller element sizes. */
13713
13714 static int
13715 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13716 unsigned *immbits, int *op, int size,
13717 enum neon_el_type type)
13718 {
13719 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13720 float. */
13721 if (type == NT_float && !float_p)
13722 return FAIL;
13723
13724 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13725 {
13726 if (size != 32 || *op == 1)
13727 return FAIL;
13728 *immbits = neon_qfloat_bits (immlo);
13729 return 0xf;
13730 }
13731
13732 if (size == 64)
13733 {
13734 if (neon_bits_same_in_bytes (immhi)
13735 && neon_bits_same_in_bytes (immlo))
13736 {
13737 if (*op == 1)
13738 return FAIL;
13739 *immbits = (neon_squash_bits (immhi) << 4)
13740 | neon_squash_bits (immlo);
13741 *op = 1;
13742 return 0xe;
13743 }
13744
13745 if (immhi != immlo)
13746 return FAIL;
13747 }
13748
13749 if (size >= 32)
13750 {
13751 if (immlo == (immlo & 0x000000ff))
13752 {
13753 *immbits = immlo;
13754 return 0x0;
13755 }
13756 else if (immlo == (immlo & 0x0000ff00))
13757 {
13758 *immbits = immlo >> 8;
13759 return 0x2;
13760 }
13761 else if (immlo == (immlo & 0x00ff0000))
13762 {
13763 *immbits = immlo >> 16;
13764 return 0x4;
13765 }
13766 else if (immlo == (immlo & 0xff000000))
13767 {
13768 *immbits = immlo >> 24;
13769 return 0x6;
13770 }
13771 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13772 {
13773 *immbits = (immlo >> 8) & 0xff;
13774 return 0xc;
13775 }
13776 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13777 {
13778 *immbits = (immlo >> 16) & 0xff;
13779 return 0xd;
13780 }
13781
13782 if ((immlo & 0xffff) != (immlo >> 16))
13783 return FAIL;
13784 immlo &= 0xffff;
13785 }
13786
13787 if (size >= 16)
13788 {
13789 if (immlo == (immlo & 0x000000ff))
13790 {
13791 *immbits = immlo;
13792 return 0x8;
13793 }
13794 else if (immlo == (immlo & 0x0000ff00))
13795 {
13796 *immbits = immlo >> 8;
13797 return 0xa;
13798 }
13799
13800 if ((immlo & 0xff) != (immlo >> 8))
13801 return FAIL;
13802 immlo &= 0xff;
13803 }
13804
13805 if (immlo == (immlo & 0x000000ff))
13806 {
13807 /* Don't allow MVN with 8-bit immediate. */
13808 if (*op == 1)
13809 return FAIL;
13810 *immbits = immlo;
13811 return 0xe;
13812 }
13813
13814 return FAIL;
13815 }
13816
13817 /* Write immediate bits [7:0] to the following locations:
13818
13819 |28/24|23 19|18 16|15 4|3 0|
13820 | 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|
13821
13822 This function is used by VMOV/VMVN/VORR/VBIC. */
13823
13824 static void
13825 neon_write_immbits (unsigned immbits)
13826 {
13827 inst.instruction |= immbits & 0xf;
13828 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13829 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13830 }
13831
13832 /* Invert low-order SIZE bits of XHI:XLO. */
13833
13834 static void
13835 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13836 {
13837 unsigned immlo = xlo ? *xlo : 0;
13838 unsigned immhi = xhi ? *xhi : 0;
13839
13840 switch (size)
13841 {
13842 case 8:
13843 immlo = (~immlo) & 0xff;
13844 break;
13845
13846 case 16:
13847 immlo = (~immlo) & 0xffff;
13848 break;
13849
13850 case 64:
13851 immhi = (~immhi) & 0xffffffff;
13852 /* fall through. */
13853
13854 case 32:
13855 immlo = (~immlo) & 0xffffffff;
13856 break;
13857
13858 default:
13859 abort ();
13860 }
13861
13862 if (xlo)
13863 *xlo = immlo;
13864
13865 if (xhi)
13866 *xhi = immhi;
13867 }
13868
13869 static void
13870 do_neon_logic (void)
13871 {
13872 if (inst.operands[2].present && inst.operands[2].isreg)
13873 {
13874 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13875 neon_check_type (3, rs, N_IGNORE_TYPE);
13876 /* U bit and size field were set as part of the bitmask. */
13877 NEON_ENCODE (INTEGER, inst);
13878 neon_three_same (neon_quad (rs), 0, -1);
13879 }
13880 else
13881 {
13882 const int three_ops_form = (inst.operands[2].present
13883 && !inst.operands[2].isreg);
13884 const int immoperand = (three_ops_form ? 2 : 1);
13885 enum neon_shape rs = (three_ops_form
13886 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13887 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13888 struct neon_type_el et = neon_check_type (2, rs,
13889 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13890 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13891 unsigned immbits;
13892 int cmode;
13893
13894 if (et.type == NT_invtype)
13895 return;
13896
13897 if (three_ops_form)
13898 constraint (inst.operands[0].reg != inst.operands[1].reg,
13899 _("first and second operands shall be the same register"));
13900
13901 NEON_ENCODE (IMMED, inst);
13902
13903 immbits = inst.operands[immoperand].imm;
13904 if (et.size == 64)
13905 {
13906 /* .i64 is a pseudo-op, so the immediate must be a repeating
13907 pattern. */
13908 if (immbits != (inst.operands[immoperand].regisimm ?
13909 inst.operands[immoperand].reg : 0))
13910 {
13911 /* Set immbits to an invalid constant. */
13912 immbits = 0xdeadbeef;
13913 }
13914 }
13915
13916 switch (opcode)
13917 {
13918 case N_MNEM_vbic:
13919 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13920 break;
13921
13922 case N_MNEM_vorr:
13923 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13924 break;
13925
13926 case N_MNEM_vand:
13927 /* Pseudo-instruction for VBIC. */
13928 neon_invert_size (&immbits, 0, et.size);
13929 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13930 break;
13931
13932 case N_MNEM_vorn:
13933 /* Pseudo-instruction for VORR. */
13934 neon_invert_size (&immbits, 0, et.size);
13935 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13936 break;
13937
13938 default:
13939 abort ();
13940 }
13941
13942 if (cmode == FAIL)
13943 return;
13944
13945 inst.instruction |= neon_quad (rs) << 6;
13946 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13947 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13948 inst.instruction |= cmode << 8;
13949 neon_write_immbits (immbits);
13950
13951 neon_dp_fixup (&inst);
13952 }
13953 }
13954
13955 static void
13956 do_neon_bitfield (void)
13957 {
13958 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13959 neon_check_type (3, rs, N_IGNORE_TYPE);
13960 neon_three_same (neon_quad (rs), 0, -1);
13961 }
13962
13963 static void
13964 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13965 unsigned destbits)
13966 {
13967 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13968 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13969 types | N_KEY);
13970 if (et.type == NT_float)
13971 {
13972 NEON_ENCODE (FLOAT, inst);
13973 neon_three_same (neon_quad (rs), 0, -1);
13974 }
13975 else
13976 {
13977 NEON_ENCODE (INTEGER, inst);
13978 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13979 }
13980 }
13981
13982 static void
13983 do_neon_dyadic_if_su (void)
13984 {
13985 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13986 }
13987
13988 static void
13989 do_neon_dyadic_if_su_d (void)
13990 {
13991 /* This version only allow D registers, but that constraint is enforced during
13992 operand parsing so we don't need to do anything extra here. */
13993 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13994 }
13995
13996 static void
13997 do_neon_dyadic_if_i_d (void)
13998 {
13999 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14000 affected if we specify unsigned args. */
14001 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14002 }
14003
14004 enum vfp_or_neon_is_neon_bits
14005 {
14006 NEON_CHECK_CC = 1,
14007 NEON_CHECK_ARCH = 2,
14008 NEON_CHECK_ARCH8 = 4
14009 };
14010
14011 /* Call this function if an instruction which may have belonged to the VFP or
14012 Neon instruction sets, but turned out to be a Neon instruction (due to the
14013 operand types involved, etc.). We have to check and/or fix-up a couple of
14014 things:
14015
14016 - Make sure the user hasn't attempted to make a Neon instruction
14017 conditional.
14018 - Alter the value in the condition code field if necessary.
14019 - Make sure that the arch supports Neon instructions.
14020
14021 Which of these operations take place depends on bits from enum
14022 vfp_or_neon_is_neon_bits.
14023
14024 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14025 current instruction's condition is COND_ALWAYS, the condition field is
14026 changed to inst.uncond_value. This is necessary because instructions shared
14027 between VFP and Neon may be conditional for the VFP variants only, and the
14028 unconditional Neon version must have, e.g., 0xF in the condition field. */
14029
14030 static int
14031 vfp_or_neon_is_neon (unsigned check)
14032 {
14033 /* Conditions are always legal in Thumb mode (IT blocks). */
14034 if (!thumb_mode && (check & NEON_CHECK_CC))
14035 {
14036 if (inst.cond != COND_ALWAYS)
14037 {
14038 first_error (_(BAD_COND));
14039 return FAIL;
14040 }
14041 if (inst.uncond_value != -1)
14042 inst.instruction |= inst.uncond_value << 28;
14043 }
14044
14045 if ((check & NEON_CHECK_ARCH)
14046 && !mark_feature_used (&fpu_neon_ext_v1))
14047 {
14048 first_error (_(BAD_FPU));
14049 return FAIL;
14050 }
14051
14052 if ((check & NEON_CHECK_ARCH8)
14053 && !mark_feature_used (&fpu_neon_ext_armv8))
14054 {
14055 first_error (_(BAD_FPU));
14056 return FAIL;
14057 }
14058
14059 return SUCCESS;
14060 }
14061
14062 static void
14063 do_neon_addsub_if_i (void)
14064 {
14065 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14066 return;
14067
14068 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14069 return;
14070
14071 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14072 affected if we specify unsigned args. */
14073 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
14074 }
14075
14076 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14077 result to be:
14078 V<op> A,B (A is operand 0, B is operand 2)
14079 to mean:
14080 V<op> A,B,A
14081 not:
14082 V<op> A,B,B
14083 so handle that case specially. */
14084
14085 static void
14086 neon_exchange_operands (void)
14087 {
14088 void *scratch = alloca (sizeof (inst.operands[0]));
14089 if (inst.operands[1].present)
14090 {
14091 /* Swap operands[1] and operands[2]. */
14092 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14093 inst.operands[1] = inst.operands[2];
14094 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14095 }
14096 else
14097 {
14098 inst.operands[1] = inst.operands[2];
14099 inst.operands[2] = inst.operands[0];
14100 }
14101 }
14102
14103 static void
14104 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14105 {
14106 if (inst.operands[2].isreg)
14107 {
14108 if (invert)
14109 neon_exchange_operands ();
14110 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
14111 }
14112 else
14113 {
14114 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14115 struct neon_type_el et = neon_check_type (2, rs,
14116 N_EQK | N_SIZ, immtypes | N_KEY);
14117
14118 NEON_ENCODE (IMMED, inst);
14119 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14120 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14121 inst.instruction |= LOW4 (inst.operands[1].reg);
14122 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14123 inst.instruction |= neon_quad (rs) << 6;
14124 inst.instruction |= (et.type == NT_float) << 10;
14125 inst.instruction |= neon_logbits (et.size) << 18;
14126
14127 neon_dp_fixup (&inst);
14128 }
14129 }
14130
14131 static void
14132 do_neon_cmp (void)
14133 {
14134 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14135 }
14136
14137 static void
14138 do_neon_cmp_inv (void)
14139 {
14140 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14141 }
14142
14143 static void
14144 do_neon_ceq (void)
14145 {
14146 neon_compare (N_IF_32, N_IF_32, FALSE);
14147 }
14148
14149 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
14150 scalars, which are encoded in 5 bits, M : Rm.
14151 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14152 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14153 index in M. */
14154
14155 static unsigned
14156 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14157 {
14158 unsigned regno = NEON_SCALAR_REG (scalar);
14159 unsigned elno = NEON_SCALAR_INDEX (scalar);
14160
14161 switch (elsize)
14162 {
14163 case 16:
14164 if (regno > 7 || elno > 3)
14165 goto bad_scalar;
14166 return regno | (elno << 3);
14167
14168 case 32:
14169 if (regno > 15 || elno > 1)
14170 goto bad_scalar;
14171 return regno | (elno << 4);
14172
14173 default:
14174 bad_scalar:
14175 first_error (_("scalar out of range for multiply instruction"));
14176 }
14177
14178 return 0;
14179 }
14180
14181 /* Encode multiply / multiply-accumulate scalar instructions. */
14182
14183 static void
14184 neon_mul_mac (struct neon_type_el et, int ubit)
14185 {
14186 unsigned scalar;
14187
14188 /* Give a more helpful error message if we have an invalid type. */
14189 if (et.type == NT_invtype)
14190 return;
14191
14192 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
14193 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14194 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14195 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14196 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14197 inst.instruction |= LOW4 (scalar);
14198 inst.instruction |= HI1 (scalar) << 5;
14199 inst.instruction |= (et.type == NT_float) << 8;
14200 inst.instruction |= neon_logbits (et.size) << 20;
14201 inst.instruction |= (ubit != 0) << 24;
14202
14203 neon_dp_fixup (&inst);
14204 }
14205
14206 static void
14207 do_neon_mac_maybe_scalar (void)
14208 {
14209 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14210 return;
14211
14212 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14213 return;
14214
14215 if (inst.operands[2].isscalar)
14216 {
14217 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14218 struct neon_type_el et = neon_check_type (3, rs,
14219 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
14220 NEON_ENCODE (SCALAR, inst);
14221 neon_mul_mac (et, neon_quad (rs));
14222 }
14223 else
14224 {
14225 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14226 affected if we specify unsigned args. */
14227 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14228 }
14229 }
14230
14231 static void
14232 do_neon_fmac (void)
14233 {
14234 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14235 return;
14236
14237 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14238 return;
14239
14240 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14241 }
14242
14243 static void
14244 do_neon_tst (void)
14245 {
14246 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14247 struct neon_type_el et = neon_check_type (3, rs,
14248 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
14249 neon_three_same (neon_quad (rs), 0, et.size);
14250 }
14251
14252 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
14253 same types as the MAC equivalents. The polynomial type for this instruction
14254 is encoded the same as the integer type. */
14255
14256 static void
14257 do_neon_mul (void)
14258 {
14259 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14260 return;
14261
14262 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14263 return;
14264
14265 if (inst.operands[2].isscalar)
14266 do_neon_mac_maybe_scalar ();
14267 else
14268 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
14269 }
14270
14271 static void
14272 do_neon_qdmulh (void)
14273 {
14274 if (inst.operands[2].isscalar)
14275 {
14276 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14277 struct neon_type_el et = neon_check_type (3, rs,
14278 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14279 NEON_ENCODE (SCALAR, inst);
14280 neon_mul_mac (et, neon_quad (rs));
14281 }
14282 else
14283 {
14284 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14285 struct neon_type_el et = neon_check_type (3, rs,
14286 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14287 NEON_ENCODE (INTEGER, inst);
14288 /* The U bit (rounding) comes from bit mask. */
14289 neon_three_same (neon_quad (rs), 0, et.size);
14290 }
14291 }
14292
14293 static void
14294 do_neon_fcmp_absolute (void)
14295 {
14296 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14297 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14298 /* Size field comes from bit mask. */
14299 neon_three_same (neon_quad (rs), 1, -1);
14300 }
14301
14302 static void
14303 do_neon_fcmp_absolute_inv (void)
14304 {
14305 neon_exchange_operands ();
14306 do_neon_fcmp_absolute ();
14307 }
14308
14309 static void
14310 do_neon_step (void)
14311 {
14312 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14313 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14314 neon_three_same (neon_quad (rs), 0, -1);
14315 }
14316
14317 static void
14318 do_neon_abs_neg (void)
14319 {
14320 enum neon_shape rs;
14321 struct neon_type_el et;
14322
14323 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14324 return;
14325
14326 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14327 return;
14328
14329 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14330 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
14331
14332 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14333 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14334 inst.instruction |= LOW4 (inst.operands[1].reg);
14335 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14336 inst.instruction |= neon_quad (rs) << 6;
14337 inst.instruction |= (et.type == NT_float) << 10;
14338 inst.instruction |= neon_logbits (et.size) << 18;
14339
14340 neon_dp_fixup (&inst);
14341 }
14342
14343 static void
14344 do_neon_sli (void)
14345 {
14346 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14347 struct neon_type_el et = neon_check_type (2, rs,
14348 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14349 int imm = inst.operands[2].imm;
14350 constraint (imm < 0 || (unsigned)imm >= et.size,
14351 _("immediate out of range for insert"));
14352 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14353 }
14354
14355 static void
14356 do_neon_sri (void)
14357 {
14358 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14359 struct neon_type_el et = neon_check_type (2, rs,
14360 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14361 int imm = inst.operands[2].imm;
14362 constraint (imm < 1 || (unsigned)imm > et.size,
14363 _("immediate out of range for insert"));
14364 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
14365 }
14366
14367 static void
14368 do_neon_qshlu_imm (void)
14369 {
14370 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14371 struct neon_type_el et = neon_check_type (2, rs,
14372 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14373 int imm = inst.operands[2].imm;
14374 constraint (imm < 0 || (unsigned)imm >= et.size,
14375 _("immediate out of range for shift"));
14376 /* Only encodes the 'U present' variant of the instruction.
14377 In this case, signed types have OP (bit 8) set to 0.
14378 Unsigned types have OP set to 1. */
14379 inst.instruction |= (et.type == NT_unsigned) << 8;
14380 /* The rest of the bits are the same as other immediate shifts. */
14381 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14382 }
14383
14384 static void
14385 do_neon_qmovn (void)
14386 {
14387 struct neon_type_el et = neon_check_type (2, NS_DQ,
14388 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14389 /* Saturating move where operands can be signed or unsigned, and the
14390 destination has the same signedness. */
14391 NEON_ENCODE (INTEGER, inst);
14392 if (et.type == NT_unsigned)
14393 inst.instruction |= 0xc0;
14394 else
14395 inst.instruction |= 0x80;
14396 neon_two_same (0, 1, et.size / 2);
14397 }
14398
14399 static void
14400 do_neon_qmovun (void)
14401 {
14402 struct neon_type_el et = neon_check_type (2, NS_DQ,
14403 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14404 /* Saturating move with unsigned results. Operands must be signed. */
14405 NEON_ENCODE (INTEGER, inst);
14406 neon_two_same (0, 1, et.size / 2);
14407 }
14408
14409 static void
14410 do_neon_rshift_sat_narrow (void)
14411 {
14412 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14413 or unsigned. If operands are unsigned, results must also be unsigned. */
14414 struct neon_type_el et = neon_check_type (2, NS_DQI,
14415 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14416 int imm = inst.operands[2].imm;
14417 /* This gets the bounds check, size encoding and immediate bits calculation
14418 right. */
14419 et.size /= 2;
14420
14421 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14422 VQMOVN.I<size> <Dd>, <Qm>. */
14423 if (imm == 0)
14424 {
14425 inst.operands[2].present = 0;
14426 inst.instruction = N_MNEM_vqmovn;
14427 do_neon_qmovn ();
14428 return;
14429 }
14430
14431 constraint (imm < 1 || (unsigned)imm > et.size,
14432 _("immediate out of range"));
14433 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14434 }
14435
14436 static void
14437 do_neon_rshift_sat_narrow_u (void)
14438 {
14439 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14440 or unsigned. If operands are unsigned, results must also be unsigned. */
14441 struct neon_type_el et = neon_check_type (2, NS_DQI,
14442 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14443 int imm = inst.operands[2].imm;
14444 /* This gets the bounds check, size encoding and immediate bits calculation
14445 right. */
14446 et.size /= 2;
14447
14448 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14449 VQMOVUN.I<size> <Dd>, <Qm>. */
14450 if (imm == 0)
14451 {
14452 inst.operands[2].present = 0;
14453 inst.instruction = N_MNEM_vqmovun;
14454 do_neon_qmovun ();
14455 return;
14456 }
14457
14458 constraint (imm < 1 || (unsigned)imm > et.size,
14459 _("immediate out of range"));
14460 /* FIXME: The manual is kind of unclear about what value U should have in
14461 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14462 must be 1. */
14463 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14464 }
14465
14466 static void
14467 do_neon_movn (void)
14468 {
14469 struct neon_type_el et = neon_check_type (2, NS_DQ,
14470 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14471 NEON_ENCODE (INTEGER, inst);
14472 neon_two_same (0, 1, et.size / 2);
14473 }
14474
14475 static void
14476 do_neon_rshift_narrow (void)
14477 {
14478 struct neon_type_el et = neon_check_type (2, NS_DQI,
14479 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14480 int imm = inst.operands[2].imm;
14481 /* This gets the bounds check, size encoding and immediate bits calculation
14482 right. */
14483 et.size /= 2;
14484
14485 /* If immediate is zero then we are a pseudo-instruction for
14486 VMOVN.I<size> <Dd>, <Qm> */
14487 if (imm == 0)
14488 {
14489 inst.operands[2].present = 0;
14490 inst.instruction = N_MNEM_vmovn;
14491 do_neon_movn ();
14492 return;
14493 }
14494
14495 constraint (imm < 1 || (unsigned)imm > et.size,
14496 _("immediate out of range for narrowing operation"));
14497 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14498 }
14499
14500 static void
14501 do_neon_shll (void)
14502 {
14503 /* FIXME: Type checking when lengthening. */
14504 struct neon_type_el et = neon_check_type (2, NS_QDI,
14505 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14506 unsigned imm = inst.operands[2].imm;
14507
14508 if (imm == et.size)
14509 {
14510 /* Maximum shift variant. */
14511 NEON_ENCODE (INTEGER, inst);
14512 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14513 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14514 inst.instruction |= LOW4 (inst.operands[1].reg);
14515 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14516 inst.instruction |= neon_logbits (et.size) << 18;
14517
14518 neon_dp_fixup (&inst);
14519 }
14520 else
14521 {
14522 /* A more-specific type check for non-max versions. */
14523 et = neon_check_type (2, NS_QDI,
14524 N_EQK | N_DBL, N_SU_32 | N_KEY);
14525 NEON_ENCODE (IMMED, inst);
14526 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14527 }
14528 }
14529
14530 /* Check the various types for the VCVT instruction, and return which version
14531 the current instruction is. */
14532
14533 #define CVT_FLAVOUR_VAR \
14534 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
14535 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
14536 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
14537 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
14538 /* Half-precision conversions. */ \
14539 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
14540 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
14541 /* VFP instructions. */ \
14542 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
14543 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
14544 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
14545 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
14546 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
14547 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
14548 /* VFP instructions with bitshift. */ \
14549 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
14550 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
14551 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
14552 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
14553 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
14554 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
14555 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
14556 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
14557
14558 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
14559 neon_cvt_flavour_##C,
14560
14561 /* The different types of conversions we can do. */
14562 enum neon_cvt_flavour
14563 {
14564 CVT_FLAVOUR_VAR
14565 neon_cvt_flavour_invalid,
14566 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
14567 };
14568
14569 #undef CVT_VAR
14570
14571 static enum neon_cvt_flavour
14572 get_neon_cvt_flavour (enum neon_shape rs)
14573 {
14574 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
14575 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
14576 if (et.type != NT_invtype) \
14577 { \
14578 inst.error = NULL; \
14579 return (neon_cvt_flavour_##C); \
14580 }
14581
14582 struct neon_type_el et;
14583 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14584 || rs == NS_FF) ? N_VFP : 0;
14585 /* The instruction versions which take an immediate take one register
14586 argument, which is extended to the width of the full register. Thus the
14587 "source" and "destination" registers must have the same width. Hack that
14588 here by making the size equal to the key (wider, in this case) operand. */
14589 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
14590
14591 CVT_FLAVOUR_VAR;
14592
14593 return neon_cvt_flavour_invalid;
14594 #undef CVT_VAR
14595 }
14596
14597 enum neon_cvt_mode
14598 {
14599 neon_cvt_mode_a,
14600 neon_cvt_mode_n,
14601 neon_cvt_mode_p,
14602 neon_cvt_mode_m,
14603 neon_cvt_mode_z,
14604 neon_cvt_mode_x,
14605 neon_cvt_mode_r
14606 };
14607
14608 /* Neon-syntax VFP conversions. */
14609
14610 static void
14611 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
14612 {
14613 const char *opname = 0;
14614
14615 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
14616 {
14617 /* Conversions with immediate bitshift. */
14618 const char *enc[] =
14619 {
14620 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
14621 CVT_FLAVOUR_VAR
14622 NULL
14623 #undef CVT_VAR
14624 };
14625
14626 if (flavour < (int) ARRAY_SIZE (enc))
14627 {
14628 opname = enc[flavour];
14629 constraint (inst.operands[0].reg != inst.operands[1].reg,
14630 _("operands 0 and 1 must be the same register"));
14631 inst.operands[1] = inst.operands[2];
14632 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14633 }
14634 }
14635 else
14636 {
14637 /* Conversions without bitshift. */
14638 const char *enc[] =
14639 {
14640 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
14641 CVT_FLAVOUR_VAR
14642 NULL
14643 #undef CVT_VAR
14644 };
14645
14646 if (flavour < (int) ARRAY_SIZE (enc))
14647 opname = enc[flavour];
14648 }
14649
14650 if (opname)
14651 do_vfp_nsyn_opcode (opname);
14652 }
14653
14654 static void
14655 do_vfp_nsyn_cvtz (void)
14656 {
14657 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14658 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
14659 const char *enc[] =
14660 {
14661 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
14662 CVT_FLAVOUR_VAR
14663 NULL
14664 #undef CVT_VAR
14665 };
14666
14667 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14668 do_vfp_nsyn_opcode (enc[flavour]);
14669 }
14670
14671 static void
14672 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
14673 enum neon_cvt_mode mode)
14674 {
14675 int sz, op;
14676 int rm;
14677
14678 set_it_insn_type (OUTSIDE_IT_INSN);
14679
14680 switch (flavour)
14681 {
14682 case neon_cvt_flavour_s32_f64:
14683 sz = 1;
14684 op = 0;
14685 break;
14686 case neon_cvt_flavour_s32_f32:
14687 sz = 0;
14688 op = 1;
14689 break;
14690 case neon_cvt_flavour_u32_f64:
14691 sz = 1;
14692 op = 0;
14693 break;
14694 case neon_cvt_flavour_u32_f32:
14695 sz = 0;
14696 op = 0;
14697 break;
14698 default:
14699 first_error (_("invalid instruction shape"));
14700 return;
14701 }
14702
14703 switch (mode)
14704 {
14705 case neon_cvt_mode_a: rm = 0; break;
14706 case neon_cvt_mode_n: rm = 1; break;
14707 case neon_cvt_mode_p: rm = 2; break;
14708 case neon_cvt_mode_m: rm = 3; break;
14709 default: first_error (_("invalid rounding mode")); return;
14710 }
14711
14712 NEON_ENCODE (FPV8, inst);
14713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14714 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
14715 inst.instruction |= sz << 8;
14716 inst.instruction |= op << 7;
14717 inst.instruction |= rm << 16;
14718 inst.instruction |= 0xf0000000;
14719 inst.is_neon = TRUE;
14720 }
14721
14722 static void
14723 do_neon_cvt_1 (enum neon_cvt_mode mode)
14724 {
14725 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
14726 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
14727 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
14728
14729 /* PR11109: Handle round-to-zero for VCVT conversions. */
14730 if (mode == neon_cvt_mode_z
14731 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14732 && (flavour == neon_cvt_flavour_s32_f32
14733 || flavour == neon_cvt_flavour_u32_f32
14734 || flavour == neon_cvt_flavour_s32_f64
14735 || flavour == neon_cvt_flavour_u32_f64)
14736 && (rs == NS_FD || rs == NS_FF))
14737 {
14738 do_vfp_nsyn_cvtz ();
14739 return;
14740 }
14741
14742 /* VFP rather than Neon conversions. */
14743 if (flavour >= neon_cvt_flavour_first_fp)
14744 {
14745 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14746 do_vfp_nsyn_cvt (rs, flavour);
14747 else
14748 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
14749
14750 return;
14751 }
14752
14753 switch (rs)
14754 {
14755 case NS_DDI:
14756 case NS_QQI:
14757 {
14758 unsigned immbits;
14759 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14760
14761 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14762 return;
14763
14764 /* Fixed-point conversion with #0 immediate is encoded as an
14765 integer conversion. */
14766 if (inst.operands[2].present && inst.operands[2].imm == 0)
14767 goto int_encode;
14768 immbits = 32 - inst.operands[2].imm;
14769 NEON_ENCODE (IMMED, inst);
14770 if (flavour != neon_cvt_flavour_invalid)
14771 inst.instruction |= enctab[flavour];
14772 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14773 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14774 inst.instruction |= LOW4 (inst.operands[1].reg);
14775 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14776 inst.instruction |= neon_quad (rs) << 6;
14777 inst.instruction |= 1 << 21;
14778 inst.instruction |= immbits << 16;
14779
14780 neon_dp_fixup (&inst);
14781 }
14782 break;
14783
14784 case NS_DD:
14785 case NS_QQ:
14786 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
14787 {
14788 NEON_ENCODE (FLOAT, inst);
14789 set_it_insn_type (OUTSIDE_IT_INSN);
14790
14791 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
14792 return;
14793
14794 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14795 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14796 inst.instruction |= LOW4 (inst.operands[1].reg);
14797 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14798 inst.instruction |= neon_quad (rs) << 6;
14799 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
14800 inst.instruction |= mode << 8;
14801 if (thumb_mode)
14802 inst.instruction |= 0xfc000000;
14803 else
14804 inst.instruction |= 0xf0000000;
14805 }
14806 else
14807 {
14808 int_encode:
14809 {
14810 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14811
14812 NEON_ENCODE (INTEGER, inst);
14813
14814 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14815 return;
14816
14817 if (flavour != neon_cvt_flavour_invalid)
14818 inst.instruction |= enctab[flavour];
14819
14820 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14821 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14822 inst.instruction |= LOW4 (inst.operands[1].reg);
14823 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14824 inst.instruction |= neon_quad (rs) << 6;
14825 inst.instruction |= 2 << 18;
14826
14827 neon_dp_fixup (&inst);
14828 }
14829 }
14830 break;
14831
14832 /* Half-precision conversions for Advanced SIMD -- neon. */
14833 case NS_QD:
14834 case NS_DQ:
14835
14836 if ((rs == NS_DQ)
14837 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14838 {
14839 as_bad (_("operand size must match register width"));
14840 break;
14841 }
14842
14843 if ((rs == NS_QD)
14844 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14845 {
14846 as_bad (_("operand size must match register width"));
14847 break;
14848 }
14849
14850 if (rs == NS_DQ)
14851 inst.instruction = 0x3b60600;
14852 else
14853 inst.instruction = 0x3b60700;
14854
14855 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14856 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14857 inst.instruction |= LOW4 (inst.operands[1].reg);
14858 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14859 neon_dp_fixup (&inst);
14860 break;
14861
14862 default:
14863 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14864 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
14865 do_vfp_nsyn_cvt (rs, flavour);
14866 else
14867 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
14868 }
14869 }
14870
14871 static void
14872 do_neon_cvtr (void)
14873 {
14874 do_neon_cvt_1 (neon_cvt_mode_x);
14875 }
14876
14877 static void
14878 do_neon_cvt (void)
14879 {
14880 do_neon_cvt_1 (neon_cvt_mode_z);
14881 }
14882
14883 static void
14884 do_neon_cvta (void)
14885 {
14886 do_neon_cvt_1 (neon_cvt_mode_a);
14887 }
14888
14889 static void
14890 do_neon_cvtn (void)
14891 {
14892 do_neon_cvt_1 (neon_cvt_mode_n);
14893 }
14894
14895 static void
14896 do_neon_cvtp (void)
14897 {
14898 do_neon_cvt_1 (neon_cvt_mode_p);
14899 }
14900
14901 static void
14902 do_neon_cvtm (void)
14903 {
14904 do_neon_cvt_1 (neon_cvt_mode_m);
14905 }
14906
14907 static void
14908 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
14909 {
14910 if (is_double)
14911 mark_feature_used (&fpu_vfp_ext_armv8);
14912
14913 encode_arm_vfp_reg (inst.operands[0].reg,
14914 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
14915 encode_arm_vfp_reg (inst.operands[1].reg,
14916 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
14917 inst.instruction |= to ? 0x10000 : 0;
14918 inst.instruction |= t ? 0x80 : 0;
14919 inst.instruction |= is_double ? 0x100 : 0;
14920 do_vfp_cond_or_thumb ();
14921 }
14922
14923 static void
14924 do_neon_cvttb_1 (bfd_boolean t)
14925 {
14926 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
14927
14928 if (rs == NS_NULL)
14929 return;
14930 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
14931 {
14932 inst.error = NULL;
14933 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
14934 }
14935 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
14936 {
14937 inst.error = NULL;
14938 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
14939 }
14940 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
14941 {
14942 inst.error = NULL;
14943 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
14944 }
14945 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
14946 {
14947 inst.error = NULL;
14948 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
14949 }
14950 else
14951 return;
14952 }
14953
14954 static void
14955 do_neon_cvtb (void)
14956 {
14957 do_neon_cvttb_1 (FALSE);
14958 }
14959
14960
14961 static void
14962 do_neon_cvtt (void)
14963 {
14964 do_neon_cvttb_1 (TRUE);
14965 }
14966
14967 static void
14968 neon_move_immediate (void)
14969 {
14970 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14971 struct neon_type_el et = neon_check_type (2, rs,
14972 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14973 unsigned immlo, immhi = 0, immbits;
14974 int op, cmode, float_p;
14975
14976 constraint (et.type == NT_invtype,
14977 _("operand size must be specified for immediate VMOV"));
14978
14979 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14980 op = (inst.instruction & (1 << 5)) != 0;
14981
14982 immlo = inst.operands[1].imm;
14983 if (inst.operands[1].regisimm)
14984 immhi = inst.operands[1].reg;
14985
14986 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14987 _("immediate has bits set outside the operand size"));
14988
14989 float_p = inst.operands[1].immisfloat;
14990
14991 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14992 et.size, et.type)) == FAIL)
14993 {
14994 /* Invert relevant bits only. */
14995 neon_invert_size (&immlo, &immhi, et.size);
14996 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14997 with one or the other; those cases are caught by
14998 neon_cmode_for_move_imm. */
14999 op = !op;
15000 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15001 &op, et.size, et.type)) == FAIL)
15002 {
15003 first_error (_("immediate out of range"));
15004 return;
15005 }
15006 }
15007
15008 inst.instruction &= ~(1 << 5);
15009 inst.instruction |= op << 5;
15010
15011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15013 inst.instruction |= neon_quad (rs) << 6;
15014 inst.instruction |= cmode << 8;
15015
15016 neon_write_immbits (immbits);
15017 }
15018
15019 static void
15020 do_neon_mvn (void)
15021 {
15022 if (inst.operands[1].isreg)
15023 {
15024 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15025
15026 NEON_ENCODE (INTEGER, inst);
15027 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15028 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15029 inst.instruction |= LOW4 (inst.operands[1].reg);
15030 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15031 inst.instruction |= neon_quad (rs) << 6;
15032 }
15033 else
15034 {
15035 NEON_ENCODE (IMMED, inst);
15036 neon_move_immediate ();
15037 }
15038
15039 neon_dp_fixup (&inst);
15040 }
15041
15042 /* Encode instructions of form:
15043
15044 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
15045 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
15046
15047 static void
15048 neon_mixed_length (struct neon_type_el et, unsigned size)
15049 {
15050 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15051 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15052 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15053 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15054 inst.instruction |= LOW4 (inst.operands[2].reg);
15055 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15056 inst.instruction |= (et.type == NT_unsigned) << 24;
15057 inst.instruction |= neon_logbits (size) << 20;
15058
15059 neon_dp_fixup (&inst);
15060 }
15061
15062 static void
15063 do_neon_dyadic_long (void)
15064 {
15065 /* FIXME: Type checking for lengthening op. */
15066 struct neon_type_el et = neon_check_type (3, NS_QDD,
15067 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15068 neon_mixed_length (et, et.size);
15069 }
15070
15071 static void
15072 do_neon_abal (void)
15073 {
15074 struct neon_type_el et = neon_check_type (3, NS_QDD,
15075 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15076 neon_mixed_length (et, et.size);
15077 }
15078
15079 static void
15080 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15081 {
15082 if (inst.operands[2].isscalar)
15083 {
15084 struct neon_type_el et = neon_check_type (3, NS_QDS,
15085 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
15086 NEON_ENCODE (SCALAR, inst);
15087 neon_mul_mac (et, et.type == NT_unsigned);
15088 }
15089 else
15090 {
15091 struct neon_type_el et = neon_check_type (3, NS_QDD,
15092 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
15093 NEON_ENCODE (INTEGER, inst);
15094 neon_mixed_length (et, et.size);
15095 }
15096 }
15097
15098 static void
15099 do_neon_mac_maybe_scalar_long (void)
15100 {
15101 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15102 }
15103
15104 static void
15105 do_neon_dyadic_wide (void)
15106 {
15107 struct neon_type_el et = neon_check_type (3, NS_QQD,
15108 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15109 neon_mixed_length (et, et.size);
15110 }
15111
15112 static void
15113 do_neon_dyadic_narrow (void)
15114 {
15115 struct neon_type_el et = neon_check_type (3, NS_QDD,
15116 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
15117 /* Operand sign is unimportant, and the U bit is part of the opcode,
15118 so force the operand type to integer. */
15119 et.type = NT_integer;
15120 neon_mixed_length (et, et.size / 2);
15121 }
15122
15123 static void
15124 do_neon_mul_sat_scalar_long (void)
15125 {
15126 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15127 }
15128
15129 static void
15130 do_neon_vmull (void)
15131 {
15132 if (inst.operands[2].isscalar)
15133 do_neon_mac_maybe_scalar_long ();
15134 else
15135 {
15136 struct neon_type_el et = neon_check_type (3, NS_QDD,
15137 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
15138
15139 if (et.type == NT_poly)
15140 NEON_ENCODE (POLY, inst);
15141 else
15142 NEON_ENCODE (INTEGER, inst);
15143
15144 /* For polynomial encoding the U bit must be zero, and the size must
15145 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15146 obviously, as 0b10). */
15147 if (et.size == 64)
15148 {
15149 /* Check we're on the correct architecture. */
15150 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15151 inst.error =
15152 _("Instruction form not available on this architecture.");
15153
15154 et.size = 32;
15155 }
15156
15157 neon_mixed_length (et, et.size);
15158 }
15159 }
15160
15161 static void
15162 do_neon_ext (void)
15163 {
15164 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
15165 struct neon_type_el et = neon_check_type (3, rs,
15166 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15167 unsigned imm = (inst.operands[3].imm * et.size) / 8;
15168
15169 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15170 _("shift out of range"));
15171 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15172 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15173 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15174 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15175 inst.instruction |= LOW4 (inst.operands[2].reg);
15176 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15177 inst.instruction |= neon_quad (rs) << 6;
15178 inst.instruction |= imm << 8;
15179
15180 neon_dp_fixup (&inst);
15181 }
15182
15183 static void
15184 do_neon_rev (void)
15185 {
15186 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15187 struct neon_type_el et = neon_check_type (2, rs,
15188 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15189 unsigned op = (inst.instruction >> 7) & 3;
15190 /* N (width of reversed regions) is encoded as part of the bitmask. We
15191 extract it here to check the elements to be reversed are smaller.
15192 Otherwise we'd get a reserved instruction. */
15193 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
15194 gas_assert (elsize != 0);
15195 constraint (et.size >= elsize,
15196 _("elements must be smaller than reversal region"));
15197 neon_two_same (neon_quad (rs), 1, et.size);
15198 }
15199
15200 static void
15201 do_neon_dup (void)
15202 {
15203 if (inst.operands[1].isscalar)
15204 {
15205 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
15206 struct neon_type_el et = neon_check_type (2, rs,
15207 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15208 unsigned sizebits = et.size >> 3;
15209 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
15210 int logsize = neon_logbits (et.size);
15211 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
15212
15213 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
15214 return;
15215
15216 NEON_ENCODE (SCALAR, inst);
15217 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15218 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15219 inst.instruction |= LOW4 (dm);
15220 inst.instruction |= HI1 (dm) << 5;
15221 inst.instruction |= neon_quad (rs) << 6;
15222 inst.instruction |= x << 17;
15223 inst.instruction |= sizebits << 16;
15224
15225 neon_dp_fixup (&inst);
15226 }
15227 else
15228 {
15229 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15230 struct neon_type_el et = neon_check_type (2, rs,
15231 N_8 | N_16 | N_32 | N_KEY, N_EQK);
15232 /* Duplicate ARM register to lanes of vector. */
15233 NEON_ENCODE (ARMREG, inst);
15234 switch (et.size)
15235 {
15236 case 8: inst.instruction |= 0x400000; break;
15237 case 16: inst.instruction |= 0x000020; break;
15238 case 32: inst.instruction |= 0x000000; break;
15239 default: break;
15240 }
15241 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15242 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15243 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
15244 inst.instruction |= neon_quad (rs) << 21;
15245 /* The encoding for this instruction is identical for the ARM and Thumb
15246 variants, except for the condition field. */
15247 do_vfp_cond_or_thumb ();
15248 }
15249 }
15250
15251 /* VMOV has particularly many variations. It can be one of:
15252 0. VMOV<c><q> <Qd>, <Qm>
15253 1. VMOV<c><q> <Dd>, <Dm>
15254 (Register operations, which are VORR with Rm = Rn.)
15255 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15256 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15257 (Immediate loads.)
15258 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15259 (ARM register to scalar.)
15260 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15261 (Two ARM registers to vector.)
15262 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15263 (Scalar to ARM register.)
15264 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15265 (Vector to two ARM registers.)
15266 8. VMOV.F32 <Sd>, <Sm>
15267 9. VMOV.F64 <Dd>, <Dm>
15268 (VFP register moves.)
15269 10. VMOV.F32 <Sd>, #imm
15270 11. VMOV.F64 <Dd>, #imm
15271 (VFP float immediate load.)
15272 12. VMOV <Rd>, <Sm>
15273 (VFP single to ARM reg.)
15274 13. VMOV <Sd>, <Rm>
15275 (ARM reg to VFP single.)
15276 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15277 (Two ARM regs to two VFP singles.)
15278 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15279 (Two VFP singles to two ARM regs.)
15280
15281 These cases can be disambiguated using neon_select_shape, except cases 1/9
15282 and 3/11 which depend on the operand type too.
15283
15284 All the encoded bits are hardcoded by this function.
15285
15286 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15287 Cases 5, 7 may be used with VFPv2 and above.
15288
15289 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
15290 can specify a type where it doesn't make sense to, and is ignored). */
15291
15292 static void
15293 do_neon_mov (void)
15294 {
15295 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15296 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15297 NS_NULL);
15298 struct neon_type_el et;
15299 const char *ldconst = 0;
15300
15301 switch (rs)
15302 {
15303 case NS_DD: /* case 1/9. */
15304 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15305 /* It is not an error here if no type is given. */
15306 inst.error = NULL;
15307 if (et.type == NT_float && et.size == 64)
15308 {
15309 do_vfp_nsyn_opcode ("fcpyd");
15310 break;
15311 }
15312 /* fall through. */
15313
15314 case NS_QQ: /* case 0/1. */
15315 {
15316 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15317 return;
15318 /* The architecture manual I have doesn't explicitly state which
15319 value the U bit should have for register->register moves, but
15320 the equivalent VORR instruction has U = 0, so do that. */
15321 inst.instruction = 0x0200110;
15322 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15323 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15324 inst.instruction |= LOW4 (inst.operands[1].reg);
15325 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15326 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15327 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15328 inst.instruction |= neon_quad (rs) << 6;
15329
15330 neon_dp_fixup (&inst);
15331 }
15332 break;
15333
15334 case NS_DI: /* case 3/11. */
15335 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15336 inst.error = NULL;
15337 if (et.type == NT_float && et.size == 64)
15338 {
15339 /* case 11 (fconstd). */
15340 ldconst = "fconstd";
15341 goto encode_fconstd;
15342 }
15343 /* fall through. */
15344
15345 case NS_QI: /* case 2/3. */
15346 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15347 return;
15348 inst.instruction = 0x0800010;
15349 neon_move_immediate ();
15350 neon_dp_fixup (&inst);
15351 break;
15352
15353 case NS_SR: /* case 4. */
15354 {
15355 unsigned bcdebits = 0;
15356 int logsize;
15357 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15358 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15359
15360 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15361 logsize = neon_logbits (et.size);
15362
15363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15364 _(BAD_FPU));
15365 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15366 && et.size != 32, _(BAD_FPU));
15367 constraint (et.type == NT_invtype, _("bad type for scalar"));
15368 constraint (x >= 64 / et.size, _("scalar index out of range"));
15369
15370 switch (et.size)
15371 {
15372 case 8: bcdebits = 0x8; break;
15373 case 16: bcdebits = 0x1; break;
15374 case 32: bcdebits = 0x0; break;
15375 default: ;
15376 }
15377
15378 bcdebits |= x << logsize;
15379
15380 inst.instruction = 0xe000b10;
15381 do_vfp_cond_or_thumb ();
15382 inst.instruction |= LOW4 (dn) << 16;
15383 inst.instruction |= HI1 (dn) << 7;
15384 inst.instruction |= inst.operands[1].reg << 12;
15385 inst.instruction |= (bcdebits & 3) << 5;
15386 inst.instruction |= (bcdebits >> 2) << 21;
15387 }
15388 break;
15389
15390 case NS_DRR: /* case 5 (fmdrr). */
15391 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15392 _(BAD_FPU));
15393
15394 inst.instruction = 0xc400b10;
15395 do_vfp_cond_or_thumb ();
15396 inst.instruction |= LOW4 (inst.operands[0].reg);
15397 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15398 inst.instruction |= inst.operands[1].reg << 12;
15399 inst.instruction |= inst.operands[2].reg << 16;
15400 break;
15401
15402 case NS_RS: /* case 6. */
15403 {
15404 unsigned logsize;
15405 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15406 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15407 unsigned abcdebits = 0;
15408
15409 et = neon_check_type (2, NS_NULL,
15410 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15411 logsize = neon_logbits (et.size);
15412
15413 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15414 _(BAD_FPU));
15415 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15416 && et.size != 32, _(BAD_FPU));
15417 constraint (et.type == NT_invtype, _("bad type for scalar"));
15418 constraint (x >= 64 / et.size, _("scalar index out of range"));
15419
15420 switch (et.size)
15421 {
15422 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15423 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15424 case 32: abcdebits = 0x00; break;
15425 default: ;
15426 }
15427
15428 abcdebits |= x << logsize;
15429 inst.instruction = 0xe100b10;
15430 do_vfp_cond_or_thumb ();
15431 inst.instruction |= LOW4 (dn) << 16;
15432 inst.instruction |= HI1 (dn) << 7;
15433 inst.instruction |= inst.operands[0].reg << 12;
15434 inst.instruction |= (abcdebits & 3) << 5;
15435 inst.instruction |= (abcdebits >> 2) << 21;
15436 }
15437 break;
15438
15439 case NS_RRD: /* case 7 (fmrrd). */
15440 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15441 _(BAD_FPU));
15442
15443 inst.instruction = 0xc500b10;
15444 do_vfp_cond_or_thumb ();
15445 inst.instruction |= inst.operands[0].reg << 12;
15446 inst.instruction |= inst.operands[1].reg << 16;
15447 inst.instruction |= LOW4 (inst.operands[2].reg);
15448 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15449 break;
15450
15451 case NS_FF: /* case 8 (fcpys). */
15452 do_vfp_nsyn_opcode ("fcpys");
15453 break;
15454
15455 case NS_FI: /* case 10 (fconsts). */
15456 ldconst = "fconsts";
15457 encode_fconstd:
15458 if (is_quarter_float (inst.operands[1].imm))
15459 {
15460 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15461 do_vfp_nsyn_opcode (ldconst);
15462 }
15463 else
15464 first_error (_("immediate out of range"));
15465 break;
15466
15467 case NS_RF: /* case 12 (fmrs). */
15468 do_vfp_nsyn_opcode ("fmrs");
15469 break;
15470
15471 case NS_FR: /* case 13 (fmsr). */
15472 do_vfp_nsyn_opcode ("fmsr");
15473 break;
15474
15475 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15476 (one of which is a list), but we have parsed four. Do some fiddling to
15477 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15478 expect. */
15479 case NS_RRFF: /* case 14 (fmrrs). */
15480 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15481 _("VFP registers must be adjacent"));
15482 inst.operands[2].imm = 2;
15483 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15484 do_vfp_nsyn_opcode ("fmrrs");
15485 break;
15486
15487 case NS_FFRR: /* case 15 (fmsrr). */
15488 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15489 _("VFP registers must be adjacent"));
15490 inst.operands[1] = inst.operands[2];
15491 inst.operands[2] = inst.operands[3];
15492 inst.operands[0].imm = 2;
15493 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15494 do_vfp_nsyn_opcode ("fmsrr");
15495 break;
15496
15497 case NS_NULL:
15498 /* neon_select_shape has determined that the instruction
15499 shape is wrong and has already set the error message. */
15500 break;
15501
15502 default:
15503 abort ();
15504 }
15505 }
15506
15507 static void
15508 do_neon_rshift_round_imm (void)
15509 {
15510 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15511 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15512 int imm = inst.operands[2].imm;
15513
15514 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15515 if (imm == 0)
15516 {
15517 inst.operands[2].present = 0;
15518 do_neon_mov ();
15519 return;
15520 }
15521
15522 constraint (imm < 1 || (unsigned)imm > et.size,
15523 _("immediate out of range for shift"));
15524 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
15525 et.size - imm);
15526 }
15527
15528 static void
15529 do_neon_movl (void)
15530 {
15531 struct neon_type_el et = neon_check_type (2, NS_QD,
15532 N_EQK | N_DBL, N_SU_32 | N_KEY);
15533 unsigned sizebits = et.size >> 3;
15534 inst.instruction |= sizebits << 19;
15535 neon_two_same (0, et.type == NT_unsigned, -1);
15536 }
15537
15538 static void
15539 do_neon_trn (void)
15540 {
15541 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15542 struct neon_type_el et = neon_check_type (2, rs,
15543 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15544 NEON_ENCODE (INTEGER, inst);
15545 neon_two_same (neon_quad (rs), 1, et.size);
15546 }
15547
15548 static void
15549 do_neon_zip_uzp (void)
15550 {
15551 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15552 struct neon_type_el et = neon_check_type (2, rs,
15553 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15554 if (rs == NS_DD && et.size == 32)
15555 {
15556 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15557 inst.instruction = N_MNEM_vtrn;
15558 do_neon_trn ();
15559 return;
15560 }
15561 neon_two_same (neon_quad (rs), 1, et.size);
15562 }
15563
15564 static void
15565 do_neon_sat_abs_neg (void)
15566 {
15567 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15568 struct neon_type_el et = neon_check_type (2, rs,
15569 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15570 neon_two_same (neon_quad (rs), 1, et.size);
15571 }
15572
15573 static void
15574 do_neon_pair_long (void)
15575 {
15576 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15577 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15578 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15579 inst.instruction |= (et.type == NT_unsigned) << 7;
15580 neon_two_same (neon_quad (rs), 1, et.size);
15581 }
15582
15583 static void
15584 do_neon_recip_est (void)
15585 {
15586 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15587 struct neon_type_el et = neon_check_type (2, rs,
15588 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15589 inst.instruction |= (et.type == NT_float) << 8;
15590 neon_two_same (neon_quad (rs), 1, et.size);
15591 }
15592
15593 static void
15594 do_neon_cls (void)
15595 {
15596 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15597 struct neon_type_el et = neon_check_type (2, rs,
15598 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15599 neon_two_same (neon_quad (rs), 1, et.size);
15600 }
15601
15602 static void
15603 do_neon_clz (void)
15604 {
15605 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15606 struct neon_type_el et = neon_check_type (2, rs,
15607 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
15608 neon_two_same (neon_quad (rs), 1, et.size);
15609 }
15610
15611 static void
15612 do_neon_cnt (void)
15613 {
15614 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15615 struct neon_type_el et = neon_check_type (2, rs,
15616 N_EQK | N_INT, N_8 | N_KEY);
15617 neon_two_same (neon_quad (rs), 1, et.size);
15618 }
15619
15620 static void
15621 do_neon_swp (void)
15622 {
15623 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15624 neon_two_same (neon_quad (rs), 1, -1);
15625 }
15626
15627 static void
15628 do_neon_tbl_tbx (void)
15629 {
15630 unsigned listlenbits;
15631 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
15632
15633 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15634 {
15635 first_error (_("bad list length for table lookup"));
15636 return;
15637 }
15638
15639 listlenbits = inst.operands[1].imm - 1;
15640 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15641 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15642 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15643 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15644 inst.instruction |= LOW4 (inst.operands[2].reg);
15645 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15646 inst.instruction |= listlenbits << 8;
15647
15648 neon_dp_fixup (&inst);
15649 }
15650
15651 static void
15652 do_neon_ldm_stm (void)
15653 {
15654 /* P, U and L bits are part of bitmask. */
15655 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15656 unsigned offsetbits = inst.operands[1].imm * 2;
15657
15658 if (inst.operands[1].issingle)
15659 {
15660 do_vfp_nsyn_ldm_stm (is_dbmode);
15661 return;
15662 }
15663
15664 constraint (is_dbmode && !inst.operands[0].writeback,
15665 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15666
15667 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15668 _("register list must contain at least 1 and at most 16 "
15669 "registers"));
15670
15671 inst.instruction |= inst.operands[0].reg << 16;
15672 inst.instruction |= inst.operands[0].writeback << 21;
15673 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15674 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15675
15676 inst.instruction |= offsetbits;
15677
15678 do_vfp_cond_or_thumb ();
15679 }
15680
15681 static void
15682 do_neon_ldr_str (void)
15683 {
15684 int is_ldr = (inst.instruction & (1 << 20)) != 0;
15685
15686 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15687 And is UNPREDICTABLE in thumb mode. */
15688 if (!is_ldr
15689 && inst.operands[1].reg == REG_PC
15690 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15691 {
15692 if (!thumb_mode && warn_on_deprecated)
15693 as_warn (_("Use of PC here is deprecated"));
15694 else
15695 inst.error = _("Use of PC here is UNPREDICTABLE");
15696 }
15697
15698 if (inst.operands[0].issingle)
15699 {
15700 if (is_ldr)
15701 do_vfp_nsyn_opcode ("flds");
15702 else
15703 do_vfp_nsyn_opcode ("fsts");
15704 }
15705 else
15706 {
15707 if (is_ldr)
15708 do_vfp_nsyn_opcode ("fldd");
15709 else
15710 do_vfp_nsyn_opcode ("fstd");
15711 }
15712 }
15713
15714 /* "interleave" version also handles non-interleaving register VLD1/VST1
15715 instructions. */
15716
15717 static void
15718 do_neon_ld_st_interleave (void)
15719 {
15720 struct neon_type_el et = neon_check_type (1, NS_NULL,
15721 N_8 | N_16 | N_32 | N_64);
15722 unsigned alignbits = 0;
15723 unsigned idx;
15724 /* The bits in this table go:
15725 0: register stride of one (0) or two (1)
15726 1,2: register list length, minus one (1, 2, 3, 4).
15727 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15728 We use -1 for invalid entries. */
15729 const int typetable[] =
15730 {
15731 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15732 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15733 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15734 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15735 };
15736 int typebits;
15737
15738 if (et.type == NT_invtype)
15739 return;
15740
15741 if (inst.operands[1].immisalign)
15742 switch (inst.operands[1].imm >> 8)
15743 {
15744 case 64: alignbits = 1; break;
15745 case 128:
15746 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15747 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15748 goto bad_alignment;
15749 alignbits = 2;
15750 break;
15751 case 256:
15752 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15753 goto bad_alignment;
15754 alignbits = 3;
15755 break;
15756 default:
15757 bad_alignment:
15758 first_error (_("bad alignment"));
15759 return;
15760 }
15761
15762 inst.instruction |= alignbits << 4;
15763 inst.instruction |= neon_logbits (et.size) << 6;
15764
15765 /* Bits [4:6] of the immediate in a list specifier encode register stride
15766 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15767 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15768 up the right value for "type" in a table based on this value and the given
15769 list style, then stick it back. */
15770 idx = ((inst.operands[0].imm >> 4) & 7)
15771 | (((inst.instruction >> 8) & 3) << 3);
15772
15773 typebits = typetable[idx];
15774
15775 constraint (typebits == -1, _("bad list type for instruction"));
15776
15777 inst.instruction &= ~0xf00;
15778 inst.instruction |= typebits << 8;
15779 }
15780
15781 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15782 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15783 otherwise. The variable arguments are a list of pairs of legal (size, align)
15784 values, terminated with -1. */
15785
15786 static int
15787 neon_alignment_bit (int size, int align, int *do_align, ...)
15788 {
15789 va_list ap;
15790 int result = FAIL, thissize, thisalign;
15791
15792 if (!inst.operands[1].immisalign)
15793 {
15794 *do_align = 0;
15795 return SUCCESS;
15796 }
15797
15798 va_start (ap, do_align);
15799
15800 do
15801 {
15802 thissize = va_arg (ap, int);
15803 if (thissize == -1)
15804 break;
15805 thisalign = va_arg (ap, int);
15806
15807 if (size == thissize && align == thisalign)
15808 result = SUCCESS;
15809 }
15810 while (result != SUCCESS);
15811
15812 va_end (ap);
15813
15814 if (result == SUCCESS)
15815 *do_align = 1;
15816 else
15817 first_error (_("unsupported alignment for instruction"));
15818
15819 return result;
15820 }
15821
15822 static void
15823 do_neon_ld_st_lane (void)
15824 {
15825 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15826 int align_good, do_align = 0;
15827 int logsize = neon_logbits (et.size);
15828 int align = inst.operands[1].imm >> 8;
15829 int n = (inst.instruction >> 8) & 3;
15830 int max_el = 64 / et.size;
15831
15832 if (et.type == NT_invtype)
15833 return;
15834
15835 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15836 _("bad list length"));
15837 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15838 _("scalar index out of range"));
15839 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15840 && et.size == 8,
15841 _("stride of 2 unavailable when element size is 8"));
15842
15843 switch (n)
15844 {
15845 case 0: /* VLD1 / VST1. */
15846 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15847 32, 32, -1);
15848 if (align_good == FAIL)
15849 return;
15850 if (do_align)
15851 {
15852 unsigned alignbits = 0;
15853 switch (et.size)
15854 {
15855 case 16: alignbits = 0x1; break;
15856 case 32: alignbits = 0x3; break;
15857 default: ;
15858 }
15859 inst.instruction |= alignbits << 4;
15860 }
15861 break;
15862
15863 case 1: /* VLD2 / VST2. */
15864 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15865 32, 64, -1);
15866 if (align_good == FAIL)
15867 return;
15868 if (do_align)
15869 inst.instruction |= 1 << 4;
15870 break;
15871
15872 case 2: /* VLD3 / VST3. */
15873 constraint (inst.operands[1].immisalign,
15874 _("can't use alignment with this instruction"));
15875 break;
15876
15877 case 3: /* VLD4 / VST4. */
15878 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15879 16, 64, 32, 64, 32, 128, -1);
15880 if (align_good == FAIL)
15881 return;
15882 if (do_align)
15883 {
15884 unsigned alignbits = 0;
15885 switch (et.size)
15886 {
15887 case 8: alignbits = 0x1; break;
15888 case 16: alignbits = 0x1; break;
15889 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15890 default: ;
15891 }
15892 inst.instruction |= alignbits << 4;
15893 }
15894 break;
15895
15896 default: ;
15897 }
15898
15899 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15900 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15901 inst.instruction |= 1 << (4 + logsize);
15902
15903 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15904 inst.instruction |= logsize << 10;
15905 }
15906
15907 /* Encode single n-element structure to all lanes VLD<n> instructions. */
15908
15909 static void
15910 do_neon_ld_dup (void)
15911 {
15912 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15913 int align_good, do_align = 0;
15914
15915 if (et.type == NT_invtype)
15916 return;
15917
15918 switch ((inst.instruction >> 8) & 3)
15919 {
15920 case 0: /* VLD1. */
15921 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
15922 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15923 &do_align, 16, 16, 32, 32, -1);
15924 if (align_good == FAIL)
15925 return;
15926 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15927 {
15928 case 1: break;
15929 case 2: inst.instruction |= 1 << 5; break;
15930 default: first_error (_("bad list length")); return;
15931 }
15932 inst.instruction |= neon_logbits (et.size) << 6;
15933 break;
15934
15935 case 1: /* VLD2. */
15936 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15937 &do_align, 8, 16, 16, 32, 32, 64, -1);
15938 if (align_good == FAIL)
15939 return;
15940 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15941 _("bad list length"));
15942 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15943 inst.instruction |= 1 << 5;
15944 inst.instruction |= neon_logbits (et.size) << 6;
15945 break;
15946
15947 case 2: /* VLD3. */
15948 constraint (inst.operands[1].immisalign,
15949 _("can't use alignment with this instruction"));
15950 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15951 _("bad list length"));
15952 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15953 inst.instruction |= 1 << 5;
15954 inst.instruction |= neon_logbits (et.size) << 6;
15955 break;
15956
15957 case 3: /* VLD4. */
15958 {
15959 int align = inst.operands[1].imm >> 8;
15960 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15961 16, 64, 32, 64, 32, 128, -1);
15962 if (align_good == FAIL)
15963 return;
15964 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15965 _("bad list length"));
15966 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15967 inst.instruction |= 1 << 5;
15968 if (et.size == 32 && align == 128)
15969 inst.instruction |= 0x3 << 6;
15970 else
15971 inst.instruction |= neon_logbits (et.size) << 6;
15972 }
15973 break;
15974
15975 default: ;
15976 }
15977
15978 inst.instruction |= do_align << 4;
15979 }
15980
15981 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15982 apart from bits [11:4]. */
15983
15984 static void
15985 do_neon_ldx_stx (void)
15986 {
15987 if (inst.operands[1].isreg)
15988 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15989
15990 switch (NEON_LANE (inst.operands[0].imm))
15991 {
15992 case NEON_INTERLEAVE_LANES:
15993 NEON_ENCODE (INTERLV, inst);
15994 do_neon_ld_st_interleave ();
15995 break;
15996
15997 case NEON_ALL_LANES:
15998 NEON_ENCODE (DUP, inst);
15999 do_neon_ld_dup ();
16000 break;
16001
16002 default:
16003 NEON_ENCODE (LANE, inst);
16004 do_neon_ld_st_lane ();
16005 }
16006
16007 /* L bit comes from bit mask. */
16008 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16009 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16010 inst.instruction |= inst.operands[1].reg << 16;
16011
16012 if (inst.operands[1].postind)
16013 {
16014 int postreg = inst.operands[1].imm & 0xf;
16015 constraint (!inst.operands[1].immisreg,
16016 _("post-index must be a register"));
16017 constraint (postreg == 0xd || postreg == 0xf,
16018 _("bad register for post-index"));
16019 inst.instruction |= postreg;
16020 }
16021 else if (inst.operands[1].writeback)
16022 {
16023 inst.instruction |= 0xd;
16024 }
16025 else
16026 inst.instruction |= 0xf;
16027
16028 if (thumb_mode)
16029 inst.instruction |= 0xf9000000;
16030 else
16031 inst.instruction |= 0xf4000000;
16032 }
16033
16034 /* FP v8. */
16035 static void
16036 do_vfp_nsyn_fpv8 (enum neon_shape rs)
16037 {
16038 NEON_ENCODE (FPV8, inst);
16039
16040 if (rs == NS_FFF)
16041 do_vfp_sp_dyadic ();
16042 else
16043 do_vfp_dp_rd_rn_rm ();
16044
16045 if (rs == NS_DDD)
16046 inst.instruction |= 0x100;
16047
16048 inst.instruction |= 0xf0000000;
16049 }
16050
16051 static void
16052 do_vsel (void)
16053 {
16054 set_it_insn_type (OUTSIDE_IT_INSN);
16055
16056 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16057 first_error (_("invalid instruction shape"));
16058 }
16059
16060 static void
16061 do_vmaxnm (void)
16062 {
16063 set_it_insn_type (OUTSIDE_IT_INSN);
16064
16065 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16066 return;
16067
16068 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16069 return;
16070
16071 neon_dyadic_misc (NT_untyped, N_F32, 0);
16072 }
16073
16074 static void
16075 do_vrint_1 (enum neon_cvt_mode mode)
16076 {
16077 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16078 struct neon_type_el et;
16079
16080 if (rs == NS_NULL)
16081 return;
16082
16083 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16084 if (et.type != NT_invtype)
16085 {
16086 /* VFP encodings. */
16087 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16088 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16089 set_it_insn_type (OUTSIDE_IT_INSN);
16090
16091 NEON_ENCODE (FPV8, inst);
16092 if (rs == NS_FF)
16093 do_vfp_sp_monadic ();
16094 else
16095 do_vfp_dp_rd_rm ();
16096
16097 switch (mode)
16098 {
16099 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16100 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16101 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16102 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16103 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16104 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16105 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16106 default: abort ();
16107 }
16108
16109 inst.instruction |= (rs == NS_DD) << 8;
16110 do_vfp_cond_or_thumb ();
16111 }
16112 else
16113 {
16114 /* Neon encodings (or something broken...). */
16115 inst.error = NULL;
16116 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16117
16118 if (et.type == NT_invtype)
16119 return;
16120
16121 set_it_insn_type (OUTSIDE_IT_INSN);
16122 NEON_ENCODE (FLOAT, inst);
16123
16124 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16125 return;
16126
16127 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16128 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16129 inst.instruction |= LOW4 (inst.operands[1].reg);
16130 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16131 inst.instruction |= neon_quad (rs) << 6;
16132 switch (mode)
16133 {
16134 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16135 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16136 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16137 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16138 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16139 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16140 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16141 default: abort ();
16142 }
16143
16144 if (thumb_mode)
16145 inst.instruction |= 0xfc000000;
16146 else
16147 inst.instruction |= 0xf0000000;
16148 }
16149 }
16150
16151 static void
16152 do_vrintx (void)
16153 {
16154 do_vrint_1 (neon_cvt_mode_x);
16155 }
16156
16157 static void
16158 do_vrintz (void)
16159 {
16160 do_vrint_1 (neon_cvt_mode_z);
16161 }
16162
16163 static void
16164 do_vrintr (void)
16165 {
16166 do_vrint_1 (neon_cvt_mode_r);
16167 }
16168
16169 static void
16170 do_vrinta (void)
16171 {
16172 do_vrint_1 (neon_cvt_mode_a);
16173 }
16174
16175 static void
16176 do_vrintn (void)
16177 {
16178 do_vrint_1 (neon_cvt_mode_n);
16179 }
16180
16181 static void
16182 do_vrintp (void)
16183 {
16184 do_vrint_1 (neon_cvt_mode_p);
16185 }
16186
16187 static void
16188 do_vrintm (void)
16189 {
16190 do_vrint_1 (neon_cvt_mode_m);
16191 }
16192
16193 /* Crypto v1 instructions. */
16194 static void
16195 do_crypto_2op_1 (unsigned elttype, int op)
16196 {
16197 set_it_insn_type (OUTSIDE_IT_INSN);
16198
16199 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16200 == NT_invtype)
16201 return;
16202
16203 inst.error = NULL;
16204
16205 NEON_ENCODE (INTEGER, inst);
16206 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16207 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16208 inst.instruction |= LOW4 (inst.operands[1].reg);
16209 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16210 if (op != -1)
16211 inst.instruction |= op << 6;
16212
16213 if (thumb_mode)
16214 inst.instruction |= 0xfc000000;
16215 else
16216 inst.instruction |= 0xf0000000;
16217 }
16218
16219 static void
16220 do_crypto_3op_1 (int u, int op)
16221 {
16222 set_it_insn_type (OUTSIDE_IT_INSN);
16223
16224 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16225 N_32 | N_UNT | N_KEY).type == NT_invtype)
16226 return;
16227
16228 inst.error = NULL;
16229
16230 NEON_ENCODE (INTEGER, inst);
16231 neon_three_same (1, u, 8 << op);
16232 }
16233
16234 static void
16235 do_aese (void)
16236 {
16237 do_crypto_2op_1 (N_8, 0);
16238 }
16239
16240 static void
16241 do_aesd (void)
16242 {
16243 do_crypto_2op_1 (N_8, 1);
16244 }
16245
16246 static void
16247 do_aesmc (void)
16248 {
16249 do_crypto_2op_1 (N_8, 2);
16250 }
16251
16252 static void
16253 do_aesimc (void)
16254 {
16255 do_crypto_2op_1 (N_8, 3);
16256 }
16257
16258 static void
16259 do_sha1c (void)
16260 {
16261 do_crypto_3op_1 (0, 0);
16262 }
16263
16264 static void
16265 do_sha1p (void)
16266 {
16267 do_crypto_3op_1 (0, 1);
16268 }
16269
16270 static void
16271 do_sha1m (void)
16272 {
16273 do_crypto_3op_1 (0, 2);
16274 }
16275
16276 static void
16277 do_sha1su0 (void)
16278 {
16279 do_crypto_3op_1 (0, 3);
16280 }
16281
16282 static void
16283 do_sha256h (void)
16284 {
16285 do_crypto_3op_1 (1, 0);
16286 }
16287
16288 static void
16289 do_sha256h2 (void)
16290 {
16291 do_crypto_3op_1 (1, 1);
16292 }
16293
16294 static void
16295 do_sha256su1 (void)
16296 {
16297 do_crypto_3op_1 (1, 2);
16298 }
16299
16300 static void
16301 do_sha1h (void)
16302 {
16303 do_crypto_2op_1 (N_32, -1);
16304 }
16305
16306 static void
16307 do_sha1su1 (void)
16308 {
16309 do_crypto_2op_1 (N_32, 0);
16310 }
16311
16312 static void
16313 do_sha256su0 (void)
16314 {
16315 do_crypto_2op_1 (N_32, 1);
16316 }
16317 \f
16318 /* Overall per-instruction processing. */
16319
16320 /* We need to be able to fix up arbitrary expressions in some statements.
16321 This is so that we can handle symbols that are an arbitrary distance from
16322 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16323 which returns part of an address in a form which will be valid for
16324 a data instruction. We do this by pushing the expression into a symbol
16325 in the expr_section, and creating a fix for that. */
16326
16327 static void
16328 fix_new_arm (fragS * frag,
16329 int where,
16330 short int size,
16331 expressionS * exp,
16332 int pc_rel,
16333 int reloc)
16334 {
16335 fixS * new_fix;
16336
16337 switch (exp->X_op)
16338 {
16339 case O_constant:
16340 if (pc_rel)
16341 {
16342 /* Create an absolute valued symbol, so we have something to
16343 refer to in the object file. Unfortunately for us, gas's
16344 generic expression parsing will already have folded out
16345 any use of .set foo/.type foo %function that may have
16346 been used to set type information of the target location,
16347 that's being specified symbolically. We have to presume
16348 the user knows what they are doing. */
16349 char name[16 + 8];
16350 symbolS *symbol;
16351
16352 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
16353
16354 symbol = symbol_find_or_make (name);
16355 S_SET_SEGMENT (symbol, absolute_section);
16356 symbol_set_frag (symbol, &zero_address_frag);
16357 S_SET_VALUE (symbol, exp->X_add_number);
16358 exp->X_op = O_symbol;
16359 exp->X_add_symbol = symbol;
16360 exp->X_add_number = 0;
16361 }
16362 /* FALLTHROUGH */
16363 case O_symbol:
16364 case O_add:
16365 case O_subtract:
16366 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
16367 (enum bfd_reloc_code_real) reloc);
16368 break;
16369
16370 default:
16371 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
16372 pc_rel, (enum bfd_reloc_code_real) reloc);
16373 break;
16374 }
16375
16376 /* Mark whether the fix is to a THUMB instruction, or an ARM
16377 instruction. */
16378 new_fix->tc_fix_data = thumb_mode;
16379 }
16380
16381 /* Create a frg for an instruction requiring relaxation. */
16382 static void
16383 output_relax_insn (void)
16384 {
16385 char * to;
16386 symbolS *sym;
16387 int offset;
16388
16389 /* The size of the instruction is unknown, so tie the debug info to the
16390 start of the instruction. */
16391 dwarf2_emit_insn (0);
16392
16393 switch (inst.reloc.exp.X_op)
16394 {
16395 case O_symbol:
16396 sym = inst.reloc.exp.X_add_symbol;
16397 offset = inst.reloc.exp.X_add_number;
16398 break;
16399 case O_constant:
16400 sym = NULL;
16401 offset = inst.reloc.exp.X_add_number;
16402 break;
16403 default:
16404 sym = make_expr_symbol (&inst.reloc.exp);
16405 offset = 0;
16406 break;
16407 }
16408 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
16409 inst.relax, sym, offset, NULL/*offset, opcode*/);
16410 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
16411 }
16412
16413 /* Write a 32-bit thumb instruction to buf. */
16414 static void
16415 put_thumb32_insn (char * buf, unsigned long insn)
16416 {
16417 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
16418 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
16419 }
16420
16421 static void
16422 output_inst (const char * str)
16423 {
16424 char * to = NULL;
16425
16426 if (inst.error)
16427 {
16428 as_bad ("%s -- `%s'", inst.error, str);
16429 return;
16430 }
16431 if (inst.relax)
16432 {
16433 output_relax_insn ();
16434 return;
16435 }
16436 if (inst.size == 0)
16437 return;
16438
16439 to = frag_more (inst.size);
16440 /* PR 9814: Record the thumb mode into the current frag so that we know
16441 what type of NOP padding to use, if necessary. We override any previous
16442 setting so that if the mode has changed then the NOPS that we use will
16443 match the encoding of the last instruction in the frag. */
16444 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
16445
16446 if (thumb_mode && (inst.size > THUMB_SIZE))
16447 {
16448 gas_assert (inst.size == (2 * THUMB_SIZE));
16449 put_thumb32_insn (to, inst.instruction);
16450 }
16451 else if (inst.size > INSN_SIZE)
16452 {
16453 gas_assert (inst.size == (2 * INSN_SIZE));
16454 md_number_to_chars (to, inst.instruction, INSN_SIZE);
16455 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
16456 }
16457 else
16458 md_number_to_chars (to, inst.instruction, inst.size);
16459
16460 if (inst.reloc.type != BFD_RELOC_UNUSED)
16461 fix_new_arm (frag_now, to - frag_now->fr_literal,
16462 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
16463 inst.reloc.type);
16464
16465 dwarf2_emit_insn (inst.size);
16466 }
16467
16468 static char *
16469 output_it_inst (int cond, int mask, char * to)
16470 {
16471 unsigned long instruction = 0xbf00;
16472
16473 mask &= 0xf;
16474 instruction |= mask;
16475 instruction |= cond << 4;
16476
16477 if (to == NULL)
16478 {
16479 to = frag_more (2);
16480 #ifdef OBJ_ELF
16481 dwarf2_emit_insn (2);
16482 #endif
16483 }
16484
16485 md_number_to_chars (to, instruction, 2);
16486
16487 return to;
16488 }
16489
16490 /* Tag values used in struct asm_opcode's tag field. */
16491 enum opcode_tag
16492 {
16493 OT_unconditional, /* Instruction cannot be conditionalized.
16494 The ARM condition field is still 0xE. */
16495 OT_unconditionalF, /* Instruction cannot be conditionalized
16496 and carries 0xF in its ARM condition field. */
16497 OT_csuffix, /* Instruction takes a conditional suffix. */
16498 OT_csuffixF, /* Some forms of the instruction take a conditional
16499 suffix, others place 0xF where the condition field
16500 would be. */
16501 OT_cinfix3, /* Instruction takes a conditional infix,
16502 beginning at character index 3. (In
16503 unified mode, it becomes a suffix.) */
16504 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
16505 tsts, cmps, cmns, and teqs. */
16506 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
16507 character index 3, even in unified mode. Used for
16508 legacy instructions where suffix and infix forms
16509 may be ambiguous. */
16510 OT_csuf_or_in3, /* Instruction takes either a conditional
16511 suffix or an infix at character index 3. */
16512 OT_odd_infix_unc, /* This is the unconditional variant of an
16513 instruction that takes a conditional infix
16514 at an unusual position. In unified mode,
16515 this variant will accept a suffix. */
16516 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
16517 are the conditional variants of instructions that
16518 take conditional infixes in unusual positions.
16519 The infix appears at character index
16520 (tag - OT_odd_infix_0). These are not accepted
16521 in unified mode. */
16522 };
16523
16524 /* Subroutine of md_assemble, responsible for looking up the primary
16525 opcode from the mnemonic the user wrote. STR points to the
16526 beginning of the mnemonic.
16527
16528 This is not simply a hash table lookup, because of conditional
16529 variants. Most instructions have conditional variants, which are
16530 expressed with a _conditional affix_ to the mnemonic. If we were
16531 to encode each conditional variant as a literal string in the opcode
16532 table, it would have approximately 20,000 entries.
16533
16534 Most mnemonics take this affix as a suffix, and in unified syntax,
16535 'most' is upgraded to 'all'. However, in the divided syntax, some
16536 instructions take the affix as an infix, notably the s-variants of
16537 the arithmetic instructions. Of those instructions, all but six
16538 have the infix appear after the third character of the mnemonic.
16539
16540 Accordingly, the algorithm for looking up primary opcodes given
16541 an identifier is:
16542
16543 1. Look up the identifier in the opcode table.
16544 If we find a match, go to step U.
16545
16546 2. Look up the last two characters of the identifier in the
16547 conditions table. If we find a match, look up the first N-2
16548 characters of the identifier in the opcode table. If we
16549 find a match, go to step CE.
16550
16551 3. Look up the fourth and fifth characters of the identifier in
16552 the conditions table. If we find a match, extract those
16553 characters from the identifier, and look up the remaining
16554 characters in the opcode table. If we find a match, go
16555 to step CM.
16556
16557 4. Fail.
16558
16559 U. Examine the tag field of the opcode structure, in case this is
16560 one of the six instructions with its conditional infix in an
16561 unusual place. If it is, the tag tells us where to find the
16562 infix; look it up in the conditions table and set inst.cond
16563 accordingly. Otherwise, this is an unconditional instruction.
16564 Again set inst.cond accordingly. Return the opcode structure.
16565
16566 CE. Examine the tag field to make sure this is an instruction that
16567 should receive a conditional suffix. If it is not, fail.
16568 Otherwise, set inst.cond from the suffix we already looked up,
16569 and return the opcode structure.
16570
16571 CM. Examine the tag field to make sure this is an instruction that
16572 should receive a conditional infix after the third character.
16573 If it is not, fail. Otherwise, undo the edits to the current
16574 line of input and proceed as for case CE. */
16575
16576 static const struct asm_opcode *
16577 opcode_lookup (char **str)
16578 {
16579 char *end, *base;
16580 char *affix;
16581 const struct asm_opcode *opcode;
16582 const struct asm_cond *cond;
16583 char save[2];
16584
16585 /* Scan up to the end of the mnemonic, which must end in white space,
16586 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
16587 for (base = end = *str; *end != '\0'; end++)
16588 if (*end == ' ' || *end == '.')
16589 break;
16590
16591 if (end == base)
16592 return NULL;
16593
16594 /* Handle a possible width suffix and/or Neon type suffix. */
16595 if (end[0] == '.')
16596 {
16597 int offset = 2;
16598
16599 /* The .w and .n suffixes are only valid if the unified syntax is in
16600 use. */
16601 if (unified_syntax && end[1] == 'w')
16602 inst.size_req = 4;
16603 else if (unified_syntax && end[1] == 'n')
16604 inst.size_req = 2;
16605 else
16606 offset = 0;
16607
16608 inst.vectype.elems = 0;
16609
16610 *str = end + offset;
16611
16612 if (end[offset] == '.')
16613 {
16614 /* See if we have a Neon type suffix (possible in either unified or
16615 non-unified ARM syntax mode). */
16616 if (parse_neon_type (&inst.vectype, str) == FAIL)
16617 return NULL;
16618 }
16619 else if (end[offset] != '\0' && end[offset] != ' ')
16620 return NULL;
16621 }
16622 else
16623 *str = end;
16624
16625 /* Look for unaffixed or special-case affixed mnemonic. */
16626 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16627 end - base);
16628 if (opcode)
16629 {
16630 /* step U */
16631 if (opcode->tag < OT_odd_infix_0)
16632 {
16633 inst.cond = COND_ALWAYS;
16634 return opcode;
16635 }
16636
16637 if (warn_on_deprecated && unified_syntax)
16638 as_warn (_("conditional infixes are deprecated in unified syntax"));
16639 affix = base + (opcode->tag - OT_odd_infix_0);
16640 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16641 gas_assert (cond);
16642
16643 inst.cond = cond->value;
16644 return opcode;
16645 }
16646
16647 /* Cannot have a conditional suffix on a mnemonic of less than two
16648 characters. */
16649 if (end - base < 3)
16650 return NULL;
16651
16652 /* Look for suffixed mnemonic. */
16653 affix = end - 2;
16654 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16655 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16656 affix - base);
16657 if (opcode && cond)
16658 {
16659 /* step CE */
16660 switch (opcode->tag)
16661 {
16662 case OT_cinfix3_legacy:
16663 /* Ignore conditional suffixes matched on infix only mnemonics. */
16664 break;
16665
16666 case OT_cinfix3:
16667 case OT_cinfix3_deprecated:
16668 case OT_odd_infix_unc:
16669 if (!unified_syntax)
16670 return 0;
16671 /* else fall through */
16672
16673 case OT_csuffix:
16674 case OT_csuffixF:
16675 case OT_csuf_or_in3:
16676 inst.cond = cond->value;
16677 return opcode;
16678
16679 case OT_unconditional:
16680 case OT_unconditionalF:
16681 if (thumb_mode)
16682 inst.cond = cond->value;
16683 else
16684 {
16685 /* Delayed diagnostic. */
16686 inst.error = BAD_COND;
16687 inst.cond = COND_ALWAYS;
16688 }
16689 return opcode;
16690
16691 default:
16692 return NULL;
16693 }
16694 }
16695
16696 /* Cannot have a usual-position infix on a mnemonic of less than
16697 six characters (five would be a suffix). */
16698 if (end - base < 6)
16699 return NULL;
16700
16701 /* Look for infixed mnemonic in the usual position. */
16702 affix = base + 3;
16703 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16704 if (!cond)
16705 return NULL;
16706
16707 memcpy (save, affix, 2);
16708 memmove (affix, affix + 2, (end - affix) - 2);
16709 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16710 (end - base) - 2);
16711 memmove (affix + 2, affix, (end - affix) - 2);
16712 memcpy (affix, save, 2);
16713
16714 if (opcode
16715 && (opcode->tag == OT_cinfix3
16716 || opcode->tag == OT_cinfix3_deprecated
16717 || opcode->tag == OT_csuf_or_in3
16718 || opcode->tag == OT_cinfix3_legacy))
16719 {
16720 /* Step CM. */
16721 if (warn_on_deprecated && unified_syntax
16722 && (opcode->tag == OT_cinfix3
16723 || opcode->tag == OT_cinfix3_deprecated))
16724 as_warn (_("conditional infixes are deprecated in unified syntax"));
16725
16726 inst.cond = cond->value;
16727 return opcode;
16728 }
16729
16730 return NULL;
16731 }
16732
16733 /* This function generates an initial IT instruction, leaving its block
16734 virtually open for the new instructions. Eventually,
16735 the mask will be updated by now_it_add_mask () each time
16736 a new instruction needs to be included in the IT block.
16737 Finally, the block is closed with close_automatic_it_block ().
16738 The block closure can be requested either from md_assemble (),
16739 a tencode (), or due to a label hook. */
16740
16741 static void
16742 new_automatic_it_block (int cond)
16743 {
16744 now_it.state = AUTOMATIC_IT_BLOCK;
16745 now_it.mask = 0x18;
16746 now_it.cc = cond;
16747 now_it.block_length = 1;
16748 mapping_state (MAP_THUMB);
16749 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
16750 now_it.warn_deprecated = FALSE;
16751 now_it.insn_cond = TRUE;
16752 }
16753
16754 /* Close an automatic IT block.
16755 See comments in new_automatic_it_block (). */
16756
16757 static void
16758 close_automatic_it_block (void)
16759 {
16760 now_it.mask = 0x10;
16761 now_it.block_length = 0;
16762 }
16763
16764 /* Update the mask of the current automatically-generated IT
16765 instruction. See comments in new_automatic_it_block (). */
16766
16767 static void
16768 now_it_add_mask (int cond)
16769 {
16770 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16771 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16772 | ((bitvalue) << (nbit)))
16773 const int resulting_bit = (cond & 1);
16774
16775 now_it.mask &= 0xf;
16776 now_it.mask = SET_BIT_VALUE (now_it.mask,
16777 resulting_bit,
16778 (5 - now_it.block_length));
16779 now_it.mask = SET_BIT_VALUE (now_it.mask,
16780 1,
16781 ((5 - now_it.block_length) - 1) );
16782 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16783
16784 #undef CLEAR_BIT
16785 #undef SET_BIT_VALUE
16786 }
16787
16788 /* The IT blocks handling machinery is accessed through the these functions:
16789 it_fsm_pre_encode () from md_assemble ()
16790 set_it_insn_type () optional, from the tencode functions
16791 set_it_insn_type_last () ditto
16792 in_it_block () ditto
16793 it_fsm_post_encode () from md_assemble ()
16794 force_automatic_it_block_close () from label habdling functions
16795
16796 Rationale:
16797 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16798 initializing the IT insn type with a generic initial value depending
16799 on the inst.condition.
16800 2) During the tencode function, two things may happen:
16801 a) The tencode function overrides the IT insn type by
16802 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16803 b) The tencode function queries the IT block state by
16804 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16805
16806 Both set_it_insn_type and in_it_block run the internal FSM state
16807 handling function (handle_it_state), because: a) setting the IT insn
16808 type may incur in an invalid state (exiting the function),
16809 and b) querying the state requires the FSM to be updated.
16810 Specifically we want to avoid creating an IT block for conditional
16811 branches, so it_fsm_pre_encode is actually a guess and we can't
16812 determine whether an IT block is required until the tencode () routine
16813 has decided what type of instruction this actually it.
16814 Because of this, if set_it_insn_type and in_it_block have to be used,
16815 set_it_insn_type has to be called first.
16816
16817 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16818 determines the insn IT type depending on the inst.cond code.
16819 When a tencode () routine encodes an instruction that can be
16820 either outside an IT block, or, in the case of being inside, has to be
16821 the last one, set_it_insn_type_last () will determine the proper
16822 IT instruction type based on the inst.cond code. Otherwise,
16823 set_it_insn_type can be called for overriding that logic or
16824 for covering other cases.
16825
16826 Calling handle_it_state () may not transition the IT block state to
16827 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16828 still queried. Instead, if the FSM determines that the state should
16829 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16830 after the tencode () function: that's what it_fsm_post_encode () does.
16831
16832 Since in_it_block () calls the state handling function to get an
16833 updated state, an error may occur (due to invalid insns combination).
16834 In that case, inst.error is set.
16835 Therefore, inst.error has to be checked after the execution of
16836 the tencode () routine.
16837
16838 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16839 any pending state change (if any) that didn't take place in
16840 handle_it_state () as explained above. */
16841
16842 static void
16843 it_fsm_pre_encode (void)
16844 {
16845 if (inst.cond != COND_ALWAYS)
16846 inst.it_insn_type = INSIDE_IT_INSN;
16847 else
16848 inst.it_insn_type = OUTSIDE_IT_INSN;
16849
16850 now_it.state_handled = 0;
16851 }
16852
16853 /* IT state FSM handling function. */
16854
16855 static int
16856 handle_it_state (void)
16857 {
16858 now_it.state_handled = 1;
16859 now_it.insn_cond = FALSE;
16860
16861 switch (now_it.state)
16862 {
16863 case OUTSIDE_IT_BLOCK:
16864 switch (inst.it_insn_type)
16865 {
16866 case OUTSIDE_IT_INSN:
16867 break;
16868
16869 case INSIDE_IT_INSN:
16870 case INSIDE_IT_LAST_INSN:
16871 if (thumb_mode == 0)
16872 {
16873 if (unified_syntax
16874 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16875 as_tsktsk (_("Warning: conditional outside an IT block"\
16876 " for Thumb."));
16877 }
16878 else
16879 {
16880 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16881 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16882 {
16883 /* Automatically generate the IT instruction. */
16884 new_automatic_it_block (inst.cond);
16885 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16886 close_automatic_it_block ();
16887 }
16888 else
16889 {
16890 inst.error = BAD_OUT_IT;
16891 return FAIL;
16892 }
16893 }
16894 break;
16895
16896 case IF_INSIDE_IT_LAST_INSN:
16897 case NEUTRAL_IT_INSN:
16898 break;
16899
16900 case IT_INSN:
16901 now_it.state = MANUAL_IT_BLOCK;
16902 now_it.block_length = 0;
16903 break;
16904 }
16905 break;
16906
16907 case AUTOMATIC_IT_BLOCK:
16908 /* Three things may happen now:
16909 a) We should increment current it block size;
16910 b) We should close current it block (closing insn or 4 insns);
16911 c) We should close current it block and start a new one (due
16912 to incompatible conditions or
16913 4 insns-length block reached). */
16914
16915 switch (inst.it_insn_type)
16916 {
16917 case OUTSIDE_IT_INSN:
16918 /* The closure of the block shall happen immediatelly,
16919 so any in_it_block () call reports the block as closed. */
16920 force_automatic_it_block_close ();
16921 break;
16922
16923 case INSIDE_IT_INSN:
16924 case INSIDE_IT_LAST_INSN:
16925 case IF_INSIDE_IT_LAST_INSN:
16926 now_it.block_length++;
16927
16928 if (now_it.block_length > 4
16929 || !now_it_compatible (inst.cond))
16930 {
16931 force_automatic_it_block_close ();
16932 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16933 new_automatic_it_block (inst.cond);
16934 }
16935 else
16936 {
16937 now_it.insn_cond = TRUE;
16938 now_it_add_mask (inst.cond);
16939 }
16940
16941 if (now_it.state == AUTOMATIC_IT_BLOCK
16942 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16943 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16944 close_automatic_it_block ();
16945 break;
16946
16947 case NEUTRAL_IT_INSN:
16948 now_it.block_length++;
16949 now_it.insn_cond = TRUE;
16950
16951 if (now_it.block_length > 4)
16952 force_automatic_it_block_close ();
16953 else
16954 now_it_add_mask (now_it.cc & 1);
16955 break;
16956
16957 case IT_INSN:
16958 close_automatic_it_block ();
16959 now_it.state = MANUAL_IT_BLOCK;
16960 break;
16961 }
16962 break;
16963
16964 case MANUAL_IT_BLOCK:
16965 {
16966 /* Check conditional suffixes. */
16967 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16968 int is_last;
16969 now_it.mask <<= 1;
16970 now_it.mask &= 0x1f;
16971 is_last = (now_it.mask == 0x10);
16972 now_it.insn_cond = TRUE;
16973
16974 switch (inst.it_insn_type)
16975 {
16976 case OUTSIDE_IT_INSN:
16977 inst.error = BAD_NOT_IT;
16978 return FAIL;
16979
16980 case INSIDE_IT_INSN:
16981 if (cond != inst.cond)
16982 {
16983 inst.error = BAD_IT_COND;
16984 return FAIL;
16985 }
16986 break;
16987
16988 case INSIDE_IT_LAST_INSN:
16989 case IF_INSIDE_IT_LAST_INSN:
16990 if (cond != inst.cond)
16991 {
16992 inst.error = BAD_IT_COND;
16993 return FAIL;
16994 }
16995 if (!is_last)
16996 {
16997 inst.error = BAD_BRANCH;
16998 return FAIL;
16999 }
17000 break;
17001
17002 case NEUTRAL_IT_INSN:
17003 /* The BKPT instruction is unconditional even in an IT block. */
17004 break;
17005
17006 case IT_INSN:
17007 inst.error = BAD_IT_IT;
17008 return FAIL;
17009 }
17010 }
17011 break;
17012 }
17013
17014 return SUCCESS;
17015 }
17016
17017 struct depr_insn_mask
17018 {
17019 unsigned long pattern;
17020 unsigned long mask;
17021 const char* description;
17022 };
17023
17024 /* List of 16-bit instruction patterns deprecated in an IT block in
17025 ARMv8. */
17026 static const struct depr_insn_mask depr_it_insns[] = {
17027 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17028 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17029 { 0xa000, 0xb800, N_("ADR") },
17030 { 0x4800, 0xf800, N_("Literal loads") },
17031 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17032 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
17033 { 0, 0, NULL }
17034 };
17035
17036 static void
17037 it_fsm_post_encode (void)
17038 {
17039 int is_last;
17040
17041 if (!now_it.state_handled)
17042 handle_it_state ();
17043
17044 if (now_it.insn_cond
17045 && !now_it.warn_deprecated
17046 && warn_on_deprecated
17047 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17048 {
17049 if (inst.instruction >= 0x10000)
17050 {
17051 as_warn (_("it blocks containing wide Thumb instructions are "
17052 "deprecated in ARMv8"));
17053 now_it.warn_deprecated = TRUE;
17054 }
17055 else
17056 {
17057 const struct depr_insn_mask *p = depr_it_insns;
17058
17059 while (p->mask != 0)
17060 {
17061 if ((inst.instruction & p->mask) == p->pattern)
17062 {
17063 as_warn (_("it blocks containing 16-bit Thumb intsructions "
17064 "of the following class are deprecated in ARMv8: "
17065 "%s"), p->description);
17066 now_it.warn_deprecated = TRUE;
17067 break;
17068 }
17069
17070 ++p;
17071 }
17072 }
17073
17074 if (now_it.block_length > 1)
17075 {
17076 as_warn (_("it blocks of more than one conditional instruction are "
17077 "deprecated in ARMv8"));
17078 now_it.warn_deprecated = TRUE;
17079 }
17080 }
17081
17082 is_last = (now_it.mask == 0x10);
17083 if (is_last)
17084 {
17085 now_it.state = OUTSIDE_IT_BLOCK;
17086 now_it.mask = 0;
17087 }
17088 }
17089
17090 static void
17091 force_automatic_it_block_close (void)
17092 {
17093 if (now_it.state == AUTOMATIC_IT_BLOCK)
17094 {
17095 close_automatic_it_block ();
17096 now_it.state = OUTSIDE_IT_BLOCK;
17097 now_it.mask = 0;
17098 }
17099 }
17100
17101 static int
17102 in_it_block (void)
17103 {
17104 if (!now_it.state_handled)
17105 handle_it_state ();
17106
17107 return now_it.state != OUTSIDE_IT_BLOCK;
17108 }
17109
17110 void
17111 md_assemble (char *str)
17112 {
17113 char *p = str;
17114 const struct asm_opcode * opcode;
17115
17116 /* Align the previous label if needed. */
17117 if (last_label_seen != NULL)
17118 {
17119 symbol_set_frag (last_label_seen, frag_now);
17120 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17121 S_SET_SEGMENT (last_label_seen, now_seg);
17122 }
17123
17124 memset (&inst, '\0', sizeof (inst));
17125 inst.reloc.type = BFD_RELOC_UNUSED;
17126
17127 opcode = opcode_lookup (&p);
17128 if (!opcode)
17129 {
17130 /* It wasn't an instruction, but it might be a register alias of
17131 the form alias .req reg, or a Neon .dn/.qn directive. */
17132 if (! create_register_alias (str, p)
17133 && ! create_neon_reg_alias (str, p))
17134 as_bad (_("bad instruction `%s'"), str);
17135
17136 return;
17137 }
17138
17139 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
17140 as_warn (_("s suffix on comparison instruction is deprecated"));
17141
17142 /* The value which unconditional instructions should have in place of the
17143 condition field. */
17144 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17145
17146 if (thumb_mode)
17147 {
17148 arm_feature_set variant;
17149
17150 variant = cpu_variant;
17151 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
17152 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17153 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
17154 /* Check that this instruction is supported for this CPU. */
17155 if (!opcode->tvariant
17156 || (thumb_mode == 1
17157 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
17158 {
17159 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
17160 return;
17161 }
17162 if (inst.cond != COND_ALWAYS && !unified_syntax
17163 && opcode->tencode != do_t_branch)
17164 {
17165 as_bad (_("Thumb does not support conditional execution"));
17166 return;
17167 }
17168
17169 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
17170 {
17171 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
17172 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17173 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17174 {
17175 /* Two things are addressed here.
17176 1) Implicit require narrow instructions on Thumb-1.
17177 This avoids relaxation accidentally introducing Thumb-2
17178 instructions.
17179 2) Reject wide instructions in non Thumb-2 cores. */
17180 if (inst.size_req == 0)
17181 inst.size_req = 2;
17182 else if (inst.size_req == 4)
17183 {
17184 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
17185 return;
17186 }
17187 }
17188 }
17189
17190 inst.instruction = opcode->tvalue;
17191
17192 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
17193 {
17194 /* Prepare the it_insn_type for those encodings that don't set
17195 it. */
17196 it_fsm_pre_encode ();
17197
17198 opcode->tencode ();
17199
17200 it_fsm_post_encode ();
17201 }
17202
17203 if (!(inst.error || inst.relax))
17204 {
17205 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
17206 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17207 if (inst.size_req && inst.size_req != inst.size)
17208 {
17209 as_bad (_("cannot honor width suffix -- `%s'"), str);
17210 return;
17211 }
17212 }
17213
17214 /* Something has gone badly wrong if we try to relax a fixed size
17215 instruction. */
17216 gas_assert (inst.size_req == 0 || !inst.relax);
17217
17218 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17219 *opcode->tvariant);
17220 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
17221 set those bits when Thumb-2 32-bit instructions are seen. ie.
17222 anything other than bl/blx and v6-M instructions.
17223 This is overly pessimistic for relaxable instructions. */
17224 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
17225 || inst.relax)
17226 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17227 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
17228 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17229 arm_ext_v6t2);
17230
17231 check_neon_suffixes;
17232
17233 if (!inst.error)
17234 {
17235 mapping_state (MAP_THUMB);
17236 }
17237 }
17238 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
17239 {
17240 bfd_boolean is_bx;
17241
17242 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17243 is_bx = (opcode->aencode == do_bx);
17244
17245 /* Check that this instruction is supported for this CPU. */
17246 if (!(is_bx && fix_v4bx)
17247 && !(opcode->avariant &&
17248 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
17249 {
17250 as_bad (_("selected processor does not support ARM mode `%s'"), str);
17251 return;
17252 }
17253 if (inst.size_req)
17254 {
17255 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17256 return;
17257 }
17258
17259 inst.instruction = opcode->avalue;
17260 if (opcode->tag == OT_unconditionalF)
17261 inst.instruction |= 0xF << 28;
17262 else
17263 inst.instruction |= inst.cond << 28;
17264 inst.size = INSN_SIZE;
17265 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
17266 {
17267 it_fsm_pre_encode ();
17268 opcode->aencode ();
17269 it_fsm_post_encode ();
17270 }
17271 /* Arm mode bx is marked as both v4T and v5 because it's still required
17272 on a hypothetical non-thumb v5 core. */
17273 if (is_bx)
17274 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
17275 else
17276 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17277 *opcode->avariant);
17278
17279 check_neon_suffixes;
17280
17281 if (!inst.error)
17282 {
17283 mapping_state (MAP_ARM);
17284 }
17285 }
17286 else
17287 {
17288 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17289 "-- `%s'"), str);
17290 return;
17291 }
17292 output_inst (str);
17293 }
17294
17295 static void
17296 check_it_blocks_finished (void)
17297 {
17298 #ifdef OBJ_ELF
17299 asection *sect;
17300
17301 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17302 if (seg_info (sect)->tc_segment_info_data.current_it.state
17303 == MANUAL_IT_BLOCK)
17304 {
17305 as_warn (_("section '%s' finished with an open IT block."),
17306 sect->name);
17307 }
17308 #else
17309 if (now_it.state == MANUAL_IT_BLOCK)
17310 as_warn (_("file finished with an open IT block."));
17311 #endif
17312 }
17313
17314 /* Various frobbings of labels and their addresses. */
17315
17316 void
17317 arm_start_line_hook (void)
17318 {
17319 last_label_seen = NULL;
17320 }
17321
17322 void
17323 arm_frob_label (symbolS * sym)
17324 {
17325 last_label_seen = sym;
17326
17327 ARM_SET_THUMB (sym, thumb_mode);
17328
17329 #if defined OBJ_COFF || defined OBJ_ELF
17330 ARM_SET_INTERWORK (sym, support_interwork);
17331 #endif
17332
17333 force_automatic_it_block_close ();
17334
17335 /* Note - do not allow local symbols (.Lxxx) to be labelled
17336 as Thumb functions. This is because these labels, whilst
17337 they exist inside Thumb code, are not the entry points for
17338 possible ARM->Thumb calls. Also, these labels can be used
17339 as part of a computed goto or switch statement. eg gcc
17340 can generate code that looks like this:
17341
17342 ldr r2, [pc, .Laaa]
17343 lsl r3, r3, #2
17344 ldr r2, [r3, r2]
17345 mov pc, r2
17346
17347 .Lbbb: .word .Lxxx
17348 .Lccc: .word .Lyyy
17349 ..etc...
17350 .Laaa: .word Lbbb
17351
17352 The first instruction loads the address of the jump table.
17353 The second instruction converts a table index into a byte offset.
17354 The third instruction gets the jump address out of the table.
17355 The fourth instruction performs the jump.
17356
17357 If the address stored at .Laaa is that of a symbol which has the
17358 Thumb_Func bit set, then the linker will arrange for this address
17359 to have the bottom bit set, which in turn would mean that the
17360 address computation performed by the third instruction would end
17361 up with the bottom bit set. Since the ARM is capable of unaligned
17362 word loads, the instruction would then load the incorrect address
17363 out of the jump table, and chaos would ensue. */
17364 if (label_is_thumb_function_name
17365 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
17366 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
17367 {
17368 /* When the address of a Thumb function is taken the bottom
17369 bit of that address should be set. This will allow
17370 interworking between Arm and Thumb functions to work
17371 correctly. */
17372
17373 THUMB_SET_FUNC (sym, 1);
17374
17375 label_is_thumb_function_name = FALSE;
17376 }
17377
17378 dwarf2_emit_label (sym);
17379 }
17380
17381 bfd_boolean
17382 arm_data_in_code (void)
17383 {
17384 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
17385 {
17386 *input_line_pointer = '/';
17387 input_line_pointer += 5;
17388 *input_line_pointer = 0;
17389 return TRUE;
17390 }
17391
17392 return FALSE;
17393 }
17394
17395 char *
17396 arm_canonicalize_symbol_name (char * name)
17397 {
17398 int len;
17399
17400 if (thumb_mode && (len = strlen (name)) > 5
17401 && streq (name + len - 5, "/data"))
17402 *(name + len - 5) = 0;
17403
17404 return name;
17405 }
17406 \f
17407 /* Table of all register names defined by default. The user can
17408 define additional names with .req. Note that all register names
17409 should appear in both upper and lowercase variants. Some registers
17410 also have mixed-case names. */
17411
17412 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
17413 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
17414 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
17415 #define REGSET(p,t) \
17416 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
17417 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
17418 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
17419 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
17420 #define REGSETH(p,t) \
17421 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
17422 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
17423 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
17424 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
17425 #define REGSET2(p,t) \
17426 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
17427 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
17428 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
17429 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
17430 #define SPLRBANK(base,bank,t) \
17431 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
17432 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
17433 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
17434 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
17435 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
17436 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
17437
17438 static const struct reg_entry reg_names[] =
17439 {
17440 /* ARM integer registers. */
17441 REGSET(r, RN), REGSET(R, RN),
17442
17443 /* ATPCS synonyms. */
17444 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
17445 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
17446 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
17447
17448 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
17449 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
17450 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
17451
17452 /* Well-known aliases. */
17453 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
17454 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
17455
17456 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
17457 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
17458
17459 /* Coprocessor numbers. */
17460 REGSET(p, CP), REGSET(P, CP),
17461
17462 /* Coprocessor register numbers. The "cr" variants are for backward
17463 compatibility. */
17464 REGSET(c, CN), REGSET(C, CN),
17465 REGSET(cr, CN), REGSET(CR, CN),
17466
17467 /* ARM banked registers. */
17468 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
17469 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
17470 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
17471 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
17472 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
17473 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
17474 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
17475
17476 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
17477 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
17478 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
17479 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
17480 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
17481 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
17482 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
17483 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
17484
17485 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
17486 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
17487 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
17488 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
17489 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
17490 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
17491 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
17492 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
17493 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
17494
17495 /* FPA registers. */
17496 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
17497 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
17498
17499 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
17500 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
17501
17502 /* VFP SP registers. */
17503 REGSET(s,VFS), REGSET(S,VFS),
17504 REGSETH(s,VFS), REGSETH(S,VFS),
17505
17506 /* VFP DP Registers. */
17507 REGSET(d,VFD), REGSET(D,VFD),
17508 /* Extra Neon DP registers. */
17509 REGSETH(d,VFD), REGSETH(D,VFD),
17510
17511 /* Neon QP registers. */
17512 REGSET2(q,NQ), REGSET2(Q,NQ),
17513
17514 /* VFP control registers. */
17515 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
17516 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
17517 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
17518 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
17519 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
17520 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
17521
17522 /* Maverick DSP coprocessor registers. */
17523 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
17524 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
17525
17526 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
17527 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
17528 REGDEF(dspsc,0,DSPSC),
17529
17530 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
17531 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
17532 REGDEF(DSPSC,0,DSPSC),
17533
17534 /* iWMMXt data registers - p0, c0-15. */
17535 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
17536
17537 /* iWMMXt control registers - p1, c0-3. */
17538 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
17539 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
17540 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
17541 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
17542
17543 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
17544 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
17545 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
17546 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
17547 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
17548
17549 /* XScale accumulator registers. */
17550 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
17551 };
17552 #undef REGDEF
17553 #undef REGNUM
17554 #undef REGSET
17555
17556 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
17557 within psr_required_here. */
17558 static const struct asm_psr psrs[] =
17559 {
17560 /* Backward compatibility notation. Note that "all" is no longer
17561 truly all possible PSR bits. */
17562 {"all", PSR_c | PSR_f},
17563 {"flg", PSR_f},
17564 {"ctl", PSR_c},
17565
17566 /* Individual flags. */
17567 {"f", PSR_f},
17568 {"c", PSR_c},
17569 {"x", PSR_x},
17570 {"s", PSR_s},
17571
17572 /* Combinations of flags. */
17573 {"fs", PSR_f | PSR_s},
17574 {"fx", PSR_f | PSR_x},
17575 {"fc", PSR_f | PSR_c},
17576 {"sf", PSR_s | PSR_f},
17577 {"sx", PSR_s | PSR_x},
17578 {"sc", PSR_s | PSR_c},
17579 {"xf", PSR_x | PSR_f},
17580 {"xs", PSR_x | PSR_s},
17581 {"xc", PSR_x | PSR_c},
17582 {"cf", PSR_c | PSR_f},
17583 {"cs", PSR_c | PSR_s},
17584 {"cx", PSR_c | PSR_x},
17585 {"fsx", PSR_f | PSR_s | PSR_x},
17586 {"fsc", PSR_f | PSR_s | PSR_c},
17587 {"fxs", PSR_f | PSR_x | PSR_s},
17588 {"fxc", PSR_f | PSR_x | PSR_c},
17589 {"fcs", PSR_f | PSR_c | PSR_s},
17590 {"fcx", PSR_f | PSR_c | PSR_x},
17591 {"sfx", PSR_s | PSR_f | PSR_x},
17592 {"sfc", PSR_s | PSR_f | PSR_c},
17593 {"sxf", PSR_s | PSR_x | PSR_f},
17594 {"sxc", PSR_s | PSR_x | PSR_c},
17595 {"scf", PSR_s | PSR_c | PSR_f},
17596 {"scx", PSR_s | PSR_c | PSR_x},
17597 {"xfs", PSR_x | PSR_f | PSR_s},
17598 {"xfc", PSR_x | PSR_f | PSR_c},
17599 {"xsf", PSR_x | PSR_s | PSR_f},
17600 {"xsc", PSR_x | PSR_s | PSR_c},
17601 {"xcf", PSR_x | PSR_c | PSR_f},
17602 {"xcs", PSR_x | PSR_c | PSR_s},
17603 {"cfs", PSR_c | PSR_f | PSR_s},
17604 {"cfx", PSR_c | PSR_f | PSR_x},
17605 {"csf", PSR_c | PSR_s | PSR_f},
17606 {"csx", PSR_c | PSR_s | PSR_x},
17607 {"cxf", PSR_c | PSR_x | PSR_f},
17608 {"cxs", PSR_c | PSR_x | PSR_s},
17609 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
17610 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
17611 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
17612 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
17613 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
17614 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
17615 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
17616 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
17617 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
17618 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
17619 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
17620 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
17621 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
17622 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
17623 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
17624 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
17625 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
17626 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
17627 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
17628 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
17629 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
17630 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
17631 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
17632 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
17633 };
17634
17635 /* Table of V7M psr names. */
17636 static const struct asm_psr v7m_psrs[] =
17637 {
17638 {"apsr", 0 }, {"APSR", 0 },
17639 {"iapsr", 1 }, {"IAPSR", 1 },
17640 {"eapsr", 2 }, {"EAPSR", 2 },
17641 {"psr", 3 }, {"PSR", 3 },
17642 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
17643 {"ipsr", 5 }, {"IPSR", 5 },
17644 {"epsr", 6 }, {"EPSR", 6 },
17645 {"iepsr", 7 }, {"IEPSR", 7 },
17646 {"msp", 8 }, {"MSP", 8 },
17647 {"psp", 9 }, {"PSP", 9 },
17648 {"primask", 16}, {"PRIMASK", 16},
17649 {"basepri", 17}, {"BASEPRI", 17},
17650 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
17651 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
17652 {"faultmask", 19}, {"FAULTMASK", 19},
17653 {"control", 20}, {"CONTROL", 20}
17654 };
17655
17656 /* Table of all shift-in-operand names. */
17657 static const struct asm_shift_name shift_names [] =
17658 {
17659 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
17660 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
17661 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
17662 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
17663 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
17664 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
17665 };
17666
17667 /* Table of all explicit relocation names. */
17668 #ifdef OBJ_ELF
17669 static struct reloc_entry reloc_names[] =
17670 {
17671 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
17672 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
17673 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
17674 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
17675 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
17676 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
17677 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
17678 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
17679 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
17680 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
17681 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
17682 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
17683 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
17684 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
17685 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
17686 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
17687 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
17688 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
17689 };
17690 #endif
17691
17692 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
17693 static const struct asm_cond conds[] =
17694 {
17695 {"eq", 0x0},
17696 {"ne", 0x1},
17697 {"cs", 0x2}, {"hs", 0x2},
17698 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
17699 {"mi", 0x4},
17700 {"pl", 0x5},
17701 {"vs", 0x6},
17702 {"vc", 0x7},
17703 {"hi", 0x8},
17704 {"ls", 0x9},
17705 {"ge", 0xa},
17706 {"lt", 0xb},
17707 {"gt", 0xc},
17708 {"le", 0xd},
17709 {"al", 0xe}
17710 };
17711
17712 #define UL_BARRIER(L,U,CODE,FEAT) \
17713 { L, CODE, ARM_FEATURE (FEAT, 0) }, \
17714 { U, CODE, ARM_FEATURE (FEAT, 0) }
17715
17716 static struct asm_barrier_opt barrier_opt_names[] =
17717 {
17718 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
17719 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
17720 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
17721 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
17722 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
17723 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
17724 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
17725 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
17726 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
17727 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
17728 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
17729 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
17730 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
17731 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
17732 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
17733 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
17734 };
17735
17736 #undef UL_BARRIER
17737
17738 /* Table of ARM-format instructions. */
17739
17740 /* Macros for gluing together operand strings. N.B. In all cases
17741 other than OPS0, the trailing OP_stop comes from default
17742 zero-initialization of the unspecified elements of the array. */
17743 #define OPS0() { OP_stop, }
17744 #define OPS1(a) { OP_##a, }
17745 #define OPS2(a,b) { OP_##a,OP_##b, }
17746 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17747 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17748 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17749 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17750
17751 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17752 This is useful when mixing operands for ARM and THUMB, i.e. using the
17753 MIX_ARM_THUMB_OPERANDS macro.
17754 In order to use these macros, prefix the number of operands with _
17755 e.g. _3. */
17756 #define OPS_1(a) { a, }
17757 #define OPS_2(a,b) { a,b, }
17758 #define OPS_3(a,b,c) { a,b,c, }
17759 #define OPS_4(a,b,c,d) { a,b,c,d, }
17760 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17761 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17762
17763 /* These macros abstract out the exact format of the mnemonic table and
17764 save some repeated characters. */
17765
17766 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
17767 #define TxCE(mnem, op, top, nops, ops, ae, te) \
17768 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
17769 THUMB_VARIANT, do_##ae, do_##te }
17770
17771 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17772 a T_MNEM_xyz enumerator. */
17773 #define TCE(mnem, aop, top, nops, ops, ae, te) \
17774 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
17775 #define tCE(mnem, aop, top, nops, ops, ae, te) \
17776 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17777
17778 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17779 infix after the third character. */
17780 #define TxC3(mnem, op, top, nops, ops, ae, te) \
17781 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
17782 THUMB_VARIANT, do_##ae, do_##te }
17783 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
17784 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
17785 THUMB_VARIANT, do_##ae, do_##te }
17786 #define TC3(mnem, aop, top, nops, ops, ae, te) \
17787 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
17788 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
17789 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
17790 #define tC3(mnem, aop, top, nops, ops, ae, te) \
17791 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17792 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
17793 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17794
17795 /* Mnemonic that cannot be conditionalized. The ARM condition-code
17796 field is still 0xE. Many of the Thumb variants can be executed
17797 conditionally, so this is checked separately. */
17798 #define TUE(mnem, op, top, nops, ops, ae, te) \
17799 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
17800 THUMB_VARIANT, do_##ae, do_##te }
17801
17802 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17803 condition code field. */
17804 #define TUF(mnem, op, top, nops, ops, ae, te) \
17805 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
17806 THUMB_VARIANT, do_##ae, do_##te }
17807
17808 /* ARM-only variants of all the above. */
17809 #define CE(mnem, op, nops, ops, ae) \
17810 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17811
17812 #define C3(mnem, op, nops, ops, ae) \
17813 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17814
17815 /* Legacy mnemonics that always have conditional infix after the third
17816 character. */
17817 #define CL(mnem, op, nops, ops, ae) \
17818 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17819 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17820
17821 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17822 #define cCE(mnem, op, nops, ops, ae) \
17823 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17824
17825 /* Legacy coprocessor instructions where conditional infix and conditional
17826 suffix are ambiguous. For consistency this includes all FPA instructions,
17827 not just the potentially ambiguous ones. */
17828 #define cCL(mnem, op, nops, ops, ae) \
17829 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17830 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17831
17832 /* Coprocessor, takes either a suffix or a position-3 infix
17833 (for an FPA corner case). */
17834 #define C3E(mnem, op, nops, ops, ae) \
17835 { mnem, OPS##nops ops, OT_csuf_or_in3, \
17836 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17837
17838 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
17839 { m1 #m2 m3, OPS##nops ops, \
17840 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17841 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17842
17843 #define CM(m1, m2, op, nops, ops, ae) \
17844 xCM_ (m1, , m2, op, nops, ops, ae), \
17845 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17846 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17847 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17848 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17849 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17850 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17851 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17852 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17853 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17854 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17855 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17856 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17857 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17858 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17859 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17860 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17861 xCM_ (m1, le, m2, op, nops, ops, ae), \
17862 xCM_ (m1, al, m2, op, nops, ops, ae)
17863
17864 #define UE(mnem, op, nops, ops, ae) \
17865 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17866
17867 #define UF(mnem, op, nops, ops, ae) \
17868 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17869
17870 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
17871 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17872 use the same encoding function for each. */
17873 #define NUF(mnem, op, nops, ops, enc) \
17874 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17875 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17876
17877 /* Neon data processing, version which indirects through neon_enc_tab for
17878 the various overloaded versions of opcodes. */
17879 #define nUF(mnem, op, nops, ops, enc) \
17880 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
17881 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17882
17883 /* Neon insn with conditional suffix for the ARM version, non-overloaded
17884 version. */
17885 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
17886 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
17887 THUMB_VARIANT, do_##enc, do_##enc }
17888
17889 #define NCE(mnem, op, nops, ops, enc) \
17890 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17891
17892 #define NCEF(mnem, op, nops, ops, enc) \
17893 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17894
17895 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
17896 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
17897 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
17898 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17899
17900 #define nCE(mnem, op, nops, ops, enc) \
17901 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17902
17903 #define nCEF(mnem, op, nops, ops, enc) \
17904 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17905
17906 #define do_0 0
17907
17908 static const struct asm_opcode insns[] =
17909 {
17910 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17911 #define THUMB_VARIANT &arm_ext_v4t
17912 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17913 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17914 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17915 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17916 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17917 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17918 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17919 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17920 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17921 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17922 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17923 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17924 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17925 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17926 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17927 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
17928
17929 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17930 for setting PSR flag bits. They are obsolete in V6 and do not
17931 have Thumb equivalents. */
17932 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17933 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17934 CL("tstp", 110f000, 2, (RR, SH), cmp),
17935 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17936 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17937 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17938 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17939 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17940 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17941
17942 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17943 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17944 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17945 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17946
17947 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
17948 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17949 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17950 OP_RRnpc),
17951 OP_ADDRGLDR),ldst, t_ldst),
17952 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17953
17954 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17955 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17956 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17957 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17958 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17959 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17960
17961 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17962 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17963 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17964 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
17965
17966 /* Pseudo ops. */
17967 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
17968 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
17969 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
17970
17971 /* Thumb-compatibility pseudo ops. */
17972 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17973 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17974 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17975 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17976 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17977 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17978 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17979 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17980 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17981 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17982 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17983 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
17984
17985 /* These may simplify to neg. */
17986 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17987 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
17988
17989 #undef THUMB_VARIANT
17990 #define THUMB_VARIANT & arm_ext_v6
17991
17992 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
17993
17994 /* V1 instructions with no Thumb analogue prior to V6T2. */
17995 #undef THUMB_VARIANT
17996 #define THUMB_VARIANT & arm_ext_v6t2
17997
17998 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17999 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18000 CL("teqp", 130f000, 2, (RR, SH), cmp),
18001
18002 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18003 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18004 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18005 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18006
18007 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18008 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18009
18010 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18011 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18012
18013 /* V1 instructions with no Thumb analogue at all. */
18014 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
18015 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18016
18017 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18018 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18019 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18020 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18021 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18022 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18023 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18024 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18025
18026 #undef ARM_VARIANT
18027 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18028 #undef THUMB_VARIANT
18029 #define THUMB_VARIANT & arm_ext_v4t
18030
18031 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18032 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18033
18034 #undef THUMB_VARIANT
18035 #define THUMB_VARIANT & arm_ext_v6t2
18036
18037 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18038 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18039
18040 /* Generic coprocessor instructions. */
18041 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18042 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18043 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18044 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18045 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18046 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18047 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
18048
18049 #undef ARM_VARIANT
18050 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18051
18052 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18053 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18054
18055 #undef ARM_VARIANT
18056 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18057 #undef THUMB_VARIANT
18058 #define THUMB_VARIANT & arm_ext_msr
18059
18060 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18061 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
18062
18063 #undef ARM_VARIANT
18064 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18065 #undef THUMB_VARIANT
18066 #define THUMB_VARIANT & arm_ext_v6t2
18067
18068 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18069 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18070 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18071 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18072 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18073 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18074 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18075 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18076
18077 #undef ARM_VARIANT
18078 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18079 #undef THUMB_VARIANT
18080 #define THUMB_VARIANT & arm_ext_v4t
18081
18082 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18083 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18084 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18085 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18086 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18087 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18088
18089 #undef ARM_VARIANT
18090 #define ARM_VARIANT & arm_ext_v4t_5
18091
18092 /* ARM Architecture 4T. */
18093 /* Note: bx (and blx) are required on V5, even if the processor does
18094 not support Thumb. */
18095 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
18096
18097 #undef ARM_VARIANT
18098 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18099 #undef THUMB_VARIANT
18100 #define THUMB_VARIANT & arm_ext_v5t
18101
18102 /* Note: blx has 2 variants; the .value coded here is for
18103 BLX(2). Only this variant has conditional execution. */
18104 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18105 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
18106
18107 #undef THUMB_VARIANT
18108 #define THUMB_VARIANT & arm_ext_v6t2
18109
18110 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18111 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18112 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18113 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18114 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18115 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18116 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18117 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18118
18119 #undef ARM_VARIANT
18120 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18121 #undef THUMB_VARIANT
18122 #define THUMB_VARIANT &arm_ext_v5exp
18123
18124 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18125 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18126 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18127 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18128
18129 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18130 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18131
18132 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18133 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18134 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18135 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18136
18137 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18138 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18139 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18140 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18141
18142 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18143 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18144
18145 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18146 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18147 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18148 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18149
18150 #undef ARM_VARIANT
18151 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18152 #undef THUMB_VARIANT
18153 #define THUMB_VARIANT &arm_ext_v6t2
18154
18155 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
18156 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18157 ldrd, t_ldstd),
18158 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18159 ADDRGLDRS), ldrd, t_ldstd),
18160
18161 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18162 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18163
18164 #undef ARM_VARIANT
18165 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18166
18167 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
18168
18169 #undef ARM_VARIANT
18170 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18171 #undef THUMB_VARIANT
18172 #define THUMB_VARIANT & arm_ext_v6
18173
18174 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18175 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18176 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18177 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18178 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18179 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18180 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18181 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18182 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18183 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
18184
18185 #undef THUMB_VARIANT
18186 #define THUMB_VARIANT & arm_ext_v6t2
18187
18188 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18189 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18190 strex, t_strex),
18191 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18192 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18193
18194 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18195 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
18196
18197 /* ARM V6 not included in V7M. */
18198 #undef THUMB_VARIANT
18199 #define THUMB_VARIANT & arm_ext_v6_notm
18200 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18201 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18202 UF(rfeib, 9900a00, 1, (RRw), rfe),
18203 UF(rfeda, 8100a00, 1, (RRw), rfe),
18204 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18205 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
18206 UF(rfefa, 8100a00, 1, (RRw), rfe),
18207 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18208 UF(rfeed, 9900a00, 1, (RRw), rfe),
18209 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18210 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18211 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18212 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
18213 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
18214 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
18215 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
18216 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
18217 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
18218
18219 /* ARM V6 not included in V7M (eg. integer SIMD). */
18220 #undef THUMB_VARIANT
18221 #define THUMB_VARIANT & arm_ext_v6_dsp
18222 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18223 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18224 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18225 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18226 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18227 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18228 /* Old name for QASX. */
18229 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18230 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18231 /* Old name for QSAX. */
18232 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18233 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18234 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18235 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18236 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18237 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18238 /* Old name for SASX. */
18239 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18240 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18241 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18242 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18243 /* Old name for SHASX. */
18244 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18245 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18246 /* Old name for SHSAX. */
18247 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18248 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18249 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18250 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18251 /* Old name for SSAX. */
18252 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18253 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18254 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18255 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18256 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18257 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18258 /* Old name for UASX. */
18259 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18260 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18261 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18262 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18263 /* Old name for UHASX. */
18264 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18265 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18266 /* Old name for UHSAX. */
18267 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18268 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18269 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18270 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18271 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18272 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18273 /* Old name for UQASX. */
18274 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18275 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18276 /* Old name for UQSAX. */
18277 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18278 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18279 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18280 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18281 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18282 /* Old name for USAX. */
18283 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18284 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18285 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18286 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18287 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18288 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18289 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18290 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18291 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18292 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18293 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18294 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18295 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18296 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18297 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18298 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18299 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18300 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18301 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18302 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18303 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18304 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18305 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18306 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18307 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18308 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18309 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18310 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18311 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18312 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18313 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18314 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18315 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18316 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
18317
18318 #undef ARM_VARIANT
18319 #define ARM_VARIANT & arm_ext_v6k
18320 #undef THUMB_VARIANT
18321 #define THUMB_VARIANT & arm_ext_v6k
18322
18323 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18324 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18325 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18326 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
18327
18328 #undef THUMB_VARIANT
18329 #define THUMB_VARIANT & arm_ext_v6_notm
18330 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
18331 ldrexd, t_ldrexd),
18332 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
18333 RRnpcb), strexd, t_strexd),
18334
18335 #undef THUMB_VARIANT
18336 #define THUMB_VARIANT & arm_ext_v6t2
18337 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
18338 rd_rn, rd_rn),
18339 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
18340 rd_rn, rd_rn),
18341 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18342 strex, t_strexbh),
18343 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18344 strex, t_strexbh),
18345 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
18346
18347 #undef ARM_VARIANT
18348 #define ARM_VARIANT & arm_ext_sec
18349 #undef THUMB_VARIANT
18350 #define THUMB_VARIANT & arm_ext_sec
18351
18352 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
18353
18354 #undef ARM_VARIANT
18355 #define ARM_VARIANT & arm_ext_virt
18356 #undef THUMB_VARIANT
18357 #define THUMB_VARIANT & arm_ext_virt
18358
18359 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
18360 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
18361
18362 #undef ARM_VARIANT
18363 #define ARM_VARIANT & arm_ext_v6t2
18364 #undef THUMB_VARIANT
18365 #define THUMB_VARIANT & arm_ext_v6t2
18366
18367 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
18368 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
18369 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18370 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18371
18372 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18373 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
18374 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
18375 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
18376
18377 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18378 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18379 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18380 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18381
18382 /* Thumb-only instructions. */
18383 #undef ARM_VARIANT
18384 #define ARM_VARIANT NULL
18385 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
18386 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
18387
18388 /* ARM does not really have an IT instruction, so always allow it.
18389 The opcode is copied from Thumb in order to allow warnings in
18390 -mimplicit-it=[never | arm] modes. */
18391 #undef ARM_VARIANT
18392 #define ARM_VARIANT & arm_ext_v1
18393
18394 TUE("it", bf08, bf08, 1, (COND), it, t_it),
18395 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
18396 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
18397 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
18398 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
18399 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
18400 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
18401 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
18402 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
18403 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
18404 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
18405 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
18406 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
18407 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
18408 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
18409 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
18410 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
18411 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
18412
18413 /* Thumb2 only instructions. */
18414 #undef ARM_VARIANT
18415 #define ARM_VARIANT NULL
18416
18417 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18418 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18419 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
18420 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
18421 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
18422 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
18423
18424 /* Hardware division instructions. */
18425 #undef ARM_VARIANT
18426 #define ARM_VARIANT & arm_ext_adiv
18427 #undef THUMB_VARIANT
18428 #define THUMB_VARIANT & arm_ext_div
18429
18430 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
18431 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
18432
18433 /* ARM V6M/V7 instructions. */
18434 #undef ARM_VARIANT
18435 #define ARM_VARIANT & arm_ext_barrier
18436 #undef THUMB_VARIANT
18437 #define THUMB_VARIANT & arm_ext_barrier
18438
18439 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
18440 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
18441 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
18442
18443 /* ARM V7 instructions. */
18444 #undef ARM_VARIANT
18445 #define ARM_VARIANT & arm_ext_v7
18446 #undef THUMB_VARIANT
18447 #define THUMB_VARIANT & arm_ext_v7
18448
18449 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
18450 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
18451
18452 #undef ARM_VARIANT
18453 #define ARM_VARIANT & arm_ext_mp
18454 #undef THUMB_VARIANT
18455 #define THUMB_VARIANT & arm_ext_mp
18456
18457 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
18458
18459 /* AArchv8 instructions. */
18460 #undef ARM_VARIANT
18461 #define ARM_VARIANT & arm_ext_v8
18462 #undef THUMB_VARIANT
18463 #define THUMB_VARIANT & arm_ext_v8
18464
18465 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
18466 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
18467 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18468 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
18469 ldrexd, t_ldrexd),
18470 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
18471 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18472 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
18473 stlex, t_stlex),
18474 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
18475 strexd, t_strexd),
18476 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
18477 stlex, t_stlex),
18478 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
18479 stlex, t_stlex),
18480 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18481 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18482 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
18483 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18484 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18485 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
18486
18487 /* ARMv8 T32 only. */
18488 #undef ARM_VARIANT
18489 #define ARM_VARIANT NULL
18490 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
18491 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
18492 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
18493
18494 /* FP for ARMv8. */
18495 #undef ARM_VARIANT
18496 #define ARM_VARIANT & fpu_vfp_ext_armv8
18497 #undef THUMB_VARIANT
18498 #define THUMB_VARIANT & fpu_vfp_ext_armv8
18499
18500 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
18501 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
18502 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
18503 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
18504 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
18505 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
18506 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
18507 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
18508 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
18509 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
18510 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
18511 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
18512 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
18513 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
18514 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
18515 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
18516 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
18517
18518 /* Crypto v1 extensions. */
18519 #undef ARM_VARIANT
18520 #define ARM_VARIANT & fpu_crypto_ext_armv8
18521 #undef THUMB_VARIANT
18522 #define THUMB_VARIANT & fpu_crypto_ext_armv8
18523
18524 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
18525 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
18526 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
18527 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
18528 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
18529 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
18530 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
18531 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
18532 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
18533 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
18534 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
18535 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
18536 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
18537 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
18538
18539 #undef ARM_VARIANT
18540 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
18541 #undef THUMB_VARIANT
18542 #define THUMB_VARIANT NULL
18543
18544 cCE("wfs", e200110, 1, (RR), rd),
18545 cCE("rfs", e300110, 1, (RR), rd),
18546 cCE("wfc", e400110, 1, (RR), rd),
18547 cCE("rfc", e500110, 1, (RR), rd),
18548
18549 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
18550 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
18551 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
18552 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
18553
18554 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
18555 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
18556 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
18557 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
18558
18559 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
18560 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
18561 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
18562 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
18563 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
18564 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
18565 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
18566 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
18567 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
18568 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
18569 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
18570 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
18571
18572 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
18573 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
18574 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
18575 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
18576 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
18577 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
18578 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
18579 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
18580 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
18581 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
18582 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
18583 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
18584
18585 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
18586 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
18587 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
18588 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
18589 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
18590 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
18591 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
18592 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
18593 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
18594 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
18595 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
18596 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
18597
18598 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
18599 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
18600 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
18601 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
18602 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
18603 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
18604 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
18605 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
18606 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
18607 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
18608 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
18609 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
18610
18611 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
18612 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
18613 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
18614 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
18615 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
18616 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
18617 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
18618 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
18619 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
18620 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
18621 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
18622 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
18623
18624 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
18625 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
18626 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
18627 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
18628 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
18629 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
18630 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
18631 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
18632 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
18633 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
18634 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
18635 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
18636
18637 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
18638 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
18639 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
18640 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
18641 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
18642 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
18643 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
18644 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
18645 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
18646 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
18647 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
18648 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
18649
18650 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
18651 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
18652 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
18653 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
18654 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
18655 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
18656 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
18657 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
18658 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
18659 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
18660 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
18661 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
18662
18663 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
18664 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
18665 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
18666 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
18667 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
18668 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
18669 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
18670 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
18671 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
18672 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
18673 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
18674 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
18675
18676 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
18677 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
18678 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
18679 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
18680 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
18681 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
18682 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
18683 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
18684 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
18685 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
18686 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
18687 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
18688
18689 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
18690 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
18691 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
18692 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
18693 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
18694 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
18695 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
18696 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
18697 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
18698 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
18699 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
18700 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
18701
18702 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
18703 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
18704 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
18705 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
18706 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
18707 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
18708 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
18709 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
18710 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
18711 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
18712 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
18713 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
18714
18715 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
18716 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
18717 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
18718 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
18719 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
18720 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
18721 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
18722 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
18723 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
18724 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
18725 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
18726 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
18727
18728 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
18729 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
18730 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
18731 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
18732 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
18733 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
18734 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
18735 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
18736 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
18737 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
18738 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
18739 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
18740
18741 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
18742 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
18743 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
18744 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
18745 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
18746 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
18747 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
18748 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
18749 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
18750 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
18751 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
18752 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
18753
18754 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
18755 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
18756 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
18757 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
18758 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
18759 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
18760 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
18761 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
18762 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
18763 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
18764 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
18765 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
18766
18767 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
18768 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
18769 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
18770 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
18771 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
18772 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18773 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18774 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18775 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
18776 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
18777 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
18778 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
18779
18780 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
18781 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
18782 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
18783 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
18784 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
18785 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18786 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18787 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18788 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
18789 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
18790 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
18791 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
18792
18793 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
18794 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
18795 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
18796 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
18797 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
18798 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18799 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18800 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18801 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
18802 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
18803 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
18804 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
18805
18806 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
18807 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
18808 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
18809 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
18810 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
18811 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18812 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18813 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18814 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
18815 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
18816 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
18817 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
18818
18819 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
18820 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
18821 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
18822 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
18823 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18824 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18825 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18826 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18827 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18828 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18829 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18830 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18831
18832 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18833 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18834 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18835 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18836 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18837 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18838 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18839 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18840 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18841 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18842 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18843 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18844
18845 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18846 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18847 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18848 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18849 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18850 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18851 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18852 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18853 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18854 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18855 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18856 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18857
18858 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18859 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18860 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18861 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18862 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18863 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18864 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18865 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18866 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18867 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18868 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18869 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18870
18871 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18872 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18873 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18874 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18875 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18876 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18877 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18878 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18879 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18880 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18881 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18882 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18883
18884 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18885 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18886 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18887 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18888 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18889 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18890 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18891 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18892 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18893 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18894 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18895 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18896
18897 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18898 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18899 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18900 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18901 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18902 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18903 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18904 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18905 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18906 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18907 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18908 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18909
18910 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18911 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18912 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18913 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18914 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18915 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18916 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18917 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18918 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18919 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18920 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18921 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18922
18923 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18924 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18925 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18926 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18927 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18928 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18929 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18930 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18931 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18932 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18933 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18934 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18935
18936 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18937 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18938 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18939 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18940
18941 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18942 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18943 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18944 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18945 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18946 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18947 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18948 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18949 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18950 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18951 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18952 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
18953
18954 /* The implementation of the FIX instruction is broken on some
18955 assemblers, in that it accepts a precision specifier as well as a
18956 rounding specifier, despite the fact that this is meaningless.
18957 To be more compatible, we accept it as well, though of course it
18958 does not set any bits. */
18959 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18960 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18961 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18962 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18963 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18964 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18965 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18966 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18967 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18968 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18969 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18970 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18971 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
18972
18973 /* Instructions that were new with the real FPA, call them V2. */
18974 #undef ARM_VARIANT
18975 #define ARM_VARIANT & fpu_fpa_ext_v2
18976
18977 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18978 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18979 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18980 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18981 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18982 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18983
18984 #undef ARM_VARIANT
18985 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18986
18987 /* Moves and type conversions. */
18988 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18989 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18990 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18991 cCE("fmstat", ef1fa10, 0, (), noargs),
18992 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18993 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
18994 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18995 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18996 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18997 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18998 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18999 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19000 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19001 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
19002
19003 /* Memory operations. */
19004 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19005 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19006 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19007 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19008 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19009 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19010 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19011 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19012 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19013 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19014 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19015 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19016 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19017 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19018 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19019 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19020 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19021 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19022
19023 /* Monadic operations. */
19024 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19025 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19026 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
19027
19028 /* Dyadic operations. */
19029 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19030 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19031 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19032 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19033 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19034 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19035 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19036 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19037 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19038
19039 /* Comparisons. */
19040 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19041 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19042 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19043 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
19044
19045 /* Double precision load/store are still present on single precision
19046 implementations. */
19047 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19048 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19049 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19050 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19051 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19052 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19053 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19054 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19055 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19056 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19057
19058 #undef ARM_VARIANT
19059 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19060
19061 /* Moves and type conversions. */
19062 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19063 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19064 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19065 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19066 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19067 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19068 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19069 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19070 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19071 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19072 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19073 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19074 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19075
19076 /* Monadic operations. */
19077 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19078 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19079 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19080
19081 /* Dyadic operations. */
19082 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19083 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19084 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19085 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19086 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19087 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19088 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19089 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19090 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19091
19092 /* Comparisons. */
19093 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19094 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19095 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19096 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
19097
19098 #undef ARM_VARIANT
19099 #define ARM_VARIANT & fpu_vfp_ext_v2
19100
19101 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19102 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19103 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19104 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
19105
19106 /* Instructions which may belong to either the Neon or VFP instruction sets.
19107 Individual encoder functions perform additional architecture checks. */
19108 #undef ARM_VARIANT
19109 #define ARM_VARIANT & fpu_vfp_ext_v1xd
19110 #undef THUMB_VARIANT
19111 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
19112
19113 /* These mnemonics are unique to VFP. */
19114 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19115 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
19116 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19117 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19118 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19119 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
19120 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
19121 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19122 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19123 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19124
19125 /* Mnemonics shared by Neon and VFP. */
19126 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19127 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19128 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19129
19130 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19131 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19132
19133 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19134 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19135
19136 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19137 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19138 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19139 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19140 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19141 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19142 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19143 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19144
19145 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
19146 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
19147 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19148 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
19149
19150
19151 /* NOTE: All VMOV encoding is special-cased! */
19152 NCE(vmov, 0, 1, (VMOV), neon_mov),
19153 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19154
19155 #undef THUMB_VARIANT
19156 #define THUMB_VARIANT & fpu_neon_ext_v1
19157 #undef ARM_VARIANT
19158 #define ARM_VARIANT & fpu_neon_ext_v1
19159
19160 /* Data processing with three registers of the same length. */
19161 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19162 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19163 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19164 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19165 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19166 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19167 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19168 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19169 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19170 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19171 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19172 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19173 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19174 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19175 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19176 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19177 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19178 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19179 /* If not immediate, fall back to neon_dyadic_i64_su.
19180 shl_imm should accept I8 I16 I32 I64,
19181 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
19182 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19183 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19184 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19185 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
19186 /* Logic ops, types optional & ignored. */
19187 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19188 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19189 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19190 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19191 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19192 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19193 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19194 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19195 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19196 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
19197 /* Bitfield ops, untyped. */
19198 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19199 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19200 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19201 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19202 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19203 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19204 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
19205 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19206 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19207 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19208 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19209 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19210 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19211 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19212 back to neon_dyadic_if_su. */
19213 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19214 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19215 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19216 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19217 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19218 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19219 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19220 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19221 /* Comparison. Type I8 I16 I32 F32. */
19222 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19223 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
19224 /* As above, D registers only. */
19225 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19226 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19227 /* Int and float variants, signedness unimportant. */
19228 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19229 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19230 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
19231 /* Add/sub take types I8 I16 I32 I64 F32. */
19232 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19233 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19234 /* vtst takes sizes 8, 16, 32. */
19235 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19236 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19237 /* VMUL takes I8 I16 I32 F32 P8. */
19238 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
19239 /* VQD{R}MULH takes S16 S32. */
19240 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19241 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19242 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19243 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19244 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19245 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19246 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19247 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19248 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19249 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19250 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19251 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19252 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19253 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19254 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19255 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19256
19257 /* Two address, int/float. Types S8 S16 S32 F32. */
19258 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
19259 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19260
19261 /* Data processing with two registers and a shift amount. */
19262 /* Right shifts, and variants with rounding.
19263 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19264 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19265 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19266 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19267 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19268 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19269 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19270 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19271 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19272 /* Shift and insert. Sizes accepted 8 16 32 64. */
19273 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19274 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19275 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19276 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19277 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19278 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19279 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19280 /* Right shift immediate, saturating & narrowing, with rounding variants.
19281 Types accepted S16 S32 S64 U16 U32 U64. */
19282 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19283 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19284 /* As above, unsigned. Types accepted S16 S32 S64. */
19285 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19286 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19287 /* Right shift narrowing. Types accepted I16 I32 I64. */
19288 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19289 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19290 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
19291 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
19292 /* CVT with optional immediate for fixed-point variant. */
19293 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
19294
19295 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19296 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
19297
19298 /* Data processing, three registers of different lengths. */
19299 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19300 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19301 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19302 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19303 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19304 /* If not scalar, fall back to neon_dyadic_long.
19305 Vector types as above, scalar types S16 S32 U16 U32. */
19306 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19307 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19308 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
19309 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19310 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19311 /* Dyadic, narrowing insns. Types I16 I32 I64. */
19312 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19313 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19314 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19315 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19316 /* Saturating doubling multiplies. Types S16 S32. */
19317 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19318 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19319 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19320 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
19321 S16 S32 U16 U32. */
19322 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
19323
19324 /* Extract. Size 8. */
19325 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
19326 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
19327
19328 /* Two registers, miscellaneous. */
19329 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
19330 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
19331 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
19332 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
19333 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
19334 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
19335 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
19336 /* Vector replicate. Sizes 8 16 32. */
19337 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
19338 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
19339 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
19340 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
19341 /* VMOVN. Types I16 I32 I64. */
19342 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
19343 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
19344 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
19345 /* VQMOVUN. Types S16 S32 S64. */
19346 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
19347 /* VZIP / VUZP. Sizes 8 16 32. */
19348 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
19349 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
19350 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
19351 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
19352 /* VQABS / VQNEG. Types S8 S16 S32. */
19353 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19354 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
19355 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19356 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
19357 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
19358 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
19359 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
19360 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
19361 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
19362 /* Reciprocal estimates. Types U32 F32. */
19363 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
19364 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
19365 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
19366 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
19367 /* VCLS. Types S8 S16 S32. */
19368 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
19369 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
19370 /* VCLZ. Types I8 I16 I32. */
19371 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
19372 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
19373 /* VCNT. Size 8. */
19374 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
19375 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
19376 /* Two address, untyped. */
19377 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
19378 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
19379 /* VTRN. Sizes 8 16 32. */
19380 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
19381 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
19382
19383 /* Table lookup. Size 8. */
19384 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19385 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19386
19387 #undef THUMB_VARIANT
19388 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
19389 #undef ARM_VARIANT
19390 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
19391
19392 /* Neon element/structure load/store. */
19393 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19394 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19395 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19396 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19397 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19398 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19399 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19400 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19401
19402 #undef THUMB_VARIANT
19403 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
19404 #undef ARM_VARIANT
19405 #define ARM_VARIANT &fpu_vfp_ext_v3xd
19406 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
19407 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19408 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19409 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19410 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19411 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19412 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19413 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19414 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19415
19416 #undef THUMB_VARIANT
19417 #define THUMB_VARIANT & fpu_vfp_ext_v3
19418 #undef ARM_VARIANT
19419 #define ARM_VARIANT & fpu_vfp_ext_v3
19420
19421 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
19422 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19423 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19424 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19425 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19426 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19427 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19428 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
19429 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
19430
19431 #undef ARM_VARIANT
19432 #define ARM_VARIANT &fpu_vfp_ext_fma
19433 #undef THUMB_VARIANT
19434 #define THUMB_VARIANT &fpu_vfp_ext_fma
19435 /* Mnemonics shared by Neon and VFP. These are included in the
19436 VFP FMA variant; NEON and VFP FMA always includes the NEON
19437 FMA instructions. */
19438 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19439 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
19440 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
19441 the v form should always be used. */
19442 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19443 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19444 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19445 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19446 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19447 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19448
19449 #undef THUMB_VARIANT
19450 #undef ARM_VARIANT
19451 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
19452
19453 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19454 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19455 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19456 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19457 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19458 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
19459 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
19460 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
19461
19462 #undef ARM_VARIANT
19463 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
19464
19465 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
19466 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
19467 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
19468 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
19469 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
19470 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
19471 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
19472 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
19473 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
19474 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19475 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19476 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
19477 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19478 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19479 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
19480 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19481 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19482 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
19483 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
19484 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
19485 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19486 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19487 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19488 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19489 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19490 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
19491 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
19492 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
19493 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
19494 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
19495 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
19496 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
19497 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
19498 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
19499 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
19500 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
19501 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
19502 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19503 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19504 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19505 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19506 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19507 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19508 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19509 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19510 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19511 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
19512 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19513 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19514 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19515 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19516 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19517 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19518 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19519 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19520 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19521 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19522 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19523 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19524 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19525 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19526 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19527 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19528 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19529 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19530 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19531 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19532 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19533 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19534 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19535 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19536 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19537 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19538 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19539 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19540 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19541 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19542 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19543 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19544 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19545 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19546 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19547 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19548 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19549 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19550 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19551 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19552 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19553 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
19554 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19555 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19556 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19557 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19558 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19559 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19560 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19561 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19562 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19563 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19564 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19565 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19566 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19567 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19568 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19569 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19570 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19571 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19572 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19573 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19574 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19575 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
19576 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19577 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19578 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19579 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19580 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19581 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19582 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19583 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19584 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19585 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19586 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19587 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19588 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19589 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19590 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19591 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19592 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
19593 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
19594 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19595 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
19596 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
19597 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
19598 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19599 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19600 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19601 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19602 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19603 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19604 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19605 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19606 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19607 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
19608 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
19609 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
19610 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
19611 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
19612 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
19613 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19614 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19615 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19616 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
19617 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
19618 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
19619 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
19620 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
19621 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
19622 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19623 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19624 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19625 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19626 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
19627
19628 #undef ARM_VARIANT
19629 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
19630
19631 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
19632 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
19633 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
19634 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
19635 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
19636 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
19637 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19638 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19639 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19640 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19641 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19642 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19643 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19644 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19645 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19646 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19647 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19648 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19649 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19650 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19651 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
19652 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19653 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19654 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19655 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19656 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19657 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19658 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19659 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19660 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19661 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19662 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19663 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19664 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19665 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19666 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19667 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19668 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19669 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19670 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19671 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19672 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19673 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19674 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19675 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19676 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19677 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19678 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19679 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19680 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19681 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19682 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19683 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19684 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19685 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19686 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19687 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
19688
19689 #undef ARM_VARIANT
19690 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
19691
19692 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19693 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19694 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19695 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19696 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19697 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19698 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19699 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19700 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
19701 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
19702 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
19703 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
19704 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
19705 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
19706 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
19707 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
19708 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
19709 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
19710 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
19711 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
19712 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
19713 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
19714 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
19715 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
19716 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
19717 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
19718 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
19719 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
19720 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
19721 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
19722 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
19723 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
19724 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
19725 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
19726 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
19727 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
19728 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
19729 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
19730 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
19731 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
19732 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
19733 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
19734 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
19735 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
19736 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
19737 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
19738 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
19739 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
19740 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
19741 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
19742 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
19743 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
19744 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
19745 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
19746 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
19747 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
19748 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
19749 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
19750 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
19751 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
19752 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
19753 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
19754 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
19755 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
19756 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19757 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19758 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19759 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19760 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19761 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19762 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19763 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19764 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19765 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19766 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19767 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19768 };
19769 #undef ARM_VARIANT
19770 #undef THUMB_VARIANT
19771 #undef TCE
19772 #undef TUE
19773 #undef TUF
19774 #undef TCC
19775 #undef cCE
19776 #undef cCL
19777 #undef C3E
19778 #undef CE
19779 #undef CM
19780 #undef UE
19781 #undef UF
19782 #undef UT
19783 #undef NUF
19784 #undef nUF
19785 #undef NCE
19786 #undef nCE
19787 #undef OPS0
19788 #undef OPS1
19789 #undef OPS2
19790 #undef OPS3
19791 #undef OPS4
19792 #undef OPS5
19793 #undef OPS6
19794 #undef do_0
19795 \f
19796 /* MD interface: bits in the object file. */
19797
19798 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
19799 for use in the a.out file, and stores them in the array pointed to by buf.
19800 This knows about the endian-ness of the target machine and does
19801 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
19802 2 (short) and 4 (long) Floating numbers are put out as a series of
19803 LITTLENUMS (shorts, here at least). */
19804
19805 void
19806 md_number_to_chars (char * buf, valueT val, int n)
19807 {
19808 if (target_big_endian)
19809 number_to_chars_bigendian (buf, val, n);
19810 else
19811 number_to_chars_littleendian (buf, val, n);
19812 }
19813
19814 static valueT
19815 md_chars_to_number (char * buf, int n)
19816 {
19817 valueT result = 0;
19818 unsigned char * where = (unsigned char *) buf;
19819
19820 if (target_big_endian)
19821 {
19822 while (n--)
19823 {
19824 result <<= 8;
19825 result |= (*where++ & 255);
19826 }
19827 }
19828 else
19829 {
19830 while (n--)
19831 {
19832 result <<= 8;
19833 result |= (where[n] & 255);
19834 }
19835 }
19836
19837 return result;
19838 }
19839
19840 /* MD interface: Sections. */
19841
19842 /* Calculate the maximum variable size (i.e., excluding fr_fix)
19843 that an rs_machine_dependent frag may reach. */
19844
19845 unsigned int
19846 arm_frag_max_var (fragS *fragp)
19847 {
19848 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19849 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19850
19851 Note that we generate relaxable instructions even for cases that don't
19852 really need it, like an immediate that's a trivial constant. So we're
19853 overestimating the instruction size for some of those cases. Rather
19854 than putting more intelligence here, it would probably be better to
19855 avoid generating a relaxation frag in the first place when it can be
19856 determined up front that a short instruction will suffice. */
19857
19858 gas_assert (fragp->fr_type == rs_machine_dependent);
19859 return INSN_SIZE;
19860 }
19861
19862 /* Estimate the size of a frag before relaxing. Assume everything fits in
19863 2 bytes. */
19864
19865 int
19866 md_estimate_size_before_relax (fragS * fragp,
19867 segT segtype ATTRIBUTE_UNUSED)
19868 {
19869 fragp->fr_var = 2;
19870 return 2;
19871 }
19872
19873 /* Convert a machine dependent frag. */
19874
19875 void
19876 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19877 {
19878 unsigned long insn;
19879 unsigned long old_op;
19880 char *buf;
19881 expressionS exp;
19882 fixS *fixp;
19883 int reloc_type;
19884 int pc_rel;
19885 int opcode;
19886
19887 buf = fragp->fr_literal + fragp->fr_fix;
19888
19889 old_op = bfd_get_16(abfd, buf);
19890 if (fragp->fr_symbol)
19891 {
19892 exp.X_op = O_symbol;
19893 exp.X_add_symbol = fragp->fr_symbol;
19894 }
19895 else
19896 {
19897 exp.X_op = O_constant;
19898 }
19899 exp.X_add_number = fragp->fr_offset;
19900 opcode = fragp->fr_subtype;
19901 switch (opcode)
19902 {
19903 case T_MNEM_ldr_pc:
19904 case T_MNEM_ldr_pc2:
19905 case T_MNEM_ldr_sp:
19906 case T_MNEM_str_sp:
19907 case T_MNEM_ldr:
19908 case T_MNEM_ldrb:
19909 case T_MNEM_ldrh:
19910 case T_MNEM_str:
19911 case T_MNEM_strb:
19912 case T_MNEM_strh:
19913 if (fragp->fr_var == 4)
19914 {
19915 insn = THUMB_OP32 (opcode);
19916 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19917 {
19918 insn |= (old_op & 0x700) << 4;
19919 }
19920 else
19921 {
19922 insn |= (old_op & 7) << 12;
19923 insn |= (old_op & 0x38) << 13;
19924 }
19925 insn |= 0x00000c00;
19926 put_thumb32_insn (buf, insn);
19927 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19928 }
19929 else
19930 {
19931 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19932 }
19933 pc_rel = (opcode == T_MNEM_ldr_pc2);
19934 break;
19935 case T_MNEM_adr:
19936 if (fragp->fr_var == 4)
19937 {
19938 insn = THUMB_OP32 (opcode);
19939 insn |= (old_op & 0xf0) << 4;
19940 put_thumb32_insn (buf, insn);
19941 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19942 }
19943 else
19944 {
19945 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19946 exp.X_add_number -= 4;
19947 }
19948 pc_rel = 1;
19949 break;
19950 case T_MNEM_mov:
19951 case T_MNEM_movs:
19952 case T_MNEM_cmp:
19953 case T_MNEM_cmn:
19954 if (fragp->fr_var == 4)
19955 {
19956 int r0off = (opcode == T_MNEM_mov
19957 || opcode == T_MNEM_movs) ? 0 : 8;
19958 insn = THUMB_OP32 (opcode);
19959 insn = (insn & 0xe1ffffff) | 0x10000000;
19960 insn |= (old_op & 0x700) << r0off;
19961 put_thumb32_insn (buf, insn);
19962 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19963 }
19964 else
19965 {
19966 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19967 }
19968 pc_rel = 0;
19969 break;
19970 case T_MNEM_b:
19971 if (fragp->fr_var == 4)
19972 {
19973 insn = THUMB_OP32(opcode);
19974 put_thumb32_insn (buf, insn);
19975 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19976 }
19977 else
19978 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19979 pc_rel = 1;
19980 break;
19981 case T_MNEM_bcond:
19982 if (fragp->fr_var == 4)
19983 {
19984 insn = THUMB_OP32(opcode);
19985 insn |= (old_op & 0xf00) << 14;
19986 put_thumb32_insn (buf, insn);
19987 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19988 }
19989 else
19990 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19991 pc_rel = 1;
19992 break;
19993 case T_MNEM_add_sp:
19994 case T_MNEM_add_pc:
19995 case T_MNEM_inc_sp:
19996 case T_MNEM_dec_sp:
19997 if (fragp->fr_var == 4)
19998 {
19999 /* ??? Choose between add and addw. */
20000 insn = THUMB_OP32 (opcode);
20001 insn |= (old_op & 0xf0) << 4;
20002 put_thumb32_insn (buf, insn);
20003 if (opcode == T_MNEM_add_pc)
20004 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20005 else
20006 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20007 }
20008 else
20009 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20010 pc_rel = 0;
20011 break;
20012
20013 case T_MNEM_addi:
20014 case T_MNEM_addis:
20015 case T_MNEM_subi:
20016 case T_MNEM_subis:
20017 if (fragp->fr_var == 4)
20018 {
20019 insn = THUMB_OP32 (opcode);
20020 insn |= (old_op & 0xf0) << 4;
20021 insn |= (old_op & 0xf) << 16;
20022 put_thumb32_insn (buf, insn);
20023 if (insn & (1 << 20))
20024 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20025 else
20026 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20027 }
20028 else
20029 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20030 pc_rel = 0;
20031 break;
20032 default:
20033 abort ();
20034 }
20035 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
20036 (enum bfd_reloc_code_real) reloc_type);
20037 fixp->fx_file = fragp->fr_file;
20038 fixp->fx_line = fragp->fr_line;
20039 fragp->fr_fix += fragp->fr_var;
20040 }
20041
20042 /* Return the size of a relaxable immediate operand instruction.
20043 SHIFT and SIZE specify the form of the allowable immediate. */
20044 static int
20045 relax_immediate (fragS *fragp, int size, int shift)
20046 {
20047 offsetT offset;
20048 offsetT mask;
20049 offsetT low;
20050
20051 /* ??? Should be able to do better than this. */
20052 if (fragp->fr_symbol)
20053 return 4;
20054
20055 low = (1 << shift) - 1;
20056 mask = (1 << (shift + size)) - (1 << shift);
20057 offset = fragp->fr_offset;
20058 /* Force misaligned offsets to 32-bit variant. */
20059 if (offset & low)
20060 return 4;
20061 if (offset & ~mask)
20062 return 4;
20063 return 2;
20064 }
20065
20066 /* Get the address of a symbol during relaxation. */
20067 static addressT
20068 relaxed_symbol_addr (fragS *fragp, long stretch)
20069 {
20070 fragS *sym_frag;
20071 addressT addr;
20072 symbolS *sym;
20073
20074 sym = fragp->fr_symbol;
20075 sym_frag = symbol_get_frag (sym);
20076 know (S_GET_SEGMENT (sym) != absolute_section
20077 || sym_frag == &zero_address_frag);
20078 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20079
20080 /* If frag has yet to be reached on this pass, assume it will
20081 move by STRETCH just as we did. If this is not so, it will
20082 be because some frag between grows, and that will force
20083 another pass. */
20084
20085 if (stretch != 0
20086 && sym_frag->relax_marker != fragp->relax_marker)
20087 {
20088 fragS *f;
20089
20090 /* Adjust stretch for any alignment frag. Note that if have
20091 been expanding the earlier code, the symbol may be
20092 defined in what appears to be an earlier frag. FIXME:
20093 This doesn't handle the fr_subtype field, which specifies
20094 a maximum number of bytes to skip when doing an
20095 alignment. */
20096 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20097 {
20098 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20099 {
20100 if (stretch < 0)
20101 stretch = - ((- stretch)
20102 & ~ ((1 << (int) f->fr_offset) - 1));
20103 else
20104 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20105 if (stretch == 0)
20106 break;
20107 }
20108 }
20109 if (f != NULL)
20110 addr += stretch;
20111 }
20112
20113 return addr;
20114 }
20115
20116 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
20117 load. */
20118 static int
20119 relax_adr (fragS *fragp, asection *sec, long stretch)
20120 {
20121 addressT addr;
20122 offsetT val;
20123
20124 /* Assume worst case for symbols not known to be in the same section. */
20125 if (fragp->fr_symbol == NULL
20126 || !S_IS_DEFINED (fragp->fr_symbol)
20127 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20128 || S_IS_WEAK (fragp->fr_symbol))
20129 return 4;
20130
20131 val = relaxed_symbol_addr (fragp, stretch);
20132 addr = fragp->fr_address + fragp->fr_fix;
20133 addr = (addr + 4) & ~3;
20134 /* Force misaligned targets to 32-bit variant. */
20135 if (val & 3)
20136 return 4;
20137 val -= addr;
20138 if (val < 0 || val > 1020)
20139 return 4;
20140 return 2;
20141 }
20142
20143 /* Return the size of a relaxable add/sub immediate instruction. */
20144 static int
20145 relax_addsub (fragS *fragp, asection *sec)
20146 {
20147 char *buf;
20148 int op;
20149
20150 buf = fragp->fr_literal + fragp->fr_fix;
20151 op = bfd_get_16(sec->owner, buf);
20152 if ((op & 0xf) == ((op >> 4) & 0xf))
20153 return relax_immediate (fragp, 8, 0);
20154 else
20155 return relax_immediate (fragp, 3, 0);
20156 }
20157
20158
20159 /* Return the size of a relaxable branch instruction. BITS is the
20160 size of the offset field in the narrow instruction. */
20161
20162 static int
20163 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
20164 {
20165 addressT addr;
20166 offsetT val;
20167 offsetT limit;
20168
20169 /* Assume worst case for symbols not known to be in the same section. */
20170 if (!S_IS_DEFINED (fragp->fr_symbol)
20171 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20172 || S_IS_WEAK (fragp->fr_symbol))
20173 return 4;
20174
20175 #ifdef OBJ_ELF
20176 if (S_IS_DEFINED (fragp->fr_symbol)
20177 && ARM_IS_FUNC (fragp->fr_symbol))
20178 return 4;
20179
20180 /* PR 12532. Global symbols with default visibility might
20181 be preempted, so do not relax relocations to them. */
20182 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
20183 && (! S_IS_LOCAL (fragp->fr_symbol)))
20184 return 4;
20185 #endif
20186
20187 val = relaxed_symbol_addr (fragp, stretch);
20188 addr = fragp->fr_address + fragp->fr_fix + 4;
20189 val -= addr;
20190
20191 /* Offset is a signed value *2 */
20192 limit = 1 << bits;
20193 if (val >= limit || val < -limit)
20194 return 4;
20195 return 2;
20196 }
20197
20198
20199 /* Relax a machine dependent frag. This returns the amount by which
20200 the current size of the frag should change. */
20201
20202 int
20203 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
20204 {
20205 int oldsize;
20206 int newsize;
20207
20208 oldsize = fragp->fr_var;
20209 switch (fragp->fr_subtype)
20210 {
20211 case T_MNEM_ldr_pc2:
20212 newsize = relax_adr (fragp, sec, stretch);
20213 break;
20214 case T_MNEM_ldr_pc:
20215 case T_MNEM_ldr_sp:
20216 case T_MNEM_str_sp:
20217 newsize = relax_immediate (fragp, 8, 2);
20218 break;
20219 case T_MNEM_ldr:
20220 case T_MNEM_str:
20221 newsize = relax_immediate (fragp, 5, 2);
20222 break;
20223 case T_MNEM_ldrh:
20224 case T_MNEM_strh:
20225 newsize = relax_immediate (fragp, 5, 1);
20226 break;
20227 case T_MNEM_ldrb:
20228 case T_MNEM_strb:
20229 newsize = relax_immediate (fragp, 5, 0);
20230 break;
20231 case T_MNEM_adr:
20232 newsize = relax_adr (fragp, sec, stretch);
20233 break;
20234 case T_MNEM_mov:
20235 case T_MNEM_movs:
20236 case T_MNEM_cmp:
20237 case T_MNEM_cmn:
20238 newsize = relax_immediate (fragp, 8, 0);
20239 break;
20240 case T_MNEM_b:
20241 newsize = relax_branch (fragp, sec, 11, stretch);
20242 break;
20243 case T_MNEM_bcond:
20244 newsize = relax_branch (fragp, sec, 8, stretch);
20245 break;
20246 case T_MNEM_add_sp:
20247 case T_MNEM_add_pc:
20248 newsize = relax_immediate (fragp, 8, 2);
20249 break;
20250 case T_MNEM_inc_sp:
20251 case T_MNEM_dec_sp:
20252 newsize = relax_immediate (fragp, 7, 2);
20253 break;
20254 case T_MNEM_addi:
20255 case T_MNEM_addis:
20256 case T_MNEM_subi:
20257 case T_MNEM_subis:
20258 newsize = relax_addsub (fragp, sec);
20259 break;
20260 default:
20261 abort ();
20262 }
20263
20264 fragp->fr_var = newsize;
20265 /* Freeze wide instructions that are at or before the same location as
20266 in the previous pass. This avoids infinite loops.
20267 Don't freeze them unconditionally because targets may be artificially
20268 misaligned by the expansion of preceding frags. */
20269 if (stretch <= 0 && newsize > 2)
20270 {
20271 md_convert_frag (sec->owner, sec, fragp);
20272 frag_wane (fragp);
20273 }
20274
20275 return newsize - oldsize;
20276 }
20277
20278 /* Round up a section size to the appropriate boundary. */
20279
20280 valueT
20281 md_section_align (segT segment ATTRIBUTE_UNUSED,
20282 valueT size)
20283 {
20284 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
20285 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
20286 {
20287 /* For a.out, force the section size to be aligned. If we don't do
20288 this, BFD will align it for us, but it will not write out the
20289 final bytes of the section. This may be a bug in BFD, but it is
20290 easier to fix it here since that is how the other a.out targets
20291 work. */
20292 int align;
20293
20294 align = bfd_get_section_alignment (stdoutput, segment);
20295 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
20296 }
20297 #endif
20298
20299 return size;
20300 }
20301
20302 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
20303 of an rs_align_code fragment. */
20304
20305 void
20306 arm_handle_align (fragS * fragP)
20307 {
20308 static char const arm_noop[2][2][4] =
20309 {
20310 { /* ARMv1 */
20311 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
20312 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
20313 },
20314 { /* ARMv6k */
20315 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
20316 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
20317 },
20318 };
20319 static char const thumb_noop[2][2][2] =
20320 {
20321 { /* Thumb-1 */
20322 {0xc0, 0x46}, /* LE */
20323 {0x46, 0xc0}, /* BE */
20324 },
20325 { /* Thumb-2 */
20326 {0x00, 0xbf}, /* LE */
20327 {0xbf, 0x00} /* BE */
20328 }
20329 };
20330 static char const wide_thumb_noop[2][4] =
20331 { /* Wide Thumb-2 */
20332 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
20333 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
20334 };
20335
20336 unsigned bytes, fix, noop_size;
20337 char * p;
20338 const char * noop;
20339 const char *narrow_noop = NULL;
20340 #ifdef OBJ_ELF
20341 enum mstate state;
20342 #endif
20343
20344 if (fragP->fr_type != rs_align_code)
20345 return;
20346
20347 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
20348 p = fragP->fr_literal + fragP->fr_fix;
20349 fix = 0;
20350
20351 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
20352 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
20353
20354 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
20355
20356 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
20357 {
20358 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
20359 {
20360 narrow_noop = thumb_noop[1][target_big_endian];
20361 noop = wide_thumb_noop[target_big_endian];
20362 }
20363 else
20364 noop = thumb_noop[0][target_big_endian];
20365 noop_size = 2;
20366 #ifdef OBJ_ELF
20367 state = MAP_THUMB;
20368 #endif
20369 }
20370 else
20371 {
20372 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
20373 [target_big_endian];
20374 noop_size = 4;
20375 #ifdef OBJ_ELF
20376 state = MAP_ARM;
20377 #endif
20378 }
20379
20380 fragP->fr_var = noop_size;
20381
20382 if (bytes & (noop_size - 1))
20383 {
20384 fix = bytes & (noop_size - 1);
20385 #ifdef OBJ_ELF
20386 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
20387 #endif
20388 memset (p, 0, fix);
20389 p += fix;
20390 bytes -= fix;
20391 }
20392
20393 if (narrow_noop)
20394 {
20395 if (bytes & noop_size)
20396 {
20397 /* Insert a narrow noop. */
20398 memcpy (p, narrow_noop, noop_size);
20399 p += noop_size;
20400 bytes -= noop_size;
20401 fix += noop_size;
20402 }
20403
20404 /* Use wide noops for the remainder */
20405 noop_size = 4;
20406 }
20407
20408 while (bytes >= noop_size)
20409 {
20410 memcpy (p, noop, noop_size);
20411 p += noop_size;
20412 bytes -= noop_size;
20413 fix += noop_size;
20414 }
20415
20416 fragP->fr_fix += fix;
20417 }
20418
20419 /* Called from md_do_align. Used to create an alignment
20420 frag in a code section. */
20421
20422 void
20423 arm_frag_align_code (int n, int max)
20424 {
20425 char * p;
20426
20427 /* We assume that there will never be a requirement
20428 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
20429 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
20430 {
20431 char err_msg[128];
20432
20433 sprintf (err_msg,
20434 _("alignments greater than %d bytes not supported in .text sections."),
20435 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20436 as_fatal ("%s", err_msg);
20437 }
20438
20439 p = frag_var (rs_align_code,
20440 MAX_MEM_FOR_RS_ALIGN_CODE,
20441 1,
20442 (relax_substateT) max,
20443 (symbolS *) NULL,
20444 (offsetT) n,
20445 (char *) NULL);
20446 *p = 0;
20447 }
20448
20449 /* Perform target specific initialisation of a frag.
20450 Note - despite the name this initialisation is not done when the frag
20451 is created, but only when its type is assigned. A frag can be created
20452 and used a long time before its type is set, so beware of assuming that
20453 this initialisationis performed first. */
20454
20455 #ifndef OBJ_ELF
20456 void
20457 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
20458 {
20459 /* Record whether this frag is in an ARM or a THUMB area. */
20460 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
20461 }
20462
20463 #else /* OBJ_ELF is defined. */
20464 void
20465 arm_init_frag (fragS * fragP, int max_chars)
20466 {
20467 /* If the current ARM vs THUMB mode has not already
20468 been recorded into this frag then do so now. */
20469 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
20470 {
20471 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
20472
20473 /* Record a mapping symbol for alignment frags. We will delete this
20474 later if the alignment ends up empty. */
20475 switch (fragP->fr_type)
20476 {
20477 case rs_align:
20478 case rs_align_test:
20479 case rs_fill:
20480 mapping_state_2 (MAP_DATA, max_chars);
20481 break;
20482 case rs_align_code:
20483 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
20484 break;
20485 default:
20486 break;
20487 }
20488 }
20489 }
20490
20491 /* When we change sections we need to issue a new mapping symbol. */
20492
20493 void
20494 arm_elf_change_section (void)
20495 {
20496 /* Link an unlinked unwind index table section to the .text section. */
20497 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
20498 && elf_linked_to_section (now_seg) == NULL)
20499 elf_linked_to_section (now_seg) = text_section;
20500 }
20501
20502 int
20503 arm_elf_section_type (const char * str, size_t len)
20504 {
20505 if (len == 5 && strncmp (str, "exidx", 5) == 0)
20506 return SHT_ARM_EXIDX;
20507
20508 return -1;
20509 }
20510 \f
20511 /* Code to deal with unwinding tables. */
20512
20513 static void add_unwind_adjustsp (offsetT);
20514
20515 /* Generate any deferred unwind frame offset. */
20516
20517 static void
20518 flush_pending_unwind (void)
20519 {
20520 offsetT offset;
20521
20522 offset = unwind.pending_offset;
20523 unwind.pending_offset = 0;
20524 if (offset != 0)
20525 add_unwind_adjustsp (offset);
20526 }
20527
20528 /* Add an opcode to this list for this function. Two-byte opcodes should
20529 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
20530 order. */
20531
20532 static void
20533 add_unwind_opcode (valueT op, int length)
20534 {
20535 /* Add any deferred stack adjustment. */
20536 if (unwind.pending_offset)
20537 flush_pending_unwind ();
20538
20539 unwind.sp_restored = 0;
20540
20541 if (unwind.opcode_count + length > unwind.opcode_alloc)
20542 {
20543 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
20544 if (unwind.opcodes)
20545 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
20546 unwind.opcode_alloc);
20547 else
20548 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
20549 }
20550 while (length > 0)
20551 {
20552 length--;
20553 unwind.opcodes[unwind.opcode_count] = op & 0xff;
20554 op >>= 8;
20555 unwind.opcode_count++;
20556 }
20557 }
20558
20559 /* Add unwind opcodes to adjust the stack pointer. */
20560
20561 static void
20562 add_unwind_adjustsp (offsetT offset)
20563 {
20564 valueT op;
20565
20566 if (offset > 0x200)
20567 {
20568 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
20569 char bytes[5];
20570 int n;
20571 valueT o;
20572
20573 /* Long form: 0xb2, uleb128. */
20574 /* This might not fit in a word so add the individual bytes,
20575 remembering the list is built in reverse order. */
20576 o = (valueT) ((offset - 0x204) >> 2);
20577 if (o == 0)
20578 add_unwind_opcode (0, 1);
20579
20580 /* Calculate the uleb128 encoding of the offset. */
20581 n = 0;
20582 while (o)
20583 {
20584 bytes[n] = o & 0x7f;
20585 o >>= 7;
20586 if (o)
20587 bytes[n] |= 0x80;
20588 n++;
20589 }
20590 /* Add the insn. */
20591 for (; n; n--)
20592 add_unwind_opcode (bytes[n - 1], 1);
20593 add_unwind_opcode (0xb2, 1);
20594 }
20595 else if (offset > 0x100)
20596 {
20597 /* Two short opcodes. */
20598 add_unwind_opcode (0x3f, 1);
20599 op = (offset - 0x104) >> 2;
20600 add_unwind_opcode (op, 1);
20601 }
20602 else if (offset > 0)
20603 {
20604 /* Short opcode. */
20605 op = (offset - 4) >> 2;
20606 add_unwind_opcode (op, 1);
20607 }
20608 else if (offset < 0)
20609 {
20610 offset = -offset;
20611 while (offset > 0x100)
20612 {
20613 add_unwind_opcode (0x7f, 1);
20614 offset -= 0x100;
20615 }
20616 op = ((offset - 4) >> 2) | 0x40;
20617 add_unwind_opcode (op, 1);
20618 }
20619 }
20620
20621 /* Finish the list of unwind opcodes for this function. */
20622 static void
20623 finish_unwind_opcodes (void)
20624 {
20625 valueT op;
20626
20627 if (unwind.fp_used)
20628 {
20629 /* Adjust sp as necessary. */
20630 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
20631 flush_pending_unwind ();
20632
20633 /* After restoring sp from the frame pointer. */
20634 op = 0x90 | unwind.fp_reg;
20635 add_unwind_opcode (op, 1);
20636 }
20637 else
20638 flush_pending_unwind ();
20639 }
20640
20641
20642 /* Start an exception table entry. If idx is nonzero this is an index table
20643 entry. */
20644
20645 static void
20646 start_unwind_section (const segT text_seg, int idx)
20647 {
20648 const char * text_name;
20649 const char * prefix;
20650 const char * prefix_once;
20651 const char * group_name;
20652 size_t prefix_len;
20653 size_t text_len;
20654 char * sec_name;
20655 size_t sec_name_len;
20656 int type;
20657 int flags;
20658 int linkonce;
20659
20660 if (idx)
20661 {
20662 prefix = ELF_STRING_ARM_unwind;
20663 prefix_once = ELF_STRING_ARM_unwind_once;
20664 type = SHT_ARM_EXIDX;
20665 }
20666 else
20667 {
20668 prefix = ELF_STRING_ARM_unwind_info;
20669 prefix_once = ELF_STRING_ARM_unwind_info_once;
20670 type = SHT_PROGBITS;
20671 }
20672
20673 text_name = segment_name (text_seg);
20674 if (streq (text_name, ".text"))
20675 text_name = "";
20676
20677 if (strncmp (text_name, ".gnu.linkonce.t.",
20678 strlen (".gnu.linkonce.t.")) == 0)
20679 {
20680 prefix = prefix_once;
20681 text_name += strlen (".gnu.linkonce.t.");
20682 }
20683
20684 prefix_len = strlen (prefix);
20685 text_len = strlen (text_name);
20686 sec_name_len = prefix_len + text_len;
20687 sec_name = (char *) xmalloc (sec_name_len + 1);
20688 memcpy (sec_name, prefix, prefix_len);
20689 memcpy (sec_name + prefix_len, text_name, text_len);
20690 sec_name[prefix_len + text_len] = '\0';
20691
20692 flags = SHF_ALLOC;
20693 linkonce = 0;
20694 group_name = 0;
20695
20696 /* Handle COMDAT group. */
20697 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
20698 {
20699 group_name = elf_group_name (text_seg);
20700 if (group_name == NULL)
20701 {
20702 as_bad (_("Group section `%s' has no group signature"),
20703 segment_name (text_seg));
20704 ignore_rest_of_line ();
20705 return;
20706 }
20707 flags |= SHF_GROUP;
20708 linkonce = 1;
20709 }
20710
20711 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
20712
20713 /* Set the section link for index tables. */
20714 if (idx)
20715 elf_linked_to_section (now_seg) = text_seg;
20716 }
20717
20718
20719 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
20720 personality routine data. Returns zero, or the index table value for
20721 and inline entry. */
20722
20723 static valueT
20724 create_unwind_entry (int have_data)
20725 {
20726 int size;
20727 addressT where;
20728 char *ptr;
20729 /* The current word of data. */
20730 valueT data;
20731 /* The number of bytes left in this word. */
20732 int n;
20733
20734 finish_unwind_opcodes ();
20735
20736 /* Remember the current text section. */
20737 unwind.saved_seg = now_seg;
20738 unwind.saved_subseg = now_subseg;
20739
20740 start_unwind_section (now_seg, 0);
20741
20742 if (unwind.personality_routine == NULL)
20743 {
20744 if (unwind.personality_index == -2)
20745 {
20746 if (have_data)
20747 as_bad (_("handlerdata in cantunwind frame"));
20748 return 1; /* EXIDX_CANTUNWIND. */
20749 }
20750
20751 /* Use a default personality routine if none is specified. */
20752 if (unwind.personality_index == -1)
20753 {
20754 if (unwind.opcode_count > 3)
20755 unwind.personality_index = 1;
20756 else
20757 unwind.personality_index = 0;
20758 }
20759
20760 /* Space for the personality routine entry. */
20761 if (unwind.personality_index == 0)
20762 {
20763 if (unwind.opcode_count > 3)
20764 as_bad (_("too many unwind opcodes for personality routine 0"));
20765
20766 if (!have_data)
20767 {
20768 /* All the data is inline in the index table. */
20769 data = 0x80;
20770 n = 3;
20771 while (unwind.opcode_count > 0)
20772 {
20773 unwind.opcode_count--;
20774 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20775 n--;
20776 }
20777
20778 /* Pad with "finish" opcodes. */
20779 while (n--)
20780 data = (data << 8) | 0xb0;
20781
20782 return data;
20783 }
20784 size = 0;
20785 }
20786 else
20787 /* We get two opcodes "free" in the first word. */
20788 size = unwind.opcode_count - 2;
20789 }
20790 else
20791 {
20792 gas_assert (unwind.personality_index == -1);
20793
20794 /* An extra byte is required for the opcode count. */
20795 size = unwind.opcode_count + 1;
20796 }
20797
20798 size = (size + 3) >> 2;
20799 if (size > 0xff)
20800 as_bad (_("too many unwind opcodes"));
20801
20802 frag_align (2, 0, 0);
20803 record_alignment (now_seg, 2);
20804 unwind.table_entry = expr_build_dot ();
20805
20806 /* Allocate the table entry. */
20807 ptr = frag_more ((size << 2) + 4);
20808 /* PR 13449: Zero the table entries in case some of them are not used. */
20809 memset (ptr, 0, (size << 2) + 4);
20810 where = frag_now_fix () - ((size << 2) + 4);
20811
20812 switch (unwind.personality_index)
20813 {
20814 case -1:
20815 /* ??? Should this be a PLT generating relocation? */
20816 /* Custom personality routine. */
20817 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
20818 BFD_RELOC_ARM_PREL31);
20819
20820 where += 4;
20821 ptr += 4;
20822
20823 /* Set the first byte to the number of additional words. */
20824 data = size > 0 ? size - 1 : 0;
20825 n = 3;
20826 break;
20827
20828 /* ABI defined personality routines. */
20829 case 0:
20830 /* Three opcodes bytes are packed into the first word. */
20831 data = 0x80;
20832 n = 3;
20833 break;
20834
20835 case 1:
20836 case 2:
20837 /* The size and first two opcode bytes go in the first word. */
20838 data = ((0x80 + unwind.personality_index) << 8) | size;
20839 n = 2;
20840 break;
20841
20842 default:
20843 /* Should never happen. */
20844 abort ();
20845 }
20846
20847 /* Pack the opcodes into words (MSB first), reversing the list at the same
20848 time. */
20849 while (unwind.opcode_count > 0)
20850 {
20851 if (n == 0)
20852 {
20853 md_number_to_chars (ptr, data, 4);
20854 ptr += 4;
20855 n = 4;
20856 data = 0;
20857 }
20858 unwind.opcode_count--;
20859 n--;
20860 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20861 }
20862
20863 /* Finish off the last word. */
20864 if (n < 4)
20865 {
20866 /* Pad with "finish" opcodes. */
20867 while (n--)
20868 data = (data << 8) | 0xb0;
20869
20870 md_number_to_chars (ptr, data, 4);
20871 }
20872
20873 if (!have_data)
20874 {
20875 /* Add an empty descriptor if there is no user-specified data. */
20876 ptr = frag_more (4);
20877 md_number_to_chars (ptr, 0, 4);
20878 }
20879
20880 return 0;
20881 }
20882
20883
20884 /* Initialize the DWARF-2 unwind information for this procedure. */
20885
20886 void
20887 tc_arm_frame_initial_instructions (void)
20888 {
20889 cfi_add_CFA_def_cfa (REG_SP, 0);
20890 }
20891 #endif /* OBJ_ELF */
20892
20893 /* Convert REGNAME to a DWARF-2 register number. */
20894
20895 int
20896 tc_arm_regname_to_dw2regnum (char *regname)
20897 {
20898 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
20899
20900 if (reg == FAIL)
20901 return -1;
20902
20903 return reg;
20904 }
20905
20906 #ifdef TE_PE
20907 void
20908 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
20909 {
20910 expressionS exp;
20911
20912 exp.X_op = O_secrel;
20913 exp.X_add_symbol = symbol;
20914 exp.X_add_number = 0;
20915 emit_expr (&exp, size);
20916 }
20917 #endif
20918
20919 /* MD interface: Symbol and relocation handling. */
20920
20921 /* Return the address within the segment that a PC-relative fixup is
20922 relative to. For ARM, PC-relative fixups applied to instructions
20923 are generally relative to the location of the fixup plus 8 bytes.
20924 Thumb branches are offset by 4, and Thumb loads relative to PC
20925 require special handling. */
20926
20927 long
20928 md_pcrel_from_section (fixS * fixP, segT seg)
20929 {
20930 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20931
20932 /* If this is pc-relative and we are going to emit a relocation
20933 then we just want to put out any pipeline compensation that the linker
20934 will need. Otherwise we want to use the calculated base.
20935 For WinCE we skip the bias for externals as well, since this
20936 is how the MS ARM-CE assembler behaves and we want to be compatible. */
20937 if (fixP->fx_pcrel
20938 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
20939 || (arm_force_relocation (fixP)
20940 #ifdef TE_WINCE
20941 && !S_IS_EXTERNAL (fixP->fx_addsy)
20942 #endif
20943 )))
20944 base = 0;
20945
20946
20947 switch (fixP->fx_r_type)
20948 {
20949 /* PC relative addressing on the Thumb is slightly odd as the
20950 bottom two bits of the PC are forced to zero for the
20951 calculation. This happens *after* application of the
20952 pipeline offset. However, Thumb adrl already adjusts for
20953 this, so we need not do it again. */
20954 case BFD_RELOC_ARM_THUMB_ADD:
20955 return base & ~3;
20956
20957 case BFD_RELOC_ARM_THUMB_OFFSET:
20958 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20959 case BFD_RELOC_ARM_T32_ADD_PC12:
20960 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20961 return (base + 4) & ~3;
20962
20963 /* Thumb branches are simply offset by +4. */
20964 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20965 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20966 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20967 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20968 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20969 return base + 4;
20970
20971 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20972 if (fixP->fx_addsy
20973 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20974 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20975 && ARM_IS_FUNC (fixP->fx_addsy)
20976 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20977 base = fixP->fx_where + fixP->fx_frag->fr_address;
20978 return base + 4;
20979
20980 /* BLX is like branches above, but forces the low two bits of PC to
20981 zero. */
20982 case BFD_RELOC_THUMB_PCREL_BLX:
20983 if (fixP->fx_addsy
20984 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20985 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20986 && THUMB_IS_FUNC (fixP->fx_addsy)
20987 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20988 base = fixP->fx_where + fixP->fx_frag->fr_address;
20989 return (base + 4) & ~3;
20990
20991 /* ARM mode branches are offset by +8. However, the Windows CE
20992 loader expects the relocation not to take this into account. */
20993 case BFD_RELOC_ARM_PCREL_BLX:
20994 if (fixP->fx_addsy
20995 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20996 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20997 && ARM_IS_FUNC (fixP->fx_addsy)
20998 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20999 base = fixP->fx_where + fixP->fx_frag->fr_address;
21000 return base + 8;
21001
21002 case BFD_RELOC_ARM_PCREL_CALL:
21003 if (fixP->fx_addsy
21004 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21005 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21006 && THUMB_IS_FUNC (fixP->fx_addsy)
21007 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21008 base = fixP->fx_where + fixP->fx_frag->fr_address;
21009 return base + 8;
21010
21011 case BFD_RELOC_ARM_PCREL_BRANCH:
21012 case BFD_RELOC_ARM_PCREL_JUMP:
21013 case BFD_RELOC_ARM_PLT32:
21014 #ifdef TE_WINCE
21015 /* When handling fixups immediately, because we have already
21016 discovered the value of a symbol, or the address of the frag involved
21017 we must account for the offset by +8, as the OS loader will never see the reloc.
21018 see fixup_segment() in write.c
21019 The S_IS_EXTERNAL test handles the case of global symbols.
21020 Those need the calculated base, not just the pipe compensation the linker will need. */
21021 if (fixP->fx_pcrel
21022 && fixP->fx_addsy != NULL
21023 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21024 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21025 return base + 8;
21026 return base;
21027 #else
21028 return base + 8;
21029 #endif
21030
21031
21032 /* ARM mode loads relative to PC are also offset by +8. Unlike
21033 branches, the Windows CE loader *does* expect the relocation
21034 to take this into account. */
21035 case BFD_RELOC_ARM_OFFSET_IMM:
21036 case BFD_RELOC_ARM_OFFSET_IMM8:
21037 case BFD_RELOC_ARM_HWLITERAL:
21038 case BFD_RELOC_ARM_LITERAL:
21039 case BFD_RELOC_ARM_CP_OFF_IMM:
21040 return base + 8;
21041
21042
21043 /* Other PC-relative relocations are un-offset. */
21044 default:
21045 return base;
21046 }
21047 }
21048
21049 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21050 Otherwise we have no need to default values of symbols. */
21051
21052 symbolS *
21053 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21054 {
21055 #ifdef OBJ_ELF
21056 if (name[0] == '_' && name[1] == 'G'
21057 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21058 {
21059 if (!GOT_symbol)
21060 {
21061 if (symbol_find (name))
21062 as_bad (_("GOT already in the symbol table"));
21063
21064 GOT_symbol = symbol_new (name, undefined_section,
21065 (valueT) 0, & zero_address_frag);
21066 }
21067
21068 return GOT_symbol;
21069 }
21070 #endif
21071
21072 return NULL;
21073 }
21074
21075 /* Subroutine of md_apply_fix. Check to see if an immediate can be
21076 computed as two separate immediate values, added together. We
21077 already know that this value cannot be computed by just one ARM
21078 instruction. */
21079
21080 static unsigned int
21081 validate_immediate_twopart (unsigned int val,
21082 unsigned int * highpart)
21083 {
21084 unsigned int a;
21085 unsigned int i;
21086
21087 for (i = 0; i < 32; i += 2)
21088 if (((a = rotate_left (val, i)) & 0xff) != 0)
21089 {
21090 if (a & 0xff00)
21091 {
21092 if (a & ~ 0xffff)
21093 continue;
21094 * highpart = (a >> 8) | ((i + 24) << 7);
21095 }
21096 else if (a & 0xff0000)
21097 {
21098 if (a & 0xff000000)
21099 continue;
21100 * highpart = (a >> 16) | ((i + 16) << 7);
21101 }
21102 else
21103 {
21104 gas_assert (a & 0xff000000);
21105 * highpart = (a >> 24) | ((i + 8) << 7);
21106 }
21107
21108 return (a & 0xff) | (i << 7);
21109 }
21110
21111 return FAIL;
21112 }
21113
21114 static int
21115 validate_offset_imm (unsigned int val, int hwse)
21116 {
21117 if ((hwse && val > 255) || val > 4095)
21118 return FAIL;
21119 return val;
21120 }
21121
21122 /* Subroutine of md_apply_fix. Do those data_ops which can take a
21123 negative immediate constant by altering the instruction. A bit of
21124 a hack really.
21125 MOV <-> MVN
21126 AND <-> BIC
21127 ADC <-> SBC
21128 by inverting the second operand, and
21129 ADD <-> SUB
21130 CMP <-> CMN
21131 by negating the second operand. */
21132
21133 static int
21134 negate_data_op (unsigned long * instruction,
21135 unsigned long value)
21136 {
21137 int op, new_inst;
21138 unsigned long negated, inverted;
21139
21140 negated = encode_arm_immediate (-value);
21141 inverted = encode_arm_immediate (~value);
21142
21143 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21144 switch (op)
21145 {
21146 /* First negates. */
21147 case OPCODE_SUB: /* ADD <-> SUB */
21148 new_inst = OPCODE_ADD;
21149 value = negated;
21150 break;
21151
21152 case OPCODE_ADD:
21153 new_inst = OPCODE_SUB;
21154 value = negated;
21155 break;
21156
21157 case OPCODE_CMP: /* CMP <-> CMN */
21158 new_inst = OPCODE_CMN;
21159 value = negated;
21160 break;
21161
21162 case OPCODE_CMN:
21163 new_inst = OPCODE_CMP;
21164 value = negated;
21165 break;
21166
21167 /* Now Inverted ops. */
21168 case OPCODE_MOV: /* MOV <-> MVN */
21169 new_inst = OPCODE_MVN;
21170 value = inverted;
21171 break;
21172
21173 case OPCODE_MVN:
21174 new_inst = OPCODE_MOV;
21175 value = inverted;
21176 break;
21177
21178 case OPCODE_AND: /* AND <-> BIC */
21179 new_inst = OPCODE_BIC;
21180 value = inverted;
21181 break;
21182
21183 case OPCODE_BIC:
21184 new_inst = OPCODE_AND;
21185 value = inverted;
21186 break;
21187
21188 case OPCODE_ADC: /* ADC <-> SBC */
21189 new_inst = OPCODE_SBC;
21190 value = inverted;
21191 break;
21192
21193 case OPCODE_SBC:
21194 new_inst = OPCODE_ADC;
21195 value = inverted;
21196 break;
21197
21198 /* We cannot do anything. */
21199 default:
21200 return FAIL;
21201 }
21202
21203 if (value == (unsigned) FAIL)
21204 return FAIL;
21205
21206 *instruction &= OPCODE_MASK;
21207 *instruction |= new_inst << DATA_OP_SHIFT;
21208 return value;
21209 }
21210
21211 /* Like negate_data_op, but for Thumb-2. */
21212
21213 static unsigned int
21214 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
21215 {
21216 int op, new_inst;
21217 int rd;
21218 unsigned int negated, inverted;
21219
21220 negated = encode_thumb32_immediate (-value);
21221 inverted = encode_thumb32_immediate (~value);
21222
21223 rd = (*instruction >> 8) & 0xf;
21224 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
21225 switch (op)
21226 {
21227 /* ADD <-> SUB. Includes CMP <-> CMN. */
21228 case T2_OPCODE_SUB:
21229 new_inst = T2_OPCODE_ADD;
21230 value = negated;
21231 break;
21232
21233 case T2_OPCODE_ADD:
21234 new_inst = T2_OPCODE_SUB;
21235 value = negated;
21236 break;
21237
21238 /* ORR <-> ORN. Includes MOV <-> MVN. */
21239 case T2_OPCODE_ORR:
21240 new_inst = T2_OPCODE_ORN;
21241 value = inverted;
21242 break;
21243
21244 case T2_OPCODE_ORN:
21245 new_inst = T2_OPCODE_ORR;
21246 value = inverted;
21247 break;
21248
21249 /* AND <-> BIC. TST has no inverted equivalent. */
21250 case T2_OPCODE_AND:
21251 new_inst = T2_OPCODE_BIC;
21252 if (rd == 15)
21253 value = FAIL;
21254 else
21255 value = inverted;
21256 break;
21257
21258 case T2_OPCODE_BIC:
21259 new_inst = T2_OPCODE_AND;
21260 value = inverted;
21261 break;
21262
21263 /* ADC <-> SBC */
21264 case T2_OPCODE_ADC:
21265 new_inst = T2_OPCODE_SBC;
21266 value = inverted;
21267 break;
21268
21269 case T2_OPCODE_SBC:
21270 new_inst = T2_OPCODE_ADC;
21271 value = inverted;
21272 break;
21273
21274 /* We cannot do anything. */
21275 default:
21276 return FAIL;
21277 }
21278
21279 if (value == (unsigned int)FAIL)
21280 return FAIL;
21281
21282 *instruction &= T2_OPCODE_MASK;
21283 *instruction |= new_inst << T2_DATA_OP_SHIFT;
21284 return value;
21285 }
21286
21287 /* Read a 32-bit thumb instruction from buf. */
21288 static unsigned long
21289 get_thumb32_insn (char * buf)
21290 {
21291 unsigned long insn;
21292 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
21293 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21294
21295 return insn;
21296 }
21297
21298
21299 /* We usually want to set the low bit on the address of thumb function
21300 symbols. In particular .word foo - . should have the low bit set.
21301 Generic code tries to fold the difference of two symbols to
21302 a constant. Prevent this and force a relocation when the first symbols
21303 is a thumb function. */
21304
21305 bfd_boolean
21306 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
21307 {
21308 if (op == O_subtract
21309 && l->X_op == O_symbol
21310 && r->X_op == O_symbol
21311 && THUMB_IS_FUNC (l->X_add_symbol))
21312 {
21313 l->X_op = O_subtract;
21314 l->X_op_symbol = r->X_add_symbol;
21315 l->X_add_number -= r->X_add_number;
21316 return TRUE;
21317 }
21318
21319 /* Process as normal. */
21320 return FALSE;
21321 }
21322
21323 /* Encode Thumb2 unconditional branches and calls. The encoding
21324 for the 2 are identical for the immediate values. */
21325
21326 static void
21327 encode_thumb2_b_bl_offset (char * buf, offsetT value)
21328 {
21329 #define T2I1I2MASK ((1 << 13) | (1 << 11))
21330 offsetT newval;
21331 offsetT newval2;
21332 addressT S, I1, I2, lo, hi;
21333
21334 S = (value >> 24) & 0x01;
21335 I1 = (value >> 23) & 0x01;
21336 I2 = (value >> 22) & 0x01;
21337 hi = (value >> 12) & 0x3ff;
21338 lo = (value >> 1) & 0x7ff;
21339 newval = md_chars_to_number (buf, THUMB_SIZE);
21340 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21341 newval |= (S << 10) | hi;
21342 newval2 &= ~T2I1I2MASK;
21343 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
21344 md_number_to_chars (buf, newval, THUMB_SIZE);
21345 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21346 }
21347
21348 void
21349 md_apply_fix (fixS * fixP,
21350 valueT * valP,
21351 segT seg)
21352 {
21353 offsetT value = * valP;
21354 offsetT newval;
21355 unsigned int newimm;
21356 unsigned long temp;
21357 int sign;
21358 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
21359
21360 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
21361
21362 /* Note whether this will delete the relocation. */
21363
21364 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
21365 fixP->fx_done = 1;
21366
21367 /* On a 64-bit host, silently truncate 'value' to 32 bits for
21368 consistency with the behaviour on 32-bit hosts. Remember value
21369 for emit_reloc. */
21370 value &= 0xffffffff;
21371 value ^= 0x80000000;
21372 value -= 0x80000000;
21373
21374 *valP = value;
21375 fixP->fx_addnumber = value;
21376
21377 /* Same treatment for fixP->fx_offset. */
21378 fixP->fx_offset &= 0xffffffff;
21379 fixP->fx_offset ^= 0x80000000;
21380 fixP->fx_offset -= 0x80000000;
21381
21382 switch (fixP->fx_r_type)
21383 {
21384 case BFD_RELOC_NONE:
21385 /* This will need to go in the object file. */
21386 fixP->fx_done = 0;
21387 break;
21388
21389 case BFD_RELOC_ARM_IMMEDIATE:
21390 /* We claim that this fixup has been processed here,
21391 even if in fact we generate an error because we do
21392 not have a reloc for it, so tc_gen_reloc will reject it. */
21393 fixP->fx_done = 1;
21394
21395 if (fixP->fx_addsy)
21396 {
21397 const char *msg = 0;
21398
21399 if (! S_IS_DEFINED (fixP->fx_addsy))
21400 msg = _("undefined symbol %s used as an immediate value");
21401 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21402 msg = _("symbol %s is in a different section");
21403 else if (S_IS_WEAK (fixP->fx_addsy))
21404 msg = _("symbol %s is weak and may be overridden later");
21405
21406 if (msg)
21407 {
21408 as_bad_where (fixP->fx_file, fixP->fx_line,
21409 msg, S_GET_NAME (fixP->fx_addsy));
21410 break;
21411 }
21412 }
21413
21414 temp = md_chars_to_number (buf, INSN_SIZE);
21415
21416 /* If the offset is negative, we should use encoding A2 for ADR. */
21417 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
21418 newimm = negate_data_op (&temp, value);
21419 else
21420 {
21421 newimm = encode_arm_immediate (value);
21422
21423 /* If the instruction will fail, see if we can fix things up by
21424 changing the opcode. */
21425 if (newimm == (unsigned int) FAIL)
21426 newimm = negate_data_op (&temp, value);
21427 }
21428
21429 if (newimm == (unsigned int) FAIL)
21430 {
21431 as_bad_where (fixP->fx_file, fixP->fx_line,
21432 _("invalid constant (%lx) after fixup"),
21433 (unsigned long) value);
21434 break;
21435 }
21436
21437 newimm |= (temp & 0xfffff000);
21438 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
21439 break;
21440
21441 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21442 {
21443 unsigned int highpart = 0;
21444 unsigned int newinsn = 0xe1a00000; /* nop. */
21445
21446 if (fixP->fx_addsy)
21447 {
21448 const char *msg = 0;
21449
21450 if (! S_IS_DEFINED (fixP->fx_addsy))
21451 msg = _("undefined symbol %s used as an immediate value");
21452 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
21453 msg = _("symbol %s is in a different section");
21454 else if (S_IS_WEAK (fixP->fx_addsy))
21455 msg = _("symbol %s is weak and may be overridden later");
21456
21457 if (msg)
21458 {
21459 as_bad_where (fixP->fx_file, fixP->fx_line,
21460 msg, S_GET_NAME (fixP->fx_addsy));
21461 break;
21462 }
21463 }
21464
21465 newimm = encode_arm_immediate (value);
21466 temp = md_chars_to_number (buf, INSN_SIZE);
21467
21468 /* If the instruction will fail, see if we can fix things up by
21469 changing the opcode. */
21470 if (newimm == (unsigned int) FAIL
21471 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
21472 {
21473 /* No ? OK - try using two ADD instructions to generate
21474 the value. */
21475 newimm = validate_immediate_twopart (value, & highpart);
21476
21477 /* Yes - then make sure that the second instruction is
21478 also an add. */
21479 if (newimm != (unsigned int) FAIL)
21480 newinsn = temp;
21481 /* Still No ? Try using a negated value. */
21482 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
21483 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
21484 /* Otherwise - give up. */
21485 else
21486 {
21487 as_bad_where (fixP->fx_file, fixP->fx_line,
21488 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
21489 (long) value);
21490 break;
21491 }
21492
21493 /* Replace the first operand in the 2nd instruction (which
21494 is the PC) with the destination register. We have
21495 already added in the PC in the first instruction and we
21496 do not want to do it again. */
21497 newinsn &= ~ 0xf0000;
21498 newinsn |= ((newinsn & 0x0f000) << 4);
21499 }
21500
21501 newimm |= (temp & 0xfffff000);
21502 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
21503
21504 highpart |= (newinsn & 0xfffff000);
21505 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
21506 }
21507 break;
21508
21509 case BFD_RELOC_ARM_OFFSET_IMM:
21510 if (!fixP->fx_done && seg->use_rela_p)
21511 value = 0;
21512
21513 case BFD_RELOC_ARM_LITERAL:
21514 sign = value > 0;
21515
21516 if (value < 0)
21517 value = - value;
21518
21519 if (validate_offset_imm (value, 0) == FAIL)
21520 {
21521 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
21522 as_bad_where (fixP->fx_file, fixP->fx_line,
21523 _("invalid literal constant: pool needs to be closer"));
21524 else
21525 as_bad_where (fixP->fx_file, fixP->fx_line,
21526 _("bad immediate value for offset (%ld)"),
21527 (long) value);
21528 break;
21529 }
21530
21531 newval = md_chars_to_number (buf, INSN_SIZE);
21532 if (value == 0)
21533 newval &= 0xfffff000;
21534 else
21535 {
21536 newval &= 0xff7ff000;
21537 newval |= value | (sign ? INDEX_UP : 0);
21538 }
21539 md_number_to_chars (buf, newval, INSN_SIZE);
21540 break;
21541
21542 case BFD_RELOC_ARM_OFFSET_IMM8:
21543 case BFD_RELOC_ARM_HWLITERAL:
21544 sign = value > 0;
21545
21546 if (value < 0)
21547 value = - value;
21548
21549 if (validate_offset_imm (value, 1) == FAIL)
21550 {
21551 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
21552 as_bad_where (fixP->fx_file, fixP->fx_line,
21553 _("invalid literal constant: pool needs to be closer"));
21554 else
21555 as_bad_where (fixP->fx_file, fixP->fx_line,
21556 _("bad immediate value for 8-bit offset (%ld)"),
21557 (long) value);
21558 break;
21559 }
21560
21561 newval = md_chars_to_number (buf, INSN_SIZE);
21562 if (value == 0)
21563 newval &= 0xfffff0f0;
21564 else
21565 {
21566 newval &= 0xff7ff0f0;
21567 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
21568 }
21569 md_number_to_chars (buf, newval, INSN_SIZE);
21570 break;
21571
21572 case BFD_RELOC_ARM_T32_OFFSET_U8:
21573 if (value < 0 || value > 1020 || value % 4 != 0)
21574 as_bad_where (fixP->fx_file, fixP->fx_line,
21575 _("bad immediate value for offset (%ld)"), (long) value);
21576 value /= 4;
21577
21578 newval = md_chars_to_number (buf+2, THUMB_SIZE);
21579 newval |= value;
21580 md_number_to_chars (buf+2, newval, THUMB_SIZE);
21581 break;
21582
21583 case BFD_RELOC_ARM_T32_OFFSET_IMM:
21584 /* This is a complicated relocation used for all varieties of Thumb32
21585 load/store instruction with immediate offset:
21586
21587 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
21588 *4, optional writeback(W)
21589 (doubleword load/store)
21590
21591 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
21592 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
21593 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
21594 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
21595 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
21596
21597 Uppercase letters indicate bits that are already encoded at
21598 this point. Lowercase letters are our problem. For the
21599 second block of instructions, the secondary opcode nybble
21600 (bits 8..11) is present, and bit 23 is zero, even if this is
21601 a PC-relative operation. */
21602 newval = md_chars_to_number (buf, THUMB_SIZE);
21603 newval <<= 16;
21604 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
21605
21606 if ((newval & 0xf0000000) == 0xe0000000)
21607 {
21608 /* Doubleword load/store: 8-bit offset, scaled by 4. */
21609 if (value >= 0)
21610 newval |= (1 << 23);
21611 else
21612 value = -value;
21613 if (value % 4 != 0)
21614 {
21615 as_bad_where (fixP->fx_file, fixP->fx_line,
21616 _("offset not a multiple of 4"));
21617 break;
21618 }
21619 value /= 4;
21620 if (value > 0xff)
21621 {
21622 as_bad_where (fixP->fx_file, fixP->fx_line,
21623 _("offset out of range"));
21624 break;
21625 }
21626 newval &= ~0xff;
21627 }
21628 else if ((newval & 0x000f0000) == 0x000f0000)
21629 {
21630 /* PC-relative, 12-bit offset. */
21631 if (value >= 0)
21632 newval |= (1 << 23);
21633 else
21634 value = -value;
21635 if (value > 0xfff)
21636 {
21637 as_bad_where (fixP->fx_file, fixP->fx_line,
21638 _("offset out of range"));
21639 break;
21640 }
21641 newval &= ~0xfff;
21642 }
21643 else if ((newval & 0x00000100) == 0x00000100)
21644 {
21645 /* Writeback: 8-bit, +/- offset. */
21646 if (value >= 0)
21647 newval |= (1 << 9);
21648 else
21649 value = -value;
21650 if (value > 0xff)
21651 {
21652 as_bad_where (fixP->fx_file, fixP->fx_line,
21653 _("offset out of range"));
21654 break;
21655 }
21656 newval &= ~0xff;
21657 }
21658 else if ((newval & 0x00000f00) == 0x00000e00)
21659 {
21660 /* T-instruction: positive 8-bit offset. */
21661 if (value < 0 || value > 0xff)
21662 {
21663 as_bad_where (fixP->fx_file, fixP->fx_line,
21664 _("offset out of range"));
21665 break;
21666 }
21667 newval &= ~0xff;
21668 newval |= value;
21669 }
21670 else
21671 {
21672 /* Positive 12-bit or negative 8-bit offset. */
21673 int limit;
21674 if (value >= 0)
21675 {
21676 newval |= (1 << 23);
21677 limit = 0xfff;
21678 }
21679 else
21680 {
21681 value = -value;
21682 limit = 0xff;
21683 }
21684 if (value > limit)
21685 {
21686 as_bad_where (fixP->fx_file, fixP->fx_line,
21687 _("offset out of range"));
21688 break;
21689 }
21690 newval &= ~limit;
21691 }
21692
21693 newval |= value;
21694 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
21695 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
21696 break;
21697
21698 case BFD_RELOC_ARM_SHIFT_IMM:
21699 newval = md_chars_to_number (buf, INSN_SIZE);
21700 if (((unsigned long) value) > 32
21701 || (value == 32
21702 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
21703 {
21704 as_bad_where (fixP->fx_file, fixP->fx_line,
21705 _("shift expression is too large"));
21706 break;
21707 }
21708
21709 if (value == 0)
21710 /* Shifts of zero must be done as lsl. */
21711 newval &= ~0x60;
21712 else if (value == 32)
21713 value = 0;
21714 newval &= 0xfffff07f;
21715 newval |= (value & 0x1f) << 7;
21716 md_number_to_chars (buf, newval, INSN_SIZE);
21717 break;
21718
21719 case BFD_RELOC_ARM_T32_IMMEDIATE:
21720 case BFD_RELOC_ARM_T32_ADD_IMM:
21721 case BFD_RELOC_ARM_T32_IMM12:
21722 case BFD_RELOC_ARM_T32_ADD_PC12:
21723 /* We claim that this fixup has been processed here,
21724 even if in fact we generate an error because we do
21725 not have a reloc for it, so tc_gen_reloc will reject it. */
21726 fixP->fx_done = 1;
21727
21728 if (fixP->fx_addsy
21729 && ! S_IS_DEFINED (fixP->fx_addsy))
21730 {
21731 as_bad_where (fixP->fx_file, fixP->fx_line,
21732 _("undefined symbol %s used as an immediate value"),
21733 S_GET_NAME (fixP->fx_addsy));
21734 break;
21735 }
21736
21737 newval = md_chars_to_number (buf, THUMB_SIZE);
21738 newval <<= 16;
21739 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
21740
21741 newimm = FAIL;
21742 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21743 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21744 {
21745 newimm = encode_thumb32_immediate (value);
21746 if (newimm == (unsigned int) FAIL)
21747 newimm = thumb32_negate_data_op (&newval, value);
21748 }
21749 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
21750 && newimm == (unsigned int) FAIL)
21751 {
21752 /* Turn add/sum into addw/subw. */
21753 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21754 newval = (newval & 0xfeffffff) | 0x02000000;
21755 /* No flat 12-bit imm encoding for addsw/subsw. */
21756 if ((newval & 0x00100000) == 0)
21757 {
21758 /* 12 bit immediate for addw/subw. */
21759 if (value < 0)
21760 {
21761 value = -value;
21762 newval ^= 0x00a00000;
21763 }
21764 if (value > 0xfff)
21765 newimm = (unsigned int) FAIL;
21766 else
21767 newimm = value;
21768 }
21769 }
21770
21771 if (newimm == (unsigned int)FAIL)
21772 {
21773 as_bad_where (fixP->fx_file, fixP->fx_line,
21774 _("invalid constant (%lx) after fixup"),
21775 (unsigned long) value);
21776 break;
21777 }
21778
21779 newval |= (newimm & 0x800) << 15;
21780 newval |= (newimm & 0x700) << 4;
21781 newval |= (newimm & 0x0ff);
21782
21783 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
21784 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
21785 break;
21786
21787 case BFD_RELOC_ARM_SMC:
21788 if (((unsigned long) value) > 0xffff)
21789 as_bad_where (fixP->fx_file, fixP->fx_line,
21790 _("invalid smc expression"));
21791 newval = md_chars_to_number (buf, INSN_SIZE);
21792 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21793 md_number_to_chars (buf, newval, INSN_SIZE);
21794 break;
21795
21796 case BFD_RELOC_ARM_HVC:
21797 if (((unsigned long) value) > 0xffff)
21798 as_bad_where (fixP->fx_file, fixP->fx_line,
21799 _("invalid hvc expression"));
21800 newval = md_chars_to_number (buf, INSN_SIZE);
21801 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21802 md_number_to_chars (buf, newval, INSN_SIZE);
21803 break;
21804
21805 case BFD_RELOC_ARM_SWI:
21806 if (fixP->tc_fix_data != 0)
21807 {
21808 if (((unsigned long) value) > 0xff)
21809 as_bad_where (fixP->fx_file, fixP->fx_line,
21810 _("invalid swi expression"));
21811 newval = md_chars_to_number (buf, THUMB_SIZE);
21812 newval |= value;
21813 md_number_to_chars (buf, newval, THUMB_SIZE);
21814 }
21815 else
21816 {
21817 if (((unsigned long) value) > 0x00ffffff)
21818 as_bad_where (fixP->fx_file, fixP->fx_line,
21819 _("invalid swi expression"));
21820 newval = md_chars_to_number (buf, INSN_SIZE);
21821 newval |= value;
21822 md_number_to_chars (buf, newval, INSN_SIZE);
21823 }
21824 break;
21825
21826 case BFD_RELOC_ARM_MULTI:
21827 if (((unsigned long) value) > 0xffff)
21828 as_bad_where (fixP->fx_file, fixP->fx_line,
21829 _("invalid expression in load/store multiple"));
21830 newval = value | md_chars_to_number (buf, INSN_SIZE);
21831 md_number_to_chars (buf, newval, INSN_SIZE);
21832 break;
21833
21834 #ifdef OBJ_ELF
21835 case BFD_RELOC_ARM_PCREL_CALL:
21836
21837 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21838 && fixP->fx_addsy
21839 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21841 && THUMB_IS_FUNC (fixP->fx_addsy))
21842 /* Flip the bl to blx. This is a simple flip
21843 bit here because we generate PCREL_CALL for
21844 unconditional bls. */
21845 {
21846 newval = md_chars_to_number (buf, INSN_SIZE);
21847 newval = newval | 0x10000000;
21848 md_number_to_chars (buf, newval, INSN_SIZE);
21849 temp = 1;
21850 fixP->fx_done = 1;
21851 }
21852 else
21853 temp = 3;
21854 goto arm_branch_common;
21855
21856 case BFD_RELOC_ARM_PCREL_JUMP:
21857 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21858 && fixP->fx_addsy
21859 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21860 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21861 && THUMB_IS_FUNC (fixP->fx_addsy))
21862 {
21863 /* This would map to a bl<cond>, b<cond>,
21864 b<always> to a Thumb function. We
21865 need to force a relocation for this particular
21866 case. */
21867 newval = md_chars_to_number (buf, INSN_SIZE);
21868 fixP->fx_done = 0;
21869 }
21870
21871 case BFD_RELOC_ARM_PLT32:
21872 #endif
21873 case BFD_RELOC_ARM_PCREL_BRANCH:
21874 temp = 3;
21875 goto arm_branch_common;
21876
21877 case BFD_RELOC_ARM_PCREL_BLX:
21878
21879 temp = 1;
21880 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21881 && fixP->fx_addsy
21882 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21883 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21884 && ARM_IS_FUNC (fixP->fx_addsy))
21885 {
21886 /* Flip the blx to a bl and warn. */
21887 const char *name = S_GET_NAME (fixP->fx_addsy);
21888 newval = 0xeb000000;
21889 as_warn_where (fixP->fx_file, fixP->fx_line,
21890 _("blx to '%s' an ARM ISA state function changed to bl"),
21891 name);
21892 md_number_to_chars (buf, newval, INSN_SIZE);
21893 temp = 3;
21894 fixP->fx_done = 1;
21895 }
21896
21897 #ifdef OBJ_ELF
21898 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21899 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21900 #endif
21901
21902 arm_branch_common:
21903 /* We are going to store value (shifted right by two) in the
21904 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21905 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21906 also be be clear. */
21907 if (value & temp)
21908 as_bad_where (fixP->fx_file, fixP->fx_line,
21909 _("misaligned branch destination"));
21910 if ((value & (offsetT)0xfe000000) != (offsetT)0
21911 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
21912 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21913
21914 if (fixP->fx_done || !seg->use_rela_p)
21915 {
21916 newval = md_chars_to_number (buf, INSN_SIZE);
21917 newval |= (value >> 2) & 0x00ffffff;
21918 /* Set the H bit on BLX instructions. */
21919 if (temp == 1)
21920 {
21921 if (value & 2)
21922 newval |= 0x01000000;
21923 else
21924 newval &= ~0x01000000;
21925 }
21926 md_number_to_chars (buf, newval, INSN_SIZE);
21927 }
21928 break;
21929
21930 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21931 /* CBZ can only branch forward. */
21932
21933 /* Attempts to use CBZ to branch to the next instruction
21934 (which, strictly speaking, are prohibited) will be turned into
21935 no-ops.
21936
21937 FIXME: It may be better to remove the instruction completely and
21938 perform relaxation. */
21939 if (value == -2)
21940 {
21941 newval = md_chars_to_number (buf, THUMB_SIZE);
21942 newval = 0xbf00; /* NOP encoding T1 */
21943 md_number_to_chars (buf, newval, THUMB_SIZE);
21944 }
21945 else
21946 {
21947 if (value & ~0x7e)
21948 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21949
21950 if (fixP->fx_done || !seg->use_rela_p)
21951 {
21952 newval = md_chars_to_number (buf, THUMB_SIZE);
21953 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21954 md_number_to_chars (buf, newval, THUMB_SIZE);
21955 }
21956 }
21957 break;
21958
21959 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
21960 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
21961 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21962
21963 if (fixP->fx_done || !seg->use_rela_p)
21964 {
21965 newval = md_chars_to_number (buf, THUMB_SIZE);
21966 newval |= (value & 0x1ff) >> 1;
21967 md_number_to_chars (buf, newval, THUMB_SIZE);
21968 }
21969 break;
21970
21971 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
21972 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
21973 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21974
21975 if (fixP->fx_done || !seg->use_rela_p)
21976 {
21977 newval = md_chars_to_number (buf, THUMB_SIZE);
21978 newval |= (value & 0xfff) >> 1;
21979 md_number_to_chars (buf, newval, THUMB_SIZE);
21980 }
21981 break;
21982
21983 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21984 if (fixP->fx_addsy
21985 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21986 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21987 && ARM_IS_FUNC (fixP->fx_addsy)
21988 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21989 {
21990 /* Force a relocation for a branch 20 bits wide. */
21991 fixP->fx_done = 0;
21992 }
21993 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
21994 as_bad_where (fixP->fx_file, fixP->fx_line,
21995 _("conditional branch out of range"));
21996
21997 if (fixP->fx_done || !seg->use_rela_p)
21998 {
21999 offsetT newval2;
22000 addressT S, J1, J2, lo, hi;
22001
22002 S = (value & 0x00100000) >> 20;
22003 J2 = (value & 0x00080000) >> 19;
22004 J1 = (value & 0x00040000) >> 18;
22005 hi = (value & 0x0003f000) >> 12;
22006 lo = (value & 0x00000ffe) >> 1;
22007
22008 newval = md_chars_to_number (buf, THUMB_SIZE);
22009 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22010 newval |= (S << 10) | hi;
22011 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22012 md_number_to_chars (buf, newval, THUMB_SIZE);
22013 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22014 }
22015 break;
22016
22017 case BFD_RELOC_THUMB_PCREL_BLX:
22018 /* If there is a blx from a thumb state function to
22019 another thumb function flip this to a bl and warn
22020 about it. */
22021
22022 if (fixP->fx_addsy
22023 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22024 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22025 && THUMB_IS_FUNC (fixP->fx_addsy))
22026 {
22027 const char *name = S_GET_NAME (fixP->fx_addsy);
22028 as_warn_where (fixP->fx_file, fixP->fx_line,
22029 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22030 name);
22031 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22032 newval = newval | 0x1000;
22033 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22034 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22035 fixP->fx_done = 1;
22036 }
22037
22038
22039 goto thumb_bl_common;
22040
22041 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22042 /* A bl from Thumb state ISA to an internal ARM state function
22043 is converted to a blx. */
22044 if (fixP->fx_addsy
22045 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22046 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22047 && ARM_IS_FUNC (fixP->fx_addsy)
22048 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22049 {
22050 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22051 newval = newval & ~0x1000;
22052 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22053 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22054 fixP->fx_done = 1;
22055 }
22056
22057 thumb_bl_common:
22058
22059 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22060 /* For a BLX instruction, make sure that the relocation is rounded up
22061 to a word boundary. This follows the semantics of the instruction
22062 which specifies that bit 1 of the target address will come from bit
22063 1 of the base address. */
22064 value = (value + 3) & ~ 3;
22065
22066 #ifdef OBJ_ELF
22067 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22068 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22069 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22070 #endif
22071
22072 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22073 {
22074 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22075 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22076 else if ((value & ~0x1ffffff)
22077 && ((value & ~0x1ffffff) != ~0x1ffffff))
22078 as_bad_where (fixP->fx_file, fixP->fx_line,
22079 _("Thumb2 branch out of range"));
22080 }
22081
22082 if (fixP->fx_done || !seg->use_rela_p)
22083 encode_thumb2_b_bl_offset (buf, value);
22084
22085 break;
22086
22087 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22088 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22089 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22090
22091 if (fixP->fx_done || !seg->use_rela_p)
22092 encode_thumb2_b_bl_offset (buf, value);
22093
22094 break;
22095
22096 case BFD_RELOC_8:
22097 if (fixP->fx_done || !seg->use_rela_p)
22098 md_number_to_chars (buf, value, 1);
22099 break;
22100
22101 case BFD_RELOC_16:
22102 if (fixP->fx_done || !seg->use_rela_p)
22103 md_number_to_chars (buf, value, 2);
22104 break;
22105
22106 #ifdef OBJ_ELF
22107 case BFD_RELOC_ARM_TLS_CALL:
22108 case BFD_RELOC_ARM_THM_TLS_CALL:
22109 case BFD_RELOC_ARM_TLS_DESCSEQ:
22110 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22111 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22112 break;
22113
22114 case BFD_RELOC_ARM_TLS_GOTDESC:
22115 case BFD_RELOC_ARM_TLS_GD32:
22116 case BFD_RELOC_ARM_TLS_LE32:
22117 case BFD_RELOC_ARM_TLS_IE32:
22118 case BFD_RELOC_ARM_TLS_LDM32:
22119 case BFD_RELOC_ARM_TLS_LDO32:
22120 S_SET_THREAD_LOCAL (fixP->fx_addsy);
22121 /* fall through */
22122
22123 case BFD_RELOC_ARM_GOT32:
22124 case BFD_RELOC_ARM_GOTOFF:
22125 if (fixP->fx_done || !seg->use_rela_p)
22126 md_number_to_chars (buf, 0, 4);
22127 break;
22128
22129 case BFD_RELOC_ARM_GOT_PREL:
22130 if (fixP->fx_done || !seg->use_rela_p)
22131 md_number_to_chars (buf, value, 4);
22132 break;
22133
22134 case BFD_RELOC_ARM_TARGET2:
22135 /* TARGET2 is not partial-inplace, so we need to write the
22136 addend here for REL targets, because it won't be written out
22137 during reloc processing later. */
22138 if (fixP->fx_done || !seg->use_rela_p)
22139 md_number_to_chars (buf, fixP->fx_offset, 4);
22140 break;
22141 #endif
22142
22143 case BFD_RELOC_RVA:
22144 case BFD_RELOC_32:
22145 case BFD_RELOC_ARM_TARGET1:
22146 case BFD_RELOC_ARM_ROSEGREL32:
22147 case BFD_RELOC_ARM_SBREL32:
22148 case BFD_RELOC_32_PCREL:
22149 #ifdef TE_PE
22150 case BFD_RELOC_32_SECREL:
22151 #endif
22152 if (fixP->fx_done || !seg->use_rela_p)
22153 #ifdef TE_WINCE
22154 /* For WinCE we only do this for pcrel fixups. */
22155 if (fixP->fx_done || fixP->fx_pcrel)
22156 #endif
22157 md_number_to_chars (buf, value, 4);
22158 break;
22159
22160 #ifdef OBJ_ELF
22161 case BFD_RELOC_ARM_PREL31:
22162 if (fixP->fx_done || !seg->use_rela_p)
22163 {
22164 newval = md_chars_to_number (buf, 4) & 0x80000000;
22165 if ((value ^ (value >> 1)) & 0x40000000)
22166 {
22167 as_bad_where (fixP->fx_file, fixP->fx_line,
22168 _("rel31 relocation overflow"));
22169 }
22170 newval |= value & 0x7fffffff;
22171 md_number_to_chars (buf, newval, 4);
22172 }
22173 break;
22174 #endif
22175
22176 case BFD_RELOC_ARM_CP_OFF_IMM:
22177 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
22178 if (value < -1023 || value > 1023 || (value & 3))
22179 as_bad_where (fixP->fx_file, fixP->fx_line,
22180 _("co-processor offset out of range"));
22181 cp_off_common:
22182 sign = value > 0;
22183 if (value < 0)
22184 value = -value;
22185 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22186 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22187 newval = md_chars_to_number (buf, INSN_SIZE);
22188 else
22189 newval = get_thumb32_insn (buf);
22190 if (value == 0)
22191 newval &= 0xffffff00;
22192 else
22193 {
22194 newval &= 0xff7fff00;
22195 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22196 }
22197 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22198 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22199 md_number_to_chars (buf, newval, INSN_SIZE);
22200 else
22201 put_thumb32_insn (buf, newval);
22202 break;
22203
22204 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
22205 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
22206 if (value < -255 || value > 255)
22207 as_bad_where (fixP->fx_file, fixP->fx_line,
22208 _("co-processor offset out of range"));
22209 value *= 4;
22210 goto cp_off_common;
22211
22212 case BFD_RELOC_ARM_THUMB_OFFSET:
22213 newval = md_chars_to_number (buf, THUMB_SIZE);
22214 /* Exactly what ranges, and where the offset is inserted depends
22215 on the type of instruction, we can establish this from the
22216 top 4 bits. */
22217 switch (newval >> 12)
22218 {
22219 case 4: /* PC load. */
22220 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22221 forced to zero for these loads; md_pcrel_from has already
22222 compensated for this. */
22223 if (value & 3)
22224 as_bad_where (fixP->fx_file, fixP->fx_line,
22225 _("invalid offset, target not word aligned (0x%08lX)"),
22226 (((unsigned long) fixP->fx_frag->fr_address
22227 + (unsigned long) fixP->fx_where) & ~3)
22228 + (unsigned long) value);
22229
22230 if (value & ~0x3fc)
22231 as_bad_where (fixP->fx_file, fixP->fx_line,
22232 _("invalid offset, value too big (0x%08lX)"),
22233 (long) value);
22234
22235 newval |= value >> 2;
22236 break;
22237
22238 case 9: /* SP load/store. */
22239 if (value & ~0x3fc)
22240 as_bad_where (fixP->fx_file, fixP->fx_line,
22241 _("invalid offset, value too big (0x%08lX)"),
22242 (long) value);
22243 newval |= value >> 2;
22244 break;
22245
22246 case 6: /* Word load/store. */
22247 if (value & ~0x7c)
22248 as_bad_where (fixP->fx_file, fixP->fx_line,
22249 _("invalid offset, value too big (0x%08lX)"),
22250 (long) value);
22251 newval |= value << 4; /* 6 - 2. */
22252 break;
22253
22254 case 7: /* Byte load/store. */
22255 if (value & ~0x1f)
22256 as_bad_where (fixP->fx_file, fixP->fx_line,
22257 _("invalid offset, value too big (0x%08lX)"),
22258 (long) value);
22259 newval |= value << 6;
22260 break;
22261
22262 case 8: /* Halfword load/store. */
22263 if (value & ~0x3e)
22264 as_bad_where (fixP->fx_file, fixP->fx_line,
22265 _("invalid offset, value too big (0x%08lX)"),
22266 (long) value);
22267 newval |= value << 5; /* 6 - 1. */
22268 break;
22269
22270 default:
22271 as_bad_where (fixP->fx_file, fixP->fx_line,
22272 "Unable to process relocation for thumb opcode: %lx",
22273 (unsigned long) newval);
22274 break;
22275 }
22276 md_number_to_chars (buf, newval, THUMB_SIZE);
22277 break;
22278
22279 case BFD_RELOC_ARM_THUMB_ADD:
22280 /* This is a complicated relocation, since we use it for all of
22281 the following immediate relocations:
22282
22283 3bit ADD/SUB
22284 8bit ADD/SUB
22285 9bit ADD/SUB SP word-aligned
22286 10bit ADD PC/SP word-aligned
22287
22288 The type of instruction being processed is encoded in the
22289 instruction field:
22290
22291 0x8000 SUB
22292 0x00F0 Rd
22293 0x000F Rs
22294 */
22295 newval = md_chars_to_number (buf, THUMB_SIZE);
22296 {
22297 int rd = (newval >> 4) & 0xf;
22298 int rs = newval & 0xf;
22299 int subtract = !!(newval & 0x8000);
22300
22301 /* Check for HI regs, only very restricted cases allowed:
22302 Adjusting SP, and using PC or SP to get an address. */
22303 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
22304 || (rs > 7 && rs != REG_SP && rs != REG_PC))
22305 as_bad_where (fixP->fx_file, fixP->fx_line,
22306 _("invalid Hi register with immediate"));
22307
22308 /* If value is negative, choose the opposite instruction. */
22309 if (value < 0)
22310 {
22311 value = -value;
22312 subtract = !subtract;
22313 if (value < 0)
22314 as_bad_where (fixP->fx_file, fixP->fx_line,
22315 _("immediate value out of range"));
22316 }
22317
22318 if (rd == REG_SP)
22319 {
22320 if (value & ~0x1fc)
22321 as_bad_where (fixP->fx_file, fixP->fx_line,
22322 _("invalid immediate for stack address calculation"));
22323 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
22324 newval |= value >> 2;
22325 }
22326 else if (rs == REG_PC || rs == REG_SP)
22327 {
22328 if (subtract || value & ~0x3fc)
22329 as_bad_where (fixP->fx_file, fixP->fx_line,
22330 _("invalid immediate for address calculation (value = 0x%08lX)"),
22331 (unsigned long) value);
22332 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
22333 newval |= rd << 8;
22334 newval |= value >> 2;
22335 }
22336 else if (rs == rd)
22337 {
22338 if (value & ~0xff)
22339 as_bad_where (fixP->fx_file, fixP->fx_line,
22340 _("immediate value out of range"));
22341 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
22342 newval |= (rd << 8) | value;
22343 }
22344 else
22345 {
22346 if (value & ~0x7)
22347 as_bad_where (fixP->fx_file, fixP->fx_line,
22348 _("immediate value out of range"));
22349 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
22350 newval |= rd | (rs << 3) | (value << 6);
22351 }
22352 }
22353 md_number_to_chars (buf, newval, THUMB_SIZE);
22354 break;
22355
22356 case BFD_RELOC_ARM_THUMB_IMM:
22357 newval = md_chars_to_number (buf, THUMB_SIZE);
22358 if (value < 0 || value > 255)
22359 as_bad_where (fixP->fx_file, fixP->fx_line,
22360 _("invalid immediate: %ld is out of range"),
22361 (long) value);
22362 newval |= value;
22363 md_number_to_chars (buf, newval, THUMB_SIZE);
22364 break;
22365
22366 case BFD_RELOC_ARM_THUMB_SHIFT:
22367 /* 5bit shift value (0..32). LSL cannot take 32. */
22368 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
22369 temp = newval & 0xf800;
22370 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
22371 as_bad_where (fixP->fx_file, fixP->fx_line,
22372 _("invalid shift value: %ld"), (long) value);
22373 /* Shifts of zero must be encoded as LSL. */
22374 if (value == 0)
22375 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
22376 /* Shifts of 32 are encoded as zero. */
22377 else if (value == 32)
22378 value = 0;
22379 newval |= value << 6;
22380 md_number_to_chars (buf, newval, THUMB_SIZE);
22381 break;
22382
22383 case BFD_RELOC_VTABLE_INHERIT:
22384 case BFD_RELOC_VTABLE_ENTRY:
22385 fixP->fx_done = 0;
22386 return;
22387
22388 case BFD_RELOC_ARM_MOVW:
22389 case BFD_RELOC_ARM_MOVT:
22390 case BFD_RELOC_ARM_THUMB_MOVW:
22391 case BFD_RELOC_ARM_THUMB_MOVT:
22392 if (fixP->fx_done || !seg->use_rela_p)
22393 {
22394 /* REL format relocations are limited to a 16-bit addend. */
22395 if (!fixP->fx_done)
22396 {
22397 if (value < -0x8000 || value > 0x7fff)
22398 as_bad_where (fixP->fx_file, fixP->fx_line,
22399 _("offset out of range"));
22400 }
22401 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22402 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22403 {
22404 value >>= 16;
22405 }
22406
22407 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22408 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
22409 {
22410 newval = get_thumb32_insn (buf);
22411 newval &= 0xfbf08f00;
22412 newval |= (value & 0xf000) << 4;
22413 newval |= (value & 0x0800) << 15;
22414 newval |= (value & 0x0700) << 4;
22415 newval |= (value & 0x00ff);
22416 put_thumb32_insn (buf, newval);
22417 }
22418 else
22419 {
22420 newval = md_chars_to_number (buf, 4);
22421 newval &= 0xfff0f000;
22422 newval |= value & 0x0fff;
22423 newval |= (value & 0xf000) << 4;
22424 md_number_to_chars (buf, newval, 4);
22425 }
22426 }
22427 return;
22428
22429 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22430 case BFD_RELOC_ARM_ALU_PC_G0:
22431 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22432 case BFD_RELOC_ARM_ALU_PC_G1:
22433 case BFD_RELOC_ARM_ALU_PC_G2:
22434 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22435 case BFD_RELOC_ARM_ALU_SB_G0:
22436 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22437 case BFD_RELOC_ARM_ALU_SB_G1:
22438 case BFD_RELOC_ARM_ALU_SB_G2:
22439 gas_assert (!fixP->fx_done);
22440 if (!seg->use_rela_p)
22441 {
22442 bfd_vma insn;
22443 bfd_vma encoded_addend;
22444 bfd_vma addend_abs = abs (value);
22445
22446 /* Check that the absolute value of the addend can be
22447 expressed as an 8-bit constant plus a rotation. */
22448 encoded_addend = encode_arm_immediate (addend_abs);
22449 if (encoded_addend == (unsigned int) FAIL)
22450 as_bad_where (fixP->fx_file, fixP->fx_line,
22451 _("the offset 0x%08lX is not representable"),
22452 (unsigned long) addend_abs);
22453
22454 /* Extract the instruction. */
22455 insn = md_chars_to_number (buf, INSN_SIZE);
22456
22457 /* If the addend is positive, use an ADD instruction.
22458 Otherwise use a SUB. Take care not to destroy the S bit. */
22459 insn &= 0xff1fffff;
22460 if (value < 0)
22461 insn |= 1 << 22;
22462 else
22463 insn |= 1 << 23;
22464
22465 /* Place the encoded addend into the first 12 bits of the
22466 instruction. */
22467 insn &= 0xfffff000;
22468 insn |= encoded_addend;
22469
22470 /* Update the instruction. */
22471 md_number_to_chars (buf, insn, INSN_SIZE);
22472 }
22473 break;
22474
22475 case BFD_RELOC_ARM_LDR_PC_G0:
22476 case BFD_RELOC_ARM_LDR_PC_G1:
22477 case BFD_RELOC_ARM_LDR_PC_G2:
22478 case BFD_RELOC_ARM_LDR_SB_G0:
22479 case BFD_RELOC_ARM_LDR_SB_G1:
22480 case BFD_RELOC_ARM_LDR_SB_G2:
22481 gas_assert (!fixP->fx_done);
22482 if (!seg->use_rela_p)
22483 {
22484 bfd_vma insn;
22485 bfd_vma addend_abs = abs (value);
22486
22487 /* Check that the absolute value of the addend can be
22488 encoded in 12 bits. */
22489 if (addend_abs >= 0x1000)
22490 as_bad_where (fixP->fx_file, fixP->fx_line,
22491 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
22492 (unsigned long) addend_abs);
22493
22494 /* Extract the instruction. */
22495 insn = md_chars_to_number (buf, INSN_SIZE);
22496
22497 /* If the addend is negative, clear bit 23 of the instruction.
22498 Otherwise set it. */
22499 if (value < 0)
22500 insn &= ~(1 << 23);
22501 else
22502 insn |= 1 << 23;
22503
22504 /* Place the absolute value of the addend into the first 12 bits
22505 of the instruction. */
22506 insn &= 0xfffff000;
22507 insn |= addend_abs;
22508
22509 /* Update the instruction. */
22510 md_number_to_chars (buf, insn, INSN_SIZE);
22511 }
22512 break;
22513
22514 case BFD_RELOC_ARM_LDRS_PC_G0:
22515 case BFD_RELOC_ARM_LDRS_PC_G1:
22516 case BFD_RELOC_ARM_LDRS_PC_G2:
22517 case BFD_RELOC_ARM_LDRS_SB_G0:
22518 case BFD_RELOC_ARM_LDRS_SB_G1:
22519 case BFD_RELOC_ARM_LDRS_SB_G2:
22520 gas_assert (!fixP->fx_done);
22521 if (!seg->use_rela_p)
22522 {
22523 bfd_vma insn;
22524 bfd_vma addend_abs = abs (value);
22525
22526 /* Check that the absolute value of the addend can be
22527 encoded in 8 bits. */
22528 if (addend_abs >= 0x100)
22529 as_bad_where (fixP->fx_file, fixP->fx_line,
22530 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
22531 (unsigned long) addend_abs);
22532
22533 /* Extract the instruction. */
22534 insn = md_chars_to_number (buf, INSN_SIZE);
22535
22536 /* If the addend is negative, clear bit 23 of the instruction.
22537 Otherwise set it. */
22538 if (value < 0)
22539 insn &= ~(1 << 23);
22540 else
22541 insn |= 1 << 23;
22542
22543 /* Place the first four bits of the absolute value of the addend
22544 into the first 4 bits of the instruction, and the remaining
22545 four into bits 8 .. 11. */
22546 insn &= 0xfffff0f0;
22547 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
22548
22549 /* Update the instruction. */
22550 md_number_to_chars (buf, insn, INSN_SIZE);
22551 }
22552 break;
22553
22554 case BFD_RELOC_ARM_LDC_PC_G0:
22555 case BFD_RELOC_ARM_LDC_PC_G1:
22556 case BFD_RELOC_ARM_LDC_PC_G2:
22557 case BFD_RELOC_ARM_LDC_SB_G0:
22558 case BFD_RELOC_ARM_LDC_SB_G1:
22559 case BFD_RELOC_ARM_LDC_SB_G2:
22560 gas_assert (!fixP->fx_done);
22561 if (!seg->use_rela_p)
22562 {
22563 bfd_vma insn;
22564 bfd_vma addend_abs = abs (value);
22565
22566 /* Check that the absolute value of the addend is a multiple of
22567 four and, when divided by four, fits in 8 bits. */
22568 if (addend_abs & 0x3)
22569 as_bad_where (fixP->fx_file, fixP->fx_line,
22570 _("bad offset 0x%08lX (must be word-aligned)"),
22571 (unsigned long) addend_abs);
22572
22573 if ((addend_abs >> 2) > 0xff)
22574 as_bad_where (fixP->fx_file, fixP->fx_line,
22575 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
22576 (unsigned long) addend_abs);
22577
22578 /* Extract the instruction. */
22579 insn = md_chars_to_number (buf, INSN_SIZE);
22580
22581 /* If the addend is negative, clear bit 23 of the instruction.
22582 Otherwise set it. */
22583 if (value < 0)
22584 insn &= ~(1 << 23);
22585 else
22586 insn |= 1 << 23;
22587
22588 /* Place the addend (divided by four) into the first eight
22589 bits of the instruction. */
22590 insn &= 0xfffffff0;
22591 insn |= addend_abs >> 2;
22592
22593 /* Update the instruction. */
22594 md_number_to_chars (buf, insn, INSN_SIZE);
22595 }
22596 break;
22597
22598 case BFD_RELOC_ARM_V4BX:
22599 /* This will need to go in the object file. */
22600 fixP->fx_done = 0;
22601 break;
22602
22603 case BFD_RELOC_UNUSED:
22604 default:
22605 as_bad_where (fixP->fx_file, fixP->fx_line,
22606 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
22607 }
22608 }
22609
22610 /* Translate internal representation of relocation info to BFD target
22611 format. */
22612
22613 arelent *
22614 tc_gen_reloc (asection *section, fixS *fixp)
22615 {
22616 arelent * reloc;
22617 bfd_reloc_code_real_type code;
22618
22619 reloc = (arelent *) xmalloc (sizeof (arelent));
22620
22621 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
22622 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
22623 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
22624
22625 if (fixp->fx_pcrel)
22626 {
22627 if (section->use_rela_p)
22628 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
22629 else
22630 fixp->fx_offset = reloc->address;
22631 }
22632 reloc->addend = fixp->fx_offset;
22633
22634 switch (fixp->fx_r_type)
22635 {
22636 case BFD_RELOC_8:
22637 if (fixp->fx_pcrel)
22638 {
22639 code = BFD_RELOC_8_PCREL;
22640 break;
22641 }
22642
22643 case BFD_RELOC_16:
22644 if (fixp->fx_pcrel)
22645 {
22646 code = BFD_RELOC_16_PCREL;
22647 break;
22648 }
22649
22650 case BFD_RELOC_32:
22651 if (fixp->fx_pcrel)
22652 {
22653 code = BFD_RELOC_32_PCREL;
22654 break;
22655 }
22656
22657 case BFD_RELOC_ARM_MOVW:
22658 if (fixp->fx_pcrel)
22659 {
22660 code = BFD_RELOC_ARM_MOVW_PCREL;
22661 break;
22662 }
22663
22664 case BFD_RELOC_ARM_MOVT:
22665 if (fixp->fx_pcrel)
22666 {
22667 code = BFD_RELOC_ARM_MOVT_PCREL;
22668 break;
22669 }
22670
22671 case BFD_RELOC_ARM_THUMB_MOVW:
22672 if (fixp->fx_pcrel)
22673 {
22674 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
22675 break;
22676 }
22677
22678 case BFD_RELOC_ARM_THUMB_MOVT:
22679 if (fixp->fx_pcrel)
22680 {
22681 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
22682 break;
22683 }
22684
22685 case BFD_RELOC_NONE:
22686 case BFD_RELOC_ARM_PCREL_BRANCH:
22687 case BFD_RELOC_ARM_PCREL_BLX:
22688 case BFD_RELOC_RVA:
22689 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22690 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22691 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22692 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22693 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22694 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22695 case BFD_RELOC_VTABLE_ENTRY:
22696 case BFD_RELOC_VTABLE_INHERIT:
22697 #ifdef TE_PE
22698 case BFD_RELOC_32_SECREL:
22699 #endif
22700 code = fixp->fx_r_type;
22701 break;
22702
22703 case BFD_RELOC_THUMB_PCREL_BLX:
22704 #ifdef OBJ_ELF
22705 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
22706 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
22707 else
22708 #endif
22709 code = BFD_RELOC_THUMB_PCREL_BLX;
22710 break;
22711
22712 case BFD_RELOC_ARM_LITERAL:
22713 case BFD_RELOC_ARM_HWLITERAL:
22714 /* If this is called then the a literal has
22715 been referenced across a section boundary. */
22716 as_bad_where (fixp->fx_file, fixp->fx_line,
22717 _("literal referenced across section boundary"));
22718 return NULL;
22719
22720 #ifdef OBJ_ELF
22721 case BFD_RELOC_ARM_TLS_CALL:
22722 case BFD_RELOC_ARM_THM_TLS_CALL:
22723 case BFD_RELOC_ARM_TLS_DESCSEQ:
22724 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22725 case BFD_RELOC_ARM_GOT32:
22726 case BFD_RELOC_ARM_GOTOFF:
22727 case BFD_RELOC_ARM_GOT_PREL:
22728 case BFD_RELOC_ARM_PLT32:
22729 case BFD_RELOC_ARM_TARGET1:
22730 case BFD_RELOC_ARM_ROSEGREL32:
22731 case BFD_RELOC_ARM_SBREL32:
22732 case BFD_RELOC_ARM_PREL31:
22733 case BFD_RELOC_ARM_TARGET2:
22734 case BFD_RELOC_ARM_TLS_LE32:
22735 case BFD_RELOC_ARM_TLS_LDO32:
22736 case BFD_RELOC_ARM_PCREL_CALL:
22737 case BFD_RELOC_ARM_PCREL_JUMP:
22738 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22739 case BFD_RELOC_ARM_ALU_PC_G0:
22740 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22741 case BFD_RELOC_ARM_ALU_PC_G1:
22742 case BFD_RELOC_ARM_ALU_PC_G2:
22743 case BFD_RELOC_ARM_LDR_PC_G0:
22744 case BFD_RELOC_ARM_LDR_PC_G1:
22745 case BFD_RELOC_ARM_LDR_PC_G2:
22746 case BFD_RELOC_ARM_LDRS_PC_G0:
22747 case BFD_RELOC_ARM_LDRS_PC_G1:
22748 case BFD_RELOC_ARM_LDRS_PC_G2:
22749 case BFD_RELOC_ARM_LDC_PC_G0:
22750 case BFD_RELOC_ARM_LDC_PC_G1:
22751 case BFD_RELOC_ARM_LDC_PC_G2:
22752 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22753 case BFD_RELOC_ARM_ALU_SB_G0:
22754 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22755 case BFD_RELOC_ARM_ALU_SB_G1:
22756 case BFD_RELOC_ARM_ALU_SB_G2:
22757 case BFD_RELOC_ARM_LDR_SB_G0:
22758 case BFD_RELOC_ARM_LDR_SB_G1:
22759 case BFD_RELOC_ARM_LDR_SB_G2:
22760 case BFD_RELOC_ARM_LDRS_SB_G0:
22761 case BFD_RELOC_ARM_LDRS_SB_G1:
22762 case BFD_RELOC_ARM_LDRS_SB_G2:
22763 case BFD_RELOC_ARM_LDC_SB_G0:
22764 case BFD_RELOC_ARM_LDC_SB_G1:
22765 case BFD_RELOC_ARM_LDC_SB_G2:
22766 case BFD_RELOC_ARM_V4BX:
22767 code = fixp->fx_r_type;
22768 break;
22769
22770 case BFD_RELOC_ARM_TLS_GOTDESC:
22771 case BFD_RELOC_ARM_TLS_GD32:
22772 case BFD_RELOC_ARM_TLS_IE32:
22773 case BFD_RELOC_ARM_TLS_LDM32:
22774 /* BFD will include the symbol's address in the addend.
22775 But we don't want that, so subtract it out again here. */
22776 if (!S_IS_COMMON (fixp->fx_addsy))
22777 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
22778 code = fixp->fx_r_type;
22779 break;
22780 #endif
22781
22782 case BFD_RELOC_ARM_IMMEDIATE:
22783 as_bad_where (fixp->fx_file, fixp->fx_line,
22784 _("internal relocation (type: IMMEDIATE) not fixed up"));
22785 return NULL;
22786
22787 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22788 as_bad_where (fixp->fx_file, fixp->fx_line,
22789 _("ADRL used for a symbol not defined in the same file"));
22790 return NULL;
22791
22792 case BFD_RELOC_ARM_OFFSET_IMM:
22793 if (section->use_rela_p)
22794 {
22795 code = fixp->fx_r_type;
22796 break;
22797 }
22798
22799 if (fixp->fx_addsy != NULL
22800 && !S_IS_DEFINED (fixp->fx_addsy)
22801 && S_IS_LOCAL (fixp->fx_addsy))
22802 {
22803 as_bad_where (fixp->fx_file, fixp->fx_line,
22804 _("undefined local label `%s'"),
22805 S_GET_NAME (fixp->fx_addsy));
22806 return NULL;
22807 }
22808
22809 as_bad_where (fixp->fx_file, fixp->fx_line,
22810 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
22811 return NULL;
22812
22813 default:
22814 {
22815 char * type;
22816
22817 switch (fixp->fx_r_type)
22818 {
22819 case BFD_RELOC_NONE: type = "NONE"; break;
22820 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
22821 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
22822 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
22823 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
22824 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
22825 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
22826 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
22827 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
22828 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
22829 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
22830 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
22831 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
22832 default: type = _("<unknown>"); break;
22833 }
22834 as_bad_where (fixp->fx_file, fixp->fx_line,
22835 _("cannot represent %s relocation in this object file format"),
22836 type);
22837 return NULL;
22838 }
22839 }
22840
22841 #ifdef OBJ_ELF
22842 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22843 && GOT_symbol
22844 && fixp->fx_addsy == GOT_symbol)
22845 {
22846 code = BFD_RELOC_ARM_GOTPC;
22847 reloc->addend = fixp->fx_offset = reloc->address;
22848 }
22849 #endif
22850
22851 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
22852
22853 if (reloc->howto == NULL)
22854 {
22855 as_bad_where (fixp->fx_file, fixp->fx_line,
22856 _("cannot represent %s relocation in this object file format"),
22857 bfd_get_reloc_code_name (code));
22858 return NULL;
22859 }
22860
22861 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22862 vtable entry to be used in the relocation's section offset. */
22863 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22864 reloc->address = fixp->fx_offset;
22865
22866 return reloc;
22867 }
22868
22869 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
22870
22871 void
22872 cons_fix_new_arm (fragS * frag,
22873 int where,
22874 int size,
22875 expressionS * exp)
22876 {
22877 bfd_reloc_code_real_type type;
22878 int pcrel = 0;
22879
22880 /* Pick a reloc.
22881 FIXME: @@ Should look at CPU word size. */
22882 switch (size)
22883 {
22884 case 1:
22885 type = BFD_RELOC_8;
22886 break;
22887 case 2:
22888 type = BFD_RELOC_16;
22889 break;
22890 case 4:
22891 default:
22892 type = BFD_RELOC_32;
22893 break;
22894 case 8:
22895 type = BFD_RELOC_64;
22896 break;
22897 }
22898
22899 #ifdef TE_PE
22900 if (exp->X_op == O_secrel)
22901 {
22902 exp->X_op = O_symbol;
22903 type = BFD_RELOC_32_SECREL;
22904 }
22905 #endif
22906
22907 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22908 }
22909
22910 #if defined (OBJ_COFF)
22911 void
22912 arm_validate_fix (fixS * fixP)
22913 {
22914 /* If the destination of the branch is a defined symbol which does not have
22915 the THUMB_FUNC attribute, then we must be calling a function which has
22916 the (interfacearm) attribute. We look for the Thumb entry point to that
22917 function and change the branch to refer to that function instead. */
22918 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22919 && fixP->fx_addsy != NULL
22920 && S_IS_DEFINED (fixP->fx_addsy)
22921 && ! THUMB_IS_FUNC (fixP->fx_addsy))
22922 {
22923 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
22924 }
22925 }
22926 #endif
22927
22928
22929 int
22930 arm_force_relocation (struct fix * fixp)
22931 {
22932 #if defined (OBJ_COFF) && defined (TE_PE)
22933 if (fixp->fx_r_type == BFD_RELOC_RVA)
22934 return 1;
22935 #endif
22936
22937 /* In case we have a call or a branch to a function in ARM ISA mode from
22938 a thumb function or vice-versa force the relocation. These relocations
22939 are cleared off for some cores that might have blx and simple transformations
22940 are possible. */
22941
22942 #ifdef OBJ_ELF
22943 switch (fixp->fx_r_type)
22944 {
22945 case BFD_RELOC_ARM_PCREL_JUMP:
22946 case BFD_RELOC_ARM_PCREL_CALL:
22947 case BFD_RELOC_THUMB_PCREL_BLX:
22948 if (THUMB_IS_FUNC (fixp->fx_addsy))
22949 return 1;
22950 break;
22951
22952 case BFD_RELOC_ARM_PCREL_BLX:
22953 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22954 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22955 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22956 if (ARM_IS_FUNC (fixp->fx_addsy))
22957 return 1;
22958 break;
22959
22960 default:
22961 break;
22962 }
22963 #endif
22964
22965 /* Resolve these relocations even if the symbol is extern or weak.
22966 Technically this is probably wrong due to symbol preemption.
22967 In practice these relocations do not have enough range to be useful
22968 at dynamic link time, and some code (e.g. in the Linux kernel)
22969 expects these references to be resolved. */
22970 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22971 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
22972 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
22973 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
22974 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22975 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22976 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
22977 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
22978 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22979 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
22980 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22981 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22982 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22983 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
22984 return 0;
22985
22986 /* Always leave these relocations for the linker. */
22987 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22988 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22989 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22990 return 1;
22991
22992 /* Always generate relocations against function symbols. */
22993 if (fixp->fx_r_type == BFD_RELOC_32
22994 && fixp->fx_addsy
22995 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22996 return 1;
22997
22998 return generic_force_reloc (fixp);
22999 }
23000
23001 #if defined (OBJ_ELF) || defined (OBJ_COFF)
23002 /* Relocations against function names must be left unadjusted,
23003 so that the linker can use this information to generate interworking
23004 stubs. The MIPS version of this function
23005 also prevents relocations that are mips-16 specific, but I do not
23006 know why it does this.
23007
23008 FIXME:
23009 There is one other problem that ought to be addressed here, but
23010 which currently is not: Taking the address of a label (rather
23011 than a function) and then later jumping to that address. Such
23012 addresses also ought to have their bottom bit set (assuming that
23013 they reside in Thumb code), but at the moment they will not. */
23014
23015 bfd_boolean
23016 arm_fix_adjustable (fixS * fixP)
23017 {
23018 if (fixP->fx_addsy == NULL)
23019 return 1;
23020
23021 /* Preserve relocations against symbols with function type. */
23022 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
23023 return FALSE;
23024
23025 if (THUMB_IS_FUNC (fixP->fx_addsy)
23026 && fixP->fx_subsy == NULL)
23027 return FALSE;
23028
23029 /* We need the symbol name for the VTABLE entries. */
23030 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23031 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23032 return FALSE;
23033
23034 /* Don't allow symbols to be discarded on GOT related relocs. */
23035 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23036 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23037 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23038 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23039 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23040 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23041 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23042 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
23043 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23044 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23045 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23046 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23047 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
23048 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
23049 return FALSE;
23050
23051 /* Similarly for group relocations. */
23052 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23053 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23054 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23055 return FALSE;
23056
23057 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23058 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23059 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23060 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23061 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23062 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23063 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23064 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23065 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
23066 return FALSE;
23067
23068 return TRUE;
23069 }
23070 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23071
23072 #ifdef OBJ_ELF
23073
23074 const char *
23075 elf32_arm_target_format (void)
23076 {
23077 #ifdef TE_SYMBIAN
23078 return (target_big_endian
23079 ? "elf32-bigarm-symbian"
23080 : "elf32-littlearm-symbian");
23081 #elif defined (TE_VXWORKS)
23082 return (target_big_endian
23083 ? "elf32-bigarm-vxworks"
23084 : "elf32-littlearm-vxworks");
23085 #elif defined (TE_NACL)
23086 return (target_big_endian
23087 ? "elf32-bigarm-nacl"
23088 : "elf32-littlearm-nacl");
23089 #else
23090 if (target_big_endian)
23091 return "elf32-bigarm";
23092 else
23093 return "elf32-littlearm";
23094 #endif
23095 }
23096
23097 void
23098 armelf_frob_symbol (symbolS * symp,
23099 int * puntp)
23100 {
23101 elf_frob_symbol (symp, puntp);
23102 }
23103 #endif
23104
23105 /* MD interface: Finalization. */
23106
23107 void
23108 arm_cleanup (void)
23109 {
23110 literal_pool * pool;
23111
23112 /* Ensure that all the IT blocks are properly closed. */
23113 check_it_blocks_finished ();
23114
23115 for (pool = list_of_pools; pool; pool = pool->next)
23116 {
23117 /* Put it at the end of the relevant section. */
23118 subseg_set (pool->section, pool->sub_section);
23119 #ifdef OBJ_ELF
23120 arm_elf_change_section ();
23121 #endif
23122 s_ltorg (0);
23123 }
23124 }
23125
23126 #ifdef OBJ_ELF
23127 /* Remove any excess mapping symbols generated for alignment frags in
23128 SEC. We may have created a mapping symbol before a zero byte
23129 alignment; remove it if there's a mapping symbol after the
23130 alignment. */
23131 static void
23132 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23133 void *dummy ATTRIBUTE_UNUSED)
23134 {
23135 segment_info_type *seginfo = seg_info (sec);
23136 fragS *fragp;
23137
23138 if (seginfo == NULL || seginfo->frchainP == NULL)
23139 return;
23140
23141 for (fragp = seginfo->frchainP->frch_root;
23142 fragp != NULL;
23143 fragp = fragp->fr_next)
23144 {
23145 symbolS *sym = fragp->tc_frag_data.last_map;
23146 fragS *next = fragp->fr_next;
23147
23148 /* Variable-sized frags have been converted to fixed size by
23149 this point. But if this was variable-sized to start with,
23150 there will be a fixed-size frag after it. So don't handle
23151 next == NULL. */
23152 if (sym == NULL || next == NULL)
23153 continue;
23154
23155 if (S_GET_VALUE (sym) < next->fr_address)
23156 /* Not at the end of this frag. */
23157 continue;
23158 know (S_GET_VALUE (sym) == next->fr_address);
23159
23160 do
23161 {
23162 if (next->tc_frag_data.first_map != NULL)
23163 {
23164 /* Next frag starts with a mapping symbol. Discard this
23165 one. */
23166 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23167 break;
23168 }
23169
23170 if (next->fr_next == NULL)
23171 {
23172 /* This mapping symbol is at the end of the section. Discard
23173 it. */
23174 know (next->fr_fix == 0 && next->fr_var == 0);
23175 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23176 break;
23177 }
23178
23179 /* As long as we have empty frags without any mapping symbols,
23180 keep looking. */
23181 /* If the next frag is non-empty and does not start with a
23182 mapping symbol, then this mapping symbol is required. */
23183 if (next->fr_address != next->fr_next->fr_address)
23184 break;
23185
23186 next = next->fr_next;
23187 }
23188 while (next != NULL);
23189 }
23190 }
23191 #endif
23192
23193 /* Adjust the symbol table. This marks Thumb symbols as distinct from
23194 ARM ones. */
23195
23196 void
23197 arm_adjust_symtab (void)
23198 {
23199 #ifdef OBJ_COFF
23200 symbolS * sym;
23201
23202 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23203 {
23204 if (ARM_IS_THUMB (sym))
23205 {
23206 if (THUMB_IS_FUNC (sym))
23207 {
23208 /* Mark the symbol as a Thumb function. */
23209 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
23210 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
23211 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
23212
23213 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
23214 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
23215 else
23216 as_bad (_("%s: unexpected function type: %d"),
23217 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
23218 }
23219 else switch (S_GET_STORAGE_CLASS (sym))
23220 {
23221 case C_EXT:
23222 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
23223 break;
23224 case C_STAT:
23225 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
23226 break;
23227 case C_LABEL:
23228 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
23229 break;
23230 default:
23231 /* Do nothing. */
23232 break;
23233 }
23234 }
23235
23236 if (ARM_IS_INTERWORK (sym))
23237 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
23238 }
23239 #endif
23240 #ifdef OBJ_ELF
23241 symbolS * sym;
23242 char bind;
23243
23244 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23245 {
23246 if (ARM_IS_THUMB (sym))
23247 {
23248 elf_symbol_type * elf_sym;
23249
23250 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
23251 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
23252
23253 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
23254 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
23255 {
23256 /* If it's a .thumb_func, declare it as so,
23257 otherwise tag label as .code 16. */
23258 if (THUMB_IS_FUNC (sym))
23259 elf_sym->internal_elf_sym.st_target_internal
23260 = ST_BRANCH_TO_THUMB;
23261 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
23262 elf_sym->internal_elf_sym.st_info =
23263 ELF_ST_INFO (bind, STT_ARM_16BIT);
23264 }
23265 }
23266 }
23267
23268 /* Remove any overlapping mapping symbols generated by alignment frags. */
23269 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
23270 /* Now do generic ELF adjustments. */
23271 elf_adjust_symtab ();
23272 #endif
23273 }
23274
23275 /* MD interface: Initialization. */
23276
23277 static void
23278 set_constant_flonums (void)
23279 {
23280 int i;
23281
23282 for (i = 0; i < NUM_FLOAT_VALS; i++)
23283 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
23284 abort ();
23285 }
23286
23287 /* Auto-select Thumb mode if it's the only available instruction set for the
23288 given architecture. */
23289
23290 static void
23291 autoselect_thumb_from_cpu_variant (void)
23292 {
23293 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23294 opcode_select (16);
23295 }
23296
23297 void
23298 md_begin (void)
23299 {
23300 unsigned mach;
23301 unsigned int i;
23302
23303 if ( (arm_ops_hsh = hash_new ()) == NULL
23304 || (arm_cond_hsh = hash_new ()) == NULL
23305 || (arm_shift_hsh = hash_new ()) == NULL
23306 || (arm_psr_hsh = hash_new ()) == NULL
23307 || (arm_v7m_psr_hsh = hash_new ()) == NULL
23308 || (arm_reg_hsh = hash_new ()) == NULL
23309 || (arm_reloc_hsh = hash_new ()) == NULL
23310 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
23311 as_fatal (_("virtual memory exhausted"));
23312
23313 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
23314 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
23315 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
23316 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
23317 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
23318 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
23319 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
23320 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
23321 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
23322 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
23323 (void *) (v7m_psrs + i));
23324 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
23325 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
23326 for (i = 0;
23327 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
23328 i++)
23329 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
23330 (void *) (barrier_opt_names + i));
23331 #ifdef OBJ_ELF
23332 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
23333 {
23334 struct reloc_entry * entry = reloc_names + i;
23335
23336 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
23337 /* This makes encode_branch() use the EABI versions of this relocation. */
23338 entry->reloc = BFD_RELOC_UNUSED;
23339
23340 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
23341 }
23342 #endif
23343
23344 set_constant_flonums ();
23345
23346 /* Set the cpu variant based on the command-line options. We prefer
23347 -mcpu= over -march= if both are set (as for GCC); and we prefer
23348 -mfpu= over any other way of setting the floating point unit.
23349 Use of legacy options with new options are faulted. */
23350 if (legacy_cpu)
23351 {
23352 if (mcpu_cpu_opt || march_cpu_opt)
23353 as_bad (_("use of old and new-style options to set CPU type"));
23354
23355 mcpu_cpu_opt = legacy_cpu;
23356 }
23357 else if (!mcpu_cpu_opt)
23358 mcpu_cpu_opt = march_cpu_opt;
23359
23360 if (legacy_fpu)
23361 {
23362 if (mfpu_opt)
23363 as_bad (_("use of old and new-style options to set FPU type"));
23364
23365 mfpu_opt = legacy_fpu;
23366 }
23367 else if (!mfpu_opt)
23368 {
23369 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
23370 || defined (TE_NetBSD) || defined (TE_VXWORKS))
23371 /* Some environments specify a default FPU. If they don't, infer it
23372 from the processor. */
23373 if (mcpu_fpu_opt)
23374 mfpu_opt = mcpu_fpu_opt;
23375 else
23376 mfpu_opt = march_fpu_opt;
23377 #else
23378 mfpu_opt = &fpu_default;
23379 #endif
23380 }
23381
23382 if (!mfpu_opt)
23383 {
23384 if (mcpu_cpu_opt != NULL)
23385 mfpu_opt = &fpu_default;
23386 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
23387 mfpu_opt = &fpu_arch_vfp_v2;
23388 else
23389 mfpu_opt = &fpu_arch_fpa;
23390 }
23391
23392 #ifdef CPU_DEFAULT
23393 if (!mcpu_cpu_opt)
23394 {
23395 mcpu_cpu_opt = &cpu_default;
23396 selected_cpu = cpu_default;
23397 }
23398 #else
23399 if (mcpu_cpu_opt)
23400 selected_cpu = *mcpu_cpu_opt;
23401 else
23402 mcpu_cpu_opt = &arm_arch_any;
23403 #endif
23404
23405 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23406
23407 autoselect_thumb_from_cpu_variant ();
23408
23409 arm_arch_used = thumb_arch_used = arm_arch_none;
23410
23411 #if defined OBJ_COFF || defined OBJ_ELF
23412 {
23413 unsigned int flags = 0;
23414
23415 #if defined OBJ_ELF
23416 flags = meabi_flags;
23417
23418 switch (meabi_flags)
23419 {
23420 case EF_ARM_EABI_UNKNOWN:
23421 #endif
23422 /* Set the flags in the private structure. */
23423 if (uses_apcs_26) flags |= F_APCS26;
23424 if (support_interwork) flags |= F_INTERWORK;
23425 if (uses_apcs_float) flags |= F_APCS_FLOAT;
23426 if (pic_code) flags |= F_PIC;
23427 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
23428 flags |= F_SOFT_FLOAT;
23429
23430 switch (mfloat_abi_opt)
23431 {
23432 case ARM_FLOAT_ABI_SOFT:
23433 case ARM_FLOAT_ABI_SOFTFP:
23434 flags |= F_SOFT_FLOAT;
23435 break;
23436
23437 case ARM_FLOAT_ABI_HARD:
23438 if (flags & F_SOFT_FLOAT)
23439 as_bad (_("hard-float conflicts with specified fpu"));
23440 break;
23441 }
23442
23443 /* Using pure-endian doubles (even if soft-float). */
23444 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
23445 flags |= F_VFP_FLOAT;
23446
23447 #if defined OBJ_ELF
23448 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
23449 flags |= EF_ARM_MAVERICK_FLOAT;
23450 break;
23451
23452 case EF_ARM_EABI_VER4:
23453 case EF_ARM_EABI_VER5:
23454 /* No additional flags to set. */
23455 break;
23456
23457 default:
23458 abort ();
23459 }
23460 #endif
23461 bfd_set_private_flags (stdoutput, flags);
23462
23463 /* We have run out flags in the COFF header to encode the
23464 status of ATPCS support, so instead we create a dummy,
23465 empty, debug section called .arm.atpcs. */
23466 if (atpcs)
23467 {
23468 asection * sec;
23469
23470 sec = bfd_make_section (stdoutput, ".arm.atpcs");
23471
23472 if (sec != NULL)
23473 {
23474 bfd_set_section_flags
23475 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
23476 bfd_set_section_size (stdoutput, sec, 0);
23477 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
23478 }
23479 }
23480 }
23481 #endif
23482
23483 /* Record the CPU type as well. */
23484 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
23485 mach = bfd_mach_arm_iWMMXt2;
23486 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
23487 mach = bfd_mach_arm_iWMMXt;
23488 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
23489 mach = bfd_mach_arm_XScale;
23490 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
23491 mach = bfd_mach_arm_ep9312;
23492 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
23493 mach = bfd_mach_arm_5TE;
23494 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
23495 {
23496 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
23497 mach = bfd_mach_arm_5T;
23498 else
23499 mach = bfd_mach_arm_5;
23500 }
23501 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
23502 {
23503 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
23504 mach = bfd_mach_arm_4T;
23505 else
23506 mach = bfd_mach_arm_4;
23507 }
23508 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
23509 mach = bfd_mach_arm_3M;
23510 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
23511 mach = bfd_mach_arm_3;
23512 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
23513 mach = bfd_mach_arm_2a;
23514 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
23515 mach = bfd_mach_arm_2;
23516 else
23517 mach = bfd_mach_arm_unknown;
23518
23519 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
23520 }
23521
23522 /* Command line processing. */
23523
23524 /* md_parse_option
23525 Invocation line includes a switch not recognized by the base assembler.
23526 See if it's a processor-specific option.
23527
23528 This routine is somewhat complicated by the need for backwards
23529 compatibility (since older releases of gcc can't be changed).
23530 The new options try to make the interface as compatible as
23531 possible with GCC.
23532
23533 New options (supported) are:
23534
23535 -mcpu=<cpu name> Assemble for selected processor
23536 -march=<architecture name> Assemble for selected architecture
23537 -mfpu=<fpu architecture> Assemble for selected FPU.
23538 -EB/-mbig-endian Big-endian
23539 -EL/-mlittle-endian Little-endian
23540 -k Generate PIC code
23541 -mthumb Start in Thumb mode
23542 -mthumb-interwork Code supports ARM/Thumb interworking
23543
23544 -m[no-]warn-deprecated Warn about deprecated features
23545
23546 For now we will also provide support for:
23547
23548 -mapcs-32 32-bit Program counter
23549 -mapcs-26 26-bit Program counter
23550 -macps-float Floats passed in FP registers
23551 -mapcs-reentrant Reentrant code
23552 -matpcs
23553 (sometime these will probably be replaced with -mapcs=<list of options>
23554 and -matpcs=<list of options>)
23555
23556 The remaining options are only supported for back-wards compatibility.
23557 Cpu variants, the arm part is optional:
23558 -m[arm]1 Currently not supported.
23559 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
23560 -m[arm]3 Arm 3 processor
23561 -m[arm]6[xx], Arm 6 processors
23562 -m[arm]7[xx][t][[d]m] Arm 7 processors
23563 -m[arm]8[10] Arm 8 processors
23564 -m[arm]9[20][tdmi] Arm 9 processors
23565 -mstrongarm[110[0]] StrongARM processors
23566 -mxscale XScale processors
23567 -m[arm]v[2345[t[e]]] Arm architectures
23568 -mall All (except the ARM1)
23569 FP variants:
23570 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
23571 -mfpe-old (No float load/store multiples)
23572 -mvfpxd VFP Single precision
23573 -mvfp All VFP
23574 -mno-fpu Disable all floating point instructions
23575
23576 The following CPU names are recognized:
23577 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
23578 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
23579 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
23580 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
23581 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
23582 arm10t arm10e, arm1020t, arm1020e, arm10200e,
23583 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
23584
23585 */
23586
23587 const char * md_shortopts = "m:k";
23588
23589 #ifdef ARM_BI_ENDIAN
23590 #define OPTION_EB (OPTION_MD_BASE + 0)
23591 #define OPTION_EL (OPTION_MD_BASE + 1)
23592 #else
23593 #if TARGET_BYTES_BIG_ENDIAN
23594 #define OPTION_EB (OPTION_MD_BASE + 0)
23595 #else
23596 #define OPTION_EL (OPTION_MD_BASE + 1)
23597 #endif
23598 #endif
23599 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
23600
23601 struct option md_longopts[] =
23602 {
23603 #ifdef OPTION_EB
23604 {"EB", no_argument, NULL, OPTION_EB},
23605 #endif
23606 #ifdef OPTION_EL
23607 {"EL", no_argument, NULL, OPTION_EL},
23608 #endif
23609 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
23610 {NULL, no_argument, NULL, 0}
23611 };
23612
23613 size_t md_longopts_size = sizeof (md_longopts);
23614
23615 struct arm_option_table
23616 {
23617 char *option; /* Option name to match. */
23618 char *help; /* Help information. */
23619 int *var; /* Variable to change. */
23620 int value; /* What to change it to. */
23621 char *deprecated; /* If non-null, print this message. */
23622 };
23623
23624 struct arm_option_table arm_opts[] =
23625 {
23626 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
23627 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
23628 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
23629 &support_interwork, 1, NULL},
23630 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
23631 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
23632 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
23633 1, NULL},
23634 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
23635 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
23636 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
23637 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
23638 NULL},
23639
23640 /* These are recognized by the assembler, but have no affect on code. */
23641 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
23642 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
23643
23644 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
23645 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
23646 &warn_on_deprecated, 0, NULL},
23647 {NULL, NULL, NULL, 0, NULL}
23648 };
23649
23650 struct arm_legacy_option_table
23651 {
23652 char *option; /* Option name to match. */
23653 const arm_feature_set **var; /* Variable to change. */
23654 const arm_feature_set value; /* What to change it to. */
23655 char *deprecated; /* If non-null, print this message. */
23656 };
23657
23658 const struct arm_legacy_option_table arm_legacy_opts[] =
23659 {
23660 /* DON'T add any new processors to this list -- we want the whole list
23661 to go away... Add them to the processors table instead. */
23662 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23663 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
23664 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23665 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
23666 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23667 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
23668 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23669 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
23670 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23671 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
23672 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23673 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
23674 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23675 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
23676 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23677 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
23678 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23679 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
23680 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23681 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
23682 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23683 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
23684 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23685 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
23686 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23687 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
23688 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23689 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23690 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23691 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23692 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23693 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23694 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23695 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23696 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23697 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23698 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23699 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23700 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23701 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23702 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23703 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23704 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23705 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23706 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23707 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23708 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23709 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23710 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23711 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23712 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23713 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23714 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23715 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23716 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23717 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23718 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23719 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23720 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23721 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23722 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23723 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23724 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23725 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23726 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23727 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23728 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23729 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23730 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
23731 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
23732 N_("use -mcpu=strongarm110")},
23733 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
23734 N_("use -mcpu=strongarm1100")},
23735 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
23736 N_("use -mcpu=strongarm1110")},
23737 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
23738 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
23739 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
23740
23741 /* Architecture variants -- don't add any more to this list either. */
23742 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23743 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23744 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23745 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23746 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23747 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23748 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23749 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23750 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23751 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23752 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23753 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23754 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23755 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23756 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23757 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23758 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23759 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23760
23761 /* Floating point variants -- don't add any more to this list either. */
23762 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
23763 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
23764 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
23765 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
23766 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
23767
23768 {NULL, NULL, ARM_ARCH_NONE, NULL}
23769 };
23770
23771 struct arm_cpu_option_table
23772 {
23773 char *name;
23774 size_t name_len;
23775 const arm_feature_set value;
23776 /* For some CPUs we assume an FPU unless the user explicitly sets
23777 -mfpu=... */
23778 const arm_feature_set default_fpu;
23779 /* The canonical name of the CPU, or NULL to use NAME converted to upper
23780 case. */
23781 const char *canonical_name;
23782 };
23783
23784 /* This list should, at a minimum, contain all the cpu names
23785 recognized by GCC. */
23786 #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
23787 static const struct arm_cpu_option_table arm_cpus[] =
23788 {
23789 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
23790 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
23791 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
23792 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23793 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23794 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23795 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23796 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23797 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23798 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23799 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23800 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23801 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23802 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23803 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23804 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23805 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23806 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23807 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23808 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23809 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23810 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23811 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23812 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23813 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23814 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23815 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23816 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23817 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23818 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23819 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23820 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23821 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23822 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23823 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23824 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23825 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23826 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23827 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23828 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
23829 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23830 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23831 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23832 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23833 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23834 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23835 /* For V5 or later processors we default to using VFP; but the user
23836 should really set the FPU type explicitly. */
23837 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23838 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23839 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23840 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23841 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23842 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23843 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23844 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23845 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23846 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23847 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23848 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23849 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23850 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23851 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23852 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23853 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23854 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23855 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23856 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23857 "ARM1026EJ-S"),
23858 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23859 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23860 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23861 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23862 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23863 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23864 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23865 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23866 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23867 "ARM1136JF-S"),
23868 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23869 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23870 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23871 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23872 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23873 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23874 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23875 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23876 FPU_NONE, "Cortex-A5"),
23877 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23878 FPU_ARCH_NEON_VFP_V4,
23879 "Cortex-A7"),
23880 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23881 ARM_FEATURE (0, FPU_VFP_V3
23882 | FPU_NEON_EXT_V1),
23883 "Cortex-A8"),
23884 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23885 ARM_FEATURE (0, FPU_VFP_V3
23886 | FPU_NEON_EXT_V1),
23887 "Cortex-A9"),
23888 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23889 FPU_ARCH_NEON_VFP_V4,
23890 "Cortex-A15"),
23891 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23892 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23893 "Cortex-R4F"),
23894 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23895 FPU_NONE, "Cortex-R5"),
23896 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23897 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23898 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23899 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
23900 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
23901 /* ??? XSCALE is really an architecture. */
23902 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23903 /* ??? iwmmxt is not a processor. */
23904 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23905 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23906 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23907 /* Maverick */
23908 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23909 FPU_ARCH_MAVERICK, "ARM920T"),
23910 /* Marvell processors. */
23911 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE (ARM_AEXT_V7A | ARM_EXT_MP | ARM_EXT_SEC, 0),
23912 FPU_ARCH_VFP_V3D16, NULL),
23913
23914 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
23915 };
23916 #undef ARM_CPU_OPT
23917
23918 struct arm_arch_option_table
23919 {
23920 char *name;
23921 size_t name_len;
23922 const arm_feature_set value;
23923 const arm_feature_set default_fpu;
23924 };
23925
23926 /* This list should, at a minimum, contain all the architecture names
23927 recognized by GCC. */
23928 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
23929 static const struct arm_arch_option_table arm_archs[] =
23930 {
23931 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23932 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23933 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23934 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23935 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23936 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23937 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23938 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23939 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23940 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23941 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23942 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23943 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23944 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23945 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23946 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23947 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23948 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23949 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23950 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23951 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23952 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23953 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23954 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23955 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23956 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23957 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23958 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23959 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
23960 /* The official spelling of the ARMv7 profile variants is the dashed form.
23961 Accept the non-dashed form for compatibility with old toolchains. */
23962 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23963 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23964 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23965 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23966 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23967 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23968 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
23969 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
23970 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23971 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23972 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23973 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
23974 };
23975 #undef ARM_ARCH_OPT
23976
23977 /* ISA extensions in the co-processor and main instruction set space. */
23978 struct arm_option_extension_value_table
23979 {
23980 char *name;
23981 size_t name_len;
23982 const arm_feature_set value;
23983 const arm_feature_set allowed_archs;
23984 };
23985
23986 /* The following table must be in alphabetical order with a NULL last entry.
23987 */
23988 #define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
23989 static const struct arm_option_extension_value_table arm_extensions[] =
23990 {
23991 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
23992 ARM_FEATURE (ARM_EXT_V8, 0)),
23993 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8,
23994 ARM_FEATURE (ARM_EXT_V8, 0)),
23995 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23996 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23997 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23998 ARM_EXT_OPT ("iwmmxt2",
23999 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
24000 ARM_EXT_OPT ("maverick",
24001 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
24002 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
24003 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
24004 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
24005 ARM_FEATURE (ARM_EXT_V8, 0)),
24006 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
24007 ARM_FEATURE (ARM_EXT_V6M, 0)),
24008 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
24009 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
24010 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
24011 | ARM_EXT_DIV, 0),
24012 ARM_FEATURE (ARM_EXT_V7A, 0)),
24013 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
24014 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
24015 };
24016 #undef ARM_EXT_OPT
24017
24018 /* ISA floating-point and Advanced SIMD extensions. */
24019 struct arm_option_fpu_value_table
24020 {
24021 char *name;
24022 const arm_feature_set value;
24023 };
24024
24025 /* This list should, at a minimum, contain all the fpu names
24026 recognized by GCC. */
24027 static const struct arm_option_fpu_value_table arm_fpus[] =
24028 {
24029 {"softfpa", FPU_NONE},
24030 {"fpe", FPU_ARCH_FPE},
24031 {"fpe2", FPU_ARCH_FPE},
24032 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24033 {"fpa", FPU_ARCH_FPA},
24034 {"fpa10", FPU_ARCH_FPA},
24035 {"fpa11", FPU_ARCH_FPA},
24036 {"arm7500fe", FPU_ARCH_FPA},
24037 {"softvfp", FPU_ARCH_VFP},
24038 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24039 {"vfp", FPU_ARCH_VFP_V2},
24040 {"vfp9", FPU_ARCH_VFP_V2},
24041 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
24042 {"vfp10", FPU_ARCH_VFP_V2},
24043 {"vfp10-r0", FPU_ARCH_VFP_V1},
24044 {"vfpxd", FPU_ARCH_VFP_V1xD},
24045 {"vfpv2", FPU_ARCH_VFP_V2},
24046 {"vfpv3", FPU_ARCH_VFP_V3},
24047 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
24048 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
24049 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24050 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24051 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
24052 {"arm1020t", FPU_ARCH_VFP_V1},
24053 {"arm1020e", FPU_ARCH_VFP_V2},
24054 {"arm1136jfs", FPU_ARCH_VFP_V2},
24055 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24056 {"maverick", FPU_ARCH_MAVERICK},
24057 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
24058 {"neon-fp16", FPU_ARCH_NEON_FP16},
24059 {"vfpv4", FPU_ARCH_VFP_V4},
24060 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
24061 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
24062 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
24063 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24064 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24065 {"crypto-neon-fp-armv8",
24066 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
24067 {NULL, ARM_ARCH_NONE}
24068 };
24069
24070 struct arm_option_value_table
24071 {
24072 char *name;
24073 long value;
24074 };
24075
24076 static const struct arm_option_value_table arm_float_abis[] =
24077 {
24078 {"hard", ARM_FLOAT_ABI_HARD},
24079 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24080 {"soft", ARM_FLOAT_ABI_SOFT},
24081 {NULL, 0}
24082 };
24083
24084 #ifdef OBJ_ELF
24085 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
24086 static const struct arm_option_value_table arm_eabis[] =
24087 {
24088 {"gnu", EF_ARM_EABI_UNKNOWN},
24089 {"4", EF_ARM_EABI_VER4},
24090 {"5", EF_ARM_EABI_VER5},
24091 {NULL, 0}
24092 };
24093 #endif
24094
24095 struct arm_long_option_table
24096 {
24097 char * option; /* Substring to match. */
24098 char * help; /* Help information. */
24099 int (* func) (char * subopt); /* Function to decode sub-option. */
24100 char * deprecated; /* If non-null, print this message. */
24101 };
24102
24103 static bfd_boolean
24104 arm_parse_extension (char *str, const arm_feature_set **opt_p)
24105 {
24106 arm_feature_set *ext_set = (arm_feature_set *)
24107 xmalloc (sizeof (arm_feature_set));
24108
24109 /* We insist on extensions being specified in alphabetical order, and with
24110 extensions being added before being removed. We achieve this by having
24111 the global ARM_EXTENSIONS table in alphabetical order, and using the
24112 ADDING_VALUE variable to indicate whether we are adding an extension (1)
24113 or removing it (0) and only allowing it to change in the order
24114 -1 -> 1 -> 0. */
24115 const struct arm_option_extension_value_table * opt = NULL;
24116 int adding_value = -1;
24117
24118 /* Copy the feature set, so that we can modify it. */
24119 *ext_set = **opt_p;
24120 *opt_p = ext_set;
24121
24122 while (str != NULL && *str != 0)
24123 {
24124 char *ext;
24125 size_t len;
24126
24127 if (*str != '+')
24128 {
24129 as_bad (_("invalid architectural extension"));
24130 return FALSE;
24131 }
24132
24133 str++;
24134 ext = strchr (str, '+');
24135
24136 if (ext != NULL)
24137 len = ext - str;
24138 else
24139 len = strlen (str);
24140
24141 if (len >= 2 && strncmp (str, "no", 2) == 0)
24142 {
24143 if (adding_value != 0)
24144 {
24145 adding_value = 0;
24146 opt = arm_extensions;
24147 }
24148
24149 len -= 2;
24150 str += 2;
24151 }
24152 else if (len > 0)
24153 {
24154 if (adding_value == -1)
24155 {
24156 adding_value = 1;
24157 opt = arm_extensions;
24158 }
24159 else if (adding_value != 1)
24160 {
24161 as_bad (_("must specify extensions to add before specifying "
24162 "those to remove"));
24163 return FALSE;
24164 }
24165 }
24166
24167 if (len == 0)
24168 {
24169 as_bad (_("missing architectural extension"));
24170 return FALSE;
24171 }
24172
24173 gas_assert (adding_value != -1);
24174 gas_assert (opt != NULL);
24175
24176 /* Scan over the options table trying to find an exact match. */
24177 for (; opt->name != NULL; opt++)
24178 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24179 {
24180 /* Check we can apply the extension to this architecture. */
24181 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
24182 {
24183 as_bad (_("extension does not apply to the base architecture"));
24184 return FALSE;
24185 }
24186
24187 /* Add or remove the extension. */
24188 if (adding_value)
24189 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
24190 else
24191 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
24192
24193 break;
24194 }
24195
24196 if (opt->name == NULL)
24197 {
24198 /* Did we fail to find an extension because it wasn't specified in
24199 alphabetical order, or because it does not exist? */
24200
24201 for (opt = arm_extensions; opt->name != NULL; opt++)
24202 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24203 break;
24204
24205 if (opt->name == NULL)
24206 as_bad (_("unknown architectural extension `%s'"), str);
24207 else
24208 as_bad (_("architectural extensions must be specified in "
24209 "alphabetical order"));
24210
24211 return FALSE;
24212 }
24213 else
24214 {
24215 /* We should skip the extension we've just matched the next time
24216 round. */
24217 opt++;
24218 }
24219
24220 str = ext;
24221 };
24222
24223 return TRUE;
24224 }
24225
24226 static bfd_boolean
24227 arm_parse_cpu (char *str)
24228 {
24229 const struct arm_cpu_option_table *opt;
24230 char *ext = strchr (str, '+');
24231 size_t len;
24232
24233 if (ext != NULL)
24234 len = ext - str;
24235 else
24236 len = strlen (str);
24237
24238 if (len == 0)
24239 {
24240 as_bad (_("missing cpu name `%s'"), str);
24241 return FALSE;
24242 }
24243
24244 for (opt = arm_cpus; opt->name != NULL; opt++)
24245 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24246 {
24247 mcpu_cpu_opt = &opt->value;
24248 mcpu_fpu_opt = &opt->default_fpu;
24249 if (opt->canonical_name)
24250 strcpy (selected_cpu_name, opt->canonical_name);
24251 else
24252 {
24253 size_t i;
24254
24255 for (i = 0; i < len; i++)
24256 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24257 selected_cpu_name[i] = 0;
24258 }
24259
24260 if (ext != NULL)
24261 return arm_parse_extension (ext, &mcpu_cpu_opt);
24262
24263 return TRUE;
24264 }
24265
24266 as_bad (_("unknown cpu `%s'"), str);
24267 return FALSE;
24268 }
24269
24270 static bfd_boolean
24271 arm_parse_arch (char *str)
24272 {
24273 const struct arm_arch_option_table *opt;
24274 char *ext = strchr (str, '+');
24275 size_t len;
24276
24277 if (ext != NULL)
24278 len = ext - str;
24279 else
24280 len = strlen (str);
24281
24282 if (len == 0)
24283 {
24284 as_bad (_("missing architecture name `%s'"), str);
24285 return FALSE;
24286 }
24287
24288 for (opt = arm_archs; opt->name != NULL; opt++)
24289 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
24290 {
24291 march_cpu_opt = &opt->value;
24292 march_fpu_opt = &opt->default_fpu;
24293 strcpy (selected_cpu_name, opt->name);
24294
24295 if (ext != NULL)
24296 return arm_parse_extension (ext, &march_cpu_opt);
24297
24298 return TRUE;
24299 }
24300
24301 as_bad (_("unknown architecture `%s'\n"), str);
24302 return FALSE;
24303 }
24304
24305 static bfd_boolean
24306 arm_parse_fpu (char * str)
24307 {
24308 const struct arm_option_fpu_value_table * opt;
24309
24310 for (opt = arm_fpus; opt->name != NULL; opt++)
24311 if (streq (opt->name, str))
24312 {
24313 mfpu_opt = &opt->value;
24314 return TRUE;
24315 }
24316
24317 as_bad (_("unknown floating point format `%s'\n"), str);
24318 return FALSE;
24319 }
24320
24321 static bfd_boolean
24322 arm_parse_float_abi (char * str)
24323 {
24324 const struct arm_option_value_table * opt;
24325
24326 for (opt = arm_float_abis; opt->name != NULL; opt++)
24327 if (streq (opt->name, str))
24328 {
24329 mfloat_abi_opt = opt->value;
24330 return TRUE;
24331 }
24332
24333 as_bad (_("unknown floating point abi `%s'\n"), str);
24334 return FALSE;
24335 }
24336
24337 #ifdef OBJ_ELF
24338 static bfd_boolean
24339 arm_parse_eabi (char * str)
24340 {
24341 const struct arm_option_value_table *opt;
24342
24343 for (opt = arm_eabis; opt->name != NULL; opt++)
24344 if (streq (opt->name, str))
24345 {
24346 meabi_flags = opt->value;
24347 return TRUE;
24348 }
24349 as_bad (_("unknown EABI `%s'\n"), str);
24350 return FALSE;
24351 }
24352 #endif
24353
24354 static bfd_boolean
24355 arm_parse_it_mode (char * str)
24356 {
24357 bfd_boolean ret = TRUE;
24358
24359 if (streq ("arm", str))
24360 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
24361 else if (streq ("thumb", str))
24362 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
24363 else if (streq ("always", str))
24364 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
24365 else if (streq ("never", str))
24366 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
24367 else
24368 {
24369 as_bad (_("unknown implicit IT mode `%s', should be "\
24370 "arm, thumb, always, or never."), str);
24371 ret = FALSE;
24372 }
24373
24374 return ret;
24375 }
24376
24377 struct arm_long_option_table arm_long_opts[] =
24378 {
24379 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
24380 arm_parse_cpu, NULL},
24381 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
24382 arm_parse_arch, NULL},
24383 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
24384 arm_parse_fpu, NULL},
24385 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
24386 arm_parse_float_abi, NULL},
24387 #ifdef OBJ_ELF
24388 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
24389 arm_parse_eabi, NULL},
24390 #endif
24391 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
24392 arm_parse_it_mode, NULL},
24393 {NULL, NULL, 0, NULL}
24394 };
24395
24396 int
24397 md_parse_option (int c, char * arg)
24398 {
24399 struct arm_option_table *opt;
24400 const struct arm_legacy_option_table *fopt;
24401 struct arm_long_option_table *lopt;
24402
24403 switch (c)
24404 {
24405 #ifdef OPTION_EB
24406 case OPTION_EB:
24407 target_big_endian = 1;
24408 break;
24409 #endif
24410
24411 #ifdef OPTION_EL
24412 case OPTION_EL:
24413 target_big_endian = 0;
24414 break;
24415 #endif
24416
24417 case OPTION_FIX_V4BX:
24418 fix_v4bx = TRUE;
24419 break;
24420
24421 case 'a':
24422 /* Listing option. Just ignore these, we don't support additional
24423 ones. */
24424 return 0;
24425
24426 default:
24427 for (opt = arm_opts; opt->option != NULL; opt++)
24428 {
24429 if (c == opt->option[0]
24430 && ((arg == NULL && opt->option[1] == 0)
24431 || streq (arg, opt->option + 1)))
24432 {
24433 /* If the option is deprecated, tell the user. */
24434 if (warn_on_deprecated && opt->deprecated != NULL)
24435 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24436 arg ? arg : "", _(opt->deprecated));
24437
24438 if (opt->var != NULL)
24439 *opt->var = opt->value;
24440
24441 return 1;
24442 }
24443 }
24444
24445 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
24446 {
24447 if (c == fopt->option[0]
24448 && ((arg == NULL && fopt->option[1] == 0)
24449 || streq (arg, fopt->option + 1)))
24450 {
24451 /* If the option is deprecated, tell the user. */
24452 if (warn_on_deprecated && fopt->deprecated != NULL)
24453 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
24454 arg ? arg : "", _(fopt->deprecated));
24455
24456 if (fopt->var != NULL)
24457 *fopt->var = &fopt->value;
24458
24459 return 1;
24460 }
24461 }
24462
24463 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24464 {
24465 /* These options are expected to have an argument. */
24466 if (c == lopt->option[0]
24467 && arg != NULL
24468 && strncmp (arg, lopt->option + 1,
24469 strlen (lopt->option + 1)) == 0)
24470 {
24471 /* If the option is deprecated, tell the user. */
24472 if (warn_on_deprecated && lopt->deprecated != NULL)
24473 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
24474 _(lopt->deprecated));
24475
24476 /* Call the sup-option parser. */
24477 return lopt->func (arg + strlen (lopt->option) - 1);
24478 }
24479 }
24480
24481 return 0;
24482 }
24483
24484 return 1;
24485 }
24486
24487 void
24488 md_show_usage (FILE * fp)
24489 {
24490 struct arm_option_table *opt;
24491 struct arm_long_option_table *lopt;
24492
24493 fprintf (fp, _(" ARM-specific assembler options:\n"));
24494
24495 for (opt = arm_opts; opt->option != NULL; opt++)
24496 if (opt->help != NULL)
24497 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
24498
24499 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
24500 if (lopt->help != NULL)
24501 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
24502
24503 #ifdef OPTION_EB
24504 fprintf (fp, _("\
24505 -EB assemble code for a big-endian cpu\n"));
24506 #endif
24507
24508 #ifdef OPTION_EL
24509 fprintf (fp, _("\
24510 -EL assemble code for a little-endian cpu\n"));
24511 #endif
24512
24513 fprintf (fp, _("\
24514 --fix-v4bx Allow BX in ARMv4 code\n"));
24515 }
24516
24517
24518 #ifdef OBJ_ELF
24519 typedef struct
24520 {
24521 int val;
24522 arm_feature_set flags;
24523 } cpu_arch_ver_table;
24524
24525 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
24526 least features first. */
24527 static const cpu_arch_ver_table cpu_arch_ver[] =
24528 {
24529 {1, ARM_ARCH_V4},
24530 {2, ARM_ARCH_V4T},
24531 {3, ARM_ARCH_V5},
24532 {3, ARM_ARCH_V5T},
24533 {4, ARM_ARCH_V5TE},
24534 {5, ARM_ARCH_V5TEJ},
24535 {6, ARM_ARCH_V6},
24536 {9, ARM_ARCH_V6K},
24537 {7, ARM_ARCH_V6Z},
24538 {11, ARM_ARCH_V6M},
24539 {12, ARM_ARCH_V6SM},
24540 {8, ARM_ARCH_V6T2},
24541 {10, ARM_ARCH_V7A_IDIV_MP_SEC_VIRT},
24542 {10, ARM_ARCH_V7R},
24543 {10, ARM_ARCH_V7M},
24544 {14, ARM_ARCH_V8A},
24545 {0, ARM_ARCH_NONE}
24546 };
24547
24548 /* Set an attribute if it has not already been set by the user. */
24549 static void
24550 aeabi_set_attribute_int (int tag, int value)
24551 {
24552 if (tag < 1
24553 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24554 || !attributes_set_explicitly[tag])
24555 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
24556 }
24557
24558 static void
24559 aeabi_set_attribute_string (int tag, const char *value)
24560 {
24561 if (tag < 1
24562 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
24563 || !attributes_set_explicitly[tag])
24564 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
24565 }
24566
24567 /* Set the public EABI object attributes. */
24568 static void
24569 aeabi_set_public_attributes (void)
24570 {
24571 int arch;
24572 char profile;
24573 int virt_sec = 0;
24574 int fp16_optional = 0;
24575 arm_feature_set flags;
24576 arm_feature_set tmp;
24577 const cpu_arch_ver_table *p;
24578
24579 /* Choose the architecture based on the capabilities of the requested cpu
24580 (if any) and/or the instructions actually used. */
24581 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
24582 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
24583 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
24584
24585 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
24586 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
24587
24588 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
24589 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
24590
24591 /* Allow the user to override the reported architecture. */
24592 if (object_arch)
24593 {
24594 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
24595 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
24596 }
24597
24598 /* We need to make sure that the attributes do not identify us as v6S-M
24599 when the only v6S-M feature in use is the Operating System Extensions. */
24600 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
24601 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
24602 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
24603
24604 tmp = flags;
24605 arch = 0;
24606 for (p = cpu_arch_ver; p->val; p++)
24607 {
24608 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
24609 {
24610 arch = p->val;
24611 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
24612 }
24613 }
24614
24615 /* The table lookup above finds the last architecture to contribute
24616 a new feature. Unfortunately, Tag13 is a subset of the union of
24617 v6T2 and v7-M, so it is never seen as contributing a new feature.
24618 We can not search for the last entry which is entirely used,
24619 because if no CPU is specified we build up only those flags
24620 actually used. Perhaps we should separate out the specified
24621 and implicit cases. Avoid taking this path for -march=all by
24622 checking for contradictory v7-A / v7-M features. */
24623 if (arch == 10
24624 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
24625 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
24626 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
24627 arch = 13;
24628
24629 /* Tag_CPU_name. */
24630 if (selected_cpu_name[0])
24631 {
24632 char *q;
24633
24634 q = selected_cpu_name;
24635 if (strncmp (q, "armv", 4) == 0)
24636 {
24637 int i;
24638
24639 q += 4;
24640 for (i = 0; q[i]; i++)
24641 q[i] = TOUPPER (q[i]);
24642 }
24643 aeabi_set_attribute_string (Tag_CPU_name, q);
24644 }
24645
24646 /* Tag_CPU_arch. */
24647 aeabi_set_attribute_int (Tag_CPU_arch, arch);
24648
24649 /* Tag_CPU_arch_profile. */
24650 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
24651 profile = 'A';
24652 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
24653 profile = 'R';
24654 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
24655 profile = 'M';
24656 else
24657 profile = '\0';
24658
24659 if (profile != '\0')
24660 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
24661
24662 /* Tag_ARM_ISA_use. */
24663 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
24664 || arch == 0)
24665 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
24666
24667 /* Tag_THUMB_ISA_use. */
24668 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
24669 || arch == 0)
24670 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
24671 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
24672
24673 /* Tag_VFP_arch. */
24674 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8))
24675 aeabi_set_attribute_int (Tag_VFP_arch, 7);
24676 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
24677 aeabi_set_attribute_int (Tag_VFP_arch,
24678 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
24679 ? 5 : 6);
24680 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
24681 {
24682 fp16_optional = 1;
24683 aeabi_set_attribute_int (Tag_VFP_arch, 3);
24684 }
24685 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
24686 {
24687 aeabi_set_attribute_int (Tag_VFP_arch, 4);
24688 fp16_optional = 1;
24689 }
24690 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
24691 aeabi_set_attribute_int (Tag_VFP_arch, 2);
24692 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
24693 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
24694 aeabi_set_attribute_int (Tag_VFP_arch, 1);
24695
24696 /* Tag_ABI_HardFP_use. */
24697 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
24698 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
24699 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
24700
24701 /* Tag_WMMX_arch. */
24702 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
24703 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
24704 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
24705 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
24706
24707 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
24708 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
24709 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
24710 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
24711 {
24712 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
24713 {
24714 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
24715 }
24716 else
24717 {
24718 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
24719 fp16_optional = 1;
24720 }
24721 }
24722
24723 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
24724 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
24725 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
24726
24727 /* Tag_DIV_use.
24728
24729 We set Tag_DIV_use to two when integer divide instructions have been used
24730 in ARM state, or when Thumb integer divide instructions have been used,
24731 but we have no architecture profile set, nor have we any ARM instructions.
24732
24733 For ARMv8 we set the tag to 0 as integer divide is implied by the base
24734 architecture.
24735
24736 For new architectures we will have to check these tests. */
24737 gas_assert (arch <= TAG_CPU_ARCH_V8);
24738 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
24739 aeabi_set_attribute_int (Tag_DIV_use, 0);
24740 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
24741 || (profile == '\0'
24742 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
24743 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
24744 aeabi_set_attribute_int (Tag_DIV_use, 2);
24745
24746 /* Tag_MP_extension_use. */
24747 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
24748 aeabi_set_attribute_int (Tag_MPextension_use, 1);
24749
24750 /* Tag Virtualization_use. */
24751 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
24752 virt_sec |= 1;
24753 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
24754 virt_sec |= 2;
24755 if (virt_sec != 0)
24756 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
24757 }
24758
24759 /* Add the default contents for the .ARM.attributes section. */
24760 void
24761 arm_md_end (void)
24762 {
24763 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
24764 return;
24765
24766 aeabi_set_public_attributes ();
24767 }
24768 #endif /* OBJ_ELF */
24769
24770
24771 /* Parse a .cpu directive. */
24772
24773 static void
24774 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
24775 {
24776 const struct arm_cpu_option_table *opt;
24777 char *name;
24778 char saved_char;
24779
24780 name = input_line_pointer;
24781 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24782 input_line_pointer++;
24783 saved_char = *input_line_pointer;
24784 *input_line_pointer = 0;
24785
24786 /* Skip the first "all" entry. */
24787 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
24788 if (streq (opt->name, name))
24789 {
24790 mcpu_cpu_opt = &opt->value;
24791 selected_cpu = opt->value;
24792 if (opt->canonical_name)
24793 strcpy (selected_cpu_name, opt->canonical_name);
24794 else
24795 {
24796 int i;
24797 for (i = 0; opt->name[i]; i++)
24798 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24799
24800 selected_cpu_name[i] = 0;
24801 }
24802 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24803 *input_line_pointer = saved_char;
24804 demand_empty_rest_of_line ();
24805 return;
24806 }
24807 as_bad (_("unknown cpu `%s'"), name);
24808 *input_line_pointer = saved_char;
24809 ignore_rest_of_line ();
24810 }
24811
24812
24813 /* Parse a .arch directive. */
24814
24815 static void
24816 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
24817 {
24818 const struct arm_arch_option_table *opt;
24819 char saved_char;
24820 char *name;
24821
24822 name = input_line_pointer;
24823 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24824 input_line_pointer++;
24825 saved_char = *input_line_pointer;
24826 *input_line_pointer = 0;
24827
24828 /* Skip the first "all" entry. */
24829 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24830 if (streq (opt->name, name))
24831 {
24832 mcpu_cpu_opt = &opt->value;
24833 selected_cpu = opt->value;
24834 strcpy (selected_cpu_name, opt->name);
24835 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24836 *input_line_pointer = saved_char;
24837 demand_empty_rest_of_line ();
24838 return;
24839 }
24840
24841 as_bad (_("unknown architecture `%s'\n"), name);
24842 *input_line_pointer = saved_char;
24843 ignore_rest_of_line ();
24844 }
24845
24846
24847 /* Parse a .object_arch directive. */
24848
24849 static void
24850 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
24851 {
24852 const struct arm_arch_option_table *opt;
24853 char saved_char;
24854 char *name;
24855
24856 name = input_line_pointer;
24857 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24858 input_line_pointer++;
24859 saved_char = *input_line_pointer;
24860 *input_line_pointer = 0;
24861
24862 /* Skip the first "all" entry. */
24863 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24864 if (streq (opt->name, name))
24865 {
24866 object_arch = &opt->value;
24867 *input_line_pointer = saved_char;
24868 demand_empty_rest_of_line ();
24869 return;
24870 }
24871
24872 as_bad (_("unknown architecture `%s'\n"), name);
24873 *input_line_pointer = saved_char;
24874 ignore_rest_of_line ();
24875 }
24876
24877 /* Parse a .arch_extension directive. */
24878
24879 static void
24880 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24881 {
24882 const struct arm_option_extension_value_table *opt;
24883 char saved_char;
24884 char *name;
24885 int adding_value = 1;
24886
24887 name = input_line_pointer;
24888 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24889 input_line_pointer++;
24890 saved_char = *input_line_pointer;
24891 *input_line_pointer = 0;
24892
24893 if (strlen (name) >= 2
24894 && strncmp (name, "no", 2) == 0)
24895 {
24896 adding_value = 0;
24897 name += 2;
24898 }
24899
24900 for (opt = arm_extensions; opt->name != NULL; opt++)
24901 if (streq (opt->name, name))
24902 {
24903 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24904 {
24905 as_bad (_("architectural extension `%s' is not allowed for the "
24906 "current base architecture"), name);
24907 break;
24908 }
24909
24910 if (adding_value)
24911 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24912 else
24913 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24914
24915 mcpu_cpu_opt = &selected_cpu;
24916 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24917 *input_line_pointer = saved_char;
24918 demand_empty_rest_of_line ();
24919 return;
24920 }
24921
24922 if (opt->name == NULL)
24923 as_bad (_("unknown architecture `%s'\n"), name);
24924
24925 *input_line_pointer = saved_char;
24926 ignore_rest_of_line ();
24927 }
24928
24929 /* Parse a .fpu directive. */
24930
24931 static void
24932 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24933 {
24934 const struct arm_option_fpu_value_table *opt;
24935 char saved_char;
24936 char *name;
24937
24938 name = input_line_pointer;
24939 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24940 input_line_pointer++;
24941 saved_char = *input_line_pointer;
24942 *input_line_pointer = 0;
24943
24944 for (opt = arm_fpus; opt->name != NULL; opt++)
24945 if (streq (opt->name, name))
24946 {
24947 mfpu_opt = &opt->value;
24948 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24949 *input_line_pointer = saved_char;
24950 demand_empty_rest_of_line ();
24951 return;
24952 }
24953
24954 as_bad (_("unknown floating point format `%s'\n"), name);
24955 *input_line_pointer = saved_char;
24956 ignore_rest_of_line ();
24957 }
24958
24959 /* Copy symbol information. */
24960
24961 void
24962 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24963 {
24964 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24965 }
24966
24967 #ifdef OBJ_ELF
24968 /* Given a symbolic attribute NAME, return the proper integer value.
24969 Returns -1 if the attribute is not known. */
24970
24971 int
24972 arm_convert_symbolic_attribute (const char *name)
24973 {
24974 static const struct
24975 {
24976 const char * name;
24977 const int tag;
24978 }
24979 attribute_table[] =
24980 {
24981 /* When you modify this table you should
24982 also modify the list in doc/c-arm.texi. */
24983 #define T(tag) {#tag, tag}
24984 T (Tag_CPU_raw_name),
24985 T (Tag_CPU_name),
24986 T (Tag_CPU_arch),
24987 T (Tag_CPU_arch_profile),
24988 T (Tag_ARM_ISA_use),
24989 T (Tag_THUMB_ISA_use),
24990 T (Tag_FP_arch),
24991 T (Tag_VFP_arch),
24992 T (Tag_WMMX_arch),
24993 T (Tag_Advanced_SIMD_arch),
24994 T (Tag_PCS_config),
24995 T (Tag_ABI_PCS_R9_use),
24996 T (Tag_ABI_PCS_RW_data),
24997 T (Tag_ABI_PCS_RO_data),
24998 T (Tag_ABI_PCS_GOT_use),
24999 T (Tag_ABI_PCS_wchar_t),
25000 T (Tag_ABI_FP_rounding),
25001 T (Tag_ABI_FP_denormal),
25002 T (Tag_ABI_FP_exceptions),
25003 T (Tag_ABI_FP_user_exceptions),
25004 T (Tag_ABI_FP_number_model),
25005 T (Tag_ABI_align_needed),
25006 T (Tag_ABI_align8_needed),
25007 T (Tag_ABI_align_preserved),
25008 T (Tag_ABI_align8_preserved),
25009 T (Tag_ABI_enum_size),
25010 T (Tag_ABI_HardFP_use),
25011 T (Tag_ABI_VFP_args),
25012 T (Tag_ABI_WMMX_args),
25013 T (Tag_ABI_optimization_goals),
25014 T (Tag_ABI_FP_optimization_goals),
25015 T (Tag_compatibility),
25016 T (Tag_CPU_unaligned_access),
25017 T (Tag_FP_HP_extension),
25018 T (Tag_VFP_HP_extension),
25019 T (Tag_ABI_FP_16bit_format),
25020 T (Tag_MPextension_use),
25021 T (Tag_DIV_use),
25022 T (Tag_nodefaults),
25023 T (Tag_also_compatible_with),
25024 T (Tag_conformance),
25025 T (Tag_T2EE_use),
25026 T (Tag_Virtualization_use),
25027 /* We deliberately do not include Tag_MPextension_use_legacy. */
25028 #undef T
25029 };
25030 unsigned int i;
25031
25032 if (name == NULL)
25033 return -1;
25034
25035 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
25036 if (streq (name, attribute_table[i].name))
25037 return attribute_table[i].tag;
25038
25039 return -1;
25040 }
25041
25042
25043 /* Apply sym value for relocations only in the case that
25044 they are for local symbols and you have the respective
25045 architectural feature for blx and simple switches. */
25046 int
25047 arm_apply_sym_value (struct fix * fixP)
25048 {
25049 if (fixP->fx_addsy
25050 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
25051 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
25052 {
25053 switch (fixP->fx_r_type)
25054 {
25055 case BFD_RELOC_ARM_PCREL_BLX:
25056 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25057 if (ARM_IS_FUNC (fixP->fx_addsy))
25058 return 1;
25059 break;
25060
25061 case BFD_RELOC_ARM_PCREL_CALL:
25062 case BFD_RELOC_THUMB_PCREL_BLX:
25063 if (THUMB_IS_FUNC (fixP->fx_addsy))
25064 return 1;
25065 break;
25066
25067 default:
25068 break;
25069 }
25070
25071 }
25072 return 0;
25073 }
25074 #endif /* OBJ_ELF */