]>
Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
250d07de | 2 | Copyright (C) 1994-2021 Free Software Foundation, Inc. |
b99bd4ef NC |
3 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) |
4 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 5 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
6 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
7 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
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 | |
ec2655a6 | 13 | the Free Software Foundation; either version 3, or (at your option) |
b99bd4ef NC |
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 | |
c19d1205 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
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 | |
699d2810 NC |
23 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
24 | 02110-1301, USA. */ | |
b99bd4ef | 25 | |
42a68e18 | 26 | #include "as.h" |
5287ad62 | 27 | #include <limits.h> |
037e8744 | 28 | #include <stdarg.h> |
c19d1205 | 29 | #define NO_RELOC 0 |
3882b010 | 30 | #include "safe-ctype.h" |
b99bd4ef NC |
31 | #include "subsegs.h" |
32 | #include "obstack.h" | |
3da1d841 | 33 | #include "libiberty.h" |
f263249b | 34 | #include "opcode/arm.h" |
f37164d7 | 35 | #include "cpu-arm.h" |
f263249b | 36 | |
b99bd4ef NC |
37 | #ifdef OBJ_ELF |
38 | #include "elf/arm.h" | |
a394c00f | 39 | #include "dw2gencfi.h" |
b99bd4ef NC |
40 | #endif |
41 | ||
f0927246 NC |
42 | #include "dwarf2dbg.h" |
43 | ||
7ed4c4c5 NC |
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 | { | |
c19d1205 ZW |
52 | symbolS * proc_start; |
53 | symbolS * table_entry; | |
54 | symbolS * personality_routine; | |
55 | int personality_index; | |
7ed4c4c5 | 56 | /* The segment containing the function. */ |
c19d1205 ZW |
57 | segT saved_seg; |
58 | subsegT saved_subseg; | |
7ed4c4c5 NC |
59 | /* Opcodes generated from this function. */ |
60 | unsigned char * opcodes; | |
c19d1205 ZW |
61 | int opcode_count; |
62 | int opcode_alloc; | |
7ed4c4c5 | 63 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 64 | offsetT frame_size; |
7ed4c4c5 NC |
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. */ | |
c19d1205 | 68 | offsetT pending_offset; |
7ed4c4c5 | 69 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
70 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
71 | offsetT fp_offset; | |
72 | int fp_reg; | |
7ed4c4c5 | 73 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 74 | unsigned fp_used:1; |
7ed4c4c5 | 75 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 76 | unsigned sp_restored:1; |
7ed4c4c5 NC |
77 | } unwind; |
78 | ||
18a20338 CL |
79 | /* Whether --fdpic was given. */ |
80 | static int arm_fdpic; | |
81 | ||
8b1ad454 NC |
82 | #endif /* OBJ_ELF */ |
83 | ||
4962c51a MS |
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 | ||
33a392fb PB |
93 | enum arm_float_abi |
94 | { | |
95 | ARM_FLOAT_ABI_HARD, | |
96 | ARM_FLOAT_ABI_SOFTFP, | |
97 | ARM_FLOAT_ABI_SOFT | |
98 | }; | |
99 | ||
c19d1205 | 100 | /* Types of processor to assemble for. */ |
b99bd4ef | 101 | #ifndef CPU_DEFAULT |
8a59fff3 | 102 | /* The code that was here used to select a default CPU depending on compiler |
fa94de6b | 103 | pre-defines which were only present when doing native builds, thus |
8a59fff3 MGD |
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. */ | |
b99bd4ef NC |
108 | #endif |
109 | ||
e8f8842d TC |
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. */ | |
5b7c81bd | 112 | static bool out_of_range_p (offsetT value, offsetT bits) |
e8f8842d TC |
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 | ||
b99bd4ef | 119 | #ifndef FPU_DEFAULT |
c820d418 MM |
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 | |
4e7fd91e PB |
129 | # elif defined (TE_VXWORKS) |
130 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
131 | # else |
132 | /* For backwards compatibility, default to FPA. */ | |
133 | # define FPU_DEFAULT FPU_ARCH_FPA | |
134 | # endif | |
135 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 136 | |
c19d1205 | 137 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 138 | |
4d354d8b TP |
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. */ | |
e74cfd16 | 142 | static arm_feature_set cpu_variant; |
4d354d8b TP |
143 | /* Feature bits used in each execution state. Used to set build attribute |
144 | (in particular Tag_*_ISA_use) in CPU autodetection mode. */ | |
e74cfd16 PB |
145 | static arm_feature_set arm_arch_used; |
146 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 147 | |
b99bd4ef | 148 | /* Flags stored in private area of BFD structure. */ |
5b7c81bd AM |
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; | |
278df34e | 155 | /* Warn on using deprecated features. */ |
5b7c81bd AM |
156 | static int warn_on_deprecated = true; |
157 | static int warn_on_restrict_it = false; | |
278df34e | 158 | |
2e6976a8 | 159 | /* Understand CodeComposer Studio assembly syntax. */ |
5b7c81bd | 160 | bool codecomposer_syntax = false; |
03b1477f RE |
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. */ | |
4d354d8b TP |
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; | |
e74cfd16 PB |
183 | |
184 | /* Constants for known architecture features. */ | |
185 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
f85d59c3 | 186 | static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1; |
e74cfd16 | 187 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; |
f85d59c3 KT |
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; | |
e74cfd16 PB |
190 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
191 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
69c9e028 | 192 | #ifdef OBJ_ELF |
e74cfd16 | 193 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; |
69c9e028 | 194 | #endif |
e74cfd16 PB |
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 | ||
823d2571 | 201 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1); |
4070243b | 202 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2); |
823d2571 TG |
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); | |
e74cfd16 | 209 | static const arm_feature_set arm_ext_v4t_5 = |
823d2571 TG |
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); | |
55e8aae7 SP |
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); | |
823d2571 TG |
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); | |
164446e0 | 233 | static const arm_feature_set arm_ext_v8r = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8R); |
69c9e028 | 234 | #ifdef OBJ_ELF |
e7d39ed3 | 235 | static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M); |
69c9e028 | 236 | #endif |
823d2571 | 237 | static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8); |
7e806470 | 238 | static const arm_feature_set arm_ext_m = |
173205ca | 239 | ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M, |
16a1fa25 | 240 | ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); |
823d2571 TG |
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); | |
ddfded2f | 246 | static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN); |
4ed7ed8d | 247 | static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M); |
16a1fa25 TP |
248 | static const arm_feature_set arm_ext_v8m_main = |
249 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN); | |
e12437dc AV |
250 | static const arm_feature_set arm_ext_v8_1m_main = |
251 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN); | |
16a1fa25 TP |
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); | |
ff8646ee TP |
255 | static const arm_feature_set arm_ext_v6t2_v8m = |
256 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M); | |
4ed7ed8d TP |
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); | |
69c9e028 | 260 | #ifdef OBJ_ELF |
15afaa63 TP |
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); | |
69c9e028 | 264 | #endif |
4d1464f2 MW |
265 | static const arm_feature_set arm_ext_ras = |
266 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS); | |
b8ec4e87 JW |
267 | /* FP16 instructions. */ |
268 | static const arm_feature_set arm_ext_fp16 = | |
269 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST); | |
01f48020 TC |
270 | static const arm_feature_set arm_ext_fp16_fml = |
271 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML); | |
dec41383 JW |
272 | static const arm_feature_set arm_ext_v8_2 = |
273 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A); | |
49e8a725 SN |
274 | static const arm_feature_set arm_ext_v8_3 = |
275 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A); | |
7fadb25d SD |
276 | static const arm_feature_set arm_ext_sb = |
277 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB); | |
dad0c3bf SD |
278 | static const arm_feature_set arm_ext_predres = |
279 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES); | |
aab2c27d MM |
280 | static const arm_feature_set arm_ext_bf16 = |
281 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16); | |
616ce08e MM |
282 | static const arm_feature_set arm_ext_i8mm = |
283 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM); | |
8b301fbb MI |
284 | static const arm_feature_set arm_ext_crc = |
285 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC); | |
4934a27c MM |
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); | |
e74cfd16 PB |
304 | |
305 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
2c6b98ea | 306 | static const arm_feature_set fpu_any = FPU_ANY; |
f85d59c3 | 307 | static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1); |
e74cfd16 PB |
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 | ||
2d447fca | 311 | static const arm_feature_set arm_cext_iwmmxt2 = |
823d2571 | 312 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2); |
e74cfd16 | 313 | static const arm_feature_set arm_cext_iwmmxt = |
823d2571 | 314 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT); |
e74cfd16 | 315 | static const arm_feature_set arm_cext_xscale = |
823d2571 | 316 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE); |
e74cfd16 | 317 | static const arm_feature_set arm_cext_maverick = |
823d2571 TG |
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); | |
e74cfd16 | 323 | static const arm_feature_set fpu_vfp_ext_v1xd = |
823d2571 TG |
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); | |
b1cc4aeb | 333 | static const arm_feature_set fpu_vfp_ext_d32 = |
823d2571 TG |
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); | |
5287ad62 | 337 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = |
823d2571 | 338 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); |
a7ad558c | 339 | static const arm_feature_set mve_ext = |
2da2eaf4 | 340 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE); |
a7ad558c | 341 | static const arm_feature_set mve_fp_ext = |
2da2eaf4 | 342 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE_FP); |
5aae9ae9 MM |
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); | |
69c9e028 | 348 | #ifdef OBJ_ELF |
823d2571 TG |
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); | |
69c9e028 | 353 | #endif |
823d2571 TG |
354 | static const arm_feature_set fpu_vfp_ext_fma = |
355 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA); | |
bca38921 | 356 | static const arm_feature_set fpu_vfp_ext_armv8 = |
823d2571 | 357 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8); |
a715796b | 358 | static const arm_feature_set fpu_vfp_ext_armv8xd = |
823d2571 | 359 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD); |
bca38921 | 360 | static const arm_feature_set fpu_neon_ext_armv8 = |
823d2571 | 361 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8); |
bca38921 | 362 | static const arm_feature_set fpu_crypto_ext_armv8 = |
823d2571 | 363 | ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8); |
d6b4b13e | 364 | static const arm_feature_set fpu_neon_ext_v8_1 = |
643afb90 | 365 | ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA); |
c604a79a JW |
366 | static const arm_feature_set fpu_neon_ext_dotprod = |
367 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD); | |
5a0c7a81 AC |
368 | static const arm_feature_set pacbti_ext = |
369 | ARM_FEATURE_CORE_HIGH_HIGH (ARM_EXT3_PACBTI); | |
e74cfd16 | 370 | |
33a392fb | 371 | static int mfloat_abi_opt = -1; |
4d354d8b TP |
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. */ | |
e74cfd16 | 381 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; |
4d354d8b TP |
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; | |
ee065d83 | 386 | /* Must be long enough to hold any of the names in arm_cpus. */ |
e20f9590 | 387 | static const struct arm_ext_table * selected_ctx_ext_table = NULL; |
ef8e6722 | 388 | static char selected_cpu_name[20]; |
8d67f500 | 389 | |
aacf0b33 KT |
390 | extern FLONUM_TYPE generic_floating_point_number; |
391 | ||
8d67f500 | 392 | /* Return if no cpu was selected on command-line. */ |
5b7c81bd | 393 | static bool |
8d67f500 NC |
394 | no_cpu_selected (void) |
395 | { | |
823d2571 | 396 | return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none); |
8d67f500 NC |
397 | } |
398 | ||
7cc69913 | 399 | #ifdef OBJ_ELF |
deeaaff8 DJ |
400 | # ifdef EABI_DEFAULT |
401 | static int meabi_flags = EABI_DEFAULT; | |
402 | # else | |
d507cf36 | 403 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 404 | # endif |
e1da3f5b | 405 | |
ee3c0378 AS |
406 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
407 | ||
5b7c81bd | 408 | bool |
5f4273c7 | 409 | arm_is_eabi (void) |
e1da3f5b PB |
410 | { |
411 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
412 | } | |
7cc69913 | 413 | #endif |
b99bd4ef | 414 | |
b99bd4ef | 415 | #ifdef OBJ_ELF |
c19d1205 | 416 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
417 | symbolS * GOT_symbol; |
418 | #endif | |
419 | ||
b99bd4ef NC |
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; | |
8dc2430f NC |
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) | |
b99bd4ef | 429 | |
e07e6e58 NC |
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 | ||
c19d1205 ZW |
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 | ||
5b7c81bd | 463 | static bool unified_syntax = false; |
b99bd4ef | 464 | |
bacebabc RM |
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 | |
477330fc RM |
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[] = "#[]{}"; | |
bacebabc | 470 | |
5287ad62 JB |
471 | enum neon_el_type |
472 | { | |
dcbf9037 | 473 | NT_invtype, |
5287ad62 JB |
474 | NT_untyped, |
475 | NT_integer, | |
476 | NT_float, | |
477 | NT_poly, | |
478 | NT_signed, | |
aab2c27d | 479 | NT_bfloat, |
dcbf9037 | 480 | NT_unsigned |
5287ad62 JB |
481 | }; |
482 | ||
483 | struct neon_type_el | |
484 | { | |
485 | enum neon_el_type type; | |
486 | unsigned size; | |
487 | }; | |
488 | ||
5aae9ae9 | 489 | #define NEON_MAX_TYPE_ELS 5 |
5287ad62 JB |
490 | |
491 | struct neon_type | |
492 | { | |
493 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
494 | unsigned elems; | |
495 | }; | |
496 | ||
5ee91343 | 497 | enum pred_instruction_type |
e07e6e58 | 498 | { |
5ee91343 AV |
499 | OUTSIDE_PRED_INSN, |
500 | INSIDE_VPT_INSN, | |
e07e6e58 NC |
501 | INSIDE_IT_INSN, |
502 | INSIDE_IT_LAST_INSN, | |
503 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
477330fc | 504 | if inside, should be the last one. */ |
e07e6e58 | 505 | NEUTRAL_IT_INSN, /* This could be either inside or outside, |
477330fc | 506 | i.e. BKPT and NOP. */ |
5ee91343 AV |
507 | IT_INSN, /* The IT insn has been parsed. */ |
508 | VPT_INSN, /* The VPT/VPST insn has been parsed. */ | |
35c228db | 509 | MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without |
5ee91343 | 510 | a predication code. */ |
4934a27c | 511 | MVE_UNPREDICABLE_INSN, /* MVE instruction that is non-predicable. */ |
e07e6e58 NC |
512 | }; |
513 | ||
ad6cec43 MGD |
514 | /* The maximum number of operands we need. */ |
515 | #define ARM_IT_MAX_OPERANDS 6 | |
e2b0ab59 | 516 | #define ARM_IT_MAX_RELOCS 3 |
ad6cec43 | 517 | |
b99bd4ef NC |
518 | struct arm_it |
519 | { | |
c19d1205 | 520 | const char * error; |
b99bd4ef | 521 | unsigned long instruction; |
7af67752 AM |
522 | unsigned int size; |
523 | unsigned int size_req; | |
524 | unsigned int cond; | |
037e8744 | 525 | /* "uncond_value" is set to the value in place of the conditional field in |
7af67752 | 526 | unconditional versions of the instruction, or -1u if nothing is |
037e8744 | 527 | appropriate. */ |
7af67752 | 528 | unsigned int uncond_value; |
5287ad62 | 529 | struct neon_type vectype; |
88714cb8 DG |
530 | /* This does not indicate an actual NEON instruction, only that |
531 | the mnemonic accepts neon-style type suffixes. */ | |
532 | int is_neon; | |
0110f2b8 PB |
533 | /* Set to the opcode if the instruction needs relaxation. |
534 | Zero if the instruction is not relaxed. */ | |
535 | unsigned long relax; | |
b99bd4ef NC |
536 | struct |
537 | { | |
538 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
539 | expressionS exp; |
540 | int pc_rel; | |
e2b0ab59 | 541 | } relocs[ARM_IT_MAX_RELOCS]; |
b99bd4ef | 542 | |
5ee91343 | 543 | enum pred_instruction_type pred_insn_type; |
e07e6e58 | 544 | |
c19d1205 ZW |
545 | struct |
546 | { | |
547 | unsigned reg; | |
ca3f61f7 | 548 | signed int imm; |
dcbf9037 | 549 | struct neon_type_el vectype; |
ca3f61f7 NC |
550 | unsigned present : 1; /* Operand present. */ |
551 | unsigned isreg : 1; /* Operand was a register. */ | |
f5f10c66 AV |
552 | unsigned immisreg : 2; /* .imm field is a second register. |
553 | 0: imm, 1: gpr, 2: MVE Q-register. */ | |
57785aa2 AV |
554 | unsigned isscalar : 2; /* Operand is a (SIMD) scalar: |
555 | 0) not scalar, | |
556 | 1) Neon scalar, | |
557 | 2) MVE scalar. */ | |
5287ad62 | 558 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ |
c96612cc | 559 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
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. */ | |
037e8744 | 563 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5ee91343 | 564 | unsigned isquad : 1; /* Operand is SIMD quad register. */ |
037e8744 | 565 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
1b883319 | 566 | unsigned iszr : 1; /* Operand is ZR register. */ |
ca3f61f7 NC |
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). */ | |
ad6cec43 | 574 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
575 | }; |
576 | ||
c19d1205 | 577 | static struct arm_it inst; |
b99bd4ef NC |
578 | |
579 | #define NUM_FLOAT_VALS 8 | |
580 | ||
05d2d07e | 581 | const char * fp_const[] = |
b99bd4ef NC |
582 | { |
583 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
584 | }; | |
585 | ||
b99bd4ef NC |
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 | ||
c19d1205 ZW |
596 | #define CP_T_X 0x00008000 |
597 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 598 | |
c19d1205 ZW |
599 | #define CONDS_BIT 0x00100000 |
600 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
601 | |
602 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
603 | ||
604 | struct asm_cond | |
605 | { | |
d3ce72d0 | 606 | const char * template_name; |
c921be7d | 607 | unsigned long value; |
b99bd4ef NC |
608 | }; |
609 | ||
c19d1205 | 610 | #define COND_ALWAYS 0xE |
b99bd4ef | 611 | |
b99bd4ef NC |
612 | struct asm_psr |
613 | { | |
d3ce72d0 | 614 | const char * template_name; |
c921be7d | 615 | unsigned long field; |
b99bd4ef NC |
616 | }; |
617 | ||
62b3e311 PB |
618 | struct asm_barrier_opt |
619 | { | |
e797f7e0 MGD |
620 | const char * template_name; |
621 | unsigned long value; | |
622 | const arm_feature_set arch; | |
62b3e311 PB |
623 | }; |
624 | ||
2d2255b5 | 625 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
626 | #define SPSR_BIT (1 << 22) |
627 | ||
c19d1205 ZW |
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) | |
b99bd4ef | 633 | |
c19d1205 | 634 | struct reloc_entry |
bfae80f2 | 635 | { |
0198d5e6 | 636 | const char * name; |
c921be7d | 637 | bfd_reloc_code_real_type reloc; |
bfae80f2 RE |
638 | }; |
639 | ||
5287ad62 | 640 | enum vfp_reg_pos |
bfae80f2 | 641 | { |
5287ad62 JB |
642 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
643 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
644 | }; |
645 | ||
646 | enum vfp_ldstm_type | |
647 | { | |
648 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
649 | }; | |
650 | ||
dcbf9037 JB |
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 | { | |
c921be7d NC |
657 | unsigned char defined; |
658 | unsigned char index; | |
659 | struct neon_type_el eltype; | |
dcbf9037 JB |
660 | }; |
661 | ||
c19d1205 | 662 | /* ARM register categories. This includes coprocessor numbers and various |
5aa75429 TP |
663 | architecture extensions' registers. Each entry should have an error message |
664 | in reg_expected_msgs below. */ | |
c19d1205 | 665 | enum arm_reg_type |
bfae80f2 | 666 | { |
c19d1205 ZW |
667 | REG_TYPE_RN, |
668 | REG_TYPE_CP, | |
669 | REG_TYPE_CN, | |
670 | REG_TYPE_FN, | |
671 | REG_TYPE_VFS, | |
672 | REG_TYPE_VFD, | |
5287ad62 | 673 | REG_TYPE_NQ, |
037e8744 | 674 | REG_TYPE_VFSD, |
5287ad62 | 675 | REG_TYPE_NDQ, |
dec41383 | 676 | REG_TYPE_NSD, |
037e8744 | 677 | REG_TYPE_NSDQ, |
c19d1205 ZW |
678 | REG_TYPE_VFC, |
679 | REG_TYPE_MVF, | |
680 | REG_TYPE_MVD, | |
681 | REG_TYPE_MVFX, | |
682 | REG_TYPE_MVDX, | |
683 | REG_TYPE_MVAX, | |
5ee91343 | 684 | REG_TYPE_MQ, |
c19d1205 ZW |
685 | REG_TYPE_DSPSC, |
686 | REG_TYPE_MMXWR, | |
687 | REG_TYPE_MMXWC, | |
688 | REG_TYPE_MMXWCG, | |
689 | REG_TYPE_XSCALE, | |
5ee91343 | 690 | REG_TYPE_RNB, |
1b883319 | 691 | REG_TYPE_ZR |
bfae80f2 RE |
692 | }; |
693 | ||
dcbf9037 JB |
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. */ | |
6c43fab6 RE |
698 | struct reg_entry |
699 | { | |
c921be7d | 700 | const char * name; |
90ec0d68 | 701 | unsigned int number; |
c921be7d NC |
702 | unsigned char type; |
703 | unsigned char builtin; | |
704 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
705 | }; |
706 | ||
c19d1205 | 707 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 708 | const char * const reg_expected_msgs[] = |
c19d1205 | 709 | { |
5aa75429 TP |
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"), | |
5ee91343 | 733 | [REG_TYPE_MQ] = N_("MVE vector register expected"), |
e925962f JB |
734 | [REG_TYPE_RNB] = "", |
735 | [REG_TYPE_ZR] = N_("ZR register expected"), | |
6c43fab6 RE |
736 | }; |
737 | ||
c19d1205 | 738 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 739 | #define REG_R12 12 |
c19d1205 ZW |
740 | #define REG_SP 13 |
741 | #define REG_LR 14 | |
742 | #define REG_PC 15 | |
404ff6b5 | 743 | |
b99bd4ef NC |
744 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
745 | take 2: */ | |
c19d1205 | 746 | #define INSN_SIZE 4 |
b99bd4ef NC |
747 | |
748 | struct asm_opcode | |
749 | { | |
750 | /* Basic string to match. */ | |
d3ce72d0 | 751 | const char * template_name; |
c19d1205 ZW |
752 | |
753 | /* Parameters to instruction. */ | |
5be8be5d | 754 | unsigned int operands[8]; |
c19d1205 ZW |
755 | |
756 | /* Conditional tag - see opcode_lookup. */ | |
757 | unsigned int tag : 4; | |
b99bd4ef NC |
758 | |
759 | /* Basic instruction code. */ | |
a302e574 | 760 | unsigned int avalue; |
b99bd4ef | 761 | |
c19d1205 ZW |
762 | /* Thumb-format instruction code. */ |
763 | unsigned int tvalue; | |
b99bd4ef | 764 | |
90e4755a | 765 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
766 | const arm_feature_set * avariant; |
767 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
768 | |
769 | /* Function to call to encode instruction in ARM format. */ | |
770 | void (* aencode) (void); | |
b99bd4ef | 771 | |
c19d1205 ZW |
772 | /* Function to call to encode instruction in Thumb format. */ |
773 | void (* tencode) (void); | |
5ee91343 AV |
774 | |
775 | /* Indicates whether this instruction may be vector predicated. */ | |
776 | unsigned int mayBeVecPred : 1; | |
b99bd4ef NC |
777 | }; |
778 | ||
a737bd4d NC |
779 | /* Defines for various bits that we will want to toggle. */ |
780 | #define INST_IMMEDIATE 0x02000000 | |
781 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 782 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
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 | |
a028a6f5 | 788 | #define CPSI_MMOD 0x00020000 |
90e4755a | 789 | |
a737bd4d NC |
790 | #define LITERAL_MASK 0xf000f000 |
791 | #define OPCODE_MASK 0xfe1fffff | |
792 | #define V4_STR_BIT 0x00000020 | |
8335d6aa | 793 | #define VLDR_VMOV_SAME 0x0040f000 |
90e4755a | 794 | |
efd81785 PB |
795 | #define T2_SUBS_PC_LR 0xf3de8f00 |
796 | ||
a737bd4d | 797 | #define DATA_OP_SHIFT 21 |
bada4342 | 798 | #define SBIT_SHIFT 20 |
90e4755a | 799 | |
ef8d22e6 PB |
800 | #define T2_OPCODE_MASK 0xfe1fffff |
801 | #define T2_DATA_OP_SHIFT 21 | |
bada4342 | 802 | #define T2_SBIT_SHIFT 20 |
ef8d22e6 | 803 | |
6530b175 NC |
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 | ||
a737bd4d NC |
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 | |
90e4755a | 829 | |
ef8d22e6 PB |
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 | ||
a737bd4d NC |
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 | |
90e4755a | 846 | |
a737bd4d NC |
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 | |
b99bd4ef | 858 | |
a737bd4d NC |
859 | #define T_OPCODE_ASR_R 0x4100 |
860 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
861 | #define T_OPCODE_LSR_R 0x40c0 |
862 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
863 | #define T_OPCODE_ASR_I 0x1000 |
864 | #define T_OPCODE_LSL_I 0x0000 | |
865 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 866 | |
a737bd4d NC |
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 | |
b99bd4ef | 872 | |
a737bd4d NC |
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 | |
c9b604bd | 888 | |
a737bd4d NC |
889 | #define T_OPCODE_PUSH 0xb400 |
890 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 891 | |
2fc8bdac | 892 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 893 | |
a737bd4d | 894 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 895 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 896 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 897 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 | 898 | |
5ee91343 | 899 | #define BAD_SYNTAX _("syntax error") |
c19d1205 | 900 | #define BAD_ARGS _("bad arguments to instruction") |
fdfde340 | 901 | #define BAD_SP _("r13 not allowed here") |
c19d1205 | 902 | #define BAD_PC _("r15 not allowed here") |
a302e574 AV |
903 | #define BAD_ODD _("Odd register not allowed here") |
904 | #define BAD_EVEN _("Even register not allowed here") | |
c19d1205 ZW |
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") | |
35c228db | 909 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode") |
dfa9f0d5 | 910 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
e12437dc | 911 | #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2") |
4934a27c | 912 | #define BAD_NO_VPT _("instruction not allowed in VPT block") |
dfa9f0d5 | 913 | #define BAD_NOT_IT _("instruction not allowed in IT block") |
5ee91343 | 914 | #define BAD_NOT_VPT _("instruction missing MVE vector predication code") |
037e8744 | 915 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 | 916 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
5ee91343 AV |
917 | #define BAD_OUT_VPT \ |
918 | _("vector predicated instruction should be in VPT/VPST block") | |
e07e6e58 | 919 | #define BAD_IT_COND _("incorrect condition in IT block") |
5ee91343 | 920 | #define BAD_VPT_COND _("incorrect condition in VPT/VPST block") |
e07e6e58 | 921 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") |
921e5f0a | 922 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
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") | |
9db2f6b4 RL |
927 | #define BAD_RANGE _("branch out of range") |
928 | #define BAD_FP16 _("selected processor does not support fp16 instruction") | |
aab2c27d | 929 | #define BAD_BF16 _("selected processor does not support bf16 instruction") |
4934a27c MM |
930 | #define BAD_CDE _("selected processor does not support cde instruction") |
931 | #define BAD_CDE_COPROC _("coprocessor for insn is not enabled for cde") | |
dd5181d5 | 932 | #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour") |
a9f02af8 | 933 | #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only") |
5ee91343 AV |
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") | |
a302e574 | 942 | #define BAD_SIMD_TYPE _("bad type in SIMD instruction") |
886e1c73 AV |
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") | |
35c228db | 948 | #define BAD_EL_TYPE _("bad element type for instruction") |
1b883319 | 949 | #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected") |
5a0c7a81 | 950 | #define BAD_PACBTI _("selected processor does not support PACBTI extention") |
c19d1205 | 951 | |
629310ab ML |
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; | |
b99bd4ef | 961 | |
b99bd4ef NC |
962 | /* Stuff needed to resolve the label ambiguity |
963 | As: | |
964 | ... | |
965 | label: <insn> | |
966 | may differ from: | |
967 | ... | |
968 | label: | |
5f4273c7 | 969 | <insn> */ |
b99bd4ef NC |
970 | |
971 | symbolS * last_label_seen; | |
5b7c81bd | 972 | static int label_is_thumb_function_name = false; |
e07e6e58 | 973 | |
3d0c9500 NC |
974 | /* Literal pool structure. Held on a per-section |
975 | and per-sub-section basis. */ | |
a737bd4d | 976 | |
c19d1205 | 977 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 978 | typedef struct literal_pool |
b99bd4ef | 979 | { |
c921be7d NC |
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; | |
a8040cf2 NC |
986 | #ifdef OBJ_ELF |
987 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
988 | #endif | |
c921be7d | 989 | struct literal_pool * next; |
8335d6aa | 990 | unsigned int alignment; |
3d0c9500 | 991 | } literal_pool; |
b99bd4ef | 992 | |
3d0c9500 NC |
993 | /* Pointer to a linked list of literal pools. */ |
994 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 995 | |
2e6976a8 DG |
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 | ||
e07e6e58 | 1005 | #ifdef OBJ_ELF |
5ee91343 | 1006 | # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred |
e07e6e58 | 1007 | #else |
5ee91343 | 1008 | static struct current_pred now_pred; |
e07e6e58 NC |
1009 | #endif |
1010 | ||
1011 | static inline int | |
5ee91343 | 1012 | now_pred_compatible (int cond) |
e07e6e58 | 1013 | { |
5ee91343 | 1014 | return (cond & ~1) == (now_pred.cc & ~1); |
e07e6e58 NC |
1015 | } |
1016 | ||
1017 | static inline int | |
1018 | conditional_insn (void) | |
1019 | { | |
1020 | return inst.cond != COND_ALWAYS; | |
1021 | } | |
1022 | ||
5ee91343 | 1023 | static int in_pred_block (void); |
e07e6e58 | 1024 | |
5ee91343 | 1025 | static int handle_pred_state (void); |
e07e6e58 NC |
1026 | |
1027 | static void force_automatic_it_block_close (void); | |
1028 | ||
c921be7d NC |
1029 | static void it_fsm_post_encode (void); |
1030 | ||
5ee91343 | 1031 | #define set_pred_insn_type(type) \ |
e07e6e58 NC |
1032 | do \ |
1033 | { \ | |
5ee91343 AV |
1034 | inst.pred_insn_type = type; \ |
1035 | if (handle_pred_state () == FAIL) \ | |
477330fc | 1036 | return; \ |
e07e6e58 NC |
1037 | } \ |
1038 | while (0) | |
1039 | ||
5ee91343 | 1040 | #define set_pred_insn_type_nonvoid(type, failret) \ |
c921be7d NC |
1041 | do \ |
1042 | { \ | |
5ee91343 AV |
1043 | inst.pred_insn_type = type; \ |
1044 | if (handle_pred_state () == FAIL) \ | |
477330fc | 1045 | return failret; \ |
c921be7d NC |
1046 | } \ |
1047 | while(0) | |
1048 | ||
5ee91343 | 1049 | #define set_pred_insn_type_last() \ |
e07e6e58 NC |
1050 | do \ |
1051 | { \ | |
1052 | if (inst.cond == COND_ALWAYS) \ | |
5ee91343 | 1053 | set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \ |
e07e6e58 | 1054 | else \ |
5ee91343 | 1055 | set_pred_insn_type (INSIDE_IT_LAST_INSN); \ |
e07e6e58 NC |
1056 | } \ |
1057 | while (0) | |
1058 | ||
e39c1607 SD |
1059 | /* Toggle value[pos]. */ |
1060 | #define TOGGLE_BIT(value, pos) (value ^ (1 << pos)) | |
1061 | ||
c19d1205 | 1062 | /* Pure syntax. */ |
b99bd4ef | 1063 | |
c19d1205 ZW |
1064 | /* This array holds the chars that always start a comment. If the |
1065 | pre-processor is disabled, these aren't very useful. */ | |
2e6976a8 | 1066 | char arm_comment_chars[] = "@"; |
3d0c9500 | 1067 | |
c19d1205 ZW |
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[] = "#"; | |
3d0c9500 | 1076 | |
2e6976a8 | 1077 | char arm_line_separator_chars[] = ";"; |
b99bd4ef | 1078 | |
c19d1205 ZW |
1079 | /* Chars that can be used to separate mant |
1080 | from exp in floating point numbers. */ | |
1081 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 1082 | |
c19d1205 ZW |
1083 | /* Chars that mean this number is a floating point constant. */ |
1084 | /* As in 0f12.456 */ | |
1085 | /* or 0d1.2345e12 */ | |
b99bd4ef | 1086 | |
5312fe52 | 1087 | const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh"; |
3d0c9500 | 1088 | |
c19d1205 ZW |
1089 | /* Prefix characters that indicate the start of an immediate |
1090 | value. */ | |
1091 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 1092 | |
c19d1205 ZW |
1093 | /* Separator character handling. */ |
1094 | ||
1095 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
1096 | ||
5312fe52 BW |
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 | ||
c19d1205 ZW |
1107 | static inline int |
1108 | skip_past_char (char ** str, char c) | |
1109 | { | |
8ab8155f NC |
1110 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
1111 | skip_whitespace (*str); | |
427d0db6 | 1112 | |
c19d1205 ZW |
1113 | if (**str == c) |
1114 | { | |
1115 | (*str)++; | |
1116 | return SUCCESS; | |
3d0c9500 | 1117 | } |
c19d1205 ZW |
1118 | else |
1119 | return FAIL; | |
1120 | } | |
c921be7d | 1121 | |
c19d1205 | 1122 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 1123 | |
c19d1205 ZW |
1124 | /* Arithmetic expressions (possibly involving symbols). */ |
1125 | ||
1126 | /* Return TRUE if anything in the expression is a bignum. */ | |
1127 | ||
5b7c81bd | 1128 | static bool |
c19d1205 ZW |
1129 | walk_no_bignums (symbolS * sp) |
1130 | { | |
1131 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
5b7c81bd | 1132 | return true; |
c19d1205 ZW |
1133 | |
1134 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 1135 | { |
c19d1205 ZW |
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))); | |
3d0c9500 NC |
1139 | } |
1140 | ||
5b7c81bd | 1141 | return false; |
3d0c9500 NC |
1142 | } |
1143 | ||
5b7c81bd | 1144 | static bool in_my_get_expression = false; |
c19d1205 ZW |
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 | |
5287ad62 JB |
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 | |
a737bd4d | 1153 | |
b99bd4ef | 1154 | static int |
c19d1205 | 1155 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 1156 | { |
c19d1205 | 1157 | char * save_in; |
b99bd4ef | 1158 | |
c19d1205 ZW |
1159 | /* In unified syntax, all prefixes are optional. */ |
1160 | if (unified_syntax) | |
5287ad62 | 1161 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
477330fc | 1162 | : GE_OPT_PREFIX; |
b99bd4ef | 1163 | |
c19d1205 | 1164 | switch (prefix_mode) |
b99bd4ef | 1165 | { |
c19d1205 ZW |
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: | |
5287ad62 | 1176 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
1177 | if (is_immediate_prefix (**str)) |
1178 | (*str)++; | |
1179 | break; | |
0198d5e6 TC |
1180 | default: |
1181 | abort (); | |
c19d1205 | 1182 | } |
b99bd4ef | 1183 | |
c19d1205 | 1184 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 1185 | |
c19d1205 ZW |
1186 | save_in = input_line_pointer; |
1187 | input_line_pointer = *str; | |
5b7c81bd | 1188 | in_my_get_expression = true; |
2ac93be7 | 1189 | expression (ep); |
5b7c81bd | 1190 | in_my_get_expression = false; |
c19d1205 | 1191 | |
f86adc07 | 1192 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 1193 | { |
f86adc07 | 1194 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
1195 | *str = input_line_pointer; |
1196 | input_line_pointer = save_in; | |
1197 | if (inst.error == NULL) | |
f86adc07 NS |
1198 | inst.error = (ep->X_op == O_absent |
1199 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
1200 | return 1; |
1201 | } | |
b99bd4ef | 1202 | |
c19d1205 ZW |
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. */ | |
5287ad62 JB |
1206 | if (prefix_mode != GE_OPT_PREFIX_BIG |
1207 | && (ep->X_op == O_big | |
477330fc | 1208 | || (ep->X_add_symbol |
5287ad62 | 1209 | && (walk_no_bignums (ep->X_add_symbol) |
477330fc | 1210 | || (ep->X_op_symbol |
5287ad62 | 1211 | && walk_no_bignums (ep->X_op_symbol)))))) |
c19d1205 ZW |
1212 | { |
1213 | inst.error = _("invalid constant"); | |
1214 | *str = input_line_pointer; | |
1215 | input_line_pointer = save_in; | |
1216 | return 1; | |
1217 | } | |
b99bd4ef | 1218 | |
c19d1205 ZW |
1219 | *str = input_line_pointer; |
1220 | input_line_pointer = save_in; | |
0198d5e6 | 1221 | return SUCCESS; |
b99bd4ef NC |
1222 | } |
1223 | ||
c19d1205 ZW |
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. | |
b99bd4ef | 1228 | |
c19d1205 ZW |
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. | |
b99bd4ef | 1235 | |
c19d1205 | 1236 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1237 | |
6d4af3c2 | 1238 | const char * |
c19d1205 ZW |
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; | |
b99bd4ef | 1245 | |
c19d1205 ZW |
1246 | switch (type) |
1247 | { | |
5312fe52 BW |
1248 | case 'H': |
1249 | case 'h': | |
2557e081 JB |
1250 | /* bfloat16, despite not being part of the IEEE specification, can also |
1251 | be handled by atof_ieee(). */ | |
1252 | case 'b': | |
5312fe52 BW |
1253 | prec = 1; |
1254 | break; | |
1255 | ||
c19d1205 ZW |
1256 | case 'f': |
1257 | case 'F': | |
1258 | case 's': | |
1259 | case 'S': | |
1260 | prec = 2; | |
1261 | break; | |
b99bd4ef | 1262 | |
c19d1205 ZW |
1263 | case 'd': |
1264 | case 'D': | |
1265 | case 'r': | |
1266 | case 'R': | |
1267 | prec = 4; | |
1268 | break; | |
b99bd4ef | 1269 | |
c19d1205 ZW |
1270 | case 'x': |
1271 | case 'X': | |
499ac353 | 1272 | prec = 5; |
c19d1205 | 1273 | break; |
b99bd4ef | 1274 | |
c19d1205 ZW |
1275 | case 'p': |
1276 | case 'P': | |
499ac353 | 1277 | prec = 5; |
c19d1205 | 1278 | break; |
a737bd4d | 1279 | |
c19d1205 ZW |
1280 | default: |
1281 | *sizeP = 0; | |
499ac353 | 1282 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1283 | } |
b99bd4ef | 1284 | |
c19d1205 ZW |
1285 | t = atof_ieee (input_line_pointer, type, words); |
1286 | if (t) | |
1287 | input_line_pointer = t; | |
499ac353 | 1288 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1289 | |
72c03e30 BW |
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 | } | |
c19d1205 | 1302 | else |
72c03e30 BW |
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 | } | |
b99bd4ef | 1313 | |
499ac353 | 1314 | return NULL; |
c19d1205 | 1315 | } |
b99bd4ef | 1316 | |
c19d1205 ZW |
1317 | /* We handle all bad expressions here, so that we can report the faulty |
1318 | instruction in the error message. */ | |
0198d5e6 | 1319 | |
c19d1205 | 1320 | void |
91d6fa6a | 1321 | md_operand (expressionS * exp) |
c19d1205 ZW |
1322 | { |
1323 | if (in_my_get_expression) | |
91d6fa6a | 1324 | exp->X_op = O_illegal; |
b99bd4ef NC |
1325 | } |
1326 | ||
c19d1205 | 1327 | /* Immediate values. */ |
b99bd4ef | 1328 | |
0198d5e6 | 1329 | #ifdef OBJ_ELF |
c19d1205 ZW |
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. */ | |
0198d5e6 | 1333 | |
c19d1205 ZW |
1334 | static int |
1335 | immediate_for_directive (int *val) | |
b99bd4ef | 1336 | { |
c19d1205 ZW |
1337 | expressionS exp; |
1338 | exp.X_op = O_illegal; | |
b99bd4ef | 1339 | |
c19d1205 ZW |
1340 | if (is_immediate_prefix (*input_line_pointer)) |
1341 | { | |
1342 | input_line_pointer++; | |
1343 | expression (&exp); | |
1344 | } | |
b99bd4ef | 1345 | |
c19d1205 ZW |
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; | |
b99bd4ef | 1354 | } |
c19d1205 | 1355 | #endif |
b99bd4ef | 1356 | |
c19d1205 | 1357 | /* Register parsing. */ |
b99bd4ef | 1358 | |
c19d1205 ZW |
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) | |
b99bd4ef | 1366 | { |
c19d1205 ZW |
1367 | char *start = *ccp; |
1368 | char *p; | |
1369 | struct reg_entry *reg; | |
b99bd4ef | 1370 | |
477330fc RM |
1371 | skip_whitespace (start); |
1372 | ||
c19d1205 ZW |
1373 | #ifdef REGISTER_PREFIX |
1374 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1375 | return NULL; |
c19d1205 ZW |
1376 | start++; |
1377 | #endif | |
1378 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1379 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1380 | start++; | |
1381 | #endif | |
b99bd4ef | 1382 | |
c19d1205 ZW |
1383 | p = start; |
1384 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1385 | return NULL; | |
b99bd4ef | 1386 | |
c19d1205 ZW |
1387 | do |
1388 | p++; | |
1389 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1390 | ||
629310ab | 1391 | reg = (struct reg_entry *) str_hash_find_n (arm_reg_hsh, start, p - start); |
c19d1205 ZW |
1392 | |
1393 | if (!reg) | |
1394 | return NULL; | |
1395 | ||
1396 | *ccp = p; | |
1397 | return reg; | |
b99bd4ef NC |
1398 | } |
1399 | ||
1400 | static int | |
dcbf9037 | 1401 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
477330fc | 1402 | enum arm_reg_type type) |
b99bd4ef | 1403 | { |
c19d1205 ZW |
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. */ | |
79134647 | 1412 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1413 | return reg->number; |
1414 | break; | |
69b97547 | 1415 | |
c19d1205 ZW |
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 | } | |
1a0670f3 | 1423 | /* Fall through. */ |
6057a28f | 1424 | |
c19d1205 ZW |
1425 | case REG_TYPE_MMXWC: |
1426 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1427 | instructions that take WC registers. */ | |
79134647 | 1428 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1429 | return reg->number; |
6057a28f | 1430 | break; |
c19d1205 | 1431 | |
6057a28f | 1432 | default: |
c19d1205 | 1433 | break; |
6057a28f NC |
1434 | } |
1435 | ||
dcbf9037 JB |
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 | ||
c19d1205 ZW |
1459 | *ccp = start; |
1460 | return FAIL; | |
1461 | } | |
69b97547 | 1462 | |
dcbf9037 JB |
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; | |
477330fc RM |
1506 | case 'd': |
1507 | thistype = NT_float; | |
1508 | thissize = 64; | |
1509 | ptr++; | |
1510 | goto done; | |
aab2c27d MM |
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; | |
dcbf9037 JB |
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 | |
477330fc RM |
1549 | && thissize != 64) |
1550 | { | |
1551 | as_bad (_("bad size %d in type specifier"), thissize); | |
dcbf9037 JB |
1552 | return FAIL; |
1553 | } | |
1554 | } | |
1555 | ||
037e8744 | 1556 | done: |
dcbf9037 | 1557 | if (type) |
477330fc RM |
1558 | { |
1559 | type->el[type->elems].type = thistype; | |
dcbf9037 JB |
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) | |
477330fc RM |
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 | } | |
dcbf9037 | 1605 | else |
477330fc RM |
1606 | { |
1607 | first_error (_("vector type expected")); | |
1608 | return FAIL; | |
1609 | } | |
dcbf9037 JB |
1610 | } |
1611 | else | |
1612 | return FAIL; | |
5f4273c7 | 1613 | |
dcbf9037 | 1614 | *ccp = str; |
5f4273c7 | 1615 | |
dcbf9037 JB |
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 | ||
5ee91343 AV |
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. */ | |
5b7c81bd | 1637 | static bool |
5ee91343 AV |
1638 | mark_feature_used (const arm_feature_set *feature) |
1639 | { | |
886e1c73 AV |
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); | |
5b7c81bd | 1647 | return false; |
886e1c73 | 1648 | } |
5ee91343 AV |
1649 | /* Ensure the option is valid on the current architecture. */ |
1650 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
5b7c81bd | 1651 | return false; |
5ee91343 AV |
1652 | |
1653 | /* Add the appropriate architecture feature for the barrier option used. | |
1654 | */ | |
1655 | record_feature_use (feature); | |
1656 | ||
5b7c81bd | 1657 | return true; |
5ee91343 AV |
1658 | } |
1659 | ||
dcbf9037 JB |
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, | |
477330fc RM |
1667 | enum arm_reg_type *rtype, |
1668 | struct neon_typed_alias *typeinfo) | |
dcbf9037 JB |
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) | |
477330fc | 1686 | *ccp = str; |
dcbf9037 | 1687 | if (typeinfo) |
477330fc | 1688 | *typeinfo = atype; |
dcbf9037 JB |
1689 | return altreg; |
1690 | } | |
1691 | ||
037e8744 JB |
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 | |
477330fc | 1696 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) |
037e8744 | 1697 | || (type == REG_TYPE_NSDQ |
477330fc RM |
1698 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD |
1699 | || reg->type == REG_TYPE_NQ)) | |
dec41383 JW |
1700 | || (type == REG_TYPE_NSD |
1701 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
f512f76f NC |
1702 | || (type == REG_TYPE_MMXWC |
1703 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1704 | type = (enum arm_reg_type) reg->type; |
dcbf9037 | 1705 | |
5ee91343 AV |
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 | ||
dcbf9037 JB |
1726 | if (type != reg->type) |
1727 | return FAIL; | |
1728 | ||
1729 | if (reg->neon) | |
1730 | atype = *reg->neon; | |
5f4273c7 | 1731 | |
dcbf9037 JB |
1732 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1733 | { | |
1734 | if ((atype.defined & NTA_HASTYPE) != 0) | |
477330fc RM |
1735 | { |
1736 | first_error (_("can't redefine type for operand")); | |
1737 | return FAIL; | |
1738 | } | |
dcbf9037 JB |
1739 | atype.defined |= NTA_HASTYPE; |
1740 | atype.eltype = parsetype; | |
1741 | } | |
5f4273c7 | 1742 | |
dcbf9037 JB |
1743 | if (skip_past_char (&str, '[') == SUCCESS) |
1744 | { | |
dec41383 JW |
1745 | if (type != REG_TYPE_VFD |
1746 | && !(type == REG_TYPE_VFS | |
57785aa2 AV |
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))) | |
477330fc | 1750 | { |
57785aa2 AV |
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")); | |
477330fc RM |
1755 | return FAIL; |
1756 | } | |
5f4273c7 | 1757 | |
dcbf9037 | 1758 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
1759 | { |
1760 | first_error (_("can't change index for operand")); | |
1761 | return FAIL; | |
1762 | } | |
dcbf9037 JB |
1763 | |
1764 | atype.defined |= NTA_HASINDEX; | |
1765 | ||
1766 | if (skip_past_char (&str, ']') == SUCCESS) | |
477330fc | 1767 | atype.index = NEON_ALL_LANES; |
dcbf9037 | 1768 | else |
477330fc RM |
1769 | { |
1770 | expressionS exp; | |
dcbf9037 | 1771 | |
477330fc | 1772 | my_get_expression (&exp, &str, GE_NO_PREFIX); |
dcbf9037 | 1773 | |
477330fc RM |
1774 | if (exp.X_op != O_constant) |
1775 | { | |
1776 | first_error (_("constant expression required")); | |
1777 | return FAIL; | |
1778 | } | |
dcbf9037 | 1779 | |
477330fc RM |
1780 | if (skip_past_char (&str, ']') == FAIL) |
1781 | return FAIL; | |
dcbf9037 | 1782 | |
477330fc RM |
1783 | atype.index = exp.X_add_number; |
1784 | } | |
dcbf9037 | 1785 | } |
5f4273c7 | 1786 | |
dcbf9037 JB |
1787 | if (typeinfo) |
1788 | *typeinfo = atype; | |
5f4273c7 | 1789 | |
dcbf9037 JB |
1790 | if (rtype) |
1791 | *rtype = type; | |
5f4273c7 | 1792 | |
dcbf9037 | 1793 | *ccp = str; |
5f4273c7 | 1794 | |
dcbf9037 JB |
1795 | return reg->number; |
1796 | } | |
1797 | ||
efd6b359 | 1798 | /* Like arm_reg_parse, but also allow the following extra features: |
dcbf9037 JB |
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). | |
5f4273c7 | 1803 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1804 | |
1805 | static int | |
1806 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
477330fc | 1807 | enum arm_reg_type *rtype, struct neon_type_el *vectype) |
dcbf9037 JB |
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 | ||
0855e32b NS |
1816 | /* Do not allow regname(... to parse as a register. */ |
1817 | if (*str == '(') | |
1818 | return FAIL; | |
1819 | ||
dcbf9037 JB |
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 | ||
5287ad62 JB |
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 | |
57785aa2 AV |
1843 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum |
1844 | arm_reg_type reg_type) | |
5287ad62 | 1845 | { |
dcbf9037 | 1846 | int reg; |
5287ad62 | 1847 | char *str = *ccp; |
dcbf9037 | 1848 | struct neon_typed_alias atype; |
57785aa2 | 1849 | unsigned reg_size; |
5f4273c7 | 1850 | |
dec41383 | 1851 | reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype); |
5f4273c7 | 1852 | |
57785aa2 AV |
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 | ||
dcbf9037 | 1869 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1870 | return FAIL; |
5f4273c7 | 1871 | |
57785aa2 | 1872 | if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES) |
5287ad62 | 1873 | { |
dcbf9037 | 1874 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1875 | return FAIL; |
1876 | } | |
57785aa2 | 1877 | else if (atype.index >= reg_size / elsize) |
5287ad62 | 1878 | { |
dcbf9037 | 1879 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1880 | return FAIL; |
1881 | } | |
5f4273c7 | 1882 | |
dcbf9037 JB |
1883 | if (type) |
1884 | *type = atype.eltype; | |
5f4273c7 | 1885 | |
5287ad62 | 1886 | *ccp = str; |
5f4273c7 | 1887 | |
dcbf9037 | 1888 | return reg * 16 + atype.index; |
5287ad62 JB |
1889 | } |
1890 | ||
4b5a202f AV |
1891 | /* Types of registers in a list. */ |
1892 | ||
1893 | enum reg_list_els | |
1894 | { | |
1895 | REGLIST_RN, | |
1896 | REGLIST_CLRM, | |
1897 | REGLIST_VFP_S, | |
efd6b359 | 1898 | REGLIST_VFP_S_VPR, |
4b5a202f | 1899 | REGLIST_VFP_D, |
efd6b359 | 1900 | REGLIST_VFP_D_VPR, |
4b5a202f AV |
1901 | REGLIST_NEON_D |
1902 | }; | |
1903 | ||
c19d1205 | 1904 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1905 | |
c19d1205 | 1906 | static long |
4b5a202f | 1907 | parse_reg_list (char ** strp, enum reg_list_els etype) |
c19d1205 | 1908 | { |
4b5a202f AV |
1909 | char *str = *strp; |
1910 | long range = 0; | |
1911 | int another_range; | |
1912 | ||
1913 | gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM); | |
a737bd4d | 1914 | |
c19d1205 ZW |
1915 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1916 | do | |
6057a28f | 1917 | { |
477330fc RM |
1918 | skip_whitespace (str); |
1919 | ||
c19d1205 | 1920 | another_range = 0; |
a737bd4d | 1921 | |
c19d1205 ZW |
1922 | if (*str == '{') |
1923 | { | |
1924 | int in_range = 0; | |
1925 | int cur_reg = -1; | |
a737bd4d | 1926 | |
c19d1205 ZW |
1927 | str++; |
1928 | do | |
1929 | { | |
1930 | int reg; | |
4b5a202f AV |
1931 | const char apsr_str[] = "apsr"; |
1932 | int apsr_str_len = strlen (apsr_str); | |
6057a28f | 1933 | |
a65b5de6 | 1934 | reg = arm_reg_parse (&str, REG_TYPE_RN); |
4b5a202f | 1935 | if (etype == REGLIST_CLRM) |
c19d1205 | 1936 | { |
4b5a202f AV |
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 | } | |
c19d1205 | 1960 | } |
a737bd4d | 1961 | |
c19d1205 ZW |
1962 | if (in_range) |
1963 | { | |
1964 | int i; | |
a737bd4d | 1965 | |
c19d1205 ZW |
1966 | if (reg <= cur_reg) |
1967 | { | |
dcbf9037 | 1968 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1969 | return FAIL; |
1970 | } | |
40a18ebd | 1971 | |
c19d1205 ZW |
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 | } | |
a737bd4d | 1983 | |
c19d1205 ZW |
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")); | |
a737bd4d | 1989 | |
c19d1205 ZW |
1990 | range |= 1 << reg; |
1991 | cur_reg = reg; | |
1992 | } | |
1993 | while (skip_past_comma (&str) != FAIL | |
1994 | || (in_range = 1, *str++ == '-')); | |
1995 | str--; | |
a737bd4d | 1996 | |
d996d970 | 1997 | if (skip_past_char (&str, '}') == FAIL) |
c19d1205 | 1998 | { |
dcbf9037 | 1999 | first_error (_("missing `}'")); |
c19d1205 ZW |
2000 | return FAIL; |
2001 | } | |
2002 | } | |
4b5a202f | 2003 | else if (etype == REGLIST_RN) |
c19d1205 | 2004 | { |
91d6fa6a | 2005 | expressionS exp; |
40a18ebd | 2006 | |
91d6fa6a | 2007 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 2008 | return FAIL; |
40a18ebd | 2009 | |
91d6fa6a | 2010 | if (exp.X_op == O_constant) |
c19d1205 | 2011 | { |
91d6fa6a NC |
2012 | if (exp.X_add_number |
2013 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
2014 | { |
2015 | inst.error = _("invalid register mask"); | |
2016 | return FAIL; | |
2017 | } | |
a737bd4d | 2018 | |
91d6fa6a | 2019 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 2020 | { |
91d6fa6a | 2021 | int regno = range & exp.X_add_number; |
a737bd4d | 2022 | |
c19d1205 ZW |
2023 | regno &= -regno; |
2024 | regno = (1 << regno) - 1; | |
2025 | as_tsktsk | |
2026 | (_("Warning: duplicated register (r%d) in register list"), | |
2027 | regno); | |
2028 | } | |
a737bd4d | 2029 | |
91d6fa6a | 2030 | range |= exp.X_add_number; |
c19d1205 ZW |
2031 | } |
2032 | else | |
2033 | { | |
e2b0ab59 | 2034 | if (inst.relocs[0].type != 0) |
c19d1205 ZW |
2035 | { |
2036 | inst.error = _("expression too complex"); | |
2037 | return FAIL; | |
2038 | } | |
a737bd4d | 2039 | |
e2b0ab59 AV |
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; | |
c19d1205 ZW |
2043 | } |
2044 | } | |
a737bd4d | 2045 | |
c19d1205 ZW |
2046 | if (*str == '|' || *str == '+') |
2047 | { | |
2048 | str++; | |
2049 | another_range = 1; | |
2050 | } | |
a737bd4d | 2051 | } |
c19d1205 | 2052 | while (another_range); |
a737bd4d | 2053 | |
c19d1205 ZW |
2054 | *strp = str; |
2055 | return range; | |
a737bd4d NC |
2056 | } |
2057 | ||
c19d1205 ZW |
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 | |
5287ad62 JB |
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 | |
477330fc RM |
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. | |
dcbf9037 JB |
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. */ | |
6057a28f | 2072 | |
c19d1205 | 2073 | static int |
efd6b359 | 2074 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype, |
5b7c81bd | 2075 | bool *partial_match) |
6057a28f | 2076 | { |
037e8744 | 2077 | char *str = *ccp; |
c19d1205 ZW |
2078 | int base_reg; |
2079 | int new_base; | |
21d799b5 | 2080 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 2081 | int max_regs = 0; |
c19d1205 ZW |
2082 | int count = 0; |
2083 | int warned = 0; | |
2084 | unsigned long mask = 0; | |
a737bd4d | 2085 | int i; |
5b7c81bd AM |
2086 | bool vpr_seen = false; |
2087 | bool expect_vpr = | |
efd6b359 | 2088 | (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR); |
6057a28f | 2089 | |
477330fc | 2090 | if (skip_past_char (&str, '{') == FAIL) |
5287ad62 JB |
2091 | { |
2092 | inst.error = _("expecting {"); | |
2093 | return FAIL; | |
2094 | } | |
6057a28f | 2095 | |
5287ad62 | 2096 | switch (etype) |
c19d1205 | 2097 | { |
5287ad62 | 2098 | case REGLIST_VFP_S: |
efd6b359 | 2099 | case REGLIST_VFP_S_VPR: |
c19d1205 ZW |
2100 | regtype = REG_TYPE_VFS; |
2101 | max_regs = 32; | |
5287ad62 | 2102 | break; |
5f4273c7 | 2103 | |
5287ad62 | 2104 | case REGLIST_VFP_D: |
efd6b359 | 2105 | case REGLIST_VFP_D_VPR: |
5287ad62 | 2106 | regtype = REG_TYPE_VFD; |
b7fc2769 | 2107 | break; |
5f4273c7 | 2108 | |
b7fc2769 JB |
2109 | case REGLIST_NEON_D: |
2110 | regtype = REG_TYPE_NDQ; | |
2111 | break; | |
4b5a202f AV |
2112 | |
2113 | default: | |
2114 | gas_assert (0); | |
b7fc2769 JB |
2115 | } |
2116 | ||
efd6b359 | 2117 | if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR) |
b7fc2769 | 2118 | { |
b1cc4aeb PB |
2119 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
2120 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
477330fc RM |
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 | } | |
5287ad62 | 2130 | else |
477330fc | 2131 | max_regs = 16; |
c19d1205 | 2132 | } |
6057a28f | 2133 | |
c19d1205 | 2134 | base_reg = max_regs; |
5b7c81bd | 2135 | *partial_match = false; |
a737bd4d | 2136 | |
c19d1205 ZW |
2137 | do |
2138 | { | |
7af67752 | 2139 | unsigned int setmask = 1, addregs = 1; |
efd6b359 | 2140 | const char vpr_str[] = "vpr"; |
7af67752 | 2141 | size_t vpr_str_len = strlen (vpr_str); |
dcbf9037 | 2142 | |
037e8744 | 2143 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 2144 | |
efd6b359 AV |
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 | { | |
5b7c81bd | 2152 | vpr_seen = true; |
efd6b359 AV |
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) | |
a737bd4d | 2174 | { |
dcbf9037 | 2175 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
2176 | return FAIL; |
2177 | } | |
5f4273c7 | 2178 | |
5b7c81bd | 2179 | *partial_match = true; |
efd6b359 AV |
2180 | if (vpr_seen) |
2181 | continue; | |
2182 | ||
b7fc2769 | 2183 | if (new_base >= max_regs) |
477330fc RM |
2184 | { |
2185 | first_error (_("register out of range in list")); | |
2186 | return FAIL; | |
2187 | } | |
5f4273c7 | 2188 | |
5287ad62 JB |
2189 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
2190 | if (regtype == REG_TYPE_NQ) | |
477330fc RM |
2191 | { |
2192 | setmask = 3; | |
2193 | addregs = 2; | |
2194 | } | |
5287ad62 | 2195 | |
c19d1205 ZW |
2196 | if (new_base < base_reg) |
2197 | base_reg = new_base; | |
a737bd4d | 2198 | |
5287ad62 | 2199 | if (mask & (setmask << new_base)) |
c19d1205 | 2200 | { |
dcbf9037 | 2201 | first_error (_("invalid register list")); |
c19d1205 | 2202 | return FAIL; |
a737bd4d | 2203 | } |
a737bd4d | 2204 | |
efd6b359 | 2205 | if ((mask >> new_base) != 0 && ! warned && !vpr_seen) |
c19d1205 ZW |
2206 | { |
2207 | as_tsktsk (_("register list not in ascending order")); | |
2208 | warned = 1; | |
2209 | } | |
0bbf2aa4 | 2210 | |
5287ad62 JB |
2211 | mask |= setmask << new_base; |
2212 | count += addregs; | |
0bbf2aa4 | 2213 | |
037e8744 | 2214 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
2215 | { |
2216 | int high_range; | |
0bbf2aa4 | 2217 | |
037e8744 | 2218 | str++; |
0bbf2aa4 | 2219 | |
037e8744 | 2220 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
477330fc | 2221 | == FAIL) |
c19d1205 ZW |
2222 | { |
2223 | inst.error = gettext (reg_expected_msgs[regtype]); | |
2224 | return FAIL; | |
2225 | } | |
0bbf2aa4 | 2226 | |
477330fc RM |
2227 | if (high_range >= max_regs) |
2228 | { | |
2229 | first_error (_("register out of range in list")); | |
2230 | return FAIL; | |
2231 | } | |
b7fc2769 | 2232 | |
477330fc RM |
2233 | if (regtype == REG_TYPE_NQ) |
2234 | high_range = high_range + 1; | |
5287ad62 | 2235 | |
c19d1205 ZW |
2236 | if (high_range <= new_base) |
2237 | { | |
2238 | inst.error = _("register range not in ascending order"); | |
2239 | return FAIL; | |
2240 | } | |
0bbf2aa4 | 2241 | |
5287ad62 | 2242 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 2243 | { |
5287ad62 | 2244 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 2245 | { |
c19d1205 ZW |
2246 | inst.error = _("invalid register list"); |
2247 | return FAIL; | |
0bbf2aa4 | 2248 | } |
c19d1205 | 2249 | |
5287ad62 JB |
2250 | mask |= setmask << new_base; |
2251 | count += addregs; | |
0bbf2aa4 | 2252 | } |
0bbf2aa4 | 2253 | } |
0bbf2aa4 | 2254 | } |
037e8744 | 2255 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 2256 | |
037e8744 | 2257 | str++; |
0bbf2aa4 | 2258 | |
c19d1205 | 2259 | /* Sanity check -- should have raised a parse error above. */ |
efd6b359 | 2260 | if ((!vpr_seen && count == 0) || count > max_regs) |
c19d1205 ZW |
2261 | abort (); |
2262 | ||
2263 | *pbase = base_reg; | |
2264 | ||
efd6b359 AV |
2265 | if (expect_vpr && !vpr_seen) |
2266 | { | |
2267 | first_error (_("VPR expected last")); | |
2268 | return FAIL; | |
2269 | } | |
2270 | ||
c19d1205 ZW |
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 | ||
037e8744 JB |
2282 | *ccp = str; |
2283 | ||
c19d1205 | 2284 | return count; |
b99bd4ef NC |
2285 | } |
2286 | ||
dcbf9037 JB |
2287 | /* True if two alias types are the same. */ |
2288 | ||
5b7c81bd | 2289 | static bool |
dcbf9037 JB |
2290 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
2291 | { | |
2292 | if (!a && !b) | |
5b7c81bd | 2293 | return true; |
5f4273c7 | 2294 | |
dcbf9037 | 2295 | if (!a || !b) |
5b7c81bd | 2296 | return false; |
dcbf9037 JB |
2297 | |
2298 | if (a->defined != b->defined) | |
5b7c81bd | 2299 | return false; |
5f4273c7 | 2300 | |
dcbf9037 JB |
2301 | if ((a->defined & NTA_HASTYPE) != 0 |
2302 | && (a->eltype.type != b->eltype.type | |
477330fc | 2303 | || a->eltype.size != b->eltype.size)) |
5b7c81bd | 2304 | return false; |
dcbf9037 JB |
2305 | |
2306 | if ((a->defined & NTA_HASINDEX) != 0 | |
2307 | && (a->index != b->index)) | |
5b7c81bd | 2308 | return false; |
5f4273c7 | 2309 | |
5b7c81bd | 2310 | return true; |
dcbf9037 JB |
2311 | } |
2312 | ||
5287ad62 JB |
2313 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
2314 | The base register is put in *PBASE. | |
dcbf9037 | 2315 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
2316 | the return value. |
2317 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
2318 | Bits [6:5] encode the list length (minus one). |
2319 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 2320 | |
5287ad62 | 2321 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 2322 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
2323 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
2324 | ||
2325 | static int | |
dcbf9037 | 2326 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
35c228db | 2327 | int mve, |
477330fc | 2328 | struct neon_type_el *eltype) |
5287ad62 JB |
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; | |
35c228db AV |
2337 | const char *const incr_error = mve ? _("register stride must be 1") : |
2338 | _("register stride must be 1 or 2"); | |
20203fb9 | 2339 | const char *const type_error = _("mismatched element/structure types in list"); |
dcbf9037 | 2340 | struct neon_typed_alias firsttype; |
f85d59c3 KT |
2341 | firsttype.defined = 0; |
2342 | firsttype.eltype.type = NT_invtype; | |
2343 | firsttype.eltype.size = -1; | |
2344 | firsttype.index = -1; | |
5f4273c7 | 2345 | |
5287ad62 JB |
2346 | if (skip_past_char (&ptr, '{') == SUCCESS) |
2347 | leading_brace = 1; | |
5f4273c7 | 2348 | |
5287ad62 JB |
2349 | do |
2350 | { | |
dcbf9037 | 2351 | struct neon_typed_alias atype; |
35c228db AV |
2352 | if (mve) |
2353 | rtype = REG_TYPE_MQ; | |
dcbf9037 JB |
2354 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); |
2355 | ||
5287ad62 | 2356 | if (getreg == FAIL) |
477330fc RM |
2357 | { |
2358 | first_error (_(reg_expected_msgs[rtype])); | |
2359 | return FAIL; | |
2360 | } | |
5f4273c7 | 2361 | |
5287ad62 | 2362 | if (base_reg == -1) |
477330fc RM |
2363 | { |
2364 | base_reg = getreg; | |
2365 | if (rtype == REG_TYPE_NQ) | |
2366 | { | |
2367 | reg_incr = 1; | |
2368 | } | |
2369 | firsttype = atype; | |
2370 | } | |
5287ad62 | 2371 | else if (reg_incr == -1) |
477330fc RM |
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 | } | |
5287ad62 | 2380 | else if (getreg != base_reg + reg_incr * count) |
477330fc RM |
2381 | { |
2382 | first_error (_(incr_error)); | |
2383 | return FAIL; | |
2384 | } | |
dcbf9037 | 2385 | |
c921be7d | 2386 | if (! neon_alias_types_same (&atype, &firsttype)) |
477330fc RM |
2387 | { |
2388 | first_error (_(type_error)); | |
2389 | return FAIL; | |
2390 | } | |
5f4273c7 | 2391 | |
5287ad62 | 2392 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
477330fc | 2393 | modes. */ |
5287ad62 | 2394 | if (ptr[0] == '-') |
477330fc RM |
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 | } | |
5f4273c7 | 2427 | |
5287ad62 JB |
2428 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2429 | if (rtype == REG_TYPE_NQ) | |
477330fc RM |
2430 | { |
2431 | count += 2; | |
2432 | continue; | |
2433 | } | |
5f4273c7 | 2434 | |
dcbf9037 | 2435 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
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 | } | |
5287ad62 | 2445 | else if (lane == -1) |
477330fc | 2446 | lane = NEON_INTERLEAVE_LANES; |
5287ad62 | 2447 | else if (lane != NEON_INTERLEAVE_LANES) |
477330fc RM |
2448 | { |
2449 | first_error (_(type_error)); | |
2450 | return FAIL; | |
2451 | } | |
5287ad62 JB |
2452 | count++; |
2453 | } | |
2454 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2455 | |
5287ad62 JB |
2456 | /* No lane set by [x]. We must be interleaving structures. */ |
2457 | if (lane == -1) | |
2458 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2459 | |
5287ad62 | 2460 | /* Sanity check. */ |
35c228db | 2461 | if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4) |
5287ad62 JB |
2462 | || (count > 1 && reg_incr == -1)) |
2463 | { | |
dcbf9037 | 2464 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2465 | return FAIL; |
2466 | } | |
2467 | ||
2468 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2469 | { | |
dcbf9037 | 2470 | first_error (_("expected }")); |
5287ad62 JB |
2471 | return FAIL; |
2472 | } | |
5f4273c7 | 2473 | |
5287ad62 JB |
2474 | if (reg_incr == -1) |
2475 | reg_incr = 1; | |
2476 | ||
dcbf9037 JB |
2477 | if (eltype) |
2478 | *eltype = firsttype.eltype; | |
2479 | ||
5287ad62 JB |
2480 | *pbase = base_reg; |
2481 | *str = ptr; | |
5f4273c7 | 2482 | |
5287ad62 JB |
2483 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2484 | } | |
2485 | ||
c19d1205 ZW |
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. */ | |
3da1d841 | 2491 | |
c19d1205 ZW |
2492 | static int |
2493 | parse_reloc (char **str) | |
b99bd4ef | 2494 | { |
c19d1205 ZW |
2495 | struct reloc_entry *r; |
2496 | char *p, *q; | |
b99bd4ef | 2497 | |
c19d1205 ZW |
2498 | if (**str != '(') |
2499 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2500 | |
c19d1205 ZW |
2501 | p = *str + 1; |
2502 | q = p; | |
2503 | ||
2504 | while (*q && *q != ')' && *q != ',') | |
2505 | q++; | |
2506 | if (*q != ')') | |
2507 | return -1; | |
2508 | ||
21d799b5 | 2509 | if ((r = (struct reloc_entry *) |
629310ab | 2510 | str_hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) |
c19d1205 ZW |
2511 | return -1; |
2512 | ||
2513 | *str = q + 1; | |
2514 | return r->reloc; | |
b99bd4ef NC |
2515 | } |
2516 | ||
c19d1205 ZW |
2517 | /* Directives: register aliases. */ |
2518 | ||
dcbf9037 | 2519 | static struct reg_entry * |
90ec0d68 | 2520 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2521 | { |
d3ce72d0 | 2522 | struct reg_entry *new_reg; |
c19d1205 | 2523 | const char *name; |
b99bd4ef | 2524 | |
629310ab | 2525 | if ((new_reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2526 | { |
d3ce72d0 | 2527 | if (new_reg->builtin) |
c19d1205 | 2528 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2529 | |
c19d1205 ZW |
2530 | /* Only warn about a redefinition if it's not defined as the |
2531 | same register. */ | |
d3ce72d0 | 2532 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2533 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2534 | |
d929913e | 2535 | return NULL; |
c19d1205 | 2536 | } |
b99bd4ef | 2537 | |
c19d1205 | 2538 | name = xstrdup (str); |
325801bd | 2539 | new_reg = XNEW (struct reg_entry); |
b99bd4ef | 2540 | |
d3ce72d0 NC |
2541 | new_reg->name = name; |
2542 | new_reg->number = number; | |
2543 | new_reg->type = type; | |
5b7c81bd | 2544 | new_reg->builtin = false; |
d3ce72d0 | 2545 | new_reg->neon = NULL; |
b99bd4ef | 2546 | |
fe0e921f | 2547 | str_hash_insert (arm_reg_hsh, name, new_reg, 0); |
5f4273c7 | 2548 | |
d3ce72d0 | 2549 | return new_reg; |
dcbf9037 JB |
2550 | } |
2551 | ||
2552 | static void | |
2553 | insert_neon_reg_alias (char *str, int number, int type, | |
477330fc | 2554 | struct neon_typed_alias *atype) |
dcbf9037 JB |
2555 | { |
2556 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2557 | |
dcbf9037 JB |
2558 | if (!reg) |
2559 | { | |
2560 | first_error (_("attempt to redefine typed alias")); | |
2561 | return; | |
2562 | } | |
5f4273c7 | 2563 | |
dcbf9037 JB |
2564 | if (atype) |
2565 | { | |
325801bd | 2566 | reg->neon = XNEW (struct neon_typed_alias); |
dcbf9037 JB |
2567 | *reg->neon = *atype; |
2568 | } | |
c19d1205 | 2569 | } |
b99bd4ef | 2570 | |
c19d1205 | 2571 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2572 | |
c19d1205 | 2573 | new_register_name .req existing_register_name |
b99bd4ef | 2574 | |
c19d1205 | 2575 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2576 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2577 | |
5b7c81bd | 2578 | static bool |
c19d1205 ZW |
2579 | create_register_alias (char * newname, char *p) |
2580 | { | |
2581 | struct reg_entry *old; | |
2582 | char *oldname, *nbuf; | |
2583 | size_t nlen; | |
b99bd4ef | 2584 | |
c19d1205 ZW |
2585 | /* The input scrubber ensures that whitespace after the mnemonic is |
2586 | collapsed to single spaces. */ | |
2587 | oldname = p; | |
d34049e8 | 2588 | if (!startswith (oldname, " .req ")) |
5b7c81bd | 2589 | return false; |
b99bd4ef | 2590 | |
c19d1205 ZW |
2591 | oldname += 6; |
2592 | if (*oldname == '\0') | |
5b7c81bd | 2593 | return false; |
b99bd4ef | 2594 | |
629310ab | 2595 | old = (struct reg_entry *) str_hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2596 | if (!old) |
b99bd4ef | 2597 | { |
c19d1205 | 2598 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
5b7c81bd | 2599 | return true; |
b99bd4ef NC |
2600 | } |
2601 | ||
c19d1205 ZW |
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 | |
b99bd4ef | 2611 | |
29a2809e | 2612 | nbuf = xmemdup0 (newname, nlen); |
b99bd4ef | 2613 | |
c19d1205 ZW |
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. */ | |
d929913e NC |
2617 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2618 | { | |
2619 | for (p = nbuf; *p; p++) | |
2620 | *p = TOUPPER (*p); | |
c19d1205 | 2621 | |
d929913e NC |
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 | |
5f4273c7 | 2631 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2632 | first .req. */ |
2633 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
e1fa0163 NC |
2634 | { |
2635 | free (nbuf); | |
5b7c81bd | 2636 | return true; |
e1fa0163 | 2637 | } |
d929913e | 2638 | } |
c19d1205 | 2639 | |
d929913e NC |
2640 | for (p = nbuf; *p; p++) |
2641 | *p = TOLOWER (*p); | |
c19d1205 | 2642 | |
d929913e NC |
2643 | if (strncmp (nbuf, newname, nlen)) |
2644 | insert_reg_alias (nbuf, old->number, old->type); | |
2645 | } | |
c19d1205 | 2646 | |
e1fa0163 | 2647 | free (nbuf); |
5b7c81bd | 2648 | return true; |
b99bd4ef NC |
2649 | } |
2650 | ||
dcbf9037 JB |
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.: | |
5f4273c7 | 2659 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2660 | |
5b7c81bd | 2661 | static bool |
dcbf9037 JB |
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; | |
12d6b0b7 | 2669 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2670 | int namelen; |
5f4273c7 | 2671 | |
dcbf9037 JB |
2672 | typeinfo.defined = 0; |
2673 | typeinfo.eltype.type = NT_invtype; | |
2674 | typeinfo.eltype.size = -1; | |
2675 | typeinfo.index = -1; | |
5f4273c7 | 2676 | |
dcbf9037 | 2677 | nameend = p; |
5f4273c7 | 2678 | |
d34049e8 | 2679 | if (startswith (p, " .dn ")) |
dcbf9037 | 2680 | basetype = REG_TYPE_VFD; |
d34049e8 | 2681 | else if (startswith (p, " .qn ")) |
dcbf9037 JB |
2682 | basetype = REG_TYPE_NQ; |
2683 | else | |
5b7c81bd | 2684 | return false; |
5f4273c7 | 2685 | |
dcbf9037 | 2686 | p += 5; |
5f4273c7 | 2687 | |
dcbf9037 | 2688 | if (*p == '\0') |
5b7c81bd | 2689 | return false; |
5f4273c7 | 2690 | |
dcbf9037 JB |
2691 | basereg = arm_reg_parse_multi (&p); |
2692 | ||
2693 | if (basereg && basereg->type != basetype) | |
2694 | { | |
2695 | as_bad (_("bad type for register")); | |
5b7c81bd | 2696 | return false; |
dcbf9037 JB |
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) | |
477330fc RM |
2705 | { |
2706 | as_bad (_("expression must be constant")); | |
5b7c81bd | 2707 | return false; |
477330fc | 2708 | } |
dcbf9037 JB |
2709 | basereg = &mybasereg; |
2710 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
477330fc | 2711 | : exp.X_add_number; |
dcbf9037 JB |
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) | |
477330fc RM |
2722 | { |
2723 | as_bad (_("can't redefine the type of a register alias")); | |
5b7c81bd | 2724 | return false; |
477330fc | 2725 | } |
5f4273c7 | 2726 | |
dcbf9037 JB |
2727 | typeinfo.defined |= NTA_HASTYPE; |
2728 | if (ntype.elems != 1) | |
477330fc RM |
2729 | { |
2730 | as_bad (_("you must specify a single type only")); | |
5b7c81bd | 2731 | return false; |
477330fc | 2732 | } |
dcbf9037 JB |
2733 | typeinfo.eltype = ntype.el[0]; |
2734 | } | |
5f4273c7 | 2735 | |
dcbf9037 JB |
2736 | if (skip_past_char (&p, '[') == SUCCESS) |
2737 | { | |
2738 | expressionS exp; | |
2739 | /* We got a scalar index. */ | |
5f4273c7 | 2740 | |
dcbf9037 | 2741 | if (typeinfo.defined & NTA_HASINDEX) |
477330fc RM |
2742 | { |
2743 | as_bad (_("can't redefine the index of a scalar alias")); | |
5b7c81bd | 2744 | return false; |
477330fc | 2745 | } |
5f4273c7 | 2746 | |
dcbf9037 | 2747 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2748 | |
dcbf9037 | 2749 | if (exp.X_op != O_constant) |
477330fc RM |
2750 | { |
2751 | as_bad (_("scalar index must be constant")); | |
5b7c81bd | 2752 | return false; |
477330fc | 2753 | } |
5f4273c7 | 2754 | |
dcbf9037 JB |
2755 | typeinfo.defined |= NTA_HASINDEX; |
2756 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2757 | |
dcbf9037 | 2758 | if (skip_past_char (&p, ']') == FAIL) |
477330fc RM |
2759 | { |
2760 | as_bad (_("expecting ]")); | |
5b7c81bd | 2761 | return false; |
477330fc | 2762 | } |
dcbf9037 JB |
2763 | } |
2764 | ||
15735687 NS |
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 | |
dcbf9037 | 2769 | namelen = nameend - newname; |
15735687 NS |
2770 | #else |
2771 | newname = original_case_string; | |
2772 | namelen = strlen (newname); | |
2773 | #endif | |
2774 | ||
29a2809e | 2775 | namebuf = xmemdup0 (newname, namelen); |
5f4273c7 | 2776 | |
dcbf9037 | 2777 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
477330fc | 2778 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2779 | |
dcbf9037 JB |
2780 | /* Insert name in all uppercase. */ |
2781 | for (p = namebuf; *p; p++) | |
2782 | *p = TOUPPER (*p); | |
5f4273c7 | 2783 | |
dcbf9037 JB |
2784 | if (strncmp (namebuf, newname, namelen)) |
2785 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2786 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2787 | |
dcbf9037 JB |
2788 | /* Insert name in all lowercase. */ |
2789 | for (p = namebuf; *p; p++) | |
2790 | *p = TOLOWER (*p); | |
5f4273c7 | 2791 | |
dcbf9037 JB |
2792 | if (strncmp (namebuf, newname, namelen)) |
2793 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2794 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2795 | |
e1fa0163 | 2796 | free (namebuf); |
5b7c81bd | 2797 | return true; |
dcbf9037 JB |
2798 | } |
2799 | ||
c19d1205 ZW |
2800 | /* Should never be called, as .req goes between the alias and the |
2801 | register name, not at the beginning of the line. */ | |
c921be7d | 2802 | |
b99bd4ef | 2803 | static void |
c19d1205 | 2804 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2805 | { |
c19d1205 ZW |
2806 | as_bad (_("invalid syntax for .req directive")); |
2807 | } | |
b99bd4ef | 2808 | |
dcbf9037 JB |
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 | ||
c19d1205 ZW |
2821 | /* The .unreq directive deletes an alias which was previously defined |
2822 | by .req. For example: | |
b99bd4ef | 2823 | |
c19d1205 ZW |
2824 | my_alias .req r11 |
2825 | .unreq my_alias */ | |
b99bd4ef NC |
2826 | |
2827 | static void | |
c19d1205 | 2828 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2829 | { |
c19d1205 ZW |
2830 | char * name; |
2831 | char saved_char; | |
b99bd4ef | 2832 | |
c19d1205 ZW |
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 | { | |
fe0e921f AM |
2847 | struct reg_entry *reg |
2848 | = (struct reg_entry *) str_hash_find (arm_reg_hsh, name); | |
c19d1205 ZW |
2849 | |
2850 | if (!reg) | |
2851 | as_bad (_("unknown register alias '%s'"), name); | |
2852 | else if (reg->builtin) | |
a1727c1a | 2853 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2854 | name); |
2855 | else | |
2856 | { | |
d929913e NC |
2857 | char * p; |
2858 | char * nbuf; | |
2859 | ||
629310ab | 2860 | str_hash_delete (arm_reg_hsh, name); |
c19d1205 | 2861 | free ((char *) reg->name); |
9fbb53c7 | 2862 | free (reg->neon); |
c19d1205 | 2863 | free (reg); |
d929913e NC |
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. */ | |
5f4273c7 | 2868 | |
d929913e NC |
2869 | nbuf = strdup (name); |
2870 | for (p = nbuf; *p; p++) | |
2871 | *p = TOUPPER (*p); | |
629310ab | 2872 | reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2873 | if (reg) |
2874 | { | |
629310ab | 2875 | str_hash_delete (arm_reg_hsh, nbuf); |
d929913e | 2876 | free ((char *) reg->name); |
9fbb53c7 | 2877 | free (reg->neon); |
d929913e NC |
2878 | free (reg); |
2879 | } | |
2880 | ||
2881 | for (p = nbuf; *p; p++) | |
2882 | *p = TOLOWER (*p); | |
629310ab | 2883 | reg = (struct reg_entry *) str_hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2884 | if (reg) |
2885 | { | |
629310ab | 2886 | str_hash_delete (arm_reg_hsh, nbuf); |
d929913e | 2887 | free ((char *) reg->name); |
9fbb53c7 | 2888 | free (reg->neon); |
d929913e NC |
2889 | free (reg); |
2890 | } | |
2891 | ||
2892 | free (nbuf); | |
c19d1205 ZW |
2893 | } |
2894 | } | |
b99bd4ef | 2895 | |
c19d1205 | 2896 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2897 | demand_empty_rest_of_line (); |
2898 | } | |
2899 | ||
c19d1205 ZW |
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 | ||
cd000bff DJ |
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) | |
b99bd4ef | 2912 | { |
a737bd4d | 2913 | symbolS * symbolP; |
c19d1205 ZW |
2914 | const char * symname; |
2915 | int type; | |
b99bd4ef | 2916 | |
c19d1205 | 2917 | switch (state) |
b99bd4ef | 2918 | { |
c19d1205 ZW |
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; | |
c19d1205 ZW |
2931 | default: |
2932 | abort (); | |
2933 | } | |
2934 | ||
e01e1cee | 2935 | symbolP = symbol_new (symname, now_seg, frag, value); |
c19d1205 ZW |
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: | |
cd000bff DJ |
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 | |
2de7820f JZ |
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. */ | |
cd000bff DJ |
2966 | if (value == 0) |
2967 | { | |
2de7820f JZ |
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 | } | |
cd000bff DJ |
2973 | frag->tc_frag_data.first_map = symbolP; |
2974 | } | |
2975 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2976 | { |
2977 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
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 | } | |
cd000bff DJ |
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); | |
c19d1205 | 3005 | } |
cd000bff DJ |
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 | ||
4e9aaefb | 3016 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
cd000bff DJ |
3017 | void |
3018 | mapping_state (enum mstate state) | |
3019 | { | |
940b5ce0 DJ |
3020 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
3021 | ||
cd000bff DJ |
3022 | if (mapstate == state) |
3023 | /* The mapping symbol has already been emitted. | |
3024 | There is nothing else to do. */ | |
3025 | return; | |
49c62a33 NC |
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 | |
33eaf5de | 3037 | PC- relative forms. However, these cases will involve implicit |
49c62a33 NC |
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)) | |
4e9aaefb | 3044 | /* This case will be evaluated later. */ |
cd000bff | 3045 | return; |
cd000bff DJ |
3046 | |
3047 | mapping_state_2 (state, 0); | |
cd000bff DJ |
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 | { | |
940b5ce0 DJ |
3056 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
3057 | ||
3058 | if (!SEG_NORMAL (now_seg)) | |
3059 | return; | |
3060 | ||
cd000bff DJ |
3061 | if (mapstate == state) |
3062 | /* The mapping symbol has already been emitted. | |
3063 | There is nothing else to do. */ | |
3064 | return; | |
3065 | ||
4e9aaefb SA |
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 | ||
cd000bff DJ |
3076 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
3077 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 | 3078 | } |
4e9aaefb | 3079 | #undef TRANSITION |
c19d1205 | 3080 | #else |
d3106081 NS |
3081 | #define mapping_state(x) ((void)0) |
3082 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
3083 | #endif |
3084 | ||
3085 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
3086 | ||
4343666d | 3087 | #ifdef OBJ_COFF |
c19d1205 ZW |
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 | ||
37f6032b ZW |
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] == '.') | |
c19d1205 ZW |
3107 | return symbolP; |
3108 | ||
e1fa0163 | 3109 | real_start = concat (STUB_NAME, name, NULL); |
c19d1205 | 3110 | new_target = symbol_find (real_start); |
e1fa0163 | 3111 | free (real_start); |
c19d1205 ZW |
3112 | |
3113 | if (new_target == NULL) | |
3114 | { | |
bd3ba5d1 | 3115 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
3116 | new_target = symbolP; |
3117 | } | |
3118 | ||
c19d1205 ZW |
3119 | return new_target; |
3120 | } | |
4343666d | 3121 | #endif |
c19d1205 ZW |
3122 | |
3123 | static void | |
3124 | opcode_select (int width) | |
3125 | { | |
3126 | switch (width) | |
3127 | { | |
3128 | case 16: | |
3129 | if (! thumb_mode) | |
3130 | { | |
e74cfd16 | 3131 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
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 | } | |
c19d1205 ZW |
3139 | break; |
3140 | ||
3141 | case 32: | |
3142 | if (thumb_mode) | |
3143 | { | |
e74cfd16 | 3144 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
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 | } | |
c19d1205 ZW |
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. */ | |
5b7c81bd | 3217 | label_is_thumb_function_name = true; |
c19d1205 ZW |
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. */ | |
d02603dc | 3237 | delim = get_symbol_name (& name); |
c19d1205 | 3238 | end_name = input_line_pointer; |
d02603dc | 3239 | (void) restore_line_pointer (delim); |
c19d1205 ZW |
3240 | |
3241 | if (*input_line_pointer != ',') | |
3242 | { | |
3243 | *end_name = 0; | |
3244 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
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 | |
c19d1205 | 3265 | for this symbol. */ |
b99bd4ef NC |
3266 | if (listing & LISTING_SYMBOLS) |
3267 | { | |
3268 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 3269 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
3270 | |
3271 | memset (dummy_frag, 0, sizeof (fragS)); | |
3272 | dummy_frag->fr_type = rs_fill; | |
3273 | dummy_frag->line = listing_tail; | |
e01e1cee | 3274 | symbolP = symbol_new (name, undefined_section, dummy_frag, 0); |
b99bd4ef NC |
3275 | dummy_frag->fr_symbol = symbolP; |
3276 | } | |
3277 | else | |
3278 | #endif | |
e01e1cee | 3279 | symbolP = symbol_new (name, undefined_section, &zero_address_frag, 0); |
b99bd4ef NC |
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 | ||
c19d1205 | 3300 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
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 | ||
c19d1205 | 3309 | /* Directives: Mode selection. */ |
b99bd4ef | 3310 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 3314 | static void |
c19d1205 | 3315 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 3316 | { |
c19d1205 ZW |
3317 | char *name, delim; |
3318 | ||
d02603dc | 3319 | delim = get_symbol_name (& name); |
c19d1205 ZW |
3320 | |
3321 | if (!strcasecmp (name, "unified")) | |
5b7c81bd | 3322 | unified_syntax = true; |
c19d1205 | 3323 | else if (!strcasecmp (name, "divided")) |
5b7c81bd | 3324 | unified_syntax = false; |
c19d1205 ZW |
3325 | else |
3326 | { | |
3327 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
3328 | return; | |
3329 | } | |
d02603dc | 3330 | (void) restore_line_pointer (delim); |
b99bd4ef NC |
3331 | demand_empty_rest_of_line (); |
3332 | } | |
3333 | ||
c19d1205 ZW |
3334 | /* Directives: sectioning and alignment. */ |
3335 | ||
c19d1205 ZW |
3336 | static void |
3337 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 3338 | { |
c19d1205 ZW |
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 (); | |
cd000bff DJ |
3343 | |
3344 | #ifdef md_elf_section_change_hook | |
3345 | md_elf_section_change_hook (); | |
3346 | #endif | |
c19d1205 | 3347 | } |
b99bd4ef | 3348 | |
c19d1205 ZW |
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); | |
b99bd4ef | 3355 | |
c19d1205 | 3356 | record_alignment (now_seg, 1); |
b99bd4ef | 3357 | |
c19d1205 | 3358 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3359 | } |
3360 | ||
2e6976a8 DG |
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 | |
2b0f3761 | 3374 | function, whereas if it is NULL then it means the function end. */ |
2e6976a8 DG |
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 | ||
c19d1205 | 3459 | /* Directives: Literal pools. */ |
a737bd4d | 3460 | |
c19d1205 ZW |
3461 | static literal_pool * |
3462 | find_literal_pool (void) | |
a737bd4d | 3463 | { |
c19d1205 | 3464 | literal_pool * pool; |
a737bd4d | 3465 | |
c19d1205 | 3466 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3467 | { |
c19d1205 ZW |
3468 | if (pool->section == now_seg |
3469 | && pool->sub_section == now_subseg) | |
3470 | break; | |
a737bd4d NC |
3471 | } |
3472 | ||
c19d1205 | 3473 | return pool; |
a737bd4d NC |
3474 | } |
3475 | ||
c19d1205 ZW |
3476 | static literal_pool * |
3477 | find_or_make_literal_pool (void) | |
a737bd4d | 3478 | { |
c19d1205 ZW |
3479 | /* Next literal pool ID number. */ |
3480 | static unsigned int latest_pool_num = 1; | |
3481 | literal_pool * pool; | |
a737bd4d | 3482 | |
c19d1205 | 3483 | pool = find_literal_pool (); |
a737bd4d | 3484 | |
c19d1205 | 3485 | if (pool == NULL) |
a737bd4d | 3486 | { |
c19d1205 | 3487 | /* Create a new pool. */ |
325801bd | 3488 | pool = XNEW (literal_pool); |
c19d1205 ZW |
3489 | if (! pool) |
3490 | return NULL; | |
a737bd4d | 3491 | |
c19d1205 ZW |
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; | |
8335d6aa | 3497 | pool->alignment = 2; |
c19d1205 ZW |
3498 | |
3499 | /* Add it to the list. */ | |
3500 | list_of_pools = pool; | |
a737bd4d | 3501 | } |
a737bd4d | 3502 | |
c19d1205 ZW |
3503 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3504 | if (pool->symbol == NULL) | |
a737bd4d | 3505 | { |
c19d1205 | 3506 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
e01e1cee | 3507 | &zero_address_frag, 0); |
c19d1205 | 3508 | pool->id = latest_pool_num ++; |
a737bd4d NC |
3509 | } |
3510 | ||
c19d1205 ZW |
3511 | /* Done. */ |
3512 | return pool; | |
a737bd4d NC |
3513 | } |
3514 | ||
c19d1205 | 3515 | /* Add the literal in the global 'inst' |
5f4273c7 | 3516 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3517 | |
3518 | static int | |
8335d6aa | 3519 | add_to_lit_pool (unsigned int nbytes) |
b99bd4ef | 3520 | { |
8335d6aa JW |
3521 | #define PADDING_SLOT 0x1 |
3522 | #define LIT_ENTRY_SIZE_MASK 0xFF | |
c19d1205 | 3523 | literal_pool * pool; |
8335d6aa | 3524 | unsigned int entry, pool_size = 0; |
5b7c81bd | 3525 | bool padding_slot_p = false; |
e56c722b | 3526 | unsigned imm1 = 0; |
8335d6aa JW |
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 | |
e2b0ab59 | 3533 | : inst.relocs[0].exp.X_unsigned ? 0 |
2569ceb0 | 3534 | : ((bfd_int64_t) inst.operands[1].imm) >> 32); |
8335d6aa JW |
3535 | if (target_big_endian) |
3536 | { | |
3537 | imm1 = imm2; | |
3538 | imm2 = inst.operands[1].imm; | |
3539 | } | |
3540 | } | |
b99bd4ef | 3541 | |
c19d1205 ZW |
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 ++) | |
b99bd4ef | 3546 | { |
8335d6aa JW |
3547 | if (nbytes == 4) |
3548 | { | |
e2b0ab59 AV |
3549 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3550 | && (inst.relocs[0].exp.X_op == O_constant) | |
8335d6aa | 3551 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3552 | == inst.relocs[0].exp.X_add_number) |
8335d6aa JW |
3553 | && (pool->literals[entry].X_md == nbytes) |
3554 | && (pool->literals[entry].X_unsigned | |
e2b0ab59 | 3555 | == inst.relocs[0].exp.X_unsigned)) |
8335d6aa JW |
3556 | break; |
3557 | ||
e2b0ab59 AV |
3558 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3559 | && (inst.relocs[0].exp.X_op == O_symbol) | |
8335d6aa | 3560 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3561 | == inst.relocs[0].exp.X_add_number) |
8335d6aa | 3562 | && (pool->literals[entry].X_add_symbol |
e2b0ab59 | 3563 | == inst.relocs[0].exp.X_add_symbol) |
8335d6aa | 3564 | && (pool->literals[entry].X_op_symbol |
e2b0ab59 | 3565 | == inst.relocs[0].exp.X_op_symbol) |
8335d6aa JW |
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) | |
19f2f6a9 | 3573 | && (pool->literals[entry].X_add_number == (offsetT) imm1) |
8335d6aa | 3574 | && (pool->literals[entry].X_unsigned |
e2b0ab59 | 3575 | == inst.relocs[0].exp.X_unsigned) |
8335d6aa | 3576 | && (pool->literals[entry + 1].X_op == O_constant) |
19f2f6a9 | 3577 | && (pool->literals[entry + 1].X_add_number == (offsetT) imm2) |
8335d6aa | 3578 | && (pool->literals[entry + 1].X_unsigned |
e2b0ab59 | 3579 | == inst.relocs[0].exp.X_unsigned)) |
c19d1205 ZW |
3580 | break; |
3581 | ||
8335d6aa JW |
3582 | padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT); |
3583 | if (padding_slot_p && (nbytes == 4)) | |
c19d1205 | 3584 | break; |
8335d6aa JW |
3585 | |
3586 | pool_size += 4; | |
b99bd4ef NC |
3587 | } |
3588 | ||
c19d1205 ZW |
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 | ||
8335d6aa JW |
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. */ | |
e2b0ab59 AV |
3611 | if (!(inst.relocs[0].exp.X_op == O_constant |
3612 | || inst.relocs[0].exp.X_op == O_big)) | |
8335d6aa JW |
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 | ||
e2b0ab59 | 3625 | pool->literals[entry] = inst.relocs[0].exp; |
a6684f0d | 3626 | pool->literals[entry].X_op = O_constant; |
8335d6aa JW |
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 | ||
e2b0ab59 | 3638 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3639 | pool->literals[entry].X_op = O_constant; |
3640 | pool->literals[entry].X_add_number = imm1; | |
e2b0ab59 | 3641 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa | 3642 | pool->literals[entry++].X_md = 4; |
e2b0ab59 | 3643 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3644 | pool->literals[entry].X_op = O_constant; |
3645 | pool->literals[entry].X_add_number = imm2; | |
e2b0ab59 | 3646 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa JW |
3647 | pool->literals[entry].X_md = 4; |
3648 | pool->alignment = 3; | |
3649 | pool->next_free_entry += 1; | |
3650 | } | |
3651 | else | |
3652 | { | |
e2b0ab59 | 3653 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3654 | pool->literals[entry].X_md = 4; |
3655 | } | |
3656 | ||
a8040cf2 NC |
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 | |
c19d1205 ZW |
3665 | pool->next_free_entry += 1; |
3666 | } | |
8335d6aa JW |
3667 | else if (padding_slot_p) |
3668 | { | |
e2b0ab59 | 3669 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3670 | pool->literals[entry].X_md = nbytes; |
3671 | } | |
b99bd4ef | 3672 | |
e2b0ab59 AV |
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; | |
b99bd4ef | 3676 | |
c19d1205 | 3677 | return SUCCESS; |
b99bd4ef NC |
3678 | } |
3679 | ||
5b7c81bd | 3680 | bool |
2e57ce7b | 3681 | tc_start_label_without_colon (void) |
2e6976a8 | 3682 | { |
5b7c81bd | 3683 | bool ret = true; |
2e6976a8 DG |
3684 | |
3685 | if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME) | |
3686 | { | |
2e57ce7b | 3687 | const char *label = input_line_pointer; |
2e6976a8 DG |
3688 | |
3689 | while (!is_end_of_line[(int) label[-1]]) | |
3690 | --label; | |
3691 | ||
3692 | if (*label == '.') | |
3693 | { | |
3694 | as_bad (_("Invalid label '%s'"), label); | |
5b7c81bd | 3695 | ret = false; |
2e6976a8 DG |
3696 | } |
3697 | ||
3698 | asmfunc_debug (label); | |
3699 | ||
3700 | asmfunc_state = WAITING_ENDASMFUNC; | |
3701 | } | |
3702 | ||
3703 | return ret; | |
3704 | } | |
3705 | ||
c19d1205 | 3706 | /* Can't use symbol_new here, so have to create a symbol and then at |
33eaf5de | 3707 | a later date assign it a value. That's what these functions do. */ |
e16bb312 | 3708 | |
c19d1205 ZW |
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 | { | |
e57e6ddc | 3716 | size_t name_length; |
c19d1205 | 3717 | char * preserved_copy_of_name; |
e16bb312 | 3718 | |
c19d1205 ZW |
3719 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3720 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3721 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3722 | |
c19d1205 ZW |
3723 | #ifdef tc_canonicalize_symbol_name |
3724 | preserved_copy_of_name = | |
3725 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3726 | #endif | |
b99bd4ef | 3727 | |
c19d1205 | 3728 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3729 | |
c19d1205 ZW |
3730 | S_SET_SEGMENT (symbolP, segment); |
3731 | S_SET_VALUE (symbolP, valu); | |
3732 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3733 | |
c19d1205 | 3734 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3735 | |
c19d1205 ZW |
3736 | /* Link to end of symbol chain. */ |
3737 | { | |
3738 | extern int symbol_table_frozen; | |
b99bd4ef | 3739 | |
c19d1205 ZW |
3740 | if (symbol_table_frozen) |
3741 | abort (); | |
3742 | } | |
b99bd4ef | 3743 | |
c19d1205 | 3744 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3745 | |
c19d1205 | 3746 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3747 | |
c19d1205 ZW |
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 */ | |
b99bd4ef NC |
3755 | } |
3756 | ||
c19d1205 ZW |
3757 | static void |
3758 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3759 | { |
c19d1205 ZW |
3760 | unsigned int entry; |
3761 | literal_pool * pool; | |
3762 | char sym_name[20]; | |
b99bd4ef | 3763 | |
c19d1205 ZW |
3764 | pool = find_literal_pool (); |
3765 | if (pool == NULL | |
3766 | || pool->symbol == NULL | |
3767 | || pool->next_free_entry == 0) | |
3768 | return; | |
b99bd4ef | 3769 | |
c19d1205 ZW |
3770 | /* Align pool as you have word accesses. |
3771 | Only make a frag if we have to. */ | |
3772 | if (!need_pass_2) | |
8335d6aa | 3773 | frag_align (pool->alignment, 0, 0); |
b99bd4ef | 3774 | |
c19d1205 | 3775 | record_alignment (now_seg, 2); |
b99bd4ef | 3776 | |
aaca88ef | 3777 | #ifdef OBJ_ELF |
47fc6e36 WN |
3778 | seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA; |
3779 | make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now); | |
aaca88ef | 3780 | #endif |
c19d1205 | 3781 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3782 | |
c19d1205 ZW |
3783 | symbol_locate (pool->symbol, sym_name, now_seg, |
3784 | (valueT) frag_now_fix (), frag_now); | |
3785 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3786 | |
c19d1205 | 3787 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3788 | |
c19d1205 ZW |
3789 | #if defined OBJ_COFF || defined OBJ_ELF |
3790 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3791 | #endif | |
6c43fab6 | 3792 | |
c19d1205 | 3793 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
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. */ | |
8335d6aa JW |
3800 | emit_expr (&(pool->literals[entry]), |
3801 | pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK); | |
a8040cf2 | 3802 | } |
b99bd4ef | 3803 | |
c19d1205 ZW |
3804 | /* Mark the pool as empty. */ |
3805 | pool->next_free_entry = 0; | |
3806 | pool->symbol = NULL; | |
b99bd4ef NC |
3807 | } |
3808 | ||
c19d1205 ZW |
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); | |
b99bd4ef | 3817 | |
c19d1205 | 3818 | /* Directives: Data. */ |
b99bd4ef | 3819 | |
c19d1205 ZW |
3820 | static void |
3821 | s_arm_elf_cons (int nbytes) | |
3822 | { | |
3823 | expressionS exp; | |
b99bd4ef | 3824 | |
c19d1205 ZW |
3825 | #ifdef md_flush_pending_output |
3826 | md_flush_pending_output (); | |
3827 | #endif | |
b99bd4ef | 3828 | |
c19d1205 | 3829 | if (is_it_end_of_statement ()) |
b99bd4ef | 3830 | { |
c19d1205 ZW |
3831 | demand_empty_rest_of_line (); |
3832 | return; | |
b99bd4ef NC |
3833 | } |
3834 | ||
c19d1205 ZW |
3835 | #ifdef md_cons_align |
3836 | md_cons_align (nbytes); | |
3837 | #endif | |
b99bd4ef | 3838 | |
c19d1205 ZW |
3839 | mapping_state (MAP_DATA); |
3840 | do | |
b99bd4ef | 3841 | { |
c19d1205 ZW |
3842 | int reloc; |
3843 | char *base = input_line_pointer; | |
b99bd4ef | 3844 | |
c19d1205 | 3845 | expression (& exp); |
b99bd4ef | 3846 | |
c19d1205 ZW |
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 | { | |
21d799b5 | 3863 | reloc_howto_type *howto = (reloc_howto_type *) |
477330fc RM |
3864 | bfd_reloc_type_lookup (stdoutput, |
3865 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3866 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3867 | |
2fc8bdac ZW |
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 | ||
c19d1205 | 3875 | if (size > nbytes) |
992a06ee AM |
3876 | as_bad (ngettext ("%s relocations do not fit in %d byte", |
3877 | "%s relocations do not fit in %d bytes", | |
3878 | nbytes), | |
c19d1205 ZW |
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; | |
325801bd | 3888 | char *save_buf = XNEWVEC (char, input_line_pointer - base); |
e1fa0163 | 3889 | |
c19d1205 ZW |
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; | |
4b1a927e AM |
3899 | p = frag_more (nbytes); |
3900 | memset (p, 0, nbytes); | |
c19d1205 | 3901 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, |
21d799b5 | 3902 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
e1fa0163 | 3903 | free (save_buf); |
c19d1205 ZW |
3904 | } |
3905 | } | |
3906 | } | |
b99bd4ef | 3907 | } |
c19d1205 | 3908 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3909 | |
c19d1205 ZW |
3910 | /* Put terminator back into stream. */ |
3911 | input_line_pointer --; | |
3912 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3913 | } |
3914 | ||
c921be7d NC |
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 | ||
5b7c81bd | 3942 | static bool |
c921be7d NC |
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 | { | |
5ee91343 AV |
3964 | if (now_pred.state == AUTOMATIC_PRED_BLOCK) |
3965 | set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0); | |
c921be7d | 3966 | else |
5ee91343 | 3967 | set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); |
c921be7d NC |
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 | } | |
b99bd4ef | 4036 | |
c19d1205 | 4037 | /* Parse a .rel31 directive. */ |
b99bd4ef | 4038 | |
c19d1205 ZW |
4039 | static void |
4040 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
4041 | { | |
4042 | expressionS exp; | |
4043 | char *p; | |
4044 | valueT highbit; | |
b99bd4ef | 4045 | |
c19d1205 ZW |
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")); | |
b99bd4ef | 4051 | |
c19d1205 ZW |
4052 | input_line_pointer++; |
4053 | if (*input_line_pointer != ',') | |
4054 | as_bad (_("missing comma")); | |
4055 | input_line_pointer++; | |
b99bd4ef | 4056 | |
c19d1205 ZW |
4057 | #ifdef md_flush_pending_output |
4058 | md_flush_pending_output (); | |
4059 | #endif | |
b99bd4ef | 4060 | |
c19d1205 ZW |
4061 | #ifdef md_cons_align |
4062 | md_cons_align (4); | |
4063 | #endif | |
b99bd4ef | 4064 | |
c19d1205 | 4065 | mapping_state (MAP_DATA); |
b99bd4ef | 4066 | |
c19d1205 | 4067 | expression (&exp); |
b99bd4ef | 4068 | |
c19d1205 ZW |
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); | |
b99bd4ef | 4073 | |
c19d1205 | 4074 | demand_empty_rest_of_line (); |
b99bd4ef NC |
4075 | } |
4076 | ||
c19d1205 | 4077 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 4078 | |
c19d1205 | 4079 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 4080 | |
c19d1205 ZW |
4081 | static void |
4082 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
4083 | { | |
4084 | demand_empty_rest_of_line (); | |
921e5f0a PB |
4085 | if (unwind.proc_start) |
4086 | { | |
c921be7d | 4087 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
4088 | return; |
4089 | } | |
4090 | ||
c19d1205 ZW |
4091 | /* Mark the start of the function. */ |
4092 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 4093 | |
c19d1205 ZW |
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; | |
fdfde340 | 4101 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
4102 | unwind.fp_used = 0; |
4103 | unwind.sp_restored = 0; | |
4104 | } | |
b99bd4ef | 4105 | |
b99bd4ef | 4106 | |
c19d1205 ZW |
4107 | /* Parse a handlerdata directive. Creates the exception handling table entry |
4108 | for the function. */ | |
b99bd4ef | 4109 | |
c19d1205 ZW |
4110 | static void |
4111 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
4112 | { | |
4113 | demand_empty_rest_of_line (); | |
921e5f0a | 4114 | if (!unwind.proc_start) |
c921be7d | 4115 | as_bad (MISSING_FNSTART); |
921e5f0a | 4116 | |
c19d1205 | 4117 | if (unwind.table_entry) |
6decc662 | 4118 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 4119 | |
c19d1205 ZW |
4120 | create_unwind_entry (1); |
4121 | } | |
a737bd4d | 4122 | |
c19d1205 | 4123 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 4124 | |
c19d1205 ZW |
4125 | static void |
4126 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
4127 | { | |
4128 | long where; | |
4129 | char *ptr; | |
4130 | valueT val; | |
940b5ce0 | 4131 | unsigned int marked_pr_dependency; |
f02232aa | 4132 | |
c19d1205 | 4133 | demand_empty_rest_of_line (); |
f02232aa | 4134 | |
921e5f0a PB |
4135 | if (!unwind.proc_start) |
4136 | { | |
c921be7d | 4137 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
4138 | return; |
4139 | } | |
4140 | ||
c19d1205 ZW |
4141 | /* Add eh table entry. */ |
4142 | if (unwind.table_entry == NULL) | |
4143 | val = create_unwind_entry (0); | |
4144 | else | |
4145 | val = 0; | |
f02232aa | 4146 | |
c19d1205 ZW |
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); | |
b99bd4ef | 4151 | |
c19d1205 | 4152 | ptr = frag_more (8); |
5011093d | 4153 | memset (ptr, 0, 8); |
c19d1205 | 4154 | where = frag_now_fix () - 8; |
f02232aa | 4155 | |
c19d1205 ZW |
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); | |
f02232aa | 4159 | |
c19d1205 ZW |
4160 | /* Indicate dependency on EHABI-defined personality routines to the |
4161 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
4162 | marked_pr_dependency |
4163 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
4164 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
4165 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
4166 | { | |
5f4273c7 NC |
4167 | static const char *const name[] = |
4168 | { | |
4169 | "__aeabi_unwind_cpp_pr0", | |
4170 | "__aeabi_unwind_cpp_pr1", | |
4171 | "__aeabi_unwind_cpp_pr2" | |
4172 | }; | |
c19d1205 ZW |
4173 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
4174 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 4175 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 4176 | |= 1 << unwind.personality_index; |
c19d1205 | 4177 | } |
f02232aa | 4178 | |
c19d1205 ZW |
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); | |
f02232aa | 4186 | |
c19d1205 ZW |
4187 | /* Restore the original section. */ |
4188 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
4189 | |
4190 | unwind.proc_start = NULL; | |
c19d1205 | 4191 | } |
f02232aa | 4192 | |
f02232aa | 4193 | |
c19d1205 | 4194 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 4195 | |
c19d1205 ZW |
4196 | static void |
4197 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
4198 | { | |
4199 | demand_empty_rest_of_line (); | |
921e5f0a | 4200 | if (!unwind.proc_start) |
c921be7d | 4201 | as_bad (MISSING_FNSTART); |
921e5f0a | 4202 | |
c19d1205 ZW |
4203 | if (unwind.personality_routine || unwind.personality_index != -1) |
4204 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 4205 | |
c19d1205 ZW |
4206 | unwind.personality_index = -2; |
4207 | } | |
b99bd4ef | 4208 | |
b99bd4ef | 4209 | |
c19d1205 | 4210 | /* Parse a personalityindex directive. */ |
b99bd4ef | 4211 | |
c19d1205 ZW |
4212 | static void |
4213 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
4214 | { | |
4215 | expressionS exp; | |
b99bd4ef | 4216 | |
921e5f0a | 4217 | if (!unwind.proc_start) |
c921be7d | 4218 | as_bad (MISSING_FNSTART); |
921e5f0a | 4219 | |
c19d1205 ZW |
4220 | if (unwind.personality_routine || unwind.personality_index != -1) |
4221 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 4222 | |
c19d1205 | 4223 | expression (&exp); |
b99bd4ef | 4224 | |
c19d1205 ZW |
4225 | if (exp.X_op != O_constant |
4226 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 4227 | { |
c19d1205 ZW |
4228 | as_bad (_("bad personality routine number")); |
4229 | ignore_rest_of_line (); | |
4230 | return; | |
b99bd4ef NC |
4231 | } |
4232 | ||
c19d1205 | 4233 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 4234 | |
c19d1205 ZW |
4235 | demand_empty_rest_of_line (); |
4236 | } | |
e16bb312 | 4237 | |
e16bb312 | 4238 | |
c19d1205 | 4239 | /* Parse a personality directive. */ |
e16bb312 | 4240 | |
c19d1205 ZW |
4241 | static void |
4242 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
4243 | { | |
4244 | char *name, *p, c; | |
a737bd4d | 4245 | |
921e5f0a | 4246 | if (!unwind.proc_start) |
c921be7d | 4247 | as_bad (MISSING_FNSTART); |
921e5f0a | 4248 | |
c19d1205 ZW |
4249 | if (unwind.personality_routine || unwind.personality_index != -1) |
4250 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 4251 | |
d02603dc | 4252 | c = get_symbol_name (& name); |
c19d1205 | 4253 | p = input_line_pointer; |
d02603dc NC |
4254 | if (c == '"') |
4255 | ++ input_line_pointer; | |
c19d1205 ZW |
4256 | unwind.personality_routine = symbol_find_or_make (name); |
4257 | *p = c; | |
4258 | demand_empty_rest_of_line (); | |
4259 | } | |
e16bb312 | 4260 | |
e16bb312 | 4261 | |
c19d1205 | 4262 | /* Parse a directive saving core registers. */ |
e16bb312 | 4263 | |
c19d1205 ZW |
4264 | static void |
4265 | s_arm_unwind_save_core (void) | |
e16bb312 | 4266 | { |
c19d1205 ZW |
4267 | valueT op; |
4268 | long range; | |
4269 | int n; | |
e16bb312 | 4270 | |
4b5a202f | 4271 | range = parse_reg_list (&input_line_pointer, REGLIST_RN); |
c19d1205 | 4272 | if (range == FAIL) |
e16bb312 | 4273 | { |
c19d1205 ZW |
4274 | as_bad (_("expected register list")); |
4275 | ignore_rest_of_line (); | |
4276 | return; | |
4277 | } | |
e16bb312 | 4278 | |
c19d1205 | 4279 | demand_empty_rest_of_line (); |
e16bb312 | 4280 | |
c19d1205 ZW |
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 | } | |
e16bb312 | 4292 | |
01ae4198 DJ |
4293 | /* Pop r4-r15. */ |
4294 | if (range & 0xfff0) | |
c19d1205 | 4295 | { |
01ae4198 DJ |
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 | } | |
0dd132b6 | 4311 | else |
01ae4198 DJ |
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 | } | |
c19d1205 | 4321 | } |
0dd132b6 | 4322 | |
c19d1205 ZW |
4323 | /* Pop r0-r3. */ |
4324 | if (range & 0xf) | |
4325 | { | |
4326 | op = 0xb100 | (range & 0xf); | |
4327 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
4328 | } |
4329 | ||
c19d1205 ZW |
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 | } | |
0dd132b6 NC |
4336 | } |
4337 | ||
c19d1205 ZW |
4338 | |
4339 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
4340 | |
4341 | static void | |
c19d1205 | 4342 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 4343 | { |
c19d1205 ZW |
4344 | expressionS exp; |
4345 | int num_regs; | |
4346 | valueT op; | |
b99bd4ef | 4347 | |
c19d1205 ZW |
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; | |
b99bd4ef | 4353 | |
c19d1205 | 4354 | if (exp.X_op != O_constant) |
b99bd4ef | 4355 | { |
c19d1205 ZW |
4356 | as_bad (_("expected , <constant>")); |
4357 | ignore_rest_of_line (); | |
b99bd4ef NC |
4358 | return; |
4359 | } | |
4360 | ||
c19d1205 ZW |
4361 | num_regs = exp.X_add_number; |
4362 | ||
4363 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 4364 | { |
c19d1205 ZW |
4365 | as_bad (_("number of registers must be in the range [1:4]")); |
4366 | ignore_rest_of_line (); | |
b99bd4ef NC |
4367 | return; |
4368 | } | |
4369 | ||
c19d1205 | 4370 | demand_empty_rest_of_line (); |
b99bd4ef | 4371 | |
c19d1205 ZW |
4372 | if (reg == 4) |
4373 | { | |
4374 | /* Short form. */ | |
4375 | op = 0xb4 | (num_regs - 1); | |
4376 | add_unwind_opcode (op, 1); | |
4377 | } | |
b99bd4ef NC |
4378 | else |
4379 | { | |
c19d1205 ZW |
4380 | /* Long form. */ |
4381 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
4382 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4383 | } |
c19d1205 | 4384 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
4385 | } |
4386 | ||
c19d1205 | 4387 | |
fa073d69 MS |
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; | |
5b7c81bd | 4398 | bool partial_match; |
fa073d69 | 4399 | |
efd6b359 AV |
4400 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D, |
4401 | &partial_match); | |
fa073d69 MS |
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; | |
9c2799c2 | 4429 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
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. */ | |
b99bd4ef NC |
4441 | |
4442 | static void | |
c19d1205 | 4443 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 4444 | { |
c19d1205 | 4445 | int count; |
ca3f61f7 | 4446 | unsigned int reg; |
c19d1205 | 4447 | valueT op; |
5b7c81bd | 4448 | bool partial_match; |
b99bd4ef | 4449 | |
efd6b359 AV |
4450 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D, |
4451 | &partial_match); | |
c19d1205 | 4452 | if (count == FAIL) |
b99bd4ef | 4453 | { |
c19d1205 ZW |
4454 | as_bad (_("expected register list")); |
4455 | ignore_rest_of_line (); | |
b99bd4ef NC |
4456 | return; |
4457 | } | |
4458 | ||
c19d1205 | 4459 | demand_empty_rest_of_line (); |
b99bd4ef | 4460 | |
c19d1205 | 4461 | if (reg == 8) |
b99bd4ef | 4462 | { |
c19d1205 ZW |
4463 | /* Short form. */ |
4464 | op = 0xb8 | (count - 1); | |
4465 | add_unwind_opcode (op, 1); | |
b99bd4ef | 4466 | } |
c19d1205 | 4467 | else |
b99bd4ef | 4468 | { |
c19d1205 ZW |
4469 | /* Long form. */ |
4470 | op = 0xb300 | (reg << 4) | (count - 1); | |
4471 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4472 | } |
c19d1205 ZW |
4473 | unwind.frame_size += count * 8 + 4; |
4474 | } | |
b99bd4ef | 4475 | |
b99bd4ef | 4476 | |
c19d1205 ZW |
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; | |
b99bd4ef | 4487 | |
c19d1205 ZW |
4488 | if (*input_line_pointer == '{') |
4489 | input_line_pointer++; | |
b99bd4ef | 4490 | |
c19d1205 | 4491 | do |
b99bd4ef | 4492 | { |
dcbf9037 | 4493 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 4494 | |
c19d1205 | 4495 | if (reg == FAIL) |
b99bd4ef | 4496 | { |
9b7132d3 | 4497 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 4498 | goto error; |
b99bd4ef NC |
4499 | } |
4500 | ||
c19d1205 ZW |
4501 | if (mask >> reg) |
4502 | as_tsktsk (_("register list not in ascending order")); | |
4503 | mask |= 1 << reg; | |
b99bd4ef | 4504 | |
c19d1205 ZW |
4505 | if (*input_line_pointer == '-') |
4506 | { | |
4507 | input_line_pointer++; | |
dcbf9037 | 4508 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
4509 | if (hi_reg == FAIL) |
4510 | { | |
9b7132d3 | 4511 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
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); | |
b99bd4ef | 4524 | |
d996d970 | 4525 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4526 | |
c19d1205 | 4527 | demand_empty_rest_of_line (); |
b99bd4ef | 4528 | |
708587a4 | 4529 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4530 | the list. */ |
4531 | flush_pending_unwind (); | |
b99bd4ef | 4532 | |
c19d1205 | 4533 | for (i = 0; i < 16; i++) |
b99bd4ef | 4534 | { |
c19d1205 ZW |
4535 | if (mask & (1 << i)) |
4536 | unwind.frame_size += 8; | |
b99bd4ef NC |
4537 | } |
4538 | ||
c19d1205 ZW |
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) | |
b99bd4ef | 4543 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 4562 | |
c19d1205 ZW |
4563 | op = 0xffff << (reg - 1); |
4564 | if (reg > 0 | |
87a1fd79 | 4565 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
4566 | { |
4567 | op = (1 << (reg + i + 1)) - 1; | |
4568 | op &= ~((1 << reg) - 1); | |
4569 | mask |= op; | |
4570 | unwind.opcode_count -= 2; | |
4571 | } | |
4572 | } | |
4573 | } | |
b99bd4ef NC |
4574 | } |
4575 | ||
c19d1205 ZW |
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--) | |
b99bd4ef | 4580 | { |
c19d1205 ZW |
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 | |
5f4273c7 | 4586 | preceding block. */ |
c19d1205 ZW |
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 | } | |
b99bd4ef NC |
4604 | } |
4605 | ||
c19d1205 | 4606 | return; |
dc1e8a47 | 4607 | error: |
c19d1205 | 4608 | ignore_rest_of_line (); |
b99bd4ef NC |
4609 | } |
4610 | ||
4611 | static void | |
c19d1205 | 4612 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4613 | { |
c19d1205 ZW |
4614 | int reg; |
4615 | int hi_reg; | |
4616 | unsigned mask = 0; | |
4617 | valueT op; | |
b99bd4ef | 4618 | |
c19d1205 ZW |
4619 | if (*input_line_pointer == '{') |
4620 | input_line_pointer++; | |
b99bd4ef | 4621 | |
477330fc RM |
4622 | skip_whitespace (input_line_pointer); |
4623 | ||
c19d1205 | 4624 | do |
b99bd4ef | 4625 | { |
dcbf9037 | 4626 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4627 | |
c19d1205 ZW |
4628 | if (reg == FAIL) |
4629 | { | |
9b7132d3 | 4630 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4631 | goto error; |
4632 | } | |
b99bd4ef | 4633 | |
c19d1205 ZW |
4634 | reg -= 8; |
4635 | if (mask >> reg) | |
4636 | as_tsktsk (_("register list not in ascending order")); | |
4637 | mask |= 1 << reg; | |
b99bd4ef | 4638 | |
c19d1205 ZW |
4639 | if (*input_line_pointer == '-') |
4640 | { | |
4641 | input_line_pointer++; | |
dcbf9037 | 4642 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4643 | if (hi_reg == FAIL) |
4644 | { | |
9b7132d3 | 4645 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
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 | } | |
b99bd4ef | 4656 | } |
c19d1205 | 4657 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4658 | |
d996d970 | 4659 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4660 | |
c19d1205 ZW |
4661 | demand_empty_rest_of_line (); |
4662 | ||
708587a4 | 4663 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4664 | the list. */ |
4665 | flush_pending_unwind (); | |
b99bd4ef | 4666 | |
c19d1205 | 4667 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4668 | { |
c19d1205 ZW |
4669 | if (mask & (1 << reg)) |
4670 | unwind.frame_size += 4; | |
b99bd4ef | 4671 | } |
c19d1205 ZW |
4672 | op = 0xc700 | mask; |
4673 | add_unwind_opcode (op, 2); | |
4674 | return; | |
dc1e8a47 | 4675 | error: |
c19d1205 | 4676 | ignore_rest_of_line (); |
b99bd4ef NC |
4677 | } |
4678 | ||
c19d1205 | 4679 | |
fa073d69 MS |
4680 | /* Parse an unwind_save directive. |
4681 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4682 | |
b99bd4ef | 4683 | static void |
fa073d69 | 4684 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4685 | { |
c19d1205 ZW |
4686 | char *peek; |
4687 | struct reg_entry *reg; | |
5b7c81bd | 4688 | bool had_brace = false; |
b99bd4ef | 4689 | |
921e5f0a | 4690 | if (!unwind.proc_start) |
c921be7d | 4691 | as_bad (MISSING_FNSTART); |
921e5f0a | 4692 | |
c19d1205 ZW |
4693 | /* Figure out what sort of save we have. */ |
4694 | peek = input_line_pointer; | |
b99bd4ef | 4695 | |
c19d1205 | 4696 | if (*peek == '{') |
b99bd4ef | 4697 | { |
5b7c81bd | 4698 | had_brace = true; |
c19d1205 | 4699 | peek++; |
b99bd4ef NC |
4700 | } |
4701 | ||
c19d1205 | 4702 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4703 | |
c19d1205 | 4704 | if (!reg) |
b99bd4ef | 4705 | { |
c19d1205 ZW |
4706 | as_bad (_("register expected")); |
4707 | ignore_rest_of_line (); | |
b99bd4ef NC |
4708 | return; |
4709 | } | |
4710 | ||
c19d1205 | 4711 | switch (reg->type) |
b99bd4ef | 4712 | { |
c19d1205 ZW |
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 | } | |
93ac2687 | 4720 | input_line_pointer = peek; |
c19d1205 | 4721 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4722 | return; |
c19d1205 | 4723 | |
1f5afe1c NC |
4724 | case REG_TYPE_RN: |
4725 | s_arm_unwind_save_core (); | |
4726 | return; | |
4727 | ||
fa073d69 MS |
4728 | case REG_TYPE_VFD: |
4729 | if (arch_v6) | |
477330fc | 4730 | s_arm_unwind_save_vfp_armv6 (); |
fa073d69 | 4731 | else |
477330fc | 4732 | s_arm_unwind_save_vfp (); |
fa073d69 | 4733 | return; |
1f5afe1c NC |
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; | |
c19d1205 ZW |
4742 | |
4743 | default: | |
4744 | as_bad (_(".unwind_save does not support this kind of register")); | |
4745 | ignore_rest_of_line (); | |
b99bd4ef | 4746 | } |
c19d1205 | 4747 | } |
b99bd4ef | 4748 | |
b99bd4ef | 4749 | |
c19d1205 ZW |
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; | |
4fa3602b | 4757 | int offset; |
c19d1205 | 4758 | |
921e5f0a | 4759 | if (!unwind.proc_start) |
c921be7d | 4760 | as_bad (MISSING_FNSTART); |
921e5f0a | 4761 | |
dcbf9037 | 4762 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4763 | if (reg == FAIL) |
b99bd4ef | 4764 | { |
9b7132d3 | 4765 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4766 | ignore_rest_of_line (); |
b99bd4ef NC |
4767 | return; |
4768 | } | |
4fa3602b PB |
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 | ||
c19d1205 | 4779 | demand_empty_rest_of_line (); |
b99bd4ef | 4780 | |
c19d1205 | 4781 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4782 | { |
c19d1205 | 4783 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4784 | return; |
4785 | } | |
4786 | ||
c19d1205 ZW |
4787 | if (unwind.fp_reg != REG_SP) |
4788 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4789 | |
c19d1205 ZW |
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; | |
4fa3602b | 4796 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4797 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4798 | } |
4799 | ||
c19d1205 ZW |
4800 | /* Parse an unwind_pad directive. */ |
4801 | ||
b05fe5cf | 4802 | static void |
c19d1205 | 4803 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4804 | { |
c19d1205 | 4805 | int offset; |
b05fe5cf | 4806 | |
921e5f0a | 4807 | if (!unwind.proc_start) |
c921be7d | 4808 | as_bad (MISSING_FNSTART); |
921e5f0a | 4809 | |
c19d1205 ZW |
4810 | if (immediate_for_directive (&offset) == FAIL) |
4811 | return; | |
b99bd4ef | 4812 | |
c19d1205 ZW |
4813 | if (offset & 3) |
4814 | { | |
4815 | as_bad (_("stack increment must be multiple of 4")); | |
4816 | ignore_rest_of_line (); | |
4817 | return; | |
4818 | } | |
b99bd4ef | 4819 | |
c19d1205 ZW |
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) | |
b99bd4ef | 4831 | { |
c19d1205 ZW |
4832 | int sp_reg; |
4833 | int fp_reg; | |
4834 | int offset; | |
4835 | ||
921e5f0a | 4836 | if (!unwind.proc_start) |
c921be7d | 4837 | as_bad (MISSING_FNSTART); |
921e5f0a | 4838 | |
dcbf9037 | 4839 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4840 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4841 | sp_reg = FAIL; | |
4842 | else | |
dcbf9037 | 4843 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4844 | |
c19d1205 ZW |
4845 | if (fp_reg == FAIL || sp_reg == FAIL) |
4846 | { | |
4847 | as_bad (_("expected <reg>, <reg>")); | |
4848 | ignore_rest_of_line (); | |
4849 | return; | |
4850 | } | |
b99bd4ef | 4851 | |
c19d1205 ZW |
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; | |
a737bd4d | 4860 | |
c19d1205 | 4861 | demand_empty_rest_of_line (); |
a737bd4d | 4862 | |
fdfde340 | 4863 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4864 | { |
c19d1205 ZW |
4865 | as_bad (_("register must be either sp or set by a previous" |
4866 | "unwind_movsp directive")); | |
4867 | return; | |
a737bd4d NC |
4868 | } |
4869 | ||
c19d1205 ZW |
4870 | /* Don't generate any opcodes, just record the information for later. */ |
4871 | unwind.fp_reg = fp_reg; | |
4872 | unwind.fp_used = 1; | |
fdfde340 | 4873 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4874 | unwind.fp_offset = unwind.frame_size - offset; |
4875 | else | |
4876 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4877 | } |
4878 | ||
c19d1205 ZW |
4879 | /* Parse an unwind_raw directive. */ |
4880 | ||
4881 | static void | |
4882 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4883 | { |
c19d1205 | 4884 | expressionS exp; |
708587a4 | 4885 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4886 | unsigned char op[16]; |
4887 | int count; | |
a737bd4d | 4888 | |
921e5f0a | 4889 | if (!unwind.proc_start) |
c921be7d | 4890 | as_bad (MISSING_FNSTART); |
921e5f0a | 4891 | |
c19d1205 ZW |
4892 | expression (&exp); |
4893 | if (exp.X_op == O_constant | |
4894 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4895 | { |
c19d1205 ZW |
4896 | unwind.frame_size += exp.X_add_number; |
4897 | expression (&exp); | |
4898 | } | |
4899 | else | |
4900 | exp.X_op = O_illegal; | |
a737bd4d | 4901 | |
c19d1205 ZW |
4902 | if (exp.X_op != O_constant) |
4903 | { | |
4904 | as_bad (_("expected <offset>, <opcode>")); | |
4905 | ignore_rest_of_line (); | |
4906 | return; | |
4907 | } | |
a737bd4d | 4908 | |
c19d1205 | 4909 | count = 0; |
a737bd4d | 4910 | |
c19d1205 ZW |
4911 | /* Parse the opcode. */ |
4912 | for (;;) | |
4913 | { | |
4914 | if (count >= 16) | |
4915 | { | |
4916 | as_bad (_("unwind opcode too long")); | |
4917 | ignore_rest_of_line (); | |
a737bd4d | 4918 | } |
c19d1205 | 4919 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4920 | { |
c19d1205 ZW |
4921 | as_bad (_("invalid unwind opcode")); |
4922 | ignore_rest_of_line (); | |
4923 | return; | |
a737bd4d | 4924 | } |
c19d1205 | 4925 | op[count++] = exp.X_add_number; |
a737bd4d | 4926 | |
c19d1205 ZW |
4927 | /* Parse the next byte. */ |
4928 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4929 | break; | |
a737bd4d | 4930 | |
c19d1205 ZW |
4931 | expression (&exp); |
4932 | } | |
b99bd4ef | 4933 | |
c19d1205 ZW |
4934 | /* Add the opcode bytes in reverse order. */ |
4935 | while (count--) | |
4936 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4937 | |
c19d1205 | 4938 | demand_empty_rest_of_line (); |
b99bd4ef | 4939 | } |
ee065d83 PB |
4940 | |
4941 | ||
4942 | /* Parse a .eabi_attribute directive. */ | |
4943 | ||
4944 | static void | |
4945 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4946 | { | |
0420f52b | 4947 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 | 4948 | |
3076e594 | 4949 | if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES) |
ee3c0378 | 4950 | attributes_set_explicitly[tag] = 1; |
ee065d83 PB |
4951 | } |
4952 | ||
0855e32b NS |
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 | } | |
cdf9ccec | 4976 | #endif /* OBJ_ELF */ |
0855e32b | 4977 | |
ee065d83 | 4978 | static void s_arm_arch (int); |
7a1d4c38 | 4979 | static void s_arm_object_arch (int); |
ee065d83 PB |
4980 | static void s_arm_cpu (int); |
4981 | static void s_arm_fpu (int); | |
69133863 | 4982 | static void s_arm_arch_extension (int); |
b99bd4ef | 4983 | |
f0927246 NC |
4984 | #ifdef TE_PE |
4985 | ||
4986 | static void | |
5f4273c7 | 4987 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
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 | ||
5312fe52 BW |
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 | ||
dc1e8a47 | 5050 | cleanup: |
5312fe52 BW |
5051 | *input_line_pointer = saved_char; |
5052 | ignore_rest_of_line (); | |
5053 | } | |
5054 | ||
c19d1205 ZW |
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. */ | |
b99bd4ef | 5060 | |
c19d1205 | 5061 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 5062 | { |
c19d1205 ZW |
5063 | /* Never called because '.req' does not start a line. */ |
5064 | { "req", s_req, 0 }, | |
dcbf9037 JB |
5065 | /* Following two are likewise never called. */ |
5066 | { "dn", s_dn, 0 }, | |
5067 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
5068 | { "unreq", s_unreq, 0 }, |
5069 | { "bss", s_bss, 0 }, | |
db2ed2e0 | 5070 | { "align", s_align_ptwo, 2 }, |
c19d1205 ZW |
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 }, | |
8463be01 PB |
5081 | { "cpu", s_arm_cpu, 0 }, |
5082 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 5083 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 5084 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 5085 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 5086 | #ifdef OBJ_ELF |
c921be7d NC |
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 }, | |
c19d1205 ZW |
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 }, | |
fa073d69 | 5100 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
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 }, | |
ee065d83 | 5105 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 5106 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
5107 | #else |
5108 | { "word", cons, 4}, | |
f0927246 NC |
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. */ | |
68d20676 | 5115 | { "file", dwarf2_directive_file, 0 }, |
f0927246 NC |
5116 | { "loc", dwarf2_directive_loc, 0 }, |
5117 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
5118 | #endif |
5119 | { "extend", float_cons, 'x' }, | |
5120 | { "ldouble", float_cons, 'x' }, | |
5121 | { "packed", float_cons, 'p' }, | |
27cce866 | 5122 | { "bfloat16", float_cons, 'b' }, |
f0927246 NC |
5123 | #ifdef TE_PE |
5124 | {"secrel32", pe_directive_secrel, 0}, | |
5125 | #endif | |
2e6976a8 DG |
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 | ||
5312fe52 BW |
5133 | {"float16", float_cons, 'h' }, |
5134 | {"float16_format", set_fp16_format, 0 }, | |
5135 | ||
c19d1205 ZW |
5136 | { 0, 0, 0 } |
5137 | }; | |
5312fe52 | 5138 | |
c19d1205 | 5139 | /* Parser functions used exclusively in instruction operands. */ |
b99bd4ef | 5140 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 5146 | |
c19d1205 ZW |
5147 | static int |
5148 | parse_immediate (char **str, int *val, int min, int max, | |
5b7c81bd | 5149 | bool prefix_opt) |
c19d1205 ZW |
5150 | { |
5151 | expressionS exp; | |
0198d5e6 | 5152 | |
c19d1205 ZW |
5153 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); |
5154 | if (exp.X_op != O_constant) | |
b99bd4ef | 5155 | { |
c19d1205 ZW |
5156 | inst.error = _("constant expression required"); |
5157 | return FAIL; | |
5158 | } | |
b99bd4ef | 5159 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 5165 | |
c19d1205 ZW |
5166 | *val = exp.X_add_number; |
5167 | return SUCCESS; | |
5168 | } | |
b99bd4ef | 5169 | |
5287ad62 | 5170 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 5171 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
5172 | instructions. Puts the result directly in inst.operands[i]. */ |
5173 | ||
5174 | static int | |
8335d6aa | 5175 | parse_big_immediate (char **str, int i, expressionS *in_exp, |
5b7c81bd | 5176 | bool allow_symbol_p) |
5287ad62 JB |
5177 | { |
5178 | expressionS exp; | |
8335d6aa | 5179 | expressionS *exp_p = in_exp ? in_exp : &exp; |
5287ad62 JB |
5180 | char *ptr = *str; |
5181 | ||
8335d6aa | 5182 | my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG); |
5287ad62 | 5183 | |
8335d6aa | 5184 | if (exp_p->X_op == O_constant) |
036dc3f7 | 5185 | { |
8335d6aa | 5186 | inst.operands[i].imm = exp_p->X_add_number & 0xffffffff; |
036dc3f7 PB |
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. */ | |
8335d6aa | 5190 | if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 | 5191 | { |
8335d6aa JW |
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); | |
036dc3f7 PB |
5195 | inst.operands[i].regisimm = 1; |
5196 | } | |
5197 | } | |
8335d6aa JW |
5198 | else if (exp_p->X_op == O_big |
5199 | && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32) | |
5287ad62 JB |
5200 | { |
5201 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 5202 | |
5287ad62 | 5203 | /* Bignums have their least significant bits in |
477330fc RM |
5204 | generic_bignum[0]. Make sure we put 32 bits in imm and |
5205 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 5206 | gas_assert (parts != 0); |
95b75c01 NC |
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. */ | |
8335d6aa | 5212 | if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64) |
95b75c01 NC |
5213 | { |
5214 | LITTLENUM_TYPE m = -1; | |
5215 | ||
5216 | if (generic_bignum[parts * 2] != 0 | |
5217 | && generic_bignum[parts * 2] != m) | |
5218 | return FAIL; | |
5219 | ||
8335d6aa | 5220 | for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++) |
95b75c01 NC |
5221 | if (generic_bignum[j] != generic_bignum[j-1]) |
5222 | return FAIL; | |
5223 | } | |
5224 | ||
5287ad62 JB |
5225 | inst.operands[i].imm = 0; |
5226 | for (j = 0; j < parts; j++, idx++) | |
7af67752 AM |
5227 | inst.operands[i].imm |= ((unsigned) generic_bignum[idx] |
5228 | << (LITTLENUM_NUMBER_OF_BITS * j)); | |
5287ad62 JB |
5229 | inst.operands[i].reg = 0; |
5230 | for (j = 0; j < parts; j++, idx++) | |
7af67752 AM |
5231 | inst.operands[i].reg |= ((unsigned) generic_bignum[idx] |
5232 | << (LITTLENUM_NUMBER_OF_BITS * j)); | |
5287ad62 JB |
5233 | inst.operands[i].regisimm = 1; |
5234 | } | |
8335d6aa | 5235 | else if (!(exp_p->X_op == O_symbol && allow_symbol_p)) |
5287ad62 | 5236 | return FAIL; |
5f4273c7 | 5237 | |
5287ad62 JB |
5238 | *str = ptr; |
5239 | ||
5240 | return SUCCESS; | |
5241 | } | |
5242 | ||
c19d1205 ZW |
5243 | /* Returns the pseudo-register number of an FPA immediate constant, |
5244 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 5245 | |
c19d1205 ZW |
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; | |
b99bd4ef | 5254 | |
c19d1205 ZW |
5255 | /* First try and match exact strings, this is to guarantee |
5256 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 5257 | |
c19d1205 ZW |
5258 | for (i = 0; fp_const[i]; i++) |
5259 | { | |
5260 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 5261 | { |
c19d1205 | 5262 | char *start = *str; |
b99bd4ef | 5263 | |
c19d1205 ZW |
5264 | *str += strlen (fp_const[i]); |
5265 | if (is_end_of_line[(unsigned char) **str]) | |
5266 | return i + 8; | |
5267 | *str = start; | |
5268 | } | |
5269 | } | |
b99bd4ef | 5270 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 5275 | |
c19d1205 | 5276 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 5277 | |
c19d1205 ZW |
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++) | |
b99bd4ef | 5285 | { |
c19d1205 ZW |
5286 | if (words[j] != fp_values[i][j]) |
5287 | break; | |
b99bd4ef NC |
5288 | } |
5289 | ||
c19d1205 | 5290 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 5291 | { |
c19d1205 ZW |
5292 | *str = save_in; |
5293 | return i + 8; | |
b99bd4ef NC |
5294 | } |
5295 | } | |
5296 | } | |
b99bd4ef | 5297 | |
c19d1205 ZW |
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. */ | |
ba592044 AM |
5308 | #define X_PRECISION 5 |
5309 | #define E_PRECISION 15L | |
5310 | if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0) | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 5319 | |
c19d1205 ZW |
5320 | if (j == MAX_LITTLENUMS) |
5321 | { | |
5322 | *str = input_line_pointer; | |
5323 | input_line_pointer = save_in; | |
5324 | return i + 8; | |
5325 | } | |
5326 | } | |
5327 | } | |
b99bd4ef NC |
5328 | } |
5329 | ||
c19d1205 ZW |
5330 | *str = input_line_pointer; |
5331 | input_line_pointer = save_in; | |
5332 | inst.error = _("invalid FPA immediate expression"); | |
5333 | return FAIL; | |
b99bd4ef NC |
5334 | } |
5335 | ||
136da414 JB |
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 | ||
aacf0b33 KT |
5346 | |
5347 | /* Detect the presence of a floating point or integer zero constant, | |
5348 | i.e. #0.0 or #0. */ | |
5349 | ||
5b7c81bd | 5350 | static bool |
aacf0b33 KT |
5351 | parse_ifimm_zero (char **in) |
5352 | { | |
5353 | int error_code; | |
5354 | ||
5355 | if (!is_immediate_prefix (**in)) | |
3c6452ae TP |
5356 | { |
5357 | /* In unified syntax, all prefixes are optional. */ | |
5358 | if (!unified_syntax) | |
5b7c81bd | 5359 | return false; |
3c6452ae TP |
5360 | } |
5361 | else | |
5362 | ++*in; | |
0900a05b JW |
5363 | |
5364 | /* Accept #0x0 as a synonym for #0. */ | |
d34049e8 | 5365 | if (startswith (*in, "0x")) |
0900a05b JW |
5366 | { |
5367 | int val; | |
5b7c81bd AM |
5368 | if (parse_immediate (in, &val, 0, 0, true) == FAIL) |
5369 | return false; | |
5370 | return true; | |
0900a05b JW |
5371 | } |
5372 | ||
aacf0b33 KT |
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)) | |
5b7c81bd | 5380 | return true; |
aacf0b33 | 5381 | |
5b7c81bd | 5382 | return false; |
aacf0b33 KT |
5383 | } |
5384 | ||
136da414 JB |
5385 | /* Parse an 8-bit "quarter-precision" floating point number of the form: |
5386 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
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. */ | |
136da414 JB |
5390 | |
5391 | static unsigned | |
5392 | parse_qfloat_immediate (char **ccp, int *immed) | |
5393 | { | |
5394 | char *str = *ccp; | |
c96612cc | 5395 | char *fpnum; |
136da414 | 5396 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 5397 | int found_fpchar = 0; |
5f4273c7 | 5398 | |
136da414 | 5399 | skip_past_char (&str, '#'); |
5f4273c7 | 5400 | |
c96612cc JB |
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 | ||
d34049e8 | 5409 | if (startswith (fpnum, "0x")) |
c96612cc JB |
5410 | return FAIL; |
5411 | else | |
5412 | { | |
5413 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
477330fc RM |
5414 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
5415 | { | |
5416 | found_fpchar = 1; | |
5417 | break; | |
5418 | } | |
c96612cc JB |
5419 | |
5420 | if (!found_fpchar) | |
477330fc | 5421 | return FAIL; |
c96612cc | 5422 | } |
5f4273c7 | 5423 | |
136da414 JB |
5424 | if ((str = atof_ieee (str, 's', words)) != NULL) |
5425 | { | |
5426 | unsigned fpword = 0; | |
5427 | int i; | |
5f4273c7 | 5428 | |
136da414 JB |
5429 | /* Our FP word must be 32 bits (single-precision FP). */ |
5430 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
477330fc RM |
5431 | { |
5432 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
5433 | fpword |= words[i]; | |
5434 | } | |
5f4273c7 | 5435 | |
c96612cc | 5436 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
477330fc | 5437 | *immed = fpword; |
136da414 | 5438 | else |
477330fc | 5439 | return FAIL; |
136da414 JB |
5440 | |
5441 | *ccp = str; | |
5f4273c7 | 5442 | |
136da414 JB |
5443 | return SUCCESS; |
5444 | } | |
5f4273c7 | 5445 | |
136da414 JB |
5446 | return FAIL; |
5447 | } | |
5448 | ||
c19d1205 ZW |
5449 | /* Shift operands. */ |
5450 | enum shift_kind | |
b99bd4ef | 5451 | { |
f5f10c66 | 5452 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW |
c19d1205 | 5453 | }; |
b99bd4ef | 5454 | |
c19d1205 ZW |
5455 | struct asm_shift_name |
5456 | { | |
5457 | const char *name; | |
5458 | enum shift_kind kind; | |
5459 | }; | |
b99bd4ef | 5460 | |
c19d1205 ZW |
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. */ | |
f5f10c66 | 5469 | SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */ |
c19d1205 | 5470 | }; |
b99bd4ef | 5471 | |
c19d1205 ZW |
5472 | /* Parse a <shift> specifier on an ARM data processing instruction. |
5473 | This has three forms: | |
b99bd4ef | 5474 | |
c19d1205 ZW |
5475 | (LSL|LSR|ASL|ASR|ROR) Rs |
5476 | (LSL|LSR|ASL|ASR|ROR) #imm | |
5477 | RRX | |
b99bd4ef | 5478 | |
c19d1205 ZW |
5479 | Note that ASL is assimilated to LSL in the instruction encoding, and |
5480 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 5481 | |
c19d1205 ZW |
5482 | static int |
5483 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 5484 | { |
c19d1205 ZW |
5485 | const struct asm_shift_name *shift_name; |
5486 | enum shift_kind shift; | |
5487 | char *s = *str; | |
5488 | char *p = s; | |
5489 | int reg; | |
b99bd4ef | 5490 | |
c19d1205 ZW |
5491 | for (p = *str; ISALPHA (*p); p++) |
5492 | ; | |
b99bd4ef | 5493 | |
c19d1205 | 5494 | if (p == *str) |
b99bd4ef | 5495 | { |
c19d1205 ZW |
5496 | inst.error = _("shift expression expected"); |
5497 | return FAIL; | |
b99bd4ef NC |
5498 | } |
5499 | ||
fe0e921f AM |
5500 | shift_name |
5501 | = (const struct asm_shift_name *) str_hash_find_n (arm_shift_hsh, *str, | |
5502 | p - *str); | |
c19d1205 ZW |
5503 | |
5504 | if (shift_name == NULL) | |
b99bd4ef | 5505 | { |
c19d1205 ZW |
5506 | inst.error = _("shift expression expected"); |
5507 | return FAIL; | |
b99bd4ef NC |
5508 | } |
5509 | ||
c19d1205 | 5510 | shift = shift_name->kind; |
b99bd4ef | 5511 | |
c19d1205 ZW |
5512 | switch (mode) |
5513 | { | |
5514 | case NO_SHIFT_RESTRICT: | |
f5f10c66 AV |
5515 | case SHIFT_IMMEDIATE: |
5516 | if (shift == SHIFT_UXTW) | |
5517 | { | |
5518 | inst.error = _("'UXTW' not allowed here"); | |
5519 | return FAIL; | |
5520 | } | |
5521 | break; | |
b99bd4ef | 5522 | |
c19d1205 ZW |
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; | |
b99bd4ef | 5530 | |
c19d1205 ZW |
5531 | case SHIFT_LSL_IMMEDIATE: |
5532 | if (shift != SHIFT_LSL) | |
5533 | { | |
5534 | inst.error = _("'LSL' required"); | |
5535 | return FAIL; | |
5536 | } | |
5537 | break; | |
b99bd4ef | 5538 | |
c19d1205 ZW |
5539 | case SHIFT_ASR_IMMEDIATE: |
5540 | if (shift != SHIFT_ASR) | |
5541 | { | |
5542 | inst.error = _("'ASR' required"); | |
5543 | return FAIL; | |
5544 | } | |
5545 | break; | |
f5f10c66 AV |
5546 | case SHIFT_UXTW_IMMEDIATE: |
5547 | if (shift != SHIFT_UXTW) | |
5548 | { | |
5549 | inst.error = _("'UXTW' required"); | |
5550 | return FAIL; | |
5551 | } | |
5552 | break; | |
b99bd4ef | 5553 | |
c19d1205 ZW |
5554 | default: abort (); |
5555 | } | |
b99bd4ef | 5556 | |
c19d1205 ZW |
5557 | if (shift != SHIFT_RRX) |
5558 | { | |
5559 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
5560 | skip_whitespace (p); | |
b99bd4ef | 5561 | |
c19d1205 | 5562 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 5563 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5564 | { |
5565 | inst.operands[i].imm = reg; | |
5566 | inst.operands[i].immisreg = 1; | |
5567 | } | |
e2b0ab59 | 5568 | else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
c19d1205 ZW |
5569 | return FAIL; |
5570 | } | |
5571 | inst.operands[i].shift_kind = shift; | |
5572 | inst.operands[i].shifted = 1; | |
5573 | *str = p; | |
5574 | return SUCCESS; | |
b99bd4ef NC |
5575 | } |
5576 | ||
c19d1205 | 5577 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 5578 | |
c19d1205 ZW |
5579 | #<immediate> |
5580 | #<immediate>, <rotate> | |
5581 | <Rm> | |
5582 | <Rm>, <shift> | |
b99bd4ef | 5583 | |
c19d1205 ZW |
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 | |
55cf6793 | 5586 | is deferred to md_apply_fix. */ |
b99bd4ef | 5587 | |
c19d1205 ZW |
5588 | static int |
5589 | parse_shifter_operand (char **str, int i) | |
5590 | { | |
5591 | int value; | |
91d6fa6a | 5592 | expressionS exp; |
b99bd4ef | 5593 | |
dcbf9037 | 5594 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5595 | { |
5596 | inst.operands[i].reg = value; | |
5597 | inst.operands[i].isreg = 1; | |
b99bd4ef | 5598 | |
c19d1205 | 5599 | /* parse_shift will override this if appropriate */ |
e2b0ab59 AV |
5600 | inst.relocs[0].exp.X_op = O_constant; |
5601 | inst.relocs[0].exp.X_add_number = 0; | |
b99bd4ef | 5602 | |
c19d1205 ZW |
5603 | if (skip_past_comma (str) == FAIL) |
5604 | return SUCCESS; | |
b99bd4ef | 5605 | |
c19d1205 ZW |
5606 | /* Shift operation on register. */ |
5607 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
5608 | } |
5609 | ||
e2b0ab59 | 5610 | if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX)) |
c19d1205 | 5611 | return FAIL; |
b99bd4ef | 5612 | |
c19d1205 | 5613 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 5614 | { |
c19d1205 | 5615 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 5616 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 5617 | return FAIL; |
b99bd4ef | 5618 | |
e2b0ab59 | 5619 | if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant) |
c19d1205 ZW |
5620 | { |
5621 | inst.error = _("constant expression expected"); | |
5622 | return FAIL; | |
5623 | } | |
b99bd4ef | 5624 | |
91d6fa6a | 5625 | value = exp.X_add_number; |
c19d1205 ZW |
5626 | if (value < 0 || value > 30 || value % 2 != 0) |
5627 | { | |
5628 | inst.error = _("invalid rotation"); | |
5629 | return FAIL; | |
5630 | } | |
e2b0ab59 AV |
5631 | if (inst.relocs[0].exp.X_add_number < 0 |
5632 | || inst.relocs[0].exp.X_add_number > 255) | |
c19d1205 ZW |
5633 | { |
5634 | inst.error = _("invalid constant"); | |
5635 | return FAIL; | |
5636 | } | |
09d92015 | 5637 | |
a415b1cd | 5638 | /* Encode as specified. */ |
e2b0ab59 | 5639 | inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7; |
a415b1cd | 5640 | return SUCCESS; |
09d92015 MM |
5641 | } |
5642 | ||
e2b0ab59 AV |
5643 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
5644 | inst.relocs[0].pc_rel = 0; | |
c19d1205 | 5645 | return SUCCESS; |
09d92015 MM |
5646 | } |
5647 | ||
4962c51a MS |
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, | |
35c228db AV |
5670 | GROUP_LDC, |
5671 | GROUP_MVE | |
4962c51a MS |
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 */ | |
72d98d16 MG |
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. */ | |
4962c51a MS |
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 | ||
5f4273c7 NC |
5764 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5765 | && (*str)[length] == ':') | |
477330fc RM |
5766 | { |
5767 | *out = &group_reloc_table[i]; | |
5768 | *str += (length + 1); | |
5769 | return SUCCESS; | |
5770 | } | |
4962c51a MS |
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] == '#') | |
477330fc | 5803 | (*str) += 2; |
4962c51a | 5804 | else |
477330fc | 5805 | (*str)++; |
4962c51a MS |
5806 | |
5807 | /* Try to parse a group relocation. Anything else is an error. */ | |
5808 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
477330fc RM |
5809 | { |
5810 | inst.error = _("unknown group relocation"); | |
5811 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5812 | } | |
4962c51a MS |
5813 | |
5814 | /* We now have the group relocation table entry corresponding to | |
477330fc | 5815 | the name in the assembler source. Next, we parse the expression. */ |
e2b0ab59 | 5816 | if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX)) |
477330fc | 5817 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
4962c51a MS |
5818 | |
5819 | /* Record the relocation type (always the ALU variant here). */ | |
e2b0ab59 AV |
5820 | inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code; |
5821 | gas_assert (inst.relocs[0].type != 0); | |
4962c51a MS |
5822 | |
5823 | return PARSE_OPERAND_SUCCESS; | |
5824 | } | |
5825 | else | |
5826 | return parse_shifter_operand (str, i) == SUCCESS | |
477330fc | 5827 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; |
4962c51a MS |
5828 | |
5829 | /* Never reached. */ | |
5830 | } | |
5831 | ||
8e560766 MGD |
5832 | /* Parse a Neon alignment expression. Information is written to |
5833 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5834 | |
8e560766 MGD |
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 | ||
c19d1205 | 5859 | /* Parse all forms of an ARM address expression. Information is written |
e2b0ab59 | 5860 | to inst.operands[i] and/or inst.relocs[0]. |
09d92015 | 5861 | |
c19d1205 | 5862 | Preindexed addressing (.preind=1): |
09d92015 | 5863 | |
e2b0ab59 | 5864 | [Rn, #offset] .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
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 | |
e2b0ab59 | 5867 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5868 | |
c19d1205 | 5869 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5870 | |
c19d1205 | 5871 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5872 | |
e2b0ab59 | 5873 | [Rn], #offset .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
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 | |
e2b0ab59 | 5876 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5877 | |
c19d1205 | 5878 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5879 | |
c19d1205 | 5880 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5881 | |
c19d1205 | 5882 | Other: |
09d92015 | 5883 | |
c19d1205 | 5884 | [Rn]{!} shorthand for [Rn,#0]{!} |
e2b0ab59 AV |
5885 | =immediate .isreg=0 .relocs[0].exp=immediate |
5886 | label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label | |
09d92015 | 5887 | |
c19d1205 | 5888 | It is the caller's responsibility to check for addressing modes not |
e2b0ab59 | 5889 | supported by the instruction, and to set inst.relocs[0].type. */ |
c19d1205 | 5890 | |
4962c51a MS |
5891 | static parse_operand_result |
5892 | parse_address_main (char **str, int i, int group_relocations, | |
477330fc | 5893 | group_reloc_type group_type) |
09d92015 | 5894 | { |
c19d1205 ZW |
5895 | char *p = *str; |
5896 | int reg; | |
09d92015 | 5897 | |
c19d1205 | 5898 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5899 | { |
79248c83 SP |
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) | |
c19d1205 | 5909 | { |
974da60d | 5910 | /* Bare address - translate to PC-relative offset. */ |
e2b0ab59 | 5911 | inst.relocs[0].pc_rel = 1; |
c19d1205 ZW |
5912 | inst.operands[i].reg = REG_PC; |
5913 | inst.operands[i].isreg = 1; | |
5914 | inst.operands[i].preind = 1; | |
09d92015 | 5915 | |
e2b0ab59 | 5916 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG)) |
8335d6aa JW |
5917 | return PARSE_OPERAND_FAIL; |
5918 | } | |
e2b0ab59 | 5919 | else if (parse_big_immediate (&p, i, &inst.relocs[0].exp, |
5b7c81bd | 5920 | /*allow_symbol_p=*/true)) |
4962c51a | 5921 | return PARSE_OPERAND_FAIL; |
09d92015 | 5922 | |
c19d1205 | 5923 | *str = p; |
4962c51a | 5924 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5925 | } |
5926 | ||
8ab8155f NC |
5927 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5928 | skip_whitespace (p); | |
5929 | ||
f5f10c66 AV |
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) | |
09d92015 | 5945 | { |
35c228db AV |
5946 | if (group_type == GROUP_MVE) |
5947 | inst.error = BAD_ADDR_MODE; | |
5948 | else | |
5949 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
4962c51a | 5950 | return PARSE_OPERAND_FAIL; |
09d92015 | 5951 | } |
c19d1205 ZW |
5952 | inst.operands[i].reg = reg; |
5953 | inst.operands[i].isreg = 1; | |
09d92015 | 5954 | |
c19d1205 | 5955 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5956 | { |
c19d1205 | 5957 | inst.operands[i].preind = 1; |
09d92015 | 5958 | |
c19d1205 ZW |
5959 | if (*p == '+') p++; |
5960 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5961 | ||
f5f10c66 AV |
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) | |
09d92015 | 5982 | { |
c19d1205 ZW |
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) | |
4962c51a | 5988 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5989 | } |
5287ad62 | 5990 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
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); | |
fa94de6b | 5996 | |
8e560766 MGD |
5997 | if (result != PARSE_OPERAND_SUCCESS) |
5998 | return result; | |
5999 | } | |
c19d1205 ZW |
6000 | else |
6001 | { | |
6002 | if (inst.operands[i].negative) | |
6003 | { | |
6004 | inst.operands[i].negative = 0; | |
6005 | p--; | |
6006 | } | |
4962c51a | 6007 | |
5f4273c7 NC |
6008 | if (group_relocations |
6009 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
6010 | { |
6011 | struct group_reloc_table_entry *entry; | |
6012 | ||
477330fc RM |
6013 | /* Skip over the #: or : sequence. */ |
6014 | if (*p == '#') | |
6015 | p += 2; | |
6016 | else | |
6017 | p++; | |
4962c51a MS |
6018 | |
6019 | /* Try to parse a group relocation. Anything else is an | |
477330fc | 6020 | error. */ |
4962c51a MS |
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 | |
477330fc | 6029 | expression. */ |
e2b0ab59 | 6030 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
4962c51a MS |
6031 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
6032 | ||
6033 | /* Record the relocation type. */ | |
477330fc RM |
6034 | switch (group_type) |
6035 | { | |
6036 | case GROUP_LDR: | |
e2b0ab59 AV |
6037 | inst.relocs[0].type |
6038 | = (bfd_reloc_code_real_type) entry->ldr_code; | |
477330fc | 6039 | break; |
4962c51a | 6040 | |
477330fc | 6041 | case GROUP_LDRS: |
e2b0ab59 AV |
6042 | inst.relocs[0].type |
6043 | = (bfd_reloc_code_real_type) entry->ldrs_code; | |
477330fc | 6044 | break; |
4962c51a | 6045 | |
477330fc | 6046 | case GROUP_LDC: |
e2b0ab59 AV |
6047 | inst.relocs[0].type |
6048 | = (bfd_reloc_code_real_type) entry->ldc_code; | |
477330fc | 6049 | break; |
4962c51a | 6050 | |
477330fc RM |
6051 | default: |
6052 | gas_assert (0); | |
6053 | } | |
4962c51a | 6054 | |
e2b0ab59 | 6055 | if (inst.relocs[0].type == 0) |
4962c51a MS |
6056 | { |
6057 | inst.error = _("this group relocation is not allowed on this instruction"); | |
6058 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
6059 | } | |
477330fc RM |
6060 | } |
6061 | else | |
26d97720 NS |
6062 | { |
6063 | char *q = p; | |
0198d5e6 | 6064 | |
e2b0ab59 | 6065 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
26d97720 NS |
6066 | return PARSE_OPERAND_FAIL; |
6067 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
e2b0ab59 AV |
6068 | if (inst.relocs[0].exp.X_op == O_constant |
6069 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
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 | } | |
09d92015 MM |
6081 | } |
6082 | } | |
8e560766 MGD |
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); | |
fa94de6b | 6088 | |
8e560766 MGD |
6089 | if (result != PARSE_OPERAND_SUCCESS) |
6090 | return result; | |
6091 | } | |
09d92015 | 6092 | |
c19d1205 | 6093 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 6094 | { |
c19d1205 | 6095 | inst.error = _("']' expected"); |
4962c51a | 6096 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
6097 | } |
6098 | ||
c19d1205 ZW |
6099 | if (skip_past_char (&p, '!') == SUCCESS) |
6100 | inst.operands[i].writeback = 1; | |
09d92015 | 6101 | |
c19d1205 | 6102 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 6103 | { |
c19d1205 ZW |
6104 | if (skip_past_char (&p, '{') == SUCCESS) |
6105 | { | |
6106 | /* [Rn], {expr} - unindexed, with option */ | |
6107 | if (parse_immediate (&p, &inst.operands[i].imm, | |
5b7c81bd | 6108 | 0, 255, true) == FAIL) |
4962c51a | 6109 | return PARSE_OPERAND_FAIL; |
09d92015 | 6110 | |
c19d1205 ZW |
6111 | if (skip_past_char (&p, '}') == FAIL) |
6112 | { | |
6113 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 6114 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
6115 | } |
6116 | if (inst.operands[i].preind) | |
6117 | { | |
6118 | inst.error = _("cannot combine index with option"); | |
4962c51a | 6119 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
6120 | } |
6121 | *str = p; | |
4962c51a | 6122 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 6123 | } |
c19d1205 ZW |
6124 | else |
6125 | { | |
6126 | inst.operands[i].postind = 1; | |
6127 | inst.operands[i].writeback = 1; | |
09d92015 | 6128 | |
c19d1205 ZW |
6129 | if (inst.operands[i].preind) |
6130 | { | |
6131 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 6132 | return PARSE_OPERAND_FAIL; |
c19d1205 | 6133 | } |
09d92015 | 6134 | |
c19d1205 ZW |
6135 | if (*p == '+') p++; |
6136 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 6137 | |
f5f10c66 AV |
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) | |
c19d1205 | 6147 | { |
477330fc RM |
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; | |
c19d1205 | 6154 | inst.operands[i].immisreg = 1; |
a737bd4d | 6155 | |
c19d1205 ZW |
6156 | if (skip_past_comma (&p) == SUCCESS) |
6157 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 6158 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
6159 | } |
6160 | else | |
6161 | { | |
26d97720 | 6162 | char *q = p; |
0198d5e6 | 6163 | |
c19d1205 ZW |
6164 | if (inst.operands[i].negative) |
6165 | { | |
6166 | inst.operands[i].negative = 0; | |
6167 | p--; | |
6168 | } | |
e2b0ab59 | 6169 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
4962c51a | 6170 | return PARSE_OPERAND_FAIL; |
26d97720 | 6171 | /* If the offset is 0, find out if it's a +0 or -0. */ |
e2b0ab59 AV |
6172 | if (inst.relocs[0].exp.X_op == O_constant |
6173 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
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 | } | |
c19d1205 ZW |
6184 | } |
6185 | } | |
a737bd4d NC |
6186 | } |
6187 | ||
c19d1205 ZW |
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; | |
e2b0ab59 AV |
6193 | inst.relocs[0].exp.X_op = O_constant; |
6194 | inst.relocs[0].exp.X_add_number = 0; | |
c19d1205 ZW |
6195 | } |
6196 | *str = p; | |
4962c51a MS |
6197 | return PARSE_OPERAND_SUCCESS; |
6198 | } | |
6199 | ||
6200 | static int | |
6201 | parse_address (char **str, int i) | |
6202 | { | |
21d799b5 | 6203 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
477330fc | 6204 | ? SUCCESS : FAIL; |
4962c51a MS |
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); | |
a737bd4d NC |
6211 | } |
6212 | ||
b6895b4f PB |
6213 | /* Parse an operand for a MOVW or MOVT instruction. */ |
6214 | static int | |
6215 | parse_half (char **str) | |
6216 | { | |
6217 | char * p; | |
5f4273c7 | 6218 | |
b6895b4f PB |
6219 | p = *str; |
6220 | skip_past_char (&p, '#'); | |
5f4273c7 | 6221 | if (strncasecmp (p, ":lower16:", 9) == 0) |
e2b0ab59 | 6222 | inst.relocs[0].type = BFD_RELOC_ARM_MOVW; |
b6895b4f | 6223 | else if (strncasecmp (p, ":upper16:", 9) == 0) |
e2b0ab59 | 6224 | inst.relocs[0].type = BFD_RELOC_ARM_MOVT; |
b6895b4f | 6225 | |
e2b0ab59 | 6226 | if (inst.relocs[0].type != BFD_RELOC_UNUSED) |
b6895b4f PB |
6227 | { |
6228 | p += 9; | |
5f4273c7 | 6229 | skip_whitespace (p); |
b6895b4f PB |
6230 | } |
6231 | ||
e2b0ab59 | 6232 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
b6895b4f PB |
6233 | return FAIL; |
6234 | ||
e2b0ab59 | 6235 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 6236 | { |
e2b0ab59 | 6237 | if (inst.relocs[0].exp.X_op != O_constant) |
b6895b4f PB |
6238 | { |
6239 | inst.error = _("constant expression expected"); | |
6240 | return FAIL; | |
6241 | } | |
e2b0ab59 AV |
6242 | if (inst.relocs[0].exp.X_add_number < 0 |
6243 | || inst.relocs[0].exp.X_add_number > 0xffff) | |
b6895b4f PB |
6244 | { |
6245 | inst.error = _("immediate value out of range"); | |
6246 | return FAIL; | |
6247 | } | |
6248 | } | |
6249 | *str = p; | |
6250 | return SUCCESS; | |
6251 | } | |
6252 | ||
c19d1205 | 6253 | /* Miscellaneous. */ |
a737bd4d | 6254 | |
c19d1205 ZW |
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 | |
5b7c81bd | 6258 | parse_psr (char **str, bool lhs) |
09d92015 | 6259 | { |
c19d1205 ZW |
6260 | char *p; |
6261 | unsigned long psr_field; | |
62b3e311 PB |
6262 | const struct asm_psr *psr; |
6263 | char *start; | |
5b7c81bd AM |
6264 | bool is_apsr = false; |
6265 | bool m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); | |
09d92015 | 6266 | |
a4482bb6 NC |
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. */ | |
823d2571 | 6270 | if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) |
5b7c81bd | 6271 | m_profile = false; |
a4482bb6 | 6272 | |
c19d1205 ZW |
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; | |
62b3e311 | 6276 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
6277 | { |
6278 | if (m_profile) | |
6279 | goto unsupported_psr; | |
fa94de6b | 6280 | |
d2cd1205 JB |
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. */ | |
5b7c81bd | 6294 | is_apsr = true; |
d2cd1205 JB |
6295 | psr_field = 0; |
6296 | } | |
6297 | else if (m_profile) | |
62b3e311 PB |
6298 | { |
6299 | start = p; | |
6300 | do | |
6301 | p++; | |
6302 | while (ISALNUM (*p) || *p == '_'); | |
6303 | ||
d2cd1205 JB |
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 | ||
629310ab | 6310 | psr = (const struct asm_psr *) str_hash_find_n (arm_v7m_psr_hsh, start, |
fe0e921f | 6311 | p - start); |
d2cd1205 | 6312 | |
62b3e311 PB |
6313 | if (!psr) |
6314 | return FAIL; | |
09d92015 | 6315 | |
d2cd1205 JB |
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; | |
5b7c81bd | 6321 | is_apsr = true; |
d2cd1205 JB |
6322 | goto check_suffix; |
6323 | } | |
6324 | ||
62b3e311 | 6325 | *str = p; |
d2cd1205 JB |
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); | |
62b3e311 | 6331 | } |
d2cd1205 JB |
6332 | else |
6333 | goto unsupported_psr; | |
09d92015 | 6334 | |
62b3e311 | 6335 | p += 4; |
dc1e8a47 | 6336 | check_suffix: |
c19d1205 ZW |
6337 | if (*p == '_') |
6338 | { | |
6339 | /* A suffix follows. */ | |
c19d1205 ZW |
6340 | p++; |
6341 | start = p; | |
a737bd4d | 6342 | |
c19d1205 ZW |
6343 | do |
6344 | p++; | |
6345 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 6346 | |
d2cd1205 JB |
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; | |
fa94de6b | 6353 | |
d2cd1205 JB |
6354 | for (bit = start; bit != p; bit++) |
6355 | { | |
6356 | switch (TOLOWER (*bit)) | |
477330fc | 6357 | { |
d2cd1205 JB |
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; | |
fa94de6b | 6373 | |
d2cd1205 JB |
6374 | case 'q': |
6375 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
6376 | break; | |
fa94de6b | 6377 | |
d2cd1205 JB |
6378 | case 'g': |
6379 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
6380 | break; | |
fa94de6b | 6381 | |
d2cd1205 JB |
6382 | default: |
6383 | inst.error = _("unexpected bit specified after APSR"); | |
6384 | return FAIL; | |
6385 | } | |
6386 | } | |
fa94de6b | 6387 | |
d2cd1205 JB |
6388 | if (nzcvq_bits == 0x1f) |
6389 | psr_field |= PSR_f; | |
fa94de6b | 6390 | |
d2cd1205 JB |
6391 | if (g_bit == 0x1) |
6392 | { | |
6393 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
477330fc | 6394 | { |
d2cd1205 JB |
6395 | inst.error = _("selected processor does not " |
6396 | "support DSP extension"); | |
6397 | return FAIL; | |
6398 | } | |
6399 | ||
6400 | psr_field |= PSR_s; | |
6401 | } | |
fa94de6b | 6402 | |
d2cd1205 JB |
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 | |
477330fc | 6412 | { |
629310ab | 6413 | psr = (const struct asm_psr *) str_hash_find_n (arm_psr_hsh, start, |
fe0e921f | 6414 | p - start); |
d2cd1205 | 6415 | if (!psr) |
477330fc | 6416 | goto error; |
a737bd4d | 6417 | |
d2cd1205 JB |
6418 | psr_field |= psr->field; |
6419 | } | |
a737bd4d | 6420 | } |
c19d1205 | 6421 | else |
a737bd4d | 6422 | { |
c19d1205 ZW |
6423 | if (ISALNUM (*p)) |
6424 | goto error; /* Garbage after "[CS]PSR". */ | |
6425 | ||
d2cd1205 | 6426 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
477330fc | 6427 | is deprecated, but allow it anyway. */ |
d2cd1205 JB |
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); | |
a737bd4d | 6438 | } |
c19d1205 ZW |
6439 | *str = p; |
6440 | return psr_field; | |
a737bd4d | 6441 | |
d2cd1205 JB |
6442 | unsupported_psr: |
6443 | inst.error = _("selected processor does not support requested special " | |
6444 | "purpose register"); | |
6445 | return FAIL; | |
6446 | ||
c19d1205 ZW |
6447 | error: |
6448 | inst.error = _("flag for {c}psr instruction expected"); | |
6449 | return FAIL; | |
a737bd4d NC |
6450 | } |
6451 | ||
32c36c3c AV |
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 | ||
c19d1205 ZW |
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. */ | |
a737bd4d | 6487 | |
c19d1205 ZW |
6488 | static int |
6489 | parse_cps_flags (char **str) | |
a737bd4d | 6490 | { |
c19d1205 ZW |
6491 | int val = 0; |
6492 | int saw_a_flag = 0; | |
6493 | char *s = *str; | |
a737bd4d | 6494 | |
c19d1205 ZW |
6495 | for (;;) |
6496 | switch (*s++) | |
6497 | { | |
6498 | case '\0': case ',': | |
6499 | goto done; | |
a737bd4d | 6500 | |
c19d1205 ZW |
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; | |
a737bd4d | 6504 | |
c19d1205 ZW |
6505 | default: |
6506 | inst.error = _("unrecognized CPS flag"); | |
6507 | return FAIL; | |
6508 | } | |
a737bd4d | 6509 | |
c19d1205 ZW |
6510 | done: |
6511 | if (saw_a_flag == 0) | |
a737bd4d | 6512 | { |
c19d1205 ZW |
6513 | inst.error = _("missing CPS flags"); |
6514 | return FAIL; | |
a737bd4d | 6515 | } |
a737bd4d | 6516 | |
c19d1205 ZW |
6517 | *str = s - 1; |
6518 | return val; | |
a737bd4d NC |
6519 | } |
6520 | ||
c19d1205 ZW |
6521 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
6522 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
6523 | |
6524 | static int | |
c19d1205 | 6525 | parse_endian_specifier (char **str) |
a737bd4d | 6526 | { |
c19d1205 ZW |
6527 | int little_endian; |
6528 | char *s = *str; | |
a737bd4d | 6529 | |
c19d1205 ZW |
6530 | if (strncasecmp (s, "BE", 2)) |
6531 | little_endian = 0; | |
6532 | else if (strncasecmp (s, "LE", 2)) | |
6533 | little_endian = 1; | |
6534 | else | |
a737bd4d | 6535 | { |
c19d1205 | 6536 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6537 | return FAIL; |
6538 | } | |
6539 | ||
c19d1205 | 6540 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 6541 | { |
c19d1205 | 6542 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6543 | return FAIL; |
6544 | } | |
6545 | ||
c19d1205 ZW |
6546 | *str = s + 2; |
6547 | return little_endian; | |
6548 | } | |
a737bd4d | 6549 | |
c19d1205 ZW |
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 | |
a737bd4d | 6563 | { |
c19d1205 | 6564 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
6565 | return FAIL; |
6566 | } | |
c19d1205 | 6567 | |
5b7c81bd | 6568 | if (parse_immediate (&s, &rot, 0, 24, false) == FAIL) |
c19d1205 ZW |
6569 | return FAIL; |
6570 | ||
6571 | switch (rot) | |
a737bd4d | 6572 | { |
c19d1205 ZW |
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"); | |
a737bd4d NC |
6580 | return FAIL; |
6581 | } | |
c19d1205 | 6582 | } |
a737bd4d | 6583 | |
c19d1205 ZW |
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 | { | |
c462b453 | 6589 | char *q; |
c19d1205 | 6590 | const struct asm_cond *c; |
c462b453 PB |
6591 | int n; |
6592 | /* Condition codes are always 2 characters, so matching up to | |
6593 | 3 characters is sufficient. */ | |
6594 | char cond[3]; | |
a737bd4d | 6595 | |
c462b453 PB |
6596 | q = *str; |
6597 | n = 0; | |
6598 | while (ISALPHA (*q) && n < 3) | |
6599 | { | |
e07e6e58 | 6600 | cond[n] = TOLOWER (*q); |
c462b453 PB |
6601 | q++; |
6602 | n++; | |
6603 | } | |
a737bd4d | 6604 | |
629310ab | 6605 | c = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 6606 | if (!c) |
a737bd4d | 6607 | { |
c19d1205 | 6608 | inst.error = _("condition required"); |
a737bd4d NC |
6609 | return FAIL; |
6610 | } | |
6611 | ||
c19d1205 ZW |
6612 | *str = q; |
6613 | return c->value; | |
6614 | } | |
6615 | ||
62b3e311 PB |
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 | ||
629310ab | 6628 | o = (const struct asm_barrier_opt *) str_hash_find_n (arm_barrier_opt_hsh, p, |
fe0e921f | 6629 | q - p); |
62b3e311 PB |
6630 | if (!o) |
6631 | return FAIL; | |
6632 | ||
e797f7e0 MGD |
6633 | if (!mark_feature_used (&o->arch)) |
6634 | return FAIL; | |
6635 | ||
62b3e311 PB |
6636 | *str = q; |
6637 | return o->value; | |
6638 | } | |
6639 | ||
92e90b6e PB |
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) | |
ab1eb5fe PB |
6649 | { |
6650 | inst.error = _("'[' expected"); | |
6651 | return FAIL; | |
6652 | } | |
92e90b6e | 6653 | |
dcbf9037 | 6654 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
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) | |
ab1eb5fe PB |
6662 | { |
6663 | inst.error = _("',' expected"); | |
6664 | return FAIL; | |
6665 | } | |
5f4273c7 | 6666 | |
dcbf9037 | 6667 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
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; | |
e2b0ab59 | 6678 | if (inst.relocs[0].exp.X_add_number != 1) |
92e90b6e PB |
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 | ||
5287ad62 JB |
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. | |
037e8744 JB |
6697 | Up to four operands may be read; this function handles setting the |
6698 | ".present" field for each read operand itself. | |
5287ad62 JB |
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; | |
dcbf9037 | 6708 | struct neon_type_el optype; |
5f4273c7 | 6709 | |
57785aa2 AV |
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) | |
5287ad62 JB |
6765 | { |
6766 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
6767 | inst.operands[i].reg = val; | |
6768 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 6769 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6770 | inst.operands[i++].present = 1; |
6771 | ||
6772 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6773 | goto wanted_comma; |
5f4273c7 | 6774 | |
dcbf9037 | 6775 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
477330fc | 6776 | goto wanted_arm; |
5f4273c7 | 6777 | |
5287ad62 JB |
6778 | inst.operands[i].reg = val; |
6779 | inst.operands[i].isreg = 1; | |
6780 | inst.operands[i].present = 1; | |
6781 | } | |
57785aa2 AV |
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)) | |
5287ad62 JB |
6786 | { |
6787 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
6788 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6789 | goto wanted_comma; |
5f4273c7 | 6790 | |
5287ad62 JB |
6791 | inst.operands[i].reg = val; |
6792 | inst.operands[i].isreg = 1; | |
6793 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
6794 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
6795 | inst.operands[i].isvec = 1; | |
dcbf9037 | 6796 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6797 | inst.operands[i++].present = 1; |
6798 | ||
dcbf9037 | 6799 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
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 | } | |
c4a23bf8 SP |
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)) | |
477330fc RM |
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 | } | |
4641781c | 6865 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
477330fc RM |
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; | |
5b7c81bd | 6871 | else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/false) |
8335d6aa | 6872 | == SUCCESS) |
477330fc RM |
6873 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
6874 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
6875 | ; | |
5287ad62 | 6876 | else |
477330fc RM |
6877 | { |
6878 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); | |
6879 | return FAIL; | |
6880 | } | |
5287ad62 | 6881 | } |
dcbf9037 | 6882 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 | 6883 | { |
57785aa2 | 6884 | /* Cases 6, 7, 16, 18. */ |
5287ad62 JB |
6885 | inst.operands[i].reg = val; |
6886 | inst.operands[i].isreg = 1; | |
6887 | inst.operands[i++].present = 1; | |
5f4273c7 | 6888 | |
5287ad62 | 6889 | if (skip_past_comma (&ptr) == FAIL) |
477330fc | 6890 | goto wanted_comma; |
5f4273c7 | 6891 | |
57785aa2 AV |
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) | |
477330fc RM |
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 | } | |
dcbf9037 | 6908 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc | 6909 | { |
477330fc RM |
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)) | |
57785aa2 | 6918 | != FAIL) |
477330fc | 6919 | { |
57785aa2 | 6920 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ |
477330fc | 6921 | |
477330fc RM |
6922 | inst.operands[i].reg = val; |
6923 | inst.operands[i].isreg = 1; | |
6924 | inst.operands[i].isvec = 1; | |
57785aa2 | 6925 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
477330fc RM |
6926 | inst.operands[i].vectype = optype; |
6927 | inst.operands[i].present = 1; | |
57785aa2 AV |
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 | } | |
477330fc RM |
6982 | } |
6983 | } | |
037e8744 | 6984 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) |
477330fc RM |
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 | } | |
5287ad62 JB |
6995 | } |
6996 | else | |
6997 | { | |
dcbf9037 | 6998 | first_error (_("parse error")); |
5287ad62 JB |
6999 | return FAIL; |
7000 | } | |
7001 | ||
7002 | /* Successfully parsed the operands. Update args. */ | |
7003 | *which_operand = i; | |
7004 | *str = ptr; | |
7005 | return SUCCESS; | |
7006 | ||
5f4273c7 | 7007 | wanted_comma: |
dcbf9037 | 7008 | first_error (_("expected comma")); |
5287ad62 | 7009 | return FAIL; |
5f4273c7 NC |
7010 | |
7011 | wanted_arm: | |
dcbf9037 | 7012 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 7013 | return FAIL; |
5287ad62 JB |
7014 | } |
7015 | ||
5be8be5d DG |
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 | ||
c19d1205 ZW |
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 */ | |
5be8be5d | 7028 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 7029 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 7030 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 7031 | optional trailing ! */ |
c19d1205 ZW |
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 */ | |
5287ad62 JB |
7037 | OP_RVD, /* VFP double precision register (0..15) */ |
7038 | OP_RND, /* Neon double precision register (0..31) */ | |
5ee91343 AV |
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 | */ | |
66d1f7cc AV |
7042 | OP_RNSDMQR, /* Neon single or double precision, MVE vector or ARM register. |
7043 | */ | |
5287ad62 | 7044 | OP_RNQ, /* Neon quad precision register */ |
5ee91343 | 7045 | OP_RNQMQ, /* Neon quad or MVE vector register. */ |
037e8744 | 7046 | OP_RVSD, /* VFP single or double precision register */ |
1b883319 | 7047 | OP_RVSD_COND, /* VFP single, double precision register or condition code. */ |
dd9634d9 | 7048 | OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */ |
dec41383 | 7049 | OP_RNSD, /* Neon single or double precision register */ |
5287ad62 | 7050 | OP_RNDQ, /* Neon double or quad precision register */ |
5ee91343 | 7051 | OP_RNDQMQ, /* Neon double, quad or MVE vector register. */ |
7df54120 | 7052 | OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */ |
037e8744 | 7053 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 7054 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
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 | ||
5aae9ae9 | 7067 | OP_RNSDMQ, /* Neon single, double or MVE vector register */ |
5ee91343 AV |
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) */ | |
a302e574 | 7072 | OP_RMQ, /* MVE vector register. */ |
1b883319 | 7073 | OP_RMQRZ, /* MVE vector or ARM register including ZR. */ |
35d1cfc2 | 7074 | OP_RMQRR, /* MVE vector or ARM register. */ |
a302e574 | 7075 | |
60f993ce AV |
7076 | /* New operands for Armv8.1-M Mainline. */ |
7077 | OP_LR, /* ARM LR register */ | |
f1e1d7f3 AC |
7078 | OP_SP, /* ARM SP register */ |
7079 | OP_R12, | |
a302e574 AV |
7080 | OP_RRe, /* ARM register, only even numbered. */ |
7081 | OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */ | |
60f993ce | 7082 | OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */ |
e39c1607 | 7083 | OP_RR_ZR, /* ARM register or ZR but no PC */ |
60f993ce | 7084 | |
c19d1205 | 7085 | OP_REGLST, /* ARM register list */ |
4b5a202f | 7086 | OP_CLRMLST, /* CLRM register list */ |
c19d1205 ZW |
7087 | OP_VRSLST, /* VFP single-precision register list */ |
7088 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 7089 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
7090 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
7091 | OP_NSTRLST, /* Neon element/structure list */ | |
efd6b359 | 7092 | OP_VRSDVLST, /* VFP single or double-precision register list and VPR */ |
35c228db AV |
7093 | OP_MSTRLST2, /* MVE vector list with two elements. */ |
7094 | OP_MSTRLST4, /* MVE vector list with four elements. */ | |
5287ad62 | 7095 | |
5287ad62 | 7096 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 7097 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
aacf0b33 | 7098 | OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */ |
1b883319 AV |
7099 | OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate |
7100 | zero. */ | |
5287ad62 | 7101 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
dec41383 | 7102 | OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */ |
037e8744 | 7103 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
886e1c73 AV |
7104 | OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register. |
7105 | */ | |
a8465a06 AV |
7106 | OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon |
7107 | scalar, or ARM register. */ | |
5287ad62 | 7108 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
42b16635 AV |
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. */ | |
5d281bf0 | 7112 | OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */ |
5287ad62 JB |
7113 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ |
7114 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 7115 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
f601a00c AV |
7116 | /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */ |
7117 | OP_RNDQMQ_Ibig, | |
5287ad62 | 7118 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
5150f0d8 AV |
7119 | OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or |
7120 | ARM register. */ | |
2d447fca | 7121 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
32c36c3c | 7122 | OP_VLDR, /* VLDR operand. */ |
5287ad62 JB |
7123 | |
7124 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
7125 | OP_I7, /* immediate value 0 .. 7 */ |
7126 | OP_I15, /* 0 .. 15 */ | |
7127 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 7128 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
7129 | OP_I31, /* 0 .. 31 */ |
7130 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
7131 | OP_I32, /* 1 .. 32 */ | |
5287ad62 | 7132 | OP_I32z, /* 0 .. 32 */ |
08132bdd | 7133 | OP_I48_I64, /* 48 or 64 */ |
5287ad62 | 7134 | OP_I63, /* 0 .. 63 */ |
c19d1205 | 7135 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
7136 | OP_I64, /* 1 .. 64 */ |
7137 | OP_I64z, /* 0 .. 64 */ | |
5aae9ae9 | 7138 | OP_I127, /* 0 .. 127 */ |
c19d1205 | 7139 | OP_I255, /* 0 .. 255 */ |
4934a27c | 7140 | OP_I511, /* 0 .. 511 */ |
5aae9ae9 | 7141 | OP_I4095, /* 0 .. 4095 */ |
4934a27c | 7142 | OP_I8191, /* 0 .. 8191 */ |
c19d1205 ZW |
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 */ | |
4962c51a | 7149 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 7150 | OP_ADDR, /* Memory address expression (any mode) */ |
35c228db | 7151 | OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */ |
4962c51a MS |
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 */ | |
c19d1205 ZW |
7155 | OP_EXP, /* arbitrary expression */ |
7156 | OP_EXPi, /* same, with optional immediate prefix */ | |
7157 | OP_EXPr, /* same, with optional relocation suffix */ | |
e2b0ab59 | 7158 | OP_EXPs, /* same, with optional non-first operand relocation suffix */ |
b6895b4f | 7159 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c28eeff2 SN |
7160 | OP_IROT1, /* VCADD rotate immediate: 90, 270. */ |
7161 | OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */ | |
c19d1205 ZW |
7162 | |
7163 | OP_CPSF, /* CPS flags */ | |
7164 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
7165 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
7166 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 7167 | OP_COND, /* conditional code */ |
92e90b6e | 7168 | OP_TB, /* Table branch. */ |
c19d1205 | 7169 | |
037e8744 JB |
7170 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
7171 | ||
c19d1205 | 7172 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
33eaf5de | 7173 | OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */ |
c19d1205 ZW |
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 */ | |
41adaa5c | 7177 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
7178 | |
7179 | /* Optional operands. */ | |
7180 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
7181 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 7182 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 7183 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
7184 | OP_oIffffb, /* 0 .. 65535 */ |
7185 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
7186 | ||
7187 | OP_oRR, /* ARM register */ | |
60f993ce | 7188 | OP_oLR, /* ARM LR register */ |
c19d1205 | 7189 | OP_oRRnpc, /* ARM register, not the PC */ |
5be8be5d | 7190 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 7191 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
7192 | OP_oRND, /* Optional Neon double precision register */ |
7193 | OP_oRNQ, /* Optional Neon quad precision register */ | |
5ee91343 | 7194 | OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */ |
5287ad62 | 7195 | OP_oRNDQ, /* Optional Neon double or quad precision register */ |
037e8744 | 7196 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
5ee91343 AV |
7197 | OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector |
7198 | register. */ | |
66d1f7cc AV |
7199 | OP_oRNSDMQ, /* Optional single, double register or MVE vector |
7200 | register. */ | |
c19d1205 ZW |
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 */ | |
52e7f43d | 7205 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 7206 | |
1b883319 AV |
7207 | OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */ |
7208 | ||
5be8be5d DG |
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 | ||
c19d1205 ZW |
7214 | OP_FIRST_OPTIONAL = OP_oI7b |
7215 | }; | |
a737bd4d | 7216 | |
c19d1205 ZW |
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 | |
5b7c81bd | 7222 | parse_operands (char *str, const unsigned int *pattern, bool thumb) |
c19d1205 | 7223 | { |
5be8be5d | 7224 | unsigned const int *upat = pattern; |
c19d1205 ZW |
7225 | char *backtrack_pos = 0; |
7226 | const char *backtrack_error = 0; | |
99aad254 | 7227 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 7228 | enum arm_reg_type rtype; |
4962c51a | 7229 | parse_operand_result result; |
5be8be5d | 7230 | unsigned int op_parse_code; |
5b7c81bd | 7231 | bool partial_match; |
c19d1205 | 7232 | |
e07e6e58 NC |
7233 | #define po_char_or_fail(chr) \ |
7234 | do \ | |
7235 | { \ | |
7236 | if (skip_past_char (&str, chr) == FAIL) \ | |
477330fc | 7237 | goto bad_args; \ |
e07e6e58 NC |
7238 | } \ |
7239 | while (0) | |
c19d1205 | 7240 | |
e07e6e58 NC |
7241 | #define po_reg_or_fail(regtype) \ |
7242 | do \ | |
dcbf9037 | 7243 | { \ |
e07e6e58 | 7244 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
477330fc | 7245 | & inst.operands[i].vectype); \ |
e07e6e58 | 7246 | if (val == FAIL) \ |
477330fc RM |
7247 | { \ |
7248 | first_error (_(reg_expected_msgs[regtype])); \ | |
7249 | goto failure; \ | |
7250 | } \ | |
e07e6e58 NC |
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 \ | |
477330fc RM |
7256 | || rtype == REG_TYPE_VFD \ |
7257 | || rtype == REG_TYPE_NQ); \ | |
1b883319 | 7258 | inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \ |
dcbf9037 | 7259 | } \ |
e07e6e58 NC |
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; \ | |
dcbf9037 | 7269 | \ |
e07e6e58 NC |
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 \ | |
477330fc | 7275 | || rtype == REG_TYPE_VFD \ |
e07e6e58 | 7276 | || rtype == REG_TYPE_NQ); \ |
1b883319 | 7277 | inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \ |
e07e6e58 NC |
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 | ||
08132bdd SP |
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 | ||
57785aa2 | 7309 | #define po_scalar_or_goto(elsz, label, reg_type) \ |
e07e6e58 NC |
7310 | do \ |
7311 | { \ | |
57785aa2 AV |
7312 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \ |
7313 | reg_type); \ | |
e07e6e58 NC |
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) | |
4962c51a | 7339 | |
52e7f43d RE |
7340 | #define po_barrier_or_imm(str) \ |
7341 | do \ | |
7342 | { \ | |
7343 | val = parse_barrier (&str); \ | |
ccb84d65 JB |
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)) \ | |
52e7f43d | 7350 | { \ |
ccb84d65 JB |
7351 | inst.error = _("invalid barrier type"); \ |
7352 | backtrack_pos = 0; \ | |
7353 | goto failure; \ | |
52e7f43d RE |
7354 | } \ |
7355 | } \ | |
7356 | while (0) | |
7357 | ||
c19d1205 ZW |
7358 | skip_whitespace (str); |
7359 | ||
7360 | for (i = 0; upat[i] != OP_stop; i++) | |
7361 | { | |
5be8be5d DG |
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) | |
c19d1205 ZW |
7368 | { |
7369 | /* Remember where we are in case we need to backtrack. */ | |
c19d1205 ZW |
7370 | backtrack_pos = str; |
7371 | backtrack_error = inst.error; | |
7372 | backtrack_index = i; | |
7373 | } | |
7374 | ||
b6702015 | 7375 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
7376 | po_char_or_fail (','); |
7377 | ||
5be8be5d | 7378 | switch (op_parse_code) |
c19d1205 ZW |
7379 | { |
7380 | /* Registers */ | |
7381 | case OP_oRRnpc: | |
5be8be5d | 7382 | case OP_oRRnpcsp: |
c19d1205 | 7383 | case OP_RRnpc: |
5be8be5d | 7384 | case OP_RRnpcsp: |
c19d1205 | 7385 | case OP_oRR: |
a302e574 AV |
7386 | case OP_RRe: |
7387 | case OP_RRo: | |
60f993ce AV |
7388 | case OP_LR: |
7389 | case OP_oLR: | |
f1e1d7f3 AC |
7390 | case OP_SP: |
7391 | case OP_R12: | |
c19d1205 ZW |
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; | |
477330fc | 7398 | case OP_oRND: |
66d1f7cc AV |
7399 | case OP_RNSDMQR: |
7400 | po_reg_or_goto (REG_TYPE_VFS, try_rndmqr); | |
7401 | break; | |
7402 | try_rndmqr: | |
5ee91343 AV |
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: | |
5287ad62 | 7411 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; |
cd2cf30b PB |
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: | |
ba6cd17f SD |
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; | |
cd2cf30b | 7431 | break; |
c19d1205 ZW |
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; | |
477330fc | 7442 | case OP_oRNQ: |
5ee91343 AV |
7443 | case OP_RNQMQ: |
7444 | po_reg_or_goto (REG_TYPE_MQ, try_nq); | |
7445 | break; | |
7446 | try_nq: | |
5287ad62 | 7447 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; |
dec41383 | 7448 | case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break; |
7df54120 AV |
7449 | case OP_RNDQMQR: |
7450 | po_reg_or_goto (REG_TYPE_RN, try_rndqmq); | |
7451 | break; | |
7452 | try_rndqmq: | |
5ee91343 AV |
7453 | case OP_oRNDQMQ: |
7454 | case OP_RNDQMQ: | |
7455 | po_reg_or_goto (REG_TYPE_MQ, try_rndq); | |
7456 | break; | |
7457 | try_rndq: | |
477330fc | 7458 | case OP_oRNDQ: |
5287ad62 | 7459 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; |
dd9634d9 AV |
7460 | case OP_RVSDMQ: |
7461 | po_reg_or_goto (REG_TYPE_MQ, try_rvsd); | |
7462 | break; | |
7463 | try_rvsd: | |
477330fc | 7464 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
1b883319 AV |
7465 | case OP_RVSD_COND: |
7466 | po_reg_or_goto (REG_TYPE_VFSD, try_cond); | |
7467 | break; | |
66d1f7cc | 7468 | case OP_oRNSDMQ: |
5aae9ae9 MM |
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; | |
477330fc RM |
7475 | case OP_oRNSDQ: |
7476 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
5ee91343 AV |
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; | |
35d1cfc2 AV |
7489 | case OP_RMQRR: |
7490 | po_reg_or_goto (REG_TYPE_RN, try_rmq); | |
7491 | break; | |
7492 | try_rmq: | |
a302e574 AV |
7493 | case OP_RMQ: |
7494 | po_reg_or_fail (REG_TYPE_MQ); | |
7495 | break; | |
477330fc RM |
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. */ | |
57785aa2 | 7498 | case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break; |
477330fc RM |
7499 | |
7500 | case OP_RNDQ_I0: | |
7501 | { | |
7502 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
7503 | break; | |
7504 | try_imm0: | |
5b7c81bd | 7505 | po_imm_or_fail (0, 0, true); |
477330fc RM |
7506 | } |
7507 | break; | |
7508 | ||
7509 | case OP_RVSD_I0: | |
7510 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
7511 | break; | |
7512 | ||
1b883319 AV |
7513 | case OP_RSVDMQ_FI0: |
7514 | po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0); | |
7515 | break; | |
7516 | try_rsvd_fi0: | |
aacf0b33 KT |
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 | ||
477330fc RM |
7533 | case OP_RR_RNSC: |
7534 | { | |
57785aa2 | 7535 | po_scalar_or_goto (8, try_rr, REG_TYPE_VFD); |
477330fc RM |
7536 | break; |
7537 | try_rr: | |
7538 | po_reg_or_fail (REG_TYPE_RN); | |
7539 | } | |
7540 | break; | |
7541 | ||
a8465a06 AV |
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: | |
886e1c73 AV |
7546 | case OP_RNSDQ_RNSC_MQ: |
7547 | po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc); | |
7548 | break; | |
7549 | try_rnsdq_rnsc: | |
477330fc RM |
7550 | case OP_RNSDQ_RNSC: |
7551 | { | |
57785aa2 AV |
7552 | po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD); |
7553 | inst.error = 0; | |
477330fc RM |
7554 | break; |
7555 | try_nsdq: | |
7556 | po_reg_or_fail (REG_TYPE_NSDQ); | |
57785aa2 | 7557 | inst.error = 0; |
477330fc RM |
7558 | } |
7559 | break; | |
7560 | ||
dec41383 JW |
7561 | case OP_RNSD_RNSC: |
7562 | { | |
57785aa2 | 7563 | po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD); |
dec41383 JW |
7564 | break; |
7565 | try_s_scalar: | |
57785aa2 | 7566 | po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS); |
dec41383 JW |
7567 | break; |
7568 | try_nsd: | |
7569 | po_reg_or_fail (REG_TYPE_NSD); | |
7570 | } | |
7571 | break; | |
7572 | ||
42b16635 AV |
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; | |
5d281bf0 AV |
7580 | case OP_RNDQMQ_RNSC: |
7581 | po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc); | |
7582 | break; | |
7583 | try_rndq_rnsc: | |
477330fc RM |
7584 | case OP_RNDQ_RNSC: |
7585 | { | |
57785aa2 | 7586 | po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD); |
477330fc RM |
7587 | break; |
7588 | try_ndq: | |
7589 | po_reg_or_fail (REG_TYPE_NDQ); | |
7590 | } | |
7591 | break; | |
7592 | ||
7593 | case OP_RND_RNSC: | |
7594 | { | |
57785aa2 | 7595 | po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD); |
477330fc RM |
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 | ||
f601a00c AV |
7608 | case OP_RNDQMQ_Ibig: |
7609 | po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig); | |
7610 | break; | |
7611 | try_rndq_ibig: | |
477330fc RM |
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. */ | |
5b7c81bd | 7619 | if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/false) |
8335d6aa | 7620 | == FAIL) |
477330fc RM |
7621 | { |
7622 | inst.error = _("immediate value is out of range"); | |
7623 | goto failure; | |
7624 | } | |
7625 | } | |
7626 | break; | |
7627 | ||
5150f0d8 AV |
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: | |
477330fc RM |
7635 | case OP_RNDQ_I63b: |
7636 | { | |
7637 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
7638 | break; | |
7639 | try_shimm: | |
5b7c81bd | 7640 | po_imm_or_fail (0, 63, true); |
477330fc RM |
7641 | } |
7642 | break; | |
c19d1205 ZW |
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; | |
a737bd4d | 7649 | |
55881a11 | 7650 | case OP_RRnpctw: |
c19d1205 | 7651 | case OP_RRw: |
b6702015 | 7652 | case OP_oRRw: |
c19d1205 ZW |
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 */ | |
5b7c81bd AM |
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; | |
c19d1205 | 7677 | case OP_oI7b: |
5b7c81bd AM |
7678 | case OP_I7b: po_imm_or_fail ( 0, 7, true); break; |
7679 | case OP_I15b: po_imm_or_fail ( 0, 15, true); break; | |
c19d1205 | 7680 | case OP_oI31b: |
5b7c81bd AM |
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; | |
c19d1205 ZW |
7685 | |
7686 | /* Immediate variants */ | |
7687 | case OP_oI255c: | |
7688 | po_char_or_fail ('{'); | |
5b7c81bd | 7689 | po_imm_or_fail (0, 255, true); |
c19d1205 ZW |
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 | } | |
5b7c81bd | 7705 | po_imm_or_fail (0, 31, true); |
c19d1205 ZW |
7706 | if (str == s - 1) |
7707 | str = s; | |
7708 | } | |
7709 | break; | |
7710 | ||
7711 | /* Expressions */ | |
7712 | case OP_EXPi: EXPi: | |
e2b0ab59 | 7713 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7714 | GE_OPT_PREFIX)); |
7715 | break; | |
7716 | ||
7717 | case OP_EXP: | |
e2b0ab59 | 7718 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7719 | GE_NO_PREFIX)); |
7720 | break; | |
7721 | ||
7722 | case OP_EXPr: EXPr: | |
e2b0ab59 | 7723 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 | 7724 | GE_NO_PREFIX)); |
e2b0ab59 | 7725 | if (inst.relocs[0].exp.X_op == O_symbol) |
a737bd4d | 7726 | { |
c19d1205 ZW |
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 | } | |
a737bd4d | 7738 | } |
c19d1205 | 7739 | break; |
a737bd4d | 7740 | |
e2b0ab59 AV |
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 | ||
b6895b4f PB |
7755 | /* Operand for MOVW or MOVT. */ |
7756 | case OP_HALF: | |
7757 | po_misc_or_fail (parse_half (&str)); | |
7758 | break; | |
7759 | ||
e07e6e58 | 7760 | /* Register or expression. */ |
c19d1205 ZW |
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; | |
a737bd4d | 7763 | |
e07e6e58 | 7764 | /* Register or immediate. */ |
c19d1205 | 7765 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
5b7c81bd | 7766 | I0: po_imm_or_fail (0, 0, false); break; |
a737bd4d | 7767 | |
23d00a41 | 7768 | case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break; |
5b7c81bd | 7769 | I32: po_imm_or_fail (1, 32, false); break; |
23d00a41 | 7770 | |
c19d1205 ZW |
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; | |
09d92015 | 7784 | |
2d447fca | 7785 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
5b7c81bd | 7786 | I32z: po_imm_or_fail (0, 32, false); break; |
2d447fca | 7787 | |
e07e6e58 | 7788 | /* Two kinds of register. */ |
c19d1205 ZW |
7789 | case OP_RIWR_RIWC: |
7790 | { | |
7791 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
7792 | if (!rege |
7793 | || (rege->type != REG_TYPE_MMXWR | |
7794 | && rege->type != REG_TYPE_MMXWC | |
7795 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
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; | |
09d92015 | 7804 | |
41adaa5c JM |
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 | ||
c19d1205 ZW |
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; | |
1b883319 | 7824 | try_cond: |
c19d1205 | 7825 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
7826 | case OP_oBARRIER_I15: |
7827 | po_barrier_or_imm (str); break; | |
7828 | immediate: | |
5b7c81bd | 7829 | if (parse_immediate (&str, &val, 0, 15, true) == FAIL) |
477330fc | 7830 | goto failure; |
52e7f43d | 7831 | break; |
c19d1205 | 7832 | |
fa94de6b | 7833 | case OP_wPSR: |
d2cd1205 | 7834 | case OP_rPSR: |
90ec0d68 MGD |
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; | |
d2cd1205 JB |
7843 | try_psr: |
7844 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
7845 | break; | |
037e8744 | 7846 | |
32c36c3c AV |
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 | ||
477330fc RM |
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; | |
f7c21dc7 NC |
7876 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
7877 | inst.operands[i].reg = REG_PC; | |
477330fc RM |
7878 | } |
7879 | else | |
7880 | goto failure; | |
7881 | break; | |
037e8744 | 7882 | |
92e90b6e PB |
7883 | case OP_TB: |
7884 | po_misc_or_fail (parse_tb (&str)); | |
7885 | break; | |
7886 | ||
e07e6e58 | 7887 | /* Register lists. */ |
c19d1205 | 7888 | case OP_REGLST: |
4b5a202f | 7889 | val = parse_reg_list (&str, REGLIST_RN); |
c19d1205 ZW |
7890 | if (*str == '^') |
7891 | { | |
5e0d7f77 | 7892 | inst.operands[i].writeback = 1; |
c19d1205 ZW |
7893 | str++; |
7894 | } | |
7895 | break; | |
09d92015 | 7896 | |
4b5a202f AV |
7897 | case OP_CLRMLST: |
7898 | val = parse_reg_list (&str, REGLIST_CLRM); | |
7899 | break; | |
7900 | ||
c19d1205 | 7901 | case OP_VRSLST: |
efd6b359 AV |
7902 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S, |
7903 | &partial_match); | |
c19d1205 | 7904 | break; |
09d92015 | 7905 | |
c19d1205 | 7906 | case OP_VRDLST: |
efd6b359 AV |
7907 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D, |
7908 | &partial_match); | |
c19d1205 | 7909 | break; |
a737bd4d | 7910 | |
477330fc RM |
7911 | case OP_VRSDLST: |
7912 | /* Allow Q registers too. */ | |
7913 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 | 7914 | REGLIST_NEON_D, &partial_match); |
477330fc RM |
7915 | if (val == FAIL) |
7916 | { | |
7917 | inst.error = NULL; | |
7918 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
efd6b359 AV |
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); | |
477330fc RM |
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, | |
efd6b359 | 7938 | REGLIST_NEON_D, &partial_match); |
477330fc | 7939 | break; |
5287ad62 | 7940 | |
35c228db AV |
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; | |
5287ad62 | 7948 | case OP_NSTRLST: |
477330fc | 7949 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
35c228db | 7950 | 0, &inst.operands[i].vectype); |
477330fc | 7951 | break; |
5287ad62 | 7952 | |
c19d1205 | 7953 | /* Addressing modes */ |
35c228db AV |
7954 | case OP_ADDRMVE: |
7955 | po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE)); | |
7956 | break; | |
7957 | ||
c19d1205 ZW |
7958 | case OP_ADDR: |
7959 | po_misc_or_fail (parse_address (&str, i)); | |
7960 | break; | |
09d92015 | 7961 | |
4962c51a MS |
7962 | case OP_ADDRGLDR: |
7963 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7964 | parse_address_group_reloc (&str, i, GROUP_LDR)); |
4962c51a MS |
7965 | break; |
7966 | ||
7967 | case OP_ADDRGLDRS: | |
7968 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7969 | parse_address_group_reloc (&str, i, GROUP_LDRS)); |
4962c51a MS |
7970 | break; |
7971 | ||
7972 | case OP_ADDRGLDC: | |
7973 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7974 | parse_address_group_reloc (&str, i, GROUP_LDC)); |
4962c51a MS |
7975 | break; |
7976 | ||
c19d1205 ZW |
7977 | case OP_SH: |
7978 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
7979 | break; | |
09d92015 | 7980 | |
4962c51a MS |
7981 | case OP_SHG: |
7982 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7983 | parse_shifter_operand_group_reloc (&str, i)); |
4962c51a MS |
7984 | break; |
7985 | ||
c19d1205 ZW |
7986 | case OP_oSHll: |
7987 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
7988 | break; | |
09d92015 | 7989 | |
c19d1205 ZW |
7990 | case OP_oSHar: |
7991 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
7992 | break; | |
09d92015 | 7993 | |
c19d1205 ZW |
7994 | case OP_oSHllar: |
7995 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
7996 | break; | |
09d92015 | 7997 | |
1b883319 AV |
7998 | case OP_RMQRZ: |
7999 | case OP_oRMQRZ: | |
8000 | po_reg_or_goto (REG_TYPE_MQ, try_rr_zr); | |
8001 | break; | |
e39c1607 SD |
8002 | |
8003 | case OP_RR_ZR: | |
1b883319 AV |
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 | ||
c19d1205 | 8011 | default: |
5be8be5d | 8012 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 8013 | } |
09d92015 | 8014 | |
c19d1205 ZW |
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. */ | |
5be8be5d | 8018 | switch (op_parse_code) |
c19d1205 ZW |
8019 | { |
8020 | case OP_oRRnpc: | |
8021 | case OP_RRnpc: | |
8022 | case OP_RRnpcb: | |
8023 | case OP_RRw: | |
b6702015 | 8024 | case OP_oRRw: |
c19d1205 ZW |
8025 | case OP_RRnpc_I0: |
8026 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
8027 | inst.error = BAD_PC; | |
8028 | break; | |
09d92015 | 8029 | |
5be8be5d DG |
8030 | case OP_oRRnpcsp: |
8031 | case OP_RRnpcsp: | |
23d00a41 | 8032 | case OP_RRnpcsp_I32: |
5be8be5d DG |
8033 | if (inst.operands[i].isreg) |
8034 | { | |
8035 | if (inst.operands[i].reg == REG_PC) | |
8036 | inst.error = BAD_PC; | |
5c8ed6a4 JW |
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 | } | |
5be8be5d DG |
8045 | } |
8046 | break; | |
8047 | ||
55881a11 | 8048 | case OP_RRnpctw: |
fa94de6b RM |
8049 | if (inst.operands[i].isreg |
8050 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
8051 | && (inst.operands[i].writeback || thumb)) |
8052 | inst.error = BAD_PC; | |
8053 | break; | |
8054 | ||
1b883319 | 8055 | case OP_RVSD_COND: |
32c36c3c AV |
8056 | case OP_VLDR: |
8057 | if (inst.operands[i].isreg) | |
8058 | break; | |
8059 | /* fall through. */ | |
1b883319 | 8060 | |
c19d1205 ZW |
8061 | case OP_CPSF: |
8062 | case OP_ENDI: | |
8063 | case OP_oROR: | |
d2cd1205 JB |
8064 | case OP_wPSR: |
8065 | case OP_rPSR: | |
c19d1205 | 8066 | case OP_COND: |
52e7f43d | 8067 | case OP_oBARRIER_I15: |
c19d1205 | 8068 | case OP_REGLST: |
4b5a202f | 8069 | case OP_CLRMLST: |
c19d1205 ZW |
8070 | case OP_VRSLST: |
8071 | case OP_VRDLST: | |
477330fc | 8072 | case OP_VRSDLST: |
efd6b359 | 8073 | case OP_VRSDVLST: |
477330fc RM |
8074 | case OP_NRDLST: |
8075 | case OP_NSTRLST: | |
35c228db AV |
8076 | case OP_MSTRLST2: |
8077 | case OP_MSTRLST4: | |
c19d1205 ZW |
8078 | if (val == FAIL) |
8079 | goto failure; | |
8080 | inst.operands[i].imm = val; | |
8081 | break; | |
a737bd4d | 8082 | |
60f993ce AV |
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 | ||
f1e1d7f3 AC |
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 | ||
1b883319 AV |
8099 | case OP_RMQRZ: |
8100 | case OP_oRMQRZ: | |
e39c1607 | 8101 | case OP_RR_ZR: |
1b883319 AV |
8102 | if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC) |
8103 | inst.error = BAD_PC; | |
8104 | break; | |
8105 | ||
a302e574 AV |
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 | ||
c19d1205 ZW |
8124 | default: |
8125 | break; | |
8126 | } | |
09d92015 | 8127 | |
c19d1205 ZW |
8128 | /* If we get here, this operand was successfully parsed. */ |
8129 | inst.operands[i].present = 1; | |
8130 | continue; | |
09d92015 | 8131 | |
c19d1205 | 8132 | bad_args: |
09d92015 | 8133 | inst.error = BAD_ARGS; |
c19d1205 ZW |
8134 | |
8135 | failure: | |
8136 | if (!backtrack_pos) | |
d252fdde PB |
8137 | { |
8138 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 8139 | default here just in case. */ |
d252fdde | 8140 | if (!inst.error) |
5ee91343 | 8141 | inst.error = BAD_SYNTAX; |
d252fdde PB |
8142 | return FAIL; |
8143 | } | |
c19d1205 ZW |
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) | |
d252fdde PB |
8151 | { |
8152 | if (!inst.error) | |
5ee91343 | 8153 | inst.error = BAD_SYNTAX; |
d252fdde PB |
8154 | return FAIL; |
8155 | } | |
c19d1205 ZW |
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; | |
09d92015 | 8163 | } |
09d92015 | 8164 | |
c19d1205 ZW |
8165 | /* Check that we have parsed all the arguments. */ |
8166 | if (*str != '\0' && !inst.error) | |
8167 | inst.error = _("garbage following instruction"); | |
09d92015 | 8168 | |
c19d1205 | 8169 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
8170 | } |
8171 | ||
c19d1205 ZW |
8172 | #undef po_char_or_fail |
8173 | #undef po_reg_or_fail | |
8174 | #undef po_reg_or_goto | |
8175 | #undef po_imm_or_fail | |
5287ad62 | 8176 | #undef po_scalar_or_fail |
52e7f43d | 8177 | #undef po_barrier_or_imm |
e07e6e58 | 8178 | |
c19d1205 | 8179 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
8180 | #define constraint(expr, err) \ |
8181 | do \ | |
c19d1205 | 8182 | { \ |
e07e6e58 NC |
8183 | if (expr) \ |
8184 | { \ | |
8185 | inst.error = err; \ | |
8186 | return; \ | |
8187 | } \ | |
c19d1205 | 8188 | } \ |
e07e6e58 | 8189 | while (0) |
c19d1205 | 8190 | |
fdfde340 JM |
8191 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
8192 | instructions are unpredictable if these registers are used. This | |
5c8ed6a4 JW |
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 | } \ | |
fdfde340 JM |
8210 | while (0) |
8211 | ||
94206790 MM |
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) \ | |
5c3696f8 | 8217 | as_tsktsk (_("use of r13 is deprecated")); \ |
94206790 MM |
8218 | while (0) |
8219 | ||
c19d1205 ZW |
8220 | /* Functions for operand encoding. ARM, then Thumb. */ |
8221 | ||
d840c081 | 8222 | #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31)) |
c19d1205 | 8223 | |
9db2f6b4 RL |
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 | |
2b0f3761 | 8228 | instruction is the same as the equivalent Coprocessor 10 instruction that |
9db2f6b4 RL |
8229 | exists for Single-Precision operation. */ |
8230 | ||
8231 | static void | |
8232 | do_scalar_fp16_v82_encode (void) | |
8233 | { | |
5ee91343 | 8234 | if (inst.cond < COND_ALWAYS) |
9db2f6b4 RL |
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 | ||
c19d1205 ZW |
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) | |
09d92015 | 8249 | { |
c19d1205 ZW |
8250 | unsigned int a, i; |
8251 | ||
4f1d6205 L |
8252 | if (val <= 0xff) |
8253 | return val; | |
8254 | ||
8255 | for (i = 2; i < 32; i += 2) | |
c19d1205 ZW |
8256 | if ((a = rotate_left (val, i)) <= 0xff) |
8257 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
8258 | ||
8259 | return FAIL; | |
09d92015 MM |
8260 | } |
8261 | ||
c19d1205 ZW |
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) | |
09d92015 | 8266 | { |
c19d1205 | 8267 | unsigned int a, i; |
09d92015 | 8268 | |
9c3c69f2 | 8269 | if (val <= 0xff) |
c19d1205 | 8270 | return val; |
a737bd4d | 8271 | |
9c3c69f2 | 8272 | for (i = 1; i <= 24; i++) |
09d92015 | 8273 | { |
9c3c69f2 | 8274 | a = val >> i; |
7af67752 | 8275 | if ((val & ~(0xffU << i)) == 0) |
9c3c69f2 | 8276 | return ((val >> i) & 0x7f) | ((32 - i) << 7); |
09d92015 | 8277 | } |
a737bd4d | 8278 | |
c19d1205 ZW |
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; | |
09d92015 | 8284 | |
c19d1205 ZW |
8285 | a = val & 0xff00; |
8286 | if (val == ((a << 16) | a)) | |
8287 | return 0x200 | (a >> 8); | |
a737bd4d | 8288 | |
c19d1205 | 8289 | return FAIL; |
09d92015 | 8290 | } |
5287ad62 | 8291 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
8292 | |
8293 | static void | |
5287ad62 JB |
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 | { | |
b1cc4aeb | 8299 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
477330fc RM |
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 | } | |
5287ad62 | 8308 | else |
477330fc RM |
8309 | { |
8310 | first_error (_("D register out of range for selected VFP version")); | |
8311 | return; | |
8312 | } | |
5287ad62 JB |
8313 | } |
8314 | ||
c19d1205 | 8315 | switch (pos) |
09d92015 | 8316 | { |
c19d1205 ZW |
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 | ||
5287ad62 JB |
8329 | case VFP_REG_Dd: |
8330 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
8331 | break; | |
5f4273c7 | 8332 | |
5287ad62 JB |
8333 | case VFP_REG_Dn: |
8334 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
8335 | break; | |
5f4273c7 | 8336 | |
5287ad62 JB |
8337 | case VFP_REG_Dm: |
8338 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
8339 | break; | |
8340 | ||
c19d1205 ZW |
8341 | default: |
8342 | abort (); | |
09d92015 | 8343 | } |
09d92015 MM |
8344 | } |
8345 | ||
c19d1205 | 8346 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 8347 | if any, is handled by md_apply_fix. */ |
09d92015 | 8348 | static void |
c19d1205 | 8349 | encode_arm_shift (int i) |
09d92015 | 8350 | { |
008a97ef RL |
8351 | /* register-shifted register. */ |
8352 | if (inst.operands[i].immisreg) | |
8353 | { | |
bf355b69 MR |
8354 | int op_index; |
8355 | for (op_index = 0; op_index <= i; ++op_index) | |
008a97ef | 8356 | { |
5689c942 RL |
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. */ | |
bf355b69 MR |
8360 | if (inst.operands[op_index].present && inst.operands[op_index].isreg |
8361 | && inst.operands[op_index].reg == REG_PC) | |
008a97ef RL |
8362 | as_warn (UNPRED_REG ("r15")); |
8363 | } | |
8364 | ||
8365 | if (inst.operands[i].imm == REG_PC) | |
8366 | as_warn (UNPRED_REG ("r15")); | |
8367 | } | |
8368 | ||
c19d1205 ZW |
8369 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
8370 | inst.instruction |= SHIFT_ROR << 5; | |
8371 | else | |
09d92015 | 8372 | { |
c19d1205 ZW |
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 | |
e2b0ab59 | 8380 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
09d92015 | 8381 | } |
c19d1205 | 8382 | } |
09d92015 | 8383 | |
c19d1205 ZW |
8384 | static void |
8385 | encode_arm_shifter_operand (int i) | |
8386 | { | |
8387 | if (inst.operands[i].isreg) | |
09d92015 | 8388 | { |
c19d1205 ZW |
8389 | inst.instruction |= inst.operands[i].reg; |
8390 | encode_arm_shift (i); | |
09d92015 | 8391 | } |
c19d1205 | 8392 | else |
a415b1cd JB |
8393 | { |
8394 | inst.instruction |= INST_IMMEDIATE; | |
e2b0ab59 | 8395 | if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE) |
a415b1cd JB |
8396 | inst.instruction |= inst.operands[i].imm; |
8397 | } | |
09d92015 MM |
8398 | } |
8399 | ||
c19d1205 | 8400 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 8401 | static void |
5b7c81bd | 8402 | encode_arm_addr_mode_common (int i, bool is_t) |
09d92015 | 8403 | { |
2b2f5df9 NC |
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 | ||
c19d1205 | 8409 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 8410 | |
c19d1205 | 8411 | if (inst.operands[i].preind) |
09d92015 | 8412 | { |
c19d1205 ZW |
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; | |
09d92015 | 8421 | |
c19d1205 ZW |
8422 | } |
8423 | else if (inst.operands[i].postind) | |
8424 | { | |
9c2799c2 | 8425 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
8426 | if (is_t) |
8427 | inst.instruction |= WRITE_BACK; | |
8428 | } | |
8429 | else /* unindexed - only for coprocessor */ | |
09d92015 | 8430 | { |
c19d1205 | 8431 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
8432 | return; |
8433 | } | |
8434 | ||
c19d1205 ZW |
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")); | |
09d92015 MM |
8441 | } |
8442 | ||
c19d1205 ZW |
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). */ | |
a737bd4d | 8447 | static void |
5b7c81bd | 8448 | encode_arm_addr_mode_2 (int i, bool is_t) |
09d92015 | 8449 | { |
5b7c81bd | 8450 | const bool is_pc = (inst.operands[i].reg == REG_PC); |
5be8be5d | 8451 | |
c19d1205 | 8452 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 8453 | |
c19d1205 | 8454 | if (inst.operands[i].immisreg) |
09d92015 | 8455 | { |
5be8be5d DG |
8456 | constraint ((inst.operands[i].imm == REG_PC |
8457 | || (is_pc && inst.operands[i].writeback)), | |
8458 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
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; | |
e2b0ab59 | 8470 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
c19d1205 ZW |
8471 | } |
8472 | } | |
09d92015 | 8473 | } |
e2b0ab59 | 8474 | else /* immediate offset in inst.relocs[0] */ |
09d92015 | 8475 | { |
e2b0ab59 | 8476 | if (is_pc && !inst.relocs[0].pc_rel) |
5be8be5d | 8477 | { |
5b7c81bd | 8478 | const bool is_load = ((inst.instruction & LOAD_BIT) != 0); |
23a10334 JZ |
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), | |
5be8be5d | 8484 | BAD_PC_ADDRESSING); |
23a10334 | 8485 | |
dc5ec521 | 8486 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
8487 | if (warn_on_deprecated |
8488 | && !is_load | |
8489 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
5c3696f8 | 8490 | as_tsktsk (_("use of PC in this instruction is deprecated")); |
5be8be5d DG |
8491 | } |
8492 | ||
e2b0ab59 | 8493 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
8494 | { |
8495 | /* Prefer + for zero encoded value. */ | |
8496 | if (!inst.operands[i].negative) | |
8497 | inst.instruction |= INDEX_UP; | |
e2b0ab59 | 8498 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM; |
26d97720 | 8499 | } |
09d92015 | 8500 | } |
09d92015 MM |
8501 | } |
8502 | ||
c19d1205 ZW |
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 | |
5b7c81bd | 8509 | encode_arm_addr_mode_3 (int i, bool is_t) |
09d92015 | 8510 | { |
c19d1205 | 8511 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 8512 | { |
c19d1205 ZW |
8513 | inst.error = _("instruction does not accept scaled register index"); |
8514 | return; | |
09d92015 | 8515 | } |
a737bd4d | 8516 | |
c19d1205 | 8517 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 8518 | |
c19d1205 ZW |
8519 | if (inst.operands[i].immisreg) |
8520 | { | |
5be8be5d | 8521 | constraint ((inst.operands[i].imm == REG_PC |
eb9f3f00 | 8522 | || (is_t && inst.operands[i].reg == REG_PC)), |
5be8be5d | 8523 | BAD_PC_ADDRESSING); |
eb9f3f00 JB |
8524 | constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback, |
8525 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
8526 | inst.instruction |= inst.operands[i].imm; |
8527 | if (!inst.operands[i].negative) | |
8528 | inst.instruction |= INDEX_UP; | |
8529 | } | |
e2b0ab59 | 8530 | else /* immediate offset in inst.relocs[0] */ |
c19d1205 | 8531 | { |
e2b0ab59 | 8532 | constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel |
5be8be5d DG |
8533 | && inst.operands[i].writeback), |
8534 | BAD_PC_WRITEBACK); | |
c19d1205 | 8535 | inst.instruction |= HWOFFSET_IMM; |
e2b0ab59 | 8536 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
8537 | { |
8538 | /* Prefer + for zero encoded value. */ | |
8539 | if (!inst.operands[i].negative) | |
8540 | inst.instruction |= INDEX_UP; | |
8541 | ||
e2b0ab59 | 8542 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8; |
26d97720 | 8543 | } |
c19d1205 | 8544 | } |
a737bd4d NC |
8545 | } |
8546 | ||
8335d6aa JW |
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. */ | |
09d92015 | 8601 | |
c19d1205 | 8602 | static int |
8335d6aa | 8603 | neon_bits_same_in_bytes (unsigned imm) |
09d92015 | 8604 | { |
8335d6aa JW |
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 | } | |
a737bd4d | 8610 | |
8335d6aa | 8611 | /* For immediate of above form, return 0bABCD. */ |
09d92015 | 8612 | |
8335d6aa JW |
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) | |
09d92015 | 8646 | { |
8335d6aa JW |
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)) | |
c19d1205 | 8657 | { |
8335d6aa JW |
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; | |
c19d1205 | 8664 | } |
a737bd4d | 8665 | |
8335d6aa JW |
8666 | if (immhi != immlo) |
8667 | return FAIL; | |
8668 | } | |
a737bd4d | 8669 | |
8335d6aa | 8670 | if (size >= 32) |
09d92015 | 8671 | { |
8335d6aa | 8672 | if (immlo == (immlo & 0x000000ff)) |
c19d1205 | 8673 | { |
8335d6aa JW |
8674 | *immbits = immlo; |
8675 | return 0x0; | |
c19d1205 | 8676 | } |
8335d6aa | 8677 | else if (immlo == (immlo & 0x0000ff00)) |
c19d1205 | 8678 | { |
8335d6aa JW |
8679 | *immbits = immlo >> 8; |
8680 | return 0x2; | |
c19d1205 | 8681 | } |
8335d6aa JW |
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; | |
09d92015 | 8706 | } |
a737bd4d | 8707 | |
8335d6aa | 8708 | if (size >= 16) |
4962c51a | 8709 | { |
8335d6aa JW |
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; | |
4962c51a MS |
8724 | } |
8725 | ||
8335d6aa JW |
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 | } | |
26d97720 | 8734 | |
8335d6aa | 8735 | return FAIL; |
c19d1205 | 8736 | } |
a737bd4d | 8737 | |
5fc177c8 | 8738 | #if defined BFD_HOST_64_BIT |
ba592044 AM |
8739 | /* Returns TRUE if double precision value V may be cast |
8740 | to single precision without loss of accuracy. */ | |
8741 | ||
5b7c81bd | 8742 | static bool |
7e30b1eb | 8743 | is_double_a_single (bfd_uint64_t v) |
ba592044 | 8744 | { |
7e30b1eb AM |
8745 | int exp = (v >> 52) & 0x7FF; |
8746 | bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL; | |
ba592044 | 8747 | |
7e30b1eb AM |
8748 | return ((exp == 0 || exp == 0x7FF |
8749 | || (exp >= 1023 - 126 && exp <= 1023 + 127)) | |
8750 | && (mantissa & 0x1FFFFFFFL) == 0); | |
ba592044 AM |
8751 | } |
8752 | ||
3739860c | 8753 | /* Returns a double precision value casted to single precision |
ba592044 AM |
8754 | (ignoring the least significant bits in exponent and mantissa). */ |
8755 | ||
8756 | static int | |
7e30b1eb | 8757 | double_to_single (bfd_uint64_t v) |
ba592044 | 8758 | { |
7af67752 AM |
8759 | unsigned int sign = (v >> 63) & 1; |
8760 | int exp = (v >> 52) & 0x7FF; | |
7e30b1eb | 8761 | bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL; |
ba592044 AM |
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 | } | |
5fc177c8 | 8784 | #endif /* BFD_HOST_64_BIT */ |
ba592044 | 8785 | |
8335d6aa JW |
8786 | enum lit_type |
8787 | { | |
8788 | CONST_THUMB, | |
8789 | CONST_ARM, | |
8790 | CONST_VEC | |
8791 | }; | |
8792 | ||
ba592044 AM |
8793 | static void do_vfp_nsyn_opcode (const char *); |
8794 | ||
e2b0ab59 | 8795 | /* inst.relocs[0].exp describes an "=expr" load pseudo-operation. |
c19d1205 ZW |
8796 | Determine whether it can be performed with a move instruction; if |
8797 | it can, convert inst.instruction to that move instruction and | |
5b7c81bd | 8798 | return true; if it can't, convert inst.instruction to a literal-pool |
c921be7d NC |
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. | |
a737bd4d | 8801 | |
c19d1205 ZW |
8802 | inst.operands[i] describes the destination register. */ |
8803 | ||
5b7c81bd AM |
8804 | static bool |
8805 | move_or_literal_pool (int i, enum lit_type t, bool mode_3) | |
c19d1205 | 8806 | { |
53365c0d | 8807 | unsigned long tbit; |
5b7c81bd AM |
8808 | bool thumb_p = (t == CONST_THUMB); |
8809 | bool arm_p = (t == CONST_ARM); | |
53365c0d PB |
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) | |
09d92015 | 8817 | { |
c19d1205 | 8818 | inst.error = _("invalid pseudo operation"); |
5b7c81bd | 8819 | return true; |
09d92015 | 8820 | } |
ba592044 | 8821 | |
e2b0ab59 AV |
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) | |
09d92015 MM |
8825 | { |
8826 | inst.error = _("constant expression expected"); | |
5b7c81bd | 8827 | return true; |
09d92015 | 8828 | } |
ba592044 | 8829 | |
e2b0ab59 AV |
8830 | if (inst.relocs[0].exp.X_op == O_constant |
8831 | || inst.relocs[0].exp.X_op == O_big) | |
8335d6aa | 8832 | { |
5fc177c8 | 8833 | #if defined BFD_HOST_64_BIT |
7e30b1eb | 8834 | bfd_uint64_t v; |
5fc177c8 | 8835 | #else |
7e30b1eb | 8836 | valueT v; |
5fc177c8 | 8837 | #endif |
e2b0ab59 | 8838 | if (inst.relocs[0].exp.X_op == O_big) |
8335d6aa | 8839 | { |
ba592044 AM |
8840 | LITTLENUM_TYPE w[X_PRECISION]; |
8841 | LITTLENUM_TYPE * l; | |
8842 | ||
e2b0ab59 | 8843 | if (inst.relocs[0].exp.X_add_number == -1) |
8335d6aa | 8844 | { |
ba592044 AM |
8845 | gen_to_words (w, X_PRECISION, E_PRECISION); |
8846 | l = w; | |
8847 | /* FIXME: Should we check words w[2..5] ? */ | |
8335d6aa | 8848 | } |
ba592044 AM |
8849 | else |
8850 | l = generic_bignum; | |
3739860c | 8851 | |
5fc177c8 | 8852 | #if defined BFD_HOST_64_BIT |
7e30b1eb AM |
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; | |
5fc177c8 | 8860 | #else |
7e30b1eb AM |
8861 | v = l[1] & LITTLENUM_MASK; |
8862 | v <<= LITTLENUM_NUMBER_OF_BITS; | |
8863 | v |= l[0] & LITTLENUM_MASK; | |
5fc177c8 | 8864 | #endif |
8335d6aa | 8865 | } |
ba592044 | 8866 | else |
e2b0ab59 | 8867 | v = inst.relocs[0].exp.X_add_number; |
ba592044 AM |
8868 | |
8869 | if (!inst.operands[i].issingle) | |
8335d6aa | 8870 | { |
12569877 | 8871 | if (thumb_p) |
8335d6aa | 8872 | { |
53445554 TP |
8873 | /* LDR should not use lead in a flag-setting instruction being |
8874 | chosen so we do not check whether movs can be used. */ | |
12569877 | 8875 | |
53445554 | 8876 | if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) |
ff8646ee | 8877 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) |
53445554 TP |
8878 | && inst.operands[i].reg != 13 |
8879 | && inst.operands[i].reg != 15) | |
12569877 | 8880 | { |
fc289b0a TP |
8881 | /* Check if on thumb2 it can be done with a mov.w, mvn or |
8882 | movw instruction. */ | |
12569877 | 8883 | unsigned int newimm; |
5b7c81bd | 8884 | bool isNegated = false; |
12569877 AM |
8885 | |
8886 | newimm = encode_thumb32_immediate (v); | |
f3da8a96 | 8887 | if (newimm == (unsigned int) FAIL) |
12569877 | 8888 | { |
582cfe03 | 8889 | newimm = encode_thumb32_immediate (~v); |
5b7c81bd | 8890 | isNegated = true; |
12569877 AM |
8891 | } |
8892 | ||
fc289b0a TP |
8893 | /* The number can be loaded with a mov.w or mvn |
8894 | instruction. */ | |
ff8646ee TP |
8895 | if (newimm != (unsigned int) FAIL |
8896 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
12569877 | 8897 | { |
fc289b0a | 8898 | inst.instruction = (0xf04f0000 /* MOV.W. */ |
582cfe03 | 8899 | | (inst.operands[i].reg << 8)); |
fc289b0a | 8900 | /* Change to MOVN. */ |
582cfe03 | 8901 | inst.instruction |= (isNegated ? 0x200000 : 0); |
12569877 AM |
8902 | inst.instruction |= (newimm & 0x800) << 15; |
8903 | inst.instruction |= (newimm & 0x700) << 4; | |
8904 | inst.instruction |= (newimm & 0x0ff); | |
5b7c81bd | 8905 | return true; |
12569877 | 8906 | } |
fc289b0a | 8907 | /* The number can be loaded with a movw instruction. */ |
ff8646ee TP |
8908 | else if ((v & ~0xFFFF) == 0 |
8909 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
3739860c | 8910 | { |
582cfe03 | 8911 | int imm = v & 0xFFFF; |
12569877 | 8912 | |
582cfe03 | 8913 | inst.instruction = 0xf2400000; /* MOVW. */ |
12569877 AM |
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); | |
8fe9a076 AV |
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; | |
5b7c81bd | 8924 | return true; |
12569877 AM |
8925 | } |
8926 | } | |
8335d6aa | 8927 | } |
12569877 | 8928 | else if (arm_p) |
ba592044 AM |
8929 | { |
8930 | int value = encode_arm_immediate (v); | |
12569877 | 8931 | |
ba592044 AM |
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; | |
5b7c81bd | 8938 | return true; |
ba592044 | 8939 | } |
8335d6aa | 8940 | |
ba592044 AM |
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; | |
5b7c81bd | 8948 | return true; |
ba592044 AM |
8949 | } |
8950 | } | |
934c2632 | 8951 | else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) |
8335d6aa | 8952 | { |
ba592044 AM |
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 | |
e2b0ab59 | 8958 | : inst.relocs[0].exp.X_unsigned |
ba592044 AM |
8959 | ? 0 |
8960 | : ((bfd_int64_t)((int) immlo)) >> 32; | |
5b7c81bd | 8961 | int cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits, |
ba592044 AM |
8962 | &op, 64, NT_invtype); |
8963 | ||
8964 | if (cmode == FAIL) | |
8965 | { | |
8966 | neon_invert_size (&immlo, &immhi, 64); | |
8967 | op = !op; | |
5b7c81bd | 8968 | cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits, |
ba592044 AM |
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) | |
eff0bc54 | 8982 | inst.instruction |= (0x7U << 29) | (0xF << 24); |
ba592044 | 8983 | else |
eff0bc54 | 8984 | inst.instruction |= (0xFU << 28) | (0x1 << 25); |
ba592044 | 8985 | neon_write_immbits (immbits); |
5b7c81bd | 8986 | return true; |
ba592044 | 8987 | } |
8335d6aa JW |
8988 | } |
8989 | } | |
8335d6aa | 8990 | |
ba592044 AM |
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)) | |
8335d6aa | 8997 | { |
ba592044 AM |
8998 | inst.operands[1].imm = |
8999 | neon_qfloat_bits (v); | |
9000 | do_vfp_nsyn_opcode ("fconsts"); | |
5b7c81bd | 9001 | return true; |
8335d6aa | 9002 | } |
5fc177c8 NC |
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 | |
ba592044 AM |
9010 | else if (!inst.operands[1].issingle |
9011 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
8335d6aa | 9012 | { |
ba592044 AM |
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"); | |
5b7c81bd | 9019 | return true; |
ba592044 | 9020 | } |
8335d6aa | 9021 | } |
5fc177c8 | 9022 | #endif |
8335d6aa JW |
9023 | } |
9024 | } | |
9025 | ||
9026 | if (add_to_lit_pool ((!inst.operands[i].isvec | |
9027 | || inst.operands[i].issingle) ? 4 : 8) == FAIL) | |
5b7c81bd | 9028 | return true; |
8335d6aa JW |
9029 | |
9030 | inst.operands[1].reg = REG_PC; | |
9031 | inst.operands[1].isreg = 1; | |
9032 | inst.operands[1].preind = 1; | |
e2b0ab59 AV |
9033 | inst.relocs[0].pc_rel = 1; |
9034 | inst.relocs[0].type = (thumb_p | |
8335d6aa JW |
9035 | ? BFD_RELOC_ARM_THUMB_OFFSET |
9036 | : (mode_3 | |
9037 | ? BFD_RELOC_ARM_HWLITERAL | |
9038 | : BFD_RELOC_ARM_LITERAL)); | |
5b7c81bd | 9039 | return false; |
8335d6aa JW |
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 | { | |
99b2a2dd NC |
9055 | /* PR 18256 */ |
9056 | if (! inst.operands[0].isvec) | |
9057 | { | |
9058 | inst.error = _("invalid co-processor operand"); | |
9059 | return FAIL; | |
9060 | } | |
5b7c81bd | 9061 | if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/false)) |
8335d6aa JW |
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) | |
09d92015 | 9086 | { |
8335d6aa | 9087 | if (inst.operands[i].reg == REG_PC) |
c19d1205 | 9088 | { |
8335d6aa JW |
9089 | inst.error = _("pc may not be used with write-back"); |
9090 | return FAIL; | |
c19d1205 | 9091 | } |
8335d6aa | 9092 | if (!wb_ok) |
c19d1205 | 9093 | { |
8335d6aa JW |
9094 | inst.error = _("instruction does not support writeback"); |
9095 | return FAIL; | |
c19d1205 | 9096 | } |
8335d6aa | 9097 | inst.instruction |= WRITE_BACK; |
09d92015 MM |
9098 | } |
9099 | ||
8335d6aa | 9100 | if (reloc_override) |
e2b0ab59 AV |
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) | |
c19d1205 | 9105 | { |
8335d6aa | 9106 | if (thumb_mode) |
e2b0ab59 | 9107 | inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM; |
8335d6aa | 9108 | else |
e2b0ab59 | 9109 | inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM; |
c19d1205 | 9110 | } |
8335d6aa JW |
9111 | |
9112 | /* Prefer + for zero encoded value. */ | |
9113 | if (!inst.operands[i].negative) | |
9114 | inst.instruction |= INDEX_UP; | |
9115 | ||
9116 | return SUCCESS; | |
09d92015 MM |
9117 | } |
9118 | ||
5f4273c7 | 9119 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
9120 | First some generics; their names are taken from the conventional |
9121 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 9122 | |
a737bd4d | 9123 | static void |
c19d1205 | 9124 | do_noargs (void) |
09d92015 | 9125 | { |
c19d1205 | 9126 | } |
a737bd4d | 9127 | |
c19d1205 ZW |
9128 | static void |
9129 | do_rd (void) | |
9130 | { | |
9131 | inst.instruction |= inst.operands[0].reg << 12; | |
9132 | } | |
a737bd4d | 9133 | |
16a1fa25 TP |
9134 | static void |
9135 | do_rn (void) | |
9136 | { | |
9137 | inst.instruction |= inst.operands[0].reg << 16; | |
9138 | } | |
9139 | ||
c19d1205 ZW |
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 | } | |
09d92015 | 9146 | |
9eb6c0f1 MGD |
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 | ||
c19d1205 ZW |
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 | } | |
a737bd4d | 9160 | |
c19d1205 ZW |
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 | } | |
09d92015 | 9167 | |
4ed7ed8d TP |
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 | ||
5b7c81bd | 9175 | static bool |
59d09be6 MGD |
9176 | check_obsolete (const arm_feature_set *feature, const char *msg) |
9177 | { | |
9178 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
9179 | { | |
5c3696f8 | 9180 | as_tsktsk ("%s", msg); |
5b7c81bd | 9181 | return true; |
59d09be6 MGD |
9182 | } |
9183 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
9184 | { | |
9185 | as_bad ("%s", msg); | |
5b7c81bd | 9186 | return true; |
59d09be6 MGD |
9187 | } |
9188 | ||
5b7c81bd | 9189 | return false; |
59d09be6 MGD |
9190 | } |
9191 | ||
c19d1205 ZW |
9192 | static void |
9193 | do_rd_rm_rn (void) | |
9194 | { | |
9a64e435 | 9195 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 9196 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 9197 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
9198 | { |
9199 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
9200 | _("Rn must not overlap other operands")); | |
9201 | ||
59d09be6 MGD |
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)) | |
5c3696f8 | 9208 | as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7")); |
56adecf4 | 9209 | } |
59d09be6 | 9210 | |
c19d1205 ZW |
9211 | inst.instruction |= inst.operands[0].reg << 12; |
9212 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 9213 | inst.instruction |= Rn << 16; |
c19d1205 | 9214 | } |
09d92015 | 9215 | |
c19d1205 ZW |
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 | } | |
a737bd4d | 9223 | |
c19d1205 ZW |
9224 | static void |
9225 | do_rm_rd_rn (void) | |
9226 | { | |
5be8be5d | 9227 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
e2b0ab59 AV |
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), | |
5be8be5d | 9231 | BAD_ADDR_MODE); |
c19d1205 ZW |
9232 | inst.instruction |= inst.operands[0].reg; |
9233 | inst.instruction |= inst.operands[1].reg << 12; | |
9234 | inst.instruction |= inst.operands[2].reg << 16; | |
9235 | } | |
09d92015 | 9236 | |
c19d1205 ZW |
9237 | static void |
9238 | do_imm0 (void) | |
9239 | { | |
9240 | inst.instruction |= inst.operands[0].imm; | |
9241 | } | |
09d92015 | 9242 | |
c19d1205 ZW |
9243 | static void |
9244 | do_rd_cpaddr (void) | |
9245 | { | |
9246 | inst.instruction |= inst.operands[0].reg << 12; | |
5b7c81bd | 9247 | encode_arm_cp_address (1, true, true, 0); |
09d92015 | 9248 | } |
a737bd4d | 9249 | |
c19d1205 ZW |
9250 | /* ARM instructions, in alphabetical order by function name (except |
9251 | that wrapper functions appear immediately after the function they | |
9252 | wrap). */ | |
09d92015 | 9253 | |
c19d1205 ZW |
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". */ | |
09d92015 MM |
9256 | |
9257 | static void | |
c19d1205 | 9258 | do_adr (void) |
09d92015 | 9259 | { |
c19d1205 | 9260 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 9261 | |
c19d1205 ZW |
9262 | /* Frag hacking will turn this into a sub instruction if the offset turns |
9263 | out to be negative. */ | |
e2b0ab59 AV |
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; | |
52a86f84 | 9267 | |
fc6141f0 | 9268 | if (support_interwork |
e2b0ab59 AV |
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; | |
c19d1205 | 9274 | } |
b99bd4ef | 9275 | |
c19d1205 ZW |
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)" */ | |
b99bd4ef | 9280 | |
c19d1205 ZW |
9281 | static void |
9282 | do_adrl (void) | |
9283 | { | |
9284 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 9285 | |
c19d1205 ZW |
9286 | /* Frag hacking will turn this into a sub instruction if the offset turns |
9287 | out to be negative. */ | |
e2b0ab59 AV |
9288 | inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE; |
9289 | inst.relocs[0].pc_rel = 1; | |
c19d1205 | 9290 | inst.size = INSN_SIZE * 2; |
e2b0ab59 | 9291 | inst.relocs[0].exp.X_add_number -= 8; |
52a86f84 | 9292 | |
fc6141f0 | 9293 | if (support_interwork |
e2b0ab59 AV |
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; | |
b99bd4ef NC |
9299 | } |
9300 | ||
b99bd4ef | 9301 | static void |
c19d1205 | 9302 | do_arit (void) |
b99bd4ef | 9303 | { |
e2b0ab59 AV |
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 , | |
a9f02af8 | 9306 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
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 | } | |
b99bd4ef | 9313 | |
62b3e311 PB |
9314 | static void |
9315 | do_barrier (void) | |
9316 | { | |
9317 | if (inst.operands[0].present) | |
ccb84d65 | 9318 | inst.instruction |= inst.operands[0].imm; |
62b3e311 PB |
9319 | else |
9320 | inst.instruction |= 0xf; | |
9321 | } | |
9322 | ||
c19d1205 ZW |
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 | } | |
b99bd4ef | 9334 | |
c19d1205 ZW |
9335 | static void |
9336 | do_bfi (void) | |
9337 | { | |
9338 | unsigned int msb; | |
b99bd4ef | 9339 | |
c19d1205 ZW |
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; | |
b99bd4ef | 9344 | |
c19d1205 ZW |
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; | |
b99bd4ef NC |
9353 | } |
9354 | ||
b99bd4ef | 9355 | static void |
c19d1205 | 9356 | do_bfx (void) |
b99bd4ef | 9357 | { |
c19d1205 ZW |
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 | } | |
09d92015 | 9365 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 9371 | |
c19d1205 ZW |
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; | |
09d92015 | 9377 | |
c19d1205 ZW |
9378 | /* Bottom 4 of 16 bits to bits 3:0. */ |
9379 | inst.instruction |= inst.operands[0].imm & 0xf; | |
9380 | } | |
09d92015 | 9381 | |
c19d1205 ZW |
9382 | static void |
9383 | encode_branch (int default_reloc) | |
9384 | { | |
9385 | if (inst.operands[0].hasreloc) | |
9386 | { | |
0855e32b NS |
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)'")); | |
e2b0ab59 | 9390 | inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 |
0855e32b NS |
9391 | ? BFD_RELOC_ARM_PLT32 |
9392 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 9393 | } |
b99bd4ef | 9394 | else |
e2b0ab59 AV |
9395 | inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc; |
9396 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
9397 | } |
9398 | ||
b99bd4ef | 9399 | static void |
c19d1205 | 9400 | do_branch (void) |
b99bd4ef | 9401 | { |
39b41c9c PB |
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); | |
c19d1205 | 9424 | } |
b99bd4ef | 9425 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 9433 | |
c19d1205 ZW |
9434 | static void |
9435 | do_blx (void) | |
9436 | { | |
9437 | if (inst.operands[0].isreg) | |
b99bd4ef | 9438 | { |
c19d1205 ZW |
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")); | |
b99bd4ef | 9443 | |
c19d1205 ZW |
9444 | inst.instruction |= inst.operands[0].reg; |
9445 | } | |
9446 | else | |
b99bd4ef | 9447 | { |
c19d1205 | 9448 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
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. */ | |
c19d1205 | 9452 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 9453 | inst.instruction = 0xfa000000; |
267bf995 | 9454 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 9455 | } |
c19d1205 ZW |
9456 | } |
9457 | ||
9458 | static void | |
9459 | do_bx (void) | |
9460 | { | |
5b7c81bd | 9461 | bool want_reloc; |
845b51d6 | 9462 | |
c19d1205 ZW |
9463 | if (inst.operands[0].reg == REG_PC) |
9464 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 9465 | |
c19d1205 | 9466 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
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); | |
4d354d8b TP |
9470 | if (!ARM_FEATURE_ZERO (selected_object_arch) |
9471 | && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5)) | |
5b7c81bd | 9472 | want_reloc = true; |
845b51d6 | 9473 | |
5ad34203 | 9474 | #ifdef OBJ_ELF |
845b51d6 | 9475 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 9476 | #endif |
5b7c81bd | 9477 | want_reloc = false; |
845b51d6 PB |
9478 | |
9479 | if (want_reloc) | |
e2b0ab59 | 9480 | inst.relocs[0].type = BFD_RELOC_ARM_V4BX; |
09d92015 MM |
9481 | } |
9482 | ||
c19d1205 ZW |
9483 | |
9484 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
9485 | |
9486 | static void | |
c19d1205 | 9487 | do_bxj (void) |
a737bd4d | 9488 | { |
c19d1205 ZW |
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; | |
a737bd4d NC |
9493 | } |
9494 | ||
c19d1205 ZW |
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 | } | |
a737bd4d NC |
9508 | |
9509 | static void | |
c19d1205 | 9510 | do_cmp (void) |
a737bd4d | 9511 | { |
c19d1205 ZW |
9512 | inst.instruction |= inst.operands[0].reg << 16; |
9513 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
9514 | } |
9515 | ||
c19d1205 ZW |
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. */ | |
09d92015 | 9523 | |
dcbd0d71 MGD |
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. */ | |
823d2571 | 9544 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9545 | DEPR_ACCESS_V8, NULL}, |
9546 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
823d2571 | 9547 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9548 | DEPR_ACCESS_V8, NULL}, |
9549 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
823d2571 | 9550 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9551 | DEPR_ACCESS_V8, NULL}, |
9552 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
823d2571 | 9553 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
9554 | DEPR_ACCESS_V8, NULL}, |
9555 | {14, 6, 0, 0, 0, /* TEECR. */ | |
823d2571 | 9556 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
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 | ||
09d92015 | 9565 | static void |
c19d1205 | 9566 | do_co_reg (void) |
09d92015 | 9567 | { |
fdfde340 | 9568 | unsigned Rd; |
dcbd0d71 | 9569 | size_t i; |
fdfde340 JM |
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); | |
5c8ed6a4 | 9578 | else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
fdfde340 JM |
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 | ||
dcbd0d71 MGD |
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 | { | |
b10bf8c5 | 9600 | if (! ARM_CPU_IS_ANY (cpu_variant) |
477330fc | 9601 | && warn_on_deprecated |
dcbd0d71 | 9602 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) |
5c3696f8 | 9603 | as_tsktsk ("%s", r->dep_msg); |
dcbd0d71 MGD |
9604 | } |
9605 | } | |
fdfde340 | 9606 | |
c19d1205 ZW |
9607 | inst.instruction |= inst.operands[0].reg << 8; |
9608 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 9609 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
9610 | inst.instruction |= inst.operands[3].reg << 16; |
9611 | inst.instruction |= inst.operands[4].reg; | |
9612 | inst.instruction |= inst.operands[5].imm << 5; | |
9613 | } | |
09d92015 | 9614 | |
c19d1205 ZW |
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 | |
b99bd4ef | 9620 | |
c19d1205 | 9621 | Two XScale instructions are special cases of these: |
09d92015 | 9622 | |
c19d1205 ZW |
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 | |
b99bd4ef | 9625 | |
5f4273c7 | 9626 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 9627 | |
c19d1205 ZW |
9628 | static void |
9629 | do_co_reg2c (void) | |
9630 | { | |
fdfde340 JM |
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 | ||
873f10f0 TC |
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 | ||
c19d1205 ZW |
9655 | inst.instruction |= inst.operands[0].reg << 8; |
9656 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
9657 | inst.instruction |= Rd << 12; |
9658 | inst.instruction |= Rn << 16; | |
c19d1205 | 9659 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
9660 | } |
9661 | ||
c19d1205 ZW |
9662 | static void |
9663 | do_cpsi (void) | |
9664 | { | |
9665 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
9666 | if (inst.operands[1].present) |
9667 | { | |
9668 | inst.instruction |= CPSI_MMOD; | |
9669 | inst.instruction |= inst.operands[1].imm; | |
9670 | } | |
c19d1205 | 9671 | } |
b99bd4ef | 9672 | |
62b3e311 PB |
9673 | static void |
9674 | do_dbg (void) | |
9675 | { | |
9676 | inst.instruction |= inst.operands[0].imm; | |
9677 | } | |
9678 | ||
eea54501 MGD |
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 | ||
b99bd4ef | 9698 | static void |
c19d1205 | 9699 | do_it (void) |
b99bd4ef | 9700 | { |
c19d1205 | 9701 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
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 | ||
c19d1205 | 9706 | inst.size = 0; |
e07e6e58 NC |
9707 | if (unified_syntax) |
9708 | { | |
5ee91343 AV |
9709 | set_pred_insn_type (IT_INSN); |
9710 | now_pred.mask = (inst.instruction & 0xf) | 0x10; | |
9711 | now_pred.cc = inst.operands[0].imm; | |
e07e6e58 | 9712 | } |
09d92015 | 9713 | } |
b99bd4ef | 9714 | |
6530b175 NC |
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 | ||
09d92015 | 9724 | static void |
6530b175 | 9725 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 9726 | { |
c19d1205 ZW |
9727 | int base_reg = inst.operands[0].reg; |
9728 | int range = inst.operands[1].imm; | |
6530b175 | 9729 | int one_reg; |
ea6ef066 | 9730 | |
c19d1205 ZW |
9731 | inst.instruction |= base_reg << 16; |
9732 | inst.instruction |= range; | |
ea6ef066 | 9733 | |
c19d1205 ZW |
9734 | if (inst.operands[1].writeback) |
9735 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 9736 | |
c19d1205 | 9737 | if (inst.operands[0].writeback) |
ea6ef066 | 9738 | { |
c19d1205 ZW |
9739 | inst.instruction |= WRITE_BACK; |
9740 | /* Check for unpredictable uses of writeback. */ | |
9741 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 9742 | { |
c19d1205 ZW |
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")); | |
09d92015 | 9760 | } |
ea6ef066 | 9761 | } |
6530b175 NC |
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 | ||
4f588891 NC |
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 | ||
6530b175 NC |
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 | { | |
5b7c81bd | 9783 | encode_ldmstm (/*from_push_pop_mnem=*/false); |
a737bd4d NC |
9784 | } |
9785 | ||
c19d1205 ZW |
9786 | /* ARMv5TE load-consecutive (argument parse) |
9787 | Mode is like LDRH. | |
9788 | ||
9789 | LDRccD R, mode | |
9790 | STRccD R, mode. */ | |
9791 | ||
a737bd4d | 9792 | static void |
c19d1205 | 9793 | do_ldrd (void) |
a737bd4d | 9794 | { |
c19d1205 | 9795 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 9796 | _("first transfer register must be even")); |
c19d1205 ZW |
9797 | constraint (inst.operands[1].present |
9798 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 9799 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
9800 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
9801 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 9802 | |
c19d1205 ZW |
9803 | if (!inst.operands[1].present) |
9804 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 9805 | |
c56791bb RE |
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. */ | |
ea6ef066 | 9809 | |
c56791bb RE |
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")); | |
b05fe5cf | 9814 | |
c56791bb RE |
9815 | if (!(inst.instruction & V4_STR_BIT)) |
9816 | { | |
c19d1205 | 9817 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
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")); | |
b05fe5cf | 9823 | } |
c19d1205 | 9824 | inst.instruction |= inst.operands[0].reg << 12; |
5b7c81bd | 9825 | encode_arm_addr_mode_3 (2, /*is_t=*/false); |
b05fe5cf ZW |
9826 | } |
9827 | ||
9828 | static void | |
c19d1205 | 9829 | do_ldrex (void) |
b05fe5cf | 9830 | { |
c19d1205 ZW |
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 | |
01cfc07f NC |
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); | |
b05fe5cf | 9848 | |
e2b0ab59 AV |
9849 | constraint (inst.relocs[0].exp.X_op != O_constant |
9850 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9851 | _("offset must be zero in ARM encoding")); |
b05fe5cf | 9852 | |
5be8be5d DG |
9853 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
9854 | ||
c19d1205 ZW |
9855 | inst.instruction |= inst.operands[0].reg << 12; |
9856 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 9857 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b05fe5cf ZW |
9858 | } |
9859 | ||
9860 | static void | |
c19d1205 | 9861 | do_ldrexd (void) |
b05fe5cf | 9862 | { |
c19d1205 ZW |
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")); | |
b05fe5cf | 9871 | |
c19d1205 ZW |
9872 | inst.instruction |= inst.operands[0].reg << 12; |
9873 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
9874 | } |
9875 | ||
1be5fd2e NC |
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 | |
e2b0ab59 | 9884 | && (inst.relocs[0].exp.X_add_number & 0x3)), |
de194d85 | 9885 | _("ldr to register 15 must be 4-byte aligned")); |
1be5fd2e NC |
9886 | } |
9887 | ||
b05fe5cf | 9888 | static void |
c19d1205 | 9889 | do_ldst (void) |
b05fe5cf | 9890 | { |
c19d1205 ZW |
9891 | inst.instruction |= inst.operands[0].reg << 12; |
9892 | if (!inst.operands[1].isreg) | |
5b7c81bd | 9893 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/false)) |
b05fe5cf | 9894 | return; |
5b7c81bd | 9895 | encode_arm_addr_mode_2 (1, /*is_t=*/false); |
1be5fd2e | 9896 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
9897 | } |
9898 | ||
9899 | static void | |
c19d1205 | 9900 | do_ldstt (void) |
b05fe5cf | 9901 | { |
c19d1205 ZW |
9902 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9903 | reject [Rn,...]. */ | |
9904 | if (inst.operands[1].preind) | |
b05fe5cf | 9905 | { |
e2b0ab59 AV |
9906 | constraint (inst.relocs[0].exp.X_op != O_constant |
9907 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9908 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9909 | |
c19d1205 ZW |
9910 | inst.operands[1].preind = 0; |
9911 | inst.operands[1].postind = 1; | |
9912 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9913 | } |
c19d1205 | 9914 | inst.instruction |= inst.operands[0].reg << 12; |
5b7c81bd | 9915 | encode_arm_addr_mode_2 (1, /*is_t=*/true); |
c19d1205 | 9916 | } |
b05fe5cf | 9917 | |
c19d1205 | 9918 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 9919 | |
c19d1205 ZW |
9920 | static void |
9921 | do_ldstv4 (void) | |
9922 | { | |
ff4a8d2b | 9923 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
9924 | inst.instruction |= inst.operands[0].reg << 12; |
9925 | if (!inst.operands[1].isreg) | |
5b7c81bd | 9926 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/true)) |
b05fe5cf | 9927 | return; |
5b7c81bd | 9928 | encode_arm_addr_mode_3 (1, /*is_t=*/false); |
b05fe5cf ZW |
9929 | } |
9930 | ||
9931 | static void | |
c19d1205 | 9932 | do_ldsttv4 (void) |
b05fe5cf | 9933 | { |
c19d1205 ZW |
9934 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9935 | reject [Rn,...]. */ | |
9936 | if (inst.operands[1].preind) | |
b05fe5cf | 9937 | { |
e2b0ab59 AV |
9938 | constraint (inst.relocs[0].exp.X_op != O_constant |
9939 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9940 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9941 | |
c19d1205 ZW |
9942 | inst.operands[1].preind = 0; |
9943 | inst.operands[1].postind = 1; | |
9944 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9945 | } |
c19d1205 | 9946 | inst.instruction |= inst.operands[0].reg << 12; |
5b7c81bd | 9947 | encode_arm_addr_mode_3 (1, /*is_t=*/true); |
c19d1205 | 9948 | } |
b05fe5cf | 9949 | |
c19d1205 ZW |
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; | |
5b7c81bd | 9957 | encode_arm_cp_address (2, true, true, 0); |
b05fe5cf ZW |
9958 | } |
9959 | ||
b05fe5cf | 9960 | static void |
c19d1205 | 9961 | do_mlas (void) |
b05fe5cf | 9962 | { |
8fb9d7b9 | 9963 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 9964 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 9965 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 9966 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 9967 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 9968 | |
c19d1205 ZW |
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; | |
c19d1205 | 9973 | } |
b05fe5cf | 9974 | |
c19d1205 ZW |
9975 | static void |
9976 | do_mov (void) | |
9977 | { | |
e2b0ab59 AV |
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 , | |
a9f02af8 | 9980 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
9981 | inst.instruction |= inst.operands[0].reg << 12; |
9982 | encode_arm_shifter_operand (1); | |
9983 | } | |
b05fe5cf | 9984 | |
c19d1205 ZW |
9985 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
9986 | static void | |
9987 | do_mov16 (void) | |
9988 | { | |
b6895b4f | 9989 | bfd_vma imm; |
5b7c81bd | 9990 | bool top; |
b6895b4f PB |
9991 | |
9992 | top = (inst.instruction & 0x00400000) != 0; | |
e2b0ab59 | 9993 | constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW, |
33eaf5de | 9994 | _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 9995 | constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT, |
33eaf5de | 9996 | _(":upper16: not allowed in this instruction")); |
c19d1205 | 9997 | inst.instruction |= inst.operands[0].reg << 12; |
e2b0ab59 | 9998 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 9999 | { |
e2b0ab59 | 10000 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
10001 | /* The value is in two pieces: 0:11, 16:19. */ |
10002 | inst.instruction |= (imm & 0x00000fff); | |
10003 | inst.instruction |= (imm & 0x0000f000) << 4; | |
10004 | } | |
b05fe5cf | 10005 | } |
b99bd4ef | 10006 | |
037e8744 JB |
10007 | static int |
10008 | do_vfp_nsyn_mrs (void) | |
10009 | { | |
10010 | if (inst.operands[0].isvec) | |
10011 | { | |
10012 | if (inst.operands[1].reg != 1) | |
477330fc | 10013 | first_error (_("operand 1 must be FPSCR")); |
037e8744 JB |
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; | |
5f4273c7 | 10022 | |
037e8744 JB |
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 | ||
f7c21dc7 NC |
10037 | static void |
10038 | do_vmrs (void) | |
10039 | { | |
10040 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 10041 | |
16d02dc9 | 10042 | if (thumb_mode && Rt == REG_SP) |
f7c21dc7 NC |
10043 | { |
10044 | inst.error = BAD_SP; | |
10045 | return; | |
10046 | } | |
10047 | ||
ba6cd17f SD |
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 | } | |
40c7d507 | 10084 | |
f7c21dc7 | 10085 | /* APSR_ sets isvec. All other refs to PC are illegal. */ |
16d02dc9 | 10086 | if (!inst.operands[0].isvec && Rt == REG_PC) |
f7c21dc7 NC |
10087 | { |
10088 | inst.error = BAD_PC; | |
10089 | return; | |
10090 | } | |
10091 | ||
16d02dc9 JB |
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); | |
f7c21dc7 NC |
10095 | inst.instruction |= (Rt << 12); |
10096 | } | |
10097 | ||
10098 | static void | |
10099 | do_vmsr (void) | |
10100 | { | |
10101 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 10102 | |
f7c21dc7 NC |
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 | ||
ba6cd17f SD |
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 | } | |
40c7d507 | 10147 | |
16d02dc9 JB |
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); | |
f7c21dc7 NC |
10151 | inst.instruction |= (Rt << 12); |
10152 | } | |
10153 | ||
b99bd4ef | 10154 | static void |
c19d1205 | 10155 | do_mrs (void) |
b99bd4ef | 10156 | { |
90ec0d68 MGD |
10157 | unsigned br; |
10158 | ||
037e8744 JB |
10159 | if (do_vfp_nsyn_mrs () == SUCCESS) |
10160 | return; | |
10161 | ||
ff4a8d2b | 10162 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 10163 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
10164 | |
10165 | if (inst.operands[1].isreg) | |
10166 | { | |
10167 | br = inst.operands[1].reg; | |
806ab1c0 | 10168 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000)) |
90ec0d68 MGD |
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), | |
d2cd1205 | 10176 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
10177 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
10178 | } | |
10179 | ||
10180 | inst.instruction |= br; | |
c19d1205 | 10181 | } |
b99bd4ef | 10182 | |
c19d1205 ZW |
10183 | /* Two possible forms: |
10184 | "{C|S}PSR_<field>, Rm", | |
10185 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 10186 | |
c19d1205 ZW |
10187 | static void |
10188 | do_msr (void) | |
10189 | { | |
037e8744 JB |
10190 | if (do_vfp_nsyn_msr () == SUCCESS) |
10191 | return; | |
10192 | ||
c19d1205 ZW |
10193 | inst.instruction |= inst.operands[0].imm; |
10194 | if (inst.operands[1].isreg) | |
10195 | inst.instruction |= inst.operands[1].reg; | |
10196 | else | |
b99bd4ef | 10197 | { |
c19d1205 | 10198 | inst.instruction |= INST_IMMEDIATE; |
e2b0ab59 AV |
10199 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
10200 | inst.relocs[0].pc_rel = 0; | |
b99bd4ef | 10201 | } |
b99bd4ef NC |
10202 | } |
10203 | ||
c19d1205 ZW |
10204 | static void |
10205 | do_mul (void) | |
a737bd4d | 10206 | { |
ff4a8d2b NC |
10207 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
10208 | ||
c19d1205 ZW |
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; | |
a737bd4d | 10214 | |
8fb9d7b9 MS |
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")); | |
a737bd4d NC |
10218 | } |
10219 | ||
c19d1205 ZW |
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. */ | |
b99bd4ef NC |
10225 | |
10226 | static void | |
c19d1205 | 10227 | do_mull (void) |
b99bd4ef | 10228 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 10233 | |
682b27ad PB |
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 | |
c19d1205 | 10240 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 10241 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
10242 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
10243 | } | |
b99bd4ef | 10244 | |
c19d1205 ZW |
10245 | static void |
10246 | do_nop (void) | |
10247 | { | |
e7495e45 NS |
10248 | if (inst.operands[0].present |
10249 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
10250 | { |
10251 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
10252 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
10253 | inst.instruction |= 0x0320f000; |
10254 | if (inst.operands[0].present) | |
10255 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 10256 | } |
b99bd4ef NC |
10257 | } |
10258 | ||
c19d1205 ZW |
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. */ | |
b99bd4ef NC |
10263 | |
10264 | static void | |
c19d1205 | 10265 | do_pkhbt (void) |
b99bd4ef | 10266 | { |
c19d1205 ZW |
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 | } | |
b99bd4ef | 10273 | |
c19d1205 | 10274 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 10275 | |
c19d1205 ZW |
10276 | static void |
10277 | do_pkhtb (void) | |
10278 | { | |
10279 | if (!inst.operands[3].present) | |
b99bd4ef | 10280 | { |
c19d1205 ZW |
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; | |
b99bd4ef NC |
10287 | } |
10288 | else | |
10289 | { | |
c19d1205 ZW |
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); | |
b99bd4ef NC |
10294 | } |
10295 | } | |
10296 | ||
c19d1205 | 10297 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 10298 | MP Extensions: Preload for write |
c19d1205 | 10299 | |
60e5ef9f | 10300 | PLD(W) <addr_mode> |
c19d1205 ZW |
10301 | |
10302 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
10303 | |
10304 | static void | |
c19d1205 | 10305 | do_pld (void) |
b99bd4ef | 10306 | { |
c19d1205 ZW |
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")); | |
5b7c81bd | 10315 | encode_arm_addr_mode_2 (0, /*is_t=*/false); |
c19d1205 | 10316 | } |
b99bd4ef | 10317 | |
62b3e311 PB |
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")); | |
5b7c81bd | 10330 | encode_arm_addr_mode_2 (0, /*is_t=*/false); |
62b3e311 PB |
10331 | inst.instruction &= ~PRE_INDEX; |
10332 | } | |
10333 | ||
c19d1205 ZW |
10334 | static void |
10335 | do_push_pop (void) | |
10336 | { | |
5e0d7f77 MP |
10337 | constraint (inst.operands[0].writeback, |
10338 | _("push/pop do not support {reglist}^")); | |
c19d1205 ZW |
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; | |
5b7c81bd | 10344 | encode_ldmstm (/*from_push_pop_mnem=*/true); |
c19d1205 | 10345 | } |
b99bd4ef | 10346 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 10352 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 10360 | |
c19d1205 | 10361 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 10362 | |
c19d1205 ZW |
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; | |
b99bd4ef | 10369 | |
c19d1205 ZW |
10370 | if (inst.operands[3].present) |
10371 | encode_arm_shift (3); | |
b99bd4ef NC |
10372 | } |
10373 | ||
c19d1205 | 10374 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
10375 | |
10376 | static void | |
c19d1205 | 10377 | do_usat (void) |
b99bd4ef | 10378 | { |
c19d1205 ZW |
10379 | inst.instruction |= inst.operands[0].reg << 12; |
10380 | inst.instruction |= inst.operands[1].imm << 16; | |
10381 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 10382 | |
c19d1205 ZW |
10383 | if (inst.operands[3].present) |
10384 | encode_arm_shift (3); | |
b99bd4ef NC |
10385 | } |
10386 | ||
c19d1205 | 10387 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
10388 | |
10389 | static void | |
c19d1205 | 10390 | do_ssat16 (void) |
09d92015 | 10391 | { |
c19d1205 ZW |
10392 | inst.instruction |= inst.operands[0].reg << 12; |
10393 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
10394 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
10395 | } |
10396 | ||
c19d1205 ZW |
10397 | static void |
10398 | do_usat16 (void) | |
a737bd4d | 10399 | { |
c19d1205 ZW |
10400 | inst.instruction |= inst.operands[0].reg << 12; |
10401 | inst.instruction |= inst.operands[1].imm << 16; | |
10402 | inst.instruction |= inst.operands[2].reg; | |
10403 | } | |
a737bd4d | 10404 | |
c19d1205 ZW |
10405 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
10406 | preserving the other bits. | |
a737bd4d | 10407 | |
c19d1205 ZW |
10408 | setend <endian_specifier>, where <endian_specifier> is either |
10409 | BE or LE. */ | |
a737bd4d | 10410 | |
c19d1205 ZW |
10411 | static void |
10412 | do_setend (void) | |
10413 | { | |
12e37cbc MGD |
10414 | if (warn_on_deprecated |
10415 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 10416 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 10417 | |
c19d1205 ZW |
10418 | if (inst.operands[0].imm) |
10419 | inst.instruction |= 0x200; | |
a737bd4d NC |
10420 | } |
10421 | ||
10422 | static void | |
c19d1205 | 10423 | do_shift (void) |
a737bd4d | 10424 | { |
c19d1205 ZW |
10425 | unsigned int Rm = (inst.operands[1].present |
10426 | ? inst.operands[1].reg | |
10427 | : inst.operands[0].reg); | |
a737bd4d | 10428 | |
c19d1205 ZW |
10429 | inst.instruction |= inst.operands[0].reg << 12; |
10430 | inst.instruction |= Rm; | |
10431 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 10432 | { |
c19d1205 ZW |
10433 | inst.instruction |= inst.operands[2].reg << 8; |
10434 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
10435 | /* PR 12854: Error on extraneous shifts. */ |
10436 | constraint (inst.operands[2].shifted, | |
10437 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
10438 | } |
10439 | else | |
e2b0ab59 | 10440 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
10441 | } |
10442 | ||
09d92015 | 10443 | static void |
3eb17e6b | 10444 | do_smc (void) |
09d92015 | 10445 | { |
ba85f98c BW |
10446 | unsigned int value = inst.relocs[0].exp.X_add_number; |
10447 | constraint (value > 0xf, _("immediate too large (bigger than 0xF)")); | |
10448 | ||
e2b0ab59 AV |
10449 | inst.relocs[0].type = BFD_RELOC_ARM_SMC; |
10450 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
10451 | } |
10452 | ||
90ec0d68 MGD |
10453 | static void |
10454 | do_hvc (void) | |
10455 | { | |
e2b0ab59 AV |
10456 | inst.relocs[0].type = BFD_RELOC_ARM_HVC; |
10457 | inst.relocs[0].pc_rel = 0; | |
90ec0d68 MGD |
10458 | } |
10459 | ||
09d92015 | 10460 | static void |
c19d1205 | 10461 | do_swi (void) |
09d92015 | 10462 | { |
e2b0ab59 AV |
10463 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
10464 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
10465 | } |
10466 | ||
ddfded2f MW |
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 | ||
c19d1205 ZW |
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. */ | |
e16bb312 | 10489 | |
c19d1205 ZW |
10490 | static void |
10491 | do_smla (void) | |
e16bb312 | 10492 | { |
c19d1205 ZW |
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 | } | |
a737bd4d | 10498 | |
c19d1205 ZW |
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. */ | |
a737bd4d | 10503 | |
c19d1205 ZW |
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; | |
a737bd4d | 10511 | |
c19d1205 ZW |
10512 | if (inst.operands[0].reg == inst.operands[1].reg) |
10513 | as_tsktsk (_("rdhi and rdlo must be different")); | |
10514 | } | |
a737bd4d | 10515 | |
c19d1205 ZW |
10516 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
10517 | SMULxy{cond} Rd,Rm,Rs | |
10518 | Error if any register is R15. */ | |
a737bd4d | 10519 | |
c19d1205 ZW |
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 | } | |
a737bd4d | 10527 | |
b6702015 PB |
10528 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
10529 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 10530 | |
c19d1205 ZW |
10531 | static void |
10532 | do_srs (void) | |
10533 | { | |
b6702015 PB |
10534 | int reg; |
10535 | ||
10536 | if (inst.operands[0].present) | |
10537 | { | |
10538 | reg = inst.operands[0].reg; | |
fdfde340 | 10539 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
10540 | } |
10541 | else | |
fdfde340 | 10542 | reg = REG_SP; |
b6702015 PB |
10543 | |
10544 | inst.instruction |= reg << 16; | |
10545 | inst.instruction |= inst.operands[1].imm; | |
10546 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
10547 | inst.instruction |= WRITE_BACK; |
10548 | } | |
a737bd4d | 10549 | |
c19d1205 | 10550 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 10551 | |
c19d1205 ZW |
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 | |
01cfc07f NC |
10558 | || inst.operands[2].negative |
10559 | /* See comment in do_ldrex(). */ | |
10560 | || (inst.operands[2].reg == REG_PC), | |
10561 | BAD_ADDR_MODE); | |
a737bd4d | 10562 | |
c19d1205 ZW |
10563 | constraint (inst.operands[0].reg == inst.operands[1].reg |
10564 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 10565 | |
e2b0ab59 AV |
10566 | constraint (inst.relocs[0].exp.X_op != O_constant |
10567 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 10568 | _("offset must be zero in ARM encoding")); |
a737bd4d | 10569 | |
c19d1205 ZW |
10570 | inst.instruction |= inst.operands[0].reg << 12; |
10571 | inst.instruction |= inst.operands[1].reg; | |
10572 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 10573 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
e16bb312 NC |
10574 | } |
10575 | ||
877807f8 NC |
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 | ||
e16bb312 | 10591 | static void |
c19d1205 | 10592 | do_strexd (void) |
e16bb312 | 10593 | { |
c19d1205 ZW |
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")); | |
e16bb312 | 10602 | |
c19d1205 ZW |
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); | |
e16bb312 | 10607 | |
c19d1205 ZW |
10608 | inst.instruction |= inst.operands[0].reg << 12; |
10609 | inst.instruction |= inst.operands[1].reg; | |
10610 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
10611 | } |
10612 | ||
9eb6c0f1 MGD |
10613 | /* ARM V8 STRL. */ |
10614 | static void | |
4b8c8c02 | 10615 | do_stlex (void) |
9eb6c0f1 MGD |
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 | |
4b8c8c02 | 10624 | do_t_stlex (void) |
9eb6c0f1 MGD |
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 | ||
c19d1205 ZW |
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 | ||
e16bb312 | 10640 | static void |
c19d1205 | 10641 | do_sxtah (void) |
e16bb312 | 10642 | { |
c19d1205 ZW |
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 | } | |
e16bb312 | 10648 | |
c19d1205 | 10649 | /* ARM V6 SXTH. |
e16bb312 | 10650 | |
c19d1205 ZW |
10651 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
10652 | Condition defaults to COND_ALWAYS. | |
10653 | Error if any register uses R15. */ | |
e16bb312 NC |
10654 | |
10655 | static void | |
c19d1205 | 10656 | do_sxth (void) |
e16bb312 | 10657 | { |
c19d1205 ZW |
10658 | inst.instruction |= inst.operands[0].reg << 12; |
10659 | inst.instruction |= inst.operands[1].reg; | |
10660 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 10661 | } |
c19d1205 ZW |
10662 | \f |
10663 | /* VFP instructions. In a logical order: SP variant first, monad | |
10664 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
10665 | |
10666 | static void | |
c19d1205 | 10667 | do_vfp_sp_monadic (void) |
e16bb312 | 10668 | { |
57785aa2 AV |
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 | ||
5287ad62 JB |
10673 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
10674 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
10675 | } |
10676 | ||
10677 | static void | |
c19d1205 | 10678 | do_vfp_sp_dyadic (void) |
e16bb312 | 10679 | { |
5287ad62 JB |
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); | |
e16bb312 NC |
10683 | } |
10684 | ||
10685 | static void | |
c19d1205 | 10686 | do_vfp_sp_compare_z (void) |
e16bb312 | 10687 | { |
5287ad62 | 10688 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
10689 | } |
10690 | ||
10691 | static void | |
c19d1205 | 10692 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 10693 | { |
5287ad62 JB |
10694 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
10695 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
10696 | } |
10697 | ||
10698 | static void | |
c19d1205 | 10699 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 10700 | { |
5287ad62 JB |
10701 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
10702 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
10703 | } |
10704 | ||
10705 | static void | |
c19d1205 | 10706 | do_vfp_reg_from_sp (void) |
e16bb312 | 10707 | { |
57785aa2 AV |
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 | ||
c19d1205 | 10712 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 10713 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
10714 | } |
10715 | ||
10716 | static void | |
c19d1205 | 10717 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 10718 | { |
c19d1205 ZW |
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; | |
5287ad62 | 10723 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
10724 | } |
10725 | ||
10726 | static void | |
c19d1205 | 10727 | do_vfp_sp_from_reg (void) |
e16bb312 | 10728 | { |
57785aa2 AV |
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 | ||
5287ad62 | 10733 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 10734 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
10735 | } |
10736 | ||
10737 | static void | |
c19d1205 | 10738 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 10739 | { |
c19d1205 ZW |
10740 | constraint (inst.operands[0].imm != 2, |
10741 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 10742 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
10743 | inst.instruction |= inst.operands[1].reg << 12; |
10744 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
10745 | } |
10746 | ||
10747 | static void | |
c19d1205 | 10748 | do_vfp_sp_ldst (void) |
e16bb312 | 10749 | { |
5287ad62 | 10750 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5b7c81bd | 10751 | encode_arm_cp_address (1, false, true, 0); |
e16bb312 NC |
10752 | } |
10753 | ||
10754 | static void | |
c19d1205 | 10755 | do_vfp_dp_ldst (void) |
e16bb312 | 10756 | { |
5287ad62 | 10757 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
5b7c81bd | 10758 | encode_arm_cp_address (1, false, true, 0); |
e16bb312 NC |
10759 | } |
10760 | ||
c19d1205 | 10761 | |
e16bb312 | 10762 | static void |
c19d1205 | 10763 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 10764 | { |
c19d1205 ZW |
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; | |
5287ad62 | 10771 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 10772 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
10773 | } |
10774 | ||
10775 | static void | |
c19d1205 | 10776 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 10777 | { |
c19d1205 | 10778 | int count; |
e16bb312 | 10779 | |
c19d1205 ZW |
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")); | |
e16bb312 | 10785 | |
c19d1205 | 10786 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 10787 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 10788 | |
c19d1205 ZW |
10789 | count = inst.operands[1].imm << 1; |
10790 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
10791 | count += 1; | |
e16bb312 | 10792 | |
c19d1205 | 10793 | inst.instruction |= count; |
e16bb312 NC |
10794 | } |
10795 | ||
10796 | static void | |
c19d1205 | 10797 | do_vfp_sp_ldstmia (void) |
e16bb312 | 10798 | { |
c19d1205 | 10799 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
10800 | } |
10801 | ||
10802 | static void | |
c19d1205 | 10803 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 10804 | { |
c19d1205 | 10805 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
10806 | } |
10807 | ||
10808 | static void | |
c19d1205 | 10809 | do_vfp_dp_ldstmia (void) |
e16bb312 | 10810 | { |
c19d1205 | 10811 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
10812 | } |
10813 | ||
10814 | static void | |
c19d1205 | 10815 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 10816 | { |
c19d1205 | 10817 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
10818 | } |
10819 | ||
10820 | static void | |
c19d1205 | 10821 | do_vfp_xp_ldstmia (void) |
e16bb312 | 10822 | { |
c19d1205 ZW |
10823 | vfp_dp_ldstm (VFP_LDSTMIAX); |
10824 | } | |
e16bb312 | 10825 | |
c19d1205 ZW |
10826 | static void |
10827 | do_vfp_xp_ldstmdb (void) | |
10828 | { | |
10829 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 10830 | } |
5287ad62 JB |
10831 | |
10832 | static void | |
10833 | do_vfp_dp_rd_rm (void) | |
10834 | { | |
57785aa2 AV |
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 | ||
5287ad62 JB |
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 | { | |
57785aa2 AV |
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 | ||
5287ad62 JB |
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 | { | |
57785aa2 AV |
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 | ||
5287ad62 JB |
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); | |
00249aaa PB |
10892 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
10893 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
10894 | } |
10895 | ||
10896 | static void | |
10897 | do_vfp_dp_const (void) | |
10898 | { | |
10899 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
10900 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
10901 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
10902 | } |
10903 | ||
10904 | static void | |
10905 | vfp_conv (int srcsize) | |
10906 | { | |
5f1af56b MGD |
10907 | int immbits = srcsize - inst.operands[1].imm; |
10908 | ||
fa94de6b RM |
10909 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
10910 | { | |
5f1af56b | 10911 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
477330fc | 10912 | i.e. immbits must be in range 0 - 16. */ |
5f1af56b MGD |
10913 | inst.error = _("immediate value out of range, expected range [0, 16]"); |
10914 | return; | |
10915 | } | |
fa94de6b | 10916 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
10917 | { |
10918 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
477330fc | 10919 | i.e. immbits must be in range 0 - 31. */ |
5f1af56b MGD |
10920 | inst.error = _("immediate value out of range, expected range [1, 32]"); |
10921 | return; | |
10922 | } | |
10923 | ||
5287ad62 JB |
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 | } | |
c19d1205 ZW |
10955 | \f |
10956 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 10957 | |
c19d1205 ZW |
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 | } | |
b99bd4ef NC |
10964 | |
10965 | static void | |
c19d1205 | 10966 | do_fpa_ldmstm (void) |
b99bd4ef | 10967 | { |
c19d1205 ZW |
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 | } | |
b99bd4ef | 10977 | |
c19d1205 ZW |
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. */ | |
e2b0ab59 AV |
10984 | constraint (inst.relocs[0].exp.X_op != O_constant |
10985 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 10986 | _("this instruction does not support indexing")); |
b99bd4ef | 10987 | |
c19d1205 | 10988 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
e2b0ab59 | 10989 | inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm; |
b99bd4ef | 10990 | |
c19d1205 | 10991 | if (!(inst.instruction & INDEX_UP)) |
e2b0ab59 | 10992 | inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number; |
b99bd4ef | 10993 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 11000 | |
5b7c81bd | 11001 | encode_arm_cp_address (2, true, true, 0); |
b99bd4ef | 11002 | } |
c19d1205 ZW |
11003 | \f |
11004 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 11005 | |
c19d1205 ZW |
11006 | static void |
11007 | do_iwmmxt_tandorc (void) | |
11008 | { | |
11009 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
11010 | } | |
b99bd4ef | 11011 | |
c19d1205 ZW |
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 | } | |
b99bd4ef NC |
11018 | |
11019 | static void | |
c19d1205 | 11020 | do_iwmmxt_textrm (void) |
b99bd4ef | 11021 | { |
c19d1205 ZW |
11022 | inst.instruction |= inst.operands[0].reg << 12; |
11023 | inst.instruction |= inst.operands[1].reg << 16; | |
11024 | inst.instruction |= inst.operands[2].imm; | |
11025 | } | |
b99bd4ef | 11026 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 11034 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 11042 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 11051 | |
2d447fca JM |
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 | ||
c19d1205 ZW |
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 | } | |
b99bd4ef | 11069 | |
c19d1205 ZW |
11070 | static void |
11071 | do_iwmmxt_wldstbh (void) | |
11072 | { | |
8f06b2d8 | 11073 | int reloc; |
c19d1205 | 11074 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
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; | |
5b7c81bd | 11079 | encode_arm_cp_address (1, true, false, reloc); |
b99bd4ef NC |
11080 | } |
11081 | ||
c19d1205 ZW |
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 | } | |
b99bd4ef | 11091 | |
c19d1205 | 11092 | inst.instruction |= inst.operands[0].reg << 12; |
5b7c81bd | 11093 | encode_arm_cp_address (1, true, true, 0); |
c19d1205 | 11094 | } |
b99bd4ef NC |
11095 | |
11096 | static void | |
c19d1205 | 11097 | do_iwmmxt_wldstd (void) |
b99bd4ef | 11098 | { |
c19d1205 | 11099 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
11100 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
11101 | && inst.operands[1].immisreg) | |
11102 | { | |
11103 | inst.instruction &= ~0x1a000ff; | |
eff0bc54 | 11104 | inst.instruction |= (0xfU << 28); |
2d447fca JM |
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; | |
e2b0ab59 | 11112 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
2d447fca JM |
11113 | inst.instruction |= inst.operands[1].imm; |
11114 | } | |
11115 | else | |
5b7c81bd | 11116 | encode_arm_cp_address (1, true, false, 0); |
c19d1205 | 11117 | } |
b99bd4ef | 11118 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 11127 | |
c19d1205 ZW |
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 | } | |
2d447fca JM |
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: | |
5f4273c7 | 11153 | case 7: |
2d447fca JM |
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; | |
eff0bc54 | 11183 | inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); |
2d447fca JM |
11184 | } |
11185 | } | |
c19d1205 ZW |
11186 | \f |
11187 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
11188 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 11189 | |
c19d1205 | 11190 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 11191 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 11199 | |
c19d1205 ZW |
11200 | /* Insns like "foo W,X,Y,Z". |
11201 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 11202 | |
c19d1205 ZW |
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; | |
a737bd4d NC |
11210 | } |
11211 | ||
c19d1205 ZW |
11212 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
11213 | static void | |
11214 | do_mav_dspsc (void) | |
a737bd4d | 11215 | { |
c19d1205 ZW |
11216 | inst.instruction |= inst.operands[1].reg << 12; |
11217 | } | |
a737bd4d | 11218 | |
c19d1205 ZW |
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]. */ | |
a737bd4d | 11222 | |
c19d1205 ZW |
11223 | static void |
11224 | do_mav_shift (void) | |
11225 | { | |
11226 | int imm = inst.operands[2].imm; | |
a737bd4d | 11227 | |
c19d1205 ZW |
11228 | inst.instruction |= inst.operands[0].reg << 12; |
11229 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 11230 | |
c19d1205 ZW |
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); | |
a737bd4d | 11235 | |
c19d1205 ZW |
11236 | inst.instruction |= imm; |
11237 | } | |
11238 | \f | |
11239 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 11240 | |
c19d1205 ZW |
11241 | /* Xscale multiply-accumulate (argument parse) |
11242 | MIAcc acc0,Rm,Rs | |
11243 | MIAPHcc acc0,Rm,Rs | |
11244 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 11245 | |
c19d1205 ZW |
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 | } | |
a737bd4d | 11252 | |
c19d1205 | 11253 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 11254 | |
c19d1205 | 11255 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 11256 | |
c19d1205 ZW |
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; | |
b99bd4ef NC |
11262 | } |
11263 | ||
c19d1205 | 11264 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 11265 | |
c19d1205 | 11266 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
11267 | |
11268 | static void | |
c19d1205 | 11269 | do_xsc_mra (void) |
b99bd4ef | 11270 | { |
c19d1205 ZW |
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. */ | |
b99bd4ef | 11277 | |
c19d1205 ZW |
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 | { | |
e2b0ab59 | 11284 | unsigned int value = inst.relocs[0].exp.X_add_number; |
c19d1205 | 11285 | unsigned int shift = inst.operands[i].shift_kind; |
b99bd4ef | 11286 | |
9c3c69f2 PB |
11287 | constraint (inst.operands[i].immisreg, |
11288 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
11289 | inst.instruction |= inst.operands[i].reg; |
11290 | if (shift == SHIFT_RRX) | |
11291 | inst.instruction |= SHIFT_ROR << 4; | |
11292 | else | |
b99bd4ef | 11293 | { |
e2b0ab59 | 11294 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 ZW |
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; | |
b99bd4ef | 11310 | } |
c19d1205 | 11311 | } |
b99bd4ef | 11312 | |
b99bd4ef | 11313 | |
c19d1205 ZW |
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 | |
5be8be5d DG |
11318 | that cannot be used with a D instruction. If it is a store insn, |
11319 | reject PC in Rn. */ | |
b99bd4ef | 11320 | |
c19d1205 | 11321 | static void |
5b7c81bd | 11322 | encode_thumb32_addr_mode (int i, bool is_t, bool is_d) |
c19d1205 | 11323 | { |
5b7c81bd | 11324 | const bool is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
11325 | |
11326 | constraint (!inst.operands[i].isreg, | |
53365c0d | 11327 | _("Instruction does not support =N addresses")); |
b99bd4ef | 11328 | |
c19d1205 ZW |
11329 | inst.instruction |= inst.operands[i].reg << 16; |
11330 | if (inst.operands[i].immisreg) | |
b99bd4ef | 11331 | { |
5be8be5d | 11332 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
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")); | |
b99bd4ef | 11342 | |
f40d1643 | 11343 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 11344 | if (inst.operands[i].shifted) |
b99bd4ef | 11345 | { |
e2b0ab59 | 11346 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 11347 | _("expression too complex")); |
e2b0ab59 AV |
11348 | constraint (inst.relocs[0].exp.X_add_number < 0 |
11349 | || inst.relocs[0].exp.X_add_number > 3, | |
c19d1205 | 11350 | _("shift out of range")); |
e2b0ab59 | 11351 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
c19d1205 | 11352 | } |
e2b0ab59 | 11353 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 ZW |
11354 | } |
11355 | else if (inst.operands[i].preind) | |
11356 | { | |
5be8be5d | 11357 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 11358 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 11359 | _("cannot use writeback with this instruction")); |
4755303e WN |
11360 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0), |
11361 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
11362 | |
11363 | if (is_d) | |
11364 | { | |
11365 | inst.instruction |= 0x01000000; | |
11366 | if (inst.operands[i].writeback) | |
11367 | inst.instruction |= 0x00200000; | |
b99bd4ef | 11368 | } |
c19d1205 | 11369 | else |
b99bd4ef | 11370 | { |
c19d1205 ZW |
11371 | inst.instruction |= 0x00000c00; |
11372 | if (inst.operands[i].writeback) | |
11373 | inst.instruction |= 0x00000100; | |
b99bd4ef | 11374 | } |
e2b0ab59 | 11375 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 11376 | } |
c19d1205 | 11377 | else if (inst.operands[i].postind) |
b99bd4ef | 11378 | { |
9c2799c2 | 11379 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
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; | |
e2b0ab59 | 11387 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
c19d1205 ZW |
11388 | } |
11389 | else /* unindexed - only for coprocessor */ | |
11390 | inst.error = _("instruction does not accept unindexed addressing"); | |
11391 | } | |
11392 | ||
e39c1607 | 11393 | /* Table of Thumb instructions which exist in 16- and/or 32-bit |
c19d1205 ZW |
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 | |
0110f2b8 PB |
11397 | holds variant (1). |
11398 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 11399 | #define T16_32_TAB \ |
21d799b5 NC |
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), \ | |
e43ca2cb | 11413 | X(_aut, 0000, f3af802d), \ |
be05908c | 11414 | X(_autg, 0000, fb500f00), \ |
21d799b5 NC |
11415 | X(_b, e000, f000b000), \ |
11416 | X(_bcond, d000, f0008000), \ | |
4389b29a | 11417 | X(_bf, 0000, f040e001), \ |
f6b2b12d | 11418 | X(_bfcsel,0000, f000e001), \ |
f1c7f421 | 11419 | X(_bfx, 0000, f060e001), \ |
65d1bc05 | 11420 | X(_bfl, 0000, f000c001), \ |
f1c7f421 | 11421 | X(_bflx, 0000, f070e001), \ |
21d799b5 NC |
11422 | X(_bic, 4380, ea200000), \ |
11423 | X(_bics, 4380, ea300000), \ | |
e07352fa | 11424 | X(_bxaut, 0000, fb500f10), \ |
e39c1607 SD |
11425 | X(_cinc, 0000, ea509000), \ |
11426 | X(_cinv, 0000, ea50a000), \ | |
21d799b5 NC |
11427 | X(_cmn, 42c0, eb100f00), \ |
11428 | X(_cmp, 2800, ebb00f00), \ | |
e39c1607 | 11429 | X(_cneg, 0000, ea50b000), \ |
21d799b5 NC |
11430 | X(_cpsie, b660, f3af8400), \ |
11431 | X(_cpsid, b670, f3af8600), \ | |
11432 | X(_cpy, 4600, ea4f0000), \ | |
e39c1607 SD |
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), \ | |
21d799b5 | 11439 | X(_dec_sp,80dd, f1ad0d00), \ |
60f993ce | 11440 | X(_dls, 0000, f040e001), \ |
1f6234a3 | 11441 | X(_dlstp, 0000, f000e001), \ |
21d799b5 NC |
11442 | X(_eor, 4040, ea800000), \ |
11443 | X(_eors, 4040, ea900000), \ | |
11444 | X(_inc_sp,00dd, f10d0d00), \ | |
1f6234a3 | 11445 | X(_lctp, 0000, f00fe001), \ |
21d799b5 NC |
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), \ | |
60f993ce | 11455 | X(_le, 0000, f00fc001), \ |
1f6234a3 | 11456 | X(_letp, 0000, f01fc001), \ |
21d799b5 NC |
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), \ | |
ce537a7d | 11471 | X(_pac, 0000, f3af801d), \ |
f1e1d7f3 | 11472 | X(_pacbti, 0000, f3af800d), \ |
5c43020d | 11473 | X(_pacg, 0000, fb60f000), \ |
21d799b5 NC |
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), \ | |
60f993ce | 11501 | X(_wls, 0000, f040c001), \ |
1f6234a3 | 11502 | X(_wlstp, 0000, f000c001), \ |
53c4b28b | 11503 | X(_sev, bf40, f3af8004), \ |
74db7efb NC |
11504 | X(_sevl, bf50, f3af8005), \ |
11505 | X(_udf, de00, f7f0a000) | |
c19d1205 ZW |
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. */ | |
21d799b5 | 11510 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
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 }; | |
c921be7d NC |
11521 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
11522 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
11523 | #undef X |
11524 | #undef T16_32_TAB | |
11525 | ||
11526 | /* Thumb instruction encoders, in alphabetical order. */ | |
11527 | ||
92e90b6e | 11528 | /* ADDW or SUBW. */ |
c921be7d | 11529 | |
92e90b6e PB |
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 | ||
539d4391 NC |
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); | |
fdfde340 | 11544 | |
92e90b6e | 11545 | inst.instruction |= (Rn << 16) | (Rd << 8); |
e2b0ab59 | 11546 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
92e90b6e PB |
11547 | } |
11548 | ||
c19d1205 | 11549 | /* Parse an add or subtract instruction. We get here with inst.instruction |
33eaf5de | 11550 | equaling any of THUMB_OPCODE_add, adds, sub, or subs. */ |
c19d1205 ZW |
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 | ||
e07e6e58 | 11562 | if (Rd == REG_PC) |
5ee91343 | 11563 | set_pred_insn_type_last (); |
e07e6e58 | 11564 | |
c19d1205 ZW |
11565 | if (unified_syntax) |
11566 | { | |
5b7c81bd AM |
11567 | bool flags; |
11568 | bool narrow; | |
0110f2b8 PB |
11569 | int opcode; |
11570 | ||
11571 | flags = (inst.instruction == T_MNEM_adds | |
11572 | || inst.instruction == T_MNEM_subs); | |
11573 | if (flags) | |
5ee91343 | 11574 | narrow = !in_pred_block (); |
0110f2b8 | 11575 | else |
5ee91343 | 11576 | narrow = in_pred_block (); |
c19d1205 | 11577 | if (!inst.operands[2].isreg) |
b99bd4ef | 11578 | { |
16805f35 PB |
11579 | int add; |
11580 | ||
5c8ed6a4 JW |
11581 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
11582 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 | 11583 | |
16805f35 PB |
11584 | add = (inst.instruction == T_MNEM_add |
11585 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
11586 | opcode = 0; |
11587 | if (inst.size_req != 4) | |
11588 | { | |
0110f2b8 | 11589 | /* Attempt to use a narrow opcode, with relaxation if |
477330fc | 11590 | appropriate. */ |
0110f2b8 PB |
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; | |
e2b0ab59 AV |
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)) | |
a9f02af8 MG |
11611 | { |
11612 | if (inst.size_req == 2) | |
e2b0ab59 | 11613 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
a9f02af8 MG |
11614 | else |
11615 | inst.relax = opcode; | |
11616 | } | |
0110f2b8 PB |
11617 | } |
11618 | else | |
fe0171d2 | 11619 | constraint (inst.size_req == 2, _("cannot honor width suffix")); |
0110f2b8 PB |
11620 | } |
11621 | if (inst.size_req == 4 | |
11622 | || (inst.size_req != 2 && !opcode)) | |
11623 | { | |
e2b0ab59 AV |
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) , | |
a9f02af8 | 11628 | THUMB1_RELOC_ONLY); |
efd81785 PB |
11629 | if (Rd == REG_PC) |
11630 | { | |
fdfde340 | 11631 | constraint (add, BAD_PC); |
efd81785 PB |
11632 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
11633 | _("only SUBS PC, LR, #const allowed")); | |
e2b0ab59 | 11634 | constraint (inst.relocs[0].exp.X_op != O_constant, |
efd81785 | 11635 | _("expression too complex")); |
e2b0ab59 AV |
11636 | constraint (inst.relocs[0].exp.X_add_number < 0 |
11637 | || inst.relocs[0].exp.X_add_number > 0xff, | |
efd81785 PB |
11638 | _("immediate value out of range")); |
11639 | inst.instruction = T2_SUBS_PC_LR | |
e2b0ab59 AV |
11640 | | inst.relocs[0].exp.X_add_number; |
11641 | inst.relocs[0].type = BFD_RELOC_UNUSED; | |
efd81785 PB |
11642 | return; |
11643 | } | |
11644 | else if (Rs == REG_PC) | |
16805f35 PB |
11645 | { |
11646 | /* Always use addw/subw. */ | |
11647 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
e2b0ab59 | 11648 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
16805f35 PB |
11649 | } |
11650 | else | |
11651 | { | |
11652 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11653 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
11654 | | 0x10000000; | |
11655 | if (flags) | |
e2b0ab59 | 11656 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
16805f35 | 11657 | else |
e2b0ab59 | 11658 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM; |
16805f35 | 11659 | } |
dc4503c6 PB |
11660 | inst.instruction |= Rd << 8; |
11661 | inst.instruction |= Rs << 16; | |
0110f2b8 | 11662 | } |
b99bd4ef | 11663 | } |
c19d1205 ZW |
11664 | else |
11665 | { | |
e2b0ab59 | 11666 | unsigned int value = inst.relocs[0].exp.X_add_number; |
5f4cb198 NC |
11667 | unsigned int shift = inst.operands[2].shift_kind; |
11668 | ||
c19d1205 ZW |
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 | { | |
e27ec89e | 11673 | if (Rd > 7 || Rs > 7 || Rn > 7) |
5b7c81bd | 11674 | narrow = false; |
e27ec89e PB |
11675 | |
11676 | if (narrow) | |
c19d1205 | 11677 | { |
e27ec89e PB |
11678 | inst.instruction = ((inst.instruction == T_MNEM_adds |
11679 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
11680 | ? T_OPCODE_ADD_R3 |
11681 | : T_OPCODE_SUB_R3); | |
11682 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
11683 | return; | |
11684 | } | |
b99bd4ef | 11685 | |
7e806470 | 11686 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 11687 | { |
7e806470 PB |
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)) | |
c19d1205 | 11693 | { |
7e806470 PB |
11694 | if (Rd == Rn) |
11695 | { | |
11696 | Rn = Rs; | |
11697 | Rs = Rd; | |
11698 | } | |
c19d1205 ZW |
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 | } | |
c19d1205 ZW |
11705 | } |
11706 | } | |
c921be7d | 11707 | |
fdfde340 | 11708 | constraint (Rd == REG_PC, BAD_PC); |
5c8ed6a4 JW |
11709 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
11710 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 JM |
11711 | constraint (Rs == REG_PC, BAD_PC); |
11712 | reject_bad_reg (Rn); | |
11713 | ||
c19d1205 ZW |
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; | |
5f4cb198 NC |
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")); | |
c19d1205 ZW |
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); | |
b99bd4ef | 11732 | |
c19d1205 | 11733 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 11734 | { |
c19d1205 ZW |
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; | |
e2b0ab59 | 11742 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
b99bd4ef NC |
11743 | return; |
11744 | } | |
11745 | ||
c19d1205 ZW |
11746 | Rn = inst.operands[2].reg; |
11747 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 11748 | |
c19d1205 ZW |
11749 | /* We now have Rd, Rs, and Rn set to registers. */ |
11750 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 11751 | { |
c19d1205 ZW |
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); | |
b99bd4ef | 11769 | } |
b99bd4ef | 11770 | } |
b99bd4ef NC |
11771 | } |
11772 | ||
c19d1205 ZW |
11773 | static void |
11774 | do_t_adr (void) | |
11775 | { | |
fdfde340 JM |
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) | |
0110f2b8 PB |
11782 | { |
11783 | /* Defer to section relaxation. */ | |
11784 | inst.relax = inst.instruction; | |
11785 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 11786 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
11787 | } |
11788 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 11789 | { |
0110f2b8 | 11790 | /* Generate a 32-bit opcode. */ |
e9f89963 | 11791 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 11792 | inst.instruction |= Rd << 8; |
e2b0ab59 AV |
11793 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12; |
11794 | inst.relocs[0].pc_rel = 1; | |
e9f89963 PB |
11795 | } |
11796 | else | |
11797 | { | |
0110f2b8 | 11798 | /* Generate a 16-bit opcode. */ |
e9f89963 | 11799 | inst.instruction = THUMB_OP16 (inst.instruction); |
e2b0ab59 AV |
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; | |
fdfde340 | 11803 | inst.instruction |= Rd << 4; |
e9f89963 | 11804 | } |
52a86f84 | 11805 | |
e2b0ab59 AV |
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; | |
c19d1205 | 11811 | } |
b99bd4ef | 11812 | |
c19d1205 ZW |
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. */ | |
b99bd4ef | 11819 | static void |
c19d1205 | 11820 | do_t_arit3 (void) |
b99bd4ef | 11821 | { |
c19d1205 | 11822 | int Rd, Rs, Rn; |
b99bd4ef | 11823 | |
c19d1205 ZW |
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; | |
b99bd4ef | 11829 | |
fdfde340 JM |
11830 | reject_bad_reg (Rd); |
11831 | reject_bad_reg (Rs); | |
11832 | if (inst.operands[2].isreg) | |
11833 | reject_bad_reg (Rn); | |
11834 | ||
c19d1205 | 11835 | if (unified_syntax) |
b99bd4ef | 11836 | { |
c19d1205 ZW |
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; | |
e2b0ab59 | 11845 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
c19d1205 ZW |
11846 | } |
11847 | else | |
11848 | { | |
5b7c81bd | 11849 | bool narrow; |
e27ec89e | 11850 | |
c19d1205 | 11851 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11852 | if (THUMB_SETS_FLAGS (inst.instruction)) |
5ee91343 | 11853 | narrow = !in_pred_block (); |
e27ec89e | 11854 | else |
5ee91343 | 11855 | narrow = in_pred_block (); |
e27ec89e PB |
11856 | |
11857 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
5b7c81bd | 11858 | narrow = false; |
e27ec89e | 11859 | if (inst.operands[2].shifted) |
5b7c81bd | 11860 | narrow = false; |
e27ec89e | 11861 | if (inst.size_req == 4) |
5b7c81bd | 11862 | narrow = false; |
e27ec89e PB |
11863 | |
11864 | if (narrow | |
c19d1205 ZW |
11865 | && Rd == Rs) |
11866 | { | |
11867 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11868 | inst.instruction |= Rd; | |
11869 | inst.instruction |= Rn << 3; | |
11870 | return; | |
11871 | } | |
b99bd4ef | 11872 | |
c19d1205 ZW |
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 | } | |
a737bd4d | 11882 | } |
c19d1205 | 11883 | else |
b99bd4ef | 11884 | { |
c19d1205 ZW |
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); | |
a737bd4d | 11889 | |
c19d1205 ZW |
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")); | |
a737bd4d | 11895 | |
c19d1205 ZW |
11896 | inst.instruction = THUMB_OP16 (inst.instruction); |
11897 | inst.instruction |= Rd; | |
11898 | inst.instruction |= Rn << 3; | |
b99bd4ef | 11899 | } |
a737bd4d | 11900 | } |
b99bd4ef | 11901 | |
c19d1205 ZW |
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) | |
a737bd4d | 11909 | { |
c19d1205 | 11910 | int Rd, Rs, Rn; |
b99bd4ef | 11911 | |
c19d1205 ZW |
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; | |
c921be7d | 11917 | |
fdfde340 JM |
11918 | reject_bad_reg (Rd); |
11919 | reject_bad_reg (Rs); | |
11920 | if (inst.operands[2].isreg) | |
11921 | reject_bad_reg (Rn); | |
a737bd4d | 11922 | |
c19d1205 | 11923 | if (unified_syntax) |
a737bd4d | 11924 | { |
c19d1205 | 11925 | if (!inst.operands[2].isreg) |
b99bd4ef | 11926 | { |
c19d1205 ZW |
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; | |
e2b0ab59 | 11933 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 11934 | } |
c19d1205 | 11935 | else |
a737bd4d | 11936 | { |
5b7c81bd | 11937 | bool narrow; |
e27ec89e | 11938 | |
c19d1205 | 11939 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11940 | if (THUMB_SETS_FLAGS (inst.instruction)) |
5ee91343 | 11941 | narrow = !in_pred_block (); |
e27ec89e | 11942 | else |
5ee91343 | 11943 | narrow = in_pred_block (); |
e27ec89e PB |
11944 | |
11945 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
5b7c81bd | 11946 | narrow = false; |
e27ec89e | 11947 | if (inst.operands[2].shifted) |
5b7c81bd | 11948 | narrow = false; |
e27ec89e | 11949 | if (inst.size_req == 4) |
5b7c81bd | 11950 | narrow = false; |
e27ec89e PB |
11951 | |
11952 | if (narrow) | |
a737bd4d | 11953 | { |
c19d1205 | 11954 | if (Rd == Rs) |
a737bd4d | 11955 | { |
c19d1205 ZW |
11956 | inst.instruction = THUMB_OP16 (inst.instruction); |
11957 | inst.instruction |= Rd; | |
11958 | inst.instruction |= Rn << 3; | |
11959 | return; | |
a737bd4d | 11960 | } |
c19d1205 | 11961 | if (Rd == Rn) |
a737bd4d | 11962 | { |
c19d1205 ZW |
11963 | inst.instruction = THUMB_OP16 (inst.instruction); |
11964 | inst.instruction |= Rd; | |
11965 | inst.instruction |= Rs << 3; | |
11966 | return; | |
a737bd4d NC |
11967 | } |
11968 | } | |
c19d1205 ZW |
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); | |
a737bd4d | 11978 | } |
b99bd4ef | 11979 | } |
c19d1205 ZW |
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); | |
a737bd4d | 11986 | |
c19d1205 ZW |
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 | } | |
a737bd4d NC |
12001 | } |
12002 | ||
c19d1205 ZW |
12003 | static void |
12004 | do_t_bfc (void) | |
a737bd4d | 12005 | { |
fdfde340 | 12006 | unsigned Rd; |
c19d1205 ZW |
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. */ | |
fdfde340 JM |
12011 | Rd = inst.operands[0].reg; |
12012 | reject_bad_reg (Rd); | |
12013 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
12014 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
12015 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
12016 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
12017 | } |
12018 | ||
c19d1205 ZW |
12019 | static void |
12020 | do_t_bfi (void) | |
b99bd4ef | 12021 | { |
fdfde340 | 12022 | int Rd, Rn; |
c19d1205 | 12023 | unsigned int msb; |
b99bd4ef | 12024 | |
fdfde340 JM |
12025 | Rd = inst.operands[0].reg; |
12026 | reject_bad_reg (Rd); | |
12027 | ||
c19d1205 ZW |
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) | |
fdfde340 JM |
12031 | Rn = REG_PC; |
12032 | else | |
12033 | { | |
12034 | Rn = inst.operands[1].reg; | |
12035 | reject_bad_reg (Rn); | |
12036 | } | |
b99bd4ef | 12037 | |
c19d1205 ZW |
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. */ | |
fdfde340 JM |
12042 | inst.instruction |= Rd << 8; |
12043 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
12044 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
12045 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
12046 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
12047 | } |
12048 | ||
c19d1205 ZW |
12049 | static void |
12050 | do_t_bfx (void) | |
b99bd4ef | 12051 | { |
fdfde340 JM |
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 | ||
c19d1205 ZW |
12060 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
12061 | _("bit-field extends past end of register")); | |
fdfde340 JM |
12062 | inst.instruction |= Rd << 8; |
12063 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 12068 | |
c19d1205 ZW |
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. | |
b99bd4ef | 12075 | |
c19d1205 ZW |
12076 | ??? How to take advantage of the additional two bits of displacement |
12077 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 12078 | |
c19d1205 ZW |
12079 | static void |
12080 | do_t_blx (void) | |
12081 | { | |
5ee91343 | 12082 | set_pred_insn_type_last (); |
e07e6e58 | 12083 | |
c19d1205 | 12084 | if (inst.operands[0].isreg) |
fdfde340 JM |
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 | } | |
b99bd4ef NC |
12090 | else |
12091 | { | |
c19d1205 | 12092 | /* No register. This must be BLX(1). */ |
2fc8bdac | 12093 | inst.instruction = 0xf000e800; |
0855e32b | 12094 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
12095 | } |
12096 | } | |
12097 | ||
c19d1205 ZW |
12098 | static void |
12099 | do_t_branch (void) | |
b99bd4ef | 12100 | { |
0110f2b8 | 12101 | int opcode; |
dfa9f0d5 | 12102 | int cond; |
2fe88214 | 12103 | bfd_reloc_code_real_type reloc; |
dfa9f0d5 | 12104 | |
e07e6e58 | 12105 | cond = inst.cond; |
5ee91343 | 12106 | set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); |
e07e6e58 | 12107 | |
5ee91343 | 12108 | if (in_pred_block ()) |
dfa9f0d5 PB |
12109 | { |
12110 | /* Conditional branches inside IT blocks are encoded as unconditional | |
477330fc | 12111 | branches. */ |
dfa9f0d5 | 12112 | cond = COND_ALWAYS; |
dfa9f0d5 PB |
12113 | } |
12114 | else | |
12115 | cond = inst.cond; | |
12116 | ||
12117 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
12118 | opcode = T_MNEM_bcond; |
12119 | else | |
12120 | opcode = inst.instruction; | |
12121 | ||
12d6b0b7 RS |
12122 | if (unified_syntax |
12123 | && (inst.size_req == 4 | |
10960bfb PB |
12124 | || (inst.size_req != 2 |
12125 | && (inst.operands[0].hasreloc | |
e2b0ab59 | 12126 | || inst.relocs[0].exp.X_op == O_constant)))) |
c19d1205 | 12127 | { |
0110f2b8 | 12128 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 12129 | if (cond == COND_ALWAYS) |
9ae92b05 | 12130 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
12131 | else |
12132 | { | |
ff8646ee TP |
12133 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2), |
12134 | _("selected architecture does not support " | |
12135 | "wide conditional branch instruction")); | |
12136 | ||
9c2799c2 | 12137 | gas_assert (cond != 0xF); |
dfa9f0d5 | 12138 | inst.instruction |= cond << 22; |
9ae92b05 | 12139 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
12140 | } |
12141 | } | |
b99bd4ef NC |
12142 | else |
12143 | { | |
0110f2b8 | 12144 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 12145 | if (cond == COND_ALWAYS) |
9ae92b05 | 12146 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 12147 | else |
b99bd4ef | 12148 | { |
dfa9f0d5 | 12149 | inst.instruction |= cond << 8; |
9ae92b05 | 12150 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 12151 | } |
0110f2b8 PB |
12152 | /* Allow section relaxation. */ |
12153 | if (unified_syntax && inst.size_req != 2) | |
12154 | inst.relax = opcode; | |
b99bd4ef | 12155 | } |
e2b0ab59 AV |
12156 | inst.relocs[0].type = reloc; |
12157 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
12158 | } |
12159 | ||
8884b720 | 12160 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 12161 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 12162 | RANGE. */ |
b99bd4ef | 12163 | static void |
8884b720 | 12164 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 12165 | { |
dfa9f0d5 PB |
12166 | constraint (inst.cond != COND_ALWAYS, |
12167 | _("instruction is always unconditional")); | |
c19d1205 | 12168 | if (inst.operands[0].present) |
b99bd4ef | 12169 | { |
8884b720 | 12170 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
12171 | _("immediate value out of range")); |
12172 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 12173 | } |
8884b720 | 12174 | |
5ee91343 | 12175 | set_pred_insn_type (NEUTRAL_IT_INSN); |
8884b720 MGD |
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); | |
b99bd4ef NC |
12188 | } |
12189 | ||
12190 | static void | |
c19d1205 | 12191 | do_t_branch23 (void) |
b99bd4ef | 12192 | { |
5ee91343 | 12193 | set_pred_insn_type_last (); |
0855e32b | 12194 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 12195 | |
0855e32b NS |
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. */ | |
e2b0ab59 AV |
12201 | if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32) |
12202 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 12203 | |
4343666d | 12204 | #if defined(OBJ_COFF) |
c19d1205 ZW |
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. */ | |
e2b0ab59 AV |
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); | |
4343666d | 12215 | #endif |
90e4755a RE |
12216 | } |
12217 | ||
12218 | static void | |
c19d1205 | 12219 | do_t_bx (void) |
90e4755a | 12220 | { |
5ee91343 | 12221 | set_pred_insn_type_last (); |
c19d1205 ZW |
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 | } | |
90e4755a | 12227 | |
c19d1205 ZW |
12228 | static void |
12229 | do_t_bxj (void) | |
12230 | { | |
fdfde340 | 12231 | int Rm; |
90e4755a | 12232 | |
5ee91343 | 12233 | set_pred_insn_type_last (); |
fdfde340 JM |
12234 | Rm = inst.operands[0].reg; |
12235 | reject_bad_reg (Rm); | |
12236 | inst.instruction |= Rm << 16; | |
90e4755a RE |
12237 | } |
12238 | ||
12239 | static void | |
c19d1205 | 12240 | do_t_clz (void) |
90e4755a | 12241 | { |
fdfde340 JM |
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; | |
c19d1205 | 12254 | } |
90e4755a | 12255 | |
e39c1607 SD |
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 | ||
91d8b670 JG |
12310 | static void |
12311 | do_t_csdb (void) | |
12312 | { | |
5ee91343 | 12313 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
91d8b670 JG |
12314 | } |
12315 | ||
dfa9f0d5 PB |
12316 | static void |
12317 | do_t_cps (void) | |
12318 | { | |
5ee91343 | 12319 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
dfa9f0d5 PB |
12320 | inst.instruction |= inst.operands[0].imm; |
12321 | } | |
12322 | ||
c19d1205 ZW |
12323 | static void |
12324 | do_t_cpsi (void) | |
12325 | { | |
5ee91343 | 12326 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
c19d1205 | 12327 | if (unified_syntax |
62b3e311 PB |
12328 | && (inst.operands[1].present || inst.size_req == 4) |
12329 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 12330 | { |
c19d1205 ZW |
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; | |
90e4755a | 12337 | } |
c19d1205 | 12338 | else |
90e4755a | 12339 | { |
62b3e311 PB |
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, | |
c19d1205 ZW |
12345 | _("Thumb does not support the 2-argument " |
12346 | "form of this instruction")); | |
12347 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 12348 | } |
90e4755a RE |
12349 | } |
12350 | ||
c19d1205 ZW |
12351 | /* THUMB CPY instruction (argument parse). */ |
12352 | ||
90e4755a | 12353 | static void |
c19d1205 | 12354 | do_t_cpy (void) |
90e4755a | 12355 | { |
c19d1205 | 12356 | if (inst.size_req == 4) |
90e4755a | 12357 | { |
c19d1205 ZW |
12358 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
12359 | inst.instruction |= inst.operands[0].reg << 8; | |
12360 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 12361 | } |
c19d1205 | 12362 | else |
90e4755a | 12363 | { |
c19d1205 ZW |
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; | |
90e4755a | 12367 | } |
90e4755a RE |
12368 | } |
12369 | ||
90e4755a | 12370 | static void |
25fe350b | 12371 | do_t_cbz (void) |
90e4755a | 12372 | { |
5ee91343 | 12373 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
c19d1205 ZW |
12374 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
12375 | inst.instruction |= inst.operands[0].reg; | |
e2b0ab59 AV |
12376 | inst.relocs[0].pc_rel = 1; |
12377 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
c19d1205 | 12378 | } |
90e4755a | 12379 | |
62b3e311 PB |
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 | { | |
fdfde340 JM |
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; | |
62b3e311 PB |
12403 | } |
12404 | ||
c19d1205 ZW |
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 | } | |
90e4755a | 12413 | |
c19d1205 ZW |
12414 | static void |
12415 | do_t_it (void) | |
12416 | { | |
12417 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 12418 | |
5ee91343 AV |
12419 | set_pred_insn_type (IT_INSN); |
12420 | now_pred.mask = (inst.instruction & 0xf) | 0x10; | |
12421 | now_pred.cc = cond; | |
5b7c81bd | 12422 | now_pred.warn_deprecated = false; |
5ee91343 | 12423 | now_pred.type = SCALAR_PRED; |
e27ec89e PB |
12424 | |
12425 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 12426 | if ((cond & 0x1) == 0x0) |
90e4755a | 12427 | { |
c19d1205 | 12428 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 12429 | |
c19d1205 | 12430 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
12431 | { |
12432 | /* No conversion needed. */ | |
5ee91343 | 12433 | now_pred.block_length = 1; |
5a01bb1d | 12434 | } |
c19d1205 | 12435 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
12436 | { |
12437 | mask ^= 0x8; | |
5ee91343 | 12438 | now_pred.block_length = 2; |
5a01bb1d | 12439 | } |
e27ec89e | 12440 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
12441 | { |
12442 | mask ^= 0xC; | |
5ee91343 | 12443 | now_pred.block_length = 3; |
5a01bb1d | 12444 | } |
c19d1205 | 12445 | else |
5a01bb1d MGD |
12446 | { |
12447 | mask ^= 0xE; | |
5ee91343 | 12448 | now_pred.block_length = 4; |
5a01bb1d | 12449 | } |
90e4755a | 12450 | |
e27ec89e PB |
12451 | inst.instruction &= 0xfff0; |
12452 | inst.instruction |= mask; | |
c19d1205 | 12453 | } |
90e4755a | 12454 | |
c19d1205 ZW |
12455 | inst.instruction |= cond << 4; |
12456 | } | |
90e4755a | 12457 | |
3c707909 PB |
12458 | /* Helper function used for both push/pop and ldm/stm. */ |
12459 | static void | |
5b7c81bd AM |
12460 | encode_thumb2_multi (bool do_io, int base, unsigned mask, |
12461 | bool writeback) | |
3c707909 | 12462 | { |
5b7c81bd | 12463 | bool load, store; |
3c707909 | 12464 | |
4b5a202f AV |
12465 | gas_assert (base != -1 || !do_io); |
12466 | load = do_io && ((inst.instruction & (1 << 20)) != 0); | |
12467 | store = do_io && !load; | |
3c707909 PB |
12468 | |
12469 | if (mask & (1 << 13)) | |
12470 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 | 12471 | |
4b5a202f | 12472 | if (do_io && (mask & (1 << base)) != 0 |
1e5b0379 NC |
12473 | && writeback) |
12474 | inst.error = _("having the base register in the register list when " | |
12475 | "using write back is UNPREDICTABLE"); | |
12476 | ||
3c707909 PB |
12477 | if (load) |
12478 | { | |
e07e6e58 | 12479 | if (mask & (1 << 15)) |
477330fc RM |
12480 | { |
12481 | if (mask & (1 << 14)) | |
12482 | inst.error = _("LR and PC should not both be in register list"); | |
12483 | else | |
5ee91343 | 12484 | set_pred_insn_type_last (); |
477330fc | 12485 | } |
3c707909 | 12486 | } |
4b5a202f | 12487 | else if (store) |
3c707909 PB |
12488 | { |
12489 | if (mask & (1 << 15)) | |
12490 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
12491 | } |
12492 | ||
4b5a202f | 12493 | if (do_io && ((mask & (mask - 1)) == 0)) |
3c707909 PB |
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 | ||
5f4273c7 | 12515 | mask = ffs (mask) - 1; |
3c707909 PB |
12516 | mask <<= 12; |
12517 | } | |
12518 | else if (writeback) | |
12519 | inst.instruction |= WRITE_BACK; | |
12520 | ||
12521 | inst.instruction |= mask; | |
4b5a202f AV |
12522 | if (do_io) |
12523 | inst.instruction |= base << 16; | |
3c707909 PB |
12524 | } |
12525 | ||
c19d1205 ZW |
12526 | static void |
12527 | do_t_ldmstm (void) | |
12528 | { | |
12529 | /* This really doesn't seem worth it. */ | |
e2b0ab59 | 12530 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 ZW |
12531 | _("expression too complex")); |
12532 | constraint (inst.operands[1].writeback, | |
12533 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 12534 | |
c19d1205 ZW |
12535 | if (unified_syntax) |
12536 | { | |
5b7c81bd | 12537 | bool narrow; |
3c707909 PB |
12538 | unsigned mask; |
12539 | ||
5b7c81bd | 12540 | narrow = false; |
c19d1205 ZW |
12541 | /* See if we can use a 16-bit instruction. */ |
12542 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
12543 | && inst.size_req != 4 | |
3c707909 | 12544 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 12545 | { |
3c707909 | 12546 | mask = 1 << inst.operands[0].reg; |
90e4755a | 12547 | |
eab4f823 | 12548 | if (inst.operands[0].reg <= 7) |
90e4755a | 12549 | { |
3c707909 | 12550 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
12551 | ? inst.operands[0].writeback |
12552 | : (inst.operands[0].writeback | |
12553 | == !(inst.operands[1].imm & mask))) | |
477330fc | 12554 | { |
eab4f823 MGD |
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); | |
3c707909 | 12560 | |
eab4f823 MGD |
12561 | inst.instruction = THUMB_OP16 (inst.instruction); |
12562 | inst.instruction |= inst.operands[0].reg << 8; | |
12563 | inst.instruction |= inst.operands[1].imm; | |
5b7c81bd | 12564 | narrow = true; |
eab4f823 MGD |
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 | |
477330fc | 12571 | reglist. |
eab4f823 MGD |
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) | |
fa94de6b | 12580 | inst.error = |
eab4f823 MGD |
12581 | _("having the base register in the register list when " |
12582 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
12583 | |
12584 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
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); | |
5b7c81bd | 12589 | narrow = true; |
eab4f823 | 12590 | } |
90e4755a | 12591 | } |
eab4f823 | 12592 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 12593 | { |
eab4f823 MGD |
12594 | if (inst.operands[0].writeback) |
12595 | { | |
fa94de6b | 12596 | inst.instruction = |
eab4f823 | 12597 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 12598 | ? T_MNEM_push : T_MNEM_pop); |
eab4f823 | 12599 | inst.instruction |= inst.operands[1].imm; |
5b7c81bd | 12600 | narrow = true; |
eab4f823 MGD |
12601 | } |
12602 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
12603 | { | |
fa94de6b | 12604 | inst.instruction = |
eab4f823 | 12605 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 12606 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); |
eab4f823 | 12607 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); |
5b7c81bd | 12608 | narrow = true; |
eab4f823 | 12609 | } |
90e4755a | 12610 | } |
3c707909 PB |
12611 | } |
12612 | ||
12613 | if (!narrow) | |
12614 | { | |
c19d1205 ZW |
12615 | if (inst.instruction < 0xffff) |
12616 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 12617 | |
5b7c81bd | 12618 | encode_thumb2_multi (true /* do_io */, inst.operands[0].reg, |
4b5a202f AV |
12619 | inst.operands[1].imm, |
12620 | inst.operands[0].writeback); | |
90e4755a RE |
12621 | } |
12622 | } | |
c19d1205 | 12623 | else |
90e4755a | 12624 | { |
c19d1205 ZW |
12625 | constraint (inst.operands[0].reg > 7 |
12626 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
12627 | constraint (inst.instruction != T_MNEM_ldmia |
12628 | && inst.instruction != T_MNEM_stmia, | |
12629 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 12630 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 12631 | { |
c19d1205 ZW |
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))) | |
1e5b0379 | 12636 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 12637 | inst.operands[0].reg); |
f03698e6 | 12638 | } |
c19d1205 | 12639 | else |
90e4755a | 12640 | { |
c19d1205 ZW |
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")); | |
90e4755a RE |
12647 | } |
12648 | ||
c19d1205 ZW |
12649 | inst.instruction = THUMB_OP16 (inst.instruction); |
12650 | inst.instruction |= inst.operands[0].reg << 8; | |
12651 | inst.instruction |= inst.operands[1].imm; | |
12652 | } | |
12653 | } | |
e28cd48c | 12654 | |
c19d1205 ZW |
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, | |
01cfc07f | 12662 | BAD_ADDR_MODE); |
e28cd48c | 12663 | |
5be8be5d DG |
12664 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
12665 | ||
c19d1205 ZW |
12666 | inst.instruction |= inst.operands[0].reg << 12; |
12667 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 12668 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
c19d1205 | 12669 | } |
e28cd48c | 12670 | |
c19d1205 ZW |
12671 | static void |
12672 | do_t_ldrexd (void) | |
12673 | { | |
12674 | if (!inst.operands[1].present) | |
1cac9012 | 12675 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 12680 | } |
c19d1205 ZW |
12681 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
12682 | BAD_OVERLAP); | |
b99bd4ef | 12683 | |
c19d1205 ZW |
12684 | inst.instruction |= inst.operands[0].reg << 12; |
12685 | inst.instruction |= inst.operands[1].reg << 8; | |
12686 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
12687 | } |
12688 | ||
12689 | static void | |
c19d1205 | 12690 | do_t_ldst (void) |
b99bd4ef | 12691 | { |
0110f2b8 PB |
12692 | unsigned long opcode; |
12693 | int Rn; | |
12694 | ||
e07e6e58 NC |
12695 | if (inst.operands[0].isreg |
12696 | && !inst.operands[0].preind | |
12697 | && inst.operands[0].reg == REG_PC) | |
5ee91343 | 12698 | set_pred_insn_type_last (); |
e07e6e58 | 12699 | |
0110f2b8 | 12700 | opcode = inst.instruction; |
c19d1205 | 12701 | if (unified_syntax) |
b99bd4ef | 12702 | { |
53365c0d PB |
12703 | if (!inst.operands[1].isreg) |
12704 | { | |
12705 | if (opcode <= 0xffff) | |
12706 | inst.instruction = THUMB_OP32 (opcode); | |
5b7c81bd | 12707 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/false)) |
53365c0d PB |
12708 | return; |
12709 | } | |
0110f2b8 PB |
12710 | if (inst.operands[1].isreg |
12711 | && !inst.operands[1].writeback | |
c19d1205 ZW |
12712 | && !inst.operands[1].shifted && !inst.operands[1].postind |
12713 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
12714 | && opcode <= 0xffff |
12715 | && inst.size_req != 4) | |
c19d1205 | 12716 | { |
0110f2b8 PB |
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); | |
5f4273c7 | 12722 | /* [Rn, Rik] */ |
0110f2b8 PB |
12723 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
12724 | goto op16; | |
5be8be5d DG |
12725 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
12726 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
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 | { | |
e2b0ab59 | 12738 | if (inst.relocs[0].pc_rel) |
0110f2b8 PB |
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) | |
e2b0ab59 | 12759 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
0110f2b8 PB |
12760 | else |
12761 | inst.relax = opcode; | |
12762 | return; | |
12763 | } | |
c19d1205 | 12764 | } |
0110f2b8 | 12765 | /* Definitely a 32-bit variant. */ |
5be8be5d | 12766 | |
8d67f500 NC |
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) | |
477330fc RM |
12775 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) |
12776 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
8d67f500 NC |
12777 | as_warn (_("This instruction may be unpredictable " |
12778 | "if executed on M-profile cores " | |
12779 | "with interrupts enabled.")); | |
12780 | } | |
12781 | ||
5be8be5d | 12782 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 12783 | if (inst.operands[1].immisreg) |
5be8be5d DG |
12784 | reject_bad_reg (inst.operands[1].imm); |
12785 | ||
1be5fd2e NC |
12786 | constraint (inst.operands[1].writeback == 1 |
12787 | && inst.operands[0].reg == inst.operands[1].reg, | |
12788 | BAD_OVERLAP); | |
12789 | ||
0110f2b8 | 12790 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 | 12791 | inst.instruction |= inst.operands[0].reg << 12; |
5b7c81bd | 12792 | encode_thumb32_addr_mode (1, /*is_t=*/false, /*is_d=*/false); |
1be5fd2e | 12793 | check_ldr_r15_aligned (); |
b99bd4ef NC |
12794 | return; |
12795 | } | |
12796 | ||
c19d1205 ZW |
12797 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
12798 | ||
12799 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 12800 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 12809 | } |
5f4273c7 | 12810 | |
c19d1205 ZW |
12811 | inst.instruction = THUMB_OP16 (inst.instruction); |
12812 | if (!inst.operands[1].isreg) | |
5b7c81bd | 12813 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/false)) |
c19d1205 | 12814 | return; |
b99bd4ef | 12815 | |
c19d1205 ZW |
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) | |
90e4755a | 12821 | { |
c19d1205 ZW |
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")); | |
b99bd4ef | 12829 | |
c19d1205 ZW |
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; | |
b99bd4ef | 12836 | |
c19d1205 | 12837 | inst.instruction |= inst.operands[0].reg << 8; |
e2b0ab59 | 12838 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
12839 | return; |
12840 | } | |
90e4755a | 12841 | |
c19d1205 ZW |
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; | |
e2b0ab59 | 12848 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
12849 | return; |
12850 | } | |
90e4755a | 12851 | |
c19d1205 ZW |
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")); | |
90e4755a | 12856 | |
c19d1205 ZW |
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 | } | |
90e4755a | 12870 | |
c19d1205 ZW |
12871 | inst.instruction |= inst.operands[0].reg; |
12872 | inst.instruction |= inst.operands[1].reg << 3; | |
12873 | inst.instruction |= inst.operands[1].imm << 6; | |
12874 | } | |
90e4755a | 12875 | |
c19d1205 ZW |
12876 | static void |
12877 | do_t_ldstd (void) | |
12878 | { | |
12879 | if (!inst.operands[1].present) | |
b99bd4ef | 12880 | { |
c19d1205 ZW |
12881 | inst.operands[1].reg = inst.operands[0].reg + 1; |
12882 | constraint (inst.operands[0].reg == REG_LR, | |
12883 | _("r14 not allowed here")); | |
bd340a04 | 12884 | constraint (inst.operands[0].reg == REG_R12, |
477330fc | 12885 | _("r12 not allowed here")); |
b99bd4ef | 12886 | } |
bd340a04 MGD |
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 " | |
477330fc | 12892 | "one of transfer registers")); |
bd340a04 | 12893 | |
c19d1205 ZW |
12894 | inst.instruction |= inst.operands[0].reg << 12; |
12895 | inst.instruction |= inst.operands[1].reg << 8; | |
5b7c81bd | 12896 | encode_thumb32_addr_mode (2, /*is_t=*/false, /*is_d=*/true); |
b99bd4ef NC |
12897 | } |
12898 | ||
c19d1205 ZW |
12899 | static void |
12900 | do_t_ldstt (void) | |
12901 | { | |
12902 | inst.instruction |= inst.operands[0].reg << 12; | |
5b7c81bd | 12903 | encode_thumb32_addr_mode (1, /*is_t=*/true, /*is_d=*/false); |
c19d1205 | 12904 | } |
a737bd4d | 12905 | |
b99bd4ef | 12906 | static void |
c19d1205 | 12907 | do_t_mla (void) |
b99bd4ef | 12908 | { |
fdfde340 | 12909 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 12910 | |
fdfde340 JM |
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; | |
c19d1205 | 12925 | } |
b99bd4ef | 12926 | |
c19d1205 ZW |
12927 | static void |
12928 | do_t_mlal (void) | |
12929 | { | |
fdfde340 JM |
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; | |
c19d1205 | 12946 | } |
b99bd4ef | 12947 | |
c19d1205 ZW |
12948 | static void |
12949 | do_t_mov_cmp (void) | |
12950 | { | |
fdfde340 JM |
12951 | unsigned Rn, Rm; |
12952 | ||
12953 | Rn = inst.operands[0].reg; | |
12954 | Rm = inst.operands[1].reg; | |
12955 | ||
e07e6e58 | 12956 | if (Rn == REG_PC) |
5ee91343 | 12957 | set_pred_insn_type_last (); |
e07e6e58 | 12958 | |
c19d1205 | 12959 | if (unified_syntax) |
b99bd4ef | 12960 | { |
c19d1205 ZW |
12961 | int r0off = (inst.instruction == T_MNEM_mov |
12962 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 12963 | unsigned long opcode; |
5b7c81bd AM |
12964 | bool narrow; |
12965 | bool low_regs; | |
3d388997 | 12966 | |
fdfde340 | 12967 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 12968 | opcode = inst.instruction; |
5ee91343 | 12969 | if (in_pred_block ()) |
0110f2b8 | 12970 | narrow = opcode != T_MNEM_movs; |
3d388997 | 12971 | else |
0110f2b8 | 12972 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
12973 | if (inst.size_req == 4 |
12974 | || inst.operands[1].shifted) | |
5b7c81bd | 12975 | narrow = false; |
3d388997 | 12976 | |
efd81785 PB |
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 | |
fdfde340 JM |
12980 | && Rn == REG_PC |
12981 | && Rm == REG_LR) | |
efd81785 PB |
12982 | { |
12983 | inst.instruction = T2_SUBS_PC_LR; | |
12984 | return; | |
12985 | } | |
12986 | ||
fdfde340 JM |
12987 | if (opcode == T_MNEM_cmp) |
12988 | { | |
12989 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
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); | |
fdfde340 JM |
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 | } | |
76fa04a4 MGD |
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 | { | |
5c3696f8 | 13019 | as_tsktsk (_("Use of r%u as a source register is " |
76fa04a4 MGD |
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); | |
5c8ed6a4 JW |
13029 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
13030 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
76fa04a4 | 13031 | } |
fdfde340 JM |
13032 | } |
13033 | else | |
13034 | reject_bad_reg (Rn); | |
13035 | } | |
13036 | ||
c19d1205 ZW |
13037 | if (!inst.operands[1].isreg) |
13038 | { | |
0110f2b8 | 13039 | /* Immediate operand. */ |
5ee91343 | 13040 | if (!in_pred_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
13041 | narrow = 0; |
13042 | if (low_regs && narrow) | |
13043 | { | |
13044 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 13045 | inst.instruction |= Rn << 8; |
e2b0ab59 AV |
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) | |
72d98d16 | 13048 | { |
a9f02af8 | 13049 | if (inst.size_req == 2) |
e2b0ab59 | 13050 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
a9f02af8 MG |
13051 | else |
13052 | inst.relax = opcode; | |
72d98d16 | 13053 | } |
0110f2b8 PB |
13054 | } |
13055 | else | |
13056 | { | |
e2b0ab59 AV |
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) , | |
a9f02af8 MG |
13061 | THUMB1_RELOC_ONLY); |
13062 | ||
0110f2b8 PB |
13063 | inst.instruction = THUMB_OP32 (inst.instruction); |
13064 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 13065 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 13066 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
0110f2b8 | 13067 | } |
c19d1205 | 13068 | } |
728ca7c9 PB |
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. */ | |
5b7c81bd | 13074 | bool flags = (inst.instruction == T_MNEM_movs); |
728ca7c9 | 13075 | |
5ee91343 | 13076 | if (in_pred_block ()) |
728ca7c9 PB |
13077 | narrow = !flags; |
13078 | else | |
13079 | narrow = flags; | |
13080 | ||
13081 | if (inst.size_req == 4) | |
5b7c81bd | 13082 | narrow = false; |
728ca7c9 PB |
13083 | |
13084 | if (!low_regs || inst.operands[1].imm > 7) | |
5b7c81bd | 13085 | narrow = false; |
728ca7c9 | 13086 | |
fdfde340 | 13087 | if (Rn != Rm) |
5b7c81bd | 13088 | narrow = false; |
728ca7c9 PB |
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: | |
5f4273c7 | 13105 | abort (); |
728ca7c9 PB |
13106 | } |
13107 | ||
13108 | inst.instruction = opcode; | |
13109 | if (narrow) | |
13110 | { | |
fdfde340 | 13111 | inst.instruction |= Rn; |
728ca7c9 PB |
13112 | inst.instruction |= inst.operands[1].imm << 3; |
13113 | } | |
13114 | else | |
13115 | { | |
13116 | if (flags) | |
13117 | inst.instruction |= CONDS_BIT; | |
13118 | ||
fdfde340 JM |
13119 | inst.instruction |= Rn << 8; |
13120 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
13121 | inst.instruction |= inst.operands[1].imm; |
13122 | } | |
13123 | } | |
3d388997 | 13124 | else if (!narrow) |
c19d1205 | 13125 | { |
728ca7c9 PB |
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 | { | |
5ee91343 | 13132 | if (in_pred_block ()) |
728ca7c9 PB |
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; | |
5b7c81bd | 13145 | default: narrow = false; break; |
728ca7c9 PB |
13146 | } |
13147 | } | |
13148 | ||
13149 | if (narrow) | |
13150 | { | |
fdfde340 JM |
13151 | inst.instruction |= Rn; |
13152 | inst.instruction |= Rm << 3; | |
e2b0ab59 | 13153 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
728ca7c9 PB |
13154 | } |
13155 | else | |
13156 | { | |
13157 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 13158 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
13159 | encode_thumb32_shifted_operand (1); |
13160 | } | |
c19d1205 ZW |
13161 | } |
13162 | else | |
13163 | switch (inst.instruction) | |
13164 | { | |
13165 | case T_MNEM_mov: | |
837b3435 | 13166 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
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"); | |
fa94de6b | 13173 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
13174 | arm_ext_v6); |
13175 | } | |
13176 | ||
c19d1205 | 13177 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
13178 | inst.instruction |= (Rn & 0x8) << 4; |
13179 | inst.instruction |= (Rn & 0x7); | |
13180 | inst.instruction |= Rm << 3; | |
c19d1205 | 13181 | break; |
b99bd4ef | 13182 | |
c19d1205 ZW |
13183 | case T_MNEM_movs: |
13184 | /* We know we have low registers at this point. | |
941a8a52 MGD |
13185 | Generate LSLS Rd, Rs, #0. */ |
13186 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
13187 | inst.instruction |= Rn; |
13188 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13189 | break; |
13190 | ||
13191 | case T_MNEM_cmp: | |
3d388997 | 13192 | if (low_regs) |
c19d1205 ZW |
13193 | { |
13194 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
13195 | inst.instruction |= Rn; |
13196 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13197 | } |
13198 | else | |
13199 | { | |
13200 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
13201 | inst.instruction |= (Rn & 0x8) << 4; |
13202 | inst.instruction |= (Rn & 0x7); | |
13203 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13204 | } |
13205 | break; | |
13206 | } | |
b99bd4ef NC |
13207 | return; |
13208 | } | |
13209 | ||
c19d1205 | 13210 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
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 | ||
c19d1205 | 13216 | if (inst.operands[1].isreg) |
b99bd4ef | 13217 | { |
fdfde340 | 13218 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 13219 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 13224 | else |
c19d1205 | 13225 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 13226 | |
fdfde340 JM |
13227 | inst.instruction |= Rn; |
13228 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
13229 | } |
13230 | else | |
13231 | { | |
c19d1205 ZW |
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 (); | |
b99bd4ef NC |
13237 | } |
13238 | } | |
c19d1205 | 13239 | else |
b99bd4ef | 13240 | { |
fdfde340 | 13241 | constraint (Rn > 7, |
c19d1205 | 13242 | _("only lo regs allowed with immediate")); |
fdfde340 | 13243 | inst.instruction |= Rn << 8; |
e2b0ab59 | 13244 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
c19d1205 ZW |
13245 | } |
13246 | } | |
b99bd4ef | 13247 | |
c19d1205 ZW |
13248 | static void |
13249 | do_t_mov16 (void) | |
13250 | { | |
fdfde340 | 13251 | unsigned Rd; |
b6895b4f | 13252 | bfd_vma imm; |
5b7c81bd | 13253 | bool top; |
b6895b4f PB |
13254 | |
13255 | top = (inst.instruction & 0x00800000) != 0; | |
e2b0ab59 | 13256 | if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW) |
b6895b4f | 13257 | { |
33eaf5de | 13258 | constraint (top, _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 13259 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW; |
b6895b4f | 13260 | } |
e2b0ab59 | 13261 | else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT) |
b6895b4f | 13262 | { |
33eaf5de | 13263 | constraint (!top, _(":upper16: not allowed in this instruction")); |
e2b0ab59 | 13264 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT; |
b6895b4f PB |
13265 | } |
13266 | ||
fdfde340 JM |
13267 | Rd = inst.operands[0].reg; |
13268 | reject_bad_reg (Rd); | |
13269 | ||
13270 | inst.instruction |= Rd << 8; | |
e2b0ab59 | 13271 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 13272 | { |
e2b0ab59 | 13273 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
13274 | inst.instruction |= (imm & 0xf000) << 4; |
13275 | inst.instruction |= (imm & 0x0800) << 15; | |
13276 | inst.instruction |= (imm & 0x0700) << 4; | |
13277 | inst.instruction |= (imm & 0x00ff); | |
13278 | } | |
c19d1205 | 13279 | } |
b99bd4ef | 13280 | |
c19d1205 ZW |
13281 | static void |
13282 | do_t_mvn_tst (void) | |
13283 | { | |
fdfde340 | 13284 | unsigned Rn, Rm; |
c921be7d | 13285 | |
fdfde340 JM |
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 | ||
c19d1205 ZW |
13296 | if (unified_syntax) |
13297 | { | |
13298 | int r0off = (inst.instruction == T_MNEM_mvn | |
13299 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
5b7c81bd | 13300 | bool narrow; |
3d388997 PB |
13301 | |
13302 | if (inst.size_req == 4 | |
13303 | || inst.instruction > 0xffff | |
13304 | || inst.operands[1].shifted | |
fdfde340 | 13305 | || Rn > 7 || Rm > 7) |
5b7c81bd | 13306 | narrow = false; |
fe8b4cc3 KT |
13307 | else if (inst.instruction == T_MNEM_cmn |
13308 | || inst.instruction == T_MNEM_tst) | |
5b7c81bd | 13309 | narrow = true; |
3d388997 | 13310 | else if (THUMB_SETS_FLAGS (inst.instruction)) |
5ee91343 | 13311 | narrow = !in_pred_block (); |
3d388997 | 13312 | else |
5ee91343 | 13313 | narrow = in_pred_block (); |
3d388997 | 13314 | |
c19d1205 | 13315 | if (!inst.operands[1].isreg) |
b99bd4ef | 13316 | { |
c19d1205 ZW |
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; | |
fdfde340 | 13322 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 13323 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 13324 | } |
c19d1205 | 13325 | else |
b99bd4ef | 13326 | { |
c19d1205 | 13327 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 13328 | if (narrow) |
b99bd4ef | 13329 | { |
c19d1205 | 13330 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13331 | inst.instruction |= Rn; |
13332 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13333 | } |
c19d1205 | 13334 | else |
b99bd4ef | 13335 | { |
c19d1205 ZW |
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); | |
fdfde340 | 13341 | inst.instruction |= Rn << r0off; |
c19d1205 | 13342 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 13343 | } |
b99bd4ef NC |
13344 | } |
13345 | } | |
13346 | else | |
13347 | { | |
c19d1205 ZW |
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")); | |
fdfde340 | 13352 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 13353 | BAD_HIREG); |
b99bd4ef | 13354 | |
c19d1205 | 13355 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13356 | inst.instruction |= Rn; |
13357 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13358 | } |
b99bd4ef NC |
13359 | } |
13360 | ||
b05fe5cf | 13361 | static void |
c19d1205 | 13362 | do_t_mrs (void) |
b05fe5cf | 13363 | { |
fdfde340 | 13364 | unsigned Rd; |
037e8744 JB |
13365 | |
13366 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
13367 | return; | |
13368 | ||
90ec0d68 MGD |
13369 | Rd = inst.operands[0].reg; |
13370 | reject_bad_reg (Rd); | |
13371 | inst.instruction |= Rd << 8; | |
13372 | ||
13373 | if (inst.operands[1].isreg) | |
62b3e311 | 13374 | { |
90ec0d68 MGD |
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; | |
62b3e311 PB |
13382 | } |
13383 | else | |
13384 | { | |
90ec0d68 | 13385 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 13386 | |
d2cd1205 | 13387 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
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. */ | |
5b7c81bd | 13392 | bool m_profile = |
823d2571 | 13393 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); |
1a43faaf NC |
13394 | constraint ((flags != 0) && m_profile, _("selected processor does " |
13395 | "not support requested special purpose register")); | |
13396 | } | |
90ec0d68 | 13397 | else |
d2cd1205 JB |
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")); | |
fdfde340 | 13402 | |
90ec0d68 MGD |
13403 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
13404 | inst.instruction |= inst.operands[1].imm & 0xff; | |
13405 | inst.instruction |= 0xf0000; | |
13406 | } | |
c19d1205 | 13407 | } |
b05fe5cf | 13408 | |
c19d1205 ZW |
13409 | static void |
13410 | do_t_msr (void) | |
13411 | { | |
62b3e311 | 13412 | int flags; |
fdfde340 | 13413 | unsigned Rn; |
62b3e311 | 13414 | |
037e8744 JB |
13415 | if (do_vfp_nsyn_msr () == SUCCESS) |
13416 | return; | |
13417 | ||
c19d1205 ZW |
13418 | constraint (!inst.operands[1].isreg, |
13419 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
13420 | |
13421 | if (inst.operands[0].isreg) | |
13422 | flags = (int)(inst.operands[0].reg); | |
13423 | else | |
13424 | flags = inst.operands[0].imm; | |
13425 | ||
d2cd1205 | 13426 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 13427 | { |
d2cd1205 JB |
13428 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
13429 | ||
1a43faaf | 13430 | /* PR gas/12698: The constraint is only applied for m_profile. |
477330fc RM |
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. */ | |
5b7c81bd | 13433 | bool m_profile = |
823d2571 | 13434 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); |
1a43faaf | 13435 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) |
477330fc RM |
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")); | |
62b3e311 PB |
13441 | } |
13442 | else | |
d2cd1205 JB |
13443 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
13444 | "requested special purpose register")); | |
c921be7d | 13445 | |
fdfde340 JM |
13446 | Rn = inst.operands[1].reg; |
13447 | reject_bad_reg (Rn); | |
13448 | ||
62b3e311 | 13449 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
13450 | inst.instruction |= (flags & 0xf0000) >> 8; |
13451 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 13452 | inst.instruction |= (flags & 0xff); |
fdfde340 | 13453 | inst.instruction |= Rn << 16; |
c19d1205 | 13454 | } |
b05fe5cf | 13455 | |
c19d1205 ZW |
13456 | static void |
13457 | do_t_mul (void) | |
13458 | { | |
5b7c81bd | 13459 | bool narrow; |
fdfde340 | 13460 | unsigned Rd, Rn, Rm; |
17828f45 | 13461 | |
c19d1205 ZW |
13462 | if (!inst.operands[2].present) |
13463 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 13464 | |
fdfde340 JM |
13465 | Rd = inst.operands[0].reg; |
13466 | Rn = inst.operands[1].reg; | |
13467 | Rm = inst.operands[2].reg; | |
13468 | ||
17828f45 | 13469 | if (unified_syntax) |
b05fe5cf | 13470 | { |
17828f45 | 13471 | if (inst.size_req == 4 |
fdfde340 JM |
13472 | || (Rd != Rn |
13473 | && Rd != Rm) | |
13474 | || Rn > 7 | |
13475 | || Rm > 7) | |
5b7c81bd | 13476 | narrow = false; |
17828f45 | 13477 | else if (inst.instruction == T_MNEM_muls) |
5ee91343 | 13478 | narrow = !in_pred_block (); |
17828f45 | 13479 | else |
5ee91343 | 13480 | narrow = in_pred_block (); |
b05fe5cf | 13481 | } |
c19d1205 | 13482 | else |
b05fe5cf | 13483 | { |
17828f45 | 13484 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 13485 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 13486 | BAD_HIREG); |
5b7c81bd | 13487 | narrow = true; |
17828f45 | 13488 | } |
b05fe5cf | 13489 | |
17828f45 JM |
13490 | if (narrow) |
13491 | { | |
13492 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 13493 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 13494 | inst.instruction |= Rd; |
b05fe5cf | 13495 | |
fdfde340 JM |
13496 | if (Rd == Rn) |
13497 | inst.instruction |= Rm << 3; | |
13498 | else if (Rd == Rm) | |
13499 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
13500 | else |
13501 | constraint (1, _("dest must overlap one source register")); | |
13502 | } | |
17828f45 JM |
13503 | else |
13504 | { | |
e07e6e58 NC |
13505 | constraint (inst.instruction != T_MNEM_mul, |
13506 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
13507 | /* 32-bit MUL. */ |
13508 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
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); | |
17828f45 | 13516 | } |
c19d1205 | 13517 | } |
b05fe5cf | 13518 | |
c19d1205 ZW |
13519 | static void |
13520 | do_t_mull (void) | |
13521 | { | |
fdfde340 | 13522 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 13523 | |
fdfde340 JM |
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) | |
c19d1205 ZW |
13540 | as_tsktsk (_("rdhi and rdlo must be different")); |
13541 | } | |
b05fe5cf | 13542 | |
c19d1205 ZW |
13543 | static void |
13544 | do_t_nop (void) | |
13545 | { | |
5ee91343 | 13546 | set_pred_insn_type (NEUTRAL_IT_INSN); |
e07e6e58 | 13547 | |
c19d1205 ZW |
13548 | if (unified_syntax) |
13549 | { | |
13550 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 13551 | { |
c19d1205 ZW |
13552 | inst.instruction = THUMB_OP32 (inst.instruction); |
13553 | inst.instruction |= inst.operands[0].imm; | |
13554 | } | |
13555 | else | |
13556 | { | |
bc2d1808 NC |
13557 | /* PR9722: Check for Thumb2 availability before |
13558 | generating a thumb2 nop instruction. */ | |
afa62d5e | 13559 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
13560 | { |
13561 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13562 | inst.instruction |= inst.operands[0].imm << 4; | |
13563 | } | |
13564 | else | |
13565 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
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 | } | |
b05fe5cf | 13575 | |
c19d1205 ZW |
13576 | static void |
13577 | do_t_neg (void) | |
13578 | { | |
13579 | if (unified_syntax) | |
13580 | { | |
5b7c81bd | 13581 | bool narrow; |
3d388997 PB |
13582 | |
13583 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
5ee91343 | 13584 | narrow = !in_pred_block (); |
3d388997 | 13585 | else |
5ee91343 | 13586 | narrow = in_pred_block (); |
3d388997 | 13587 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
5b7c81bd | 13588 | narrow = false; |
3d388997 | 13589 | if (inst.size_req == 4) |
5b7c81bd | 13590 | narrow = false; |
3d388997 PB |
13591 | |
13592 | if (!narrow) | |
c19d1205 ZW |
13593 | { |
13594 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13595 | inst.instruction |= inst.operands[0].reg << 8; | |
13596 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
13597 | } |
13598 | else | |
13599 | { | |
c19d1205 ZW |
13600 | inst.instruction = THUMB_OP16 (inst.instruction); |
13601 | inst.instruction |= inst.operands[0].reg; | |
13602 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
13603 | } |
13604 | } | |
13605 | else | |
13606 | { | |
c19d1205 ZW |
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 | ||
1c444d06 JM |
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 | ||
fdfde340 JM |
13625 | reject_bad_reg (Rd); |
13626 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
13627 | reject_bad_reg (Rn); | |
13628 | ||
1c444d06 JM |
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; | |
e2b0ab59 | 13635 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
1c444d06 JM |
13636 | } |
13637 | else | |
13638 | { | |
13639 | unsigned Rm; | |
13640 | ||
13641 | Rm = inst.operands[2].reg; | |
fdfde340 | 13642 | reject_bad_reg (Rm); |
1c444d06 JM |
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 | ||
c19d1205 ZW |
13651 | static void |
13652 | do_t_pkhbt (void) | |
13653 | { | |
fdfde340 JM |
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; | |
c19d1205 ZW |
13667 | if (inst.operands[3].present) |
13668 | { | |
e2b0ab59 AV |
13669 | unsigned int val = inst.relocs[0].exp.X_add_number; |
13670 | constraint (inst.relocs[0].exp.X_op != O_constant, | |
c19d1205 ZW |
13671 | _("expression too complex")); |
13672 | inst.instruction |= (val & 0x1c) << 10; | |
13673 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 13674 | } |
c19d1205 | 13675 | } |
b05fe5cf | 13676 | |
c19d1205 ZW |
13677 | static void |
13678 | do_t_pkhtb (void) | |
13679 | { | |
13680 | if (!inst.operands[3].present) | |
1ef52f49 NC |
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 | } | |
c19d1205 | 13691 | do_t_pkhbt (); |
b05fe5cf ZW |
13692 | } |
13693 | ||
c19d1205 ZW |
13694 | static void |
13695 | do_t_pld (void) | |
13696 | { | |
fdfde340 JM |
13697 | if (inst.operands[0].immisreg) |
13698 | reject_bad_reg (inst.operands[0].imm); | |
13699 | ||
5b7c81bd | 13700 | encode_thumb32_addr_mode (0, /*is_t=*/false, /*is_d=*/false); |
c19d1205 | 13701 | } |
b05fe5cf | 13702 | |
c19d1205 ZW |
13703 | static void |
13704 | do_t_push_pop (void) | |
b99bd4ef | 13705 | { |
e9f89963 | 13706 | unsigned mask; |
5f4273c7 | 13707 | |
c19d1205 ZW |
13708 | constraint (inst.operands[0].writeback, |
13709 | _("push/pop do not support {reglist}^")); | |
e2b0ab59 | 13710 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 | 13711 | _("expression too complex")); |
b99bd4ef | 13712 | |
e9f89963 | 13713 | mask = inst.operands[0].imm; |
d3bfe16e | 13714 | if (inst.size_req != 4 && (mask & ~0xff) == 0) |
3c707909 | 13715 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
d3bfe16e | 13716 | else if (inst.size_req != 4 |
c6025a80 | 13717 | && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push |
d3bfe16e | 13718 | ? REG_LR : REG_PC))) |
b99bd4ef | 13719 | { |
c19d1205 ZW |
13720 | inst.instruction = THUMB_OP16 (inst.instruction); |
13721 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 13722 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
13723 | } |
13724 | else if (unified_syntax) | |
13725 | { | |
3c707909 | 13726 | inst.instruction = THUMB_OP32 (inst.instruction); |
5b7c81bd | 13727 | encode_thumb2_multi (true /* do_io */, 13, mask, true); |
4b5a202f AV |
13728 | } |
13729 | else | |
13730 | { | |
13731 | inst.error = _("invalid register list to push/pop instruction"); | |
13732 | return; | |
c19d1205 | 13733 | } |
4b5a202f AV |
13734 | } |
13735 | ||
13736 | static void | |
13737 | do_t_clrm (void) | |
13738 | { | |
13739 | if (unified_syntax) | |
5b7c81bd | 13740 | encode_thumb2_multi (false /* do_io */, -1, inst.operands[0].imm, false); |
c19d1205 ZW |
13741 | else |
13742 | { | |
13743 | inst.error = _("invalid register list to push/pop instruction"); | |
13744 | return; | |
13745 | } | |
c19d1205 | 13746 | } |
b99bd4ef | 13747 | |
efd6b359 AV |
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 | ||
c19d1205 ZW |
13766 | static void |
13767 | do_t_rbit (void) | |
13768 | { | |
fdfde340 JM |
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; | |
c19d1205 | 13780 | } |
b99bd4ef | 13781 | |
c19d1205 ZW |
13782 | static void |
13783 | do_t_rev (void) | |
13784 | { | |
fdfde340 JM |
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 | |
c19d1205 ZW |
13794 | && inst.size_req != 4) |
13795 | { | |
13796 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
13797 | inst.instruction |= Rd; |
13798 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
13799 | } |
13800 | else if (unified_syntax) | |
13801 | { | |
13802 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
13803 | inst.instruction |= Rd << 8; |
13804 | inst.instruction |= Rm << 16; | |
13805 | inst.instruction |= Rm; | |
c19d1205 ZW |
13806 | } |
13807 | else | |
13808 | inst.error = BAD_HIREG; | |
13809 | } | |
b99bd4ef | 13810 | |
1c444d06 JM |
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 | ||
fdfde340 JM |
13819 | reject_bad_reg (Rd); |
13820 | reject_bad_reg (Rm); | |
c921be7d | 13821 | |
1c444d06 JM |
13822 | inst.instruction |= Rd << 8; |
13823 | inst.instruction |= Rm; | |
13824 | } | |
13825 | ||
c19d1205 ZW |
13826 | static void |
13827 | do_t_rsb (void) | |
13828 | { | |
fdfde340 | 13829 | unsigned Rd, Rs; |
b99bd4ef | 13830 | |
c19d1205 ZW |
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 */ | |
b99bd4ef | 13835 | |
fdfde340 JM |
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 | ||
c19d1205 ZW |
13841 | inst.instruction |= Rd << 8; |
13842 | inst.instruction |= Rs << 16; | |
13843 | if (!inst.operands[2].isreg) | |
13844 | { | |
5b7c81bd | 13845 | bool narrow; |
026d3abb PB |
13846 | |
13847 | if ((inst.instruction & 0x00100000) != 0) | |
5ee91343 | 13848 | narrow = !in_pred_block (); |
026d3abb | 13849 | else |
5ee91343 | 13850 | narrow = in_pred_block (); |
026d3abb PB |
13851 | |
13852 | if (Rd > 7 || Rs > 7) | |
5b7c81bd | 13853 | narrow = false; |
026d3abb PB |
13854 | |
13855 | if (inst.size_req == 4 || !unified_syntax) | |
5b7c81bd | 13856 | narrow = false; |
026d3abb | 13857 | |
e2b0ab59 AV |
13858 | if (inst.relocs[0].exp.X_op != O_constant |
13859 | || inst.relocs[0].exp.X_add_number != 0) | |
5b7c81bd | 13860 | narrow = false; |
026d3abb PB |
13861 | |
13862 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
477330fc | 13863 | relaxation, but it doesn't seem worth the hassle. */ |
026d3abb PB |
13864 | if (narrow) |
13865 | { | |
e2b0ab59 | 13866 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
026d3abb PB |
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; | |
e2b0ab59 | 13874 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
026d3abb | 13875 | } |
c19d1205 ZW |
13876 | } |
13877 | else | |
13878 | encode_thumb32_shifted_operand (2); | |
13879 | } | |
b99bd4ef | 13880 | |
c19d1205 ZW |
13881 | static void |
13882 | do_t_setend (void) | |
13883 | { | |
12e37cbc MGD |
13884 | if (warn_on_deprecated |
13885 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 13886 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 13887 | |
5ee91343 | 13888 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
c19d1205 ZW |
13889 | if (inst.operands[0].imm) |
13890 | inst.instruction |= 0x8; | |
13891 | } | |
b99bd4ef | 13892 | |
c19d1205 ZW |
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 | { | |
5b7c81bd | 13901 | bool narrow; |
3d388997 PB |
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)) | |
5ee91343 | 13918 | narrow = !in_pred_block (); |
3d388997 | 13919 | else |
5ee91343 | 13920 | narrow = in_pred_block (); |
3d388997 | 13921 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
5b7c81bd | 13922 | narrow = false; |
3d388997 | 13923 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) |
5b7c81bd | 13924 | narrow = false; |
3d388997 PB |
13925 | if (inst.operands[2].isreg |
13926 | && (inst.operands[1].reg != inst.operands[0].reg | |
13927 | || inst.operands[2].reg > 7)) | |
5b7c81bd | 13928 | narrow = false; |
3d388997 | 13929 | if (inst.size_req == 4) |
5b7c81bd | 13930 | narrow = false; |
3d388997 | 13931 | |
fdfde340 JM |
13932 | reject_bad_reg (inst.operands[0].reg); |
13933 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 13934 | |
3d388997 | 13935 | if (!narrow) |
c19d1205 ZW |
13936 | { |
13937 | if (inst.operands[2].isreg) | |
b99bd4ef | 13938 | { |
fdfde340 | 13939 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
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; | |
94342ec3 NC |
13944 | |
13945 | /* PR 12854: Error on extraneous shifts. */ | |
13946 | constraint (inst.operands[2].shifted, | |
13947 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
13948 | } |
13949 | else | |
13950 | { | |
13951 | inst.operands[1].shifted = 1; | |
3d388997 | 13952 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
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. */ | |
e2b0ab59 | 13958 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b99bd4ef NC |
13959 | } |
13960 | } | |
13961 | else | |
13962 | { | |
c19d1205 | 13963 | if (inst.operands[2].isreg) |
b99bd4ef | 13964 | { |
3d388997 | 13965 | switch (shift_kind) |
b99bd4ef | 13966 | { |
3d388997 PB |
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; | |
c19d1205 | 13971 | default: abort (); |
b99bd4ef | 13972 | } |
5f4273c7 | 13973 | |
c19d1205 ZW |
13974 | inst.instruction |= inst.operands[0].reg; |
13975 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
13976 | |
13977 | /* PR 12854: Error on extraneous shifts. */ | |
13978 | constraint (inst.operands[2].shifted, | |
13979 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
13980 | } |
13981 | else | |
13982 | { | |
3d388997 | 13983 | switch (shift_kind) |
b99bd4ef | 13984 | { |
3d388997 PB |
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; | |
c19d1205 | 13988 | default: abort (); |
b99bd4ef | 13989 | } |
e2b0ab59 | 13990 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
13991 | inst.instruction |= inst.operands[0].reg; |
13992 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
13993 | } |
13994 | } | |
c19d1205 ZW |
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); | |
b99bd4ef | 14001 | |
c19d1205 ZW |
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")); | |
b99bd4ef | 14007 | |
c19d1205 ZW |
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 | } | |
5f4273c7 | 14016 | |
c19d1205 ZW |
14017 | inst.instruction |= inst.operands[0].reg; |
14018 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
14019 | |
14020 | /* PR 12854: Error on extraneous shifts. */ | |
14021 | constraint (inst.operands[2].shifted, | |
14022 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
14023 | } |
14024 | else | |
b99bd4ef | 14025 | { |
c19d1205 ZW |
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 | } | |
e2b0ab59 | 14034 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
14035 | inst.instruction |= inst.operands[0].reg; |
14036 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
14037 | } |
14038 | } | |
b99bd4ef NC |
14039 | } |
14040 | ||
14041 | static void | |
c19d1205 | 14042 | do_t_simd (void) |
b99bd4ef | 14043 | { |
fdfde340 JM |
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; | |
c19d1205 | 14057 | } |
b99bd4ef | 14058 | |
03ee1b7f NC |
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 | ||
c19d1205 | 14077 | static void |
3eb17e6b | 14078 | do_t_smc (void) |
c19d1205 | 14079 | { |
e2b0ab59 | 14080 | unsigned int value = inst.relocs[0].exp.X_add_number; |
f4c65163 MGD |
14081 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
14082 | _("SMC is not permitted on this architecture")); | |
e2b0ab59 | 14083 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 14084 | _("expression too complex")); |
ba85f98c BW |
14085 | constraint (value > 0xf, _("immediate too large (bigger than 0xF)")); |
14086 | ||
e2b0ab59 | 14087 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 | 14088 | inst.instruction |= (value & 0x000f) << 16; |
ba85f98c | 14089 | |
24382199 | 14090 | /* PR gas/15623: SMC instructions must be last in an IT block. */ |
5ee91343 | 14091 | set_pred_insn_type_last (); |
c19d1205 | 14092 | } |
b99bd4ef | 14093 | |
90ec0d68 MGD |
14094 | static void |
14095 | do_t_hvc (void) | |
14096 | { | |
e2b0ab59 | 14097 | unsigned int value = inst.relocs[0].exp.X_add_number; |
90ec0d68 | 14098 | |
e2b0ab59 | 14099 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
90ec0d68 MGD |
14100 | inst.instruction |= (value & 0x0fff); |
14101 | inst.instruction |= (value & 0xf000) << 4; | |
14102 | } | |
14103 | ||
c19d1205 | 14104 | static void |
3a21c15a | 14105 | do_t_ssat_usat (int bias) |
c19d1205 | 14106 | { |
fdfde340 JM |
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; | |
3a21c15a | 14116 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 14117 | inst.instruction |= Rn << 16; |
b99bd4ef | 14118 | |
c19d1205 | 14119 | if (inst.operands[3].present) |
b99bd4ef | 14120 | { |
e2b0ab59 | 14121 | offsetT shift_amount = inst.relocs[0].exp.X_add_number; |
3a21c15a | 14122 | |
e2b0ab59 | 14123 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
3a21c15a | 14124 | |
e2b0ab59 | 14125 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 14126 | _("expression too complex")); |
b99bd4ef | 14127 | |
3a21c15a | 14128 | if (shift_amount != 0) |
6189168b | 14129 | { |
3a21c15a NC |
14130 | constraint (shift_amount > 31, |
14131 | _("shift expression is too large")); | |
14132 | ||
c19d1205 | 14133 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
14134 | inst.instruction |= 0x00200000; /* sh bit. */ |
14135 | ||
14136 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
14137 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
14138 | } |
14139 | } | |
b99bd4ef | 14140 | } |
c921be7d | 14141 | |
3a21c15a NC |
14142 | static void |
14143 | do_t_ssat (void) | |
14144 | { | |
14145 | do_t_ssat_usat (1); | |
14146 | } | |
b99bd4ef | 14147 | |
0dd132b6 | 14148 | static void |
c19d1205 | 14149 | do_t_ssat16 (void) |
0dd132b6 | 14150 | { |
fdfde340 JM |
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; | |
c19d1205 | 14160 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 14161 | inst.instruction |= Rn << 16; |
c19d1205 | 14162 | } |
0dd132b6 | 14163 | |
c19d1205 ZW |
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, | |
01cfc07f | 14171 | BAD_ADDR_MODE); |
0dd132b6 | 14172 | |
5be8be5d DG |
14173 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
14174 | ||
c19d1205 ZW |
14175 | inst.instruction |= inst.operands[0].reg << 8; |
14176 | inst.instruction |= inst.operands[1].reg << 12; | |
14177 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 14178 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
0dd132b6 NC |
14179 | } |
14180 | ||
b99bd4ef | 14181 | static void |
c19d1205 | 14182 | do_t_strexd (void) |
b99bd4ef | 14183 | { |
c19d1205 ZW |
14184 | if (!inst.operands[2].present) |
14185 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 14186 | |
c19d1205 ZW |
14187 | constraint (inst.operands[0].reg == inst.operands[1].reg |
14188 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 14189 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 14190 | BAD_OVERLAP); |
b99bd4ef | 14191 | |
c19d1205 ZW |
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; | |
b99bd4ef NC |
14196 | } |
14197 | ||
14198 | static void | |
c19d1205 | 14199 | do_t_sxtah (void) |
b99bd4ef | 14200 | { |
fdfde340 JM |
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; | |
c19d1205 ZW |
14214 | inst.instruction |= inst.operands[3].imm << 4; |
14215 | } | |
b99bd4ef | 14216 | |
c19d1205 ZW |
14217 | static void |
14218 | do_t_sxth (void) | |
14219 | { | |
fdfde340 JM |
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); | |
c921be7d NC |
14227 | |
14228 | if (inst.instruction <= 0xffff | |
14229 | && inst.size_req != 4 | |
fdfde340 | 14230 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 14231 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 14232 | { |
c19d1205 | 14233 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
14234 | inst.instruction |= Rd; |
14235 | inst.instruction |= Rm << 3; | |
b99bd4ef | 14236 | } |
c19d1205 | 14237 | else if (unified_syntax) |
b99bd4ef | 14238 | { |
c19d1205 ZW |
14239 | if (inst.instruction <= 0xffff) |
14240 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
14241 | inst.instruction |= Rd << 8; |
14242 | inst.instruction |= Rm; | |
c19d1205 | 14243 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 14244 | } |
c19d1205 | 14245 | else |
b99bd4ef | 14246 | { |
c19d1205 ZW |
14247 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
14248 | _("Thumb encoding does not support rotation")); | |
14249 | constraint (1, BAD_HIREG); | |
b99bd4ef | 14250 | } |
c19d1205 | 14251 | } |
b99bd4ef | 14252 | |
c19d1205 ZW |
14253 | static void |
14254 | do_t_swi (void) | |
14255 | { | |
e2b0ab59 | 14256 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
c19d1205 | 14257 | } |
b99bd4ef | 14258 | |
92e90b6e PB |
14259 | static void |
14260 | do_t_tb (void) | |
14261 | { | |
fdfde340 | 14262 | unsigned Rn, Rm; |
92e90b6e PB |
14263 | int half; |
14264 | ||
14265 | half = (inst.instruction & 0x10) != 0; | |
5ee91343 | 14266 | set_pred_insn_type_last (); |
dfa9f0d5 PB |
14267 | constraint (inst.operands[0].immisreg, |
14268 | _("instruction requires register index")); | |
fdfde340 JM |
14269 | |
14270 | Rn = inst.operands[0].reg; | |
14271 | Rm = inst.operands[0].imm; | |
c921be7d | 14272 | |
5c8ed6a4 JW |
14273 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
14274 | constraint (Rn == REG_SP, BAD_SP); | |
fdfde340 JM |
14275 | reject_bad_reg (Rm); |
14276 | ||
92e90b6e PB |
14277 | constraint (!half && inst.operands[0].shifted, |
14278 | _("instruction does not allow shifted index")); | |
fdfde340 | 14279 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
14280 | } |
14281 | ||
74db7efb NC |
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 | ||
5ee91343 | 14302 | set_pred_insn_type (NEUTRAL_IT_INSN); |
74db7efb NC |
14303 | } |
14304 | ||
14305 | ||
c19d1205 ZW |
14306 | static void |
14307 | do_t_usat (void) | |
14308 | { | |
3a21c15a | 14309 | do_t_ssat_usat (0); |
b99bd4ef NC |
14310 | } |
14311 | ||
14312 | static void | |
c19d1205 | 14313 | do_t_usat16 (void) |
b99bd4ef | 14314 | { |
fdfde340 JM |
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; | |
c19d1205 | 14324 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 14325 | inst.instruction |= Rn << 16; |
b99bd4ef | 14326 | } |
c19d1205 | 14327 | |
e12437dc AV |
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 | ||
4389b29a AV |
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 | { | |
5b7c81bd | 14357 | if (v8_1_branch_value_check (inst.operands[0].imm, 5, false) == FAIL) |
4389b29a AV |
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; | |
5b7c81bd | 14374 | if (v8_1_branch_value_check (inst.operands[1].imm, 17, true) == FAIL) |
4389b29a AV |
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 | ||
65d1bc05 AV |
14389 | case T_MNEM_bfl: |
14390 | if (inst.operands[1].hasreloc == 0) | |
14391 | { | |
14392 | int val = inst.operands[1].imm; | |
5b7c81bd | 14393 | if (v8_1_branch_value_check (inst.operands[1].imm, 19, true) == FAIL) |
65d1bc05 AV |
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 | ||
f6b2b12d AV |
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 | ||
f1c7f421 AV |
14448 | case T_MNEM_bfx: |
14449 | case T_MNEM_bflx: | |
14450 | inst.instruction |= inst.operands[1].reg << 16; | |
14451 | break; | |
14452 | ||
4389b29a AV |
14453 | default: abort (); |
14454 | } | |
14455 | } | |
14456 | ||
60f993ce AV |
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 | ||
5b7c81bd | 14466 | if (v8_1_branch_value_check (value, 12, false) == FAIL) |
60f993ce AV |
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 | ||
08132bdd SP |
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 | ||
23d00a41 SD |
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 | ||
a302e574 AV |
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 | |
886e1c73 AV |
14542 | #define M_MNEM_vmullt 0xee011e00 |
14543 | #define M_MNEM_vmullb 0xee010e00 | |
efd0b310 | 14544 | #define M_MNEM_vctp 0xf000e801 |
35c228db AV |
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 | |
f5f10c66 AV |
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 | |
57785aa2 AV |
14565 | #define M_MNEM_vmovlt 0xeea01f40 |
14566 | #define M_MNEM_vmovlb 0xeea00f40 | |
14567 | #define M_MNEM_vmovnt 0xfe311e81 | |
14568 | #define M_MNEM_vmovnb 0xfe310e81 | |
c2dafc2a AV |
14569 | #define M_MNEM_vadc 0xee300f00 |
14570 | #define M_MNEM_vadci 0xee301f00 | |
14571 | #define M_MNEM_vbrsr 0xfe011e60 | |
26c1e780 AV |
14572 | #define M_MNEM_vaddlv 0xee890f00 |
14573 | #define M_MNEM_vaddlva 0xee890f20 | |
14574 | #define M_MNEM_vaddv 0xeef10f00 | |
14575 | #define M_MNEM_vaddva 0xeef10f20 | |
b409bdb6 AV |
14576 | #define M_MNEM_vddup 0xee011f6e |
14577 | #define M_MNEM_vdwdup 0xee011f60 | |
14578 | #define M_MNEM_vidup 0xee010f6e | |
14579 | #define M_MNEM_viwdup 0xee010f60 | |
13ccd4c0 AV |
14580 | #define M_MNEM_vmaxv 0xeee20f00 |
14581 | #define M_MNEM_vmaxav 0xeee00f00 | |
14582 | #define M_MNEM_vminv 0xeee20f80 | |
14583 | #define M_MNEM_vminav 0xeee00f80 | |
93925576 AV |
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 | |
1be7aba3 AV |
14598 | #define M_MNEM_vqmovnt 0xee331e01 |
14599 | #define M_MNEM_vqmovnb 0xee330e01 | |
14600 | #define M_MNEM_vqmovunt 0xee311e81 | |
14601 | #define M_MNEM_vqmovunb 0xee310e81 | |
4aa88b50 AV |
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 | |
a302e574 | 14614 | |
aab2c27d MM |
14615 | /* Bfloat16 instruction encoder helpers. */ |
14616 | #define B_MNEM_vfmat 0xfc300850 | |
14617 | #define B_MNEM_vfmab 0xfc300810 | |
14618 | ||
5287ad62 | 14619 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 14620 | |
5287ad62 | 14621 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 14622 | |
5287ad62 JB |
14623 | /* An "invalid" code for the following tables. */ |
14624 | #define N_INV -1u | |
14625 | ||
14626 | struct neon_tab_entry | |
b99bd4ef | 14627 | { |
5287ad62 JB |
14628 | unsigned integer; |
14629 | unsigned float_or_poly; | |
14630 | unsigned scalar_or_imm; | |
14631 | }; | |
5f4273c7 | 14632 | |
5287ad62 JB |
14633 | /* Map overloaded Neon opcodes to their respective encodings. */ |
14634 | #define NEON_ENC_TAB \ | |
14635 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
5ee91343 | 14636 | X(vabdl, 0x0800700, N_INV, N_INV), \ |
5287ad62 JB |
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), \ | |
5ee91343 | 14643 | X(vaddl, 0x0800000, N_INV, N_INV), \ |
5287ad62 | 14644 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ |
5ee91343 | 14645 | X(vsubl, 0x0800200, N_INV, N_INV), \ |
5287ad62 JB |
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 | |
e07e6e58 | 14650 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
14651 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
14652 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
14653 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
14654 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
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), \ | |
d6b4b13e MW |
14666 | X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \ |
14667 | X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \ | |
5287ad62 JB |
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), \ | |
037e8744 JB |
14690 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
14691 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
14692 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
14693 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
14694 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
14695 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
14696 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
14697 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
14698 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
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), \ | |
73924fbc MGD |
14703 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
14704 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 14705 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
14706 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
14707 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 14708 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 14709 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
14710 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
14711 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
14712 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
14713 | |
14714 | enum neon_opc | |
14715 | { | |
14716 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
14717 | NEON_ENC_TAB | |
14718 | #undef X | |
14719 | }; | |
b99bd4ef | 14720 | |
5287ad62 JB |
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 | }; | |
b99bd4ef | 14727 | |
88714cb8 DG |
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) \ | |
037e8744 | 14739 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 14740 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 14741 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
14742 | #define NEON_ENC_FPV8_(X) \ |
14743 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 14744 | |
88714cb8 DG |
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 | ||
037e8744 JB |
14764 | /* Define shapes for instruction operands. The following mnemonic characters |
14765 | are used in this table: | |
5287ad62 | 14766 | |
037e8744 | 14767 | F - VFP S<n> register |
5287ad62 JB |
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 | |
5f4273c7 | 14774 | |
037e8744 JB |
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. | |
5f4273c7 | 14779 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 14780 | |
037e8744 | 14781 | #define NEON_SHAPE_DEF \ |
93925576 | 14782 | X(4, (R, R, Q, Q), QUAD), \ |
b409bdb6 | 14783 | X(4, (Q, R, R, I), QUAD), \ |
57785aa2 AV |
14784 | X(4, (R, R, S, S), QUAD), \ |
14785 | X(4, (S, S, R, R), QUAD), \ | |
b409bdb6 | 14786 | X(3, (Q, R, I), QUAD), \ |
1b883319 AV |
14787 | X(3, (I, Q, Q), QUAD), \ |
14788 | X(3, (I, Q, R), QUAD), \ | |
a302e574 | 14789 | X(3, (R, Q, Q), QUAD), \ |
037e8744 JB |
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), \ | |
5ee91343 | 14796 | X(3, (Q, Q, R), QUAD), \ |
26c1e780 AV |
14797 | X(3, (R, R, Q), QUAD), \ |
14798 | X(2, (R, Q), QUAD), \ | |
037e8744 JB |
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), \ | |
5aae9ae9 MM |
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), \ | |
037e8744 JB |
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), \ | |
c28eeff2 SN |
14828 | X(4, (D, D, S, I), DOUBLE), \ |
14829 | X(4, (Q, Q, S, I), QUAD), \ | |
037e8744 JB |
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), \ | |
d54af2d0 | 14843 | X(2, (R, F), SINGLE), \ |
1f6234a3 AV |
14844 | /* Used for MVE tail predicated loop instructions. */\ |
14845 | X(2, (R, R), QUAD), \ | |
d54af2d0 RL |
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), \ | |
dec41383 JW |
14857 | X (3, (F, H, I), MIXED), \ |
14858 | X (3, (D, H, H), MIXED), \ | |
14859 | X (3, (D, H, S), MIXED) | |
037e8744 JB |
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 | |
5aae9ae9 | 14864 | #define S5(A,B,C,D,E) NS_##A##B##C##D##E |
037e8744 JB |
14865 | |
14866 | #define X(N, L, C) S##N L | |
14867 | ||
5287ad62 JB |
14868 | enum neon_shape |
14869 | { | |
037e8744 JB |
14870 | NEON_SHAPE_DEF, |
14871 | NS_NULL | |
5287ad62 | 14872 | }; |
b99bd4ef | 14873 | |
037e8744 JB |
14874 | #undef X |
14875 | #undef S2 | |
14876 | #undef S3 | |
14877 | #undef S4 | |
5aae9ae9 | 14878 | #undef S5 |
037e8744 JB |
14879 | |
14880 | enum neon_shape_class | |
14881 | { | |
d54af2d0 | 14882 | SC_HALF, |
037e8744 JB |
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 | { | |
d54af2d0 | 14900 | SE_H, |
037e8744 JB |
14901 | SE_F, |
14902 | SE_D, | |
14903 | SE_Q, | |
14904 | SE_I, | |
14905 | SE_S, | |
14906 | SE_R, | |
5aae9ae9 MM |
14907 | SE_L, |
14908 | SE_P | |
037e8744 JB |
14909 | }; |
14910 | ||
14911 | /* Register widths of above. */ | |
14912 | static unsigned neon_shape_el_size[] = | |
14913 | { | |
d54af2d0 | 14914 | 16, |
037e8744 JB |
14915 | 32, |
14916 | 64, | |
14917 | 128, | |
14918 | 0, | |
14919 | 32, | |
14920 | 32, | |
5aae9ae9 | 14921 | 0, |
037e8744 JB |
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 } | |
5aae9ae9 | 14934 | #define S5(A,B,C,D,E) { SE_##A, SE_##B, SE_##C, SE_##D, SE_##E } |
037e8744 JB |
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 | |
5aae9ae9 | 14947 | #undef S5 |
037e8744 | 14948 | |
5287ad62 JB |
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 | { | |
8e79c3df CM |
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, | |
4f51b4bd | 14978 | N_P64 = 0x0200000, |
aab2c27d | 14979 | N_BF16 = 0x0400000, |
c921be7d NC |
14980 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
14981 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 14982 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 14983 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
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. */ | |
5287ad62 | 14991 | N_UTYP = 0, |
4f51b4bd | 14992 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
14993 | }; |
14994 | ||
dcbf9037 JB |
14995 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
14996 | ||
5287ad62 JB |
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) | |
cc933301 JW |
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) | |
5287ad62 | 15003 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) |
cc933301 | 15004 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32) |
d54af2d0 | 15005 | #define N_F_ALL (N_F16 | N_F32 | N_F64) |
5ee91343 AV |
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) | |
5287ad62 JB |
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 | ||
037e8744 JB |
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. */ | |
5287ad62 JB |
15019 | |
15020 | static enum neon_shape | |
037e8744 | 15021 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 15022 | { |
037e8744 JB |
15023 | va_list ap; |
15024 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
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 | ||
037e8744 | 15033 | va_start (ap, shape); |
5f4273c7 | 15034 | |
21d799b5 | 15035 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
15036 | { |
15037 | unsigned j; | |
15038 | int matches = 1; | |
15039 | ||
15040 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
477330fc RM |
15041 | { |
15042 | if (!inst.operands[j].present) | |
15043 | { | |
15044 | matches = 0; | |
15045 | break; | |
15046 | } | |
15047 | ||
15048 | switch (neon_shape_tab[shape].el[j]) | |
15049 | { | |
d54af2d0 RL |
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 | ||
477330fc RM |
15090 | case SE_F: |
15091 | if (!(inst.operands[j].isreg | |
15092 | && inst.operands[j].isvec | |
15093 | && inst.operands[j].issingle | |
d54af2d0 RL |
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))))) | |
477330fc RM |
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 | ||
5aae9ae9 | 15137 | case SE_P: |
477330fc RM |
15138 | case SE_L: |
15139 | break; | |
15140 | } | |
3fde54a2 JZ |
15141 | if (!matches) |
15142 | break; | |
477330fc | 15143 | } |
ad6cec43 MGD |
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. */ | |
477330fc | 15147 | break; |
037e8744 | 15148 | } |
5f4273c7 | 15149 | |
037e8744 | 15150 | va_end (ap); |
5287ad62 | 15151 | |
037e8744 JB |
15152 | if (shape == NS_NULL && first_shape != NS_NULL) |
15153 | first_error (_("invalid instruction shape")); | |
5287ad62 | 15154 | |
037e8744 JB |
15155 | return shape; |
15156 | } | |
5287ad62 | 15157 | |
037e8744 JB |
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; | |
5287ad62 | 15165 | } |
037e8744 | 15166 | |
5287ad62 JB |
15167 | static void |
15168 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
477330fc | 15169 | unsigned *g_size) |
5287ad62 JB |
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) | |
477330fc | 15182 | *g_type = NT_unsigned; |
5287ad62 | 15183 | else if ((typebits & N_INT) != 0) |
477330fc | 15184 | *g_type = NT_integer; |
5287ad62 | 15185 | else if ((typebits & N_FLT) != 0) |
477330fc | 15186 | *g_type = NT_float; |
dcbf9037 | 15187 | else if ((typebits & N_SIZ) != 0) |
477330fc | 15188 | *g_type = NT_untyped; |
5287ad62 JB |
15189 | } |
15190 | } | |
5f4273c7 | 15191 | |
5287ad62 JB |
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; | |
5f4273c7 | 15200 | |
9c2799c2 | 15201 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 15202 | |
5287ad62 JB |
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) | |
477330fc RM |
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 | } | |
5287ad62 JB |
15224 | break; |
15225 | ||
15226 | case NT_integer: | |
15227 | switch (size) | |
477330fc RM |
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 | } | |
5287ad62 JB |
15235 | break; |
15236 | ||
15237 | case NT_float: | |
037e8744 | 15238 | switch (size) |
477330fc | 15239 | { |
8e79c3df | 15240 | case 16: return N_F16; |
477330fc RM |
15241 | case 32: return N_F32; |
15242 | case 64: return N_F64; | |
15243 | default: ; | |
15244 | } | |
5287ad62 JB |
15245 | break; |
15246 | ||
15247 | case NT_poly: | |
15248 | switch (size) | |
477330fc RM |
15249 | { |
15250 | case 8: return N_P8; | |
15251 | case 16: return N_P16; | |
4f51b4bd | 15252 | case 64: return N_P64; |
477330fc RM |
15253 | default: ; |
15254 | } | |
5287ad62 JB |
15255 | break; |
15256 | ||
15257 | case NT_signed: | |
15258 | switch (size) | |
477330fc RM |
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 | } | |
5287ad62 JB |
15266 | break; |
15267 | ||
15268 | case NT_unsigned: | |
15269 | switch (size) | |
477330fc RM |
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 | } | |
5287ad62 JB |
15277 | break; |
15278 | ||
aab2c27d MM |
15279 | case NT_bfloat: |
15280 | if (size == 16) return N_BF16; | |
15281 | break; | |
15282 | ||
5287ad62 JB |
15283 | default: ; |
15284 | } | |
5f4273c7 | 15285 | |
5287ad62 JB |
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 | ||
dcbf9037 | 15292 | static int |
5287ad62 | 15293 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
477330fc | 15294 | enum neon_type_mask mask) |
5287ad62 | 15295 | { |
dcbf9037 JB |
15296 | if ((mask & N_EQK) != 0) |
15297 | return FAIL; | |
15298 | ||
5287ad62 JB |
15299 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
15300 | *size = 8; | |
aab2c27d MM |
15301 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16 | N_BF16)) |
15302 | != 0) | |
5287ad62 | 15303 | *size = 16; |
dcbf9037 | 15304 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 15305 | *size = 32; |
4f51b4bd | 15306 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 15307 | *size = 64; |
dcbf9037 JB |
15308 | else |
15309 | return FAIL; | |
15310 | ||
5287ad62 JB |
15311 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
15312 | *type = NT_signed; | |
dcbf9037 | 15313 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 15314 | *type = NT_unsigned; |
dcbf9037 | 15315 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 15316 | *type = NT_integer; |
dcbf9037 | 15317 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 15318 | *type = NT_untyped; |
4f51b4bd | 15319 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 15320 | *type = NT_poly; |
d54af2d0 | 15321 | else if ((mask & (N_F_ALL)) != 0) |
5287ad62 | 15322 | *type = NT_float; |
aab2c27d MM |
15323 | else if ((mask & (N_BF16)) != 0) |
15324 | *type = NT_bfloat; | |
dcbf9037 JB |
15325 | else |
15326 | return FAIL; | |
5f4273c7 | 15327 | |
dcbf9037 | 15328 | return SUCCESS; |
5287ad62 JB |
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; | |
5f4273c7 | 15341 | |
5287ad62 | 15342 | destmask = 0; |
5f4273c7 | 15343 | |
5287ad62 JB |
15344 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
15345 | { | |
21d799b5 | 15346 | if (el_type_of_type_chk (&type, &size, |
477330fc RM |
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 | } | |
5287ad62 | 15352 | } |
5f4273c7 | 15353 | |
5287ad62 JB |
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 | |
037e8744 | 15367 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
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) | |
477330fc RM |
15391 | { |
15392 | va_end (ap); | |
15393 | return badtype; | |
15394 | } | |
5287ad62 JB |
15395 | types[i] = thisarg; |
15396 | if ((thisarg & N_KEY) != 0) | |
477330fc | 15397 | key_el = i; |
5287ad62 JB |
15398 | } |
15399 | va_end (ap); | |
15400 | ||
dcbf9037 JB |
15401 | if (inst.vectype.elems > 0) |
15402 | for (i = 0; i < els; i++) | |
15403 | if (inst.operands[i].vectype.type != NT_invtype) | |
477330fc RM |
15404 | { |
15405 | first_error (_("types specified in both the mnemonic and operands")); | |
15406 | return badtype; | |
15407 | } | |
dcbf9037 | 15408 | |
5287ad62 JB |
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++) | |
477330fc RM |
15419 | if (j != key_el) |
15420 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
15421 | types[j]); | |
dcbf9037 JB |
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 | |
477330fc RM |
15427 | after each operand. We allow some flexibility here; as long as the |
15428 | "key" operand has a type, we can infer the others. */ | |
dcbf9037 | 15429 | for (j = 0; j < els; j++) |
477330fc RM |
15430 | if (inst.operands[j].vectype.type != NT_invtype) |
15431 | inst.vectype.el[j] = inst.operands[j].vectype; | |
dcbf9037 JB |
15432 | |
15433 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
477330fc RM |
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 | } | |
dcbf9037 | 15440 | else |
477330fc RM |
15441 | { |
15442 | first_error (_("operand types can't be inferred")); | |
15443 | return badtype; | |
15444 | } | |
5287ad62 JB |
15445 | } |
15446 | else if (inst.vectype.elems != els) | |
15447 | { | |
dcbf9037 | 15448 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
15449 | return badtype; |
15450 | } | |
15451 | ||
15452 | for (pass = 0; pass < 2; pass++) | |
15453 | { | |
15454 | for (i = 0; i < els; i++) | |
477330fc RM |
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 | |
5287ad62 | 15463 | integer types if sign-specific variants are unavailable. */ |
477330fc | 15464 | if ((g_type == NT_signed || g_type == NT_unsigned) |
5287ad62 JB |
15465 | && (types_allowed & N_SU_ALL) == 0) |
15466 | g_type = NT_integer; | |
15467 | ||
477330fc | 15468 | /* If only untyped args are allowed, decay any more specific types to |
5287ad62 JB |
15469 | them. Some instructions only care about signs for some element |
15470 | sizes, so handle that properly. */ | |
477330fc | 15471 | if (((types_allowed & N_UNT) == 0) |
91ff7894 MGD |
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))) | |
5287ad62 JB |
15476 | g_type = NT_untyped; |
15477 | ||
477330fc RM |
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; | |
cc933301 JW |
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 | } | |
477330fc RM |
15494 | } |
15495 | } | |
15496 | else | |
15497 | { | |
15498 | if ((thisarg & N_VFP) != 0) | |
15499 | { | |
15500 | enum neon_shape_el regshape; | |
15501 | unsigned regwidth, match; | |
99b253c5 NC |
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 | } | |
477330fc RM |
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 | ||
9db2f6b4 RL |
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 | ||
477330fc RM |
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 | { | |
a302e574 | 15545 | first_error (BAD_SIMD_TYPE); |
477330fc RM |
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 | } | |
5287ad62 JB |
15562 | } |
15563 | ||
15564 | return inst.vectype.el[key_el]; | |
15565 | } | |
15566 | ||
037e8744 | 15567 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 15568 | |
037e8744 JB |
15569 | /* Thumb VFP instructions have 0xE in the condition field. */ |
15570 | ||
15571 | static void | |
15572 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 15573 | { |
88714cb8 DG |
15574 | inst.is_neon = 1; |
15575 | ||
5287ad62 | 15576 | if (thumb_mode) |
037e8744 | 15577 | inst.instruction |= 0xe0000000; |
5287ad62 | 15578 | else |
037e8744 | 15579 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
15580 | } |
15581 | ||
037e8744 JB |
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. */ | |
5287ad62 | 15589 | |
037e8744 JB |
15590 | static void |
15591 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 15592 | { |
037e8744 | 15593 | const struct asm_opcode *opcode; |
5f4273c7 | 15594 | |
629310ab | 15595 | opcode = (const struct asm_opcode *) str_hash_find (arm_ops_hsh, opname); |
5287ad62 | 15596 | |
037e8744 JB |
15597 | if (!opcode) |
15598 | abort (); | |
5287ad62 | 15599 | |
037e8744 | 15600 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
477330fc RM |
15601 | thumb_mode ? *opcode->tvariant : *opcode->avariant), |
15602 | _(BAD_FPU)); | |
5287ad62 | 15603 | |
88714cb8 DG |
15604 | inst.is_neon = 1; |
15605 | ||
037e8744 JB |
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 | } | |
5287ad62 JB |
15617 | |
15618 | static void | |
037e8744 | 15619 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 15620 | { |
037e8744 JB |
15621 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
15622 | ||
9db2f6b4 | 15623 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
15624 | { |
15625 | if (is_add) | |
477330fc | 15626 | do_vfp_nsyn_opcode ("fadds"); |
037e8744 | 15627 | else |
477330fc | 15628 | do_vfp_nsyn_opcode ("fsubs"); |
9db2f6b4 RL |
15629 | |
15630 | /* ARMv8.2 fp16 instruction. */ | |
15631 | if (rs == NS_HHH) | |
15632 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15633 | } |
15634 | else | |
15635 | { | |
15636 | if (is_add) | |
477330fc | 15637 | do_vfp_nsyn_opcode ("faddd"); |
037e8744 | 15638 | else |
477330fc | 15639 | do_vfp_nsyn_opcode ("fsubd"); |
037e8744 JB |
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: | |
9db2f6b4 RL |
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); | |
037e8744 | 15657 | break; |
5f4273c7 | 15658 | |
037e8744 | 15659 | case 3: |
9db2f6b4 RL |
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); | |
037e8744 JB |
15663 | break; |
15664 | ||
15665 | default: | |
15666 | abort (); | |
15667 | } | |
15668 | ||
15669 | if (et.type != NT_invtype) | |
15670 | { | |
15671 | pfn (rs); | |
15672 | return SUCCESS; | |
15673 | } | |
037e8744 | 15674 | |
99b253c5 | 15675 | inst.error = NULL; |
037e8744 JB |
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; | |
5f4273c7 | 15683 | |
9db2f6b4 | 15684 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
15685 | { |
15686 | if (is_mla) | |
477330fc | 15687 | do_vfp_nsyn_opcode ("fmacs"); |
037e8744 | 15688 | else |
477330fc | 15689 | do_vfp_nsyn_opcode ("fnmacs"); |
9db2f6b4 RL |
15690 | |
15691 | /* ARMv8.2 fp16 instruction. */ | |
15692 | if (rs == NS_HHH) | |
15693 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15694 | } |
15695 | else | |
15696 | { | |
15697 | if (is_mla) | |
477330fc | 15698 | do_vfp_nsyn_opcode ("fmacd"); |
037e8744 | 15699 | else |
477330fc | 15700 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
15701 | } |
15702 | } | |
15703 | ||
62f3b8c8 PB |
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 | ||
9db2f6b4 | 15709 | if (rs == NS_FFF || rs == NS_HHH) |
62f3b8c8 PB |
15710 | { |
15711 | if (is_fma) | |
477330fc | 15712 | do_vfp_nsyn_opcode ("ffmas"); |
62f3b8c8 | 15713 | else |
477330fc | 15714 | do_vfp_nsyn_opcode ("ffnmas"); |
9db2f6b4 RL |
15715 | |
15716 | /* ARMv8.2 fp16 instruction. */ | |
15717 | if (rs == NS_HHH) | |
15718 | do_scalar_fp16_v82_encode (); | |
62f3b8c8 PB |
15719 | } |
15720 | else | |
15721 | { | |
15722 | if (is_fma) | |
477330fc | 15723 | do_vfp_nsyn_opcode ("ffmad"); |
62f3b8c8 | 15724 | else |
477330fc | 15725 | do_vfp_nsyn_opcode ("ffnmad"); |
62f3b8c8 PB |
15726 | } |
15727 | } | |
15728 | ||
037e8744 JB |
15729 | static void |
15730 | do_vfp_nsyn_mul (enum neon_shape rs) | |
15731 | { | |
9db2f6b4 RL |
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 | } | |
037e8744 JB |
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; | |
9db2f6b4 | 15748 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY); |
037e8744 | 15749 | |
9db2f6b4 | 15750 | if (rs == NS_FF || rs == NS_HH) |
037e8744 JB |
15751 | { |
15752 | if (is_neg) | |
477330fc | 15753 | do_vfp_nsyn_opcode ("fnegs"); |
037e8744 | 15754 | else |
477330fc | 15755 | do_vfp_nsyn_opcode ("fabss"); |
9db2f6b4 RL |
15756 | |
15757 | /* ARMv8.2 fp16 instruction. */ | |
15758 | if (rs == NS_HH) | |
15759 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15760 | } |
15761 | else | |
15762 | { | |
15763 | if (is_neg) | |
477330fc | 15764 | do_vfp_nsyn_opcode ("fnegd"); |
037e8744 | 15765 | else |
477330fc | 15766 | do_vfp_nsyn_opcode ("fabsd"); |
037e8744 JB |
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) | |
477330fc | 15780 | do_vfp_nsyn_opcode ("fldmdbs"); |
037e8744 | 15781 | else |
477330fc | 15782 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 JB |
15783 | } |
15784 | else | |
15785 | { | |
15786 | if (is_dbmode) | |
477330fc | 15787 | do_vfp_nsyn_opcode ("fstmdbs"); |
037e8744 | 15788 | else |
477330fc | 15789 | do_vfp_nsyn_opcode ("fstmias"); |
037e8744 JB |
15790 | } |
15791 | } | |
15792 | ||
037e8744 JB |
15793 | static void |
15794 | do_vfp_nsyn_sqrt (void) | |
15795 | { | |
9db2f6b4 RL |
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); | |
5f4273c7 | 15798 | |
9db2f6b4 RL |
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 | } | |
037e8744 JB |
15807 | else |
15808 | do_vfp_nsyn_opcode ("fsqrtd"); | |
15809 | } | |
15810 | ||
15811 | static void | |
15812 | do_vfp_nsyn_div (void) | |
15813 | { | |
9db2f6b4 | 15814 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 15815 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 15816 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 15817 | |
9db2f6b4 RL |
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 | } | |
037e8744 JB |
15826 | else |
15827 | do_vfp_nsyn_opcode ("fdivd"); | |
15828 | } | |
15829 | ||
15830 | static void | |
15831 | do_vfp_nsyn_nmul (void) | |
15832 | { | |
9db2f6b4 | 15833 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 15834 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 15835 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 15836 | |
9db2f6b4 | 15837 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 | 15838 | { |
88714cb8 | 15839 | NEON_ENCODE (SINGLE, inst); |
037e8744 | 15840 | do_vfp_sp_dyadic (); |
9db2f6b4 RL |
15841 | |
15842 | /* ARMv8.2 fp16 instruction. */ | |
15843 | if (rs == NS_HHH) | |
15844 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15845 | } |
15846 | else | |
15847 | { | |
88714cb8 | 15848 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
15849 | do_vfp_dp_rd_rn_rm (); |
15850 | } | |
15851 | do_vfp_cond_or_thumb (); | |
9db2f6b4 | 15852 | |
037e8744 JB |
15853 | } |
15854 | ||
1b883319 AV |
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) | |
5aae9ae9 MM |
15866 | #define LOW1(R) ((R) & 0x1) |
15867 | #define HI4(R) (((R) >> 1) & 0xf) | |
1b883319 AV |
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 | ||
efd0b310 SP |
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 | ||
1b883319 AV |
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); | |
5b7c81bd | 16040 | now_pred.warn_deprecated = false; |
1b883319 AV |
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 | ||
935295b5 AV |
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 | ||
f30ee27c AV |
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 | ||
b409bdb6 AV |
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 | ||
2d78f95b AV |
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 | ||
acca5630 AV |
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 | ||
4aa88b50 AV |
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 | ||
1be7aba3 AV |
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 | ||
3063888e AV |
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 | ||
935295b5 AV |
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 | ||
5d281bf0 AV |
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 | ||
1f6234a3 AV |
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 | ||
5b7c81bd | 16476 | v8_1_loop_reloc (true); |
1f6234a3 AV |
16477 | break; |
16478 | ||
16479 | case T_MNEM_wls: | |
16480 | case T_MNEM_wlstp: | |
5b7c81bd | 16481 | v8_1_loop_reloc (false); |
1f6234a3 AV |
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 | ||
037e8744 JB |
16503 | static void |
16504 | do_vfp_nsyn_cmp (void) | |
16505 | { | |
9db2f6b4 | 16506 | enum neon_shape rs; |
1b883319 AV |
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 | ||
037e8744 JB |
16519 | if (inst.operands[1].isreg) |
16520 | { | |
9db2f6b4 RL |
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); | |
5f4273c7 | 16523 | |
9db2f6b4 | 16524 | if (rs == NS_FF || rs == NS_HH) |
477330fc RM |
16525 | { |
16526 | NEON_ENCODE (SINGLE, inst); | |
16527 | do_vfp_sp_monadic (); | |
16528 | } | |
037e8744 | 16529 | else |
477330fc RM |
16530 | { |
16531 | NEON_ENCODE (DOUBLE, inst); | |
16532 | do_vfp_dp_rd_rm (); | |
16533 | } | |
037e8744 JB |
16534 | } |
16535 | else | |
16536 | { | |
9db2f6b4 RL |
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); | |
037e8744 JB |
16539 | |
16540 | switch (inst.instruction & 0x0fffffff) | |
477330fc RM |
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 | } | |
5f4273c7 | 16551 | |
9db2f6b4 | 16552 | if (rs == NS_FI || rs == NS_HI) |
477330fc RM |
16553 | { |
16554 | NEON_ENCODE (SINGLE, inst); | |
16555 | do_vfp_sp_compare_z (); | |
16556 | } | |
037e8744 | 16557 | else |
477330fc RM |
16558 | { |
16559 | NEON_ENCODE (DOUBLE, inst); | |
16560 | do_vfp_dp_rd (); | |
16561 | } | |
037e8744 JB |
16562 | } |
16563 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
16564 | |
16565 | /* ARMv8.2 fp16 instruction. */ | |
16566 | if (rs == NS_HI || rs == NS_HH) | |
16567 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
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])); | |
fdfde340 | 16575 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
16576 | inst.operands[0].isreg = 1; |
16577 | inst.operands[0].writeback = 1; | |
16578 | inst.operands[0].present = 1; | |
16579 | } | |
16580 | ||
037e8744 JB |
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 | ||
88714cb8 DG |
16584 | static void |
16585 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 16586 | { |
88714cb8 DG |
16587 | unsigned int i = insn->instruction; |
16588 | insn->is_neon = 1; | |
16589 | ||
037e8744 JB |
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)) | |
477330fc | 16594 | i |= 1 << 28; |
5f4273c7 | 16595 | |
037e8744 | 16596 | i &= ~(1 << 24); |
5f4273c7 | 16597 | |
037e8744 JB |
16598 | i |= 0xef000000; |
16599 | } | |
16600 | else | |
16601 | i |= 0xf2000000; | |
5f4273c7 | 16602 | |
88714cb8 | 16603 | insn->instruction = i; |
037e8744 JB |
16604 | } |
16605 | ||
5ee91343 | 16606 | static void |
7df54120 | 16607 | mve_encode_qqr (int size, int U, int fp) |
5ee91343 AV |
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; | |
a8465a06 AV |
16622 | /* vmul. */ |
16623 | else if (((unsigned)inst.instruction) == 0x1000d10) | |
16624 | inst.instruction = 0xee310e60; | |
5ee91343 AV |
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; | |
7df54120 AV |
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; | |
a8465a06 AV |
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; | |
42b16635 AV |
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; | |
7df54120 AV |
16664 | |
16665 | /* Set U-bit. */ | |
16666 | inst.instruction |= U << 28; | |
16667 | ||
5ee91343 AV |
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 | ||
a302e574 AV |
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 | ||
886e1c73 AV |
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 | ||
26c1e780 AV |
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 | } | |
886e1c73 | 16717 | |
93925576 AV |
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 | ||
aab2c27d MM |
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 | ||
037e8744 JB |
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 | | |
5f4273c7 | 16751 | |
037e8744 JB |
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 | { | |
aab2c27d | 16758 | neon_three_args (isquad); |
037e8744 JB |
16759 | inst.instruction |= (ubit != 0) << 24; |
16760 | if (size != -1) | |
16761 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 16762 | |
88714cb8 | 16763 | neon_dp_fixup (&inst); |
037e8744 JB |
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 | | |
5287ad62 JB |
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 | ||
88714cb8 | 16786 | neon_dp_fixup (&inst); |
5287ad62 JB |
16787 | } |
16788 | ||
7df54120 AV |
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 | } | |
7af67752 | 16826 | if (inst.uncond_value != -1u) |
7df54120 AV |
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 | ||
64c350f2 AV |
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 | ||
5b7c81bd | 16848 | static bool |
7df54120 AV |
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; | |
5b7c81bd | 16856 | return false; |
7df54120 AV |
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) | |
5b7c81bd | 16865 | return false; |
7df54120 AV |
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) | |
5b7c81bd | 16871 | return false; |
7df54120 AV |
16872 | |
16873 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
16874 | inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN; | |
16875 | } | |
5b7c81bd | 16876 | return true; |
7df54120 AV |
16877 | } |
16878 | ||
5287ad62 JB |
16879 | /* Neon instruction encoders, in approximate order of appearance. */ |
16880 | ||
16881 | static void | |
16882 | do_neon_dyadic_i_su (void) | |
16883 | { | |
5b7c81bd | 16884 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
7df54120 AV |
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); | |
5287ad62 JB |
16901 | } |
16902 | ||
16903 | static void | |
16904 | do_neon_dyadic_i64_su (void) | |
16905 | { | |
5b7c81bd | 16906 | if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
a8465a06 AV |
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); | |
5287ad62 JB |
16924 | } |
16925 | ||
16926 | static void | |
16927 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
477330fc | 16928 | unsigned immbits) |
5287ad62 JB |
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 | ||
88714cb8 | 16942 | neon_dp_fixup (&inst); |
5287ad62 JB |
16943 | } |
16944 | ||
16945 | static void | |
5150f0d8 | 16946 | do_neon_shl (void) |
5287ad62 | 16947 | { |
5b7c81bd | 16948 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
5150f0d8 AV |
16949 | return; |
16950 | ||
5287ad62 JB |
16951 | if (!inst.operands[2].isreg) |
16952 | { | |
5150f0d8 AV |
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 | } | |
cb3b1e65 JB |
16965 | int imm = inst.operands[2].imm; |
16966 | ||
16967 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
16968 | _("immediate out of range for shift")); | |
88714cb8 | 16969 | NEON_ENCODE (IMMED, inst); |
5b7c81bd | 16970 | neon_imm_shift (false, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
16971 | } |
16972 | else | |
16973 | { | |
5150f0d8 AV |
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 | } | |
5287ad62 JB |
17022 | } |
17023 | } | |
17024 | ||
17025 | static void | |
5150f0d8 | 17026 | do_neon_qshl (void) |
5287ad62 | 17027 | { |
5b7c81bd | 17028 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
5150f0d8 AV |
17029 | return; |
17030 | ||
5287ad62 JB |
17031 | if (!inst.operands[2].isreg) |
17032 | { | |
5150f0d8 AV |
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 | } | |
cb3b1e65 | 17045 | int imm = inst.operands[2].imm; |
627907b7 | 17046 | |
cb3b1e65 JB |
17047 | constraint (imm < 0 || (unsigned)imm >= et.size, |
17048 | _("immediate out of range for shift")); | |
88714cb8 | 17049 | NEON_ENCODE (IMMED, inst); |
5b7c81bd | 17050 | neon_imm_shift (true, et.type == NT_unsigned, neon_quad (rs), et, imm); |
5287ad62 JB |
17051 | } |
17052 | else | |
17053 | { | |
5150f0d8 AV |
17054 | enum neon_shape rs; |
17055 | struct neon_type_el et; | |
627907b7 | 17056 | |
5150f0d8 AV |
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 | } | |
5287ad62 JB |
17096 | } |
17097 | } | |
17098 | ||
627907b7 JB |
17099 | static void |
17100 | do_neon_rshl (void) | |
17101 | { | |
5b7c81bd | 17102 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
1be7aba3 AV |
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 | ||
627907b7 JB |
17118 | unsigned int tmp; |
17119 | ||
1be7aba3 AV |
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 | } | |
627907b7 JB |
17151 | } |
17152 | ||
5287ad62 JB |
17153 | static int |
17154 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
17155 | { | |
036dc3f7 PB |
17156 | /* Handle .I8 pseudo-instructions. */ |
17157 | if (size == 8) | |
5287ad62 | 17158 | { |
5287ad62 | 17159 | /* Unfortunately, this will make everything apart from zero out-of-range. |
477330fc RM |
17160 | FIXME is this the intended semantics? There doesn't seem much point in |
17161 | accepting .I8 if so. */ | |
5287ad62 JB |
17162 | immediate |= immediate << 8; |
17163 | size = 16; | |
036dc3f7 PB |
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; | |
5287ad62 JB |
17191 | } |
17192 | ||
17193 | if (immediate == (immediate & 0x000000ff)) | |
17194 | { | |
17195 | *immbits = immediate; | |
036dc3f7 | 17196 | return 0x9; |
5287ad62 JB |
17197 | } |
17198 | else if (immediate == (immediate & 0x0000ff00)) | |
17199 | { | |
17200 | *immbits = immediate >> 8; | |
036dc3f7 | 17201 | return 0xb; |
5287ad62 JB |
17202 | } |
17203 | ||
17204 | bad_immediate: | |
dcbf9037 | 17205 | first_error (_("immediate value out of range")); |
5287ad62 JB |
17206 | return FAIL; |
17207 | } | |
17208 | ||
5287ad62 JB |
17209 | static void |
17210 | do_neon_logic (void) | |
17211 | { | |
17212 | if (inst.operands[2].present && inst.operands[2].isreg) | |
17213 | { | |
037e8744 | 17214 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
f601a00c | 17215 | if (rs == NS_QQQ |
5b7c81bd | 17216 | && !check_simd_pred_availability (false, |
64c350f2 | 17217 | NEON_CHECK_ARCH | NEON_CHECK_CC)) |
f601a00c AV |
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 | ||
5287ad62 JB |
17223 | neon_check_type (3, rs, N_IGNORE_TYPE); |
17224 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 17225 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 17226 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
17227 | } |
17228 | else | |
17229 | { | |
4316f0d2 DG |
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)); | |
f601a00c AV |
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 | |
5b7c81bd | 17239 | && !check_simd_pred_availability (false, |
64c350f2 | 17240 | NEON_CHECK_ARCH | NEON_CHECK_CC)) |
f601a00c AV |
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; | |
21d799b5 | 17255 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
17256 | unsigned immbits; |
17257 | int cmode; | |
5f4273c7 | 17258 | |
5f4273c7 | 17259 | |
4316f0d2 DG |
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 | ||
88714cb8 | 17264 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 17265 | |
4316f0d2 | 17266 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
17267 | if (et.size == 64) |
17268 | { | |
17269 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
17270 | pattern. */ | |
4316f0d2 DG |
17271 | if (immbits != (inst.operands[immoperand].regisimm ? |
17272 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
17273 | { |
17274 | /* Set immbits to an invalid constant. */ | |
17275 | immbits = 0xdeadbeef; | |
17276 | } | |
17277 | } | |
17278 | ||
5287ad62 | 17279 | switch (opcode) |
477330fc RM |
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 | } | |
5287ad62 JB |
17304 | |
17305 | if (cmode == FAIL) | |
477330fc | 17306 | return; |
5287ad62 | 17307 | |
037e8744 | 17308 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
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); | |
5f4273c7 | 17313 | |
88714cb8 | 17314 | neon_dp_fixup (&inst); |
5287ad62 JB |
17315 | } |
17316 | } | |
17317 | ||
17318 | static void | |
17319 | do_neon_bitfield (void) | |
17320 | { | |
037e8744 | 17321 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 17322 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 17323 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
17324 | } |
17325 | ||
17326 | static void | |
dcbf9037 | 17327 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
477330fc | 17328 | unsigned destbits) |
5287ad62 | 17329 | { |
5ee91343 | 17330 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL); |
dcbf9037 | 17331 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
477330fc | 17332 | types | N_KEY); |
5287ad62 JB |
17333 | if (et.type == NT_float) |
17334 | { | |
88714cb8 | 17335 | NEON_ENCODE (FLOAT, inst); |
5ee91343 | 17336 | if (rs == NS_QQR) |
7df54120 | 17337 | mve_encode_qqr (et.size, 0, 1); |
5ee91343 AV |
17338 | else |
17339 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); | |
5287ad62 JB |
17340 | } |
17341 | else | |
17342 | { | |
88714cb8 | 17343 | NEON_ENCODE (INTEGER, inst); |
5ee91343 | 17344 | if (rs == NS_QQR) |
a8465a06 | 17345 | mve_encode_qqr (et.size, et.type == ubit_meaning, 0); |
5ee91343 AV |
17346 | else |
17347 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); | |
5287ad62 JB |
17348 | } |
17349 | } | |
17350 | ||
5287ad62 JB |
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. */ | |
dcbf9037 | 17357 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
17358 | } |
17359 | ||
5287ad62 JB |
17360 | static void |
17361 | do_neon_dyadic_if_i_d (void) | |
17362 | { | |
428e3f1f PB |
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); | |
5287ad62 JB |
17366 | } |
17367 | ||
f5f10c66 AV |
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; | |
e449ea97 | 17409 | unsigned type = inst.vectype.el[0].type; |
f5f10c66 AV |
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")); | |
e449ea97 SP |
17440 | constraint (size == elsize && type == NT_signed, BAD_EL_TYPE); |
17441 | constraint (size != elsize && type != NT_unsigned && type != NT_signed, | |
f5f10c66 | 17442 | BAD_EL_TYPE); |
e449ea97 | 17443 | inst.instruction |= ((size == elsize) || (type == NT_unsigned)) << 28; |
f5f10c66 AV |
17444 | } |
17445 | else | |
17446 | { | |
e449ea97 | 17447 | constraint (type != NT_untyped, BAD_EL_TYPE); |
f5f10c66 AV |
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 | ||
35c228db AV |
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 | ||
26c1e780 AV |
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 | ||
5287ad62 | 17671 | static void |
5ee91343 | 17672 | do_neon_dyadic_if_su (void) |
5287ad62 | 17673 | { |
5ee91343 AV |
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 | ||
935295b5 AV |
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 | ||
64c350f2 AV |
17683 | if (!check_simd_pred_availability (et.type == NT_float, |
17684 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
037e8744 JB |
17685 | return; |
17686 | ||
5ee91343 AV |
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) | |
037e8744 JB |
17695 | return; |
17696 | ||
5ee91343 AV |
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 | { | |
64c350f2 AV |
17708 | if (!check_simd_pred_availability (et.type == NT_float, |
17709 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
5ee91343 AV |
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 | ||
5287ad62 JB |
17720 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
17721 | affected if we specify unsigned args. */ | |
dcbf9037 | 17722 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
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 | { | |
5287ad62 JB |
17737 | if (inst.operands[1].present) |
17738 | { | |
e1fa0163 NC |
17739 | void *scratch = xmalloc (sizeof (inst.operands[0])); |
17740 | ||
5287ad62 JB |
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])); | |
e1fa0163 | 17745 | free (scratch); |
5287ad62 JB |
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) | |
477330fc | 17760 | neon_exchange_operands (); |
dcbf9037 | 17761 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
17762 | } |
17763 | else | |
17764 | { | |
037e8744 | 17765 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 | 17766 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 17767 | N_EQK | N_SIZ, immtypes | N_KEY); |
5287ad62 | 17768 | |
88714cb8 | 17769 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
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; | |
037e8744 | 17774 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
17775 | inst.instruction |= (et.type == NT_float) << 10; |
17776 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 17777 | |
88714cb8 | 17778 | neon_dp_fixup (&inst); |
5287ad62 JB |
17779 | } |
17780 | } | |
17781 | ||
17782 | static void | |
17783 | do_neon_cmp (void) | |
17784 | { | |
5b7c81bd | 17785 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, false); |
5287ad62 JB |
17786 | } |
17787 | ||
17788 | static void | |
17789 | do_neon_cmp_inv (void) | |
17790 | { | |
5b7c81bd | 17791 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, true); |
5287ad62 JB |
17792 | } |
17793 | ||
17794 | static void | |
17795 | do_neon_ceq (void) | |
17796 | { | |
5b7c81bd | 17797 | neon_compare (N_IF_32, N_IF_32, false); |
5287ad62 JB |
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 | |
c604a79a JW |
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. */ | |
5287ad62 JB |
17812 | |
17813 | static unsigned | |
17814 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
17815 | { | |
dcbf9037 JB |
17816 | unsigned regno = NEON_SCALAR_REG (scalar); |
17817 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
17818 | |
17819 | switch (elsize) | |
17820 | { | |
17821 | case 16: | |
17822 | if (regno > 7 || elno > 3) | |
477330fc | 17823 | goto bad_scalar; |
5287ad62 | 17824 | return regno | (elno << 3); |
5f4273c7 | 17825 | |
5287ad62 JB |
17826 | case 32: |
17827 | if (regno > 15 || elno > 1) | |
477330fc | 17828 | goto bad_scalar; |
5287ad62 JB |
17829 | return regno | (elno << 4); |
17830 | ||
17831 | default: | |
17832 | bad_scalar: | |
dcbf9037 | 17833 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
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 | { | |
dcbf9037 JB |
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; | |
5f4273c7 | 17849 | |
dcbf9037 | 17850 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
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 | ||
88714cb8 | 17861 | neon_dp_fixup (&inst); |
5287ad62 JB |
17862 | } |
17863 | ||
17864 | static void | |
17865 | do_neon_mac_maybe_scalar (void) | |
17866 | { | |
037e8744 JB |
17867 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
17868 | return; | |
17869 | ||
5b7c81bd | 17870 | if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
037e8744 JB |
17871 | return; |
17872 | ||
5287ad62 JB |
17873 | if (inst.operands[2].isscalar) |
17874 | { | |
a8465a06 | 17875 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); |
037e8744 | 17876 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 17877 | struct neon_type_el et = neon_check_type (3, rs, |
589a7d88 | 17878 | N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY); |
88714cb8 | 17879 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 17880 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 | 17881 | } |
a8465a06 AV |
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 | } | |
5287ad62 | 17891 | else |
428e3f1f | 17892 | { |
a8465a06 | 17893 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); |
428e3f1f PB |
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 | } | |
5287ad62 JB |
17898 | } |
17899 | ||
aab2c27d MM |
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); | |
1db66fb6 JB |
17920 | int idx = inst.operands[2].reg & 0xf; |
17921 | constraint (!(idx < 4), _("index must be in the range 0 to 3")); | |
aab2c27d MM |
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); | |
1db66fb6 JB |
17926 | inst.instruction |= ((idx & 1) << 3); |
17927 | inst.instruction |= ((idx & 2) << 4); | |
aab2c27d MM |
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 | ||
62f3b8c8 PB |
17938 | static void |
17939 | do_neon_fmac (void) | |
17940 | { | |
d58196e0 AV |
17941 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma) |
17942 | && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
62f3b8c8 PB |
17943 | return; |
17944 | ||
5b7c81bd | 17945 | if (!check_simd_pred_availability (true, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
62f3b8c8 PB |
17946 | return; |
17947 | ||
d58196e0 AV |
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 | { | |
aab2c27d | 17956 | |
d58196e0 AV |
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 | ||
62f3b8c8 PB |
17978 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); |
17979 | } | |
17980 | ||
aab2c27d MM |
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 | ||
5287ad62 JB |
17999 | static void |
18000 | do_neon_tst (void) | |
18001 | { | |
037e8744 | 18002 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
18003 | struct neon_type_el et = neon_check_type (3, rs, |
18004 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 18005 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
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 | { | |
037e8744 JB |
18015 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
18016 | return; | |
18017 | ||
5b7c81bd | 18018 | if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
037e8744 JB |
18019 | return; |
18020 | ||
5287ad62 | 18021 | if (inst.operands[2].isscalar) |
a8465a06 AV |
18022 | { |
18023 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); | |
18024 | do_neon_mac_maybe_scalar (); | |
18025 | } | |
5287ad62 | 18026 | else |
a8465a06 AV |
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 | } | |
5287ad62 JB |
18046 | } |
18047 | ||
18048 | static void | |
18049 | do_neon_qdmulh (void) | |
18050 | { | |
5b7c81bd | 18051 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
42b16635 AV |
18052 | return; |
18053 | ||
5287ad62 JB |
18054 | if (inst.operands[2].isscalar) |
18055 | { | |
42b16635 | 18056 | constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU); |
037e8744 | 18057 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 18058 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 18059 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 18060 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 18061 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
18062 | } |
18063 | else | |
18064 | { | |
42b16635 AV |
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 | ||
88714cb8 | 18080 | NEON_ENCODE (INTEGER, inst); |
42b16635 AV |
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); | |
5287ad62 JB |
18086 | } |
18087 | } | |
18088 | ||
26c1e780 AV |
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 | ||
7df54120 AV |
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 | ||
35d1cfc2 AV |
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 | ||
c2dafc2a AV |
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 | ||
7df54120 | 18192 | mve_encode_qqr (et.size, 0, 0); |
c2dafc2a AV |
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 | ||
2d78f95b AV |
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 | ||
42b16635 AV |
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 | |
23d188c7 | 18228 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY); |
42b16635 AV |
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 | } | |
8b8b22a4 AV |
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 | ||
8b8b22a4 AV |
18250 | mve_encode_qqq (0, et.size); |
18251 | } | |
18252 | ||
18253 | ||
886e1c73 AV |
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); | |
fe05f369 | 18260 | if (inst.cond == COND_ALWAYS |
886e1c73 AV |
18261 | && ((unsigned)inst.instruction) == M_MNEM_vmullt) |
18262 | { | |
fe05f369 | 18263 | |
886e1c73 AV |
18264 | if (rs == NS_QQQ) |
18265 | { | |
fe05f369 | 18266 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) |
886e1c73 AV |
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 | ||
dc1e8a47 | 18295 | neon_vmul: |
886e1c73 AV |
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 | ||
a302e574 AV |
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 | ||
93925576 AV |
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 | ||
8cd78170 AV |
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 | ||
13ccd4c0 AV |
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 | ||
643afb90 MW |
18474 | static void |
18475 | do_neon_qrdmlah (void) | |
18476 | { | |
5b7c81bd | 18477 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
42b16635 AV |
18478 | return; |
18479 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
643afb90 | 18480 | { |
42b16635 AV |
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 | } | |
643afb90 MW |
18507 | } |
18508 | else | |
18509 | { | |
42b16635 AV |
18510 | enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL); |
18511 | struct neon_type_el et | |
23d188c7 | 18512 | = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY); |
42b16635 | 18513 | |
643afb90 | 18514 | NEON_ENCODE (INTEGER, inst); |
42b16635 | 18515 | mve_encode_qqr (et.size, et.type == NT_unsigned, 0); |
643afb90 MW |
18516 | } |
18517 | } | |
18518 | ||
5287ad62 JB |
18519 | static void |
18520 | do_neon_fcmp_absolute (void) | |
18521 | { | |
037e8744 | 18522 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
18523 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
18524 | N_F_16_32 | N_KEY); | |
5287ad62 | 18525 | /* Size field comes from bit mask. */ |
cc933301 | 18526 | neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
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 | { | |
037e8744 | 18539 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
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); | |
5287ad62 JB |
18543 | } |
18544 | ||
18545 | static void | |
18546 | do_neon_abs_neg (void) | |
18547 | { | |
037e8744 JB |
18548 | enum neon_shape rs; |
18549 | struct neon_type_el et; | |
5f4273c7 | 18550 | |
037e8744 JB |
18551 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
18552 | return; | |
18553 | ||
037e8744 | 18554 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
cc933301 | 18555 | et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY); |
5f4273c7 | 18556 | |
64c350f2 AV |
18557 | if (!check_simd_pred_availability (et.type == NT_float, |
18558 | NEON_CHECK_ARCH | NEON_CHECK_CC)) | |
485dee97 AV |
18559 | return; |
18560 | ||
5287ad62 JB |
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; | |
037e8744 | 18565 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
18566 | inst.instruction |= (et.type == NT_float) << 10; |
18567 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 18568 | |
88714cb8 | 18569 | neon_dp_fixup (&inst); |
5287ad62 JB |
18570 | } |
18571 | ||
18572 | static void | |
18573 | do_neon_sli (void) | |
18574 | { | |
5b7c81bd | 18575 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
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 | ||
5287ad62 JB |
18592 | int imm = inst.operands[2].imm; |
18593 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 18594 | _("immediate out of range for insert")); |
5b7c81bd | 18595 | neon_imm_shift (false, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
18596 | } |
18597 | ||
18598 | static void | |
18599 | do_neon_sri (void) | |
18600 | { | |
5b7c81bd | 18601 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
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 | ||
5287ad62 JB |
18617 | int imm = inst.operands[2].imm; |
18618 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 18619 | _("immediate out of range for insert")); |
5b7c81bd | 18620 | neon_imm_shift (false, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
18621 | } |
18622 | ||
18623 | static void | |
18624 | do_neon_qshlu_imm (void) | |
18625 | { | |
5b7c81bd | 18626 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
5150f0d8 AV |
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 | ||
5287ad62 JB |
18643 | int imm = inst.operands[2].imm; |
18644 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 18645 | _("immediate out of range for shift")); |
5287ad62 JB |
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. */ | |
5b7c81bd | 18651 | neon_imm_shift (false, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
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. */ | |
88714cb8 | 18661 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
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. */ | |
88714cb8 | 18675 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
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; | |
5f4273c7 | 18690 | |
5287ad62 JB |
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 | } | |
5f4273c7 | 18700 | |
5287ad62 | 18701 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 18702 | _("immediate out of range")); |
5b7c81bd | 18703 | neon_imm_shift (true, et.type == NT_unsigned, 0, et, et.size - imm); |
5287ad62 JB |
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, | |
477330fc | 18729 | _("immediate out of range")); |
5287ad62 JB |
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. */ | |
5b7c81bd | 18733 | neon_imm_shift (true, 1, 0, et, et.size - imm); |
5287ad62 JB |
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); | |
88714cb8 | 18741 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
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; | |
5f4273c7 | 18754 | |
5287ad62 JB |
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 | } | |
5f4273c7 | 18764 | |
5287ad62 | 18765 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 18766 | _("immediate out of range for narrowing operation")); |
5b7c81bd | 18767 | neon_imm_shift (false, 0, 0, et, et.size - imm); |
5287ad62 JB |
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. */ | |
88714cb8 | 18781 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
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; | |
5f4273c7 | 18787 | |
88714cb8 | 18788 | neon_dp_fixup (&inst); |
5287ad62 JB |
18789 | } |
18790 | else | |
18791 | { | |
18792 | /* A more-specific type check for non-max versions. */ | |
18793 | et = neon_check_type (2, NS_QDI, | |
477330fc | 18794 | N_EQK | N_DBL, N_SU_32 | N_KEY); |
88714cb8 | 18795 | NEON_ENCODE (IMMED, inst); |
5b7c81bd | 18796 | neon_imm_shift (true, et.type == NT_unsigned, 0, et, imm); |
5287ad62 JB |
18797 | } |
18798 | } | |
18799 | ||
037e8744 | 18800 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
18801 | the current instruction is. */ |
18802 | ||
6b9a8b67 MGD |
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. */ \ | |
cc933301 JW |
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) \ | |
6b9a8b67 MGD |
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) \ | |
9db2f6b4 RL |
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")\ | |
aab2c27d | 18822 | CVT_VAR (bf16_f32, N_BF16, N_F32, whole_reg, NULL, NULL, NULL) \ |
6b9a8b67 MGD |
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) | |
5287ad62 | 18855 | { |
6b9a8b67 MGD |
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); \ | |
5287ad62 | 18862 | } |
6b9a8b67 | 18863 | |
5287ad62 | 18864 | struct neon_type_el et; |
037e8744 | 18865 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
477330fc | 18866 | || rs == NS_FF) ? N_VFP : 0; |
037e8744 JB |
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; | |
5f4273c7 | 18872 | |
6b9a8b67 MGD |
18873 | CVT_FLAVOUR_VAR; |
18874 | ||
18875 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
18876 | #undef CVT_VAR |
18877 | } | |
18878 | ||
7e8e6784 MGD |
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, | |
30bdf752 MGD |
18886 | neon_cvt_mode_x, |
18887 | neon_cvt_mode_r | |
7e8e6784 MGD |
18888 | }; |
18889 | ||
037e8744 JB |
18890 | /* Neon-syntax VFP conversions. */ |
18891 | ||
5287ad62 | 18892 | static void |
6b9a8b67 | 18893 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 18894 | { |
037e8744 | 18895 | const char *opname = 0; |
5f4273c7 | 18896 | |
d54af2d0 RL |
18897 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI |
18898 | || rs == NS_FHI || rs == NS_HFI) | |
5287ad62 | 18899 | { |
037e8744 JB |
18900 | /* Conversions with immediate bitshift. */ |
18901 | const char *enc[] = | |
477330fc | 18902 | { |
6b9a8b67 MGD |
18903 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
18904 | CVT_FLAVOUR_VAR | |
18905 | NULL | |
18906 | #undef CVT_VAR | |
477330fc | 18907 | }; |
037e8744 | 18908 | |
6b9a8b67 | 18909 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc RM |
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 | } | |
5287ad62 JB |
18917 | } |
18918 | else | |
18919 | { | |
037e8744 JB |
18920 | /* Conversions without bitshift. */ |
18921 | const char *enc[] = | |
477330fc | 18922 | { |
6b9a8b67 MGD |
18923 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
18924 | CVT_FLAVOUR_VAR | |
18925 | NULL | |
18926 | #undef CVT_VAR | |
477330fc | 18927 | }; |
037e8744 | 18928 | |
6b9a8b67 | 18929 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc | 18930 | opname = enc[flavour]; |
037e8744 JB |
18931 | } |
18932 | ||
18933 | if (opname) | |
18934 | do_vfp_nsyn_opcode (opname); | |
9db2f6b4 RL |
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 (); | |
037e8744 JB |
18942 | } |
18943 | ||
18944 | static void | |
18945 | do_vfp_nsyn_cvtz (void) | |
18946 | { | |
d54af2d0 | 18947 | enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL); |
6b9a8b67 | 18948 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
18949 | const char *enc[] = |
18950 | { | |
6b9a8b67 MGD |
18951 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
18952 | CVT_FLAVOUR_VAR | |
18953 | NULL | |
18954 | #undef CVT_VAR | |
037e8744 JB |
18955 | }; |
18956 | ||
6b9a8b67 | 18957 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
18958 | do_vfp_nsyn_opcode (enc[flavour]); |
18959 | } | |
f31fef98 | 18960 | |
037e8744 | 18961 | static void |
bacebabc | 18962 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
18963 | enum neon_cvt_mode mode) |
18964 | { | |
18965 | int sz, op; | |
18966 | int rm; | |
18967 | ||
a715796b TG |
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 | ||
9db2f6b4 RL |
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 | ||
5ee91343 | 18980 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
7e8e6784 MGD |
18981 | |
18982 | switch (flavour) | |
18983 | { | |
18984 | case neon_cvt_flavour_s32_f64: | |
18985 | sz = 1; | |
827f64ff | 18986 | op = 1; |
7e8e6784 MGD |
18987 | break; |
18988 | case neon_cvt_flavour_s32_f32: | |
18989 | sz = 0; | |
18990 | op = 1; | |
18991 | break; | |
9db2f6b4 RL |
18992 | case neon_cvt_flavour_s32_f16: |
18993 | sz = 0; | |
18994 | op = 1; | |
18995 | break; | |
7e8e6784 MGD |
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; | |
9db2f6b4 RL |
19004 | case neon_cvt_flavour_u32_f16: |
19005 | sz = 0; | |
19006 | op = 0; | |
19007 | break; | |
7e8e6784 MGD |
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; | |
9db2f6b4 RL |
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 (); | |
7e8e6784 MGD |
19031 | inst.instruction |= op << 7; |
19032 | inst.instruction |= rm << 16; | |
19033 | inst.instruction |= 0xf0000000; | |
5b7c81bd | 19034 | inst.is_neon = true; |
7e8e6784 MGD |
19035 | } |
19036 | ||
19037 | static void | |
19038 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
19039 | { |
19040 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
d54af2d0 RL |
19041 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, |
19042 | NS_FH, NS_HF, NS_FHI, NS_HFI, | |
19043 | NS_NULL); | |
6b9a8b67 | 19044 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 19045 | |
cc933301 JW |
19046 | if (flavour == neon_cvt_flavour_invalid) |
19047 | return; | |
19048 | ||
e3e535bc | 19049 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 19050 | if (mode == neon_cvt_mode_z |
e3e535bc | 19051 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
cc933301 JW |
19052 | && (flavour == neon_cvt_flavour_s16_f16 |
19053 | || flavour == neon_cvt_flavour_u16_f16 | |
19054 | || flavour == neon_cvt_flavour_s32_f32 | |
bacebabc RM |
19055 | || flavour == neon_cvt_flavour_u32_f32 |
19056 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 19057 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
19058 | && (rs == NS_FD || rs == NS_FF)) |
19059 | { | |
19060 | do_vfp_nsyn_cvtz (); | |
19061 | return; | |
19062 | } | |
19063 | ||
9db2f6b4 RL |
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 | ||
225f1684 JR |
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 | ||
037e8744 | 19086 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 19087 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 19088 | { |
7e8e6784 MGD |
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 | ||
037e8744 JB |
19094 | return; |
19095 | } | |
19096 | ||
19097 | switch (rs) | |
19098 | { | |
037e8744 | 19099 | case NS_QQI: |
dd9634d9 AV |
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 | { | |
5b7c81bd | 19110 | if (!check_simd_pred_availability (true, |
64c350f2 | 19111 | NEON_CHECK_CC | NEON_CHECK_ARCH)) |
dd9634d9 AV |
19112 | return; |
19113 | } | |
dd9634d9 AV |
19114 | /* fall through. */ |
19115 | case NS_DDI: | |
037e8744 | 19116 | { |
477330fc | 19117 | unsigned immbits; |
cc933301 JW |
19118 | unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000, |
19119 | 0x0000100, 0x1000100, 0x0, 0x1000000}; | |
35997600 | 19120 | |
dd9634d9 AV |
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 | } | |
037e8744 | 19150 | |
477330fc RM |
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; | |
477330fc RM |
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; | |
cc933301 JW |
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 | } | |
477330fc RM |
19177 | |
19178 | neon_dp_fixup (&inst); | |
037e8744 JB |
19179 | } |
19180 | break; | |
19181 | ||
037e8744 | 19182 | case NS_QQ: |
dd9634d9 AV |
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 | { | |
5b7c81bd | 19190 | if (!check_simd_pred_availability (true, |
64c350f2 | 19191 | NEON_CHECK_CC | NEON_CHECK_ARCH8)) |
dd9634d9 AV |
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 | { | |
5b7c81bd | 19204 | if (!check_simd_pred_availability (true, |
64c350f2 | 19205 | NEON_CHECK_CC | NEON_CHECK_ARCH)) |
dd9634d9 AV |
19206 | return; |
19207 | } | |
19208 | /* fall through. */ | |
19209 | case NS_DD: | |
7e8e6784 MGD |
19210 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
19211 | { | |
7e8e6784 | 19212 | |
dd9634d9 | 19213 | NEON_ENCODE (FLOAT, inst); |
5b7c81bd | 19214 | if (!check_simd_pred_availability (true, |
64c350f2 | 19215 | NEON_CHECK_CC | NEON_CHECK_ARCH8)) |
7e8e6784 MGD |
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; | |
cc933301 JW |
19223 | inst.instruction |= (flavour == neon_cvt_flavour_u16_f16 |
19224 | || flavour == neon_cvt_flavour_u32_f32) << 7; | |
7e8e6784 | 19225 | inst.instruction |= mode << 8; |
cc933301 JW |
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 | ||
7e8e6784 MGD |
19231 | if (thumb_mode) |
19232 | inst.instruction |= 0xfc000000; | |
19233 | else | |
19234 | inst.instruction |= 0xf0000000; | |
19235 | } | |
19236 | else | |
19237 | { | |
037e8744 | 19238 | int_encode: |
7e8e6784 | 19239 | { |
cc933301 JW |
19240 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080, |
19241 | 0x100, 0x180, 0x0, 0x080}; | |
037e8744 | 19242 | |
7e8e6784 | 19243 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 19244 | |
dd9634d9 AV |
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 | } | |
037e8744 | 19250 | |
7e8e6784 MGD |
19251 | if (flavour != neon_cvt_flavour_invalid) |
19252 | inst.instruction |= enctab[flavour]; | |
037e8744 | 19253 | |
7e8e6784 MGD |
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; | |
cc933301 JW |
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; | |
037e8744 | 19265 | |
7e8e6784 MGD |
19266 | neon_dp_fixup (&inst); |
19267 | } | |
19268 | } | |
19269 | break; | |
037e8744 | 19270 | |
8e79c3df CM |
19271 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
19272 | case NS_QD: | |
19273 | case NS_DQ: | |
bc52d49c MM |
19274 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
19275 | return; | |
8e79c3df CM |
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) | |
aab2c27d MM |
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 | } | |
8e79c3df | 19305 | else |
aab2c27d | 19306 | /* VCVT.f32.f16. */ |
8e79c3df CM |
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; | |
88714cb8 | 19313 | neon_dp_fixup (&inst); |
8e79c3df CM |
19314 | break; |
19315 | ||
037e8744 JB |
19316 | default: |
19317 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
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); | |
5287ad62 | 19322 | } |
5287ad62 JB |
19323 | } |
19324 | ||
e3e535bc NC |
19325 | static void |
19326 | do_neon_cvtr (void) | |
19327 | { | |
7e8e6784 | 19328 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
19329 | } |
19330 | ||
19331 | static void | |
19332 | do_neon_cvt (void) | |
19333 | { | |
7e8e6784 MGD |
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); | |
e3e535bc NC |
19359 | } |
19360 | ||
8e79c3df | 19361 | static void |
5b7c81bd | 19362 | do_neon_cvttb_2 (bool t, bool to, bool is_double) |
8e79c3df | 19363 | { |
c70a8987 MGD |
19364 | if (is_double) |
19365 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 19366 | |
c70a8987 MGD |
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 | } | |
8e79c3df | 19376 | |
c70a8987 | 19377 | static void |
5b7c81bd | 19378 | do_neon_cvttb_1 (bool t) |
c70a8987 | 19379 | { |
d54af2d0 | 19380 | enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD, |
dd9634d9 | 19381 | NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL); |
8e79c3df | 19382 | |
c70a8987 MGD |
19383 | if (rs == NS_NULL) |
19384 | return; | |
dd9634d9 AV |
19385 | else if (rs == NS_QQ || rs == NS_QQI) |
19386 | { | |
19387 | int single_to_half = 0; | |
5b7c81bd | 19388 | if (!check_simd_pred_availability (true, NEON_CHECK_ARCH)) |
dd9634d9 AV |
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 | } | |
c70a8987 MGD |
19426 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) |
19427 | { | |
19428 | inst.error = NULL; | |
5b7c81bd | 19429 | do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/false); |
c70a8987 MGD |
19430 | } |
19431 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
19432 | { | |
19433 | inst.error = NULL; | |
5b7c81bd | 19434 | do_neon_cvttb_2 (t, /*to=*/false, /*is_double=*/false); |
c70a8987 MGD |
19435 | } |
19436 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
19437 | { | |
a715796b TG |
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 | ||
c70a8987 | 19443 | inst.error = NULL; |
5b7c81bd | 19444 | do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/true); |
c70a8987 MGD |
19445 | } |
19446 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
19447 | { | |
a715796b TG |
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 | ||
c70a8987 | 19453 | inst.error = NULL; |
5b7c81bd | 19454 | do_neon_cvttb_2 (t, /*to=*/false, /*is_double=*/true); |
c70a8987 | 19455 | } |
aab2c27d MM |
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); | |
5b7c81bd | 19462 | do_neon_cvttb_2 (t, /*to=*/true, /*is_double=*/false); |
aab2c27d | 19463 | } |
c70a8987 MGD |
19464 | else |
19465 | return; | |
19466 | } | |
19467 | ||
19468 | static void | |
19469 | do_neon_cvtb (void) | |
19470 | { | |
5b7c81bd | 19471 | do_neon_cvttb_1 (false); |
8e79c3df CM |
19472 | } |
19473 | ||
19474 | ||
19475 | static void | |
19476 | do_neon_cvtt (void) | |
19477 | { | |
5b7c81bd | 19478 | do_neon_cvttb_1 (true); |
8e79c3df CM |
19479 | } |
19480 | ||
5287ad62 JB |
19481 | static void |
19482 | neon_move_immediate (void) | |
19483 | { | |
037e8744 JB |
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); | |
5287ad62 | 19487 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 19488 | int op, cmode, float_p; |
5287ad62 | 19489 | |
037e8744 | 19490 | constraint (et.type == NT_invtype, |
477330fc | 19491 | _("operand size must be specified for immediate VMOV")); |
037e8744 | 19492 | |
5287ad62 JB |
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, | |
477330fc | 19501 | _("immediate has bits set outside the operand size")); |
5287ad62 | 19502 | |
c96612cc JB |
19503 | float_p = inst.operands[1].immisfloat; |
19504 | ||
19505 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
477330fc | 19506 | et.size, et.type)) == FAIL) |
5287ad62 JB |
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 | |
477330fc RM |
19511 | with one or the other; those cases are caught by |
19512 | neon_cmode_for_move_imm. */ | |
5287ad62 | 19513 | op = !op; |
c96612cc JB |
19514 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
19515 | &op, et.size, et.type)) == FAIL) | |
477330fc RM |
19516 | { |
19517 | first_error (_("immediate out of range")); | |
19518 | return; | |
19519 | } | |
5287ad62 JB |
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; | |
037e8744 | 19527 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
19528 | inst.instruction |= cmode << 8; |
19529 | ||
19530 | neon_write_immbits (immbits); | |
19531 | } | |
19532 | ||
19533 | static void | |
19534 | do_neon_mvn (void) | |
19535 | { | |
5b7c81bd | 19536 | if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
1a186d29 AV |
19537 | return; |
19538 | ||
5287ad62 JB |
19539 | if (inst.operands[1].isreg) |
19540 | { | |
1a186d29 AV |
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); | |
5f4273c7 | 19546 | |
250dd99f AM |
19547 | if (rs == NS_NULL) |
19548 | return; | |
19549 | ||
88714cb8 | 19550 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
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; | |
037e8744 | 19555 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
19556 | } |
19557 | else | |
19558 | { | |
88714cb8 | 19559 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
19560 | neon_move_immediate (); |
19561 | } | |
19562 | ||
88714cb8 | 19563 | neon_dp_fixup (&inst); |
1a186d29 AV |
19564 | |
19565 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
19566 | { | |
19567 | constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU); | |
1a186d29 | 19568 | } |
5287ad62 JB |
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| | |
5f4273c7 | 19574 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
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; | |
5f4273c7 | 19587 | |
88714cb8 | 19588 | neon_dp_fixup (&inst); |
5287ad62 JB |
19589 | } |
19590 | ||
19591 | static void | |
19592 | do_neon_dyadic_long (void) | |
19593 | { | |
66d1f7cc | 19594 | enum neon_shape rs = neon_select_shape (NS_QDD, NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
5ee91343 AV |
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); | |
5287ad62 JB |
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 | { | |
dcbf9037 | 19652 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
477330fc | 19653 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); |
88714cb8 | 19654 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
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, | |
477330fc | 19660 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); |
88714cb8 | 19661 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
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 | ||
dec41383 JW |
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 | ||
dc1e8a47 | 19700 | bad_scalar: |
dec41383 JW |
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 | ||
dec41383 JW |
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 | ||
aab2c27d MM |
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)); | |
dec41383 JW |
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 | ||
dec41383 JW |
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 | ||
5287ad62 JB |
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); | |
428e3f1f PB |
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; | |
5287ad62 JB |
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, | |
477330fc | 19829 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
4f51b4bd | 19830 | |
5287ad62 | 19831 | if (et.type == NT_poly) |
477330fc | 19832 | NEON_ENCODE (POLY, inst); |
5287ad62 | 19833 | else |
477330fc | 19834 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
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 | ||
5287ad62 JB |
19849 | neon_mixed_length (et, et.size); |
19850 | } | |
19851 | } | |
19852 | ||
19853 | static void | |
19854 | do_neon_ext (void) | |
19855 | { | |
037e8744 | 19856 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
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; | |
35997600 NC |
19860 | |
19861 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
19862 | _("shift out of range")); | |
5287ad62 JB |
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; | |
037e8744 | 19869 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 19870 | inst.instruction |= imm << 8; |
5f4273c7 | 19871 | |
88714cb8 | 19872 | neon_dp_fixup (&inst); |
5287ad62 JB |
19873 | } |
19874 | ||
19875 | static void | |
19876 | do_neon_rev (void) | |
19877 | { | |
5b7c81bd | 19878 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
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 | ||
5287ad62 JB |
19887 | struct neon_type_el et = neon_check_type (2, rs, |
19888 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
4401c241 | 19889 | |
5287ad62 JB |
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; | |
4401c241 AV |
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 | ||
9c2799c2 | 19901 | gas_assert (elsize != 0); |
5287ad62 | 19902 | constraint (et.size >= elsize, |
477330fc | 19903 | _("elements must be smaller than reversal region")); |
037e8744 | 19904 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
19905 | } |
19906 | ||
19907 | static void | |
19908 | do_neon_dup (void) | |
19909 | { | |
19910 | if (inst.operands[1].isscalar) | |
19911 | { | |
b409bdb6 AV |
19912 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1), |
19913 | BAD_FPU); | |
037e8744 | 19914 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 | 19915 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 19916 | N_EQK, N_8 | N_16 | N_32 | N_KEY); |
5287ad62 | 19917 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 19918 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 19919 | int logsize = neon_logbits (et.size); |
dcbf9037 | 19920 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
19921 | |
19922 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
477330fc | 19923 | return; |
037e8744 | 19924 | |
88714cb8 | 19925 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
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; | |
037e8744 | 19930 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
19931 | inst.instruction |= x << 17; |
19932 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 19933 | |
88714cb8 | 19934 | neon_dp_fixup (&inst); |
5287ad62 JB |
19935 | } |
19936 | else | |
19937 | { | |
037e8744 JB |
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, | |
477330fc | 19940 | N_8 | N_16 | N_32 | N_KEY, N_EQK); |
b409bdb6 AV |
19941 | if (rs == NS_QR) |
19942 | { | |
5b7c81bd | 19943 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH)) |
b409bdb6 AV |
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 | ||
5287ad62 | 19958 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 19959 | NEON_ENCODE (ARMREG, inst); |
5287ad62 | 19960 | switch (et.size) |
477330fc RM |
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 | } | |
5287ad62 JB |
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; | |
037e8744 | 19970 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 | 19971 | /* The encoding for this instruction is identical for the ARM and Thumb |
477330fc | 19972 | variants, except for the condition field. */ |
037e8744 | 19973 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
19974 | } |
19975 | } | |
19976 | ||
57785aa2 AV |
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.")); | |
e683cb41 AC |
19997 | constraint (!toQ && inst.operands[Rt].reg == inst.operands[Rt2].reg, |
19998 | _("Destination registers may not be the same")); | |
57785aa2 AV |
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 | ||
5287ad62 JB |
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.) | |
037e8744 JB |
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.) | |
57785aa2 AV |
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> | |
5f4273c7 | 20071 | |
037e8744 JB |
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. | |
5f4273c7 | 20074 | |
5287ad62 | 20075 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 20076 | |
b7fc2769 JB |
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. | |
5f4273c7 | 20079 | |
5287ad62 | 20080 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 20081 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
20082 | |
20083 | static void | |
20084 | do_neon_mov (void) | |
20085 | { | |
57785aa2 AV |
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); | |
037e8744 JB |
20091 | struct neon_type_el et; |
20092 | const char *ldconst = 0; | |
5287ad62 | 20093 | |
037e8744 | 20094 | switch (rs) |
5287ad62 | 20095 | { |
037e8744 JB |
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; | |
1c1e0fe5 SP |
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))) | |
477330fc RM |
20107 | { |
20108 | do_vfp_nsyn_opcode ("fcpyd"); | |
20109 | break; | |
20110 | } | |
037e8744 | 20111 | /* fall through. */ |
5287ad62 | 20112 | |
037e8744 JB |
20113 | case NS_QQ: /* case 0/1. */ |
20114 | { | |
5b7c81bd | 20115 | if (!check_simd_pred_availability (false, |
64c350f2 | 20116 | NEON_CHECK_CC | NEON_CHECK_ARCH)) |
477330fc RM |
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); | |
037e8744 JB |
20131 | } |
20132 | break; | |
5f4273c7 | 20133 | |
037e8744 JB |
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) | |
477330fc RM |
20138 | { |
20139 | /* case 11 (fconstd). */ | |
20140 | ldconst = "fconstd"; | |
20141 | goto encode_fconstd; | |
20142 | } | |
037e8744 JB |
20143 | /* fall through. */ |
20144 | ||
20145 | case NS_QI: /* case 2/3. */ | |
5b7c81bd | 20146 | if (!check_simd_pred_availability (false, |
64c350f2 | 20147 | NEON_CHECK_CC | NEON_CHECK_ARCH)) |
477330fc | 20148 | return; |
037e8744 JB |
20149 | inst.instruction = 0x0800010; |
20150 | neon_move_immediate (); | |
88714cb8 | 20151 | neon_dp_fixup (&inst); |
5287ad62 | 20152 | break; |
5f4273c7 | 20153 | |
037e8744 JB |
20154 | case NS_SR: /* case 4. */ |
20155 | { | |
477330fc RM |
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); | |
037e8744 | 20160 | |
05ac0ffb JB |
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 | ||
477330fc RM |
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 | ||
57785aa2 AV |
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 | ||
477330fc | 20196 | constraint (et.type == NT_invtype, _("bad type for scalar")); |
57785aa2 AV |
20197 | constraint (x >= size / et.size, _("scalar index out of range")); |
20198 | ||
477330fc RM |
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 | ||
57785aa2 | 20208 | bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize; |
477330fc RM |
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; | |
57785aa2 AV |
20216 | inst.instruction |= ((bcdebits >> 2) & 3) << 21; |
20217 | inst.instruction |= (x >> (3-logsize)) << 16; | |
037e8744 JB |
20218 | } |
20219 | break; | |
5f4273c7 | 20220 | |
037e8744 | 20221 | case NS_DRR: /* case 5 (fmdrr). */ |
57785aa2 AV |
20222 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20223 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
477330fc | 20224 | _(BAD_FPU)); |
b7fc2769 | 20225 | |
037e8744 JB |
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; | |
5f4273c7 | 20233 | |
037e8744 JB |
20234 | case NS_RS: /* case 6. */ |
20235 | { | |
477330fc RM |
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; | |
037e8744 | 20240 | |
05ac0ffb JB |
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 | ||
91d6fa6a NC |
20251 | et = neon_check_type (2, NS_NULL, |
20252 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
477330fc RM |
20253 | logsize = neon_logbits (et.size); |
20254 | ||
57785aa2 AV |
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 | ||
477330fc | 20279 | constraint (et.type == NT_invtype, _("bad type for scalar")); |
57785aa2 | 20280 | constraint (x >= size / et.size, _("scalar index out of range")); |
477330fc RM |
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 | ||
57785aa2 | 20290 | abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize; |
477330fc RM |
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; | |
57785aa2 | 20298 | inst.instruction |= (x >> (3-logsize)) << 16; |
037e8744 JB |
20299 | } |
20300 | break; | |
5f4273c7 | 20301 | |
037e8744 | 20302 | case NS_RRD: /* case 7 (fmrrd). */ |
57785aa2 AV |
20303 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20304 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
477330fc | 20305 | _(BAD_FPU)); |
037e8744 JB |
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; | |
5f4273c7 | 20314 | |
037e8744 JB |
20315 | case NS_FF: /* case 8 (fcpys). */ |
20316 | do_vfp_nsyn_opcode ("fcpys"); | |
20317 | break; | |
5f4273c7 | 20318 | |
9db2f6b4 | 20319 | case NS_HI: |
037e8744 JB |
20320 | case NS_FI: /* case 10 (fconsts). */ |
20321 | ldconst = "fconsts"; | |
4ef4710f | 20322 | encode_fconstd: |
58ed5c38 TC |
20323 | if (!inst.operands[1].immisfloat) |
20324 | { | |
4ef4710f | 20325 | unsigned new_imm; |
58ed5c38 | 20326 | /* Immediate has to fit in 8 bits so float is enough. */ |
4ef4710f NC |
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 | } | |
58ed5c38 TC |
20340 | } |
20341 | ||
037e8744 | 20342 | if (is_quarter_float (inst.operands[1].imm)) |
477330fc RM |
20343 | { |
20344 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); | |
20345 | do_vfp_nsyn_opcode (ldconst); | |
9db2f6b4 RL |
20346 | |
20347 | /* ARMv8.2 fp16 vmov.f16 instruction. */ | |
20348 | if (rs == NS_HI) | |
20349 | do_scalar_fp16_v82_encode (); | |
477330fc | 20350 | } |
5287ad62 | 20351 | else |
477330fc | 20352 | first_error (_("immediate out of range")); |
037e8744 | 20353 | break; |
5f4273c7 | 20354 | |
9db2f6b4 | 20355 | case NS_RH: |
037e8744 JB |
20356 | case NS_RF: /* case 12 (fmrs). */ |
20357 | do_vfp_nsyn_opcode ("fmrs"); | |
9db2f6b4 RL |
20358 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
20359 | if (rs == NS_RH) | |
20360 | do_scalar_fp16_v82_encode (); | |
037e8744 | 20361 | break; |
5f4273c7 | 20362 | |
9db2f6b4 | 20363 | case NS_HR: |
037e8744 JB |
20364 | case NS_FR: /* case 13 (fmsr). */ |
20365 | do_vfp_nsyn_opcode ("fmsr"); | |
9db2f6b4 RL |
20366 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
20367 | if (rs == NS_HR) | |
20368 | do_scalar_fp16_v82_encode (); | |
037e8744 | 20369 | break; |
5f4273c7 | 20370 | |
57785aa2 AV |
20371 | case NS_RRSS: |
20372 | do_mve_mov (0); | |
20373 | break; | |
20374 | case NS_SSRR: | |
20375 | do_mve_mov (1); | |
20376 | break; | |
20377 | ||
037e8744 JB |
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). */ | |
57785aa2 AV |
20383 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20384 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
20385 | _(BAD_FPU)); | |
037e8744 | 20386 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, |
477330fc | 20387 | _("VFP registers must be adjacent")); |
037e8744 JB |
20388 | inst.operands[2].imm = 2; |
20389 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
20390 | do_vfp_nsyn_opcode ("fmrrs"); | |
20391 | break; | |
5f4273c7 | 20392 | |
037e8744 | 20393 | case NS_FFRR: /* case 15 (fmsrr). */ |
57785aa2 AV |
20394 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2) |
20395 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
20396 | _(BAD_FPU)); | |
037e8744 | 20397 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, |
477330fc | 20398 | _("VFP registers must be adjacent")); |
037e8744 JB |
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"); | |
5287ad62 | 20404 | break; |
5f4273c7 | 20405 | |
4c261dff NC |
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 | ||
5287ad62 JB |
20411 | default: |
20412 | abort (); | |
20413 | } | |
20414 | } | |
20415 | ||
57785aa2 AV |
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 | ||
5287ad62 JB |
20449 | static void |
20450 | do_neon_rshift_round_imm (void) | |
20451 | { | |
5b7c81bd | 20452 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
4401c241 AV |
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 | } | |
5287ad62 JB |
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, | |
477330fc | 20479 | _("immediate out of range for shift")); |
5b7c81bd | 20480 | neon_imm_shift (true, et.type == NT_unsigned, neon_quad (rs), et, |
477330fc | 20481 | et.size - imm); |
5287ad62 JB |
20482 | } |
20483 | ||
9db2f6b4 RL |
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 | ||
7bdf778b ASDV |
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 | ||
9db2f6b4 RL |
20504 | do_vfp_sp_monadic (); |
20505 | ||
20506 | inst.is_neon = 1; | |
20507 | inst.instruction |= 0xf0000000; | |
20508 | } | |
20509 | ||
5287ad62 JB |
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 | { | |
037e8744 | 20523 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
20524 | struct neon_type_el et = neon_check_type (2, rs, |
20525 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 20526 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 20527 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20528 | } |
20529 | ||
20530 | static void | |
20531 | do_neon_zip_uzp (void) | |
20532 | { | |
037e8744 | 20533 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
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 | } | |
037e8744 | 20543 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20544 | } |
20545 | ||
20546 | static void | |
20547 | do_neon_sat_abs_neg (void) | |
20548 | { | |
5b7c81bd | 20549 | if (!check_simd_pred_availability (false, NEON_CHECK_CC | NEON_CHECK_ARCH)) |
1a186d29 AV |
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); | |
5287ad62 JB |
20557 | struct neon_type_el et = neon_check_type (2, rs, |
20558 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 20559 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20560 | } |
20561 | ||
20562 | static void | |
20563 | do_neon_pair_long (void) | |
20564 | { | |
037e8744 | 20565 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
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; | |
037e8744 | 20569 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20570 | } |
20571 | ||
20572 | static void | |
20573 | do_neon_recip_est (void) | |
20574 | { | |
037e8744 | 20575 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 | 20576 | struct neon_type_el et = neon_check_type (2, rs, |
cc933301 | 20577 | N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY); |
5287ad62 | 20578 | inst.instruction |= (et.type == NT_float) << 8; |
037e8744 | 20579 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20580 | } |
20581 | ||
20582 | static void | |
20583 | do_neon_cls (void) | |
20584 | { | |
5b7c81bd | 20585 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
f30ee27c AV |
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 | ||
5287ad62 JB |
20594 | struct neon_type_el et = neon_check_type (2, rs, |
20595 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 20596 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20597 | } |
20598 | ||
20599 | static void | |
20600 | do_neon_clz (void) | |
20601 | { | |
5b7c81bd | 20602 | if (!check_simd_pred_availability (false, NEON_CHECK_ARCH | NEON_CHECK_CC)) |
f30ee27c AV |
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 | ||
5287ad62 JB |
20611 | struct neon_type_el et = neon_check_type (2, rs, |
20612 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 20613 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20614 | } |
20615 | ||
20616 | static void | |
20617 | do_neon_cnt (void) | |
20618 | { | |
037e8744 | 20619 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
20620 | struct neon_type_el et = neon_check_type (2, rs, |
20621 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 20622 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
20623 | } |
20624 | ||
20625 | static void | |
20626 | do_neon_swp (void) | |
20627 | { | |
037e8744 | 20628 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
250dd99f AM |
20629 | if (rs == NS_NULL) |
20630 | return; | |
037e8744 | 20631 | neon_two_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
20632 | } |
20633 | ||
20634 | static void | |
20635 | do_neon_tbl_tbx (void) | |
20636 | { | |
20637 | unsigned listlenbits; | |
dcbf9037 | 20638 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 20639 | |
5287ad62 JB |
20640 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
20641 | { | |
dcbf9037 | 20642 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
20643 | return; |
20644 | } | |
5f4273c7 | 20645 | |
5287ad62 JB |
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; | |
5f4273c7 | 20654 | |
88714cb8 | 20655 | neon_dp_fixup (&inst); |
5287ad62 JB |
20656 | } |
20657 | ||
20658 | static void | |
20659 | do_neon_ldm_stm (void) | |
20660 | { | |
ef8f595f MI |
20661 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd) |
20662 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), | |
20663 | _(BAD_FPU)); | |
5287ad62 JB |
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 | ||
037e8744 JB |
20668 | if (inst.operands[1].issingle) |
20669 | { | |
20670 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
20671 | return; | |
20672 | } | |
20673 | ||
5287ad62 | 20674 | constraint (is_dbmode && !inst.operands[0].writeback, |
477330fc | 20675 | _("writeback (!) must be used for VLDMDB and VSTMDB")); |
5287ad62 JB |
20676 | |
20677 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
477330fc RM |
20678 | _("register list must contain at least 1 and at most 16 " |
20679 | "registers")); | |
5287ad62 JB |
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; | |
5f4273c7 | 20687 | |
037e8744 | 20688 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
20689 | } |
20690 | ||
ef8f595f MI |
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 | ||
5287ad62 JB |
20734 | static void |
20735 | do_neon_ldr_str (void) | |
20736 | { | |
5287ad62 | 20737 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 20738 | |
6844b2c2 MGD |
20739 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
20740 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 20741 | if (!is_ldr |
6844b2c2 | 20742 | && inst.operands[1].reg == REG_PC |
ba86b375 | 20743 | && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode)) |
6844b2c2 | 20744 | { |
94dcf8bf | 20745 | if (thumb_mode) |
6844b2c2 | 20746 | inst.error = _("Use of PC here is UNPREDICTABLE"); |
94dcf8bf | 20747 | else if (warn_on_deprecated) |
5c3696f8 | 20748 | as_tsktsk (_("Use of PC here is deprecated")); |
6844b2c2 MGD |
20749 | } |
20750 | ||
037e8744 JB |
20751 | if (inst.operands[0].issingle) |
20752 | { | |
cd2f129f | 20753 | if (is_ldr) |
477330fc | 20754 | do_vfp_nsyn_opcode ("flds"); |
cd2f129f | 20755 | else |
477330fc | 20756 | do_vfp_nsyn_opcode ("fsts"); |
9db2f6b4 RL |
20757 | |
20758 | /* ARMv8.2 vldr.16/vstr.16 instruction. */ | |
20759 | if (inst.vectype.el[0].size == 16) | |
20760 | do_scalar_fp16_v82_encode (); | |
5287ad62 JB |
20761 | } |
20762 | else | |
5287ad62 | 20763 | { |
cd2f129f | 20764 | if (is_ldr) |
477330fc | 20765 | do_vfp_nsyn_opcode ("fldd"); |
5287ad62 | 20766 | else |
477330fc | 20767 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 20768 | } |
5287ad62 JB |
20769 | } |
20770 | ||
32c36c3c AV |
20771 | static void |
20772 | do_t_vldr_vstr_sysreg (void) | |
20773 | { | |
20774 | int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20; | |
5b7c81bd | 20775 | bool is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0); |
32c36c3c AV |
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; | |
5b7c81bd | 20793 | encode_arm_cp_address (1, true, false, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM); |
32c36c3c AV |
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 | { | |
5b7c81bd | 20801 | bool sysreg_op = !inst.operands[0].isreg; |
32c36c3c AV |
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 | { | |
ef8f595f MI |
20814 | if (!mark_feature_used (&fpu_vfp_ext_v1xd) |
20815 | && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) | |
32c36c3c AV |
20816 | as_bad (_("Instruction not permitted on this architecture")); |
20817 | do_neon_ldr_str (); | |
20818 | } | |
20819 | } | |
20820 | ||
5287ad62 JB |
20821 | /* "interleave" version also handles non-interleaving register VLD1/VST1 |
20822 | instructions. */ | |
20823 | ||
20824 | static void | |
20825 | do_neon_ld_st_interleave (void) | |
20826 | { | |
037e8744 | 20827 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
477330fc | 20828 | N_8 | N_16 | N_32 | N_64); |
5287ad62 JB |
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 | ||
dcbf9037 JB |
20845 | if (et.type == NT_invtype) |
20846 | return; | |
20847 | ||
5287ad62 JB |
20848 | if (inst.operands[1].immisalign) |
20849 | switch (inst.operands[1].imm >> 8) | |
20850 | { | |
20851 | case 64: alignbits = 1; break; | |
20852 | case 128: | |
477330fc | 20853 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
e23c0ad8 | 20854 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
477330fc RM |
20855 | goto bad_alignment; |
20856 | alignbits = 2; | |
20857 | break; | |
5287ad62 | 20858 | case 256: |
477330fc RM |
20859 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
20860 | goto bad_alignment; | |
20861 | alignbits = 3; | |
20862 | break; | |
5287ad62 JB |
20863 | default: |
20864 | bad_alignment: | |
477330fc RM |
20865 | first_error (_("bad alignment")); |
20866 | return; | |
5287ad62 JB |
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) | |
477330fc | 20878 | | (((inst.instruction >> 8) & 3) << 3); |
5287ad62 JB |
20879 | |
20880 | typebits = typetable[idx]; | |
5f4273c7 | 20881 | |
5287ad62 | 20882 | constraint (typebits == -1, _("bad list type for instruction")); |
1d50d57c | 20883 | constraint (((inst.instruction >> 8) & 3) && et.size == 64, |
35c228db | 20884 | BAD_EL_TYPE); |
5287ad62 JB |
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 | |
aa8a0863 | 20896 | neon_alignment_bit (int size, int align, int *do_alignment, ...) |
5287ad62 JB |
20897 | { |
20898 | va_list ap; | |
20899 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 20900 | |
5287ad62 JB |
20901 | if (!inst.operands[1].immisalign) |
20902 | { | |
aa8a0863 | 20903 | *do_alignment = 0; |
5287ad62 JB |
20904 | return SUCCESS; |
20905 | } | |
5f4273c7 | 20906 | |
aa8a0863 | 20907 | va_start (ap, do_alignment); |
5287ad62 JB |
20908 | |
20909 | do | |
20910 | { | |
20911 | thissize = va_arg (ap, int); | |
20912 | if (thissize == -1) | |
477330fc | 20913 | break; |
5287ad62 JB |
20914 | thisalign = va_arg (ap, int); |
20915 | ||
20916 | if (size == thissize && align == thisalign) | |
477330fc | 20917 | result = SUCCESS; |
5287ad62 JB |
20918 | } |
20919 | while (result != SUCCESS); | |
20920 | ||
20921 | va_end (ap); | |
20922 | ||
20923 | if (result == SUCCESS) | |
aa8a0863 | 20924 | *do_alignment = 1; |
5287ad62 | 20925 | else |
dcbf9037 | 20926 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 20927 | |
5287ad62 JB |
20928 | return result; |
20929 | } | |
20930 | ||
20931 | static void | |
20932 | do_neon_ld_st_lane (void) | |
20933 | { | |
037e8744 | 20934 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 20935 | int align_good, do_alignment = 0; |
5287ad62 JB |
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; | |
5f4273c7 | 20940 | |
dcbf9037 JB |
20941 | if (et.type == NT_invtype) |
20942 | return; | |
5f4273c7 | 20943 | |
5287ad62 | 20944 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
477330fc | 20945 | _("bad list length")); |
5287ad62 | 20946 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, |
477330fc | 20947 | _("scalar index out of range")); |
5287ad62 | 20948 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 |
477330fc RM |
20949 | && et.size == 8, |
20950 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 20951 | |
5287ad62 JB |
20952 | switch (n) |
20953 | { | |
20954 | case 0: /* VLD1 / VST1. */ | |
aa8a0863 | 20955 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16, |
477330fc | 20956 | 32, 32, -1); |
5287ad62 | 20957 | if (align_good == FAIL) |
477330fc | 20958 | return; |
aa8a0863 | 20959 | if (do_alignment) |
477330fc RM |
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 | } | |
5287ad62 JB |
20970 | break; |
20971 | ||
20972 | case 1: /* VLD2 / VST2. */ | |
aa8a0863 TS |
20973 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16, |
20974 | 16, 32, 32, 64, -1); | |
5287ad62 | 20975 | if (align_good == FAIL) |
477330fc | 20976 | return; |
aa8a0863 | 20977 | if (do_alignment) |
477330fc | 20978 | inst.instruction |= 1 << 4; |
5287ad62 JB |
20979 | break; |
20980 | ||
20981 | case 2: /* VLD3 / VST3. */ | |
20982 | constraint (inst.operands[1].immisalign, | |
477330fc | 20983 | _("can't use alignment with this instruction")); |
5287ad62 JB |
20984 | break; |
20985 | ||
20986 | case 3: /* VLD4 / VST4. */ | |
aa8a0863 | 20987 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc | 20988 | 16, 64, 32, 64, 32, 128, -1); |
5287ad62 | 20989 | if (align_good == FAIL) |
477330fc | 20990 | return; |
aa8a0863 | 20991 | if (do_alignment) |
477330fc RM |
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 | } | |
5287ad62 JB |
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); | |
5f4273c7 | 21011 | |
5287ad62 JB |
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 | { | |
037e8744 | 21021 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 21022 | int align_good, do_alignment = 0; |
5287ad62 | 21023 | |
dcbf9037 JB |
21024 | if (et.type == NT_invtype) |
21025 | return; | |
21026 | ||
5287ad62 JB |
21027 | switch ((inst.instruction >> 8) & 3) |
21028 | { | |
21029 | case 0: /* VLD1. */ | |
9c2799c2 | 21030 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 | 21031 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
aa8a0863 | 21032 | &do_alignment, 16, 16, 32, 32, -1); |
5287ad62 | 21033 | if (align_good == FAIL) |
477330fc | 21034 | return; |
5287ad62 | 21035 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) |
477330fc RM |
21036 | { |
21037 | case 1: break; | |
21038 | case 2: inst.instruction |= 1 << 5; break; | |
21039 | default: first_error (_("bad list length")); return; | |
21040 | } | |
5287ad62 JB |
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, | |
aa8a0863 TS |
21046 | &do_alignment, 8, 16, 16, 32, 32, 64, |
21047 | -1); | |
5287ad62 | 21048 | if (align_good == FAIL) |
477330fc | 21049 | return; |
5287ad62 | 21050 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, |
477330fc | 21051 | _("bad list length")); |
5287ad62 | 21052 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 21053 | inst.instruction |= 1 << 5; |
5287ad62 JB |
21054 | inst.instruction |= neon_logbits (et.size) << 6; |
21055 | break; | |
21056 | ||
21057 | case 2: /* VLD3. */ | |
21058 | constraint (inst.operands[1].immisalign, | |
477330fc | 21059 | _("can't use alignment with this instruction")); |
5287ad62 | 21060 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, |
477330fc | 21061 | _("bad list length")); |
5287ad62 | 21062 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 21063 | inst.instruction |= 1 << 5; |
5287ad62 JB |
21064 | inst.instruction |= neon_logbits (et.size) << 6; |
21065 | break; | |
21066 | ||
21067 | case 3: /* VLD4. */ | |
21068 | { | |
477330fc | 21069 | int align = inst.operands[1].imm >> 8; |
aa8a0863 | 21070 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc RM |
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; | |
5287ad62 JB |
21082 | } |
21083 | break; | |
21084 | ||
21085 | default: ; | |
21086 | } | |
21087 | ||
aa8a0863 | 21088 | inst.instruction |= do_alignment << 4; |
5287ad62 JB |
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 | { | |
b1a769ed DG |
21097 | if (inst.operands[1].isreg) |
21098 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
21099 | ||
5287ad62 JB |
21100 | switch (NEON_LANE (inst.operands[0].imm)) |
21101 | { | |
21102 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 21103 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
21104 | do_neon_ld_st_interleave (); |
21105 | break; | |
5f4273c7 | 21106 | |
5287ad62 | 21107 | case NEON_ALL_LANES: |
88714cb8 | 21108 | NEON_ENCODE (DUP, inst); |
2d51fb74 JB |
21109 | if (inst.instruction == N_INV) |
21110 | { | |
21111 | first_error ("only loads support such operands"); | |
21112 | break; | |
21113 | } | |
5287ad62 JB |
21114 | do_neon_ld_dup (); |
21115 | break; | |
5f4273c7 | 21116 | |
5287ad62 | 21117 | default: |
88714cb8 | 21118 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
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; | |
5f4273c7 | 21126 | |
5287ad62 JB |
21127 | if (inst.operands[1].postind) |
21128 | { | |
21129 | int postreg = inst.operands[1].imm & 0xf; | |
21130 | constraint (!inst.operands[1].immisreg, | |
477330fc | 21131 | _("post-index must be a register")); |
5287ad62 | 21132 | constraint (postreg == 0xd || postreg == 0xf, |
477330fc | 21133 | _("bad register for post-index")); |
5287ad62 JB |
21134 | inst.instruction |= postreg; |
21135 | } | |
4f2374c7 | 21136 | else |
5287ad62 | 21137 | { |
4f2374c7 | 21138 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); |
e2b0ab59 AV |
21139 | constraint (inst.relocs[0].exp.X_op != O_constant |
21140 | || inst.relocs[0].exp.X_add_number != 0, | |
4f2374c7 WN |
21141 | BAD_ADDR_MODE); |
21142 | ||
21143 | if (inst.operands[1].writeback) | |
21144 | { | |
21145 | inst.instruction |= 0xd; | |
21146 | } | |
21147 | else | |
21148 | inst.instruction |= 0xf; | |
5287ad62 | 21149 | } |
5f4273c7 | 21150 | |
5287ad62 JB |
21151 | if (thumb_mode) |
21152 | inst.instruction |= 0xf9000000; | |
21153 | else | |
21154 | inst.instruction |= 0xf4000000; | |
21155 | } | |
33399f07 MGD |
21156 | |
21157 | /* FP v8. */ | |
21158 | static void | |
21159 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
21160 | { | |
a715796b TG |
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 | ||
33399f07 MGD |
21167 | NEON_ENCODE (FPV8, inst); |
21168 | ||
9db2f6b4 RL |
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 | } | |
33399f07 MGD |
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 | { | |
5ee91343 | 21189 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
33399f07 MGD |
21190 | |
21191 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
21192 | first_error (_("invalid instruction shape")); | |
21193 | } | |
21194 | ||
73924fbc MGD |
21195 | static void |
21196 | do_vmaxnm (void) | |
21197 | { | |
935295b5 AV |
21198 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)) |
21199 | set_pred_insn_type (OUTSIDE_PRED_INSN); | |
73924fbc MGD |
21200 | |
21201 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
21202 | return; | |
21203 | ||
5b7c81bd | 21204 | if (!check_simd_pred_availability (true, NEON_CHECK_CC | NEON_CHECK_ARCH8)) |
73924fbc MGD |
21205 | return; |
21206 | ||
cc933301 | 21207 | neon_dyadic_misc (NT_untyped, N_F_16_32, 0); |
73924fbc MGD |
21208 | } |
21209 | ||
30bdf752 MGD |
21210 | static void |
21211 | do_vrint_1 (enum neon_cvt_mode mode) | |
21212 | { | |
9db2f6b4 | 21213 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL); |
30bdf752 MGD |
21214 | struct neon_type_el et; |
21215 | ||
21216 | if (rs == NS_NULL) | |
21217 | return; | |
21218 | ||
a715796b TG |
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 | ||
9db2f6b4 RL |
21225 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY |
21226 | | N_VFP); | |
30bdf752 MGD |
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) | |
5ee91343 | 21232 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
30bdf752 MGD |
21233 | |
21234 | NEON_ENCODE (FPV8, inst); | |
9db2f6b4 | 21235 | if (rs == NS_FF || rs == NS_HH) |
30bdf752 MGD |
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 (); | |
9db2f6b4 RL |
21254 | |
21255 | /* ARMv8.2 fp16 vrint instruction. */ | |
21256 | if (rs == NS_HH) | |
21257 | do_scalar_fp16_v82_encode (); | |
30bdf752 MGD |
21258 | } |
21259 | else | |
21260 | { | |
21261 | /* Neon encodings (or something broken...). */ | |
21262 | inst.error = NULL; | |
cc933301 | 21263 | et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY); |
30bdf752 MGD |
21264 | |
21265 | if (et.type == NT_invtype) | |
21266 | return; | |
21267 | ||
5b7c81bd | 21268 | if (!check_simd_pred_availability (true, |
64c350f2 | 21269 | NEON_CHECK_CC | NEON_CHECK_ARCH8)) |
30bdf752 MGD |
21270 | return; |
21271 | ||
a710b305 AV |
21272 | NEON_ENCODE (FLOAT, inst); |
21273 | ||
30bdf752 MGD |
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; | |
cc933301 JW |
21279 | /* Mask off the original size bits and reencode them. */ |
21280 | inst.instruction = ((inst.instruction & 0xfff3ffff) | |
21281 | | neon_logbits (et.size) << 18); | |
21282 | ||
30bdf752 MGD |
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 | ||
c28eeff2 SN |
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 | { | |
5d281bf0 AV |
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)); | |
e2b0ab59 AV |
21365 | constraint (inst.relocs[0].exp.X_op != O_constant, |
21366 | _("expression too complex")); | |
21367 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
c28eeff2 SN |
21368 | constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270, |
21369 | _("immediate out of range")); | |
21370 | rot /= 90; | |
5d281bf0 | 21371 | |
5b7c81bd | 21372 | if (!check_simd_pred_availability (true, |
64c350f2 | 21373 | NEON_CHECK_ARCH8 | NEON_CHECK_CC)) |
5d281bf0 AV |
21374 | return; |
21375 | ||
c28eeff2 SN |
21376 | if (inst.operands[2].isscalar) |
21377 | { | |
5d281bf0 AV |
21378 | if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)) |
21379 | first_error (_("invalid instruction shape")); | |
c28eeff2 SN |
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 | { | |
5d281bf0 AV |
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 | ||
c28eeff2 SN |
21404 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, |
21405 | N_KEY | N_F16 | N_F32).size; | |
5d281bf0 AV |
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 | ||
c28eeff2 SN |
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 | { | |
5d281bf0 AV |
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)); | |
e2b0ab59 AV |
21425 | constraint (inst.relocs[0].exp.X_op != O_constant, |
21426 | _("expression too complex")); | |
5d281bf0 | 21427 | |
e2b0ab59 | 21428 | unsigned rot = inst.relocs[0].exp.X_add_number; |
c28eeff2 | 21429 | constraint (rot != 90 && rot != 270, _("immediate out of range")); |
5d281bf0 AV |
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 | ||
64c350f2 AV |
21450 | if (!check_simd_pred_availability (et.type == NT_float, |
21451 | NEON_CHECK_ARCH8 | NEON_CHECK_CC)) | |
5d281bf0 AV |
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 | } | |
c28eeff2 SN |
21476 | } |
21477 | ||
c604a79a JW |
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 | ||
616ce08e MM |
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); | |
1db66fb6 JB |
21562 | int idx = inst.operands[2].reg & 0xf; |
21563 | constraint ((idx != 1 && idx != 0), _("index must be 0 or 1")); | |
616ce08e MM |
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); | |
1db66fb6 | 21568 | inst.instruction |= (idx << 5); |
616ce08e MM |
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); | |
1db66fb6 JB |
21590 | int idx = inst.operands[2].reg & 0xf; |
21591 | constraint ((idx != 1 && idx != 0), _("index must be 0 or 1")); | |
616ce08e MM |
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); | |
1db66fb6 | 21596 | inst.instruction |= (idx << 5); |
616ce08e MM |
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 | ||
4934a27c | 21624 | static void |
1db66fb6 | 21625 | check_cde_operand (size_t idx, int is_dual) |
4934a27c | 21626 | { |
1db66fb6 JB |
21627 | unsigned Rx = inst.operands[idx].reg; |
21628 | bool isvec = inst.operands[idx].isvec; | |
4934a27c MM |
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 | ||
5b7c81bd | 21638 | static bool |
4934a27c MM |
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); | |
5b7c81bd | 21651 | default: return false; |
4934a27c MM |
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 | |
5b7c81bd | 21667 | cxn_handle_predication (bool is_accum) |
4934a27c | 21668 | { |
cceb53b8 MM |
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. */ | |
4934a27c | 21675 | inst.error = BAD_SYNTAX; |
4934a27c MM |
21676 | else |
21677 | set_pred_insn_type (OUTSIDE_PRED_INSN); | |
21678 | } | |
21679 | ||
21680 | static void | |
5b7c81bd | 21681 | do_custom_instruction_1 (int is_dual, bool is_accum) |
4934a27c MM |
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 | |
5b7c81bd | 21712 | do_custom_instruction_2 (int is_dual, bool is_accum) |
4934a27c MM |
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 | |
5b7c81bd | 21751 | do_custom_instruction_3 (int is_dual, bool is_accum) |
4934a27c MM |
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 | ||
5aae9ae9 MM |
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 | { | |
1ed818b4 | 21973 | unsigned R, i; |
5aae9ae9 | 21974 | unsigned reg_mult = vcx_handle_shape (reg_type); |
1ed818b4 | 21975 | for (i = 0; i < num_registers; i++) |
5aae9ae9 MM |
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" | |
ddc73fa9 | 22021 | " or Armv8-M floating point extension.")); |
5aae9ae9 MM |
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 | ||
91ff7894 MGD |
22071 | /* Crypto v1 instructions. */ |
22072 | static void | |
22073 | do_crypto_2op_1 (unsigned elttype, int op) | |
22074 | { | |
5ee91343 | 22075 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
91ff7894 MGD |
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 | ||
48adcd8e MGD |
22097 | static void |
22098 | do_crypto_3op_1 (int u, int op) | |
22099 | { | |
5ee91343 | 22100 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
48adcd8e MGD |
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 | ||
91ff7894 MGD |
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 | ||
48adcd8e MGD |
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 | } | |
91ff7894 | 22159 | |
48adcd8e MGD |
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 | } | |
3c9017d2 MGD |
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 | } | |
dd5181d5 KT |
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 | ||
5ee91343 | 22203 | set_pred_insn_type (OUTSIDE_PRED_INSN); |
dd5181d5 KT |
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")); | |
dd5181d5 KT |
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 | ||
49e8a725 SN |
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 | ||
aab2c27d MM |
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); | |
1db66fb6 JB |
22272 | int idx = inst.operands[2].reg & 0xf; |
22273 | constraint ((idx != 1 && idx != 0), _("index must be 0 or 1")); | |
aab2c27d MM |
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); | |
1db66fb6 | 22278 | inst.instruction |= (idx << 5); |
aab2c27d MM |
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 | ||
f1e1d7f3 AC |
22300 | static void |
22301 | do_t_pacbti (void) | |
22302 | { | |
22303 | inst.instruction = THUMB_OP32 (inst.instruction); | |
22304 | } | |
22305 | ||
e07352fa AC |
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 | ||
5c43020d AC |
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 | ||
5287ad62 JB |
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: | |
6e7ce2cd PB |
22353 | if (pc_rel) |
22354 | { | |
22355 | /* Create an absolute valued symbol, so we have something to | |
477330fc RM |
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. */ | |
6e7ce2cd PB |
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 */ | |
5287ad62 JB |
22376 | case O_symbol: |
22377 | case O_add: | |
22378 | case O_subtract: | |
21d799b5 | 22379 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
477330fc | 22380 | (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
22381 | break; |
22382 | ||
22383 | default: | |
21d799b5 | 22384 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
477330fc | 22385 | pc_rel, (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
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; | |
0110f2b8 PB |
22400 | int offset; |
22401 | ||
6e1cb1a6 PB |
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); | |
6e1cb1a6 | 22405 | |
e2b0ab59 | 22406 | switch (inst.relocs[0].exp.X_op) |
0110f2b8 PB |
22407 | { |
22408 | case O_symbol: | |
e2b0ab59 AV |
22409 | sym = inst.relocs[0].exp.X_add_symbol; |
22410 | offset = inst.relocs[0].exp.X_add_number; | |
0110f2b8 PB |
22411 | break; |
22412 | case O_constant: | |
22413 | sym = NULL; | |
e2b0ab59 | 22414 | offset = inst.relocs[0].exp.X_add_number; |
0110f2b8 PB |
22415 | break; |
22416 | default: | |
e2b0ab59 | 22417 | sym = make_expr_symbol (&inst.relocs[0].exp); |
0110f2b8 PB |
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); | |
0110f2b8 PB |
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 | ||
b99bd4ef | 22434 | static void |
c19d1205 | 22435 | output_inst (const char * str) |
b99bd4ef | 22436 | { |
c19d1205 | 22437 | char * to = NULL; |
b99bd4ef | 22438 | |
c19d1205 | 22439 | if (inst.error) |
b99bd4ef | 22440 | { |
c19d1205 | 22441 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
22442 | return; |
22443 | } | |
5f4273c7 NC |
22444 | if (inst.relax) |
22445 | { | |
22446 | output_relax_insn (); | |
0110f2b8 | 22447 | return; |
5f4273c7 | 22448 | } |
c19d1205 ZW |
22449 | if (inst.size == 0) |
22450 | return; | |
b99bd4ef | 22451 | |
c19d1205 | 22452 | to = frag_more (inst.size); |
8dc2430f NC |
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. */ | |
cd000bff | 22457 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
22458 | |
22459 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 22460 | { |
9c2799c2 | 22461 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 22462 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 22463 | } |
c19d1205 | 22464 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 22465 | { |
9c2799c2 | 22466 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
22467 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
22468 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 22469 | } |
c19d1205 ZW |
22470 | else |
22471 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 22472 | |
e2b0ab59 AV |
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 | } | |
b99bd4ef | 22481 | |
c19d1205 | 22482 | dwarf2_emit_insn (inst.size); |
c19d1205 | 22483 | } |
b99bd4ef | 22484 | |
e07e6e58 NC |
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 | ||
c19d1205 ZW |
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. */ | |
5ee91343 AV |
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. */ | |
c19d1205 ZW |
22519 | OT_cinfix3, /* Instruction takes a conditional infix, |
22520 | beginning at character index 3. (In | |
22521 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
22522 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
22523 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
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. */ | |
c19d1205 | 22528 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 22529 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
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 | }; | |
b99bd4ef | 22541 | |
c19d1205 ZW |
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; | |
e3cb604e | 22601 | char save[2]; |
c19d1205 ZW |
22602 | |
22603 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 22604 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 22605 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 22606 | if (*end == ' ' || *end == '.') |
c19d1205 | 22607 | break; |
b99bd4ef | 22608 | |
c19d1205 | 22609 | if (end == base) |
c921be7d | 22610 | return NULL; |
b99bd4ef | 22611 | |
5287ad62 | 22612 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 22613 | if (end[0] == '.') |
b99bd4ef | 22614 | { |
5287ad62 | 22615 | int offset = 2; |
5f4273c7 | 22616 | |
267d2029 | 22617 | /* The .w and .n suffixes are only valid if the unified syntax is in |
477330fc | 22618 | use. */ |
267d2029 | 22619 | if (unified_syntax && end[1] == 'w') |
c19d1205 | 22620 | inst.size_req = 4; |
267d2029 | 22621 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
22622 | inst.size_req = 2; |
22623 | else | |
477330fc | 22624 | offset = 0; |
5287ad62 JB |
22625 | |
22626 | inst.vectype.elems = 0; | |
22627 | ||
22628 | *str = end + offset; | |
b99bd4ef | 22629 | |
5f4273c7 | 22630 | if (end[offset] == '.') |
5287ad62 | 22631 | { |
267d2029 | 22632 | /* See if we have a Neon type suffix (possible in either unified or |
477330fc RM |
22633 | non-unified ARM syntax mode). */ |
22634 | if (parse_neon_type (&inst.vectype, str) == FAIL) | |
c921be7d | 22635 | return NULL; |
477330fc | 22636 | } |
5287ad62 | 22637 | else if (end[offset] != '\0' && end[offset] != ' ') |
477330fc | 22638 | return NULL; |
b99bd4ef | 22639 | } |
c19d1205 ZW |
22640 | else |
22641 | *str = end; | |
b99bd4ef | 22642 | |
c19d1205 | 22643 | /* Look for unaffixed or special-case affixed mnemonic. */ |
629310ab | 22644 | opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base, |
fe0e921f | 22645 | end - base); |
f3da8a96 | 22646 | cond = NULL; |
c19d1205 | 22647 | if (opcode) |
b99bd4ef | 22648 | { |
c19d1205 ZW |
22649 | /* step U */ |
22650 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 22651 | { |
c19d1205 ZW |
22652 | inst.cond = COND_ALWAYS; |
22653 | return opcode; | |
b99bd4ef | 22654 | } |
b99bd4ef | 22655 | |
278df34e | 22656 | if (warn_on_deprecated && unified_syntax) |
5c3696f8 | 22657 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 | 22658 | affix = base + (opcode->tag - OT_odd_infix_0); |
629310ab | 22659 | cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 22660 | gas_assert (cond); |
b99bd4ef | 22661 | |
c19d1205 ZW |
22662 | inst.cond = cond->value; |
22663 | return opcode; | |
22664 | } | |
5ee91343 AV |
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; | |
629310ab ML |
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, | |
fe0e921f | 22674 | affix - base); |
5ee91343 AV |
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; | |
b99bd4ef | 22686 | |
5ee91343 AV |
22687 | /* Look for suffixed mnemonic. */ |
22688 | affix = end - 2; | |
629310ab ML |
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, | |
fe0e921f | 22691 | affix - base); |
5ee91343 | 22692 | } |
b99bd4ef | 22693 | |
c19d1205 ZW |
22694 | if (opcode && cond) |
22695 | { | |
22696 | /* step CE */ | |
22697 | switch (opcode->tag) | |
22698 | { | |
e3cb604e PB |
22699 | case OT_cinfix3_legacy: |
22700 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
22701 | break; | |
22702 | ||
c19d1205 | 22703 | case OT_cinfix3: |
088fa78e | 22704 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
22705 | case OT_odd_infix_unc: |
22706 | if (!unified_syntax) | |
0198d5e6 | 22707 | return NULL; |
1a0670f3 | 22708 | /* Fall through. */ |
c19d1205 ZW |
22709 | |
22710 | case OT_csuffix: | |
477330fc | 22711 | case OT_csuffixF: |
c19d1205 ZW |
22712 | case OT_csuf_or_in3: |
22713 | inst.cond = cond->value; | |
22714 | return opcode; | |
22715 | ||
22716 | case OT_unconditional: | |
22717 | case OT_unconditionalF: | |
dfa9f0d5 | 22718 | if (thumb_mode) |
c921be7d | 22719 | inst.cond = cond->value; |
dfa9f0d5 PB |
22720 | else |
22721 | { | |
c921be7d | 22722 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
22723 | inst.error = BAD_COND; |
22724 | inst.cond = COND_ALWAYS; | |
22725 | } | |
c19d1205 | 22726 | return opcode; |
b99bd4ef | 22727 | |
c19d1205 | 22728 | default: |
c921be7d | 22729 | return NULL; |
c19d1205 ZW |
22730 | } |
22731 | } | |
b99bd4ef | 22732 | |
c19d1205 ZW |
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) | |
c921be7d | 22736 | return NULL; |
b99bd4ef | 22737 | |
c19d1205 ZW |
22738 | /* Look for infixed mnemonic in the usual position. */ |
22739 | affix = base + 3; | |
629310ab | 22740 | cond = (const struct asm_cond *) str_hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 22741 | if (!cond) |
c921be7d | 22742 | return NULL; |
e3cb604e PB |
22743 | |
22744 | memcpy (save, affix, 2); | |
22745 | memmove (affix, affix + 2, (end - affix) - 2); | |
629310ab | 22746 | opcode = (const struct asm_opcode *) str_hash_find_n (arm_ops_hsh, base, |
fe0e921f | 22747 | (end - base) - 2); |
e3cb604e PB |
22748 | memmove (affix + 2, affix, (end - affix) - 2); |
22749 | memcpy (affix, save, 2); | |
22750 | ||
088fa78e KH |
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)) | |
b99bd4ef | 22756 | { |
c921be7d | 22757 | /* Step CM. */ |
278df34e | 22758 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
22759 | && (opcode->tag == OT_cinfix3 |
22760 | || opcode->tag == OT_cinfix3_deprecated)) | |
5c3696f8 | 22761 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 ZW |
22762 | |
22763 | inst.cond = cond->value; | |
22764 | return opcode; | |
b99bd4ef NC |
22765 | } |
22766 | ||
c921be7d | 22767 | return NULL; |
b99bd4ef NC |
22768 | } |
22769 | ||
e07e6e58 NC |
22770 | /* This function generates an initial IT instruction, leaving its block |
22771 | virtually open for the new instructions. Eventually, | |
5ee91343 | 22772 | the mask will be updated by now_pred_add_mask () each time |
e07e6e58 NC |
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 | { | |
5ee91343 AV |
22781 | now_pred.state = AUTOMATIC_PRED_BLOCK; |
22782 | now_pred.mask = 0x18; | |
22783 | now_pred.cc = cond; | |
22784 | now_pred.block_length = 1; | |
cd000bff | 22785 | mapping_state (MAP_THUMB); |
5ee91343 | 22786 | now_pred.insn = output_it_inst (cond, now_pred.mask, NULL); |
5b7c81bd AM |
22787 | now_pred.warn_deprecated = false; |
22788 | now_pred.insn_cond = true; | |
e07e6e58 NC |
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 | { | |
5ee91343 AV |
22797 | now_pred.mask = 0x10; |
22798 | now_pred.block_length = 0; | |
e07e6e58 NC |
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 | |
5ee91343 | 22805 | now_pred_add_mask (int cond) |
e07e6e58 NC |
22806 | { |
22807 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
22808 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
477330fc | 22809 | | ((bitvalue) << (nbit))) |
e07e6e58 | 22810 | const int resulting_bit = (cond & 1); |
c921be7d | 22811 | |
5ee91343 AV |
22812 | now_pred.mask &= 0xf; |
22813 | now_pred.mask = SET_BIT_VALUE (now_pred.mask, | |
477330fc | 22814 | resulting_bit, |
5ee91343 AV |
22815 | (5 - now_pred.block_length)); |
22816 | now_pred.mask = SET_BIT_VALUE (now_pred.mask, | |
477330fc | 22817 | 1, |
5ee91343 AV |
22818 | ((5 - now_pred.block_length) - 1)); |
22819 | output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn); | |
e07e6e58 NC |
22820 | |
22821 | #undef CLEAR_BIT | |
22822 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
22823 | } |
22824 | ||
22825 | /* The IT blocks handling machinery is accessed through the these functions: | |
22826 | it_fsm_pre_encode () from md_assemble () | |
5ee91343 AV |
22827 | set_pred_insn_type () optional, from the tencode functions |
22828 | set_pred_insn_type_last () ditto | |
22829 | in_pred_block () ditto | |
e07e6e58 | 22830 | it_fsm_post_encode () from md_assemble () |
33eaf5de | 22831 | force_automatic_it_block_close () from label handling functions |
e07e6e58 NC |
22832 | |
22833 | Rationale: | |
22834 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
477330fc RM |
22835 | initializing the IT insn type with a generic initial value depending |
22836 | on the inst.condition. | |
e07e6e58 | 22837 | 2) During the tencode function, two things may happen: |
477330fc | 22838 | a) The tencode function overrides the IT insn type by |
5ee91343 AV |
22839 | calling either set_pred_insn_type (type) or |
22840 | set_pred_insn_type_last (). | |
477330fc | 22841 | b) The tencode function queries the IT block state by |
5ee91343 | 22842 | calling in_pred_block () (i.e. to determine narrow/not narrow mode). |
477330fc | 22843 | |
5ee91343 AV |
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 | |
477330fc RM |
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. | |
5ee91343 AV |
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. | |
477330fc | 22854 | |
5ee91343 AV |
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. | |
477330fc RM |
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 | |
5ee91343 | 22859 | the last one, set_pred_insn_type_last () will determine the proper |
477330fc | 22860 | IT instruction type based on the inst.cond code. Otherwise, |
5ee91343 | 22861 | set_pred_insn_type can be called for overriding that logic or |
477330fc RM |
22862 | for covering other cases. |
22863 | ||
5ee91343 AV |
22864 | Calling handle_pred_state () may not transition the IT block state to |
22865 | OUTSIDE_PRED_BLOCK immediately, since the (current) state could be | |
477330fc | 22866 | still queried. Instead, if the FSM determines that the state should |
5ee91343 | 22867 | be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed |
477330fc RM |
22868 | after the tencode () function: that's what it_fsm_post_encode () does. |
22869 | ||
5ee91343 | 22870 | Since in_pred_block () calls the state handling function to get an |
477330fc RM |
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. | |
e07e6e58 NC |
22875 | |
22876 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
477330fc | 22877 | any pending state change (if any) that didn't take place in |
5ee91343 | 22878 | handle_pred_state () as explained above. */ |
e07e6e58 NC |
22879 | |
22880 | static void | |
22881 | it_fsm_pre_encode (void) | |
22882 | { | |
22883 | if (inst.cond != COND_ALWAYS) | |
5ee91343 | 22884 | inst.pred_insn_type = INSIDE_IT_INSN; |
e07e6e58 | 22885 | else |
5ee91343 | 22886 | inst.pred_insn_type = OUTSIDE_PRED_INSN; |
e07e6e58 | 22887 | |
5ee91343 | 22888 | now_pred.state_handled = 0; |
e07e6e58 NC |
22889 | } |
22890 | ||
22891 | /* IT state FSM handling function. */ | |
5ee91343 AV |
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 | |
35c228db | 22897 | few exceptions we have MVE_UNPREDICABLE_INSN. |
5ee91343 AV |
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 | ||
e07e6e58 NC |
22922 | |
22923 | static int | |
5ee91343 | 22924 | handle_pred_state (void) |
e07e6e58 | 22925 | { |
5ee91343 | 22926 | now_pred.state_handled = 1; |
5b7c81bd | 22927 | now_pred.insn_cond = false; |
e07e6e58 | 22928 | |
5ee91343 | 22929 | switch (now_pred.state) |
e07e6e58 | 22930 | { |
5ee91343 AV |
22931 | case OUTSIDE_PRED_BLOCK: |
22932 | switch (inst.pred_insn_type) | |
e07e6e58 | 22933 | { |
35c228db | 22934 | case MVE_UNPREDICABLE_INSN: |
5ee91343 AV |
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! */ | |
e07e6e58 NC |
22954 | break; |
22955 | ||
5ee91343 AV |
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 | ||
e07e6e58 NC |
22962 | case INSIDE_IT_INSN: |
22963 | case INSIDE_IT_LAST_INSN: | |
5ee91343 | 22964 | if (inst.cond < COND_ALWAYS) |
e07e6e58 | 22965 | { |
5ee91343 AV |
22966 | /* Case 16: Outside a pred block, with an IT code: error: should |
22967 | be in an IT block. */ | |
22968 | if (thumb_mode == 0) | |
e07e6e58 | 22969 | { |
5ee91343 AV |
22970 | if (unified_syntax |
22971 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) | |
22972 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
22973 | " for Thumb.")); | |
e07e6e58 NC |
22974 | } |
22975 | else | |
22976 | { | |
5ee91343 AV |
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 | } | |
e07e6e58 | 22990 | } |
5ee91343 | 22991 | break; |
e07e6e58 | 22992 | } |
5ee91343 AV |
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); | |
e07e6e58 NC |
23002 | case IF_INSIDE_IT_LAST_INSN: |
23003 | case NEUTRAL_IT_INSN: | |
23004 | break; | |
23005 | ||
5ee91343 AV |
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; | |
e07e6e58 | 23014 | case IT_INSN: |
5ee91343 AV |
23015 | now_pred.state = MANUAL_PRED_BLOCK; |
23016 | now_pred.block_length = 0; | |
23017 | now_pred.type = SCALAR_PRED; | |
e07e6e58 NC |
23018 | break; |
23019 | } | |
23020 | break; | |
23021 | ||
5ee91343 | 23022 | case AUTOMATIC_PRED_BLOCK: |
e07e6e58 NC |
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 | ||
5ee91343 | 23030 | switch (inst.pred_insn_type) |
e07e6e58 | 23031 | { |
5ee91343 AV |
23032 | case INSIDE_VPT_INSN: |
23033 | case VPT_INSN: | |
35c228db | 23034 | case MVE_UNPREDICABLE_INSN: |
5ee91343 AV |
23035 | case MVE_OUTSIDE_PRED_INSN: |
23036 | gas_assert (0); | |
23037 | case OUTSIDE_PRED_INSN: | |
2b0f3761 | 23038 | /* The closure of the block shall happen immediately, |
5ee91343 | 23039 | so any in_pred_block () call reports the block as closed. */ |
e07e6e58 NC |
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: | |
5ee91343 | 23046 | now_pred.block_length++; |
e07e6e58 | 23047 | |
5ee91343 AV |
23048 | if (now_pred.block_length > 4 |
23049 | || !now_pred_compatible (inst.cond)) | |
e07e6e58 NC |
23050 | { |
23051 | force_automatic_it_block_close (); | |
5ee91343 | 23052 | if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN) |
e07e6e58 NC |
23053 | new_automatic_it_block (inst.cond); |
23054 | } | |
23055 | else | |
23056 | { | |
5b7c81bd | 23057 | now_pred.insn_cond = true; |
5ee91343 | 23058 | now_pred_add_mask (inst.cond); |
e07e6e58 NC |
23059 | } |
23060 | ||
5ee91343 AV |
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)) | |
e07e6e58 NC |
23064 | close_automatic_it_block (); |
23065 | break; | |
23066 | ||
4934a27c | 23067 | /* Fallthrough. */ |
e07e6e58 | 23068 | case NEUTRAL_IT_INSN: |
5ee91343 | 23069 | now_pred.block_length++; |
5b7c81bd | 23070 | now_pred.insn_cond = true; |
e07e6e58 | 23071 | |
5ee91343 | 23072 | if (now_pred.block_length > 4) |
e07e6e58 NC |
23073 | force_automatic_it_block_close (); |
23074 | else | |
5ee91343 | 23075 | now_pred_add_mask (now_pred.cc & 1); |
e07e6e58 NC |
23076 | break; |
23077 | ||
23078 | case IT_INSN: | |
23079 | close_automatic_it_block (); | |
5ee91343 | 23080 | now_pred.state = MANUAL_PRED_BLOCK; |
e07e6e58 NC |
23081 | break; |
23082 | } | |
23083 | break; | |
23084 | ||
5ee91343 | 23085 | case MANUAL_PRED_BLOCK: |
e07e6e58 | 23086 | { |
7af67752 AM |
23087 | unsigned int cond; |
23088 | int is_last; | |
5ee91343 | 23089 | if (now_pred.type == SCALAR_PRED) |
e07e6e58 | 23090 | { |
5ee91343 AV |
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 | } | |
5b7c81bd | 23105 | now_pred.insn_cond = true; |
e07e6e58 | 23106 | |
5ee91343 AV |
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 | } | |
35c228db AV |
23186 | case MVE_UNPREDICABLE_INSN: |
23187 | as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT); | |
23188 | return SUCCESS; | |
e07e6e58 | 23189 | case INSIDE_IT_INSN: |
5ee91343 | 23190 | if (inst.cond > COND_ALWAYS) |
e07e6e58 | 23191 | { |
5ee91343 AV |
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; | |
e07e6e58 NC |
23212 | return FAIL; |
23213 | } | |
23214 | break; | |
23215 | ||
5ee91343 AV |
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; | |
e07e6e58 NC |
23231 | case INSIDE_IT_LAST_INSN: |
23232 | case IF_INSIDE_IT_LAST_INSN: | |
5ee91343 AV |
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) | |
e07e6e58 NC |
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: | |
5ee91343 AV |
23253 | /* The BKPT instruction is unconditional even in a IT or VPT |
23254 | block. */ | |
e07e6e58 NC |
23255 | break; |
23256 | ||
23257 | case IT_INSN: | |
5ee91343 AV |
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 | } | |
e07e6e58 | 23282 | } |
5ee91343 | 23283 | } |
e07e6e58 NC |
23284 | break; |
23285 | } | |
23286 | ||
23287 | return SUCCESS; | |
23288 | } | |
23289 | ||
5a01bb1d MGD |
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") }, | |
c8de034b JW |
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") }, | |
5a01bb1d MGD |
23309 | { 0, 0, NULL } |
23310 | }; | |
23311 | ||
e07e6e58 NC |
23312 | static void |
23313 | it_fsm_post_encode (void) | |
23314 | { | |
23315 | int is_last; | |
23316 | ||
5ee91343 AV |
23317 | if (!now_pred.state_handled) |
23318 | handle_pred_state (); | |
e07e6e58 | 23319 | |
5ee91343 | 23320 | if (now_pred.insn_cond |
24f19ccb | 23321 | && warn_on_restrict_it |
5ee91343 | 23322 | && !now_pred.warn_deprecated |
5a01bb1d | 23323 | && warn_on_deprecated |
164446e0 AF |
23324 | && (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8) |
23325 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8r)) | |
df9909b8 | 23326 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m)) |
5a01bb1d MGD |
23327 | { |
23328 | if (inst.instruction >= 0x10000) | |
23329 | { | |
5c3696f8 | 23330 | as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are " |
df9909b8 | 23331 | "performance deprecated in ARMv8-A and ARMv8-R")); |
5b7c81bd | 23332 | now_pred.warn_deprecated = true; |
5a01bb1d MGD |
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 | { | |
df9909b8 TP |
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); | |
5b7c81bd | 23346 | now_pred.warn_deprecated = true; |
5a01bb1d MGD |
23347 | break; |
23348 | } | |
23349 | ||
23350 | ++p; | |
23351 | } | |
23352 | } | |
23353 | ||
5ee91343 | 23354 | if (now_pred.block_length > 1) |
5a01bb1d | 23355 | { |
5c3696f8 | 23356 | as_tsktsk (_("IT blocks containing more than one conditional " |
df9909b8 TP |
23357 | "instruction are performance deprecated in ARMv8-A and " |
23358 | "ARMv8-R")); | |
5b7c81bd | 23359 | now_pred.warn_deprecated = true; |
5a01bb1d MGD |
23360 | } |
23361 | } | |
23362 | ||
5ee91343 AV |
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 | } | |
e07e6e58 NC |
23369 | } |
23370 | ||
23371 | static void | |
23372 | force_automatic_it_block_close (void) | |
23373 | { | |
5ee91343 | 23374 | if (now_pred.state == AUTOMATIC_PRED_BLOCK) |
e07e6e58 NC |
23375 | { |
23376 | close_automatic_it_block (); | |
5ee91343 AV |
23377 | now_pred.state = OUTSIDE_PRED_BLOCK; |
23378 | now_pred.mask = 0; | |
e07e6e58 NC |
23379 | } |
23380 | } | |
23381 | ||
23382 | static int | |
5ee91343 | 23383 | in_pred_block (void) |
e07e6e58 | 23384 | { |
5ee91343 AV |
23385 | if (!now_pred.state_handled) |
23386 | handle_pred_state (); | |
e07e6e58 | 23387 | |
5ee91343 | 23388 | return now_pred.state != OUTSIDE_PRED_BLOCK; |
e07e6e58 NC |
23389 | } |
23390 | ||
ff8646ee TP |
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. */ | |
fc289b0a | 23394 | |
5b7c81bd | 23395 | static bool |
ff8646ee | 23396 | known_t32_only_insn (const struct asm_opcode *opcode) |
fc289b0a TP |
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)) | |
5b7c81bd | 23403 | return true; |
fc289b0a | 23404 | |
16a1fa25 TP |
23405 | /* Wide-only instruction added to ARMv8-M Baseline. */ |
23406 | if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only) | |
ff8646ee TP |
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)) | |
5b7c81bd | 23410 | return true; |
ff8646ee | 23411 | |
5b7c81bd | 23412 | return false; |
ff8646ee TP |
23413 | } |
23414 | ||
23415 | /* Whether wide instruction variant can be used if available for a valid OPCODE | |
23416 | in ARCH. */ | |
23417 | ||
5b7c81bd | 23418 | static bool |
ff8646ee TP |
23419 | t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode) |
23420 | { | |
23421 | if (known_t32_only_insn (opcode)) | |
5b7c81bd | 23422 | return true; |
ff8646ee TP |
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) | |
5b7c81bd | 23428 | return true; |
ff8646ee | 23429 | |
bada4342 JW |
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) | |
5b7c81bd | 23435 | return true; |
bada4342 | 23436 | |
ff8646ee TP |
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)) | |
5b7c81bd | 23441 | return true; |
ff8646ee TP |
23442 | |
23443 | /* OPCODE with narrow only instruction variant or wide variant not | |
23444 | available. */ | |
5b7c81bd | 23445 | return false; |
fc289b0a TP |
23446 | } |
23447 | ||
c19d1205 ZW |
23448 | void |
23449 | md_assemble (char *str) | |
b99bd4ef | 23450 | { |
c19d1205 ZW |
23451 | char *p = str; |
23452 | const struct asm_opcode * opcode; | |
b99bd4ef | 23453 | |
c19d1205 ZW |
23454 | /* Align the previous label if needed. */ |
23455 | if (last_label_seen != NULL) | |
b99bd4ef | 23456 | { |
c19d1205 ZW |
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); | |
b99bd4ef NC |
23460 | } |
23461 | ||
c19d1205 | 23462 | memset (&inst, '\0', sizeof (inst)); |
e2b0ab59 AV |
23463 | int r; |
23464 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
23465 | inst.relocs[r].type = BFD_RELOC_UNUSED; | |
b99bd4ef | 23466 | |
c19d1205 ZW |
23467 | opcode = opcode_lookup (&p); |
23468 | if (!opcode) | |
b99bd4ef | 23469 | { |
c19d1205 | 23470 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 23471 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d | 23472 | if (! create_register_alias (str, p) |
477330fc | 23473 | && ! create_neon_reg_alias (str, p)) |
c19d1205 | 23474 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 23475 | |
b99bd4ef NC |
23476 | return; |
23477 | } | |
23478 | ||
278df34e | 23479 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
5c3696f8 | 23480 | as_tsktsk (_("s suffix on comparison instruction is deprecated")); |
088fa78e | 23481 | |
037e8744 JB |
23482 | /* The value which unconditional instructions should have in place of the |
23483 | condition field. */ | |
7af67752 | 23484 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1u; |
037e8744 | 23485 | |
c19d1205 | 23486 | if (thumb_mode) |
b99bd4ef | 23487 | { |
e74cfd16 | 23488 | arm_feature_set variant; |
8f06b2d8 PB |
23489 | |
23490 | variant = cpu_variant; | |
23491 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
23492 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
23493 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 23494 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
23495 | if (!opcode->tvariant |
23496 | || (thumb_mode == 1 | |
23497 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 23498 | { |
173205ca TP |
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); | |
b99bd4ef NC |
23503 | return; |
23504 | } | |
c19d1205 ZW |
23505 | if (inst.cond != COND_ALWAYS && !unified_syntax |
23506 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 23507 | { |
c19d1205 | 23508 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
23509 | return; |
23510 | } | |
23511 | ||
fc289b0a TP |
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) | |
ff8646ee | 23521 | && !t32_insn_ok (variant, opcode)) |
076d447c | 23522 | { |
fc289b0a TP |
23523 | if (inst.size_req == 0) |
23524 | inst.size_req = 2; | |
23525 | else if (inst.size_req == 4) | |
752d5da4 | 23526 | { |
ff8646ee TP |
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); | |
fc289b0a | 23533 | return; |
752d5da4 | 23534 | } |
076d447c PB |
23535 | } |
23536 | ||
c19d1205 ZW |
23537 | inst.instruction = opcode->tvalue; |
23538 | ||
5b7c81bd | 23539 | if (!parse_operands (p, opcode->operands, /*thumb=*/true)) |
477330fc | 23540 | { |
5ee91343 | 23541 | /* Prepare the pred_insn_type for those encodings that don't set |
477330fc RM |
23542 | it. */ |
23543 | it_fsm_pre_encode (); | |
c19d1205 | 23544 | |
477330fc | 23545 | opcode->tencode (); |
e07e6e58 | 23546 | |
477330fc RM |
23547 | it_fsm_post_encode (); |
23548 | } | |
e27ec89e | 23549 | |
0110f2b8 | 23550 | if (!(inst.error || inst.relax)) |
b99bd4ef | 23551 | { |
9c2799c2 | 23552 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
23553 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
23554 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 23555 | { |
c19d1205 | 23556 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
23557 | return; |
23558 | } | |
23559 | } | |
076d447c PB |
23560 | |
23561 | /* Something has gone badly wrong if we try to relax a fixed size | |
477330fc | 23562 | instruction. */ |
9c2799c2 | 23563 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 23564 | |
e74cfd16 PB |
23565 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
23566 | *opcode->tvariant); | |
ee065d83 | 23567 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
fc289b0a TP |
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. */ | |
ff8646ee TP |
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)) | |
e74cfd16 PB |
23576 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
23577 | arm_ext_v6t2); | |
cd000bff | 23578 | |
88714cb8 DG |
23579 | check_neon_suffixes; |
23580 | ||
cd000bff | 23581 | if (!inst.error) |
c877a2f2 NC |
23582 | { |
23583 | mapping_state (MAP_THUMB); | |
23584 | } | |
c19d1205 | 23585 | } |
3e9e4fcf | 23586 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 23587 | { |
5b7c81bd | 23588 | bool is_bx; |
845b51d6 PB |
23589 | |
23590 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
23591 | is_bx = (opcode->aencode == do_bx); | |
23592 | ||
c19d1205 | 23593 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
23594 | if (!(is_bx && fix_v4bx) |
23595 | && !(opcode->avariant && | |
23596 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 23597 | { |
84b52b66 | 23598 | as_bad (_("selected processor does not support `%s' in ARM mode"), str); |
c19d1205 | 23599 | return; |
b99bd4ef | 23600 | } |
c19d1205 | 23601 | if (inst.size_req) |
b99bd4ef | 23602 | { |
c19d1205 ZW |
23603 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
23604 | return; | |
b99bd4ef NC |
23605 | } |
23606 | ||
c19d1205 ZW |
23607 | inst.instruction = opcode->avalue; |
23608 | if (opcode->tag == OT_unconditionalF) | |
eff0bc54 | 23609 | inst.instruction |= 0xFU << 28; |
c19d1205 ZW |
23610 | else |
23611 | inst.instruction |= inst.cond << 28; | |
23612 | inst.size = INSN_SIZE; | |
5b7c81bd | 23613 | if (!parse_operands (p, opcode->operands, /*thumb=*/false)) |
477330fc RM |
23614 | { |
23615 | it_fsm_pre_encode (); | |
23616 | opcode->aencode (); | |
23617 | it_fsm_post_encode (); | |
23618 | } | |
ee065d83 | 23619 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
477330fc | 23620 | on a hypothetical non-thumb v5 core. */ |
845b51d6 | 23621 | if (is_bx) |
e74cfd16 | 23622 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 23623 | else |
e74cfd16 PB |
23624 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
23625 | *opcode->avariant); | |
88714cb8 DG |
23626 | |
23627 | check_neon_suffixes; | |
23628 | ||
cd000bff | 23629 | if (!inst.error) |
c877a2f2 NC |
23630 | { |
23631 | mapping_state (MAP_ARM); | |
23632 | } | |
b99bd4ef | 23633 | } |
3e9e4fcf JB |
23634 | else |
23635 | { | |
23636 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
23637 | "-- `%s'"), str); | |
23638 | return; | |
23639 | } | |
c19d1205 ZW |
23640 | output_inst (str); |
23641 | } | |
b99bd4ef | 23642 | |
e07e6e58 | 23643 | static void |
5ee91343 | 23644 | check_pred_blocks_finished (void) |
e07e6e58 NC |
23645 | { |
23646 | #ifdef OBJ_ELF | |
23647 | asection *sect; | |
23648 | ||
23649 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
5ee91343 AV |
23650 | if (seg_info (sect)->tc_segment_info_data.current_pred.state |
23651 | == MANUAL_PRED_BLOCK) | |
e07e6e58 | 23652 | { |
5ee91343 AV |
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); | |
e07e6e58 NC |
23659 | } |
23660 | #else | |
5ee91343 AV |
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 | } | |
e07e6e58 NC |
23668 | #endif |
23669 | } | |
23670 | ||
c19d1205 ZW |
23671 | /* Various frobbings of labels and their addresses. */ |
23672 | ||
23673 | void | |
23674 | arm_start_line_hook (void) | |
23675 | { | |
23676 | last_label_seen = NULL; | |
b99bd4ef NC |
23677 | } |
23678 | ||
c19d1205 ZW |
23679 | void |
23680 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 23681 | { |
c19d1205 | 23682 | last_label_seen = sym; |
b99bd4ef | 23683 | |
c19d1205 | 23684 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 23685 | |
c19d1205 ZW |
23686 | #if defined OBJ_COFF || defined OBJ_ELF |
23687 | ARM_SET_INTERWORK (sym, support_interwork); | |
23688 | #endif | |
b99bd4ef | 23689 | |
e07e6e58 NC |
23690 | force_automatic_it_block_close (); |
23691 | ||
5f4273c7 | 23692 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
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: | |
b99bd4ef | 23698 | |
c19d1205 ZW |
23699 | ldr r2, [pc, .Laaa] |
23700 | lsl r3, r3, #2 | |
23701 | ldr r2, [r3, r2] | |
23702 | mov pc, r2 | |
b99bd4ef | 23703 | |
c19d1205 ZW |
23704 | .Lbbb: .word .Lxxx |
23705 | .Lccc: .word .Lyyy | |
23706 | ..etc... | |
23707 | .Laaa: .word Lbbb | |
b99bd4ef | 23708 | |
c19d1205 ZW |
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. | |
b99bd4ef | 23713 | |
c19d1205 ZW |
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') | |
fd361982 | 23723 | && (bfd_section_flags (now_seg) & SEC_CODE) != 0) |
b99bd4ef | 23724 | { |
c19d1205 ZW |
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. */ | |
b99bd4ef | 23729 | |
c19d1205 | 23730 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 23731 | |
5b7c81bd | 23732 | label_is_thumb_function_name = false; |
b99bd4ef | 23733 | } |
07a53e5c | 23734 | |
07a53e5c | 23735 | dwarf2_emit_label (sym); |
b99bd4ef NC |
23736 | } |
23737 | ||
5b7c81bd | 23738 | bool |
c19d1205 | 23739 | arm_data_in_code (void) |
b99bd4ef | 23740 | { |
d34049e8 | 23741 | if (thumb_mode && startswith (input_line_pointer + 1, "data:")) |
b99bd4ef | 23742 | { |
c19d1205 ZW |
23743 | *input_line_pointer = '/'; |
23744 | input_line_pointer += 5; | |
23745 | *input_line_pointer = 0; | |
5b7c81bd | 23746 | return true; |
b99bd4ef NC |
23747 | } |
23748 | ||
5b7c81bd | 23749 | return false; |
b99bd4ef NC |
23750 | } |
23751 | ||
c19d1205 ZW |
23752 | char * |
23753 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 23754 | { |
c19d1205 | 23755 | int len; |
b99bd4ef | 23756 | |
c19d1205 ZW |
23757 | if (thumb_mode && (len = strlen (name)) > 5 |
23758 | && streq (name + len - 5, "/data")) | |
23759 | *(name + len - 5) = 0; | |
b99bd4ef | 23760 | |
c19d1205 | 23761 | return name; |
b99bd4ef | 23762 | } |
c19d1205 ZW |
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. */ | |
b99bd4ef | 23768 | |
5b7c81bd | 23769 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, true, 0 } |
c19d1205 | 23770 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 23771 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
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) | |
5287ad62 JB |
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) | |
90ec0d68 MGD |
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) | |
7ed4c4c5 | 23794 | |
c19d1205 | 23795 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 23796 | { |
c19d1205 ZW |
23797 | /* ARM integer registers. */ |
23798 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 23799 | |
c19d1205 ZW |
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), | |
7ed4c4c5 | 23804 | |
c19d1205 ZW |
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), | |
7ed4c4c5 | 23808 | |
c19d1205 ZW |
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 | ||
1b883319 AV |
23816 | /* Defining the new Zero register from ARMv8.1-M. */ |
23817 | REGDEF(zr,15,ZR), | |
23818 | REGDEF(ZR,15,ZR), | |
23819 | ||
c19d1205 ZW |
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 | ||
90ec0d68 MGD |
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), | |
1472d06f | 23842 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB), |
90ec0d68 MGD |
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), | |
fa94de6b | 23853 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
23854 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
23855 | ||
c19d1205 ZW |
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. */ | |
5287ad62 JB |
23864 | REGSET(s,VFS), REGSET(S,VFS), |
23865 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
23866 | |
23867 | /* VFP DP Registers. */ | |
5287ad62 JB |
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), | |
c19d1205 ZW |
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), | |
cd2cf30b PB |
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), | |
40c7d507 | 23882 | REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC), |
ba6cd17f SD |
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), | |
c19d1205 ZW |
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), | |
0264bf6f AC |
23917 | |
23918 | /* Alias 'ra_auth_code' to r12 for pacbti. */ | |
23919 | REGDEF(ra_auth_code,12,RN), | |
c19d1205 ZW |
23920 | }; |
23921 | #undef REGDEF | |
23922 | #undef REGNUM | |
23923 | #undef REGSET | |
7ed4c4c5 | 23924 | |
c19d1205 ZW |
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}, | |
59b42a0d | 23940 | |
c19d1205 ZW |
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 | ||
62b3e311 PB |
24004 | /* Table of V7M psr names. */ |
24005 | static const struct asm_psr v7m_psrs[] = | |
24006 | { | |
1a336194 TP |
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}, | |
1a336194 TP |
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 } | |
62b3e311 PB |
24033 | }; |
24034 | ||
c19d1205 ZW |
24035 | /* Table of all shift-in-operand names. */ |
24036 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 24037 | { |
c19d1205 ZW |
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 }, | |
f5f10c66 AV |
24043 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }, |
24044 | { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW} | |
c19d1205 | 24045 | }; |
b99bd4ef | 24046 | |
c19d1205 ZW |
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}, | |
b43420e6 | 24061 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
24062 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
24063 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
477330fc | 24064 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, |
0855e32b | 24065 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, |
477330fc | 24066 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, |
0855e32b | 24067 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, |
188fd7ae CL |
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 }, | |
5c5a4843 CL |
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 }, | |
c19d1205 ZW |
24078 | }; |
24079 | #endif | |
b99bd4ef | 24080 | |
5ee91343 | 24081 | /* Table of all conditional affixes. */ |
c19d1205 ZW |
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 | }; | |
5ee91343 AV |
24100 | static const struct asm_cond vconds[] = |
24101 | { | |
24102 | {"t", 0xf}, | |
24103 | {"e", 0x10} | |
24104 | }; | |
bfae80f2 | 24105 | |
e797f7e0 | 24106 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
823d2571 TG |
24107 | { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \ |
24108 | { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) } | |
e797f7e0 | 24109 | |
62b3e311 PB |
24110 | static struct asm_barrier_opt barrier_opt_names[] = |
24111 | { | |
e797f7e0 MGD |
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) | |
62b3e311 PB |
24128 | }; |
24129 | ||
e797f7e0 MGD |
24130 | #undef UL_BARRIER |
24131 | ||
c19d1205 ZW |
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 | ||
5be8be5d DG |
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 | ||
c19d1205 ZW |
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) \ | |
21d799b5 | 24162 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
5ee91343 | 24163 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 ZW |
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) \ | |
e07e6e58 | 24168 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 24169 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 24170 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
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) \ | |
21d799b5 | 24175 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
5ee91343 | 24176 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
088fa78e | 24177 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 24178 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
5ee91343 | 24179 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 | 24180 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 24181 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 24182 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 24183 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 24184 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 24185 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 24186 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 24187 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 24188 | |
c19d1205 | 24189 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
24190 | field is still 0xE. Many of the Thumb variants can be executed |
24191 | conditionally, so this is checked separately. */ | |
c19d1205 | 24192 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 24193 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
5ee91343 | 24194 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 | 24195 | |
dd5181d5 KT |
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, \ | |
5ee91343 | 24201 | THUMB_VARIANT, do_##en, do_##en, 0 } |
dd5181d5 | 24202 | |
c19d1205 ZW |
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) \ | |
21d799b5 | 24206 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
5ee91343 | 24207 | THUMB_VARIANT, do_##ae, do_##te, 0 } |
c19d1205 ZW |
24208 | |
24209 | /* ARM-only variants of all the above. */ | |
6a86118a | 24210 | #define CE(mnem, op, nops, ops, ae) \ |
5ee91343 | 24211 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a NC |
24212 | |
24213 | #define C3(mnem, op, nops, ops, ae) \ | |
5ee91343 | 24214 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a | 24215 | |
cf3cf39d TP |
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, \ | |
5ee91343 | 24219 | do_##te, 0 } |
cf3cf39d TP |
24220 | |
24221 | #define ToU(mnem, top, nops, ops, te) \ | |
24222 | { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \ | |
5ee91343 | 24223 | NULL, do_##te, 0 } |
cf3cf39d | 24224 | |
4389b29a AV |
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, \ | |
5ee91343 | 24228 | do_##te, 0 } |
4389b29a | 24229 | |
f6b2b12d AV |
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, \ | |
5ee91343 | 24233 | NULL, do_##te, 0 } |
f6b2b12d | 24234 | |
e3cb604e PB |
24235 | /* Legacy mnemonics that always have conditional infix after the third |
24236 | character. */ | |
24237 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 24238 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
5ee91343 | 24239 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
e3cb604e | 24240 | |
8f06b2d8 PB |
24241 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
24242 | #define cCE(mnem, op, nops, ops, ae) \ | |
5ee91343 | 24243 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 } |
8f06b2d8 | 24244 | |
57785aa2 AV |
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 | ||
e3cb604e PB |
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) \ | |
21d799b5 | 24253 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
5ee91343 | 24254 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 } |
e3cb604e PB |
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) \ | |
21d799b5 | 24259 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
5ee91343 | 24260 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 } |
8f06b2d8 | 24261 | |
6a86118a | 24262 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
24263 | { m1 #m2 m3, OPS##nops ops, \ |
24264 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
5ee91343 | 24265 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a NC |
24266 | |
24267 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
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) | |
6a86118a NC |
24287 | |
24288 | #define UE(mnem, op, nops, ops, ae) \ | |
5ee91343 | 24289 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a NC |
24290 | |
24291 | #define UF(mnem, op, nops, ops, ae) \ | |
5ee91343 | 24292 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 } |
6a86118a | 24293 | |
5287ad62 JB |
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, \ | |
5ee91343 | 24299 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 } |
5287ad62 JB |
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) \ | |
21d799b5 | 24304 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5ee91343 | 24305 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 } |
5287ad62 JB |
24306 | |
24307 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
24308 | version. */ | |
5ee91343 | 24309 | #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \ |
037e8744 | 24310 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ |
5ee91343 | 24311 | THUMB_VARIANT, do_##enc, do_##enc, mve_p } |
5287ad62 | 24312 | |
037e8744 | 24313 | #define NCE(mnem, op, nops, ops, enc) \ |
5ee91343 | 24314 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0) |
037e8744 JB |
24315 | |
24316 | #define NCEF(mnem, op, nops, ops, enc) \ | |
5ee91343 | 24317 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0) |
037e8744 | 24318 | |
5287ad62 | 24319 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
5ee91343 | 24320 | #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \ |
21d799b5 | 24321 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5ee91343 | 24322 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p } |
5287ad62 | 24323 | |
037e8744 | 24324 | #define nCE(mnem, op, nops, ops, enc) \ |
5ee91343 | 24325 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0) |
037e8744 JB |
24326 | |
24327 | #define nCEF(mnem, op, nops, ops, enc) \ | |
5ee91343 AV |
24328 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0) |
24329 | ||
24330 | /* */ | |
24331 | #define mCEF(mnem, op, nops, ops, enc) \ | |
a302e574 | 24332 | { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \ |
5ee91343 AV |
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) | |
037e8744 | 24343 | |
5ee91343 AV |
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) | |
c19d1205 ZW |
24366 | #define do_0 0 |
24367 | ||
c19d1205 | 24368 | static const struct asm_opcode insns[] = |
bfae80f2 | 24369 | { |
74db7efb NC |
24370 | #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */ |
24371 | #define THUMB_VARIANT & arm_ext_v4t | |
21d799b5 NC |
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), | |
c19d1205 ZW |
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. */ | |
21d799b5 NC |
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), | |
72d98d16 | 24403 | tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp), |
21d799b5 NC |
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), | |
5be8be5d DG |
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), | |
21d799b5 NC |
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 | ||
21d799b5 NC |
24421 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), |
24422 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 24423 | |
c19d1205 | 24424 | /* Pseudo ops. */ |
21d799b5 | 24425 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 24426 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 24427 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
74db7efb | 24428 | tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf), |
c19d1205 ZW |
24429 | |
24430 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
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), | |
c19d1205 | 24443 | |
16a4cf17 | 24444 | /* These may simplify to neg. */ |
21d799b5 NC |
24445 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
24446 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 24447 | |
173205ca TP |
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 | ||
c921be7d NC |
24454 | #undef THUMB_VARIANT |
24455 | #define THUMB_VARIANT & arm_ext_v6 | |
24456 | ||
21d799b5 | 24457 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
24458 | |
24459 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
24460 | #undef THUMB_VARIANT |
24461 | #define THUMB_VARIANT & arm_ext_v6t2 | |
24462 | ||
21d799b5 NC |
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), | |
c19d1205 | 24466 | |
5be8be5d DG |
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), | |
c19d1205 | 24471 | |
21d799b5 NC |
24472 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
24473 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 24474 | |
21d799b5 NC |
24475 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
24476 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
24477 | |
24478 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 24479 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
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 | ||
c921be7d NC |
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 | ||
21d799b5 NC |
24496 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
24497 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 24498 | |
c921be7d NC |
24499 | #undef THUMB_VARIANT |
24500 | #define THUMB_VARIANT & arm_ext_v6t2 | |
24501 | ||
21d799b5 | 24502 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
24503 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
24504 | ||
24505 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
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), | |
db472d6f | 24512 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 24513 | |
c921be7d NC |
24514 | #undef ARM_VARIANT |
24515 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
24516 | ||
21d799b5 | 24517 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
24518 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
24519 | ||
c921be7d NC |
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 | ||
d2cd1205 JB |
24525 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
24526 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 24527 | |
c921be7d NC |
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 | ||
21d799b5 NC |
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), | |
c19d1205 | 24541 | |
c921be7d NC |
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 | ||
5be8be5d DG |
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), | |
56c0a61f RE |
24551 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
24552 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 24553 | |
c921be7d NC |
24554 | #undef ARM_VARIANT |
24555 | #define ARM_VARIANT & arm_ext_v4t_5 | |
24556 | ||
c19d1205 ZW |
24557 | /* ARM Architecture 4T. */ |
24558 | /* Note: bx (and blx) are required on V5, even if the processor does | |
24559 | not support Thumb. */ | |
21d799b5 | 24560 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 24561 | |
c921be7d NC |
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 | ||
c19d1205 ZW |
24567 | /* Note: blx has 2 variants; the .value coded here is for |
24568 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
24569 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
24570 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 24571 | |
c921be7d NC |
24572 | #undef THUMB_VARIANT |
24573 | #define THUMB_VARIANT & arm_ext_v6t2 | |
24574 | ||
21d799b5 NC |
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), | |
c19d1205 | 24583 | |
c921be7d | 24584 | #undef ARM_VARIANT |
74db7efb NC |
24585 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ |
24586 | #undef THUMB_VARIANT | |
24587 | #define THUMB_VARIANT & arm_ext_v5exp | |
c921be7d | 24588 | |
21d799b5 NC |
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), | |
c19d1205 | 24593 | |
21d799b5 NC |
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), | |
c19d1205 | 24596 | |
21d799b5 NC |
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), | |
c19d1205 | 24601 | |
21d799b5 NC |
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), | |
c19d1205 | 24606 | |
21d799b5 NC |
24607 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
24608 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 24609 | |
03ee1b7f NC |
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), | |
c19d1205 | 24614 | |
c921be7d | 24615 | #undef ARM_VARIANT |
74db7efb NC |
24616 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ |
24617 | #undef THUMB_VARIANT | |
24618 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 24619 | |
21d799b5 | 24620 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
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), | |
c19d1205 | 24625 | |
21d799b5 NC |
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), | |
c19d1205 | 24628 | |
c921be7d NC |
24629 | #undef ARM_VARIANT |
24630 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
24631 | ||
21d799b5 | 24632 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 24633 | |
c921be7d NC |
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 | ||
21d799b5 NC |
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), | |
c19d1205 | 24649 | |
c921be7d | 24650 | #undef THUMB_VARIANT |
ff8646ee | 24651 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
c921be7d | 24652 | |
5be8be5d DG |
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), | |
ff8646ee TP |
24656 | #undef THUMB_VARIANT |
24657 | #define THUMB_VARIANT & arm_ext_v6t2 | |
24658 | ||
21d799b5 NC |
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), | |
62b3e311 | 24661 | |
21d799b5 NC |
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), | |
62b3e311 | 24664 | |
9e3c6df6 | 24665 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
24666 | #undef THUMB_VARIANT |
24667 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 24668 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 24669 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
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), | |
d709e4e6 RE |
24674 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
24675 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
24676 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 24677 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
24678 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
24679 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 24680 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 24681 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 24682 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 24683 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 24684 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 24685 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
941c9cad | 24686 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c921be7d | 24687 | |
9e3c6df6 PB |
24688 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
24689 | #undef THUMB_VARIANT | |
24690 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
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), | |
4f80ef3e | 24696 | /* Old name for QASX. */ |
74db7efb | 24697 | TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 24698 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 24699 | /* Old name for QSAX. */ |
74db7efb | 24700 | TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
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), | |
4f80ef3e | 24706 | /* Old name for SASX. */ |
74db7efb | 24707 | TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
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), | |
74db7efb | 24710 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 24711 | /* Old name for SHASX. */ |
21d799b5 | 24712 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
74db7efb | 24713 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 24714 | /* Old name for SHSAX. */ |
21d799b5 NC |
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), | |
4f80ef3e | 24719 | /* Old name for SSAX. */ |
74db7efb | 24720 | TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
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), | |
4f80ef3e | 24726 | /* Old name for UASX. */ |
74db7efb | 24727 | TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
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), | |
74db7efb | 24730 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 24731 | /* Old name for UHASX. */ |
21d799b5 NC |
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), | |
4f80ef3e | 24734 | /* Old name for UHSAX. */ |
21d799b5 NC |
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), | |
74db7efb | 24740 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 24741 | /* Old name for UQASX. */ |
21d799b5 NC |
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), | |
4f80ef3e | 24744 | /* Old name for UQSAX. */ |
21d799b5 NC |
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), | |
4f80ef3e | 24750 | /* Old name for USAX. */ |
74db7efb | 24751 | TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 24752 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
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), | |
21d799b5 NC |
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), | |
c19d1205 | 24785 | |
c921be7d | 24786 | #undef ARM_VARIANT |
55e8aae7 | 24787 | #define ARM_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 24788 | #undef THUMB_VARIANT |
55e8aae7 | 24789 | #define THUMB_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 24790 | |
21d799b5 NC |
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), | |
c19d1205 | 24795 | |
c921be7d NC |
24796 | #undef THUMB_VARIANT |
24797 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
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), | |
ebdca51a | 24802 | |
c921be7d | 24803 | #undef THUMB_VARIANT |
ff8646ee | 24804 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
5be8be5d DG |
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), | |
877807f8 | 24810 | strex, t_strexbh), |
5be8be5d | 24811 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 24812 | strex, t_strexbh), |
21d799b5 | 24813 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 24814 | |
c921be7d | 24815 | #undef ARM_VARIANT |
f4c65163 | 24816 | #define ARM_VARIANT & arm_ext_sec |
74db7efb | 24817 | #undef THUMB_VARIANT |
f4c65163 | 24818 | #define THUMB_VARIANT & arm_ext_sec |
c921be7d | 24819 | |
21d799b5 | 24820 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 24821 | |
90ec0d68 MGD |
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 | ||
ddfded2f MW |
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 | ||
c921be7d | 24837 | #undef ARM_VARIANT |
74db7efb | 24838 | #define ARM_VARIANT & arm_ext_v6t2 |
f4c65163 MGD |
24839 | #undef THUMB_VARIANT |
24840 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 24841 | |
21d799b5 NC |
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), | |
c19d1205 | 24846 | |
21d799b5 | 24847 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
21d799b5 | 24848 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 | 24849 | |
5be8be5d DG |
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), | |
c19d1205 | 24854 | |
91d8b670 JG |
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), | |
c597cc3d SD |
24861 | TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb), |
24862 | TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb), | |
91d8b670 JG |
24863 | |
24864 | #undef ARM_VARIANT | |
24865 | #define ARM_VARIANT & arm_ext_v6t2 | |
ff8646ee TP |
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 | ||
bf3eeda7 | 24871 | /* Thumb-only instructions. */ |
74db7efb | 24872 | #undef ARM_VARIANT |
bf3eeda7 NS |
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), | |
c921be7d NC |
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 | |
ff8646ee TP |
24882 | #undef THUMB_VARIANT |
24883 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 24884 | |
21d799b5 NC |
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), | |
1c444d06 | 24900 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
24901 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
24902 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 24903 | |
92e90b6e | 24904 | /* Thumb2 only instructions. */ |
c921be7d NC |
24905 | #undef ARM_VARIANT |
24906 | #define ARM_VARIANT NULL | |
92e90b6e | 24907 | |
21d799b5 NC |
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), | |
92e90b6e | 24914 | |
eea54501 MGD |
24915 | /* Hardware division instructions. */ |
24916 | #undef ARM_VARIANT | |
24917 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
24918 | #undef THUMB_VARIANT |
24919 | #define THUMB_VARIANT & arm_ext_div | |
24920 | ||
eea54501 MGD |
24921 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
24922 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 24923 | |
7e806470 | 24924 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
24925 | #undef ARM_VARIANT |
24926 | #define ARM_VARIANT & arm_ext_barrier | |
24927 | #undef THUMB_VARIANT | |
24928 | #define THUMB_VARIANT & arm_ext_barrier | |
24929 | ||
ccb84d65 JB |
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), | |
7e806470 | 24933 | |
62b3e311 | 24934 | /* ARM V7 instructions. */ |
c921be7d NC |
24935 | #undef ARM_VARIANT |
24936 | #define ARM_VARIANT & arm_ext_v7 | |
24937 | #undef THUMB_VARIANT | |
24938 | #define THUMB_VARIANT & arm_ext_v7 | |
24939 | ||
21d799b5 NC |
24940 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
24941 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 24942 | |
74db7efb | 24943 | #undef ARM_VARIANT |
60e5ef9f | 24944 | #define ARM_VARIANT & arm_ext_mp |
74db7efb | 24945 | #undef THUMB_VARIANT |
60e5ef9f MGD |
24946 | #define THUMB_VARIANT & arm_ext_mp |
24947 | ||
24948 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
24949 | ||
53c4b28b MGD |
24950 | /* AArchv8 instructions. */ |
24951 | #undef ARM_VARIANT | |
24952 | #define ARM_VARIANT & arm_ext_v8 | |
4ed7ed8d TP |
24953 | |
24954 | /* Instructions shared between armv8-a and armv8-m. */ | |
53c4b28b | 24955 | #undef THUMB_VARIANT |
4ed7ed8d | 24956 | #define THUMB_VARIANT & arm_ext_atomics |
53c4b28b | 24957 | |
4ed7ed8d TP |
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), | |
4b8c8c02 | 24964 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
4b8c8c02 RE |
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), | |
4b8c8c02 RE |
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), | |
4ed7ed8d TP |
24973 | #undef THUMB_VARIANT |
24974 | #define THUMB_VARIANT & arm_ext_v8 | |
53c4b28b | 24975 | |
4ed7ed8d | 24976 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), |
4ed7ed8d TP |
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), | |
26417f19 AC |
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), | |
f7dd2fb2 TC |
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 | ||
8884b720 | 25000 | /* ARMv8 T32 only. */ |
74db7efb | 25001 | #undef ARM_VARIANT |
b79f7053 MGD |
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 | ||
33399f07 MGD |
25007 | /* FP for ARMv8. */ |
25008 | #undef ARM_VARIANT | |
a715796b | 25009 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 | 25010 | #undef THUMB_VARIANT |
a715796b | 25011 | #define THUMB_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 MGD |
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), | |
30bdf752 | 25017 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
a710b305 AV |
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), | |
33399f07 | 25024 | |
91ff7894 MGD |
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), | |
48adcd8e MGD |
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), | |
3c9017d2 MGD |
25042 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
25043 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
25044 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 25045 | |
dd5181d5 | 25046 | #undef ARM_VARIANT |
8b301fbb | 25047 | #define ARM_VARIANT & arm_ext_crc |
dd5181d5 | 25048 | #undef THUMB_VARIANT |
8b301fbb | 25049 | #define THUMB_VARIANT & arm_ext_crc |
dd5181d5 KT |
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 | ||
105bde57 MW |
25057 | /* ARMv8.2 RAS extension. */ |
25058 | #undef ARM_VARIANT | |
4d1464f2 | 25059 | #define ARM_VARIANT & arm_ext_ras |
105bde57 | 25060 | #undef THUMB_VARIANT |
4d1464f2 | 25061 | #define THUMB_VARIANT & arm_ext_ras |
105bde57 MW |
25062 | TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs), |
25063 | ||
49e8a725 SN |
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 | ||
c604a79a JW |
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 | ||
c921be7d NC |
25077 | #undef ARM_VARIANT |
25078 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
25079 | #undef THUMB_VARIANT |
25080 | #define THUMB_VARIANT NULL | |
c921be7d | 25081 | |
21d799b5 NC |
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), | |
b99bd4ef | 25491 | |
c19d1205 ZW |
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. */ | |
21d799b5 NC |
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), | |
bfae80f2 | 25510 | |
c19d1205 | 25511 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
25512 | #undef ARM_VARIANT |
25513 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
25514 | ||
21d799b5 NC |
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), | |
c19d1205 | 25521 | |
c921be7d NC |
25522 | #undef ARM_VARIANT |
25523 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
ba6cd17f SD |
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), | |
ef8f595f MI |
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), | |
90e9955a SP |
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), | |
ba6cd17f | 25538 | #undef THUMB_VARIANT |
c921be7d | 25539 | |
c19d1205 | 25540 | /* Moves and type conversions. */ |
21d799b5 NC |
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), | |
c19d1205 ZW |
25550 | |
25551 | /* Memory operations. */ | |
55881a11 | 25552 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
55881a11 MGD |
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), | |
55881a11 | 25558 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
55881a11 MGD |
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), | |
bfae80f2 | 25564 | |
c19d1205 | 25565 | /* Monadic operations. */ |
21d799b5 NC |
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), | |
c19d1205 ZW |
25569 | |
25570 | /* Dyadic operations. */ | |
21d799b5 NC |
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), | |
b99bd4ef | 25580 | |
c19d1205 | 25581 | /* Comparisons. */ |
21d799b5 NC |
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), | |
b99bd4ef | 25586 | |
62f3b8c8 PB |
25587 | /* Double precision load/store are still present on single precision |
25588 | implementations. */ | |
55881a11 MGD |
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), | |
62f3b8c8 | 25597 | |
c921be7d NC |
25598 | #undef ARM_VARIANT |
25599 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
25600 | ||
c19d1205 | 25601 | /* Moves and type conversions. */ |
21d799b5 NC |
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), | |
c19d1205 | 25614 | |
c19d1205 | 25615 | /* Monadic operations. */ |
21d799b5 NC |
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), | |
c19d1205 ZW |
25619 | |
25620 | /* Dyadic operations. */ | |
21d799b5 NC |
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), | |
b99bd4ef | 25630 | |
c19d1205 | 25631 | /* Comparisons. */ |
21d799b5 NC |
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), | |
c19d1205 | 25636 | |
037e8744 JB |
25637 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
25638 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
25639 | #undef ARM_VARIANT |
25640 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
ef8f595f MI |
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 | ||
c921be7d NC |
25654 | #undef THUMB_VARIANT |
25655 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
25656 | ||
037e8744 JB |
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), | |
21d799b5 NC |
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), | |
037e8744 JB |
25663 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), |
25664 | ||
25665 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 | 25666 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), |
037e8744 | 25667 | |
dd9634d9 | 25668 | mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt), |
e3e535bc | 25669 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
dd9634d9 AV |
25670 | MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb), |
25671 | MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt), | |
f31fef98 | 25672 | |
037e8744 JB |
25673 | |
25674 | /* NOTE: All VMOV encoding is special-cased! */ | |
037e8744 JB |
25675 | NCE(vmovq, 0, 1, (VMOV), neon_mov), |
25676 | ||
32c36c3c AV |
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 | ||
9db2f6b4 RL |
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 | ||
dec41383 | 25695 | /* New backported fma/fms instructions optional in v8.2. */ |
aab2c27d MM |
25696 | NUF (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl), |
25697 | NUF (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal), | |
dec41383 | 25698 | |
c921be7d NC |
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 | ||
5287ad62 JB |
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), | |
5287ad62 | 25708 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), |
5287ad62 | 25709 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), |
5287ad62 JB |
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. */ | |
5287ad62 | 25712 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), |
5287ad62 | 25713 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), |
627907b7 | 25714 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), |
627907b7 | 25715 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), |
5287ad62 | 25716 | /* If not immediate, fall back to neon_dyadic_i64_su. |
5150f0d8 AV |
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), | |
5287ad62 | 25721 | /* Logic ops, types optional & ignored. */ |
4316f0d2 | 25722 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 25723 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 25724 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 25725 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), |
4316f0d2 | 25726 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), |
5287ad62 JB |
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), | |
cc933301 | 25734 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */ |
21d799b5 | 25735 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), |
21d799b5 | 25736 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), |
21d799b5 | 25737 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), |
5287ad62 JB |
25738 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
25739 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
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), | |
428e3f1f | 25748 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
25749 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
25750 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 25751 | /* As above, D registers only. */ |
21d799b5 NC |
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), | |
5287ad62 | 25754 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
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), | |
5287ad62 | 25758 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
25759 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
25760 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
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. */ | |
21d799b5 | 25765 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 25766 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 | 25767 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), |
21d799b5 | 25768 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), |
5287ad62 JB |
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), | |
92559b5b PB |
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), | |
5287ad62 JB |
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), | |
d6b4b13e | 25781 | /* ARM v8.1 extension. */ |
643afb90 MW |
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), | |
5287ad62 JB |
25785 | |
25786 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 25787 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
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. */ | |
5287ad62 | 25793 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), |
5287ad62 JB |
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. */ | |
5287ad62 | 25800 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), |
5287ad62 JB |
25801 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), |
25802 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
5287ad62 JB |
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. */ | |
21d799b5 | 25815 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 25816 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 25817 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 25818 | |
4316f0d2 | 25819 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), |
5287ad62 JB |
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), | |
5287ad62 JB |
25824 | /* If not scalar, fall back to neon_dyadic_long. |
25825 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
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), | |
5287ad62 JB |
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. */ | |
21d799b5 NC |
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), | |
5287ad62 JB |
25840 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
25841 | S16 S32 U16 U32. */ | |
21d799b5 | 25842 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
25843 | |
25844 | /* Extract. Size 8. */ | |
3b8d421e PB |
25845 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
25846 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
25847 | |
25848 | /* Two registers, miscellaneous. */ | |
25849 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
5287ad62 | 25850 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), |
5287ad62 | 25851 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), |
5287ad62 JB |
25852 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), |
25853 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 | 25854 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), |
5287ad62 JB |
25855 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
25856 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
25857 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 25858 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 25859 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 25860 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 25861 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 25862 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
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. */ | |
5287ad62 | 25869 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), |
5287ad62 JB |
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), | |
cc933301 | 25876 | /* Reciprocal estimates. Types U32 F16 F32. */ |
5287ad62 JB |
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. */ | |
5287ad62 JB |
25882 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), |
25883 | /* VCLZ. Types I8 I16 I32. */ | |
5287ad62 JB |
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. */ | |
21d799b5 NC |
25892 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
25893 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
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 | ||
c921be7d NC |
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 | ||
5287ad62 | 25904 | /* Neon element/structure load/store. */ |
21d799b5 NC |
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), | |
5287ad62 | 25913 | |
c921be7d | 25914 | #undef THUMB_VARIANT |
74db7efb NC |
25915 | #define THUMB_VARIANT & fpu_vfp_ext_v3xd |
25916 | #undef ARM_VARIANT | |
25917 | #define ARM_VARIANT & fpu_vfp_ext_v3xd | |
62f3b8c8 PB |
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 | ||
74db7efb | 25928 | #undef THUMB_VARIANT |
c921be7d NC |
25929 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
25930 | #undef ARM_VARIANT | |
25931 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
25932 | ||
21d799b5 | 25933 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 25934 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25935 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 25936 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25937 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 25938 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25939 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 25940 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 25941 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 25942 | |
74db7efb NC |
25943 | #undef ARM_VARIANT |
25944 | #define ARM_VARIANT & fpu_vfp_ext_fma | |
25945 | #undef THUMB_VARIANT | |
25946 | #define THUMB_VARIANT & fpu_vfp_ext_fma | |
aab2c27d | 25947 | /* Mnemonics shared by Neon, VFP, MVE and BF16. These are included in the |
62f3b8c8 PB |
25948 | VFP FMA variant; NEON and VFP FMA always includes the NEON |
25949 | FMA instructions. */ | |
d58196e0 | 25950 | mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac), |
aab2c27d | 25951 | TUF ("vfmat", c300850, fc300850, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), mve_vfma, mve_vfma), |
d58196e0 AV |
25952 | mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac), |
25953 | ||
62f3b8c8 PB |
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 | ||
5287ad62 | 25963 | #undef THUMB_VARIANT |
c921be7d NC |
25964 | #undef ARM_VARIANT |
25965 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
25966 | ||
21d799b5 NC |
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), | |
c19d1205 | 25975 | |
c921be7d NC |
25976 | #undef ARM_VARIANT |
25977 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
25978 | ||
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
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), | |
c19d1205 | 26141 | |
c921be7d NC |
26142 | #undef ARM_VARIANT |
26143 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
26144 | ||
21d799b5 NC |
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), | |
2d447fca | 26202 | |
c921be7d NC |
26203 | #undef ARM_VARIANT |
26204 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
26205 | ||
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
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), | |
74db7efb NC |
26234 | cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc), |
26235 | cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd), | |
21d799b5 NC |
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), | |
74db7efb NC |
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), | |
21d799b5 NC |
26246 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), |
26247 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
74db7efb NC |
26248 | cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple), |
26249 | cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
21d799b5 NC |
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), | |
74db7efb NC |
26278 | cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), |
26279 | cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
21d799b5 NC |
26280 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), |
26281 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
4ed7ed8d | 26282 | |
7fadb25d SD |
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 | ||
dad0c3bf SD |
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 | ||
16a1fa25 | 26298 | /* ARMv8-M instructions. */ |
4ed7ed8d TP |
26299 | #undef ARM_VARIANT |
26300 | #define ARM_VARIANT NULL | |
26301 | #undef THUMB_VARIANT | |
26302 | #define THUMB_VARIANT & arm_ext_v8m | |
cf3cf39d TP |
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), | |
16a1fa25 TP |
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 | |
cf3cf39d TP |
26315 | ToC("vlldm", ec300a00, 1, (RRnpc), rn), |
26316 | ToC("vlstm", ec200a00, 1, (RRnpc), rn), | |
4389b29a AV |
26317 | |
26318 | /* Armv8.1-M Mainline instructions. */ | |
26319 | #undef THUMB_VARIANT | |
26320 | #define THUMB_VARIANT & arm_ext_v8_1m_main | |
e43ca2cb | 26321 | toU("aut", _aut, 3, (R12, LR, SP), t_pacbti), |
be05908c | 26322 | toU("autg", _autg, 3, (RR, RR, RR), t_pacbti_nonop), |
3751264c | 26323 | ToU("bti", f3af800f, 0, (), noargs), |
e07352fa | 26324 | toU("bxaut", _bxaut, 3, (RR, RR, RR), t_pacbti_nonop), |
ce537a7d | 26325 | toU("pac", _pac, 3, (R12, LR, SP), t_pacbti), |
f1e1d7f3 | 26326 | toU("pacbti", _pacbti, 3, (R12, LR, SP), t_pacbti), |
5c43020d | 26327 | toU("pacg", _pacg, 3, (RR, RR, RR), t_pacbti_pacg), |
e39c1607 SD |
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 | ||
4389b29a | 26338 | toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future), |
f6b2b12d | 26339 | toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future), |
f1c7f421 | 26340 | toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future), |
65d1bc05 | 26341 | toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future), |
f1c7f421 | 26342 | toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future), |
60f993ce AV |
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), | |
4b5a202f | 26347 | |
efd6b359 | 26348 | ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm), |
5ee91343 AV |
26349 | ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm), |
26350 | ||
26351 | #undef THUMB_VARIANT | |
26352 | #define THUMB_VARIANT & mve_ext | |
23d00a41 SD |
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), | |
08132bdd SP |
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), | |
23d00a41 SD |
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), | |
1b883319 AV |
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 | ||
5ee91343 AV |
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 | ||
a302e574 | 26401 | /* MVE and MVE FP only. */ |
7df54120 | 26402 | mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd), |
efd0b310 | 26403 | mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp), |
c2dafc2a AV |
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), | |
886e1c73 | 26408 | mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull), |
a302e574 AV |
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 | ||
35c228db AV |
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), | |
f5f10c66 AV |
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), | |
35c228db | 26441 | |
57785aa2 AV |
26442 | mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn), |
26443 | mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn), | |
c2dafc2a | 26444 | mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr), |
26c1e780 AV |
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), | |
b409bdb6 AV |
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), | |
935295b5 AV |
26453 | mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina), |
26454 | mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina), | |
13ccd4c0 AV |
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), | |
57785aa2 | 26459 | |
93925576 AV |
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 | ||
2d78f95b AV |
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), | |
3063888e AV |
26484 | mToC("vpnot", fe310f4d, 0, (), mve_vpnot), |
26485 | mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel), | |
2d78f95b | 26486 | |
8b8b22a4 AV |
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), | |
42b16635 AV |
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), | |
35d1cfc2 AV |
26498 | mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull), |
26499 | mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull), | |
1be7aba3 AV |
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), | |
8b8b22a4 | 26504 | |
4aa88b50 AV |
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 | ||
acca5630 AV |
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 | ||
1f6234a3 AV |
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 | ||
5d281bf0 AV |
26527 | #undef THUMB_VARIANT |
26528 | #define THUMB_VARIANT & mve_fp_ext | |
26529 | mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul), | |
f30ee27c | 26530 | mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas), |
935295b5 AV |
26531 | mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma), |
26532 | mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma), | |
8cd78170 AV |
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), | |
5d281bf0 | 26537 | |
5ee91343 | 26538 | #undef ARM_VARIANT |
57785aa2 | 26539 | #define ARM_VARIANT & fpu_vfp_ext_v1 |
5ee91343 AV |
26540 | #undef THUMB_VARIANT |
26541 | #define THUMB_VARIANT & arm_ext_v6t2 | |
26542 | ||
57785aa2 AV |
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 | ||
48f4d8ce AV |
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), | |
57785aa2 AV |
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 | ||
886e1c73 AV |
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), | |
5ee91343 | 26558 | |
485dee97 AV |
26559 | MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg), |
26560 | MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg), | |
26561 | ||
57785aa2 AV |
26562 | mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl), |
26563 | mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl), | |
26564 | ||
1b883319 AV |
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 | ||
57785aa2 AV |
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 | ||
dd9634d9 AV |
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), | |
935295b5 AV |
26582 | mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm), |
26583 | mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm), | |
dd9634d9 AV |
26584 | |
26585 | #undef ARM_VARIANT | |
5ee91343 | 26586 | #define ARM_VARIANT & fpu_neon_ext_v1 |
f601a00c | 26587 | mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su), |
5ee91343 | 26588 | mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long), |
66d1f7cc AV |
26589 | mnUF(vaddl, _vaddl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long), |
26590 | mnUF(vsubl, _vsubl, 3, (RNSDQMQ, oRNSDMQ, RNSDMQR), neon_dyadic_long), | |
f601a00c AV |
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), | |
f30ee27c AV |
26596 | MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls), |
26597 | MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz), | |
b409bdb6 | 26598 | mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup), |
7df54120 AV |
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), | |
935295b5 AV |
26602 | mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su), |
26603 | mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su), | |
a8465a06 AV |
26604 | MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su), |
26605 | MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su), | |
1a186d29 AV |
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), | |
42b16635 AV |
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), | |
1be7aba3 AV |
26612 | MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl), |
26613 | MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl), | |
4401c241 AV |
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), | |
5150f0d8 AV |
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), | |
5d281bf0 AV |
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), | |
aab2c27d MM |
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), | |
616ce08e | 26646 | TUF ("vusmmla", ca00c40, fca00c40, 3, (RNQ, RNQ, RNQ), vsmmla, vsmmla), |
aab2c27d MM |
26647 | TUF ("vusdot", c800d00, fc800d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), vusdot, vusdot), |
26648 | TUF ("vsudot", c800d10, fc800d10, 3, (RNDQ, RNDQ, RNSC), vsudot, vsudot), | |
4934a27c MM |
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), | |
5aae9ae9 MM |
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), | |
c19d1205 | 26676 | }; |
5aae9ae9 | 26677 | |
c19d1205 ZW |
26678 | #undef ARM_VARIANT |
26679 | #undef THUMB_VARIANT | |
26680 | #undef TCE | |
c19d1205 ZW |
26681 | #undef TUE |
26682 | #undef TUF | |
26683 | #undef TCC | |
8f06b2d8 | 26684 | #undef cCE |
e3cb604e PB |
26685 | #undef cCL |
26686 | #undef C3E | |
4389b29a | 26687 | #undef C3 |
c19d1205 ZW |
26688 | #undef CE |
26689 | #undef CM | |
4389b29a | 26690 | #undef CL |
c19d1205 ZW |
26691 | #undef UE |
26692 | #undef UF | |
26693 | #undef UT | |
5287ad62 JB |
26694 | #undef NUF |
26695 | #undef nUF | |
26696 | #undef NCE | |
26697 | #undef nCE | |
c19d1205 ZW |
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 | |
4389b29a AV |
26706 | #undef ToC |
26707 | #undef toC | |
26708 | #undef ToU | |
f6b2b12d | 26709 | #undef toU |
c19d1205 ZW |
26710 | \f |
26711 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 26712 | |
c19d1205 ZW |
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). */ | |
b99bd4ef | 26719 | |
c19d1205 ZW |
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); | |
bfae80f2 RE |
26727 | } |
26728 | ||
c19d1205 ZW |
26729 | static valueT |
26730 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 26731 | { |
c19d1205 ZW |
26732 | valueT result = 0; |
26733 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 26734 | |
c19d1205 | 26735 | if (target_big_endian) |
b99bd4ef | 26736 | { |
c19d1205 ZW |
26737 | while (n--) |
26738 | { | |
26739 | result <<= 8; | |
26740 | result |= (*where++ & 255); | |
26741 | } | |
b99bd4ef | 26742 | } |
c19d1205 | 26743 | else |
b99bd4ef | 26744 | { |
c19d1205 ZW |
26745 | while (n--) |
26746 | { | |
26747 | result <<= 8; | |
26748 | result |= (where[n] & 255); | |
26749 | } | |
bfae80f2 | 26750 | } |
b99bd4ef | 26751 | |
c19d1205 | 26752 | return result; |
bfae80f2 | 26753 | } |
b99bd4ef | 26754 | |
c19d1205 | 26755 | /* MD interface: Sections. */ |
b99bd4ef | 26756 | |
fa94de6b RM |
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 | ||
0110f2b8 PB |
26777 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
26778 | 2 bytes. */ | |
26779 | ||
c19d1205 | 26780 | int |
0110f2b8 | 26781 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
26782 | segT segtype ATTRIBUTE_UNUSED) |
26783 | { | |
0110f2b8 PB |
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); | |
5f4273c7 NC |
26805 | if (fragp->fr_symbol) |
26806 | { | |
0110f2b8 PB |
26807 | exp.X_op = O_symbol; |
26808 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
26809 | } |
26810 | else | |
26811 | { | |
0110f2b8 | 26812 | exp.X_op = O_constant; |
5f4273c7 | 26813 | } |
0110f2b8 PB |
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 | { | |
5f4273c7 | 26830 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
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: | |
d3e52e12 TC |
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 | ||
0110f2b8 PB |
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); | |
16805f35 PB |
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; | |
0110f2b8 PB |
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); | |
16805f35 PB |
26946 | if (insn & (1 << 20)) |
26947 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
26948 | else | |
26949 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
26950 | } |
26951 | else | |
26952 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
26953 | pc_rel = 0; | |
26954 | break; | |
26955 | default: | |
5f4273c7 | 26956 | abort (); |
0110f2b8 PB |
26957 | } |
26958 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 26959 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
26960 | fixp->fx_file = fragp->fr_file; |
26961 | fixp->fx_line = fragp->fr_line; | |
26962 | fragp->fr_fix += fragp->fr_var; | |
3cfdb781 TG |
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); | |
0110f2b8 PB |
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) | |
5e77afaa | 26988 | return 4; |
0110f2b8 PB |
26989 | if (offset & ~mask) |
26990 | return 4; | |
26991 | return 2; | |
26992 | } | |
26993 | ||
5e77afaa PB |
26994 | /* Get the address of a symbol during relaxation. */ |
26995 | static addressT | |
5f4273c7 | 26996 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
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) | |
4396b686 PB |
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 | } | |
5e77afaa PB |
27040 | |
27041 | return addr; | |
27042 | } | |
27043 | ||
0110f2b8 PB |
27044 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
27045 | load. */ | |
27046 | static int | |
5e77afaa | 27047 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
27048 | { |
27049 | addressT addr; | |
27050 | offsetT val; | |
27051 | ||
27052 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
27053 | if (fragp->fr_symbol == NULL |
27054 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e | 27055 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
d3e52e12 TC |
27056 | || S_IS_WEAK (fragp->fr_symbol) |
27057 | || THUMB_IS_FUNC (fragp->fr_symbol)) | |
0110f2b8 PB |
27058 | return 4; |
27059 | ||
5f4273c7 | 27060 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
27061 | addr = fragp->fr_address + fragp->fr_fix; |
27062 | addr = (addr + 4) & ~3; | |
5e77afaa | 27063 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 27064 | if (val & 3) |
5e77afaa | 27065 | return 4; |
0110f2b8 PB |
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 | ||
e83a675f RE |
27087 | /* Return TRUE iff the definition of symbol S could be pre-empted |
27088 | (overridden) at link or load time. */ | |
5b7c81bd | 27089 | static bool |
e83a675f RE |
27090 | symbol_preemptible (symbolS *s) |
27091 | { | |
27092 | /* Weak symbols can always be pre-empted. */ | |
27093 | if (S_IS_WEAK (s)) | |
5b7c81bd | 27094 | return true; |
e83a675f RE |
27095 | |
27096 | /* Non-global symbols cannot be pre-empted. */ | |
27097 | if (! S_IS_EXTERNAL (s)) | |
5b7c81bd | 27098 | return false; |
e83a675f RE |
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) | |
5b7c81bd | 27105 | return false; |
e83a675f RE |
27106 | #endif |
27107 | ||
27108 | /* Other global symbols might be pre-empted. */ | |
5b7c81bd | 27109 | return true; |
e83a675f | 27110 | } |
0110f2b8 PB |
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 | |
5e77afaa | 27116 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
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. */ | |
5f4273c7 | 27123 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
27124 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
27125 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
27126 | return 4; |
27127 | ||
267bf995 | 27128 | #ifdef OBJ_ELF |
e83a675f | 27129 | /* A branch to a function in ARM state will require interworking. */ |
267bf995 RR |
27130 | if (S_IS_DEFINED (fragp->fr_symbol) |
27131 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
27132 | return 4; | |
e83a675f | 27133 | #endif |
0d9b4b55 | 27134 | |
e83a675f | 27135 | if (symbol_preemptible (fragp->fr_symbol)) |
0d9b4b55 | 27136 | return 4; |
267bf995 | 27137 | |
5f4273c7 | 27138 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
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 | |
5e77afaa | 27154 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
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: | |
5f4273c7 | 27163 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
27164 | break; |
27165 | case T_MNEM_ldr_pc: | |
27166 | case T_MNEM_ldr_sp: | |
27167 | case T_MNEM_str_sp: | |
5f4273c7 | 27168 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
27169 | break; |
27170 | case T_MNEM_ldr: | |
27171 | case T_MNEM_str: | |
5f4273c7 | 27172 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
27173 | break; |
27174 | case T_MNEM_ldrh: | |
27175 | case T_MNEM_strh: | |
5f4273c7 | 27176 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
27177 | break; |
27178 | case T_MNEM_ldrb: | |
27179 | case T_MNEM_strb: | |
5f4273c7 | 27180 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
27181 | break; |
27182 | case T_MNEM_adr: | |
5f4273c7 | 27183 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
27184 | break; |
27185 | case T_MNEM_mov: | |
27186 | case T_MNEM_movs: | |
27187 | case T_MNEM_cmp: | |
27188 | case T_MNEM_cmn: | |
5f4273c7 | 27189 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
27190 | break; |
27191 | case T_MNEM_b: | |
5f4273c7 | 27192 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
27193 | break; |
27194 | case T_MNEM_bcond: | |
5f4273c7 | 27195 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
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: | |
5f4273c7 | 27212 | abort (); |
0110f2b8 | 27213 | } |
5e77afaa PB |
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. | |
5f4273c7 NC |
27218 | Don't freeze them unconditionally because targets may be artificially |
27219 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 27220 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 27221 | { |
0110f2b8 | 27222 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 27223 | frag_wane (fragp); |
0110f2b8 | 27224 | } |
5e77afaa | 27225 | |
0110f2b8 | 27226 | return newsize - oldsize; |
c19d1205 | 27227 | } |
b99bd4ef | 27228 | |
c19d1205 | 27229 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 27230 | |
c19d1205 ZW |
27231 | valueT |
27232 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
27233 | valueT size) | |
27234 | { | |
6844c0cc | 27235 | return size; |
bfae80f2 | 27236 | } |
b99bd4ef | 27237 | |
c19d1205 ZW |
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) | |
bfae80f2 | 27243 | { |
d9235011 | 27244 | static unsigned char const arm_noop[2][2][4] = |
e7495e45 NS |
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 | }; | |
d9235011 | 27255 | static unsigned char const thumb_noop[2][2][2] = |
e7495e45 NS |
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 | }; | |
d9235011 | 27266 | static unsigned char const wide_thumb_noop[2][4] = |
e7495e45 NS |
27267 | { /* Wide Thumb-2 */ |
27268 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
27269 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
27270 | }; | |
c921be7d | 27271 | |
e7495e45 | 27272 | unsigned bytes, fix, noop_size; |
c19d1205 | 27273 | char * p; |
d9235011 TS |
27274 | const unsigned char * noop; |
27275 | const unsigned char *narrow_noop = NULL; | |
cd000bff DJ |
27276 | #ifdef OBJ_ELF |
27277 | enum mstate state; | |
27278 | #endif | |
bfae80f2 | 27279 | |
c19d1205 | 27280 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
27281 | return; |
27282 | ||
c19d1205 ZW |
27283 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
27284 | p = fragP->fr_literal + fragP->fr_fix; | |
27285 | fix = 0; | |
bfae80f2 | 27286 | |
c19d1205 ZW |
27287 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
27288 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 27289 | |
cd000bff | 27290 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 27291 | |
cd000bff | 27292 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 27293 | { |
7f78eb34 JW |
27294 | if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
27295 | ? selected_cpu : arm_arch_none, arm_ext_v6t2)) | |
e7495e45 NS |
27296 | { |
27297 | narrow_noop = thumb_noop[1][target_big_endian]; | |
27298 | noop = wide_thumb_noop[target_big_endian]; | |
27299 | } | |
c19d1205 | 27300 | else |
e7495e45 NS |
27301 | noop = thumb_noop[0][target_big_endian]; |
27302 | noop_size = 2; | |
cd000bff DJ |
27303 | #ifdef OBJ_ELF |
27304 | state = MAP_THUMB; | |
27305 | #endif | |
7ed4c4c5 NC |
27306 | } |
27307 | else | |
27308 | { | |
7f78eb34 JW |
27309 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
27310 | ? selected_cpu : arm_arch_none, | |
27311 | arm_ext_v6k) != 0] | |
e7495e45 NS |
27312 | [target_big_endian]; |
27313 | noop_size = 4; | |
cd000bff DJ |
27314 | #ifdef OBJ_ELF |
27315 | state = MAP_ARM; | |
27316 | #endif | |
7ed4c4c5 | 27317 | } |
c921be7d | 27318 | |
e7495e45 | 27319 | fragP->fr_var = noop_size; |
c921be7d | 27320 | |
c19d1205 | 27321 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 27322 | { |
c19d1205 | 27323 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
27324 | #ifdef OBJ_ELF |
27325 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
27326 | #endif | |
c19d1205 ZW |
27327 | memset (p, 0, fix); |
27328 | p += fix; | |
27329 | bytes -= fix; | |
a737bd4d | 27330 | } |
a737bd4d | 27331 | |
e7495e45 NS |
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 | ||
c19d1205 | 27347 | while (bytes >= noop_size) |
a737bd4d | 27348 | { |
c19d1205 ZW |
27349 | memcpy (p, noop, noop_size); |
27350 | p += noop_size; | |
27351 | bytes -= noop_size; | |
27352 | fix += noop_size; | |
a737bd4d NC |
27353 | } |
27354 | ||
c19d1205 | 27355 | fragP->fr_fix += fix; |
a737bd4d NC |
27356 | } |
27357 | ||
c19d1205 ZW |
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) | |
bfae80f2 | 27363 | { |
c19d1205 | 27364 | char * p; |
7ed4c4c5 | 27365 | |
c19d1205 | 27366 | /* We assume that there will never be a requirement |
6ec8e702 | 27367 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 27368 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
27369 | { |
27370 | char err_msg[128]; | |
27371 | ||
fa94de6b | 27372 | sprintf (err_msg, |
477330fc RM |
27373 | _("alignments greater than %d bytes not supported in .text sections."), |
27374 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 27375 | as_fatal ("%s", err_msg); |
6ec8e702 | 27376 | } |
bfae80f2 | 27377 | |
c19d1205 ZW |
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 | } | |
bfae80f2 | 27387 | |
8dc2430f NC |
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 | |
33eaf5de | 27392 | this initialisation is performed first. */ |
bfae80f2 | 27393 | |
cd000bff DJ |
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. */ | |
2e98972e | 27399 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
27400 | } |
27401 | ||
27402 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 27403 | void |
cd000bff | 27404 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 27405 | { |
5b7c81bd | 27406 | bool frag_thumb_mode; |
b968d18a | 27407 | |
8dc2430f NC |
27408 | /* If the current ARM vs THUMB mode has not already |
27409 | been recorded into this frag then do so now. */ | |
cd000bff | 27410 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
b968d18a JW |
27411 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
27412 | ||
e8d84ca1 NC |
27413 | /* PR 21809: Do not set a mapping state for debug sections |
27414 | - it just confuses other tools. */ | |
fd361982 | 27415 | if (bfd_section_flags (now_seg) & SEC_DEBUGGING) |
e8d84ca1 NC |
27416 | return; |
27417 | ||
b968d18a | 27418 | frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED; |
cd000bff | 27419 | |
f9c1b181 RL |
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: | |
b968d18a | 27430 | mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); |
f9c1b181 RL |
27431 | break; |
27432 | default: | |
27433 | break; | |
cd000bff | 27434 | } |
bfae80f2 RE |
27435 | } |
27436 | ||
c19d1205 ZW |
27437 | /* When we change sections we need to issue a new mapping symbol. */ |
27438 | ||
27439 | void | |
27440 | arm_elf_change_section (void) | |
bfae80f2 | 27441 | { |
c19d1205 ZW |
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; | |
bfae80f2 RE |
27446 | } |
27447 | ||
c19d1205 ZW |
27448 | int |
27449 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 27450 | { |
d34049e8 | 27451 | if (len == 5 && startswith (str, "exidx")) |
c19d1205 | 27452 | return SHT_ARM_EXIDX; |
e45d0630 | 27453 | |
c19d1205 ZW |
27454 | return -1; |
27455 | } | |
27456 | \f | |
27457 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 27458 | |
c19d1205 | 27459 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 27460 | |
5f4273c7 | 27461 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 27462 | |
bfae80f2 | 27463 | static void |
c19d1205 | 27464 | flush_pending_unwind (void) |
bfae80f2 | 27465 | { |
c19d1205 | 27466 | offsetT offset; |
bfae80f2 | 27467 | |
c19d1205 ZW |
27468 | offset = unwind.pending_offset; |
27469 | unwind.pending_offset = 0; | |
27470 | if (offset != 0) | |
27471 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
27472 | } |
27473 | ||
c19d1205 ZW |
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 | ||
bfae80f2 | 27478 | static void |
c19d1205 | 27479 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 27480 | { |
c19d1205 ZW |
27481 | /* Add any deferred stack adjustment. */ |
27482 | if (unwind.pending_offset) | |
27483 | flush_pending_unwind (); | |
bfae80f2 | 27484 | |
c19d1205 | 27485 | unwind.sp_restored = 0; |
bfae80f2 | 27486 | |
c19d1205 | 27487 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 27488 | { |
c19d1205 ZW |
27489 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
27490 | if (unwind.opcodes) | |
325801bd TS |
27491 | unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes, |
27492 | unwind.opcode_alloc); | |
c19d1205 | 27493 | else |
325801bd | 27494 | unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc); |
bfae80f2 | 27495 | } |
c19d1205 | 27496 | while (length > 0) |
bfae80f2 | 27497 | { |
c19d1205 ZW |
27498 | length--; |
27499 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
27500 | op >>= 8; | |
27501 | unwind.opcode_count++; | |
bfae80f2 | 27502 | } |
bfae80f2 RE |
27503 | } |
27504 | ||
c19d1205 ZW |
27505 | /* Add unwind opcodes to adjust the stack pointer. */ |
27506 | ||
bfae80f2 | 27507 | static void |
c19d1205 | 27508 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 27509 | { |
c19d1205 | 27510 | valueT op; |
bfae80f2 | 27511 | |
c19d1205 | 27512 | if (offset > 0x200) |
bfae80f2 | 27513 | { |
c19d1205 ZW |
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; | |
bfae80f2 | 27518 | |
c19d1205 ZW |
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); | |
bfae80f2 | 27525 | |
c19d1205 ZW |
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) | |
bfae80f2 | 27542 | { |
c19d1205 ZW |
27543 | /* Two short opcodes. */ |
27544 | add_unwind_opcode (0x3f, 1); | |
27545 | op = (offset - 0x104) >> 2; | |
27546 | add_unwind_opcode (op, 1); | |
bfae80f2 | 27547 | } |
c19d1205 ZW |
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) | |
bfae80f2 | 27555 | { |
c19d1205 ZW |
27556 | offset = -offset; |
27557 | while (offset > 0x100) | |
bfae80f2 | 27558 | { |
c19d1205 ZW |
27559 | add_unwind_opcode (0x7f, 1); |
27560 | offset -= 0x100; | |
bfae80f2 | 27561 | } |
c19d1205 ZW |
27562 | op = ((offset - 4) >> 2) | 0x40; |
27563 | add_unwind_opcode (op, 1); | |
bfae80f2 | 27564 | } |
bfae80f2 RE |
27565 | } |
27566 | ||
c19d1205 | 27567 | /* Finish the list of unwind opcodes for this function. */ |
0198d5e6 | 27568 | |
c19d1205 ZW |
27569 | static void |
27570 | finish_unwind_opcodes (void) | |
bfae80f2 | 27571 | { |
c19d1205 | 27572 | valueT op; |
bfae80f2 | 27573 | |
c19d1205 | 27574 | if (unwind.fp_used) |
bfae80f2 | 27575 | { |
708587a4 | 27576 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
27577 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
27578 | flush_pending_unwind (); | |
bfae80f2 | 27579 | |
c19d1205 ZW |
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 (); | |
bfae80f2 RE |
27586 | } |
27587 | ||
bfae80f2 | 27588 | |
c19d1205 ZW |
27589 | /* Start an exception table entry. If idx is nonzero this is an index table |
27590 | entry. */ | |
bfae80f2 RE |
27591 | |
27592 | static void | |
c19d1205 | 27593 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 27594 | { |
c19d1205 ZW |
27595 | const char * text_name; |
27596 | const char * prefix; | |
27597 | const char * prefix_once; | |
a8c4d40b | 27598 | struct elf_section_match match; |
c19d1205 | 27599 | char * sec_name; |
c19d1205 ZW |
27600 | int type; |
27601 | int flags; | |
27602 | int linkonce; | |
bfae80f2 | 27603 | |
c19d1205 | 27604 | if (idx) |
bfae80f2 | 27605 | { |
c19d1205 ZW |
27606 | prefix = ELF_STRING_ARM_unwind; |
27607 | prefix_once = ELF_STRING_ARM_unwind_once; | |
27608 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 27609 | } |
c19d1205 | 27610 | else |
bfae80f2 | 27611 | { |
c19d1205 ZW |
27612 | prefix = ELF_STRING_ARM_unwind_info; |
27613 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
27614 | type = SHT_PROGBITS; | |
bfae80f2 RE |
27615 | } |
27616 | ||
c19d1205 ZW |
27617 | text_name = segment_name (text_seg); |
27618 | if (streq (text_name, ".text")) | |
27619 | text_name = ""; | |
27620 | ||
d34049e8 | 27621 | if (startswith (text_name, ".gnu.linkonce.t.")) |
bfae80f2 | 27622 | { |
c19d1205 ZW |
27623 | prefix = prefix_once; |
27624 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
27625 | } |
27626 | ||
29a2809e | 27627 | sec_name = concat (prefix, text_name, (char *) NULL); |
bfae80f2 | 27628 | |
c19d1205 ZW |
27629 | flags = SHF_ALLOC; |
27630 | linkonce = 0; | |
a8c4d40b | 27631 | memset (&match, 0, sizeof (match)); |
bfae80f2 | 27632 | |
c19d1205 ZW |
27633 | /* Handle COMDAT group. */ |
27634 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 27635 | { |
a8c4d40b L |
27636 | match.group_name = elf_group_name (text_seg); |
27637 | if (match.group_name == NULL) | |
c19d1205 | 27638 | { |
bd3ba5d1 | 27639 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
27640 | segment_name (text_seg)); |
27641 | ignore_rest_of_line (); | |
27642 | return; | |
27643 | } | |
27644 | flags |= SHF_GROUP; | |
27645 | linkonce = 1; | |
bfae80f2 RE |
27646 | } |
27647 | ||
a8c4d40b | 27648 | obj_elf_change_section (sec_name, type, flags, 0, &match, |
a91e1603 | 27649 | linkonce, 0); |
bfae80f2 | 27650 | |
5f4273c7 | 27651 | /* Set the section link for index tables. */ |
c19d1205 ZW |
27652 | if (idx) |
27653 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
27654 | } |
27655 | ||
bfae80f2 | 27656 | |
c19d1205 ZW |
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 | |
cad0da33 | 27659 | an inline entry. */ |
c19d1205 ZW |
27660 | |
27661 | static valueT | |
27662 | create_unwind_entry (int have_data) | |
bfae80f2 | 27663 | { |
c19d1205 ZW |
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; | |
bfae80f2 | 27671 | |
c19d1205 | 27672 | finish_unwind_opcodes (); |
bfae80f2 | 27673 | |
c19d1205 ZW |
27674 | /* Remember the current text section. */ |
27675 | unwind.saved_seg = now_seg; | |
27676 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 27677 | |
c19d1205 | 27678 | start_unwind_section (now_seg, 0); |
bfae80f2 | 27679 | |
c19d1205 | 27680 | if (unwind.personality_routine == NULL) |
bfae80f2 | 27681 | { |
c19d1205 ZW |
27682 | if (unwind.personality_index == -2) |
27683 | { | |
27684 | if (have_data) | |
5f4273c7 | 27685 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
27686 | return 1; /* EXIDX_CANTUNWIND. */ |
27687 | } | |
bfae80f2 | 27688 | |
c19d1205 ZW |
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 | } | |
bfae80f2 | 27697 | |
c19d1205 ZW |
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")); | |
bfae80f2 | 27703 | |
c19d1205 ZW |
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 | } | |
bfae80f2 | 27715 | |
c19d1205 ZW |
27716 | /* Pad with "finish" opcodes. */ |
27717 | while (n--) | |
27718 | data = (data << 8) | 0xb0; | |
bfae80f2 | 27719 | |
c19d1205 ZW |
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 | |
5011093d | 27729 | { |
cad0da33 NC |
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 | } | |
5011093d NC |
27736 | |
27737 | /* An extra byte is required for the opcode count. */ | |
27738 | size = unwind.opcode_count + 1; | |
27739 | } | |
bfae80f2 | 27740 | |
c19d1205 ZW |
27741 | size = (size + 3) >> 2; |
27742 | if (size > 0xff) | |
27743 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 27744 | |
c19d1205 ZW |
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); | |
74929e7b NC |
27751 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
27752 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 27753 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 27754 | |
c19d1205 | 27755 | switch (unwind.personality_index) |
bfae80f2 | 27756 | { |
c19d1205 ZW |
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); | |
bfae80f2 | 27762 | |
c19d1205 ZW |
27763 | where += 4; |
27764 | ptr += 4; | |
bfae80f2 | 27765 | |
c19d1205 | 27766 | /* Set the first byte to the number of additional words. */ |
5011093d | 27767 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
27768 | n = 3; |
27769 | break; | |
bfae80f2 | 27770 | |
c19d1205 ZW |
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; | |
bfae80f2 | 27777 | |
c19d1205 ZW |
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; | |
bfae80f2 | 27784 | |
c19d1205 ZW |
27785 | default: |
27786 | /* Should never happen. */ | |
27787 | abort (); | |
27788 | } | |
bfae80f2 | 27789 | |
c19d1205 ZW |
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; | |
bfae80f2 RE |
27824 | } |
27825 | ||
f0927246 NC |
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 | ||
c19d1205 ZW |
27836 | /* Convert REGNAME to a DWARF-2 register number. */ |
27837 | ||
27838 | int | |
1df69f4f | 27839 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 27840 | { |
1df69f4f | 27841 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
1f5afe1c NC |
27842 | if (reg != FAIL) |
27843 | return reg; | |
c19d1205 | 27844 | |
1f5afe1c NC |
27845 | /* PR 16694: Allow VFP registers as well. */ |
27846 | reg = arm_reg_parse (®name, REG_TYPE_VFS); | |
27847 | if (reg != FAIL) | |
27848 | return 64 + reg; | |
c19d1205 | 27849 | |
1f5afe1c NC |
27850 | reg = arm_reg_parse (®name, REG_TYPE_VFD); |
27851 | if (reg != FAIL) | |
27852 | return reg + 256; | |
27853 | ||
0198d5e6 | 27854 | return FAIL; |
bfae80f2 RE |
27855 | } |
27856 | ||
f0927246 | 27857 | #ifdef TE_PE |
c19d1205 | 27858 | void |
f0927246 | 27859 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 27860 | { |
91d6fa6a | 27861 | expressionS exp; |
bfae80f2 | 27862 | |
91d6fa6a NC |
27863 | exp.X_op = O_secrel; |
27864 | exp.X_add_symbol = symbol; | |
27865 | exp.X_add_number = 0; | |
27866 | emit_expr (&exp, size); | |
f0927246 NC |
27867 | } |
27868 | #endif | |
bfae80f2 | 27869 | |
c19d1205 | 27870 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 27871 | |
2fc8bdac ZW |
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. */ | |
bfae80f2 | 27877 | |
c19d1205 | 27878 | long |
2fc8bdac | 27879 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 27880 | { |
2fc8bdac ZW |
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 | |
53baae48 NC |
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. */ | |
5f4273c7 | 27888 | if (fixP->fx_pcrel |
2fc8bdac | 27889 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
27890 | || (arm_force_relocation (fixP) |
27891 | #ifdef TE_WINCE | |
27892 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
27893 | #endif | |
27894 | ))) | |
2fc8bdac | 27895 | base = 0; |
bfae80f2 | 27896 | |
267bf995 | 27897 | |
c19d1205 | 27898 | switch (fixP->fx_r_type) |
bfae80f2 | 27899 | { |
2fc8bdac ZW |
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. */ | |
c19d1205 | 27905 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 27906 | return base & ~3; |
c19d1205 ZW |
27907 | |
27908 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
27909 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 27910 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 27911 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 27912 | return (base + 4) & ~3; |
c19d1205 | 27913 | |
2fc8bdac | 27914 | /* Thumb branches are simply offset by +4. */ |
e12437dc | 27915 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
2fc8bdac ZW |
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: | |
2fc8bdac | 27920 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
f6b2b12d | 27921 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
e5d6e09e | 27922 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 27923 | case BFD_RELOC_ARM_THUMB_BF19: |
1889da70 | 27924 | case BFD_RELOC_ARM_THUMB_BF13: |
60f993ce | 27925 | case BFD_RELOC_ARM_THUMB_LOOP12: |
2fc8bdac | 27926 | return base + 4; |
bfae80f2 | 27927 | |
267bf995 | 27928 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
27929 | if (fixP->fx_addsy |
27930 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 27931 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 | 27932 | && ARM_IS_FUNC (fixP->fx_addsy) |
477330fc RM |
27933 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) |
27934 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
267bf995 RR |
27935 | return base + 4; |
27936 | ||
00adf2d4 JB |
27937 | /* BLX is like branches above, but forces the low two bits of PC to |
27938 | zero. */ | |
486499d0 CL |
27939 | case BFD_RELOC_THUMB_PCREL_BLX: |
27940 | if (fixP->fx_addsy | |
27941 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 27942 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
477330fc RM |
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; | |
00adf2d4 JB |
27946 | return (base + 4) & ~3; |
27947 | ||
2fc8bdac ZW |
27948 | /* ARM mode branches are offset by +8. However, the Windows CE |
27949 | loader expects the relocation not to take this into account. */ | |
267bf995 | 27950 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
27951 | if (fixP->fx_addsy |
27952 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 27953 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
477330fc RM |
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; | |
486499d0 | 27957 | return base + 8; |
267bf995 | 27958 | |
486499d0 CL |
27959 | case BFD_RELOC_ARM_PCREL_CALL: |
27960 | if (fixP->fx_addsy | |
27961 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 27962 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
477330fc RM |
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; | |
486499d0 | 27966 | return base + 8; |
267bf995 | 27967 | |
2fc8bdac | 27968 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 27969 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 27970 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 27971 | #ifdef TE_WINCE |
5f4273c7 | 27972 | /* When handling fixups immediately, because we have already |
477330fc | 27973 | discovered the value of a symbol, or the address of the frag involved |
53baae48 | 27974 | we must account for the offset by +8, as the OS loader will never see the reloc. |
477330fc RM |
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. */ | |
53baae48 NC |
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; | |
2fc8bdac | 27983 | return base; |
c19d1205 | 27984 | #else |
2fc8bdac | 27985 | return base + 8; |
c19d1205 | 27986 | #endif |
2fc8bdac | 27987 | |
267bf995 | 27988 | |
2fc8bdac ZW |
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 | } | |
bfae80f2 RE |
28004 | } |
28005 | ||
5b7c81bd | 28006 | static bool flag_warn_syms = true; |
8b2d793c | 28007 | |
5b7c81bd | 28008 | bool |
ae8714c2 | 28009 | arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) |
bfae80f2 | 28010 | { |
8b2d793c NC |
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 | |
ae8714c2 NC |
28025 | lower case too. */ |
28026 | if (flag_warn_syms && arm_ops_hsh) | |
8b2d793c NC |
28027 | { |
28028 | char * nbuf = strdup (name); | |
28029 | char * p; | |
28030 | ||
28031 | for (p = nbuf; *p; p++) | |
28032 | *p = TOLOWER (*p); | |
629310ab | 28033 | if (str_hash_find (arm_ops_hsh, nbuf) != NULL) |
8b2d793c | 28034 | { |
629310ab | 28035 | static htab_t already_warned = NULL; |
8b2d793c NC |
28036 | |
28037 | if (already_warned == NULL) | |
629310ab | 28038 | already_warned = str_htab_create (); |
8b2d793c | 28039 | /* Only warn about the symbol once. To keep the code |
629310ab ML |
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); | |
fe0e921f | 28044 | str_hash_insert (already_warned, nbuf, NULL, 0); |
629310ab | 28045 | } |
8b2d793c NC |
28046 | } |
28047 | else | |
28048 | free (nbuf); | |
28049 | } | |
3739860c | 28050 | |
5b7c81bd | 28051 | return false; |
ae8714c2 NC |
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, | |
e01e1cee | 28070 | &zero_address_frag, 0); |
ae8714c2 NC |
28071 | } |
28072 | ||
28073 | return GOT_symbol; | |
28074 | } | |
28075 | #endif | |
28076 | ||
c921be7d | 28077 | return NULL; |
bfae80f2 RE |
28078 | } |
28079 | ||
55cf6793 | 28080 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
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) | |
bfae80f2 | 28088 | { |
c19d1205 ZW |
28089 | unsigned int a; |
28090 | unsigned int i; | |
bfae80f2 | 28091 | |
c19d1205 ZW |
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 | { | |
9c2799c2 | 28109 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
28110 | * highpart = (a >> 24) | ((i + 8) << 7); |
28111 | } | |
bfae80f2 | 28112 | |
c19d1205 ZW |
28113 | return (a & 0xff) | (i << 7); |
28114 | } | |
bfae80f2 | 28115 | |
c19d1205 | 28116 | return FAIL; |
bfae80f2 RE |
28117 | } |
28118 | ||
c19d1205 ZW |
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 | } | |
bfae80f2 | 28126 | |
55cf6793 | 28127 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
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. */ | |
bfae80f2 | 28137 | |
c19d1205 ZW |
28138 | static int |
28139 | negate_data_op (unsigned long * instruction, | |
28140 | unsigned long value) | |
bfae80f2 | 28141 | { |
c19d1205 ZW |
28142 | int op, new_inst; |
28143 | unsigned long negated, inverted; | |
bfae80f2 | 28144 | |
c19d1205 ZW |
28145 | negated = encode_arm_immediate (-value); |
28146 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 28147 | |
c19d1205 ZW |
28148 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
28149 | switch (op) | |
bfae80f2 | 28150 | { |
c19d1205 ZW |
28151 | /* First negates. */ |
28152 | case OPCODE_SUB: /* ADD <-> SUB */ | |
28153 | new_inst = OPCODE_ADD; | |
28154 | value = negated; | |
28155 | break; | |
bfae80f2 | 28156 | |
c19d1205 ZW |
28157 | case OPCODE_ADD: |
28158 | new_inst = OPCODE_SUB; | |
28159 | value = negated; | |
28160 | break; | |
bfae80f2 | 28161 | |
c19d1205 ZW |
28162 | case OPCODE_CMP: /* CMP <-> CMN */ |
28163 | new_inst = OPCODE_CMN; | |
28164 | value = negated; | |
28165 | break; | |
bfae80f2 | 28166 | |
c19d1205 ZW |
28167 | case OPCODE_CMN: |
28168 | new_inst = OPCODE_CMP; | |
28169 | value = negated; | |
28170 | break; | |
bfae80f2 | 28171 | |
c19d1205 ZW |
28172 | /* Now Inverted ops. */ |
28173 | case OPCODE_MOV: /* MOV <-> MVN */ | |
28174 | new_inst = OPCODE_MVN; | |
28175 | value = inverted; | |
28176 | break; | |
bfae80f2 | 28177 | |
c19d1205 ZW |
28178 | case OPCODE_MVN: |
28179 | new_inst = OPCODE_MOV; | |
28180 | value = inverted; | |
28181 | break; | |
bfae80f2 | 28182 | |
c19d1205 ZW |
28183 | case OPCODE_AND: /* AND <-> BIC */ |
28184 | new_inst = OPCODE_BIC; | |
28185 | value = inverted; | |
28186 | break; | |
bfae80f2 | 28187 | |
c19d1205 ZW |
28188 | case OPCODE_BIC: |
28189 | new_inst = OPCODE_AND; | |
28190 | value = inverted; | |
28191 | break; | |
bfae80f2 | 28192 | |
c19d1205 ZW |
28193 | case OPCODE_ADC: /* ADC <-> SBC */ |
28194 | new_inst = OPCODE_SBC; | |
28195 | value = inverted; | |
28196 | break; | |
bfae80f2 | 28197 | |
c19d1205 ZW |
28198 | case OPCODE_SBC: |
28199 | new_inst = OPCODE_ADC; | |
28200 | value = inverted; | |
28201 | break; | |
bfae80f2 | 28202 | |
c19d1205 ZW |
28203 | /* We cannot do anything. */ |
28204 | default: | |
28205 | return FAIL; | |
b99bd4ef NC |
28206 | } |
28207 | ||
c19d1205 ZW |
28208 | if (value == (unsigned) FAIL) |
28209 | return FAIL; | |
28210 | ||
28211 | *instruction &= OPCODE_MASK; | |
28212 | *instruction |= new_inst << DATA_OP_SHIFT; | |
28213 | return value; | |
b99bd4ef NC |
28214 | } |
28215 | ||
ef8d22e6 PB |
28216 | /* Like negate_data_op, but for Thumb-2. */ |
28217 | ||
28218 | static unsigned int | |
7af67752 | 28219 | thumb32_negate_data_op (valueT *instruction, unsigned int value) |
ef8d22e6 | 28220 | { |
7af67752 AM |
28221 | unsigned int op, new_inst; |
28222 | unsigned int rd; | |
16dd5e42 | 28223 | unsigned int negated, inverted; |
ef8d22e6 PB |
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 | ||
16dd5e42 | 28284 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
28285 | return FAIL; |
28286 | ||
28287 | *instruction &= T2_OPCODE_MASK; | |
28288 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
28289 | return value; | |
28290 | } | |
28291 | ||
8f06b2d8 | 28292 | /* Read a 32-bit thumb instruction from buf. */ |
0198d5e6 | 28293 | |
8f06b2d8 PB |
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 | ||
a8bc6c78 PB |
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. */ | |
c921be7d | 28309 | |
5b7c81bd | 28310 | bool |
a8bc6c78 PB |
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; | |
5b7c81bd | 28321 | return true; |
a8bc6c78 | 28322 | } |
c921be7d | 28323 | |
a8bc6c78 | 28324 | /* Process as normal. */ |
5b7c81bd | 28325 | return false; |
a8bc6c78 PB |
28326 | } |
28327 | ||
4a42ebbc RR |
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; | |
fa94de6b | 28343 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
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 | ||
c19d1205 | 28353 | void |
55cf6793 | 28354 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
28355 | valueT * valP, |
28356 | segT seg) | |
28357 | { | |
7af67752 AM |
28358 | valueT value = * valP; |
28359 | valueT newval; | |
c19d1205 ZW |
28360 | unsigned int newimm; |
28361 | unsigned long temp; | |
28362 | int sign; | |
28363 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 28364 | |
9c2799c2 | 28365 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 28366 | |
c19d1205 | 28367 | /* Note whether this will delete the relocation. */ |
4962c51a | 28368 | |
c19d1205 ZW |
28369 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
28370 | fixP->fx_done = 1; | |
b99bd4ef | 28371 | |
adbaf948 | 28372 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 28373 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
28374 | for emit_reloc. */ |
28375 | value &= 0xffffffff; | |
28376 | value ^= 0x80000000; | |
5f4273c7 | 28377 | value -= 0x80000000; |
adbaf948 ZW |
28378 | |
28379 | *valP = value; | |
c19d1205 | 28380 | fixP->fx_addnumber = value; |
b99bd4ef | 28381 | |
adbaf948 ZW |
28382 | /* Same treatment for fixP->fx_offset. */ |
28383 | fixP->fx_offset &= 0xffffffff; | |
28384 | fixP->fx_offset ^= 0x80000000; | |
28385 | fixP->fx_offset -= 0x80000000; | |
28386 | ||
c19d1205 | 28387 | switch (fixP->fx_r_type) |
b99bd4ef | 28388 | { |
c19d1205 ZW |
28389 | case BFD_RELOC_NONE: |
28390 | /* This will need to go in the object file. */ | |
28391 | fixP->fx_done = 0; | |
28392 | break; | |
b99bd4ef | 28393 | |
c19d1205 ZW |
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; | |
b99bd4ef | 28399 | |
77db8e2e | 28400 | if (fixP->fx_addsy) |
b99bd4ef | 28401 | { |
77db8e2e | 28402 | const char *msg = 0; |
b99bd4ef | 28403 | |
77db8e2e NC |
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 | } | |
42e5fcbf AS |
28417 | } |
28418 | ||
c19d1205 ZW |
28419 | temp = md_chars_to_number (buf, INSN_SIZE); |
28420 | ||
5e73442d | 28421 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
7af67752 | 28422 | if ((temp & 0xfff0000) == 0x28f0000 && (offsetT) value < 0) |
5e73442d SL |
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); | |
bada4342 JW |
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) | |
7af67752 | 28440 | && value <= 0xffff) |
bada4342 JW |
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 | } | |
5e73442d SL |
28449 | } |
28450 | ||
28451 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 28452 | { |
c19d1205 ZW |
28453 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28454 | _("invalid constant (%lx) after fixup"), | |
28455 | (unsigned long) value); | |
28456 | break; | |
b99bd4ef | 28457 | } |
b99bd4ef | 28458 | |
c19d1205 ZW |
28459 | newimm |= (temp & 0xfffff000); |
28460 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
28461 | break; | |
b99bd4ef | 28462 | |
c19d1205 ZW |
28463 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
28464 | { | |
28465 | unsigned int highpart = 0; | |
28466 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 28467 | |
77db8e2e | 28468 | if (fixP->fx_addsy) |
42e5fcbf | 28469 | { |
77db8e2e | 28470 | const char *msg = 0; |
42e5fcbf | 28471 | |
77db8e2e NC |
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"); | |
42e5fcbf | 28478 | |
77db8e2e NC |
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 | } | |
fa94de6b | 28486 | |
c19d1205 ZW |
28487 | newimm = encode_arm_immediate (value); |
28488 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 28489 | |
c19d1205 ZW |
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); | |
b99bd4ef | 28498 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 28514 | |
c19d1205 ZW |
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 | } | |
b99bd4ef | 28522 | |
c19d1205 ZW |
28523 | newimm |= (temp & 0xfffff000); |
28524 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 28525 | |
c19d1205 ZW |
28526 | highpart |= (newinsn & 0xfffff000); |
28527 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
28528 | } | |
28529 | break; | |
b99bd4ef | 28530 | |
c19d1205 | 28531 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
28532 | if (!fixP->fx_done && seg->use_rela_p) |
28533 | value = 0; | |
1a0670f3 | 28534 | /* Fall through. */ |
00a97672 | 28535 | |
c19d1205 | 28536 | case BFD_RELOC_ARM_LITERAL: |
7af67752 | 28537 | sign = (offsetT) value > 0; |
b99bd4ef | 28538 | |
7af67752 | 28539 | if ((offsetT) value < 0) |
c19d1205 | 28540 | value = - value; |
b99bd4ef | 28541 | |
c19d1205 | 28542 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 28543 | { |
c19d1205 ZW |
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; | |
f03698e6 RE |
28552 | } |
28553 | ||
c19d1205 | 28554 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
28555 | if (value == 0) |
28556 | newval &= 0xfffff000; | |
28557 | else | |
28558 | { | |
28559 | newval &= 0xff7ff000; | |
28560 | newval |= value | (sign ? INDEX_UP : 0); | |
28561 | } | |
c19d1205 ZW |
28562 | md_number_to_chars (buf, newval, INSN_SIZE); |
28563 | break; | |
b99bd4ef | 28564 | |
c19d1205 ZW |
28565 | case BFD_RELOC_ARM_OFFSET_IMM8: |
28566 | case BFD_RELOC_ARM_HWLITERAL: | |
7af67752 | 28567 | sign = (offsetT) value > 0; |
b99bd4ef | 28568 | |
7af67752 | 28569 | if ((offsetT) value < 0) |
c19d1205 | 28570 | value = - value; |
b99bd4ef | 28571 | |
c19d1205 | 28572 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 28573 | { |
c19d1205 ZW |
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 | |
427d0db6 RM |
28578 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28579 | _("bad immediate value for 8-bit offset (%ld)"), | |
28580 | (long) value); | |
c19d1205 | 28581 | break; |
b99bd4ef NC |
28582 | } |
28583 | ||
c19d1205 | 28584 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
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 | } | |
c19d1205 ZW |
28592 | md_number_to_chars (buf, newval, INSN_SIZE); |
28593 | break; | |
b99bd4ef | 28594 | |
c19d1205 | 28595 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
7af67752 | 28596 | if (value > 1020 || value % 4 != 0) |
c19d1205 ZW |
28597 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28598 | _("bad immediate value for offset (%ld)"), (long) value); | |
28599 | value /= 4; | |
b99bd4ef | 28600 | |
c19d1205 | 28601 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
28602 | newval |= value; |
28603 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
28604 | break; | |
b99bd4ef | 28605 | |
c19d1205 ZW |
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, | |
477330fc | 28611 | *4, optional writeback(W) |
c19d1205 ZW |
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); | |
b99bd4ef | 28628 | |
c19d1205 | 28629 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 28630 | { |
c19d1205 | 28631 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
7af67752 | 28632 | if ((offsetT) value >= 0) |
c19d1205 ZW |
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; | |
216d22bc | 28643 | if (value > 0xff) |
c19d1205 ZW |
28644 | { |
28645 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28646 | _("offset out of range")); | |
28647 | break; | |
28648 | } | |
28649 | newval &= ~0xff; | |
b99bd4ef | 28650 | } |
c19d1205 | 28651 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 28652 | { |
c19d1205 | 28653 | /* PC-relative, 12-bit offset. */ |
7af67752 | 28654 | if ((offsetT) value >= 0) |
c19d1205 ZW |
28655 | newval |= (1 << 23); |
28656 | else | |
28657 | value = -value; | |
216d22bc | 28658 | if (value > 0xfff) |
c19d1205 ZW |
28659 | { |
28660 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28661 | _("offset out of range")); | |
28662 | break; | |
28663 | } | |
28664 | newval &= ~0xfff; | |
b99bd4ef | 28665 | } |
c19d1205 | 28666 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 28667 | { |
c19d1205 | 28668 | /* Writeback: 8-bit, +/- offset. */ |
7af67752 | 28669 | if ((offsetT) value >= 0) |
c19d1205 ZW |
28670 | newval |= (1 << 9); |
28671 | else | |
28672 | value = -value; | |
216d22bc | 28673 | if (value > 0xff) |
c19d1205 ZW |
28674 | { |
28675 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
28676 | _("offset out of range")); | |
28677 | break; | |
28678 | } | |
28679 | newval &= ~0xff; | |
b99bd4ef | 28680 | } |
c19d1205 | 28681 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 28682 | { |
c19d1205 | 28683 | /* T-instruction: positive 8-bit offset. */ |
7af67752 | 28684 | if (value > 0xff) |
b99bd4ef | 28685 | { |
c19d1205 ZW |
28686 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28687 | _("offset out of range")); | |
28688 | break; | |
b99bd4ef | 28689 | } |
c19d1205 ZW |
28690 | newval &= ~0xff; |
28691 | newval |= value; | |
b99bd4ef NC |
28692 | } |
28693 | else | |
b99bd4ef | 28694 | { |
c19d1205 | 28695 | /* Positive 12-bit or negative 8-bit offset. */ |
7af67752 AM |
28696 | unsigned int limit; |
28697 | if ((offsetT) value >= 0) | |
b99bd4ef | 28698 | { |
c19d1205 ZW |
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; | |
b99bd4ef | 28712 | } |
c19d1205 | 28713 | newval &= ~limit; |
b99bd4ef | 28714 | } |
b99bd4ef | 28715 | |
c19d1205 ZW |
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; | |
404ff6b5 | 28720 | |
c19d1205 ZW |
28721 | case BFD_RELOC_ARM_SHIFT_IMM: |
28722 | newval = md_chars_to_number (buf, INSN_SIZE); | |
7af67752 | 28723 | if (value > 32 |
c19d1205 ZW |
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 | } | |
404ff6b5 | 28731 | |
c19d1205 ZW |
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; | |
404ff6b5 | 28741 | |
c19d1205 | 28742 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 28743 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 28744 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 28745 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
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; | |
404ff6b5 | 28750 | |
c19d1205 ZW |
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 | } | |
404ff6b5 | 28759 | |
c19d1205 ZW |
28760 | newval = md_chars_to_number (buf, THUMB_SIZE); |
28761 | newval <<= 16; | |
28762 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 28763 | |
16805f35 | 28764 | newimm = FAIL; |
bada4342 JW |
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)) | |
16805f35 | 28769 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) |
ef8d22e6 PB |
28770 | { |
28771 | newimm = encode_thumb32_immediate (value); | |
28772 | if (newimm == (unsigned int) FAIL) | |
28773 | newimm = thumb32_negate_data_op (&newval, value); | |
28774 | } | |
bada4342 | 28775 | if (newimm == (unsigned int) FAIL) |
92e90b6e | 28776 | { |
bada4342 | 28777 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE) |
e9f89963 | 28778 | { |
bada4342 JW |
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) | |
40f246e3 | 28784 | { |
bada4342 | 28785 | /* 12 bit immediate for addw/subw. */ |
7af67752 | 28786 | if ((offsetT) value < 0) |
bada4342 JW |
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 | |
db7bf105 | 28802 | overlap. */ |
bada4342 | 28803 | if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR |
db7bf105 NC |
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) | |
bada4342 JW |
28807 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m) |
28808 | && !((newval >> T2_SBIT_SHIFT) & 0x1) | |
7af67752 | 28809 | && value <= 0xffff) |
bada4342 JW |
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; | |
40f246e3 | 28819 | } |
e9f89963 | 28820 | } |
92e90b6e | 28821 | } |
cc8a6dd0 | 28822 | |
c19d1205 | 28823 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 28824 | { |
c19d1205 ZW |
28825 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28826 | _("invalid constant (%lx) after fixup"), | |
28827 | (unsigned long) value); | |
28828 | break; | |
3631a3c8 NC |
28829 | } |
28830 | ||
c19d1205 ZW |
28831 | newval |= (newimm & 0x800) << 15; |
28832 | newval |= (newimm & 0x700) << 4; | |
28833 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 28834 | |
c19d1205 ZW |
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; | |
a737bd4d | 28838 | |
3eb17e6b | 28839 | case BFD_RELOC_ARM_SMC: |
7af67752 | 28840 | if (value > 0xf) |
c19d1205 | 28841 | as_bad_where (fixP->fx_file, fixP->fx_line, |
3eb17e6b | 28842 | _("invalid smc expression")); |
ba85f98c | 28843 | |
2fc8bdac | 28844 | newval = md_chars_to_number (buf, INSN_SIZE); |
ba85f98c | 28845 | newval |= (value & 0xf); |
c19d1205 ZW |
28846 | md_number_to_chars (buf, newval, INSN_SIZE); |
28847 | break; | |
a737bd4d | 28848 | |
90ec0d68 | 28849 | case BFD_RELOC_ARM_HVC: |
7af67752 | 28850 | if (value > 0xffff) |
90ec0d68 MGD |
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 | ||
c19d1205 | 28858 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 28859 | if (fixP->tc_fix_data != 0) |
c19d1205 | 28860 | { |
7af67752 | 28861 | if (value > 0xff) |
c19d1205 ZW |
28862 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28863 | _("invalid swi expression")); | |
2fc8bdac | 28864 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
28865 | newval |= value; |
28866 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
28867 | } | |
28868 | else | |
28869 | { | |
7af67752 | 28870 | if (value > 0x00ffffff) |
c19d1205 ZW |
28871 | as_bad_where (fixP->fx_file, fixP->fx_line, |
28872 | _("invalid swi expression")); | |
2fc8bdac | 28873 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
28874 | newval |= value; |
28875 | md_number_to_chars (buf, newval, INSN_SIZE); | |
28876 | } | |
28877 | break; | |
a737bd4d | 28878 | |
c19d1205 | 28879 | case BFD_RELOC_ARM_MULTI: |
7af67752 | 28880 | if (value > 0xffff) |
c19d1205 ZW |
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; | |
a737bd4d | 28886 | |
c19d1205 | 28887 | #ifdef OBJ_ELF |
39b41c9c | 28888 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
28889 | |
28890 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
28891 | && fixP->fx_addsy | |
5b7c81bd | 28892 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 RR |
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 | } | |
39b41c9c PB |
28905 | else |
28906 | temp = 3; | |
28907 | goto arm_branch_common; | |
28908 | ||
28909 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
28910 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
28911 | && fixP->fx_addsy | |
5b7c81bd | 28912 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 RR |
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 | } | |
1a0670f3 | 28923 | /* Fall through. */ |
267bf995 | 28924 | |
2fc8bdac | 28925 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 28926 | #endif |
39b41c9c PB |
28927 | case BFD_RELOC_ARM_PCREL_BRANCH: |
28928 | temp = 3; | |
28929 | goto arm_branch_common; | |
a737bd4d | 28930 | |
39b41c9c | 28931 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 28932 | |
39b41c9c | 28933 | temp = 1; |
267bf995 RR |
28934 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
28935 | && fixP->fx_addsy | |
5b7c81bd | 28936 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 RR |
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) | |
477330fc | 28953 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; |
267bf995 RR |
28954 | #endif |
28955 | ||
39b41c9c | 28956 | arm_branch_common: |
c19d1205 | 28957 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
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 | |
de194d85 | 28960 | also be clear. */ |
39b41c9c | 28961 | if (value & temp) |
c19d1205 | 28962 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac | 28963 | _("misaligned branch destination")); |
7af67752 AM |
28964 | if ((value & 0xfe000000) != 0 |
28965 | && (value & 0xfe000000) != 0xfe000000) | |
08f10d51 | 28966 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 28967 | |
2fc8bdac | 28968 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 28969 | { |
2fc8bdac ZW |
28970 | newval = md_chars_to_number (buf, INSN_SIZE); |
28971 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
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 | } | |
2fc8bdac | 28980 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 28981 | } |
c19d1205 | 28982 | break; |
a737bd4d | 28983 | |
25fe350b MS |
28984 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
28985 | /* CBZ can only branch forward. */ | |
a737bd4d | 28986 | |
738755b0 | 28987 | /* Attempts to use CBZ to branch to the next instruction |
477330fc RM |
28988 | (which, strictly speaking, are prohibited) will be turned into |
28989 | no-ops. | |
738755b0 MS |
28990 | |
28991 | FIXME: It may be better to remove the instruction completely and | |
28992 | perform relaxation. */ | |
7af67752 | 28993 | if ((offsetT) value == -2) |
2fc8bdac ZW |
28994 | { |
28995 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 28996 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
28997 | md_number_to_chars (buf, newval, THUMB_SIZE); |
28998 | } | |
738755b0 MS |
28999 | else |
29000 | { | |
29001 | if (value & ~0x7e) | |
08f10d51 | 29002 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 | 29003 | |
477330fc | 29004 | if (fixP->fx_done || !seg->use_rela_p) |
738755b0 MS |
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 | } | |
c19d1205 | 29011 | break; |
a737bd4d | 29012 | |
c19d1205 | 29013 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
e8f8842d | 29014 | if (out_of_range_p (value, 8)) |
08f10d51 | 29015 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 29016 | |
2fc8bdac ZW |
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 | } | |
c19d1205 | 29023 | break; |
a737bd4d | 29024 | |
c19d1205 | 29025 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
e8f8842d | 29026 | if (out_of_range_p (value, 11)) |
08f10d51 | 29027 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 29028 | |
2fc8bdac ZW |
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 | } | |
c19d1205 | 29035 | break; |
a737bd4d | 29036 | |
e8f8842d | 29037 | /* This relocation is misnamed, it should be BRANCH21. */ |
c19d1205 | 29038 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
29039 | if (fixP->fx_addsy |
29040 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29041 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 RR |
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 | } | |
e8f8842d | 29048 | if (out_of_range_p (value, 20)) |
2fc8bdac ZW |
29049 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29050 | _("conditional branch out of range")); | |
404ff6b5 | 29051 | |
2fc8bdac ZW |
29052 | if (fixP->fx_done || !seg->use_rela_p) |
29053 | { | |
29054 | offsetT newval2; | |
29055 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 29056 | |
2fc8bdac ZW |
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; | |
6c43fab6 | 29062 | |
2fc8bdac ZW |
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 | } | |
c19d1205 | 29070 | break; |
6c43fab6 | 29071 | |
c19d1205 | 29072 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
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 | |
5b7c81bd | 29078 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 RR |
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 | ||
c19d1205 | 29096 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
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) | |
5b7c81bd | 29101 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
267bf995 RR |
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 | ||
2fc8bdac ZW |
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. */ | |
d406f3e4 JB |
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 | |
404ff6b5 | 29126 | |
e8f8842d | 29127 | if (out_of_range_p (value, 22)) |
2b2f5df9 | 29128 | { |
fc289b0a | 29129 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))) |
2b2f5df9 | 29130 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
e8f8842d | 29131 | else if (out_of_range_p (value, 24)) |
2b2f5df9 NC |
29132 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29133 | _("Thumb2 branch out of range")); | |
29134 | } | |
4a42ebbc RR |
29135 | |
29136 | if (fixP->fx_done || !seg->use_rela_p) | |
29137 | encode_thumb2_b_bl_offset (buf, value); | |
29138 | ||
c19d1205 | 29139 | break; |
404ff6b5 | 29140 | |
c19d1205 | 29141 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
e8f8842d | 29142 | if (out_of_range_p (value, 24)) |
08f10d51 | 29143 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
6c43fab6 | 29144 | |
2fc8bdac | 29145 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 29146 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 29147 | |
2fc8bdac | 29148 | break; |
a737bd4d | 29149 | |
2fc8bdac ZW |
29150 | case BFD_RELOC_8: |
29151 | if (fixP->fx_done || !seg->use_rela_p) | |
4b1a927e | 29152 | *buf = value; |
c19d1205 | 29153 | break; |
a737bd4d | 29154 | |
c19d1205 | 29155 | case BFD_RELOC_16: |
2fc8bdac | 29156 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 29157 | md_number_to_chars (buf, value, 2); |
c19d1205 | 29158 | break; |
a737bd4d | 29159 | |
c19d1205 | 29160 | #ifdef OBJ_ELF |
0855e32b NS |
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: | |
0855e32b | 29165 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
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); | |
4b1a927e | 29172 | break; |
6c43fab6 | 29173 | |
5c5a4843 CL |
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 | ||
c19d1205 ZW |
29189 | case BFD_RELOC_ARM_GOT32: |
29190 | case BFD_RELOC_ARM_GOTOFF: | |
c19d1205 | 29191 | break; |
b43420e6 NC |
29192 | |
29193 | case BFD_RELOC_ARM_GOT_PREL: | |
29194 | if (fixP->fx_done || !seg->use_rela_p) | |
477330fc | 29195 | md_number_to_chars (buf, value, 4); |
b43420e6 NC |
29196 | break; |
29197 | ||
9a6f4e97 NS |
29198 | case BFD_RELOC_ARM_TARGET2: |
29199 | /* TARGET2 is not partial-inplace, so we need to write the | |
477330fc RM |
29200 | addend here for REL targets, because it won't be written out |
29201 | during reloc processing later. */ | |
9a6f4e97 NS |
29202 | if (fixP->fx_done || !seg->use_rela_p) |
29203 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
29204 | break; | |
188fd7ae CL |
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; | |
c19d1205 | 29221 | #endif |
6c43fab6 | 29222 | |
c19d1205 ZW |
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: | |
f0927246 NC |
29229 | #ifdef TE_PE |
29230 | case BFD_RELOC_32_SECREL: | |
29231 | #endif | |
2fc8bdac | 29232 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
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); | |
c19d1205 | 29238 | break; |
6c43fab6 | 29239 | |
c19d1205 ZW |
29240 | #ifdef OBJ_ELF |
29241 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 29242 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
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; | |
c19d1205 | 29254 | #endif |
a737bd4d | 29255 | |
c19d1205 | 29256 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 29257 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
32c36c3c | 29258 | case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM: |
9db2f6b4 RL |
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 | |
7af67752 | 29266 | has permitted values that are multiples of 2, in the range -510 |
9db2f6b4 | 29267 | to 510. */ |
7af67752 | 29268 | if (value + 510 > 510 + 510 || (value & 1)) |
9db2f6b4 RL |
29269 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29270 | _("co-processor offset out of range")); | |
29271 | } | |
32c36c3c AV |
29272 | else if ((newval & 0xfe001f80) == 0xec000f80) |
29273 | { | |
7af67752 | 29274 | if (value + 511 > 512 + 511 || (value & 3)) |
32c36c3c AV |
29275 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29276 | _("co-processor offset out of range")); | |
29277 | } | |
7af67752 | 29278 | else if (value + 1023 > 1023 + 1023 || (value & 3)) |
c19d1205 ZW |
29279 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29280 | _("co-processor offset out of range")); | |
29281 | cp_off_common: | |
7af67752 AM |
29282 | sign = (offsetT) value > 0; |
29283 | if ((offsetT) value < 0) | |
c19d1205 | 29284 | value = -value; |
8f06b2d8 PB |
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); | |
26d97720 | 29290 | if (value == 0) |
32c36c3c AV |
29291 | { |
29292 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM) | |
29293 | newval &= 0xffffff80; | |
29294 | else | |
29295 | newval &= 0xffffff00; | |
29296 | } | |
26d97720 NS |
29297 | else |
29298 | { | |
32c36c3c AV |
29299 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM) |
29300 | newval &= 0xff7fff80; | |
29301 | else | |
29302 | newval &= 0xff7fff00; | |
9db2f6b4 RL |
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 | } | |
26d97720 NS |
29314 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
29315 | } | |
8f06b2d8 PB |
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); | |
c19d1205 | 29321 | break; |
a737bd4d | 29322 | |
c19d1205 | 29323 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 29324 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
7af67752 | 29325 | if (value + 255 > 255 + 255) |
c19d1205 ZW |
29326 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29327 | _("co-processor offset out of range")); | |
df7849c5 | 29328 | value *= 4; |
c19d1205 | 29329 | goto cp_off_common; |
6c43fab6 | 29330 | |
c19d1205 ZW |
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)"), | |
0359e808 NC |
29345 | (((unsigned long) fixP->fx_frag->fr_address |
29346 | + (unsigned long) fixP->fx_where) & ~3) | |
29347 | + (unsigned long) value); | |
749479c8 AO |
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")); | |
a737bd4d | 29351 | |
c19d1205 ZW |
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); | |
a737bd4d | 29356 | |
c19d1205 ZW |
29357 | newval |= value >> 2; |
29358 | break; | |
a737bd4d | 29359 | |
c19d1205 ZW |
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; | |
6c43fab6 | 29367 | |
c19d1205 ZW |
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; | |
a737bd4d | 29375 | |
c19d1205 ZW |
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; | |
a737bd4d | 29383 | |
c19d1205 ZW |
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; | |
a737bd4d | 29391 | |
c19d1205 ZW |
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; | |
a737bd4d | 29400 | |
c19d1205 ZW |
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: | |
a737bd4d | 29404 | |
c19d1205 ZW |
29405 | 3bit ADD/SUB |
29406 | 8bit ADD/SUB | |
29407 | 9bit ADD/SUB SP word-aligned | |
29408 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 29409 | |
c19d1205 ZW |
29410 | The type of instruction being processed is encoded in the |
29411 | instruction field: | |
a737bd4d | 29412 | |
c19d1205 ZW |
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); | |
a737bd4d | 29422 | |
c19d1205 ZW |
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")); | |
a737bd4d | 29429 | |
c19d1205 | 29430 | /* If value is negative, choose the opposite instruction. */ |
7af67752 | 29431 | if ((offsetT) value < 0) |
c19d1205 ZW |
29432 | { |
29433 | value = -value; | |
29434 | subtract = !subtract; | |
7af67752 | 29435 | if ((offsetT) value < 0) |
c19d1205 ZW |
29436 | as_bad_where (fixP->fx_file, fixP->fx_line, |
29437 | _("immediate value out of range")); | |
29438 | } | |
a737bd4d | 29439 | |
c19d1205 ZW |
29440 | if (rd == REG_SP) |
29441 | { | |
75c11999 | 29442 | if (value & ~0x1fc) |
c19d1205 ZW |
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 | { | |
c12d2c9d NC |
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 | ||
c19d1205 ZW |
29489 | if (subtract || value & ~0x3fc) |
29490 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
29491 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
5fc177c8 | 29492 | (unsigned long) (subtract ? - value : value)); |
c19d1205 ZW |
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; | |
a737bd4d | 29516 | |
c19d1205 ZW |
29517 | case BFD_RELOC_ARM_THUMB_IMM: |
29518 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
7af67752 | 29519 | if (value > 255) |
c19d1205 | 29520 | as_bad_where (fixP->fx_file, fixP->fx_line, |
4e6e072b | 29521 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
29522 | (long) value); |
29523 | newval |= value; | |
29524 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
29525 | break; | |
a737bd4d | 29526 | |
c19d1205 ZW |
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; | |
7af67752 | 29531 | if (value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) |
c19d1205 ZW |
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; | |
a737bd4d | 29543 | |
c19d1205 ZW |
29544 | case BFD_RELOC_VTABLE_INHERIT: |
29545 | case BFD_RELOC_VTABLE_ENTRY: | |
29546 | fixP->fx_done = 0; | |
29547 | return; | |
6c43fab6 | 29548 | |
b6895b4f PB |
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 | { | |
7af67752 | 29558 | if (value + 0x8000 > 0x7fff + 0x8000) |
b6895b4f | 29559 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 29560 | _("offset out of range")); |
b6895b4f PB |
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 | ||
72d98d16 MG |
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; | |
5b7c81bd | 29597 | bool is_mov; |
72d98d16 MG |
29598 | bfd_vma encoded_addend = value; |
29599 | ||
29600 | /* Check that addend can be encoded in instruction. */ | |
7af67752 | 29601 | if (!seg->use_rela_p && value > 255) |
72d98d16 MG |
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 | ||
4962c51a MS |
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: | |
9c2799c2 | 29662 | gas_assert (!fixP->fx_done); |
4962c51a MS |
29663 | if (!seg->use_rela_p) |
29664 | { | |
477330fc RM |
29665 | bfd_vma insn; |
29666 | bfd_vma encoded_addend; | |
7af67752 | 29667 | bfd_vma addend_abs = llabs ((offsetT) value); |
477330fc RM |
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) | |
4962c51a | 29673 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
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; | |
7af67752 | 29683 | if ((offsetT) value < 0) |
477330fc RM |
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); | |
4962c51a MS |
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: | |
9c2799c2 | 29704 | gas_assert (!fixP->fx_done); |
4962c51a | 29705 | if (!seg->use_rela_p) |
477330fc RM |
29706 | { |
29707 | bfd_vma insn; | |
7af67752 | 29708 | bfd_vma addend_abs = llabs ((offsetT) value); |
4962c51a | 29709 | |
477330fc RM |
29710 | /* Check that the absolute value of the addend can be |
29711 | encoded in 12 bits. */ | |
29712 | if (addend_abs >= 0x1000) | |
4962c51a | 29713 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
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. */ | |
7af67752 | 29722 | if ((offsetT) value < 0) |
477330fc RM |
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 | } | |
4962c51a MS |
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: | |
9c2799c2 | 29743 | gas_assert (!fixP->fx_done); |
4962c51a | 29744 | if (!seg->use_rela_p) |
477330fc RM |
29745 | { |
29746 | bfd_vma insn; | |
7af67752 | 29747 | bfd_vma addend_abs = llabs ((offsetT) value); |
4962c51a | 29748 | |
477330fc RM |
29749 | /* Check that the absolute value of the addend can be |
29750 | encoded in 8 bits. */ | |
29751 | if (addend_abs >= 0x100) | |
4962c51a | 29752 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
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. */ | |
7af67752 | 29761 | if ((offsetT) value < 0) |
477330fc RM |
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 | } | |
4962c51a MS |
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: | |
9c2799c2 | 29783 | gas_assert (!fixP->fx_done); |
4962c51a | 29784 | if (!seg->use_rela_p) |
477330fc RM |
29785 | { |
29786 | bfd_vma insn; | |
7af67752 | 29787 | bfd_vma addend_abs = llabs ((offsetT) value); |
4962c51a | 29788 | |
477330fc RM |
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) | |
4962c51a | 29792 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
29793 | _("bad offset 0x%08lX (must be word-aligned)"), |
29794 | (unsigned long) addend_abs); | |
4962c51a | 29795 | |
477330fc | 29796 | if ((addend_abs >> 2) > 0xff) |
4962c51a | 29797 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
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. */ | |
7af67752 | 29806 | if ((offsetT) value < 0) |
477330fc RM |
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 | } | |
4962c51a MS |
29819 | break; |
29820 | ||
e12437dc AV |
29821 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
29822 | if (fixP->fx_addsy | |
29823 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29824 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
e12437dc AV |
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 | } | |
5b7c81bd | 29831 | if (v8_1_branch_value_check (value, 5, false) == FAIL) |
e12437dc AV |
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 | ||
f6b2b12d AV |
29845 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
29846 | if (fixP->fx_addsy | |
29847 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29848 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
f6b2b12d AV |
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 | } | |
7af67752 | 29854 | if ((value & ~0x7f) && ((value & ~0x3f) != (valueT) ~0x3f)) |
f6b2b12d AV |
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 | ||
e5d6e09e AV |
29878 | case BFD_RELOC_ARM_THUMB_BF17: |
29879 | if (fixP->fx_addsy | |
29880 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29881 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
e5d6e09e AV |
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 | ||
5b7c81bd | 29889 | if (v8_1_branch_value_check (value, 17, true) == FAIL) |
e5d6e09e AV |
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 | ||
1caf72a5 AV |
29911 | case BFD_RELOC_ARM_THUMB_BF19: |
29912 | if (fixP->fx_addsy | |
29913 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29914 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
1caf72a5 AV |
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 | ||
5b7c81bd | 29922 | if (v8_1_branch_value_check (value, 19, true) == FAIL) |
1caf72a5 AV |
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 | ||
1889da70 AV |
29944 | case BFD_RELOC_ARM_THUMB_BF13: |
29945 | if (fixP->fx_addsy | |
29946 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29947 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
1889da70 AV |
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 | ||
5b7c81bd | 29955 | if (v8_1_branch_value_check (value, 13, true) == FAIL) |
1889da70 AV |
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 | ||
60f993ce AV |
29977 | case BFD_RELOC_ARM_THUMB_LOOP12: |
29978 | if (fixP->fx_addsy | |
29979 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
5b7c81bd | 29980 | && !S_FORCE_RELOC (fixP->fx_addsy, true) |
60f993ce AV |
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); | |
1f6234a3 | 29989 | /* le lr, <label>, le <label> or letp lr, <label> */ |
60f993ce | 29990 | if (((insn & 0xffffffff) == 0xf00fc001) |
1f6234a3 AV |
29991 | || ((insn & 0xffffffff) == 0xf02fc001) |
29992 | || ((insn & 0xffffffff) == 0xf01fc001)) | |
60f993ce AV |
29993 | value = -value; |
29994 | ||
5b7c81bd | 29995 | if (v8_1_branch_value_check (value, 12, false) == FAIL) |
60f993ce AV |
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 | ||
845b51d6 PB |
30011 | case BFD_RELOC_ARM_V4BX: |
30012 | /* This will need to go in the object file. */ | |
30013 | fixP->fx_done = 0; | |
30014 | break; | |
30015 | ||
c19d1205 ZW |
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 | } | |
6c43fab6 RE |
30021 | } |
30022 | ||
c19d1205 ZW |
30023 | /* Translate internal representation of relocation info to BFD target |
30024 | format. */ | |
a737bd4d | 30025 | |
c19d1205 | 30026 | arelent * |
00a97672 | 30027 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 30028 | { |
c19d1205 ZW |
30029 | arelent * reloc; |
30030 | bfd_reloc_code_real_type code; | |
a737bd4d | 30031 | |
325801bd | 30032 | reloc = XNEW (arelent); |
a737bd4d | 30033 | |
325801bd | 30034 | reloc->sym_ptr_ptr = XNEW (asymbol *); |
c19d1205 ZW |
30035 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
30036 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 30037 | |
2fc8bdac | 30038 | if (fixp->fx_pcrel) |
00a97672 RS |
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 | } | |
c19d1205 | 30045 | reloc->addend = fixp->fx_offset; |
a737bd4d | 30046 | |
c19d1205 | 30047 | switch (fixp->fx_r_type) |
a737bd4d | 30048 | { |
c19d1205 ZW |
30049 | case BFD_RELOC_8: |
30050 | if (fixp->fx_pcrel) | |
30051 | { | |
30052 | code = BFD_RELOC_8_PCREL; | |
30053 | break; | |
30054 | } | |
1a0670f3 | 30055 | /* Fall through. */ |
a737bd4d | 30056 | |
c19d1205 ZW |
30057 | case BFD_RELOC_16: |
30058 | if (fixp->fx_pcrel) | |
30059 | { | |
30060 | code = BFD_RELOC_16_PCREL; | |
30061 | break; | |
30062 | } | |
1a0670f3 | 30063 | /* Fall through. */ |
6c43fab6 | 30064 | |
c19d1205 ZW |
30065 | case BFD_RELOC_32: |
30066 | if (fixp->fx_pcrel) | |
30067 | { | |
30068 | code = BFD_RELOC_32_PCREL; | |
30069 | break; | |
30070 | } | |
1a0670f3 | 30071 | /* Fall through. */ |
a737bd4d | 30072 | |
b6895b4f PB |
30073 | case BFD_RELOC_ARM_MOVW: |
30074 | if (fixp->fx_pcrel) | |
30075 | { | |
30076 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
30077 | break; | |
30078 | } | |
1a0670f3 | 30079 | /* Fall through. */ |
b6895b4f PB |
30080 | |
30081 | case BFD_RELOC_ARM_MOVT: | |
30082 | if (fixp->fx_pcrel) | |
30083 | { | |
30084 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
30085 | break; | |
30086 | } | |
1a0670f3 | 30087 | /* Fall through. */ |
b6895b4f PB |
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 | } | |
1a0670f3 | 30095 | /* Fall through. */ |
b6895b4f PB |
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 | } | |
1a0670f3 | 30103 | /* Fall through. */ |
b6895b4f | 30104 | |
c19d1205 ZW |
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: | |
c19d1205 ZW |
30115 | case BFD_RELOC_VTABLE_ENTRY: |
30116 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
30117 | #ifdef TE_PE |
30118 | case BFD_RELOC_32_SECREL: | |
30119 | #endif | |
c19d1205 ZW |
30120 | code = fixp->fx_r_type; |
30121 | break; | |
a737bd4d | 30122 | |
00adf2d4 JB |
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 | ||
c19d1205 ZW |
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; | |
a737bd4d | 30139 | |
c19d1205 | 30140 | #ifdef OBJ_ELF |
0855e32b NS |
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: | |
c19d1205 ZW |
30145 | case BFD_RELOC_ARM_GOT32: |
30146 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 30147 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
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: | |
c19d1205 | 30154 | case BFD_RELOC_ARM_TLS_LDO32: |
39b41c9c PB |
30155 | case BFD_RELOC_ARM_PCREL_CALL: |
30156 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
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: | |
845b51d6 | 30185 | case BFD_RELOC_ARM_V4BX: |
72d98d16 MG |
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: | |
188fd7ae CL |
30190 | case BFD_RELOC_ARM_GOTFUNCDESC: |
30191 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
30192 | case BFD_RELOC_ARM_FUNCDESC: | |
e5d6e09e | 30193 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 30194 | case BFD_RELOC_ARM_THUMB_BF19: |
1889da70 | 30195 | case BFD_RELOC_ARM_THUMB_BF13: |
c19d1205 ZW |
30196 | code = fixp->fx_r_type; |
30197 | break; | |
a737bd4d | 30198 | |
0855e32b | 30199 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 | 30200 | case BFD_RELOC_ARM_TLS_GD32: |
5c5a4843 | 30201 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: |
75c11999 | 30202 | case BFD_RELOC_ARM_TLS_LE32: |
c19d1205 | 30203 | case BFD_RELOC_ARM_TLS_IE32: |
5c5a4843 | 30204 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: |
c19d1205 | 30205 | case BFD_RELOC_ARM_TLS_LDM32: |
5c5a4843 | 30206 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: |
c19d1205 ZW |
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 | |
a737bd4d | 30214 | |
c19d1205 ZW |
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; | |
a737bd4d | 30219 | |
c19d1205 ZW |
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; | |
a737bd4d | 30224 | |
e12437dc | 30225 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
f6b2b12d | 30226 | case BFD_RELOC_THUMB_PCREL_BFCSEL: |
60f993ce | 30227 | case BFD_RELOC_ARM_THUMB_LOOP12: |
e12437dc AV |
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 | ||
c19d1205 | 30233 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
30234 | if (section->use_rela_p) |
30235 | { | |
30236 | code = fixp->fx_r_type; | |
30237 | break; | |
30238 | } | |
30239 | ||
c19d1205 ZW |
30240 | if (fixp->fx_addsy != NULL |
30241 | && !S_IS_DEFINED (fixp->fx_addsy) | |
30242 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 30243 | { |
c19d1205 ZW |
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; | |
a737bd4d NC |
30248 | } |
30249 | ||
c19d1205 ZW |
30250 | as_bad_where (fixp->fx_file, fixp->fx_line, |
30251 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
30252 | return NULL; | |
a737bd4d | 30253 | |
c19d1205 ZW |
30254 | default: |
30255 | { | |
e0471c16 | 30256 | const char * type; |
6c43fab6 | 30257 | |
c19d1205 ZW |
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; | |
3eb17e6b | 30263 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
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; | |
db187cb9 | 30267 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 30268 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
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 | } | |
a737bd4d | 30280 | } |
6c43fab6 | 30281 | |
c19d1205 ZW |
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 | |
6c43fab6 | 30291 | |
c19d1205 | 30292 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 30293 | |
c19d1205 ZW |
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 | } | |
6c43fab6 | 30301 | |
c19d1205 ZW |
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; | |
6c43fab6 | 30306 | |
c19d1205 | 30307 | return reloc; |
6c43fab6 RE |
30308 | } |
30309 | ||
c19d1205 | 30310 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 30311 | |
c19d1205 ZW |
30312 | void |
30313 | cons_fix_new_arm (fragS * frag, | |
30314 | int where, | |
30315 | int size, | |
62ebcb5c AM |
30316 | expressionS * exp, |
30317 | bfd_reloc_code_real_type reloc) | |
6c43fab6 | 30318 | { |
c19d1205 | 30319 | int pcrel = 0; |
6c43fab6 | 30320 | |
c19d1205 ZW |
30321 | /* Pick a reloc. |
30322 | FIXME: @@ Should look at CPU word size. */ | |
30323 | switch (size) | |
30324 | { | |
30325 | case 1: | |
62ebcb5c | 30326 | reloc = BFD_RELOC_8; |
c19d1205 ZW |
30327 | break; |
30328 | case 2: | |
62ebcb5c | 30329 | reloc = BFD_RELOC_16; |
c19d1205 ZW |
30330 | break; |
30331 | case 4: | |
30332 | default: | |
62ebcb5c | 30333 | reloc = BFD_RELOC_32; |
c19d1205 ZW |
30334 | break; |
30335 | case 8: | |
62ebcb5c | 30336 | reloc = BFD_RELOC_64; |
c19d1205 ZW |
30337 | break; |
30338 | } | |
6c43fab6 | 30339 | |
f0927246 NC |
30340 | #ifdef TE_PE |
30341 | if (exp->X_op == O_secrel) | |
30342 | { | |
30343 | exp->X_op = O_symbol; | |
62ebcb5c | 30344 | reloc = BFD_RELOC_32_SECREL; |
f0927246 NC |
30345 | } |
30346 | #endif | |
30347 | ||
62ebcb5c | 30348 | fix_new_exp (frag, where, size, exp, pcrel, reloc); |
c19d1205 | 30349 | } |
6c43fab6 | 30350 | |
4343666d | 30351 | #if defined (OBJ_COFF) |
c19d1205 ZW |
30352 | void |
30353 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 30354 | { |
c19d1205 ZW |
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)) | |
6c43fab6 | 30363 | { |
c19d1205 | 30364 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 30365 | } |
c19d1205 ZW |
30366 | } |
30367 | #endif | |
6c43fab6 | 30368 | |
267bf995 | 30369 | |
c19d1205 ZW |
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 | |
6c43fab6 | 30377 | |
267bf995 RR |
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 | ||
b5884301 PB |
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. */ | |
c19d1205 ZW |
30411 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
30412 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 30413 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 30414 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
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 | |
b59d128a | 30418 | || fixp->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH12 |
16805f35 | 30419 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
30420 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
30421 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
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) | |
c19d1205 | 30426 | return 0; |
a737bd4d | 30427 | |
4962c51a MS |
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 | ||
f0291e4c PB |
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 | ||
c19d1205 | 30440 | return generic_force_reloc (fixp); |
404ff6b5 AH |
30441 | } |
30442 | ||
0ffdc86c | 30443 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
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 | |
c19d1205 ZW |
30447 | also prevents relocations that are mips-16 specific, but I do not |
30448 | know why it does this. | |
404ff6b5 | 30449 | |
c19d1205 ZW |
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. */ | |
404ff6b5 | 30456 | |
5b7c81bd | 30457 | bool |
c19d1205 | 30458 | arm_fix_adjustable (fixS * fixP) |
404ff6b5 | 30459 | { |
c19d1205 ZW |
30460 | if (fixP->fx_addsy == NULL) |
30461 | return 1; | |
404ff6b5 | 30462 | |
e28387c3 PB |
30463 | /* Preserve relocations against symbols with function type. */ |
30464 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
5b7c81bd | 30465 | return false; |
e28387c3 | 30466 | |
c19d1205 ZW |
30467 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
30468 | && fixP->fx_subsy == NULL) | |
5b7c81bd | 30469 | return false; |
a737bd4d | 30470 | |
c19d1205 ZW |
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) | |
5b7c81bd | 30474 | return false; |
404ff6b5 | 30475 | |
c19d1205 ZW |
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 | |
5c5a4843 | 30481 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC |
c19d1205 ZW |
30482 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 |
30483 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
5c5a4843 | 30484 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC |
c19d1205 | 30485 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 |
5c5a4843 | 30486 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC |
c19d1205 | 30487 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 |
0855e32b NS |
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 | |
c19d1205 | 30493 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
5b7c81bd | 30494 | return false; |
a737bd4d | 30495 | |
4962c51a MS |
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) | |
5b7c81bd | 30500 | return false; |
4962c51a | 30501 | |
79947c54 CD |
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) | |
5b7c81bd | 30511 | return false; |
79947c54 | 30512 | |
72d98d16 MG |
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) | |
5b7c81bd | 30517 | return false; |
72d98d16 | 30518 | |
5b7c81bd | 30519 | return true; |
a737bd4d | 30520 | } |
0ffdc86c NC |
30521 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
30522 | ||
30523 | #ifdef OBJ_ELF | |
c19d1205 ZW |
30524 | const char * |
30525 | elf32_arm_target_format (void) | |
404ff6b5 | 30526 | { |
a57d1773 | 30527 | #if defined (TE_VXWORKS) |
c19d1205 ZW |
30528 | return (target_big_endian |
30529 | ? "elf32-bigarm-vxworks" | |
30530 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
30531 | #elif defined (TE_NACL) |
30532 | return (target_big_endian | |
30533 | ? "elf32-bigarm-nacl" | |
30534 | : "elf32-littlearm-nacl"); | |
c19d1205 | 30535 | #else |
18a20338 CL |
30536 | if (arm_fdpic) |
30537 | { | |
30538 | if (target_big_endian) | |
30539 | return "elf32-bigarm-fdpic"; | |
30540 | else | |
30541 | return "elf32-littlearm-fdpic"; | |
30542 | } | |
c19d1205 | 30543 | else |
18a20338 CL |
30544 | { |
30545 | if (target_big_endian) | |
30546 | return "elf32-bigarm"; | |
30547 | else | |
30548 | return "elf32-littlearm"; | |
30549 | } | |
c19d1205 | 30550 | #endif |
404ff6b5 AH |
30551 | } |
30552 | ||
c19d1205 ZW |
30553 | void |
30554 | armelf_frob_symbol (symbolS * symp, | |
30555 | int * puntp) | |
404ff6b5 | 30556 | { |
c19d1205 ZW |
30557 | elf_frob_symbol (symp, puntp); |
30558 | } | |
30559 | #endif | |
404ff6b5 | 30560 | |
c19d1205 | 30561 | /* MD interface: Finalization. */ |
a737bd4d | 30562 | |
c19d1205 ZW |
30563 | void |
30564 | arm_cleanup (void) | |
30565 | { | |
30566 | literal_pool * pool; | |
a737bd4d | 30567 | |
5ee91343 AV |
30568 | /* Ensure that all the predication blocks are properly closed. */ |
30569 | check_pred_blocks_finished (); | |
e07e6e58 | 30570 | |
c19d1205 ZW |
30571 | for (pool = list_of_pools; pool; pool = pool->next) |
30572 | { | |
5f4273c7 | 30573 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
30574 | subseg_set (pool->section, pool->sub_section); |
30575 | #ifdef OBJ_ELF | |
30576 | arm_elf_change_section (); | |
30577 | #endif | |
30578 | s_ltorg (0); | |
30579 | } | |
404ff6b5 AH |
30580 | } |
30581 | ||
cd000bff DJ |
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 | ||
c19d1205 ZW |
30649 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
30650 | ARM ones. */ | |
404ff6b5 | 30651 | |
c19d1205 ZW |
30652 | void |
30653 | arm_adjust_symtab (void) | |
404ff6b5 | 30654 | { |
c19d1205 ZW |
30655 | #ifdef OBJ_COFF |
30656 | symbolS * sym; | |
404ff6b5 | 30657 | |
c19d1205 ZW |
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); | |
404ff6b5 | 30668 | |
c19d1205 ZW |
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 | } | |
a737bd4d | 30691 | |
c19d1205 ZW |
30692 | if (ARM_IS_INTERWORK (sym)) |
30693 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 30694 | } |
c19d1205 ZW |
30695 | #endif |
30696 | #ifdef OBJ_ELF | |
30697 | symbolS * sym; | |
30698 | char bind; | |
404ff6b5 | 30699 | |
c19d1205 | 30700 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 30701 | { |
c19d1205 ZW |
30702 | if (ARM_IS_THUMB (sym)) |
30703 | { | |
30704 | elf_symbol_type * elf_sym; | |
404ff6b5 | 30705 | |
c19d1205 ZW |
30706 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
30707 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 30708 | |
b0796911 PB |
30709 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
30710 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
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)) | |
39d911fc TP |
30715 | ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal, |
30716 | ST_BRANCH_TO_THUMB); | |
3ba67470 | 30717 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
30718 | elf_sym->internal_elf_sym.st_info = |
30719 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
30720 | } | |
30721 | } | |
30722 | } | |
cd000bff DJ |
30723 | |
30724 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
30725 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
30726 | /* Now do generic ELF adjustments. */ |
30727 | elf_adjust_symtab (); | |
c19d1205 | 30728 | #endif |
404ff6b5 AH |
30729 | } |
30730 | ||
c19d1205 | 30731 | /* MD interface: Initialization. */ |
404ff6b5 | 30732 | |
a737bd4d | 30733 | static void |
c19d1205 | 30734 | set_constant_flonums (void) |
a737bd4d | 30735 | { |
c19d1205 | 30736 | int i; |
404ff6b5 | 30737 | |
c19d1205 ZW |
30738 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
30739 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
30740 | abort (); | |
a737bd4d | 30741 | } |
404ff6b5 | 30742 | |
3e9e4fcf JB |
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 | ||
c19d1205 ZW |
30753 | void |
30754 | md_begin (void) | |
a737bd4d | 30755 | { |
c19d1205 ZW |
30756 | unsigned mach; |
30757 | unsigned int i; | |
404ff6b5 | 30758 | |
f16c3d4f AM |
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 (); | |
c19d1205 ZW |
30768 | |
30769 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
629310ab | 30770 | if (str_hash_find (arm_ops_hsh, insns[i].template_name) == NULL) |
fe0e921f | 30771 | str_hash_insert (arm_ops_hsh, insns[i].template_name, insns + i, 0); |
c19d1205 | 30772 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
fe0e921f | 30773 | str_hash_insert (arm_cond_hsh, conds[i].template_name, conds + i, 0); |
5ee91343 | 30774 | for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++) |
fe0e921f | 30775 | str_hash_insert (arm_vcond_hsh, vconds[i].template_name, vconds + i, 0); |
c19d1205 | 30776 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
fe0e921f | 30777 | str_hash_insert (arm_shift_hsh, shift_names[i].name, shift_names + i, 0); |
c19d1205 | 30778 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
fe0e921f | 30779 | str_hash_insert (arm_psr_hsh, psrs[i].template_name, psrs + i, 0); |
62b3e311 | 30780 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
629310ab | 30781 | str_hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
fe0e921f | 30782 | v7m_psrs + i, 0); |
c19d1205 | 30783 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
fe0e921f | 30784 | str_hash_insert (arm_reg_hsh, reg_names[i].name, reg_names + i, 0); |
62b3e311 PB |
30785 | for (i = 0; |
30786 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
30787 | i++) | |
629310ab | 30788 | str_hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
fe0e921f | 30789 | barrier_opt_names + i, 0); |
c19d1205 | 30790 | #ifdef OBJ_ELF |
3da1d841 NC |
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 | ||
fe0e921f | 30799 | str_hash_insert (arm_reloc_hsh, entry->name, entry, 0); |
3da1d841 | 30800 | } |
c19d1205 ZW |
30801 | #endif |
30802 | ||
30803 | set_constant_flonums (); | |
404ff6b5 | 30804 | |
c19d1205 ZW |
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. */ | |
e74cfd16 | 30809 | if (legacy_cpu) |
404ff6b5 | 30810 | { |
e74cfd16 | 30811 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
30812 | as_bad (_("use of old and new-style options to set CPU type")); |
30813 | ||
4d354d8b | 30814 | selected_arch = *legacy_cpu; |
404ff6b5 | 30815 | } |
4d354d8b TP |
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) | |
c168ce07 | 30822 | { |
4d354d8b TP |
30823 | selected_arch = *march_cpu_opt; |
30824 | selected_ext = *march_ext_opt; | |
c168ce07 | 30825 | } |
4d354d8b | 30826 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
404ff6b5 | 30827 | |
e74cfd16 | 30828 | if (legacy_fpu) |
c19d1205 | 30829 | { |
e74cfd16 | 30830 | if (mfpu_opt) |
c19d1205 | 30831 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f | 30832 | |
4d354d8b | 30833 | selected_fpu = *legacy_fpu; |
03b1477f | 30834 | } |
4d354d8b TP |
30835 | else if (mfpu_opt) |
30836 | selected_fpu = *mfpu_opt; | |
30837 | else | |
03b1477f | 30838 | { |
45eb4c1b NS |
30839 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
30840 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
30841 | /* Some environments specify a default FPU. If they don't, infer it |
30842 | from the processor. */ | |
e74cfd16 | 30843 | if (mcpu_fpu_opt) |
4d354d8b | 30844 | selected_fpu = *mcpu_fpu_opt; |
e7da50fa | 30845 | else if (march_fpu_opt) |
4d354d8b | 30846 | selected_fpu = *march_fpu_opt; |
39c2da32 | 30847 | #else |
4d354d8b | 30848 | selected_fpu = fpu_default; |
39c2da32 | 30849 | #endif |
03b1477f RE |
30850 | } |
30851 | ||
4d354d8b | 30852 | if (ARM_FEATURE_ZERO (selected_fpu)) |
03b1477f | 30853 | { |
4d354d8b TP |
30854 | if (!no_cpu_selected ()) |
30855 | selected_fpu = fpu_default; | |
03b1477f | 30856 | else |
4d354d8b | 30857 | selected_fpu = fpu_arch_fpa; |
03b1477f RE |
30858 | } |
30859 | ||
ee065d83 | 30860 | #ifdef CPU_DEFAULT |
4d354d8b | 30861 | if (ARM_FEATURE_ZERO (selected_arch)) |
ee065d83 | 30862 | { |
4d354d8b TP |
30863 | selected_arch = cpu_default; |
30864 | selected_cpu = selected_arch; | |
ee065d83 | 30865 | } |
4d354d8b | 30866 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
e74cfd16 | 30867 | #else |
4d354d8b TP |
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); | |
ee065d83 | 30874 | else |
4d354d8b | 30875 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 | 30876 | #endif |
03b1477f | 30877 | |
3e9e4fcf JB |
30878 | autoselect_thumb_from_cpu_variant (); |
30879 | ||
e74cfd16 | 30880 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 30881 | |
f17c130b | 30882 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 30883 | { |
7cc69913 NC |
30884 | unsigned int flags = 0; |
30885 | ||
30886 | #if defined OBJ_ELF | |
30887 | flags = meabi_flags; | |
d507cf36 PB |
30888 | |
30889 | switch (meabi_flags) | |
33a392fb | 30890 | { |
d507cf36 | 30891 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 30892 | #endif |
d507cf36 PB |
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; | |
c19d1205 | 30897 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 30898 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
30899 | flags |= F_SOFT_FLOAT; |
30900 | ||
d507cf36 PB |
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; | |
33a392fb | 30907 | |
d507cf36 PB |
30908 | case ARM_FLOAT_ABI_HARD: |
30909 | if (flags & F_SOFT_FLOAT) | |
30910 | as_bad (_("hard-float conflicts with specified fpu")); | |
30911 | break; | |
30912 | } | |
03b1477f | 30913 | |
e74cfd16 PB |
30914 | /* Using pure-endian doubles (even if soft-float). */ |
30915 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 30916 | flags |= F_VFP_FLOAT; |
f17c130b | 30917 | |
fde78edd | 30918 | #if defined OBJ_ELF |
e74cfd16 | 30919 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 30920 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
30921 | break; |
30922 | ||
8cb51566 | 30923 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 30924 | case EF_ARM_EABI_VER5: |
c19d1205 | 30925 | /* No additional flags to set. */ |
d507cf36 PB |
30926 | break; |
30927 | ||
30928 | default: | |
30929 | abort (); | |
30930 | } | |
7cc69913 | 30931 | #endif |
b99bd4ef NC |
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, | |
c19d1205 | 30936 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
30937 | if (atpcs) |
30938 | { | |
30939 | asection * sec; | |
30940 | ||
30941 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
30942 | ||
30943 | if (sec != NULL) | |
30944 | { | |
fd361982 AM |
30945 | bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING); |
30946 | bfd_set_section_size (sec, 0); | |
b99bd4ef NC |
30947 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); |
30948 | } | |
30949 | } | |
7cc69913 | 30950 | } |
f17c130b | 30951 | #endif |
b99bd4ef NC |
30952 | |
30953 | /* Record the CPU type as well. */ | |
2d447fca JM |
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)) | |
e16bb312 | 30957 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 30958 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 30959 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 30960 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 30961 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 30962 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 30963 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 30964 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 30965 | { |
e74cfd16 | 30966 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
30967 | mach = bfd_mach_arm_5T; |
30968 | else | |
30969 | mach = bfd_mach_arm_5; | |
30970 | } | |
e74cfd16 | 30971 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 30972 | { |
e74cfd16 | 30973 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
30974 | mach = bfd_mach_arm_4T; |
30975 | else | |
30976 | mach = bfd_mach_arm_4; | |
30977 | } | |
e74cfd16 | 30978 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 30979 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
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; | |
b99bd4ef NC |
30988 | |
30989 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
30990 | } | |
30991 | ||
c19d1205 | 30992 | /* Command line processing. */ |
b99bd4ef | 30993 | |
c19d1205 ZW |
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. | |
b99bd4ef | 30997 | |
c19d1205 ZW |
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. | |
b99bd4ef | 31002 | |
c19d1205 | 31003 | New options (supported) are: |
b99bd4ef | 31004 | |
c19d1205 ZW |
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 | |
b99bd4ef | 31013 | |
278df34e | 31014 | -m[no-]warn-deprecated Warn about deprecated features |
8b2d793c | 31015 | -m[no-]warn-syms Warn when symbols match instructions |
267bf995 | 31016 | |
c19d1205 | 31017 | For now we will also provide support for: |
b99bd4ef | 31018 | |
c19d1205 ZW |
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>) | |
b99bd4ef | 31026 | |
c19d1205 ZW |
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 | |
b99bd4ef | 31046 | |
c19d1205 ZW |
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. | |
b99bd4ef | 31055 | |
c19d1205 | 31056 | */ |
b99bd4ef | 31057 | |
c19d1205 | 31058 | const char * md_shortopts = "m:k"; |
b99bd4ef | 31059 | |
c19d1205 ZW |
31060 | #ifdef ARM_BI_ENDIAN |
31061 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
31062 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 31063 | #else |
c19d1205 ZW |
31064 | #if TARGET_BYTES_BIG_ENDIAN |
31065 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 31066 | #else |
c19d1205 ZW |
31067 | #define OPTION_EL (OPTION_MD_BASE + 1) |
31068 | #endif | |
b99bd4ef | 31069 | #endif |
845b51d6 | 31070 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
18a20338 | 31071 | #define OPTION_FDPIC (OPTION_MD_BASE + 3) |
b99bd4ef | 31072 | |
c19d1205 | 31073 | struct option md_longopts[] = |
b99bd4ef | 31074 | { |
c19d1205 ZW |
31075 | #ifdef OPTION_EB |
31076 | {"EB", no_argument, NULL, OPTION_EB}, | |
31077 | #endif | |
31078 | #ifdef OPTION_EL | |
31079 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 31080 | #endif |
845b51d6 | 31081 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
18a20338 CL |
31082 | #ifdef OBJ_ELF |
31083 | {"fdpic", no_argument, NULL, OPTION_FDPIC}, | |
31084 | #endif | |
c19d1205 ZW |
31085 | {NULL, no_argument, NULL, 0} |
31086 | }; | |
b99bd4ef | 31087 | |
c19d1205 | 31088 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 31089 | |
c19d1205 | 31090 | struct arm_option_table |
b99bd4ef | 31091 | { |
0198d5e6 TC |
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. */ | |
c19d1205 | 31097 | }; |
b99bd4ef | 31098 | |
c19d1205 ZW |
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}, | |
b99bd4ef | 31114 | |
c19d1205 ZW |
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}, | |
278df34e NS |
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}, | |
24f19ccb AV |
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 | ||
5b7c81bd AM |
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}, | |
e74cfd16 PB |
31129 | {NULL, NULL, NULL, 0, NULL} |
31130 | }; | |
31131 | ||
31132 | struct arm_legacy_option_table | |
31133 | { | |
0198d5e6 TC |
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. */ | |
e74cfd16 | 31138 | }; |
b99bd4ef | 31139 | |
e74cfd16 PB |
31140 | const struct arm_legacy_option_table arm_legacy_opts[] = |
31141 | { | |
c19d1205 ZW |
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. */ | |
e74cfd16 PB |
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, | |
c19d1205 | 31214 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 31215 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 31216 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 31217 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 31218 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
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")}, | |
7ed4c4c5 | 31222 | |
c19d1205 | 31223 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
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")}, | |
7ed4c4c5 | 31242 | |
c19d1205 | 31243 | /* Floating point variants -- don't add any more to this list either. */ |
0198d5e6 TC |
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, | |
c19d1205 | 31248 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 31249 | |
e74cfd16 | 31250 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 31251 | }; |
7ed4c4c5 | 31252 | |
c19d1205 | 31253 | struct arm_cpu_option_table |
7ed4c4c5 | 31254 | { |
0198d5e6 TC |
31255 | const char * name; |
31256 | size_t name_len; | |
31257 | const arm_feature_set value; | |
31258 | const arm_feature_set ext; | |
c19d1205 ZW |
31259 | /* For some CPUs we assume an FPU unless the user explicitly sets |
31260 | -mfpu=... */ | |
0198d5e6 | 31261 | const arm_feature_set default_fpu; |
ee065d83 PB |
31262 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
31263 | case. */ | |
0198d5e6 | 31264 | const char * canonical_name; |
c19d1205 | 31265 | }; |
7ed4c4c5 | 31266 | |
c19d1205 ZW |
31267 | /* This list should, at a minimum, contain all the cpu names |
31268 | recognized by GCC. */ | |
996b5569 | 31269 | #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN } |
0198d5e6 | 31270 | |
e74cfd16 | 31271 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 31272 | { |
996b5569 TP |
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 | ||
c19d1205 ZW |
31412 | /* For V5 or later processors we default to using VFP; but the user |
31413 | should really set the FPU type explicitly. */ | |
996b5569 TP |
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, | |
8b301fbb | 31544 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 TP |
31545 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
31546 | ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A, | |
8b301fbb | 31547 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 TP |
31548 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
31549 | ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A, | |
8b301fbb | 31550 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 | 31551 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
15a7695f JG |
31552 | ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A, |
31553 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 31554 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
996b5569 | 31555 | ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A, |
8b301fbb | 31556 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 TP |
31557 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
31558 | ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A, | |
8b301fbb | 31559 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 TP |
31560 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
31561 | ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A, | |
8b301fbb | 31562 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 | 31563 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
15a7695f JG |
31564 | ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A, |
31565 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 31566 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
7ebd1359 | 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), | |
0535e5d7 DZ |
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), | |
42c36b73 PW |
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), | |
1bbda94f PW |
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), | |
ef8df4ca KT |
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), | |
996b5569 TP |
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), | |
0cda1e19 | 31603 | ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R, |
8b301fbb | 31604 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
0cda1e19 | 31605 | FPU_ARCH_NEON_VFP_ARMV8), |
0535e5d7 DZ |
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), | |
996b5569 TP |
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), | |
394e9bf6 | 31633 | ARM_CPU_OPT ("cortex-x1", "Cortex-X1", ARM_ARCH_V8_2A, |
a417e439 | 31634 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | ARM_EXT2_SB), |
394e9bf6 | 31635 | FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), |
996b5569 | 31636 | ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A, |
8b301fbb | 31637 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 | 31638 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
83f43c83 KT |
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), | |
f3034e25 AC |
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), | |
6eee0315 | 31647 | ARM_CPU_OPT ("neoverse-v1", "Neoverse V1", ARM_ARCH_V8_4A, |
9bede61c AC |
31648 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST |
31649 | | ARM_EXT2_BF16 | |
31650 | | ARM_EXT2_I8MM), | |
6eee0315 | 31651 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4), |
c19d1205 | 31652 | /* ??? XSCALE is really an architecture. */ |
996b5569 TP |
31653 | ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE, |
31654 | ARM_ARCH_NONE, | |
31655 | FPU_ARCH_VFP_V2), | |
31656 | ||
c19d1205 | 31657 | /* ??? iwmmxt is not a processor. */ |
996b5569 TP |
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 | ||
0198d5e6 | 31668 | /* Maverick. */ |
996b5569 TP |
31669 | ARM_CPU_OPT ("ep9312", "ARM920T", |
31670 | ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), | |
31671 | ARM_ARCH_NONE, FPU_ARCH_MAVERICK), | |
31672 | ||
da4339ed | 31673 | /* Marvell processors. */ |
996b5569 TP |
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), | |
da4339ed | 31680 | |
996b5569 TP |
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, | |
8b301fbb | 31686 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC), |
996b5569 TP |
31687 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), |
31688 | ||
31689 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } | |
c19d1205 | 31690 | }; |
f3bad469 | 31691 | #undef ARM_CPU_OPT |
7ed4c4c5 | 31692 | |
34ef62f4 AV |
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 | ||
c19d1205 | 31701 | struct arm_arch_option_table |
7ed4c4c5 | 31702 | { |
34ef62f4 AV |
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 | { | |
8b301fbb | 31806 | ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)), |
34ef62f4 AV |
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), | |
616ce08e MM |
31839 | ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)), |
31840 | ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)), | |
34ef62f4 AV |
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), | |
616ce08e MM |
31857 | ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)), |
31858 | ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)), | |
34ef62f4 AV |
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), | |
616ce08e MM |
31874 | ARM_ADD ("bf16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_BF16)), |
31875 | ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)), | |
34ef62f4 AV |
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 | ||
aab2c27d MM |
31885 | static const struct arm_ext_table armv86a_ext_table[] = |
31886 | { | |
616ce08e | 31887 | ARM_ADD ("i8mm", ARM_FEATURE_CORE_HIGH (ARM_EXT2_I8MM)), |
aab2c27d MM |
31888 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } |
31889 | }; | |
31890 | ||
4934a27c MM |
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 | ||
34ef62f4 AV |
31901 | static const struct arm_ext_table armv8m_main_ext_table[] = |
31902 | { | |
92169145 AV |
31903 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP), |
31904 | ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)), | |
34ef62f4 AV |
31905 | ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP), |
31906 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
4934a27c | 31907 | CDE_EXTENSIONS, |
34ef62f4 AV |
31908 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } |
31909 | }; | |
31910 | ||
92169145 | 31911 | |
e0991585 AV |
31912 | static const struct arm_ext_table armv8_1m_main_ext_table[] = |
31913 | { | |
92169145 AV |
31914 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP), |
31915 | ARM_FEATURE_CORE_LOW (ARM_AEXT_V8M_MAIN_DSP)), | |
e0991585 AV |
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)), | |
92169145 | 31923 | ARM_EXT ("mve", ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, ARM_EXT2_MVE, 0), |
2da2eaf4 | 31924 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_MVE | ARM_EXT2_MVE_FP)), |
a7ad558c | 31925 | ARM_ADD ("mve.fp", |
92169145 AV |
31926 | ARM_FEATURE (ARM_AEXT_V8M_MAIN_DSP, |
31927 | ARM_EXT2_FP16_INST | ARM_EXT2_MVE | ARM_EXT2_MVE_FP, | |
2da2eaf4 | 31928 | FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)), |
4934a27c | 31929 | CDE_EXTENSIONS, |
5a0c7a81 | 31930 | ARM_ADD ("pacbti", ARM_FEATURE_CORE_HIGH_HIGH (ARM_AEXT3_V8_1M_MAIN_PACBTI)), |
e0991585 AV |
31931 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } |
31932 | }; | |
31933 | ||
4934a27c MM |
31934 | #undef CDE_EXTENSIONS |
31935 | ||
34ef62f4 AV |
31936 | static const struct arm_ext_table armv8r_ext_table[] = |
31937 | { | |
8b301fbb | 31938 | ARM_ADD ("crc", ARM_FEATURE_CORE_HIGH (ARM_EXT2_CRC)), |
34ef62f4 AV |
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 } | |
c19d1205 | 31945 | }; |
7ed4c4c5 | 31946 | |
c19d1205 ZW |
31947 | /* This list should, at a minimum, contain all the architecture names |
31948 | recognized by GCC. */ | |
34ef62f4 AV |
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 } | |
0198d5e6 | 31952 | |
e74cfd16 | 31953 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 31954 | { |
497d849d TP |
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), | |
34ef62f4 AV |
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), | |
f33026a9 MW |
31976 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is |
31977 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
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), | |
f33026a9 MW |
31983 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is |
31984 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
31985 | ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), |
31986 | ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), | |
497d849d TP |
31987 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), |
31988 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
34ef62f4 | 31989 | ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7), |
c450d570 PB |
31990 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
31991 | Accept the non-dashed form for compatibility with old toolchains. */ | |
34ef62f4 AV |
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), | |
497d849d | 31995 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 AV |
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), | |
497d849d | 31998 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 | 31999 | ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em), |
497d849d | 32000 | ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP), |
34ef62f4 AV |
32001 | ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP, |
32002 | armv8m_main), | |
e0991585 AV |
32003 | ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP, |
32004 | armv8_1m_main), | |
34ef62f4 AV |
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), | |
aab2c27d | 32012 | ARM_ARCH_OPT2 ("armv8.6-a", ARM_ARCH_V8_6A, FPU_ARCH_VFP, armv86a), |
497d849d TP |
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), | |
34ef62f4 | 32016 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 32017 | }; |
f3bad469 | 32018 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 32019 | |
69133863 | 32020 | /* ISA extensions in the co-processor and main instruction set space. */ |
0198d5e6 | 32021 | |
69133863 | 32022 | struct arm_option_extension_value_table |
c19d1205 | 32023 | { |
0198d5e6 TC |
32024 | const char * name; |
32025 | size_t name_len; | |
32026 | const arm_feature_set merge_value; | |
32027 | const arm_feature_set clear_value; | |
d942732e TP |
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. */ | |
0198d5e6 | 32031 | const arm_feature_set allowed_archs[2]; |
c19d1205 | 32032 | }; |
7ed4c4c5 | 32033 | |
0198d5e6 TC |
32034 | /* The following table must be in alphabetical order with a NULL last entry. */ |
32035 | ||
d942732e TP |
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} } | |
0198d5e6 | 32038 | |
34ef62f4 AV |
32039 | /* DEPRECATED: Refrain from using this table to add any new extensions, instead |
32040 | use the context sensitive approach using arm_ext_table's. */ | |
69133863 | 32041 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 32042 | { |
8b301fbb MI |
32043 | ARM_EXT_OPT ("crc", ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC), |
32044 | ARM_FEATURE_CORE_HIGH(ARM_EXT2_CRC), | |
823d2571 | 32045 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), |
bca38921 | 32046 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
823d2571 TG |
32047 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8), |
32048 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
c604a79a JW |
32049 | ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8, |
32050 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD), | |
32051 | ARM_ARCH_V8_2A), | |
15afaa63 TP |
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)), | |
823d2571 TG |
32055 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8), |
32056 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
b8ec4e87 JW |
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), | |
01f48020 TC |
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), | |
d942732e | 32065 | ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
823d2571 | 32066 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
d942732e TP |
32067 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
32068 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
3d030cdb TP |
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)), | |
823d2571 | 32076 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), |
d942732e | 32077 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE), |
823d2571 | 32078 | ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), |
d942732e | 32079 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE), |
823d2571 | 32080 | ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), |
d942732e TP |
32081 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE), |
32082 | ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
823d2571 | 32083 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP), |
d942732e TP |
32084 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
32085 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
823d2571 TG |
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)), | |
ddfded2f MW |
32089 | ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN), |
32090 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0), | |
ced40572 | 32091 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
dad0c3bf SD |
32092 | ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), |
32093 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), | |
32094 | ARM_ARCH_V8A), | |
4d1464f2 MW |
32095 | ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS), |
32096 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0), | |
ced40572 | 32097 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
643afb90 MW |
32098 | ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1, |
32099 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA), | |
ced40572 | 32100 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
7fadb25d SD |
32101 | ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), |
32102 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), | |
32103 | ARM_ARCH_V8A), | |
d942732e | 32104 | ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
823d2571 | 32105 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
d942732e TP |
32106 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K), |
32107 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
643afb90 MW |
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)), | |
823d2571 TG |
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), | |
d942732e TP |
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 } } | |
69133863 | 32118 | }; |
f3bad469 | 32119 | #undef ARM_EXT_OPT |
69133863 MGD |
32120 | |
32121 | /* ISA floating-point and Advanced SIMD extensions. */ | |
32122 | struct arm_option_fpu_value_table | |
32123 | { | |
0198d5e6 TC |
32124 | const char * name; |
32125 | const arm_feature_set value; | |
c19d1205 | 32126 | }; |
7ed4c4c5 | 32127 | |
c19d1205 ZW |
32128 | /* This list should, at a minimum, contain all the fpu names |
32129 | recognized by GCC. */ | |
69133863 | 32130 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
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}, | |
d5e0ba9c | 32144 | {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */ |
c19d1205 ZW |
32145 | {"vfp10", FPU_ARCH_VFP_V2}, |
32146 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
32147 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
32148 | {"vfpv2", FPU_ARCH_VFP_V2}, |
32149 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 32150 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 32151 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
32152 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
32153 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
32154 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
32155 | {"arm1020t", FPU_ARCH_VFP_V1}, |
32156 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 32157 | {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */ |
c19d1205 ZW |
32158 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, |
32159 | {"maverick", FPU_ARCH_MAVERICK}, | |
d5e0ba9c | 32160 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
d3375ddd | 32161 | {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 32162 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
32163 | {"vfpv4", FPU_ARCH_VFP_V4}, |
32164 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 32165 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
a715796b TG |
32166 | {"fpv5-d16", FPU_ARCH_VFP_V5D16}, |
32167 | {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16}, | |
62f3b8c8 | 32168 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
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}, | |
d6b4b13e | 32173 | {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1}, |
081e4c7d MW |
32174 | {"crypto-neon-fp-armv8.1", |
32175 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1}, | |
e74cfd16 PB |
32176 | {NULL, ARM_ARCH_NONE} |
32177 | }; | |
32178 | ||
32179 | struct arm_option_value_table | |
32180 | { | |
e0471c16 | 32181 | const char *name; |
e74cfd16 | 32182 | long value; |
c19d1205 | 32183 | }; |
7ed4c4c5 | 32184 | |
e74cfd16 | 32185 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
32186 | { |
32187 | {"hard", ARM_FLOAT_ABI_HARD}, | |
32188 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
32189 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 32190 | {NULL, 0} |
c19d1205 | 32191 | }; |
7ed4c4c5 | 32192 | |
c19d1205 | 32193 | #ifdef OBJ_ELF |
3a4a14e9 | 32194 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 32195 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
32196 | { |
32197 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
32198 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 32199 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 32200 | {NULL, 0} |
c19d1205 ZW |
32201 | }; |
32202 | #endif | |
7ed4c4c5 | 32203 | |
c19d1205 ZW |
32204 | struct arm_long_option_table |
32205 | { | |
5b7c81bd AM |
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. */ | |
c19d1205 | 32210 | }; |
7ed4c4c5 | 32211 | |
5b7c81bd | 32212 | static bool |
c168ce07 | 32213 | arm_parse_extension (const char *str, const arm_feature_set *opt_set, |
34ef62f4 AV |
32214 | arm_feature_set *ext_set, |
32215 | const struct arm_ext_table *ext_table) | |
7ed4c4c5 | 32216 | { |
69133863 | 32217 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
32218 | extensions being added before being removed. We achieve this by having |
32219 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 32220 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 32221 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
32222 | -1 -> 1 -> 0. */ |
32223 | const struct arm_option_extension_value_table * opt = NULL; | |
d942732e | 32224 | const arm_feature_set arm_any = ARM_ANY; |
69133863 MGD |
32225 | int adding_value = -1; |
32226 | ||
c19d1205 | 32227 | while (str != NULL && *str != 0) |
7ed4c4c5 | 32228 | { |
82b8a785 | 32229 | const char *ext; |
f3bad469 | 32230 | size_t len; |
7ed4c4c5 | 32231 | |
c19d1205 ZW |
32232 | if (*str != '+') |
32233 | { | |
32234 | as_bad (_("invalid architectural extension")); | |
5b7c81bd | 32235 | return false; |
c19d1205 | 32236 | } |
7ed4c4c5 | 32237 | |
c19d1205 ZW |
32238 | str++; |
32239 | ext = strchr (str, '+'); | |
7ed4c4c5 | 32240 | |
c19d1205 | 32241 | if (ext != NULL) |
f3bad469 | 32242 | len = ext - str; |
c19d1205 | 32243 | else |
f3bad469 | 32244 | len = strlen (str); |
7ed4c4c5 | 32245 | |
d34049e8 | 32246 | if (len >= 2 && startswith (str, "no")) |
69133863 MGD |
32247 | { |
32248 | if (adding_value != 0) | |
32249 | { | |
32250 | adding_value = 0; | |
32251 | opt = arm_extensions; | |
32252 | } | |
32253 | ||
f3bad469 | 32254 | len -= 2; |
69133863 MGD |
32255 | str += 2; |
32256 | } | |
f3bad469 | 32257 | else if (len > 0) |
69133863 MGD |
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")); | |
5b7c81bd | 32268 | return false; |
69133863 MGD |
32269 | } |
32270 | } | |
32271 | ||
f3bad469 | 32272 | if (len == 0) |
c19d1205 ZW |
32273 | { |
32274 | as_bad (_("missing architectural extension")); | |
5b7c81bd | 32275 | return false; |
c19d1205 | 32276 | } |
7ed4c4c5 | 32277 | |
69133863 MGD |
32278 | gas_assert (adding_value != -1); |
32279 | gas_assert (opt != NULL); | |
32280 | ||
34ef62f4 AV |
32281 | if (ext_table != NULL) |
32282 | { | |
32283 | const struct arm_ext_table * ext_opt = ext_table; | |
5b7c81bd | 32284 | bool found = false; |
34ef62f4 AV |
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 | } | |
5b7c81bd | 32306 | found = true; |
34ef62f4 AV |
32307 | break; |
32308 | } | |
32309 | if (found) | |
32310 | { | |
32311 | str = ext; | |
32312 | continue; | |
32313 | } | |
32314 | } | |
32315 | ||
69133863 MGD |
32316 | /* Scan over the options table trying to find an exact match. */ |
32317 | for (; opt->name != NULL; opt++) | |
f3bad469 | 32318 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 32319 | { |
d942732e TP |
32320 | int i, nb_allowed_archs = |
32321 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
69133863 | 32322 | /* Check we can apply the extension to this architecture. */ |
d942732e TP |
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; | |
c168ce07 | 32328 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set)) |
d942732e TP |
32329 | break; |
32330 | } | |
32331 | if (i == nb_allowed_archs) | |
69133863 MGD |
32332 | { |
32333 | as_bad (_("extension does not apply to the base architecture")); | |
5b7c81bd | 32334 | return false; |
69133863 MGD |
32335 | } |
32336 | ||
32337 | /* Add or remove the extension. */ | |
32338 | if (adding_value) | |
4d354d8b | 32339 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value); |
69133863 | 32340 | else |
4d354d8b | 32341 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value); |
69133863 | 32342 | |
3d030cdb TP |
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. */ | |
c19d1205 ZW |
32347 | break; |
32348 | } | |
7ed4c4c5 | 32349 | |
c19d1205 ZW |
32350 | if (opt->name == NULL) |
32351 | { | |
69133863 MGD |
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++) | |
f3bad469 | 32356 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
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 | ||
5b7c81bd | 32365 | return false; |
c19d1205 | 32366 | } |
69133863 MGD |
32367 | else |
32368 | { | |
32369 | /* We should skip the extension we've just matched the next time | |
32370 | round. */ | |
32371 | opt++; | |
32372 | } | |
7ed4c4c5 | 32373 | |
c19d1205 ZW |
32374 | str = ext; |
32375 | }; | |
7ed4c4c5 | 32376 | |
5b7c81bd | 32377 | return true; |
c19d1205 | 32378 | } |
7ed4c4c5 | 32379 | |
5b7c81bd | 32380 | static bool |
5312fe52 BW |
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); | |
5b7c81bd | 32390 | return false; |
5312fe52 BW |
32391 | } |
32392 | ||
5b7c81bd | 32393 | return true; |
5312fe52 BW |
32394 | } |
32395 | ||
5b7c81bd | 32396 | static bool |
17b9d67d | 32397 | arm_parse_cpu (const char *str) |
7ed4c4c5 | 32398 | { |
f3bad469 | 32399 | const struct arm_cpu_option_table *opt; |
82b8a785 | 32400 | const char *ext = strchr (str, '+'); |
f3bad469 | 32401 | size_t len; |
7ed4c4c5 | 32402 | |
c19d1205 | 32403 | if (ext != NULL) |
f3bad469 | 32404 | len = ext - str; |
7ed4c4c5 | 32405 | else |
f3bad469 | 32406 | len = strlen (str); |
7ed4c4c5 | 32407 | |
f3bad469 | 32408 | if (len == 0) |
7ed4c4c5 | 32409 | { |
c19d1205 | 32410 | as_bad (_("missing cpu name `%s'"), str); |
5b7c81bd | 32411 | return false; |
7ed4c4c5 NC |
32412 | } |
32413 | ||
c19d1205 | 32414 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 32415 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 32416 | { |
c168ce07 | 32417 | mcpu_cpu_opt = &opt->value; |
4d354d8b TP |
32418 | if (mcpu_ext_opt == NULL) |
32419 | mcpu_ext_opt = XNEW (arm_feature_set); | |
32420 | *mcpu_ext_opt = opt->ext; | |
e74cfd16 | 32421 | mcpu_fpu_opt = &opt->default_fpu; |
ee065d83 | 32422 | if (opt->canonical_name) |
ef8e6722 JW |
32423 | { |
32424 | gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name)); | |
32425 | strcpy (selected_cpu_name, opt->canonical_name); | |
32426 | } | |
ee065d83 PB |
32427 | else |
32428 | { | |
f3bad469 | 32429 | size_t i; |
c921be7d | 32430 | |
ef8e6722 JW |
32431 | if (len >= sizeof selected_cpu_name) |
32432 | len = (sizeof selected_cpu_name) - 1; | |
32433 | ||
f3bad469 | 32434 | for (i = 0; i < len; i++) |
ee065d83 PB |
32435 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
32436 | selected_cpu_name[i] = 0; | |
32437 | } | |
7ed4c4c5 | 32438 | |
c19d1205 | 32439 | if (ext != NULL) |
34ef62f4 | 32440 | return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL); |
7ed4c4c5 | 32441 | |
5b7c81bd | 32442 | return true; |
c19d1205 | 32443 | } |
7ed4c4c5 | 32444 | |
c19d1205 | 32445 | as_bad (_("unknown cpu `%s'"), str); |
5b7c81bd | 32446 | return false; |
7ed4c4c5 NC |
32447 | } |
32448 | ||
5b7c81bd | 32449 | static bool |
17b9d67d | 32450 | arm_parse_arch (const char *str) |
7ed4c4c5 | 32451 | { |
e74cfd16 | 32452 | const struct arm_arch_option_table *opt; |
82b8a785 | 32453 | const char *ext = strchr (str, '+'); |
f3bad469 | 32454 | size_t len; |
7ed4c4c5 | 32455 | |
c19d1205 | 32456 | if (ext != NULL) |
f3bad469 | 32457 | len = ext - str; |
7ed4c4c5 | 32458 | else |
f3bad469 | 32459 | len = strlen (str); |
7ed4c4c5 | 32460 | |
f3bad469 | 32461 | if (len == 0) |
7ed4c4c5 | 32462 | { |
c19d1205 | 32463 | as_bad (_("missing architecture name `%s'"), str); |
5b7c81bd | 32464 | return false; |
7ed4c4c5 NC |
32465 | } |
32466 | ||
c19d1205 | 32467 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 32468 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 32469 | { |
e74cfd16 | 32470 | march_cpu_opt = &opt->value; |
4d354d8b TP |
32471 | if (march_ext_opt == NULL) |
32472 | march_ext_opt = XNEW (arm_feature_set); | |
32473 | *march_ext_opt = arm_arch_none; | |
e74cfd16 | 32474 | march_fpu_opt = &opt->default_fpu; |
e20f9590 | 32475 | selected_ctx_ext_table = opt->ext_table; |
5f4273c7 | 32476 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 32477 | |
c19d1205 | 32478 | if (ext != NULL) |
34ef62f4 AV |
32479 | return arm_parse_extension (ext, march_cpu_opt, march_ext_opt, |
32480 | opt->ext_table); | |
7ed4c4c5 | 32481 | |
5b7c81bd | 32482 | return true; |
c19d1205 ZW |
32483 | } |
32484 | ||
32485 | as_bad (_("unknown architecture `%s'\n"), str); | |
5b7c81bd | 32486 | return false; |
7ed4c4c5 | 32487 | } |
eb043451 | 32488 | |
5b7c81bd | 32489 | static bool |
17b9d67d | 32490 | arm_parse_fpu (const char * str) |
c19d1205 | 32491 | { |
69133863 | 32492 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 32493 | |
c19d1205 ZW |
32494 | for (opt = arm_fpus; opt->name != NULL; opt++) |
32495 | if (streq (opt->name, str)) | |
32496 | { | |
e74cfd16 | 32497 | mfpu_opt = &opt->value; |
5b7c81bd | 32498 | return true; |
c19d1205 | 32499 | } |
b99bd4ef | 32500 | |
c19d1205 | 32501 | as_bad (_("unknown floating point format `%s'\n"), str); |
5b7c81bd | 32502 | return false; |
c19d1205 ZW |
32503 | } |
32504 | ||
5b7c81bd | 32505 | static bool |
17b9d67d | 32506 | arm_parse_float_abi (const char * str) |
b99bd4ef | 32507 | { |
e74cfd16 | 32508 | const struct arm_option_value_table * opt; |
b99bd4ef | 32509 | |
c19d1205 ZW |
32510 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
32511 | if (streq (opt->name, str)) | |
32512 | { | |
32513 | mfloat_abi_opt = opt->value; | |
5b7c81bd | 32514 | return true; |
c19d1205 | 32515 | } |
cc8a6dd0 | 32516 | |
c19d1205 | 32517 | as_bad (_("unknown floating point abi `%s'\n"), str); |
5b7c81bd | 32518 | return false; |
c19d1205 | 32519 | } |
b99bd4ef | 32520 | |
c19d1205 | 32521 | #ifdef OBJ_ELF |
5b7c81bd | 32522 | static bool |
17b9d67d | 32523 | arm_parse_eabi (const char * str) |
c19d1205 | 32524 | { |
e74cfd16 | 32525 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 32526 | |
c19d1205 ZW |
32527 | for (opt = arm_eabis; opt->name != NULL; opt++) |
32528 | if (streq (opt->name, str)) | |
32529 | { | |
32530 | meabi_flags = opt->value; | |
5b7c81bd | 32531 | return true; |
c19d1205 ZW |
32532 | } |
32533 | as_bad (_("unknown EABI `%s'\n"), str); | |
5b7c81bd | 32534 | return false; |
c19d1205 ZW |
32535 | } |
32536 | #endif | |
cc8a6dd0 | 32537 | |
5b7c81bd | 32538 | static bool |
17b9d67d | 32539 | arm_parse_it_mode (const char * str) |
e07e6e58 | 32540 | { |
5b7c81bd | 32541 | bool ret = true; |
e07e6e58 NC |
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 "\ | |
477330fc | 32554 | "arm, thumb, always, or never."), str); |
5b7c81bd | 32555 | ret = false; |
e07e6e58 NC |
32556 | } |
32557 | ||
32558 | return ret; | |
32559 | } | |
32560 | ||
5b7c81bd | 32561 | static bool |
17b9d67d | 32562 | arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED) |
2e6976a8 | 32563 | { |
5b7c81bd | 32564 | codecomposer_syntax = true; |
2e6976a8 DG |
32565 | arm_comment_chars[0] = ';'; |
32566 | arm_line_separator_chars[0] = 0; | |
5b7c81bd | 32567 | return true; |
2e6976a8 DG |
32568 | } |
32569 | ||
c19d1205 ZW |
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 | |
7fac0536 | 32581 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
32582 | arm_parse_eabi, NULL}, |
32583 | #endif | |
e07e6e58 NC |
32584 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
32585 | arm_parse_it_mode, NULL}, | |
2e6976a8 DG |
32586 | {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"), |
32587 | arm_ccs_mode, NULL}, | |
5312fe52 BW |
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 }, | |
c19d1205 ZW |
32594 | {NULL, NULL, 0, NULL} |
32595 | }; | |
cc8a6dd0 | 32596 | |
c19d1205 | 32597 | int |
17b9d67d | 32598 | md_parse_option (int c, const char * arg) |
c19d1205 ZW |
32599 | { |
32600 | struct arm_option_table *opt; | |
e74cfd16 | 32601 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 32602 | struct arm_long_option_table *lopt; |
b99bd4ef | 32603 | |
c19d1205 | 32604 | switch (c) |
b99bd4ef | 32605 | { |
c19d1205 ZW |
32606 | #ifdef OPTION_EB |
32607 | case OPTION_EB: | |
32608 | target_big_endian = 1; | |
32609 | break; | |
32610 | #endif | |
cc8a6dd0 | 32611 | |
c19d1205 ZW |
32612 | #ifdef OPTION_EL |
32613 | case OPTION_EL: | |
32614 | target_big_endian = 0; | |
32615 | break; | |
32616 | #endif | |
b99bd4ef | 32617 | |
845b51d6 | 32618 | case OPTION_FIX_V4BX: |
5b7c81bd | 32619 | fix_v4bx = true; |
845b51d6 PB |
32620 | break; |
32621 | ||
18a20338 CL |
32622 | #ifdef OBJ_ELF |
32623 | case OPTION_FDPIC: | |
5b7c81bd | 32624 | arm_fdpic = true; |
18a20338 CL |
32625 | break; |
32626 | #endif /* OBJ_ELF */ | |
32627 | ||
c19d1205 ZW |
32628 | case 'a': |
32629 | /* Listing option. Just ignore these, we don't support additional | |
32630 | ones. */ | |
32631 | return 0; | |
b99bd4ef | 32632 | |
c19d1205 ZW |
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 | { | |
c19d1205 | 32640 | /* If the option is deprecated, tell the user. */ |
278df34e | 32641 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
32642 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
32643 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 32644 | |
c19d1205 ZW |
32645 | if (opt->var != NULL) |
32646 | *opt->var = opt->value; | |
cc8a6dd0 | 32647 | |
c19d1205 ZW |
32648 | return 1; |
32649 | } | |
32650 | } | |
b99bd4ef | 32651 | |
e74cfd16 PB |
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 | { | |
e74cfd16 | 32658 | /* If the option is deprecated, tell the user. */ |
278df34e | 32659 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
32660 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
32661 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
32662 | |
32663 | if (fopt->var != NULL) | |
32664 | *fopt->var = &fopt->value; | |
32665 | ||
32666 | return 1; | |
32667 | } | |
32668 | } | |
32669 | ||
c19d1205 ZW |
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 | { | |
c19d1205 | 32678 | /* If the option is deprecated, tell the user. */ |
278df34e | 32679 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
32680 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
32681 | _(lopt->deprecated)); | |
b99bd4ef | 32682 | |
c19d1205 ZW |
32683 | /* Call the sup-option parser. */ |
32684 | return lopt->func (arg + strlen (lopt->option) - 1); | |
32685 | } | |
32686 | } | |
a737bd4d | 32687 | |
c19d1205 ZW |
32688 | return 0; |
32689 | } | |
a394c00f | 32690 | |
c19d1205 ZW |
32691 | return 1; |
32692 | } | |
a394c00f | 32693 | |
c19d1205 ZW |
32694 | void |
32695 | md_show_usage (FILE * fp) | |
a394c00f | 32696 | { |
c19d1205 ZW |
32697 | struct arm_option_table *opt; |
32698 | struct arm_long_option_table *lopt; | |
a394c00f | 32699 | |
c19d1205 | 32700 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 32701 | |
c19d1205 ZW |
32702 | for (opt = arm_opts; opt->option != NULL; opt++) |
32703 | if (opt->help != NULL) | |
32704 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 32705 | |
c19d1205 ZW |
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)); | |
a394c00f | 32709 | |
c19d1205 ZW |
32710 | #ifdef OPTION_EB |
32711 | fprintf (fp, _("\ | |
32712 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
32713 | #endif |
32714 | ||
c19d1205 ZW |
32715 | #ifdef OPTION_EL |
32716 | fprintf (fp, _("\ | |
32717 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 32718 | #endif |
845b51d6 PB |
32719 | |
32720 | fprintf (fp, _("\ | |
32721 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
18a20338 CL |
32722 | |
32723 | #ifdef OBJ_ELF | |
32724 | fprintf (fp, _("\ | |
32725 | --fdpic generate an FDPIC object file\n")); | |
32726 | #endif /* OBJ_ELF */ | |
c19d1205 | 32727 | } |
ee065d83 | 32728 | |
ee065d83 | 32729 | #ifdef OBJ_ELF |
0198d5e6 | 32730 | |
62b3e311 PB |
32731 | typedef struct |
32732 | { | |
32733 | int val; | |
32734 | arm_feature_set flags; | |
32735 | } cpu_arch_ver_table; | |
32736 | ||
2c6b98ea TP |
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. */ | |
62b3e311 PB |
32742 | static const cpu_arch_ver_table cpu_arch_ver[] = |
32743 | { | |
031254f2 AV |
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}, | |
2c6b98ea TP |
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. */ | |
031254f2 AV |
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}, | |
aab2c27d MM |
32795 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_6A}, |
32796 | {-1, ARM_ARCH_NONE} | |
62b3e311 PB |
32797 | }; |
32798 | ||
ee3c0378 | 32799 | /* Set an attribute if it has not already been set by the user. */ |
0198d5e6 | 32800 | |
ee3c0378 AS |
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 | ||
2c6b98ea TP |
32819 | /* Return whether features in the *NEEDED feature set are available via |
32820 | extensions for the architecture whose feature set is *ARCH_FSET. */ | |
0198d5e6 | 32821 | |
5b7c81bd | 32822 | static bool |
2c6b98ea TP |
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. */ | |
0198d5e6 | 32865 | |
2c6b98ea TP |
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. */ | |
031254f2 | 32879 | gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN); |
2c6b98ea TP |
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 | ||
dc1e8a47 | 32951 | found: |
2c6b98ea | 32952 | /* Tag_CPU_arch_profile. */ |
164446e0 AF |
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)))) | |
2c6b98ea | 32958 | *profile = 'A'; |
164446e0 AF |
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)) | |
2c6b98ea TP |
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 | ||
ee065d83 | 32969 | /* Set the public EABI object attributes. */ |
0198d5e6 | 32970 | |
c168ce07 | 32971 | static void |
ee065d83 PB |
32972 | aeabi_set_public_attributes (void) |
32973 | { | |
b90d5ba0 | 32974 | char profile = '\0'; |
2c6b98ea | 32975 | int arch = -1; |
90ec0d68 | 32976 | int virt_sec = 0; |
bca38921 | 32977 | int fp16_optional = 0; |
2c6b98ea TP |
32978 | int skip_exact_match = 0; |
32979 | arm_feature_set flags, flags_arch, flags_ext; | |
ee065d83 | 32980 | |
54bab281 TP |
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); | |
ddd7f988 | 32986 | |
54bab281 TP |
32987 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) |
32988 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
ddd7f988 | 32989 | |
54bab281 TP |
32990 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) |
32991 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
ddd7f988 | 32992 | |
54bab281 | 32993 | /* Code run during relaxation relies on selected_cpu being set. */ |
4d354d8b TP |
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; | |
54bab281 TP |
32998 | selected_cpu = flags; |
32999 | } | |
33000 | /* Otherwise, choose the architecture based on the capabilities of the | |
33001 | requested cpu. */ | |
33002 | else | |
4d354d8b TP |
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); | |
7f78eb34 | 33010 | |
ddd7f988 | 33011 | /* Allow the user to override the reported architecture. */ |
4d354d8b | 33012 | if (!ARM_FEATURE_ZERO (selected_object_arch)) |
7a1d4c38 | 33013 | { |
4d354d8b | 33014 | ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any); |
2c6b98ea | 33015 | flags_ext = arm_arch_none; |
7a1d4c38 | 33016 | } |
2c6b98ea | 33017 | else |
4d354d8b | 33018 | skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any); |
2c6b98ea TP |
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")); | |
9e3c6df6 | 33033 | |
ee065d83 PB |
33034 | /* Tag_CPU_name. */ |
33035 | if (selected_cpu_name[0]) | |
33036 | { | |
91d6fa6a | 33037 | char *q; |
ee065d83 | 33038 | |
91d6fa6a | 33039 | q = selected_cpu_name; |
d34049e8 | 33040 | if (startswith (q, "armv")) |
ee065d83 PB |
33041 | { |
33042 | int i; | |
5f4273c7 | 33043 | |
91d6fa6a NC |
33044 | q += 4; |
33045 | for (i = 0; q[i]; i++) | |
33046 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 33047 | } |
91d6fa6a | 33048 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 33049 | } |
62f3b8c8 | 33050 | |
ee065d83 | 33051 | /* Tag_CPU_arch. */ |
ee3c0378 | 33052 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 33053 | |
62b3e311 | 33054 | /* Tag_CPU_arch_profile. */ |
69239280 MGD |
33055 | if (profile != '\0') |
33056 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 33057 | |
15afaa63 | 33058 | /* Tag_DSP_extension. */ |
4d354d8b | 33059 | if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp)) |
6c290d53 | 33060 | aeabi_set_attribute_int (Tag_DSP_extension, 1); |
15afaa63 | 33061 | |
2c6b98ea | 33062 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
ee065d83 | 33063 | /* Tag_ARM_ISA_use. */ |
ee3c0378 | 33064 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
2c6b98ea | 33065 | || ARM_FEATURE_ZERO (flags_arch)) |
ee3c0378 | 33066 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); |
62f3b8c8 | 33067 | |
ee065d83 | 33068 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 | 33069 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
2c6b98ea | 33070 | || ARM_FEATURE_ZERO (flags_arch)) |
4ed7ed8d TP |
33071 | { |
33072 | int thumb_isa_use; | |
33073 | ||
33074 | if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) | |
16a1fa25 | 33075 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)) |
4ed7ed8d TP |
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 | } | |
62f3b8c8 | 33083 | |
ee065d83 | 33084 | /* Tag_VFP_arch. */ |
a715796b TG |
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); | |
bca38921 | 33089 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
62f3b8c8 PB |
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)) | |
bca38921 MGD |
33094 | { |
33095 | fp16_optional = 1; | |
33096 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
33097 | } | |
ada65aa3 | 33098 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
33099 | { |
33100 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
33101 | fp16_optional = 1; | |
33102 | } | |
ee3c0378 AS |
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) | |
477330fc | 33106 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) |
ee3c0378 | 33107 | aeabi_set_attribute_int (Tag_VFP_arch, 1); |
62f3b8c8 | 33108 | |
4547cb56 NC |
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 | ||
ee065d83 | 33114 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
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); | |
62f3b8c8 | 33119 | |
ee3c0378 | 33120 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
9411fd44 MW |
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)) | |
bca38921 MGD |
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 | } | |
fa94de6b | 33137 | |
a7ad558c AV |
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 | ||
ee3c0378 | 33143 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 33144 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 33145 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 33146 | |
69239280 MGD |
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 | ||
4ed7ed8d TP |
33153 | For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied |
33154 | by the base architecture. | |
bca38921 | 33155 | |
69239280 | 33156 | For new architectures we will have to check these tests. */ |
031254f2 | 33157 | gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN); |
4ed7ed8d TP |
33158 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
33159 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
bca38921 MGD |
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))) | |
eea54501 | 33165 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
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); | |
f4c65163 MGD |
33170 | |
33171 | /* Tag Virtualization_use. */ | |
33172 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
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); | |
5312fe52 BW |
33178 | |
33179 | if (fp16_format != ARM_FP16_FORMAT_DEFAULT) | |
33180 | aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format); | |
ee065d83 PB |
33181 | } |
33182 | ||
c168ce07 TP |
33183 | /* Post relaxation hook. Recompute ARM attributes now that relaxation is |
33184 | finished and free extension feature bits which will not be used anymore. */ | |
0198d5e6 | 33185 | |
c168ce07 TP |
33186 | void |
33187 | arm_md_post_relax (void) | |
33188 | { | |
33189 | aeabi_set_public_attributes (); | |
4d354d8b TP |
33190 | XDELETE (mcpu_ext_opt); |
33191 | mcpu_ext_opt = NULL; | |
33192 | XDELETE (march_ext_opt); | |
33193 | march_ext_opt = NULL; | |
c168ce07 TP |
33194 | } |
33195 | ||
104d59d1 | 33196 | /* Add the default contents for the .ARM.attributes section. */ |
0198d5e6 | 33197 | |
ee065d83 PB |
33198 | void |
33199 | arm_md_end (void) | |
33200 | { | |
ee065d83 PB |
33201 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
33202 | return; | |
33203 | ||
33204 | aeabi_set_public_attributes (); | |
ee065d83 | 33205 | } |
8463be01 | 33206 | #endif /* OBJ_ELF */ |
ee065d83 | 33207 | |
ee065d83 PB |
33208 | /* Parse a .cpu directive. */ |
33209 | ||
33210 | static void | |
33211 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
33212 | { | |
e74cfd16 | 33213 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
33214 | char *name; |
33215 | char saved_char; | |
33216 | ||
33217 | name = input_line_pointer; | |
5f4273c7 | 33218 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
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 | { | |
4d354d8b TP |
33227 | selected_arch = opt->value; |
33228 | selected_ext = opt->ext; | |
33229 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); | |
ee065d83 | 33230 | if (opt->canonical_name) |
5f4273c7 | 33231 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
33232 | else |
33233 | { | |
33234 | int i; | |
33235 | for (i = 0; opt->name[i]; i++) | |
33236 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 33237 | |
ee065d83 PB |
33238 | selected_cpu_name[i] = 0; |
33239 | } | |
4d354d8b TP |
33240 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
33241 | ||
ee065d83 PB |
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 | ||
ee065d83 PB |
33251 | /* Parse a .arch directive. */ |
33252 | ||
33253 | static void | |
33254 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
33255 | { | |
e74cfd16 | 33256 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
33257 | char saved_char; |
33258 | char *name; | |
33259 | ||
33260 | name = input_line_pointer; | |
5f4273c7 | 33261 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
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 | { | |
4d354d8b | 33270 | selected_arch = opt->value; |
0e7aaa72 | 33271 | selected_ctx_ext_table = opt->ext_table; |
4d354d8b TP |
33272 | selected_ext = arm_arch_none; |
33273 | selected_cpu = selected_arch; | |
5f4273c7 | 33274 | strcpy (selected_cpu_name, opt->name); |
4d354d8b | 33275 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 PB |
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 | ||
7a1d4c38 PB |
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; | |
5f4273c7 | 33296 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
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 | { | |
4d354d8b | 33305 | selected_object_arch = opt->value; |
7a1d4c38 PB |
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 | ||
69133863 MGD |
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 | |
d34049e8 | 33333 | && startswith (name, "no")) |
69133863 MGD |
33334 | { |
33335 | adding_value = 0; | |
33336 | name += 2; | |
33337 | } | |
33338 | ||
e20f9590 MI |
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 | ||
69133863 MGD |
33368 | for (opt = arm_extensions; opt->name != NULL; opt++) |
33369 | if (streq (opt->name, name)) | |
33370 | { | |
d942732e TP |
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. */ | |
4d354d8b | 33376 | if (ARM_CPU_IS_ANY (opt->allowed_archs[i])) |
d942732e | 33377 | continue; |
4d354d8b | 33378 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch)) |
d942732e TP |
33379 | break; |
33380 | } | |
33381 | ||
33382 | if (i == nb_allowed_archs) | |
69133863 MGD |
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) | |
4d354d8b | 33390 | ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext, |
5a70a223 | 33391 | opt->merge_value); |
69133863 | 33392 | else |
4d354d8b | 33393 | ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value); |
69133863 | 33394 | |
4d354d8b TP |
33395 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
33396 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
69133863 MGD |
33397 | *input_line_pointer = saved_char; |
33398 | demand_empty_rest_of_line (); | |
3d030cdb TP |
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. */ | |
69133863 MGD |
33403 | return; |
33404 | } | |
33405 | ||
33406 | if (opt->name == NULL) | |
e673710a | 33407 | as_bad (_("unknown architecture extension `%s'\n"), name); |
69133863 MGD |
33408 | |
33409 | *input_line_pointer = saved_char; | |
33410 | ignore_rest_of_line (); | |
33411 | } | |
33412 | ||
ee065d83 PB |
33413 | /* Parse a .fpu directive. */ |
33414 | ||
33415 | static void | |
33416 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
33417 | { | |
69133863 | 33418 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
33419 | char saved_char; |
33420 | char *name; | |
33421 | ||
33422 | name = input_line_pointer; | |
5f4273c7 | 33423 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
33424 | input_line_pointer++; |
33425 | saved_char = *input_line_pointer; | |
33426 | *input_line_pointer = 0; | |
5f4273c7 | 33427 | |
ee065d83 PB |
33428 | for (opt = arm_fpus; opt->name != NULL; opt++) |
33429 | if (streq (opt->name, name)) | |
33430 | { | |
4d354d8b | 33431 | selected_fpu = opt->value; |
f4399880 | 33432 | ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, fpu_any); |
4d354d8b TP |
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); | |
ee065d83 PB |
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 | } | |
ee065d83 | 33448 | |
794ba86a | 33449 | /* Copy symbol information. */ |
f31fef98 | 33450 | |
794ba86a DJ |
33451 | void |
33452 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
33453 | { | |
33454 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
33455 | } | |
e04befd0 | 33456 | |
f31fef98 | 33457 | #ifdef OBJ_ELF |
e04befd0 AS |
33458 | /* Given a symbolic attribute NAME, return the proper integer value. |
33459 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 33460 | |
e04befd0 AS |
33461 | int |
33462 | arm_convert_symbolic_attribute (const char *name) | |
33463 | { | |
f31fef98 NC |
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. */ | |
e04befd0 | 33473 | #define T(tag) {#tag, tag} |
f31fef98 NC |
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), | |
75375b3e | 33480 | T (Tag_FP_arch), |
f31fef98 NC |
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), | |
75375b3e | 33495 | T (Tag_ABI_align_needed), |
f31fef98 | 33496 | T (Tag_ABI_align8_needed), |
75375b3e | 33497 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
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), | |
75375b3e | 33507 | T (Tag_FP_HP_extension), |
f31fef98 NC |
33508 | T (Tag_VFP_HP_extension), |
33509 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
33510 | T (Tag_MPextension_use), |
33511 | T (Tag_DIV_use), | |
f31fef98 NC |
33512 | T (Tag_nodefaults), |
33513 | T (Tag_also_compatible_with), | |
33514 | T (Tag_conformance), | |
33515 | T (Tag_T2EE_use), | |
33516 | T (Tag_Virtualization_use), | |
15afaa63 | 33517 | T (Tag_DSP_extension), |
a7ad558c | 33518 | T (Tag_MVE_arch), |
99db83d0 | 33519 | T (Tag_PAC_extension), |
4b535030 | 33520 | T (Tag_BTI_extension), |
b81ee92f | 33521 | T (Tag_BTI_use), |
cd21e546 | 33522 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 33523 | #undef T |
f31fef98 | 33524 | }; |
e04befd0 AS |
33525 | unsigned int i; |
33526 | ||
33527 | if (name == NULL) | |
33528 | return -1; | |
33529 | ||
f31fef98 | 33530 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 33531 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
33532 | return attribute_table[i].tag; |
33533 | ||
33534 | return -1; | |
33535 | } | |
267bf995 | 33536 | |
93ef582d NC |
33537 | /* Apply sym value for relocations only in the case that they are for |
33538 | local symbols in the same segment as the fixup and you have the | |
33539 | respective architectural feature for blx and simple switches. */ | |
0198d5e6 | 33540 | |
267bf995 | 33541 | int |
93ef582d | 33542 | arm_apply_sym_value (struct fix * fixP, segT this_seg) |
267bf995 RR |
33543 | { |
33544 | if (fixP->fx_addsy | |
33545 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
93ef582d NC |
33546 | /* PR 17444: If the local symbol is in a different section then a reloc |
33547 | will always be generated for it, so applying the symbol value now | |
33548 | will result in a double offset being stored in the relocation. */ | |
33549 | && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg) | |
5b7c81bd | 33550 | && !S_FORCE_RELOC (fixP->fx_addsy, true)) |
267bf995 RR |
33551 | { |
33552 | switch (fixP->fx_r_type) | |
33553 | { | |
33554 | case BFD_RELOC_ARM_PCREL_BLX: | |
33555 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
33556 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
33557 | return 1; | |
33558 | break; | |
33559 | ||
33560 | case BFD_RELOC_ARM_PCREL_CALL: | |
33561 | case BFD_RELOC_THUMB_PCREL_BLX: | |
33562 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
93ef582d | 33563 | return 1; |
267bf995 RR |
33564 | break; |
33565 | ||
33566 | default: | |
33567 | break; | |
33568 | } | |
33569 | ||
33570 | } | |
33571 | return 0; | |
33572 | } | |
f31fef98 | 33573 | #endif /* OBJ_ELF */ |