Indent labels
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2020 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 #include "cpu-arm.h"
36
37 #ifdef OBJ_ELF
38 #include "elf/arm.h"
39 #include "dw2gencfi.h"
40 #endif
41
42 #include "dwarf2dbg.h"
43
44 #ifdef OBJ_ELF
45 /* Must be at least the size of the largest unwind opcode (currently two). */
46 #define ARM_OPCODE_CHUNK_SIZE 8
47
48 /* This structure holds the unwinding state. */
49
50 static struct
51 {
52 symbolS * proc_start;
53 symbolS * table_entry;
54 symbolS * personality_routine;
55 int personality_index;
56 /* The segment containing the function. */
57 segT saved_seg;
58 subsegT saved_subseg;
59 /* Opcodes generated from this function. */
60 unsigned char * opcodes;
61 int opcode_count;
62 int opcode_alloc;
63 /* The number of bytes pushed to the stack. */
64 offsetT frame_size;
65 /* We don't add stack adjustment opcodes immediately so that we can merge
66 multiple adjustments. We can also omit the final adjustment
67 when using a frame pointer. */
68 offsetT pending_offset;
69 /* These two fields are set by both unwind_movsp and unwind_setfp. They
70 hold the reg+offset to use when restoring sp from a frame pointer. */
71 offsetT fp_offset;
72 int fp_reg;
73 /* Nonzero if an unwind_setfp directive has been seen. */
74 unsigned fp_used:1;
75 /* Nonzero if the last opcode restores sp from fp_reg. */
76 unsigned sp_restored:1;
77 } unwind;
78
79 /* Whether --fdpic was given. */
80 static int arm_fdpic;
81
82 #endif /* OBJ_ELF */
83
84 /* Results from operand parsing worker functions. */
85
86 typedef enum
87 {
88 PARSE_OPERAND_SUCCESS,
89 PARSE_OPERAND_FAIL,
90 PARSE_OPERAND_FAIL_NO_BACKTRACK
91 } parse_operand_result;
92
93 enum arm_float_abi
94 {
95 ARM_FLOAT_ABI_HARD,
96 ARM_FLOAT_ABI_SOFTFP,
97 ARM_FLOAT_ABI_SOFT
98 };
99
100 /* Types of processor to assemble for. */
101 #ifndef CPU_DEFAULT
102 /* The code that was here used to select a default CPU depending on compiler
103 pre-defines which were only present when doing native builds, thus
104 changing gas' default behaviour depending upon the build host.
105
106 If you have a target that requires a default CPU option then the you
107 should define CPU_DEFAULT here. */
108 #endif
109
110 /* Perform range checks on positive and negative overflows by checking if the
111 VALUE given fits within the range of an BITS sized immediate. */
112 static bfd_boolean out_of_range_p (offsetT value, offsetT bits)
113 {
114 gas_assert (bits < (offsetT)(sizeof (value) * 8));
115 return (value & ~((1 << bits)-1))
116 && ((value & ~((1 << bits)-1)) != ~((1 << bits)-1));
117 }
118
119 #ifndef FPU_DEFAULT
120 # ifdef TE_LINUX
121 # define FPU_DEFAULT FPU_ARCH_FPA
122 # elif defined (TE_NetBSD)
123 # ifdef OBJ_ELF
124 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
125 # else
126 /* Legacy a.out format. */
127 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
128 # endif
129 # elif defined (TE_VXWORKS)
130 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
131 # else
132 /* For backwards compatibility, default to FPA. */
133 # define FPU_DEFAULT FPU_ARCH_FPA
134 # endif
135 #endif /* ifndef FPU_DEFAULT */
136
137 #define streq(a, b) (strcmp (a, b) == 0)
138
139 /* Current set of feature bits available (CPU+FPU). Different from
140 selected_cpu + selected_fpu in case of autodetection since the CPU
141 feature bits are then all set. */
142 static arm_feature_set cpu_variant;
143 /* Feature bits used in each execution state. Used to set build attribute
144 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
145 static arm_feature_set arm_arch_used;
146 static arm_feature_set thumb_arch_used;
147
148 /* Flags stored in private area of BFD structure. */
149 static int uses_apcs_26 = FALSE;
150 static int atpcs = FALSE;
151 static int support_interwork = FALSE;
152 static int uses_apcs_float = FALSE;
153 static int pic_code = FALSE;
154 static int fix_v4bx = FALSE;
155 /* Warn on using deprecated features. */
156 static int warn_on_deprecated = TRUE;
157 static int warn_on_restrict_it = FALSE;
158
159 /* Understand CodeComposer Studio assembly syntax. */
160 bfd_boolean codecomposer_syntax = FALSE;
161
162 /* Variables that we set while parsing command-line options. Once all
163 options have been read we re-process these values to set the real
164 assembly flags. */
165
166 /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
167 instead of -mcpu=arm1). */
168 static const arm_feature_set *legacy_cpu = NULL;
169 static const arm_feature_set *legacy_fpu = NULL;
170
171 /* CPU, extension and FPU feature bits selected by -mcpu. */
172 static const arm_feature_set *mcpu_cpu_opt = NULL;
173 static arm_feature_set *mcpu_ext_opt = NULL;
174 static const arm_feature_set *mcpu_fpu_opt = NULL;
175
176 /* CPU, extension and FPU feature bits selected by -march. */
177 static const arm_feature_set *march_cpu_opt = NULL;
178 static arm_feature_set *march_ext_opt = NULL;
179 static const arm_feature_set *march_fpu_opt = NULL;
180
181 /* Feature bits selected by -mfpu. */
182 static const arm_feature_set *mfpu_opt = NULL;
183
184 /* Constants for known architecture features. */
185 static const arm_feature_set fpu_default = FPU_DEFAULT;
186 static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
187 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
188 static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
189 static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
190 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
191 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
192 #ifdef OBJ_ELF
193 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
194 #endif
195 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
196
197 #ifdef CPU_DEFAULT
198 static const arm_feature_set cpu_default = CPU_DEFAULT;
199 #endif
200
201 static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
202 static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
203 static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
204 static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
205 static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
206 static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
207 static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
208 static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
209 static const arm_feature_set arm_ext_v4t_5 =
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
211 static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
212 static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
213 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
214 static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
215 static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
216 static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
217 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
218 /* Only for compatability of hint instructions. */
219 static const arm_feature_set arm_ext_v6k_v6t2 =
220 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
221 static const arm_feature_set arm_ext_v6_notm =
222 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
223 static const arm_feature_set arm_ext_v6_dsp =
224 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
225 static const arm_feature_set arm_ext_barrier =
226 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
227 static const arm_feature_set arm_ext_msr =
228 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
229 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
230 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
231 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
232 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
233 #ifdef OBJ_ELF
234 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
235 #endif
236 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
237 static const arm_feature_set arm_ext_m =
238 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
239 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
240 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
241 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
242 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
243 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
244 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
245 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
246 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
247 static const arm_feature_set arm_ext_v8m_main =
248 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
249 static const arm_feature_set arm_ext_v8_1m_main =
250 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
251 /* Instructions in ARMv8-M only found in M profile architectures. */
252 static const arm_feature_set arm_ext_v8m_m_only =
253 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
254 static const arm_feature_set arm_ext_v6t2_v8m =
255 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
256 /* Instructions shared between ARMv8-A and ARMv8-M. */
257 static const arm_feature_set arm_ext_atomics =
258 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
259 #ifdef OBJ_ELF
260 /* DSP instructions Tag_DSP_extension refers to. */
261 static const arm_feature_set arm_ext_dsp =
262 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
263 #endif
264 static const arm_feature_set arm_ext_ras =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
266 /* FP16 instructions. */
267 static const arm_feature_set arm_ext_fp16 =
268 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
269 static const arm_feature_set arm_ext_fp16_fml =
270 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
271 static const arm_feature_set arm_ext_v8_2 =
272 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
273 static const arm_feature_set arm_ext_v8_3 =
274 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
275 static const arm_feature_set arm_ext_sb =
276 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
277 static const arm_feature_set arm_ext_predres =
278 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
279 static const arm_feature_set arm_ext_bf16 =
280 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
281 static const arm_feature_set arm_ext_i8mm =
282 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
283 static const arm_feature_set arm_ext_crc =
284 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
285 static const arm_feature_set arm_ext_cde =
286 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
287 static const arm_feature_set arm_ext_cde0 =
288 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
289 static const arm_feature_set arm_ext_cde1 =
290 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
291 static const arm_feature_set arm_ext_cde2 =
292 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
293 static const arm_feature_set arm_ext_cde3 =
294 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
295 static const arm_feature_set arm_ext_cde4 =
296 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
297 static const arm_feature_set arm_ext_cde5 =
298 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
299 static const arm_feature_set arm_ext_cde6 =
300 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
301 static const arm_feature_set arm_ext_cde7 =
302 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
303
304 static const arm_feature_set arm_arch_any = ARM_ANY;
305 static const arm_feature_set fpu_any = FPU_ANY;
306 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
307 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
308 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
309
310 static const arm_feature_set arm_cext_iwmmxt2 =
311 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
312 static const arm_feature_set arm_cext_iwmmxt =
313 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
314 static const arm_feature_set arm_cext_xscale =
315 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
316 static const arm_feature_set arm_cext_maverick =
317 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
318 static const arm_feature_set fpu_fpa_ext_v1 =
319 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
320 static const arm_feature_set fpu_fpa_ext_v2 =
321 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
322 static const arm_feature_set fpu_vfp_ext_v1xd =
323 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
324 static const arm_feature_set fpu_vfp_ext_v1 =
325 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
326 static const arm_feature_set fpu_vfp_ext_v2 =
327 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
328 static const arm_feature_set fpu_vfp_ext_v3xd =
329 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
330 static const arm_feature_set fpu_vfp_ext_v3 =
331 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
332 static const arm_feature_set fpu_vfp_ext_d32 =
333 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
334 static const arm_feature_set fpu_neon_ext_v1 =
335 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
336 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
337 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
338 static const arm_feature_set mve_ext =
339 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
340 static const arm_feature_set mve_fp_ext =
341 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
342 /* Note: This has more than one bit set, which means using it with
343 mark_feature_used (which returns if *any* of the bits are set in the current
344 cpu variant) can give surprising results. */
345 static const arm_feature_set armv8m_fp =
346 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
347 #ifdef OBJ_ELF
348 static const arm_feature_set fpu_vfp_fp16 =
349 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
350 static const arm_feature_set fpu_neon_ext_fma =
351 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
352 #endif
353 static const arm_feature_set fpu_vfp_ext_fma =
354 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
355 static const arm_feature_set fpu_vfp_ext_armv8 =
356 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
357 static const arm_feature_set fpu_vfp_ext_armv8xd =
358 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
359 static const arm_feature_set fpu_neon_ext_armv8 =
360 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
361 static const arm_feature_set fpu_crypto_ext_armv8 =
362 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
363 static const arm_feature_set fpu_neon_ext_v8_1 =
364 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
365 static const arm_feature_set fpu_neon_ext_dotprod =
366 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
367
368 static int mfloat_abi_opt = -1;
369 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
370 directive. */
371 static arm_feature_set selected_arch = ARM_ARCH_NONE;
372 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
373 directive. */
374 static arm_feature_set selected_ext = ARM_ARCH_NONE;
375 /* Feature bits selected by the last -mcpu/-march or by the combination of the
376 last .cpu/.arch directive .arch_extension directives since that
377 directive. */
378 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
379 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
380 static arm_feature_set selected_fpu = FPU_NONE;
381 /* Feature bits selected by the last .object_arch directive. */
382 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
383 /* Must be long enough to hold any of the names in arm_cpus. */
384 static const struct arm_ext_table * selected_ctx_ext_table = NULL;
385 static char selected_cpu_name[20];
386
387 extern FLONUM_TYPE generic_floating_point_number;
388
389 /* Return if no cpu was selected on command-line. */
390 static bfd_boolean
391 no_cpu_selected (void)
392 {
393 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
394 }
395
396 #ifdef OBJ_ELF
397 # ifdef EABI_DEFAULT
398 static int meabi_flags = EABI_DEFAULT;
399 # else
400 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
401 # endif
402
403 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
404
405 bfd_boolean
406 arm_is_eabi (void)
407 {
408 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
409 }
410 #endif
411
412 #ifdef OBJ_ELF
413 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
414 symbolS * GOT_symbol;
415 #endif
416
417 /* 0: assemble for ARM,
418 1: assemble for Thumb,
419 2: assemble for Thumb even though target CPU does not support thumb
420 instructions. */
421 static int thumb_mode = 0;
422 /* A value distinct from the possible values for thumb_mode that we
423 can use to record whether thumb_mode has been copied into the
424 tc_frag_data field of a frag. */
425 #define MODE_RECORDED (1 << 4)
426
427 /* Specifies the intrinsic IT insn behavior mode. */
428 enum implicit_it_mode
429 {
430 IMPLICIT_IT_MODE_NEVER = 0x00,
431 IMPLICIT_IT_MODE_ARM = 0x01,
432 IMPLICIT_IT_MODE_THUMB = 0x02,
433 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
434 };
435 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
436
437 /* If unified_syntax is true, we are processing the new unified
438 ARM/Thumb syntax. Important differences from the old ARM mode:
439
440 - Immediate operands do not require a # prefix.
441 - Conditional affixes always appear at the end of the
442 instruction. (For backward compatibility, those instructions
443 that formerly had them in the middle, continue to accept them
444 there.)
445 - The IT instruction may appear, and if it does is validated
446 against subsequent conditional affixes. It does not generate
447 machine code.
448
449 Important differences from the old Thumb mode:
450
451 - Immediate operands do not require a # prefix.
452 - Most of the V6T2 instructions are only available in unified mode.
453 - The .N and .W suffixes are recognized and honored (it is an error
454 if they cannot be honored).
455 - All instructions set the flags if and only if they have an 's' affix.
456 - Conditional affixes may be used. They are validated against
457 preceding IT instructions. Unlike ARM mode, you cannot use a
458 conditional affix except in the scope of an IT instruction. */
459
460 static bfd_boolean unified_syntax = FALSE;
461
462 /* An immediate operand can start with #, and ld*, st*, pld operands
463 can contain [ and ]. We need to tell APP not to elide whitespace
464 before a [, which can appear as the first operand for pld.
465 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
466 const char arm_symbol_chars[] = "#[]{}";
467
468 enum neon_el_type
469 {
470 NT_invtype,
471 NT_untyped,
472 NT_integer,
473 NT_float,
474 NT_poly,
475 NT_signed,
476 NT_bfloat,
477 NT_unsigned
478 };
479
480 struct neon_type_el
481 {
482 enum neon_el_type type;
483 unsigned size;
484 };
485
486 #define NEON_MAX_TYPE_ELS 5
487
488 struct neon_type
489 {
490 struct neon_type_el el[NEON_MAX_TYPE_ELS];
491 unsigned elems;
492 };
493
494 enum pred_instruction_type
495 {
496 OUTSIDE_PRED_INSN,
497 INSIDE_VPT_INSN,
498 INSIDE_IT_INSN,
499 INSIDE_IT_LAST_INSN,
500 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
501 if inside, should be the last one. */
502 NEUTRAL_IT_INSN, /* This could be either inside or outside,
503 i.e. BKPT and NOP. */
504 IT_INSN, /* The IT insn has been parsed. */
505 VPT_INSN, /* The VPT/VPST insn has been parsed. */
506 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
507 a predication code. */
508 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
509 NEUTRAL_IT_NO_VPT_INSN, /* Instruction that can be either inside or outside
510 an IT block, but must not be in a VPT block. */
511 };
512
513 /* The maximum number of operands we need. */
514 #define ARM_IT_MAX_OPERANDS 6
515 #define ARM_IT_MAX_RELOCS 3
516
517 struct arm_it
518 {
519 const char * error;
520 unsigned long instruction;
521 int size;
522 int size_req;
523 int cond;
524 /* "uncond_value" is set to the value in place of the conditional field in
525 unconditional versions of the instruction, or -1 if nothing is
526 appropriate. */
527 int uncond_value;
528 struct neon_type vectype;
529 /* This does not indicate an actual NEON instruction, only that
530 the mnemonic accepts neon-style type suffixes. */
531 int is_neon;
532 /* Set to the opcode if the instruction needs relaxation.
533 Zero if the instruction is not relaxed. */
534 unsigned long relax;
535 struct
536 {
537 bfd_reloc_code_real_type type;
538 expressionS exp;
539 int pc_rel;
540 } relocs[ARM_IT_MAX_RELOCS];
541
542 enum pred_instruction_type pred_insn_type;
543
544 struct
545 {
546 unsigned reg;
547 signed int imm;
548 struct neon_type_el vectype;
549 unsigned present : 1; /* Operand present. */
550 unsigned isreg : 1; /* Operand was a register. */
551 unsigned immisreg : 2; /* .imm field is a second register.
552 0: imm, 1: gpr, 2: MVE Q-register. */
553 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
554 0) not scalar,
555 1) Neon scalar,
556 2) MVE scalar. */
557 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
558 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
559 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
560 instructions. This allows us to disambiguate ARM <-> vector insns. */
561 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
562 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
563 unsigned isquad : 1; /* Operand is SIMD quad register. */
564 unsigned issingle : 1; /* Operand is VFP single-precision register. */
565 unsigned iszr : 1; /* Operand is ZR register. */
566 unsigned hasreloc : 1; /* Operand has relocation suffix. */
567 unsigned writeback : 1; /* Operand has trailing ! */
568 unsigned preind : 1; /* Preindexed address. */
569 unsigned postind : 1; /* Postindexed address. */
570 unsigned negative : 1; /* Index register was negated. */
571 unsigned shifted : 1; /* Shift applied to operation. */
572 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
573 } operands[ARM_IT_MAX_OPERANDS];
574 };
575
576 static struct arm_it inst;
577
578 #define NUM_FLOAT_VALS 8
579
580 const char * fp_const[] =
581 {
582 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
583 };
584
585 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
586
587 #define FAIL (-1)
588 #define SUCCESS (0)
589
590 #define SUFF_S 1
591 #define SUFF_D 2
592 #define SUFF_E 3
593 #define SUFF_P 4
594
595 #define CP_T_X 0x00008000
596 #define CP_T_Y 0x00400000
597
598 #define CONDS_BIT 0x00100000
599 #define LOAD_BIT 0x00100000
600
601 #define DOUBLE_LOAD_FLAG 0x00000001
602
603 struct asm_cond
604 {
605 const char * template_name;
606 unsigned long value;
607 };
608
609 #define COND_ALWAYS 0xE
610
611 struct asm_psr
612 {
613 const char * template_name;
614 unsigned long field;
615 };
616
617 struct asm_barrier_opt
618 {
619 const char * template_name;
620 unsigned long value;
621 const arm_feature_set arch;
622 };
623
624 /* The bit that distinguishes CPSR and SPSR. */
625 #define SPSR_BIT (1 << 22)
626
627 /* The individual PSR flag bits. */
628 #define PSR_c (1 << 16)
629 #define PSR_x (1 << 17)
630 #define PSR_s (1 << 18)
631 #define PSR_f (1 << 19)
632
633 struct reloc_entry
634 {
635 const char * name;
636 bfd_reloc_code_real_type reloc;
637 };
638
639 enum vfp_reg_pos
640 {
641 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
642 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
643 };
644
645 enum vfp_ldstm_type
646 {
647 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
648 };
649
650 /* Bits for DEFINED field in neon_typed_alias. */
651 #define NTA_HASTYPE 1
652 #define NTA_HASINDEX 2
653
654 struct neon_typed_alias
655 {
656 unsigned char defined;
657 unsigned char index;
658 struct neon_type_el eltype;
659 };
660
661 /* ARM register categories. This includes coprocessor numbers and various
662 architecture extensions' registers. Each entry should have an error message
663 in reg_expected_msgs below. */
664 enum arm_reg_type
665 {
666 REG_TYPE_RN,
667 REG_TYPE_CP,
668 REG_TYPE_CN,
669 REG_TYPE_FN,
670 REG_TYPE_VFS,
671 REG_TYPE_VFD,
672 REG_TYPE_NQ,
673 REG_TYPE_VFSD,
674 REG_TYPE_NDQ,
675 REG_TYPE_NSD,
676 REG_TYPE_NSDQ,
677 REG_TYPE_VFC,
678 REG_TYPE_MVF,
679 REG_TYPE_MVD,
680 REG_TYPE_MVFX,
681 REG_TYPE_MVDX,
682 REG_TYPE_MVAX,
683 REG_TYPE_MQ,
684 REG_TYPE_DSPSC,
685 REG_TYPE_MMXWR,
686 REG_TYPE_MMXWC,
687 REG_TYPE_MMXWCG,
688 REG_TYPE_XSCALE,
689 REG_TYPE_RNB,
690 REG_TYPE_ZR
691 };
692
693 /* Structure for a hash table entry for a register.
694 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
695 information which states whether a vector type or index is specified (for a
696 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
697 struct reg_entry
698 {
699 const char * name;
700 unsigned int number;
701 unsigned char type;
702 unsigned char builtin;
703 struct neon_typed_alias * neon;
704 };
705
706 /* Diagnostics used when we don't get a register of the expected type. */
707 const char * const reg_expected_msgs[] =
708 {
709 [REG_TYPE_RN] = N_("ARM register expected"),
710 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
711 [REG_TYPE_CN] = N_("co-processor register expected"),
712 [REG_TYPE_FN] = N_("FPA register expected"),
713 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
714 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
715 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
716 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
717 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
718 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
719 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
720 " expected"),
721 [REG_TYPE_VFC] = N_("VFP system register expected"),
722 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
723 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
724 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
725 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
726 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
727 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
728 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
729 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
730 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
731 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
732 [REG_TYPE_MQ] = N_("MVE vector register expected"),
733 [REG_TYPE_RNB] = N_("")
734 };
735
736 /* Some well known registers that we refer to directly elsewhere. */
737 #define REG_R12 12
738 #define REG_SP 13
739 #define REG_LR 14
740 #define REG_PC 15
741
742 /* ARM instructions take 4bytes in the object file, Thumb instructions
743 take 2: */
744 #define INSN_SIZE 4
745
746 struct asm_opcode
747 {
748 /* Basic string to match. */
749 const char * template_name;
750
751 /* Parameters to instruction. */
752 unsigned int operands[8];
753
754 /* Conditional tag - see opcode_lookup. */
755 unsigned int tag : 4;
756
757 /* Basic instruction code. */
758 unsigned int avalue;
759
760 /* Thumb-format instruction code. */
761 unsigned int tvalue;
762
763 /* Which architecture variant provides this instruction. */
764 const arm_feature_set * avariant;
765 const arm_feature_set * tvariant;
766
767 /* Function to call to encode instruction in ARM format. */
768 void (* aencode) (void);
769
770 /* Function to call to encode instruction in Thumb format. */
771 void (* tencode) (void);
772
773 /* Indicates whether this instruction may be vector predicated. */
774 unsigned int mayBeVecPred : 1;
775 };
776
777 /* Defines for various bits that we will want to toggle. */
778 #define INST_IMMEDIATE 0x02000000
779 #define OFFSET_REG 0x02000000
780 #define HWOFFSET_IMM 0x00400000
781 #define SHIFT_BY_REG 0x00000010
782 #define PRE_INDEX 0x01000000
783 #define INDEX_UP 0x00800000
784 #define WRITE_BACK 0x00200000
785 #define LDM_TYPE_2_OR_3 0x00400000
786 #define CPSI_MMOD 0x00020000
787
788 #define LITERAL_MASK 0xf000f000
789 #define OPCODE_MASK 0xfe1fffff
790 #define V4_STR_BIT 0x00000020
791 #define VLDR_VMOV_SAME 0x0040f000
792
793 #define T2_SUBS_PC_LR 0xf3de8f00
794
795 #define DATA_OP_SHIFT 21
796 #define SBIT_SHIFT 20
797
798 #define T2_OPCODE_MASK 0xfe1fffff
799 #define T2_DATA_OP_SHIFT 21
800 #define T2_SBIT_SHIFT 20
801
802 #define A_COND_MASK 0xf0000000
803 #define A_PUSH_POP_OP_MASK 0x0fff0000
804
805 /* Opcodes for pushing/poping registers to/from the stack. */
806 #define A1_OPCODE_PUSH 0x092d0000
807 #define A2_OPCODE_PUSH 0x052d0004
808 #define A2_OPCODE_POP 0x049d0004
809
810 /* Codes to distinguish the arithmetic instructions. */
811 #define OPCODE_AND 0
812 #define OPCODE_EOR 1
813 #define OPCODE_SUB 2
814 #define OPCODE_RSB 3
815 #define OPCODE_ADD 4
816 #define OPCODE_ADC 5
817 #define OPCODE_SBC 6
818 #define OPCODE_RSC 7
819 #define OPCODE_TST 8
820 #define OPCODE_TEQ 9
821 #define OPCODE_CMP 10
822 #define OPCODE_CMN 11
823 #define OPCODE_ORR 12
824 #define OPCODE_MOV 13
825 #define OPCODE_BIC 14
826 #define OPCODE_MVN 15
827
828 #define T2_OPCODE_AND 0
829 #define T2_OPCODE_BIC 1
830 #define T2_OPCODE_ORR 2
831 #define T2_OPCODE_ORN 3
832 #define T2_OPCODE_EOR 4
833 #define T2_OPCODE_ADD 8
834 #define T2_OPCODE_ADC 10
835 #define T2_OPCODE_SBC 11
836 #define T2_OPCODE_SUB 13
837 #define T2_OPCODE_RSB 14
838
839 #define T_OPCODE_MUL 0x4340
840 #define T_OPCODE_TST 0x4200
841 #define T_OPCODE_CMN 0x42c0
842 #define T_OPCODE_NEG 0x4240
843 #define T_OPCODE_MVN 0x43c0
844
845 #define T_OPCODE_ADD_R3 0x1800
846 #define T_OPCODE_SUB_R3 0x1a00
847 #define T_OPCODE_ADD_HI 0x4400
848 #define T_OPCODE_ADD_ST 0xb000
849 #define T_OPCODE_SUB_ST 0xb080
850 #define T_OPCODE_ADD_SP 0xa800
851 #define T_OPCODE_ADD_PC 0xa000
852 #define T_OPCODE_ADD_I8 0x3000
853 #define T_OPCODE_SUB_I8 0x3800
854 #define T_OPCODE_ADD_I3 0x1c00
855 #define T_OPCODE_SUB_I3 0x1e00
856
857 #define T_OPCODE_ASR_R 0x4100
858 #define T_OPCODE_LSL_R 0x4080
859 #define T_OPCODE_LSR_R 0x40c0
860 #define T_OPCODE_ROR_R 0x41c0
861 #define T_OPCODE_ASR_I 0x1000
862 #define T_OPCODE_LSL_I 0x0000
863 #define T_OPCODE_LSR_I 0x0800
864
865 #define T_OPCODE_MOV_I8 0x2000
866 #define T_OPCODE_CMP_I8 0x2800
867 #define T_OPCODE_CMP_LR 0x4280
868 #define T_OPCODE_MOV_HR 0x4600
869 #define T_OPCODE_CMP_HR 0x4500
870
871 #define T_OPCODE_LDR_PC 0x4800
872 #define T_OPCODE_LDR_SP 0x9800
873 #define T_OPCODE_STR_SP 0x9000
874 #define T_OPCODE_LDR_IW 0x6800
875 #define T_OPCODE_STR_IW 0x6000
876 #define T_OPCODE_LDR_IH 0x8800
877 #define T_OPCODE_STR_IH 0x8000
878 #define T_OPCODE_LDR_IB 0x7800
879 #define T_OPCODE_STR_IB 0x7000
880 #define T_OPCODE_LDR_RW 0x5800
881 #define T_OPCODE_STR_RW 0x5000
882 #define T_OPCODE_LDR_RH 0x5a00
883 #define T_OPCODE_STR_RH 0x5200
884 #define T_OPCODE_LDR_RB 0x5c00
885 #define T_OPCODE_STR_RB 0x5400
886
887 #define T_OPCODE_PUSH 0xb400
888 #define T_OPCODE_POP 0xbc00
889
890 #define T_OPCODE_BRANCH 0xe000
891
892 #define THUMB_SIZE 2 /* Size of thumb instruction. */
893 #define THUMB_PP_PC_LR 0x0100
894 #define THUMB_LOAD_BIT 0x0800
895 #define THUMB2_LOAD_BIT 0x00100000
896
897 #define BAD_SYNTAX _("syntax error")
898 #define BAD_ARGS _("bad arguments to instruction")
899 #define BAD_SP _("r13 not allowed here")
900 #define BAD_PC _("r15 not allowed here")
901 #define BAD_ODD _("Odd register not allowed here")
902 #define BAD_EVEN _("Even register not allowed here")
903 #define BAD_COND _("instruction cannot be conditional")
904 #define BAD_OVERLAP _("registers may not be the same")
905 #define BAD_HIREG _("lo register required")
906 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
907 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
908 #define BAD_BRANCH _("branch must be last instruction in IT block")
909 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
910 #define BAD_NO_VPT _("instruction not allowed in VPT block")
911 #define BAD_NOT_IT _("instruction not allowed in IT block")
912 #define BAD_NOT_VPT _("instruction missing MVE vector predication code")
913 #define BAD_FPU _("selected FPU does not support instruction")
914 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
915 #define BAD_OUT_VPT \
916 _("vector predicated instruction should be in VPT/VPST block")
917 #define BAD_IT_COND _("incorrect condition in IT block")
918 #define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
919 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
920 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
921 #define BAD_PC_ADDRESSING \
922 _("cannot use register index with PC-relative addressing")
923 #define BAD_PC_WRITEBACK \
924 _("cannot use writeback with PC-relative addressing")
925 #define BAD_RANGE _("branch out of range")
926 #define BAD_FP16 _("selected processor does not support fp16 instruction")
927 #define BAD_BF16 _("selected processor does not support bf16 instruction")
928 #define BAD_CDE _("selected processor does not support cde instruction")
929 #define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
930 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
931 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
932 #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
933 "block")
934 #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
935 "block")
936 #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
937 " operand")
938 #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
939 " operand")
940 #define BAD_SIMD_TYPE _("bad type in SIMD instruction")
941 #define BAD_MVE_AUTO \
942 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
943 " use a valid -march or -mcpu option.")
944 #define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
945 "and source operands makes instruction UNPREDICTABLE")
946 #define BAD_EL_TYPE _("bad element type for instruction")
947 #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
948
949 static struct hash_control * arm_ops_hsh;
950 static struct hash_control * arm_cond_hsh;
951 static struct hash_control * arm_vcond_hsh;
952 static struct hash_control * arm_shift_hsh;
953 static struct hash_control * arm_psr_hsh;
954 static struct hash_control * arm_v7m_psr_hsh;
955 static struct hash_control * arm_reg_hsh;
956 static struct hash_control * arm_reloc_hsh;
957 static struct hash_control * arm_barrier_opt_hsh;
958
959 /* Stuff needed to resolve the label ambiguity
960 As:
961 ...
962 label: <insn>
963 may differ from:
964 ...
965 label:
966 <insn> */
967
968 symbolS * last_label_seen;
969 static int label_is_thumb_function_name = FALSE;
970
971 /* Literal pool structure. Held on a per-section
972 and per-sub-section basis. */
973
974 #define MAX_LITERAL_POOL_SIZE 1024
975 typedef struct literal_pool
976 {
977 expressionS literals [MAX_LITERAL_POOL_SIZE];
978 unsigned int next_free_entry;
979 unsigned int id;
980 symbolS * symbol;
981 segT section;
982 subsegT sub_section;
983 #ifdef OBJ_ELF
984 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
985 #endif
986 struct literal_pool * next;
987 unsigned int alignment;
988 } literal_pool;
989
990 /* Pointer to a linked list of literal pools. */
991 literal_pool * list_of_pools = NULL;
992
993 typedef enum asmfunc_states
994 {
995 OUTSIDE_ASMFUNC,
996 WAITING_ASMFUNC_NAME,
997 WAITING_ENDASMFUNC
998 } asmfunc_states;
999
1000 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
1001
1002 #ifdef OBJ_ELF
1003 # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
1004 #else
1005 static struct current_pred now_pred;
1006 #endif
1007
1008 static inline int
1009 now_pred_compatible (int cond)
1010 {
1011 return (cond & ~1) == (now_pred.cc & ~1);
1012 }
1013
1014 static inline int
1015 conditional_insn (void)
1016 {
1017 return inst.cond != COND_ALWAYS;
1018 }
1019
1020 static int in_pred_block (void);
1021
1022 static int handle_pred_state (void);
1023
1024 static void force_automatic_it_block_close (void);
1025
1026 static void it_fsm_post_encode (void);
1027
1028 #define set_pred_insn_type(type) \
1029 do \
1030 { \
1031 inst.pred_insn_type = type; \
1032 if (handle_pred_state () == FAIL) \
1033 return; \
1034 } \
1035 while (0)
1036
1037 #define set_pred_insn_type_nonvoid(type, failret) \
1038 do \
1039 { \
1040 inst.pred_insn_type = type; \
1041 if (handle_pred_state () == FAIL) \
1042 return failret; \
1043 } \
1044 while(0)
1045
1046 #define set_pred_insn_type_last() \
1047 do \
1048 { \
1049 if (inst.cond == COND_ALWAYS) \
1050 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
1051 else \
1052 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
1053 } \
1054 while (0)
1055
1056 /* Toggle value[pos]. */
1057 #define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1058
1059 /* Pure syntax. */
1060
1061 /* This array holds the chars that always start a comment. If the
1062 pre-processor is disabled, these aren't very useful. */
1063 char arm_comment_chars[] = "@";
1064
1065 /* This array holds the chars that only start a comment at the beginning of
1066 a line. If the line seems to have the form '# 123 filename'
1067 .line and .file directives will appear in the pre-processed output. */
1068 /* Note that input_file.c hand checks for '#' at the beginning of the
1069 first line of the input file. This is because the compiler outputs
1070 #NO_APP at the beginning of its output. */
1071 /* Also note that comments like this one will always work. */
1072 const char line_comment_chars[] = "#";
1073
1074 char arm_line_separator_chars[] = ";";
1075
1076 /* Chars that can be used to separate mant
1077 from exp in floating point numbers. */
1078 const char EXP_CHARS[] = "eE";
1079
1080 /* Chars that mean this number is a floating point constant. */
1081 /* As in 0f12.456 */
1082 /* or 0d1.2345e12 */
1083
1084 const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
1085
1086 /* Prefix characters that indicate the start of an immediate
1087 value. */
1088 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1089
1090 /* Separator character handling. */
1091
1092 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1093
1094 enum fp_16bit_format
1095 {
1096 ARM_FP16_FORMAT_IEEE = 0x1,
1097 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1098 ARM_FP16_FORMAT_DEFAULT = 0x3
1099 };
1100
1101 static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1102
1103
1104 static inline int
1105 skip_past_char (char ** str, char c)
1106 {
1107 /* PR gas/14987: Allow for whitespace before the expected character. */
1108 skip_whitespace (*str);
1109
1110 if (**str == c)
1111 {
1112 (*str)++;
1113 return SUCCESS;
1114 }
1115 else
1116 return FAIL;
1117 }
1118
1119 #define skip_past_comma(str) skip_past_char (str, ',')
1120
1121 /* Arithmetic expressions (possibly involving symbols). */
1122
1123 /* Return TRUE if anything in the expression is a bignum. */
1124
1125 static bfd_boolean
1126 walk_no_bignums (symbolS * sp)
1127 {
1128 if (symbol_get_value_expression (sp)->X_op == O_big)
1129 return TRUE;
1130
1131 if (symbol_get_value_expression (sp)->X_add_symbol)
1132 {
1133 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1134 || (symbol_get_value_expression (sp)->X_op_symbol
1135 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1136 }
1137
1138 return FALSE;
1139 }
1140
1141 static bfd_boolean in_my_get_expression = FALSE;
1142
1143 /* Third argument to my_get_expression. */
1144 #define GE_NO_PREFIX 0
1145 #define GE_IMM_PREFIX 1
1146 #define GE_OPT_PREFIX 2
1147 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1148 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1149 #define GE_OPT_PREFIX_BIG 3
1150
1151 static int
1152 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1153 {
1154 char * save_in;
1155
1156 /* In unified syntax, all prefixes are optional. */
1157 if (unified_syntax)
1158 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1159 : GE_OPT_PREFIX;
1160
1161 switch (prefix_mode)
1162 {
1163 case GE_NO_PREFIX: break;
1164 case GE_IMM_PREFIX:
1165 if (!is_immediate_prefix (**str))
1166 {
1167 inst.error = _("immediate expression requires a # prefix");
1168 return FAIL;
1169 }
1170 (*str)++;
1171 break;
1172 case GE_OPT_PREFIX:
1173 case GE_OPT_PREFIX_BIG:
1174 if (is_immediate_prefix (**str))
1175 (*str)++;
1176 break;
1177 default:
1178 abort ();
1179 }
1180
1181 memset (ep, 0, sizeof (expressionS));
1182
1183 save_in = input_line_pointer;
1184 input_line_pointer = *str;
1185 in_my_get_expression = TRUE;
1186 expression (ep);
1187 in_my_get_expression = FALSE;
1188
1189 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1190 {
1191 /* We found a bad or missing expression in md_operand(). */
1192 *str = input_line_pointer;
1193 input_line_pointer = save_in;
1194 if (inst.error == NULL)
1195 inst.error = (ep->X_op == O_absent
1196 ? _("missing expression") :_("bad expression"));
1197 return 1;
1198 }
1199
1200 /* Get rid of any bignums now, so that we don't generate an error for which
1201 we can't establish a line number later on. Big numbers are never valid
1202 in instructions, which is where this routine is always called. */
1203 if (prefix_mode != GE_OPT_PREFIX_BIG
1204 && (ep->X_op == O_big
1205 || (ep->X_add_symbol
1206 && (walk_no_bignums (ep->X_add_symbol)
1207 || (ep->X_op_symbol
1208 && walk_no_bignums (ep->X_op_symbol))))))
1209 {
1210 inst.error = _("invalid constant");
1211 *str = input_line_pointer;
1212 input_line_pointer = save_in;
1213 return 1;
1214 }
1215
1216 *str = input_line_pointer;
1217 input_line_pointer = save_in;
1218 return SUCCESS;
1219 }
1220
1221 /* Turn a string in input_line_pointer into a floating point constant
1222 of type TYPE, and store the appropriate bytes in *LITP. The number
1223 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1224 returned, or NULL on OK.
1225
1226 Note that fp constants aren't represent in the normal way on the ARM.
1227 In big endian mode, things are as expected. However, in little endian
1228 mode fp constants are big-endian word-wise, and little-endian byte-wise
1229 within the words. For example, (double) 1.1 in big endian mode is
1230 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1231 the byte sequence 99 99 f1 3f 9a 99 99 99.
1232
1233 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1234
1235 const char *
1236 md_atof (int type, char * litP, int * sizeP)
1237 {
1238 int prec;
1239 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1240 char *t;
1241 int i;
1242
1243 switch (type)
1244 {
1245 case 'H':
1246 case 'h':
1247 prec = 1;
1248 break;
1249
1250 /* If this is a bfloat16, then parse it slightly differently, as it
1251 does not follow the IEEE specification for floating point numbers
1252 exactly. */
1253 case 'b':
1254 {
1255 FLONUM_TYPE generic_float;
1256
1257 t = atof_ieee_detail (input_line_pointer, 1, 8, words, &generic_float);
1258
1259 if (t)
1260 input_line_pointer = t;
1261 else
1262 return _("invalid floating point number");
1263
1264 switch (generic_float.sign)
1265 {
1266 /* Is +Inf. */
1267 case 'P':
1268 words[0] = 0x7f80;
1269 break;
1270
1271 /* Is -Inf. */
1272 case 'N':
1273 words[0] = 0xff80;
1274 break;
1275
1276 /* Is NaN. */
1277 /* bfloat16 has two types of NaN - quiet and signalling.
1278 Quiet NaN has bit[6] == 1 && faction != 0, whereas
1279 signalling NaN's have bit[0] == 0 && fraction != 0.
1280 Chosen this specific encoding as it is the same form
1281 as used by other IEEE 754 encodings in GAS. */
1282 case 0:
1283 words[0] = 0x7fff;
1284 break;
1285
1286 default:
1287 break;
1288 }
1289
1290 *sizeP = 2;
1291
1292 md_number_to_chars (litP, (valueT) words[0], sizeof (LITTLENUM_TYPE));
1293
1294 return NULL;
1295 }
1296 case 'f':
1297 case 'F':
1298 case 's':
1299 case 'S':
1300 prec = 2;
1301 break;
1302
1303 case 'd':
1304 case 'D':
1305 case 'r':
1306 case 'R':
1307 prec = 4;
1308 break;
1309
1310 case 'x':
1311 case 'X':
1312 prec = 5;
1313 break;
1314
1315 case 'p':
1316 case 'P':
1317 prec = 5;
1318 break;
1319
1320 default:
1321 *sizeP = 0;
1322 return _("Unrecognized or unsupported floating point constant");
1323 }
1324
1325 t = atof_ieee (input_line_pointer, type, words);
1326 if (t)
1327 input_line_pointer = t;
1328 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1329
1330 if (target_big_endian || prec == 1)
1331 for (i = 0; i < prec; i++)
1332 {
1333 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1334 litP += sizeof (LITTLENUM_TYPE);
1335 }
1336 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1337 for (i = prec - 1; i >= 0; i--)
1338 {
1339 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1340 litP += sizeof (LITTLENUM_TYPE);
1341 }
1342 else
1343 /* For a 4 byte float the order of elements in `words' is 1 0.
1344 For an 8 byte float the order is 1 0 3 2. */
1345 for (i = 0; i < prec; i += 2)
1346 {
1347 md_number_to_chars (litP, (valueT) words[i + 1],
1348 sizeof (LITTLENUM_TYPE));
1349 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1350 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1351 litP += 2 * sizeof (LITTLENUM_TYPE);
1352 }
1353
1354 return NULL;
1355 }
1356
1357 /* We handle all bad expressions here, so that we can report the faulty
1358 instruction in the error message. */
1359
1360 void
1361 md_operand (expressionS * exp)
1362 {
1363 if (in_my_get_expression)
1364 exp->X_op = O_illegal;
1365 }
1366
1367 /* Immediate values. */
1368
1369 #ifdef OBJ_ELF
1370 /* Generic immediate-value read function for use in directives.
1371 Accepts anything that 'expression' can fold to a constant.
1372 *val receives the number. */
1373
1374 static int
1375 immediate_for_directive (int *val)
1376 {
1377 expressionS exp;
1378 exp.X_op = O_illegal;
1379
1380 if (is_immediate_prefix (*input_line_pointer))
1381 {
1382 input_line_pointer++;
1383 expression (&exp);
1384 }
1385
1386 if (exp.X_op != O_constant)
1387 {
1388 as_bad (_("expected #constant"));
1389 ignore_rest_of_line ();
1390 return FAIL;
1391 }
1392 *val = exp.X_add_number;
1393 return SUCCESS;
1394 }
1395 #endif
1396
1397 /* Register parsing. */
1398
1399 /* Generic register parser. CCP points to what should be the
1400 beginning of a register name. If it is indeed a valid register
1401 name, advance CCP over it and return the reg_entry structure;
1402 otherwise return NULL. Does not issue diagnostics. */
1403
1404 static struct reg_entry *
1405 arm_reg_parse_multi (char **ccp)
1406 {
1407 char *start = *ccp;
1408 char *p;
1409 struct reg_entry *reg;
1410
1411 skip_whitespace (start);
1412
1413 #ifdef REGISTER_PREFIX
1414 if (*start != REGISTER_PREFIX)
1415 return NULL;
1416 start++;
1417 #endif
1418 #ifdef OPTIONAL_REGISTER_PREFIX
1419 if (*start == OPTIONAL_REGISTER_PREFIX)
1420 start++;
1421 #endif
1422
1423 p = start;
1424 if (!ISALPHA (*p) || !is_name_beginner (*p))
1425 return NULL;
1426
1427 do
1428 p++;
1429 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1430
1431 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1432
1433 if (!reg)
1434 return NULL;
1435
1436 *ccp = p;
1437 return reg;
1438 }
1439
1440 static int
1441 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1442 enum arm_reg_type type)
1443 {
1444 /* Alternative syntaxes are accepted for a few register classes. */
1445 switch (type)
1446 {
1447 case REG_TYPE_MVF:
1448 case REG_TYPE_MVD:
1449 case REG_TYPE_MVFX:
1450 case REG_TYPE_MVDX:
1451 /* Generic coprocessor register names are allowed for these. */
1452 if (reg && reg->type == REG_TYPE_CN)
1453 return reg->number;
1454 break;
1455
1456 case REG_TYPE_CP:
1457 /* For backward compatibility, a bare number is valid here. */
1458 {
1459 unsigned long processor = strtoul (start, ccp, 10);
1460 if (*ccp != start && processor <= 15)
1461 return processor;
1462 }
1463 /* Fall through. */
1464
1465 case REG_TYPE_MMXWC:
1466 /* WC includes WCG. ??? I'm not sure this is true for all
1467 instructions that take WC registers. */
1468 if (reg && reg->type == REG_TYPE_MMXWCG)
1469 return reg->number;
1470 break;
1471
1472 default:
1473 break;
1474 }
1475
1476 return FAIL;
1477 }
1478
1479 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1480 return value is the register number or FAIL. */
1481
1482 static int
1483 arm_reg_parse (char **ccp, enum arm_reg_type type)
1484 {
1485 char *start = *ccp;
1486 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1487 int ret;
1488
1489 /* Do not allow a scalar (reg+index) to parse as a register. */
1490 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1491 return FAIL;
1492
1493 if (reg && reg->type == type)
1494 return reg->number;
1495
1496 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1497 return ret;
1498
1499 *ccp = start;
1500 return FAIL;
1501 }
1502
1503 /* Parse a Neon type specifier. *STR should point at the leading '.'
1504 character. Does no verification at this stage that the type fits the opcode
1505 properly. E.g.,
1506
1507 .i32.i32.s16
1508 .s32.f32
1509 .u16
1510
1511 Can all be legally parsed by this function.
1512
1513 Fills in neon_type struct pointer with parsed information, and updates STR
1514 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1515 type, FAIL if not. */
1516
1517 static int
1518 parse_neon_type (struct neon_type *type, char **str)
1519 {
1520 char *ptr = *str;
1521
1522 if (type)
1523 type->elems = 0;
1524
1525 while (type->elems < NEON_MAX_TYPE_ELS)
1526 {
1527 enum neon_el_type thistype = NT_untyped;
1528 unsigned thissize = -1u;
1529
1530 if (*ptr != '.')
1531 break;
1532
1533 ptr++;
1534
1535 /* Just a size without an explicit type. */
1536 if (ISDIGIT (*ptr))
1537 goto parsesize;
1538
1539 switch (TOLOWER (*ptr))
1540 {
1541 case 'i': thistype = NT_integer; break;
1542 case 'f': thistype = NT_float; break;
1543 case 'p': thistype = NT_poly; break;
1544 case 's': thistype = NT_signed; break;
1545 case 'u': thistype = NT_unsigned; break;
1546 case 'd':
1547 thistype = NT_float;
1548 thissize = 64;
1549 ptr++;
1550 goto done;
1551 case 'b':
1552 thistype = NT_bfloat;
1553 switch (TOLOWER (*(++ptr)))
1554 {
1555 case 'f':
1556 ptr += 1;
1557 thissize = strtoul (ptr, &ptr, 10);
1558 if (thissize != 16)
1559 {
1560 as_bad (_("bad size %d in type specifier"), thissize);
1561 return FAIL;
1562 }
1563 goto done;
1564 case '0': case '1': case '2': case '3': case '4':
1565 case '5': case '6': case '7': case '8': case '9':
1566 case ' ': case '.':
1567 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1568 return FAIL;
1569 default:
1570 break;
1571 }
1572 break;
1573 default:
1574 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1575 return FAIL;
1576 }
1577
1578 ptr++;
1579
1580 /* .f is an abbreviation for .f32. */
1581 if (thistype == NT_float && !ISDIGIT (*ptr))
1582 thissize = 32;
1583 else
1584 {
1585 parsesize:
1586 thissize = strtoul (ptr, &ptr, 10);
1587
1588 if (thissize != 8 && thissize != 16 && thissize != 32
1589 && thissize != 64)
1590 {
1591 as_bad (_("bad size %d in type specifier"), thissize);
1592 return FAIL;
1593 }
1594 }
1595
1596 done:
1597 if (type)
1598 {
1599 type->el[type->elems].type = thistype;
1600 type->el[type->elems].size = thissize;
1601 type->elems++;
1602 }
1603 }
1604
1605 /* Empty/missing type is not a successful parse. */
1606 if (type->elems == 0)
1607 return FAIL;
1608
1609 *str = ptr;
1610
1611 return SUCCESS;
1612 }
1613
1614 /* Errors may be set multiple times during parsing or bit encoding
1615 (particularly in the Neon bits), but usually the earliest error which is set
1616 will be the most meaningful. Avoid overwriting it with later (cascading)
1617 errors by calling this function. */
1618
1619 static void
1620 first_error (const char *err)
1621 {
1622 if (!inst.error)
1623 inst.error = err;
1624 }
1625
1626 /* Parse a single type, e.g. ".s32", leading period included. */
1627 static int
1628 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1629 {
1630 char *str = *ccp;
1631 struct neon_type optype;
1632
1633 if (*str == '.')
1634 {
1635 if (parse_neon_type (&optype, &str) == SUCCESS)
1636 {
1637 if (optype.elems == 1)
1638 *vectype = optype.el[0];
1639 else
1640 {
1641 first_error (_("only one type should be specified for operand"));
1642 return FAIL;
1643 }
1644 }
1645 else
1646 {
1647 first_error (_("vector type expected"));
1648 return FAIL;
1649 }
1650 }
1651 else
1652 return FAIL;
1653
1654 *ccp = str;
1655
1656 return SUCCESS;
1657 }
1658
1659 /* Special meanings for indices (which have a range of 0-7), which will fit into
1660 a 4-bit integer. */
1661
1662 #define NEON_ALL_LANES 15
1663 #define NEON_INTERLEAVE_LANES 14
1664
1665 /* Record a use of the given feature. */
1666 static void
1667 record_feature_use (const arm_feature_set *feature)
1668 {
1669 if (thumb_mode)
1670 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1671 else
1672 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1673 }
1674
1675 /* If the given feature available in the selected CPU, mark it as used.
1676 Returns TRUE iff feature is available. */
1677 static bfd_boolean
1678 mark_feature_used (const arm_feature_set *feature)
1679 {
1680
1681 /* Do not support the use of MVE only instructions when in auto-detection or
1682 -march=all. */
1683 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1684 && ARM_CPU_IS_ANY (cpu_variant))
1685 {
1686 first_error (BAD_MVE_AUTO);
1687 return FALSE;
1688 }
1689 /* Ensure the option is valid on the current architecture. */
1690 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1691 return FALSE;
1692
1693 /* Add the appropriate architecture feature for the barrier option used.
1694 */
1695 record_feature_use (feature);
1696
1697 return TRUE;
1698 }
1699
1700 /* Parse either a register or a scalar, with an optional type. Return the
1701 register number, and optionally fill in the actual type of the register
1702 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1703 type/index information in *TYPEINFO. */
1704
1705 static int
1706 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1707 enum arm_reg_type *rtype,
1708 struct neon_typed_alias *typeinfo)
1709 {
1710 char *str = *ccp;
1711 struct reg_entry *reg = arm_reg_parse_multi (&str);
1712 struct neon_typed_alias atype;
1713 struct neon_type_el parsetype;
1714
1715 atype.defined = 0;
1716 atype.index = -1;
1717 atype.eltype.type = NT_invtype;
1718 atype.eltype.size = -1;
1719
1720 /* Try alternate syntax for some types of register. Note these are mutually
1721 exclusive with the Neon syntax extensions. */
1722 if (reg == NULL)
1723 {
1724 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1725 if (altreg != FAIL)
1726 *ccp = str;
1727 if (typeinfo)
1728 *typeinfo = atype;
1729 return altreg;
1730 }
1731
1732 /* Undo polymorphism when a set of register types may be accepted. */
1733 if ((type == REG_TYPE_NDQ
1734 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1735 || (type == REG_TYPE_VFSD
1736 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1737 || (type == REG_TYPE_NSDQ
1738 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1739 || reg->type == REG_TYPE_NQ))
1740 || (type == REG_TYPE_NSD
1741 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1742 || (type == REG_TYPE_MMXWC
1743 && (reg->type == REG_TYPE_MMXWCG)))
1744 type = (enum arm_reg_type) reg->type;
1745
1746 if (type == REG_TYPE_MQ)
1747 {
1748 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1749 return FAIL;
1750
1751 if (!reg || reg->type != REG_TYPE_NQ)
1752 return FAIL;
1753
1754 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1755 {
1756 first_error (_("expected MVE register [q0..q7]"));
1757 return FAIL;
1758 }
1759 type = REG_TYPE_NQ;
1760 }
1761 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1762 && (type == REG_TYPE_NQ))
1763 return FAIL;
1764
1765
1766 if (type != reg->type)
1767 return FAIL;
1768
1769 if (reg->neon)
1770 atype = *reg->neon;
1771
1772 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1773 {
1774 if ((atype.defined & NTA_HASTYPE) != 0)
1775 {
1776 first_error (_("can't redefine type for operand"));
1777 return FAIL;
1778 }
1779 atype.defined |= NTA_HASTYPE;
1780 atype.eltype = parsetype;
1781 }
1782
1783 if (skip_past_char (&str, '[') == SUCCESS)
1784 {
1785 if (type != REG_TYPE_VFD
1786 && !(type == REG_TYPE_VFS
1787 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1788 && !(type == REG_TYPE_NQ
1789 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
1790 {
1791 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1792 first_error (_("only D and Q registers may be indexed"));
1793 else
1794 first_error (_("only D registers may be indexed"));
1795 return FAIL;
1796 }
1797
1798 if ((atype.defined & NTA_HASINDEX) != 0)
1799 {
1800 first_error (_("can't change index for operand"));
1801 return FAIL;
1802 }
1803
1804 atype.defined |= NTA_HASINDEX;
1805
1806 if (skip_past_char (&str, ']') == SUCCESS)
1807 atype.index = NEON_ALL_LANES;
1808 else
1809 {
1810 expressionS exp;
1811
1812 my_get_expression (&exp, &str, GE_NO_PREFIX);
1813
1814 if (exp.X_op != O_constant)
1815 {
1816 first_error (_("constant expression required"));
1817 return FAIL;
1818 }
1819
1820 if (skip_past_char (&str, ']') == FAIL)
1821 return FAIL;
1822
1823 atype.index = exp.X_add_number;
1824 }
1825 }
1826
1827 if (typeinfo)
1828 *typeinfo = atype;
1829
1830 if (rtype)
1831 *rtype = type;
1832
1833 *ccp = str;
1834
1835 return reg->number;
1836 }
1837
1838 /* Like arm_reg_parse, but also allow the following extra features:
1839 - If RTYPE is non-zero, return the (possibly restricted) type of the
1840 register (e.g. Neon double or quad reg when either has been requested).
1841 - If this is a Neon vector type with additional type information, fill
1842 in the struct pointed to by VECTYPE (if non-NULL).
1843 This function will fault on encountering a scalar. */
1844
1845 static int
1846 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1847 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1848 {
1849 struct neon_typed_alias atype;
1850 char *str = *ccp;
1851 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1852
1853 if (reg == FAIL)
1854 return FAIL;
1855
1856 /* Do not allow regname(... to parse as a register. */
1857 if (*str == '(')
1858 return FAIL;
1859
1860 /* Do not allow a scalar (reg+index) to parse as a register. */
1861 if ((atype.defined & NTA_HASINDEX) != 0)
1862 {
1863 first_error (_("register operand expected, but got scalar"));
1864 return FAIL;
1865 }
1866
1867 if (vectype)
1868 *vectype = atype.eltype;
1869
1870 *ccp = str;
1871
1872 return reg;
1873 }
1874
1875 #define NEON_SCALAR_REG(X) ((X) >> 4)
1876 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1877
1878 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1879 have enough information to be able to do a good job bounds-checking. So, we
1880 just do easy checks here, and do further checks later. */
1881
1882 static int
1883 parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1884 arm_reg_type reg_type)
1885 {
1886 int reg;
1887 char *str = *ccp;
1888 struct neon_typed_alias atype;
1889 unsigned reg_size;
1890
1891 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1892
1893 switch (reg_type)
1894 {
1895 case REG_TYPE_VFS:
1896 reg_size = 32;
1897 break;
1898 case REG_TYPE_VFD:
1899 reg_size = 64;
1900 break;
1901 case REG_TYPE_MQ:
1902 reg_size = 128;
1903 break;
1904 default:
1905 gas_assert (0);
1906 return FAIL;
1907 }
1908
1909 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1910 return FAIL;
1911
1912 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
1913 {
1914 first_error (_("scalar must have an index"));
1915 return FAIL;
1916 }
1917 else if (atype.index >= reg_size / elsize)
1918 {
1919 first_error (_("scalar index out of range"));
1920 return FAIL;
1921 }
1922
1923 if (type)
1924 *type = atype.eltype;
1925
1926 *ccp = str;
1927
1928 return reg * 16 + atype.index;
1929 }
1930
1931 /* Types of registers in a list. */
1932
1933 enum reg_list_els
1934 {
1935 REGLIST_RN,
1936 REGLIST_CLRM,
1937 REGLIST_VFP_S,
1938 REGLIST_VFP_S_VPR,
1939 REGLIST_VFP_D,
1940 REGLIST_VFP_D_VPR,
1941 REGLIST_NEON_D
1942 };
1943
1944 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1945
1946 static long
1947 parse_reg_list (char ** strp, enum reg_list_els etype)
1948 {
1949 char *str = *strp;
1950 long range = 0;
1951 int another_range;
1952
1953 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
1954
1955 /* We come back here if we get ranges concatenated by '+' or '|'. */
1956 do
1957 {
1958 skip_whitespace (str);
1959
1960 another_range = 0;
1961
1962 if (*str == '{')
1963 {
1964 int in_range = 0;
1965 int cur_reg = -1;
1966
1967 str++;
1968 do
1969 {
1970 int reg;
1971 const char apsr_str[] = "apsr";
1972 int apsr_str_len = strlen (apsr_str);
1973
1974 reg = arm_reg_parse (&str, REG_TYPE_RN);
1975 if (etype == REGLIST_CLRM)
1976 {
1977 if (reg == REG_SP || reg == REG_PC)
1978 reg = FAIL;
1979 else if (reg == FAIL
1980 && !strncasecmp (str, apsr_str, apsr_str_len)
1981 && !ISALPHA (*(str + apsr_str_len)))
1982 {
1983 reg = 15;
1984 str += apsr_str_len;
1985 }
1986
1987 if (reg == FAIL)
1988 {
1989 first_error (_("r0-r12, lr or APSR expected"));
1990 return FAIL;
1991 }
1992 }
1993 else /* etype == REGLIST_RN. */
1994 {
1995 if (reg == FAIL)
1996 {
1997 first_error (_(reg_expected_msgs[REGLIST_RN]));
1998 return FAIL;
1999 }
2000 }
2001
2002 if (in_range)
2003 {
2004 int i;
2005
2006 if (reg <= cur_reg)
2007 {
2008 first_error (_("bad range in register list"));
2009 return FAIL;
2010 }
2011
2012 for (i = cur_reg + 1; i < reg; i++)
2013 {
2014 if (range & (1 << i))
2015 as_tsktsk
2016 (_("Warning: duplicated register (r%d) in register list"),
2017 i);
2018 else
2019 range |= 1 << i;
2020 }
2021 in_range = 0;
2022 }
2023
2024 if (range & (1 << reg))
2025 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
2026 reg);
2027 else if (reg <= cur_reg)
2028 as_tsktsk (_("Warning: register range not in ascending order"));
2029
2030 range |= 1 << reg;
2031 cur_reg = reg;
2032 }
2033 while (skip_past_comma (&str) != FAIL
2034 || (in_range = 1, *str++ == '-'));
2035 str--;
2036
2037 if (skip_past_char (&str, '}') == FAIL)
2038 {
2039 first_error (_("missing `}'"));
2040 return FAIL;
2041 }
2042 }
2043 else if (etype == REGLIST_RN)
2044 {
2045 expressionS exp;
2046
2047 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
2048 return FAIL;
2049
2050 if (exp.X_op == O_constant)
2051 {
2052 if (exp.X_add_number
2053 != (exp.X_add_number & 0x0000ffff))
2054 {
2055 inst.error = _("invalid register mask");
2056 return FAIL;
2057 }
2058
2059 if ((range & exp.X_add_number) != 0)
2060 {
2061 int regno = range & exp.X_add_number;
2062
2063 regno &= -regno;
2064 regno = (1 << regno) - 1;
2065 as_tsktsk
2066 (_("Warning: duplicated register (r%d) in register list"),
2067 regno);
2068 }
2069
2070 range |= exp.X_add_number;
2071 }
2072 else
2073 {
2074 if (inst.relocs[0].type != 0)
2075 {
2076 inst.error = _("expression too complex");
2077 return FAIL;
2078 }
2079
2080 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2081 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2082 inst.relocs[0].pc_rel = 0;
2083 }
2084 }
2085
2086 if (*str == '|' || *str == '+')
2087 {
2088 str++;
2089 another_range = 1;
2090 }
2091 }
2092 while (another_range);
2093
2094 *strp = str;
2095 return range;
2096 }
2097
2098 /* Parse a VFP register list. If the string is invalid return FAIL.
2099 Otherwise return the number of registers, and set PBASE to the first
2100 register. Parses registers of type ETYPE.
2101 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2102 - Q registers can be used to specify pairs of D registers
2103 - { } can be omitted from around a singleton register list
2104 FIXME: This is not implemented, as it would require backtracking in
2105 some cases, e.g.:
2106 vtbl.8 d3,d4,d5
2107 This could be done (the meaning isn't really ambiguous), but doesn't
2108 fit in well with the current parsing framework.
2109 - 32 D registers may be used (also true for VFPv3).
2110 FIXME: Types are ignored in these register lists, which is probably a
2111 bug. */
2112
2113 static int
2114 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2115 bfd_boolean *partial_match)
2116 {
2117 char *str = *ccp;
2118 int base_reg;
2119 int new_base;
2120 enum arm_reg_type regtype = (enum arm_reg_type) 0;
2121 int max_regs = 0;
2122 int count = 0;
2123 int warned = 0;
2124 unsigned long mask = 0;
2125 int i;
2126 bfd_boolean vpr_seen = FALSE;
2127 bfd_boolean expect_vpr =
2128 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
2129
2130 if (skip_past_char (&str, '{') == FAIL)
2131 {
2132 inst.error = _("expecting {");
2133 return FAIL;
2134 }
2135
2136 switch (etype)
2137 {
2138 case REGLIST_VFP_S:
2139 case REGLIST_VFP_S_VPR:
2140 regtype = REG_TYPE_VFS;
2141 max_regs = 32;
2142 break;
2143
2144 case REGLIST_VFP_D:
2145 case REGLIST_VFP_D_VPR:
2146 regtype = REG_TYPE_VFD;
2147 break;
2148
2149 case REGLIST_NEON_D:
2150 regtype = REG_TYPE_NDQ;
2151 break;
2152
2153 default:
2154 gas_assert (0);
2155 }
2156
2157 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
2158 {
2159 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2160 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
2161 {
2162 max_regs = 32;
2163 if (thumb_mode)
2164 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2165 fpu_vfp_ext_d32);
2166 else
2167 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2168 fpu_vfp_ext_d32);
2169 }
2170 else
2171 max_regs = 16;
2172 }
2173
2174 base_reg = max_regs;
2175 *partial_match = FALSE;
2176
2177 do
2178 {
2179 int setmask = 1, addregs = 1;
2180 const char vpr_str[] = "vpr";
2181 int vpr_str_len = strlen (vpr_str);
2182
2183 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
2184
2185 if (expect_vpr)
2186 {
2187 if (new_base == FAIL
2188 && !strncasecmp (str, vpr_str, vpr_str_len)
2189 && !ISALPHA (*(str + vpr_str_len))
2190 && !vpr_seen)
2191 {
2192 vpr_seen = TRUE;
2193 str += vpr_str_len;
2194 if (count == 0)
2195 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2196 }
2197 else if (vpr_seen)
2198 {
2199 first_error (_("VPR expected last"));
2200 return FAIL;
2201 }
2202 else if (new_base == FAIL)
2203 {
2204 if (regtype == REG_TYPE_VFS)
2205 first_error (_("VFP single precision register or VPR "
2206 "expected"));
2207 else /* regtype == REG_TYPE_VFD. */
2208 first_error (_("VFP/Neon double precision register or VPR "
2209 "expected"));
2210 return FAIL;
2211 }
2212 }
2213 else if (new_base == FAIL)
2214 {
2215 first_error (_(reg_expected_msgs[regtype]));
2216 return FAIL;
2217 }
2218
2219 *partial_match = TRUE;
2220 if (vpr_seen)
2221 continue;
2222
2223 if (new_base >= max_regs)
2224 {
2225 first_error (_("register out of range in list"));
2226 return FAIL;
2227 }
2228
2229 /* Note: a value of 2 * n is returned for the register Q<n>. */
2230 if (regtype == REG_TYPE_NQ)
2231 {
2232 setmask = 3;
2233 addregs = 2;
2234 }
2235
2236 if (new_base < base_reg)
2237 base_reg = new_base;
2238
2239 if (mask & (setmask << new_base))
2240 {
2241 first_error (_("invalid register list"));
2242 return FAIL;
2243 }
2244
2245 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
2246 {
2247 as_tsktsk (_("register list not in ascending order"));
2248 warned = 1;
2249 }
2250
2251 mask |= setmask << new_base;
2252 count += addregs;
2253
2254 if (*str == '-') /* We have the start of a range expression */
2255 {
2256 int high_range;
2257
2258 str++;
2259
2260 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
2261 == FAIL)
2262 {
2263 inst.error = gettext (reg_expected_msgs[regtype]);
2264 return FAIL;
2265 }
2266
2267 if (high_range >= max_regs)
2268 {
2269 first_error (_("register out of range in list"));
2270 return FAIL;
2271 }
2272
2273 if (regtype == REG_TYPE_NQ)
2274 high_range = high_range + 1;
2275
2276 if (high_range <= new_base)
2277 {
2278 inst.error = _("register range not in ascending order");
2279 return FAIL;
2280 }
2281
2282 for (new_base += addregs; new_base <= high_range; new_base += addregs)
2283 {
2284 if (mask & (setmask << new_base))
2285 {
2286 inst.error = _("invalid register list");
2287 return FAIL;
2288 }
2289
2290 mask |= setmask << new_base;
2291 count += addregs;
2292 }
2293 }
2294 }
2295 while (skip_past_comma (&str) != FAIL);
2296
2297 str++;
2298
2299 /* Sanity check -- should have raised a parse error above. */
2300 if ((!vpr_seen && count == 0) || count > max_regs)
2301 abort ();
2302
2303 *pbase = base_reg;
2304
2305 if (expect_vpr && !vpr_seen)
2306 {
2307 first_error (_("VPR expected last"));
2308 return FAIL;
2309 }
2310
2311 /* Final test -- the registers must be consecutive. */
2312 mask >>= base_reg;
2313 for (i = 0; i < count; i++)
2314 {
2315 if ((mask & (1u << i)) == 0)
2316 {
2317 inst.error = _("non-contiguous register range");
2318 return FAIL;
2319 }
2320 }
2321
2322 *ccp = str;
2323
2324 return count;
2325 }
2326
2327 /* True if two alias types are the same. */
2328
2329 static bfd_boolean
2330 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2331 {
2332 if (!a && !b)
2333 return TRUE;
2334
2335 if (!a || !b)
2336 return FALSE;
2337
2338 if (a->defined != b->defined)
2339 return FALSE;
2340
2341 if ((a->defined & NTA_HASTYPE) != 0
2342 && (a->eltype.type != b->eltype.type
2343 || a->eltype.size != b->eltype.size))
2344 return FALSE;
2345
2346 if ((a->defined & NTA_HASINDEX) != 0
2347 && (a->index != b->index))
2348 return FALSE;
2349
2350 return TRUE;
2351 }
2352
2353 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2354 The base register is put in *PBASE.
2355 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2356 the return value.
2357 The register stride (minus one) is put in bit 4 of the return value.
2358 Bits [6:5] encode the list length (minus one).
2359 The type of the list elements is put in *ELTYPE, if non-NULL. */
2360
2361 #define NEON_LANE(X) ((X) & 0xf)
2362 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2363 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2364
2365 static int
2366 parse_neon_el_struct_list (char **str, unsigned *pbase,
2367 int mve,
2368 struct neon_type_el *eltype)
2369 {
2370 char *ptr = *str;
2371 int base_reg = -1;
2372 int reg_incr = -1;
2373 int count = 0;
2374 int lane = -1;
2375 int leading_brace = 0;
2376 enum arm_reg_type rtype = REG_TYPE_NDQ;
2377 const char *const incr_error = mve ? _("register stride must be 1") :
2378 _("register stride must be 1 or 2");
2379 const char *const type_error = _("mismatched element/structure types in list");
2380 struct neon_typed_alias firsttype;
2381 firsttype.defined = 0;
2382 firsttype.eltype.type = NT_invtype;
2383 firsttype.eltype.size = -1;
2384 firsttype.index = -1;
2385
2386 if (skip_past_char (&ptr, '{') == SUCCESS)
2387 leading_brace = 1;
2388
2389 do
2390 {
2391 struct neon_typed_alias atype;
2392 if (mve)
2393 rtype = REG_TYPE_MQ;
2394 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2395
2396 if (getreg == FAIL)
2397 {
2398 first_error (_(reg_expected_msgs[rtype]));
2399 return FAIL;
2400 }
2401
2402 if (base_reg == -1)
2403 {
2404 base_reg = getreg;
2405 if (rtype == REG_TYPE_NQ)
2406 {
2407 reg_incr = 1;
2408 }
2409 firsttype = atype;
2410 }
2411 else if (reg_incr == -1)
2412 {
2413 reg_incr = getreg - base_reg;
2414 if (reg_incr < 1 || reg_incr > 2)
2415 {
2416 first_error (_(incr_error));
2417 return FAIL;
2418 }
2419 }
2420 else if (getreg != base_reg + reg_incr * count)
2421 {
2422 first_error (_(incr_error));
2423 return FAIL;
2424 }
2425
2426 if (! neon_alias_types_same (&atype, &firsttype))
2427 {
2428 first_error (_(type_error));
2429 return FAIL;
2430 }
2431
2432 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2433 modes. */
2434 if (ptr[0] == '-')
2435 {
2436 struct neon_typed_alias htype;
2437 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2438 if (lane == -1)
2439 lane = NEON_INTERLEAVE_LANES;
2440 else if (lane != NEON_INTERLEAVE_LANES)
2441 {
2442 first_error (_(type_error));
2443 return FAIL;
2444 }
2445 if (reg_incr == -1)
2446 reg_incr = 1;
2447 else if (reg_incr != 1)
2448 {
2449 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2450 return FAIL;
2451 }
2452 ptr++;
2453 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2454 if (hireg == FAIL)
2455 {
2456 first_error (_(reg_expected_msgs[rtype]));
2457 return FAIL;
2458 }
2459 if (! neon_alias_types_same (&htype, &firsttype))
2460 {
2461 first_error (_(type_error));
2462 return FAIL;
2463 }
2464 count += hireg + dregs - getreg;
2465 continue;
2466 }
2467
2468 /* If we're using Q registers, we can't use [] or [n] syntax. */
2469 if (rtype == REG_TYPE_NQ)
2470 {
2471 count += 2;
2472 continue;
2473 }
2474
2475 if ((atype.defined & NTA_HASINDEX) != 0)
2476 {
2477 if (lane == -1)
2478 lane = atype.index;
2479 else if (lane != atype.index)
2480 {
2481 first_error (_(type_error));
2482 return FAIL;
2483 }
2484 }
2485 else if (lane == -1)
2486 lane = NEON_INTERLEAVE_LANES;
2487 else if (lane != NEON_INTERLEAVE_LANES)
2488 {
2489 first_error (_(type_error));
2490 return FAIL;
2491 }
2492 count++;
2493 }
2494 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2495
2496 /* No lane set by [x]. We must be interleaving structures. */
2497 if (lane == -1)
2498 lane = NEON_INTERLEAVE_LANES;
2499
2500 /* Sanity check. */
2501 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
2502 || (count > 1 && reg_incr == -1))
2503 {
2504 first_error (_("error parsing element/structure list"));
2505 return FAIL;
2506 }
2507
2508 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2509 {
2510 first_error (_("expected }"));
2511 return FAIL;
2512 }
2513
2514 if (reg_incr == -1)
2515 reg_incr = 1;
2516
2517 if (eltype)
2518 *eltype = firsttype.eltype;
2519
2520 *pbase = base_reg;
2521 *str = ptr;
2522
2523 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2524 }
2525
2526 /* Parse an explicit relocation suffix on an expression. This is
2527 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2528 arm_reloc_hsh contains no entries, so this function can only
2529 succeed if there is no () after the word. Returns -1 on error,
2530 BFD_RELOC_UNUSED if there wasn't any suffix. */
2531
2532 static int
2533 parse_reloc (char **str)
2534 {
2535 struct reloc_entry *r;
2536 char *p, *q;
2537
2538 if (**str != '(')
2539 return BFD_RELOC_UNUSED;
2540
2541 p = *str + 1;
2542 q = p;
2543
2544 while (*q && *q != ')' && *q != ',')
2545 q++;
2546 if (*q != ')')
2547 return -1;
2548
2549 if ((r = (struct reloc_entry *)
2550 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2551 return -1;
2552
2553 *str = q + 1;
2554 return r->reloc;
2555 }
2556
2557 /* Directives: register aliases. */
2558
2559 static struct reg_entry *
2560 insert_reg_alias (char *str, unsigned number, int type)
2561 {
2562 struct reg_entry *new_reg;
2563 const char *name;
2564
2565 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2566 {
2567 if (new_reg->builtin)
2568 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2569
2570 /* Only warn about a redefinition if it's not defined as the
2571 same register. */
2572 else if (new_reg->number != number || new_reg->type != type)
2573 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2574
2575 return NULL;
2576 }
2577
2578 name = xstrdup (str);
2579 new_reg = XNEW (struct reg_entry);
2580
2581 new_reg->name = name;
2582 new_reg->number = number;
2583 new_reg->type = type;
2584 new_reg->builtin = FALSE;
2585 new_reg->neon = NULL;
2586
2587 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2588 abort ();
2589
2590 return new_reg;
2591 }
2592
2593 static void
2594 insert_neon_reg_alias (char *str, int number, int type,
2595 struct neon_typed_alias *atype)
2596 {
2597 struct reg_entry *reg = insert_reg_alias (str, number, type);
2598
2599 if (!reg)
2600 {
2601 first_error (_("attempt to redefine typed alias"));
2602 return;
2603 }
2604
2605 if (atype)
2606 {
2607 reg->neon = XNEW (struct neon_typed_alias);
2608 *reg->neon = *atype;
2609 }
2610 }
2611
2612 /* Look for the .req directive. This is of the form:
2613
2614 new_register_name .req existing_register_name
2615
2616 If we find one, or if it looks sufficiently like one that we want to
2617 handle any error here, return TRUE. Otherwise return FALSE. */
2618
2619 static bfd_boolean
2620 create_register_alias (char * newname, char *p)
2621 {
2622 struct reg_entry *old;
2623 char *oldname, *nbuf;
2624 size_t nlen;
2625
2626 /* The input scrubber ensures that whitespace after the mnemonic is
2627 collapsed to single spaces. */
2628 oldname = p;
2629 if (strncmp (oldname, " .req ", 6) != 0)
2630 return FALSE;
2631
2632 oldname += 6;
2633 if (*oldname == '\0')
2634 return FALSE;
2635
2636 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2637 if (!old)
2638 {
2639 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2640 return TRUE;
2641 }
2642
2643 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2644 the desired alias name, and p points to its end. If not, then
2645 the desired alias name is in the global original_case_string. */
2646 #ifdef TC_CASE_SENSITIVE
2647 nlen = p - newname;
2648 #else
2649 newname = original_case_string;
2650 nlen = strlen (newname);
2651 #endif
2652
2653 nbuf = xmemdup0 (newname, nlen);
2654
2655 /* Create aliases under the new name as stated; an all-lowercase
2656 version of the new name; and an all-uppercase version of the new
2657 name. */
2658 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2659 {
2660 for (p = nbuf; *p; p++)
2661 *p = TOUPPER (*p);
2662
2663 if (strncmp (nbuf, newname, nlen))
2664 {
2665 /* If this attempt to create an additional alias fails, do not bother
2666 trying to create the all-lower case alias. We will fail and issue
2667 a second, duplicate error message. This situation arises when the
2668 programmer does something like:
2669 foo .req r0
2670 Foo .req r1
2671 The second .req creates the "Foo" alias but then fails to create
2672 the artificial FOO alias because it has already been created by the
2673 first .req. */
2674 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2675 {
2676 free (nbuf);
2677 return TRUE;
2678 }
2679 }
2680
2681 for (p = nbuf; *p; p++)
2682 *p = TOLOWER (*p);
2683
2684 if (strncmp (nbuf, newname, nlen))
2685 insert_reg_alias (nbuf, old->number, old->type);
2686 }
2687
2688 free (nbuf);
2689 return TRUE;
2690 }
2691
2692 /* Create a Neon typed/indexed register alias using directives, e.g.:
2693 X .dn d5.s32[1]
2694 Y .qn 6.s16
2695 Z .dn d7
2696 T .dn Z[0]
2697 These typed registers can be used instead of the types specified after the
2698 Neon mnemonic, so long as all operands given have types. Types can also be
2699 specified directly, e.g.:
2700 vadd d0.s32, d1.s32, d2.s32 */
2701
2702 static bfd_boolean
2703 create_neon_reg_alias (char *newname, char *p)
2704 {
2705 enum arm_reg_type basetype;
2706 struct reg_entry *basereg;
2707 struct reg_entry mybasereg;
2708 struct neon_type ntype;
2709 struct neon_typed_alias typeinfo;
2710 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2711 int namelen;
2712
2713 typeinfo.defined = 0;
2714 typeinfo.eltype.type = NT_invtype;
2715 typeinfo.eltype.size = -1;
2716 typeinfo.index = -1;
2717
2718 nameend = p;
2719
2720 if (strncmp (p, " .dn ", 5) == 0)
2721 basetype = REG_TYPE_VFD;
2722 else if (strncmp (p, " .qn ", 5) == 0)
2723 basetype = REG_TYPE_NQ;
2724 else
2725 return FALSE;
2726
2727 p += 5;
2728
2729 if (*p == '\0')
2730 return FALSE;
2731
2732 basereg = arm_reg_parse_multi (&p);
2733
2734 if (basereg && basereg->type != basetype)
2735 {
2736 as_bad (_("bad type for register"));
2737 return FALSE;
2738 }
2739
2740 if (basereg == NULL)
2741 {
2742 expressionS exp;
2743 /* Try parsing as an integer. */
2744 my_get_expression (&exp, &p, GE_NO_PREFIX);
2745 if (exp.X_op != O_constant)
2746 {
2747 as_bad (_("expression must be constant"));
2748 return FALSE;
2749 }
2750 basereg = &mybasereg;
2751 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2752 : exp.X_add_number;
2753 basereg->neon = 0;
2754 }
2755
2756 if (basereg->neon)
2757 typeinfo = *basereg->neon;
2758
2759 if (parse_neon_type (&ntype, &p) == SUCCESS)
2760 {
2761 /* We got a type. */
2762 if (typeinfo.defined & NTA_HASTYPE)
2763 {
2764 as_bad (_("can't redefine the type of a register alias"));
2765 return FALSE;
2766 }
2767
2768 typeinfo.defined |= NTA_HASTYPE;
2769 if (ntype.elems != 1)
2770 {
2771 as_bad (_("you must specify a single type only"));
2772 return FALSE;
2773 }
2774 typeinfo.eltype = ntype.el[0];
2775 }
2776
2777 if (skip_past_char (&p, '[') == SUCCESS)
2778 {
2779 expressionS exp;
2780 /* We got a scalar index. */
2781
2782 if (typeinfo.defined & NTA_HASINDEX)
2783 {
2784 as_bad (_("can't redefine the index of a scalar alias"));
2785 return FALSE;
2786 }
2787
2788 my_get_expression (&exp, &p, GE_NO_PREFIX);
2789
2790 if (exp.X_op != O_constant)
2791 {
2792 as_bad (_("scalar index must be constant"));
2793 return FALSE;
2794 }
2795
2796 typeinfo.defined |= NTA_HASINDEX;
2797 typeinfo.index = exp.X_add_number;
2798
2799 if (skip_past_char (&p, ']') == FAIL)
2800 {
2801 as_bad (_("expecting ]"));
2802 return FALSE;
2803 }
2804 }
2805
2806 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2807 the desired alias name, and p points to its end. If not, then
2808 the desired alias name is in the global original_case_string. */
2809 #ifdef TC_CASE_SENSITIVE
2810 namelen = nameend - newname;
2811 #else
2812 newname = original_case_string;
2813 namelen = strlen (newname);
2814 #endif
2815
2816 namebuf = xmemdup0 (newname, namelen);
2817
2818 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2819 typeinfo.defined != 0 ? &typeinfo : NULL);
2820
2821 /* Insert name in all uppercase. */
2822 for (p = namebuf; *p; p++)
2823 *p = TOUPPER (*p);
2824
2825 if (strncmp (namebuf, newname, namelen))
2826 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2827 typeinfo.defined != 0 ? &typeinfo : NULL);
2828
2829 /* Insert name in all lowercase. */
2830 for (p = namebuf; *p; p++)
2831 *p = TOLOWER (*p);
2832
2833 if (strncmp (namebuf, newname, namelen))
2834 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2835 typeinfo.defined != 0 ? &typeinfo : NULL);
2836
2837 free (namebuf);
2838 return TRUE;
2839 }
2840
2841 /* Should never be called, as .req goes between the alias and the
2842 register name, not at the beginning of the line. */
2843
2844 static void
2845 s_req (int a ATTRIBUTE_UNUSED)
2846 {
2847 as_bad (_("invalid syntax for .req directive"));
2848 }
2849
2850 static void
2851 s_dn (int a ATTRIBUTE_UNUSED)
2852 {
2853 as_bad (_("invalid syntax for .dn directive"));
2854 }
2855
2856 static void
2857 s_qn (int a ATTRIBUTE_UNUSED)
2858 {
2859 as_bad (_("invalid syntax for .qn directive"));
2860 }
2861
2862 /* The .unreq directive deletes an alias which was previously defined
2863 by .req. For example:
2864
2865 my_alias .req r11
2866 .unreq my_alias */
2867
2868 static void
2869 s_unreq (int a ATTRIBUTE_UNUSED)
2870 {
2871 char * name;
2872 char saved_char;
2873
2874 name = input_line_pointer;
2875
2876 while (*input_line_pointer != 0
2877 && *input_line_pointer != ' '
2878 && *input_line_pointer != '\n')
2879 ++input_line_pointer;
2880
2881 saved_char = *input_line_pointer;
2882 *input_line_pointer = 0;
2883
2884 if (!*name)
2885 as_bad (_("invalid syntax for .unreq directive"));
2886 else
2887 {
2888 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2889 name);
2890
2891 if (!reg)
2892 as_bad (_("unknown register alias '%s'"), name);
2893 else if (reg->builtin)
2894 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2895 name);
2896 else
2897 {
2898 char * p;
2899 char * nbuf;
2900
2901 hash_delete (arm_reg_hsh, name, FALSE);
2902 free ((char *) reg->name);
2903 if (reg->neon)
2904 free (reg->neon);
2905 free (reg);
2906
2907 /* Also locate the all upper case and all lower case versions.
2908 Do not complain if we cannot find one or the other as it
2909 was probably deleted above. */
2910
2911 nbuf = strdup (name);
2912 for (p = nbuf; *p; p++)
2913 *p = TOUPPER (*p);
2914 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2915 if (reg)
2916 {
2917 hash_delete (arm_reg_hsh, nbuf, FALSE);
2918 free ((char *) reg->name);
2919 if (reg->neon)
2920 free (reg->neon);
2921 free (reg);
2922 }
2923
2924 for (p = nbuf; *p; p++)
2925 *p = TOLOWER (*p);
2926 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2927 if (reg)
2928 {
2929 hash_delete (arm_reg_hsh, nbuf, FALSE);
2930 free ((char *) reg->name);
2931 if (reg->neon)
2932 free (reg->neon);
2933 free (reg);
2934 }
2935
2936 free (nbuf);
2937 }
2938 }
2939
2940 *input_line_pointer = saved_char;
2941 demand_empty_rest_of_line ();
2942 }
2943
2944 /* Directives: Instruction set selection. */
2945
2946 #ifdef OBJ_ELF
2947 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2948 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2949 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2950 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2951
2952 /* Create a new mapping symbol for the transition to STATE. */
2953
2954 static void
2955 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2956 {
2957 symbolS * symbolP;
2958 const char * symname;
2959 int type;
2960
2961 switch (state)
2962 {
2963 case MAP_DATA:
2964 symname = "$d";
2965 type = BSF_NO_FLAGS;
2966 break;
2967 case MAP_ARM:
2968 symname = "$a";
2969 type = BSF_NO_FLAGS;
2970 break;
2971 case MAP_THUMB:
2972 symname = "$t";
2973 type = BSF_NO_FLAGS;
2974 break;
2975 default:
2976 abort ();
2977 }
2978
2979 symbolP = symbol_new (symname, now_seg, value, frag);
2980 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2981
2982 switch (state)
2983 {
2984 case MAP_ARM:
2985 THUMB_SET_FUNC (symbolP, 0);
2986 ARM_SET_THUMB (symbolP, 0);
2987 ARM_SET_INTERWORK (symbolP, support_interwork);
2988 break;
2989
2990 case MAP_THUMB:
2991 THUMB_SET_FUNC (symbolP, 1);
2992 ARM_SET_THUMB (symbolP, 1);
2993 ARM_SET_INTERWORK (symbolP, support_interwork);
2994 break;
2995
2996 case MAP_DATA:
2997 default:
2998 break;
2999 }
3000
3001 /* Save the mapping symbols for future reference. Also check that
3002 we do not place two mapping symbols at the same offset within a
3003 frag. We'll handle overlap between frags in
3004 check_mapping_symbols.
3005
3006 If .fill or other data filling directive generates zero sized data,
3007 the mapping symbol for the following code will have the same value
3008 as the one generated for the data filling directive. In this case,
3009 we replace the old symbol with the new one at the same address. */
3010 if (value == 0)
3011 {
3012 if (frag->tc_frag_data.first_map != NULL)
3013 {
3014 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
3015 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
3016 }
3017 frag->tc_frag_data.first_map = symbolP;
3018 }
3019 if (frag->tc_frag_data.last_map != NULL)
3020 {
3021 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
3022 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
3023 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
3024 }
3025 frag->tc_frag_data.last_map = symbolP;
3026 }
3027
3028 /* We must sometimes convert a region marked as code to data during
3029 code alignment, if an odd number of bytes have to be padded. The
3030 code mapping symbol is pushed to an aligned address. */
3031
3032 static void
3033 insert_data_mapping_symbol (enum mstate state,
3034 valueT value, fragS *frag, offsetT bytes)
3035 {
3036 /* If there was already a mapping symbol, remove it. */
3037 if (frag->tc_frag_data.last_map != NULL
3038 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
3039 {
3040 symbolS *symp = frag->tc_frag_data.last_map;
3041
3042 if (value == 0)
3043 {
3044 know (frag->tc_frag_data.first_map == symp);
3045 frag->tc_frag_data.first_map = NULL;
3046 }
3047 frag->tc_frag_data.last_map = NULL;
3048 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
3049 }
3050
3051 make_mapping_symbol (MAP_DATA, value, frag);
3052 make_mapping_symbol (state, value + bytes, frag);
3053 }
3054
3055 static void mapping_state_2 (enum mstate state, int max_chars);
3056
3057 /* Set the mapping state to STATE. Only call this when about to
3058 emit some STATE bytes to the file. */
3059
3060 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
3061 void
3062 mapping_state (enum mstate state)
3063 {
3064 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3065
3066 if (mapstate == state)
3067 /* The mapping symbol has already been emitted.
3068 There is nothing else to do. */
3069 return;
3070
3071 if (state == MAP_ARM || state == MAP_THUMB)
3072 /* PR gas/12931
3073 All ARM instructions require 4-byte alignment.
3074 (Almost) all Thumb instructions require 2-byte alignment.
3075
3076 When emitting instructions into any section, mark the section
3077 appropriately.
3078
3079 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3080 but themselves require 2-byte alignment; this applies to some
3081 PC- relative forms. However, these cases will involve implicit
3082 literal pool generation or an explicit .align >=2, both of
3083 which will cause the section to me marked with sufficient
3084 alignment. Thus, we don't handle those cases here. */
3085 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3086
3087 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
3088 /* This case will be evaluated later. */
3089 return;
3090
3091 mapping_state_2 (state, 0);
3092 }
3093
3094 /* Same as mapping_state, but MAX_CHARS bytes have already been
3095 allocated. Put the mapping symbol that far back. */
3096
3097 static void
3098 mapping_state_2 (enum mstate state, int max_chars)
3099 {
3100 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3101
3102 if (!SEG_NORMAL (now_seg))
3103 return;
3104
3105 if (mapstate == state)
3106 /* The mapping symbol has already been emitted.
3107 There is nothing else to do. */
3108 return;
3109
3110 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3111 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3112 {
3113 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3114 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3115
3116 if (add_symbol)
3117 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3118 }
3119
3120 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3121 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
3122 }
3123 #undef TRANSITION
3124 #else
3125 #define mapping_state(x) ((void)0)
3126 #define mapping_state_2(x, y) ((void)0)
3127 #endif
3128
3129 /* Find the real, Thumb encoded start of a Thumb function. */
3130
3131 #ifdef OBJ_COFF
3132 static symbolS *
3133 find_real_start (symbolS * symbolP)
3134 {
3135 char * real_start;
3136 const char * name = S_GET_NAME (symbolP);
3137 symbolS * new_target;
3138
3139 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3140 #define STUB_NAME ".real_start_of"
3141
3142 if (name == NULL)
3143 abort ();
3144
3145 /* The compiler may generate BL instructions to local labels because
3146 it needs to perform a branch to a far away location. These labels
3147 do not have a corresponding ".real_start_of" label. We check
3148 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3149 the ".real_start_of" convention for nonlocal branches. */
3150 if (S_IS_LOCAL (symbolP) || name[0] == '.')
3151 return symbolP;
3152
3153 real_start = concat (STUB_NAME, name, NULL);
3154 new_target = symbol_find (real_start);
3155 free (real_start);
3156
3157 if (new_target == NULL)
3158 {
3159 as_warn (_("Failed to find real start of function: %s\n"), name);
3160 new_target = symbolP;
3161 }
3162
3163 return new_target;
3164 }
3165 #endif
3166
3167 static void
3168 opcode_select (int width)
3169 {
3170 switch (width)
3171 {
3172 case 16:
3173 if (! thumb_mode)
3174 {
3175 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
3176 as_bad (_("selected processor does not support THUMB opcodes"));
3177
3178 thumb_mode = 1;
3179 /* No need to force the alignment, since we will have been
3180 coming from ARM mode, which is word-aligned. */
3181 record_alignment (now_seg, 1);
3182 }
3183 break;
3184
3185 case 32:
3186 if (thumb_mode)
3187 {
3188 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
3189 as_bad (_("selected processor does not support ARM opcodes"));
3190
3191 thumb_mode = 0;
3192
3193 if (!need_pass_2)
3194 frag_align (2, 0, 0);
3195
3196 record_alignment (now_seg, 1);
3197 }
3198 break;
3199
3200 default:
3201 as_bad (_("invalid instruction size selected (%d)"), width);
3202 }
3203 }
3204
3205 static void
3206 s_arm (int ignore ATTRIBUTE_UNUSED)
3207 {
3208 opcode_select (32);
3209 demand_empty_rest_of_line ();
3210 }
3211
3212 static void
3213 s_thumb (int ignore ATTRIBUTE_UNUSED)
3214 {
3215 opcode_select (16);
3216 demand_empty_rest_of_line ();
3217 }
3218
3219 static void
3220 s_code (int unused ATTRIBUTE_UNUSED)
3221 {
3222 int temp;
3223
3224 temp = get_absolute_expression ();
3225 switch (temp)
3226 {
3227 case 16:
3228 case 32:
3229 opcode_select (temp);
3230 break;
3231
3232 default:
3233 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3234 }
3235 }
3236
3237 static void
3238 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3239 {
3240 /* If we are not already in thumb mode go into it, EVEN if
3241 the target processor does not support thumb instructions.
3242 This is used by gcc/config/arm/lib1funcs.asm for example
3243 to compile interworking support functions even if the
3244 target processor should not support interworking. */
3245 if (! thumb_mode)
3246 {
3247 thumb_mode = 2;
3248 record_alignment (now_seg, 1);
3249 }
3250
3251 demand_empty_rest_of_line ();
3252 }
3253
3254 static void
3255 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3256 {
3257 s_thumb (0);
3258
3259 /* The following label is the name/address of the start of a Thumb function.
3260 We need to know this for the interworking support. */
3261 label_is_thumb_function_name = TRUE;
3262 }
3263
3264 /* Perform a .set directive, but also mark the alias as
3265 being a thumb function. */
3266
3267 static void
3268 s_thumb_set (int equiv)
3269 {
3270 /* XXX the following is a duplicate of the code for s_set() in read.c
3271 We cannot just call that code as we need to get at the symbol that
3272 is created. */
3273 char * name;
3274 char delim;
3275 char * end_name;
3276 symbolS * symbolP;
3277
3278 /* Especial apologies for the random logic:
3279 This just grew, and could be parsed much more simply!
3280 Dean - in haste. */
3281 delim = get_symbol_name (& name);
3282 end_name = input_line_pointer;
3283 (void) restore_line_pointer (delim);
3284
3285 if (*input_line_pointer != ',')
3286 {
3287 *end_name = 0;
3288 as_bad (_("expected comma after name \"%s\""), name);
3289 *end_name = delim;
3290 ignore_rest_of_line ();
3291 return;
3292 }
3293
3294 input_line_pointer++;
3295 *end_name = 0;
3296
3297 if (name[0] == '.' && name[1] == '\0')
3298 {
3299 /* XXX - this should not happen to .thumb_set. */
3300 abort ();
3301 }
3302
3303 if ((symbolP = symbol_find (name)) == NULL
3304 && (symbolP = md_undefined_symbol (name)) == NULL)
3305 {
3306 #ifndef NO_LISTING
3307 /* When doing symbol listings, play games with dummy fragments living
3308 outside the normal fragment chain to record the file and line info
3309 for this symbol. */
3310 if (listing & LISTING_SYMBOLS)
3311 {
3312 extern struct list_info_struct * listing_tail;
3313 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
3314
3315 memset (dummy_frag, 0, sizeof (fragS));
3316 dummy_frag->fr_type = rs_fill;
3317 dummy_frag->line = listing_tail;
3318 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3319 dummy_frag->fr_symbol = symbolP;
3320 }
3321 else
3322 #endif
3323 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3324
3325 #ifdef OBJ_COFF
3326 /* "set" symbols are local unless otherwise specified. */
3327 SF_SET_LOCAL (symbolP);
3328 #endif /* OBJ_COFF */
3329 } /* Make a new symbol. */
3330
3331 symbol_table_insert (symbolP);
3332
3333 * end_name = delim;
3334
3335 if (equiv
3336 && S_IS_DEFINED (symbolP)
3337 && S_GET_SEGMENT (symbolP) != reg_section)
3338 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3339
3340 pseudo_set (symbolP);
3341
3342 demand_empty_rest_of_line ();
3343
3344 /* XXX Now we come to the Thumb specific bit of code. */
3345
3346 THUMB_SET_FUNC (symbolP, 1);
3347 ARM_SET_THUMB (symbolP, 1);
3348 #if defined OBJ_ELF || defined OBJ_COFF
3349 ARM_SET_INTERWORK (symbolP, support_interwork);
3350 #endif
3351 }
3352
3353 /* Directives: Mode selection. */
3354
3355 /* .syntax [unified|divided] - choose the new unified syntax
3356 (same for Arm and Thumb encoding, modulo slight differences in what
3357 can be represented) or the old divergent syntax for each mode. */
3358 static void
3359 s_syntax (int unused ATTRIBUTE_UNUSED)
3360 {
3361 char *name, delim;
3362
3363 delim = get_symbol_name (& name);
3364
3365 if (!strcasecmp (name, "unified"))
3366 unified_syntax = TRUE;
3367 else if (!strcasecmp (name, "divided"))
3368 unified_syntax = FALSE;
3369 else
3370 {
3371 as_bad (_("unrecognized syntax mode \"%s\""), name);
3372 return;
3373 }
3374 (void) restore_line_pointer (delim);
3375 demand_empty_rest_of_line ();
3376 }
3377
3378 /* Directives: sectioning and alignment. */
3379
3380 static void
3381 s_bss (int ignore ATTRIBUTE_UNUSED)
3382 {
3383 /* We don't support putting frags in the BSS segment, we fake it by
3384 marking in_bss, then looking at s_skip for clues. */
3385 subseg_set (bss_section, 0);
3386 demand_empty_rest_of_line ();
3387
3388 #ifdef md_elf_section_change_hook
3389 md_elf_section_change_hook ();
3390 #endif
3391 }
3392
3393 static void
3394 s_even (int ignore ATTRIBUTE_UNUSED)
3395 {
3396 /* Never make frag if expect extra pass. */
3397 if (!need_pass_2)
3398 frag_align (1, 0, 0);
3399
3400 record_alignment (now_seg, 1);
3401
3402 demand_empty_rest_of_line ();
3403 }
3404
3405 /* Directives: CodeComposer Studio. */
3406
3407 /* .ref (for CodeComposer Studio syntax only). */
3408 static void
3409 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3410 {
3411 if (codecomposer_syntax)
3412 ignore_rest_of_line ();
3413 else
3414 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3415 }
3416
3417 /* If name is not NULL, then it is used for marking the beginning of a
3418 function, whereas if it is NULL then it means the function end. */
3419 static void
3420 asmfunc_debug (const char * name)
3421 {
3422 static const char * last_name = NULL;
3423
3424 if (name != NULL)
3425 {
3426 gas_assert (last_name == NULL);
3427 last_name = name;
3428
3429 if (debug_type == DEBUG_STABS)
3430 stabs_generate_asm_func (name, name);
3431 }
3432 else
3433 {
3434 gas_assert (last_name != NULL);
3435
3436 if (debug_type == DEBUG_STABS)
3437 stabs_generate_asm_endfunc (last_name, last_name);
3438
3439 last_name = NULL;
3440 }
3441 }
3442
3443 static void
3444 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3445 {
3446 if (codecomposer_syntax)
3447 {
3448 switch (asmfunc_state)
3449 {
3450 case OUTSIDE_ASMFUNC:
3451 asmfunc_state = WAITING_ASMFUNC_NAME;
3452 break;
3453
3454 case WAITING_ASMFUNC_NAME:
3455 as_bad (_(".asmfunc repeated."));
3456 break;
3457
3458 case WAITING_ENDASMFUNC:
3459 as_bad (_(".asmfunc without function."));
3460 break;
3461 }
3462 demand_empty_rest_of_line ();
3463 }
3464 else
3465 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3466 }
3467
3468 static void
3469 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3470 {
3471 if (codecomposer_syntax)
3472 {
3473 switch (asmfunc_state)
3474 {
3475 case OUTSIDE_ASMFUNC:
3476 as_bad (_(".endasmfunc without a .asmfunc."));
3477 break;
3478
3479 case WAITING_ASMFUNC_NAME:
3480 as_bad (_(".endasmfunc without function."));
3481 break;
3482
3483 case WAITING_ENDASMFUNC:
3484 asmfunc_state = OUTSIDE_ASMFUNC;
3485 asmfunc_debug (NULL);
3486 break;
3487 }
3488 demand_empty_rest_of_line ();
3489 }
3490 else
3491 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3492 }
3493
3494 static void
3495 s_ccs_def (int name)
3496 {
3497 if (codecomposer_syntax)
3498 s_globl (name);
3499 else
3500 as_bad (_(".def pseudo-op only available with -mccs flag."));
3501 }
3502
3503 /* Directives: Literal pools. */
3504
3505 static literal_pool *
3506 find_literal_pool (void)
3507 {
3508 literal_pool * pool;
3509
3510 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3511 {
3512 if (pool->section == now_seg
3513 && pool->sub_section == now_subseg)
3514 break;
3515 }
3516
3517 return pool;
3518 }
3519
3520 static literal_pool *
3521 find_or_make_literal_pool (void)
3522 {
3523 /* Next literal pool ID number. */
3524 static unsigned int latest_pool_num = 1;
3525 literal_pool * pool;
3526
3527 pool = find_literal_pool ();
3528
3529 if (pool == NULL)
3530 {
3531 /* Create a new pool. */
3532 pool = XNEW (literal_pool);
3533 if (! pool)
3534 return NULL;
3535
3536 pool->next_free_entry = 0;
3537 pool->section = now_seg;
3538 pool->sub_section = now_subseg;
3539 pool->next = list_of_pools;
3540 pool->symbol = NULL;
3541 pool->alignment = 2;
3542
3543 /* Add it to the list. */
3544 list_of_pools = pool;
3545 }
3546
3547 /* New pools, and emptied pools, will have a NULL symbol. */
3548 if (pool->symbol == NULL)
3549 {
3550 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3551 (valueT) 0, &zero_address_frag);
3552 pool->id = latest_pool_num ++;
3553 }
3554
3555 /* Done. */
3556 return pool;
3557 }
3558
3559 /* Add the literal in the global 'inst'
3560 structure to the relevant literal pool. */
3561
3562 static int
3563 add_to_lit_pool (unsigned int nbytes)
3564 {
3565 #define PADDING_SLOT 0x1
3566 #define LIT_ENTRY_SIZE_MASK 0xFF
3567 literal_pool * pool;
3568 unsigned int entry, pool_size = 0;
3569 bfd_boolean padding_slot_p = FALSE;
3570 unsigned imm1 = 0;
3571 unsigned imm2 = 0;
3572
3573 if (nbytes == 8)
3574 {
3575 imm1 = inst.operands[1].imm;
3576 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3577 : inst.relocs[0].exp.X_unsigned ? 0
3578 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3579 if (target_big_endian)
3580 {
3581 imm1 = imm2;
3582 imm2 = inst.operands[1].imm;
3583 }
3584 }
3585
3586 pool = find_or_make_literal_pool ();
3587
3588 /* Check if this literal value is already in the pool. */
3589 for (entry = 0; entry < pool->next_free_entry; entry ++)
3590 {
3591 if (nbytes == 4)
3592 {
3593 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3594 && (inst.relocs[0].exp.X_op == O_constant)
3595 && (pool->literals[entry].X_add_number
3596 == inst.relocs[0].exp.X_add_number)
3597 && (pool->literals[entry].X_md == nbytes)
3598 && (pool->literals[entry].X_unsigned
3599 == inst.relocs[0].exp.X_unsigned))
3600 break;
3601
3602 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3603 && (inst.relocs[0].exp.X_op == O_symbol)
3604 && (pool->literals[entry].X_add_number
3605 == inst.relocs[0].exp.X_add_number)
3606 && (pool->literals[entry].X_add_symbol
3607 == inst.relocs[0].exp.X_add_symbol)
3608 && (pool->literals[entry].X_op_symbol
3609 == inst.relocs[0].exp.X_op_symbol)
3610 && (pool->literals[entry].X_md == nbytes))
3611 break;
3612 }
3613 else if ((nbytes == 8)
3614 && !(pool_size & 0x7)
3615 && ((entry + 1) != pool->next_free_entry)
3616 && (pool->literals[entry].X_op == O_constant)
3617 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3618 && (pool->literals[entry].X_unsigned
3619 == inst.relocs[0].exp.X_unsigned)
3620 && (pool->literals[entry + 1].X_op == O_constant)
3621 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3622 && (pool->literals[entry + 1].X_unsigned
3623 == inst.relocs[0].exp.X_unsigned))
3624 break;
3625
3626 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3627 if (padding_slot_p && (nbytes == 4))
3628 break;
3629
3630 pool_size += 4;
3631 }
3632
3633 /* Do we need to create a new entry? */
3634 if (entry == pool->next_free_entry)
3635 {
3636 if (entry >= MAX_LITERAL_POOL_SIZE)
3637 {
3638 inst.error = _("literal pool overflow");
3639 return FAIL;
3640 }
3641
3642 if (nbytes == 8)
3643 {
3644 /* For 8-byte entries, we align to an 8-byte boundary,
3645 and split it into two 4-byte entries, because on 32-bit
3646 host, 8-byte constants are treated as big num, thus
3647 saved in "generic_bignum" which will be overwritten
3648 by later assignments.
3649
3650 We also need to make sure there is enough space for
3651 the split.
3652
3653 We also check to make sure the literal operand is a
3654 constant number. */
3655 if (!(inst.relocs[0].exp.X_op == O_constant
3656 || inst.relocs[0].exp.X_op == O_big))
3657 {
3658 inst.error = _("invalid type for literal pool");
3659 return FAIL;
3660 }
3661 else if (pool_size & 0x7)
3662 {
3663 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3664 {
3665 inst.error = _("literal pool overflow");
3666 return FAIL;
3667 }
3668
3669 pool->literals[entry] = inst.relocs[0].exp;
3670 pool->literals[entry].X_op = O_constant;
3671 pool->literals[entry].X_add_number = 0;
3672 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3673 pool->next_free_entry += 1;
3674 pool_size += 4;
3675 }
3676 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3677 {
3678 inst.error = _("literal pool overflow");
3679 return FAIL;
3680 }
3681
3682 pool->literals[entry] = inst.relocs[0].exp;
3683 pool->literals[entry].X_op = O_constant;
3684 pool->literals[entry].X_add_number = imm1;
3685 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3686 pool->literals[entry++].X_md = 4;
3687 pool->literals[entry] = inst.relocs[0].exp;
3688 pool->literals[entry].X_op = O_constant;
3689 pool->literals[entry].X_add_number = imm2;
3690 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3691 pool->literals[entry].X_md = 4;
3692 pool->alignment = 3;
3693 pool->next_free_entry += 1;
3694 }
3695 else
3696 {
3697 pool->literals[entry] = inst.relocs[0].exp;
3698 pool->literals[entry].X_md = 4;
3699 }
3700
3701 #ifdef OBJ_ELF
3702 /* PR ld/12974: Record the location of the first source line to reference
3703 this entry in the literal pool. If it turns out during linking that the
3704 symbol does not exist we will be able to give an accurate line number for
3705 the (first use of the) missing reference. */
3706 if (debug_type == DEBUG_DWARF2)
3707 dwarf2_where (pool->locs + entry);
3708 #endif
3709 pool->next_free_entry += 1;
3710 }
3711 else if (padding_slot_p)
3712 {
3713 pool->literals[entry] = inst.relocs[0].exp;
3714 pool->literals[entry].X_md = nbytes;
3715 }
3716
3717 inst.relocs[0].exp.X_op = O_symbol;
3718 inst.relocs[0].exp.X_add_number = pool_size;
3719 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3720
3721 return SUCCESS;
3722 }
3723
3724 bfd_boolean
3725 tc_start_label_without_colon (void)
3726 {
3727 bfd_boolean ret = TRUE;
3728
3729 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3730 {
3731 const char *label = input_line_pointer;
3732
3733 while (!is_end_of_line[(int) label[-1]])
3734 --label;
3735
3736 if (*label == '.')
3737 {
3738 as_bad (_("Invalid label '%s'"), label);
3739 ret = FALSE;
3740 }
3741
3742 asmfunc_debug (label);
3743
3744 asmfunc_state = WAITING_ENDASMFUNC;
3745 }
3746
3747 return ret;
3748 }
3749
3750 /* Can't use symbol_new here, so have to create a symbol and then at
3751 a later date assign it a value. That's what these functions do. */
3752
3753 static void
3754 symbol_locate (symbolS * symbolP,
3755 const char * name, /* It is copied, the caller can modify. */
3756 segT segment, /* Segment identifier (SEG_<something>). */
3757 valueT valu, /* Symbol value. */
3758 fragS * frag) /* Associated fragment. */
3759 {
3760 size_t name_length;
3761 char * preserved_copy_of_name;
3762
3763 name_length = strlen (name) + 1; /* +1 for \0. */
3764 obstack_grow (&notes, name, name_length);
3765 preserved_copy_of_name = (char *) obstack_finish (&notes);
3766
3767 #ifdef tc_canonicalize_symbol_name
3768 preserved_copy_of_name =
3769 tc_canonicalize_symbol_name (preserved_copy_of_name);
3770 #endif
3771
3772 S_SET_NAME (symbolP, preserved_copy_of_name);
3773
3774 S_SET_SEGMENT (symbolP, segment);
3775 S_SET_VALUE (symbolP, valu);
3776 symbol_clear_list_pointers (symbolP);
3777
3778 symbol_set_frag (symbolP, frag);
3779
3780 /* Link to end of symbol chain. */
3781 {
3782 extern int symbol_table_frozen;
3783
3784 if (symbol_table_frozen)
3785 abort ();
3786 }
3787
3788 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3789
3790 obj_symbol_new_hook (symbolP);
3791
3792 #ifdef tc_symbol_new_hook
3793 tc_symbol_new_hook (symbolP);
3794 #endif
3795
3796 #ifdef DEBUG_SYMS
3797 verify_symbol_chain (symbol_rootP, symbol_lastP);
3798 #endif /* DEBUG_SYMS */
3799 }
3800
3801 static void
3802 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3803 {
3804 unsigned int entry;
3805 literal_pool * pool;
3806 char sym_name[20];
3807
3808 pool = find_literal_pool ();
3809 if (pool == NULL
3810 || pool->symbol == NULL
3811 || pool->next_free_entry == 0)
3812 return;
3813
3814 /* Align pool as you have word accesses.
3815 Only make a frag if we have to. */
3816 if (!need_pass_2)
3817 frag_align (pool->alignment, 0, 0);
3818
3819 record_alignment (now_seg, 2);
3820
3821 #ifdef OBJ_ELF
3822 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3823 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3824 #endif
3825 sprintf (sym_name, "$$lit_\002%x", pool->id);
3826
3827 symbol_locate (pool->symbol, sym_name, now_seg,
3828 (valueT) frag_now_fix (), frag_now);
3829 symbol_table_insert (pool->symbol);
3830
3831 ARM_SET_THUMB (pool->symbol, thumb_mode);
3832
3833 #if defined OBJ_COFF || defined OBJ_ELF
3834 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3835 #endif
3836
3837 for (entry = 0; entry < pool->next_free_entry; entry ++)
3838 {
3839 #ifdef OBJ_ELF
3840 if (debug_type == DEBUG_DWARF2)
3841 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3842 #endif
3843 /* First output the expression in the instruction to the pool. */
3844 emit_expr (&(pool->literals[entry]),
3845 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3846 }
3847
3848 /* Mark the pool as empty. */
3849 pool->next_free_entry = 0;
3850 pool->symbol = NULL;
3851 }
3852
3853 #ifdef OBJ_ELF
3854 /* Forward declarations for functions below, in the MD interface
3855 section. */
3856 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3857 static valueT create_unwind_entry (int);
3858 static void start_unwind_section (const segT, int);
3859 static void add_unwind_opcode (valueT, int);
3860 static void flush_pending_unwind (void);
3861
3862 /* Directives: Data. */
3863
3864 static void
3865 s_arm_elf_cons (int nbytes)
3866 {
3867 expressionS exp;
3868
3869 #ifdef md_flush_pending_output
3870 md_flush_pending_output ();
3871 #endif
3872
3873 if (is_it_end_of_statement ())
3874 {
3875 demand_empty_rest_of_line ();
3876 return;
3877 }
3878
3879 #ifdef md_cons_align
3880 md_cons_align (nbytes);
3881 #endif
3882
3883 mapping_state (MAP_DATA);
3884 do
3885 {
3886 int reloc;
3887 char *base = input_line_pointer;
3888
3889 expression (& exp);
3890
3891 if (exp.X_op != O_symbol)
3892 emit_expr (&exp, (unsigned int) nbytes);
3893 else
3894 {
3895 char *before_reloc = input_line_pointer;
3896 reloc = parse_reloc (&input_line_pointer);
3897 if (reloc == -1)
3898 {
3899 as_bad (_("unrecognized relocation suffix"));
3900 ignore_rest_of_line ();
3901 return;
3902 }
3903 else if (reloc == BFD_RELOC_UNUSED)
3904 emit_expr (&exp, (unsigned int) nbytes);
3905 else
3906 {
3907 reloc_howto_type *howto = (reloc_howto_type *)
3908 bfd_reloc_type_lookup (stdoutput,
3909 (bfd_reloc_code_real_type) reloc);
3910 int size = bfd_get_reloc_size (howto);
3911
3912 if (reloc == BFD_RELOC_ARM_PLT32)
3913 {
3914 as_bad (_("(plt) is only valid on branch targets"));
3915 reloc = BFD_RELOC_UNUSED;
3916 size = 0;
3917 }
3918
3919 if (size > nbytes)
3920 as_bad (ngettext ("%s relocations do not fit in %d byte",
3921 "%s relocations do not fit in %d bytes",
3922 nbytes),
3923 howto->name, nbytes);
3924 else
3925 {
3926 /* We've parsed an expression stopping at O_symbol.
3927 But there may be more expression left now that we
3928 have parsed the relocation marker. Parse it again.
3929 XXX Surely there is a cleaner way to do this. */
3930 char *p = input_line_pointer;
3931 int offset;
3932 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3933
3934 memcpy (save_buf, base, input_line_pointer - base);
3935 memmove (base + (input_line_pointer - before_reloc),
3936 base, before_reloc - base);
3937
3938 input_line_pointer = base + (input_line_pointer-before_reloc);
3939 expression (&exp);
3940 memcpy (base, save_buf, p - base);
3941
3942 offset = nbytes - size;
3943 p = frag_more (nbytes);
3944 memset (p, 0, nbytes);
3945 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3946 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3947 free (save_buf);
3948 }
3949 }
3950 }
3951 }
3952 while (*input_line_pointer++ == ',');
3953
3954 /* Put terminator back into stream. */
3955 input_line_pointer --;
3956 demand_empty_rest_of_line ();
3957 }
3958
3959 /* Emit an expression containing a 32-bit thumb instruction.
3960 Implementation based on put_thumb32_insn. */
3961
3962 static void
3963 emit_thumb32_expr (expressionS * exp)
3964 {
3965 expressionS exp_high = *exp;
3966
3967 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3968 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3969 exp->X_add_number &= 0xffff;
3970 emit_expr (exp, (unsigned int) THUMB_SIZE);
3971 }
3972
3973 /* Guess the instruction size based on the opcode. */
3974
3975 static int
3976 thumb_insn_size (int opcode)
3977 {
3978 if ((unsigned int) opcode < 0xe800u)
3979 return 2;
3980 else if ((unsigned int) opcode >= 0xe8000000u)
3981 return 4;
3982 else
3983 return 0;
3984 }
3985
3986 static bfd_boolean
3987 emit_insn (expressionS *exp, int nbytes)
3988 {
3989 int size = 0;
3990
3991 if (exp->X_op == O_constant)
3992 {
3993 size = nbytes;
3994
3995 if (size == 0)
3996 size = thumb_insn_size (exp->X_add_number);
3997
3998 if (size != 0)
3999 {
4000 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
4001 {
4002 as_bad (_(".inst.n operand too big. "\
4003 "Use .inst.w instead"));
4004 size = 0;
4005 }
4006 else
4007 {
4008 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
4009 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
4010 else
4011 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
4012
4013 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
4014 emit_thumb32_expr (exp);
4015 else
4016 emit_expr (exp, (unsigned int) size);
4017
4018 it_fsm_post_encode ();
4019 }
4020 }
4021 else
4022 as_bad (_("cannot determine Thumb instruction size. " \
4023 "Use .inst.n/.inst.w instead"));
4024 }
4025 else
4026 as_bad (_("constant expression required"));
4027
4028 return (size != 0);
4029 }
4030
4031 /* Like s_arm_elf_cons but do not use md_cons_align and
4032 set the mapping state to MAP_ARM/MAP_THUMB. */
4033
4034 static void
4035 s_arm_elf_inst (int nbytes)
4036 {
4037 if (is_it_end_of_statement ())
4038 {
4039 demand_empty_rest_of_line ();
4040 return;
4041 }
4042
4043 /* Calling mapping_state () here will not change ARM/THUMB,
4044 but will ensure not to be in DATA state. */
4045
4046 if (thumb_mode)
4047 mapping_state (MAP_THUMB);
4048 else
4049 {
4050 if (nbytes != 0)
4051 {
4052 as_bad (_("width suffixes are invalid in ARM mode"));
4053 ignore_rest_of_line ();
4054 return;
4055 }
4056
4057 nbytes = 4;
4058
4059 mapping_state (MAP_ARM);
4060 }
4061
4062 do
4063 {
4064 expressionS exp;
4065
4066 expression (& exp);
4067
4068 if (! emit_insn (& exp, nbytes))
4069 {
4070 ignore_rest_of_line ();
4071 return;
4072 }
4073 }
4074 while (*input_line_pointer++ == ',');
4075
4076 /* Put terminator back into stream. */
4077 input_line_pointer --;
4078 demand_empty_rest_of_line ();
4079 }
4080
4081 /* Parse a .rel31 directive. */
4082
4083 static void
4084 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4085 {
4086 expressionS exp;
4087 char *p;
4088 valueT highbit;
4089
4090 highbit = 0;
4091 if (*input_line_pointer == '1')
4092 highbit = 0x80000000;
4093 else if (*input_line_pointer != '0')
4094 as_bad (_("expected 0 or 1"));
4095
4096 input_line_pointer++;
4097 if (*input_line_pointer != ',')
4098 as_bad (_("missing comma"));
4099 input_line_pointer++;
4100
4101 #ifdef md_flush_pending_output
4102 md_flush_pending_output ();
4103 #endif
4104
4105 #ifdef md_cons_align
4106 md_cons_align (4);
4107 #endif
4108
4109 mapping_state (MAP_DATA);
4110
4111 expression (&exp);
4112
4113 p = frag_more (4);
4114 md_number_to_chars (p, highbit, 4);
4115 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4116 BFD_RELOC_ARM_PREL31);
4117
4118 demand_empty_rest_of_line ();
4119 }
4120
4121 /* Directives: AEABI stack-unwind tables. */
4122
4123 /* Parse an unwind_fnstart directive. Simply records the current location. */
4124
4125 static void
4126 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4127 {
4128 demand_empty_rest_of_line ();
4129 if (unwind.proc_start)
4130 {
4131 as_bad (_("duplicate .fnstart directive"));
4132 return;
4133 }
4134
4135 /* Mark the start of the function. */
4136 unwind.proc_start = expr_build_dot ();
4137
4138 /* Reset the rest of the unwind info. */
4139 unwind.opcode_count = 0;
4140 unwind.table_entry = NULL;
4141 unwind.personality_routine = NULL;
4142 unwind.personality_index = -1;
4143 unwind.frame_size = 0;
4144 unwind.fp_offset = 0;
4145 unwind.fp_reg = REG_SP;
4146 unwind.fp_used = 0;
4147 unwind.sp_restored = 0;
4148 }
4149
4150
4151 /* Parse a handlerdata directive. Creates the exception handling table entry
4152 for the function. */
4153
4154 static void
4155 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4156 {
4157 demand_empty_rest_of_line ();
4158 if (!unwind.proc_start)
4159 as_bad (MISSING_FNSTART);
4160
4161 if (unwind.table_entry)
4162 as_bad (_("duplicate .handlerdata directive"));
4163
4164 create_unwind_entry (1);
4165 }
4166
4167 /* Parse an unwind_fnend directive. Generates the index table entry. */
4168
4169 static void
4170 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4171 {
4172 long where;
4173 char *ptr;
4174 valueT val;
4175 unsigned int marked_pr_dependency;
4176
4177 demand_empty_rest_of_line ();
4178
4179 if (!unwind.proc_start)
4180 {
4181 as_bad (_(".fnend directive without .fnstart"));
4182 return;
4183 }
4184
4185 /* Add eh table entry. */
4186 if (unwind.table_entry == NULL)
4187 val = create_unwind_entry (0);
4188 else
4189 val = 0;
4190
4191 /* Add index table entry. This is two words. */
4192 start_unwind_section (unwind.saved_seg, 1);
4193 frag_align (2, 0, 0);
4194 record_alignment (now_seg, 2);
4195
4196 ptr = frag_more (8);
4197 memset (ptr, 0, 8);
4198 where = frag_now_fix () - 8;
4199
4200 /* Self relative offset of the function start. */
4201 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4202 BFD_RELOC_ARM_PREL31);
4203
4204 /* Indicate dependency on EHABI-defined personality routines to the
4205 linker, if it hasn't been done already. */
4206 marked_pr_dependency
4207 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
4208 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4209 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4210 {
4211 static const char *const name[] =
4212 {
4213 "__aeabi_unwind_cpp_pr0",
4214 "__aeabi_unwind_cpp_pr1",
4215 "__aeabi_unwind_cpp_pr2"
4216 };
4217 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4218 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
4219 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
4220 |= 1 << unwind.personality_index;
4221 }
4222
4223 if (val)
4224 /* Inline exception table entry. */
4225 md_number_to_chars (ptr + 4, val, 4);
4226 else
4227 /* Self relative offset of the table entry. */
4228 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4229 BFD_RELOC_ARM_PREL31);
4230
4231 /* Restore the original section. */
4232 subseg_set (unwind.saved_seg, unwind.saved_subseg);
4233
4234 unwind.proc_start = NULL;
4235 }
4236
4237
4238 /* Parse an unwind_cantunwind directive. */
4239
4240 static void
4241 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4242 {
4243 demand_empty_rest_of_line ();
4244 if (!unwind.proc_start)
4245 as_bad (MISSING_FNSTART);
4246
4247 if (unwind.personality_routine || unwind.personality_index != -1)
4248 as_bad (_("personality routine specified for cantunwind frame"));
4249
4250 unwind.personality_index = -2;
4251 }
4252
4253
4254 /* Parse a personalityindex directive. */
4255
4256 static void
4257 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4258 {
4259 expressionS exp;
4260
4261 if (!unwind.proc_start)
4262 as_bad (MISSING_FNSTART);
4263
4264 if (unwind.personality_routine || unwind.personality_index != -1)
4265 as_bad (_("duplicate .personalityindex directive"));
4266
4267 expression (&exp);
4268
4269 if (exp.X_op != O_constant
4270 || exp.X_add_number < 0 || exp.X_add_number > 15)
4271 {
4272 as_bad (_("bad personality routine number"));
4273 ignore_rest_of_line ();
4274 return;
4275 }
4276
4277 unwind.personality_index = exp.X_add_number;
4278
4279 demand_empty_rest_of_line ();
4280 }
4281
4282
4283 /* Parse a personality directive. */
4284
4285 static void
4286 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4287 {
4288 char *name, *p, c;
4289
4290 if (!unwind.proc_start)
4291 as_bad (MISSING_FNSTART);
4292
4293 if (unwind.personality_routine || unwind.personality_index != -1)
4294 as_bad (_("duplicate .personality directive"));
4295
4296 c = get_symbol_name (& name);
4297 p = input_line_pointer;
4298 if (c == '"')
4299 ++ input_line_pointer;
4300 unwind.personality_routine = symbol_find_or_make (name);
4301 *p = c;
4302 demand_empty_rest_of_line ();
4303 }
4304
4305
4306 /* Parse a directive saving core registers. */
4307
4308 static void
4309 s_arm_unwind_save_core (void)
4310 {
4311 valueT op;
4312 long range;
4313 int n;
4314
4315 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
4316 if (range == FAIL)
4317 {
4318 as_bad (_("expected register list"));
4319 ignore_rest_of_line ();
4320 return;
4321 }
4322
4323 demand_empty_rest_of_line ();
4324
4325 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4326 into .unwind_save {..., sp...}. We aren't bothered about the value of
4327 ip because it is clobbered by calls. */
4328 if (unwind.sp_restored && unwind.fp_reg == 12
4329 && (range & 0x3000) == 0x1000)
4330 {
4331 unwind.opcode_count--;
4332 unwind.sp_restored = 0;
4333 range = (range | 0x2000) & ~0x1000;
4334 unwind.pending_offset = 0;
4335 }
4336
4337 /* Pop r4-r15. */
4338 if (range & 0xfff0)
4339 {
4340 /* See if we can use the short opcodes. These pop a block of up to 8
4341 registers starting with r4, plus maybe r14. */
4342 for (n = 0; n < 8; n++)
4343 {
4344 /* Break at the first non-saved register. */
4345 if ((range & (1 << (n + 4))) == 0)
4346 break;
4347 }
4348 /* See if there are any other bits set. */
4349 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4350 {
4351 /* Use the long form. */
4352 op = 0x8000 | ((range >> 4) & 0xfff);
4353 add_unwind_opcode (op, 2);
4354 }
4355 else
4356 {
4357 /* Use the short form. */
4358 if (range & 0x4000)
4359 op = 0xa8; /* Pop r14. */
4360 else
4361 op = 0xa0; /* Do not pop r14. */
4362 op |= (n - 1);
4363 add_unwind_opcode (op, 1);
4364 }
4365 }
4366
4367 /* Pop r0-r3. */
4368 if (range & 0xf)
4369 {
4370 op = 0xb100 | (range & 0xf);
4371 add_unwind_opcode (op, 2);
4372 }
4373
4374 /* Record the number of bytes pushed. */
4375 for (n = 0; n < 16; n++)
4376 {
4377 if (range & (1 << n))
4378 unwind.frame_size += 4;
4379 }
4380 }
4381
4382
4383 /* Parse a directive saving FPA registers. */
4384
4385 static void
4386 s_arm_unwind_save_fpa (int reg)
4387 {
4388 expressionS exp;
4389 int num_regs;
4390 valueT op;
4391
4392 /* Get Number of registers to transfer. */
4393 if (skip_past_comma (&input_line_pointer) != FAIL)
4394 expression (&exp);
4395 else
4396 exp.X_op = O_illegal;
4397
4398 if (exp.X_op != O_constant)
4399 {
4400 as_bad (_("expected , <constant>"));
4401 ignore_rest_of_line ();
4402 return;
4403 }
4404
4405 num_regs = exp.X_add_number;
4406
4407 if (num_regs < 1 || num_regs > 4)
4408 {
4409 as_bad (_("number of registers must be in the range [1:4]"));
4410 ignore_rest_of_line ();
4411 return;
4412 }
4413
4414 demand_empty_rest_of_line ();
4415
4416 if (reg == 4)
4417 {
4418 /* Short form. */
4419 op = 0xb4 | (num_regs - 1);
4420 add_unwind_opcode (op, 1);
4421 }
4422 else
4423 {
4424 /* Long form. */
4425 op = 0xc800 | (reg << 4) | (num_regs - 1);
4426 add_unwind_opcode (op, 2);
4427 }
4428 unwind.frame_size += num_regs * 12;
4429 }
4430
4431
4432 /* Parse a directive saving VFP registers for ARMv6 and above. */
4433
4434 static void
4435 s_arm_unwind_save_vfp_armv6 (void)
4436 {
4437 int count;
4438 unsigned int start;
4439 valueT op;
4440 int num_vfpv3_regs = 0;
4441 int num_regs_below_16;
4442 bfd_boolean partial_match;
4443
4444 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4445 &partial_match);
4446 if (count == FAIL)
4447 {
4448 as_bad (_("expected register list"));
4449 ignore_rest_of_line ();
4450 return;
4451 }
4452
4453 demand_empty_rest_of_line ();
4454
4455 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4456 than FSTMX/FLDMX-style ones). */
4457
4458 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4459 if (start >= 16)
4460 num_vfpv3_regs = count;
4461 else if (start + count > 16)
4462 num_vfpv3_regs = start + count - 16;
4463
4464 if (num_vfpv3_regs > 0)
4465 {
4466 int start_offset = start > 16 ? start - 16 : 0;
4467 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4468 add_unwind_opcode (op, 2);
4469 }
4470
4471 /* Generate opcode for registers numbered in the range 0 .. 15. */
4472 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4473 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4474 if (num_regs_below_16 > 0)
4475 {
4476 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4477 add_unwind_opcode (op, 2);
4478 }
4479
4480 unwind.frame_size += count * 8;
4481 }
4482
4483
4484 /* Parse a directive saving VFP registers for pre-ARMv6. */
4485
4486 static void
4487 s_arm_unwind_save_vfp (void)
4488 {
4489 int count;
4490 unsigned int reg;
4491 valueT op;
4492 bfd_boolean partial_match;
4493
4494 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4495 &partial_match);
4496 if (count == FAIL)
4497 {
4498 as_bad (_("expected register list"));
4499 ignore_rest_of_line ();
4500 return;
4501 }
4502
4503 demand_empty_rest_of_line ();
4504
4505 if (reg == 8)
4506 {
4507 /* Short form. */
4508 op = 0xb8 | (count - 1);
4509 add_unwind_opcode (op, 1);
4510 }
4511 else
4512 {
4513 /* Long form. */
4514 op = 0xb300 | (reg << 4) | (count - 1);
4515 add_unwind_opcode (op, 2);
4516 }
4517 unwind.frame_size += count * 8 + 4;
4518 }
4519
4520
4521 /* Parse a directive saving iWMMXt data registers. */
4522
4523 static void
4524 s_arm_unwind_save_mmxwr (void)
4525 {
4526 int reg;
4527 int hi_reg;
4528 int i;
4529 unsigned mask = 0;
4530 valueT op;
4531
4532 if (*input_line_pointer == '{')
4533 input_line_pointer++;
4534
4535 do
4536 {
4537 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4538
4539 if (reg == FAIL)
4540 {
4541 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4542 goto error;
4543 }
4544
4545 if (mask >> reg)
4546 as_tsktsk (_("register list not in ascending order"));
4547 mask |= 1 << reg;
4548
4549 if (*input_line_pointer == '-')
4550 {
4551 input_line_pointer++;
4552 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4553 if (hi_reg == FAIL)
4554 {
4555 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4556 goto error;
4557 }
4558 else if (reg >= hi_reg)
4559 {
4560 as_bad (_("bad register range"));
4561 goto error;
4562 }
4563 for (; reg < hi_reg; reg++)
4564 mask |= 1 << reg;
4565 }
4566 }
4567 while (skip_past_comma (&input_line_pointer) != FAIL);
4568
4569 skip_past_char (&input_line_pointer, '}');
4570
4571 demand_empty_rest_of_line ();
4572
4573 /* Generate any deferred opcodes because we're going to be looking at
4574 the list. */
4575 flush_pending_unwind ();
4576
4577 for (i = 0; i < 16; i++)
4578 {
4579 if (mask & (1 << i))
4580 unwind.frame_size += 8;
4581 }
4582
4583 /* Attempt to combine with a previous opcode. We do this because gcc
4584 likes to output separate unwind directives for a single block of
4585 registers. */
4586 if (unwind.opcode_count > 0)
4587 {
4588 i = unwind.opcodes[unwind.opcode_count - 1];
4589 if ((i & 0xf8) == 0xc0)
4590 {
4591 i &= 7;
4592 /* Only merge if the blocks are contiguous. */
4593 if (i < 6)
4594 {
4595 if ((mask & 0xfe00) == (1 << 9))
4596 {
4597 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4598 unwind.opcode_count--;
4599 }
4600 }
4601 else if (i == 6 && unwind.opcode_count >= 2)
4602 {
4603 i = unwind.opcodes[unwind.opcode_count - 2];
4604 reg = i >> 4;
4605 i &= 0xf;
4606
4607 op = 0xffff << (reg - 1);
4608 if (reg > 0
4609 && ((mask & op) == (1u << (reg - 1))))
4610 {
4611 op = (1 << (reg + i + 1)) - 1;
4612 op &= ~((1 << reg) - 1);
4613 mask |= op;
4614 unwind.opcode_count -= 2;
4615 }
4616 }
4617 }
4618 }
4619
4620 hi_reg = 15;
4621 /* We want to generate opcodes in the order the registers have been
4622 saved, ie. descending order. */
4623 for (reg = 15; reg >= -1; reg--)
4624 {
4625 /* Save registers in blocks. */
4626 if (reg < 0
4627 || !(mask & (1 << reg)))
4628 {
4629 /* We found an unsaved reg. Generate opcodes to save the
4630 preceding block. */
4631 if (reg != hi_reg)
4632 {
4633 if (reg == 9)
4634 {
4635 /* Short form. */
4636 op = 0xc0 | (hi_reg - 10);
4637 add_unwind_opcode (op, 1);
4638 }
4639 else
4640 {
4641 /* Long form. */
4642 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4643 add_unwind_opcode (op, 2);
4644 }
4645 }
4646 hi_reg = reg - 1;
4647 }
4648 }
4649
4650 return;
4651 error:
4652 ignore_rest_of_line ();
4653 }
4654
4655 static void
4656 s_arm_unwind_save_mmxwcg (void)
4657 {
4658 int reg;
4659 int hi_reg;
4660 unsigned mask = 0;
4661 valueT op;
4662
4663 if (*input_line_pointer == '{')
4664 input_line_pointer++;
4665
4666 skip_whitespace (input_line_pointer);
4667
4668 do
4669 {
4670 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4671
4672 if (reg == FAIL)
4673 {
4674 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4675 goto error;
4676 }
4677
4678 reg -= 8;
4679 if (mask >> reg)
4680 as_tsktsk (_("register list not in ascending order"));
4681 mask |= 1 << reg;
4682
4683 if (*input_line_pointer == '-')
4684 {
4685 input_line_pointer++;
4686 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4687 if (hi_reg == FAIL)
4688 {
4689 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4690 goto error;
4691 }
4692 else if (reg >= hi_reg)
4693 {
4694 as_bad (_("bad register range"));
4695 goto error;
4696 }
4697 for (; reg < hi_reg; reg++)
4698 mask |= 1 << reg;
4699 }
4700 }
4701 while (skip_past_comma (&input_line_pointer) != FAIL);
4702
4703 skip_past_char (&input_line_pointer, '}');
4704
4705 demand_empty_rest_of_line ();
4706
4707 /* Generate any deferred opcodes because we're going to be looking at
4708 the list. */
4709 flush_pending_unwind ();
4710
4711 for (reg = 0; reg < 16; reg++)
4712 {
4713 if (mask & (1 << reg))
4714 unwind.frame_size += 4;
4715 }
4716 op = 0xc700 | mask;
4717 add_unwind_opcode (op, 2);
4718 return;
4719 error:
4720 ignore_rest_of_line ();
4721 }
4722
4723
4724 /* Parse an unwind_save directive.
4725 If the argument is non-zero, this is a .vsave directive. */
4726
4727 static void
4728 s_arm_unwind_save (int arch_v6)
4729 {
4730 char *peek;
4731 struct reg_entry *reg;
4732 bfd_boolean had_brace = FALSE;
4733
4734 if (!unwind.proc_start)
4735 as_bad (MISSING_FNSTART);
4736
4737 /* Figure out what sort of save we have. */
4738 peek = input_line_pointer;
4739
4740 if (*peek == '{')
4741 {
4742 had_brace = TRUE;
4743 peek++;
4744 }
4745
4746 reg = arm_reg_parse_multi (&peek);
4747
4748 if (!reg)
4749 {
4750 as_bad (_("register expected"));
4751 ignore_rest_of_line ();
4752 return;
4753 }
4754
4755 switch (reg->type)
4756 {
4757 case REG_TYPE_FN:
4758 if (had_brace)
4759 {
4760 as_bad (_("FPA .unwind_save does not take a register list"));
4761 ignore_rest_of_line ();
4762 return;
4763 }
4764 input_line_pointer = peek;
4765 s_arm_unwind_save_fpa (reg->number);
4766 return;
4767
4768 case REG_TYPE_RN:
4769 s_arm_unwind_save_core ();
4770 return;
4771
4772 case REG_TYPE_VFD:
4773 if (arch_v6)
4774 s_arm_unwind_save_vfp_armv6 ();
4775 else
4776 s_arm_unwind_save_vfp ();
4777 return;
4778
4779 case REG_TYPE_MMXWR:
4780 s_arm_unwind_save_mmxwr ();
4781 return;
4782
4783 case REG_TYPE_MMXWCG:
4784 s_arm_unwind_save_mmxwcg ();
4785 return;
4786
4787 default:
4788 as_bad (_(".unwind_save does not support this kind of register"));
4789 ignore_rest_of_line ();
4790 }
4791 }
4792
4793
4794 /* Parse an unwind_movsp directive. */
4795
4796 static void
4797 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4798 {
4799 int reg;
4800 valueT op;
4801 int offset;
4802
4803 if (!unwind.proc_start)
4804 as_bad (MISSING_FNSTART);
4805
4806 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4807 if (reg == FAIL)
4808 {
4809 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4810 ignore_rest_of_line ();
4811 return;
4812 }
4813
4814 /* Optional constant. */
4815 if (skip_past_comma (&input_line_pointer) != FAIL)
4816 {
4817 if (immediate_for_directive (&offset) == FAIL)
4818 return;
4819 }
4820 else
4821 offset = 0;
4822
4823 demand_empty_rest_of_line ();
4824
4825 if (reg == REG_SP || reg == REG_PC)
4826 {
4827 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4828 return;
4829 }
4830
4831 if (unwind.fp_reg != REG_SP)
4832 as_bad (_("unexpected .unwind_movsp directive"));
4833
4834 /* Generate opcode to restore the value. */
4835 op = 0x90 | reg;
4836 add_unwind_opcode (op, 1);
4837
4838 /* Record the information for later. */
4839 unwind.fp_reg = reg;
4840 unwind.fp_offset = unwind.frame_size - offset;
4841 unwind.sp_restored = 1;
4842 }
4843
4844 /* Parse an unwind_pad directive. */
4845
4846 static void
4847 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4848 {
4849 int offset;
4850
4851 if (!unwind.proc_start)
4852 as_bad (MISSING_FNSTART);
4853
4854 if (immediate_for_directive (&offset) == FAIL)
4855 return;
4856
4857 if (offset & 3)
4858 {
4859 as_bad (_("stack increment must be multiple of 4"));
4860 ignore_rest_of_line ();
4861 return;
4862 }
4863
4864 /* Don't generate any opcodes, just record the details for later. */
4865 unwind.frame_size += offset;
4866 unwind.pending_offset += offset;
4867
4868 demand_empty_rest_of_line ();
4869 }
4870
4871 /* Parse an unwind_setfp directive. */
4872
4873 static void
4874 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4875 {
4876 int sp_reg;
4877 int fp_reg;
4878 int offset;
4879
4880 if (!unwind.proc_start)
4881 as_bad (MISSING_FNSTART);
4882
4883 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4884 if (skip_past_comma (&input_line_pointer) == FAIL)
4885 sp_reg = FAIL;
4886 else
4887 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4888
4889 if (fp_reg == FAIL || sp_reg == FAIL)
4890 {
4891 as_bad (_("expected <reg>, <reg>"));
4892 ignore_rest_of_line ();
4893 return;
4894 }
4895
4896 /* Optional constant. */
4897 if (skip_past_comma (&input_line_pointer) != FAIL)
4898 {
4899 if (immediate_for_directive (&offset) == FAIL)
4900 return;
4901 }
4902 else
4903 offset = 0;
4904
4905 demand_empty_rest_of_line ();
4906
4907 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4908 {
4909 as_bad (_("register must be either sp or set by a previous"
4910 "unwind_movsp directive"));
4911 return;
4912 }
4913
4914 /* Don't generate any opcodes, just record the information for later. */
4915 unwind.fp_reg = fp_reg;
4916 unwind.fp_used = 1;
4917 if (sp_reg == REG_SP)
4918 unwind.fp_offset = unwind.frame_size - offset;
4919 else
4920 unwind.fp_offset -= offset;
4921 }
4922
4923 /* Parse an unwind_raw directive. */
4924
4925 static void
4926 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4927 {
4928 expressionS exp;
4929 /* This is an arbitrary limit. */
4930 unsigned char op[16];
4931 int count;
4932
4933 if (!unwind.proc_start)
4934 as_bad (MISSING_FNSTART);
4935
4936 expression (&exp);
4937 if (exp.X_op == O_constant
4938 && skip_past_comma (&input_line_pointer) != FAIL)
4939 {
4940 unwind.frame_size += exp.X_add_number;
4941 expression (&exp);
4942 }
4943 else
4944 exp.X_op = O_illegal;
4945
4946 if (exp.X_op != O_constant)
4947 {
4948 as_bad (_("expected <offset>, <opcode>"));
4949 ignore_rest_of_line ();
4950 return;
4951 }
4952
4953 count = 0;
4954
4955 /* Parse the opcode. */
4956 for (;;)
4957 {
4958 if (count >= 16)
4959 {
4960 as_bad (_("unwind opcode too long"));
4961 ignore_rest_of_line ();
4962 }
4963 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4964 {
4965 as_bad (_("invalid unwind opcode"));
4966 ignore_rest_of_line ();
4967 return;
4968 }
4969 op[count++] = exp.X_add_number;
4970
4971 /* Parse the next byte. */
4972 if (skip_past_comma (&input_line_pointer) == FAIL)
4973 break;
4974
4975 expression (&exp);
4976 }
4977
4978 /* Add the opcode bytes in reverse order. */
4979 while (count--)
4980 add_unwind_opcode (op[count], 1);
4981
4982 demand_empty_rest_of_line ();
4983 }
4984
4985
4986 /* Parse a .eabi_attribute directive. */
4987
4988 static void
4989 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4990 {
4991 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4992
4993 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4994 attributes_set_explicitly[tag] = 1;
4995 }
4996
4997 /* Emit a tls fix for the symbol. */
4998
4999 static void
5000 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
5001 {
5002 char *p;
5003 expressionS exp;
5004 #ifdef md_flush_pending_output
5005 md_flush_pending_output ();
5006 #endif
5007
5008 #ifdef md_cons_align
5009 md_cons_align (4);
5010 #endif
5011
5012 /* Since we're just labelling the code, there's no need to define a
5013 mapping symbol. */
5014 expression (&exp);
5015 p = obstack_next_free (&frchain_now->frch_obstack);
5016 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
5017 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
5018 : BFD_RELOC_ARM_TLS_DESCSEQ);
5019 }
5020 #endif /* OBJ_ELF */
5021
5022 static void s_arm_arch (int);
5023 static void s_arm_object_arch (int);
5024 static void s_arm_cpu (int);
5025 static void s_arm_fpu (int);
5026 static void s_arm_arch_extension (int);
5027
5028 #ifdef TE_PE
5029
5030 static void
5031 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
5032 {
5033 expressionS exp;
5034
5035 do
5036 {
5037 expression (&exp);
5038 if (exp.X_op == O_symbol)
5039 exp.X_op = O_secrel;
5040
5041 emit_expr (&exp, 4);
5042 }
5043 while (*input_line_pointer++ == ',');
5044
5045 input_line_pointer--;
5046 demand_empty_rest_of_line ();
5047 }
5048 #endif /* TE_PE */
5049
5050 int
5051 arm_is_largest_exponent_ok (int precision)
5052 {
5053 /* precision == 1 ensures that this will only return
5054 true for 16 bit floats. */
5055 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5056 }
5057
5058 static void
5059 set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5060 {
5061 char saved_char;
5062 char* name;
5063 enum fp_16bit_format new_format;
5064
5065 new_format = ARM_FP16_FORMAT_DEFAULT;
5066
5067 name = input_line_pointer;
5068 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5069 input_line_pointer++;
5070
5071 saved_char = *input_line_pointer;
5072 *input_line_pointer = 0;
5073
5074 if (strcasecmp (name, "ieee") == 0)
5075 new_format = ARM_FP16_FORMAT_IEEE;
5076 else if (strcasecmp (name, "alternative") == 0)
5077 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5078 else
5079 {
5080 as_bad (_("unrecognised float16 format \"%s\""), name);
5081 goto cleanup;
5082 }
5083
5084 /* Only set fp16_format if it is still the default (aka not already
5085 been set yet). */
5086 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5087 fp16_format = new_format;
5088 else
5089 {
5090 if (new_format != fp16_format)
5091 as_warn (_("float16 format cannot be set more than once, ignoring."));
5092 }
5093
5094 cleanup:
5095 *input_line_pointer = saved_char;
5096 ignore_rest_of_line ();
5097 }
5098
5099 /* This table describes all the machine specific pseudo-ops the assembler
5100 has to support. The fields are:
5101 pseudo-op name without dot
5102 function to call to execute this pseudo-op
5103 Integer arg to pass to the function. */
5104
5105 const pseudo_typeS md_pseudo_table[] =
5106 {
5107 /* Never called because '.req' does not start a line. */
5108 { "req", s_req, 0 },
5109 /* Following two are likewise never called. */
5110 { "dn", s_dn, 0 },
5111 { "qn", s_qn, 0 },
5112 { "unreq", s_unreq, 0 },
5113 { "bss", s_bss, 0 },
5114 { "align", s_align_ptwo, 2 },
5115 { "arm", s_arm, 0 },
5116 { "thumb", s_thumb, 0 },
5117 { "code", s_code, 0 },
5118 { "force_thumb", s_force_thumb, 0 },
5119 { "thumb_func", s_thumb_func, 0 },
5120 { "thumb_set", s_thumb_set, 0 },
5121 { "even", s_even, 0 },
5122 { "ltorg", s_ltorg, 0 },
5123 { "pool", s_ltorg, 0 },
5124 { "syntax", s_syntax, 0 },
5125 { "cpu", s_arm_cpu, 0 },
5126 { "arch", s_arm_arch, 0 },
5127 { "object_arch", s_arm_object_arch, 0 },
5128 { "fpu", s_arm_fpu, 0 },
5129 { "arch_extension", s_arm_arch_extension, 0 },
5130 #ifdef OBJ_ELF
5131 { "word", s_arm_elf_cons, 4 },
5132 { "long", s_arm_elf_cons, 4 },
5133 { "inst.n", s_arm_elf_inst, 2 },
5134 { "inst.w", s_arm_elf_inst, 4 },
5135 { "inst", s_arm_elf_inst, 0 },
5136 { "rel31", s_arm_rel31, 0 },
5137 { "fnstart", s_arm_unwind_fnstart, 0 },
5138 { "fnend", s_arm_unwind_fnend, 0 },
5139 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5140 { "personality", s_arm_unwind_personality, 0 },
5141 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5142 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5143 { "save", s_arm_unwind_save, 0 },
5144 { "vsave", s_arm_unwind_save, 1 },
5145 { "movsp", s_arm_unwind_movsp, 0 },
5146 { "pad", s_arm_unwind_pad, 0 },
5147 { "setfp", s_arm_unwind_setfp, 0 },
5148 { "unwind_raw", s_arm_unwind_raw, 0 },
5149 { "eabi_attribute", s_arm_eabi_attribute, 0 },
5150 { "tlsdescseq", s_arm_tls_descseq, 0 },
5151 #else
5152 { "word", cons, 4},
5153
5154 /* These are used for dwarf. */
5155 {"2byte", cons, 2},
5156 {"4byte", cons, 4},
5157 {"8byte", cons, 8},
5158 /* These are used for dwarf2. */
5159 { "file", dwarf2_directive_file, 0 },
5160 { "loc", dwarf2_directive_loc, 0 },
5161 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
5162 #endif
5163 { "extend", float_cons, 'x' },
5164 { "ldouble", float_cons, 'x' },
5165 { "packed", float_cons, 'p' },
5166 { "bfloat16", float_cons, 'b' },
5167 #ifdef TE_PE
5168 {"secrel32", pe_directive_secrel, 0},
5169 #endif
5170
5171 /* These are for compatibility with CodeComposer Studio. */
5172 {"ref", s_ccs_ref, 0},
5173 {"def", s_ccs_def, 0},
5174 {"asmfunc", s_ccs_asmfunc, 0},
5175 {"endasmfunc", s_ccs_endasmfunc, 0},
5176
5177 {"float16", float_cons, 'h' },
5178 {"float16_format", set_fp16_format, 0 },
5179
5180 { 0, 0, 0 }
5181 };
5182
5183 /* Parser functions used exclusively in instruction operands. */
5184
5185 /* Generic immediate-value read function for use in insn parsing.
5186 STR points to the beginning of the immediate (the leading #);
5187 VAL receives the value; if the value is outside [MIN, MAX]
5188 issue an error. PREFIX_OPT is true if the immediate prefix is
5189 optional. */
5190
5191 static int
5192 parse_immediate (char **str, int *val, int min, int max,
5193 bfd_boolean prefix_opt)
5194 {
5195 expressionS exp;
5196
5197 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5198 if (exp.X_op != O_constant)
5199 {
5200 inst.error = _("constant expression required");
5201 return FAIL;
5202 }
5203
5204 if (exp.X_add_number < min || exp.X_add_number > max)
5205 {
5206 inst.error = _("immediate value out of range");
5207 return FAIL;
5208 }
5209
5210 *val = exp.X_add_number;
5211 return SUCCESS;
5212 }
5213
5214 /* Less-generic immediate-value read function with the possibility of loading a
5215 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5216 instructions. Puts the result directly in inst.operands[i]. */
5217
5218 static int
5219 parse_big_immediate (char **str, int i, expressionS *in_exp,
5220 bfd_boolean allow_symbol_p)
5221 {
5222 expressionS exp;
5223 expressionS *exp_p = in_exp ? in_exp : &exp;
5224 char *ptr = *str;
5225
5226 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5227
5228 if (exp_p->X_op == O_constant)
5229 {
5230 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
5231 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5232 O_constant. We have to be careful not to break compilation for
5233 32-bit X_add_number, though. */
5234 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
5235 {
5236 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5237 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5238 & 0xffffffff);
5239 inst.operands[i].regisimm = 1;
5240 }
5241 }
5242 else if (exp_p->X_op == O_big
5243 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5244 {
5245 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
5246
5247 /* Bignums have their least significant bits in
5248 generic_bignum[0]. Make sure we put 32 bits in imm and
5249 32 bits in reg, in a (hopefully) portable way. */
5250 gas_assert (parts != 0);
5251
5252 /* Make sure that the number is not too big.
5253 PR 11972: Bignums can now be sign-extended to the
5254 size of a .octa so check that the out of range bits
5255 are all zero or all one. */
5256 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
5257 {
5258 LITTLENUM_TYPE m = -1;
5259
5260 if (generic_bignum[parts * 2] != 0
5261 && generic_bignum[parts * 2] != m)
5262 return FAIL;
5263
5264 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
5265 if (generic_bignum[j] != generic_bignum[j-1])
5266 return FAIL;
5267 }
5268
5269 inst.operands[i].imm = 0;
5270 for (j = 0; j < parts; j++, idx++)
5271 inst.operands[i].imm |= generic_bignum[idx]
5272 << (LITTLENUM_NUMBER_OF_BITS * j);
5273 inst.operands[i].reg = 0;
5274 for (j = 0; j < parts; j++, idx++)
5275 inst.operands[i].reg |= generic_bignum[idx]
5276 << (LITTLENUM_NUMBER_OF_BITS * j);
5277 inst.operands[i].regisimm = 1;
5278 }
5279 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5280 return FAIL;
5281
5282 *str = ptr;
5283
5284 return SUCCESS;
5285 }
5286
5287 /* Returns the pseudo-register number of an FPA immediate constant,
5288 or FAIL if there isn't a valid constant here. */
5289
5290 static int
5291 parse_fpa_immediate (char ** str)
5292 {
5293 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5294 char * save_in;
5295 expressionS exp;
5296 int i;
5297 int j;
5298
5299 /* First try and match exact strings, this is to guarantee
5300 that some formats will work even for cross assembly. */
5301
5302 for (i = 0; fp_const[i]; i++)
5303 {
5304 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
5305 {
5306 char *start = *str;
5307
5308 *str += strlen (fp_const[i]);
5309 if (is_end_of_line[(unsigned char) **str])
5310 return i + 8;
5311 *str = start;
5312 }
5313 }
5314
5315 /* Just because we didn't get a match doesn't mean that the constant
5316 isn't valid, just that it is in a format that we don't
5317 automatically recognize. Try parsing it with the standard
5318 expression routines. */
5319
5320 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
5321
5322 /* Look for a raw floating point number. */
5323 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5324 && is_end_of_line[(unsigned char) *save_in])
5325 {
5326 for (i = 0; i < NUM_FLOAT_VALS; i++)
5327 {
5328 for (j = 0; j < MAX_LITTLENUMS; j++)
5329 {
5330 if (words[j] != fp_values[i][j])
5331 break;
5332 }
5333
5334 if (j == MAX_LITTLENUMS)
5335 {
5336 *str = save_in;
5337 return i + 8;
5338 }
5339 }
5340 }
5341
5342 /* Try and parse a more complex expression, this will probably fail
5343 unless the code uses a floating point prefix (eg "0f"). */
5344 save_in = input_line_pointer;
5345 input_line_pointer = *str;
5346 if (expression (&exp) == absolute_section
5347 && exp.X_op == O_big
5348 && exp.X_add_number < 0)
5349 {
5350 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5351 Ditto for 15. */
5352 #define X_PRECISION 5
5353 #define E_PRECISION 15L
5354 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
5355 {
5356 for (i = 0; i < NUM_FLOAT_VALS; i++)
5357 {
5358 for (j = 0; j < MAX_LITTLENUMS; j++)
5359 {
5360 if (words[j] != fp_values[i][j])
5361 break;
5362 }
5363
5364 if (j == MAX_LITTLENUMS)
5365 {
5366 *str = input_line_pointer;
5367 input_line_pointer = save_in;
5368 return i + 8;
5369 }
5370 }
5371 }
5372 }
5373
5374 *str = input_line_pointer;
5375 input_line_pointer = save_in;
5376 inst.error = _("invalid FPA immediate expression");
5377 return FAIL;
5378 }
5379
5380 /* Returns 1 if a number has "quarter-precision" float format
5381 0baBbbbbbc defgh000 00000000 00000000. */
5382
5383 static int
5384 is_quarter_float (unsigned imm)
5385 {
5386 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5387 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5388 }
5389
5390
5391 /* Detect the presence of a floating point or integer zero constant,
5392 i.e. #0.0 or #0. */
5393
5394 static bfd_boolean
5395 parse_ifimm_zero (char **in)
5396 {
5397 int error_code;
5398
5399 if (!is_immediate_prefix (**in))
5400 {
5401 /* In unified syntax, all prefixes are optional. */
5402 if (!unified_syntax)
5403 return FALSE;
5404 }
5405 else
5406 ++*in;
5407
5408 /* Accept #0x0 as a synonym for #0. */
5409 if (strncmp (*in, "0x", 2) == 0)
5410 {
5411 int val;
5412 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5413 return FALSE;
5414 return TRUE;
5415 }
5416
5417 error_code = atof_generic (in, ".", EXP_CHARS,
5418 &generic_floating_point_number);
5419
5420 if (!error_code
5421 && generic_floating_point_number.sign == '+'
5422 && (generic_floating_point_number.low
5423 > generic_floating_point_number.leader))
5424 return TRUE;
5425
5426 return FALSE;
5427 }
5428
5429 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5430 0baBbbbbbc defgh000 00000000 00000000.
5431 The zero and minus-zero cases need special handling, since they can't be
5432 encoded in the "quarter-precision" float format, but can nonetheless be
5433 loaded as integer constants. */
5434
5435 static unsigned
5436 parse_qfloat_immediate (char **ccp, int *immed)
5437 {
5438 char *str = *ccp;
5439 char *fpnum;
5440 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5441 int found_fpchar = 0;
5442
5443 skip_past_char (&str, '#');
5444
5445 /* We must not accidentally parse an integer as a floating-point number. Make
5446 sure that the value we parse is not an integer by checking for special
5447 characters '.' or 'e'.
5448 FIXME: This is a horrible hack, but doing better is tricky because type
5449 information isn't in a very usable state at parse time. */
5450 fpnum = str;
5451 skip_whitespace (fpnum);
5452
5453 if (strncmp (fpnum, "0x", 2) == 0)
5454 return FAIL;
5455 else
5456 {
5457 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5458 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5459 {
5460 found_fpchar = 1;
5461 break;
5462 }
5463
5464 if (!found_fpchar)
5465 return FAIL;
5466 }
5467
5468 if ((str = atof_ieee (str, 's', words)) != NULL)
5469 {
5470 unsigned fpword = 0;
5471 int i;
5472
5473 /* Our FP word must be 32 bits (single-precision FP). */
5474 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5475 {
5476 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5477 fpword |= words[i];
5478 }
5479
5480 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5481 *immed = fpword;
5482 else
5483 return FAIL;
5484
5485 *ccp = str;
5486
5487 return SUCCESS;
5488 }
5489
5490 return FAIL;
5491 }
5492
5493 /* Shift operands. */
5494 enum shift_kind
5495 {
5496 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
5497 };
5498
5499 struct asm_shift_name
5500 {
5501 const char *name;
5502 enum shift_kind kind;
5503 };
5504
5505 /* Third argument to parse_shift. */
5506 enum parse_shift_mode
5507 {
5508 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5509 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5510 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5511 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5512 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5513 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
5514 };
5515
5516 /* Parse a <shift> specifier on an ARM data processing instruction.
5517 This has three forms:
5518
5519 (LSL|LSR|ASL|ASR|ROR) Rs
5520 (LSL|LSR|ASL|ASR|ROR) #imm
5521 RRX
5522
5523 Note that ASL is assimilated to LSL in the instruction encoding, and
5524 RRX to ROR #0 (which cannot be written as such). */
5525
5526 static int
5527 parse_shift (char **str, int i, enum parse_shift_mode mode)
5528 {
5529 const struct asm_shift_name *shift_name;
5530 enum shift_kind shift;
5531 char *s = *str;
5532 char *p = s;
5533 int reg;
5534
5535 for (p = *str; ISALPHA (*p); p++)
5536 ;
5537
5538 if (p == *str)
5539 {
5540 inst.error = _("shift expression expected");
5541 return FAIL;
5542 }
5543
5544 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5545 p - *str);
5546
5547 if (shift_name == NULL)
5548 {
5549 inst.error = _("shift expression expected");
5550 return FAIL;
5551 }
5552
5553 shift = shift_name->kind;
5554
5555 switch (mode)
5556 {
5557 case NO_SHIFT_RESTRICT:
5558 case SHIFT_IMMEDIATE:
5559 if (shift == SHIFT_UXTW)
5560 {
5561 inst.error = _("'UXTW' not allowed here");
5562 return FAIL;
5563 }
5564 break;
5565
5566 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5567 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5568 {
5569 inst.error = _("'LSL' or 'ASR' required");
5570 return FAIL;
5571 }
5572 break;
5573
5574 case SHIFT_LSL_IMMEDIATE:
5575 if (shift != SHIFT_LSL)
5576 {
5577 inst.error = _("'LSL' required");
5578 return FAIL;
5579 }
5580 break;
5581
5582 case SHIFT_ASR_IMMEDIATE:
5583 if (shift != SHIFT_ASR)
5584 {
5585 inst.error = _("'ASR' required");
5586 return FAIL;
5587 }
5588 break;
5589 case SHIFT_UXTW_IMMEDIATE:
5590 if (shift != SHIFT_UXTW)
5591 {
5592 inst.error = _("'UXTW' required");
5593 return FAIL;
5594 }
5595 break;
5596
5597 default: abort ();
5598 }
5599
5600 if (shift != SHIFT_RRX)
5601 {
5602 /* Whitespace can appear here if the next thing is a bare digit. */
5603 skip_whitespace (p);
5604
5605 if (mode == NO_SHIFT_RESTRICT
5606 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5607 {
5608 inst.operands[i].imm = reg;
5609 inst.operands[i].immisreg = 1;
5610 }
5611 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5612 return FAIL;
5613 }
5614 inst.operands[i].shift_kind = shift;
5615 inst.operands[i].shifted = 1;
5616 *str = p;
5617 return SUCCESS;
5618 }
5619
5620 /* Parse a <shifter_operand> for an ARM data processing instruction:
5621
5622 #<immediate>
5623 #<immediate>, <rotate>
5624 <Rm>
5625 <Rm>, <shift>
5626
5627 where <shift> is defined by parse_shift above, and <rotate> is a
5628 multiple of 2 between 0 and 30. Validation of immediate operands
5629 is deferred to md_apply_fix. */
5630
5631 static int
5632 parse_shifter_operand (char **str, int i)
5633 {
5634 int value;
5635 expressionS exp;
5636
5637 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5638 {
5639 inst.operands[i].reg = value;
5640 inst.operands[i].isreg = 1;
5641
5642 /* parse_shift will override this if appropriate */
5643 inst.relocs[0].exp.X_op = O_constant;
5644 inst.relocs[0].exp.X_add_number = 0;
5645
5646 if (skip_past_comma (str) == FAIL)
5647 return SUCCESS;
5648
5649 /* Shift operation on register. */
5650 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5651 }
5652
5653 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5654 return FAIL;
5655
5656 if (skip_past_comma (str) == SUCCESS)
5657 {
5658 /* #x, y -- ie explicit rotation by Y. */
5659 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5660 return FAIL;
5661
5662 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5663 {
5664 inst.error = _("constant expression expected");
5665 return FAIL;
5666 }
5667
5668 value = exp.X_add_number;
5669 if (value < 0 || value > 30 || value % 2 != 0)
5670 {
5671 inst.error = _("invalid rotation");
5672 return FAIL;
5673 }
5674 if (inst.relocs[0].exp.X_add_number < 0
5675 || inst.relocs[0].exp.X_add_number > 255)
5676 {
5677 inst.error = _("invalid constant");
5678 return FAIL;
5679 }
5680
5681 /* Encode as specified. */
5682 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5683 return SUCCESS;
5684 }
5685
5686 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5687 inst.relocs[0].pc_rel = 0;
5688 return SUCCESS;
5689 }
5690
5691 /* Group relocation information. Each entry in the table contains the
5692 textual name of the relocation as may appear in assembler source
5693 and must end with a colon.
5694 Along with this textual name are the relocation codes to be used if
5695 the corresponding instruction is an ALU instruction (ADD or SUB only),
5696 an LDR, an LDRS, or an LDC. */
5697
5698 struct group_reloc_table_entry
5699 {
5700 const char *name;
5701 int alu_code;
5702 int ldr_code;
5703 int ldrs_code;
5704 int ldc_code;
5705 };
5706
5707 typedef enum
5708 {
5709 /* Varieties of non-ALU group relocation. */
5710
5711 GROUP_LDR,
5712 GROUP_LDRS,
5713 GROUP_LDC,
5714 GROUP_MVE
5715 } group_reloc_type;
5716
5717 static struct group_reloc_table_entry group_reloc_table[] =
5718 { /* Program counter relative: */
5719 { "pc_g0_nc",
5720 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5721 0, /* LDR */
5722 0, /* LDRS */
5723 0 }, /* LDC */
5724 { "pc_g0",
5725 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5726 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5727 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5728 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5729 { "pc_g1_nc",
5730 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5731 0, /* LDR */
5732 0, /* LDRS */
5733 0 }, /* LDC */
5734 { "pc_g1",
5735 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5736 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5737 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5738 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5739 { "pc_g2",
5740 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5741 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5742 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5743 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5744 /* Section base relative */
5745 { "sb_g0_nc",
5746 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5747 0, /* LDR */
5748 0, /* LDRS */
5749 0 }, /* LDC */
5750 { "sb_g0",
5751 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5752 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5753 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5754 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5755 { "sb_g1_nc",
5756 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5757 0, /* LDR */
5758 0, /* LDRS */
5759 0 }, /* LDC */
5760 { "sb_g1",
5761 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5762 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5763 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5764 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5765 { "sb_g2",
5766 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5767 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5768 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5769 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5770 /* Absolute thumb alu relocations. */
5771 { "lower0_7",
5772 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5773 0, /* LDR. */
5774 0, /* LDRS. */
5775 0 }, /* LDC. */
5776 { "lower8_15",
5777 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5778 0, /* LDR. */
5779 0, /* LDRS. */
5780 0 }, /* LDC. */
5781 { "upper0_7",
5782 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5783 0, /* LDR. */
5784 0, /* LDRS. */
5785 0 }, /* LDC. */
5786 { "upper8_15",
5787 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5788 0, /* LDR. */
5789 0, /* LDRS. */
5790 0 } }; /* LDC. */
5791
5792 /* Given the address of a pointer pointing to the textual name of a group
5793 relocation as may appear in assembler source, attempt to find its details
5794 in group_reloc_table. The pointer will be updated to the character after
5795 the trailing colon. On failure, FAIL will be returned; SUCCESS
5796 otherwise. On success, *entry will be updated to point at the relevant
5797 group_reloc_table entry. */
5798
5799 static int
5800 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5801 {
5802 unsigned int i;
5803 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5804 {
5805 int length = strlen (group_reloc_table[i].name);
5806
5807 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5808 && (*str)[length] == ':')
5809 {
5810 *out = &group_reloc_table[i];
5811 *str += (length + 1);
5812 return SUCCESS;
5813 }
5814 }
5815
5816 return FAIL;
5817 }
5818
5819 /* Parse a <shifter_operand> for an ARM data processing instruction
5820 (as for parse_shifter_operand) where group relocations are allowed:
5821
5822 #<immediate>
5823 #<immediate>, <rotate>
5824 #:<group_reloc>:<expression>
5825 <Rm>
5826 <Rm>, <shift>
5827
5828 where <group_reloc> is one of the strings defined in group_reloc_table.
5829 The hashes are optional.
5830
5831 Everything else is as for parse_shifter_operand. */
5832
5833 static parse_operand_result
5834 parse_shifter_operand_group_reloc (char **str, int i)
5835 {
5836 /* Determine if we have the sequence of characters #: or just :
5837 coming next. If we do, then we check for a group relocation.
5838 If we don't, punt the whole lot to parse_shifter_operand. */
5839
5840 if (((*str)[0] == '#' && (*str)[1] == ':')
5841 || (*str)[0] == ':')
5842 {
5843 struct group_reloc_table_entry *entry;
5844
5845 if ((*str)[0] == '#')
5846 (*str) += 2;
5847 else
5848 (*str)++;
5849
5850 /* Try to parse a group relocation. Anything else is an error. */
5851 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5852 {
5853 inst.error = _("unknown group relocation");
5854 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5855 }
5856
5857 /* We now have the group relocation table entry corresponding to
5858 the name in the assembler source. Next, we parse the expression. */
5859 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5860 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5861
5862 /* Record the relocation type (always the ALU variant here). */
5863 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5864 gas_assert (inst.relocs[0].type != 0);
5865
5866 return PARSE_OPERAND_SUCCESS;
5867 }
5868 else
5869 return parse_shifter_operand (str, i) == SUCCESS
5870 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5871
5872 /* Never reached. */
5873 }
5874
5875 /* Parse a Neon alignment expression. Information is written to
5876 inst.operands[i]. We assume the initial ':' has been skipped.
5877
5878 align .imm = align << 8, .immisalign=1, .preind=0 */
5879 static parse_operand_result
5880 parse_neon_alignment (char **str, int i)
5881 {
5882 char *p = *str;
5883 expressionS exp;
5884
5885 my_get_expression (&exp, &p, GE_NO_PREFIX);
5886
5887 if (exp.X_op != O_constant)
5888 {
5889 inst.error = _("alignment must be constant");
5890 return PARSE_OPERAND_FAIL;
5891 }
5892
5893 inst.operands[i].imm = exp.X_add_number << 8;
5894 inst.operands[i].immisalign = 1;
5895 /* Alignments are not pre-indexes. */
5896 inst.operands[i].preind = 0;
5897
5898 *str = p;
5899 return PARSE_OPERAND_SUCCESS;
5900 }
5901
5902 /* Parse all forms of an ARM address expression. Information is written
5903 to inst.operands[i] and/or inst.relocs[0].
5904
5905 Preindexed addressing (.preind=1):
5906
5907 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5908 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5909 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5910 .shift_kind=shift .relocs[0].exp=shift_imm
5911
5912 These three may have a trailing ! which causes .writeback to be set also.
5913
5914 Postindexed addressing (.postind=1, .writeback=1):
5915
5916 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5917 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5918 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5919 .shift_kind=shift .relocs[0].exp=shift_imm
5920
5921 Unindexed addressing (.preind=0, .postind=0):
5922
5923 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5924
5925 Other:
5926
5927 [Rn]{!} shorthand for [Rn,#0]{!}
5928 =immediate .isreg=0 .relocs[0].exp=immediate
5929 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5930
5931 It is the caller's responsibility to check for addressing modes not
5932 supported by the instruction, and to set inst.relocs[0].type. */
5933
5934 static parse_operand_result
5935 parse_address_main (char **str, int i, int group_relocations,
5936 group_reloc_type group_type)
5937 {
5938 char *p = *str;
5939 int reg;
5940
5941 if (skip_past_char (&p, '[') == FAIL)
5942 {
5943 if (skip_past_char (&p, '=') == FAIL)
5944 {
5945 /* Bare address - translate to PC-relative offset. */
5946 inst.relocs[0].pc_rel = 1;
5947 inst.operands[i].reg = REG_PC;
5948 inst.operands[i].isreg = 1;
5949 inst.operands[i].preind = 1;
5950
5951 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5952 return PARSE_OPERAND_FAIL;
5953 }
5954 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5955 /*allow_symbol_p=*/TRUE))
5956 return PARSE_OPERAND_FAIL;
5957
5958 *str = p;
5959 return PARSE_OPERAND_SUCCESS;
5960 }
5961
5962 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5963 skip_whitespace (p);
5964
5965 if (group_type == GROUP_MVE)
5966 {
5967 enum arm_reg_type rtype = REG_TYPE_MQ;
5968 struct neon_type_el et;
5969 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5970 {
5971 inst.operands[i].isquad = 1;
5972 }
5973 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5974 {
5975 inst.error = BAD_ADDR_MODE;
5976 return PARSE_OPERAND_FAIL;
5977 }
5978 }
5979 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5980 {
5981 if (group_type == GROUP_MVE)
5982 inst.error = BAD_ADDR_MODE;
5983 else
5984 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5985 return PARSE_OPERAND_FAIL;
5986 }
5987 inst.operands[i].reg = reg;
5988 inst.operands[i].isreg = 1;
5989
5990 if (skip_past_comma (&p) == SUCCESS)
5991 {
5992 inst.operands[i].preind = 1;
5993
5994 if (*p == '+') p++;
5995 else if (*p == '-') p++, inst.operands[i].negative = 1;
5996
5997 enum arm_reg_type rtype = REG_TYPE_MQ;
5998 struct neon_type_el et;
5999 if (group_type == GROUP_MVE
6000 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6001 {
6002 inst.operands[i].immisreg = 2;
6003 inst.operands[i].imm = reg;
6004
6005 if (skip_past_comma (&p) == SUCCESS)
6006 {
6007 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
6008 {
6009 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
6010 inst.relocs[0].exp.X_add_number = 0;
6011 }
6012 else
6013 return PARSE_OPERAND_FAIL;
6014 }
6015 }
6016 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6017 {
6018 inst.operands[i].imm = reg;
6019 inst.operands[i].immisreg = 1;
6020
6021 if (skip_past_comma (&p) == SUCCESS)
6022 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6023 return PARSE_OPERAND_FAIL;
6024 }
6025 else if (skip_past_char (&p, ':') == SUCCESS)
6026 {
6027 /* FIXME: '@' should be used here, but it's filtered out by generic
6028 code before we get to see it here. This may be subject to
6029 change. */
6030 parse_operand_result result = parse_neon_alignment (&p, i);
6031
6032 if (result != PARSE_OPERAND_SUCCESS)
6033 return result;
6034 }
6035 else
6036 {
6037 if (inst.operands[i].negative)
6038 {
6039 inst.operands[i].negative = 0;
6040 p--;
6041 }
6042
6043 if (group_relocations
6044 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
6045 {
6046 struct group_reloc_table_entry *entry;
6047
6048 /* Skip over the #: or : sequence. */
6049 if (*p == '#')
6050 p += 2;
6051 else
6052 p++;
6053
6054 /* Try to parse a group relocation. Anything else is an
6055 error. */
6056 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6057 {
6058 inst.error = _("unknown group relocation");
6059 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6060 }
6061
6062 /* We now have the group relocation table entry corresponding to
6063 the name in the assembler source. Next, we parse the
6064 expression. */
6065 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6066 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6067
6068 /* Record the relocation type. */
6069 switch (group_type)
6070 {
6071 case GROUP_LDR:
6072 inst.relocs[0].type
6073 = (bfd_reloc_code_real_type) entry->ldr_code;
6074 break;
6075
6076 case GROUP_LDRS:
6077 inst.relocs[0].type
6078 = (bfd_reloc_code_real_type) entry->ldrs_code;
6079 break;
6080
6081 case GROUP_LDC:
6082 inst.relocs[0].type
6083 = (bfd_reloc_code_real_type) entry->ldc_code;
6084 break;
6085
6086 default:
6087 gas_assert (0);
6088 }
6089
6090 if (inst.relocs[0].type == 0)
6091 {
6092 inst.error = _("this group relocation is not allowed on this instruction");
6093 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6094 }
6095 }
6096 else
6097 {
6098 char *q = p;
6099
6100 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6101 return PARSE_OPERAND_FAIL;
6102 /* If the offset is 0, find out if it's a +0 or -0. */
6103 if (inst.relocs[0].exp.X_op == O_constant
6104 && inst.relocs[0].exp.X_add_number == 0)
6105 {
6106 skip_whitespace (q);
6107 if (*q == '#')
6108 {
6109 q++;
6110 skip_whitespace (q);
6111 }
6112 if (*q == '-')
6113 inst.operands[i].negative = 1;
6114 }
6115 }
6116 }
6117 }
6118 else if (skip_past_char (&p, ':') == SUCCESS)
6119 {
6120 /* FIXME: '@' should be used here, but it's filtered out by generic code
6121 before we get to see it here. This may be subject to change. */
6122 parse_operand_result result = parse_neon_alignment (&p, i);
6123
6124 if (result != PARSE_OPERAND_SUCCESS)
6125 return result;
6126 }
6127
6128 if (skip_past_char (&p, ']') == FAIL)
6129 {
6130 inst.error = _("']' expected");
6131 return PARSE_OPERAND_FAIL;
6132 }
6133
6134 if (skip_past_char (&p, '!') == SUCCESS)
6135 inst.operands[i].writeback = 1;
6136
6137 else if (skip_past_comma (&p) == SUCCESS)
6138 {
6139 if (skip_past_char (&p, '{') == SUCCESS)
6140 {
6141 /* [Rn], {expr} - unindexed, with option */
6142 if (parse_immediate (&p, &inst.operands[i].imm,
6143 0, 255, TRUE) == FAIL)
6144 return PARSE_OPERAND_FAIL;
6145
6146 if (skip_past_char (&p, '}') == FAIL)
6147 {
6148 inst.error = _("'}' expected at end of 'option' field");
6149 return PARSE_OPERAND_FAIL;
6150 }
6151 if (inst.operands[i].preind)
6152 {
6153 inst.error = _("cannot combine index with option");
6154 return PARSE_OPERAND_FAIL;
6155 }
6156 *str = p;
6157 return PARSE_OPERAND_SUCCESS;
6158 }
6159 else
6160 {
6161 inst.operands[i].postind = 1;
6162 inst.operands[i].writeback = 1;
6163
6164 if (inst.operands[i].preind)
6165 {
6166 inst.error = _("cannot combine pre- and post-indexing");
6167 return PARSE_OPERAND_FAIL;
6168 }
6169
6170 if (*p == '+') p++;
6171 else if (*p == '-') p++, inst.operands[i].negative = 1;
6172
6173 enum arm_reg_type rtype = REG_TYPE_MQ;
6174 struct neon_type_el et;
6175 if (group_type == GROUP_MVE
6176 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6177 {
6178 inst.operands[i].immisreg = 2;
6179 inst.operands[i].imm = reg;
6180 }
6181 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6182 {
6183 /* We might be using the immediate for alignment already. If we
6184 are, OR the register number into the low-order bits. */
6185 if (inst.operands[i].immisalign)
6186 inst.operands[i].imm |= reg;
6187 else
6188 inst.operands[i].imm = reg;
6189 inst.operands[i].immisreg = 1;
6190
6191 if (skip_past_comma (&p) == SUCCESS)
6192 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6193 return PARSE_OPERAND_FAIL;
6194 }
6195 else
6196 {
6197 char *q = p;
6198
6199 if (inst.operands[i].negative)
6200 {
6201 inst.operands[i].negative = 0;
6202 p--;
6203 }
6204 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6205 return PARSE_OPERAND_FAIL;
6206 /* If the offset is 0, find out if it's a +0 or -0. */
6207 if (inst.relocs[0].exp.X_op == O_constant
6208 && inst.relocs[0].exp.X_add_number == 0)
6209 {
6210 skip_whitespace (q);
6211 if (*q == '#')
6212 {
6213 q++;
6214 skip_whitespace (q);
6215 }
6216 if (*q == '-')
6217 inst.operands[i].negative = 1;
6218 }
6219 }
6220 }
6221 }
6222
6223 /* If at this point neither .preind nor .postind is set, we have a
6224 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6225 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6226 {
6227 inst.operands[i].preind = 1;
6228 inst.relocs[0].exp.X_op = O_constant;
6229 inst.relocs[0].exp.X_add_number = 0;
6230 }
6231 *str = p;
6232 return PARSE_OPERAND_SUCCESS;
6233 }
6234
6235 static int
6236 parse_address (char **str, int i)
6237 {
6238 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
6239 ? SUCCESS : FAIL;
6240 }
6241
6242 static parse_operand_result
6243 parse_address_group_reloc (char **str, int i, group_reloc_type type)
6244 {
6245 return parse_address_main (str, i, 1, type);
6246 }
6247
6248 /* Parse an operand for a MOVW or MOVT instruction. */
6249 static int
6250 parse_half (char **str)
6251 {
6252 char * p;
6253
6254 p = *str;
6255 skip_past_char (&p, '#');
6256 if (strncasecmp (p, ":lower16:", 9) == 0)
6257 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
6258 else if (strncasecmp (p, ":upper16:", 9) == 0)
6259 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
6260
6261 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
6262 {
6263 p += 9;
6264 skip_whitespace (p);
6265 }
6266
6267 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6268 return FAIL;
6269
6270 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
6271 {
6272 if (inst.relocs[0].exp.X_op != O_constant)
6273 {
6274 inst.error = _("constant expression expected");
6275 return FAIL;
6276 }
6277 if (inst.relocs[0].exp.X_add_number < 0
6278 || inst.relocs[0].exp.X_add_number > 0xffff)
6279 {
6280 inst.error = _("immediate value out of range");
6281 return FAIL;
6282 }
6283 }
6284 *str = p;
6285 return SUCCESS;
6286 }
6287
6288 /* Miscellaneous. */
6289
6290 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6291 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6292 static int
6293 parse_psr (char **str, bfd_boolean lhs)
6294 {
6295 char *p;
6296 unsigned long psr_field;
6297 const struct asm_psr *psr;
6298 char *start;
6299 bfd_boolean is_apsr = FALSE;
6300 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
6301
6302 /* PR gas/12698: If the user has specified -march=all then m_profile will
6303 be TRUE, but we want to ignore it in this case as we are building for any
6304 CPU type, including non-m variants. */
6305 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
6306 m_profile = FALSE;
6307
6308 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6309 feature for ease of use and backwards compatibility. */
6310 p = *str;
6311 if (strncasecmp (p, "SPSR", 4) == 0)
6312 {
6313 if (m_profile)
6314 goto unsupported_psr;
6315
6316 psr_field = SPSR_BIT;
6317 }
6318 else if (strncasecmp (p, "CPSR", 4) == 0)
6319 {
6320 if (m_profile)
6321 goto unsupported_psr;
6322
6323 psr_field = 0;
6324 }
6325 else if (strncasecmp (p, "APSR", 4) == 0)
6326 {
6327 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6328 and ARMv7-R architecture CPUs. */
6329 is_apsr = TRUE;
6330 psr_field = 0;
6331 }
6332 else if (m_profile)
6333 {
6334 start = p;
6335 do
6336 p++;
6337 while (ISALNUM (*p) || *p == '_');
6338
6339 if (strncasecmp (start, "iapsr", 5) == 0
6340 || strncasecmp (start, "eapsr", 5) == 0
6341 || strncasecmp (start, "xpsr", 4) == 0
6342 || strncasecmp (start, "psr", 3) == 0)
6343 p = start + strcspn (start, "rR") + 1;
6344
6345 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
6346 p - start);
6347
6348 if (!psr)
6349 return FAIL;
6350
6351 /* If APSR is being written, a bitfield may be specified. Note that
6352 APSR itself is handled above. */
6353 if (psr->field <= 3)
6354 {
6355 psr_field = psr->field;
6356 is_apsr = TRUE;
6357 goto check_suffix;
6358 }
6359
6360 *str = p;
6361 /* M-profile MSR instructions have the mask field set to "10", except
6362 *PSR variants which modify APSR, which may use a different mask (and
6363 have been handled already). Do that by setting the PSR_f field
6364 here. */
6365 return psr->field | (lhs ? PSR_f : 0);
6366 }
6367 else
6368 goto unsupported_psr;
6369
6370 p += 4;
6371 check_suffix:
6372 if (*p == '_')
6373 {
6374 /* A suffix follows. */
6375 p++;
6376 start = p;
6377
6378 do
6379 p++;
6380 while (ISALNUM (*p) || *p == '_');
6381
6382 if (is_apsr)
6383 {
6384 /* APSR uses a notation for bits, rather than fields. */
6385 unsigned int nzcvq_bits = 0;
6386 unsigned int g_bit = 0;
6387 char *bit;
6388
6389 for (bit = start; bit != p; bit++)
6390 {
6391 switch (TOLOWER (*bit))
6392 {
6393 case 'n':
6394 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6395 break;
6396
6397 case 'z':
6398 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6399 break;
6400
6401 case 'c':
6402 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6403 break;
6404
6405 case 'v':
6406 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6407 break;
6408
6409 case 'q':
6410 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6411 break;
6412
6413 case 'g':
6414 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6415 break;
6416
6417 default:
6418 inst.error = _("unexpected bit specified after APSR");
6419 return FAIL;
6420 }
6421 }
6422
6423 if (nzcvq_bits == 0x1f)
6424 psr_field |= PSR_f;
6425
6426 if (g_bit == 0x1)
6427 {
6428 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
6429 {
6430 inst.error = _("selected processor does not "
6431 "support DSP extension");
6432 return FAIL;
6433 }
6434
6435 psr_field |= PSR_s;
6436 }
6437
6438 if ((nzcvq_bits & 0x20) != 0
6439 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6440 || (g_bit & 0x2) != 0)
6441 {
6442 inst.error = _("bad bitmask specified after APSR");
6443 return FAIL;
6444 }
6445 }
6446 else
6447 {
6448 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
6449 p - start);
6450 if (!psr)
6451 goto error;
6452
6453 psr_field |= psr->field;
6454 }
6455 }
6456 else
6457 {
6458 if (ISALNUM (*p))
6459 goto error; /* Garbage after "[CS]PSR". */
6460
6461 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6462 is deprecated, but allow it anyway. */
6463 if (is_apsr && lhs)
6464 {
6465 psr_field |= PSR_f;
6466 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6467 "deprecated"));
6468 }
6469 else if (!m_profile)
6470 /* These bits are never right for M-profile devices: don't set them
6471 (only code paths which read/write APSR reach here). */
6472 psr_field |= (PSR_c | PSR_f);
6473 }
6474 *str = p;
6475 return psr_field;
6476
6477 unsupported_psr:
6478 inst.error = _("selected processor does not support requested special "
6479 "purpose register");
6480 return FAIL;
6481
6482 error:
6483 inst.error = _("flag for {c}psr instruction expected");
6484 return FAIL;
6485 }
6486
6487 static int
6488 parse_sys_vldr_vstr (char **str)
6489 {
6490 unsigned i;
6491 int val = FAIL;
6492 struct {
6493 const char *name;
6494 int regl;
6495 int regh;
6496 } sysregs[] = {
6497 {"FPSCR", 0x1, 0x0},
6498 {"FPSCR_nzcvqc", 0x2, 0x0},
6499 {"VPR", 0x4, 0x1},
6500 {"P0", 0x5, 0x1},
6501 {"FPCXTNS", 0x6, 0x1},
6502 {"FPCXTS", 0x7, 0x1}
6503 };
6504 char *op_end = strchr (*str, ',');
6505 size_t op_strlen = op_end - *str;
6506
6507 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6508 {
6509 if (!strncmp (*str, sysregs[i].name, op_strlen))
6510 {
6511 val = sysregs[i].regl | (sysregs[i].regh << 3);
6512 *str = op_end;
6513 break;
6514 }
6515 }
6516
6517 return val;
6518 }
6519
6520 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6521 value suitable for splatting into the AIF field of the instruction. */
6522
6523 static int
6524 parse_cps_flags (char **str)
6525 {
6526 int val = 0;
6527 int saw_a_flag = 0;
6528 char *s = *str;
6529
6530 for (;;)
6531 switch (*s++)
6532 {
6533 case '\0': case ',':
6534 goto done;
6535
6536 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6537 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6538 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6539
6540 default:
6541 inst.error = _("unrecognized CPS flag");
6542 return FAIL;
6543 }
6544
6545 done:
6546 if (saw_a_flag == 0)
6547 {
6548 inst.error = _("missing CPS flags");
6549 return FAIL;
6550 }
6551
6552 *str = s - 1;
6553 return val;
6554 }
6555
6556 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6557 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6558
6559 static int
6560 parse_endian_specifier (char **str)
6561 {
6562 int little_endian;
6563 char *s = *str;
6564
6565 if (strncasecmp (s, "BE", 2))
6566 little_endian = 0;
6567 else if (strncasecmp (s, "LE", 2))
6568 little_endian = 1;
6569 else
6570 {
6571 inst.error = _("valid endian specifiers are be or le");
6572 return FAIL;
6573 }
6574
6575 if (ISALNUM (s[2]) || s[2] == '_')
6576 {
6577 inst.error = _("valid endian specifiers are be or le");
6578 return FAIL;
6579 }
6580
6581 *str = s + 2;
6582 return little_endian;
6583 }
6584
6585 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6586 value suitable for poking into the rotate field of an sxt or sxta
6587 instruction, or FAIL on error. */
6588
6589 static int
6590 parse_ror (char **str)
6591 {
6592 int rot;
6593 char *s = *str;
6594
6595 if (strncasecmp (s, "ROR", 3) == 0)
6596 s += 3;
6597 else
6598 {
6599 inst.error = _("missing rotation field after comma");
6600 return FAIL;
6601 }
6602
6603 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6604 return FAIL;
6605
6606 switch (rot)
6607 {
6608 case 0: *str = s; return 0x0;
6609 case 8: *str = s; return 0x1;
6610 case 16: *str = s; return 0x2;
6611 case 24: *str = s; return 0x3;
6612
6613 default:
6614 inst.error = _("rotation can only be 0, 8, 16, or 24");
6615 return FAIL;
6616 }
6617 }
6618
6619 /* Parse a conditional code (from conds[] below). The value returned is in the
6620 range 0 .. 14, or FAIL. */
6621 static int
6622 parse_cond (char **str)
6623 {
6624 char *q;
6625 const struct asm_cond *c;
6626 int n;
6627 /* Condition codes are always 2 characters, so matching up to
6628 3 characters is sufficient. */
6629 char cond[3];
6630
6631 q = *str;
6632 n = 0;
6633 while (ISALPHA (*q) && n < 3)
6634 {
6635 cond[n] = TOLOWER (*q);
6636 q++;
6637 n++;
6638 }
6639
6640 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6641 if (!c)
6642 {
6643 inst.error = _("condition required");
6644 return FAIL;
6645 }
6646
6647 *str = q;
6648 return c->value;
6649 }
6650
6651 /* Parse an option for a barrier instruction. Returns the encoding for the
6652 option, or FAIL. */
6653 static int
6654 parse_barrier (char **str)
6655 {
6656 char *p, *q;
6657 const struct asm_barrier_opt *o;
6658
6659 p = q = *str;
6660 while (ISALPHA (*q))
6661 q++;
6662
6663 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6664 q - p);
6665 if (!o)
6666 return FAIL;
6667
6668 if (!mark_feature_used (&o->arch))
6669 return FAIL;
6670
6671 *str = q;
6672 return o->value;
6673 }
6674
6675 /* Parse the operands of a table branch instruction. Similar to a memory
6676 operand. */
6677 static int
6678 parse_tb (char **str)
6679 {
6680 char * p = *str;
6681 int reg;
6682
6683 if (skip_past_char (&p, '[') == FAIL)
6684 {
6685 inst.error = _("'[' expected");
6686 return FAIL;
6687 }
6688
6689 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6690 {
6691 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6692 return FAIL;
6693 }
6694 inst.operands[0].reg = reg;
6695
6696 if (skip_past_comma (&p) == FAIL)
6697 {
6698 inst.error = _("',' expected");
6699 return FAIL;
6700 }
6701
6702 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6703 {
6704 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6705 return FAIL;
6706 }
6707 inst.operands[0].imm = reg;
6708
6709 if (skip_past_comma (&p) == SUCCESS)
6710 {
6711 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6712 return FAIL;
6713 if (inst.relocs[0].exp.X_add_number != 1)
6714 {
6715 inst.error = _("invalid shift");
6716 return FAIL;
6717 }
6718 inst.operands[0].shifted = 1;
6719 }
6720
6721 if (skip_past_char (&p, ']') == FAIL)
6722 {
6723 inst.error = _("']' expected");
6724 return FAIL;
6725 }
6726 *str = p;
6727 return SUCCESS;
6728 }
6729
6730 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6731 information on the types the operands can take and how they are encoded.
6732 Up to four operands may be read; this function handles setting the
6733 ".present" field for each read operand itself.
6734 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6735 else returns FAIL. */
6736
6737 static int
6738 parse_neon_mov (char **str, int *which_operand)
6739 {
6740 int i = *which_operand, val;
6741 enum arm_reg_type rtype;
6742 char *ptr = *str;
6743 struct neon_type_el optype;
6744
6745 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6746 {
6747 /* Cases 17 or 19. */
6748 inst.operands[i].reg = val;
6749 inst.operands[i].isvec = 1;
6750 inst.operands[i].isscalar = 2;
6751 inst.operands[i].vectype = optype;
6752 inst.operands[i++].present = 1;
6753
6754 if (skip_past_comma (&ptr) == FAIL)
6755 goto wanted_comma;
6756
6757 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6758 {
6759 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6760 inst.operands[i].reg = val;
6761 inst.operands[i].isreg = 1;
6762 inst.operands[i].present = 1;
6763 }
6764 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6765 {
6766 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6767 inst.operands[i].reg = val;
6768 inst.operands[i].isvec = 1;
6769 inst.operands[i].isscalar = 2;
6770 inst.operands[i].vectype = optype;
6771 inst.operands[i++].present = 1;
6772
6773 if (skip_past_comma (&ptr) == FAIL)
6774 goto wanted_comma;
6775
6776 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6777 goto wanted_arm;
6778
6779 inst.operands[i].reg = val;
6780 inst.operands[i].isreg = 1;
6781 inst.operands[i++].present = 1;
6782
6783 if (skip_past_comma (&ptr) == FAIL)
6784 goto wanted_comma;
6785
6786 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6787 goto wanted_arm;
6788
6789 inst.operands[i].reg = val;
6790 inst.operands[i].isreg = 1;
6791 inst.operands[i].present = 1;
6792 }
6793 else
6794 {
6795 first_error (_("expected ARM or MVE vector register"));
6796 return FAIL;
6797 }
6798 }
6799 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6800 {
6801 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6802 inst.operands[i].reg = val;
6803 inst.operands[i].isscalar = 1;
6804 inst.operands[i].vectype = optype;
6805 inst.operands[i++].present = 1;
6806
6807 if (skip_past_comma (&ptr) == FAIL)
6808 goto wanted_comma;
6809
6810 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6811 goto wanted_arm;
6812
6813 inst.operands[i].reg = val;
6814 inst.operands[i].isreg = 1;
6815 inst.operands[i].present = 1;
6816 }
6817 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6818 != FAIL)
6819 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6820 != FAIL))
6821 {
6822 /* Cases 0, 1, 2, 3, 5 (D only). */
6823 if (skip_past_comma (&ptr) == FAIL)
6824 goto wanted_comma;
6825
6826 inst.operands[i].reg = val;
6827 inst.operands[i].isreg = 1;
6828 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6829 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6830 inst.operands[i].isvec = 1;
6831 inst.operands[i].vectype = optype;
6832 inst.operands[i++].present = 1;
6833
6834 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6835 {
6836 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6837 Case 13: VMOV <Sd>, <Rm> */
6838 inst.operands[i].reg = val;
6839 inst.operands[i].isreg = 1;
6840 inst.operands[i].present = 1;
6841
6842 if (rtype == REG_TYPE_NQ)
6843 {
6844 first_error (_("can't use Neon quad register here"));
6845 return FAIL;
6846 }
6847 else if (rtype != REG_TYPE_VFS)
6848 {
6849 i++;
6850 if (skip_past_comma (&ptr) == FAIL)
6851 goto wanted_comma;
6852 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6853 goto wanted_arm;
6854 inst.operands[i].reg = val;
6855 inst.operands[i].isreg = 1;
6856 inst.operands[i].present = 1;
6857 }
6858 }
6859 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6860 &optype)) != FAIL)
6861 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6862 &optype)) != FAIL))
6863 {
6864 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6865 Case 1: VMOV<c><q> <Dd>, <Dm>
6866 Case 8: VMOV.F32 <Sd>, <Sm>
6867 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6868
6869 inst.operands[i].reg = val;
6870 inst.operands[i].isreg = 1;
6871 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6872 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6873 inst.operands[i].isvec = 1;
6874 inst.operands[i].vectype = optype;
6875 inst.operands[i].present = 1;
6876
6877 if (skip_past_comma (&ptr) == SUCCESS)
6878 {
6879 /* Case 15. */
6880 i++;
6881
6882 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6883 goto wanted_arm;
6884
6885 inst.operands[i].reg = val;
6886 inst.operands[i].isreg = 1;
6887 inst.operands[i++].present = 1;
6888
6889 if (skip_past_comma (&ptr) == FAIL)
6890 goto wanted_comma;
6891
6892 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6893 goto wanted_arm;
6894
6895 inst.operands[i].reg = val;
6896 inst.operands[i].isreg = 1;
6897 inst.operands[i].present = 1;
6898 }
6899 }
6900 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6901 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6902 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6903 Case 10: VMOV.F32 <Sd>, #<imm>
6904 Case 11: VMOV.F64 <Dd>, #<imm> */
6905 inst.operands[i].immisfloat = 1;
6906 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6907 == SUCCESS)
6908 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6909 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6910 ;
6911 else
6912 {
6913 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6914 return FAIL;
6915 }
6916 }
6917 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6918 {
6919 /* Cases 6, 7, 16, 18. */
6920 inst.operands[i].reg = val;
6921 inst.operands[i].isreg = 1;
6922 inst.operands[i++].present = 1;
6923
6924 if (skip_past_comma (&ptr) == FAIL)
6925 goto wanted_comma;
6926
6927 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6928 {
6929 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6930 inst.operands[i].reg = val;
6931 inst.operands[i].isscalar = 2;
6932 inst.operands[i].present = 1;
6933 inst.operands[i].vectype = optype;
6934 }
6935 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6936 {
6937 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6938 inst.operands[i].reg = val;
6939 inst.operands[i].isscalar = 1;
6940 inst.operands[i].present = 1;
6941 inst.operands[i].vectype = optype;
6942 }
6943 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6944 {
6945 inst.operands[i].reg = val;
6946 inst.operands[i].isreg = 1;
6947 inst.operands[i++].present = 1;
6948
6949 if (skip_past_comma (&ptr) == FAIL)
6950 goto wanted_comma;
6951
6952 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6953 != FAIL)
6954 {
6955 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6956
6957 inst.operands[i].reg = val;
6958 inst.operands[i].isreg = 1;
6959 inst.operands[i].isvec = 1;
6960 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6961 inst.operands[i].vectype = optype;
6962 inst.operands[i].present = 1;
6963
6964 if (rtype == REG_TYPE_VFS)
6965 {
6966 /* Case 14. */
6967 i++;
6968 if (skip_past_comma (&ptr) == FAIL)
6969 goto wanted_comma;
6970 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6971 &optype)) == FAIL)
6972 {
6973 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6974 return FAIL;
6975 }
6976 inst.operands[i].reg = val;
6977 inst.operands[i].isreg = 1;
6978 inst.operands[i].isvec = 1;
6979 inst.operands[i].issingle = 1;
6980 inst.operands[i].vectype = optype;
6981 inst.operands[i].present = 1;
6982 }
6983 }
6984 else
6985 {
6986 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6987 != FAIL)
6988 {
6989 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6990 inst.operands[i].reg = val;
6991 inst.operands[i].isvec = 1;
6992 inst.operands[i].isscalar = 2;
6993 inst.operands[i].vectype = optype;
6994 inst.operands[i++].present = 1;
6995
6996 if (skip_past_comma (&ptr) == FAIL)
6997 goto wanted_comma;
6998
6999 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
7000 == FAIL)
7001 {
7002 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
7003 return FAIL;
7004 }
7005 inst.operands[i].reg = val;
7006 inst.operands[i].isvec = 1;
7007 inst.operands[i].isscalar = 2;
7008 inst.operands[i].vectype = optype;
7009 inst.operands[i].present = 1;
7010 }
7011 else
7012 {
7013 first_error (_("VFP single, double or MVE vector register"
7014 " expected"));
7015 return FAIL;
7016 }
7017 }
7018 }
7019 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
7020 != FAIL)
7021 {
7022 /* Case 13. */
7023 inst.operands[i].reg = val;
7024 inst.operands[i].isreg = 1;
7025 inst.operands[i].isvec = 1;
7026 inst.operands[i].issingle = 1;
7027 inst.operands[i].vectype = optype;
7028 inst.operands[i].present = 1;
7029 }
7030 }
7031 else
7032 {
7033 first_error (_("parse error"));
7034 return FAIL;
7035 }
7036
7037 /* Successfully parsed the operands. Update args. */
7038 *which_operand = i;
7039 *str = ptr;
7040 return SUCCESS;
7041
7042 wanted_comma:
7043 first_error (_("expected comma"));
7044 return FAIL;
7045
7046 wanted_arm:
7047 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
7048 return FAIL;
7049 }
7050
7051 /* Use this macro when the operand constraints are different
7052 for ARM and THUMB (e.g. ldrd). */
7053 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7054 ((arm_operand) | ((thumb_operand) << 16))
7055
7056 /* Matcher codes for parse_operands. */
7057 enum operand_parse_code
7058 {
7059 OP_stop, /* end of line */
7060
7061 OP_RR, /* ARM register */
7062 OP_RRnpc, /* ARM register, not r15 */
7063 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
7064 OP_RRnpcb, /* ARM register, not r15, in square brackets */
7065 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
7066 optional trailing ! */
7067 OP_RRw, /* ARM register, not r15, optional trailing ! */
7068 OP_RCP, /* Coprocessor number */
7069 OP_RCN, /* Coprocessor register */
7070 OP_RF, /* FPA register */
7071 OP_RVS, /* VFP single precision register */
7072 OP_RVD, /* VFP double precision register (0..15) */
7073 OP_RND, /* Neon double precision register (0..31) */
7074 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7075 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7076 */
7077 OP_RNQ, /* Neon quad precision register */
7078 OP_RNQMQ, /* Neon quad or MVE vector register. */
7079 OP_RVSD, /* VFP single or double precision register */
7080 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
7081 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
7082 OP_RNSD, /* Neon single or double precision register */
7083 OP_RNDQ, /* Neon double or quad precision register */
7084 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7085 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
7086 OP_RNSDQ, /* Neon single, double or quad precision register */
7087 OP_RNSC, /* Neon scalar D[X] */
7088 OP_RVC, /* VFP control register */
7089 OP_RMF, /* Maverick F register */
7090 OP_RMD, /* Maverick D register */
7091 OP_RMFX, /* Maverick FX register */
7092 OP_RMDX, /* Maverick DX register */
7093 OP_RMAX, /* Maverick AX register */
7094 OP_RMDS, /* Maverick DSPSC register */
7095 OP_RIWR, /* iWMMXt wR register */
7096 OP_RIWC, /* iWMMXt wC register */
7097 OP_RIWG, /* iWMMXt wCG register */
7098 OP_RXA, /* XScale accumulator register */
7099
7100 OP_RNSDMQ, /* Neon single, double or MVE vector register */
7101 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7102 */
7103 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7104 GPR (no SP/SP) */
7105 OP_RMQ, /* MVE vector register. */
7106 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
7107 OP_RMQRR, /* MVE vector or ARM register. */
7108
7109 /* New operands for Armv8.1-M Mainline. */
7110 OP_LR, /* ARM LR register */
7111 OP_RRe, /* ARM register, only even numbered. */
7112 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
7113 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
7114 OP_RR_ZR, /* ARM register or ZR but no PC */
7115
7116 OP_REGLST, /* ARM register list */
7117 OP_CLRMLST, /* CLRM register list */
7118 OP_VRSLST, /* VFP single-precision register list */
7119 OP_VRDLST, /* VFP double-precision register list */
7120 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
7121 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7122 OP_NSTRLST, /* Neon element/structure list */
7123 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
7124 OP_MSTRLST2, /* MVE vector list with two elements. */
7125 OP_MSTRLST4, /* MVE vector list with four elements. */
7126
7127 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
7128 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
7129 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
7130 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7131 zero. */
7132 OP_RR_RNSC, /* ARM reg or Neon scalar. */
7133 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
7134 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
7135 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7136 */
7137 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7138 scalar, or ARM register. */
7139 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
7140 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7141 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7142 register. */
7143 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
7144 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7145 OP_VMOV, /* Neon VMOV operands. */
7146 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
7147 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7148 OP_RNDQMQ_Ibig,
7149 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
7150 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7151 ARM register. */
7152 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
7153 OP_VLDR, /* VLDR operand. */
7154
7155 OP_I0, /* immediate zero */
7156 OP_I7, /* immediate value 0 .. 7 */
7157 OP_I15, /* 0 .. 15 */
7158 OP_I16, /* 1 .. 16 */
7159 OP_I16z, /* 0 .. 16 */
7160 OP_I31, /* 0 .. 31 */
7161 OP_I31w, /* 0 .. 31, optional trailing ! */
7162 OP_I32, /* 1 .. 32 */
7163 OP_I32z, /* 0 .. 32 */
7164 OP_I48_I64, /* 48 or 64 */
7165 OP_I63, /* 0 .. 63 */
7166 OP_I63s, /* -64 .. 63 */
7167 OP_I64, /* 1 .. 64 */
7168 OP_I64z, /* 0 .. 64 */
7169 OP_I127, /* 0 .. 127 */
7170 OP_I255, /* 0 .. 255 */
7171 OP_I511, /* 0 .. 511 */
7172 OP_I4095, /* 0 .. 4095 */
7173 OP_I8191, /* 0 .. 8191 */
7174 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7175 OP_I7b, /* 0 .. 7 */
7176 OP_I15b, /* 0 .. 15 */
7177 OP_I31b, /* 0 .. 31 */
7178
7179 OP_SH, /* shifter operand */
7180 OP_SHG, /* shifter operand with possible group relocation */
7181 OP_ADDR, /* Memory address expression (any mode) */
7182 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
7183 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7184 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7185 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
7186 OP_EXP, /* arbitrary expression */
7187 OP_EXPi, /* same, with optional immediate prefix */
7188 OP_EXPr, /* same, with optional relocation suffix */
7189 OP_EXPs, /* same, with optional non-first operand relocation suffix */
7190 OP_HALF, /* 0 .. 65535 or low/high reloc. */
7191 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7192 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
7193
7194 OP_CPSF, /* CPS flags */
7195 OP_ENDI, /* Endianness specifier */
7196 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7197 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
7198 OP_COND, /* conditional code */
7199 OP_TB, /* Table branch. */
7200
7201 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7202
7203 OP_RRnpc_I0, /* ARM register or literal 0 */
7204 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
7205 OP_RR_EXi, /* ARM register or expression with imm prefix */
7206 OP_RF_IF, /* FPA register or immediate */
7207 OP_RIWR_RIWC, /* iWMMXt R or C reg */
7208 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
7209
7210 /* Optional operands. */
7211 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7212 OP_oI31b, /* 0 .. 31 */
7213 OP_oI32b, /* 1 .. 32 */
7214 OP_oI32z, /* 0 .. 32 */
7215 OP_oIffffb, /* 0 .. 65535 */
7216 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7217
7218 OP_oRR, /* ARM register */
7219 OP_oLR, /* ARM LR register */
7220 OP_oRRnpc, /* ARM register, not the PC */
7221 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
7222 OP_oRRw, /* ARM register, not r15, optional trailing ! */
7223 OP_oRND, /* Optional Neon double precision register */
7224 OP_oRNQ, /* Optional Neon quad precision register */
7225 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
7226 OP_oRNDQ, /* Optional Neon double or quad precision register */
7227 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
7228 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7229 register. */
7230 OP_oSHll, /* LSL immediate */
7231 OP_oSHar, /* ASR immediate */
7232 OP_oSHllar, /* LSL or ASR immediate */
7233 OP_oROR, /* ROR 0/8/16/24 */
7234 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
7235
7236 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7237
7238 /* Some pre-defined mixed (ARM/THUMB) operands. */
7239 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7240 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7241 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7242
7243 OP_FIRST_OPTIONAL = OP_oI7b
7244 };
7245
7246 /* Generic instruction operand parser. This does no encoding and no
7247 semantic validation; it merely squirrels values away in the inst
7248 structure. Returns SUCCESS or FAIL depending on whether the
7249 specified grammar matched. */
7250 static int
7251 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
7252 {
7253 unsigned const int *upat = pattern;
7254 char *backtrack_pos = 0;
7255 const char *backtrack_error = 0;
7256 int i, val = 0, backtrack_index = 0;
7257 enum arm_reg_type rtype;
7258 parse_operand_result result;
7259 unsigned int op_parse_code;
7260 bfd_boolean partial_match;
7261
7262 #define po_char_or_fail(chr) \
7263 do \
7264 { \
7265 if (skip_past_char (&str, chr) == FAIL) \
7266 goto bad_args; \
7267 } \
7268 while (0)
7269
7270 #define po_reg_or_fail(regtype) \
7271 do \
7272 { \
7273 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7274 & inst.operands[i].vectype); \
7275 if (val == FAIL) \
7276 { \
7277 first_error (_(reg_expected_msgs[regtype])); \
7278 goto failure; \
7279 } \
7280 inst.operands[i].reg = val; \
7281 inst.operands[i].isreg = 1; \
7282 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7283 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7284 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7285 || rtype == REG_TYPE_VFD \
7286 || rtype == REG_TYPE_NQ); \
7287 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7288 } \
7289 while (0)
7290
7291 #define po_reg_or_goto(regtype, label) \
7292 do \
7293 { \
7294 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7295 & inst.operands[i].vectype); \
7296 if (val == FAIL) \
7297 goto label; \
7298 \
7299 inst.operands[i].reg = val; \
7300 inst.operands[i].isreg = 1; \
7301 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7302 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7303 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7304 || rtype == REG_TYPE_VFD \
7305 || rtype == REG_TYPE_NQ); \
7306 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7307 } \
7308 while (0)
7309
7310 #define po_imm_or_fail(min, max, popt) \
7311 do \
7312 { \
7313 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7314 goto failure; \
7315 inst.operands[i].imm = val; \
7316 } \
7317 while (0)
7318
7319 #define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7320 do \
7321 { \
7322 expressionS exp; \
7323 my_get_expression (&exp, &str, popt); \
7324 if (exp.X_op != O_constant) \
7325 { \
7326 inst.error = _("constant expression required"); \
7327 goto failure; \
7328 } \
7329 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7330 { \
7331 inst.error = _("immediate value 48 or 64 expected"); \
7332 goto failure; \
7333 } \
7334 inst.operands[i].imm = exp.X_add_number; \
7335 } \
7336 while (0)
7337
7338 #define po_scalar_or_goto(elsz, label, reg_type) \
7339 do \
7340 { \
7341 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7342 reg_type); \
7343 if (val == FAIL) \
7344 goto label; \
7345 inst.operands[i].reg = val; \
7346 inst.operands[i].isscalar = 1; \
7347 } \
7348 while (0)
7349
7350 #define po_misc_or_fail(expr) \
7351 do \
7352 { \
7353 if (expr) \
7354 goto failure; \
7355 } \
7356 while (0)
7357
7358 #define po_misc_or_fail_no_backtrack(expr) \
7359 do \
7360 { \
7361 result = expr; \
7362 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7363 backtrack_pos = 0; \
7364 if (result != PARSE_OPERAND_SUCCESS) \
7365 goto failure; \
7366 } \
7367 while (0)
7368
7369 #define po_barrier_or_imm(str) \
7370 do \
7371 { \
7372 val = parse_barrier (&str); \
7373 if (val == FAIL && ! ISALPHA (*str)) \
7374 goto immediate; \
7375 if (val == FAIL \
7376 /* ISB can only take SY as an option. */ \
7377 || ((inst.instruction & 0xf0) == 0x60 \
7378 && val != 0xf)) \
7379 { \
7380 inst.error = _("invalid barrier type"); \
7381 backtrack_pos = 0; \
7382 goto failure; \
7383 } \
7384 } \
7385 while (0)
7386
7387 skip_whitespace (str);
7388
7389 for (i = 0; upat[i] != OP_stop; i++)
7390 {
7391 op_parse_code = upat[i];
7392 if (op_parse_code >= 1<<16)
7393 op_parse_code = thumb ? (op_parse_code >> 16)
7394 : (op_parse_code & ((1<<16)-1));
7395
7396 if (op_parse_code >= OP_FIRST_OPTIONAL)
7397 {
7398 /* Remember where we are in case we need to backtrack. */
7399 backtrack_pos = str;
7400 backtrack_error = inst.error;
7401 backtrack_index = i;
7402 }
7403
7404 if (i > 0 && (i > 1 || inst.operands[0].present))
7405 po_char_or_fail (',');
7406
7407 switch (op_parse_code)
7408 {
7409 /* Registers */
7410 case OP_oRRnpc:
7411 case OP_oRRnpcsp:
7412 case OP_RRnpc:
7413 case OP_RRnpcsp:
7414 case OP_oRR:
7415 case OP_RRe:
7416 case OP_RRo:
7417 case OP_LR:
7418 case OP_oLR:
7419 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7420 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7421 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7422 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7423 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7424 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
7425 case OP_oRND:
7426 case OP_RNDMQR:
7427 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7428 break;
7429 try_rndmq:
7430 case OP_RNDMQ:
7431 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7432 break;
7433 try_rnd:
7434 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
7435 case OP_RVC:
7436 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7437 break;
7438 /* Also accept generic coprocessor regs for unknown registers. */
7439 coproc_reg:
7440 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7441 break;
7442 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7443 existing register with a value of 0, this seems like the
7444 best way to parse P0. */
7445 vpr_po:
7446 if (strncasecmp (str, "P0", 2) == 0)
7447 {
7448 str += 2;
7449 inst.operands[i].isreg = 1;
7450 inst.operands[i].reg = 13;
7451 }
7452 else
7453 goto failure;
7454 break;
7455 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7456 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7457 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7458 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7459 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7460 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7461 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7462 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7463 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7464 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
7465 case OP_oRNQ:
7466 case OP_RNQMQ:
7467 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7468 break;
7469 try_nq:
7470 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
7471 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7472 case OP_RNDQMQR:
7473 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7474 break;
7475 try_rndqmq:
7476 case OP_oRNDQMQ:
7477 case OP_RNDQMQ:
7478 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7479 break;
7480 try_rndq:
7481 case OP_oRNDQ:
7482 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
7483 case OP_RVSDMQ:
7484 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7485 break;
7486 try_rvsd:
7487 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7488 case OP_RVSD_COND:
7489 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7490 break;
7491 case OP_RNSDMQ:
7492 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7493 break;
7494 try_mq2:
7495 po_reg_or_fail (REG_TYPE_MQ);
7496 break;
7497 case OP_oRNSDQ:
7498 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
7499 case OP_RNSDQMQR:
7500 po_reg_or_goto (REG_TYPE_RN, try_mq);
7501 break;
7502 try_mq:
7503 case OP_oRNSDQMQ:
7504 case OP_RNSDQMQ:
7505 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7506 break;
7507 try_nsdq2:
7508 po_reg_or_fail (REG_TYPE_NSDQ);
7509 inst.error = 0;
7510 break;
7511 case OP_RMQRR:
7512 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7513 break;
7514 try_rmq:
7515 case OP_RMQ:
7516 po_reg_or_fail (REG_TYPE_MQ);
7517 break;
7518 /* Neon scalar. Using an element size of 8 means that some invalid
7519 scalars are accepted here, so deal with those in later code. */
7520 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
7521
7522 case OP_RNDQ_I0:
7523 {
7524 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7525 break;
7526 try_imm0:
7527 po_imm_or_fail (0, 0, TRUE);
7528 }
7529 break;
7530
7531 case OP_RVSD_I0:
7532 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7533 break;
7534
7535 case OP_RSVDMQ_FI0:
7536 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7537 break;
7538 try_rsvd_fi0:
7539 case OP_RSVD_FI0:
7540 {
7541 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7542 break;
7543 try_ifimm0:
7544 if (parse_ifimm_zero (&str))
7545 inst.operands[i].imm = 0;
7546 else
7547 {
7548 inst.error
7549 = _("only floating point zero is allowed as immediate value");
7550 goto failure;
7551 }
7552 }
7553 break;
7554
7555 case OP_RR_RNSC:
7556 {
7557 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
7558 break;
7559 try_rr:
7560 po_reg_or_fail (REG_TYPE_RN);
7561 }
7562 break;
7563
7564 case OP_RNSDQ_RNSC_MQ_RR:
7565 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7566 break;
7567 try_rnsdq_rnsc_mq:
7568 case OP_RNSDQ_RNSC_MQ:
7569 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7570 break;
7571 try_rnsdq_rnsc:
7572 case OP_RNSDQ_RNSC:
7573 {
7574 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7575 inst.error = 0;
7576 break;
7577 try_nsdq:
7578 po_reg_or_fail (REG_TYPE_NSDQ);
7579 inst.error = 0;
7580 }
7581 break;
7582
7583 case OP_RNSD_RNSC:
7584 {
7585 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
7586 break;
7587 try_s_scalar:
7588 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
7589 break;
7590 try_nsd:
7591 po_reg_or_fail (REG_TYPE_NSD);
7592 }
7593 break;
7594
7595 case OP_RNDQMQ_RNSC_RR:
7596 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7597 break;
7598 try_rndq_rnsc_rr:
7599 case OP_RNDQ_RNSC_RR:
7600 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7601 break;
7602 case OP_RNDQMQ_RNSC:
7603 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7604 break;
7605 try_rndq_rnsc:
7606 case OP_RNDQ_RNSC:
7607 {
7608 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
7609 break;
7610 try_ndq:
7611 po_reg_or_fail (REG_TYPE_NDQ);
7612 }
7613 break;
7614
7615 case OP_RND_RNSC:
7616 {
7617 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
7618 break;
7619 try_vfd:
7620 po_reg_or_fail (REG_TYPE_VFD);
7621 }
7622 break;
7623
7624 case OP_VMOV:
7625 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7626 not careful then bad things might happen. */
7627 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7628 break;
7629
7630 case OP_RNDQMQ_Ibig:
7631 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7632 break;
7633 try_rndq_ibig:
7634 case OP_RNDQ_Ibig:
7635 {
7636 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7637 break;
7638 try_immbig:
7639 /* There's a possibility of getting a 64-bit immediate here, so
7640 we need special handling. */
7641 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7642 == FAIL)
7643 {
7644 inst.error = _("immediate value is out of range");
7645 goto failure;
7646 }
7647 }
7648 break;
7649
7650 case OP_RNDQMQ_I63b_RR:
7651 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7652 break;
7653 try_rndq_i63b_rr:
7654 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7655 break;
7656 try_rndq_i63b:
7657 case OP_RNDQ_I63b:
7658 {
7659 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7660 break;
7661 try_shimm:
7662 po_imm_or_fail (0, 63, TRUE);
7663 }
7664 break;
7665
7666 case OP_RRnpcb:
7667 po_char_or_fail ('[');
7668 po_reg_or_fail (REG_TYPE_RN);
7669 po_char_or_fail (']');
7670 break;
7671
7672 case OP_RRnpctw:
7673 case OP_RRw:
7674 case OP_oRRw:
7675 po_reg_or_fail (REG_TYPE_RN);
7676 if (skip_past_char (&str, '!') == SUCCESS)
7677 inst.operands[i].writeback = 1;
7678 break;
7679
7680 /* Immediates */
7681 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7682 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7683 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
7684 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
7685 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7686 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
7687 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
7688 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
7689 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
7690 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7691 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7692 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
7693 case OP_I127: po_imm_or_fail ( 0, 127, FALSE); break;
7694 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
7695 case OP_I511: po_imm_or_fail ( 0, 511, FALSE); break;
7696 case OP_I4095: po_imm_or_fail ( 0, 4095, FALSE); break;
7697 case OP_I8191: po_imm_or_fail ( 0, 8191, FALSE); break;
7698 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7699 case OP_oI7b:
7700 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7701 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7702 case OP_oI31b:
7703 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
7704 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7705 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
7706 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7707
7708 /* Immediate variants */
7709 case OP_oI255c:
7710 po_char_or_fail ('{');
7711 po_imm_or_fail (0, 255, TRUE);
7712 po_char_or_fail ('}');
7713 break;
7714
7715 case OP_I31w:
7716 /* The expression parser chokes on a trailing !, so we have
7717 to find it first and zap it. */
7718 {
7719 char *s = str;
7720 while (*s && *s != ',')
7721 s++;
7722 if (s[-1] == '!')
7723 {
7724 s[-1] = '\0';
7725 inst.operands[i].writeback = 1;
7726 }
7727 po_imm_or_fail (0, 31, TRUE);
7728 if (str == s - 1)
7729 str = s;
7730 }
7731 break;
7732
7733 /* Expressions */
7734 case OP_EXPi: EXPi:
7735 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7736 GE_OPT_PREFIX));
7737 break;
7738
7739 case OP_EXP:
7740 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7741 GE_NO_PREFIX));
7742 break;
7743
7744 case OP_EXPr: EXPr:
7745 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7746 GE_NO_PREFIX));
7747 if (inst.relocs[0].exp.X_op == O_symbol)
7748 {
7749 val = parse_reloc (&str);
7750 if (val == -1)
7751 {
7752 inst.error = _("unrecognized relocation suffix");
7753 goto failure;
7754 }
7755 else if (val != BFD_RELOC_UNUSED)
7756 {
7757 inst.operands[i].imm = val;
7758 inst.operands[i].hasreloc = 1;
7759 }
7760 }
7761 break;
7762
7763 case OP_EXPs:
7764 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7765 GE_NO_PREFIX));
7766 if (inst.relocs[i].exp.X_op == O_symbol)
7767 {
7768 inst.operands[i].hasreloc = 1;
7769 }
7770 else if (inst.relocs[i].exp.X_op == O_constant)
7771 {
7772 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7773 inst.operands[i].hasreloc = 0;
7774 }
7775 break;
7776
7777 /* Operand for MOVW or MOVT. */
7778 case OP_HALF:
7779 po_misc_or_fail (parse_half (&str));
7780 break;
7781
7782 /* Register or expression. */
7783 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7784 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7785
7786 /* Register or immediate. */
7787 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7788 I0: po_imm_or_fail (0, 0, FALSE); break;
7789
7790 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7791 I32: po_imm_or_fail (1, 32, FALSE); break;
7792
7793 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7794 IF:
7795 if (!is_immediate_prefix (*str))
7796 goto bad_args;
7797 str++;
7798 val = parse_fpa_immediate (&str);
7799 if (val == FAIL)
7800 goto failure;
7801 /* FPA immediates are encoded as registers 8-15.
7802 parse_fpa_immediate has already applied the offset. */
7803 inst.operands[i].reg = val;
7804 inst.operands[i].isreg = 1;
7805 break;
7806
7807 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7808 I32z: po_imm_or_fail (0, 32, FALSE); break;
7809
7810 /* Two kinds of register. */
7811 case OP_RIWR_RIWC:
7812 {
7813 struct reg_entry *rege = arm_reg_parse_multi (&str);
7814 if (!rege
7815 || (rege->type != REG_TYPE_MMXWR
7816 && rege->type != REG_TYPE_MMXWC
7817 && rege->type != REG_TYPE_MMXWCG))
7818 {
7819 inst.error = _("iWMMXt data or control register expected");
7820 goto failure;
7821 }
7822 inst.operands[i].reg = rege->number;
7823 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7824 }
7825 break;
7826
7827 case OP_RIWC_RIWG:
7828 {
7829 struct reg_entry *rege = arm_reg_parse_multi (&str);
7830 if (!rege
7831 || (rege->type != REG_TYPE_MMXWC
7832 && rege->type != REG_TYPE_MMXWCG))
7833 {
7834 inst.error = _("iWMMXt control register expected");
7835 goto failure;
7836 }
7837 inst.operands[i].reg = rege->number;
7838 inst.operands[i].isreg = 1;
7839 }
7840 break;
7841
7842 /* Misc */
7843 case OP_CPSF: val = parse_cps_flags (&str); break;
7844 case OP_ENDI: val = parse_endian_specifier (&str); break;
7845 case OP_oROR: val = parse_ror (&str); break;
7846 try_cond:
7847 case OP_COND: val = parse_cond (&str); break;
7848 case OP_oBARRIER_I15:
7849 po_barrier_or_imm (str); break;
7850 immediate:
7851 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
7852 goto failure;
7853 break;
7854
7855 case OP_wPSR:
7856 case OP_rPSR:
7857 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7858 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7859 {
7860 inst.error = _("Banked registers are not available with this "
7861 "architecture.");
7862 goto failure;
7863 }
7864 break;
7865 try_psr:
7866 val = parse_psr (&str, op_parse_code == OP_wPSR);
7867 break;
7868
7869 case OP_VLDR:
7870 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7871 break;
7872 try_sysreg:
7873 val = parse_sys_vldr_vstr (&str);
7874 break;
7875
7876 case OP_APSR_RR:
7877 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7878 break;
7879 try_apsr:
7880 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7881 instruction). */
7882 if (strncasecmp (str, "APSR_", 5) == 0)
7883 {
7884 unsigned found = 0;
7885 str += 5;
7886 while (found < 15)
7887 switch (*str++)
7888 {
7889 case 'c': found = (found & 1) ? 16 : found | 1; break;
7890 case 'n': found = (found & 2) ? 16 : found | 2; break;
7891 case 'z': found = (found & 4) ? 16 : found | 4; break;
7892 case 'v': found = (found & 8) ? 16 : found | 8; break;
7893 default: found = 16;
7894 }
7895 if (found != 15)
7896 goto failure;
7897 inst.operands[i].isvec = 1;
7898 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7899 inst.operands[i].reg = REG_PC;
7900 }
7901 else
7902 goto failure;
7903 break;
7904
7905 case OP_TB:
7906 po_misc_or_fail (parse_tb (&str));
7907 break;
7908
7909 /* Register lists. */
7910 case OP_REGLST:
7911 val = parse_reg_list (&str, REGLIST_RN);
7912 if (*str == '^')
7913 {
7914 inst.operands[i].writeback = 1;
7915 str++;
7916 }
7917 break;
7918
7919 case OP_CLRMLST:
7920 val = parse_reg_list (&str, REGLIST_CLRM);
7921 break;
7922
7923 case OP_VRSLST:
7924 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7925 &partial_match);
7926 break;
7927
7928 case OP_VRDLST:
7929 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7930 &partial_match);
7931 break;
7932
7933 case OP_VRSDLST:
7934 /* Allow Q registers too. */
7935 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7936 REGLIST_NEON_D, &partial_match);
7937 if (val == FAIL)
7938 {
7939 inst.error = NULL;
7940 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7941 REGLIST_VFP_S, &partial_match);
7942 inst.operands[i].issingle = 1;
7943 }
7944 break;
7945
7946 case OP_VRSDVLST:
7947 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7948 REGLIST_VFP_D_VPR, &partial_match);
7949 if (val == FAIL && !partial_match)
7950 {
7951 inst.error = NULL;
7952 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7953 REGLIST_VFP_S_VPR, &partial_match);
7954 inst.operands[i].issingle = 1;
7955 }
7956 break;
7957
7958 case OP_NRDLST:
7959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7960 REGLIST_NEON_D, &partial_match);
7961 break;
7962
7963 case OP_MSTRLST4:
7964 case OP_MSTRLST2:
7965 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7966 1, &inst.operands[i].vectype);
7967 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7968 goto failure;
7969 break;
7970 case OP_NSTRLST:
7971 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7972 0, &inst.operands[i].vectype);
7973 break;
7974
7975 /* Addressing modes */
7976 case OP_ADDRMVE:
7977 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7978 break;
7979
7980 case OP_ADDR:
7981 po_misc_or_fail (parse_address (&str, i));
7982 break;
7983
7984 case OP_ADDRGLDR:
7985 po_misc_or_fail_no_backtrack (
7986 parse_address_group_reloc (&str, i, GROUP_LDR));
7987 break;
7988
7989 case OP_ADDRGLDRS:
7990 po_misc_or_fail_no_backtrack (
7991 parse_address_group_reloc (&str, i, GROUP_LDRS));
7992 break;
7993
7994 case OP_ADDRGLDC:
7995 po_misc_or_fail_no_backtrack (
7996 parse_address_group_reloc (&str, i, GROUP_LDC));
7997 break;
7998
7999 case OP_SH:
8000 po_misc_or_fail (parse_shifter_operand (&str, i));
8001 break;
8002
8003 case OP_SHG:
8004 po_misc_or_fail_no_backtrack (
8005 parse_shifter_operand_group_reloc (&str, i));
8006 break;
8007
8008 case OP_oSHll:
8009 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
8010 break;
8011
8012 case OP_oSHar:
8013 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
8014 break;
8015
8016 case OP_oSHllar:
8017 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
8018 break;
8019
8020 case OP_RMQRZ:
8021 case OP_oRMQRZ:
8022 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8023 break;
8024
8025 case OP_RR_ZR:
8026 try_rr_zr:
8027 po_reg_or_goto (REG_TYPE_RN, ZR);
8028 break;
8029 ZR:
8030 po_reg_or_fail (REG_TYPE_ZR);
8031 break;
8032
8033 default:
8034 as_fatal (_("unhandled operand code %d"), op_parse_code);
8035 }
8036
8037 /* Various value-based sanity checks and shared operations. We
8038 do not signal immediate failures for the register constraints;
8039 this allows a syntax error to take precedence. */
8040 switch (op_parse_code)
8041 {
8042 case OP_oRRnpc:
8043 case OP_RRnpc:
8044 case OP_RRnpcb:
8045 case OP_RRw:
8046 case OP_oRRw:
8047 case OP_RRnpc_I0:
8048 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8049 inst.error = BAD_PC;
8050 break;
8051
8052 case OP_oRRnpcsp:
8053 case OP_RRnpcsp:
8054 case OP_RRnpcsp_I32:
8055 if (inst.operands[i].isreg)
8056 {
8057 if (inst.operands[i].reg == REG_PC)
8058 inst.error = BAD_PC;
8059 else if (inst.operands[i].reg == REG_SP
8060 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8061 relaxed since ARMv8-A. */
8062 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8063 {
8064 gas_assert (thumb);
8065 inst.error = BAD_SP;
8066 }
8067 }
8068 break;
8069
8070 case OP_RRnpctw:
8071 if (inst.operands[i].isreg
8072 && inst.operands[i].reg == REG_PC
8073 && (inst.operands[i].writeback || thumb))
8074 inst.error = BAD_PC;
8075 break;
8076
8077 case OP_RVSD_COND:
8078 case OP_VLDR:
8079 if (inst.operands[i].isreg)
8080 break;
8081 /* fall through. */
8082
8083 case OP_CPSF:
8084 case OP_ENDI:
8085 case OP_oROR:
8086 case OP_wPSR:
8087 case OP_rPSR:
8088 case OP_COND:
8089 case OP_oBARRIER_I15:
8090 case OP_REGLST:
8091 case OP_CLRMLST:
8092 case OP_VRSLST:
8093 case OP_VRDLST:
8094 case OP_VRSDLST:
8095 case OP_VRSDVLST:
8096 case OP_NRDLST:
8097 case OP_NSTRLST:
8098 case OP_MSTRLST2:
8099 case OP_MSTRLST4:
8100 if (val == FAIL)
8101 goto failure;
8102 inst.operands[i].imm = val;
8103 break;
8104
8105 case OP_LR:
8106 case OP_oLR:
8107 if (inst.operands[i].reg != REG_LR)
8108 inst.error = _("operand must be LR register");
8109 break;
8110
8111 case OP_RMQRZ:
8112 case OP_oRMQRZ:
8113 case OP_RR_ZR:
8114 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8115 inst.error = BAD_PC;
8116 break;
8117
8118 case OP_RRe:
8119 if (inst.operands[i].isreg
8120 && (inst.operands[i].reg & 0x00000001) != 0)
8121 inst.error = BAD_ODD;
8122 break;
8123
8124 case OP_RRo:
8125 if (inst.operands[i].isreg)
8126 {
8127 if ((inst.operands[i].reg & 0x00000001) != 1)
8128 inst.error = BAD_EVEN;
8129 else if (inst.operands[i].reg == REG_SP)
8130 as_tsktsk (MVE_BAD_SP);
8131 else if (inst.operands[i].reg == REG_PC)
8132 inst.error = BAD_PC;
8133 }
8134 break;
8135
8136 default:
8137 break;
8138 }
8139
8140 /* If we get here, this operand was successfully parsed. */
8141 inst.operands[i].present = 1;
8142 continue;
8143
8144 bad_args:
8145 inst.error = BAD_ARGS;
8146
8147 failure:
8148 if (!backtrack_pos)
8149 {
8150 /* The parse routine should already have set inst.error, but set a
8151 default here just in case. */
8152 if (!inst.error)
8153 inst.error = BAD_SYNTAX;
8154 return FAIL;
8155 }
8156
8157 /* Do not backtrack over a trailing optional argument that
8158 absorbed some text. We will only fail again, with the
8159 'garbage following instruction' error message, which is
8160 probably less helpful than the current one. */
8161 if (backtrack_index == i && backtrack_pos != str
8162 && upat[i+1] == OP_stop)
8163 {
8164 if (!inst.error)
8165 inst.error = BAD_SYNTAX;
8166 return FAIL;
8167 }
8168
8169 /* Try again, skipping the optional argument at backtrack_pos. */
8170 str = backtrack_pos;
8171 inst.error = backtrack_error;
8172 inst.operands[backtrack_index].present = 0;
8173 i = backtrack_index;
8174 backtrack_pos = 0;
8175 }
8176
8177 /* Check that we have parsed all the arguments. */
8178 if (*str != '\0' && !inst.error)
8179 inst.error = _("garbage following instruction");
8180
8181 return inst.error ? FAIL : SUCCESS;
8182 }
8183
8184 #undef po_char_or_fail
8185 #undef po_reg_or_fail
8186 #undef po_reg_or_goto
8187 #undef po_imm_or_fail
8188 #undef po_scalar_or_fail
8189 #undef po_barrier_or_imm
8190
8191 /* Shorthand macro for instruction encoding functions issuing errors. */
8192 #define constraint(expr, err) \
8193 do \
8194 { \
8195 if (expr) \
8196 { \
8197 inst.error = err; \
8198 return; \
8199 } \
8200 } \
8201 while (0)
8202
8203 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8204 instructions are unpredictable if these registers are used. This
8205 is the BadReg predicate in ARM's Thumb-2 documentation.
8206
8207 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8208 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8209 #define reject_bad_reg(reg) \
8210 do \
8211 if (reg == REG_PC) \
8212 { \
8213 inst.error = BAD_PC; \
8214 return; \
8215 } \
8216 else if (reg == REG_SP \
8217 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8218 { \
8219 inst.error = BAD_SP; \
8220 return; \
8221 } \
8222 while (0)
8223
8224 /* If REG is R13 (the stack pointer), warn that its use is
8225 deprecated. */
8226 #define warn_deprecated_sp(reg) \
8227 do \
8228 if (warn_on_deprecated && reg == REG_SP) \
8229 as_tsktsk (_("use of r13 is deprecated")); \
8230 while (0)
8231
8232 /* Functions for operand encoding. ARM, then Thumb. */
8233
8234 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
8235
8236 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8237
8238 The only binary encoding difference is the Coprocessor number. Coprocessor
8239 9 is used for half-precision calculations or conversions. The format of the
8240 instruction is the same as the equivalent Coprocessor 10 instruction that
8241 exists for Single-Precision operation. */
8242
8243 static void
8244 do_scalar_fp16_v82_encode (void)
8245 {
8246 if (inst.cond < COND_ALWAYS)
8247 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8248 " the behaviour is UNPREDICTABLE"));
8249 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8250 _(BAD_FP16));
8251
8252 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8253 mark_feature_used (&arm_ext_fp16);
8254 }
8255
8256 /* If VAL can be encoded in the immediate field of an ARM instruction,
8257 return the encoded form. Otherwise, return FAIL. */
8258
8259 static unsigned int
8260 encode_arm_immediate (unsigned int val)
8261 {
8262 unsigned int a, i;
8263
8264 if (val <= 0xff)
8265 return val;
8266
8267 for (i = 2; i < 32; i += 2)
8268 if ((a = rotate_left (val, i)) <= 0xff)
8269 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8270
8271 return FAIL;
8272 }
8273
8274 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8275 return the encoded form. Otherwise, return FAIL. */
8276 static unsigned int
8277 encode_thumb32_immediate (unsigned int val)
8278 {
8279 unsigned int a, i;
8280
8281 if (val <= 0xff)
8282 return val;
8283
8284 for (i = 1; i <= 24; i++)
8285 {
8286 a = val >> i;
8287 if ((val & ~(0xff << i)) == 0)
8288 return ((val >> i) & 0x7f) | ((32 - i) << 7);
8289 }
8290
8291 a = val & 0xff;
8292 if (val == ((a << 16) | a))
8293 return 0x100 | a;
8294 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8295 return 0x300 | a;
8296
8297 a = val & 0xff00;
8298 if (val == ((a << 16) | a))
8299 return 0x200 | (a >> 8);
8300
8301 return FAIL;
8302 }
8303 /* Encode a VFP SP or DP register number into inst.instruction. */
8304
8305 static void
8306 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8307 {
8308 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8309 && reg > 15)
8310 {
8311 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
8312 {
8313 if (thumb_mode)
8314 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8315 fpu_vfp_ext_d32);
8316 else
8317 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8318 fpu_vfp_ext_d32);
8319 }
8320 else
8321 {
8322 first_error (_("D register out of range for selected VFP version"));
8323 return;
8324 }
8325 }
8326
8327 switch (pos)
8328 {
8329 case VFP_REG_Sd:
8330 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8331 break;
8332
8333 case VFP_REG_Sn:
8334 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8335 break;
8336
8337 case VFP_REG_Sm:
8338 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8339 break;
8340
8341 case VFP_REG_Dd:
8342 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8343 break;
8344
8345 case VFP_REG_Dn:
8346 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8347 break;
8348
8349 case VFP_REG_Dm:
8350 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8351 break;
8352
8353 default:
8354 abort ();
8355 }
8356 }
8357
8358 /* Encode a <shift> in an ARM-format instruction. The immediate,
8359 if any, is handled by md_apply_fix. */
8360 static void
8361 encode_arm_shift (int i)
8362 {
8363 /* register-shifted register. */
8364 if (inst.operands[i].immisreg)
8365 {
8366 int op_index;
8367 for (op_index = 0; op_index <= i; ++op_index)
8368 {
8369 /* Check the operand only when it's presented. In pre-UAL syntax,
8370 if the destination register is the same as the first operand, two
8371 register form of the instruction can be used. */
8372 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8373 && inst.operands[op_index].reg == REG_PC)
8374 as_warn (UNPRED_REG ("r15"));
8375 }
8376
8377 if (inst.operands[i].imm == REG_PC)
8378 as_warn (UNPRED_REG ("r15"));
8379 }
8380
8381 if (inst.operands[i].shift_kind == SHIFT_RRX)
8382 inst.instruction |= SHIFT_ROR << 5;
8383 else
8384 {
8385 inst.instruction |= inst.operands[i].shift_kind << 5;
8386 if (inst.operands[i].immisreg)
8387 {
8388 inst.instruction |= SHIFT_BY_REG;
8389 inst.instruction |= inst.operands[i].imm << 8;
8390 }
8391 else
8392 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8393 }
8394 }
8395
8396 static void
8397 encode_arm_shifter_operand (int i)
8398 {
8399 if (inst.operands[i].isreg)
8400 {
8401 inst.instruction |= inst.operands[i].reg;
8402 encode_arm_shift (i);
8403 }
8404 else
8405 {
8406 inst.instruction |= INST_IMMEDIATE;
8407 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
8408 inst.instruction |= inst.operands[i].imm;
8409 }
8410 }
8411
8412 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
8413 static void
8414 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
8415 {
8416 /* PR 14260:
8417 Generate an error if the operand is not a register. */
8418 constraint (!inst.operands[i].isreg,
8419 _("Instruction does not support =N addresses"));
8420
8421 inst.instruction |= inst.operands[i].reg << 16;
8422
8423 if (inst.operands[i].preind)
8424 {
8425 if (is_t)
8426 {
8427 inst.error = _("instruction does not accept preindexed addressing");
8428 return;
8429 }
8430 inst.instruction |= PRE_INDEX;
8431 if (inst.operands[i].writeback)
8432 inst.instruction |= WRITE_BACK;
8433
8434 }
8435 else if (inst.operands[i].postind)
8436 {
8437 gas_assert (inst.operands[i].writeback);
8438 if (is_t)
8439 inst.instruction |= WRITE_BACK;
8440 }
8441 else /* unindexed - only for coprocessor */
8442 {
8443 inst.error = _("instruction does not accept unindexed addressing");
8444 return;
8445 }
8446
8447 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8448 && (((inst.instruction & 0x000f0000) >> 16)
8449 == ((inst.instruction & 0x0000f000) >> 12)))
8450 as_warn ((inst.instruction & LOAD_BIT)
8451 ? _("destination register same as write-back base")
8452 : _("source register same as write-back base"));
8453 }
8454
8455 /* inst.operands[i] was set up by parse_address. Encode it into an
8456 ARM-format mode 2 load or store instruction. If is_t is true,
8457 reject forms that cannot be used with a T instruction (i.e. not
8458 post-indexed). */
8459 static void
8460 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
8461 {
8462 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8463
8464 encode_arm_addr_mode_common (i, is_t);
8465
8466 if (inst.operands[i].immisreg)
8467 {
8468 constraint ((inst.operands[i].imm == REG_PC
8469 || (is_pc && inst.operands[i].writeback)),
8470 BAD_PC_ADDRESSING);
8471 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8472 inst.instruction |= inst.operands[i].imm;
8473 if (!inst.operands[i].negative)
8474 inst.instruction |= INDEX_UP;
8475 if (inst.operands[i].shifted)
8476 {
8477 if (inst.operands[i].shift_kind == SHIFT_RRX)
8478 inst.instruction |= SHIFT_ROR << 5;
8479 else
8480 {
8481 inst.instruction |= inst.operands[i].shift_kind << 5;
8482 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8483 }
8484 }
8485 }
8486 else /* immediate offset in inst.relocs[0] */
8487 {
8488 if (is_pc && !inst.relocs[0].pc_rel)
8489 {
8490 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
8491
8492 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8493 cannot use PC in addressing.
8494 PC cannot be used in writeback addressing, either. */
8495 constraint ((is_t || inst.operands[i].writeback),
8496 BAD_PC_ADDRESSING);
8497
8498 /* Use of PC in str is deprecated for ARMv7. */
8499 if (warn_on_deprecated
8500 && !is_load
8501 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
8502 as_tsktsk (_("use of PC in this instruction is deprecated"));
8503 }
8504
8505 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8506 {
8507 /* Prefer + for zero encoded value. */
8508 if (!inst.operands[i].negative)
8509 inst.instruction |= INDEX_UP;
8510 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
8511 }
8512 }
8513 }
8514
8515 /* inst.operands[i] was set up by parse_address. Encode it into an
8516 ARM-format mode 3 load or store instruction. Reject forms that
8517 cannot be used with such instructions. If is_t is true, reject
8518 forms that cannot be used with a T instruction (i.e. not
8519 post-indexed). */
8520 static void
8521 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
8522 {
8523 if (inst.operands[i].immisreg && inst.operands[i].shifted)
8524 {
8525 inst.error = _("instruction does not accept scaled register index");
8526 return;
8527 }
8528
8529 encode_arm_addr_mode_common (i, is_t);
8530
8531 if (inst.operands[i].immisreg)
8532 {
8533 constraint ((inst.operands[i].imm == REG_PC
8534 || (is_t && inst.operands[i].reg == REG_PC)),
8535 BAD_PC_ADDRESSING);
8536 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8537 BAD_PC_WRITEBACK);
8538 inst.instruction |= inst.operands[i].imm;
8539 if (!inst.operands[i].negative)
8540 inst.instruction |= INDEX_UP;
8541 }
8542 else /* immediate offset in inst.relocs[0] */
8543 {
8544 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
8545 && inst.operands[i].writeback),
8546 BAD_PC_WRITEBACK);
8547 inst.instruction |= HWOFFSET_IMM;
8548 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8549 {
8550 /* Prefer + for zero encoded value. */
8551 if (!inst.operands[i].negative)
8552 inst.instruction |= INDEX_UP;
8553
8554 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
8555 }
8556 }
8557 }
8558
8559 /* Write immediate bits [7:0] to the following locations:
8560
8561 |28/24|23 19|18 16|15 4|3 0|
8562 | 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|
8563
8564 This function is used by VMOV/VMVN/VORR/VBIC. */
8565
8566 static void
8567 neon_write_immbits (unsigned immbits)
8568 {
8569 inst.instruction |= immbits & 0xf;
8570 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8571 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8572 }
8573
8574 /* Invert low-order SIZE bits of XHI:XLO. */
8575
8576 static void
8577 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8578 {
8579 unsigned immlo = xlo ? *xlo : 0;
8580 unsigned immhi = xhi ? *xhi : 0;
8581
8582 switch (size)
8583 {
8584 case 8:
8585 immlo = (~immlo) & 0xff;
8586 break;
8587
8588 case 16:
8589 immlo = (~immlo) & 0xffff;
8590 break;
8591
8592 case 64:
8593 immhi = (~immhi) & 0xffffffff;
8594 /* fall through. */
8595
8596 case 32:
8597 immlo = (~immlo) & 0xffffffff;
8598 break;
8599
8600 default:
8601 abort ();
8602 }
8603
8604 if (xlo)
8605 *xlo = immlo;
8606
8607 if (xhi)
8608 *xhi = immhi;
8609 }
8610
8611 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8612 A, B, C, D. */
8613
8614 static int
8615 neon_bits_same_in_bytes (unsigned imm)
8616 {
8617 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8618 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8619 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8620 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8621 }
8622
8623 /* For immediate of above form, return 0bABCD. */
8624
8625 static unsigned
8626 neon_squash_bits (unsigned imm)
8627 {
8628 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8629 | ((imm & 0x01000000) >> 21);
8630 }
8631
8632 /* Compress quarter-float representation to 0b...000 abcdefgh. */
8633
8634 static unsigned
8635 neon_qfloat_bits (unsigned imm)
8636 {
8637 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8638 }
8639
8640 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8641 the instruction. *OP is passed as the initial value of the op field, and
8642 may be set to a different value depending on the constant (i.e.
8643 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8644 MVN). If the immediate looks like a repeated pattern then also
8645 try smaller element sizes. */
8646
8647 static int
8648 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8649 unsigned *immbits, int *op, int size,
8650 enum neon_el_type type)
8651 {
8652 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8653 float. */
8654 if (type == NT_float && !float_p)
8655 return FAIL;
8656
8657 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
8658 {
8659 if (size != 32 || *op == 1)
8660 return FAIL;
8661 *immbits = neon_qfloat_bits (immlo);
8662 return 0xf;
8663 }
8664
8665 if (size == 64)
8666 {
8667 if (neon_bits_same_in_bytes (immhi)
8668 && neon_bits_same_in_bytes (immlo))
8669 {
8670 if (*op == 1)
8671 return FAIL;
8672 *immbits = (neon_squash_bits (immhi) << 4)
8673 | neon_squash_bits (immlo);
8674 *op = 1;
8675 return 0xe;
8676 }
8677
8678 if (immhi != immlo)
8679 return FAIL;
8680 }
8681
8682 if (size >= 32)
8683 {
8684 if (immlo == (immlo & 0x000000ff))
8685 {
8686 *immbits = immlo;
8687 return 0x0;
8688 }
8689 else if (immlo == (immlo & 0x0000ff00))
8690 {
8691 *immbits = immlo >> 8;
8692 return 0x2;
8693 }
8694 else if (immlo == (immlo & 0x00ff0000))
8695 {
8696 *immbits = immlo >> 16;
8697 return 0x4;
8698 }
8699 else if (immlo == (immlo & 0xff000000))
8700 {
8701 *immbits = immlo >> 24;
8702 return 0x6;
8703 }
8704 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8705 {
8706 *immbits = (immlo >> 8) & 0xff;
8707 return 0xc;
8708 }
8709 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8710 {
8711 *immbits = (immlo >> 16) & 0xff;
8712 return 0xd;
8713 }
8714
8715 if ((immlo & 0xffff) != (immlo >> 16))
8716 return FAIL;
8717 immlo &= 0xffff;
8718 }
8719
8720 if (size >= 16)
8721 {
8722 if (immlo == (immlo & 0x000000ff))
8723 {
8724 *immbits = immlo;
8725 return 0x8;
8726 }
8727 else if (immlo == (immlo & 0x0000ff00))
8728 {
8729 *immbits = immlo >> 8;
8730 return 0xa;
8731 }
8732
8733 if ((immlo & 0xff) != (immlo >> 8))
8734 return FAIL;
8735 immlo &= 0xff;
8736 }
8737
8738 if (immlo == (immlo & 0x000000ff))
8739 {
8740 /* Don't allow MVN with 8-bit immediate. */
8741 if (*op == 1)
8742 return FAIL;
8743 *immbits = immlo;
8744 return 0xe;
8745 }
8746
8747 return FAIL;
8748 }
8749
8750 #if defined BFD_HOST_64_BIT
8751 /* Returns TRUE if double precision value V may be cast
8752 to single precision without loss of accuracy. */
8753
8754 static bfd_boolean
8755 is_double_a_single (bfd_int64_t v)
8756 {
8757 int exp = (int)((v >> 52) & 0x7FF);
8758 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8759
8760 return (exp == 0 || exp == 0x7FF
8761 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8762 && (mantissa & 0x1FFFFFFFl) == 0;
8763 }
8764
8765 /* Returns a double precision value casted to single precision
8766 (ignoring the least significant bits in exponent and mantissa). */
8767
8768 static int
8769 double_to_single (bfd_int64_t v)
8770 {
8771 int sign = (int) ((v >> 63) & 1l);
8772 int exp = (int) ((v >> 52) & 0x7FF);
8773 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8774
8775 if (exp == 0x7FF)
8776 exp = 0xFF;
8777 else
8778 {
8779 exp = exp - 1023 + 127;
8780 if (exp >= 0xFF)
8781 {
8782 /* Infinity. */
8783 exp = 0x7F;
8784 mantissa = 0;
8785 }
8786 else if (exp < 0)
8787 {
8788 /* No denormalized numbers. */
8789 exp = 0;
8790 mantissa = 0;
8791 }
8792 }
8793 mantissa >>= 29;
8794 return (sign << 31) | (exp << 23) | mantissa;
8795 }
8796 #endif /* BFD_HOST_64_BIT */
8797
8798 enum lit_type
8799 {
8800 CONST_THUMB,
8801 CONST_ARM,
8802 CONST_VEC
8803 };
8804
8805 static void do_vfp_nsyn_opcode (const char *);
8806
8807 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
8808 Determine whether it can be performed with a move instruction; if
8809 it can, convert inst.instruction to that move instruction and
8810 return TRUE; if it can't, convert inst.instruction to a literal-pool
8811 load and return FALSE. If this is not a valid thing to do in the
8812 current context, set inst.error and return TRUE.
8813
8814 inst.operands[i] describes the destination register. */
8815
8816 static bfd_boolean
8817 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
8818 {
8819 unsigned long tbit;
8820 bfd_boolean thumb_p = (t == CONST_THUMB);
8821 bfd_boolean arm_p = (t == CONST_ARM);
8822
8823 if (thumb_p)
8824 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8825 else
8826 tbit = LOAD_BIT;
8827
8828 if ((inst.instruction & tbit) == 0)
8829 {
8830 inst.error = _("invalid pseudo operation");
8831 return TRUE;
8832 }
8833
8834 if (inst.relocs[0].exp.X_op != O_constant
8835 && inst.relocs[0].exp.X_op != O_symbol
8836 && inst.relocs[0].exp.X_op != O_big)
8837 {
8838 inst.error = _("constant expression expected");
8839 return TRUE;
8840 }
8841
8842 if (inst.relocs[0].exp.X_op == O_constant
8843 || inst.relocs[0].exp.X_op == O_big)
8844 {
8845 #if defined BFD_HOST_64_BIT
8846 bfd_int64_t v;
8847 #else
8848 offsetT v;
8849 #endif
8850 if (inst.relocs[0].exp.X_op == O_big)
8851 {
8852 LITTLENUM_TYPE w[X_PRECISION];
8853 LITTLENUM_TYPE * l;
8854
8855 if (inst.relocs[0].exp.X_add_number == -1)
8856 {
8857 gen_to_words (w, X_PRECISION, E_PRECISION);
8858 l = w;
8859 /* FIXME: Should we check words w[2..5] ? */
8860 }
8861 else
8862 l = generic_bignum;
8863
8864 #if defined BFD_HOST_64_BIT
8865 v =
8866 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8867 << LITTLENUM_NUMBER_OF_BITS)
8868 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8869 << LITTLENUM_NUMBER_OF_BITS)
8870 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8871 << LITTLENUM_NUMBER_OF_BITS)
8872 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8873 #else
8874 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8875 | (l[0] & LITTLENUM_MASK);
8876 #endif
8877 }
8878 else
8879 v = inst.relocs[0].exp.X_add_number;
8880
8881 if (!inst.operands[i].issingle)
8882 {
8883 if (thumb_p)
8884 {
8885 /* LDR should not use lead in a flag-setting instruction being
8886 chosen so we do not check whether movs can be used. */
8887
8888 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8889 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8890 && inst.operands[i].reg != 13
8891 && inst.operands[i].reg != 15)
8892 {
8893 /* Check if on thumb2 it can be done with a mov.w, mvn or
8894 movw instruction. */
8895 unsigned int newimm;
8896 bfd_boolean isNegated;
8897
8898 newimm = encode_thumb32_immediate (v);
8899 if (newimm != (unsigned int) FAIL)
8900 isNegated = FALSE;
8901 else
8902 {
8903 newimm = encode_thumb32_immediate (~v);
8904 if (newimm != (unsigned int) FAIL)
8905 isNegated = TRUE;
8906 }
8907
8908 /* The number can be loaded with a mov.w or mvn
8909 instruction. */
8910 if (newimm != (unsigned int) FAIL
8911 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8912 {
8913 inst.instruction = (0xf04f0000 /* MOV.W. */
8914 | (inst.operands[i].reg << 8));
8915 /* Change to MOVN. */
8916 inst.instruction |= (isNegated ? 0x200000 : 0);
8917 inst.instruction |= (newimm & 0x800) << 15;
8918 inst.instruction |= (newimm & 0x700) << 4;
8919 inst.instruction |= (newimm & 0x0ff);
8920 return TRUE;
8921 }
8922 /* The number can be loaded with a movw instruction. */
8923 else if ((v & ~0xFFFF) == 0
8924 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8925 {
8926 int imm = v & 0xFFFF;
8927
8928 inst.instruction = 0xf2400000; /* MOVW. */
8929 inst.instruction |= (inst.operands[i].reg << 8);
8930 inst.instruction |= (imm & 0xf000) << 4;
8931 inst.instruction |= (imm & 0x0800) << 15;
8932 inst.instruction |= (imm & 0x0700) << 4;
8933 inst.instruction |= (imm & 0x00ff);
8934 /* In case this replacement is being done on Armv8-M
8935 Baseline we need to make sure to disable the
8936 instruction size check, as otherwise GAS will reject
8937 the use of this T32 instruction. */
8938 inst.size_req = 0;
8939 return TRUE;
8940 }
8941 }
8942 }
8943 else if (arm_p)
8944 {
8945 int value = encode_arm_immediate (v);
8946
8947 if (value != FAIL)
8948 {
8949 /* This can be done with a mov instruction. */
8950 inst.instruction &= LITERAL_MASK;
8951 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8952 inst.instruction |= value & 0xfff;
8953 return TRUE;
8954 }
8955
8956 value = encode_arm_immediate (~ v);
8957 if (value != FAIL)
8958 {
8959 /* This can be done with a mvn instruction. */
8960 inst.instruction &= LITERAL_MASK;
8961 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8962 inst.instruction |= value & 0xfff;
8963 return TRUE;
8964 }
8965 }
8966 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8967 {
8968 int op = 0;
8969 unsigned immbits = 0;
8970 unsigned immlo = inst.operands[1].imm;
8971 unsigned immhi = inst.operands[1].regisimm
8972 ? inst.operands[1].reg
8973 : inst.relocs[0].exp.X_unsigned
8974 ? 0
8975 : ((bfd_int64_t)((int) immlo)) >> 32;
8976 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8977 &op, 64, NT_invtype);
8978
8979 if (cmode == FAIL)
8980 {
8981 neon_invert_size (&immlo, &immhi, 64);
8982 op = !op;
8983 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8984 &op, 64, NT_invtype);
8985 }
8986
8987 if (cmode != FAIL)
8988 {
8989 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8990 | (1 << 23)
8991 | (cmode << 8)
8992 | (op << 5)
8993 | (1 << 4);
8994
8995 /* Fill other bits in vmov encoding for both thumb and arm. */
8996 if (thumb_mode)
8997 inst.instruction |= (0x7U << 29) | (0xF << 24);
8998 else
8999 inst.instruction |= (0xFU << 28) | (0x1 << 25);
9000 neon_write_immbits (immbits);
9001 return TRUE;
9002 }
9003 }
9004 }
9005
9006 if (t == CONST_VEC)
9007 {
9008 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
9009 if (inst.operands[i].issingle
9010 && is_quarter_float (inst.operands[1].imm)
9011 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
9012 {
9013 inst.operands[1].imm =
9014 neon_qfloat_bits (v);
9015 do_vfp_nsyn_opcode ("fconsts");
9016 return TRUE;
9017 }
9018
9019 /* If our host does not support a 64-bit type then we cannot perform
9020 the following optimization. This mean that there will be a
9021 discrepancy between the output produced by an assembler built for
9022 a 32-bit-only host and the output produced from a 64-bit host, but
9023 this cannot be helped. */
9024 #if defined BFD_HOST_64_BIT
9025 else if (!inst.operands[1].issingle
9026 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
9027 {
9028 if (is_double_a_single (v)
9029 && is_quarter_float (double_to_single (v)))
9030 {
9031 inst.operands[1].imm =
9032 neon_qfloat_bits (double_to_single (v));
9033 do_vfp_nsyn_opcode ("fconstd");
9034 return TRUE;
9035 }
9036 }
9037 #endif
9038 }
9039 }
9040
9041 if (add_to_lit_pool ((!inst.operands[i].isvec
9042 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9043 return TRUE;
9044
9045 inst.operands[1].reg = REG_PC;
9046 inst.operands[1].isreg = 1;
9047 inst.operands[1].preind = 1;
9048 inst.relocs[0].pc_rel = 1;
9049 inst.relocs[0].type = (thumb_p
9050 ? BFD_RELOC_ARM_THUMB_OFFSET
9051 : (mode_3
9052 ? BFD_RELOC_ARM_HWLITERAL
9053 : BFD_RELOC_ARM_LITERAL));
9054 return FALSE;
9055 }
9056
9057 /* inst.operands[i] was set up by parse_address. Encode it into an
9058 ARM-format instruction. Reject all forms which cannot be encoded
9059 into a coprocessor load/store instruction. If wb_ok is false,
9060 reject use of writeback; if unind_ok is false, reject use of
9061 unindexed addressing. If reloc_override is not 0, use it instead
9062 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9063 (in which case it is preserved). */
9064
9065 static int
9066 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9067 {
9068 if (!inst.operands[i].isreg)
9069 {
9070 /* PR 18256 */
9071 if (! inst.operands[0].isvec)
9072 {
9073 inst.error = _("invalid co-processor operand");
9074 return FAIL;
9075 }
9076 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
9077 return SUCCESS;
9078 }
9079
9080 inst.instruction |= inst.operands[i].reg << 16;
9081
9082 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9083
9084 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9085 {
9086 gas_assert (!inst.operands[i].writeback);
9087 if (!unind_ok)
9088 {
9089 inst.error = _("instruction does not support unindexed addressing");
9090 return FAIL;
9091 }
9092 inst.instruction |= inst.operands[i].imm;
9093 inst.instruction |= INDEX_UP;
9094 return SUCCESS;
9095 }
9096
9097 if (inst.operands[i].preind)
9098 inst.instruction |= PRE_INDEX;
9099
9100 if (inst.operands[i].writeback)
9101 {
9102 if (inst.operands[i].reg == REG_PC)
9103 {
9104 inst.error = _("pc may not be used with write-back");
9105 return FAIL;
9106 }
9107 if (!wb_ok)
9108 {
9109 inst.error = _("instruction does not support writeback");
9110 return FAIL;
9111 }
9112 inst.instruction |= WRITE_BACK;
9113 }
9114
9115 if (reloc_override)
9116 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9117 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9118 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9119 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
9120 {
9121 if (thumb_mode)
9122 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
9123 else
9124 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
9125 }
9126
9127 /* Prefer + for zero encoded value. */
9128 if (!inst.operands[i].negative)
9129 inst.instruction |= INDEX_UP;
9130
9131 return SUCCESS;
9132 }
9133
9134 /* Functions for instruction encoding, sorted by sub-architecture.
9135 First some generics; their names are taken from the conventional
9136 bit positions for register arguments in ARM format instructions. */
9137
9138 static void
9139 do_noargs (void)
9140 {
9141 }
9142
9143 static void
9144 do_rd (void)
9145 {
9146 inst.instruction |= inst.operands[0].reg << 12;
9147 }
9148
9149 static void
9150 do_rn (void)
9151 {
9152 inst.instruction |= inst.operands[0].reg << 16;
9153 }
9154
9155 static void
9156 do_rd_rm (void)
9157 {
9158 inst.instruction |= inst.operands[0].reg << 12;
9159 inst.instruction |= inst.operands[1].reg;
9160 }
9161
9162 static void
9163 do_rm_rn (void)
9164 {
9165 inst.instruction |= inst.operands[0].reg;
9166 inst.instruction |= inst.operands[1].reg << 16;
9167 }
9168
9169 static void
9170 do_rd_rn (void)
9171 {
9172 inst.instruction |= inst.operands[0].reg << 12;
9173 inst.instruction |= inst.operands[1].reg << 16;
9174 }
9175
9176 static void
9177 do_rn_rd (void)
9178 {
9179 inst.instruction |= inst.operands[0].reg << 16;
9180 inst.instruction |= inst.operands[1].reg << 12;
9181 }
9182
9183 static void
9184 do_tt (void)
9185 {
9186 inst.instruction |= inst.operands[0].reg << 8;
9187 inst.instruction |= inst.operands[1].reg << 16;
9188 }
9189
9190 static bfd_boolean
9191 check_obsolete (const arm_feature_set *feature, const char *msg)
9192 {
9193 if (ARM_CPU_IS_ANY (cpu_variant))
9194 {
9195 as_tsktsk ("%s", msg);
9196 return TRUE;
9197 }
9198 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9199 {
9200 as_bad ("%s", msg);
9201 return TRUE;
9202 }
9203
9204 return FALSE;
9205 }
9206
9207 static void
9208 do_rd_rm_rn (void)
9209 {
9210 unsigned Rn = inst.operands[2].reg;
9211 /* Enforce restrictions on SWP instruction. */
9212 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
9213 {
9214 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9215 _("Rn must not overlap other operands"));
9216
9217 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9218 */
9219 if (!check_obsolete (&arm_ext_v8,
9220 _("swp{b} use is obsoleted for ARMv8 and later"))
9221 && warn_on_deprecated
9222 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
9223 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
9224 }
9225
9226 inst.instruction |= inst.operands[0].reg << 12;
9227 inst.instruction |= inst.operands[1].reg;
9228 inst.instruction |= Rn << 16;
9229 }
9230
9231 static void
9232 do_rd_rn_rm (void)
9233 {
9234 inst.instruction |= inst.operands[0].reg << 12;
9235 inst.instruction |= inst.operands[1].reg << 16;
9236 inst.instruction |= inst.operands[2].reg;
9237 }
9238
9239 static void
9240 do_rm_rd_rn (void)
9241 {
9242 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
9243 constraint (((inst.relocs[0].exp.X_op != O_constant
9244 && inst.relocs[0].exp.X_op != O_illegal)
9245 || inst.relocs[0].exp.X_add_number != 0),
9246 BAD_ADDR_MODE);
9247 inst.instruction |= inst.operands[0].reg;
9248 inst.instruction |= inst.operands[1].reg << 12;
9249 inst.instruction |= inst.operands[2].reg << 16;
9250 }
9251
9252 static void
9253 do_imm0 (void)
9254 {
9255 inst.instruction |= inst.operands[0].imm;
9256 }
9257
9258 static void
9259 do_rd_cpaddr (void)
9260 {
9261 inst.instruction |= inst.operands[0].reg << 12;
9262 encode_arm_cp_address (1, TRUE, TRUE, 0);
9263 }
9264
9265 /* ARM instructions, in alphabetical order by function name (except
9266 that wrapper functions appear immediately after the function they
9267 wrap). */
9268
9269 /* This is a pseudo-op of the form "adr rd, label" to be converted
9270 into a relative address of the form "add rd, pc, #label-.-8". */
9271
9272 static void
9273 do_adr (void)
9274 {
9275 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9276
9277 /* Frag hacking will turn this into a sub instruction if the offset turns
9278 out to be negative. */
9279 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9280 inst.relocs[0].pc_rel = 1;
9281 inst.relocs[0].exp.X_add_number -= 8;
9282
9283 if (support_interwork
9284 && inst.relocs[0].exp.X_op == O_symbol
9285 && inst.relocs[0].exp.X_add_symbol != NULL
9286 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9287 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9288 inst.relocs[0].exp.X_add_number |= 1;
9289 }
9290
9291 /* This is a pseudo-op of the form "adrl rd, label" to be converted
9292 into a relative address of the form:
9293 add rd, pc, #low(label-.-8)"
9294 add rd, rd, #high(label-.-8)" */
9295
9296 static void
9297 do_adrl (void)
9298 {
9299 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9300
9301 /* Frag hacking will turn this into a sub instruction if the offset turns
9302 out to be negative. */
9303 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9304 inst.relocs[0].pc_rel = 1;
9305 inst.size = INSN_SIZE * 2;
9306 inst.relocs[0].exp.X_add_number -= 8;
9307
9308 if (support_interwork
9309 && inst.relocs[0].exp.X_op == O_symbol
9310 && inst.relocs[0].exp.X_add_symbol != NULL
9311 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9312 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9313 inst.relocs[0].exp.X_add_number |= 1;
9314 }
9315
9316 static void
9317 do_arit (void)
9318 {
9319 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9320 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9321 THUMB1_RELOC_ONLY);
9322 if (!inst.operands[1].present)
9323 inst.operands[1].reg = inst.operands[0].reg;
9324 inst.instruction |= inst.operands[0].reg << 12;
9325 inst.instruction |= inst.operands[1].reg << 16;
9326 encode_arm_shifter_operand (2);
9327 }
9328
9329 static void
9330 do_barrier (void)
9331 {
9332 if (inst.operands[0].present)
9333 inst.instruction |= inst.operands[0].imm;
9334 else
9335 inst.instruction |= 0xf;
9336 }
9337
9338 static void
9339 do_bfc (void)
9340 {
9341 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9342 constraint (msb > 32, _("bit-field extends past end of register"));
9343 /* The instruction encoding stores the LSB and MSB,
9344 not the LSB and width. */
9345 inst.instruction |= inst.operands[0].reg << 12;
9346 inst.instruction |= inst.operands[1].imm << 7;
9347 inst.instruction |= (msb - 1) << 16;
9348 }
9349
9350 static void
9351 do_bfi (void)
9352 {
9353 unsigned int msb;
9354
9355 /* #0 in second position is alternative syntax for bfc, which is
9356 the same instruction but with REG_PC in the Rm field. */
9357 if (!inst.operands[1].isreg)
9358 inst.operands[1].reg = REG_PC;
9359
9360 msb = inst.operands[2].imm + inst.operands[3].imm;
9361 constraint (msb > 32, _("bit-field extends past end of register"));
9362 /* The instruction encoding stores the LSB and MSB,
9363 not the LSB and width. */
9364 inst.instruction |= inst.operands[0].reg << 12;
9365 inst.instruction |= inst.operands[1].reg;
9366 inst.instruction |= inst.operands[2].imm << 7;
9367 inst.instruction |= (msb - 1) << 16;
9368 }
9369
9370 static void
9371 do_bfx (void)
9372 {
9373 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9374 _("bit-field extends past end of register"));
9375 inst.instruction |= inst.operands[0].reg << 12;
9376 inst.instruction |= inst.operands[1].reg;
9377 inst.instruction |= inst.operands[2].imm << 7;
9378 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9379 }
9380
9381 /* ARM V5 breakpoint instruction (argument parse)
9382 BKPT <16 bit unsigned immediate>
9383 Instruction is not conditional.
9384 The bit pattern given in insns[] has the COND_ALWAYS condition,
9385 and it is an error if the caller tried to override that. */
9386
9387 static void
9388 do_bkpt (void)
9389 {
9390 /* Top 12 of 16 bits to bits 19:8. */
9391 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
9392
9393 /* Bottom 4 of 16 bits to bits 3:0. */
9394 inst.instruction |= inst.operands[0].imm & 0xf;
9395 }
9396
9397 static void
9398 encode_branch (int default_reloc)
9399 {
9400 if (inst.operands[0].hasreloc)
9401 {
9402 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9403 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9404 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
9405 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
9406 ? BFD_RELOC_ARM_PLT32
9407 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
9408 }
9409 else
9410 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9411 inst.relocs[0].pc_rel = 1;
9412 }
9413
9414 static void
9415 do_branch (void)
9416 {
9417 #ifdef OBJ_ELF
9418 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9419 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9420 else
9421 #endif
9422 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9423 }
9424
9425 static void
9426 do_bl (void)
9427 {
9428 #ifdef OBJ_ELF
9429 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9430 {
9431 if (inst.cond == COND_ALWAYS)
9432 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9433 else
9434 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9435 }
9436 else
9437 #endif
9438 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9439 }
9440
9441 /* ARM V5 branch-link-exchange instruction (argument parse)
9442 BLX <target_addr> ie BLX(1)
9443 BLX{<condition>} <Rm> ie BLX(2)
9444 Unfortunately, there are two different opcodes for this mnemonic.
9445 So, the insns[].value is not used, and the code here zaps values
9446 into inst.instruction.
9447 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
9448
9449 static void
9450 do_blx (void)
9451 {
9452 if (inst.operands[0].isreg)
9453 {
9454 /* Arg is a register; the opcode provided by insns[] is correct.
9455 It is not illegal to do "blx pc", just useless. */
9456 if (inst.operands[0].reg == REG_PC)
9457 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
9458
9459 inst.instruction |= inst.operands[0].reg;
9460 }
9461 else
9462 {
9463 /* Arg is an address; this instruction cannot be executed
9464 conditionally, and the opcode must be adjusted.
9465 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9466 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
9467 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9468 inst.instruction = 0xfa000000;
9469 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
9470 }
9471 }
9472
9473 static void
9474 do_bx (void)
9475 {
9476 bfd_boolean want_reloc;
9477
9478 if (inst.operands[0].reg == REG_PC)
9479 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
9480
9481 inst.instruction |= inst.operands[0].reg;
9482 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9483 it is for ARMv4t or earlier. */
9484 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
9485 if (!ARM_FEATURE_ZERO (selected_object_arch)
9486 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
9487 want_reloc = TRUE;
9488
9489 #ifdef OBJ_ELF
9490 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
9491 #endif
9492 want_reloc = FALSE;
9493
9494 if (want_reloc)
9495 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
9496 }
9497
9498
9499 /* ARM v5TEJ. Jump to Jazelle code. */
9500
9501 static void
9502 do_bxj (void)
9503 {
9504 if (inst.operands[0].reg == REG_PC)
9505 as_tsktsk (_("use of r15 in bxj is not really useful"));
9506
9507 inst.instruction |= inst.operands[0].reg;
9508 }
9509
9510 /* Co-processor data operation:
9511 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9512 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9513 static void
9514 do_cdp (void)
9515 {
9516 inst.instruction |= inst.operands[0].reg << 8;
9517 inst.instruction |= inst.operands[1].imm << 20;
9518 inst.instruction |= inst.operands[2].reg << 12;
9519 inst.instruction |= inst.operands[3].reg << 16;
9520 inst.instruction |= inst.operands[4].reg;
9521 inst.instruction |= inst.operands[5].imm << 5;
9522 }
9523
9524 static void
9525 do_cmp (void)
9526 {
9527 inst.instruction |= inst.operands[0].reg << 16;
9528 encode_arm_shifter_operand (1);
9529 }
9530
9531 /* Transfer between coprocessor and ARM registers.
9532 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9533 MRC2
9534 MCR{cond}
9535 MCR2
9536
9537 No special properties. */
9538
9539 struct deprecated_coproc_regs_s
9540 {
9541 unsigned cp;
9542 int opc1;
9543 unsigned crn;
9544 unsigned crm;
9545 int opc2;
9546 arm_feature_set deprecated;
9547 arm_feature_set obsoleted;
9548 const char *dep_msg;
9549 const char *obs_msg;
9550 };
9551
9552 #define DEPR_ACCESS_V8 \
9553 N_("This coprocessor register access is deprecated in ARMv8")
9554
9555 /* Table of all deprecated coprocessor registers. */
9556 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9557 {
9558 {15, 0, 7, 10, 5, /* CP15DMB. */
9559 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9560 DEPR_ACCESS_V8, NULL},
9561 {15, 0, 7, 10, 4, /* CP15DSB. */
9562 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9563 DEPR_ACCESS_V8, NULL},
9564 {15, 0, 7, 5, 4, /* CP15ISB. */
9565 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9566 DEPR_ACCESS_V8, NULL},
9567 {14, 6, 1, 0, 0, /* TEEHBR. */
9568 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9569 DEPR_ACCESS_V8, NULL},
9570 {14, 6, 0, 0, 0, /* TEECR. */
9571 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9572 DEPR_ACCESS_V8, NULL},
9573 };
9574
9575 #undef DEPR_ACCESS_V8
9576
9577 static const size_t deprecated_coproc_reg_count =
9578 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9579
9580 static void
9581 do_co_reg (void)
9582 {
9583 unsigned Rd;
9584 size_t i;
9585
9586 Rd = inst.operands[2].reg;
9587 if (thumb_mode)
9588 {
9589 if (inst.instruction == 0xee000010
9590 || inst.instruction == 0xfe000010)
9591 /* MCR, MCR2 */
9592 reject_bad_reg (Rd);
9593 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9594 /* MRC, MRC2 */
9595 constraint (Rd == REG_SP, BAD_SP);
9596 }
9597 else
9598 {
9599 /* MCR */
9600 if (inst.instruction == 0xe000010)
9601 constraint (Rd == REG_PC, BAD_PC);
9602 }
9603
9604 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9605 {
9606 const struct deprecated_coproc_regs_s *r =
9607 deprecated_coproc_regs + i;
9608
9609 if (inst.operands[0].reg == r->cp
9610 && inst.operands[1].imm == r->opc1
9611 && inst.operands[3].reg == r->crn
9612 && inst.operands[4].reg == r->crm
9613 && inst.operands[5].imm == r->opc2)
9614 {
9615 if (! ARM_CPU_IS_ANY (cpu_variant)
9616 && warn_on_deprecated
9617 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
9618 as_tsktsk ("%s", r->dep_msg);
9619 }
9620 }
9621
9622 inst.instruction |= inst.operands[0].reg << 8;
9623 inst.instruction |= inst.operands[1].imm << 21;
9624 inst.instruction |= Rd << 12;
9625 inst.instruction |= inst.operands[3].reg << 16;
9626 inst.instruction |= inst.operands[4].reg;
9627 inst.instruction |= inst.operands[5].imm << 5;
9628 }
9629
9630 /* Transfer between coprocessor register and pair of ARM registers.
9631 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9632 MCRR2
9633 MRRC{cond}
9634 MRRC2
9635
9636 Two XScale instructions are special cases of these:
9637
9638 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9639 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
9640
9641 Result unpredictable if Rd or Rn is R15. */
9642
9643 static void
9644 do_co_reg2c (void)
9645 {
9646 unsigned Rd, Rn;
9647
9648 Rd = inst.operands[2].reg;
9649 Rn = inst.operands[3].reg;
9650
9651 if (thumb_mode)
9652 {
9653 reject_bad_reg (Rd);
9654 reject_bad_reg (Rn);
9655 }
9656 else
9657 {
9658 constraint (Rd == REG_PC, BAD_PC);
9659 constraint (Rn == REG_PC, BAD_PC);
9660 }
9661
9662 /* Only check the MRRC{2} variants. */
9663 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9664 {
9665 /* If Rd == Rn, error that the operation is
9666 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9667 constraint (Rd == Rn, BAD_OVERLAP);
9668 }
9669
9670 inst.instruction |= inst.operands[0].reg << 8;
9671 inst.instruction |= inst.operands[1].imm << 4;
9672 inst.instruction |= Rd << 12;
9673 inst.instruction |= Rn << 16;
9674 inst.instruction |= inst.operands[4].reg;
9675 }
9676
9677 static void
9678 do_cpsi (void)
9679 {
9680 inst.instruction |= inst.operands[0].imm << 6;
9681 if (inst.operands[1].present)
9682 {
9683 inst.instruction |= CPSI_MMOD;
9684 inst.instruction |= inst.operands[1].imm;
9685 }
9686 }
9687
9688 static void
9689 do_dbg (void)
9690 {
9691 inst.instruction |= inst.operands[0].imm;
9692 }
9693
9694 static void
9695 do_div (void)
9696 {
9697 unsigned Rd, Rn, Rm;
9698
9699 Rd = inst.operands[0].reg;
9700 Rn = (inst.operands[1].present
9701 ? inst.operands[1].reg : Rd);
9702 Rm = inst.operands[2].reg;
9703
9704 constraint ((Rd == REG_PC), BAD_PC);
9705 constraint ((Rn == REG_PC), BAD_PC);
9706 constraint ((Rm == REG_PC), BAD_PC);
9707
9708 inst.instruction |= Rd << 16;
9709 inst.instruction |= Rn << 0;
9710 inst.instruction |= Rm << 8;
9711 }
9712
9713 static void
9714 do_it (void)
9715 {
9716 /* There is no IT instruction in ARM mode. We
9717 process it to do the validation as if in
9718 thumb mode, just in case the code gets
9719 assembled for thumb using the unified syntax. */
9720
9721 inst.size = 0;
9722 if (unified_syntax)
9723 {
9724 set_pred_insn_type (IT_INSN);
9725 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9726 now_pred.cc = inst.operands[0].imm;
9727 }
9728 }
9729
9730 /* If there is only one register in the register list,
9731 then return its register number. Otherwise return -1. */
9732 static int
9733 only_one_reg_in_list (int range)
9734 {
9735 int i = ffs (range) - 1;
9736 return (i > 15 || range != (1 << i)) ? -1 : i;
9737 }
9738
9739 static void
9740 encode_ldmstm(int from_push_pop_mnem)
9741 {
9742 int base_reg = inst.operands[0].reg;
9743 int range = inst.operands[1].imm;
9744 int one_reg;
9745
9746 inst.instruction |= base_reg << 16;
9747 inst.instruction |= range;
9748
9749 if (inst.operands[1].writeback)
9750 inst.instruction |= LDM_TYPE_2_OR_3;
9751
9752 if (inst.operands[0].writeback)
9753 {
9754 inst.instruction |= WRITE_BACK;
9755 /* Check for unpredictable uses of writeback. */
9756 if (inst.instruction & LOAD_BIT)
9757 {
9758 /* Not allowed in LDM type 2. */
9759 if ((inst.instruction & LDM_TYPE_2_OR_3)
9760 && ((range & (1 << REG_PC)) == 0))
9761 as_warn (_("writeback of base register is UNPREDICTABLE"));
9762 /* Only allowed if base reg not in list for other types. */
9763 else if (range & (1 << base_reg))
9764 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9765 }
9766 else /* STM. */
9767 {
9768 /* Not allowed for type 2. */
9769 if (inst.instruction & LDM_TYPE_2_OR_3)
9770 as_warn (_("writeback of base register is UNPREDICTABLE"));
9771 /* Only allowed if base reg not in list, or first in list. */
9772 else if ((range & (1 << base_reg))
9773 && (range & ((1 << base_reg) - 1)))
9774 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
9775 }
9776 }
9777
9778 /* If PUSH/POP has only one register, then use the A2 encoding. */
9779 one_reg = only_one_reg_in_list (range);
9780 if (from_push_pop_mnem && one_reg >= 0)
9781 {
9782 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9783
9784 if (is_push && one_reg == 13 /* SP */)
9785 /* PR 22483: The A2 encoding cannot be used when
9786 pushing the stack pointer as this is UNPREDICTABLE. */
9787 return;
9788
9789 inst.instruction &= A_COND_MASK;
9790 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9791 inst.instruction |= one_reg << 12;
9792 }
9793 }
9794
9795 static void
9796 do_ldmstm (void)
9797 {
9798 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
9799 }
9800
9801 /* ARMv5TE load-consecutive (argument parse)
9802 Mode is like LDRH.
9803
9804 LDRccD R, mode
9805 STRccD R, mode. */
9806
9807 static void
9808 do_ldrd (void)
9809 {
9810 constraint (inst.operands[0].reg % 2 != 0,
9811 _("first transfer register must be even"));
9812 constraint (inst.operands[1].present
9813 && inst.operands[1].reg != inst.operands[0].reg + 1,
9814 _("can only transfer two consecutive registers"));
9815 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9816 constraint (!inst.operands[2].isreg, _("'[' expected"));
9817
9818 if (!inst.operands[1].present)
9819 inst.operands[1].reg = inst.operands[0].reg + 1;
9820
9821 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9822 register and the first register written; we have to diagnose
9823 overlap between the base and the second register written here. */
9824
9825 if (inst.operands[2].reg == inst.operands[1].reg
9826 && (inst.operands[2].writeback || inst.operands[2].postind))
9827 as_warn (_("base register written back, and overlaps "
9828 "second transfer register"));
9829
9830 if (!(inst.instruction & V4_STR_BIT))
9831 {
9832 /* For an index-register load, the index register must not overlap the
9833 destination (even if not write-back). */
9834 if (inst.operands[2].immisreg
9835 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9836 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9837 as_warn (_("index register overlaps transfer register"));
9838 }
9839 inst.instruction |= inst.operands[0].reg << 12;
9840 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
9841 }
9842
9843 static void
9844 do_ldrex (void)
9845 {
9846 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9847 || inst.operands[1].postind || inst.operands[1].writeback
9848 || inst.operands[1].immisreg || inst.operands[1].shifted
9849 || inst.operands[1].negative
9850 /* This can arise if the programmer has written
9851 strex rN, rM, foo
9852 or if they have mistakenly used a register name as the last
9853 operand, eg:
9854 strex rN, rM, rX
9855 It is very difficult to distinguish between these two cases
9856 because "rX" might actually be a label. ie the register
9857 name has been occluded by a symbol of the same name. So we
9858 just generate a general 'bad addressing mode' type error
9859 message and leave it up to the programmer to discover the
9860 true cause and fix their mistake. */
9861 || (inst.operands[1].reg == REG_PC),
9862 BAD_ADDR_MODE);
9863
9864 constraint (inst.relocs[0].exp.X_op != O_constant
9865 || inst.relocs[0].exp.X_add_number != 0,
9866 _("offset must be zero in ARM encoding"));
9867
9868 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9869
9870 inst.instruction |= inst.operands[0].reg << 12;
9871 inst.instruction |= inst.operands[1].reg << 16;
9872 inst.relocs[0].type = BFD_RELOC_UNUSED;
9873 }
9874
9875 static void
9876 do_ldrexd (void)
9877 {
9878 constraint (inst.operands[0].reg % 2 != 0,
9879 _("even register required"));
9880 constraint (inst.operands[1].present
9881 && inst.operands[1].reg != inst.operands[0].reg + 1,
9882 _("can only load two consecutive registers"));
9883 /* If op 1 were present and equal to PC, this function wouldn't
9884 have been called in the first place. */
9885 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9886
9887 inst.instruction |= inst.operands[0].reg << 12;
9888 inst.instruction |= inst.operands[2].reg << 16;
9889 }
9890
9891 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9892 which is not a multiple of four is UNPREDICTABLE. */
9893 static void
9894 check_ldr_r15_aligned (void)
9895 {
9896 constraint (!(inst.operands[1].immisreg)
9897 && (inst.operands[0].reg == REG_PC
9898 && inst.operands[1].reg == REG_PC
9899 && (inst.relocs[0].exp.X_add_number & 0x3)),
9900 _("ldr to register 15 must be 4-byte aligned"));
9901 }
9902
9903 static void
9904 do_ldst (void)
9905 {
9906 inst.instruction |= inst.operands[0].reg << 12;
9907 if (!inst.operands[1].isreg)
9908 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
9909 return;
9910 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
9911 check_ldr_r15_aligned ();
9912 }
9913
9914 static void
9915 do_ldstt (void)
9916 {
9917 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9918 reject [Rn,...]. */
9919 if (inst.operands[1].preind)
9920 {
9921 constraint (inst.relocs[0].exp.X_op != O_constant
9922 || inst.relocs[0].exp.X_add_number != 0,
9923 _("this instruction requires a post-indexed address"));
9924
9925 inst.operands[1].preind = 0;
9926 inst.operands[1].postind = 1;
9927 inst.operands[1].writeback = 1;
9928 }
9929 inst.instruction |= inst.operands[0].reg << 12;
9930 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9931 }
9932
9933 /* Halfword and signed-byte load/store operations. */
9934
9935 static void
9936 do_ldstv4 (void)
9937 {
9938 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9939 inst.instruction |= inst.operands[0].reg << 12;
9940 if (!inst.operands[1].isreg)
9941 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
9942 return;
9943 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
9944 }
9945
9946 static void
9947 do_ldsttv4 (void)
9948 {
9949 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9950 reject [Rn,...]. */
9951 if (inst.operands[1].preind)
9952 {
9953 constraint (inst.relocs[0].exp.X_op != O_constant
9954 || inst.relocs[0].exp.X_add_number != 0,
9955 _("this instruction requires a post-indexed address"));
9956
9957 inst.operands[1].preind = 0;
9958 inst.operands[1].postind = 1;
9959 inst.operands[1].writeback = 1;
9960 }
9961 inst.instruction |= inst.operands[0].reg << 12;
9962 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9963 }
9964
9965 /* Co-processor register load/store.
9966 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9967 static void
9968 do_lstc (void)
9969 {
9970 inst.instruction |= inst.operands[0].reg << 8;
9971 inst.instruction |= inst.operands[1].reg << 12;
9972 encode_arm_cp_address (2, TRUE, TRUE, 0);
9973 }
9974
9975 static void
9976 do_mlas (void)
9977 {
9978 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9979 if (inst.operands[0].reg == inst.operands[1].reg
9980 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9981 && !(inst.instruction & 0x00400000))
9982 as_tsktsk (_("Rd and Rm should be different in mla"));
9983
9984 inst.instruction |= inst.operands[0].reg << 16;
9985 inst.instruction |= inst.operands[1].reg;
9986 inst.instruction |= inst.operands[2].reg << 8;
9987 inst.instruction |= inst.operands[3].reg << 12;
9988 }
9989
9990 static void
9991 do_mov (void)
9992 {
9993 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9994 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9995 THUMB1_RELOC_ONLY);
9996 inst.instruction |= inst.operands[0].reg << 12;
9997 encode_arm_shifter_operand (1);
9998 }
9999
10000 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
10001 static void
10002 do_mov16 (void)
10003 {
10004 bfd_vma imm;
10005 bfd_boolean top;
10006
10007 top = (inst.instruction & 0x00400000) != 0;
10008 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
10009 _(":lower16: not allowed in this instruction"));
10010 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
10011 _(":upper16: not allowed in this instruction"));
10012 inst.instruction |= inst.operands[0].reg << 12;
10013 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
10014 {
10015 imm = inst.relocs[0].exp.X_add_number;
10016 /* The value is in two pieces: 0:11, 16:19. */
10017 inst.instruction |= (imm & 0x00000fff);
10018 inst.instruction |= (imm & 0x0000f000) << 4;
10019 }
10020 }
10021
10022 static int
10023 do_vfp_nsyn_mrs (void)
10024 {
10025 if (inst.operands[0].isvec)
10026 {
10027 if (inst.operands[1].reg != 1)
10028 first_error (_("operand 1 must be FPSCR"));
10029 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10030 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10031 do_vfp_nsyn_opcode ("fmstat");
10032 }
10033 else if (inst.operands[1].isvec)
10034 do_vfp_nsyn_opcode ("fmrx");
10035 else
10036 return FAIL;
10037
10038 return SUCCESS;
10039 }
10040
10041 static int
10042 do_vfp_nsyn_msr (void)
10043 {
10044 if (inst.operands[0].isvec)
10045 do_vfp_nsyn_opcode ("fmxr");
10046 else
10047 return FAIL;
10048
10049 return SUCCESS;
10050 }
10051
10052 static void
10053 do_vmrs (void)
10054 {
10055 unsigned Rt = inst.operands[0].reg;
10056
10057 if (thumb_mode && Rt == REG_SP)
10058 {
10059 inst.error = BAD_SP;
10060 return;
10061 }
10062
10063 switch (inst.operands[1].reg)
10064 {
10065 /* MVFR2 is only valid for Armv8-A. */
10066 case 5:
10067 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10068 _(BAD_FPU));
10069 break;
10070
10071 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10072 case 1: /* fpscr. */
10073 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10074 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10075 _(BAD_FPU));
10076 break;
10077
10078 case 14: /* fpcxt_ns. */
10079 case 15: /* fpcxt_s. */
10080 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10081 _("selected processor does not support instruction"));
10082 break;
10083
10084 case 2: /* fpscr_nzcvqc. */
10085 case 12: /* vpr. */
10086 case 13: /* p0. */
10087 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10088 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10089 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10090 _("selected processor does not support instruction"));
10091 if (inst.operands[0].reg != 2
10092 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10093 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10094 break;
10095
10096 default:
10097 break;
10098 }
10099
10100 /* APSR_ sets isvec. All other refs to PC are illegal. */
10101 if (!inst.operands[0].isvec && Rt == REG_PC)
10102 {
10103 inst.error = BAD_PC;
10104 return;
10105 }
10106
10107 /* If we get through parsing the register name, we just insert the number
10108 generated into the instruction without further validation. */
10109 inst.instruction |= (inst.operands[1].reg << 16);
10110 inst.instruction |= (Rt << 12);
10111 }
10112
10113 static void
10114 do_vmsr (void)
10115 {
10116 unsigned Rt = inst.operands[1].reg;
10117
10118 if (thumb_mode)
10119 reject_bad_reg (Rt);
10120 else if (Rt == REG_PC)
10121 {
10122 inst.error = BAD_PC;
10123 return;
10124 }
10125
10126 switch (inst.operands[0].reg)
10127 {
10128 /* MVFR2 is only valid for Armv8-A. */
10129 case 5:
10130 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10131 _(BAD_FPU));
10132 break;
10133
10134 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10135 case 1: /* fpcr. */
10136 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10137 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10138 _(BAD_FPU));
10139 break;
10140
10141 case 14: /* fpcxt_ns. */
10142 case 15: /* fpcxt_s. */
10143 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10144 _("selected processor does not support instruction"));
10145 break;
10146
10147 case 2: /* fpscr_nzcvqc. */
10148 case 12: /* vpr. */
10149 case 13: /* p0. */
10150 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10151 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10152 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10153 _("selected processor does not support instruction"));
10154 if (inst.operands[0].reg != 2
10155 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10156 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10157 break;
10158
10159 default:
10160 break;
10161 }
10162
10163 /* If we get through parsing the register name, we just insert the number
10164 generated into the instruction without further validation. */
10165 inst.instruction |= (inst.operands[0].reg << 16);
10166 inst.instruction |= (Rt << 12);
10167 }
10168
10169 static void
10170 do_mrs (void)
10171 {
10172 unsigned br;
10173
10174 if (do_vfp_nsyn_mrs () == SUCCESS)
10175 return;
10176
10177 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10178 inst.instruction |= inst.operands[0].reg << 12;
10179
10180 if (inst.operands[1].isreg)
10181 {
10182 br = inst.operands[1].reg;
10183 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
10184 as_bad (_("bad register for mrs"));
10185 }
10186 else
10187 {
10188 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10189 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10190 != (PSR_c|PSR_f),
10191 _("'APSR', 'CPSR' or 'SPSR' expected"));
10192 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10193 }
10194
10195 inst.instruction |= br;
10196 }
10197
10198 /* Two possible forms:
10199 "{C|S}PSR_<field>, Rm",
10200 "{C|S}PSR_f, #expression". */
10201
10202 static void
10203 do_msr (void)
10204 {
10205 if (do_vfp_nsyn_msr () == SUCCESS)
10206 return;
10207
10208 inst.instruction |= inst.operands[0].imm;
10209 if (inst.operands[1].isreg)
10210 inst.instruction |= inst.operands[1].reg;
10211 else
10212 {
10213 inst.instruction |= INST_IMMEDIATE;
10214 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10215 inst.relocs[0].pc_rel = 0;
10216 }
10217 }
10218
10219 static void
10220 do_mul (void)
10221 {
10222 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10223
10224 if (!inst.operands[2].present)
10225 inst.operands[2].reg = inst.operands[0].reg;
10226 inst.instruction |= inst.operands[0].reg << 16;
10227 inst.instruction |= inst.operands[1].reg;
10228 inst.instruction |= inst.operands[2].reg << 8;
10229
10230 if (inst.operands[0].reg == inst.operands[1].reg
10231 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10232 as_tsktsk (_("Rd and Rm should be different in mul"));
10233 }
10234
10235 /* Long Multiply Parser
10236 UMULL RdLo, RdHi, Rm, Rs
10237 SMULL RdLo, RdHi, Rm, Rs
10238 UMLAL RdLo, RdHi, Rm, Rs
10239 SMLAL RdLo, RdHi, Rm, Rs. */
10240
10241 static void
10242 do_mull (void)
10243 {
10244 inst.instruction |= inst.operands[0].reg << 12;
10245 inst.instruction |= inst.operands[1].reg << 16;
10246 inst.instruction |= inst.operands[2].reg;
10247 inst.instruction |= inst.operands[3].reg << 8;
10248
10249 /* rdhi and rdlo must be different. */
10250 if (inst.operands[0].reg == inst.operands[1].reg)
10251 as_tsktsk (_("rdhi and rdlo must be different"));
10252
10253 /* rdhi, rdlo and rm must all be different before armv6. */
10254 if ((inst.operands[0].reg == inst.operands[2].reg
10255 || inst.operands[1].reg == inst.operands[2].reg)
10256 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10257 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10258 }
10259
10260 static void
10261 do_nop (void)
10262 {
10263 if (inst.operands[0].present
10264 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
10265 {
10266 /* Architectural NOP hints are CPSR sets with no bits selected. */
10267 inst.instruction &= 0xf0000000;
10268 inst.instruction |= 0x0320f000;
10269 if (inst.operands[0].present)
10270 inst.instruction |= inst.operands[0].imm;
10271 }
10272 }
10273
10274 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10275 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10276 Condition defaults to COND_ALWAYS.
10277 Error if Rd, Rn or Rm are R15. */
10278
10279 static void
10280 do_pkhbt (void)
10281 {
10282 inst.instruction |= inst.operands[0].reg << 12;
10283 inst.instruction |= inst.operands[1].reg << 16;
10284 inst.instruction |= inst.operands[2].reg;
10285 if (inst.operands[3].present)
10286 encode_arm_shift (3);
10287 }
10288
10289 /* ARM V6 PKHTB (Argument Parse). */
10290
10291 static void
10292 do_pkhtb (void)
10293 {
10294 if (!inst.operands[3].present)
10295 {
10296 /* If the shift specifier is omitted, turn the instruction
10297 into pkhbt rd, rm, rn. */
10298 inst.instruction &= 0xfff00010;
10299 inst.instruction |= inst.operands[0].reg << 12;
10300 inst.instruction |= inst.operands[1].reg;
10301 inst.instruction |= inst.operands[2].reg << 16;
10302 }
10303 else
10304 {
10305 inst.instruction |= inst.operands[0].reg << 12;
10306 inst.instruction |= inst.operands[1].reg << 16;
10307 inst.instruction |= inst.operands[2].reg;
10308 encode_arm_shift (3);
10309 }
10310 }
10311
10312 /* ARMv5TE: Preload-Cache
10313 MP Extensions: Preload for write
10314
10315 PLD(W) <addr_mode>
10316
10317 Syntactically, like LDR with B=1, W=0, L=1. */
10318
10319 static void
10320 do_pld (void)
10321 {
10322 constraint (!inst.operands[0].isreg,
10323 _("'[' expected after PLD mnemonic"));
10324 constraint (inst.operands[0].postind,
10325 _("post-indexed expression used in preload instruction"));
10326 constraint (inst.operands[0].writeback,
10327 _("writeback used in preload instruction"));
10328 constraint (!inst.operands[0].preind,
10329 _("unindexed addressing used in preload instruction"));
10330 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10331 }
10332
10333 /* ARMv7: PLI <addr_mode> */
10334 static void
10335 do_pli (void)
10336 {
10337 constraint (!inst.operands[0].isreg,
10338 _("'[' expected after PLI mnemonic"));
10339 constraint (inst.operands[0].postind,
10340 _("post-indexed expression used in preload instruction"));
10341 constraint (inst.operands[0].writeback,
10342 _("writeback used in preload instruction"));
10343 constraint (!inst.operands[0].preind,
10344 _("unindexed addressing used in preload instruction"));
10345 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10346 inst.instruction &= ~PRE_INDEX;
10347 }
10348
10349 static void
10350 do_push_pop (void)
10351 {
10352 constraint (inst.operands[0].writeback,
10353 _("push/pop do not support {reglist}^"));
10354 inst.operands[1] = inst.operands[0];
10355 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10356 inst.operands[0].isreg = 1;
10357 inst.operands[0].writeback = 1;
10358 inst.operands[0].reg = REG_SP;
10359 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
10360 }
10361
10362 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10363 word at the specified address and the following word
10364 respectively.
10365 Unconditionally executed.
10366 Error if Rn is R15. */
10367
10368 static void
10369 do_rfe (void)
10370 {
10371 inst.instruction |= inst.operands[0].reg << 16;
10372 if (inst.operands[0].writeback)
10373 inst.instruction |= WRITE_BACK;
10374 }
10375
10376 /* ARM V6 ssat (argument parse). */
10377
10378 static void
10379 do_ssat (void)
10380 {
10381 inst.instruction |= inst.operands[0].reg << 12;
10382 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10383 inst.instruction |= inst.operands[2].reg;
10384
10385 if (inst.operands[3].present)
10386 encode_arm_shift (3);
10387 }
10388
10389 /* ARM V6 usat (argument parse). */
10390
10391 static void
10392 do_usat (void)
10393 {
10394 inst.instruction |= inst.operands[0].reg << 12;
10395 inst.instruction |= inst.operands[1].imm << 16;
10396 inst.instruction |= inst.operands[2].reg;
10397
10398 if (inst.operands[3].present)
10399 encode_arm_shift (3);
10400 }
10401
10402 /* ARM V6 ssat16 (argument parse). */
10403
10404 static void
10405 do_ssat16 (void)
10406 {
10407 inst.instruction |= inst.operands[0].reg << 12;
10408 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10409 inst.instruction |= inst.operands[2].reg;
10410 }
10411
10412 static void
10413 do_usat16 (void)
10414 {
10415 inst.instruction |= inst.operands[0].reg << 12;
10416 inst.instruction |= inst.operands[1].imm << 16;
10417 inst.instruction |= inst.operands[2].reg;
10418 }
10419
10420 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10421 preserving the other bits.
10422
10423 setend <endian_specifier>, where <endian_specifier> is either
10424 BE or LE. */
10425
10426 static void
10427 do_setend (void)
10428 {
10429 if (warn_on_deprecated
10430 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10431 as_tsktsk (_("setend use is deprecated for ARMv8"));
10432
10433 if (inst.operands[0].imm)
10434 inst.instruction |= 0x200;
10435 }
10436
10437 static void
10438 do_shift (void)
10439 {
10440 unsigned int Rm = (inst.operands[1].present
10441 ? inst.operands[1].reg
10442 : inst.operands[0].reg);
10443
10444 inst.instruction |= inst.operands[0].reg << 12;
10445 inst.instruction |= Rm;
10446 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
10447 {
10448 inst.instruction |= inst.operands[2].reg << 8;
10449 inst.instruction |= SHIFT_BY_REG;
10450 /* PR 12854: Error on extraneous shifts. */
10451 constraint (inst.operands[2].shifted,
10452 _("extraneous shift as part of operand to shift insn"));
10453 }
10454 else
10455 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
10456 }
10457
10458 static void
10459 do_smc (void)
10460 {
10461 unsigned int value = inst.relocs[0].exp.X_add_number;
10462 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10463
10464 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10465 inst.relocs[0].pc_rel = 0;
10466 }
10467
10468 static void
10469 do_hvc (void)
10470 {
10471 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10472 inst.relocs[0].pc_rel = 0;
10473 }
10474
10475 static void
10476 do_swi (void)
10477 {
10478 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10479 inst.relocs[0].pc_rel = 0;
10480 }
10481
10482 static void
10483 do_setpan (void)
10484 {
10485 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10486 _("selected processor does not support SETPAN instruction"));
10487
10488 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10489 }
10490
10491 static void
10492 do_t_setpan (void)
10493 {
10494 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10495 _("selected processor does not support SETPAN instruction"));
10496
10497 inst.instruction |= (inst.operands[0].imm << 3);
10498 }
10499
10500 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10501 SMLAxy{cond} Rd,Rm,Rs,Rn
10502 SMLAWy{cond} Rd,Rm,Rs,Rn
10503 Error if any register is R15. */
10504
10505 static void
10506 do_smla (void)
10507 {
10508 inst.instruction |= inst.operands[0].reg << 16;
10509 inst.instruction |= inst.operands[1].reg;
10510 inst.instruction |= inst.operands[2].reg << 8;
10511 inst.instruction |= inst.operands[3].reg << 12;
10512 }
10513
10514 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10515 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10516 Error if any register is R15.
10517 Warning if Rdlo == Rdhi. */
10518
10519 static void
10520 do_smlal (void)
10521 {
10522 inst.instruction |= inst.operands[0].reg << 12;
10523 inst.instruction |= inst.operands[1].reg << 16;
10524 inst.instruction |= inst.operands[2].reg;
10525 inst.instruction |= inst.operands[3].reg << 8;
10526
10527 if (inst.operands[0].reg == inst.operands[1].reg)
10528 as_tsktsk (_("rdhi and rdlo must be different"));
10529 }
10530
10531 /* ARM V5E (El Segundo) signed-multiply (argument parse)
10532 SMULxy{cond} Rd,Rm,Rs
10533 Error if any register is R15. */
10534
10535 static void
10536 do_smul (void)
10537 {
10538 inst.instruction |= inst.operands[0].reg << 16;
10539 inst.instruction |= inst.operands[1].reg;
10540 inst.instruction |= inst.operands[2].reg << 8;
10541 }
10542
10543 /* ARM V6 srs (argument parse). The variable fields in the encoding are
10544 the same for both ARM and Thumb-2. */
10545
10546 static void
10547 do_srs (void)
10548 {
10549 int reg;
10550
10551 if (inst.operands[0].present)
10552 {
10553 reg = inst.operands[0].reg;
10554 constraint (reg != REG_SP, _("SRS base register must be r13"));
10555 }
10556 else
10557 reg = REG_SP;
10558
10559 inst.instruction |= reg << 16;
10560 inst.instruction |= inst.operands[1].imm;
10561 if (inst.operands[0].writeback || inst.operands[1].writeback)
10562 inst.instruction |= WRITE_BACK;
10563 }
10564
10565 /* ARM V6 strex (argument parse). */
10566
10567 static void
10568 do_strex (void)
10569 {
10570 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10571 || inst.operands[2].postind || inst.operands[2].writeback
10572 || inst.operands[2].immisreg || inst.operands[2].shifted
10573 || inst.operands[2].negative
10574 /* See comment in do_ldrex(). */
10575 || (inst.operands[2].reg == REG_PC),
10576 BAD_ADDR_MODE);
10577
10578 constraint (inst.operands[0].reg == inst.operands[1].reg
10579 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10580
10581 constraint (inst.relocs[0].exp.X_op != O_constant
10582 || inst.relocs[0].exp.X_add_number != 0,
10583 _("offset must be zero in ARM encoding"));
10584
10585 inst.instruction |= inst.operands[0].reg << 12;
10586 inst.instruction |= inst.operands[1].reg;
10587 inst.instruction |= inst.operands[2].reg << 16;
10588 inst.relocs[0].type = BFD_RELOC_UNUSED;
10589 }
10590
10591 static void
10592 do_t_strexbh (void)
10593 {
10594 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10595 || inst.operands[2].postind || inst.operands[2].writeback
10596 || inst.operands[2].immisreg || inst.operands[2].shifted
10597 || inst.operands[2].negative,
10598 BAD_ADDR_MODE);
10599
10600 constraint (inst.operands[0].reg == inst.operands[1].reg
10601 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10602
10603 do_rm_rd_rn ();
10604 }
10605
10606 static void
10607 do_strexd (void)
10608 {
10609 constraint (inst.operands[1].reg % 2 != 0,
10610 _("even register required"));
10611 constraint (inst.operands[2].present
10612 && inst.operands[2].reg != inst.operands[1].reg + 1,
10613 _("can only store two consecutive registers"));
10614 /* If op 2 were present and equal to PC, this function wouldn't
10615 have been called in the first place. */
10616 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
10617
10618 constraint (inst.operands[0].reg == inst.operands[1].reg
10619 || inst.operands[0].reg == inst.operands[1].reg + 1
10620 || inst.operands[0].reg == inst.operands[3].reg,
10621 BAD_OVERLAP);
10622
10623 inst.instruction |= inst.operands[0].reg << 12;
10624 inst.instruction |= inst.operands[1].reg;
10625 inst.instruction |= inst.operands[3].reg << 16;
10626 }
10627
10628 /* ARM V8 STRL. */
10629 static void
10630 do_stlex (void)
10631 {
10632 constraint (inst.operands[0].reg == inst.operands[1].reg
10633 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10634
10635 do_rd_rm_rn ();
10636 }
10637
10638 static void
10639 do_t_stlex (void)
10640 {
10641 constraint (inst.operands[0].reg == inst.operands[1].reg
10642 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10643
10644 do_rm_rd_rn ();
10645 }
10646
10647 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10648 extends it to 32-bits, and adds the result to a value in another
10649 register. You can specify a rotation by 0, 8, 16, or 24 bits
10650 before extracting the 16-bit value.
10651 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10652 Condition defaults to COND_ALWAYS.
10653 Error if any register uses R15. */
10654
10655 static void
10656 do_sxtah (void)
10657 {
10658 inst.instruction |= inst.operands[0].reg << 12;
10659 inst.instruction |= inst.operands[1].reg << 16;
10660 inst.instruction |= inst.operands[2].reg;
10661 inst.instruction |= inst.operands[3].imm << 10;
10662 }
10663
10664 /* ARM V6 SXTH.
10665
10666 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10667 Condition defaults to COND_ALWAYS.
10668 Error if any register uses R15. */
10669
10670 static void
10671 do_sxth (void)
10672 {
10673 inst.instruction |= inst.operands[0].reg << 12;
10674 inst.instruction |= inst.operands[1].reg;
10675 inst.instruction |= inst.operands[2].imm << 10;
10676 }
10677 \f
10678 /* VFP instructions. In a logical order: SP variant first, monad
10679 before dyad, arithmetic then move then load/store. */
10680
10681 static void
10682 do_vfp_sp_monadic (void)
10683 {
10684 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10685 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10686 _(BAD_FPU));
10687
10688 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10689 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10690 }
10691
10692 static void
10693 do_vfp_sp_dyadic (void)
10694 {
10695 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10696 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10697 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10698 }
10699
10700 static void
10701 do_vfp_sp_compare_z (void)
10702 {
10703 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10704 }
10705
10706 static void
10707 do_vfp_dp_sp_cvt (void)
10708 {
10709 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10710 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10711 }
10712
10713 static void
10714 do_vfp_sp_dp_cvt (void)
10715 {
10716 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10717 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10718 }
10719
10720 static void
10721 do_vfp_reg_from_sp (void)
10722 {
10723 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10724 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10725 _(BAD_FPU));
10726
10727 inst.instruction |= inst.operands[0].reg << 12;
10728 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10729 }
10730
10731 static void
10732 do_vfp_reg2_from_sp2 (void)
10733 {
10734 constraint (inst.operands[2].imm != 2,
10735 _("only two consecutive VFP SP registers allowed here"));
10736 inst.instruction |= inst.operands[0].reg << 12;
10737 inst.instruction |= inst.operands[1].reg << 16;
10738 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10739 }
10740
10741 static void
10742 do_vfp_sp_from_reg (void)
10743 {
10744 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10745 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10746 _(BAD_FPU));
10747
10748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
10749 inst.instruction |= inst.operands[1].reg << 12;
10750 }
10751
10752 static void
10753 do_vfp_sp2_from_reg2 (void)
10754 {
10755 constraint (inst.operands[0].imm != 2,
10756 _("only two consecutive VFP SP registers allowed here"));
10757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
10758 inst.instruction |= inst.operands[1].reg << 12;
10759 inst.instruction |= inst.operands[2].reg << 16;
10760 }
10761
10762 static void
10763 do_vfp_sp_ldst (void)
10764 {
10765 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10766 encode_arm_cp_address (1, FALSE, TRUE, 0);
10767 }
10768
10769 static void
10770 do_vfp_dp_ldst (void)
10771 {
10772 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10773 encode_arm_cp_address (1, FALSE, TRUE, 0);
10774 }
10775
10776
10777 static void
10778 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
10779 {
10780 if (inst.operands[0].writeback)
10781 inst.instruction |= WRITE_BACK;
10782 else
10783 constraint (ldstm_type != VFP_LDSTMIA,
10784 _("this addressing mode requires base-register writeback"));
10785 inst.instruction |= inst.operands[0].reg << 16;
10786 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
10787 inst.instruction |= inst.operands[1].imm;
10788 }
10789
10790 static void
10791 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
10792 {
10793 int count;
10794
10795 if (inst.operands[0].writeback)
10796 inst.instruction |= WRITE_BACK;
10797 else
10798 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10799 _("this addressing mode requires base-register writeback"));
10800
10801 inst.instruction |= inst.operands[0].reg << 16;
10802 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10803
10804 count = inst.operands[1].imm << 1;
10805 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10806 count += 1;
10807
10808 inst.instruction |= count;
10809 }
10810
10811 static void
10812 do_vfp_sp_ldstmia (void)
10813 {
10814 vfp_sp_ldstm (VFP_LDSTMIA);
10815 }
10816
10817 static void
10818 do_vfp_sp_ldstmdb (void)
10819 {
10820 vfp_sp_ldstm (VFP_LDSTMDB);
10821 }
10822
10823 static void
10824 do_vfp_dp_ldstmia (void)
10825 {
10826 vfp_dp_ldstm (VFP_LDSTMIA);
10827 }
10828
10829 static void
10830 do_vfp_dp_ldstmdb (void)
10831 {
10832 vfp_dp_ldstm (VFP_LDSTMDB);
10833 }
10834
10835 static void
10836 do_vfp_xp_ldstmia (void)
10837 {
10838 vfp_dp_ldstm (VFP_LDSTMIAX);
10839 }
10840
10841 static void
10842 do_vfp_xp_ldstmdb (void)
10843 {
10844 vfp_dp_ldstm (VFP_LDSTMDBX);
10845 }
10846
10847 static void
10848 do_vfp_dp_rd_rm (void)
10849 {
10850 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10851 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10852 _(BAD_FPU));
10853
10854 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10855 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10856 }
10857
10858 static void
10859 do_vfp_dp_rn_rd (void)
10860 {
10861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10863 }
10864
10865 static void
10866 do_vfp_dp_rd_rn (void)
10867 {
10868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10869 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10870 }
10871
10872 static void
10873 do_vfp_dp_rd_rn_rm (void)
10874 {
10875 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10876 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10877 _(BAD_FPU));
10878
10879 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10880 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10881 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10882 }
10883
10884 static void
10885 do_vfp_dp_rd (void)
10886 {
10887 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10888 }
10889
10890 static void
10891 do_vfp_dp_rm_rd_rn (void)
10892 {
10893 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10894 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10895 _(BAD_FPU));
10896
10897 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10898 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10899 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10900 }
10901
10902 /* VFPv3 instructions. */
10903 static void
10904 do_vfp_sp_const (void)
10905 {
10906 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10907 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10908 inst.instruction |= (inst.operands[1].imm & 0x0f);
10909 }
10910
10911 static void
10912 do_vfp_dp_const (void)
10913 {
10914 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10915 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10916 inst.instruction |= (inst.operands[1].imm & 0x0f);
10917 }
10918
10919 static void
10920 vfp_conv (int srcsize)
10921 {
10922 int immbits = srcsize - inst.operands[1].imm;
10923
10924 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10925 {
10926 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10927 i.e. immbits must be in range 0 - 16. */
10928 inst.error = _("immediate value out of range, expected range [0, 16]");
10929 return;
10930 }
10931 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10932 {
10933 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10934 i.e. immbits must be in range 0 - 31. */
10935 inst.error = _("immediate value out of range, expected range [1, 32]");
10936 return;
10937 }
10938
10939 inst.instruction |= (immbits & 1) << 5;
10940 inst.instruction |= (immbits >> 1);
10941 }
10942
10943 static void
10944 do_vfp_sp_conv_16 (void)
10945 {
10946 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10947 vfp_conv (16);
10948 }
10949
10950 static void
10951 do_vfp_dp_conv_16 (void)
10952 {
10953 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10954 vfp_conv (16);
10955 }
10956
10957 static void
10958 do_vfp_sp_conv_32 (void)
10959 {
10960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10961 vfp_conv (32);
10962 }
10963
10964 static void
10965 do_vfp_dp_conv_32 (void)
10966 {
10967 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10968 vfp_conv (32);
10969 }
10970 \f
10971 /* FPA instructions. Also in a logical order. */
10972
10973 static void
10974 do_fpa_cmp (void)
10975 {
10976 inst.instruction |= inst.operands[0].reg << 16;
10977 inst.instruction |= inst.operands[1].reg;
10978 }
10979
10980 static void
10981 do_fpa_ldmstm (void)
10982 {
10983 inst.instruction |= inst.operands[0].reg << 12;
10984 switch (inst.operands[1].imm)
10985 {
10986 case 1: inst.instruction |= CP_T_X; break;
10987 case 2: inst.instruction |= CP_T_Y; break;
10988 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10989 case 4: break;
10990 default: abort ();
10991 }
10992
10993 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10994 {
10995 /* The instruction specified "ea" or "fd", so we can only accept
10996 [Rn]{!}. The instruction does not really support stacking or
10997 unstacking, so we have to emulate these by setting appropriate
10998 bits and offsets. */
10999 constraint (inst.relocs[0].exp.X_op != O_constant
11000 || inst.relocs[0].exp.X_add_number != 0,
11001 _("this instruction does not support indexing"));
11002
11003 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
11004 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
11005
11006 if (!(inst.instruction & INDEX_UP))
11007 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
11008
11009 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
11010 {
11011 inst.operands[2].preind = 0;
11012 inst.operands[2].postind = 1;
11013 }
11014 }
11015
11016 encode_arm_cp_address (2, TRUE, TRUE, 0);
11017 }
11018 \f
11019 /* iWMMXt instructions: strictly in alphabetical order. */
11020
11021 static void
11022 do_iwmmxt_tandorc (void)
11023 {
11024 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11025 }
11026
11027 static void
11028 do_iwmmxt_textrc (void)
11029 {
11030 inst.instruction |= inst.operands[0].reg << 12;
11031 inst.instruction |= inst.operands[1].imm;
11032 }
11033
11034 static void
11035 do_iwmmxt_textrm (void)
11036 {
11037 inst.instruction |= inst.operands[0].reg << 12;
11038 inst.instruction |= inst.operands[1].reg << 16;
11039 inst.instruction |= inst.operands[2].imm;
11040 }
11041
11042 static void
11043 do_iwmmxt_tinsr (void)
11044 {
11045 inst.instruction |= inst.operands[0].reg << 16;
11046 inst.instruction |= inst.operands[1].reg << 12;
11047 inst.instruction |= inst.operands[2].imm;
11048 }
11049
11050 static void
11051 do_iwmmxt_tmia (void)
11052 {
11053 inst.instruction |= inst.operands[0].reg << 5;
11054 inst.instruction |= inst.operands[1].reg;
11055 inst.instruction |= inst.operands[2].reg << 12;
11056 }
11057
11058 static void
11059 do_iwmmxt_waligni (void)
11060 {
11061 inst.instruction |= inst.operands[0].reg << 12;
11062 inst.instruction |= inst.operands[1].reg << 16;
11063 inst.instruction |= inst.operands[2].reg;
11064 inst.instruction |= inst.operands[3].imm << 20;
11065 }
11066
11067 static void
11068 do_iwmmxt_wmerge (void)
11069 {
11070 inst.instruction |= inst.operands[0].reg << 12;
11071 inst.instruction |= inst.operands[1].reg << 16;
11072 inst.instruction |= inst.operands[2].reg;
11073 inst.instruction |= inst.operands[3].imm << 21;
11074 }
11075
11076 static void
11077 do_iwmmxt_wmov (void)
11078 {
11079 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11080 inst.instruction |= inst.operands[0].reg << 12;
11081 inst.instruction |= inst.operands[1].reg << 16;
11082 inst.instruction |= inst.operands[1].reg;
11083 }
11084
11085 static void
11086 do_iwmmxt_wldstbh (void)
11087 {
11088 int reloc;
11089 inst.instruction |= inst.operands[0].reg << 12;
11090 if (thumb_mode)
11091 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11092 else
11093 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11094 encode_arm_cp_address (1, TRUE, FALSE, reloc);
11095 }
11096
11097 static void
11098 do_iwmmxt_wldstw (void)
11099 {
11100 /* RIWR_RIWC clears .isreg for a control register. */
11101 if (!inst.operands[0].isreg)
11102 {
11103 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11104 inst.instruction |= 0xf0000000;
11105 }
11106
11107 inst.instruction |= inst.operands[0].reg << 12;
11108 encode_arm_cp_address (1, TRUE, TRUE, 0);
11109 }
11110
11111 static void
11112 do_iwmmxt_wldstd (void)
11113 {
11114 inst.instruction |= inst.operands[0].reg << 12;
11115 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11116 && inst.operands[1].immisreg)
11117 {
11118 inst.instruction &= ~0x1a000ff;
11119 inst.instruction |= (0xfU << 28);
11120 if (inst.operands[1].preind)
11121 inst.instruction |= PRE_INDEX;
11122 if (!inst.operands[1].negative)
11123 inst.instruction |= INDEX_UP;
11124 if (inst.operands[1].writeback)
11125 inst.instruction |= WRITE_BACK;
11126 inst.instruction |= inst.operands[1].reg << 16;
11127 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11128 inst.instruction |= inst.operands[1].imm;
11129 }
11130 else
11131 encode_arm_cp_address (1, TRUE, FALSE, 0);
11132 }
11133
11134 static void
11135 do_iwmmxt_wshufh (void)
11136 {
11137 inst.instruction |= inst.operands[0].reg << 12;
11138 inst.instruction |= inst.operands[1].reg << 16;
11139 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11140 inst.instruction |= (inst.operands[2].imm & 0x0f);
11141 }
11142
11143 static void
11144 do_iwmmxt_wzero (void)
11145 {
11146 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11147 inst.instruction |= inst.operands[0].reg;
11148 inst.instruction |= inst.operands[0].reg << 12;
11149 inst.instruction |= inst.operands[0].reg << 16;
11150 }
11151
11152 static void
11153 do_iwmmxt_wrwrwr_or_imm5 (void)
11154 {
11155 if (inst.operands[2].isreg)
11156 do_rd_rn_rm ();
11157 else {
11158 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11159 _("immediate operand requires iWMMXt2"));
11160 do_rd_rn ();
11161 if (inst.operands[2].imm == 0)
11162 {
11163 switch ((inst.instruction >> 20) & 0xf)
11164 {
11165 case 4:
11166 case 5:
11167 case 6:
11168 case 7:
11169 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11170 inst.operands[2].imm = 16;
11171 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11172 break;
11173 case 8:
11174 case 9:
11175 case 10:
11176 case 11:
11177 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11178 inst.operands[2].imm = 32;
11179 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11180 break;
11181 case 12:
11182 case 13:
11183 case 14:
11184 case 15:
11185 {
11186 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11187 unsigned long wrn;
11188 wrn = (inst.instruction >> 16) & 0xf;
11189 inst.instruction &= 0xff0fff0f;
11190 inst.instruction |= wrn;
11191 /* Bail out here; the instruction is now assembled. */
11192 return;
11193 }
11194 }
11195 }
11196 /* Map 32 -> 0, etc. */
11197 inst.operands[2].imm &= 0x1f;
11198 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
11199 }
11200 }
11201 \f
11202 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11203 operations first, then control, shift, and load/store. */
11204
11205 /* Insns like "foo X,Y,Z". */
11206
11207 static void
11208 do_mav_triple (void)
11209 {
11210 inst.instruction |= inst.operands[0].reg << 16;
11211 inst.instruction |= inst.operands[1].reg;
11212 inst.instruction |= inst.operands[2].reg << 12;
11213 }
11214
11215 /* Insns like "foo W,X,Y,Z".
11216 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
11217
11218 static void
11219 do_mav_quad (void)
11220 {
11221 inst.instruction |= inst.operands[0].reg << 5;
11222 inst.instruction |= inst.operands[1].reg << 12;
11223 inst.instruction |= inst.operands[2].reg << 16;
11224 inst.instruction |= inst.operands[3].reg;
11225 }
11226
11227 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11228 static void
11229 do_mav_dspsc (void)
11230 {
11231 inst.instruction |= inst.operands[1].reg << 12;
11232 }
11233
11234 /* Maverick shift immediate instructions.
11235 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11236 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
11237
11238 static void
11239 do_mav_shift (void)
11240 {
11241 int imm = inst.operands[2].imm;
11242
11243 inst.instruction |= inst.operands[0].reg << 12;
11244 inst.instruction |= inst.operands[1].reg << 16;
11245
11246 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11247 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11248 Bit 4 should be 0. */
11249 imm = (imm & 0xf) | ((imm & 0x70) << 1);
11250
11251 inst.instruction |= imm;
11252 }
11253 \f
11254 /* XScale instructions. Also sorted arithmetic before move. */
11255
11256 /* Xscale multiply-accumulate (argument parse)
11257 MIAcc acc0,Rm,Rs
11258 MIAPHcc acc0,Rm,Rs
11259 MIAxycc acc0,Rm,Rs. */
11260
11261 static void
11262 do_xsc_mia (void)
11263 {
11264 inst.instruction |= inst.operands[1].reg;
11265 inst.instruction |= inst.operands[2].reg << 12;
11266 }
11267
11268 /* Xscale move-accumulator-register (argument parse)
11269
11270 MARcc acc0,RdLo,RdHi. */
11271
11272 static void
11273 do_xsc_mar (void)
11274 {
11275 inst.instruction |= inst.operands[1].reg << 12;
11276 inst.instruction |= inst.operands[2].reg << 16;
11277 }
11278
11279 /* Xscale move-register-accumulator (argument parse)
11280
11281 MRAcc RdLo,RdHi,acc0. */
11282
11283 static void
11284 do_xsc_mra (void)
11285 {
11286 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11287 inst.instruction |= inst.operands[0].reg << 12;
11288 inst.instruction |= inst.operands[1].reg << 16;
11289 }
11290 \f
11291 /* Encoding functions relevant only to Thumb. */
11292
11293 /* inst.operands[i] is a shifted-register operand; encode
11294 it into inst.instruction in the format used by Thumb32. */
11295
11296 static void
11297 encode_thumb32_shifted_operand (int i)
11298 {
11299 unsigned int value = inst.relocs[0].exp.X_add_number;
11300 unsigned int shift = inst.operands[i].shift_kind;
11301
11302 constraint (inst.operands[i].immisreg,
11303 _("shift by register not allowed in thumb mode"));
11304 inst.instruction |= inst.operands[i].reg;
11305 if (shift == SHIFT_RRX)
11306 inst.instruction |= SHIFT_ROR << 4;
11307 else
11308 {
11309 constraint (inst.relocs[0].exp.X_op != O_constant,
11310 _("expression too complex"));
11311
11312 constraint (value > 32
11313 || (value == 32 && (shift == SHIFT_LSL
11314 || shift == SHIFT_ROR)),
11315 _("shift expression is too large"));
11316
11317 if (value == 0)
11318 shift = SHIFT_LSL;
11319 else if (value == 32)
11320 value = 0;
11321
11322 inst.instruction |= shift << 4;
11323 inst.instruction |= (value & 0x1c) << 10;
11324 inst.instruction |= (value & 0x03) << 6;
11325 }
11326 }
11327
11328
11329 /* inst.operands[i] was set up by parse_address. Encode it into a
11330 Thumb32 format load or store instruction. Reject forms that cannot
11331 be used with such instructions. If is_t is true, reject forms that
11332 cannot be used with a T instruction; if is_d is true, reject forms
11333 that cannot be used with a D instruction. If it is a store insn,
11334 reject PC in Rn. */
11335
11336 static void
11337 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11338 {
11339 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
11340
11341 constraint (!inst.operands[i].isreg,
11342 _("Instruction does not support =N addresses"));
11343
11344 inst.instruction |= inst.operands[i].reg << 16;
11345 if (inst.operands[i].immisreg)
11346 {
11347 constraint (is_pc, BAD_PC_ADDRESSING);
11348 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11349 constraint (inst.operands[i].negative,
11350 _("Thumb does not support negative register indexing"));
11351 constraint (inst.operands[i].postind,
11352 _("Thumb does not support register post-indexing"));
11353 constraint (inst.operands[i].writeback,
11354 _("Thumb does not support register indexing with writeback"));
11355 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11356 _("Thumb supports only LSL in shifted register indexing"));
11357
11358 inst.instruction |= inst.operands[i].imm;
11359 if (inst.operands[i].shifted)
11360 {
11361 constraint (inst.relocs[0].exp.X_op != O_constant,
11362 _("expression too complex"));
11363 constraint (inst.relocs[0].exp.X_add_number < 0
11364 || inst.relocs[0].exp.X_add_number > 3,
11365 _("shift out of range"));
11366 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11367 }
11368 inst.relocs[0].type = BFD_RELOC_UNUSED;
11369 }
11370 else if (inst.operands[i].preind)
11371 {
11372 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
11373 constraint (is_t && inst.operands[i].writeback,
11374 _("cannot use writeback with this instruction"));
11375 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11376 BAD_PC_ADDRESSING);
11377
11378 if (is_d)
11379 {
11380 inst.instruction |= 0x01000000;
11381 if (inst.operands[i].writeback)
11382 inst.instruction |= 0x00200000;
11383 }
11384 else
11385 {
11386 inst.instruction |= 0x00000c00;
11387 if (inst.operands[i].writeback)
11388 inst.instruction |= 0x00000100;
11389 }
11390 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11391 }
11392 else if (inst.operands[i].postind)
11393 {
11394 gas_assert (inst.operands[i].writeback);
11395 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11396 constraint (is_t, _("cannot use post-indexing with this instruction"));
11397
11398 if (is_d)
11399 inst.instruction |= 0x00200000;
11400 else
11401 inst.instruction |= 0x00000900;
11402 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11403 }
11404 else /* unindexed - only for coprocessor */
11405 inst.error = _("instruction does not accept unindexed addressing");
11406 }
11407
11408 /* Table of Thumb instructions which exist in 16- and/or 32-bit
11409 encodings (the latter only in post-V6T2 cores). The index is the
11410 value used in the insns table below. When there is more than one
11411 possible 16-bit encoding for the instruction, this table always
11412 holds variant (1).
11413 Also contains several pseudo-instructions used during relaxation. */
11414 #define T16_32_TAB \
11415 X(_adc, 4140, eb400000), \
11416 X(_adcs, 4140, eb500000), \
11417 X(_add, 1c00, eb000000), \
11418 X(_adds, 1c00, eb100000), \
11419 X(_addi, 0000, f1000000), \
11420 X(_addis, 0000, f1100000), \
11421 X(_add_pc,000f, f20f0000), \
11422 X(_add_sp,000d, f10d0000), \
11423 X(_adr, 000f, f20f0000), \
11424 X(_and, 4000, ea000000), \
11425 X(_ands, 4000, ea100000), \
11426 X(_asr, 1000, fa40f000), \
11427 X(_asrs, 1000, fa50f000), \
11428 X(_b, e000, f000b000), \
11429 X(_bcond, d000, f0008000), \
11430 X(_bf, 0000, f040e001), \
11431 X(_bfcsel,0000, f000e001), \
11432 X(_bfx, 0000, f060e001), \
11433 X(_bfl, 0000, f000c001), \
11434 X(_bflx, 0000, f070e001), \
11435 X(_bic, 4380, ea200000), \
11436 X(_bics, 4380, ea300000), \
11437 X(_cinc, 0000, ea509000), \
11438 X(_cinv, 0000, ea50a000), \
11439 X(_cmn, 42c0, eb100f00), \
11440 X(_cmp, 2800, ebb00f00), \
11441 X(_cneg, 0000, ea50b000), \
11442 X(_cpsie, b660, f3af8400), \
11443 X(_cpsid, b670, f3af8600), \
11444 X(_cpy, 4600, ea4f0000), \
11445 X(_csel, 0000, ea508000), \
11446 X(_cset, 0000, ea5f900f), \
11447 X(_csetm, 0000, ea5fa00f), \
11448 X(_csinc, 0000, ea509000), \
11449 X(_csinv, 0000, ea50a000), \
11450 X(_csneg, 0000, ea50b000), \
11451 X(_dec_sp,80dd, f1ad0d00), \
11452 X(_dls, 0000, f040e001), \
11453 X(_dlstp, 0000, f000e001), \
11454 X(_eor, 4040, ea800000), \
11455 X(_eors, 4040, ea900000), \
11456 X(_inc_sp,00dd, f10d0d00), \
11457 X(_lctp, 0000, f00fe001), \
11458 X(_ldmia, c800, e8900000), \
11459 X(_ldr, 6800, f8500000), \
11460 X(_ldrb, 7800, f8100000), \
11461 X(_ldrh, 8800, f8300000), \
11462 X(_ldrsb, 5600, f9100000), \
11463 X(_ldrsh, 5e00, f9300000), \
11464 X(_ldr_pc,4800, f85f0000), \
11465 X(_ldr_pc2,4800, f85f0000), \
11466 X(_ldr_sp,9800, f85d0000), \
11467 X(_le, 0000, f00fc001), \
11468 X(_letp, 0000, f01fc001), \
11469 X(_lsl, 0000, fa00f000), \
11470 X(_lsls, 0000, fa10f000), \
11471 X(_lsr, 0800, fa20f000), \
11472 X(_lsrs, 0800, fa30f000), \
11473 X(_mov, 2000, ea4f0000), \
11474 X(_movs, 2000, ea5f0000), \
11475 X(_mul, 4340, fb00f000), \
11476 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11477 X(_mvn, 43c0, ea6f0000), \
11478 X(_mvns, 43c0, ea7f0000), \
11479 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11480 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11481 X(_orr, 4300, ea400000), \
11482 X(_orrs, 4300, ea500000), \
11483 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11484 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11485 X(_rev, ba00, fa90f080), \
11486 X(_rev16, ba40, fa90f090), \
11487 X(_revsh, bac0, fa90f0b0), \
11488 X(_ror, 41c0, fa60f000), \
11489 X(_rors, 41c0, fa70f000), \
11490 X(_sbc, 4180, eb600000), \
11491 X(_sbcs, 4180, eb700000), \
11492 X(_stmia, c000, e8800000), \
11493 X(_str, 6000, f8400000), \
11494 X(_strb, 7000, f8000000), \
11495 X(_strh, 8000, f8200000), \
11496 X(_str_sp,9000, f84d0000), \
11497 X(_sub, 1e00, eba00000), \
11498 X(_subs, 1e00, ebb00000), \
11499 X(_subi, 8000, f1a00000), \
11500 X(_subis, 8000, f1b00000), \
11501 X(_sxtb, b240, fa4ff080), \
11502 X(_sxth, b200, fa0ff080), \
11503 X(_tst, 4200, ea100f00), \
11504 X(_uxtb, b2c0, fa5ff080), \
11505 X(_uxth, b280, fa1ff080), \
11506 X(_nop, bf00, f3af8000), \
11507 X(_yield, bf10, f3af8001), \
11508 X(_wfe, bf20, f3af8002), \
11509 X(_wfi, bf30, f3af8003), \
11510 X(_wls, 0000, f040c001), \
11511 X(_wlstp, 0000, f000c001), \
11512 X(_sev, bf40, f3af8004), \
11513 X(_sevl, bf50, f3af8005), \
11514 X(_udf, de00, f7f0a000)
11515
11516 /* To catch errors in encoding functions, the codes are all offset by
11517 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11518 as 16-bit instructions. */
11519 #define X(a,b,c) T_MNEM##a
11520 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11521 #undef X
11522
11523 #define X(a,b,c) 0x##b
11524 static const unsigned short thumb_op16[] = { T16_32_TAB };
11525 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11526 #undef X
11527
11528 #define X(a,b,c) 0x##c
11529 static const unsigned int thumb_op32[] = { T16_32_TAB };
11530 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11531 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
11532 #undef X
11533 #undef T16_32_TAB
11534
11535 /* Thumb instruction encoders, in alphabetical order. */
11536
11537 /* ADDW or SUBW. */
11538
11539 static void
11540 do_t_add_sub_w (void)
11541 {
11542 int Rd, Rn;
11543
11544 Rd = inst.operands[0].reg;
11545 Rn = inst.operands[1].reg;
11546
11547 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11548 is the SP-{plus,minus}-immediate form of the instruction. */
11549 if (Rn == REG_SP)
11550 constraint (Rd == REG_PC, BAD_PC);
11551 else
11552 reject_bad_reg (Rd);
11553
11554 inst.instruction |= (Rn << 16) | (Rd << 8);
11555 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11556 }
11557
11558 /* Parse an add or subtract instruction. We get here with inst.instruction
11559 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
11560
11561 static void
11562 do_t_add_sub (void)
11563 {
11564 int Rd, Rs, Rn;
11565
11566 Rd = inst.operands[0].reg;
11567 Rs = (inst.operands[1].present
11568 ? inst.operands[1].reg /* Rd, Rs, foo */
11569 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11570
11571 if (Rd == REG_PC)
11572 set_pred_insn_type_last ();
11573
11574 if (unified_syntax)
11575 {
11576 bfd_boolean flags;
11577 bfd_boolean narrow;
11578 int opcode;
11579
11580 flags = (inst.instruction == T_MNEM_adds
11581 || inst.instruction == T_MNEM_subs);
11582 if (flags)
11583 narrow = !in_pred_block ();
11584 else
11585 narrow = in_pred_block ();
11586 if (!inst.operands[2].isreg)
11587 {
11588 int add;
11589
11590 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11591 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11592
11593 add = (inst.instruction == T_MNEM_add
11594 || inst.instruction == T_MNEM_adds);
11595 opcode = 0;
11596 if (inst.size_req != 4)
11597 {
11598 /* Attempt to use a narrow opcode, with relaxation if
11599 appropriate. */
11600 if (Rd == REG_SP && Rs == REG_SP && !flags)
11601 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11602 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11603 opcode = T_MNEM_add_sp;
11604 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11605 opcode = T_MNEM_add_pc;
11606 else if (Rd <= 7 && Rs <= 7 && narrow)
11607 {
11608 if (flags)
11609 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11610 else
11611 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11612 }
11613 if (opcode)
11614 {
11615 inst.instruction = THUMB_OP16(opcode);
11616 inst.instruction |= (Rd << 4) | Rs;
11617 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11618 || (inst.relocs[0].type
11619 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
11620 {
11621 if (inst.size_req == 2)
11622 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11623 else
11624 inst.relax = opcode;
11625 }
11626 }
11627 else
11628 constraint (inst.size_req == 2, BAD_HIREG);
11629 }
11630 if (inst.size_req == 4
11631 || (inst.size_req != 2 && !opcode))
11632 {
11633 constraint ((inst.relocs[0].type
11634 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11635 && (inst.relocs[0].type
11636 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
11637 THUMB1_RELOC_ONLY);
11638 if (Rd == REG_PC)
11639 {
11640 constraint (add, BAD_PC);
11641 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11642 _("only SUBS PC, LR, #const allowed"));
11643 constraint (inst.relocs[0].exp.X_op != O_constant,
11644 _("expression too complex"));
11645 constraint (inst.relocs[0].exp.X_add_number < 0
11646 || inst.relocs[0].exp.X_add_number > 0xff,
11647 _("immediate value out of range"));
11648 inst.instruction = T2_SUBS_PC_LR
11649 | inst.relocs[0].exp.X_add_number;
11650 inst.relocs[0].type = BFD_RELOC_UNUSED;
11651 return;
11652 }
11653 else if (Rs == REG_PC)
11654 {
11655 /* Always use addw/subw. */
11656 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
11657 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11658 }
11659 else
11660 {
11661 inst.instruction = THUMB_OP32 (inst.instruction);
11662 inst.instruction = (inst.instruction & 0xe1ffffff)
11663 | 0x10000000;
11664 if (flags)
11665 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11666 else
11667 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
11668 }
11669 inst.instruction |= Rd << 8;
11670 inst.instruction |= Rs << 16;
11671 }
11672 }
11673 else
11674 {
11675 unsigned int value = inst.relocs[0].exp.X_add_number;
11676 unsigned int shift = inst.operands[2].shift_kind;
11677
11678 Rn = inst.operands[2].reg;
11679 /* See if we can do this with a 16-bit instruction. */
11680 if (!inst.operands[2].shifted && inst.size_req != 4)
11681 {
11682 if (Rd > 7 || Rs > 7 || Rn > 7)
11683 narrow = FALSE;
11684
11685 if (narrow)
11686 {
11687 inst.instruction = ((inst.instruction == T_MNEM_adds
11688 || inst.instruction == T_MNEM_add)
11689 ? T_OPCODE_ADD_R3
11690 : T_OPCODE_SUB_R3);
11691 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11692 return;
11693 }
11694
11695 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
11696 {
11697 /* Thumb-1 cores (except v6-M) require at least one high
11698 register in a narrow non flag setting add. */
11699 if (Rd > 7 || Rn > 7
11700 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11701 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
11702 {
11703 if (Rd == Rn)
11704 {
11705 Rn = Rs;
11706 Rs = Rd;
11707 }
11708 inst.instruction = T_OPCODE_ADD_HI;
11709 inst.instruction |= (Rd & 8) << 4;
11710 inst.instruction |= (Rd & 7);
11711 inst.instruction |= Rn << 3;
11712 return;
11713 }
11714 }
11715 }
11716
11717 constraint (Rd == REG_PC, BAD_PC);
11718 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11719 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11720 constraint (Rs == REG_PC, BAD_PC);
11721 reject_bad_reg (Rn);
11722
11723 /* If we get here, it can't be done in 16 bits. */
11724 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11725 _("shift must be constant"));
11726 inst.instruction = THUMB_OP32 (inst.instruction);
11727 inst.instruction |= Rd << 8;
11728 inst.instruction |= Rs << 16;
11729 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11730 _("shift value over 3 not allowed in thumb mode"));
11731 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11732 _("only LSL shift allowed in thumb mode"));
11733 encode_thumb32_shifted_operand (2);
11734 }
11735 }
11736 else
11737 {
11738 constraint (inst.instruction == T_MNEM_adds
11739 || inst.instruction == T_MNEM_subs,
11740 BAD_THUMB32);
11741
11742 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
11743 {
11744 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11745 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11746 BAD_HIREG);
11747
11748 inst.instruction = (inst.instruction == T_MNEM_add
11749 ? 0x0000 : 0x8000);
11750 inst.instruction |= (Rd << 4) | Rs;
11751 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11752 return;
11753 }
11754
11755 Rn = inst.operands[2].reg;
11756 constraint (inst.operands[2].shifted, _("unshifted register required"));
11757
11758 /* We now have Rd, Rs, and Rn set to registers. */
11759 if (Rd > 7 || Rs > 7 || Rn > 7)
11760 {
11761 /* Can't do this for SUB. */
11762 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11763 inst.instruction = T_OPCODE_ADD_HI;
11764 inst.instruction |= (Rd & 8) << 4;
11765 inst.instruction |= (Rd & 7);
11766 if (Rs == Rd)
11767 inst.instruction |= Rn << 3;
11768 else if (Rn == Rd)
11769 inst.instruction |= Rs << 3;
11770 else
11771 constraint (1, _("dest must overlap one source register"));
11772 }
11773 else
11774 {
11775 inst.instruction = (inst.instruction == T_MNEM_add
11776 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11777 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11778 }
11779 }
11780 }
11781
11782 static void
11783 do_t_adr (void)
11784 {
11785 unsigned Rd;
11786
11787 Rd = inst.operands[0].reg;
11788 reject_bad_reg (Rd);
11789
11790 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
11791 {
11792 /* Defer to section relaxation. */
11793 inst.relax = inst.instruction;
11794 inst.instruction = THUMB_OP16 (inst.instruction);
11795 inst.instruction |= Rd << 4;
11796 }
11797 else if (unified_syntax && inst.size_req != 2)
11798 {
11799 /* Generate a 32-bit opcode. */
11800 inst.instruction = THUMB_OP32 (inst.instruction);
11801 inst.instruction |= Rd << 8;
11802 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11803 inst.relocs[0].pc_rel = 1;
11804 }
11805 else
11806 {
11807 /* Generate a 16-bit opcode. */
11808 inst.instruction = THUMB_OP16 (inst.instruction);
11809 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11810 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11811 inst.relocs[0].pc_rel = 1;
11812 inst.instruction |= Rd << 4;
11813 }
11814
11815 if (inst.relocs[0].exp.X_op == O_symbol
11816 && inst.relocs[0].exp.X_add_symbol != NULL
11817 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11818 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11819 inst.relocs[0].exp.X_add_number += 1;
11820 }
11821
11822 /* Arithmetic instructions for which there is just one 16-bit
11823 instruction encoding, and it allows only two low registers.
11824 For maximal compatibility with ARM syntax, we allow three register
11825 operands even when Thumb-32 instructions are not available, as long
11826 as the first two are identical. For instance, both "sbc r0,r1" and
11827 "sbc r0,r0,r1" are allowed. */
11828 static void
11829 do_t_arit3 (void)
11830 {
11831 int Rd, Rs, Rn;
11832
11833 Rd = inst.operands[0].reg;
11834 Rs = (inst.operands[1].present
11835 ? inst.operands[1].reg /* Rd, Rs, foo */
11836 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11837 Rn = inst.operands[2].reg;
11838
11839 reject_bad_reg (Rd);
11840 reject_bad_reg (Rs);
11841 if (inst.operands[2].isreg)
11842 reject_bad_reg (Rn);
11843
11844 if (unified_syntax)
11845 {
11846 if (!inst.operands[2].isreg)
11847 {
11848 /* For an immediate, we always generate a 32-bit opcode;
11849 section relaxation will shrink it later if possible. */
11850 inst.instruction = THUMB_OP32 (inst.instruction);
11851 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11852 inst.instruction |= Rd << 8;
11853 inst.instruction |= Rs << 16;
11854 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11855 }
11856 else
11857 {
11858 bfd_boolean narrow;
11859
11860 /* See if we can do this with a 16-bit instruction. */
11861 if (THUMB_SETS_FLAGS (inst.instruction))
11862 narrow = !in_pred_block ();
11863 else
11864 narrow = in_pred_block ();
11865
11866 if (Rd > 7 || Rn > 7 || Rs > 7)
11867 narrow = FALSE;
11868 if (inst.operands[2].shifted)
11869 narrow = FALSE;
11870 if (inst.size_req == 4)
11871 narrow = FALSE;
11872
11873 if (narrow
11874 && Rd == Rs)
11875 {
11876 inst.instruction = THUMB_OP16 (inst.instruction);
11877 inst.instruction |= Rd;
11878 inst.instruction |= Rn << 3;
11879 return;
11880 }
11881
11882 /* If we get here, it can't be done in 16 bits. */
11883 constraint (inst.operands[2].shifted
11884 && inst.operands[2].immisreg,
11885 _("shift must be constant"));
11886 inst.instruction = THUMB_OP32 (inst.instruction);
11887 inst.instruction |= Rd << 8;
11888 inst.instruction |= Rs << 16;
11889 encode_thumb32_shifted_operand (2);
11890 }
11891 }
11892 else
11893 {
11894 /* On its face this is a lie - the instruction does set the
11895 flags. However, the only supported mnemonic in this mode
11896 says it doesn't. */
11897 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11898
11899 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11900 _("unshifted register required"));
11901 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11902 constraint (Rd != Rs,
11903 _("dest and source1 must be the same register"));
11904
11905 inst.instruction = THUMB_OP16 (inst.instruction);
11906 inst.instruction |= Rd;
11907 inst.instruction |= Rn << 3;
11908 }
11909 }
11910
11911 /* Similarly, but for instructions where the arithmetic operation is
11912 commutative, so we can allow either of them to be different from
11913 the destination operand in a 16-bit instruction. For instance, all
11914 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11915 accepted. */
11916 static void
11917 do_t_arit3c (void)
11918 {
11919 int Rd, Rs, Rn;
11920
11921 Rd = inst.operands[0].reg;
11922 Rs = (inst.operands[1].present
11923 ? inst.operands[1].reg /* Rd, Rs, foo */
11924 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11925 Rn = inst.operands[2].reg;
11926
11927 reject_bad_reg (Rd);
11928 reject_bad_reg (Rs);
11929 if (inst.operands[2].isreg)
11930 reject_bad_reg (Rn);
11931
11932 if (unified_syntax)
11933 {
11934 if (!inst.operands[2].isreg)
11935 {
11936 /* For an immediate, we always generate a 32-bit opcode;
11937 section relaxation will shrink it later if possible. */
11938 inst.instruction = THUMB_OP32 (inst.instruction);
11939 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11940 inst.instruction |= Rd << 8;
11941 inst.instruction |= Rs << 16;
11942 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11943 }
11944 else
11945 {
11946 bfd_boolean narrow;
11947
11948 /* See if we can do this with a 16-bit instruction. */
11949 if (THUMB_SETS_FLAGS (inst.instruction))
11950 narrow = !in_pred_block ();
11951 else
11952 narrow = in_pred_block ();
11953
11954 if (Rd > 7 || Rn > 7 || Rs > 7)
11955 narrow = FALSE;
11956 if (inst.operands[2].shifted)
11957 narrow = FALSE;
11958 if (inst.size_req == 4)
11959 narrow = FALSE;
11960
11961 if (narrow)
11962 {
11963 if (Rd == Rs)
11964 {
11965 inst.instruction = THUMB_OP16 (inst.instruction);
11966 inst.instruction |= Rd;
11967 inst.instruction |= Rn << 3;
11968 return;
11969 }
11970 if (Rd == Rn)
11971 {
11972 inst.instruction = THUMB_OP16 (inst.instruction);
11973 inst.instruction |= Rd;
11974 inst.instruction |= Rs << 3;
11975 return;
11976 }
11977 }
11978
11979 /* If we get here, it can't be done in 16 bits. */
11980 constraint (inst.operands[2].shifted
11981 && inst.operands[2].immisreg,
11982 _("shift must be constant"));
11983 inst.instruction = THUMB_OP32 (inst.instruction);
11984 inst.instruction |= Rd << 8;
11985 inst.instruction |= Rs << 16;
11986 encode_thumb32_shifted_operand (2);
11987 }
11988 }
11989 else
11990 {
11991 /* On its face this is a lie - the instruction does set the
11992 flags. However, the only supported mnemonic in this mode
11993 says it doesn't. */
11994 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11995
11996 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11997 _("unshifted register required"));
11998 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11999
12000 inst.instruction = THUMB_OP16 (inst.instruction);
12001 inst.instruction |= Rd;
12002
12003 if (Rd == Rs)
12004 inst.instruction |= Rn << 3;
12005 else if (Rd == Rn)
12006 inst.instruction |= Rs << 3;
12007 else
12008 constraint (1, _("dest must overlap one source register"));
12009 }
12010 }
12011
12012 static void
12013 do_t_bfc (void)
12014 {
12015 unsigned Rd;
12016 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12017 constraint (msb > 32, _("bit-field extends past end of register"));
12018 /* The instruction encoding stores the LSB and MSB,
12019 not the LSB and width. */
12020 Rd = inst.operands[0].reg;
12021 reject_bad_reg (Rd);
12022 inst.instruction |= Rd << 8;
12023 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12024 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12025 inst.instruction |= msb - 1;
12026 }
12027
12028 static void
12029 do_t_bfi (void)
12030 {
12031 int Rd, Rn;
12032 unsigned int msb;
12033
12034 Rd = inst.operands[0].reg;
12035 reject_bad_reg (Rd);
12036
12037 /* #0 in second position is alternative syntax for bfc, which is
12038 the same instruction but with REG_PC in the Rm field. */
12039 if (!inst.operands[1].isreg)
12040 Rn = REG_PC;
12041 else
12042 {
12043 Rn = inst.operands[1].reg;
12044 reject_bad_reg (Rn);
12045 }
12046
12047 msb = inst.operands[2].imm + inst.operands[3].imm;
12048 constraint (msb > 32, _("bit-field extends past end of register"));
12049 /* The instruction encoding stores the LSB and MSB,
12050 not the LSB and width. */
12051 inst.instruction |= Rd << 8;
12052 inst.instruction |= Rn << 16;
12053 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12054 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12055 inst.instruction |= msb - 1;
12056 }
12057
12058 static void
12059 do_t_bfx (void)
12060 {
12061 unsigned Rd, Rn;
12062
12063 Rd = inst.operands[0].reg;
12064 Rn = inst.operands[1].reg;
12065
12066 reject_bad_reg (Rd);
12067 reject_bad_reg (Rn);
12068
12069 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12070 _("bit-field extends past end of register"));
12071 inst.instruction |= Rd << 8;
12072 inst.instruction |= Rn << 16;
12073 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12074 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12075 inst.instruction |= inst.operands[3].imm - 1;
12076 }
12077
12078 /* ARM V5 Thumb BLX (argument parse)
12079 BLX <target_addr> which is BLX(1)
12080 BLX <Rm> which is BLX(2)
12081 Unfortunately, there are two different opcodes for this mnemonic.
12082 So, the insns[].value is not used, and the code here zaps values
12083 into inst.instruction.
12084
12085 ??? How to take advantage of the additional two bits of displacement
12086 available in Thumb32 mode? Need new relocation? */
12087
12088 static void
12089 do_t_blx (void)
12090 {
12091 set_pred_insn_type_last ();
12092
12093 if (inst.operands[0].isreg)
12094 {
12095 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12096 /* We have a register, so this is BLX(2). */
12097 inst.instruction |= inst.operands[0].reg << 3;
12098 }
12099 else
12100 {
12101 /* No register. This must be BLX(1). */
12102 inst.instruction = 0xf000e800;
12103 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
12104 }
12105 }
12106
12107 static void
12108 do_t_branch (void)
12109 {
12110 int opcode;
12111 int cond;
12112 bfd_reloc_code_real_type reloc;
12113
12114 cond = inst.cond;
12115 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
12116
12117 if (in_pred_block ())
12118 {
12119 /* Conditional branches inside IT blocks are encoded as unconditional
12120 branches. */
12121 cond = COND_ALWAYS;
12122 }
12123 else
12124 cond = inst.cond;
12125
12126 if (cond != COND_ALWAYS)
12127 opcode = T_MNEM_bcond;
12128 else
12129 opcode = inst.instruction;
12130
12131 if (unified_syntax
12132 && (inst.size_req == 4
12133 || (inst.size_req != 2
12134 && (inst.operands[0].hasreloc
12135 || inst.relocs[0].exp.X_op == O_constant))))
12136 {
12137 inst.instruction = THUMB_OP32(opcode);
12138 if (cond == COND_ALWAYS)
12139 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
12140 else
12141 {
12142 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12143 _("selected architecture does not support "
12144 "wide conditional branch instruction"));
12145
12146 gas_assert (cond != 0xF);
12147 inst.instruction |= cond << 22;
12148 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
12149 }
12150 }
12151 else
12152 {
12153 inst.instruction = THUMB_OP16(opcode);
12154 if (cond == COND_ALWAYS)
12155 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
12156 else
12157 {
12158 inst.instruction |= cond << 8;
12159 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
12160 }
12161 /* Allow section relaxation. */
12162 if (unified_syntax && inst.size_req != 2)
12163 inst.relax = opcode;
12164 }
12165 inst.relocs[0].type = reloc;
12166 inst.relocs[0].pc_rel = 1;
12167 }
12168
12169 /* Actually do the work for Thumb state bkpt and hlt. The only difference
12170 between the two is the maximum immediate allowed - which is passed in
12171 RANGE. */
12172 static void
12173 do_t_bkpt_hlt1 (int range)
12174 {
12175 constraint (inst.cond != COND_ALWAYS,
12176 _("instruction is always unconditional"));
12177 if (inst.operands[0].present)
12178 {
12179 constraint (inst.operands[0].imm > range,
12180 _("immediate value out of range"));
12181 inst.instruction |= inst.operands[0].imm;
12182 }
12183
12184 set_pred_insn_type (NEUTRAL_IT_INSN);
12185 }
12186
12187 static void
12188 do_t_hlt (void)
12189 {
12190 do_t_bkpt_hlt1 (63);
12191 }
12192
12193 static void
12194 do_t_bkpt (void)
12195 {
12196 do_t_bkpt_hlt1 (255);
12197 }
12198
12199 static void
12200 do_t_branch23 (void)
12201 {
12202 set_pred_insn_type_last ();
12203 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
12204
12205 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12206 this file. We used to simply ignore the PLT reloc type here --
12207 the branch encoding is now needed to deal with TLSCALL relocs.
12208 So if we see a PLT reloc now, put it back to how it used to be to
12209 keep the preexisting behaviour. */
12210 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12211 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
12212
12213 #if defined(OBJ_COFF)
12214 /* If the destination of the branch is a defined symbol which does not have
12215 the THUMB_FUNC attribute, then we must be calling a function which has
12216 the (interfacearm) attribute. We look for the Thumb entry point to that
12217 function and change the branch to refer to that function instead. */
12218 if ( inst.relocs[0].exp.X_op == O_symbol
12219 && inst.relocs[0].exp.X_add_symbol != NULL
12220 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12221 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12222 inst.relocs[0].exp.X_add_symbol
12223 = find_real_start (inst.relocs[0].exp.X_add_symbol);
12224 #endif
12225 }
12226
12227 static void
12228 do_t_bx (void)
12229 {
12230 set_pred_insn_type_last ();
12231 inst.instruction |= inst.operands[0].reg << 3;
12232 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12233 should cause the alignment to be checked once it is known. This is
12234 because BX PC only works if the instruction is word aligned. */
12235 }
12236
12237 static void
12238 do_t_bxj (void)
12239 {
12240 int Rm;
12241
12242 set_pred_insn_type_last ();
12243 Rm = inst.operands[0].reg;
12244 reject_bad_reg (Rm);
12245 inst.instruction |= Rm << 16;
12246 }
12247
12248 static void
12249 do_t_clz (void)
12250 {
12251 unsigned Rd;
12252 unsigned Rm;
12253
12254 Rd = inst.operands[0].reg;
12255 Rm = inst.operands[1].reg;
12256
12257 reject_bad_reg (Rd);
12258 reject_bad_reg (Rm);
12259
12260 inst.instruction |= Rd << 8;
12261 inst.instruction |= Rm << 16;
12262 inst.instruction |= Rm;
12263 }
12264
12265 /* For the Armv8.1-M conditional instructions. */
12266 static void
12267 do_t_cond (void)
12268 {
12269 unsigned Rd, Rn, Rm;
12270 signed int cond;
12271
12272 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12273
12274 Rd = inst.operands[0].reg;
12275 switch (inst.instruction)
12276 {
12277 case T_MNEM_csinc:
12278 case T_MNEM_csinv:
12279 case T_MNEM_csneg:
12280 case T_MNEM_csel:
12281 Rn = inst.operands[1].reg;
12282 Rm = inst.operands[2].reg;
12283 cond = inst.operands[3].imm;
12284 constraint (Rn == REG_SP, BAD_SP);
12285 constraint (Rm == REG_SP, BAD_SP);
12286 break;
12287
12288 case T_MNEM_cinc:
12289 case T_MNEM_cinv:
12290 case T_MNEM_cneg:
12291 Rn = inst.operands[1].reg;
12292 cond = inst.operands[2].imm;
12293 /* Invert the last bit to invert the cond. */
12294 cond = TOGGLE_BIT (cond, 0);
12295 constraint (Rn == REG_SP, BAD_SP);
12296 Rm = Rn;
12297 break;
12298
12299 case T_MNEM_csetm:
12300 case T_MNEM_cset:
12301 cond = inst.operands[1].imm;
12302 /* Invert the last bit to invert the cond. */
12303 cond = TOGGLE_BIT (cond, 0);
12304 Rn = REG_PC;
12305 Rm = REG_PC;
12306 break;
12307
12308 default: abort ();
12309 }
12310
12311 set_pred_insn_type (OUTSIDE_PRED_INSN);
12312 inst.instruction = THUMB_OP32 (inst.instruction);
12313 inst.instruction |= Rd << 8;
12314 inst.instruction |= Rn << 16;
12315 inst.instruction |= Rm;
12316 inst.instruction |= cond << 4;
12317 }
12318
12319 static void
12320 do_t_csdb (void)
12321 {
12322 set_pred_insn_type (OUTSIDE_PRED_INSN);
12323 }
12324
12325 static void
12326 do_t_cps (void)
12327 {
12328 set_pred_insn_type (OUTSIDE_PRED_INSN);
12329 inst.instruction |= inst.operands[0].imm;
12330 }
12331
12332 static void
12333 do_t_cpsi (void)
12334 {
12335 set_pred_insn_type (OUTSIDE_PRED_INSN);
12336 if (unified_syntax
12337 && (inst.operands[1].present || inst.size_req == 4)
12338 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
12339 {
12340 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12341 inst.instruction = 0xf3af8000;
12342 inst.instruction |= imod << 9;
12343 inst.instruction |= inst.operands[0].imm << 5;
12344 if (inst.operands[1].present)
12345 inst.instruction |= 0x100 | inst.operands[1].imm;
12346 }
12347 else
12348 {
12349 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12350 && (inst.operands[0].imm & 4),
12351 _("selected processor does not support 'A' form "
12352 "of this instruction"));
12353 constraint (inst.operands[1].present || inst.size_req == 4,
12354 _("Thumb does not support the 2-argument "
12355 "form of this instruction"));
12356 inst.instruction |= inst.operands[0].imm;
12357 }
12358 }
12359
12360 /* THUMB CPY instruction (argument parse). */
12361
12362 static void
12363 do_t_cpy (void)
12364 {
12365 if (inst.size_req == 4)
12366 {
12367 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12368 inst.instruction |= inst.operands[0].reg << 8;
12369 inst.instruction |= inst.operands[1].reg;
12370 }
12371 else
12372 {
12373 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12374 inst.instruction |= (inst.operands[0].reg & 0x7);
12375 inst.instruction |= inst.operands[1].reg << 3;
12376 }
12377 }
12378
12379 static void
12380 do_t_cbz (void)
12381 {
12382 set_pred_insn_type (OUTSIDE_PRED_INSN);
12383 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12384 inst.instruction |= inst.operands[0].reg;
12385 inst.relocs[0].pc_rel = 1;
12386 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
12387 }
12388
12389 static void
12390 do_t_dbg (void)
12391 {
12392 inst.instruction |= inst.operands[0].imm;
12393 }
12394
12395 static void
12396 do_t_div (void)
12397 {
12398 unsigned Rd, Rn, Rm;
12399
12400 Rd = inst.operands[0].reg;
12401 Rn = (inst.operands[1].present
12402 ? inst.operands[1].reg : Rd);
12403 Rm = inst.operands[2].reg;
12404
12405 reject_bad_reg (Rd);
12406 reject_bad_reg (Rn);
12407 reject_bad_reg (Rm);
12408
12409 inst.instruction |= Rd << 8;
12410 inst.instruction |= Rn << 16;
12411 inst.instruction |= Rm;
12412 }
12413
12414 static void
12415 do_t_hint (void)
12416 {
12417 if (unified_syntax && inst.size_req == 4)
12418 inst.instruction = THUMB_OP32 (inst.instruction);
12419 else
12420 inst.instruction = THUMB_OP16 (inst.instruction);
12421 }
12422
12423 static void
12424 do_t_it (void)
12425 {
12426 unsigned int cond = inst.operands[0].imm;
12427
12428 set_pred_insn_type (IT_INSN);
12429 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12430 now_pred.cc = cond;
12431 now_pred.warn_deprecated = FALSE;
12432 now_pred.type = SCALAR_PRED;
12433
12434 /* If the condition is a negative condition, invert the mask. */
12435 if ((cond & 0x1) == 0x0)
12436 {
12437 unsigned int mask = inst.instruction & 0x000f;
12438
12439 if ((mask & 0x7) == 0)
12440 {
12441 /* No conversion needed. */
12442 now_pred.block_length = 1;
12443 }
12444 else if ((mask & 0x3) == 0)
12445 {
12446 mask ^= 0x8;
12447 now_pred.block_length = 2;
12448 }
12449 else if ((mask & 0x1) == 0)
12450 {
12451 mask ^= 0xC;
12452 now_pred.block_length = 3;
12453 }
12454 else
12455 {
12456 mask ^= 0xE;
12457 now_pred.block_length = 4;
12458 }
12459
12460 inst.instruction &= 0xfff0;
12461 inst.instruction |= mask;
12462 }
12463
12464 inst.instruction |= cond << 4;
12465 }
12466
12467 /* Helper function used for both push/pop and ldm/stm. */
12468 static void
12469 encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12470 bfd_boolean writeback)
12471 {
12472 bfd_boolean load, store;
12473
12474 gas_assert (base != -1 || !do_io);
12475 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12476 store = do_io && !load;
12477
12478 if (mask & (1 << 13))
12479 inst.error = _("SP not allowed in register list");
12480
12481 if (do_io && (mask & (1 << base)) != 0
12482 && writeback)
12483 inst.error = _("having the base register in the register list when "
12484 "using write back is UNPREDICTABLE");
12485
12486 if (load)
12487 {
12488 if (mask & (1 << 15))
12489 {
12490 if (mask & (1 << 14))
12491 inst.error = _("LR and PC should not both be in register list");
12492 else
12493 set_pred_insn_type_last ();
12494 }
12495 }
12496 else if (store)
12497 {
12498 if (mask & (1 << 15))
12499 inst.error = _("PC not allowed in register list");
12500 }
12501
12502 if (do_io && ((mask & (mask - 1)) == 0))
12503 {
12504 /* Single register transfers implemented as str/ldr. */
12505 if (writeback)
12506 {
12507 if (inst.instruction & (1 << 23))
12508 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12509 else
12510 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12511 }
12512 else
12513 {
12514 if (inst.instruction & (1 << 23))
12515 inst.instruction = 0x00800000; /* ia -> [base] */
12516 else
12517 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12518 }
12519
12520 inst.instruction |= 0xf8400000;
12521 if (load)
12522 inst.instruction |= 0x00100000;
12523
12524 mask = ffs (mask) - 1;
12525 mask <<= 12;
12526 }
12527 else if (writeback)
12528 inst.instruction |= WRITE_BACK;
12529
12530 inst.instruction |= mask;
12531 if (do_io)
12532 inst.instruction |= base << 16;
12533 }
12534
12535 static void
12536 do_t_ldmstm (void)
12537 {
12538 /* This really doesn't seem worth it. */
12539 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12540 _("expression too complex"));
12541 constraint (inst.operands[1].writeback,
12542 _("Thumb load/store multiple does not support {reglist}^"));
12543
12544 if (unified_syntax)
12545 {
12546 bfd_boolean narrow;
12547 unsigned mask;
12548
12549 narrow = FALSE;
12550 /* See if we can use a 16-bit instruction. */
12551 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12552 && inst.size_req != 4
12553 && !(inst.operands[1].imm & ~0xff))
12554 {
12555 mask = 1 << inst.operands[0].reg;
12556
12557 if (inst.operands[0].reg <= 7)
12558 {
12559 if (inst.instruction == T_MNEM_stmia
12560 ? inst.operands[0].writeback
12561 : (inst.operands[0].writeback
12562 == !(inst.operands[1].imm & mask)))
12563 {
12564 if (inst.instruction == T_MNEM_stmia
12565 && (inst.operands[1].imm & mask)
12566 && (inst.operands[1].imm & (mask - 1)))
12567 as_warn (_("value stored for r%d is UNKNOWN"),
12568 inst.operands[0].reg);
12569
12570 inst.instruction = THUMB_OP16 (inst.instruction);
12571 inst.instruction |= inst.operands[0].reg << 8;
12572 inst.instruction |= inst.operands[1].imm;
12573 narrow = TRUE;
12574 }
12575 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12576 {
12577 /* This means 1 register in reg list one of 3 situations:
12578 1. Instruction is stmia, but without writeback.
12579 2. lmdia without writeback, but with Rn not in
12580 reglist.
12581 3. ldmia with writeback, but with Rn in reglist.
12582 Case 3 is UNPREDICTABLE behaviour, so we handle
12583 case 1 and 2 which can be converted into a 16-bit
12584 str or ldr. The SP cases are handled below. */
12585 unsigned long opcode;
12586 /* First, record an error for Case 3. */
12587 if (inst.operands[1].imm & mask
12588 && inst.operands[0].writeback)
12589 inst.error =
12590 _("having the base register in the register list when "
12591 "using write back is UNPREDICTABLE");
12592
12593 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
12594 : T_MNEM_ldr);
12595 inst.instruction = THUMB_OP16 (opcode);
12596 inst.instruction |= inst.operands[0].reg << 3;
12597 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12598 narrow = TRUE;
12599 }
12600 }
12601 else if (inst.operands[0] .reg == REG_SP)
12602 {
12603 if (inst.operands[0].writeback)
12604 {
12605 inst.instruction =
12606 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12607 ? T_MNEM_push : T_MNEM_pop);
12608 inst.instruction |= inst.operands[1].imm;
12609 narrow = TRUE;
12610 }
12611 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12612 {
12613 inst.instruction =
12614 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12615 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
12616 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
12617 narrow = TRUE;
12618 }
12619 }
12620 }
12621
12622 if (!narrow)
12623 {
12624 if (inst.instruction < 0xffff)
12625 inst.instruction = THUMB_OP32 (inst.instruction);
12626
12627 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12628 inst.operands[1].imm,
12629 inst.operands[0].writeback);
12630 }
12631 }
12632 else
12633 {
12634 constraint (inst.operands[0].reg > 7
12635 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
12636 constraint (inst.instruction != T_MNEM_ldmia
12637 && inst.instruction != T_MNEM_stmia,
12638 _("Thumb-2 instruction only valid in unified syntax"));
12639 if (inst.instruction == T_MNEM_stmia)
12640 {
12641 if (!inst.operands[0].writeback)
12642 as_warn (_("this instruction will write back the base register"));
12643 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12644 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
12645 as_warn (_("value stored for r%d is UNKNOWN"),
12646 inst.operands[0].reg);
12647 }
12648 else
12649 {
12650 if (!inst.operands[0].writeback
12651 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12652 as_warn (_("this instruction will write back the base register"));
12653 else if (inst.operands[0].writeback
12654 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12655 as_warn (_("this instruction will not write back the base register"));
12656 }
12657
12658 inst.instruction = THUMB_OP16 (inst.instruction);
12659 inst.instruction |= inst.operands[0].reg << 8;
12660 inst.instruction |= inst.operands[1].imm;
12661 }
12662 }
12663
12664 static void
12665 do_t_ldrex (void)
12666 {
12667 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12668 || inst.operands[1].postind || inst.operands[1].writeback
12669 || inst.operands[1].immisreg || inst.operands[1].shifted
12670 || inst.operands[1].negative,
12671 BAD_ADDR_MODE);
12672
12673 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12674
12675 inst.instruction |= inst.operands[0].reg << 12;
12676 inst.instruction |= inst.operands[1].reg << 16;
12677 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
12678 }
12679
12680 static void
12681 do_t_ldrexd (void)
12682 {
12683 if (!inst.operands[1].present)
12684 {
12685 constraint (inst.operands[0].reg == REG_LR,
12686 _("r14 not allowed as first register "
12687 "when second register is omitted"));
12688 inst.operands[1].reg = inst.operands[0].reg + 1;
12689 }
12690 constraint (inst.operands[0].reg == inst.operands[1].reg,
12691 BAD_OVERLAP);
12692
12693 inst.instruction |= inst.operands[0].reg << 12;
12694 inst.instruction |= inst.operands[1].reg << 8;
12695 inst.instruction |= inst.operands[2].reg << 16;
12696 }
12697
12698 static void
12699 do_t_ldst (void)
12700 {
12701 unsigned long opcode;
12702 int Rn;
12703
12704 if (inst.operands[0].isreg
12705 && !inst.operands[0].preind
12706 && inst.operands[0].reg == REG_PC)
12707 set_pred_insn_type_last ();
12708
12709 opcode = inst.instruction;
12710 if (unified_syntax)
12711 {
12712 if (!inst.operands[1].isreg)
12713 {
12714 if (opcode <= 0xffff)
12715 inst.instruction = THUMB_OP32 (opcode);
12716 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12717 return;
12718 }
12719 if (inst.operands[1].isreg
12720 && !inst.operands[1].writeback
12721 && !inst.operands[1].shifted && !inst.operands[1].postind
12722 && !inst.operands[1].negative && inst.operands[0].reg <= 7
12723 && opcode <= 0xffff
12724 && inst.size_req != 4)
12725 {
12726 /* Insn may have a 16-bit form. */
12727 Rn = inst.operands[1].reg;
12728 if (inst.operands[1].immisreg)
12729 {
12730 inst.instruction = THUMB_OP16 (opcode);
12731 /* [Rn, Rik] */
12732 if (Rn <= 7 && inst.operands[1].imm <= 7)
12733 goto op16;
12734 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12735 reject_bad_reg (inst.operands[1].imm);
12736 }
12737 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12738 && opcode != T_MNEM_ldrsb)
12739 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12740 || (Rn == REG_SP && opcode == T_MNEM_str))
12741 {
12742 /* [Rn, #const] */
12743 if (Rn > 7)
12744 {
12745 if (Rn == REG_PC)
12746 {
12747 if (inst.relocs[0].pc_rel)
12748 opcode = T_MNEM_ldr_pc2;
12749 else
12750 opcode = T_MNEM_ldr_pc;
12751 }
12752 else
12753 {
12754 if (opcode == T_MNEM_ldr)
12755 opcode = T_MNEM_ldr_sp;
12756 else
12757 opcode = T_MNEM_str_sp;
12758 }
12759 inst.instruction = inst.operands[0].reg << 8;
12760 }
12761 else
12762 {
12763 inst.instruction = inst.operands[0].reg;
12764 inst.instruction |= inst.operands[1].reg << 3;
12765 }
12766 inst.instruction |= THUMB_OP16 (opcode);
12767 if (inst.size_req == 2)
12768 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12769 else
12770 inst.relax = opcode;
12771 return;
12772 }
12773 }
12774 /* Definitely a 32-bit variant. */
12775
12776 /* Warning for Erratum 752419. */
12777 if (opcode == T_MNEM_ldr
12778 && inst.operands[0].reg == REG_SP
12779 && inst.operands[1].writeback == 1
12780 && !inst.operands[1].immisreg)
12781 {
12782 if (no_cpu_selected ()
12783 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
12784 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12785 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
12786 as_warn (_("This instruction may be unpredictable "
12787 "if executed on M-profile cores "
12788 "with interrupts enabled."));
12789 }
12790
12791 /* Do some validations regarding addressing modes. */
12792 if (inst.operands[1].immisreg)
12793 reject_bad_reg (inst.operands[1].imm);
12794
12795 constraint (inst.operands[1].writeback == 1
12796 && inst.operands[0].reg == inst.operands[1].reg,
12797 BAD_OVERLAP);
12798
12799 inst.instruction = THUMB_OP32 (opcode);
12800 inst.instruction |= inst.operands[0].reg << 12;
12801 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
12802 check_ldr_r15_aligned ();
12803 return;
12804 }
12805
12806 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12807
12808 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
12809 {
12810 /* Only [Rn,Rm] is acceptable. */
12811 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12812 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12813 || inst.operands[1].postind || inst.operands[1].shifted
12814 || inst.operands[1].negative,
12815 _("Thumb does not support this addressing mode"));
12816 inst.instruction = THUMB_OP16 (inst.instruction);
12817 goto op16;
12818 }
12819
12820 inst.instruction = THUMB_OP16 (inst.instruction);
12821 if (!inst.operands[1].isreg)
12822 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12823 return;
12824
12825 constraint (!inst.operands[1].preind
12826 || inst.operands[1].shifted
12827 || inst.operands[1].writeback,
12828 _("Thumb does not support this addressing mode"));
12829 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
12830 {
12831 constraint (inst.instruction & 0x0600,
12832 _("byte or halfword not valid for base register"));
12833 constraint (inst.operands[1].reg == REG_PC
12834 && !(inst.instruction & THUMB_LOAD_BIT),
12835 _("r15 based store not allowed"));
12836 constraint (inst.operands[1].immisreg,
12837 _("invalid base register for register offset"));
12838
12839 if (inst.operands[1].reg == REG_PC)
12840 inst.instruction = T_OPCODE_LDR_PC;
12841 else if (inst.instruction & THUMB_LOAD_BIT)
12842 inst.instruction = T_OPCODE_LDR_SP;
12843 else
12844 inst.instruction = T_OPCODE_STR_SP;
12845
12846 inst.instruction |= inst.operands[0].reg << 8;
12847 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12848 return;
12849 }
12850
12851 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12852 if (!inst.operands[1].immisreg)
12853 {
12854 /* Immediate offset. */
12855 inst.instruction |= inst.operands[0].reg;
12856 inst.instruction |= inst.operands[1].reg << 3;
12857 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12858 return;
12859 }
12860
12861 /* Register offset. */
12862 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12863 constraint (inst.operands[1].negative,
12864 _("Thumb does not support this addressing mode"));
12865
12866 op16:
12867 switch (inst.instruction)
12868 {
12869 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12870 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12871 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12872 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12873 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12874 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12875 case 0x5600 /* ldrsb */:
12876 case 0x5e00 /* ldrsh */: break;
12877 default: abort ();
12878 }
12879
12880 inst.instruction |= inst.operands[0].reg;
12881 inst.instruction |= inst.operands[1].reg << 3;
12882 inst.instruction |= inst.operands[1].imm << 6;
12883 }
12884
12885 static void
12886 do_t_ldstd (void)
12887 {
12888 if (!inst.operands[1].present)
12889 {
12890 inst.operands[1].reg = inst.operands[0].reg + 1;
12891 constraint (inst.operands[0].reg == REG_LR,
12892 _("r14 not allowed here"));
12893 constraint (inst.operands[0].reg == REG_R12,
12894 _("r12 not allowed here"));
12895 }
12896
12897 if (inst.operands[2].writeback
12898 && (inst.operands[0].reg == inst.operands[2].reg
12899 || inst.operands[1].reg == inst.operands[2].reg))
12900 as_warn (_("base register written back, and overlaps "
12901 "one of transfer registers"));
12902
12903 inst.instruction |= inst.operands[0].reg << 12;
12904 inst.instruction |= inst.operands[1].reg << 8;
12905 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
12906 }
12907
12908 static void
12909 do_t_ldstt (void)
12910 {
12911 inst.instruction |= inst.operands[0].reg << 12;
12912 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12913 }
12914
12915 static void
12916 do_t_mla (void)
12917 {
12918 unsigned Rd, Rn, Rm, Ra;
12919
12920 Rd = inst.operands[0].reg;
12921 Rn = inst.operands[1].reg;
12922 Rm = inst.operands[2].reg;
12923 Ra = inst.operands[3].reg;
12924
12925 reject_bad_reg (Rd);
12926 reject_bad_reg (Rn);
12927 reject_bad_reg (Rm);
12928 reject_bad_reg (Ra);
12929
12930 inst.instruction |= Rd << 8;
12931 inst.instruction |= Rn << 16;
12932 inst.instruction |= Rm;
12933 inst.instruction |= Ra << 12;
12934 }
12935
12936 static void
12937 do_t_mlal (void)
12938 {
12939 unsigned RdLo, RdHi, Rn, Rm;
12940
12941 RdLo = inst.operands[0].reg;
12942 RdHi = inst.operands[1].reg;
12943 Rn = inst.operands[2].reg;
12944 Rm = inst.operands[3].reg;
12945
12946 reject_bad_reg (RdLo);
12947 reject_bad_reg (RdHi);
12948 reject_bad_reg (Rn);
12949 reject_bad_reg (Rm);
12950
12951 inst.instruction |= RdLo << 12;
12952 inst.instruction |= RdHi << 8;
12953 inst.instruction |= Rn << 16;
12954 inst.instruction |= Rm;
12955 }
12956
12957 static void
12958 do_t_mov_cmp (void)
12959 {
12960 unsigned Rn, Rm;
12961
12962 Rn = inst.operands[0].reg;
12963 Rm = inst.operands[1].reg;
12964
12965 if (Rn == REG_PC)
12966 set_pred_insn_type_last ();
12967
12968 if (unified_syntax)
12969 {
12970 int r0off = (inst.instruction == T_MNEM_mov
12971 || inst.instruction == T_MNEM_movs) ? 8 : 16;
12972 unsigned long opcode;
12973 bfd_boolean narrow;
12974 bfd_boolean low_regs;
12975
12976 low_regs = (Rn <= 7 && Rm <= 7);
12977 opcode = inst.instruction;
12978 if (in_pred_block ())
12979 narrow = opcode != T_MNEM_movs;
12980 else
12981 narrow = opcode != T_MNEM_movs || low_regs;
12982 if (inst.size_req == 4
12983 || inst.operands[1].shifted)
12984 narrow = FALSE;
12985
12986 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12987 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12988 && !inst.operands[1].shifted
12989 && Rn == REG_PC
12990 && Rm == REG_LR)
12991 {
12992 inst.instruction = T2_SUBS_PC_LR;
12993 return;
12994 }
12995
12996 if (opcode == T_MNEM_cmp)
12997 {
12998 constraint (Rn == REG_PC, BAD_PC);
12999 if (narrow)
13000 {
13001 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
13002 but valid. */
13003 warn_deprecated_sp (Rm);
13004 /* R15 was documented as a valid choice for Rm in ARMv6,
13005 but as UNPREDICTABLE in ARMv7. ARM's proprietary
13006 tools reject R15, so we do too. */
13007 constraint (Rm == REG_PC, BAD_PC);
13008 }
13009 else
13010 reject_bad_reg (Rm);
13011 }
13012 else if (opcode == T_MNEM_mov
13013 || opcode == T_MNEM_movs)
13014 {
13015 if (inst.operands[1].isreg)
13016 {
13017 if (opcode == T_MNEM_movs)
13018 {
13019 reject_bad_reg (Rn);
13020 reject_bad_reg (Rm);
13021 }
13022 else if (narrow)
13023 {
13024 /* This is mov.n. */
13025 if ((Rn == REG_SP || Rn == REG_PC)
13026 && (Rm == REG_SP || Rm == REG_PC))
13027 {
13028 as_tsktsk (_("Use of r%u as a source register is "
13029 "deprecated when r%u is the destination "
13030 "register."), Rm, Rn);
13031 }
13032 }
13033 else
13034 {
13035 /* This is mov.w. */
13036 constraint (Rn == REG_PC, BAD_PC);
13037 constraint (Rm == REG_PC, BAD_PC);
13038 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13039 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
13040 }
13041 }
13042 else
13043 reject_bad_reg (Rn);
13044 }
13045
13046 if (!inst.operands[1].isreg)
13047 {
13048 /* Immediate operand. */
13049 if (!in_pred_block () && opcode == T_MNEM_mov)
13050 narrow = 0;
13051 if (low_regs && narrow)
13052 {
13053 inst.instruction = THUMB_OP16 (opcode);
13054 inst.instruction |= Rn << 8;
13055 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13056 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
13057 {
13058 if (inst.size_req == 2)
13059 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13060 else
13061 inst.relax = opcode;
13062 }
13063 }
13064 else
13065 {
13066 constraint ((inst.relocs[0].type
13067 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13068 && (inst.relocs[0].type
13069 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
13070 THUMB1_RELOC_ONLY);
13071
13072 inst.instruction = THUMB_OP32 (inst.instruction);
13073 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13074 inst.instruction |= Rn << r0off;
13075 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13076 }
13077 }
13078 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13079 && (inst.instruction == T_MNEM_mov
13080 || inst.instruction == T_MNEM_movs))
13081 {
13082 /* Register shifts are encoded as separate shift instructions. */
13083 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
13084
13085 if (in_pred_block ())
13086 narrow = !flags;
13087 else
13088 narrow = flags;
13089
13090 if (inst.size_req == 4)
13091 narrow = FALSE;
13092
13093 if (!low_regs || inst.operands[1].imm > 7)
13094 narrow = FALSE;
13095
13096 if (Rn != Rm)
13097 narrow = FALSE;
13098
13099 switch (inst.operands[1].shift_kind)
13100 {
13101 case SHIFT_LSL:
13102 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13103 break;
13104 case SHIFT_ASR:
13105 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13106 break;
13107 case SHIFT_LSR:
13108 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13109 break;
13110 case SHIFT_ROR:
13111 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13112 break;
13113 default:
13114 abort ();
13115 }
13116
13117 inst.instruction = opcode;
13118 if (narrow)
13119 {
13120 inst.instruction |= Rn;
13121 inst.instruction |= inst.operands[1].imm << 3;
13122 }
13123 else
13124 {
13125 if (flags)
13126 inst.instruction |= CONDS_BIT;
13127
13128 inst.instruction |= Rn << 8;
13129 inst.instruction |= Rm << 16;
13130 inst.instruction |= inst.operands[1].imm;
13131 }
13132 }
13133 else if (!narrow)
13134 {
13135 /* Some mov with immediate shift have narrow variants.
13136 Register shifts are handled above. */
13137 if (low_regs && inst.operands[1].shifted
13138 && (inst.instruction == T_MNEM_mov
13139 || inst.instruction == T_MNEM_movs))
13140 {
13141 if (in_pred_block ())
13142 narrow = (inst.instruction == T_MNEM_mov);
13143 else
13144 narrow = (inst.instruction == T_MNEM_movs);
13145 }
13146
13147 if (narrow)
13148 {
13149 switch (inst.operands[1].shift_kind)
13150 {
13151 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13152 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13153 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13154 default: narrow = FALSE; break;
13155 }
13156 }
13157
13158 if (narrow)
13159 {
13160 inst.instruction |= Rn;
13161 inst.instruction |= Rm << 3;
13162 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13163 }
13164 else
13165 {
13166 inst.instruction = THUMB_OP32 (inst.instruction);
13167 inst.instruction |= Rn << r0off;
13168 encode_thumb32_shifted_operand (1);
13169 }
13170 }
13171 else
13172 switch (inst.instruction)
13173 {
13174 case T_MNEM_mov:
13175 /* In v4t or v5t a move of two lowregs produces unpredictable
13176 results. Don't allow this. */
13177 if (low_regs)
13178 {
13179 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13180 "MOV Rd, Rs with two low registers is not "
13181 "permitted on this architecture");
13182 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13183 arm_ext_v6);
13184 }
13185
13186 inst.instruction = T_OPCODE_MOV_HR;
13187 inst.instruction |= (Rn & 0x8) << 4;
13188 inst.instruction |= (Rn & 0x7);
13189 inst.instruction |= Rm << 3;
13190 break;
13191
13192 case T_MNEM_movs:
13193 /* We know we have low registers at this point.
13194 Generate LSLS Rd, Rs, #0. */
13195 inst.instruction = T_OPCODE_LSL_I;
13196 inst.instruction |= Rn;
13197 inst.instruction |= Rm << 3;
13198 break;
13199
13200 case T_MNEM_cmp:
13201 if (low_regs)
13202 {
13203 inst.instruction = T_OPCODE_CMP_LR;
13204 inst.instruction |= Rn;
13205 inst.instruction |= Rm << 3;
13206 }
13207 else
13208 {
13209 inst.instruction = T_OPCODE_CMP_HR;
13210 inst.instruction |= (Rn & 0x8) << 4;
13211 inst.instruction |= (Rn & 0x7);
13212 inst.instruction |= Rm << 3;
13213 }
13214 break;
13215 }
13216 return;
13217 }
13218
13219 inst.instruction = THUMB_OP16 (inst.instruction);
13220
13221 /* PR 10443: Do not silently ignore shifted operands. */
13222 constraint (inst.operands[1].shifted,
13223 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13224
13225 if (inst.operands[1].isreg)
13226 {
13227 if (Rn < 8 && Rm < 8)
13228 {
13229 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13230 since a MOV instruction produces unpredictable results. */
13231 if (inst.instruction == T_OPCODE_MOV_I8)
13232 inst.instruction = T_OPCODE_ADD_I3;
13233 else
13234 inst.instruction = T_OPCODE_CMP_LR;
13235
13236 inst.instruction |= Rn;
13237 inst.instruction |= Rm << 3;
13238 }
13239 else
13240 {
13241 if (inst.instruction == T_OPCODE_MOV_I8)
13242 inst.instruction = T_OPCODE_MOV_HR;
13243 else
13244 inst.instruction = T_OPCODE_CMP_HR;
13245 do_t_cpy ();
13246 }
13247 }
13248 else
13249 {
13250 constraint (Rn > 7,
13251 _("only lo regs allowed with immediate"));
13252 inst.instruction |= Rn << 8;
13253 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13254 }
13255 }
13256
13257 static void
13258 do_t_mov16 (void)
13259 {
13260 unsigned Rd;
13261 bfd_vma imm;
13262 bfd_boolean top;
13263
13264 top = (inst.instruction & 0x00800000) != 0;
13265 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
13266 {
13267 constraint (top, _(":lower16: not allowed in this instruction"));
13268 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
13269 }
13270 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
13271 {
13272 constraint (!top, _(":upper16: not allowed in this instruction"));
13273 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
13274 }
13275
13276 Rd = inst.operands[0].reg;
13277 reject_bad_reg (Rd);
13278
13279 inst.instruction |= Rd << 8;
13280 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
13281 {
13282 imm = inst.relocs[0].exp.X_add_number;
13283 inst.instruction |= (imm & 0xf000) << 4;
13284 inst.instruction |= (imm & 0x0800) << 15;
13285 inst.instruction |= (imm & 0x0700) << 4;
13286 inst.instruction |= (imm & 0x00ff);
13287 }
13288 }
13289
13290 static void
13291 do_t_mvn_tst (void)
13292 {
13293 unsigned Rn, Rm;
13294
13295 Rn = inst.operands[0].reg;
13296 Rm = inst.operands[1].reg;
13297
13298 if (inst.instruction == T_MNEM_cmp
13299 || inst.instruction == T_MNEM_cmn)
13300 constraint (Rn == REG_PC, BAD_PC);
13301 else
13302 reject_bad_reg (Rn);
13303 reject_bad_reg (Rm);
13304
13305 if (unified_syntax)
13306 {
13307 int r0off = (inst.instruction == T_MNEM_mvn
13308 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
13309 bfd_boolean narrow;
13310
13311 if (inst.size_req == 4
13312 || inst.instruction > 0xffff
13313 || inst.operands[1].shifted
13314 || Rn > 7 || Rm > 7)
13315 narrow = FALSE;
13316 else if (inst.instruction == T_MNEM_cmn
13317 || inst.instruction == T_MNEM_tst)
13318 narrow = TRUE;
13319 else if (THUMB_SETS_FLAGS (inst.instruction))
13320 narrow = !in_pred_block ();
13321 else
13322 narrow = in_pred_block ();
13323
13324 if (!inst.operands[1].isreg)
13325 {
13326 /* For an immediate, we always generate a 32-bit opcode;
13327 section relaxation will shrink it later if possible. */
13328 if (inst.instruction < 0xffff)
13329 inst.instruction = THUMB_OP32 (inst.instruction);
13330 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13331 inst.instruction |= Rn << r0off;
13332 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13333 }
13334 else
13335 {
13336 /* See if we can do this with a 16-bit instruction. */
13337 if (narrow)
13338 {
13339 inst.instruction = THUMB_OP16 (inst.instruction);
13340 inst.instruction |= Rn;
13341 inst.instruction |= Rm << 3;
13342 }
13343 else
13344 {
13345 constraint (inst.operands[1].shifted
13346 && inst.operands[1].immisreg,
13347 _("shift must be constant"));
13348 if (inst.instruction < 0xffff)
13349 inst.instruction = THUMB_OP32 (inst.instruction);
13350 inst.instruction |= Rn << r0off;
13351 encode_thumb32_shifted_operand (1);
13352 }
13353 }
13354 }
13355 else
13356 {
13357 constraint (inst.instruction > 0xffff
13358 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13359 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13360 _("unshifted register required"));
13361 constraint (Rn > 7 || Rm > 7,
13362 BAD_HIREG);
13363
13364 inst.instruction = THUMB_OP16 (inst.instruction);
13365 inst.instruction |= Rn;
13366 inst.instruction |= Rm << 3;
13367 }
13368 }
13369
13370 static void
13371 do_t_mrs (void)
13372 {
13373 unsigned Rd;
13374
13375 if (do_vfp_nsyn_mrs () == SUCCESS)
13376 return;
13377
13378 Rd = inst.operands[0].reg;
13379 reject_bad_reg (Rd);
13380 inst.instruction |= Rd << 8;
13381
13382 if (inst.operands[1].isreg)
13383 {
13384 unsigned br = inst.operands[1].reg;
13385 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13386 as_bad (_("bad register for mrs"));
13387
13388 inst.instruction |= br & (0xf << 16);
13389 inst.instruction |= (br & 0x300) >> 4;
13390 inst.instruction |= (br & SPSR_BIT) >> 2;
13391 }
13392 else
13393 {
13394 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13395
13396 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13397 {
13398 /* PR gas/12698: The constraint is only applied for m_profile.
13399 If the user has specified -march=all, we want to ignore it as
13400 we are building for any CPU type, including non-m variants. */
13401 bfd_boolean m_profile =
13402 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13403 constraint ((flags != 0) && m_profile, _("selected processor does "
13404 "not support requested special purpose register"));
13405 }
13406 else
13407 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13408 devices). */
13409 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13410 _("'APSR', 'CPSR' or 'SPSR' expected"));
13411
13412 inst.instruction |= (flags & SPSR_BIT) >> 2;
13413 inst.instruction |= inst.operands[1].imm & 0xff;
13414 inst.instruction |= 0xf0000;
13415 }
13416 }
13417
13418 static void
13419 do_t_msr (void)
13420 {
13421 int flags;
13422 unsigned Rn;
13423
13424 if (do_vfp_nsyn_msr () == SUCCESS)
13425 return;
13426
13427 constraint (!inst.operands[1].isreg,
13428 _("Thumb encoding does not support an immediate here"));
13429
13430 if (inst.operands[0].isreg)
13431 flags = (int)(inst.operands[0].reg);
13432 else
13433 flags = inst.operands[0].imm;
13434
13435 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13436 {
13437 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13438
13439 /* PR gas/12698: The constraint is only applied for m_profile.
13440 If the user has specified -march=all, we want to ignore it as
13441 we are building for any CPU type, including non-m variants. */
13442 bfd_boolean m_profile =
13443 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13444 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13445 && (bits & ~(PSR_s | PSR_f)) != 0)
13446 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13447 && bits != PSR_f)) && m_profile,
13448 _("selected processor does not support requested special "
13449 "purpose register"));
13450 }
13451 else
13452 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13453 "requested special purpose register"));
13454
13455 Rn = inst.operands[1].reg;
13456 reject_bad_reg (Rn);
13457
13458 inst.instruction |= (flags & SPSR_BIT) >> 2;
13459 inst.instruction |= (flags & 0xf0000) >> 8;
13460 inst.instruction |= (flags & 0x300) >> 4;
13461 inst.instruction |= (flags & 0xff);
13462 inst.instruction |= Rn << 16;
13463 }
13464
13465 static void
13466 do_t_mul (void)
13467 {
13468 bfd_boolean narrow;
13469 unsigned Rd, Rn, Rm;
13470
13471 if (!inst.operands[2].present)
13472 inst.operands[2].reg = inst.operands[0].reg;
13473
13474 Rd = inst.operands[0].reg;
13475 Rn = inst.operands[1].reg;
13476 Rm = inst.operands[2].reg;
13477
13478 if (unified_syntax)
13479 {
13480 if (inst.size_req == 4
13481 || (Rd != Rn
13482 && Rd != Rm)
13483 || Rn > 7
13484 || Rm > 7)
13485 narrow = FALSE;
13486 else if (inst.instruction == T_MNEM_muls)
13487 narrow = !in_pred_block ();
13488 else
13489 narrow = in_pred_block ();
13490 }
13491 else
13492 {
13493 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
13494 constraint (Rn > 7 || Rm > 7,
13495 BAD_HIREG);
13496 narrow = TRUE;
13497 }
13498
13499 if (narrow)
13500 {
13501 /* 16-bit MULS/Conditional MUL. */
13502 inst.instruction = THUMB_OP16 (inst.instruction);
13503 inst.instruction |= Rd;
13504
13505 if (Rd == Rn)
13506 inst.instruction |= Rm << 3;
13507 else if (Rd == Rm)
13508 inst.instruction |= Rn << 3;
13509 else
13510 constraint (1, _("dest must overlap one source register"));
13511 }
13512 else
13513 {
13514 constraint (inst.instruction != T_MNEM_mul,
13515 _("Thumb-2 MUL must not set flags"));
13516 /* 32-bit MUL. */
13517 inst.instruction = THUMB_OP32 (inst.instruction);
13518 inst.instruction |= Rd << 8;
13519 inst.instruction |= Rn << 16;
13520 inst.instruction |= Rm << 0;
13521
13522 reject_bad_reg (Rd);
13523 reject_bad_reg (Rn);
13524 reject_bad_reg (Rm);
13525 }
13526 }
13527
13528 static void
13529 do_t_mull (void)
13530 {
13531 unsigned RdLo, RdHi, Rn, Rm;
13532
13533 RdLo = inst.operands[0].reg;
13534 RdHi = inst.operands[1].reg;
13535 Rn = inst.operands[2].reg;
13536 Rm = inst.operands[3].reg;
13537
13538 reject_bad_reg (RdLo);
13539 reject_bad_reg (RdHi);
13540 reject_bad_reg (Rn);
13541 reject_bad_reg (Rm);
13542
13543 inst.instruction |= RdLo << 12;
13544 inst.instruction |= RdHi << 8;
13545 inst.instruction |= Rn << 16;
13546 inst.instruction |= Rm;
13547
13548 if (RdLo == RdHi)
13549 as_tsktsk (_("rdhi and rdlo must be different"));
13550 }
13551
13552 static void
13553 do_t_nop (void)
13554 {
13555 set_pred_insn_type (NEUTRAL_IT_INSN);
13556
13557 if (unified_syntax)
13558 {
13559 if (inst.size_req == 4 || inst.operands[0].imm > 15)
13560 {
13561 inst.instruction = THUMB_OP32 (inst.instruction);
13562 inst.instruction |= inst.operands[0].imm;
13563 }
13564 else
13565 {
13566 /* PR9722: Check for Thumb2 availability before
13567 generating a thumb2 nop instruction. */
13568 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
13569 {
13570 inst.instruction = THUMB_OP16 (inst.instruction);
13571 inst.instruction |= inst.operands[0].imm << 4;
13572 }
13573 else
13574 inst.instruction = 0x46c0;
13575 }
13576 }
13577 else
13578 {
13579 constraint (inst.operands[0].present,
13580 _("Thumb does not support NOP with hints"));
13581 inst.instruction = 0x46c0;
13582 }
13583 }
13584
13585 static void
13586 do_t_neg (void)
13587 {
13588 if (unified_syntax)
13589 {
13590 bfd_boolean narrow;
13591
13592 if (THUMB_SETS_FLAGS (inst.instruction))
13593 narrow = !in_pred_block ();
13594 else
13595 narrow = in_pred_block ();
13596 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13597 narrow = FALSE;
13598 if (inst.size_req == 4)
13599 narrow = FALSE;
13600
13601 if (!narrow)
13602 {
13603 inst.instruction = THUMB_OP32 (inst.instruction);
13604 inst.instruction |= inst.operands[0].reg << 8;
13605 inst.instruction |= inst.operands[1].reg << 16;
13606 }
13607 else
13608 {
13609 inst.instruction = THUMB_OP16 (inst.instruction);
13610 inst.instruction |= inst.operands[0].reg;
13611 inst.instruction |= inst.operands[1].reg << 3;
13612 }
13613 }
13614 else
13615 {
13616 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13617 BAD_HIREG);
13618 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13619
13620 inst.instruction = THUMB_OP16 (inst.instruction);
13621 inst.instruction |= inst.operands[0].reg;
13622 inst.instruction |= inst.operands[1].reg << 3;
13623 }
13624 }
13625
13626 static void
13627 do_t_orn (void)
13628 {
13629 unsigned Rd, Rn;
13630
13631 Rd = inst.operands[0].reg;
13632 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13633
13634 reject_bad_reg (Rd);
13635 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13636 reject_bad_reg (Rn);
13637
13638 inst.instruction |= Rd << 8;
13639 inst.instruction |= Rn << 16;
13640
13641 if (!inst.operands[2].isreg)
13642 {
13643 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13644 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13645 }
13646 else
13647 {
13648 unsigned Rm;
13649
13650 Rm = inst.operands[2].reg;
13651 reject_bad_reg (Rm);
13652
13653 constraint (inst.operands[2].shifted
13654 && inst.operands[2].immisreg,
13655 _("shift must be constant"));
13656 encode_thumb32_shifted_operand (2);
13657 }
13658 }
13659
13660 static void
13661 do_t_pkhbt (void)
13662 {
13663 unsigned Rd, Rn, Rm;
13664
13665 Rd = inst.operands[0].reg;
13666 Rn = inst.operands[1].reg;
13667 Rm = inst.operands[2].reg;
13668
13669 reject_bad_reg (Rd);
13670 reject_bad_reg (Rn);
13671 reject_bad_reg (Rm);
13672
13673 inst.instruction |= Rd << 8;
13674 inst.instruction |= Rn << 16;
13675 inst.instruction |= Rm;
13676 if (inst.operands[3].present)
13677 {
13678 unsigned int val = inst.relocs[0].exp.X_add_number;
13679 constraint (inst.relocs[0].exp.X_op != O_constant,
13680 _("expression too complex"));
13681 inst.instruction |= (val & 0x1c) << 10;
13682 inst.instruction |= (val & 0x03) << 6;
13683 }
13684 }
13685
13686 static void
13687 do_t_pkhtb (void)
13688 {
13689 if (!inst.operands[3].present)
13690 {
13691 unsigned Rtmp;
13692
13693 inst.instruction &= ~0x00000020;
13694
13695 /* PR 10168. Swap the Rm and Rn registers. */
13696 Rtmp = inst.operands[1].reg;
13697 inst.operands[1].reg = inst.operands[2].reg;
13698 inst.operands[2].reg = Rtmp;
13699 }
13700 do_t_pkhbt ();
13701 }
13702
13703 static void
13704 do_t_pld (void)
13705 {
13706 if (inst.operands[0].immisreg)
13707 reject_bad_reg (inst.operands[0].imm);
13708
13709 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13710 }
13711
13712 static void
13713 do_t_push_pop (void)
13714 {
13715 unsigned mask;
13716
13717 constraint (inst.operands[0].writeback,
13718 _("push/pop do not support {reglist}^"));
13719 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
13720 _("expression too complex"));
13721
13722 mask = inst.operands[0].imm;
13723 if (inst.size_req != 4 && (mask & ~0xff) == 0)
13724 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
13725 else if (inst.size_req != 4
13726 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
13727 ? REG_LR : REG_PC)))
13728 {
13729 inst.instruction = THUMB_OP16 (inst.instruction);
13730 inst.instruction |= THUMB_PP_PC_LR;
13731 inst.instruction |= mask & 0xff;
13732 }
13733 else if (unified_syntax)
13734 {
13735 inst.instruction = THUMB_OP32 (inst.instruction);
13736 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13737 }
13738 else
13739 {
13740 inst.error = _("invalid register list to push/pop instruction");
13741 return;
13742 }
13743 }
13744
13745 static void
13746 do_t_clrm (void)
13747 {
13748 if (unified_syntax)
13749 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
13750 else
13751 {
13752 inst.error = _("invalid register list to push/pop instruction");
13753 return;
13754 }
13755 }
13756
13757 static void
13758 do_t_vscclrm (void)
13759 {
13760 if (inst.operands[0].issingle)
13761 {
13762 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13763 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13764 inst.instruction |= inst.operands[0].imm;
13765 }
13766 else
13767 {
13768 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13769 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13770 inst.instruction |= 1 << 8;
13771 inst.instruction |= inst.operands[0].imm << 1;
13772 }
13773 }
13774
13775 static void
13776 do_t_rbit (void)
13777 {
13778 unsigned Rd, Rm;
13779
13780 Rd = inst.operands[0].reg;
13781 Rm = inst.operands[1].reg;
13782
13783 reject_bad_reg (Rd);
13784 reject_bad_reg (Rm);
13785
13786 inst.instruction |= Rd << 8;
13787 inst.instruction |= Rm << 16;
13788 inst.instruction |= Rm;
13789 }
13790
13791 static void
13792 do_t_rev (void)
13793 {
13794 unsigned Rd, Rm;
13795
13796 Rd = inst.operands[0].reg;
13797 Rm = inst.operands[1].reg;
13798
13799 reject_bad_reg (Rd);
13800 reject_bad_reg (Rm);
13801
13802 if (Rd <= 7 && Rm <= 7
13803 && inst.size_req != 4)
13804 {
13805 inst.instruction = THUMB_OP16 (inst.instruction);
13806 inst.instruction |= Rd;
13807 inst.instruction |= Rm << 3;
13808 }
13809 else if (unified_syntax)
13810 {
13811 inst.instruction = THUMB_OP32 (inst.instruction);
13812 inst.instruction |= Rd << 8;
13813 inst.instruction |= Rm << 16;
13814 inst.instruction |= Rm;
13815 }
13816 else
13817 inst.error = BAD_HIREG;
13818 }
13819
13820 static void
13821 do_t_rrx (void)
13822 {
13823 unsigned Rd, Rm;
13824
13825 Rd = inst.operands[0].reg;
13826 Rm = inst.operands[1].reg;
13827
13828 reject_bad_reg (Rd);
13829 reject_bad_reg (Rm);
13830
13831 inst.instruction |= Rd << 8;
13832 inst.instruction |= Rm;
13833 }
13834
13835 static void
13836 do_t_rsb (void)
13837 {
13838 unsigned Rd, Rs;
13839
13840 Rd = inst.operands[0].reg;
13841 Rs = (inst.operands[1].present
13842 ? inst.operands[1].reg /* Rd, Rs, foo */
13843 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
13844
13845 reject_bad_reg (Rd);
13846 reject_bad_reg (Rs);
13847 if (inst.operands[2].isreg)
13848 reject_bad_reg (inst.operands[2].reg);
13849
13850 inst.instruction |= Rd << 8;
13851 inst.instruction |= Rs << 16;
13852 if (!inst.operands[2].isreg)
13853 {
13854 bfd_boolean narrow;
13855
13856 if ((inst.instruction & 0x00100000) != 0)
13857 narrow = !in_pred_block ();
13858 else
13859 narrow = in_pred_block ();
13860
13861 if (Rd > 7 || Rs > 7)
13862 narrow = FALSE;
13863
13864 if (inst.size_req == 4 || !unified_syntax)
13865 narrow = FALSE;
13866
13867 if (inst.relocs[0].exp.X_op != O_constant
13868 || inst.relocs[0].exp.X_add_number != 0)
13869 narrow = FALSE;
13870
13871 /* Turn rsb #0 into 16-bit neg. We should probably do this via
13872 relaxation, but it doesn't seem worth the hassle. */
13873 if (narrow)
13874 {
13875 inst.relocs[0].type = BFD_RELOC_UNUSED;
13876 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13877 inst.instruction |= Rs << 3;
13878 inst.instruction |= Rd;
13879 }
13880 else
13881 {
13882 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13883 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13884 }
13885 }
13886 else
13887 encode_thumb32_shifted_operand (2);
13888 }
13889
13890 static void
13891 do_t_setend (void)
13892 {
13893 if (warn_on_deprecated
13894 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13895 as_tsktsk (_("setend use is deprecated for ARMv8"));
13896
13897 set_pred_insn_type (OUTSIDE_PRED_INSN);
13898 if (inst.operands[0].imm)
13899 inst.instruction |= 0x8;
13900 }
13901
13902 static void
13903 do_t_shift (void)
13904 {
13905 if (!inst.operands[1].present)
13906 inst.operands[1].reg = inst.operands[0].reg;
13907
13908 if (unified_syntax)
13909 {
13910 bfd_boolean narrow;
13911 int shift_kind;
13912
13913 switch (inst.instruction)
13914 {
13915 case T_MNEM_asr:
13916 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13917 case T_MNEM_lsl:
13918 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13919 case T_MNEM_lsr:
13920 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13921 case T_MNEM_ror:
13922 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13923 default: abort ();
13924 }
13925
13926 if (THUMB_SETS_FLAGS (inst.instruction))
13927 narrow = !in_pred_block ();
13928 else
13929 narrow = in_pred_block ();
13930 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13931 narrow = FALSE;
13932 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13933 narrow = FALSE;
13934 if (inst.operands[2].isreg
13935 && (inst.operands[1].reg != inst.operands[0].reg
13936 || inst.operands[2].reg > 7))
13937 narrow = FALSE;
13938 if (inst.size_req == 4)
13939 narrow = FALSE;
13940
13941 reject_bad_reg (inst.operands[0].reg);
13942 reject_bad_reg (inst.operands[1].reg);
13943
13944 if (!narrow)
13945 {
13946 if (inst.operands[2].isreg)
13947 {
13948 reject_bad_reg (inst.operands[2].reg);
13949 inst.instruction = THUMB_OP32 (inst.instruction);
13950 inst.instruction |= inst.operands[0].reg << 8;
13951 inst.instruction |= inst.operands[1].reg << 16;
13952 inst.instruction |= inst.operands[2].reg;
13953
13954 /* PR 12854: Error on extraneous shifts. */
13955 constraint (inst.operands[2].shifted,
13956 _("extraneous shift as part of operand to shift insn"));
13957 }
13958 else
13959 {
13960 inst.operands[1].shifted = 1;
13961 inst.operands[1].shift_kind = shift_kind;
13962 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13963 ? T_MNEM_movs : T_MNEM_mov);
13964 inst.instruction |= inst.operands[0].reg << 8;
13965 encode_thumb32_shifted_operand (1);
13966 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
13967 inst.relocs[0].type = BFD_RELOC_UNUSED;
13968 }
13969 }
13970 else
13971 {
13972 if (inst.operands[2].isreg)
13973 {
13974 switch (shift_kind)
13975 {
13976 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13977 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13978 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13979 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
13980 default: abort ();
13981 }
13982
13983 inst.instruction |= inst.operands[0].reg;
13984 inst.instruction |= inst.operands[2].reg << 3;
13985
13986 /* PR 12854: Error on extraneous shifts. */
13987 constraint (inst.operands[2].shifted,
13988 _("extraneous shift as part of operand to shift insn"));
13989 }
13990 else
13991 {
13992 switch (shift_kind)
13993 {
13994 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13995 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13996 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13997 default: abort ();
13998 }
13999 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
14000 inst.instruction |= inst.operands[0].reg;
14001 inst.instruction |= inst.operands[1].reg << 3;
14002 }
14003 }
14004 }
14005 else
14006 {
14007 constraint (inst.operands[0].reg > 7
14008 || inst.operands[1].reg > 7, BAD_HIREG);
14009 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
14010
14011 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14012 {
14013 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14014 constraint (inst.operands[0].reg != inst.operands[1].reg,
14015 _("source1 and dest must be same register"));
14016
14017 switch (inst.instruction)
14018 {
14019 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14020 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14021 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14022 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14023 default: abort ();
14024 }
14025
14026 inst.instruction |= inst.operands[0].reg;
14027 inst.instruction |= inst.operands[2].reg << 3;
14028
14029 /* PR 12854: Error on extraneous shifts. */
14030 constraint (inst.operands[2].shifted,
14031 _("extraneous shift as part of operand to shift insn"));
14032 }
14033 else
14034 {
14035 switch (inst.instruction)
14036 {
14037 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14038 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14039 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14040 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14041 default: abort ();
14042 }
14043 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
14044 inst.instruction |= inst.operands[0].reg;
14045 inst.instruction |= inst.operands[1].reg << 3;
14046 }
14047 }
14048 }
14049
14050 static void
14051 do_t_simd (void)
14052 {
14053 unsigned Rd, Rn, Rm;
14054
14055 Rd = inst.operands[0].reg;
14056 Rn = inst.operands[1].reg;
14057 Rm = inst.operands[2].reg;
14058
14059 reject_bad_reg (Rd);
14060 reject_bad_reg (Rn);
14061 reject_bad_reg (Rm);
14062
14063 inst.instruction |= Rd << 8;
14064 inst.instruction |= Rn << 16;
14065 inst.instruction |= Rm;
14066 }
14067
14068 static void
14069 do_t_simd2 (void)
14070 {
14071 unsigned Rd, Rn, Rm;
14072
14073 Rd = inst.operands[0].reg;
14074 Rm = inst.operands[1].reg;
14075 Rn = inst.operands[2].reg;
14076
14077 reject_bad_reg (Rd);
14078 reject_bad_reg (Rn);
14079 reject_bad_reg (Rm);
14080
14081 inst.instruction |= Rd << 8;
14082 inst.instruction |= Rn << 16;
14083 inst.instruction |= Rm;
14084 }
14085
14086 static void
14087 do_t_smc (void)
14088 {
14089 unsigned int value = inst.relocs[0].exp.X_add_number;
14090 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14091 _("SMC is not permitted on this architecture"));
14092 constraint (inst.relocs[0].exp.X_op != O_constant,
14093 _("expression too complex"));
14094 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14095
14096 inst.relocs[0].type = BFD_RELOC_UNUSED;
14097 inst.instruction |= (value & 0x000f) << 16;
14098
14099 /* PR gas/15623: SMC instructions must be last in an IT block. */
14100 set_pred_insn_type_last ();
14101 }
14102
14103 static void
14104 do_t_hvc (void)
14105 {
14106 unsigned int value = inst.relocs[0].exp.X_add_number;
14107
14108 inst.relocs[0].type = BFD_RELOC_UNUSED;
14109 inst.instruction |= (value & 0x0fff);
14110 inst.instruction |= (value & 0xf000) << 4;
14111 }
14112
14113 static void
14114 do_t_ssat_usat (int bias)
14115 {
14116 unsigned Rd, Rn;
14117
14118 Rd = inst.operands[0].reg;
14119 Rn = inst.operands[2].reg;
14120
14121 reject_bad_reg (Rd);
14122 reject_bad_reg (Rn);
14123
14124 inst.instruction |= Rd << 8;
14125 inst.instruction |= inst.operands[1].imm - bias;
14126 inst.instruction |= Rn << 16;
14127
14128 if (inst.operands[3].present)
14129 {
14130 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
14131
14132 inst.relocs[0].type = BFD_RELOC_UNUSED;
14133
14134 constraint (inst.relocs[0].exp.X_op != O_constant,
14135 _("expression too complex"));
14136
14137 if (shift_amount != 0)
14138 {
14139 constraint (shift_amount > 31,
14140 _("shift expression is too large"));
14141
14142 if (inst.operands[3].shift_kind == SHIFT_ASR)
14143 inst.instruction |= 0x00200000; /* sh bit. */
14144
14145 inst.instruction |= (shift_amount & 0x1c) << 10;
14146 inst.instruction |= (shift_amount & 0x03) << 6;
14147 }
14148 }
14149 }
14150
14151 static void
14152 do_t_ssat (void)
14153 {
14154 do_t_ssat_usat (1);
14155 }
14156
14157 static void
14158 do_t_ssat16 (void)
14159 {
14160 unsigned Rd, Rn;
14161
14162 Rd = inst.operands[0].reg;
14163 Rn = inst.operands[2].reg;
14164
14165 reject_bad_reg (Rd);
14166 reject_bad_reg (Rn);
14167
14168 inst.instruction |= Rd << 8;
14169 inst.instruction |= inst.operands[1].imm - 1;
14170 inst.instruction |= Rn << 16;
14171 }
14172
14173 static void
14174 do_t_strex (void)
14175 {
14176 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14177 || inst.operands[2].postind || inst.operands[2].writeback
14178 || inst.operands[2].immisreg || inst.operands[2].shifted
14179 || inst.operands[2].negative,
14180 BAD_ADDR_MODE);
14181
14182 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14183
14184 inst.instruction |= inst.operands[0].reg << 8;
14185 inst.instruction |= inst.operands[1].reg << 12;
14186 inst.instruction |= inst.operands[2].reg << 16;
14187 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
14188 }
14189
14190 static void
14191 do_t_strexd (void)
14192 {
14193 if (!inst.operands[2].present)
14194 inst.operands[2].reg = inst.operands[1].reg + 1;
14195
14196 constraint (inst.operands[0].reg == inst.operands[1].reg
14197 || inst.operands[0].reg == inst.operands[2].reg
14198 || inst.operands[0].reg == inst.operands[3].reg,
14199 BAD_OVERLAP);
14200
14201 inst.instruction |= inst.operands[0].reg;
14202 inst.instruction |= inst.operands[1].reg << 12;
14203 inst.instruction |= inst.operands[2].reg << 8;
14204 inst.instruction |= inst.operands[3].reg << 16;
14205 }
14206
14207 static void
14208 do_t_sxtah (void)
14209 {
14210 unsigned Rd, Rn, Rm;
14211
14212 Rd = inst.operands[0].reg;
14213 Rn = inst.operands[1].reg;
14214 Rm = inst.operands[2].reg;
14215
14216 reject_bad_reg (Rd);
14217 reject_bad_reg (Rn);
14218 reject_bad_reg (Rm);
14219
14220 inst.instruction |= Rd << 8;
14221 inst.instruction |= Rn << 16;
14222 inst.instruction |= Rm;
14223 inst.instruction |= inst.operands[3].imm << 4;
14224 }
14225
14226 static void
14227 do_t_sxth (void)
14228 {
14229 unsigned Rd, Rm;
14230
14231 Rd = inst.operands[0].reg;
14232 Rm = inst.operands[1].reg;
14233
14234 reject_bad_reg (Rd);
14235 reject_bad_reg (Rm);
14236
14237 if (inst.instruction <= 0xffff
14238 && inst.size_req != 4
14239 && Rd <= 7 && Rm <= 7
14240 && (!inst.operands[2].present || inst.operands[2].imm == 0))
14241 {
14242 inst.instruction = THUMB_OP16 (inst.instruction);
14243 inst.instruction |= Rd;
14244 inst.instruction |= Rm << 3;
14245 }
14246 else if (unified_syntax)
14247 {
14248 if (inst.instruction <= 0xffff)
14249 inst.instruction = THUMB_OP32 (inst.instruction);
14250 inst.instruction |= Rd << 8;
14251 inst.instruction |= Rm;
14252 inst.instruction |= inst.operands[2].imm << 4;
14253 }
14254 else
14255 {
14256 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14257 _("Thumb encoding does not support rotation"));
14258 constraint (1, BAD_HIREG);
14259 }
14260 }
14261
14262 static void
14263 do_t_swi (void)
14264 {
14265 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
14266 }
14267
14268 static void
14269 do_t_tb (void)
14270 {
14271 unsigned Rn, Rm;
14272 int half;
14273
14274 half = (inst.instruction & 0x10) != 0;
14275 set_pred_insn_type_last ();
14276 constraint (inst.operands[0].immisreg,
14277 _("instruction requires register index"));
14278
14279 Rn = inst.operands[0].reg;
14280 Rm = inst.operands[0].imm;
14281
14282 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14283 constraint (Rn == REG_SP, BAD_SP);
14284 reject_bad_reg (Rm);
14285
14286 constraint (!half && inst.operands[0].shifted,
14287 _("instruction does not allow shifted index"));
14288 inst.instruction |= (Rn << 16) | Rm;
14289 }
14290
14291 static void
14292 do_t_udf (void)
14293 {
14294 if (!inst.operands[0].present)
14295 inst.operands[0].imm = 0;
14296
14297 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14298 {
14299 constraint (inst.size_req == 2,
14300 _("immediate value out of range"));
14301 inst.instruction = THUMB_OP32 (inst.instruction);
14302 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14303 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14304 }
14305 else
14306 {
14307 inst.instruction = THUMB_OP16 (inst.instruction);
14308 inst.instruction |= inst.operands[0].imm;
14309 }
14310
14311 set_pred_insn_type (NEUTRAL_IT_INSN);
14312 }
14313
14314
14315 static void
14316 do_t_usat (void)
14317 {
14318 do_t_ssat_usat (0);
14319 }
14320
14321 static void
14322 do_t_usat16 (void)
14323 {
14324 unsigned Rd, Rn;
14325
14326 Rd = inst.operands[0].reg;
14327 Rn = inst.operands[2].reg;
14328
14329 reject_bad_reg (Rd);
14330 reject_bad_reg (Rn);
14331
14332 inst.instruction |= Rd << 8;
14333 inst.instruction |= inst.operands[1].imm;
14334 inst.instruction |= Rn << 16;
14335 }
14336
14337 /* Checking the range of the branch offset (VAL) with NBITS bits
14338 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14339 static int
14340 v8_1_branch_value_check (int val, int nbits, int is_signed)
14341 {
14342 gas_assert (nbits > 0 && nbits <= 32);
14343 if (is_signed)
14344 {
14345 int cmp = (1 << (nbits - 1));
14346 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14347 return FAIL;
14348 }
14349 else
14350 {
14351 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14352 return FAIL;
14353 }
14354 return SUCCESS;
14355 }
14356
14357 /* For branches in Armv8.1-M Mainline. */
14358 static void
14359 do_t_branch_future (void)
14360 {
14361 unsigned long insn = inst.instruction;
14362
14363 inst.instruction = THUMB_OP32 (inst.instruction);
14364 if (inst.operands[0].hasreloc == 0)
14365 {
14366 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14367 as_bad (BAD_BRANCH_OFF);
14368
14369 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14370 }
14371 else
14372 {
14373 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14374 inst.relocs[0].pc_rel = 1;
14375 }
14376
14377 switch (insn)
14378 {
14379 case T_MNEM_bf:
14380 if (inst.operands[1].hasreloc == 0)
14381 {
14382 int val = inst.operands[1].imm;
14383 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14384 as_bad (BAD_BRANCH_OFF);
14385
14386 int immA = (val & 0x0001f000) >> 12;
14387 int immB = (val & 0x00000ffc) >> 2;
14388 int immC = (val & 0x00000002) >> 1;
14389 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14390 }
14391 else
14392 {
14393 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14394 inst.relocs[1].pc_rel = 1;
14395 }
14396 break;
14397
14398 case T_MNEM_bfl:
14399 if (inst.operands[1].hasreloc == 0)
14400 {
14401 int val = inst.operands[1].imm;
14402 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14403 as_bad (BAD_BRANCH_OFF);
14404
14405 int immA = (val & 0x0007f000) >> 12;
14406 int immB = (val & 0x00000ffc) >> 2;
14407 int immC = (val & 0x00000002) >> 1;
14408 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14409 }
14410 else
14411 {
14412 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14413 inst.relocs[1].pc_rel = 1;
14414 }
14415 break;
14416
14417 case T_MNEM_bfcsel:
14418 /* Operand 1. */
14419 if (inst.operands[1].hasreloc == 0)
14420 {
14421 int val = inst.operands[1].imm;
14422 int immA = (val & 0x00001000) >> 12;
14423 int immB = (val & 0x00000ffc) >> 2;
14424 int immC = (val & 0x00000002) >> 1;
14425 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14426 }
14427 else
14428 {
14429 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14430 inst.relocs[1].pc_rel = 1;
14431 }
14432
14433 /* Operand 2. */
14434 if (inst.operands[2].hasreloc == 0)
14435 {
14436 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14437 int val2 = inst.operands[2].imm;
14438 int val0 = inst.operands[0].imm & 0x1f;
14439 int diff = val2 - val0;
14440 if (diff == 4)
14441 inst.instruction |= 1 << 17; /* T bit. */
14442 else if (diff != 2)
14443 as_bad (_("out of range label-relative fixup value"));
14444 }
14445 else
14446 {
14447 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14448 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14449 inst.relocs[2].pc_rel = 1;
14450 }
14451
14452 /* Operand 3. */
14453 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14454 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14455 break;
14456
14457 case T_MNEM_bfx:
14458 case T_MNEM_bflx:
14459 inst.instruction |= inst.operands[1].reg << 16;
14460 break;
14461
14462 default: abort ();
14463 }
14464 }
14465
14466 /* Helper function for do_t_loloop to handle relocations. */
14467 static void
14468 v8_1_loop_reloc (int is_le)
14469 {
14470 if (inst.relocs[0].exp.X_op == O_constant)
14471 {
14472 int value = inst.relocs[0].exp.X_add_number;
14473 value = (is_le) ? -value : value;
14474
14475 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14476 as_bad (BAD_BRANCH_OFF);
14477
14478 int imml, immh;
14479
14480 immh = (value & 0x00000ffc) >> 2;
14481 imml = (value & 0x00000002) >> 1;
14482
14483 inst.instruction |= (imml << 11) | (immh << 1);
14484 }
14485 else
14486 {
14487 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14488 inst.relocs[0].pc_rel = 1;
14489 }
14490 }
14491
14492 /* For shifts with four operands in MVE. */
14493 static void
14494 do_mve_scalar_shift1 (void)
14495 {
14496 unsigned int value = inst.operands[2].imm;
14497
14498 inst.instruction |= inst.operands[0].reg << 16;
14499 inst.instruction |= inst.operands[1].reg << 8;
14500
14501 /* Setting the bit for saturation. */
14502 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14503
14504 /* Assuming Rm is already checked not to be 11x1. */
14505 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14506 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14507 inst.instruction |= inst.operands[3].reg << 12;
14508 }
14509
14510 /* For shifts in MVE. */
14511 static void
14512 do_mve_scalar_shift (void)
14513 {
14514 if (!inst.operands[2].present)
14515 {
14516 inst.operands[2] = inst.operands[1];
14517 inst.operands[1].reg = 0xf;
14518 }
14519
14520 inst.instruction |= inst.operands[0].reg << 16;
14521 inst.instruction |= inst.operands[1].reg << 8;
14522
14523 if (inst.operands[2].isreg)
14524 {
14525 /* Assuming Rm is already checked not to be 11x1. */
14526 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14527 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14528 inst.instruction |= inst.operands[2].reg << 12;
14529 }
14530 else
14531 {
14532 /* Assuming imm is already checked as [1,32]. */
14533 unsigned int value = inst.operands[2].imm;
14534 inst.instruction |= (value & 0x1c) << 10;
14535 inst.instruction |= (value & 0x03) << 6;
14536 /* Change last 4 bits from 0xd to 0xf. */
14537 inst.instruction |= 0x2;
14538 }
14539 }
14540
14541 /* MVE instruction encoder helpers. */
14542 #define M_MNEM_vabav 0xee800f01
14543 #define M_MNEM_vmladav 0xeef00e00
14544 #define M_MNEM_vmladava 0xeef00e20
14545 #define M_MNEM_vmladavx 0xeef01e00
14546 #define M_MNEM_vmladavax 0xeef01e20
14547 #define M_MNEM_vmlsdav 0xeef00e01
14548 #define M_MNEM_vmlsdava 0xeef00e21
14549 #define M_MNEM_vmlsdavx 0xeef01e01
14550 #define M_MNEM_vmlsdavax 0xeef01e21
14551 #define M_MNEM_vmullt 0xee011e00
14552 #define M_MNEM_vmullb 0xee010e00
14553 #define M_MNEM_vctp 0xf000e801
14554 #define M_MNEM_vst20 0xfc801e00
14555 #define M_MNEM_vst21 0xfc801e20
14556 #define M_MNEM_vst40 0xfc801e01
14557 #define M_MNEM_vst41 0xfc801e21
14558 #define M_MNEM_vst42 0xfc801e41
14559 #define M_MNEM_vst43 0xfc801e61
14560 #define M_MNEM_vld20 0xfc901e00
14561 #define M_MNEM_vld21 0xfc901e20
14562 #define M_MNEM_vld40 0xfc901e01
14563 #define M_MNEM_vld41 0xfc901e21
14564 #define M_MNEM_vld42 0xfc901e41
14565 #define M_MNEM_vld43 0xfc901e61
14566 #define M_MNEM_vstrb 0xec000e00
14567 #define M_MNEM_vstrh 0xec000e10
14568 #define M_MNEM_vstrw 0xec000e40
14569 #define M_MNEM_vstrd 0xec000e50
14570 #define M_MNEM_vldrb 0xec100e00
14571 #define M_MNEM_vldrh 0xec100e10
14572 #define M_MNEM_vldrw 0xec100e40
14573 #define M_MNEM_vldrd 0xec100e50
14574 #define M_MNEM_vmovlt 0xeea01f40
14575 #define M_MNEM_vmovlb 0xeea00f40
14576 #define M_MNEM_vmovnt 0xfe311e81
14577 #define M_MNEM_vmovnb 0xfe310e81
14578 #define M_MNEM_vadc 0xee300f00
14579 #define M_MNEM_vadci 0xee301f00
14580 #define M_MNEM_vbrsr 0xfe011e60
14581 #define M_MNEM_vaddlv 0xee890f00
14582 #define M_MNEM_vaddlva 0xee890f20
14583 #define M_MNEM_vaddv 0xeef10f00
14584 #define M_MNEM_vaddva 0xeef10f20
14585 #define M_MNEM_vddup 0xee011f6e
14586 #define M_MNEM_vdwdup 0xee011f60
14587 #define M_MNEM_vidup 0xee010f6e
14588 #define M_MNEM_viwdup 0xee010f60
14589 #define M_MNEM_vmaxv 0xeee20f00
14590 #define M_MNEM_vmaxav 0xeee00f00
14591 #define M_MNEM_vminv 0xeee20f80
14592 #define M_MNEM_vminav 0xeee00f80
14593 #define M_MNEM_vmlaldav 0xee800e00
14594 #define M_MNEM_vmlaldava 0xee800e20
14595 #define M_MNEM_vmlaldavx 0xee801e00
14596 #define M_MNEM_vmlaldavax 0xee801e20
14597 #define M_MNEM_vmlsldav 0xee800e01
14598 #define M_MNEM_vmlsldava 0xee800e21
14599 #define M_MNEM_vmlsldavx 0xee801e01
14600 #define M_MNEM_vmlsldavax 0xee801e21
14601 #define M_MNEM_vrmlaldavhx 0xee801f00
14602 #define M_MNEM_vrmlaldavhax 0xee801f20
14603 #define M_MNEM_vrmlsldavh 0xfe800e01
14604 #define M_MNEM_vrmlsldavha 0xfe800e21
14605 #define M_MNEM_vrmlsldavhx 0xfe801e01
14606 #define M_MNEM_vrmlsldavhax 0xfe801e21
14607 #define M_MNEM_vqmovnt 0xee331e01
14608 #define M_MNEM_vqmovnb 0xee330e01
14609 #define M_MNEM_vqmovunt 0xee311e81
14610 #define M_MNEM_vqmovunb 0xee310e81
14611 #define M_MNEM_vshrnt 0xee801fc1
14612 #define M_MNEM_vshrnb 0xee800fc1
14613 #define M_MNEM_vrshrnt 0xfe801fc1
14614 #define M_MNEM_vqshrnt 0xee801f40
14615 #define M_MNEM_vqshrnb 0xee800f40
14616 #define M_MNEM_vqshrunt 0xee801fc0
14617 #define M_MNEM_vqshrunb 0xee800fc0
14618 #define M_MNEM_vrshrnb 0xfe800fc1
14619 #define M_MNEM_vqrshrnt 0xee801f41
14620 #define M_MNEM_vqrshrnb 0xee800f41
14621 #define M_MNEM_vqrshrunt 0xfe801fc0
14622 #define M_MNEM_vqrshrunb 0xfe800fc0
14623
14624 /* Bfloat16 instruction encoder helpers. */
14625 #define B_MNEM_vfmat 0xfc300850
14626 #define B_MNEM_vfmab 0xfc300810
14627
14628 /* Neon instruction encoder helpers. */
14629
14630 /* Encodings for the different types for various Neon opcodes. */
14631
14632 /* An "invalid" code for the following tables. */
14633 #define N_INV -1u
14634
14635 struct neon_tab_entry
14636 {
14637 unsigned integer;
14638 unsigned float_or_poly;
14639 unsigned scalar_or_imm;
14640 };
14641
14642 /* Map overloaded Neon opcodes to their respective encodings. */
14643 #define NEON_ENC_TAB \
14644 X(vabd, 0x0000700, 0x1200d00, N_INV), \
14645 X(vabdl, 0x0800700, N_INV, N_INV), \
14646 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14647 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14648 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14649 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14650 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14651 X(vadd, 0x0000800, 0x0000d00, N_INV), \
14652 X(vaddl, 0x0800000, N_INV, N_INV), \
14653 X(vsub, 0x1000800, 0x0200d00, N_INV), \
14654 X(vsubl, 0x0800200, N_INV, N_INV), \
14655 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14656 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14657 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14658 /* Register variants of the following two instructions are encoded as
14659 vcge / vcgt with the operands reversed. */ \
14660 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14661 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
14662 X(vfma, N_INV, 0x0000c10, N_INV), \
14663 X(vfms, N_INV, 0x0200c10, N_INV), \
14664 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14665 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14666 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14667 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14668 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14669 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14670 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14671 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14672 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14673 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14674 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
14675 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14676 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
14677 X(vshl, 0x0000400, N_INV, 0x0800510), \
14678 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14679 X(vand, 0x0000110, N_INV, 0x0800030), \
14680 X(vbic, 0x0100110, N_INV, 0x0800030), \
14681 X(veor, 0x1000110, N_INV, N_INV), \
14682 X(vorn, 0x0300110, N_INV, 0x0800010), \
14683 X(vorr, 0x0200110, N_INV, 0x0800010), \
14684 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14685 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14686 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14687 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14688 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14689 X(vst1, 0x0000000, 0x0800000, N_INV), \
14690 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14691 X(vst2, 0x0000100, 0x0800100, N_INV), \
14692 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14693 X(vst3, 0x0000200, 0x0800200, N_INV), \
14694 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14695 X(vst4, 0x0000300, 0x0800300, N_INV), \
14696 X(vmovn, 0x1b20200, N_INV, N_INV), \
14697 X(vtrn, 0x1b20080, N_INV, N_INV), \
14698 X(vqmovn, 0x1b20200, N_INV, N_INV), \
14699 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14700 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
14701 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14702 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
14703 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14704 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
14705 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14706 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14707 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
14708 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14709 X(vseleq, 0xe000a00, N_INV, N_INV), \
14710 X(vselvs, 0xe100a00, N_INV, N_INV), \
14711 X(vselge, 0xe200a00, N_INV, N_INV), \
14712 X(vselgt, 0xe300a00, N_INV, N_INV), \
14713 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
14714 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
14715 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14716 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
14717 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
14718 X(aes, 0x3b00300, N_INV, N_INV), \
14719 X(sha3op, 0x2000c00, N_INV, N_INV), \
14720 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14721 X(sha2op, 0x3ba0380, N_INV, N_INV)
14722
14723 enum neon_opc
14724 {
14725 #define X(OPC,I,F,S) N_MNEM_##OPC
14726 NEON_ENC_TAB
14727 #undef X
14728 };
14729
14730 static const struct neon_tab_entry neon_enc_tab[] =
14731 {
14732 #define X(OPC,I,F,S) { (I), (F), (S) }
14733 NEON_ENC_TAB
14734 #undef X
14735 };
14736
14737 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
14738 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14739 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14740 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14741 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14742 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14743 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14744 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14745 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14746 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14747 #define NEON_ENC_SINGLE_(X) \
14748 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
14749 #define NEON_ENC_DOUBLE_(X) \
14750 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
14751 #define NEON_ENC_FPV8_(X) \
14752 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
14753
14754 #define NEON_ENCODE(type, inst) \
14755 do \
14756 { \
14757 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14758 inst.is_neon = 1; \
14759 } \
14760 while (0)
14761
14762 #define check_neon_suffixes \
14763 do \
14764 { \
14765 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14766 { \
14767 as_bad (_("invalid neon suffix for non neon instruction")); \
14768 return; \
14769 } \
14770 } \
14771 while (0)
14772
14773 /* Define shapes for instruction operands. The following mnemonic characters
14774 are used in this table:
14775
14776 F - VFP S<n> register
14777 D - Neon D<n> register
14778 Q - Neon Q<n> register
14779 I - Immediate
14780 S - Scalar
14781 R - ARM register
14782 L - D<n> register list
14783
14784 This table is used to generate various data:
14785 - enumerations of the form NS_DDR to be used as arguments to
14786 neon_select_shape.
14787 - a table classifying shapes into single, double, quad, mixed.
14788 - a table used to drive neon_select_shape. */
14789
14790 #define NEON_SHAPE_DEF \
14791 X(4, (R, R, Q, Q), QUAD), \
14792 X(4, (Q, R, R, I), QUAD), \
14793 X(4, (R, R, S, S), QUAD), \
14794 X(4, (S, S, R, R), QUAD), \
14795 X(3, (Q, R, I), QUAD), \
14796 X(3, (I, Q, Q), QUAD), \
14797 X(3, (I, Q, R), QUAD), \
14798 X(3, (R, Q, Q), QUAD), \
14799 X(3, (D, D, D), DOUBLE), \
14800 X(3, (Q, Q, Q), QUAD), \
14801 X(3, (D, D, I), DOUBLE), \
14802 X(3, (Q, Q, I), QUAD), \
14803 X(3, (D, D, S), DOUBLE), \
14804 X(3, (Q, Q, S), QUAD), \
14805 X(3, (Q, Q, R), QUAD), \
14806 X(3, (R, R, Q), QUAD), \
14807 X(2, (R, Q), QUAD), \
14808 X(2, (D, D), DOUBLE), \
14809 X(2, (Q, Q), QUAD), \
14810 X(2, (D, S), DOUBLE), \
14811 X(2, (Q, S), QUAD), \
14812 X(2, (D, R), DOUBLE), \
14813 X(2, (Q, R), QUAD), \
14814 X(2, (D, I), DOUBLE), \
14815 X(2, (Q, I), QUAD), \
14816 X(3, (P, F, I), SINGLE), \
14817 X(3, (P, D, I), DOUBLE), \
14818 X(3, (P, Q, I), QUAD), \
14819 X(4, (P, F, F, I), SINGLE), \
14820 X(4, (P, D, D, I), DOUBLE), \
14821 X(4, (P, Q, Q, I), QUAD), \
14822 X(5, (P, F, F, F, I), SINGLE), \
14823 X(5, (P, D, D, D, I), DOUBLE), \
14824 X(5, (P, Q, Q, Q, I), QUAD), \
14825 X(3, (D, L, D), DOUBLE), \
14826 X(2, (D, Q), MIXED), \
14827 X(2, (Q, D), MIXED), \
14828 X(3, (D, Q, I), MIXED), \
14829 X(3, (Q, D, I), MIXED), \
14830 X(3, (Q, D, D), MIXED), \
14831 X(3, (D, Q, Q), MIXED), \
14832 X(3, (Q, Q, D), MIXED), \
14833 X(3, (Q, D, S), MIXED), \
14834 X(3, (D, Q, S), MIXED), \
14835 X(4, (D, D, D, I), DOUBLE), \
14836 X(4, (Q, Q, Q, I), QUAD), \
14837 X(4, (D, D, S, I), DOUBLE), \
14838 X(4, (Q, Q, S, I), QUAD), \
14839 X(2, (F, F), SINGLE), \
14840 X(3, (F, F, F), SINGLE), \
14841 X(2, (F, I), SINGLE), \
14842 X(2, (F, D), MIXED), \
14843 X(2, (D, F), MIXED), \
14844 X(3, (F, F, I), MIXED), \
14845 X(4, (R, R, F, F), SINGLE), \
14846 X(4, (F, F, R, R), SINGLE), \
14847 X(3, (D, R, R), DOUBLE), \
14848 X(3, (R, R, D), DOUBLE), \
14849 X(2, (S, R), SINGLE), \
14850 X(2, (R, S), SINGLE), \
14851 X(2, (F, R), SINGLE), \
14852 X(2, (R, F), SINGLE), \
14853 /* Used for MVE tail predicated loop instructions. */\
14854 X(2, (R, R), QUAD), \
14855 /* Half float shape supported so far. */\
14856 X (2, (H, D), MIXED), \
14857 X (2, (D, H), MIXED), \
14858 X (2, (H, F), MIXED), \
14859 X (2, (F, H), MIXED), \
14860 X (2, (H, H), HALF), \
14861 X (2, (H, R), HALF), \
14862 X (2, (R, H), HALF), \
14863 X (2, (H, I), HALF), \
14864 X (3, (H, H, H), HALF), \
14865 X (3, (H, F, I), MIXED), \
14866 X (3, (F, H, I), MIXED), \
14867 X (3, (D, H, H), MIXED), \
14868 X (3, (D, H, S), MIXED)
14869
14870 #define S2(A,B) NS_##A##B
14871 #define S3(A,B,C) NS_##A##B##C
14872 #define S4(A,B,C,D) NS_##A##B##C##D
14873 #define S5(A,B,C,D,E) NS_##A##B##C##D##E
14874
14875 #define X(N, L, C) S##N L
14876
14877 enum neon_shape
14878 {
14879 NEON_SHAPE_DEF,
14880 NS_NULL
14881 };
14882
14883 #undef X
14884 #undef S2
14885 #undef S3
14886 #undef S4
14887 #undef S5
14888
14889 enum neon_shape_class
14890 {
14891 SC_HALF,
14892 SC_SINGLE,
14893 SC_DOUBLE,
14894 SC_QUAD,
14895 SC_MIXED
14896 };
14897
14898 #define X(N, L, C) SC_##C
14899
14900 static enum neon_shape_class neon_shape_class[] =
14901 {
14902 NEON_SHAPE_DEF
14903 };
14904
14905 #undef X
14906
14907 enum neon_shape_el
14908 {
14909 SE_H,
14910 SE_F,
14911 SE_D,
14912 SE_Q,
14913 SE_I,
14914 SE_S,
14915 SE_R,
14916 SE_L,
14917 SE_P
14918 };
14919
14920 /* Register widths of above. */
14921 static unsigned neon_shape_el_size[] =
14922 {
14923 16,
14924 32,
14925 64,
14926 128,
14927 0,
14928 32,
14929 32,
14930 0,
14931 0
14932 };
14933
14934 struct neon_shape_info
14935 {
14936 unsigned els;
14937 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14938 };
14939
14940 #define S2(A,B) { SE_##A, SE_##B }
14941 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14942 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14943 #define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
14944
14945 #define X(N, L, C) { N, S##N L }
14946
14947 static struct neon_shape_info neon_shape_tab[] =
14948 {
14949 NEON_SHAPE_DEF
14950 };
14951
14952 #undef X
14953 #undef S2
14954 #undef S3
14955 #undef S4
14956 #undef S5
14957
14958 /* Bit masks used in type checking given instructions.
14959 'N_EQK' means the type must be the same as (or based on in some way) the key
14960 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14961 set, various other bits can be set as well in order to modify the meaning of
14962 the type constraint. */
14963
14964 enum neon_type_mask
14965 {
14966 N_S8 = 0x0000001,
14967 N_S16 = 0x0000002,
14968 N_S32 = 0x0000004,
14969 N_S64 = 0x0000008,
14970 N_U8 = 0x0000010,
14971 N_U16 = 0x0000020,
14972 N_U32 = 0x0000040,
14973 N_U64 = 0x0000080,
14974 N_I8 = 0x0000100,
14975 N_I16 = 0x0000200,
14976 N_I32 = 0x0000400,
14977 N_I64 = 0x0000800,
14978 N_8 = 0x0001000,
14979 N_16 = 0x0002000,
14980 N_32 = 0x0004000,
14981 N_64 = 0x0008000,
14982 N_P8 = 0x0010000,
14983 N_P16 = 0x0020000,
14984 N_F16 = 0x0040000,
14985 N_F32 = 0x0080000,
14986 N_F64 = 0x0100000,
14987 N_P64 = 0x0200000,
14988 N_BF16 = 0x0400000,
14989 N_KEY = 0x1000000, /* Key element (main type specifier). */
14990 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
14991 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
14992 N_UNT = 0x8000000, /* Must be explicitly untyped. */
14993 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14994 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14995 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14996 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14997 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14998 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14999 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
15000 N_UTYP = 0,
15001 N_MAX_NONSPECIAL = N_P64
15002 };
15003
15004 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
15005
15006 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
15007 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15008 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
15009 #define N_S_32 (N_S8 | N_S16 | N_S32)
15010 #define N_F_16_32 (N_F16 | N_F32)
15011 #define N_SUF_32 (N_SU_32 | N_F_16_32)
15012 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
15013 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
15014 #define N_F_ALL (N_F16 | N_F32 | N_F64)
15015 #define N_I_MVE (N_I8 | N_I16 | N_I32)
15016 #define N_F_MVE (N_F16 | N_F32)
15017 #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15018
15019 /* Pass this as the first type argument to neon_check_type to ignore types
15020 altogether. */
15021 #define N_IGNORE_TYPE (N_KEY | N_EQK)
15022
15023 /* Select a "shape" for the current instruction (describing register types or
15024 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15025 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15026 function of operand parsing, so this function doesn't need to be called.
15027 Shapes should be listed in order of decreasing length. */
15028
15029 static enum neon_shape
15030 neon_select_shape (enum neon_shape shape, ...)
15031 {
15032 va_list ap;
15033 enum neon_shape first_shape = shape;
15034
15035 /* Fix missing optional operands. FIXME: we don't know at this point how
15036 many arguments we should have, so this makes the assumption that we have
15037 > 1. This is true of all current Neon opcodes, I think, but may not be
15038 true in the future. */
15039 if (!inst.operands[1].present)
15040 inst.operands[1] = inst.operands[0];
15041
15042 va_start (ap, shape);
15043
15044 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
15045 {
15046 unsigned j;
15047 int matches = 1;
15048
15049 for (j = 0; j < neon_shape_tab[shape].els; j++)
15050 {
15051 if (!inst.operands[j].present)
15052 {
15053 matches = 0;
15054 break;
15055 }
15056
15057 switch (neon_shape_tab[shape].el[j])
15058 {
15059 /* If a .f16, .16, .u16, .s16 type specifier is given over
15060 a VFP single precision register operand, it's essentially
15061 means only half of the register is used.
15062
15063 If the type specifier is given after the mnemonics, the
15064 information is stored in inst.vectype. If the type specifier
15065 is given after register operand, the information is stored
15066 in inst.operands[].vectype.
15067
15068 When there is only one type specifier, and all the register
15069 operands are the same type of hardware register, the type
15070 specifier applies to all register operands.
15071
15072 If no type specifier is given, the shape is inferred from
15073 operand information.
15074
15075 for example:
15076 vadd.f16 s0, s1, s2: NS_HHH
15077 vabs.f16 s0, s1: NS_HH
15078 vmov.f16 s0, r1: NS_HR
15079 vmov.f16 r0, s1: NS_RH
15080 vcvt.f16 r0, s1: NS_RH
15081 vcvt.f16.s32 s2, s2, #29: NS_HFI
15082 vcvt.f16.s32 s2, s2: NS_HF
15083 */
15084 case SE_H:
15085 if (!(inst.operands[j].isreg
15086 && inst.operands[j].isvec
15087 && inst.operands[j].issingle
15088 && !inst.operands[j].isquad
15089 && ((inst.vectype.elems == 1
15090 && inst.vectype.el[0].size == 16)
15091 || (inst.vectype.elems > 1
15092 && inst.vectype.el[j].size == 16)
15093 || (inst.vectype.elems == 0
15094 && inst.operands[j].vectype.type != NT_invtype
15095 && inst.operands[j].vectype.size == 16))))
15096 matches = 0;
15097 break;
15098
15099 case SE_F:
15100 if (!(inst.operands[j].isreg
15101 && inst.operands[j].isvec
15102 && inst.operands[j].issingle
15103 && !inst.operands[j].isquad
15104 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15105 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15106 || (inst.vectype.elems == 0
15107 && (inst.operands[j].vectype.size == 32
15108 || inst.operands[j].vectype.type == NT_invtype)))))
15109 matches = 0;
15110 break;
15111
15112 case SE_D:
15113 if (!(inst.operands[j].isreg
15114 && inst.operands[j].isvec
15115 && !inst.operands[j].isquad
15116 && !inst.operands[j].issingle))
15117 matches = 0;
15118 break;
15119
15120 case SE_R:
15121 if (!(inst.operands[j].isreg
15122 && !inst.operands[j].isvec))
15123 matches = 0;
15124 break;
15125
15126 case SE_Q:
15127 if (!(inst.operands[j].isreg
15128 && inst.operands[j].isvec
15129 && inst.operands[j].isquad
15130 && !inst.operands[j].issingle))
15131 matches = 0;
15132 break;
15133
15134 case SE_I:
15135 if (!(!inst.operands[j].isreg
15136 && !inst.operands[j].isscalar))
15137 matches = 0;
15138 break;
15139
15140 case SE_S:
15141 if (!(!inst.operands[j].isreg
15142 && inst.operands[j].isscalar))
15143 matches = 0;
15144 break;
15145
15146 case SE_P:
15147 case SE_L:
15148 break;
15149 }
15150 if (!matches)
15151 break;
15152 }
15153 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15154 /* We've matched all the entries in the shape table, and we don't
15155 have any left over operands which have not been matched. */
15156 break;
15157 }
15158
15159 va_end (ap);
15160
15161 if (shape == NS_NULL && first_shape != NS_NULL)
15162 first_error (_("invalid instruction shape"));
15163
15164 return shape;
15165 }
15166
15167 /* True if SHAPE is predominantly a quadword operation (most of the time, this
15168 means the Q bit should be set). */
15169
15170 static int
15171 neon_quad (enum neon_shape shape)
15172 {
15173 return neon_shape_class[shape] == SC_QUAD;
15174 }
15175
15176 static void
15177 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
15178 unsigned *g_size)
15179 {
15180 /* Allow modification to be made to types which are constrained to be
15181 based on the key element, based on bits set alongside N_EQK. */
15182 if ((typebits & N_EQK) != 0)
15183 {
15184 if ((typebits & N_HLF) != 0)
15185 *g_size /= 2;
15186 else if ((typebits & N_DBL) != 0)
15187 *g_size *= 2;
15188 if ((typebits & N_SGN) != 0)
15189 *g_type = NT_signed;
15190 else if ((typebits & N_UNS) != 0)
15191 *g_type = NT_unsigned;
15192 else if ((typebits & N_INT) != 0)
15193 *g_type = NT_integer;
15194 else if ((typebits & N_FLT) != 0)
15195 *g_type = NT_float;
15196 else if ((typebits & N_SIZ) != 0)
15197 *g_type = NT_untyped;
15198 }
15199 }
15200
15201 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15202 operand type, i.e. the single type specified in a Neon instruction when it
15203 is the only one given. */
15204
15205 static struct neon_type_el
15206 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15207 {
15208 struct neon_type_el dest = *key;
15209
15210 gas_assert ((thisarg & N_EQK) != 0);
15211
15212 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15213
15214 return dest;
15215 }
15216
15217 /* Convert Neon type and size into compact bitmask representation. */
15218
15219 static enum neon_type_mask
15220 type_chk_of_el_type (enum neon_el_type type, unsigned size)
15221 {
15222 switch (type)
15223 {
15224 case NT_untyped:
15225 switch (size)
15226 {
15227 case 8: return N_8;
15228 case 16: return N_16;
15229 case 32: return N_32;
15230 case 64: return N_64;
15231 default: ;
15232 }
15233 break;
15234
15235 case NT_integer:
15236 switch (size)
15237 {
15238 case 8: return N_I8;
15239 case 16: return N_I16;
15240 case 32: return N_I32;
15241 case 64: return N_I64;
15242 default: ;
15243 }
15244 break;
15245
15246 case NT_float:
15247 switch (size)
15248 {
15249 case 16: return N_F16;
15250 case 32: return N_F32;
15251 case 64: return N_F64;
15252 default: ;
15253 }
15254 break;
15255
15256 case NT_poly:
15257 switch (size)
15258 {
15259 case 8: return N_P8;
15260 case 16: return N_P16;
15261 case 64: return N_P64;
15262 default: ;
15263 }
15264 break;
15265
15266 case NT_signed:
15267 switch (size)
15268 {
15269 case 8: return N_S8;
15270 case 16: return N_S16;
15271 case 32: return N_S32;
15272 case 64: return N_S64;
15273 default: ;
15274 }
15275 break;
15276
15277 case NT_unsigned:
15278 switch (size)
15279 {
15280 case 8: return N_U8;
15281 case 16: return N_U16;
15282 case 32: return N_U32;
15283 case 64: return N_U64;
15284 default: ;
15285 }
15286 break;
15287
15288 case NT_bfloat:
15289 if (size == 16) return N_BF16;
15290 break;
15291
15292 default: ;
15293 }
15294
15295 return N_UTYP;
15296 }
15297
15298 /* Convert compact Neon bitmask type representation to a type and size. Only
15299 handles the case where a single bit is set in the mask. */
15300
15301 static int
15302 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
15303 enum neon_type_mask mask)
15304 {
15305 if ((mask & N_EQK) != 0)
15306 return FAIL;
15307
15308 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15309 *size = 8;
15310 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15311 != 0)
15312 *size = 16;
15313 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
15314 *size = 32;
15315 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
15316 *size = 64;
15317 else
15318 return FAIL;
15319
15320 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15321 *type = NT_signed;
15322 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
15323 *type = NT_unsigned;
15324 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
15325 *type = NT_integer;
15326 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
15327 *type = NT_untyped;
15328 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
15329 *type = NT_poly;
15330 else if ((mask & (N_F_ALL)) != 0)
15331 *type = NT_float;
15332 else if ((mask & (N_BF16)) != 0)
15333 *type = NT_bfloat;
15334 else
15335 return FAIL;
15336
15337 return SUCCESS;
15338 }
15339
15340 /* Modify a bitmask of allowed types. This is only needed for type
15341 relaxation. */
15342
15343 static unsigned
15344 modify_types_allowed (unsigned allowed, unsigned mods)
15345 {
15346 unsigned size;
15347 enum neon_el_type type;
15348 unsigned destmask;
15349 int i;
15350
15351 destmask = 0;
15352
15353 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15354 {
15355 if (el_type_of_type_chk (&type, &size,
15356 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15357 {
15358 neon_modify_type_size (mods, &type, &size);
15359 destmask |= type_chk_of_el_type (type, size);
15360 }
15361 }
15362
15363 return destmask;
15364 }
15365
15366 /* Check type and return type classification.
15367 The manual states (paraphrase): If one datatype is given, it indicates the
15368 type given in:
15369 - the second operand, if there is one
15370 - the operand, if there is no second operand
15371 - the result, if there are no operands.
15372 This isn't quite good enough though, so we use a concept of a "key" datatype
15373 which is set on a per-instruction basis, which is the one which matters when
15374 only one data type is written.
15375 Note: this function has side-effects (e.g. filling in missing operands). All
15376 Neon instructions should call it before performing bit encoding. */
15377
15378 static struct neon_type_el
15379 neon_check_type (unsigned els, enum neon_shape ns, ...)
15380 {
15381 va_list ap;
15382 unsigned i, pass, key_el = 0;
15383 unsigned types[NEON_MAX_TYPE_ELS];
15384 enum neon_el_type k_type = NT_invtype;
15385 unsigned k_size = -1u;
15386 struct neon_type_el badtype = {NT_invtype, -1};
15387 unsigned key_allowed = 0;
15388
15389 /* Optional registers in Neon instructions are always (not) in operand 1.
15390 Fill in the missing operand here, if it was omitted. */
15391 if (els > 1 && !inst.operands[1].present)
15392 inst.operands[1] = inst.operands[0];
15393
15394 /* Suck up all the varargs. */
15395 va_start (ap, ns);
15396 for (i = 0; i < els; i++)
15397 {
15398 unsigned thisarg = va_arg (ap, unsigned);
15399 if (thisarg == N_IGNORE_TYPE)
15400 {
15401 va_end (ap);
15402 return badtype;
15403 }
15404 types[i] = thisarg;
15405 if ((thisarg & N_KEY) != 0)
15406 key_el = i;
15407 }
15408 va_end (ap);
15409
15410 if (inst.vectype.elems > 0)
15411 for (i = 0; i < els; i++)
15412 if (inst.operands[i].vectype.type != NT_invtype)
15413 {
15414 first_error (_("types specified in both the mnemonic and operands"));
15415 return badtype;
15416 }
15417
15418 /* Duplicate inst.vectype elements here as necessary.
15419 FIXME: No idea if this is exactly the same as the ARM assembler,
15420 particularly when an insn takes one register and one non-register
15421 operand. */
15422 if (inst.vectype.elems == 1 && els > 1)
15423 {
15424 unsigned j;
15425 inst.vectype.elems = els;
15426 inst.vectype.el[key_el] = inst.vectype.el[0];
15427 for (j = 0; j < els; j++)
15428 if (j != key_el)
15429 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15430 types[j]);
15431 }
15432 else if (inst.vectype.elems == 0 && els > 0)
15433 {
15434 unsigned j;
15435 /* No types were given after the mnemonic, so look for types specified
15436 after each operand. We allow some flexibility here; as long as the
15437 "key" operand has a type, we can infer the others. */
15438 for (j = 0; j < els; j++)
15439 if (inst.operands[j].vectype.type != NT_invtype)
15440 inst.vectype.el[j] = inst.operands[j].vectype;
15441
15442 if (inst.operands[key_el].vectype.type != NT_invtype)
15443 {
15444 for (j = 0; j < els; j++)
15445 if (inst.operands[j].vectype.type == NT_invtype)
15446 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15447 types[j]);
15448 }
15449 else
15450 {
15451 first_error (_("operand types can't be inferred"));
15452 return badtype;
15453 }
15454 }
15455 else if (inst.vectype.elems != els)
15456 {
15457 first_error (_("type specifier has the wrong number of parts"));
15458 return badtype;
15459 }
15460
15461 for (pass = 0; pass < 2; pass++)
15462 {
15463 for (i = 0; i < els; i++)
15464 {
15465 unsigned thisarg = types[i];
15466 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15467 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15468 enum neon_el_type g_type = inst.vectype.el[i].type;
15469 unsigned g_size = inst.vectype.el[i].size;
15470
15471 /* Decay more-specific signed & unsigned types to sign-insensitive
15472 integer types if sign-specific variants are unavailable. */
15473 if ((g_type == NT_signed || g_type == NT_unsigned)
15474 && (types_allowed & N_SU_ALL) == 0)
15475 g_type = NT_integer;
15476
15477 /* If only untyped args are allowed, decay any more specific types to
15478 them. Some instructions only care about signs for some element
15479 sizes, so handle that properly. */
15480 if (((types_allowed & N_UNT) == 0)
15481 && ((g_size == 8 && (types_allowed & N_8) != 0)
15482 || (g_size == 16 && (types_allowed & N_16) != 0)
15483 || (g_size == 32 && (types_allowed & N_32) != 0)
15484 || (g_size == 64 && (types_allowed & N_64) != 0)))
15485 g_type = NT_untyped;
15486
15487 if (pass == 0)
15488 {
15489 if ((thisarg & N_KEY) != 0)
15490 {
15491 k_type = g_type;
15492 k_size = g_size;
15493 key_allowed = thisarg & ~N_KEY;
15494
15495 /* Check architecture constraint on FP16 extension. */
15496 if (k_size == 16
15497 && k_type == NT_float
15498 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15499 {
15500 inst.error = _(BAD_FP16);
15501 return badtype;
15502 }
15503 }
15504 }
15505 else
15506 {
15507 if ((thisarg & N_VFP) != 0)
15508 {
15509 enum neon_shape_el regshape;
15510 unsigned regwidth, match;
15511
15512 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15513 if (ns == NS_NULL)
15514 {
15515 first_error (_("invalid instruction shape"));
15516 return badtype;
15517 }
15518 regshape = neon_shape_tab[ns].el[i];
15519 regwidth = neon_shape_el_size[regshape];
15520
15521 /* In VFP mode, operands must match register widths. If we
15522 have a key operand, use its width, else use the width of
15523 the current operand. */
15524 if (k_size != -1u)
15525 match = k_size;
15526 else
15527 match = g_size;
15528
15529 /* FP16 will use a single precision register. */
15530 if (regwidth == 32 && match == 16)
15531 {
15532 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15533 match = regwidth;
15534 else
15535 {
15536 inst.error = _(BAD_FP16);
15537 return badtype;
15538 }
15539 }
15540
15541 if (regwidth != match)
15542 {
15543 first_error (_("operand size must match register width"));
15544 return badtype;
15545 }
15546 }
15547
15548 if ((thisarg & N_EQK) == 0)
15549 {
15550 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15551
15552 if ((given_type & types_allowed) == 0)
15553 {
15554 first_error (BAD_SIMD_TYPE);
15555 return badtype;
15556 }
15557 }
15558 else
15559 {
15560 enum neon_el_type mod_k_type = k_type;
15561 unsigned mod_k_size = k_size;
15562 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15563 if (g_type != mod_k_type || g_size != mod_k_size)
15564 {
15565 first_error (_("inconsistent types in Neon instruction"));
15566 return badtype;
15567 }
15568 }
15569 }
15570 }
15571 }
15572
15573 return inst.vectype.el[key_el];
15574 }
15575
15576 /* Neon-style VFP instruction forwarding. */
15577
15578 /* Thumb VFP instructions have 0xE in the condition field. */
15579
15580 static void
15581 do_vfp_cond_or_thumb (void)
15582 {
15583 inst.is_neon = 1;
15584
15585 if (thumb_mode)
15586 inst.instruction |= 0xe0000000;
15587 else
15588 inst.instruction |= inst.cond << 28;
15589 }
15590
15591 /* Look up and encode a simple mnemonic, for use as a helper function for the
15592 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15593 etc. It is assumed that operand parsing has already been done, and that the
15594 operands are in the form expected by the given opcode (this isn't necessarily
15595 the same as the form in which they were parsed, hence some massaging must
15596 take place before this function is called).
15597 Checks current arch version against that in the looked-up opcode. */
15598
15599 static void
15600 do_vfp_nsyn_opcode (const char *opname)
15601 {
15602 const struct asm_opcode *opcode;
15603
15604 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
15605
15606 if (!opcode)
15607 abort ();
15608
15609 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
15610 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15611 _(BAD_FPU));
15612
15613 inst.is_neon = 1;
15614
15615 if (thumb_mode)
15616 {
15617 inst.instruction = opcode->tvalue;
15618 opcode->tencode ();
15619 }
15620 else
15621 {
15622 inst.instruction = (inst.cond << 28) | opcode->avalue;
15623 opcode->aencode ();
15624 }
15625 }
15626
15627 static void
15628 do_vfp_nsyn_add_sub (enum neon_shape rs)
15629 {
15630 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15631
15632 if (rs == NS_FFF || rs == NS_HHH)
15633 {
15634 if (is_add)
15635 do_vfp_nsyn_opcode ("fadds");
15636 else
15637 do_vfp_nsyn_opcode ("fsubs");
15638
15639 /* ARMv8.2 fp16 instruction. */
15640 if (rs == NS_HHH)
15641 do_scalar_fp16_v82_encode ();
15642 }
15643 else
15644 {
15645 if (is_add)
15646 do_vfp_nsyn_opcode ("faddd");
15647 else
15648 do_vfp_nsyn_opcode ("fsubd");
15649 }
15650 }
15651
15652 /* Check operand types to see if this is a VFP instruction, and if so call
15653 PFN (). */
15654
15655 static int
15656 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15657 {
15658 enum neon_shape rs;
15659 struct neon_type_el et;
15660
15661 switch (args)
15662 {
15663 case 2:
15664 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15665 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15666 break;
15667
15668 case 3:
15669 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15670 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15671 N_F_ALL | N_KEY | N_VFP);
15672 break;
15673
15674 default:
15675 abort ();
15676 }
15677
15678 if (et.type != NT_invtype)
15679 {
15680 pfn (rs);
15681 return SUCCESS;
15682 }
15683
15684 inst.error = NULL;
15685 return FAIL;
15686 }
15687
15688 static void
15689 do_vfp_nsyn_mla_mls (enum neon_shape rs)
15690 {
15691 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
15692
15693 if (rs == NS_FFF || rs == NS_HHH)
15694 {
15695 if (is_mla)
15696 do_vfp_nsyn_opcode ("fmacs");
15697 else
15698 do_vfp_nsyn_opcode ("fnmacs");
15699
15700 /* ARMv8.2 fp16 instruction. */
15701 if (rs == NS_HHH)
15702 do_scalar_fp16_v82_encode ();
15703 }
15704 else
15705 {
15706 if (is_mla)
15707 do_vfp_nsyn_opcode ("fmacd");
15708 else
15709 do_vfp_nsyn_opcode ("fnmacd");
15710 }
15711 }
15712
15713 static void
15714 do_vfp_nsyn_fma_fms (enum neon_shape rs)
15715 {
15716 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15717
15718 if (rs == NS_FFF || rs == NS_HHH)
15719 {
15720 if (is_fma)
15721 do_vfp_nsyn_opcode ("ffmas");
15722 else
15723 do_vfp_nsyn_opcode ("ffnmas");
15724
15725 /* ARMv8.2 fp16 instruction. */
15726 if (rs == NS_HHH)
15727 do_scalar_fp16_v82_encode ();
15728 }
15729 else
15730 {
15731 if (is_fma)
15732 do_vfp_nsyn_opcode ("ffmad");
15733 else
15734 do_vfp_nsyn_opcode ("ffnmad");
15735 }
15736 }
15737
15738 static void
15739 do_vfp_nsyn_mul (enum neon_shape rs)
15740 {
15741 if (rs == NS_FFF || rs == NS_HHH)
15742 {
15743 do_vfp_nsyn_opcode ("fmuls");
15744
15745 /* ARMv8.2 fp16 instruction. */
15746 if (rs == NS_HHH)
15747 do_scalar_fp16_v82_encode ();
15748 }
15749 else
15750 do_vfp_nsyn_opcode ("fmuld");
15751 }
15752
15753 static void
15754 do_vfp_nsyn_abs_neg (enum neon_shape rs)
15755 {
15756 int is_neg = (inst.instruction & 0x80) != 0;
15757 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
15758
15759 if (rs == NS_FF || rs == NS_HH)
15760 {
15761 if (is_neg)
15762 do_vfp_nsyn_opcode ("fnegs");
15763 else
15764 do_vfp_nsyn_opcode ("fabss");
15765
15766 /* ARMv8.2 fp16 instruction. */
15767 if (rs == NS_HH)
15768 do_scalar_fp16_v82_encode ();
15769 }
15770 else
15771 {
15772 if (is_neg)
15773 do_vfp_nsyn_opcode ("fnegd");
15774 else
15775 do_vfp_nsyn_opcode ("fabsd");
15776 }
15777 }
15778
15779 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15780 insns belong to Neon, and are handled elsewhere. */
15781
15782 static void
15783 do_vfp_nsyn_ldm_stm (int is_dbmode)
15784 {
15785 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15786 if (is_ldm)
15787 {
15788 if (is_dbmode)
15789 do_vfp_nsyn_opcode ("fldmdbs");
15790 else
15791 do_vfp_nsyn_opcode ("fldmias");
15792 }
15793 else
15794 {
15795 if (is_dbmode)
15796 do_vfp_nsyn_opcode ("fstmdbs");
15797 else
15798 do_vfp_nsyn_opcode ("fstmias");
15799 }
15800 }
15801
15802 static void
15803 do_vfp_nsyn_sqrt (void)
15804 {
15805 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15806 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15807
15808 if (rs == NS_FF || rs == NS_HH)
15809 {
15810 do_vfp_nsyn_opcode ("fsqrts");
15811
15812 /* ARMv8.2 fp16 instruction. */
15813 if (rs == NS_HH)
15814 do_scalar_fp16_v82_encode ();
15815 }
15816 else
15817 do_vfp_nsyn_opcode ("fsqrtd");
15818 }
15819
15820 static void
15821 do_vfp_nsyn_div (void)
15822 {
15823 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15824 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15825 N_F_ALL | N_KEY | N_VFP);
15826
15827 if (rs == NS_FFF || rs == NS_HHH)
15828 {
15829 do_vfp_nsyn_opcode ("fdivs");
15830
15831 /* ARMv8.2 fp16 instruction. */
15832 if (rs == NS_HHH)
15833 do_scalar_fp16_v82_encode ();
15834 }
15835 else
15836 do_vfp_nsyn_opcode ("fdivd");
15837 }
15838
15839 static void
15840 do_vfp_nsyn_nmul (void)
15841 {
15842 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15843 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15844 N_F_ALL | N_KEY | N_VFP);
15845
15846 if (rs == NS_FFF || rs == NS_HHH)
15847 {
15848 NEON_ENCODE (SINGLE, inst);
15849 do_vfp_sp_dyadic ();
15850
15851 /* ARMv8.2 fp16 instruction. */
15852 if (rs == NS_HHH)
15853 do_scalar_fp16_v82_encode ();
15854 }
15855 else
15856 {
15857 NEON_ENCODE (DOUBLE, inst);
15858 do_vfp_dp_rd_rn_rm ();
15859 }
15860 do_vfp_cond_or_thumb ();
15861
15862 }
15863
15864 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15865 (0, 1, 2, 3). */
15866
15867 static unsigned
15868 neon_logbits (unsigned x)
15869 {
15870 return ffs (x) - 4;
15871 }
15872
15873 #define LOW4(R) ((R) & 0xf)
15874 #define HI1(R) (((R) >> 4) & 1)
15875 #define LOW1(R) ((R) & 0x1)
15876 #define HI4(R) (((R) >> 1) & 0xf)
15877
15878 static unsigned
15879 mve_get_vcmp_vpt_cond (struct neon_type_el et)
15880 {
15881 switch (et.type)
15882 {
15883 default:
15884 first_error (BAD_EL_TYPE);
15885 return 0;
15886 case NT_float:
15887 switch (inst.operands[0].imm)
15888 {
15889 default:
15890 first_error (_("invalid condition"));
15891 return 0;
15892 case 0x0:
15893 /* eq. */
15894 return 0;
15895 case 0x1:
15896 /* ne. */
15897 return 1;
15898 case 0xa:
15899 /* ge/ */
15900 return 4;
15901 case 0xb:
15902 /* lt. */
15903 return 5;
15904 case 0xc:
15905 /* gt. */
15906 return 6;
15907 case 0xd:
15908 /* le. */
15909 return 7;
15910 }
15911 case NT_integer:
15912 /* only accept eq and ne. */
15913 if (inst.operands[0].imm > 1)
15914 {
15915 first_error (_("invalid condition"));
15916 return 0;
15917 }
15918 return inst.operands[0].imm;
15919 case NT_unsigned:
15920 if (inst.operands[0].imm == 0x2)
15921 return 2;
15922 else if (inst.operands[0].imm == 0x8)
15923 return 3;
15924 else
15925 {
15926 first_error (_("invalid condition"));
15927 return 0;
15928 }
15929 case NT_signed:
15930 switch (inst.operands[0].imm)
15931 {
15932 default:
15933 first_error (_("invalid condition"));
15934 return 0;
15935 case 0xa:
15936 /* ge. */
15937 return 4;
15938 case 0xb:
15939 /* lt. */
15940 return 5;
15941 case 0xc:
15942 /* gt. */
15943 return 6;
15944 case 0xd:
15945 /* le. */
15946 return 7;
15947 }
15948 }
15949 /* Should be unreachable. */
15950 abort ();
15951 }
15952
15953 /* For VCTP (create vector tail predicate) in MVE. */
15954 static void
15955 do_mve_vctp (void)
15956 {
15957 int dt = 0;
15958 unsigned size = 0x0;
15959
15960 if (inst.cond > COND_ALWAYS)
15961 inst.pred_insn_type = INSIDE_VPT_INSN;
15962 else
15963 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15964
15965 /* This is a typical MVE instruction which has no type but have size 8, 16,
15966 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15967 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15968 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15969 dt = inst.vectype.el[0].size;
15970
15971 /* Setting this does not indicate an actual NEON instruction, but only
15972 indicates that the mnemonic accepts neon-style type suffixes. */
15973 inst.is_neon = 1;
15974
15975 switch (dt)
15976 {
15977 case 8:
15978 break;
15979 case 16:
15980 size = 0x1; break;
15981 case 32:
15982 size = 0x2; break;
15983 case 64:
15984 size = 0x3; break;
15985 default:
15986 first_error (_("Type is not allowed for this instruction"));
15987 }
15988 inst.instruction |= size << 20;
15989 inst.instruction |= inst.operands[0].reg << 16;
15990 }
15991
15992 static void
15993 do_mve_vpt (void)
15994 {
15995 /* We are dealing with a vector predicated block. */
15996 if (inst.operands[0].present)
15997 {
15998 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15999 struct neon_type_el et
16000 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16001 N_EQK);
16002
16003 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16004
16005 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16006
16007 if (et.type == NT_invtype)
16008 return;
16009
16010 if (et.type == NT_float)
16011 {
16012 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16013 BAD_FPU);
16014 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16015 inst.instruction |= (et.size == 16) << 28;
16016 inst.instruction |= 0x3 << 20;
16017 }
16018 else
16019 {
16020 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16021 BAD_EL_TYPE);
16022 inst.instruction |= 1 << 28;
16023 inst.instruction |= neon_logbits (et.size) << 20;
16024 }
16025
16026 if (inst.operands[2].isquad)
16027 {
16028 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16029 inst.instruction |= LOW4 (inst.operands[2].reg);
16030 inst.instruction |= (fcond & 0x2) >> 1;
16031 }
16032 else
16033 {
16034 if (inst.operands[2].reg == REG_SP)
16035 as_tsktsk (MVE_BAD_SP);
16036 inst.instruction |= 1 << 6;
16037 inst.instruction |= (fcond & 0x2) << 4;
16038 inst.instruction |= inst.operands[2].reg;
16039 }
16040 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16041 inst.instruction |= (fcond & 0x4) << 10;
16042 inst.instruction |= (fcond & 0x1) << 7;
16043
16044 }
16045 set_pred_insn_type (VPT_INSN);
16046 now_pred.cc = 0;
16047 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16048 | ((inst.instruction & 0xe000) >> 13);
16049 now_pred.warn_deprecated = FALSE;
16050 now_pred.type = VECTOR_PRED;
16051 inst.is_neon = 1;
16052 }
16053
16054 static void
16055 do_mve_vcmp (void)
16056 {
16057 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16058 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16059 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16060 if (!inst.operands[2].present)
16061 first_error (_("MVE vector or ARM register expected"));
16062 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16063
16064 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16065 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16066 && inst.operands[1].isquad)
16067 {
16068 inst.instruction = N_MNEM_vcmp;
16069 inst.cond = 0x10;
16070 }
16071
16072 if (inst.cond > COND_ALWAYS)
16073 inst.pred_insn_type = INSIDE_VPT_INSN;
16074 else
16075 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16076
16077 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16078 struct neon_type_el et
16079 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16080 N_EQK);
16081
16082 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16083 && !inst.operands[2].iszr, BAD_PC);
16084
16085 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16086
16087 inst.instruction = 0xee010f00;
16088 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16089 inst.instruction |= (fcond & 0x4) << 10;
16090 inst.instruction |= (fcond & 0x1) << 7;
16091 if (et.type == NT_float)
16092 {
16093 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16094 BAD_FPU);
16095 inst.instruction |= (et.size == 16) << 28;
16096 inst.instruction |= 0x3 << 20;
16097 }
16098 else
16099 {
16100 inst.instruction |= 1 << 28;
16101 inst.instruction |= neon_logbits (et.size) << 20;
16102 }
16103 if (inst.operands[2].isquad)
16104 {
16105 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16106 inst.instruction |= (fcond & 0x2) >> 1;
16107 inst.instruction |= LOW4 (inst.operands[2].reg);
16108 }
16109 else
16110 {
16111 if (inst.operands[2].reg == REG_SP)
16112 as_tsktsk (MVE_BAD_SP);
16113 inst.instruction |= 1 << 6;
16114 inst.instruction |= (fcond & 0x2) << 4;
16115 inst.instruction |= inst.operands[2].reg;
16116 }
16117
16118 inst.is_neon = 1;
16119 return;
16120 }
16121
16122 static void
16123 do_mve_vmaxa_vmina (void)
16124 {
16125 if (inst.cond > COND_ALWAYS)
16126 inst.pred_insn_type = INSIDE_VPT_INSN;
16127 else
16128 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16129
16130 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16131 struct neon_type_el et
16132 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16133
16134 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16135 inst.instruction |= neon_logbits (et.size) << 18;
16136 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16137 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16138 inst.instruction |= LOW4 (inst.operands[1].reg);
16139 inst.is_neon = 1;
16140 }
16141
16142 static void
16143 do_mve_vfmas (void)
16144 {
16145 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16146 struct neon_type_el et
16147 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16148
16149 if (inst.cond > COND_ALWAYS)
16150 inst.pred_insn_type = INSIDE_VPT_INSN;
16151 else
16152 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16153
16154 if (inst.operands[2].reg == REG_SP)
16155 as_tsktsk (MVE_BAD_SP);
16156 else if (inst.operands[2].reg == REG_PC)
16157 as_tsktsk (MVE_BAD_PC);
16158
16159 inst.instruction |= (et.size == 16) << 28;
16160 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16161 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16162 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16163 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16164 inst.instruction |= inst.operands[2].reg;
16165 inst.is_neon = 1;
16166 }
16167
16168 static void
16169 do_mve_viddup (void)
16170 {
16171 if (inst.cond > COND_ALWAYS)
16172 inst.pred_insn_type = INSIDE_VPT_INSN;
16173 else
16174 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16175
16176 unsigned imm = inst.relocs[0].exp.X_add_number;
16177 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16178 _("immediate must be either 1, 2, 4 or 8"));
16179
16180 enum neon_shape rs;
16181 struct neon_type_el et;
16182 unsigned Rm;
16183 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16184 {
16185 rs = neon_select_shape (NS_QRI, NS_NULL);
16186 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16187 Rm = 7;
16188 }
16189 else
16190 {
16191 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16192 if (inst.operands[2].reg == REG_SP)
16193 as_tsktsk (MVE_BAD_SP);
16194 else if (inst.operands[2].reg == REG_PC)
16195 first_error (BAD_PC);
16196
16197 rs = neon_select_shape (NS_QRRI, NS_NULL);
16198 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16199 Rm = inst.operands[2].reg >> 1;
16200 }
16201 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16202 inst.instruction |= neon_logbits (et.size) << 20;
16203 inst.instruction |= inst.operands[1].reg << 16;
16204 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16205 inst.instruction |= (imm > 2) << 7;
16206 inst.instruction |= Rm << 1;
16207 inst.instruction |= (imm == 2 || imm == 8);
16208 inst.is_neon = 1;
16209 }
16210
16211 static void
16212 do_mve_vmlas (void)
16213 {
16214 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16215 struct neon_type_el et
16216 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16217
16218 if (inst.operands[2].reg == REG_PC)
16219 as_tsktsk (MVE_BAD_PC);
16220 else if (inst.operands[2].reg == REG_SP)
16221 as_tsktsk (MVE_BAD_SP);
16222
16223 if (inst.cond > COND_ALWAYS)
16224 inst.pred_insn_type = INSIDE_VPT_INSN;
16225 else
16226 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16227
16228 inst.instruction |= (et.type == NT_unsigned) << 28;
16229 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16230 inst.instruction |= neon_logbits (et.size) << 20;
16231 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16232 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16233 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16234 inst.instruction |= inst.operands[2].reg;
16235 inst.is_neon = 1;
16236 }
16237
16238 static void
16239 do_mve_vshll (void)
16240 {
16241 struct neon_type_el et
16242 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16243
16244 if (inst.cond > COND_ALWAYS)
16245 inst.pred_insn_type = INSIDE_VPT_INSN;
16246 else
16247 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16248
16249 int imm = inst.operands[2].imm;
16250 constraint (imm < 1 || (unsigned)imm > et.size,
16251 _("immediate value out of range"));
16252
16253 if ((unsigned)imm == et.size)
16254 {
16255 inst.instruction |= neon_logbits (et.size) << 18;
16256 inst.instruction |= 0x110001;
16257 }
16258 else
16259 {
16260 inst.instruction |= (et.size + imm) << 16;
16261 inst.instruction |= 0x800140;
16262 }
16263
16264 inst.instruction |= (et.type == NT_unsigned) << 28;
16265 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16266 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16267 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16268 inst.instruction |= LOW4 (inst.operands[1].reg);
16269 inst.is_neon = 1;
16270 }
16271
16272 static void
16273 do_mve_vshlc (void)
16274 {
16275 if (inst.cond > COND_ALWAYS)
16276 inst.pred_insn_type = INSIDE_VPT_INSN;
16277 else
16278 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16279
16280 if (inst.operands[1].reg == REG_PC)
16281 as_tsktsk (MVE_BAD_PC);
16282 else if (inst.operands[1].reg == REG_SP)
16283 as_tsktsk (MVE_BAD_SP);
16284
16285 int imm = inst.operands[2].imm;
16286 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16287
16288 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16289 inst.instruction |= (imm & 0x1f) << 16;
16290 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16291 inst.instruction |= inst.operands[1].reg;
16292 inst.is_neon = 1;
16293 }
16294
16295 static void
16296 do_mve_vshrn (void)
16297 {
16298 unsigned types;
16299 switch (inst.instruction)
16300 {
16301 case M_MNEM_vshrnt:
16302 case M_MNEM_vshrnb:
16303 case M_MNEM_vrshrnt:
16304 case M_MNEM_vrshrnb:
16305 types = N_I16 | N_I32;
16306 break;
16307 case M_MNEM_vqshrnt:
16308 case M_MNEM_vqshrnb:
16309 case M_MNEM_vqrshrnt:
16310 case M_MNEM_vqrshrnb:
16311 types = N_U16 | N_U32 | N_S16 | N_S32;
16312 break;
16313 case M_MNEM_vqshrunt:
16314 case M_MNEM_vqshrunb:
16315 case M_MNEM_vqrshrunt:
16316 case M_MNEM_vqrshrunb:
16317 types = N_S16 | N_S32;
16318 break;
16319 default:
16320 abort ();
16321 }
16322
16323 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16324
16325 if (inst.cond > COND_ALWAYS)
16326 inst.pred_insn_type = INSIDE_VPT_INSN;
16327 else
16328 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16329
16330 unsigned Qd = inst.operands[0].reg;
16331 unsigned Qm = inst.operands[1].reg;
16332 unsigned imm = inst.operands[2].imm;
16333 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16334 et.size == 16
16335 ? _("immediate operand expected in the range [1,8]")
16336 : _("immediate operand expected in the range [1,16]"));
16337
16338 inst.instruction |= (et.type == NT_unsigned) << 28;
16339 inst.instruction |= HI1 (Qd) << 22;
16340 inst.instruction |= (et.size - imm) << 16;
16341 inst.instruction |= LOW4 (Qd) << 12;
16342 inst.instruction |= HI1 (Qm) << 5;
16343 inst.instruction |= LOW4 (Qm);
16344 inst.is_neon = 1;
16345 }
16346
16347 static void
16348 do_mve_vqmovn (void)
16349 {
16350 struct neon_type_el et;
16351 if (inst.instruction == M_MNEM_vqmovnt
16352 || inst.instruction == M_MNEM_vqmovnb)
16353 et = neon_check_type (2, NS_QQ, N_EQK,
16354 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16355 else
16356 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16357
16358 if (inst.cond > COND_ALWAYS)
16359 inst.pred_insn_type = INSIDE_VPT_INSN;
16360 else
16361 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16362
16363 inst.instruction |= (et.type == NT_unsigned) << 28;
16364 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16365 inst.instruction |= (et.size == 32) << 18;
16366 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16367 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16368 inst.instruction |= LOW4 (inst.operands[1].reg);
16369 inst.is_neon = 1;
16370 }
16371
16372 static void
16373 do_mve_vpsel (void)
16374 {
16375 neon_select_shape (NS_QQQ, NS_NULL);
16376
16377 if (inst.cond > COND_ALWAYS)
16378 inst.pred_insn_type = INSIDE_VPT_INSN;
16379 else
16380 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16381
16382 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16383 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16384 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16385 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16386 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16387 inst.instruction |= LOW4 (inst.operands[2].reg);
16388 inst.is_neon = 1;
16389 }
16390
16391 static void
16392 do_mve_vpnot (void)
16393 {
16394 if (inst.cond > COND_ALWAYS)
16395 inst.pred_insn_type = INSIDE_VPT_INSN;
16396 else
16397 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16398 }
16399
16400 static void
16401 do_mve_vmaxnma_vminnma (void)
16402 {
16403 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16404 struct neon_type_el et
16405 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16406
16407 if (inst.cond > COND_ALWAYS)
16408 inst.pred_insn_type = INSIDE_VPT_INSN;
16409 else
16410 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16411
16412 inst.instruction |= (et.size == 16) << 28;
16413 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16414 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16415 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16416 inst.instruction |= LOW4 (inst.operands[1].reg);
16417 inst.is_neon = 1;
16418 }
16419
16420 static void
16421 do_mve_vcmul (void)
16422 {
16423 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16424 struct neon_type_el et
16425 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16426
16427 if (inst.cond > COND_ALWAYS)
16428 inst.pred_insn_type = INSIDE_VPT_INSN;
16429 else
16430 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16431
16432 unsigned rot = inst.relocs[0].exp.X_add_number;
16433 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16434 _("immediate out of range"));
16435
16436 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16437 || inst.operands[0].reg == inst.operands[2].reg))
16438 as_tsktsk (BAD_MVE_SRCDEST);
16439
16440 inst.instruction |= (et.size == 32) << 28;
16441 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16442 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16443 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16444 inst.instruction |= (rot > 90) << 12;
16445 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16446 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16447 inst.instruction |= LOW4 (inst.operands[2].reg);
16448 inst.instruction |= (rot == 90 || rot == 270);
16449 inst.is_neon = 1;
16450 }
16451
16452 /* To handle the Low Overhead Loop instructions
16453 in Armv8.1-M Mainline and MVE. */
16454 static void
16455 do_t_loloop (void)
16456 {
16457 unsigned long insn = inst.instruction;
16458
16459 inst.instruction = THUMB_OP32 (inst.instruction);
16460
16461 if (insn == T_MNEM_lctp)
16462 return;
16463
16464 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16465
16466 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16467 {
16468 struct neon_type_el et
16469 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16470 inst.instruction |= neon_logbits (et.size) << 20;
16471 inst.is_neon = 1;
16472 }
16473
16474 switch (insn)
16475 {
16476 case T_MNEM_letp:
16477 constraint (!inst.operands[0].present,
16478 _("expected LR"));
16479 /* fall through. */
16480 case T_MNEM_le:
16481 /* le <label>. */
16482 if (!inst.operands[0].present)
16483 inst.instruction |= 1 << 21;
16484
16485 v8_1_loop_reloc (TRUE);
16486 break;
16487
16488 case T_MNEM_wls:
16489 case T_MNEM_wlstp:
16490 v8_1_loop_reloc (FALSE);
16491 /* fall through. */
16492 case T_MNEM_dlstp:
16493 case T_MNEM_dls:
16494 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16495
16496 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16497 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16498 else if (inst.operands[1].reg == REG_PC)
16499 as_tsktsk (MVE_BAD_PC);
16500 if (inst.operands[1].reg == REG_SP)
16501 as_tsktsk (MVE_BAD_SP);
16502
16503 inst.instruction |= (inst.operands[1].reg << 16);
16504 break;
16505
16506 default:
16507 abort ();
16508 }
16509 }
16510
16511
16512 static void
16513 do_vfp_nsyn_cmp (void)
16514 {
16515 enum neon_shape rs;
16516 if (!inst.operands[0].isreg)
16517 {
16518 do_mve_vcmp ();
16519 return;
16520 }
16521 else
16522 {
16523 constraint (inst.operands[2].present, BAD_SYNTAX);
16524 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16525 BAD_FPU);
16526 }
16527
16528 if (inst.operands[1].isreg)
16529 {
16530 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16531 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
16532
16533 if (rs == NS_FF || rs == NS_HH)
16534 {
16535 NEON_ENCODE (SINGLE, inst);
16536 do_vfp_sp_monadic ();
16537 }
16538 else
16539 {
16540 NEON_ENCODE (DOUBLE, inst);
16541 do_vfp_dp_rd_rm ();
16542 }
16543 }
16544 else
16545 {
16546 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16547 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
16548
16549 switch (inst.instruction & 0x0fffffff)
16550 {
16551 case N_MNEM_vcmp:
16552 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16553 break;
16554 case N_MNEM_vcmpe:
16555 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16556 break;
16557 default:
16558 abort ();
16559 }
16560
16561 if (rs == NS_FI || rs == NS_HI)
16562 {
16563 NEON_ENCODE (SINGLE, inst);
16564 do_vfp_sp_compare_z ();
16565 }
16566 else
16567 {
16568 NEON_ENCODE (DOUBLE, inst);
16569 do_vfp_dp_rd ();
16570 }
16571 }
16572 do_vfp_cond_or_thumb ();
16573
16574 /* ARMv8.2 fp16 instruction. */
16575 if (rs == NS_HI || rs == NS_HH)
16576 do_scalar_fp16_v82_encode ();
16577 }
16578
16579 static void
16580 nsyn_insert_sp (void)
16581 {
16582 inst.operands[1] = inst.operands[0];
16583 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
16584 inst.operands[0].reg = REG_SP;
16585 inst.operands[0].isreg = 1;
16586 inst.operands[0].writeback = 1;
16587 inst.operands[0].present = 1;
16588 }
16589
16590 /* Fix up Neon data-processing instructions, ORing in the correct bits for
16591 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16592
16593 static void
16594 neon_dp_fixup (struct arm_it* insn)
16595 {
16596 unsigned int i = insn->instruction;
16597 insn->is_neon = 1;
16598
16599 if (thumb_mode)
16600 {
16601 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16602 if (i & (1 << 24))
16603 i |= 1 << 28;
16604
16605 i &= ~(1 << 24);
16606
16607 i |= 0xef000000;
16608 }
16609 else
16610 i |= 0xf2000000;
16611
16612 insn->instruction = i;
16613 }
16614
16615 static void
16616 mve_encode_qqr (int size, int U, int fp)
16617 {
16618 if (inst.operands[2].reg == REG_SP)
16619 as_tsktsk (MVE_BAD_SP);
16620 else if (inst.operands[2].reg == REG_PC)
16621 as_tsktsk (MVE_BAD_PC);
16622
16623 if (fp)
16624 {
16625 /* vadd. */
16626 if (((unsigned)inst.instruction) == 0xd00)
16627 inst.instruction = 0xee300f40;
16628 /* vsub. */
16629 else if (((unsigned)inst.instruction) == 0x200d00)
16630 inst.instruction = 0xee301f40;
16631 /* vmul. */
16632 else if (((unsigned)inst.instruction) == 0x1000d10)
16633 inst.instruction = 0xee310e60;
16634
16635 /* Setting size which is 1 for F16 and 0 for F32. */
16636 inst.instruction |= (size == 16) << 28;
16637 }
16638 else
16639 {
16640 /* vadd. */
16641 if (((unsigned)inst.instruction) == 0x800)
16642 inst.instruction = 0xee010f40;
16643 /* vsub. */
16644 else if (((unsigned)inst.instruction) == 0x1000800)
16645 inst.instruction = 0xee011f40;
16646 /* vhadd. */
16647 else if (((unsigned)inst.instruction) == 0)
16648 inst.instruction = 0xee000f40;
16649 /* vhsub. */
16650 else if (((unsigned)inst.instruction) == 0x200)
16651 inst.instruction = 0xee001f40;
16652 /* vmla. */
16653 else if (((unsigned)inst.instruction) == 0x900)
16654 inst.instruction = 0xee010e40;
16655 /* vmul. */
16656 else if (((unsigned)inst.instruction) == 0x910)
16657 inst.instruction = 0xee011e60;
16658 /* vqadd. */
16659 else if (((unsigned)inst.instruction) == 0x10)
16660 inst.instruction = 0xee000f60;
16661 /* vqsub. */
16662 else if (((unsigned)inst.instruction) == 0x210)
16663 inst.instruction = 0xee001f60;
16664 /* vqrdmlah. */
16665 else if (((unsigned)inst.instruction) == 0x3000b10)
16666 inst.instruction = 0xee000e40;
16667 /* vqdmulh. */
16668 else if (((unsigned)inst.instruction) == 0x0000b00)
16669 inst.instruction = 0xee010e60;
16670 /* vqrdmulh. */
16671 else if (((unsigned)inst.instruction) == 0x1000b00)
16672 inst.instruction = 0xfe010e60;
16673
16674 /* Set U-bit. */
16675 inst.instruction |= U << 28;
16676
16677 /* Setting bits for size. */
16678 inst.instruction |= neon_logbits (size) << 20;
16679 }
16680 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16681 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16682 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16683 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16684 inst.instruction |= inst.operands[2].reg;
16685 inst.is_neon = 1;
16686 }
16687
16688 static void
16689 mve_encode_rqq (unsigned bit28, unsigned size)
16690 {
16691 inst.instruction |= bit28 << 28;
16692 inst.instruction |= neon_logbits (size) << 20;
16693 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16694 inst.instruction |= inst.operands[0].reg << 12;
16695 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16696 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16697 inst.instruction |= LOW4 (inst.operands[2].reg);
16698 inst.is_neon = 1;
16699 }
16700
16701 static void
16702 mve_encode_qqq (int ubit, int size)
16703 {
16704
16705 inst.instruction |= (ubit != 0) << 28;
16706 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16707 inst.instruction |= neon_logbits (size) << 20;
16708 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16709 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16710 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16711 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16712 inst.instruction |= LOW4 (inst.operands[2].reg);
16713
16714 inst.is_neon = 1;
16715 }
16716
16717 static void
16718 mve_encode_rq (unsigned bit28, unsigned size)
16719 {
16720 inst.instruction |= bit28 << 28;
16721 inst.instruction |= neon_logbits (size) << 18;
16722 inst.instruction |= inst.operands[0].reg << 12;
16723 inst.instruction |= LOW4 (inst.operands[1].reg);
16724 inst.is_neon = 1;
16725 }
16726
16727 static void
16728 mve_encode_rrqq (unsigned U, unsigned size)
16729 {
16730 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16731
16732 inst.instruction |= U << 28;
16733 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16734 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16735 inst.instruction |= (size == 32) << 16;
16736 inst.instruction |= inst.operands[0].reg << 12;
16737 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16738 inst.instruction |= inst.operands[3].reg;
16739 inst.is_neon = 1;
16740 }
16741
16742 /* Helper function for neon_three_same handling the operands. */
16743 static void
16744 neon_three_args (int isquad)
16745 {
16746 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16747 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16748 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16749 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16750 inst.instruction |= LOW4 (inst.operands[2].reg);
16751 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16752 inst.instruction |= (isquad != 0) << 6;
16753 inst.is_neon = 1;
16754 }
16755
16756 /* Encode insns with bit pattern:
16757
16758 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16759 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
16760
16761 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16762 different meaning for some instruction. */
16763
16764 static void
16765 neon_three_same (int isquad, int ubit, int size)
16766 {
16767 neon_three_args (isquad);
16768 inst.instruction |= (ubit != 0) << 24;
16769 if (size != -1)
16770 inst.instruction |= neon_logbits (size) << 20;
16771
16772 neon_dp_fixup (&inst);
16773 }
16774
16775 /* Encode instructions of the form:
16776
16777 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16778 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
16779
16780 Don't write size if SIZE == -1. */
16781
16782 static void
16783 neon_two_same (int qbit, int ubit, int size)
16784 {
16785 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16786 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16787 inst.instruction |= LOW4 (inst.operands[1].reg);
16788 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16789 inst.instruction |= (qbit != 0) << 6;
16790 inst.instruction |= (ubit != 0) << 24;
16791
16792 if (size != -1)
16793 inst.instruction |= neon_logbits (size) << 18;
16794
16795 neon_dp_fixup (&inst);
16796 }
16797
16798 enum vfp_or_neon_is_neon_bits
16799 {
16800 NEON_CHECK_CC = 1,
16801 NEON_CHECK_ARCH = 2,
16802 NEON_CHECK_ARCH8 = 4
16803 };
16804
16805 /* Call this function if an instruction which may have belonged to the VFP or
16806 Neon instruction sets, but turned out to be a Neon instruction (due to the
16807 operand types involved, etc.). We have to check and/or fix-up a couple of
16808 things:
16809
16810 - Make sure the user hasn't attempted to make a Neon instruction
16811 conditional.
16812 - Alter the value in the condition code field if necessary.
16813 - Make sure that the arch supports Neon instructions.
16814
16815 Which of these operations take place depends on bits from enum
16816 vfp_or_neon_is_neon_bits.
16817
16818 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16819 current instruction's condition is COND_ALWAYS, the condition field is
16820 changed to inst.uncond_value. This is necessary because instructions shared
16821 between VFP and Neon may be conditional for the VFP variants only, and the
16822 unconditional Neon version must have, e.g., 0xF in the condition field. */
16823
16824 static int
16825 vfp_or_neon_is_neon (unsigned check)
16826 {
16827 /* Conditions are always legal in Thumb mode (IT blocks). */
16828 if (!thumb_mode && (check & NEON_CHECK_CC))
16829 {
16830 if (inst.cond != COND_ALWAYS)
16831 {
16832 first_error (_(BAD_COND));
16833 return FAIL;
16834 }
16835 if (inst.uncond_value != -1)
16836 inst.instruction |= inst.uncond_value << 28;
16837 }
16838
16839
16840 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16841 || ((check & NEON_CHECK_ARCH8)
16842 && !mark_feature_used (&fpu_neon_ext_armv8)))
16843 {
16844 first_error (_(BAD_FPU));
16845 return FAIL;
16846 }
16847
16848 return SUCCESS;
16849 }
16850
16851
16852 /* Return TRUE if the SIMD instruction is available for the current
16853 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16854 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16855 vfp_or_neon_is_neon for the NEON specific checks. */
16856
16857 static bfd_boolean
16858 check_simd_pred_availability (int fp, unsigned check)
16859 {
16860 if (inst.cond > COND_ALWAYS)
16861 {
16862 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16863 {
16864 inst.error = BAD_FPU;
16865 return FALSE;
16866 }
16867 inst.pred_insn_type = INSIDE_VPT_INSN;
16868 }
16869 else if (inst.cond < COND_ALWAYS)
16870 {
16871 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16872 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16873 else if (vfp_or_neon_is_neon (check) == FAIL)
16874 return FALSE;
16875 }
16876 else
16877 {
16878 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16879 && vfp_or_neon_is_neon (check) == FAIL)
16880 return FALSE;
16881
16882 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16883 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16884 }
16885 return TRUE;
16886 }
16887
16888 /* Neon instruction encoders, in approximate order of appearance. */
16889
16890 static void
16891 do_neon_dyadic_i_su (void)
16892 {
16893 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16894 return;
16895
16896 enum neon_shape rs;
16897 struct neon_type_el et;
16898 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16899 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16900 else
16901 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16902
16903 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16904
16905
16906 if (rs != NS_QQR)
16907 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16908 else
16909 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16910 }
16911
16912 static void
16913 do_neon_dyadic_i64_su (void)
16914 {
16915 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
16916 return;
16917 enum neon_shape rs;
16918 struct neon_type_el et;
16919 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16920 {
16921 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16922 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16923 }
16924 else
16925 {
16926 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16927 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16928 }
16929 if (rs == NS_QQR)
16930 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16931 else
16932 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16933 }
16934
16935 static void
16936 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
16937 unsigned immbits)
16938 {
16939 unsigned size = et.size >> 3;
16940 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16941 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16942 inst.instruction |= LOW4 (inst.operands[1].reg);
16943 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16944 inst.instruction |= (isquad != 0) << 6;
16945 inst.instruction |= immbits << 16;
16946 inst.instruction |= (size >> 3) << 7;
16947 inst.instruction |= (size & 0x7) << 19;
16948 if (write_ubit)
16949 inst.instruction |= (uval != 0) << 24;
16950
16951 neon_dp_fixup (&inst);
16952 }
16953
16954 static void
16955 do_neon_shl (void)
16956 {
16957 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16958 return;
16959
16960 if (!inst.operands[2].isreg)
16961 {
16962 enum neon_shape rs;
16963 struct neon_type_el et;
16964 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16965 {
16966 rs = neon_select_shape (NS_QQI, NS_NULL);
16967 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16968 }
16969 else
16970 {
16971 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16972 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16973 }
16974 int imm = inst.operands[2].imm;
16975
16976 constraint (imm < 0 || (unsigned)imm >= et.size,
16977 _("immediate out of range for shift"));
16978 NEON_ENCODE (IMMED, inst);
16979 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
16980 }
16981 else
16982 {
16983 enum neon_shape rs;
16984 struct neon_type_el et;
16985 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16986 {
16987 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16988 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16989 }
16990 else
16991 {
16992 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16993 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16994 }
16995
16996
16997 if (rs == NS_QQR)
16998 {
16999 constraint (inst.operands[0].reg != inst.operands[1].reg,
17000 _("invalid instruction shape"));
17001 if (inst.operands[2].reg == REG_SP)
17002 as_tsktsk (MVE_BAD_SP);
17003 else if (inst.operands[2].reg == REG_PC)
17004 as_tsktsk (MVE_BAD_PC);
17005
17006 inst.instruction = 0xee311e60;
17007 inst.instruction |= (et.type == NT_unsigned) << 28;
17008 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17009 inst.instruction |= neon_logbits (et.size) << 18;
17010 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17011 inst.instruction |= inst.operands[2].reg;
17012 inst.is_neon = 1;
17013 }
17014 else
17015 {
17016 unsigned int tmp;
17017
17018 /* VSHL/VQSHL 3-register variants have syntax such as:
17019 vshl.xx Dd, Dm, Dn
17020 whereas other 3-register operations encoded by neon_three_same have
17021 syntax like:
17022 vadd.xx Dd, Dn, Dm
17023 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17024 operands[2].reg here. */
17025 tmp = inst.operands[2].reg;
17026 inst.operands[2].reg = inst.operands[1].reg;
17027 inst.operands[1].reg = tmp;
17028 NEON_ENCODE (INTEGER, inst);
17029 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17030 }
17031 }
17032 }
17033
17034 static void
17035 do_neon_qshl (void)
17036 {
17037 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
17038 return;
17039
17040 if (!inst.operands[2].isreg)
17041 {
17042 enum neon_shape rs;
17043 struct neon_type_el et;
17044 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17045 {
17046 rs = neon_select_shape (NS_QQI, NS_NULL);
17047 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17048 }
17049 else
17050 {
17051 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17052 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17053 }
17054 int imm = inst.operands[2].imm;
17055
17056 constraint (imm < 0 || (unsigned)imm >= et.size,
17057 _("immediate out of range for shift"));
17058 NEON_ENCODE (IMMED, inst);
17059 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
17060 }
17061 else
17062 {
17063 enum neon_shape rs;
17064 struct neon_type_el et;
17065
17066 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17067 {
17068 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17069 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17070 }
17071 else
17072 {
17073 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17074 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17075 }
17076
17077 if (rs == NS_QQR)
17078 {
17079 constraint (inst.operands[0].reg != inst.operands[1].reg,
17080 _("invalid instruction shape"));
17081 if (inst.operands[2].reg == REG_SP)
17082 as_tsktsk (MVE_BAD_SP);
17083 else if (inst.operands[2].reg == REG_PC)
17084 as_tsktsk (MVE_BAD_PC);
17085
17086 inst.instruction = 0xee311ee0;
17087 inst.instruction |= (et.type == NT_unsigned) << 28;
17088 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17089 inst.instruction |= neon_logbits (et.size) << 18;
17090 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17091 inst.instruction |= inst.operands[2].reg;
17092 inst.is_neon = 1;
17093 }
17094 else
17095 {
17096 unsigned int tmp;
17097
17098 /* See note in do_neon_shl. */
17099 tmp = inst.operands[2].reg;
17100 inst.operands[2].reg = inst.operands[1].reg;
17101 inst.operands[1].reg = tmp;
17102 NEON_ENCODE (INTEGER, inst);
17103 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17104 }
17105 }
17106 }
17107
17108 static void
17109 do_neon_rshl (void)
17110 {
17111 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
17112 return;
17113
17114 enum neon_shape rs;
17115 struct neon_type_el et;
17116 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17117 {
17118 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17119 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17120 }
17121 else
17122 {
17123 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17124 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17125 }
17126
17127 unsigned int tmp;
17128
17129 if (rs == NS_QQR)
17130 {
17131 if (inst.operands[2].reg == REG_PC)
17132 as_tsktsk (MVE_BAD_PC);
17133 else if (inst.operands[2].reg == REG_SP)
17134 as_tsktsk (MVE_BAD_SP);
17135
17136 constraint (inst.operands[0].reg != inst.operands[1].reg,
17137 _("invalid instruction shape"));
17138
17139 if (inst.instruction == 0x0000510)
17140 /* We are dealing with vqrshl. */
17141 inst.instruction = 0xee331ee0;
17142 else
17143 /* We are dealing with vrshl. */
17144 inst.instruction = 0xee331e60;
17145
17146 inst.instruction |= (et.type == NT_unsigned) << 28;
17147 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17148 inst.instruction |= neon_logbits (et.size) << 18;
17149 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17150 inst.instruction |= inst.operands[2].reg;
17151 inst.is_neon = 1;
17152 }
17153 else
17154 {
17155 tmp = inst.operands[2].reg;
17156 inst.operands[2].reg = inst.operands[1].reg;
17157 inst.operands[1].reg = tmp;
17158 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17159 }
17160 }
17161
17162 static int
17163 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17164 {
17165 /* Handle .I8 pseudo-instructions. */
17166 if (size == 8)
17167 {
17168 /* Unfortunately, this will make everything apart from zero out-of-range.
17169 FIXME is this the intended semantics? There doesn't seem much point in
17170 accepting .I8 if so. */
17171 immediate |= immediate << 8;
17172 size = 16;
17173 }
17174
17175 if (size >= 32)
17176 {
17177 if (immediate == (immediate & 0x000000ff))
17178 {
17179 *immbits = immediate;
17180 return 0x1;
17181 }
17182 else if (immediate == (immediate & 0x0000ff00))
17183 {
17184 *immbits = immediate >> 8;
17185 return 0x3;
17186 }
17187 else if (immediate == (immediate & 0x00ff0000))
17188 {
17189 *immbits = immediate >> 16;
17190 return 0x5;
17191 }
17192 else if (immediate == (immediate & 0xff000000))
17193 {
17194 *immbits = immediate >> 24;
17195 return 0x7;
17196 }
17197 if ((immediate & 0xffff) != (immediate >> 16))
17198 goto bad_immediate;
17199 immediate &= 0xffff;
17200 }
17201
17202 if (immediate == (immediate & 0x000000ff))
17203 {
17204 *immbits = immediate;
17205 return 0x9;
17206 }
17207 else if (immediate == (immediate & 0x0000ff00))
17208 {
17209 *immbits = immediate >> 8;
17210 return 0xb;
17211 }
17212
17213 bad_immediate:
17214 first_error (_("immediate value out of range"));
17215 return FAIL;
17216 }
17217
17218 static void
17219 do_neon_logic (void)
17220 {
17221 if (inst.operands[2].present && inst.operands[2].isreg)
17222 {
17223 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17224 if (rs == NS_QQQ
17225 && !check_simd_pred_availability (FALSE,
17226 NEON_CHECK_ARCH | NEON_CHECK_CC))
17227 return;
17228 else if (rs != NS_QQQ
17229 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17230 first_error (BAD_FPU);
17231
17232 neon_check_type (3, rs, N_IGNORE_TYPE);
17233 /* U bit and size field were set as part of the bitmask. */
17234 NEON_ENCODE (INTEGER, inst);
17235 neon_three_same (neon_quad (rs), 0, -1);
17236 }
17237 else
17238 {
17239 const int three_ops_form = (inst.operands[2].present
17240 && !inst.operands[2].isreg);
17241 const int immoperand = (three_ops_form ? 2 : 1);
17242 enum neon_shape rs = (three_ops_form
17243 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17244 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
17245 /* Because neon_select_shape makes the second operand a copy of the first
17246 if the second operand is not present. */
17247 if (rs == NS_QQI
17248 && !check_simd_pred_availability (FALSE,
17249 NEON_CHECK_ARCH | NEON_CHECK_CC))
17250 return;
17251 else if (rs != NS_QQI
17252 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17253 first_error (BAD_FPU);
17254
17255 struct neon_type_el et;
17256 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17257 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17258 else
17259 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17260 | N_KEY, N_EQK);
17261
17262 if (et.type == NT_invtype)
17263 return;
17264 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
17265 unsigned immbits;
17266 int cmode;
17267
17268
17269 if (three_ops_form)
17270 constraint (inst.operands[0].reg != inst.operands[1].reg,
17271 _("first and second operands shall be the same register"));
17272
17273 NEON_ENCODE (IMMED, inst);
17274
17275 immbits = inst.operands[immoperand].imm;
17276 if (et.size == 64)
17277 {
17278 /* .i64 is a pseudo-op, so the immediate must be a repeating
17279 pattern. */
17280 if (immbits != (inst.operands[immoperand].regisimm ?
17281 inst.operands[immoperand].reg : 0))
17282 {
17283 /* Set immbits to an invalid constant. */
17284 immbits = 0xdeadbeef;
17285 }
17286 }
17287
17288 switch (opcode)
17289 {
17290 case N_MNEM_vbic:
17291 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17292 break;
17293
17294 case N_MNEM_vorr:
17295 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17296 break;
17297
17298 case N_MNEM_vand:
17299 /* Pseudo-instruction for VBIC. */
17300 neon_invert_size (&immbits, 0, et.size);
17301 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17302 break;
17303
17304 case N_MNEM_vorn:
17305 /* Pseudo-instruction for VORR. */
17306 neon_invert_size (&immbits, 0, et.size);
17307 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17308 break;
17309
17310 default:
17311 abort ();
17312 }
17313
17314 if (cmode == FAIL)
17315 return;
17316
17317 inst.instruction |= neon_quad (rs) << 6;
17318 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17319 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17320 inst.instruction |= cmode << 8;
17321 neon_write_immbits (immbits);
17322
17323 neon_dp_fixup (&inst);
17324 }
17325 }
17326
17327 static void
17328 do_neon_bitfield (void)
17329 {
17330 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17331 neon_check_type (3, rs, N_IGNORE_TYPE);
17332 neon_three_same (neon_quad (rs), 0, -1);
17333 }
17334
17335 static void
17336 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
17337 unsigned destbits)
17338 {
17339 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17340 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
17341 types | N_KEY);
17342 if (et.type == NT_float)
17343 {
17344 NEON_ENCODE (FLOAT, inst);
17345 if (rs == NS_QQR)
17346 mve_encode_qqr (et.size, 0, 1);
17347 else
17348 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
17349 }
17350 else
17351 {
17352 NEON_ENCODE (INTEGER, inst);
17353 if (rs == NS_QQR)
17354 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
17355 else
17356 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
17357 }
17358 }
17359
17360
17361 static void
17362 do_neon_dyadic_if_su_d (void)
17363 {
17364 /* This version only allow D registers, but that constraint is enforced during
17365 operand parsing so we don't need to do anything extra here. */
17366 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17367 }
17368
17369 static void
17370 do_neon_dyadic_if_i_d (void)
17371 {
17372 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17373 affected if we specify unsigned args. */
17374 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17375 }
17376
17377 static void
17378 do_mve_vstr_vldr_QI (int size, int elsize, int load)
17379 {
17380 constraint (size < 32, BAD_ADDR_MODE);
17381 constraint (size != elsize, BAD_EL_TYPE);
17382 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17383 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17384 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17385 _("destination register and offset register may not be the"
17386 " same"));
17387
17388 int imm = inst.relocs[0].exp.X_add_number;
17389 int add = 1;
17390 if (imm < 0)
17391 {
17392 add = 0;
17393 imm = -imm;
17394 }
17395 constraint ((imm % (size / 8) != 0)
17396 || imm > (0x7f << neon_logbits (size)),
17397 (size == 32) ? _("immediate must be a multiple of 4 in the"
17398 " range of +/-[0,508]")
17399 : _("immediate must be a multiple of 8 in the"
17400 " range of +/-[0,1016]"));
17401 inst.instruction |= 0x11 << 24;
17402 inst.instruction |= add << 23;
17403 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17404 inst.instruction |= inst.operands[1].writeback << 21;
17405 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17406 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17407 inst.instruction |= 1 << 12;
17408 inst.instruction |= (size == 64) << 8;
17409 inst.instruction &= 0xffffff00;
17410 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17411 inst.instruction |= imm >> neon_logbits (size);
17412 }
17413
17414 static void
17415 do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17416 {
17417 unsigned os = inst.operands[1].imm >> 5;
17418 unsigned type = inst.vectype.el[0].type;
17419 constraint (os != 0 && size == 8,
17420 _("can not shift offsets when accessing less than half-word"));
17421 constraint (os && os != neon_logbits (size),
17422 _("shift immediate must be 1, 2 or 3 for half-word, word"
17423 " or double-word accesses respectively"));
17424 if (inst.operands[1].reg == REG_PC)
17425 as_tsktsk (MVE_BAD_PC);
17426
17427 switch (size)
17428 {
17429 case 8:
17430 constraint (elsize >= 64, BAD_EL_TYPE);
17431 break;
17432 case 16:
17433 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17434 break;
17435 case 32:
17436 case 64:
17437 constraint (elsize != size, BAD_EL_TYPE);
17438 break;
17439 default:
17440 break;
17441 }
17442 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17443 BAD_ADDR_MODE);
17444 if (load)
17445 {
17446 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17447 _("destination register and offset register may not be"
17448 " the same"));
17449 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17450 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
17451 BAD_EL_TYPE);
17452 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
17453 }
17454 else
17455 {
17456 constraint (type != NT_untyped, BAD_EL_TYPE);
17457 }
17458
17459 inst.instruction |= 1 << 23;
17460 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17461 inst.instruction |= inst.operands[1].reg << 16;
17462 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17463 inst.instruction |= neon_logbits (elsize) << 7;
17464 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17465 inst.instruction |= LOW4 (inst.operands[1].imm);
17466 inst.instruction |= !!os;
17467 }
17468
17469 static void
17470 do_mve_vstr_vldr_RI (int size, int elsize, int load)
17471 {
17472 enum neon_el_type type = inst.vectype.el[0].type;
17473
17474 constraint (size >= 64, BAD_ADDR_MODE);
17475 switch (size)
17476 {
17477 case 16:
17478 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17479 break;
17480 case 32:
17481 constraint (elsize != size, BAD_EL_TYPE);
17482 break;
17483 default:
17484 break;
17485 }
17486 if (load)
17487 {
17488 constraint (elsize != size && type != NT_unsigned
17489 && type != NT_signed, BAD_EL_TYPE);
17490 }
17491 else
17492 {
17493 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17494 }
17495
17496 int imm = inst.relocs[0].exp.X_add_number;
17497 int add = 1;
17498 if (imm < 0)
17499 {
17500 add = 0;
17501 imm = -imm;
17502 }
17503
17504 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17505 {
17506 switch (size)
17507 {
17508 case 8:
17509 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17510 break;
17511 case 16:
17512 constraint (1, _("immediate must be a multiple of 2 in the"
17513 " range of +/-[0,254]"));
17514 break;
17515 case 32:
17516 constraint (1, _("immediate must be a multiple of 4 in the"
17517 " range of +/-[0,508]"));
17518 break;
17519 }
17520 }
17521
17522 if (size != elsize)
17523 {
17524 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17525 constraint (inst.operands[0].reg > 14,
17526 _("MVE vector register in the range [Q0..Q7] expected"));
17527 inst.instruction |= (load && type == NT_unsigned) << 28;
17528 inst.instruction |= (size == 16) << 19;
17529 inst.instruction |= neon_logbits (elsize) << 7;
17530 }
17531 else
17532 {
17533 if (inst.operands[1].reg == REG_PC)
17534 as_tsktsk (MVE_BAD_PC);
17535 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17536 as_tsktsk (MVE_BAD_SP);
17537 inst.instruction |= 1 << 12;
17538 inst.instruction |= neon_logbits (size) << 7;
17539 }
17540 inst.instruction |= inst.operands[1].preind << 24;
17541 inst.instruction |= add << 23;
17542 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17543 inst.instruction |= inst.operands[1].writeback << 21;
17544 inst.instruction |= inst.operands[1].reg << 16;
17545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17546 inst.instruction &= 0xffffff80;
17547 inst.instruction |= imm >> neon_logbits (size);
17548
17549 }
17550
17551 static void
17552 do_mve_vstr_vldr (void)
17553 {
17554 unsigned size;
17555 int load = 0;
17556
17557 if (inst.cond > COND_ALWAYS)
17558 inst.pred_insn_type = INSIDE_VPT_INSN;
17559 else
17560 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17561
17562 switch (inst.instruction)
17563 {
17564 default:
17565 gas_assert (0);
17566 break;
17567 case M_MNEM_vldrb:
17568 load = 1;
17569 /* fall through. */
17570 case M_MNEM_vstrb:
17571 size = 8;
17572 break;
17573 case M_MNEM_vldrh:
17574 load = 1;
17575 /* fall through. */
17576 case M_MNEM_vstrh:
17577 size = 16;
17578 break;
17579 case M_MNEM_vldrw:
17580 load = 1;
17581 /* fall through. */
17582 case M_MNEM_vstrw:
17583 size = 32;
17584 break;
17585 case M_MNEM_vldrd:
17586 load = 1;
17587 /* fall through. */
17588 case M_MNEM_vstrd:
17589 size = 64;
17590 break;
17591 }
17592 unsigned elsize = inst.vectype.el[0].size;
17593
17594 if (inst.operands[1].isquad)
17595 {
17596 /* We are dealing with [Q, imm]{!} cases. */
17597 do_mve_vstr_vldr_QI (size, elsize, load);
17598 }
17599 else
17600 {
17601 if (inst.operands[1].immisreg == 2)
17602 {
17603 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17604 do_mve_vstr_vldr_RQ (size, elsize, load);
17605 }
17606 else if (!inst.operands[1].immisreg)
17607 {
17608 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17609 do_mve_vstr_vldr_RI (size, elsize, load);
17610 }
17611 else
17612 constraint (1, BAD_ADDR_MODE);
17613 }
17614
17615 inst.is_neon = 1;
17616 }
17617
17618 static void
17619 do_mve_vst_vld (void)
17620 {
17621 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17622 return;
17623
17624 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17625 || inst.relocs[0].exp.X_add_number != 0
17626 || inst.operands[1].immisreg != 0,
17627 BAD_ADDR_MODE);
17628 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17629 if (inst.operands[1].reg == REG_PC)
17630 as_tsktsk (MVE_BAD_PC);
17631 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17632 as_tsktsk (MVE_BAD_SP);
17633
17634
17635 /* These instructions are one of the "exceptions" mentioned in
17636 handle_pred_state. They are MVE instructions that are not VPT compatible
17637 and do not accept a VPT code, thus appending such a code is a syntax
17638 error. */
17639 if (inst.cond > COND_ALWAYS)
17640 first_error (BAD_SYNTAX);
17641 /* If we append a scalar condition code we can set this to
17642 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17643 else if (inst.cond < COND_ALWAYS)
17644 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17645 else
17646 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17647
17648 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17649 inst.instruction |= inst.operands[1].writeback << 21;
17650 inst.instruction |= inst.operands[1].reg << 16;
17651 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17652 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17653 inst.is_neon = 1;
17654 }
17655
17656 static void
17657 do_mve_vaddlv (void)
17658 {
17659 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17660 struct neon_type_el et
17661 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17662
17663 if (et.type == NT_invtype)
17664 first_error (BAD_EL_TYPE);
17665
17666 if (inst.cond > COND_ALWAYS)
17667 inst.pred_insn_type = INSIDE_VPT_INSN;
17668 else
17669 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17670
17671 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17672
17673 inst.instruction |= (et.type == NT_unsigned) << 28;
17674 inst.instruction |= inst.operands[1].reg << 19;
17675 inst.instruction |= inst.operands[0].reg << 12;
17676 inst.instruction |= inst.operands[2].reg;
17677 inst.is_neon = 1;
17678 }
17679
17680 static void
17681 do_neon_dyadic_if_su (void)
17682 {
17683 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17684 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17685 N_SUF_32 | N_KEY);
17686
17687 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17688 || inst.instruction == ((unsigned) N_MNEM_vmin))
17689 && et.type == NT_float
17690 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17691
17692 if (!check_simd_pred_availability (et.type == NT_float,
17693 NEON_CHECK_ARCH | NEON_CHECK_CC))
17694 return;
17695
17696 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17697 }
17698
17699 static void
17700 do_neon_addsub_if_i (void)
17701 {
17702 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17703 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
17704 return;
17705
17706 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17707 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17708 N_EQK, N_IF_32 | N_I64 | N_KEY);
17709
17710 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17711 /* If we are parsing Q registers and the element types match MVE, which NEON
17712 also supports, then we must check whether this is an instruction that can
17713 be used by both MVE/NEON. This distinction can be made based on whether
17714 they are predicated or not. */
17715 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17716 {
17717 if (!check_simd_pred_availability (et.type == NT_float,
17718 NEON_CHECK_ARCH | NEON_CHECK_CC))
17719 return;
17720 }
17721 else
17722 {
17723 /* If they are either in a D register or are using an unsupported. */
17724 if (rs != NS_QQR
17725 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17726 return;
17727 }
17728
17729 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17730 affected if we specify unsigned args. */
17731 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
17732 }
17733
17734 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17735 result to be:
17736 V<op> A,B (A is operand 0, B is operand 2)
17737 to mean:
17738 V<op> A,B,A
17739 not:
17740 V<op> A,B,B
17741 so handle that case specially. */
17742
17743 static void
17744 neon_exchange_operands (void)
17745 {
17746 if (inst.operands[1].present)
17747 {
17748 void *scratch = xmalloc (sizeof (inst.operands[0]));
17749
17750 /* Swap operands[1] and operands[2]. */
17751 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17752 inst.operands[1] = inst.operands[2];
17753 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
17754 free (scratch);
17755 }
17756 else
17757 {
17758 inst.operands[1] = inst.operands[2];
17759 inst.operands[2] = inst.operands[0];
17760 }
17761 }
17762
17763 static void
17764 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17765 {
17766 if (inst.operands[2].isreg)
17767 {
17768 if (invert)
17769 neon_exchange_operands ();
17770 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
17771 }
17772 else
17773 {
17774 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17775 struct neon_type_el et = neon_check_type (2, rs,
17776 N_EQK | N_SIZ, immtypes | N_KEY);
17777
17778 NEON_ENCODE (IMMED, inst);
17779 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17780 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17781 inst.instruction |= LOW4 (inst.operands[1].reg);
17782 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17783 inst.instruction |= neon_quad (rs) << 6;
17784 inst.instruction |= (et.type == NT_float) << 10;
17785 inst.instruction |= neon_logbits (et.size) << 18;
17786
17787 neon_dp_fixup (&inst);
17788 }
17789 }
17790
17791 static void
17792 do_neon_cmp (void)
17793 {
17794 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
17795 }
17796
17797 static void
17798 do_neon_cmp_inv (void)
17799 {
17800 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
17801 }
17802
17803 static void
17804 do_neon_ceq (void)
17805 {
17806 neon_compare (N_IF_32, N_IF_32, FALSE);
17807 }
17808
17809 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
17810 scalars, which are encoded in 5 bits, M : Rm.
17811 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17812 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
17813 index in M.
17814
17815 Dot Product instructions are similar to multiply instructions except elsize
17816 should always be 32.
17817
17818 This function translates SCALAR, which is GAS's internal encoding of indexed
17819 scalar register, to raw encoding. There is also register and index range
17820 check based on ELSIZE. */
17821
17822 static unsigned
17823 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17824 {
17825 unsigned regno = NEON_SCALAR_REG (scalar);
17826 unsigned elno = NEON_SCALAR_INDEX (scalar);
17827
17828 switch (elsize)
17829 {
17830 case 16:
17831 if (regno > 7 || elno > 3)
17832 goto bad_scalar;
17833 return regno | (elno << 3);
17834
17835 case 32:
17836 if (regno > 15 || elno > 1)
17837 goto bad_scalar;
17838 return regno | (elno << 4);
17839
17840 default:
17841 bad_scalar:
17842 first_error (_("scalar out of range for multiply instruction"));
17843 }
17844
17845 return 0;
17846 }
17847
17848 /* Encode multiply / multiply-accumulate scalar instructions. */
17849
17850 static void
17851 neon_mul_mac (struct neon_type_el et, int ubit)
17852 {
17853 unsigned scalar;
17854
17855 /* Give a more helpful error message if we have an invalid type. */
17856 if (et.type == NT_invtype)
17857 return;
17858
17859 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
17860 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17861 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17862 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17863 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17864 inst.instruction |= LOW4 (scalar);
17865 inst.instruction |= HI1 (scalar) << 5;
17866 inst.instruction |= (et.type == NT_float) << 8;
17867 inst.instruction |= neon_logbits (et.size) << 20;
17868 inst.instruction |= (ubit != 0) << 24;
17869
17870 neon_dp_fixup (&inst);
17871 }
17872
17873 static void
17874 do_neon_mac_maybe_scalar (void)
17875 {
17876 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17877 return;
17878
17879 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17880 return;
17881
17882 if (inst.operands[2].isscalar)
17883 {
17884 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17885 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17886 struct neon_type_el et = neon_check_type (3, rs,
17887 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
17888 NEON_ENCODE (SCALAR, inst);
17889 neon_mul_mac (et, neon_quad (rs));
17890 }
17891 else if (!inst.operands[2].isvec)
17892 {
17893 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17894
17895 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17896 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17897
17898 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17899 }
17900 else
17901 {
17902 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17903 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17904 affected if we specify unsigned args. */
17905 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17906 }
17907 }
17908
17909 static void
17910 do_bfloat_vfma (void)
17911 {
17912 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17913 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17914 enum neon_shape rs;
17915 int t_bit = 0;
17916
17917 if (inst.instruction != B_MNEM_vfmab)
17918 {
17919 t_bit = 1;
17920 inst.instruction = B_MNEM_vfmat;
17921 }
17922
17923 if (inst.operands[2].isscalar)
17924 {
17925 rs = neon_select_shape (NS_QQS, NS_NULL);
17926 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17927
17928 inst.instruction |= (1 << 25);
17929 int index = inst.operands[2].reg & 0xf;
17930 constraint (!(index < 4), _("index must be in the range 0 to 3"));
17931 inst.operands[2].reg >>= 4;
17932 constraint (!(inst.operands[2].reg < 8),
17933 _("indexed register must be less than 8"));
17934 neon_three_args (t_bit);
17935 inst.instruction |= ((index & 1) << 3);
17936 inst.instruction |= ((index & 2) << 4);
17937 }
17938 else
17939 {
17940 rs = neon_select_shape (NS_QQQ, NS_NULL);
17941 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17942 neon_three_args (t_bit);
17943 }
17944
17945 }
17946
17947 static void
17948 do_neon_fmac (void)
17949 {
17950 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17951 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
17952 return;
17953
17954 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17955 return;
17956
17957 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17958 {
17959 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17960 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17961 N_EQK);
17962
17963 if (rs == NS_QQR)
17964 {
17965
17966 if (inst.operands[2].reg == REG_SP)
17967 as_tsktsk (MVE_BAD_SP);
17968 else if (inst.operands[2].reg == REG_PC)
17969 as_tsktsk (MVE_BAD_PC);
17970
17971 inst.instruction = 0xee310e40;
17972 inst.instruction |= (et.size == 16) << 28;
17973 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17974 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17975 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17976 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17977 inst.instruction |= inst.operands[2].reg;
17978 inst.is_neon = 1;
17979 return;
17980 }
17981 }
17982 else
17983 {
17984 constraint (!inst.operands[2].isvec, BAD_FPU);
17985 }
17986
17987 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17988 }
17989
17990 static void
17991 do_mve_vfma (void)
17992 {
17993 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
17994 inst.cond == COND_ALWAYS)
17995 {
17996 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17997 inst.instruction = N_MNEM_vfma;
17998 inst.pred_insn_type = INSIDE_VPT_INSN;
17999 inst.cond = 0xf;
18000 return do_neon_fmac();
18001 }
18002 else
18003 {
18004 do_bfloat_vfma();
18005 }
18006 }
18007
18008 static void
18009 do_neon_tst (void)
18010 {
18011 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18012 struct neon_type_el et = neon_check_type (3, rs,
18013 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18014 neon_three_same (neon_quad (rs), 0, et.size);
18015 }
18016
18017 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
18018 same types as the MAC equivalents. The polynomial type for this instruction
18019 is encoded the same as the integer type. */
18020
18021 static void
18022 do_neon_mul (void)
18023 {
18024 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18025 return;
18026
18027 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
18028 return;
18029
18030 if (inst.operands[2].isscalar)
18031 {
18032 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18033 do_neon_mac_maybe_scalar ();
18034 }
18035 else
18036 {
18037 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18038 {
18039 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18040 struct neon_type_el et
18041 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18042 if (et.type == NT_float)
18043 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18044 BAD_FPU);
18045
18046 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18047 }
18048 else
18049 {
18050 constraint (!inst.operands[2].isvec, BAD_FPU);
18051 neon_dyadic_misc (NT_poly,
18052 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18053 }
18054 }
18055 }
18056
18057 static void
18058 do_neon_qdmulh (void)
18059 {
18060 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18061 return;
18062
18063 if (inst.operands[2].isscalar)
18064 {
18065 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18066 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18067 struct neon_type_el et = neon_check_type (3, rs,
18068 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18069 NEON_ENCODE (SCALAR, inst);
18070 neon_mul_mac (et, neon_quad (rs));
18071 }
18072 else
18073 {
18074 enum neon_shape rs;
18075 struct neon_type_el et;
18076 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18077 {
18078 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18079 et = neon_check_type (3, rs,
18080 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18081 }
18082 else
18083 {
18084 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18085 et = neon_check_type (3, rs,
18086 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18087 }
18088
18089 NEON_ENCODE (INTEGER, inst);
18090 if (rs == NS_QQR)
18091 mve_encode_qqr (et.size, 0, 0);
18092 else
18093 /* The U bit (rounding) comes from bit mask. */
18094 neon_three_same (neon_quad (rs), 0, et.size);
18095 }
18096 }
18097
18098 static void
18099 do_mve_vaddv (void)
18100 {
18101 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18102 struct neon_type_el et
18103 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18104
18105 if (et.type == NT_invtype)
18106 first_error (BAD_EL_TYPE);
18107
18108 if (inst.cond > COND_ALWAYS)
18109 inst.pred_insn_type = INSIDE_VPT_INSN;
18110 else
18111 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18112
18113 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18114
18115 mve_encode_rq (et.type == NT_unsigned, et.size);
18116 }
18117
18118 static void
18119 do_mve_vhcadd (void)
18120 {
18121 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18122 struct neon_type_el et
18123 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18124
18125 if (inst.cond > COND_ALWAYS)
18126 inst.pred_insn_type = INSIDE_VPT_INSN;
18127 else
18128 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18129
18130 unsigned rot = inst.relocs[0].exp.X_add_number;
18131 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18132
18133 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18134 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18135 "operand makes instruction UNPREDICTABLE"));
18136
18137 mve_encode_qqq (0, et.size);
18138 inst.instruction |= (rot == 270) << 12;
18139 inst.is_neon = 1;
18140 }
18141
18142 static void
18143 do_mve_vqdmull (void)
18144 {
18145 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18146 struct neon_type_el et
18147 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18148
18149 if (et.size == 32
18150 && (inst.operands[0].reg == inst.operands[1].reg
18151 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18152 as_tsktsk (BAD_MVE_SRCDEST);
18153
18154 if (inst.cond > COND_ALWAYS)
18155 inst.pred_insn_type = INSIDE_VPT_INSN;
18156 else
18157 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18158
18159 if (rs == NS_QQQ)
18160 {
18161 mve_encode_qqq (et.size == 32, 64);
18162 inst.instruction |= 1;
18163 }
18164 else
18165 {
18166 mve_encode_qqr (64, et.size == 32, 0);
18167 inst.instruction |= 0x3 << 5;
18168 }
18169 }
18170
18171 static void
18172 do_mve_vadc (void)
18173 {
18174 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18175 struct neon_type_el et
18176 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18177
18178 if (et.type == NT_invtype)
18179 first_error (BAD_EL_TYPE);
18180
18181 if (inst.cond > COND_ALWAYS)
18182 inst.pred_insn_type = INSIDE_VPT_INSN;
18183 else
18184 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18185
18186 mve_encode_qqq (0, 64);
18187 }
18188
18189 static void
18190 do_mve_vbrsr (void)
18191 {
18192 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18193 struct neon_type_el et
18194 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18195
18196 if (inst.cond > COND_ALWAYS)
18197 inst.pred_insn_type = INSIDE_VPT_INSN;
18198 else
18199 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18200
18201 mve_encode_qqr (et.size, 0, 0);
18202 }
18203
18204 static void
18205 do_mve_vsbc (void)
18206 {
18207 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18208
18209 if (inst.cond > COND_ALWAYS)
18210 inst.pred_insn_type = INSIDE_VPT_INSN;
18211 else
18212 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18213
18214 mve_encode_qqq (1, 64);
18215 }
18216
18217 static void
18218 do_mve_vmulh (void)
18219 {
18220 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18221 struct neon_type_el et
18222 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18223
18224 if (inst.cond > COND_ALWAYS)
18225 inst.pred_insn_type = INSIDE_VPT_INSN;
18226 else
18227 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18228
18229 mve_encode_qqq (et.type == NT_unsigned, et.size);
18230 }
18231
18232 static void
18233 do_mve_vqdmlah (void)
18234 {
18235 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18236 struct neon_type_el et
18237 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18238
18239 if (inst.cond > COND_ALWAYS)
18240 inst.pred_insn_type = INSIDE_VPT_INSN;
18241 else
18242 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18243
18244 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18245 }
18246
18247 static void
18248 do_mve_vqdmladh (void)
18249 {
18250 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18251 struct neon_type_el et
18252 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18253
18254 if (inst.cond > COND_ALWAYS)
18255 inst.pred_insn_type = INSIDE_VPT_INSN;
18256 else
18257 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18258
18259 mve_encode_qqq (0, et.size);
18260 }
18261
18262
18263 static void
18264 do_mve_vmull (void)
18265 {
18266
18267 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18268 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18269 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
18270 && inst.cond == COND_ALWAYS
18271 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18272 {
18273 if (rs == NS_QQQ)
18274 {
18275
18276 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18277 N_SUF_32 | N_F64 | N_P8
18278 | N_P16 | N_I_MVE | N_KEY);
18279 if (((et.type == NT_poly) && et.size == 8
18280 && ARM_CPU_IS_ANY (cpu_variant))
18281 || (et.type == NT_integer) || (et.type == NT_float))
18282 goto neon_vmul;
18283 }
18284 else
18285 goto neon_vmul;
18286 }
18287
18288 constraint (rs != NS_QQQ, BAD_FPU);
18289 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18290 N_SU_32 | N_P8 | N_P16 | N_KEY);
18291
18292 /* We are dealing with MVE's vmullt. */
18293 if (et.size == 32
18294 && (inst.operands[0].reg == inst.operands[1].reg
18295 || inst.operands[0].reg == inst.operands[2].reg))
18296 as_tsktsk (BAD_MVE_SRCDEST);
18297
18298 if (inst.cond > COND_ALWAYS)
18299 inst.pred_insn_type = INSIDE_VPT_INSN;
18300 else
18301 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18302
18303 if (et.type == NT_poly)
18304 mve_encode_qqq (neon_logbits (et.size), 64);
18305 else
18306 mve_encode_qqq (et.type == NT_unsigned, et.size);
18307
18308 return;
18309
18310 neon_vmul:
18311 inst.instruction = N_MNEM_vmul;
18312 inst.cond = 0xb;
18313 if (thumb_mode)
18314 inst.pred_insn_type = INSIDE_IT_INSN;
18315 do_neon_mul ();
18316 }
18317
18318 static void
18319 do_mve_vabav (void)
18320 {
18321 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18322
18323 if (rs == NS_NULL)
18324 return;
18325
18326 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18327 return;
18328
18329 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18330 | N_S16 | N_S32 | N_U8 | N_U16
18331 | N_U32);
18332
18333 if (inst.cond > COND_ALWAYS)
18334 inst.pred_insn_type = INSIDE_VPT_INSN;
18335 else
18336 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18337
18338 mve_encode_rqq (et.type == NT_unsigned, et.size);
18339 }
18340
18341 static void
18342 do_mve_vmladav (void)
18343 {
18344 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18345 struct neon_type_el et = neon_check_type (3, rs,
18346 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18347
18348 if (et.type == NT_unsigned
18349 && (inst.instruction == M_MNEM_vmladavx
18350 || inst.instruction == M_MNEM_vmladavax
18351 || inst.instruction == M_MNEM_vmlsdav
18352 || inst.instruction == M_MNEM_vmlsdava
18353 || inst.instruction == M_MNEM_vmlsdavx
18354 || inst.instruction == M_MNEM_vmlsdavax))
18355 first_error (BAD_SIMD_TYPE);
18356
18357 constraint (inst.operands[2].reg > 14,
18358 _("MVE vector register in the range [Q0..Q7] expected"));
18359
18360 if (inst.cond > COND_ALWAYS)
18361 inst.pred_insn_type = INSIDE_VPT_INSN;
18362 else
18363 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18364
18365 if (inst.instruction == M_MNEM_vmlsdav
18366 || inst.instruction == M_MNEM_vmlsdava
18367 || inst.instruction == M_MNEM_vmlsdavx
18368 || inst.instruction == M_MNEM_vmlsdavax)
18369 inst.instruction |= (et.size == 8) << 28;
18370 else
18371 inst.instruction |= (et.size == 8) << 8;
18372
18373 mve_encode_rqq (et.type == NT_unsigned, 64);
18374 inst.instruction |= (et.size == 32) << 16;
18375 }
18376
18377 static void
18378 do_mve_vmlaldav (void)
18379 {
18380 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18381 struct neon_type_el et
18382 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18383 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18384
18385 if (et.type == NT_unsigned
18386 && (inst.instruction == M_MNEM_vmlsldav
18387 || inst.instruction == M_MNEM_vmlsldava
18388 || inst.instruction == M_MNEM_vmlsldavx
18389 || inst.instruction == M_MNEM_vmlsldavax))
18390 first_error (BAD_SIMD_TYPE);
18391
18392 if (inst.cond > COND_ALWAYS)
18393 inst.pred_insn_type = INSIDE_VPT_INSN;
18394 else
18395 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18396
18397 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18398 }
18399
18400 static void
18401 do_mve_vrmlaldavh (void)
18402 {
18403 struct neon_type_el et;
18404 if (inst.instruction == M_MNEM_vrmlsldavh
18405 || inst.instruction == M_MNEM_vrmlsldavha
18406 || inst.instruction == M_MNEM_vrmlsldavhx
18407 || inst.instruction == M_MNEM_vrmlsldavhax)
18408 {
18409 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18410 if (inst.operands[1].reg == REG_SP)
18411 as_tsktsk (MVE_BAD_SP);
18412 }
18413 else
18414 {
18415 if (inst.instruction == M_MNEM_vrmlaldavhx
18416 || inst.instruction == M_MNEM_vrmlaldavhax)
18417 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18418 else
18419 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18420 N_U32 | N_S32 | N_KEY);
18421 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18422 with vmax/min instructions, making the use of SP in assembly really
18423 nonsensical, so instead of issuing a warning like we do for other uses
18424 of SP for the odd register operand we error out. */
18425 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18426 }
18427
18428 /* Make sure we still check the second operand is an odd one and that PC is
18429 disallowed. This because we are parsing for any GPR operand, to be able
18430 to distinguish between giving a warning or an error for SP as described
18431 above. */
18432 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18433 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18434
18435 if (inst.cond > COND_ALWAYS)
18436 inst.pred_insn_type = INSIDE_VPT_INSN;
18437 else
18438 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18439
18440 mve_encode_rrqq (et.type == NT_unsigned, 0);
18441 }
18442
18443
18444 static void
18445 do_mve_vmaxnmv (void)
18446 {
18447 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18448 struct neon_type_el et
18449 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18450
18451 if (inst.cond > COND_ALWAYS)
18452 inst.pred_insn_type = INSIDE_VPT_INSN;
18453 else
18454 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18455
18456 if (inst.operands[0].reg == REG_SP)
18457 as_tsktsk (MVE_BAD_SP);
18458 else if (inst.operands[0].reg == REG_PC)
18459 as_tsktsk (MVE_BAD_PC);
18460
18461 mve_encode_rq (et.size == 16, 64);
18462 }
18463
18464 static void
18465 do_mve_vmaxv (void)
18466 {
18467 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18468 struct neon_type_el et;
18469
18470 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18471 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18472 else
18473 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18474
18475 if (inst.cond > COND_ALWAYS)
18476 inst.pred_insn_type = INSIDE_VPT_INSN;
18477 else
18478 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18479
18480 if (inst.operands[0].reg == REG_SP)
18481 as_tsktsk (MVE_BAD_SP);
18482 else if (inst.operands[0].reg == REG_PC)
18483 as_tsktsk (MVE_BAD_PC);
18484
18485 mve_encode_rq (et.type == NT_unsigned, et.size);
18486 }
18487
18488
18489 static void
18490 do_neon_qrdmlah (void)
18491 {
18492 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18493 return;
18494 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18495 {
18496 /* Check we're on the correct architecture. */
18497 if (!mark_feature_used (&fpu_neon_ext_armv8))
18498 inst.error
18499 = _("instruction form not available on this architecture.");
18500 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18501 {
18502 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18503 record_feature_use (&fpu_neon_ext_v8_1);
18504 }
18505 if (inst.operands[2].isscalar)
18506 {
18507 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18508 struct neon_type_el et = neon_check_type (3, rs,
18509 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18510 NEON_ENCODE (SCALAR, inst);
18511 neon_mul_mac (et, neon_quad (rs));
18512 }
18513 else
18514 {
18515 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18516 struct neon_type_el et = neon_check_type (3, rs,
18517 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18518 NEON_ENCODE (INTEGER, inst);
18519 /* The U bit (rounding) comes from bit mask. */
18520 neon_three_same (neon_quad (rs), 0, et.size);
18521 }
18522 }
18523 else
18524 {
18525 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18526 struct neon_type_el et
18527 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18528
18529 NEON_ENCODE (INTEGER, inst);
18530 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18531 }
18532 }
18533
18534 static void
18535 do_neon_fcmp_absolute (void)
18536 {
18537 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18538 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18539 N_F_16_32 | N_KEY);
18540 /* Size field comes from bit mask. */
18541 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
18542 }
18543
18544 static void
18545 do_neon_fcmp_absolute_inv (void)
18546 {
18547 neon_exchange_operands ();
18548 do_neon_fcmp_absolute ();
18549 }
18550
18551 static void
18552 do_neon_step (void)
18553 {
18554 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18555 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18556 N_F_16_32 | N_KEY);
18557 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
18558 }
18559
18560 static void
18561 do_neon_abs_neg (void)
18562 {
18563 enum neon_shape rs;
18564 struct neon_type_el et;
18565
18566 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18567 return;
18568
18569 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
18570 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
18571
18572 if (!check_simd_pred_availability (et.type == NT_float,
18573 NEON_CHECK_ARCH | NEON_CHECK_CC))
18574 return;
18575
18576 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18577 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18578 inst.instruction |= LOW4 (inst.operands[1].reg);
18579 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18580 inst.instruction |= neon_quad (rs) << 6;
18581 inst.instruction |= (et.type == NT_float) << 10;
18582 inst.instruction |= neon_logbits (et.size) << 18;
18583
18584 neon_dp_fixup (&inst);
18585 }
18586
18587 static void
18588 do_neon_sli (void)
18589 {
18590 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18591 return;
18592
18593 enum neon_shape rs;
18594 struct neon_type_el et;
18595 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18596 {
18597 rs = neon_select_shape (NS_QQI, NS_NULL);
18598 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18599 }
18600 else
18601 {
18602 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18603 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18604 }
18605
18606
18607 int imm = inst.operands[2].imm;
18608 constraint (imm < 0 || (unsigned)imm >= et.size,
18609 _("immediate out of range for insert"));
18610 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
18611 }
18612
18613 static void
18614 do_neon_sri (void)
18615 {
18616 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18617 return;
18618
18619 enum neon_shape rs;
18620 struct neon_type_el et;
18621 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18622 {
18623 rs = neon_select_shape (NS_QQI, NS_NULL);
18624 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18625 }
18626 else
18627 {
18628 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18629 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18630 }
18631
18632 int imm = inst.operands[2].imm;
18633 constraint (imm < 1 || (unsigned)imm > et.size,
18634 _("immediate out of range for insert"));
18635 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
18636 }
18637
18638 static void
18639 do_neon_qshlu_imm (void)
18640 {
18641 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18642 return;
18643
18644 enum neon_shape rs;
18645 struct neon_type_el et;
18646 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18647 {
18648 rs = neon_select_shape (NS_QQI, NS_NULL);
18649 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18650 }
18651 else
18652 {
18653 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18654 et = neon_check_type (2, rs, N_EQK | N_UNS,
18655 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18656 }
18657
18658 int imm = inst.operands[2].imm;
18659 constraint (imm < 0 || (unsigned)imm >= et.size,
18660 _("immediate out of range for shift"));
18661 /* Only encodes the 'U present' variant of the instruction.
18662 In this case, signed types have OP (bit 8) set to 0.
18663 Unsigned types have OP set to 1. */
18664 inst.instruction |= (et.type == NT_unsigned) << 8;
18665 /* The rest of the bits are the same as other immediate shifts. */
18666 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
18667 }
18668
18669 static void
18670 do_neon_qmovn (void)
18671 {
18672 struct neon_type_el et = neon_check_type (2, NS_DQ,
18673 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18674 /* Saturating move where operands can be signed or unsigned, and the
18675 destination has the same signedness. */
18676 NEON_ENCODE (INTEGER, inst);
18677 if (et.type == NT_unsigned)
18678 inst.instruction |= 0xc0;
18679 else
18680 inst.instruction |= 0x80;
18681 neon_two_same (0, 1, et.size / 2);
18682 }
18683
18684 static void
18685 do_neon_qmovun (void)
18686 {
18687 struct neon_type_el et = neon_check_type (2, NS_DQ,
18688 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18689 /* Saturating move with unsigned results. Operands must be signed. */
18690 NEON_ENCODE (INTEGER, inst);
18691 neon_two_same (0, 1, et.size / 2);
18692 }
18693
18694 static void
18695 do_neon_rshift_sat_narrow (void)
18696 {
18697 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18698 or unsigned. If operands are unsigned, results must also be unsigned. */
18699 struct neon_type_el et = neon_check_type (2, NS_DQI,
18700 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18701 int imm = inst.operands[2].imm;
18702 /* This gets the bounds check, size encoding and immediate bits calculation
18703 right. */
18704 et.size /= 2;
18705
18706 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18707 VQMOVN.I<size> <Dd>, <Qm>. */
18708 if (imm == 0)
18709 {
18710 inst.operands[2].present = 0;
18711 inst.instruction = N_MNEM_vqmovn;
18712 do_neon_qmovn ();
18713 return;
18714 }
18715
18716 constraint (imm < 1 || (unsigned)imm > et.size,
18717 _("immediate out of range"));
18718 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18719 }
18720
18721 static void
18722 do_neon_rshift_sat_narrow_u (void)
18723 {
18724 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18725 or unsigned. If operands are unsigned, results must also be unsigned. */
18726 struct neon_type_el et = neon_check_type (2, NS_DQI,
18727 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18728 int imm = inst.operands[2].imm;
18729 /* This gets the bounds check, size encoding and immediate bits calculation
18730 right. */
18731 et.size /= 2;
18732
18733 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18734 VQMOVUN.I<size> <Dd>, <Qm>. */
18735 if (imm == 0)
18736 {
18737 inst.operands[2].present = 0;
18738 inst.instruction = N_MNEM_vqmovun;
18739 do_neon_qmovun ();
18740 return;
18741 }
18742
18743 constraint (imm < 1 || (unsigned)imm > et.size,
18744 _("immediate out of range"));
18745 /* FIXME: The manual is kind of unclear about what value U should have in
18746 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18747 must be 1. */
18748 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18749 }
18750
18751 static void
18752 do_neon_movn (void)
18753 {
18754 struct neon_type_el et = neon_check_type (2, NS_DQ,
18755 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18756 NEON_ENCODE (INTEGER, inst);
18757 neon_two_same (0, 1, et.size / 2);
18758 }
18759
18760 static void
18761 do_neon_rshift_narrow (void)
18762 {
18763 struct neon_type_el et = neon_check_type (2, NS_DQI,
18764 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18765 int imm = inst.operands[2].imm;
18766 /* This gets the bounds check, size encoding and immediate bits calculation
18767 right. */
18768 et.size /= 2;
18769
18770 /* If immediate is zero then we are a pseudo-instruction for
18771 VMOVN.I<size> <Dd>, <Qm> */
18772 if (imm == 0)
18773 {
18774 inst.operands[2].present = 0;
18775 inst.instruction = N_MNEM_vmovn;
18776 do_neon_movn ();
18777 return;
18778 }
18779
18780 constraint (imm < 1 || (unsigned)imm > et.size,
18781 _("immediate out of range for narrowing operation"));
18782 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18783 }
18784
18785 static void
18786 do_neon_shll (void)
18787 {
18788 /* FIXME: Type checking when lengthening. */
18789 struct neon_type_el et = neon_check_type (2, NS_QDI,
18790 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18791 unsigned imm = inst.operands[2].imm;
18792
18793 if (imm == et.size)
18794 {
18795 /* Maximum shift variant. */
18796 NEON_ENCODE (INTEGER, inst);
18797 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18798 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18799 inst.instruction |= LOW4 (inst.operands[1].reg);
18800 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18801 inst.instruction |= neon_logbits (et.size) << 18;
18802
18803 neon_dp_fixup (&inst);
18804 }
18805 else
18806 {
18807 /* A more-specific type check for non-max versions. */
18808 et = neon_check_type (2, NS_QDI,
18809 N_EQK | N_DBL, N_SU_32 | N_KEY);
18810 NEON_ENCODE (IMMED, inst);
18811 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18812 }
18813 }
18814
18815 /* Check the various types for the VCVT instruction, and return which version
18816 the current instruction is. */
18817
18818 #define CVT_FLAVOUR_VAR \
18819 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18820 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18821 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18822 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18823 /* Half-precision conversions. */ \
18824 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18825 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18826 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18827 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
18828 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18829 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
18830 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18831 Compared with single/double precision variants, only the co-processor \
18832 field is different, so the encoding flow is reused here. */ \
18833 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18834 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18835 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18836 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
18837 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
18838 /* VFP instructions. */ \
18839 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18840 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18841 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18842 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18843 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18844 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18845 /* VFP instructions with bitshift. */ \
18846 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18847 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18848 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18849 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18850 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18851 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18852 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18853 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18854
18855 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18856 neon_cvt_flavour_##C,
18857
18858 /* The different types of conversions we can do. */
18859 enum neon_cvt_flavour
18860 {
18861 CVT_FLAVOUR_VAR
18862 neon_cvt_flavour_invalid,
18863 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18864 };
18865
18866 #undef CVT_VAR
18867
18868 static enum neon_cvt_flavour
18869 get_neon_cvt_flavour (enum neon_shape rs)
18870 {
18871 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18872 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18873 if (et.type != NT_invtype) \
18874 { \
18875 inst.error = NULL; \
18876 return (neon_cvt_flavour_##C); \
18877 }
18878
18879 struct neon_type_el et;
18880 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
18881 || rs == NS_FF) ? N_VFP : 0;
18882 /* The instruction versions which take an immediate take one register
18883 argument, which is extended to the width of the full register. Thus the
18884 "source" and "destination" registers must have the same width. Hack that
18885 here by making the size equal to the key (wider, in this case) operand. */
18886 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
18887
18888 CVT_FLAVOUR_VAR;
18889
18890 return neon_cvt_flavour_invalid;
18891 #undef CVT_VAR
18892 }
18893
18894 enum neon_cvt_mode
18895 {
18896 neon_cvt_mode_a,
18897 neon_cvt_mode_n,
18898 neon_cvt_mode_p,
18899 neon_cvt_mode_m,
18900 neon_cvt_mode_z,
18901 neon_cvt_mode_x,
18902 neon_cvt_mode_r
18903 };
18904
18905 /* Neon-syntax VFP conversions. */
18906
18907 static void
18908 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
18909 {
18910 const char *opname = 0;
18911
18912 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18913 || rs == NS_FHI || rs == NS_HFI)
18914 {
18915 /* Conversions with immediate bitshift. */
18916 const char *enc[] =
18917 {
18918 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18919 CVT_FLAVOUR_VAR
18920 NULL
18921 #undef CVT_VAR
18922 };
18923
18924 if (flavour < (int) ARRAY_SIZE (enc))
18925 {
18926 opname = enc[flavour];
18927 constraint (inst.operands[0].reg != inst.operands[1].reg,
18928 _("operands 0 and 1 must be the same register"));
18929 inst.operands[1] = inst.operands[2];
18930 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18931 }
18932 }
18933 else
18934 {
18935 /* Conversions without bitshift. */
18936 const char *enc[] =
18937 {
18938 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18939 CVT_FLAVOUR_VAR
18940 NULL
18941 #undef CVT_VAR
18942 };
18943
18944 if (flavour < (int) ARRAY_SIZE (enc))
18945 opname = enc[flavour];
18946 }
18947
18948 if (opname)
18949 do_vfp_nsyn_opcode (opname);
18950
18951 /* ARMv8.2 fp16 VCVT instruction. */
18952 if (flavour == neon_cvt_flavour_s32_f16
18953 || flavour == neon_cvt_flavour_u32_f16
18954 || flavour == neon_cvt_flavour_f16_u32
18955 || flavour == neon_cvt_flavour_f16_s32)
18956 do_scalar_fp16_v82_encode ();
18957 }
18958
18959 static void
18960 do_vfp_nsyn_cvtz (void)
18961 {
18962 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
18963 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18964 const char *enc[] =
18965 {
18966 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18967 CVT_FLAVOUR_VAR
18968 NULL
18969 #undef CVT_VAR
18970 };
18971
18972 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
18973 do_vfp_nsyn_opcode (enc[flavour]);
18974 }
18975
18976 static void
18977 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
18978 enum neon_cvt_mode mode)
18979 {
18980 int sz, op;
18981 int rm;
18982
18983 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18984 D register operands. */
18985 if (flavour == neon_cvt_flavour_s32_f64
18986 || flavour == neon_cvt_flavour_u32_f64)
18987 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18988 _(BAD_FPU));
18989
18990 if (flavour == neon_cvt_flavour_s32_f16
18991 || flavour == neon_cvt_flavour_u32_f16)
18992 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18993 _(BAD_FP16));
18994
18995 set_pred_insn_type (OUTSIDE_PRED_INSN);
18996
18997 switch (flavour)
18998 {
18999 case neon_cvt_flavour_s32_f64:
19000 sz = 1;
19001 op = 1;
19002 break;
19003 case neon_cvt_flavour_s32_f32:
19004 sz = 0;
19005 op = 1;
19006 break;
19007 case neon_cvt_flavour_s32_f16:
19008 sz = 0;
19009 op = 1;
19010 break;
19011 case neon_cvt_flavour_u32_f64:
19012 sz = 1;
19013 op = 0;
19014 break;
19015 case neon_cvt_flavour_u32_f32:
19016 sz = 0;
19017 op = 0;
19018 break;
19019 case neon_cvt_flavour_u32_f16:
19020 sz = 0;
19021 op = 0;
19022 break;
19023 default:
19024 first_error (_("invalid instruction shape"));
19025 return;
19026 }
19027
19028 switch (mode)
19029 {
19030 case neon_cvt_mode_a: rm = 0; break;
19031 case neon_cvt_mode_n: rm = 1; break;
19032 case neon_cvt_mode_p: rm = 2; break;
19033 case neon_cvt_mode_m: rm = 3; break;
19034 default: first_error (_("invalid rounding mode")); return;
19035 }
19036
19037 NEON_ENCODE (FPV8, inst);
19038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19039 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19040 inst.instruction |= sz << 8;
19041
19042 /* ARMv8.2 fp16 VCVT instruction. */
19043 if (flavour == neon_cvt_flavour_s32_f16
19044 ||flavour == neon_cvt_flavour_u32_f16)
19045 do_scalar_fp16_v82_encode ();
19046 inst.instruction |= op << 7;
19047 inst.instruction |= rm << 16;
19048 inst.instruction |= 0xf0000000;
19049 inst.is_neon = TRUE;
19050 }
19051
19052 static void
19053 do_neon_cvt_1 (enum neon_cvt_mode mode)
19054 {
19055 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
19056 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19057 NS_FH, NS_HF, NS_FHI, NS_HFI,
19058 NS_NULL);
19059 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19060
19061 if (flavour == neon_cvt_flavour_invalid)
19062 return;
19063
19064 /* PR11109: Handle round-to-zero for VCVT conversions. */
19065 if (mode == neon_cvt_mode_z
19066 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
19067 && (flavour == neon_cvt_flavour_s16_f16
19068 || flavour == neon_cvt_flavour_u16_f16
19069 || flavour == neon_cvt_flavour_s32_f32
19070 || flavour == neon_cvt_flavour_u32_f32
19071 || flavour == neon_cvt_flavour_s32_f64
19072 || flavour == neon_cvt_flavour_u32_f64)
19073 && (rs == NS_FD || rs == NS_FF))
19074 {
19075 do_vfp_nsyn_cvtz ();
19076 return;
19077 }
19078
19079 /* ARMv8.2 fp16 VCVT conversions. */
19080 if (mode == neon_cvt_mode_z
19081 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19082 && (flavour == neon_cvt_flavour_s32_f16
19083 || flavour == neon_cvt_flavour_u32_f16)
19084 && (rs == NS_FH))
19085 {
19086 do_vfp_nsyn_cvtz ();
19087 do_scalar_fp16_v82_encode ();
19088 return;
19089 }
19090
19091 /* VFP rather than Neon conversions. */
19092 if (flavour >= neon_cvt_flavour_first_fp)
19093 {
19094 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19095 do_vfp_nsyn_cvt (rs, flavour);
19096 else
19097 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19098
19099 return;
19100 }
19101
19102 switch (rs)
19103 {
19104 case NS_QQI:
19105 if (mode == neon_cvt_mode_z
19106 && (flavour == neon_cvt_flavour_f16_s16
19107 || flavour == neon_cvt_flavour_f16_u16
19108 || flavour == neon_cvt_flavour_s16_f16
19109 || flavour == neon_cvt_flavour_u16_f16
19110 || flavour == neon_cvt_flavour_f32_u32
19111 || flavour == neon_cvt_flavour_f32_s32
19112 || flavour == neon_cvt_flavour_s32_f32
19113 || flavour == neon_cvt_flavour_u32_f32))
19114 {
19115 if (!check_simd_pred_availability (TRUE,
19116 NEON_CHECK_CC | NEON_CHECK_ARCH))
19117 return;
19118 }
19119 else if (mode == neon_cvt_mode_n)
19120 {
19121 /* We are dealing with vcvt with the 'ne' condition. */
19122 inst.cond = 0x1;
19123 inst.instruction = N_MNEM_vcvt;
19124 do_neon_cvt_1 (neon_cvt_mode_z);
19125 return;
19126 }
19127 /* fall through. */
19128 case NS_DDI:
19129 {
19130 unsigned immbits;
19131 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19132 0x0000100, 0x1000100, 0x0, 0x1000000};
19133
19134 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19135 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19136 return;
19137
19138 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19139 {
19140 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19141 _("immediate value out of range"));
19142 switch (flavour)
19143 {
19144 case neon_cvt_flavour_f16_s16:
19145 case neon_cvt_flavour_f16_u16:
19146 case neon_cvt_flavour_s16_f16:
19147 case neon_cvt_flavour_u16_f16:
19148 constraint (inst.operands[2].imm > 16,
19149 _("immediate value out of range"));
19150 break;
19151 case neon_cvt_flavour_f32_u32:
19152 case neon_cvt_flavour_f32_s32:
19153 case neon_cvt_flavour_s32_f32:
19154 case neon_cvt_flavour_u32_f32:
19155 constraint (inst.operands[2].imm > 32,
19156 _("immediate value out of range"));
19157 break;
19158 default:
19159 inst.error = BAD_FPU;
19160 return;
19161 }
19162 }
19163
19164 /* Fixed-point conversion with #0 immediate is encoded as an
19165 integer conversion. */
19166 if (inst.operands[2].present && inst.operands[2].imm == 0)
19167 goto int_encode;
19168 NEON_ENCODE (IMMED, inst);
19169 if (flavour != neon_cvt_flavour_invalid)
19170 inst.instruction |= enctab[flavour];
19171 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19172 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19173 inst.instruction |= LOW4 (inst.operands[1].reg);
19174 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19175 inst.instruction |= neon_quad (rs) << 6;
19176 inst.instruction |= 1 << 21;
19177 if (flavour < neon_cvt_flavour_s16_f16)
19178 {
19179 inst.instruction |= 1 << 21;
19180 immbits = 32 - inst.operands[2].imm;
19181 inst.instruction |= immbits << 16;
19182 }
19183 else
19184 {
19185 inst.instruction |= 3 << 20;
19186 immbits = 16 - inst.operands[2].imm;
19187 inst.instruction |= immbits << 16;
19188 inst.instruction &= ~(1 << 9);
19189 }
19190
19191 neon_dp_fixup (&inst);
19192 }
19193 break;
19194
19195 case NS_QQ:
19196 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19197 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19198 && (flavour == neon_cvt_flavour_s16_f16
19199 || flavour == neon_cvt_flavour_u16_f16
19200 || flavour == neon_cvt_flavour_s32_f32
19201 || flavour == neon_cvt_flavour_u32_f32))
19202 {
19203 if (!check_simd_pred_availability (TRUE,
19204 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19205 return;
19206 }
19207 else if (mode == neon_cvt_mode_z
19208 && (flavour == neon_cvt_flavour_f16_s16
19209 || flavour == neon_cvt_flavour_f16_u16
19210 || flavour == neon_cvt_flavour_s16_f16
19211 || flavour == neon_cvt_flavour_u16_f16
19212 || flavour == neon_cvt_flavour_f32_u32
19213 || flavour == neon_cvt_flavour_f32_s32
19214 || flavour == neon_cvt_flavour_s32_f32
19215 || flavour == neon_cvt_flavour_u32_f32))
19216 {
19217 if (!check_simd_pred_availability (TRUE,
19218 NEON_CHECK_CC | NEON_CHECK_ARCH))
19219 return;
19220 }
19221 /* fall through. */
19222 case NS_DD:
19223 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19224 {
19225
19226 NEON_ENCODE (FLOAT, inst);
19227 if (!check_simd_pred_availability (TRUE,
19228 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19229 return;
19230
19231 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19232 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19233 inst.instruction |= LOW4 (inst.operands[1].reg);
19234 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19235 inst.instruction |= neon_quad (rs) << 6;
19236 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19237 || flavour == neon_cvt_flavour_u32_f32) << 7;
19238 inst.instruction |= mode << 8;
19239 if (flavour == neon_cvt_flavour_u16_f16
19240 || flavour == neon_cvt_flavour_s16_f16)
19241 /* Mask off the original size bits and reencode them. */
19242 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19243
19244 if (thumb_mode)
19245 inst.instruction |= 0xfc000000;
19246 else
19247 inst.instruction |= 0xf0000000;
19248 }
19249 else
19250 {
19251 int_encode:
19252 {
19253 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19254 0x100, 0x180, 0x0, 0x080};
19255
19256 NEON_ENCODE (INTEGER, inst);
19257
19258 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19259 {
19260 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19261 return;
19262 }
19263
19264 if (flavour != neon_cvt_flavour_invalid)
19265 inst.instruction |= enctab[flavour];
19266
19267 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19268 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19269 inst.instruction |= LOW4 (inst.operands[1].reg);
19270 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19271 inst.instruction |= neon_quad (rs) << 6;
19272 if (flavour >= neon_cvt_flavour_s16_f16
19273 && flavour <= neon_cvt_flavour_f16_u16)
19274 /* Half precision. */
19275 inst.instruction |= 1 << 18;
19276 else
19277 inst.instruction |= 2 << 18;
19278
19279 neon_dp_fixup (&inst);
19280 }
19281 }
19282 break;
19283
19284 /* Half-precision conversions for Advanced SIMD -- neon. */
19285 case NS_QD:
19286 case NS_DQ:
19287 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19288 return;
19289
19290 if ((rs == NS_DQ)
19291 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19292 {
19293 as_bad (_("operand size must match register width"));
19294 break;
19295 }
19296
19297 if ((rs == NS_QD)
19298 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19299 {
19300 as_bad (_("operand size must match register width"));
19301 break;
19302 }
19303
19304 if (rs == NS_DQ)
19305 {
19306 if (flavour == neon_cvt_flavour_bf16_f32)
19307 {
19308 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19309 return;
19310 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19311 /* VCVT.bf16.f32. */
19312 inst.instruction = 0x11b60640;
19313 }
19314 else
19315 /* VCVT.f16.f32. */
19316 inst.instruction = 0x3b60600;
19317 }
19318 else
19319 /* VCVT.f32.f16. */
19320 inst.instruction = 0x3b60700;
19321
19322 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19323 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19324 inst.instruction |= LOW4 (inst.operands[1].reg);
19325 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19326 neon_dp_fixup (&inst);
19327 break;
19328
19329 default:
19330 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
19331 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19332 do_vfp_nsyn_cvt (rs, flavour);
19333 else
19334 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19335 }
19336 }
19337
19338 static void
19339 do_neon_cvtr (void)
19340 {
19341 do_neon_cvt_1 (neon_cvt_mode_x);
19342 }
19343
19344 static void
19345 do_neon_cvt (void)
19346 {
19347 do_neon_cvt_1 (neon_cvt_mode_z);
19348 }
19349
19350 static void
19351 do_neon_cvta (void)
19352 {
19353 do_neon_cvt_1 (neon_cvt_mode_a);
19354 }
19355
19356 static void
19357 do_neon_cvtn (void)
19358 {
19359 do_neon_cvt_1 (neon_cvt_mode_n);
19360 }
19361
19362 static void
19363 do_neon_cvtp (void)
19364 {
19365 do_neon_cvt_1 (neon_cvt_mode_p);
19366 }
19367
19368 static void
19369 do_neon_cvtm (void)
19370 {
19371 do_neon_cvt_1 (neon_cvt_mode_m);
19372 }
19373
19374 static void
19375 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
19376 {
19377 if (is_double)
19378 mark_feature_used (&fpu_vfp_ext_armv8);
19379
19380 encode_arm_vfp_reg (inst.operands[0].reg,
19381 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19382 encode_arm_vfp_reg (inst.operands[1].reg,
19383 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19384 inst.instruction |= to ? 0x10000 : 0;
19385 inst.instruction |= t ? 0x80 : 0;
19386 inst.instruction |= is_double ? 0x100 : 0;
19387 do_vfp_cond_or_thumb ();
19388 }
19389
19390 static void
19391 do_neon_cvttb_1 (bfd_boolean t)
19392 {
19393 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
19394 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
19395
19396 if (rs == NS_NULL)
19397 return;
19398 else if (rs == NS_QQ || rs == NS_QQI)
19399 {
19400 int single_to_half = 0;
19401 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
19402 return;
19403
19404 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19405
19406 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19407 && (flavour == neon_cvt_flavour_u16_f16
19408 || flavour == neon_cvt_flavour_s16_f16
19409 || flavour == neon_cvt_flavour_f16_s16
19410 || flavour == neon_cvt_flavour_f16_u16
19411 || flavour == neon_cvt_flavour_u32_f32
19412 || flavour == neon_cvt_flavour_s32_f32
19413 || flavour == neon_cvt_flavour_f32_s32
19414 || flavour == neon_cvt_flavour_f32_u32))
19415 {
19416 inst.cond = 0xf;
19417 inst.instruction = N_MNEM_vcvt;
19418 set_pred_insn_type (INSIDE_VPT_INSN);
19419 do_neon_cvt_1 (neon_cvt_mode_z);
19420 return;
19421 }
19422 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19423 single_to_half = 1;
19424 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19425 {
19426 first_error (BAD_FPU);
19427 return;
19428 }
19429
19430 inst.instruction = 0xee3f0e01;
19431 inst.instruction |= single_to_half << 28;
19432 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19433 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19434 inst.instruction |= t << 12;
19435 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19436 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19437 inst.is_neon = 1;
19438 }
19439 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19440 {
19441 inst.error = NULL;
19442 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19443 }
19444 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19445 {
19446 inst.error = NULL;
19447 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19448 }
19449 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19450 {
19451 /* The VCVTB and VCVTT instructions with D-register operands
19452 don't work for SP only targets. */
19453 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19454 _(BAD_FPU));
19455
19456 inst.error = NULL;
19457 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19458 }
19459 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19460 {
19461 /* The VCVTB and VCVTT instructions with D-register operands
19462 don't work for SP only targets. */
19463 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19464 _(BAD_FPU));
19465
19466 inst.error = NULL;
19467 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19468 }
19469 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19470 {
19471 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19472 inst.error = NULL;
19473 inst.instruction |= (1 << 8);
19474 inst.instruction &= ~(1 << 9);
19475 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19476 }
19477 else
19478 return;
19479 }
19480
19481 static void
19482 do_neon_cvtb (void)
19483 {
19484 do_neon_cvttb_1 (FALSE);
19485 }
19486
19487
19488 static void
19489 do_neon_cvtt (void)
19490 {
19491 do_neon_cvttb_1 (TRUE);
19492 }
19493
19494 static void
19495 neon_move_immediate (void)
19496 {
19497 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19498 struct neon_type_el et = neon_check_type (2, rs,
19499 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
19500 unsigned immlo, immhi = 0, immbits;
19501 int op, cmode, float_p;
19502
19503 constraint (et.type == NT_invtype,
19504 _("operand size must be specified for immediate VMOV"));
19505
19506 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19507 op = (inst.instruction & (1 << 5)) != 0;
19508
19509 immlo = inst.operands[1].imm;
19510 if (inst.operands[1].regisimm)
19511 immhi = inst.operands[1].reg;
19512
19513 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
19514 _("immediate has bits set outside the operand size"));
19515
19516 float_p = inst.operands[1].immisfloat;
19517
19518 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
19519 et.size, et.type)) == FAIL)
19520 {
19521 /* Invert relevant bits only. */
19522 neon_invert_size (&immlo, &immhi, et.size);
19523 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
19524 with one or the other; those cases are caught by
19525 neon_cmode_for_move_imm. */
19526 op = !op;
19527 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19528 &op, et.size, et.type)) == FAIL)
19529 {
19530 first_error (_("immediate out of range"));
19531 return;
19532 }
19533 }
19534
19535 inst.instruction &= ~(1 << 5);
19536 inst.instruction |= op << 5;
19537
19538 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19539 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19540 inst.instruction |= neon_quad (rs) << 6;
19541 inst.instruction |= cmode << 8;
19542
19543 neon_write_immbits (immbits);
19544 }
19545
19546 static void
19547 do_neon_mvn (void)
19548 {
19549 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
19550 return;
19551
19552 if (inst.operands[1].isreg)
19553 {
19554 enum neon_shape rs;
19555 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19556 rs = neon_select_shape (NS_QQ, NS_NULL);
19557 else
19558 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19559
19560 NEON_ENCODE (INTEGER, inst);
19561 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19562 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19563 inst.instruction |= LOW4 (inst.operands[1].reg);
19564 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19565 inst.instruction |= neon_quad (rs) << 6;
19566 }
19567 else
19568 {
19569 NEON_ENCODE (IMMED, inst);
19570 neon_move_immediate ();
19571 }
19572
19573 neon_dp_fixup (&inst);
19574
19575 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19576 {
19577 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19578 }
19579 }
19580
19581 /* Encode instructions of form:
19582
19583 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
19584 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
19585
19586 static void
19587 neon_mixed_length (struct neon_type_el et, unsigned size)
19588 {
19589 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19590 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19591 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19592 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19593 inst.instruction |= LOW4 (inst.operands[2].reg);
19594 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19595 inst.instruction |= (et.type == NT_unsigned) << 24;
19596 inst.instruction |= neon_logbits (size) << 20;
19597
19598 neon_dp_fixup (&inst);
19599 }
19600
19601 static void
19602 do_neon_dyadic_long (void)
19603 {
19604 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
19605 if (rs == NS_QDD)
19606 {
19607 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19608 return;
19609
19610 NEON_ENCODE (INTEGER, inst);
19611 /* FIXME: Type checking for lengthening op. */
19612 struct neon_type_el et = neon_check_type (3, NS_QDD,
19613 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19614 neon_mixed_length (et, et.size);
19615 }
19616 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19617 && (inst.cond == 0xf || inst.cond == 0x10))
19618 {
19619 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19620 in an IT block with le/lt conditions. */
19621
19622 if (inst.cond == 0xf)
19623 inst.cond = 0xb;
19624 else if (inst.cond == 0x10)
19625 inst.cond = 0xd;
19626
19627 inst.pred_insn_type = INSIDE_IT_INSN;
19628
19629 if (inst.instruction == N_MNEM_vaddl)
19630 {
19631 inst.instruction = N_MNEM_vadd;
19632 do_neon_addsub_if_i ();
19633 }
19634 else if (inst.instruction == N_MNEM_vsubl)
19635 {
19636 inst.instruction = N_MNEM_vsub;
19637 do_neon_addsub_if_i ();
19638 }
19639 else if (inst.instruction == N_MNEM_vabdl)
19640 {
19641 inst.instruction = N_MNEM_vabd;
19642 do_neon_dyadic_if_su ();
19643 }
19644 }
19645 else
19646 first_error (BAD_FPU);
19647 }
19648
19649 static void
19650 do_neon_abal (void)
19651 {
19652 struct neon_type_el et = neon_check_type (3, NS_QDD,
19653 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19654 neon_mixed_length (et, et.size);
19655 }
19656
19657 static void
19658 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19659 {
19660 if (inst.operands[2].isscalar)
19661 {
19662 struct neon_type_el et = neon_check_type (3, NS_QDS,
19663 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
19664 NEON_ENCODE (SCALAR, inst);
19665 neon_mul_mac (et, et.type == NT_unsigned);
19666 }
19667 else
19668 {
19669 struct neon_type_el et = neon_check_type (3, NS_QDD,
19670 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
19671 NEON_ENCODE (INTEGER, inst);
19672 neon_mixed_length (et, et.size);
19673 }
19674 }
19675
19676 static void
19677 do_neon_mac_maybe_scalar_long (void)
19678 {
19679 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19680 }
19681
19682 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19683 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19684
19685 static unsigned
19686 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19687 {
19688 unsigned regno = NEON_SCALAR_REG (scalar);
19689 unsigned elno = NEON_SCALAR_INDEX (scalar);
19690
19691 if (quad_p)
19692 {
19693 if (regno > 7 || elno > 3)
19694 goto bad_scalar;
19695
19696 return ((regno & 0x7)
19697 | ((elno & 0x1) << 3)
19698 | (((elno >> 1) & 0x1) << 5));
19699 }
19700 else
19701 {
19702 if (regno > 15 || elno > 1)
19703 goto bad_scalar;
19704
19705 return (((regno & 0x1) << 5)
19706 | ((regno >> 1) & 0x7)
19707 | ((elno & 0x1) << 3));
19708 }
19709
19710 bad_scalar:
19711 first_error (_("scalar out of range for multiply instruction"));
19712 return 0;
19713 }
19714
19715 static void
19716 do_neon_fmac_maybe_scalar_long (int subtype)
19717 {
19718 enum neon_shape rs;
19719 int high8;
19720 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19721 field (bits[21:20]) has different meaning. For scalar index variant, it's
19722 used to differentiate add and subtract, otherwise it's with fixed value
19723 0x2. */
19724 int size = -1;
19725
19726 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19727 be a scalar index register. */
19728 if (inst.operands[2].isscalar)
19729 {
19730 high8 = 0xfe000000;
19731 if (subtype)
19732 size = 16;
19733 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19734 }
19735 else
19736 {
19737 high8 = 0xfc000000;
19738 size = 32;
19739 if (subtype)
19740 inst.instruction |= (0x1 << 23);
19741 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19742 }
19743
19744
19745 if (inst.cond != COND_ALWAYS)
19746 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19747 "behaviour is UNPREDICTABLE"));
19748
19749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19750 _(BAD_FP16));
19751
19752 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19753 _(BAD_FPU));
19754
19755 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19756 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19757 so we simply pass -1 as size. */
19758 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19759 neon_three_same (quad_p, 0, size);
19760
19761 /* Undo neon_dp_fixup. Redo the high eight bits. */
19762 inst.instruction &= 0x00ffffff;
19763 inst.instruction |= high8;
19764
19765 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19766 whether the instruction is in Q form and whether Vm is a scalar indexed
19767 operand. */
19768 if (inst.operands[2].isscalar)
19769 {
19770 unsigned rm
19771 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19772 inst.instruction &= 0xffffffd0;
19773 inst.instruction |= rm;
19774
19775 if (!quad_p)
19776 {
19777 /* Redo Rn as well. */
19778 inst.instruction &= 0xfff0ff7f;
19779 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19780 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19781 }
19782 }
19783 else if (!quad_p)
19784 {
19785 /* Redo Rn and Rm. */
19786 inst.instruction &= 0xfff0ff50;
19787 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19788 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19789 inst.instruction |= HI4 (inst.operands[2].reg);
19790 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19791 }
19792 }
19793
19794 static void
19795 do_neon_vfmal (void)
19796 {
19797 return do_neon_fmac_maybe_scalar_long (0);
19798 }
19799
19800 static void
19801 do_neon_vfmsl (void)
19802 {
19803 return do_neon_fmac_maybe_scalar_long (1);
19804 }
19805
19806 static void
19807 do_neon_dyadic_wide (void)
19808 {
19809 struct neon_type_el et = neon_check_type (3, NS_QQD,
19810 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19811 neon_mixed_length (et, et.size);
19812 }
19813
19814 static void
19815 do_neon_dyadic_narrow (void)
19816 {
19817 struct neon_type_el et = neon_check_type (3, NS_QDD,
19818 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
19819 /* Operand sign is unimportant, and the U bit is part of the opcode,
19820 so force the operand type to integer. */
19821 et.type = NT_integer;
19822 neon_mixed_length (et, et.size / 2);
19823 }
19824
19825 static void
19826 do_neon_mul_sat_scalar_long (void)
19827 {
19828 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19829 }
19830
19831 static void
19832 do_neon_vmull (void)
19833 {
19834 if (inst.operands[2].isscalar)
19835 do_neon_mac_maybe_scalar_long ();
19836 else
19837 {
19838 struct neon_type_el et = neon_check_type (3, NS_QDD,
19839 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
19840
19841 if (et.type == NT_poly)
19842 NEON_ENCODE (POLY, inst);
19843 else
19844 NEON_ENCODE (INTEGER, inst);
19845
19846 /* For polynomial encoding the U bit must be zero, and the size must
19847 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19848 obviously, as 0b10). */
19849 if (et.size == 64)
19850 {
19851 /* Check we're on the correct architecture. */
19852 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19853 inst.error =
19854 _("Instruction form not available on this architecture.");
19855
19856 et.size = 32;
19857 }
19858
19859 neon_mixed_length (et, et.size);
19860 }
19861 }
19862
19863 static void
19864 do_neon_ext (void)
19865 {
19866 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
19867 struct neon_type_el et = neon_check_type (3, rs,
19868 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19869 unsigned imm = (inst.operands[3].imm * et.size) / 8;
19870
19871 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19872 _("shift out of range"));
19873 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19874 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19875 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19876 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19877 inst.instruction |= LOW4 (inst.operands[2].reg);
19878 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19879 inst.instruction |= neon_quad (rs) << 6;
19880 inst.instruction |= imm << 8;
19881
19882 neon_dp_fixup (&inst);
19883 }
19884
19885 static void
19886 do_neon_rev (void)
19887 {
19888 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
19889 return;
19890
19891 enum neon_shape rs;
19892 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19893 rs = neon_select_shape (NS_QQ, NS_NULL);
19894 else
19895 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19896
19897 struct neon_type_el et = neon_check_type (2, rs,
19898 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19899
19900 unsigned op = (inst.instruction >> 7) & 3;
19901 /* N (width of reversed regions) is encoded as part of the bitmask. We
19902 extract it here to check the elements to be reversed are smaller.
19903 Otherwise we'd get a reserved instruction. */
19904 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
19905
19906 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19907 && inst.operands[0].reg == inst.operands[1].reg)
19908 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19909 " operands makes instruction UNPREDICTABLE"));
19910
19911 gas_assert (elsize != 0);
19912 constraint (et.size >= elsize,
19913 _("elements must be smaller than reversal region"));
19914 neon_two_same (neon_quad (rs), 1, et.size);
19915 }
19916
19917 static void
19918 do_neon_dup (void)
19919 {
19920 if (inst.operands[1].isscalar)
19921 {
19922 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19923 BAD_FPU);
19924 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
19925 struct neon_type_el et = neon_check_type (2, rs,
19926 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19927 unsigned sizebits = et.size >> 3;
19928 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
19929 int logsize = neon_logbits (et.size);
19930 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
19931
19932 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
19933 return;
19934
19935 NEON_ENCODE (SCALAR, inst);
19936 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19937 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19938 inst.instruction |= LOW4 (dm);
19939 inst.instruction |= HI1 (dm) << 5;
19940 inst.instruction |= neon_quad (rs) << 6;
19941 inst.instruction |= x << 17;
19942 inst.instruction |= sizebits << 16;
19943
19944 neon_dp_fixup (&inst);
19945 }
19946 else
19947 {
19948 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19949 struct neon_type_el et = neon_check_type (2, rs,
19950 N_8 | N_16 | N_32 | N_KEY, N_EQK);
19951 if (rs == NS_QR)
19952 {
19953 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
19954 return;
19955 }
19956 else
19957 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19958 BAD_FPU);
19959
19960 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19961 {
19962 if (inst.operands[1].reg == REG_SP)
19963 as_tsktsk (MVE_BAD_SP);
19964 else if (inst.operands[1].reg == REG_PC)
19965 as_tsktsk (MVE_BAD_PC);
19966 }
19967
19968 /* Duplicate ARM register to lanes of vector. */
19969 NEON_ENCODE (ARMREG, inst);
19970 switch (et.size)
19971 {
19972 case 8: inst.instruction |= 0x400000; break;
19973 case 16: inst.instruction |= 0x000020; break;
19974 case 32: inst.instruction |= 0x000000; break;
19975 default: break;
19976 }
19977 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19978 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19979 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
19980 inst.instruction |= neon_quad (rs) << 21;
19981 /* The encoding for this instruction is identical for the ARM and Thumb
19982 variants, except for the condition field. */
19983 do_vfp_cond_or_thumb ();
19984 }
19985 }
19986
19987 static void
19988 do_mve_mov (int toQ)
19989 {
19990 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19991 return;
19992 if (inst.cond > COND_ALWAYS)
19993 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19994
19995 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19996 if (toQ)
19997 {
19998 Q0 = 0;
19999 Q1 = 1;
20000 Rt = 2;
20001 Rt2 = 3;
20002 }
20003
20004 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
20005 _("Index one must be [2,3] and index two must be two less than"
20006 " index one."));
20007 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
20008 _("General purpose registers may not be the same"));
20009 constraint (inst.operands[Rt].reg == REG_SP
20010 || inst.operands[Rt2].reg == REG_SP,
20011 BAD_SP);
20012 constraint (inst.operands[Rt].reg == REG_PC
20013 || inst.operands[Rt2].reg == REG_PC,
20014 BAD_PC);
20015
20016 inst.instruction = 0xec000f00;
20017 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
20018 inst.instruction |= !!toQ << 20;
20019 inst.instruction |= inst.operands[Rt2].reg << 16;
20020 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
20021 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
20022 inst.instruction |= inst.operands[Rt].reg;
20023 }
20024
20025 static void
20026 do_mve_movn (void)
20027 {
20028 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20029 return;
20030
20031 if (inst.cond > COND_ALWAYS)
20032 inst.pred_insn_type = INSIDE_VPT_INSN;
20033 else
20034 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20035
20036 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20037 | N_KEY);
20038
20039 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20040 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20041 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20042 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20043 inst.instruction |= LOW4 (inst.operands[1].reg);
20044 inst.is_neon = 1;
20045
20046 }
20047
20048 /* VMOV has particularly many variations. It can be one of:
20049 0. VMOV<c><q> <Qd>, <Qm>
20050 1. VMOV<c><q> <Dd>, <Dm>
20051 (Register operations, which are VORR with Rm = Rn.)
20052 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20053 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20054 (Immediate loads.)
20055 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20056 (ARM register to scalar.)
20057 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20058 (Two ARM registers to vector.)
20059 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20060 (Scalar to ARM register.)
20061 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20062 (Vector to two ARM registers.)
20063 8. VMOV.F32 <Sd>, <Sm>
20064 9. VMOV.F64 <Dd>, <Dm>
20065 (VFP register moves.)
20066 10. VMOV.F32 <Sd>, #imm
20067 11. VMOV.F64 <Dd>, #imm
20068 (VFP float immediate load.)
20069 12. VMOV <Rd>, <Sm>
20070 (VFP single to ARM reg.)
20071 13. VMOV <Sd>, <Rm>
20072 (ARM reg to VFP single.)
20073 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20074 (Two ARM regs to two VFP singles.)
20075 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20076 (Two VFP singles to two ARM regs.)
20077 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20078 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20079 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20080 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
20081
20082 These cases can be disambiguated using neon_select_shape, except cases 1/9
20083 and 3/11 which depend on the operand type too.
20084
20085 All the encoded bits are hardcoded by this function.
20086
20087 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20088 Cases 5, 7 may be used with VFPv2 and above.
20089
20090 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
20091 can specify a type where it doesn't make sense to, and is ignored). */
20092
20093 static void
20094 do_neon_mov (void)
20095 {
20096 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20097 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20098 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20099 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20100 NS_NULL);
20101 struct neon_type_el et;
20102 const char *ldconst = 0;
20103
20104 switch (rs)
20105 {
20106 case NS_DD: /* case 1/9. */
20107 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20108 /* It is not an error here if no type is given. */
20109 inst.error = NULL;
20110
20111 /* In MVE we interpret the following instructions as same, so ignoring
20112 the following type (float) and size (64) checks.
20113 a: VMOV<c><q> <Dd>, <Dm>
20114 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20115 if ((et.type == NT_float && et.size == 64)
20116 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
20117 {
20118 do_vfp_nsyn_opcode ("fcpyd");
20119 break;
20120 }
20121 /* fall through. */
20122
20123 case NS_QQ: /* case 0/1. */
20124 {
20125 if (!check_simd_pred_availability (FALSE,
20126 NEON_CHECK_CC | NEON_CHECK_ARCH))
20127 return;
20128 /* The architecture manual I have doesn't explicitly state which
20129 value the U bit should have for register->register moves, but
20130 the equivalent VORR instruction has U = 0, so do that. */
20131 inst.instruction = 0x0200110;
20132 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20133 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20134 inst.instruction |= LOW4 (inst.operands[1].reg);
20135 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20136 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20137 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20138 inst.instruction |= neon_quad (rs) << 6;
20139
20140 neon_dp_fixup (&inst);
20141 }
20142 break;
20143
20144 case NS_DI: /* case 3/11. */
20145 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20146 inst.error = NULL;
20147 if (et.type == NT_float && et.size == 64)
20148 {
20149 /* case 11 (fconstd). */
20150 ldconst = "fconstd";
20151 goto encode_fconstd;
20152 }
20153 /* fall through. */
20154
20155 case NS_QI: /* case 2/3. */
20156 if (!check_simd_pred_availability (FALSE,
20157 NEON_CHECK_CC | NEON_CHECK_ARCH))
20158 return;
20159 inst.instruction = 0x0800010;
20160 neon_move_immediate ();
20161 neon_dp_fixup (&inst);
20162 break;
20163
20164 case NS_SR: /* case 4. */
20165 {
20166 unsigned bcdebits = 0;
20167 int logsize;
20168 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20169 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
20170
20171 /* .<size> is optional here, defaulting to .32. */
20172 if (inst.vectype.elems == 0
20173 && inst.operands[0].vectype.type == NT_invtype
20174 && inst.operands[1].vectype.type == NT_invtype)
20175 {
20176 inst.vectype.el[0].type = NT_untyped;
20177 inst.vectype.el[0].size = 32;
20178 inst.vectype.elems = 1;
20179 }
20180
20181 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20182 logsize = neon_logbits (et.size);
20183
20184 if (et.size != 32)
20185 {
20186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20187 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20188 return;
20189 }
20190 else
20191 {
20192 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20193 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20194 _(BAD_FPU));
20195 }
20196
20197 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20198 {
20199 if (inst.operands[1].reg == REG_SP)
20200 as_tsktsk (MVE_BAD_SP);
20201 else if (inst.operands[1].reg == REG_PC)
20202 as_tsktsk (MVE_BAD_PC);
20203 }
20204 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20205
20206 constraint (et.type == NT_invtype, _("bad type for scalar"));
20207 constraint (x >= size / et.size, _("scalar index out of range"));
20208
20209
20210 switch (et.size)
20211 {
20212 case 8: bcdebits = 0x8; break;
20213 case 16: bcdebits = 0x1; break;
20214 case 32: bcdebits = 0x0; break;
20215 default: ;
20216 }
20217
20218 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20219
20220 inst.instruction = 0xe000b10;
20221 do_vfp_cond_or_thumb ();
20222 inst.instruction |= LOW4 (dn) << 16;
20223 inst.instruction |= HI1 (dn) << 7;
20224 inst.instruction |= inst.operands[1].reg << 12;
20225 inst.instruction |= (bcdebits & 3) << 5;
20226 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20227 inst.instruction |= (x >> (3-logsize)) << 16;
20228 }
20229 break;
20230
20231 case NS_DRR: /* case 5 (fmdrr). */
20232 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20233 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20234 _(BAD_FPU));
20235
20236 inst.instruction = 0xc400b10;
20237 do_vfp_cond_or_thumb ();
20238 inst.instruction |= LOW4 (inst.operands[0].reg);
20239 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20240 inst.instruction |= inst.operands[1].reg << 12;
20241 inst.instruction |= inst.operands[2].reg << 16;
20242 break;
20243
20244 case NS_RS: /* case 6. */
20245 {
20246 unsigned logsize;
20247 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20248 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20249 unsigned abcdebits = 0;
20250
20251 /* .<dt> is optional here, defaulting to .32. */
20252 if (inst.vectype.elems == 0
20253 && inst.operands[0].vectype.type == NT_invtype
20254 && inst.operands[1].vectype.type == NT_invtype)
20255 {
20256 inst.vectype.el[0].type = NT_untyped;
20257 inst.vectype.el[0].size = 32;
20258 inst.vectype.elems = 1;
20259 }
20260
20261 et = neon_check_type (2, NS_NULL,
20262 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
20263 logsize = neon_logbits (et.size);
20264
20265 if (et.size != 32)
20266 {
20267 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20268 && vfp_or_neon_is_neon (NEON_CHECK_CC
20269 | NEON_CHECK_ARCH) == FAIL)
20270 return;
20271 }
20272 else
20273 {
20274 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20275 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20276 _(BAD_FPU));
20277 }
20278
20279 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20280 {
20281 if (inst.operands[0].reg == REG_SP)
20282 as_tsktsk (MVE_BAD_SP);
20283 else if (inst.operands[0].reg == REG_PC)
20284 as_tsktsk (MVE_BAD_PC);
20285 }
20286
20287 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20288
20289 constraint (et.type == NT_invtype, _("bad type for scalar"));
20290 constraint (x >= size / et.size, _("scalar index out of range"));
20291
20292 switch (et.size)
20293 {
20294 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20295 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20296 case 32: abcdebits = 0x00; break;
20297 default: ;
20298 }
20299
20300 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20301 inst.instruction = 0xe100b10;
20302 do_vfp_cond_or_thumb ();
20303 inst.instruction |= LOW4 (dn) << 16;
20304 inst.instruction |= HI1 (dn) << 7;
20305 inst.instruction |= inst.operands[0].reg << 12;
20306 inst.instruction |= (abcdebits & 3) << 5;
20307 inst.instruction |= (abcdebits >> 2) << 21;
20308 inst.instruction |= (x >> (3-logsize)) << 16;
20309 }
20310 break;
20311
20312 case NS_RRD: /* case 7 (fmrrd). */
20313 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20314 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20315 _(BAD_FPU));
20316
20317 inst.instruction = 0xc500b10;
20318 do_vfp_cond_or_thumb ();
20319 inst.instruction |= inst.operands[0].reg << 12;
20320 inst.instruction |= inst.operands[1].reg << 16;
20321 inst.instruction |= LOW4 (inst.operands[2].reg);
20322 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20323 break;
20324
20325 case NS_FF: /* case 8 (fcpys). */
20326 do_vfp_nsyn_opcode ("fcpys");
20327 break;
20328
20329 case NS_HI:
20330 case NS_FI: /* case 10 (fconsts). */
20331 ldconst = "fconsts";
20332 encode_fconstd:
20333 if (!inst.operands[1].immisfloat)
20334 {
20335 unsigned new_imm;
20336 /* Immediate has to fit in 8 bits so float is enough. */
20337 float imm = (float) inst.operands[1].imm;
20338 memcpy (&new_imm, &imm, sizeof (float));
20339 /* But the assembly may have been written to provide an integer
20340 bit pattern that equates to a float, so check that the
20341 conversion has worked. */
20342 if (is_quarter_float (new_imm))
20343 {
20344 if (is_quarter_float (inst.operands[1].imm))
20345 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20346
20347 inst.operands[1].imm = new_imm;
20348 inst.operands[1].immisfloat = 1;
20349 }
20350 }
20351
20352 if (is_quarter_float (inst.operands[1].imm))
20353 {
20354 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20355 do_vfp_nsyn_opcode (ldconst);
20356
20357 /* ARMv8.2 fp16 vmov.f16 instruction. */
20358 if (rs == NS_HI)
20359 do_scalar_fp16_v82_encode ();
20360 }
20361 else
20362 first_error (_("immediate out of range"));
20363 break;
20364
20365 case NS_RH:
20366 case NS_RF: /* case 12 (fmrs). */
20367 do_vfp_nsyn_opcode ("fmrs");
20368 /* ARMv8.2 fp16 vmov.f16 instruction. */
20369 if (rs == NS_RH)
20370 do_scalar_fp16_v82_encode ();
20371 break;
20372
20373 case NS_HR:
20374 case NS_FR: /* case 13 (fmsr). */
20375 do_vfp_nsyn_opcode ("fmsr");
20376 /* ARMv8.2 fp16 vmov.f16 instruction. */
20377 if (rs == NS_HR)
20378 do_scalar_fp16_v82_encode ();
20379 break;
20380
20381 case NS_RRSS:
20382 do_mve_mov (0);
20383 break;
20384 case NS_SSRR:
20385 do_mve_mov (1);
20386 break;
20387
20388 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20389 (one of which is a list), but we have parsed four. Do some fiddling to
20390 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20391 expect. */
20392 case NS_RRFF: /* case 14 (fmrrs). */
20393 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20394 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20395 _(BAD_FPU));
20396 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
20397 _("VFP registers must be adjacent"));
20398 inst.operands[2].imm = 2;
20399 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20400 do_vfp_nsyn_opcode ("fmrrs");
20401 break;
20402
20403 case NS_FFRR: /* case 15 (fmsrr). */
20404 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20405 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20406 _(BAD_FPU));
20407 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
20408 _("VFP registers must be adjacent"));
20409 inst.operands[1] = inst.operands[2];
20410 inst.operands[2] = inst.operands[3];
20411 inst.operands[0].imm = 2;
20412 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20413 do_vfp_nsyn_opcode ("fmsrr");
20414 break;
20415
20416 case NS_NULL:
20417 /* neon_select_shape has determined that the instruction
20418 shape is wrong and has already set the error message. */
20419 break;
20420
20421 default:
20422 abort ();
20423 }
20424 }
20425
20426 static void
20427 do_mve_movl (void)
20428 {
20429 if (!(inst.operands[0].present && inst.operands[0].isquad
20430 && inst.operands[1].present && inst.operands[1].isquad
20431 && !inst.operands[2].present))
20432 {
20433 inst.instruction = 0;
20434 inst.cond = 0xb;
20435 if (thumb_mode)
20436 set_pred_insn_type (INSIDE_IT_INSN);
20437 do_neon_mov ();
20438 return;
20439 }
20440
20441 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20442 return;
20443
20444 if (inst.cond != COND_ALWAYS)
20445 inst.pred_insn_type = INSIDE_VPT_INSN;
20446
20447 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20448 | N_S16 | N_U16 | N_KEY);
20449
20450 inst.instruction |= (et.type == NT_unsigned) << 28;
20451 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20452 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20453 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20454 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20455 inst.instruction |= LOW4 (inst.operands[1].reg);
20456 inst.is_neon = 1;
20457 }
20458
20459 static void
20460 do_neon_rshift_round_imm (void)
20461 {
20462 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20463 return;
20464
20465 enum neon_shape rs;
20466 struct neon_type_el et;
20467
20468 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20469 {
20470 rs = neon_select_shape (NS_QQI, NS_NULL);
20471 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20472 }
20473 else
20474 {
20475 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20476 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20477 }
20478 int imm = inst.operands[2].imm;
20479
20480 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20481 if (imm == 0)
20482 {
20483 inst.operands[2].present = 0;
20484 do_neon_mov ();
20485 return;
20486 }
20487
20488 constraint (imm < 1 || (unsigned)imm > et.size,
20489 _("immediate out of range for shift"));
20490 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
20491 et.size - imm);
20492 }
20493
20494 static void
20495 do_neon_movhf (void)
20496 {
20497 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20498 constraint (rs != NS_HH, _("invalid suffix"));
20499
20500 if (inst.cond != COND_ALWAYS)
20501 {
20502 if (thumb_mode)
20503 {
20504 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20505 " the behaviour is UNPREDICTABLE"));
20506 }
20507 else
20508 {
20509 inst.error = BAD_COND;
20510 return;
20511 }
20512 }
20513
20514 do_vfp_sp_monadic ();
20515
20516 inst.is_neon = 1;
20517 inst.instruction |= 0xf0000000;
20518 }
20519
20520 static void
20521 do_neon_movl (void)
20522 {
20523 struct neon_type_el et = neon_check_type (2, NS_QD,
20524 N_EQK | N_DBL, N_SU_32 | N_KEY);
20525 unsigned sizebits = et.size >> 3;
20526 inst.instruction |= sizebits << 19;
20527 neon_two_same (0, et.type == NT_unsigned, -1);
20528 }
20529
20530 static void
20531 do_neon_trn (void)
20532 {
20533 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20534 struct neon_type_el et = neon_check_type (2, rs,
20535 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20536 NEON_ENCODE (INTEGER, inst);
20537 neon_two_same (neon_quad (rs), 1, et.size);
20538 }
20539
20540 static void
20541 do_neon_zip_uzp (void)
20542 {
20543 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20544 struct neon_type_el et = neon_check_type (2, rs,
20545 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20546 if (rs == NS_DD && et.size == 32)
20547 {
20548 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20549 inst.instruction = N_MNEM_vtrn;
20550 do_neon_trn ();
20551 return;
20552 }
20553 neon_two_same (neon_quad (rs), 1, et.size);
20554 }
20555
20556 static void
20557 do_neon_sat_abs_neg (void)
20558 {
20559 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
20560 return;
20561
20562 enum neon_shape rs;
20563 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20564 rs = neon_select_shape (NS_QQ, NS_NULL);
20565 else
20566 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20567 struct neon_type_el et = neon_check_type (2, rs,
20568 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20569 neon_two_same (neon_quad (rs), 1, et.size);
20570 }
20571
20572 static void
20573 do_neon_pair_long (void)
20574 {
20575 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20576 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20577 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20578 inst.instruction |= (et.type == NT_unsigned) << 7;
20579 neon_two_same (neon_quad (rs), 1, et.size);
20580 }
20581
20582 static void
20583 do_neon_recip_est (void)
20584 {
20585 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20586 struct neon_type_el et = neon_check_type (2, rs,
20587 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
20588 inst.instruction |= (et.type == NT_float) << 8;
20589 neon_two_same (neon_quad (rs), 1, et.size);
20590 }
20591
20592 static void
20593 do_neon_cls (void)
20594 {
20595 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20596 return;
20597
20598 enum neon_shape rs;
20599 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20600 rs = neon_select_shape (NS_QQ, NS_NULL);
20601 else
20602 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20603
20604 struct neon_type_el et = neon_check_type (2, rs,
20605 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20606 neon_two_same (neon_quad (rs), 1, et.size);
20607 }
20608
20609 static void
20610 do_neon_clz (void)
20611 {
20612 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20613 return;
20614
20615 enum neon_shape rs;
20616 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20617 rs = neon_select_shape (NS_QQ, NS_NULL);
20618 else
20619 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20620
20621 struct neon_type_el et = neon_check_type (2, rs,
20622 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
20623 neon_two_same (neon_quad (rs), 1, et.size);
20624 }
20625
20626 static void
20627 do_neon_cnt (void)
20628 {
20629 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20630 struct neon_type_el et = neon_check_type (2, rs,
20631 N_EQK | N_INT, N_8 | N_KEY);
20632 neon_two_same (neon_quad (rs), 1, et.size);
20633 }
20634
20635 static void
20636 do_neon_swp (void)
20637 {
20638 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20639 neon_two_same (neon_quad (rs), 1, -1);
20640 }
20641
20642 static void
20643 do_neon_tbl_tbx (void)
20644 {
20645 unsigned listlenbits;
20646 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
20647
20648 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20649 {
20650 first_error (_("bad list length for table lookup"));
20651 return;
20652 }
20653
20654 listlenbits = inst.operands[1].imm - 1;
20655 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20656 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20657 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20658 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20659 inst.instruction |= LOW4 (inst.operands[2].reg);
20660 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20661 inst.instruction |= listlenbits << 8;
20662
20663 neon_dp_fixup (&inst);
20664 }
20665
20666 static void
20667 do_neon_ldm_stm (void)
20668 {
20669 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20670 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20671 _(BAD_FPU));
20672 /* P, U and L bits are part of bitmask. */
20673 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20674 unsigned offsetbits = inst.operands[1].imm * 2;
20675
20676 if (inst.operands[1].issingle)
20677 {
20678 do_vfp_nsyn_ldm_stm (is_dbmode);
20679 return;
20680 }
20681
20682 constraint (is_dbmode && !inst.operands[0].writeback,
20683 _("writeback (!) must be used for VLDMDB and VSTMDB"));
20684
20685 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20686 _("register list must contain at least 1 and at most 16 "
20687 "registers"));
20688
20689 inst.instruction |= inst.operands[0].reg << 16;
20690 inst.instruction |= inst.operands[0].writeback << 21;
20691 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20692 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20693
20694 inst.instruction |= offsetbits;
20695
20696 do_vfp_cond_or_thumb ();
20697 }
20698
20699 static void
20700 do_vfp_nsyn_pop (void)
20701 {
20702 nsyn_insert_sp ();
20703 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20704 return do_vfp_nsyn_opcode ("vldm");
20705 }
20706
20707 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20708 _(BAD_FPU));
20709
20710 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20711 _("register list must contain at least 1 and at most 16 "
20712 "registers"));
20713
20714 if (inst.operands[1].issingle)
20715 do_vfp_nsyn_opcode ("fldmias");
20716 else
20717 do_vfp_nsyn_opcode ("fldmiad");
20718 }
20719
20720 static void
20721 do_vfp_nsyn_push (void)
20722 {
20723 nsyn_insert_sp ();
20724 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20725 return do_vfp_nsyn_opcode ("vstmdb");
20726 }
20727
20728 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20729 _(BAD_FPU));
20730
20731 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20732 _("register list must contain at least 1 and at most 16 "
20733 "registers"));
20734
20735 if (inst.operands[1].issingle)
20736 do_vfp_nsyn_opcode ("fstmdbs");
20737 else
20738 do_vfp_nsyn_opcode ("fstmdbd");
20739 }
20740
20741
20742 static void
20743 do_neon_ldr_str (void)
20744 {
20745 int is_ldr = (inst.instruction & (1 << 20)) != 0;
20746
20747 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20748 And is UNPREDICTABLE in thumb mode. */
20749 if (!is_ldr
20750 && inst.operands[1].reg == REG_PC
20751 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
20752 {
20753 if (thumb_mode)
20754 inst.error = _("Use of PC here is UNPREDICTABLE");
20755 else if (warn_on_deprecated)
20756 as_tsktsk (_("Use of PC here is deprecated"));
20757 }
20758
20759 if (inst.operands[0].issingle)
20760 {
20761 if (is_ldr)
20762 do_vfp_nsyn_opcode ("flds");
20763 else
20764 do_vfp_nsyn_opcode ("fsts");
20765
20766 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20767 if (inst.vectype.el[0].size == 16)
20768 do_scalar_fp16_v82_encode ();
20769 }
20770 else
20771 {
20772 if (is_ldr)
20773 do_vfp_nsyn_opcode ("fldd");
20774 else
20775 do_vfp_nsyn_opcode ("fstd");
20776 }
20777 }
20778
20779 static void
20780 do_t_vldr_vstr_sysreg (void)
20781 {
20782 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20783 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20784
20785 /* Use of PC is UNPREDICTABLE. */
20786 if (inst.operands[1].reg == REG_PC)
20787 inst.error = _("Use of PC here is UNPREDICTABLE");
20788
20789 if (inst.operands[1].immisreg)
20790 inst.error = _("instruction does not accept register index");
20791
20792 if (!inst.operands[1].isreg)
20793 inst.error = _("instruction does not accept PC-relative addressing");
20794
20795 if (abs (inst.operands[1].imm) >= (1 << 7))
20796 inst.error = _("immediate value out of range");
20797
20798 inst.instruction = 0xec000f80;
20799 if (is_vldr)
20800 inst.instruction |= 1 << sysreg_vldr_bitno;
20801 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20802 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20803 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20804 }
20805
20806 static void
20807 do_vldr_vstr (void)
20808 {
20809 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20810
20811 /* VLDR/VSTR (System Register). */
20812 if (sysreg_op)
20813 {
20814 if (!mark_feature_used (&arm_ext_v8_1m_main))
20815 as_bad (_("Instruction not permitted on this architecture"));
20816
20817 do_t_vldr_vstr_sysreg ();
20818 }
20819 /* VLDR/VSTR. */
20820 else
20821 {
20822 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20823 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20824 as_bad (_("Instruction not permitted on this architecture"));
20825 do_neon_ldr_str ();
20826 }
20827 }
20828
20829 /* "interleave" version also handles non-interleaving register VLD1/VST1
20830 instructions. */
20831
20832 static void
20833 do_neon_ld_st_interleave (void)
20834 {
20835 struct neon_type_el et = neon_check_type (1, NS_NULL,
20836 N_8 | N_16 | N_32 | N_64);
20837 unsigned alignbits = 0;
20838 unsigned idx;
20839 /* The bits in this table go:
20840 0: register stride of one (0) or two (1)
20841 1,2: register list length, minus one (1, 2, 3, 4).
20842 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20843 We use -1 for invalid entries. */
20844 const int typetable[] =
20845 {
20846 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20847 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20848 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20849 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20850 };
20851 int typebits;
20852
20853 if (et.type == NT_invtype)
20854 return;
20855
20856 if (inst.operands[1].immisalign)
20857 switch (inst.operands[1].imm >> 8)
20858 {
20859 case 64: alignbits = 1; break;
20860 case 128:
20861 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
20862 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20863 goto bad_alignment;
20864 alignbits = 2;
20865 break;
20866 case 256:
20867 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20868 goto bad_alignment;
20869 alignbits = 3;
20870 break;
20871 default:
20872 bad_alignment:
20873 first_error (_("bad alignment"));
20874 return;
20875 }
20876
20877 inst.instruction |= alignbits << 4;
20878 inst.instruction |= neon_logbits (et.size) << 6;
20879
20880 /* Bits [4:6] of the immediate in a list specifier encode register stride
20881 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20882 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20883 up the right value for "type" in a table based on this value and the given
20884 list style, then stick it back. */
20885 idx = ((inst.operands[0].imm >> 4) & 7)
20886 | (((inst.instruction >> 8) & 3) << 3);
20887
20888 typebits = typetable[idx];
20889
20890 constraint (typebits == -1, _("bad list type for instruction"));
20891 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
20892 BAD_EL_TYPE);
20893
20894 inst.instruction &= ~0xf00;
20895 inst.instruction |= typebits << 8;
20896 }
20897
20898 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20899 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20900 otherwise. The variable arguments are a list of pairs of legal (size, align)
20901 values, terminated with -1. */
20902
20903 static int
20904 neon_alignment_bit (int size, int align, int *do_alignment, ...)
20905 {
20906 va_list ap;
20907 int result = FAIL, thissize, thisalign;
20908
20909 if (!inst.operands[1].immisalign)
20910 {
20911 *do_alignment = 0;
20912 return SUCCESS;
20913 }
20914
20915 va_start (ap, do_alignment);
20916
20917 do
20918 {
20919 thissize = va_arg (ap, int);
20920 if (thissize == -1)
20921 break;
20922 thisalign = va_arg (ap, int);
20923
20924 if (size == thissize && align == thisalign)
20925 result = SUCCESS;
20926 }
20927 while (result != SUCCESS);
20928
20929 va_end (ap);
20930
20931 if (result == SUCCESS)
20932 *do_alignment = 1;
20933 else
20934 first_error (_("unsupported alignment for instruction"));
20935
20936 return result;
20937 }
20938
20939 static void
20940 do_neon_ld_st_lane (void)
20941 {
20942 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20943 int align_good, do_alignment = 0;
20944 int logsize = neon_logbits (et.size);
20945 int align = inst.operands[1].imm >> 8;
20946 int n = (inst.instruction >> 8) & 3;
20947 int max_el = 64 / et.size;
20948
20949 if (et.type == NT_invtype)
20950 return;
20951
20952 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
20953 _("bad list length"));
20954 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
20955 _("scalar index out of range"));
20956 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
20957 && et.size == 8,
20958 _("stride of 2 unavailable when element size is 8"));
20959
20960 switch (n)
20961 {
20962 case 0: /* VLD1 / VST1. */
20963 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
20964 32, 32, -1);
20965 if (align_good == FAIL)
20966 return;
20967 if (do_alignment)
20968 {
20969 unsigned alignbits = 0;
20970 switch (et.size)
20971 {
20972 case 16: alignbits = 0x1; break;
20973 case 32: alignbits = 0x3; break;
20974 default: ;
20975 }
20976 inst.instruction |= alignbits << 4;
20977 }
20978 break;
20979
20980 case 1: /* VLD2 / VST2. */
20981 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20982 16, 32, 32, 64, -1);
20983 if (align_good == FAIL)
20984 return;
20985 if (do_alignment)
20986 inst.instruction |= 1 << 4;
20987 break;
20988
20989 case 2: /* VLD3 / VST3. */
20990 constraint (inst.operands[1].immisalign,
20991 _("can't use alignment with this instruction"));
20992 break;
20993
20994 case 3: /* VLD4 / VST4. */
20995 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
20996 16, 64, 32, 64, 32, 128, -1);
20997 if (align_good == FAIL)
20998 return;
20999 if (do_alignment)
21000 {
21001 unsigned alignbits = 0;
21002 switch (et.size)
21003 {
21004 case 8: alignbits = 0x1; break;
21005 case 16: alignbits = 0x1; break;
21006 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
21007 default: ;
21008 }
21009 inst.instruction |= alignbits << 4;
21010 }
21011 break;
21012
21013 default: ;
21014 }
21015
21016 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21017 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21018 inst.instruction |= 1 << (4 + logsize);
21019
21020 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21021 inst.instruction |= logsize << 10;
21022 }
21023
21024 /* Encode single n-element structure to all lanes VLD<n> instructions. */
21025
21026 static void
21027 do_neon_ld_dup (void)
21028 {
21029 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
21030 int align_good, do_alignment = 0;
21031
21032 if (et.type == NT_invtype)
21033 return;
21034
21035 switch ((inst.instruction >> 8) & 3)
21036 {
21037 case 0: /* VLD1. */
21038 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
21039 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
21040 &do_alignment, 16, 16, 32, 32, -1);
21041 if (align_good == FAIL)
21042 return;
21043 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
21044 {
21045 case 1: break;
21046 case 2: inst.instruction |= 1 << 5; break;
21047 default: first_error (_("bad list length")); return;
21048 }
21049 inst.instruction |= neon_logbits (et.size) << 6;
21050 break;
21051
21052 case 1: /* VLD2. */
21053 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
21054 &do_alignment, 8, 16, 16, 32, 32, 64,
21055 -1);
21056 if (align_good == FAIL)
21057 return;
21058 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
21059 _("bad list length"));
21060 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21061 inst.instruction |= 1 << 5;
21062 inst.instruction |= neon_logbits (et.size) << 6;
21063 break;
21064
21065 case 2: /* VLD3. */
21066 constraint (inst.operands[1].immisalign,
21067 _("can't use alignment with this instruction"));
21068 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
21069 _("bad list length"));
21070 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21071 inst.instruction |= 1 << 5;
21072 inst.instruction |= neon_logbits (et.size) << 6;
21073 break;
21074
21075 case 3: /* VLD4. */
21076 {
21077 int align = inst.operands[1].imm >> 8;
21078 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
21079 16, 64, 32, 64, 32, 128, -1);
21080 if (align_good == FAIL)
21081 return;
21082 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21083 _("bad list length"));
21084 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21085 inst.instruction |= 1 << 5;
21086 if (et.size == 32 && align == 128)
21087 inst.instruction |= 0x3 << 6;
21088 else
21089 inst.instruction |= neon_logbits (et.size) << 6;
21090 }
21091 break;
21092
21093 default: ;
21094 }
21095
21096 inst.instruction |= do_alignment << 4;
21097 }
21098
21099 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21100 apart from bits [11:4]. */
21101
21102 static void
21103 do_neon_ldx_stx (void)
21104 {
21105 if (inst.operands[1].isreg)
21106 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21107
21108 switch (NEON_LANE (inst.operands[0].imm))
21109 {
21110 case NEON_INTERLEAVE_LANES:
21111 NEON_ENCODE (INTERLV, inst);
21112 do_neon_ld_st_interleave ();
21113 break;
21114
21115 case NEON_ALL_LANES:
21116 NEON_ENCODE (DUP, inst);
21117 if (inst.instruction == N_INV)
21118 {
21119 first_error ("only loads support such operands");
21120 break;
21121 }
21122 do_neon_ld_dup ();
21123 break;
21124
21125 default:
21126 NEON_ENCODE (LANE, inst);
21127 do_neon_ld_st_lane ();
21128 }
21129
21130 /* L bit comes from bit mask. */
21131 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21132 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21133 inst.instruction |= inst.operands[1].reg << 16;
21134
21135 if (inst.operands[1].postind)
21136 {
21137 int postreg = inst.operands[1].imm & 0xf;
21138 constraint (!inst.operands[1].immisreg,
21139 _("post-index must be a register"));
21140 constraint (postreg == 0xd || postreg == 0xf,
21141 _("bad register for post-index"));
21142 inst.instruction |= postreg;
21143 }
21144 else
21145 {
21146 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
21147 constraint (inst.relocs[0].exp.X_op != O_constant
21148 || inst.relocs[0].exp.X_add_number != 0,
21149 BAD_ADDR_MODE);
21150
21151 if (inst.operands[1].writeback)
21152 {
21153 inst.instruction |= 0xd;
21154 }
21155 else
21156 inst.instruction |= 0xf;
21157 }
21158
21159 if (thumb_mode)
21160 inst.instruction |= 0xf9000000;
21161 else
21162 inst.instruction |= 0xf4000000;
21163 }
21164
21165 /* FP v8. */
21166 static void
21167 do_vfp_nsyn_fpv8 (enum neon_shape rs)
21168 {
21169 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21170 D register operands. */
21171 if (neon_shape_class[rs] == SC_DOUBLE)
21172 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21173 _(BAD_FPU));
21174
21175 NEON_ENCODE (FPV8, inst);
21176
21177 if (rs == NS_FFF || rs == NS_HHH)
21178 {
21179 do_vfp_sp_dyadic ();
21180
21181 /* ARMv8.2 fp16 instruction. */
21182 if (rs == NS_HHH)
21183 do_scalar_fp16_v82_encode ();
21184 }
21185 else
21186 do_vfp_dp_rd_rn_rm ();
21187
21188 if (rs == NS_DDD)
21189 inst.instruction |= 0x100;
21190
21191 inst.instruction |= 0xf0000000;
21192 }
21193
21194 static void
21195 do_vsel (void)
21196 {
21197 set_pred_insn_type (OUTSIDE_PRED_INSN);
21198
21199 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21200 first_error (_("invalid instruction shape"));
21201 }
21202
21203 static void
21204 do_vmaxnm (void)
21205 {
21206 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21207 set_pred_insn_type (OUTSIDE_PRED_INSN);
21208
21209 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21210 return;
21211
21212 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
21213 return;
21214
21215 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
21216 }
21217
21218 static void
21219 do_vrint_1 (enum neon_cvt_mode mode)
21220 {
21221 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
21222 struct neon_type_el et;
21223
21224 if (rs == NS_NULL)
21225 return;
21226
21227 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21228 D register operands. */
21229 if (neon_shape_class[rs] == SC_DOUBLE)
21230 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21231 _(BAD_FPU));
21232
21233 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21234 | N_VFP);
21235 if (et.type != NT_invtype)
21236 {
21237 /* VFP encodings. */
21238 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21239 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
21240 set_pred_insn_type (OUTSIDE_PRED_INSN);
21241
21242 NEON_ENCODE (FPV8, inst);
21243 if (rs == NS_FF || rs == NS_HH)
21244 do_vfp_sp_monadic ();
21245 else
21246 do_vfp_dp_rd_rm ();
21247
21248 switch (mode)
21249 {
21250 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21251 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21252 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21253 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21254 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21255 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21256 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21257 default: abort ();
21258 }
21259
21260 inst.instruction |= (rs == NS_DD) << 8;
21261 do_vfp_cond_or_thumb ();
21262
21263 /* ARMv8.2 fp16 vrint instruction. */
21264 if (rs == NS_HH)
21265 do_scalar_fp16_v82_encode ();
21266 }
21267 else
21268 {
21269 /* Neon encodings (or something broken...). */
21270 inst.error = NULL;
21271 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
21272
21273 if (et.type == NT_invtype)
21274 return;
21275
21276 if (!check_simd_pred_availability (TRUE,
21277 NEON_CHECK_CC | NEON_CHECK_ARCH8))
21278 return;
21279
21280 NEON_ENCODE (FLOAT, inst);
21281
21282 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21283 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21284 inst.instruction |= LOW4 (inst.operands[1].reg);
21285 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21286 inst.instruction |= neon_quad (rs) << 6;
21287 /* Mask off the original size bits and reencode them. */
21288 inst.instruction = ((inst.instruction & 0xfff3ffff)
21289 | neon_logbits (et.size) << 18);
21290
21291 switch (mode)
21292 {
21293 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21294 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21295 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21296 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21297 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21298 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21299 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21300 default: abort ();
21301 }
21302
21303 if (thumb_mode)
21304 inst.instruction |= 0xfc000000;
21305 else
21306 inst.instruction |= 0xf0000000;
21307 }
21308 }
21309
21310 static void
21311 do_vrintx (void)
21312 {
21313 do_vrint_1 (neon_cvt_mode_x);
21314 }
21315
21316 static void
21317 do_vrintz (void)
21318 {
21319 do_vrint_1 (neon_cvt_mode_z);
21320 }
21321
21322 static void
21323 do_vrintr (void)
21324 {
21325 do_vrint_1 (neon_cvt_mode_r);
21326 }
21327
21328 static void
21329 do_vrinta (void)
21330 {
21331 do_vrint_1 (neon_cvt_mode_a);
21332 }
21333
21334 static void
21335 do_vrintn (void)
21336 {
21337 do_vrint_1 (neon_cvt_mode_n);
21338 }
21339
21340 static void
21341 do_vrintp (void)
21342 {
21343 do_vrint_1 (neon_cvt_mode_p);
21344 }
21345
21346 static void
21347 do_vrintm (void)
21348 {
21349 do_vrint_1 (neon_cvt_mode_m);
21350 }
21351
21352 static unsigned
21353 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21354 {
21355 unsigned regno = NEON_SCALAR_REG (opnd);
21356 unsigned elno = NEON_SCALAR_INDEX (opnd);
21357
21358 if (elsize == 16 && elno < 2 && regno < 16)
21359 return regno | (elno << 4);
21360 else if (elsize == 32 && elno == 0)
21361 return regno;
21362
21363 first_error (_("scalar out of range"));
21364 return 0;
21365 }
21366
21367 static void
21368 do_vcmla (void)
21369 {
21370 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21371 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21372 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21373 constraint (inst.relocs[0].exp.X_op != O_constant,
21374 _("expression too complex"));
21375 unsigned rot = inst.relocs[0].exp.X_add_number;
21376 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21377 _("immediate out of range"));
21378 rot /= 90;
21379
21380 if (!check_simd_pred_availability (TRUE,
21381 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21382 return;
21383
21384 if (inst.operands[2].isscalar)
21385 {
21386 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21387 first_error (_("invalid instruction shape"));
21388 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21389 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21390 N_KEY | N_F16 | N_F32).size;
21391 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21392 inst.is_neon = 1;
21393 inst.instruction = 0xfe000800;
21394 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21395 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21396 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21397 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21398 inst.instruction |= LOW4 (m);
21399 inst.instruction |= HI1 (m) << 5;
21400 inst.instruction |= neon_quad (rs) << 6;
21401 inst.instruction |= rot << 20;
21402 inst.instruction |= (size == 32) << 23;
21403 }
21404 else
21405 {
21406 enum neon_shape rs;
21407 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21408 rs = neon_select_shape (NS_QQQI, NS_NULL);
21409 else
21410 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21411
21412 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21413 N_KEY | N_F16 | N_F32).size;
21414 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21415 && (inst.operands[0].reg == inst.operands[1].reg
21416 || inst.operands[0].reg == inst.operands[2].reg))
21417 as_tsktsk (BAD_MVE_SRCDEST);
21418
21419 neon_three_same (neon_quad (rs), 0, -1);
21420 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21421 inst.instruction |= 0xfc200800;
21422 inst.instruction |= rot << 23;
21423 inst.instruction |= (size == 32) << 20;
21424 }
21425 }
21426
21427 static void
21428 do_vcadd (void)
21429 {
21430 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21431 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21432 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21433 constraint (inst.relocs[0].exp.X_op != O_constant,
21434 _("expression too complex"));
21435
21436 unsigned rot = inst.relocs[0].exp.X_add_number;
21437 constraint (rot != 90 && rot != 270, _("immediate out of range"));
21438 enum neon_shape rs;
21439 struct neon_type_el et;
21440 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21441 {
21442 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21443 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21444 }
21445 else
21446 {
21447 rs = neon_select_shape (NS_QQQI, NS_NULL);
21448 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21449 | N_I16 | N_I32);
21450 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21451 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21452 "operand makes instruction UNPREDICTABLE"));
21453 }
21454
21455 if (et.type == NT_invtype)
21456 return;
21457
21458 if (!check_simd_pred_availability (et.type == NT_float,
21459 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21460 return;
21461
21462 if (et.type == NT_float)
21463 {
21464 neon_three_same (neon_quad (rs), 0, -1);
21465 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21466 inst.instruction |= 0xfc800800;
21467 inst.instruction |= (rot == 270) << 24;
21468 inst.instruction |= (et.size == 32) << 20;
21469 }
21470 else
21471 {
21472 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21473 inst.instruction = 0xfe000f00;
21474 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21475 inst.instruction |= neon_logbits (et.size) << 20;
21476 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21477 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21478 inst.instruction |= (rot == 270) << 12;
21479 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21480 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21481 inst.instruction |= LOW4 (inst.operands[2].reg);
21482 inst.is_neon = 1;
21483 }
21484 }
21485
21486 /* Dot Product instructions encoding support. */
21487
21488 static void
21489 do_neon_dotproduct (int unsigned_p)
21490 {
21491 enum neon_shape rs;
21492 unsigned scalar_oprd2 = 0;
21493 int high8;
21494
21495 if (inst.cond != COND_ALWAYS)
21496 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21497 "is UNPREDICTABLE"));
21498
21499 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21500 _(BAD_FPU));
21501
21502 /* Dot Product instructions are in three-same D/Q register format or the third
21503 operand can be a scalar index register. */
21504 if (inst.operands[2].isscalar)
21505 {
21506 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21507 high8 = 0xfe000000;
21508 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21509 }
21510 else
21511 {
21512 high8 = 0xfc000000;
21513 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21514 }
21515
21516 if (unsigned_p)
21517 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21518 else
21519 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21520
21521 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21522 Product instruction, so we pass 0 as the "ubit" parameter. And the
21523 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21524 neon_three_same (neon_quad (rs), 0, 32);
21525
21526 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21527 different NEON three-same encoding. */
21528 inst.instruction &= 0x00ffffff;
21529 inst.instruction |= high8;
21530 /* Encode 'U' bit which indicates signedness. */
21531 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21532 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21533 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21534 the instruction encoding. */
21535 if (inst.operands[2].isscalar)
21536 {
21537 inst.instruction &= 0xffffffd0;
21538 inst.instruction |= LOW4 (scalar_oprd2);
21539 inst.instruction |= HI1 (scalar_oprd2) << 5;
21540 }
21541 }
21542
21543 /* Dot Product instructions for signed integer. */
21544
21545 static void
21546 do_neon_dotproduct_s (void)
21547 {
21548 return do_neon_dotproduct (0);
21549 }
21550
21551 /* Dot Product instructions for unsigned integer. */
21552
21553 static void
21554 do_neon_dotproduct_u (void)
21555 {
21556 return do_neon_dotproduct (1);
21557 }
21558
21559 static void
21560 do_vusdot (void)
21561 {
21562 enum neon_shape rs;
21563 set_pred_insn_type (OUTSIDE_PRED_INSN);
21564 if (inst.operands[2].isscalar)
21565 {
21566 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21567 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21568
21569 inst.instruction |= (1 << 25);
21570 int index = inst.operands[2].reg & 0xf;
21571 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21572 inst.operands[2].reg >>= 4;
21573 constraint (!(inst.operands[2].reg < 16),
21574 _("indexed register must be less than 16"));
21575 neon_three_args (rs == NS_QQS);
21576 inst.instruction |= (index << 5);
21577 }
21578 else
21579 {
21580 inst.instruction |= (1 << 21);
21581 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21582 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21583 neon_three_args (rs == NS_QQQ);
21584 }
21585 }
21586
21587 static void
21588 do_vsudot (void)
21589 {
21590 enum neon_shape rs;
21591 set_pred_insn_type (OUTSIDE_PRED_INSN);
21592 if (inst.operands[2].isscalar)
21593 {
21594 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21595 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21596
21597 inst.instruction |= (1 << 25);
21598 int index = inst.operands[2].reg & 0xf;
21599 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
21600 inst.operands[2].reg >>= 4;
21601 constraint (!(inst.operands[2].reg < 16),
21602 _("indexed register must be less than 16"));
21603 neon_three_args (rs == NS_QQS);
21604 inst.instruction |= (index << 5);
21605 }
21606 }
21607
21608 static void
21609 do_vsmmla (void)
21610 {
21611 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21612 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21613
21614 set_pred_insn_type (OUTSIDE_PRED_INSN);
21615
21616 neon_three_args (1);
21617
21618 }
21619
21620 static void
21621 do_vummla (void)
21622 {
21623 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21624 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21625
21626 set_pred_insn_type (OUTSIDE_PRED_INSN);
21627
21628 neon_three_args (1);
21629
21630 }
21631
21632 static void
21633 check_cde_operand (size_t index, int is_dual)
21634 {
21635 unsigned Rx = inst.operands[index].reg;
21636 bfd_boolean isvec = inst.operands[index].isvec;
21637 if (is_dual == 0 && thumb_mode)
21638 constraint (
21639 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21640 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21641 else
21642 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21643 _("Register must be an even register between r0-r10."));
21644 }
21645
21646 static bfd_boolean
21647 cde_coproc_enabled (unsigned coproc)
21648 {
21649 switch (coproc)
21650 {
21651 case 0: return mark_feature_used (&arm_ext_cde0);
21652 case 1: return mark_feature_used (&arm_ext_cde1);
21653 case 2: return mark_feature_used (&arm_ext_cde2);
21654 case 3: return mark_feature_used (&arm_ext_cde3);
21655 case 4: return mark_feature_used (&arm_ext_cde4);
21656 case 5: return mark_feature_used (&arm_ext_cde5);
21657 case 6: return mark_feature_used (&arm_ext_cde6);
21658 case 7: return mark_feature_used (&arm_ext_cde7);
21659 default: return FALSE;
21660 }
21661 }
21662
21663 #define cde_coproc_pos 8
21664 static void
21665 cde_handle_coproc (void)
21666 {
21667 unsigned coproc = inst.operands[0].reg;
21668 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21669 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21670 inst.instruction |= coproc << cde_coproc_pos;
21671 }
21672 #undef cde_coproc_pos
21673
21674 static void
21675 cxn_handle_predication (bfd_boolean is_accum)
21676 {
21677 /* This function essentially checks for a suffix, not whether the instruction
21678 is inside an IT block or not.
21679 The CX* instructions should never have a conditional suffix -- this is not
21680 mentioned in the syntax. */
21681 if (conditional_insn ())
21682 inst.error = BAD_SYNTAX;
21683 /* Here we ensure that if the current element */
21684 else if (is_accum)
21685 set_pred_insn_type (NEUTRAL_IT_NO_VPT_INSN);
21686 else
21687 set_pred_insn_type (OUTSIDE_PRED_INSN);
21688 }
21689
21690 static void
21691 do_custom_instruction_1 (int is_dual, bfd_boolean is_accum)
21692 {
21693
21694 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21695
21696 unsigned imm, Rd;
21697
21698 Rd = inst.operands[1].reg;
21699 check_cde_operand (1, is_dual);
21700
21701 if (is_dual == 1)
21702 {
21703 constraint (inst.operands[2].reg != Rd + 1,
21704 _("cx1d requires consecutive destination registers."));
21705 imm = inst.operands[3].imm;
21706 }
21707 else if (is_dual == 0)
21708 imm = inst.operands[2].imm;
21709 else
21710 abort ();
21711
21712 inst.instruction |= Rd << 12;
21713 inst.instruction |= (imm & 0x1F80) << 9;
21714 inst.instruction |= (imm & 0x0040) << 1;
21715 inst.instruction |= (imm & 0x003f);
21716
21717 cde_handle_coproc ();
21718 cxn_handle_predication (is_accum);
21719 }
21720
21721 static void
21722 do_custom_instruction_2 (int is_dual, bfd_boolean is_accum)
21723 {
21724
21725 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21726
21727 unsigned imm, Rd, Rn;
21728
21729 Rd = inst.operands[1].reg;
21730
21731 if (is_dual == 1)
21732 {
21733 constraint (inst.operands[2].reg != Rd + 1,
21734 _("cx2d requires consecutive destination registers."));
21735 imm = inst.operands[4].imm;
21736 Rn = inst.operands[3].reg;
21737 }
21738 else if (is_dual == 0)
21739 {
21740 imm = inst.operands[3].imm;
21741 Rn = inst.operands[2].reg;
21742 }
21743 else
21744 abort ();
21745
21746 check_cde_operand (2 + is_dual, /* is_dual = */0);
21747 check_cde_operand (1, is_dual);
21748
21749 inst.instruction |= Rd << 12;
21750 inst.instruction |= Rn << 16;
21751
21752 inst.instruction |= (imm & 0x0380) << 13;
21753 inst.instruction |= (imm & 0x0040) << 1;
21754 inst.instruction |= (imm & 0x003f);
21755
21756 cde_handle_coproc ();
21757 cxn_handle_predication (is_accum);
21758 }
21759
21760 static void
21761 do_custom_instruction_3 (int is_dual, bfd_boolean is_accum)
21762 {
21763
21764 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21765
21766 unsigned imm, Rd, Rn, Rm;
21767
21768 Rd = inst.operands[1].reg;
21769
21770 if (is_dual == 1)
21771 {
21772 constraint (inst.operands[2].reg != Rd + 1,
21773 _("cx3d requires consecutive destination registers."));
21774 imm = inst.operands[5].imm;
21775 Rn = inst.operands[3].reg;
21776 Rm = inst.operands[4].reg;
21777 }
21778 else if (is_dual == 0)
21779 {
21780 imm = inst.operands[4].imm;
21781 Rn = inst.operands[2].reg;
21782 Rm = inst.operands[3].reg;
21783 }
21784 else
21785 abort ();
21786
21787 check_cde_operand (1, is_dual);
21788 check_cde_operand (2 + is_dual, /* is_dual = */0);
21789 check_cde_operand (3 + is_dual, /* is_dual = */0);
21790
21791 inst.instruction |= Rd;
21792 inst.instruction |= Rn << 16;
21793 inst.instruction |= Rm << 12;
21794
21795 inst.instruction |= (imm & 0x0038) << 17;
21796 inst.instruction |= (imm & 0x0004) << 5;
21797 inst.instruction |= (imm & 0x0003) << 4;
21798
21799 cde_handle_coproc ();
21800 cxn_handle_predication (is_accum);
21801 }
21802
21803 static void
21804 do_cx1 (void)
21805 {
21806 return do_custom_instruction_1 (0, 0);
21807 }
21808
21809 static void
21810 do_cx1a (void)
21811 {
21812 return do_custom_instruction_1 (0, 1);
21813 }
21814
21815 static void
21816 do_cx1d (void)
21817 {
21818 return do_custom_instruction_1 (1, 0);
21819 }
21820
21821 static void
21822 do_cx1da (void)
21823 {
21824 return do_custom_instruction_1 (1, 1);
21825 }
21826
21827 static void
21828 do_cx2 (void)
21829 {
21830 return do_custom_instruction_2 (0, 0);
21831 }
21832
21833 static void
21834 do_cx2a (void)
21835 {
21836 return do_custom_instruction_2 (0, 1);
21837 }
21838
21839 static void
21840 do_cx2d (void)
21841 {
21842 return do_custom_instruction_2 (1, 0);
21843 }
21844
21845 static void
21846 do_cx2da (void)
21847 {
21848 return do_custom_instruction_2 (1, 1);
21849 }
21850
21851 static void
21852 do_cx3 (void)
21853 {
21854 return do_custom_instruction_3 (0, 0);
21855 }
21856
21857 static void
21858 do_cx3a (void)
21859 {
21860 return do_custom_instruction_3 (0, 1);
21861 }
21862
21863 static void
21864 do_cx3d (void)
21865 {
21866 return do_custom_instruction_3 (1, 0);
21867 }
21868
21869 static void
21870 do_cx3da (void)
21871 {
21872 return do_custom_instruction_3 (1, 1);
21873 }
21874
21875 static void
21876 vcx_assign_vec_d (unsigned regnum)
21877 {
21878 inst.instruction |= HI4 (regnum) << 12;
21879 inst.instruction |= LOW1 (regnum) << 22;
21880 }
21881
21882 static void
21883 vcx_assign_vec_m (unsigned regnum)
21884 {
21885 inst.instruction |= HI4 (regnum);
21886 inst.instruction |= LOW1 (regnum) << 5;
21887 }
21888
21889 static void
21890 vcx_assign_vec_n (unsigned regnum)
21891 {
21892 inst.instruction |= HI4 (regnum) << 16;
21893 inst.instruction |= LOW1 (regnum) << 7;
21894 }
21895
21896 enum vcx_reg_type {
21897 q_reg,
21898 d_reg,
21899 s_reg
21900 };
21901
21902 static enum vcx_reg_type
21903 vcx_get_reg_type (enum neon_shape ns)
21904 {
21905 gas_assert (ns == NS_PQI
21906 || ns == NS_PDI
21907 || ns == NS_PFI
21908 || ns == NS_PQQI
21909 || ns == NS_PDDI
21910 || ns == NS_PFFI
21911 || ns == NS_PQQQI
21912 || ns == NS_PDDDI
21913 || ns == NS_PFFFI);
21914 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21915 return q_reg;
21916 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21917 return d_reg;
21918 return s_reg;
21919 }
21920
21921 #define vcx_size_pos 24
21922 #define vcx_vec_pos 6
21923 static unsigned
21924 vcx_handle_shape (enum vcx_reg_type reg_type)
21925 {
21926 unsigned mult = 2;
21927 if (reg_type == q_reg)
21928 inst.instruction |= 1 << vcx_vec_pos;
21929 else if (reg_type == d_reg)
21930 inst.instruction |= 1 << vcx_size_pos;
21931 else
21932 mult = 1;
21933 /* NOTE:
21934 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21935 bits (or equivalent for N and M registers).
21936 Similarly the D registers are encoded as N in D:Vd bits.
21937 While the S registers are encoded as N in the Vd:D bits.
21938
21939 Taking into account the maximum values of these registers we can see a
21940 nicer pattern for calculation:
21941 Q -> 7, D -> 15, S -> 31
21942
21943 If we say that everything is encoded in the Vd:D bits, then we can say
21944 that Q is encoded as 4*N, and D is encoded as 2*N.
21945 This way the bits will end up the same, and calculation is simpler.
21946 (calculation is now:
21947 1. Multiply by a number determined by the register letter.
21948 2. Encode resulting number in Vd:D bits.)
21949
21950 This is made a little more complicated by automatic handling of 'Q'
21951 registers elsewhere, which means the register number is already 2*N where
21952 N is the number the user wrote after the register letter.
21953 */
21954 return mult;
21955 }
21956 #undef vcx_vec_pos
21957 #undef vcx_size_pos
21958
21959 static void
21960 vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21961 {
21962 if (reg_type == q_reg)
21963 {
21964 gas_assert (R % 2 == 0);
21965 constraint (R >= 16, _("'q' register must be in range 0-7"));
21966 }
21967 else if (reg_type == d_reg)
21968 constraint (R >= 16, _("'d' register must be in range 0-15"));
21969 else
21970 constraint (R >= 32, _("'s' register must be in range 0-31"));
21971 }
21972
21973 static void (*vcx_assign_vec[3]) (unsigned) = {
21974 vcx_assign_vec_d,
21975 vcx_assign_vec_m,
21976 vcx_assign_vec_n
21977 };
21978
21979 static void
21980 vcx_handle_register_arguments (unsigned num_registers,
21981 enum vcx_reg_type reg_type)
21982 {
21983 unsigned R, i;
21984 unsigned reg_mult = vcx_handle_shape (reg_type);
21985 for (i = 0; i < num_registers; i++)
21986 {
21987 R = inst.operands[i+1].reg;
21988 vcx_ensure_register_in_range (R, reg_type);
21989 if (num_registers == 3 && i > 0)
21990 {
21991 if (i == 2)
21992 vcx_assign_vec[1] (R * reg_mult);
21993 else
21994 vcx_assign_vec[2] (R * reg_mult);
21995 continue;
21996 }
21997 vcx_assign_vec[i](R * reg_mult);
21998 }
21999 }
22000
22001 static void
22002 vcx_handle_insn_block (enum vcx_reg_type reg_type)
22003 {
22004 if (reg_type == q_reg)
22005 if (inst.cond > COND_ALWAYS)
22006 inst.pred_insn_type = INSIDE_VPT_INSN;
22007 else
22008 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
22009 else if (inst.cond == COND_ALWAYS)
22010 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22011 else
22012 inst.error = BAD_NOT_IT;
22013 }
22014
22015 static void
22016 vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22017 {
22018 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22019 cde_handle_coproc ();
22020 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22021 vcx_handle_register_arguments (num_args, reg_type);
22022 vcx_handle_insn_block (reg_type);
22023 if (reg_type == q_reg)
22024 constraint (!mark_feature_used (&mve_ext),
22025 _("vcx instructions with Q registers require MVE"));
22026 else
22027 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22028 && mark_feature_used (&armv8m_fp))
22029 && !mark_feature_used (&mve_ext),
22030 _("vcx instructions with S or D registers require either MVE"
22031 " or Armv8-M floating point etension."));
22032 }
22033
22034 static void
22035 do_vcx1 (void)
22036 {
22037 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22038 vcx_handle_common_checks (1, rs);
22039
22040 unsigned imm = inst.operands[2].imm;
22041 inst.instruction |= (imm & 0x03f);
22042 inst.instruction |= (imm & 0x040) << 1;
22043 inst.instruction |= (imm & 0x780) << 9;
22044 if (rs != NS_PQI)
22045 constraint (imm >= 2048,
22046 _("vcx1 with S or D registers takes immediate within 0-2047"));
22047 inst.instruction |= (imm & 0x800) << 13;
22048 }
22049
22050 static void
22051 do_vcx2 (void)
22052 {
22053 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22054 vcx_handle_common_checks (2, rs);
22055
22056 unsigned imm = inst.operands[3].imm;
22057 inst.instruction |= (imm & 0x01) << 4;
22058 inst.instruction |= (imm & 0x02) << 6;
22059 inst.instruction |= (imm & 0x3c) << 14;
22060 if (rs != NS_PQQI)
22061 constraint (imm >= 64,
22062 _("vcx2 with S or D registers takes immediate within 0-63"));
22063 inst.instruction |= (imm & 0x40) << 18;
22064 }
22065
22066 static void
22067 do_vcx3 (void)
22068 {
22069 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22070 vcx_handle_common_checks (3, rs);
22071
22072 unsigned imm = inst.operands[4].imm;
22073 inst.instruction |= (imm & 0x1) << 4;
22074 inst.instruction |= (imm & 0x6) << 19;
22075 if (rs != NS_PQQQI)
22076 constraint (imm >= 8,
22077 _("vcx2 with S or D registers takes immediate within 0-7"));
22078 inst.instruction |= (imm & 0x8) << 21;
22079 }
22080
22081 /* Crypto v1 instructions. */
22082 static void
22083 do_crypto_2op_1 (unsigned elttype, int op)
22084 {
22085 set_pred_insn_type (OUTSIDE_PRED_INSN);
22086
22087 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22088 == NT_invtype)
22089 return;
22090
22091 inst.error = NULL;
22092
22093 NEON_ENCODE (INTEGER, inst);
22094 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22095 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22096 inst.instruction |= LOW4 (inst.operands[1].reg);
22097 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22098 if (op != -1)
22099 inst.instruction |= op << 6;
22100
22101 if (thumb_mode)
22102 inst.instruction |= 0xfc000000;
22103 else
22104 inst.instruction |= 0xf0000000;
22105 }
22106
22107 static void
22108 do_crypto_3op_1 (int u, int op)
22109 {
22110 set_pred_insn_type (OUTSIDE_PRED_INSN);
22111
22112 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22113 N_32 | N_UNT | N_KEY).type == NT_invtype)
22114 return;
22115
22116 inst.error = NULL;
22117
22118 NEON_ENCODE (INTEGER, inst);
22119 neon_three_same (1, u, 8 << op);
22120 }
22121
22122 static void
22123 do_aese (void)
22124 {
22125 do_crypto_2op_1 (N_8, 0);
22126 }
22127
22128 static void
22129 do_aesd (void)
22130 {
22131 do_crypto_2op_1 (N_8, 1);
22132 }
22133
22134 static void
22135 do_aesmc (void)
22136 {
22137 do_crypto_2op_1 (N_8, 2);
22138 }
22139
22140 static void
22141 do_aesimc (void)
22142 {
22143 do_crypto_2op_1 (N_8, 3);
22144 }
22145
22146 static void
22147 do_sha1c (void)
22148 {
22149 do_crypto_3op_1 (0, 0);
22150 }
22151
22152 static void
22153 do_sha1p (void)
22154 {
22155 do_crypto_3op_1 (0, 1);
22156 }
22157
22158 static void
22159 do_sha1m (void)
22160 {
22161 do_crypto_3op_1 (0, 2);
22162 }
22163
22164 static void
22165 do_sha1su0 (void)
22166 {
22167 do_crypto_3op_1 (0, 3);
22168 }
22169
22170 static void
22171 do_sha256h (void)
22172 {
22173 do_crypto_3op_1 (1, 0);
22174 }
22175
22176 static void
22177 do_sha256h2 (void)
22178 {
22179 do_crypto_3op_1 (1, 1);
22180 }
22181
22182 static void
22183 do_sha256su1 (void)
22184 {
22185 do_crypto_3op_1 (1, 2);
22186 }
22187
22188 static void
22189 do_sha1h (void)
22190 {
22191 do_crypto_2op_1 (N_32, -1);
22192 }
22193
22194 static void
22195 do_sha1su1 (void)
22196 {
22197 do_crypto_2op_1 (N_32, 0);
22198 }
22199
22200 static void
22201 do_sha256su0 (void)
22202 {
22203 do_crypto_2op_1 (N_32, 1);
22204 }
22205
22206 static void
22207 do_crc32_1 (unsigned int poly, unsigned int sz)
22208 {
22209 unsigned int Rd = inst.operands[0].reg;
22210 unsigned int Rn = inst.operands[1].reg;
22211 unsigned int Rm = inst.operands[2].reg;
22212
22213 set_pred_insn_type (OUTSIDE_PRED_INSN);
22214 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22215 inst.instruction |= LOW4 (Rn) << 16;
22216 inst.instruction |= LOW4 (Rm);
22217 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22218 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22219
22220 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22221 as_warn (UNPRED_REG ("r15"));
22222 }
22223
22224 static void
22225 do_crc32b (void)
22226 {
22227 do_crc32_1 (0, 0);
22228 }
22229
22230 static void
22231 do_crc32h (void)
22232 {
22233 do_crc32_1 (0, 1);
22234 }
22235
22236 static void
22237 do_crc32w (void)
22238 {
22239 do_crc32_1 (0, 2);
22240 }
22241
22242 static void
22243 do_crc32cb (void)
22244 {
22245 do_crc32_1 (1, 0);
22246 }
22247
22248 static void
22249 do_crc32ch (void)
22250 {
22251 do_crc32_1 (1, 1);
22252 }
22253
22254 static void
22255 do_crc32cw (void)
22256 {
22257 do_crc32_1 (1, 2);
22258 }
22259
22260 static void
22261 do_vjcvt (void)
22262 {
22263 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22264 _(BAD_FPU));
22265 neon_check_type (2, NS_FD, N_S32, N_F64);
22266 do_vfp_sp_dp_cvt ();
22267 do_vfp_cond_or_thumb ();
22268 }
22269
22270 static void
22271 do_vdot (void)
22272 {
22273 enum neon_shape rs;
22274 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22275 set_pred_insn_type (OUTSIDE_PRED_INSN);
22276 if (inst.operands[2].isscalar)
22277 {
22278 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22279 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22280
22281 inst.instruction |= (1 << 25);
22282 int index = inst.operands[2].reg & 0xf;
22283 constraint ((index != 1 && index != 0), _("index must be 0 or 1"));
22284 inst.operands[2].reg >>= 4;
22285 constraint (!(inst.operands[2].reg < 16),
22286 _("indexed register must be less than 16"));
22287 neon_three_args (rs == NS_QQS);
22288 inst.instruction |= (index << 5);
22289 }
22290 else
22291 {
22292 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22293 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22294 neon_three_args (rs == NS_QQQ);
22295 }
22296 }
22297
22298 static void
22299 do_vmmla (void)
22300 {
22301 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22302 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22303
22304 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22305 set_pred_insn_type (OUTSIDE_PRED_INSN);
22306
22307 neon_three_args (1);
22308 }
22309
22310 \f
22311 /* Overall per-instruction processing. */
22312
22313 /* We need to be able to fix up arbitrary expressions in some statements.
22314 This is so that we can handle symbols that are an arbitrary distance from
22315 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22316 which returns part of an address in a form which will be valid for
22317 a data instruction. We do this by pushing the expression into a symbol
22318 in the expr_section, and creating a fix for that. */
22319
22320 static void
22321 fix_new_arm (fragS * frag,
22322 int where,
22323 short int size,
22324 expressionS * exp,
22325 int pc_rel,
22326 int reloc)
22327 {
22328 fixS * new_fix;
22329
22330 switch (exp->X_op)
22331 {
22332 case O_constant:
22333 if (pc_rel)
22334 {
22335 /* Create an absolute valued symbol, so we have something to
22336 refer to in the object file. Unfortunately for us, gas's
22337 generic expression parsing will already have folded out
22338 any use of .set foo/.type foo %function that may have
22339 been used to set type information of the target location,
22340 that's being specified symbolically. We have to presume
22341 the user knows what they are doing. */
22342 char name[16 + 8];
22343 symbolS *symbol;
22344
22345 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22346
22347 symbol = symbol_find_or_make (name);
22348 S_SET_SEGMENT (symbol, absolute_section);
22349 symbol_set_frag (symbol, &zero_address_frag);
22350 S_SET_VALUE (symbol, exp->X_add_number);
22351 exp->X_op = O_symbol;
22352 exp->X_add_symbol = symbol;
22353 exp->X_add_number = 0;
22354 }
22355 /* FALLTHROUGH */
22356 case O_symbol:
22357 case O_add:
22358 case O_subtract:
22359 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
22360 (enum bfd_reloc_code_real) reloc);
22361 break;
22362
22363 default:
22364 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
22365 pc_rel, (enum bfd_reloc_code_real) reloc);
22366 break;
22367 }
22368
22369 /* Mark whether the fix is to a THUMB instruction, or an ARM
22370 instruction. */
22371 new_fix->tc_fix_data = thumb_mode;
22372 }
22373
22374 /* Create a frg for an instruction requiring relaxation. */
22375 static void
22376 output_relax_insn (void)
22377 {
22378 char * to;
22379 symbolS *sym;
22380 int offset;
22381
22382 /* The size of the instruction is unknown, so tie the debug info to the
22383 start of the instruction. */
22384 dwarf2_emit_insn (0);
22385
22386 switch (inst.relocs[0].exp.X_op)
22387 {
22388 case O_symbol:
22389 sym = inst.relocs[0].exp.X_add_symbol;
22390 offset = inst.relocs[0].exp.X_add_number;
22391 break;
22392 case O_constant:
22393 sym = NULL;
22394 offset = inst.relocs[0].exp.X_add_number;
22395 break;
22396 default:
22397 sym = make_expr_symbol (&inst.relocs[0].exp);
22398 offset = 0;
22399 break;
22400 }
22401 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22402 inst.relax, sym, offset, NULL/*offset, opcode*/);
22403 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
22404 }
22405
22406 /* Write a 32-bit thumb instruction to buf. */
22407 static void
22408 put_thumb32_insn (char * buf, unsigned long insn)
22409 {
22410 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22411 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22412 }
22413
22414 static void
22415 output_inst (const char * str)
22416 {
22417 char * to = NULL;
22418
22419 if (inst.error)
22420 {
22421 as_bad ("%s -- `%s'", inst.error, str);
22422 return;
22423 }
22424 if (inst.relax)
22425 {
22426 output_relax_insn ();
22427 return;
22428 }
22429 if (inst.size == 0)
22430 return;
22431
22432 to = frag_more (inst.size);
22433 /* PR 9814: Record the thumb mode into the current frag so that we know
22434 what type of NOP padding to use, if necessary. We override any previous
22435 setting so that if the mode has changed then the NOPS that we use will
22436 match the encoding of the last instruction in the frag. */
22437 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22438
22439 if (thumb_mode && (inst.size > THUMB_SIZE))
22440 {
22441 gas_assert (inst.size == (2 * THUMB_SIZE));
22442 put_thumb32_insn (to, inst.instruction);
22443 }
22444 else if (inst.size > INSN_SIZE)
22445 {
22446 gas_assert (inst.size == (2 * INSN_SIZE));
22447 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22448 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
22449 }
22450 else
22451 md_number_to_chars (to, inst.instruction, inst.size);
22452
22453 int r;
22454 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22455 {
22456 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22457 fix_new_arm (frag_now, to - frag_now->fr_literal,
22458 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22459 inst.relocs[r].type);
22460 }
22461
22462 dwarf2_emit_insn (inst.size);
22463 }
22464
22465 static char *
22466 output_it_inst (int cond, int mask, char * to)
22467 {
22468 unsigned long instruction = 0xbf00;
22469
22470 mask &= 0xf;
22471 instruction |= mask;
22472 instruction |= cond << 4;
22473
22474 if (to == NULL)
22475 {
22476 to = frag_more (2);
22477 #ifdef OBJ_ELF
22478 dwarf2_emit_insn (2);
22479 #endif
22480 }
22481
22482 md_number_to_chars (to, instruction, 2);
22483
22484 return to;
22485 }
22486
22487 /* Tag values used in struct asm_opcode's tag field. */
22488 enum opcode_tag
22489 {
22490 OT_unconditional, /* Instruction cannot be conditionalized.
22491 The ARM condition field is still 0xE. */
22492 OT_unconditionalF, /* Instruction cannot be conditionalized
22493 and carries 0xF in its ARM condition field. */
22494 OT_csuffix, /* Instruction takes a conditional suffix. */
22495 OT_csuffixF, /* Some forms of the instruction take a scalar
22496 conditional suffix, others place 0xF where the
22497 condition field would be, others take a vector
22498 conditional suffix. */
22499 OT_cinfix3, /* Instruction takes a conditional infix,
22500 beginning at character index 3. (In
22501 unified mode, it becomes a suffix.) */
22502 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22503 tsts, cmps, cmns, and teqs. */
22504 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22505 character index 3, even in unified mode. Used for
22506 legacy instructions where suffix and infix forms
22507 may be ambiguous. */
22508 OT_csuf_or_in3, /* Instruction takes either a conditional
22509 suffix or an infix at character index 3. */
22510 OT_odd_infix_unc, /* This is the unconditional variant of an
22511 instruction that takes a conditional infix
22512 at an unusual position. In unified mode,
22513 this variant will accept a suffix. */
22514 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22515 are the conditional variants of instructions that
22516 take conditional infixes in unusual positions.
22517 The infix appears at character index
22518 (tag - OT_odd_infix_0). These are not accepted
22519 in unified mode. */
22520 };
22521
22522 /* Subroutine of md_assemble, responsible for looking up the primary
22523 opcode from the mnemonic the user wrote. STR points to the
22524 beginning of the mnemonic.
22525
22526 This is not simply a hash table lookup, because of conditional
22527 variants. Most instructions have conditional variants, which are
22528 expressed with a _conditional affix_ to the mnemonic. If we were
22529 to encode each conditional variant as a literal string in the opcode
22530 table, it would have approximately 20,000 entries.
22531
22532 Most mnemonics take this affix as a suffix, and in unified syntax,
22533 'most' is upgraded to 'all'. However, in the divided syntax, some
22534 instructions take the affix as an infix, notably the s-variants of
22535 the arithmetic instructions. Of those instructions, all but six
22536 have the infix appear after the third character of the mnemonic.
22537
22538 Accordingly, the algorithm for looking up primary opcodes given
22539 an identifier is:
22540
22541 1. Look up the identifier in the opcode table.
22542 If we find a match, go to step U.
22543
22544 2. Look up the last two characters of the identifier in the
22545 conditions table. If we find a match, look up the first N-2
22546 characters of the identifier in the opcode table. If we
22547 find a match, go to step CE.
22548
22549 3. Look up the fourth and fifth characters of the identifier in
22550 the conditions table. If we find a match, extract those
22551 characters from the identifier, and look up the remaining
22552 characters in the opcode table. If we find a match, go
22553 to step CM.
22554
22555 4. Fail.
22556
22557 U. Examine the tag field of the opcode structure, in case this is
22558 one of the six instructions with its conditional infix in an
22559 unusual place. If it is, the tag tells us where to find the
22560 infix; look it up in the conditions table and set inst.cond
22561 accordingly. Otherwise, this is an unconditional instruction.
22562 Again set inst.cond accordingly. Return the opcode structure.
22563
22564 CE. Examine the tag field to make sure this is an instruction that
22565 should receive a conditional suffix. If it is not, fail.
22566 Otherwise, set inst.cond from the suffix we already looked up,
22567 and return the opcode structure.
22568
22569 CM. Examine the tag field to make sure this is an instruction that
22570 should receive a conditional infix after the third character.
22571 If it is not, fail. Otherwise, undo the edits to the current
22572 line of input and proceed as for case CE. */
22573
22574 static const struct asm_opcode *
22575 opcode_lookup (char **str)
22576 {
22577 char *end, *base;
22578 char *affix;
22579 const struct asm_opcode *opcode;
22580 const struct asm_cond *cond;
22581 char save[2];
22582
22583 /* Scan up to the end of the mnemonic, which must end in white space,
22584 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
22585 for (base = end = *str; *end != '\0'; end++)
22586 if (*end == ' ' || *end == '.')
22587 break;
22588
22589 if (end == base)
22590 return NULL;
22591
22592 /* Handle a possible width suffix and/or Neon type suffix. */
22593 if (end[0] == '.')
22594 {
22595 int offset = 2;
22596
22597 /* The .w and .n suffixes are only valid if the unified syntax is in
22598 use. */
22599 if (unified_syntax && end[1] == 'w')
22600 inst.size_req = 4;
22601 else if (unified_syntax && end[1] == 'n')
22602 inst.size_req = 2;
22603 else
22604 offset = 0;
22605
22606 inst.vectype.elems = 0;
22607
22608 *str = end + offset;
22609
22610 if (end[offset] == '.')
22611 {
22612 /* See if we have a Neon type suffix (possible in either unified or
22613 non-unified ARM syntax mode). */
22614 if (parse_neon_type (&inst.vectype, str) == FAIL)
22615 return NULL;
22616 }
22617 else if (end[offset] != '\0' && end[offset] != ' ')
22618 return NULL;
22619 }
22620 else
22621 *str = end;
22622
22623 /* Look for unaffixed or special-case affixed mnemonic. */
22624 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22625 end - base);
22626 if (opcode)
22627 {
22628 /* step U */
22629 if (opcode->tag < OT_odd_infix_0)
22630 {
22631 inst.cond = COND_ALWAYS;
22632 return opcode;
22633 }
22634
22635 if (warn_on_deprecated && unified_syntax)
22636 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22637 affix = base + (opcode->tag - OT_odd_infix_0);
22638 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22639 gas_assert (cond);
22640
22641 inst.cond = cond->value;
22642 return opcode;
22643 }
22644 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22645 {
22646 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22647 */
22648 if (end - base < 2)
22649 return NULL;
22650 affix = end - 1;
22651 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
22652 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22653 affix - base);
22654 /* If this opcode can not be vector predicated then don't accept it with a
22655 vector predication code. */
22656 if (opcode && !opcode->mayBeVecPred)
22657 opcode = NULL;
22658 }
22659 if (!opcode || !cond)
22660 {
22661 /* Cannot have a conditional suffix on a mnemonic of less than two
22662 characters. */
22663 if (end - base < 3)
22664 return NULL;
22665
22666 /* Look for suffixed mnemonic. */
22667 affix = end - 2;
22668 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22669 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22670 affix - base);
22671 }
22672
22673 if (opcode && cond)
22674 {
22675 /* step CE */
22676 switch (opcode->tag)
22677 {
22678 case OT_cinfix3_legacy:
22679 /* Ignore conditional suffixes matched on infix only mnemonics. */
22680 break;
22681
22682 case OT_cinfix3:
22683 case OT_cinfix3_deprecated:
22684 case OT_odd_infix_unc:
22685 if (!unified_syntax)
22686 return NULL;
22687 /* Fall through. */
22688
22689 case OT_csuffix:
22690 case OT_csuffixF:
22691 case OT_csuf_or_in3:
22692 inst.cond = cond->value;
22693 return opcode;
22694
22695 case OT_unconditional:
22696 case OT_unconditionalF:
22697 if (thumb_mode)
22698 inst.cond = cond->value;
22699 else
22700 {
22701 /* Delayed diagnostic. */
22702 inst.error = BAD_COND;
22703 inst.cond = COND_ALWAYS;
22704 }
22705 return opcode;
22706
22707 default:
22708 return NULL;
22709 }
22710 }
22711
22712 /* Cannot have a usual-position infix on a mnemonic of less than
22713 six characters (five would be a suffix). */
22714 if (end - base < 6)
22715 return NULL;
22716
22717 /* Look for infixed mnemonic in the usual position. */
22718 affix = base + 3;
22719 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
22720 if (!cond)
22721 return NULL;
22722
22723 memcpy (save, affix, 2);
22724 memmove (affix, affix + 2, (end - affix) - 2);
22725 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
22726 (end - base) - 2);
22727 memmove (affix + 2, affix, (end - affix) - 2);
22728 memcpy (affix, save, 2);
22729
22730 if (opcode
22731 && (opcode->tag == OT_cinfix3
22732 || opcode->tag == OT_cinfix3_deprecated
22733 || opcode->tag == OT_csuf_or_in3
22734 || opcode->tag == OT_cinfix3_legacy))
22735 {
22736 /* Step CM. */
22737 if (warn_on_deprecated && unified_syntax
22738 && (opcode->tag == OT_cinfix3
22739 || opcode->tag == OT_cinfix3_deprecated))
22740 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22741
22742 inst.cond = cond->value;
22743 return opcode;
22744 }
22745
22746 return NULL;
22747 }
22748
22749 /* This function generates an initial IT instruction, leaving its block
22750 virtually open for the new instructions. Eventually,
22751 the mask will be updated by now_pred_add_mask () each time
22752 a new instruction needs to be included in the IT block.
22753 Finally, the block is closed with close_automatic_it_block ().
22754 The block closure can be requested either from md_assemble (),
22755 a tencode (), or due to a label hook. */
22756
22757 static void
22758 new_automatic_it_block (int cond)
22759 {
22760 now_pred.state = AUTOMATIC_PRED_BLOCK;
22761 now_pred.mask = 0x18;
22762 now_pred.cc = cond;
22763 now_pred.block_length = 1;
22764 mapping_state (MAP_THUMB);
22765 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22766 now_pred.warn_deprecated = FALSE;
22767 now_pred.insn_cond = TRUE;
22768 }
22769
22770 /* Close an automatic IT block.
22771 See comments in new_automatic_it_block (). */
22772
22773 static void
22774 close_automatic_it_block (void)
22775 {
22776 now_pred.mask = 0x10;
22777 now_pred.block_length = 0;
22778 }
22779
22780 /* Update the mask of the current automatically-generated IT
22781 instruction. See comments in new_automatic_it_block (). */
22782
22783 static void
22784 now_pred_add_mask (int cond)
22785 {
22786 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22787 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
22788 | ((bitvalue) << (nbit)))
22789 const int resulting_bit = (cond & 1);
22790
22791 now_pred.mask &= 0xf;
22792 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22793 resulting_bit,
22794 (5 - now_pred.block_length));
22795 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22796 1,
22797 ((5 - now_pred.block_length) - 1));
22798 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
22799
22800 #undef CLEAR_BIT
22801 #undef SET_BIT_VALUE
22802 }
22803
22804 /* The IT blocks handling machinery is accessed through the these functions:
22805 it_fsm_pre_encode () from md_assemble ()
22806 set_pred_insn_type () optional, from the tencode functions
22807 set_pred_insn_type_last () ditto
22808 in_pred_block () ditto
22809 it_fsm_post_encode () from md_assemble ()
22810 force_automatic_it_block_close () from label handling functions
22811
22812 Rationale:
22813 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
22814 initializing the IT insn type with a generic initial value depending
22815 on the inst.condition.
22816 2) During the tencode function, two things may happen:
22817 a) The tencode function overrides the IT insn type by
22818 calling either set_pred_insn_type (type) or
22819 set_pred_insn_type_last ().
22820 b) The tencode function queries the IT block state by
22821 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
22822
22823 Both set_pred_insn_type and in_pred_block run the internal FSM state
22824 handling function (handle_pred_state), because: a) setting the IT insn
22825 type may incur in an invalid state (exiting the function),
22826 and b) querying the state requires the FSM to be updated.
22827 Specifically we want to avoid creating an IT block for conditional
22828 branches, so it_fsm_pre_encode is actually a guess and we can't
22829 determine whether an IT block is required until the tencode () routine
22830 has decided what type of instruction this actually it.
22831 Because of this, if set_pred_insn_type and in_pred_block have to be
22832 used, set_pred_insn_type has to be called first.
22833
22834 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22835 that determines the insn IT type depending on the inst.cond code.
22836 When a tencode () routine encodes an instruction that can be
22837 either outside an IT block, or, in the case of being inside, has to be
22838 the last one, set_pred_insn_type_last () will determine the proper
22839 IT instruction type based on the inst.cond code. Otherwise,
22840 set_pred_insn_type can be called for overriding that logic or
22841 for covering other cases.
22842
22843 Calling handle_pred_state () may not transition the IT block state to
22844 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
22845 still queried. Instead, if the FSM determines that the state should
22846 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
22847 after the tencode () function: that's what it_fsm_post_encode () does.
22848
22849 Since in_pred_block () calls the state handling function to get an
22850 updated state, an error may occur (due to invalid insns combination).
22851 In that case, inst.error is set.
22852 Therefore, inst.error has to be checked after the execution of
22853 the tencode () routine.
22854
22855 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
22856 any pending state change (if any) that didn't take place in
22857 handle_pred_state () as explained above. */
22858
22859 static void
22860 it_fsm_pre_encode (void)
22861 {
22862 if (inst.cond != COND_ALWAYS)
22863 inst.pred_insn_type = INSIDE_IT_INSN;
22864 else
22865 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22866
22867 now_pred.state_handled = 0;
22868 }
22869
22870 /* IT state FSM handling function. */
22871 /* MVE instructions and non-MVE instructions are handled differently because of
22872 the introduction of VPT blocks.
22873 Specifications say that any non-MVE instruction inside a VPT block is
22874 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22875 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
22876 few exceptions we have MVE_UNPREDICABLE_INSN.
22877 The error messages provided depending on the different combinations possible
22878 are described in the cases below:
22879 For 'most' MVE instructions:
22880 1) In an IT block, with an IT code: syntax error
22881 2) In an IT block, with a VPT code: error: must be in a VPT block
22882 3) In an IT block, with no code: warning: UNPREDICTABLE
22883 4) In a VPT block, with an IT code: syntax error
22884 5) In a VPT block, with a VPT code: OK!
22885 6) In a VPT block, with no code: error: missing code
22886 7) Outside a pred block, with an IT code: error: syntax error
22887 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22888 9) Outside a pred block, with no code: OK!
22889 For non-MVE instructions:
22890 10) In an IT block, with an IT code: OK!
22891 11) In an IT block, with a VPT code: syntax error
22892 12) In an IT block, with no code: error: missing code
22893 13) In a VPT block, with an IT code: error: should be in an IT block
22894 14) In a VPT block, with a VPT code: syntax error
22895 15) In a VPT block, with no code: UNPREDICTABLE
22896 16) Outside a pred block, with an IT code: error: should be in an IT block
22897 17) Outside a pred block, with a VPT code: syntax error
22898 18) Outside a pred block, with no code: OK!
22899 */
22900
22901
22902 static int
22903 handle_pred_state (void)
22904 {
22905 now_pred.state_handled = 1;
22906 now_pred.insn_cond = FALSE;
22907
22908 switch (now_pred.state)
22909 {
22910 case OUTSIDE_PRED_BLOCK:
22911 switch (inst.pred_insn_type)
22912 {
22913 case MVE_UNPREDICABLE_INSN:
22914 case MVE_OUTSIDE_PRED_INSN:
22915 if (inst.cond < COND_ALWAYS)
22916 {
22917 /* Case 7: Outside a pred block, with an IT code: error: syntax
22918 error. */
22919 inst.error = BAD_SYNTAX;
22920 return FAIL;
22921 }
22922 /* Case 9: Outside a pred block, with no code: OK! */
22923 break;
22924 case OUTSIDE_PRED_INSN:
22925 if (inst.cond > COND_ALWAYS)
22926 {
22927 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22928 */
22929 inst.error = BAD_SYNTAX;
22930 return FAIL;
22931 }
22932 /* Case 18: Outside a pred block, with no code: OK! */
22933 break;
22934
22935 case INSIDE_VPT_INSN:
22936 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22937 a VPT block. */
22938 inst.error = BAD_OUT_VPT;
22939 return FAIL;
22940
22941 case INSIDE_IT_INSN:
22942 case INSIDE_IT_LAST_INSN:
22943 if (inst.cond < COND_ALWAYS)
22944 {
22945 /* Case 16: Outside a pred block, with an IT code: error: should
22946 be in an IT block. */
22947 if (thumb_mode == 0)
22948 {
22949 if (unified_syntax
22950 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22951 as_tsktsk (_("Warning: conditional outside an IT block"\
22952 " for Thumb."));
22953 }
22954 else
22955 {
22956 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22957 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22958 {
22959 /* Automatically generate the IT instruction. */
22960 new_automatic_it_block (inst.cond);
22961 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22962 close_automatic_it_block ();
22963 }
22964 else
22965 {
22966 inst.error = BAD_OUT_IT;
22967 return FAIL;
22968 }
22969 }
22970 break;
22971 }
22972 else if (inst.cond > COND_ALWAYS)
22973 {
22974 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22975 */
22976 inst.error = BAD_SYNTAX;
22977 return FAIL;
22978 }
22979 else
22980 gas_assert (0);
22981 case IF_INSIDE_IT_LAST_INSN:
22982 case NEUTRAL_IT_INSN:
22983 case NEUTRAL_IT_NO_VPT_INSN:
22984 break;
22985
22986 case VPT_INSN:
22987 if (inst.cond != COND_ALWAYS)
22988 first_error (BAD_SYNTAX);
22989 now_pred.state = MANUAL_PRED_BLOCK;
22990 now_pred.block_length = 0;
22991 now_pred.type = VECTOR_PRED;
22992 now_pred.cc = 0;
22993 break;
22994 case IT_INSN:
22995 now_pred.state = MANUAL_PRED_BLOCK;
22996 now_pred.block_length = 0;
22997 now_pred.type = SCALAR_PRED;
22998 break;
22999 }
23000 break;
23001
23002 case AUTOMATIC_PRED_BLOCK:
23003 /* Three things may happen now:
23004 a) We should increment current it block size;
23005 b) We should close current it block (closing insn or 4 insns);
23006 c) We should close current it block and start a new one (due
23007 to incompatible conditions or
23008 4 insns-length block reached). */
23009
23010 switch (inst.pred_insn_type)
23011 {
23012 case INSIDE_VPT_INSN:
23013 case VPT_INSN:
23014 case MVE_UNPREDICABLE_INSN:
23015 case MVE_OUTSIDE_PRED_INSN:
23016 gas_assert (0);
23017 case OUTSIDE_PRED_INSN:
23018 /* The closure of the block shall happen immediately,
23019 so any in_pred_block () call reports the block as closed. */
23020 force_automatic_it_block_close ();
23021 break;
23022
23023 case INSIDE_IT_INSN:
23024 case INSIDE_IT_LAST_INSN:
23025 case IF_INSIDE_IT_LAST_INSN:
23026 now_pred.block_length++;
23027
23028 if (now_pred.block_length > 4
23029 || !now_pred_compatible (inst.cond))
23030 {
23031 force_automatic_it_block_close ();
23032 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
23033 new_automatic_it_block (inst.cond);
23034 }
23035 else
23036 {
23037 now_pred.insn_cond = TRUE;
23038 now_pred_add_mask (inst.cond);
23039 }
23040
23041 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23042 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23043 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
23044 close_automatic_it_block ();
23045 break;
23046
23047 case NEUTRAL_IT_NO_VPT_INSN:
23048 if (now_pred.type == VECTOR_PRED)
23049 {
23050 inst.error = BAD_NO_VPT;
23051 break;
23052 }
23053 /* Fallthrough. */
23054 case NEUTRAL_IT_INSN:
23055 now_pred.block_length++;
23056 now_pred.insn_cond = TRUE;
23057
23058 if (now_pred.block_length > 4)
23059 force_automatic_it_block_close ();
23060 else
23061 now_pred_add_mask (now_pred.cc & 1);
23062 break;
23063
23064 case IT_INSN:
23065 close_automatic_it_block ();
23066 now_pred.state = MANUAL_PRED_BLOCK;
23067 break;
23068 }
23069 break;
23070
23071 case MANUAL_PRED_BLOCK:
23072 {
23073 int cond, is_last;
23074 if (now_pred.type == SCALAR_PRED)
23075 {
23076 /* Check conditional suffixes. */
23077 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23078 now_pred.mask <<= 1;
23079 now_pred.mask &= 0x1f;
23080 is_last = (now_pred.mask == 0x10);
23081 }
23082 else
23083 {
23084 now_pred.cc ^= (now_pred.mask >> 4);
23085 cond = now_pred.cc + 0xf;
23086 now_pred.mask <<= 1;
23087 now_pred.mask &= 0x1f;
23088 is_last = now_pred.mask == 0x10;
23089 }
23090 now_pred.insn_cond = TRUE;
23091
23092 switch (inst.pred_insn_type)
23093 {
23094 case OUTSIDE_PRED_INSN:
23095 if (now_pred.type == SCALAR_PRED)
23096 {
23097 if (inst.cond == COND_ALWAYS)
23098 {
23099 /* Case 12: In an IT block, with no code: error: missing
23100 code. */
23101 inst.error = BAD_NOT_IT;
23102 return FAIL;
23103 }
23104 else if (inst.cond > COND_ALWAYS)
23105 {
23106 /* Case 11: In an IT block, with a VPT code: syntax error.
23107 */
23108 inst.error = BAD_SYNTAX;
23109 return FAIL;
23110 }
23111 else if (thumb_mode)
23112 {
23113 /* This is for some special cases where a non-MVE
23114 instruction is not allowed in an IT block, such as cbz,
23115 but are put into one with a condition code.
23116 You could argue this should be a syntax error, but we
23117 gave the 'not allowed in IT block' diagnostic in the
23118 past so we will keep doing so. */
23119 inst.error = BAD_NOT_IT;
23120 return FAIL;
23121 }
23122 break;
23123 }
23124 else
23125 {
23126 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23127 as_tsktsk (MVE_NOT_VPT);
23128 return SUCCESS;
23129 }
23130 case MVE_OUTSIDE_PRED_INSN:
23131 if (now_pred.type == SCALAR_PRED)
23132 {
23133 if (inst.cond == COND_ALWAYS)
23134 {
23135 /* Case 3: In an IT block, with no code: warning:
23136 UNPREDICTABLE. */
23137 as_tsktsk (MVE_NOT_IT);
23138 return SUCCESS;
23139 }
23140 else if (inst.cond < COND_ALWAYS)
23141 {
23142 /* Case 1: In an IT block, with an IT code: syntax error.
23143 */
23144 inst.error = BAD_SYNTAX;
23145 return FAIL;
23146 }
23147 else
23148 gas_assert (0);
23149 }
23150 else
23151 {
23152 if (inst.cond < COND_ALWAYS)
23153 {
23154 /* Case 4: In a VPT block, with an IT code: syntax error.
23155 */
23156 inst.error = BAD_SYNTAX;
23157 return FAIL;
23158 }
23159 else if (inst.cond == COND_ALWAYS)
23160 {
23161 /* Case 6: In a VPT block, with no code: error: missing
23162 code. */
23163 inst.error = BAD_NOT_VPT;
23164 return FAIL;
23165 }
23166 else
23167 {
23168 gas_assert (0);
23169 }
23170 }
23171 case MVE_UNPREDICABLE_INSN:
23172 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23173 return SUCCESS;
23174 case INSIDE_IT_INSN:
23175 if (inst.cond > COND_ALWAYS)
23176 {
23177 /* Case 11: In an IT block, with a VPT code: syntax error. */
23178 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23179 inst.error = BAD_SYNTAX;
23180 return FAIL;
23181 }
23182 else if (now_pred.type == SCALAR_PRED)
23183 {
23184 /* Case 10: In an IT block, with an IT code: OK! */
23185 if (cond != inst.cond)
23186 {
23187 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23188 BAD_VPT_COND;
23189 return FAIL;
23190 }
23191 }
23192 else
23193 {
23194 /* Case 13: In a VPT block, with an IT code: error: should be
23195 in an IT block. */
23196 inst.error = BAD_OUT_IT;
23197 return FAIL;
23198 }
23199 break;
23200
23201 case INSIDE_VPT_INSN:
23202 if (now_pred.type == SCALAR_PRED)
23203 {
23204 /* Case 2: In an IT block, with a VPT code: error: must be in a
23205 VPT block. */
23206 inst.error = BAD_OUT_VPT;
23207 return FAIL;
23208 }
23209 /* Case 5: In a VPT block, with a VPT code: OK! */
23210 else if (cond != inst.cond)
23211 {
23212 inst.error = BAD_VPT_COND;
23213 return FAIL;
23214 }
23215 break;
23216 case INSIDE_IT_LAST_INSN:
23217 case IF_INSIDE_IT_LAST_INSN:
23218 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23219 {
23220 /* Case 4: In a VPT block, with an IT code: syntax error. */
23221 /* Case 11: In an IT block, with a VPT code: syntax error. */
23222 inst.error = BAD_SYNTAX;
23223 return FAIL;
23224 }
23225 else if (cond != inst.cond)
23226 {
23227 inst.error = BAD_IT_COND;
23228 return FAIL;
23229 }
23230 if (!is_last)
23231 {
23232 inst.error = BAD_BRANCH;
23233 return FAIL;
23234 }
23235 break;
23236
23237 case NEUTRAL_IT_NO_VPT_INSN:
23238 if (now_pred.type == VECTOR_PRED)
23239 {
23240 inst.error = BAD_NO_VPT;
23241 break;
23242 }
23243 /* Fallthrough. */
23244 case NEUTRAL_IT_INSN:
23245 /* The BKPT instruction is unconditional even in a IT or VPT
23246 block. */
23247 break;
23248
23249 case IT_INSN:
23250 if (now_pred.type == SCALAR_PRED)
23251 {
23252 inst.error = BAD_IT_IT;
23253 return FAIL;
23254 }
23255 /* fall through. */
23256 case VPT_INSN:
23257 if (inst.cond == COND_ALWAYS)
23258 {
23259 /* Executing a VPT/VPST instruction inside an IT block or a
23260 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23261 */
23262 if (now_pred.type == SCALAR_PRED)
23263 as_tsktsk (MVE_NOT_IT);
23264 else
23265 as_tsktsk (MVE_NOT_VPT);
23266 return SUCCESS;
23267 }
23268 else
23269 {
23270 /* VPT/VPST do not accept condition codes. */
23271 inst.error = BAD_SYNTAX;
23272 return FAIL;
23273 }
23274 }
23275 }
23276 break;
23277 }
23278
23279 return SUCCESS;
23280 }
23281
23282 struct depr_insn_mask
23283 {
23284 unsigned long pattern;
23285 unsigned long mask;
23286 const char* description;
23287 };
23288
23289 /* List of 16-bit instruction patterns deprecated in an IT block in
23290 ARMv8. */
23291 static const struct depr_insn_mask depr_it_insns[] = {
23292 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23293 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23294 { 0xa000, 0xb800, N_("ADR") },
23295 { 0x4800, 0xf800, N_("Literal loads") },
23296 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23297 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
23298 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23299 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23300 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
23301 { 0, 0, NULL }
23302 };
23303
23304 static void
23305 it_fsm_post_encode (void)
23306 {
23307 int is_last;
23308
23309 if (!now_pred.state_handled)
23310 handle_pred_state ();
23311
23312 if (now_pred.insn_cond
23313 && warn_on_restrict_it
23314 && !now_pred.warn_deprecated
23315 && warn_on_deprecated
23316 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23317 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
23318 {
23319 if (inst.instruction >= 0x10000)
23320 {
23321 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
23322 "performance deprecated in ARMv8-A and ARMv8-R"));
23323 now_pred.warn_deprecated = TRUE;
23324 }
23325 else
23326 {
23327 const struct depr_insn_mask *p = depr_it_insns;
23328
23329 while (p->mask != 0)
23330 {
23331 if ((inst.instruction & p->mask) == p->pattern)
23332 {
23333 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23334 "instructions of the following class are "
23335 "performance deprecated in ARMv8-A and "
23336 "ARMv8-R: %s"), p->description);
23337 now_pred.warn_deprecated = TRUE;
23338 break;
23339 }
23340
23341 ++p;
23342 }
23343 }
23344
23345 if (now_pred.block_length > 1)
23346 {
23347 as_tsktsk (_("IT blocks containing more than one conditional "
23348 "instruction are performance deprecated in ARMv8-A and "
23349 "ARMv8-R"));
23350 now_pred.warn_deprecated = TRUE;
23351 }
23352 }
23353
23354 is_last = (now_pred.mask == 0x10);
23355 if (is_last)
23356 {
23357 now_pred.state = OUTSIDE_PRED_BLOCK;
23358 now_pred.mask = 0;
23359 }
23360 }
23361
23362 static void
23363 force_automatic_it_block_close (void)
23364 {
23365 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
23366 {
23367 close_automatic_it_block ();
23368 now_pred.state = OUTSIDE_PRED_BLOCK;
23369 now_pred.mask = 0;
23370 }
23371 }
23372
23373 static int
23374 in_pred_block (void)
23375 {
23376 if (!now_pred.state_handled)
23377 handle_pred_state ();
23378
23379 return now_pred.state != OUTSIDE_PRED_BLOCK;
23380 }
23381
23382 /* Whether OPCODE only has T32 encoding. Since this function is only used by
23383 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23384 here, hence the "known" in the function name. */
23385
23386 static bfd_boolean
23387 known_t32_only_insn (const struct asm_opcode *opcode)
23388 {
23389 /* Original Thumb-1 wide instruction. */
23390 if (opcode->tencode == do_t_blx
23391 || opcode->tencode == do_t_branch23
23392 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23393 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23394 return TRUE;
23395
23396 /* Wide-only instruction added to ARMv8-M Baseline. */
23397 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
23398 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23399 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23400 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23401 return TRUE;
23402
23403 return FALSE;
23404 }
23405
23406 /* Whether wide instruction variant can be used if available for a valid OPCODE
23407 in ARCH. */
23408
23409 static bfd_boolean
23410 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23411 {
23412 if (known_t32_only_insn (opcode))
23413 return TRUE;
23414
23415 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23416 of variant T3 of B.W is checked in do_t_branch. */
23417 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23418 && opcode->tencode == do_t_branch)
23419 return TRUE;
23420
23421 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23422 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23423 && opcode->tencode == do_t_mov_cmp
23424 /* Make sure CMP instruction is not affected. */
23425 && opcode->aencode == do_mov)
23426 return TRUE;
23427
23428 /* Wide instruction variants of all instructions with narrow *and* wide
23429 variants become available with ARMv6t2. Other opcodes are either
23430 narrow-only or wide-only and are thus available if OPCODE is valid. */
23431 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23432 return TRUE;
23433
23434 /* OPCODE with narrow only instruction variant or wide variant not
23435 available. */
23436 return FALSE;
23437 }
23438
23439 void
23440 md_assemble (char *str)
23441 {
23442 char *p = str;
23443 const struct asm_opcode * opcode;
23444
23445 /* Align the previous label if needed. */
23446 if (last_label_seen != NULL)
23447 {
23448 symbol_set_frag (last_label_seen, frag_now);
23449 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23450 S_SET_SEGMENT (last_label_seen, now_seg);
23451 }
23452
23453 memset (&inst, '\0', sizeof (inst));
23454 int r;
23455 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23456 inst.relocs[r].type = BFD_RELOC_UNUSED;
23457
23458 opcode = opcode_lookup (&p);
23459 if (!opcode)
23460 {
23461 /* It wasn't an instruction, but it might be a register alias of
23462 the form alias .req reg, or a Neon .dn/.qn directive. */
23463 if (! create_register_alias (str, p)
23464 && ! create_neon_reg_alias (str, p))
23465 as_bad (_("bad instruction `%s'"), str);
23466
23467 return;
23468 }
23469
23470 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
23471 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
23472
23473 /* The value which unconditional instructions should have in place of the
23474 condition field. */
23475 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
23476
23477 if (thumb_mode)
23478 {
23479 arm_feature_set variant;
23480
23481 variant = cpu_variant;
23482 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
23483 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23484 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
23485 /* Check that this instruction is supported for this CPU. */
23486 if (!opcode->tvariant
23487 || (thumb_mode == 1
23488 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
23489 {
23490 if (opcode->tencode == do_t_swi)
23491 as_bad (_("SVC is not permitted on this architecture"));
23492 else
23493 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
23494 return;
23495 }
23496 if (inst.cond != COND_ALWAYS && !unified_syntax
23497 && opcode->tencode != do_t_branch)
23498 {
23499 as_bad (_("Thumb does not support conditional execution"));
23500 return;
23501 }
23502
23503 /* Two things are addressed here:
23504 1) Implicit require narrow instructions on Thumb-1.
23505 This avoids relaxation accidentally introducing Thumb-2
23506 instructions.
23507 2) Reject wide instructions in non Thumb-2 cores.
23508
23509 Only instructions with narrow and wide variants need to be handled
23510 but selecting all non wide-only instructions is easier. */
23511 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
23512 && !t32_insn_ok (variant, opcode))
23513 {
23514 if (inst.size_req == 0)
23515 inst.size_req = 2;
23516 else if (inst.size_req == 4)
23517 {
23518 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23519 as_bad (_("selected processor does not support 32bit wide "
23520 "variant of instruction `%s'"), str);
23521 else
23522 as_bad (_("selected processor does not support `%s' in "
23523 "Thumb-2 mode"), str);
23524 return;
23525 }
23526 }
23527
23528 inst.instruction = opcode->tvalue;
23529
23530 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
23531 {
23532 /* Prepare the pred_insn_type for those encodings that don't set
23533 it. */
23534 it_fsm_pre_encode ();
23535
23536 opcode->tencode ();
23537
23538 it_fsm_post_encode ();
23539 }
23540
23541 if (!(inst.error || inst.relax))
23542 {
23543 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
23544 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23545 if (inst.size_req && inst.size_req != inst.size)
23546 {
23547 as_bad (_("cannot honor width suffix -- `%s'"), str);
23548 return;
23549 }
23550 }
23551
23552 /* Something has gone badly wrong if we try to relax a fixed size
23553 instruction. */
23554 gas_assert (inst.size_req == 0 || !inst.relax);
23555
23556 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23557 *opcode->tvariant);
23558 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
23559 set those bits when Thumb-2 32-bit instructions are seen. The impact
23560 of relaxable instructions will be considered later after we finish all
23561 relaxation. */
23562 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23563 variant = arm_arch_none;
23564 else
23565 variant = cpu_variant;
23566 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
23567 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23568 arm_ext_v6t2);
23569
23570 check_neon_suffixes;
23571
23572 if (!inst.error)
23573 {
23574 mapping_state (MAP_THUMB);
23575 }
23576 }
23577 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23578 {
23579 bfd_boolean is_bx;
23580
23581 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23582 is_bx = (opcode->aencode == do_bx);
23583
23584 /* Check that this instruction is supported for this CPU. */
23585 if (!(is_bx && fix_v4bx)
23586 && !(opcode->avariant &&
23587 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
23588 {
23589 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
23590 return;
23591 }
23592 if (inst.size_req)
23593 {
23594 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23595 return;
23596 }
23597
23598 inst.instruction = opcode->avalue;
23599 if (opcode->tag == OT_unconditionalF)
23600 inst.instruction |= 0xFU << 28;
23601 else
23602 inst.instruction |= inst.cond << 28;
23603 inst.size = INSN_SIZE;
23604 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
23605 {
23606 it_fsm_pre_encode ();
23607 opcode->aencode ();
23608 it_fsm_post_encode ();
23609 }
23610 /* Arm mode bx is marked as both v4T and v5 because it's still required
23611 on a hypothetical non-thumb v5 core. */
23612 if (is_bx)
23613 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
23614 else
23615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23616 *opcode->avariant);
23617
23618 check_neon_suffixes;
23619
23620 if (!inst.error)
23621 {
23622 mapping_state (MAP_ARM);
23623 }
23624 }
23625 else
23626 {
23627 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23628 "-- `%s'"), str);
23629 return;
23630 }
23631 output_inst (str);
23632 }
23633
23634 static void
23635 check_pred_blocks_finished (void)
23636 {
23637 #ifdef OBJ_ELF
23638 asection *sect;
23639
23640 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
23641 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23642 == MANUAL_PRED_BLOCK)
23643 {
23644 if (now_pred.type == SCALAR_PRED)
23645 as_warn (_("section '%s' finished with an open IT block."),
23646 sect->name);
23647 else
23648 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23649 sect->name);
23650 }
23651 #else
23652 if (now_pred.state == MANUAL_PRED_BLOCK)
23653 {
23654 if (now_pred.type == SCALAR_PRED)
23655 as_warn (_("file finished with an open IT block."));
23656 else
23657 as_warn (_("file finished with an open VPT/VPST block."));
23658 }
23659 #endif
23660 }
23661
23662 /* Various frobbings of labels and their addresses. */
23663
23664 void
23665 arm_start_line_hook (void)
23666 {
23667 last_label_seen = NULL;
23668 }
23669
23670 void
23671 arm_frob_label (symbolS * sym)
23672 {
23673 last_label_seen = sym;
23674
23675 ARM_SET_THUMB (sym, thumb_mode);
23676
23677 #if defined OBJ_COFF || defined OBJ_ELF
23678 ARM_SET_INTERWORK (sym, support_interwork);
23679 #endif
23680
23681 force_automatic_it_block_close ();
23682
23683 /* Note - do not allow local symbols (.Lxxx) to be labelled
23684 as Thumb functions. This is because these labels, whilst
23685 they exist inside Thumb code, are not the entry points for
23686 possible ARM->Thumb calls. Also, these labels can be used
23687 as part of a computed goto or switch statement. eg gcc
23688 can generate code that looks like this:
23689
23690 ldr r2, [pc, .Laaa]
23691 lsl r3, r3, #2
23692 ldr r2, [r3, r2]
23693 mov pc, r2
23694
23695 .Lbbb: .word .Lxxx
23696 .Lccc: .word .Lyyy
23697 ..etc...
23698 .Laaa: .word Lbbb
23699
23700 The first instruction loads the address of the jump table.
23701 The second instruction converts a table index into a byte offset.
23702 The third instruction gets the jump address out of the table.
23703 The fourth instruction performs the jump.
23704
23705 If the address stored at .Laaa is that of a symbol which has the
23706 Thumb_Func bit set, then the linker will arrange for this address
23707 to have the bottom bit set, which in turn would mean that the
23708 address computation performed by the third instruction would end
23709 up with the bottom bit set. Since the ARM is capable of unaligned
23710 word loads, the instruction would then load the incorrect address
23711 out of the jump table, and chaos would ensue. */
23712 if (label_is_thumb_function_name
23713 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
23714 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
23715 {
23716 /* When the address of a Thumb function is taken the bottom
23717 bit of that address should be set. This will allow
23718 interworking between Arm and Thumb functions to work
23719 correctly. */
23720
23721 THUMB_SET_FUNC (sym, 1);
23722
23723 label_is_thumb_function_name = FALSE;
23724 }
23725
23726 dwarf2_emit_label (sym);
23727 }
23728
23729 bfd_boolean
23730 arm_data_in_code (void)
23731 {
23732 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
23733 {
23734 *input_line_pointer = '/';
23735 input_line_pointer += 5;
23736 *input_line_pointer = 0;
23737 return TRUE;
23738 }
23739
23740 return FALSE;
23741 }
23742
23743 char *
23744 arm_canonicalize_symbol_name (char * name)
23745 {
23746 int len;
23747
23748 if (thumb_mode && (len = strlen (name)) > 5
23749 && streq (name + len - 5, "/data"))
23750 *(name + len - 5) = 0;
23751
23752 return name;
23753 }
23754 \f
23755 /* Table of all register names defined by default. The user can
23756 define additional names with .req. Note that all register names
23757 should appear in both upper and lowercase variants. Some registers
23758 also have mixed-case names. */
23759
23760 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
23761 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
23762 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
23763 #define REGSET(p,t) \
23764 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23765 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23766 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23767 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
23768 #define REGSETH(p,t) \
23769 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23770 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23771 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23772 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23773 #define REGSET2(p,t) \
23774 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23775 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23776 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23777 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
23778 #define SPLRBANK(base,bank,t) \
23779 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23780 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23781 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23782 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23783 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23784 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
23785
23786 static const struct reg_entry reg_names[] =
23787 {
23788 /* ARM integer registers. */
23789 REGSET(r, RN), REGSET(R, RN),
23790
23791 /* ATPCS synonyms. */
23792 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23793 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23794 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
23795
23796 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23797 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23798 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
23799
23800 /* Well-known aliases. */
23801 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23802 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23803
23804 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23805 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23806
23807 /* Defining the new Zero register from ARMv8.1-M. */
23808 REGDEF(zr,15,ZR),
23809 REGDEF(ZR,15,ZR),
23810
23811 /* Coprocessor numbers. */
23812 REGSET(p, CP), REGSET(P, CP),
23813
23814 /* Coprocessor register numbers. The "cr" variants are for backward
23815 compatibility. */
23816 REGSET(c, CN), REGSET(C, CN),
23817 REGSET(cr, CN), REGSET(CR, CN),
23818
23819 /* ARM banked registers. */
23820 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23821 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23822 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23823 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23824 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23825 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23826 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23827
23828 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23829 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23830 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23831 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23832 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
23833 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
23834 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23835 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23836
23837 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23838 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23839 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23840 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23841 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23842 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23843 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
23844 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
23845 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23846
23847 /* FPA registers. */
23848 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23849 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23850
23851 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23852 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23853
23854 /* VFP SP registers. */
23855 REGSET(s,VFS), REGSET(S,VFS),
23856 REGSETH(s,VFS), REGSETH(S,VFS),
23857
23858 /* VFP DP Registers. */
23859 REGSET(d,VFD), REGSET(D,VFD),
23860 /* Extra Neon DP registers. */
23861 REGSETH(d,VFD), REGSETH(D,VFD),
23862
23863 /* Neon QP registers. */
23864 REGSET2(q,NQ), REGSET2(Q,NQ),
23865
23866 /* VFP control registers. */
23867 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23868 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
23869 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23870 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23871 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23872 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
23873 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
23874 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23875 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23876 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23877 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
23878
23879 /* Maverick DSP coprocessor registers. */
23880 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23881 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23882
23883 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23884 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23885 REGDEF(dspsc,0,DSPSC),
23886
23887 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23888 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23889 REGDEF(DSPSC,0,DSPSC),
23890
23891 /* iWMMXt data registers - p0, c0-15. */
23892 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23893
23894 /* iWMMXt control registers - p1, c0-3. */
23895 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23896 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23897 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23898 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23899
23900 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23901 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23902 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23903 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23904 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23905
23906 /* XScale accumulator registers. */
23907 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23908 };
23909 #undef REGDEF
23910 #undef REGNUM
23911 #undef REGSET
23912
23913 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23914 within psr_required_here. */
23915 static const struct asm_psr psrs[] =
23916 {
23917 /* Backward compatibility notation. Note that "all" is no longer
23918 truly all possible PSR bits. */
23919 {"all", PSR_c | PSR_f},
23920 {"flg", PSR_f},
23921 {"ctl", PSR_c},
23922
23923 /* Individual flags. */
23924 {"f", PSR_f},
23925 {"c", PSR_c},
23926 {"x", PSR_x},
23927 {"s", PSR_s},
23928
23929 /* Combinations of flags. */
23930 {"fs", PSR_f | PSR_s},
23931 {"fx", PSR_f | PSR_x},
23932 {"fc", PSR_f | PSR_c},
23933 {"sf", PSR_s | PSR_f},
23934 {"sx", PSR_s | PSR_x},
23935 {"sc", PSR_s | PSR_c},
23936 {"xf", PSR_x | PSR_f},
23937 {"xs", PSR_x | PSR_s},
23938 {"xc", PSR_x | PSR_c},
23939 {"cf", PSR_c | PSR_f},
23940 {"cs", PSR_c | PSR_s},
23941 {"cx", PSR_c | PSR_x},
23942 {"fsx", PSR_f | PSR_s | PSR_x},
23943 {"fsc", PSR_f | PSR_s | PSR_c},
23944 {"fxs", PSR_f | PSR_x | PSR_s},
23945 {"fxc", PSR_f | PSR_x | PSR_c},
23946 {"fcs", PSR_f | PSR_c | PSR_s},
23947 {"fcx", PSR_f | PSR_c | PSR_x},
23948 {"sfx", PSR_s | PSR_f | PSR_x},
23949 {"sfc", PSR_s | PSR_f | PSR_c},
23950 {"sxf", PSR_s | PSR_x | PSR_f},
23951 {"sxc", PSR_s | PSR_x | PSR_c},
23952 {"scf", PSR_s | PSR_c | PSR_f},
23953 {"scx", PSR_s | PSR_c | PSR_x},
23954 {"xfs", PSR_x | PSR_f | PSR_s},
23955 {"xfc", PSR_x | PSR_f | PSR_c},
23956 {"xsf", PSR_x | PSR_s | PSR_f},
23957 {"xsc", PSR_x | PSR_s | PSR_c},
23958 {"xcf", PSR_x | PSR_c | PSR_f},
23959 {"xcs", PSR_x | PSR_c | PSR_s},
23960 {"cfs", PSR_c | PSR_f | PSR_s},
23961 {"cfx", PSR_c | PSR_f | PSR_x},
23962 {"csf", PSR_c | PSR_s | PSR_f},
23963 {"csx", PSR_c | PSR_s | PSR_x},
23964 {"cxf", PSR_c | PSR_x | PSR_f},
23965 {"cxs", PSR_c | PSR_x | PSR_s},
23966 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23967 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23968 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23969 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23970 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23971 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23972 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23973 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23974 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23975 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23976 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23977 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23978 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23979 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23980 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23981 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23982 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23983 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23984 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23985 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23986 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23987 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23988 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23989 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23990 };
23991
23992 /* Table of V7M psr names. */
23993 static const struct asm_psr v7m_psrs[] =
23994 {
23995 {"apsr", 0x0 }, {"APSR", 0x0 },
23996 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23997 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23998 {"psr", 0x3 }, {"PSR", 0x3 },
23999 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
24000 {"ipsr", 0x5 }, {"IPSR", 0x5 },
24001 {"epsr", 0x6 }, {"EPSR", 0x6 },
24002 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
24003 {"msp", 0x8 }, {"MSP", 0x8 },
24004 {"psp", 0x9 }, {"PSP", 0x9 },
24005 {"msplim", 0xa }, {"MSPLIM", 0xa },
24006 {"psplim", 0xb }, {"PSPLIM", 0xb },
24007 {"primask", 0x10}, {"PRIMASK", 0x10},
24008 {"basepri", 0x11}, {"BASEPRI", 0x11},
24009 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
24010 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
24011 {"control", 0x14}, {"CONTROL", 0x14},
24012 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
24013 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
24014 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24015 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24016 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24017 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24018 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24019 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24020 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
24021 };
24022
24023 /* Table of all shift-in-operand names. */
24024 static const struct asm_shift_name shift_names [] =
24025 {
24026 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24027 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24028 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24029 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24030 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
24031 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24032 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
24033 };
24034
24035 /* Table of all explicit relocation names. */
24036 #ifdef OBJ_ELF
24037 static struct reloc_entry reloc_names[] =
24038 {
24039 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24040 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24041 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24042 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24043 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24044 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24045 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24046 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24047 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24048 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
24049 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
24050 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24051 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
24052 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
24053 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
24054 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
24055 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
24056 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24057 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24058 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24059 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24060 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24061 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
24062 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24063 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24064 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24065 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
24066 };
24067 #endif
24068
24069 /* Table of all conditional affixes. */
24070 static const struct asm_cond conds[] =
24071 {
24072 {"eq", 0x0},
24073 {"ne", 0x1},
24074 {"cs", 0x2}, {"hs", 0x2},
24075 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24076 {"mi", 0x4},
24077 {"pl", 0x5},
24078 {"vs", 0x6},
24079 {"vc", 0x7},
24080 {"hi", 0x8},
24081 {"ls", 0x9},
24082 {"ge", 0xa},
24083 {"lt", 0xb},
24084 {"gt", 0xc},
24085 {"le", 0xd},
24086 {"al", 0xe}
24087 };
24088 static const struct asm_cond vconds[] =
24089 {
24090 {"t", 0xf},
24091 {"e", 0x10}
24092 };
24093
24094 #define UL_BARRIER(L,U,CODE,FEAT) \
24095 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24096 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
24097
24098 static struct asm_barrier_opt barrier_opt_names[] =
24099 {
24100 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24101 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24102 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24103 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24104 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24105 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24106 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24107 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24108 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24109 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24110 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24111 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24112 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24113 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24114 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24115 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
24116 };
24117
24118 #undef UL_BARRIER
24119
24120 /* Table of ARM-format instructions. */
24121
24122 /* Macros for gluing together operand strings. N.B. In all cases
24123 other than OPS0, the trailing OP_stop comes from default
24124 zero-initialization of the unspecified elements of the array. */
24125 #define OPS0() { OP_stop, }
24126 #define OPS1(a) { OP_##a, }
24127 #define OPS2(a,b) { OP_##a,OP_##b, }
24128 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24129 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24130 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24131 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24132
24133 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24134 This is useful when mixing operands for ARM and THUMB, i.e. using the
24135 MIX_ARM_THUMB_OPERANDS macro.
24136 In order to use these macros, prefix the number of operands with _
24137 e.g. _3. */
24138 #define OPS_1(a) { a, }
24139 #define OPS_2(a,b) { a,b, }
24140 #define OPS_3(a,b,c) { a,b,c, }
24141 #define OPS_4(a,b,c,d) { a,b,c,d, }
24142 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24143 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24144
24145 /* These macros abstract out the exact format of the mnemonic table and
24146 save some repeated characters. */
24147
24148 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24149 #define TxCE(mnem, op, top, nops, ops, ae, te) \
24150 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
24151 THUMB_VARIANT, do_##ae, do_##te, 0 }
24152
24153 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24154 a T_MNEM_xyz enumerator. */
24155 #define TCE(mnem, aop, top, nops, ops, ae, te) \
24156 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
24157 #define tCE(mnem, aop, top, nops, ops, ae, te) \
24158 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24159
24160 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24161 infix after the third character. */
24162 #define TxC3(mnem, op, top, nops, ops, ae, te) \
24163 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
24164 THUMB_VARIANT, do_##ae, do_##te, 0 }
24165 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
24166 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
24167 THUMB_VARIANT, do_##ae, do_##te, 0 }
24168 #define TC3(mnem, aop, top, nops, ops, ae, te) \
24169 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
24170 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
24171 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
24172 #define tC3(mnem, aop, top, nops, ops, ae, te) \
24173 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24174 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
24175 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24176
24177 /* Mnemonic that cannot be conditionalized. The ARM condition-code
24178 field is still 0xE. Many of the Thumb variants can be executed
24179 conditionally, so this is checked separately. */
24180 #define TUE(mnem, op, top, nops, ops, ae, te) \
24181 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24182 THUMB_VARIANT, do_##ae, do_##te, 0 }
24183
24184 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24185 Used by mnemonics that have very minimal differences in the encoding for
24186 ARM and Thumb variants and can be handled in a common function. */
24187 #define TUEc(mnem, op, top, nops, ops, en) \
24188 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24189 THUMB_VARIANT, do_##en, do_##en, 0 }
24190
24191 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24192 condition code field. */
24193 #define TUF(mnem, op, top, nops, ops, ae, te) \
24194 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
24195 THUMB_VARIANT, do_##ae, do_##te, 0 }
24196
24197 /* ARM-only variants of all the above. */
24198 #define CE(mnem, op, nops, ops, ae) \
24199 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24200
24201 #define C3(mnem, op, nops, ops, ae) \
24202 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24203
24204 /* Thumb-only variants of TCE and TUE. */
24205 #define ToC(mnem, top, nops, ops, te) \
24206 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24207 do_##te, 0 }
24208
24209 #define ToU(mnem, top, nops, ops, te) \
24210 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
24211 NULL, do_##te, 0 }
24212
24213 /* T_MNEM_xyz enumerator variants of ToC. */
24214 #define toC(mnem, top, nops, ops, te) \
24215 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
24216 do_##te, 0 }
24217
24218 /* T_MNEM_xyz enumerator variants of ToU. */
24219 #define toU(mnem, top, nops, ops, te) \
24220 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
24221 NULL, do_##te, 0 }
24222
24223 /* Legacy mnemonics that always have conditional infix after the third
24224 character. */
24225 #define CL(mnem, op, nops, ops, ae) \
24226 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24227 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24228
24229 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24230 #define cCE(mnem, op, nops, ops, ae) \
24231 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24232
24233 /* mov instructions that are shared between coprocessor and MVE. */
24234 #define mcCE(mnem, op, nops, ops, ae) \
24235 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24236
24237 /* Legacy coprocessor instructions where conditional infix and conditional
24238 suffix are ambiguous. For consistency this includes all FPA instructions,
24239 not just the potentially ambiguous ones. */
24240 #define cCL(mnem, op, nops, ops, ae) \
24241 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24242 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24243
24244 /* Coprocessor, takes either a suffix or a position-3 infix
24245 (for an FPA corner case). */
24246 #define C3E(mnem, op, nops, ops, ae) \
24247 { mnem, OPS##nops ops, OT_csuf_or_in3, \
24248 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24249
24250 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
24251 { m1 #m2 m3, OPS##nops ops, \
24252 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
24253 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24254
24255 #define CM(m1, m2, op, nops, ops, ae) \
24256 xCM_ (m1, , m2, op, nops, ops, ae), \
24257 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24258 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24259 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24260 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24261 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24262 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24263 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24264 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24265 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24266 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24267 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24268 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24269 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24270 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24271 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24272 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24273 xCM_ (m1, le, m2, op, nops, ops, ae), \
24274 xCM_ (m1, al, m2, op, nops, ops, ae)
24275
24276 #define UE(mnem, op, nops, ops, ae) \
24277 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24278
24279 #define UF(mnem, op, nops, ops, ae) \
24280 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24281
24282 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
24283 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24284 use the same encoding function for each. */
24285 #define NUF(mnem, op, nops, ops, enc) \
24286 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24287 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24288
24289 /* Neon data processing, version which indirects through neon_enc_tab for
24290 the various overloaded versions of opcodes. */
24291 #define nUF(mnem, op, nops, ops, enc) \
24292 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24293 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24294
24295 /* Neon insn with conditional suffix for the ARM version, non-overloaded
24296 version. */
24297 #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24298 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
24299 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24300
24301 #define NCE(mnem, op, nops, ops, enc) \
24302 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24303
24304 #define NCEF(mnem, op, nops, ops, enc) \
24305 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24306
24307 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
24308 #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24309 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
24310 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24311
24312 #define nCE(mnem, op, nops, ops, enc) \
24313 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24314
24315 #define nCEF(mnem, op, nops, ops, enc) \
24316 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24317
24318 /* */
24319 #define mCEF(mnem, op, nops, ops, enc) \
24320 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
24321 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24322
24323
24324 /* nCEF but for MVE predicated instructions. */
24325 #define mnCEF(mnem, op, nops, ops, enc) \
24326 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24327
24328 /* nCE but for MVE predicated instructions. */
24329 #define mnCE(mnem, op, nops, ops, enc) \
24330 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24331
24332 /* NUF but for potentially MVE predicated instructions. */
24333 #define MNUF(mnem, op, nops, ops, enc) \
24334 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24335 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24336
24337 /* nUF but for potentially MVE predicated instructions. */
24338 #define mnUF(mnem, op, nops, ops, enc) \
24339 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24340 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24341
24342 /* ToC but for potentially MVE predicated instructions. */
24343 #define mToC(mnem, top, nops, ops, te) \
24344 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24345 do_##te, 1 }
24346
24347 /* NCE but for MVE predicated instructions. */
24348 #define MNCE(mnem, op, nops, ops, enc) \
24349 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24350
24351 /* NCEF but for MVE predicated instructions. */
24352 #define MNCEF(mnem, op, nops, ops, enc) \
24353 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24354 #define do_0 0
24355
24356 static const struct asm_opcode insns[] =
24357 {
24358 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24359 #define THUMB_VARIANT & arm_ext_v4t
24360 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24361 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24362 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24363 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24364 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24365 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24366 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24367 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24368 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24369 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24370 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24371 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24372 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24373 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24374 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24375 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
24376
24377 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24378 for setting PSR flag bits. They are obsolete in V6 and do not
24379 have Thumb equivalents. */
24380 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24381 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24382 CL("tstp", 110f000, 2, (RR, SH), cmp),
24383 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24384 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24385 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24386 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24387 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24388 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24389
24390 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
24391 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
24392 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24393 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24394
24395 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
24396 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24397 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24398 OP_RRnpc),
24399 OP_ADDRGLDR),ldst, t_ldst),
24400 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24401
24402 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24403 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24404 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24405 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24406 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24407 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24408
24409 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24410 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
24411
24412 /* Pseudo ops. */
24413 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
24414 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
24415 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
24416 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
24417
24418 /* Thumb-compatibility pseudo ops. */
24419 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24420 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24421 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24422 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24423 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24424 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24425 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24426 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24427 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24428 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24429 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24430 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
24431
24432 /* These may simplify to neg. */
24433 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24434 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
24435
24436 #undef THUMB_VARIANT
24437 #define THUMB_VARIANT & arm_ext_os
24438
24439 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24440 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24441
24442 #undef THUMB_VARIANT
24443 #define THUMB_VARIANT & arm_ext_v6
24444
24445 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
24446
24447 /* V1 instructions with no Thumb analogue prior to V6T2. */
24448 #undef THUMB_VARIANT
24449 #define THUMB_VARIANT & arm_ext_v6t2
24450
24451 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24452 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24453 CL("teqp", 130f000, 2, (RR, SH), cmp),
24454
24455 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24456 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24457 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24458 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24459
24460 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24461 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24462
24463 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24464 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24465
24466 /* V1 instructions with no Thumb analogue at all. */
24467 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
24468 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24469
24470 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24471 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24472 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24473 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24474 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24475 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24476 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24477 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24478
24479 #undef ARM_VARIANT
24480 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24481 #undef THUMB_VARIANT
24482 #define THUMB_VARIANT & arm_ext_v4t
24483
24484 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24485 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24486
24487 #undef THUMB_VARIANT
24488 #define THUMB_VARIANT & arm_ext_v6t2
24489
24490 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24491 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24492
24493 /* Generic coprocessor instructions. */
24494 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24495 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24496 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24497 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24498 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24499 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24500 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
24501
24502 #undef ARM_VARIANT
24503 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24504
24505 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24506 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24507
24508 #undef ARM_VARIANT
24509 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24510 #undef THUMB_VARIANT
24511 #define THUMB_VARIANT & arm_ext_msr
24512
24513 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24514 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
24515
24516 #undef ARM_VARIANT
24517 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24518 #undef THUMB_VARIANT
24519 #define THUMB_VARIANT & arm_ext_v6t2
24520
24521 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24522 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24523 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24524 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24525 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24526 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24527 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24528 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24529
24530 #undef ARM_VARIANT
24531 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24532 #undef THUMB_VARIANT
24533 #define THUMB_VARIANT & arm_ext_v4t
24534
24535 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24536 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24537 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24538 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24539 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24540 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24541
24542 #undef ARM_VARIANT
24543 #define ARM_VARIANT & arm_ext_v4t_5
24544
24545 /* ARM Architecture 4T. */
24546 /* Note: bx (and blx) are required on V5, even if the processor does
24547 not support Thumb. */
24548 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
24549
24550 #undef ARM_VARIANT
24551 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24552 #undef THUMB_VARIANT
24553 #define THUMB_VARIANT & arm_ext_v5t
24554
24555 /* Note: blx has 2 variants; the .value coded here is for
24556 BLX(2). Only this variant has conditional execution. */
24557 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24558 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
24559
24560 #undef THUMB_VARIANT
24561 #define THUMB_VARIANT & arm_ext_v6t2
24562
24563 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24564 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24565 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24566 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24567 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24568 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24569 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24570 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24571
24572 #undef ARM_VARIANT
24573 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24574 #undef THUMB_VARIANT
24575 #define THUMB_VARIANT & arm_ext_v5exp
24576
24577 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24578 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24579 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24580 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24581
24582 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24583 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24584
24585 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24586 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24587 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24588 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24589
24590 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24591 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24592 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24593 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24594
24595 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24596 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24597
24598 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24599 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24600 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24601 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24602
24603 #undef ARM_VARIANT
24604 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24605 #undef THUMB_VARIANT
24606 #define THUMB_VARIANT & arm_ext_v6t2
24607
24608 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
24609 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24610 ldrd, t_ldstd),
24611 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24612 ADDRGLDRS), ldrd, t_ldstd),
24613
24614 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24615 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24616
24617 #undef ARM_VARIANT
24618 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24619
24620 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
24621
24622 #undef ARM_VARIANT
24623 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24624 #undef THUMB_VARIANT
24625 #define THUMB_VARIANT & arm_ext_v6
24626
24627 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24628 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24629 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24630 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24631 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24632 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24633 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24634 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24635 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24636 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
24637
24638 #undef THUMB_VARIANT
24639 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24640
24641 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24642 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24643 strex, t_strex),
24644 #undef THUMB_VARIANT
24645 #define THUMB_VARIANT & arm_ext_v6t2
24646
24647 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24648 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24649
24650 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24651 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
24652
24653 /* ARM V6 not included in V7M. */
24654 #undef THUMB_VARIANT
24655 #define THUMB_VARIANT & arm_ext_v6_notm
24656 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24657 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24658 UF(rfeib, 9900a00, 1, (RRw), rfe),
24659 UF(rfeda, 8100a00, 1, (RRw), rfe),
24660 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24661 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24662 UF(rfefa, 8100a00, 1, (RRw), rfe),
24663 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24664 UF(rfeed, 9900a00, 1, (RRw), rfe),
24665 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24666 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24667 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24668 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
24669 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
24670 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
24671 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
24672 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24673 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24674 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
24675
24676 /* ARM V6 not included in V7M (eg. integer SIMD). */
24677 #undef THUMB_VARIANT
24678 #define THUMB_VARIANT & arm_ext_v6_dsp
24679 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24680 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24681 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24682 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24683 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24684 /* Old name for QASX. */
24685 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24686 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24687 /* Old name for QSAX. */
24688 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24689 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24690 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24691 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24692 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24693 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24694 /* Old name for SASX. */
24695 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24696 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24697 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24698 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24699 /* Old name for SHASX. */
24700 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24701 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24702 /* Old name for SHSAX. */
24703 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24704 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24705 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24706 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24707 /* Old name for SSAX. */
24708 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24709 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24710 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24711 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24712 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24713 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24714 /* Old name for UASX. */
24715 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24716 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24717 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24718 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24719 /* Old name for UHASX. */
24720 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24721 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24722 /* Old name for UHSAX. */
24723 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24724 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24725 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24726 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24727 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24728 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24729 /* Old name for UQASX. */
24730 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24731 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24732 /* Old name for UQSAX. */
24733 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24734 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24735 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24736 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24737 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24738 /* Old name for USAX. */
24739 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24740 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24741 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24742 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24743 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24744 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24745 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24746 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24747 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24748 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24749 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24750 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24751 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24752 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24753 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24754 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24755 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24756 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24757 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24758 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24759 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24760 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24761 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24762 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24763 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24764 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24765 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24766 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24767 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24768 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24769 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24770 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24771 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24772 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
24773
24774 #undef ARM_VARIANT
24775 #define ARM_VARIANT & arm_ext_v6k_v6t2
24776 #undef THUMB_VARIANT
24777 #define THUMB_VARIANT & arm_ext_v6k_v6t2
24778
24779 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24780 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24781 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24782 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
24783
24784 #undef THUMB_VARIANT
24785 #define THUMB_VARIANT & arm_ext_v6_notm
24786 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24787 ldrexd, t_ldrexd),
24788 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24789 RRnpcb), strexd, t_strexd),
24790
24791 #undef THUMB_VARIANT
24792 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24793 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24794 rd_rn, rd_rn),
24795 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24796 rd_rn, rd_rn),
24797 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24798 strex, t_strexbh),
24799 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24800 strex, t_strexbh),
24801 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
24802
24803 #undef ARM_VARIANT
24804 #define ARM_VARIANT & arm_ext_sec
24805 #undef THUMB_VARIANT
24806 #define THUMB_VARIANT & arm_ext_sec
24807
24808 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
24809
24810 #undef ARM_VARIANT
24811 #define ARM_VARIANT & arm_ext_virt
24812 #undef THUMB_VARIANT
24813 #define THUMB_VARIANT & arm_ext_virt
24814
24815 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24816 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24817
24818 #undef ARM_VARIANT
24819 #define ARM_VARIANT & arm_ext_pan
24820 #undef THUMB_VARIANT
24821 #define THUMB_VARIANT & arm_ext_pan
24822
24823 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24824
24825 #undef ARM_VARIANT
24826 #define ARM_VARIANT & arm_ext_v6t2
24827 #undef THUMB_VARIANT
24828 #define THUMB_VARIANT & arm_ext_v6t2
24829
24830 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24831 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24832 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24833 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24834
24835 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24836 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
24837
24838 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24839 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24840 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24841 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24842
24843 #undef ARM_VARIANT
24844 #define ARM_VARIANT & arm_ext_v3
24845 #undef THUMB_VARIANT
24846 #define THUMB_VARIANT & arm_ext_v6t2
24847
24848 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
24849 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24850 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
24851
24852 #undef ARM_VARIANT
24853 #define ARM_VARIANT & arm_ext_v6t2
24854 #undef THUMB_VARIANT
24855 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24856 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24857 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24858
24859 /* Thumb-only instructions. */
24860 #undef ARM_VARIANT
24861 #define ARM_VARIANT NULL
24862 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24863 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
24864
24865 /* ARM does not really have an IT instruction, so always allow it.
24866 The opcode is copied from Thumb in order to allow warnings in
24867 -mimplicit-it=[never | arm] modes. */
24868 #undef ARM_VARIANT
24869 #define ARM_VARIANT & arm_ext_v1
24870 #undef THUMB_VARIANT
24871 #define THUMB_VARIANT & arm_ext_v6t2
24872
24873 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24874 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24875 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24876 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24877 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24878 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24879 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24880 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24881 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24882 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24883 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24884 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24885 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24886 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24887 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
24888 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
24889 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24890 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
24891
24892 /* Thumb2 only instructions. */
24893 #undef ARM_VARIANT
24894 #define ARM_VARIANT NULL
24895
24896 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24897 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24898 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24899 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24900 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24901 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
24902
24903 /* Hardware division instructions. */
24904 #undef ARM_VARIANT
24905 #define ARM_VARIANT & arm_ext_adiv
24906 #undef THUMB_VARIANT
24907 #define THUMB_VARIANT & arm_ext_div
24908
24909 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24910 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
24911
24912 /* ARM V6M/V7 instructions. */
24913 #undef ARM_VARIANT
24914 #define ARM_VARIANT & arm_ext_barrier
24915 #undef THUMB_VARIANT
24916 #define THUMB_VARIANT & arm_ext_barrier
24917
24918 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24919 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24920 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
24921
24922 /* ARM V7 instructions. */
24923 #undef ARM_VARIANT
24924 #define ARM_VARIANT & arm_ext_v7
24925 #undef THUMB_VARIANT
24926 #define THUMB_VARIANT & arm_ext_v7
24927
24928 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24929 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
24930
24931 #undef ARM_VARIANT
24932 #define ARM_VARIANT & arm_ext_mp
24933 #undef THUMB_VARIANT
24934 #define THUMB_VARIANT & arm_ext_mp
24935
24936 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24937
24938 /* AArchv8 instructions. */
24939 #undef ARM_VARIANT
24940 #define ARM_VARIANT & arm_ext_v8
24941
24942 /* Instructions shared between armv8-a and armv8-m. */
24943 #undef THUMB_VARIANT
24944 #define THUMB_VARIANT & arm_ext_atomics
24945
24946 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24947 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24948 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24949 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24950 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24951 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24952 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24953 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24954 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24955 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24956 stlex, t_stlex),
24957 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24958 stlex, t_stlex),
24959 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24960 stlex, t_stlex),
24961 #undef THUMB_VARIANT
24962 #define THUMB_VARIANT & arm_ext_v8
24963
24964 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
24965 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24966 ldrexd, t_ldrexd),
24967 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24968 strexd, t_strexd),
24969
24970 /* Defined in V8 but is in undefined encoding space for earlier
24971 architectures. However earlier architectures are required to treat
24972 this instuction as a semihosting trap as well. Hence while not explicitly
24973 defined as such, it is in fact correct to define the instruction for all
24974 architectures. */
24975 #undef THUMB_VARIANT
24976 #define THUMB_VARIANT & arm_ext_v1
24977 #undef ARM_VARIANT
24978 #define ARM_VARIANT & arm_ext_v1
24979 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24980
24981 /* ARMv8 T32 only. */
24982 #undef ARM_VARIANT
24983 #define ARM_VARIANT NULL
24984 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24985 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24986 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24987
24988 /* FP for ARMv8. */
24989 #undef ARM_VARIANT
24990 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
24991 #undef THUMB_VARIANT
24992 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
24993
24994 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24995 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24996 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24997 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
24998 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
24999 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
25000 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
25001 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
25002 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
25003 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
25004 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
25005
25006 /* Crypto v1 extensions. */
25007 #undef ARM_VARIANT
25008 #define ARM_VARIANT & fpu_crypto_ext_armv8
25009 #undef THUMB_VARIANT
25010 #define THUMB_VARIANT & fpu_crypto_ext_armv8
25011
25012 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
25013 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
25014 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25015 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
25016 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25017 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25018 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25019 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25020 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25021 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25022 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
25023 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25024 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25025 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
25026
25027 #undef ARM_VARIANT
25028 #define ARM_VARIANT & arm_ext_crc
25029 #undef THUMB_VARIANT
25030 #define THUMB_VARIANT & arm_ext_crc
25031 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25032 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25033 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25034 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25035 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25036 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25037
25038 /* ARMv8.2 RAS extension. */
25039 #undef ARM_VARIANT
25040 #define ARM_VARIANT & arm_ext_ras
25041 #undef THUMB_VARIANT
25042 #define THUMB_VARIANT & arm_ext_ras
25043 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25044
25045 #undef ARM_VARIANT
25046 #define ARM_VARIANT & arm_ext_v8_3
25047 #undef THUMB_VARIANT
25048 #define THUMB_VARIANT & arm_ext_v8_3
25049 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25050
25051 #undef ARM_VARIANT
25052 #define ARM_VARIANT & fpu_neon_ext_dotprod
25053 #undef THUMB_VARIANT
25054 #define THUMB_VARIANT & fpu_neon_ext_dotprod
25055 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25056 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25057
25058 #undef ARM_VARIANT
25059 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
25060 #undef THUMB_VARIANT
25061 #define THUMB_VARIANT NULL
25062
25063 cCE("wfs", e200110, 1, (RR), rd),
25064 cCE("rfs", e300110, 1, (RR), rd),
25065 cCE("wfc", e400110, 1, (RR), rd),
25066 cCE("rfc", e500110, 1, (RR), rd),
25067
25068 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25069 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25070 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25071 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25072
25073 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25074 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25075 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25076 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25077
25078 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25079 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25080 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25081 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25082 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25083 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25084 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25085 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25086 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25087 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25088 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25089 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25090
25091 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25092 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25093 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25094 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25095 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25096 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25097 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25098 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25099 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25100 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25101 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25102 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25103
25104 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25105 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25106 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25107 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25108 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25109 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25110 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25111 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25112 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25113 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25114 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25115 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25116
25117 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25118 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25119 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25120 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25121 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25122 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25123 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25124 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25125 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25126 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25127 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25128 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25129
25130 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25131 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25132 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25133 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25134 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25135 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25136 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25137 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25138 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25139 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25140 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25141 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25142
25143 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25144 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25145 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25146 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25147 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25148 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25149 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25150 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25151 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25152 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25153 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25154 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25155
25156 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25157 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25158 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25159 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25160 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25161 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25162 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25163 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25164 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25165 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25166 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25167 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25168
25169 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25170 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25171 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25172 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25173 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25174 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25175 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25176 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25177 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25178 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25179 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25180 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25181
25182 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25183 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25184 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25185 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25186 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25187 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25188 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25189 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25190 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25191 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25192 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25193 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25194
25195 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25196 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25197 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25198 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25199 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25200 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25201 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25202 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25203 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25204 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25205 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25206 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25207
25208 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25209 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25210 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25211 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25212 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25213 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25214 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25215 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25216 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25217 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25218 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25219 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25220
25221 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25222 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25223 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25224 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25225 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25226 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25227 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25228 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25229 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25230 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25231 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25232 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25233
25234 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25235 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25236 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25237 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25238 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25239 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25240 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25241 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25242 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25243 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25244 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25245 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25246
25247 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25248 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25249 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25250 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25251 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25252 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25253 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25254 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25255 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25256 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25257 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25258 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25259
25260 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25261 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25262 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25263 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25264 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25265 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25266 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25267 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25268 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25269 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25270 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25271 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25272
25273 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25274 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25275 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25276 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25277 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25278 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25279 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25280 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25281 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25282 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25283 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25284 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25285
25286 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25287 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25288 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25289 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25290 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25291 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25292 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25293 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25294 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25295 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25296 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25297 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25298
25299 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25300 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25301 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25302 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25303 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25304 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25305 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25308 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25309 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25310 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25311
25312 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25315 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25316 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25317 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25318 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25321 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25322 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25323 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25324
25325 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25328 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25329 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25330 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25331 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25334 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25335 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25336 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25337
25338 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25341 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25342 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25343 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25344 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25347 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25348 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25349 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25350
25351 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25354 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25355 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25356 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25357 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25360 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25361 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25362 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25363
25364 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25367 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25368 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25369 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25370 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25373 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25374 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25375 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25376
25377 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25380 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25381 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25382 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25383 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25386 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25387 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25388 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25389
25390 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25393 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25394 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25395 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25396 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25399 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25400 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25401 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25402
25403 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25406 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25407 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25408 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25409 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25412 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25413 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25414 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25415
25416 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25419 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25420 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25421 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25422 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25425 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25426 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25427 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25428
25429 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25432 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25433 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25434 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25435 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25438 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25439 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25440 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25441
25442 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25443 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25444 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25445 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25446 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25447 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25448 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25449 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25450 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25451 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25452 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25453 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25454
25455 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25456 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25457 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25458 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25459
25460 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25461 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25462 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25463 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25464 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25465 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25466 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25467 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25468 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25469 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25470 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25471 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
25472
25473 /* The implementation of the FIX instruction is broken on some
25474 assemblers, in that it accepts a precision specifier as well as a
25475 rounding specifier, despite the fact that this is meaningless.
25476 To be more compatible, we accept it as well, though of course it
25477 does not set any bits. */
25478 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25479 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25480 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25481 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25482 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25483 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25484 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25485 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25486 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25487 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25488 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25489 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25490 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
25491
25492 /* Instructions that were new with the real FPA, call them V2. */
25493 #undef ARM_VARIANT
25494 #define ARM_VARIANT & fpu_fpa_ext_v2
25495
25496 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25497 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25498 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25499 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25500 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25501 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25502
25503 #undef ARM_VARIANT
25504 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
25505 #undef THUMB_VARIANT
25506 #define THUMB_VARIANT & arm_ext_v6t2
25507 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25508 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
25509 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25510 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25511 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25512 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25513
25514 /* Memory operations. */
25515 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25516 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25517 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25518 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25519 #undef THUMB_VARIANT
25520
25521 /* Moves and type conversions. */
25522 cCE("fmstat", ef1fa10, 0, (), noargs),
25523 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25524 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25525 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25526 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25527 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25528 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25529 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25530 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
25531
25532 /* Memory operations. */
25533 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25534 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25535 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25536 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25537 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25538 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25539 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25540 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25541 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25542 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25543 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25544 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25545
25546 /* Monadic operations. */
25547 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25548 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25549 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
25550
25551 /* Dyadic operations. */
25552 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25553 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25554 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25555 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25556 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25557 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25558 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25559 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25560 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25561
25562 /* Comparisons. */
25563 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25564 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25565 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25566 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
25567
25568 /* Double precision load/store are still present on single precision
25569 implementations. */
25570 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25571 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25572 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25573 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25574 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25575 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25576 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25577 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25578
25579 #undef ARM_VARIANT
25580 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25581
25582 /* Moves and type conversions. */
25583 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25584 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25585 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25586 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25587 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25588 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25589 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25590 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25591 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25592 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25593 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25594 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25595
25596 /* Monadic operations. */
25597 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25598 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25599 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25600
25601 /* Dyadic operations. */
25602 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25603 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25604 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25605 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25606 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25607 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25608 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25609 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25610 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25611
25612 /* Comparisons. */
25613 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25614 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25615 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25616 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
25617
25618 /* Instructions which may belong to either the Neon or VFP instruction sets.
25619 Individual encoder functions perform additional architecture checks. */
25620 #undef ARM_VARIANT
25621 #define ARM_VARIANT & fpu_vfp_ext_v1xd
25622 #undef THUMB_VARIANT
25623 #define THUMB_VARIANT & arm_ext_v6t2
25624
25625 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25626 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25627 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25628 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25629 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25630 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25631
25632 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25633 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25634
25635 #undef THUMB_VARIANT
25636 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
25637
25638 /* These mnemonics are unique to VFP. */
25639 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25640 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
25641 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25642 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25643 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25644 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25645
25646 /* Mnemonics shared by Neon and VFP. */
25647 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
25648
25649 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
25650 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
25651 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25652 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
25653
25654
25655 /* NOTE: All VMOV encoding is special-cased! */
25656 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25657
25658 #undef THUMB_VARIANT
25659 /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25660 by different feature bits. Since we are setting the Thumb guard, we can
25661 require Thumb-1 which makes it a nop guard and set the right feature bit in
25662 do_vldr_vstr (). */
25663 #define THUMB_VARIANT & arm_ext_v4t
25664 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25665 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25666
25667 #undef ARM_VARIANT
25668 #define ARM_VARIANT & arm_ext_fp16
25669 #undef THUMB_VARIANT
25670 #define THUMB_VARIANT & arm_ext_fp16
25671 /* New instructions added from v8.2, allowing the extraction and insertion of
25672 the upper 16 bits of a 32-bit vector register. */
25673 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25674 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25675
25676 /* New backported fma/fms instructions optional in v8.2. */
25677 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25678 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
25679
25680 #undef THUMB_VARIANT
25681 #define THUMB_VARIANT & fpu_neon_ext_v1
25682 #undef ARM_VARIANT
25683 #define ARM_VARIANT & fpu_neon_ext_v1
25684
25685 /* Data processing with three registers of the same length. */
25686 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25687 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25688 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
25689 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25690 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25691 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25692 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
25693 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25694 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25695 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25696 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25697 /* If not immediate, fall back to neon_dyadic_i64_su.
25698 shl should accept I8 I16 I32 I64,
25699 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25700 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25701 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
25702 /* Logic ops, types optional & ignored. */
25703 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25704 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25705 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25706 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25707 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
25708 /* Bitfield ops, untyped. */
25709 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25710 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25711 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25712 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25713 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25714 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25715 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
25716 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25717 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25718 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25719 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25720 back to neon_dyadic_if_su. */
25721 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25722 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25723 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25724 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25725 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25726 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25727 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25728 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25729 /* Comparison. Type I8 I16 I32 F32. */
25730 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25731 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
25732 /* As above, D registers only. */
25733 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25734 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25735 /* Int and float variants, signedness unimportant. */
25736 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25737 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25738 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
25739 /* Add/sub take types I8 I16 I32 I64 F32. */
25740 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25741 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25742 /* vtst takes sizes 8, 16, 32. */
25743 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25744 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25745 /* VMUL takes I8 I16 I32 F32 P8. */
25746 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
25747 /* VQD{R}MULH takes S16 S32. */
25748 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25749 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25750 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25751 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25752 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25753 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25754 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25755 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25756 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25757 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25758 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25759 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25760 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25761 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25762 /* ARM v8.1 extension. */
25763 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25764 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25765 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25766
25767 /* Two address, int/float. Types S8 S16 S32 F32. */
25768 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
25769 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25770
25771 /* Data processing with two registers and a shift amount. */
25772 /* Right shifts, and variants with rounding.
25773 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
25774 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25775 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25776 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25777 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25778 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25779 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25780 /* Shift and insert. Sizes accepted 8 16 32 64. */
25781 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
25782 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25783 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
25784 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25785 /* Right shift immediate, saturating & narrowing, with rounding variants.
25786 Types accepted S16 S32 S64 U16 U32 U64. */
25787 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25788 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25789 /* As above, unsigned. Types accepted S16 S32 S64. */
25790 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25791 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25792 /* Right shift narrowing. Types accepted I16 I32 I64. */
25793 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25794 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25795 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
25796 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
25797 /* CVT with optional immediate for fixed-point variant. */
25798 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
25799
25800 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
25801
25802 /* Data processing, three registers of different lengths. */
25803 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25804 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
25805 /* If not scalar, fall back to neon_dyadic_long.
25806 Vector types as above, scalar types S16 S32 U16 U32. */
25807 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25808 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25809 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25810 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25811 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25812 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25813 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25814 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25815 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25816 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25817 /* Saturating doubling multiplies. Types S16 S32. */
25818 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25819 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25820 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25821 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25822 S16 S32 U16 U32. */
25823 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
25824
25825 /* Extract. Size 8. */
25826 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25827 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
25828
25829 /* Two registers, miscellaneous. */
25830 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
25831 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
25832 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
25833 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25834 /* Vector replicate. Sizes 8 16 32. */
25835 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
25836 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25837 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25838 /* VMOVN. Types I16 I32 I64. */
25839 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
25840 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
25841 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
25842 /* VQMOVUN. Types S16 S32 S64. */
25843 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
25844 /* VZIP / VUZP. Sizes 8 16 32. */
25845 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25846 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25847 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25848 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25849 /* VQABS / VQNEG. Types S8 S16 S32. */
25850 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
25851 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25852 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25853 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25854 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25855 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25856 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
25857 /* Reciprocal estimates. Types U32 F16 F32. */
25858 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25859 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25860 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25861 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25862 /* VCLS. Types S8 S16 S32. */
25863 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25864 /* VCLZ. Types I8 I16 I32. */
25865 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25866 /* VCNT. Size 8. */
25867 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25868 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25869 /* Two address, untyped. */
25870 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25871 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25872 /* VTRN. Sizes 8 16 32. */
25873 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25874 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
25875
25876 /* Table lookup. Size 8. */
25877 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25878 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25879
25880 #undef THUMB_VARIANT
25881 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25882 #undef ARM_VARIANT
25883 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25884
25885 /* Neon element/structure load/store. */
25886 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25887 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25888 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25889 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25890 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25891 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25892 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25893 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25894
25895 #undef THUMB_VARIANT
25896 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
25897 #undef ARM_VARIANT
25898 #define ARM_VARIANT & fpu_vfp_ext_v3xd
25899 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25900 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25901 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25902 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25903 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25904 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25905 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25906 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25907 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25908
25909 #undef THUMB_VARIANT
25910 #define THUMB_VARIANT & fpu_vfp_ext_v3
25911 #undef ARM_VARIANT
25912 #define ARM_VARIANT & fpu_vfp_ext_v3
25913
25914 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
25915 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25916 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25917 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25918 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25919 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25920 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25921 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25922 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25923
25924 #undef ARM_VARIANT
25925 #define ARM_VARIANT & fpu_vfp_ext_fma
25926 #undef THUMB_VARIANT
25927 #define THUMB_VARIANT & fpu_vfp_ext_fma
25928 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
25929 VFP FMA variant; NEON and VFP FMA always includes the NEON
25930 FMA instructions. */
25931 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
25932 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
25933 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25934
25935 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25936 the v form should always be used. */
25937 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25938 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25939 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25940 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25941 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25942 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25943
25944 #undef THUMB_VARIANT
25945 #undef ARM_VARIANT
25946 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25947
25948 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25949 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25950 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25951 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25952 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25953 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25954 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25955 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
25956
25957 #undef ARM_VARIANT
25958 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25959
25960 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25961 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25962 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25963 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25964 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25965 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25966 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25967 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25968 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
25969 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25970 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25971 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25972 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25973 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25974 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25975 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25976 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25977 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25978 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25979 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25980 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25981 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25982 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25983 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25984 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25985 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25986 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25987 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25988 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
25989 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25990 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25991 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25992 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25993 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25994 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25995 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25996 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25997 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25998 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25999 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26000 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26001 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26002 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26003 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26004 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26005 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26006 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
26007 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26008 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26009 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26010 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26011 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26012 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26013 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26014 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26015 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26016 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26017 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26018 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26019 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26020 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26021 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26023 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26024 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26025 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26026 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26027 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26028 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26029 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26030 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26031 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26032 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26033 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26034 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26035 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26039 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26040 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26045 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26046 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26047 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26048 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26049 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26050 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26051 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26052 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26053 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26054 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26055 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26056 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26057 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26058 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26059 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26060 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26061 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26062 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26063 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26064 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26065 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26066 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26067 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26068 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26069 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26070 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26071 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26072 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26073 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26074 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26075 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26076 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26077 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26078 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26079 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26080 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26081 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26082 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26083 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26084 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26085 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26086 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26087 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26088 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26089 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26090 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26091 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26092 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26093 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26094 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26095 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26096 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26097 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26098 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26099 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26100 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26101 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26102 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26103 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26104 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26105 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26106 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26107 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26108 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26109 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26110 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26111 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26112 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26113 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26114 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26115 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26116 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26117 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26118 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26119 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26120 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26121 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
26122
26123 #undef ARM_VARIANT
26124 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26125
26126 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26127 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26128 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26129 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26130 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26131 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26132 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26133 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26134 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26135 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26136 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26137 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26138 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26141 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26142 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26143 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26144 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26145 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26146 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26147 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26148 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26149 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26150 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26151 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26152 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26166 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26168 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26169 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26170 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26171 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26172 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26173 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26174 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26175 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26176 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26177 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26178 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26179 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26180 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26181 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26182 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26183
26184 #undef ARM_VARIANT
26185 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26186
26187 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26188 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26189 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26190 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26191 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26192 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26193 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26194 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26195 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26196 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26197 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26198 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26199 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26200 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
26201 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26202 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26203 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26204 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26205 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26206 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26207 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26208 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26209 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26210 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
26211 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26212 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26213 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26214 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
26215 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26216 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
26217 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26218 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26219 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26220 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
26221 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26222 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26223 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26224 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26225 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26226 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
26227 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26228 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
26229 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26230 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
26231 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26232 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26233 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26234 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26235 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26236 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26237 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26238 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26239 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26240 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26241 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26242 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26243 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26244 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26245 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26246 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26247 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26248 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26249 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26250 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26251 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26252 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26253 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26254 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26255 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26256 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26257 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26258 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26259 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26260 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26261 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26262 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26263
26264 /* ARMv8.5-A instructions. */
26265 #undef ARM_VARIANT
26266 #define ARM_VARIANT & arm_ext_sb
26267 #undef THUMB_VARIANT
26268 #define THUMB_VARIANT & arm_ext_sb
26269 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26270
26271 #undef ARM_VARIANT
26272 #define ARM_VARIANT & arm_ext_predres
26273 #undef THUMB_VARIANT
26274 #define THUMB_VARIANT & arm_ext_predres
26275 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26276 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26277 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26278
26279 /* ARMv8-M instructions. */
26280 #undef ARM_VARIANT
26281 #define ARM_VARIANT NULL
26282 #undef THUMB_VARIANT
26283 #define THUMB_VARIANT & arm_ext_v8m
26284 ToU("sg", e97fe97f, 0, (), noargs),
26285 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26286 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26287 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26288 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26289 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26290 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
26291
26292 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26293 instructions behave as nop if no VFP is present. */
26294 #undef THUMB_VARIANT
26295 #define THUMB_VARIANT & arm_ext_v8m_main
26296 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26297 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
26298
26299 /* Armv8.1-M Mainline instructions. */
26300 #undef THUMB_VARIANT
26301 #define THUMB_VARIANT & arm_ext_v8_1m_main
26302 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26303 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26304 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26305 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26306 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26307 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26308 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26309 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26310 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26311
26312 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
26313 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
26314 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
26315 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
26316 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
26317
26318 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26319 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26320 toU("le", _le, 2, (oLR, EXP), t_loloop),
26321
26322 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
26323 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26324
26325 #undef THUMB_VARIANT
26326 #define THUMB_VARIANT & mve_ext
26327 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26328 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26329 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26330 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26331 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26332 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26333 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26334 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26335 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26336 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26337 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26338 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26339 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26340 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26341 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
26342
26343 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26344 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26345 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26346 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26347 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26348 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26349 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26350 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26351 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26352 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26353 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26354 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26355 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26356 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26357 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26358
26359 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26360 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26361 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26362 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26363 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26364 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26365 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26366 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26367 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26368 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26369 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26370 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26371 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26372 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26373 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26374
26375 /* MVE and MVE FP only. */
26376 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
26377 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
26378 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26379 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26380 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26381 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26382 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
26383 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26384 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26385 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26386 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26387 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26388 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26389 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26390 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26391 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26392 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26393 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26394
26395 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26396 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26397 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26398 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26399 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26400 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26401 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26402 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26403 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26404 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26405 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26406 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26407 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26408 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26409 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26410 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26411 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26412 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26413 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26414 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26415
26416 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26417 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
26418 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26419 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26420 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26421 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26422 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
26423 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26424 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26425 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26426 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26427 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26428 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26429 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26430 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26431 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26432 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
26433
26434 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26435 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26436 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26437 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26438 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26439 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26440 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26441 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26442 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26443 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26444 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26445 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26446 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26447 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26448 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26449 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26450 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26451 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26452 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26453 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26454
26455 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26456 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26457 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26458 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26459 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
26460
26461 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26462 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26463 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26464 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26465 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26466 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26467 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26468 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26469 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26470 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26471 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26472 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26473 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26474 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26475 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26476 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26477 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
26478
26479 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26480 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26481 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26482 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26483 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26484 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26485 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26486 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26487 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26488 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26489 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26490 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26491
26492 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26493 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26494 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26495
26496 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26497 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26498 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26499 toU("lctp", _lctp, 0, (), t_loloop),
26500
26501 #undef THUMB_VARIANT
26502 #define THUMB_VARIANT & mve_fp_ext
26503 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
26504 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
26505 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26506 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26507 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26508 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26509 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26510 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
26511
26512 #undef ARM_VARIANT
26513 #define ARM_VARIANT & fpu_vfp_ext_v1
26514 #undef THUMB_VARIANT
26515 #define THUMB_VARIANT & arm_ext_v6t2
26516 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26517 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
26518
26519 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26520
26521 #undef ARM_VARIANT
26522 #define ARM_VARIANT & fpu_vfp_ext_v1xd
26523
26524 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26525 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26526 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26527 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26528
26529 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26530 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26531 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26532
26533 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26534 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26535
26536 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26537 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26538
26539 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26540 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26541
26542 #undef ARM_VARIANT
26543 #define ARM_VARIANT & fpu_vfp_ext_v2
26544
26545 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26546 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26547 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26548 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26549
26550 #undef ARM_VARIANT
26551 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
26552 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26553 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26554 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26555 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
26556 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26557 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26558
26559 #undef ARM_VARIANT
26560 #define ARM_VARIANT & fpu_neon_ext_v1
26561 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26562 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
26563 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
26564 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
26565 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26566 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26567 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26568 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26569 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
26570 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26571 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
26572 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
26573 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26574 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26575 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26576 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26577 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26578 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26579 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26580 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26581 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26582 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26583 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26584 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26585 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26586 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26587 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26588 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26589 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26590 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26591 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26592 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26593 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26594 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
26595 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26596 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26597 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
26598
26599 #undef ARM_VARIANT
26600 #define ARM_VARIANT & arm_ext_v8_3
26601 #undef THUMB_VARIANT
26602 #define THUMB_VARIANT & arm_ext_v6t2_v8m
26603 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26604 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
26605
26606 #undef ARM_VARIANT
26607 #define ARM_VARIANT &arm_ext_bf16
26608 #undef THUMB_VARIANT
26609 #define THUMB_VARIANT &arm_ext_bf16
26610 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26611 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26612 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26613
26614 #undef ARM_VARIANT
26615 #define ARM_VARIANT &arm_ext_i8mm
26616 #undef THUMB_VARIANT
26617 #define THUMB_VARIANT &arm_ext_i8mm
26618 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26619 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
26620 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26621 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26622 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
26623
26624 #undef ARM_VARIANT
26625 #undef THUMB_VARIANT
26626 #define THUMB_VARIANT &arm_ext_cde
26627 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26628 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26629 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26630 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26631
26632 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26633 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26634 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26635 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26636
26637 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26638 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26639 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26640 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
26641
26642 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26643 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26644
26645 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26646 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26647
26648 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26649 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26650 };
26651
26652 #undef ARM_VARIANT
26653 #undef THUMB_VARIANT
26654 #undef TCE
26655 #undef TUE
26656 #undef TUF
26657 #undef TCC
26658 #undef cCE
26659 #undef cCL
26660 #undef C3E
26661 #undef C3
26662 #undef CE
26663 #undef CM
26664 #undef CL
26665 #undef UE
26666 #undef UF
26667 #undef UT
26668 #undef NUF
26669 #undef nUF
26670 #undef NCE
26671 #undef nCE
26672 #undef OPS0
26673 #undef OPS1
26674 #undef OPS2
26675 #undef OPS3
26676 #undef OPS4
26677 #undef OPS5
26678 #undef OPS6
26679 #undef do_0
26680 #undef ToC
26681 #undef toC
26682 #undef ToU
26683 #undef toU
26684 \f
26685 /* MD interface: bits in the object file. */
26686
26687 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26688 for use in the a.out file, and stores them in the array pointed to by buf.
26689 This knows about the endian-ness of the target machine and does
26690 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26691 2 (short) and 4 (long) Floating numbers are put out as a series of
26692 LITTLENUMS (shorts, here at least). */
26693
26694 void
26695 md_number_to_chars (char * buf, valueT val, int n)
26696 {
26697 if (target_big_endian)
26698 number_to_chars_bigendian (buf, val, n);
26699 else
26700 number_to_chars_littleendian (buf, val, n);
26701 }
26702
26703 static valueT
26704 md_chars_to_number (char * buf, int n)
26705 {
26706 valueT result = 0;
26707 unsigned char * where = (unsigned char *) buf;
26708
26709 if (target_big_endian)
26710 {
26711 while (n--)
26712 {
26713 result <<= 8;
26714 result |= (*where++ & 255);
26715 }
26716 }
26717 else
26718 {
26719 while (n--)
26720 {
26721 result <<= 8;
26722 result |= (where[n] & 255);
26723 }
26724 }
26725
26726 return result;
26727 }
26728
26729 /* MD interface: Sections. */
26730
26731 /* Calculate the maximum variable size (i.e., excluding fr_fix)
26732 that an rs_machine_dependent frag may reach. */
26733
26734 unsigned int
26735 arm_frag_max_var (fragS *fragp)
26736 {
26737 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26738 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26739
26740 Note that we generate relaxable instructions even for cases that don't
26741 really need it, like an immediate that's a trivial constant. So we're
26742 overestimating the instruction size for some of those cases. Rather
26743 than putting more intelligence here, it would probably be better to
26744 avoid generating a relaxation frag in the first place when it can be
26745 determined up front that a short instruction will suffice. */
26746
26747 gas_assert (fragp->fr_type == rs_machine_dependent);
26748 return INSN_SIZE;
26749 }
26750
26751 /* Estimate the size of a frag before relaxing. Assume everything fits in
26752 2 bytes. */
26753
26754 int
26755 md_estimate_size_before_relax (fragS * fragp,
26756 segT segtype ATTRIBUTE_UNUSED)
26757 {
26758 fragp->fr_var = 2;
26759 return 2;
26760 }
26761
26762 /* Convert a machine dependent frag. */
26763
26764 void
26765 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26766 {
26767 unsigned long insn;
26768 unsigned long old_op;
26769 char *buf;
26770 expressionS exp;
26771 fixS *fixp;
26772 int reloc_type;
26773 int pc_rel;
26774 int opcode;
26775
26776 buf = fragp->fr_literal + fragp->fr_fix;
26777
26778 old_op = bfd_get_16(abfd, buf);
26779 if (fragp->fr_symbol)
26780 {
26781 exp.X_op = O_symbol;
26782 exp.X_add_symbol = fragp->fr_symbol;
26783 }
26784 else
26785 {
26786 exp.X_op = O_constant;
26787 }
26788 exp.X_add_number = fragp->fr_offset;
26789 opcode = fragp->fr_subtype;
26790 switch (opcode)
26791 {
26792 case T_MNEM_ldr_pc:
26793 case T_MNEM_ldr_pc2:
26794 case T_MNEM_ldr_sp:
26795 case T_MNEM_str_sp:
26796 case T_MNEM_ldr:
26797 case T_MNEM_ldrb:
26798 case T_MNEM_ldrh:
26799 case T_MNEM_str:
26800 case T_MNEM_strb:
26801 case T_MNEM_strh:
26802 if (fragp->fr_var == 4)
26803 {
26804 insn = THUMB_OP32 (opcode);
26805 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26806 {
26807 insn |= (old_op & 0x700) << 4;
26808 }
26809 else
26810 {
26811 insn |= (old_op & 7) << 12;
26812 insn |= (old_op & 0x38) << 13;
26813 }
26814 insn |= 0x00000c00;
26815 put_thumb32_insn (buf, insn);
26816 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26817 }
26818 else
26819 {
26820 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26821 }
26822 pc_rel = (opcode == T_MNEM_ldr_pc2);
26823 break;
26824 case T_MNEM_adr:
26825 if (fragp->fr_var == 4)
26826 {
26827 insn = THUMB_OP32 (opcode);
26828 insn |= (old_op & 0xf0) << 4;
26829 put_thumb32_insn (buf, insn);
26830 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26831 }
26832 else
26833 {
26834 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26835 exp.X_add_number -= 4;
26836 }
26837 pc_rel = 1;
26838 break;
26839 case T_MNEM_mov:
26840 case T_MNEM_movs:
26841 case T_MNEM_cmp:
26842 case T_MNEM_cmn:
26843 if (fragp->fr_var == 4)
26844 {
26845 int r0off = (opcode == T_MNEM_mov
26846 || opcode == T_MNEM_movs) ? 0 : 8;
26847 insn = THUMB_OP32 (opcode);
26848 insn = (insn & 0xe1ffffff) | 0x10000000;
26849 insn |= (old_op & 0x700) << r0off;
26850 put_thumb32_insn (buf, insn);
26851 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26852 }
26853 else
26854 {
26855 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26856 }
26857 pc_rel = 0;
26858 break;
26859 case T_MNEM_b:
26860 if (fragp->fr_var == 4)
26861 {
26862 insn = THUMB_OP32(opcode);
26863 put_thumb32_insn (buf, insn);
26864 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26865 }
26866 else
26867 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26868 pc_rel = 1;
26869 break;
26870 case T_MNEM_bcond:
26871 if (fragp->fr_var == 4)
26872 {
26873 insn = THUMB_OP32(opcode);
26874 insn |= (old_op & 0xf00) << 14;
26875 put_thumb32_insn (buf, insn);
26876 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26877 }
26878 else
26879 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26880 pc_rel = 1;
26881 break;
26882 case T_MNEM_add_sp:
26883 case T_MNEM_add_pc:
26884 case T_MNEM_inc_sp:
26885 case T_MNEM_dec_sp:
26886 if (fragp->fr_var == 4)
26887 {
26888 /* ??? Choose between add and addw. */
26889 insn = THUMB_OP32 (opcode);
26890 insn |= (old_op & 0xf0) << 4;
26891 put_thumb32_insn (buf, insn);
26892 if (opcode == T_MNEM_add_pc)
26893 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26894 else
26895 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26896 }
26897 else
26898 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26899 pc_rel = 0;
26900 break;
26901
26902 case T_MNEM_addi:
26903 case T_MNEM_addis:
26904 case T_MNEM_subi:
26905 case T_MNEM_subis:
26906 if (fragp->fr_var == 4)
26907 {
26908 insn = THUMB_OP32 (opcode);
26909 insn |= (old_op & 0xf0) << 4;
26910 insn |= (old_op & 0xf) << 16;
26911 put_thumb32_insn (buf, insn);
26912 if (insn & (1 << 20))
26913 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26914 else
26915 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26916 }
26917 else
26918 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26919 pc_rel = 0;
26920 break;
26921 default:
26922 abort ();
26923 }
26924 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
26925 (enum bfd_reloc_code_real) reloc_type);
26926 fixp->fx_file = fragp->fr_file;
26927 fixp->fx_line = fragp->fr_line;
26928 fragp->fr_fix += fragp->fr_var;
26929
26930 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26931 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26932 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26933 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
26934 }
26935
26936 /* Return the size of a relaxable immediate operand instruction.
26937 SHIFT and SIZE specify the form of the allowable immediate. */
26938 static int
26939 relax_immediate (fragS *fragp, int size, int shift)
26940 {
26941 offsetT offset;
26942 offsetT mask;
26943 offsetT low;
26944
26945 /* ??? Should be able to do better than this. */
26946 if (fragp->fr_symbol)
26947 return 4;
26948
26949 low = (1 << shift) - 1;
26950 mask = (1 << (shift + size)) - (1 << shift);
26951 offset = fragp->fr_offset;
26952 /* Force misaligned offsets to 32-bit variant. */
26953 if (offset & low)
26954 return 4;
26955 if (offset & ~mask)
26956 return 4;
26957 return 2;
26958 }
26959
26960 /* Get the address of a symbol during relaxation. */
26961 static addressT
26962 relaxed_symbol_addr (fragS *fragp, long stretch)
26963 {
26964 fragS *sym_frag;
26965 addressT addr;
26966 symbolS *sym;
26967
26968 sym = fragp->fr_symbol;
26969 sym_frag = symbol_get_frag (sym);
26970 know (S_GET_SEGMENT (sym) != absolute_section
26971 || sym_frag == &zero_address_frag);
26972 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26973
26974 /* If frag has yet to be reached on this pass, assume it will
26975 move by STRETCH just as we did. If this is not so, it will
26976 be because some frag between grows, and that will force
26977 another pass. */
26978
26979 if (stretch != 0
26980 && sym_frag->relax_marker != fragp->relax_marker)
26981 {
26982 fragS *f;
26983
26984 /* Adjust stretch for any alignment frag. Note that if have
26985 been expanding the earlier code, the symbol may be
26986 defined in what appears to be an earlier frag. FIXME:
26987 This doesn't handle the fr_subtype field, which specifies
26988 a maximum number of bytes to skip when doing an
26989 alignment. */
26990 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26991 {
26992 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26993 {
26994 if (stretch < 0)
26995 stretch = - ((- stretch)
26996 & ~ ((1 << (int) f->fr_offset) - 1));
26997 else
26998 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26999 if (stretch == 0)
27000 break;
27001 }
27002 }
27003 if (f != NULL)
27004 addr += stretch;
27005 }
27006
27007 return addr;
27008 }
27009
27010 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
27011 load. */
27012 static int
27013 relax_adr (fragS *fragp, asection *sec, long stretch)
27014 {
27015 addressT addr;
27016 offsetT val;
27017
27018 /* Assume worst case for symbols not known to be in the same section. */
27019 if (fragp->fr_symbol == NULL
27020 || !S_IS_DEFINED (fragp->fr_symbol)
27021 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27022 || S_IS_WEAK (fragp->fr_symbol))
27023 return 4;
27024
27025 val = relaxed_symbol_addr (fragp, stretch);
27026 addr = fragp->fr_address + fragp->fr_fix;
27027 addr = (addr + 4) & ~3;
27028 /* Force misaligned targets to 32-bit variant. */
27029 if (val & 3)
27030 return 4;
27031 val -= addr;
27032 if (val < 0 || val > 1020)
27033 return 4;
27034 return 2;
27035 }
27036
27037 /* Return the size of a relaxable add/sub immediate instruction. */
27038 static int
27039 relax_addsub (fragS *fragp, asection *sec)
27040 {
27041 char *buf;
27042 int op;
27043
27044 buf = fragp->fr_literal + fragp->fr_fix;
27045 op = bfd_get_16(sec->owner, buf);
27046 if ((op & 0xf) == ((op >> 4) & 0xf))
27047 return relax_immediate (fragp, 8, 0);
27048 else
27049 return relax_immediate (fragp, 3, 0);
27050 }
27051
27052 /* Return TRUE iff the definition of symbol S could be pre-empted
27053 (overridden) at link or load time. */
27054 static bfd_boolean
27055 symbol_preemptible (symbolS *s)
27056 {
27057 /* Weak symbols can always be pre-empted. */
27058 if (S_IS_WEAK (s))
27059 return TRUE;
27060
27061 /* Non-global symbols cannot be pre-empted. */
27062 if (! S_IS_EXTERNAL (s))
27063 return FALSE;
27064
27065 #ifdef OBJ_ELF
27066 /* In ELF, a global symbol can be marked protected, or private. In that
27067 case it can't be pre-empted (other definitions in the same link unit
27068 would violate the ODR). */
27069 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27070 return FALSE;
27071 #endif
27072
27073 /* Other global symbols might be pre-empted. */
27074 return TRUE;
27075 }
27076
27077 /* Return the size of a relaxable branch instruction. BITS is the
27078 size of the offset field in the narrow instruction. */
27079
27080 static int
27081 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
27082 {
27083 addressT addr;
27084 offsetT val;
27085 offsetT limit;
27086
27087 /* Assume worst case for symbols not known to be in the same section. */
27088 if (!S_IS_DEFINED (fragp->fr_symbol)
27089 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27090 || S_IS_WEAK (fragp->fr_symbol))
27091 return 4;
27092
27093 #ifdef OBJ_ELF
27094 /* A branch to a function in ARM state will require interworking. */
27095 if (S_IS_DEFINED (fragp->fr_symbol)
27096 && ARM_IS_FUNC (fragp->fr_symbol))
27097 return 4;
27098 #endif
27099
27100 if (symbol_preemptible (fragp->fr_symbol))
27101 return 4;
27102
27103 val = relaxed_symbol_addr (fragp, stretch);
27104 addr = fragp->fr_address + fragp->fr_fix + 4;
27105 val -= addr;
27106
27107 /* Offset is a signed value *2 */
27108 limit = 1 << bits;
27109 if (val >= limit || val < -limit)
27110 return 4;
27111 return 2;
27112 }
27113
27114
27115 /* Relax a machine dependent frag. This returns the amount by which
27116 the current size of the frag should change. */
27117
27118 int
27119 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
27120 {
27121 int oldsize;
27122 int newsize;
27123
27124 oldsize = fragp->fr_var;
27125 switch (fragp->fr_subtype)
27126 {
27127 case T_MNEM_ldr_pc2:
27128 newsize = relax_adr (fragp, sec, stretch);
27129 break;
27130 case T_MNEM_ldr_pc:
27131 case T_MNEM_ldr_sp:
27132 case T_MNEM_str_sp:
27133 newsize = relax_immediate (fragp, 8, 2);
27134 break;
27135 case T_MNEM_ldr:
27136 case T_MNEM_str:
27137 newsize = relax_immediate (fragp, 5, 2);
27138 break;
27139 case T_MNEM_ldrh:
27140 case T_MNEM_strh:
27141 newsize = relax_immediate (fragp, 5, 1);
27142 break;
27143 case T_MNEM_ldrb:
27144 case T_MNEM_strb:
27145 newsize = relax_immediate (fragp, 5, 0);
27146 break;
27147 case T_MNEM_adr:
27148 newsize = relax_adr (fragp, sec, stretch);
27149 break;
27150 case T_MNEM_mov:
27151 case T_MNEM_movs:
27152 case T_MNEM_cmp:
27153 case T_MNEM_cmn:
27154 newsize = relax_immediate (fragp, 8, 0);
27155 break;
27156 case T_MNEM_b:
27157 newsize = relax_branch (fragp, sec, 11, stretch);
27158 break;
27159 case T_MNEM_bcond:
27160 newsize = relax_branch (fragp, sec, 8, stretch);
27161 break;
27162 case T_MNEM_add_sp:
27163 case T_MNEM_add_pc:
27164 newsize = relax_immediate (fragp, 8, 2);
27165 break;
27166 case T_MNEM_inc_sp:
27167 case T_MNEM_dec_sp:
27168 newsize = relax_immediate (fragp, 7, 2);
27169 break;
27170 case T_MNEM_addi:
27171 case T_MNEM_addis:
27172 case T_MNEM_subi:
27173 case T_MNEM_subis:
27174 newsize = relax_addsub (fragp, sec);
27175 break;
27176 default:
27177 abort ();
27178 }
27179
27180 fragp->fr_var = newsize;
27181 /* Freeze wide instructions that are at or before the same location as
27182 in the previous pass. This avoids infinite loops.
27183 Don't freeze them unconditionally because targets may be artificially
27184 misaligned by the expansion of preceding frags. */
27185 if (stretch <= 0 && newsize > 2)
27186 {
27187 md_convert_frag (sec->owner, sec, fragp);
27188 frag_wane (fragp);
27189 }
27190
27191 return newsize - oldsize;
27192 }
27193
27194 /* Round up a section size to the appropriate boundary. */
27195
27196 valueT
27197 md_section_align (segT segment ATTRIBUTE_UNUSED,
27198 valueT size)
27199 {
27200 return size;
27201 }
27202
27203 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27204 of an rs_align_code fragment. */
27205
27206 void
27207 arm_handle_align (fragS * fragP)
27208 {
27209 static unsigned char const arm_noop[2][2][4] =
27210 {
27211 { /* ARMv1 */
27212 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27213 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27214 },
27215 { /* ARMv6k */
27216 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27217 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27218 },
27219 };
27220 static unsigned char const thumb_noop[2][2][2] =
27221 {
27222 { /* Thumb-1 */
27223 {0xc0, 0x46}, /* LE */
27224 {0x46, 0xc0}, /* BE */
27225 },
27226 { /* Thumb-2 */
27227 {0x00, 0xbf}, /* LE */
27228 {0xbf, 0x00} /* BE */
27229 }
27230 };
27231 static unsigned char const wide_thumb_noop[2][4] =
27232 { /* Wide Thumb-2 */
27233 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27234 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27235 };
27236
27237 unsigned bytes, fix, noop_size;
27238 char * p;
27239 const unsigned char * noop;
27240 const unsigned char *narrow_noop = NULL;
27241 #ifdef OBJ_ELF
27242 enum mstate state;
27243 #endif
27244
27245 if (fragP->fr_type != rs_align_code)
27246 return;
27247
27248 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27249 p = fragP->fr_literal + fragP->fr_fix;
27250 fix = 0;
27251
27252 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27253 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
27254
27255 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
27256
27257 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
27258 {
27259 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27260 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
27261 {
27262 narrow_noop = thumb_noop[1][target_big_endian];
27263 noop = wide_thumb_noop[target_big_endian];
27264 }
27265 else
27266 noop = thumb_noop[0][target_big_endian];
27267 noop_size = 2;
27268 #ifdef OBJ_ELF
27269 state = MAP_THUMB;
27270 #endif
27271 }
27272 else
27273 {
27274 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27275 ? selected_cpu : arm_arch_none,
27276 arm_ext_v6k) != 0]
27277 [target_big_endian];
27278 noop_size = 4;
27279 #ifdef OBJ_ELF
27280 state = MAP_ARM;
27281 #endif
27282 }
27283
27284 fragP->fr_var = noop_size;
27285
27286 if (bytes & (noop_size - 1))
27287 {
27288 fix = bytes & (noop_size - 1);
27289 #ifdef OBJ_ELF
27290 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27291 #endif
27292 memset (p, 0, fix);
27293 p += fix;
27294 bytes -= fix;
27295 }
27296
27297 if (narrow_noop)
27298 {
27299 if (bytes & noop_size)
27300 {
27301 /* Insert a narrow noop. */
27302 memcpy (p, narrow_noop, noop_size);
27303 p += noop_size;
27304 bytes -= noop_size;
27305 fix += noop_size;
27306 }
27307
27308 /* Use wide noops for the remainder */
27309 noop_size = 4;
27310 }
27311
27312 while (bytes >= noop_size)
27313 {
27314 memcpy (p, noop, noop_size);
27315 p += noop_size;
27316 bytes -= noop_size;
27317 fix += noop_size;
27318 }
27319
27320 fragP->fr_fix += fix;
27321 }
27322
27323 /* Called from md_do_align. Used to create an alignment
27324 frag in a code section. */
27325
27326 void
27327 arm_frag_align_code (int n, int max)
27328 {
27329 char * p;
27330
27331 /* We assume that there will never be a requirement
27332 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
27333 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
27334 {
27335 char err_msg[128];
27336
27337 sprintf (err_msg,
27338 _("alignments greater than %d bytes not supported in .text sections."),
27339 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
27340 as_fatal ("%s", err_msg);
27341 }
27342
27343 p = frag_var (rs_align_code,
27344 MAX_MEM_FOR_RS_ALIGN_CODE,
27345 1,
27346 (relax_substateT) max,
27347 (symbolS *) NULL,
27348 (offsetT) n,
27349 (char *) NULL);
27350 *p = 0;
27351 }
27352
27353 /* Perform target specific initialisation of a frag.
27354 Note - despite the name this initialisation is not done when the frag
27355 is created, but only when its type is assigned. A frag can be created
27356 and used a long time before its type is set, so beware of assuming that
27357 this initialisation is performed first. */
27358
27359 #ifndef OBJ_ELF
27360 void
27361 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27362 {
27363 /* Record whether this frag is in an ARM or a THUMB area. */
27364 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27365 }
27366
27367 #else /* OBJ_ELF is defined. */
27368 void
27369 arm_init_frag (fragS * fragP, int max_chars)
27370 {
27371 bfd_boolean frag_thumb_mode;
27372
27373 /* If the current ARM vs THUMB mode has not already
27374 been recorded into this frag then do so now. */
27375 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
27376 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27377
27378 /* PR 21809: Do not set a mapping state for debug sections
27379 - it just confuses other tools. */
27380 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
27381 return;
27382
27383 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
27384
27385 /* Record a mapping symbol for alignment frags. We will delete this
27386 later if the alignment ends up empty. */
27387 switch (fragP->fr_type)
27388 {
27389 case rs_align:
27390 case rs_align_test:
27391 case rs_fill:
27392 mapping_state_2 (MAP_DATA, max_chars);
27393 break;
27394 case rs_align_code:
27395 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
27396 break;
27397 default:
27398 break;
27399 }
27400 }
27401
27402 /* When we change sections we need to issue a new mapping symbol. */
27403
27404 void
27405 arm_elf_change_section (void)
27406 {
27407 /* Link an unlinked unwind index table section to the .text section. */
27408 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27409 && elf_linked_to_section (now_seg) == NULL)
27410 elf_linked_to_section (now_seg) = text_section;
27411 }
27412
27413 int
27414 arm_elf_section_type (const char * str, size_t len)
27415 {
27416 if (len == 5 && strncmp (str, "exidx", 5) == 0)
27417 return SHT_ARM_EXIDX;
27418
27419 return -1;
27420 }
27421 \f
27422 /* Code to deal with unwinding tables. */
27423
27424 static void add_unwind_adjustsp (offsetT);
27425
27426 /* Generate any deferred unwind frame offset. */
27427
27428 static void
27429 flush_pending_unwind (void)
27430 {
27431 offsetT offset;
27432
27433 offset = unwind.pending_offset;
27434 unwind.pending_offset = 0;
27435 if (offset != 0)
27436 add_unwind_adjustsp (offset);
27437 }
27438
27439 /* Add an opcode to this list for this function. Two-byte opcodes should
27440 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27441 order. */
27442
27443 static void
27444 add_unwind_opcode (valueT op, int length)
27445 {
27446 /* Add any deferred stack adjustment. */
27447 if (unwind.pending_offset)
27448 flush_pending_unwind ();
27449
27450 unwind.sp_restored = 0;
27451
27452 if (unwind.opcode_count + length > unwind.opcode_alloc)
27453 {
27454 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27455 if (unwind.opcodes)
27456 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27457 unwind.opcode_alloc);
27458 else
27459 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
27460 }
27461 while (length > 0)
27462 {
27463 length--;
27464 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27465 op >>= 8;
27466 unwind.opcode_count++;
27467 }
27468 }
27469
27470 /* Add unwind opcodes to adjust the stack pointer. */
27471
27472 static void
27473 add_unwind_adjustsp (offsetT offset)
27474 {
27475 valueT op;
27476
27477 if (offset > 0x200)
27478 {
27479 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27480 char bytes[5];
27481 int n;
27482 valueT o;
27483
27484 /* Long form: 0xb2, uleb128. */
27485 /* This might not fit in a word so add the individual bytes,
27486 remembering the list is built in reverse order. */
27487 o = (valueT) ((offset - 0x204) >> 2);
27488 if (o == 0)
27489 add_unwind_opcode (0, 1);
27490
27491 /* Calculate the uleb128 encoding of the offset. */
27492 n = 0;
27493 while (o)
27494 {
27495 bytes[n] = o & 0x7f;
27496 o >>= 7;
27497 if (o)
27498 bytes[n] |= 0x80;
27499 n++;
27500 }
27501 /* Add the insn. */
27502 for (; n; n--)
27503 add_unwind_opcode (bytes[n - 1], 1);
27504 add_unwind_opcode (0xb2, 1);
27505 }
27506 else if (offset > 0x100)
27507 {
27508 /* Two short opcodes. */
27509 add_unwind_opcode (0x3f, 1);
27510 op = (offset - 0x104) >> 2;
27511 add_unwind_opcode (op, 1);
27512 }
27513 else if (offset > 0)
27514 {
27515 /* Short opcode. */
27516 op = (offset - 4) >> 2;
27517 add_unwind_opcode (op, 1);
27518 }
27519 else if (offset < 0)
27520 {
27521 offset = -offset;
27522 while (offset > 0x100)
27523 {
27524 add_unwind_opcode (0x7f, 1);
27525 offset -= 0x100;
27526 }
27527 op = ((offset - 4) >> 2) | 0x40;
27528 add_unwind_opcode (op, 1);
27529 }
27530 }
27531
27532 /* Finish the list of unwind opcodes for this function. */
27533
27534 static void
27535 finish_unwind_opcodes (void)
27536 {
27537 valueT op;
27538
27539 if (unwind.fp_used)
27540 {
27541 /* Adjust sp as necessary. */
27542 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27543 flush_pending_unwind ();
27544
27545 /* After restoring sp from the frame pointer. */
27546 op = 0x90 | unwind.fp_reg;
27547 add_unwind_opcode (op, 1);
27548 }
27549 else
27550 flush_pending_unwind ();
27551 }
27552
27553
27554 /* Start an exception table entry. If idx is nonzero this is an index table
27555 entry. */
27556
27557 static void
27558 start_unwind_section (const segT text_seg, int idx)
27559 {
27560 const char * text_name;
27561 const char * prefix;
27562 const char * prefix_once;
27563 struct elf_section_match match;
27564 char * sec_name;
27565 int type;
27566 int flags;
27567 int linkonce;
27568
27569 if (idx)
27570 {
27571 prefix = ELF_STRING_ARM_unwind;
27572 prefix_once = ELF_STRING_ARM_unwind_once;
27573 type = SHT_ARM_EXIDX;
27574 }
27575 else
27576 {
27577 prefix = ELF_STRING_ARM_unwind_info;
27578 prefix_once = ELF_STRING_ARM_unwind_info_once;
27579 type = SHT_PROGBITS;
27580 }
27581
27582 text_name = segment_name (text_seg);
27583 if (streq (text_name, ".text"))
27584 text_name = "";
27585
27586 if (strncmp (text_name, ".gnu.linkonce.t.",
27587 strlen (".gnu.linkonce.t.")) == 0)
27588 {
27589 prefix = prefix_once;
27590 text_name += strlen (".gnu.linkonce.t.");
27591 }
27592
27593 sec_name = concat (prefix, text_name, (char *) NULL);
27594
27595 flags = SHF_ALLOC;
27596 linkonce = 0;
27597 memset (&match, 0, sizeof (match));
27598
27599 /* Handle COMDAT group. */
27600 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
27601 {
27602 match.group_name = elf_group_name (text_seg);
27603 if (match.group_name == NULL)
27604 {
27605 as_bad (_("Group section `%s' has no group signature"),
27606 segment_name (text_seg));
27607 ignore_rest_of_line ();
27608 return;
27609 }
27610 flags |= SHF_GROUP;
27611 linkonce = 1;
27612 }
27613
27614 obj_elf_change_section (sec_name, type, flags, 0, &match,
27615 linkonce, 0);
27616
27617 /* Set the section link for index tables. */
27618 if (idx)
27619 elf_linked_to_section (now_seg) = text_seg;
27620 }
27621
27622
27623 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27624 personality routine data. Returns zero, or the index table value for
27625 an inline entry. */
27626
27627 static valueT
27628 create_unwind_entry (int have_data)
27629 {
27630 int size;
27631 addressT where;
27632 char *ptr;
27633 /* The current word of data. */
27634 valueT data;
27635 /* The number of bytes left in this word. */
27636 int n;
27637
27638 finish_unwind_opcodes ();
27639
27640 /* Remember the current text section. */
27641 unwind.saved_seg = now_seg;
27642 unwind.saved_subseg = now_subseg;
27643
27644 start_unwind_section (now_seg, 0);
27645
27646 if (unwind.personality_routine == NULL)
27647 {
27648 if (unwind.personality_index == -2)
27649 {
27650 if (have_data)
27651 as_bad (_("handlerdata in cantunwind frame"));
27652 return 1; /* EXIDX_CANTUNWIND. */
27653 }
27654
27655 /* Use a default personality routine if none is specified. */
27656 if (unwind.personality_index == -1)
27657 {
27658 if (unwind.opcode_count > 3)
27659 unwind.personality_index = 1;
27660 else
27661 unwind.personality_index = 0;
27662 }
27663
27664 /* Space for the personality routine entry. */
27665 if (unwind.personality_index == 0)
27666 {
27667 if (unwind.opcode_count > 3)
27668 as_bad (_("too many unwind opcodes for personality routine 0"));
27669
27670 if (!have_data)
27671 {
27672 /* All the data is inline in the index table. */
27673 data = 0x80;
27674 n = 3;
27675 while (unwind.opcode_count > 0)
27676 {
27677 unwind.opcode_count--;
27678 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27679 n--;
27680 }
27681
27682 /* Pad with "finish" opcodes. */
27683 while (n--)
27684 data = (data << 8) | 0xb0;
27685
27686 return data;
27687 }
27688 size = 0;
27689 }
27690 else
27691 /* We get two opcodes "free" in the first word. */
27692 size = unwind.opcode_count - 2;
27693 }
27694 else
27695 {
27696 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27697 if (unwind.personality_index != -1)
27698 {
27699 as_bad (_("attempt to recreate an unwind entry"));
27700 return 1;
27701 }
27702
27703 /* An extra byte is required for the opcode count. */
27704 size = unwind.opcode_count + 1;
27705 }
27706
27707 size = (size + 3) >> 2;
27708 if (size > 0xff)
27709 as_bad (_("too many unwind opcodes"));
27710
27711 frag_align (2, 0, 0);
27712 record_alignment (now_seg, 2);
27713 unwind.table_entry = expr_build_dot ();
27714
27715 /* Allocate the table entry. */
27716 ptr = frag_more ((size << 2) + 4);
27717 /* PR 13449: Zero the table entries in case some of them are not used. */
27718 memset (ptr, 0, (size << 2) + 4);
27719 where = frag_now_fix () - ((size << 2) + 4);
27720
27721 switch (unwind.personality_index)
27722 {
27723 case -1:
27724 /* ??? Should this be a PLT generating relocation? */
27725 /* Custom personality routine. */
27726 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27727 BFD_RELOC_ARM_PREL31);
27728
27729 where += 4;
27730 ptr += 4;
27731
27732 /* Set the first byte to the number of additional words. */
27733 data = size > 0 ? size - 1 : 0;
27734 n = 3;
27735 break;
27736
27737 /* ABI defined personality routines. */
27738 case 0:
27739 /* Three opcodes bytes are packed into the first word. */
27740 data = 0x80;
27741 n = 3;
27742 break;
27743
27744 case 1:
27745 case 2:
27746 /* The size and first two opcode bytes go in the first word. */
27747 data = ((0x80 + unwind.personality_index) << 8) | size;
27748 n = 2;
27749 break;
27750
27751 default:
27752 /* Should never happen. */
27753 abort ();
27754 }
27755
27756 /* Pack the opcodes into words (MSB first), reversing the list at the same
27757 time. */
27758 while (unwind.opcode_count > 0)
27759 {
27760 if (n == 0)
27761 {
27762 md_number_to_chars (ptr, data, 4);
27763 ptr += 4;
27764 n = 4;
27765 data = 0;
27766 }
27767 unwind.opcode_count--;
27768 n--;
27769 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27770 }
27771
27772 /* Finish off the last word. */
27773 if (n < 4)
27774 {
27775 /* Pad with "finish" opcodes. */
27776 while (n--)
27777 data = (data << 8) | 0xb0;
27778
27779 md_number_to_chars (ptr, data, 4);
27780 }
27781
27782 if (!have_data)
27783 {
27784 /* Add an empty descriptor if there is no user-specified data. */
27785 ptr = frag_more (4);
27786 md_number_to_chars (ptr, 0, 4);
27787 }
27788
27789 return 0;
27790 }
27791
27792
27793 /* Initialize the DWARF-2 unwind information for this procedure. */
27794
27795 void
27796 tc_arm_frame_initial_instructions (void)
27797 {
27798 cfi_add_CFA_def_cfa (REG_SP, 0);
27799 }
27800 #endif /* OBJ_ELF */
27801
27802 /* Convert REGNAME to a DWARF-2 register number. */
27803
27804 int
27805 tc_arm_regname_to_dw2regnum (char *regname)
27806 {
27807 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
27808 if (reg != FAIL)
27809 return reg;
27810
27811 /* PR 16694: Allow VFP registers as well. */
27812 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27813 if (reg != FAIL)
27814 return 64 + reg;
27815
27816 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27817 if (reg != FAIL)
27818 return reg + 256;
27819
27820 return FAIL;
27821 }
27822
27823 #ifdef TE_PE
27824 void
27825 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
27826 {
27827 expressionS exp;
27828
27829 exp.X_op = O_secrel;
27830 exp.X_add_symbol = symbol;
27831 exp.X_add_number = 0;
27832 emit_expr (&exp, size);
27833 }
27834 #endif
27835
27836 /* MD interface: Symbol and relocation handling. */
27837
27838 /* Return the address within the segment that a PC-relative fixup is
27839 relative to. For ARM, PC-relative fixups applied to instructions
27840 are generally relative to the location of the fixup plus 8 bytes.
27841 Thumb branches are offset by 4, and Thumb loads relative to PC
27842 require special handling. */
27843
27844 long
27845 md_pcrel_from_section (fixS * fixP, segT seg)
27846 {
27847 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27848
27849 /* If this is pc-relative and we are going to emit a relocation
27850 then we just want to put out any pipeline compensation that the linker
27851 will need. Otherwise we want to use the calculated base.
27852 For WinCE we skip the bias for externals as well, since this
27853 is how the MS ARM-CE assembler behaves and we want to be compatible. */
27854 if (fixP->fx_pcrel
27855 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
27856 || (arm_force_relocation (fixP)
27857 #ifdef TE_WINCE
27858 && !S_IS_EXTERNAL (fixP->fx_addsy)
27859 #endif
27860 )))
27861 base = 0;
27862
27863
27864 switch (fixP->fx_r_type)
27865 {
27866 /* PC relative addressing on the Thumb is slightly odd as the
27867 bottom two bits of the PC are forced to zero for the
27868 calculation. This happens *after* application of the
27869 pipeline offset. However, Thumb adrl already adjusts for
27870 this, so we need not do it again. */
27871 case BFD_RELOC_ARM_THUMB_ADD:
27872 return base & ~3;
27873
27874 case BFD_RELOC_ARM_THUMB_OFFSET:
27875 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27876 case BFD_RELOC_ARM_T32_ADD_PC12:
27877 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
27878 return (base + 4) & ~3;
27879
27880 /* Thumb branches are simply offset by +4. */
27881 case BFD_RELOC_THUMB_PCREL_BRANCH5:
27882 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27883 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27884 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27885 case BFD_RELOC_THUMB_PCREL_BRANCH20:
27886 case BFD_RELOC_THUMB_PCREL_BRANCH25:
27887 case BFD_RELOC_THUMB_PCREL_BFCSEL:
27888 case BFD_RELOC_ARM_THUMB_BF17:
27889 case BFD_RELOC_ARM_THUMB_BF19:
27890 case BFD_RELOC_ARM_THUMB_BF13:
27891 case BFD_RELOC_ARM_THUMB_LOOP12:
27892 return base + 4;
27893
27894 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27895 if (fixP->fx_addsy
27896 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27897 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27898 && ARM_IS_FUNC (fixP->fx_addsy)
27899 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27900 base = fixP->fx_where + fixP->fx_frag->fr_address;
27901 return base + 4;
27902
27903 /* BLX is like branches above, but forces the low two bits of PC to
27904 zero. */
27905 case BFD_RELOC_THUMB_PCREL_BLX:
27906 if (fixP->fx_addsy
27907 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27908 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27909 && THUMB_IS_FUNC (fixP->fx_addsy)
27910 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27911 base = fixP->fx_where + fixP->fx_frag->fr_address;
27912 return (base + 4) & ~3;
27913
27914 /* ARM mode branches are offset by +8. However, the Windows CE
27915 loader expects the relocation not to take this into account. */
27916 case BFD_RELOC_ARM_PCREL_BLX:
27917 if (fixP->fx_addsy
27918 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27919 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27920 && ARM_IS_FUNC (fixP->fx_addsy)
27921 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27922 base = fixP->fx_where + fixP->fx_frag->fr_address;
27923 return base + 8;
27924
27925 case BFD_RELOC_ARM_PCREL_CALL:
27926 if (fixP->fx_addsy
27927 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27928 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27929 && THUMB_IS_FUNC (fixP->fx_addsy)
27930 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27931 base = fixP->fx_where + fixP->fx_frag->fr_address;
27932 return base + 8;
27933
27934 case BFD_RELOC_ARM_PCREL_BRANCH:
27935 case BFD_RELOC_ARM_PCREL_JUMP:
27936 case BFD_RELOC_ARM_PLT32:
27937 #ifdef TE_WINCE
27938 /* When handling fixups immediately, because we have already
27939 discovered the value of a symbol, or the address of the frag involved
27940 we must account for the offset by +8, as the OS loader will never see the reloc.
27941 see fixup_segment() in write.c
27942 The S_IS_EXTERNAL test handles the case of global symbols.
27943 Those need the calculated base, not just the pipe compensation the linker will need. */
27944 if (fixP->fx_pcrel
27945 && fixP->fx_addsy != NULL
27946 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27947 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27948 return base + 8;
27949 return base;
27950 #else
27951 return base + 8;
27952 #endif
27953
27954
27955 /* ARM mode loads relative to PC are also offset by +8. Unlike
27956 branches, the Windows CE loader *does* expect the relocation
27957 to take this into account. */
27958 case BFD_RELOC_ARM_OFFSET_IMM:
27959 case BFD_RELOC_ARM_OFFSET_IMM8:
27960 case BFD_RELOC_ARM_HWLITERAL:
27961 case BFD_RELOC_ARM_LITERAL:
27962 case BFD_RELOC_ARM_CP_OFF_IMM:
27963 return base + 8;
27964
27965
27966 /* Other PC-relative relocations are un-offset. */
27967 default:
27968 return base;
27969 }
27970 }
27971
27972 static bfd_boolean flag_warn_syms = TRUE;
27973
27974 bfd_boolean
27975 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
27976 {
27977 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27978 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27979 does mean that the resulting code might be very confusing to the reader.
27980 Also this warning can be triggered if the user omits an operand before
27981 an immediate address, eg:
27982
27983 LDR =foo
27984
27985 GAS treats this as an assignment of the value of the symbol foo to a
27986 symbol LDR, and so (without this code) it will not issue any kind of
27987 warning or error message.
27988
27989 Note - ARM instructions are case-insensitive but the strings in the hash
27990 table are all stored in lower case, so we must first ensure that name is
27991 lower case too. */
27992 if (flag_warn_syms && arm_ops_hsh)
27993 {
27994 char * nbuf = strdup (name);
27995 char * p;
27996
27997 for (p = nbuf; *p; p++)
27998 *p = TOLOWER (*p);
27999 if (hash_find (arm_ops_hsh, nbuf) != NULL)
28000 {
28001 static struct hash_control * already_warned = NULL;
28002
28003 if (already_warned == NULL)
28004 already_warned = hash_new ();
28005 /* Only warn about the symbol once. To keep the code
28006 simple we let hash_insert do the lookup for us. */
28007 if (hash_insert (already_warned, nbuf, NULL) == NULL)
28008 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
28009 }
28010 else
28011 free (nbuf);
28012 }
28013
28014 return FALSE;
28015 }
28016
28017 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
28018 Otherwise we have no need to default values of symbols. */
28019
28020 symbolS *
28021 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
28022 {
28023 #ifdef OBJ_ELF
28024 if (name[0] == '_' && name[1] == 'G'
28025 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
28026 {
28027 if (!GOT_symbol)
28028 {
28029 if (symbol_find (name))
28030 as_bad (_("GOT already in the symbol table"));
28031
28032 GOT_symbol = symbol_new (name, undefined_section,
28033 (valueT) 0, & zero_address_frag);
28034 }
28035
28036 return GOT_symbol;
28037 }
28038 #endif
28039
28040 return NULL;
28041 }
28042
28043 /* Subroutine of md_apply_fix. Check to see if an immediate can be
28044 computed as two separate immediate values, added together. We
28045 already know that this value cannot be computed by just one ARM
28046 instruction. */
28047
28048 static unsigned int
28049 validate_immediate_twopart (unsigned int val,
28050 unsigned int * highpart)
28051 {
28052 unsigned int a;
28053 unsigned int i;
28054
28055 for (i = 0; i < 32; i += 2)
28056 if (((a = rotate_left (val, i)) & 0xff) != 0)
28057 {
28058 if (a & 0xff00)
28059 {
28060 if (a & ~ 0xffff)
28061 continue;
28062 * highpart = (a >> 8) | ((i + 24) << 7);
28063 }
28064 else if (a & 0xff0000)
28065 {
28066 if (a & 0xff000000)
28067 continue;
28068 * highpart = (a >> 16) | ((i + 16) << 7);
28069 }
28070 else
28071 {
28072 gas_assert (a & 0xff000000);
28073 * highpart = (a >> 24) | ((i + 8) << 7);
28074 }
28075
28076 return (a & 0xff) | (i << 7);
28077 }
28078
28079 return FAIL;
28080 }
28081
28082 static int
28083 validate_offset_imm (unsigned int val, int hwse)
28084 {
28085 if ((hwse && val > 255) || val > 4095)
28086 return FAIL;
28087 return val;
28088 }
28089
28090 /* Subroutine of md_apply_fix. Do those data_ops which can take a
28091 negative immediate constant by altering the instruction. A bit of
28092 a hack really.
28093 MOV <-> MVN
28094 AND <-> BIC
28095 ADC <-> SBC
28096 by inverting the second operand, and
28097 ADD <-> SUB
28098 CMP <-> CMN
28099 by negating the second operand. */
28100
28101 static int
28102 negate_data_op (unsigned long * instruction,
28103 unsigned long value)
28104 {
28105 int op, new_inst;
28106 unsigned long negated, inverted;
28107
28108 negated = encode_arm_immediate (-value);
28109 inverted = encode_arm_immediate (~value);
28110
28111 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
28112 switch (op)
28113 {
28114 /* First negates. */
28115 case OPCODE_SUB: /* ADD <-> SUB */
28116 new_inst = OPCODE_ADD;
28117 value = negated;
28118 break;
28119
28120 case OPCODE_ADD:
28121 new_inst = OPCODE_SUB;
28122 value = negated;
28123 break;
28124
28125 case OPCODE_CMP: /* CMP <-> CMN */
28126 new_inst = OPCODE_CMN;
28127 value = negated;
28128 break;
28129
28130 case OPCODE_CMN:
28131 new_inst = OPCODE_CMP;
28132 value = negated;
28133 break;
28134
28135 /* Now Inverted ops. */
28136 case OPCODE_MOV: /* MOV <-> MVN */
28137 new_inst = OPCODE_MVN;
28138 value = inverted;
28139 break;
28140
28141 case OPCODE_MVN:
28142 new_inst = OPCODE_MOV;
28143 value = inverted;
28144 break;
28145
28146 case OPCODE_AND: /* AND <-> BIC */
28147 new_inst = OPCODE_BIC;
28148 value = inverted;
28149 break;
28150
28151 case OPCODE_BIC:
28152 new_inst = OPCODE_AND;
28153 value = inverted;
28154 break;
28155
28156 case OPCODE_ADC: /* ADC <-> SBC */
28157 new_inst = OPCODE_SBC;
28158 value = inverted;
28159 break;
28160
28161 case OPCODE_SBC:
28162 new_inst = OPCODE_ADC;
28163 value = inverted;
28164 break;
28165
28166 /* We cannot do anything. */
28167 default:
28168 return FAIL;
28169 }
28170
28171 if (value == (unsigned) FAIL)
28172 return FAIL;
28173
28174 *instruction &= OPCODE_MASK;
28175 *instruction |= new_inst << DATA_OP_SHIFT;
28176 return value;
28177 }
28178
28179 /* Like negate_data_op, but for Thumb-2. */
28180
28181 static unsigned int
28182 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
28183 {
28184 int op, new_inst;
28185 int rd;
28186 unsigned int negated, inverted;
28187
28188 negated = encode_thumb32_immediate (-value);
28189 inverted = encode_thumb32_immediate (~value);
28190
28191 rd = (*instruction >> 8) & 0xf;
28192 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
28193 switch (op)
28194 {
28195 /* ADD <-> SUB. Includes CMP <-> CMN. */
28196 case T2_OPCODE_SUB:
28197 new_inst = T2_OPCODE_ADD;
28198 value = negated;
28199 break;
28200
28201 case T2_OPCODE_ADD:
28202 new_inst = T2_OPCODE_SUB;
28203 value = negated;
28204 break;
28205
28206 /* ORR <-> ORN. Includes MOV <-> MVN. */
28207 case T2_OPCODE_ORR:
28208 new_inst = T2_OPCODE_ORN;
28209 value = inverted;
28210 break;
28211
28212 case T2_OPCODE_ORN:
28213 new_inst = T2_OPCODE_ORR;
28214 value = inverted;
28215 break;
28216
28217 /* AND <-> BIC. TST has no inverted equivalent. */
28218 case T2_OPCODE_AND:
28219 new_inst = T2_OPCODE_BIC;
28220 if (rd == 15)
28221 value = FAIL;
28222 else
28223 value = inverted;
28224 break;
28225
28226 case T2_OPCODE_BIC:
28227 new_inst = T2_OPCODE_AND;
28228 value = inverted;
28229 break;
28230
28231 /* ADC <-> SBC */
28232 case T2_OPCODE_ADC:
28233 new_inst = T2_OPCODE_SBC;
28234 value = inverted;
28235 break;
28236
28237 case T2_OPCODE_SBC:
28238 new_inst = T2_OPCODE_ADC;
28239 value = inverted;
28240 break;
28241
28242 /* We cannot do anything. */
28243 default:
28244 return FAIL;
28245 }
28246
28247 if (value == (unsigned int)FAIL)
28248 return FAIL;
28249
28250 *instruction &= T2_OPCODE_MASK;
28251 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28252 return value;
28253 }
28254
28255 /* Read a 32-bit thumb instruction from buf. */
28256
28257 static unsigned long
28258 get_thumb32_insn (char * buf)
28259 {
28260 unsigned long insn;
28261 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28262 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28263
28264 return insn;
28265 }
28266
28267 /* We usually want to set the low bit on the address of thumb function
28268 symbols. In particular .word foo - . should have the low bit set.
28269 Generic code tries to fold the difference of two symbols to
28270 a constant. Prevent this and force a relocation when the first symbols
28271 is a thumb function. */
28272
28273 bfd_boolean
28274 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28275 {
28276 if (op == O_subtract
28277 && l->X_op == O_symbol
28278 && r->X_op == O_symbol
28279 && THUMB_IS_FUNC (l->X_add_symbol))
28280 {
28281 l->X_op = O_subtract;
28282 l->X_op_symbol = r->X_add_symbol;
28283 l->X_add_number -= r->X_add_number;
28284 return TRUE;
28285 }
28286
28287 /* Process as normal. */
28288 return FALSE;
28289 }
28290
28291 /* Encode Thumb2 unconditional branches and calls. The encoding
28292 for the 2 are identical for the immediate values. */
28293
28294 static void
28295 encode_thumb2_b_bl_offset (char * buf, offsetT value)
28296 {
28297 #define T2I1I2MASK ((1 << 13) | (1 << 11))
28298 offsetT newval;
28299 offsetT newval2;
28300 addressT S, I1, I2, lo, hi;
28301
28302 S = (value >> 24) & 0x01;
28303 I1 = (value >> 23) & 0x01;
28304 I2 = (value >> 22) & 0x01;
28305 hi = (value >> 12) & 0x3ff;
28306 lo = (value >> 1) & 0x7ff;
28307 newval = md_chars_to_number (buf, THUMB_SIZE);
28308 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28309 newval |= (S << 10) | hi;
28310 newval2 &= ~T2I1I2MASK;
28311 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28312 md_number_to_chars (buf, newval, THUMB_SIZE);
28313 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28314 }
28315
28316 void
28317 md_apply_fix (fixS * fixP,
28318 valueT * valP,
28319 segT seg)
28320 {
28321 offsetT value = * valP;
28322 offsetT newval;
28323 unsigned int newimm;
28324 unsigned long temp;
28325 int sign;
28326 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
28327
28328 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
28329
28330 /* Note whether this will delete the relocation. */
28331
28332 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28333 fixP->fx_done = 1;
28334
28335 /* On a 64-bit host, silently truncate 'value' to 32 bits for
28336 consistency with the behaviour on 32-bit hosts. Remember value
28337 for emit_reloc. */
28338 value &= 0xffffffff;
28339 value ^= 0x80000000;
28340 value -= 0x80000000;
28341
28342 *valP = value;
28343 fixP->fx_addnumber = value;
28344
28345 /* Same treatment for fixP->fx_offset. */
28346 fixP->fx_offset &= 0xffffffff;
28347 fixP->fx_offset ^= 0x80000000;
28348 fixP->fx_offset -= 0x80000000;
28349
28350 switch (fixP->fx_r_type)
28351 {
28352 case BFD_RELOC_NONE:
28353 /* This will need to go in the object file. */
28354 fixP->fx_done = 0;
28355 break;
28356
28357 case BFD_RELOC_ARM_IMMEDIATE:
28358 /* We claim that this fixup has been processed here,
28359 even if in fact we generate an error because we do
28360 not have a reloc for it, so tc_gen_reloc will reject it. */
28361 fixP->fx_done = 1;
28362
28363 if (fixP->fx_addsy)
28364 {
28365 const char *msg = 0;
28366
28367 if (! S_IS_DEFINED (fixP->fx_addsy))
28368 msg = _("undefined symbol %s used as an immediate value");
28369 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28370 msg = _("symbol %s is in a different section");
28371 else if (S_IS_WEAK (fixP->fx_addsy))
28372 msg = _("symbol %s is weak and may be overridden later");
28373
28374 if (msg)
28375 {
28376 as_bad_where (fixP->fx_file, fixP->fx_line,
28377 msg, S_GET_NAME (fixP->fx_addsy));
28378 break;
28379 }
28380 }
28381
28382 temp = md_chars_to_number (buf, INSN_SIZE);
28383
28384 /* If the offset is negative, we should use encoding A2 for ADR. */
28385 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
28386 newimm = negate_data_op (&temp, value);
28387 else
28388 {
28389 newimm = encode_arm_immediate (value);
28390
28391 /* If the instruction will fail, see if we can fix things up by
28392 changing the opcode. */
28393 if (newimm == (unsigned int) FAIL)
28394 newimm = negate_data_op (&temp, value);
28395 /* MOV accepts both ARM modified immediate (A1 encoding) and
28396 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28397 When disassembling, MOV is preferred when there is no encoding
28398 overlap. */
28399 if (newimm == (unsigned int) FAIL
28400 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28401 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28402 && !((temp >> SBIT_SHIFT) & 0x1)
28403 && value >= 0 && value <= 0xffff)
28404 {
28405 /* Clear bits[23:20] to change encoding from A1 to A2. */
28406 temp &= 0xff0fffff;
28407 /* Encoding high 4bits imm. Code below will encode the remaining
28408 low 12bits. */
28409 temp |= (value & 0x0000f000) << 4;
28410 newimm = value & 0x00000fff;
28411 }
28412 }
28413
28414 if (newimm == (unsigned int) FAIL)
28415 {
28416 as_bad_where (fixP->fx_file, fixP->fx_line,
28417 _("invalid constant (%lx) after fixup"),
28418 (unsigned long) value);
28419 break;
28420 }
28421
28422 newimm |= (temp & 0xfffff000);
28423 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28424 break;
28425
28426 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28427 {
28428 unsigned int highpart = 0;
28429 unsigned int newinsn = 0xe1a00000; /* nop. */
28430
28431 if (fixP->fx_addsy)
28432 {
28433 const char *msg = 0;
28434
28435 if (! S_IS_DEFINED (fixP->fx_addsy))
28436 msg = _("undefined symbol %s used as an immediate value");
28437 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28438 msg = _("symbol %s is in a different section");
28439 else if (S_IS_WEAK (fixP->fx_addsy))
28440 msg = _("symbol %s is weak and may be overridden later");
28441
28442 if (msg)
28443 {
28444 as_bad_where (fixP->fx_file, fixP->fx_line,
28445 msg, S_GET_NAME (fixP->fx_addsy));
28446 break;
28447 }
28448 }
28449
28450 newimm = encode_arm_immediate (value);
28451 temp = md_chars_to_number (buf, INSN_SIZE);
28452
28453 /* If the instruction will fail, see if we can fix things up by
28454 changing the opcode. */
28455 if (newimm == (unsigned int) FAIL
28456 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28457 {
28458 /* No ? OK - try using two ADD instructions to generate
28459 the value. */
28460 newimm = validate_immediate_twopart (value, & highpart);
28461
28462 /* Yes - then make sure that the second instruction is
28463 also an add. */
28464 if (newimm != (unsigned int) FAIL)
28465 newinsn = temp;
28466 /* Still No ? Try using a negated value. */
28467 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28468 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28469 /* Otherwise - give up. */
28470 else
28471 {
28472 as_bad_where (fixP->fx_file, fixP->fx_line,
28473 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28474 (long) value);
28475 break;
28476 }
28477
28478 /* Replace the first operand in the 2nd instruction (which
28479 is the PC) with the destination register. We have
28480 already added in the PC in the first instruction and we
28481 do not want to do it again. */
28482 newinsn &= ~ 0xf0000;
28483 newinsn |= ((newinsn & 0x0f000) << 4);
28484 }
28485
28486 newimm |= (temp & 0xfffff000);
28487 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28488
28489 highpart |= (newinsn & 0xfffff000);
28490 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28491 }
28492 break;
28493
28494 case BFD_RELOC_ARM_OFFSET_IMM:
28495 if (!fixP->fx_done && seg->use_rela_p)
28496 value = 0;
28497 /* Fall through. */
28498
28499 case BFD_RELOC_ARM_LITERAL:
28500 sign = value > 0;
28501
28502 if (value < 0)
28503 value = - value;
28504
28505 if (validate_offset_imm (value, 0) == FAIL)
28506 {
28507 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28508 as_bad_where (fixP->fx_file, fixP->fx_line,
28509 _("invalid literal constant: pool needs to be closer"));
28510 else
28511 as_bad_where (fixP->fx_file, fixP->fx_line,
28512 _("bad immediate value for offset (%ld)"),
28513 (long) value);
28514 break;
28515 }
28516
28517 newval = md_chars_to_number (buf, INSN_SIZE);
28518 if (value == 0)
28519 newval &= 0xfffff000;
28520 else
28521 {
28522 newval &= 0xff7ff000;
28523 newval |= value | (sign ? INDEX_UP : 0);
28524 }
28525 md_number_to_chars (buf, newval, INSN_SIZE);
28526 break;
28527
28528 case BFD_RELOC_ARM_OFFSET_IMM8:
28529 case BFD_RELOC_ARM_HWLITERAL:
28530 sign = value > 0;
28531
28532 if (value < 0)
28533 value = - value;
28534
28535 if (validate_offset_imm (value, 1) == FAIL)
28536 {
28537 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28538 as_bad_where (fixP->fx_file, fixP->fx_line,
28539 _("invalid literal constant: pool needs to be closer"));
28540 else
28541 as_bad_where (fixP->fx_file, fixP->fx_line,
28542 _("bad immediate value for 8-bit offset (%ld)"),
28543 (long) value);
28544 break;
28545 }
28546
28547 newval = md_chars_to_number (buf, INSN_SIZE);
28548 if (value == 0)
28549 newval &= 0xfffff0f0;
28550 else
28551 {
28552 newval &= 0xff7ff0f0;
28553 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28554 }
28555 md_number_to_chars (buf, newval, INSN_SIZE);
28556 break;
28557
28558 case BFD_RELOC_ARM_T32_OFFSET_U8:
28559 if (value < 0 || value > 1020 || value % 4 != 0)
28560 as_bad_where (fixP->fx_file, fixP->fx_line,
28561 _("bad immediate value for offset (%ld)"), (long) value);
28562 value /= 4;
28563
28564 newval = md_chars_to_number (buf+2, THUMB_SIZE);
28565 newval |= value;
28566 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28567 break;
28568
28569 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28570 /* This is a complicated relocation used for all varieties of Thumb32
28571 load/store instruction with immediate offset:
28572
28573 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
28574 *4, optional writeback(W)
28575 (doubleword load/store)
28576
28577 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28578 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28579 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28580 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28581 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28582
28583 Uppercase letters indicate bits that are already encoded at
28584 this point. Lowercase letters are our problem. For the
28585 second block of instructions, the secondary opcode nybble
28586 (bits 8..11) is present, and bit 23 is zero, even if this is
28587 a PC-relative operation. */
28588 newval = md_chars_to_number (buf, THUMB_SIZE);
28589 newval <<= 16;
28590 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
28591
28592 if ((newval & 0xf0000000) == 0xe0000000)
28593 {
28594 /* Doubleword load/store: 8-bit offset, scaled by 4. */
28595 if (value >= 0)
28596 newval |= (1 << 23);
28597 else
28598 value = -value;
28599 if (value % 4 != 0)
28600 {
28601 as_bad_where (fixP->fx_file, fixP->fx_line,
28602 _("offset not a multiple of 4"));
28603 break;
28604 }
28605 value /= 4;
28606 if (value > 0xff)
28607 {
28608 as_bad_where (fixP->fx_file, fixP->fx_line,
28609 _("offset out of range"));
28610 break;
28611 }
28612 newval &= ~0xff;
28613 }
28614 else if ((newval & 0x000f0000) == 0x000f0000)
28615 {
28616 /* PC-relative, 12-bit offset. */
28617 if (value >= 0)
28618 newval |= (1 << 23);
28619 else
28620 value = -value;
28621 if (value > 0xfff)
28622 {
28623 as_bad_where (fixP->fx_file, fixP->fx_line,
28624 _("offset out of range"));
28625 break;
28626 }
28627 newval &= ~0xfff;
28628 }
28629 else if ((newval & 0x00000100) == 0x00000100)
28630 {
28631 /* Writeback: 8-bit, +/- offset. */
28632 if (value >= 0)
28633 newval |= (1 << 9);
28634 else
28635 value = -value;
28636 if (value > 0xff)
28637 {
28638 as_bad_where (fixP->fx_file, fixP->fx_line,
28639 _("offset out of range"));
28640 break;
28641 }
28642 newval &= ~0xff;
28643 }
28644 else if ((newval & 0x00000f00) == 0x00000e00)
28645 {
28646 /* T-instruction: positive 8-bit offset. */
28647 if (value < 0 || value > 0xff)
28648 {
28649 as_bad_where (fixP->fx_file, fixP->fx_line,
28650 _("offset out of range"));
28651 break;
28652 }
28653 newval &= ~0xff;
28654 newval |= value;
28655 }
28656 else
28657 {
28658 /* Positive 12-bit or negative 8-bit offset. */
28659 int limit;
28660 if (value >= 0)
28661 {
28662 newval |= (1 << 23);
28663 limit = 0xfff;
28664 }
28665 else
28666 {
28667 value = -value;
28668 limit = 0xff;
28669 }
28670 if (value > limit)
28671 {
28672 as_bad_where (fixP->fx_file, fixP->fx_line,
28673 _("offset out of range"));
28674 break;
28675 }
28676 newval &= ~limit;
28677 }
28678
28679 newval |= value;
28680 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28681 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28682 break;
28683
28684 case BFD_RELOC_ARM_SHIFT_IMM:
28685 newval = md_chars_to_number (buf, INSN_SIZE);
28686 if (((unsigned long) value) > 32
28687 || (value == 32
28688 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28689 {
28690 as_bad_where (fixP->fx_file, fixP->fx_line,
28691 _("shift expression is too large"));
28692 break;
28693 }
28694
28695 if (value == 0)
28696 /* Shifts of zero must be done as lsl. */
28697 newval &= ~0x60;
28698 else if (value == 32)
28699 value = 0;
28700 newval &= 0xfffff07f;
28701 newval |= (value & 0x1f) << 7;
28702 md_number_to_chars (buf, newval, INSN_SIZE);
28703 break;
28704
28705 case BFD_RELOC_ARM_T32_IMMEDIATE:
28706 case BFD_RELOC_ARM_T32_ADD_IMM:
28707 case BFD_RELOC_ARM_T32_IMM12:
28708 case BFD_RELOC_ARM_T32_ADD_PC12:
28709 /* We claim that this fixup has been processed here,
28710 even if in fact we generate an error because we do
28711 not have a reloc for it, so tc_gen_reloc will reject it. */
28712 fixP->fx_done = 1;
28713
28714 if (fixP->fx_addsy
28715 && ! S_IS_DEFINED (fixP->fx_addsy))
28716 {
28717 as_bad_where (fixP->fx_file, fixP->fx_line,
28718 _("undefined symbol %s used as an immediate value"),
28719 S_GET_NAME (fixP->fx_addsy));
28720 break;
28721 }
28722
28723 newval = md_chars_to_number (buf, THUMB_SIZE);
28724 newval <<= 16;
28725 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
28726
28727 newimm = FAIL;
28728 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28729 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28730 Thumb2 modified immediate encoding (T2). */
28731 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
28732 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28733 {
28734 newimm = encode_thumb32_immediate (value);
28735 if (newimm == (unsigned int) FAIL)
28736 newimm = thumb32_negate_data_op (&newval, value);
28737 }
28738 if (newimm == (unsigned int) FAIL)
28739 {
28740 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
28741 {
28742 /* Turn add/sum into addw/subw. */
28743 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28744 newval = (newval & 0xfeffffff) | 0x02000000;
28745 /* No flat 12-bit imm encoding for addsw/subsw. */
28746 if ((newval & 0x00100000) == 0)
28747 {
28748 /* 12 bit immediate for addw/subw. */
28749 if (value < 0)
28750 {
28751 value = -value;
28752 newval ^= 0x00a00000;
28753 }
28754 if (value > 0xfff)
28755 newimm = (unsigned int) FAIL;
28756 else
28757 newimm = value;
28758 }
28759 }
28760 else
28761 {
28762 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28763 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28764 disassembling, MOV is preferred when there is no encoding
28765 overlap. */
28766 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
28767 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28768 but with the Rn field [19:16] set to 1111. */
28769 && (((newval >> 16) & 0xf) == 0xf)
28770 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28771 && !((newval >> T2_SBIT_SHIFT) & 0x1)
28772 && value >= 0 && value <= 0xffff)
28773 {
28774 /* Toggle bit[25] to change encoding from T2 to T3. */
28775 newval ^= 1 << 25;
28776 /* Clear bits[19:16]. */
28777 newval &= 0xfff0ffff;
28778 /* Encoding high 4bits imm. Code below will encode the
28779 remaining low 12bits. */
28780 newval |= (value & 0x0000f000) << 4;
28781 newimm = value & 0x00000fff;
28782 }
28783 }
28784 }
28785
28786 if (newimm == (unsigned int)FAIL)
28787 {
28788 as_bad_where (fixP->fx_file, fixP->fx_line,
28789 _("invalid constant (%lx) after fixup"),
28790 (unsigned long) value);
28791 break;
28792 }
28793
28794 newval |= (newimm & 0x800) << 15;
28795 newval |= (newimm & 0x700) << 4;
28796 newval |= (newimm & 0x0ff);
28797
28798 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28799 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28800 break;
28801
28802 case BFD_RELOC_ARM_SMC:
28803 if (((unsigned long) value) > 0xf)
28804 as_bad_where (fixP->fx_file, fixP->fx_line,
28805 _("invalid smc expression"));
28806
28807 newval = md_chars_to_number (buf, INSN_SIZE);
28808 newval |= (value & 0xf);
28809 md_number_to_chars (buf, newval, INSN_SIZE);
28810 break;
28811
28812 case BFD_RELOC_ARM_HVC:
28813 if (((unsigned long) value) > 0xffff)
28814 as_bad_where (fixP->fx_file, fixP->fx_line,
28815 _("invalid hvc expression"));
28816 newval = md_chars_to_number (buf, INSN_SIZE);
28817 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28818 md_number_to_chars (buf, newval, INSN_SIZE);
28819 break;
28820
28821 case BFD_RELOC_ARM_SWI:
28822 if (fixP->tc_fix_data != 0)
28823 {
28824 if (((unsigned long) value) > 0xff)
28825 as_bad_where (fixP->fx_file, fixP->fx_line,
28826 _("invalid swi expression"));
28827 newval = md_chars_to_number (buf, THUMB_SIZE);
28828 newval |= value;
28829 md_number_to_chars (buf, newval, THUMB_SIZE);
28830 }
28831 else
28832 {
28833 if (((unsigned long) value) > 0x00ffffff)
28834 as_bad_where (fixP->fx_file, fixP->fx_line,
28835 _("invalid swi expression"));
28836 newval = md_chars_to_number (buf, INSN_SIZE);
28837 newval |= value;
28838 md_number_to_chars (buf, newval, INSN_SIZE);
28839 }
28840 break;
28841
28842 case BFD_RELOC_ARM_MULTI:
28843 if (((unsigned long) value) > 0xffff)
28844 as_bad_where (fixP->fx_file, fixP->fx_line,
28845 _("invalid expression in load/store multiple"));
28846 newval = value | md_chars_to_number (buf, INSN_SIZE);
28847 md_number_to_chars (buf, newval, INSN_SIZE);
28848 break;
28849
28850 #ifdef OBJ_ELF
28851 case BFD_RELOC_ARM_PCREL_CALL:
28852
28853 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28854 && fixP->fx_addsy
28855 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28856 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28857 && THUMB_IS_FUNC (fixP->fx_addsy))
28858 /* Flip the bl to blx. This is a simple flip
28859 bit here because we generate PCREL_CALL for
28860 unconditional bls. */
28861 {
28862 newval = md_chars_to_number (buf, INSN_SIZE);
28863 newval = newval | 0x10000000;
28864 md_number_to_chars (buf, newval, INSN_SIZE);
28865 temp = 1;
28866 fixP->fx_done = 1;
28867 }
28868 else
28869 temp = 3;
28870 goto arm_branch_common;
28871
28872 case BFD_RELOC_ARM_PCREL_JUMP:
28873 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28874 && fixP->fx_addsy
28875 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28876 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28877 && THUMB_IS_FUNC (fixP->fx_addsy))
28878 {
28879 /* This would map to a bl<cond>, b<cond>,
28880 b<always> to a Thumb function. We
28881 need to force a relocation for this particular
28882 case. */
28883 newval = md_chars_to_number (buf, INSN_SIZE);
28884 fixP->fx_done = 0;
28885 }
28886 /* Fall through. */
28887
28888 case BFD_RELOC_ARM_PLT32:
28889 #endif
28890 case BFD_RELOC_ARM_PCREL_BRANCH:
28891 temp = 3;
28892 goto arm_branch_common;
28893
28894 case BFD_RELOC_ARM_PCREL_BLX:
28895
28896 temp = 1;
28897 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28898 && fixP->fx_addsy
28899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28900 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28901 && ARM_IS_FUNC (fixP->fx_addsy))
28902 {
28903 /* Flip the blx to a bl and warn. */
28904 const char *name = S_GET_NAME (fixP->fx_addsy);
28905 newval = 0xeb000000;
28906 as_warn_where (fixP->fx_file, fixP->fx_line,
28907 _("blx to '%s' an ARM ISA state function changed to bl"),
28908 name);
28909 md_number_to_chars (buf, newval, INSN_SIZE);
28910 temp = 3;
28911 fixP->fx_done = 1;
28912 }
28913
28914 #ifdef OBJ_ELF
28915 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
28916 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
28917 #endif
28918
28919 arm_branch_common:
28920 /* We are going to store value (shifted right by two) in the
28921 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28922 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
28923 also be clear. */
28924 if (value & temp)
28925 as_bad_where (fixP->fx_file, fixP->fx_line,
28926 _("misaligned branch destination"));
28927 if ((value & (offsetT)0xfe000000) != (offsetT)0
28928 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
28929 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28930
28931 if (fixP->fx_done || !seg->use_rela_p)
28932 {
28933 newval = md_chars_to_number (buf, INSN_SIZE);
28934 newval |= (value >> 2) & 0x00ffffff;
28935 /* Set the H bit on BLX instructions. */
28936 if (temp == 1)
28937 {
28938 if (value & 2)
28939 newval |= 0x01000000;
28940 else
28941 newval &= ~0x01000000;
28942 }
28943 md_number_to_chars (buf, newval, INSN_SIZE);
28944 }
28945 break;
28946
28947 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28948 /* CBZ can only branch forward. */
28949
28950 /* Attempts to use CBZ to branch to the next instruction
28951 (which, strictly speaking, are prohibited) will be turned into
28952 no-ops.
28953
28954 FIXME: It may be better to remove the instruction completely and
28955 perform relaxation. */
28956 if (value == -2)
28957 {
28958 newval = md_chars_to_number (buf, THUMB_SIZE);
28959 newval = 0xbf00; /* NOP encoding T1 */
28960 md_number_to_chars (buf, newval, THUMB_SIZE);
28961 }
28962 else
28963 {
28964 if (value & ~0x7e)
28965 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28966
28967 if (fixP->fx_done || !seg->use_rela_p)
28968 {
28969 newval = md_chars_to_number (buf, THUMB_SIZE);
28970 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28971 md_number_to_chars (buf, newval, THUMB_SIZE);
28972 }
28973 }
28974 break;
28975
28976 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
28977 if (out_of_range_p (value, 8))
28978 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28979
28980 if (fixP->fx_done || !seg->use_rela_p)
28981 {
28982 newval = md_chars_to_number (buf, THUMB_SIZE);
28983 newval |= (value & 0x1ff) >> 1;
28984 md_number_to_chars (buf, newval, THUMB_SIZE);
28985 }
28986 break;
28987
28988 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
28989 if (out_of_range_p (value, 11))
28990 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28991
28992 if (fixP->fx_done || !seg->use_rela_p)
28993 {
28994 newval = md_chars_to_number (buf, THUMB_SIZE);
28995 newval |= (value & 0xfff) >> 1;
28996 md_number_to_chars (buf, newval, THUMB_SIZE);
28997 }
28998 break;
28999
29000 /* This relocation is misnamed, it should be BRANCH21. */
29001 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29002 if (fixP->fx_addsy
29003 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29004 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29005 && ARM_IS_FUNC (fixP->fx_addsy)
29006 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29007 {
29008 /* Force a relocation for a branch 20 bits wide. */
29009 fixP->fx_done = 0;
29010 }
29011 if (out_of_range_p (value, 20))
29012 as_bad_where (fixP->fx_file, fixP->fx_line,
29013 _("conditional branch out of range"));
29014
29015 if (fixP->fx_done || !seg->use_rela_p)
29016 {
29017 offsetT newval2;
29018 addressT S, J1, J2, lo, hi;
29019
29020 S = (value & 0x00100000) >> 20;
29021 J2 = (value & 0x00080000) >> 19;
29022 J1 = (value & 0x00040000) >> 18;
29023 hi = (value & 0x0003f000) >> 12;
29024 lo = (value & 0x00000ffe) >> 1;
29025
29026 newval = md_chars_to_number (buf, THUMB_SIZE);
29027 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29028 newval |= (S << 10) | hi;
29029 newval2 |= (J1 << 13) | (J2 << 11) | lo;
29030 md_number_to_chars (buf, newval, THUMB_SIZE);
29031 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29032 }
29033 break;
29034
29035 case BFD_RELOC_THUMB_PCREL_BLX:
29036 /* If there is a blx from a thumb state function to
29037 another thumb function flip this to a bl and warn
29038 about it. */
29039
29040 if (fixP->fx_addsy
29041 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29042 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29043 && THUMB_IS_FUNC (fixP->fx_addsy))
29044 {
29045 const char *name = S_GET_NAME (fixP->fx_addsy);
29046 as_warn_where (fixP->fx_file, fixP->fx_line,
29047 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
29048 name);
29049 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29050 newval = newval | 0x1000;
29051 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29052 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29053 fixP->fx_done = 1;
29054 }
29055
29056
29057 goto thumb_bl_common;
29058
29059 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29060 /* A bl from Thumb state ISA to an internal ARM state function
29061 is converted to a blx. */
29062 if (fixP->fx_addsy
29063 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29064 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29065 && ARM_IS_FUNC (fixP->fx_addsy)
29066 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29067 {
29068 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29069 newval = newval & ~0x1000;
29070 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29071 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
29072 fixP->fx_done = 1;
29073 }
29074
29075 thumb_bl_common:
29076
29077 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29078 /* For a BLX instruction, make sure that the relocation is rounded up
29079 to a word boundary. This follows the semantics of the instruction
29080 which specifies that bit 1 of the target address will come from bit
29081 1 of the base address. */
29082 value = (value + 3) & ~ 3;
29083
29084 #ifdef OBJ_ELF
29085 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
29086 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29087 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29088 #endif
29089
29090 if (out_of_range_p (value, 22))
29091 {
29092 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
29093 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29094 else if (out_of_range_p (value, 24))
29095 as_bad_where (fixP->fx_file, fixP->fx_line,
29096 _("Thumb2 branch out of range"));
29097 }
29098
29099 if (fixP->fx_done || !seg->use_rela_p)
29100 encode_thumb2_b_bl_offset (buf, value);
29101
29102 break;
29103
29104 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29105 if (out_of_range_p (value, 24))
29106 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29107
29108 if (fixP->fx_done || !seg->use_rela_p)
29109 encode_thumb2_b_bl_offset (buf, value);
29110
29111 break;
29112
29113 case BFD_RELOC_8:
29114 if (fixP->fx_done || !seg->use_rela_p)
29115 *buf = value;
29116 break;
29117
29118 case BFD_RELOC_16:
29119 if (fixP->fx_done || !seg->use_rela_p)
29120 md_number_to_chars (buf, value, 2);
29121 break;
29122
29123 #ifdef OBJ_ELF
29124 case BFD_RELOC_ARM_TLS_CALL:
29125 case BFD_RELOC_ARM_THM_TLS_CALL:
29126 case BFD_RELOC_ARM_TLS_DESCSEQ:
29127 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
29128 case BFD_RELOC_ARM_TLS_GOTDESC:
29129 case BFD_RELOC_ARM_TLS_GD32:
29130 case BFD_RELOC_ARM_TLS_LE32:
29131 case BFD_RELOC_ARM_TLS_IE32:
29132 case BFD_RELOC_ARM_TLS_LDM32:
29133 case BFD_RELOC_ARM_TLS_LDO32:
29134 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29135 break;
29136
29137 /* Same handling as above, but with the arm_fdpic guard. */
29138 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29139 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29140 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29141 if (arm_fdpic)
29142 {
29143 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29144 }
29145 else
29146 {
29147 as_bad_where (fixP->fx_file, fixP->fx_line,
29148 _("Relocation supported only in FDPIC mode"));
29149 }
29150 break;
29151
29152 case BFD_RELOC_ARM_GOT32:
29153 case BFD_RELOC_ARM_GOTOFF:
29154 break;
29155
29156 case BFD_RELOC_ARM_GOT_PREL:
29157 if (fixP->fx_done || !seg->use_rela_p)
29158 md_number_to_chars (buf, value, 4);
29159 break;
29160
29161 case BFD_RELOC_ARM_TARGET2:
29162 /* TARGET2 is not partial-inplace, so we need to write the
29163 addend here for REL targets, because it won't be written out
29164 during reloc processing later. */
29165 if (fixP->fx_done || !seg->use_rela_p)
29166 md_number_to_chars (buf, fixP->fx_offset, 4);
29167 break;
29168
29169 /* Relocations for FDPIC. */
29170 case BFD_RELOC_ARM_GOTFUNCDESC:
29171 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29172 case BFD_RELOC_ARM_FUNCDESC:
29173 if (arm_fdpic)
29174 {
29175 if (fixP->fx_done || !seg->use_rela_p)
29176 md_number_to_chars (buf, 0, 4);
29177 }
29178 else
29179 {
29180 as_bad_where (fixP->fx_file, fixP->fx_line,
29181 _("Relocation supported only in FDPIC mode"));
29182 }
29183 break;
29184 #endif
29185
29186 case BFD_RELOC_RVA:
29187 case BFD_RELOC_32:
29188 case BFD_RELOC_ARM_TARGET1:
29189 case BFD_RELOC_ARM_ROSEGREL32:
29190 case BFD_RELOC_ARM_SBREL32:
29191 case BFD_RELOC_32_PCREL:
29192 #ifdef TE_PE
29193 case BFD_RELOC_32_SECREL:
29194 #endif
29195 if (fixP->fx_done || !seg->use_rela_p)
29196 #ifdef TE_WINCE
29197 /* For WinCE we only do this for pcrel fixups. */
29198 if (fixP->fx_done || fixP->fx_pcrel)
29199 #endif
29200 md_number_to_chars (buf, value, 4);
29201 break;
29202
29203 #ifdef OBJ_ELF
29204 case BFD_RELOC_ARM_PREL31:
29205 if (fixP->fx_done || !seg->use_rela_p)
29206 {
29207 newval = md_chars_to_number (buf, 4) & 0x80000000;
29208 if ((value ^ (value >> 1)) & 0x40000000)
29209 {
29210 as_bad_where (fixP->fx_file, fixP->fx_line,
29211 _("rel31 relocation overflow"));
29212 }
29213 newval |= value & 0x7fffffff;
29214 md_number_to_chars (buf, newval, 4);
29215 }
29216 break;
29217 #endif
29218
29219 case BFD_RELOC_ARM_CP_OFF_IMM:
29220 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
29221 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
29222 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
29223 newval = md_chars_to_number (buf, INSN_SIZE);
29224 else
29225 newval = get_thumb32_insn (buf);
29226 if ((newval & 0x0f200f00) == 0x0d000900)
29227 {
29228 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
29229 has permitted values that are multiples of 2, in the range 0
29230 to 510. */
29231 if (value < -510 || value > 510 || (value & 1))
29232 as_bad_where (fixP->fx_file, fixP->fx_line,
29233 _("co-processor offset out of range"));
29234 }
29235 else if ((newval & 0xfe001f80) == 0xec000f80)
29236 {
29237 if (value < -511 || value > 512 || (value & 3))
29238 as_bad_where (fixP->fx_file, fixP->fx_line,
29239 _("co-processor offset out of range"));
29240 }
29241 else if (value < -1023 || value > 1023 || (value & 3))
29242 as_bad_where (fixP->fx_file, fixP->fx_line,
29243 _("co-processor offset out of range"));
29244 cp_off_common:
29245 sign = value > 0;
29246 if (value < 0)
29247 value = -value;
29248 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29249 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29250 newval = md_chars_to_number (buf, INSN_SIZE);
29251 else
29252 newval = get_thumb32_insn (buf);
29253 if (value == 0)
29254 {
29255 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29256 newval &= 0xffffff80;
29257 else
29258 newval &= 0xffffff00;
29259 }
29260 else
29261 {
29262 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29263 newval &= 0xff7fff80;
29264 else
29265 newval &= 0xff7fff00;
29266 if ((newval & 0x0f200f00) == 0x0d000900)
29267 {
29268 /* This is a fp16 vstr/vldr.
29269
29270 It requires the immediate offset in the instruction is shifted
29271 left by 1 to be a half-word offset.
29272
29273 Here, left shift by 1 first, and later right shift by 2
29274 should get the right offset. */
29275 value <<= 1;
29276 }
29277 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29278 }
29279 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29280 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29281 md_number_to_chars (buf, newval, INSN_SIZE);
29282 else
29283 put_thumb32_insn (buf, newval);
29284 break;
29285
29286 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
29287 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
29288 if (value < -255 || value > 255)
29289 as_bad_where (fixP->fx_file, fixP->fx_line,
29290 _("co-processor offset out of range"));
29291 value *= 4;
29292 goto cp_off_common;
29293
29294 case BFD_RELOC_ARM_THUMB_OFFSET:
29295 newval = md_chars_to_number (buf, THUMB_SIZE);
29296 /* Exactly what ranges, and where the offset is inserted depends
29297 on the type of instruction, we can establish this from the
29298 top 4 bits. */
29299 switch (newval >> 12)
29300 {
29301 case 4: /* PC load. */
29302 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29303 forced to zero for these loads; md_pcrel_from has already
29304 compensated for this. */
29305 if (value & 3)
29306 as_bad_where (fixP->fx_file, fixP->fx_line,
29307 _("invalid offset, target not word aligned (0x%08lX)"),
29308 (((unsigned long) fixP->fx_frag->fr_address
29309 + (unsigned long) fixP->fx_where) & ~3)
29310 + (unsigned long) value);
29311
29312 if (value & ~0x3fc)
29313 as_bad_where (fixP->fx_file, fixP->fx_line,
29314 _("invalid offset, value too big (0x%08lX)"),
29315 (long) value);
29316
29317 newval |= value >> 2;
29318 break;
29319
29320 case 9: /* SP load/store. */
29321 if (value & ~0x3fc)
29322 as_bad_where (fixP->fx_file, fixP->fx_line,
29323 _("invalid offset, value too big (0x%08lX)"),
29324 (long) value);
29325 newval |= value >> 2;
29326 break;
29327
29328 case 6: /* Word load/store. */
29329 if (value & ~0x7c)
29330 as_bad_where (fixP->fx_file, fixP->fx_line,
29331 _("invalid offset, value too big (0x%08lX)"),
29332 (long) value);
29333 newval |= value << 4; /* 6 - 2. */
29334 break;
29335
29336 case 7: /* Byte load/store. */
29337 if (value & ~0x1f)
29338 as_bad_where (fixP->fx_file, fixP->fx_line,
29339 _("invalid offset, value too big (0x%08lX)"),
29340 (long) value);
29341 newval |= value << 6;
29342 break;
29343
29344 case 8: /* Halfword load/store. */
29345 if (value & ~0x3e)
29346 as_bad_where (fixP->fx_file, fixP->fx_line,
29347 _("invalid offset, value too big (0x%08lX)"),
29348 (long) value);
29349 newval |= value << 5; /* 6 - 1. */
29350 break;
29351
29352 default:
29353 as_bad_where (fixP->fx_file, fixP->fx_line,
29354 "Unable to process relocation for thumb opcode: %lx",
29355 (unsigned long) newval);
29356 break;
29357 }
29358 md_number_to_chars (buf, newval, THUMB_SIZE);
29359 break;
29360
29361 case BFD_RELOC_ARM_THUMB_ADD:
29362 /* This is a complicated relocation, since we use it for all of
29363 the following immediate relocations:
29364
29365 3bit ADD/SUB
29366 8bit ADD/SUB
29367 9bit ADD/SUB SP word-aligned
29368 10bit ADD PC/SP word-aligned
29369
29370 The type of instruction being processed is encoded in the
29371 instruction field:
29372
29373 0x8000 SUB
29374 0x00F0 Rd
29375 0x000F Rs
29376 */
29377 newval = md_chars_to_number (buf, THUMB_SIZE);
29378 {
29379 int rd = (newval >> 4) & 0xf;
29380 int rs = newval & 0xf;
29381 int subtract = !!(newval & 0x8000);
29382
29383 /* Check for HI regs, only very restricted cases allowed:
29384 Adjusting SP, and using PC or SP to get an address. */
29385 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29386 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29387 as_bad_where (fixP->fx_file, fixP->fx_line,
29388 _("invalid Hi register with immediate"));
29389
29390 /* If value is negative, choose the opposite instruction. */
29391 if (value < 0)
29392 {
29393 value = -value;
29394 subtract = !subtract;
29395 if (value < 0)
29396 as_bad_where (fixP->fx_file, fixP->fx_line,
29397 _("immediate value out of range"));
29398 }
29399
29400 if (rd == REG_SP)
29401 {
29402 if (value & ~0x1fc)
29403 as_bad_where (fixP->fx_file, fixP->fx_line,
29404 _("invalid immediate for stack address calculation"));
29405 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29406 newval |= value >> 2;
29407 }
29408 else if (rs == REG_PC || rs == REG_SP)
29409 {
29410 /* PR gas/18541. If the addition is for a defined symbol
29411 within range of an ADR instruction then accept it. */
29412 if (subtract
29413 && value == 4
29414 && fixP->fx_addsy != NULL)
29415 {
29416 subtract = 0;
29417
29418 if (! S_IS_DEFINED (fixP->fx_addsy)
29419 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29420 || S_IS_WEAK (fixP->fx_addsy))
29421 {
29422 as_bad_where (fixP->fx_file, fixP->fx_line,
29423 _("address calculation needs a strongly defined nearby symbol"));
29424 }
29425 else
29426 {
29427 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29428
29429 /* Round up to the next 4-byte boundary. */
29430 if (v & 3)
29431 v = (v + 3) & ~ 3;
29432 else
29433 v += 4;
29434 v = S_GET_VALUE (fixP->fx_addsy) - v;
29435
29436 if (v & ~0x3fc)
29437 {
29438 as_bad_where (fixP->fx_file, fixP->fx_line,
29439 _("symbol too far away"));
29440 }
29441 else
29442 {
29443 fixP->fx_done = 1;
29444 value = v;
29445 }
29446 }
29447 }
29448
29449 if (subtract || value & ~0x3fc)
29450 as_bad_where (fixP->fx_file, fixP->fx_line,
29451 _("invalid immediate for address calculation (value = 0x%08lX)"),
29452 (unsigned long) (subtract ? - value : value));
29453 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29454 newval |= rd << 8;
29455 newval |= value >> 2;
29456 }
29457 else if (rs == rd)
29458 {
29459 if (value & ~0xff)
29460 as_bad_where (fixP->fx_file, fixP->fx_line,
29461 _("immediate value out of range"));
29462 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29463 newval |= (rd << 8) | value;
29464 }
29465 else
29466 {
29467 if (value & ~0x7)
29468 as_bad_where (fixP->fx_file, fixP->fx_line,
29469 _("immediate value out of range"));
29470 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29471 newval |= rd | (rs << 3) | (value << 6);
29472 }
29473 }
29474 md_number_to_chars (buf, newval, THUMB_SIZE);
29475 break;
29476
29477 case BFD_RELOC_ARM_THUMB_IMM:
29478 newval = md_chars_to_number (buf, THUMB_SIZE);
29479 if (value < 0 || value > 255)
29480 as_bad_where (fixP->fx_file, fixP->fx_line,
29481 _("invalid immediate: %ld is out of range"),
29482 (long) value);
29483 newval |= value;
29484 md_number_to_chars (buf, newval, THUMB_SIZE);
29485 break;
29486
29487 case BFD_RELOC_ARM_THUMB_SHIFT:
29488 /* 5bit shift value (0..32). LSL cannot take 32. */
29489 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29490 temp = newval & 0xf800;
29491 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
29492 as_bad_where (fixP->fx_file, fixP->fx_line,
29493 _("invalid shift value: %ld"), (long) value);
29494 /* Shifts of zero must be encoded as LSL. */
29495 if (value == 0)
29496 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29497 /* Shifts of 32 are encoded as zero. */
29498 else if (value == 32)
29499 value = 0;
29500 newval |= value << 6;
29501 md_number_to_chars (buf, newval, THUMB_SIZE);
29502 break;
29503
29504 case BFD_RELOC_VTABLE_INHERIT:
29505 case BFD_RELOC_VTABLE_ENTRY:
29506 fixP->fx_done = 0;
29507 return;
29508
29509 case BFD_RELOC_ARM_MOVW:
29510 case BFD_RELOC_ARM_MOVT:
29511 case BFD_RELOC_ARM_THUMB_MOVW:
29512 case BFD_RELOC_ARM_THUMB_MOVT:
29513 if (fixP->fx_done || !seg->use_rela_p)
29514 {
29515 /* REL format relocations are limited to a 16-bit addend. */
29516 if (!fixP->fx_done)
29517 {
29518 if (value < -0x8000 || value > 0x7fff)
29519 as_bad_where (fixP->fx_file, fixP->fx_line,
29520 _("offset out of range"));
29521 }
29522 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29523 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29524 {
29525 value >>= 16;
29526 }
29527
29528 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29529 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29530 {
29531 newval = get_thumb32_insn (buf);
29532 newval &= 0xfbf08f00;
29533 newval |= (value & 0xf000) << 4;
29534 newval |= (value & 0x0800) << 15;
29535 newval |= (value & 0x0700) << 4;
29536 newval |= (value & 0x00ff);
29537 put_thumb32_insn (buf, newval);
29538 }
29539 else
29540 {
29541 newval = md_chars_to_number (buf, 4);
29542 newval &= 0xfff0f000;
29543 newval |= value & 0x0fff;
29544 newval |= (value & 0xf000) << 4;
29545 md_number_to_chars (buf, newval, 4);
29546 }
29547 }
29548 return;
29549
29550 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29551 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29552 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29553 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29554 gas_assert (!fixP->fx_done);
29555 {
29556 bfd_vma insn;
29557 bfd_boolean is_mov;
29558 bfd_vma encoded_addend = value;
29559
29560 /* Check that addend can be encoded in instruction. */
29561 if (!seg->use_rela_p && (value < 0 || value > 255))
29562 as_bad_where (fixP->fx_file, fixP->fx_line,
29563 _("the offset 0x%08lX is not representable"),
29564 (unsigned long) encoded_addend);
29565
29566 /* Extract the instruction. */
29567 insn = md_chars_to_number (buf, THUMB_SIZE);
29568 is_mov = (insn & 0xf800) == 0x2000;
29569
29570 /* Encode insn. */
29571 if (is_mov)
29572 {
29573 if (!seg->use_rela_p)
29574 insn |= encoded_addend;
29575 }
29576 else
29577 {
29578 int rd, rs;
29579
29580 /* Extract the instruction. */
29581 /* Encoding is the following
29582 0x8000 SUB
29583 0x00F0 Rd
29584 0x000F Rs
29585 */
29586 /* The following conditions must be true :
29587 - ADD
29588 - Rd == Rs
29589 - Rd <= 7
29590 */
29591 rd = (insn >> 4) & 0xf;
29592 rs = insn & 0xf;
29593 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29594 as_bad_where (fixP->fx_file, fixP->fx_line,
29595 _("Unable to process relocation for thumb opcode: %lx"),
29596 (unsigned long) insn);
29597
29598 /* Encode as ADD immediate8 thumb 1 code. */
29599 insn = 0x3000 | (rd << 8);
29600
29601 /* Place the encoded addend into the first 8 bits of the
29602 instruction. */
29603 if (!seg->use_rela_p)
29604 insn |= encoded_addend;
29605 }
29606
29607 /* Update the instruction. */
29608 md_number_to_chars (buf, insn, THUMB_SIZE);
29609 }
29610 break;
29611
29612 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29613 case BFD_RELOC_ARM_ALU_PC_G0:
29614 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29615 case BFD_RELOC_ARM_ALU_PC_G1:
29616 case BFD_RELOC_ARM_ALU_PC_G2:
29617 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29618 case BFD_RELOC_ARM_ALU_SB_G0:
29619 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29620 case BFD_RELOC_ARM_ALU_SB_G1:
29621 case BFD_RELOC_ARM_ALU_SB_G2:
29622 gas_assert (!fixP->fx_done);
29623 if (!seg->use_rela_p)
29624 {
29625 bfd_vma insn;
29626 bfd_vma encoded_addend;
29627 bfd_vma addend_abs = llabs (value);
29628
29629 /* Check that the absolute value of the addend can be
29630 expressed as an 8-bit constant plus a rotation. */
29631 encoded_addend = encode_arm_immediate (addend_abs);
29632 if (encoded_addend == (unsigned int) FAIL)
29633 as_bad_where (fixP->fx_file, fixP->fx_line,
29634 _("the offset 0x%08lX is not representable"),
29635 (unsigned long) addend_abs);
29636
29637 /* Extract the instruction. */
29638 insn = md_chars_to_number (buf, INSN_SIZE);
29639
29640 /* If the addend is positive, use an ADD instruction.
29641 Otherwise use a SUB. Take care not to destroy the S bit. */
29642 insn &= 0xff1fffff;
29643 if (value < 0)
29644 insn |= 1 << 22;
29645 else
29646 insn |= 1 << 23;
29647
29648 /* Place the encoded addend into the first 12 bits of the
29649 instruction. */
29650 insn &= 0xfffff000;
29651 insn |= encoded_addend;
29652
29653 /* Update the instruction. */
29654 md_number_to_chars (buf, insn, INSN_SIZE);
29655 }
29656 break;
29657
29658 case BFD_RELOC_ARM_LDR_PC_G0:
29659 case BFD_RELOC_ARM_LDR_PC_G1:
29660 case BFD_RELOC_ARM_LDR_PC_G2:
29661 case BFD_RELOC_ARM_LDR_SB_G0:
29662 case BFD_RELOC_ARM_LDR_SB_G1:
29663 case BFD_RELOC_ARM_LDR_SB_G2:
29664 gas_assert (!fixP->fx_done);
29665 if (!seg->use_rela_p)
29666 {
29667 bfd_vma insn;
29668 bfd_vma addend_abs = llabs (value);
29669
29670 /* Check that the absolute value of the addend can be
29671 encoded in 12 bits. */
29672 if (addend_abs >= 0x1000)
29673 as_bad_where (fixP->fx_file, fixP->fx_line,
29674 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29675 (unsigned long) addend_abs);
29676
29677 /* Extract the instruction. */
29678 insn = md_chars_to_number (buf, INSN_SIZE);
29679
29680 /* If the addend is negative, clear bit 23 of the instruction.
29681 Otherwise set it. */
29682 if (value < 0)
29683 insn &= ~(1 << 23);
29684 else
29685 insn |= 1 << 23;
29686
29687 /* Place the absolute value of the addend into the first 12 bits
29688 of the instruction. */
29689 insn &= 0xfffff000;
29690 insn |= addend_abs;
29691
29692 /* Update the instruction. */
29693 md_number_to_chars (buf, insn, INSN_SIZE);
29694 }
29695 break;
29696
29697 case BFD_RELOC_ARM_LDRS_PC_G0:
29698 case BFD_RELOC_ARM_LDRS_PC_G1:
29699 case BFD_RELOC_ARM_LDRS_PC_G2:
29700 case BFD_RELOC_ARM_LDRS_SB_G0:
29701 case BFD_RELOC_ARM_LDRS_SB_G1:
29702 case BFD_RELOC_ARM_LDRS_SB_G2:
29703 gas_assert (!fixP->fx_done);
29704 if (!seg->use_rela_p)
29705 {
29706 bfd_vma insn;
29707 bfd_vma addend_abs = llabs (value);
29708
29709 /* Check that the absolute value of the addend can be
29710 encoded in 8 bits. */
29711 if (addend_abs >= 0x100)
29712 as_bad_where (fixP->fx_file, fixP->fx_line,
29713 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29714 (unsigned long) addend_abs);
29715
29716 /* Extract the instruction. */
29717 insn = md_chars_to_number (buf, INSN_SIZE);
29718
29719 /* If the addend is negative, clear bit 23 of the instruction.
29720 Otherwise set it. */
29721 if (value < 0)
29722 insn &= ~(1 << 23);
29723 else
29724 insn |= 1 << 23;
29725
29726 /* Place the first four bits of the absolute value of the addend
29727 into the first 4 bits of the instruction, and the remaining
29728 four into bits 8 .. 11. */
29729 insn &= 0xfffff0f0;
29730 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29731
29732 /* Update the instruction. */
29733 md_number_to_chars (buf, insn, INSN_SIZE);
29734 }
29735 break;
29736
29737 case BFD_RELOC_ARM_LDC_PC_G0:
29738 case BFD_RELOC_ARM_LDC_PC_G1:
29739 case BFD_RELOC_ARM_LDC_PC_G2:
29740 case BFD_RELOC_ARM_LDC_SB_G0:
29741 case BFD_RELOC_ARM_LDC_SB_G1:
29742 case BFD_RELOC_ARM_LDC_SB_G2:
29743 gas_assert (!fixP->fx_done);
29744 if (!seg->use_rela_p)
29745 {
29746 bfd_vma insn;
29747 bfd_vma addend_abs = llabs (value);
29748
29749 /* Check that the absolute value of the addend is a multiple of
29750 four and, when divided by four, fits in 8 bits. */
29751 if (addend_abs & 0x3)
29752 as_bad_where (fixP->fx_file, fixP->fx_line,
29753 _("bad offset 0x%08lX (must be word-aligned)"),
29754 (unsigned long) addend_abs);
29755
29756 if ((addend_abs >> 2) > 0xff)
29757 as_bad_where (fixP->fx_file, fixP->fx_line,
29758 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29759 (unsigned long) addend_abs);
29760
29761 /* Extract the instruction. */
29762 insn = md_chars_to_number (buf, INSN_SIZE);
29763
29764 /* If the addend is negative, clear bit 23 of the instruction.
29765 Otherwise set it. */
29766 if (value < 0)
29767 insn &= ~(1 << 23);
29768 else
29769 insn |= 1 << 23;
29770
29771 /* Place the addend (divided by four) into the first eight
29772 bits of the instruction. */
29773 insn &= 0xfffffff0;
29774 insn |= addend_abs >> 2;
29775
29776 /* Update the instruction. */
29777 md_number_to_chars (buf, insn, INSN_SIZE);
29778 }
29779 break;
29780
29781 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29782 if (fixP->fx_addsy
29783 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29784 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29785 && ARM_IS_FUNC (fixP->fx_addsy)
29786 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29787 {
29788 /* Force a relocation for a branch 5 bits wide. */
29789 fixP->fx_done = 0;
29790 }
29791 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
29792 as_bad_where (fixP->fx_file, fixP->fx_line,
29793 BAD_BRANCH_OFF);
29794
29795 if (fixP->fx_done || !seg->use_rela_p)
29796 {
29797 addressT boff = value >> 1;
29798
29799 newval = md_chars_to_number (buf, THUMB_SIZE);
29800 newval |= (boff << 7);
29801 md_number_to_chars (buf, newval, THUMB_SIZE);
29802 }
29803 break;
29804
29805 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29806 if (fixP->fx_addsy
29807 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29808 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29809 && ARM_IS_FUNC (fixP->fx_addsy)
29810 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29811 {
29812 fixP->fx_done = 0;
29813 }
29814 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
29815 as_bad_where (fixP->fx_file, fixP->fx_line,
29816 _("branch out of range"));
29817
29818 if (fixP->fx_done || !seg->use_rela_p)
29819 {
29820 newval = md_chars_to_number (buf, THUMB_SIZE);
29821
29822 addressT boff = ((newval & 0x0780) >> 7) << 1;
29823 addressT diff = value - boff;
29824
29825 if (diff == 4)
29826 {
29827 newval |= 1 << 1; /* T bit. */
29828 }
29829 else if (diff != 2)
29830 {
29831 as_bad_where (fixP->fx_file, fixP->fx_line,
29832 _("out of range label-relative fixup value"));
29833 }
29834 md_number_to_chars (buf, newval, THUMB_SIZE);
29835 }
29836 break;
29837
29838 case BFD_RELOC_ARM_THUMB_BF17:
29839 if (fixP->fx_addsy
29840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29841 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29842 && ARM_IS_FUNC (fixP->fx_addsy)
29843 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29844 {
29845 /* Force a relocation for a branch 17 bits wide. */
29846 fixP->fx_done = 0;
29847 }
29848
29849 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
29850 as_bad_where (fixP->fx_file, fixP->fx_line,
29851 BAD_BRANCH_OFF);
29852
29853 if (fixP->fx_done || !seg->use_rela_p)
29854 {
29855 offsetT newval2;
29856 addressT immA, immB, immC;
29857
29858 immA = (value & 0x0001f000) >> 12;
29859 immB = (value & 0x00000ffc) >> 2;
29860 immC = (value & 0x00000002) >> 1;
29861
29862 newval = md_chars_to_number (buf, THUMB_SIZE);
29863 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29864 newval |= immA;
29865 newval2 |= (immC << 11) | (immB << 1);
29866 md_number_to_chars (buf, newval, THUMB_SIZE);
29867 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29868 }
29869 break;
29870
29871 case BFD_RELOC_ARM_THUMB_BF19:
29872 if (fixP->fx_addsy
29873 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29874 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29875 && ARM_IS_FUNC (fixP->fx_addsy)
29876 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29877 {
29878 /* Force a relocation for a branch 19 bits wide. */
29879 fixP->fx_done = 0;
29880 }
29881
29882 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
29883 as_bad_where (fixP->fx_file, fixP->fx_line,
29884 BAD_BRANCH_OFF);
29885
29886 if (fixP->fx_done || !seg->use_rela_p)
29887 {
29888 offsetT newval2;
29889 addressT immA, immB, immC;
29890
29891 immA = (value & 0x0007f000) >> 12;
29892 immB = (value & 0x00000ffc) >> 2;
29893 immC = (value & 0x00000002) >> 1;
29894
29895 newval = md_chars_to_number (buf, THUMB_SIZE);
29896 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29897 newval |= immA;
29898 newval2 |= (immC << 11) | (immB << 1);
29899 md_number_to_chars (buf, newval, THUMB_SIZE);
29900 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29901 }
29902 break;
29903
29904 case BFD_RELOC_ARM_THUMB_BF13:
29905 if (fixP->fx_addsy
29906 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29907 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29908 && ARM_IS_FUNC (fixP->fx_addsy)
29909 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29910 {
29911 /* Force a relocation for a branch 13 bits wide. */
29912 fixP->fx_done = 0;
29913 }
29914
29915 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29916 as_bad_where (fixP->fx_file, fixP->fx_line,
29917 BAD_BRANCH_OFF);
29918
29919 if (fixP->fx_done || !seg->use_rela_p)
29920 {
29921 offsetT newval2;
29922 addressT immA, immB, immC;
29923
29924 immA = (value & 0x00001000) >> 12;
29925 immB = (value & 0x00000ffc) >> 2;
29926 immC = (value & 0x00000002) >> 1;
29927
29928 newval = md_chars_to_number (buf, THUMB_SIZE);
29929 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29930 newval |= immA;
29931 newval2 |= (immC << 11) | (immB << 1);
29932 md_number_to_chars (buf, newval, THUMB_SIZE);
29933 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29934 }
29935 break;
29936
29937 case BFD_RELOC_ARM_THUMB_LOOP12:
29938 if (fixP->fx_addsy
29939 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29940 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29941 && ARM_IS_FUNC (fixP->fx_addsy)
29942 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29943 {
29944 /* Force a relocation for a branch 12 bits wide. */
29945 fixP->fx_done = 0;
29946 }
29947
29948 bfd_vma insn = get_thumb32_insn (buf);
29949 /* le lr, <label>, le <label> or letp lr, <label> */
29950 if (((insn & 0xffffffff) == 0xf00fc001)
29951 || ((insn & 0xffffffff) == 0xf02fc001)
29952 || ((insn & 0xffffffff) == 0xf01fc001))
29953 value = -value;
29954
29955 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29956 as_bad_where (fixP->fx_file, fixP->fx_line,
29957 BAD_BRANCH_OFF);
29958 if (fixP->fx_done || !seg->use_rela_p)
29959 {
29960 addressT imml, immh;
29961
29962 immh = (value & 0x00000ffc) >> 2;
29963 imml = (value & 0x00000002) >> 1;
29964
29965 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29966 newval |= (imml << 11) | (immh << 1);
29967 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29968 }
29969 break;
29970
29971 case BFD_RELOC_ARM_V4BX:
29972 /* This will need to go in the object file. */
29973 fixP->fx_done = 0;
29974 break;
29975
29976 case BFD_RELOC_UNUSED:
29977 default:
29978 as_bad_where (fixP->fx_file, fixP->fx_line,
29979 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29980 }
29981 }
29982
29983 /* Translate internal representation of relocation info to BFD target
29984 format. */
29985
29986 arelent *
29987 tc_gen_reloc (asection *section, fixS *fixp)
29988 {
29989 arelent * reloc;
29990 bfd_reloc_code_real_type code;
29991
29992 reloc = XNEW (arelent);
29993
29994 reloc->sym_ptr_ptr = XNEW (asymbol *);
29995 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29996 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
29997
29998 if (fixp->fx_pcrel)
29999 {
30000 if (section->use_rela_p)
30001 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
30002 else
30003 fixp->fx_offset = reloc->address;
30004 }
30005 reloc->addend = fixp->fx_offset;
30006
30007 switch (fixp->fx_r_type)
30008 {
30009 case BFD_RELOC_8:
30010 if (fixp->fx_pcrel)
30011 {
30012 code = BFD_RELOC_8_PCREL;
30013 break;
30014 }
30015 /* Fall through. */
30016
30017 case BFD_RELOC_16:
30018 if (fixp->fx_pcrel)
30019 {
30020 code = BFD_RELOC_16_PCREL;
30021 break;
30022 }
30023 /* Fall through. */
30024
30025 case BFD_RELOC_32:
30026 if (fixp->fx_pcrel)
30027 {
30028 code = BFD_RELOC_32_PCREL;
30029 break;
30030 }
30031 /* Fall through. */
30032
30033 case BFD_RELOC_ARM_MOVW:
30034 if (fixp->fx_pcrel)
30035 {
30036 code = BFD_RELOC_ARM_MOVW_PCREL;
30037 break;
30038 }
30039 /* Fall through. */
30040
30041 case BFD_RELOC_ARM_MOVT:
30042 if (fixp->fx_pcrel)
30043 {
30044 code = BFD_RELOC_ARM_MOVT_PCREL;
30045 break;
30046 }
30047 /* Fall through. */
30048
30049 case BFD_RELOC_ARM_THUMB_MOVW:
30050 if (fixp->fx_pcrel)
30051 {
30052 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30053 break;
30054 }
30055 /* Fall through. */
30056
30057 case BFD_RELOC_ARM_THUMB_MOVT:
30058 if (fixp->fx_pcrel)
30059 {
30060 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30061 break;
30062 }
30063 /* Fall through. */
30064
30065 case BFD_RELOC_NONE:
30066 case BFD_RELOC_ARM_PCREL_BRANCH:
30067 case BFD_RELOC_ARM_PCREL_BLX:
30068 case BFD_RELOC_RVA:
30069 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30070 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30071 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30072 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30073 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30074 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30075 case BFD_RELOC_VTABLE_ENTRY:
30076 case BFD_RELOC_VTABLE_INHERIT:
30077 #ifdef TE_PE
30078 case BFD_RELOC_32_SECREL:
30079 #endif
30080 code = fixp->fx_r_type;
30081 break;
30082
30083 case BFD_RELOC_THUMB_PCREL_BLX:
30084 #ifdef OBJ_ELF
30085 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30086 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30087 else
30088 #endif
30089 code = BFD_RELOC_THUMB_PCREL_BLX;
30090 break;
30091
30092 case BFD_RELOC_ARM_LITERAL:
30093 case BFD_RELOC_ARM_HWLITERAL:
30094 /* If this is called then the a literal has
30095 been referenced across a section boundary. */
30096 as_bad_where (fixp->fx_file, fixp->fx_line,
30097 _("literal referenced across section boundary"));
30098 return NULL;
30099
30100 #ifdef OBJ_ELF
30101 case BFD_RELOC_ARM_TLS_CALL:
30102 case BFD_RELOC_ARM_THM_TLS_CALL:
30103 case BFD_RELOC_ARM_TLS_DESCSEQ:
30104 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
30105 case BFD_RELOC_ARM_GOT32:
30106 case BFD_RELOC_ARM_GOTOFF:
30107 case BFD_RELOC_ARM_GOT_PREL:
30108 case BFD_RELOC_ARM_PLT32:
30109 case BFD_RELOC_ARM_TARGET1:
30110 case BFD_RELOC_ARM_ROSEGREL32:
30111 case BFD_RELOC_ARM_SBREL32:
30112 case BFD_RELOC_ARM_PREL31:
30113 case BFD_RELOC_ARM_TARGET2:
30114 case BFD_RELOC_ARM_TLS_LDO32:
30115 case BFD_RELOC_ARM_PCREL_CALL:
30116 case BFD_RELOC_ARM_PCREL_JUMP:
30117 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30118 case BFD_RELOC_ARM_ALU_PC_G0:
30119 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30120 case BFD_RELOC_ARM_ALU_PC_G1:
30121 case BFD_RELOC_ARM_ALU_PC_G2:
30122 case BFD_RELOC_ARM_LDR_PC_G0:
30123 case BFD_RELOC_ARM_LDR_PC_G1:
30124 case BFD_RELOC_ARM_LDR_PC_G2:
30125 case BFD_RELOC_ARM_LDRS_PC_G0:
30126 case BFD_RELOC_ARM_LDRS_PC_G1:
30127 case BFD_RELOC_ARM_LDRS_PC_G2:
30128 case BFD_RELOC_ARM_LDC_PC_G0:
30129 case BFD_RELOC_ARM_LDC_PC_G1:
30130 case BFD_RELOC_ARM_LDC_PC_G2:
30131 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30132 case BFD_RELOC_ARM_ALU_SB_G0:
30133 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30134 case BFD_RELOC_ARM_ALU_SB_G1:
30135 case BFD_RELOC_ARM_ALU_SB_G2:
30136 case BFD_RELOC_ARM_LDR_SB_G0:
30137 case BFD_RELOC_ARM_LDR_SB_G1:
30138 case BFD_RELOC_ARM_LDR_SB_G2:
30139 case BFD_RELOC_ARM_LDRS_SB_G0:
30140 case BFD_RELOC_ARM_LDRS_SB_G1:
30141 case BFD_RELOC_ARM_LDRS_SB_G2:
30142 case BFD_RELOC_ARM_LDC_SB_G0:
30143 case BFD_RELOC_ARM_LDC_SB_G1:
30144 case BFD_RELOC_ARM_LDC_SB_G2:
30145 case BFD_RELOC_ARM_V4BX:
30146 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30147 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30148 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30149 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
30150 case BFD_RELOC_ARM_GOTFUNCDESC:
30151 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30152 case BFD_RELOC_ARM_FUNCDESC:
30153 case BFD_RELOC_ARM_THUMB_BF17:
30154 case BFD_RELOC_ARM_THUMB_BF19:
30155 case BFD_RELOC_ARM_THUMB_BF13:
30156 code = fixp->fx_r_type;
30157 break;
30158
30159 case BFD_RELOC_ARM_TLS_GOTDESC:
30160 case BFD_RELOC_ARM_TLS_GD32:
30161 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
30162 case BFD_RELOC_ARM_TLS_LE32:
30163 case BFD_RELOC_ARM_TLS_IE32:
30164 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
30165 case BFD_RELOC_ARM_TLS_LDM32:
30166 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
30167 /* BFD will include the symbol's address in the addend.
30168 But we don't want that, so subtract it out again here. */
30169 if (!S_IS_COMMON (fixp->fx_addsy))
30170 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30171 code = fixp->fx_r_type;
30172 break;
30173 #endif
30174
30175 case BFD_RELOC_ARM_IMMEDIATE:
30176 as_bad_where (fixp->fx_file, fixp->fx_line,
30177 _("internal relocation (type: IMMEDIATE) not fixed up"));
30178 return NULL;
30179
30180 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30181 as_bad_where (fixp->fx_file, fixp->fx_line,
30182 _("ADRL used for a symbol not defined in the same file"));
30183 return NULL;
30184
30185 case BFD_RELOC_THUMB_PCREL_BRANCH5:
30186 case BFD_RELOC_THUMB_PCREL_BFCSEL:
30187 case BFD_RELOC_ARM_THUMB_LOOP12:
30188 as_bad_where (fixp->fx_file, fixp->fx_line,
30189 _("%s used for a symbol not defined in the same file"),
30190 bfd_get_reloc_code_name (fixp->fx_r_type));
30191 return NULL;
30192
30193 case BFD_RELOC_ARM_OFFSET_IMM:
30194 if (section->use_rela_p)
30195 {
30196 code = fixp->fx_r_type;
30197 break;
30198 }
30199
30200 if (fixp->fx_addsy != NULL
30201 && !S_IS_DEFINED (fixp->fx_addsy)
30202 && S_IS_LOCAL (fixp->fx_addsy))
30203 {
30204 as_bad_where (fixp->fx_file, fixp->fx_line,
30205 _("undefined local label `%s'"),
30206 S_GET_NAME (fixp->fx_addsy));
30207 return NULL;
30208 }
30209
30210 as_bad_where (fixp->fx_file, fixp->fx_line,
30211 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30212 return NULL;
30213
30214 default:
30215 {
30216 const char * type;
30217
30218 switch (fixp->fx_r_type)
30219 {
30220 case BFD_RELOC_NONE: type = "NONE"; break;
30221 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30222 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
30223 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
30224 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30225 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30226 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
30227 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
30228 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
30229 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30230 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30231 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30232 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30233 default: type = _("<unknown>"); break;
30234 }
30235 as_bad_where (fixp->fx_file, fixp->fx_line,
30236 _("cannot represent %s relocation in this object file format"),
30237 type);
30238 return NULL;
30239 }
30240 }
30241
30242 #ifdef OBJ_ELF
30243 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30244 && GOT_symbol
30245 && fixp->fx_addsy == GOT_symbol)
30246 {
30247 code = BFD_RELOC_ARM_GOTPC;
30248 reloc->addend = fixp->fx_offset = reloc->address;
30249 }
30250 #endif
30251
30252 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
30253
30254 if (reloc->howto == NULL)
30255 {
30256 as_bad_where (fixp->fx_file, fixp->fx_line,
30257 _("cannot represent %s relocation in this object file format"),
30258 bfd_get_reloc_code_name (code));
30259 return NULL;
30260 }
30261
30262 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30263 vtable entry to be used in the relocation's section offset. */
30264 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30265 reloc->address = fixp->fx_offset;
30266
30267 return reloc;
30268 }
30269
30270 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
30271
30272 void
30273 cons_fix_new_arm (fragS * frag,
30274 int where,
30275 int size,
30276 expressionS * exp,
30277 bfd_reloc_code_real_type reloc)
30278 {
30279 int pcrel = 0;
30280
30281 /* Pick a reloc.
30282 FIXME: @@ Should look at CPU word size. */
30283 switch (size)
30284 {
30285 case 1:
30286 reloc = BFD_RELOC_8;
30287 break;
30288 case 2:
30289 reloc = BFD_RELOC_16;
30290 break;
30291 case 4:
30292 default:
30293 reloc = BFD_RELOC_32;
30294 break;
30295 case 8:
30296 reloc = BFD_RELOC_64;
30297 break;
30298 }
30299
30300 #ifdef TE_PE
30301 if (exp->X_op == O_secrel)
30302 {
30303 exp->X_op = O_symbol;
30304 reloc = BFD_RELOC_32_SECREL;
30305 }
30306 #endif
30307
30308 fix_new_exp (frag, where, size, exp, pcrel, reloc);
30309 }
30310
30311 #if defined (OBJ_COFF)
30312 void
30313 arm_validate_fix (fixS * fixP)
30314 {
30315 /* If the destination of the branch is a defined symbol which does not have
30316 the THUMB_FUNC attribute, then we must be calling a function which has
30317 the (interfacearm) attribute. We look for the Thumb entry point to that
30318 function and change the branch to refer to that function instead. */
30319 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30320 && fixP->fx_addsy != NULL
30321 && S_IS_DEFINED (fixP->fx_addsy)
30322 && ! THUMB_IS_FUNC (fixP->fx_addsy))
30323 {
30324 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
30325 }
30326 }
30327 #endif
30328
30329
30330 int
30331 arm_force_relocation (struct fix * fixp)
30332 {
30333 #if defined (OBJ_COFF) && defined (TE_PE)
30334 if (fixp->fx_r_type == BFD_RELOC_RVA)
30335 return 1;
30336 #endif
30337
30338 /* In case we have a call or a branch to a function in ARM ISA mode from
30339 a thumb function or vice-versa force the relocation. These relocations
30340 are cleared off for some cores that might have blx and simple transformations
30341 are possible. */
30342
30343 #ifdef OBJ_ELF
30344 switch (fixp->fx_r_type)
30345 {
30346 case BFD_RELOC_ARM_PCREL_JUMP:
30347 case BFD_RELOC_ARM_PCREL_CALL:
30348 case BFD_RELOC_THUMB_PCREL_BLX:
30349 if (THUMB_IS_FUNC (fixp->fx_addsy))
30350 return 1;
30351 break;
30352
30353 case BFD_RELOC_ARM_PCREL_BLX:
30354 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30355 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30356 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30357 if (ARM_IS_FUNC (fixp->fx_addsy))
30358 return 1;
30359 break;
30360
30361 default:
30362 break;
30363 }
30364 #endif
30365
30366 /* Resolve these relocations even if the symbol is extern or weak.
30367 Technically this is probably wrong due to symbol preemption.
30368 In practice these relocations do not have enough range to be useful
30369 at dynamic link time, and some code (e.g. in the Linux kernel)
30370 expects these references to be resolved. */
30371 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30372 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
30373 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
30374 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
30375 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30376 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30377 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
30378 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
30379 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30380 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
30381 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30382 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30383 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30384 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
30385 return 0;
30386
30387 /* Always leave these relocations for the linker. */
30388 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30389 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30390 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30391 return 1;
30392
30393 /* Always generate relocations against function symbols. */
30394 if (fixp->fx_r_type == BFD_RELOC_32
30395 && fixp->fx_addsy
30396 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30397 return 1;
30398
30399 return generic_force_reloc (fixp);
30400 }
30401
30402 #if defined (OBJ_ELF) || defined (OBJ_COFF)
30403 /* Relocations against function names must be left unadjusted,
30404 so that the linker can use this information to generate interworking
30405 stubs. The MIPS version of this function
30406 also prevents relocations that are mips-16 specific, but I do not
30407 know why it does this.
30408
30409 FIXME:
30410 There is one other problem that ought to be addressed here, but
30411 which currently is not: Taking the address of a label (rather
30412 than a function) and then later jumping to that address. Such
30413 addresses also ought to have their bottom bit set (assuming that
30414 they reside in Thumb code), but at the moment they will not. */
30415
30416 bfd_boolean
30417 arm_fix_adjustable (fixS * fixP)
30418 {
30419 if (fixP->fx_addsy == NULL)
30420 return 1;
30421
30422 /* Preserve relocations against symbols with function type. */
30423 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
30424 return FALSE;
30425
30426 if (THUMB_IS_FUNC (fixP->fx_addsy)
30427 && fixP->fx_subsy == NULL)
30428 return FALSE;
30429
30430 /* We need the symbol name for the VTABLE entries. */
30431 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30432 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30433 return FALSE;
30434
30435 /* Don't allow symbols to be discarded on GOT related relocs. */
30436 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30437 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30438 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30439 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
30440 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
30441 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30442 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
30443 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
30444 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
30445 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
30446 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
30447 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30448 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30449 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30450 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30451 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
30452 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
30453 return FALSE;
30454
30455 /* Similarly for group relocations. */
30456 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30457 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30458 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30459 return FALSE;
30460
30461 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30462 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30463 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30464 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30465 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30466 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30467 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30468 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30469 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
30470 return FALSE;
30471
30472 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30473 offsets, so keep these symbols. */
30474 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30475 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30476 return FALSE;
30477
30478 return TRUE;
30479 }
30480 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30481
30482 #ifdef OBJ_ELF
30483 const char *
30484 elf32_arm_target_format (void)
30485 {
30486 #ifdef TE_SYMBIAN
30487 return (target_big_endian
30488 ? "elf32-bigarm-symbian"
30489 : "elf32-littlearm-symbian");
30490 #elif defined (TE_VXWORKS)
30491 return (target_big_endian
30492 ? "elf32-bigarm-vxworks"
30493 : "elf32-littlearm-vxworks");
30494 #elif defined (TE_NACL)
30495 return (target_big_endian
30496 ? "elf32-bigarm-nacl"
30497 : "elf32-littlearm-nacl");
30498 #else
30499 if (arm_fdpic)
30500 {
30501 if (target_big_endian)
30502 return "elf32-bigarm-fdpic";
30503 else
30504 return "elf32-littlearm-fdpic";
30505 }
30506 else
30507 {
30508 if (target_big_endian)
30509 return "elf32-bigarm";
30510 else
30511 return "elf32-littlearm";
30512 }
30513 #endif
30514 }
30515
30516 void
30517 armelf_frob_symbol (symbolS * symp,
30518 int * puntp)
30519 {
30520 elf_frob_symbol (symp, puntp);
30521 }
30522 #endif
30523
30524 /* MD interface: Finalization. */
30525
30526 void
30527 arm_cleanup (void)
30528 {
30529 literal_pool * pool;
30530
30531 /* Ensure that all the predication blocks are properly closed. */
30532 check_pred_blocks_finished ();
30533
30534 for (pool = list_of_pools; pool; pool = pool->next)
30535 {
30536 /* Put it at the end of the relevant section. */
30537 subseg_set (pool->section, pool->sub_section);
30538 #ifdef OBJ_ELF
30539 arm_elf_change_section ();
30540 #endif
30541 s_ltorg (0);
30542 }
30543 }
30544
30545 #ifdef OBJ_ELF
30546 /* Remove any excess mapping symbols generated for alignment frags in
30547 SEC. We may have created a mapping symbol before a zero byte
30548 alignment; remove it if there's a mapping symbol after the
30549 alignment. */
30550 static void
30551 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30552 void *dummy ATTRIBUTE_UNUSED)
30553 {
30554 segment_info_type *seginfo = seg_info (sec);
30555 fragS *fragp;
30556
30557 if (seginfo == NULL || seginfo->frchainP == NULL)
30558 return;
30559
30560 for (fragp = seginfo->frchainP->frch_root;
30561 fragp != NULL;
30562 fragp = fragp->fr_next)
30563 {
30564 symbolS *sym = fragp->tc_frag_data.last_map;
30565 fragS *next = fragp->fr_next;
30566
30567 /* Variable-sized frags have been converted to fixed size by
30568 this point. But if this was variable-sized to start with,
30569 there will be a fixed-size frag after it. So don't handle
30570 next == NULL. */
30571 if (sym == NULL || next == NULL)
30572 continue;
30573
30574 if (S_GET_VALUE (sym) < next->fr_address)
30575 /* Not at the end of this frag. */
30576 continue;
30577 know (S_GET_VALUE (sym) == next->fr_address);
30578
30579 do
30580 {
30581 if (next->tc_frag_data.first_map != NULL)
30582 {
30583 /* Next frag starts with a mapping symbol. Discard this
30584 one. */
30585 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30586 break;
30587 }
30588
30589 if (next->fr_next == NULL)
30590 {
30591 /* This mapping symbol is at the end of the section. Discard
30592 it. */
30593 know (next->fr_fix == 0 && next->fr_var == 0);
30594 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30595 break;
30596 }
30597
30598 /* As long as we have empty frags without any mapping symbols,
30599 keep looking. */
30600 /* If the next frag is non-empty and does not start with a
30601 mapping symbol, then this mapping symbol is required. */
30602 if (next->fr_address != next->fr_next->fr_address)
30603 break;
30604
30605 next = next->fr_next;
30606 }
30607 while (next != NULL);
30608 }
30609 }
30610 #endif
30611
30612 /* Adjust the symbol table. This marks Thumb symbols as distinct from
30613 ARM ones. */
30614
30615 void
30616 arm_adjust_symtab (void)
30617 {
30618 #ifdef OBJ_COFF
30619 symbolS * sym;
30620
30621 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30622 {
30623 if (ARM_IS_THUMB (sym))
30624 {
30625 if (THUMB_IS_FUNC (sym))
30626 {
30627 /* Mark the symbol as a Thumb function. */
30628 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30629 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30630 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
30631
30632 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30633 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30634 else
30635 as_bad (_("%s: unexpected function type: %d"),
30636 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30637 }
30638 else switch (S_GET_STORAGE_CLASS (sym))
30639 {
30640 case C_EXT:
30641 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30642 break;
30643 case C_STAT:
30644 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30645 break;
30646 case C_LABEL:
30647 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30648 break;
30649 default:
30650 /* Do nothing. */
30651 break;
30652 }
30653 }
30654
30655 if (ARM_IS_INTERWORK (sym))
30656 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
30657 }
30658 #endif
30659 #ifdef OBJ_ELF
30660 symbolS * sym;
30661 char bind;
30662
30663 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30664 {
30665 if (ARM_IS_THUMB (sym))
30666 {
30667 elf_symbol_type * elf_sym;
30668
30669 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30670 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
30671
30672 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30673 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
30674 {
30675 /* If it's a .thumb_func, declare it as so,
30676 otherwise tag label as .code 16. */
30677 if (THUMB_IS_FUNC (sym))
30678 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30679 ST_BRANCH_TO_THUMB);
30680 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
30681 elf_sym->internal_elf_sym.st_info =
30682 ELF_ST_INFO (bind, STT_ARM_16BIT);
30683 }
30684 }
30685 }
30686
30687 /* Remove any overlapping mapping symbols generated by alignment frags. */
30688 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
30689 /* Now do generic ELF adjustments. */
30690 elf_adjust_symtab ();
30691 #endif
30692 }
30693
30694 /* MD interface: Initialization. */
30695
30696 static void
30697 set_constant_flonums (void)
30698 {
30699 int i;
30700
30701 for (i = 0; i < NUM_FLOAT_VALS; i++)
30702 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30703 abort ();
30704 }
30705
30706 /* Auto-select Thumb mode if it's the only available instruction set for the
30707 given architecture. */
30708
30709 static void
30710 autoselect_thumb_from_cpu_variant (void)
30711 {
30712 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30713 opcode_select (16);
30714 }
30715
30716 void
30717 md_begin (void)
30718 {
30719 unsigned mach;
30720 unsigned int i;
30721
30722 if ( (arm_ops_hsh = hash_new ()) == NULL
30723 || (arm_cond_hsh = hash_new ()) == NULL
30724 || (arm_vcond_hsh = hash_new ()) == NULL
30725 || (arm_shift_hsh = hash_new ()) == NULL
30726 || (arm_psr_hsh = hash_new ()) == NULL
30727 || (arm_v7m_psr_hsh = hash_new ()) == NULL
30728 || (arm_reg_hsh = hash_new ()) == NULL
30729 || (arm_reloc_hsh = hash_new ()) == NULL
30730 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
30731 as_fatal (_("virtual memory exhausted"));
30732
30733 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
30734 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
30735 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
30736 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
30737 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30738 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
30739 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
30740 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
30741 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
30742 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
30743 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
30744 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
30745 (void *) (v7m_psrs + i));
30746 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
30747 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
30748 for (i = 0;
30749 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30750 i++)
30751 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
30752 (void *) (barrier_opt_names + i));
30753 #ifdef OBJ_ELF
30754 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30755 {
30756 struct reloc_entry * entry = reloc_names + i;
30757
30758 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30759 /* This makes encode_branch() use the EABI versions of this relocation. */
30760 entry->reloc = BFD_RELOC_UNUSED;
30761
30762 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
30763 }
30764 #endif
30765
30766 set_constant_flonums ();
30767
30768 /* Set the cpu variant based on the command-line options. We prefer
30769 -mcpu= over -march= if both are set (as for GCC); and we prefer
30770 -mfpu= over any other way of setting the floating point unit.
30771 Use of legacy options with new options are faulted. */
30772 if (legacy_cpu)
30773 {
30774 if (mcpu_cpu_opt || march_cpu_opt)
30775 as_bad (_("use of old and new-style options to set CPU type"));
30776
30777 selected_arch = *legacy_cpu;
30778 }
30779 else if (mcpu_cpu_opt)
30780 {
30781 selected_arch = *mcpu_cpu_opt;
30782 selected_ext = *mcpu_ext_opt;
30783 }
30784 else if (march_cpu_opt)
30785 {
30786 selected_arch = *march_cpu_opt;
30787 selected_ext = *march_ext_opt;
30788 }
30789 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
30790
30791 if (legacy_fpu)
30792 {
30793 if (mfpu_opt)
30794 as_bad (_("use of old and new-style options to set FPU type"));
30795
30796 selected_fpu = *legacy_fpu;
30797 }
30798 else if (mfpu_opt)
30799 selected_fpu = *mfpu_opt;
30800 else
30801 {
30802 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30803 || defined (TE_NetBSD) || defined (TE_VXWORKS))
30804 /* Some environments specify a default FPU. If they don't, infer it
30805 from the processor. */
30806 if (mcpu_fpu_opt)
30807 selected_fpu = *mcpu_fpu_opt;
30808 else if (march_fpu_opt)
30809 selected_fpu = *march_fpu_opt;
30810 #else
30811 selected_fpu = fpu_default;
30812 #endif
30813 }
30814
30815 if (ARM_FEATURE_ZERO (selected_fpu))
30816 {
30817 if (!no_cpu_selected ())
30818 selected_fpu = fpu_default;
30819 else
30820 selected_fpu = fpu_arch_fpa;
30821 }
30822
30823 #ifdef CPU_DEFAULT
30824 if (ARM_FEATURE_ZERO (selected_arch))
30825 {
30826 selected_arch = cpu_default;
30827 selected_cpu = selected_arch;
30828 }
30829 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30830 #else
30831 /* Autodection of feature mode: allow all features in cpu_variant but leave
30832 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30833 after all instruction have been processed and we can decide what CPU
30834 should be selected. */
30835 if (ARM_FEATURE_ZERO (selected_arch))
30836 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
30837 else
30838 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30839 #endif
30840
30841 autoselect_thumb_from_cpu_variant ();
30842
30843 arm_arch_used = thumb_arch_used = arm_arch_none;
30844
30845 #if defined OBJ_COFF || defined OBJ_ELF
30846 {
30847 unsigned int flags = 0;
30848
30849 #if defined OBJ_ELF
30850 flags = meabi_flags;
30851
30852 switch (meabi_flags)
30853 {
30854 case EF_ARM_EABI_UNKNOWN:
30855 #endif
30856 /* Set the flags in the private structure. */
30857 if (uses_apcs_26) flags |= F_APCS26;
30858 if (support_interwork) flags |= F_INTERWORK;
30859 if (uses_apcs_float) flags |= F_APCS_FLOAT;
30860 if (pic_code) flags |= F_PIC;
30861 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
30862 flags |= F_SOFT_FLOAT;
30863
30864 switch (mfloat_abi_opt)
30865 {
30866 case ARM_FLOAT_ABI_SOFT:
30867 case ARM_FLOAT_ABI_SOFTFP:
30868 flags |= F_SOFT_FLOAT;
30869 break;
30870
30871 case ARM_FLOAT_ABI_HARD:
30872 if (flags & F_SOFT_FLOAT)
30873 as_bad (_("hard-float conflicts with specified fpu"));
30874 break;
30875 }
30876
30877 /* Using pure-endian doubles (even if soft-float). */
30878 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
30879 flags |= F_VFP_FLOAT;
30880
30881 #if defined OBJ_ELF
30882 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
30883 flags |= EF_ARM_MAVERICK_FLOAT;
30884 break;
30885
30886 case EF_ARM_EABI_VER4:
30887 case EF_ARM_EABI_VER5:
30888 /* No additional flags to set. */
30889 break;
30890
30891 default:
30892 abort ();
30893 }
30894 #endif
30895 bfd_set_private_flags (stdoutput, flags);
30896
30897 /* We have run out flags in the COFF header to encode the
30898 status of ATPCS support, so instead we create a dummy,
30899 empty, debug section called .arm.atpcs. */
30900 if (atpcs)
30901 {
30902 asection * sec;
30903
30904 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30905
30906 if (sec != NULL)
30907 {
30908 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30909 bfd_set_section_size (sec, 0);
30910 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30911 }
30912 }
30913 }
30914 #endif
30915
30916 /* Record the CPU type as well. */
30917 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30918 mach = bfd_mach_arm_iWMMXt2;
30919 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
30920 mach = bfd_mach_arm_iWMMXt;
30921 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
30922 mach = bfd_mach_arm_XScale;
30923 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
30924 mach = bfd_mach_arm_ep9312;
30925 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
30926 mach = bfd_mach_arm_5TE;
30927 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
30928 {
30929 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30930 mach = bfd_mach_arm_5T;
30931 else
30932 mach = bfd_mach_arm_5;
30933 }
30934 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
30935 {
30936 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30937 mach = bfd_mach_arm_4T;
30938 else
30939 mach = bfd_mach_arm_4;
30940 }
30941 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
30942 mach = bfd_mach_arm_3M;
30943 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30944 mach = bfd_mach_arm_3;
30945 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30946 mach = bfd_mach_arm_2a;
30947 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30948 mach = bfd_mach_arm_2;
30949 else
30950 mach = bfd_mach_arm_unknown;
30951
30952 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30953 }
30954
30955 /* Command line processing. */
30956
30957 /* md_parse_option
30958 Invocation line includes a switch not recognized by the base assembler.
30959 See if it's a processor-specific option.
30960
30961 This routine is somewhat complicated by the need for backwards
30962 compatibility (since older releases of gcc can't be changed).
30963 The new options try to make the interface as compatible as
30964 possible with GCC.
30965
30966 New options (supported) are:
30967
30968 -mcpu=<cpu name> Assemble for selected processor
30969 -march=<architecture name> Assemble for selected architecture
30970 -mfpu=<fpu architecture> Assemble for selected FPU.
30971 -EB/-mbig-endian Big-endian
30972 -EL/-mlittle-endian Little-endian
30973 -k Generate PIC code
30974 -mthumb Start in Thumb mode
30975 -mthumb-interwork Code supports ARM/Thumb interworking
30976
30977 -m[no-]warn-deprecated Warn about deprecated features
30978 -m[no-]warn-syms Warn when symbols match instructions
30979
30980 For now we will also provide support for:
30981
30982 -mapcs-32 32-bit Program counter
30983 -mapcs-26 26-bit Program counter
30984 -macps-float Floats passed in FP registers
30985 -mapcs-reentrant Reentrant code
30986 -matpcs
30987 (sometime these will probably be replaced with -mapcs=<list of options>
30988 and -matpcs=<list of options>)
30989
30990 The remaining options are only supported for back-wards compatibility.
30991 Cpu variants, the arm part is optional:
30992 -m[arm]1 Currently not supported.
30993 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30994 -m[arm]3 Arm 3 processor
30995 -m[arm]6[xx], Arm 6 processors
30996 -m[arm]7[xx][t][[d]m] Arm 7 processors
30997 -m[arm]8[10] Arm 8 processors
30998 -m[arm]9[20][tdmi] Arm 9 processors
30999 -mstrongarm[110[0]] StrongARM processors
31000 -mxscale XScale processors
31001 -m[arm]v[2345[t[e]]] Arm architectures
31002 -mall All (except the ARM1)
31003 FP variants:
31004 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
31005 -mfpe-old (No float load/store multiples)
31006 -mvfpxd VFP Single precision
31007 -mvfp All VFP
31008 -mno-fpu Disable all floating point instructions
31009
31010 The following CPU names are recognized:
31011 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31012 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31013 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31014 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31015 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31016 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31017 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
31018
31019 */
31020
31021 const char * md_shortopts = "m:k";
31022
31023 #ifdef ARM_BI_ENDIAN
31024 #define OPTION_EB (OPTION_MD_BASE + 0)
31025 #define OPTION_EL (OPTION_MD_BASE + 1)
31026 #else
31027 #if TARGET_BYTES_BIG_ENDIAN
31028 #define OPTION_EB (OPTION_MD_BASE + 0)
31029 #else
31030 #define OPTION_EL (OPTION_MD_BASE + 1)
31031 #endif
31032 #endif
31033 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
31034 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
31035
31036 struct option md_longopts[] =
31037 {
31038 #ifdef OPTION_EB
31039 {"EB", no_argument, NULL, OPTION_EB},
31040 #endif
31041 #ifdef OPTION_EL
31042 {"EL", no_argument, NULL, OPTION_EL},
31043 #endif
31044 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
31045 #ifdef OBJ_ELF
31046 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31047 #endif
31048 {NULL, no_argument, NULL, 0}
31049 };
31050
31051 size_t md_longopts_size = sizeof (md_longopts);
31052
31053 struct arm_option_table
31054 {
31055 const char * option; /* Option name to match. */
31056 const char * help; /* Help information. */
31057 int * var; /* Variable to change. */
31058 int value; /* What to change it to. */
31059 const char * deprecated; /* If non-null, print this message. */
31060 };
31061
31062 struct arm_option_table arm_opts[] =
31063 {
31064 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31065 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31066 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31067 &support_interwork, 1, NULL},
31068 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31069 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31070 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31071 1, NULL},
31072 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31073 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31074 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31075 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31076 NULL},
31077
31078 /* These are recognized by the assembler, but have no affect on code. */
31079 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31080 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
31081
31082 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31083 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31084 &warn_on_deprecated, 0, NULL},
31085
31086 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31087 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31088 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31089
31090 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
31091 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
31092 {NULL, NULL, NULL, 0, NULL}
31093 };
31094
31095 struct arm_legacy_option_table
31096 {
31097 const char * option; /* Option name to match. */
31098 const arm_feature_set ** var; /* Variable to change. */
31099 const arm_feature_set value; /* What to change it to. */
31100 const char * deprecated; /* If non-null, print this message. */
31101 };
31102
31103 const struct arm_legacy_option_table arm_legacy_opts[] =
31104 {
31105 /* DON'T add any new processors to this list -- we want the whole list
31106 to go away... Add them to the processors table instead. */
31107 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31108 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31109 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31110 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31111 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31112 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31113 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31114 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31115 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31116 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31117 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31118 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31119 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31120 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31121 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31122 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31123 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31124 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31125 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31126 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31127 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31128 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31129 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31130 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31131 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31132 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31133 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31134 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31135 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31136 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31137 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31138 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31139 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31140 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31141 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31142 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31143 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31144 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31145 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31146 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31147 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31148 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31149 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31150 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31151 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31152 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31153 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31154 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31155 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31156 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31157 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31158 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31159 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31160 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31161 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31162 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31163 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31164 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31165 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31166 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31167 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31168 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31169 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31170 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31171 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31172 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31173 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31174 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31175 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31176 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
31177 N_("use -mcpu=strongarm110")},
31178 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
31179 N_("use -mcpu=strongarm1100")},
31180 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
31181 N_("use -mcpu=strongarm1110")},
31182 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31183 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31184 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
31185
31186 /* Architecture variants -- don't add any more to this list either. */
31187 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31188 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31189 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31190 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31191 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31192 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31193 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31194 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31195 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31196 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31197 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31198 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31199 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31200 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31201 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31202 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31203 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31204 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31205
31206 /* Floating point variants -- don't add any more to this list either. */
31207 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31208 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31209 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31210 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
31211 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
31212
31213 {NULL, NULL, ARM_ARCH_NONE, NULL}
31214 };
31215
31216 struct arm_cpu_option_table
31217 {
31218 const char * name;
31219 size_t name_len;
31220 const arm_feature_set value;
31221 const arm_feature_set ext;
31222 /* For some CPUs we assume an FPU unless the user explicitly sets
31223 -mfpu=... */
31224 const arm_feature_set default_fpu;
31225 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31226 case. */
31227 const char * canonical_name;
31228 };
31229
31230 /* This list should, at a minimum, contain all the cpu names
31231 recognized by GCC. */
31232 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
31233
31234 static const struct arm_cpu_option_table arm_cpus[] =
31235 {
31236 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31237 ARM_ARCH_NONE,
31238 FPU_ARCH_FPA),
31239 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31240 ARM_ARCH_NONE,
31241 FPU_ARCH_FPA),
31242 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31243 ARM_ARCH_NONE,
31244 FPU_ARCH_FPA),
31245 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31246 ARM_ARCH_NONE,
31247 FPU_ARCH_FPA),
31248 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31249 ARM_ARCH_NONE,
31250 FPU_ARCH_FPA),
31251 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31252 ARM_ARCH_NONE,
31253 FPU_ARCH_FPA),
31254 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31255 ARM_ARCH_NONE,
31256 FPU_ARCH_FPA),
31257 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31258 ARM_ARCH_NONE,
31259 FPU_ARCH_FPA),
31260 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31261 ARM_ARCH_NONE,
31262 FPU_ARCH_FPA),
31263 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31264 ARM_ARCH_NONE,
31265 FPU_ARCH_FPA),
31266 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31267 ARM_ARCH_NONE,
31268 FPU_ARCH_FPA),
31269 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31270 ARM_ARCH_NONE,
31271 FPU_ARCH_FPA),
31272 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31273 ARM_ARCH_NONE,
31274 FPU_ARCH_FPA),
31275 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31276 ARM_ARCH_NONE,
31277 FPU_ARCH_FPA),
31278 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31279 ARM_ARCH_NONE,
31280 FPU_ARCH_FPA),
31281 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31282 ARM_ARCH_NONE,
31283 FPU_ARCH_FPA),
31284 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31285 ARM_ARCH_NONE,
31286 FPU_ARCH_FPA),
31287 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31288 ARM_ARCH_NONE,
31289 FPU_ARCH_FPA),
31290 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31291 ARM_ARCH_NONE,
31292 FPU_ARCH_FPA),
31293 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31294 ARM_ARCH_NONE,
31295 FPU_ARCH_FPA),
31296 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31297 ARM_ARCH_NONE,
31298 FPU_ARCH_FPA),
31299 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31300 ARM_ARCH_NONE,
31301 FPU_ARCH_FPA),
31302 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31303 ARM_ARCH_NONE,
31304 FPU_ARCH_FPA),
31305 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31306 ARM_ARCH_NONE,
31307 FPU_ARCH_FPA),
31308 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31309 ARM_ARCH_NONE,
31310 FPU_ARCH_FPA),
31311 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31312 ARM_ARCH_NONE,
31313 FPU_ARCH_FPA),
31314 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31315 ARM_ARCH_NONE,
31316 FPU_ARCH_FPA),
31317 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31318 ARM_ARCH_NONE,
31319 FPU_ARCH_FPA),
31320 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31321 ARM_ARCH_NONE,
31322 FPU_ARCH_FPA),
31323 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31324 ARM_ARCH_NONE,
31325 FPU_ARCH_FPA),
31326 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31327 ARM_ARCH_NONE,
31328 FPU_ARCH_FPA),
31329 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31330 ARM_ARCH_NONE,
31331 FPU_ARCH_FPA),
31332 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31333 ARM_ARCH_NONE,
31334 FPU_ARCH_FPA),
31335 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31336 ARM_ARCH_NONE,
31337 FPU_ARCH_FPA),
31338 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31339 ARM_ARCH_NONE,
31340 FPU_ARCH_FPA),
31341 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31342 ARM_ARCH_NONE,
31343 FPU_ARCH_FPA),
31344 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31345 ARM_ARCH_NONE,
31346 FPU_ARCH_FPA),
31347 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31348 ARM_ARCH_NONE,
31349 FPU_ARCH_FPA),
31350 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31351 ARM_ARCH_NONE,
31352 FPU_ARCH_FPA),
31353 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31354 ARM_ARCH_NONE,
31355 FPU_ARCH_FPA),
31356 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31357 ARM_ARCH_NONE,
31358 FPU_ARCH_FPA),
31359 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31360 ARM_ARCH_NONE,
31361 FPU_ARCH_FPA),
31362 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31363 ARM_ARCH_NONE,
31364 FPU_ARCH_FPA),
31365 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31366 ARM_ARCH_NONE,
31367 FPU_ARCH_FPA),
31368 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31369 ARM_ARCH_NONE,
31370 FPU_ARCH_FPA),
31371 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31372 ARM_ARCH_NONE,
31373 FPU_ARCH_FPA),
31374
31375 /* For V5 or later processors we default to using VFP; but the user
31376 should really set the FPU type explicitly. */
31377 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31378 ARM_ARCH_NONE,
31379 FPU_ARCH_VFP_V2),
31380 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31381 ARM_ARCH_NONE,
31382 FPU_ARCH_VFP_V2),
31383 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31384 ARM_ARCH_NONE,
31385 FPU_ARCH_VFP_V2),
31386 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31387 ARM_ARCH_NONE,
31388 FPU_ARCH_VFP_V2),
31389 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31390 ARM_ARCH_NONE,
31391 FPU_ARCH_VFP_V2),
31392 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31393 ARM_ARCH_NONE,
31394 FPU_ARCH_VFP_V2),
31395 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31396 ARM_ARCH_NONE,
31397 FPU_ARCH_VFP_V2),
31398 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31399 ARM_ARCH_NONE,
31400 FPU_ARCH_VFP_V2),
31401 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31402 ARM_ARCH_NONE,
31403 FPU_ARCH_VFP_V2),
31404 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31405 ARM_ARCH_NONE,
31406 FPU_ARCH_VFP_V2),
31407 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31408 ARM_ARCH_NONE,
31409 FPU_ARCH_VFP_V2),
31410 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31411 ARM_ARCH_NONE,
31412 FPU_ARCH_VFP_V2),
31413 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31414 ARM_ARCH_NONE,
31415 FPU_ARCH_VFP_V1),
31416 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31417 ARM_ARCH_NONE,
31418 FPU_ARCH_VFP_V1),
31419 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31420 ARM_ARCH_NONE,
31421 FPU_ARCH_VFP_V2),
31422 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31423 ARM_ARCH_NONE,
31424 FPU_ARCH_VFP_V2),
31425 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31426 ARM_ARCH_NONE,
31427 FPU_ARCH_VFP_V1),
31428 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31429 ARM_ARCH_NONE,
31430 FPU_ARCH_VFP_V2),
31431 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31432 ARM_ARCH_NONE,
31433 FPU_ARCH_VFP_V2),
31434 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31435 ARM_ARCH_NONE,
31436 FPU_ARCH_VFP_V2),
31437 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31438 ARM_ARCH_NONE,
31439 FPU_ARCH_VFP_V2),
31440 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31441 ARM_ARCH_NONE,
31442 FPU_ARCH_VFP_V2),
31443 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31444 ARM_ARCH_NONE,
31445 FPU_ARCH_VFP_V2),
31446 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31447 ARM_ARCH_NONE,
31448 FPU_ARCH_VFP_V2),
31449 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31450 ARM_ARCH_NONE,
31451 FPU_ARCH_VFP_V2),
31452 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31453 ARM_ARCH_NONE,
31454 FPU_ARCH_VFP_V2),
31455 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31456 ARM_ARCH_NONE,
31457 FPU_NONE),
31458 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31459 ARM_ARCH_NONE,
31460 FPU_NONE),
31461 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31462 ARM_ARCH_NONE,
31463 FPU_ARCH_VFP_V2),
31464 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31465 ARM_ARCH_NONE,
31466 FPU_ARCH_VFP_V2),
31467 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31468 ARM_ARCH_NONE,
31469 FPU_ARCH_VFP_V2),
31470 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31471 ARM_ARCH_NONE,
31472 FPU_NONE),
31473 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31474 ARM_ARCH_NONE,
31475 FPU_NONE),
31476 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31477 ARM_ARCH_NONE,
31478 FPU_ARCH_VFP_V2),
31479 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31480 ARM_ARCH_NONE,
31481 FPU_NONE),
31482 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31483 ARM_ARCH_NONE,
31484 FPU_ARCH_VFP_V2),
31485 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31486 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31487 FPU_NONE),
31488 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31489 ARM_ARCH_NONE,
31490 FPU_ARCH_NEON_VFP_V4),
31491 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31492 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31493 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31494 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31495 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31496 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31497 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31498 ARM_ARCH_NONE,
31499 FPU_ARCH_NEON_VFP_V4),
31500 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31501 ARM_ARCH_NONE,
31502 FPU_ARCH_NEON_VFP_V4),
31503 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31504 ARM_ARCH_NONE,
31505 FPU_ARCH_NEON_VFP_V4),
31506 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
31507 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31508 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31509 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
31510 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31511 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31512 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
31513 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31514 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31515 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31516 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31517 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31518 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
31519 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31520 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31521 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
31522 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31523 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31524 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
31525 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31526 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31527 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31528 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31529 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31530 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31531 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31532 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31533 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31534 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31535 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31536 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31537 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31538 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31539 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31540 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31541 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31542 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31543 ARM_ARCH_NONE,
31544 FPU_NONE),
31545 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31546 ARM_ARCH_NONE,
31547 FPU_ARCH_VFP_V3D16),
31548 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31549 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31550 FPU_NONE),
31551 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31552 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31553 FPU_ARCH_VFP_V3D16),
31554 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31555 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31556 FPU_ARCH_VFP_V3D16),
31557 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
31558 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31559 FPU_ARCH_NEON_VFP_ARMV8),
31560 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31561 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31562 FPU_NONE),
31563 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31564 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31565 FPU_NONE),
31566 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31567 ARM_ARCH_NONE,
31568 FPU_NONE),
31569 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31570 ARM_ARCH_NONE,
31571 FPU_NONE),
31572 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31573 ARM_ARCH_NONE,
31574 FPU_NONE),
31575 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31576 ARM_ARCH_NONE,
31577 FPU_NONE),
31578 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31579 ARM_ARCH_NONE,
31580 FPU_NONE),
31581 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31582 ARM_ARCH_NONE,
31583 FPU_NONE),
31584 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31585 ARM_ARCH_NONE,
31586 FPU_NONE),
31587 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
31588 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31589 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31590 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31591 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31592 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31593 /* ??? XSCALE is really an architecture. */
31594 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31595 ARM_ARCH_NONE,
31596 FPU_ARCH_VFP_V2),
31597
31598 /* ??? iwmmxt is not a processor. */
31599 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31600 ARM_ARCH_NONE,
31601 FPU_ARCH_VFP_V2),
31602 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31603 ARM_ARCH_NONE,
31604 FPU_ARCH_VFP_V2),
31605 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31606 ARM_ARCH_NONE,
31607 FPU_ARCH_VFP_V2),
31608
31609 /* Maverick. */
31610 ARM_CPU_OPT ("ep9312", "ARM920T",
31611 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31612 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31613
31614 /* Marvell processors. */
31615 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31616 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31617 FPU_ARCH_VFP_V3D16),
31618 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31619 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31620 FPU_ARCH_NEON_VFP_V4),
31621
31622 /* APM X-Gene family. */
31623 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31624 ARM_ARCH_NONE,
31625 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31626 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
31627 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31628 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31629
31630 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31631 };
31632 #undef ARM_CPU_OPT
31633
31634 struct arm_ext_table
31635 {
31636 const char * name;
31637 size_t name_len;
31638 const arm_feature_set merge;
31639 const arm_feature_set clear;
31640 };
31641
31642 struct arm_arch_option_table
31643 {
31644 const char * name;
31645 size_t name_len;
31646 const arm_feature_set value;
31647 const arm_feature_set default_fpu;
31648 const struct arm_ext_table * ext_table;
31649 };
31650
31651 /* Used to add support for +E and +noE extension. */
31652 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31653 /* Used to add support for a +E extension. */
31654 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31655 /* Used to add support for a +noE extension. */
31656 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31657
31658 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31659 ~0 & ~FPU_ENDIAN_PURE)
31660
31661 static const struct arm_ext_table armv5te_ext_table[] =
31662 {
31663 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31664 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31665 };
31666
31667 static const struct arm_ext_table armv7_ext_table[] =
31668 {
31669 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31670 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31671 };
31672
31673 static const struct arm_ext_table armv7ve_ext_table[] =
31674 {
31675 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31676 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31677 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31678 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31679 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31680 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31681 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31682
31683 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31684 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31685
31686 /* Aliases for +simd. */
31687 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31688
31689 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31690 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31691 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31692
31693 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31694 };
31695
31696 static const struct arm_ext_table armv7a_ext_table[] =
31697 {
31698 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31699 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31700 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31701 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31702 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31703 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31704 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31705
31706 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31707 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31708
31709 /* Aliases for +simd. */
31710 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31711 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31712
31713 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31714 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31715
31716 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31717 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31718 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31719 };
31720
31721 static const struct arm_ext_table armv7r_ext_table[] =
31722 {
31723 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31724 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31725 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31726 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31727 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31728 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31729 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31730 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31731 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31732 };
31733
31734 static const struct arm_ext_table armv7em_ext_table[] =
31735 {
31736 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31737 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31738 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31739 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31740 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31741 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31742 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31743 };
31744
31745 static const struct arm_ext_table armv8a_ext_table[] =
31746 {
31747 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31748 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31749 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31750 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31751
31752 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31753 should use the +simd option to turn on FP. */
31754 ARM_REMOVE ("fp", ALL_FP),
31755 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31756 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31757 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31758 };
31759
31760
31761 static const struct arm_ext_table armv81a_ext_table[] =
31762 {
31763 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31764 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31765 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31766
31767 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31768 should use the +simd option to turn on FP. */
31769 ARM_REMOVE ("fp", ALL_FP),
31770 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31771 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31772 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31773 };
31774
31775 static const struct arm_ext_table armv82a_ext_table[] =
31776 {
31777 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31778 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31779 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
31780 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31781 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31782 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31783 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31784 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31785
31786 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31787 should use the +simd option to turn on FP. */
31788 ARM_REMOVE ("fp", ALL_FP),
31789 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31790 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31791 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31792 };
31793
31794 static const struct arm_ext_table armv84a_ext_table[] =
31795 {
31796 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31797 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31798 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31799 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31800 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31801 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31802
31803 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31804 should use the +simd option to turn on FP. */
31805 ARM_REMOVE ("fp", ALL_FP),
31806 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31807 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31808 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31809 };
31810
31811 static const struct arm_ext_table armv85a_ext_table[] =
31812 {
31813 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31814 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31815 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31816 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31817 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31818 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31819
31820 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31821 should use the +simd option to turn on FP. */
31822 ARM_REMOVE ("fp", ALL_FP),
31823 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31824 };
31825
31826 static const struct arm_ext_table armv86a_ext_table[] =
31827 {
31828 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31829 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31830 };
31831
31832 #define CDE_EXTENSIONS \
31833 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31834 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31835 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31836 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31837 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31838 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31839 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31840 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31841
31842 static const struct arm_ext_table armv8m_main_ext_table[] =
31843 {
31844 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31845 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31846 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31847 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31848 CDE_EXTENSIONS,
31849 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31850 };
31851
31852
31853 static const struct arm_ext_table armv8_1m_main_ext_table[] =
31854 {
31855 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31856 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31857 ARM_EXT ("fp",
31858 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31859 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31860 ALL_FP),
31861 ARM_ADD ("fp.dp",
31862 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31863 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31864 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
31865 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
31866 ARM_ADD ("mve.fp",
31867 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31868 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
31869 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31870 CDE_EXTENSIONS,
31871 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31872 };
31873
31874 #undef CDE_EXTENSIONS
31875
31876 static const struct arm_ext_table armv8r_ext_table[] =
31877 {
31878 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31879 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31880 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31881 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31882 ARM_REMOVE ("fp", ALL_FP),
31883 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31884 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31885 };
31886
31887 /* This list should, at a minimum, contain all the architecture names
31888 recognized by GCC. */
31889 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31890 #define ARM_ARCH_OPT2(N, V, DF, ext) \
31891 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
31892
31893 static const struct arm_arch_option_table arm_archs[] =
31894 {
31895 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31896 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31897 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31898 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31899 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31900 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31901 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31902 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31903 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31904 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31905 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31906 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31907 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31908 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
31909 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31910 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31911 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31912 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31913 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31914 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31915 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
31916 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31917 kept to preserve existing behaviour. */
31918 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31919 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31920 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31921 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31922 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
31923 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31924 kept to preserve existing behaviour. */
31925 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31926 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31927 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31928 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
31929 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
31930 /* The official spelling of the ARMv7 profile variants is the dashed form.
31931 Accept the non-dashed form for compatibility with old toolchains. */
31932 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31933 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31934 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31935 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31936 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31937 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31938 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31939 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
31940 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
31941 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31942 armv8m_main),
31943 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31944 armv8_1m_main),
31945 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31946 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31947 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31948 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31949 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31950 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31951 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
31952 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
31953 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31954 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31955 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
31956 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31957 };
31958 #undef ARM_ARCH_OPT
31959
31960 /* ISA extensions in the co-processor and main instruction set space. */
31961
31962 struct arm_option_extension_value_table
31963 {
31964 const char * name;
31965 size_t name_len;
31966 const arm_feature_set merge_value;
31967 const arm_feature_set clear_value;
31968 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31969 indicates that an extension is available for all architectures while
31970 ARM_ANY marks an empty entry. */
31971 const arm_feature_set allowed_archs[2];
31972 };
31973
31974 /* The following table must be in alphabetical order with a NULL last entry. */
31975
31976 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31977 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
31978
31979 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
31980 use the context sensitive approach using arm_ext_table's. */
31981 static const struct arm_option_extension_value_table arm_extensions[] =
31982 {
31983 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31984 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
31985 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31986 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31987 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31988 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31989 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31990 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31991 ARM_ARCH_V8_2A),
31992 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31993 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31994 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
31995 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31996 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31997 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31998 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31999 ARM_ARCH_V8_2A),
32000 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32001 | ARM_EXT2_FP16_FML),
32002 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32003 | ARM_EXT2_FP16_FML),
32004 ARM_ARCH_V8_2A),
32005 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
32006 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
32007 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32008 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
32009 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
32010 Thumb divide instruction. Due to this having the same name as the
32011 previous entry, this will be ignored when doing command-line parsing and
32012 only considered by build attribute selection code. */
32013 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32014 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32015 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
32016 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
32017 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
32018 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
32019 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
32020 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
32021 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32022 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
32023 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
32024 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32025 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
32026 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32027 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32028 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
32029 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32030 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
32031 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32032 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32033 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32034 ARM_ARCH_V8A),
32035 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32036 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
32037 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32038 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32039 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
32040 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32041 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32042 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32043 ARM_ARCH_V8A),
32044 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
32045 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
32046 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32047 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32048 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32049 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32050 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
32051 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32052 | ARM_EXT_DIV),
32053 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32054 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32055 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
32056 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32057 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
32058 };
32059 #undef ARM_EXT_OPT
32060
32061 /* ISA floating-point and Advanced SIMD extensions. */
32062 struct arm_option_fpu_value_table
32063 {
32064 const char * name;
32065 const arm_feature_set value;
32066 };
32067
32068 /* This list should, at a minimum, contain all the fpu names
32069 recognized by GCC. */
32070 static const struct arm_option_fpu_value_table arm_fpus[] =
32071 {
32072 {"softfpa", FPU_NONE},
32073 {"fpe", FPU_ARCH_FPE},
32074 {"fpe2", FPU_ARCH_FPE},
32075 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32076 {"fpa", FPU_ARCH_FPA},
32077 {"fpa10", FPU_ARCH_FPA},
32078 {"fpa11", FPU_ARCH_FPA},
32079 {"arm7500fe", FPU_ARCH_FPA},
32080 {"softvfp", FPU_ARCH_VFP},
32081 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32082 {"vfp", FPU_ARCH_VFP_V2},
32083 {"vfp9", FPU_ARCH_VFP_V2},
32084 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
32085 {"vfp10", FPU_ARCH_VFP_V2},
32086 {"vfp10-r0", FPU_ARCH_VFP_V1},
32087 {"vfpxd", FPU_ARCH_VFP_V1xD},
32088 {"vfpv2", FPU_ARCH_VFP_V2},
32089 {"vfpv3", FPU_ARCH_VFP_V3},
32090 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
32091 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
32092 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32093 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32094 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
32095 {"arm1020t", FPU_ARCH_VFP_V1},
32096 {"arm1020e", FPU_ARCH_VFP_V2},
32097 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
32098 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32099 {"maverick", FPU_ARCH_MAVERICK},
32100 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
32101 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
32102 {"neon-fp16", FPU_ARCH_NEON_FP16},
32103 {"vfpv4", FPU_ARCH_VFP_V4},
32104 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
32105 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
32106 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32107 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
32108 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
32109 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32110 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32111 {"crypto-neon-fp-armv8",
32112 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
32113 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
32114 {"crypto-neon-fp-armv8.1",
32115 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
32116 {NULL, ARM_ARCH_NONE}
32117 };
32118
32119 struct arm_option_value_table
32120 {
32121 const char *name;
32122 long value;
32123 };
32124
32125 static const struct arm_option_value_table arm_float_abis[] =
32126 {
32127 {"hard", ARM_FLOAT_ABI_HARD},
32128 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32129 {"soft", ARM_FLOAT_ABI_SOFT},
32130 {NULL, 0}
32131 };
32132
32133 #ifdef OBJ_ELF
32134 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
32135 static const struct arm_option_value_table arm_eabis[] =
32136 {
32137 {"gnu", EF_ARM_EABI_UNKNOWN},
32138 {"4", EF_ARM_EABI_VER4},
32139 {"5", EF_ARM_EABI_VER5},
32140 {NULL, 0}
32141 };
32142 #endif
32143
32144 struct arm_long_option_table
32145 {
32146 const char * option; /* Substring to match. */
32147 const char * help; /* Help information. */
32148 int (* func) (const char * subopt); /* Function to decode sub-option. */
32149 const char * deprecated; /* If non-null, print this message. */
32150 };
32151
32152 static bfd_boolean
32153 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
32154 arm_feature_set *ext_set,
32155 const struct arm_ext_table *ext_table)
32156 {
32157 /* We insist on extensions being specified in alphabetical order, and with
32158 extensions being added before being removed. We achieve this by having
32159 the global ARM_EXTENSIONS table in alphabetical order, and using the
32160 ADDING_VALUE variable to indicate whether we are adding an extension (1)
32161 or removing it (0) and only allowing it to change in the order
32162 -1 -> 1 -> 0. */
32163 const struct arm_option_extension_value_table * opt = NULL;
32164 const arm_feature_set arm_any = ARM_ANY;
32165 int adding_value = -1;
32166
32167 while (str != NULL && *str != 0)
32168 {
32169 const char *ext;
32170 size_t len;
32171
32172 if (*str != '+')
32173 {
32174 as_bad (_("invalid architectural extension"));
32175 return FALSE;
32176 }
32177
32178 str++;
32179 ext = strchr (str, '+');
32180
32181 if (ext != NULL)
32182 len = ext - str;
32183 else
32184 len = strlen (str);
32185
32186 if (len >= 2 && strncmp (str, "no", 2) == 0)
32187 {
32188 if (adding_value != 0)
32189 {
32190 adding_value = 0;
32191 opt = arm_extensions;
32192 }
32193
32194 len -= 2;
32195 str += 2;
32196 }
32197 else if (len > 0)
32198 {
32199 if (adding_value == -1)
32200 {
32201 adding_value = 1;
32202 opt = arm_extensions;
32203 }
32204 else if (adding_value != 1)
32205 {
32206 as_bad (_("must specify extensions to add before specifying "
32207 "those to remove"));
32208 return FALSE;
32209 }
32210 }
32211
32212 if (len == 0)
32213 {
32214 as_bad (_("missing architectural extension"));
32215 return FALSE;
32216 }
32217
32218 gas_assert (adding_value != -1);
32219 gas_assert (opt != NULL);
32220
32221 if (ext_table != NULL)
32222 {
32223 const struct arm_ext_table * ext_opt = ext_table;
32224 bfd_boolean found = FALSE;
32225 for (; ext_opt->name != NULL; ext_opt++)
32226 if (ext_opt->name_len == len
32227 && strncmp (ext_opt->name, str, len) == 0)
32228 {
32229 if (adding_value)
32230 {
32231 if (ARM_FEATURE_ZERO (ext_opt->merge))
32232 /* TODO: Option not supported. When we remove the
32233 legacy table this case should error out. */
32234 continue;
32235
32236 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32237 }
32238 else
32239 {
32240 if (ARM_FEATURE_ZERO (ext_opt->clear))
32241 /* TODO: Option not supported. When we remove the
32242 legacy table this case should error out. */
32243 continue;
32244 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32245 }
32246 found = TRUE;
32247 break;
32248 }
32249 if (found)
32250 {
32251 str = ext;
32252 continue;
32253 }
32254 }
32255
32256 /* Scan over the options table trying to find an exact match. */
32257 for (; opt->name != NULL; opt++)
32258 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32259 {
32260 int i, nb_allowed_archs =
32261 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32262 /* Check we can apply the extension to this architecture. */
32263 for (i = 0; i < nb_allowed_archs; i++)
32264 {
32265 /* Empty entry. */
32266 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32267 continue;
32268 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
32269 break;
32270 }
32271 if (i == nb_allowed_archs)
32272 {
32273 as_bad (_("extension does not apply to the base architecture"));
32274 return FALSE;
32275 }
32276
32277 /* Add or remove the extension. */
32278 if (adding_value)
32279 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
32280 else
32281 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
32282
32283 /* Allowing Thumb division instructions for ARMv7 in autodetection
32284 rely on this break so that duplicate extensions (extensions
32285 with the same name as a previous extension in the list) are not
32286 considered for command-line parsing. */
32287 break;
32288 }
32289
32290 if (opt->name == NULL)
32291 {
32292 /* Did we fail to find an extension because it wasn't specified in
32293 alphabetical order, or because it does not exist? */
32294
32295 for (opt = arm_extensions; opt->name != NULL; opt++)
32296 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32297 break;
32298
32299 if (opt->name == NULL)
32300 as_bad (_("unknown architectural extension `%s'"), str);
32301 else
32302 as_bad (_("architectural extensions must be specified in "
32303 "alphabetical order"));
32304
32305 return FALSE;
32306 }
32307 else
32308 {
32309 /* We should skip the extension we've just matched the next time
32310 round. */
32311 opt++;
32312 }
32313
32314 str = ext;
32315 };
32316
32317 return TRUE;
32318 }
32319
32320 static bfd_boolean
32321 arm_parse_fp16_opt (const char *str)
32322 {
32323 if (strcasecmp (str, "ieee") == 0)
32324 fp16_format = ARM_FP16_FORMAT_IEEE;
32325 else if (strcasecmp (str, "alternative") == 0)
32326 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32327 else
32328 {
32329 as_bad (_("unrecognised float16 format \"%s\""), str);
32330 return FALSE;
32331 }
32332
32333 return TRUE;
32334 }
32335
32336 static bfd_boolean
32337 arm_parse_cpu (const char *str)
32338 {
32339 const struct arm_cpu_option_table *opt;
32340 const char *ext = strchr (str, '+');
32341 size_t len;
32342
32343 if (ext != NULL)
32344 len = ext - str;
32345 else
32346 len = strlen (str);
32347
32348 if (len == 0)
32349 {
32350 as_bad (_("missing cpu name `%s'"), str);
32351 return FALSE;
32352 }
32353
32354 for (opt = arm_cpus; opt->name != NULL; opt++)
32355 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32356 {
32357 mcpu_cpu_opt = &opt->value;
32358 if (mcpu_ext_opt == NULL)
32359 mcpu_ext_opt = XNEW (arm_feature_set);
32360 *mcpu_ext_opt = opt->ext;
32361 mcpu_fpu_opt = &opt->default_fpu;
32362 if (opt->canonical_name)
32363 {
32364 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32365 strcpy (selected_cpu_name, opt->canonical_name);
32366 }
32367 else
32368 {
32369 size_t i;
32370
32371 if (len >= sizeof selected_cpu_name)
32372 len = (sizeof selected_cpu_name) - 1;
32373
32374 for (i = 0; i < len; i++)
32375 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32376 selected_cpu_name[i] = 0;
32377 }
32378
32379 if (ext != NULL)
32380 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
32381
32382 return TRUE;
32383 }
32384
32385 as_bad (_("unknown cpu `%s'"), str);
32386 return FALSE;
32387 }
32388
32389 static bfd_boolean
32390 arm_parse_arch (const char *str)
32391 {
32392 const struct arm_arch_option_table *opt;
32393 const char *ext = strchr (str, '+');
32394 size_t len;
32395
32396 if (ext != NULL)
32397 len = ext - str;
32398 else
32399 len = strlen (str);
32400
32401 if (len == 0)
32402 {
32403 as_bad (_("missing architecture name `%s'"), str);
32404 return FALSE;
32405 }
32406
32407 for (opt = arm_archs; opt->name != NULL; opt++)
32408 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32409 {
32410 march_cpu_opt = &opt->value;
32411 if (march_ext_opt == NULL)
32412 march_ext_opt = XNEW (arm_feature_set);
32413 *march_ext_opt = arm_arch_none;
32414 march_fpu_opt = &opt->default_fpu;
32415 selected_ctx_ext_table = opt->ext_table;
32416 strcpy (selected_cpu_name, opt->name);
32417
32418 if (ext != NULL)
32419 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32420 opt->ext_table);
32421
32422 return TRUE;
32423 }
32424
32425 as_bad (_("unknown architecture `%s'\n"), str);
32426 return FALSE;
32427 }
32428
32429 static bfd_boolean
32430 arm_parse_fpu (const char * str)
32431 {
32432 const struct arm_option_fpu_value_table * opt;
32433
32434 for (opt = arm_fpus; opt->name != NULL; opt++)
32435 if (streq (opt->name, str))
32436 {
32437 mfpu_opt = &opt->value;
32438 return TRUE;
32439 }
32440
32441 as_bad (_("unknown floating point format `%s'\n"), str);
32442 return FALSE;
32443 }
32444
32445 static bfd_boolean
32446 arm_parse_float_abi (const char * str)
32447 {
32448 const struct arm_option_value_table * opt;
32449
32450 for (opt = arm_float_abis; opt->name != NULL; opt++)
32451 if (streq (opt->name, str))
32452 {
32453 mfloat_abi_opt = opt->value;
32454 return TRUE;
32455 }
32456
32457 as_bad (_("unknown floating point abi `%s'\n"), str);
32458 return FALSE;
32459 }
32460
32461 #ifdef OBJ_ELF
32462 static bfd_boolean
32463 arm_parse_eabi (const char * str)
32464 {
32465 const struct arm_option_value_table *opt;
32466
32467 for (opt = arm_eabis; opt->name != NULL; opt++)
32468 if (streq (opt->name, str))
32469 {
32470 meabi_flags = opt->value;
32471 return TRUE;
32472 }
32473 as_bad (_("unknown EABI `%s'\n"), str);
32474 return FALSE;
32475 }
32476 #endif
32477
32478 static bfd_boolean
32479 arm_parse_it_mode (const char * str)
32480 {
32481 bfd_boolean ret = TRUE;
32482
32483 if (streq ("arm", str))
32484 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32485 else if (streq ("thumb", str))
32486 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32487 else if (streq ("always", str))
32488 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32489 else if (streq ("never", str))
32490 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32491 else
32492 {
32493 as_bad (_("unknown implicit IT mode `%s', should be "\
32494 "arm, thumb, always, or never."), str);
32495 ret = FALSE;
32496 }
32497
32498 return ret;
32499 }
32500
32501 static bfd_boolean
32502 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
32503 {
32504 codecomposer_syntax = TRUE;
32505 arm_comment_chars[0] = ';';
32506 arm_line_separator_chars[0] = 0;
32507 return TRUE;
32508 }
32509
32510 struct arm_long_option_table arm_long_opts[] =
32511 {
32512 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32513 arm_parse_cpu, NULL},
32514 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32515 arm_parse_arch, NULL},
32516 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32517 arm_parse_fpu, NULL},
32518 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32519 arm_parse_float_abi, NULL},
32520 #ifdef OBJ_ELF
32521 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
32522 arm_parse_eabi, NULL},
32523 #endif
32524 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32525 arm_parse_it_mode, NULL},
32526 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32527 arm_ccs_mode, NULL},
32528 {"mfp16-format=",
32529 N_("[ieee|alternative]\n\
32530 set the encoding for half precision floating point "
32531 "numbers to IEEE\n\
32532 or Arm alternative format."),
32533 arm_parse_fp16_opt, NULL },
32534 {NULL, NULL, 0, NULL}
32535 };
32536
32537 int
32538 md_parse_option (int c, const char * arg)
32539 {
32540 struct arm_option_table *opt;
32541 const struct arm_legacy_option_table *fopt;
32542 struct arm_long_option_table *lopt;
32543
32544 switch (c)
32545 {
32546 #ifdef OPTION_EB
32547 case OPTION_EB:
32548 target_big_endian = 1;
32549 break;
32550 #endif
32551
32552 #ifdef OPTION_EL
32553 case OPTION_EL:
32554 target_big_endian = 0;
32555 break;
32556 #endif
32557
32558 case OPTION_FIX_V4BX:
32559 fix_v4bx = TRUE;
32560 break;
32561
32562 #ifdef OBJ_ELF
32563 case OPTION_FDPIC:
32564 arm_fdpic = TRUE;
32565 break;
32566 #endif /* OBJ_ELF */
32567
32568 case 'a':
32569 /* Listing option. Just ignore these, we don't support additional
32570 ones. */
32571 return 0;
32572
32573 default:
32574 for (opt = arm_opts; opt->option != NULL; opt++)
32575 {
32576 if (c == opt->option[0]
32577 && ((arg == NULL && opt->option[1] == 0)
32578 || streq (arg, opt->option + 1)))
32579 {
32580 /* If the option is deprecated, tell the user. */
32581 if (warn_on_deprecated && opt->deprecated != NULL)
32582 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32583 arg ? arg : "", _(opt->deprecated));
32584
32585 if (opt->var != NULL)
32586 *opt->var = opt->value;
32587
32588 return 1;
32589 }
32590 }
32591
32592 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32593 {
32594 if (c == fopt->option[0]
32595 && ((arg == NULL && fopt->option[1] == 0)
32596 || streq (arg, fopt->option + 1)))
32597 {
32598 /* If the option is deprecated, tell the user. */
32599 if (warn_on_deprecated && fopt->deprecated != NULL)
32600 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32601 arg ? arg : "", _(fopt->deprecated));
32602
32603 if (fopt->var != NULL)
32604 *fopt->var = &fopt->value;
32605
32606 return 1;
32607 }
32608 }
32609
32610 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32611 {
32612 /* These options are expected to have an argument. */
32613 if (c == lopt->option[0]
32614 && arg != NULL
32615 && strncmp (arg, lopt->option + 1,
32616 strlen (lopt->option + 1)) == 0)
32617 {
32618 /* If the option is deprecated, tell the user. */
32619 if (warn_on_deprecated && lopt->deprecated != NULL)
32620 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32621 _(lopt->deprecated));
32622
32623 /* Call the sup-option parser. */
32624 return lopt->func (arg + strlen (lopt->option) - 1);
32625 }
32626 }
32627
32628 return 0;
32629 }
32630
32631 return 1;
32632 }
32633
32634 void
32635 md_show_usage (FILE * fp)
32636 {
32637 struct arm_option_table *opt;
32638 struct arm_long_option_table *lopt;
32639
32640 fprintf (fp, _(" ARM-specific assembler options:\n"));
32641
32642 for (opt = arm_opts; opt->option != NULL; opt++)
32643 if (opt->help != NULL)
32644 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
32645
32646 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32647 if (lopt->help != NULL)
32648 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
32649
32650 #ifdef OPTION_EB
32651 fprintf (fp, _("\
32652 -EB assemble code for a big-endian cpu\n"));
32653 #endif
32654
32655 #ifdef OPTION_EL
32656 fprintf (fp, _("\
32657 -EL assemble code for a little-endian cpu\n"));
32658 #endif
32659
32660 fprintf (fp, _("\
32661 --fix-v4bx Allow BX in ARMv4 code\n"));
32662
32663 #ifdef OBJ_ELF
32664 fprintf (fp, _("\
32665 --fdpic generate an FDPIC object file\n"));
32666 #endif /* OBJ_ELF */
32667 }
32668
32669 #ifdef OBJ_ELF
32670
32671 typedef struct
32672 {
32673 int val;
32674 arm_feature_set flags;
32675 } cpu_arch_ver_table;
32676
32677 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32678 chronologically for architectures, with an exception for ARMv6-M and
32679 ARMv6S-M due to legacy reasons. No new architecture should have a
32680 special case. This allows for build attribute selection results to be
32681 stable when new architectures are added. */
32682 static const cpu_arch_ver_table cpu_arch_ver[] =
32683 {
32684 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32685 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32686 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32687 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32688 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32689 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32690 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32691 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32692 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32693 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32694 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32695 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32696 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32697 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32698 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32699 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32700 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32701 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32702 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32703 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32704 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32705 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32706 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32707 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
32708
32709 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32710 always selected build attributes to match those of ARMv6-M
32711 (resp. ARMv6S-M). However, due to these architectures being a strict
32712 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32713 would be selected when fully respecting chronology of architectures.
32714 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32715 move them before ARMv7 architectures. */
32716 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32717 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32718
32719 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32720 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32721 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32722 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32723 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32724 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32725 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32726 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32727 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32728 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32729 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32730 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32731 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32732 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32733 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32734 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
32735 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32736 {-1, ARM_ARCH_NONE}
32737 };
32738
32739 /* Set an attribute if it has not already been set by the user. */
32740
32741 static void
32742 aeabi_set_attribute_int (int tag, int value)
32743 {
32744 if (tag < 1
32745 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32746 || !attributes_set_explicitly[tag])
32747 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32748 }
32749
32750 static void
32751 aeabi_set_attribute_string (int tag, const char *value)
32752 {
32753 if (tag < 1
32754 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32755 || !attributes_set_explicitly[tag])
32756 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32757 }
32758
32759 /* Return whether features in the *NEEDED feature set are available via
32760 extensions for the architecture whose feature set is *ARCH_FSET. */
32761
32762 static bfd_boolean
32763 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32764 const arm_feature_set *needed)
32765 {
32766 int i, nb_allowed_archs;
32767 arm_feature_set ext_fset;
32768 const struct arm_option_extension_value_table *opt;
32769
32770 ext_fset = arm_arch_none;
32771 for (opt = arm_extensions; opt->name != NULL; opt++)
32772 {
32773 /* Extension does not provide any feature we need. */
32774 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32775 continue;
32776
32777 nb_allowed_archs =
32778 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32779 for (i = 0; i < nb_allowed_archs; i++)
32780 {
32781 /* Empty entry. */
32782 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32783 break;
32784
32785 /* Extension is available, add it. */
32786 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32787 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32788 }
32789 }
32790
32791 /* Can we enable all features in *needed? */
32792 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32793 }
32794
32795 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32796 a given architecture feature set *ARCH_EXT_FSET including extension feature
32797 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32798 - if true, check for an exact match of the architecture modulo extensions;
32799 - otherwise, select build attribute value of the first superset
32800 architecture released so that results remains stable when new architectures
32801 are added.
32802 For -march/-mcpu=all the build attribute value of the most featureful
32803 architecture is returned. Tag_CPU_arch_profile result is returned in
32804 PROFILE. */
32805
32806 static int
32807 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32808 const arm_feature_set *ext_fset,
32809 char *profile, int exact_match)
32810 {
32811 arm_feature_set arch_fset;
32812 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32813
32814 /* Select most featureful architecture with all its extensions if building
32815 for -march=all as the feature sets used to set build attributes. */
32816 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32817 {
32818 /* Force revisiting of decision for each new architecture. */
32819 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
32820 *profile = 'A';
32821 return TAG_CPU_ARCH_V8;
32822 }
32823
32824 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32825
32826 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32827 {
32828 arm_feature_set known_arch_fset;
32829
32830 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32831 if (exact_match)
32832 {
32833 /* Base architecture match user-specified architecture and
32834 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32835 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32836 {
32837 p_ver_ret = p_ver;
32838 goto found;
32839 }
32840 /* Base architecture match user-specified architecture only
32841 (eg. ARMv6-M in the same case as above). Record it in case we
32842 find a match with above condition. */
32843 else if (p_ver_ret == NULL
32844 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32845 p_ver_ret = p_ver;
32846 }
32847 else
32848 {
32849
32850 /* Architecture has all features wanted. */
32851 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32852 {
32853 arm_feature_set added_fset;
32854
32855 /* Compute features added by this architecture over the one
32856 recorded in p_ver_ret. */
32857 if (p_ver_ret != NULL)
32858 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32859 p_ver_ret->flags);
32860 /* First architecture that match incl. with extensions, or the
32861 only difference in features over the recorded match is
32862 features that were optional and are now mandatory. */
32863 if (p_ver_ret == NULL
32864 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32865 {
32866 p_ver_ret = p_ver;
32867 goto found;
32868 }
32869 }
32870 else if (p_ver_ret == NULL)
32871 {
32872 arm_feature_set needed_ext_fset;
32873
32874 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32875
32876 /* Architecture has all features needed when using some
32877 extensions. Record it and continue searching in case there
32878 exist an architecture providing all needed features without
32879 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32880 OS extension). */
32881 if (have_ext_for_needed_feat_p (&known_arch_fset,
32882 &needed_ext_fset))
32883 p_ver_ret = p_ver;
32884 }
32885 }
32886 }
32887
32888 if (p_ver_ret == NULL)
32889 return -1;
32890
32891 found:
32892 /* Tag_CPU_arch_profile. */
32893 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32894 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32895 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32896 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
32897 *profile = 'A';
32898 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
32899 *profile = 'R';
32900 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32901 *profile = 'M';
32902 else
32903 *profile = '\0';
32904 return p_ver_ret->val;
32905 }
32906
32907 /* Set the public EABI object attributes. */
32908
32909 static void
32910 aeabi_set_public_attributes (void)
32911 {
32912 char profile = '\0';
32913 int arch = -1;
32914 int virt_sec = 0;
32915 int fp16_optional = 0;
32916 int skip_exact_match = 0;
32917 arm_feature_set flags, flags_arch, flags_ext;
32918
32919 /* Autodetection mode, choose the architecture based the instructions
32920 actually used. */
32921 if (no_cpu_selected ())
32922 {
32923 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
32924
32925 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32926 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
32927
32928 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32929 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
32930
32931 /* Code run during relaxation relies on selected_cpu being set. */
32932 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32933 flags_ext = arm_arch_none;
32934 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32935 selected_ext = flags_ext;
32936 selected_cpu = flags;
32937 }
32938 /* Otherwise, choose the architecture based on the capabilities of the
32939 requested cpu. */
32940 else
32941 {
32942 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32943 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32944 flags_ext = selected_ext;
32945 flags = selected_cpu;
32946 }
32947 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
32948
32949 /* Allow the user to override the reported architecture. */
32950 if (!ARM_FEATURE_ZERO (selected_object_arch))
32951 {
32952 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
32953 flags_ext = arm_arch_none;
32954 }
32955 else
32956 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
32957
32958 /* When this function is run again after relaxation has happened there is no
32959 way to determine whether an architecture or CPU was specified by the user:
32960 - selected_cpu is set above for relaxation to work;
32961 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32962 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32963 Therefore, if not in -march=all case we first try an exact match and fall
32964 back to autodetection. */
32965 if (!skip_exact_match)
32966 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32967 if (arch == -1)
32968 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32969 if (arch == -1)
32970 as_bad (_("no architecture contains all the instructions used\n"));
32971
32972 /* Tag_CPU_name. */
32973 if (selected_cpu_name[0])
32974 {
32975 char *q;
32976
32977 q = selected_cpu_name;
32978 if (strncmp (q, "armv", 4) == 0)
32979 {
32980 int i;
32981
32982 q += 4;
32983 for (i = 0; q[i]; i++)
32984 q[i] = TOUPPER (q[i]);
32985 }
32986 aeabi_set_attribute_string (Tag_CPU_name, q);
32987 }
32988
32989 /* Tag_CPU_arch. */
32990 aeabi_set_attribute_int (Tag_CPU_arch, arch);
32991
32992 /* Tag_CPU_arch_profile. */
32993 if (profile != '\0')
32994 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
32995
32996 /* Tag_DSP_extension. */
32997 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
32998 aeabi_set_attribute_int (Tag_DSP_extension, 1);
32999
33000 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
33001 /* Tag_ARM_ISA_use. */
33002 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
33003 || ARM_FEATURE_ZERO (flags_arch))
33004 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
33005
33006 /* Tag_THUMB_ISA_use. */
33007 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
33008 || ARM_FEATURE_ZERO (flags_arch))
33009 {
33010 int thumb_isa_use;
33011
33012 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33013 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
33014 thumb_isa_use = 3;
33015 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33016 thumb_isa_use = 2;
33017 else
33018 thumb_isa_use = 1;
33019 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33020 }
33021
33022 /* Tag_VFP_arch. */
33023 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33024 aeabi_set_attribute_int (Tag_VFP_arch,
33025 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33026 ? 7 : 8);
33027 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
33028 aeabi_set_attribute_int (Tag_VFP_arch,
33029 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33030 ? 5 : 6);
33031 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
33032 {
33033 fp16_optional = 1;
33034 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33035 }
33036 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
33037 {
33038 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33039 fp16_optional = 1;
33040 }
33041 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33042 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33043 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
33044 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
33045 aeabi_set_attribute_int (Tag_VFP_arch, 1);
33046
33047 /* Tag_ABI_HardFP_use. */
33048 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33049 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33050 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33051
33052 /* Tag_WMMX_arch. */
33053 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33054 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33055 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33056 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
33057
33058 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
33059 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33060 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33061 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
33062 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33063 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33064 {
33065 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33066 {
33067 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33068 }
33069 else
33070 {
33071 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33072 fp16_optional = 1;
33073 }
33074 }
33075
33076 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33077 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33078 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33079 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33080
33081 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
33082 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
33083 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
33084
33085 /* Tag_DIV_use.
33086
33087 We set Tag_DIV_use to two when integer divide instructions have been used
33088 in ARM state, or when Thumb integer divide instructions have been used,
33089 but we have no architecture profile set, nor have we any ARM instructions.
33090
33091 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33092 by the base architecture.
33093
33094 For new architectures we will have to check these tests. */
33095 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
33096 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33097 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
33098 aeabi_set_attribute_int (Tag_DIV_use, 0);
33099 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33100 || (profile == '\0'
33101 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33102 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
33103 aeabi_set_attribute_int (Tag_DIV_use, 2);
33104
33105 /* Tag_MP_extension_use. */
33106 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33107 aeabi_set_attribute_int (Tag_MPextension_use, 1);
33108
33109 /* Tag Virtualization_use. */
33110 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
33111 virt_sec |= 1;
33112 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33113 virt_sec |= 2;
33114 if (virt_sec != 0)
33115 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
33116
33117 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33118 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
33119 }
33120
33121 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
33122 finished and free extension feature bits which will not be used anymore. */
33123
33124 void
33125 arm_md_post_relax (void)
33126 {
33127 aeabi_set_public_attributes ();
33128 XDELETE (mcpu_ext_opt);
33129 mcpu_ext_opt = NULL;
33130 XDELETE (march_ext_opt);
33131 march_ext_opt = NULL;
33132 }
33133
33134 /* Add the default contents for the .ARM.attributes section. */
33135
33136 void
33137 arm_md_end (void)
33138 {
33139 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33140 return;
33141
33142 aeabi_set_public_attributes ();
33143 }
33144 #endif /* OBJ_ELF */
33145
33146 /* Parse a .cpu directive. */
33147
33148 static void
33149 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33150 {
33151 const struct arm_cpu_option_table *opt;
33152 char *name;
33153 char saved_char;
33154
33155 name = input_line_pointer;
33156 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33157 input_line_pointer++;
33158 saved_char = *input_line_pointer;
33159 *input_line_pointer = 0;
33160
33161 /* Skip the first "all" entry. */
33162 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33163 if (streq (opt->name, name))
33164 {
33165 selected_arch = opt->value;
33166 selected_ext = opt->ext;
33167 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33168 if (opt->canonical_name)
33169 strcpy (selected_cpu_name, opt->canonical_name);
33170 else
33171 {
33172 int i;
33173 for (i = 0; opt->name[i]; i++)
33174 selected_cpu_name[i] = TOUPPER (opt->name[i]);
33175
33176 selected_cpu_name[i] = 0;
33177 }
33178 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33179
33180 *input_line_pointer = saved_char;
33181 demand_empty_rest_of_line ();
33182 return;
33183 }
33184 as_bad (_("unknown cpu `%s'"), name);
33185 *input_line_pointer = saved_char;
33186 ignore_rest_of_line ();
33187 }
33188
33189 /* Parse a .arch directive. */
33190
33191 static void
33192 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33193 {
33194 const struct arm_arch_option_table *opt;
33195 char saved_char;
33196 char *name;
33197
33198 name = input_line_pointer;
33199 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33200 input_line_pointer++;
33201 saved_char = *input_line_pointer;
33202 *input_line_pointer = 0;
33203
33204 /* Skip the first "all" entry. */
33205 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33206 if (streq (opt->name, name))
33207 {
33208 selected_arch = opt->value;
33209 selected_ctx_ext_table = opt->ext_table;
33210 selected_ext = arm_arch_none;
33211 selected_cpu = selected_arch;
33212 strcpy (selected_cpu_name, opt->name);
33213 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33214 *input_line_pointer = saved_char;
33215 demand_empty_rest_of_line ();
33216 return;
33217 }
33218
33219 as_bad (_("unknown architecture `%s'\n"), name);
33220 *input_line_pointer = saved_char;
33221 ignore_rest_of_line ();
33222 }
33223
33224 /* Parse a .object_arch directive. */
33225
33226 static void
33227 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33228 {
33229 const struct arm_arch_option_table *opt;
33230 char saved_char;
33231 char *name;
33232
33233 name = input_line_pointer;
33234 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33235 input_line_pointer++;
33236 saved_char = *input_line_pointer;
33237 *input_line_pointer = 0;
33238
33239 /* Skip the first "all" entry. */
33240 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33241 if (streq (opt->name, name))
33242 {
33243 selected_object_arch = opt->value;
33244 *input_line_pointer = saved_char;
33245 demand_empty_rest_of_line ();
33246 return;
33247 }
33248
33249 as_bad (_("unknown architecture `%s'\n"), name);
33250 *input_line_pointer = saved_char;
33251 ignore_rest_of_line ();
33252 }
33253
33254 /* Parse a .arch_extension directive. */
33255
33256 static void
33257 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33258 {
33259 const struct arm_option_extension_value_table *opt;
33260 char saved_char;
33261 char *name;
33262 int adding_value = 1;
33263
33264 name = input_line_pointer;
33265 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33266 input_line_pointer++;
33267 saved_char = *input_line_pointer;
33268 *input_line_pointer = 0;
33269
33270 if (strlen (name) >= 2
33271 && strncmp (name, "no", 2) == 0)
33272 {
33273 adding_value = 0;
33274 name += 2;
33275 }
33276
33277 /* Check the context specific extension table */
33278 if (selected_ctx_ext_table)
33279 {
33280 const struct arm_ext_table * ext_opt;
33281 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33282 {
33283 if (streq (ext_opt->name, name))
33284 {
33285 if (adding_value)
33286 {
33287 if (ARM_FEATURE_ZERO (ext_opt->merge))
33288 /* TODO: Option not supported. When we remove the
33289 legacy table this case should error out. */
33290 continue;
33291 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33292 ext_opt->merge);
33293 }
33294 else
33295 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33296
33297 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33298 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33299 *input_line_pointer = saved_char;
33300 demand_empty_rest_of_line ();
33301 return;
33302 }
33303 }
33304 }
33305
33306 for (opt = arm_extensions; opt->name != NULL; opt++)
33307 if (streq (opt->name, name))
33308 {
33309 int i, nb_allowed_archs =
33310 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33311 for (i = 0; i < nb_allowed_archs; i++)
33312 {
33313 /* Empty entry. */
33314 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
33315 continue;
33316 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
33317 break;
33318 }
33319
33320 if (i == nb_allowed_archs)
33321 {
33322 as_bad (_("architectural extension `%s' is not allowed for the "
33323 "current base architecture"), name);
33324 break;
33325 }
33326
33327 if (adding_value)
33328 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33329 opt->merge_value);
33330 else
33331 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
33332
33333 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33334 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33335 *input_line_pointer = saved_char;
33336 demand_empty_rest_of_line ();
33337 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33338 on this return so that duplicate extensions (extensions with the
33339 same name as a previous extension in the list) are not considered
33340 for command-line parsing. */
33341 return;
33342 }
33343
33344 if (opt->name == NULL)
33345 as_bad (_("unknown architecture extension `%s'\n"), name);
33346
33347 *input_line_pointer = saved_char;
33348 ignore_rest_of_line ();
33349 }
33350
33351 /* Parse a .fpu directive. */
33352
33353 static void
33354 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33355 {
33356 const struct arm_option_fpu_value_table *opt;
33357 char saved_char;
33358 char *name;
33359
33360 name = input_line_pointer;
33361 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33362 input_line_pointer++;
33363 saved_char = *input_line_pointer;
33364 *input_line_pointer = 0;
33365
33366 for (opt = arm_fpus; opt->name != NULL; opt++)
33367 if (streq (opt->name, name))
33368 {
33369 selected_fpu = opt->value;
33370 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
33371 #ifndef CPU_DEFAULT
33372 if (no_cpu_selected ())
33373 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33374 else
33375 #endif
33376 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33377 *input_line_pointer = saved_char;
33378 demand_empty_rest_of_line ();
33379 return;
33380 }
33381
33382 as_bad (_("unknown floating point format `%s'\n"), name);
33383 *input_line_pointer = saved_char;
33384 ignore_rest_of_line ();
33385 }
33386
33387 /* Copy symbol information. */
33388
33389 void
33390 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33391 {
33392 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33393 }
33394
33395 #ifdef OBJ_ELF
33396 /* Given a symbolic attribute NAME, return the proper integer value.
33397 Returns -1 if the attribute is not known. */
33398
33399 int
33400 arm_convert_symbolic_attribute (const char *name)
33401 {
33402 static const struct
33403 {
33404 const char * name;
33405 const int tag;
33406 }
33407 attribute_table[] =
33408 {
33409 /* When you modify this table you should
33410 also modify the list in doc/c-arm.texi. */
33411 #define T(tag) {#tag, tag}
33412 T (Tag_CPU_raw_name),
33413 T (Tag_CPU_name),
33414 T (Tag_CPU_arch),
33415 T (Tag_CPU_arch_profile),
33416 T (Tag_ARM_ISA_use),
33417 T (Tag_THUMB_ISA_use),
33418 T (Tag_FP_arch),
33419 T (Tag_VFP_arch),
33420 T (Tag_WMMX_arch),
33421 T (Tag_Advanced_SIMD_arch),
33422 T (Tag_PCS_config),
33423 T (Tag_ABI_PCS_R9_use),
33424 T (Tag_ABI_PCS_RW_data),
33425 T (Tag_ABI_PCS_RO_data),
33426 T (Tag_ABI_PCS_GOT_use),
33427 T (Tag_ABI_PCS_wchar_t),
33428 T (Tag_ABI_FP_rounding),
33429 T (Tag_ABI_FP_denormal),
33430 T (Tag_ABI_FP_exceptions),
33431 T (Tag_ABI_FP_user_exceptions),
33432 T (Tag_ABI_FP_number_model),
33433 T (Tag_ABI_align_needed),
33434 T (Tag_ABI_align8_needed),
33435 T (Tag_ABI_align_preserved),
33436 T (Tag_ABI_align8_preserved),
33437 T (Tag_ABI_enum_size),
33438 T (Tag_ABI_HardFP_use),
33439 T (Tag_ABI_VFP_args),
33440 T (Tag_ABI_WMMX_args),
33441 T (Tag_ABI_optimization_goals),
33442 T (Tag_ABI_FP_optimization_goals),
33443 T (Tag_compatibility),
33444 T (Tag_CPU_unaligned_access),
33445 T (Tag_FP_HP_extension),
33446 T (Tag_VFP_HP_extension),
33447 T (Tag_ABI_FP_16bit_format),
33448 T (Tag_MPextension_use),
33449 T (Tag_DIV_use),
33450 T (Tag_nodefaults),
33451 T (Tag_also_compatible_with),
33452 T (Tag_conformance),
33453 T (Tag_T2EE_use),
33454 T (Tag_Virtualization_use),
33455 T (Tag_DSP_extension),
33456 T (Tag_MVE_arch),
33457 /* We deliberately do not include Tag_MPextension_use_legacy. */
33458 #undef T
33459 };
33460 unsigned int i;
33461
33462 if (name == NULL)
33463 return -1;
33464
33465 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
33466 if (streq (name, attribute_table[i].name))
33467 return attribute_table[i].tag;
33468
33469 return -1;
33470 }
33471
33472 /* Apply sym value for relocations only in the case that they are for
33473 local symbols in the same segment as the fixup and you have the
33474 respective architectural feature for blx and simple switches. */
33475
33476 int
33477 arm_apply_sym_value (struct fix * fixP, segT this_seg)
33478 {
33479 if (fixP->fx_addsy
33480 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
33481 /* PR 17444: If the local symbol is in a different section then a reloc
33482 will always be generated for it, so applying the symbol value now
33483 will result in a double offset being stored in the relocation. */
33484 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
33485 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
33486 {
33487 switch (fixP->fx_r_type)
33488 {
33489 case BFD_RELOC_ARM_PCREL_BLX:
33490 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33491 if (ARM_IS_FUNC (fixP->fx_addsy))
33492 return 1;
33493 break;
33494
33495 case BFD_RELOC_ARM_PCREL_CALL:
33496 case BFD_RELOC_THUMB_PCREL_BLX:
33497 if (THUMB_IS_FUNC (fixP->fx_addsy))
33498 return 1;
33499 break;
33500
33501 default:
33502 break;
33503 }
33504
33505 }
33506 return 0;
33507 }
33508 #endif /* OBJ_ELF */
This page took 0.806287 seconds and 4 git commands to generate.