21a2e2d3053e8da9d2d7363d915bf3678e6b5177
[binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2021 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 bool 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 bool 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 static const arm_feature_set arm_ext_v8r = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8R);
234 #ifdef OBJ_ELF
235 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
236 #endif
237 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
238 static const arm_feature_set arm_ext_m =
239 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
240 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
241 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
242 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
243 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
244 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
245 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
246 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
247 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
248 static const arm_feature_set arm_ext_v8m_main =
249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
250 static const arm_feature_set arm_ext_v8_1m_main =
251 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
252 /* Instructions in ARMv8-M only found in M profile architectures. */
253 static const arm_feature_set arm_ext_v8m_m_only =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
255 static const arm_feature_set arm_ext_v6t2_v8m =
256 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
257 /* Instructions shared between ARMv8-A and ARMv8-M. */
258 static const arm_feature_set arm_ext_atomics =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
260 #ifdef OBJ_ELF
261 /* DSP instructions Tag_DSP_extension refers to. */
262 static const arm_feature_set arm_ext_dsp =
263 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
264 #endif
265 static const arm_feature_set arm_ext_ras =
266 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
267 /* FP16 instructions. */
268 static const arm_feature_set arm_ext_fp16 =
269 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
270 static const arm_feature_set arm_ext_fp16_fml =
271 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
272 static const arm_feature_set arm_ext_v8_2 =
273 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
274 static const arm_feature_set arm_ext_v8_3 =
275 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
276 static const arm_feature_set arm_ext_sb =
277 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
278 static const arm_feature_set arm_ext_predres =
279 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
280 static const arm_feature_set arm_ext_bf16 =
281 ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16);
282 static const arm_feature_set arm_ext_i8mm =
283 ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM);
284 static const arm_feature_set arm_ext_crc =
285 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC);
286 static const arm_feature_set arm_ext_cde =
287 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE);
288 static const arm_feature_set arm_ext_cde0 =
289 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE0);
290 static const arm_feature_set arm_ext_cde1 =
291 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE1);
292 static const arm_feature_set arm_ext_cde2 =
293 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE2);
294 static const arm_feature_set arm_ext_cde3 =
295 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE3);
296 static const arm_feature_set arm_ext_cde4 =
297 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE4);
298 static const arm_feature_set arm_ext_cde5 =
299 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE5);
300 static const arm_feature_set arm_ext_cde6 =
301 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE6);
302 static const arm_feature_set arm_ext_cde7 =
303 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE7);
304
305 static const arm_feature_set arm_arch_any = ARM_ANY;
306 static const arm_feature_set fpu_any = FPU_ANY;
307 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
308 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
309 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
310
311 static const arm_feature_set arm_cext_iwmmxt2 =
312 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
313 static const arm_feature_set arm_cext_iwmmxt =
314 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
315 static const arm_feature_set arm_cext_xscale =
316 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
317 static const arm_feature_set arm_cext_maverick =
318 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
319 static const arm_feature_set fpu_fpa_ext_v1 =
320 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
321 static const arm_feature_set fpu_fpa_ext_v2 =
322 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
323 static const arm_feature_set fpu_vfp_ext_v1xd =
324 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
325 static const arm_feature_set fpu_vfp_ext_v1 =
326 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
327 static const arm_feature_set fpu_vfp_ext_v2 =
328 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
329 static const arm_feature_set fpu_vfp_ext_v3xd =
330 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
331 static const arm_feature_set fpu_vfp_ext_v3 =
332 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
333 static const arm_feature_set fpu_vfp_ext_d32 =
334 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
335 static const arm_feature_set fpu_neon_ext_v1 =
336 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
337 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
338 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
339 static const arm_feature_set mve_ext =
340 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE);
341 static const arm_feature_set mve_fp_ext =
342 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP);
343 /* Note: This has more than one bit set, which means using it with
344 mark_feature_used (which returns if *any* of the bits are set in the current
345 cpu variant) can give surprising results. */
346 static const arm_feature_set armv8m_fp =
347 ARM_FEATURE_COPROC (FPU_VFP_V5_SP_D16);
348 #ifdef OBJ_ELF
349 static const arm_feature_set fpu_vfp_fp16 =
350 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
351 static const arm_feature_set fpu_neon_ext_fma =
352 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
353 #endif
354 static const arm_feature_set fpu_vfp_ext_fma =
355 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
356 static const arm_feature_set fpu_vfp_ext_armv8 =
357 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
358 static const arm_feature_set fpu_vfp_ext_armv8xd =
359 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
360 static const arm_feature_set fpu_neon_ext_armv8 =
361 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
362 static const arm_feature_set fpu_crypto_ext_armv8 =
363 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
364 static const arm_feature_set fpu_neon_ext_v8_1 =
365 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
366 static const arm_feature_set fpu_neon_ext_dotprod =
367 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
368 static const arm_feature_set pacbti_ext =
369 ARM_FEATURE_CORE_HIGH_HIGH (ARM_EXT3_PACBTI);
370
371 static int mfloat_abi_opt = -1;
372 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
373 directive. */
374 static arm_feature_set selected_arch = ARM_ARCH_NONE;
375 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
376 directive. */
377 static arm_feature_set selected_ext = ARM_ARCH_NONE;
378 /* Feature bits selected by the last -mcpu/-march or by the combination of the
379 last .cpu/.arch directive .arch_extension directives since that
380 directive. */
381 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
382 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
383 static arm_feature_set selected_fpu = FPU_NONE;
384 /* Feature bits selected by the last .object_arch directive. */
385 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
386 /* Must be long enough to hold any of the names in arm_cpus. */
387 static const struct arm_ext_table * selected_ctx_ext_table = NULL;
388 static char selected_cpu_name[20];
389
390 extern FLONUM_TYPE generic_floating_point_number;
391
392 /* Return if no cpu was selected on command-line. */
393 static bool
394 no_cpu_selected (void)
395 {
396 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
397 }
398
399 #ifdef OBJ_ELF
400 # ifdef EABI_DEFAULT
401 static int meabi_flags = EABI_DEFAULT;
402 # else
403 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
404 # endif
405
406 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
407
408 bool
409 arm_is_eabi (void)
410 {
411 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
412 }
413 #endif
414
415 #ifdef OBJ_ELF
416 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
417 symbolS * GOT_symbol;
418 #endif
419
420 /* 0: assemble for ARM,
421 1: assemble for Thumb,
422 2: assemble for Thumb even though target CPU does not support thumb
423 instructions. */
424 static int thumb_mode = 0;
425 /* A value distinct from the possible values for thumb_mode that we
426 can use to record whether thumb_mode has been copied into the
427 tc_frag_data field of a frag. */
428 #define MODE_RECORDED (1 << 4)
429
430 /* Specifies the intrinsic IT insn behavior mode. */
431 enum implicit_it_mode
432 {
433 IMPLICIT_IT_MODE_NEVER = 0x00,
434 IMPLICIT_IT_MODE_ARM = 0x01,
435 IMPLICIT_IT_MODE_THUMB = 0x02,
436 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
437 };
438 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
439
440 /* If unified_syntax is true, we are processing the new unified
441 ARM/Thumb syntax. Important differences from the old ARM mode:
442
443 - Immediate operands do not require a # prefix.
444 - Conditional affixes always appear at the end of the
445 instruction. (For backward compatibility, those instructions
446 that formerly had them in the middle, continue to accept them
447 there.)
448 - The IT instruction may appear, and if it does is validated
449 against subsequent conditional affixes. It does not generate
450 machine code.
451
452 Important differences from the old Thumb mode:
453
454 - Immediate operands do not require a # prefix.
455 - Most of the V6T2 instructions are only available in unified mode.
456 - The .N and .W suffixes are recognized and honored (it is an error
457 if they cannot be honored).
458 - All instructions set the flags if and only if they have an 's' affix.
459 - Conditional affixes may be used. They are validated against
460 preceding IT instructions. Unlike ARM mode, you cannot use a
461 conditional affix except in the scope of an IT instruction. */
462
463 static bool unified_syntax = false;
464
465 /* An immediate operand can start with #, and ld*, st*, pld operands
466 can contain [ and ]. We need to tell APP not to elide whitespace
467 before a [, which can appear as the first operand for pld.
468 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
469 const char arm_symbol_chars[] = "#[]{}";
470
471 enum neon_el_type
472 {
473 NT_invtype,
474 NT_untyped,
475 NT_integer,
476 NT_float,
477 NT_poly,
478 NT_signed,
479 NT_bfloat,
480 NT_unsigned
481 };
482
483 struct neon_type_el
484 {
485 enum neon_el_type type;
486 unsigned size;
487 };
488
489 #define NEON_MAX_TYPE_ELS 5
490
491 struct neon_type
492 {
493 struct neon_type_el el[NEON_MAX_TYPE_ELS];
494 unsigned elems;
495 };
496
497 enum pred_instruction_type
498 {
499 OUTSIDE_PRED_INSN,
500 INSIDE_VPT_INSN,
501 INSIDE_IT_INSN,
502 INSIDE_IT_LAST_INSN,
503 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
504 if inside, should be the last one. */
505 NEUTRAL_IT_INSN, /* This could be either inside or outside,
506 i.e. BKPT and NOP. */
507 IT_INSN, /* The IT insn has been parsed. */
508 VPT_INSN, /* The VPT/VPST insn has been parsed. */
509 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
510 a predication code. */
511 MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */
512 };
513
514 /* The maximum number of operands we need. */
515 #define ARM_IT_MAX_OPERANDS 6
516 #define ARM_IT_MAX_RELOCS 3
517
518 struct arm_it
519 {
520 const char * error;
521 unsigned long instruction;
522 unsigned int size;
523 unsigned int size_req;
524 unsigned int cond;
525 /* "uncond_value" is set to the value in place of the conditional field in
526 unconditional versions of the instruction, or -1u if nothing is
527 appropriate. */
528 unsigned int uncond_value;
529 struct neon_type vectype;
530 /* This does not indicate an actual NEON instruction, only that
531 the mnemonic accepts neon-style type suffixes. */
532 int is_neon;
533 /* Set to the opcode if the instruction needs relaxation.
534 Zero if the instruction is not relaxed. */
535 unsigned long relax;
536 struct
537 {
538 bfd_reloc_code_real_type type;
539 expressionS exp;
540 int pc_rel;
541 } relocs[ARM_IT_MAX_RELOCS];
542
543 enum pred_instruction_type pred_insn_type;
544
545 struct
546 {
547 unsigned reg;
548 signed int imm;
549 struct neon_type_el vectype;
550 unsigned present : 1; /* Operand present. */
551 unsigned isreg : 1; /* Operand was a register. */
552 unsigned immisreg : 2; /* .imm field is a second register.
553 0: imm, 1: gpr, 2: MVE Q-register. */
554 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
555 0) not scalar,
556 1) Neon scalar,
557 2) MVE scalar. */
558 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
559 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
560 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
561 instructions. This allows us to disambiguate ARM <-> vector insns. */
562 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
563 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
564 unsigned isquad : 1; /* Operand is SIMD quad register. */
565 unsigned issingle : 1; /* Operand is VFP single-precision register. */
566 unsigned iszr : 1; /* Operand is ZR register. */
567 unsigned hasreloc : 1; /* Operand has relocation suffix. */
568 unsigned writeback : 1; /* Operand has trailing ! */
569 unsigned preind : 1; /* Preindexed address. */
570 unsigned postind : 1; /* Postindexed address. */
571 unsigned negative : 1; /* Index register was negated. */
572 unsigned shifted : 1; /* Shift applied to operation. */
573 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
574 } operands[ARM_IT_MAX_OPERANDS];
575 };
576
577 static struct arm_it inst;
578
579 #define NUM_FLOAT_VALS 8
580
581 const char * fp_const[] =
582 {
583 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
584 };
585
586 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
587
588 #define FAIL (-1)
589 #define SUCCESS (0)
590
591 #define SUFF_S 1
592 #define SUFF_D 2
593 #define SUFF_E 3
594 #define SUFF_P 4
595
596 #define CP_T_X 0x00008000
597 #define CP_T_Y 0x00400000
598
599 #define CONDS_BIT 0x00100000
600 #define LOAD_BIT 0x00100000
601
602 #define DOUBLE_LOAD_FLAG 0x00000001
603
604 struct asm_cond
605 {
606 const char * template_name;
607 unsigned long value;
608 };
609
610 #define COND_ALWAYS 0xE
611
612 struct asm_psr
613 {
614 const char * template_name;
615 unsigned long field;
616 };
617
618 struct asm_barrier_opt
619 {
620 const char * template_name;
621 unsigned long value;
622 const arm_feature_set arch;
623 };
624
625 /* The bit that distinguishes CPSR and SPSR. */
626 #define SPSR_BIT (1 << 22)
627
628 /* The individual PSR flag bits. */
629 #define PSR_c (1 << 16)
630 #define PSR_x (1 << 17)
631 #define PSR_s (1 << 18)
632 #define PSR_f (1 << 19)
633
634 struct reloc_entry
635 {
636 const char * name;
637 bfd_reloc_code_real_type reloc;
638 };
639
640 enum vfp_reg_pos
641 {
642 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
643 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
644 };
645
646 enum vfp_ldstm_type
647 {
648 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
649 };
650
651 /* Bits for DEFINED field in neon_typed_alias. */
652 #define NTA_HASTYPE 1
653 #define NTA_HASINDEX 2
654
655 struct neon_typed_alias
656 {
657 unsigned char defined;
658 unsigned char index;
659 struct neon_type_el eltype;
660 };
661
662 /* ARM register categories. This includes coprocessor numbers and various
663 architecture extensions' registers. Each entry should have an error message
664 in reg_expected_msgs below. */
665 enum arm_reg_type
666 {
667 REG_TYPE_RN,
668 REG_TYPE_CP,
669 REG_TYPE_CN,
670 REG_TYPE_FN,
671 REG_TYPE_VFS,
672 REG_TYPE_VFD,
673 REG_TYPE_NQ,
674 REG_TYPE_VFSD,
675 REG_TYPE_NDQ,
676 REG_TYPE_NSD,
677 REG_TYPE_NSDQ,
678 REG_TYPE_VFC,
679 REG_TYPE_MVF,
680 REG_TYPE_MVD,
681 REG_TYPE_MVFX,
682 REG_TYPE_MVDX,
683 REG_TYPE_MVAX,
684 REG_TYPE_MQ,
685 REG_TYPE_DSPSC,
686 REG_TYPE_MMXWR,
687 REG_TYPE_MMXWC,
688 REG_TYPE_MMXWCG,
689 REG_TYPE_XSCALE,
690 REG_TYPE_RNB,
691 REG_TYPE_ZR
692 };
693
694 /* Structure for a hash table entry for a register.
695 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
696 information which states whether a vector type or index is specified (for a
697 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
698 struct reg_entry
699 {
700 const char * name;
701 unsigned int number;
702 unsigned char type;
703 unsigned char builtin;
704 struct neon_typed_alias * neon;
705 };
706
707 /* Diagnostics used when we don't get a register of the expected type. */
708 const char * const reg_expected_msgs[] =
709 {
710 [REG_TYPE_RN] = N_("ARM register expected"),
711 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
712 [REG_TYPE_CN] = N_("co-processor register expected"),
713 [REG_TYPE_FN] = N_("FPA register expected"),
714 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
715 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
716 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
717 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
718 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
719 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
720 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
721 " expected"),
722 [REG_TYPE_VFC] = N_("VFP system register expected"),
723 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
724 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
725 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
726 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
727 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
728 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
729 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
730 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
731 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
732 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
733 [REG_TYPE_MQ] = N_("MVE vector register expected"),
734 [REG_TYPE_RNB] = "",
735 [REG_TYPE_ZR] = N_("ZR register expected"),
736 };
737
738 /* Some well known registers that we refer to directly elsewhere. */
739 #define REG_R12 12
740 #define REG_SP 13
741 #define REG_LR 14
742 #define REG_PC 15
743
744 /* ARM instructions take 4bytes in the object file, Thumb instructions
745 take 2: */
746 #define INSN_SIZE 4
747
748 struct asm_opcode
749 {
750 /* Basic string to match. */
751 const char * template_name;
752
753 /* Parameters to instruction. */
754 unsigned int operands[8];
755
756 /* Conditional tag - see opcode_lookup. */
757 unsigned int tag : 4;
758
759 /* Basic instruction code. */
760 unsigned int avalue;
761
762 /* Thumb-format instruction code. */
763 unsigned int tvalue;
764
765 /* Which architecture variant provides this instruction. */
766 const arm_feature_set * avariant;
767 const arm_feature_set * tvariant;
768
769 /* Function to call to encode instruction in ARM format. */
770 void (* aencode) (void);
771
772 /* Function to call to encode instruction in Thumb format. */
773 void (* tencode) (void);
774
775 /* Indicates whether this instruction may be vector predicated. */
776 unsigned int mayBeVecPred : 1;
777 };
778
779 /* Defines for various bits that we will want to toggle. */
780 #define INST_IMMEDIATE 0x02000000
781 #define OFFSET_REG 0x02000000
782 #define HWOFFSET_IMM 0x00400000
783 #define SHIFT_BY_REG 0x00000010
784 #define PRE_INDEX 0x01000000
785 #define INDEX_UP 0x00800000
786 #define WRITE_BACK 0x00200000
787 #define LDM_TYPE_2_OR_3 0x00400000
788 #define CPSI_MMOD 0x00020000
789
790 #define LITERAL_MASK 0xf000f000
791 #define OPCODE_MASK 0xfe1fffff
792 #define V4_STR_BIT 0x00000020
793 #define VLDR_VMOV_SAME 0x0040f000
794
795 #define T2_SUBS_PC_LR 0xf3de8f00
796
797 #define DATA_OP_SHIFT 21
798 #define SBIT_SHIFT 20
799
800 #define T2_OPCODE_MASK 0xfe1fffff
801 #define T2_DATA_OP_SHIFT 21
802 #define T2_SBIT_SHIFT 20
803
804 #define A_COND_MASK 0xf0000000
805 #define A_PUSH_POP_OP_MASK 0x0fff0000
806
807 /* Opcodes for pushing/poping registers to/from the stack. */
808 #define A1_OPCODE_PUSH 0x092d0000
809 #define A2_OPCODE_PUSH 0x052d0004
810 #define A2_OPCODE_POP 0x049d0004
811
812 /* Codes to distinguish the arithmetic instructions. */
813 #define OPCODE_AND 0
814 #define OPCODE_EOR 1
815 #define OPCODE_SUB 2
816 #define OPCODE_RSB 3
817 #define OPCODE_ADD 4
818 #define OPCODE_ADC 5
819 #define OPCODE_SBC 6
820 #define OPCODE_RSC 7
821 #define OPCODE_TST 8
822 #define OPCODE_TEQ 9
823 #define OPCODE_CMP 10
824 #define OPCODE_CMN 11
825 #define OPCODE_ORR 12
826 #define OPCODE_MOV 13
827 #define OPCODE_BIC 14
828 #define OPCODE_MVN 15
829
830 #define T2_OPCODE_AND 0
831 #define T2_OPCODE_BIC 1
832 #define T2_OPCODE_ORR 2
833 #define T2_OPCODE_ORN 3
834 #define T2_OPCODE_EOR 4
835 #define T2_OPCODE_ADD 8
836 #define T2_OPCODE_ADC 10
837 #define T2_OPCODE_SBC 11
838 #define T2_OPCODE_SUB 13
839 #define T2_OPCODE_RSB 14
840
841 #define T_OPCODE_MUL 0x4340
842 #define T_OPCODE_TST 0x4200
843 #define T_OPCODE_CMN 0x42c0
844 #define T_OPCODE_NEG 0x4240
845 #define T_OPCODE_MVN 0x43c0
846
847 #define T_OPCODE_ADD_R3 0x1800
848 #define T_OPCODE_SUB_R3 0x1a00
849 #define T_OPCODE_ADD_HI 0x4400
850 #define T_OPCODE_ADD_ST 0xb000
851 #define T_OPCODE_SUB_ST 0xb080
852 #define T_OPCODE_ADD_SP 0xa800
853 #define T_OPCODE_ADD_PC 0xa000
854 #define T_OPCODE_ADD_I8 0x3000
855 #define T_OPCODE_SUB_I8 0x3800
856 #define T_OPCODE_ADD_I3 0x1c00
857 #define T_OPCODE_SUB_I3 0x1e00
858
859 #define T_OPCODE_ASR_R 0x4100
860 #define T_OPCODE_LSL_R 0x4080
861 #define T_OPCODE_LSR_R 0x40c0
862 #define T_OPCODE_ROR_R 0x41c0
863 #define T_OPCODE_ASR_I 0x1000
864 #define T_OPCODE_LSL_I 0x0000
865 #define T_OPCODE_LSR_I 0x0800
866
867 #define T_OPCODE_MOV_I8 0x2000
868 #define T_OPCODE_CMP_I8 0x2800
869 #define T_OPCODE_CMP_LR 0x4280
870 #define T_OPCODE_MOV_HR 0x4600
871 #define T_OPCODE_CMP_HR 0x4500
872
873 #define T_OPCODE_LDR_PC 0x4800
874 #define T_OPCODE_LDR_SP 0x9800
875 #define T_OPCODE_STR_SP 0x9000
876 #define T_OPCODE_LDR_IW 0x6800
877 #define T_OPCODE_STR_IW 0x6000
878 #define T_OPCODE_LDR_IH 0x8800
879 #define T_OPCODE_STR_IH 0x8000
880 #define T_OPCODE_LDR_IB 0x7800
881 #define T_OPCODE_STR_IB 0x7000
882 #define T_OPCODE_LDR_RW 0x5800
883 #define T_OPCODE_STR_RW 0x5000
884 #define T_OPCODE_LDR_RH 0x5a00
885 #define T_OPCODE_STR_RH 0x5200
886 #define T_OPCODE_LDR_RB 0x5c00
887 #define T_OPCODE_STR_RB 0x5400
888
889 #define T_OPCODE_PUSH 0xb400
890 #define T_OPCODE_POP 0xbc00
891
892 #define T_OPCODE_BRANCH 0xe000
893
894 #define THUMB_SIZE 2 /* Size of thumb instruction. */
895 #define THUMB_PP_PC_LR 0x0100
896 #define THUMB_LOAD_BIT 0x0800
897 #define THUMB2_LOAD_BIT 0x00100000
898
899 #define BAD_SYNTAX _("syntax error")
900 #define BAD_ARGS _("bad arguments to instruction")
901 #define BAD_SP _("r13 not allowed here")
902 #define BAD_PC _("r15 not allowed here")
903 #define BAD_ODD _("Odd register not allowed here")
904 #define BAD_EVEN _("Even register not allowed here")
905 #define BAD_COND _("instruction cannot be conditional")
906 #define BAD_OVERLAP _("registers may not be the same")
907 #define BAD_HIREG _("lo register required")
908 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
909 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
910 #define BAD_BRANCH _("branch must be last instruction in IT block")
911 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
912 #define BAD_NO_VPT _("instruction not allowed in VPT block")
913 #define BAD_NOT_IT _("instruction not allowed in IT block")
914 #define BAD_NOT_VPT _("instruction missing MVE vector predication code")
915 #define BAD_FPU _("selected FPU does not support instruction")
916 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
917 #define BAD_OUT_VPT \
918 _("vector predicated instruction should be in VPT/VPST block")
919 #define BAD_IT_COND _("incorrect condition in IT block")
920 #define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
921 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
922 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
923 #define BAD_PC_ADDRESSING \
924 _("cannot use register index with PC-relative addressing")
925 #define BAD_PC_WRITEBACK \
926 _("cannot use writeback with PC-relative addressing")
927 #define BAD_RANGE _("branch out of range")
928 #define BAD_FP16 _("selected processor does not support fp16 instruction")
929 #define BAD_BF16 _("selected processor does not support bf16 instruction")
930 #define BAD_CDE _("selected processor does not support cde instruction")
931 #define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde")
932 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
933 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
934 #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
935 "block")
936 #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
937 "block")
938 #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
939 " operand")
940 #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
941 " operand")
942 #define BAD_SIMD_TYPE _("bad type in SIMD instruction")
943 #define BAD_MVE_AUTO \
944 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
945 " use a valid -march or -mcpu option.")
946 #define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
947 "and source operands makes instruction UNPREDICTABLE")
948 #define BAD_EL_TYPE _("bad element type for instruction")
949 #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
950 #define BAD_PACBTI _("selected processor does not support PACBTI extention")
951
952 static htab_t arm_ops_hsh;
953 static htab_t arm_cond_hsh;
954 static htab_t arm_vcond_hsh;
955 static htab_t arm_shift_hsh;
956 static htab_t arm_psr_hsh;
957 static htab_t arm_v7m_psr_hsh;
958 static htab_t arm_reg_hsh;
959 static htab_t arm_reloc_hsh;
960 static htab_t arm_barrier_opt_hsh;
961
962 /* Stuff needed to resolve the label ambiguity
963 As:
964 ...
965 label: <insn>
966 may differ from:
967 ...
968 label:
969 <insn> */
970
971 symbolS * last_label_seen;
972 static int label_is_thumb_function_name = false;
973
974 /* Literal pool structure. Held on a per-section
975 and per-sub-section basis. */
976
977 #define MAX_LITERAL_POOL_SIZE 1024
978 typedef struct literal_pool
979 {
980 expressionS literals [MAX_LITERAL_POOL_SIZE];
981 unsigned int next_free_entry;
982 unsigned int id;
983 symbolS * symbol;
984 segT section;
985 subsegT sub_section;
986 #ifdef OBJ_ELF
987 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
988 #endif
989 struct literal_pool * next;
990 unsigned int alignment;
991 } literal_pool;
992
993 /* Pointer to a linked list of literal pools. */
994 literal_pool * list_of_pools = NULL;
995
996 typedef enum asmfunc_states
997 {
998 OUTSIDE_ASMFUNC,
999 WAITING_ASMFUNC_NAME,
1000 WAITING_ENDASMFUNC
1001 } asmfunc_states;
1002
1003 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
1004
1005 #ifdef OBJ_ELF
1006 # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
1007 #else
1008 static struct current_pred now_pred;
1009 #endif
1010
1011 static inline int
1012 now_pred_compatible (int cond)
1013 {
1014 return (cond & ~1) == (now_pred.cc & ~1);
1015 }
1016
1017 static inline int
1018 conditional_insn (void)
1019 {
1020 return inst.cond != COND_ALWAYS;
1021 }
1022
1023 static int in_pred_block (void);
1024
1025 static int handle_pred_state (void);
1026
1027 static void force_automatic_it_block_close (void);
1028
1029 static void it_fsm_post_encode (void);
1030
1031 #define set_pred_insn_type(type) \
1032 do \
1033 { \
1034 inst.pred_insn_type = type; \
1035 if (handle_pred_state () == FAIL) \
1036 return; \
1037 } \
1038 while (0)
1039
1040 #define set_pred_insn_type_nonvoid(type, failret) \
1041 do \
1042 { \
1043 inst.pred_insn_type = type; \
1044 if (handle_pred_state () == FAIL) \
1045 return failret; \
1046 } \
1047 while(0)
1048
1049 #define set_pred_insn_type_last() \
1050 do \
1051 { \
1052 if (inst.cond == COND_ALWAYS) \
1053 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
1054 else \
1055 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
1056 } \
1057 while (0)
1058
1059 /* Toggle value[pos]. */
1060 #define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1061
1062 /* Pure syntax. */
1063
1064 /* This array holds the chars that always start a comment. If the
1065 pre-processor is disabled, these aren't very useful. */
1066 char arm_comment_chars[] = "@";
1067
1068 /* This array holds the chars that only start a comment at the beginning of
1069 a line. If the line seems to have the form '# 123 filename'
1070 .line and .file directives will appear in the pre-processed output. */
1071 /* Note that input_file.c hand checks for '#' at the beginning of the
1072 first line of the input file. This is because the compiler outputs
1073 #NO_APP at the beginning of its output. */
1074 /* Also note that comments like this one will always work. */
1075 const char line_comment_chars[] = "#";
1076
1077 char arm_line_separator_chars[] = ";";
1078
1079 /* Chars that can be used to separate mant
1080 from exp in floating point numbers. */
1081 const char EXP_CHARS[] = "eE";
1082
1083 /* Chars that mean this number is a floating point constant. */
1084 /* As in 0f12.456 */
1085 /* or 0d1.2345e12 */
1086
1087 const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
1088
1089 /* Prefix characters that indicate the start of an immediate
1090 value. */
1091 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1092
1093 /* Separator character handling. */
1094
1095 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1096
1097 enum fp_16bit_format
1098 {
1099 ARM_FP16_FORMAT_IEEE = 0x1,
1100 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1101 ARM_FP16_FORMAT_DEFAULT = 0x3
1102 };
1103
1104 static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1105
1106
1107 static inline int
1108 skip_past_char (char ** str, char c)
1109 {
1110 /* PR gas/14987: Allow for whitespace before the expected character. */
1111 skip_whitespace (*str);
1112
1113 if (**str == c)
1114 {
1115 (*str)++;
1116 return SUCCESS;
1117 }
1118 else
1119 return FAIL;
1120 }
1121
1122 #define skip_past_comma(str) skip_past_char (str, ',')
1123
1124 /* Arithmetic expressions (possibly involving symbols). */
1125
1126 /* Return TRUE if anything in the expression is a bignum. */
1127
1128 static bool
1129 walk_no_bignums (symbolS * sp)
1130 {
1131 if (symbol_get_value_expression (sp)->X_op == O_big)
1132 return true;
1133
1134 if (symbol_get_value_expression (sp)->X_add_symbol)
1135 {
1136 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1137 || (symbol_get_value_expression (sp)->X_op_symbol
1138 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1139 }
1140
1141 return false;
1142 }
1143
1144 static bool in_my_get_expression = false;
1145
1146 /* Third argument to my_get_expression. */
1147 #define GE_NO_PREFIX 0
1148 #define GE_IMM_PREFIX 1
1149 #define GE_OPT_PREFIX 2
1150 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1151 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1152 #define GE_OPT_PREFIX_BIG 3
1153
1154 static int
1155 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1156 {
1157 char * save_in;
1158
1159 /* In unified syntax, all prefixes are optional. */
1160 if (unified_syntax)
1161 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1162 : GE_OPT_PREFIX;
1163
1164 switch (prefix_mode)
1165 {
1166 case GE_NO_PREFIX: break;
1167 case GE_IMM_PREFIX:
1168 if (!is_immediate_prefix (**str))
1169 {
1170 inst.error = _("immediate expression requires a # prefix");
1171 return FAIL;
1172 }
1173 (*str)++;
1174 break;
1175 case GE_OPT_PREFIX:
1176 case GE_OPT_PREFIX_BIG:
1177 if (is_immediate_prefix (**str))
1178 (*str)++;
1179 break;
1180 default:
1181 abort ();
1182 }
1183
1184 memset (ep, 0, sizeof (expressionS));
1185
1186 save_in = input_line_pointer;
1187 input_line_pointer = *str;
1188 in_my_get_expression = true;
1189 expression (ep);
1190 in_my_get_expression = false;
1191
1192 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1193 {
1194 /* We found a bad or missing expression in md_operand(). */
1195 *str = input_line_pointer;
1196 input_line_pointer = save_in;
1197 if (inst.error == NULL)
1198 inst.error = (ep->X_op == O_absent
1199 ? _("missing expression") :_("bad expression"));
1200 return 1;
1201 }
1202
1203 /* Get rid of any bignums now, so that we don't generate an error for which
1204 we can't establish a line number later on. Big numbers are never valid
1205 in instructions, which is where this routine is always called. */
1206 if (prefix_mode != GE_OPT_PREFIX_BIG
1207 && (ep->X_op == O_big
1208 || (ep->X_add_symbol
1209 && (walk_no_bignums (ep->X_add_symbol)
1210 || (ep->X_op_symbol
1211 && walk_no_bignums (ep->X_op_symbol))))))
1212 {
1213 inst.error = _("invalid constant");
1214 *str = input_line_pointer;
1215 input_line_pointer = save_in;
1216 return 1;
1217 }
1218
1219 *str = input_line_pointer;
1220 input_line_pointer = save_in;
1221 return SUCCESS;
1222 }
1223
1224 /* Turn a string in input_line_pointer into a floating point constant
1225 of type TYPE, and store the appropriate bytes in *LITP. The number
1226 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1227 returned, or NULL on OK.
1228
1229 Note that fp constants aren't represent in the normal way on the ARM.
1230 In big endian mode, things are as expected. However, in little endian
1231 mode fp constants are big-endian word-wise, and little-endian byte-wise
1232 within the words. For example, (double) 1.1 in big endian mode is
1233 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1234 the byte sequence 99 99 f1 3f 9a 99 99 99.
1235
1236 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1237
1238 const char *
1239 md_atof (int type, char * litP, int * sizeP)
1240 {
1241 int prec;
1242 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1243 char *t;
1244 int i;
1245
1246 switch (type)
1247 {
1248 case 'H':
1249 case 'h':
1250 /* bfloat16, despite not being part of the IEEE specification, can also
1251 be handled by atof_ieee(). */
1252 case 'b':
1253 prec = 1;
1254 break;
1255
1256 case 'f':
1257 case 'F':
1258 case 's':
1259 case 'S':
1260 prec = 2;
1261 break;
1262
1263 case 'd':
1264 case 'D':
1265 case 'r':
1266 case 'R':
1267 prec = 4;
1268 break;
1269
1270 case 'x':
1271 case 'X':
1272 prec = 5;
1273 break;
1274
1275 case 'p':
1276 case 'P':
1277 prec = 5;
1278 break;
1279
1280 default:
1281 *sizeP = 0;
1282 return _("Unrecognized or unsupported floating point constant");
1283 }
1284
1285 t = atof_ieee (input_line_pointer, type, words);
1286 if (t)
1287 input_line_pointer = t;
1288 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1289
1290 if (target_big_endian || prec == 1)
1291 for (i = 0; i < prec; i++)
1292 {
1293 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1294 litP += sizeof (LITTLENUM_TYPE);
1295 }
1296 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1297 for (i = prec - 1; i >= 0; i--)
1298 {
1299 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1300 litP += sizeof (LITTLENUM_TYPE);
1301 }
1302 else
1303 /* For a 4 byte float the order of elements in `words' is 1 0.
1304 For an 8 byte float the order is 1 0 3 2. */
1305 for (i = 0; i < prec; i += 2)
1306 {
1307 md_number_to_chars (litP, (valueT) words[i + 1],
1308 sizeof (LITTLENUM_TYPE));
1309 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1310 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1311 litP += 2 * sizeof (LITTLENUM_TYPE);
1312 }
1313
1314 return NULL;
1315 }
1316
1317 /* We handle all bad expressions here, so that we can report the faulty
1318 instruction in the error message. */
1319
1320 void
1321 md_operand (expressionS * exp)
1322 {
1323 if (in_my_get_expression)
1324 exp->X_op = O_illegal;
1325 }
1326
1327 /* Immediate values. */
1328
1329 #ifdef OBJ_ELF
1330 /* Generic immediate-value read function for use in directives.
1331 Accepts anything that 'expression' can fold to a constant.
1332 *val receives the number. */
1333
1334 static int
1335 immediate_for_directive (int *val)
1336 {
1337 expressionS exp;
1338 exp.X_op = O_illegal;
1339
1340 if (is_immediate_prefix (*input_line_pointer))
1341 {
1342 input_line_pointer++;
1343 expression (&exp);
1344 }
1345
1346 if (exp.X_op != O_constant)
1347 {
1348 as_bad (_("expected #constant"));
1349 ignore_rest_of_line ();
1350 return FAIL;
1351 }
1352 *val = exp.X_add_number;
1353 return SUCCESS;
1354 }
1355 #endif
1356
1357 /* Register parsing. */
1358
1359 /* Generic register parser. CCP points to what should be the
1360 beginning of a register name. If it is indeed a valid register
1361 name, advance CCP over it and return the reg_entry structure;
1362 otherwise return NULL. Does not issue diagnostics. */
1363
1364 static struct reg_entry *
1365 arm_reg_parse_multi (char **ccp)
1366 {
1367 char *start = *ccp;
1368 char *p;
1369 struct reg_entry *reg;
1370
1371 skip_whitespace (start);
1372
1373 #ifdef REGISTER_PREFIX
1374 if (*start != REGISTER_PREFIX)
1375 return NULL;
1376 start++;
1377 #endif
1378 #ifdef OPTIONAL_REGISTER_PREFIX
1379 if (*start == OPTIONAL_REGISTER_PREFIX)
1380 start++;
1381 #endif
1382
1383 p = start;
1384 if (!ISALPHA (*p) || !is_name_beginner (*p))
1385 return NULL;
1386
1387 do
1388 p++;
1389 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1390
1391 reg = (struct reg_entry *) str_hash_find_n (arm_reg_hsh, start, p - start);
1392
1393 if (!reg)
1394 return NULL;
1395
1396 *ccp = p;
1397 return reg;
1398 }
1399
1400 static int
1401 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1402 enum arm_reg_type type)
1403 {
1404 /* Alternative syntaxes are accepted for a few register classes. */
1405 switch (type)
1406 {
1407 case REG_TYPE_MVF:
1408 case REG_TYPE_MVD:
1409 case REG_TYPE_MVFX:
1410 case REG_TYPE_MVDX:
1411 /* Generic coprocessor register names are allowed for these. */
1412 if (reg && reg->type == REG_TYPE_CN)
1413 return reg->number;
1414 break;
1415
1416 case REG_TYPE_CP:
1417 /* For backward compatibility, a bare number is valid here. */
1418 {
1419 unsigned long processor = strtoul (start, ccp, 10);
1420 if (*ccp != start && processor <= 15)
1421 return processor;
1422 }
1423 /* Fall through. */
1424
1425 case REG_TYPE_MMXWC:
1426 /* WC includes WCG. ??? I'm not sure this is true for all
1427 instructions that take WC registers. */
1428 if (reg && reg->type == REG_TYPE_MMXWCG)
1429 return reg->number;
1430 break;
1431
1432 default:
1433 break;
1434 }
1435
1436 return FAIL;
1437 }
1438
1439 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1440 return value is the register number or FAIL. */
1441
1442 static int
1443 arm_reg_parse (char **ccp, enum arm_reg_type type)
1444 {
1445 char *start = *ccp;
1446 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1447 int ret;
1448
1449 /* Do not allow a scalar (reg+index) to parse as a register. */
1450 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1451 return FAIL;
1452
1453 if (reg && reg->type == type)
1454 return reg->number;
1455
1456 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1457 return ret;
1458
1459 *ccp = start;
1460 return FAIL;
1461 }
1462
1463 /* Parse a Neon type specifier. *STR should point at the leading '.'
1464 character. Does no verification at this stage that the type fits the opcode
1465 properly. E.g.,
1466
1467 .i32.i32.s16
1468 .s32.f32
1469 .u16
1470
1471 Can all be legally parsed by this function.
1472
1473 Fills in neon_type struct pointer with parsed information, and updates STR
1474 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1475 type, FAIL if not. */
1476
1477 static int
1478 parse_neon_type (struct neon_type *type, char **str)
1479 {
1480 char *ptr = *str;
1481
1482 if (type)
1483 type->elems = 0;
1484
1485 while (type->elems < NEON_MAX_TYPE_ELS)
1486 {
1487 enum neon_el_type thistype = NT_untyped;
1488 unsigned thissize = -1u;
1489
1490 if (*ptr != '.')
1491 break;
1492
1493 ptr++;
1494
1495 /* Just a size without an explicit type. */
1496 if (ISDIGIT (*ptr))
1497 goto parsesize;
1498
1499 switch (TOLOWER (*ptr))
1500 {
1501 case 'i': thistype = NT_integer; break;
1502 case 'f': thistype = NT_float; break;
1503 case 'p': thistype = NT_poly; break;
1504 case 's': thistype = NT_signed; break;
1505 case 'u': thistype = NT_unsigned; break;
1506 case 'd':
1507 thistype = NT_float;
1508 thissize = 64;
1509 ptr++;
1510 goto done;
1511 case 'b':
1512 thistype = NT_bfloat;
1513 switch (TOLOWER (*(++ptr)))
1514 {
1515 case 'f':
1516 ptr += 1;
1517 thissize = strtoul (ptr, &ptr, 10);
1518 if (thissize != 16)
1519 {
1520 as_bad (_("bad size %d in type specifier"), thissize);
1521 return FAIL;
1522 }
1523 goto done;
1524 case '0': case '1': case '2': case '3': case '4':
1525 case '5': case '6': case '7': case '8': case '9':
1526 case ' ': case '.':
1527 as_bad (_("unexpected type character `b' -- did you mean `bf'?"));
1528 return FAIL;
1529 default:
1530 break;
1531 }
1532 break;
1533 default:
1534 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1535 return FAIL;
1536 }
1537
1538 ptr++;
1539
1540 /* .f is an abbreviation for .f32. */
1541 if (thistype == NT_float && !ISDIGIT (*ptr))
1542 thissize = 32;
1543 else
1544 {
1545 parsesize:
1546 thissize = strtoul (ptr, &ptr, 10);
1547
1548 if (thissize != 8 && thissize != 16 && thissize != 32
1549 && thissize != 64)
1550 {
1551 as_bad (_("bad size %d in type specifier"), thissize);
1552 return FAIL;
1553 }
1554 }
1555
1556 done:
1557 if (type)
1558 {
1559 type->el[type->elems].type = thistype;
1560 type->el[type->elems].size = thissize;
1561 type->elems++;
1562 }
1563 }
1564
1565 /* Empty/missing type is not a successful parse. */
1566 if (type->elems == 0)
1567 return FAIL;
1568
1569 *str = ptr;
1570
1571 return SUCCESS;
1572 }
1573
1574 /* Errors may be set multiple times during parsing or bit encoding
1575 (particularly in the Neon bits), but usually the earliest error which is set
1576 will be the most meaningful. Avoid overwriting it with later (cascading)
1577 errors by calling this function. */
1578
1579 static void
1580 first_error (const char *err)
1581 {
1582 if (!inst.error)
1583 inst.error = err;
1584 }
1585
1586 /* Parse a single type, e.g. ".s32", leading period included. */
1587 static int
1588 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1589 {
1590 char *str = *ccp;
1591 struct neon_type optype;
1592
1593 if (*str == '.')
1594 {
1595 if (parse_neon_type (&optype, &str) == SUCCESS)
1596 {
1597 if (optype.elems == 1)
1598 *vectype = optype.el[0];
1599 else
1600 {
1601 first_error (_("only one type should be specified for operand"));
1602 return FAIL;
1603 }
1604 }
1605 else
1606 {
1607 first_error (_("vector type expected"));
1608 return FAIL;
1609 }
1610 }
1611 else
1612 return FAIL;
1613
1614 *ccp = str;
1615
1616 return SUCCESS;
1617 }
1618
1619 /* Special meanings for indices (which have a range of 0-7), which will fit into
1620 a 4-bit integer. */
1621
1622 #define NEON_ALL_LANES 15
1623 #define NEON_INTERLEAVE_LANES 14
1624
1625 /* Record a use of the given feature. */
1626 static void
1627 record_feature_use (const arm_feature_set *feature)
1628 {
1629 if (thumb_mode)
1630 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1631 else
1632 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1633 }
1634
1635 /* If the given feature available in the selected CPU, mark it as used.
1636 Returns TRUE iff feature is available. */
1637 static bool
1638 mark_feature_used (const arm_feature_set *feature)
1639 {
1640
1641 /* Do not support the use of MVE only instructions when in auto-detection or
1642 -march=all. */
1643 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1644 && ARM_CPU_IS_ANY (cpu_variant))
1645 {
1646 first_error (BAD_MVE_AUTO);
1647 return false;
1648 }
1649 /* Ensure the option is valid on the current architecture. */
1650 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1651 return false;
1652
1653 /* Add the appropriate architecture feature for the barrier option used.
1654 */
1655 record_feature_use (feature);
1656
1657 return true;
1658 }
1659
1660 /* Parse either a register or a scalar, with an optional type. Return the
1661 register number, and optionally fill in the actual type of the register
1662 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1663 type/index information in *TYPEINFO. */
1664
1665 static int
1666 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1667 enum arm_reg_type *rtype,
1668 struct neon_typed_alias *typeinfo)
1669 {
1670 char *str = *ccp;
1671 struct reg_entry *reg = arm_reg_parse_multi (&str);
1672 struct neon_typed_alias atype;
1673 struct neon_type_el parsetype;
1674
1675 atype.defined = 0;
1676 atype.index = -1;
1677 atype.eltype.type = NT_invtype;
1678 atype.eltype.size = -1;
1679
1680 /* Try alternate syntax for some types of register. Note these are mutually
1681 exclusive with the Neon syntax extensions. */
1682 if (reg == NULL)
1683 {
1684 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1685 if (altreg != FAIL)
1686 *ccp = str;
1687 if (typeinfo)
1688 *typeinfo = atype;
1689 return altreg;
1690 }
1691
1692 /* Undo polymorphism when a set of register types may be accepted. */
1693 if ((type == REG_TYPE_NDQ
1694 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1695 || (type == REG_TYPE_VFSD
1696 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1697 || (type == REG_TYPE_NSDQ
1698 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1699 || reg->type == REG_TYPE_NQ))
1700 || (type == REG_TYPE_NSD
1701 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1702 || (type == REG_TYPE_MMXWC
1703 && (reg->type == REG_TYPE_MMXWCG)))
1704 type = (enum arm_reg_type) reg->type;
1705
1706 if (type == REG_TYPE_MQ)
1707 {
1708 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1709 return FAIL;
1710
1711 if (!reg || reg->type != REG_TYPE_NQ)
1712 return FAIL;
1713
1714 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1715 {
1716 first_error (_("expected MVE register [q0..q7]"));
1717 return FAIL;
1718 }
1719 type = REG_TYPE_NQ;
1720 }
1721 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1722 && (type == REG_TYPE_NQ))
1723 return FAIL;
1724
1725
1726 if (type != reg->type)
1727 return FAIL;
1728
1729 if (reg->neon)
1730 atype = *reg->neon;
1731
1732 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1733 {
1734 if ((atype.defined & NTA_HASTYPE) != 0)
1735 {
1736 first_error (_("can't redefine type for operand"));
1737 return FAIL;
1738 }
1739 atype.defined |= NTA_HASTYPE;
1740 atype.eltype = parsetype;
1741 }
1742
1743 if (skip_past_char (&str, '[') == SUCCESS)
1744 {
1745 if (type != REG_TYPE_VFD
1746 && !(type == REG_TYPE_VFS
1747 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1748 && !(type == REG_TYPE_NQ
1749 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
1750 {
1751 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1752 first_error (_("only D and Q registers may be indexed"));
1753 else
1754 first_error (_("only D registers may be indexed"));
1755 return FAIL;
1756 }
1757
1758 if ((atype.defined & NTA_HASINDEX) != 0)
1759 {
1760 first_error (_("can't change index for operand"));
1761 return FAIL;
1762 }
1763
1764 atype.defined |= NTA_HASINDEX;
1765
1766 if (skip_past_char (&str, ']') == SUCCESS)
1767 atype.index = NEON_ALL_LANES;
1768 else
1769 {
1770 expressionS exp;
1771
1772 my_get_expression (&exp, &str, GE_NO_PREFIX);
1773
1774 if (exp.X_op != O_constant)
1775 {
1776 first_error (_("constant expression required"));
1777 return FAIL;
1778 }
1779
1780 if (skip_past_char (&str, ']') == FAIL)
1781 return FAIL;
1782
1783 atype.index = exp.X_add_number;
1784 }
1785 }
1786
1787 if (typeinfo)
1788 *typeinfo = atype;
1789
1790 if (rtype)
1791 *rtype = type;
1792
1793 *ccp = str;
1794
1795 return reg->number;
1796 }
1797
1798 /* Like arm_reg_parse, but also allow the following extra features:
1799 - If RTYPE is non-zero, return the (possibly restricted) type of the
1800 register (e.g. Neon double or quad reg when either has been requested).
1801 - If this is a Neon vector type with additional type information, fill
1802 in the struct pointed to by VECTYPE (if non-NULL).
1803 This function will fault on encountering a scalar. */
1804
1805 static int
1806 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1807 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1808 {
1809 struct neon_typed_alias atype;
1810 char *str = *ccp;
1811 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1812
1813 if (reg == FAIL)
1814 return FAIL;
1815
1816 /* Do not allow regname(... to parse as a register. */
1817 if (*str == '(')
1818 return FAIL;
1819
1820 /* Do not allow a scalar (reg+index) to parse as a register. */
1821 if ((atype.defined & NTA_HASINDEX) != 0)
1822 {
1823 first_error (_("register operand expected, but got scalar"));
1824 return FAIL;
1825 }
1826
1827 if (vectype)
1828 *vectype = atype.eltype;
1829
1830 *ccp = str;
1831
1832 return reg;
1833 }
1834
1835 #define NEON_SCALAR_REG(X) ((X) >> 4)
1836 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1837
1838 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1839 have enough information to be able to do a good job bounds-checking. So, we
1840 just do easy checks here, and do further checks later. */
1841
1842 static int
1843 parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1844 arm_reg_type reg_type)
1845 {
1846 int reg;
1847 char *str = *ccp;
1848 struct neon_typed_alias atype;
1849 unsigned reg_size;
1850
1851 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1852
1853 switch (reg_type)
1854 {
1855 case REG_TYPE_VFS:
1856 reg_size = 32;
1857 break;
1858 case REG_TYPE_VFD:
1859 reg_size = 64;
1860 break;
1861 case REG_TYPE_MQ:
1862 reg_size = 128;
1863 break;
1864 default:
1865 gas_assert (0);
1866 return FAIL;
1867 }
1868
1869 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1870 return FAIL;
1871
1872 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
1873 {
1874 first_error (_("scalar must have an index"));
1875 return FAIL;
1876 }
1877 else if (atype.index >= reg_size / elsize)
1878 {
1879 first_error (_("scalar index out of range"));
1880 return FAIL;
1881 }
1882
1883 if (type)
1884 *type = atype.eltype;
1885
1886 *ccp = str;
1887
1888 return reg * 16 + atype.index;
1889 }
1890
1891 /* Types of registers in a list. */
1892
1893 enum reg_list_els
1894 {
1895 REGLIST_RN,
1896 REGLIST_CLRM,
1897 REGLIST_VFP_S,
1898 REGLIST_VFP_S_VPR,
1899 REGLIST_VFP_D,
1900 REGLIST_VFP_D_VPR,
1901 REGLIST_NEON_D
1902 };
1903
1904 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1905
1906 static long
1907 parse_reg_list (char ** strp, enum reg_list_els etype)
1908 {
1909 char *str = *strp;
1910 long range = 0;
1911 int another_range;
1912
1913 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
1914
1915 /* We come back here if we get ranges concatenated by '+' or '|'. */
1916 do
1917 {
1918 skip_whitespace (str);
1919
1920 another_range = 0;
1921
1922 if (*str == '{')
1923 {
1924 int in_range = 0;
1925 int cur_reg = -1;
1926
1927 str++;
1928 do
1929 {
1930 int reg;
1931 const char apsr_str[] = "apsr";
1932 int apsr_str_len = strlen (apsr_str);
1933
1934 reg = arm_reg_parse (&str, REG_TYPE_RN);
1935 if (etype == REGLIST_CLRM)
1936 {
1937 if (reg == REG_SP || reg == REG_PC)
1938 reg = FAIL;
1939 else if (reg == FAIL
1940 && !strncasecmp (str, apsr_str, apsr_str_len)
1941 && !ISALPHA (*(str + apsr_str_len)))
1942 {
1943 reg = 15;
1944 str += apsr_str_len;
1945 }
1946
1947 if (reg == FAIL)
1948 {
1949 first_error (_("r0-r12, lr or APSR expected"));
1950 return FAIL;
1951 }
1952 }
1953 else /* etype == REGLIST_RN. */
1954 {
1955 if (reg == FAIL)
1956 {
1957 first_error (_(reg_expected_msgs[REGLIST_RN]));
1958 return FAIL;
1959 }
1960 }
1961
1962 if (in_range)
1963 {
1964 int i;
1965
1966 if (reg <= cur_reg)
1967 {
1968 first_error (_("bad range in register list"));
1969 return FAIL;
1970 }
1971
1972 for (i = cur_reg + 1; i < reg; i++)
1973 {
1974 if (range & (1 << i))
1975 as_tsktsk
1976 (_("Warning: duplicated register (r%d) in register list"),
1977 i);
1978 else
1979 range |= 1 << i;
1980 }
1981 in_range = 0;
1982 }
1983
1984 if (range & (1 << reg))
1985 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1986 reg);
1987 else if (reg <= cur_reg)
1988 as_tsktsk (_("Warning: register range not in ascending order"));
1989
1990 range |= 1 << reg;
1991 cur_reg = reg;
1992 }
1993 while (skip_past_comma (&str) != FAIL
1994 || (in_range = 1, *str++ == '-'));
1995 str--;
1996
1997 if (skip_past_char (&str, '}') == FAIL)
1998 {
1999 first_error (_("missing `}'"));
2000 return FAIL;
2001 }
2002 }
2003 else if (etype == REGLIST_RN)
2004 {
2005 expressionS exp;
2006
2007 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
2008 return FAIL;
2009
2010 if (exp.X_op == O_constant)
2011 {
2012 if (exp.X_add_number
2013 != (exp.X_add_number & 0x0000ffff))
2014 {
2015 inst.error = _("invalid register mask");
2016 return FAIL;
2017 }
2018
2019 if ((range & exp.X_add_number) != 0)
2020 {
2021 int regno = range & exp.X_add_number;
2022
2023 regno &= -regno;
2024 regno = (1 << regno) - 1;
2025 as_tsktsk
2026 (_("Warning: duplicated register (r%d) in register list"),
2027 regno);
2028 }
2029
2030 range |= exp.X_add_number;
2031 }
2032 else
2033 {
2034 if (inst.relocs[0].type != 0)
2035 {
2036 inst.error = _("expression too complex");
2037 return FAIL;
2038 }
2039
2040 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
2041 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
2042 inst.relocs[0].pc_rel = 0;
2043 }
2044 }
2045
2046 if (*str == '|' || *str == '+')
2047 {
2048 str++;
2049 another_range = 1;
2050 }
2051 }
2052 while (another_range);
2053
2054 *strp = str;
2055 return range;
2056 }
2057
2058 /* Parse a VFP register list. If the string is invalid return FAIL.
2059 Otherwise return the number of registers, and set PBASE to the first
2060 register. Parses registers of type ETYPE.
2061 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
2062 - Q registers can be used to specify pairs of D registers
2063 - { } can be omitted from around a singleton register list
2064 FIXME: This is not implemented, as it would require backtracking in
2065 some cases, e.g.:
2066 vtbl.8 d3,d4,d5
2067 This could be done (the meaning isn't really ambiguous), but doesn't
2068 fit in well with the current parsing framework.
2069 - 32 D registers may be used (also true for VFPv3).
2070 FIXME: Types are ignored in these register lists, which is probably a
2071 bug. */
2072
2073 static int
2074 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2075 bool *partial_match)
2076 {
2077 char *str = *ccp;
2078 int base_reg;
2079 int new_base;
2080 enum arm_reg_type regtype = (enum arm_reg_type) 0;
2081 int max_regs = 0;
2082 int count = 0;
2083 int warned = 0;
2084 unsigned long mask = 0;
2085 int i;
2086 bool vpr_seen = false;
2087 bool expect_vpr =
2088 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
2089
2090 if (skip_past_char (&str, '{') == FAIL)
2091 {
2092 inst.error = _("expecting {");
2093 return FAIL;
2094 }
2095
2096 switch (etype)
2097 {
2098 case REGLIST_VFP_S:
2099 case REGLIST_VFP_S_VPR:
2100 regtype = REG_TYPE_VFS;
2101 max_regs = 32;
2102 break;
2103
2104 case REGLIST_VFP_D:
2105 case REGLIST_VFP_D_VPR:
2106 regtype = REG_TYPE_VFD;
2107 break;
2108
2109 case REGLIST_NEON_D:
2110 regtype = REG_TYPE_NDQ;
2111 break;
2112
2113 default:
2114 gas_assert (0);
2115 }
2116
2117 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
2118 {
2119 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2120 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
2121 {
2122 max_regs = 32;
2123 if (thumb_mode)
2124 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2125 fpu_vfp_ext_d32);
2126 else
2127 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2128 fpu_vfp_ext_d32);
2129 }
2130 else
2131 max_regs = 16;
2132 }
2133
2134 base_reg = max_regs;
2135 *partial_match = false;
2136
2137 do
2138 {
2139 unsigned int setmask = 1, addregs = 1;
2140 const char vpr_str[] = "vpr";
2141 size_t vpr_str_len = strlen (vpr_str);
2142
2143 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
2144
2145 if (expect_vpr)
2146 {
2147 if (new_base == FAIL
2148 && !strncasecmp (str, vpr_str, vpr_str_len)
2149 && !ISALPHA (*(str + vpr_str_len))
2150 && !vpr_seen)
2151 {
2152 vpr_seen = true;
2153 str += vpr_str_len;
2154 if (count == 0)
2155 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2156 }
2157 else if (vpr_seen)
2158 {
2159 first_error (_("VPR expected last"));
2160 return FAIL;
2161 }
2162 else if (new_base == FAIL)
2163 {
2164 if (regtype == REG_TYPE_VFS)
2165 first_error (_("VFP single precision register or VPR "
2166 "expected"));
2167 else /* regtype == REG_TYPE_VFD. */
2168 first_error (_("VFP/Neon double precision register or VPR "
2169 "expected"));
2170 return FAIL;
2171 }
2172 }
2173 else if (new_base == FAIL)
2174 {
2175 first_error (_(reg_expected_msgs[regtype]));
2176 return FAIL;
2177 }
2178
2179 *partial_match = true;
2180 if (vpr_seen)
2181 continue;
2182
2183 if (new_base >= max_regs)
2184 {
2185 first_error (_("register out of range in list"));
2186 return FAIL;
2187 }
2188
2189 /* Note: a value of 2 * n is returned for the register Q<n>. */
2190 if (regtype == REG_TYPE_NQ)
2191 {
2192 setmask = 3;
2193 addregs = 2;
2194 }
2195
2196 if (new_base < base_reg)
2197 base_reg = new_base;
2198
2199 if (mask & (setmask << new_base))
2200 {
2201 first_error (_("invalid register list"));
2202 return FAIL;
2203 }
2204
2205 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
2206 {
2207 as_tsktsk (_("register list not in ascending order"));
2208 warned = 1;
2209 }
2210
2211 mask |= setmask << new_base;
2212 count += addregs;
2213
2214 if (*str == '-') /* We have the start of a range expression */
2215 {
2216 int high_range;
2217
2218 str++;
2219
2220 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
2221 == FAIL)
2222 {
2223 inst.error = gettext (reg_expected_msgs[regtype]);
2224 return FAIL;
2225 }
2226
2227 if (high_range >= max_regs)
2228 {
2229 first_error (_("register out of range in list"));
2230 return FAIL;
2231 }
2232
2233 if (regtype == REG_TYPE_NQ)
2234 high_range = high_range + 1;
2235
2236 if (high_range <= new_base)
2237 {
2238 inst.error = _("register range not in ascending order");
2239 return FAIL;
2240 }
2241
2242 for (new_base += addregs; new_base <= high_range; new_base += addregs)
2243 {
2244 if (mask & (setmask << new_base))
2245 {
2246 inst.error = _("invalid register list");
2247 return FAIL;
2248 }
2249
2250 mask |= setmask << new_base;
2251 count += addregs;
2252 }
2253 }
2254 }
2255 while (skip_past_comma (&str) != FAIL);
2256
2257 str++;
2258
2259 /* Sanity check -- should have raised a parse error above. */
2260 if ((!vpr_seen && count == 0) || count > max_regs)
2261 abort ();
2262
2263 *pbase = base_reg;
2264
2265 if (expect_vpr && !vpr_seen)
2266 {
2267 first_error (_("VPR expected last"));
2268 return FAIL;
2269 }
2270
2271 /* Final test -- the registers must be consecutive. */
2272 mask >>= base_reg;
2273 for (i = 0; i < count; i++)
2274 {
2275 if ((mask & (1u << i)) == 0)
2276 {
2277 inst.error = _("non-contiguous register range");
2278 return FAIL;
2279 }
2280 }
2281
2282 *ccp = str;
2283
2284 return count;
2285 }
2286
2287 /* True if two alias types are the same. */
2288
2289 static bool
2290 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2291 {
2292 if (!a && !b)
2293 return true;
2294
2295 if (!a || !b)
2296 return false;
2297
2298 if (a->defined != b->defined)
2299 return false;
2300
2301 if ((a->defined & NTA_HASTYPE) != 0
2302 && (a->eltype.type != b->eltype.type
2303 || a->eltype.size != b->eltype.size))
2304 return false;
2305
2306 if ((a->defined & NTA_HASINDEX) != 0
2307 && (a->index != b->index))
2308 return false;
2309
2310 return true;
2311 }
2312
2313 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2314 The base register is put in *PBASE.
2315 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2316 the return value.
2317 The register stride (minus one) is put in bit 4 of the return value.
2318 Bits [6:5] encode the list length (minus one).
2319 The type of the list elements is put in *ELTYPE, if non-NULL. */
2320
2321 #define NEON_LANE(X) ((X) & 0xf)
2322 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2323 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2324
2325 static int
2326 parse_neon_el_struct_list (char **str, unsigned *pbase,
2327 int mve,
2328 struct neon_type_el *eltype)
2329 {
2330 char *ptr = *str;
2331 int base_reg = -1;
2332 int reg_incr = -1;
2333 int count = 0;
2334 int lane = -1;
2335 int leading_brace = 0;
2336 enum arm_reg_type rtype = REG_TYPE_NDQ;
2337 const char *const incr_error = mve ? _("register stride must be 1") :
2338 _("register stride must be 1 or 2");
2339 const char *const type_error = _("mismatched element/structure types in list");
2340 struct neon_typed_alias firsttype;
2341 firsttype.defined = 0;
2342 firsttype.eltype.type = NT_invtype;
2343 firsttype.eltype.size = -1;
2344 firsttype.index = -1;
2345
2346 if (skip_past_char (&ptr, '{') == SUCCESS)
2347 leading_brace = 1;
2348
2349 do
2350 {
2351 struct neon_typed_alias atype;
2352 if (mve)
2353 rtype = REG_TYPE_MQ;
2354 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2355
2356 if (getreg == FAIL)
2357 {
2358 first_error (_(reg_expected_msgs[rtype]));
2359 return FAIL;
2360 }
2361
2362 if (base_reg == -1)
2363 {
2364 base_reg = getreg;
2365 if (rtype == REG_TYPE_NQ)
2366 {
2367 reg_incr = 1;
2368 }
2369 firsttype = atype;
2370 }
2371 else if (reg_incr == -1)
2372 {
2373 reg_incr = getreg - base_reg;
2374 if (reg_incr < 1 || reg_incr > 2)
2375 {
2376 first_error (_(incr_error));
2377 return FAIL;
2378 }
2379 }
2380 else if (getreg != base_reg + reg_incr * count)
2381 {
2382 first_error (_(incr_error));
2383 return FAIL;
2384 }
2385
2386 if (! neon_alias_types_same (&atype, &firsttype))
2387 {
2388 first_error (_(type_error));
2389 return FAIL;
2390 }
2391
2392 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2393 modes. */
2394 if (ptr[0] == '-')
2395 {
2396 struct neon_typed_alias htype;
2397 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2398 if (lane == -1)
2399 lane = NEON_INTERLEAVE_LANES;
2400 else if (lane != NEON_INTERLEAVE_LANES)
2401 {
2402 first_error (_(type_error));
2403 return FAIL;
2404 }
2405 if (reg_incr == -1)
2406 reg_incr = 1;
2407 else if (reg_incr != 1)
2408 {
2409 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2410 return FAIL;
2411 }
2412 ptr++;
2413 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2414 if (hireg == FAIL)
2415 {
2416 first_error (_(reg_expected_msgs[rtype]));
2417 return FAIL;
2418 }
2419 if (! neon_alias_types_same (&htype, &firsttype))
2420 {
2421 first_error (_(type_error));
2422 return FAIL;
2423 }
2424 count += hireg + dregs - getreg;
2425 continue;
2426 }
2427
2428 /* If we're using Q registers, we can't use [] or [n] syntax. */
2429 if (rtype == REG_TYPE_NQ)
2430 {
2431 count += 2;
2432 continue;
2433 }
2434
2435 if ((atype.defined & NTA_HASINDEX) != 0)
2436 {
2437 if (lane == -1)
2438 lane = atype.index;
2439 else if (lane != atype.index)
2440 {
2441 first_error (_(type_error));
2442 return FAIL;
2443 }
2444 }
2445 else if (lane == -1)
2446 lane = NEON_INTERLEAVE_LANES;
2447 else if (lane != NEON_INTERLEAVE_LANES)
2448 {
2449 first_error (_(type_error));
2450 return FAIL;
2451 }
2452 count++;
2453 }
2454 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2455
2456 /* No lane set by [x]. We must be interleaving structures. */
2457 if (lane == -1)
2458 lane = NEON_INTERLEAVE_LANES;
2459
2460 /* Sanity check. */
2461 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
2462 || (count > 1 && reg_incr == -1))
2463 {
2464 first_error (_("error parsing element/structure list"));
2465 return FAIL;
2466 }
2467
2468 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2469 {
2470 first_error (_("expected }"));
2471 return FAIL;
2472 }
2473
2474 if (reg_incr == -1)
2475 reg_incr = 1;
2476
2477 if (eltype)
2478 *eltype = firsttype.eltype;
2479
2480 *pbase = base_reg;
2481 *str = ptr;
2482
2483 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2484 }
2485
2486 /* Parse an explicit relocation suffix on an expression. This is
2487 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2488 arm_reloc_hsh contains no entries, so this function can only
2489 succeed if there is no () after the word. Returns -1 on error,
2490 BFD_RELOC_UNUSED if there wasn't any suffix. */
2491
2492 static int
2493 parse_reloc (char **str)
2494 {
2495 struct reloc_entry *r;
2496 char *p, *q;
2497
2498 if (**str != '(')
2499 return BFD_RELOC_UNUSED;
2500
2501 p = *str + 1;
2502 q = p;
2503
2504 while (*q && *q != ')' && *q != ',')
2505 q++;
2506 if (*q != ')')
2507 return -1;
2508
2509 if ((r = (struct reloc_entry *)
2510 str_hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2511 return -1;
2512
2513 *str = q + 1;
2514 return r->reloc;
2515 }
2516
2517 /* Directives: register aliases. */
2518
2519 static struct reg_entry *
2520 insert_reg_alias (char *str, unsigned number, int type)
2521 {
2522 struct reg_entry *new_reg;
2523 const char *name;
2524
2525 if ((new_reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, str)) != 0)
2526 {
2527 if (new_reg->builtin)
2528 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2529
2530 /* Only warn about a redefinition if it's not defined as the
2531 same register. */
2532 else if (new_reg->number != number || new_reg->type != type)
2533 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2534
2535 return NULL;
2536 }
2537
2538 name = xstrdup (str);
2539 new_reg = XNEW (struct reg_entry);
2540
2541 new_reg->name = name;
2542 new_reg->number = number;
2543 new_reg->type = type;
2544 new_reg->builtin = false;
2545 new_reg->neon = NULL;
2546
2547 str_hash_insert (arm_reg_hsh, name, new_reg, 0);
2548
2549 return new_reg;
2550 }
2551
2552 static void
2553 insert_neon_reg_alias (char *str, int number, int type,
2554 struct neon_typed_alias *atype)
2555 {
2556 struct reg_entry *reg = insert_reg_alias (str, number, type);
2557
2558 if (!reg)
2559 {
2560 first_error (_("attempt to redefine typed alias"));
2561 return;
2562 }
2563
2564 if (atype)
2565 {
2566 reg->neon = XNEW (struct neon_typed_alias);
2567 *reg->neon = *atype;
2568 }
2569 }
2570
2571 /* Look for the .req directive. This is of the form:
2572
2573 new_register_name .req existing_register_name
2574
2575 If we find one, or if it looks sufficiently like one that we want to
2576 handle any error here, return TRUE. Otherwise return FALSE. */
2577
2578 static bool
2579 create_register_alias (char * newname, char *p)
2580 {
2581 struct reg_entry *old;
2582 char *oldname, *nbuf;
2583 size_t nlen;
2584
2585 /* The input scrubber ensures that whitespace after the mnemonic is
2586 collapsed to single spaces. */
2587 oldname = p;
2588 if (!startswith (oldname, " .req "))
2589 return false;
2590
2591 oldname += 6;
2592 if (*oldname == '\0')
2593 return false;
2594
2595 old = (struct reg_entry *) str_hash_find (arm_reg_hsh, oldname);
2596 if (!old)
2597 {
2598 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2599 return true;
2600 }
2601
2602 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2603 the desired alias name, and p points to its end. If not, then
2604 the desired alias name is in the global original_case_string. */
2605 #ifdef TC_CASE_SENSITIVE
2606 nlen = p - newname;
2607 #else
2608 newname = original_case_string;
2609 nlen = strlen (newname);
2610 #endif
2611
2612 nbuf = xmemdup0 (newname, nlen);
2613
2614 /* Create aliases under the new name as stated; an all-lowercase
2615 version of the new name; and an all-uppercase version of the new
2616 name. */
2617 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2618 {
2619 for (p = nbuf; *p; p++)
2620 *p = TOUPPER (*p);
2621
2622 if (strncmp (nbuf, newname, nlen))
2623 {
2624 /* If this attempt to create an additional alias fails, do not bother
2625 trying to create the all-lower case alias. We will fail and issue
2626 a second, duplicate error message. This situation arises when the
2627 programmer does something like:
2628 foo .req r0
2629 Foo .req r1
2630 The second .req creates the "Foo" alias but then fails to create
2631 the artificial FOO alias because it has already been created by the
2632 first .req. */
2633 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2634 {
2635 free (nbuf);
2636 return true;
2637 }
2638 }
2639
2640 for (p = nbuf; *p; p++)
2641 *p = TOLOWER (*p);
2642
2643 if (strncmp (nbuf, newname, nlen))
2644 insert_reg_alias (nbuf, old->number, old->type);
2645 }
2646
2647 free (nbuf);
2648 return true;
2649 }
2650
2651 /* Create a Neon typed/indexed register alias using directives, e.g.:
2652 X .dn d5.s32[1]
2653 Y .qn 6.s16
2654 Z .dn d7
2655 T .dn Z[0]
2656 These typed registers can be used instead of the types specified after the
2657 Neon mnemonic, so long as all operands given have types. Types can also be
2658 specified directly, e.g.:
2659 vadd d0.s32, d1.s32, d2.s32 */
2660
2661 static bool
2662 create_neon_reg_alias (char *newname, char *p)
2663 {
2664 enum arm_reg_type basetype;
2665 struct reg_entry *basereg;
2666 struct reg_entry mybasereg;
2667 struct neon_type ntype;
2668 struct neon_typed_alias typeinfo;
2669 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2670 int namelen;
2671
2672 typeinfo.defined = 0;
2673 typeinfo.eltype.type = NT_invtype;
2674 typeinfo.eltype.size = -1;
2675 typeinfo.index = -1;
2676
2677 nameend = p;
2678
2679 if (startswith (p, " .dn "))
2680 basetype = REG_TYPE_VFD;
2681 else if (startswith (p, " .qn "))
2682 basetype = REG_TYPE_NQ;
2683 else
2684 return false;
2685
2686 p += 5;
2687
2688 if (*p == '\0')
2689 return false;
2690
2691 basereg = arm_reg_parse_multi (&p);
2692
2693 if (basereg && basereg->type != basetype)
2694 {
2695 as_bad (_("bad type for register"));
2696 return false;
2697 }
2698
2699 if (basereg == NULL)
2700 {
2701 expressionS exp;
2702 /* Try parsing as an integer. */
2703 my_get_expression (&exp, &p, GE_NO_PREFIX);
2704 if (exp.X_op != O_constant)
2705 {
2706 as_bad (_("expression must be constant"));
2707 return false;
2708 }
2709 basereg = &mybasereg;
2710 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2711 : exp.X_add_number;
2712 basereg->neon = 0;
2713 }
2714
2715 if (basereg->neon)
2716 typeinfo = *basereg->neon;
2717
2718 if (parse_neon_type (&ntype, &p) == SUCCESS)
2719 {
2720 /* We got a type. */
2721 if (typeinfo.defined & NTA_HASTYPE)
2722 {
2723 as_bad (_("can't redefine the type of a register alias"));
2724 return false;
2725 }
2726
2727 typeinfo.defined |= NTA_HASTYPE;
2728 if (ntype.elems != 1)
2729 {
2730 as_bad (_("you must specify a single type only"));
2731 return false;
2732 }
2733 typeinfo.eltype = ntype.el[0];
2734 }
2735
2736 if (skip_past_char (&p, '[') == SUCCESS)
2737 {
2738 expressionS exp;
2739 /* We got a scalar index. */
2740
2741 if (typeinfo.defined & NTA_HASINDEX)
2742 {
2743 as_bad (_("can't redefine the index of a scalar alias"));
2744 return false;
2745 }
2746
2747 my_get_expression (&exp, &p, GE_NO_PREFIX);
2748
2749 if (exp.X_op != O_constant)
2750 {
2751 as_bad (_("scalar index must be constant"));
2752 return false;
2753 }
2754
2755 typeinfo.defined |= NTA_HASINDEX;
2756 typeinfo.index = exp.X_add_number;
2757
2758 if (skip_past_char (&p, ']') == FAIL)
2759 {
2760 as_bad (_("expecting ]"));
2761 return false;
2762 }
2763 }
2764
2765 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2766 the desired alias name, and p points to its end. If not, then
2767 the desired alias name is in the global original_case_string. */
2768 #ifdef TC_CASE_SENSITIVE
2769 namelen = nameend - newname;
2770 #else
2771 newname = original_case_string;
2772 namelen = strlen (newname);
2773 #endif
2774
2775 namebuf = xmemdup0 (newname, namelen);
2776
2777 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2778 typeinfo.defined != 0 ? &typeinfo : NULL);
2779
2780 /* Insert name in all uppercase. */
2781 for (p = namebuf; *p; p++)
2782 *p = TOUPPER (*p);
2783
2784 if (strncmp (namebuf, newname, namelen))
2785 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2786 typeinfo.defined != 0 ? &typeinfo : NULL);
2787
2788 /* Insert name in all lowercase. */
2789 for (p = namebuf; *p; p++)
2790 *p = TOLOWER (*p);
2791
2792 if (strncmp (namebuf, newname, namelen))
2793 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2794 typeinfo.defined != 0 ? &typeinfo : NULL);
2795
2796 free (namebuf);
2797 return true;
2798 }
2799
2800 /* Should never be called, as .req goes between the alias and the
2801 register name, not at the beginning of the line. */
2802
2803 static void
2804 s_req (int a ATTRIBUTE_UNUSED)
2805 {
2806 as_bad (_("invalid syntax for .req directive"));
2807 }
2808
2809 static void
2810 s_dn (int a ATTRIBUTE_UNUSED)
2811 {
2812 as_bad (_("invalid syntax for .dn directive"));
2813 }
2814
2815 static void
2816 s_qn (int a ATTRIBUTE_UNUSED)
2817 {
2818 as_bad (_("invalid syntax for .qn directive"));
2819 }
2820
2821 /* The .unreq directive deletes an alias which was previously defined
2822 by .req. For example:
2823
2824 my_alias .req r11
2825 .unreq my_alias */
2826
2827 static void
2828 s_unreq (int a ATTRIBUTE_UNUSED)
2829 {
2830 char * name;
2831 char saved_char;
2832
2833 name = input_line_pointer;
2834
2835 while (*input_line_pointer != 0
2836 && *input_line_pointer != ' '
2837 && *input_line_pointer != '\n')
2838 ++input_line_pointer;
2839
2840 saved_char = *input_line_pointer;
2841 *input_line_pointer = 0;
2842
2843 if (!*name)
2844 as_bad (_("invalid syntax for .unreq directive"));
2845 else
2846 {
2847 struct reg_entry *reg
2848 = (struct reg_entry *) str_hash_find (arm_reg_hsh, name);
2849
2850 if (!reg)
2851 as_bad (_("unknown register alias '%s'"), name);
2852 else if (reg->builtin)
2853 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2854 name);
2855 else
2856 {
2857 char * p;
2858 char * nbuf;
2859
2860 str_hash_delete (arm_reg_hsh, name);
2861 free ((char *) reg->name);
2862 free (reg->neon);
2863 free (reg);
2864
2865 /* Also locate the all upper case and all lower case versions.
2866 Do not complain if we cannot find one or the other as it
2867 was probably deleted above. */
2868
2869 nbuf = strdup (name);
2870 for (p = nbuf; *p; p++)
2871 *p = TOUPPER (*p);
2872 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
2873 if (reg)
2874 {
2875 str_hash_delete (arm_reg_hsh, nbuf);
2876 free ((char *) reg->name);
2877 free (reg->neon);
2878 free (reg);
2879 }
2880
2881 for (p = nbuf; *p; p++)
2882 *p = TOLOWER (*p);
2883 reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf);
2884 if (reg)
2885 {
2886 str_hash_delete (arm_reg_hsh, nbuf);
2887 free ((char *) reg->name);
2888 free (reg->neon);
2889 free (reg);
2890 }
2891
2892 free (nbuf);
2893 }
2894 }
2895
2896 *input_line_pointer = saved_char;
2897 demand_empty_rest_of_line ();
2898 }
2899
2900 /* Directives: Instruction set selection. */
2901
2902 #ifdef OBJ_ELF
2903 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2904 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2905 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2906 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2907
2908 /* Create a new mapping symbol for the transition to STATE. */
2909
2910 static void
2911 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2912 {
2913 symbolS * symbolP;
2914 const char * symname;
2915 int type;
2916
2917 switch (state)
2918 {
2919 case MAP_DATA:
2920 symname = "$d";
2921 type = BSF_NO_FLAGS;
2922 break;
2923 case MAP_ARM:
2924 symname = "$a";
2925 type = BSF_NO_FLAGS;
2926 break;
2927 case MAP_THUMB:
2928 symname = "$t";
2929 type = BSF_NO_FLAGS;
2930 break;
2931 default:
2932 abort ();
2933 }
2934
2935 symbolP = symbol_new (symname, now_seg, frag, value);
2936 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2937
2938 switch (state)
2939 {
2940 case MAP_ARM:
2941 THUMB_SET_FUNC (symbolP, 0);
2942 ARM_SET_THUMB (symbolP, 0);
2943 ARM_SET_INTERWORK (symbolP, support_interwork);
2944 break;
2945
2946 case MAP_THUMB:
2947 THUMB_SET_FUNC (symbolP, 1);
2948 ARM_SET_THUMB (symbolP, 1);
2949 ARM_SET_INTERWORK (symbolP, support_interwork);
2950 break;
2951
2952 case MAP_DATA:
2953 default:
2954 break;
2955 }
2956
2957 /* Save the mapping symbols for future reference. Also check that
2958 we do not place two mapping symbols at the same offset within a
2959 frag. We'll handle overlap between frags in
2960 check_mapping_symbols.
2961
2962 If .fill or other data filling directive generates zero sized data,
2963 the mapping symbol for the following code will have the same value
2964 as the one generated for the data filling directive. In this case,
2965 we replace the old symbol with the new one at the same address. */
2966 if (value == 0)
2967 {
2968 if (frag->tc_frag_data.first_map != NULL)
2969 {
2970 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2971 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2972 }
2973 frag->tc_frag_data.first_map = symbolP;
2974 }
2975 if (frag->tc_frag_data.last_map != NULL)
2976 {
2977 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2978 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2979 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2980 }
2981 frag->tc_frag_data.last_map = symbolP;
2982 }
2983
2984 /* We must sometimes convert a region marked as code to data during
2985 code alignment, if an odd number of bytes have to be padded. The
2986 code mapping symbol is pushed to an aligned address. */
2987
2988 static void
2989 insert_data_mapping_symbol (enum mstate state,
2990 valueT value, fragS *frag, offsetT bytes)
2991 {
2992 /* If there was already a mapping symbol, remove it. */
2993 if (frag->tc_frag_data.last_map != NULL
2994 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2995 {
2996 symbolS *symp = frag->tc_frag_data.last_map;
2997
2998 if (value == 0)
2999 {
3000 know (frag->tc_frag_data.first_map == symp);
3001 frag->tc_frag_data.first_map = NULL;
3002 }
3003 frag->tc_frag_data.last_map = NULL;
3004 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
3005 }
3006
3007 make_mapping_symbol (MAP_DATA, value, frag);
3008 make_mapping_symbol (state, value + bytes, frag);
3009 }
3010
3011 static void mapping_state_2 (enum mstate state, int max_chars);
3012
3013 /* Set the mapping state to STATE. Only call this when about to
3014 emit some STATE bytes to the file. */
3015
3016 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
3017 void
3018 mapping_state (enum mstate state)
3019 {
3020 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3021
3022 if (mapstate == state)
3023 /* The mapping symbol has already been emitted.
3024 There is nothing else to do. */
3025 return;
3026
3027 if (state == MAP_ARM || state == MAP_THUMB)
3028 /* PR gas/12931
3029 All ARM instructions require 4-byte alignment.
3030 (Almost) all Thumb instructions require 2-byte alignment.
3031
3032 When emitting instructions into any section, mark the section
3033 appropriately.
3034
3035 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
3036 but themselves require 2-byte alignment; this applies to some
3037 PC- relative forms. However, these cases will involve implicit
3038 literal pool generation or an explicit .align >=2, both of
3039 which will cause the section to me marked with sufficient
3040 alignment. Thus, we don't handle those cases here. */
3041 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
3042
3043 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
3044 /* This case will be evaluated later. */
3045 return;
3046
3047 mapping_state_2 (state, 0);
3048 }
3049
3050 /* Same as mapping_state, but MAX_CHARS bytes have already been
3051 allocated. Put the mapping symbol that far back. */
3052
3053 static void
3054 mapping_state_2 (enum mstate state, int max_chars)
3055 {
3056 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
3057
3058 if (!SEG_NORMAL (now_seg))
3059 return;
3060
3061 if (mapstate == state)
3062 /* The mapping symbol has already been emitted.
3063 There is nothing else to do. */
3064 return;
3065
3066 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
3067 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3068 {
3069 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3070 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3071
3072 if (add_symbol)
3073 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3074 }
3075
3076 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3077 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
3078 }
3079 #undef TRANSITION
3080 #else
3081 #define mapping_state(x) ((void)0)
3082 #define mapping_state_2(x, y) ((void)0)
3083 #endif
3084
3085 /* Find the real, Thumb encoded start of a Thumb function. */
3086
3087 #ifdef OBJ_COFF
3088 static symbolS *
3089 find_real_start (symbolS * symbolP)
3090 {
3091 char * real_start;
3092 const char * name = S_GET_NAME (symbolP);
3093 symbolS * new_target;
3094
3095 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3096 #define STUB_NAME ".real_start_of"
3097
3098 if (name == NULL)
3099 abort ();
3100
3101 /* The compiler may generate BL instructions to local labels because
3102 it needs to perform a branch to a far away location. These labels
3103 do not have a corresponding ".real_start_of" label. We check
3104 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3105 the ".real_start_of" convention for nonlocal branches. */
3106 if (S_IS_LOCAL (symbolP) || name[0] == '.')
3107 return symbolP;
3108
3109 real_start = concat (STUB_NAME, name, NULL);
3110 new_target = symbol_find (real_start);
3111 free (real_start);
3112
3113 if (new_target == NULL)
3114 {
3115 as_warn (_("Failed to find real start of function: %s\n"), name);
3116 new_target = symbolP;
3117 }
3118
3119 return new_target;
3120 }
3121 #endif
3122
3123 static void
3124 opcode_select (int width)
3125 {
3126 switch (width)
3127 {
3128 case 16:
3129 if (! thumb_mode)
3130 {
3131 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
3132 as_bad (_("selected processor does not support THUMB opcodes"));
3133
3134 thumb_mode = 1;
3135 /* No need to force the alignment, since we will have been
3136 coming from ARM mode, which is word-aligned. */
3137 record_alignment (now_seg, 1);
3138 }
3139 break;
3140
3141 case 32:
3142 if (thumb_mode)
3143 {
3144 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
3145 as_bad (_("selected processor does not support ARM opcodes"));
3146
3147 thumb_mode = 0;
3148
3149 if (!need_pass_2)
3150 frag_align (2, 0, 0);
3151
3152 record_alignment (now_seg, 1);
3153 }
3154 break;
3155
3156 default:
3157 as_bad (_("invalid instruction size selected (%d)"), width);
3158 }
3159 }
3160
3161 static void
3162 s_arm (int ignore ATTRIBUTE_UNUSED)
3163 {
3164 opcode_select (32);
3165 demand_empty_rest_of_line ();
3166 }
3167
3168 static void
3169 s_thumb (int ignore ATTRIBUTE_UNUSED)
3170 {
3171 opcode_select (16);
3172 demand_empty_rest_of_line ();
3173 }
3174
3175 static void
3176 s_code (int unused ATTRIBUTE_UNUSED)
3177 {
3178 int temp;
3179
3180 temp = get_absolute_expression ();
3181 switch (temp)
3182 {
3183 case 16:
3184 case 32:
3185 opcode_select (temp);
3186 break;
3187
3188 default:
3189 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3190 }
3191 }
3192
3193 static void
3194 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3195 {
3196 /* If we are not already in thumb mode go into it, EVEN if
3197 the target processor does not support thumb instructions.
3198 This is used by gcc/config/arm/lib1funcs.asm for example
3199 to compile interworking support functions even if the
3200 target processor should not support interworking. */
3201 if (! thumb_mode)
3202 {
3203 thumb_mode = 2;
3204 record_alignment (now_seg, 1);
3205 }
3206
3207 demand_empty_rest_of_line ();
3208 }
3209
3210 static void
3211 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3212 {
3213 s_thumb (0);
3214
3215 /* The following label is the name/address of the start of a Thumb function.
3216 We need to know this for the interworking support. */
3217 label_is_thumb_function_name = true;
3218 }
3219
3220 /* Perform a .set directive, but also mark the alias as
3221 being a thumb function. */
3222
3223 static void
3224 s_thumb_set (int equiv)
3225 {
3226 /* XXX the following is a duplicate of the code for s_set() in read.c
3227 We cannot just call that code as we need to get at the symbol that
3228 is created. */
3229 char * name;
3230 char delim;
3231 char * end_name;
3232 symbolS * symbolP;
3233
3234 /* Especial apologies for the random logic:
3235 This just grew, and could be parsed much more simply!
3236 Dean - in haste. */
3237 delim = get_symbol_name (& name);
3238 end_name = input_line_pointer;
3239 (void) restore_line_pointer (delim);
3240
3241 if (*input_line_pointer != ',')
3242 {
3243 *end_name = 0;
3244 as_bad (_("expected comma after name \"%s\""), name);
3245 *end_name = delim;
3246 ignore_rest_of_line ();
3247 return;
3248 }
3249
3250 input_line_pointer++;
3251 *end_name = 0;
3252
3253 if (name[0] == '.' && name[1] == '\0')
3254 {
3255 /* XXX - this should not happen to .thumb_set. */
3256 abort ();
3257 }
3258
3259 if ((symbolP = symbol_find (name)) == NULL
3260 && (symbolP = md_undefined_symbol (name)) == NULL)
3261 {
3262 #ifndef NO_LISTING
3263 /* When doing symbol listings, play games with dummy fragments living
3264 outside the normal fragment chain to record the file and line info
3265 for this symbol. */
3266 if (listing & LISTING_SYMBOLS)
3267 {
3268 extern struct list_info_struct * listing_tail;
3269 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
3270
3271 memset (dummy_frag, 0, sizeof (fragS));
3272 dummy_frag->fr_type = rs_fill;
3273 dummy_frag->line = listing_tail;
3274 symbolP = symbol_new (name, undefined_section, dummy_frag, 0);
3275 dummy_frag->fr_symbol = symbolP;
3276 }
3277 else
3278 #endif
3279 symbolP = symbol_new (name, undefined_section, &zero_address_frag, 0);
3280
3281 #ifdef OBJ_COFF
3282 /* "set" symbols are local unless otherwise specified. */
3283 SF_SET_LOCAL (symbolP);
3284 #endif /* OBJ_COFF */
3285 } /* Make a new symbol. */
3286
3287 symbol_table_insert (symbolP);
3288
3289 * end_name = delim;
3290
3291 if (equiv
3292 && S_IS_DEFINED (symbolP)
3293 && S_GET_SEGMENT (symbolP) != reg_section)
3294 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3295
3296 pseudo_set (symbolP);
3297
3298 demand_empty_rest_of_line ();
3299
3300 /* XXX Now we come to the Thumb specific bit of code. */
3301
3302 THUMB_SET_FUNC (symbolP, 1);
3303 ARM_SET_THUMB (symbolP, 1);
3304 #if defined OBJ_ELF || defined OBJ_COFF
3305 ARM_SET_INTERWORK (symbolP, support_interwork);
3306 #endif
3307 }
3308
3309 /* Directives: Mode selection. */
3310
3311 /* .syntax [unified|divided] - choose the new unified syntax
3312 (same for Arm and Thumb encoding, modulo slight differences in what
3313 can be represented) or the old divergent syntax for each mode. */
3314 static void
3315 s_syntax (int unused ATTRIBUTE_UNUSED)
3316 {
3317 char *name, delim;
3318
3319 delim = get_symbol_name (& name);
3320
3321 if (!strcasecmp (name, "unified"))
3322 unified_syntax = true;
3323 else if (!strcasecmp (name, "divided"))
3324 unified_syntax = false;
3325 else
3326 {
3327 as_bad (_("unrecognized syntax mode \"%s\""), name);
3328 return;
3329 }
3330 (void) restore_line_pointer (delim);
3331 demand_empty_rest_of_line ();
3332 }
3333
3334 /* Directives: sectioning and alignment. */
3335
3336 static void
3337 s_bss (int ignore ATTRIBUTE_UNUSED)
3338 {
3339 /* We don't support putting frags in the BSS segment, we fake it by
3340 marking in_bss, then looking at s_skip for clues. */
3341 subseg_set (bss_section, 0);
3342 demand_empty_rest_of_line ();
3343
3344 #ifdef md_elf_section_change_hook
3345 md_elf_section_change_hook ();
3346 #endif
3347 }
3348
3349 static void
3350 s_even (int ignore ATTRIBUTE_UNUSED)
3351 {
3352 /* Never make frag if expect extra pass. */
3353 if (!need_pass_2)
3354 frag_align (1, 0, 0);
3355
3356 record_alignment (now_seg, 1);
3357
3358 demand_empty_rest_of_line ();
3359 }
3360
3361 /* Directives: CodeComposer Studio. */
3362
3363 /* .ref (for CodeComposer Studio syntax only). */
3364 static void
3365 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3366 {
3367 if (codecomposer_syntax)
3368 ignore_rest_of_line ();
3369 else
3370 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3371 }
3372
3373 /* If name is not NULL, then it is used for marking the beginning of a
3374 function, whereas if it is NULL then it means the function end. */
3375 static void
3376 asmfunc_debug (const char * name)
3377 {
3378 static const char * last_name = NULL;
3379
3380 if (name != NULL)
3381 {
3382 gas_assert (last_name == NULL);
3383 last_name = name;
3384
3385 if (debug_type == DEBUG_STABS)
3386 stabs_generate_asm_func (name, name);
3387 }
3388 else
3389 {
3390 gas_assert (last_name != NULL);
3391
3392 if (debug_type == DEBUG_STABS)
3393 stabs_generate_asm_endfunc (last_name, last_name);
3394
3395 last_name = NULL;
3396 }
3397 }
3398
3399 static void
3400 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3401 {
3402 if (codecomposer_syntax)
3403 {
3404 switch (asmfunc_state)
3405 {
3406 case OUTSIDE_ASMFUNC:
3407 asmfunc_state = WAITING_ASMFUNC_NAME;
3408 break;
3409
3410 case WAITING_ASMFUNC_NAME:
3411 as_bad (_(".asmfunc repeated."));
3412 break;
3413
3414 case WAITING_ENDASMFUNC:
3415 as_bad (_(".asmfunc without function."));
3416 break;
3417 }
3418 demand_empty_rest_of_line ();
3419 }
3420 else
3421 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3422 }
3423
3424 static void
3425 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3426 {
3427 if (codecomposer_syntax)
3428 {
3429 switch (asmfunc_state)
3430 {
3431 case OUTSIDE_ASMFUNC:
3432 as_bad (_(".endasmfunc without a .asmfunc."));
3433 break;
3434
3435 case WAITING_ASMFUNC_NAME:
3436 as_bad (_(".endasmfunc without function."));
3437 break;
3438
3439 case WAITING_ENDASMFUNC:
3440 asmfunc_state = OUTSIDE_ASMFUNC;
3441 asmfunc_debug (NULL);
3442 break;
3443 }
3444 demand_empty_rest_of_line ();
3445 }
3446 else
3447 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3448 }
3449
3450 static void
3451 s_ccs_def (int name)
3452 {
3453 if (codecomposer_syntax)
3454 s_globl (name);
3455 else
3456 as_bad (_(".def pseudo-op only available with -mccs flag."));
3457 }
3458
3459 /* Directives: Literal pools. */
3460
3461 static literal_pool *
3462 find_literal_pool (void)
3463 {
3464 literal_pool * pool;
3465
3466 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3467 {
3468 if (pool->section == now_seg
3469 && pool->sub_section == now_subseg)
3470 break;
3471 }
3472
3473 return pool;
3474 }
3475
3476 static literal_pool *
3477 find_or_make_literal_pool (void)
3478 {
3479 /* Next literal pool ID number. */
3480 static unsigned int latest_pool_num = 1;
3481 literal_pool * pool;
3482
3483 pool = find_literal_pool ();
3484
3485 if (pool == NULL)
3486 {
3487 /* Create a new pool. */
3488 pool = XNEW (literal_pool);
3489 if (! pool)
3490 return NULL;
3491
3492 pool->next_free_entry = 0;
3493 pool->section = now_seg;
3494 pool->sub_section = now_subseg;
3495 pool->next = list_of_pools;
3496 pool->symbol = NULL;
3497 pool->alignment = 2;
3498
3499 /* Add it to the list. */
3500 list_of_pools = pool;
3501 }
3502
3503 /* New pools, and emptied pools, will have a NULL symbol. */
3504 if (pool->symbol == NULL)
3505 {
3506 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3507 &zero_address_frag, 0);
3508 pool->id = latest_pool_num ++;
3509 }
3510
3511 /* Done. */
3512 return pool;
3513 }
3514
3515 /* Add the literal in the global 'inst'
3516 structure to the relevant literal pool. */
3517
3518 static int
3519 add_to_lit_pool (unsigned int nbytes)
3520 {
3521 #define PADDING_SLOT 0x1
3522 #define LIT_ENTRY_SIZE_MASK 0xFF
3523 literal_pool * pool;
3524 unsigned int entry, pool_size = 0;
3525 bool padding_slot_p = false;
3526 unsigned imm1 = 0;
3527 unsigned imm2 = 0;
3528
3529 if (nbytes == 8)
3530 {
3531 imm1 = inst.operands[1].imm;
3532 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3533 : inst.relocs[0].exp.X_unsigned ? 0
3534 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3535 if (target_big_endian)
3536 {
3537 imm1 = imm2;
3538 imm2 = inst.operands[1].imm;
3539 }
3540 }
3541
3542 pool = find_or_make_literal_pool ();
3543
3544 /* Check if this literal value is already in the pool. */
3545 for (entry = 0; entry < pool->next_free_entry; entry ++)
3546 {
3547 if (nbytes == 4)
3548 {
3549 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3550 && (inst.relocs[0].exp.X_op == O_constant)
3551 && (pool->literals[entry].X_add_number
3552 == inst.relocs[0].exp.X_add_number)
3553 && (pool->literals[entry].X_md == nbytes)
3554 && (pool->literals[entry].X_unsigned
3555 == inst.relocs[0].exp.X_unsigned))
3556 break;
3557
3558 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3559 && (inst.relocs[0].exp.X_op == O_symbol)
3560 && (pool->literals[entry].X_add_number
3561 == inst.relocs[0].exp.X_add_number)
3562 && (pool->literals[entry].X_add_symbol
3563 == inst.relocs[0].exp.X_add_symbol)
3564 && (pool->literals[entry].X_op_symbol
3565 == inst.relocs[0].exp.X_op_symbol)
3566 && (pool->literals[entry].X_md == nbytes))
3567 break;
3568 }
3569 else if ((nbytes == 8)
3570 && !(pool_size & 0x7)
3571 && ((entry + 1) != pool->next_free_entry)
3572 && (pool->literals[entry].X_op == O_constant)
3573 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3574 && (pool->literals[entry].X_unsigned
3575 == inst.relocs[0].exp.X_unsigned)
3576 && (pool->literals[entry + 1].X_op == O_constant)
3577 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3578 && (pool->literals[entry + 1].X_unsigned
3579 == inst.relocs[0].exp.X_unsigned))
3580 break;
3581
3582 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3583 if (padding_slot_p && (nbytes == 4))
3584 break;
3585
3586 pool_size += 4;
3587 }
3588
3589 /* Do we need to create a new entry? */
3590 if (entry == pool->next_free_entry)
3591 {
3592 if (entry >= MAX_LITERAL_POOL_SIZE)
3593 {
3594 inst.error = _("literal pool overflow");
3595 return FAIL;
3596 }
3597
3598 if (nbytes == 8)
3599 {
3600 /* For 8-byte entries, we align to an 8-byte boundary,
3601 and split it into two 4-byte entries, because on 32-bit
3602 host, 8-byte constants are treated as big num, thus
3603 saved in "generic_bignum" which will be overwritten
3604 by later assignments.
3605
3606 We also need to make sure there is enough space for
3607 the split.
3608
3609 We also check to make sure the literal operand is a
3610 constant number. */
3611 if (!(inst.relocs[0].exp.X_op == O_constant
3612 || inst.relocs[0].exp.X_op == O_big))
3613 {
3614 inst.error = _("invalid type for literal pool");
3615 return FAIL;
3616 }
3617 else if (pool_size & 0x7)
3618 {
3619 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3620 {
3621 inst.error = _("literal pool overflow");
3622 return FAIL;
3623 }
3624
3625 pool->literals[entry] = inst.relocs[0].exp;
3626 pool->literals[entry].X_op = O_constant;
3627 pool->literals[entry].X_add_number = 0;
3628 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3629 pool->next_free_entry += 1;
3630 pool_size += 4;
3631 }
3632 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3633 {
3634 inst.error = _("literal pool overflow");
3635 return FAIL;
3636 }
3637
3638 pool->literals[entry] = inst.relocs[0].exp;
3639 pool->literals[entry].X_op = O_constant;
3640 pool->literals[entry].X_add_number = imm1;
3641 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3642 pool->literals[entry++].X_md = 4;
3643 pool->literals[entry] = inst.relocs[0].exp;
3644 pool->literals[entry].X_op = O_constant;
3645 pool->literals[entry].X_add_number = imm2;
3646 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3647 pool->literals[entry].X_md = 4;
3648 pool->alignment = 3;
3649 pool->next_free_entry += 1;
3650 }
3651 else
3652 {
3653 pool->literals[entry] = inst.relocs[0].exp;
3654 pool->literals[entry].X_md = 4;
3655 }
3656
3657 #ifdef OBJ_ELF
3658 /* PR ld/12974: Record the location of the first source line to reference
3659 this entry in the literal pool. If it turns out during linking that the
3660 symbol does not exist we will be able to give an accurate line number for
3661 the (first use of the) missing reference. */
3662 if (debug_type == DEBUG_DWARF2)
3663 dwarf2_where (pool->locs + entry);
3664 #endif
3665 pool->next_free_entry += 1;
3666 }
3667 else if (padding_slot_p)
3668 {
3669 pool->literals[entry] = inst.relocs[0].exp;
3670 pool->literals[entry].X_md = nbytes;
3671 }
3672
3673 inst.relocs[0].exp.X_op = O_symbol;
3674 inst.relocs[0].exp.X_add_number = pool_size;
3675 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3676
3677 return SUCCESS;
3678 }
3679
3680 bool
3681 tc_start_label_without_colon (void)
3682 {
3683 bool ret = true;
3684
3685 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3686 {
3687 const char *label = input_line_pointer;
3688
3689 while (!is_end_of_line[(int) label[-1]])
3690 --label;
3691
3692 if (*label == '.')
3693 {
3694 as_bad (_("Invalid label '%s'"), label);
3695 ret = false;
3696 }
3697
3698 asmfunc_debug (label);
3699
3700 asmfunc_state = WAITING_ENDASMFUNC;
3701 }
3702
3703 return ret;
3704 }
3705
3706 /* Can't use symbol_new here, so have to create a symbol and then at
3707 a later date assign it a value. That's what these functions do. */
3708
3709 static void
3710 symbol_locate (symbolS * symbolP,
3711 const char * name, /* It is copied, the caller can modify. */
3712 segT segment, /* Segment identifier (SEG_<something>). */
3713 valueT valu, /* Symbol value. */
3714 fragS * frag) /* Associated fragment. */
3715 {
3716 size_t name_length;
3717 char * preserved_copy_of_name;
3718
3719 name_length = strlen (name) + 1; /* +1 for \0. */
3720 obstack_grow (&notes, name, name_length);
3721 preserved_copy_of_name = (char *) obstack_finish (&notes);
3722
3723 #ifdef tc_canonicalize_symbol_name
3724 preserved_copy_of_name =
3725 tc_canonicalize_symbol_name (preserved_copy_of_name);
3726 #endif
3727
3728 S_SET_NAME (symbolP, preserved_copy_of_name);
3729
3730 S_SET_SEGMENT (symbolP, segment);
3731 S_SET_VALUE (symbolP, valu);
3732 symbol_clear_list_pointers (symbolP);
3733
3734 symbol_set_frag (symbolP, frag);
3735
3736 /* Link to end of symbol chain. */
3737 {
3738 extern int symbol_table_frozen;
3739
3740 if (symbol_table_frozen)
3741 abort ();
3742 }
3743
3744 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3745
3746 obj_symbol_new_hook (symbolP);
3747
3748 #ifdef tc_symbol_new_hook
3749 tc_symbol_new_hook (symbolP);
3750 #endif
3751
3752 #ifdef DEBUG_SYMS
3753 verify_symbol_chain (symbol_rootP, symbol_lastP);
3754 #endif /* DEBUG_SYMS */
3755 }
3756
3757 static void
3758 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3759 {
3760 unsigned int entry;
3761 literal_pool * pool;
3762 char sym_name[20];
3763
3764 pool = find_literal_pool ();
3765 if (pool == NULL
3766 || pool->symbol == NULL
3767 || pool->next_free_entry == 0)
3768 return;
3769
3770 /* Align pool as you have word accesses.
3771 Only make a frag if we have to. */
3772 if (!need_pass_2)
3773 frag_align (pool->alignment, 0, 0);
3774
3775 record_alignment (now_seg, 2);
3776
3777 #ifdef OBJ_ELF
3778 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3779 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3780 #endif
3781 sprintf (sym_name, "$$lit_\002%x", pool->id);
3782
3783 symbol_locate (pool->symbol, sym_name, now_seg,
3784 (valueT) frag_now_fix (), frag_now);
3785 symbol_table_insert (pool->symbol);
3786
3787 ARM_SET_THUMB (pool->symbol, thumb_mode);
3788
3789 #if defined OBJ_COFF || defined OBJ_ELF
3790 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3791 #endif
3792
3793 for (entry = 0; entry < pool->next_free_entry; entry ++)
3794 {
3795 #ifdef OBJ_ELF
3796 if (debug_type == DEBUG_DWARF2)
3797 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3798 #endif
3799 /* First output the expression in the instruction to the pool. */
3800 emit_expr (&(pool->literals[entry]),
3801 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3802 }
3803
3804 /* Mark the pool as empty. */
3805 pool->next_free_entry = 0;
3806 pool->symbol = NULL;
3807 }
3808
3809 #ifdef OBJ_ELF
3810 /* Forward declarations for functions below, in the MD interface
3811 section. */
3812 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3813 static valueT create_unwind_entry (int);
3814 static void start_unwind_section (const segT, int);
3815 static void add_unwind_opcode (valueT, int);
3816 static void flush_pending_unwind (void);
3817
3818 /* Directives: Data. */
3819
3820 static void
3821 s_arm_elf_cons (int nbytes)
3822 {
3823 expressionS exp;
3824
3825 #ifdef md_flush_pending_output
3826 md_flush_pending_output ();
3827 #endif
3828
3829 if (is_it_end_of_statement ())
3830 {
3831 demand_empty_rest_of_line ();
3832 return;
3833 }
3834
3835 #ifdef md_cons_align
3836 md_cons_align (nbytes);
3837 #endif
3838
3839 mapping_state (MAP_DATA);
3840 do
3841 {
3842 int reloc;
3843 char *base = input_line_pointer;
3844
3845 expression (& exp);
3846
3847 if (exp.X_op != O_symbol)
3848 emit_expr (&exp, (unsigned int) nbytes);
3849 else
3850 {
3851 char *before_reloc = input_line_pointer;
3852 reloc = parse_reloc (&input_line_pointer);
3853 if (reloc == -1)
3854 {
3855 as_bad (_("unrecognized relocation suffix"));
3856 ignore_rest_of_line ();
3857 return;
3858 }
3859 else if (reloc == BFD_RELOC_UNUSED)
3860 emit_expr (&exp, (unsigned int) nbytes);
3861 else
3862 {
3863 reloc_howto_type *howto = (reloc_howto_type *)
3864 bfd_reloc_type_lookup (stdoutput,
3865 (bfd_reloc_code_real_type) reloc);
3866 int size = bfd_get_reloc_size (howto);
3867
3868 if (reloc == BFD_RELOC_ARM_PLT32)
3869 {
3870 as_bad (_("(plt) is only valid on branch targets"));
3871 reloc = BFD_RELOC_UNUSED;
3872 size = 0;
3873 }
3874
3875 if (size > nbytes)
3876 as_bad (ngettext ("%s relocations do not fit in %d byte",
3877 "%s relocations do not fit in %d bytes",
3878 nbytes),
3879 howto->name, nbytes);
3880 else
3881 {
3882 /* We've parsed an expression stopping at O_symbol.
3883 But there may be more expression left now that we
3884 have parsed the relocation marker. Parse it again.
3885 XXX Surely there is a cleaner way to do this. */
3886 char *p = input_line_pointer;
3887 int offset;
3888 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3889
3890 memcpy (save_buf, base, input_line_pointer - base);
3891 memmove (base + (input_line_pointer - before_reloc),
3892 base, before_reloc - base);
3893
3894 input_line_pointer = base + (input_line_pointer-before_reloc);
3895 expression (&exp);
3896 memcpy (base, save_buf, p - base);
3897
3898 offset = nbytes - size;
3899 p = frag_more (nbytes);
3900 memset (p, 0, nbytes);
3901 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3902 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3903 free (save_buf);
3904 }
3905 }
3906 }
3907 }
3908 while (*input_line_pointer++ == ',');
3909
3910 /* Put terminator back into stream. */
3911 input_line_pointer --;
3912 demand_empty_rest_of_line ();
3913 }
3914
3915 /* Emit an expression containing a 32-bit thumb instruction.
3916 Implementation based on put_thumb32_insn. */
3917
3918 static void
3919 emit_thumb32_expr (expressionS * exp)
3920 {
3921 expressionS exp_high = *exp;
3922
3923 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3924 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3925 exp->X_add_number &= 0xffff;
3926 emit_expr (exp, (unsigned int) THUMB_SIZE);
3927 }
3928
3929 /* Guess the instruction size based on the opcode. */
3930
3931 static int
3932 thumb_insn_size (int opcode)
3933 {
3934 if ((unsigned int) opcode < 0xe800u)
3935 return 2;
3936 else if ((unsigned int) opcode >= 0xe8000000u)
3937 return 4;
3938 else
3939 return 0;
3940 }
3941
3942 static bool
3943 emit_insn (expressionS *exp, int nbytes)
3944 {
3945 int size = 0;
3946
3947 if (exp->X_op == O_constant)
3948 {
3949 size = nbytes;
3950
3951 if (size == 0)
3952 size = thumb_insn_size (exp->X_add_number);
3953
3954 if (size != 0)
3955 {
3956 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3957 {
3958 as_bad (_(".inst.n operand too big. "\
3959 "Use .inst.w instead"));
3960 size = 0;
3961 }
3962 else
3963 {
3964 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3965 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
3966 else
3967 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3968
3969 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3970 emit_thumb32_expr (exp);
3971 else
3972 emit_expr (exp, (unsigned int) size);
3973
3974 it_fsm_post_encode ();
3975 }
3976 }
3977 else
3978 as_bad (_("cannot determine Thumb instruction size. " \
3979 "Use .inst.n/.inst.w instead"));
3980 }
3981 else
3982 as_bad (_("constant expression required"));
3983
3984 return (size != 0);
3985 }
3986
3987 /* Like s_arm_elf_cons but do not use md_cons_align and
3988 set the mapping state to MAP_ARM/MAP_THUMB. */
3989
3990 static void
3991 s_arm_elf_inst (int nbytes)
3992 {
3993 if (is_it_end_of_statement ())
3994 {
3995 demand_empty_rest_of_line ();
3996 return;
3997 }
3998
3999 /* Calling mapping_state () here will not change ARM/THUMB,
4000 but will ensure not to be in DATA state. */
4001
4002 if (thumb_mode)
4003 mapping_state (MAP_THUMB);
4004 else
4005 {
4006 if (nbytes != 0)
4007 {
4008 as_bad (_("width suffixes are invalid in ARM mode"));
4009 ignore_rest_of_line ();
4010 return;
4011 }
4012
4013 nbytes = 4;
4014
4015 mapping_state (MAP_ARM);
4016 }
4017
4018 do
4019 {
4020 expressionS exp;
4021
4022 expression (& exp);
4023
4024 if (! emit_insn (& exp, nbytes))
4025 {
4026 ignore_rest_of_line ();
4027 return;
4028 }
4029 }
4030 while (*input_line_pointer++ == ',');
4031
4032 /* Put terminator back into stream. */
4033 input_line_pointer --;
4034 demand_empty_rest_of_line ();
4035 }
4036
4037 /* Parse a .rel31 directive. */
4038
4039 static void
4040 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
4041 {
4042 expressionS exp;
4043 char *p;
4044 valueT highbit;
4045
4046 highbit = 0;
4047 if (*input_line_pointer == '1')
4048 highbit = 0x80000000;
4049 else if (*input_line_pointer != '0')
4050 as_bad (_("expected 0 or 1"));
4051
4052 input_line_pointer++;
4053 if (*input_line_pointer != ',')
4054 as_bad (_("missing comma"));
4055 input_line_pointer++;
4056
4057 #ifdef md_flush_pending_output
4058 md_flush_pending_output ();
4059 #endif
4060
4061 #ifdef md_cons_align
4062 md_cons_align (4);
4063 #endif
4064
4065 mapping_state (MAP_DATA);
4066
4067 expression (&exp);
4068
4069 p = frag_more (4);
4070 md_number_to_chars (p, highbit, 4);
4071 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4072 BFD_RELOC_ARM_PREL31);
4073
4074 demand_empty_rest_of_line ();
4075 }
4076
4077 /* Directives: AEABI stack-unwind tables. */
4078
4079 /* Parse an unwind_fnstart directive. Simply records the current location. */
4080
4081 static void
4082 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4083 {
4084 demand_empty_rest_of_line ();
4085 if (unwind.proc_start)
4086 {
4087 as_bad (_("duplicate .fnstart directive"));
4088 return;
4089 }
4090
4091 /* Mark the start of the function. */
4092 unwind.proc_start = expr_build_dot ();
4093
4094 /* Reset the rest of the unwind info. */
4095 unwind.opcode_count = 0;
4096 unwind.table_entry = NULL;
4097 unwind.personality_routine = NULL;
4098 unwind.personality_index = -1;
4099 unwind.frame_size = 0;
4100 unwind.fp_offset = 0;
4101 unwind.fp_reg = REG_SP;
4102 unwind.fp_used = 0;
4103 unwind.sp_restored = 0;
4104 }
4105
4106
4107 /* Parse a handlerdata directive. Creates the exception handling table entry
4108 for the function. */
4109
4110 static void
4111 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4112 {
4113 demand_empty_rest_of_line ();
4114 if (!unwind.proc_start)
4115 as_bad (MISSING_FNSTART);
4116
4117 if (unwind.table_entry)
4118 as_bad (_("duplicate .handlerdata directive"));
4119
4120 create_unwind_entry (1);
4121 }
4122
4123 /* Parse an unwind_fnend directive. Generates the index table entry. */
4124
4125 static void
4126 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4127 {
4128 long where;
4129 char *ptr;
4130 valueT val;
4131 unsigned int marked_pr_dependency;
4132
4133 demand_empty_rest_of_line ();
4134
4135 if (!unwind.proc_start)
4136 {
4137 as_bad (_(".fnend directive without .fnstart"));
4138 return;
4139 }
4140
4141 /* Add eh table entry. */
4142 if (unwind.table_entry == NULL)
4143 val = create_unwind_entry (0);
4144 else
4145 val = 0;
4146
4147 /* Add index table entry. This is two words. */
4148 start_unwind_section (unwind.saved_seg, 1);
4149 frag_align (2, 0, 0);
4150 record_alignment (now_seg, 2);
4151
4152 ptr = frag_more (8);
4153 memset (ptr, 0, 8);
4154 where = frag_now_fix () - 8;
4155
4156 /* Self relative offset of the function start. */
4157 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4158 BFD_RELOC_ARM_PREL31);
4159
4160 /* Indicate dependency on EHABI-defined personality routines to the
4161 linker, if it hasn't been done already. */
4162 marked_pr_dependency
4163 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
4164 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4165 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4166 {
4167 static const char *const name[] =
4168 {
4169 "__aeabi_unwind_cpp_pr0",
4170 "__aeabi_unwind_cpp_pr1",
4171 "__aeabi_unwind_cpp_pr2"
4172 };
4173 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4174 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
4175 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
4176 |= 1 << unwind.personality_index;
4177 }
4178
4179 if (val)
4180 /* Inline exception table entry. */
4181 md_number_to_chars (ptr + 4, val, 4);
4182 else
4183 /* Self relative offset of the table entry. */
4184 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4185 BFD_RELOC_ARM_PREL31);
4186
4187 /* Restore the original section. */
4188 subseg_set (unwind.saved_seg, unwind.saved_subseg);
4189
4190 unwind.proc_start = NULL;
4191 }
4192
4193
4194 /* Parse an unwind_cantunwind directive. */
4195
4196 static void
4197 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4198 {
4199 demand_empty_rest_of_line ();
4200 if (!unwind.proc_start)
4201 as_bad (MISSING_FNSTART);
4202
4203 if (unwind.personality_routine || unwind.personality_index != -1)
4204 as_bad (_("personality routine specified for cantunwind frame"));
4205
4206 unwind.personality_index = -2;
4207 }
4208
4209
4210 /* Parse a personalityindex directive. */
4211
4212 static void
4213 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4214 {
4215 expressionS exp;
4216
4217 if (!unwind.proc_start)
4218 as_bad (MISSING_FNSTART);
4219
4220 if (unwind.personality_routine || unwind.personality_index != -1)
4221 as_bad (_("duplicate .personalityindex directive"));
4222
4223 expression (&exp);
4224
4225 if (exp.X_op != O_constant
4226 || exp.X_add_number < 0 || exp.X_add_number > 15)
4227 {
4228 as_bad (_("bad personality routine number"));
4229 ignore_rest_of_line ();
4230 return;
4231 }
4232
4233 unwind.personality_index = exp.X_add_number;
4234
4235 demand_empty_rest_of_line ();
4236 }
4237
4238
4239 /* Parse a personality directive. */
4240
4241 static void
4242 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4243 {
4244 char *name, *p, c;
4245
4246 if (!unwind.proc_start)
4247 as_bad (MISSING_FNSTART);
4248
4249 if (unwind.personality_routine || unwind.personality_index != -1)
4250 as_bad (_("duplicate .personality directive"));
4251
4252 c = get_symbol_name (& name);
4253 p = input_line_pointer;
4254 if (c == '"')
4255 ++ input_line_pointer;
4256 unwind.personality_routine = symbol_find_or_make (name);
4257 *p = c;
4258 demand_empty_rest_of_line ();
4259 }
4260
4261
4262 /* Parse a directive saving core registers. */
4263
4264 static void
4265 s_arm_unwind_save_core (void)
4266 {
4267 valueT op;
4268 long range;
4269 int n;
4270
4271 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
4272 if (range == FAIL)
4273 {
4274 as_bad (_("expected register list"));
4275 ignore_rest_of_line ();
4276 return;
4277 }
4278
4279 demand_empty_rest_of_line ();
4280
4281 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4282 into .unwind_save {..., sp...}. We aren't bothered about the value of
4283 ip because it is clobbered by calls. */
4284 if (unwind.sp_restored && unwind.fp_reg == 12
4285 && (range & 0x3000) == 0x1000)
4286 {
4287 unwind.opcode_count--;
4288 unwind.sp_restored = 0;
4289 range = (range | 0x2000) & ~0x1000;
4290 unwind.pending_offset = 0;
4291 }
4292
4293 /* Pop r4-r15. */
4294 if (range & 0xfff0)
4295 {
4296 /* See if we can use the short opcodes. These pop a block of up to 8
4297 registers starting with r4, plus maybe r14. */
4298 for (n = 0; n < 8; n++)
4299 {
4300 /* Break at the first non-saved register. */
4301 if ((range & (1 << (n + 4))) == 0)
4302 break;
4303 }
4304 /* See if there are any other bits set. */
4305 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4306 {
4307 /* Use the long form. */
4308 op = 0x8000 | ((range >> 4) & 0xfff);
4309 add_unwind_opcode (op, 2);
4310 }
4311 else
4312 {
4313 /* Use the short form. */
4314 if (range & 0x4000)
4315 op = 0xa8; /* Pop r14. */
4316 else
4317 op = 0xa0; /* Do not pop r14. */
4318 op |= (n - 1);
4319 add_unwind_opcode (op, 1);
4320 }
4321 }
4322
4323 /* Pop r0-r3. */
4324 if (range & 0xf)
4325 {
4326 op = 0xb100 | (range & 0xf);
4327 add_unwind_opcode (op, 2);
4328 }
4329
4330 /* Record the number of bytes pushed. */
4331 for (n = 0; n < 16; n++)
4332 {
4333 if (range & (1 << n))
4334 unwind.frame_size += 4;
4335 }
4336 }
4337
4338
4339 /* Parse a directive saving FPA registers. */
4340
4341 static void
4342 s_arm_unwind_save_fpa (int reg)
4343 {
4344 expressionS exp;
4345 int num_regs;
4346 valueT op;
4347
4348 /* Get Number of registers to transfer. */
4349 if (skip_past_comma (&input_line_pointer) != FAIL)
4350 expression (&exp);
4351 else
4352 exp.X_op = O_illegal;
4353
4354 if (exp.X_op != O_constant)
4355 {
4356 as_bad (_("expected , <constant>"));
4357 ignore_rest_of_line ();
4358 return;
4359 }
4360
4361 num_regs = exp.X_add_number;
4362
4363 if (num_regs < 1 || num_regs > 4)
4364 {
4365 as_bad (_("number of registers must be in the range [1:4]"));
4366 ignore_rest_of_line ();
4367 return;
4368 }
4369
4370 demand_empty_rest_of_line ();
4371
4372 if (reg == 4)
4373 {
4374 /* Short form. */
4375 op = 0xb4 | (num_regs - 1);
4376 add_unwind_opcode (op, 1);
4377 }
4378 else
4379 {
4380 /* Long form. */
4381 op = 0xc800 | (reg << 4) | (num_regs - 1);
4382 add_unwind_opcode (op, 2);
4383 }
4384 unwind.frame_size += num_regs * 12;
4385 }
4386
4387
4388 /* Parse a directive saving VFP registers for ARMv6 and above. */
4389
4390 static void
4391 s_arm_unwind_save_vfp_armv6 (void)
4392 {
4393 int count;
4394 unsigned int start;
4395 valueT op;
4396 int num_vfpv3_regs = 0;
4397 int num_regs_below_16;
4398 bool partial_match;
4399
4400 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4401 &partial_match);
4402 if (count == FAIL)
4403 {
4404 as_bad (_("expected register list"));
4405 ignore_rest_of_line ();
4406 return;
4407 }
4408
4409 demand_empty_rest_of_line ();
4410
4411 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4412 than FSTMX/FLDMX-style ones). */
4413
4414 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4415 if (start >= 16)
4416 num_vfpv3_regs = count;
4417 else if (start + count > 16)
4418 num_vfpv3_regs = start + count - 16;
4419
4420 if (num_vfpv3_regs > 0)
4421 {
4422 int start_offset = start > 16 ? start - 16 : 0;
4423 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4424 add_unwind_opcode (op, 2);
4425 }
4426
4427 /* Generate opcode for registers numbered in the range 0 .. 15. */
4428 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4429 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4430 if (num_regs_below_16 > 0)
4431 {
4432 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4433 add_unwind_opcode (op, 2);
4434 }
4435
4436 unwind.frame_size += count * 8;
4437 }
4438
4439
4440 /* Parse a directive saving VFP registers for pre-ARMv6. */
4441
4442 static void
4443 s_arm_unwind_save_vfp (void)
4444 {
4445 int count;
4446 unsigned int reg;
4447 valueT op;
4448 bool partial_match;
4449
4450 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4451 &partial_match);
4452 if (count == FAIL)
4453 {
4454 as_bad (_("expected register list"));
4455 ignore_rest_of_line ();
4456 return;
4457 }
4458
4459 demand_empty_rest_of_line ();
4460
4461 if (reg == 8)
4462 {
4463 /* Short form. */
4464 op = 0xb8 | (count - 1);
4465 add_unwind_opcode (op, 1);
4466 }
4467 else
4468 {
4469 /* Long form. */
4470 op = 0xb300 | (reg << 4) | (count - 1);
4471 add_unwind_opcode (op, 2);
4472 }
4473 unwind.frame_size += count * 8 + 4;
4474 }
4475
4476
4477 /* Parse a directive saving iWMMXt data registers. */
4478
4479 static void
4480 s_arm_unwind_save_mmxwr (void)
4481 {
4482 int reg;
4483 int hi_reg;
4484 int i;
4485 unsigned mask = 0;
4486 valueT op;
4487
4488 if (*input_line_pointer == '{')
4489 input_line_pointer++;
4490
4491 do
4492 {
4493 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4494
4495 if (reg == FAIL)
4496 {
4497 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4498 goto error;
4499 }
4500
4501 if (mask >> reg)
4502 as_tsktsk (_("register list not in ascending order"));
4503 mask |= 1 << reg;
4504
4505 if (*input_line_pointer == '-')
4506 {
4507 input_line_pointer++;
4508 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4509 if (hi_reg == FAIL)
4510 {
4511 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4512 goto error;
4513 }
4514 else if (reg >= hi_reg)
4515 {
4516 as_bad (_("bad register range"));
4517 goto error;
4518 }
4519 for (; reg < hi_reg; reg++)
4520 mask |= 1 << reg;
4521 }
4522 }
4523 while (skip_past_comma (&input_line_pointer) != FAIL);
4524
4525 skip_past_char (&input_line_pointer, '}');
4526
4527 demand_empty_rest_of_line ();
4528
4529 /* Generate any deferred opcodes because we're going to be looking at
4530 the list. */
4531 flush_pending_unwind ();
4532
4533 for (i = 0; i < 16; i++)
4534 {
4535 if (mask & (1 << i))
4536 unwind.frame_size += 8;
4537 }
4538
4539 /* Attempt to combine with a previous opcode. We do this because gcc
4540 likes to output separate unwind directives for a single block of
4541 registers. */
4542 if (unwind.opcode_count > 0)
4543 {
4544 i = unwind.opcodes[unwind.opcode_count - 1];
4545 if ((i & 0xf8) == 0xc0)
4546 {
4547 i &= 7;
4548 /* Only merge if the blocks are contiguous. */
4549 if (i < 6)
4550 {
4551 if ((mask & 0xfe00) == (1 << 9))
4552 {
4553 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4554 unwind.opcode_count--;
4555 }
4556 }
4557 else if (i == 6 && unwind.opcode_count >= 2)
4558 {
4559 i = unwind.opcodes[unwind.opcode_count - 2];
4560 reg = i >> 4;
4561 i &= 0xf;
4562
4563 op = 0xffff << (reg - 1);
4564 if (reg > 0
4565 && ((mask & op) == (1u << (reg - 1))))
4566 {
4567 op = (1 << (reg + i + 1)) - 1;
4568 op &= ~((1 << reg) - 1);
4569 mask |= op;
4570 unwind.opcode_count -= 2;
4571 }
4572 }
4573 }
4574 }
4575
4576 hi_reg = 15;
4577 /* We want to generate opcodes in the order the registers have been
4578 saved, ie. descending order. */
4579 for (reg = 15; reg >= -1; reg--)
4580 {
4581 /* Save registers in blocks. */
4582 if (reg < 0
4583 || !(mask & (1 << reg)))
4584 {
4585 /* We found an unsaved reg. Generate opcodes to save the
4586 preceding block. */
4587 if (reg != hi_reg)
4588 {
4589 if (reg == 9)
4590 {
4591 /* Short form. */
4592 op = 0xc0 | (hi_reg - 10);
4593 add_unwind_opcode (op, 1);
4594 }
4595 else
4596 {
4597 /* Long form. */
4598 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4599 add_unwind_opcode (op, 2);
4600 }
4601 }
4602 hi_reg = reg - 1;
4603 }
4604 }
4605
4606 return;
4607 error:
4608 ignore_rest_of_line ();
4609 }
4610
4611 static void
4612 s_arm_unwind_save_mmxwcg (void)
4613 {
4614 int reg;
4615 int hi_reg;
4616 unsigned mask = 0;
4617 valueT op;
4618
4619 if (*input_line_pointer == '{')
4620 input_line_pointer++;
4621
4622 skip_whitespace (input_line_pointer);
4623
4624 do
4625 {
4626 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4627
4628 if (reg == FAIL)
4629 {
4630 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4631 goto error;
4632 }
4633
4634 reg -= 8;
4635 if (mask >> reg)
4636 as_tsktsk (_("register list not in ascending order"));
4637 mask |= 1 << reg;
4638
4639 if (*input_line_pointer == '-')
4640 {
4641 input_line_pointer++;
4642 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4643 if (hi_reg == FAIL)
4644 {
4645 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4646 goto error;
4647 }
4648 else if (reg >= hi_reg)
4649 {
4650 as_bad (_("bad register range"));
4651 goto error;
4652 }
4653 for (; reg < hi_reg; reg++)
4654 mask |= 1 << reg;
4655 }
4656 }
4657 while (skip_past_comma (&input_line_pointer) != FAIL);
4658
4659 skip_past_char (&input_line_pointer, '}');
4660
4661 demand_empty_rest_of_line ();
4662
4663 /* Generate any deferred opcodes because we're going to be looking at
4664 the list. */
4665 flush_pending_unwind ();
4666
4667 for (reg = 0; reg < 16; reg++)
4668 {
4669 if (mask & (1 << reg))
4670 unwind.frame_size += 4;
4671 }
4672 op = 0xc700 | mask;
4673 add_unwind_opcode (op, 2);
4674 return;
4675 error:
4676 ignore_rest_of_line ();
4677 }
4678
4679
4680 /* Parse an unwind_save directive.
4681 If the argument is non-zero, this is a .vsave directive. */
4682
4683 static void
4684 s_arm_unwind_save (int arch_v6)
4685 {
4686 char *peek;
4687 struct reg_entry *reg;
4688 bool had_brace = false;
4689
4690 if (!unwind.proc_start)
4691 as_bad (MISSING_FNSTART);
4692
4693 /* Figure out what sort of save we have. */
4694 peek = input_line_pointer;
4695
4696 if (*peek == '{')
4697 {
4698 had_brace = true;
4699 peek++;
4700 }
4701
4702 reg = arm_reg_parse_multi (&peek);
4703
4704 if (!reg)
4705 {
4706 as_bad (_("register expected"));
4707 ignore_rest_of_line ();
4708 return;
4709 }
4710
4711 switch (reg->type)
4712 {
4713 case REG_TYPE_FN:
4714 if (had_brace)
4715 {
4716 as_bad (_("FPA .unwind_save does not take a register list"));
4717 ignore_rest_of_line ();
4718 return;
4719 }
4720 input_line_pointer = peek;
4721 s_arm_unwind_save_fpa (reg->number);
4722 return;
4723
4724 case REG_TYPE_RN:
4725 s_arm_unwind_save_core ();
4726 return;
4727
4728 case REG_TYPE_VFD:
4729 if (arch_v6)
4730 s_arm_unwind_save_vfp_armv6 ();
4731 else
4732 s_arm_unwind_save_vfp ();
4733 return;
4734
4735 case REG_TYPE_MMXWR:
4736 s_arm_unwind_save_mmxwr ();
4737 return;
4738
4739 case REG_TYPE_MMXWCG:
4740 s_arm_unwind_save_mmxwcg ();
4741 return;
4742
4743 default:
4744 as_bad (_(".unwind_save does not support this kind of register"));
4745 ignore_rest_of_line ();
4746 }
4747 }
4748
4749
4750 /* Parse an unwind_movsp directive. */
4751
4752 static void
4753 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4754 {
4755 int reg;
4756 valueT op;
4757 int offset;
4758
4759 if (!unwind.proc_start)
4760 as_bad (MISSING_FNSTART);
4761
4762 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4763 if (reg == FAIL)
4764 {
4765 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4766 ignore_rest_of_line ();
4767 return;
4768 }
4769
4770 /* Optional constant. */
4771 if (skip_past_comma (&input_line_pointer) != FAIL)
4772 {
4773 if (immediate_for_directive (&offset) == FAIL)
4774 return;
4775 }
4776 else
4777 offset = 0;
4778
4779 demand_empty_rest_of_line ();
4780
4781 if (reg == REG_SP || reg == REG_PC)
4782 {
4783 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4784 return;
4785 }
4786
4787 if (unwind.fp_reg != REG_SP)
4788 as_bad (_("unexpected .unwind_movsp directive"));
4789
4790 /* Generate opcode to restore the value. */
4791 op = 0x90 | reg;
4792 add_unwind_opcode (op, 1);
4793
4794 /* Record the information for later. */
4795 unwind.fp_reg = reg;
4796 unwind.fp_offset = unwind.frame_size - offset;
4797 unwind.sp_restored = 1;
4798 }
4799
4800 /* Parse an unwind_pad directive. */
4801
4802 static void
4803 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4804 {
4805 int offset;
4806
4807 if (!unwind.proc_start)
4808 as_bad (MISSING_FNSTART);
4809
4810 if (immediate_for_directive (&offset) == FAIL)
4811 return;
4812
4813 if (offset & 3)
4814 {
4815 as_bad (_("stack increment must be multiple of 4"));
4816 ignore_rest_of_line ();
4817 return;
4818 }
4819
4820 /* Don't generate any opcodes, just record the details for later. */
4821 unwind.frame_size += offset;
4822 unwind.pending_offset += offset;
4823
4824 demand_empty_rest_of_line ();
4825 }
4826
4827 /* Parse an unwind_setfp directive. */
4828
4829 static void
4830 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4831 {
4832 int sp_reg;
4833 int fp_reg;
4834 int offset;
4835
4836 if (!unwind.proc_start)
4837 as_bad (MISSING_FNSTART);
4838
4839 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4840 if (skip_past_comma (&input_line_pointer) == FAIL)
4841 sp_reg = FAIL;
4842 else
4843 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4844
4845 if (fp_reg == FAIL || sp_reg == FAIL)
4846 {
4847 as_bad (_("expected <reg>, <reg>"));
4848 ignore_rest_of_line ();
4849 return;
4850 }
4851
4852 /* Optional constant. */
4853 if (skip_past_comma (&input_line_pointer) != FAIL)
4854 {
4855 if (immediate_for_directive (&offset) == FAIL)
4856 return;
4857 }
4858 else
4859 offset = 0;
4860
4861 demand_empty_rest_of_line ();
4862
4863 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4864 {
4865 as_bad (_("register must be either sp or set by a previous"
4866 "unwind_movsp directive"));
4867 return;
4868 }
4869
4870 /* Don't generate any opcodes, just record the information for later. */
4871 unwind.fp_reg = fp_reg;
4872 unwind.fp_used = 1;
4873 if (sp_reg == REG_SP)
4874 unwind.fp_offset = unwind.frame_size - offset;
4875 else
4876 unwind.fp_offset -= offset;
4877 }
4878
4879 /* Parse an unwind_raw directive. */
4880
4881 static void
4882 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4883 {
4884 expressionS exp;
4885 /* This is an arbitrary limit. */
4886 unsigned char op[16];
4887 int count;
4888
4889 if (!unwind.proc_start)
4890 as_bad (MISSING_FNSTART);
4891
4892 expression (&exp);
4893 if (exp.X_op == O_constant
4894 && skip_past_comma (&input_line_pointer) != FAIL)
4895 {
4896 unwind.frame_size += exp.X_add_number;
4897 expression (&exp);
4898 }
4899 else
4900 exp.X_op = O_illegal;
4901
4902 if (exp.X_op != O_constant)
4903 {
4904 as_bad (_("expected <offset>, <opcode>"));
4905 ignore_rest_of_line ();
4906 return;
4907 }
4908
4909 count = 0;
4910
4911 /* Parse the opcode. */
4912 for (;;)
4913 {
4914 if (count >= 16)
4915 {
4916 as_bad (_("unwind opcode too long"));
4917 ignore_rest_of_line ();
4918 }
4919 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4920 {
4921 as_bad (_("invalid unwind opcode"));
4922 ignore_rest_of_line ();
4923 return;
4924 }
4925 op[count++] = exp.X_add_number;
4926
4927 /* Parse the next byte. */
4928 if (skip_past_comma (&input_line_pointer) == FAIL)
4929 break;
4930
4931 expression (&exp);
4932 }
4933
4934 /* Add the opcode bytes in reverse order. */
4935 while (count--)
4936 add_unwind_opcode (op[count], 1);
4937
4938 demand_empty_rest_of_line ();
4939 }
4940
4941
4942 /* Parse a .eabi_attribute directive. */
4943
4944 static void
4945 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4946 {
4947 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4948
4949 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4950 attributes_set_explicitly[tag] = 1;
4951 }
4952
4953 /* Emit a tls fix for the symbol. */
4954
4955 static void
4956 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4957 {
4958 char *p;
4959 expressionS exp;
4960 #ifdef md_flush_pending_output
4961 md_flush_pending_output ();
4962 #endif
4963
4964 #ifdef md_cons_align
4965 md_cons_align (4);
4966 #endif
4967
4968 /* Since we're just labelling the code, there's no need to define a
4969 mapping symbol. */
4970 expression (&exp);
4971 p = obstack_next_free (&frchain_now->frch_obstack);
4972 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4973 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4974 : BFD_RELOC_ARM_TLS_DESCSEQ);
4975 }
4976 #endif /* OBJ_ELF */
4977
4978 static void s_arm_arch (int);
4979 static void s_arm_object_arch (int);
4980 static void s_arm_cpu (int);
4981 static void s_arm_fpu (int);
4982 static void s_arm_arch_extension (int);
4983
4984 #ifdef TE_PE
4985
4986 static void
4987 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4988 {
4989 expressionS exp;
4990
4991 do
4992 {
4993 expression (&exp);
4994 if (exp.X_op == O_symbol)
4995 exp.X_op = O_secrel;
4996
4997 emit_expr (&exp, 4);
4998 }
4999 while (*input_line_pointer++ == ',');
5000
5001 input_line_pointer--;
5002 demand_empty_rest_of_line ();
5003 }
5004 #endif /* TE_PE */
5005
5006 int
5007 arm_is_largest_exponent_ok (int precision)
5008 {
5009 /* precision == 1 ensures that this will only return
5010 true for 16 bit floats. */
5011 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
5012 }
5013
5014 static void
5015 set_fp16_format (int dummy ATTRIBUTE_UNUSED)
5016 {
5017 char saved_char;
5018 char* name;
5019 enum fp_16bit_format new_format;
5020
5021 new_format = ARM_FP16_FORMAT_DEFAULT;
5022
5023 name = input_line_pointer;
5024 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
5025 input_line_pointer++;
5026
5027 saved_char = *input_line_pointer;
5028 *input_line_pointer = 0;
5029
5030 if (strcasecmp (name, "ieee") == 0)
5031 new_format = ARM_FP16_FORMAT_IEEE;
5032 else if (strcasecmp (name, "alternative") == 0)
5033 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
5034 else
5035 {
5036 as_bad (_("unrecognised float16 format \"%s\""), name);
5037 goto cleanup;
5038 }
5039
5040 /* Only set fp16_format if it is still the default (aka not already
5041 been set yet). */
5042 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
5043 fp16_format = new_format;
5044 else
5045 {
5046 if (new_format != fp16_format)
5047 as_warn (_("float16 format cannot be set more than once, ignoring."));
5048 }
5049
5050 cleanup:
5051 *input_line_pointer = saved_char;
5052 ignore_rest_of_line ();
5053 }
5054
5055 /* This table describes all the machine specific pseudo-ops the assembler
5056 has to support. The fields are:
5057 pseudo-op name without dot
5058 function to call to execute this pseudo-op
5059 Integer arg to pass to the function. */
5060
5061 const pseudo_typeS md_pseudo_table[] =
5062 {
5063 /* Never called because '.req' does not start a line. */
5064 { "req", s_req, 0 },
5065 /* Following two are likewise never called. */
5066 { "dn", s_dn, 0 },
5067 { "qn", s_qn, 0 },
5068 { "unreq", s_unreq, 0 },
5069 { "bss", s_bss, 0 },
5070 { "align", s_align_ptwo, 2 },
5071 { "arm", s_arm, 0 },
5072 { "thumb", s_thumb, 0 },
5073 { "code", s_code, 0 },
5074 { "force_thumb", s_force_thumb, 0 },
5075 { "thumb_func", s_thumb_func, 0 },
5076 { "thumb_set", s_thumb_set, 0 },
5077 { "even", s_even, 0 },
5078 { "ltorg", s_ltorg, 0 },
5079 { "pool", s_ltorg, 0 },
5080 { "syntax", s_syntax, 0 },
5081 { "cpu", s_arm_cpu, 0 },
5082 { "arch", s_arm_arch, 0 },
5083 { "object_arch", s_arm_object_arch, 0 },
5084 { "fpu", s_arm_fpu, 0 },
5085 { "arch_extension", s_arm_arch_extension, 0 },
5086 #ifdef OBJ_ELF
5087 { "word", s_arm_elf_cons, 4 },
5088 { "long", s_arm_elf_cons, 4 },
5089 { "inst.n", s_arm_elf_inst, 2 },
5090 { "inst.w", s_arm_elf_inst, 4 },
5091 { "inst", s_arm_elf_inst, 0 },
5092 { "rel31", s_arm_rel31, 0 },
5093 { "fnstart", s_arm_unwind_fnstart, 0 },
5094 { "fnend", s_arm_unwind_fnend, 0 },
5095 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5096 { "personality", s_arm_unwind_personality, 0 },
5097 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5098 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5099 { "save", s_arm_unwind_save, 0 },
5100 { "vsave", s_arm_unwind_save, 1 },
5101 { "movsp", s_arm_unwind_movsp, 0 },
5102 { "pad", s_arm_unwind_pad, 0 },
5103 { "setfp", s_arm_unwind_setfp, 0 },
5104 { "unwind_raw", s_arm_unwind_raw, 0 },
5105 { "eabi_attribute", s_arm_eabi_attribute, 0 },
5106 { "tlsdescseq", s_arm_tls_descseq, 0 },
5107 #else
5108 { "word", cons, 4},
5109
5110 /* These are used for dwarf. */
5111 {"2byte", cons, 2},
5112 {"4byte", cons, 4},
5113 {"8byte", cons, 8},
5114 /* These are used for dwarf2. */
5115 { "file", dwarf2_directive_file, 0 },
5116 { "loc", dwarf2_directive_loc, 0 },
5117 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
5118 #endif
5119 { "extend", float_cons, 'x' },
5120 { "ldouble", float_cons, 'x' },
5121 { "packed", float_cons, 'p' },
5122 { "bfloat16", float_cons, 'b' },
5123 #ifdef TE_PE
5124 {"secrel32", pe_directive_secrel, 0},
5125 #endif
5126
5127 /* These are for compatibility with CodeComposer Studio. */
5128 {"ref", s_ccs_ref, 0},
5129 {"def", s_ccs_def, 0},
5130 {"asmfunc", s_ccs_asmfunc, 0},
5131 {"endasmfunc", s_ccs_endasmfunc, 0},
5132
5133 {"float16", float_cons, 'h' },
5134 {"float16_format", set_fp16_format, 0 },
5135
5136 { 0, 0, 0 }
5137 };
5138
5139 /* Parser functions used exclusively in instruction operands. */
5140
5141 /* Generic immediate-value read function for use in insn parsing.
5142 STR points to the beginning of the immediate (the leading #);
5143 VAL receives the value; if the value is outside [MIN, MAX]
5144 issue an error. PREFIX_OPT is true if the immediate prefix is
5145 optional. */
5146
5147 static int
5148 parse_immediate (char **str, int *val, int min, int max,
5149 bool prefix_opt)
5150 {
5151 expressionS exp;
5152
5153 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5154 if (exp.X_op != O_constant)
5155 {
5156 inst.error = _("constant expression required");
5157 return FAIL;
5158 }
5159
5160 if (exp.X_add_number < min || exp.X_add_number > max)
5161 {
5162 inst.error = _("immediate value out of range");
5163 return FAIL;
5164 }
5165
5166 *val = exp.X_add_number;
5167 return SUCCESS;
5168 }
5169
5170 /* Less-generic immediate-value read function with the possibility of loading a
5171 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5172 instructions. Puts the result directly in inst.operands[i]. */
5173
5174 static int
5175 parse_big_immediate (char **str, int i, expressionS *in_exp,
5176 bool allow_symbol_p)
5177 {
5178 expressionS exp;
5179 expressionS *exp_p = in_exp ? in_exp : &exp;
5180 char *ptr = *str;
5181
5182 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5183
5184 if (exp_p->X_op == O_constant)
5185 {
5186 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
5187 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5188 O_constant. We have to be careful not to break compilation for
5189 32-bit X_add_number, though. */
5190 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
5191 {
5192 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5193 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5194 & 0xffffffff);
5195 inst.operands[i].regisimm = 1;
5196 }
5197 }
5198 else if (exp_p->X_op == O_big
5199 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5200 {
5201 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
5202
5203 /* Bignums have their least significant bits in
5204 generic_bignum[0]. Make sure we put 32 bits in imm and
5205 32 bits in reg, in a (hopefully) portable way. */
5206 gas_assert (parts != 0);
5207
5208 /* Make sure that the number is not too big.
5209 PR 11972: Bignums can now be sign-extended to the
5210 size of a .octa so check that the out of range bits
5211 are all zero or all one. */
5212 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
5213 {
5214 LITTLENUM_TYPE m = -1;
5215
5216 if (generic_bignum[parts * 2] != 0
5217 && generic_bignum[parts * 2] != m)
5218 return FAIL;
5219
5220 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
5221 if (generic_bignum[j] != generic_bignum[j-1])
5222 return FAIL;
5223 }
5224
5225 inst.operands[i].imm = 0;
5226 for (j = 0; j < parts; j++, idx++)
5227 inst.operands[i].imm |= ((unsigned) generic_bignum[idx]
5228 << (LITTLENUM_NUMBER_OF_BITS * j));
5229 inst.operands[i].reg = 0;
5230 for (j = 0; j < parts; j++, idx++)
5231 inst.operands[i].reg |= ((unsigned) generic_bignum[idx]
5232 << (LITTLENUM_NUMBER_OF_BITS * j));
5233 inst.operands[i].regisimm = 1;
5234 }
5235 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5236 return FAIL;
5237
5238 *str = ptr;
5239
5240 return SUCCESS;
5241 }
5242
5243 /* Returns the pseudo-register number of an FPA immediate constant,
5244 or FAIL if there isn't a valid constant here. */
5245
5246 static int
5247 parse_fpa_immediate (char ** str)
5248 {
5249 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5250 char * save_in;
5251 expressionS exp;
5252 int i;
5253 int j;
5254
5255 /* First try and match exact strings, this is to guarantee
5256 that some formats will work even for cross assembly. */
5257
5258 for (i = 0; fp_const[i]; i++)
5259 {
5260 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
5261 {
5262 char *start = *str;
5263
5264 *str += strlen (fp_const[i]);
5265 if (is_end_of_line[(unsigned char) **str])
5266 return i + 8;
5267 *str = start;
5268 }
5269 }
5270
5271 /* Just because we didn't get a match doesn't mean that the constant
5272 isn't valid, just that it is in a format that we don't
5273 automatically recognize. Try parsing it with the standard
5274 expression routines. */
5275
5276 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
5277
5278 /* Look for a raw floating point number. */
5279 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5280 && is_end_of_line[(unsigned char) *save_in])
5281 {
5282 for (i = 0; i < NUM_FLOAT_VALS; i++)
5283 {
5284 for (j = 0; j < MAX_LITTLENUMS; j++)
5285 {
5286 if (words[j] != fp_values[i][j])
5287 break;
5288 }
5289
5290 if (j == MAX_LITTLENUMS)
5291 {
5292 *str = save_in;
5293 return i + 8;
5294 }
5295 }
5296 }
5297
5298 /* Try and parse a more complex expression, this will probably fail
5299 unless the code uses a floating point prefix (eg "0f"). */
5300 save_in = input_line_pointer;
5301 input_line_pointer = *str;
5302 if (expression (&exp) == absolute_section
5303 && exp.X_op == O_big
5304 && exp.X_add_number < 0)
5305 {
5306 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5307 Ditto for 15. */
5308 #define X_PRECISION 5
5309 #define E_PRECISION 15L
5310 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
5311 {
5312 for (i = 0; i < NUM_FLOAT_VALS; i++)
5313 {
5314 for (j = 0; j < MAX_LITTLENUMS; j++)
5315 {
5316 if (words[j] != fp_values[i][j])
5317 break;
5318 }
5319
5320 if (j == MAX_LITTLENUMS)
5321 {
5322 *str = input_line_pointer;
5323 input_line_pointer = save_in;
5324 return i + 8;
5325 }
5326 }
5327 }
5328 }
5329
5330 *str = input_line_pointer;
5331 input_line_pointer = save_in;
5332 inst.error = _("invalid FPA immediate expression");
5333 return FAIL;
5334 }
5335
5336 /* Returns 1 if a number has "quarter-precision" float format
5337 0baBbbbbbc defgh000 00000000 00000000. */
5338
5339 static int
5340 is_quarter_float (unsigned imm)
5341 {
5342 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5343 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5344 }
5345
5346
5347 /* Detect the presence of a floating point or integer zero constant,
5348 i.e. #0.0 or #0. */
5349
5350 static bool
5351 parse_ifimm_zero (char **in)
5352 {
5353 int error_code;
5354
5355 if (!is_immediate_prefix (**in))
5356 {
5357 /* In unified syntax, all prefixes are optional. */
5358 if (!unified_syntax)
5359 return false;
5360 }
5361 else
5362 ++*in;
5363
5364 /* Accept #0x0 as a synonym for #0. */
5365 if (startswith (*in, "0x"))
5366 {
5367 int val;
5368 if (parse_immediate (in, &val, 0, 0, true) == FAIL)
5369 return false;
5370 return true;
5371 }
5372
5373 error_code = atof_generic (in, ".", EXP_CHARS,
5374 &generic_floating_point_number);
5375
5376 if (!error_code
5377 && generic_floating_point_number.sign == '+'
5378 && (generic_floating_point_number.low
5379 > generic_floating_point_number.leader))
5380 return true;
5381
5382 return false;
5383 }
5384
5385 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5386 0baBbbbbbc defgh000 00000000 00000000.
5387 The zero and minus-zero cases need special handling, since they can't be
5388 encoded in the "quarter-precision" float format, but can nonetheless be
5389 loaded as integer constants. */
5390
5391 static unsigned
5392 parse_qfloat_immediate (char **ccp, int *immed)
5393 {
5394 char *str = *ccp;
5395 char *fpnum;
5396 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5397 int found_fpchar = 0;
5398
5399 skip_past_char (&str, '#');
5400
5401 /* We must not accidentally parse an integer as a floating-point number. Make
5402 sure that the value we parse is not an integer by checking for special
5403 characters '.' or 'e'.
5404 FIXME: This is a horrible hack, but doing better is tricky because type
5405 information isn't in a very usable state at parse time. */
5406 fpnum = str;
5407 skip_whitespace (fpnum);
5408
5409 if (startswith (fpnum, "0x"))
5410 return FAIL;
5411 else
5412 {
5413 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5414 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5415 {
5416 found_fpchar = 1;
5417 break;
5418 }
5419
5420 if (!found_fpchar)
5421 return FAIL;
5422 }
5423
5424 if ((str = atof_ieee (str, 's', words)) != NULL)
5425 {
5426 unsigned fpword = 0;
5427 int i;
5428
5429 /* Our FP word must be 32 bits (single-precision FP). */
5430 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5431 {
5432 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5433 fpword |= words[i];
5434 }
5435
5436 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5437 *immed = fpword;
5438 else
5439 return FAIL;
5440
5441 *ccp = str;
5442
5443 return SUCCESS;
5444 }
5445
5446 return FAIL;
5447 }
5448
5449 /* Shift operands. */
5450 enum shift_kind
5451 {
5452 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
5453 };
5454
5455 struct asm_shift_name
5456 {
5457 const char *name;
5458 enum shift_kind kind;
5459 };
5460
5461 /* Third argument to parse_shift. */
5462 enum parse_shift_mode
5463 {
5464 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5465 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5466 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5467 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5468 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5469 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
5470 };
5471
5472 /* Parse a <shift> specifier on an ARM data processing instruction.
5473 This has three forms:
5474
5475 (LSL|LSR|ASL|ASR|ROR) Rs
5476 (LSL|LSR|ASL|ASR|ROR) #imm
5477 RRX
5478
5479 Note that ASL is assimilated to LSL in the instruction encoding, and
5480 RRX to ROR #0 (which cannot be written as such). */
5481
5482 static int
5483 parse_shift (char **str, int i, enum parse_shift_mode mode)
5484 {
5485 const struct asm_shift_name *shift_name;
5486 enum shift_kind shift;
5487 char *s = *str;
5488 char *p = s;
5489 int reg;
5490
5491 for (p = *str; ISALPHA (*p); p++)
5492 ;
5493
5494 if (p == *str)
5495 {
5496 inst.error = _("shift expression expected");
5497 return FAIL;
5498 }
5499
5500 shift_name
5501 = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str,
5502 p - *str);
5503
5504 if (shift_name == NULL)
5505 {
5506 inst.error = _("shift expression expected");
5507 return FAIL;
5508 }
5509
5510 shift = shift_name->kind;
5511
5512 switch (mode)
5513 {
5514 case NO_SHIFT_RESTRICT:
5515 case SHIFT_IMMEDIATE:
5516 if (shift == SHIFT_UXTW)
5517 {
5518 inst.error = _("'UXTW' not allowed here");
5519 return FAIL;
5520 }
5521 break;
5522
5523 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5524 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5525 {
5526 inst.error = _("'LSL' or 'ASR' required");
5527 return FAIL;
5528 }
5529 break;
5530
5531 case SHIFT_LSL_IMMEDIATE:
5532 if (shift != SHIFT_LSL)
5533 {
5534 inst.error = _("'LSL' required");
5535 return FAIL;
5536 }
5537 break;
5538
5539 case SHIFT_ASR_IMMEDIATE:
5540 if (shift != SHIFT_ASR)
5541 {
5542 inst.error = _("'ASR' required");
5543 return FAIL;
5544 }
5545 break;
5546 case SHIFT_UXTW_IMMEDIATE:
5547 if (shift != SHIFT_UXTW)
5548 {
5549 inst.error = _("'UXTW' required");
5550 return FAIL;
5551 }
5552 break;
5553
5554 default: abort ();
5555 }
5556
5557 if (shift != SHIFT_RRX)
5558 {
5559 /* Whitespace can appear here if the next thing is a bare digit. */
5560 skip_whitespace (p);
5561
5562 if (mode == NO_SHIFT_RESTRICT
5563 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5564 {
5565 inst.operands[i].imm = reg;
5566 inst.operands[i].immisreg = 1;
5567 }
5568 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5569 return FAIL;
5570 }
5571 inst.operands[i].shift_kind = shift;
5572 inst.operands[i].shifted = 1;
5573 *str = p;
5574 return SUCCESS;
5575 }
5576
5577 /* Parse a <shifter_operand> for an ARM data processing instruction:
5578
5579 #<immediate>
5580 #<immediate>, <rotate>
5581 <Rm>
5582 <Rm>, <shift>
5583
5584 where <shift> is defined by parse_shift above, and <rotate> is a
5585 multiple of 2 between 0 and 30. Validation of immediate operands
5586 is deferred to md_apply_fix. */
5587
5588 static int
5589 parse_shifter_operand (char **str, int i)
5590 {
5591 int value;
5592 expressionS exp;
5593
5594 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5595 {
5596 inst.operands[i].reg = value;
5597 inst.operands[i].isreg = 1;
5598
5599 /* parse_shift will override this if appropriate */
5600 inst.relocs[0].exp.X_op = O_constant;
5601 inst.relocs[0].exp.X_add_number = 0;
5602
5603 if (skip_past_comma (str) == FAIL)
5604 return SUCCESS;
5605
5606 /* Shift operation on register. */
5607 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5608 }
5609
5610 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5611 return FAIL;
5612
5613 if (skip_past_comma (str) == SUCCESS)
5614 {
5615 /* #x, y -- ie explicit rotation by Y. */
5616 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5617 return FAIL;
5618
5619 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5620 {
5621 inst.error = _("constant expression expected");
5622 return FAIL;
5623 }
5624
5625 value = exp.X_add_number;
5626 if (value < 0 || value > 30 || value % 2 != 0)
5627 {
5628 inst.error = _("invalid rotation");
5629 return FAIL;
5630 }
5631 if (inst.relocs[0].exp.X_add_number < 0
5632 || inst.relocs[0].exp.X_add_number > 255)
5633 {
5634 inst.error = _("invalid constant");
5635 return FAIL;
5636 }
5637
5638 /* Encode as specified. */
5639 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5640 return SUCCESS;
5641 }
5642
5643 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5644 inst.relocs[0].pc_rel = 0;
5645 return SUCCESS;
5646 }
5647
5648 /* Group relocation information. Each entry in the table contains the
5649 textual name of the relocation as may appear in assembler source
5650 and must end with a colon.
5651 Along with this textual name are the relocation codes to be used if
5652 the corresponding instruction is an ALU instruction (ADD or SUB only),
5653 an LDR, an LDRS, or an LDC. */
5654
5655 struct group_reloc_table_entry
5656 {
5657 const char *name;
5658 int alu_code;
5659 int ldr_code;
5660 int ldrs_code;
5661 int ldc_code;
5662 };
5663
5664 typedef enum
5665 {
5666 /* Varieties of non-ALU group relocation. */
5667
5668 GROUP_LDR,
5669 GROUP_LDRS,
5670 GROUP_LDC,
5671 GROUP_MVE
5672 } group_reloc_type;
5673
5674 static struct group_reloc_table_entry group_reloc_table[] =
5675 { /* Program counter relative: */
5676 { "pc_g0_nc",
5677 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5678 0, /* LDR */
5679 0, /* LDRS */
5680 0 }, /* LDC */
5681 { "pc_g0",
5682 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5683 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5684 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5685 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5686 { "pc_g1_nc",
5687 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5688 0, /* LDR */
5689 0, /* LDRS */
5690 0 }, /* LDC */
5691 { "pc_g1",
5692 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5693 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5694 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5695 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5696 { "pc_g2",
5697 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5698 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5699 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5700 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5701 /* Section base relative */
5702 { "sb_g0_nc",
5703 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5704 0, /* LDR */
5705 0, /* LDRS */
5706 0 }, /* LDC */
5707 { "sb_g0",
5708 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5709 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5710 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5711 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5712 { "sb_g1_nc",
5713 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5714 0, /* LDR */
5715 0, /* LDRS */
5716 0 }, /* LDC */
5717 { "sb_g1",
5718 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5719 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5720 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5721 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5722 { "sb_g2",
5723 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5724 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5725 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5726 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5727 /* Absolute thumb alu relocations. */
5728 { "lower0_7",
5729 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5730 0, /* LDR. */
5731 0, /* LDRS. */
5732 0 }, /* LDC. */
5733 { "lower8_15",
5734 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5735 0, /* LDR. */
5736 0, /* LDRS. */
5737 0 }, /* LDC. */
5738 { "upper0_7",
5739 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5740 0, /* LDR. */
5741 0, /* LDRS. */
5742 0 }, /* LDC. */
5743 { "upper8_15",
5744 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5745 0, /* LDR. */
5746 0, /* LDRS. */
5747 0 } }; /* LDC. */
5748
5749 /* Given the address of a pointer pointing to the textual name of a group
5750 relocation as may appear in assembler source, attempt to find its details
5751 in group_reloc_table. The pointer will be updated to the character after
5752 the trailing colon. On failure, FAIL will be returned; SUCCESS
5753 otherwise. On success, *entry will be updated to point at the relevant
5754 group_reloc_table entry. */
5755
5756 static int
5757 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5758 {
5759 unsigned int i;
5760 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5761 {
5762 int length = strlen (group_reloc_table[i].name);
5763
5764 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5765 && (*str)[length] == ':')
5766 {
5767 *out = &group_reloc_table[i];
5768 *str += (length + 1);
5769 return SUCCESS;
5770 }
5771 }
5772
5773 return FAIL;
5774 }
5775
5776 /* Parse a <shifter_operand> for an ARM data processing instruction
5777 (as for parse_shifter_operand) where group relocations are allowed:
5778
5779 #<immediate>
5780 #<immediate>, <rotate>
5781 #:<group_reloc>:<expression>
5782 <Rm>
5783 <Rm>, <shift>
5784
5785 where <group_reloc> is one of the strings defined in group_reloc_table.
5786 The hashes are optional.
5787
5788 Everything else is as for parse_shifter_operand. */
5789
5790 static parse_operand_result
5791 parse_shifter_operand_group_reloc (char **str, int i)
5792 {
5793 /* Determine if we have the sequence of characters #: or just :
5794 coming next. If we do, then we check for a group relocation.
5795 If we don't, punt the whole lot to parse_shifter_operand. */
5796
5797 if (((*str)[0] == '#' && (*str)[1] == ':')
5798 || (*str)[0] == ':')
5799 {
5800 struct group_reloc_table_entry *entry;
5801
5802 if ((*str)[0] == '#')
5803 (*str) += 2;
5804 else
5805 (*str)++;
5806
5807 /* Try to parse a group relocation. Anything else is an error. */
5808 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5809 {
5810 inst.error = _("unknown group relocation");
5811 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5812 }
5813
5814 /* We now have the group relocation table entry corresponding to
5815 the name in the assembler source. Next, we parse the expression. */
5816 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5817 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5818
5819 /* Record the relocation type (always the ALU variant here). */
5820 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5821 gas_assert (inst.relocs[0].type != 0);
5822
5823 return PARSE_OPERAND_SUCCESS;
5824 }
5825 else
5826 return parse_shifter_operand (str, i) == SUCCESS
5827 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5828
5829 /* Never reached. */
5830 }
5831
5832 /* Parse a Neon alignment expression. Information is written to
5833 inst.operands[i]. We assume the initial ':' has been skipped.
5834
5835 align .imm = align << 8, .immisalign=1, .preind=0 */
5836 static parse_operand_result
5837 parse_neon_alignment (char **str, int i)
5838 {
5839 char *p = *str;
5840 expressionS exp;
5841
5842 my_get_expression (&exp, &p, GE_NO_PREFIX);
5843
5844 if (exp.X_op != O_constant)
5845 {
5846 inst.error = _("alignment must be constant");
5847 return PARSE_OPERAND_FAIL;
5848 }
5849
5850 inst.operands[i].imm = exp.X_add_number << 8;
5851 inst.operands[i].immisalign = 1;
5852 /* Alignments are not pre-indexes. */
5853 inst.operands[i].preind = 0;
5854
5855 *str = p;
5856 return PARSE_OPERAND_SUCCESS;
5857 }
5858
5859 /* Parse all forms of an ARM address expression. Information is written
5860 to inst.operands[i] and/or inst.relocs[0].
5861
5862 Preindexed addressing (.preind=1):
5863
5864 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5865 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5866 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5867 .shift_kind=shift .relocs[0].exp=shift_imm
5868
5869 These three may have a trailing ! which causes .writeback to be set also.
5870
5871 Postindexed addressing (.postind=1, .writeback=1):
5872
5873 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5874 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5875 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5876 .shift_kind=shift .relocs[0].exp=shift_imm
5877
5878 Unindexed addressing (.preind=0, .postind=0):
5879
5880 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5881
5882 Other:
5883
5884 [Rn]{!} shorthand for [Rn,#0]{!}
5885 =immediate .isreg=0 .relocs[0].exp=immediate
5886 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5887
5888 It is the caller's responsibility to check for addressing modes not
5889 supported by the instruction, and to set inst.relocs[0].type. */
5890
5891 static parse_operand_result
5892 parse_address_main (char **str, int i, int group_relocations,
5893 group_reloc_type group_type)
5894 {
5895 char *p = *str;
5896 int reg;
5897
5898 if (skip_past_char (&p, '[') == FAIL)
5899 {
5900 if (group_type == GROUP_MVE
5901 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5902 {
5903 /* [r0-r15] expected as argument but receiving r0-r15 without
5904 [] brackets. */
5905 inst.error = BAD_SYNTAX;
5906 return PARSE_OPERAND_FAIL;
5907 }
5908 else if (skip_past_char (&p, '=') == FAIL)
5909 {
5910 /* Bare address - translate to PC-relative offset. */
5911 inst.relocs[0].pc_rel = 1;
5912 inst.operands[i].reg = REG_PC;
5913 inst.operands[i].isreg = 1;
5914 inst.operands[i].preind = 1;
5915
5916 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5917 return PARSE_OPERAND_FAIL;
5918 }
5919 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5920 /*allow_symbol_p=*/true))
5921 return PARSE_OPERAND_FAIL;
5922
5923 *str = p;
5924 return PARSE_OPERAND_SUCCESS;
5925 }
5926
5927 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5928 skip_whitespace (p);
5929
5930 if (group_type == GROUP_MVE)
5931 {
5932 enum arm_reg_type rtype = REG_TYPE_MQ;
5933 struct neon_type_el et;
5934 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5935 {
5936 inst.operands[i].isquad = 1;
5937 }
5938 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5939 {
5940 inst.error = BAD_ADDR_MODE;
5941 return PARSE_OPERAND_FAIL;
5942 }
5943 }
5944 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5945 {
5946 if (group_type == GROUP_MVE)
5947 inst.error = BAD_ADDR_MODE;
5948 else
5949 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5950 return PARSE_OPERAND_FAIL;
5951 }
5952 inst.operands[i].reg = reg;
5953 inst.operands[i].isreg = 1;
5954
5955 if (skip_past_comma (&p) == SUCCESS)
5956 {
5957 inst.operands[i].preind = 1;
5958
5959 if (*p == '+') p++;
5960 else if (*p == '-') p++, inst.operands[i].negative = 1;
5961
5962 enum arm_reg_type rtype = REG_TYPE_MQ;
5963 struct neon_type_el et;
5964 if (group_type == GROUP_MVE
5965 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5966 {
5967 inst.operands[i].immisreg = 2;
5968 inst.operands[i].imm = reg;
5969
5970 if (skip_past_comma (&p) == SUCCESS)
5971 {
5972 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
5973 {
5974 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
5975 inst.relocs[0].exp.X_add_number = 0;
5976 }
5977 else
5978 return PARSE_OPERAND_FAIL;
5979 }
5980 }
5981 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5982 {
5983 inst.operands[i].imm = reg;
5984 inst.operands[i].immisreg = 1;
5985
5986 if (skip_past_comma (&p) == SUCCESS)
5987 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5988 return PARSE_OPERAND_FAIL;
5989 }
5990 else if (skip_past_char (&p, ':') == SUCCESS)
5991 {
5992 /* FIXME: '@' should be used here, but it's filtered out by generic
5993 code before we get to see it here. This may be subject to
5994 change. */
5995 parse_operand_result result = parse_neon_alignment (&p, i);
5996
5997 if (result != PARSE_OPERAND_SUCCESS)
5998 return result;
5999 }
6000 else
6001 {
6002 if (inst.operands[i].negative)
6003 {
6004 inst.operands[i].negative = 0;
6005 p--;
6006 }
6007
6008 if (group_relocations
6009 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
6010 {
6011 struct group_reloc_table_entry *entry;
6012
6013 /* Skip over the #: or : sequence. */
6014 if (*p == '#')
6015 p += 2;
6016 else
6017 p++;
6018
6019 /* Try to parse a group relocation. Anything else is an
6020 error. */
6021 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
6022 {
6023 inst.error = _("unknown group relocation");
6024 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6025 }
6026
6027 /* We now have the group relocation table entry corresponding to
6028 the name in the assembler source. Next, we parse the
6029 expression. */
6030 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6031 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6032
6033 /* Record the relocation type. */
6034 switch (group_type)
6035 {
6036 case GROUP_LDR:
6037 inst.relocs[0].type
6038 = (bfd_reloc_code_real_type) entry->ldr_code;
6039 break;
6040
6041 case GROUP_LDRS:
6042 inst.relocs[0].type
6043 = (bfd_reloc_code_real_type) entry->ldrs_code;
6044 break;
6045
6046 case GROUP_LDC:
6047 inst.relocs[0].type
6048 = (bfd_reloc_code_real_type) entry->ldc_code;
6049 break;
6050
6051 default:
6052 gas_assert (0);
6053 }
6054
6055 if (inst.relocs[0].type == 0)
6056 {
6057 inst.error = _("this group relocation is not allowed on this instruction");
6058 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
6059 }
6060 }
6061 else
6062 {
6063 char *q = p;
6064
6065 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6066 return PARSE_OPERAND_FAIL;
6067 /* If the offset is 0, find out if it's a +0 or -0. */
6068 if (inst.relocs[0].exp.X_op == O_constant
6069 && inst.relocs[0].exp.X_add_number == 0)
6070 {
6071 skip_whitespace (q);
6072 if (*q == '#')
6073 {
6074 q++;
6075 skip_whitespace (q);
6076 }
6077 if (*q == '-')
6078 inst.operands[i].negative = 1;
6079 }
6080 }
6081 }
6082 }
6083 else if (skip_past_char (&p, ':') == SUCCESS)
6084 {
6085 /* FIXME: '@' should be used here, but it's filtered out by generic code
6086 before we get to see it here. This may be subject to change. */
6087 parse_operand_result result = parse_neon_alignment (&p, i);
6088
6089 if (result != PARSE_OPERAND_SUCCESS)
6090 return result;
6091 }
6092
6093 if (skip_past_char (&p, ']') == FAIL)
6094 {
6095 inst.error = _("']' expected");
6096 return PARSE_OPERAND_FAIL;
6097 }
6098
6099 if (skip_past_char (&p, '!') == SUCCESS)
6100 inst.operands[i].writeback = 1;
6101
6102 else if (skip_past_comma (&p) == SUCCESS)
6103 {
6104 if (skip_past_char (&p, '{') == SUCCESS)
6105 {
6106 /* [Rn], {expr} - unindexed, with option */
6107 if (parse_immediate (&p, &inst.operands[i].imm,
6108 0, 255, true) == FAIL)
6109 return PARSE_OPERAND_FAIL;
6110
6111 if (skip_past_char (&p, '}') == FAIL)
6112 {
6113 inst.error = _("'}' expected at end of 'option' field");
6114 return PARSE_OPERAND_FAIL;
6115 }
6116 if (inst.operands[i].preind)
6117 {
6118 inst.error = _("cannot combine index with option");
6119 return PARSE_OPERAND_FAIL;
6120 }
6121 *str = p;
6122 return PARSE_OPERAND_SUCCESS;
6123 }
6124 else
6125 {
6126 inst.operands[i].postind = 1;
6127 inst.operands[i].writeback = 1;
6128
6129 if (inst.operands[i].preind)
6130 {
6131 inst.error = _("cannot combine pre- and post-indexing");
6132 return PARSE_OPERAND_FAIL;
6133 }
6134
6135 if (*p == '+') p++;
6136 else if (*p == '-') p++, inst.operands[i].negative = 1;
6137
6138 enum arm_reg_type rtype = REG_TYPE_MQ;
6139 struct neon_type_el et;
6140 if (group_type == GROUP_MVE
6141 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6142 {
6143 inst.operands[i].immisreg = 2;
6144 inst.operands[i].imm = reg;
6145 }
6146 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6147 {
6148 /* We might be using the immediate for alignment already. If we
6149 are, OR the register number into the low-order bits. */
6150 if (inst.operands[i].immisalign)
6151 inst.operands[i].imm |= reg;
6152 else
6153 inst.operands[i].imm = reg;
6154 inst.operands[i].immisreg = 1;
6155
6156 if (skip_past_comma (&p) == SUCCESS)
6157 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6158 return PARSE_OPERAND_FAIL;
6159 }
6160 else
6161 {
6162 char *q = p;
6163
6164 if (inst.operands[i].negative)
6165 {
6166 inst.operands[i].negative = 0;
6167 p--;
6168 }
6169 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6170 return PARSE_OPERAND_FAIL;
6171 /* If the offset is 0, find out if it's a +0 or -0. */
6172 if (inst.relocs[0].exp.X_op == O_constant
6173 && inst.relocs[0].exp.X_add_number == 0)
6174 {
6175 skip_whitespace (q);
6176 if (*q == '#')
6177 {
6178 q++;
6179 skip_whitespace (q);
6180 }
6181 if (*q == '-')
6182 inst.operands[i].negative = 1;
6183 }
6184 }
6185 }
6186 }
6187
6188 /* If at this point neither .preind nor .postind is set, we have a
6189 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6190 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6191 {
6192 inst.operands[i].preind = 1;
6193 inst.relocs[0].exp.X_op = O_constant;
6194 inst.relocs[0].exp.X_add_number = 0;
6195 }
6196 *str = p;
6197 return PARSE_OPERAND_SUCCESS;
6198 }
6199
6200 static int
6201 parse_address (char **str, int i)
6202 {
6203 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
6204 ? SUCCESS : FAIL;
6205 }
6206
6207 static parse_operand_result
6208 parse_address_group_reloc (char **str, int i, group_reloc_type type)
6209 {
6210 return parse_address_main (str, i, 1, type);
6211 }
6212
6213 /* Parse an operand for a MOVW or MOVT instruction. */
6214 static int
6215 parse_half (char **str)
6216 {
6217 char * p;
6218
6219 p = *str;
6220 skip_past_char (&p, '#');
6221 if (strncasecmp (p, ":lower16:", 9) == 0)
6222 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
6223 else if (strncasecmp (p, ":upper16:", 9) == 0)
6224 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
6225
6226 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
6227 {
6228 p += 9;
6229 skip_whitespace (p);
6230 }
6231
6232 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6233 return FAIL;
6234
6235 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
6236 {
6237 if (inst.relocs[0].exp.X_op != O_constant)
6238 {
6239 inst.error = _("constant expression expected");
6240 return FAIL;
6241 }
6242 if (inst.relocs[0].exp.X_add_number < 0
6243 || inst.relocs[0].exp.X_add_number > 0xffff)
6244 {
6245 inst.error = _("immediate value out of range");
6246 return FAIL;
6247 }
6248 }
6249 *str = p;
6250 return SUCCESS;
6251 }
6252
6253 /* Miscellaneous. */
6254
6255 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6256 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6257 static int
6258 parse_psr (char **str, bool lhs)
6259 {
6260 char *p;
6261 unsigned long psr_field;
6262 const struct asm_psr *psr;
6263 char *start;
6264 bool is_apsr = false;
6265 bool m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
6266
6267 /* PR gas/12698: If the user has specified -march=all then m_profile will
6268 be TRUE, but we want to ignore it in this case as we are building for any
6269 CPU type, including non-m variants. */
6270 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
6271 m_profile = false;
6272
6273 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6274 feature for ease of use and backwards compatibility. */
6275 p = *str;
6276 if (strncasecmp (p, "SPSR", 4) == 0)
6277 {
6278 if (m_profile)
6279 goto unsupported_psr;
6280
6281 psr_field = SPSR_BIT;
6282 }
6283 else if (strncasecmp (p, "CPSR", 4) == 0)
6284 {
6285 if (m_profile)
6286 goto unsupported_psr;
6287
6288 psr_field = 0;
6289 }
6290 else if (strncasecmp (p, "APSR", 4) == 0)
6291 {
6292 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6293 and ARMv7-R architecture CPUs. */
6294 is_apsr = true;
6295 psr_field = 0;
6296 }
6297 else if (m_profile)
6298 {
6299 start = p;
6300 do
6301 p++;
6302 while (ISALNUM (*p) || *p == '_');
6303
6304 if (strncasecmp (start, "iapsr", 5) == 0
6305 || strncasecmp (start, "eapsr", 5) == 0
6306 || strncasecmp (start, "xpsr", 4) == 0
6307 || strncasecmp (start, "psr", 3) == 0)
6308 p = start + strcspn (start, "rR") + 1;
6309
6310 psr = (const struct asm_psr *) str_hash_find_n (arm_v7m_psr_hsh, start,
6311 p - start);
6312
6313 if (!psr)
6314 return FAIL;
6315
6316 /* If APSR is being written, a bitfield may be specified. Note that
6317 APSR itself is handled above. */
6318 if (psr->field <= 3)
6319 {
6320 psr_field = psr->field;
6321 is_apsr = true;
6322 goto check_suffix;
6323 }
6324
6325 *str = p;
6326 /* M-profile MSR instructions have the mask field set to "10", except
6327 *PSR variants which modify APSR, which may use a different mask (and
6328 have been handled already). Do that by setting the PSR_f field
6329 here. */
6330 return psr->field | (lhs ? PSR_f : 0);
6331 }
6332 else
6333 goto unsupported_psr;
6334
6335 p += 4;
6336 check_suffix:
6337 if (*p == '_')
6338 {
6339 /* A suffix follows. */
6340 p++;
6341 start = p;
6342
6343 do
6344 p++;
6345 while (ISALNUM (*p) || *p == '_');
6346
6347 if (is_apsr)
6348 {
6349 /* APSR uses a notation for bits, rather than fields. */
6350 unsigned int nzcvq_bits = 0;
6351 unsigned int g_bit = 0;
6352 char *bit;
6353
6354 for (bit = start; bit != p; bit++)
6355 {
6356 switch (TOLOWER (*bit))
6357 {
6358 case 'n':
6359 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6360 break;
6361
6362 case 'z':
6363 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6364 break;
6365
6366 case 'c':
6367 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6368 break;
6369
6370 case 'v':
6371 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6372 break;
6373
6374 case 'q':
6375 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6376 break;
6377
6378 case 'g':
6379 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6380 break;
6381
6382 default:
6383 inst.error = _("unexpected bit specified after APSR");
6384 return FAIL;
6385 }
6386 }
6387
6388 if (nzcvq_bits == 0x1f)
6389 psr_field |= PSR_f;
6390
6391 if (g_bit == 0x1)
6392 {
6393 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
6394 {
6395 inst.error = _("selected processor does not "
6396 "support DSP extension");
6397 return FAIL;
6398 }
6399
6400 psr_field |= PSR_s;
6401 }
6402
6403 if ((nzcvq_bits & 0x20) != 0
6404 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6405 || (g_bit & 0x2) != 0)
6406 {
6407 inst.error = _("bad bitmask specified after APSR");
6408 return FAIL;
6409 }
6410 }
6411 else
6412 {
6413 psr = (const struct asm_psr *) str_hash_find_n (arm_psr_hsh, start,
6414 p - start);
6415 if (!psr)
6416 goto error;
6417
6418 psr_field |= psr->field;
6419 }
6420 }
6421 else
6422 {
6423 if (ISALNUM (*p))
6424 goto error; /* Garbage after "[CS]PSR". */
6425
6426 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6427 is deprecated, but allow it anyway. */
6428 if (is_apsr && lhs)
6429 {
6430 psr_field |= PSR_f;
6431 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6432 "deprecated"));
6433 }
6434 else if (!m_profile)
6435 /* These bits are never right for M-profile devices: don't set them
6436 (only code paths which read/write APSR reach here). */
6437 psr_field |= (PSR_c | PSR_f);
6438 }
6439 *str = p;
6440 return psr_field;
6441
6442 unsupported_psr:
6443 inst.error = _("selected processor does not support requested special "
6444 "purpose register");
6445 return FAIL;
6446
6447 error:
6448 inst.error = _("flag for {c}psr instruction expected");
6449 return FAIL;
6450 }
6451
6452 static int
6453 parse_sys_vldr_vstr (char **str)
6454 {
6455 unsigned i;
6456 int val = FAIL;
6457 struct {
6458 const char *name;
6459 int regl;
6460 int regh;
6461 } sysregs[] = {
6462 {"FPSCR", 0x1, 0x0},
6463 {"FPSCR_nzcvqc", 0x2, 0x0},
6464 {"VPR", 0x4, 0x1},
6465 {"P0", 0x5, 0x1},
6466 {"FPCXTNS", 0x6, 0x1},
6467 {"FPCXTS", 0x7, 0x1}
6468 };
6469 char *op_end = strchr (*str, ',');
6470 size_t op_strlen = op_end - *str;
6471
6472 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6473 {
6474 if (!strncmp (*str, sysregs[i].name, op_strlen))
6475 {
6476 val = sysregs[i].regl | (sysregs[i].regh << 3);
6477 *str = op_end;
6478 break;
6479 }
6480 }
6481
6482 return val;
6483 }
6484
6485 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6486 value suitable for splatting into the AIF field of the instruction. */
6487
6488 static int
6489 parse_cps_flags (char **str)
6490 {
6491 int val = 0;
6492 int saw_a_flag = 0;
6493 char *s = *str;
6494
6495 for (;;)
6496 switch (*s++)
6497 {
6498 case '\0': case ',':
6499 goto done;
6500
6501 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6502 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6503 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6504
6505 default:
6506 inst.error = _("unrecognized CPS flag");
6507 return FAIL;
6508 }
6509
6510 done:
6511 if (saw_a_flag == 0)
6512 {
6513 inst.error = _("missing CPS flags");
6514 return FAIL;
6515 }
6516
6517 *str = s - 1;
6518 return val;
6519 }
6520
6521 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6522 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6523
6524 static int
6525 parse_endian_specifier (char **str)
6526 {
6527 int little_endian;
6528 char *s = *str;
6529
6530 if (strncasecmp (s, "BE", 2))
6531 little_endian = 0;
6532 else if (strncasecmp (s, "LE", 2))
6533 little_endian = 1;
6534 else
6535 {
6536 inst.error = _("valid endian specifiers are be or le");
6537 return FAIL;
6538 }
6539
6540 if (ISALNUM (s[2]) || s[2] == '_')
6541 {
6542 inst.error = _("valid endian specifiers are be or le");
6543 return FAIL;
6544 }
6545
6546 *str = s + 2;
6547 return little_endian;
6548 }
6549
6550 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6551 value suitable for poking into the rotate field of an sxt or sxta
6552 instruction, or FAIL on error. */
6553
6554 static int
6555 parse_ror (char **str)
6556 {
6557 int rot;
6558 char *s = *str;
6559
6560 if (strncasecmp (s, "ROR", 3) == 0)
6561 s += 3;
6562 else
6563 {
6564 inst.error = _("missing rotation field after comma");
6565 return FAIL;
6566 }
6567
6568 if (parse_immediate (&s, &rot, 0, 24, false) == FAIL)
6569 return FAIL;
6570
6571 switch (rot)
6572 {
6573 case 0: *str = s; return 0x0;
6574 case 8: *str = s; return 0x1;
6575 case 16: *str = s; return 0x2;
6576 case 24: *str = s; return 0x3;
6577
6578 default:
6579 inst.error = _("rotation can only be 0, 8, 16, or 24");
6580 return FAIL;
6581 }
6582 }
6583
6584 /* Parse a conditional code (from conds[] below). The value returned is in the
6585 range 0 .. 14, or FAIL. */
6586 static int
6587 parse_cond (char **str)
6588 {
6589 char *q;
6590 const struct asm_cond *c;
6591 int n;
6592 /* Condition codes are always 2 characters, so matching up to
6593 3 characters is sufficient. */
6594 char cond[3];
6595
6596 q = *str;
6597 n = 0;
6598 while (ISALPHA (*q) && n < 3)
6599 {
6600 cond[n] = TOLOWER (*q);
6601 q++;
6602 n++;
6603 }
6604
6605 c = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, cond, n);
6606 if (!c)
6607 {
6608 inst.error = _("condition required");
6609 return FAIL;
6610 }
6611
6612 *str = q;
6613 return c->value;
6614 }
6615
6616 /* Parse an option for a barrier instruction. Returns the encoding for the
6617 option, or FAIL. */
6618 static int
6619 parse_barrier (char **str)
6620 {
6621 char *p, *q;
6622 const struct asm_barrier_opt *o;
6623
6624 p = q = *str;
6625 while (ISALPHA (*q))
6626 q++;
6627
6628 o = (const struct asm_barrier_opt *) str_hash_find_n (arm_barrier_opt_hsh, p,
6629 q - p);
6630 if (!o)
6631 return FAIL;
6632
6633 if (!mark_feature_used (&o->arch))
6634 return FAIL;
6635
6636 *str = q;
6637 return o->value;
6638 }
6639
6640 /* Parse the operands of a table branch instruction. Similar to a memory
6641 operand. */
6642 static int
6643 parse_tb (char **str)
6644 {
6645 char * p = *str;
6646 int reg;
6647
6648 if (skip_past_char (&p, '[') == FAIL)
6649 {
6650 inst.error = _("'[' expected");
6651 return FAIL;
6652 }
6653
6654 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6655 {
6656 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6657 return FAIL;
6658 }
6659 inst.operands[0].reg = reg;
6660
6661 if (skip_past_comma (&p) == FAIL)
6662 {
6663 inst.error = _("',' expected");
6664 return FAIL;
6665 }
6666
6667 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6668 {
6669 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6670 return FAIL;
6671 }
6672 inst.operands[0].imm = reg;
6673
6674 if (skip_past_comma (&p) == SUCCESS)
6675 {
6676 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6677 return FAIL;
6678 if (inst.relocs[0].exp.X_add_number != 1)
6679 {
6680 inst.error = _("invalid shift");
6681 return FAIL;
6682 }
6683 inst.operands[0].shifted = 1;
6684 }
6685
6686 if (skip_past_char (&p, ']') == FAIL)
6687 {
6688 inst.error = _("']' expected");
6689 return FAIL;
6690 }
6691 *str = p;
6692 return SUCCESS;
6693 }
6694
6695 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6696 information on the types the operands can take and how they are encoded.
6697 Up to four operands may be read; this function handles setting the
6698 ".present" field for each read operand itself.
6699 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6700 else returns FAIL. */
6701
6702 static int
6703 parse_neon_mov (char **str, int *which_operand)
6704 {
6705 int i = *which_operand, val;
6706 enum arm_reg_type rtype;
6707 char *ptr = *str;
6708 struct neon_type_el optype;
6709
6710 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6711 {
6712 /* Cases 17 or 19. */
6713 inst.operands[i].reg = val;
6714 inst.operands[i].isvec = 1;
6715 inst.operands[i].isscalar = 2;
6716 inst.operands[i].vectype = optype;
6717 inst.operands[i++].present = 1;
6718
6719 if (skip_past_comma (&ptr) == FAIL)
6720 goto wanted_comma;
6721
6722 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6723 {
6724 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6725 inst.operands[i].reg = val;
6726 inst.operands[i].isreg = 1;
6727 inst.operands[i].present = 1;
6728 }
6729 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6730 {
6731 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6732 inst.operands[i].reg = val;
6733 inst.operands[i].isvec = 1;
6734 inst.operands[i].isscalar = 2;
6735 inst.operands[i].vectype = optype;
6736 inst.operands[i++].present = 1;
6737
6738 if (skip_past_comma (&ptr) == FAIL)
6739 goto wanted_comma;
6740
6741 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6742 goto wanted_arm;
6743
6744 inst.operands[i].reg = val;
6745 inst.operands[i].isreg = 1;
6746 inst.operands[i++].present = 1;
6747
6748 if (skip_past_comma (&ptr) == FAIL)
6749 goto wanted_comma;
6750
6751 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6752 goto wanted_arm;
6753
6754 inst.operands[i].reg = val;
6755 inst.operands[i].isreg = 1;
6756 inst.operands[i].present = 1;
6757 }
6758 else
6759 {
6760 first_error (_("expected ARM or MVE vector register"));
6761 return FAIL;
6762 }
6763 }
6764 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6765 {
6766 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6767 inst.operands[i].reg = val;
6768 inst.operands[i].isscalar = 1;
6769 inst.operands[i].vectype = optype;
6770 inst.operands[i++].present = 1;
6771
6772 if (skip_past_comma (&ptr) == FAIL)
6773 goto wanted_comma;
6774
6775 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6776 goto wanted_arm;
6777
6778 inst.operands[i].reg = val;
6779 inst.operands[i].isreg = 1;
6780 inst.operands[i].present = 1;
6781 }
6782 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6783 != FAIL)
6784 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6785 != FAIL))
6786 {
6787 /* Cases 0, 1, 2, 3, 5 (D only). */
6788 if (skip_past_comma (&ptr) == FAIL)
6789 goto wanted_comma;
6790
6791 inst.operands[i].reg = val;
6792 inst.operands[i].isreg = 1;
6793 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6794 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6795 inst.operands[i].isvec = 1;
6796 inst.operands[i].vectype = optype;
6797 inst.operands[i++].present = 1;
6798
6799 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6800 {
6801 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6802 Case 13: VMOV <Sd>, <Rm> */
6803 inst.operands[i].reg = val;
6804 inst.operands[i].isreg = 1;
6805 inst.operands[i].present = 1;
6806
6807 if (rtype == REG_TYPE_NQ)
6808 {
6809 first_error (_("can't use Neon quad register here"));
6810 return FAIL;
6811 }
6812 else if (rtype != REG_TYPE_VFS)
6813 {
6814 i++;
6815 if (skip_past_comma (&ptr) == FAIL)
6816 goto wanted_comma;
6817 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6818 goto wanted_arm;
6819 inst.operands[i].reg = val;
6820 inst.operands[i].isreg = 1;
6821 inst.operands[i].present = 1;
6822 }
6823 }
6824 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6825 &optype)) != FAIL)
6826 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6827 &optype)) != FAIL))
6828 {
6829 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6830 Case 1: VMOV<c><q> <Dd>, <Dm>
6831 Case 8: VMOV.F32 <Sd>, <Sm>
6832 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6833
6834 inst.operands[i].reg = val;
6835 inst.operands[i].isreg = 1;
6836 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6837 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6838 inst.operands[i].isvec = 1;
6839 inst.operands[i].vectype = optype;
6840 inst.operands[i].present = 1;
6841
6842 if (skip_past_comma (&ptr) == SUCCESS)
6843 {
6844 /* Case 15. */
6845 i++;
6846
6847 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6848 goto wanted_arm;
6849
6850 inst.operands[i].reg = val;
6851 inst.operands[i].isreg = 1;
6852 inst.operands[i++].present = 1;
6853
6854 if (skip_past_comma (&ptr) == FAIL)
6855 goto wanted_comma;
6856
6857 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6858 goto wanted_arm;
6859
6860 inst.operands[i].reg = val;
6861 inst.operands[i].isreg = 1;
6862 inst.operands[i].present = 1;
6863 }
6864 }
6865 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6866 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6867 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6868 Case 10: VMOV.F32 <Sd>, #<imm>
6869 Case 11: VMOV.F64 <Dd>, #<imm> */
6870 inst.operands[i].immisfloat = 1;
6871 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/false)
6872 == SUCCESS)
6873 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6874 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6875 ;
6876 else
6877 {
6878 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6879 return FAIL;
6880 }
6881 }
6882 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6883 {
6884 /* Cases 6, 7, 16, 18. */
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 = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6893 {
6894 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6895 inst.operands[i].reg = val;
6896 inst.operands[i].isscalar = 2;
6897 inst.operands[i].present = 1;
6898 inst.operands[i].vectype = optype;
6899 }
6900 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6901 {
6902 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6903 inst.operands[i].reg = val;
6904 inst.operands[i].isscalar = 1;
6905 inst.operands[i].present = 1;
6906 inst.operands[i].vectype = optype;
6907 }
6908 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6909 {
6910 inst.operands[i].reg = val;
6911 inst.operands[i].isreg = 1;
6912 inst.operands[i++].present = 1;
6913
6914 if (skip_past_comma (&ptr) == FAIL)
6915 goto wanted_comma;
6916
6917 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6918 != FAIL)
6919 {
6920 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6921
6922 inst.operands[i].reg = val;
6923 inst.operands[i].isreg = 1;
6924 inst.operands[i].isvec = 1;
6925 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6926 inst.operands[i].vectype = optype;
6927 inst.operands[i].present = 1;
6928
6929 if (rtype == REG_TYPE_VFS)
6930 {
6931 /* Case 14. */
6932 i++;
6933 if (skip_past_comma (&ptr) == FAIL)
6934 goto wanted_comma;
6935 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6936 &optype)) == FAIL)
6937 {
6938 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6939 return FAIL;
6940 }
6941 inst.operands[i].reg = val;
6942 inst.operands[i].isreg = 1;
6943 inst.operands[i].isvec = 1;
6944 inst.operands[i].issingle = 1;
6945 inst.operands[i].vectype = optype;
6946 inst.operands[i].present = 1;
6947 }
6948 }
6949 else
6950 {
6951 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6952 != FAIL)
6953 {
6954 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6955 inst.operands[i].reg = val;
6956 inst.operands[i].isvec = 1;
6957 inst.operands[i].isscalar = 2;
6958 inst.operands[i].vectype = optype;
6959 inst.operands[i++].present = 1;
6960
6961 if (skip_past_comma (&ptr) == FAIL)
6962 goto wanted_comma;
6963
6964 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6965 == FAIL)
6966 {
6967 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6968 return FAIL;
6969 }
6970 inst.operands[i].reg = val;
6971 inst.operands[i].isvec = 1;
6972 inst.operands[i].isscalar = 2;
6973 inst.operands[i].vectype = optype;
6974 inst.operands[i].present = 1;
6975 }
6976 else
6977 {
6978 first_error (_("VFP single, double or MVE vector register"
6979 " expected"));
6980 return FAIL;
6981 }
6982 }
6983 }
6984 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6985 != FAIL)
6986 {
6987 /* Case 13. */
6988 inst.operands[i].reg = val;
6989 inst.operands[i].isreg = 1;
6990 inst.operands[i].isvec = 1;
6991 inst.operands[i].issingle = 1;
6992 inst.operands[i].vectype = optype;
6993 inst.operands[i].present = 1;
6994 }
6995 }
6996 else
6997 {
6998 first_error (_("parse error"));
6999 return FAIL;
7000 }
7001
7002 /* Successfully parsed the operands. Update args. */
7003 *which_operand = i;
7004 *str = ptr;
7005 return SUCCESS;
7006
7007 wanted_comma:
7008 first_error (_("expected comma"));
7009 return FAIL;
7010
7011 wanted_arm:
7012 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
7013 return FAIL;
7014 }
7015
7016 /* Use this macro when the operand constraints are different
7017 for ARM and THUMB (e.g. ldrd). */
7018 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
7019 ((arm_operand) | ((thumb_operand) << 16))
7020
7021 /* Matcher codes for parse_operands. */
7022 enum operand_parse_code
7023 {
7024 OP_stop, /* end of line */
7025
7026 OP_RR, /* ARM register */
7027 OP_RRnpc, /* ARM register, not r15 */
7028 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
7029 OP_RRnpcb, /* ARM register, not r15, in square brackets */
7030 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
7031 optional trailing ! */
7032 OP_RRw, /* ARM register, not r15, optional trailing ! */
7033 OP_RCP, /* Coprocessor number */
7034 OP_RCN, /* Coprocessor register */
7035 OP_RF, /* FPA register */
7036 OP_RVS, /* VFP single precision register */
7037 OP_RVD, /* VFP double precision register (0..15) */
7038 OP_RND, /* Neon double precision register (0..31) */
7039 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
7040 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
7041 */
7042 OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register.
7043 */
7044 OP_RNQ, /* Neon quad precision register */
7045 OP_RNQMQ, /* Neon quad or MVE vector register. */
7046 OP_RVSD, /* VFP single or double precision register */
7047 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
7048 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
7049 OP_RNSD, /* Neon single or double precision register */
7050 OP_RNDQ, /* Neon double or quad precision register */
7051 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
7052 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
7053 OP_RNSDQ, /* Neon single, double or quad precision register */
7054 OP_RNSC, /* Neon scalar D[X] */
7055 OP_RVC, /* VFP control register */
7056 OP_RMF, /* Maverick F register */
7057 OP_RMD, /* Maverick D register */
7058 OP_RMFX, /* Maverick FX register */
7059 OP_RMDX, /* Maverick DX register */
7060 OP_RMAX, /* Maverick AX register */
7061 OP_RMDS, /* Maverick DSPSC register */
7062 OP_RIWR, /* iWMMXt wR register */
7063 OP_RIWC, /* iWMMXt wC register */
7064 OP_RIWG, /* iWMMXt wCG register */
7065 OP_RXA, /* XScale accumulator register */
7066
7067 OP_RNSDMQ, /* Neon single, double or MVE vector register */
7068 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
7069 */
7070 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
7071 GPR (no SP/SP) */
7072 OP_RMQ, /* MVE vector register. */
7073 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
7074 OP_RMQRR, /* MVE vector or ARM register. */
7075
7076 /* New operands for Armv8.1-M Mainline. */
7077 OP_LR, /* ARM LR register */
7078 OP_SP, /* ARM SP register */
7079 OP_R12,
7080 OP_RRe, /* ARM register, only even numbered. */
7081 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
7082 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
7083 OP_RR_ZR, /* ARM register or ZR but no PC */
7084
7085 OP_REGLST, /* ARM register list */
7086 OP_CLRMLST, /* CLRM register list */
7087 OP_VRSLST, /* VFP single-precision register list */
7088 OP_VRDLST, /* VFP double-precision register list */
7089 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
7090 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7091 OP_NSTRLST, /* Neon element/structure list */
7092 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
7093 OP_MSTRLST2, /* MVE vector list with two elements. */
7094 OP_MSTRLST4, /* MVE vector list with four elements. */
7095
7096 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
7097 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
7098 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
7099 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7100 zero. */
7101 OP_RR_RNSC, /* ARM reg or Neon scalar. */
7102 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
7103 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
7104 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7105 */
7106 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7107 scalar, or ARM register. */
7108 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
7109 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7110 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7111 register. */
7112 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
7113 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7114 OP_VMOV, /* Neon VMOV operands. */
7115 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
7116 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7117 OP_RNDQMQ_Ibig,
7118 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
7119 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7120 ARM register. */
7121 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
7122 OP_VLDR, /* VLDR operand. */
7123
7124 OP_I0, /* immediate zero */
7125 OP_I7, /* immediate value 0 .. 7 */
7126 OP_I15, /* 0 .. 15 */
7127 OP_I16, /* 1 .. 16 */
7128 OP_I16z, /* 0 .. 16 */
7129 OP_I31, /* 0 .. 31 */
7130 OP_I31w, /* 0 .. 31, optional trailing ! */
7131 OP_I32, /* 1 .. 32 */
7132 OP_I32z, /* 0 .. 32 */
7133 OP_I48_I64, /* 48 or 64 */
7134 OP_I63, /* 0 .. 63 */
7135 OP_I63s, /* -64 .. 63 */
7136 OP_I64, /* 1 .. 64 */
7137 OP_I64z, /* 0 .. 64 */
7138 OP_I127, /* 0 .. 127 */
7139 OP_I255, /* 0 .. 255 */
7140 OP_I511, /* 0 .. 511 */
7141 OP_I4095, /* 0 .. 4095 */
7142 OP_I8191, /* 0 .. 8191 */
7143 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7144 OP_I7b, /* 0 .. 7 */
7145 OP_I15b, /* 0 .. 15 */
7146 OP_I31b, /* 0 .. 31 */
7147
7148 OP_SH, /* shifter operand */
7149 OP_SHG, /* shifter operand with possible group relocation */
7150 OP_ADDR, /* Memory address expression (any mode) */
7151 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
7152 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7153 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7154 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
7155 OP_EXP, /* arbitrary expression */
7156 OP_EXPi, /* same, with optional immediate prefix */
7157 OP_EXPr, /* same, with optional relocation suffix */
7158 OP_EXPs, /* same, with optional non-first operand relocation suffix */
7159 OP_HALF, /* 0 .. 65535 or low/high reloc. */
7160 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7161 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
7162
7163 OP_CPSF, /* CPS flags */
7164 OP_ENDI, /* Endianness specifier */
7165 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7166 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
7167 OP_COND, /* conditional code */
7168 OP_TB, /* Table branch. */
7169
7170 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7171
7172 OP_RRnpc_I0, /* ARM register or literal 0 */
7173 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
7174 OP_RR_EXi, /* ARM register or expression with imm prefix */
7175 OP_RF_IF, /* FPA register or immediate */
7176 OP_RIWR_RIWC, /* iWMMXt R or C reg */
7177 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
7178
7179 /* Optional operands. */
7180 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7181 OP_oI31b, /* 0 .. 31 */
7182 OP_oI32b, /* 1 .. 32 */
7183 OP_oI32z, /* 0 .. 32 */
7184 OP_oIffffb, /* 0 .. 65535 */
7185 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7186
7187 OP_oRR, /* ARM register */
7188 OP_oLR, /* ARM LR register */
7189 OP_oRRnpc, /* ARM register, not the PC */
7190 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
7191 OP_oRRw, /* ARM register, not r15, optional trailing ! */
7192 OP_oRND, /* Optional Neon double precision register */
7193 OP_oRNQ, /* Optional Neon quad precision register */
7194 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
7195 OP_oRNDQ, /* Optional Neon double or quad precision register */
7196 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
7197 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7198 register. */
7199 OP_oRNSDMQ, /* Optional single, double register or MVE vector
7200 register. */
7201 OP_oSHll, /* LSL immediate */
7202 OP_oSHar, /* ASR immediate */
7203 OP_oSHllar, /* LSL or ASR immediate */
7204 OP_oROR, /* ROR 0/8/16/24 */
7205 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
7206
7207 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7208
7209 /* Some pre-defined mixed (ARM/THUMB) operands. */
7210 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7211 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7212 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7213
7214 OP_FIRST_OPTIONAL = OP_oI7b
7215 };
7216
7217 /* Generic instruction operand parser. This does no encoding and no
7218 semantic validation; it merely squirrels values away in the inst
7219 structure. Returns SUCCESS or FAIL depending on whether the
7220 specified grammar matched. */
7221 static int
7222 parse_operands (char *str, const unsigned int *pattern, bool thumb)
7223 {
7224 unsigned const int *upat = pattern;
7225 char *backtrack_pos = 0;
7226 const char *backtrack_error = 0;
7227 int i, val = 0, backtrack_index = 0;
7228 enum arm_reg_type rtype;
7229 parse_operand_result result;
7230 unsigned int op_parse_code;
7231 bool partial_match;
7232
7233 #define po_char_or_fail(chr) \
7234 do \
7235 { \
7236 if (skip_past_char (&str, chr) == FAIL) \
7237 goto bad_args; \
7238 } \
7239 while (0)
7240
7241 #define po_reg_or_fail(regtype) \
7242 do \
7243 { \
7244 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7245 & inst.operands[i].vectype); \
7246 if (val == FAIL) \
7247 { \
7248 first_error (_(reg_expected_msgs[regtype])); \
7249 goto failure; \
7250 } \
7251 inst.operands[i].reg = val; \
7252 inst.operands[i].isreg = 1; \
7253 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7254 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7255 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7256 || rtype == REG_TYPE_VFD \
7257 || rtype == REG_TYPE_NQ); \
7258 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7259 } \
7260 while (0)
7261
7262 #define po_reg_or_goto(regtype, label) \
7263 do \
7264 { \
7265 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7266 & inst.operands[i].vectype); \
7267 if (val == FAIL) \
7268 goto label; \
7269 \
7270 inst.operands[i].reg = val; \
7271 inst.operands[i].isreg = 1; \
7272 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7273 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7274 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7275 || rtype == REG_TYPE_VFD \
7276 || rtype == REG_TYPE_NQ); \
7277 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7278 } \
7279 while (0)
7280
7281 #define po_imm_or_fail(min, max, popt) \
7282 do \
7283 { \
7284 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7285 goto failure; \
7286 inst.operands[i].imm = val; \
7287 } \
7288 while (0)
7289
7290 #define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7291 do \
7292 { \
7293 expressionS exp; \
7294 my_get_expression (&exp, &str, popt); \
7295 if (exp.X_op != O_constant) \
7296 { \
7297 inst.error = _("constant expression required"); \
7298 goto failure; \
7299 } \
7300 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7301 { \
7302 inst.error = _("immediate value 48 or 64 expected"); \
7303 goto failure; \
7304 } \
7305 inst.operands[i].imm = exp.X_add_number; \
7306 } \
7307 while (0)
7308
7309 #define po_scalar_or_goto(elsz, label, reg_type) \
7310 do \
7311 { \
7312 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7313 reg_type); \
7314 if (val == FAIL) \
7315 goto label; \
7316 inst.operands[i].reg = val; \
7317 inst.operands[i].isscalar = 1; \
7318 } \
7319 while (0)
7320
7321 #define po_misc_or_fail(expr) \
7322 do \
7323 { \
7324 if (expr) \
7325 goto failure; \
7326 } \
7327 while (0)
7328
7329 #define po_misc_or_fail_no_backtrack(expr) \
7330 do \
7331 { \
7332 result = expr; \
7333 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7334 backtrack_pos = 0; \
7335 if (result != PARSE_OPERAND_SUCCESS) \
7336 goto failure; \
7337 } \
7338 while (0)
7339
7340 #define po_barrier_or_imm(str) \
7341 do \
7342 { \
7343 val = parse_barrier (&str); \
7344 if (val == FAIL && ! ISALPHA (*str)) \
7345 goto immediate; \
7346 if (val == FAIL \
7347 /* ISB can only take SY as an option. */ \
7348 || ((inst.instruction & 0xf0) == 0x60 \
7349 && val != 0xf)) \
7350 { \
7351 inst.error = _("invalid barrier type"); \
7352 backtrack_pos = 0; \
7353 goto failure; \
7354 } \
7355 } \
7356 while (0)
7357
7358 skip_whitespace (str);
7359
7360 for (i = 0; upat[i] != OP_stop; i++)
7361 {
7362 op_parse_code = upat[i];
7363 if (op_parse_code >= 1<<16)
7364 op_parse_code = thumb ? (op_parse_code >> 16)
7365 : (op_parse_code & ((1<<16)-1));
7366
7367 if (op_parse_code >= OP_FIRST_OPTIONAL)
7368 {
7369 /* Remember where we are in case we need to backtrack. */
7370 backtrack_pos = str;
7371 backtrack_error = inst.error;
7372 backtrack_index = i;
7373 }
7374
7375 if (i > 0 && (i > 1 || inst.operands[0].present))
7376 po_char_or_fail (',');
7377
7378 switch (op_parse_code)
7379 {
7380 /* Registers */
7381 case OP_oRRnpc:
7382 case OP_oRRnpcsp:
7383 case OP_RRnpc:
7384 case OP_RRnpcsp:
7385 case OP_oRR:
7386 case OP_RRe:
7387 case OP_RRo:
7388 case OP_LR:
7389 case OP_oLR:
7390 case OP_SP:
7391 case OP_R12:
7392 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7393 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7394 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7395 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7396 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7397 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
7398 case OP_oRND:
7399 case OP_RNSDMQR:
7400 po_reg_or_goto (REG_TYPE_VFS, try_rndmqr);
7401 break;
7402 try_rndmqr:
7403 case OP_RNDMQR:
7404 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7405 break;
7406 try_rndmq:
7407 case OP_RNDMQ:
7408 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7409 break;
7410 try_rnd:
7411 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
7412 case OP_RVC:
7413 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7414 break;
7415 /* Also accept generic coprocessor regs for unknown registers. */
7416 coproc_reg:
7417 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7418 break;
7419 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7420 existing register with a value of 0, this seems like the
7421 best way to parse P0. */
7422 vpr_po:
7423 if (strncasecmp (str, "P0", 2) == 0)
7424 {
7425 str += 2;
7426 inst.operands[i].isreg = 1;
7427 inst.operands[i].reg = 13;
7428 }
7429 else
7430 goto failure;
7431 break;
7432 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7433 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7434 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7435 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7436 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7437 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7438 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7439 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7440 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7441 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
7442 case OP_oRNQ:
7443 case OP_RNQMQ:
7444 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7445 break;
7446 try_nq:
7447 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
7448 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7449 case OP_RNDQMQR:
7450 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7451 break;
7452 try_rndqmq:
7453 case OP_oRNDQMQ:
7454 case OP_RNDQMQ:
7455 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7456 break;
7457 try_rndq:
7458 case OP_oRNDQ:
7459 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
7460 case OP_RVSDMQ:
7461 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7462 break;
7463 try_rvsd:
7464 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7465 case OP_RVSD_COND:
7466 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7467 break;
7468 case OP_oRNSDMQ:
7469 case OP_RNSDMQ:
7470 po_reg_or_goto (REG_TYPE_NSD, try_mq2);
7471 break;
7472 try_mq2:
7473 po_reg_or_fail (REG_TYPE_MQ);
7474 break;
7475 case OP_oRNSDQ:
7476 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
7477 case OP_RNSDQMQR:
7478 po_reg_or_goto (REG_TYPE_RN, try_mq);
7479 break;
7480 try_mq:
7481 case OP_oRNSDQMQ:
7482 case OP_RNSDQMQ:
7483 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7484 break;
7485 try_nsdq2:
7486 po_reg_or_fail (REG_TYPE_NSDQ);
7487 inst.error = 0;
7488 break;
7489 case OP_RMQRR:
7490 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7491 break;
7492 try_rmq:
7493 case OP_RMQ:
7494 po_reg_or_fail (REG_TYPE_MQ);
7495 break;
7496 /* Neon scalar. Using an element size of 8 means that some invalid
7497 scalars are accepted here, so deal with those in later code. */
7498 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
7499
7500 case OP_RNDQ_I0:
7501 {
7502 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7503 break;
7504 try_imm0:
7505 po_imm_or_fail (0, 0, true);
7506 }
7507 break;
7508
7509 case OP_RVSD_I0:
7510 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7511 break;
7512
7513 case OP_RSVDMQ_FI0:
7514 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7515 break;
7516 try_rsvd_fi0:
7517 case OP_RSVD_FI0:
7518 {
7519 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7520 break;
7521 try_ifimm0:
7522 if (parse_ifimm_zero (&str))
7523 inst.operands[i].imm = 0;
7524 else
7525 {
7526 inst.error
7527 = _("only floating point zero is allowed as immediate value");
7528 goto failure;
7529 }
7530 }
7531 break;
7532
7533 case OP_RR_RNSC:
7534 {
7535 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
7536 break;
7537 try_rr:
7538 po_reg_or_fail (REG_TYPE_RN);
7539 }
7540 break;
7541
7542 case OP_RNSDQ_RNSC_MQ_RR:
7543 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7544 break;
7545 try_rnsdq_rnsc_mq:
7546 case OP_RNSDQ_RNSC_MQ:
7547 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7548 break;
7549 try_rnsdq_rnsc:
7550 case OP_RNSDQ_RNSC:
7551 {
7552 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7553 inst.error = 0;
7554 break;
7555 try_nsdq:
7556 po_reg_or_fail (REG_TYPE_NSDQ);
7557 inst.error = 0;
7558 }
7559 break;
7560
7561 case OP_RNSD_RNSC:
7562 {
7563 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
7564 break;
7565 try_s_scalar:
7566 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
7567 break;
7568 try_nsd:
7569 po_reg_or_fail (REG_TYPE_NSD);
7570 }
7571 break;
7572
7573 case OP_RNDQMQ_RNSC_RR:
7574 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7575 break;
7576 try_rndq_rnsc_rr:
7577 case OP_RNDQ_RNSC_RR:
7578 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7579 break;
7580 case OP_RNDQMQ_RNSC:
7581 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7582 break;
7583 try_rndq_rnsc:
7584 case OP_RNDQ_RNSC:
7585 {
7586 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
7587 break;
7588 try_ndq:
7589 po_reg_or_fail (REG_TYPE_NDQ);
7590 }
7591 break;
7592
7593 case OP_RND_RNSC:
7594 {
7595 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
7596 break;
7597 try_vfd:
7598 po_reg_or_fail (REG_TYPE_VFD);
7599 }
7600 break;
7601
7602 case OP_VMOV:
7603 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7604 not careful then bad things might happen. */
7605 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7606 break;
7607
7608 case OP_RNDQMQ_Ibig:
7609 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7610 break;
7611 try_rndq_ibig:
7612 case OP_RNDQ_Ibig:
7613 {
7614 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7615 break;
7616 try_immbig:
7617 /* There's a possibility of getting a 64-bit immediate here, so
7618 we need special handling. */
7619 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/false)
7620 == FAIL)
7621 {
7622 inst.error = _("immediate value is out of range");
7623 goto failure;
7624 }
7625 }
7626 break;
7627
7628 case OP_RNDQMQ_I63b_RR:
7629 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7630 break;
7631 try_rndq_i63b_rr:
7632 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7633 break;
7634 try_rndq_i63b:
7635 case OP_RNDQ_I63b:
7636 {
7637 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7638 break;
7639 try_shimm:
7640 po_imm_or_fail (0, 63, true);
7641 }
7642 break;
7643
7644 case OP_RRnpcb:
7645 po_char_or_fail ('[');
7646 po_reg_or_fail (REG_TYPE_RN);
7647 po_char_or_fail (']');
7648 break;
7649
7650 case OP_RRnpctw:
7651 case OP_RRw:
7652 case OP_oRRw:
7653 po_reg_or_fail (REG_TYPE_RN);
7654 if (skip_past_char (&str, '!') == SUCCESS)
7655 inst.operands[i].writeback = 1;
7656 break;
7657
7658 /* Immediates */
7659 case OP_I7: po_imm_or_fail ( 0, 7, false); break;
7660 case OP_I15: po_imm_or_fail ( 0, 15, false); break;
7661 case OP_I16: po_imm_or_fail ( 1, 16, false); break;
7662 case OP_I16z: po_imm_or_fail ( 0, 16, false); break;
7663 case OP_I31: po_imm_or_fail ( 0, 31, false); break;
7664 case OP_I32: po_imm_or_fail ( 1, 32, false); break;
7665 case OP_I32z: po_imm_or_fail ( 0, 32, false); break;
7666 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, false); break;
7667 case OP_I63s: po_imm_or_fail (-64, 63, false); break;
7668 case OP_I63: po_imm_or_fail ( 0, 63, false); break;
7669 case OP_I64: po_imm_or_fail ( 1, 64, false); break;
7670 case OP_I64z: po_imm_or_fail ( 0, 64, false); break;
7671 case OP_I127: po_imm_or_fail ( 0, 127, false); break;
7672 case OP_I255: po_imm_or_fail ( 0, 255, false); break;
7673 case OP_I511: po_imm_or_fail ( 0, 511, false); break;
7674 case OP_I4095: po_imm_or_fail ( 0, 4095, false); break;
7675 case OP_I8191: po_imm_or_fail ( 0, 8191, false); break;
7676 case OP_I4b: po_imm_or_fail ( 1, 4, true); break;
7677 case OP_oI7b:
7678 case OP_I7b: po_imm_or_fail ( 0, 7, true); break;
7679 case OP_I15b: po_imm_or_fail ( 0, 15, true); break;
7680 case OP_oI31b:
7681 case OP_I31b: po_imm_or_fail ( 0, 31, true); break;
7682 case OP_oI32b: po_imm_or_fail ( 1, 32, true); break;
7683 case OP_oI32z: po_imm_or_fail ( 0, 32, true); break;
7684 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, true); break;
7685
7686 /* Immediate variants */
7687 case OP_oI255c:
7688 po_char_or_fail ('{');
7689 po_imm_or_fail (0, 255, true);
7690 po_char_or_fail ('}');
7691 break;
7692
7693 case OP_I31w:
7694 /* The expression parser chokes on a trailing !, so we have
7695 to find it first and zap it. */
7696 {
7697 char *s = str;
7698 while (*s && *s != ',')
7699 s++;
7700 if (s[-1] == '!')
7701 {
7702 s[-1] = '\0';
7703 inst.operands[i].writeback = 1;
7704 }
7705 po_imm_or_fail (0, 31, true);
7706 if (str == s - 1)
7707 str = s;
7708 }
7709 break;
7710
7711 /* Expressions */
7712 case OP_EXPi: EXPi:
7713 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7714 GE_OPT_PREFIX));
7715 break;
7716
7717 case OP_EXP:
7718 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7719 GE_NO_PREFIX));
7720 break;
7721
7722 case OP_EXPr: EXPr:
7723 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7724 GE_NO_PREFIX));
7725 if (inst.relocs[0].exp.X_op == O_symbol)
7726 {
7727 val = parse_reloc (&str);
7728 if (val == -1)
7729 {
7730 inst.error = _("unrecognized relocation suffix");
7731 goto failure;
7732 }
7733 else if (val != BFD_RELOC_UNUSED)
7734 {
7735 inst.operands[i].imm = val;
7736 inst.operands[i].hasreloc = 1;
7737 }
7738 }
7739 break;
7740
7741 case OP_EXPs:
7742 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7743 GE_NO_PREFIX));
7744 if (inst.relocs[i].exp.X_op == O_symbol)
7745 {
7746 inst.operands[i].hasreloc = 1;
7747 }
7748 else if (inst.relocs[i].exp.X_op == O_constant)
7749 {
7750 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7751 inst.operands[i].hasreloc = 0;
7752 }
7753 break;
7754
7755 /* Operand for MOVW or MOVT. */
7756 case OP_HALF:
7757 po_misc_or_fail (parse_half (&str));
7758 break;
7759
7760 /* Register or expression. */
7761 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7762 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7763
7764 /* Register or immediate. */
7765 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7766 I0: po_imm_or_fail (0, 0, false); break;
7767
7768 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7769 I32: po_imm_or_fail (1, 32, false); break;
7770
7771 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7772 IF:
7773 if (!is_immediate_prefix (*str))
7774 goto bad_args;
7775 str++;
7776 val = parse_fpa_immediate (&str);
7777 if (val == FAIL)
7778 goto failure;
7779 /* FPA immediates are encoded as registers 8-15.
7780 parse_fpa_immediate has already applied the offset. */
7781 inst.operands[i].reg = val;
7782 inst.operands[i].isreg = 1;
7783 break;
7784
7785 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7786 I32z: po_imm_or_fail (0, 32, false); break;
7787
7788 /* Two kinds of register. */
7789 case OP_RIWR_RIWC:
7790 {
7791 struct reg_entry *rege = arm_reg_parse_multi (&str);
7792 if (!rege
7793 || (rege->type != REG_TYPE_MMXWR
7794 && rege->type != REG_TYPE_MMXWC
7795 && rege->type != REG_TYPE_MMXWCG))
7796 {
7797 inst.error = _("iWMMXt data or control register expected");
7798 goto failure;
7799 }
7800 inst.operands[i].reg = rege->number;
7801 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7802 }
7803 break;
7804
7805 case OP_RIWC_RIWG:
7806 {
7807 struct reg_entry *rege = arm_reg_parse_multi (&str);
7808 if (!rege
7809 || (rege->type != REG_TYPE_MMXWC
7810 && rege->type != REG_TYPE_MMXWCG))
7811 {
7812 inst.error = _("iWMMXt control register expected");
7813 goto failure;
7814 }
7815 inst.operands[i].reg = rege->number;
7816 inst.operands[i].isreg = 1;
7817 }
7818 break;
7819
7820 /* Misc */
7821 case OP_CPSF: val = parse_cps_flags (&str); break;
7822 case OP_ENDI: val = parse_endian_specifier (&str); break;
7823 case OP_oROR: val = parse_ror (&str); break;
7824 try_cond:
7825 case OP_COND: val = parse_cond (&str); break;
7826 case OP_oBARRIER_I15:
7827 po_barrier_or_imm (str); break;
7828 immediate:
7829 if (parse_immediate (&str, &val, 0, 15, true) == FAIL)
7830 goto failure;
7831 break;
7832
7833 case OP_wPSR:
7834 case OP_rPSR:
7835 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7836 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7837 {
7838 inst.error = _("Banked registers are not available with this "
7839 "architecture.");
7840 goto failure;
7841 }
7842 break;
7843 try_psr:
7844 val = parse_psr (&str, op_parse_code == OP_wPSR);
7845 break;
7846
7847 case OP_VLDR:
7848 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7849 break;
7850 try_sysreg:
7851 val = parse_sys_vldr_vstr (&str);
7852 break;
7853
7854 case OP_APSR_RR:
7855 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7856 break;
7857 try_apsr:
7858 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7859 instruction). */
7860 if (strncasecmp (str, "APSR_", 5) == 0)
7861 {
7862 unsigned found = 0;
7863 str += 5;
7864 while (found < 15)
7865 switch (*str++)
7866 {
7867 case 'c': found = (found & 1) ? 16 : found | 1; break;
7868 case 'n': found = (found & 2) ? 16 : found | 2; break;
7869 case 'z': found = (found & 4) ? 16 : found | 4; break;
7870 case 'v': found = (found & 8) ? 16 : found | 8; break;
7871 default: found = 16;
7872 }
7873 if (found != 15)
7874 goto failure;
7875 inst.operands[i].isvec = 1;
7876 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7877 inst.operands[i].reg = REG_PC;
7878 }
7879 else
7880 goto failure;
7881 break;
7882
7883 case OP_TB:
7884 po_misc_or_fail (parse_tb (&str));
7885 break;
7886
7887 /* Register lists. */
7888 case OP_REGLST:
7889 val = parse_reg_list (&str, REGLIST_RN);
7890 if (*str == '^')
7891 {
7892 inst.operands[i].writeback = 1;
7893 str++;
7894 }
7895 break;
7896
7897 case OP_CLRMLST:
7898 val = parse_reg_list (&str, REGLIST_CLRM);
7899 break;
7900
7901 case OP_VRSLST:
7902 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7903 &partial_match);
7904 break;
7905
7906 case OP_VRDLST:
7907 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7908 &partial_match);
7909 break;
7910
7911 case OP_VRSDLST:
7912 /* Allow Q registers too. */
7913 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7914 REGLIST_NEON_D, &partial_match);
7915 if (val == FAIL)
7916 {
7917 inst.error = NULL;
7918 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7919 REGLIST_VFP_S, &partial_match);
7920 inst.operands[i].issingle = 1;
7921 }
7922 break;
7923
7924 case OP_VRSDVLST:
7925 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7926 REGLIST_VFP_D_VPR, &partial_match);
7927 if (val == FAIL && !partial_match)
7928 {
7929 inst.error = NULL;
7930 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7931 REGLIST_VFP_S_VPR, &partial_match);
7932 inst.operands[i].issingle = 1;
7933 }
7934 break;
7935
7936 case OP_NRDLST:
7937 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7938 REGLIST_NEON_D, &partial_match);
7939 break;
7940
7941 case OP_MSTRLST4:
7942 case OP_MSTRLST2:
7943 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7944 1, &inst.operands[i].vectype);
7945 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7946 goto failure;
7947 break;
7948 case OP_NSTRLST:
7949 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7950 0, &inst.operands[i].vectype);
7951 break;
7952
7953 /* Addressing modes */
7954 case OP_ADDRMVE:
7955 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7956 break;
7957
7958 case OP_ADDR:
7959 po_misc_or_fail (parse_address (&str, i));
7960 break;
7961
7962 case OP_ADDRGLDR:
7963 po_misc_or_fail_no_backtrack (
7964 parse_address_group_reloc (&str, i, GROUP_LDR));
7965 break;
7966
7967 case OP_ADDRGLDRS:
7968 po_misc_or_fail_no_backtrack (
7969 parse_address_group_reloc (&str, i, GROUP_LDRS));
7970 break;
7971
7972 case OP_ADDRGLDC:
7973 po_misc_or_fail_no_backtrack (
7974 parse_address_group_reloc (&str, i, GROUP_LDC));
7975 break;
7976
7977 case OP_SH:
7978 po_misc_or_fail (parse_shifter_operand (&str, i));
7979 break;
7980
7981 case OP_SHG:
7982 po_misc_or_fail_no_backtrack (
7983 parse_shifter_operand_group_reloc (&str, i));
7984 break;
7985
7986 case OP_oSHll:
7987 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7988 break;
7989
7990 case OP_oSHar:
7991 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7992 break;
7993
7994 case OP_oSHllar:
7995 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7996 break;
7997
7998 case OP_RMQRZ:
7999 case OP_oRMQRZ:
8000 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
8001 break;
8002
8003 case OP_RR_ZR:
8004 try_rr_zr:
8005 po_reg_or_goto (REG_TYPE_RN, ZR);
8006 break;
8007 ZR:
8008 po_reg_or_fail (REG_TYPE_ZR);
8009 break;
8010
8011 default:
8012 as_fatal (_("unhandled operand code %d"), op_parse_code);
8013 }
8014
8015 /* Various value-based sanity checks and shared operations. We
8016 do not signal immediate failures for the register constraints;
8017 this allows a syntax error to take precedence. */
8018 switch (op_parse_code)
8019 {
8020 case OP_oRRnpc:
8021 case OP_RRnpc:
8022 case OP_RRnpcb:
8023 case OP_RRw:
8024 case OP_oRRw:
8025 case OP_RRnpc_I0:
8026 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
8027 inst.error = BAD_PC;
8028 break;
8029
8030 case OP_oRRnpcsp:
8031 case OP_RRnpcsp:
8032 case OP_RRnpcsp_I32:
8033 if (inst.operands[i].isreg)
8034 {
8035 if (inst.operands[i].reg == REG_PC)
8036 inst.error = BAD_PC;
8037 else if (inst.operands[i].reg == REG_SP
8038 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
8039 relaxed since ARMv8-A. */
8040 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8041 {
8042 gas_assert (thumb);
8043 inst.error = BAD_SP;
8044 }
8045 }
8046 break;
8047
8048 case OP_RRnpctw:
8049 if (inst.operands[i].isreg
8050 && inst.operands[i].reg == REG_PC
8051 && (inst.operands[i].writeback || thumb))
8052 inst.error = BAD_PC;
8053 break;
8054
8055 case OP_RVSD_COND:
8056 case OP_VLDR:
8057 if (inst.operands[i].isreg)
8058 break;
8059 /* fall through. */
8060
8061 case OP_CPSF:
8062 case OP_ENDI:
8063 case OP_oROR:
8064 case OP_wPSR:
8065 case OP_rPSR:
8066 case OP_COND:
8067 case OP_oBARRIER_I15:
8068 case OP_REGLST:
8069 case OP_CLRMLST:
8070 case OP_VRSLST:
8071 case OP_VRDLST:
8072 case OP_VRSDLST:
8073 case OP_VRSDVLST:
8074 case OP_NRDLST:
8075 case OP_NSTRLST:
8076 case OP_MSTRLST2:
8077 case OP_MSTRLST4:
8078 if (val == FAIL)
8079 goto failure;
8080 inst.operands[i].imm = val;
8081 break;
8082
8083 case OP_LR:
8084 case OP_oLR:
8085 if (inst.operands[i].reg != REG_LR)
8086 inst.error = _("operand must be LR register");
8087 break;
8088
8089 case OP_SP:
8090 if (inst.operands[i].reg != REG_SP)
8091 inst.error = _("operand must be SP register");
8092 break;
8093
8094 case OP_R12:
8095 if (inst.operands[i].reg != REG_R12)
8096 inst.error = _("operand must be r12");
8097 break;
8098
8099 case OP_RMQRZ:
8100 case OP_oRMQRZ:
8101 case OP_RR_ZR:
8102 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
8103 inst.error = BAD_PC;
8104 break;
8105
8106 case OP_RRe:
8107 if (inst.operands[i].isreg
8108 && (inst.operands[i].reg & 0x00000001) != 0)
8109 inst.error = BAD_ODD;
8110 break;
8111
8112 case OP_RRo:
8113 if (inst.operands[i].isreg)
8114 {
8115 if ((inst.operands[i].reg & 0x00000001) != 1)
8116 inst.error = BAD_EVEN;
8117 else if (inst.operands[i].reg == REG_SP)
8118 as_tsktsk (MVE_BAD_SP);
8119 else if (inst.operands[i].reg == REG_PC)
8120 inst.error = BAD_PC;
8121 }
8122 break;
8123
8124 default:
8125 break;
8126 }
8127
8128 /* If we get here, this operand was successfully parsed. */
8129 inst.operands[i].present = 1;
8130 continue;
8131
8132 bad_args:
8133 inst.error = BAD_ARGS;
8134
8135 failure:
8136 if (!backtrack_pos)
8137 {
8138 /* The parse routine should already have set inst.error, but set a
8139 default here just in case. */
8140 if (!inst.error)
8141 inst.error = BAD_SYNTAX;
8142 return FAIL;
8143 }
8144
8145 /* Do not backtrack over a trailing optional argument that
8146 absorbed some text. We will only fail again, with the
8147 'garbage following instruction' error message, which is
8148 probably less helpful than the current one. */
8149 if (backtrack_index == i && backtrack_pos != str
8150 && upat[i+1] == OP_stop)
8151 {
8152 if (!inst.error)
8153 inst.error = BAD_SYNTAX;
8154 return FAIL;
8155 }
8156
8157 /* Try again, skipping the optional argument at backtrack_pos. */
8158 str = backtrack_pos;
8159 inst.error = backtrack_error;
8160 inst.operands[backtrack_index].present = 0;
8161 i = backtrack_index;
8162 backtrack_pos = 0;
8163 }
8164
8165 /* Check that we have parsed all the arguments. */
8166 if (*str != '\0' && !inst.error)
8167 inst.error = _("garbage following instruction");
8168
8169 return inst.error ? FAIL : SUCCESS;
8170 }
8171
8172 #undef po_char_or_fail
8173 #undef po_reg_or_fail
8174 #undef po_reg_or_goto
8175 #undef po_imm_or_fail
8176 #undef po_scalar_or_fail
8177 #undef po_barrier_or_imm
8178
8179 /* Shorthand macro for instruction encoding functions issuing errors. */
8180 #define constraint(expr, err) \
8181 do \
8182 { \
8183 if (expr) \
8184 { \
8185 inst.error = err; \
8186 return; \
8187 } \
8188 } \
8189 while (0)
8190
8191 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8192 instructions are unpredictable if these registers are used. This
8193 is the BadReg predicate in ARM's Thumb-2 documentation.
8194
8195 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8196 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8197 #define reject_bad_reg(reg) \
8198 do \
8199 if (reg == REG_PC) \
8200 { \
8201 inst.error = BAD_PC; \
8202 return; \
8203 } \
8204 else if (reg == REG_SP \
8205 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8206 { \
8207 inst.error = BAD_SP; \
8208 return; \
8209 } \
8210 while (0)
8211
8212 /* If REG is R13 (the stack pointer), warn that its use is
8213 deprecated. */
8214 #define warn_deprecated_sp(reg) \
8215 do \
8216 if (warn_on_deprecated && reg == REG_SP) \
8217 as_tsktsk (_("use of r13 is deprecated")); \
8218 while (0)
8219
8220 /* Functions for operand encoding. ARM, then Thumb. */
8221
8222 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
8223
8224 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8225
8226 The only binary encoding difference is the Coprocessor number. Coprocessor
8227 9 is used for half-precision calculations or conversions. The format of the
8228 instruction is the same as the equivalent Coprocessor 10 instruction that
8229 exists for Single-Precision operation. */
8230
8231 static void
8232 do_scalar_fp16_v82_encode (void)
8233 {
8234 if (inst.cond < COND_ALWAYS)
8235 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8236 " the behaviour is UNPREDICTABLE"));
8237 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8238 _(BAD_FP16));
8239
8240 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8241 mark_feature_used (&arm_ext_fp16);
8242 }
8243
8244 /* If VAL can be encoded in the immediate field of an ARM instruction,
8245 return the encoded form. Otherwise, return FAIL. */
8246
8247 static unsigned int
8248 encode_arm_immediate (unsigned int val)
8249 {
8250 unsigned int a, i;
8251
8252 if (val <= 0xff)
8253 return val;
8254
8255 for (i = 2; i < 32; i += 2)
8256 if ((a = rotate_left (val, i)) <= 0xff)
8257 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8258
8259 return FAIL;
8260 }
8261
8262 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8263 return the encoded form. Otherwise, return FAIL. */
8264 static unsigned int
8265 encode_thumb32_immediate (unsigned int val)
8266 {
8267 unsigned int a, i;
8268
8269 if (val <= 0xff)
8270 return val;
8271
8272 for (i = 1; i <= 24; i++)
8273 {
8274 a = val >> i;
8275 if ((val & ~(0xffU << i)) == 0)
8276 return ((val >> i) & 0x7f) | ((32 - i) << 7);
8277 }
8278
8279 a = val & 0xff;
8280 if (val == ((a << 16) | a))
8281 return 0x100 | a;
8282 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8283 return 0x300 | a;
8284
8285 a = val & 0xff00;
8286 if (val == ((a << 16) | a))
8287 return 0x200 | (a >> 8);
8288
8289 return FAIL;
8290 }
8291 /* Encode a VFP SP or DP register number into inst.instruction. */
8292
8293 static void
8294 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8295 {
8296 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8297 && reg > 15)
8298 {
8299 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
8300 {
8301 if (thumb_mode)
8302 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8303 fpu_vfp_ext_d32);
8304 else
8305 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8306 fpu_vfp_ext_d32);
8307 }
8308 else
8309 {
8310 first_error (_("D register out of range for selected VFP version"));
8311 return;
8312 }
8313 }
8314
8315 switch (pos)
8316 {
8317 case VFP_REG_Sd:
8318 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8319 break;
8320
8321 case VFP_REG_Sn:
8322 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8323 break;
8324
8325 case VFP_REG_Sm:
8326 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8327 break;
8328
8329 case VFP_REG_Dd:
8330 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8331 break;
8332
8333 case VFP_REG_Dn:
8334 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8335 break;
8336
8337 case VFP_REG_Dm:
8338 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8339 break;
8340
8341 default:
8342 abort ();
8343 }
8344 }
8345
8346 /* Encode a <shift> in an ARM-format instruction. The immediate,
8347 if any, is handled by md_apply_fix. */
8348 static void
8349 encode_arm_shift (int i)
8350 {
8351 /* register-shifted register. */
8352 if (inst.operands[i].immisreg)
8353 {
8354 int op_index;
8355 for (op_index = 0; op_index <= i; ++op_index)
8356 {
8357 /* Check the operand only when it's presented. In pre-UAL syntax,
8358 if the destination register is the same as the first operand, two
8359 register form of the instruction can be used. */
8360 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8361 && inst.operands[op_index].reg == REG_PC)
8362 as_warn (UNPRED_REG ("r15"));
8363 }
8364
8365 if (inst.operands[i].imm == REG_PC)
8366 as_warn (UNPRED_REG ("r15"));
8367 }
8368
8369 if (inst.operands[i].shift_kind == SHIFT_RRX)
8370 inst.instruction |= SHIFT_ROR << 5;
8371 else
8372 {
8373 inst.instruction |= inst.operands[i].shift_kind << 5;
8374 if (inst.operands[i].immisreg)
8375 {
8376 inst.instruction |= SHIFT_BY_REG;
8377 inst.instruction |= inst.operands[i].imm << 8;
8378 }
8379 else
8380 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8381 }
8382 }
8383
8384 static void
8385 encode_arm_shifter_operand (int i)
8386 {
8387 if (inst.operands[i].isreg)
8388 {
8389 inst.instruction |= inst.operands[i].reg;
8390 encode_arm_shift (i);
8391 }
8392 else
8393 {
8394 inst.instruction |= INST_IMMEDIATE;
8395 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
8396 inst.instruction |= inst.operands[i].imm;
8397 }
8398 }
8399
8400 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
8401 static void
8402 encode_arm_addr_mode_common (int i, bool is_t)
8403 {
8404 /* PR 14260:
8405 Generate an error if the operand is not a register. */
8406 constraint (!inst.operands[i].isreg,
8407 _("Instruction does not support =N addresses"));
8408
8409 inst.instruction |= inst.operands[i].reg << 16;
8410
8411 if (inst.operands[i].preind)
8412 {
8413 if (is_t)
8414 {
8415 inst.error = _("instruction does not accept preindexed addressing");
8416 return;
8417 }
8418 inst.instruction |= PRE_INDEX;
8419 if (inst.operands[i].writeback)
8420 inst.instruction |= WRITE_BACK;
8421
8422 }
8423 else if (inst.operands[i].postind)
8424 {
8425 gas_assert (inst.operands[i].writeback);
8426 if (is_t)
8427 inst.instruction |= WRITE_BACK;
8428 }
8429 else /* unindexed - only for coprocessor */
8430 {
8431 inst.error = _("instruction does not accept unindexed addressing");
8432 return;
8433 }
8434
8435 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8436 && (((inst.instruction & 0x000f0000) >> 16)
8437 == ((inst.instruction & 0x0000f000) >> 12)))
8438 as_warn ((inst.instruction & LOAD_BIT)
8439 ? _("destination register same as write-back base")
8440 : _("source register same as write-back base"));
8441 }
8442
8443 /* inst.operands[i] was set up by parse_address. Encode it into an
8444 ARM-format mode 2 load or store instruction. If is_t is true,
8445 reject forms that cannot be used with a T instruction (i.e. not
8446 post-indexed). */
8447 static void
8448 encode_arm_addr_mode_2 (int i, bool is_t)
8449 {
8450 const bool is_pc = (inst.operands[i].reg == REG_PC);
8451
8452 encode_arm_addr_mode_common (i, is_t);
8453
8454 if (inst.operands[i].immisreg)
8455 {
8456 constraint ((inst.operands[i].imm == REG_PC
8457 || (is_pc && inst.operands[i].writeback)),
8458 BAD_PC_ADDRESSING);
8459 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8460 inst.instruction |= inst.operands[i].imm;
8461 if (!inst.operands[i].negative)
8462 inst.instruction |= INDEX_UP;
8463 if (inst.operands[i].shifted)
8464 {
8465 if (inst.operands[i].shift_kind == SHIFT_RRX)
8466 inst.instruction |= SHIFT_ROR << 5;
8467 else
8468 {
8469 inst.instruction |= inst.operands[i].shift_kind << 5;
8470 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8471 }
8472 }
8473 }
8474 else /* immediate offset in inst.relocs[0] */
8475 {
8476 if (is_pc && !inst.relocs[0].pc_rel)
8477 {
8478 const bool is_load = ((inst.instruction & LOAD_BIT) != 0);
8479
8480 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8481 cannot use PC in addressing.
8482 PC cannot be used in writeback addressing, either. */
8483 constraint ((is_t || inst.operands[i].writeback),
8484 BAD_PC_ADDRESSING);
8485
8486 /* Use of PC in str is deprecated for ARMv7. */
8487 if (warn_on_deprecated
8488 && !is_load
8489 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
8490 as_tsktsk (_("use of PC in this instruction is deprecated"));
8491 }
8492
8493 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8494 {
8495 /* Prefer + for zero encoded value. */
8496 if (!inst.operands[i].negative)
8497 inst.instruction |= INDEX_UP;
8498 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
8499 }
8500 }
8501 }
8502
8503 /* inst.operands[i] was set up by parse_address. Encode it into an
8504 ARM-format mode 3 load or store instruction. Reject forms that
8505 cannot be used with such instructions. If is_t is true, reject
8506 forms that cannot be used with a T instruction (i.e. not
8507 post-indexed). */
8508 static void
8509 encode_arm_addr_mode_3 (int i, bool is_t)
8510 {
8511 if (inst.operands[i].immisreg && inst.operands[i].shifted)
8512 {
8513 inst.error = _("instruction does not accept scaled register index");
8514 return;
8515 }
8516
8517 encode_arm_addr_mode_common (i, is_t);
8518
8519 if (inst.operands[i].immisreg)
8520 {
8521 constraint ((inst.operands[i].imm == REG_PC
8522 || (is_t && inst.operands[i].reg == REG_PC)),
8523 BAD_PC_ADDRESSING);
8524 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8525 BAD_PC_WRITEBACK);
8526 inst.instruction |= inst.operands[i].imm;
8527 if (!inst.operands[i].negative)
8528 inst.instruction |= INDEX_UP;
8529 }
8530 else /* immediate offset in inst.relocs[0] */
8531 {
8532 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
8533 && inst.operands[i].writeback),
8534 BAD_PC_WRITEBACK);
8535 inst.instruction |= HWOFFSET_IMM;
8536 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8537 {
8538 /* Prefer + for zero encoded value. */
8539 if (!inst.operands[i].negative)
8540 inst.instruction |= INDEX_UP;
8541
8542 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
8543 }
8544 }
8545 }
8546
8547 /* Write immediate bits [7:0] to the following locations:
8548
8549 |28/24|23 19|18 16|15 4|3 0|
8550 | 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|
8551
8552 This function is used by VMOV/VMVN/VORR/VBIC. */
8553
8554 static void
8555 neon_write_immbits (unsigned immbits)
8556 {
8557 inst.instruction |= immbits & 0xf;
8558 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8559 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8560 }
8561
8562 /* Invert low-order SIZE bits of XHI:XLO. */
8563
8564 static void
8565 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8566 {
8567 unsigned immlo = xlo ? *xlo : 0;
8568 unsigned immhi = xhi ? *xhi : 0;
8569
8570 switch (size)
8571 {
8572 case 8:
8573 immlo = (~immlo) & 0xff;
8574 break;
8575
8576 case 16:
8577 immlo = (~immlo) & 0xffff;
8578 break;
8579
8580 case 64:
8581 immhi = (~immhi) & 0xffffffff;
8582 /* fall through. */
8583
8584 case 32:
8585 immlo = (~immlo) & 0xffffffff;
8586 break;
8587
8588 default:
8589 abort ();
8590 }
8591
8592 if (xlo)
8593 *xlo = immlo;
8594
8595 if (xhi)
8596 *xhi = immhi;
8597 }
8598
8599 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8600 A, B, C, D. */
8601
8602 static int
8603 neon_bits_same_in_bytes (unsigned imm)
8604 {
8605 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8606 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8607 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8608 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8609 }
8610
8611 /* For immediate of above form, return 0bABCD. */
8612
8613 static unsigned
8614 neon_squash_bits (unsigned imm)
8615 {
8616 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8617 | ((imm & 0x01000000) >> 21);
8618 }
8619
8620 /* Compress quarter-float representation to 0b...000 abcdefgh. */
8621
8622 static unsigned
8623 neon_qfloat_bits (unsigned imm)
8624 {
8625 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8626 }
8627
8628 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8629 the instruction. *OP is passed as the initial value of the op field, and
8630 may be set to a different value depending on the constant (i.e.
8631 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8632 MVN). If the immediate looks like a repeated pattern then also
8633 try smaller element sizes. */
8634
8635 static int
8636 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8637 unsigned *immbits, int *op, int size,
8638 enum neon_el_type type)
8639 {
8640 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8641 float. */
8642 if (type == NT_float && !float_p)
8643 return FAIL;
8644
8645 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
8646 {
8647 if (size != 32 || *op == 1)
8648 return FAIL;
8649 *immbits = neon_qfloat_bits (immlo);
8650 return 0xf;
8651 }
8652
8653 if (size == 64)
8654 {
8655 if (neon_bits_same_in_bytes (immhi)
8656 && neon_bits_same_in_bytes (immlo))
8657 {
8658 if (*op == 1)
8659 return FAIL;
8660 *immbits = (neon_squash_bits (immhi) << 4)
8661 | neon_squash_bits (immlo);
8662 *op = 1;
8663 return 0xe;
8664 }
8665
8666 if (immhi != immlo)
8667 return FAIL;
8668 }
8669
8670 if (size >= 32)
8671 {
8672 if (immlo == (immlo & 0x000000ff))
8673 {
8674 *immbits = immlo;
8675 return 0x0;
8676 }
8677 else if (immlo == (immlo & 0x0000ff00))
8678 {
8679 *immbits = immlo >> 8;
8680 return 0x2;
8681 }
8682 else if (immlo == (immlo & 0x00ff0000))
8683 {
8684 *immbits = immlo >> 16;
8685 return 0x4;
8686 }
8687 else if (immlo == (immlo & 0xff000000))
8688 {
8689 *immbits = immlo >> 24;
8690 return 0x6;
8691 }
8692 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8693 {
8694 *immbits = (immlo >> 8) & 0xff;
8695 return 0xc;
8696 }
8697 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8698 {
8699 *immbits = (immlo >> 16) & 0xff;
8700 return 0xd;
8701 }
8702
8703 if ((immlo & 0xffff) != (immlo >> 16))
8704 return FAIL;
8705 immlo &= 0xffff;
8706 }
8707
8708 if (size >= 16)
8709 {
8710 if (immlo == (immlo & 0x000000ff))
8711 {
8712 *immbits = immlo;
8713 return 0x8;
8714 }
8715 else if (immlo == (immlo & 0x0000ff00))
8716 {
8717 *immbits = immlo >> 8;
8718 return 0xa;
8719 }
8720
8721 if ((immlo & 0xff) != (immlo >> 8))
8722 return FAIL;
8723 immlo &= 0xff;
8724 }
8725
8726 if (immlo == (immlo & 0x000000ff))
8727 {
8728 /* Don't allow MVN with 8-bit immediate. */
8729 if (*op == 1)
8730 return FAIL;
8731 *immbits = immlo;
8732 return 0xe;
8733 }
8734
8735 return FAIL;
8736 }
8737
8738 #if defined BFD_HOST_64_BIT
8739 /* Returns TRUE if double precision value V may be cast
8740 to single precision without loss of accuracy. */
8741
8742 static bool
8743 is_double_a_single (bfd_uint64_t v)
8744 {
8745 int exp = (v >> 52) & 0x7FF;
8746 bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
8747
8748 return ((exp == 0 || exp == 0x7FF
8749 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8750 && (mantissa & 0x1FFFFFFFL) == 0);
8751 }
8752
8753 /* Returns a double precision value casted to single precision
8754 (ignoring the least significant bits in exponent and mantissa). */
8755
8756 static int
8757 double_to_single (bfd_uint64_t v)
8758 {
8759 unsigned int sign = (v >> 63) & 1;
8760 int exp = (v >> 52) & 0x7FF;
8761 bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
8762
8763 if (exp == 0x7FF)
8764 exp = 0xFF;
8765 else
8766 {
8767 exp = exp - 1023 + 127;
8768 if (exp >= 0xFF)
8769 {
8770 /* Infinity. */
8771 exp = 0x7F;
8772 mantissa = 0;
8773 }
8774 else if (exp < 0)
8775 {
8776 /* No denormalized numbers. */
8777 exp = 0;
8778 mantissa = 0;
8779 }
8780 }
8781 mantissa >>= 29;
8782 return (sign << 31) | (exp << 23) | mantissa;
8783 }
8784 #endif /* BFD_HOST_64_BIT */
8785
8786 enum lit_type
8787 {
8788 CONST_THUMB,
8789 CONST_ARM,
8790 CONST_VEC
8791 };
8792
8793 static void do_vfp_nsyn_opcode (const char *);
8794
8795 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
8796 Determine whether it can be performed with a move instruction; if
8797 it can, convert inst.instruction to that move instruction and
8798 return true; if it can't, convert inst.instruction to a literal-pool
8799 load and return FALSE. If this is not a valid thing to do in the
8800 current context, set inst.error and return TRUE.
8801
8802 inst.operands[i] describes the destination register. */
8803
8804 static bool
8805 move_or_literal_pool (int i, enum lit_type t, bool mode_3)
8806 {
8807 unsigned long tbit;
8808 bool thumb_p = (t == CONST_THUMB);
8809 bool arm_p = (t == CONST_ARM);
8810
8811 if (thumb_p)
8812 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8813 else
8814 tbit = LOAD_BIT;
8815
8816 if ((inst.instruction & tbit) == 0)
8817 {
8818 inst.error = _("invalid pseudo operation");
8819 return true;
8820 }
8821
8822 if (inst.relocs[0].exp.X_op != O_constant
8823 && inst.relocs[0].exp.X_op != O_symbol
8824 && inst.relocs[0].exp.X_op != O_big)
8825 {
8826 inst.error = _("constant expression expected");
8827 return true;
8828 }
8829
8830 if (inst.relocs[0].exp.X_op == O_constant
8831 || inst.relocs[0].exp.X_op == O_big)
8832 {
8833 #if defined BFD_HOST_64_BIT
8834 bfd_uint64_t v;
8835 #else
8836 valueT v;
8837 #endif
8838 if (inst.relocs[0].exp.X_op == O_big)
8839 {
8840 LITTLENUM_TYPE w[X_PRECISION];
8841 LITTLENUM_TYPE * l;
8842
8843 if (inst.relocs[0].exp.X_add_number == -1)
8844 {
8845 gen_to_words (w, X_PRECISION, E_PRECISION);
8846 l = w;
8847 /* FIXME: Should we check words w[2..5] ? */
8848 }
8849 else
8850 l = generic_bignum;
8851
8852 #if defined BFD_HOST_64_BIT
8853 v = l[3] & LITTLENUM_MASK;
8854 v <<= LITTLENUM_NUMBER_OF_BITS;
8855 v |= l[2] & LITTLENUM_MASK;
8856 v <<= LITTLENUM_NUMBER_OF_BITS;
8857 v |= l[1] & LITTLENUM_MASK;
8858 v <<= LITTLENUM_NUMBER_OF_BITS;
8859 v |= l[0] & LITTLENUM_MASK;
8860 #else
8861 v = l[1] & LITTLENUM_MASK;
8862 v <<= LITTLENUM_NUMBER_OF_BITS;
8863 v |= l[0] & LITTLENUM_MASK;
8864 #endif
8865 }
8866 else
8867 v = inst.relocs[0].exp.X_add_number;
8868
8869 if (!inst.operands[i].issingle)
8870 {
8871 if (thumb_p)
8872 {
8873 /* LDR should not use lead in a flag-setting instruction being
8874 chosen so we do not check whether movs can be used. */
8875
8876 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8877 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8878 && inst.operands[i].reg != 13
8879 && inst.operands[i].reg != 15)
8880 {
8881 /* Check if on thumb2 it can be done with a mov.w, mvn or
8882 movw instruction. */
8883 unsigned int newimm;
8884 bool isNegated = false;
8885
8886 newimm = encode_thumb32_immediate (v);
8887 if (newimm == (unsigned int) FAIL)
8888 {
8889 newimm = encode_thumb32_immediate (~v);
8890 isNegated = true;
8891 }
8892
8893 /* The number can be loaded with a mov.w or mvn
8894 instruction. */
8895 if (newimm != (unsigned int) FAIL
8896 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8897 {
8898 inst.instruction = (0xf04f0000 /* MOV.W. */
8899 | (inst.operands[i].reg << 8));
8900 /* Change to MOVN. */
8901 inst.instruction |= (isNegated ? 0x200000 : 0);
8902 inst.instruction |= (newimm & 0x800) << 15;
8903 inst.instruction |= (newimm & 0x700) << 4;
8904 inst.instruction |= (newimm & 0x0ff);
8905 return true;
8906 }
8907 /* The number can be loaded with a movw instruction. */
8908 else if ((v & ~0xFFFF) == 0
8909 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8910 {
8911 int imm = v & 0xFFFF;
8912
8913 inst.instruction = 0xf2400000; /* MOVW. */
8914 inst.instruction |= (inst.operands[i].reg << 8);
8915 inst.instruction |= (imm & 0xf000) << 4;
8916 inst.instruction |= (imm & 0x0800) << 15;
8917 inst.instruction |= (imm & 0x0700) << 4;
8918 inst.instruction |= (imm & 0x00ff);
8919 /* In case this replacement is being done on Armv8-M
8920 Baseline we need to make sure to disable the
8921 instruction size check, as otherwise GAS will reject
8922 the use of this T32 instruction. */
8923 inst.size_req = 0;
8924 return true;
8925 }
8926 }
8927 }
8928 else if (arm_p)
8929 {
8930 int value = encode_arm_immediate (v);
8931
8932 if (value != FAIL)
8933 {
8934 /* This can be done with a mov instruction. */
8935 inst.instruction &= LITERAL_MASK;
8936 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8937 inst.instruction |= value & 0xfff;
8938 return true;
8939 }
8940
8941 value = encode_arm_immediate (~ v);
8942 if (value != FAIL)
8943 {
8944 /* This can be done with a mvn instruction. */
8945 inst.instruction &= LITERAL_MASK;
8946 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8947 inst.instruction |= value & 0xfff;
8948 return true;
8949 }
8950 }
8951 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8952 {
8953 int op = 0;
8954 unsigned immbits = 0;
8955 unsigned immlo = inst.operands[1].imm;
8956 unsigned immhi = inst.operands[1].regisimm
8957 ? inst.operands[1].reg
8958 : inst.relocs[0].exp.X_unsigned
8959 ? 0
8960 : ((bfd_int64_t)((int) immlo)) >> 32;
8961 int cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits,
8962 &op, 64, NT_invtype);
8963
8964 if (cmode == FAIL)
8965 {
8966 neon_invert_size (&immlo, &immhi, 64);
8967 op = !op;
8968 cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits,
8969 &op, 64, NT_invtype);
8970 }
8971
8972 if (cmode != FAIL)
8973 {
8974 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8975 | (1 << 23)
8976 | (cmode << 8)
8977 | (op << 5)
8978 | (1 << 4);
8979
8980 /* Fill other bits in vmov encoding for both thumb and arm. */
8981 if (thumb_mode)
8982 inst.instruction |= (0x7U << 29) | (0xF << 24);
8983 else
8984 inst.instruction |= (0xFU << 28) | (0x1 << 25);
8985 neon_write_immbits (immbits);
8986 return true;
8987 }
8988 }
8989 }
8990
8991 if (t == CONST_VEC)
8992 {
8993 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8994 if (inst.operands[i].issingle
8995 && is_quarter_float (inst.operands[1].imm)
8996 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8997 {
8998 inst.operands[1].imm =
8999 neon_qfloat_bits (v);
9000 do_vfp_nsyn_opcode ("fconsts");
9001 return true;
9002 }
9003
9004 /* If our host does not support a 64-bit type then we cannot perform
9005 the following optimization. This mean that there will be a
9006 discrepancy between the output produced by an assembler built for
9007 a 32-bit-only host and the output produced from a 64-bit host, but
9008 this cannot be helped. */
9009 #if defined BFD_HOST_64_BIT
9010 else if (!inst.operands[1].issingle
9011 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
9012 {
9013 if (is_double_a_single (v)
9014 && is_quarter_float (double_to_single (v)))
9015 {
9016 inst.operands[1].imm =
9017 neon_qfloat_bits (double_to_single (v));
9018 do_vfp_nsyn_opcode ("fconstd");
9019 return true;
9020 }
9021 }
9022 #endif
9023 }
9024 }
9025
9026 if (add_to_lit_pool ((!inst.operands[i].isvec
9027 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
9028 return true;
9029
9030 inst.operands[1].reg = REG_PC;
9031 inst.operands[1].isreg = 1;
9032 inst.operands[1].preind = 1;
9033 inst.relocs[0].pc_rel = 1;
9034 inst.relocs[0].type = (thumb_p
9035 ? BFD_RELOC_ARM_THUMB_OFFSET
9036 : (mode_3
9037 ? BFD_RELOC_ARM_HWLITERAL
9038 : BFD_RELOC_ARM_LITERAL));
9039 return false;
9040 }
9041
9042 /* inst.operands[i] was set up by parse_address. Encode it into an
9043 ARM-format instruction. Reject all forms which cannot be encoded
9044 into a coprocessor load/store instruction. If wb_ok is false,
9045 reject use of writeback; if unind_ok is false, reject use of
9046 unindexed addressing. If reloc_override is not 0, use it instead
9047 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
9048 (in which case it is preserved). */
9049
9050 static int
9051 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
9052 {
9053 if (!inst.operands[i].isreg)
9054 {
9055 /* PR 18256 */
9056 if (! inst.operands[0].isvec)
9057 {
9058 inst.error = _("invalid co-processor operand");
9059 return FAIL;
9060 }
9061 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/false))
9062 return SUCCESS;
9063 }
9064
9065 inst.instruction |= inst.operands[i].reg << 16;
9066
9067 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
9068
9069 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
9070 {
9071 gas_assert (!inst.operands[i].writeback);
9072 if (!unind_ok)
9073 {
9074 inst.error = _("instruction does not support unindexed addressing");
9075 return FAIL;
9076 }
9077 inst.instruction |= inst.operands[i].imm;
9078 inst.instruction |= INDEX_UP;
9079 return SUCCESS;
9080 }
9081
9082 if (inst.operands[i].preind)
9083 inst.instruction |= PRE_INDEX;
9084
9085 if (inst.operands[i].writeback)
9086 {
9087 if (inst.operands[i].reg == REG_PC)
9088 {
9089 inst.error = _("pc may not be used with write-back");
9090 return FAIL;
9091 }
9092 if (!wb_ok)
9093 {
9094 inst.error = _("instruction does not support writeback");
9095 return FAIL;
9096 }
9097 inst.instruction |= WRITE_BACK;
9098 }
9099
9100 if (reloc_override)
9101 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
9102 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
9103 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
9104 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
9105 {
9106 if (thumb_mode)
9107 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
9108 else
9109 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
9110 }
9111
9112 /* Prefer + for zero encoded value. */
9113 if (!inst.operands[i].negative)
9114 inst.instruction |= INDEX_UP;
9115
9116 return SUCCESS;
9117 }
9118
9119 /* Functions for instruction encoding, sorted by sub-architecture.
9120 First some generics; their names are taken from the conventional
9121 bit positions for register arguments in ARM format instructions. */
9122
9123 static void
9124 do_noargs (void)
9125 {
9126 }
9127
9128 static void
9129 do_rd (void)
9130 {
9131 inst.instruction |= inst.operands[0].reg << 12;
9132 }
9133
9134 static void
9135 do_rn (void)
9136 {
9137 inst.instruction |= inst.operands[0].reg << 16;
9138 }
9139
9140 static void
9141 do_rd_rm (void)
9142 {
9143 inst.instruction |= inst.operands[0].reg << 12;
9144 inst.instruction |= inst.operands[1].reg;
9145 }
9146
9147 static void
9148 do_rm_rn (void)
9149 {
9150 inst.instruction |= inst.operands[0].reg;
9151 inst.instruction |= inst.operands[1].reg << 16;
9152 }
9153
9154 static void
9155 do_rd_rn (void)
9156 {
9157 inst.instruction |= inst.operands[0].reg << 12;
9158 inst.instruction |= inst.operands[1].reg << 16;
9159 }
9160
9161 static void
9162 do_rn_rd (void)
9163 {
9164 inst.instruction |= inst.operands[0].reg << 16;
9165 inst.instruction |= inst.operands[1].reg << 12;
9166 }
9167
9168 static void
9169 do_tt (void)
9170 {
9171 inst.instruction |= inst.operands[0].reg << 8;
9172 inst.instruction |= inst.operands[1].reg << 16;
9173 }
9174
9175 static bool
9176 check_obsolete (const arm_feature_set *feature, const char *msg)
9177 {
9178 if (ARM_CPU_IS_ANY (cpu_variant))
9179 {
9180 as_tsktsk ("%s", msg);
9181 return true;
9182 }
9183 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9184 {
9185 as_bad ("%s", msg);
9186 return true;
9187 }
9188
9189 return false;
9190 }
9191
9192 static void
9193 do_rd_rm_rn (void)
9194 {
9195 unsigned Rn = inst.operands[2].reg;
9196 /* Enforce restrictions on SWP instruction. */
9197 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
9198 {
9199 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9200 _("Rn must not overlap other operands"));
9201
9202 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9203 */
9204 if (!check_obsolete (&arm_ext_v8,
9205 _("swp{b} use is obsoleted for ARMv8 and later"))
9206 && warn_on_deprecated
9207 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
9208 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
9209 }
9210
9211 inst.instruction |= inst.operands[0].reg << 12;
9212 inst.instruction |= inst.operands[1].reg;
9213 inst.instruction |= Rn << 16;
9214 }
9215
9216 static void
9217 do_rd_rn_rm (void)
9218 {
9219 inst.instruction |= inst.operands[0].reg << 12;
9220 inst.instruction |= inst.operands[1].reg << 16;
9221 inst.instruction |= inst.operands[2].reg;
9222 }
9223
9224 static void
9225 do_rm_rd_rn (void)
9226 {
9227 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
9228 constraint (((inst.relocs[0].exp.X_op != O_constant
9229 && inst.relocs[0].exp.X_op != O_illegal)
9230 || inst.relocs[0].exp.X_add_number != 0),
9231 BAD_ADDR_MODE);
9232 inst.instruction |= inst.operands[0].reg;
9233 inst.instruction |= inst.operands[1].reg << 12;
9234 inst.instruction |= inst.operands[2].reg << 16;
9235 }
9236
9237 static void
9238 do_imm0 (void)
9239 {
9240 inst.instruction |= inst.operands[0].imm;
9241 }
9242
9243 static void
9244 do_rd_cpaddr (void)
9245 {
9246 inst.instruction |= inst.operands[0].reg << 12;
9247 encode_arm_cp_address (1, true, true, 0);
9248 }
9249
9250 /* ARM instructions, in alphabetical order by function name (except
9251 that wrapper functions appear immediately after the function they
9252 wrap). */
9253
9254 /* This is a pseudo-op of the form "adr rd, label" to be converted
9255 into a relative address of the form "add rd, pc, #label-.-8". */
9256
9257 static void
9258 do_adr (void)
9259 {
9260 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9261
9262 /* Frag hacking will turn this into a sub instruction if the offset turns
9263 out to be negative. */
9264 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9265 inst.relocs[0].pc_rel = 1;
9266 inst.relocs[0].exp.X_add_number -= 8;
9267
9268 if (support_interwork
9269 && inst.relocs[0].exp.X_op == O_symbol
9270 && inst.relocs[0].exp.X_add_symbol != NULL
9271 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9272 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9273 inst.relocs[0].exp.X_add_number |= 1;
9274 }
9275
9276 /* This is a pseudo-op of the form "adrl rd, label" to be converted
9277 into a relative address of the form:
9278 add rd, pc, #low(label-.-8)"
9279 add rd, rd, #high(label-.-8)" */
9280
9281 static void
9282 do_adrl (void)
9283 {
9284 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9285
9286 /* Frag hacking will turn this into a sub instruction if the offset turns
9287 out to be negative. */
9288 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9289 inst.relocs[0].pc_rel = 1;
9290 inst.size = INSN_SIZE * 2;
9291 inst.relocs[0].exp.X_add_number -= 8;
9292
9293 if (support_interwork
9294 && inst.relocs[0].exp.X_op == O_symbol
9295 && inst.relocs[0].exp.X_add_symbol != NULL
9296 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9297 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9298 inst.relocs[0].exp.X_add_number |= 1;
9299 }
9300
9301 static void
9302 do_arit (void)
9303 {
9304 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9305 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9306 THUMB1_RELOC_ONLY);
9307 if (!inst.operands[1].present)
9308 inst.operands[1].reg = inst.operands[0].reg;
9309 inst.instruction |= inst.operands[0].reg << 12;
9310 inst.instruction |= inst.operands[1].reg << 16;
9311 encode_arm_shifter_operand (2);
9312 }
9313
9314 static void
9315 do_barrier (void)
9316 {
9317 if (inst.operands[0].present)
9318 inst.instruction |= inst.operands[0].imm;
9319 else
9320 inst.instruction |= 0xf;
9321 }
9322
9323 static void
9324 do_bfc (void)
9325 {
9326 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9327 constraint (msb > 32, _("bit-field extends past end of register"));
9328 /* The instruction encoding stores the LSB and MSB,
9329 not the LSB and width. */
9330 inst.instruction |= inst.operands[0].reg << 12;
9331 inst.instruction |= inst.operands[1].imm << 7;
9332 inst.instruction |= (msb - 1) << 16;
9333 }
9334
9335 static void
9336 do_bfi (void)
9337 {
9338 unsigned int msb;
9339
9340 /* #0 in second position is alternative syntax for bfc, which is
9341 the same instruction but with REG_PC in the Rm field. */
9342 if (!inst.operands[1].isreg)
9343 inst.operands[1].reg = REG_PC;
9344
9345 msb = inst.operands[2].imm + inst.operands[3].imm;
9346 constraint (msb > 32, _("bit-field extends past end of register"));
9347 /* The instruction encoding stores the LSB and MSB,
9348 not the LSB and width. */
9349 inst.instruction |= inst.operands[0].reg << 12;
9350 inst.instruction |= inst.operands[1].reg;
9351 inst.instruction |= inst.operands[2].imm << 7;
9352 inst.instruction |= (msb - 1) << 16;
9353 }
9354
9355 static void
9356 do_bfx (void)
9357 {
9358 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9359 _("bit-field extends past end of register"));
9360 inst.instruction |= inst.operands[0].reg << 12;
9361 inst.instruction |= inst.operands[1].reg;
9362 inst.instruction |= inst.operands[2].imm << 7;
9363 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9364 }
9365
9366 /* ARM V5 breakpoint instruction (argument parse)
9367 BKPT <16 bit unsigned immediate>
9368 Instruction is not conditional.
9369 The bit pattern given in insns[] has the COND_ALWAYS condition,
9370 and it is an error if the caller tried to override that. */
9371
9372 static void
9373 do_bkpt (void)
9374 {
9375 /* Top 12 of 16 bits to bits 19:8. */
9376 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
9377
9378 /* Bottom 4 of 16 bits to bits 3:0. */
9379 inst.instruction |= inst.operands[0].imm & 0xf;
9380 }
9381
9382 static void
9383 encode_branch (int default_reloc)
9384 {
9385 if (inst.operands[0].hasreloc)
9386 {
9387 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9388 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9389 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
9390 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
9391 ? BFD_RELOC_ARM_PLT32
9392 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
9393 }
9394 else
9395 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9396 inst.relocs[0].pc_rel = 1;
9397 }
9398
9399 static void
9400 do_branch (void)
9401 {
9402 #ifdef OBJ_ELF
9403 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9404 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9405 else
9406 #endif
9407 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9408 }
9409
9410 static void
9411 do_bl (void)
9412 {
9413 #ifdef OBJ_ELF
9414 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9415 {
9416 if (inst.cond == COND_ALWAYS)
9417 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9418 else
9419 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9420 }
9421 else
9422 #endif
9423 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9424 }
9425
9426 /* ARM V5 branch-link-exchange instruction (argument parse)
9427 BLX <target_addr> ie BLX(1)
9428 BLX{<condition>} <Rm> ie BLX(2)
9429 Unfortunately, there are two different opcodes for this mnemonic.
9430 So, the insns[].value is not used, and the code here zaps values
9431 into inst.instruction.
9432 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
9433
9434 static void
9435 do_blx (void)
9436 {
9437 if (inst.operands[0].isreg)
9438 {
9439 /* Arg is a register; the opcode provided by insns[] is correct.
9440 It is not illegal to do "blx pc", just useless. */
9441 if (inst.operands[0].reg == REG_PC)
9442 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
9443
9444 inst.instruction |= inst.operands[0].reg;
9445 }
9446 else
9447 {
9448 /* Arg is an address; this instruction cannot be executed
9449 conditionally, and the opcode must be adjusted.
9450 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9451 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
9452 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9453 inst.instruction = 0xfa000000;
9454 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
9455 }
9456 }
9457
9458 static void
9459 do_bx (void)
9460 {
9461 bool want_reloc;
9462
9463 if (inst.operands[0].reg == REG_PC)
9464 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
9465
9466 inst.instruction |= inst.operands[0].reg;
9467 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9468 it is for ARMv4t or earlier. */
9469 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
9470 if (!ARM_FEATURE_ZERO (selected_object_arch)
9471 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
9472 want_reloc = true;
9473
9474 #ifdef OBJ_ELF
9475 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
9476 #endif
9477 want_reloc = false;
9478
9479 if (want_reloc)
9480 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
9481 }
9482
9483
9484 /* ARM v5TEJ. Jump to Jazelle code. */
9485
9486 static void
9487 do_bxj (void)
9488 {
9489 if (inst.operands[0].reg == REG_PC)
9490 as_tsktsk (_("use of r15 in bxj is not really useful"));
9491
9492 inst.instruction |= inst.operands[0].reg;
9493 }
9494
9495 /* Co-processor data operation:
9496 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9497 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9498 static void
9499 do_cdp (void)
9500 {
9501 inst.instruction |= inst.operands[0].reg << 8;
9502 inst.instruction |= inst.operands[1].imm << 20;
9503 inst.instruction |= inst.operands[2].reg << 12;
9504 inst.instruction |= inst.operands[3].reg << 16;
9505 inst.instruction |= inst.operands[4].reg;
9506 inst.instruction |= inst.operands[5].imm << 5;
9507 }
9508
9509 static void
9510 do_cmp (void)
9511 {
9512 inst.instruction |= inst.operands[0].reg << 16;
9513 encode_arm_shifter_operand (1);
9514 }
9515
9516 /* Transfer between coprocessor and ARM registers.
9517 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9518 MRC2
9519 MCR{cond}
9520 MCR2
9521
9522 No special properties. */
9523
9524 struct deprecated_coproc_regs_s
9525 {
9526 unsigned cp;
9527 int opc1;
9528 unsigned crn;
9529 unsigned crm;
9530 int opc2;
9531 arm_feature_set deprecated;
9532 arm_feature_set obsoleted;
9533 const char *dep_msg;
9534 const char *obs_msg;
9535 };
9536
9537 #define DEPR_ACCESS_V8 \
9538 N_("This coprocessor register access is deprecated in ARMv8")
9539
9540 /* Table of all deprecated coprocessor registers. */
9541 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9542 {
9543 {15, 0, 7, 10, 5, /* CP15DMB. */
9544 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9545 DEPR_ACCESS_V8, NULL},
9546 {15, 0, 7, 10, 4, /* CP15DSB. */
9547 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9548 DEPR_ACCESS_V8, NULL},
9549 {15, 0, 7, 5, 4, /* CP15ISB. */
9550 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9551 DEPR_ACCESS_V8, NULL},
9552 {14, 6, 1, 0, 0, /* TEEHBR. */
9553 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9554 DEPR_ACCESS_V8, NULL},
9555 {14, 6, 0, 0, 0, /* TEECR. */
9556 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9557 DEPR_ACCESS_V8, NULL},
9558 };
9559
9560 #undef DEPR_ACCESS_V8
9561
9562 static const size_t deprecated_coproc_reg_count =
9563 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9564
9565 static void
9566 do_co_reg (void)
9567 {
9568 unsigned Rd;
9569 size_t i;
9570
9571 Rd = inst.operands[2].reg;
9572 if (thumb_mode)
9573 {
9574 if (inst.instruction == 0xee000010
9575 || inst.instruction == 0xfe000010)
9576 /* MCR, MCR2 */
9577 reject_bad_reg (Rd);
9578 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9579 /* MRC, MRC2 */
9580 constraint (Rd == REG_SP, BAD_SP);
9581 }
9582 else
9583 {
9584 /* MCR */
9585 if (inst.instruction == 0xe000010)
9586 constraint (Rd == REG_PC, BAD_PC);
9587 }
9588
9589 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9590 {
9591 const struct deprecated_coproc_regs_s *r =
9592 deprecated_coproc_regs + i;
9593
9594 if (inst.operands[0].reg == r->cp
9595 && inst.operands[1].imm == r->opc1
9596 && inst.operands[3].reg == r->crn
9597 && inst.operands[4].reg == r->crm
9598 && inst.operands[5].imm == r->opc2)
9599 {
9600 if (! ARM_CPU_IS_ANY (cpu_variant)
9601 && warn_on_deprecated
9602 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
9603 as_tsktsk ("%s", r->dep_msg);
9604 }
9605 }
9606
9607 inst.instruction |= inst.operands[0].reg << 8;
9608 inst.instruction |= inst.operands[1].imm << 21;
9609 inst.instruction |= Rd << 12;
9610 inst.instruction |= inst.operands[3].reg << 16;
9611 inst.instruction |= inst.operands[4].reg;
9612 inst.instruction |= inst.operands[5].imm << 5;
9613 }
9614
9615 /* Transfer between coprocessor register and pair of ARM registers.
9616 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9617 MCRR2
9618 MRRC{cond}
9619 MRRC2
9620
9621 Two XScale instructions are special cases of these:
9622
9623 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9624 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
9625
9626 Result unpredictable if Rd or Rn is R15. */
9627
9628 static void
9629 do_co_reg2c (void)
9630 {
9631 unsigned Rd, Rn;
9632
9633 Rd = inst.operands[2].reg;
9634 Rn = inst.operands[3].reg;
9635
9636 if (thumb_mode)
9637 {
9638 reject_bad_reg (Rd);
9639 reject_bad_reg (Rn);
9640 }
9641 else
9642 {
9643 constraint (Rd == REG_PC, BAD_PC);
9644 constraint (Rn == REG_PC, BAD_PC);
9645 }
9646
9647 /* Only check the MRRC{2} variants. */
9648 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9649 {
9650 /* If Rd == Rn, error that the operation is
9651 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9652 constraint (Rd == Rn, BAD_OVERLAP);
9653 }
9654
9655 inst.instruction |= inst.operands[0].reg << 8;
9656 inst.instruction |= inst.operands[1].imm << 4;
9657 inst.instruction |= Rd << 12;
9658 inst.instruction |= Rn << 16;
9659 inst.instruction |= inst.operands[4].reg;
9660 }
9661
9662 static void
9663 do_cpsi (void)
9664 {
9665 inst.instruction |= inst.operands[0].imm << 6;
9666 if (inst.operands[1].present)
9667 {
9668 inst.instruction |= CPSI_MMOD;
9669 inst.instruction |= inst.operands[1].imm;
9670 }
9671 }
9672
9673 static void
9674 do_dbg (void)
9675 {
9676 inst.instruction |= inst.operands[0].imm;
9677 }
9678
9679 static void
9680 do_div (void)
9681 {
9682 unsigned Rd, Rn, Rm;
9683
9684 Rd = inst.operands[0].reg;
9685 Rn = (inst.operands[1].present
9686 ? inst.operands[1].reg : Rd);
9687 Rm = inst.operands[2].reg;
9688
9689 constraint ((Rd == REG_PC), BAD_PC);
9690 constraint ((Rn == REG_PC), BAD_PC);
9691 constraint ((Rm == REG_PC), BAD_PC);
9692
9693 inst.instruction |= Rd << 16;
9694 inst.instruction |= Rn << 0;
9695 inst.instruction |= Rm << 8;
9696 }
9697
9698 static void
9699 do_it (void)
9700 {
9701 /* There is no IT instruction in ARM mode. We
9702 process it to do the validation as if in
9703 thumb mode, just in case the code gets
9704 assembled for thumb using the unified syntax. */
9705
9706 inst.size = 0;
9707 if (unified_syntax)
9708 {
9709 set_pred_insn_type (IT_INSN);
9710 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9711 now_pred.cc = inst.operands[0].imm;
9712 }
9713 }
9714
9715 /* If there is only one register in the register list,
9716 then return its register number. Otherwise return -1. */
9717 static int
9718 only_one_reg_in_list (int range)
9719 {
9720 int i = ffs (range) - 1;
9721 return (i > 15 || range != (1 << i)) ? -1 : i;
9722 }
9723
9724 static void
9725 encode_ldmstm(int from_push_pop_mnem)
9726 {
9727 int base_reg = inst.operands[0].reg;
9728 int range = inst.operands[1].imm;
9729 int one_reg;
9730
9731 inst.instruction |= base_reg << 16;
9732 inst.instruction |= range;
9733
9734 if (inst.operands[1].writeback)
9735 inst.instruction |= LDM_TYPE_2_OR_3;
9736
9737 if (inst.operands[0].writeback)
9738 {
9739 inst.instruction |= WRITE_BACK;
9740 /* Check for unpredictable uses of writeback. */
9741 if (inst.instruction & LOAD_BIT)
9742 {
9743 /* Not allowed in LDM type 2. */
9744 if ((inst.instruction & LDM_TYPE_2_OR_3)
9745 && ((range & (1 << REG_PC)) == 0))
9746 as_warn (_("writeback of base register is UNPREDICTABLE"));
9747 /* Only allowed if base reg not in list for other types. */
9748 else if (range & (1 << base_reg))
9749 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9750 }
9751 else /* STM. */
9752 {
9753 /* Not allowed for type 2. */
9754 if (inst.instruction & LDM_TYPE_2_OR_3)
9755 as_warn (_("writeback of base register is UNPREDICTABLE"));
9756 /* Only allowed if base reg not in list, or first in list. */
9757 else if ((range & (1 << base_reg))
9758 && (range & ((1 << base_reg) - 1)))
9759 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
9760 }
9761 }
9762
9763 /* If PUSH/POP has only one register, then use the A2 encoding. */
9764 one_reg = only_one_reg_in_list (range);
9765 if (from_push_pop_mnem && one_reg >= 0)
9766 {
9767 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9768
9769 if (is_push && one_reg == 13 /* SP */)
9770 /* PR 22483: The A2 encoding cannot be used when
9771 pushing the stack pointer as this is UNPREDICTABLE. */
9772 return;
9773
9774 inst.instruction &= A_COND_MASK;
9775 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9776 inst.instruction |= one_reg << 12;
9777 }
9778 }
9779
9780 static void
9781 do_ldmstm (void)
9782 {
9783 encode_ldmstm (/*from_push_pop_mnem=*/false);
9784 }
9785
9786 /* ARMv5TE load-consecutive (argument parse)
9787 Mode is like LDRH.
9788
9789 LDRccD R, mode
9790 STRccD R, mode. */
9791
9792 static void
9793 do_ldrd (void)
9794 {
9795 constraint (inst.operands[0].reg % 2 != 0,
9796 _("first transfer register must be even"));
9797 constraint (inst.operands[1].present
9798 && inst.operands[1].reg != inst.operands[0].reg + 1,
9799 _("can only transfer two consecutive registers"));
9800 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9801 constraint (!inst.operands[2].isreg, _("'[' expected"));
9802
9803 if (!inst.operands[1].present)
9804 inst.operands[1].reg = inst.operands[0].reg + 1;
9805
9806 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9807 register and the first register written; we have to diagnose
9808 overlap between the base and the second register written here. */
9809
9810 if (inst.operands[2].reg == inst.operands[1].reg
9811 && (inst.operands[2].writeback || inst.operands[2].postind))
9812 as_warn (_("base register written back, and overlaps "
9813 "second transfer register"));
9814
9815 if (!(inst.instruction & V4_STR_BIT))
9816 {
9817 /* For an index-register load, the index register must not overlap the
9818 destination (even if not write-back). */
9819 if (inst.operands[2].immisreg
9820 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9821 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9822 as_warn (_("index register overlaps transfer register"));
9823 }
9824 inst.instruction |= inst.operands[0].reg << 12;
9825 encode_arm_addr_mode_3 (2, /*is_t=*/false);
9826 }
9827
9828 static void
9829 do_ldrex (void)
9830 {
9831 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9832 || inst.operands[1].postind || inst.operands[1].writeback
9833 || inst.operands[1].immisreg || inst.operands[1].shifted
9834 || inst.operands[1].negative
9835 /* This can arise if the programmer has written
9836 strex rN, rM, foo
9837 or if they have mistakenly used a register name as the last
9838 operand, eg:
9839 strex rN, rM, rX
9840 It is very difficult to distinguish between these two cases
9841 because "rX" might actually be a label. ie the register
9842 name has been occluded by a symbol of the same name. So we
9843 just generate a general 'bad addressing mode' type error
9844 message and leave it up to the programmer to discover the
9845 true cause and fix their mistake. */
9846 || (inst.operands[1].reg == REG_PC),
9847 BAD_ADDR_MODE);
9848
9849 constraint (inst.relocs[0].exp.X_op != O_constant
9850 || inst.relocs[0].exp.X_add_number != 0,
9851 _("offset must be zero in ARM encoding"));
9852
9853 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9854
9855 inst.instruction |= inst.operands[0].reg << 12;
9856 inst.instruction |= inst.operands[1].reg << 16;
9857 inst.relocs[0].type = BFD_RELOC_UNUSED;
9858 }
9859
9860 static void
9861 do_ldrexd (void)
9862 {
9863 constraint (inst.operands[0].reg % 2 != 0,
9864 _("even register required"));
9865 constraint (inst.operands[1].present
9866 && inst.operands[1].reg != inst.operands[0].reg + 1,
9867 _("can only load two consecutive registers"));
9868 /* If op 1 were present and equal to PC, this function wouldn't
9869 have been called in the first place. */
9870 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9871
9872 inst.instruction |= inst.operands[0].reg << 12;
9873 inst.instruction |= inst.operands[2].reg << 16;
9874 }
9875
9876 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9877 which is not a multiple of four is UNPREDICTABLE. */
9878 static void
9879 check_ldr_r15_aligned (void)
9880 {
9881 constraint (!(inst.operands[1].immisreg)
9882 && (inst.operands[0].reg == REG_PC
9883 && inst.operands[1].reg == REG_PC
9884 && (inst.relocs[0].exp.X_add_number & 0x3)),
9885 _("ldr to register 15 must be 4-byte aligned"));
9886 }
9887
9888 static void
9889 do_ldst (void)
9890 {
9891 inst.instruction |= inst.operands[0].reg << 12;
9892 if (!inst.operands[1].isreg)
9893 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/false))
9894 return;
9895 encode_arm_addr_mode_2 (1, /*is_t=*/false);
9896 check_ldr_r15_aligned ();
9897 }
9898
9899 static void
9900 do_ldstt (void)
9901 {
9902 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9903 reject [Rn,...]. */
9904 if (inst.operands[1].preind)
9905 {
9906 constraint (inst.relocs[0].exp.X_op != O_constant
9907 || inst.relocs[0].exp.X_add_number != 0,
9908 _("this instruction requires a post-indexed address"));
9909
9910 inst.operands[1].preind = 0;
9911 inst.operands[1].postind = 1;
9912 inst.operands[1].writeback = 1;
9913 }
9914 inst.instruction |= inst.operands[0].reg << 12;
9915 encode_arm_addr_mode_2 (1, /*is_t=*/true);
9916 }
9917
9918 /* Halfword and signed-byte load/store operations. */
9919
9920 static void
9921 do_ldstv4 (void)
9922 {
9923 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9924 inst.instruction |= inst.operands[0].reg << 12;
9925 if (!inst.operands[1].isreg)
9926 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/true))
9927 return;
9928 encode_arm_addr_mode_3 (1, /*is_t=*/false);
9929 }
9930
9931 static void
9932 do_ldsttv4 (void)
9933 {
9934 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9935 reject [Rn,...]. */
9936 if (inst.operands[1].preind)
9937 {
9938 constraint (inst.relocs[0].exp.X_op != O_constant
9939 || inst.relocs[0].exp.X_add_number != 0,
9940 _("this instruction requires a post-indexed address"));
9941
9942 inst.operands[1].preind = 0;
9943 inst.operands[1].postind = 1;
9944 inst.operands[1].writeback = 1;
9945 }
9946 inst.instruction |= inst.operands[0].reg << 12;
9947 encode_arm_addr_mode_3 (1, /*is_t=*/true);
9948 }
9949
9950 /* Co-processor register load/store.
9951 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9952 static void
9953 do_lstc (void)
9954 {
9955 inst.instruction |= inst.operands[0].reg << 8;
9956 inst.instruction |= inst.operands[1].reg << 12;
9957 encode_arm_cp_address (2, true, true, 0);
9958 }
9959
9960 static void
9961 do_mlas (void)
9962 {
9963 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9964 if (inst.operands[0].reg == inst.operands[1].reg
9965 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9966 && !(inst.instruction & 0x00400000))
9967 as_tsktsk (_("Rd and Rm should be different in mla"));
9968
9969 inst.instruction |= inst.operands[0].reg << 16;
9970 inst.instruction |= inst.operands[1].reg;
9971 inst.instruction |= inst.operands[2].reg << 8;
9972 inst.instruction |= inst.operands[3].reg << 12;
9973 }
9974
9975 static void
9976 do_mov (void)
9977 {
9978 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9979 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9980 THUMB1_RELOC_ONLY);
9981 inst.instruction |= inst.operands[0].reg << 12;
9982 encode_arm_shifter_operand (1);
9983 }
9984
9985 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9986 static void
9987 do_mov16 (void)
9988 {
9989 bfd_vma imm;
9990 bool top;
9991
9992 top = (inst.instruction & 0x00400000) != 0;
9993 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
9994 _(":lower16: not allowed in this instruction"));
9995 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
9996 _(":upper16: not allowed in this instruction"));
9997 inst.instruction |= inst.operands[0].reg << 12;
9998 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
9999 {
10000 imm = inst.relocs[0].exp.X_add_number;
10001 /* The value is in two pieces: 0:11, 16:19. */
10002 inst.instruction |= (imm & 0x00000fff);
10003 inst.instruction |= (imm & 0x0000f000) << 4;
10004 }
10005 }
10006
10007 static int
10008 do_vfp_nsyn_mrs (void)
10009 {
10010 if (inst.operands[0].isvec)
10011 {
10012 if (inst.operands[1].reg != 1)
10013 first_error (_("operand 1 must be FPSCR"));
10014 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
10015 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
10016 do_vfp_nsyn_opcode ("fmstat");
10017 }
10018 else if (inst.operands[1].isvec)
10019 do_vfp_nsyn_opcode ("fmrx");
10020 else
10021 return FAIL;
10022
10023 return SUCCESS;
10024 }
10025
10026 static int
10027 do_vfp_nsyn_msr (void)
10028 {
10029 if (inst.operands[0].isvec)
10030 do_vfp_nsyn_opcode ("fmxr");
10031 else
10032 return FAIL;
10033
10034 return SUCCESS;
10035 }
10036
10037 static void
10038 do_vmrs (void)
10039 {
10040 unsigned Rt = inst.operands[0].reg;
10041
10042 if (thumb_mode && Rt == REG_SP)
10043 {
10044 inst.error = BAD_SP;
10045 return;
10046 }
10047
10048 switch (inst.operands[1].reg)
10049 {
10050 /* MVFR2 is only valid for Armv8-A. */
10051 case 5:
10052 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10053 _(BAD_FPU));
10054 break;
10055
10056 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10057 case 1: /* fpscr. */
10058 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10059 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10060 _(BAD_FPU));
10061 break;
10062
10063 case 14: /* fpcxt_ns. */
10064 case 15: /* fpcxt_s. */
10065 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10066 _("selected processor does not support instruction"));
10067 break;
10068
10069 case 2: /* fpscr_nzcvqc. */
10070 case 12: /* vpr. */
10071 case 13: /* p0. */
10072 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10073 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10074 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10075 _("selected processor does not support instruction"));
10076 if (inst.operands[0].reg != 2
10077 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10078 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10079 break;
10080
10081 default:
10082 break;
10083 }
10084
10085 /* APSR_ sets isvec. All other refs to PC are illegal. */
10086 if (!inst.operands[0].isvec && Rt == REG_PC)
10087 {
10088 inst.error = BAD_PC;
10089 return;
10090 }
10091
10092 /* If we get through parsing the register name, we just insert the number
10093 generated into the instruction without further validation. */
10094 inst.instruction |= (inst.operands[1].reg << 16);
10095 inst.instruction |= (Rt << 12);
10096 }
10097
10098 static void
10099 do_vmsr (void)
10100 {
10101 unsigned Rt = inst.operands[1].reg;
10102
10103 if (thumb_mode)
10104 reject_bad_reg (Rt);
10105 else if (Rt == REG_PC)
10106 {
10107 inst.error = BAD_PC;
10108 return;
10109 }
10110
10111 switch (inst.operands[0].reg)
10112 {
10113 /* MVFR2 is only valid for Armv8-A. */
10114 case 5:
10115 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10116 _(BAD_FPU));
10117 break;
10118
10119 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10120 case 1: /* fpcr. */
10121 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10122 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10123 _(BAD_FPU));
10124 break;
10125
10126 case 14: /* fpcxt_ns. */
10127 case 15: /* fpcxt_s. */
10128 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10129 _("selected processor does not support instruction"));
10130 break;
10131
10132 case 2: /* fpscr_nzcvqc. */
10133 case 12: /* vpr. */
10134 case 13: /* p0. */
10135 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10136 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10137 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10138 _("selected processor does not support instruction"));
10139 if (inst.operands[0].reg != 2
10140 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10141 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10142 break;
10143
10144 default:
10145 break;
10146 }
10147
10148 /* If we get through parsing the register name, we just insert the number
10149 generated into the instruction without further validation. */
10150 inst.instruction |= (inst.operands[0].reg << 16);
10151 inst.instruction |= (Rt << 12);
10152 }
10153
10154 static void
10155 do_mrs (void)
10156 {
10157 unsigned br;
10158
10159 if (do_vfp_nsyn_mrs () == SUCCESS)
10160 return;
10161
10162 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10163 inst.instruction |= inst.operands[0].reg << 12;
10164
10165 if (inst.operands[1].isreg)
10166 {
10167 br = inst.operands[1].reg;
10168 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
10169 as_bad (_("bad register for mrs"));
10170 }
10171 else
10172 {
10173 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10174 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10175 != (PSR_c|PSR_f),
10176 _("'APSR', 'CPSR' or 'SPSR' expected"));
10177 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10178 }
10179
10180 inst.instruction |= br;
10181 }
10182
10183 /* Two possible forms:
10184 "{C|S}PSR_<field>, Rm",
10185 "{C|S}PSR_f, #expression". */
10186
10187 static void
10188 do_msr (void)
10189 {
10190 if (do_vfp_nsyn_msr () == SUCCESS)
10191 return;
10192
10193 inst.instruction |= inst.operands[0].imm;
10194 if (inst.operands[1].isreg)
10195 inst.instruction |= inst.operands[1].reg;
10196 else
10197 {
10198 inst.instruction |= INST_IMMEDIATE;
10199 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10200 inst.relocs[0].pc_rel = 0;
10201 }
10202 }
10203
10204 static void
10205 do_mul (void)
10206 {
10207 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10208
10209 if (!inst.operands[2].present)
10210 inst.operands[2].reg = inst.operands[0].reg;
10211 inst.instruction |= inst.operands[0].reg << 16;
10212 inst.instruction |= inst.operands[1].reg;
10213 inst.instruction |= inst.operands[2].reg << 8;
10214
10215 if (inst.operands[0].reg == inst.operands[1].reg
10216 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10217 as_tsktsk (_("Rd and Rm should be different in mul"));
10218 }
10219
10220 /* Long Multiply Parser
10221 UMULL RdLo, RdHi, Rm, Rs
10222 SMULL RdLo, RdHi, Rm, Rs
10223 UMLAL RdLo, RdHi, Rm, Rs
10224 SMLAL RdLo, RdHi, Rm, Rs. */
10225
10226 static void
10227 do_mull (void)
10228 {
10229 inst.instruction |= inst.operands[0].reg << 12;
10230 inst.instruction |= inst.operands[1].reg << 16;
10231 inst.instruction |= inst.operands[2].reg;
10232 inst.instruction |= inst.operands[3].reg << 8;
10233
10234 /* rdhi and rdlo must be different. */
10235 if (inst.operands[0].reg == inst.operands[1].reg)
10236 as_tsktsk (_("rdhi and rdlo must be different"));
10237
10238 /* rdhi, rdlo and rm must all be different before armv6. */
10239 if ((inst.operands[0].reg == inst.operands[2].reg
10240 || inst.operands[1].reg == inst.operands[2].reg)
10241 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10242 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10243 }
10244
10245 static void
10246 do_nop (void)
10247 {
10248 if (inst.operands[0].present
10249 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
10250 {
10251 /* Architectural NOP hints are CPSR sets with no bits selected. */
10252 inst.instruction &= 0xf0000000;
10253 inst.instruction |= 0x0320f000;
10254 if (inst.operands[0].present)
10255 inst.instruction |= inst.operands[0].imm;
10256 }
10257 }
10258
10259 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10260 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10261 Condition defaults to COND_ALWAYS.
10262 Error if Rd, Rn or Rm are R15. */
10263
10264 static void
10265 do_pkhbt (void)
10266 {
10267 inst.instruction |= inst.operands[0].reg << 12;
10268 inst.instruction |= inst.operands[1].reg << 16;
10269 inst.instruction |= inst.operands[2].reg;
10270 if (inst.operands[3].present)
10271 encode_arm_shift (3);
10272 }
10273
10274 /* ARM V6 PKHTB (Argument Parse). */
10275
10276 static void
10277 do_pkhtb (void)
10278 {
10279 if (!inst.operands[3].present)
10280 {
10281 /* If the shift specifier is omitted, turn the instruction
10282 into pkhbt rd, rm, rn. */
10283 inst.instruction &= 0xfff00010;
10284 inst.instruction |= inst.operands[0].reg << 12;
10285 inst.instruction |= inst.operands[1].reg;
10286 inst.instruction |= inst.operands[2].reg << 16;
10287 }
10288 else
10289 {
10290 inst.instruction |= inst.operands[0].reg << 12;
10291 inst.instruction |= inst.operands[1].reg << 16;
10292 inst.instruction |= inst.operands[2].reg;
10293 encode_arm_shift (3);
10294 }
10295 }
10296
10297 /* ARMv5TE: Preload-Cache
10298 MP Extensions: Preload for write
10299
10300 PLD(W) <addr_mode>
10301
10302 Syntactically, like LDR with B=1, W=0, L=1. */
10303
10304 static void
10305 do_pld (void)
10306 {
10307 constraint (!inst.operands[0].isreg,
10308 _("'[' expected after PLD mnemonic"));
10309 constraint (inst.operands[0].postind,
10310 _("post-indexed expression used in preload instruction"));
10311 constraint (inst.operands[0].writeback,
10312 _("writeback used in preload instruction"));
10313 constraint (!inst.operands[0].preind,
10314 _("unindexed addressing used in preload instruction"));
10315 encode_arm_addr_mode_2 (0, /*is_t=*/false);
10316 }
10317
10318 /* ARMv7: PLI <addr_mode> */
10319 static void
10320 do_pli (void)
10321 {
10322 constraint (!inst.operands[0].isreg,
10323 _("'[' expected after PLI 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 inst.instruction &= ~PRE_INDEX;
10332 }
10333
10334 static void
10335 do_push_pop (void)
10336 {
10337 constraint (inst.operands[0].writeback,
10338 _("push/pop do not support {reglist}^"));
10339 inst.operands[1] = inst.operands[0];
10340 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10341 inst.operands[0].isreg = 1;
10342 inst.operands[0].writeback = 1;
10343 inst.operands[0].reg = REG_SP;
10344 encode_ldmstm (/*from_push_pop_mnem=*/true);
10345 }
10346
10347 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10348 word at the specified address and the following word
10349 respectively.
10350 Unconditionally executed.
10351 Error if Rn is R15. */
10352
10353 static void
10354 do_rfe (void)
10355 {
10356 inst.instruction |= inst.operands[0].reg << 16;
10357 if (inst.operands[0].writeback)
10358 inst.instruction |= WRITE_BACK;
10359 }
10360
10361 /* ARM V6 ssat (argument parse). */
10362
10363 static void
10364 do_ssat (void)
10365 {
10366 inst.instruction |= inst.operands[0].reg << 12;
10367 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10368 inst.instruction |= inst.operands[2].reg;
10369
10370 if (inst.operands[3].present)
10371 encode_arm_shift (3);
10372 }
10373
10374 /* ARM V6 usat (argument parse). */
10375
10376 static void
10377 do_usat (void)
10378 {
10379 inst.instruction |= inst.operands[0].reg << 12;
10380 inst.instruction |= inst.operands[1].imm << 16;
10381 inst.instruction |= inst.operands[2].reg;
10382
10383 if (inst.operands[3].present)
10384 encode_arm_shift (3);
10385 }
10386
10387 /* ARM V6 ssat16 (argument parse). */
10388
10389 static void
10390 do_ssat16 (void)
10391 {
10392 inst.instruction |= inst.operands[0].reg << 12;
10393 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10394 inst.instruction |= inst.operands[2].reg;
10395 }
10396
10397 static void
10398 do_usat16 (void)
10399 {
10400 inst.instruction |= inst.operands[0].reg << 12;
10401 inst.instruction |= inst.operands[1].imm << 16;
10402 inst.instruction |= inst.operands[2].reg;
10403 }
10404
10405 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10406 preserving the other bits.
10407
10408 setend <endian_specifier>, where <endian_specifier> is either
10409 BE or LE. */
10410
10411 static void
10412 do_setend (void)
10413 {
10414 if (warn_on_deprecated
10415 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10416 as_tsktsk (_("setend use is deprecated for ARMv8"));
10417
10418 if (inst.operands[0].imm)
10419 inst.instruction |= 0x200;
10420 }
10421
10422 static void
10423 do_shift (void)
10424 {
10425 unsigned int Rm = (inst.operands[1].present
10426 ? inst.operands[1].reg
10427 : inst.operands[0].reg);
10428
10429 inst.instruction |= inst.operands[0].reg << 12;
10430 inst.instruction |= Rm;
10431 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
10432 {
10433 inst.instruction |= inst.operands[2].reg << 8;
10434 inst.instruction |= SHIFT_BY_REG;
10435 /* PR 12854: Error on extraneous shifts. */
10436 constraint (inst.operands[2].shifted,
10437 _("extraneous shift as part of operand to shift insn"));
10438 }
10439 else
10440 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
10441 }
10442
10443 static void
10444 do_smc (void)
10445 {
10446 unsigned int value = inst.relocs[0].exp.X_add_number;
10447 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10448
10449 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10450 inst.relocs[0].pc_rel = 0;
10451 }
10452
10453 static void
10454 do_hvc (void)
10455 {
10456 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10457 inst.relocs[0].pc_rel = 0;
10458 }
10459
10460 static void
10461 do_swi (void)
10462 {
10463 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10464 inst.relocs[0].pc_rel = 0;
10465 }
10466
10467 static void
10468 do_setpan (void)
10469 {
10470 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10471 _("selected processor does not support SETPAN instruction"));
10472
10473 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10474 }
10475
10476 static void
10477 do_t_setpan (void)
10478 {
10479 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10480 _("selected processor does not support SETPAN instruction"));
10481
10482 inst.instruction |= (inst.operands[0].imm << 3);
10483 }
10484
10485 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10486 SMLAxy{cond} Rd,Rm,Rs,Rn
10487 SMLAWy{cond} Rd,Rm,Rs,Rn
10488 Error if any register is R15. */
10489
10490 static void
10491 do_smla (void)
10492 {
10493 inst.instruction |= inst.operands[0].reg << 16;
10494 inst.instruction |= inst.operands[1].reg;
10495 inst.instruction |= inst.operands[2].reg << 8;
10496 inst.instruction |= inst.operands[3].reg << 12;
10497 }
10498
10499 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10500 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10501 Error if any register is R15.
10502 Warning if Rdlo == Rdhi. */
10503
10504 static void
10505 do_smlal (void)
10506 {
10507 inst.instruction |= inst.operands[0].reg << 12;
10508 inst.instruction |= inst.operands[1].reg << 16;
10509 inst.instruction |= inst.operands[2].reg;
10510 inst.instruction |= inst.operands[3].reg << 8;
10511
10512 if (inst.operands[0].reg == inst.operands[1].reg)
10513 as_tsktsk (_("rdhi and rdlo must be different"));
10514 }
10515
10516 /* ARM V5E (El Segundo) signed-multiply (argument parse)
10517 SMULxy{cond} Rd,Rm,Rs
10518 Error if any register is R15. */
10519
10520 static void
10521 do_smul (void)
10522 {
10523 inst.instruction |= inst.operands[0].reg << 16;
10524 inst.instruction |= inst.operands[1].reg;
10525 inst.instruction |= inst.operands[2].reg << 8;
10526 }
10527
10528 /* ARM V6 srs (argument parse). The variable fields in the encoding are
10529 the same for both ARM and Thumb-2. */
10530
10531 static void
10532 do_srs (void)
10533 {
10534 int reg;
10535
10536 if (inst.operands[0].present)
10537 {
10538 reg = inst.operands[0].reg;
10539 constraint (reg != REG_SP, _("SRS base register must be r13"));
10540 }
10541 else
10542 reg = REG_SP;
10543
10544 inst.instruction |= reg << 16;
10545 inst.instruction |= inst.operands[1].imm;
10546 if (inst.operands[0].writeback || inst.operands[1].writeback)
10547 inst.instruction |= WRITE_BACK;
10548 }
10549
10550 /* ARM V6 strex (argument parse). */
10551
10552 static void
10553 do_strex (void)
10554 {
10555 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10556 || inst.operands[2].postind || inst.operands[2].writeback
10557 || inst.operands[2].immisreg || inst.operands[2].shifted
10558 || inst.operands[2].negative
10559 /* See comment in do_ldrex(). */
10560 || (inst.operands[2].reg == REG_PC),
10561 BAD_ADDR_MODE);
10562
10563 constraint (inst.operands[0].reg == inst.operands[1].reg
10564 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10565
10566 constraint (inst.relocs[0].exp.X_op != O_constant
10567 || inst.relocs[0].exp.X_add_number != 0,
10568 _("offset must be zero in ARM encoding"));
10569
10570 inst.instruction |= inst.operands[0].reg << 12;
10571 inst.instruction |= inst.operands[1].reg;
10572 inst.instruction |= inst.operands[2].reg << 16;
10573 inst.relocs[0].type = BFD_RELOC_UNUSED;
10574 }
10575
10576 static void
10577 do_t_strexbh (void)
10578 {
10579 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10580 || inst.operands[2].postind || inst.operands[2].writeback
10581 || inst.operands[2].immisreg || inst.operands[2].shifted
10582 || inst.operands[2].negative,
10583 BAD_ADDR_MODE);
10584
10585 constraint (inst.operands[0].reg == inst.operands[1].reg
10586 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10587
10588 do_rm_rd_rn ();
10589 }
10590
10591 static void
10592 do_strexd (void)
10593 {
10594 constraint (inst.operands[1].reg % 2 != 0,
10595 _("even register required"));
10596 constraint (inst.operands[2].present
10597 && inst.operands[2].reg != inst.operands[1].reg + 1,
10598 _("can only store two consecutive registers"));
10599 /* If op 2 were present and equal to PC, this function wouldn't
10600 have been called in the first place. */
10601 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
10602
10603 constraint (inst.operands[0].reg == inst.operands[1].reg
10604 || inst.operands[0].reg == inst.operands[1].reg + 1
10605 || inst.operands[0].reg == inst.operands[3].reg,
10606 BAD_OVERLAP);
10607
10608 inst.instruction |= inst.operands[0].reg << 12;
10609 inst.instruction |= inst.operands[1].reg;
10610 inst.instruction |= inst.operands[3].reg << 16;
10611 }
10612
10613 /* ARM V8 STRL. */
10614 static void
10615 do_stlex (void)
10616 {
10617 constraint (inst.operands[0].reg == inst.operands[1].reg
10618 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10619
10620 do_rd_rm_rn ();
10621 }
10622
10623 static void
10624 do_t_stlex (void)
10625 {
10626 constraint (inst.operands[0].reg == inst.operands[1].reg
10627 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10628
10629 do_rm_rd_rn ();
10630 }
10631
10632 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10633 extends it to 32-bits, and adds the result to a value in another
10634 register. You can specify a rotation by 0, 8, 16, or 24 bits
10635 before extracting the 16-bit value.
10636 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10637 Condition defaults to COND_ALWAYS.
10638 Error if any register uses R15. */
10639
10640 static void
10641 do_sxtah (void)
10642 {
10643 inst.instruction |= inst.operands[0].reg << 12;
10644 inst.instruction |= inst.operands[1].reg << 16;
10645 inst.instruction |= inst.operands[2].reg;
10646 inst.instruction |= inst.operands[3].imm << 10;
10647 }
10648
10649 /* ARM V6 SXTH.
10650
10651 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10652 Condition defaults to COND_ALWAYS.
10653 Error if any register uses R15. */
10654
10655 static void
10656 do_sxth (void)
10657 {
10658 inst.instruction |= inst.operands[0].reg << 12;
10659 inst.instruction |= inst.operands[1].reg;
10660 inst.instruction |= inst.operands[2].imm << 10;
10661 }
10662 \f
10663 /* VFP instructions. In a logical order: SP variant first, monad
10664 before dyad, arithmetic then move then load/store. */
10665
10666 static void
10667 do_vfp_sp_monadic (void)
10668 {
10669 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10670 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10671 _(BAD_FPU));
10672
10673 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10674 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10675 }
10676
10677 static void
10678 do_vfp_sp_dyadic (void)
10679 {
10680 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10681 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10682 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10683 }
10684
10685 static void
10686 do_vfp_sp_compare_z (void)
10687 {
10688 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10689 }
10690
10691 static void
10692 do_vfp_dp_sp_cvt (void)
10693 {
10694 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10695 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10696 }
10697
10698 static void
10699 do_vfp_sp_dp_cvt (void)
10700 {
10701 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10702 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10703 }
10704
10705 static void
10706 do_vfp_reg_from_sp (void)
10707 {
10708 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10709 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10710 _(BAD_FPU));
10711
10712 inst.instruction |= inst.operands[0].reg << 12;
10713 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10714 }
10715
10716 static void
10717 do_vfp_reg2_from_sp2 (void)
10718 {
10719 constraint (inst.operands[2].imm != 2,
10720 _("only two consecutive VFP SP registers allowed here"));
10721 inst.instruction |= inst.operands[0].reg << 12;
10722 inst.instruction |= inst.operands[1].reg << 16;
10723 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10724 }
10725
10726 static void
10727 do_vfp_sp_from_reg (void)
10728 {
10729 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10730 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10731 _(BAD_FPU));
10732
10733 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
10734 inst.instruction |= inst.operands[1].reg << 12;
10735 }
10736
10737 static void
10738 do_vfp_sp2_from_reg2 (void)
10739 {
10740 constraint (inst.operands[0].imm != 2,
10741 _("only two consecutive VFP SP registers allowed here"));
10742 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
10743 inst.instruction |= inst.operands[1].reg << 12;
10744 inst.instruction |= inst.operands[2].reg << 16;
10745 }
10746
10747 static void
10748 do_vfp_sp_ldst (void)
10749 {
10750 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10751 encode_arm_cp_address (1, false, true, 0);
10752 }
10753
10754 static void
10755 do_vfp_dp_ldst (void)
10756 {
10757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10758 encode_arm_cp_address (1, false, true, 0);
10759 }
10760
10761
10762 static void
10763 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
10764 {
10765 if (inst.operands[0].writeback)
10766 inst.instruction |= WRITE_BACK;
10767 else
10768 constraint (ldstm_type != VFP_LDSTMIA,
10769 _("this addressing mode requires base-register writeback"));
10770 inst.instruction |= inst.operands[0].reg << 16;
10771 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
10772 inst.instruction |= inst.operands[1].imm;
10773 }
10774
10775 static void
10776 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
10777 {
10778 int count;
10779
10780 if (inst.operands[0].writeback)
10781 inst.instruction |= WRITE_BACK;
10782 else
10783 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10784 _("this addressing mode requires base-register writeback"));
10785
10786 inst.instruction |= inst.operands[0].reg << 16;
10787 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10788
10789 count = inst.operands[1].imm << 1;
10790 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10791 count += 1;
10792
10793 inst.instruction |= count;
10794 }
10795
10796 static void
10797 do_vfp_sp_ldstmia (void)
10798 {
10799 vfp_sp_ldstm (VFP_LDSTMIA);
10800 }
10801
10802 static void
10803 do_vfp_sp_ldstmdb (void)
10804 {
10805 vfp_sp_ldstm (VFP_LDSTMDB);
10806 }
10807
10808 static void
10809 do_vfp_dp_ldstmia (void)
10810 {
10811 vfp_dp_ldstm (VFP_LDSTMIA);
10812 }
10813
10814 static void
10815 do_vfp_dp_ldstmdb (void)
10816 {
10817 vfp_dp_ldstm (VFP_LDSTMDB);
10818 }
10819
10820 static void
10821 do_vfp_xp_ldstmia (void)
10822 {
10823 vfp_dp_ldstm (VFP_LDSTMIAX);
10824 }
10825
10826 static void
10827 do_vfp_xp_ldstmdb (void)
10828 {
10829 vfp_dp_ldstm (VFP_LDSTMDBX);
10830 }
10831
10832 static void
10833 do_vfp_dp_rd_rm (void)
10834 {
10835 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10836 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10837 _(BAD_FPU));
10838
10839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10840 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10841 }
10842
10843 static void
10844 do_vfp_dp_rn_rd (void)
10845 {
10846 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10847 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10848 }
10849
10850 static void
10851 do_vfp_dp_rd_rn (void)
10852 {
10853 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10854 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10855 }
10856
10857 static void
10858 do_vfp_dp_rd_rn_rm (void)
10859 {
10860 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10861 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10862 _(BAD_FPU));
10863
10864 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10865 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10866 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10867 }
10868
10869 static void
10870 do_vfp_dp_rd (void)
10871 {
10872 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10873 }
10874
10875 static void
10876 do_vfp_dp_rm_rd_rn (void)
10877 {
10878 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10879 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10880 _(BAD_FPU));
10881
10882 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10883 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10884 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10885 }
10886
10887 /* VFPv3 instructions. */
10888 static void
10889 do_vfp_sp_const (void)
10890 {
10891 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10892 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10893 inst.instruction |= (inst.operands[1].imm & 0x0f);
10894 }
10895
10896 static void
10897 do_vfp_dp_const (void)
10898 {
10899 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10900 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10901 inst.instruction |= (inst.operands[1].imm & 0x0f);
10902 }
10903
10904 static void
10905 vfp_conv (int srcsize)
10906 {
10907 int immbits = srcsize - inst.operands[1].imm;
10908
10909 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10910 {
10911 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10912 i.e. immbits must be in range 0 - 16. */
10913 inst.error = _("immediate value out of range, expected range [0, 16]");
10914 return;
10915 }
10916 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10917 {
10918 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10919 i.e. immbits must be in range 0 - 31. */
10920 inst.error = _("immediate value out of range, expected range [1, 32]");
10921 return;
10922 }
10923
10924 inst.instruction |= (immbits & 1) << 5;
10925 inst.instruction |= (immbits >> 1);
10926 }
10927
10928 static void
10929 do_vfp_sp_conv_16 (void)
10930 {
10931 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10932 vfp_conv (16);
10933 }
10934
10935 static void
10936 do_vfp_dp_conv_16 (void)
10937 {
10938 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10939 vfp_conv (16);
10940 }
10941
10942 static void
10943 do_vfp_sp_conv_32 (void)
10944 {
10945 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10946 vfp_conv (32);
10947 }
10948
10949 static void
10950 do_vfp_dp_conv_32 (void)
10951 {
10952 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10953 vfp_conv (32);
10954 }
10955 \f
10956 /* FPA instructions. Also in a logical order. */
10957
10958 static void
10959 do_fpa_cmp (void)
10960 {
10961 inst.instruction |= inst.operands[0].reg << 16;
10962 inst.instruction |= inst.operands[1].reg;
10963 }
10964
10965 static void
10966 do_fpa_ldmstm (void)
10967 {
10968 inst.instruction |= inst.operands[0].reg << 12;
10969 switch (inst.operands[1].imm)
10970 {
10971 case 1: inst.instruction |= CP_T_X; break;
10972 case 2: inst.instruction |= CP_T_Y; break;
10973 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10974 case 4: break;
10975 default: abort ();
10976 }
10977
10978 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10979 {
10980 /* The instruction specified "ea" or "fd", so we can only accept
10981 [Rn]{!}. The instruction does not really support stacking or
10982 unstacking, so we have to emulate these by setting appropriate
10983 bits and offsets. */
10984 constraint (inst.relocs[0].exp.X_op != O_constant
10985 || inst.relocs[0].exp.X_add_number != 0,
10986 _("this instruction does not support indexing"));
10987
10988 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10989 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
10990
10991 if (!(inst.instruction & INDEX_UP))
10992 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
10993
10994 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10995 {
10996 inst.operands[2].preind = 0;
10997 inst.operands[2].postind = 1;
10998 }
10999 }
11000
11001 encode_arm_cp_address (2, true, true, 0);
11002 }
11003 \f
11004 /* iWMMXt instructions: strictly in alphabetical order. */
11005
11006 static void
11007 do_iwmmxt_tandorc (void)
11008 {
11009 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
11010 }
11011
11012 static void
11013 do_iwmmxt_textrc (void)
11014 {
11015 inst.instruction |= inst.operands[0].reg << 12;
11016 inst.instruction |= inst.operands[1].imm;
11017 }
11018
11019 static void
11020 do_iwmmxt_textrm (void)
11021 {
11022 inst.instruction |= inst.operands[0].reg << 12;
11023 inst.instruction |= inst.operands[1].reg << 16;
11024 inst.instruction |= inst.operands[2].imm;
11025 }
11026
11027 static void
11028 do_iwmmxt_tinsr (void)
11029 {
11030 inst.instruction |= inst.operands[0].reg << 16;
11031 inst.instruction |= inst.operands[1].reg << 12;
11032 inst.instruction |= inst.operands[2].imm;
11033 }
11034
11035 static void
11036 do_iwmmxt_tmia (void)
11037 {
11038 inst.instruction |= inst.operands[0].reg << 5;
11039 inst.instruction |= inst.operands[1].reg;
11040 inst.instruction |= inst.operands[2].reg << 12;
11041 }
11042
11043 static void
11044 do_iwmmxt_waligni (void)
11045 {
11046 inst.instruction |= inst.operands[0].reg << 12;
11047 inst.instruction |= inst.operands[1].reg << 16;
11048 inst.instruction |= inst.operands[2].reg;
11049 inst.instruction |= inst.operands[3].imm << 20;
11050 }
11051
11052 static void
11053 do_iwmmxt_wmerge (void)
11054 {
11055 inst.instruction |= inst.operands[0].reg << 12;
11056 inst.instruction |= inst.operands[1].reg << 16;
11057 inst.instruction |= inst.operands[2].reg;
11058 inst.instruction |= inst.operands[3].imm << 21;
11059 }
11060
11061 static void
11062 do_iwmmxt_wmov (void)
11063 {
11064 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
11065 inst.instruction |= inst.operands[0].reg << 12;
11066 inst.instruction |= inst.operands[1].reg << 16;
11067 inst.instruction |= inst.operands[1].reg;
11068 }
11069
11070 static void
11071 do_iwmmxt_wldstbh (void)
11072 {
11073 int reloc;
11074 inst.instruction |= inst.operands[0].reg << 12;
11075 if (thumb_mode)
11076 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
11077 else
11078 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
11079 encode_arm_cp_address (1, true, false, reloc);
11080 }
11081
11082 static void
11083 do_iwmmxt_wldstw (void)
11084 {
11085 /* RIWR_RIWC clears .isreg for a control register. */
11086 if (!inst.operands[0].isreg)
11087 {
11088 constraint (inst.cond != COND_ALWAYS, BAD_COND);
11089 inst.instruction |= 0xf0000000;
11090 }
11091
11092 inst.instruction |= inst.operands[0].reg << 12;
11093 encode_arm_cp_address (1, true, true, 0);
11094 }
11095
11096 static void
11097 do_iwmmxt_wldstd (void)
11098 {
11099 inst.instruction |= inst.operands[0].reg << 12;
11100 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
11101 && inst.operands[1].immisreg)
11102 {
11103 inst.instruction &= ~0x1a000ff;
11104 inst.instruction |= (0xfU << 28);
11105 if (inst.operands[1].preind)
11106 inst.instruction |= PRE_INDEX;
11107 if (!inst.operands[1].negative)
11108 inst.instruction |= INDEX_UP;
11109 if (inst.operands[1].writeback)
11110 inst.instruction |= WRITE_BACK;
11111 inst.instruction |= inst.operands[1].reg << 16;
11112 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11113 inst.instruction |= inst.operands[1].imm;
11114 }
11115 else
11116 encode_arm_cp_address (1, true, false, 0);
11117 }
11118
11119 static void
11120 do_iwmmxt_wshufh (void)
11121 {
11122 inst.instruction |= inst.operands[0].reg << 12;
11123 inst.instruction |= inst.operands[1].reg << 16;
11124 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11125 inst.instruction |= (inst.operands[2].imm & 0x0f);
11126 }
11127
11128 static void
11129 do_iwmmxt_wzero (void)
11130 {
11131 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11132 inst.instruction |= inst.operands[0].reg;
11133 inst.instruction |= inst.operands[0].reg << 12;
11134 inst.instruction |= inst.operands[0].reg << 16;
11135 }
11136
11137 static void
11138 do_iwmmxt_wrwrwr_or_imm5 (void)
11139 {
11140 if (inst.operands[2].isreg)
11141 do_rd_rn_rm ();
11142 else {
11143 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11144 _("immediate operand requires iWMMXt2"));
11145 do_rd_rn ();
11146 if (inst.operands[2].imm == 0)
11147 {
11148 switch ((inst.instruction >> 20) & 0xf)
11149 {
11150 case 4:
11151 case 5:
11152 case 6:
11153 case 7:
11154 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11155 inst.operands[2].imm = 16;
11156 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11157 break;
11158 case 8:
11159 case 9:
11160 case 10:
11161 case 11:
11162 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11163 inst.operands[2].imm = 32;
11164 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11165 break;
11166 case 12:
11167 case 13:
11168 case 14:
11169 case 15:
11170 {
11171 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11172 unsigned long wrn;
11173 wrn = (inst.instruction >> 16) & 0xf;
11174 inst.instruction &= 0xff0fff0f;
11175 inst.instruction |= wrn;
11176 /* Bail out here; the instruction is now assembled. */
11177 return;
11178 }
11179 }
11180 }
11181 /* Map 32 -> 0, etc. */
11182 inst.operands[2].imm &= 0x1f;
11183 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
11184 }
11185 }
11186 \f
11187 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11188 operations first, then control, shift, and load/store. */
11189
11190 /* Insns like "foo X,Y,Z". */
11191
11192 static void
11193 do_mav_triple (void)
11194 {
11195 inst.instruction |= inst.operands[0].reg << 16;
11196 inst.instruction |= inst.operands[1].reg;
11197 inst.instruction |= inst.operands[2].reg << 12;
11198 }
11199
11200 /* Insns like "foo W,X,Y,Z".
11201 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
11202
11203 static void
11204 do_mav_quad (void)
11205 {
11206 inst.instruction |= inst.operands[0].reg << 5;
11207 inst.instruction |= inst.operands[1].reg << 12;
11208 inst.instruction |= inst.operands[2].reg << 16;
11209 inst.instruction |= inst.operands[3].reg;
11210 }
11211
11212 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11213 static void
11214 do_mav_dspsc (void)
11215 {
11216 inst.instruction |= inst.operands[1].reg << 12;
11217 }
11218
11219 /* Maverick shift immediate instructions.
11220 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11221 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
11222
11223 static void
11224 do_mav_shift (void)
11225 {
11226 int imm = inst.operands[2].imm;
11227
11228 inst.instruction |= inst.operands[0].reg << 12;
11229 inst.instruction |= inst.operands[1].reg << 16;
11230
11231 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11232 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11233 Bit 4 should be 0. */
11234 imm = (imm & 0xf) | ((imm & 0x70) << 1);
11235
11236 inst.instruction |= imm;
11237 }
11238 \f
11239 /* XScale instructions. Also sorted arithmetic before move. */
11240
11241 /* Xscale multiply-accumulate (argument parse)
11242 MIAcc acc0,Rm,Rs
11243 MIAPHcc acc0,Rm,Rs
11244 MIAxycc acc0,Rm,Rs. */
11245
11246 static void
11247 do_xsc_mia (void)
11248 {
11249 inst.instruction |= inst.operands[1].reg;
11250 inst.instruction |= inst.operands[2].reg << 12;
11251 }
11252
11253 /* Xscale move-accumulator-register (argument parse)
11254
11255 MARcc acc0,RdLo,RdHi. */
11256
11257 static void
11258 do_xsc_mar (void)
11259 {
11260 inst.instruction |= inst.operands[1].reg << 12;
11261 inst.instruction |= inst.operands[2].reg << 16;
11262 }
11263
11264 /* Xscale move-register-accumulator (argument parse)
11265
11266 MRAcc RdLo,RdHi,acc0. */
11267
11268 static void
11269 do_xsc_mra (void)
11270 {
11271 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11272 inst.instruction |= inst.operands[0].reg << 12;
11273 inst.instruction |= inst.operands[1].reg << 16;
11274 }
11275 \f
11276 /* Encoding functions relevant only to Thumb. */
11277
11278 /* inst.operands[i] is a shifted-register operand; encode
11279 it into inst.instruction in the format used by Thumb32. */
11280
11281 static void
11282 encode_thumb32_shifted_operand (int i)
11283 {
11284 unsigned int value = inst.relocs[0].exp.X_add_number;
11285 unsigned int shift = inst.operands[i].shift_kind;
11286
11287 constraint (inst.operands[i].immisreg,
11288 _("shift by register not allowed in thumb mode"));
11289 inst.instruction |= inst.operands[i].reg;
11290 if (shift == SHIFT_RRX)
11291 inst.instruction |= SHIFT_ROR << 4;
11292 else
11293 {
11294 constraint (inst.relocs[0].exp.X_op != O_constant,
11295 _("expression too complex"));
11296
11297 constraint (value > 32
11298 || (value == 32 && (shift == SHIFT_LSL
11299 || shift == SHIFT_ROR)),
11300 _("shift expression is too large"));
11301
11302 if (value == 0)
11303 shift = SHIFT_LSL;
11304 else if (value == 32)
11305 value = 0;
11306
11307 inst.instruction |= shift << 4;
11308 inst.instruction |= (value & 0x1c) << 10;
11309 inst.instruction |= (value & 0x03) << 6;
11310 }
11311 }
11312
11313
11314 /* inst.operands[i] was set up by parse_address. Encode it into a
11315 Thumb32 format load or store instruction. Reject forms that cannot
11316 be used with such instructions. If is_t is true, reject forms that
11317 cannot be used with a T instruction; if is_d is true, reject forms
11318 that cannot be used with a D instruction. If it is a store insn,
11319 reject PC in Rn. */
11320
11321 static void
11322 encode_thumb32_addr_mode (int i, bool is_t, bool is_d)
11323 {
11324 const bool is_pc = (inst.operands[i].reg == REG_PC);
11325
11326 constraint (!inst.operands[i].isreg,
11327 _("Instruction does not support =N addresses"));
11328
11329 inst.instruction |= inst.operands[i].reg << 16;
11330 if (inst.operands[i].immisreg)
11331 {
11332 constraint (is_pc, BAD_PC_ADDRESSING);
11333 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11334 constraint (inst.operands[i].negative,
11335 _("Thumb does not support negative register indexing"));
11336 constraint (inst.operands[i].postind,
11337 _("Thumb does not support register post-indexing"));
11338 constraint (inst.operands[i].writeback,
11339 _("Thumb does not support register indexing with writeback"));
11340 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11341 _("Thumb supports only LSL in shifted register indexing"));
11342
11343 inst.instruction |= inst.operands[i].imm;
11344 if (inst.operands[i].shifted)
11345 {
11346 constraint (inst.relocs[0].exp.X_op != O_constant,
11347 _("expression too complex"));
11348 constraint (inst.relocs[0].exp.X_add_number < 0
11349 || inst.relocs[0].exp.X_add_number > 3,
11350 _("shift out of range"));
11351 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11352 }
11353 inst.relocs[0].type = BFD_RELOC_UNUSED;
11354 }
11355 else if (inst.operands[i].preind)
11356 {
11357 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
11358 constraint (is_t && inst.operands[i].writeback,
11359 _("cannot use writeback with this instruction"));
11360 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11361 BAD_PC_ADDRESSING);
11362
11363 if (is_d)
11364 {
11365 inst.instruction |= 0x01000000;
11366 if (inst.operands[i].writeback)
11367 inst.instruction |= 0x00200000;
11368 }
11369 else
11370 {
11371 inst.instruction |= 0x00000c00;
11372 if (inst.operands[i].writeback)
11373 inst.instruction |= 0x00000100;
11374 }
11375 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11376 }
11377 else if (inst.operands[i].postind)
11378 {
11379 gas_assert (inst.operands[i].writeback);
11380 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11381 constraint (is_t, _("cannot use post-indexing with this instruction"));
11382
11383 if (is_d)
11384 inst.instruction |= 0x00200000;
11385 else
11386 inst.instruction |= 0x00000900;
11387 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11388 }
11389 else /* unindexed - only for coprocessor */
11390 inst.error = _("instruction does not accept unindexed addressing");
11391 }
11392
11393 /* Table of Thumb instructions which exist in 16- and/or 32-bit
11394 encodings (the latter only in post-V6T2 cores). The index is the
11395 value used in the insns table below. When there is more than one
11396 possible 16-bit encoding for the instruction, this table always
11397 holds variant (1).
11398 Also contains several pseudo-instructions used during relaxation. */
11399 #define T16_32_TAB \
11400 X(_adc, 4140, eb400000), \
11401 X(_adcs, 4140, eb500000), \
11402 X(_add, 1c00, eb000000), \
11403 X(_adds, 1c00, eb100000), \
11404 X(_addi, 0000, f1000000), \
11405 X(_addis, 0000, f1100000), \
11406 X(_add_pc,000f, f20f0000), \
11407 X(_add_sp,000d, f10d0000), \
11408 X(_adr, 000f, f20f0000), \
11409 X(_and, 4000, ea000000), \
11410 X(_ands, 4000, ea100000), \
11411 X(_asr, 1000, fa40f000), \
11412 X(_asrs, 1000, fa50f000), \
11413 X(_aut, 0000, f3af802d), \
11414 X(_autg, 0000, fb500f00), \
11415 X(_b, e000, f000b000), \
11416 X(_bcond, d000, f0008000), \
11417 X(_bf, 0000, f040e001), \
11418 X(_bfcsel,0000, f000e001), \
11419 X(_bfx, 0000, f060e001), \
11420 X(_bfl, 0000, f000c001), \
11421 X(_bflx, 0000, f070e001), \
11422 X(_bic, 4380, ea200000), \
11423 X(_bics, 4380, ea300000), \
11424 X(_bxaut, 0000, fb500f10), \
11425 X(_cinc, 0000, ea509000), \
11426 X(_cinv, 0000, ea50a000), \
11427 X(_cmn, 42c0, eb100f00), \
11428 X(_cmp, 2800, ebb00f00), \
11429 X(_cneg, 0000, ea50b000), \
11430 X(_cpsie, b660, f3af8400), \
11431 X(_cpsid, b670, f3af8600), \
11432 X(_cpy, 4600, ea4f0000), \
11433 X(_csel, 0000, ea508000), \
11434 X(_cset, 0000, ea5f900f), \
11435 X(_csetm, 0000, ea5fa00f), \
11436 X(_csinc, 0000, ea509000), \
11437 X(_csinv, 0000, ea50a000), \
11438 X(_csneg, 0000, ea50b000), \
11439 X(_dec_sp,80dd, f1ad0d00), \
11440 X(_dls, 0000, f040e001), \
11441 X(_dlstp, 0000, f000e001), \
11442 X(_eor, 4040, ea800000), \
11443 X(_eors, 4040, ea900000), \
11444 X(_inc_sp,00dd, f10d0d00), \
11445 X(_lctp, 0000, f00fe001), \
11446 X(_ldmia, c800, e8900000), \
11447 X(_ldr, 6800, f8500000), \
11448 X(_ldrb, 7800, f8100000), \
11449 X(_ldrh, 8800, f8300000), \
11450 X(_ldrsb, 5600, f9100000), \
11451 X(_ldrsh, 5e00, f9300000), \
11452 X(_ldr_pc,4800, f85f0000), \
11453 X(_ldr_pc2,4800, f85f0000), \
11454 X(_ldr_sp,9800, f85d0000), \
11455 X(_le, 0000, f00fc001), \
11456 X(_letp, 0000, f01fc001), \
11457 X(_lsl, 0000, fa00f000), \
11458 X(_lsls, 0000, fa10f000), \
11459 X(_lsr, 0800, fa20f000), \
11460 X(_lsrs, 0800, fa30f000), \
11461 X(_mov, 2000, ea4f0000), \
11462 X(_movs, 2000, ea5f0000), \
11463 X(_mul, 4340, fb00f000), \
11464 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11465 X(_mvn, 43c0, ea6f0000), \
11466 X(_mvns, 43c0, ea7f0000), \
11467 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11468 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11469 X(_orr, 4300, ea400000), \
11470 X(_orrs, 4300, ea500000), \
11471 X(_pac, 0000, f3af801d), \
11472 X(_pacbti, 0000, f3af800d), \
11473 X(_pacg, 0000, fb60f000), \
11474 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11475 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11476 X(_rev, ba00, fa90f080), \
11477 X(_rev16, ba40, fa90f090), \
11478 X(_revsh, bac0, fa90f0b0), \
11479 X(_ror, 41c0, fa60f000), \
11480 X(_rors, 41c0, fa70f000), \
11481 X(_sbc, 4180, eb600000), \
11482 X(_sbcs, 4180, eb700000), \
11483 X(_stmia, c000, e8800000), \
11484 X(_str, 6000, f8400000), \
11485 X(_strb, 7000, f8000000), \
11486 X(_strh, 8000, f8200000), \
11487 X(_str_sp,9000, f84d0000), \
11488 X(_sub, 1e00, eba00000), \
11489 X(_subs, 1e00, ebb00000), \
11490 X(_subi, 8000, f1a00000), \
11491 X(_subis, 8000, f1b00000), \
11492 X(_sxtb, b240, fa4ff080), \
11493 X(_sxth, b200, fa0ff080), \
11494 X(_tst, 4200, ea100f00), \
11495 X(_uxtb, b2c0, fa5ff080), \
11496 X(_uxth, b280, fa1ff080), \
11497 X(_nop, bf00, f3af8000), \
11498 X(_yield, bf10, f3af8001), \
11499 X(_wfe, bf20, f3af8002), \
11500 X(_wfi, bf30, f3af8003), \
11501 X(_wls, 0000, f040c001), \
11502 X(_wlstp, 0000, f000c001), \
11503 X(_sev, bf40, f3af8004), \
11504 X(_sevl, bf50, f3af8005), \
11505 X(_udf, de00, f7f0a000)
11506
11507 /* To catch errors in encoding functions, the codes are all offset by
11508 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11509 as 16-bit instructions. */
11510 #define X(a,b,c) T_MNEM##a
11511 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11512 #undef X
11513
11514 #define X(a,b,c) 0x##b
11515 static const unsigned short thumb_op16[] = { T16_32_TAB };
11516 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11517 #undef X
11518
11519 #define X(a,b,c) 0x##c
11520 static const unsigned int thumb_op32[] = { T16_32_TAB };
11521 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11522 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
11523 #undef X
11524 #undef T16_32_TAB
11525
11526 /* Thumb instruction encoders, in alphabetical order. */
11527
11528 /* ADDW or SUBW. */
11529
11530 static void
11531 do_t_add_sub_w (void)
11532 {
11533 int Rd, Rn;
11534
11535 Rd = inst.operands[0].reg;
11536 Rn = inst.operands[1].reg;
11537
11538 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11539 is the SP-{plus,minus}-immediate form of the instruction. */
11540 if (Rn == REG_SP)
11541 constraint (Rd == REG_PC, BAD_PC);
11542 else
11543 reject_bad_reg (Rd);
11544
11545 inst.instruction |= (Rn << 16) | (Rd << 8);
11546 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11547 }
11548
11549 /* Parse an add or subtract instruction. We get here with inst.instruction
11550 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
11551
11552 static void
11553 do_t_add_sub (void)
11554 {
11555 int Rd, Rs, Rn;
11556
11557 Rd = inst.operands[0].reg;
11558 Rs = (inst.operands[1].present
11559 ? inst.operands[1].reg /* Rd, Rs, foo */
11560 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11561
11562 if (Rd == REG_PC)
11563 set_pred_insn_type_last ();
11564
11565 if (unified_syntax)
11566 {
11567 bool flags;
11568 bool narrow;
11569 int opcode;
11570
11571 flags = (inst.instruction == T_MNEM_adds
11572 || inst.instruction == T_MNEM_subs);
11573 if (flags)
11574 narrow = !in_pred_block ();
11575 else
11576 narrow = in_pred_block ();
11577 if (!inst.operands[2].isreg)
11578 {
11579 int add;
11580
11581 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11582 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11583
11584 add = (inst.instruction == T_MNEM_add
11585 || inst.instruction == T_MNEM_adds);
11586 opcode = 0;
11587 if (inst.size_req != 4)
11588 {
11589 /* Attempt to use a narrow opcode, with relaxation if
11590 appropriate. */
11591 if (Rd == REG_SP && Rs == REG_SP && !flags)
11592 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11593 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11594 opcode = T_MNEM_add_sp;
11595 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11596 opcode = T_MNEM_add_pc;
11597 else if (Rd <= 7 && Rs <= 7 && narrow)
11598 {
11599 if (flags)
11600 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11601 else
11602 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11603 }
11604 if (opcode)
11605 {
11606 inst.instruction = THUMB_OP16(opcode);
11607 inst.instruction |= (Rd << 4) | Rs;
11608 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11609 || (inst.relocs[0].type
11610 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
11611 {
11612 if (inst.size_req == 2)
11613 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11614 else
11615 inst.relax = opcode;
11616 }
11617 }
11618 else
11619 constraint (inst.size_req == 2, _("cannot honor width suffix"));
11620 }
11621 if (inst.size_req == 4
11622 || (inst.size_req != 2 && !opcode))
11623 {
11624 constraint ((inst.relocs[0].type
11625 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11626 && (inst.relocs[0].type
11627 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
11628 THUMB1_RELOC_ONLY);
11629 if (Rd == REG_PC)
11630 {
11631 constraint (add, BAD_PC);
11632 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11633 _("only SUBS PC, LR, #const allowed"));
11634 constraint (inst.relocs[0].exp.X_op != O_constant,
11635 _("expression too complex"));
11636 constraint (inst.relocs[0].exp.X_add_number < 0
11637 || inst.relocs[0].exp.X_add_number > 0xff,
11638 _("immediate value out of range"));
11639 inst.instruction = T2_SUBS_PC_LR
11640 | inst.relocs[0].exp.X_add_number;
11641 inst.relocs[0].type = BFD_RELOC_UNUSED;
11642 return;
11643 }
11644 else if (Rs == REG_PC)
11645 {
11646 /* Always use addw/subw. */
11647 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
11648 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11649 }
11650 else
11651 {
11652 inst.instruction = THUMB_OP32 (inst.instruction);
11653 inst.instruction = (inst.instruction & 0xe1ffffff)
11654 | 0x10000000;
11655 if (flags)
11656 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11657 else
11658 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
11659 }
11660 inst.instruction |= Rd << 8;
11661 inst.instruction |= Rs << 16;
11662 }
11663 }
11664 else
11665 {
11666 unsigned int value = inst.relocs[0].exp.X_add_number;
11667 unsigned int shift = inst.operands[2].shift_kind;
11668
11669 Rn = inst.operands[2].reg;
11670 /* See if we can do this with a 16-bit instruction. */
11671 if (!inst.operands[2].shifted && inst.size_req != 4)
11672 {
11673 if (Rd > 7 || Rs > 7 || Rn > 7)
11674 narrow = false;
11675
11676 if (narrow)
11677 {
11678 inst.instruction = ((inst.instruction == T_MNEM_adds
11679 || inst.instruction == T_MNEM_add)
11680 ? T_OPCODE_ADD_R3
11681 : T_OPCODE_SUB_R3);
11682 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11683 return;
11684 }
11685
11686 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
11687 {
11688 /* Thumb-1 cores (except v6-M) require at least one high
11689 register in a narrow non flag setting add. */
11690 if (Rd > 7 || Rn > 7
11691 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11692 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
11693 {
11694 if (Rd == Rn)
11695 {
11696 Rn = Rs;
11697 Rs = Rd;
11698 }
11699 inst.instruction = T_OPCODE_ADD_HI;
11700 inst.instruction |= (Rd & 8) << 4;
11701 inst.instruction |= (Rd & 7);
11702 inst.instruction |= Rn << 3;
11703 return;
11704 }
11705 }
11706 }
11707
11708 constraint (Rd == REG_PC, BAD_PC);
11709 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11710 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11711 constraint (Rs == REG_PC, BAD_PC);
11712 reject_bad_reg (Rn);
11713
11714 /* If we get here, it can't be done in 16 bits. */
11715 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11716 _("shift must be constant"));
11717 inst.instruction = THUMB_OP32 (inst.instruction);
11718 inst.instruction |= Rd << 8;
11719 inst.instruction |= Rs << 16;
11720 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11721 _("shift value over 3 not allowed in thumb mode"));
11722 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11723 _("only LSL shift allowed in thumb mode"));
11724 encode_thumb32_shifted_operand (2);
11725 }
11726 }
11727 else
11728 {
11729 constraint (inst.instruction == T_MNEM_adds
11730 || inst.instruction == T_MNEM_subs,
11731 BAD_THUMB32);
11732
11733 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
11734 {
11735 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11736 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11737 BAD_HIREG);
11738
11739 inst.instruction = (inst.instruction == T_MNEM_add
11740 ? 0x0000 : 0x8000);
11741 inst.instruction |= (Rd << 4) | Rs;
11742 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11743 return;
11744 }
11745
11746 Rn = inst.operands[2].reg;
11747 constraint (inst.operands[2].shifted, _("unshifted register required"));
11748
11749 /* We now have Rd, Rs, and Rn set to registers. */
11750 if (Rd > 7 || Rs > 7 || Rn > 7)
11751 {
11752 /* Can't do this for SUB. */
11753 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11754 inst.instruction = T_OPCODE_ADD_HI;
11755 inst.instruction |= (Rd & 8) << 4;
11756 inst.instruction |= (Rd & 7);
11757 if (Rs == Rd)
11758 inst.instruction |= Rn << 3;
11759 else if (Rn == Rd)
11760 inst.instruction |= Rs << 3;
11761 else
11762 constraint (1, _("dest must overlap one source register"));
11763 }
11764 else
11765 {
11766 inst.instruction = (inst.instruction == T_MNEM_add
11767 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11768 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11769 }
11770 }
11771 }
11772
11773 static void
11774 do_t_adr (void)
11775 {
11776 unsigned Rd;
11777
11778 Rd = inst.operands[0].reg;
11779 reject_bad_reg (Rd);
11780
11781 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
11782 {
11783 /* Defer to section relaxation. */
11784 inst.relax = inst.instruction;
11785 inst.instruction = THUMB_OP16 (inst.instruction);
11786 inst.instruction |= Rd << 4;
11787 }
11788 else if (unified_syntax && inst.size_req != 2)
11789 {
11790 /* Generate a 32-bit opcode. */
11791 inst.instruction = THUMB_OP32 (inst.instruction);
11792 inst.instruction |= Rd << 8;
11793 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11794 inst.relocs[0].pc_rel = 1;
11795 }
11796 else
11797 {
11798 /* Generate a 16-bit opcode. */
11799 inst.instruction = THUMB_OP16 (inst.instruction);
11800 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11801 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11802 inst.relocs[0].pc_rel = 1;
11803 inst.instruction |= Rd << 4;
11804 }
11805
11806 if (inst.relocs[0].exp.X_op == O_symbol
11807 && inst.relocs[0].exp.X_add_symbol != NULL
11808 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11809 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11810 inst.relocs[0].exp.X_add_number += 1;
11811 }
11812
11813 /* Arithmetic instructions for which there is just one 16-bit
11814 instruction encoding, and it allows only two low registers.
11815 For maximal compatibility with ARM syntax, we allow three register
11816 operands even when Thumb-32 instructions are not available, as long
11817 as the first two are identical. For instance, both "sbc r0,r1" and
11818 "sbc r0,r0,r1" are allowed. */
11819 static void
11820 do_t_arit3 (void)
11821 {
11822 int Rd, Rs, Rn;
11823
11824 Rd = inst.operands[0].reg;
11825 Rs = (inst.operands[1].present
11826 ? inst.operands[1].reg /* Rd, Rs, foo */
11827 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11828 Rn = inst.operands[2].reg;
11829
11830 reject_bad_reg (Rd);
11831 reject_bad_reg (Rs);
11832 if (inst.operands[2].isreg)
11833 reject_bad_reg (Rn);
11834
11835 if (unified_syntax)
11836 {
11837 if (!inst.operands[2].isreg)
11838 {
11839 /* For an immediate, we always generate a 32-bit opcode;
11840 section relaxation will shrink it later if possible. */
11841 inst.instruction = THUMB_OP32 (inst.instruction);
11842 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11843 inst.instruction |= Rd << 8;
11844 inst.instruction |= Rs << 16;
11845 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11846 }
11847 else
11848 {
11849 bool narrow;
11850
11851 /* See if we can do this with a 16-bit instruction. */
11852 if (THUMB_SETS_FLAGS (inst.instruction))
11853 narrow = !in_pred_block ();
11854 else
11855 narrow = in_pred_block ();
11856
11857 if (Rd > 7 || Rn > 7 || Rs > 7)
11858 narrow = false;
11859 if (inst.operands[2].shifted)
11860 narrow = false;
11861 if (inst.size_req == 4)
11862 narrow = false;
11863
11864 if (narrow
11865 && Rd == Rs)
11866 {
11867 inst.instruction = THUMB_OP16 (inst.instruction);
11868 inst.instruction |= Rd;
11869 inst.instruction |= Rn << 3;
11870 return;
11871 }
11872
11873 /* If we get here, it can't be done in 16 bits. */
11874 constraint (inst.operands[2].shifted
11875 && inst.operands[2].immisreg,
11876 _("shift must be constant"));
11877 inst.instruction = THUMB_OP32 (inst.instruction);
11878 inst.instruction |= Rd << 8;
11879 inst.instruction |= Rs << 16;
11880 encode_thumb32_shifted_operand (2);
11881 }
11882 }
11883 else
11884 {
11885 /* On its face this is a lie - the instruction does set the
11886 flags. However, the only supported mnemonic in this mode
11887 says it doesn't. */
11888 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11889
11890 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11891 _("unshifted register required"));
11892 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11893 constraint (Rd != Rs,
11894 _("dest and source1 must be the same register"));
11895
11896 inst.instruction = THUMB_OP16 (inst.instruction);
11897 inst.instruction |= Rd;
11898 inst.instruction |= Rn << 3;
11899 }
11900 }
11901
11902 /* Similarly, but for instructions where the arithmetic operation is
11903 commutative, so we can allow either of them to be different from
11904 the destination operand in a 16-bit instruction. For instance, all
11905 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11906 accepted. */
11907 static void
11908 do_t_arit3c (void)
11909 {
11910 int Rd, Rs, Rn;
11911
11912 Rd = inst.operands[0].reg;
11913 Rs = (inst.operands[1].present
11914 ? inst.operands[1].reg /* Rd, Rs, foo */
11915 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11916 Rn = inst.operands[2].reg;
11917
11918 reject_bad_reg (Rd);
11919 reject_bad_reg (Rs);
11920 if (inst.operands[2].isreg)
11921 reject_bad_reg (Rn);
11922
11923 if (unified_syntax)
11924 {
11925 if (!inst.operands[2].isreg)
11926 {
11927 /* For an immediate, we always generate a 32-bit opcode;
11928 section relaxation will shrink it later if possible. */
11929 inst.instruction = THUMB_OP32 (inst.instruction);
11930 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11931 inst.instruction |= Rd << 8;
11932 inst.instruction |= Rs << 16;
11933 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11934 }
11935 else
11936 {
11937 bool narrow;
11938
11939 /* See if we can do this with a 16-bit instruction. */
11940 if (THUMB_SETS_FLAGS (inst.instruction))
11941 narrow = !in_pred_block ();
11942 else
11943 narrow = in_pred_block ();
11944
11945 if (Rd > 7 || Rn > 7 || Rs > 7)
11946 narrow = false;
11947 if (inst.operands[2].shifted)
11948 narrow = false;
11949 if (inst.size_req == 4)
11950 narrow = false;
11951
11952 if (narrow)
11953 {
11954 if (Rd == Rs)
11955 {
11956 inst.instruction = THUMB_OP16 (inst.instruction);
11957 inst.instruction |= Rd;
11958 inst.instruction |= Rn << 3;
11959 return;
11960 }
11961 if (Rd == Rn)
11962 {
11963 inst.instruction = THUMB_OP16 (inst.instruction);
11964 inst.instruction |= Rd;
11965 inst.instruction |= Rs << 3;
11966 return;
11967 }
11968 }
11969
11970 /* If we get here, it can't be done in 16 bits. */
11971 constraint (inst.operands[2].shifted
11972 && inst.operands[2].immisreg,
11973 _("shift must be constant"));
11974 inst.instruction = THUMB_OP32 (inst.instruction);
11975 inst.instruction |= Rd << 8;
11976 inst.instruction |= Rs << 16;
11977 encode_thumb32_shifted_operand (2);
11978 }
11979 }
11980 else
11981 {
11982 /* On its face this is a lie - the instruction does set the
11983 flags. However, the only supported mnemonic in this mode
11984 says it doesn't. */
11985 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11986
11987 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11988 _("unshifted register required"));
11989 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11990
11991 inst.instruction = THUMB_OP16 (inst.instruction);
11992 inst.instruction |= Rd;
11993
11994 if (Rd == Rs)
11995 inst.instruction |= Rn << 3;
11996 else if (Rd == Rn)
11997 inst.instruction |= Rs << 3;
11998 else
11999 constraint (1, _("dest must overlap one source register"));
12000 }
12001 }
12002
12003 static void
12004 do_t_bfc (void)
12005 {
12006 unsigned Rd;
12007 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
12008 constraint (msb > 32, _("bit-field extends past end of register"));
12009 /* The instruction encoding stores the LSB and MSB,
12010 not the LSB and width. */
12011 Rd = inst.operands[0].reg;
12012 reject_bad_reg (Rd);
12013 inst.instruction |= Rd << 8;
12014 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
12015 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
12016 inst.instruction |= msb - 1;
12017 }
12018
12019 static void
12020 do_t_bfi (void)
12021 {
12022 int Rd, Rn;
12023 unsigned int msb;
12024
12025 Rd = inst.operands[0].reg;
12026 reject_bad_reg (Rd);
12027
12028 /* #0 in second position is alternative syntax for bfc, which is
12029 the same instruction but with REG_PC in the Rm field. */
12030 if (!inst.operands[1].isreg)
12031 Rn = REG_PC;
12032 else
12033 {
12034 Rn = inst.operands[1].reg;
12035 reject_bad_reg (Rn);
12036 }
12037
12038 msb = inst.operands[2].imm + inst.operands[3].imm;
12039 constraint (msb > 32, _("bit-field extends past end of register"));
12040 /* The instruction encoding stores the LSB and MSB,
12041 not the LSB and width. */
12042 inst.instruction |= Rd << 8;
12043 inst.instruction |= Rn << 16;
12044 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12045 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12046 inst.instruction |= msb - 1;
12047 }
12048
12049 static void
12050 do_t_bfx (void)
12051 {
12052 unsigned Rd, Rn;
12053
12054 Rd = inst.operands[0].reg;
12055 Rn = inst.operands[1].reg;
12056
12057 reject_bad_reg (Rd);
12058 reject_bad_reg (Rn);
12059
12060 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
12061 _("bit-field extends past end of register"));
12062 inst.instruction |= Rd << 8;
12063 inst.instruction |= Rn << 16;
12064 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
12065 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
12066 inst.instruction |= inst.operands[3].imm - 1;
12067 }
12068
12069 /* ARM V5 Thumb BLX (argument parse)
12070 BLX <target_addr> which is BLX(1)
12071 BLX <Rm> which is BLX(2)
12072 Unfortunately, there are two different opcodes for this mnemonic.
12073 So, the insns[].value is not used, and the code here zaps values
12074 into inst.instruction.
12075
12076 ??? How to take advantage of the additional two bits of displacement
12077 available in Thumb32 mode? Need new relocation? */
12078
12079 static void
12080 do_t_blx (void)
12081 {
12082 set_pred_insn_type_last ();
12083
12084 if (inst.operands[0].isreg)
12085 {
12086 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
12087 /* We have a register, so this is BLX(2). */
12088 inst.instruction |= inst.operands[0].reg << 3;
12089 }
12090 else
12091 {
12092 /* No register. This must be BLX(1). */
12093 inst.instruction = 0xf000e800;
12094 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
12095 }
12096 }
12097
12098 static void
12099 do_t_branch (void)
12100 {
12101 int opcode;
12102 int cond;
12103 bfd_reloc_code_real_type reloc;
12104
12105 cond = inst.cond;
12106 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
12107
12108 if (in_pred_block ())
12109 {
12110 /* Conditional branches inside IT blocks are encoded as unconditional
12111 branches. */
12112 cond = COND_ALWAYS;
12113 }
12114 else
12115 cond = inst.cond;
12116
12117 if (cond != COND_ALWAYS)
12118 opcode = T_MNEM_bcond;
12119 else
12120 opcode = inst.instruction;
12121
12122 if (unified_syntax
12123 && (inst.size_req == 4
12124 || (inst.size_req != 2
12125 && (inst.operands[0].hasreloc
12126 || inst.relocs[0].exp.X_op == O_constant))))
12127 {
12128 inst.instruction = THUMB_OP32(opcode);
12129 if (cond == COND_ALWAYS)
12130 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
12131 else
12132 {
12133 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12134 _("selected architecture does not support "
12135 "wide conditional branch instruction"));
12136
12137 gas_assert (cond != 0xF);
12138 inst.instruction |= cond << 22;
12139 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
12140 }
12141 }
12142 else
12143 {
12144 inst.instruction = THUMB_OP16(opcode);
12145 if (cond == COND_ALWAYS)
12146 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
12147 else
12148 {
12149 inst.instruction |= cond << 8;
12150 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
12151 }
12152 /* Allow section relaxation. */
12153 if (unified_syntax && inst.size_req != 2)
12154 inst.relax = opcode;
12155 }
12156 inst.relocs[0].type = reloc;
12157 inst.relocs[0].pc_rel = 1;
12158 }
12159
12160 /* Actually do the work for Thumb state bkpt and hlt. The only difference
12161 between the two is the maximum immediate allowed - which is passed in
12162 RANGE. */
12163 static void
12164 do_t_bkpt_hlt1 (int range)
12165 {
12166 constraint (inst.cond != COND_ALWAYS,
12167 _("instruction is always unconditional"));
12168 if (inst.operands[0].present)
12169 {
12170 constraint (inst.operands[0].imm > range,
12171 _("immediate value out of range"));
12172 inst.instruction |= inst.operands[0].imm;
12173 }
12174
12175 set_pred_insn_type (NEUTRAL_IT_INSN);
12176 }
12177
12178 static void
12179 do_t_hlt (void)
12180 {
12181 do_t_bkpt_hlt1 (63);
12182 }
12183
12184 static void
12185 do_t_bkpt (void)
12186 {
12187 do_t_bkpt_hlt1 (255);
12188 }
12189
12190 static void
12191 do_t_branch23 (void)
12192 {
12193 set_pred_insn_type_last ();
12194 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
12195
12196 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12197 this file. We used to simply ignore the PLT reloc type here --
12198 the branch encoding is now needed to deal with TLSCALL relocs.
12199 So if we see a PLT reloc now, put it back to how it used to be to
12200 keep the preexisting behaviour. */
12201 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12202 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
12203
12204 #if defined(OBJ_COFF)
12205 /* If the destination of the branch is a defined symbol which does not have
12206 the THUMB_FUNC attribute, then we must be calling a function which has
12207 the (interfacearm) attribute. We look for the Thumb entry point to that
12208 function and change the branch to refer to that function instead. */
12209 if ( inst.relocs[0].exp.X_op == O_symbol
12210 && inst.relocs[0].exp.X_add_symbol != NULL
12211 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12212 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12213 inst.relocs[0].exp.X_add_symbol
12214 = find_real_start (inst.relocs[0].exp.X_add_symbol);
12215 #endif
12216 }
12217
12218 static void
12219 do_t_bx (void)
12220 {
12221 set_pred_insn_type_last ();
12222 inst.instruction |= inst.operands[0].reg << 3;
12223 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12224 should cause the alignment to be checked once it is known. This is
12225 because BX PC only works if the instruction is word aligned. */
12226 }
12227
12228 static void
12229 do_t_bxj (void)
12230 {
12231 int Rm;
12232
12233 set_pred_insn_type_last ();
12234 Rm = inst.operands[0].reg;
12235 reject_bad_reg (Rm);
12236 inst.instruction |= Rm << 16;
12237 }
12238
12239 static void
12240 do_t_clz (void)
12241 {
12242 unsigned Rd;
12243 unsigned Rm;
12244
12245 Rd = inst.operands[0].reg;
12246 Rm = inst.operands[1].reg;
12247
12248 reject_bad_reg (Rd);
12249 reject_bad_reg (Rm);
12250
12251 inst.instruction |= Rd << 8;
12252 inst.instruction |= Rm << 16;
12253 inst.instruction |= Rm;
12254 }
12255
12256 /* For the Armv8.1-M conditional instructions. */
12257 static void
12258 do_t_cond (void)
12259 {
12260 unsigned Rd, Rn, Rm;
12261 signed int cond;
12262
12263 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12264
12265 Rd = inst.operands[0].reg;
12266 switch (inst.instruction)
12267 {
12268 case T_MNEM_csinc:
12269 case T_MNEM_csinv:
12270 case T_MNEM_csneg:
12271 case T_MNEM_csel:
12272 Rn = inst.operands[1].reg;
12273 Rm = inst.operands[2].reg;
12274 cond = inst.operands[3].imm;
12275 constraint (Rn == REG_SP, BAD_SP);
12276 constraint (Rm == REG_SP, BAD_SP);
12277 break;
12278
12279 case T_MNEM_cinc:
12280 case T_MNEM_cinv:
12281 case T_MNEM_cneg:
12282 Rn = inst.operands[1].reg;
12283 cond = inst.operands[2].imm;
12284 /* Invert the last bit to invert the cond. */
12285 cond = TOGGLE_BIT (cond, 0);
12286 constraint (Rn == REG_SP, BAD_SP);
12287 Rm = Rn;
12288 break;
12289
12290 case T_MNEM_csetm:
12291 case T_MNEM_cset:
12292 cond = inst.operands[1].imm;
12293 /* Invert the last bit to invert the cond. */
12294 cond = TOGGLE_BIT (cond, 0);
12295 Rn = REG_PC;
12296 Rm = REG_PC;
12297 break;
12298
12299 default: abort ();
12300 }
12301
12302 set_pred_insn_type (OUTSIDE_PRED_INSN);
12303 inst.instruction = THUMB_OP32 (inst.instruction);
12304 inst.instruction |= Rd << 8;
12305 inst.instruction |= Rn << 16;
12306 inst.instruction |= Rm;
12307 inst.instruction |= cond << 4;
12308 }
12309
12310 static void
12311 do_t_csdb (void)
12312 {
12313 set_pred_insn_type (OUTSIDE_PRED_INSN);
12314 }
12315
12316 static void
12317 do_t_cps (void)
12318 {
12319 set_pred_insn_type (OUTSIDE_PRED_INSN);
12320 inst.instruction |= inst.operands[0].imm;
12321 }
12322
12323 static void
12324 do_t_cpsi (void)
12325 {
12326 set_pred_insn_type (OUTSIDE_PRED_INSN);
12327 if (unified_syntax
12328 && (inst.operands[1].present || inst.size_req == 4)
12329 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
12330 {
12331 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12332 inst.instruction = 0xf3af8000;
12333 inst.instruction |= imod << 9;
12334 inst.instruction |= inst.operands[0].imm << 5;
12335 if (inst.operands[1].present)
12336 inst.instruction |= 0x100 | inst.operands[1].imm;
12337 }
12338 else
12339 {
12340 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12341 && (inst.operands[0].imm & 4),
12342 _("selected processor does not support 'A' form "
12343 "of this instruction"));
12344 constraint (inst.operands[1].present || inst.size_req == 4,
12345 _("Thumb does not support the 2-argument "
12346 "form of this instruction"));
12347 inst.instruction |= inst.operands[0].imm;
12348 }
12349 }
12350
12351 /* THUMB CPY instruction (argument parse). */
12352
12353 static void
12354 do_t_cpy (void)
12355 {
12356 if (inst.size_req == 4)
12357 {
12358 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12359 inst.instruction |= inst.operands[0].reg << 8;
12360 inst.instruction |= inst.operands[1].reg;
12361 }
12362 else
12363 {
12364 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12365 inst.instruction |= (inst.operands[0].reg & 0x7);
12366 inst.instruction |= inst.operands[1].reg << 3;
12367 }
12368 }
12369
12370 static void
12371 do_t_cbz (void)
12372 {
12373 set_pred_insn_type (OUTSIDE_PRED_INSN);
12374 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12375 inst.instruction |= inst.operands[0].reg;
12376 inst.relocs[0].pc_rel = 1;
12377 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
12378 }
12379
12380 static void
12381 do_t_dbg (void)
12382 {
12383 inst.instruction |= inst.operands[0].imm;
12384 }
12385
12386 static void
12387 do_t_div (void)
12388 {
12389 unsigned Rd, Rn, Rm;
12390
12391 Rd = inst.operands[0].reg;
12392 Rn = (inst.operands[1].present
12393 ? inst.operands[1].reg : Rd);
12394 Rm = inst.operands[2].reg;
12395
12396 reject_bad_reg (Rd);
12397 reject_bad_reg (Rn);
12398 reject_bad_reg (Rm);
12399
12400 inst.instruction |= Rd << 8;
12401 inst.instruction |= Rn << 16;
12402 inst.instruction |= Rm;
12403 }
12404
12405 static void
12406 do_t_hint (void)
12407 {
12408 if (unified_syntax && inst.size_req == 4)
12409 inst.instruction = THUMB_OP32 (inst.instruction);
12410 else
12411 inst.instruction = THUMB_OP16 (inst.instruction);
12412 }
12413
12414 static void
12415 do_t_it (void)
12416 {
12417 unsigned int cond = inst.operands[0].imm;
12418
12419 set_pred_insn_type (IT_INSN);
12420 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12421 now_pred.cc = cond;
12422 now_pred.warn_deprecated = false;
12423 now_pred.type = SCALAR_PRED;
12424
12425 /* If the condition is a negative condition, invert the mask. */
12426 if ((cond & 0x1) == 0x0)
12427 {
12428 unsigned int mask = inst.instruction & 0x000f;
12429
12430 if ((mask & 0x7) == 0)
12431 {
12432 /* No conversion needed. */
12433 now_pred.block_length = 1;
12434 }
12435 else if ((mask & 0x3) == 0)
12436 {
12437 mask ^= 0x8;
12438 now_pred.block_length = 2;
12439 }
12440 else if ((mask & 0x1) == 0)
12441 {
12442 mask ^= 0xC;
12443 now_pred.block_length = 3;
12444 }
12445 else
12446 {
12447 mask ^= 0xE;
12448 now_pred.block_length = 4;
12449 }
12450
12451 inst.instruction &= 0xfff0;
12452 inst.instruction |= mask;
12453 }
12454
12455 inst.instruction |= cond << 4;
12456 }
12457
12458 /* Helper function used for both push/pop and ldm/stm. */
12459 static void
12460 encode_thumb2_multi (bool do_io, int base, unsigned mask,
12461 bool writeback)
12462 {
12463 bool load, store;
12464
12465 gas_assert (base != -1 || !do_io);
12466 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12467 store = do_io && !load;
12468
12469 if (mask & (1 << 13))
12470 inst.error = _("SP not allowed in register list");
12471
12472 if (do_io && (mask & (1 << base)) != 0
12473 && writeback)
12474 inst.error = _("having the base register in the register list when "
12475 "using write back is UNPREDICTABLE");
12476
12477 if (load)
12478 {
12479 if (mask & (1 << 15))
12480 {
12481 if (mask & (1 << 14))
12482 inst.error = _("LR and PC should not both be in register list");
12483 else
12484 set_pred_insn_type_last ();
12485 }
12486 }
12487 else if (store)
12488 {
12489 if (mask & (1 << 15))
12490 inst.error = _("PC not allowed in register list");
12491 }
12492
12493 if (do_io && ((mask & (mask - 1)) == 0))
12494 {
12495 /* Single register transfers implemented as str/ldr. */
12496 if (writeback)
12497 {
12498 if (inst.instruction & (1 << 23))
12499 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12500 else
12501 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12502 }
12503 else
12504 {
12505 if (inst.instruction & (1 << 23))
12506 inst.instruction = 0x00800000; /* ia -> [base] */
12507 else
12508 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12509 }
12510
12511 inst.instruction |= 0xf8400000;
12512 if (load)
12513 inst.instruction |= 0x00100000;
12514
12515 mask = ffs (mask) - 1;
12516 mask <<= 12;
12517 }
12518 else if (writeback)
12519 inst.instruction |= WRITE_BACK;
12520
12521 inst.instruction |= mask;
12522 if (do_io)
12523 inst.instruction |= base << 16;
12524 }
12525
12526 static void
12527 do_t_ldmstm (void)
12528 {
12529 /* This really doesn't seem worth it. */
12530 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12531 _("expression too complex"));
12532 constraint (inst.operands[1].writeback,
12533 _("Thumb load/store multiple does not support {reglist}^"));
12534
12535 if (unified_syntax)
12536 {
12537 bool narrow;
12538 unsigned mask;
12539
12540 narrow = false;
12541 /* See if we can use a 16-bit instruction. */
12542 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12543 && inst.size_req != 4
12544 && !(inst.operands[1].imm & ~0xff))
12545 {
12546 mask = 1 << inst.operands[0].reg;
12547
12548 if (inst.operands[0].reg <= 7)
12549 {
12550 if (inst.instruction == T_MNEM_stmia
12551 ? inst.operands[0].writeback
12552 : (inst.operands[0].writeback
12553 == !(inst.operands[1].imm & mask)))
12554 {
12555 if (inst.instruction == T_MNEM_stmia
12556 && (inst.operands[1].imm & mask)
12557 && (inst.operands[1].imm & (mask - 1)))
12558 as_warn (_("value stored for r%d is UNKNOWN"),
12559 inst.operands[0].reg);
12560
12561 inst.instruction = THUMB_OP16 (inst.instruction);
12562 inst.instruction |= inst.operands[0].reg << 8;
12563 inst.instruction |= inst.operands[1].imm;
12564 narrow = true;
12565 }
12566 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12567 {
12568 /* This means 1 register in reg list one of 3 situations:
12569 1. Instruction is stmia, but without writeback.
12570 2. lmdia without writeback, but with Rn not in
12571 reglist.
12572 3. ldmia with writeback, but with Rn in reglist.
12573 Case 3 is UNPREDICTABLE behaviour, so we handle
12574 case 1 and 2 which can be converted into a 16-bit
12575 str or ldr. The SP cases are handled below. */
12576 unsigned long opcode;
12577 /* First, record an error for Case 3. */
12578 if (inst.operands[1].imm & mask
12579 && inst.operands[0].writeback)
12580 inst.error =
12581 _("having the base register in the register list when "
12582 "using write back is UNPREDICTABLE");
12583
12584 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
12585 : T_MNEM_ldr);
12586 inst.instruction = THUMB_OP16 (opcode);
12587 inst.instruction |= inst.operands[0].reg << 3;
12588 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12589 narrow = true;
12590 }
12591 }
12592 else if (inst.operands[0] .reg == REG_SP)
12593 {
12594 if (inst.operands[0].writeback)
12595 {
12596 inst.instruction =
12597 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12598 ? T_MNEM_push : T_MNEM_pop);
12599 inst.instruction |= inst.operands[1].imm;
12600 narrow = true;
12601 }
12602 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12603 {
12604 inst.instruction =
12605 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12606 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
12607 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
12608 narrow = true;
12609 }
12610 }
12611 }
12612
12613 if (!narrow)
12614 {
12615 if (inst.instruction < 0xffff)
12616 inst.instruction = THUMB_OP32 (inst.instruction);
12617
12618 encode_thumb2_multi (true /* do_io */, inst.operands[0].reg,
12619 inst.operands[1].imm,
12620 inst.operands[0].writeback);
12621 }
12622 }
12623 else
12624 {
12625 constraint (inst.operands[0].reg > 7
12626 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
12627 constraint (inst.instruction != T_MNEM_ldmia
12628 && inst.instruction != T_MNEM_stmia,
12629 _("Thumb-2 instruction only valid in unified syntax"));
12630 if (inst.instruction == T_MNEM_stmia)
12631 {
12632 if (!inst.operands[0].writeback)
12633 as_warn (_("this instruction will write back the base register"));
12634 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12635 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
12636 as_warn (_("value stored for r%d is UNKNOWN"),
12637 inst.operands[0].reg);
12638 }
12639 else
12640 {
12641 if (!inst.operands[0].writeback
12642 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12643 as_warn (_("this instruction will write back the base register"));
12644 else if (inst.operands[0].writeback
12645 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12646 as_warn (_("this instruction will not write back the base register"));
12647 }
12648
12649 inst.instruction = THUMB_OP16 (inst.instruction);
12650 inst.instruction |= inst.operands[0].reg << 8;
12651 inst.instruction |= inst.operands[1].imm;
12652 }
12653 }
12654
12655 static void
12656 do_t_ldrex (void)
12657 {
12658 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12659 || inst.operands[1].postind || inst.operands[1].writeback
12660 || inst.operands[1].immisreg || inst.operands[1].shifted
12661 || inst.operands[1].negative,
12662 BAD_ADDR_MODE);
12663
12664 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12665
12666 inst.instruction |= inst.operands[0].reg << 12;
12667 inst.instruction |= inst.operands[1].reg << 16;
12668 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
12669 }
12670
12671 static void
12672 do_t_ldrexd (void)
12673 {
12674 if (!inst.operands[1].present)
12675 {
12676 constraint (inst.operands[0].reg == REG_LR,
12677 _("r14 not allowed as first register "
12678 "when second register is omitted"));
12679 inst.operands[1].reg = inst.operands[0].reg + 1;
12680 }
12681 constraint (inst.operands[0].reg == inst.operands[1].reg,
12682 BAD_OVERLAP);
12683
12684 inst.instruction |= inst.operands[0].reg << 12;
12685 inst.instruction |= inst.operands[1].reg << 8;
12686 inst.instruction |= inst.operands[2].reg << 16;
12687 }
12688
12689 static void
12690 do_t_ldst (void)
12691 {
12692 unsigned long opcode;
12693 int Rn;
12694
12695 if (inst.operands[0].isreg
12696 && !inst.operands[0].preind
12697 && inst.operands[0].reg == REG_PC)
12698 set_pred_insn_type_last ();
12699
12700 opcode = inst.instruction;
12701 if (unified_syntax)
12702 {
12703 if (!inst.operands[1].isreg)
12704 {
12705 if (opcode <= 0xffff)
12706 inst.instruction = THUMB_OP32 (opcode);
12707 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/false))
12708 return;
12709 }
12710 if (inst.operands[1].isreg
12711 && !inst.operands[1].writeback
12712 && !inst.operands[1].shifted && !inst.operands[1].postind
12713 && !inst.operands[1].negative && inst.operands[0].reg <= 7
12714 && opcode <= 0xffff
12715 && inst.size_req != 4)
12716 {
12717 /* Insn may have a 16-bit form. */
12718 Rn = inst.operands[1].reg;
12719 if (inst.operands[1].immisreg)
12720 {
12721 inst.instruction = THUMB_OP16 (opcode);
12722 /* [Rn, Rik] */
12723 if (Rn <= 7 && inst.operands[1].imm <= 7)
12724 goto op16;
12725 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12726 reject_bad_reg (inst.operands[1].imm);
12727 }
12728 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12729 && opcode != T_MNEM_ldrsb)
12730 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12731 || (Rn == REG_SP && opcode == T_MNEM_str))
12732 {
12733 /* [Rn, #const] */
12734 if (Rn > 7)
12735 {
12736 if (Rn == REG_PC)
12737 {
12738 if (inst.relocs[0].pc_rel)
12739 opcode = T_MNEM_ldr_pc2;
12740 else
12741 opcode = T_MNEM_ldr_pc;
12742 }
12743 else
12744 {
12745 if (opcode == T_MNEM_ldr)
12746 opcode = T_MNEM_ldr_sp;
12747 else
12748 opcode = T_MNEM_str_sp;
12749 }
12750 inst.instruction = inst.operands[0].reg << 8;
12751 }
12752 else
12753 {
12754 inst.instruction = inst.operands[0].reg;
12755 inst.instruction |= inst.operands[1].reg << 3;
12756 }
12757 inst.instruction |= THUMB_OP16 (opcode);
12758 if (inst.size_req == 2)
12759 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12760 else
12761 inst.relax = opcode;
12762 return;
12763 }
12764 }
12765 /* Definitely a 32-bit variant. */
12766
12767 /* Warning for Erratum 752419. */
12768 if (opcode == T_MNEM_ldr
12769 && inst.operands[0].reg == REG_SP
12770 && inst.operands[1].writeback == 1
12771 && !inst.operands[1].immisreg)
12772 {
12773 if (no_cpu_selected ()
12774 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
12775 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12776 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
12777 as_warn (_("This instruction may be unpredictable "
12778 "if executed on M-profile cores "
12779 "with interrupts enabled."));
12780 }
12781
12782 /* Do some validations regarding addressing modes. */
12783 if (inst.operands[1].immisreg)
12784 reject_bad_reg (inst.operands[1].imm);
12785
12786 constraint (inst.operands[1].writeback == 1
12787 && inst.operands[0].reg == inst.operands[1].reg,
12788 BAD_OVERLAP);
12789
12790 inst.instruction = THUMB_OP32 (opcode);
12791 inst.instruction |= inst.operands[0].reg << 12;
12792 encode_thumb32_addr_mode (1, /*is_t=*/false, /*is_d=*/false);
12793 check_ldr_r15_aligned ();
12794 return;
12795 }
12796
12797 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12798
12799 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
12800 {
12801 /* Only [Rn,Rm] is acceptable. */
12802 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12803 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12804 || inst.operands[1].postind || inst.operands[1].shifted
12805 || inst.operands[1].negative,
12806 _("Thumb does not support this addressing mode"));
12807 inst.instruction = THUMB_OP16 (inst.instruction);
12808 goto op16;
12809 }
12810
12811 inst.instruction = THUMB_OP16 (inst.instruction);
12812 if (!inst.operands[1].isreg)
12813 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/false))
12814 return;
12815
12816 constraint (!inst.operands[1].preind
12817 || inst.operands[1].shifted
12818 || inst.operands[1].writeback,
12819 _("Thumb does not support this addressing mode"));
12820 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
12821 {
12822 constraint (inst.instruction & 0x0600,
12823 _("byte or halfword not valid for base register"));
12824 constraint (inst.operands[1].reg == REG_PC
12825 && !(inst.instruction & THUMB_LOAD_BIT),
12826 _("r15 based store not allowed"));
12827 constraint (inst.operands[1].immisreg,
12828 _("invalid base register for register offset"));
12829
12830 if (inst.operands[1].reg == REG_PC)
12831 inst.instruction = T_OPCODE_LDR_PC;
12832 else if (inst.instruction & THUMB_LOAD_BIT)
12833 inst.instruction = T_OPCODE_LDR_SP;
12834 else
12835 inst.instruction = T_OPCODE_STR_SP;
12836
12837 inst.instruction |= inst.operands[0].reg << 8;
12838 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12839 return;
12840 }
12841
12842 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12843 if (!inst.operands[1].immisreg)
12844 {
12845 /* Immediate offset. */
12846 inst.instruction |= inst.operands[0].reg;
12847 inst.instruction |= inst.operands[1].reg << 3;
12848 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12849 return;
12850 }
12851
12852 /* Register offset. */
12853 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12854 constraint (inst.operands[1].negative,
12855 _("Thumb does not support this addressing mode"));
12856
12857 op16:
12858 switch (inst.instruction)
12859 {
12860 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12861 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12862 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12863 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12864 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12865 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12866 case 0x5600 /* ldrsb */:
12867 case 0x5e00 /* ldrsh */: break;
12868 default: abort ();
12869 }
12870
12871 inst.instruction |= inst.operands[0].reg;
12872 inst.instruction |= inst.operands[1].reg << 3;
12873 inst.instruction |= inst.operands[1].imm << 6;
12874 }
12875
12876 static void
12877 do_t_ldstd (void)
12878 {
12879 if (!inst.operands[1].present)
12880 {
12881 inst.operands[1].reg = inst.operands[0].reg + 1;
12882 constraint (inst.operands[0].reg == REG_LR,
12883 _("r14 not allowed here"));
12884 constraint (inst.operands[0].reg == REG_R12,
12885 _("r12 not allowed here"));
12886 }
12887
12888 if (inst.operands[2].writeback
12889 && (inst.operands[0].reg == inst.operands[2].reg
12890 || inst.operands[1].reg == inst.operands[2].reg))
12891 as_warn (_("base register written back, and overlaps "
12892 "one of transfer registers"));
12893
12894 inst.instruction |= inst.operands[0].reg << 12;
12895 inst.instruction |= inst.operands[1].reg << 8;
12896 encode_thumb32_addr_mode (2, /*is_t=*/false, /*is_d=*/true);
12897 }
12898
12899 static void
12900 do_t_ldstt (void)
12901 {
12902 inst.instruction |= inst.operands[0].reg << 12;
12903 encode_thumb32_addr_mode (1, /*is_t=*/true, /*is_d=*/false);
12904 }
12905
12906 static void
12907 do_t_mla (void)
12908 {
12909 unsigned Rd, Rn, Rm, Ra;
12910
12911 Rd = inst.operands[0].reg;
12912 Rn = inst.operands[1].reg;
12913 Rm = inst.operands[2].reg;
12914 Ra = inst.operands[3].reg;
12915
12916 reject_bad_reg (Rd);
12917 reject_bad_reg (Rn);
12918 reject_bad_reg (Rm);
12919 reject_bad_reg (Ra);
12920
12921 inst.instruction |= Rd << 8;
12922 inst.instruction |= Rn << 16;
12923 inst.instruction |= Rm;
12924 inst.instruction |= Ra << 12;
12925 }
12926
12927 static void
12928 do_t_mlal (void)
12929 {
12930 unsigned RdLo, RdHi, Rn, Rm;
12931
12932 RdLo = inst.operands[0].reg;
12933 RdHi = inst.operands[1].reg;
12934 Rn = inst.operands[2].reg;
12935 Rm = inst.operands[3].reg;
12936
12937 reject_bad_reg (RdLo);
12938 reject_bad_reg (RdHi);
12939 reject_bad_reg (Rn);
12940 reject_bad_reg (Rm);
12941
12942 inst.instruction |= RdLo << 12;
12943 inst.instruction |= RdHi << 8;
12944 inst.instruction |= Rn << 16;
12945 inst.instruction |= Rm;
12946 }
12947
12948 static void
12949 do_t_mov_cmp (void)
12950 {
12951 unsigned Rn, Rm;
12952
12953 Rn = inst.operands[0].reg;
12954 Rm = inst.operands[1].reg;
12955
12956 if (Rn == REG_PC)
12957 set_pred_insn_type_last ();
12958
12959 if (unified_syntax)
12960 {
12961 int r0off = (inst.instruction == T_MNEM_mov
12962 || inst.instruction == T_MNEM_movs) ? 8 : 16;
12963 unsigned long opcode;
12964 bool narrow;
12965 bool low_regs;
12966
12967 low_regs = (Rn <= 7 && Rm <= 7);
12968 opcode = inst.instruction;
12969 if (in_pred_block ())
12970 narrow = opcode != T_MNEM_movs;
12971 else
12972 narrow = opcode != T_MNEM_movs || low_regs;
12973 if (inst.size_req == 4
12974 || inst.operands[1].shifted)
12975 narrow = false;
12976
12977 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12978 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12979 && !inst.operands[1].shifted
12980 && Rn == REG_PC
12981 && Rm == REG_LR)
12982 {
12983 inst.instruction = T2_SUBS_PC_LR;
12984 return;
12985 }
12986
12987 if (opcode == T_MNEM_cmp)
12988 {
12989 constraint (Rn == REG_PC, BAD_PC);
12990 if (narrow)
12991 {
12992 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12993 but valid. */
12994 warn_deprecated_sp (Rm);
12995 /* R15 was documented as a valid choice for Rm in ARMv6,
12996 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12997 tools reject R15, so we do too. */
12998 constraint (Rm == REG_PC, BAD_PC);
12999 }
13000 else
13001 reject_bad_reg (Rm);
13002 }
13003 else if (opcode == T_MNEM_mov
13004 || opcode == T_MNEM_movs)
13005 {
13006 if (inst.operands[1].isreg)
13007 {
13008 if (opcode == T_MNEM_movs)
13009 {
13010 reject_bad_reg (Rn);
13011 reject_bad_reg (Rm);
13012 }
13013 else if (narrow)
13014 {
13015 /* This is mov.n. */
13016 if ((Rn == REG_SP || Rn == REG_PC)
13017 && (Rm == REG_SP || Rm == REG_PC))
13018 {
13019 as_tsktsk (_("Use of r%u as a source register is "
13020 "deprecated when r%u is the destination "
13021 "register."), Rm, Rn);
13022 }
13023 }
13024 else
13025 {
13026 /* This is mov.w. */
13027 constraint (Rn == REG_PC, BAD_PC);
13028 constraint (Rm == REG_PC, BAD_PC);
13029 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13030 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
13031 }
13032 }
13033 else
13034 reject_bad_reg (Rn);
13035 }
13036
13037 if (!inst.operands[1].isreg)
13038 {
13039 /* Immediate operand. */
13040 if (!in_pred_block () && opcode == T_MNEM_mov)
13041 narrow = 0;
13042 if (low_regs && narrow)
13043 {
13044 inst.instruction = THUMB_OP16 (opcode);
13045 inst.instruction |= Rn << 8;
13046 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
13047 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
13048 {
13049 if (inst.size_req == 2)
13050 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13051 else
13052 inst.relax = opcode;
13053 }
13054 }
13055 else
13056 {
13057 constraint ((inst.relocs[0].type
13058 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
13059 && (inst.relocs[0].type
13060 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
13061 THUMB1_RELOC_ONLY);
13062
13063 inst.instruction = THUMB_OP32 (inst.instruction);
13064 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13065 inst.instruction |= Rn << r0off;
13066 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13067 }
13068 }
13069 else if (inst.operands[1].shifted && inst.operands[1].immisreg
13070 && (inst.instruction == T_MNEM_mov
13071 || inst.instruction == T_MNEM_movs))
13072 {
13073 /* Register shifts are encoded as separate shift instructions. */
13074 bool flags = (inst.instruction == T_MNEM_movs);
13075
13076 if (in_pred_block ())
13077 narrow = !flags;
13078 else
13079 narrow = flags;
13080
13081 if (inst.size_req == 4)
13082 narrow = false;
13083
13084 if (!low_regs || inst.operands[1].imm > 7)
13085 narrow = false;
13086
13087 if (Rn != Rm)
13088 narrow = false;
13089
13090 switch (inst.operands[1].shift_kind)
13091 {
13092 case SHIFT_LSL:
13093 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
13094 break;
13095 case SHIFT_ASR:
13096 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
13097 break;
13098 case SHIFT_LSR:
13099 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
13100 break;
13101 case SHIFT_ROR:
13102 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
13103 break;
13104 default:
13105 abort ();
13106 }
13107
13108 inst.instruction = opcode;
13109 if (narrow)
13110 {
13111 inst.instruction |= Rn;
13112 inst.instruction |= inst.operands[1].imm << 3;
13113 }
13114 else
13115 {
13116 if (flags)
13117 inst.instruction |= CONDS_BIT;
13118
13119 inst.instruction |= Rn << 8;
13120 inst.instruction |= Rm << 16;
13121 inst.instruction |= inst.operands[1].imm;
13122 }
13123 }
13124 else if (!narrow)
13125 {
13126 /* Some mov with immediate shift have narrow variants.
13127 Register shifts are handled above. */
13128 if (low_regs && inst.operands[1].shifted
13129 && (inst.instruction == T_MNEM_mov
13130 || inst.instruction == T_MNEM_movs))
13131 {
13132 if (in_pred_block ())
13133 narrow = (inst.instruction == T_MNEM_mov);
13134 else
13135 narrow = (inst.instruction == T_MNEM_movs);
13136 }
13137
13138 if (narrow)
13139 {
13140 switch (inst.operands[1].shift_kind)
13141 {
13142 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13143 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13144 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13145 default: narrow = false; break;
13146 }
13147 }
13148
13149 if (narrow)
13150 {
13151 inst.instruction |= Rn;
13152 inst.instruction |= Rm << 3;
13153 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13154 }
13155 else
13156 {
13157 inst.instruction = THUMB_OP32 (inst.instruction);
13158 inst.instruction |= Rn << r0off;
13159 encode_thumb32_shifted_operand (1);
13160 }
13161 }
13162 else
13163 switch (inst.instruction)
13164 {
13165 case T_MNEM_mov:
13166 /* In v4t or v5t a move of two lowregs produces unpredictable
13167 results. Don't allow this. */
13168 if (low_regs)
13169 {
13170 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13171 "MOV Rd, Rs with two low registers is not "
13172 "permitted on this architecture");
13173 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13174 arm_ext_v6);
13175 }
13176
13177 inst.instruction = T_OPCODE_MOV_HR;
13178 inst.instruction |= (Rn & 0x8) << 4;
13179 inst.instruction |= (Rn & 0x7);
13180 inst.instruction |= Rm << 3;
13181 break;
13182
13183 case T_MNEM_movs:
13184 /* We know we have low registers at this point.
13185 Generate LSLS Rd, Rs, #0. */
13186 inst.instruction = T_OPCODE_LSL_I;
13187 inst.instruction |= Rn;
13188 inst.instruction |= Rm << 3;
13189 break;
13190
13191 case T_MNEM_cmp:
13192 if (low_regs)
13193 {
13194 inst.instruction = T_OPCODE_CMP_LR;
13195 inst.instruction |= Rn;
13196 inst.instruction |= Rm << 3;
13197 }
13198 else
13199 {
13200 inst.instruction = T_OPCODE_CMP_HR;
13201 inst.instruction |= (Rn & 0x8) << 4;
13202 inst.instruction |= (Rn & 0x7);
13203 inst.instruction |= Rm << 3;
13204 }
13205 break;
13206 }
13207 return;
13208 }
13209
13210 inst.instruction = THUMB_OP16 (inst.instruction);
13211
13212 /* PR 10443: Do not silently ignore shifted operands. */
13213 constraint (inst.operands[1].shifted,
13214 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13215
13216 if (inst.operands[1].isreg)
13217 {
13218 if (Rn < 8 && Rm < 8)
13219 {
13220 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13221 since a MOV instruction produces unpredictable results. */
13222 if (inst.instruction == T_OPCODE_MOV_I8)
13223 inst.instruction = T_OPCODE_ADD_I3;
13224 else
13225 inst.instruction = T_OPCODE_CMP_LR;
13226
13227 inst.instruction |= Rn;
13228 inst.instruction |= Rm << 3;
13229 }
13230 else
13231 {
13232 if (inst.instruction == T_OPCODE_MOV_I8)
13233 inst.instruction = T_OPCODE_MOV_HR;
13234 else
13235 inst.instruction = T_OPCODE_CMP_HR;
13236 do_t_cpy ();
13237 }
13238 }
13239 else
13240 {
13241 constraint (Rn > 7,
13242 _("only lo regs allowed with immediate"));
13243 inst.instruction |= Rn << 8;
13244 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13245 }
13246 }
13247
13248 static void
13249 do_t_mov16 (void)
13250 {
13251 unsigned Rd;
13252 bfd_vma imm;
13253 bool top;
13254
13255 top = (inst.instruction & 0x00800000) != 0;
13256 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
13257 {
13258 constraint (top, _(":lower16: not allowed in this instruction"));
13259 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
13260 }
13261 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
13262 {
13263 constraint (!top, _(":upper16: not allowed in this instruction"));
13264 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
13265 }
13266
13267 Rd = inst.operands[0].reg;
13268 reject_bad_reg (Rd);
13269
13270 inst.instruction |= Rd << 8;
13271 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
13272 {
13273 imm = inst.relocs[0].exp.X_add_number;
13274 inst.instruction |= (imm & 0xf000) << 4;
13275 inst.instruction |= (imm & 0x0800) << 15;
13276 inst.instruction |= (imm & 0x0700) << 4;
13277 inst.instruction |= (imm & 0x00ff);
13278 }
13279 }
13280
13281 static void
13282 do_t_mvn_tst (void)
13283 {
13284 unsigned Rn, Rm;
13285
13286 Rn = inst.operands[0].reg;
13287 Rm = inst.operands[1].reg;
13288
13289 if (inst.instruction == T_MNEM_cmp
13290 || inst.instruction == T_MNEM_cmn)
13291 constraint (Rn == REG_PC, BAD_PC);
13292 else
13293 reject_bad_reg (Rn);
13294 reject_bad_reg (Rm);
13295
13296 if (unified_syntax)
13297 {
13298 int r0off = (inst.instruction == T_MNEM_mvn
13299 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
13300 bool narrow;
13301
13302 if (inst.size_req == 4
13303 || inst.instruction > 0xffff
13304 || inst.operands[1].shifted
13305 || Rn > 7 || Rm > 7)
13306 narrow = false;
13307 else if (inst.instruction == T_MNEM_cmn
13308 || inst.instruction == T_MNEM_tst)
13309 narrow = true;
13310 else if (THUMB_SETS_FLAGS (inst.instruction))
13311 narrow = !in_pred_block ();
13312 else
13313 narrow = in_pred_block ();
13314
13315 if (!inst.operands[1].isreg)
13316 {
13317 /* For an immediate, we always generate a 32-bit opcode;
13318 section relaxation will shrink it later if possible. */
13319 if (inst.instruction < 0xffff)
13320 inst.instruction = THUMB_OP32 (inst.instruction);
13321 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13322 inst.instruction |= Rn << r0off;
13323 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13324 }
13325 else
13326 {
13327 /* See if we can do this with a 16-bit instruction. */
13328 if (narrow)
13329 {
13330 inst.instruction = THUMB_OP16 (inst.instruction);
13331 inst.instruction |= Rn;
13332 inst.instruction |= Rm << 3;
13333 }
13334 else
13335 {
13336 constraint (inst.operands[1].shifted
13337 && inst.operands[1].immisreg,
13338 _("shift must be constant"));
13339 if (inst.instruction < 0xffff)
13340 inst.instruction = THUMB_OP32 (inst.instruction);
13341 inst.instruction |= Rn << r0off;
13342 encode_thumb32_shifted_operand (1);
13343 }
13344 }
13345 }
13346 else
13347 {
13348 constraint (inst.instruction > 0xffff
13349 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13350 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13351 _("unshifted register required"));
13352 constraint (Rn > 7 || Rm > 7,
13353 BAD_HIREG);
13354
13355 inst.instruction = THUMB_OP16 (inst.instruction);
13356 inst.instruction |= Rn;
13357 inst.instruction |= Rm << 3;
13358 }
13359 }
13360
13361 static void
13362 do_t_mrs (void)
13363 {
13364 unsigned Rd;
13365
13366 if (do_vfp_nsyn_mrs () == SUCCESS)
13367 return;
13368
13369 Rd = inst.operands[0].reg;
13370 reject_bad_reg (Rd);
13371 inst.instruction |= Rd << 8;
13372
13373 if (inst.operands[1].isreg)
13374 {
13375 unsigned br = inst.operands[1].reg;
13376 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13377 as_bad (_("bad register for mrs"));
13378
13379 inst.instruction |= br & (0xf << 16);
13380 inst.instruction |= (br & 0x300) >> 4;
13381 inst.instruction |= (br & SPSR_BIT) >> 2;
13382 }
13383 else
13384 {
13385 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13386
13387 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13388 {
13389 /* PR gas/12698: The constraint is only applied for m_profile.
13390 If the user has specified -march=all, we want to ignore it as
13391 we are building for any CPU type, including non-m variants. */
13392 bool m_profile =
13393 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13394 constraint ((flags != 0) && m_profile, _("selected processor does "
13395 "not support requested special purpose register"));
13396 }
13397 else
13398 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13399 devices). */
13400 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13401 _("'APSR', 'CPSR' or 'SPSR' expected"));
13402
13403 inst.instruction |= (flags & SPSR_BIT) >> 2;
13404 inst.instruction |= inst.operands[1].imm & 0xff;
13405 inst.instruction |= 0xf0000;
13406 }
13407 }
13408
13409 static void
13410 do_t_msr (void)
13411 {
13412 int flags;
13413 unsigned Rn;
13414
13415 if (do_vfp_nsyn_msr () == SUCCESS)
13416 return;
13417
13418 constraint (!inst.operands[1].isreg,
13419 _("Thumb encoding does not support an immediate here"));
13420
13421 if (inst.operands[0].isreg)
13422 flags = (int)(inst.operands[0].reg);
13423 else
13424 flags = inst.operands[0].imm;
13425
13426 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13427 {
13428 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13429
13430 /* PR gas/12698: The constraint is only applied for m_profile.
13431 If the user has specified -march=all, we want to ignore it as
13432 we are building for any CPU type, including non-m variants. */
13433 bool m_profile =
13434 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13435 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13436 && (bits & ~(PSR_s | PSR_f)) != 0)
13437 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13438 && bits != PSR_f)) && m_profile,
13439 _("selected processor does not support requested special "
13440 "purpose register"));
13441 }
13442 else
13443 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13444 "requested special purpose register"));
13445
13446 Rn = inst.operands[1].reg;
13447 reject_bad_reg (Rn);
13448
13449 inst.instruction |= (flags & SPSR_BIT) >> 2;
13450 inst.instruction |= (flags & 0xf0000) >> 8;
13451 inst.instruction |= (flags & 0x300) >> 4;
13452 inst.instruction |= (flags & 0xff);
13453 inst.instruction |= Rn << 16;
13454 }
13455
13456 static void
13457 do_t_mul (void)
13458 {
13459 bool narrow;
13460 unsigned Rd, Rn, Rm;
13461
13462 if (!inst.operands[2].present)
13463 inst.operands[2].reg = inst.operands[0].reg;
13464
13465 Rd = inst.operands[0].reg;
13466 Rn = inst.operands[1].reg;
13467 Rm = inst.operands[2].reg;
13468
13469 if (unified_syntax)
13470 {
13471 if (inst.size_req == 4
13472 || (Rd != Rn
13473 && Rd != Rm)
13474 || Rn > 7
13475 || Rm > 7)
13476 narrow = false;
13477 else if (inst.instruction == T_MNEM_muls)
13478 narrow = !in_pred_block ();
13479 else
13480 narrow = in_pred_block ();
13481 }
13482 else
13483 {
13484 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
13485 constraint (Rn > 7 || Rm > 7,
13486 BAD_HIREG);
13487 narrow = true;
13488 }
13489
13490 if (narrow)
13491 {
13492 /* 16-bit MULS/Conditional MUL. */
13493 inst.instruction = THUMB_OP16 (inst.instruction);
13494 inst.instruction |= Rd;
13495
13496 if (Rd == Rn)
13497 inst.instruction |= Rm << 3;
13498 else if (Rd == Rm)
13499 inst.instruction |= Rn << 3;
13500 else
13501 constraint (1, _("dest must overlap one source register"));
13502 }
13503 else
13504 {
13505 constraint (inst.instruction != T_MNEM_mul,
13506 _("Thumb-2 MUL must not set flags"));
13507 /* 32-bit MUL. */
13508 inst.instruction = THUMB_OP32 (inst.instruction);
13509 inst.instruction |= Rd << 8;
13510 inst.instruction |= Rn << 16;
13511 inst.instruction |= Rm << 0;
13512
13513 reject_bad_reg (Rd);
13514 reject_bad_reg (Rn);
13515 reject_bad_reg (Rm);
13516 }
13517 }
13518
13519 static void
13520 do_t_mull (void)
13521 {
13522 unsigned RdLo, RdHi, Rn, Rm;
13523
13524 RdLo = inst.operands[0].reg;
13525 RdHi = inst.operands[1].reg;
13526 Rn = inst.operands[2].reg;
13527 Rm = inst.operands[3].reg;
13528
13529 reject_bad_reg (RdLo);
13530 reject_bad_reg (RdHi);
13531 reject_bad_reg (Rn);
13532 reject_bad_reg (Rm);
13533
13534 inst.instruction |= RdLo << 12;
13535 inst.instruction |= RdHi << 8;
13536 inst.instruction |= Rn << 16;
13537 inst.instruction |= Rm;
13538
13539 if (RdLo == RdHi)
13540 as_tsktsk (_("rdhi and rdlo must be different"));
13541 }
13542
13543 static void
13544 do_t_nop (void)
13545 {
13546 set_pred_insn_type (NEUTRAL_IT_INSN);
13547
13548 if (unified_syntax)
13549 {
13550 if (inst.size_req == 4 || inst.operands[0].imm > 15)
13551 {
13552 inst.instruction = THUMB_OP32 (inst.instruction);
13553 inst.instruction |= inst.operands[0].imm;
13554 }
13555 else
13556 {
13557 /* PR9722: Check for Thumb2 availability before
13558 generating a thumb2 nop instruction. */
13559 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
13560 {
13561 inst.instruction = THUMB_OP16 (inst.instruction);
13562 inst.instruction |= inst.operands[0].imm << 4;
13563 }
13564 else
13565 inst.instruction = 0x46c0;
13566 }
13567 }
13568 else
13569 {
13570 constraint (inst.operands[0].present,
13571 _("Thumb does not support NOP with hints"));
13572 inst.instruction = 0x46c0;
13573 }
13574 }
13575
13576 static void
13577 do_t_neg (void)
13578 {
13579 if (unified_syntax)
13580 {
13581 bool narrow;
13582
13583 if (THUMB_SETS_FLAGS (inst.instruction))
13584 narrow = !in_pred_block ();
13585 else
13586 narrow = in_pred_block ();
13587 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13588 narrow = false;
13589 if (inst.size_req == 4)
13590 narrow = false;
13591
13592 if (!narrow)
13593 {
13594 inst.instruction = THUMB_OP32 (inst.instruction);
13595 inst.instruction |= inst.operands[0].reg << 8;
13596 inst.instruction |= inst.operands[1].reg << 16;
13597 }
13598 else
13599 {
13600 inst.instruction = THUMB_OP16 (inst.instruction);
13601 inst.instruction |= inst.operands[0].reg;
13602 inst.instruction |= inst.operands[1].reg << 3;
13603 }
13604 }
13605 else
13606 {
13607 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13608 BAD_HIREG);
13609 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13610
13611 inst.instruction = THUMB_OP16 (inst.instruction);
13612 inst.instruction |= inst.operands[0].reg;
13613 inst.instruction |= inst.operands[1].reg << 3;
13614 }
13615 }
13616
13617 static void
13618 do_t_orn (void)
13619 {
13620 unsigned Rd, Rn;
13621
13622 Rd = inst.operands[0].reg;
13623 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13624
13625 reject_bad_reg (Rd);
13626 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13627 reject_bad_reg (Rn);
13628
13629 inst.instruction |= Rd << 8;
13630 inst.instruction |= Rn << 16;
13631
13632 if (!inst.operands[2].isreg)
13633 {
13634 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13635 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13636 }
13637 else
13638 {
13639 unsigned Rm;
13640
13641 Rm = inst.operands[2].reg;
13642 reject_bad_reg (Rm);
13643
13644 constraint (inst.operands[2].shifted
13645 && inst.operands[2].immisreg,
13646 _("shift must be constant"));
13647 encode_thumb32_shifted_operand (2);
13648 }
13649 }
13650
13651 static void
13652 do_t_pkhbt (void)
13653 {
13654 unsigned Rd, Rn, Rm;
13655
13656 Rd = inst.operands[0].reg;
13657 Rn = inst.operands[1].reg;
13658 Rm = inst.operands[2].reg;
13659
13660 reject_bad_reg (Rd);
13661 reject_bad_reg (Rn);
13662 reject_bad_reg (Rm);
13663
13664 inst.instruction |= Rd << 8;
13665 inst.instruction |= Rn << 16;
13666 inst.instruction |= Rm;
13667 if (inst.operands[3].present)
13668 {
13669 unsigned int val = inst.relocs[0].exp.X_add_number;
13670 constraint (inst.relocs[0].exp.X_op != O_constant,
13671 _("expression too complex"));
13672 inst.instruction |= (val & 0x1c) << 10;
13673 inst.instruction |= (val & 0x03) << 6;
13674 }
13675 }
13676
13677 static void
13678 do_t_pkhtb (void)
13679 {
13680 if (!inst.operands[3].present)
13681 {
13682 unsigned Rtmp;
13683
13684 inst.instruction &= ~0x00000020;
13685
13686 /* PR 10168. Swap the Rm and Rn registers. */
13687 Rtmp = inst.operands[1].reg;
13688 inst.operands[1].reg = inst.operands[2].reg;
13689 inst.operands[2].reg = Rtmp;
13690 }
13691 do_t_pkhbt ();
13692 }
13693
13694 static void
13695 do_t_pld (void)
13696 {
13697 if (inst.operands[0].immisreg)
13698 reject_bad_reg (inst.operands[0].imm);
13699
13700 encode_thumb32_addr_mode (0, /*is_t=*/false, /*is_d=*/false);
13701 }
13702
13703 static void
13704 do_t_push_pop (void)
13705 {
13706 unsigned mask;
13707
13708 constraint (inst.operands[0].writeback,
13709 _("push/pop do not support {reglist}^"));
13710 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
13711 _("expression too complex"));
13712
13713 mask = inst.operands[0].imm;
13714 if (inst.size_req != 4 && (mask & ~0xff) == 0)
13715 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
13716 else if (inst.size_req != 4
13717 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
13718 ? REG_LR : REG_PC)))
13719 {
13720 inst.instruction = THUMB_OP16 (inst.instruction);
13721 inst.instruction |= THUMB_PP_PC_LR;
13722 inst.instruction |= mask & 0xff;
13723 }
13724 else if (unified_syntax)
13725 {
13726 inst.instruction = THUMB_OP32 (inst.instruction);
13727 encode_thumb2_multi (true /* do_io */, 13, mask, true);
13728 }
13729 else
13730 {
13731 inst.error = _("invalid register list to push/pop instruction");
13732 return;
13733 }
13734 }
13735
13736 static void
13737 do_t_clrm (void)
13738 {
13739 if (unified_syntax)
13740 encode_thumb2_multi (false /* do_io */, -1, inst.operands[0].imm, false);
13741 else
13742 {
13743 inst.error = _("invalid register list to push/pop instruction");
13744 return;
13745 }
13746 }
13747
13748 static void
13749 do_t_vscclrm (void)
13750 {
13751 if (inst.operands[0].issingle)
13752 {
13753 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13754 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13755 inst.instruction |= inst.operands[0].imm;
13756 }
13757 else
13758 {
13759 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13760 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13761 inst.instruction |= 1 << 8;
13762 inst.instruction |= inst.operands[0].imm << 1;
13763 }
13764 }
13765
13766 static void
13767 do_t_rbit (void)
13768 {
13769 unsigned Rd, Rm;
13770
13771 Rd = inst.operands[0].reg;
13772 Rm = inst.operands[1].reg;
13773
13774 reject_bad_reg (Rd);
13775 reject_bad_reg (Rm);
13776
13777 inst.instruction |= Rd << 8;
13778 inst.instruction |= Rm << 16;
13779 inst.instruction |= Rm;
13780 }
13781
13782 static void
13783 do_t_rev (void)
13784 {
13785 unsigned Rd, Rm;
13786
13787 Rd = inst.operands[0].reg;
13788 Rm = inst.operands[1].reg;
13789
13790 reject_bad_reg (Rd);
13791 reject_bad_reg (Rm);
13792
13793 if (Rd <= 7 && Rm <= 7
13794 && inst.size_req != 4)
13795 {
13796 inst.instruction = THUMB_OP16 (inst.instruction);
13797 inst.instruction |= Rd;
13798 inst.instruction |= Rm << 3;
13799 }
13800 else if (unified_syntax)
13801 {
13802 inst.instruction = THUMB_OP32 (inst.instruction);
13803 inst.instruction |= Rd << 8;
13804 inst.instruction |= Rm << 16;
13805 inst.instruction |= Rm;
13806 }
13807 else
13808 inst.error = BAD_HIREG;
13809 }
13810
13811 static void
13812 do_t_rrx (void)
13813 {
13814 unsigned Rd, Rm;
13815
13816 Rd = inst.operands[0].reg;
13817 Rm = inst.operands[1].reg;
13818
13819 reject_bad_reg (Rd);
13820 reject_bad_reg (Rm);
13821
13822 inst.instruction |= Rd << 8;
13823 inst.instruction |= Rm;
13824 }
13825
13826 static void
13827 do_t_rsb (void)
13828 {
13829 unsigned Rd, Rs;
13830
13831 Rd = inst.operands[0].reg;
13832 Rs = (inst.operands[1].present
13833 ? inst.operands[1].reg /* Rd, Rs, foo */
13834 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
13835
13836 reject_bad_reg (Rd);
13837 reject_bad_reg (Rs);
13838 if (inst.operands[2].isreg)
13839 reject_bad_reg (inst.operands[2].reg);
13840
13841 inst.instruction |= Rd << 8;
13842 inst.instruction |= Rs << 16;
13843 if (!inst.operands[2].isreg)
13844 {
13845 bool narrow;
13846
13847 if ((inst.instruction & 0x00100000) != 0)
13848 narrow = !in_pred_block ();
13849 else
13850 narrow = in_pred_block ();
13851
13852 if (Rd > 7 || Rs > 7)
13853 narrow = false;
13854
13855 if (inst.size_req == 4 || !unified_syntax)
13856 narrow = false;
13857
13858 if (inst.relocs[0].exp.X_op != O_constant
13859 || inst.relocs[0].exp.X_add_number != 0)
13860 narrow = false;
13861
13862 /* Turn rsb #0 into 16-bit neg. We should probably do this via
13863 relaxation, but it doesn't seem worth the hassle. */
13864 if (narrow)
13865 {
13866 inst.relocs[0].type = BFD_RELOC_UNUSED;
13867 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13868 inst.instruction |= Rs << 3;
13869 inst.instruction |= Rd;
13870 }
13871 else
13872 {
13873 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13874 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13875 }
13876 }
13877 else
13878 encode_thumb32_shifted_operand (2);
13879 }
13880
13881 static void
13882 do_t_setend (void)
13883 {
13884 if (warn_on_deprecated
13885 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13886 as_tsktsk (_("setend use is deprecated for ARMv8"));
13887
13888 set_pred_insn_type (OUTSIDE_PRED_INSN);
13889 if (inst.operands[0].imm)
13890 inst.instruction |= 0x8;
13891 }
13892
13893 static void
13894 do_t_shift (void)
13895 {
13896 if (!inst.operands[1].present)
13897 inst.operands[1].reg = inst.operands[0].reg;
13898
13899 if (unified_syntax)
13900 {
13901 bool narrow;
13902 int shift_kind;
13903
13904 switch (inst.instruction)
13905 {
13906 case T_MNEM_asr:
13907 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13908 case T_MNEM_lsl:
13909 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13910 case T_MNEM_lsr:
13911 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13912 case T_MNEM_ror:
13913 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13914 default: abort ();
13915 }
13916
13917 if (THUMB_SETS_FLAGS (inst.instruction))
13918 narrow = !in_pred_block ();
13919 else
13920 narrow = in_pred_block ();
13921 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13922 narrow = false;
13923 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13924 narrow = false;
13925 if (inst.operands[2].isreg
13926 && (inst.operands[1].reg != inst.operands[0].reg
13927 || inst.operands[2].reg > 7))
13928 narrow = false;
13929 if (inst.size_req == 4)
13930 narrow = false;
13931
13932 reject_bad_reg (inst.operands[0].reg);
13933 reject_bad_reg (inst.operands[1].reg);
13934
13935 if (!narrow)
13936 {
13937 if (inst.operands[2].isreg)
13938 {
13939 reject_bad_reg (inst.operands[2].reg);
13940 inst.instruction = THUMB_OP32 (inst.instruction);
13941 inst.instruction |= inst.operands[0].reg << 8;
13942 inst.instruction |= inst.operands[1].reg << 16;
13943 inst.instruction |= inst.operands[2].reg;
13944
13945 /* PR 12854: Error on extraneous shifts. */
13946 constraint (inst.operands[2].shifted,
13947 _("extraneous shift as part of operand to shift insn"));
13948 }
13949 else
13950 {
13951 inst.operands[1].shifted = 1;
13952 inst.operands[1].shift_kind = shift_kind;
13953 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13954 ? T_MNEM_movs : T_MNEM_mov);
13955 inst.instruction |= inst.operands[0].reg << 8;
13956 encode_thumb32_shifted_operand (1);
13957 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
13958 inst.relocs[0].type = BFD_RELOC_UNUSED;
13959 }
13960 }
13961 else
13962 {
13963 if (inst.operands[2].isreg)
13964 {
13965 switch (shift_kind)
13966 {
13967 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13968 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13969 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13970 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
13971 default: abort ();
13972 }
13973
13974 inst.instruction |= inst.operands[0].reg;
13975 inst.instruction |= inst.operands[2].reg << 3;
13976
13977 /* PR 12854: Error on extraneous shifts. */
13978 constraint (inst.operands[2].shifted,
13979 _("extraneous shift as part of operand to shift insn"));
13980 }
13981 else
13982 {
13983 switch (shift_kind)
13984 {
13985 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13986 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13987 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13988 default: abort ();
13989 }
13990 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13991 inst.instruction |= inst.operands[0].reg;
13992 inst.instruction |= inst.operands[1].reg << 3;
13993 }
13994 }
13995 }
13996 else
13997 {
13998 constraint (inst.operands[0].reg > 7
13999 || inst.operands[1].reg > 7, BAD_HIREG);
14000 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
14001
14002 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
14003 {
14004 constraint (inst.operands[2].reg > 7, BAD_HIREG);
14005 constraint (inst.operands[0].reg != inst.operands[1].reg,
14006 _("source1 and dest must be same register"));
14007
14008 switch (inst.instruction)
14009 {
14010 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
14011 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
14012 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
14013 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
14014 default: abort ();
14015 }
14016
14017 inst.instruction |= inst.operands[0].reg;
14018 inst.instruction |= inst.operands[2].reg << 3;
14019
14020 /* PR 12854: Error on extraneous shifts. */
14021 constraint (inst.operands[2].shifted,
14022 _("extraneous shift as part of operand to shift insn"));
14023 }
14024 else
14025 {
14026 switch (inst.instruction)
14027 {
14028 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
14029 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
14030 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
14031 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
14032 default: abort ();
14033 }
14034 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
14035 inst.instruction |= inst.operands[0].reg;
14036 inst.instruction |= inst.operands[1].reg << 3;
14037 }
14038 }
14039 }
14040
14041 static void
14042 do_t_simd (void)
14043 {
14044 unsigned Rd, Rn, Rm;
14045
14046 Rd = inst.operands[0].reg;
14047 Rn = inst.operands[1].reg;
14048 Rm = inst.operands[2].reg;
14049
14050 reject_bad_reg (Rd);
14051 reject_bad_reg (Rn);
14052 reject_bad_reg (Rm);
14053
14054 inst.instruction |= Rd << 8;
14055 inst.instruction |= Rn << 16;
14056 inst.instruction |= Rm;
14057 }
14058
14059 static void
14060 do_t_simd2 (void)
14061 {
14062 unsigned Rd, Rn, Rm;
14063
14064 Rd = inst.operands[0].reg;
14065 Rm = inst.operands[1].reg;
14066 Rn = inst.operands[2].reg;
14067
14068 reject_bad_reg (Rd);
14069 reject_bad_reg (Rn);
14070 reject_bad_reg (Rm);
14071
14072 inst.instruction |= Rd << 8;
14073 inst.instruction |= Rn << 16;
14074 inst.instruction |= Rm;
14075 }
14076
14077 static void
14078 do_t_smc (void)
14079 {
14080 unsigned int value = inst.relocs[0].exp.X_add_number;
14081 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
14082 _("SMC is not permitted on this architecture"));
14083 constraint (inst.relocs[0].exp.X_op != O_constant,
14084 _("expression too complex"));
14085 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
14086
14087 inst.relocs[0].type = BFD_RELOC_UNUSED;
14088 inst.instruction |= (value & 0x000f) << 16;
14089
14090 /* PR gas/15623: SMC instructions must be last in an IT block. */
14091 set_pred_insn_type_last ();
14092 }
14093
14094 static void
14095 do_t_hvc (void)
14096 {
14097 unsigned int value = inst.relocs[0].exp.X_add_number;
14098
14099 inst.relocs[0].type = BFD_RELOC_UNUSED;
14100 inst.instruction |= (value & 0x0fff);
14101 inst.instruction |= (value & 0xf000) << 4;
14102 }
14103
14104 static void
14105 do_t_ssat_usat (int bias)
14106 {
14107 unsigned Rd, Rn;
14108
14109 Rd = inst.operands[0].reg;
14110 Rn = inst.operands[2].reg;
14111
14112 reject_bad_reg (Rd);
14113 reject_bad_reg (Rn);
14114
14115 inst.instruction |= Rd << 8;
14116 inst.instruction |= inst.operands[1].imm - bias;
14117 inst.instruction |= Rn << 16;
14118
14119 if (inst.operands[3].present)
14120 {
14121 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
14122
14123 inst.relocs[0].type = BFD_RELOC_UNUSED;
14124
14125 constraint (inst.relocs[0].exp.X_op != O_constant,
14126 _("expression too complex"));
14127
14128 if (shift_amount != 0)
14129 {
14130 constraint (shift_amount > 31,
14131 _("shift expression is too large"));
14132
14133 if (inst.operands[3].shift_kind == SHIFT_ASR)
14134 inst.instruction |= 0x00200000; /* sh bit. */
14135
14136 inst.instruction |= (shift_amount & 0x1c) << 10;
14137 inst.instruction |= (shift_amount & 0x03) << 6;
14138 }
14139 }
14140 }
14141
14142 static void
14143 do_t_ssat (void)
14144 {
14145 do_t_ssat_usat (1);
14146 }
14147
14148 static void
14149 do_t_ssat16 (void)
14150 {
14151 unsigned Rd, Rn;
14152
14153 Rd = inst.operands[0].reg;
14154 Rn = inst.operands[2].reg;
14155
14156 reject_bad_reg (Rd);
14157 reject_bad_reg (Rn);
14158
14159 inst.instruction |= Rd << 8;
14160 inst.instruction |= inst.operands[1].imm - 1;
14161 inst.instruction |= Rn << 16;
14162 }
14163
14164 static void
14165 do_t_strex (void)
14166 {
14167 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14168 || inst.operands[2].postind || inst.operands[2].writeback
14169 || inst.operands[2].immisreg || inst.operands[2].shifted
14170 || inst.operands[2].negative,
14171 BAD_ADDR_MODE);
14172
14173 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14174
14175 inst.instruction |= inst.operands[0].reg << 8;
14176 inst.instruction |= inst.operands[1].reg << 12;
14177 inst.instruction |= inst.operands[2].reg << 16;
14178 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
14179 }
14180
14181 static void
14182 do_t_strexd (void)
14183 {
14184 if (!inst.operands[2].present)
14185 inst.operands[2].reg = inst.operands[1].reg + 1;
14186
14187 constraint (inst.operands[0].reg == inst.operands[1].reg
14188 || inst.operands[0].reg == inst.operands[2].reg
14189 || inst.operands[0].reg == inst.operands[3].reg,
14190 BAD_OVERLAP);
14191
14192 inst.instruction |= inst.operands[0].reg;
14193 inst.instruction |= inst.operands[1].reg << 12;
14194 inst.instruction |= inst.operands[2].reg << 8;
14195 inst.instruction |= inst.operands[3].reg << 16;
14196 }
14197
14198 static void
14199 do_t_sxtah (void)
14200 {
14201 unsigned Rd, Rn, Rm;
14202
14203 Rd = inst.operands[0].reg;
14204 Rn = inst.operands[1].reg;
14205 Rm = inst.operands[2].reg;
14206
14207 reject_bad_reg (Rd);
14208 reject_bad_reg (Rn);
14209 reject_bad_reg (Rm);
14210
14211 inst.instruction |= Rd << 8;
14212 inst.instruction |= Rn << 16;
14213 inst.instruction |= Rm;
14214 inst.instruction |= inst.operands[3].imm << 4;
14215 }
14216
14217 static void
14218 do_t_sxth (void)
14219 {
14220 unsigned Rd, Rm;
14221
14222 Rd = inst.operands[0].reg;
14223 Rm = inst.operands[1].reg;
14224
14225 reject_bad_reg (Rd);
14226 reject_bad_reg (Rm);
14227
14228 if (inst.instruction <= 0xffff
14229 && inst.size_req != 4
14230 && Rd <= 7 && Rm <= 7
14231 && (!inst.operands[2].present || inst.operands[2].imm == 0))
14232 {
14233 inst.instruction = THUMB_OP16 (inst.instruction);
14234 inst.instruction |= Rd;
14235 inst.instruction |= Rm << 3;
14236 }
14237 else if (unified_syntax)
14238 {
14239 if (inst.instruction <= 0xffff)
14240 inst.instruction = THUMB_OP32 (inst.instruction);
14241 inst.instruction |= Rd << 8;
14242 inst.instruction |= Rm;
14243 inst.instruction |= inst.operands[2].imm << 4;
14244 }
14245 else
14246 {
14247 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14248 _("Thumb encoding does not support rotation"));
14249 constraint (1, BAD_HIREG);
14250 }
14251 }
14252
14253 static void
14254 do_t_swi (void)
14255 {
14256 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
14257 }
14258
14259 static void
14260 do_t_tb (void)
14261 {
14262 unsigned Rn, Rm;
14263 int half;
14264
14265 half = (inst.instruction & 0x10) != 0;
14266 set_pred_insn_type_last ();
14267 constraint (inst.operands[0].immisreg,
14268 _("instruction requires register index"));
14269
14270 Rn = inst.operands[0].reg;
14271 Rm = inst.operands[0].imm;
14272
14273 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14274 constraint (Rn == REG_SP, BAD_SP);
14275 reject_bad_reg (Rm);
14276
14277 constraint (!half && inst.operands[0].shifted,
14278 _("instruction does not allow shifted index"));
14279 inst.instruction |= (Rn << 16) | Rm;
14280 }
14281
14282 static void
14283 do_t_udf (void)
14284 {
14285 if (!inst.operands[0].present)
14286 inst.operands[0].imm = 0;
14287
14288 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14289 {
14290 constraint (inst.size_req == 2,
14291 _("immediate value out of range"));
14292 inst.instruction = THUMB_OP32 (inst.instruction);
14293 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14294 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14295 }
14296 else
14297 {
14298 inst.instruction = THUMB_OP16 (inst.instruction);
14299 inst.instruction |= inst.operands[0].imm;
14300 }
14301
14302 set_pred_insn_type (NEUTRAL_IT_INSN);
14303 }
14304
14305
14306 static void
14307 do_t_usat (void)
14308 {
14309 do_t_ssat_usat (0);
14310 }
14311
14312 static void
14313 do_t_usat16 (void)
14314 {
14315 unsigned Rd, Rn;
14316
14317 Rd = inst.operands[0].reg;
14318 Rn = inst.operands[2].reg;
14319
14320 reject_bad_reg (Rd);
14321 reject_bad_reg (Rn);
14322
14323 inst.instruction |= Rd << 8;
14324 inst.instruction |= inst.operands[1].imm;
14325 inst.instruction |= Rn << 16;
14326 }
14327
14328 /* Checking the range of the branch offset (VAL) with NBITS bits
14329 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14330 static int
14331 v8_1_branch_value_check (int val, int nbits, int is_signed)
14332 {
14333 gas_assert (nbits > 0 && nbits <= 32);
14334 if (is_signed)
14335 {
14336 int cmp = (1 << (nbits - 1));
14337 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14338 return FAIL;
14339 }
14340 else
14341 {
14342 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14343 return FAIL;
14344 }
14345 return SUCCESS;
14346 }
14347
14348 /* For branches in Armv8.1-M Mainline. */
14349 static void
14350 do_t_branch_future (void)
14351 {
14352 unsigned long insn = inst.instruction;
14353
14354 inst.instruction = THUMB_OP32 (inst.instruction);
14355 if (inst.operands[0].hasreloc == 0)
14356 {
14357 if (v8_1_branch_value_check (inst.operands[0].imm, 5, false) == FAIL)
14358 as_bad (BAD_BRANCH_OFF);
14359
14360 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14361 }
14362 else
14363 {
14364 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14365 inst.relocs[0].pc_rel = 1;
14366 }
14367
14368 switch (insn)
14369 {
14370 case T_MNEM_bf:
14371 if (inst.operands[1].hasreloc == 0)
14372 {
14373 int val = inst.operands[1].imm;
14374 if (v8_1_branch_value_check (inst.operands[1].imm, 17, true) == FAIL)
14375 as_bad (BAD_BRANCH_OFF);
14376
14377 int immA = (val & 0x0001f000) >> 12;
14378 int immB = (val & 0x00000ffc) >> 2;
14379 int immC = (val & 0x00000002) >> 1;
14380 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14381 }
14382 else
14383 {
14384 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14385 inst.relocs[1].pc_rel = 1;
14386 }
14387 break;
14388
14389 case T_MNEM_bfl:
14390 if (inst.operands[1].hasreloc == 0)
14391 {
14392 int val = inst.operands[1].imm;
14393 if (v8_1_branch_value_check (inst.operands[1].imm, 19, true) == FAIL)
14394 as_bad (BAD_BRANCH_OFF);
14395
14396 int immA = (val & 0x0007f000) >> 12;
14397 int immB = (val & 0x00000ffc) >> 2;
14398 int immC = (val & 0x00000002) >> 1;
14399 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14400 }
14401 else
14402 {
14403 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14404 inst.relocs[1].pc_rel = 1;
14405 }
14406 break;
14407
14408 case T_MNEM_bfcsel:
14409 /* Operand 1. */
14410 if (inst.operands[1].hasreloc == 0)
14411 {
14412 int val = inst.operands[1].imm;
14413 int immA = (val & 0x00001000) >> 12;
14414 int immB = (val & 0x00000ffc) >> 2;
14415 int immC = (val & 0x00000002) >> 1;
14416 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14417 }
14418 else
14419 {
14420 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14421 inst.relocs[1].pc_rel = 1;
14422 }
14423
14424 /* Operand 2. */
14425 if (inst.operands[2].hasreloc == 0)
14426 {
14427 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14428 int val2 = inst.operands[2].imm;
14429 int val0 = inst.operands[0].imm & 0x1f;
14430 int diff = val2 - val0;
14431 if (diff == 4)
14432 inst.instruction |= 1 << 17; /* T bit. */
14433 else if (diff != 2)
14434 as_bad (_("out of range label-relative fixup value"));
14435 }
14436 else
14437 {
14438 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14439 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14440 inst.relocs[2].pc_rel = 1;
14441 }
14442
14443 /* Operand 3. */
14444 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14445 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14446 break;
14447
14448 case T_MNEM_bfx:
14449 case T_MNEM_bflx:
14450 inst.instruction |= inst.operands[1].reg << 16;
14451 break;
14452
14453 default: abort ();
14454 }
14455 }
14456
14457 /* Helper function for do_t_loloop to handle relocations. */
14458 static void
14459 v8_1_loop_reloc (int is_le)
14460 {
14461 if (inst.relocs[0].exp.X_op == O_constant)
14462 {
14463 int value = inst.relocs[0].exp.X_add_number;
14464 value = (is_le) ? -value : value;
14465
14466 if (v8_1_branch_value_check (value, 12, false) == FAIL)
14467 as_bad (BAD_BRANCH_OFF);
14468
14469 int imml, immh;
14470
14471 immh = (value & 0x00000ffc) >> 2;
14472 imml = (value & 0x00000002) >> 1;
14473
14474 inst.instruction |= (imml << 11) | (immh << 1);
14475 }
14476 else
14477 {
14478 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14479 inst.relocs[0].pc_rel = 1;
14480 }
14481 }
14482
14483 /* For shifts with four operands in MVE. */
14484 static void
14485 do_mve_scalar_shift1 (void)
14486 {
14487 unsigned int value = inst.operands[2].imm;
14488
14489 inst.instruction |= inst.operands[0].reg << 16;
14490 inst.instruction |= inst.operands[1].reg << 8;
14491
14492 /* Setting the bit for saturation. */
14493 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14494
14495 /* Assuming Rm is already checked not to be 11x1. */
14496 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14497 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14498 inst.instruction |= inst.operands[3].reg << 12;
14499 }
14500
14501 /* For shifts in MVE. */
14502 static void
14503 do_mve_scalar_shift (void)
14504 {
14505 if (!inst.operands[2].present)
14506 {
14507 inst.operands[2] = inst.operands[1];
14508 inst.operands[1].reg = 0xf;
14509 }
14510
14511 inst.instruction |= inst.operands[0].reg << 16;
14512 inst.instruction |= inst.operands[1].reg << 8;
14513
14514 if (inst.operands[2].isreg)
14515 {
14516 /* Assuming Rm is already checked not to be 11x1. */
14517 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14518 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14519 inst.instruction |= inst.operands[2].reg << 12;
14520 }
14521 else
14522 {
14523 /* Assuming imm is already checked as [1,32]. */
14524 unsigned int value = inst.operands[2].imm;
14525 inst.instruction |= (value & 0x1c) << 10;
14526 inst.instruction |= (value & 0x03) << 6;
14527 /* Change last 4 bits from 0xd to 0xf. */
14528 inst.instruction |= 0x2;
14529 }
14530 }
14531
14532 /* MVE instruction encoder helpers. */
14533 #define M_MNEM_vabav 0xee800f01
14534 #define M_MNEM_vmladav 0xeef00e00
14535 #define M_MNEM_vmladava 0xeef00e20
14536 #define M_MNEM_vmladavx 0xeef01e00
14537 #define M_MNEM_vmladavax 0xeef01e20
14538 #define M_MNEM_vmlsdav 0xeef00e01
14539 #define M_MNEM_vmlsdava 0xeef00e21
14540 #define M_MNEM_vmlsdavx 0xeef01e01
14541 #define M_MNEM_vmlsdavax 0xeef01e21
14542 #define M_MNEM_vmullt 0xee011e00
14543 #define M_MNEM_vmullb 0xee010e00
14544 #define M_MNEM_vctp 0xf000e801
14545 #define M_MNEM_vst20 0xfc801e00
14546 #define M_MNEM_vst21 0xfc801e20
14547 #define M_MNEM_vst40 0xfc801e01
14548 #define M_MNEM_vst41 0xfc801e21
14549 #define M_MNEM_vst42 0xfc801e41
14550 #define M_MNEM_vst43 0xfc801e61
14551 #define M_MNEM_vld20 0xfc901e00
14552 #define M_MNEM_vld21 0xfc901e20
14553 #define M_MNEM_vld40 0xfc901e01
14554 #define M_MNEM_vld41 0xfc901e21
14555 #define M_MNEM_vld42 0xfc901e41
14556 #define M_MNEM_vld43 0xfc901e61
14557 #define M_MNEM_vstrb 0xec000e00
14558 #define M_MNEM_vstrh 0xec000e10
14559 #define M_MNEM_vstrw 0xec000e40
14560 #define M_MNEM_vstrd 0xec000e50
14561 #define M_MNEM_vldrb 0xec100e00
14562 #define M_MNEM_vldrh 0xec100e10
14563 #define M_MNEM_vldrw 0xec100e40
14564 #define M_MNEM_vldrd 0xec100e50
14565 #define M_MNEM_vmovlt 0xeea01f40
14566 #define M_MNEM_vmovlb 0xeea00f40
14567 #define M_MNEM_vmovnt 0xfe311e81
14568 #define M_MNEM_vmovnb 0xfe310e81
14569 #define M_MNEM_vadc 0xee300f00
14570 #define M_MNEM_vadci 0xee301f00
14571 #define M_MNEM_vbrsr 0xfe011e60
14572 #define M_MNEM_vaddlv 0xee890f00
14573 #define M_MNEM_vaddlva 0xee890f20
14574 #define M_MNEM_vaddv 0xeef10f00
14575 #define M_MNEM_vaddva 0xeef10f20
14576 #define M_MNEM_vddup 0xee011f6e
14577 #define M_MNEM_vdwdup 0xee011f60
14578 #define M_MNEM_vidup 0xee010f6e
14579 #define M_MNEM_viwdup 0xee010f60
14580 #define M_MNEM_vmaxv 0xeee20f00
14581 #define M_MNEM_vmaxav 0xeee00f00
14582 #define M_MNEM_vminv 0xeee20f80
14583 #define M_MNEM_vminav 0xeee00f80
14584 #define M_MNEM_vmlaldav 0xee800e00
14585 #define M_MNEM_vmlaldava 0xee800e20
14586 #define M_MNEM_vmlaldavx 0xee801e00
14587 #define M_MNEM_vmlaldavax 0xee801e20
14588 #define M_MNEM_vmlsldav 0xee800e01
14589 #define M_MNEM_vmlsldava 0xee800e21
14590 #define M_MNEM_vmlsldavx 0xee801e01
14591 #define M_MNEM_vmlsldavax 0xee801e21
14592 #define M_MNEM_vrmlaldavhx 0xee801f00
14593 #define M_MNEM_vrmlaldavhax 0xee801f20
14594 #define M_MNEM_vrmlsldavh 0xfe800e01
14595 #define M_MNEM_vrmlsldavha 0xfe800e21
14596 #define M_MNEM_vrmlsldavhx 0xfe801e01
14597 #define M_MNEM_vrmlsldavhax 0xfe801e21
14598 #define M_MNEM_vqmovnt 0xee331e01
14599 #define M_MNEM_vqmovnb 0xee330e01
14600 #define M_MNEM_vqmovunt 0xee311e81
14601 #define M_MNEM_vqmovunb 0xee310e81
14602 #define M_MNEM_vshrnt 0xee801fc1
14603 #define M_MNEM_vshrnb 0xee800fc1
14604 #define M_MNEM_vrshrnt 0xfe801fc1
14605 #define M_MNEM_vqshrnt 0xee801f40
14606 #define M_MNEM_vqshrnb 0xee800f40
14607 #define M_MNEM_vqshrunt 0xee801fc0
14608 #define M_MNEM_vqshrunb 0xee800fc0
14609 #define M_MNEM_vrshrnb 0xfe800fc1
14610 #define M_MNEM_vqrshrnt 0xee801f41
14611 #define M_MNEM_vqrshrnb 0xee800f41
14612 #define M_MNEM_vqrshrunt 0xfe801fc0
14613 #define M_MNEM_vqrshrunb 0xfe800fc0
14614
14615 /* Bfloat16 instruction encoder helpers. */
14616 #define B_MNEM_vfmat 0xfc300850
14617 #define B_MNEM_vfmab 0xfc300810
14618
14619 /* Neon instruction encoder helpers. */
14620
14621 /* Encodings for the different types for various Neon opcodes. */
14622
14623 /* An "invalid" code for the following tables. */
14624 #define N_INV -1u
14625
14626 struct neon_tab_entry
14627 {
14628 unsigned integer;
14629 unsigned float_or_poly;
14630 unsigned scalar_or_imm;
14631 };
14632
14633 /* Map overloaded Neon opcodes to their respective encodings. */
14634 #define NEON_ENC_TAB \
14635 X(vabd, 0x0000700, 0x1200d00, N_INV), \
14636 X(vabdl, 0x0800700, N_INV, N_INV), \
14637 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14638 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14639 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14640 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14641 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14642 X(vadd, 0x0000800, 0x0000d00, N_INV), \
14643 X(vaddl, 0x0800000, N_INV, N_INV), \
14644 X(vsub, 0x1000800, 0x0200d00, N_INV), \
14645 X(vsubl, 0x0800200, N_INV, N_INV), \
14646 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14647 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14648 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14649 /* Register variants of the following two instructions are encoded as
14650 vcge / vcgt with the operands reversed. */ \
14651 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14652 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
14653 X(vfma, N_INV, 0x0000c10, N_INV), \
14654 X(vfms, N_INV, 0x0200c10, N_INV), \
14655 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14656 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14657 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14658 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14659 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14660 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14661 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14662 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14663 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14664 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14665 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
14666 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14667 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
14668 X(vshl, 0x0000400, N_INV, 0x0800510), \
14669 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14670 X(vand, 0x0000110, N_INV, 0x0800030), \
14671 X(vbic, 0x0100110, N_INV, 0x0800030), \
14672 X(veor, 0x1000110, N_INV, N_INV), \
14673 X(vorn, 0x0300110, N_INV, 0x0800010), \
14674 X(vorr, 0x0200110, N_INV, 0x0800010), \
14675 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14676 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14677 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14678 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14679 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14680 X(vst1, 0x0000000, 0x0800000, N_INV), \
14681 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14682 X(vst2, 0x0000100, 0x0800100, N_INV), \
14683 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14684 X(vst3, 0x0000200, 0x0800200, N_INV), \
14685 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14686 X(vst4, 0x0000300, 0x0800300, N_INV), \
14687 X(vmovn, 0x1b20200, N_INV, N_INV), \
14688 X(vtrn, 0x1b20080, N_INV, N_INV), \
14689 X(vqmovn, 0x1b20200, N_INV, N_INV), \
14690 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14691 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
14692 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14693 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
14694 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14695 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
14696 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14697 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14698 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
14699 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14700 X(vseleq, 0xe000a00, N_INV, N_INV), \
14701 X(vselvs, 0xe100a00, N_INV, N_INV), \
14702 X(vselge, 0xe200a00, N_INV, N_INV), \
14703 X(vselgt, 0xe300a00, N_INV, N_INV), \
14704 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
14705 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
14706 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14707 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
14708 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
14709 X(aes, 0x3b00300, N_INV, N_INV), \
14710 X(sha3op, 0x2000c00, N_INV, N_INV), \
14711 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14712 X(sha2op, 0x3ba0380, N_INV, N_INV)
14713
14714 enum neon_opc
14715 {
14716 #define X(OPC,I,F,S) N_MNEM_##OPC
14717 NEON_ENC_TAB
14718 #undef X
14719 };
14720
14721 static const struct neon_tab_entry neon_enc_tab[] =
14722 {
14723 #define X(OPC,I,F,S) { (I), (F), (S) }
14724 NEON_ENC_TAB
14725 #undef X
14726 };
14727
14728 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
14729 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14730 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14731 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14732 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14733 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14734 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14735 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14736 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14737 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14738 #define NEON_ENC_SINGLE_(X) \
14739 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
14740 #define NEON_ENC_DOUBLE_(X) \
14741 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
14742 #define NEON_ENC_FPV8_(X) \
14743 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
14744
14745 #define NEON_ENCODE(type, inst) \
14746 do \
14747 { \
14748 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14749 inst.is_neon = 1; \
14750 } \
14751 while (0)
14752
14753 #define check_neon_suffixes \
14754 do \
14755 { \
14756 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14757 { \
14758 as_bad (_("invalid neon suffix for non neon instruction")); \
14759 return; \
14760 } \
14761 } \
14762 while (0)
14763
14764 /* Define shapes for instruction operands. The following mnemonic characters
14765 are used in this table:
14766
14767 F - VFP S<n> register
14768 D - Neon D<n> register
14769 Q - Neon Q<n> register
14770 I - Immediate
14771 S - Scalar
14772 R - ARM register
14773 L - D<n> register list
14774
14775 This table is used to generate various data:
14776 - enumerations of the form NS_DDR to be used as arguments to
14777 neon_select_shape.
14778 - a table classifying shapes into single, double, quad, mixed.
14779 - a table used to drive neon_select_shape. */
14780
14781 #define NEON_SHAPE_DEF \
14782 X(4, (R, R, Q, Q), QUAD), \
14783 X(4, (Q, R, R, I), QUAD), \
14784 X(4, (R, R, S, S), QUAD), \
14785 X(4, (S, S, R, R), QUAD), \
14786 X(3, (Q, R, I), QUAD), \
14787 X(3, (I, Q, Q), QUAD), \
14788 X(3, (I, Q, R), QUAD), \
14789 X(3, (R, Q, Q), QUAD), \
14790 X(3, (D, D, D), DOUBLE), \
14791 X(3, (Q, Q, Q), QUAD), \
14792 X(3, (D, D, I), DOUBLE), \
14793 X(3, (Q, Q, I), QUAD), \
14794 X(3, (D, D, S), DOUBLE), \
14795 X(3, (Q, Q, S), QUAD), \
14796 X(3, (Q, Q, R), QUAD), \
14797 X(3, (R, R, Q), QUAD), \
14798 X(2, (R, Q), QUAD), \
14799 X(2, (D, D), DOUBLE), \
14800 X(2, (Q, Q), QUAD), \
14801 X(2, (D, S), DOUBLE), \
14802 X(2, (Q, S), QUAD), \
14803 X(2, (D, R), DOUBLE), \
14804 X(2, (Q, R), QUAD), \
14805 X(2, (D, I), DOUBLE), \
14806 X(2, (Q, I), QUAD), \
14807 X(3, (P, F, I), SINGLE), \
14808 X(3, (P, D, I), DOUBLE), \
14809 X(3, (P, Q, I), QUAD), \
14810 X(4, (P, F, F, I), SINGLE), \
14811 X(4, (P, D, D, I), DOUBLE), \
14812 X(4, (P, Q, Q, I), QUAD), \
14813 X(5, (P, F, F, F, I), SINGLE), \
14814 X(5, (P, D, D, D, I), DOUBLE), \
14815 X(5, (P, Q, Q, Q, I), QUAD), \
14816 X(3, (D, L, D), DOUBLE), \
14817 X(2, (D, Q), MIXED), \
14818 X(2, (Q, D), MIXED), \
14819 X(3, (D, Q, I), MIXED), \
14820 X(3, (Q, D, I), MIXED), \
14821 X(3, (Q, D, D), MIXED), \
14822 X(3, (D, Q, Q), MIXED), \
14823 X(3, (Q, Q, D), MIXED), \
14824 X(3, (Q, D, S), MIXED), \
14825 X(3, (D, Q, S), MIXED), \
14826 X(4, (D, D, D, I), DOUBLE), \
14827 X(4, (Q, Q, Q, I), QUAD), \
14828 X(4, (D, D, S, I), DOUBLE), \
14829 X(4, (Q, Q, S, I), QUAD), \
14830 X(2, (F, F), SINGLE), \
14831 X(3, (F, F, F), SINGLE), \
14832 X(2, (F, I), SINGLE), \
14833 X(2, (F, D), MIXED), \
14834 X(2, (D, F), MIXED), \
14835 X(3, (F, F, I), MIXED), \
14836 X(4, (R, R, F, F), SINGLE), \
14837 X(4, (F, F, R, R), SINGLE), \
14838 X(3, (D, R, R), DOUBLE), \
14839 X(3, (R, R, D), DOUBLE), \
14840 X(2, (S, R), SINGLE), \
14841 X(2, (R, S), SINGLE), \
14842 X(2, (F, R), SINGLE), \
14843 X(2, (R, F), SINGLE), \
14844 /* Used for MVE tail predicated loop instructions. */\
14845 X(2, (R, R), QUAD), \
14846 /* Half float shape supported so far. */\
14847 X (2, (H, D), MIXED), \
14848 X (2, (D, H), MIXED), \
14849 X (2, (H, F), MIXED), \
14850 X (2, (F, H), MIXED), \
14851 X (2, (H, H), HALF), \
14852 X (2, (H, R), HALF), \
14853 X (2, (R, H), HALF), \
14854 X (2, (H, I), HALF), \
14855 X (3, (H, H, H), HALF), \
14856 X (3, (H, F, I), MIXED), \
14857 X (3, (F, H, I), MIXED), \
14858 X (3, (D, H, H), MIXED), \
14859 X (3, (D, H, S), MIXED)
14860
14861 #define S2(A,B) NS_##A##B
14862 #define S3(A,B,C) NS_##A##B##C
14863 #define S4(A,B,C,D) NS_##A##B##C##D
14864 #define S5(A,B,C,D,E) NS_##A##B##C##D##E
14865
14866 #define X(N, L, C) S##N L
14867
14868 enum neon_shape
14869 {
14870 NEON_SHAPE_DEF,
14871 NS_NULL
14872 };
14873
14874 #undef X
14875 #undef S2
14876 #undef S3
14877 #undef S4
14878 #undef S5
14879
14880 enum neon_shape_class
14881 {
14882 SC_HALF,
14883 SC_SINGLE,
14884 SC_DOUBLE,
14885 SC_QUAD,
14886 SC_MIXED
14887 };
14888
14889 #define X(N, L, C) SC_##C
14890
14891 static enum neon_shape_class neon_shape_class[] =
14892 {
14893 NEON_SHAPE_DEF
14894 };
14895
14896 #undef X
14897
14898 enum neon_shape_el
14899 {
14900 SE_H,
14901 SE_F,
14902 SE_D,
14903 SE_Q,
14904 SE_I,
14905 SE_S,
14906 SE_R,
14907 SE_L,
14908 SE_P
14909 };
14910
14911 /* Register widths of above. */
14912 static unsigned neon_shape_el_size[] =
14913 {
14914 16,
14915 32,
14916 64,
14917 128,
14918 0,
14919 32,
14920 32,
14921 0,
14922 0
14923 };
14924
14925 struct neon_shape_info
14926 {
14927 unsigned els;
14928 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14929 };
14930
14931 #define S2(A,B) { SE_##A, SE_##B }
14932 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14933 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14934 #define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E }
14935
14936 #define X(N, L, C) { N, S##N L }
14937
14938 static struct neon_shape_info neon_shape_tab[] =
14939 {
14940 NEON_SHAPE_DEF
14941 };
14942
14943 #undef X
14944 #undef S2
14945 #undef S3
14946 #undef S4
14947 #undef S5
14948
14949 /* Bit masks used in type checking given instructions.
14950 'N_EQK' means the type must be the same as (or based on in some way) the key
14951 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14952 set, various other bits can be set as well in order to modify the meaning of
14953 the type constraint. */
14954
14955 enum neon_type_mask
14956 {
14957 N_S8 = 0x0000001,
14958 N_S16 = 0x0000002,
14959 N_S32 = 0x0000004,
14960 N_S64 = 0x0000008,
14961 N_U8 = 0x0000010,
14962 N_U16 = 0x0000020,
14963 N_U32 = 0x0000040,
14964 N_U64 = 0x0000080,
14965 N_I8 = 0x0000100,
14966 N_I16 = 0x0000200,
14967 N_I32 = 0x0000400,
14968 N_I64 = 0x0000800,
14969 N_8 = 0x0001000,
14970 N_16 = 0x0002000,
14971 N_32 = 0x0004000,
14972 N_64 = 0x0008000,
14973 N_P8 = 0x0010000,
14974 N_P16 = 0x0020000,
14975 N_F16 = 0x0040000,
14976 N_F32 = 0x0080000,
14977 N_F64 = 0x0100000,
14978 N_P64 = 0x0200000,
14979 N_BF16 = 0x0400000,
14980 N_KEY = 0x1000000, /* Key element (main type specifier). */
14981 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
14982 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
14983 N_UNT = 0x8000000, /* Must be explicitly untyped. */
14984 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14985 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14986 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14987 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14988 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14989 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14990 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
14991 N_UTYP = 0,
14992 N_MAX_NONSPECIAL = N_P64
14993 };
14994
14995 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14996
14997 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14998 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14999 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
15000 #define N_S_32 (N_S8 | N_S16 | N_S32)
15001 #define N_F_16_32 (N_F16 | N_F32)
15002 #define N_SUF_32 (N_SU_32 | N_F_16_32)
15003 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
15004 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
15005 #define N_F_ALL (N_F16 | N_F32 | N_F64)
15006 #define N_I_MVE (N_I8 | N_I16 | N_I32)
15007 #define N_F_MVE (N_F16 | N_F32)
15008 #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
15009
15010 /* Pass this as the first type argument to neon_check_type to ignore types
15011 altogether. */
15012 #define N_IGNORE_TYPE (N_KEY | N_EQK)
15013
15014 /* Select a "shape" for the current instruction (describing register types or
15015 sizes) from a list of alternatives. Return NS_NULL if the current instruction
15016 doesn't fit. For non-polymorphic shapes, checking is usually done as a
15017 function of operand parsing, so this function doesn't need to be called.
15018 Shapes should be listed in order of decreasing length. */
15019
15020 static enum neon_shape
15021 neon_select_shape (enum neon_shape shape, ...)
15022 {
15023 va_list ap;
15024 enum neon_shape first_shape = shape;
15025
15026 /* Fix missing optional operands. FIXME: we don't know at this point how
15027 many arguments we should have, so this makes the assumption that we have
15028 > 1. This is true of all current Neon opcodes, I think, but may not be
15029 true in the future. */
15030 if (!inst.operands[1].present)
15031 inst.operands[1] = inst.operands[0];
15032
15033 va_start (ap, shape);
15034
15035 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
15036 {
15037 unsigned j;
15038 int matches = 1;
15039
15040 for (j = 0; j < neon_shape_tab[shape].els; j++)
15041 {
15042 if (!inst.operands[j].present)
15043 {
15044 matches = 0;
15045 break;
15046 }
15047
15048 switch (neon_shape_tab[shape].el[j])
15049 {
15050 /* If a .f16, .16, .u16, .s16 type specifier is given over
15051 a VFP single precision register operand, it's essentially
15052 means only half of the register is used.
15053
15054 If the type specifier is given after the mnemonics, the
15055 information is stored in inst.vectype. If the type specifier
15056 is given after register operand, the information is stored
15057 in inst.operands[].vectype.
15058
15059 When there is only one type specifier, and all the register
15060 operands are the same type of hardware register, the type
15061 specifier applies to all register operands.
15062
15063 If no type specifier is given, the shape is inferred from
15064 operand information.
15065
15066 for example:
15067 vadd.f16 s0, s1, s2: NS_HHH
15068 vabs.f16 s0, s1: NS_HH
15069 vmov.f16 s0, r1: NS_HR
15070 vmov.f16 r0, s1: NS_RH
15071 vcvt.f16 r0, s1: NS_RH
15072 vcvt.f16.s32 s2, s2, #29: NS_HFI
15073 vcvt.f16.s32 s2, s2: NS_HF
15074 */
15075 case SE_H:
15076 if (!(inst.operands[j].isreg
15077 && inst.operands[j].isvec
15078 && inst.operands[j].issingle
15079 && !inst.operands[j].isquad
15080 && ((inst.vectype.elems == 1
15081 && inst.vectype.el[0].size == 16)
15082 || (inst.vectype.elems > 1
15083 && inst.vectype.el[j].size == 16)
15084 || (inst.vectype.elems == 0
15085 && inst.operands[j].vectype.type != NT_invtype
15086 && inst.operands[j].vectype.size == 16))))
15087 matches = 0;
15088 break;
15089
15090 case SE_F:
15091 if (!(inst.operands[j].isreg
15092 && inst.operands[j].isvec
15093 && inst.operands[j].issingle
15094 && !inst.operands[j].isquad
15095 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
15096 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
15097 || (inst.vectype.elems == 0
15098 && (inst.operands[j].vectype.size == 32
15099 || inst.operands[j].vectype.type == NT_invtype)))))
15100 matches = 0;
15101 break;
15102
15103 case SE_D:
15104 if (!(inst.operands[j].isreg
15105 && inst.operands[j].isvec
15106 && !inst.operands[j].isquad
15107 && !inst.operands[j].issingle))
15108 matches = 0;
15109 break;
15110
15111 case SE_R:
15112 if (!(inst.operands[j].isreg
15113 && !inst.operands[j].isvec))
15114 matches = 0;
15115 break;
15116
15117 case SE_Q:
15118 if (!(inst.operands[j].isreg
15119 && inst.operands[j].isvec
15120 && inst.operands[j].isquad
15121 && !inst.operands[j].issingle))
15122 matches = 0;
15123 break;
15124
15125 case SE_I:
15126 if (!(!inst.operands[j].isreg
15127 && !inst.operands[j].isscalar))
15128 matches = 0;
15129 break;
15130
15131 case SE_S:
15132 if (!(!inst.operands[j].isreg
15133 && inst.operands[j].isscalar))
15134 matches = 0;
15135 break;
15136
15137 case SE_P:
15138 case SE_L:
15139 break;
15140 }
15141 if (!matches)
15142 break;
15143 }
15144 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15145 /* We've matched all the entries in the shape table, and we don't
15146 have any left over operands which have not been matched. */
15147 break;
15148 }
15149
15150 va_end (ap);
15151
15152 if (shape == NS_NULL && first_shape != NS_NULL)
15153 first_error (_("invalid instruction shape"));
15154
15155 return shape;
15156 }
15157
15158 /* True if SHAPE is predominantly a quadword operation (most of the time, this
15159 means the Q bit should be set). */
15160
15161 static int
15162 neon_quad (enum neon_shape shape)
15163 {
15164 return neon_shape_class[shape] == SC_QUAD;
15165 }
15166
15167 static void
15168 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
15169 unsigned *g_size)
15170 {
15171 /* Allow modification to be made to types which are constrained to be
15172 based on the key element, based on bits set alongside N_EQK. */
15173 if ((typebits & N_EQK) != 0)
15174 {
15175 if ((typebits & N_HLF) != 0)
15176 *g_size /= 2;
15177 else if ((typebits & N_DBL) != 0)
15178 *g_size *= 2;
15179 if ((typebits & N_SGN) != 0)
15180 *g_type = NT_signed;
15181 else if ((typebits & N_UNS) != 0)
15182 *g_type = NT_unsigned;
15183 else if ((typebits & N_INT) != 0)
15184 *g_type = NT_integer;
15185 else if ((typebits & N_FLT) != 0)
15186 *g_type = NT_float;
15187 else if ((typebits & N_SIZ) != 0)
15188 *g_type = NT_untyped;
15189 }
15190 }
15191
15192 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15193 operand type, i.e. the single type specified in a Neon instruction when it
15194 is the only one given. */
15195
15196 static struct neon_type_el
15197 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15198 {
15199 struct neon_type_el dest = *key;
15200
15201 gas_assert ((thisarg & N_EQK) != 0);
15202
15203 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15204
15205 return dest;
15206 }
15207
15208 /* Convert Neon type and size into compact bitmask representation. */
15209
15210 static enum neon_type_mask
15211 type_chk_of_el_type (enum neon_el_type type, unsigned size)
15212 {
15213 switch (type)
15214 {
15215 case NT_untyped:
15216 switch (size)
15217 {
15218 case 8: return N_8;
15219 case 16: return N_16;
15220 case 32: return N_32;
15221 case 64: return N_64;
15222 default: ;
15223 }
15224 break;
15225
15226 case NT_integer:
15227 switch (size)
15228 {
15229 case 8: return N_I8;
15230 case 16: return N_I16;
15231 case 32: return N_I32;
15232 case 64: return N_I64;
15233 default: ;
15234 }
15235 break;
15236
15237 case NT_float:
15238 switch (size)
15239 {
15240 case 16: return N_F16;
15241 case 32: return N_F32;
15242 case 64: return N_F64;
15243 default: ;
15244 }
15245 break;
15246
15247 case NT_poly:
15248 switch (size)
15249 {
15250 case 8: return N_P8;
15251 case 16: return N_P16;
15252 case 64: return N_P64;
15253 default: ;
15254 }
15255 break;
15256
15257 case NT_signed:
15258 switch (size)
15259 {
15260 case 8: return N_S8;
15261 case 16: return N_S16;
15262 case 32: return N_S32;
15263 case 64: return N_S64;
15264 default: ;
15265 }
15266 break;
15267
15268 case NT_unsigned:
15269 switch (size)
15270 {
15271 case 8: return N_U8;
15272 case 16: return N_U16;
15273 case 32: return N_U32;
15274 case 64: return N_U64;
15275 default: ;
15276 }
15277 break;
15278
15279 case NT_bfloat:
15280 if (size == 16) return N_BF16;
15281 break;
15282
15283 default: ;
15284 }
15285
15286 return N_UTYP;
15287 }
15288
15289 /* Convert compact Neon bitmask type representation to a type and size. Only
15290 handles the case where a single bit is set in the mask. */
15291
15292 static int
15293 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
15294 enum neon_type_mask mask)
15295 {
15296 if ((mask & N_EQK) != 0)
15297 return FAIL;
15298
15299 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15300 *size = 8;
15301 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16))
15302 != 0)
15303 *size = 16;
15304 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
15305 *size = 32;
15306 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
15307 *size = 64;
15308 else
15309 return FAIL;
15310
15311 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15312 *type = NT_signed;
15313 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
15314 *type = NT_unsigned;
15315 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
15316 *type = NT_integer;
15317 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
15318 *type = NT_untyped;
15319 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
15320 *type = NT_poly;
15321 else if ((mask & (N_F_ALL)) != 0)
15322 *type = NT_float;
15323 else if ((mask & (N_BF16)) != 0)
15324 *type = NT_bfloat;
15325 else
15326 return FAIL;
15327
15328 return SUCCESS;
15329 }
15330
15331 /* Modify a bitmask of allowed types. This is only needed for type
15332 relaxation. */
15333
15334 static unsigned
15335 modify_types_allowed (unsigned allowed, unsigned mods)
15336 {
15337 unsigned size;
15338 enum neon_el_type type;
15339 unsigned destmask;
15340 int i;
15341
15342 destmask = 0;
15343
15344 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15345 {
15346 if (el_type_of_type_chk (&type, &size,
15347 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15348 {
15349 neon_modify_type_size (mods, &type, &size);
15350 destmask |= type_chk_of_el_type (type, size);
15351 }
15352 }
15353
15354 return destmask;
15355 }
15356
15357 /* Check type and return type classification.
15358 The manual states (paraphrase): If one datatype is given, it indicates the
15359 type given in:
15360 - the second operand, if there is one
15361 - the operand, if there is no second operand
15362 - the result, if there are no operands.
15363 This isn't quite good enough though, so we use a concept of a "key" datatype
15364 which is set on a per-instruction basis, which is the one which matters when
15365 only one data type is written.
15366 Note: this function has side-effects (e.g. filling in missing operands). All
15367 Neon instructions should call it before performing bit encoding. */
15368
15369 static struct neon_type_el
15370 neon_check_type (unsigned els, enum neon_shape ns, ...)
15371 {
15372 va_list ap;
15373 unsigned i, pass, key_el = 0;
15374 unsigned types[NEON_MAX_TYPE_ELS];
15375 enum neon_el_type k_type = NT_invtype;
15376 unsigned k_size = -1u;
15377 struct neon_type_el badtype = {NT_invtype, -1};
15378 unsigned key_allowed = 0;
15379
15380 /* Optional registers in Neon instructions are always (not) in operand 1.
15381 Fill in the missing operand here, if it was omitted. */
15382 if (els > 1 && !inst.operands[1].present)
15383 inst.operands[1] = inst.operands[0];
15384
15385 /* Suck up all the varargs. */
15386 va_start (ap, ns);
15387 for (i = 0; i < els; i++)
15388 {
15389 unsigned thisarg = va_arg (ap, unsigned);
15390 if (thisarg == N_IGNORE_TYPE)
15391 {
15392 va_end (ap);
15393 return badtype;
15394 }
15395 types[i] = thisarg;
15396 if ((thisarg & N_KEY) != 0)
15397 key_el = i;
15398 }
15399 va_end (ap);
15400
15401 if (inst.vectype.elems > 0)
15402 for (i = 0; i < els; i++)
15403 if (inst.operands[i].vectype.type != NT_invtype)
15404 {
15405 first_error (_("types specified in both the mnemonic and operands"));
15406 return badtype;
15407 }
15408
15409 /* Duplicate inst.vectype elements here as necessary.
15410 FIXME: No idea if this is exactly the same as the ARM assembler,
15411 particularly when an insn takes one register and one non-register
15412 operand. */
15413 if (inst.vectype.elems == 1 && els > 1)
15414 {
15415 unsigned j;
15416 inst.vectype.elems = els;
15417 inst.vectype.el[key_el] = inst.vectype.el[0];
15418 for (j = 0; j < els; j++)
15419 if (j != key_el)
15420 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15421 types[j]);
15422 }
15423 else if (inst.vectype.elems == 0 && els > 0)
15424 {
15425 unsigned j;
15426 /* No types were given after the mnemonic, so look for types specified
15427 after each operand. We allow some flexibility here; as long as the
15428 "key" operand has a type, we can infer the others. */
15429 for (j = 0; j < els; j++)
15430 if (inst.operands[j].vectype.type != NT_invtype)
15431 inst.vectype.el[j] = inst.operands[j].vectype;
15432
15433 if (inst.operands[key_el].vectype.type != NT_invtype)
15434 {
15435 for (j = 0; j < els; j++)
15436 if (inst.operands[j].vectype.type == NT_invtype)
15437 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15438 types[j]);
15439 }
15440 else
15441 {
15442 first_error (_("operand types can't be inferred"));
15443 return badtype;
15444 }
15445 }
15446 else if (inst.vectype.elems != els)
15447 {
15448 first_error (_("type specifier has the wrong number of parts"));
15449 return badtype;
15450 }
15451
15452 for (pass = 0; pass < 2; pass++)
15453 {
15454 for (i = 0; i < els; i++)
15455 {
15456 unsigned thisarg = types[i];
15457 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15458 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15459 enum neon_el_type g_type = inst.vectype.el[i].type;
15460 unsigned g_size = inst.vectype.el[i].size;
15461
15462 /* Decay more-specific signed & unsigned types to sign-insensitive
15463 integer types if sign-specific variants are unavailable. */
15464 if ((g_type == NT_signed || g_type == NT_unsigned)
15465 && (types_allowed & N_SU_ALL) == 0)
15466 g_type = NT_integer;
15467
15468 /* If only untyped args are allowed, decay any more specific types to
15469 them. Some instructions only care about signs for some element
15470 sizes, so handle that properly. */
15471 if (((types_allowed & N_UNT) == 0)
15472 && ((g_size == 8 && (types_allowed & N_8) != 0)
15473 || (g_size == 16 && (types_allowed & N_16) != 0)
15474 || (g_size == 32 && (types_allowed & N_32) != 0)
15475 || (g_size == 64 && (types_allowed & N_64) != 0)))
15476 g_type = NT_untyped;
15477
15478 if (pass == 0)
15479 {
15480 if ((thisarg & N_KEY) != 0)
15481 {
15482 k_type = g_type;
15483 k_size = g_size;
15484 key_allowed = thisarg & ~N_KEY;
15485
15486 /* Check architecture constraint on FP16 extension. */
15487 if (k_size == 16
15488 && k_type == NT_float
15489 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15490 {
15491 inst.error = _(BAD_FP16);
15492 return badtype;
15493 }
15494 }
15495 }
15496 else
15497 {
15498 if ((thisarg & N_VFP) != 0)
15499 {
15500 enum neon_shape_el regshape;
15501 unsigned regwidth, match;
15502
15503 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15504 if (ns == NS_NULL)
15505 {
15506 first_error (_("invalid instruction shape"));
15507 return badtype;
15508 }
15509 regshape = neon_shape_tab[ns].el[i];
15510 regwidth = neon_shape_el_size[regshape];
15511
15512 /* In VFP mode, operands must match register widths. If we
15513 have a key operand, use its width, else use the width of
15514 the current operand. */
15515 if (k_size != -1u)
15516 match = k_size;
15517 else
15518 match = g_size;
15519
15520 /* FP16 will use a single precision register. */
15521 if (regwidth == 32 && match == 16)
15522 {
15523 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15524 match = regwidth;
15525 else
15526 {
15527 inst.error = _(BAD_FP16);
15528 return badtype;
15529 }
15530 }
15531
15532 if (regwidth != match)
15533 {
15534 first_error (_("operand size must match register width"));
15535 return badtype;
15536 }
15537 }
15538
15539 if ((thisarg & N_EQK) == 0)
15540 {
15541 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15542
15543 if ((given_type & types_allowed) == 0)
15544 {
15545 first_error (BAD_SIMD_TYPE);
15546 return badtype;
15547 }
15548 }
15549 else
15550 {
15551 enum neon_el_type mod_k_type = k_type;
15552 unsigned mod_k_size = k_size;
15553 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15554 if (g_type != mod_k_type || g_size != mod_k_size)
15555 {
15556 first_error (_("inconsistent types in Neon instruction"));
15557 return badtype;
15558 }
15559 }
15560 }
15561 }
15562 }
15563
15564 return inst.vectype.el[key_el];
15565 }
15566
15567 /* Neon-style VFP instruction forwarding. */
15568
15569 /* Thumb VFP instructions have 0xE in the condition field. */
15570
15571 static void
15572 do_vfp_cond_or_thumb (void)
15573 {
15574 inst.is_neon = 1;
15575
15576 if (thumb_mode)
15577 inst.instruction |= 0xe0000000;
15578 else
15579 inst.instruction |= inst.cond << 28;
15580 }
15581
15582 /* Look up and encode a simple mnemonic, for use as a helper function for the
15583 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15584 etc. It is assumed that operand parsing has already been done, and that the
15585 operands are in the form expected by the given opcode (this isn't necessarily
15586 the same as the form in which they were parsed, hence some massaging must
15587 take place before this function is called).
15588 Checks current arch version against that in the looked-up opcode. */
15589
15590 static void
15591 do_vfp_nsyn_opcode (const char *opname)
15592 {
15593 const struct asm_opcode *opcode;
15594
15595 opcode = (const struct asm_opcode *) str_hash_find (arm_ops_hsh, opname);
15596
15597 if (!opcode)
15598 abort ();
15599
15600 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
15601 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15602 _(BAD_FPU));
15603
15604 inst.is_neon = 1;
15605
15606 if (thumb_mode)
15607 {
15608 inst.instruction = opcode->tvalue;
15609 opcode->tencode ();
15610 }
15611 else
15612 {
15613 inst.instruction = (inst.cond << 28) | opcode->avalue;
15614 opcode->aencode ();
15615 }
15616 }
15617
15618 static void
15619 do_vfp_nsyn_add_sub (enum neon_shape rs)
15620 {
15621 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15622
15623 if (rs == NS_FFF || rs == NS_HHH)
15624 {
15625 if (is_add)
15626 do_vfp_nsyn_opcode ("fadds");
15627 else
15628 do_vfp_nsyn_opcode ("fsubs");
15629
15630 /* ARMv8.2 fp16 instruction. */
15631 if (rs == NS_HHH)
15632 do_scalar_fp16_v82_encode ();
15633 }
15634 else
15635 {
15636 if (is_add)
15637 do_vfp_nsyn_opcode ("faddd");
15638 else
15639 do_vfp_nsyn_opcode ("fsubd");
15640 }
15641 }
15642
15643 /* Check operand types to see if this is a VFP instruction, and if so call
15644 PFN (). */
15645
15646 static int
15647 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15648 {
15649 enum neon_shape rs;
15650 struct neon_type_el et;
15651
15652 switch (args)
15653 {
15654 case 2:
15655 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15656 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15657 break;
15658
15659 case 3:
15660 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15661 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15662 N_F_ALL | N_KEY | N_VFP);
15663 break;
15664
15665 default:
15666 abort ();
15667 }
15668
15669 if (et.type != NT_invtype)
15670 {
15671 pfn (rs);
15672 return SUCCESS;
15673 }
15674
15675 inst.error = NULL;
15676 return FAIL;
15677 }
15678
15679 static void
15680 do_vfp_nsyn_mla_mls (enum neon_shape rs)
15681 {
15682 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
15683
15684 if (rs == NS_FFF || rs == NS_HHH)
15685 {
15686 if (is_mla)
15687 do_vfp_nsyn_opcode ("fmacs");
15688 else
15689 do_vfp_nsyn_opcode ("fnmacs");
15690
15691 /* ARMv8.2 fp16 instruction. */
15692 if (rs == NS_HHH)
15693 do_scalar_fp16_v82_encode ();
15694 }
15695 else
15696 {
15697 if (is_mla)
15698 do_vfp_nsyn_opcode ("fmacd");
15699 else
15700 do_vfp_nsyn_opcode ("fnmacd");
15701 }
15702 }
15703
15704 static void
15705 do_vfp_nsyn_fma_fms (enum neon_shape rs)
15706 {
15707 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15708
15709 if (rs == NS_FFF || rs == NS_HHH)
15710 {
15711 if (is_fma)
15712 do_vfp_nsyn_opcode ("ffmas");
15713 else
15714 do_vfp_nsyn_opcode ("ffnmas");
15715
15716 /* ARMv8.2 fp16 instruction. */
15717 if (rs == NS_HHH)
15718 do_scalar_fp16_v82_encode ();
15719 }
15720 else
15721 {
15722 if (is_fma)
15723 do_vfp_nsyn_opcode ("ffmad");
15724 else
15725 do_vfp_nsyn_opcode ("ffnmad");
15726 }
15727 }
15728
15729 static void
15730 do_vfp_nsyn_mul (enum neon_shape rs)
15731 {
15732 if (rs == NS_FFF || rs == NS_HHH)
15733 {
15734 do_vfp_nsyn_opcode ("fmuls");
15735
15736 /* ARMv8.2 fp16 instruction. */
15737 if (rs == NS_HHH)
15738 do_scalar_fp16_v82_encode ();
15739 }
15740 else
15741 do_vfp_nsyn_opcode ("fmuld");
15742 }
15743
15744 static void
15745 do_vfp_nsyn_abs_neg (enum neon_shape rs)
15746 {
15747 int is_neg = (inst.instruction & 0x80) != 0;
15748 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
15749
15750 if (rs == NS_FF || rs == NS_HH)
15751 {
15752 if (is_neg)
15753 do_vfp_nsyn_opcode ("fnegs");
15754 else
15755 do_vfp_nsyn_opcode ("fabss");
15756
15757 /* ARMv8.2 fp16 instruction. */
15758 if (rs == NS_HH)
15759 do_scalar_fp16_v82_encode ();
15760 }
15761 else
15762 {
15763 if (is_neg)
15764 do_vfp_nsyn_opcode ("fnegd");
15765 else
15766 do_vfp_nsyn_opcode ("fabsd");
15767 }
15768 }
15769
15770 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15771 insns belong to Neon, and are handled elsewhere. */
15772
15773 static void
15774 do_vfp_nsyn_ldm_stm (int is_dbmode)
15775 {
15776 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15777 if (is_ldm)
15778 {
15779 if (is_dbmode)
15780 do_vfp_nsyn_opcode ("fldmdbs");
15781 else
15782 do_vfp_nsyn_opcode ("fldmias");
15783 }
15784 else
15785 {
15786 if (is_dbmode)
15787 do_vfp_nsyn_opcode ("fstmdbs");
15788 else
15789 do_vfp_nsyn_opcode ("fstmias");
15790 }
15791 }
15792
15793 static void
15794 do_vfp_nsyn_sqrt (void)
15795 {
15796 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15797 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15798
15799 if (rs == NS_FF || rs == NS_HH)
15800 {
15801 do_vfp_nsyn_opcode ("fsqrts");
15802
15803 /* ARMv8.2 fp16 instruction. */
15804 if (rs == NS_HH)
15805 do_scalar_fp16_v82_encode ();
15806 }
15807 else
15808 do_vfp_nsyn_opcode ("fsqrtd");
15809 }
15810
15811 static void
15812 do_vfp_nsyn_div (void)
15813 {
15814 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15815 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15816 N_F_ALL | N_KEY | N_VFP);
15817
15818 if (rs == NS_FFF || rs == NS_HHH)
15819 {
15820 do_vfp_nsyn_opcode ("fdivs");
15821
15822 /* ARMv8.2 fp16 instruction. */
15823 if (rs == NS_HHH)
15824 do_scalar_fp16_v82_encode ();
15825 }
15826 else
15827 do_vfp_nsyn_opcode ("fdivd");
15828 }
15829
15830 static void
15831 do_vfp_nsyn_nmul (void)
15832 {
15833 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15834 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15835 N_F_ALL | N_KEY | N_VFP);
15836
15837 if (rs == NS_FFF || rs == NS_HHH)
15838 {
15839 NEON_ENCODE (SINGLE, inst);
15840 do_vfp_sp_dyadic ();
15841
15842 /* ARMv8.2 fp16 instruction. */
15843 if (rs == NS_HHH)
15844 do_scalar_fp16_v82_encode ();
15845 }
15846 else
15847 {
15848 NEON_ENCODE (DOUBLE, inst);
15849 do_vfp_dp_rd_rn_rm ();
15850 }
15851 do_vfp_cond_or_thumb ();
15852
15853 }
15854
15855 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15856 (0, 1, 2, 3). */
15857
15858 static unsigned
15859 neon_logbits (unsigned x)
15860 {
15861 return ffs (x) - 4;
15862 }
15863
15864 #define LOW4(R) ((R) & 0xf)
15865 #define HI1(R) (((R) >> 4) & 1)
15866 #define LOW1(R) ((R) & 0x1)
15867 #define HI4(R) (((R) >> 1) & 0xf)
15868
15869 static unsigned
15870 mve_get_vcmp_vpt_cond (struct neon_type_el et)
15871 {
15872 switch (et.type)
15873 {
15874 default:
15875 first_error (BAD_EL_TYPE);
15876 return 0;
15877 case NT_float:
15878 switch (inst.operands[0].imm)
15879 {
15880 default:
15881 first_error (_("invalid condition"));
15882 return 0;
15883 case 0x0:
15884 /* eq. */
15885 return 0;
15886 case 0x1:
15887 /* ne. */
15888 return 1;
15889 case 0xa:
15890 /* ge/ */
15891 return 4;
15892 case 0xb:
15893 /* lt. */
15894 return 5;
15895 case 0xc:
15896 /* gt. */
15897 return 6;
15898 case 0xd:
15899 /* le. */
15900 return 7;
15901 }
15902 case NT_integer:
15903 /* only accept eq and ne. */
15904 if (inst.operands[0].imm > 1)
15905 {
15906 first_error (_("invalid condition"));
15907 return 0;
15908 }
15909 return inst.operands[0].imm;
15910 case NT_unsigned:
15911 if (inst.operands[0].imm == 0x2)
15912 return 2;
15913 else if (inst.operands[0].imm == 0x8)
15914 return 3;
15915 else
15916 {
15917 first_error (_("invalid condition"));
15918 return 0;
15919 }
15920 case NT_signed:
15921 switch (inst.operands[0].imm)
15922 {
15923 default:
15924 first_error (_("invalid condition"));
15925 return 0;
15926 case 0xa:
15927 /* ge. */
15928 return 4;
15929 case 0xb:
15930 /* lt. */
15931 return 5;
15932 case 0xc:
15933 /* gt. */
15934 return 6;
15935 case 0xd:
15936 /* le. */
15937 return 7;
15938 }
15939 }
15940 /* Should be unreachable. */
15941 abort ();
15942 }
15943
15944 /* For VCTP (create vector tail predicate) in MVE. */
15945 static void
15946 do_mve_vctp (void)
15947 {
15948 int dt = 0;
15949 unsigned size = 0x0;
15950
15951 if (inst.cond > COND_ALWAYS)
15952 inst.pred_insn_type = INSIDE_VPT_INSN;
15953 else
15954 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15955
15956 /* This is a typical MVE instruction which has no type but have size 8, 16,
15957 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15958 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15959 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15960 dt = inst.vectype.el[0].size;
15961
15962 /* Setting this does not indicate an actual NEON instruction, but only
15963 indicates that the mnemonic accepts neon-style type suffixes. */
15964 inst.is_neon = 1;
15965
15966 switch (dt)
15967 {
15968 case 8:
15969 break;
15970 case 16:
15971 size = 0x1; break;
15972 case 32:
15973 size = 0x2; break;
15974 case 64:
15975 size = 0x3; break;
15976 default:
15977 first_error (_("Type is not allowed for this instruction"));
15978 }
15979 inst.instruction |= size << 20;
15980 inst.instruction |= inst.operands[0].reg << 16;
15981 }
15982
15983 static void
15984 do_mve_vpt (void)
15985 {
15986 /* We are dealing with a vector predicated block. */
15987 if (inst.operands[0].present)
15988 {
15989 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15990 struct neon_type_el et
15991 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15992 N_EQK);
15993
15994 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15995
15996 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15997
15998 if (et.type == NT_invtype)
15999 return;
16000
16001 if (et.type == NT_float)
16002 {
16003 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16004 BAD_FPU);
16005 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
16006 inst.instruction |= (et.size == 16) << 28;
16007 inst.instruction |= 0x3 << 20;
16008 }
16009 else
16010 {
16011 constraint (et.size != 8 && et.size != 16 && et.size != 32,
16012 BAD_EL_TYPE);
16013 inst.instruction |= 1 << 28;
16014 inst.instruction |= neon_logbits (et.size) << 20;
16015 }
16016
16017 if (inst.operands[2].isquad)
16018 {
16019 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16020 inst.instruction |= LOW4 (inst.operands[2].reg);
16021 inst.instruction |= (fcond & 0x2) >> 1;
16022 }
16023 else
16024 {
16025 if (inst.operands[2].reg == REG_SP)
16026 as_tsktsk (MVE_BAD_SP);
16027 inst.instruction |= 1 << 6;
16028 inst.instruction |= (fcond & 0x2) << 4;
16029 inst.instruction |= inst.operands[2].reg;
16030 }
16031 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16032 inst.instruction |= (fcond & 0x4) << 10;
16033 inst.instruction |= (fcond & 0x1) << 7;
16034
16035 }
16036 set_pred_insn_type (VPT_INSN);
16037 now_pred.cc = 0;
16038 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
16039 | ((inst.instruction & 0xe000) >> 13);
16040 now_pred.warn_deprecated = false;
16041 now_pred.type = VECTOR_PRED;
16042 inst.is_neon = 1;
16043 }
16044
16045 static void
16046 do_mve_vcmp (void)
16047 {
16048 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
16049 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
16050 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
16051 if (!inst.operands[2].present)
16052 first_error (_("MVE vector or ARM register expected"));
16053 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
16054
16055 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
16056 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
16057 && inst.operands[1].isquad)
16058 {
16059 inst.instruction = N_MNEM_vcmp;
16060 inst.cond = 0x10;
16061 }
16062
16063 if (inst.cond > COND_ALWAYS)
16064 inst.pred_insn_type = INSIDE_VPT_INSN;
16065 else
16066 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16067
16068 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
16069 struct neon_type_el et
16070 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
16071 N_EQK);
16072
16073 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
16074 && !inst.operands[2].iszr, BAD_PC);
16075
16076 unsigned fcond = mve_get_vcmp_vpt_cond (et);
16077
16078 inst.instruction = 0xee010f00;
16079 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16080 inst.instruction |= (fcond & 0x4) << 10;
16081 inst.instruction |= (fcond & 0x1) << 7;
16082 if (et.type == NT_float)
16083 {
16084 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
16085 BAD_FPU);
16086 inst.instruction |= (et.size == 16) << 28;
16087 inst.instruction |= 0x3 << 20;
16088 }
16089 else
16090 {
16091 inst.instruction |= 1 << 28;
16092 inst.instruction |= neon_logbits (et.size) << 20;
16093 }
16094 if (inst.operands[2].isquad)
16095 {
16096 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16097 inst.instruction |= (fcond & 0x2) >> 1;
16098 inst.instruction |= LOW4 (inst.operands[2].reg);
16099 }
16100 else
16101 {
16102 if (inst.operands[2].reg == REG_SP)
16103 as_tsktsk (MVE_BAD_SP);
16104 inst.instruction |= 1 << 6;
16105 inst.instruction |= (fcond & 0x2) << 4;
16106 inst.instruction |= inst.operands[2].reg;
16107 }
16108
16109 inst.is_neon = 1;
16110 return;
16111 }
16112
16113 static void
16114 do_mve_vmaxa_vmina (void)
16115 {
16116 if (inst.cond > COND_ALWAYS)
16117 inst.pred_insn_type = INSIDE_VPT_INSN;
16118 else
16119 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16120
16121 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16122 struct neon_type_el et
16123 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
16124
16125 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16126 inst.instruction |= neon_logbits (et.size) << 18;
16127 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16128 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16129 inst.instruction |= LOW4 (inst.operands[1].reg);
16130 inst.is_neon = 1;
16131 }
16132
16133 static void
16134 do_mve_vfmas (void)
16135 {
16136 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16137 struct neon_type_el et
16138 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
16139
16140 if (inst.cond > COND_ALWAYS)
16141 inst.pred_insn_type = INSIDE_VPT_INSN;
16142 else
16143 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16144
16145 if (inst.operands[2].reg == REG_SP)
16146 as_tsktsk (MVE_BAD_SP);
16147 else if (inst.operands[2].reg == REG_PC)
16148 as_tsktsk (MVE_BAD_PC);
16149
16150 inst.instruction |= (et.size == 16) << 28;
16151 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16152 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16153 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16154 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16155 inst.instruction |= inst.operands[2].reg;
16156 inst.is_neon = 1;
16157 }
16158
16159 static void
16160 do_mve_viddup (void)
16161 {
16162 if (inst.cond > COND_ALWAYS)
16163 inst.pred_insn_type = INSIDE_VPT_INSN;
16164 else
16165 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16166
16167 unsigned imm = inst.relocs[0].exp.X_add_number;
16168 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16169 _("immediate must be either 1, 2, 4 or 8"));
16170
16171 enum neon_shape rs;
16172 struct neon_type_el et;
16173 unsigned Rm;
16174 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16175 {
16176 rs = neon_select_shape (NS_QRI, NS_NULL);
16177 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16178 Rm = 7;
16179 }
16180 else
16181 {
16182 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16183 if (inst.operands[2].reg == REG_SP)
16184 as_tsktsk (MVE_BAD_SP);
16185 else if (inst.operands[2].reg == REG_PC)
16186 first_error (BAD_PC);
16187
16188 rs = neon_select_shape (NS_QRRI, NS_NULL);
16189 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16190 Rm = inst.operands[2].reg >> 1;
16191 }
16192 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16193 inst.instruction |= neon_logbits (et.size) << 20;
16194 inst.instruction |= inst.operands[1].reg << 16;
16195 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16196 inst.instruction |= (imm > 2) << 7;
16197 inst.instruction |= Rm << 1;
16198 inst.instruction |= (imm == 2 || imm == 8);
16199 inst.is_neon = 1;
16200 }
16201
16202 static void
16203 do_mve_vmlas (void)
16204 {
16205 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16206 struct neon_type_el et
16207 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16208
16209 if (inst.operands[2].reg == REG_PC)
16210 as_tsktsk (MVE_BAD_PC);
16211 else if (inst.operands[2].reg == REG_SP)
16212 as_tsktsk (MVE_BAD_SP);
16213
16214 if (inst.cond > COND_ALWAYS)
16215 inst.pred_insn_type = INSIDE_VPT_INSN;
16216 else
16217 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16218
16219 inst.instruction |= (et.type == NT_unsigned) << 28;
16220 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16221 inst.instruction |= neon_logbits (et.size) << 20;
16222 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16223 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16224 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16225 inst.instruction |= inst.operands[2].reg;
16226 inst.is_neon = 1;
16227 }
16228
16229 static void
16230 do_mve_vshll (void)
16231 {
16232 struct neon_type_el et
16233 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16234
16235 if (inst.cond > COND_ALWAYS)
16236 inst.pred_insn_type = INSIDE_VPT_INSN;
16237 else
16238 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16239
16240 int imm = inst.operands[2].imm;
16241 constraint (imm < 1 || (unsigned)imm > et.size,
16242 _("immediate value out of range"));
16243
16244 if ((unsigned)imm == et.size)
16245 {
16246 inst.instruction |= neon_logbits (et.size) << 18;
16247 inst.instruction |= 0x110001;
16248 }
16249 else
16250 {
16251 inst.instruction |= (et.size + imm) << 16;
16252 inst.instruction |= 0x800140;
16253 }
16254
16255 inst.instruction |= (et.type == NT_unsigned) << 28;
16256 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16257 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16258 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16259 inst.instruction |= LOW4 (inst.operands[1].reg);
16260 inst.is_neon = 1;
16261 }
16262
16263 static void
16264 do_mve_vshlc (void)
16265 {
16266 if (inst.cond > COND_ALWAYS)
16267 inst.pred_insn_type = INSIDE_VPT_INSN;
16268 else
16269 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16270
16271 if (inst.operands[1].reg == REG_PC)
16272 as_tsktsk (MVE_BAD_PC);
16273 else if (inst.operands[1].reg == REG_SP)
16274 as_tsktsk (MVE_BAD_SP);
16275
16276 int imm = inst.operands[2].imm;
16277 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16278
16279 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16280 inst.instruction |= (imm & 0x1f) << 16;
16281 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16282 inst.instruction |= inst.operands[1].reg;
16283 inst.is_neon = 1;
16284 }
16285
16286 static void
16287 do_mve_vshrn (void)
16288 {
16289 unsigned types;
16290 switch (inst.instruction)
16291 {
16292 case M_MNEM_vshrnt:
16293 case M_MNEM_vshrnb:
16294 case M_MNEM_vrshrnt:
16295 case M_MNEM_vrshrnb:
16296 types = N_I16 | N_I32;
16297 break;
16298 case M_MNEM_vqshrnt:
16299 case M_MNEM_vqshrnb:
16300 case M_MNEM_vqrshrnt:
16301 case M_MNEM_vqrshrnb:
16302 types = N_U16 | N_U32 | N_S16 | N_S32;
16303 break;
16304 case M_MNEM_vqshrunt:
16305 case M_MNEM_vqshrunb:
16306 case M_MNEM_vqrshrunt:
16307 case M_MNEM_vqrshrunb:
16308 types = N_S16 | N_S32;
16309 break;
16310 default:
16311 abort ();
16312 }
16313
16314 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16315
16316 if (inst.cond > COND_ALWAYS)
16317 inst.pred_insn_type = INSIDE_VPT_INSN;
16318 else
16319 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16320
16321 unsigned Qd = inst.operands[0].reg;
16322 unsigned Qm = inst.operands[1].reg;
16323 unsigned imm = inst.operands[2].imm;
16324 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16325 et.size == 16
16326 ? _("immediate operand expected in the range [1,8]")
16327 : _("immediate operand expected in the range [1,16]"));
16328
16329 inst.instruction |= (et.type == NT_unsigned) << 28;
16330 inst.instruction |= HI1 (Qd) << 22;
16331 inst.instruction |= (et.size - imm) << 16;
16332 inst.instruction |= LOW4 (Qd) << 12;
16333 inst.instruction |= HI1 (Qm) << 5;
16334 inst.instruction |= LOW4 (Qm);
16335 inst.is_neon = 1;
16336 }
16337
16338 static void
16339 do_mve_vqmovn (void)
16340 {
16341 struct neon_type_el et;
16342 if (inst.instruction == M_MNEM_vqmovnt
16343 || inst.instruction == M_MNEM_vqmovnb)
16344 et = neon_check_type (2, NS_QQ, N_EQK,
16345 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16346 else
16347 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16348
16349 if (inst.cond > COND_ALWAYS)
16350 inst.pred_insn_type = INSIDE_VPT_INSN;
16351 else
16352 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16353
16354 inst.instruction |= (et.type == NT_unsigned) << 28;
16355 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16356 inst.instruction |= (et.size == 32) << 18;
16357 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16358 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16359 inst.instruction |= LOW4 (inst.operands[1].reg);
16360 inst.is_neon = 1;
16361 }
16362
16363 static void
16364 do_mve_vpsel (void)
16365 {
16366 neon_select_shape (NS_QQQ, NS_NULL);
16367
16368 if (inst.cond > COND_ALWAYS)
16369 inst.pred_insn_type = INSIDE_VPT_INSN;
16370 else
16371 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16372
16373 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16374 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16375 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16376 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16377 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16378 inst.instruction |= LOW4 (inst.operands[2].reg);
16379 inst.is_neon = 1;
16380 }
16381
16382 static void
16383 do_mve_vpnot (void)
16384 {
16385 if (inst.cond > COND_ALWAYS)
16386 inst.pred_insn_type = INSIDE_VPT_INSN;
16387 else
16388 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16389 }
16390
16391 static void
16392 do_mve_vmaxnma_vminnma (void)
16393 {
16394 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16395 struct neon_type_el et
16396 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
16397
16398 if (inst.cond > COND_ALWAYS)
16399 inst.pred_insn_type = INSIDE_VPT_INSN;
16400 else
16401 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16402
16403 inst.instruction |= (et.size == 16) << 28;
16404 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16405 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16406 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16407 inst.instruction |= LOW4 (inst.operands[1].reg);
16408 inst.is_neon = 1;
16409 }
16410
16411 static void
16412 do_mve_vcmul (void)
16413 {
16414 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16415 struct neon_type_el et
16416 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16417
16418 if (inst.cond > COND_ALWAYS)
16419 inst.pred_insn_type = INSIDE_VPT_INSN;
16420 else
16421 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16422
16423 unsigned rot = inst.relocs[0].exp.X_add_number;
16424 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16425 _("immediate out of range"));
16426
16427 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16428 || inst.operands[0].reg == inst.operands[2].reg))
16429 as_tsktsk (BAD_MVE_SRCDEST);
16430
16431 inst.instruction |= (et.size == 32) << 28;
16432 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16433 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16434 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16435 inst.instruction |= (rot > 90) << 12;
16436 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16437 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16438 inst.instruction |= LOW4 (inst.operands[2].reg);
16439 inst.instruction |= (rot == 90 || rot == 270);
16440 inst.is_neon = 1;
16441 }
16442
16443 /* To handle the Low Overhead Loop instructions
16444 in Armv8.1-M Mainline and MVE. */
16445 static void
16446 do_t_loloop (void)
16447 {
16448 unsigned long insn = inst.instruction;
16449
16450 inst.instruction = THUMB_OP32 (inst.instruction);
16451
16452 if (insn == T_MNEM_lctp)
16453 return;
16454
16455 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16456
16457 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16458 {
16459 struct neon_type_el et
16460 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16461 inst.instruction |= neon_logbits (et.size) << 20;
16462 inst.is_neon = 1;
16463 }
16464
16465 switch (insn)
16466 {
16467 case T_MNEM_letp:
16468 constraint (!inst.operands[0].present,
16469 _("expected LR"));
16470 /* fall through. */
16471 case T_MNEM_le:
16472 /* le <label>. */
16473 if (!inst.operands[0].present)
16474 inst.instruction |= 1 << 21;
16475
16476 v8_1_loop_reloc (true);
16477 break;
16478
16479 case T_MNEM_wls:
16480 case T_MNEM_wlstp:
16481 v8_1_loop_reloc (false);
16482 /* fall through. */
16483 case T_MNEM_dlstp:
16484 case T_MNEM_dls:
16485 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16486
16487 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16488 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16489 else if (inst.operands[1].reg == REG_PC)
16490 as_tsktsk (MVE_BAD_PC);
16491 if (inst.operands[1].reg == REG_SP)
16492 as_tsktsk (MVE_BAD_SP);
16493
16494 inst.instruction |= (inst.operands[1].reg << 16);
16495 break;
16496
16497 default:
16498 abort ();
16499 }
16500 }
16501
16502
16503 static void
16504 do_vfp_nsyn_cmp (void)
16505 {
16506 enum neon_shape rs;
16507 if (!inst.operands[0].isreg)
16508 {
16509 do_mve_vcmp ();
16510 return;
16511 }
16512 else
16513 {
16514 constraint (inst.operands[2].present, BAD_SYNTAX);
16515 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16516 BAD_FPU);
16517 }
16518
16519 if (inst.operands[1].isreg)
16520 {
16521 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16522 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
16523
16524 if (rs == NS_FF || rs == NS_HH)
16525 {
16526 NEON_ENCODE (SINGLE, inst);
16527 do_vfp_sp_monadic ();
16528 }
16529 else
16530 {
16531 NEON_ENCODE (DOUBLE, inst);
16532 do_vfp_dp_rd_rm ();
16533 }
16534 }
16535 else
16536 {
16537 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16538 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
16539
16540 switch (inst.instruction & 0x0fffffff)
16541 {
16542 case N_MNEM_vcmp:
16543 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16544 break;
16545 case N_MNEM_vcmpe:
16546 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16547 break;
16548 default:
16549 abort ();
16550 }
16551
16552 if (rs == NS_FI || rs == NS_HI)
16553 {
16554 NEON_ENCODE (SINGLE, inst);
16555 do_vfp_sp_compare_z ();
16556 }
16557 else
16558 {
16559 NEON_ENCODE (DOUBLE, inst);
16560 do_vfp_dp_rd ();
16561 }
16562 }
16563 do_vfp_cond_or_thumb ();
16564
16565 /* ARMv8.2 fp16 instruction. */
16566 if (rs == NS_HI || rs == NS_HH)
16567 do_scalar_fp16_v82_encode ();
16568 }
16569
16570 static void
16571 nsyn_insert_sp (void)
16572 {
16573 inst.operands[1] = inst.operands[0];
16574 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
16575 inst.operands[0].reg = REG_SP;
16576 inst.operands[0].isreg = 1;
16577 inst.operands[0].writeback = 1;
16578 inst.operands[0].present = 1;
16579 }
16580
16581 /* Fix up Neon data-processing instructions, ORing in the correct bits for
16582 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16583
16584 static void
16585 neon_dp_fixup (struct arm_it* insn)
16586 {
16587 unsigned int i = insn->instruction;
16588 insn->is_neon = 1;
16589
16590 if (thumb_mode)
16591 {
16592 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16593 if (i & (1 << 24))
16594 i |= 1 << 28;
16595
16596 i &= ~(1 << 24);
16597
16598 i |= 0xef000000;
16599 }
16600 else
16601 i |= 0xf2000000;
16602
16603 insn->instruction = i;
16604 }
16605
16606 static void
16607 mve_encode_qqr (int size, int U, int fp)
16608 {
16609 if (inst.operands[2].reg == REG_SP)
16610 as_tsktsk (MVE_BAD_SP);
16611 else if (inst.operands[2].reg == REG_PC)
16612 as_tsktsk (MVE_BAD_PC);
16613
16614 if (fp)
16615 {
16616 /* vadd. */
16617 if (((unsigned)inst.instruction) == 0xd00)
16618 inst.instruction = 0xee300f40;
16619 /* vsub. */
16620 else if (((unsigned)inst.instruction) == 0x200d00)
16621 inst.instruction = 0xee301f40;
16622 /* vmul. */
16623 else if (((unsigned)inst.instruction) == 0x1000d10)
16624 inst.instruction = 0xee310e60;
16625
16626 /* Setting size which is 1 for F16 and 0 for F32. */
16627 inst.instruction |= (size == 16) << 28;
16628 }
16629 else
16630 {
16631 /* vadd. */
16632 if (((unsigned)inst.instruction) == 0x800)
16633 inst.instruction = 0xee010f40;
16634 /* vsub. */
16635 else if (((unsigned)inst.instruction) == 0x1000800)
16636 inst.instruction = 0xee011f40;
16637 /* vhadd. */
16638 else if (((unsigned)inst.instruction) == 0)
16639 inst.instruction = 0xee000f40;
16640 /* vhsub. */
16641 else if (((unsigned)inst.instruction) == 0x200)
16642 inst.instruction = 0xee001f40;
16643 /* vmla. */
16644 else if (((unsigned)inst.instruction) == 0x900)
16645 inst.instruction = 0xee010e40;
16646 /* vmul. */
16647 else if (((unsigned)inst.instruction) == 0x910)
16648 inst.instruction = 0xee011e60;
16649 /* vqadd. */
16650 else if (((unsigned)inst.instruction) == 0x10)
16651 inst.instruction = 0xee000f60;
16652 /* vqsub. */
16653 else if (((unsigned)inst.instruction) == 0x210)
16654 inst.instruction = 0xee001f60;
16655 /* vqrdmlah. */
16656 else if (((unsigned)inst.instruction) == 0x3000b10)
16657 inst.instruction = 0xee000e40;
16658 /* vqdmulh. */
16659 else if (((unsigned)inst.instruction) == 0x0000b00)
16660 inst.instruction = 0xee010e60;
16661 /* vqrdmulh. */
16662 else if (((unsigned)inst.instruction) == 0x1000b00)
16663 inst.instruction = 0xfe010e60;
16664
16665 /* Set U-bit. */
16666 inst.instruction |= U << 28;
16667
16668 /* Setting bits for size. */
16669 inst.instruction |= neon_logbits (size) << 20;
16670 }
16671 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16672 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16673 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16674 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16675 inst.instruction |= inst.operands[2].reg;
16676 inst.is_neon = 1;
16677 }
16678
16679 static void
16680 mve_encode_rqq (unsigned bit28, unsigned size)
16681 {
16682 inst.instruction |= bit28 << 28;
16683 inst.instruction |= neon_logbits (size) << 20;
16684 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16685 inst.instruction |= inst.operands[0].reg << 12;
16686 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16687 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16688 inst.instruction |= LOW4 (inst.operands[2].reg);
16689 inst.is_neon = 1;
16690 }
16691
16692 static void
16693 mve_encode_qqq (int ubit, int size)
16694 {
16695
16696 inst.instruction |= (ubit != 0) << 28;
16697 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16698 inst.instruction |= neon_logbits (size) << 20;
16699 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16700 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16701 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16702 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16703 inst.instruction |= LOW4 (inst.operands[2].reg);
16704
16705 inst.is_neon = 1;
16706 }
16707
16708 static void
16709 mve_encode_rq (unsigned bit28, unsigned size)
16710 {
16711 inst.instruction |= bit28 << 28;
16712 inst.instruction |= neon_logbits (size) << 18;
16713 inst.instruction |= inst.operands[0].reg << 12;
16714 inst.instruction |= LOW4 (inst.operands[1].reg);
16715 inst.is_neon = 1;
16716 }
16717
16718 static void
16719 mve_encode_rrqq (unsigned U, unsigned size)
16720 {
16721 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16722
16723 inst.instruction |= U << 28;
16724 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16725 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16726 inst.instruction |= (size == 32) << 16;
16727 inst.instruction |= inst.operands[0].reg << 12;
16728 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16729 inst.instruction |= inst.operands[3].reg;
16730 inst.is_neon = 1;
16731 }
16732
16733 /* Helper function for neon_three_same handling the operands. */
16734 static void
16735 neon_three_args (int isquad)
16736 {
16737 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16738 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16739 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16740 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16741 inst.instruction |= LOW4 (inst.operands[2].reg);
16742 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16743 inst.instruction |= (isquad != 0) << 6;
16744 inst.is_neon = 1;
16745 }
16746
16747 /* Encode insns with bit pattern:
16748
16749 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16750 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
16751
16752 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16753 different meaning for some instruction. */
16754
16755 static void
16756 neon_three_same (int isquad, int ubit, int size)
16757 {
16758 neon_three_args (isquad);
16759 inst.instruction |= (ubit != 0) << 24;
16760 if (size != -1)
16761 inst.instruction |= neon_logbits (size) << 20;
16762
16763 neon_dp_fixup (&inst);
16764 }
16765
16766 /* Encode instructions of the form:
16767
16768 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16769 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
16770
16771 Don't write size if SIZE == -1. */
16772
16773 static void
16774 neon_two_same (int qbit, int ubit, int size)
16775 {
16776 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16777 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16778 inst.instruction |= LOW4 (inst.operands[1].reg);
16779 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16780 inst.instruction |= (qbit != 0) << 6;
16781 inst.instruction |= (ubit != 0) << 24;
16782
16783 if (size != -1)
16784 inst.instruction |= neon_logbits (size) << 18;
16785
16786 neon_dp_fixup (&inst);
16787 }
16788
16789 enum vfp_or_neon_is_neon_bits
16790 {
16791 NEON_CHECK_CC = 1,
16792 NEON_CHECK_ARCH = 2,
16793 NEON_CHECK_ARCH8 = 4
16794 };
16795
16796 /* Call this function if an instruction which may have belonged to the VFP or
16797 Neon instruction sets, but turned out to be a Neon instruction (due to the
16798 operand types involved, etc.). We have to check and/or fix-up a couple of
16799 things:
16800
16801 - Make sure the user hasn't attempted to make a Neon instruction
16802 conditional.
16803 - Alter the value in the condition code field if necessary.
16804 - Make sure that the arch supports Neon instructions.
16805
16806 Which of these operations take place depends on bits from enum
16807 vfp_or_neon_is_neon_bits.
16808
16809 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16810 current instruction's condition is COND_ALWAYS, the condition field is
16811 changed to inst.uncond_value. This is necessary because instructions shared
16812 between VFP and Neon may be conditional for the VFP variants only, and the
16813 unconditional Neon version must have, e.g., 0xF in the condition field. */
16814
16815 static int
16816 vfp_or_neon_is_neon (unsigned check)
16817 {
16818 /* Conditions are always legal in Thumb mode (IT blocks). */
16819 if (!thumb_mode && (check & NEON_CHECK_CC))
16820 {
16821 if (inst.cond != COND_ALWAYS)
16822 {
16823 first_error (_(BAD_COND));
16824 return FAIL;
16825 }
16826 if (inst.uncond_value != -1u)
16827 inst.instruction |= inst.uncond_value << 28;
16828 }
16829
16830
16831 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16832 || ((check & NEON_CHECK_ARCH8)
16833 && !mark_feature_used (&fpu_neon_ext_armv8)))
16834 {
16835 first_error (_(BAD_FPU));
16836 return FAIL;
16837 }
16838
16839 return SUCCESS;
16840 }
16841
16842
16843 /* Return TRUE if the SIMD instruction is available for the current
16844 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16845 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16846 vfp_or_neon_is_neon for the NEON specific checks. */
16847
16848 static bool
16849 check_simd_pred_availability (int fp, unsigned check)
16850 {
16851 if (inst.cond > COND_ALWAYS)
16852 {
16853 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16854 {
16855 inst.error = BAD_FPU;
16856 return false;
16857 }
16858 inst.pred_insn_type = INSIDE_VPT_INSN;
16859 }
16860 else if (inst.cond < COND_ALWAYS)
16861 {
16862 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16863 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16864 else if (vfp_or_neon_is_neon (check) == FAIL)
16865 return false;
16866 }
16867 else
16868 {
16869 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16870 && vfp_or_neon_is_neon (check) == FAIL)
16871 return false;
16872
16873 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16874 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16875 }
16876 return true;
16877 }
16878
16879 /* Neon instruction encoders, in approximate order of appearance. */
16880
16881 static void
16882 do_neon_dyadic_i_su (void)
16883 {
16884 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
16885 return;
16886
16887 enum neon_shape rs;
16888 struct neon_type_el et;
16889 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16890 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16891 else
16892 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16893
16894 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16895
16896
16897 if (rs != NS_QQR)
16898 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16899 else
16900 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16901 }
16902
16903 static void
16904 do_neon_dyadic_i64_su (void)
16905 {
16906 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
16907 return;
16908 enum neon_shape rs;
16909 struct neon_type_el et;
16910 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16911 {
16912 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16913 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16914 }
16915 else
16916 {
16917 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16918 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16919 }
16920 if (rs == NS_QQR)
16921 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16922 else
16923 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16924 }
16925
16926 static void
16927 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
16928 unsigned immbits)
16929 {
16930 unsigned size = et.size >> 3;
16931 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16932 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16933 inst.instruction |= LOW4 (inst.operands[1].reg);
16934 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16935 inst.instruction |= (isquad != 0) << 6;
16936 inst.instruction |= immbits << 16;
16937 inst.instruction |= (size >> 3) << 7;
16938 inst.instruction |= (size & 0x7) << 19;
16939 if (write_ubit)
16940 inst.instruction |= (uval != 0) << 24;
16941
16942 neon_dp_fixup (&inst);
16943 }
16944
16945 static void
16946 do_neon_shl (void)
16947 {
16948 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
16949 return;
16950
16951 if (!inst.operands[2].isreg)
16952 {
16953 enum neon_shape rs;
16954 struct neon_type_el et;
16955 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16956 {
16957 rs = neon_select_shape (NS_QQI, NS_NULL);
16958 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16959 }
16960 else
16961 {
16962 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16963 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16964 }
16965 int imm = inst.operands[2].imm;
16966
16967 constraint (imm < 0 || (unsigned)imm >= et.size,
16968 _("immediate out of range for shift"));
16969 NEON_ENCODE (IMMED, inst);
16970 neon_imm_shift (false, 0, neon_quad (rs), et, imm);
16971 }
16972 else
16973 {
16974 enum neon_shape rs;
16975 struct neon_type_el et;
16976 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16977 {
16978 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16979 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16980 }
16981 else
16982 {
16983 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16984 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16985 }
16986
16987
16988 if (rs == NS_QQR)
16989 {
16990 constraint (inst.operands[0].reg != inst.operands[1].reg,
16991 _("invalid instruction shape"));
16992 if (inst.operands[2].reg == REG_SP)
16993 as_tsktsk (MVE_BAD_SP);
16994 else if (inst.operands[2].reg == REG_PC)
16995 as_tsktsk (MVE_BAD_PC);
16996
16997 inst.instruction = 0xee311e60;
16998 inst.instruction |= (et.type == NT_unsigned) << 28;
16999 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17000 inst.instruction |= neon_logbits (et.size) << 18;
17001 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17002 inst.instruction |= inst.operands[2].reg;
17003 inst.is_neon = 1;
17004 }
17005 else
17006 {
17007 unsigned int tmp;
17008
17009 /* VSHL/VQSHL 3-register variants have syntax such as:
17010 vshl.xx Dd, Dm, Dn
17011 whereas other 3-register operations encoded by neon_three_same have
17012 syntax like:
17013 vadd.xx Dd, Dn, Dm
17014 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
17015 operands[2].reg here. */
17016 tmp = inst.operands[2].reg;
17017 inst.operands[2].reg = inst.operands[1].reg;
17018 inst.operands[1].reg = tmp;
17019 NEON_ENCODE (INTEGER, inst);
17020 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17021 }
17022 }
17023 }
17024
17025 static void
17026 do_neon_qshl (void)
17027 {
17028 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
17029 return;
17030
17031 if (!inst.operands[2].isreg)
17032 {
17033 enum neon_shape rs;
17034 struct neon_type_el et;
17035 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17036 {
17037 rs = neon_select_shape (NS_QQI, NS_NULL);
17038 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
17039 }
17040 else
17041 {
17042 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17043 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
17044 }
17045 int imm = inst.operands[2].imm;
17046
17047 constraint (imm < 0 || (unsigned)imm >= et.size,
17048 _("immediate out of range for shift"));
17049 NEON_ENCODE (IMMED, inst);
17050 neon_imm_shift (true, et.type == NT_unsigned, neon_quad (rs), et, imm);
17051 }
17052 else
17053 {
17054 enum neon_shape rs;
17055 struct neon_type_el et;
17056
17057 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17058 {
17059 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17060 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
17061 }
17062 else
17063 {
17064 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17065 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
17066 }
17067
17068 if (rs == NS_QQR)
17069 {
17070 constraint (inst.operands[0].reg != inst.operands[1].reg,
17071 _("invalid instruction shape"));
17072 if (inst.operands[2].reg == REG_SP)
17073 as_tsktsk (MVE_BAD_SP);
17074 else if (inst.operands[2].reg == REG_PC)
17075 as_tsktsk (MVE_BAD_PC);
17076
17077 inst.instruction = 0xee311ee0;
17078 inst.instruction |= (et.type == NT_unsigned) << 28;
17079 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17080 inst.instruction |= neon_logbits (et.size) << 18;
17081 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17082 inst.instruction |= inst.operands[2].reg;
17083 inst.is_neon = 1;
17084 }
17085 else
17086 {
17087 unsigned int tmp;
17088
17089 /* See note in do_neon_shl. */
17090 tmp = inst.operands[2].reg;
17091 inst.operands[2].reg = inst.operands[1].reg;
17092 inst.operands[1].reg = tmp;
17093 NEON_ENCODE (INTEGER, inst);
17094 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17095 }
17096 }
17097 }
17098
17099 static void
17100 do_neon_rshl (void)
17101 {
17102 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
17103 return;
17104
17105 enum neon_shape rs;
17106 struct neon_type_el et;
17107 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17108 {
17109 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17110 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17111 }
17112 else
17113 {
17114 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17115 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
17116 }
17117
17118 unsigned int tmp;
17119
17120 if (rs == NS_QQR)
17121 {
17122 if (inst.operands[2].reg == REG_PC)
17123 as_tsktsk (MVE_BAD_PC);
17124 else if (inst.operands[2].reg == REG_SP)
17125 as_tsktsk (MVE_BAD_SP);
17126
17127 constraint (inst.operands[0].reg != inst.operands[1].reg,
17128 _("invalid instruction shape"));
17129
17130 if (inst.instruction == 0x0000510)
17131 /* We are dealing with vqrshl. */
17132 inst.instruction = 0xee331ee0;
17133 else
17134 /* We are dealing with vrshl. */
17135 inst.instruction = 0xee331e60;
17136
17137 inst.instruction |= (et.type == NT_unsigned) << 28;
17138 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17139 inst.instruction |= neon_logbits (et.size) << 18;
17140 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17141 inst.instruction |= inst.operands[2].reg;
17142 inst.is_neon = 1;
17143 }
17144 else
17145 {
17146 tmp = inst.operands[2].reg;
17147 inst.operands[2].reg = inst.operands[1].reg;
17148 inst.operands[1].reg = tmp;
17149 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17150 }
17151 }
17152
17153 static int
17154 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17155 {
17156 /* Handle .I8 pseudo-instructions. */
17157 if (size == 8)
17158 {
17159 /* Unfortunately, this will make everything apart from zero out-of-range.
17160 FIXME is this the intended semantics? There doesn't seem much point in
17161 accepting .I8 if so. */
17162 immediate |= immediate << 8;
17163 size = 16;
17164 }
17165
17166 if (size >= 32)
17167 {
17168 if (immediate == (immediate & 0x000000ff))
17169 {
17170 *immbits = immediate;
17171 return 0x1;
17172 }
17173 else if (immediate == (immediate & 0x0000ff00))
17174 {
17175 *immbits = immediate >> 8;
17176 return 0x3;
17177 }
17178 else if (immediate == (immediate & 0x00ff0000))
17179 {
17180 *immbits = immediate >> 16;
17181 return 0x5;
17182 }
17183 else if (immediate == (immediate & 0xff000000))
17184 {
17185 *immbits = immediate >> 24;
17186 return 0x7;
17187 }
17188 if ((immediate & 0xffff) != (immediate >> 16))
17189 goto bad_immediate;
17190 immediate &= 0xffff;
17191 }
17192
17193 if (immediate == (immediate & 0x000000ff))
17194 {
17195 *immbits = immediate;
17196 return 0x9;
17197 }
17198 else if (immediate == (immediate & 0x0000ff00))
17199 {
17200 *immbits = immediate >> 8;
17201 return 0xb;
17202 }
17203
17204 bad_immediate:
17205 first_error (_("immediate value out of range"));
17206 return FAIL;
17207 }
17208
17209 static void
17210 do_neon_logic (void)
17211 {
17212 if (inst.operands[2].present && inst.operands[2].isreg)
17213 {
17214 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17215 if (rs == NS_QQQ
17216 && !check_simd_pred_availability (false,
17217 NEON_CHECK_ARCH | NEON_CHECK_CC))
17218 return;
17219 else if (rs != NS_QQQ
17220 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17221 first_error (BAD_FPU);
17222
17223 neon_check_type (3, rs, N_IGNORE_TYPE);
17224 /* U bit and size field were set as part of the bitmask. */
17225 NEON_ENCODE (INTEGER, inst);
17226 neon_three_same (neon_quad (rs), 0, -1);
17227 }
17228 else
17229 {
17230 const int three_ops_form = (inst.operands[2].present
17231 && !inst.operands[2].isreg);
17232 const int immoperand = (three_ops_form ? 2 : 1);
17233 enum neon_shape rs = (three_ops_form
17234 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17235 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
17236 /* Because neon_select_shape makes the second operand a copy of the first
17237 if the second operand is not present. */
17238 if (rs == NS_QQI
17239 && !check_simd_pred_availability (false,
17240 NEON_CHECK_ARCH | NEON_CHECK_CC))
17241 return;
17242 else if (rs != NS_QQI
17243 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17244 first_error (BAD_FPU);
17245
17246 struct neon_type_el et;
17247 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17248 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17249 else
17250 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17251 | N_KEY, N_EQK);
17252
17253 if (et.type == NT_invtype)
17254 return;
17255 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
17256 unsigned immbits;
17257 int cmode;
17258
17259
17260 if (three_ops_form)
17261 constraint (inst.operands[0].reg != inst.operands[1].reg,
17262 _("first and second operands shall be the same register"));
17263
17264 NEON_ENCODE (IMMED, inst);
17265
17266 immbits = inst.operands[immoperand].imm;
17267 if (et.size == 64)
17268 {
17269 /* .i64 is a pseudo-op, so the immediate must be a repeating
17270 pattern. */
17271 if (immbits != (inst.operands[immoperand].regisimm ?
17272 inst.operands[immoperand].reg : 0))
17273 {
17274 /* Set immbits to an invalid constant. */
17275 immbits = 0xdeadbeef;
17276 }
17277 }
17278
17279 switch (opcode)
17280 {
17281 case N_MNEM_vbic:
17282 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17283 break;
17284
17285 case N_MNEM_vorr:
17286 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17287 break;
17288
17289 case N_MNEM_vand:
17290 /* Pseudo-instruction for VBIC. */
17291 neon_invert_size (&immbits, 0, et.size);
17292 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17293 break;
17294
17295 case N_MNEM_vorn:
17296 /* Pseudo-instruction for VORR. */
17297 neon_invert_size (&immbits, 0, et.size);
17298 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17299 break;
17300
17301 default:
17302 abort ();
17303 }
17304
17305 if (cmode == FAIL)
17306 return;
17307
17308 inst.instruction |= neon_quad (rs) << 6;
17309 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17310 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17311 inst.instruction |= cmode << 8;
17312 neon_write_immbits (immbits);
17313
17314 neon_dp_fixup (&inst);
17315 }
17316 }
17317
17318 static void
17319 do_neon_bitfield (void)
17320 {
17321 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17322 neon_check_type (3, rs, N_IGNORE_TYPE);
17323 neon_three_same (neon_quad (rs), 0, -1);
17324 }
17325
17326 static void
17327 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
17328 unsigned destbits)
17329 {
17330 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17331 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
17332 types | N_KEY);
17333 if (et.type == NT_float)
17334 {
17335 NEON_ENCODE (FLOAT, inst);
17336 if (rs == NS_QQR)
17337 mve_encode_qqr (et.size, 0, 1);
17338 else
17339 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
17340 }
17341 else
17342 {
17343 NEON_ENCODE (INTEGER, inst);
17344 if (rs == NS_QQR)
17345 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
17346 else
17347 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
17348 }
17349 }
17350
17351
17352 static void
17353 do_neon_dyadic_if_su_d (void)
17354 {
17355 /* This version only allow D registers, but that constraint is enforced during
17356 operand parsing so we don't need to do anything extra here. */
17357 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17358 }
17359
17360 static void
17361 do_neon_dyadic_if_i_d (void)
17362 {
17363 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17364 affected if we specify unsigned args. */
17365 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17366 }
17367
17368 static void
17369 do_mve_vstr_vldr_QI (int size, int elsize, int load)
17370 {
17371 constraint (size < 32, BAD_ADDR_MODE);
17372 constraint (size != elsize, BAD_EL_TYPE);
17373 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17374 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17375 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17376 _("destination register and offset register may not be the"
17377 " same"));
17378
17379 int imm = inst.relocs[0].exp.X_add_number;
17380 int add = 1;
17381 if (imm < 0)
17382 {
17383 add = 0;
17384 imm = -imm;
17385 }
17386 constraint ((imm % (size / 8) != 0)
17387 || imm > (0x7f << neon_logbits (size)),
17388 (size == 32) ? _("immediate must be a multiple of 4 in the"
17389 " range of +/-[0,508]")
17390 : _("immediate must be a multiple of 8 in the"
17391 " range of +/-[0,1016]"));
17392 inst.instruction |= 0x11 << 24;
17393 inst.instruction |= add << 23;
17394 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17395 inst.instruction |= inst.operands[1].writeback << 21;
17396 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17397 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17398 inst.instruction |= 1 << 12;
17399 inst.instruction |= (size == 64) << 8;
17400 inst.instruction &= 0xffffff00;
17401 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17402 inst.instruction |= imm >> neon_logbits (size);
17403 }
17404
17405 static void
17406 do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17407 {
17408 unsigned os = inst.operands[1].imm >> 5;
17409 unsigned type = inst.vectype.el[0].type;
17410 constraint (os != 0 && size == 8,
17411 _("can not shift offsets when accessing less than half-word"));
17412 constraint (os && os != neon_logbits (size),
17413 _("shift immediate must be 1, 2 or 3 for half-word, word"
17414 " or double-word accesses respectively"));
17415 if (inst.operands[1].reg == REG_PC)
17416 as_tsktsk (MVE_BAD_PC);
17417
17418 switch (size)
17419 {
17420 case 8:
17421 constraint (elsize >= 64, BAD_EL_TYPE);
17422 break;
17423 case 16:
17424 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17425 break;
17426 case 32:
17427 case 64:
17428 constraint (elsize != size, BAD_EL_TYPE);
17429 break;
17430 default:
17431 break;
17432 }
17433 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17434 BAD_ADDR_MODE);
17435 if (load)
17436 {
17437 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17438 _("destination register and offset register may not be"
17439 " the same"));
17440 constraint (size == elsize && type == NT_signed, BAD_EL_TYPE);
17441 constraint (size != elsize && type != NT_unsigned && type != NT_signed,
17442 BAD_EL_TYPE);
17443 inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28;
17444 }
17445 else
17446 {
17447 constraint (type != NT_untyped, BAD_EL_TYPE);
17448 }
17449
17450 inst.instruction |= 1 << 23;
17451 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17452 inst.instruction |= inst.operands[1].reg << 16;
17453 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17454 inst.instruction |= neon_logbits (elsize) << 7;
17455 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17456 inst.instruction |= LOW4 (inst.operands[1].imm);
17457 inst.instruction |= !!os;
17458 }
17459
17460 static void
17461 do_mve_vstr_vldr_RI (int size, int elsize, int load)
17462 {
17463 enum neon_el_type type = inst.vectype.el[0].type;
17464
17465 constraint (size >= 64, BAD_ADDR_MODE);
17466 switch (size)
17467 {
17468 case 16:
17469 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17470 break;
17471 case 32:
17472 constraint (elsize != size, BAD_EL_TYPE);
17473 break;
17474 default:
17475 break;
17476 }
17477 if (load)
17478 {
17479 constraint (elsize != size && type != NT_unsigned
17480 && type != NT_signed, BAD_EL_TYPE);
17481 }
17482 else
17483 {
17484 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17485 }
17486
17487 int imm = inst.relocs[0].exp.X_add_number;
17488 int add = 1;
17489 if (imm < 0)
17490 {
17491 add = 0;
17492 imm = -imm;
17493 }
17494
17495 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17496 {
17497 switch (size)
17498 {
17499 case 8:
17500 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17501 break;
17502 case 16:
17503 constraint (1, _("immediate must be a multiple of 2 in the"
17504 " range of +/-[0,254]"));
17505 break;
17506 case 32:
17507 constraint (1, _("immediate must be a multiple of 4 in the"
17508 " range of +/-[0,508]"));
17509 break;
17510 }
17511 }
17512
17513 if (size != elsize)
17514 {
17515 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17516 constraint (inst.operands[0].reg > 14,
17517 _("MVE vector register in the range [Q0..Q7] expected"));
17518 inst.instruction |= (load && type == NT_unsigned) << 28;
17519 inst.instruction |= (size == 16) << 19;
17520 inst.instruction |= neon_logbits (elsize) << 7;
17521 }
17522 else
17523 {
17524 if (inst.operands[1].reg == REG_PC)
17525 as_tsktsk (MVE_BAD_PC);
17526 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17527 as_tsktsk (MVE_BAD_SP);
17528 inst.instruction |= 1 << 12;
17529 inst.instruction |= neon_logbits (size) << 7;
17530 }
17531 inst.instruction |= inst.operands[1].preind << 24;
17532 inst.instruction |= add << 23;
17533 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17534 inst.instruction |= inst.operands[1].writeback << 21;
17535 inst.instruction |= inst.operands[1].reg << 16;
17536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17537 inst.instruction &= 0xffffff80;
17538 inst.instruction |= imm >> neon_logbits (size);
17539
17540 }
17541
17542 static void
17543 do_mve_vstr_vldr (void)
17544 {
17545 unsigned size;
17546 int load = 0;
17547
17548 if (inst.cond > COND_ALWAYS)
17549 inst.pred_insn_type = INSIDE_VPT_INSN;
17550 else
17551 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17552
17553 switch (inst.instruction)
17554 {
17555 default:
17556 gas_assert (0);
17557 break;
17558 case M_MNEM_vldrb:
17559 load = 1;
17560 /* fall through. */
17561 case M_MNEM_vstrb:
17562 size = 8;
17563 break;
17564 case M_MNEM_vldrh:
17565 load = 1;
17566 /* fall through. */
17567 case M_MNEM_vstrh:
17568 size = 16;
17569 break;
17570 case M_MNEM_vldrw:
17571 load = 1;
17572 /* fall through. */
17573 case M_MNEM_vstrw:
17574 size = 32;
17575 break;
17576 case M_MNEM_vldrd:
17577 load = 1;
17578 /* fall through. */
17579 case M_MNEM_vstrd:
17580 size = 64;
17581 break;
17582 }
17583 unsigned elsize = inst.vectype.el[0].size;
17584
17585 if (inst.operands[1].isquad)
17586 {
17587 /* We are dealing with [Q, imm]{!} cases. */
17588 do_mve_vstr_vldr_QI (size, elsize, load);
17589 }
17590 else
17591 {
17592 if (inst.operands[1].immisreg == 2)
17593 {
17594 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17595 do_mve_vstr_vldr_RQ (size, elsize, load);
17596 }
17597 else if (!inst.operands[1].immisreg)
17598 {
17599 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17600 do_mve_vstr_vldr_RI (size, elsize, load);
17601 }
17602 else
17603 constraint (1, BAD_ADDR_MODE);
17604 }
17605
17606 inst.is_neon = 1;
17607 }
17608
17609 static void
17610 do_mve_vst_vld (void)
17611 {
17612 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17613 return;
17614
17615 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17616 || inst.relocs[0].exp.X_add_number != 0
17617 || inst.operands[1].immisreg != 0,
17618 BAD_ADDR_MODE);
17619 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17620 if (inst.operands[1].reg == REG_PC)
17621 as_tsktsk (MVE_BAD_PC);
17622 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17623 as_tsktsk (MVE_BAD_SP);
17624
17625
17626 /* These instructions are one of the "exceptions" mentioned in
17627 handle_pred_state. They are MVE instructions that are not VPT compatible
17628 and do not accept a VPT code, thus appending such a code is a syntax
17629 error. */
17630 if (inst.cond > COND_ALWAYS)
17631 first_error (BAD_SYNTAX);
17632 /* If we append a scalar condition code we can set this to
17633 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17634 else if (inst.cond < COND_ALWAYS)
17635 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17636 else
17637 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17638
17639 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17640 inst.instruction |= inst.operands[1].writeback << 21;
17641 inst.instruction |= inst.operands[1].reg << 16;
17642 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17643 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17644 inst.is_neon = 1;
17645 }
17646
17647 static void
17648 do_mve_vaddlv (void)
17649 {
17650 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17651 struct neon_type_el et
17652 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17653
17654 if (et.type == NT_invtype)
17655 first_error (BAD_EL_TYPE);
17656
17657 if (inst.cond > COND_ALWAYS)
17658 inst.pred_insn_type = INSIDE_VPT_INSN;
17659 else
17660 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17661
17662 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17663
17664 inst.instruction |= (et.type == NT_unsigned) << 28;
17665 inst.instruction |= inst.operands[1].reg << 19;
17666 inst.instruction |= inst.operands[0].reg << 12;
17667 inst.instruction |= inst.operands[2].reg;
17668 inst.is_neon = 1;
17669 }
17670
17671 static void
17672 do_neon_dyadic_if_su (void)
17673 {
17674 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17675 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17676 N_SUF_32 | N_KEY);
17677
17678 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17679 || inst.instruction == ((unsigned) N_MNEM_vmin))
17680 && et.type == NT_float
17681 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17682
17683 if (!check_simd_pred_availability (et.type == NT_float,
17684 NEON_CHECK_ARCH | NEON_CHECK_CC))
17685 return;
17686
17687 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17688 }
17689
17690 static void
17691 do_neon_addsub_if_i (void)
17692 {
17693 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17694 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
17695 return;
17696
17697 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17698 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17699 N_EQK, N_IF_32 | N_I64 | N_KEY);
17700
17701 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17702 /* If we are parsing Q registers and the element types match MVE, which NEON
17703 also supports, then we must check whether this is an instruction that can
17704 be used by both MVE/NEON. This distinction can be made based on whether
17705 they are predicated or not. */
17706 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17707 {
17708 if (!check_simd_pred_availability (et.type == NT_float,
17709 NEON_CHECK_ARCH | NEON_CHECK_CC))
17710 return;
17711 }
17712 else
17713 {
17714 /* If they are either in a D register or are using an unsupported. */
17715 if (rs != NS_QQR
17716 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17717 return;
17718 }
17719
17720 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17721 affected if we specify unsigned args. */
17722 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
17723 }
17724
17725 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17726 result to be:
17727 V<op> A,B (A is operand 0, B is operand 2)
17728 to mean:
17729 V<op> A,B,A
17730 not:
17731 V<op> A,B,B
17732 so handle that case specially. */
17733
17734 static void
17735 neon_exchange_operands (void)
17736 {
17737 if (inst.operands[1].present)
17738 {
17739 void *scratch = xmalloc (sizeof (inst.operands[0]));
17740
17741 /* Swap operands[1] and operands[2]. */
17742 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17743 inst.operands[1] = inst.operands[2];
17744 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
17745 free (scratch);
17746 }
17747 else
17748 {
17749 inst.operands[1] = inst.operands[2];
17750 inst.operands[2] = inst.operands[0];
17751 }
17752 }
17753
17754 static void
17755 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17756 {
17757 if (inst.operands[2].isreg)
17758 {
17759 if (invert)
17760 neon_exchange_operands ();
17761 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
17762 }
17763 else
17764 {
17765 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17766 struct neon_type_el et = neon_check_type (2, rs,
17767 N_EQK | N_SIZ, immtypes | N_KEY);
17768
17769 NEON_ENCODE (IMMED, inst);
17770 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17771 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17772 inst.instruction |= LOW4 (inst.operands[1].reg);
17773 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17774 inst.instruction |= neon_quad (rs) << 6;
17775 inst.instruction |= (et.type == NT_float) << 10;
17776 inst.instruction |= neon_logbits (et.size) << 18;
17777
17778 neon_dp_fixup (&inst);
17779 }
17780 }
17781
17782 static void
17783 do_neon_cmp (void)
17784 {
17785 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, false);
17786 }
17787
17788 static void
17789 do_neon_cmp_inv (void)
17790 {
17791 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, true);
17792 }
17793
17794 static void
17795 do_neon_ceq (void)
17796 {
17797 neon_compare (N_IF_32, N_IF_32, false);
17798 }
17799
17800 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
17801 scalars, which are encoded in 5 bits, M : Rm.
17802 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17803 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
17804 index in M.
17805
17806 Dot Product instructions are similar to multiply instructions except elsize
17807 should always be 32.
17808
17809 This function translates SCALAR, which is GAS's internal encoding of indexed
17810 scalar register, to raw encoding. There is also register and index range
17811 check based on ELSIZE. */
17812
17813 static unsigned
17814 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17815 {
17816 unsigned regno = NEON_SCALAR_REG (scalar);
17817 unsigned elno = NEON_SCALAR_INDEX (scalar);
17818
17819 switch (elsize)
17820 {
17821 case 16:
17822 if (regno > 7 || elno > 3)
17823 goto bad_scalar;
17824 return regno | (elno << 3);
17825
17826 case 32:
17827 if (regno > 15 || elno > 1)
17828 goto bad_scalar;
17829 return regno | (elno << 4);
17830
17831 default:
17832 bad_scalar:
17833 first_error (_("scalar out of range for multiply instruction"));
17834 }
17835
17836 return 0;
17837 }
17838
17839 /* Encode multiply / multiply-accumulate scalar instructions. */
17840
17841 static void
17842 neon_mul_mac (struct neon_type_el et, int ubit)
17843 {
17844 unsigned scalar;
17845
17846 /* Give a more helpful error message if we have an invalid type. */
17847 if (et.type == NT_invtype)
17848 return;
17849
17850 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
17851 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17852 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17853 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17854 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17855 inst.instruction |= LOW4 (scalar);
17856 inst.instruction |= HI1 (scalar) << 5;
17857 inst.instruction |= (et.type == NT_float) << 8;
17858 inst.instruction |= neon_logbits (et.size) << 20;
17859 inst.instruction |= (ubit != 0) << 24;
17860
17861 neon_dp_fixup (&inst);
17862 }
17863
17864 static void
17865 do_neon_mac_maybe_scalar (void)
17866 {
17867 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17868 return;
17869
17870 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
17871 return;
17872
17873 if (inst.operands[2].isscalar)
17874 {
17875 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17876 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17877 struct neon_type_el et = neon_check_type (3, rs,
17878 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
17879 NEON_ENCODE (SCALAR, inst);
17880 neon_mul_mac (et, neon_quad (rs));
17881 }
17882 else if (!inst.operands[2].isvec)
17883 {
17884 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17885
17886 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17887 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17888
17889 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17890 }
17891 else
17892 {
17893 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17894 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17895 affected if we specify unsigned args. */
17896 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17897 }
17898 }
17899
17900 static void
17901 do_bfloat_vfma (void)
17902 {
17903 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
17904 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
17905 enum neon_shape rs;
17906 int t_bit = 0;
17907
17908 if (inst.instruction != B_MNEM_vfmab)
17909 {
17910 t_bit = 1;
17911 inst.instruction = B_MNEM_vfmat;
17912 }
17913
17914 if (inst.operands[2].isscalar)
17915 {
17916 rs = neon_select_shape (NS_QQS, NS_NULL);
17917 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17918
17919 inst.instruction |= (1 << 25);
17920 int idx = inst.operands[2].reg & 0xf;
17921 constraint (!(idx < 4), _("index must be in the range 0 to 3"));
17922 inst.operands[2].reg >>= 4;
17923 constraint (!(inst.operands[2].reg < 8),
17924 _("indexed register must be less than 8"));
17925 neon_three_args (t_bit);
17926 inst.instruction |= ((idx & 1) << 3);
17927 inst.instruction |= ((idx & 2) << 4);
17928 }
17929 else
17930 {
17931 rs = neon_select_shape (NS_QQQ, NS_NULL);
17932 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
17933 neon_three_args (t_bit);
17934 }
17935
17936 }
17937
17938 static void
17939 do_neon_fmac (void)
17940 {
17941 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17942 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
17943 return;
17944
17945 if (!check_simd_pred_availability (true, NEON_CHECK_CC | NEON_CHECK_ARCH))
17946 return;
17947
17948 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17949 {
17950 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17951 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17952 N_EQK);
17953
17954 if (rs == NS_QQR)
17955 {
17956
17957 if (inst.operands[2].reg == REG_SP)
17958 as_tsktsk (MVE_BAD_SP);
17959 else if (inst.operands[2].reg == REG_PC)
17960 as_tsktsk (MVE_BAD_PC);
17961
17962 inst.instruction = 0xee310e40;
17963 inst.instruction |= (et.size == 16) << 28;
17964 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17965 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17966 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17967 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17968 inst.instruction |= inst.operands[2].reg;
17969 inst.is_neon = 1;
17970 return;
17971 }
17972 }
17973 else
17974 {
17975 constraint (!inst.operands[2].isvec, BAD_FPU);
17976 }
17977
17978 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17979 }
17980
17981 static void
17982 do_mve_vfma (void)
17983 {
17984 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_bf16) &&
17985 inst.cond == COND_ALWAYS)
17986 {
17987 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17988 inst.instruction = N_MNEM_vfma;
17989 inst.pred_insn_type = INSIDE_VPT_INSN;
17990 inst.cond = 0xf;
17991 return do_neon_fmac();
17992 }
17993 else
17994 {
17995 do_bfloat_vfma();
17996 }
17997 }
17998
17999 static void
18000 do_neon_tst (void)
18001 {
18002 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18003 struct neon_type_el et = neon_check_type (3, rs,
18004 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18005 neon_three_same (neon_quad (rs), 0, et.size);
18006 }
18007
18008 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
18009 same types as the MAC equivalents. The polynomial type for this instruction
18010 is encoded the same as the integer type. */
18011
18012 static void
18013 do_neon_mul (void)
18014 {
18015 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
18016 return;
18017
18018 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
18019 return;
18020
18021 if (inst.operands[2].isscalar)
18022 {
18023 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18024 do_neon_mac_maybe_scalar ();
18025 }
18026 else
18027 {
18028 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18029 {
18030 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18031 struct neon_type_el et
18032 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
18033 if (et.type == NT_float)
18034 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
18035 BAD_FPU);
18036
18037 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
18038 }
18039 else
18040 {
18041 constraint (!inst.operands[2].isvec, BAD_FPU);
18042 neon_dyadic_misc (NT_poly,
18043 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
18044 }
18045 }
18046 }
18047
18048 static void
18049 do_neon_qdmulh (void)
18050 {
18051 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18052 return;
18053
18054 if (inst.operands[2].isscalar)
18055 {
18056 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
18057 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18058 struct neon_type_el et = neon_check_type (3, rs,
18059 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18060 NEON_ENCODE (SCALAR, inst);
18061 neon_mul_mac (et, neon_quad (rs));
18062 }
18063 else
18064 {
18065 enum neon_shape rs;
18066 struct neon_type_el et;
18067 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18068 {
18069 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
18070 et = neon_check_type (3, rs,
18071 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18072 }
18073 else
18074 {
18075 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18076 et = neon_check_type (3, rs,
18077 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18078 }
18079
18080 NEON_ENCODE (INTEGER, inst);
18081 if (rs == NS_QQR)
18082 mve_encode_qqr (et.size, 0, 0);
18083 else
18084 /* The U bit (rounding) comes from bit mask. */
18085 neon_three_same (neon_quad (rs), 0, et.size);
18086 }
18087 }
18088
18089 static void
18090 do_mve_vaddv (void)
18091 {
18092 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18093 struct neon_type_el et
18094 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
18095
18096 if (et.type == NT_invtype)
18097 first_error (BAD_EL_TYPE);
18098
18099 if (inst.cond > COND_ALWAYS)
18100 inst.pred_insn_type = INSIDE_VPT_INSN;
18101 else
18102 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18103
18104 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
18105
18106 mve_encode_rq (et.type == NT_unsigned, et.size);
18107 }
18108
18109 static void
18110 do_mve_vhcadd (void)
18111 {
18112 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
18113 struct neon_type_el et
18114 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18115
18116 if (inst.cond > COND_ALWAYS)
18117 inst.pred_insn_type = INSIDE_VPT_INSN;
18118 else
18119 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18120
18121 unsigned rot = inst.relocs[0].exp.X_add_number;
18122 constraint (rot != 90 && rot != 270, _("immediate out of range"));
18123
18124 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
18125 as_tsktsk (_("Warning: 32-bit element size and same first and third "
18126 "operand makes instruction UNPREDICTABLE"));
18127
18128 mve_encode_qqq (0, et.size);
18129 inst.instruction |= (rot == 270) << 12;
18130 inst.is_neon = 1;
18131 }
18132
18133 static void
18134 do_mve_vqdmull (void)
18135 {
18136 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
18137 struct neon_type_el et
18138 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18139
18140 if (et.size == 32
18141 && (inst.operands[0].reg == inst.operands[1].reg
18142 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
18143 as_tsktsk (BAD_MVE_SRCDEST);
18144
18145 if (inst.cond > COND_ALWAYS)
18146 inst.pred_insn_type = INSIDE_VPT_INSN;
18147 else
18148 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18149
18150 if (rs == NS_QQQ)
18151 {
18152 mve_encode_qqq (et.size == 32, 64);
18153 inst.instruction |= 1;
18154 }
18155 else
18156 {
18157 mve_encode_qqr (64, et.size == 32, 0);
18158 inst.instruction |= 0x3 << 5;
18159 }
18160 }
18161
18162 static void
18163 do_mve_vadc (void)
18164 {
18165 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18166 struct neon_type_el et
18167 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
18168
18169 if (et.type == NT_invtype)
18170 first_error (BAD_EL_TYPE);
18171
18172 if (inst.cond > COND_ALWAYS)
18173 inst.pred_insn_type = INSIDE_VPT_INSN;
18174 else
18175 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18176
18177 mve_encode_qqq (0, 64);
18178 }
18179
18180 static void
18181 do_mve_vbrsr (void)
18182 {
18183 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18184 struct neon_type_el et
18185 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18186
18187 if (inst.cond > COND_ALWAYS)
18188 inst.pred_insn_type = INSIDE_VPT_INSN;
18189 else
18190 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18191
18192 mve_encode_qqr (et.size, 0, 0);
18193 }
18194
18195 static void
18196 do_mve_vsbc (void)
18197 {
18198 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18199
18200 if (inst.cond > COND_ALWAYS)
18201 inst.pred_insn_type = INSIDE_VPT_INSN;
18202 else
18203 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18204
18205 mve_encode_qqq (1, 64);
18206 }
18207
18208 static void
18209 do_mve_vmulh (void)
18210 {
18211 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18212 struct neon_type_el et
18213 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18214
18215 if (inst.cond > COND_ALWAYS)
18216 inst.pred_insn_type = INSIDE_VPT_INSN;
18217 else
18218 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18219
18220 mve_encode_qqq (et.type == NT_unsigned, et.size);
18221 }
18222
18223 static void
18224 do_mve_vqdmlah (void)
18225 {
18226 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18227 struct neon_type_el et
18228 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18229
18230 if (inst.cond > COND_ALWAYS)
18231 inst.pred_insn_type = INSIDE_VPT_INSN;
18232 else
18233 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18234
18235 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18236 }
18237
18238 static void
18239 do_mve_vqdmladh (void)
18240 {
18241 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18242 struct neon_type_el et
18243 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18244
18245 if (inst.cond > COND_ALWAYS)
18246 inst.pred_insn_type = INSIDE_VPT_INSN;
18247 else
18248 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18249
18250 mve_encode_qqq (0, et.size);
18251 }
18252
18253
18254 static void
18255 do_mve_vmull (void)
18256 {
18257
18258 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18259 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18260 if (inst.cond == COND_ALWAYS
18261 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18262 {
18263
18264 if (rs == NS_QQQ)
18265 {
18266 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18267 goto neon_vmul;
18268 }
18269 else
18270 goto neon_vmul;
18271 }
18272
18273 constraint (rs != NS_QQQ, BAD_FPU);
18274 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18275 N_SU_32 | N_P8 | N_P16 | N_KEY);
18276
18277 /* We are dealing with MVE's vmullt. */
18278 if (et.size == 32
18279 && (inst.operands[0].reg == inst.operands[1].reg
18280 || inst.operands[0].reg == inst.operands[2].reg))
18281 as_tsktsk (BAD_MVE_SRCDEST);
18282
18283 if (inst.cond > COND_ALWAYS)
18284 inst.pred_insn_type = INSIDE_VPT_INSN;
18285 else
18286 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18287
18288 if (et.type == NT_poly)
18289 mve_encode_qqq (neon_logbits (et.size), 64);
18290 else
18291 mve_encode_qqq (et.type == NT_unsigned, et.size);
18292
18293 return;
18294
18295 neon_vmul:
18296 inst.instruction = N_MNEM_vmul;
18297 inst.cond = 0xb;
18298 if (thumb_mode)
18299 inst.pred_insn_type = INSIDE_IT_INSN;
18300 do_neon_mul ();
18301 }
18302
18303 static void
18304 do_mve_vabav (void)
18305 {
18306 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18307
18308 if (rs == NS_NULL)
18309 return;
18310
18311 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18312 return;
18313
18314 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18315 | N_S16 | N_S32 | N_U8 | N_U16
18316 | N_U32);
18317
18318 if (inst.cond > COND_ALWAYS)
18319 inst.pred_insn_type = INSIDE_VPT_INSN;
18320 else
18321 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18322
18323 mve_encode_rqq (et.type == NT_unsigned, et.size);
18324 }
18325
18326 static void
18327 do_mve_vmladav (void)
18328 {
18329 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18330 struct neon_type_el et = neon_check_type (3, rs,
18331 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18332
18333 if (et.type == NT_unsigned
18334 && (inst.instruction == M_MNEM_vmladavx
18335 || inst.instruction == M_MNEM_vmladavax
18336 || inst.instruction == M_MNEM_vmlsdav
18337 || inst.instruction == M_MNEM_vmlsdava
18338 || inst.instruction == M_MNEM_vmlsdavx
18339 || inst.instruction == M_MNEM_vmlsdavax))
18340 first_error (BAD_SIMD_TYPE);
18341
18342 constraint (inst.operands[2].reg > 14,
18343 _("MVE vector register in the range [Q0..Q7] expected"));
18344
18345 if (inst.cond > COND_ALWAYS)
18346 inst.pred_insn_type = INSIDE_VPT_INSN;
18347 else
18348 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18349
18350 if (inst.instruction == M_MNEM_vmlsdav
18351 || inst.instruction == M_MNEM_vmlsdava
18352 || inst.instruction == M_MNEM_vmlsdavx
18353 || inst.instruction == M_MNEM_vmlsdavax)
18354 inst.instruction |= (et.size == 8) << 28;
18355 else
18356 inst.instruction |= (et.size == 8) << 8;
18357
18358 mve_encode_rqq (et.type == NT_unsigned, 64);
18359 inst.instruction |= (et.size == 32) << 16;
18360 }
18361
18362 static void
18363 do_mve_vmlaldav (void)
18364 {
18365 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18366 struct neon_type_el et
18367 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18368 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18369
18370 if (et.type == NT_unsigned
18371 && (inst.instruction == M_MNEM_vmlsldav
18372 || inst.instruction == M_MNEM_vmlsldava
18373 || inst.instruction == M_MNEM_vmlsldavx
18374 || inst.instruction == M_MNEM_vmlsldavax))
18375 first_error (BAD_SIMD_TYPE);
18376
18377 if (inst.cond > COND_ALWAYS)
18378 inst.pred_insn_type = INSIDE_VPT_INSN;
18379 else
18380 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18381
18382 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18383 }
18384
18385 static void
18386 do_mve_vrmlaldavh (void)
18387 {
18388 struct neon_type_el et;
18389 if (inst.instruction == M_MNEM_vrmlsldavh
18390 || inst.instruction == M_MNEM_vrmlsldavha
18391 || inst.instruction == M_MNEM_vrmlsldavhx
18392 || inst.instruction == M_MNEM_vrmlsldavhax)
18393 {
18394 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18395 if (inst.operands[1].reg == REG_SP)
18396 as_tsktsk (MVE_BAD_SP);
18397 }
18398 else
18399 {
18400 if (inst.instruction == M_MNEM_vrmlaldavhx
18401 || inst.instruction == M_MNEM_vrmlaldavhax)
18402 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18403 else
18404 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18405 N_U32 | N_S32 | N_KEY);
18406 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18407 with vmax/min instructions, making the use of SP in assembly really
18408 nonsensical, so instead of issuing a warning like we do for other uses
18409 of SP for the odd register operand we error out. */
18410 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18411 }
18412
18413 /* Make sure we still check the second operand is an odd one and that PC is
18414 disallowed. This because we are parsing for any GPR operand, to be able
18415 to distinguish between giving a warning or an error for SP as described
18416 above. */
18417 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18418 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18419
18420 if (inst.cond > COND_ALWAYS)
18421 inst.pred_insn_type = INSIDE_VPT_INSN;
18422 else
18423 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18424
18425 mve_encode_rrqq (et.type == NT_unsigned, 0);
18426 }
18427
18428
18429 static void
18430 do_mve_vmaxnmv (void)
18431 {
18432 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18433 struct neon_type_el et
18434 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18435
18436 if (inst.cond > COND_ALWAYS)
18437 inst.pred_insn_type = INSIDE_VPT_INSN;
18438 else
18439 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18440
18441 if (inst.operands[0].reg == REG_SP)
18442 as_tsktsk (MVE_BAD_SP);
18443 else if (inst.operands[0].reg == REG_PC)
18444 as_tsktsk (MVE_BAD_PC);
18445
18446 mve_encode_rq (et.size == 16, 64);
18447 }
18448
18449 static void
18450 do_mve_vmaxv (void)
18451 {
18452 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18453 struct neon_type_el et;
18454
18455 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18456 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18457 else
18458 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18459
18460 if (inst.cond > COND_ALWAYS)
18461 inst.pred_insn_type = INSIDE_VPT_INSN;
18462 else
18463 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18464
18465 if (inst.operands[0].reg == REG_SP)
18466 as_tsktsk (MVE_BAD_SP);
18467 else if (inst.operands[0].reg == REG_PC)
18468 as_tsktsk (MVE_BAD_PC);
18469
18470 mve_encode_rq (et.type == NT_unsigned, et.size);
18471 }
18472
18473
18474 static void
18475 do_neon_qrdmlah (void)
18476 {
18477 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18478 return;
18479 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18480 {
18481 /* Check we're on the correct architecture. */
18482 if (!mark_feature_used (&fpu_neon_ext_armv8))
18483 inst.error
18484 = _("instruction form not available on this architecture.");
18485 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18486 {
18487 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18488 record_feature_use (&fpu_neon_ext_v8_1);
18489 }
18490 if (inst.operands[2].isscalar)
18491 {
18492 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18493 struct neon_type_el et = neon_check_type (3, rs,
18494 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18495 NEON_ENCODE (SCALAR, inst);
18496 neon_mul_mac (et, neon_quad (rs));
18497 }
18498 else
18499 {
18500 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18501 struct neon_type_el et = neon_check_type (3, rs,
18502 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18503 NEON_ENCODE (INTEGER, inst);
18504 /* The U bit (rounding) comes from bit mask. */
18505 neon_three_same (neon_quad (rs), 0, et.size);
18506 }
18507 }
18508 else
18509 {
18510 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18511 struct neon_type_el et
18512 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18513
18514 NEON_ENCODE (INTEGER, inst);
18515 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18516 }
18517 }
18518
18519 static void
18520 do_neon_fcmp_absolute (void)
18521 {
18522 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18523 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18524 N_F_16_32 | N_KEY);
18525 /* Size field comes from bit mask. */
18526 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
18527 }
18528
18529 static void
18530 do_neon_fcmp_absolute_inv (void)
18531 {
18532 neon_exchange_operands ();
18533 do_neon_fcmp_absolute ();
18534 }
18535
18536 static void
18537 do_neon_step (void)
18538 {
18539 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18540 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18541 N_F_16_32 | N_KEY);
18542 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
18543 }
18544
18545 static void
18546 do_neon_abs_neg (void)
18547 {
18548 enum neon_shape rs;
18549 struct neon_type_el et;
18550
18551 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18552 return;
18553
18554 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
18555 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
18556
18557 if (!check_simd_pred_availability (et.type == NT_float,
18558 NEON_CHECK_ARCH | NEON_CHECK_CC))
18559 return;
18560
18561 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18562 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18563 inst.instruction |= LOW4 (inst.operands[1].reg);
18564 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18565 inst.instruction |= neon_quad (rs) << 6;
18566 inst.instruction |= (et.type == NT_float) << 10;
18567 inst.instruction |= neon_logbits (et.size) << 18;
18568
18569 neon_dp_fixup (&inst);
18570 }
18571
18572 static void
18573 do_neon_sli (void)
18574 {
18575 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18576 return;
18577
18578 enum neon_shape rs;
18579 struct neon_type_el et;
18580 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18581 {
18582 rs = neon_select_shape (NS_QQI, NS_NULL);
18583 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18584 }
18585 else
18586 {
18587 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18588 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18589 }
18590
18591
18592 int imm = inst.operands[2].imm;
18593 constraint (imm < 0 || (unsigned)imm >= et.size,
18594 _("immediate out of range for insert"));
18595 neon_imm_shift (false, 0, neon_quad (rs), et, imm);
18596 }
18597
18598 static void
18599 do_neon_sri (void)
18600 {
18601 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18602 return;
18603
18604 enum neon_shape rs;
18605 struct neon_type_el et;
18606 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18607 {
18608 rs = neon_select_shape (NS_QQI, NS_NULL);
18609 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18610 }
18611 else
18612 {
18613 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18614 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18615 }
18616
18617 int imm = inst.operands[2].imm;
18618 constraint (imm < 1 || (unsigned)imm > et.size,
18619 _("immediate out of range for insert"));
18620 neon_imm_shift (false, 0, neon_quad (rs), et, et.size - imm);
18621 }
18622
18623 static void
18624 do_neon_qshlu_imm (void)
18625 {
18626 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
18627 return;
18628
18629 enum neon_shape rs;
18630 struct neon_type_el et;
18631 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18632 {
18633 rs = neon_select_shape (NS_QQI, NS_NULL);
18634 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18635 }
18636 else
18637 {
18638 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18639 et = neon_check_type (2, rs, N_EQK | N_UNS,
18640 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18641 }
18642
18643 int imm = inst.operands[2].imm;
18644 constraint (imm < 0 || (unsigned)imm >= et.size,
18645 _("immediate out of range for shift"));
18646 /* Only encodes the 'U present' variant of the instruction.
18647 In this case, signed types have OP (bit 8) set to 0.
18648 Unsigned types have OP set to 1. */
18649 inst.instruction |= (et.type == NT_unsigned) << 8;
18650 /* The rest of the bits are the same as other immediate shifts. */
18651 neon_imm_shift (false, 0, neon_quad (rs), et, imm);
18652 }
18653
18654 static void
18655 do_neon_qmovn (void)
18656 {
18657 struct neon_type_el et = neon_check_type (2, NS_DQ,
18658 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18659 /* Saturating move where operands can be signed or unsigned, and the
18660 destination has the same signedness. */
18661 NEON_ENCODE (INTEGER, inst);
18662 if (et.type == NT_unsigned)
18663 inst.instruction |= 0xc0;
18664 else
18665 inst.instruction |= 0x80;
18666 neon_two_same (0, 1, et.size / 2);
18667 }
18668
18669 static void
18670 do_neon_qmovun (void)
18671 {
18672 struct neon_type_el et = neon_check_type (2, NS_DQ,
18673 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18674 /* Saturating move with unsigned results. Operands must be signed. */
18675 NEON_ENCODE (INTEGER, inst);
18676 neon_two_same (0, 1, et.size / 2);
18677 }
18678
18679 static void
18680 do_neon_rshift_sat_narrow (void)
18681 {
18682 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18683 or unsigned. If operands are unsigned, results must also be unsigned. */
18684 struct neon_type_el et = neon_check_type (2, NS_DQI,
18685 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18686 int imm = inst.operands[2].imm;
18687 /* This gets the bounds check, size encoding and immediate bits calculation
18688 right. */
18689 et.size /= 2;
18690
18691 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18692 VQMOVN.I<size> <Dd>, <Qm>. */
18693 if (imm == 0)
18694 {
18695 inst.operands[2].present = 0;
18696 inst.instruction = N_MNEM_vqmovn;
18697 do_neon_qmovn ();
18698 return;
18699 }
18700
18701 constraint (imm < 1 || (unsigned)imm > et.size,
18702 _("immediate out of range"));
18703 neon_imm_shift (true, et.type == NT_unsigned, 0, et, et.size - imm);
18704 }
18705
18706 static void
18707 do_neon_rshift_sat_narrow_u (void)
18708 {
18709 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18710 or unsigned. If operands are unsigned, results must also be unsigned. */
18711 struct neon_type_el et = neon_check_type (2, NS_DQI,
18712 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18713 int imm = inst.operands[2].imm;
18714 /* This gets the bounds check, size encoding and immediate bits calculation
18715 right. */
18716 et.size /= 2;
18717
18718 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18719 VQMOVUN.I<size> <Dd>, <Qm>. */
18720 if (imm == 0)
18721 {
18722 inst.operands[2].present = 0;
18723 inst.instruction = N_MNEM_vqmovun;
18724 do_neon_qmovun ();
18725 return;
18726 }
18727
18728 constraint (imm < 1 || (unsigned)imm > et.size,
18729 _("immediate out of range"));
18730 /* FIXME: The manual is kind of unclear about what value U should have in
18731 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18732 must be 1. */
18733 neon_imm_shift (true, 1, 0, et, et.size - imm);
18734 }
18735
18736 static void
18737 do_neon_movn (void)
18738 {
18739 struct neon_type_el et = neon_check_type (2, NS_DQ,
18740 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18741 NEON_ENCODE (INTEGER, inst);
18742 neon_two_same (0, 1, et.size / 2);
18743 }
18744
18745 static void
18746 do_neon_rshift_narrow (void)
18747 {
18748 struct neon_type_el et = neon_check_type (2, NS_DQI,
18749 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18750 int imm = inst.operands[2].imm;
18751 /* This gets the bounds check, size encoding and immediate bits calculation
18752 right. */
18753 et.size /= 2;
18754
18755 /* If immediate is zero then we are a pseudo-instruction for
18756 VMOVN.I<size> <Dd>, <Qm> */
18757 if (imm == 0)
18758 {
18759 inst.operands[2].present = 0;
18760 inst.instruction = N_MNEM_vmovn;
18761 do_neon_movn ();
18762 return;
18763 }
18764
18765 constraint (imm < 1 || (unsigned)imm > et.size,
18766 _("immediate out of range for narrowing operation"));
18767 neon_imm_shift (false, 0, 0, et, et.size - imm);
18768 }
18769
18770 static void
18771 do_neon_shll (void)
18772 {
18773 /* FIXME: Type checking when lengthening. */
18774 struct neon_type_el et = neon_check_type (2, NS_QDI,
18775 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18776 unsigned imm = inst.operands[2].imm;
18777
18778 if (imm == et.size)
18779 {
18780 /* Maximum shift variant. */
18781 NEON_ENCODE (INTEGER, inst);
18782 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18783 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18784 inst.instruction |= LOW4 (inst.operands[1].reg);
18785 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18786 inst.instruction |= neon_logbits (et.size) << 18;
18787
18788 neon_dp_fixup (&inst);
18789 }
18790 else
18791 {
18792 /* A more-specific type check for non-max versions. */
18793 et = neon_check_type (2, NS_QDI,
18794 N_EQK | N_DBL, N_SU_32 | N_KEY);
18795 NEON_ENCODE (IMMED, inst);
18796 neon_imm_shift (true, et.type == NT_unsigned, 0, et, imm);
18797 }
18798 }
18799
18800 /* Check the various types for the VCVT instruction, and return which version
18801 the current instruction is. */
18802
18803 #define CVT_FLAVOUR_VAR \
18804 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18805 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18806 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18807 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18808 /* Half-precision conversions. */ \
18809 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18810 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18811 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18812 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
18813 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18814 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
18815 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18816 Compared with single/double precision variants, only the co-processor \
18817 field is different, so the encoding flow is reused here. */ \
18818 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18819 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18820 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18821 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
18822 CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \
18823 /* VFP instructions. */ \
18824 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18825 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18826 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18827 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18828 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18829 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18830 /* VFP instructions with bitshift. */ \
18831 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18832 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18833 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18834 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18835 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18836 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18837 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18838 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18839
18840 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18841 neon_cvt_flavour_##C,
18842
18843 /* The different types of conversions we can do. */
18844 enum neon_cvt_flavour
18845 {
18846 CVT_FLAVOUR_VAR
18847 neon_cvt_flavour_invalid,
18848 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18849 };
18850
18851 #undef CVT_VAR
18852
18853 static enum neon_cvt_flavour
18854 get_neon_cvt_flavour (enum neon_shape rs)
18855 {
18856 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18857 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18858 if (et.type != NT_invtype) \
18859 { \
18860 inst.error = NULL; \
18861 return (neon_cvt_flavour_##C); \
18862 }
18863
18864 struct neon_type_el et;
18865 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
18866 || rs == NS_FF) ? N_VFP : 0;
18867 /* The instruction versions which take an immediate take one register
18868 argument, which is extended to the width of the full register. Thus the
18869 "source" and "destination" registers must have the same width. Hack that
18870 here by making the size equal to the key (wider, in this case) operand. */
18871 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
18872
18873 CVT_FLAVOUR_VAR;
18874
18875 return neon_cvt_flavour_invalid;
18876 #undef CVT_VAR
18877 }
18878
18879 enum neon_cvt_mode
18880 {
18881 neon_cvt_mode_a,
18882 neon_cvt_mode_n,
18883 neon_cvt_mode_p,
18884 neon_cvt_mode_m,
18885 neon_cvt_mode_z,
18886 neon_cvt_mode_x,
18887 neon_cvt_mode_r
18888 };
18889
18890 /* Neon-syntax VFP conversions. */
18891
18892 static void
18893 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
18894 {
18895 const char *opname = 0;
18896
18897 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18898 || rs == NS_FHI || rs == NS_HFI)
18899 {
18900 /* Conversions with immediate bitshift. */
18901 const char *enc[] =
18902 {
18903 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18904 CVT_FLAVOUR_VAR
18905 NULL
18906 #undef CVT_VAR
18907 };
18908
18909 if (flavour < (int) ARRAY_SIZE (enc))
18910 {
18911 opname = enc[flavour];
18912 constraint (inst.operands[0].reg != inst.operands[1].reg,
18913 _("operands 0 and 1 must be the same register"));
18914 inst.operands[1] = inst.operands[2];
18915 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18916 }
18917 }
18918 else
18919 {
18920 /* Conversions without bitshift. */
18921 const char *enc[] =
18922 {
18923 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18924 CVT_FLAVOUR_VAR
18925 NULL
18926 #undef CVT_VAR
18927 };
18928
18929 if (flavour < (int) ARRAY_SIZE (enc))
18930 opname = enc[flavour];
18931 }
18932
18933 if (opname)
18934 do_vfp_nsyn_opcode (opname);
18935
18936 /* ARMv8.2 fp16 VCVT instruction. */
18937 if (flavour == neon_cvt_flavour_s32_f16
18938 || flavour == neon_cvt_flavour_u32_f16
18939 || flavour == neon_cvt_flavour_f16_u32
18940 || flavour == neon_cvt_flavour_f16_s32)
18941 do_scalar_fp16_v82_encode ();
18942 }
18943
18944 static void
18945 do_vfp_nsyn_cvtz (void)
18946 {
18947 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
18948 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18949 const char *enc[] =
18950 {
18951 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18952 CVT_FLAVOUR_VAR
18953 NULL
18954 #undef CVT_VAR
18955 };
18956
18957 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
18958 do_vfp_nsyn_opcode (enc[flavour]);
18959 }
18960
18961 static void
18962 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
18963 enum neon_cvt_mode mode)
18964 {
18965 int sz, op;
18966 int rm;
18967
18968 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18969 D register operands. */
18970 if (flavour == neon_cvt_flavour_s32_f64
18971 || flavour == neon_cvt_flavour_u32_f64)
18972 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18973 _(BAD_FPU));
18974
18975 if (flavour == neon_cvt_flavour_s32_f16
18976 || flavour == neon_cvt_flavour_u32_f16)
18977 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18978 _(BAD_FP16));
18979
18980 set_pred_insn_type (OUTSIDE_PRED_INSN);
18981
18982 switch (flavour)
18983 {
18984 case neon_cvt_flavour_s32_f64:
18985 sz = 1;
18986 op = 1;
18987 break;
18988 case neon_cvt_flavour_s32_f32:
18989 sz = 0;
18990 op = 1;
18991 break;
18992 case neon_cvt_flavour_s32_f16:
18993 sz = 0;
18994 op = 1;
18995 break;
18996 case neon_cvt_flavour_u32_f64:
18997 sz = 1;
18998 op = 0;
18999 break;
19000 case neon_cvt_flavour_u32_f32:
19001 sz = 0;
19002 op = 0;
19003 break;
19004 case neon_cvt_flavour_u32_f16:
19005 sz = 0;
19006 op = 0;
19007 break;
19008 default:
19009 first_error (_("invalid instruction shape"));
19010 return;
19011 }
19012
19013 switch (mode)
19014 {
19015 case neon_cvt_mode_a: rm = 0; break;
19016 case neon_cvt_mode_n: rm = 1; break;
19017 case neon_cvt_mode_p: rm = 2; break;
19018 case neon_cvt_mode_m: rm = 3; break;
19019 default: first_error (_("invalid rounding mode")); return;
19020 }
19021
19022 NEON_ENCODE (FPV8, inst);
19023 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
19024 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
19025 inst.instruction |= sz << 8;
19026
19027 /* ARMv8.2 fp16 VCVT instruction. */
19028 if (flavour == neon_cvt_flavour_s32_f16
19029 ||flavour == neon_cvt_flavour_u32_f16)
19030 do_scalar_fp16_v82_encode ();
19031 inst.instruction |= op << 7;
19032 inst.instruction |= rm << 16;
19033 inst.instruction |= 0xf0000000;
19034 inst.is_neon = true;
19035 }
19036
19037 static void
19038 do_neon_cvt_1 (enum neon_cvt_mode mode)
19039 {
19040 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
19041 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
19042 NS_FH, NS_HF, NS_FHI, NS_HFI,
19043 NS_NULL);
19044 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19045
19046 if (flavour == neon_cvt_flavour_invalid)
19047 return;
19048
19049 /* PR11109: Handle round-to-zero for VCVT conversions. */
19050 if (mode == neon_cvt_mode_z
19051 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
19052 && (flavour == neon_cvt_flavour_s16_f16
19053 || flavour == neon_cvt_flavour_u16_f16
19054 || flavour == neon_cvt_flavour_s32_f32
19055 || flavour == neon_cvt_flavour_u32_f32
19056 || flavour == neon_cvt_flavour_s32_f64
19057 || flavour == neon_cvt_flavour_u32_f64)
19058 && (rs == NS_FD || rs == NS_FF))
19059 {
19060 do_vfp_nsyn_cvtz ();
19061 return;
19062 }
19063
19064 /* ARMv8.2 fp16 VCVT conversions. */
19065 if (mode == neon_cvt_mode_z
19066 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
19067 && (flavour == neon_cvt_flavour_s32_f16
19068 || flavour == neon_cvt_flavour_u32_f16)
19069 && (rs == NS_FH))
19070 {
19071 do_vfp_nsyn_cvtz ();
19072 do_scalar_fp16_v82_encode ();
19073 return;
19074 }
19075
19076 if ((rs == NS_FD || rs == NS_QQI) && mode == neon_cvt_mode_n
19077 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19078 {
19079 /* We are dealing with vcvt with the 'ne' condition. */
19080 inst.cond = 0x1;
19081 inst.instruction = N_MNEM_vcvt;
19082 do_neon_cvt_1 (neon_cvt_mode_z);
19083 return;
19084 }
19085
19086 /* VFP rather than Neon conversions. */
19087 if (flavour >= neon_cvt_flavour_first_fp)
19088 {
19089 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19090 do_vfp_nsyn_cvt (rs, flavour);
19091 else
19092 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19093
19094 return;
19095 }
19096
19097 switch (rs)
19098 {
19099 case NS_QQI:
19100 if (mode == neon_cvt_mode_z
19101 && (flavour == neon_cvt_flavour_f16_s16
19102 || flavour == neon_cvt_flavour_f16_u16
19103 || flavour == neon_cvt_flavour_s16_f16
19104 || flavour == neon_cvt_flavour_u16_f16
19105 || flavour == neon_cvt_flavour_f32_u32
19106 || flavour == neon_cvt_flavour_f32_s32
19107 || flavour == neon_cvt_flavour_s32_f32
19108 || flavour == neon_cvt_flavour_u32_f32))
19109 {
19110 if (!check_simd_pred_availability (true,
19111 NEON_CHECK_CC | NEON_CHECK_ARCH))
19112 return;
19113 }
19114 /* fall through. */
19115 case NS_DDI:
19116 {
19117 unsigned immbits;
19118 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
19119 0x0000100, 0x1000100, 0x0, 0x1000000};
19120
19121 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19122 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19123 return;
19124
19125 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19126 {
19127 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
19128 _("immediate value out of range"));
19129 switch (flavour)
19130 {
19131 case neon_cvt_flavour_f16_s16:
19132 case neon_cvt_flavour_f16_u16:
19133 case neon_cvt_flavour_s16_f16:
19134 case neon_cvt_flavour_u16_f16:
19135 constraint (inst.operands[2].imm > 16,
19136 _("immediate value out of range"));
19137 break;
19138 case neon_cvt_flavour_f32_u32:
19139 case neon_cvt_flavour_f32_s32:
19140 case neon_cvt_flavour_s32_f32:
19141 case neon_cvt_flavour_u32_f32:
19142 constraint (inst.operands[2].imm > 32,
19143 _("immediate value out of range"));
19144 break;
19145 default:
19146 inst.error = BAD_FPU;
19147 return;
19148 }
19149 }
19150
19151 /* Fixed-point conversion with #0 immediate is encoded as an
19152 integer conversion. */
19153 if (inst.operands[2].present && inst.operands[2].imm == 0)
19154 goto int_encode;
19155 NEON_ENCODE (IMMED, inst);
19156 if (flavour != neon_cvt_flavour_invalid)
19157 inst.instruction |= enctab[flavour];
19158 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19159 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19160 inst.instruction |= LOW4 (inst.operands[1].reg);
19161 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19162 inst.instruction |= neon_quad (rs) << 6;
19163 inst.instruction |= 1 << 21;
19164 if (flavour < neon_cvt_flavour_s16_f16)
19165 {
19166 inst.instruction |= 1 << 21;
19167 immbits = 32 - inst.operands[2].imm;
19168 inst.instruction |= immbits << 16;
19169 }
19170 else
19171 {
19172 inst.instruction |= 3 << 20;
19173 immbits = 16 - inst.operands[2].imm;
19174 inst.instruction |= immbits << 16;
19175 inst.instruction &= ~(1 << 9);
19176 }
19177
19178 neon_dp_fixup (&inst);
19179 }
19180 break;
19181
19182 case NS_QQ:
19183 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19184 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19185 && (flavour == neon_cvt_flavour_s16_f16
19186 || flavour == neon_cvt_flavour_u16_f16
19187 || flavour == neon_cvt_flavour_s32_f32
19188 || flavour == neon_cvt_flavour_u32_f32))
19189 {
19190 if (!check_simd_pred_availability (true,
19191 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19192 return;
19193 }
19194 else if (mode == neon_cvt_mode_z
19195 && (flavour == neon_cvt_flavour_f16_s16
19196 || flavour == neon_cvt_flavour_f16_u16
19197 || flavour == neon_cvt_flavour_s16_f16
19198 || flavour == neon_cvt_flavour_u16_f16
19199 || flavour == neon_cvt_flavour_f32_u32
19200 || flavour == neon_cvt_flavour_f32_s32
19201 || flavour == neon_cvt_flavour_s32_f32
19202 || flavour == neon_cvt_flavour_u32_f32))
19203 {
19204 if (!check_simd_pred_availability (true,
19205 NEON_CHECK_CC | NEON_CHECK_ARCH))
19206 return;
19207 }
19208 /* fall through. */
19209 case NS_DD:
19210 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19211 {
19212
19213 NEON_ENCODE (FLOAT, inst);
19214 if (!check_simd_pred_availability (true,
19215 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19216 return;
19217
19218 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19219 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19220 inst.instruction |= LOW4 (inst.operands[1].reg);
19221 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19222 inst.instruction |= neon_quad (rs) << 6;
19223 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19224 || flavour == neon_cvt_flavour_u32_f32) << 7;
19225 inst.instruction |= mode << 8;
19226 if (flavour == neon_cvt_flavour_u16_f16
19227 || flavour == neon_cvt_flavour_s16_f16)
19228 /* Mask off the original size bits and reencode them. */
19229 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19230
19231 if (thumb_mode)
19232 inst.instruction |= 0xfc000000;
19233 else
19234 inst.instruction |= 0xf0000000;
19235 }
19236 else
19237 {
19238 int_encode:
19239 {
19240 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19241 0x100, 0x180, 0x0, 0x080};
19242
19243 NEON_ENCODE (INTEGER, inst);
19244
19245 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19246 {
19247 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19248 return;
19249 }
19250
19251 if (flavour != neon_cvt_flavour_invalid)
19252 inst.instruction |= enctab[flavour];
19253
19254 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19255 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19256 inst.instruction |= LOW4 (inst.operands[1].reg);
19257 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19258 inst.instruction |= neon_quad (rs) << 6;
19259 if (flavour >= neon_cvt_flavour_s16_f16
19260 && flavour <= neon_cvt_flavour_f16_u16)
19261 /* Half precision. */
19262 inst.instruction |= 1 << 18;
19263 else
19264 inst.instruction |= 2 << 18;
19265
19266 neon_dp_fixup (&inst);
19267 }
19268 }
19269 break;
19270
19271 /* Half-precision conversions for Advanced SIMD -- neon. */
19272 case NS_QD:
19273 case NS_DQ:
19274 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19275 return;
19276
19277 if ((rs == NS_DQ)
19278 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19279 {
19280 as_bad (_("operand size must match register width"));
19281 break;
19282 }
19283
19284 if ((rs == NS_QD)
19285 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19286 {
19287 as_bad (_("operand size must match register width"));
19288 break;
19289 }
19290
19291 if (rs == NS_DQ)
19292 {
19293 if (flavour == neon_cvt_flavour_bf16_f32)
19294 {
19295 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH8) == FAIL)
19296 return;
19297 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19298 /* VCVT.bf16.f32. */
19299 inst.instruction = 0x11b60640;
19300 }
19301 else
19302 /* VCVT.f16.f32. */
19303 inst.instruction = 0x3b60600;
19304 }
19305 else
19306 /* VCVT.f32.f16. */
19307 inst.instruction = 0x3b60700;
19308
19309 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19310 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19311 inst.instruction |= LOW4 (inst.operands[1].reg);
19312 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19313 neon_dp_fixup (&inst);
19314 break;
19315
19316 default:
19317 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
19318 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19319 do_vfp_nsyn_cvt (rs, flavour);
19320 else
19321 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19322 }
19323 }
19324
19325 static void
19326 do_neon_cvtr (void)
19327 {
19328 do_neon_cvt_1 (neon_cvt_mode_x);
19329 }
19330
19331 static void
19332 do_neon_cvt (void)
19333 {
19334 do_neon_cvt_1 (neon_cvt_mode_z);
19335 }
19336
19337 static void
19338 do_neon_cvta (void)
19339 {
19340 do_neon_cvt_1 (neon_cvt_mode_a);
19341 }
19342
19343 static void
19344 do_neon_cvtn (void)
19345 {
19346 do_neon_cvt_1 (neon_cvt_mode_n);
19347 }
19348
19349 static void
19350 do_neon_cvtp (void)
19351 {
19352 do_neon_cvt_1 (neon_cvt_mode_p);
19353 }
19354
19355 static void
19356 do_neon_cvtm (void)
19357 {
19358 do_neon_cvt_1 (neon_cvt_mode_m);
19359 }
19360
19361 static void
19362 do_neon_cvttb_2 (bool t, bool to, bool is_double)
19363 {
19364 if (is_double)
19365 mark_feature_used (&fpu_vfp_ext_armv8);
19366
19367 encode_arm_vfp_reg (inst.operands[0].reg,
19368 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19369 encode_arm_vfp_reg (inst.operands[1].reg,
19370 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19371 inst.instruction |= to ? 0x10000 : 0;
19372 inst.instruction |= t ? 0x80 : 0;
19373 inst.instruction |= is_double ? 0x100 : 0;
19374 do_vfp_cond_or_thumb ();
19375 }
19376
19377 static void
19378 do_neon_cvttb_1 (bool t)
19379 {
19380 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
19381 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
19382
19383 if (rs == NS_NULL)
19384 return;
19385 else if (rs == NS_QQ || rs == NS_QQI)
19386 {
19387 int single_to_half = 0;
19388 if (!check_simd_pred_availability (true, NEON_CHECK_ARCH))
19389 return;
19390
19391 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19392
19393 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19394 && (flavour == neon_cvt_flavour_u16_f16
19395 || flavour == neon_cvt_flavour_s16_f16
19396 || flavour == neon_cvt_flavour_f16_s16
19397 || flavour == neon_cvt_flavour_f16_u16
19398 || flavour == neon_cvt_flavour_u32_f32
19399 || flavour == neon_cvt_flavour_s32_f32
19400 || flavour == neon_cvt_flavour_f32_s32
19401 || flavour == neon_cvt_flavour_f32_u32))
19402 {
19403 inst.cond = 0xf;
19404 inst.instruction = N_MNEM_vcvt;
19405 set_pred_insn_type (INSIDE_VPT_INSN);
19406 do_neon_cvt_1 (neon_cvt_mode_z);
19407 return;
19408 }
19409 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19410 single_to_half = 1;
19411 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19412 {
19413 first_error (BAD_FPU);
19414 return;
19415 }
19416
19417 inst.instruction = 0xee3f0e01;
19418 inst.instruction |= single_to_half << 28;
19419 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19420 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19421 inst.instruction |= t << 12;
19422 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19423 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19424 inst.is_neon = 1;
19425 }
19426 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19427 {
19428 inst.error = NULL;
19429 do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/false);
19430 }
19431 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19432 {
19433 inst.error = NULL;
19434 do_neon_cvttb_2 (t, /*to=*/false, /*is_double=*/false);
19435 }
19436 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19437 {
19438 /* The VCVTB and VCVTT instructions with D-register operands
19439 don't work for SP only targets. */
19440 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19441 _(BAD_FPU));
19442
19443 inst.error = NULL;
19444 do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/true);
19445 }
19446 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19447 {
19448 /* The VCVTB and VCVTT instructions with D-register operands
19449 don't work for SP only targets. */
19450 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19451 _(BAD_FPU));
19452
19453 inst.error = NULL;
19454 do_neon_cvttb_2 (t, /*to=*/false, /*is_double=*/true);
19455 }
19456 else if (neon_check_type (2, rs, N_BF16 | N_VFP, N_F32).type != NT_invtype)
19457 {
19458 constraint (!mark_feature_used (&arm_ext_bf16), _(BAD_BF16));
19459 inst.error = NULL;
19460 inst.instruction |= (1 << 8);
19461 inst.instruction &= ~(1 << 9);
19462 do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/false);
19463 }
19464 else
19465 return;
19466 }
19467
19468 static void
19469 do_neon_cvtb (void)
19470 {
19471 do_neon_cvttb_1 (false);
19472 }
19473
19474
19475 static void
19476 do_neon_cvtt (void)
19477 {
19478 do_neon_cvttb_1 (true);
19479 }
19480
19481 static void
19482 neon_move_immediate (void)
19483 {
19484 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19485 struct neon_type_el et = neon_check_type (2, rs,
19486 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
19487 unsigned immlo, immhi = 0, immbits;
19488 int op, cmode, float_p;
19489
19490 constraint (et.type == NT_invtype,
19491 _("operand size must be specified for immediate VMOV"));
19492
19493 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19494 op = (inst.instruction & (1 << 5)) != 0;
19495
19496 immlo = inst.operands[1].imm;
19497 if (inst.operands[1].regisimm)
19498 immhi = inst.operands[1].reg;
19499
19500 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
19501 _("immediate has bits set outside the operand size"));
19502
19503 float_p = inst.operands[1].immisfloat;
19504
19505 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
19506 et.size, et.type)) == FAIL)
19507 {
19508 /* Invert relevant bits only. */
19509 neon_invert_size (&immlo, &immhi, et.size);
19510 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
19511 with one or the other; those cases are caught by
19512 neon_cmode_for_move_imm. */
19513 op = !op;
19514 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19515 &op, et.size, et.type)) == FAIL)
19516 {
19517 first_error (_("immediate out of range"));
19518 return;
19519 }
19520 }
19521
19522 inst.instruction &= ~(1 << 5);
19523 inst.instruction |= op << 5;
19524
19525 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19526 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19527 inst.instruction |= neon_quad (rs) << 6;
19528 inst.instruction |= cmode << 8;
19529
19530 neon_write_immbits (immbits);
19531 }
19532
19533 static void
19534 do_neon_mvn (void)
19535 {
19536 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
19537 return;
19538
19539 if (inst.operands[1].isreg)
19540 {
19541 enum neon_shape rs;
19542 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19543 rs = neon_select_shape (NS_QQ, NS_NULL);
19544 else
19545 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19546
19547 if (rs == NS_NULL)
19548 return;
19549
19550 NEON_ENCODE (INTEGER, inst);
19551 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19552 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19553 inst.instruction |= LOW4 (inst.operands[1].reg);
19554 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19555 inst.instruction |= neon_quad (rs) << 6;
19556 }
19557 else
19558 {
19559 NEON_ENCODE (IMMED, inst);
19560 neon_move_immediate ();
19561 }
19562
19563 neon_dp_fixup (&inst);
19564
19565 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19566 {
19567 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19568 }
19569 }
19570
19571 /* Encode instructions of form:
19572
19573 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
19574 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
19575
19576 static void
19577 neon_mixed_length (struct neon_type_el et, unsigned size)
19578 {
19579 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19580 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19581 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19582 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19583 inst.instruction |= LOW4 (inst.operands[2].reg);
19584 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19585 inst.instruction |= (et.type == NT_unsigned) << 24;
19586 inst.instruction |= neon_logbits (size) << 20;
19587
19588 neon_dp_fixup (&inst);
19589 }
19590
19591 static void
19592 do_neon_dyadic_long (void)
19593 {
19594 enum neon_shape rs = neon_select_shape (NS_QDD, NS_HHH, NS_FFF, NS_DDD, NS_NULL);
19595 if (rs == NS_QDD)
19596 {
19597 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19598 return;
19599
19600 NEON_ENCODE (INTEGER, inst);
19601 /* FIXME: Type checking for lengthening op. */
19602 struct neon_type_el et = neon_check_type (3, NS_QDD,
19603 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19604 neon_mixed_length (et, et.size);
19605 }
19606 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19607 && (inst.cond == 0xf || inst.cond == 0x10))
19608 {
19609 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19610 in an IT block with le/lt conditions. */
19611
19612 if (inst.cond == 0xf)
19613 inst.cond = 0xb;
19614 else if (inst.cond == 0x10)
19615 inst.cond = 0xd;
19616
19617 inst.pred_insn_type = INSIDE_IT_INSN;
19618
19619 if (inst.instruction == N_MNEM_vaddl)
19620 {
19621 inst.instruction = N_MNEM_vadd;
19622 do_neon_addsub_if_i ();
19623 }
19624 else if (inst.instruction == N_MNEM_vsubl)
19625 {
19626 inst.instruction = N_MNEM_vsub;
19627 do_neon_addsub_if_i ();
19628 }
19629 else if (inst.instruction == N_MNEM_vabdl)
19630 {
19631 inst.instruction = N_MNEM_vabd;
19632 do_neon_dyadic_if_su ();
19633 }
19634 }
19635 else
19636 first_error (BAD_FPU);
19637 }
19638
19639 static void
19640 do_neon_abal (void)
19641 {
19642 struct neon_type_el et = neon_check_type (3, NS_QDD,
19643 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19644 neon_mixed_length (et, et.size);
19645 }
19646
19647 static void
19648 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19649 {
19650 if (inst.operands[2].isscalar)
19651 {
19652 struct neon_type_el et = neon_check_type (3, NS_QDS,
19653 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
19654 NEON_ENCODE (SCALAR, inst);
19655 neon_mul_mac (et, et.type == NT_unsigned);
19656 }
19657 else
19658 {
19659 struct neon_type_el et = neon_check_type (3, NS_QDD,
19660 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
19661 NEON_ENCODE (INTEGER, inst);
19662 neon_mixed_length (et, et.size);
19663 }
19664 }
19665
19666 static void
19667 do_neon_mac_maybe_scalar_long (void)
19668 {
19669 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19670 }
19671
19672 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19673 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19674
19675 static unsigned
19676 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19677 {
19678 unsigned regno = NEON_SCALAR_REG (scalar);
19679 unsigned elno = NEON_SCALAR_INDEX (scalar);
19680
19681 if (quad_p)
19682 {
19683 if (regno > 7 || elno > 3)
19684 goto bad_scalar;
19685
19686 return ((regno & 0x7)
19687 | ((elno & 0x1) << 3)
19688 | (((elno >> 1) & 0x1) << 5));
19689 }
19690 else
19691 {
19692 if (regno > 15 || elno > 1)
19693 goto bad_scalar;
19694
19695 return (((regno & 0x1) << 5)
19696 | ((regno >> 1) & 0x7)
19697 | ((elno & 0x1) << 3));
19698 }
19699
19700 bad_scalar:
19701 first_error (_("scalar out of range for multiply instruction"));
19702 return 0;
19703 }
19704
19705 static void
19706 do_neon_fmac_maybe_scalar_long (int subtype)
19707 {
19708 enum neon_shape rs;
19709 int high8;
19710 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19711 field (bits[21:20]) has different meaning. For scalar index variant, it's
19712 used to differentiate add and subtract, otherwise it's with fixed value
19713 0x2. */
19714 int size = -1;
19715
19716 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19717 be a scalar index register. */
19718 if (inst.operands[2].isscalar)
19719 {
19720 high8 = 0xfe000000;
19721 if (subtype)
19722 size = 16;
19723 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19724 }
19725 else
19726 {
19727 high8 = 0xfc000000;
19728 size = 32;
19729 if (subtype)
19730 inst.instruction |= (0x1 << 23);
19731 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19732 }
19733
19734
19735 if (inst.cond != COND_ALWAYS)
19736 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19737 "behaviour is UNPREDICTABLE"));
19738
19739 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19740 _(BAD_FP16));
19741
19742 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19743 _(BAD_FPU));
19744
19745 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19746 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19747 so we simply pass -1 as size. */
19748 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19749 neon_three_same (quad_p, 0, size);
19750
19751 /* Undo neon_dp_fixup. Redo the high eight bits. */
19752 inst.instruction &= 0x00ffffff;
19753 inst.instruction |= high8;
19754
19755 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19756 whether the instruction is in Q form and whether Vm is a scalar indexed
19757 operand. */
19758 if (inst.operands[2].isscalar)
19759 {
19760 unsigned rm
19761 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19762 inst.instruction &= 0xffffffd0;
19763 inst.instruction |= rm;
19764
19765 if (!quad_p)
19766 {
19767 /* Redo Rn as well. */
19768 inst.instruction &= 0xfff0ff7f;
19769 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19770 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19771 }
19772 }
19773 else if (!quad_p)
19774 {
19775 /* Redo Rn and Rm. */
19776 inst.instruction &= 0xfff0ff50;
19777 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19778 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19779 inst.instruction |= HI4 (inst.operands[2].reg);
19780 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19781 }
19782 }
19783
19784 static void
19785 do_neon_vfmal (void)
19786 {
19787 return do_neon_fmac_maybe_scalar_long (0);
19788 }
19789
19790 static void
19791 do_neon_vfmsl (void)
19792 {
19793 return do_neon_fmac_maybe_scalar_long (1);
19794 }
19795
19796 static void
19797 do_neon_dyadic_wide (void)
19798 {
19799 struct neon_type_el et = neon_check_type (3, NS_QQD,
19800 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19801 neon_mixed_length (et, et.size);
19802 }
19803
19804 static void
19805 do_neon_dyadic_narrow (void)
19806 {
19807 struct neon_type_el et = neon_check_type (3, NS_QDD,
19808 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
19809 /* Operand sign is unimportant, and the U bit is part of the opcode,
19810 so force the operand type to integer. */
19811 et.type = NT_integer;
19812 neon_mixed_length (et, et.size / 2);
19813 }
19814
19815 static void
19816 do_neon_mul_sat_scalar_long (void)
19817 {
19818 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19819 }
19820
19821 static void
19822 do_neon_vmull (void)
19823 {
19824 if (inst.operands[2].isscalar)
19825 do_neon_mac_maybe_scalar_long ();
19826 else
19827 {
19828 struct neon_type_el et = neon_check_type (3, NS_QDD,
19829 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
19830
19831 if (et.type == NT_poly)
19832 NEON_ENCODE (POLY, inst);
19833 else
19834 NEON_ENCODE (INTEGER, inst);
19835
19836 /* For polynomial encoding the U bit must be zero, and the size must
19837 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19838 obviously, as 0b10). */
19839 if (et.size == 64)
19840 {
19841 /* Check we're on the correct architecture. */
19842 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19843 inst.error =
19844 _("Instruction form not available on this architecture.");
19845
19846 et.size = 32;
19847 }
19848
19849 neon_mixed_length (et, et.size);
19850 }
19851 }
19852
19853 static void
19854 do_neon_ext (void)
19855 {
19856 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
19857 struct neon_type_el et = neon_check_type (3, rs,
19858 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19859 unsigned imm = (inst.operands[3].imm * et.size) / 8;
19860
19861 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19862 _("shift out of range"));
19863 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19864 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19865 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19866 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19867 inst.instruction |= LOW4 (inst.operands[2].reg);
19868 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19869 inst.instruction |= neon_quad (rs) << 6;
19870 inst.instruction |= imm << 8;
19871
19872 neon_dp_fixup (&inst);
19873 }
19874
19875 static void
19876 do_neon_rev (void)
19877 {
19878 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
19879 return;
19880
19881 enum neon_shape rs;
19882 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19883 rs = neon_select_shape (NS_QQ, NS_NULL);
19884 else
19885 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19886
19887 struct neon_type_el et = neon_check_type (2, rs,
19888 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19889
19890 unsigned op = (inst.instruction >> 7) & 3;
19891 /* N (width of reversed regions) is encoded as part of the bitmask. We
19892 extract it here to check the elements to be reversed are smaller.
19893 Otherwise we'd get a reserved instruction. */
19894 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
19895
19896 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19897 && inst.operands[0].reg == inst.operands[1].reg)
19898 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19899 " operands makes instruction UNPREDICTABLE"));
19900
19901 gas_assert (elsize != 0);
19902 constraint (et.size >= elsize,
19903 _("elements must be smaller than reversal region"));
19904 neon_two_same (neon_quad (rs), 1, et.size);
19905 }
19906
19907 static void
19908 do_neon_dup (void)
19909 {
19910 if (inst.operands[1].isscalar)
19911 {
19912 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19913 BAD_FPU);
19914 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
19915 struct neon_type_el et = neon_check_type (2, rs,
19916 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19917 unsigned sizebits = et.size >> 3;
19918 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
19919 int logsize = neon_logbits (et.size);
19920 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
19921
19922 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
19923 return;
19924
19925 NEON_ENCODE (SCALAR, inst);
19926 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19927 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19928 inst.instruction |= LOW4 (dm);
19929 inst.instruction |= HI1 (dm) << 5;
19930 inst.instruction |= neon_quad (rs) << 6;
19931 inst.instruction |= x << 17;
19932 inst.instruction |= sizebits << 16;
19933
19934 neon_dp_fixup (&inst);
19935 }
19936 else
19937 {
19938 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19939 struct neon_type_el et = neon_check_type (2, rs,
19940 N_8 | N_16 | N_32 | N_KEY, N_EQK);
19941 if (rs == NS_QR)
19942 {
19943 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH))
19944 return;
19945 }
19946 else
19947 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19948 BAD_FPU);
19949
19950 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19951 {
19952 if (inst.operands[1].reg == REG_SP)
19953 as_tsktsk (MVE_BAD_SP);
19954 else if (inst.operands[1].reg == REG_PC)
19955 as_tsktsk (MVE_BAD_PC);
19956 }
19957
19958 /* Duplicate ARM register to lanes of vector. */
19959 NEON_ENCODE (ARMREG, inst);
19960 switch (et.size)
19961 {
19962 case 8: inst.instruction |= 0x400000; break;
19963 case 16: inst.instruction |= 0x000020; break;
19964 case 32: inst.instruction |= 0x000000; break;
19965 default: break;
19966 }
19967 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19968 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19969 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
19970 inst.instruction |= neon_quad (rs) << 21;
19971 /* The encoding for this instruction is identical for the ARM and Thumb
19972 variants, except for the condition field. */
19973 do_vfp_cond_or_thumb ();
19974 }
19975 }
19976
19977 static void
19978 do_mve_mov (int toQ)
19979 {
19980 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19981 return;
19982 if (inst.cond > COND_ALWAYS)
19983 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19984
19985 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19986 if (toQ)
19987 {
19988 Q0 = 0;
19989 Q1 = 1;
19990 Rt = 2;
19991 Rt2 = 3;
19992 }
19993
19994 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
19995 _("Index one must be [2,3] and index two must be two less than"
19996 " index one."));
19997 constraint (!toQ && inst.operands[Rt].reg == inst.operands[Rt2].reg,
19998 _("Destination registers may not be the same"));
19999 constraint (inst.operands[Rt].reg == REG_SP
20000 || inst.operands[Rt2].reg == REG_SP,
20001 BAD_SP);
20002 constraint (inst.operands[Rt].reg == REG_PC
20003 || inst.operands[Rt2].reg == REG_PC,
20004 BAD_PC);
20005
20006 inst.instruction = 0xec000f00;
20007 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
20008 inst.instruction |= !!toQ << 20;
20009 inst.instruction |= inst.operands[Rt2].reg << 16;
20010 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
20011 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
20012 inst.instruction |= inst.operands[Rt].reg;
20013 }
20014
20015 static void
20016 do_mve_movn (void)
20017 {
20018 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20019 return;
20020
20021 if (inst.cond > COND_ALWAYS)
20022 inst.pred_insn_type = INSIDE_VPT_INSN;
20023 else
20024 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
20025
20026 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
20027 | N_KEY);
20028
20029 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20030 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
20031 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20032 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20033 inst.instruction |= LOW4 (inst.operands[1].reg);
20034 inst.is_neon = 1;
20035
20036 }
20037
20038 /* VMOV has particularly many variations. It can be one of:
20039 0. VMOV<c><q> <Qd>, <Qm>
20040 1. VMOV<c><q> <Dd>, <Dm>
20041 (Register operations, which are VORR with Rm = Rn.)
20042 2. VMOV<c><q>.<dt> <Qd>, #<imm>
20043 3. VMOV<c><q>.<dt> <Dd>, #<imm>
20044 (Immediate loads.)
20045 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
20046 (ARM register to scalar.)
20047 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
20048 (Two ARM registers to vector.)
20049 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
20050 (Scalar to ARM register.)
20051 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
20052 (Vector to two ARM registers.)
20053 8. VMOV.F32 <Sd>, <Sm>
20054 9. VMOV.F64 <Dd>, <Dm>
20055 (VFP register moves.)
20056 10. VMOV.F32 <Sd>, #imm
20057 11. VMOV.F64 <Dd>, #imm
20058 (VFP float immediate load.)
20059 12. VMOV <Rd>, <Sm>
20060 (VFP single to ARM reg.)
20061 13. VMOV <Sd>, <Rm>
20062 (ARM reg to VFP single.)
20063 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
20064 (Two ARM regs to two VFP singles.)
20065 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
20066 (Two VFP singles to two ARM regs.)
20067 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
20068 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
20069 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
20070 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
20071
20072 These cases can be disambiguated using neon_select_shape, except cases 1/9
20073 and 3/11 which depend on the operand type too.
20074
20075 All the encoded bits are hardcoded by this function.
20076
20077 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
20078 Cases 5, 7 may be used with VFPv2 and above.
20079
20080 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
20081 can specify a type where it doesn't make sense to, and is ignored). */
20082
20083 static void
20084 do_neon_mov (void)
20085 {
20086 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
20087 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
20088 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
20089 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
20090 NS_NULL);
20091 struct neon_type_el et;
20092 const char *ldconst = 0;
20093
20094 switch (rs)
20095 {
20096 case NS_DD: /* case 1/9. */
20097 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20098 /* It is not an error here if no type is given. */
20099 inst.error = NULL;
20100
20101 /* In MVE we interpret the following instructions as same, so ignoring
20102 the following type (float) and size (64) checks.
20103 a: VMOV<c><q> <Dd>, <Dm>
20104 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
20105 if ((et.type == NT_float && et.size == 64)
20106 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
20107 {
20108 do_vfp_nsyn_opcode ("fcpyd");
20109 break;
20110 }
20111 /* fall through. */
20112
20113 case NS_QQ: /* case 0/1. */
20114 {
20115 if (!check_simd_pred_availability (false,
20116 NEON_CHECK_CC | NEON_CHECK_ARCH))
20117 return;
20118 /* The architecture manual I have doesn't explicitly state which
20119 value the U bit should have for register->register moves, but
20120 the equivalent VORR instruction has U = 0, so do that. */
20121 inst.instruction = 0x0200110;
20122 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20123 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20124 inst.instruction |= LOW4 (inst.operands[1].reg);
20125 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20126 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20127 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20128 inst.instruction |= neon_quad (rs) << 6;
20129
20130 neon_dp_fixup (&inst);
20131 }
20132 break;
20133
20134 case NS_DI: /* case 3/11. */
20135 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
20136 inst.error = NULL;
20137 if (et.type == NT_float && et.size == 64)
20138 {
20139 /* case 11 (fconstd). */
20140 ldconst = "fconstd";
20141 goto encode_fconstd;
20142 }
20143 /* fall through. */
20144
20145 case NS_QI: /* case 2/3. */
20146 if (!check_simd_pred_availability (false,
20147 NEON_CHECK_CC | NEON_CHECK_ARCH))
20148 return;
20149 inst.instruction = 0x0800010;
20150 neon_move_immediate ();
20151 neon_dp_fixup (&inst);
20152 break;
20153
20154 case NS_SR: /* case 4. */
20155 {
20156 unsigned bcdebits = 0;
20157 int logsize;
20158 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
20159 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
20160
20161 /* .<size> is optional here, defaulting to .32. */
20162 if (inst.vectype.elems == 0
20163 && inst.operands[0].vectype.type == NT_invtype
20164 && inst.operands[1].vectype.type == NT_invtype)
20165 {
20166 inst.vectype.el[0].type = NT_untyped;
20167 inst.vectype.el[0].size = 32;
20168 inst.vectype.elems = 1;
20169 }
20170
20171 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
20172 logsize = neon_logbits (et.size);
20173
20174 if (et.size != 32)
20175 {
20176 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20177 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
20178 return;
20179 }
20180 else
20181 {
20182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20183 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20184 _(BAD_FPU));
20185 }
20186
20187 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20188 {
20189 if (inst.operands[1].reg == REG_SP)
20190 as_tsktsk (MVE_BAD_SP);
20191 else if (inst.operands[1].reg == REG_PC)
20192 as_tsktsk (MVE_BAD_PC);
20193 }
20194 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
20195
20196 constraint (et.type == NT_invtype, _("bad type for scalar"));
20197 constraint (x >= size / et.size, _("scalar index out of range"));
20198
20199
20200 switch (et.size)
20201 {
20202 case 8: bcdebits = 0x8; break;
20203 case 16: bcdebits = 0x1; break;
20204 case 32: bcdebits = 0x0; break;
20205 default: ;
20206 }
20207
20208 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20209
20210 inst.instruction = 0xe000b10;
20211 do_vfp_cond_or_thumb ();
20212 inst.instruction |= LOW4 (dn) << 16;
20213 inst.instruction |= HI1 (dn) << 7;
20214 inst.instruction |= inst.operands[1].reg << 12;
20215 inst.instruction |= (bcdebits & 3) << 5;
20216 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20217 inst.instruction |= (x >> (3-logsize)) << 16;
20218 }
20219 break;
20220
20221 case NS_DRR: /* case 5 (fmdrr). */
20222 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20223 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20224 _(BAD_FPU));
20225
20226 inst.instruction = 0xc400b10;
20227 do_vfp_cond_or_thumb ();
20228 inst.instruction |= LOW4 (inst.operands[0].reg);
20229 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20230 inst.instruction |= inst.operands[1].reg << 12;
20231 inst.instruction |= inst.operands[2].reg << 16;
20232 break;
20233
20234 case NS_RS: /* case 6. */
20235 {
20236 unsigned logsize;
20237 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20238 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20239 unsigned abcdebits = 0;
20240
20241 /* .<dt> is optional here, defaulting to .32. */
20242 if (inst.vectype.elems == 0
20243 && inst.operands[0].vectype.type == NT_invtype
20244 && inst.operands[1].vectype.type == NT_invtype)
20245 {
20246 inst.vectype.el[0].type = NT_untyped;
20247 inst.vectype.el[0].size = 32;
20248 inst.vectype.elems = 1;
20249 }
20250
20251 et = neon_check_type (2, NS_NULL,
20252 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
20253 logsize = neon_logbits (et.size);
20254
20255 if (et.size != 32)
20256 {
20257 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20258 && vfp_or_neon_is_neon (NEON_CHECK_CC
20259 | NEON_CHECK_ARCH) == FAIL)
20260 return;
20261 }
20262 else
20263 {
20264 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20265 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20266 _(BAD_FPU));
20267 }
20268
20269 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20270 {
20271 if (inst.operands[0].reg == REG_SP)
20272 as_tsktsk (MVE_BAD_SP);
20273 else if (inst.operands[0].reg == REG_PC)
20274 as_tsktsk (MVE_BAD_PC);
20275 }
20276
20277 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20278
20279 constraint (et.type == NT_invtype, _("bad type for scalar"));
20280 constraint (x >= size / et.size, _("scalar index out of range"));
20281
20282 switch (et.size)
20283 {
20284 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20285 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20286 case 32: abcdebits = 0x00; break;
20287 default: ;
20288 }
20289
20290 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20291 inst.instruction = 0xe100b10;
20292 do_vfp_cond_or_thumb ();
20293 inst.instruction |= LOW4 (dn) << 16;
20294 inst.instruction |= HI1 (dn) << 7;
20295 inst.instruction |= inst.operands[0].reg << 12;
20296 inst.instruction |= (abcdebits & 3) << 5;
20297 inst.instruction |= (abcdebits >> 2) << 21;
20298 inst.instruction |= (x >> (3-logsize)) << 16;
20299 }
20300 break;
20301
20302 case NS_RRD: /* case 7 (fmrrd). */
20303 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20304 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20305 _(BAD_FPU));
20306
20307 inst.instruction = 0xc500b10;
20308 do_vfp_cond_or_thumb ();
20309 inst.instruction |= inst.operands[0].reg << 12;
20310 inst.instruction |= inst.operands[1].reg << 16;
20311 inst.instruction |= LOW4 (inst.operands[2].reg);
20312 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20313 break;
20314
20315 case NS_FF: /* case 8 (fcpys). */
20316 do_vfp_nsyn_opcode ("fcpys");
20317 break;
20318
20319 case NS_HI:
20320 case NS_FI: /* case 10 (fconsts). */
20321 ldconst = "fconsts";
20322 encode_fconstd:
20323 if (!inst.operands[1].immisfloat)
20324 {
20325 unsigned new_imm;
20326 /* Immediate has to fit in 8 bits so float is enough. */
20327 float imm = (float) inst.operands[1].imm;
20328 memcpy (&new_imm, &imm, sizeof (float));
20329 /* But the assembly may have been written to provide an integer
20330 bit pattern that equates to a float, so check that the
20331 conversion has worked. */
20332 if (is_quarter_float (new_imm))
20333 {
20334 if (is_quarter_float (inst.operands[1].imm))
20335 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20336
20337 inst.operands[1].imm = new_imm;
20338 inst.operands[1].immisfloat = 1;
20339 }
20340 }
20341
20342 if (is_quarter_float (inst.operands[1].imm))
20343 {
20344 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20345 do_vfp_nsyn_opcode (ldconst);
20346
20347 /* ARMv8.2 fp16 vmov.f16 instruction. */
20348 if (rs == NS_HI)
20349 do_scalar_fp16_v82_encode ();
20350 }
20351 else
20352 first_error (_("immediate out of range"));
20353 break;
20354
20355 case NS_RH:
20356 case NS_RF: /* case 12 (fmrs). */
20357 do_vfp_nsyn_opcode ("fmrs");
20358 /* ARMv8.2 fp16 vmov.f16 instruction. */
20359 if (rs == NS_RH)
20360 do_scalar_fp16_v82_encode ();
20361 break;
20362
20363 case NS_HR:
20364 case NS_FR: /* case 13 (fmsr). */
20365 do_vfp_nsyn_opcode ("fmsr");
20366 /* ARMv8.2 fp16 vmov.f16 instruction. */
20367 if (rs == NS_HR)
20368 do_scalar_fp16_v82_encode ();
20369 break;
20370
20371 case NS_RRSS:
20372 do_mve_mov (0);
20373 break;
20374 case NS_SSRR:
20375 do_mve_mov (1);
20376 break;
20377
20378 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20379 (one of which is a list), but we have parsed four. Do some fiddling to
20380 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20381 expect. */
20382 case NS_RRFF: /* case 14 (fmrrs). */
20383 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20384 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20385 _(BAD_FPU));
20386 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
20387 _("VFP registers must be adjacent"));
20388 inst.operands[2].imm = 2;
20389 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20390 do_vfp_nsyn_opcode ("fmrrs");
20391 break;
20392
20393 case NS_FFRR: /* case 15 (fmsrr). */
20394 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20395 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20396 _(BAD_FPU));
20397 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
20398 _("VFP registers must be adjacent"));
20399 inst.operands[1] = inst.operands[2];
20400 inst.operands[2] = inst.operands[3];
20401 inst.operands[0].imm = 2;
20402 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20403 do_vfp_nsyn_opcode ("fmsrr");
20404 break;
20405
20406 case NS_NULL:
20407 /* neon_select_shape has determined that the instruction
20408 shape is wrong and has already set the error message. */
20409 break;
20410
20411 default:
20412 abort ();
20413 }
20414 }
20415
20416 static void
20417 do_mve_movl (void)
20418 {
20419 if (!(inst.operands[0].present && inst.operands[0].isquad
20420 && inst.operands[1].present && inst.operands[1].isquad
20421 && !inst.operands[2].present))
20422 {
20423 inst.instruction = 0;
20424 inst.cond = 0xb;
20425 if (thumb_mode)
20426 set_pred_insn_type (INSIDE_IT_INSN);
20427 do_neon_mov ();
20428 return;
20429 }
20430
20431 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20432 return;
20433
20434 if (inst.cond != COND_ALWAYS)
20435 inst.pred_insn_type = INSIDE_VPT_INSN;
20436
20437 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20438 | N_S16 | N_U16 | N_KEY);
20439
20440 inst.instruction |= (et.type == NT_unsigned) << 28;
20441 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20442 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20443 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20444 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20445 inst.instruction |= LOW4 (inst.operands[1].reg);
20446 inst.is_neon = 1;
20447 }
20448
20449 static void
20450 do_neon_rshift_round_imm (void)
20451 {
20452 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
20453 return;
20454
20455 enum neon_shape rs;
20456 struct neon_type_el et;
20457
20458 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20459 {
20460 rs = neon_select_shape (NS_QQI, NS_NULL);
20461 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20462 }
20463 else
20464 {
20465 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20466 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20467 }
20468 int imm = inst.operands[2].imm;
20469
20470 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20471 if (imm == 0)
20472 {
20473 inst.operands[2].present = 0;
20474 do_neon_mov ();
20475 return;
20476 }
20477
20478 constraint (imm < 1 || (unsigned)imm > et.size,
20479 _("immediate out of range for shift"));
20480 neon_imm_shift (true, et.type == NT_unsigned, neon_quad (rs), et,
20481 et.size - imm);
20482 }
20483
20484 static void
20485 do_neon_movhf (void)
20486 {
20487 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20488 constraint (rs != NS_HH, _("invalid suffix"));
20489
20490 if (inst.cond != COND_ALWAYS)
20491 {
20492 if (thumb_mode)
20493 {
20494 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20495 " the behaviour is UNPREDICTABLE"));
20496 }
20497 else
20498 {
20499 inst.error = BAD_COND;
20500 return;
20501 }
20502 }
20503
20504 do_vfp_sp_monadic ();
20505
20506 inst.is_neon = 1;
20507 inst.instruction |= 0xf0000000;
20508 }
20509
20510 static void
20511 do_neon_movl (void)
20512 {
20513 struct neon_type_el et = neon_check_type (2, NS_QD,
20514 N_EQK | N_DBL, N_SU_32 | N_KEY);
20515 unsigned sizebits = et.size >> 3;
20516 inst.instruction |= sizebits << 19;
20517 neon_two_same (0, et.type == NT_unsigned, -1);
20518 }
20519
20520 static void
20521 do_neon_trn (void)
20522 {
20523 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20524 struct neon_type_el et = neon_check_type (2, rs,
20525 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20526 NEON_ENCODE (INTEGER, inst);
20527 neon_two_same (neon_quad (rs), 1, et.size);
20528 }
20529
20530 static void
20531 do_neon_zip_uzp (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 if (rs == NS_DD && et.size == 32)
20537 {
20538 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20539 inst.instruction = N_MNEM_vtrn;
20540 do_neon_trn ();
20541 return;
20542 }
20543 neon_two_same (neon_quad (rs), 1, et.size);
20544 }
20545
20546 static void
20547 do_neon_sat_abs_neg (void)
20548 {
20549 if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH))
20550 return;
20551
20552 enum neon_shape rs;
20553 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20554 rs = neon_select_shape (NS_QQ, NS_NULL);
20555 else
20556 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20557 struct neon_type_el et = neon_check_type (2, rs,
20558 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20559 neon_two_same (neon_quad (rs), 1, et.size);
20560 }
20561
20562 static void
20563 do_neon_pair_long (void)
20564 {
20565 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20566 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20567 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20568 inst.instruction |= (et.type == NT_unsigned) << 7;
20569 neon_two_same (neon_quad (rs), 1, et.size);
20570 }
20571
20572 static void
20573 do_neon_recip_est (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,
20577 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
20578 inst.instruction |= (et.type == NT_float) << 8;
20579 neon_two_same (neon_quad (rs), 1, et.size);
20580 }
20581
20582 static void
20583 do_neon_cls (void)
20584 {
20585 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
20586 return;
20587
20588 enum neon_shape rs;
20589 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20590 rs = neon_select_shape (NS_QQ, NS_NULL);
20591 else
20592 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20593
20594 struct neon_type_el et = neon_check_type (2, rs,
20595 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20596 neon_two_same (neon_quad (rs), 1, et.size);
20597 }
20598
20599 static void
20600 do_neon_clz (void)
20601 {
20602 if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC))
20603 return;
20604
20605 enum neon_shape rs;
20606 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20607 rs = neon_select_shape (NS_QQ, NS_NULL);
20608 else
20609 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20610
20611 struct neon_type_el et = neon_check_type (2, rs,
20612 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
20613 neon_two_same (neon_quad (rs), 1, et.size);
20614 }
20615
20616 static void
20617 do_neon_cnt (void)
20618 {
20619 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20620 struct neon_type_el et = neon_check_type (2, rs,
20621 N_EQK | N_INT, N_8 | N_KEY);
20622 neon_two_same (neon_quad (rs), 1, et.size);
20623 }
20624
20625 static void
20626 do_neon_swp (void)
20627 {
20628 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20629 if (rs == NS_NULL)
20630 return;
20631 neon_two_same (neon_quad (rs), 1, -1);
20632 }
20633
20634 static void
20635 do_neon_tbl_tbx (void)
20636 {
20637 unsigned listlenbits;
20638 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
20639
20640 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20641 {
20642 first_error (_("bad list length for table lookup"));
20643 return;
20644 }
20645
20646 listlenbits = inst.operands[1].imm - 1;
20647 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20648 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20649 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20650 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20651 inst.instruction |= LOW4 (inst.operands[2].reg);
20652 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20653 inst.instruction |= listlenbits << 8;
20654
20655 neon_dp_fixup (&inst);
20656 }
20657
20658 static void
20659 do_neon_ldm_stm (void)
20660 {
20661 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
20662 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20663 _(BAD_FPU));
20664 /* P, U and L bits are part of bitmask. */
20665 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20666 unsigned offsetbits = inst.operands[1].imm * 2;
20667
20668 if (inst.operands[1].issingle)
20669 {
20670 do_vfp_nsyn_ldm_stm (is_dbmode);
20671 return;
20672 }
20673
20674 constraint (is_dbmode && !inst.operands[0].writeback,
20675 _("writeback (!) must be used for VLDMDB and VSTMDB"));
20676
20677 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20678 _("register list must contain at least 1 and at most 16 "
20679 "registers"));
20680
20681 inst.instruction |= inst.operands[0].reg << 16;
20682 inst.instruction |= inst.operands[0].writeback << 21;
20683 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20684 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20685
20686 inst.instruction |= offsetbits;
20687
20688 do_vfp_cond_or_thumb ();
20689 }
20690
20691 static void
20692 do_vfp_nsyn_pop (void)
20693 {
20694 nsyn_insert_sp ();
20695 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20696 return do_vfp_nsyn_opcode ("vldm");
20697 }
20698
20699 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20700 _(BAD_FPU));
20701
20702 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20703 _("register list must contain at least 1 and at most 16 "
20704 "registers"));
20705
20706 if (inst.operands[1].issingle)
20707 do_vfp_nsyn_opcode ("fldmias");
20708 else
20709 do_vfp_nsyn_opcode ("fldmiad");
20710 }
20711
20712 static void
20713 do_vfp_nsyn_push (void)
20714 {
20715 nsyn_insert_sp ();
20716 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) {
20717 return do_vfp_nsyn_opcode ("vstmdb");
20718 }
20719
20720 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
20721 _(BAD_FPU));
20722
20723 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20724 _("register list must contain at least 1 and at most 16 "
20725 "registers"));
20726
20727 if (inst.operands[1].issingle)
20728 do_vfp_nsyn_opcode ("fstmdbs");
20729 else
20730 do_vfp_nsyn_opcode ("fstmdbd");
20731 }
20732
20733
20734 static void
20735 do_neon_ldr_str (void)
20736 {
20737 int is_ldr = (inst.instruction & (1 << 20)) != 0;
20738
20739 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20740 And is UNPREDICTABLE in thumb mode. */
20741 if (!is_ldr
20742 && inst.operands[1].reg == REG_PC
20743 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
20744 {
20745 if (thumb_mode)
20746 inst.error = _("Use of PC here is UNPREDICTABLE");
20747 else if (warn_on_deprecated)
20748 as_tsktsk (_("Use of PC here is deprecated"));
20749 }
20750
20751 if (inst.operands[0].issingle)
20752 {
20753 if (is_ldr)
20754 do_vfp_nsyn_opcode ("flds");
20755 else
20756 do_vfp_nsyn_opcode ("fsts");
20757
20758 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20759 if (inst.vectype.el[0].size == 16)
20760 do_scalar_fp16_v82_encode ();
20761 }
20762 else
20763 {
20764 if (is_ldr)
20765 do_vfp_nsyn_opcode ("fldd");
20766 else
20767 do_vfp_nsyn_opcode ("fstd");
20768 }
20769 }
20770
20771 static void
20772 do_t_vldr_vstr_sysreg (void)
20773 {
20774 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20775 bool is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20776
20777 /* Use of PC is UNPREDICTABLE. */
20778 if (inst.operands[1].reg == REG_PC)
20779 inst.error = _("Use of PC here is UNPREDICTABLE");
20780
20781 if (inst.operands[1].immisreg)
20782 inst.error = _("instruction does not accept register index");
20783
20784 if (!inst.operands[1].isreg)
20785 inst.error = _("instruction does not accept PC-relative addressing");
20786
20787 if (abs (inst.operands[1].imm) >= (1 << 7))
20788 inst.error = _("immediate value out of range");
20789
20790 inst.instruction = 0xec000f80;
20791 if (is_vldr)
20792 inst.instruction |= 1 << sysreg_vldr_bitno;
20793 encode_arm_cp_address (1, true, false, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20794 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20795 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20796 }
20797
20798 static void
20799 do_vldr_vstr (void)
20800 {
20801 bool sysreg_op = !inst.operands[0].isreg;
20802
20803 /* VLDR/VSTR (System Register). */
20804 if (sysreg_op)
20805 {
20806 if (!mark_feature_used (&arm_ext_v8_1m_main))
20807 as_bad (_("Instruction not permitted on this architecture"));
20808
20809 do_t_vldr_vstr_sysreg ();
20810 }
20811 /* VLDR/VSTR. */
20812 else
20813 {
20814 if (!mark_feature_used (&fpu_vfp_ext_v1xd)
20815 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20816 as_bad (_("Instruction not permitted on this architecture"));
20817 do_neon_ldr_str ();
20818 }
20819 }
20820
20821 /* "interleave" version also handles non-interleaving register VLD1/VST1
20822 instructions. */
20823
20824 static void
20825 do_neon_ld_st_interleave (void)
20826 {
20827 struct neon_type_el et = neon_check_type (1, NS_NULL,
20828 N_8 | N_16 | N_32 | N_64);
20829 unsigned alignbits = 0;
20830 unsigned idx;
20831 /* The bits in this table go:
20832 0: register stride of one (0) or two (1)
20833 1,2: register list length, minus one (1, 2, 3, 4).
20834 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20835 We use -1 for invalid entries. */
20836 const int typetable[] =
20837 {
20838 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20839 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20840 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20841 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20842 };
20843 int typebits;
20844
20845 if (et.type == NT_invtype)
20846 return;
20847
20848 if (inst.operands[1].immisalign)
20849 switch (inst.operands[1].imm >> 8)
20850 {
20851 case 64: alignbits = 1; break;
20852 case 128:
20853 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
20854 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20855 goto bad_alignment;
20856 alignbits = 2;
20857 break;
20858 case 256:
20859 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20860 goto bad_alignment;
20861 alignbits = 3;
20862 break;
20863 default:
20864 bad_alignment:
20865 first_error (_("bad alignment"));
20866 return;
20867 }
20868
20869 inst.instruction |= alignbits << 4;
20870 inst.instruction |= neon_logbits (et.size) << 6;
20871
20872 /* Bits [4:6] of the immediate in a list specifier encode register stride
20873 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20874 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20875 up the right value for "type" in a table based on this value and the given
20876 list style, then stick it back. */
20877 idx = ((inst.operands[0].imm >> 4) & 7)
20878 | (((inst.instruction >> 8) & 3) << 3);
20879
20880 typebits = typetable[idx];
20881
20882 constraint (typebits == -1, _("bad list type for instruction"));
20883 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
20884 BAD_EL_TYPE);
20885
20886 inst.instruction &= ~0xf00;
20887 inst.instruction |= typebits << 8;
20888 }
20889
20890 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20891 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20892 otherwise. The variable arguments are a list of pairs of legal (size, align)
20893 values, terminated with -1. */
20894
20895 static int
20896 neon_alignment_bit (int size, int align, int *do_alignment, ...)
20897 {
20898 va_list ap;
20899 int result = FAIL, thissize, thisalign;
20900
20901 if (!inst.operands[1].immisalign)
20902 {
20903 *do_alignment = 0;
20904 return SUCCESS;
20905 }
20906
20907 va_start (ap, do_alignment);
20908
20909 do
20910 {
20911 thissize = va_arg (ap, int);
20912 if (thissize == -1)
20913 break;
20914 thisalign = va_arg (ap, int);
20915
20916 if (size == thissize && align == thisalign)
20917 result = SUCCESS;
20918 }
20919 while (result != SUCCESS);
20920
20921 va_end (ap);
20922
20923 if (result == SUCCESS)
20924 *do_alignment = 1;
20925 else
20926 first_error (_("unsupported alignment for instruction"));
20927
20928 return result;
20929 }
20930
20931 static void
20932 do_neon_ld_st_lane (void)
20933 {
20934 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20935 int align_good, do_alignment = 0;
20936 int logsize = neon_logbits (et.size);
20937 int align = inst.operands[1].imm >> 8;
20938 int n = (inst.instruction >> 8) & 3;
20939 int max_el = 64 / et.size;
20940
20941 if (et.type == NT_invtype)
20942 return;
20943
20944 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
20945 _("bad list length"));
20946 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
20947 _("scalar index out of range"));
20948 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
20949 && et.size == 8,
20950 _("stride of 2 unavailable when element size is 8"));
20951
20952 switch (n)
20953 {
20954 case 0: /* VLD1 / VST1. */
20955 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
20956 32, 32, -1);
20957 if (align_good == FAIL)
20958 return;
20959 if (do_alignment)
20960 {
20961 unsigned alignbits = 0;
20962 switch (et.size)
20963 {
20964 case 16: alignbits = 0x1; break;
20965 case 32: alignbits = 0x3; break;
20966 default: ;
20967 }
20968 inst.instruction |= alignbits << 4;
20969 }
20970 break;
20971
20972 case 1: /* VLD2 / VST2. */
20973 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20974 16, 32, 32, 64, -1);
20975 if (align_good == FAIL)
20976 return;
20977 if (do_alignment)
20978 inst.instruction |= 1 << 4;
20979 break;
20980
20981 case 2: /* VLD3 / VST3. */
20982 constraint (inst.operands[1].immisalign,
20983 _("can't use alignment with this instruction"));
20984 break;
20985
20986 case 3: /* VLD4 / VST4. */
20987 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
20988 16, 64, 32, 64, 32, 128, -1);
20989 if (align_good == FAIL)
20990 return;
20991 if (do_alignment)
20992 {
20993 unsigned alignbits = 0;
20994 switch (et.size)
20995 {
20996 case 8: alignbits = 0x1; break;
20997 case 16: alignbits = 0x1; break;
20998 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
20999 default: ;
21000 }
21001 inst.instruction |= alignbits << 4;
21002 }
21003 break;
21004
21005 default: ;
21006 }
21007
21008 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
21009 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21010 inst.instruction |= 1 << (4 + logsize);
21011
21012 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
21013 inst.instruction |= logsize << 10;
21014 }
21015
21016 /* Encode single n-element structure to all lanes VLD<n> instructions. */
21017
21018 static void
21019 do_neon_ld_dup (void)
21020 {
21021 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
21022 int align_good, do_alignment = 0;
21023
21024 if (et.type == NT_invtype)
21025 return;
21026
21027 switch ((inst.instruction >> 8) & 3)
21028 {
21029 case 0: /* VLD1. */
21030 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
21031 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
21032 &do_alignment, 16, 16, 32, 32, -1);
21033 if (align_good == FAIL)
21034 return;
21035 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
21036 {
21037 case 1: break;
21038 case 2: inst.instruction |= 1 << 5; break;
21039 default: first_error (_("bad list length")); return;
21040 }
21041 inst.instruction |= neon_logbits (et.size) << 6;
21042 break;
21043
21044 case 1: /* VLD2. */
21045 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
21046 &do_alignment, 8, 16, 16, 32, 32, 64,
21047 -1);
21048 if (align_good == FAIL)
21049 return;
21050 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
21051 _("bad list length"));
21052 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21053 inst.instruction |= 1 << 5;
21054 inst.instruction |= neon_logbits (et.size) << 6;
21055 break;
21056
21057 case 2: /* VLD3. */
21058 constraint (inst.operands[1].immisalign,
21059 _("can't use alignment with this instruction"));
21060 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
21061 _("bad list length"));
21062 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21063 inst.instruction |= 1 << 5;
21064 inst.instruction |= neon_logbits (et.size) << 6;
21065 break;
21066
21067 case 3: /* VLD4. */
21068 {
21069 int align = inst.operands[1].imm >> 8;
21070 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
21071 16, 64, 32, 64, 32, 128, -1);
21072 if (align_good == FAIL)
21073 return;
21074 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
21075 _("bad list length"));
21076 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
21077 inst.instruction |= 1 << 5;
21078 if (et.size == 32 && align == 128)
21079 inst.instruction |= 0x3 << 6;
21080 else
21081 inst.instruction |= neon_logbits (et.size) << 6;
21082 }
21083 break;
21084
21085 default: ;
21086 }
21087
21088 inst.instruction |= do_alignment << 4;
21089 }
21090
21091 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
21092 apart from bits [11:4]. */
21093
21094 static void
21095 do_neon_ldx_stx (void)
21096 {
21097 if (inst.operands[1].isreg)
21098 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
21099
21100 switch (NEON_LANE (inst.operands[0].imm))
21101 {
21102 case NEON_INTERLEAVE_LANES:
21103 NEON_ENCODE (INTERLV, inst);
21104 do_neon_ld_st_interleave ();
21105 break;
21106
21107 case NEON_ALL_LANES:
21108 NEON_ENCODE (DUP, inst);
21109 if (inst.instruction == N_INV)
21110 {
21111 first_error ("only loads support such operands");
21112 break;
21113 }
21114 do_neon_ld_dup ();
21115 break;
21116
21117 default:
21118 NEON_ENCODE (LANE, inst);
21119 do_neon_ld_st_lane ();
21120 }
21121
21122 /* L bit comes from bit mask. */
21123 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21124 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21125 inst.instruction |= inst.operands[1].reg << 16;
21126
21127 if (inst.operands[1].postind)
21128 {
21129 int postreg = inst.operands[1].imm & 0xf;
21130 constraint (!inst.operands[1].immisreg,
21131 _("post-index must be a register"));
21132 constraint (postreg == 0xd || postreg == 0xf,
21133 _("bad register for post-index"));
21134 inst.instruction |= postreg;
21135 }
21136 else
21137 {
21138 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
21139 constraint (inst.relocs[0].exp.X_op != O_constant
21140 || inst.relocs[0].exp.X_add_number != 0,
21141 BAD_ADDR_MODE);
21142
21143 if (inst.operands[1].writeback)
21144 {
21145 inst.instruction |= 0xd;
21146 }
21147 else
21148 inst.instruction |= 0xf;
21149 }
21150
21151 if (thumb_mode)
21152 inst.instruction |= 0xf9000000;
21153 else
21154 inst.instruction |= 0xf4000000;
21155 }
21156
21157 /* FP v8. */
21158 static void
21159 do_vfp_nsyn_fpv8 (enum neon_shape rs)
21160 {
21161 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21162 D register operands. */
21163 if (neon_shape_class[rs] == SC_DOUBLE)
21164 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21165 _(BAD_FPU));
21166
21167 NEON_ENCODE (FPV8, inst);
21168
21169 if (rs == NS_FFF || rs == NS_HHH)
21170 {
21171 do_vfp_sp_dyadic ();
21172
21173 /* ARMv8.2 fp16 instruction. */
21174 if (rs == NS_HHH)
21175 do_scalar_fp16_v82_encode ();
21176 }
21177 else
21178 do_vfp_dp_rd_rn_rm ();
21179
21180 if (rs == NS_DDD)
21181 inst.instruction |= 0x100;
21182
21183 inst.instruction |= 0xf0000000;
21184 }
21185
21186 static void
21187 do_vsel (void)
21188 {
21189 set_pred_insn_type (OUTSIDE_PRED_INSN);
21190
21191 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
21192 first_error (_("invalid instruction shape"));
21193 }
21194
21195 static void
21196 do_vmaxnm (void)
21197 {
21198 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21199 set_pred_insn_type (OUTSIDE_PRED_INSN);
21200
21201 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
21202 return;
21203
21204 if (!check_simd_pred_availability (true, NEON_CHECK_CC | NEON_CHECK_ARCH8))
21205 return;
21206
21207 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
21208 }
21209
21210 static void
21211 do_vrint_1 (enum neon_cvt_mode mode)
21212 {
21213 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
21214 struct neon_type_el et;
21215
21216 if (rs == NS_NULL)
21217 return;
21218
21219 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
21220 D register operands. */
21221 if (neon_shape_class[rs] == SC_DOUBLE)
21222 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21223 _(BAD_FPU));
21224
21225 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
21226 | N_VFP);
21227 if (et.type != NT_invtype)
21228 {
21229 /* VFP encodings. */
21230 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
21231 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
21232 set_pred_insn_type (OUTSIDE_PRED_INSN);
21233
21234 NEON_ENCODE (FPV8, inst);
21235 if (rs == NS_FF || rs == NS_HH)
21236 do_vfp_sp_monadic ();
21237 else
21238 do_vfp_dp_rd_rm ();
21239
21240 switch (mode)
21241 {
21242 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
21243 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
21244 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
21245 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
21246 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21247 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21248 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21249 default: abort ();
21250 }
21251
21252 inst.instruction |= (rs == NS_DD) << 8;
21253 do_vfp_cond_or_thumb ();
21254
21255 /* ARMv8.2 fp16 vrint instruction. */
21256 if (rs == NS_HH)
21257 do_scalar_fp16_v82_encode ();
21258 }
21259 else
21260 {
21261 /* Neon encodings (or something broken...). */
21262 inst.error = NULL;
21263 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
21264
21265 if (et.type == NT_invtype)
21266 return;
21267
21268 if (!check_simd_pred_availability (true,
21269 NEON_CHECK_CC | NEON_CHECK_ARCH8))
21270 return;
21271
21272 NEON_ENCODE (FLOAT, inst);
21273
21274 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21275 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21276 inst.instruction |= LOW4 (inst.operands[1].reg);
21277 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21278 inst.instruction |= neon_quad (rs) << 6;
21279 /* Mask off the original size bits and reencode them. */
21280 inst.instruction = ((inst.instruction & 0xfff3ffff)
21281 | neon_logbits (et.size) << 18);
21282
21283 switch (mode)
21284 {
21285 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21286 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21287 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21288 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21289 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21290 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21291 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21292 default: abort ();
21293 }
21294
21295 if (thumb_mode)
21296 inst.instruction |= 0xfc000000;
21297 else
21298 inst.instruction |= 0xf0000000;
21299 }
21300 }
21301
21302 static void
21303 do_vrintx (void)
21304 {
21305 do_vrint_1 (neon_cvt_mode_x);
21306 }
21307
21308 static void
21309 do_vrintz (void)
21310 {
21311 do_vrint_1 (neon_cvt_mode_z);
21312 }
21313
21314 static void
21315 do_vrintr (void)
21316 {
21317 do_vrint_1 (neon_cvt_mode_r);
21318 }
21319
21320 static void
21321 do_vrinta (void)
21322 {
21323 do_vrint_1 (neon_cvt_mode_a);
21324 }
21325
21326 static void
21327 do_vrintn (void)
21328 {
21329 do_vrint_1 (neon_cvt_mode_n);
21330 }
21331
21332 static void
21333 do_vrintp (void)
21334 {
21335 do_vrint_1 (neon_cvt_mode_p);
21336 }
21337
21338 static void
21339 do_vrintm (void)
21340 {
21341 do_vrint_1 (neon_cvt_mode_m);
21342 }
21343
21344 static unsigned
21345 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21346 {
21347 unsigned regno = NEON_SCALAR_REG (opnd);
21348 unsigned elno = NEON_SCALAR_INDEX (opnd);
21349
21350 if (elsize == 16 && elno < 2 && regno < 16)
21351 return regno | (elno << 4);
21352 else if (elsize == 32 && elno == 0)
21353 return regno;
21354
21355 first_error (_("scalar out of range"));
21356 return 0;
21357 }
21358
21359 static void
21360 do_vcmla (void)
21361 {
21362 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21363 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21364 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21365 constraint (inst.relocs[0].exp.X_op != O_constant,
21366 _("expression too complex"));
21367 unsigned rot = inst.relocs[0].exp.X_add_number;
21368 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21369 _("immediate out of range"));
21370 rot /= 90;
21371
21372 if (!check_simd_pred_availability (true,
21373 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21374 return;
21375
21376 if (inst.operands[2].isscalar)
21377 {
21378 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21379 first_error (_("invalid instruction shape"));
21380 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21381 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21382 N_KEY | N_F16 | N_F32).size;
21383 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21384 inst.is_neon = 1;
21385 inst.instruction = 0xfe000800;
21386 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21387 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21388 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21389 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21390 inst.instruction |= LOW4 (m);
21391 inst.instruction |= HI1 (m) << 5;
21392 inst.instruction |= neon_quad (rs) << 6;
21393 inst.instruction |= rot << 20;
21394 inst.instruction |= (size == 32) << 23;
21395 }
21396 else
21397 {
21398 enum neon_shape rs;
21399 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21400 rs = neon_select_shape (NS_QQQI, NS_NULL);
21401 else
21402 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21403
21404 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21405 N_KEY | N_F16 | N_F32).size;
21406 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21407 && (inst.operands[0].reg == inst.operands[1].reg
21408 || inst.operands[0].reg == inst.operands[2].reg))
21409 as_tsktsk (BAD_MVE_SRCDEST);
21410
21411 neon_three_same (neon_quad (rs), 0, -1);
21412 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21413 inst.instruction |= 0xfc200800;
21414 inst.instruction |= rot << 23;
21415 inst.instruction |= (size == 32) << 20;
21416 }
21417 }
21418
21419 static void
21420 do_vcadd (void)
21421 {
21422 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21423 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21424 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21425 constraint (inst.relocs[0].exp.X_op != O_constant,
21426 _("expression too complex"));
21427
21428 unsigned rot = inst.relocs[0].exp.X_add_number;
21429 constraint (rot != 90 && rot != 270, _("immediate out of range"));
21430 enum neon_shape rs;
21431 struct neon_type_el et;
21432 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21433 {
21434 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21435 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21436 }
21437 else
21438 {
21439 rs = neon_select_shape (NS_QQQI, NS_NULL);
21440 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21441 | N_I16 | N_I32);
21442 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21443 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21444 "operand makes instruction UNPREDICTABLE"));
21445 }
21446
21447 if (et.type == NT_invtype)
21448 return;
21449
21450 if (!check_simd_pred_availability (et.type == NT_float,
21451 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21452 return;
21453
21454 if (et.type == NT_float)
21455 {
21456 neon_three_same (neon_quad (rs), 0, -1);
21457 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21458 inst.instruction |= 0xfc800800;
21459 inst.instruction |= (rot == 270) << 24;
21460 inst.instruction |= (et.size == 32) << 20;
21461 }
21462 else
21463 {
21464 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21465 inst.instruction = 0xfe000f00;
21466 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21467 inst.instruction |= neon_logbits (et.size) << 20;
21468 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21469 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21470 inst.instruction |= (rot == 270) << 12;
21471 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21472 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21473 inst.instruction |= LOW4 (inst.operands[2].reg);
21474 inst.is_neon = 1;
21475 }
21476 }
21477
21478 /* Dot Product instructions encoding support. */
21479
21480 static void
21481 do_neon_dotproduct (int unsigned_p)
21482 {
21483 enum neon_shape rs;
21484 unsigned scalar_oprd2 = 0;
21485 int high8;
21486
21487 if (inst.cond != COND_ALWAYS)
21488 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21489 "is UNPREDICTABLE"));
21490
21491 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21492 _(BAD_FPU));
21493
21494 /* Dot Product instructions are in three-same D/Q register format or the third
21495 operand can be a scalar index register. */
21496 if (inst.operands[2].isscalar)
21497 {
21498 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21499 high8 = 0xfe000000;
21500 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21501 }
21502 else
21503 {
21504 high8 = 0xfc000000;
21505 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21506 }
21507
21508 if (unsigned_p)
21509 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21510 else
21511 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21512
21513 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21514 Product instruction, so we pass 0 as the "ubit" parameter. And the
21515 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21516 neon_three_same (neon_quad (rs), 0, 32);
21517
21518 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21519 different NEON three-same encoding. */
21520 inst.instruction &= 0x00ffffff;
21521 inst.instruction |= high8;
21522 /* Encode 'U' bit which indicates signedness. */
21523 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21524 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21525 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21526 the instruction encoding. */
21527 if (inst.operands[2].isscalar)
21528 {
21529 inst.instruction &= 0xffffffd0;
21530 inst.instruction |= LOW4 (scalar_oprd2);
21531 inst.instruction |= HI1 (scalar_oprd2) << 5;
21532 }
21533 }
21534
21535 /* Dot Product instructions for signed integer. */
21536
21537 static void
21538 do_neon_dotproduct_s (void)
21539 {
21540 return do_neon_dotproduct (0);
21541 }
21542
21543 /* Dot Product instructions for unsigned integer. */
21544
21545 static void
21546 do_neon_dotproduct_u (void)
21547 {
21548 return do_neon_dotproduct (1);
21549 }
21550
21551 static void
21552 do_vusdot (void)
21553 {
21554 enum neon_shape rs;
21555 set_pred_insn_type (OUTSIDE_PRED_INSN);
21556 if (inst.operands[2].isscalar)
21557 {
21558 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21559 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21560
21561 inst.instruction |= (1 << 25);
21562 int idx = inst.operands[2].reg & 0xf;
21563 constraint ((idx != 1 && idx != 0), _("index must be 0 or 1"));
21564 inst.operands[2].reg >>= 4;
21565 constraint (!(inst.operands[2].reg < 16),
21566 _("indexed register must be less than 16"));
21567 neon_three_args (rs == NS_QQS);
21568 inst.instruction |= (idx << 5);
21569 }
21570 else
21571 {
21572 inst.instruction |= (1 << 21);
21573 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21574 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21575 neon_three_args (rs == NS_QQQ);
21576 }
21577 }
21578
21579 static void
21580 do_vsudot (void)
21581 {
21582 enum neon_shape rs;
21583 set_pred_insn_type (OUTSIDE_PRED_INSN);
21584 if (inst.operands[2].isscalar)
21585 {
21586 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21587 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21588
21589 inst.instruction |= (1 << 25);
21590 int idx = inst.operands[2].reg & 0xf;
21591 constraint ((idx != 1 && idx != 0), _("index must be 0 or 1"));
21592 inst.operands[2].reg >>= 4;
21593 constraint (!(inst.operands[2].reg < 16),
21594 _("indexed register must be less than 16"));
21595 neon_three_args (rs == NS_QQS);
21596 inst.instruction |= (idx << 5);
21597 }
21598 }
21599
21600 static void
21601 do_vsmmla (void)
21602 {
21603 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21604 neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_KEY);
21605
21606 set_pred_insn_type (OUTSIDE_PRED_INSN);
21607
21608 neon_three_args (1);
21609
21610 }
21611
21612 static void
21613 do_vummla (void)
21614 {
21615 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
21616 neon_check_type (3, rs, N_EQK, N_EQK, N_U8 | N_KEY);
21617
21618 set_pred_insn_type (OUTSIDE_PRED_INSN);
21619
21620 neon_three_args (1);
21621
21622 }
21623
21624 static void
21625 check_cde_operand (size_t idx, int is_dual)
21626 {
21627 unsigned Rx = inst.operands[idx].reg;
21628 bool isvec = inst.operands[idx].isvec;
21629 if (is_dual == 0 && thumb_mode)
21630 constraint (
21631 !((Rx <= 14 && Rx != 13) || (Rx == REG_PC && isvec)),
21632 _("Register must be r0-r14 except r13, or APSR_nzcv."));
21633 else
21634 constraint ( !((Rx <= 10 && Rx % 2 == 0 )),
21635 _("Register must be an even register between r0-r10."));
21636 }
21637
21638 static bool
21639 cde_coproc_enabled (unsigned coproc)
21640 {
21641 switch (coproc)
21642 {
21643 case 0: return mark_feature_used (&arm_ext_cde0);
21644 case 1: return mark_feature_used (&arm_ext_cde1);
21645 case 2: return mark_feature_used (&arm_ext_cde2);
21646 case 3: return mark_feature_used (&arm_ext_cde3);
21647 case 4: return mark_feature_used (&arm_ext_cde4);
21648 case 5: return mark_feature_used (&arm_ext_cde5);
21649 case 6: return mark_feature_used (&arm_ext_cde6);
21650 case 7: return mark_feature_used (&arm_ext_cde7);
21651 default: return false;
21652 }
21653 }
21654
21655 #define cde_coproc_pos 8
21656 static void
21657 cde_handle_coproc (void)
21658 {
21659 unsigned coproc = inst.operands[0].reg;
21660 constraint (coproc > 7, _("CDE Coprocessor must be in range 0-7"));
21661 constraint (!(cde_coproc_enabled (coproc)), BAD_CDE_COPROC);
21662 inst.instruction |= coproc << cde_coproc_pos;
21663 }
21664 #undef cde_coproc_pos
21665
21666 static void
21667 cxn_handle_predication (bool is_accum)
21668 {
21669 if (is_accum && conditional_insn ())
21670 set_pred_insn_type (INSIDE_IT_INSN);
21671 else if (conditional_insn ())
21672 /* conditional_insn essentially checks for a suffix, not whether the
21673 instruction is inside an IT block or not.
21674 The non-accumulator versions should not have suffixes. */
21675 inst.error = BAD_SYNTAX;
21676 else
21677 set_pred_insn_type (OUTSIDE_PRED_INSN);
21678 }
21679
21680 static void
21681 do_custom_instruction_1 (int is_dual, bool is_accum)
21682 {
21683
21684 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21685
21686 unsigned imm, Rd;
21687
21688 Rd = inst.operands[1].reg;
21689 check_cde_operand (1, is_dual);
21690
21691 if (is_dual == 1)
21692 {
21693 constraint (inst.operands[2].reg != Rd + 1,
21694 _("cx1d requires consecutive destination registers."));
21695 imm = inst.operands[3].imm;
21696 }
21697 else if (is_dual == 0)
21698 imm = inst.operands[2].imm;
21699 else
21700 abort ();
21701
21702 inst.instruction |= Rd << 12;
21703 inst.instruction |= (imm & 0x1F80) << 9;
21704 inst.instruction |= (imm & 0x0040) << 1;
21705 inst.instruction |= (imm & 0x003f);
21706
21707 cde_handle_coproc ();
21708 cxn_handle_predication (is_accum);
21709 }
21710
21711 static void
21712 do_custom_instruction_2 (int is_dual, bool is_accum)
21713 {
21714
21715 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21716
21717 unsigned imm, Rd, Rn;
21718
21719 Rd = inst.operands[1].reg;
21720
21721 if (is_dual == 1)
21722 {
21723 constraint (inst.operands[2].reg != Rd + 1,
21724 _("cx2d requires consecutive destination registers."));
21725 imm = inst.operands[4].imm;
21726 Rn = inst.operands[3].reg;
21727 }
21728 else if (is_dual == 0)
21729 {
21730 imm = inst.operands[3].imm;
21731 Rn = inst.operands[2].reg;
21732 }
21733 else
21734 abort ();
21735
21736 check_cde_operand (2 + is_dual, /* is_dual = */0);
21737 check_cde_operand (1, is_dual);
21738
21739 inst.instruction |= Rd << 12;
21740 inst.instruction |= Rn << 16;
21741
21742 inst.instruction |= (imm & 0x0380) << 13;
21743 inst.instruction |= (imm & 0x0040) << 1;
21744 inst.instruction |= (imm & 0x003f);
21745
21746 cde_handle_coproc ();
21747 cxn_handle_predication (is_accum);
21748 }
21749
21750 static void
21751 do_custom_instruction_3 (int is_dual, bool is_accum)
21752 {
21753
21754 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
21755
21756 unsigned imm, Rd, Rn, Rm;
21757
21758 Rd = inst.operands[1].reg;
21759
21760 if (is_dual == 1)
21761 {
21762 constraint (inst.operands[2].reg != Rd + 1,
21763 _("cx3d requires consecutive destination registers."));
21764 imm = inst.operands[5].imm;
21765 Rn = inst.operands[3].reg;
21766 Rm = inst.operands[4].reg;
21767 }
21768 else if (is_dual == 0)
21769 {
21770 imm = inst.operands[4].imm;
21771 Rn = inst.operands[2].reg;
21772 Rm = inst.operands[3].reg;
21773 }
21774 else
21775 abort ();
21776
21777 check_cde_operand (1, is_dual);
21778 check_cde_operand (2 + is_dual, /* is_dual = */0);
21779 check_cde_operand (3 + is_dual, /* is_dual = */0);
21780
21781 inst.instruction |= Rd;
21782 inst.instruction |= Rn << 16;
21783 inst.instruction |= Rm << 12;
21784
21785 inst.instruction |= (imm & 0x0038) << 17;
21786 inst.instruction |= (imm & 0x0004) << 5;
21787 inst.instruction |= (imm & 0x0003) << 4;
21788
21789 cde_handle_coproc ();
21790 cxn_handle_predication (is_accum);
21791 }
21792
21793 static void
21794 do_cx1 (void)
21795 {
21796 return do_custom_instruction_1 (0, 0);
21797 }
21798
21799 static void
21800 do_cx1a (void)
21801 {
21802 return do_custom_instruction_1 (0, 1);
21803 }
21804
21805 static void
21806 do_cx1d (void)
21807 {
21808 return do_custom_instruction_1 (1, 0);
21809 }
21810
21811 static void
21812 do_cx1da (void)
21813 {
21814 return do_custom_instruction_1 (1, 1);
21815 }
21816
21817 static void
21818 do_cx2 (void)
21819 {
21820 return do_custom_instruction_2 (0, 0);
21821 }
21822
21823 static void
21824 do_cx2a (void)
21825 {
21826 return do_custom_instruction_2 (0, 1);
21827 }
21828
21829 static void
21830 do_cx2d (void)
21831 {
21832 return do_custom_instruction_2 (1, 0);
21833 }
21834
21835 static void
21836 do_cx2da (void)
21837 {
21838 return do_custom_instruction_2 (1, 1);
21839 }
21840
21841 static void
21842 do_cx3 (void)
21843 {
21844 return do_custom_instruction_3 (0, 0);
21845 }
21846
21847 static void
21848 do_cx3a (void)
21849 {
21850 return do_custom_instruction_3 (0, 1);
21851 }
21852
21853 static void
21854 do_cx3d (void)
21855 {
21856 return do_custom_instruction_3 (1, 0);
21857 }
21858
21859 static void
21860 do_cx3da (void)
21861 {
21862 return do_custom_instruction_3 (1, 1);
21863 }
21864
21865 static void
21866 vcx_assign_vec_d (unsigned regnum)
21867 {
21868 inst.instruction |= HI4 (regnum) << 12;
21869 inst.instruction |= LOW1 (regnum) << 22;
21870 }
21871
21872 static void
21873 vcx_assign_vec_m (unsigned regnum)
21874 {
21875 inst.instruction |= HI4 (regnum);
21876 inst.instruction |= LOW1 (regnum) << 5;
21877 }
21878
21879 static void
21880 vcx_assign_vec_n (unsigned regnum)
21881 {
21882 inst.instruction |= HI4 (regnum) << 16;
21883 inst.instruction |= LOW1 (regnum) << 7;
21884 }
21885
21886 enum vcx_reg_type {
21887 q_reg,
21888 d_reg,
21889 s_reg
21890 };
21891
21892 static enum vcx_reg_type
21893 vcx_get_reg_type (enum neon_shape ns)
21894 {
21895 gas_assert (ns == NS_PQI
21896 || ns == NS_PDI
21897 || ns == NS_PFI
21898 || ns == NS_PQQI
21899 || ns == NS_PDDI
21900 || ns == NS_PFFI
21901 || ns == NS_PQQQI
21902 || ns == NS_PDDDI
21903 || ns == NS_PFFFI);
21904 if (ns == NS_PQI || ns == NS_PQQI || ns == NS_PQQQI)
21905 return q_reg;
21906 if (ns == NS_PDI || ns == NS_PDDI || ns == NS_PDDDI)
21907 return d_reg;
21908 return s_reg;
21909 }
21910
21911 #define vcx_size_pos 24
21912 #define vcx_vec_pos 6
21913 static unsigned
21914 vcx_handle_shape (enum vcx_reg_type reg_type)
21915 {
21916 unsigned mult = 2;
21917 if (reg_type == q_reg)
21918 inst.instruction |= 1 << vcx_vec_pos;
21919 else if (reg_type == d_reg)
21920 inst.instruction |= 1 << vcx_size_pos;
21921 else
21922 mult = 1;
21923 /* NOTE:
21924 The documentation says that the Q registers are encoded as 2*N in the D:Vd
21925 bits (or equivalent for N and M registers).
21926 Similarly the D registers are encoded as N in D:Vd bits.
21927 While the S registers are encoded as N in the Vd:D bits.
21928
21929 Taking into account the maximum values of these registers we can see a
21930 nicer pattern for calculation:
21931 Q -> 7, D -> 15, S -> 31
21932
21933 If we say that everything is encoded in the Vd:D bits, then we can say
21934 that Q is encoded as 4*N, and D is encoded as 2*N.
21935 This way the bits will end up the same, and calculation is simpler.
21936 (calculation is now:
21937 1. Multiply by a number determined by the register letter.
21938 2. Encode resulting number in Vd:D bits.)
21939
21940 This is made a little more complicated by automatic handling of 'Q'
21941 registers elsewhere, which means the register number is already 2*N where
21942 N is the number the user wrote after the register letter.
21943 */
21944 return mult;
21945 }
21946 #undef vcx_vec_pos
21947 #undef vcx_size_pos
21948
21949 static void
21950 vcx_ensure_register_in_range (unsigned R, enum vcx_reg_type reg_type)
21951 {
21952 if (reg_type == q_reg)
21953 {
21954 gas_assert (R % 2 == 0);
21955 constraint (R >= 16, _("'q' register must be in range 0-7"));
21956 }
21957 else if (reg_type == d_reg)
21958 constraint (R >= 16, _("'d' register must be in range 0-15"));
21959 else
21960 constraint (R >= 32, _("'s' register must be in range 0-31"));
21961 }
21962
21963 static void (*vcx_assign_vec[3]) (unsigned) = {
21964 vcx_assign_vec_d,
21965 vcx_assign_vec_m,
21966 vcx_assign_vec_n
21967 };
21968
21969 static void
21970 vcx_handle_register_arguments (unsigned num_registers,
21971 enum vcx_reg_type reg_type)
21972 {
21973 unsigned R, i;
21974 unsigned reg_mult = vcx_handle_shape (reg_type);
21975 for (i = 0; i < num_registers; i++)
21976 {
21977 R = inst.operands[i+1].reg;
21978 vcx_ensure_register_in_range (R, reg_type);
21979 if (num_registers == 3 && i > 0)
21980 {
21981 if (i == 2)
21982 vcx_assign_vec[1] (R * reg_mult);
21983 else
21984 vcx_assign_vec[2] (R * reg_mult);
21985 continue;
21986 }
21987 vcx_assign_vec[i](R * reg_mult);
21988 }
21989 }
21990
21991 static void
21992 vcx_handle_insn_block (enum vcx_reg_type reg_type)
21993 {
21994 if (reg_type == q_reg)
21995 if (inst.cond > COND_ALWAYS)
21996 inst.pred_insn_type = INSIDE_VPT_INSN;
21997 else
21998 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
21999 else if (inst.cond == COND_ALWAYS)
22000 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22001 else
22002 inst.error = BAD_NOT_IT;
22003 }
22004
22005 static void
22006 vcx_handle_common_checks (unsigned num_args, enum neon_shape rs)
22007 {
22008 constraint (!mark_feature_used (&arm_ext_cde), _(BAD_CDE));
22009 cde_handle_coproc ();
22010 enum vcx_reg_type reg_type = vcx_get_reg_type (rs);
22011 vcx_handle_register_arguments (num_args, reg_type);
22012 vcx_handle_insn_block (reg_type);
22013 if (reg_type == q_reg)
22014 constraint (!mark_feature_used (&mve_ext),
22015 _("vcx instructions with Q registers require MVE"));
22016 else
22017 constraint (!(ARM_FSET_CPU_SUBSET (armv8m_fp, cpu_variant)
22018 && mark_feature_used (&armv8m_fp))
22019 && !mark_feature_used (&mve_ext),
22020 _("vcx instructions with S or D registers require either MVE"
22021 " or Armv8-M floating point extension."));
22022 }
22023
22024 static void
22025 do_vcx1 (void)
22026 {
22027 enum neon_shape rs = neon_select_shape (NS_PQI, NS_PDI, NS_PFI, NS_NULL);
22028 vcx_handle_common_checks (1, rs);
22029
22030 unsigned imm = inst.operands[2].imm;
22031 inst.instruction |= (imm & 0x03f);
22032 inst.instruction |= (imm & 0x040) << 1;
22033 inst.instruction |= (imm & 0x780) << 9;
22034 if (rs != NS_PQI)
22035 constraint (imm >= 2048,
22036 _("vcx1 with S or D registers takes immediate within 0-2047"));
22037 inst.instruction |= (imm & 0x800) << 13;
22038 }
22039
22040 static void
22041 do_vcx2 (void)
22042 {
22043 enum neon_shape rs = neon_select_shape (NS_PQQI, NS_PDDI, NS_PFFI, NS_NULL);
22044 vcx_handle_common_checks (2, rs);
22045
22046 unsigned imm = inst.operands[3].imm;
22047 inst.instruction |= (imm & 0x01) << 4;
22048 inst.instruction |= (imm & 0x02) << 6;
22049 inst.instruction |= (imm & 0x3c) << 14;
22050 if (rs != NS_PQQI)
22051 constraint (imm >= 64,
22052 _("vcx2 with S or D registers takes immediate within 0-63"));
22053 inst.instruction |= (imm & 0x40) << 18;
22054 }
22055
22056 static void
22057 do_vcx3 (void)
22058 {
22059 enum neon_shape rs = neon_select_shape (NS_PQQQI, NS_PDDDI, NS_PFFFI, NS_NULL);
22060 vcx_handle_common_checks (3, rs);
22061
22062 unsigned imm = inst.operands[4].imm;
22063 inst.instruction |= (imm & 0x1) << 4;
22064 inst.instruction |= (imm & 0x6) << 19;
22065 if (rs != NS_PQQQI)
22066 constraint (imm >= 8,
22067 _("vcx2 with S or D registers takes immediate within 0-7"));
22068 inst.instruction |= (imm & 0x8) << 21;
22069 }
22070
22071 /* Crypto v1 instructions. */
22072 static void
22073 do_crypto_2op_1 (unsigned elttype, int op)
22074 {
22075 set_pred_insn_type (OUTSIDE_PRED_INSN);
22076
22077 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
22078 == NT_invtype)
22079 return;
22080
22081 inst.error = NULL;
22082
22083 NEON_ENCODE (INTEGER, inst);
22084 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
22085 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
22086 inst.instruction |= LOW4 (inst.operands[1].reg);
22087 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
22088 if (op != -1)
22089 inst.instruction |= op << 6;
22090
22091 if (thumb_mode)
22092 inst.instruction |= 0xfc000000;
22093 else
22094 inst.instruction |= 0xf0000000;
22095 }
22096
22097 static void
22098 do_crypto_3op_1 (int u, int op)
22099 {
22100 set_pred_insn_type (OUTSIDE_PRED_INSN);
22101
22102 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
22103 N_32 | N_UNT | N_KEY).type == NT_invtype)
22104 return;
22105
22106 inst.error = NULL;
22107
22108 NEON_ENCODE (INTEGER, inst);
22109 neon_three_same (1, u, 8 << op);
22110 }
22111
22112 static void
22113 do_aese (void)
22114 {
22115 do_crypto_2op_1 (N_8, 0);
22116 }
22117
22118 static void
22119 do_aesd (void)
22120 {
22121 do_crypto_2op_1 (N_8, 1);
22122 }
22123
22124 static void
22125 do_aesmc (void)
22126 {
22127 do_crypto_2op_1 (N_8, 2);
22128 }
22129
22130 static void
22131 do_aesimc (void)
22132 {
22133 do_crypto_2op_1 (N_8, 3);
22134 }
22135
22136 static void
22137 do_sha1c (void)
22138 {
22139 do_crypto_3op_1 (0, 0);
22140 }
22141
22142 static void
22143 do_sha1p (void)
22144 {
22145 do_crypto_3op_1 (0, 1);
22146 }
22147
22148 static void
22149 do_sha1m (void)
22150 {
22151 do_crypto_3op_1 (0, 2);
22152 }
22153
22154 static void
22155 do_sha1su0 (void)
22156 {
22157 do_crypto_3op_1 (0, 3);
22158 }
22159
22160 static void
22161 do_sha256h (void)
22162 {
22163 do_crypto_3op_1 (1, 0);
22164 }
22165
22166 static void
22167 do_sha256h2 (void)
22168 {
22169 do_crypto_3op_1 (1, 1);
22170 }
22171
22172 static void
22173 do_sha256su1 (void)
22174 {
22175 do_crypto_3op_1 (1, 2);
22176 }
22177
22178 static void
22179 do_sha1h (void)
22180 {
22181 do_crypto_2op_1 (N_32, -1);
22182 }
22183
22184 static void
22185 do_sha1su1 (void)
22186 {
22187 do_crypto_2op_1 (N_32, 0);
22188 }
22189
22190 static void
22191 do_sha256su0 (void)
22192 {
22193 do_crypto_2op_1 (N_32, 1);
22194 }
22195
22196 static void
22197 do_crc32_1 (unsigned int poly, unsigned int sz)
22198 {
22199 unsigned int Rd = inst.operands[0].reg;
22200 unsigned int Rn = inst.operands[1].reg;
22201 unsigned int Rm = inst.operands[2].reg;
22202
22203 set_pred_insn_type (OUTSIDE_PRED_INSN);
22204 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
22205 inst.instruction |= LOW4 (Rn) << 16;
22206 inst.instruction |= LOW4 (Rm);
22207 inst.instruction |= sz << (thumb_mode ? 4 : 21);
22208 inst.instruction |= poly << (thumb_mode ? 20 : 9);
22209
22210 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
22211 as_warn (UNPRED_REG ("r15"));
22212 }
22213
22214 static void
22215 do_crc32b (void)
22216 {
22217 do_crc32_1 (0, 0);
22218 }
22219
22220 static void
22221 do_crc32h (void)
22222 {
22223 do_crc32_1 (0, 1);
22224 }
22225
22226 static void
22227 do_crc32w (void)
22228 {
22229 do_crc32_1 (0, 2);
22230 }
22231
22232 static void
22233 do_crc32cb (void)
22234 {
22235 do_crc32_1 (1, 0);
22236 }
22237
22238 static void
22239 do_crc32ch (void)
22240 {
22241 do_crc32_1 (1, 1);
22242 }
22243
22244 static void
22245 do_crc32cw (void)
22246 {
22247 do_crc32_1 (1, 2);
22248 }
22249
22250 static void
22251 do_vjcvt (void)
22252 {
22253 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
22254 _(BAD_FPU));
22255 neon_check_type (2, NS_FD, N_S32, N_F64);
22256 do_vfp_sp_dp_cvt ();
22257 do_vfp_cond_or_thumb ();
22258 }
22259
22260 static void
22261 do_vdot (void)
22262 {
22263 enum neon_shape rs;
22264 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22265 set_pred_insn_type (OUTSIDE_PRED_INSN);
22266 if (inst.operands[2].isscalar)
22267 {
22268 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
22269 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22270
22271 inst.instruction |= (1 << 25);
22272 int idx = inst.operands[2].reg & 0xf;
22273 constraint ((idx != 1 && idx != 0), _("index must be 0 or 1"));
22274 inst.operands[2].reg >>= 4;
22275 constraint (!(inst.operands[2].reg < 16),
22276 _("indexed register must be less than 16"));
22277 neon_three_args (rs == NS_QQS);
22278 inst.instruction |= (idx << 5);
22279 }
22280 else
22281 {
22282 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
22283 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22284 neon_three_args (rs == NS_QQQ);
22285 }
22286 }
22287
22288 static void
22289 do_vmmla (void)
22290 {
22291 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
22292 neon_check_type (3, rs, N_EQK, N_EQK, N_BF16 | N_KEY);
22293
22294 constraint (!mark_feature_used (&fpu_neon_ext_armv8), _(BAD_FPU));
22295 set_pred_insn_type (OUTSIDE_PRED_INSN);
22296
22297 neon_three_args (1);
22298 }
22299
22300 static void
22301 do_t_pacbti (void)
22302 {
22303 inst.instruction = THUMB_OP32 (inst.instruction);
22304 }
22305
22306 static void
22307 do_t_pacbti_nonop (void)
22308 {
22309 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, pacbti_ext),
22310 _(BAD_PACBTI));
22311
22312 inst.instruction = THUMB_OP32 (inst.instruction);
22313 inst.instruction |= inst.operands[0].reg << 12;
22314 inst.instruction |= inst.operands[1].reg << 16;
22315 inst.instruction |= inst.operands[2].reg;
22316 }
22317
22318 static void
22319 do_t_pacbti_pacg (void)
22320 {
22321 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, pacbti_ext),
22322 _(BAD_PACBTI));
22323
22324 inst.instruction = THUMB_OP32 (inst.instruction);
22325 inst.instruction |= inst.operands[0].reg << 8;
22326 inst.instruction |= inst.operands[1].reg << 16;
22327 inst.instruction |= inst.operands[2].reg;
22328 }
22329
22330 \f
22331 /* Overall per-instruction processing. */
22332
22333 /* We need to be able to fix up arbitrary expressions in some statements.
22334 This is so that we can handle symbols that are an arbitrary distance from
22335 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
22336 which returns part of an address in a form which will be valid for
22337 a data instruction. We do this by pushing the expression into a symbol
22338 in the expr_section, and creating a fix for that. */
22339
22340 static void
22341 fix_new_arm (fragS * frag,
22342 int where,
22343 short int size,
22344 expressionS * exp,
22345 int pc_rel,
22346 int reloc)
22347 {
22348 fixS * new_fix;
22349
22350 switch (exp->X_op)
22351 {
22352 case O_constant:
22353 if (pc_rel)
22354 {
22355 /* Create an absolute valued symbol, so we have something to
22356 refer to in the object file. Unfortunately for us, gas's
22357 generic expression parsing will already have folded out
22358 any use of .set foo/.type foo %function that may have
22359 been used to set type information of the target location,
22360 that's being specified symbolically. We have to presume
22361 the user knows what they are doing. */
22362 char name[16 + 8];
22363 symbolS *symbol;
22364
22365 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
22366
22367 symbol = symbol_find_or_make (name);
22368 S_SET_SEGMENT (symbol, absolute_section);
22369 symbol_set_frag (symbol, &zero_address_frag);
22370 S_SET_VALUE (symbol, exp->X_add_number);
22371 exp->X_op = O_symbol;
22372 exp->X_add_symbol = symbol;
22373 exp->X_add_number = 0;
22374 }
22375 /* FALLTHROUGH */
22376 case O_symbol:
22377 case O_add:
22378 case O_subtract:
22379 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
22380 (enum bfd_reloc_code_real) reloc);
22381 break;
22382
22383 default:
22384 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
22385 pc_rel, (enum bfd_reloc_code_real) reloc);
22386 break;
22387 }
22388
22389 /* Mark whether the fix is to a THUMB instruction, or an ARM
22390 instruction. */
22391 new_fix->tc_fix_data = thumb_mode;
22392 }
22393
22394 /* Create a frg for an instruction requiring relaxation. */
22395 static void
22396 output_relax_insn (void)
22397 {
22398 char * to;
22399 symbolS *sym;
22400 int offset;
22401
22402 /* The size of the instruction is unknown, so tie the debug info to the
22403 start of the instruction. */
22404 dwarf2_emit_insn (0);
22405
22406 switch (inst.relocs[0].exp.X_op)
22407 {
22408 case O_symbol:
22409 sym = inst.relocs[0].exp.X_add_symbol;
22410 offset = inst.relocs[0].exp.X_add_number;
22411 break;
22412 case O_constant:
22413 sym = NULL;
22414 offset = inst.relocs[0].exp.X_add_number;
22415 break;
22416 default:
22417 sym = make_expr_symbol (&inst.relocs[0].exp);
22418 offset = 0;
22419 break;
22420 }
22421 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
22422 inst.relax, sym, offset, NULL/*offset, opcode*/);
22423 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
22424 }
22425
22426 /* Write a 32-bit thumb instruction to buf. */
22427 static void
22428 put_thumb32_insn (char * buf, unsigned long insn)
22429 {
22430 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
22431 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
22432 }
22433
22434 static void
22435 output_inst (const char * str)
22436 {
22437 char * to = NULL;
22438
22439 if (inst.error)
22440 {
22441 as_bad ("%s -- `%s'", inst.error, str);
22442 return;
22443 }
22444 if (inst.relax)
22445 {
22446 output_relax_insn ();
22447 return;
22448 }
22449 if (inst.size == 0)
22450 return;
22451
22452 to = frag_more (inst.size);
22453 /* PR 9814: Record the thumb mode into the current frag so that we know
22454 what type of NOP padding to use, if necessary. We override any previous
22455 setting so that if the mode has changed then the NOPS that we use will
22456 match the encoding of the last instruction in the frag. */
22457 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22458
22459 if (thumb_mode && (inst.size > THUMB_SIZE))
22460 {
22461 gas_assert (inst.size == (2 * THUMB_SIZE));
22462 put_thumb32_insn (to, inst.instruction);
22463 }
22464 else if (inst.size > INSN_SIZE)
22465 {
22466 gas_assert (inst.size == (2 * INSN_SIZE));
22467 md_number_to_chars (to, inst.instruction, INSN_SIZE);
22468 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
22469 }
22470 else
22471 md_number_to_chars (to, inst.instruction, inst.size);
22472
22473 int r;
22474 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22475 {
22476 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
22477 fix_new_arm (frag_now, to - frag_now->fr_literal,
22478 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
22479 inst.relocs[r].type);
22480 }
22481
22482 dwarf2_emit_insn (inst.size);
22483 }
22484
22485 static char *
22486 output_it_inst (int cond, int mask, char * to)
22487 {
22488 unsigned long instruction = 0xbf00;
22489
22490 mask &= 0xf;
22491 instruction |= mask;
22492 instruction |= cond << 4;
22493
22494 if (to == NULL)
22495 {
22496 to = frag_more (2);
22497 #ifdef OBJ_ELF
22498 dwarf2_emit_insn (2);
22499 #endif
22500 }
22501
22502 md_number_to_chars (to, instruction, 2);
22503
22504 return to;
22505 }
22506
22507 /* Tag values used in struct asm_opcode's tag field. */
22508 enum opcode_tag
22509 {
22510 OT_unconditional, /* Instruction cannot be conditionalized.
22511 The ARM condition field is still 0xE. */
22512 OT_unconditionalF, /* Instruction cannot be conditionalized
22513 and carries 0xF in its ARM condition field. */
22514 OT_csuffix, /* Instruction takes a conditional suffix. */
22515 OT_csuffixF, /* Some forms of the instruction take a scalar
22516 conditional suffix, others place 0xF where the
22517 condition field would be, others take a vector
22518 conditional suffix. */
22519 OT_cinfix3, /* Instruction takes a conditional infix,
22520 beginning at character index 3. (In
22521 unified mode, it becomes a suffix.) */
22522 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
22523 tsts, cmps, cmns, and teqs. */
22524 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
22525 character index 3, even in unified mode. Used for
22526 legacy instructions where suffix and infix forms
22527 may be ambiguous. */
22528 OT_csuf_or_in3, /* Instruction takes either a conditional
22529 suffix or an infix at character index 3. */
22530 OT_odd_infix_unc, /* This is the unconditional variant of an
22531 instruction that takes a conditional infix
22532 at an unusual position. In unified mode,
22533 this variant will accept a suffix. */
22534 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
22535 are the conditional variants of instructions that
22536 take conditional infixes in unusual positions.
22537 The infix appears at character index
22538 (tag - OT_odd_infix_0). These are not accepted
22539 in unified mode. */
22540 };
22541
22542 /* Subroutine of md_assemble, responsible for looking up the primary
22543 opcode from the mnemonic the user wrote. STR points to the
22544 beginning of the mnemonic.
22545
22546 This is not simply a hash table lookup, because of conditional
22547 variants. Most instructions have conditional variants, which are
22548 expressed with a _conditional affix_ to the mnemonic. If we were
22549 to encode each conditional variant as a literal string in the opcode
22550 table, it would have approximately 20,000 entries.
22551
22552 Most mnemonics take this affix as a suffix, and in unified syntax,
22553 'most' is upgraded to 'all'. However, in the divided syntax, some
22554 instructions take the affix as an infix, notably the s-variants of
22555 the arithmetic instructions. Of those instructions, all but six
22556 have the infix appear after the third character of the mnemonic.
22557
22558 Accordingly, the algorithm for looking up primary opcodes given
22559 an identifier is:
22560
22561 1. Look up the identifier in the opcode table.
22562 If we find a match, go to step U.
22563
22564 2. Look up the last two characters of the identifier in the
22565 conditions table. If we find a match, look up the first N-2
22566 characters of the identifier in the opcode table. If we
22567 find a match, go to step CE.
22568
22569 3. Look up the fourth and fifth characters of the identifier in
22570 the conditions table. If we find a match, extract those
22571 characters from the identifier, and look up the remaining
22572 characters in the opcode table. If we find a match, go
22573 to step CM.
22574
22575 4. Fail.
22576
22577 U. Examine the tag field of the opcode structure, in case this is
22578 one of the six instructions with its conditional infix in an
22579 unusual place. If it is, the tag tells us where to find the
22580 infix; look it up in the conditions table and set inst.cond
22581 accordingly. Otherwise, this is an unconditional instruction.
22582 Again set inst.cond accordingly. Return the opcode structure.
22583
22584 CE. Examine the tag field to make sure this is an instruction that
22585 should receive a conditional suffix. If it is not, fail.
22586 Otherwise, set inst.cond from the suffix we already looked up,
22587 and return the opcode structure.
22588
22589 CM. Examine the tag field to make sure this is an instruction that
22590 should receive a conditional infix after the third character.
22591 If it is not, fail. Otherwise, undo the edits to the current
22592 line of input and proceed as for case CE. */
22593
22594 static const struct asm_opcode *
22595 opcode_lookup (char **str)
22596 {
22597 char *end, *base;
22598 char *affix;
22599 const struct asm_opcode *opcode;
22600 const struct asm_cond *cond;
22601 char save[2];
22602
22603 /* Scan up to the end of the mnemonic, which must end in white space,
22604 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
22605 for (base = end = *str; *end != '\0'; end++)
22606 if (*end == ' ' || *end == '.')
22607 break;
22608
22609 if (end == base)
22610 return NULL;
22611
22612 /* Handle a possible width suffix and/or Neon type suffix. */
22613 if (end[0] == '.')
22614 {
22615 int offset = 2;
22616
22617 /* The .w and .n suffixes are only valid if the unified syntax is in
22618 use. */
22619 if (unified_syntax && end[1] == 'w')
22620 inst.size_req = 4;
22621 else if (unified_syntax && end[1] == 'n')
22622 inst.size_req = 2;
22623 else
22624 offset = 0;
22625
22626 inst.vectype.elems = 0;
22627
22628 *str = end + offset;
22629
22630 if (end[offset] == '.')
22631 {
22632 /* See if we have a Neon type suffix (possible in either unified or
22633 non-unified ARM syntax mode). */
22634 if (parse_neon_type (&inst.vectype, str) == FAIL)
22635 return NULL;
22636 }
22637 else if (end[offset] != '\0' && end[offset] != ' ')
22638 return NULL;
22639 }
22640 else
22641 *str = end;
22642
22643 /* Look for unaffixed or special-case affixed mnemonic. */
22644 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22645 end - base);
22646 cond = NULL;
22647 if (opcode)
22648 {
22649 /* step U */
22650 if (opcode->tag < OT_odd_infix_0)
22651 {
22652 inst.cond = COND_ALWAYS;
22653 return opcode;
22654 }
22655
22656 if (warn_on_deprecated && unified_syntax)
22657 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22658 affix = base + (opcode->tag - OT_odd_infix_0);
22659 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22660 gas_assert (cond);
22661
22662 inst.cond = cond->value;
22663 return opcode;
22664 }
22665 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
22666 {
22667 /* Cannot have a conditional suffix on a mnemonic of less than a character.
22668 */
22669 if (end - base < 2)
22670 return NULL;
22671 affix = end - 1;
22672 cond = (const struct asm_cond *) str_hash_find_n (arm_vcond_hsh, affix, 1);
22673 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22674 affix - base);
22675 /* If this opcode can not be vector predicated then don't accept it with a
22676 vector predication code. */
22677 if (opcode && !opcode->mayBeVecPred)
22678 opcode = NULL;
22679 }
22680 if (!opcode || !cond)
22681 {
22682 /* Cannot have a conditional suffix on a mnemonic of less than two
22683 characters. */
22684 if (end - base < 3)
22685 return NULL;
22686
22687 /* Look for suffixed mnemonic. */
22688 affix = end - 2;
22689 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22690 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22691 affix - base);
22692 }
22693
22694 if (opcode && cond)
22695 {
22696 /* step CE */
22697 switch (opcode->tag)
22698 {
22699 case OT_cinfix3_legacy:
22700 /* Ignore conditional suffixes matched on infix only mnemonics. */
22701 break;
22702
22703 case OT_cinfix3:
22704 case OT_cinfix3_deprecated:
22705 case OT_odd_infix_unc:
22706 if (!unified_syntax)
22707 return NULL;
22708 /* Fall through. */
22709
22710 case OT_csuffix:
22711 case OT_csuffixF:
22712 case OT_csuf_or_in3:
22713 inst.cond = cond->value;
22714 return opcode;
22715
22716 case OT_unconditional:
22717 case OT_unconditionalF:
22718 if (thumb_mode)
22719 inst.cond = cond->value;
22720 else
22721 {
22722 /* Delayed diagnostic. */
22723 inst.error = BAD_COND;
22724 inst.cond = COND_ALWAYS;
22725 }
22726 return opcode;
22727
22728 default:
22729 return NULL;
22730 }
22731 }
22732
22733 /* Cannot have a usual-position infix on a mnemonic of less than
22734 six characters (five would be a suffix). */
22735 if (end - base < 6)
22736 return NULL;
22737
22738 /* Look for infixed mnemonic in the usual position. */
22739 affix = base + 3;
22740 cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2);
22741 if (!cond)
22742 return NULL;
22743
22744 memcpy (save, affix, 2);
22745 memmove (affix, affix + 2, (end - affix) - 2);
22746 opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base,
22747 (end - base) - 2);
22748 memmove (affix + 2, affix, (end - affix) - 2);
22749 memcpy (affix, save, 2);
22750
22751 if (opcode
22752 && (opcode->tag == OT_cinfix3
22753 || opcode->tag == OT_cinfix3_deprecated
22754 || opcode->tag == OT_csuf_or_in3
22755 || opcode->tag == OT_cinfix3_legacy))
22756 {
22757 /* Step CM. */
22758 if (warn_on_deprecated && unified_syntax
22759 && (opcode->tag == OT_cinfix3
22760 || opcode->tag == OT_cinfix3_deprecated))
22761 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
22762
22763 inst.cond = cond->value;
22764 return opcode;
22765 }
22766
22767 return NULL;
22768 }
22769
22770 /* This function generates an initial IT instruction, leaving its block
22771 virtually open for the new instructions. Eventually,
22772 the mask will be updated by now_pred_add_mask () each time
22773 a new instruction needs to be included in the IT block.
22774 Finally, the block is closed with close_automatic_it_block ().
22775 The block closure can be requested either from md_assemble (),
22776 a tencode (), or due to a label hook. */
22777
22778 static void
22779 new_automatic_it_block (int cond)
22780 {
22781 now_pred.state = AUTOMATIC_PRED_BLOCK;
22782 now_pred.mask = 0x18;
22783 now_pred.cc = cond;
22784 now_pred.block_length = 1;
22785 mapping_state (MAP_THUMB);
22786 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
22787 now_pred.warn_deprecated = false;
22788 now_pred.insn_cond = true;
22789 }
22790
22791 /* Close an automatic IT block.
22792 See comments in new_automatic_it_block (). */
22793
22794 static void
22795 close_automatic_it_block (void)
22796 {
22797 now_pred.mask = 0x10;
22798 now_pred.block_length = 0;
22799 }
22800
22801 /* Update the mask of the current automatically-generated IT
22802 instruction. See comments in new_automatic_it_block (). */
22803
22804 static void
22805 now_pred_add_mask (int cond)
22806 {
22807 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
22808 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
22809 | ((bitvalue) << (nbit)))
22810 const int resulting_bit = (cond & 1);
22811
22812 now_pred.mask &= 0xf;
22813 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22814 resulting_bit,
22815 (5 - now_pred.block_length));
22816 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
22817 1,
22818 ((5 - now_pred.block_length) - 1));
22819 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
22820
22821 #undef CLEAR_BIT
22822 #undef SET_BIT_VALUE
22823 }
22824
22825 /* The IT blocks handling machinery is accessed through the these functions:
22826 it_fsm_pre_encode () from md_assemble ()
22827 set_pred_insn_type () optional, from the tencode functions
22828 set_pred_insn_type_last () ditto
22829 in_pred_block () ditto
22830 it_fsm_post_encode () from md_assemble ()
22831 force_automatic_it_block_close () from label handling functions
22832
22833 Rationale:
22834 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
22835 initializing the IT insn type with a generic initial value depending
22836 on the inst.condition.
22837 2) During the tencode function, two things may happen:
22838 a) The tencode function overrides the IT insn type by
22839 calling either set_pred_insn_type (type) or
22840 set_pred_insn_type_last ().
22841 b) The tencode function queries the IT block state by
22842 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
22843
22844 Both set_pred_insn_type and in_pred_block run the internal FSM state
22845 handling function (handle_pred_state), because: a) setting the IT insn
22846 type may incur in an invalid state (exiting the function),
22847 and b) querying the state requires the FSM to be updated.
22848 Specifically we want to avoid creating an IT block for conditional
22849 branches, so it_fsm_pre_encode is actually a guess and we can't
22850 determine whether an IT block is required until the tencode () routine
22851 has decided what type of instruction this actually it.
22852 Because of this, if set_pred_insn_type and in_pred_block have to be
22853 used, set_pred_insn_type has to be called first.
22854
22855 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22856 that determines the insn IT type depending on the inst.cond code.
22857 When a tencode () routine encodes an instruction that can be
22858 either outside an IT block, or, in the case of being inside, has to be
22859 the last one, set_pred_insn_type_last () will determine the proper
22860 IT instruction type based on the inst.cond code. Otherwise,
22861 set_pred_insn_type can be called for overriding that logic or
22862 for covering other cases.
22863
22864 Calling handle_pred_state () may not transition the IT block state to
22865 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
22866 still queried. Instead, if the FSM determines that the state should
22867 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
22868 after the tencode () function: that's what it_fsm_post_encode () does.
22869
22870 Since in_pred_block () calls the state handling function to get an
22871 updated state, an error may occur (due to invalid insns combination).
22872 In that case, inst.error is set.
22873 Therefore, inst.error has to be checked after the execution of
22874 the tencode () routine.
22875
22876 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
22877 any pending state change (if any) that didn't take place in
22878 handle_pred_state () as explained above. */
22879
22880 static void
22881 it_fsm_pre_encode (void)
22882 {
22883 if (inst.cond != COND_ALWAYS)
22884 inst.pred_insn_type = INSIDE_IT_INSN;
22885 else
22886 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22887
22888 now_pred.state_handled = 0;
22889 }
22890
22891 /* IT state FSM handling function. */
22892 /* MVE instructions and non-MVE instructions are handled differently because of
22893 the introduction of VPT blocks.
22894 Specifications say that any non-MVE instruction inside a VPT block is
22895 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22896 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
22897 few exceptions we have MVE_UNPREDICABLE_INSN.
22898 The error messages provided depending on the different combinations possible
22899 are described in the cases below:
22900 For 'most' MVE instructions:
22901 1) In an IT block, with an IT code: syntax error
22902 2) In an IT block, with a VPT code: error: must be in a VPT block
22903 3) In an IT block, with no code: warning: UNPREDICTABLE
22904 4) In a VPT block, with an IT code: syntax error
22905 5) In a VPT block, with a VPT code: OK!
22906 6) In a VPT block, with no code: error: missing code
22907 7) Outside a pred block, with an IT code: error: syntax error
22908 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22909 9) Outside a pred block, with no code: OK!
22910 For non-MVE instructions:
22911 10) In an IT block, with an IT code: OK!
22912 11) In an IT block, with a VPT code: syntax error
22913 12) In an IT block, with no code: error: missing code
22914 13) In a VPT block, with an IT code: error: should be in an IT block
22915 14) In a VPT block, with a VPT code: syntax error
22916 15) In a VPT block, with no code: UNPREDICTABLE
22917 16) Outside a pred block, with an IT code: error: should be in an IT block
22918 17) Outside a pred block, with a VPT code: syntax error
22919 18) Outside a pred block, with no code: OK!
22920 */
22921
22922
22923 static int
22924 handle_pred_state (void)
22925 {
22926 now_pred.state_handled = 1;
22927 now_pred.insn_cond = false;
22928
22929 switch (now_pred.state)
22930 {
22931 case OUTSIDE_PRED_BLOCK:
22932 switch (inst.pred_insn_type)
22933 {
22934 case MVE_UNPREDICABLE_INSN:
22935 case MVE_OUTSIDE_PRED_INSN:
22936 if (inst.cond < COND_ALWAYS)
22937 {
22938 /* Case 7: Outside a pred block, with an IT code: error: syntax
22939 error. */
22940 inst.error = BAD_SYNTAX;
22941 return FAIL;
22942 }
22943 /* Case 9: Outside a pred block, with no code: OK! */
22944 break;
22945 case OUTSIDE_PRED_INSN:
22946 if (inst.cond > COND_ALWAYS)
22947 {
22948 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22949 */
22950 inst.error = BAD_SYNTAX;
22951 return FAIL;
22952 }
22953 /* Case 18: Outside a pred block, with no code: OK! */
22954 break;
22955
22956 case INSIDE_VPT_INSN:
22957 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22958 a VPT block. */
22959 inst.error = BAD_OUT_VPT;
22960 return FAIL;
22961
22962 case INSIDE_IT_INSN:
22963 case INSIDE_IT_LAST_INSN:
22964 if (inst.cond < COND_ALWAYS)
22965 {
22966 /* Case 16: Outside a pred block, with an IT code: error: should
22967 be in an IT block. */
22968 if (thumb_mode == 0)
22969 {
22970 if (unified_syntax
22971 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22972 as_tsktsk (_("Warning: conditional outside an IT block"\
22973 " for Thumb."));
22974 }
22975 else
22976 {
22977 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22978 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22979 {
22980 /* Automatically generate the IT instruction. */
22981 new_automatic_it_block (inst.cond);
22982 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22983 close_automatic_it_block ();
22984 }
22985 else
22986 {
22987 inst.error = BAD_OUT_IT;
22988 return FAIL;
22989 }
22990 }
22991 break;
22992 }
22993 else if (inst.cond > COND_ALWAYS)
22994 {
22995 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22996 */
22997 inst.error = BAD_SYNTAX;
22998 return FAIL;
22999 }
23000 else
23001 gas_assert (0);
23002 case IF_INSIDE_IT_LAST_INSN:
23003 case NEUTRAL_IT_INSN:
23004 break;
23005
23006 case VPT_INSN:
23007 if (inst.cond != COND_ALWAYS)
23008 first_error (BAD_SYNTAX);
23009 now_pred.state = MANUAL_PRED_BLOCK;
23010 now_pred.block_length = 0;
23011 now_pred.type = VECTOR_PRED;
23012 now_pred.cc = 0;
23013 break;
23014 case IT_INSN:
23015 now_pred.state = MANUAL_PRED_BLOCK;
23016 now_pred.block_length = 0;
23017 now_pred.type = SCALAR_PRED;
23018 break;
23019 }
23020 break;
23021
23022 case AUTOMATIC_PRED_BLOCK:
23023 /* Three things may happen now:
23024 a) We should increment current it block size;
23025 b) We should close current it block (closing insn or 4 insns);
23026 c) We should close current it block and start a new one (due
23027 to incompatible conditions or
23028 4 insns-length block reached). */
23029
23030 switch (inst.pred_insn_type)
23031 {
23032 case INSIDE_VPT_INSN:
23033 case VPT_INSN:
23034 case MVE_UNPREDICABLE_INSN:
23035 case MVE_OUTSIDE_PRED_INSN:
23036 gas_assert (0);
23037 case OUTSIDE_PRED_INSN:
23038 /* The closure of the block shall happen immediately,
23039 so any in_pred_block () call reports the block as closed. */
23040 force_automatic_it_block_close ();
23041 break;
23042
23043 case INSIDE_IT_INSN:
23044 case INSIDE_IT_LAST_INSN:
23045 case IF_INSIDE_IT_LAST_INSN:
23046 now_pred.block_length++;
23047
23048 if (now_pred.block_length > 4
23049 || !now_pred_compatible (inst.cond))
23050 {
23051 force_automatic_it_block_close ();
23052 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
23053 new_automatic_it_block (inst.cond);
23054 }
23055 else
23056 {
23057 now_pred.insn_cond = true;
23058 now_pred_add_mask (inst.cond);
23059 }
23060
23061 if (now_pred.state == AUTOMATIC_PRED_BLOCK
23062 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
23063 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
23064 close_automatic_it_block ();
23065 break;
23066
23067 /* Fallthrough. */
23068 case NEUTRAL_IT_INSN:
23069 now_pred.block_length++;
23070 now_pred.insn_cond = true;
23071
23072 if (now_pred.block_length > 4)
23073 force_automatic_it_block_close ();
23074 else
23075 now_pred_add_mask (now_pred.cc & 1);
23076 break;
23077
23078 case IT_INSN:
23079 close_automatic_it_block ();
23080 now_pred.state = MANUAL_PRED_BLOCK;
23081 break;
23082 }
23083 break;
23084
23085 case MANUAL_PRED_BLOCK:
23086 {
23087 unsigned int cond;
23088 int is_last;
23089 if (now_pred.type == SCALAR_PRED)
23090 {
23091 /* Check conditional suffixes. */
23092 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
23093 now_pred.mask <<= 1;
23094 now_pred.mask &= 0x1f;
23095 is_last = (now_pred.mask == 0x10);
23096 }
23097 else
23098 {
23099 now_pred.cc ^= (now_pred.mask >> 4);
23100 cond = now_pred.cc + 0xf;
23101 now_pred.mask <<= 1;
23102 now_pred.mask &= 0x1f;
23103 is_last = now_pred.mask == 0x10;
23104 }
23105 now_pred.insn_cond = true;
23106
23107 switch (inst.pred_insn_type)
23108 {
23109 case OUTSIDE_PRED_INSN:
23110 if (now_pred.type == SCALAR_PRED)
23111 {
23112 if (inst.cond == COND_ALWAYS)
23113 {
23114 /* Case 12: In an IT block, with no code: error: missing
23115 code. */
23116 inst.error = BAD_NOT_IT;
23117 return FAIL;
23118 }
23119 else if (inst.cond > COND_ALWAYS)
23120 {
23121 /* Case 11: In an IT block, with a VPT code: syntax error.
23122 */
23123 inst.error = BAD_SYNTAX;
23124 return FAIL;
23125 }
23126 else if (thumb_mode)
23127 {
23128 /* This is for some special cases where a non-MVE
23129 instruction is not allowed in an IT block, such as cbz,
23130 but are put into one with a condition code.
23131 You could argue this should be a syntax error, but we
23132 gave the 'not allowed in IT block' diagnostic in the
23133 past so we will keep doing so. */
23134 inst.error = BAD_NOT_IT;
23135 return FAIL;
23136 }
23137 break;
23138 }
23139 else
23140 {
23141 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
23142 as_tsktsk (MVE_NOT_VPT);
23143 return SUCCESS;
23144 }
23145 case MVE_OUTSIDE_PRED_INSN:
23146 if (now_pred.type == SCALAR_PRED)
23147 {
23148 if (inst.cond == COND_ALWAYS)
23149 {
23150 /* Case 3: In an IT block, with no code: warning:
23151 UNPREDICTABLE. */
23152 as_tsktsk (MVE_NOT_IT);
23153 return SUCCESS;
23154 }
23155 else if (inst.cond < COND_ALWAYS)
23156 {
23157 /* Case 1: In an IT block, with an IT code: syntax error.
23158 */
23159 inst.error = BAD_SYNTAX;
23160 return FAIL;
23161 }
23162 else
23163 gas_assert (0);
23164 }
23165 else
23166 {
23167 if (inst.cond < COND_ALWAYS)
23168 {
23169 /* Case 4: In a VPT block, with an IT code: syntax error.
23170 */
23171 inst.error = BAD_SYNTAX;
23172 return FAIL;
23173 }
23174 else if (inst.cond == COND_ALWAYS)
23175 {
23176 /* Case 6: In a VPT block, with no code: error: missing
23177 code. */
23178 inst.error = BAD_NOT_VPT;
23179 return FAIL;
23180 }
23181 else
23182 {
23183 gas_assert (0);
23184 }
23185 }
23186 case MVE_UNPREDICABLE_INSN:
23187 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
23188 return SUCCESS;
23189 case INSIDE_IT_INSN:
23190 if (inst.cond > COND_ALWAYS)
23191 {
23192 /* Case 11: In an IT block, with a VPT code: syntax error. */
23193 /* Case 14: In a VPT block, with a VPT code: syntax error. */
23194 inst.error = BAD_SYNTAX;
23195 return FAIL;
23196 }
23197 else if (now_pred.type == SCALAR_PRED)
23198 {
23199 /* Case 10: In an IT block, with an IT code: OK! */
23200 if (cond != inst.cond)
23201 {
23202 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
23203 BAD_VPT_COND;
23204 return FAIL;
23205 }
23206 }
23207 else
23208 {
23209 /* Case 13: In a VPT block, with an IT code: error: should be
23210 in an IT block. */
23211 inst.error = BAD_OUT_IT;
23212 return FAIL;
23213 }
23214 break;
23215
23216 case INSIDE_VPT_INSN:
23217 if (now_pred.type == SCALAR_PRED)
23218 {
23219 /* Case 2: In an IT block, with a VPT code: error: must be in a
23220 VPT block. */
23221 inst.error = BAD_OUT_VPT;
23222 return FAIL;
23223 }
23224 /* Case 5: In a VPT block, with a VPT code: OK! */
23225 else if (cond != inst.cond)
23226 {
23227 inst.error = BAD_VPT_COND;
23228 return FAIL;
23229 }
23230 break;
23231 case INSIDE_IT_LAST_INSN:
23232 case IF_INSIDE_IT_LAST_INSN:
23233 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
23234 {
23235 /* Case 4: In a VPT block, with an IT code: syntax error. */
23236 /* Case 11: In an IT block, with a VPT code: syntax error. */
23237 inst.error = BAD_SYNTAX;
23238 return FAIL;
23239 }
23240 else if (cond != inst.cond)
23241 {
23242 inst.error = BAD_IT_COND;
23243 return FAIL;
23244 }
23245 if (!is_last)
23246 {
23247 inst.error = BAD_BRANCH;
23248 return FAIL;
23249 }
23250 break;
23251
23252 case NEUTRAL_IT_INSN:
23253 /* The BKPT instruction is unconditional even in a IT or VPT
23254 block. */
23255 break;
23256
23257 case IT_INSN:
23258 if (now_pred.type == SCALAR_PRED)
23259 {
23260 inst.error = BAD_IT_IT;
23261 return FAIL;
23262 }
23263 /* fall through. */
23264 case VPT_INSN:
23265 if (inst.cond == COND_ALWAYS)
23266 {
23267 /* Executing a VPT/VPST instruction inside an IT block or a
23268 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
23269 */
23270 if (now_pred.type == SCALAR_PRED)
23271 as_tsktsk (MVE_NOT_IT);
23272 else
23273 as_tsktsk (MVE_NOT_VPT);
23274 return SUCCESS;
23275 }
23276 else
23277 {
23278 /* VPT/VPST do not accept condition codes. */
23279 inst.error = BAD_SYNTAX;
23280 return FAIL;
23281 }
23282 }
23283 }
23284 break;
23285 }
23286
23287 return SUCCESS;
23288 }
23289
23290 struct depr_insn_mask
23291 {
23292 unsigned long pattern;
23293 unsigned long mask;
23294 const char* description;
23295 };
23296
23297 /* List of 16-bit instruction patterns deprecated in an IT block in
23298 ARMv8. */
23299 static const struct depr_insn_mask depr_it_insns[] = {
23300 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
23301 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
23302 { 0xa000, 0xb800, N_("ADR") },
23303 { 0x4800, 0xf800, N_("Literal loads") },
23304 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
23305 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
23306 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
23307 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
23308 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
23309 { 0, 0, NULL }
23310 };
23311
23312 static void
23313 it_fsm_post_encode (void)
23314 {
23315 int is_last;
23316
23317 if (!now_pred.state_handled)
23318 handle_pred_state ();
23319
23320 if (now_pred.insn_cond
23321 && warn_on_restrict_it
23322 && !now_pred.warn_deprecated
23323 && warn_on_deprecated
23324 && (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
23325 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8r))
23326 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
23327 {
23328 if (inst.instruction >= 0x10000)
23329 {
23330 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
23331 "performance deprecated in ARMv8-A and ARMv8-R"));
23332 now_pred.warn_deprecated = true;
23333 }
23334 else
23335 {
23336 const struct depr_insn_mask *p = depr_it_insns;
23337
23338 while (p->mask != 0)
23339 {
23340 if ((inst.instruction & p->mask) == p->pattern)
23341 {
23342 as_tsktsk (_("IT blocks containing 16-bit Thumb "
23343 "instructions of the following class are "
23344 "performance deprecated in ARMv8-A and "
23345 "ARMv8-R: %s"), p->description);
23346 now_pred.warn_deprecated = true;
23347 break;
23348 }
23349
23350 ++p;
23351 }
23352 }
23353
23354 if (now_pred.block_length > 1)
23355 {
23356 as_tsktsk (_("IT blocks containing more than one conditional "
23357 "instruction are performance deprecated in ARMv8-A and "
23358 "ARMv8-R"));
23359 now_pred.warn_deprecated = true;
23360 }
23361 }
23362
23363 is_last = (now_pred.mask == 0x10);
23364 if (is_last)
23365 {
23366 now_pred.state = OUTSIDE_PRED_BLOCK;
23367 now_pred.mask = 0;
23368 }
23369 }
23370
23371 static void
23372 force_automatic_it_block_close (void)
23373 {
23374 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
23375 {
23376 close_automatic_it_block ();
23377 now_pred.state = OUTSIDE_PRED_BLOCK;
23378 now_pred.mask = 0;
23379 }
23380 }
23381
23382 static int
23383 in_pred_block (void)
23384 {
23385 if (!now_pred.state_handled)
23386 handle_pred_state ();
23387
23388 return now_pred.state != OUTSIDE_PRED_BLOCK;
23389 }
23390
23391 /* Whether OPCODE only has T32 encoding. Since this function is only used by
23392 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
23393 here, hence the "known" in the function name. */
23394
23395 static bool
23396 known_t32_only_insn (const struct asm_opcode *opcode)
23397 {
23398 /* Original Thumb-1 wide instruction. */
23399 if (opcode->tencode == do_t_blx
23400 || opcode->tencode == do_t_branch23
23401 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
23402 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
23403 return true;
23404
23405 /* Wide-only instruction added to ARMv8-M Baseline. */
23406 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
23407 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
23408 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
23409 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
23410 return true;
23411
23412 return false;
23413 }
23414
23415 /* Whether wide instruction variant can be used if available for a valid OPCODE
23416 in ARCH. */
23417
23418 static bool
23419 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
23420 {
23421 if (known_t32_only_insn (opcode))
23422 return true;
23423
23424 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
23425 of variant T3 of B.W is checked in do_t_branch. */
23426 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23427 && opcode->tencode == do_t_branch)
23428 return true;
23429
23430 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
23431 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
23432 && opcode->tencode == do_t_mov_cmp
23433 /* Make sure CMP instruction is not affected. */
23434 && opcode->aencode == do_mov)
23435 return true;
23436
23437 /* Wide instruction variants of all instructions with narrow *and* wide
23438 variants become available with ARMv6t2. Other opcodes are either
23439 narrow-only or wide-only and are thus available if OPCODE is valid. */
23440 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
23441 return true;
23442
23443 /* OPCODE with narrow only instruction variant or wide variant not
23444 available. */
23445 return false;
23446 }
23447
23448 void
23449 md_assemble (char *str)
23450 {
23451 char *p = str;
23452 const struct asm_opcode * opcode;
23453
23454 /* Align the previous label if needed. */
23455 if (last_label_seen != NULL)
23456 {
23457 symbol_set_frag (last_label_seen, frag_now);
23458 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
23459 S_SET_SEGMENT (last_label_seen, now_seg);
23460 }
23461
23462 memset (&inst, '\0', sizeof (inst));
23463 int r;
23464 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
23465 inst.relocs[r].type = BFD_RELOC_UNUSED;
23466
23467 opcode = opcode_lookup (&p);
23468 if (!opcode)
23469 {
23470 /* It wasn't an instruction, but it might be a register alias of
23471 the form alias .req reg, or a Neon .dn/.qn directive. */
23472 if (! create_register_alias (str, p)
23473 && ! create_neon_reg_alias (str, p))
23474 as_bad (_("bad instruction `%s'"), str);
23475
23476 return;
23477 }
23478
23479 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
23480 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
23481
23482 /* The value which unconditional instructions should have in place of the
23483 condition field. */
23484 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1u;
23485
23486 if (thumb_mode)
23487 {
23488 arm_feature_set variant;
23489
23490 variant = cpu_variant;
23491 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
23492 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
23493 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
23494 /* Check that this instruction is supported for this CPU. */
23495 if (!opcode->tvariant
23496 || (thumb_mode == 1
23497 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
23498 {
23499 if (opcode->tencode == do_t_swi)
23500 as_bad (_("SVC is not permitted on this architecture"));
23501 else
23502 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
23503 return;
23504 }
23505 if (inst.cond != COND_ALWAYS && !unified_syntax
23506 && opcode->tencode != do_t_branch)
23507 {
23508 as_bad (_("Thumb does not support conditional execution"));
23509 return;
23510 }
23511
23512 /* Two things are addressed here:
23513 1) Implicit require narrow instructions on Thumb-1.
23514 This avoids relaxation accidentally introducing Thumb-2
23515 instructions.
23516 2) Reject wide instructions in non Thumb-2 cores.
23517
23518 Only instructions with narrow and wide variants need to be handled
23519 but selecting all non wide-only instructions is easier. */
23520 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
23521 && !t32_insn_ok (variant, opcode))
23522 {
23523 if (inst.size_req == 0)
23524 inst.size_req = 2;
23525 else if (inst.size_req == 4)
23526 {
23527 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
23528 as_bad (_("selected processor does not support 32bit wide "
23529 "variant of instruction `%s'"), str);
23530 else
23531 as_bad (_("selected processor does not support `%s' in "
23532 "Thumb-2 mode"), str);
23533 return;
23534 }
23535 }
23536
23537 inst.instruction = opcode->tvalue;
23538
23539 if (!parse_operands (p, opcode->operands, /*thumb=*/true))
23540 {
23541 /* Prepare the pred_insn_type for those encodings that don't set
23542 it. */
23543 it_fsm_pre_encode ();
23544
23545 opcode->tencode ();
23546
23547 it_fsm_post_encode ();
23548 }
23549
23550 if (!(inst.error || inst.relax))
23551 {
23552 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
23553 inst.size = (inst.instruction > 0xffff ? 4 : 2);
23554 if (inst.size_req && inst.size_req != inst.size)
23555 {
23556 as_bad (_("cannot honor width suffix -- `%s'"), str);
23557 return;
23558 }
23559 }
23560
23561 /* Something has gone badly wrong if we try to relax a fixed size
23562 instruction. */
23563 gas_assert (inst.size_req == 0 || !inst.relax);
23564
23565 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23566 *opcode->tvariant);
23567 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
23568 set those bits when Thumb-2 32-bit instructions are seen. The impact
23569 of relaxable instructions will be considered later after we finish all
23570 relaxation. */
23571 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
23572 variant = arm_arch_none;
23573 else
23574 variant = cpu_variant;
23575 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
23576 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
23577 arm_ext_v6t2);
23578
23579 check_neon_suffixes;
23580
23581 if (!inst.error)
23582 {
23583 mapping_state (MAP_THUMB);
23584 }
23585 }
23586 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23587 {
23588 bool is_bx;
23589
23590 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
23591 is_bx = (opcode->aencode == do_bx);
23592
23593 /* Check that this instruction is supported for this CPU. */
23594 if (!(is_bx && fix_v4bx)
23595 && !(opcode->avariant &&
23596 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
23597 {
23598 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
23599 return;
23600 }
23601 if (inst.size_req)
23602 {
23603 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
23604 return;
23605 }
23606
23607 inst.instruction = opcode->avalue;
23608 if (opcode->tag == OT_unconditionalF)
23609 inst.instruction |= 0xFU << 28;
23610 else
23611 inst.instruction |= inst.cond << 28;
23612 inst.size = INSN_SIZE;
23613 if (!parse_operands (p, opcode->operands, /*thumb=*/false))
23614 {
23615 it_fsm_pre_encode ();
23616 opcode->aencode ();
23617 it_fsm_post_encode ();
23618 }
23619 /* Arm mode bx is marked as both v4T and v5 because it's still required
23620 on a hypothetical non-thumb v5 core. */
23621 if (is_bx)
23622 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
23623 else
23624 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
23625 *opcode->avariant);
23626
23627 check_neon_suffixes;
23628
23629 if (!inst.error)
23630 {
23631 mapping_state (MAP_ARM);
23632 }
23633 }
23634 else
23635 {
23636 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
23637 "-- `%s'"), str);
23638 return;
23639 }
23640 output_inst (str);
23641 }
23642
23643 static void
23644 check_pred_blocks_finished (void)
23645 {
23646 #ifdef OBJ_ELF
23647 asection *sect;
23648
23649 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
23650 if (seg_info (sect)->tc_segment_info_data.current_pred.state
23651 == MANUAL_PRED_BLOCK)
23652 {
23653 if (now_pred.type == SCALAR_PRED)
23654 as_warn (_("section '%s' finished with an open IT block."),
23655 sect->name);
23656 else
23657 as_warn (_("section '%s' finished with an open VPT/VPST block."),
23658 sect->name);
23659 }
23660 #else
23661 if (now_pred.state == MANUAL_PRED_BLOCK)
23662 {
23663 if (now_pred.type == SCALAR_PRED)
23664 as_warn (_("file finished with an open IT block."));
23665 else
23666 as_warn (_("file finished with an open VPT/VPST block."));
23667 }
23668 #endif
23669 }
23670
23671 /* Various frobbings of labels and their addresses. */
23672
23673 void
23674 arm_start_line_hook (void)
23675 {
23676 last_label_seen = NULL;
23677 }
23678
23679 void
23680 arm_frob_label (symbolS * sym)
23681 {
23682 last_label_seen = sym;
23683
23684 ARM_SET_THUMB (sym, thumb_mode);
23685
23686 #if defined OBJ_COFF || defined OBJ_ELF
23687 ARM_SET_INTERWORK (sym, support_interwork);
23688 #endif
23689
23690 force_automatic_it_block_close ();
23691
23692 /* Note - do not allow local symbols (.Lxxx) to be labelled
23693 as Thumb functions. This is because these labels, whilst
23694 they exist inside Thumb code, are not the entry points for
23695 possible ARM->Thumb calls. Also, these labels can be used
23696 as part of a computed goto or switch statement. eg gcc
23697 can generate code that looks like this:
23698
23699 ldr r2, [pc, .Laaa]
23700 lsl r3, r3, #2
23701 ldr r2, [r3, r2]
23702 mov pc, r2
23703
23704 .Lbbb: .word .Lxxx
23705 .Lccc: .word .Lyyy
23706 ..etc...
23707 .Laaa: .word Lbbb
23708
23709 The first instruction loads the address of the jump table.
23710 The second instruction converts a table index into a byte offset.
23711 The third instruction gets the jump address out of the table.
23712 The fourth instruction performs the jump.
23713
23714 If the address stored at .Laaa is that of a symbol which has the
23715 Thumb_Func bit set, then the linker will arrange for this address
23716 to have the bottom bit set, which in turn would mean that the
23717 address computation performed by the third instruction would end
23718 up with the bottom bit set. Since the ARM is capable of unaligned
23719 word loads, the instruction would then load the incorrect address
23720 out of the jump table, and chaos would ensue. */
23721 if (label_is_thumb_function_name
23722 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
23723 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
23724 {
23725 /* When the address of a Thumb function is taken the bottom
23726 bit of that address should be set. This will allow
23727 interworking between Arm and Thumb functions to work
23728 correctly. */
23729
23730 THUMB_SET_FUNC (sym, 1);
23731
23732 label_is_thumb_function_name = false;
23733 }
23734
23735 dwarf2_emit_label (sym);
23736 }
23737
23738 bool
23739 arm_data_in_code (void)
23740 {
23741 if (thumb_mode && startswith (input_line_pointer + 1, "data:"))
23742 {
23743 *input_line_pointer = '/';
23744 input_line_pointer += 5;
23745 *input_line_pointer = 0;
23746 return true;
23747 }
23748
23749 return false;
23750 }
23751
23752 char *
23753 arm_canonicalize_symbol_name (char * name)
23754 {
23755 int len;
23756
23757 if (thumb_mode && (len = strlen (name)) > 5
23758 && streq (name + len - 5, "/data"))
23759 *(name + len - 5) = 0;
23760
23761 return name;
23762 }
23763 \f
23764 /* Table of all register names defined by default. The user can
23765 define additional names with .req. Note that all register names
23766 should appear in both upper and lowercase variants. Some registers
23767 also have mixed-case names. */
23768
23769 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, true, 0 }
23770 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
23771 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
23772 #define REGSET(p,t) \
23773 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
23774 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
23775 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
23776 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
23777 #define REGSETH(p,t) \
23778 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
23779 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
23780 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
23781 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
23782 #define REGSET2(p,t) \
23783 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
23784 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
23785 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
23786 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
23787 #define SPLRBANK(base,bank,t) \
23788 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
23789 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
23790 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
23791 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
23792 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
23793 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
23794
23795 static const struct reg_entry reg_names[] =
23796 {
23797 /* ARM integer registers. */
23798 REGSET(r, RN), REGSET(R, RN),
23799
23800 /* ATPCS synonyms. */
23801 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
23802 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
23803 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
23804
23805 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
23806 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
23807 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
23808
23809 /* Well-known aliases. */
23810 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
23811 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
23812
23813 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
23814 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
23815
23816 /* Defining the new Zero register from ARMv8.1-M. */
23817 REGDEF(zr,15,ZR),
23818 REGDEF(ZR,15,ZR),
23819
23820 /* Coprocessor numbers. */
23821 REGSET(p, CP), REGSET(P, CP),
23822
23823 /* Coprocessor register numbers. The "cr" variants are for backward
23824 compatibility. */
23825 REGSET(c, CN), REGSET(C, CN),
23826 REGSET(cr, CN), REGSET(CR, CN),
23827
23828 /* ARM banked registers. */
23829 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
23830 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
23831 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
23832 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
23833 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
23834 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
23835 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
23836
23837 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
23838 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
23839 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
23840 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
23841 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
23842 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
23843 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23844 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23845
23846 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23847 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23848 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23849 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23850 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23851 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23852 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
23853 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
23854 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23855
23856 /* FPA registers. */
23857 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23858 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23859
23860 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23861 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23862
23863 /* VFP SP registers. */
23864 REGSET(s,VFS), REGSET(S,VFS),
23865 REGSETH(s,VFS), REGSETH(S,VFS),
23866
23867 /* VFP DP Registers. */
23868 REGSET(d,VFD), REGSET(D,VFD),
23869 /* Extra Neon DP registers. */
23870 REGSETH(d,VFD), REGSETH(D,VFD),
23871
23872 /* Neon QP registers. */
23873 REGSET2(q,NQ), REGSET2(Q,NQ),
23874
23875 /* VFP control registers. */
23876 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23877 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
23878 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23879 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23880 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23881 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
23882 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
23883 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23884 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23885 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23886 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
23887
23888 /* Maverick DSP coprocessor registers. */
23889 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23890 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23891
23892 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23893 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23894 REGDEF(dspsc,0,DSPSC),
23895
23896 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23897 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23898 REGDEF(DSPSC,0,DSPSC),
23899
23900 /* iWMMXt data registers - p0, c0-15. */
23901 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23902
23903 /* iWMMXt control registers - p1, c0-3. */
23904 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23905 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23906 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23907 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23908
23909 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23910 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23911 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23912 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23913 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23914
23915 /* XScale accumulator registers. */
23916 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23917
23918 /* Alias 'ra_auth_code' to r12 for pacbti. */
23919 REGDEF(ra_auth_code,12,RN),
23920 };
23921 #undef REGDEF
23922 #undef REGNUM
23923 #undef REGSET
23924
23925 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23926 within psr_required_here. */
23927 static const struct asm_psr psrs[] =
23928 {
23929 /* Backward compatibility notation. Note that "all" is no longer
23930 truly all possible PSR bits. */
23931 {"all", PSR_c | PSR_f},
23932 {"flg", PSR_f},
23933 {"ctl", PSR_c},
23934
23935 /* Individual flags. */
23936 {"f", PSR_f},
23937 {"c", PSR_c},
23938 {"x", PSR_x},
23939 {"s", PSR_s},
23940
23941 /* Combinations of flags. */
23942 {"fs", PSR_f | PSR_s},
23943 {"fx", PSR_f | PSR_x},
23944 {"fc", PSR_f | PSR_c},
23945 {"sf", PSR_s | PSR_f},
23946 {"sx", PSR_s | PSR_x},
23947 {"sc", PSR_s | PSR_c},
23948 {"xf", PSR_x | PSR_f},
23949 {"xs", PSR_x | PSR_s},
23950 {"xc", PSR_x | PSR_c},
23951 {"cf", PSR_c | PSR_f},
23952 {"cs", PSR_c | PSR_s},
23953 {"cx", PSR_c | PSR_x},
23954 {"fsx", PSR_f | PSR_s | PSR_x},
23955 {"fsc", PSR_f | PSR_s | PSR_c},
23956 {"fxs", PSR_f | PSR_x | PSR_s},
23957 {"fxc", PSR_f | PSR_x | PSR_c},
23958 {"fcs", PSR_f | PSR_c | PSR_s},
23959 {"fcx", PSR_f | PSR_c | PSR_x},
23960 {"sfx", PSR_s | PSR_f | PSR_x},
23961 {"sfc", PSR_s | PSR_f | PSR_c},
23962 {"sxf", PSR_s | PSR_x | PSR_f},
23963 {"sxc", PSR_s | PSR_x | PSR_c},
23964 {"scf", PSR_s | PSR_c | PSR_f},
23965 {"scx", PSR_s | PSR_c | PSR_x},
23966 {"xfs", PSR_x | PSR_f | PSR_s},
23967 {"xfc", PSR_x | PSR_f | PSR_c},
23968 {"xsf", PSR_x | PSR_s | PSR_f},
23969 {"xsc", PSR_x | PSR_s | PSR_c},
23970 {"xcf", PSR_x | PSR_c | PSR_f},
23971 {"xcs", PSR_x | PSR_c | PSR_s},
23972 {"cfs", PSR_c | PSR_f | PSR_s},
23973 {"cfx", PSR_c | PSR_f | PSR_x},
23974 {"csf", PSR_c | PSR_s | PSR_f},
23975 {"csx", PSR_c | PSR_s | PSR_x},
23976 {"cxf", PSR_c | PSR_x | PSR_f},
23977 {"cxs", PSR_c | PSR_x | PSR_s},
23978 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23979 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23980 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23981 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23982 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23983 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23984 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23985 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23986 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23987 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23988 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23989 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23990 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23991 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23992 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23993 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23994 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23995 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23996 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23997 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23998 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23999 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
24000 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
24001 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
24002 };
24003
24004 /* Table of V7M psr names. */
24005 static const struct asm_psr v7m_psrs[] =
24006 {
24007 {"apsr", 0x0 }, {"APSR", 0x0 },
24008 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
24009 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
24010 {"psr", 0x3 }, {"PSR", 0x3 },
24011 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
24012 {"ipsr", 0x5 }, {"IPSR", 0x5 },
24013 {"epsr", 0x6 }, {"EPSR", 0x6 },
24014 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
24015 {"msp", 0x8 }, {"MSP", 0x8 },
24016 {"psp", 0x9 }, {"PSP", 0x9 },
24017 {"msplim", 0xa }, {"MSPLIM", 0xa },
24018 {"psplim", 0xb }, {"PSPLIM", 0xb },
24019 {"primask", 0x10}, {"PRIMASK", 0x10},
24020 {"basepri", 0x11}, {"BASEPRI", 0x11},
24021 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
24022 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
24023 {"control", 0x14}, {"CONTROL", 0x14},
24024 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
24025 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
24026 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
24027 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
24028 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
24029 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
24030 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
24031 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
24032 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
24033 };
24034
24035 /* Table of all shift-in-operand names. */
24036 static const struct asm_shift_name shift_names [] =
24037 {
24038 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
24039 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
24040 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
24041 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
24042 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
24043 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
24044 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
24045 };
24046
24047 /* Table of all explicit relocation names. */
24048 #ifdef OBJ_ELF
24049 static struct reloc_entry reloc_names[] =
24050 {
24051 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
24052 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
24053 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
24054 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
24055 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
24056 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
24057 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
24058 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
24059 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
24060 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
24061 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
24062 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
24063 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
24064 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
24065 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
24066 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
24067 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
24068 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
24069 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
24070 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
24071 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24072 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
24073 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
24074 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
24075 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
24076 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
24077 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
24078 };
24079 #endif
24080
24081 /* Table of all conditional affixes. */
24082 static const struct asm_cond conds[] =
24083 {
24084 {"eq", 0x0},
24085 {"ne", 0x1},
24086 {"cs", 0x2}, {"hs", 0x2},
24087 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
24088 {"mi", 0x4},
24089 {"pl", 0x5},
24090 {"vs", 0x6},
24091 {"vc", 0x7},
24092 {"hi", 0x8},
24093 {"ls", 0x9},
24094 {"ge", 0xa},
24095 {"lt", 0xb},
24096 {"gt", 0xc},
24097 {"le", 0xd},
24098 {"al", 0xe}
24099 };
24100 static const struct asm_cond vconds[] =
24101 {
24102 {"t", 0xf},
24103 {"e", 0x10}
24104 };
24105
24106 #define UL_BARRIER(L,U,CODE,FEAT) \
24107 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
24108 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
24109
24110 static struct asm_barrier_opt barrier_opt_names[] =
24111 {
24112 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
24113 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
24114 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
24115 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
24116 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
24117 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
24118 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
24119 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
24120 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
24121 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
24122 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
24123 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
24124 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
24125 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
24126 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
24127 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
24128 };
24129
24130 #undef UL_BARRIER
24131
24132 /* Table of ARM-format instructions. */
24133
24134 /* Macros for gluing together operand strings. N.B. In all cases
24135 other than OPS0, the trailing OP_stop comes from default
24136 zero-initialization of the unspecified elements of the array. */
24137 #define OPS0() { OP_stop, }
24138 #define OPS1(a) { OP_##a, }
24139 #define OPS2(a,b) { OP_##a,OP_##b, }
24140 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
24141 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
24142 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
24143 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
24144
24145 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
24146 This is useful when mixing operands for ARM and THUMB, i.e. using the
24147 MIX_ARM_THUMB_OPERANDS macro.
24148 In order to use these macros, prefix the number of operands with _
24149 e.g. _3. */
24150 #define OPS_1(a) { a, }
24151 #define OPS_2(a,b) { a,b, }
24152 #define OPS_3(a,b,c) { a,b,c, }
24153 #define OPS_4(a,b,c,d) { a,b,c,d, }
24154 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
24155 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
24156
24157 /* These macros abstract out the exact format of the mnemonic table and
24158 save some repeated characters. */
24159
24160 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
24161 #define TxCE(mnem, op, top, nops, ops, ae, te) \
24162 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
24163 THUMB_VARIANT, do_##ae, do_##te, 0 }
24164
24165 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
24166 a T_MNEM_xyz enumerator. */
24167 #define TCE(mnem, aop, top, nops, ops, ae, te) \
24168 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
24169 #define tCE(mnem, aop, top, nops, ops, ae, te) \
24170 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24171
24172 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
24173 infix after the third character. */
24174 #define TxC3(mnem, op, top, nops, ops, ae, te) \
24175 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
24176 THUMB_VARIANT, do_##ae, do_##te, 0 }
24177 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
24178 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
24179 THUMB_VARIANT, do_##ae, do_##te, 0 }
24180 #define TC3(mnem, aop, top, nops, ops, ae, te) \
24181 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
24182 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
24183 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
24184 #define tC3(mnem, aop, top, nops, ops, ae, te) \
24185 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24186 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
24187 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
24188
24189 /* Mnemonic that cannot be conditionalized. The ARM condition-code
24190 field is still 0xE. Many of the Thumb variants can be executed
24191 conditionally, so this is checked separately. */
24192 #define TUE(mnem, op, top, nops, ops, ae, te) \
24193 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24194 THUMB_VARIANT, do_##ae, do_##te, 0 }
24195
24196 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
24197 Used by mnemonics that have very minimal differences in the encoding for
24198 ARM and Thumb variants and can be handled in a common function. */
24199 #define TUEc(mnem, op, top, nops, ops, en) \
24200 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
24201 THUMB_VARIANT, do_##en, do_##en, 0 }
24202
24203 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
24204 condition code field. */
24205 #define TUF(mnem, op, top, nops, ops, ae, te) \
24206 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
24207 THUMB_VARIANT, do_##ae, do_##te, 0 }
24208
24209 /* ARM-only variants of all the above. */
24210 #define CE(mnem, op, nops, ops, ae) \
24211 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24212
24213 #define C3(mnem, op, nops, ops, ae) \
24214 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24215
24216 /* Thumb-only variants of TCE and TUE. */
24217 #define ToC(mnem, top, nops, ops, te) \
24218 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24219 do_##te, 0 }
24220
24221 #define ToU(mnem, top, nops, ops, te) \
24222 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
24223 NULL, do_##te, 0 }
24224
24225 /* T_MNEM_xyz enumerator variants of ToC. */
24226 #define toC(mnem, top, nops, ops, te) \
24227 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
24228 do_##te, 0 }
24229
24230 /* T_MNEM_xyz enumerator variants of ToU. */
24231 #define toU(mnem, top, nops, ops, te) \
24232 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
24233 NULL, do_##te, 0 }
24234
24235 /* Legacy mnemonics that always have conditional infix after the third
24236 character. */
24237 #define CL(mnem, op, nops, ops, ae) \
24238 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24239 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24240
24241 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
24242 #define cCE(mnem, op, nops, ops, ae) \
24243 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24244
24245 /* mov instructions that are shared between coprocessor and MVE. */
24246 #define mcCE(mnem, op, nops, ops, ae) \
24247 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
24248
24249 /* Legacy coprocessor instructions where conditional infix and conditional
24250 suffix are ambiguous. For consistency this includes all FPA instructions,
24251 not just the potentially ambiguous ones. */
24252 #define cCL(mnem, op, nops, ops, ae) \
24253 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
24254 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24255
24256 /* Coprocessor, takes either a suffix or a position-3 infix
24257 (for an FPA corner case). */
24258 #define C3E(mnem, op, nops, ops, ae) \
24259 { mnem, OPS##nops ops, OT_csuf_or_in3, \
24260 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
24261
24262 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
24263 { m1 #m2 m3, OPS##nops ops, \
24264 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
24265 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24266
24267 #define CM(m1, m2, op, nops, ops, ae) \
24268 xCM_ (m1, , m2, op, nops, ops, ae), \
24269 xCM_ (m1, eq, m2, op, nops, ops, ae), \
24270 xCM_ (m1, ne, m2, op, nops, ops, ae), \
24271 xCM_ (m1, cs, m2, op, nops, ops, ae), \
24272 xCM_ (m1, hs, m2, op, nops, ops, ae), \
24273 xCM_ (m1, cc, m2, op, nops, ops, ae), \
24274 xCM_ (m1, ul, m2, op, nops, ops, ae), \
24275 xCM_ (m1, lo, m2, op, nops, ops, ae), \
24276 xCM_ (m1, mi, m2, op, nops, ops, ae), \
24277 xCM_ (m1, pl, m2, op, nops, ops, ae), \
24278 xCM_ (m1, vs, m2, op, nops, ops, ae), \
24279 xCM_ (m1, vc, m2, op, nops, ops, ae), \
24280 xCM_ (m1, hi, m2, op, nops, ops, ae), \
24281 xCM_ (m1, ls, m2, op, nops, ops, ae), \
24282 xCM_ (m1, ge, m2, op, nops, ops, ae), \
24283 xCM_ (m1, lt, m2, op, nops, ops, ae), \
24284 xCM_ (m1, gt, m2, op, nops, ops, ae), \
24285 xCM_ (m1, le, m2, op, nops, ops, ae), \
24286 xCM_ (m1, al, m2, op, nops, ops, ae)
24287
24288 #define UE(mnem, op, nops, ops, ae) \
24289 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24290
24291 #define UF(mnem, op, nops, ops, ae) \
24292 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
24293
24294 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
24295 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
24296 use the same encoding function for each. */
24297 #define NUF(mnem, op, nops, ops, enc) \
24298 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24299 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24300
24301 /* Neon data processing, version which indirects through neon_enc_tab for
24302 the various overloaded versions of opcodes. */
24303 #define nUF(mnem, op, nops, ops, enc) \
24304 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24305 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
24306
24307 /* Neon insn with conditional suffix for the ARM version, non-overloaded
24308 version. */
24309 #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24310 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
24311 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24312
24313 #define NCE(mnem, op, nops, ops, enc) \
24314 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24315
24316 #define NCEF(mnem, op, nops, ops, enc) \
24317 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24318
24319 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
24320 #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
24321 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
24322 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
24323
24324 #define nCE(mnem, op, nops, ops, enc) \
24325 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
24326
24327 #define nCEF(mnem, op, nops, ops, enc) \
24328 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
24329
24330 /* */
24331 #define mCEF(mnem, op, nops, ops, enc) \
24332 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
24333 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24334
24335
24336 /* nCEF but for MVE predicated instructions. */
24337 #define mnCEF(mnem, op, nops, ops, enc) \
24338 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24339
24340 /* nCE but for MVE predicated instructions. */
24341 #define mnCE(mnem, op, nops, ops, enc) \
24342 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24343
24344 /* NUF but for potentially MVE predicated instructions. */
24345 #define MNUF(mnem, op, nops, ops, enc) \
24346 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
24347 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24348
24349 /* nUF but for potentially MVE predicated instructions. */
24350 #define mnUF(mnem, op, nops, ops, enc) \
24351 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
24352 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
24353
24354 /* ToC but for potentially MVE predicated instructions. */
24355 #define mToC(mnem, top, nops, ops, te) \
24356 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
24357 do_##te, 1 }
24358
24359 /* NCE but for MVE predicated instructions. */
24360 #define MNCE(mnem, op, nops, ops, enc) \
24361 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
24362
24363 /* NCEF but for MVE predicated instructions. */
24364 #define MNCEF(mnem, op, nops, ops, enc) \
24365 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
24366 #define do_0 0
24367
24368 static const struct asm_opcode insns[] =
24369 {
24370 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
24371 #define THUMB_VARIANT & arm_ext_v4t
24372 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
24373 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
24374 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
24375 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
24376 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
24377 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
24378 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
24379 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
24380 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
24381 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
24382 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
24383 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
24384 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
24385 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
24386 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
24387 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
24388
24389 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
24390 for setting PSR flag bits. They are obsolete in V6 and do not
24391 have Thumb equivalents. */
24392 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24393 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
24394 CL("tstp", 110f000, 2, (RR, SH), cmp),
24395 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24396 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
24397 CL("cmpp", 150f000, 2, (RR, SH), cmp),
24398 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24399 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
24400 CL("cmnp", 170f000, 2, (RR, SH), cmp),
24401
24402 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
24403 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
24404 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
24405 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
24406
24407 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
24408 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24409 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
24410 OP_RRnpc),
24411 OP_ADDRGLDR),ldst, t_ldst),
24412 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
24413
24414 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24415 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24416 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24417 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24418 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24419 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24420
24421 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
24422 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
24423
24424 /* Pseudo ops. */
24425 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
24426 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
24427 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
24428 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
24429
24430 /* Thumb-compatibility pseudo ops. */
24431 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
24432 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
24433 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
24434 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
24435 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
24436 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
24437 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
24438 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
24439 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
24440 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
24441 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
24442 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
24443
24444 /* These may simplify to neg. */
24445 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
24446 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
24447
24448 #undef THUMB_VARIANT
24449 #define THUMB_VARIANT & arm_ext_os
24450
24451 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
24452 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
24453
24454 #undef THUMB_VARIANT
24455 #define THUMB_VARIANT & arm_ext_v6
24456
24457 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
24458
24459 /* V1 instructions with no Thumb analogue prior to V6T2. */
24460 #undef THUMB_VARIANT
24461 #define THUMB_VARIANT & arm_ext_v6t2
24462
24463 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24464 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
24465 CL("teqp", 130f000, 2, (RR, SH), cmp),
24466
24467 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24468 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24469 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
24470 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
24471
24472 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24473 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24474
24475 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24476 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
24477
24478 /* V1 instructions with no Thumb analogue at all. */
24479 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
24480 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
24481
24482 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
24483 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
24484 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
24485 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
24486 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
24487 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
24488 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
24489 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
24490
24491 #undef ARM_VARIANT
24492 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
24493 #undef THUMB_VARIANT
24494 #define THUMB_VARIANT & arm_ext_v4t
24495
24496 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24497 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
24498
24499 #undef THUMB_VARIANT
24500 #define THUMB_VARIANT & arm_ext_v6t2
24501
24502 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24503 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
24504
24505 /* Generic coprocessor instructions. */
24506 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24507 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24508 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24509 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24510 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24511 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24512 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
24513
24514 #undef ARM_VARIANT
24515 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
24516
24517 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24518 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
24519
24520 #undef ARM_VARIANT
24521 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
24522 #undef THUMB_VARIANT
24523 #define THUMB_VARIANT & arm_ext_msr
24524
24525 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
24526 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
24527
24528 #undef ARM_VARIANT
24529 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
24530 #undef THUMB_VARIANT
24531 #define THUMB_VARIANT & arm_ext_v6t2
24532
24533 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24534 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24535 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24536 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24537 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24538 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24539 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
24540 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
24541
24542 #undef ARM_VARIANT
24543 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
24544 #undef THUMB_VARIANT
24545 #define THUMB_VARIANT & arm_ext_v4t
24546
24547 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24548 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24549 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24550 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24551 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24552 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
24553
24554 #undef ARM_VARIANT
24555 #define ARM_VARIANT & arm_ext_v4t_5
24556
24557 /* ARM Architecture 4T. */
24558 /* Note: bx (and blx) are required on V5, even if the processor does
24559 not support Thumb. */
24560 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
24561
24562 #undef ARM_VARIANT
24563 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
24564 #undef THUMB_VARIANT
24565 #define THUMB_VARIANT & arm_ext_v5t
24566
24567 /* Note: blx has 2 variants; the .value coded here is for
24568 BLX(2). Only this variant has conditional execution. */
24569 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
24570 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
24571
24572 #undef THUMB_VARIANT
24573 #define THUMB_VARIANT & arm_ext_v6t2
24574
24575 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
24576 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24577 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24578 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24579 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
24580 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
24581 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24582 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
24583
24584 #undef ARM_VARIANT
24585 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
24586 #undef THUMB_VARIANT
24587 #define THUMB_VARIANT & arm_ext_v5exp
24588
24589 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24590 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24591 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24592 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24593
24594 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24595 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
24596
24597 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24598 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24599 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24600 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
24601
24602 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24603 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24604 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24605 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24606
24607 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24608 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24609
24610 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24611 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24612 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24613 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
24614
24615 #undef ARM_VARIANT
24616 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
24617 #undef THUMB_VARIANT
24618 #define THUMB_VARIANT & arm_ext_v6t2
24619
24620 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
24621 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
24622 ldrd, t_ldstd),
24623 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
24624 ADDRGLDRS), ldrd, t_ldstd),
24625
24626 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24627 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24628
24629 #undef ARM_VARIANT
24630 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
24631
24632 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
24633
24634 #undef ARM_VARIANT
24635 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
24636 #undef THUMB_VARIANT
24637 #define THUMB_VARIANT & arm_ext_v6
24638
24639 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
24640 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
24641 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24642 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24643 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
24644 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24645 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24646 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24647 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24648 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
24649
24650 #undef THUMB_VARIANT
24651 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24652
24653 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
24654 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24655 strex, t_strex),
24656 #undef THUMB_VARIANT
24657 #define THUMB_VARIANT & arm_ext_v6t2
24658
24659 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24660 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
24661
24662 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
24663 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
24664
24665 /* ARM V6 not included in V7M. */
24666 #undef THUMB_VARIANT
24667 #define THUMB_VARIANT & arm_ext_v6_notm
24668 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24669 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24670 UF(rfeib, 9900a00, 1, (RRw), rfe),
24671 UF(rfeda, 8100a00, 1, (RRw), rfe),
24672 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24673 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
24674 UF(rfefa, 8100a00, 1, (RRw), rfe),
24675 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
24676 UF(rfeed, 9900a00, 1, (RRw), rfe),
24677 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24678 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24679 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
24680 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
24681 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
24682 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
24683 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
24684 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24685 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
24686 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
24687
24688 /* ARM V6 not included in V7M (eg. integer SIMD). */
24689 #undef THUMB_VARIANT
24690 #define THUMB_VARIANT & arm_ext_v6_dsp
24691 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
24692 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
24693 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24694 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24695 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24696 /* Old name for QASX. */
24697 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24698 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24699 /* Old name for QSAX. */
24700 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24701 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24702 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24703 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24704 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24705 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24706 /* Old name for SASX. */
24707 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24708 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24709 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24710 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24711 /* Old name for SHASX. */
24712 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24713 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24714 /* Old name for SHSAX. */
24715 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24716 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24717 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24718 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24719 /* Old name for SSAX. */
24720 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24721 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24722 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24723 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24724 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24725 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24726 /* Old name for UASX. */
24727 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24728 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24729 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24730 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24731 /* Old name for UHASX. */
24732 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24733 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24734 /* Old name for UHSAX. */
24735 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24736 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24737 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24738 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24739 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24740 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24741 /* Old name for UQASX. */
24742 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24743 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24744 /* Old name for UQSAX. */
24745 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24746 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24747 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24748 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24749 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24750 /* Old name for USAX. */
24751 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24752 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24753 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24754 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24755 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24756 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24757 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24758 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24759 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
24760 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
24761 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
24762 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24763 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24764 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24765 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24766 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24767 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24768 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24769 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
24770 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24771 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24772 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24773 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24774 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24775 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24776 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24777 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24778 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24779 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24780 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
24781 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
24782 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
24783 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
24784 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
24785
24786 #undef ARM_VARIANT
24787 #define ARM_VARIANT & arm_ext_v6k_v6t2
24788 #undef THUMB_VARIANT
24789 #define THUMB_VARIANT & arm_ext_v6k_v6t2
24790
24791 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
24792 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
24793 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
24794 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
24795
24796 #undef THUMB_VARIANT
24797 #define THUMB_VARIANT & arm_ext_v6_notm
24798 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
24799 ldrexd, t_ldrexd),
24800 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
24801 RRnpcb), strexd, t_strexd),
24802
24803 #undef THUMB_VARIANT
24804 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24805 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
24806 rd_rn, rd_rn),
24807 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
24808 rd_rn, rd_rn),
24809 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24810 strex, t_strexbh),
24811 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
24812 strex, t_strexbh),
24813 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
24814
24815 #undef ARM_VARIANT
24816 #define ARM_VARIANT & arm_ext_sec
24817 #undef THUMB_VARIANT
24818 #define THUMB_VARIANT & arm_ext_sec
24819
24820 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
24821
24822 #undef ARM_VARIANT
24823 #define ARM_VARIANT & arm_ext_virt
24824 #undef THUMB_VARIANT
24825 #define THUMB_VARIANT & arm_ext_virt
24826
24827 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
24828 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
24829
24830 #undef ARM_VARIANT
24831 #define ARM_VARIANT & arm_ext_pan
24832 #undef THUMB_VARIANT
24833 #define THUMB_VARIANT & arm_ext_pan
24834
24835 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
24836
24837 #undef ARM_VARIANT
24838 #define ARM_VARIANT & arm_ext_v6t2
24839 #undef THUMB_VARIANT
24840 #define THUMB_VARIANT & arm_ext_v6t2
24841
24842 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
24843 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
24844 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24845 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24846
24847 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24848 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
24849
24850 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24851 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24852 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24853 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24854
24855 #undef ARM_VARIANT
24856 #define ARM_VARIANT & arm_ext_v3
24857 #undef THUMB_VARIANT
24858 #define THUMB_VARIANT & arm_ext_v6t2
24859
24860 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
24861 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24862 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
24863
24864 #undef ARM_VARIANT
24865 #define ARM_VARIANT & arm_ext_v6t2
24866 #undef THUMB_VARIANT
24867 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24868 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24869 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24870
24871 /* Thumb-only instructions. */
24872 #undef ARM_VARIANT
24873 #define ARM_VARIANT NULL
24874 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24875 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
24876
24877 /* ARM does not really have an IT instruction, so always allow it.
24878 The opcode is copied from Thumb in order to allow warnings in
24879 -mimplicit-it=[never | arm] modes. */
24880 #undef ARM_VARIANT
24881 #define ARM_VARIANT & arm_ext_v1
24882 #undef THUMB_VARIANT
24883 #define THUMB_VARIANT & arm_ext_v6t2
24884
24885 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24886 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24887 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24888 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24889 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24890 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24891 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24892 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24893 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24894 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24895 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24896 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24897 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24898 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24899 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
24900 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
24901 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24902 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
24903
24904 /* Thumb2 only instructions. */
24905 #undef ARM_VARIANT
24906 #define ARM_VARIANT NULL
24907
24908 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24909 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24910 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24911 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24912 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24913 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
24914
24915 /* Hardware division instructions. */
24916 #undef ARM_VARIANT
24917 #define ARM_VARIANT & arm_ext_adiv
24918 #undef THUMB_VARIANT
24919 #define THUMB_VARIANT & arm_ext_div
24920
24921 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24922 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
24923
24924 /* ARM V6M/V7 instructions. */
24925 #undef ARM_VARIANT
24926 #define ARM_VARIANT & arm_ext_barrier
24927 #undef THUMB_VARIANT
24928 #define THUMB_VARIANT & arm_ext_barrier
24929
24930 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24931 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24932 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
24933
24934 /* ARM V7 instructions. */
24935 #undef ARM_VARIANT
24936 #define ARM_VARIANT & arm_ext_v7
24937 #undef THUMB_VARIANT
24938 #define THUMB_VARIANT & arm_ext_v7
24939
24940 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24941 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
24942
24943 #undef ARM_VARIANT
24944 #define ARM_VARIANT & arm_ext_mp
24945 #undef THUMB_VARIANT
24946 #define THUMB_VARIANT & arm_ext_mp
24947
24948 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24949
24950 /* AArchv8 instructions. */
24951 #undef ARM_VARIANT
24952 #define ARM_VARIANT & arm_ext_v8
24953
24954 /* Instructions shared between armv8-a and armv8-m. */
24955 #undef THUMB_VARIANT
24956 #define THUMB_VARIANT & arm_ext_atomics
24957
24958 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24959 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24960 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24961 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24962 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24963 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24964 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24965 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24966 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24967 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24968 stlex, t_stlex),
24969 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24970 stlex, t_stlex),
24971 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24972 stlex, t_stlex),
24973 #undef THUMB_VARIANT
24974 #define THUMB_VARIANT & arm_ext_v8
24975
24976 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
24977 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24978 ldrexd, t_ldrexd),
24979 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24980 strexd, t_strexd),
24981 #undef THUMB_VARIANT
24982 #define THUMB_VARIANT & arm_ext_v8r
24983 #undef ARM_VARIANT
24984 #define ARM_VARIANT & arm_ext_v8r
24985
24986 /* ARMv8-R instructions. */
24987 TUF("dfb", 57ff04c, f3bf8f4c, 0, (), noargs, noargs),
24988
24989 /* Defined in V8 but is in undefined encoding space for earlier
24990 architectures. However earlier architectures are required to treat
24991 this instuction as a semihosting trap as well. Hence while not explicitly
24992 defined as such, it is in fact correct to define the instruction for all
24993 architectures. */
24994 #undef THUMB_VARIANT
24995 #define THUMB_VARIANT & arm_ext_v1
24996 #undef ARM_VARIANT
24997 #define ARM_VARIANT & arm_ext_v1
24998 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24999
25000 /* ARMv8 T32 only. */
25001 #undef ARM_VARIANT
25002 #define ARM_VARIANT NULL
25003 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
25004 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
25005 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
25006
25007 /* FP for ARMv8. */
25008 #undef ARM_VARIANT
25009 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
25010 #undef THUMB_VARIANT
25011 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
25012
25013 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
25014 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
25015 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
25016 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
25017 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
25018 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
25019 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
25020 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
25021 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
25022 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
25023 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
25024
25025 /* Crypto v1 extensions. */
25026 #undef ARM_VARIANT
25027 #define ARM_VARIANT & fpu_crypto_ext_armv8
25028 #undef THUMB_VARIANT
25029 #define THUMB_VARIANT & fpu_crypto_ext_armv8
25030
25031 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
25032 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
25033 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
25034 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
25035 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
25036 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
25037 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
25038 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
25039 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
25040 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
25041 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
25042 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
25043 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
25044 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
25045
25046 #undef ARM_VARIANT
25047 #define ARM_VARIANT & arm_ext_crc
25048 #undef THUMB_VARIANT
25049 #define THUMB_VARIANT & arm_ext_crc
25050 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
25051 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
25052 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
25053 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
25054 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
25055 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
25056
25057 /* ARMv8.2 RAS extension. */
25058 #undef ARM_VARIANT
25059 #define ARM_VARIANT & arm_ext_ras
25060 #undef THUMB_VARIANT
25061 #define THUMB_VARIANT & arm_ext_ras
25062 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
25063
25064 #undef ARM_VARIANT
25065 #define ARM_VARIANT & arm_ext_v8_3
25066 #undef THUMB_VARIANT
25067 #define THUMB_VARIANT & arm_ext_v8_3
25068 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
25069
25070 #undef ARM_VARIANT
25071 #define ARM_VARIANT & fpu_neon_ext_dotprod
25072 #undef THUMB_VARIANT
25073 #define THUMB_VARIANT & fpu_neon_ext_dotprod
25074 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
25075 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
25076
25077 #undef ARM_VARIANT
25078 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
25079 #undef THUMB_VARIANT
25080 #define THUMB_VARIANT NULL
25081
25082 cCE("wfs", e200110, 1, (RR), rd),
25083 cCE("rfs", e300110, 1, (RR), rd),
25084 cCE("wfc", e400110, 1, (RR), rd),
25085 cCE("rfc", e500110, 1, (RR), rd),
25086
25087 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
25088 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
25089 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
25090 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
25091
25092 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
25093 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
25094 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
25095 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
25096
25097 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
25098 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
25099 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
25100 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
25101 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
25102 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
25103 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
25104 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
25105 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
25106 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
25107 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
25108 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
25109
25110 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
25111 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
25112 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
25113 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
25114 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
25115 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
25116 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
25117 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
25118 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
25119 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
25120 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
25121 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
25122
25123 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
25124 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
25125 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
25126 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
25127 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
25128 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
25129 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
25130 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
25131 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
25132 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
25133 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
25134 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
25135
25136 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
25137 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
25138 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
25139 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
25140 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
25141 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
25142 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
25143 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
25144 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
25145 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
25146 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
25147 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
25148
25149 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
25150 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
25151 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
25152 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
25153 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
25154 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
25155 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
25156 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
25157 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
25158 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
25159 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
25160 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
25161
25162 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
25163 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
25164 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
25165 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
25166 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
25167 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
25168 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
25169 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
25170 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
25171 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
25172 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
25173 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
25174
25175 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
25176 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
25177 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
25178 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
25179 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
25180 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
25181 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
25182 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
25183 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
25184 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
25185 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
25186 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
25187
25188 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
25189 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
25190 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
25191 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
25192 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
25193 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
25194 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
25195 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
25196 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
25197 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
25198 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
25199 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
25200
25201 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
25202 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
25203 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
25204 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
25205 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
25206 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
25207 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
25208 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
25209 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
25210 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
25211 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
25212 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
25213
25214 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
25215 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
25216 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
25217 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
25218 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
25219 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
25220 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
25221 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
25222 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
25223 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
25224 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
25225 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
25226
25227 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
25228 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
25229 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
25230 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
25231 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
25232 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
25233 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
25234 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
25235 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
25236 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
25237 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
25238 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
25239
25240 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
25241 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
25242 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
25243 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
25244 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
25245 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
25246 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
25247 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
25248 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
25249 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
25250 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
25251 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
25252
25253 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
25254 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
25255 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
25256 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
25257 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
25258 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
25259 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
25260 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
25261 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
25262 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
25263 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
25264 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
25265
25266 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
25267 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
25268 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
25269 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
25270 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
25271 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
25272 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
25273 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
25274 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
25275 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
25276 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
25277 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
25278
25279 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
25280 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
25281 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
25282 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
25283 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
25284 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
25285 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
25286 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
25287 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
25288 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
25289 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
25290 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
25291
25292 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
25293 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
25294 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
25295 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
25296 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
25297 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
25298 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
25299 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
25300 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
25301 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
25302 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
25303 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
25304
25305 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
25306 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
25307 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
25308 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
25309 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
25310 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25311 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25312 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25313 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
25314 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
25315 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
25316 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
25317
25318 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
25319 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
25320 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
25321 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
25322 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
25323 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25324 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25325 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25326 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
25327 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
25328 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
25329 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
25330
25331 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
25332 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
25333 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
25334 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
25335 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
25336 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25337 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25338 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25339 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
25340 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
25341 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
25342 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
25343
25344 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
25345 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
25346 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
25347 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
25348 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
25349 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25350 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25351 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25352 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
25353 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
25354 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
25355 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
25356
25357 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
25358 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
25359 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
25360 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
25361 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
25362 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25363 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25364 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25365 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
25366 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
25367 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
25368 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
25369
25370 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
25371 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
25372 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
25373 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
25374 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
25375 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25376 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25377 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25378 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
25379 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
25380 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
25381 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
25382
25383 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
25384 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
25385 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
25386 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
25387 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
25388 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25389 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25390 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25391 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
25392 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
25393 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
25394 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
25395
25396 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
25397 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
25398 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
25399 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
25400 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
25401 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25402 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25403 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25404 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
25405 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
25406 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
25407 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
25408
25409 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
25410 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
25411 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
25412 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
25413 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
25414 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25415 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25416 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25417 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
25418 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
25419 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
25420 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
25421
25422 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
25423 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
25424 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
25425 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
25426 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
25427 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25428 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25429 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25430 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
25431 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
25432 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
25433 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
25434
25435 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25436 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25437 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25438 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25439 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25440 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25441 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25442 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25443 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25444 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25445 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25446 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25447
25448 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25449 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25450 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25451 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25452 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25453 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25454 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25455 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25456 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25457 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25458 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25459 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25460
25461 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
25462 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
25463 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
25464 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
25465 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
25466 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
25467 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
25468 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
25469 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
25470 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
25471 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
25472 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
25473
25474 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
25475 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
25476 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
25477 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
25478
25479 cCL("flts", e000110, 2, (RF, RR), rn_rd),
25480 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
25481 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
25482 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
25483 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
25484 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
25485 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
25486 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
25487 cCL("flte", e080110, 2, (RF, RR), rn_rd),
25488 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
25489 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
25490 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
25491
25492 /* The implementation of the FIX instruction is broken on some
25493 assemblers, in that it accepts a precision specifier as well as a
25494 rounding specifier, despite the fact that this is meaningless.
25495 To be more compatible, we accept it as well, though of course it
25496 does not set any bits. */
25497 cCE("fix", e100110, 2, (RR, RF), rd_rm),
25498 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
25499 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
25500 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
25501 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
25502 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
25503 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
25504 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
25505 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
25506 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
25507 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
25508 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
25509 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
25510
25511 /* Instructions that were new with the real FPA, call them V2. */
25512 #undef ARM_VARIANT
25513 #define ARM_VARIANT & fpu_fpa_ext_v2
25514
25515 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25516 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25517 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25518 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25519 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25520 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
25521
25522 #undef ARM_VARIANT
25523 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
25524 #undef THUMB_VARIANT
25525 #define THUMB_VARIANT & arm_ext_v6t2
25526 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
25527 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
25528 mcCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25529 mcCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
25530 mcCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25531 mcCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
25532
25533 /* Memory operations. */
25534 mcCE(fldmias, c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25535 mcCE(fldmdbs, d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25536 mcCE(fstmias, c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25537 mcCE(fstmdbs, d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25538 #undef THUMB_VARIANT
25539
25540 /* Moves and type conversions. */
25541 cCE("fmstat", ef1fa10, 0, (), noargs),
25542 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
25543 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
25544 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
25545 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25546 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
25547 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
25548 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
25549 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
25550
25551 /* Memory operations. */
25552 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25553 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25554 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25555 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25556 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25557 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25558 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
25559 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
25560 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25561 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
25562 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25563 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
25564
25565 /* Monadic operations. */
25566 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
25567 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
25568 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
25569
25570 /* Dyadic operations. */
25571 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25572 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25573 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25574 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25575 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25576 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25577 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25578 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25579 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25580
25581 /* Comparisons. */
25582 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
25583 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
25584 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
25585 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
25586
25587 /* Double precision load/store are still present on single precision
25588 implementations. */
25589 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25590 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25591 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25592 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25593 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25594 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
25595 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25596 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
25597
25598 #undef ARM_VARIANT
25599 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
25600
25601 /* Moves and type conversions. */
25602 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25603 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25604 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
25605 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
25606 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
25607 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
25608 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
25609 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
25610 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25611 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25612 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
25613 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
25614
25615 /* Monadic operations. */
25616 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25617 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25618 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25619
25620 /* Dyadic operations. */
25621 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25622 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25623 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25624 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25625 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25626 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25627 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25628 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25629 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25630
25631 /* Comparisons. */
25632 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25633 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
25634 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
25635 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
25636
25637 /* Instructions which may belong to either the Neon or VFP instruction sets.
25638 Individual encoder functions perform additional architecture checks. */
25639 #undef ARM_VARIANT
25640 #define ARM_VARIANT & fpu_vfp_ext_v1xd
25641 #undef THUMB_VARIANT
25642 #define THUMB_VARIANT & arm_ext_v6t2
25643
25644 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25645 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25646 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25647 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25648 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25649 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
25650
25651 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
25652 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
25653
25654 #undef THUMB_VARIANT
25655 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
25656
25657 /* These mnemonics are unique to VFP. */
25658 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
25659 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
25660 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25661 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25662 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25663 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
25664
25665 /* Mnemonics shared by Neon and VFP. */
25666 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
25667
25668 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
25669 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
25670 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
25671 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
25672
25673
25674 /* NOTE: All VMOV encoding is special-cased! */
25675 NCE(vmovq, 0, 1, (VMOV), neon_mov),
25676
25677 #undef THUMB_VARIANT
25678 /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
25679 by different feature bits. Since we are setting the Thumb guard, we can
25680 require Thumb-1 which makes it a nop guard and set the right feature bit in
25681 do_vldr_vstr (). */
25682 #define THUMB_VARIANT & arm_ext_v4t
25683 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25684 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
25685
25686 #undef ARM_VARIANT
25687 #define ARM_VARIANT & arm_ext_fp16
25688 #undef THUMB_VARIANT
25689 #define THUMB_VARIANT & arm_ext_fp16
25690 /* New instructions added from v8.2, allowing the extraction and insertion of
25691 the upper 16 bits of a 32-bit vector register. */
25692 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
25693 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
25694
25695 /* New backported fma/fms instructions optional in v8.2. */
25696 NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
25697 NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
25698
25699 #undef THUMB_VARIANT
25700 #define THUMB_VARIANT & fpu_neon_ext_v1
25701 #undef ARM_VARIANT
25702 #define ARM_VARIANT & fpu_neon_ext_v1
25703
25704 /* Data processing with three registers of the same length. */
25705 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
25706 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
25707 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
25708 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25709 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25710 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
25711 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
25712 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25713 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
25714 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25715 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
25716 /* If not immediate, fall back to neon_dyadic_i64_su.
25717 shl should accept I8 I16 I32 I64,
25718 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
25719 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
25720 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
25721 /* Logic ops, types optional & ignored. */
25722 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25723 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25724 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25725 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
25726 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
25727 /* Bitfield ops, untyped. */
25728 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25729 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25730 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25731 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25732 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
25733 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
25734 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
25735 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25736 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25737 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
25738 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
25739 back to neon_dyadic_if_su. */
25740 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25741 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25742 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
25743 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
25744 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25745 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25746 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
25747 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
25748 /* Comparison. Type I8 I16 I32 F32. */
25749 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
25750 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
25751 /* As above, D registers only. */
25752 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25753 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
25754 /* Int and float variants, signedness unimportant. */
25755 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25756 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
25757 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
25758 /* Add/sub take types I8 I16 I32 I64 F32. */
25759 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25760 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
25761 /* vtst takes sizes 8, 16, 32. */
25762 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
25763 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
25764 /* VMUL takes I8 I16 I32 F32 P8. */
25765 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
25766 /* VQD{R}MULH takes S16 S32. */
25767 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25768 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
25769 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25770 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25771 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
25772 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
25773 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25774 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25775 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
25776 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
25777 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25778 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25779 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
25780 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
25781 /* ARM v8.1 extension. */
25782 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25783 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
25784 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
25785
25786 /* Two address, int/float. Types S8 S16 S32 F32. */
25787 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
25788 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
25789
25790 /* Data processing with two registers and a shift amount. */
25791 /* Right shifts, and variants with rounding.
25792 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
25793 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25794 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
25795 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25796 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25797 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
25798 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
25799 /* Shift and insert. Sizes accepted 8 16 32 64. */
25800 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
25801 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
25802 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
25803 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
25804 /* Right shift immediate, saturating & narrowing, with rounding variants.
25805 Types accepted S16 S32 S64 U16 U32 U64. */
25806 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25807 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
25808 /* As above, unsigned. Types accepted S16 S32 S64. */
25809 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25810 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
25811 /* Right shift narrowing. Types accepted I16 I32 I64. */
25812 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25813 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
25814 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
25815 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
25816 /* CVT with optional immediate for fixed-point variant. */
25817 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
25818
25819 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
25820
25821 /* Data processing, three registers of different lengths. */
25822 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
25823 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
25824 /* If not scalar, fall back to neon_dyadic_long.
25825 Vector types as above, scalar types S16 S32 U16 U32. */
25826 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25827 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
25828 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
25829 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25830 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
25831 /* Dyadic, narrowing insns. Types I16 I32 I64. */
25832 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25833 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25834 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25835 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
25836 /* Saturating doubling multiplies. Types S16 S32. */
25837 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25838 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25839 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
25840 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
25841 S16 S32 U16 U32. */
25842 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
25843
25844 /* Extract. Size 8. */
25845 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
25846 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
25847
25848 /* Two registers, miscellaneous. */
25849 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
25850 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
25851 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
25852 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
25853 /* Vector replicate. Sizes 8 16 32. */
25854 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
25855 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
25856 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
25857 /* VMOVN. Types I16 I32 I64. */
25858 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
25859 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
25860 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
25861 /* VQMOVUN. Types S16 S32 S64. */
25862 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
25863 /* VZIP / VUZP. Sizes 8 16 32. */
25864 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25865 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25866 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25867 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25868 /* VQABS / VQNEG. Types S8 S16 S32. */
25869 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
25870 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25871 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25872 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25873 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25874 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25875 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
25876 /* Reciprocal estimates. Types U32 F16 F32. */
25877 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25878 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25879 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25880 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25881 /* VCLS. Types S8 S16 S32. */
25882 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25883 /* VCLZ. Types I8 I16 I32. */
25884 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25885 /* VCNT. Size 8. */
25886 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25887 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25888 /* Two address, untyped. */
25889 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25890 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25891 /* VTRN. Sizes 8 16 32. */
25892 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25893 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
25894
25895 /* Table lookup. Size 8. */
25896 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25897 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25898
25899 #undef THUMB_VARIANT
25900 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25901 #undef ARM_VARIANT
25902 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25903
25904 /* Neon element/structure load/store. */
25905 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25906 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25907 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25908 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25909 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25910 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25911 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25912 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25913
25914 #undef THUMB_VARIANT
25915 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
25916 #undef ARM_VARIANT
25917 #define ARM_VARIANT & fpu_vfp_ext_v3xd
25918 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25919 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25920 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25921 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25922 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25923 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25924 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25925 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25926 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25927
25928 #undef THUMB_VARIANT
25929 #define THUMB_VARIANT & fpu_vfp_ext_v3
25930 #undef ARM_VARIANT
25931 #define ARM_VARIANT & fpu_vfp_ext_v3
25932
25933 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
25934 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25935 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25936 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25937 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25938 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25939 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25940 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25941 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25942
25943 #undef ARM_VARIANT
25944 #define ARM_VARIANT & fpu_vfp_ext_fma
25945 #undef THUMB_VARIANT
25946 #define THUMB_VARIANT & fpu_vfp_ext_fma
25947 /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the
25948 VFP FMA variant; NEON and VFP FMA always includes the NEON
25949 FMA instructions. */
25950 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
25951 TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma),
25952 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25953
25954 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25955 the v form should always be used. */
25956 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25957 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25958 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25959 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25960 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25961 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25962
25963 #undef THUMB_VARIANT
25964 #undef ARM_VARIANT
25965 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25966
25967 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25968 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25969 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25970 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25971 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25972 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25973 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25974 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
25975
25976 #undef ARM_VARIANT
25977 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25978
25979 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25980 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25981 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25982 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25983 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25984 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25985 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25986 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25987 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
25988 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25989 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25990 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25991 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25992 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25993 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25994 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25995 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25996 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25997 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25998 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25999 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
26000 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
26001 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
26002 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
26003 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
26004 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
26005 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
26006 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
26007 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
26008 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
26009 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
26010 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
26011 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
26012 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
26013 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
26014 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
26015 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
26016 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26017 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26018 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26019 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26020 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26021 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26022 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26023 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26024 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26025 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
26026 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26027 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26028 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26029 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26030 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26031 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26032 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26033 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26034 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26035 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26036 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26037 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26038 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26039 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26040 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26041 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26042 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26043 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26044 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26045 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26046 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26047 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26048 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26049 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26050 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26051 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26052 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26053 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26054 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26055 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26056 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26057 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26058 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26059 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26060 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26061 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26062 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26063 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26064 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26065 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26066 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26067 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
26068 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26069 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26070 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26071 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26072 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26073 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26074 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26075 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26076 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26077 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26078 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26079 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26080 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26081 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26082 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26083 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26084 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26085 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26086 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26087 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26088 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26089 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
26090 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26091 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26092 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26093 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26094 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26095 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26096 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26097 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26098 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26099 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26100 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26101 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26102 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26103 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26104 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26105 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26106 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
26107 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
26108 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26109 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
26110 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
26111 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
26112 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26113 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26114 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26115 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26116 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26117 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26118 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26119 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26120 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26121 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
26122 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
26123 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
26124 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
26125 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
26126 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
26127 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26128 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26129 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26130 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
26131 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
26132 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
26133 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
26134 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
26135 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
26136 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26137 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26138 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26139 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26140 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
26141
26142 #undef ARM_VARIANT
26143 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
26144
26145 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
26146 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
26147 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
26148 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
26149 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
26150 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
26151 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26152 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26153 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26154 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26155 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26156 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26157 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26158 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26159 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26160 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26161 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26162 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26163 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26164 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26165 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
26166 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26167 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26168 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26169 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26170 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26171 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26172 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26173 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26174 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26175 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26176 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26177 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26178 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26179 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26180 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26181 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26182 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26183 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26184 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26185 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26186 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26187 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26188 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26189 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26190 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26191 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26192 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26193 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26194 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26195 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26196 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26197 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26198 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26199 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26200 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26201 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
26202
26203 #undef ARM_VARIANT
26204 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
26205
26206 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26207 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26208 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26209 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26210 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
26211 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
26212 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
26213 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
26214 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
26215 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
26216 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
26217 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
26218 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
26219 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
26220 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
26221 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
26222 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
26223 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
26224 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
26225 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
26226 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
26227 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
26228 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
26229 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
26230 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
26231 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
26232 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
26233 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
26234 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
26235 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
26236 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
26237 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
26238 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
26239 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
26240 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
26241 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
26242 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
26243 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
26244 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
26245 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
26246 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
26247 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
26248 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
26249 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
26250 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
26251 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
26252 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
26253 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
26254 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
26255 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
26256 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
26257 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
26258 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
26259 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
26260 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
26261 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
26262 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
26263 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
26264 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
26265 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
26266 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
26267 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
26268 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
26269 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
26270 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26271 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26272 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26273 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26274 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26275 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
26276 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26277 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
26278 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26279 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
26280 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26281 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
26282
26283 /* ARMv8.5-A instructions. */
26284 #undef ARM_VARIANT
26285 #define ARM_VARIANT & arm_ext_sb
26286 #undef THUMB_VARIANT
26287 #define THUMB_VARIANT & arm_ext_sb
26288 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
26289
26290 #undef ARM_VARIANT
26291 #define ARM_VARIANT & arm_ext_predres
26292 #undef THUMB_VARIANT
26293 #define THUMB_VARIANT & arm_ext_predres
26294 CE("cfprctx", e070f93, 1, (RRnpc), rd),
26295 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
26296 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
26297
26298 /* ARMv8-M instructions. */
26299 #undef ARM_VARIANT
26300 #define ARM_VARIANT NULL
26301 #undef THUMB_VARIANT
26302 #define THUMB_VARIANT & arm_ext_v8m
26303 ToU("sg", e97fe97f, 0, (), noargs),
26304 ToC("blxns", 4784, 1, (RRnpc), t_blx),
26305 ToC("bxns", 4704, 1, (RRnpc), t_bx),
26306 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
26307 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
26308 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
26309 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
26310
26311 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
26312 instructions behave as nop if no VFP is present. */
26313 #undef THUMB_VARIANT
26314 #define THUMB_VARIANT & arm_ext_v8m_main
26315 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
26316 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
26317
26318 /* Armv8.1-M Mainline instructions. */
26319 #undef THUMB_VARIANT
26320 #define THUMB_VARIANT & arm_ext_v8_1m_main
26321 toU("aut", _aut, 3, (R12, LR, SP), t_pacbti),
26322 toU("autg", _autg, 3, (RR, RR, RR), t_pacbti_nonop),
26323 ToU("bti", f3af800f, 0, (), noargs),
26324 toU("bxaut", _bxaut, 3, (RR, RR, RR), t_pacbti_nonop),
26325 toU("pac", _pac, 3, (R12, LR, SP), t_pacbti),
26326 toU("pacbti", _pacbti, 3, (R12, LR, SP), t_pacbti),
26327 toU("pacg", _pacg, 3, (RR, RR, RR), t_pacbti_pacg),
26328 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26329 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26330 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
26331 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26332 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
26333 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
26334 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26335 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26336 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
26337
26338 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
26339 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
26340 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
26341 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
26342 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
26343
26344 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
26345 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
26346 toU("le", _le, 2, (oLR, EXP), t_loloop),
26347
26348 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
26349 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
26350
26351 #undef THUMB_VARIANT
26352 #define THUMB_VARIANT & mve_ext
26353 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26354 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26355 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
26356 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26357 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
26358 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
26359 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
26360 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
26361 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
26362 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26363 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
26364 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
26365 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
26366 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
26367 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
26368
26369 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26370 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26371 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26372 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26373 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26374 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26375 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26376 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26377 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26378 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26379 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26380 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26381 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26382 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26383 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
26384
26385 ToC("vpst", fe710f4d, 0, (), mve_vpt),
26386 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
26387 ToC("vpste", fe718f4d, 0, (), mve_vpt),
26388 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
26389 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
26390 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
26391 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
26392 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
26393 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
26394 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
26395 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
26396 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
26397 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
26398 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
26399 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
26400
26401 /* MVE and MVE FP only. */
26402 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
26403 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
26404 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
26405 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
26406 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26407 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
26408 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
26409 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
26410 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26411 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26412 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26413 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26414 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26415 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26416 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
26417 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
26418 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
26419 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
26420
26421 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26422 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26423 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26424 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26425 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26426 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26427 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26428 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
26429 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26430 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26431 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26432 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
26433 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26434 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26435 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26436 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26437 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26438 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26439 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26440 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
26441
26442 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
26443 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
26444 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
26445 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
26446 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
26447 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
26448 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
26449 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
26450 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26451 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
26452 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
26453 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26454 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
26455 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
26456 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
26457 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
26458 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
26459
26460 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26461 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26462 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26463 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26464 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26465 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26466 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26467 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26468 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26469 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
26470 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26471 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26472 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26473 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26474 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26475 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26476 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26477 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26478 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26479 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
26480
26481 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
26482 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26483 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
26484 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
26485 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
26486
26487 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26488 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26489 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26490 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26491 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26492 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26493 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26494 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
26495 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26496 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26497 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
26498 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26499 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
26500 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
26501 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
26502 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
26503 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
26504
26505 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26506 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26507 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26508 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26509 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26510 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26511 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26512 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26513 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26514 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26515 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
26516 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
26517
26518 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
26519 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
26520 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
26521
26522 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
26523 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
26524 toU("letp", _letp, 2, (LR, EXP), t_loloop),
26525 toU("lctp", _lctp, 0, (), t_loloop),
26526
26527 #undef THUMB_VARIANT
26528 #define THUMB_VARIANT & mve_fp_ext
26529 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
26530 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
26531 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26532 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
26533 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
26534 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
26535 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
26536 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
26537
26538 #undef ARM_VARIANT
26539 #define ARM_VARIANT & fpu_vfp_ext_v1
26540 #undef THUMB_VARIANT
26541 #define THUMB_VARIANT & arm_ext_v6t2
26542
26543 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
26544
26545 #undef ARM_VARIANT
26546 #define ARM_VARIANT & fpu_vfp_ext_v1xd
26547
26548 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
26549 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
26550 MNCE(vmov, 0, 1, (VMOV), neon_mov),
26551 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
26552 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
26553 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
26554
26555 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
26556 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26557 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
26558
26559 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26560 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
26561
26562 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
26563 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
26564
26565 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26566 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
26567
26568 #undef ARM_VARIANT
26569 #define ARM_VARIANT & fpu_vfp_ext_v2
26570
26571 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
26572 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
26573 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
26574 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
26575
26576 #undef ARM_VARIANT
26577 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
26578 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
26579 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
26580 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
26581 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
26582 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26583 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
26584
26585 #undef ARM_VARIANT
26586 #define ARM_VARIANT & fpu_neon_ext_v1
26587 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26588 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
26589 mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26590 mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long),
26591 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26592 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26593 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26594 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
26595 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
26596 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
26597 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
26598 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
26599 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26600 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
26601 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
26602 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26603 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
26604 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26605 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
26606 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
26607 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26608 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
26609 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
26610 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26611 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
26612 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26613 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
26614 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26615 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
26616 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
26617 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
26618 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
26619 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
26620 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
26621 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
26622 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
26623 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
26624
26625 #undef ARM_VARIANT
26626 #define ARM_VARIANT & arm_ext_v8_3
26627 #undef THUMB_VARIANT
26628 #define THUMB_VARIANT & arm_ext_v6t2_v8m
26629 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
26630 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
26631
26632 #undef ARM_VARIANT
26633 #define ARM_VARIANT &arm_ext_bf16
26634 #undef THUMB_VARIANT
26635 #define THUMB_VARIANT &arm_ext_bf16
26636 TUF ("vdot", c000d00, fc000d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vdot, vdot),
26637 TUF ("vmmla", c000c40, fc000c40, 3, (RNQ, RNQ, RNQ), vmmla, vmmla),
26638 TUF ("vfmab", c300810, fc300810, 3, (RNDQ, RNDQ, RNDQ_RNSC), bfloat_vfma, bfloat_vfma),
26639
26640 #undef ARM_VARIANT
26641 #define ARM_VARIANT &arm_ext_i8mm
26642 #undef THUMB_VARIANT
26643 #define THUMB_VARIANT &arm_ext_i8mm
26644 TUF ("vsmmla", c200c40, fc200c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26645 TUF ("vummla", c200c50, fc200c50, 3, (RNQ, RNQ, RNQ), vummla, vummla),
26646 TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla),
26647 TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot),
26648 TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot),
26649
26650 #undef ARM_VARIANT
26651 #undef THUMB_VARIANT
26652 #define THUMB_VARIANT &arm_ext_cde
26653 ToC ("cx1", ee000000, 3, (RCP, APSR_RR, I8191), cx1),
26654 ToC ("cx1a", fe000000, 3, (RCP, APSR_RR, I8191), cx1a),
26655 ToC ("cx1d", ee000040, 4, (RCP, RR, APSR_RR, I8191), cx1d),
26656 ToC ("cx1da", fe000040, 4, (RCP, RR, APSR_RR, I8191), cx1da),
26657
26658 ToC ("cx2", ee400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2),
26659 ToC ("cx2a", fe400000, 4, (RCP, APSR_RR, APSR_RR, I511), cx2a),
26660 ToC ("cx2d", ee400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2d),
26661 ToC ("cx2da", fe400040, 5, (RCP, RR, APSR_RR, APSR_RR, I511), cx2da),
26662
26663 ToC ("cx3", ee800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3),
26664 ToC ("cx3a", fe800000, 5, (RCP, APSR_RR, APSR_RR, APSR_RR, I63), cx3a),
26665 ToC ("cx3d", ee800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3d),
26666 ToC ("cx3da", fe800040, 6, (RCP, RR, APSR_RR, APSR_RR, APSR_RR, I63), cx3da),
26667
26668 mToC ("vcx1", ec200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26669 mToC ("vcx1a", fc200000, 3, (RCP, RNSDMQ, I4095), vcx1),
26670
26671 mToC ("vcx2", ec300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26672 mToC ("vcx2a", fc300000, 4, (RCP, RNSDMQ, RNSDMQ, I127), vcx2),
26673
26674 mToC ("vcx3", ec800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26675 mToC ("vcx3a", fc800000, 5, (RCP, RNSDMQ, RNSDMQ, RNSDMQ, I15), vcx3),
26676 };
26677
26678 #undef ARM_VARIANT
26679 #undef THUMB_VARIANT
26680 #undef TCE
26681 #undef TUE
26682 #undef TUF
26683 #undef TCC
26684 #undef cCE
26685 #undef cCL
26686 #undef C3E
26687 #undef C3
26688 #undef CE
26689 #undef CM
26690 #undef CL
26691 #undef UE
26692 #undef UF
26693 #undef UT
26694 #undef NUF
26695 #undef nUF
26696 #undef NCE
26697 #undef nCE
26698 #undef OPS0
26699 #undef OPS1
26700 #undef OPS2
26701 #undef OPS3
26702 #undef OPS4
26703 #undef OPS5
26704 #undef OPS6
26705 #undef do_0
26706 #undef ToC
26707 #undef toC
26708 #undef ToU
26709 #undef toU
26710 \f
26711 /* MD interface: bits in the object file. */
26712
26713 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
26714 for use in the a.out file, and stores them in the array pointed to by buf.
26715 This knows about the endian-ness of the target machine and does
26716 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
26717 2 (short) and 4 (long) Floating numbers are put out as a series of
26718 LITTLENUMS (shorts, here at least). */
26719
26720 void
26721 md_number_to_chars (char * buf, valueT val, int n)
26722 {
26723 if (target_big_endian)
26724 number_to_chars_bigendian (buf, val, n);
26725 else
26726 number_to_chars_littleendian (buf, val, n);
26727 }
26728
26729 static valueT
26730 md_chars_to_number (char * buf, int n)
26731 {
26732 valueT result = 0;
26733 unsigned char * where = (unsigned char *) buf;
26734
26735 if (target_big_endian)
26736 {
26737 while (n--)
26738 {
26739 result <<= 8;
26740 result |= (*where++ & 255);
26741 }
26742 }
26743 else
26744 {
26745 while (n--)
26746 {
26747 result <<= 8;
26748 result |= (where[n] & 255);
26749 }
26750 }
26751
26752 return result;
26753 }
26754
26755 /* MD interface: Sections. */
26756
26757 /* Calculate the maximum variable size (i.e., excluding fr_fix)
26758 that an rs_machine_dependent frag may reach. */
26759
26760 unsigned int
26761 arm_frag_max_var (fragS *fragp)
26762 {
26763 /* We only use rs_machine_dependent for variable-size Thumb instructions,
26764 which are either THUMB_SIZE (2) or INSN_SIZE (4).
26765
26766 Note that we generate relaxable instructions even for cases that don't
26767 really need it, like an immediate that's a trivial constant. So we're
26768 overestimating the instruction size for some of those cases. Rather
26769 than putting more intelligence here, it would probably be better to
26770 avoid generating a relaxation frag in the first place when it can be
26771 determined up front that a short instruction will suffice. */
26772
26773 gas_assert (fragp->fr_type == rs_machine_dependent);
26774 return INSN_SIZE;
26775 }
26776
26777 /* Estimate the size of a frag before relaxing. Assume everything fits in
26778 2 bytes. */
26779
26780 int
26781 md_estimate_size_before_relax (fragS * fragp,
26782 segT segtype ATTRIBUTE_UNUSED)
26783 {
26784 fragp->fr_var = 2;
26785 return 2;
26786 }
26787
26788 /* Convert a machine dependent frag. */
26789
26790 void
26791 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
26792 {
26793 unsigned long insn;
26794 unsigned long old_op;
26795 char *buf;
26796 expressionS exp;
26797 fixS *fixp;
26798 int reloc_type;
26799 int pc_rel;
26800 int opcode;
26801
26802 buf = fragp->fr_literal + fragp->fr_fix;
26803
26804 old_op = bfd_get_16(abfd, buf);
26805 if (fragp->fr_symbol)
26806 {
26807 exp.X_op = O_symbol;
26808 exp.X_add_symbol = fragp->fr_symbol;
26809 }
26810 else
26811 {
26812 exp.X_op = O_constant;
26813 }
26814 exp.X_add_number = fragp->fr_offset;
26815 opcode = fragp->fr_subtype;
26816 switch (opcode)
26817 {
26818 case T_MNEM_ldr_pc:
26819 case T_MNEM_ldr_pc2:
26820 case T_MNEM_ldr_sp:
26821 case T_MNEM_str_sp:
26822 case T_MNEM_ldr:
26823 case T_MNEM_ldrb:
26824 case T_MNEM_ldrh:
26825 case T_MNEM_str:
26826 case T_MNEM_strb:
26827 case T_MNEM_strh:
26828 if (fragp->fr_var == 4)
26829 {
26830 insn = THUMB_OP32 (opcode);
26831 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
26832 {
26833 insn |= (old_op & 0x700) << 4;
26834 }
26835 else
26836 {
26837 insn |= (old_op & 7) << 12;
26838 insn |= (old_op & 0x38) << 13;
26839 }
26840 insn |= 0x00000c00;
26841 put_thumb32_insn (buf, insn);
26842 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
26843 }
26844 else
26845 {
26846 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
26847 }
26848 pc_rel = (opcode == T_MNEM_ldr_pc2);
26849 break;
26850 case T_MNEM_adr:
26851 /* Thumb bits should be set in the frag handling so we process them
26852 after all symbols have been seen. PR gas/25235. */
26853 if (exp.X_op == O_symbol
26854 && exp.X_add_symbol != NULL
26855 && S_IS_DEFINED (exp.X_add_symbol)
26856 && THUMB_IS_FUNC (exp.X_add_symbol))
26857 exp.X_add_number |= 1;
26858
26859 if (fragp->fr_var == 4)
26860 {
26861 insn = THUMB_OP32 (opcode);
26862 insn |= (old_op & 0xf0) << 4;
26863 put_thumb32_insn (buf, insn);
26864 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
26865 }
26866 else
26867 {
26868 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26869 exp.X_add_number -= 4;
26870 }
26871 pc_rel = 1;
26872 break;
26873 case T_MNEM_mov:
26874 case T_MNEM_movs:
26875 case T_MNEM_cmp:
26876 case T_MNEM_cmn:
26877 if (fragp->fr_var == 4)
26878 {
26879 int r0off = (opcode == T_MNEM_mov
26880 || opcode == T_MNEM_movs) ? 0 : 8;
26881 insn = THUMB_OP32 (opcode);
26882 insn = (insn & 0xe1ffffff) | 0x10000000;
26883 insn |= (old_op & 0x700) << r0off;
26884 put_thumb32_insn (buf, insn);
26885 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26886 }
26887 else
26888 {
26889 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
26890 }
26891 pc_rel = 0;
26892 break;
26893 case T_MNEM_b:
26894 if (fragp->fr_var == 4)
26895 {
26896 insn = THUMB_OP32(opcode);
26897 put_thumb32_insn (buf, insn);
26898 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
26899 }
26900 else
26901 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
26902 pc_rel = 1;
26903 break;
26904 case T_MNEM_bcond:
26905 if (fragp->fr_var == 4)
26906 {
26907 insn = THUMB_OP32(opcode);
26908 insn |= (old_op & 0xf00) << 14;
26909 put_thumb32_insn (buf, insn);
26910 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
26911 }
26912 else
26913 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
26914 pc_rel = 1;
26915 break;
26916 case T_MNEM_add_sp:
26917 case T_MNEM_add_pc:
26918 case T_MNEM_inc_sp:
26919 case T_MNEM_dec_sp:
26920 if (fragp->fr_var == 4)
26921 {
26922 /* ??? Choose between add and addw. */
26923 insn = THUMB_OP32 (opcode);
26924 insn |= (old_op & 0xf0) << 4;
26925 put_thumb32_insn (buf, insn);
26926 if (opcode == T_MNEM_add_pc)
26927 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26928 else
26929 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26930 }
26931 else
26932 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26933 pc_rel = 0;
26934 break;
26935
26936 case T_MNEM_addi:
26937 case T_MNEM_addis:
26938 case T_MNEM_subi:
26939 case T_MNEM_subis:
26940 if (fragp->fr_var == 4)
26941 {
26942 insn = THUMB_OP32 (opcode);
26943 insn |= (old_op & 0xf0) << 4;
26944 insn |= (old_op & 0xf) << 16;
26945 put_thumb32_insn (buf, insn);
26946 if (insn & (1 << 20))
26947 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26948 else
26949 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26950 }
26951 else
26952 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26953 pc_rel = 0;
26954 break;
26955 default:
26956 abort ();
26957 }
26958 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
26959 (enum bfd_reloc_code_real) reloc_type);
26960 fixp->fx_file = fragp->fr_file;
26961 fixp->fx_line = fragp->fr_line;
26962 fragp->fr_fix += fragp->fr_var;
26963
26964 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26965 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26966 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26967 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
26968 }
26969
26970 /* Return the size of a relaxable immediate operand instruction.
26971 SHIFT and SIZE specify the form of the allowable immediate. */
26972 static int
26973 relax_immediate (fragS *fragp, int size, int shift)
26974 {
26975 offsetT offset;
26976 offsetT mask;
26977 offsetT low;
26978
26979 /* ??? Should be able to do better than this. */
26980 if (fragp->fr_symbol)
26981 return 4;
26982
26983 low = (1 << shift) - 1;
26984 mask = (1 << (shift + size)) - (1 << shift);
26985 offset = fragp->fr_offset;
26986 /* Force misaligned offsets to 32-bit variant. */
26987 if (offset & low)
26988 return 4;
26989 if (offset & ~mask)
26990 return 4;
26991 return 2;
26992 }
26993
26994 /* Get the address of a symbol during relaxation. */
26995 static addressT
26996 relaxed_symbol_addr (fragS *fragp, long stretch)
26997 {
26998 fragS *sym_frag;
26999 addressT addr;
27000 symbolS *sym;
27001
27002 sym = fragp->fr_symbol;
27003 sym_frag = symbol_get_frag (sym);
27004 know (S_GET_SEGMENT (sym) != absolute_section
27005 || sym_frag == &zero_address_frag);
27006 addr = S_GET_VALUE (sym) + fragp->fr_offset;
27007
27008 /* If frag has yet to be reached on this pass, assume it will
27009 move by STRETCH just as we did. If this is not so, it will
27010 be because some frag between grows, and that will force
27011 another pass. */
27012
27013 if (stretch != 0
27014 && sym_frag->relax_marker != fragp->relax_marker)
27015 {
27016 fragS *f;
27017
27018 /* Adjust stretch for any alignment frag. Note that if have
27019 been expanding the earlier code, the symbol may be
27020 defined in what appears to be an earlier frag. FIXME:
27021 This doesn't handle the fr_subtype field, which specifies
27022 a maximum number of bytes to skip when doing an
27023 alignment. */
27024 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
27025 {
27026 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
27027 {
27028 if (stretch < 0)
27029 stretch = - ((- stretch)
27030 & ~ ((1 << (int) f->fr_offset) - 1));
27031 else
27032 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
27033 if (stretch == 0)
27034 break;
27035 }
27036 }
27037 if (f != NULL)
27038 addr += stretch;
27039 }
27040
27041 return addr;
27042 }
27043
27044 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
27045 load. */
27046 static int
27047 relax_adr (fragS *fragp, asection *sec, long stretch)
27048 {
27049 addressT addr;
27050 offsetT val;
27051
27052 /* Assume worst case for symbols not known to be in the same section. */
27053 if (fragp->fr_symbol == NULL
27054 || !S_IS_DEFINED (fragp->fr_symbol)
27055 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27056 || S_IS_WEAK (fragp->fr_symbol)
27057 || THUMB_IS_FUNC (fragp->fr_symbol))
27058 return 4;
27059
27060 val = relaxed_symbol_addr (fragp, stretch);
27061 addr = fragp->fr_address + fragp->fr_fix;
27062 addr = (addr + 4) & ~3;
27063 /* Force misaligned targets to 32-bit variant. */
27064 if (val & 3)
27065 return 4;
27066 val -= addr;
27067 if (val < 0 || val > 1020)
27068 return 4;
27069 return 2;
27070 }
27071
27072 /* Return the size of a relaxable add/sub immediate instruction. */
27073 static int
27074 relax_addsub (fragS *fragp, asection *sec)
27075 {
27076 char *buf;
27077 int op;
27078
27079 buf = fragp->fr_literal + fragp->fr_fix;
27080 op = bfd_get_16(sec->owner, buf);
27081 if ((op & 0xf) == ((op >> 4) & 0xf))
27082 return relax_immediate (fragp, 8, 0);
27083 else
27084 return relax_immediate (fragp, 3, 0);
27085 }
27086
27087 /* Return TRUE iff the definition of symbol S could be pre-empted
27088 (overridden) at link or load time. */
27089 static bool
27090 symbol_preemptible (symbolS *s)
27091 {
27092 /* Weak symbols can always be pre-empted. */
27093 if (S_IS_WEAK (s))
27094 return true;
27095
27096 /* Non-global symbols cannot be pre-empted. */
27097 if (! S_IS_EXTERNAL (s))
27098 return false;
27099
27100 #ifdef OBJ_ELF
27101 /* In ELF, a global symbol can be marked protected, or private. In that
27102 case it can't be pre-empted (other definitions in the same link unit
27103 would violate the ODR). */
27104 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
27105 return false;
27106 #endif
27107
27108 /* Other global symbols might be pre-empted. */
27109 return true;
27110 }
27111
27112 /* Return the size of a relaxable branch instruction. BITS is the
27113 size of the offset field in the narrow instruction. */
27114
27115 static int
27116 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
27117 {
27118 addressT addr;
27119 offsetT val;
27120 offsetT limit;
27121
27122 /* Assume worst case for symbols not known to be in the same section. */
27123 if (!S_IS_DEFINED (fragp->fr_symbol)
27124 || sec != S_GET_SEGMENT (fragp->fr_symbol)
27125 || S_IS_WEAK (fragp->fr_symbol))
27126 return 4;
27127
27128 #ifdef OBJ_ELF
27129 /* A branch to a function in ARM state will require interworking. */
27130 if (S_IS_DEFINED (fragp->fr_symbol)
27131 && ARM_IS_FUNC (fragp->fr_symbol))
27132 return 4;
27133 #endif
27134
27135 if (symbol_preemptible (fragp->fr_symbol))
27136 return 4;
27137
27138 val = relaxed_symbol_addr (fragp, stretch);
27139 addr = fragp->fr_address + fragp->fr_fix + 4;
27140 val -= addr;
27141
27142 /* Offset is a signed value *2 */
27143 limit = 1 << bits;
27144 if (val >= limit || val < -limit)
27145 return 4;
27146 return 2;
27147 }
27148
27149
27150 /* Relax a machine dependent frag. This returns the amount by which
27151 the current size of the frag should change. */
27152
27153 int
27154 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
27155 {
27156 int oldsize;
27157 int newsize;
27158
27159 oldsize = fragp->fr_var;
27160 switch (fragp->fr_subtype)
27161 {
27162 case T_MNEM_ldr_pc2:
27163 newsize = relax_adr (fragp, sec, stretch);
27164 break;
27165 case T_MNEM_ldr_pc:
27166 case T_MNEM_ldr_sp:
27167 case T_MNEM_str_sp:
27168 newsize = relax_immediate (fragp, 8, 2);
27169 break;
27170 case T_MNEM_ldr:
27171 case T_MNEM_str:
27172 newsize = relax_immediate (fragp, 5, 2);
27173 break;
27174 case T_MNEM_ldrh:
27175 case T_MNEM_strh:
27176 newsize = relax_immediate (fragp, 5, 1);
27177 break;
27178 case T_MNEM_ldrb:
27179 case T_MNEM_strb:
27180 newsize = relax_immediate (fragp, 5, 0);
27181 break;
27182 case T_MNEM_adr:
27183 newsize = relax_adr (fragp, sec, stretch);
27184 break;
27185 case T_MNEM_mov:
27186 case T_MNEM_movs:
27187 case T_MNEM_cmp:
27188 case T_MNEM_cmn:
27189 newsize = relax_immediate (fragp, 8, 0);
27190 break;
27191 case T_MNEM_b:
27192 newsize = relax_branch (fragp, sec, 11, stretch);
27193 break;
27194 case T_MNEM_bcond:
27195 newsize = relax_branch (fragp, sec, 8, stretch);
27196 break;
27197 case T_MNEM_add_sp:
27198 case T_MNEM_add_pc:
27199 newsize = relax_immediate (fragp, 8, 2);
27200 break;
27201 case T_MNEM_inc_sp:
27202 case T_MNEM_dec_sp:
27203 newsize = relax_immediate (fragp, 7, 2);
27204 break;
27205 case T_MNEM_addi:
27206 case T_MNEM_addis:
27207 case T_MNEM_subi:
27208 case T_MNEM_subis:
27209 newsize = relax_addsub (fragp, sec);
27210 break;
27211 default:
27212 abort ();
27213 }
27214
27215 fragp->fr_var = newsize;
27216 /* Freeze wide instructions that are at or before the same location as
27217 in the previous pass. This avoids infinite loops.
27218 Don't freeze them unconditionally because targets may be artificially
27219 misaligned by the expansion of preceding frags. */
27220 if (stretch <= 0 && newsize > 2)
27221 {
27222 md_convert_frag (sec->owner, sec, fragp);
27223 frag_wane (fragp);
27224 }
27225
27226 return newsize - oldsize;
27227 }
27228
27229 /* Round up a section size to the appropriate boundary. */
27230
27231 valueT
27232 md_section_align (segT segment ATTRIBUTE_UNUSED,
27233 valueT size)
27234 {
27235 return size;
27236 }
27237
27238 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
27239 of an rs_align_code fragment. */
27240
27241 void
27242 arm_handle_align (fragS * fragP)
27243 {
27244 static unsigned char const arm_noop[2][2][4] =
27245 {
27246 { /* ARMv1 */
27247 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
27248 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
27249 },
27250 { /* ARMv6k */
27251 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
27252 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
27253 },
27254 };
27255 static unsigned char const thumb_noop[2][2][2] =
27256 {
27257 { /* Thumb-1 */
27258 {0xc0, 0x46}, /* LE */
27259 {0x46, 0xc0}, /* BE */
27260 },
27261 { /* Thumb-2 */
27262 {0x00, 0xbf}, /* LE */
27263 {0xbf, 0x00} /* BE */
27264 }
27265 };
27266 static unsigned char const wide_thumb_noop[2][4] =
27267 { /* Wide Thumb-2 */
27268 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
27269 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
27270 };
27271
27272 unsigned bytes, fix, noop_size;
27273 char * p;
27274 const unsigned char * noop;
27275 const unsigned char *narrow_noop = NULL;
27276 #ifdef OBJ_ELF
27277 enum mstate state;
27278 #endif
27279
27280 if (fragP->fr_type != rs_align_code)
27281 return;
27282
27283 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
27284 p = fragP->fr_literal + fragP->fr_fix;
27285 fix = 0;
27286
27287 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
27288 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
27289
27290 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
27291
27292 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
27293 {
27294 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27295 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
27296 {
27297 narrow_noop = thumb_noop[1][target_big_endian];
27298 noop = wide_thumb_noop[target_big_endian];
27299 }
27300 else
27301 noop = thumb_noop[0][target_big_endian];
27302 noop_size = 2;
27303 #ifdef OBJ_ELF
27304 state = MAP_THUMB;
27305 #endif
27306 }
27307 else
27308 {
27309 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
27310 ? selected_cpu : arm_arch_none,
27311 arm_ext_v6k) != 0]
27312 [target_big_endian];
27313 noop_size = 4;
27314 #ifdef OBJ_ELF
27315 state = MAP_ARM;
27316 #endif
27317 }
27318
27319 fragP->fr_var = noop_size;
27320
27321 if (bytes & (noop_size - 1))
27322 {
27323 fix = bytes & (noop_size - 1);
27324 #ifdef OBJ_ELF
27325 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
27326 #endif
27327 memset (p, 0, fix);
27328 p += fix;
27329 bytes -= fix;
27330 }
27331
27332 if (narrow_noop)
27333 {
27334 if (bytes & noop_size)
27335 {
27336 /* Insert a narrow noop. */
27337 memcpy (p, narrow_noop, noop_size);
27338 p += noop_size;
27339 bytes -= noop_size;
27340 fix += noop_size;
27341 }
27342
27343 /* Use wide noops for the remainder */
27344 noop_size = 4;
27345 }
27346
27347 while (bytes >= noop_size)
27348 {
27349 memcpy (p, noop, noop_size);
27350 p += noop_size;
27351 bytes -= noop_size;
27352 fix += noop_size;
27353 }
27354
27355 fragP->fr_fix += fix;
27356 }
27357
27358 /* Called from md_do_align. Used to create an alignment
27359 frag in a code section. */
27360
27361 void
27362 arm_frag_align_code (int n, int max)
27363 {
27364 char * p;
27365
27366 /* We assume that there will never be a requirement
27367 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
27368 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
27369 {
27370 char err_msg[128];
27371
27372 sprintf (err_msg,
27373 _("alignments greater than %d bytes not supported in .text sections."),
27374 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
27375 as_fatal ("%s", err_msg);
27376 }
27377
27378 p = frag_var (rs_align_code,
27379 MAX_MEM_FOR_RS_ALIGN_CODE,
27380 1,
27381 (relax_substateT) max,
27382 (symbolS *) NULL,
27383 (offsetT) n,
27384 (char *) NULL);
27385 *p = 0;
27386 }
27387
27388 /* Perform target specific initialisation of a frag.
27389 Note - despite the name this initialisation is not done when the frag
27390 is created, but only when its type is assigned. A frag can be created
27391 and used a long time before its type is set, so beware of assuming that
27392 this initialisation is performed first. */
27393
27394 #ifndef OBJ_ELF
27395 void
27396 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
27397 {
27398 /* Record whether this frag is in an ARM or a THUMB area. */
27399 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27400 }
27401
27402 #else /* OBJ_ELF is defined. */
27403 void
27404 arm_init_frag (fragS * fragP, int max_chars)
27405 {
27406 bool frag_thumb_mode;
27407
27408 /* If the current ARM vs THUMB mode has not already
27409 been recorded into this frag then do so now. */
27410 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
27411 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
27412
27413 /* PR 21809: Do not set a mapping state for debug sections
27414 - it just confuses other tools. */
27415 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
27416 return;
27417
27418 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
27419
27420 /* Record a mapping symbol for alignment frags. We will delete this
27421 later if the alignment ends up empty. */
27422 switch (fragP->fr_type)
27423 {
27424 case rs_align:
27425 case rs_align_test:
27426 case rs_fill:
27427 mapping_state_2 (MAP_DATA, max_chars);
27428 break;
27429 case rs_align_code:
27430 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
27431 break;
27432 default:
27433 break;
27434 }
27435 }
27436
27437 /* When we change sections we need to issue a new mapping symbol. */
27438
27439 void
27440 arm_elf_change_section (void)
27441 {
27442 /* Link an unlinked unwind index table section to the .text section. */
27443 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
27444 && elf_linked_to_section (now_seg) == NULL)
27445 elf_linked_to_section (now_seg) = text_section;
27446 }
27447
27448 int
27449 arm_elf_section_type (const char * str, size_t len)
27450 {
27451 if (len == 5 && startswith (str, "exidx"))
27452 return SHT_ARM_EXIDX;
27453
27454 return -1;
27455 }
27456 \f
27457 /* Code to deal with unwinding tables. */
27458
27459 static void add_unwind_adjustsp (offsetT);
27460
27461 /* Generate any deferred unwind frame offset. */
27462
27463 static void
27464 flush_pending_unwind (void)
27465 {
27466 offsetT offset;
27467
27468 offset = unwind.pending_offset;
27469 unwind.pending_offset = 0;
27470 if (offset != 0)
27471 add_unwind_adjustsp (offset);
27472 }
27473
27474 /* Add an opcode to this list for this function. Two-byte opcodes should
27475 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
27476 order. */
27477
27478 static void
27479 add_unwind_opcode (valueT op, int length)
27480 {
27481 /* Add any deferred stack adjustment. */
27482 if (unwind.pending_offset)
27483 flush_pending_unwind ();
27484
27485 unwind.sp_restored = 0;
27486
27487 if (unwind.opcode_count + length > unwind.opcode_alloc)
27488 {
27489 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
27490 if (unwind.opcodes)
27491 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
27492 unwind.opcode_alloc);
27493 else
27494 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
27495 }
27496 while (length > 0)
27497 {
27498 length--;
27499 unwind.opcodes[unwind.opcode_count] = op & 0xff;
27500 op >>= 8;
27501 unwind.opcode_count++;
27502 }
27503 }
27504
27505 /* Add unwind opcodes to adjust the stack pointer. */
27506
27507 static void
27508 add_unwind_adjustsp (offsetT offset)
27509 {
27510 valueT op;
27511
27512 if (offset > 0x200)
27513 {
27514 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
27515 char bytes[5];
27516 int n;
27517 valueT o;
27518
27519 /* Long form: 0xb2, uleb128. */
27520 /* This might not fit in a word so add the individual bytes,
27521 remembering the list is built in reverse order. */
27522 o = (valueT) ((offset - 0x204) >> 2);
27523 if (o == 0)
27524 add_unwind_opcode (0, 1);
27525
27526 /* Calculate the uleb128 encoding of the offset. */
27527 n = 0;
27528 while (o)
27529 {
27530 bytes[n] = o & 0x7f;
27531 o >>= 7;
27532 if (o)
27533 bytes[n] |= 0x80;
27534 n++;
27535 }
27536 /* Add the insn. */
27537 for (; n; n--)
27538 add_unwind_opcode (bytes[n - 1], 1);
27539 add_unwind_opcode (0xb2, 1);
27540 }
27541 else if (offset > 0x100)
27542 {
27543 /* Two short opcodes. */
27544 add_unwind_opcode (0x3f, 1);
27545 op = (offset - 0x104) >> 2;
27546 add_unwind_opcode (op, 1);
27547 }
27548 else if (offset > 0)
27549 {
27550 /* Short opcode. */
27551 op = (offset - 4) >> 2;
27552 add_unwind_opcode (op, 1);
27553 }
27554 else if (offset < 0)
27555 {
27556 offset = -offset;
27557 while (offset > 0x100)
27558 {
27559 add_unwind_opcode (0x7f, 1);
27560 offset -= 0x100;
27561 }
27562 op = ((offset - 4) >> 2) | 0x40;
27563 add_unwind_opcode (op, 1);
27564 }
27565 }
27566
27567 /* Finish the list of unwind opcodes for this function. */
27568
27569 static void
27570 finish_unwind_opcodes (void)
27571 {
27572 valueT op;
27573
27574 if (unwind.fp_used)
27575 {
27576 /* Adjust sp as necessary. */
27577 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
27578 flush_pending_unwind ();
27579
27580 /* After restoring sp from the frame pointer. */
27581 op = 0x90 | unwind.fp_reg;
27582 add_unwind_opcode (op, 1);
27583 }
27584 else
27585 flush_pending_unwind ();
27586 }
27587
27588
27589 /* Start an exception table entry. If idx is nonzero this is an index table
27590 entry. */
27591
27592 static void
27593 start_unwind_section (const segT text_seg, int idx)
27594 {
27595 const char * text_name;
27596 const char * prefix;
27597 const char * prefix_once;
27598 struct elf_section_match match;
27599 char * sec_name;
27600 int type;
27601 int flags;
27602 int linkonce;
27603
27604 if (idx)
27605 {
27606 prefix = ELF_STRING_ARM_unwind;
27607 prefix_once = ELF_STRING_ARM_unwind_once;
27608 type = SHT_ARM_EXIDX;
27609 }
27610 else
27611 {
27612 prefix = ELF_STRING_ARM_unwind_info;
27613 prefix_once = ELF_STRING_ARM_unwind_info_once;
27614 type = SHT_PROGBITS;
27615 }
27616
27617 text_name = segment_name (text_seg);
27618 if (streq (text_name, ".text"))
27619 text_name = "";
27620
27621 if (startswith (text_name, ".gnu.linkonce.t."))
27622 {
27623 prefix = prefix_once;
27624 text_name += strlen (".gnu.linkonce.t.");
27625 }
27626
27627 sec_name = concat (prefix, text_name, (char *) NULL);
27628
27629 flags = SHF_ALLOC;
27630 linkonce = 0;
27631 memset (&match, 0, sizeof (match));
27632
27633 /* Handle COMDAT group. */
27634 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
27635 {
27636 match.group_name = elf_group_name (text_seg);
27637 if (match.group_name == NULL)
27638 {
27639 as_bad (_("Group section `%s' has no group signature"),
27640 segment_name (text_seg));
27641 ignore_rest_of_line ();
27642 return;
27643 }
27644 flags |= SHF_GROUP;
27645 linkonce = 1;
27646 }
27647
27648 obj_elf_change_section (sec_name, type, flags, 0, &match,
27649 linkonce, 0);
27650
27651 /* Set the section link for index tables. */
27652 if (idx)
27653 elf_linked_to_section (now_seg) = text_seg;
27654 }
27655
27656
27657 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
27658 personality routine data. Returns zero, or the index table value for
27659 an inline entry. */
27660
27661 static valueT
27662 create_unwind_entry (int have_data)
27663 {
27664 int size;
27665 addressT where;
27666 char *ptr;
27667 /* The current word of data. */
27668 valueT data;
27669 /* The number of bytes left in this word. */
27670 int n;
27671
27672 finish_unwind_opcodes ();
27673
27674 /* Remember the current text section. */
27675 unwind.saved_seg = now_seg;
27676 unwind.saved_subseg = now_subseg;
27677
27678 start_unwind_section (now_seg, 0);
27679
27680 if (unwind.personality_routine == NULL)
27681 {
27682 if (unwind.personality_index == -2)
27683 {
27684 if (have_data)
27685 as_bad (_("handlerdata in cantunwind frame"));
27686 return 1; /* EXIDX_CANTUNWIND. */
27687 }
27688
27689 /* Use a default personality routine if none is specified. */
27690 if (unwind.personality_index == -1)
27691 {
27692 if (unwind.opcode_count > 3)
27693 unwind.personality_index = 1;
27694 else
27695 unwind.personality_index = 0;
27696 }
27697
27698 /* Space for the personality routine entry. */
27699 if (unwind.personality_index == 0)
27700 {
27701 if (unwind.opcode_count > 3)
27702 as_bad (_("too many unwind opcodes for personality routine 0"));
27703
27704 if (!have_data)
27705 {
27706 /* All the data is inline in the index table. */
27707 data = 0x80;
27708 n = 3;
27709 while (unwind.opcode_count > 0)
27710 {
27711 unwind.opcode_count--;
27712 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27713 n--;
27714 }
27715
27716 /* Pad with "finish" opcodes. */
27717 while (n--)
27718 data = (data << 8) | 0xb0;
27719
27720 return data;
27721 }
27722 size = 0;
27723 }
27724 else
27725 /* We get two opcodes "free" in the first word. */
27726 size = unwind.opcode_count - 2;
27727 }
27728 else
27729 {
27730 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
27731 if (unwind.personality_index != -1)
27732 {
27733 as_bad (_("attempt to recreate an unwind entry"));
27734 return 1;
27735 }
27736
27737 /* An extra byte is required for the opcode count. */
27738 size = unwind.opcode_count + 1;
27739 }
27740
27741 size = (size + 3) >> 2;
27742 if (size > 0xff)
27743 as_bad (_("too many unwind opcodes"));
27744
27745 frag_align (2, 0, 0);
27746 record_alignment (now_seg, 2);
27747 unwind.table_entry = expr_build_dot ();
27748
27749 /* Allocate the table entry. */
27750 ptr = frag_more ((size << 2) + 4);
27751 /* PR 13449: Zero the table entries in case some of them are not used. */
27752 memset (ptr, 0, (size << 2) + 4);
27753 where = frag_now_fix () - ((size << 2) + 4);
27754
27755 switch (unwind.personality_index)
27756 {
27757 case -1:
27758 /* ??? Should this be a PLT generating relocation? */
27759 /* Custom personality routine. */
27760 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
27761 BFD_RELOC_ARM_PREL31);
27762
27763 where += 4;
27764 ptr += 4;
27765
27766 /* Set the first byte to the number of additional words. */
27767 data = size > 0 ? size - 1 : 0;
27768 n = 3;
27769 break;
27770
27771 /* ABI defined personality routines. */
27772 case 0:
27773 /* Three opcodes bytes are packed into the first word. */
27774 data = 0x80;
27775 n = 3;
27776 break;
27777
27778 case 1:
27779 case 2:
27780 /* The size and first two opcode bytes go in the first word. */
27781 data = ((0x80 + unwind.personality_index) << 8) | size;
27782 n = 2;
27783 break;
27784
27785 default:
27786 /* Should never happen. */
27787 abort ();
27788 }
27789
27790 /* Pack the opcodes into words (MSB first), reversing the list at the same
27791 time. */
27792 while (unwind.opcode_count > 0)
27793 {
27794 if (n == 0)
27795 {
27796 md_number_to_chars (ptr, data, 4);
27797 ptr += 4;
27798 n = 4;
27799 data = 0;
27800 }
27801 unwind.opcode_count--;
27802 n--;
27803 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
27804 }
27805
27806 /* Finish off the last word. */
27807 if (n < 4)
27808 {
27809 /* Pad with "finish" opcodes. */
27810 while (n--)
27811 data = (data << 8) | 0xb0;
27812
27813 md_number_to_chars (ptr, data, 4);
27814 }
27815
27816 if (!have_data)
27817 {
27818 /* Add an empty descriptor if there is no user-specified data. */
27819 ptr = frag_more (4);
27820 md_number_to_chars (ptr, 0, 4);
27821 }
27822
27823 return 0;
27824 }
27825
27826
27827 /* Initialize the DWARF-2 unwind information for this procedure. */
27828
27829 void
27830 tc_arm_frame_initial_instructions (void)
27831 {
27832 cfi_add_CFA_def_cfa (REG_SP, 0);
27833 }
27834 #endif /* OBJ_ELF */
27835
27836 /* Convert REGNAME to a DWARF-2 register number. */
27837
27838 int
27839 tc_arm_regname_to_dw2regnum (char *regname)
27840 {
27841 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
27842 if (reg != FAIL)
27843 return reg;
27844
27845 /* PR 16694: Allow VFP registers as well. */
27846 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
27847 if (reg != FAIL)
27848 return 64 + reg;
27849
27850 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
27851 if (reg != FAIL)
27852 return reg + 256;
27853
27854 return FAIL;
27855 }
27856
27857 #ifdef TE_PE
27858 void
27859 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
27860 {
27861 expressionS exp;
27862
27863 exp.X_op = O_secrel;
27864 exp.X_add_symbol = symbol;
27865 exp.X_add_number = 0;
27866 emit_expr (&exp, size);
27867 }
27868 #endif
27869
27870 /* MD interface: Symbol and relocation handling. */
27871
27872 /* Return the address within the segment that a PC-relative fixup is
27873 relative to. For ARM, PC-relative fixups applied to instructions
27874 are generally relative to the location of the fixup plus 8 bytes.
27875 Thumb branches are offset by 4, and Thumb loads relative to PC
27876 require special handling. */
27877
27878 long
27879 md_pcrel_from_section (fixS * fixP, segT seg)
27880 {
27881 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
27882
27883 /* If this is pc-relative and we are going to emit a relocation
27884 then we just want to put out any pipeline compensation that the linker
27885 will need. Otherwise we want to use the calculated base.
27886 For WinCE we skip the bias for externals as well, since this
27887 is how the MS ARM-CE assembler behaves and we want to be compatible. */
27888 if (fixP->fx_pcrel
27889 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
27890 || (arm_force_relocation (fixP)
27891 #ifdef TE_WINCE
27892 && !S_IS_EXTERNAL (fixP->fx_addsy)
27893 #endif
27894 )))
27895 base = 0;
27896
27897
27898 switch (fixP->fx_r_type)
27899 {
27900 /* PC relative addressing on the Thumb is slightly odd as the
27901 bottom two bits of the PC are forced to zero for the
27902 calculation. This happens *after* application of the
27903 pipeline offset. However, Thumb adrl already adjusts for
27904 this, so we need not do it again. */
27905 case BFD_RELOC_ARM_THUMB_ADD:
27906 return base & ~3;
27907
27908 case BFD_RELOC_ARM_THUMB_OFFSET:
27909 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27910 case BFD_RELOC_ARM_T32_ADD_PC12:
27911 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
27912 return (base + 4) & ~3;
27913
27914 /* Thumb branches are simply offset by +4. */
27915 case BFD_RELOC_THUMB_PCREL_BRANCH5:
27916 case BFD_RELOC_THUMB_PCREL_BRANCH7:
27917 case BFD_RELOC_THUMB_PCREL_BRANCH9:
27918 case BFD_RELOC_THUMB_PCREL_BRANCH12:
27919 case BFD_RELOC_THUMB_PCREL_BRANCH20:
27920 case BFD_RELOC_THUMB_PCREL_BRANCH25:
27921 case BFD_RELOC_THUMB_PCREL_BFCSEL:
27922 case BFD_RELOC_ARM_THUMB_BF17:
27923 case BFD_RELOC_ARM_THUMB_BF19:
27924 case BFD_RELOC_ARM_THUMB_BF13:
27925 case BFD_RELOC_ARM_THUMB_LOOP12:
27926 return base + 4;
27927
27928 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27929 if (fixP->fx_addsy
27930 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27931 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27932 && ARM_IS_FUNC (fixP->fx_addsy)
27933 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27934 base = fixP->fx_where + fixP->fx_frag->fr_address;
27935 return base + 4;
27936
27937 /* BLX is like branches above, but forces the low two bits of PC to
27938 zero. */
27939 case BFD_RELOC_THUMB_PCREL_BLX:
27940 if (fixP->fx_addsy
27941 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27942 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27943 && THUMB_IS_FUNC (fixP->fx_addsy)
27944 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27945 base = fixP->fx_where + fixP->fx_frag->fr_address;
27946 return (base + 4) & ~3;
27947
27948 /* ARM mode branches are offset by +8. However, the Windows CE
27949 loader expects the relocation not to take this into account. */
27950 case BFD_RELOC_ARM_PCREL_BLX:
27951 if (fixP->fx_addsy
27952 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27953 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27954 && ARM_IS_FUNC (fixP->fx_addsy)
27955 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27956 base = fixP->fx_where + fixP->fx_frag->fr_address;
27957 return base + 8;
27958
27959 case BFD_RELOC_ARM_PCREL_CALL:
27960 if (fixP->fx_addsy
27961 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27962 && !S_FORCE_RELOC (fixP->fx_addsy, true)
27963 && THUMB_IS_FUNC (fixP->fx_addsy)
27964 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27965 base = fixP->fx_where + fixP->fx_frag->fr_address;
27966 return base + 8;
27967
27968 case BFD_RELOC_ARM_PCREL_BRANCH:
27969 case BFD_RELOC_ARM_PCREL_JUMP:
27970 case BFD_RELOC_ARM_PLT32:
27971 #ifdef TE_WINCE
27972 /* When handling fixups immediately, because we have already
27973 discovered the value of a symbol, or the address of the frag involved
27974 we must account for the offset by +8, as the OS loader will never see the reloc.
27975 see fixup_segment() in write.c
27976 The S_IS_EXTERNAL test handles the case of global symbols.
27977 Those need the calculated base, not just the pipe compensation the linker will need. */
27978 if (fixP->fx_pcrel
27979 && fixP->fx_addsy != NULL
27980 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27981 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27982 return base + 8;
27983 return base;
27984 #else
27985 return base + 8;
27986 #endif
27987
27988
27989 /* ARM mode loads relative to PC are also offset by +8. Unlike
27990 branches, the Windows CE loader *does* expect the relocation
27991 to take this into account. */
27992 case BFD_RELOC_ARM_OFFSET_IMM:
27993 case BFD_RELOC_ARM_OFFSET_IMM8:
27994 case BFD_RELOC_ARM_HWLITERAL:
27995 case BFD_RELOC_ARM_LITERAL:
27996 case BFD_RELOC_ARM_CP_OFF_IMM:
27997 return base + 8;
27998
27999
28000 /* Other PC-relative relocations are un-offset. */
28001 default:
28002 return base;
28003 }
28004 }
28005
28006 static bool flag_warn_syms = true;
28007
28008 bool
28009 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
28010 {
28011 /* PR 18347 - Warn if the user attempts to create a symbol with the same
28012 name as an ARM instruction. Whilst strictly speaking it is allowed, it
28013 does mean that the resulting code might be very confusing to the reader.
28014 Also this warning can be triggered if the user omits an operand before
28015 an immediate address, eg:
28016
28017 LDR =foo
28018
28019 GAS treats this as an assignment of the value of the symbol foo to a
28020 symbol LDR, and so (without this code) it will not issue any kind of
28021 warning or error message.
28022
28023 Note - ARM instructions are case-insensitive but the strings in the hash
28024 table are all stored in lower case, so we must first ensure that name is
28025 lower case too. */
28026 if (flag_warn_syms && arm_ops_hsh)
28027 {
28028 char * nbuf = strdup (name);
28029 char * p;
28030
28031 for (p = nbuf; *p; p++)
28032 *p = TOLOWER (*p);
28033 if (str_hash_find (arm_ops_hsh, nbuf) != NULL)
28034 {
28035 static htab_t already_warned = NULL;
28036
28037 if (already_warned == NULL)
28038 already_warned = str_htab_create ();
28039 /* Only warn about the symbol once. To keep the code
28040 simple we let str_hash_insert do the lookup for us. */
28041 if (str_hash_find (already_warned, nbuf) == NULL)
28042 {
28043 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
28044 str_hash_insert (already_warned, nbuf, NULL, 0);
28045 }
28046 }
28047 else
28048 free (nbuf);
28049 }
28050
28051 return false;
28052 }
28053
28054 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
28055 Otherwise we have no need to default values of symbols. */
28056
28057 symbolS *
28058 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
28059 {
28060 #ifdef OBJ_ELF
28061 if (name[0] == '_' && name[1] == 'G'
28062 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
28063 {
28064 if (!GOT_symbol)
28065 {
28066 if (symbol_find (name))
28067 as_bad (_("GOT already in the symbol table"));
28068
28069 GOT_symbol = symbol_new (name, undefined_section,
28070 &zero_address_frag, 0);
28071 }
28072
28073 return GOT_symbol;
28074 }
28075 #endif
28076
28077 return NULL;
28078 }
28079
28080 /* Subroutine of md_apply_fix. Check to see if an immediate can be
28081 computed as two separate immediate values, added together. We
28082 already know that this value cannot be computed by just one ARM
28083 instruction. */
28084
28085 static unsigned int
28086 validate_immediate_twopart (unsigned int val,
28087 unsigned int * highpart)
28088 {
28089 unsigned int a;
28090 unsigned int i;
28091
28092 for (i = 0; i < 32; i += 2)
28093 if (((a = rotate_left (val, i)) & 0xff) != 0)
28094 {
28095 if (a & 0xff00)
28096 {
28097 if (a & ~ 0xffff)
28098 continue;
28099 * highpart = (a >> 8) | ((i + 24) << 7);
28100 }
28101 else if (a & 0xff0000)
28102 {
28103 if (a & 0xff000000)
28104 continue;
28105 * highpart = (a >> 16) | ((i + 16) << 7);
28106 }
28107 else
28108 {
28109 gas_assert (a & 0xff000000);
28110 * highpart = (a >> 24) | ((i + 8) << 7);
28111 }
28112
28113 return (a & 0xff) | (i << 7);
28114 }
28115
28116 return FAIL;
28117 }
28118
28119 static int
28120 validate_offset_imm (unsigned int val, int hwse)
28121 {
28122 if ((hwse && val > 255) || val > 4095)
28123 return FAIL;
28124 return val;
28125 }
28126
28127 /* Subroutine of md_apply_fix. Do those data_ops which can take a
28128 negative immediate constant by altering the instruction. A bit of
28129 a hack really.
28130 MOV <-> MVN
28131 AND <-> BIC
28132 ADC <-> SBC
28133 by inverting the second operand, and
28134 ADD <-> SUB
28135 CMP <-> CMN
28136 by negating the second operand. */
28137
28138 static int
28139 negate_data_op (unsigned long * instruction,
28140 unsigned long value)
28141 {
28142 int op, new_inst;
28143 unsigned long negated, inverted;
28144
28145 negated = encode_arm_immediate (-value);
28146 inverted = encode_arm_immediate (~value);
28147
28148 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
28149 switch (op)
28150 {
28151 /* First negates. */
28152 case OPCODE_SUB: /* ADD <-> SUB */
28153 new_inst = OPCODE_ADD;
28154 value = negated;
28155 break;
28156
28157 case OPCODE_ADD:
28158 new_inst = OPCODE_SUB;
28159 value = negated;
28160 break;
28161
28162 case OPCODE_CMP: /* CMP <-> CMN */
28163 new_inst = OPCODE_CMN;
28164 value = negated;
28165 break;
28166
28167 case OPCODE_CMN:
28168 new_inst = OPCODE_CMP;
28169 value = negated;
28170 break;
28171
28172 /* Now Inverted ops. */
28173 case OPCODE_MOV: /* MOV <-> MVN */
28174 new_inst = OPCODE_MVN;
28175 value = inverted;
28176 break;
28177
28178 case OPCODE_MVN:
28179 new_inst = OPCODE_MOV;
28180 value = inverted;
28181 break;
28182
28183 case OPCODE_AND: /* AND <-> BIC */
28184 new_inst = OPCODE_BIC;
28185 value = inverted;
28186 break;
28187
28188 case OPCODE_BIC:
28189 new_inst = OPCODE_AND;
28190 value = inverted;
28191 break;
28192
28193 case OPCODE_ADC: /* ADC <-> SBC */
28194 new_inst = OPCODE_SBC;
28195 value = inverted;
28196 break;
28197
28198 case OPCODE_SBC:
28199 new_inst = OPCODE_ADC;
28200 value = inverted;
28201 break;
28202
28203 /* We cannot do anything. */
28204 default:
28205 return FAIL;
28206 }
28207
28208 if (value == (unsigned) FAIL)
28209 return FAIL;
28210
28211 *instruction &= OPCODE_MASK;
28212 *instruction |= new_inst << DATA_OP_SHIFT;
28213 return value;
28214 }
28215
28216 /* Like negate_data_op, but for Thumb-2. */
28217
28218 static unsigned int
28219 thumb32_negate_data_op (valueT *instruction, unsigned int value)
28220 {
28221 unsigned int op, new_inst;
28222 unsigned int rd;
28223 unsigned int negated, inverted;
28224
28225 negated = encode_thumb32_immediate (-value);
28226 inverted = encode_thumb32_immediate (~value);
28227
28228 rd = (*instruction >> 8) & 0xf;
28229 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
28230 switch (op)
28231 {
28232 /* ADD <-> SUB. Includes CMP <-> CMN. */
28233 case T2_OPCODE_SUB:
28234 new_inst = T2_OPCODE_ADD;
28235 value = negated;
28236 break;
28237
28238 case T2_OPCODE_ADD:
28239 new_inst = T2_OPCODE_SUB;
28240 value = negated;
28241 break;
28242
28243 /* ORR <-> ORN. Includes MOV <-> MVN. */
28244 case T2_OPCODE_ORR:
28245 new_inst = T2_OPCODE_ORN;
28246 value = inverted;
28247 break;
28248
28249 case T2_OPCODE_ORN:
28250 new_inst = T2_OPCODE_ORR;
28251 value = inverted;
28252 break;
28253
28254 /* AND <-> BIC. TST has no inverted equivalent. */
28255 case T2_OPCODE_AND:
28256 new_inst = T2_OPCODE_BIC;
28257 if (rd == 15)
28258 value = FAIL;
28259 else
28260 value = inverted;
28261 break;
28262
28263 case T2_OPCODE_BIC:
28264 new_inst = T2_OPCODE_AND;
28265 value = inverted;
28266 break;
28267
28268 /* ADC <-> SBC */
28269 case T2_OPCODE_ADC:
28270 new_inst = T2_OPCODE_SBC;
28271 value = inverted;
28272 break;
28273
28274 case T2_OPCODE_SBC:
28275 new_inst = T2_OPCODE_ADC;
28276 value = inverted;
28277 break;
28278
28279 /* We cannot do anything. */
28280 default:
28281 return FAIL;
28282 }
28283
28284 if (value == (unsigned int)FAIL)
28285 return FAIL;
28286
28287 *instruction &= T2_OPCODE_MASK;
28288 *instruction |= new_inst << T2_DATA_OP_SHIFT;
28289 return value;
28290 }
28291
28292 /* Read a 32-bit thumb instruction from buf. */
28293
28294 static unsigned long
28295 get_thumb32_insn (char * buf)
28296 {
28297 unsigned long insn;
28298 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
28299 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28300
28301 return insn;
28302 }
28303
28304 /* We usually want to set the low bit on the address of thumb function
28305 symbols. In particular .word foo - . should have the low bit set.
28306 Generic code tries to fold the difference of two symbols to
28307 a constant. Prevent this and force a relocation when the first symbols
28308 is a thumb function. */
28309
28310 bool
28311 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
28312 {
28313 if (op == O_subtract
28314 && l->X_op == O_symbol
28315 && r->X_op == O_symbol
28316 && THUMB_IS_FUNC (l->X_add_symbol))
28317 {
28318 l->X_op = O_subtract;
28319 l->X_op_symbol = r->X_add_symbol;
28320 l->X_add_number -= r->X_add_number;
28321 return true;
28322 }
28323
28324 /* Process as normal. */
28325 return false;
28326 }
28327
28328 /* Encode Thumb2 unconditional branches and calls. The encoding
28329 for the 2 are identical for the immediate values. */
28330
28331 static void
28332 encode_thumb2_b_bl_offset (char * buf, offsetT value)
28333 {
28334 #define T2I1I2MASK ((1 << 13) | (1 << 11))
28335 offsetT newval;
28336 offsetT newval2;
28337 addressT S, I1, I2, lo, hi;
28338
28339 S = (value >> 24) & 0x01;
28340 I1 = (value >> 23) & 0x01;
28341 I2 = (value >> 22) & 0x01;
28342 hi = (value >> 12) & 0x3ff;
28343 lo = (value >> 1) & 0x7ff;
28344 newval = md_chars_to_number (buf, THUMB_SIZE);
28345 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28346 newval |= (S << 10) | hi;
28347 newval2 &= ~T2I1I2MASK;
28348 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
28349 md_number_to_chars (buf, newval, THUMB_SIZE);
28350 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28351 }
28352
28353 void
28354 md_apply_fix (fixS * fixP,
28355 valueT * valP,
28356 segT seg)
28357 {
28358 valueT value = * valP;
28359 valueT newval;
28360 unsigned int newimm;
28361 unsigned long temp;
28362 int sign;
28363 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
28364
28365 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
28366
28367 /* Note whether this will delete the relocation. */
28368
28369 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
28370 fixP->fx_done = 1;
28371
28372 /* On a 64-bit host, silently truncate 'value' to 32 bits for
28373 consistency with the behaviour on 32-bit hosts. Remember value
28374 for emit_reloc. */
28375 value &= 0xffffffff;
28376 value ^= 0x80000000;
28377 value -= 0x80000000;
28378
28379 *valP = value;
28380 fixP->fx_addnumber = value;
28381
28382 /* Same treatment for fixP->fx_offset. */
28383 fixP->fx_offset &= 0xffffffff;
28384 fixP->fx_offset ^= 0x80000000;
28385 fixP->fx_offset -= 0x80000000;
28386
28387 switch (fixP->fx_r_type)
28388 {
28389 case BFD_RELOC_NONE:
28390 /* This will need to go in the object file. */
28391 fixP->fx_done = 0;
28392 break;
28393
28394 case BFD_RELOC_ARM_IMMEDIATE:
28395 /* We claim that this fixup has been processed here,
28396 even if in fact we generate an error because we do
28397 not have a reloc for it, so tc_gen_reloc will reject it. */
28398 fixP->fx_done = 1;
28399
28400 if (fixP->fx_addsy)
28401 {
28402 const char *msg = 0;
28403
28404 if (! S_IS_DEFINED (fixP->fx_addsy))
28405 msg = _("undefined symbol %s used as an immediate value");
28406 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28407 msg = _("symbol %s is in a different section");
28408 else if (S_IS_WEAK (fixP->fx_addsy))
28409 msg = _("symbol %s is weak and may be overridden later");
28410
28411 if (msg)
28412 {
28413 as_bad_where (fixP->fx_file, fixP->fx_line,
28414 msg, S_GET_NAME (fixP->fx_addsy));
28415 break;
28416 }
28417 }
28418
28419 temp = md_chars_to_number (buf, INSN_SIZE);
28420
28421 /* If the offset is negative, we should use encoding A2 for ADR. */
28422 if ((temp & 0xfff0000) == 0x28f0000 && (offsetT) value < 0)
28423 newimm = negate_data_op (&temp, value);
28424 else
28425 {
28426 newimm = encode_arm_immediate (value);
28427
28428 /* If the instruction will fail, see if we can fix things up by
28429 changing the opcode. */
28430 if (newimm == (unsigned int) FAIL)
28431 newimm = negate_data_op (&temp, value);
28432 /* MOV accepts both ARM modified immediate (A1 encoding) and
28433 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
28434 When disassembling, MOV is preferred when there is no encoding
28435 overlap. */
28436 if (newimm == (unsigned int) FAIL
28437 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
28438 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
28439 && !((temp >> SBIT_SHIFT) & 0x1)
28440 && value <= 0xffff)
28441 {
28442 /* Clear bits[23:20] to change encoding from A1 to A2. */
28443 temp &= 0xff0fffff;
28444 /* Encoding high 4bits imm. Code below will encode the remaining
28445 low 12bits. */
28446 temp |= (value & 0x0000f000) << 4;
28447 newimm = value & 0x00000fff;
28448 }
28449 }
28450
28451 if (newimm == (unsigned int) FAIL)
28452 {
28453 as_bad_where (fixP->fx_file, fixP->fx_line,
28454 _("invalid constant (%lx) after fixup"),
28455 (unsigned long) value);
28456 break;
28457 }
28458
28459 newimm |= (temp & 0xfffff000);
28460 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28461 break;
28462
28463 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
28464 {
28465 unsigned int highpart = 0;
28466 unsigned int newinsn = 0xe1a00000; /* nop. */
28467
28468 if (fixP->fx_addsy)
28469 {
28470 const char *msg = 0;
28471
28472 if (! S_IS_DEFINED (fixP->fx_addsy))
28473 msg = _("undefined symbol %s used as an immediate value");
28474 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
28475 msg = _("symbol %s is in a different section");
28476 else if (S_IS_WEAK (fixP->fx_addsy))
28477 msg = _("symbol %s is weak and may be overridden later");
28478
28479 if (msg)
28480 {
28481 as_bad_where (fixP->fx_file, fixP->fx_line,
28482 msg, S_GET_NAME (fixP->fx_addsy));
28483 break;
28484 }
28485 }
28486
28487 newimm = encode_arm_immediate (value);
28488 temp = md_chars_to_number (buf, INSN_SIZE);
28489
28490 /* If the instruction will fail, see if we can fix things up by
28491 changing the opcode. */
28492 if (newimm == (unsigned int) FAIL
28493 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
28494 {
28495 /* No ? OK - try using two ADD instructions to generate
28496 the value. */
28497 newimm = validate_immediate_twopart (value, & highpart);
28498
28499 /* Yes - then make sure that the second instruction is
28500 also an add. */
28501 if (newimm != (unsigned int) FAIL)
28502 newinsn = temp;
28503 /* Still No ? Try using a negated value. */
28504 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
28505 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
28506 /* Otherwise - give up. */
28507 else
28508 {
28509 as_bad_where (fixP->fx_file, fixP->fx_line,
28510 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
28511 (long) value);
28512 break;
28513 }
28514
28515 /* Replace the first operand in the 2nd instruction (which
28516 is the PC) with the destination register. We have
28517 already added in the PC in the first instruction and we
28518 do not want to do it again. */
28519 newinsn &= ~ 0xf0000;
28520 newinsn |= ((newinsn & 0x0f000) << 4);
28521 }
28522
28523 newimm |= (temp & 0xfffff000);
28524 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
28525
28526 highpart |= (newinsn & 0xfffff000);
28527 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
28528 }
28529 break;
28530
28531 case BFD_RELOC_ARM_OFFSET_IMM:
28532 if (!fixP->fx_done && seg->use_rela_p)
28533 value = 0;
28534 /* Fall through. */
28535
28536 case BFD_RELOC_ARM_LITERAL:
28537 sign = (offsetT) value > 0;
28538
28539 if ((offsetT) value < 0)
28540 value = - value;
28541
28542 if (validate_offset_imm (value, 0) == FAIL)
28543 {
28544 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
28545 as_bad_where (fixP->fx_file, fixP->fx_line,
28546 _("invalid literal constant: pool needs to be closer"));
28547 else
28548 as_bad_where (fixP->fx_file, fixP->fx_line,
28549 _("bad immediate value for offset (%ld)"),
28550 (long) value);
28551 break;
28552 }
28553
28554 newval = md_chars_to_number (buf, INSN_SIZE);
28555 if (value == 0)
28556 newval &= 0xfffff000;
28557 else
28558 {
28559 newval &= 0xff7ff000;
28560 newval |= value | (sign ? INDEX_UP : 0);
28561 }
28562 md_number_to_chars (buf, newval, INSN_SIZE);
28563 break;
28564
28565 case BFD_RELOC_ARM_OFFSET_IMM8:
28566 case BFD_RELOC_ARM_HWLITERAL:
28567 sign = (offsetT) value > 0;
28568
28569 if ((offsetT) value < 0)
28570 value = - value;
28571
28572 if (validate_offset_imm (value, 1) == FAIL)
28573 {
28574 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
28575 as_bad_where (fixP->fx_file, fixP->fx_line,
28576 _("invalid literal constant: pool needs to be closer"));
28577 else
28578 as_bad_where (fixP->fx_file, fixP->fx_line,
28579 _("bad immediate value for 8-bit offset (%ld)"),
28580 (long) value);
28581 break;
28582 }
28583
28584 newval = md_chars_to_number (buf, INSN_SIZE);
28585 if (value == 0)
28586 newval &= 0xfffff0f0;
28587 else
28588 {
28589 newval &= 0xff7ff0f0;
28590 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
28591 }
28592 md_number_to_chars (buf, newval, INSN_SIZE);
28593 break;
28594
28595 case BFD_RELOC_ARM_T32_OFFSET_U8:
28596 if (value > 1020 || value % 4 != 0)
28597 as_bad_where (fixP->fx_file, fixP->fx_line,
28598 _("bad immediate value for offset (%ld)"), (long) value);
28599 value /= 4;
28600
28601 newval = md_chars_to_number (buf+2, THUMB_SIZE);
28602 newval |= value;
28603 md_number_to_chars (buf+2, newval, THUMB_SIZE);
28604 break;
28605
28606 case BFD_RELOC_ARM_T32_OFFSET_IMM:
28607 /* This is a complicated relocation used for all varieties of Thumb32
28608 load/store instruction with immediate offset:
28609
28610 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
28611 *4, optional writeback(W)
28612 (doubleword load/store)
28613
28614 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
28615 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
28616 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
28617 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
28618 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
28619
28620 Uppercase letters indicate bits that are already encoded at
28621 this point. Lowercase letters are our problem. For the
28622 second block of instructions, the secondary opcode nybble
28623 (bits 8..11) is present, and bit 23 is zero, even if this is
28624 a PC-relative operation. */
28625 newval = md_chars_to_number (buf, THUMB_SIZE);
28626 newval <<= 16;
28627 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
28628
28629 if ((newval & 0xf0000000) == 0xe0000000)
28630 {
28631 /* Doubleword load/store: 8-bit offset, scaled by 4. */
28632 if ((offsetT) value >= 0)
28633 newval |= (1 << 23);
28634 else
28635 value = -value;
28636 if (value % 4 != 0)
28637 {
28638 as_bad_where (fixP->fx_file, fixP->fx_line,
28639 _("offset not a multiple of 4"));
28640 break;
28641 }
28642 value /= 4;
28643 if (value > 0xff)
28644 {
28645 as_bad_where (fixP->fx_file, fixP->fx_line,
28646 _("offset out of range"));
28647 break;
28648 }
28649 newval &= ~0xff;
28650 }
28651 else if ((newval & 0x000f0000) == 0x000f0000)
28652 {
28653 /* PC-relative, 12-bit offset. */
28654 if ((offsetT) value >= 0)
28655 newval |= (1 << 23);
28656 else
28657 value = -value;
28658 if (value > 0xfff)
28659 {
28660 as_bad_where (fixP->fx_file, fixP->fx_line,
28661 _("offset out of range"));
28662 break;
28663 }
28664 newval &= ~0xfff;
28665 }
28666 else if ((newval & 0x00000100) == 0x00000100)
28667 {
28668 /* Writeback: 8-bit, +/- offset. */
28669 if ((offsetT) value >= 0)
28670 newval |= (1 << 9);
28671 else
28672 value = -value;
28673 if (value > 0xff)
28674 {
28675 as_bad_where (fixP->fx_file, fixP->fx_line,
28676 _("offset out of range"));
28677 break;
28678 }
28679 newval &= ~0xff;
28680 }
28681 else if ((newval & 0x00000f00) == 0x00000e00)
28682 {
28683 /* T-instruction: positive 8-bit offset. */
28684 if (value > 0xff)
28685 {
28686 as_bad_where (fixP->fx_file, fixP->fx_line,
28687 _("offset out of range"));
28688 break;
28689 }
28690 newval &= ~0xff;
28691 newval |= value;
28692 }
28693 else
28694 {
28695 /* Positive 12-bit or negative 8-bit offset. */
28696 unsigned int limit;
28697 if ((offsetT) value >= 0)
28698 {
28699 newval |= (1 << 23);
28700 limit = 0xfff;
28701 }
28702 else
28703 {
28704 value = -value;
28705 limit = 0xff;
28706 }
28707 if (value > limit)
28708 {
28709 as_bad_where (fixP->fx_file, fixP->fx_line,
28710 _("offset out of range"));
28711 break;
28712 }
28713 newval &= ~limit;
28714 }
28715
28716 newval |= value;
28717 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
28718 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
28719 break;
28720
28721 case BFD_RELOC_ARM_SHIFT_IMM:
28722 newval = md_chars_to_number (buf, INSN_SIZE);
28723 if (value > 32
28724 || (value == 32
28725 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
28726 {
28727 as_bad_where (fixP->fx_file, fixP->fx_line,
28728 _("shift expression is too large"));
28729 break;
28730 }
28731
28732 if (value == 0)
28733 /* Shifts of zero must be done as lsl. */
28734 newval &= ~0x60;
28735 else if (value == 32)
28736 value = 0;
28737 newval &= 0xfffff07f;
28738 newval |= (value & 0x1f) << 7;
28739 md_number_to_chars (buf, newval, INSN_SIZE);
28740 break;
28741
28742 case BFD_RELOC_ARM_T32_IMMEDIATE:
28743 case BFD_RELOC_ARM_T32_ADD_IMM:
28744 case BFD_RELOC_ARM_T32_IMM12:
28745 case BFD_RELOC_ARM_T32_ADD_PC12:
28746 /* We claim that this fixup has been processed here,
28747 even if in fact we generate an error because we do
28748 not have a reloc for it, so tc_gen_reloc will reject it. */
28749 fixP->fx_done = 1;
28750
28751 if (fixP->fx_addsy
28752 && ! S_IS_DEFINED (fixP->fx_addsy))
28753 {
28754 as_bad_where (fixP->fx_file, fixP->fx_line,
28755 _("undefined symbol %s used as an immediate value"),
28756 S_GET_NAME (fixP->fx_addsy));
28757 break;
28758 }
28759
28760 newval = md_chars_to_number (buf, THUMB_SIZE);
28761 newval <<= 16;
28762 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
28763
28764 newimm = FAIL;
28765 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
28766 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
28767 Thumb2 modified immediate encoding (T2). */
28768 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
28769 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28770 {
28771 newimm = encode_thumb32_immediate (value);
28772 if (newimm == (unsigned int) FAIL)
28773 newimm = thumb32_negate_data_op (&newval, value);
28774 }
28775 if (newimm == (unsigned int) FAIL)
28776 {
28777 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
28778 {
28779 /* Turn add/sum into addw/subw. */
28780 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
28781 newval = (newval & 0xfeffffff) | 0x02000000;
28782 /* No flat 12-bit imm encoding for addsw/subsw. */
28783 if ((newval & 0x00100000) == 0)
28784 {
28785 /* 12 bit immediate for addw/subw. */
28786 if ((offsetT) value < 0)
28787 {
28788 value = -value;
28789 newval ^= 0x00a00000;
28790 }
28791 if (value > 0xfff)
28792 newimm = (unsigned int) FAIL;
28793 else
28794 newimm = value;
28795 }
28796 }
28797 else
28798 {
28799 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
28800 UINT16 (T3 encoding), MOVW only accepts UINT16. When
28801 disassembling, MOV is preferred when there is no encoding
28802 overlap. */
28803 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
28804 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
28805 but with the Rn field [19:16] set to 1111. */
28806 && (((newval >> 16) & 0xf) == 0xf)
28807 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
28808 && !((newval >> T2_SBIT_SHIFT) & 0x1)
28809 && value <= 0xffff)
28810 {
28811 /* Toggle bit[25] to change encoding from T2 to T3. */
28812 newval ^= 1 << 25;
28813 /* Clear bits[19:16]. */
28814 newval &= 0xfff0ffff;
28815 /* Encoding high 4bits imm. Code below will encode the
28816 remaining low 12bits. */
28817 newval |= (value & 0x0000f000) << 4;
28818 newimm = value & 0x00000fff;
28819 }
28820 }
28821 }
28822
28823 if (newimm == (unsigned int)FAIL)
28824 {
28825 as_bad_where (fixP->fx_file, fixP->fx_line,
28826 _("invalid constant (%lx) after fixup"),
28827 (unsigned long) value);
28828 break;
28829 }
28830
28831 newval |= (newimm & 0x800) << 15;
28832 newval |= (newimm & 0x700) << 4;
28833 newval |= (newimm & 0x0ff);
28834
28835 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
28836 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
28837 break;
28838
28839 case BFD_RELOC_ARM_SMC:
28840 if (value > 0xf)
28841 as_bad_where (fixP->fx_file, fixP->fx_line,
28842 _("invalid smc expression"));
28843
28844 newval = md_chars_to_number (buf, INSN_SIZE);
28845 newval |= (value & 0xf);
28846 md_number_to_chars (buf, newval, INSN_SIZE);
28847 break;
28848
28849 case BFD_RELOC_ARM_HVC:
28850 if (value > 0xffff)
28851 as_bad_where (fixP->fx_file, fixP->fx_line,
28852 _("invalid hvc expression"));
28853 newval = md_chars_to_number (buf, INSN_SIZE);
28854 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
28855 md_number_to_chars (buf, newval, INSN_SIZE);
28856 break;
28857
28858 case BFD_RELOC_ARM_SWI:
28859 if (fixP->tc_fix_data != 0)
28860 {
28861 if (value > 0xff)
28862 as_bad_where (fixP->fx_file, fixP->fx_line,
28863 _("invalid swi expression"));
28864 newval = md_chars_to_number (buf, THUMB_SIZE);
28865 newval |= value;
28866 md_number_to_chars (buf, newval, THUMB_SIZE);
28867 }
28868 else
28869 {
28870 if (value > 0x00ffffff)
28871 as_bad_where (fixP->fx_file, fixP->fx_line,
28872 _("invalid swi expression"));
28873 newval = md_chars_to_number (buf, INSN_SIZE);
28874 newval |= value;
28875 md_number_to_chars (buf, newval, INSN_SIZE);
28876 }
28877 break;
28878
28879 case BFD_RELOC_ARM_MULTI:
28880 if (value > 0xffff)
28881 as_bad_where (fixP->fx_file, fixP->fx_line,
28882 _("invalid expression in load/store multiple"));
28883 newval = value | md_chars_to_number (buf, INSN_SIZE);
28884 md_number_to_chars (buf, newval, INSN_SIZE);
28885 break;
28886
28887 #ifdef OBJ_ELF
28888 case BFD_RELOC_ARM_PCREL_CALL:
28889
28890 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28891 && fixP->fx_addsy
28892 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28893 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28894 && THUMB_IS_FUNC (fixP->fx_addsy))
28895 /* Flip the bl to blx. This is a simple flip
28896 bit here because we generate PCREL_CALL for
28897 unconditional bls. */
28898 {
28899 newval = md_chars_to_number (buf, INSN_SIZE);
28900 newval = newval | 0x10000000;
28901 md_number_to_chars (buf, newval, INSN_SIZE);
28902 temp = 1;
28903 fixP->fx_done = 1;
28904 }
28905 else
28906 temp = 3;
28907 goto arm_branch_common;
28908
28909 case BFD_RELOC_ARM_PCREL_JUMP:
28910 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28911 && fixP->fx_addsy
28912 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28913 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28914 && THUMB_IS_FUNC (fixP->fx_addsy))
28915 {
28916 /* This would map to a bl<cond>, b<cond>,
28917 b<always> to a Thumb function. We
28918 need to force a relocation for this particular
28919 case. */
28920 newval = md_chars_to_number (buf, INSN_SIZE);
28921 fixP->fx_done = 0;
28922 }
28923 /* Fall through. */
28924
28925 case BFD_RELOC_ARM_PLT32:
28926 #endif
28927 case BFD_RELOC_ARM_PCREL_BRANCH:
28928 temp = 3;
28929 goto arm_branch_common;
28930
28931 case BFD_RELOC_ARM_PCREL_BLX:
28932
28933 temp = 1;
28934 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28935 && fixP->fx_addsy
28936 && !S_FORCE_RELOC (fixP->fx_addsy, true)
28937 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28938 && ARM_IS_FUNC (fixP->fx_addsy))
28939 {
28940 /* Flip the blx to a bl and warn. */
28941 const char *name = S_GET_NAME (fixP->fx_addsy);
28942 newval = 0xeb000000;
28943 as_warn_where (fixP->fx_file, fixP->fx_line,
28944 _("blx to '%s' an ARM ISA state function changed to bl"),
28945 name);
28946 md_number_to_chars (buf, newval, INSN_SIZE);
28947 temp = 3;
28948 fixP->fx_done = 1;
28949 }
28950
28951 #ifdef OBJ_ELF
28952 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
28953 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
28954 #endif
28955
28956 arm_branch_common:
28957 /* We are going to store value (shifted right by two) in the
28958 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28959 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
28960 also be clear. */
28961 if (value & temp)
28962 as_bad_where (fixP->fx_file, fixP->fx_line,
28963 _("misaligned branch destination"));
28964 if ((value & 0xfe000000) != 0
28965 && (value & 0xfe000000) != 0xfe000000)
28966 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28967
28968 if (fixP->fx_done || !seg->use_rela_p)
28969 {
28970 newval = md_chars_to_number (buf, INSN_SIZE);
28971 newval |= (value >> 2) & 0x00ffffff;
28972 /* Set the H bit on BLX instructions. */
28973 if (temp == 1)
28974 {
28975 if (value & 2)
28976 newval |= 0x01000000;
28977 else
28978 newval &= ~0x01000000;
28979 }
28980 md_number_to_chars (buf, newval, INSN_SIZE);
28981 }
28982 break;
28983
28984 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28985 /* CBZ can only branch forward. */
28986
28987 /* Attempts to use CBZ to branch to the next instruction
28988 (which, strictly speaking, are prohibited) will be turned into
28989 no-ops.
28990
28991 FIXME: It may be better to remove the instruction completely and
28992 perform relaxation. */
28993 if ((offsetT) value == -2)
28994 {
28995 newval = md_chars_to_number (buf, THUMB_SIZE);
28996 newval = 0xbf00; /* NOP encoding T1 */
28997 md_number_to_chars (buf, newval, THUMB_SIZE);
28998 }
28999 else
29000 {
29001 if (value & ~0x7e)
29002 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29003
29004 if (fixP->fx_done || !seg->use_rela_p)
29005 {
29006 newval = md_chars_to_number (buf, THUMB_SIZE);
29007 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
29008 md_number_to_chars (buf, newval, THUMB_SIZE);
29009 }
29010 }
29011 break;
29012
29013 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
29014 if (out_of_range_p (value, 8))
29015 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29016
29017 if (fixP->fx_done || !seg->use_rela_p)
29018 {
29019 newval = md_chars_to_number (buf, THUMB_SIZE);
29020 newval |= (value & 0x1ff) >> 1;
29021 md_number_to_chars (buf, newval, THUMB_SIZE);
29022 }
29023 break;
29024
29025 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
29026 if (out_of_range_p (value, 11))
29027 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29028
29029 if (fixP->fx_done || !seg->use_rela_p)
29030 {
29031 newval = md_chars_to_number (buf, THUMB_SIZE);
29032 newval |= (value & 0xfff) >> 1;
29033 md_number_to_chars (buf, newval, THUMB_SIZE);
29034 }
29035 break;
29036
29037 /* This relocation is misnamed, it should be BRANCH21. */
29038 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29039 if (fixP->fx_addsy
29040 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29041 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29042 && ARM_IS_FUNC (fixP->fx_addsy)
29043 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29044 {
29045 /* Force a relocation for a branch 20 bits wide. */
29046 fixP->fx_done = 0;
29047 }
29048 if (out_of_range_p (value, 20))
29049 as_bad_where (fixP->fx_file, fixP->fx_line,
29050 _("conditional branch out of range"));
29051
29052 if (fixP->fx_done || !seg->use_rela_p)
29053 {
29054 offsetT newval2;
29055 addressT S, J1, J2, lo, hi;
29056
29057 S = (value & 0x00100000) >> 20;
29058 J2 = (value & 0x00080000) >> 19;
29059 J1 = (value & 0x00040000) >> 18;
29060 hi = (value & 0x0003f000) >> 12;
29061 lo = (value & 0x00000ffe) >> 1;
29062
29063 newval = md_chars_to_number (buf, THUMB_SIZE);
29064 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29065 newval |= (S << 10) | hi;
29066 newval2 |= (J1 << 13) | (J2 << 11) | lo;
29067 md_number_to_chars (buf, newval, THUMB_SIZE);
29068 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29069 }
29070 break;
29071
29072 case BFD_RELOC_THUMB_PCREL_BLX:
29073 /* If there is a blx from a thumb state function to
29074 another thumb function flip this to a bl and warn
29075 about it. */
29076
29077 if (fixP->fx_addsy
29078 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29079 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29080 && THUMB_IS_FUNC (fixP->fx_addsy))
29081 {
29082 const char *name = S_GET_NAME (fixP->fx_addsy);
29083 as_warn_where (fixP->fx_file, fixP->fx_line,
29084 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
29085 name);
29086 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29087 newval = newval | 0x1000;
29088 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29089 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29090 fixP->fx_done = 1;
29091 }
29092
29093
29094 goto thumb_bl_common;
29095
29096 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29097 /* A bl from Thumb state ISA to an internal ARM state function
29098 is converted to a blx. */
29099 if (fixP->fx_addsy
29100 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29101 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29102 && ARM_IS_FUNC (fixP->fx_addsy)
29103 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
29104 {
29105 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29106 newval = newval & ~0x1000;
29107 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
29108 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
29109 fixP->fx_done = 1;
29110 }
29111
29112 thumb_bl_common:
29113
29114 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29115 /* For a BLX instruction, make sure that the relocation is rounded up
29116 to a word boundary. This follows the semantics of the instruction
29117 which specifies that bit 1 of the target address will come from bit
29118 1 of the base address. */
29119 value = (value + 3) & ~ 3;
29120
29121 #ifdef OBJ_ELF
29122 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
29123 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
29124 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
29125 #endif
29126
29127 if (out_of_range_p (value, 22))
29128 {
29129 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
29130 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29131 else if (out_of_range_p (value, 24))
29132 as_bad_where (fixP->fx_file, fixP->fx_line,
29133 _("Thumb2 branch out of range"));
29134 }
29135
29136 if (fixP->fx_done || !seg->use_rela_p)
29137 encode_thumb2_b_bl_offset (buf, value);
29138
29139 break;
29140
29141 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29142 if (out_of_range_p (value, 24))
29143 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
29144
29145 if (fixP->fx_done || !seg->use_rela_p)
29146 encode_thumb2_b_bl_offset (buf, value);
29147
29148 break;
29149
29150 case BFD_RELOC_8:
29151 if (fixP->fx_done || !seg->use_rela_p)
29152 *buf = value;
29153 break;
29154
29155 case BFD_RELOC_16:
29156 if (fixP->fx_done || !seg->use_rela_p)
29157 md_number_to_chars (buf, value, 2);
29158 break;
29159
29160 #ifdef OBJ_ELF
29161 case BFD_RELOC_ARM_TLS_CALL:
29162 case BFD_RELOC_ARM_THM_TLS_CALL:
29163 case BFD_RELOC_ARM_TLS_DESCSEQ:
29164 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
29165 case BFD_RELOC_ARM_TLS_GOTDESC:
29166 case BFD_RELOC_ARM_TLS_GD32:
29167 case BFD_RELOC_ARM_TLS_LE32:
29168 case BFD_RELOC_ARM_TLS_IE32:
29169 case BFD_RELOC_ARM_TLS_LDM32:
29170 case BFD_RELOC_ARM_TLS_LDO32:
29171 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29172 break;
29173
29174 /* Same handling as above, but with the arm_fdpic guard. */
29175 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29176 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29177 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29178 if (arm_fdpic)
29179 {
29180 S_SET_THREAD_LOCAL (fixP->fx_addsy);
29181 }
29182 else
29183 {
29184 as_bad_where (fixP->fx_file, fixP->fx_line,
29185 _("Relocation supported only in FDPIC mode"));
29186 }
29187 break;
29188
29189 case BFD_RELOC_ARM_GOT32:
29190 case BFD_RELOC_ARM_GOTOFF:
29191 break;
29192
29193 case BFD_RELOC_ARM_GOT_PREL:
29194 if (fixP->fx_done || !seg->use_rela_p)
29195 md_number_to_chars (buf, value, 4);
29196 break;
29197
29198 case BFD_RELOC_ARM_TARGET2:
29199 /* TARGET2 is not partial-inplace, so we need to write the
29200 addend here for REL targets, because it won't be written out
29201 during reloc processing later. */
29202 if (fixP->fx_done || !seg->use_rela_p)
29203 md_number_to_chars (buf, fixP->fx_offset, 4);
29204 break;
29205
29206 /* Relocations for FDPIC. */
29207 case BFD_RELOC_ARM_GOTFUNCDESC:
29208 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29209 case BFD_RELOC_ARM_FUNCDESC:
29210 if (arm_fdpic)
29211 {
29212 if (fixP->fx_done || !seg->use_rela_p)
29213 md_number_to_chars (buf, 0, 4);
29214 }
29215 else
29216 {
29217 as_bad_where (fixP->fx_file, fixP->fx_line,
29218 _("Relocation supported only in FDPIC mode"));
29219 }
29220 break;
29221 #endif
29222
29223 case BFD_RELOC_RVA:
29224 case BFD_RELOC_32:
29225 case BFD_RELOC_ARM_TARGET1:
29226 case BFD_RELOC_ARM_ROSEGREL32:
29227 case BFD_RELOC_ARM_SBREL32:
29228 case BFD_RELOC_32_PCREL:
29229 #ifdef TE_PE
29230 case BFD_RELOC_32_SECREL:
29231 #endif
29232 if (fixP->fx_done || !seg->use_rela_p)
29233 #ifdef TE_WINCE
29234 /* For WinCE we only do this for pcrel fixups. */
29235 if (fixP->fx_done || fixP->fx_pcrel)
29236 #endif
29237 md_number_to_chars (buf, value, 4);
29238 break;
29239
29240 #ifdef OBJ_ELF
29241 case BFD_RELOC_ARM_PREL31:
29242 if (fixP->fx_done || !seg->use_rela_p)
29243 {
29244 newval = md_chars_to_number (buf, 4) & 0x80000000;
29245 if ((value ^ (value >> 1)) & 0x40000000)
29246 {
29247 as_bad_where (fixP->fx_file, fixP->fx_line,
29248 _("rel31 relocation overflow"));
29249 }
29250 newval |= value & 0x7fffffff;
29251 md_number_to_chars (buf, newval, 4);
29252 }
29253 break;
29254 #endif
29255
29256 case BFD_RELOC_ARM_CP_OFF_IMM:
29257 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
29258 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
29259 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
29260 newval = md_chars_to_number (buf, INSN_SIZE);
29261 else
29262 newval = get_thumb32_insn (buf);
29263 if ((newval & 0x0f200f00) == 0x0d000900)
29264 {
29265 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
29266 has permitted values that are multiples of 2, in the range -510
29267 to 510. */
29268 if (value + 510 > 510 + 510 || (value & 1))
29269 as_bad_where (fixP->fx_file, fixP->fx_line,
29270 _("co-processor offset out of range"));
29271 }
29272 else if ((newval & 0xfe001f80) == 0xec000f80)
29273 {
29274 if (value + 511 > 512 + 511 || (value & 3))
29275 as_bad_where (fixP->fx_file, fixP->fx_line,
29276 _("co-processor offset out of range"));
29277 }
29278 else if (value + 1023 > 1023 + 1023 || (value & 3))
29279 as_bad_where (fixP->fx_file, fixP->fx_line,
29280 _("co-processor offset out of range"));
29281 cp_off_common:
29282 sign = (offsetT) value > 0;
29283 if ((offsetT) value < 0)
29284 value = -value;
29285 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29286 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29287 newval = md_chars_to_number (buf, INSN_SIZE);
29288 else
29289 newval = get_thumb32_insn (buf);
29290 if (value == 0)
29291 {
29292 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29293 newval &= 0xffffff80;
29294 else
29295 newval &= 0xffffff00;
29296 }
29297 else
29298 {
29299 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
29300 newval &= 0xff7fff80;
29301 else
29302 newval &= 0xff7fff00;
29303 if ((newval & 0x0f200f00) == 0x0d000900)
29304 {
29305 /* This is a fp16 vstr/vldr.
29306
29307 It requires the immediate offset in the instruction is shifted
29308 left by 1 to be a half-word offset.
29309
29310 Here, left shift by 1 first, and later right shift by 2
29311 should get the right offset. */
29312 value <<= 1;
29313 }
29314 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
29315 }
29316 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29317 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
29318 md_number_to_chars (buf, newval, INSN_SIZE);
29319 else
29320 put_thumb32_insn (buf, newval);
29321 break;
29322
29323 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
29324 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
29325 if (value + 255 > 255 + 255)
29326 as_bad_where (fixP->fx_file, fixP->fx_line,
29327 _("co-processor offset out of range"));
29328 value *= 4;
29329 goto cp_off_common;
29330
29331 case BFD_RELOC_ARM_THUMB_OFFSET:
29332 newval = md_chars_to_number (buf, THUMB_SIZE);
29333 /* Exactly what ranges, and where the offset is inserted depends
29334 on the type of instruction, we can establish this from the
29335 top 4 bits. */
29336 switch (newval >> 12)
29337 {
29338 case 4: /* PC load. */
29339 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
29340 forced to zero for these loads; md_pcrel_from has already
29341 compensated for this. */
29342 if (value & 3)
29343 as_bad_where (fixP->fx_file, fixP->fx_line,
29344 _("invalid offset, target not word aligned (0x%08lX)"),
29345 (((unsigned long) fixP->fx_frag->fr_address
29346 + (unsigned long) fixP->fx_where) & ~3)
29347 + (unsigned long) value);
29348 else if (get_recorded_alignment (seg) < 2)
29349 as_warn_where (fixP->fx_file, fixP->fx_line,
29350 _("section does not have enough alignment to ensure safe PC-relative loads"));
29351
29352 if (value & ~0x3fc)
29353 as_bad_where (fixP->fx_file, fixP->fx_line,
29354 _("invalid offset, value too big (0x%08lX)"),
29355 (long) value);
29356
29357 newval |= value >> 2;
29358 break;
29359
29360 case 9: /* SP load/store. */
29361 if (value & ~0x3fc)
29362 as_bad_where (fixP->fx_file, fixP->fx_line,
29363 _("invalid offset, value too big (0x%08lX)"),
29364 (long) value);
29365 newval |= value >> 2;
29366 break;
29367
29368 case 6: /* Word load/store. */
29369 if (value & ~0x7c)
29370 as_bad_where (fixP->fx_file, fixP->fx_line,
29371 _("invalid offset, value too big (0x%08lX)"),
29372 (long) value);
29373 newval |= value << 4; /* 6 - 2. */
29374 break;
29375
29376 case 7: /* Byte load/store. */
29377 if (value & ~0x1f)
29378 as_bad_where (fixP->fx_file, fixP->fx_line,
29379 _("invalid offset, value too big (0x%08lX)"),
29380 (long) value);
29381 newval |= value << 6;
29382 break;
29383
29384 case 8: /* Halfword load/store. */
29385 if (value & ~0x3e)
29386 as_bad_where (fixP->fx_file, fixP->fx_line,
29387 _("invalid offset, value too big (0x%08lX)"),
29388 (long) value);
29389 newval |= value << 5; /* 6 - 1. */
29390 break;
29391
29392 default:
29393 as_bad_where (fixP->fx_file, fixP->fx_line,
29394 "Unable to process relocation for thumb opcode: %lx",
29395 (unsigned long) newval);
29396 break;
29397 }
29398 md_number_to_chars (buf, newval, THUMB_SIZE);
29399 break;
29400
29401 case BFD_RELOC_ARM_THUMB_ADD:
29402 /* This is a complicated relocation, since we use it for all of
29403 the following immediate relocations:
29404
29405 3bit ADD/SUB
29406 8bit ADD/SUB
29407 9bit ADD/SUB SP word-aligned
29408 10bit ADD PC/SP word-aligned
29409
29410 The type of instruction being processed is encoded in the
29411 instruction field:
29412
29413 0x8000 SUB
29414 0x00F0 Rd
29415 0x000F Rs
29416 */
29417 newval = md_chars_to_number (buf, THUMB_SIZE);
29418 {
29419 int rd = (newval >> 4) & 0xf;
29420 int rs = newval & 0xf;
29421 int subtract = !!(newval & 0x8000);
29422
29423 /* Check for HI regs, only very restricted cases allowed:
29424 Adjusting SP, and using PC or SP to get an address. */
29425 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
29426 || (rs > 7 && rs != REG_SP && rs != REG_PC))
29427 as_bad_where (fixP->fx_file, fixP->fx_line,
29428 _("invalid Hi register with immediate"));
29429
29430 /* If value is negative, choose the opposite instruction. */
29431 if ((offsetT) value < 0)
29432 {
29433 value = -value;
29434 subtract = !subtract;
29435 if ((offsetT) value < 0)
29436 as_bad_where (fixP->fx_file, fixP->fx_line,
29437 _("immediate value out of range"));
29438 }
29439
29440 if (rd == REG_SP)
29441 {
29442 if (value & ~0x1fc)
29443 as_bad_where (fixP->fx_file, fixP->fx_line,
29444 _("invalid immediate for stack address calculation"));
29445 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
29446 newval |= value >> 2;
29447 }
29448 else if (rs == REG_PC || rs == REG_SP)
29449 {
29450 /* PR gas/18541. If the addition is for a defined symbol
29451 within range of an ADR instruction then accept it. */
29452 if (subtract
29453 && value == 4
29454 && fixP->fx_addsy != NULL)
29455 {
29456 subtract = 0;
29457
29458 if (! S_IS_DEFINED (fixP->fx_addsy)
29459 || S_GET_SEGMENT (fixP->fx_addsy) != seg
29460 || S_IS_WEAK (fixP->fx_addsy))
29461 {
29462 as_bad_where (fixP->fx_file, fixP->fx_line,
29463 _("address calculation needs a strongly defined nearby symbol"));
29464 }
29465 else
29466 {
29467 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
29468
29469 /* Round up to the next 4-byte boundary. */
29470 if (v & 3)
29471 v = (v + 3) & ~ 3;
29472 else
29473 v += 4;
29474 v = S_GET_VALUE (fixP->fx_addsy) - v;
29475
29476 if (v & ~0x3fc)
29477 {
29478 as_bad_where (fixP->fx_file, fixP->fx_line,
29479 _("symbol too far away"));
29480 }
29481 else
29482 {
29483 fixP->fx_done = 1;
29484 value = v;
29485 }
29486 }
29487 }
29488
29489 if (subtract || value & ~0x3fc)
29490 as_bad_where (fixP->fx_file, fixP->fx_line,
29491 _("invalid immediate for address calculation (value = 0x%08lX)"),
29492 (unsigned long) (subtract ? - value : value));
29493 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
29494 newval |= rd << 8;
29495 newval |= value >> 2;
29496 }
29497 else if (rs == rd)
29498 {
29499 if (value & ~0xff)
29500 as_bad_where (fixP->fx_file, fixP->fx_line,
29501 _("immediate value out of range"));
29502 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
29503 newval |= (rd << 8) | value;
29504 }
29505 else
29506 {
29507 if (value & ~0x7)
29508 as_bad_where (fixP->fx_file, fixP->fx_line,
29509 _("immediate value out of range"));
29510 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
29511 newval |= rd | (rs << 3) | (value << 6);
29512 }
29513 }
29514 md_number_to_chars (buf, newval, THUMB_SIZE);
29515 break;
29516
29517 case BFD_RELOC_ARM_THUMB_IMM:
29518 newval = md_chars_to_number (buf, THUMB_SIZE);
29519 if (value > 255)
29520 as_bad_where (fixP->fx_file, fixP->fx_line,
29521 _("invalid immediate: %ld is out of range"),
29522 (long) value);
29523 newval |= value;
29524 md_number_to_chars (buf, newval, THUMB_SIZE);
29525 break;
29526
29527 case BFD_RELOC_ARM_THUMB_SHIFT:
29528 /* 5bit shift value (0..32). LSL cannot take 32. */
29529 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
29530 temp = newval & 0xf800;
29531 if (value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
29532 as_bad_where (fixP->fx_file, fixP->fx_line,
29533 _("invalid shift value: %ld"), (long) value);
29534 /* Shifts of zero must be encoded as LSL. */
29535 if (value == 0)
29536 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
29537 /* Shifts of 32 are encoded as zero. */
29538 else if (value == 32)
29539 value = 0;
29540 newval |= value << 6;
29541 md_number_to_chars (buf, newval, THUMB_SIZE);
29542 break;
29543
29544 case BFD_RELOC_VTABLE_INHERIT:
29545 case BFD_RELOC_VTABLE_ENTRY:
29546 fixP->fx_done = 0;
29547 return;
29548
29549 case BFD_RELOC_ARM_MOVW:
29550 case BFD_RELOC_ARM_MOVT:
29551 case BFD_RELOC_ARM_THUMB_MOVW:
29552 case BFD_RELOC_ARM_THUMB_MOVT:
29553 if (fixP->fx_done || !seg->use_rela_p)
29554 {
29555 /* REL format relocations are limited to a 16-bit addend. */
29556 if (!fixP->fx_done)
29557 {
29558 if (value + 0x8000 > 0x7fff + 0x8000)
29559 as_bad_where (fixP->fx_file, fixP->fx_line,
29560 _("offset out of range"));
29561 }
29562 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29563 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29564 {
29565 value >>= 16;
29566 }
29567
29568 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29569 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
29570 {
29571 newval = get_thumb32_insn (buf);
29572 newval &= 0xfbf08f00;
29573 newval |= (value & 0xf000) << 4;
29574 newval |= (value & 0x0800) << 15;
29575 newval |= (value & 0x0700) << 4;
29576 newval |= (value & 0x00ff);
29577 put_thumb32_insn (buf, newval);
29578 }
29579 else
29580 {
29581 newval = md_chars_to_number (buf, 4);
29582 newval &= 0xfff0f000;
29583 newval |= value & 0x0fff;
29584 newval |= (value & 0xf000) << 4;
29585 md_number_to_chars (buf, newval, 4);
29586 }
29587 }
29588 return;
29589
29590 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29591 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29592 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29593 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29594 gas_assert (!fixP->fx_done);
29595 {
29596 bfd_vma insn;
29597 bool is_mov;
29598 bfd_vma encoded_addend = value;
29599
29600 /* Check that addend can be encoded in instruction. */
29601 if (!seg->use_rela_p && value > 255)
29602 as_bad_where (fixP->fx_file, fixP->fx_line,
29603 _("the offset 0x%08lX is not representable"),
29604 (unsigned long) encoded_addend);
29605
29606 /* Extract the instruction. */
29607 insn = md_chars_to_number (buf, THUMB_SIZE);
29608 is_mov = (insn & 0xf800) == 0x2000;
29609
29610 /* Encode insn. */
29611 if (is_mov)
29612 {
29613 if (!seg->use_rela_p)
29614 insn |= encoded_addend;
29615 }
29616 else
29617 {
29618 int rd, rs;
29619
29620 /* Extract the instruction. */
29621 /* Encoding is the following
29622 0x8000 SUB
29623 0x00F0 Rd
29624 0x000F Rs
29625 */
29626 /* The following conditions must be true :
29627 - ADD
29628 - Rd == Rs
29629 - Rd <= 7
29630 */
29631 rd = (insn >> 4) & 0xf;
29632 rs = insn & 0xf;
29633 if ((insn & 0x8000) || (rd != rs) || rd > 7)
29634 as_bad_where (fixP->fx_file, fixP->fx_line,
29635 _("Unable to process relocation for thumb opcode: %lx"),
29636 (unsigned long) insn);
29637
29638 /* Encode as ADD immediate8 thumb 1 code. */
29639 insn = 0x3000 | (rd << 8);
29640
29641 /* Place the encoded addend into the first 8 bits of the
29642 instruction. */
29643 if (!seg->use_rela_p)
29644 insn |= encoded_addend;
29645 }
29646
29647 /* Update the instruction. */
29648 md_number_to_chars (buf, insn, THUMB_SIZE);
29649 }
29650 break;
29651
29652 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29653 case BFD_RELOC_ARM_ALU_PC_G0:
29654 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29655 case BFD_RELOC_ARM_ALU_PC_G1:
29656 case BFD_RELOC_ARM_ALU_PC_G2:
29657 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29658 case BFD_RELOC_ARM_ALU_SB_G0:
29659 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29660 case BFD_RELOC_ARM_ALU_SB_G1:
29661 case BFD_RELOC_ARM_ALU_SB_G2:
29662 gas_assert (!fixP->fx_done);
29663 if (!seg->use_rela_p)
29664 {
29665 bfd_vma insn;
29666 bfd_vma encoded_addend;
29667 bfd_vma addend_abs = llabs ((offsetT) value);
29668
29669 /* Check that the absolute value of the addend can be
29670 expressed as an 8-bit constant plus a rotation. */
29671 encoded_addend = encode_arm_immediate (addend_abs);
29672 if (encoded_addend == (unsigned int) FAIL)
29673 as_bad_where (fixP->fx_file, fixP->fx_line,
29674 _("the offset 0x%08lX is not representable"),
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 positive, use an ADD instruction.
29681 Otherwise use a SUB. Take care not to destroy the S bit. */
29682 insn &= 0xff1fffff;
29683 if ((offsetT) value < 0)
29684 insn |= 1 << 22;
29685 else
29686 insn |= 1 << 23;
29687
29688 /* Place the encoded addend into the first 12 bits of the
29689 instruction. */
29690 insn &= 0xfffff000;
29691 insn |= encoded_addend;
29692
29693 /* Update the instruction. */
29694 md_number_to_chars (buf, insn, INSN_SIZE);
29695 }
29696 break;
29697
29698 case BFD_RELOC_ARM_LDR_PC_G0:
29699 case BFD_RELOC_ARM_LDR_PC_G1:
29700 case BFD_RELOC_ARM_LDR_PC_G2:
29701 case BFD_RELOC_ARM_LDR_SB_G0:
29702 case BFD_RELOC_ARM_LDR_SB_G1:
29703 case BFD_RELOC_ARM_LDR_SB_G2:
29704 gas_assert (!fixP->fx_done);
29705 if (!seg->use_rela_p)
29706 {
29707 bfd_vma insn;
29708 bfd_vma addend_abs = llabs ((offsetT) value);
29709
29710 /* Check that the absolute value of the addend can be
29711 encoded in 12 bits. */
29712 if (addend_abs >= 0x1000)
29713 as_bad_where (fixP->fx_file, fixP->fx_line,
29714 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
29715 (unsigned long) addend_abs);
29716
29717 /* Extract the instruction. */
29718 insn = md_chars_to_number (buf, INSN_SIZE);
29719
29720 /* If the addend is negative, clear bit 23 of the instruction.
29721 Otherwise set it. */
29722 if ((offsetT) value < 0)
29723 insn &= ~(1 << 23);
29724 else
29725 insn |= 1 << 23;
29726
29727 /* Place the absolute value of the addend into the first 12 bits
29728 of the instruction. */
29729 insn &= 0xfffff000;
29730 insn |= addend_abs;
29731
29732 /* Update the instruction. */
29733 md_number_to_chars (buf, insn, INSN_SIZE);
29734 }
29735 break;
29736
29737 case BFD_RELOC_ARM_LDRS_PC_G0:
29738 case BFD_RELOC_ARM_LDRS_PC_G1:
29739 case BFD_RELOC_ARM_LDRS_PC_G2:
29740 case BFD_RELOC_ARM_LDRS_SB_G0:
29741 case BFD_RELOC_ARM_LDRS_SB_G1:
29742 case BFD_RELOC_ARM_LDRS_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 ((offsetT) value);
29748
29749 /* Check that the absolute value of the addend can be
29750 encoded in 8 bits. */
29751 if (addend_abs >= 0x100)
29752 as_bad_where (fixP->fx_file, fixP->fx_line,
29753 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
29754 (unsigned long) addend_abs);
29755
29756 /* Extract the instruction. */
29757 insn = md_chars_to_number (buf, INSN_SIZE);
29758
29759 /* If the addend is negative, clear bit 23 of the instruction.
29760 Otherwise set it. */
29761 if ((offsetT) value < 0)
29762 insn &= ~(1 << 23);
29763 else
29764 insn |= 1 << 23;
29765
29766 /* Place the first four bits of the absolute value of the addend
29767 into the first 4 bits of the instruction, and the remaining
29768 four into bits 8 .. 11. */
29769 insn &= 0xfffff0f0;
29770 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
29771
29772 /* Update the instruction. */
29773 md_number_to_chars (buf, insn, INSN_SIZE);
29774 }
29775 break;
29776
29777 case BFD_RELOC_ARM_LDC_PC_G0:
29778 case BFD_RELOC_ARM_LDC_PC_G1:
29779 case BFD_RELOC_ARM_LDC_PC_G2:
29780 case BFD_RELOC_ARM_LDC_SB_G0:
29781 case BFD_RELOC_ARM_LDC_SB_G1:
29782 case BFD_RELOC_ARM_LDC_SB_G2:
29783 gas_assert (!fixP->fx_done);
29784 if (!seg->use_rela_p)
29785 {
29786 bfd_vma insn;
29787 bfd_vma addend_abs = llabs ((offsetT) value);
29788
29789 /* Check that the absolute value of the addend is a multiple of
29790 four and, when divided by four, fits in 8 bits. */
29791 if (addend_abs & 0x3)
29792 as_bad_where (fixP->fx_file, fixP->fx_line,
29793 _("bad offset 0x%08lX (must be word-aligned)"),
29794 (unsigned long) addend_abs);
29795
29796 if ((addend_abs >> 2) > 0xff)
29797 as_bad_where (fixP->fx_file, fixP->fx_line,
29798 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
29799 (unsigned long) addend_abs);
29800
29801 /* Extract the instruction. */
29802 insn = md_chars_to_number (buf, INSN_SIZE);
29803
29804 /* If the addend is negative, clear bit 23 of the instruction.
29805 Otherwise set it. */
29806 if ((offsetT) value < 0)
29807 insn &= ~(1 << 23);
29808 else
29809 insn |= 1 << 23;
29810
29811 /* Place the addend (divided by four) into the first eight
29812 bits of the instruction. */
29813 insn &= 0xfffffff0;
29814 insn |= addend_abs >> 2;
29815
29816 /* Update the instruction. */
29817 md_number_to_chars (buf, insn, INSN_SIZE);
29818 }
29819 break;
29820
29821 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29822 if (fixP->fx_addsy
29823 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29824 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29825 && ARM_IS_FUNC (fixP->fx_addsy)
29826 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29827 {
29828 /* Force a relocation for a branch 5 bits wide. */
29829 fixP->fx_done = 0;
29830 }
29831 if (v8_1_branch_value_check (value, 5, false) == FAIL)
29832 as_bad_where (fixP->fx_file, fixP->fx_line,
29833 BAD_BRANCH_OFF);
29834
29835 if (fixP->fx_done || !seg->use_rela_p)
29836 {
29837 addressT boff = value >> 1;
29838
29839 newval = md_chars_to_number (buf, THUMB_SIZE);
29840 newval |= (boff << 7);
29841 md_number_to_chars (buf, newval, THUMB_SIZE);
29842 }
29843 break;
29844
29845 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29846 if (fixP->fx_addsy
29847 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29848 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29849 && ARM_IS_FUNC (fixP->fx_addsy)
29850 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29851 {
29852 fixP->fx_done = 0;
29853 }
29854 if ((value & ~0x7f) && ((value & ~0x3f) != (valueT) ~0x3f))
29855 as_bad_where (fixP->fx_file, fixP->fx_line,
29856 _("branch out of range"));
29857
29858 if (fixP->fx_done || !seg->use_rela_p)
29859 {
29860 newval = md_chars_to_number (buf, THUMB_SIZE);
29861
29862 addressT boff = ((newval & 0x0780) >> 7) << 1;
29863 addressT diff = value - boff;
29864
29865 if (diff == 4)
29866 {
29867 newval |= 1 << 1; /* T bit. */
29868 }
29869 else if (diff != 2)
29870 {
29871 as_bad_where (fixP->fx_file, fixP->fx_line,
29872 _("out of range label-relative fixup value"));
29873 }
29874 md_number_to_chars (buf, newval, THUMB_SIZE);
29875 }
29876 break;
29877
29878 case BFD_RELOC_ARM_THUMB_BF17:
29879 if (fixP->fx_addsy
29880 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29881 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29882 && ARM_IS_FUNC (fixP->fx_addsy)
29883 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29884 {
29885 /* Force a relocation for a branch 17 bits wide. */
29886 fixP->fx_done = 0;
29887 }
29888
29889 if (v8_1_branch_value_check (value, 17, true) == FAIL)
29890 as_bad_where (fixP->fx_file, fixP->fx_line,
29891 BAD_BRANCH_OFF);
29892
29893 if (fixP->fx_done || !seg->use_rela_p)
29894 {
29895 offsetT newval2;
29896 addressT immA, immB, immC;
29897
29898 immA = (value & 0x0001f000) >> 12;
29899 immB = (value & 0x00000ffc) >> 2;
29900 immC = (value & 0x00000002) >> 1;
29901
29902 newval = md_chars_to_number (buf, THUMB_SIZE);
29903 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29904 newval |= immA;
29905 newval2 |= (immC << 11) | (immB << 1);
29906 md_number_to_chars (buf, newval, THUMB_SIZE);
29907 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29908 }
29909 break;
29910
29911 case BFD_RELOC_ARM_THUMB_BF19:
29912 if (fixP->fx_addsy
29913 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29914 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29915 && ARM_IS_FUNC (fixP->fx_addsy)
29916 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29917 {
29918 /* Force a relocation for a branch 19 bits wide. */
29919 fixP->fx_done = 0;
29920 }
29921
29922 if (v8_1_branch_value_check (value, 19, true) == FAIL)
29923 as_bad_where (fixP->fx_file, fixP->fx_line,
29924 BAD_BRANCH_OFF);
29925
29926 if (fixP->fx_done || !seg->use_rela_p)
29927 {
29928 offsetT newval2;
29929 addressT immA, immB, immC;
29930
29931 immA = (value & 0x0007f000) >> 12;
29932 immB = (value & 0x00000ffc) >> 2;
29933 immC = (value & 0x00000002) >> 1;
29934
29935 newval = md_chars_to_number (buf, THUMB_SIZE);
29936 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29937 newval |= immA;
29938 newval2 |= (immC << 11) | (immB << 1);
29939 md_number_to_chars (buf, newval, THUMB_SIZE);
29940 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29941 }
29942 break;
29943
29944 case BFD_RELOC_ARM_THUMB_BF13:
29945 if (fixP->fx_addsy
29946 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29947 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29948 && ARM_IS_FUNC (fixP->fx_addsy)
29949 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29950 {
29951 /* Force a relocation for a branch 13 bits wide. */
29952 fixP->fx_done = 0;
29953 }
29954
29955 if (v8_1_branch_value_check (value, 13, true) == FAIL)
29956 as_bad_where (fixP->fx_file, fixP->fx_line,
29957 BAD_BRANCH_OFF);
29958
29959 if (fixP->fx_done || !seg->use_rela_p)
29960 {
29961 offsetT newval2;
29962 addressT immA, immB, immC;
29963
29964 immA = (value & 0x00001000) >> 12;
29965 immB = (value & 0x00000ffc) >> 2;
29966 immC = (value & 0x00000002) >> 1;
29967
29968 newval = md_chars_to_number (buf, THUMB_SIZE);
29969 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29970 newval |= immA;
29971 newval2 |= (immC << 11) | (immB << 1);
29972 md_number_to_chars (buf, newval, THUMB_SIZE);
29973 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29974 }
29975 break;
29976
29977 case BFD_RELOC_ARM_THUMB_LOOP12:
29978 if (fixP->fx_addsy
29979 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29980 && !S_FORCE_RELOC (fixP->fx_addsy, true)
29981 && ARM_IS_FUNC (fixP->fx_addsy)
29982 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29983 {
29984 /* Force a relocation for a branch 12 bits wide. */
29985 fixP->fx_done = 0;
29986 }
29987
29988 bfd_vma insn = get_thumb32_insn (buf);
29989 /* le lr, <label>, le <label> or letp lr, <label> */
29990 if (((insn & 0xffffffff) == 0xf00fc001)
29991 || ((insn & 0xffffffff) == 0xf02fc001)
29992 || ((insn & 0xffffffff) == 0xf01fc001))
29993 value = -value;
29994
29995 if (v8_1_branch_value_check (value, 12, false) == FAIL)
29996 as_bad_where (fixP->fx_file, fixP->fx_line,
29997 BAD_BRANCH_OFF);
29998 if (fixP->fx_done || !seg->use_rela_p)
29999 {
30000 addressT imml, immh;
30001
30002 immh = (value & 0x00000ffc) >> 2;
30003 imml = (value & 0x00000002) >> 1;
30004
30005 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
30006 newval |= (imml << 11) | (immh << 1);
30007 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
30008 }
30009 break;
30010
30011 case BFD_RELOC_ARM_V4BX:
30012 /* This will need to go in the object file. */
30013 fixP->fx_done = 0;
30014 break;
30015
30016 case BFD_RELOC_UNUSED:
30017 default:
30018 as_bad_where (fixP->fx_file, fixP->fx_line,
30019 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
30020 }
30021 }
30022
30023 /* Translate internal representation of relocation info to BFD target
30024 format. */
30025
30026 arelent *
30027 tc_gen_reloc (asection *section, fixS *fixp)
30028 {
30029 arelent * reloc;
30030 bfd_reloc_code_real_type code;
30031
30032 reloc = XNEW (arelent);
30033
30034 reloc->sym_ptr_ptr = XNEW (asymbol *);
30035 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
30036 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
30037
30038 if (fixp->fx_pcrel)
30039 {
30040 if (section->use_rela_p)
30041 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
30042 else
30043 fixp->fx_offset = reloc->address;
30044 }
30045 reloc->addend = fixp->fx_offset;
30046
30047 switch (fixp->fx_r_type)
30048 {
30049 case BFD_RELOC_8:
30050 if (fixp->fx_pcrel)
30051 {
30052 code = BFD_RELOC_8_PCREL;
30053 break;
30054 }
30055 /* Fall through. */
30056
30057 case BFD_RELOC_16:
30058 if (fixp->fx_pcrel)
30059 {
30060 code = BFD_RELOC_16_PCREL;
30061 break;
30062 }
30063 /* Fall through. */
30064
30065 case BFD_RELOC_32:
30066 if (fixp->fx_pcrel)
30067 {
30068 code = BFD_RELOC_32_PCREL;
30069 break;
30070 }
30071 /* Fall through. */
30072
30073 case BFD_RELOC_ARM_MOVW:
30074 if (fixp->fx_pcrel)
30075 {
30076 code = BFD_RELOC_ARM_MOVW_PCREL;
30077 break;
30078 }
30079 /* Fall through. */
30080
30081 case BFD_RELOC_ARM_MOVT:
30082 if (fixp->fx_pcrel)
30083 {
30084 code = BFD_RELOC_ARM_MOVT_PCREL;
30085 break;
30086 }
30087 /* Fall through. */
30088
30089 case BFD_RELOC_ARM_THUMB_MOVW:
30090 if (fixp->fx_pcrel)
30091 {
30092 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
30093 break;
30094 }
30095 /* Fall through. */
30096
30097 case BFD_RELOC_ARM_THUMB_MOVT:
30098 if (fixp->fx_pcrel)
30099 {
30100 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
30101 break;
30102 }
30103 /* Fall through. */
30104
30105 case BFD_RELOC_NONE:
30106 case BFD_RELOC_ARM_PCREL_BRANCH:
30107 case BFD_RELOC_ARM_PCREL_BLX:
30108 case BFD_RELOC_RVA:
30109 case BFD_RELOC_THUMB_PCREL_BRANCH7:
30110 case BFD_RELOC_THUMB_PCREL_BRANCH9:
30111 case BFD_RELOC_THUMB_PCREL_BRANCH12:
30112 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30113 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30114 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30115 case BFD_RELOC_VTABLE_ENTRY:
30116 case BFD_RELOC_VTABLE_INHERIT:
30117 #ifdef TE_PE
30118 case BFD_RELOC_32_SECREL:
30119 #endif
30120 code = fixp->fx_r_type;
30121 break;
30122
30123 case BFD_RELOC_THUMB_PCREL_BLX:
30124 #ifdef OBJ_ELF
30125 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
30126 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
30127 else
30128 #endif
30129 code = BFD_RELOC_THUMB_PCREL_BLX;
30130 break;
30131
30132 case BFD_RELOC_ARM_LITERAL:
30133 case BFD_RELOC_ARM_HWLITERAL:
30134 /* If this is called then the a literal has
30135 been referenced across a section boundary. */
30136 as_bad_where (fixp->fx_file, fixp->fx_line,
30137 _("literal referenced across section boundary"));
30138 return NULL;
30139
30140 #ifdef OBJ_ELF
30141 case BFD_RELOC_ARM_TLS_CALL:
30142 case BFD_RELOC_ARM_THM_TLS_CALL:
30143 case BFD_RELOC_ARM_TLS_DESCSEQ:
30144 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
30145 case BFD_RELOC_ARM_GOT32:
30146 case BFD_RELOC_ARM_GOTOFF:
30147 case BFD_RELOC_ARM_GOT_PREL:
30148 case BFD_RELOC_ARM_PLT32:
30149 case BFD_RELOC_ARM_TARGET1:
30150 case BFD_RELOC_ARM_ROSEGREL32:
30151 case BFD_RELOC_ARM_SBREL32:
30152 case BFD_RELOC_ARM_PREL31:
30153 case BFD_RELOC_ARM_TARGET2:
30154 case BFD_RELOC_ARM_TLS_LDO32:
30155 case BFD_RELOC_ARM_PCREL_CALL:
30156 case BFD_RELOC_ARM_PCREL_JUMP:
30157 case BFD_RELOC_ARM_ALU_PC_G0_NC:
30158 case BFD_RELOC_ARM_ALU_PC_G0:
30159 case BFD_RELOC_ARM_ALU_PC_G1_NC:
30160 case BFD_RELOC_ARM_ALU_PC_G1:
30161 case BFD_RELOC_ARM_ALU_PC_G2:
30162 case BFD_RELOC_ARM_LDR_PC_G0:
30163 case BFD_RELOC_ARM_LDR_PC_G1:
30164 case BFD_RELOC_ARM_LDR_PC_G2:
30165 case BFD_RELOC_ARM_LDRS_PC_G0:
30166 case BFD_RELOC_ARM_LDRS_PC_G1:
30167 case BFD_RELOC_ARM_LDRS_PC_G2:
30168 case BFD_RELOC_ARM_LDC_PC_G0:
30169 case BFD_RELOC_ARM_LDC_PC_G1:
30170 case BFD_RELOC_ARM_LDC_PC_G2:
30171 case BFD_RELOC_ARM_ALU_SB_G0_NC:
30172 case BFD_RELOC_ARM_ALU_SB_G0:
30173 case BFD_RELOC_ARM_ALU_SB_G1_NC:
30174 case BFD_RELOC_ARM_ALU_SB_G1:
30175 case BFD_RELOC_ARM_ALU_SB_G2:
30176 case BFD_RELOC_ARM_LDR_SB_G0:
30177 case BFD_RELOC_ARM_LDR_SB_G1:
30178 case BFD_RELOC_ARM_LDR_SB_G2:
30179 case BFD_RELOC_ARM_LDRS_SB_G0:
30180 case BFD_RELOC_ARM_LDRS_SB_G1:
30181 case BFD_RELOC_ARM_LDRS_SB_G2:
30182 case BFD_RELOC_ARM_LDC_SB_G0:
30183 case BFD_RELOC_ARM_LDC_SB_G1:
30184 case BFD_RELOC_ARM_LDC_SB_G2:
30185 case BFD_RELOC_ARM_V4BX:
30186 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
30187 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
30188 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
30189 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
30190 case BFD_RELOC_ARM_GOTFUNCDESC:
30191 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
30192 case BFD_RELOC_ARM_FUNCDESC:
30193 case BFD_RELOC_ARM_THUMB_BF17:
30194 case BFD_RELOC_ARM_THUMB_BF19:
30195 case BFD_RELOC_ARM_THUMB_BF13:
30196 code = fixp->fx_r_type;
30197 break;
30198
30199 case BFD_RELOC_ARM_TLS_GOTDESC:
30200 case BFD_RELOC_ARM_TLS_GD32:
30201 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
30202 case BFD_RELOC_ARM_TLS_LE32:
30203 case BFD_RELOC_ARM_TLS_IE32:
30204 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
30205 case BFD_RELOC_ARM_TLS_LDM32:
30206 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
30207 /* BFD will include the symbol's address in the addend.
30208 But we don't want that, so subtract it out again here. */
30209 if (!S_IS_COMMON (fixp->fx_addsy))
30210 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
30211 code = fixp->fx_r_type;
30212 break;
30213 #endif
30214
30215 case BFD_RELOC_ARM_IMMEDIATE:
30216 as_bad_where (fixp->fx_file, fixp->fx_line,
30217 _("internal relocation (type: IMMEDIATE) not fixed up"));
30218 return NULL;
30219
30220 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
30221 as_bad_where (fixp->fx_file, fixp->fx_line,
30222 _("ADRL used for a symbol not defined in the same file"));
30223 return NULL;
30224
30225 case BFD_RELOC_THUMB_PCREL_BRANCH5:
30226 case BFD_RELOC_THUMB_PCREL_BFCSEL:
30227 case BFD_RELOC_ARM_THUMB_LOOP12:
30228 as_bad_where (fixp->fx_file, fixp->fx_line,
30229 _("%s used for a symbol not defined in the same file"),
30230 bfd_get_reloc_code_name (fixp->fx_r_type));
30231 return NULL;
30232
30233 case BFD_RELOC_ARM_OFFSET_IMM:
30234 if (section->use_rela_p)
30235 {
30236 code = fixp->fx_r_type;
30237 break;
30238 }
30239
30240 if (fixp->fx_addsy != NULL
30241 && !S_IS_DEFINED (fixp->fx_addsy)
30242 && S_IS_LOCAL (fixp->fx_addsy))
30243 {
30244 as_bad_where (fixp->fx_file, fixp->fx_line,
30245 _("undefined local label `%s'"),
30246 S_GET_NAME (fixp->fx_addsy));
30247 return NULL;
30248 }
30249
30250 as_bad_where (fixp->fx_file, fixp->fx_line,
30251 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
30252 return NULL;
30253
30254 default:
30255 {
30256 const char * type;
30257
30258 switch (fixp->fx_r_type)
30259 {
30260 case BFD_RELOC_NONE: type = "NONE"; break;
30261 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
30262 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
30263 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
30264 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
30265 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
30266 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
30267 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
30268 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
30269 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
30270 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
30271 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
30272 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
30273 default: type = _("<unknown>"); break;
30274 }
30275 as_bad_where (fixp->fx_file, fixp->fx_line,
30276 _("cannot represent %s relocation in this object file format"),
30277 type);
30278 return NULL;
30279 }
30280 }
30281
30282 #ifdef OBJ_ELF
30283 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
30284 && GOT_symbol
30285 && fixp->fx_addsy == GOT_symbol)
30286 {
30287 code = BFD_RELOC_ARM_GOTPC;
30288 reloc->addend = fixp->fx_offset = reloc->address;
30289 }
30290 #endif
30291
30292 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
30293
30294 if (reloc->howto == NULL)
30295 {
30296 as_bad_where (fixp->fx_file, fixp->fx_line,
30297 _("cannot represent %s relocation in this object file format"),
30298 bfd_get_reloc_code_name (code));
30299 return NULL;
30300 }
30301
30302 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
30303 vtable entry to be used in the relocation's section offset. */
30304 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30305 reloc->address = fixp->fx_offset;
30306
30307 return reloc;
30308 }
30309
30310 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
30311
30312 void
30313 cons_fix_new_arm (fragS * frag,
30314 int where,
30315 int size,
30316 expressionS * exp,
30317 bfd_reloc_code_real_type reloc)
30318 {
30319 int pcrel = 0;
30320
30321 /* Pick a reloc.
30322 FIXME: @@ Should look at CPU word size. */
30323 switch (size)
30324 {
30325 case 1:
30326 reloc = BFD_RELOC_8;
30327 break;
30328 case 2:
30329 reloc = BFD_RELOC_16;
30330 break;
30331 case 4:
30332 default:
30333 reloc = BFD_RELOC_32;
30334 break;
30335 case 8:
30336 reloc = BFD_RELOC_64;
30337 break;
30338 }
30339
30340 #ifdef TE_PE
30341 if (exp->X_op == O_secrel)
30342 {
30343 exp->X_op = O_symbol;
30344 reloc = BFD_RELOC_32_SECREL;
30345 }
30346 #endif
30347
30348 fix_new_exp (frag, where, size, exp, pcrel, reloc);
30349 }
30350
30351 #if defined (OBJ_COFF)
30352 void
30353 arm_validate_fix (fixS * fixP)
30354 {
30355 /* If the destination of the branch is a defined symbol which does not have
30356 the THUMB_FUNC attribute, then we must be calling a function which has
30357 the (interfacearm) attribute. We look for the Thumb entry point to that
30358 function and change the branch to refer to that function instead. */
30359 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
30360 && fixP->fx_addsy != NULL
30361 && S_IS_DEFINED (fixP->fx_addsy)
30362 && ! THUMB_IS_FUNC (fixP->fx_addsy))
30363 {
30364 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
30365 }
30366 }
30367 #endif
30368
30369
30370 int
30371 arm_force_relocation (struct fix * fixp)
30372 {
30373 #if defined (OBJ_COFF) && defined (TE_PE)
30374 if (fixp->fx_r_type == BFD_RELOC_RVA)
30375 return 1;
30376 #endif
30377
30378 /* In case we have a call or a branch to a function in ARM ISA mode from
30379 a thumb function or vice-versa force the relocation. These relocations
30380 are cleared off for some cores that might have blx and simple transformations
30381 are possible. */
30382
30383 #ifdef OBJ_ELF
30384 switch (fixp->fx_r_type)
30385 {
30386 case BFD_RELOC_ARM_PCREL_JUMP:
30387 case BFD_RELOC_ARM_PCREL_CALL:
30388 case BFD_RELOC_THUMB_PCREL_BLX:
30389 if (THUMB_IS_FUNC (fixp->fx_addsy))
30390 return 1;
30391 break;
30392
30393 case BFD_RELOC_ARM_PCREL_BLX:
30394 case BFD_RELOC_THUMB_PCREL_BRANCH25:
30395 case BFD_RELOC_THUMB_PCREL_BRANCH20:
30396 case BFD_RELOC_THUMB_PCREL_BRANCH23:
30397 if (ARM_IS_FUNC (fixp->fx_addsy))
30398 return 1;
30399 break;
30400
30401 default:
30402 break;
30403 }
30404 #endif
30405
30406 /* Resolve these relocations even if the symbol is extern or weak.
30407 Technically this is probably wrong due to symbol preemption.
30408 In practice these relocations do not have enough range to be useful
30409 at dynamic link time, and some code (e.g. in the Linux kernel)
30410 expects these references to be resolved. */
30411 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
30412 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
30413 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
30414 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
30415 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
30416 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
30417 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
30418 || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH12
30419 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
30420 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
30421 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
30422 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
30423 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
30424 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
30425 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
30426 return 0;
30427
30428 /* Always leave these relocations for the linker. */
30429 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30430 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30431 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30432 return 1;
30433
30434 /* Always generate relocations against function symbols. */
30435 if (fixp->fx_r_type == BFD_RELOC_32
30436 && fixp->fx_addsy
30437 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
30438 return 1;
30439
30440 return generic_force_reloc (fixp);
30441 }
30442
30443 #if defined (OBJ_ELF) || defined (OBJ_COFF)
30444 /* Relocations against function names must be left unadjusted,
30445 so that the linker can use this information to generate interworking
30446 stubs. The MIPS version of this function
30447 also prevents relocations that are mips-16 specific, but I do not
30448 know why it does this.
30449
30450 FIXME:
30451 There is one other problem that ought to be addressed here, but
30452 which currently is not: Taking the address of a label (rather
30453 than a function) and then later jumping to that address. Such
30454 addresses also ought to have their bottom bit set (assuming that
30455 they reside in Thumb code), but at the moment they will not. */
30456
30457 bool
30458 arm_fix_adjustable (fixS * fixP)
30459 {
30460 if (fixP->fx_addsy == NULL)
30461 return 1;
30462
30463 /* Preserve relocations against symbols with function type. */
30464 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
30465 return false;
30466
30467 if (THUMB_IS_FUNC (fixP->fx_addsy)
30468 && fixP->fx_subsy == NULL)
30469 return false;
30470
30471 /* We need the symbol name for the VTABLE entries. */
30472 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
30473 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
30474 return false;
30475
30476 /* Don't allow symbols to be discarded on GOT related relocs. */
30477 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
30478 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
30479 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
30480 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
30481 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
30482 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
30483 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
30484 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
30485 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
30486 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
30487 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
30488 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
30489 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
30490 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
30491 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
30492 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
30493 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
30494 return false;
30495
30496 /* Similarly for group relocations. */
30497 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
30498 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
30499 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
30500 return false;
30501
30502 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
30503 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
30504 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
30505 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
30506 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
30507 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
30508 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
30509 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
30510 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
30511 return false;
30512
30513 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
30514 offsets, so keep these symbols. */
30515 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
30516 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
30517 return false;
30518
30519 return true;
30520 }
30521 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
30522
30523 #ifdef OBJ_ELF
30524 const char *
30525 elf32_arm_target_format (void)
30526 {
30527 #if defined (TE_VXWORKS)
30528 return (target_big_endian
30529 ? "elf32-bigarm-vxworks"
30530 : "elf32-littlearm-vxworks");
30531 #elif defined (TE_NACL)
30532 return (target_big_endian
30533 ? "elf32-bigarm-nacl"
30534 : "elf32-littlearm-nacl");
30535 #else
30536 if (arm_fdpic)
30537 {
30538 if (target_big_endian)
30539 return "elf32-bigarm-fdpic";
30540 else
30541 return "elf32-littlearm-fdpic";
30542 }
30543 else
30544 {
30545 if (target_big_endian)
30546 return "elf32-bigarm";
30547 else
30548 return "elf32-littlearm";
30549 }
30550 #endif
30551 }
30552
30553 void
30554 armelf_frob_symbol (symbolS * symp,
30555 int * puntp)
30556 {
30557 elf_frob_symbol (symp, puntp);
30558 }
30559 #endif
30560
30561 /* MD interface: Finalization. */
30562
30563 void
30564 arm_cleanup (void)
30565 {
30566 literal_pool * pool;
30567
30568 /* Ensure that all the predication blocks are properly closed. */
30569 check_pred_blocks_finished ();
30570
30571 for (pool = list_of_pools; pool; pool = pool->next)
30572 {
30573 /* Put it at the end of the relevant section. */
30574 subseg_set (pool->section, pool->sub_section);
30575 #ifdef OBJ_ELF
30576 arm_elf_change_section ();
30577 #endif
30578 s_ltorg (0);
30579 }
30580 }
30581
30582 #ifdef OBJ_ELF
30583 /* Remove any excess mapping symbols generated for alignment frags in
30584 SEC. We may have created a mapping symbol before a zero byte
30585 alignment; remove it if there's a mapping symbol after the
30586 alignment. */
30587 static void
30588 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
30589 void *dummy ATTRIBUTE_UNUSED)
30590 {
30591 segment_info_type *seginfo = seg_info (sec);
30592 fragS *fragp;
30593
30594 if (seginfo == NULL || seginfo->frchainP == NULL)
30595 return;
30596
30597 for (fragp = seginfo->frchainP->frch_root;
30598 fragp != NULL;
30599 fragp = fragp->fr_next)
30600 {
30601 symbolS *sym = fragp->tc_frag_data.last_map;
30602 fragS *next = fragp->fr_next;
30603
30604 /* Variable-sized frags have been converted to fixed size by
30605 this point. But if this was variable-sized to start with,
30606 there will be a fixed-size frag after it. So don't handle
30607 next == NULL. */
30608 if (sym == NULL || next == NULL)
30609 continue;
30610
30611 if (S_GET_VALUE (sym) < next->fr_address)
30612 /* Not at the end of this frag. */
30613 continue;
30614 know (S_GET_VALUE (sym) == next->fr_address);
30615
30616 do
30617 {
30618 if (next->tc_frag_data.first_map != NULL)
30619 {
30620 /* Next frag starts with a mapping symbol. Discard this
30621 one. */
30622 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30623 break;
30624 }
30625
30626 if (next->fr_next == NULL)
30627 {
30628 /* This mapping symbol is at the end of the section. Discard
30629 it. */
30630 know (next->fr_fix == 0 && next->fr_var == 0);
30631 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
30632 break;
30633 }
30634
30635 /* As long as we have empty frags without any mapping symbols,
30636 keep looking. */
30637 /* If the next frag is non-empty and does not start with a
30638 mapping symbol, then this mapping symbol is required. */
30639 if (next->fr_address != next->fr_next->fr_address)
30640 break;
30641
30642 next = next->fr_next;
30643 }
30644 while (next != NULL);
30645 }
30646 }
30647 #endif
30648
30649 /* Adjust the symbol table. This marks Thumb symbols as distinct from
30650 ARM ones. */
30651
30652 void
30653 arm_adjust_symtab (void)
30654 {
30655 #ifdef OBJ_COFF
30656 symbolS * sym;
30657
30658 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30659 {
30660 if (ARM_IS_THUMB (sym))
30661 {
30662 if (THUMB_IS_FUNC (sym))
30663 {
30664 /* Mark the symbol as a Thumb function. */
30665 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
30666 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
30667 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
30668
30669 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
30670 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
30671 else
30672 as_bad (_("%s: unexpected function type: %d"),
30673 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
30674 }
30675 else switch (S_GET_STORAGE_CLASS (sym))
30676 {
30677 case C_EXT:
30678 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
30679 break;
30680 case C_STAT:
30681 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
30682 break;
30683 case C_LABEL:
30684 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
30685 break;
30686 default:
30687 /* Do nothing. */
30688 break;
30689 }
30690 }
30691
30692 if (ARM_IS_INTERWORK (sym))
30693 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
30694 }
30695 #endif
30696 #ifdef OBJ_ELF
30697 symbolS * sym;
30698 char bind;
30699
30700 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
30701 {
30702 if (ARM_IS_THUMB (sym))
30703 {
30704 elf_symbol_type * elf_sym;
30705
30706 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
30707 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
30708
30709 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
30710 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
30711 {
30712 /* If it's a .thumb_func, declare it as so,
30713 otherwise tag label as .code 16. */
30714 if (THUMB_IS_FUNC (sym))
30715 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
30716 ST_BRANCH_TO_THUMB);
30717 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
30718 elf_sym->internal_elf_sym.st_info =
30719 ELF_ST_INFO (bind, STT_ARM_16BIT);
30720 }
30721 }
30722 }
30723
30724 /* Remove any overlapping mapping symbols generated by alignment frags. */
30725 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
30726 /* Now do generic ELF adjustments. */
30727 elf_adjust_symtab ();
30728 #endif
30729 }
30730
30731 /* MD interface: Initialization. */
30732
30733 static void
30734 set_constant_flonums (void)
30735 {
30736 int i;
30737
30738 for (i = 0; i < NUM_FLOAT_VALS; i++)
30739 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
30740 abort ();
30741 }
30742
30743 /* Auto-select Thumb mode if it's the only available instruction set for the
30744 given architecture. */
30745
30746 static void
30747 autoselect_thumb_from_cpu_variant (void)
30748 {
30749 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
30750 opcode_select (16);
30751 }
30752
30753 void
30754 md_begin (void)
30755 {
30756 unsigned mach;
30757 unsigned int i;
30758
30759 arm_ops_hsh = str_htab_create ();
30760 arm_cond_hsh = str_htab_create ();
30761 arm_vcond_hsh = str_htab_create ();
30762 arm_shift_hsh = str_htab_create ();
30763 arm_psr_hsh = str_htab_create ();
30764 arm_v7m_psr_hsh = str_htab_create ();
30765 arm_reg_hsh = str_htab_create ();
30766 arm_reloc_hsh = str_htab_create ();
30767 arm_barrier_opt_hsh = str_htab_create ();
30768
30769 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
30770 if (str_hash_find (arm_ops_hsh, insns[i].template_name) == NULL)
30771 str_hash_insert (arm_ops_hsh, insns[i].template_name, insns + i, 0);
30772 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
30773 str_hash_insert (arm_cond_hsh, conds[i].template_name, conds + i, 0);
30774 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
30775 str_hash_insert (arm_vcond_hsh, vconds[i].template_name, vconds + i, 0);
30776 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
30777 str_hash_insert (arm_shift_hsh, shift_names[i].name, shift_names + i, 0);
30778 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
30779 str_hash_insert (arm_psr_hsh, psrs[i].template_name, psrs + i, 0);
30780 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
30781 str_hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
30782 v7m_psrs + i, 0);
30783 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
30784 str_hash_insert (arm_reg_hsh, reg_names[i].name, reg_names + i, 0);
30785 for (i = 0;
30786 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
30787 i++)
30788 str_hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
30789 barrier_opt_names + i, 0);
30790 #ifdef OBJ_ELF
30791 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
30792 {
30793 struct reloc_entry * entry = reloc_names + i;
30794
30795 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
30796 /* This makes encode_branch() use the EABI versions of this relocation. */
30797 entry->reloc = BFD_RELOC_UNUSED;
30798
30799 str_hash_insert (arm_reloc_hsh, entry->name, entry, 0);
30800 }
30801 #endif
30802
30803 set_constant_flonums ();
30804
30805 /* Set the cpu variant based on the command-line options. We prefer
30806 -mcpu= over -march= if both are set (as for GCC); and we prefer
30807 -mfpu= over any other way of setting the floating point unit.
30808 Use of legacy options with new options are faulted. */
30809 if (legacy_cpu)
30810 {
30811 if (mcpu_cpu_opt || march_cpu_opt)
30812 as_bad (_("use of old and new-style options to set CPU type"));
30813
30814 selected_arch = *legacy_cpu;
30815 }
30816 else if (mcpu_cpu_opt)
30817 {
30818 selected_arch = *mcpu_cpu_opt;
30819 selected_ext = *mcpu_ext_opt;
30820 }
30821 else if (march_cpu_opt)
30822 {
30823 selected_arch = *march_cpu_opt;
30824 selected_ext = *march_ext_opt;
30825 }
30826 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
30827
30828 if (legacy_fpu)
30829 {
30830 if (mfpu_opt)
30831 as_bad (_("use of old and new-style options to set FPU type"));
30832
30833 selected_fpu = *legacy_fpu;
30834 }
30835 else if (mfpu_opt)
30836 selected_fpu = *mfpu_opt;
30837 else
30838 {
30839 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
30840 || defined (TE_NetBSD) || defined (TE_VXWORKS))
30841 /* Some environments specify a default FPU. If they don't, infer it
30842 from the processor. */
30843 if (mcpu_fpu_opt)
30844 selected_fpu = *mcpu_fpu_opt;
30845 else if (march_fpu_opt)
30846 selected_fpu = *march_fpu_opt;
30847 #else
30848 selected_fpu = fpu_default;
30849 #endif
30850 }
30851
30852 if (ARM_FEATURE_ZERO (selected_fpu))
30853 {
30854 if (!no_cpu_selected ())
30855 selected_fpu = fpu_default;
30856 else
30857 selected_fpu = fpu_arch_fpa;
30858 }
30859
30860 #ifdef CPU_DEFAULT
30861 if (ARM_FEATURE_ZERO (selected_arch))
30862 {
30863 selected_arch = cpu_default;
30864 selected_cpu = selected_arch;
30865 }
30866 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30867 #else
30868 /* Autodection of feature mode: allow all features in cpu_variant but leave
30869 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
30870 after all instruction have been processed and we can decide what CPU
30871 should be selected. */
30872 if (ARM_FEATURE_ZERO (selected_arch))
30873 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
30874 else
30875 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
30876 #endif
30877
30878 autoselect_thumb_from_cpu_variant ();
30879
30880 arm_arch_used = thumb_arch_used = arm_arch_none;
30881
30882 #if defined OBJ_COFF || defined OBJ_ELF
30883 {
30884 unsigned int flags = 0;
30885
30886 #if defined OBJ_ELF
30887 flags = meabi_flags;
30888
30889 switch (meabi_flags)
30890 {
30891 case EF_ARM_EABI_UNKNOWN:
30892 #endif
30893 /* Set the flags in the private structure. */
30894 if (uses_apcs_26) flags |= F_APCS26;
30895 if (support_interwork) flags |= F_INTERWORK;
30896 if (uses_apcs_float) flags |= F_APCS_FLOAT;
30897 if (pic_code) flags |= F_PIC;
30898 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
30899 flags |= F_SOFT_FLOAT;
30900
30901 switch (mfloat_abi_opt)
30902 {
30903 case ARM_FLOAT_ABI_SOFT:
30904 case ARM_FLOAT_ABI_SOFTFP:
30905 flags |= F_SOFT_FLOAT;
30906 break;
30907
30908 case ARM_FLOAT_ABI_HARD:
30909 if (flags & F_SOFT_FLOAT)
30910 as_bad (_("hard-float conflicts with specified fpu"));
30911 break;
30912 }
30913
30914 /* Using pure-endian doubles (even if soft-float). */
30915 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
30916 flags |= F_VFP_FLOAT;
30917
30918 #if defined OBJ_ELF
30919 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
30920 flags |= EF_ARM_MAVERICK_FLOAT;
30921 break;
30922
30923 case EF_ARM_EABI_VER4:
30924 case EF_ARM_EABI_VER5:
30925 /* No additional flags to set. */
30926 break;
30927
30928 default:
30929 abort ();
30930 }
30931 #endif
30932 bfd_set_private_flags (stdoutput, flags);
30933
30934 /* We have run out flags in the COFF header to encode the
30935 status of ATPCS support, so instead we create a dummy,
30936 empty, debug section called .arm.atpcs. */
30937 if (atpcs)
30938 {
30939 asection * sec;
30940
30941 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30942
30943 if (sec != NULL)
30944 {
30945 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30946 bfd_set_section_size (sec, 0);
30947 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30948 }
30949 }
30950 }
30951 #endif
30952
30953 /* Record the CPU type as well. */
30954 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30955 mach = bfd_mach_arm_iWMMXt2;
30956 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
30957 mach = bfd_mach_arm_iWMMXt;
30958 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
30959 mach = bfd_mach_arm_XScale;
30960 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
30961 mach = bfd_mach_arm_ep9312;
30962 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
30963 mach = bfd_mach_arm_5TE;
30964 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
30965 {
30966 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30967 mach = bfd_mach_arm_5T;
30968 else
30969 mach = bfd_mach_arm_5;
30970 }
30971 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
30972 {
30973 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30974 mach = bfd_mach_arm_4T;
30975 else
30976 mach = bfd_mach_arm_4;
30977 }
30978 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
30979 mach = bfd_mach_arm_3M;
30980 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30981 mach = bfd_mach_arm_3;
30982 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30983 mach = bfd_mach_arm_2a;
30984 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30985 mach = bfd_mach_arm_2;
30986 else
30987 mach = bfd_mach_arm_unknown;
30988
30989 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30990 }
30991
30992 /* Command line processing. */
30993
30994 /* md_parse_option
30995 Invocation line includes a switch not recognized by the base assembler.
30996 See if it's a processor-specific option.
30997
30998 This routine is somewhat complicated by the need for backwards
30999 compatibility (since older releases of gcc can't be changed).
31000 The new options try to make the interface as compatible as
31001 possible with GCC.
31002
31003 New options (supported) are:
31004
31005 -mcpu=<cpu name> Assemble for selected processor
31006 -march=<architecture name> Assemble for selected architecture
31007 -mfpu=<fpu architecture> Assemble for selected FPU.
31008 -EB/-mbig-endian Big-endian
31009 -EL/-mlittle-endian Little-endian
31010 -k Generate PIC code
31011 -mthumb Start in Thumb mode
31012 -mthumb-interwork Code supports ARM/Thumb interworking
31013
31014 -m[no-]warn-deprecated Warn about deprecated features
31015 -m[no-]warn-syms Warn when symbols match instructions
31016
31017 For now we will also provide support for:
31018
31019 -mapcs-32 32-bit Program counter
31020 -mapcs-26 26-bit Program counter
31021 -macps-float Floats passed in FP registers
31022 -mapcs-reentrant Reentrant code
31023 -matpcs
31024 (sometime these will probably be replaced with -mapcs=<list of options>
31025 and -matpcs=<list of options>)
31026
31027 The remaining options are only supported for back-wards compatibility.
31028 Cpu variants, the arm part is optional:
31029 -m[arm]1 Currently not supported.
31030 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
31031 -m[arm]3 Arm 3 processor
31032 -m[arm]6[xx], Arm 6 processors
31033 -m[arm]7[xx][t][[d]m] Arm 7 processors
31034 -m[arm]8[10] Arm 8 processors
31035 -m[arm]9[20][tdmi] Arm 9 processors
31036 -mstrongarm[110[0]] StrongARM processors
31037 -mxscale XScale processors
31038 -m[arm]v[2345[t[e]]] Arm architectures
31039 -mall All (except the ARM1)
31040 FP variants:
31041 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
31042 -mfpe-old (No float load/store multiples)
31043 -mvfpxd VFP Single precision
31044 -mvfp All VFP
31045 -mno-fpu Disable all floating point instructions
31046
31047 The following CPU names are recognized:
31048 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
31049 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
31050 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
31051 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
31052 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
31053 arm10t arm10e, arm1020t, arm1020e, arm10200e,
31054 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
31055
31056 */
31057
31058 const char * md_shortopts = "m:k";
31059
31060 #ifdef ARM_BI_ENDIAN
31061 #define OPTION_EB (OPTION_MD_BASE + 0)
31062 #define OPTION_EL (OPTION_MD_BASE + 1)
31063 #else
31064 #if TARGET_BYTES_BIG_ENDIAN
31065 #define OPTION_EB (OPTION_MD_BASE + 0)
31066 #else
31067 #define OPTION_EL (OPTION_MD_BASE + 1)
31068 #endif
31069 #endif
31070 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
31071 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
31072
31073 struct option md_longopts[] =
31074 {
31075 #ifdef OPTION_EB
31076 {"EB", no_argument, NULL, OPTION_EB},
31077 #endif
31078 #ifdef OPTION_EL
31079 {"EL", no_argument, NULL, OPTION_EL},
31080 #endif
31081 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
31082 #ifdef OBJ_ELF
31083 {"fdpic", no_argument, NULL, OPTION_FDPIC},
31084 #endif
31085 {NULL, no_argument, NULL, 0}
31086 };
31087
31088 size_t md_longopts_size = sizeof (md_longopts);
31089
31090 struct arm_option_table
31091 {
31092 const char * option; /* Option name to match. */
31093 const char * help; /* Help information. */
31094 int * var; /* Variable to change. */
31095 int value; /* What to change it to. */
31096 const char * deprecated; /* If non-null, print this message. */
31097 };
31098
31099 struct arm_option_table arm_opts[] =
31100 {
31101 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
31102 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
31103 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
31104 &support_interwork, 1, NULL},
31105 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
31106 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
31107 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
31108 1, NULL},
31109 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
31110 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
31111 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
31112 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
31113 NULL},
31114
31115 /* These are recognized by the assembler, but have no affect on code. */
31116 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
31117 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
31118
31119 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
31120 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
31121 &warn_on_deprecated, 0, NULL},
31122
31123 {"mwarn-restrict-it", N_("warn about performance deprecated IT instructions"
31124 " in ARMv8-A and ARMv8-R"), &warn_on_restrict_it, 1, NULL},
31125 {"mno-warn-restrict-it", NULL, &warn_on_restrict_it, 0, NULL},
31126
31127 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), true, NULL},
31128 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), false, NULL},
31129 {NULL, NULL, NULL, 0, NULL}
31130 };
31131
31132 struct arm_legacy_option_table
31133 {
31134 const char * option; /* Option name to match. */
31135 const arm_feature_set ** var; /* Variable to change. */
31136 const arm_feature_set value; /* What to change it to. */
31137 const char * deprecated; /* If non-null, print this message. */
31138 };
31139
31140 const struct arm_legacy_option_table arm_legacy_opts[] =
31141 {
31142 /* DON'T add any new processors to this list -- we want the whole list
31143 to go away... Add them to the processors table instead. */
31144 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31145 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
31146 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31147 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
31148 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31149 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
31150 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31151 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
31152 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31153 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
31154 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31155 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
31156 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31157 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
31158 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31159 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
31160 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31161 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
31162 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31163 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
31164 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31165 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
31166 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31167 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
31168 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31169 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
31170 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31171 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
31172 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31173 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
31174 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31175 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
31176 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31177 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
31178 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31179 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
31180 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31181 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
31182 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31183 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
31184 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31185 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
31186 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31187 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
31188 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31189 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
31190 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31191 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31192 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31193 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
31194 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31195 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
31196 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31197 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
31198 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31199 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
31200 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31201 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
31202 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31203 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
31204 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31205 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
31206 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31207 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
31208 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31209 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
31210 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31211 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
31212 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
31213 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
31214 N_("use -mcpu=strongarm110")},
31215 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
31216 N_("use -mcpu=strongarm1100")},
31217 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
31218 N_("use -mcpu=strongarm1110")},
31219 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
31220 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
31221 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
31222
31223 /* Architecture variants -- don't add any more to this list either. */
31224 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31225 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
31226 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31227 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
31228 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31229 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
31230 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31231 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
31232 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31233 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
31234 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31235 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
31236 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31237 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
31238 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31239 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
31240 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31241 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
31242
31243 /* Floating point variants -- don't add any more to this list either. */
31244 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
31245 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
31246 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
31247 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
31248 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
31249
31250 {NULL, NULL, ARM_ARCH_NONE, NULL}
31251 };
31252
31253 struct arm_cpu_option_table
31254 {
31255 const char * name;
31256 size_t name_len;
31257 const arm_feature_set value;
31258 const arm_feature_set ext;
31259 /* For some CPUs we assume an FPU unless the user explicitly sets
31260 -mfpu=... */
31261 const arm_feature_set default_fpu;
31262 /* The canonical name of the CPU, or NULL to use NAME converted to upper
31263 case. */
31264 const char * canonical_name;
31265 };
31266
31267 /* This list should, at a minimum, contain all the cpu names
31268 recognized by GCC. */
31269 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
31270
31271 static const struct arm_cpu_option_table arm_cpus[] =
31272 {
31273 ARM_CPU_OPT ("all", NULL, ARM_ANY,
31274 ARM_ARCH_NONE,
31275 FPU_ARCH_FPA),
31276 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
31277 ARM_ARCH_NONE,
31278 FPU_ARCH_FPA),
31279 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
31280 ARM_ARCH_NONE,
31281 FPU_ARCH_FPA),
31282 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
31283 ARM_ARCH_NONE,
31284 FPU_ARCH_FPA),
31285 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
31286 ARM_ARCH_NONE,
31287 FPU_ARCH_FPA),
31288 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
31289 ARM_ARCH_NONE,
31290 FPU_ARCH_FPA),
31291 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
31292 ARM_ARCH_NONE,
31293 FPU_ARCH_FPA),
31294 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
31295 ARM_ARCH_NONE,
31296 FPU_ARCH_FPA),
31297 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
31298 ARM_ARCH_NONE,
31299 FPU_ARCH_FPA),
31300 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
31301 ARM_ARCH_NONE,
31302 FPU_ARCH_FPA),
31303 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
31304 ARM_ARCH_NONE,
31305 FPU_ARCH_FPA),
31306 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
31307 ARM_ARCH_NONE,
31308 FPU_ARCH_FPA),
31309 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
31310 ARM_ARCH_NONE,
31311 FPU_ARCH_FPA),
31312 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
31313 ARM_ARCH_NONE,
31314 FPU_ARCH_FPA),
31315 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
31316 ARM_ARCH_NONE,
31317 FPU_ARCH_FPA),
31318 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
31319 ARM_ARCH_NONE,
31320 FPU_ARCH_FPA),
31321 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
31322 ARM_ARCH_NONE,
31323 FPU_ARCH_FPA),
31324 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
31325 ARM_ARCH_NONE,
31326 FPU_ARCH_FPA),
31327 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
31328 ARM_ARCH_NONE,
31329 FPU_ARCH_FPA),
31330 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
31331 ARM_ARCH_NONE,
31332 FPU_ARCH_FPA),
31333 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
31334 ARM_ARCH_NONE,
31335 FPU_ARCH_FPA),
31336 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
31337 ARM_ARCH_NONE,
31338 FPU_ARCH_FPA),
31339 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
31340 ARM_ARCH_NONE,
31341 FPU_ARCH_FPA),
31342 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
31343 ARM_ARCH_NONE,
31344 FPU_ARCH_FPA),
31345 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
31346 ARM_ARCH_NONE,
31347 FPU_ARCH_FPA),
31348 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
31349 ARM_ARCH_NONE,
31350 FPU_ARCH_FPA),
31351 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
31352 ARM_ARCH_NONE,
31353 FPU_ARCH_FPA),
31354 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
31355 ARM_ARCH_NONE,
31356 FPU_ARCH_FPA),
31357 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
31358 ARM_ARCH_NONE,
31359 FPU_ARCH_FPA),
31360 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
31361 ARM_ARCH_NONE,
31362 FPU_ARCH_FPA),
31363 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
31364 ARM_ARCH_NONE,
31365 FPU_ARCH_FPA),
31366 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
31367 ARM_ARCH_NONE,
31368 FPU_ARCH_FPA),
31369 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
31370 ARM_ARCH_NONE,
31371 FPU_ARCH_FPA),
31372 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
31373 ARM_ARCH_NONE,
31374 FPU_ARCH_FPA),
31375 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
31376 ARM_ARCH_NONE,
31377 FPU_ARCH_FPA),
31378 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
31379 ARM_ARCH_NONE,
31380 FPU_ARCH_FPA),
31381 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
31382 ARM_ARCH_NONE,
31383 FPU_ARCH_FPA),
31384 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
31385 ARM_ARCH_NONE,
31386 FPU_ARCH_FPA),
31387 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
31388 ARM_ARCH_NONE,
31389 FPU_ARCH_FPA),
31390 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
31391 ARM_ARCH_NONE,
31392 FPU_ARCH_FPA),
31393 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
31394 ARM_ARCH_NONE,
31395 FPU_ARCH_FPA),
31396 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
31397 ARM_ARCH_NONE,
31398 FPU_ARCH_FPA),
31399 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
31400 ARM_ARCH_NONE,
31401 FPU_ARCH_FPA),
31402 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
31403 ARM_ARCH_NONE,
31404 FPU_ARCH_FPA),
31405 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
31406 ARM_ARCH_NONE,
31407 FPU_ARCH_FPA),
31408 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
31409 ARM_ARCH_NONE,
31410 FPU_ARCH_FPA),
31411
31412 /* For V5 or later processors we default to using VFP; but the user
31413 should really set the FPU type explicitly. */
31414 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
31415 ARM_ARCH_NONE,
31416 FPU_ARCH_VFP_V2),
31417 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
31418 ARM_ARCH_NONE,
31419 FPU_ARCH_VFP_V2),
31420 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31421 ARM_ARCH_NONE,
31422 FPU_ARCH_VFP_V2),
31423 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
31424 ARM_ARCH_NONE,
31425 FPU_ARCH_VFP_V2),
31426 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
31427 ARM_ARCH_NONE,
31428 FPU_ARCH_VFP_V2),
31429 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
31430 ARM_ARCH_NONE,
31431 FPU_ARCH_VFP_V2),
31432 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
31433 ARM_ARCH_NONE,
31434 FPU_ARCH_VFP_V2),
31435 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
31436 ARM_ARCH_NONE,
31437 FPU_ARCH_VFP_V2),
31438 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
31439 ARM_ARCH_NONE,
31440 FPU_ARCH_VFP_V2),
31441 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
31442 ARM_ARCH_NONE,
31443 FPU_ARCH_VFP_V2),
31444 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
31445 ARM_ARCH_NONE,
31446 FPU_ARCH_VFP_V2),
31447 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
31448 ARM_ARCH_NONE,
31449 FPU_ARCH_VFP_V2),
31450 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
31451 ARM_ARCH_NONE,
31452 FPU_ARCH_VFP_V1),
31453 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
31454 ARM_ARCH_NONE,
31455 FPU_ARCH_VFP_V1),
31456 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
31457 ARM_ARCH_NONE,
31458 FPU_ARCH_VFP_V2),
31459 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
31460 ARM_ARCH_NONE,
31461 FPU_ARCH_VFP_V2),
31462 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
31463 ARM_ARCH_NONE,
31464 FPU_ARCH_VFP_V1),
31465 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
31466 ARM_ARCH_NONE,
31467 FPU_ARCH_VFP_V2),
31468 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
31469 ARM_ARCH_NONE,
31470 FPU_ARCH_VFP_V2),
31471 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
31472 ARM_ARCH_NONE,
31473 FPU_ARCH_VFP_V2),
31474 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
31475 ARM_ARCH_NONE,
31476 FPU_ARCH_VFP_V2),
31477 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
31478 ARM_ARCH_NONE,
31479 FPU_ARCH_VFP_V2),
31480 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
31481 ARM_ARCH_NONE,
31482 FPU_ARCH_VFP_V2),
31483 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
31484 ARM_ARCH_NONE,
31485 FPU_ARCH_VFP_V2),
31486 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
31487 ARM_ARCH_NONE,
31488 FPU_ARCH_VFP_V2),
31489 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
31490 ARM_ARCH_NONE,
31491 FPU_ARCH_VFP_V2),
31492 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
31493 ARM_ARCH_NONE,
31494 FPU_NONE),
31495 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
31496 ARM_ARCH_NONE,
31497 FPU_NONE),
31498 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
31499 ARM_ARCH_NONE,
31500 FPU_ARCH_VFP_V2),
31501 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
31502 ARM_ARCH_NONE,
31503 FPU_ARCH_VFP_V2),
31504 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
31505 ARM_ARCH_NONE,
31506 FPU_ARCH_VFP_V2),
31507 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
31508 ARM_ARCH_NONE,
31509 FPU_NONE),
31510 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
31511 ARM_ARCH_NONE,
31512 FPU_NONE),
31513 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
31514 ARM_ARCH_NONE,
31515 FPU_ARCH_VFP_V2),
31516 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
31517 ARM_ARCH_NONE,
31518 FPU_NONE),
31519 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
31520 ARM_ARCH_NONE,
31521 FPU_ARCH_VFP_V2),
31522 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
31523 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31524 FPU_NONE),
31525 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
31526 ARM_ARCH_NONE,
31527 FPU_ARCH_NEON_VFP_V4),
31528 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
31529 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31530 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31531 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
31532 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31533 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
31534 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
31535 ARM_ARCH_NONE,
31536 FPU_ARCH_NEON_VFP_V4),
31537 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
31538 ARM_ARCH_NONE,
31539 FPU_ARCH_NEON_VFP_V4),
31540 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
31541 ARM_ARCH_NONE,
31542 FPU_ARCH_NEON_VFP_V4),
31543 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
31544 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31545 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31546 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
31547 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31548 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31549 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
31550 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31551 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31552 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
31553 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31554 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31555 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
31556 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31557 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31558 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
31559 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31560 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31561 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
31562 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31563 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31564 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
31565 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31566 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31567 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
31568 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31569 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31570 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
31571 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31572 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31573 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
31574 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31575 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31576 ARM_CPU_OPT ("cortex-a78", "Cortex-A78", ARM_ARCH_V8_2A,
31577 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31578 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31579 ARM_CPU_OPT ("cortex-a78ae", "Cortex-A78AE", ARM_ARCH_V8_2A,
31580 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31581 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31582 ARM_CPU_OPT ("cortex-a78c", "Cortex-A78C", ARM_ARCH_V8_2A,
31583 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31584 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31585 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
31586 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31587 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31588 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
31589 ARM_ARCH_NONE,
31590 FPU_NONE),
31591 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
31592 ARM_ARCH_NONE,
31593 FPU_ARCH_VFP_V3D16),
31594 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
31595 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31596 FPU_NONE),
31597 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
31598 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31599 FPU_ARCH_VFP_V3D16),
31600 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
31601 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
31602 FPU_ARCH_VFP_V3D16),
31603 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
31604 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31605 FPU_ARCH_NEON_VFP_ARMV8),
31606 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
31607 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31608 FPU_NONE),
31609 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
31610 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31611 FPU_NONE),
31612 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
31613 ARM_ARCH_NONE,
31614 FPU_NONE),
31615 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
31616 ARM_ARCH_NONE,
31617 FPU_NONE),
31618 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
31619 ARM_ARCH_NONE,
31620 FPU_NONE),
31621 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
31622 ARM_ARCH_NONE,
31623 FPU_NONE),
31624 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
31625 ARM_ARCH_NONE,
31626 FPU_NONE),
31627 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
31628 ARM_ARCH_NONE,
31629 FPU_NONE),
31630 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
31631 ARM_ARCH_NONE,
31632 FPU_NONE),
31633 ARM_CPU_OPT ("cortex-x1", "Cortex-X1", ARM_ARCH_V8_2A,
31634 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB),
31635 FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31636 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
31637 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31638 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31639 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
31640 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31641 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
31642 ARM_CPU_OPT ("neoverse-n2", "Neoverse N2", ARM_ARCH_V8_5A,
31643 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31644 | ARM_EXT2_BF16
31645 | ARM_EXT2_I8MM),
31646 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
31647 ARM_CPU_OPT ("neoverse-v1", "Neoverse V1", ARM_ARCH_V8_4A,
31648 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31649 | ARM_EXT2_BF16
31650 | ARM_EXT2_I8MM),
31651 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4),
31652 /* ??? XSCALE is really an architecture. */
31653 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
31654 ARM_ARCH_NONE,
31655 FPU_ARCH_VFP_V2),
31656
31657 /* ??? iwmmxt is not a processor. */
31658 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
31659 ARM_ARCH_NONE,
31660 FPU_ARCH_VFP_V2),
31661 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
31662 ARM_ARCH_NONE,
31663 FPU_ARCH_VFP_V2),
31664 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
31665 ARM_ARCH_NONE,
31666 FPU_ARCH_VFP_V2),
31667
31668 /* Maverick. */
31669 ARM_CPU_OPT ("ep9312", "ARM920T",
31670 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
31671 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
31672
31673 /* Marvell processors. */
31674 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
31675 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31676 FPU_ARCH_VFP_V3D16),
31677 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
31678 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
31679 FPU_ARCH_NEON_VFP_V4),
31680
31681 /* APM X-Gene family. */
31682 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
31683 ARM_ARCH_NONE,
31684 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31685 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
31686 ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC),
31687 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
31688
31689 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31690 };
31691 #undef ARM_CPU_OPT
31692
31693 struct arm_ext_table
31694 {
31695 const char * name;
31696 size_t name_len;
31697 const arm_feature_set merge;
31698 const arm_feature_set clear;
31699 };
31700
31701 struct arm_arch_option_table
31702 {
31703 const char * name;
31704 size_t name_len;
31705 const arm_feature_set value;
31706 const arm_feature_set default_fpu;
31707 const struct arm_ext_table * ext_table;
31708 };
31709
31710 /* Used to add support for +E and +noE extension. */
31711 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
31712 /* Used to add support for a +E extension. */
31713 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
31714 /* Used to add support for a +noE extension. */
31715 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
31716
31717 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
31718 ~0 & ~FPU_ENDIAN_PURE)
31719
31720 static const struct arm_ext_table armv5te_ext_table[] =
31721 {
31722 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
31723 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31724 };
31725
31726 static const struct arm_ext_table armv7_ext_table[] =
31727 {
31728 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31729 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31730 };
31731
31732 static const struct arm_ext_table armv7ve_ext_table[] =
31733 {
31734 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
31735 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
31736 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31737 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31738 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31739 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
31740 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31741
31742 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
31743 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31744
31745 /* Aliases for +simd. */
31746 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31747
31748 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31749 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31750 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31751
31752 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31753 };
31754
31755 static const struct arm_ext_table armv7a_ext_table[] =
31756 {
31757 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31758 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31759 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
31760 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31761 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
31762 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
31763 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
31764
31765 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
31766 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
31767
31768 /* Aliases for +simd. */
31769 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31770 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
31771
31772 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
31773 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
31774
31775 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
31776 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
31777 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31778 };
31779
31780 static const struct arm_ext_table armv7r_ext_table[] =
31781 {
31782 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
31783 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
31784 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
31785 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
31786 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
31787 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
31788 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31789 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
31790 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31791 };
31792
31793 static const struct arm_ext_table armv7em_ext_table[] =
31794 {
31795 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
31796 /* Alias for +fp, used to be known as fpv4-sp-d16. */
31797 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
31798 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
31799 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31800 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
31801 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31802 };
31803
31804 static const struct arm_ext_table armv8a_ext_table[] =
31805 {
31806 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31807 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31808 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31809 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31810
31811 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31812 should use the +simd option to turn on FP. */
31813 ARM_REMOVE ("fp", ALL_FP),
31814 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31815 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31816 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31817 };
31818
31819
31820 static const struct arm_ext_table armv81a_ext_table[] =
31821 {
31822 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31823 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31824 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31825
31826 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31827 should use the +simd option to turn on FP. */
31828 ARM_REMOVE ("fp", ALL_FP),
31829 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31830 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31831 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31832 };
31833
31834 static const struct arm_ext_table armv82a_ext_table[] =
31835 {
31836 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
31837 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
31838 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
31839 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31840 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31841 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
31842 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31843 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31844
31845 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31846 should use the +simd option to turn on FP. */
31847 ARM_REMOVE ("fp", ALL_FP),
31848 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31849 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31850 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31851 };
31852
31853 static const struct arm_ext_table armv84a_ext_table[] =
31854 {
31855 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31856 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31857 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31858 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31859 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31860 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31861
31862 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31863 should use the +simd option to turn on FP. */
31864 ARM_REMOVE ("fp", ALL_FP),
31865 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
31866 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
31867 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31868 };
31869
31870 static const struct arm_ext_table armv85a_ext_table[] =
31871 {
31872 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
31873 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
31874 ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)),
31875 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31876 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
31877 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31878
31879 /* Armv8-a does not allow an FP implementation without SIMD, so the user
31880 should use the +simd option to turn on FP. */
31881 ARM_REMOVE ("fp", ALL_FP),
31882 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31883 };
31884
31885 static const struct arm_ext_table armv86a_ext_table[] =
31886 {
31887 ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)),
31888 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31889 };
31890
31891 #define CDE_EXTENSIONS \
31892 ARM_ADD ("cdecp0", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE0)), \
31893 ARM_ADD ("cdecp1", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE1)), \
31894 ARM_ADD ("cdecp2", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE2)), \
31895 ARM_ADD ("cdecp3", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE3)), \
31896 ARM_ADD ("cdecp4", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE4)), \
31897 ARM_ADD ("cdecp5", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE5)), \
31898 ARM_ADD ("cdecp6", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE6)), \
31899 ARM_ADD ("cdecp7", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CDE | ARM_EXT2_CDE7))
31900
31901 static const struct arm_ext_table armv8m_main_ext_table[] =
31902 {
31903 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31904 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31905 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
31906 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
31907 CDE_EXTENSIONS,
31908 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31909 };
31910
31911
31912 static const struct arm_ext_table armv8_1m_main_ext_table[] =
31913 {
31914 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP),
31915 ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)),
31916 ARM_EXT ("fp",
31917 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31918 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
31919 ALL_FP),
31920 ARM_ADD ("fp.dp",
31921 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
31922 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31923 ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0),
31924 ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)),
31925 ARM_ADD ("mve.fp",
31926 ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP,
31927 ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP,
31928 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
31929 CDE_EXTENSIONS,
31930 ARM_ADD ("pacbti", ARM_FEATURE_CORE_HIGH_HIGH (ARM_AEXT3_V8_1M_MAIN_PACBTI)),
31931 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31932 };
31933
31934 #undef CDE_EXTENSIONS
31935
31936 static const struct arm_ext_table armv8r_ext_table[] =
31937 {
31938 ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)),
31939 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
31940 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31941 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
31942 ARM_REMOVE ("fp", ALL_FP),
31943 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
31944 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
31945 };
31946
31947 /* This list should, at a minimum, contain all the architecture names
31948 recognized by GCC. */
31949 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
31950 #define ARM_ARCH_OPT2(N, V, DF, ext) \
31951 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
31952
31953 static const struct arm_arch_option_table arm_archs[] =
31954 {
31955 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
31956 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
31957 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
31958 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
31959 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
31960 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
31961 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
31962 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
31963 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
31964 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
31965 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
31966 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
31967 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
31968 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
31969 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
31970 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
31971 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
31972 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31973 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
31974 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
31975 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
31976 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
31977 kept to preserve existing behaviour. */
31978 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31979 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31980 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31981 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31982 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
31983 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31984 kept to preserve existing behaviour. */
31985 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31986 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31987 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31988 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
31989 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
31990 /* The official spelling of the ARMv7 profile variants is the dashed form.
31991 Accept the non-dashed form for compatibility with old toolchains. */
31992 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31993 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31994 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31995 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31996 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31997 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31998 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31999 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
32000 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
32001 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
32002 armv8m_main),
32003 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
32004 armv8_1m_main),
32005 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
32006 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
32007 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
32008 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
32009 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
32010 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
32011 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
32012 ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a),
32013 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
32014 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
32015 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
32016 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
32017 };
32018 #undef ARM_ARCH_OPT
32019
32020 /* ISA extensions in the co-processor and main instruction set space. */
32021
32022 struct arm_option_extension_value_table
32023 {
32024 const char * name;
32025 size_t name_len;
32026 const arm_feature_set merge_value;
32027 const arm_feature_set clear_value;
32028 /* List of architectures for which an extension is available. ARM_ARCH_NONE
32029 indicates that an extension is available for all architectures while
32030 ARM_ANY marks an empty entry. */
32031 const arm_feature_set allowed_archs[2];
32032 };
32033
32034 /* The following table must be in alphabetical order with a NULL last entry. */
32035
32036 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
32037 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
32038
32039 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
32040 use the context sensitive approach using arm_ext_table's. */
32041 static const struct arm_option_extension_value_table arm_extensions[] =
32042 {
32043 ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
32044 ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC),
32045 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
32046 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
32047 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
32048 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
32049 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
32050 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
32051 ARM_ARCH_V8_2A),
32052 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
32053 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
32054 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
32055 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
32056 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
32057 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
32058 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
32059 ARM_ARCH_V8_2A),
32060 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32061 | ARM_EXT2_FP16_FML),
32062 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
32063 | ARM_EXT2_FP16_FML),
32064 ARM_ARCH_V8_2A),
32065 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
32066 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
32067 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32068 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
32069 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
32070 Thumb divide instruction. Due to this having the same name as the
32071 previous entry, this will be ignored when doing command-line parsing and
32072 only considered by build attribute selection code. */
32073 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32074 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
32075 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
32076 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
32077 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
32078 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
32079 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
32080 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
32081 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
32082 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
32083 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
32084 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
32085 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
32086 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32087 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
32088 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
32089 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
32090 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
32091 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32092 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32093 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
32094 ARM_ARCH_V8A),
32095 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
32096 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
32097 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32098 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
32099 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
32100 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
32101 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32102 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
32103 ARM_ARCH_V8A),
32104 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
32105 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
32106 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
32107 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32108 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
32109 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
32110 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
32111 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
32112 | ARM_EXT_DIV),
32113 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
32114 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
32115 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
32116 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
32117 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
32118 };
32119 #undef ARM_EXT_OPT
32120
32121 /* ISA floating-point and Advanced SIMD extensions. */
32122 struct arm_option_fpu_value_table
32123 {
32124 const char * name;
32125 const arm_feature_set value;
32126 };
32127
32128 /* This list should, at a minimum, contain all the fpu names
32129 recognized by GCC. */
32130 static const struct arm_option_fpu_value_table arm_fpus[] =
32131 {
32132 {"softfpa", FPU_NONE},
32133 {"fpe", FPU_ARCH_FPE},
32134 {"fpe2", FPU_ARCH_FPE},
32135 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
32136 {"fpa", FPU_ARCH_FPA},
32137 {"fpa10", FPU_ARCH_FPA},
32138 {"fpa11", FPU_ARCH_FPA},
32139 {"arm7500fe", FPU_ARCH_FPA},
32140 {"softvfp", FPU_ARCH_VFP},
32141 {"softvfp+vfp", FPU_ARCH_VFP_V2},
32142 {"vfp", FPU_ARCH_VFP_V2},
32143 {"vfp9", FPU_ARCH_VFP_V2},
32144 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
32145 {"vfp10", FPU_ARCH_VFP_V2},
32146 {"vfp10-r0", FPU_ARCH_VFP_V1},
32147 {"vfpxd", FPU_ARCH_VFP_V1xD},
32148 {"vfpv2", FPU_ARCH_VFP_V2},
32149 {"vfpv3", FPU_ARCH_VFP_V3},
32150 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
32151 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
32152 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
32153 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
32154 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
32155 {"arm1020t", FPU_ARCH_VFP_V1},
32156 {"arm1020e", FPU_ARCH_VFP_V2},
32157 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
32158 {"arm1136jf-s", FPU_ARCH_VFP_V2},
32159 {"maverick", FPU_ARCH_MAVERICK},
32160 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
32161 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
32162 {"neon-fp16", FPU_ARCH_NEON_FP16},
32163 {"vfpv4", FPU_ARCH_VFP_V4},
32164 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
32165 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
32166 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
32167 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
32168 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
32169 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
32170 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
32171 {"crypto-neon-fp-armv8",
32172 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
32173 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
32174 {"crypto-neon-fp-armv8.1",
32175 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
32176 {NULL, ARM_ARCH_NONE}
32177 };
32178
32179 struct arm_option_value_table
32180 {
32181 const char *name;
32182 long value;
32183 };
32184
32185 static const struct arm_option_value_table arm_float_abis[] =
32186 {
32187 {"hard", ARM_FLOAT_ABI_HARD},
32188 {"softfp", ARM_FLOAT_ABI_SOFTFP},
32189 {"soft", ARM_FLOAT_ABI_SOFT},
32190 {NULL, 0}
32191 };
32192
32193 #ifdef OBJ_ELF
32194 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
32195 static const struct arm_option_value_table arm_eabis[] =
32196 {
32197 {"gnu", EF_ARM_EABI_UNKNOWN},
32198 {"4", EF_ARM_EABI_VER4},
32199 {"5", EF_ARM_EABI_VER5},
32200 {NULL, 0}
32201 };
32202 #endif
32203
32204 struct arm_long_option_table
32205 {
32206 const char *option; /* Substring to match. */
32207 const char *help; /* Help information. */
32208 bool (*func) (const char *subopt); /* Function to decode sub-option. */
32209 const char *deprecated; /* If non-null, print this message. */
32210 };
32211
32212 static bool
32213 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
32214 arm_feature_set *ext_set,
32215 const struct arm_ext_table *ext_table)
32216 {
32217 /* We insist on extensions being specified in alphabetical order, and with
32218 extensions being added before being removed. We achieve this by having
32219 the global ARM_EXTENSIONS table in alphabetical order, and using the
32220 ADDING_VALUE variable to indicate whether we are adding an extension (1)
32221 or removing it (0) and only allowing it to change in the order
32222 -1 -> 1 -> 0. */
32223 const struct arm_option_extension_value_table * opt = NULL;
32224 const arm_feature_set arm_any = ARM_ANY;
32225 int adding_value = -1;
32226
32227 while (str != NULL && *str != 0)
32228 {
32229 const char *ext;
32230 size_t len;
32231
32232 if (*str != '+')
32233 {
32234 as_bad (_("invalid architectural extension"));
32235 return false;
32236 }
32237
32238 str++;
32239 ext = strchr (str, '+');
32240
32241 if (ext != NULL)
32242 len = ext - str;
32243 else
32244 len = strlen (str);
32245
32246 if (len >= 2 && startswith (str, "no"))
32247 {
32248 if (adding_value != 0)
32249 {
32250 adding_value = 0;
32251 opt = arm_extensions;
32252 }
32253
32254 len -= 2;
32255 str += 2;
32256 }
32257 else if (len > 0)
32258 {
32259 if (adding_value == -1)
32260 {
32261 adding_value = 1;
32262 opt = arm_extensions;
32263 }
32264 else if (adding_value != 1)
32265 {
32266 as_bad (_("must specify extensions to add before specifying "
32267 "those to remove"));
32268 return false;
32269 }
32270 }
32271
32272 if (len == 0)
32273 {
32274 as_bad (_("missing architectural extension"));
32275 return false;
32276 }
32277
32278 gas_assert (adding_value != -1);
32279 gas_assert (opt != NULL);
32280
32281 if (ext_table != NULL)
32282 {
32283 const struct arm_ext_table * ext_opt = ext_table;
32284 bool found = false;
32285 for (; ext_opt->name != NULL; ext_opt++)
32286 if (ext_opt->name_len == len
32287 && strncmp (ext_opt->name, str, len) == 0)
32288 {
32289 if (adding_value)
32290 {
32291 if (ARM_FEATURE_ZERO (ext_opt->merge))
32292 /* TODO: Option not supported. When we remove the
32293 legacy table this case should error out. */
32294 continue;
32295
32296 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
32297 }
32298 else
32299 {
32300 if (ARM_FEATURE_ZERO (ext_opt->clear))
32301 /* TODO: Option not supported. When we remove the
32302 legacy table this case should error out. */
32303 continue;
32304 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
32305 }
32306 found = true;
32307 break;
32308 }
32309 if (found)
32310 {
32311 str = ext;
32312 continue;
32313 }
32314 }
32315
32316 /* Scan over the options table trying to find an exact match. */
32317 for (; opt->name != NULL; opt++)
32318 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32319 {
32320 int i, nb_allowed_archs =
32321 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32322 /* Check we can apply the extension to this architecture. */
32323 for (i = 0; i < nb_allowed_archs; i++)
32324 {
32325 /* Empty entry. */
32326 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
32327 continue;
32328 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
32329 break;
32330 }
32331 if (i == nb_allowed_archs)
32332 {
32333 as_bad (_("extension does not apply to the base architecture"));
32334 return false;
32335 }
32336
32337 /* Add or remove the extension. */
32338 if (adding_value)
32339 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
32340 else
32341 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
32342
32343 /* Allowing Thumb division instructions for ARMv7 in autodetection
32344 rely on this break so that duplicate extensions (extensions
32345 with the same name as a previous extension in the list) are not
32346 considered for command-line parsing. */
32347 break;
32348 }
32349
32350 if (opt->name == NULL)
32351 {
32352 /* Did we fail to find an extension because it wasn't specified in
32353 alphabetical order, or because it does not exist? */
32354
32355 for (opt = arm_extensions; opt->name != NULL; opt++)
32356 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32357 break;
32358
32359 if (opt->name == NULL)
32360 as_bad (_("unknown architectural extension `%s'"), str);
32361 else
32362 as_bad (_("architectural extensions must be specified in "
32363 "alphabetical order"));
32364
32365 return false;
32366 }
32367 else
32368 {
32369 /* We should skip the extension we've just matched the next time
32370 round. */
32371 opt++;
32372 }
32373
32374 str = ext;
32375 };
32376
32377 return true;
32378 }
32379
32380 static bool
32381 arm_parse_fp16_opt (const char *str)
32382 {
32383 if (strcasecmp (str, "ieee") == 0)
32384 fp16_format = ARM_FP16_FORMAT_IEEE;
32385 else if (strcasecmp (str, "alternative") == 0)
32386 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
32387 else
32388 {
32389 as_bad (_("unrecognised float16 format \"%s\""), str);
32390 return false;
32391 }
32392
32393 return true;
32394 }
32395
32396 static bool
32397 arm_parse_cpu (const char *str)
32398 {
32399 const struct arm_cpu_option_table *opt;
32400 const char *ext = strchr (str, '+');
32401 size_t len;
32402
32403 if (ext != NULL)
32404 len = ext - str;
32405 else
32406 len = strlen (str);
32407
32408 if (len == 0)
32409 {
32410 as_bad (_("missing cpu name `%s'"), str);
32411 return false;
32412 }
32413
32414 for (opt = arm_cpus; opt->name != NULL; opt++)
32415 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32416 {
32417 mcpu_cpu_opt = &opt->value;
32418 if (mcpu_ext_opt == NULL)
32419 mcpu_ext_opt = XNEW (arm_feature_set);
32420 *mcpu_ext_opt = opt->ext;
32421 mcpu_fpu_opt = &opt->default_fpu;
32422 if (opt->canonical_name)
32423 {
32424 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
32425 strcpy (selected_cpu_name, opt->canonical_name);
32426 }
32427 else
32428 {
32429 size_t i;
32430
32431 if (len >= sizeof selected_cpu_name)
32432 len = (sizeof selected_cpu_name) - 1;
32433
32434 for (i = 0; i < len; i++)
32435 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32436 selected_cpu_name[i] = 0;
32437 }
32438
32439 if (ext != NULL)
32440 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
32441
32442 return true;
32443 }
32444
32445 as_bad (_("unknown cpu `%s'"), str);
32446 return false;
32447 }
32448
32449 static bool
32450 arm_parse_arch (const char *str)
32451 {
32452 const struct arm_arch_option_table *opt;
32453 const char *ext = strchr (str, '+');
32454 size_t len;
32455
32456 if (ext != NULL)
32457 len = ext - str;
32458 else
32459 len = strlen (str);
32460
32461 if (len == 0)
32462 {
32463 as_bad (_("missing architecture name `%s'"), str);
32464 return false;
32465 }
32466
32467 for (opt = arm_archs; opt->name != NULL; opt++)
32468 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
32469 {
32470 march_cpu_opt = &opt->value;
32471 if (march_ext_opt == NULL)
32472 march_ext_opt = XNEW (arm_feature_set);
32473 *march_ext_opt = arm_arch_none;
32474 march_fpu_opt = &opt->default_fpu;
32475 selected_ctx_ext_table = opt->ext_table;
32476 strcpy (selected_cpu_name, opt->name);
32477
32478 if (ext != NULL)
32479 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
32480 opt->ext_table);
32481
32482 return true;
32483 }
32484
32485 as_bad (_("unknown architecture `%s'\n"), str);
32486 return false;
32487 }
32488
32489 static bool
32490 arm_parse_fpu (const char * str)
32491 {
32492 const struct arm_option_fpu_value_table * opt;
32493
32494 for (opt = arm_fpus; opt->name != NULL; opt++)
32495 if (streq (opt->name, str))
32496 {
32497 mfpu_opt = &opt->value;
32498 return true;
32499 }
32500
32501 as_bad (_("unknown floating point format `%s'\n"), str);
32502 return false;
32503 }
32504
32505 static bool
32506 arm_parse_float_abi (const char * str)
32507 {
32508 const struct arm_option_value_table * opt;
32509
32510 for (opt = arm_float_abis; opt->name != NULL; opt++)
32511 if (streq (opt->name, str))
32512 {
32513 mfloat_abi_opt = opt->value;
32514 return true;
32515 }
32516
32517 as_bad (_("unknown floating point abi `%s'\n"), str);
32518 return false;
32519 }
32520
32521 #ifdef OBJ_ELF
32522 static bool
32523 arm_parse_eabi (const char * str)
32524 {
32525 const struct arm_option_value_table *opt;
32526
32527 for (opt = arm_eabis; opt->name != NULL; opt++)
32528 if (streq (opt->name, str))
32529 {
32530 meabi_flags = opt->value;
32531 return true;
32532 }
32533 as_bad (_("unknown EABI `%s'\n"), str);
32534 return false;
32535 }
32536 #endif
32537
32538 static bool
32539 arm_parse_it_mode (const char * str)
32540 {
32541 bool ret = true;
32542
32543 if (streq ("arm", str))
32544 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
32545 else if (streq ("thumb", str))
32546 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
32547 else if (streq ("always", str))
32548 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
32549 else if (streq ("never", str))
32550 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
32551 else
32552 {
32553 as_bad (_("unknown implicit IT mode `%s', should be "\
32554 "arm, thumb, always, or never."), str);
32555 ret = false;
32556 }
32557
32558 return ret;
32559 }
32560
32561 static bool
32562 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
32563 {
32564 codecomposer_syntax = true;
32565 arm_comment_chars[0] = ';';
32566 arm_line_separator_chars[0] = 0;
32567 return true;
32568 }
32569
32570 struct arm_long_option_table arm_long_opts[] =
32571 {
32572 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
32573 arm_parse_cpu, NULL},
32574 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
32575 arm_parse_arch, NULL},
32576 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
32577 arm_parse_fpu, NULL},
32578 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
32579 arm_parse_float_abi, NULL},
32580 #ifdef OBJ_ELF
32581 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
32582 arm_parse_eabi, NULL},
32583 #endif
32584 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
32585 arm_parse_it_mode, NULL},
32586 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
32587 arm_ccs_mode, NULL},
32588 {"mfp16-format=",
32589 N_("[ieee|alternative]\n\
32590 set the encoding for half precision floating point "
32591 "numbers to IEEE\n\
32592 or Arm alternative format."),
32593 arm_parse_fp16_opt, NULL },
32594 {NULL, NULL, 0, NULL}
32595 };
32596
32597 int
32598 md_parse_option (int c, const char * arg)
32599 {
32600 struct arm_option_table *opt;
32601 const struct arm_legacy_option_table *fopt;
32602 struct arm_long_option_table *lopt;
32603
32604 switch (c)
32605 {
32606 #ifdef OPTION_EB
32607 case OPTION_EB:
32608 target_big_endian = 1;
32609 break;
32610 #endif
32611
32612 #ifdef OPTION_EL
32613 case OPTION_EL:
32614 target_big_endian = 0;
32615 break;
32616 #endif
32617
32618 case OPTION_FIX_V4BX:
32619 fix_v4bx = true;
32620 break;
32621
32622 #ifdef OBJ_ELF
32623 case OPTION_FDPIC:
32624 arm_fdpic = true;
32625 break;
32626 #endif /* OBJ_ELF */
32627
32628 case 'a':
32629 /* Listing option. Just ignore these, we don't support additional
32630 ones. */
32631 return 0;
32632
32633 default:
32634 for (opt = arm_opts; opt->option != NULL; opt++)
32635 {
32636 if (c == opt->option[0]
32637 && ((arg == NULL && opt->option[1] == 0)
32638 || streq (arg, opt->option + 1)))
32639 {
32640 /* If the option is deprecated, tell the user. */
32641 if (warn_on_deprecated && opt->deprecated != NULL)
32642 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32643 arg ? arg : "", _(opt->deprecated));
32644
32645 if (opt->var != NULL)
32646 *opt->var = opt->value;
32647
32648 return 1;
32649 }
32650 }
32651
32652 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
32653 {
32654 if (c == fopt->option[0]
32655 && ((arg == NULL && fopt->option[1] == 0)
32656 || streq (arg, fopt->option + 1)))
32657 {
32658 /* If the option is deprecated, tell the user. */
32659 if (warn_on_deprecated && fopt->deprecated != NULL)
32660 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
32661 arg ? arg : "", _(fopt->deprecated));
32662
32663 if (fopt->var != NULL)
32664 *fopt->var = &fopt->value;
32665
32666 return 1;
32667 }
32668 }
32669
32670 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32671 {
32672 /* These options are expected to have an argument. */
32673 if (c == lopt->option[0]
32674 && arg != NULL
32675 && strncmp (arg, lopt->option + 1,
32676 strlen (lopt->option + 1)) == 0)
32677 {
32678 /* If the option is deprecated, tell the user. */
32679 if (warn_on_deprecated && lopt->deprecated != NULL)
32680 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
32681 _(lopt->deprecated));
32682
32683 /* Call the sup-option parser. */
32684 return lopt->func (arg + strlen (lopt->option) - 1);
32685 }
32686 }
32687
32688 return 0;
32689 }
32690
32691 return 1;
32692 }
32693
32694 void
32695 md_show_usage (FILE * fp)
32696 {
32697 struct arm_option_table *opt;
32698 struct arm_long_option_table *lopt;
32699
32700 fprintf (fp, _(" ARM-specific assembler options:\n"));
32701
32702 for (opt = arm_opts; opt->option != NULL; opt++)
32703 if (opt->help != NULL)
32704 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
32705
32706 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
32707 if (lopt->help != NULL)
32708 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
32709
32710 #ifdef OPTION_EB
32711 fprintf (fp, _("\
32712 -EB assemble code for a big-endian cpu\n"));
32713 #endif
32714
32715 #ifdef OPTION_EL
32716 fprintf (fp, _("\
32717 -EL assemble code for a little-endian cpu\n"));
32718 #endif
32719
32720 fprintf (fp, _("\
32721 --fix-v4bx Allow BX in ARMv4 code\n"));
32722
32723 #ifdef OBJ_ELF
32724 fprintf (fp, _("\
32725 --fdpic generate an FDPIC object file\n"));
32726 #endif /* OBJ_ELF */
32727 }
32728
32729 #ifdef OBJ_ELF
32730
32731 typedef struct
32732 {
32733 int val;
32734 arm_feature_set flags;
32735 } cpu_arch_ver_table;
32736
32737 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
32738 chronologically for architectures, with an exception for ARMv6-M and
32739 ARMv6S-M due to legacy reasons. No new architecture should have a
32740 special case. This allows for build attribute selection results to be
32741 stable when new architectures are added. */
32742 static const cpu_arch_ver_table cpu_arch_ver[] =
32743 {
32744 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
32745 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
32746 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
32747 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
32748 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
32749 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
32750 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
32751 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
32752 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
32753 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
32754 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
32755 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
32756 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
32757 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
32758 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
32759 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
32760 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
32761 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
32762 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
32763 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
32764 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
32765 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
32766 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
32767 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
32768
32769 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
32770 always selected build attributes to match those of ARMv6-M
32771 (resp. ARMv6S-M). However, due to these architectures being a strict
32772 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
32773 would be selected when fully respecting chronology of architectures.
32774 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
32775 move them before ARMv7 architectures. */
32776 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
32777 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
32778
32779 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
32780 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
32781 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
32782 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
32783 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
32784 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
32785 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
32786 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
32787 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
32788 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
32789 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
32790 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
32791 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
32792 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
32793 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
32794 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
32795 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A},
32796 {-1, ARM_ARCH_NONE}
32797 };
32798
32799 /* Set an attribute if it has not already been set by the user. */
32800
32801 static void
32802 aeabi_set_attribute_int (int tag, int value)
32803 {
32804 if (tag < 1
32805 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32806 || !attributes_set_explicitly[tag])
32807 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
32808 }
32809
32810 static void
32811 aeabi_set_attribute_string (int tag, const char *value)
32812 {
32813 if (tag < 1
32814 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
32815 || !attributes_set_explicitly[tag])
32816 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
32817 }
32818
32819 /* Return whether features in the *NEEDED feature set are available via
32820 extensions for the architecture whose feature set is *ARCH_FSET. */
32821
32822 static bool
32823 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
32824 const arm_feature_set *needed)
32825 {
32826 int i, nb_allowed_archs;
32827 arm_feature_set ext_fset;
32828 const struct arm_option_extension_value_table *opt;
32829
32830 ext_fset = arm_arch_none;
32831 for (opt = arm_extensions; opt->name != NULL; opt++)
32832 {
32833 /* Extension does not provide any feature we need. */
32834 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
32835 continue;
32836
32837 nb_allowed_archs =
32838 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
32839 for (i = 0; i < nb_allowed_archs; i++)
32840 {
32841 /* Empty entry. */
32842 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
32843 break;
32844
32845 /* Extension is available, add it. */
32846 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
32847 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
32848 }
32849 }
32850
32851 /* Can we enable all features in *needed? */
32852 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
32853 }
32854
32855 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
32856 a given architecture feature set *ARCH_EXT_FSET including extension feature
32857 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
32858 - if true, check for an exact match of the architecture modulo extensions;
32859 - otherwise, select build attribute value of the first superset
32860 architecture released so that results remains stable when new architectures
32861 are added.
32862 For -march/-mcpu=all the build attribute value of the most featureful
32863 architecture is returned. Tag_CPU_arch_profile result is returned in
32864 PROFILE. */
32865
32866 static int
32867 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
32868 const arm_feature_set *ext_fset,
32869 char *profile, int exact_match)
32870 {
32871 arm_feature_set arch_fset;
32872 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
32873
32874 /* Select most featureful architecture with all its extensions if building
32875 for -march=all as the feature sets used to set build attributes. */
32876 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
32877 {
32878 /* Force revisiting of decision for each new architecture. */
32879 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
32880 *profile = 'A';
32881 return TAG_CPU_ARCH_V8;
32882 }
32883
32884 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
32885
32886 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
32887 {
32888 arm_feature_set known_arch_fset;
32889
32890 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
32891 if (exact_match)
32892 {
32893 /* Base architecture match user-specified architecture and
32894 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
32895 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
32896 {
32897 p_ver_ret = p_ver;
32898 goto found;
32899 }
32900 /* Base architecture match user-specified architecture only
32901 (eg. ARMv6-M in the same case as above). Record it in case we
32902 find a match with above condition. */
32903 else if (p_ver_ret == NULL
32904 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
32905 p_ver_ret = p_ver;
32906 }
32907 else
32908 {
32909
32910 /* Architecture has all features wanted. */
32911 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
32912 {
32913 arm_feature_set added_fset;
32914
32915 /* Compute features added by this architecture over the one
32916 recorded in p_ver_ret. */
32917 if (p_ver_ret != NULL)
32918 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
32919 p_ver_ret->flags);
32920 /* First architecture that match incl. with extensions, or the
32921 only difference in features over the recorded match is
32922 features that were optional and are now mandatory. */
32923 if (p_ver_ret == NULL
32924 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
32925 {
32926 p_ver_ret = p_ver;
32927 goto found;
32928 }
32929 }
32930 else if (p_ver_ret == NULL)
32931 {
32932 arm_feature_set needed_ext_fset;
32933
32934 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
32935
32936 /* Architecture has all features needed when using some
32937 extensions. Record it and continue searching in case there
32938 exist an architecture providing all needed features without
32939 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
32940 OS extension). */
32941 if (have_ext_for_needed_feat_p (&known_arch_fset,
32942 &needed_ext_fset))
32943 p_ver_ret = p_ver;
32944 }
32945 }
32946 }
32947
32948 if (p_ver_ret == NULL)
32949 return -1;
32950
32951 found:
32952 /* Tag_CPU_arch_profile. */
32953 if (!ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r)
32954 && (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
32955 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
32956 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
32957 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))))
32958 *profile = 'A';
32959 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)
32960 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8r))
32961 *profile = 'R';
32962 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
32963 *profile = 'M';
32964 else
32965 *profile = '\0';
32966 return p_ver_ret->val;
32967 }
32968
32969 /* Set the public EABI object attributes. */
32970
32971 static void
32972 aeabi_set_public_attributes (void)
32973 {
32974 char profile = '\0';
32975 int arch = -1;
32976 int virt_sec = 0;
32977 int fp16_optional = 0;
32978 int skip_exact_match = 0;
32979 arm_feature_set flags, flags_arch, flags_ext;
32980
32981 /* Autodetection mode, choose the architecture based the instructions
32982 actually used. */
32983 if (no_cpu_selected ())
32984 {
32985 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
32986
32987 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32988 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
32989
32990 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32991 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
32992
32993 /* Code run during relaxation relies on selected_cpu being set. */
32994 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32995 flags_ext = arm_arch_none;
32996 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32997 selected_ext = flags_ext;
32998 selected_cpu = flags;
32999 }
33000 /* Otherwise, choose the architecture based on the capabilities of the
33001 requested cpu. */
33002 else
33003 {
33004 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
33005 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
33006 flags_ext = selected_ext;
33007 flags = selected_cpu;
33008 }
33009 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
33010
33011 /* Allow the user to override the reported architecture. */
33012 if (!ARM_FEATURE_ZERO (selected_object_arch))
33013 {
33014 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
33015 flags_ext = arm_arch_none;
33016 }
33017 else
33018 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
33019
33020 /* When this function is run again after relaxation has happened there is no
33021 way to determine whether an architecture or CPU was specified by the user:
33022 - selected_cpu is set above for relaxation to work;
33023 - march_cpu_opt is not set if only -mcpu or .cpu is used;
33024 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
33025 Therefore, if not in -march=all case we first try an exact match and fall
33026 back to autodetection. */
33027 if (!skip_exact_match)
33028 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
33029 if (arch == -1)
33030 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
33031 if (arch == -1)
33032 as_bad (_("no architecture contains all the instructions used\n"));
33033
33034 /* Tag_CPU_name. */
33035 if (selected_cpu_name[0])
33036 {
33037 char *q;
33038
33039 q = selected_cpu_name;
33040 if (startswith (q, "armv"))
33041 {
33042 int i;
33043
33044 q += 4;
33045 for (i = 0; q[i]; i++)
33046 q[i] = TOUPPER (q[i]);
33047 }
33048 aeabi_set_attribute_string (Tag_CPU_name, q);
33049 }
33050
33051 /* Tag_CPU_arch. */
33052 aeabi_set_attribute_int (Tag_CPU_arch, arch);
33053
33054 /* Tag_CPU_arch_profile. */
33055 if (profile != '\0')
33056 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
33057
33058 /* Tag_DSP_extension. */
33059 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
33060 aeabi_set_attribute_int (Tag_DSP_extension, 1);
33061
33062 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
33063 /* Tag_ARM_ISA_use. */
33064 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
33065 || ARM_FEATURE_ZERO (flags_arch))
33066 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
33067
33068 /* Tag_THUMB_ISA_use. */
33069 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
33070 || ARM_FEATURE_ZERO (flags_arch))
33071 {
33072 int thumb_isa_use;
33073
33074 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33075 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
33076 thumb_isa_use = 3;
33077 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
33078 thumb_isa_use = 2;
33079 else
33080 thumb_isa_use = 1;
33081 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
33082 }
33083
33084 /* Tag_VFP_arch. */
33085 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
33086 aeabi_set_attribute_int (Tag_VFP_arch,
33087 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33088 ? 7 : 8);
33089 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
33090 aeabi_set_attribute_int (Tag_VFP_arch,
33091 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
33092 ? 5 : 6);
33093 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
33094 {
33095 fp16_optional = 1;
33096 aeabi_set_attribute_int (Tag_VFP_arch, 3);
33097 }
33098 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
33099 {
33100 aeabi_set_attribute_int (Tag_VFP_arch, 4);
33101 fp16_optional = 1;
33102 }
33103 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
33104 aeabi_set_attribute_int (Tag_VFP_arch, 2);
33105 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
33106 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
33107 aeabi_set_attribute_int (Tag_VFP_arch, 1);
33108
33109 /* Tag_ABI_HardFP_use. */
33110 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
33111 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
33112 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
33113
33114 /* Tag_WMMX_arch. */
33115 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
33116 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
33117 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
33118 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
33119
33120 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
33121 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
33122 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
33123 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
33124 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
33125 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
33126 {
33127 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
33128 {
33129 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
33130 }
33131 else
33132 {
33133 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
33134 fp16_optional = 1;
33135 }
33136 }
33137
33138 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
33139 aeabi_set_attribute_int (Tag_MVE_arch, 2);
33140 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
33141 aeabi_set_attribute_int (Tag_MVE_arch, 1);
33142
33143 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
33144 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
33145 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
33146
33147 /* Tag_DIV_use.
33148
33149 We set Tag_DIV_use to two when integer divide instructions have been used
33150 in ARM state, or when Thumb integer divide instructions have been used,
33151 but we have no architecture profile set, nor have we any ARM instructions.
33152
33153 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
33154 by the base architecture.
33155
33156 For new architectures we will have to check these tests. */
33157 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
33158 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
33159 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
33160 aeabi_set_attribute_int (Tag_DIV_use, 0);
33161 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
33162 || (profile == '\0'
33163 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
33164 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
33165 aeabi_set_attribute_int (Tag_DIV_use, 2);
33166
33167 /* Tag_MP_extension_use. */
33168 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
33169 aeabi_set_attribute_int (Tag_MPextension_use, 1);
33170
33171 /* Tag Virtualization_use. */
33172 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
33173 virt_sec |= 1;
33174 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
33175 virt_sec |= 2;
33176 if (virt_sec != 0)
33177 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
33178
33179 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
33180 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
33181 }
33182
33183 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
33184 finished and free extension feature bits which will not be used anymore. */
33185
33186 void
33187 arm_md_post_relax (void)
33188 {
33189 aeabi_set_public_attributes ();
33190 XDELETE (mcpu_ext_opt);
33191 mcpu_ext_opt = NULL;
33192 XDELETE (march_ext_opt);
33193 march_ext_opt = NULL;
33194 }
33195
33196 /* Add the default contents for the .ARM.attributes section. */
33197
33198 void
33199 arm_md_end (void)
33200 {
33201 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
33202 return;
33203
33204 aeabi_set_public_attributes ();
33205 }
33206 #endif /* OBJ_ELF */
33207
33208 /* Parse a .cpu directive. */
33209
33210 static void
33211 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
33212 {
33213 const struct arm_cpu_option_table *opt;
33214 char *name;
33215 char saved_char;
33216
33217 name = input_line_pointer;
33218 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33219 input_line_pointer++;
33220 saved_char = *input_line_pointer;
33221 *input_line_pointer = 0;
33222
33223 /* Skip the first "all" entry. */
33224 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
33225 if (streq (opt->name, name))
33226 {
33227 selected_arch = opt->value;
33228 selected_ext = opt->ext;
33229 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33230 if (opt->canonical_name)
33231 strcpy (selected_cpu_name, opt->canonical_name);
33232 else
33233 {
33234 int i;
33235 for (i = 0; opt->name[i]; i++)
33236 selected_cpu_name[i] = TOUPPER (opt->name[i]);
33237
33238 selected_cpu_name[i] = 0;
33239 }
33240 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33241
33242 *input_line_pointer = saved_char;
33243 demand_empty_rest_of_line ();
33244 return;
33245 }
33246 as_bad (_("unknown cpu `%s'"), name);
33247 *input_line_pointer = saved_char;
33248 ignore_rest_of_line ();
33249 }
33250
33251 /* Parse a .arch directive. */
33252
33253 static void
33254 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
33255 {
33256 const struct arm_arch_option_table *opt;
33257 char saved_char;
33258 char *name;
33259
33260 name = input_line_pointer;
33261 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33262 input_line_pointer++;
33263 saved_char = *input_line_pointer;
33264 *input_line_pointer = 0;
33265
33266 /* Skip the first "all" entry. */
33267 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33268 if (streq (opt->name, name))
33269 {
33270 selected_arch = opt->value;
33271 selected_ctx_ext_table = opt->ext_table;
33272 selected_ext = arm_arch_none;
33273 selected_cpu = selected_arch;
33274 strcpy (selected_cpu_name, opt->name);
33275 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33276 *input_line_pointer = saved_char;
33277 demand_empty_rest_of_line ();
33278 return;
33279 }
33280
33281 as_bad (_("unknown architecture `%s'\n"), name);
33282 *input_line_pointer = saved_char;
33283 ignore_rest_of_line ();
33284 }
33285
33286 /* Parse a .object_arch directive. */
33287
33288 static void
33289 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
33290 {
33291 const struct arm_arch_option_table *opt;
33292 char saved_char;
33293 char *name;
33294
33295 name = input_line_pointer;
33296 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33297 input_line_pointer++;
33298 saved_char = *input_line_pointer;
33299 *input_line_pointer = 0;
33300
33301 /* Skip the first "all" entry. */
33302 for (opt = arm_archs + 1; opt->name != NULL; opt++)
33303 if (streq (opt->name, name))
33304 {
33305 selected_object_arch = opt->value;
33306 *input_line_pointer = saved_char;
33307 demand_empty_rest_of_line ();
33308 return;
33309 }
33310
33311 as_bad (_("unknown architecture `%s'\n"), name);
33312 *input_line_pointer = saved_char;
33313 ignore_rest_of_line ();
33314 }
33315
33316 /* Parse a .arch_extension directive. */
33317
33318 static void
33319 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
33320 {
33321 const struct arm_option_extension_value_table *opt;
33322 char saved_char;
33323 char *name;
33324 int adding_value = 1;
33325
33326 name = input_line_pointer;
33327 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33328 input_line_pointer++;
33329 saved_char = *input_line_pointer;
33330 *input_line_pointer = 0;
33331
33332 if (strlen (name) >= 2
33333 && startswith (name, "no"))
33334 {
33335 adding_value = 0;
33336 name += 2;
33337 }
33338
33339 /* Check the context specific extension table */
33340 if (selected_ctx_ext_table)
33341 {
33342 const struct arm_ext_table * ext_opt;
33343 for (ext_opt = selected_ctx_ext_table; ext_opt->name != NULL; ext_opt++)
33344 {
33345 if (streq (ext_opt->name, name))
33346 {
33347 if (adding_value)
33348 {
33349 if (ARM_FEATURE_ZERO (ext_opt->merge))
33350 /* TODO: Option not supported. When we remove the
33351 legacy table this case should error out. */
33352 continue;
33353 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33354 ext_opt->merge);
33355 }
33356 else
33357 ARM_CLEAR_FEATURE (selected_ext, selected_ext, ext_opt->clear);
33358
33359 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33360 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33361 *input_line_pointer = saved_char;
33362 demand_empty_rest_of_line ();
33363 return;
33364 }
33365 }
33366 }
33367
33368 for (opt = arm_extensions; opt->name != NULL; opt++)
33369 if (streq (opt->name, name))
33370 {
33371 int i, nb_allowed_archs =
33372 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
33373 for (i = 0; i < nb_allowed_archs; i++)
33374 {
33375 /* Empty entry. */
33376 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
33377 continue;
33378 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
33379 break;
33380 }
33381
33382 if (i == nb_allowed_archs)
33383 {
33384 as_bad (_("architectural extension `%s' is not allowed for the "
33385 "current base architecture"), name);
33386 break;
33387 }
33388
33389 if (adding_value)
33390 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
33391 opt->merge_value);
33392 else
33393 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
33394
33395 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
33396 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33397 *input_line_pointer = saved_char;
33398 demand_empty_rest_of_line ();
33399 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
33400 on this return so that duplicate extensions (extensions with the
33401 same name as a previous extension in the list) are not considered
33402 for command-line parsing. */
33403 return;
33404 }
33405
33406 if (opt->name == NULL)
33407 as_bad (_("unknown architecture extension `%s'\n"), name);
33408
33409 *input_line_pointer = saved_char;
33410 ignore_rest_of_line ();
33411 }
33412
33413 /* Parse a .fpu directive. */
33414
33415 static void
33416 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
33417 {
33418 const struct arm_option_fpu_value_table *opt;
33419 char saved_char;
33420 char *name;
33421
33422 name = input_line_pointer;
33423 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
33424 input_line_pointer++;
33425 saved_char = *input_line_pointer;
33426 *input_line_pointer = 0;
33427
33428 for (opt = arm_fpus; opt->name != NULL; opt++)
33429 if (streq (opt->name, name))
33430 {
33431 selected_fpu = opt->value;
33432 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any);
33433 #ifndef CPU_DEFAULT
33434 if (no_cpu_selected ())
33435 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
33436 else
33437 #endif
33438 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
33439 *input_line_pointer = saved_char;
33440 demand_empty_rest_of_line ();
33441 return;
33442 }
33443
33444 as_bad (_("unknown floating point format `%s'\n"), name);
33445 *input_line_pointer = saved_char;
33446 ignore_rest_of_line ();
33447 }
33448
33449 /* Copy symbol information. */
33450
33451 void
33452 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
33453 {
33454 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
33455 }
33456
33457 #ifdef OBJ_ELF
33458 /* Given a symbolic attribute NAME, return the proper integer value.
33459 Returns -1 if the attribute is not known. */
33460
33461 int
33462 arm_convert_symbolic_attribute (const char *name)
33463 {
33464 static const struct
33465 {
33466 const char * name;
33467 const int tag;
33468 }
33469 attribute_table[] =
33470 {
33471 /* When you modify this table you should
33472 also modify the list in doc/c-arm.texi. */
33473 #define T(tag) {#tag, tag}
33474 T (Tag_CPU_raw_name),
33475 T (Tag_CPU_name),
33476 T (Tag_CPU_arch),
33477 T (Tag_CPU_arch_profile),
33478 T (Tag_ARM_ISA_use),
33479 T (Tag_THUMB_ISA_use),
33480 T (Tag_FP_arch),
33481 T (Tag_VFP_arch),
33482 T (Tag_WMMX_arch),
33483 T (Tag_Advanced_SIMD_arch),
33484 T (Tag_PCS_config),
33485 T (Tag_ABI_PCS_R9_use),
33486 T (Tag_ABI_PCS_RW_data),
33487 T (Tag_ABI_PCS_RO_data),
33488 T (Tag_ABI_PCS_GOT_use),
33489 T (Tag_ABI_PCS_wchar_t),
33490 T (Tag_ABI_FP_rounding),
33491 T (Tag_ABI_FP_denormal),
33492 T (Tag_ABI_FP_exceptions),
33493 T (Tag_ABI_FP_user_exceptions),
33494 T (Tag_ABI_FP_number_model),
33495 T (Tag_ABI_align_needed),
33496 T (Tag_ABI_align8_needed),
33497 T (Tag_ABI_align_preserved),
33498 T (Tag_ABI_align8_preserved),
33499 T (Tag_ABI_enum_size),
33500 T (Tag_ABI_HardFP_use),
33501 T (Tag_ABI_VFP_args),
33502 T (Tag_ABI_WMMX_args),
33503 T (Tag_ABI_optimization_goals),
33504 T (Tag_ABI_FP_optimization_goals),
33505 T (Tag_compatibility),
33506 T (Tag_CPU_unaligned_access),
33507 T (Tag_FP_HP_extension),
33508 T (Tag_VFP_HP_extension),
33509 T (Tag_ABI_FP_16bit_format),
33510 T (Tag_MPextension_use),
33511 T (Tag_DIV_use),
33512 T (Tag_nodefaults),
33513 T (Tag_also_compatible_with),
33514 T (Tag_conformance),
33515 T (Tag_T2EE_use),
33516 T (Tag_Virtualization_use),
33517 T (Tag_DSP_extension),
33518 T (Tag_MVE_arch),
33519 /* We deliberately do not include Tag_MPextension_use_legacy. */
33520 #undef T
33521 };
33522 unsigned int i;
33523
33524 if (name == NULL)
33525 return -1;
33526
33527 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
33528 if (streq (name, attribute_table[i].name))
33529 return attribute_table[i].tag;
33530
33531 return -1;
33532 }
33533
33534 /* Apply sym value for relocations only in the case that they are for
33535 local symbols in the same segment as the fixup and you have the
33536 respective architectural feature for blx and simple switches. */
33537
33538 int
33539 arm_apply_sym_value (struct fix * fixP, segT this_seg)
33540 {
33541 if (fixP->fx_addsy
33542 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
33543 /* PR 17444: If the local symbol is in a different section then a reloc
33544 will always be generated for it, so applying the symbol value now
33545 will result in a double offset being stored in the relocation. */
33546 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
33547 && !S_FORCE_RELOC (fixP->fx_addsy, true))
33548 {
33549 switch (fixP->fx_r_type)
33550 {
33551 case BFD_RELOC_ARM_PCREL_BLX:
33552 case BFD_RELOC_THUMB_PCREL_BRANCH23:
33553 if (ARM_IS_FUNC (fixP->fx_addsy))
33554 return 1;
33555 break;
33556
33557 case BFD_RELOC_ARM_PCREL_CALL:
33558 case BFD_RELOC_THUMB_PCREL_BLX:
33559 if (THUMB_IS_FUNC (fixP->fx_addsy))
33560 return 1;
33561 break;
33562
33563 default:
33564 break;
33565 }
33566
33567 }
33568 return 0;
33569 }
33570 #endif /* OBJ_ELF */