Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
82704155 | 2 | Copyright (C) 1994-2019 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 RE |
34 | #include "opcode/arm.h" |
35 | ||
b99bd4ef NC |
36 | #ifdef OBJ_ELF |
37 | #include "elf/arm.h" | |
a394c00f | 38 | #include "dw2gencfi.h" |
b99bd4ef NC |
39 | #endif |
40 | ||
f0927246 NC |
41 | #include "dwarf2dbg.h" |
42 | ||
7ed4c4c5 NC |
43 | #ifdef OBJ_ELF |
44 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
45 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
46 | ||
47 | /* This structure holds the unwinding state. */ | |
48 | ||
49 | static struct | |
50 | { | |
c19d1205 ZW |
51 | symbolS * proc_start; |
52 | symbolS * table_entry; | |
53 | symbolS * personality_routine; | |
54 | int personality_index; | |
7ed4c4c5 | 55 | /* The segment containing the function. */ |
c19d1205 ZW |
56 | segT saved_seg; |
57 | subsegT saved_subseg; | |
7ed4c4c5 NC |
58 | /* Opcodes generated from this function. */ |
59 | unsigned char * opcodes; | |
c19d1205 ZW |
60 | int opcode_count; |
61 | int opcode_alloc; | |
7ed4c4c5 | 62 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 63 | offsetT frame_size; |
7ed4c4c5 NC |
64 | /* We don't add stack adjustment opcodes immediately so that we can merge |
65 | multiple adjustments. We can also omit the final adjustment | |
66 | when using a frame pointer. */ | |
c19d1205 | 67 | offsetT pending_offset; |
7ed4c4c5 | 68 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
69 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
70 | offsetT fp_offset; | |
71 | int fp_reg; | |
7ed4c4c5 | 72 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 73 | unsigned fp_used:1; |
7ed4c4c5 | 74 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 75 | unsigned sp_restored:1; |
7ed4c4c5 NC |
76 | } unwind; |
77 | ||
18a20338 CL |
78 | /* Whether --fdpic was given. */ |
79 | static int arm_fdpic; | |
80 | ||
8b1ad454 NC |
81 | #endif /* OBJ_ELF */ |
82 | ||
4962c51a MS |
83 | /* Results from operand parsing worker functions. */ |
84 | ||
85 | typedef enum | |
86 | { | |
87 | PARSE_OPERAND_SUCCESS, | |
88 | PARSE_OPERAND_FAIL, | |
89 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
90 | } parse_operand_result; | |
91 | ||
33a392fb PB |
92 | enum arm_float_abi |
93 | { | |
94 | ARM_FLOAT_ABI_HARD, | |
95 | ARM_FLOAT_ABI_SOFTFP, | |
96 | ARM_FLOAT_ABI_SOFT | |
97 | }; | |
98 | ||
c19d1205 | 99 | /* Types of processor to assemble for. */ |
b99bd4ef | 100 | #ifndef CPU_DEFAULT |
8a59fff3 | 101 | /* The code that was here used to select a default CPU depending on compiler |
fa94de6b | 102 | pre-defines which were only present when doing native builds, thus |
8a59fff3 MGD |
103 | changing gas' default behaviour depending upon the build host. |
104 | ||
105 | If you have a target that requires a default CPU option then the you | |
106 | should define CPU_DEFAULT here. */ | |
b99bd4ef NC |
107 | #endif |
108 | ||
109 | #ifndef FPU_DEFAULT | |
c820d418 MM |
110 | # ifdef TE_LINUX |
111 | # define FPU_DEFAULT FPU_ARCH_FPA | |
112 | # elif defined (TE_NetBSD) | |
113 | # ifdef OBJ_ELF | |
114 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
115 | # else | |
116 | /* Legacy a.out format. */ | |
117 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
118 | # endif | |
4e7fd91e PB |
119 | # elif defined (TE_VXWORKS) |
120 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
121 | # else |
122 | /* For backwards compatibility, default to FPA. */ | |
123 | # define FPU_DEFAULT FPU_ARCH_FPA | |
124 | # endif | |
125 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 126 | |
c19d1205 | 127 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 128 | |
4d354d8b TP |
129 | /* Current set of feature bits available (CPU+FPU). Different from |
130 | selected_cpu + selected_fpu in case of autodetection since the CPU | |
131 | feature bits are then all set. */ | |
e74cfd16 | 132 | static arm_feature_set cpu_variant; |
4d354d8b TP |
133 | /* Feature bits used in each execution state. Used to set build attribute |
134 | (in particular Tag_*_ISA_use) in CPU autodetection mode. */ | |
e74cfd16 PB |
135 | static arm_feature_set arm_arch_used; |
136 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 137 | |
b99bd4ef | 138 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
139 | static int uses_apcs_26 = FALSE; |
140 | static int atpcs = FALSE; | |
b34976b6 AM |
141 | static int support_interwork = FALSE; |
142 | static int uses_apcs_float = FALSE; | |
c19d1205 | 143 | static int pic_code = FALSE; |
845b51d6 | 144 | static int fix_v4bx = FALSE; |
278df34e NS |
145 | /* Warn on using deprecated features. */ |
146 | static int warn_on_deprecated = TRUE; | |
147 | ||
2e6976a8 DG |
148 | /* Understand CodeComposer Studio assembly syntax. */ |
149 | bfd_boolean codecomposer_syntax = FALSE; | |
03b1477f RE |
150 | |
151 | /* Variables that we set while parsing command-line options. Once all | |
152 | options have been read we re-process these values to set the real | |
153 | assembly flags. */ | |
4d354d8b TP |
154 | |
155 | /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1 | |
156 | instead of -mcpu=arm1). */ | |
157 | static const arm_feature_set *legacy_cpu = NULL; | |
158 | static const arm_feature_set *legacy_fpu = NULL; | |
159 | ||
160 | /* CPU, extension and FPU feature bits selected by -mcpu. */ | |
161 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
162 | static arm_feature_set *mcpu_ext_opt = NULL; | |
163 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
164 | ||
165 | /* CPU, extension and FPU feature bits selected by -march. */ | |
166 | static const arm_feature_set *march_cpu_opt = NULL; | |
167 | static arm_feature_set *march_ext_opt = NULL; | |
168 | static const arm_feature_set *march_fpu_opt = NULL; | |
169 | ||
170 | /* Feature bits selected by -mfpu. */ | |
171 | static const arm_feature_set *mfpu_opt = NULL; | |
e74cfd16 PB |
172 | |
173 | /* Constants for known architecture features. */ | |
174 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
f85d59c3 | 175 | static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1; |
e74cfd16 | 176 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; |
f85d59c3 KT |
177 | static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3; |
178 | static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
179 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
180 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
69c9e028 | 181 | #ifdef OBJ_ELF |
e74cfd16 | 182 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; |
69c9e028 | 183 | #endif |
e74cfd16 PB |
184 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; |
185 | ||
186 | #ifdef CPU_DEFAULT | |
187 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
188 | #endif | |
189 | ||
823d2571 | 190 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1); |
4070243b | 191 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2); |
823d2571 TG |
192 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S); |
193 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3); | |
194 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M); | |
195 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4); | |
196 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T); | |
197 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5); | |
e74cfd16 | 198 | static const arm_feature_set arm_ext_v4t_5 = |
823d2571 TG |
199 | ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5); |
200 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T); | |
201 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E); | |
202 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP); | |
203 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J); | |
204 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6); | |
205 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K); | |
206 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2); | |
55e8aae7 SP |
207 | /* Only for compatability of hint instructions. */ |
208 | static const arm_feature_set arm_ext_v6k_v6t2 = | |
209 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2); | |
823d2571 TG |
210 | static const arm_feature_set arm_ext_v6_notm = |
211 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM); | |
212 | static const arm_feature_set arm_ext_v6_dsp = | |
213 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP); | |
214 | static const arm_feature_set arm_ext_barrier = | |
215 | ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER); | |
216 | static const arm_feature_set arm_ext_msr = | |
217 | ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR); | |
218 | static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV); | |
219 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7); | |
220 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A); | |
221 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R); | |
69c9e028 | 222 | #ifdef OBJ_ELF |
e7d39ed3 | 223 | static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M); |
69c9e028 | 224 | #endif |
823d2571 | 225 | static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8); |
7e806470 | 226 | static const arm_feature_set arm_ext_m = |
173205ca | 227 | ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M, |
16a1fa25 | 228 | ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); |
823d2571 TG |
229 | static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP); |
230 | static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC); | |
231 | static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS); | |
232 | static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV); | |
233 | static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT); | |
ddfded2f | 234 | static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN); |
4ed7ed8d | 235 | static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M); |
16a1fa25 TP |
236 | static const arm_feature_set arm_ext_v8m_main = |
237 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN); | |
e12437dc AV |
238 | static const arm_feature_set arm_ext_v8_1m_main = |
239 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN); | |
16a1fa25 TP |
240 | /* Instructions in ARMv8-M only found in M profile architectures. */ |
241 | static const arm_feature_set arm_ext_v8m_m_only = | |
242 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN); | |
ff8646ee TP |
243 | static const arm_feature_set arm_ext_v6t2_v8m = |
244 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M); | |
4ed7ed8d TP |
245 | /* Instructions shared between ARMv8-A and ARMv8-M. */ |
246 | static const arm_feature_set arm_ext_atomics = | |
247 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS); | |
69c9e028 | 248 | #ifdef OBJ_ELF |
15afaa63 TP |
249 | /* DSP instructions Tag_DSP_extension refers to. */ |
250 | static const arm_feature_set arm_ext_dsp = | |
251 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP); | |
69c9e028 | 252 | #endif |
4d1464f2 MW |
253 | static const arm_feature_set arm_ext_ras = |
254 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS); | |
b8ec4e87 JW |
255 | /* FP16 instructions. */ |
256 | static const arm_feature_set arm_ext_fp16 = | |
257 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST); | |
01f48020 TC |
258 | static const arm_feature_set arm_ext_fp16_fml = |
259 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML); | |
dec41383 JW |
260 | static const arm_feature_set arm_ext_v8_2 = |
261 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A); | |
49e8a725 SN |
262 | static const arm_feature_set arm_ext_v8_3 = |
263 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A); | |
7fadb25d SD |
264 | static const arm_feature_set arm_ext_sb = |
265 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB); | |
dad0c3bf SD |
266 | static const arm_feature_set arm_ext_predres = |
267 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES); | |
e74cfd16 PB |
268 | |
269 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
49fa50ef | 270 | #ifdef OBJ_ELF |
2c6b98ea | 271 | static const arm_feature_set fpu_any = FPU_ANY; |
49fa50ef | 272 | #endif |
f85d59c3 | 273 | static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1); |
e74cfd16 PB |
274 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; |
275 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
276 | ||
2d447fca | 277 | static const arm_feature_set arm_cext_iwmmxt2 = |
823d2571 | 278 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2); |
e74cfd16 | 279 | static const arm_feature_set arm_cext_iwmmxt = |
823d2571 | 280 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT); |
e74cfd16 | 281 | static const arm_feature_set arm_cext_xscale = |
823d2571 | 282 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE); |
e74cfd16 | 283 | static const arm_feature_set arm_cext_maverick = |
823d2571 TG |
284 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK); |
285 | static const arm_feature_set fpu_fpa_ext_v1 = | |
286 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V1); | |
287 | static const arm_feature_set fpu_fpa_ext_v2 = | |
288 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V2); | |
e74cfd16 | 289 | static const arm_feature_set fpu_vfp_ext_v1xd = |
823d2571 TG |
290 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD); |
291 | static const arm_feature_set fpu_vfp_ext_v1 = | |
292 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1); | |
293 | static const arm_feature_set fpu_vfp_ext_v2 = | |
294 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V2); | |
295 | static const arm_feature_set fpu_vfp_ext_v3xd = | |
296 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD); | |
297 | static const arm_feature_set fpu_vfp_ext_v3 = | |
298 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3); | |
b1cc4aeb | 299 | static const arm_feature_set fpu_vfp_ext_d32 = |
823d2571 TG |
300 | ARM_FEATURE_COPROC (FPU_VFP_EXT_D32); |
301 | static const arm_feature_set fpu_neon_ext_v1 = | |
302 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1); | |
5287ad62 | 303 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = |
823d2571 | 304 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); |
69c9e028 | 305 | #ifdef OBJ_ELF |
823d2571 TG |
306 | static const arm_feature_set fpu_vfp_fp16 = |
307 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16); | |
308 | static const arm_feature_set fpu_neon_ext_fma = | |
309 | ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA); | |
69c9e028 | 310 | #endif |
823d2571 TG |
311 | static const arm_feature_set fpu_vfp_ext_fma = |
312 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA); | |
bca38921 | 313 | static const arm_feature_set fpu_vfp_ext_armv8 = |
823d2571 | 314 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8); |
a715796b | 315 | static const arm_feature_set fpu_vfp_ext_armv8xd = |
823d2571 | 316 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD); |
bca38921 | 317 | static const arm_feature_set fpu_neon_ext_armv8 = |
823d2571 | 318 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8); |
bca38921 | 319 | static const arm_feature_set fpu_crypto_ext_armv8 = |
823d2571 | 320 | ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8); |
dd5181d5 | 321 | static const arm_feature_set crc_ext_armv8 = |
823d2571 | 322 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8); |
d6b4b13e | 323 | static const arm_feature_set fpu_neon_ext_v8_1 = |
643afb90 | 324 | ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA); |
c604a79a JW |
325 | static const arm_feature_set fpu_neon_ext_dotprod = |
326 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD); | |
e74cfd16 | 327 | |
33a392fb | 328 | static int mfloat_abi_opt = -1; |
4d354d8b TP |
329 | /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch |
330 | directive. */ | |
331 | static arm_feature_set selected_arch = ARM_ARCH_NONE; | |
332 | /* Extension feature bits selected by the last -mcpu/-march or .arch_extension | |
333 | directive. */ | |
334 | static arm_feature_set selected_ext = ARM_ARCH_NONE; | |
335 | /* Feature bits selected by the last -mcpu/-march or by the combination of the | |
336 | last .cpu/.arch directive .arch_extension directives since that | |
337 | directive. */ | |
e74cfd16 | 338 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; |
4d354d8b TP |
339 | /* FPU feature bits selected by the last -mfpu or .fpu directive. */ |
340 | static arm_feature_set selected_fpu = FPU_NONE; | |
341 | /* Feature bits selected by the last .object_arch directive. */ | |
342 | static arm_feature_set selected_object_arch = ARM_ARCH_NONE; | |
ee065d83 | 343 | /* Must be long enough to hold any of the names in arm_cpus. */ |
ef8e6722 | 344 | static char selected_cpu_name[20]; |
8d67f500 | 345 | |
aacf0b33 KT |
346 | extern FLONUM_TYPE generic_floating_point_number; |
347 | ||
8d67f500 NC |
348 | /* Return if no cpu was selected on command-line. */ |
349 | static bfd_boolean | |
350 | no_cpu_selected (void) | |
351 | { | |
823d2571 | 352 | return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none); |
8d67f500 NC |
353 | } |
354 | ||
7cc69913 | 355 | #ifdef OBJ_ELF |
deeaaff8 DJ |
356 | # ifdef EABI_DEFAULT |
357 | static int meabi_flags = EABI_DEFAULT; | |
358 | # else | |
d507cf36 | 359 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 360 | # endif |
e1da3f5b | 361 | |
ee3c0378 AS |
362 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
363 | ||
e1da3f5b | 364 | bfd_boolean |
5f4273c7 | 365 | arm_is_eabi (void) |
e1da3f5b PB |
366 | { |
367 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
368 | } | |
7cc69913 | 369 | #endif |
b99bd4ef | 370 | |
b99bd4ef | 371 | #ifdef OBJ_ELF |
c19d1205 | 372 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
373 | symbolS * GOT_symbol; |
374 | #endif | |
375 | ||
b99bd4ef NC |
376 | /* 0: assemble for ARM, |
377 | 1: assemble for Thumb, | |
378 | 2: assemble for Thumb even though target CPU does not support thumb | |
379 | instructions. */ | |
380 | static int thumb_mode = 0; | |
8dc2430f NC |
381 | /* A value distinct from the possible values for thumb_mode that we |
382 | can use to record whether thumb_mode has been copied into the | |
383 | tc_frag_data field of a frag. */ | |
384 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 385 | |
e07e6e58 NC |
386 | /* Specifies the intrinsic IT insn behavior mode. */ |
387 | enum implicit_it_mode | |
388 | { | |
389 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
390 | IMPLICIT_IT_MODE_ARM = 0x01, | |
391 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
392 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
393 | }; | |
394 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
395 | ||
c19d1205 ZW |
396 | /* If unified_syntax is true, we are processing the new unified |
397 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
398 | ||
399 | - Immediate operands do not require a # prefix. | |
400 | - Conditional affixes always appear at the end of the | |
401 | instruction. (For backward compatibility, those instructions | |
402 | that formerly had them in the middle, continue to accept them | |
403 | there.) | |
404 | - The IT instruction may appear, and if it does is validated | |
405 | against subsequent conditional affixes. It does not generate | |
406 | machine code. | |
407 | ||
408 | Important differences from the old Thumb mode: | |
409 | ||
410 | - Immediate operands do not require a # prefix. | |
411 | - Most of the V6T2 instructions are only available in unified mode. | |
412 | - The .N and .W suffixes are recognized and honored (it is an error | |
413 | if they cannot be honored). | |
414 | - All instructions set the flags if and only if they have an 's' affix. | |
415 | - Conditional affixes may be used. They are validated against | |
416 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
417 | conditional affix except in the scope of an IT instruction. */ | |
418 | ||
419 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 420 | |
bacebabc RM |
421 | /* An immediate operand can start with #, and ld*, st*, pld operands |
422 | can contain [ and ]. We need to tell APP not to elide whitespace | |
477330fc RM |
423 | before a [, which can appear as the first operand for pld. |
424 | Likewise, a { can appear as the first operand for push, pop, vld*, etc. */ | |
425 | const char arm_symbol_chars[] = "#[]{}"; | |
bacebabc | 426 | |
5287ad62 JB |
427 | enum neon_el_type |
428 | { | |
dcbf9037 | 429 | NT_invtype, |
5287ad62 JB |
430 | NT_untyped, |
431 | NT_integer, | |
432 | NT_float, | |
433 | NT_poly, | |
434 | NT_signed, | |
dcbf9037 | 435 | NT_unsigned |
5287ad62 JB |
436 | }; |
437 | ||
438 | struct neon_type_el | |
439 | { | |
440 | enum neon_el_type type; | |
441 | unsigned size; | |
442 | }; | |
443 | ||
444 | #define NEON_MAX_TYPE_ELS 4 | |
445 | ||
446 | struct neon_type | |
447 | { | |
448 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
449 | unsigned elems; | |
450 | }; | |
451 | ||
e07e6e58 NC |
452 | enum it_instruction_type |
453 | { | |
454 | OUTSIDE_IT_INSN, | |
455 | INSIDE_IT_INSN, | |
456 | INSIDE_IT_LAST_INSN, | |
457 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
477330fc | 458 | if inside, should be the last one. */ |
e07e6e58 | 459 | NEUTRAL_IT_INSN, /* This could be either inside or outside, |
477330fc | 460 | i.e. BKPT and NOP. */ |
e07e6e58 NC |
461 | IT_INSN /* The IT insn has been parsed. */ |
462 | }; | |
463 | ||
ad6cec43 MGD |
464 | /* The maximum number of operands we need. */ |
465 | #define ARM_IT_MAX_OPERANDS 6 | |
e2b0ab59 | 466 | #define ARM_IT_MAX_RELOCS 3 |
ad6cec43 | 467 | |
b99bd4ef NC |
468 | struct arm_it |
469 | { | |
c19d1205 | 470 | const char * error; |
b99bd4ef | 471 | unsigned long instruction; |
c19d1205 ZW |
472 | int size; |
473 | int size_req; | |
474 | int cond; | |
037e8744 JB |
475 | /* "uncond_value" is set to the value in place of the conditional field in |
476 | unconditional versions of the instruction, or -1 if nothing is | |
477 | appropriate. */ | |
478 | int uncond_value; | |
5287ad62 | 479 | struct neon_type vectype; |
88714cb8 DG |
480 | /* This does not indicate an actual NEON instruction, only that |
481 | the mnemonic accepts neon-style type suffixes. */ | |
482 | int is_neon; | |
0110f2b8 PB |
483 | /* Set to the opcode if the instruction needs relaxation. |
484 | Zero if the instruction is not relaxed. */ | |
485 | unsigned long relax; | |
b99bd4ef NC |
486 | struct |
487 | { | |
488 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
489 | expressionS exp; |
490 | int pc_rel; | |
e2b0ab59 | 491 | } relocs[ARM_IT_MAX_RELOCS]; |
b99bd4ef | 492 | |
e07e6e58 NC |
493 | enum it_instruction_type it_insn_type; |
494 | ||
c19d1205 ZW |
495 | struct |
496 | { | |
497 | unsigned reg; | |
ca3f61f7 | 498 | signed int imm; |
dcbf9037 | 499 | struct neon_type_el vectype; |
ca3f61f7 NC |
500 | unsigned present : 1; /* Operand present. */ |
501 | unsigned isreg : 1; /* Operand was a register. */ | |
502 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
503 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
504 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 505 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
506 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
507 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
508 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 509 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 510 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 511 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
512 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
513 | unsigned writeback : 1; /* Operand has trailing ! */ | |
514 | unsigned preind : 1; /* Preindexed address. */ | |
515 | unsigned postind : 1; /* Postindexed address. */ | |
516 | unsigned negative : 1; /* Index register was negated. */ | |
517 | unsigned shifted : 1; /* Shift applied to operation. */ | |
518 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
ad6cec43 | 519 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
520 | }; |
521 | ||
c19d1205 | 522 | static struct arm_it inst; |
b99bd4ef NC |
523 | |
524 | #define NUM_FLOAT_VALS 8 | |
525 | ||
05d2d07e | 526 | const char * fp_const[] = |
b99bd4ef NC |
527 | { |
528 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
529 | }; | |
530 | ||
c19d1205 | 531 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
532 | #define MAX_LITTLENUMS 6 |
533 | ||
534 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
535 | ||
536 | #define FAIL (-1) | |
537 | #define SUCCESS (0) | |
538 | ||
539 | #define SUFF_S 1 | |
540 | #define SUFF_D 2 | |
541 | #define SUFF_E 3 | |
542 | #define SUFF_P 4 | |
543 | ||
c19d1205 ZW |
544 | #define CP_T_X 0x00008000 |
545 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 546 | |
c19d1205 ZW |
547 | #define CONDS_BIT 0x00100000 |
548 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
549 | |
550 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
551 | ||
552 | struct asm_cond | |
553 | { | |
d3ce72d0 | 554 | const char * template_name; |
c921be7d | 555 | unsigned long value; |
b99bd4ef NC |
556 | }; |
557 | ||
c19d1205 | 558 | #define COND_ALWAYS 0xE |
b99bd4ef | 559 | |
b99bd4ef NC |
560 | struct asm_psr |
561 | { | |
d3ce72d0 | 562 | const char * template_name; |
c921be7d | 563 | unsigned long field; |
b99bd4ef NC |
564 | }; |
565 | ||
62b3e311 PB |
566 | struct asm_barrier_opt |
567 | { | |
e797f7e0 MGD |
568 | const char * template_name; |
569 | unsigned long value; | |
570 | const arm_feature_set arch; | |
62b3e311 PB |
571 | }; |
572 | ||
2d2255b5 | 573 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
574 | #define SPSR_BIT (1 << 22) |
575 | ||
c19d1205 ZW |
576 | /* The individual PSR flag bits. */ |
577 | #define PSR_c (1 << 16) | |
578 | #define PSR_x (1 << 17) | |
579 | #define PSR_s (1 << 18) | |
580 | #define PSR_f (1 << 19) | |
b99bd4ef | 581 | |
c19d1205 | 582 | struct reloc_entry |
bfae80f2 | 583 | { |
0198d5e6 | 584 | const char * name; |
c921be7d | 585 | bfd_reloc_code_real_type reloc; |
bfae80f2 RE |
586 | }; |
587 | ||
5287ad62 | 588 | enum vfp_reg_pos |
bfae80f2 | 589 | { |
5287ad62 JB |
590 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
591 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
592 | }; |
593 | ||
594 | enum vfp_ldstm_type | |
595 | { | |
596 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
597 | }; | |
598 | ||
dcbf9037 JB |
599 | /* Bits for DEFINED field in neon_typed_alias. */ |
600 | #define NTA_HASTYPE 1 | |
601 | #define NTA_HASINDEX 2 | |
602 | ||
603 | struct neon_typed_alias | |
604 | { | |
c921be7d NC |
605 | unsigned char defined; |
606 | unsigned char index; | |
607 | struct neon_type_el eltype; | |
dcbf9037 JB |
608 | }; |
609 | ||
c19d1205 | 610 | /* ARM register categories. This includes coprocessor numbers and various |
5aa75429 TP |
611 | architecture extensions' registers. Each entry should have an error message |
612 | in reg_expected_msgs below. */ | |
c19d1205 | 613 | enum arm_reg_type |
bfae80f2 | 614 | { |
c19d1205 ZW |
615 | REG_TYPE_RN, |
616 | REG_TYPE_CP, | |
617 | REG_TYPE_CN, | |
618 | REG_TYPE_FN, | |
619 | REG_TYPE_VFS, | |
620 | REG_TYPE_VFD, | |
5287ad62 | 621 | REG_TYPE_NQ, |
037e8744 | 622 | REG_TYPE_VFSD, |
5287ad62 | 623 | REG_TYPE_NDQ, |
dec41383 | 624 | REG_TYPE_NSD, |
037e8744 | 625 | REG_TYPE_NSDQ, |
c19d1205 ZW |
626 | REG_TYPE_VFC, |
627 | REG_TYPE_MVF, | |
628 | REG_TYPE_MVD, | |
629 | REG_TYPE_MVFX, | |
630 | REG_TYPE_MVDX, | |
631 | REG_TYPE_MVAX, | |
632 | REG_TYPE_DSPSC, | |
633 | REG_TYPE_MMXWR, | |
634 | REG_TYPE_MMXWC, | |
635 | REG_TYPE_MMXWCG, | |
636 | REG_TYPE_XSCALE, | |
90ec0d68 | 637 | REG_TYPE_RNB |
bfae80f2 RE |
638 | }; |
639 | ||
dcbf9037 JB |
640 | /* Structure for a hash table entry for a register. |
641 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
642 | information which states whether a vector type or index is specified (for a | |
643 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
644 | struct reg_entry |
645 | { | |
c921be7d | 646 | const char * name; |
90ec0d68 | 647 | unsigned int number; |
c921be7d NC |
648 | unsigned char type; |
649 | unsigned char builtin; | |
650 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
651 | }; |
652 | ||
c19d1205 | 653 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 654 | const char * const reg_expected_msgs[] = |
c19d1205 | 655 | { |
5aa75429 TP |
656 | [REG_TYPE_RN] = N_("ARM register expected"), |
657 | [REG_TYPE_CP] = N_("bad or missing co-processor number"), | |
658 | [REG_TYPE_CN] = N_("co-processor register expected"), | |
659 | [REG_TYPE_FN] = N_("FPA register expected"), | |
660 | [REG_TYPE_VFS] = N_("VFP single precision register expected"), | |
661 | [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"), | |
662 | [REG_TYPE_NQ] = N_("Neon quad precision register expected"), | |
663 | [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"), | |
664 | [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"), | |
665 | [REG_TYPE_NSD] = N_("Neon single or double precision register expected"), | |
666 | [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register" | |
667 | " expected"), | |
668 | [REG_TYPE_VFC] = N_("VFP system register expected"), | |
669 | [REG_TYPE_MVF] = N_("Maverick MVF register expected"), | |
670 | [REG_TYPE_MVD] = N_("Maverick MVD register expected"), | |
671 | [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"), | |
672 | [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"), | |
673 | [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"), | |
674 | [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"), | |
675 | [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"), | |
676 | [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"), | |
677 | [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"), | |
678 | [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"), | |
679 | [REG_TYPE_RNB] = N_("") | |
6c43fab6 RE |
680 | }; |
681 | ||
c19d1205 | 682 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 683 | #define REG_R12 12 |
c19d1205 ZW |
684 | #define REG_SP 13 |
685 | #define REG_LR 14 | |
686 | #define REG_PC 15 | |
404ff6b5 | 687 | |
b99bd4ef NC |
688 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
689 | take 2: */ | |
c19d1205 | 690 | #define INSN_SIZE 4 |
b99bd4ef NC |
691 | |
692 | struct asm_opcode | |
693 | { | |
694 | /* Basic string to match. */ | |
d3ce72d0 | 695 | const char * template_name; |
c19d1205 ZW |
696 | |
697 | /* Parameters to instruction. */ | |
5be8be5d | 698 | unsigned int operands[8]; |
c19d1205 ZW |
699 | |
700 | /* Conditional tag - see opcode_lookup. */ | |
701 | unsigned int tag : 4; | |
b99bd4ef NC |
702 | |
703 | /* Basic instruction code. */ | |
c19d1205 | 704 | unsigned int avalue : 28; |
b99bd4ef | 705 | |
c19d1205 ZW |
706 | /* Thumb-format instruction code. */ |
707 | unsigned int tvalue; | |
b99bd4ef | 708 | |
90e4755a | 709 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
710 | const arm_feature_set * avariant; |
711 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
712 | |
713 | /* Function to call to encode instruction in ARM format. */ | |
714 | void (* aencode) (void); | |
b99bd4ef | 715 | |
c19d1205 ZW |
716 | /* Function to call to encode instruction in Thumb format. */ |
717 | void (* tencode) (void); | |
b99bd4ef NC |
718 | }; |
719 | ||
a737bd4d NC |
720 | /* Defines for various bits that we will want to toggle. */ |
721 | #define INST_IMMEDIATE 0x02000000 | |
722 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 723 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
724 | #define SHIFT_BY_REG 0x00000010 |
725 | #define PRE_INDEX 0x01000000 | |
726 | #define INDEX_UP 0x00800000 | |
727 | #define WRITE_BACK 0x00200000 | |
728 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 729 | #define CPSI_MMOD 0x00020000 |
90e4755a | 730 | |
a737bd4d NC |
731 | #define LITERAL_MASK 0xf000f000 |
732 | #define OPCODE_MASK 0xfe1fffff | |
733 | #define V4_STR_BIT 0x00000020 | |
8335d6aa | 734 | #define VLDR_VMOV_SAME 0x0040f000 |
90e4755a | 735 | |
efd81785 PB |
736 | #define T2_SUBS_PC_LR 0xf3de8f00 |
737 | ||
a737bd4d | 738 | #define DATA_OP_SHIFT 21 |
bada4342 | 739 | #define SBIT_SHIFT 20 |
90e4755a | 740 | |
ef8d22e6 PB |
741 | #define T2_OPCODE_MASK 0xfe1fffff |
742 | #define T2_DATA_OP_SHIFT 21 | |
bada4342 | 743 | #define T2_SBIT_SHIFT 20 |
ef8d22e6 | 744 | |
6530b175 NC |
745 | #define A_COND_MASK 0xf0000000 |
746 | #define A_PUSH_POP_OP_MASK 0x0fff0000 | |
747 | ||
748 | /* Opcodes for pushing/poping registers to/from the stack. */ | |
749 | #define A1_OPCODE_PUSH 0x092d0000 | |
750 | #define A2_OPCODE_PUSH 0x052d0004 | |
751 | #define A2_OPCODE_POP 0x049d0004 | |
752 | ||
a737bd4d NC |
753 | /* Codes to distinguish the arithmetic instructions. */ |
754 | #define OPCODE_AND 0 | |
755 | #define OPCODE_EOR 1 | |
756 | #define OPCODE_SUB 2 | |
757 | #define OPCODE_RSB 3 | |
758 | #define OPCODE_ADD 4 | |
759 | #define OPCODE_ADC 5 | |
760 | #define OPCODE_SBC 6 | |
761 | #define OPCODE_RSC 7 | |
762 | #define OPCODE_TST 8 | |
763 | #define OPCODE_TEQ 9 | |
764 | #define OPCODE_CMP 10 | |
765 | #define OPCODE_CMN 11 | |
766 | #define OPCODE_ORR 12 | |
767 | #define OPCODE_MOV 13 | |
768 | #define OPCODE_BIC 14 | |
769 | #define OPCODE_MVN 15 | |
90e4755a | 770 | |
ef8d22e6 PB |
771 | #define T2_OPCODE_AND 0 |
772 | #define T2_OPCODE_BIC 1 | |
773 | #define T2_OPCODE_ORR 2 | |
774 | #define T2_OPCODE_ORN 3 | |
775 | #define T2_OPCODE_EOR 4 | |
776 | #define T2_OPCODE_ADD 8 | |
777 | #define T2_OPCODE_ADC 10 | |
778 | #define T2_OPCODE_SBC 11 | |
779 | #define T2_OPCODE_SUB 13 | |
780 | #define T2_OPCODE_RSB 14 | |
781 | ||
a737bd4d NC |
782 | #define T_OPCODE_MUL 0x4340 |
783 | #define T_OPCODE_TST 0x4200 | |
784 | #define T_OPCODE_CMN 0x42c0 | |
785 | #define T_OPCODE_NEG 0x4240 | |
786 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 787 | |
a737bd4d NC |
788 | #define T_OPCODE_ADD_R3 0x1800 |
789 | #define T_OPCODE_SUB_R3 0x1a00 | |
790 | #define T_OPCODE_ADD_HI 0x4400 | |
791 | #define T_OPCODE_ADD_ST 0xb000 | |
792 | #define T_OPCODE_SUB_ST 0xb080 | |
793 | #define T_OPCODE_ADD_SP 0xa800 | |
794 | #define T_OPCODE_ADD_PC 0xa000 | |
795 | #define T_OPCODE_ADD_I8 0x3000 | |
796 | #define T_OPCODE_SUB_I8 0x3800 | |
797 | #define T_OPCODE_ADD_I3 0x1c00 | |
798 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 799 | |
a737bd4d NC |
800 | #define T_OPCODE_ASR_R 0x4100 |
801 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
802 | #define T_OPCODE_LSR_R 0x40c0 |
803 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
804 | #define T_OPCODE_ASR_I 0x1000 |
805 | #define T_OPCODE_LSL_I 0x0000 | |
806 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 807 | |
a737bd4d NC |
808 | #define T_OPCODE_MOV_I8 0x2000 |
809 | #define T_OPCODE_CMP_I8 0x2800 | |
810 | #define T_OPCODE_CMP_LR 0x4280 | |
811 | #define T_OPCODE_MOV_HR 0x4600 | |
812 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 813 | |
a737bd4d NC |
814 | #define T_OPCODE_LDR_PC 0x4800 |
815 | #define T_OPCODE_LDR_SP 0x9800 | |
816 | #define T_OPCODE_STR_SP 0x9000 | |
817 | #define T_OPCODE_LDR_IW 0x6800 | |
818 | #define T_OPCODE_STR_IW 0x6000 | |
819 | #define T_OPCODE_LDR_IH 0x8800 | |
820 | #define T_OPCODE_STR_IH 0x8000 | |
821 | #define T_OPCODE_LDR_IB 0x7800 | |
822 | #define T_OPCODE_STR_IB 0x7000 | |
823 | #define T_OPCODE_LDR_RW 0x5800 | |
824 | #define T_OPCODE_STR_RW 0x5000 | |
825 | #define T_OPCODE_LDR_RH 0x5a00 | |
826 | #define T_OPCODE_STR_RH 0x5200 | |
827 | #define T_OPCODE_LDR_RB 0x5c00 | |
828 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 829 | |
a737bd4d NC |
830 | #define T_OPCODE_PUSH 0xb400 |
831 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 832 | |
2fc8bdac | 833 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 834 | |
a737bd4d | 835 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 836 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 837 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 838 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
839 | |
840 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 841 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
842 | #define BAD_PC _("r15 not allowed here") |
843 | #define BAD_COND _("instruction cannot be conditional") | |
844 | #define BAD_OVERLAP _("registers may not be the same") | |
845 | #define BAD_HIREG _("lo register required") | |
846 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 847 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 | 848 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
e12437dc | 849 | #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2") |
dfa9f0d5 | 850 | #define BAD_NOT_IT _("instruction not allowed in IT block") |
037e8744 | 851 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
852 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
853 | #define BAD_IT_COND _("incorrect condition in IT block") | |
854 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 855 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
856 | #define BAD_PC_ADDRESSING \ |
857 | _("cannot use register index with PC-relative addressing") | |
858 | #define BAD_PC_WRITEBACK \ | |
859 | _("cannot use writeback with PC-relative addressing") | |
9db2f6b4 RL |
860 | #define BAD_RANGE _("branch out of range") |
861 | #define BAD_FP16 _("selected processor does not support fp16 instruction") | |
dd5181d5 | 862 | #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour") |
a9f02af8 | 863 | #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only") |
c19d1205 | 864 | |
c921be7d NC |
865 | static struct hash_control * arm_ops_hsh; |
866 | static struct hash_control * arm_cond_hsh; | |
867 | static struct hash_control * arm_shift_hsh; | |
868 | static struct hash_control * arm_psr_hsh; | |
869 | static struct hash_control * arm_v7m_psr_hsh; | |
870 | static struct hash_control * arm_reg_hsh; | |
871 | static struct hash_control * arm_reloc_hsh; | |
872 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 873 | |
b99bd4ef NC |
874 | /* Stuff needed to resolve the label ambiguity |
875 | As: | |
876 | ... | |
877 | label: <insn> | |
878 | may differ from: | |
879 | ... | |
880 | label: | |
5f4273c7 | 881 | <insn> */ |
b99bd4ef NC |
882 | |
883 | symbolS * last_label_seen; | |
b34976b6 | 884 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 885 | |
3d0c9500 NC |
886 | /* Literal pool structure. Held on a per-section |
887 | and per-sub-section basis. */ | |
a737bd4d | 888 | |
c19d1205 | 889 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 890 | typedef struct literal_pool |
b99bd4ef | 891 | { |
c921be7d NC |
892 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
893 | unsigned int next_free_entry; | |
894 | unsigned int id; | |
895 | symbolS * symbol; | |
896 | segT section; | |
897 | subsegT sub_section; | |
a8040cf2 NC |
898 | #ifdef OBJ_ELF |
899 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
900 | #endif | |
c921be7d | 901 | struct literal_pool * next; |
8335d6aa | 902 | unsigned int alignment; |
3d0c9500 | 903 | } literal_pool; |
b99bd4ef | 904 | |
3d0c9500 NC |
905 | /* Pointer to a linked list of literal pools. */ |
906 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 907 | |
2e6976a8 DG |
908 | typedef enum asmfunc_states |
909 | { | |
910 | OUTSIDE_ASMFUNC, | |
911 | WAITING_ASMFUNC_NAME, | |
912 | WAITING_ENDASMFUNC | |
913 | } asmfunc_states; | |
914 | ||
915 | static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC; | |
916 | ||
e07e6e58 NC |
917 | #ifdef OBJ_ELF |
918 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
919 | #else | |
920 | static struct current_it now_it; | |
921 | #endif | |
922 | ||
923 | static inline int | |
924 | now_it_compatible (int cond) | |
925 | { | |
926 | return (cond & ~1) == (now_it.cc & ~1); | |
927 | } | |
928 | ||
929 | static inline int | |
930 | conditional_insn (void) | |
931 | { | |
932 | return inst.cond != COND_ALWAYS; | |
933 | } | |
934 | ||
935 | static int in_it_block (void); | |
936 | ||
937 | static int handle_it_state (void); | |
938 | ||
939 | static void force_automatic_it_block_close (void); | |
940 | ||
c921be7d NC |
941 | static void it_fsm_post_encode (void); |
942 | ||
e07e6e58 NC |
943 | #define set_it_insn_type(type) \ |
944 | do \ | |
945 | { \ | |
946 | inst.it_insn_type = type; \ | |
947 | if (handle_it_state () == FAIL) \ | |
477330fc | 948 | return; \ |
e07e6e58 NC |
949 | } \ |
950 | while (0) | |
951 | ||
c921be7d NC |
952 | #define set_it_insn_type_nonvoid(type, failret) \ |
953 | do \ | |
954 | { \ | |
955 | inst.it_insn_type = type; \ | |
956 | if (handle_it_state () == FAIL) \ | |
477330fc | 957 | return failret; \ |
c921be7d NC |
958 | } \ |
959 | while(0) | |
960 | ||
e07e6e58 NC |
961 | #define set_it_insn_type_last() \ |
962 | do \ | |
963 | { \ | |
964 | if (inst.cond == COND_ALWAYS) \ | |
477330fc | 965 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ |
e07e6e58 | 966 | else \ |
477330fc | 967 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ |
e07e6e58 NC |
968 | } \ |
969 | while (0) | |
970 | ||
c19d1205 | 971 | /* Pure syntax. */ |
b99bd4ef | 972 | |
c19d1205 ZW |
973 | /* This array holds the chars that always start a comment. If the |
974 | pre-processor is disabled, these aren't very useful. */ | |
2e6976a8 | 975 | char arm_comment_chars[] = "@"; |
3d0c9500 | 976 | |
c19d1205 ZW |
977 | /* This array holds the chars that only start a comment at the beginning of |
978 | a line. If the line seems to have the form '# 123 filename' | |
979 | .line and .file directives will appear in the pre-processed output. */ | |
980 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
981 | first line of the input file. This is because the compiler outputs | |
982 | #NO_APP at the beginning of its output. */ | |
983 | /* Also note that comments like this one will always work. */ | |
984 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 985 | |
2e6976a8 | 986 | char arm_line_separator_chars[] = ";"; |
b99bd4ef | 987 | |
c19d1205 ZW |
988 | /* Chars that can be used to separate mant |
989 | from exp in floating point numbers. */ | |
990 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 991 | |
c19d1205 ZW |
992 | /* Chars that mean this number is a floating point constant. */ |
993 | /* As in 0f12.456 */ | |
994 | /* or 0d1.2345e12 */ | |
b99bd4ef | 995 | |
c19d1205 | 996 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 997 | |
c19d1205 ZW |
998 | /* Prefix characters that indicate the start of an immediate |
999 | value. */ | |
1000 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 1001 | |
c19d1205 ZW |
1002 | /* Separator character handling. */ |
1003 | ||
1004 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
1005 | ||
1006 | static inline int | |
1007 | skip_past_char (char ** str, char c) | |
1008 | { | |
8ab8155f NC |
1009 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
1010 | skip_whitespace (*str); | |
427d0db6 | 1011 | |
c19d1205 ZW |
1012 | if (**str == c) |
1013 | { | |
1014 | (*str)++; | |
1015 | return SUCCESS; | |
3d0c9500 | 1016 | } |
c19d1205 ZW |
1017 | else |
1018 | return FAIL; | |
1019 | } | |
c921be7d | 1020 | |
c19d1205 | 1021 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 1022 | |
c19d1205 ZW |
1023 | /* Arithmetic expressions (possibly involving symbols). */ |
1024 | ||
1025 | /* Return TRUE if anything in the expression is a bignum. */ | |
1026 | ||
0198d5e6 | 1027 | static bfd_boolean |
c19d1205 ZW |
1028 | walk_no_bignums (symbolS * sp) |
1029 | { | |
1030 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
0198d5e6 | 1031 | return TRUE; |
c19d1205 ZW |
1032 | |
1033 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 1034 | { |
c19d1205 ZW |
1035 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
1036 | || (symbol_get_value_expression (sp)->X_op_symbol | |
1037 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
1038 | } |
1039 | ||
0198d5e6 | 1040 | return FALSE; |
3d0c9500 NC |
1041 | } |
1042 | ||
0198d5e6 | 1043 | static bfd_boolean in_my_get_expression = FALSE; |
c19d1205 ZW |
1044 | |
1045 | /* Third argument to my_get_expression. */ | |
1046 | #define GE_NO_PREFIX 0 | |
1047 | #define GE_IMM_PREFIX 1 | |
1048 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
1049 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
1050 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
1051 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 1052 | |
b99bd4ef | 1053 | static int |
c19d1205 | 1054 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 1055 | { |
c19d1205 | 1056 | char * save_in; |
b99bd4ef | 1057 | |
c19d1205 ZW |
1058 | /* In unified syntax, all prefixes are optional. */ |
1059 | if (unified_syntax) | |
5287ad62 | 1060 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
477330fc | 1061 | : GE_OPT_PREFIX; |
b99bd4ef | 1062 | |
c19d1205 | 1063 | switch (prefix_mode) |
b99bd4ef | 1064 | { |
c19d1205 ZW |
1065 | case GE_NO_PREFIX: break; |
1066 | case GE_IMM_PREFIX: | |
1067 | if (!is_immediate_prefix (**str)) | |
1068 | { | |
1069 | inst.error = _("immediate expression requires a # prefix"); | |
1070 | return FAIL; | |
1071 | } | |
1072 | (*str)++; | |
1073 | break; | |
1074 | case GE_OPT_PREFIX: | |
5287ad62 | 1075 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
1076 | if (is_immediate_prefix (**str)) |
1077 | (*str)++; | |
1078 | break; | |
0198d5e6 TC |
1079 | default: |
1080 | abort (); | |
c19d1205 | 1081 | } |
b99bd4ef | 1082 | |
c19d1205 | 1083 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 1084 | |
c19d1205 ZW |
1085 | save_in = input_line_pointer; |
1086 | input_line_pointer = *str; | |
0198d5e6 | 1087 | in_my_get_expression = TRUE; |
2ac93be7 | 1088 | expression (ep); |
0198d5e6 | 1089 | in_my_get_expression = FALSE; |
c19d1205 | 1090 | |
f86adc07 | 1091 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 1092 | { |
f86adc07 | 1093 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
1094 | *str = input_line_pointer; |
1095 | input_line_pointer = save_in; | |
1096 | if (inst.error == NULL) | |
f86adc07 NS |
1097 | inst.error = (ep->X_op == O_absent |
1098 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
1099 | return 1; |
1100 | } | |
b99bd4ef | 1101 | |
c19d1205 ZW |
1102 | /* Get rid of any bignums now, so that we don't generate an error for which |
1103 | we can't establish a line number later on. Big numbers are never valid | |
1104 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
1105 | if (prefix_mode != GE_OPT_PREFIX_BIG |
1106 | && (ep->X_op == O_big | |
477330fc | 1107 | || (ep->X_add_symbol |
5287ad62 | 1108 | && (walk_no_bignums (ep->X_add_symbol) |
477330fc | 1109 | || (ep->X_op_symbol |
5287ad62 | 1110 | && walk_no_bignums (ep->X_op_symbol)))))) |
c19d1205 ZW |
1111 | { |
1112 | inst.error = _("invalid constant"); | |
1113 | *str = input_line_pointer; | |
1114 | input_line_pointer = save_in; | |
1115 | return 1; | |
1116 | } | |
b99bd4ef | 1117 | |
c19d1205 ZW |
1118 | *str = input_line_pointer; |
1119 | input_line_pointer = save_in; | |
0198d5e6 | 1120 | return SUCCESS; |
b99bd4ef NC |
1121 | } |
1122 | ||
c19d1205 ZW |
1123 | /* Turn a string in input_line_pointer into a floating point constant |
1124 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1125 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1126 | returned, or NULL on OK. | |
b99bd4ef | 1127 | |
c19d1205 ZW |
1128 | Note that fp constants aren't represent in the normal way on the ARM. |
1129 | In big endian mode, things are as expected. However, in little endian | |
1130 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
1131 | within the words. For example, (double) 1.1 in big endian mode is | |
1132 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
1133 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 1134 | |
c19d1205 | 1135 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1136 | |
6d4af3c2 | 1137 | const char * |
c19d1205 ZW |
1138 | md_atof (int type, char * litP, int * sizeP) |
1139 | { | |
1140 | int prec; | |
1141 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1142 | char *t; | |
1143 | int i; | |
b99bd4ef | 1144 | |
c19d1205 ZW |
1145 | switch (type) |
1146 | { | |
1147 | case 'f': | |
1148 | case 'F': | |
1149 | case 's': | |
1150 | case 'S': | |
1151 | prec = 2; | |
1152 | break; | |
b99bd4ef | 1153 | |
c19d1205 ZW |
1154 | case 'd': |
1155 | case 'D': | |
1156 | case 'r': | |
1157 | case 'R': | |
1158 | prec = 4; | |
1159 | break; | |
b99bd4ef | 1160 | |
c19d1205 ZW |
1161 | case 'x': |
1162 | case 'X': | |
499ac353 | 1163 | prec = 5; |
c19d1205 | 1164 | break; |
b99bd4ef | 1165 | |
c19d1205 ZW |
1166 | case 'p': |
1167 | case 'P': | |
499ac353 | 1168 | prec = 5; |
c19d1205 | 1169 | break; |
a737bd4d | 1170 | |
c19d1205 ZW |
1171 | default: |
1172 | *sizeP = 0; | |
499ac353 | 1173 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1174 | } |
b99bd4ef | 1175 | |
c19d1205 ZW |
1176 | t = atof_ieee (input_line_pointer, type, words); |
1177 | if (t) | |
1178 | input_line_pointer = t; | |
499ac353 | 1179 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1180 | |
c19d1205 ZW |
1181 | if (target_big_endian) |
1182 | { | |
1183 | for (i = 0; i < prec; i++) | |
1184 | { | |
499ac353 NC |
1185 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1186 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1187 | } |
1188 | } | |
1189 | else | |
1190 | { | |
e74cfd16 | 1191 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1192 | for (i = prec - 1; i >= 0; i--) |
1193 | { | |
499ac353 NC |
1194 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1195 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1196 | } |
1197 | else | |
1198 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1199 | For an 8 byte float the order is 1 0 3 2. */ | |
1200 | for (i = 0; i < prec; i += 2) | |
1201 | { | |
499ac353 NC |
1202 | md_number_to_chars (litP, (valueT) words[i + 1], |
1203 | sizeof (LITTLENUM_TYPE)); | |
1204 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1205 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1206 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1207 | } |
1208 | } | |
b99bd4ef | 1209 | |
499ac353 | 1210 | return NULL; |
c19d1205 | 1211 | } |
b99bd4ef | 1212 | |
c19d1205 ZW |
1213 | /* We handle all bad expressions here, so that we can report the faulty |
1214 | instruction in the error message. */ | |
0198d5e6 | 1215 | |
c19d1205 | 1216 | void |
91d6fa6a | 1217 | md_operand (expressionS * exp) |
c19d1205 ZW |
1218 | { |
1219 | if (in_my_get_expression) | |
91d6fa6a | 1220 | exp->X_op = O_illegal; |
b99bd4ef NC |
1221 | } |
1222 | ||
c19d1205 | 1223 | /* Immediate values. */ |
b99bd4ef | 1224 | |
0198d5e6 | 1225 | #ifdef OBJ_ELF |
c19d1205 ZW |
1226 | /* Generic immediate-value read function for use in directives. |
1227 | Accepts anything that 'expression' can fold to a constant. | |
1228 | *val receives the number. */ | |
0198d5e6 | 1229 | |
c19d1205 ZW |
1230 | static int |
1231 | immediate_for_directive (int *val) | |
b99bd4ef | 1232 | { |
c19d1205 ZW |
1233 | expressionS exp; |
1234 | exp.X_op = O_illegal; | |
b99bd4ef | 1235 | |
c19d1205 ZW |
1236 | if (is_immediate_prefix (*input_line_pointer)) |
1237 | { | |
1238 | input_line_pointer++; | |
1239 | expression (&exp); | |
1240 | } | |
b99bd4ef | 1241 | |
c19d1205 ZW |
1242 | if (exp.X_op != O_constant) |
1243 | { | |
1244 | as_bad (_("expected #constant")); | |
1245 | ignore_rest_of_line (); | |
1246 | return FAIL; | |
1247 | } | |
1248 | *val = exp.X_add_number; | |
1249 | return SUCCESS; | |
b99bd4ef | 1250 | } |
c19d1205 | 1251 | #endif |
b99bd4ef | 1252 | |
c19d1205 | 1253 | /* Register parsing. */ |
b99bd4ef | 1254 | |
c19d1205 ZW |
1255 | /* Generic register parser. CCP points to what should be the |
1256 | beginning of a register name. If it is indeed a valid register | |
1257 | name, advance CCP over it and return the reg_entry structure; | |
1258 | otherwise return NULL. Does not issue diagnostics. */ | |
1259 | ||
1260 | static struct reg_entry * | |
1261 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1262 | { |
c19d1205 ZW |
1263 | char *start = *ccp; |
1264 | char *p; | |
1265 | struct reg_entry *reg; | |
b99bd4ef | 1266 | |
477330fc RM |
1267 | skip_whitespace (start); |
1268 | ||
c19d1205 ZW |
1269 | #ifdef REGISTER_PREFIX |
1270 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1271 | return NULL; |
c19d1205 ZW |
1272 | start++; |
1273 | #endif | |
1274 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1275 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1276 | start++; | |
1277 | #endif | |
b99bd4ef | 1278 | |
c19d1205 ZW |
1279 | p = start; |
1280 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1281 | return NULL; | |
b99bd4ef | 1282 | |
c19d1205 ZW |
1283 | do |
1284 | p++; | |
1285 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1286 | ||
1287 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1288 | ||
1289 | if (!reg) | |
1290 | return NULL; | |
1291 | ||
1292 | *ccp = p; | |
1293 | return reg; | |
b99bd4ef NC |
1294 | } |
1295 | ||
1296 | static int | |
dcbf9037 | 1297 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
477330fc | 1298 | enum arm_reg_type type) |
b99bd4ef | 1299 | { |
c19d1205 ZW |
1300 | /* Alternative syntaxes are accepted for a few register classes. */ |
1301 | switch (type) | |
1302 | { | |
1303 | case REG_TYPE_MVF: | |
1304 | case REG_TYPE_MVD: | |
1305 | case REG_TYPE_MVFX: | |
1306 | case REG_TYPE_MVDX: | |
1307 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1308 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1309 | return reg->number; |
1310 | break; | |
69b97547 | 1311 | |
c19d1205 ZW |
1312 | case REG_TYPE_CP: |
1313 | /* For backward compatibility, a bare number is valid here. */ | |
1314 | { | |
1315 | unsigned long processor = strtoul (start, ccp, 10); | |
1316 | if (*ccp != start && processor <= 15) | |
1317 | return processor; | |
1318 | } | |
1a0670f3 | 1319 | /* Fall through. */ |
6057a28f | 1320 | |
c19d1205 ZW |
1321 | case REG_TYPE_MMXWC: |
1322 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1323 | instructions that take WC registers. */ | |
79134647 | 1324 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1325 | return reg->number; |
6057a28f | 1326 | break; |
c19d1205 | 1327 | |
6057a28f | 1328 | default: |
c19d1205 | 1329 | break; |
6057a28f NC |
1330 | } |
1331 | ||
dcbf9037 JB |
1332 | return FAIL; |
1333 | } | |
1334 | ||
1335 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1336 | return value is the register number or FAIL. */ | |
1337 | ||
1338 | static int | |
1339 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1340 | { | |
1341 | char *start = *ccp; | |
1342 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1343 | int ret; | |
1344 | ||
1345 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1346 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1347 | return FAIL; | |
1348 | ||
1349 | if (reg && reg->type == type) | |
1350 | return reg->number; | |
1351 | ||
1352 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1353 | return ret; | |
1354 | ||
c19d1205 ZW |
1355 | *ccp = start; |
1356 | return FAIL; | |
1357 | } | |
69b97547 | 1358 | |
dcbf9037 JB |
1359 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1360 | character. Does no verification at this stage that the type fits the opcode | |
1361 | properly. E.g., | |
1362 | ||
1363 | .i32.i32.s16 | |
1364 | .s32.f32 | |
1365 | .u16 | |
1366 | ||
1367 | Can all be legally parsed by this function. | |
1368 | ||
1369 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1370 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1371 | type, FAIL if not. */ | |
1372 | ||
1373 | static int | |
1374 | parse_neon_type (struct neon_type *type, char **str) | |
1375 | { | |
1376 | char *ptr = *str; | |
1377 | ||
1378 | if (type) | |
1379 | type->elems = 0; | |
1380 | ||
1381 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1382 | { | |
1383 | enum neon_el_type thistype = NT_untyped; | |
1384 | unsigned thissize = -1u; | |
1385 | ||
1386 | if (*ptr != '.') | |
1387 | break; | |
1388 | ||
1389 | ptr++; | |
1390 | ||
1391 | /* Just a size without an explicit type. */ | |
1392 | if (ISDIGIT (*ptr)) | |
1393 | goto parsesize; | |
1394 | ||
1395 | switch (TOLOWER (*ptr)) | |
1396 | { | |
1397 | case 'i': thistype = NT_integer; break; | |
1398 | case 'f': thistype = NT_float; break; | |
1399 | case 'p': thistype = NT_poly; break; | |
1400 | case 's': thistype = NT_signed; break; | |
1401 | case 'u': thistype = NT_unsigned; break; | |
477330fc RM |
1402 | case 'd': |
1403 | thistype = NT_float; | |
1404 | thissize = 64; | |
1405 | ptr++; | |
1406 | goto done; | |
dcbf9037 JB |
1407 | default: |
1408 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1409 | return FAIL; | |
1410 | } | |
1411 | ||
1412 | ptr++; | |
1413 | ||
1414 | /* .f is an abbreviation for .f32. */ | |
1415 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1416 | thissize = 32; | |
1417 | else | |
1418 | { | |
1419 | parsesize: | |
1420 | thissize = strtoul (ptr, &ptr, 10); | |
1421 | ||
1422 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
477330fc RM |
1423 | && thissize != 64) |
1424 | { | |
1425 | as_bad (_("bad size %d in type specifier"), thissize); | |
dcbf9037 JB |
1426 | return FAIL; |
1427 | } | |
1428 | } | |
1429 | ||
037e8744 | 1430 | done: |
dcbf9037 | 1431 | if (type) |
477330fc RM |
1432 | { |
1433 | type->el[type->elems].type = thistype; | |
dcbf9037 JB |
1434 | type->el[type->elems].size = thissize; |
1435 | type->elems++; | |
1436 | } | |
1437 | } | |
1438 | ||
1439 | /* Empty/missing type is not a successful parse. */ | |
1440 | if (type->elems == 0) | |
1441 | return FAIL; | |
1442 | ||
1443 | *str = ptr; | |
1444 | ||
1445 | return SUCCESS; | |
1446 | } | |
1447 | ||
1448 | /* Errors may be set multiple times during parsing or bit encoding | |
1449 | (particularly in the Neon bits), but usually the earliest error which is set | |
1450 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1451 | errors by calling this function. */ | |
1452 | ||
1453 | static void | |
1454 | first_error (const char *err) | |
1455 | { | |
1456 | if (!inst.error) | |
1457 | inst.error = err; | |
1458 | } | |
1459 | ||
1460 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1461 | static int | |
1462 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1463 | { | |
1464 | char *str = *ccp; | |
1465 | struct neon_type optype; | |
1466 | ||
1467 | if (*str == '.') | |
1468 | { | |
1469 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
477330fc RM |
1470 | { |
1471 | if (optype.elems == 1) | |
1472 | *vectype = optype.el[0]; | |
1473 | else | |
1474 | { | |
1475 | first_error (_("only one type should be specified for operand")); | |
1476 | return FAIL; | |
1477 | } | |
1478 | } | |
dcbf9037 | 1479 | else |
477330fc RM |
1480 | { |
1481 | first_error (_("vector type expected")); | |
1482 | return FAIL; | |
1483 | } | |
dcbf9037 JB |
1484 | } |
1485 | else | |
1486 | return FAIL; | |
5f4273c7 | 1487 | |
dcbf9037 | 1488 | *ccp = str; |
5f4273c7 | 1489 | |
dcbf9037 JB |
1490 | return SUCCESS; |
1491 | } | |
1492 | ||
1493 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1494 | a 4-bit integer. */ | |
1495 | ||
1496 | #define NEON_ALL_LANES 15 | |
1497 | #define NEON_INTERLEAVE_LANES 14 | |
1498 | ||
1499 | /* Parse either a register or a scalar, with an optional type. Return the | |
1500 | register number, and optionally fill in the actual type of the register | |
1501 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1502 | type/index information in *TYPEINFO. */ | |
1503 | ||
1504 | static int | |
1505 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
477330fc RM |
1506 | enum arm_reg_type *rtype, |
1507 | struct neon_typed_alias *typeinfo) | |
dcbf9037 JB |
1508 | { |
1509 | char *str = *ccp; | |
1510 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1511 | struct neon_typed_alias atype; | |
1512 | struct neon_type_el parsetype; | |
1513 | ||
1514 | atype.defined = 0; | |
1515 | atype.index = -1; | |
1516 | atype.eltype.type = NT_invtype; | |
1517 | atype.eltype.size = -1; | |
1518 | ||
1519 | /* Try alternate syntax for some types of register. Note these are mutually | |
1520 | exclusive with the Neon syntax extensions. */ | |
1521 | if (reg == NULL) | |
1522 | { | |
1523 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1524 | if (altreg != FAIL) | |
477330fc | 1525 | *ccp = str; |
dcbf9037 | 1526 | if (typeinfo) |
477330fc | 1527 | *typeinfo = atype; |
dcbf9037 JB |
1528 | return altreg; |
1529 | } | |
1530 | ||
037e8744 JB |
1531 | /* Undo polymorphism when a set of register types may be accepted. */ |
1532 | if ((type == REG_TYPE_NDQ | |
1533 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1534 | || (type == REG_TYPE_VFSD | |
477330fc | 1535 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) |
037e8744 | 1536 | || (type == REG_TYPE_NSDQ |
477330fc RM |
1537 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD |
1538 | || reg->type == REG_TYPE_NQ)) | |
dec41383 JW |
1539 | || (type == REG_TYPE_NSD |
1540 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) | |
f512f76f NC |
1541 | || (type == REG_TYPE_MMXWC |
1542 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1543 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1544 | |
1545 | if (type != reg->type) | |
1546 | return FAIL; | |
1547 | ||
1548 | if (reg->neon) | |
1549 | atype = *reg->neon; | |
5f4273c7 | 1550 | |
dcbf9037 JB |
1551 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1552 | { | |
1553 | if ((atype.defined & NTA_HASTYPE) != 0) | |
477330fc RM |
1554 | { |
1555 | first_error (_("can't redefine type for operand")); | |
1556 | return FAIL; | |
1557 | } | |
dcbf9037 JB |
1558 | atype.defined |= NTA_HASTYPE; |
1559 | atype.eltype = parsetype; | |
1560 | } | |
5f4273c7 | 1561 | |
dcbf9037 JB |
1562 | if (skip_past_char (&str, '[') == SUCCESS) |
1563 | { | |
dec41383 JW |
1564 | if (type != REG_TYPE_VFD |
1565 | && !(type == REG_TYPE_VFS | |
1566 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))) | |
477330fc RM |
1567 | { |
1568 | first_error (_("only D registers may be indexed")); | |
1569 | return FAIL; | |
1570 | } | |
5f4273c7 | 1571 | |
dcbf9037 | 1572 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
1573 | { |
1574 | first_error (_("can't change index for operand")); | |
1575 | return FAIL; | |
1576 | } | |
dcbf9037 JB |
1577 | |
1578 | atype.defined |= NTA_HASINDEX; | |
1579 | ||
1580 | if (skip_past_char (&str, ']') == SUCCESS) | |
477330fc | 1581 | atype.index = NEON_ALL_LANES; |
dcbf9037 | 1582 | else |
477330fc RM |
1583 | { |
1584 | expressionS exp; | |
dcbf9037 | 1585 | |
477330fc | 1586 | my_get_expression (&exp, &str, GE_NO_PREFIX); |
dcbf9037 | 1587 | |
477330fc RM |
1588 | if (exp.X_op != O_constant) |
1589 | { | |
1590 | first_error (_("constant expression required")); | |
1591 | return FAIL; | |
1592 | } | |
dcbf9037 | 1593 | |
477330fc RM |
1594 | if (skip_past_char (&str, ']') == FAIL) |
1595 | return FAIL; | |
dcbf9037 | 1596 | |
477330fc RM |
1597 | atype.index = exp.X_add_number; |
1598 | } | |
dcbf9037 | 1599 | } |
5f4273c7 | 1600 | |
dcbf9037 JB |
1601 | if (typeinfo) |
1602 | *typeinfo = atype; | |
5f4273c7 | 1603 | |
dcbf9037 JB |
1604 | if (rtype) |
1605 | *rtype = type; | |
5f4273c7 | 1606 | |
dcbf9037 | 1607 | *ccp = str; |
5f4273c7 | 1608 | |
dcbf9037 JB |
1609 | return reg->number; |
1610 | } | |
1611 | ||
1612 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1613 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1614 | register (e.g. Neon double or quad reg when either has been requested). | |
1615 | - If this is a Neon vector type with additional type information, fill | |
1616 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1617 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1618 | |
1619 | static int | |
1620 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
477330fc | 1621 | enum arm_reg_type *rtype, struct neon_type_el *vectype) |
dcbf9037 JB |
1622 | { |
1623 | struct neon_typed_alias atype; | |
1624 | char *str = *ccp; | |
1625 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1626 | ||
1627 | if (reg == FAIL) | |
1628 | return FAIL; | |
1629 | ||
0855e32b NS |
1630 | /* Do not allow regname(... to parse as a register. */ |
1631 | if (*str == '(') | |
1632 | return FAIL; | |
1633 | ||
dcbf9037 JB |
1634 | /* Do not allow a scalar (reg+index) to parse as a register. */ |
1635 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1636 | { | |
1637 | first_error (_("register operand expected, but got scalar")); | |
1638 | return FAIL; | |
1639 | } | |
1640 | ||
1641 | if (vectype) | |
1642 | *vectype = atype.eltype; | |
1643 | ||
1644 | *ccp = str; | |
1645 | ||
1646 | return reg; | |
1647 | } | |
1648 | ||
1649 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1650 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1651 | ||
5287ad62 JB |
1652 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1653 | have enough information to be able to do a good job bounds-checking. So, we | |
1654 | just do easy checks here, and do further checks later. */ | |
1655 | ||
1656 | static int | |
dcbf9037 | 1657 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1658 | { |
dcbf9037 | 1659 | int reg; |
5287ad62 | 1660 | char *str = *ccp; |
dcbf9037 | 1661 | struct neon_typed_alias atype; |
dec41383 JW |
1662 | enum arm_reg_type reg_type = REG_TYPE_VFD; |
1663 | ||
1664 | if (elsize == 4) | |
1665 | reg_type = REG_TYPE_VFS; | |
5f4273c7 | 1666 | |
dec41383 | 1667 | reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype); |
5f4273c7 | 1668 | |
dcbf9037 | 1669 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1670 | return FAIL; |
5f4273c7 | 1671 | |
dcbf9037 | 1672 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1673 | { |
dcbf9037 | 1674 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1675 | return FAIL; |
1676 | } | |
dcbf9037 | 1677 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1678 | { |
dcbf9037 | 1679 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1680 | return FAIL; |
1681 | } | |
5f4273c7 | 1682 | |
dcbf9037 JB |
1683 | if (type) |
1684 | *type = atype.eltype; | |
5f4273c7 | 1685 | |
5287ad62 | 1686 | *ccp = str; |
5f4273c7 | 1687 | |
dcbf9037 | 1688 | return reg * 16 + atype.index; |
5287ad62 JB |
1689 | } |
1690 | ||
c19d1205 | 1691 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1692 | |
c19d1205 ZW |
1693 | static long |
1694 | parse_reg_list (char ** strp) | |
1695 | { | |
1696 | char * str = * strp; | |
1697 | long range = 0; | |
1698 | int another_range; | |
a737bd4d | 1699 | |
c19d1205 ZW |
1700 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1701 | do | |
6057a28f | 1702 | { |
477330fc RM |
1703 | skip_whitespace (str); |
1704 | ||
c19d1205 | 1705 | another_range = 0; |
a737bd4d | 1706 | |
c19d1205 ZW |
1707 | if (*str == '{') |
1708 | { | |
1709 | int in_range = 0; | |
1710 | int cur_reg = -1; | |
a737bd4d | 1711 | |
c19d1205 ZW |
1712 | str++; |
1713 | do | |
1714 | { | |
1715 | int reg; | |
6057a28f | 1716 | |
dcbf9037 | 1717 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1718 | { |
dcbf9037 | 1719 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1720 | return FAIL; |
1721 | } | |
a737bd4d | 1722 | |
c19d1205 ZW |
1723 | if (in_range) |
1724 | { | |
1725 | int i; | |
a737bd4d | 1726 | |
c19d1205 ZW |
1727 | if (reg <= cur_reg) |
1728 | { | |
dcbf9037 | 1729 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1730 | return FAIL; |
1731 | } | |
40a18ebd | 1732 | |
c19d1205 ZW |
1733 | for (i = cur_reg + 1; i < reg; i++) |
1734 | { | |
1735 | if (range & (1 << i)) | |
1736 | as_tsktsk | |
1737 | (_("Warning: duplicated register (r%d) in register list"), | |
1738 | i); | |
1739 | else | |
1740 | range |= 1 << i; | |
1741 | } | |
1742 | in_range = 0; | |
1743 | } | |
a737bd4d | 1744 | |
c19d1205 ZW |
1745 | if (range & (1 << reg)) |
1746 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1747 | reg); | |
1748 | else if (reg <= cur_reg) | |
1749 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1750 | |
c19d1205 ZW |
1751 | range |= 1 << reg; |
1752 | cur_reg = reg; | |
1753 | } | |
1754 | while (skip_past_comma (&str) != FAIL | |
1755 | || (in_range = 1, *str++ == '-')); | |
1756 | str--; | |
a737bd4d | 1757 | |
d996d970 | 1758 | if (skip_past_char (&str, '}') == FAIL) |
c19d1205 | 1759 | { |
dcbf9037 | 1760 | first_error (_("missing `}'")); |
c19d1205 ZW |
1761 | return FAIL; |
1762 | } | |
1763 | } | |
1764 | else | |
1765 | { | |
91d6fa6a | 1766 | expressionS exp; |
40a18ebd | 1767 | |
91d6fa6a | 1768 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1769 | return FAIL; |
40a18ebd | 1770 | |
91d6fa6a | 1771 | if (exp.X_op == O_constant) |
c19d1205 | 1772 | { |
91d6fa6a NC |
1773 | if (exp.X_add_number |
1774 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1775 | { |
1776 | inst.error = _("invalid register mask"); | |
1777 | return FAIL; | |
1778 | } | |
a737bd4d | 1779 | |
91d6fa6a | 1780 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1781 | { |
91d6fa6a | 1782 | int regno = range & exp.X_add_number; |
a737bd4d | 1783 | |
c19d1205 ZW |
1784 | regno &= -regno; |
1785 | regno = (1 << regno) - 1; | |
1786 | as_tsktsk | |
1787 | (_("Warning: duplicated register (r%d) in register list"), | |
1788 | regno); | |
1789 | } | |
a737bd4d | 1790 | |
91d6fa6a | 1791 | range |= exp.X_add_number; |
c19d1205 ZW |
1792 | } |
1793 | else | |
1794 | { | |
e2b0ab59 | 1795 | if (inst.relocs[0].type != 0) |
c19d1205 ZW |
1796 | { |
1797 | inst.error = _("expression too complex"); | |
1798 | return FAIL; | |
1799 | } | |
a737bd4d | 1800 | |
e2b0ab59 AV |
1801 | memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS)); |
1802 | inst.relocs[0].type = BFD_RELOC_ARM_MULTI; | |
1803 | inst.relocs[0].pc_rel = 0; | |
c19d1205 ZW |
1804 | } |
1805 | } | |
a737bd4d | 1806 | |
c19d1205 ZW |
1807 | if (*str == '|' || *str == '+') |
1808 | { | |
1809 | str++; | |
1810 | another_range = 1; | |
1811 | } | |
a737bd4d | 1812 | } |
c19d1205 | 1813 | while (another_range); |
a737bd4d | 1814 | |
c19d1205 ZW |
1815 | *strp = str; |
1816 | return range; | |
a737bd4d NC |
1817 | } |
1818 | ||
5287ad62 JB |
1819 | /* Types of registers in a list. */ |
1820 | ||
1821 | enum reg_list_els | |
1822 | { | |
1823 | REGLIST_VFP_S, | |
1824 | REGLIST_VFP_D, | |
1825 | REGLIST_NEON_D | |
1826 | }; | |
1827 | ||
c19d1205 ZW |
1828 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1829 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1830 | register. Parses registers of type ETYPE. |
1831 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1832 | - Q registers can be used to specify pairs of D registers | |
1833 | - { } can be omitted from around a singleton register list | |
477330fc RM |
1834 | FIXME: This is not implemented, as it would require backtracking in |
1835 | some cases, e.g.: | |
1836 | vtbl.8 d3,d4,d5 | |
1837 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1838 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1839 | - 32 D registers may be used (also true for VFPv3). |
1840 | FIXME: Types are ignored in these register lists, which is probably a | |
1841 | bug. */ | |
6057a28f | 1842 | |
c19d1205 | 1843 | static int |
037e8744 | 1844 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1845 | { |
037e8744 | 1846 | char *str = *ccp; |
c19d1205 ZW |
1847 | int base_reg; |
1848 | int new_base; | |
21d799b5 | 1849 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1850 | int max_regs = 0; |
c19d1205 ZW |
1851 | int count = 0; |
1852 | int warned = 0; | |
1853 | unsigned long mask = 0; | |
a737bd4d | 1854 | int i; |
6057a28f | 1855 | |
477330fc | 1856 | if (skip_past_char (&str, '{') == FAIL) |
5287ad62 JB |
1857 | { |
1858 | inst.error = _("expecting {"); | |
1859 | return FAIL; | |
1860 | } | |
6057a28f | 1861 | |
5287ad62 | 1862 | switch (etype) |
c19d1205 | 1863 | { |
5287ad62 | 1864 | case REGLIST_VFP_S: |
c19d1205 ZW |
1865 | regtype = REG_TYPE_VFS; |
1866 | max_regs = 32; | |
5287ad62 | 1867 | break; |
5f4273c7 | 1868 | |
5287ad62 JB |
1869 | case REGLIST_VFP_D: |
1870 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1871 | break; |
5f4273c7 | 1872 | |
b7fc2769 JB |
1873 | case REGLIST_NEON_D: |
1874 | regtype = REG_TYPE_NDQ; | |
1875 | break; | |
1876 | } | |
1877 | ||
1878 | if (etype != REGLIST_VFP_S) | |
1879 | { | |
b1cc4aeb PB |
1880 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1881 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
477330fc RM |
1882 | { |
1883 | max_regs = 32; | |
1884 | if (thumb_mode) | |
1885 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
1886 | fpu_vfp_ext_d32); | |
1887 | else | |
1888 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
1889 | fpu_vfp_ext_d32); | |
1890 | } | |
5287ad62 | 1891 | else |
477330fc | 1892 | max_regs = 16; |
c19d1205 | 1893 | } |
6057a28f | 1894 | |
c19d1205 | 1895 | base_reg = max_regs; |
a737bd4d | 1896 | |
c19d1205 ZW |
1897 | do |
1898 | { | |
5287ad62 | 1899 | int setmask = 1, addregs = 1; |
dcbf9037 | 1900 | |
037e8744 | 1901 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1902 | |
c19d1205 | 1903 | if (new_base == FAIL) |
a737bd4d | 1904 | { |
dcbf9037 | 1905 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1906 | return FAIL; |
1907 | } | |
5f4273c7 | 1908 | |
b7fc2769 | 1909 | if (new_base >= max_regs) |
477330fc RM |
1910 | { |
1911 | first_error (_("register out of range in list")); | |
1912 | return FAIL; | |
1913 | } | |
5f4273c7 | 1914 | |
5287ad62 JB |
1915 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1916 | if (regtype == REG_TYPE_NQ) | |
477330fc RM |
1917 | { |
1918 | setmask = 3; | |
1919 | addregs = 2; | |
1920 | } | |
5287ad62 | 1921 | |
c19d1205 ZW |
1922 | if (new_base < base_reg) |
1923 | base_reg = new_base; | |
a737bd4d | 1924 | |
5287ad62 | 1925 | if (mask & (setmask << new_base)) |
c19d1205 | 1926 | { |
dcbf9037 | 1927 | first_error (_("invalid register list")); |
c19d1205 | 1928 | return FAIL; |
a737bd4d | 1929 | } |
a737bd4d | 1930 | |
c19d1205 ZW |
1931 | if ((mask >> new_base) != 0 && ! warned) |
1932 | { | |
1933 | as_tsktsk (_("register list not in ascending order")); | |
1934 | warned = 1; | |
1935 | } | |
0bbf2aa4 | 1936 | |
5287ad62 JB |
1937 | mask |= setmask << new_base; |
1938 | count += addregs; | |
0bbf2aa4 | 1939 | |
037e8744 | 1940 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1941 | { |
1942 | int high_range; | |
0bbf2aa4 | 1943 | |
037e8744 | 1944 | str++; |
0bbf2aa4 | 1945 | |
037e8744 | 1946 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
477330fc | 1947 | == FAIL) |
c19d1205 ZW |
1948 | { |
1949 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1950 | return FAIL; | |
1951 | } | |
0bbf2aa4 | 1952 | |
477330fc RM |
1953 | if (high_range >= max_regs) |
1954 | { | |
1955 | first_error (_("register out of range in list")); | |
1956 | return FAIL; | |
1957 | } | |
b7fc2769 | 1958 | |
477330fc RM |
1959 | if (regtype == REG_TYPE_NQ) |
1960 | high_range = high_range + 1; | |
5287ad62 | 1961 | |
c19d1205 ZW |
1962 | if (high_range <= new_base) |
1963 | { | |
1964 | inst.error = _("register range not in ascending order"); | |
1965 | return FAIL; | |
1966 | } | |
0bbf2aa4 | 1967 | |
5287ad62 | 1968 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1969 | { |
5287ad62 | 1970 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1971 | { |
c19d1205 ZW |
1972 | inst.error = _("invalid register list"); |
1973 | return FAIL; | |
0bbf2aa4 | 1974 | } |
c19d1205 | 1975 | |
5287ad62 JB |
1976 | mask |= setmask << new_base; |
1977 | count += addregs; | |
0bbf2aa4 | 1978 | } |
0bbf2aa4 | 1979 | } |
0bbf2aa4 | 1980 | } |
037e8744 | 1981 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1982 | |
037e8744 | 1983 | str++; |
0bbf2aa4 | 1984 | |
c19d1205 ZW |
1985 | /* Sanity check -- should have raised a parse error above. */ |
1986 | if (count == 0 || count > max_regs) | |
1987 | abort (); | |
1988 | ||
1989 | *pbase = base_reg; | |
1990 | ||
1991 | /* Final test -- the registers must be consecutive. */ | |
1992 | mask >>= base_reg; | |
1993 | for (i = 0; i < count; i++) | |
1994 | { | |
1995 | if ((mask & (1u << i)) == 0) | |
1996 | { | |
1997 | inst.error = _("non-contiguous register range"); | |
1998 | return FAIL; | |
1999 | } | |
2000 | } | |
2001 | ||
037e8744 JB |
2002 | *ccp = str; |
2003 | ||
c19d1205 | 2004 | return count; |
b99bd4ef NC |
2005 | } |
2006 | ||
dcbf9037 JB |
2007 | /* True if two alias types are the same. */ |
2008 | ||
c921be7d | 2009 | static bfd_boolean |
dcbf9037 JB |
2010 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
2011 | { | |
2012 | if (!a && !b) | |
c921be7d | 2013 | return TRUE; |
5f4273c7 | 2014 | |
dcbf9037 | 2015 | if (!a || !b) |
c921be7d | 2016 | return FALSE; |
dcbf9037 JB |
2017 | |
2018 | if (a->defined != b->defined) | |
c921be7d | 2019 | return FALSE; |
5f4273c7 | 2020 | |
dcbf9037 JB |
2021 | if ((a->defined & NTA_HASTYPE) != 0 |
2022 | && (a->eltype.type != b->eltype.type | |
477330fc | 2023 | || a->eltype.size != b->eltype.size)) |
c921be7d | 2024 | return FALSE; |
dcbf9037 JB |
2025 | |
2026 | if ((a->defined & NTA_HASINDEX) != 0 | |
2027 | && (a->index != b->index)) | |
c921be7d | 2028 | return FALSE; |
5f4273c7 | 2029 | |
c921be7d | 2030 | return TRUE; |
dcbf9037 JB |
2031 | } |
2032 | ||
5287ad62 JB |
2033 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
2034 | The base register is put in *PBASE. | |
dcbf9037 | 2035 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
2036 | the return value. |
2037 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
2038 | Bits [6:5] encode the list length (minus one). |
2039 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 2040 | |
5287ad62 | 2041 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 2042 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
2043 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
2044 | ||
2045 | static int | |
dcbf9037 | 2046 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
477330fc | 2047 | struct neon_type_el *eltype) |
5287ad62 JB |
2048 | { |
2049 | char *ptr = *str; | |
2050 | int base_reg = -1; | |
2051 | int reg_incr = -1; | |
2052 | int count = 0; | |
2053 | int lane = -1; | |
2054 | int leading_brace = 0; | |
2055 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
20203fb9 NC |
2056 | const char *const incr_error = _("register stride must be 1 or 2"); |
2057 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 2058 | struct neon_typed_alias firsttype; |
f85d59c3 KT |
2059 | firsttype.defined = 0; |
2060 | firsttype.eltype.type = NT_invtype; | |
2061 | firsttype.eltype.size = -1; | |
2062 | firsttype.index = -1; | |
5f4273c7 | 2063 | |
5287ad62 JB |
2064 | if (skip_past_char (&ptr, '{') == SUCCESS) |
2065 | leading_brace = 1; | |
5f4273c7 | 2066 | |
5287ad62 JB |
2067 | do |
2068 | { | |
dcbf9037 JB |
2069 | struct neon_typed_alias atype; |
2070 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
2071 | ||
5287ad62 | 2072 | if (getreg == FAIL) |
477330fc RM |
2073 | { |
2074 | first_error (_(reg_expected_msgs[rtype])); | |
2075 | return FAIL; | |
2076 | } | |
5f4273c7 | 2077 | |
5287ad62 | 2078 | if (base_reg == -1) |
477330fc RM |
2079 | { |
2080 | base_reg = getreg; | |
2081 | if (rtype == REG_TYPE_NQ) | |
2082 | { | |
2083 | reg_incr = 1; | |
2084 | } | |
2085 | firsttype = atype; | |
2086 | } | |
5287ad62 | 2087 | else if (reg_incr == -1) |
477330fc RM |
2088 | { |
2089 | reg_incr = getreg - base_reg; | |
2090 | if (reg_incr < 1 || reg_incr > 2) | |
2091 | { | |
2092 | first_error (_(incr_error)); | |
2093 | return FAIL; | |
2094 | } | |
2095 | } | |
5287ad62 | 2096 | else if (getreg != base_reg + reg_incr * count) |
477330fc RM |
2097 | { |
2098 | first_error (_(incr_error)); | |
2099 | return FAIL; | |
2100 | } | |
dcbf9037 | 2101 | |
c921be7d | 2102 | if (! neon_alias_types_same (&atype, &firsttype)) |
477330fc RM |
2103 | { |
2104 | first_error (_(type_error)); | |
2105 | return FAIL; | |
2106 | } | |
5f4273c7 | 2107 | |
5287ad62 | 2108 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
477330fc | 2109 | modes. */ |
5287ad62 | 2110 | if (ptr[0] == '-') |
477330fc RM |
2111 | { |
2112 | struct neon_typed_alias htype; | |
2113 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; | |
2114 | if (lane == -1) | |
2115 | lane = NEON_INTERLEAVE_LANES; | |
2116 | else if (lane != NEON_INTERLEAVE_LANES) | |
2117 | { | |
2118 | first_error (_(type_error)); | |
2119 | return FAIL; | |
2120 | } | |
2121 | if (reg_incr == -1) | |
2122 | reg_incr = 1; | |
2123 | else if (reg_incr != 1) | |
2124 | { | |
2125 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); | |
2126 | return FAIL; | |
2127 | } | |
2128 | ptr++; | |
2129 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); | |
2130 | if (hireg == FAIL) | |
2131 | { | |
2132 | first_error (_(reg_expected_msgs[rtype])); | |
2133 | return FAIL; | |
2134 | } | |
2135 | if (! neon_alias_types_same (&htype, &firsttype)) | |
2136 | { | |
2137 | first_error (_(type_error)); | |
2138 | return FAIL; | |
2139 | } | |
2140 | count += hireg + dregs - getreg; | |
2141 | continue; | |
2142 | } | |
5f4273c7 | 2143 | |
5287ad62 JB |
2144 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2145 | if (rtype == REG_TYPE_NQ) | |
477330fc RM |
2146 | { |
2147 | count += 2; | |
2148 | continue; | |
2149 | } | |
5f4273c7 | 2150 | |
dcbf9037 | 2151 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
2152 | { |
2153 | if (lane == -1) | |
2154 | lane = atype.index; | |
2155 | else if (lane != atype.index) | |
2156 | { | |
2157 | first_error (_(type_error)); | |
2158 | return FAIL; | |
2159 | } | |
2160 | } | |
5287ad62 | 2161 | else if (lane == -1) |
477330fc | 2162 | lane = NEON_INTERLEAVE_LANES; |
5287ad62 | 2163 | else if (lane != NEON_INTERLEAVE_LANES) |
477330fc RM |
2164 | { |
2165 | first_error (_(type_error)); | |
2166 | return FAIL; | |
2167 | } | |
5287ad62 JB |
2168 | count++; |
2169 | } | |
2170 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2171 | |
5287ad62 JB |
2172 | /* No lane set by [x]. We must be interleaving structures. */ |
2173 | if (lane == -1) | |
2174 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2175 | |
5287ad62 JB |
2176 | /* Sanity check. */ |
2177 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
2178 | || (count > 1 && reg_incr == -1)) | |
2179 | { | |
dcbf9037 | 2180 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2181 | return FAIL; |
2182 | } | |
2183 | ||
2184 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2185 | { | |
dcbf9037 | 2186 | first_error (_("expected }")); |
5287ad62 JB |
2187 | return FAIL; |
2188 | } | |
5f4273c7 | 2189 | |
5287ad62 JB |
2190 | if (reg_incr == -1) |
2191 | reg_incr = 1; | |
2192 | ||
dcbf9037 JB |
2193 | if (eltype) |
2194 | *eltype = firsttype.eltype; | |
2195 | ||
5287ad62 JB |
2196 | *pbase = base_reg; |
2197 | *str = ptr; | |
5f4273c7 | 2198 | |
5287ad62 JB |
2199 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2200 | } | |
2201 | ||
c19d1205 ZW |
2202 | /* Parse an explicit relocation suffix on an expression. This is |
2203 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2204 | arm_reloc_hsh contains no entries, so this function can only | |
2205 | succeed if there is no () after the word. Returns -1 on error, | |
2206 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
3da1d841 | 2207 | |
c19d1205 ZW |
2208 | static int |
2209 | parse_reloc (char **str) | |
b99bd4ef | 2210 | { |
c19d1205 ZW |
2211 | struct reloc_entry *r; |
2212 | char *p, *q; | |
b99bd4ef | 2213 | |
c19d1205 ZW |
2214 | if (**str != '(') |
2215 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2216 | |
c19d1205 ZW |
2217 | p = *str + 1; |
2218 | q = p; | |
2219 | ||
2220 | while (*q && *q != ')' && *q != ',') | |
2221 | q++; | |
2222 | if (*q != ')') | |
2223 | return -1; | |
2224 | ||
21d799b5 NC |
2225 | if ((r = (struct reloc_entry *) |
2226 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2227 | return -1; |
2228 | ||
2229 | *str = q + 1; | |
2230 | return r->reloc; | |
b99bd4ef NC |
2231 | } |
2232 | ||
c19d1205 ZW |
2233 | /* Directives: register aliases. */ |
2234 | ||
dcbf9037 | 2235 | static struct reg_entry * |
90ec0d68 | 2236 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2237 | { |
d3ce72d0 | 2238 | struct reg_entry *new_reg; |
c19d1205 | 2239 | const char *name; |
b99bd4ef | 2240 | |
d3ce72d0 | 2241 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2242 | { |
d3ce72d0 | 2243 | if (new_reg->builtin) |
c19d1205 | 2244 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2245 | |
c19d1205 ZW |
2246 | /* Only warn about a redefinition if it's not defined as the |
2247 | same register. */ | |
d3ce72d0 | 2248 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2249 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2250 | |
d929913e | 2251 | return NULL; |
c19d1205 | 2252 | } |
b99bd4ef | 2253 | |
c19d1205 | 2254 | name = xstrdup (str); |
325801bd | 2255 | new_reg = XNEW (struct reg_entry); |
b99bd4ef | 2256 | |
d3ce72d0 NC |
2257 | new_reg->name = name; |
2258 | new_reg->number = number; | |
2259 | new_reg->type = type; | |
2260 | new_reg->builtin = FALSE; | |
2261 | new_reg->neon = NULL; | |
b99bd4ef | 2262 | |
d3ce72d0 | 2263 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2264 | abort (); |
5f4273c7 | 2265 | |
d3ce72d0 | 2266 | return new_reg; |
dcbf9037 JB |
2267 | } |
2268 | ||
2269 | static void | |
2270 | insert_neon_reg_alias (char *str, int number, int type, | |
477330fc | 2271 | struct neon_typed_alias *atype) |
dcbf9037 JB |
2272 | { |
2273 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2274 | |
dcbf9037 JB |
2275 | if (!reg) |
2276 | { | |
2277 | first_error (_("attempt to redefine typed alias")); | |
2278 | return; | |
2279 | } | |
5f4273c7 | 2280 | |
dcbf9037 JB |
2281 | if (atype) |
2282 | { | |
325801bd | 2283 | reg->neon = XNEW (struct neon_typed_alias); |
dcbf9037 JB |
2284 | *reg->neon = *atype; |
2285 | } | |
c19d1205 | 2286 | } |
b99bd4ef | 2287 | |
c19d1205 | 2288 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2289 | |
c19d1205 | 2290 | new_register_name .req existing_register_name |
b99bd4ef | 2291 | |
c19d1205 | 2292 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2293 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2294 | |
d929913e | 2295 | static bfd_boolean |
c19d1205 ZW |
2296 | create_register_alias (char * newname, char *p) |
2297 | { | |
2298 | struct reg_entry *old; | |
2299 | char *oldname, *nbuf; | |
2300 | size_t nlen; | |
b99bd4ef | 2301 | |
c19d1205 ZW |
2302 | /* The input scrubber ensures that whitespace after the mnemonic is |
2303 | collapsed to single spaces. */ | |
2304 | oldname = p; | |
2305 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2306 | return FALSE; |
b99bd4ef | 2307 | |
c19d1205 ZW |
2308 | oldname += 6; |
2309 | if (*oldname == '\0') | |
d929913e | 2310 | return FALSE; |
b99bd4ef | 2311 | |
21d799b5 | 2312 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2313 | if (!old) |
b99bd4ef | 2314 | { |
c19d1205 | 2315 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2316 | return TRUE; |
b99bd4ef NC |
2317 | } |
2318 | ||
c19d1205 ZW |
2319 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2320 | the desired alias name, and p points to its end. If not, then | |
2321 | the desired alias name is in the global original_case_string. */ | |
2322 | #ifdef TC_CASE_SENSITIVE | |
2323 | nlen = p - newname; | |
2324 | #else | |
2325 | newname = original_case_string; | |
2326 | nlen = strlen (newname); | |
2327 | #endif | |
b99bd4ef | 2328 | |
29a2809e | 2329 | nbuf = xmemdup0 (newname, nlen); |
b99bd4ef | 2330 | |
c19d1205 ZW |
2331 | /* Create aliases under the new name as stated; an all-lowercase |
2332 | version of the new name; and an all-uppercase version of the new | |
2333 | name. */ | |
d929913e NC |
2334 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2335 | { | |
2336 | for (p = nbuf; *p; p++) | |
2337 | *p = TOUPPER (*p); | |
c19d1205 | 2338 | |
d929913e NC |
2339 | if (strncmp (nbuf, newname, nlen)) |
2340 | { | |
2341 | /* If this attempt to create an additional alias fails, do not bother | |
2342 | trying to create the all-lower case alias. We will fail and issue | |
2343 | a second, duplicate error message. This situation arises when the | |
2344 | programmer does something like: | |
2345 | foo .req r0 | |
2346 | Foo .req r1 | |
2347 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2348 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2349 | first .req. */ |
2350 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
e1fa0163 NC |
2351 | { |
2352 | free (nbuf); | |
2353 | return TRUE; | |
2354 | } | |
d929913e | 2355 | } |
c19d1205 | 2356 | |
d929913e NC |
2357 | for (p = nbuf; *p; p++) |
2358 | *p = TOLOWER (*p); | |
c19d1205 | 2359 | |
d929913e NC |
2360 | if (strncmp (nbuf, newname, nlen)) |
2361 | insert_reg_alias (nbuf, old->number, old->type); | |
2362 | } | |
c19d1205 | 2363 | |
e1fa0163 | 2364 | free (nbuf); |
d929913e | 2365 | return TRUE; |
b99bd4ef NC |
2366 | } |
2367 | ||
dcbf9037 JB |
2368 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2369 | X .dn d5.s32[1] | |
2370 | Y .qn 6.s16 | |
2371 | Z .dn d7 | |
2372 | T .dn Z[0] | |
2373 | These typed registers can be used instead of the types specified after the | |
2374 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2375 | specified directly, e.g.: | |
5f4273c7 | 2376 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2377 | |
c921be7d | 2378 | static bfd_boolean |
dcbf9037 JB |
2379 | create_neon_reg_alias (char *newname, char *p) |
2380 | { | |
2381 | enum arm_reg_type basetype; | |
2382 | struct reg_entry *basereg; | |
2383 | struct reg_entry mybasereg; | |
2384 | struct neon_type ntype; | |
2385 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2386 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2387 | int namelen; |
5f4273c7 | 2388 | |
dcbf9037 JB |
2389 | typeinfo.defined = 0; |
2390 | typeinfo.eltype.type = NT_invtype; | |
2391 | typeinfo.eltype.size = -1; | |
2392 | typeinfo.index = -1; | |
5f4273c7 | 2393 | |
dcbf9037 | 2394 | nameend = p; |
5f4273c7 | 2395 | |
dcbf9037 JB |
2396 | if (strncmp (p, " .dn ", 5) == 0) |
2397 | basetype = REG_TYPE_VFD; | |
2398 | else if (strncmp (p, " .qn ", 5) == 0) | |
2399 | basetype = REG_TYPE_NQ; | |
2400 | else | |
c921be7d | 2401 | return FALSE; |
5f4273c7 | 2402 | |
dcbf9037 | 2403 | p += 5; |
5f4273c7 | 2404 | |
dcbf9037 | 2405 | if (*p == '\0') |
c921be7d | 2406 | return FALSE; |
5f4273c7 | 2407 | |
dcbf9037 JB |
2408 | basereg = arm_reg_parse_multi (&p); |
2409 | ||
2410 | if (basereg && basereg->type != basetype) | |
2411 | { | |
2412 | as_bad (_("bad type for register")); | |
c921be7d | 2413 | return FALSE; |
dcbf9037 JB |
2414 | } |
2415 | ||
2416 | if (basereg == NULL) | |
2417 | { | |
2418 | expressionS exp; | |
2419 | /* Try parsing as an integer. */ | |
2420 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2421 | if (exp.X_op != O_constant) | |
477330fc RM |
2422 | { |
2423 | as_bad (_("expression must be constant")); | |
2424 | return FALSE; | |
2425 | } | |
dcbf9037 JB |
2426 | basereg = &mybasereg; |
2427 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
477330fc | 2428 | : exp.X_add_number; |
dcbf9037 JB |
2429 | basereg->neon = 0; |
2430 | } | |
2431 | ||
2432 | if (basereg->neon) | |
2433 | typeinfo = *basereg->neon; | |
2434 | ||
2435 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2436 | { | |
2437 | /* We got a type. */ | |
2438 | if (typeinfo.defined & NTA_HASTYPE) | |
477330fc RM |
2439 | { |
2440 | as_bad (_("can't redefine the type of a register alias")); | |
2441 | return FALSE; | |
2442 | } | |
5f4273c7 | 2443 | |
dcbf9037 JB |
2444 | typeinfo.defined |= NTA_HASTYPE; |
2445 | if (ntype.elems != 1) | |
477330fc RM |
2446 | { |
2447 | as_bad (_("you must specify a single type only")); | |
2448 | return FALSE; | |
2449 | } | |
dcbf9037 JB |
2450 | typeinfo.eltype = ntype.el[0]; |
2451 | } | |
5f4273c7 | 2452 | |
dcbf9037 JB |
2453 | if (skip_past_char (&p, '[') == SUCCESS) |
2454 | { | |
2455 | expressionS exp; | |
2456 | /* We got a scalar index. */ | |
5f4273c7 | 2457 | |
dcbf9037 | 2458 | if (typeinfo.defined & NTA_HASINDEX) |
477330fc RM |
2459 | { |
2460 | as_bad (_("can't redefine the index of a scalar alias")); | |
2461 | return FALSE; | |
2462 | } | |
5f4273c7 | 2463 | |
dcbf9037 | 2464 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2465 | |
dcbf9037 | 2466 | if (exp.X_op != O_constant) |
477330fc RM |
2467 | { |
2468 | as_bad (_("scalar index must be constant")); | |
2469 | return FALSE; | |
2470 | } | |
5f4273c7 | 2471 | |
dcbf9037 JB |
2472 | typeinfo.defined |= NTA_HASINDEX; |
2473 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2474 | |
dcbf9037 | 2475 | if (skip_past_char (&p, ']') == FAIL) |
477330fc RM |
2476 | { |
2477 | as_bad (_("expecting ]")); | |
2478 | return FALSE; | |
2479 | } | |
dcbf9037 JB |
2480 | } |
2481 | ||
15735687 NS |
2482 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2483 | the desired alias name, and p points to its end. If not, then | |
2484 | the desired alias name is in the global original_case_string. */ | |
2485 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2486 | namelen = nameend - newname; |
15735687 NS |
2487 | #else |
2488 | newname = original_case_string; | |
2489 | namelen = strlen (newname); | |
2490 | #endif | |
2491 | ||
29a2809e | 2492 | namebuf = xmemdup0 (newname, namelen); |
5f4273c7 | 2493 | |
dcbf9037 | 2494 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
477330fc | 2495 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2496 | |
dcbf9037 JB |
2497 | /* Insert name in all uppercase. */ |
2498 | for (p = namebuf; *p; p++) | |
2499 | *p = TOUPPER (*p); | |
5f4273c7 | 2500 | |
dcbf9037 JB |
2501 | if (strncmp (namebuf, newname, namelen)) |
2502 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2503 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2504 | |
dcbf9037 JB |
2505 | /* Insert name in all lowercase. */ |
2506 | for (p = namebuf; *p; p++) | |
2507 | *p = TOLOWER (*p); | |
5f4273c7 | 2508 | |
dcbf9037 JB |
2509 | if (strncmp (namebuf, newname, namelen)) |
2510 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2511 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2512 | |
e1fa0163 | 2513 | free (namebuf); |
c921be7d | 2514 | return TRUE; |
dcbf9037 JB |
2515 | } |
2516 | ||
c19d1205 ZW |
2517 | /* Should never be called, as .req goes between the alias and the |
2518 | register name, not at the beginning of the line. */ | |
c921be7d | 2519 | |
b99bd4ef | 2520 | static void |
c19d1205 | 2521 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2522 | { |
c19d1205 ZW |
2523 | as_bad (_("invalid syntax for .req directive")); |
2524 | } | |
b99bd4ef | 2525 | |
dcbf9037 JB |
2526 | static void |
2527 | s_dn (int a ATTRIBUTE_UNUSED) | |
2528 | { | |
2529 | as_bad (_("invalid syntax for .dn directive")); | |
2530 | } | |
2531 | ||
2532 | static void | |
2533 | s_qn (int a ATTRIBUTE_UNUSED) | |
2534 | { | |
2535 | as_bad (_("invalid syntax for .qn directive")); | |
2536 | } | |
2537 | ||
c19d1205 ZW |
2538 | /* The .unreq directive deletes an alias which was previously defined |
2539 | by .req. For example: | |
b99bd4ef | 2540 | |
c19d1205 ZW |
2541 | my_alias .req r11 |
2542 | .unreq my_alias */ | |
b99bd4ef NC |
2543 | |
2544 | static void | |
c19d1205 | 2545 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2546 | { |
c19d1205 ZW |
2547 | char * name; |
2548 | char saved_char; | |
b99bd4ef | 2549 | |
c19d1205 ZW |
2550 | name = input_line_pointer; |
2551 | ||
2552 | while (*input_line_pointer != 0 | |
2553 | && *input_line_pointer != ' ' | |
2554 | && *input_line_pointer != '\n') | |
2555 | ++input_line_pointer; | |
2556 | ||
2557 | saved_char = *input_line_pointer; | |
2558 | *input_line_pointer = 0; | |
2559 | ||
2560 | if (!*name) | |
2561 | as_bad (_("invalid syntax for .unreq directive")); | |
2562 | else | |
2563 | { | |
21d799b5 | 2564 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
477330fc | 2565 | name); |
c19d1205 ZW |
2566 | |
2567 | if (!reg) | |
2568 | as_bad (_("unknown register alias '%s'"), name); | |
2569 | else if (reg->builtin) | |
a1727c1a | 2570 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2571 | name); |
2572 | else | |
2573 | { | |
d929913e NC |
2574 | char * p; |
2575 | char * nbuf; | |
2576 | ||
db0bc284 | 2577 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2578 | free ((char *) reg->name); |
477330fc RM |
2579 | if (reg->neon) |
2580 | free (reg->neon); | |
c19d1205 | 2581 | free (reg); |
d929913e NC |
2582 | |
2583 | /* Also locate the all upper case and all lower case versions. | |
2584 | Do not complain if we cannot find one or the other as it | |
2585 | was probably deleted above. */ | |
5f4273c7 | 2586 | |
d929913e NC |
2587 | nbuf = strdup (name); |
2588 | for (p = nbuf; *p; p++) | |
2589 | *p = TOUPPER (*p); | |
21d799b5 | 2590 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2591 | if (reg) |
2592 | { | |
db0bc284 | 2593 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2594 | free ((char *) reg->name); |
2595 | if (reg->neon) | |
2596 | free (reg->neon); | |
2597 | free (reg); | |
2598 | } | |
2599 | ||
2600 | for (p = nbuf; *p; p++) | |
2601 | *p = TOLOWER (*p); | |
21d799b5 | 2602 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2603 | if (reg) |
2604 | { | |
db0bc284 | 2605 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2606 | free ((char *) reg->name); |
2607 | if (reg->neon) | |
2608 | free (reg->neon); | |
2609 | free (reg); | |
2610 | } | |
2611 | ||
2612 | free (nbuf); | |
c19d1205 ZW |
2613 | } |
2614 | } | |
b99bd4ef | 2615 | |
c19d1205 | 2616 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2617 | demand_empty_rest_of_line (); |
2618 | } | |
2619 | ||
c19d1205 ZW |
2620 | /* Directives: Instruction set selection. */ |
2621 | ||
2622 | #ifdef OBJ_ELF | |
2623 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2624 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2625 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2626 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2627 | ||
cd000bff DJ |
2628 | /* Create a new mapping symbol for the transition to STATE. */ |
2629 | ||
2630 | static void | |
2631 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2632 | { |
a737bd4d | 2633 | symbolS * symbolP; |
c19d1205 ZW |
2634 | const char * symname; |
2635 | int type; | |
b99bd4ef | 2636 | |
c19d1205 | 2637 | switch (state) |
b99bd4ef | 2638 | { |
c19d1205 ZW |
2639 | case MAP_DATA: |
2640 | symname = "$d"; | |
2641 | type = BSF_NO_FLAGS; | |
2642 | break; | |
2643 | case MAP_ARM: | |
2644 | symname = "$a"; | |
2645 | type = BSF_NO_FLAGS; | |
2646 | break; | |
2647 | case MAP_THUMB: | |
2648 | symname = "$t"; | |
2649 | type = BSF_NO_FLAGS; | |
2650 | break; | |
c19d1205 ZW |
2651 | default: |
2652 | abort (); | |
2653 | } | |
2654 | ||
cd000bff | 2655 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2656 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2657 | ||
2658 | switch (state) | |
2659 | { | |
2660 | case MAP_ARM: | |
2661 | THUMB_SET_FUNC (symbolP, 0); | |
2662 | ARM_SET_THUMB (symbolP, 0); | |
2663 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2664 | break; | |
2665 | ||
2666 | case MAP_THUMB: | |
2667 | THUMB_SET_FUNC (symbolP, 1); | |
2668 | ARM_SET_THUMB (symbolP, 1); | |
2669 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2670 | break; | |
2671 | ||
2672 | case MAP_DATA: | |
2673 | default: | |
cd000bff DJ |
2674 | break; |
2675 | } | |
2676 | ||
2677 | /* Save the mapping symbols for future reference. Also check that | |
2678 | we do not place two mapping symbols at the same offset within a | |
2679 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2680 | check_mapping_symbols. |
2681 | ||
2682 | If .fill or other data filling directive generates zero sized data, | |
2683 | the mapping symbol for the following code will have the same value | |
2684 | as the one generated for the data filling directive. In this case, | |
2685 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2686 | if (value == 0) |
2687 | { | |
2de7820f JZ |
2688 | if (frag->tc_frag_data.first_map != NULL) |
2689 | { | |
2690 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2691 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2692 | } | |
cd000bff DJ |
2693 | frag->tc_frag_data.first_map = symbolP; |
2694 | } | |
2695 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2696 | { |
2697 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2698 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2699 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2700 | } | |
cd000bff DJ |
2701 | frag->tc_frag_data.last_map = symbolP; |
2702 | } | |
2703 | ||
2704 | /* We must sometimes convert a region marked as code to data during | |
2705 | code alignment, if an odd number of bytes have to be padded. The | |
2706 | code mapping symbol is pushed to an aligned address. */ | |
2707 | ||
2708 | static void | |
2709 | insert_data_mapping_symbol (enum mstate state, | |
2710 | valueT value, fragS *frag, offsetT bytes) | |
2711 | { | |
2712 | /* If there was already a mapping symbol, remove it. */ | |
2713 | if (frag->tc_frag_data.last_map != NULL | |
2714 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2715 | { | |
2716 | symbolS *symp = frag->tc_frag_data.last_map; | |
2717 | ||
2718 | if (value == 0) | |
2719 | { | |
2720 | know (frag->tc_frag_data.first_map == symp); | |
2721 | frag->tc_frag_data.first_map = NULL; | |
2722 | } | |
2723 | frag->tc_frag_data.last_map = NULL; | |
2724 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2725 | } |
cd000bff DJ |
2726 | |
2727 | make_mapping_symbol (MAP_DATA, value, frag); | |
2728 | make_mapping_symbol (state, value + bytes, frag); | |
2729 | } | |
2730 | ||
2731 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2732 | ||
2733 | /* Set the mapping state to STATE. Only call this when about to | |
2734 | emit some STATE bytes to the file. */ | |
2735 | ||
4e9aaefb | 2736 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
cd000bff DJ |
2737 | void |
2738 | mapping_state (enum mstate state) | |
2739 | { | |
940b5ce0 DJ |
2740 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2741 | ||
cd000bff DJ |
2742 | if (mapstate == state) |
2743 | /* The mapping symbol has already been emitted. | |
2744 | There is nothing else to do. */ | |
2745 | return; | |
49c62a33 NC |
2746 | |
2747 | if (state == MAP_ARM || state == MAP_THUMB) | |
2748 | /* PR gas/12931 | |
2749 | All ARM instructions require 4-byte alignment. | |
2750 | (Almost) all Thumb instructions require 2-byte alignment. | |
2751 | ||
2752 | When emitting instructions into any section, mark the section | |
2753 | appropriately. | |
2754 | ||
2755 | Some Thumb instructions are alignment-sensitive modulo 4 bytes, | |
2756 | but themselves require 2-byte alignment; this applies to some | |
33eaf5de | 2757 | PC- relative forms. However, these cases will involve implicit |
49c62a33 NC |
2758 | literal pool generation or an explicit .align >=2, both of |
2759 | which will cause the section to me marked with sufficient | |
2760 | alignment. Thus, we don't handle those cases here. */ | |
2761 | record_alignment (now_seg, state == MAP_ARM ? 2 : 1); | |
2762 | ||
2763 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
4e9aaefb | 2764 | /* This case will be evaluated later. */ |
cd000bff | 2765 | return; |
cd000bff DJ |
2766 | |
2767 | mapping_state_2 (state, 0); | |
cd000bff DJ |
2768 | } |
2769 | ||
2770 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2771 | allocated. Put the mapping symbol that far back. */ | |
2772 | ||
2773 | static void | |
2774 | mapping_state_2 (enum mstate state, int max_chars) | |
2775 | { | |
940b5ce0 DJ |
2776 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2777 | ||
2778 | if (!SEG_NORMAL (now_seg)) | |
2779 | return; | |
2780 | ||
cd000bff DJ |
2781 | if (mapstate == state) |
2782 | /* The mapping symbol has already been emitted. | |
2783 | There is nothing else to do. */ | |
2784 | return; | |
2785 | ||
4e9aaefb SA |
2786 | if (TRANSITION (MAP_UNDEFINED, MAP_ARM) |
2787 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2788 | { | |
2789 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2790 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2791 | ||
2792 | if (add_symbol) | |
2793 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2794 | } | |
2795 | ||
cd000bff DJ |
2796 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2797 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 | 2798 | } |
4e9aaefb | 2799 | #undef TRANSITION |
c19d1205 | 2800 | #else |
d3106081 NS |
2801 | #define mapping_state(x) ((void)0) |
2802 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2803 | #endif |
2804 | ||
2805 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2806 | ||
4343666d | 2807 | #ifdef OBJ_COFF |
c19d1205 ZW |
2808 | static symbolS * |
2809 | find_real_start (symbolS * symbolP) | |
2810 | { | |
2811 | char * real_start; | |
2812 | const char * name = S_GET_NAME (symbolP); | |
2813 | symbolS * new_target; | |
2814 | ||
2815 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2816 | #define STUB_NAME ".real_start_of" | |
2817 | ||
2818 | if (name == NULL) | |
2819 | abort (); | |
2820 | ||
37f6032b ZW |
2821 | /* The compiler may generate BL instructions to local labels because |
2822 | it needs to perform a branch to a far away location. These labels | |
2823 | do not have a corresponding ".real_start_of" label. We check | |
2824 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2825 | the ".real_start_of" convention for nonlocal branches. */ | |
2826 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2827 | return symbolP; |
2828 | ||
e1fa0163 | 2829 | real_start = concat (STUB_NAME, name, NULL); |
c19d1205 | 2830 | new_target = symbol_find (real_start); |
e1fa0163 | 2831 | free (real_start); |
c19d1205 ZW |
2832 | |
2833 | if (new_target == NULL) | |
2834 | { | |
bd3ba5d1 | 2835 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2836 | new_target = symbolP; |
2837 | } | |
2838 | ||
c19d1205 ZW |
2839 | return new_target; |
2840 | } | |
4343666d | 2841 | #endif |
c19d1205 ZW |
2842 | |
2843 | static void | |
2844 | opcode_select (int width) | |
2845 | { | |
2846 | switch (width) | |
2847 | { | |
2848 | case 16: | |
2849 | if (! thumb_mode) | |
2850 | { | |
e74cfd16 | 2851 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2852 | as_bad (_("selected processor does not support THUMB opcodes")); |
2853 | ||
2854 | thumb_mode = 1; | |
2855 | /* No need to force the alignment, since we will have been | |
2856 | coming from ARM mode, which is word-aligned. */ | |
2857 | record_alignment (now_seg, 1); | |
2858 | } | |
c19d1205 ZW |
2859 | break; |
2860 | ||
2861 | case 32: | |
2862 | if (thumb_mode) | |
2863 | { | |
e74cfd16 | 2864 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2865 | as_bad (_("selected processor does not support ARM opcodes")); |
2866 | ||
2867 | thumb_mode = 0; | |
2868 | ||
2869 | if (!need_pass_2) | |
2870 | frag_align (2, 0, 0); | |
2871 | ||
2872 | record_alignment (now_seg, 1); | |
2873 | } | |
c19d1205 ZW |
2874 | break; |
2875 | ||
2876 | default: | |
2877 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2878 | } | |
2879 | } | |
2880 | ||
2881 | static void | |
2882 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2883 | { | |
2884 | opcode_select (32); | |
2885 | demand_empty_rest_of_line (); | |
2886 | } | |
2887 | ||
2888 | static void | |
2889 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2890 | { | |
2891 | opcode_select (16); | |
2892 | demand_empty_rest_of_line (); | |
2893 | } | |
2894 | ||
2895 | static void | |
2896 | s_code (int unused ATTRIBUTE_UNUSED) | |
2897 | { | |
2898 | int temp; | |
2899 | ||
2900 | temp = get_absolute_expression (); | |
2901 | switch (temp) | |
2902 | { | |
2903 | case 16: | |
2904 | case 32: | |
2905 | opcode_select (temp); | |
2906 | break; | |
2907 | ||
2908 | default: | |
2909 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2910 | } | |
2911 | } | |
2912 | ||
2913 | static void | |
2914 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2915 | { | |
2916 | /* If we are not already in thumb mode go into it, EVEN if | |
2917 | the target processor does not support thumb instructions. | |
2918 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2919 | to compile interworking support functions even if the | |
2920 | target processor should not support interworking. */ | |
2921 | if (! thumb_mode) | |
2922 | { | |
2923 | thumb_mode = 2; | |
2924 | record_alignment (now_seg, 1); | |
2925 | } | |
2926 | ||
2927 | demand_empty_rest_of_line (); | |
2928 | } | |
2929 | ||
2930 | static void | |
2931 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2932 | { | |
2933 | s_thumb (0); | |
2934 | ||
2935 | /* The following label is the name/address of the start of a Thumb function. | |
2936 | We need to know this for the interworking support. */ | |
2937 | label_is_thumb_function_name = TRUE; | |
2938 | } | |
2939 | ||
2940 | /* Perform a .set directive, but also mark the alias as | |
2941 | being a thumb function. */ | |
2942 | ||
2943 | static void | |
2944 | s_thumb_set (int equiv) | |
2945 | { | |
2946 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2947 | We cannot just call that code as we need to get at the symbol that | |
2948 | is created. */ | |
2949 | char * name; | |
2950 | char delim; | |
2951 | char * end_name; | |
2952 | symbolS * symbolP; | |
2953 | ||
2954 | /* Especial apologies for the random logic: | |
2955 | This just grew, and could be parsed much more simply! | |
2956 | Dean - in haste. */ | |
d02603dc | 2957 | delim = get_symbol_name (& name); |
c19d1205 | 2958 | end_name = input_line_pointer; |
d02603dc | 2959 | (void) restore_line_pointer (delim); |
c19d1205 ZW |
2960 | |
2961 | if (*input_line_pointer != ',') | |
2962 | { | |
2963 | *end_name = 0; | |
2964 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2965 | *end_name = delim; |
2966 | ignore_rest_of_line (); | |
2967 | return; | |
2968 | } | |
2969 | ||
2970 | input_line_pointer++; | |
2971 | *end_name = 0; | |
2972 | ||
2973 | if (name[0] == '.' && name[1] == '\0') | |
2974 | { | |
2975 | /* XXX - this should not happen to .thumb_set. */ | |
2976 | abort (); | |
2977 | } | |
2978 | ||
2979 | if ((symbolP = symbol_find (name)) == NULL | |
2980 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2981 | { | |
2982 | #ifndef NO_LISTING | |
2983 | /* When doing symbol listings, play games with dummy fragments living | |
2984 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2985 | for this symbol. */ |
b99bd4ef NC |
2986 | if (listing & LISTING_SYMBOLS) |
2987 | { | |
2988 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 2989 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2990 | |
2991 | memset (dummy_frag, 0, sizeof (fragS)); | |
2992 | dummy_frag->fr_type = rs_fill; | |
2993 | dummy_frag->line = listing_tail; | |
2994 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2995 | dummy_frag->fr_symbol = symbolP; | |
2996 | } | |
2997 | else | |
2998 | #endif | |
2999 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
3000 | ||
3001 | #ifdef OBJ_COFF | |
3002 | /* "set" symbols are local unless otherwise specified. */ | |
3003 | SF_SET_LOCAL (symbolP); | |
3004 | #endif /* OBJ_COFF */ | |
3005 | } /* Make a new symbol. */ | |
3006 | ||
3007 | symbol_table_insert (symbolP); | |
3008 | ||
3009 | * end_name = delim; | |
3010 | ||
3011 | if (equiv | |
3012 | && S_IS_DEFINED (symbolP) | |
3013 | && S_GET_SEGMENT (symbolP) != reg_section) | |
3014 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
3015 | ||
3016 | pseudo_set (symbolP); | |
3017 | ||
3018 | demand_empty_rest_of_line (); | |
3019 | ||
c19d1205 | 3020 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
3021 | |
3022 | THUMB_SET_FUNC (symbolP, 1); | |
3023 | ARM_SET_THUMB (symbolP, 1); | |
3024 | #if defined OBJ_ELF || defined OBJ_COFF | |
3025 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
3026 | #endif | |
3027 | } | |
3028 | ||
c19d1205 | 3029 | /* Directives: Mode selection. */ |
b99bd4ef | 3030 | |
c19d1205 ZW |
3031 | /* .syntax [unified|divided] - choose the new unified syntax |
3032 | (same for Arm and Thumb encoding, modulo slight differences in what | |
3033 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 3034 | static void |
c19d1205 | 3035 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 3036 | { |
c19d1205 ZW |
3037 | char *name, delim; |
3038 | ||
d02603dc | 3039 | delim = get_symbol_name (& name); |
c19d1205 ZW |
3040 | |
3041 | if (!strcasecmp (name, "unified")) | |
3042 | unified_syntax = TRUE; | |
3043 | else if (!strcasecmp (name, "divided")) | |
3044 | unified_syntax = FALSE; | |
3045 | else | |
3046 | { | |
3047 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
3048 | return; | |
3049 | } | |
d02603dc | 3050 | (void) restore_line_pointer (delim); |
b99bd4ef NC |
3051 | demand_empty_rest_of_line (); |
3052 | } | |
3053 | ||
c19d1205 ZW |
3054 | /* Directives: sectioning and alignment. */ |
3055 | ||
c19d1205 ZW |
3056 | static void |
3057 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 3058 | { |
c19d1205 ZW |
3059 | /* We don't support putting frags in the BSS segment, we fake it by |
3060 | marking in_bss, then looking at s_skip for clues. */ | |
3061 | subseg_set (bss_section, 0); | |
3062 | demand_empty_rest_of_line (); | |
cd000bff DJ |
3063 | |
3064 | #ifdef md_elf_section_change_hook | |
3065 | md_elf_section_change_hook (); | |
3066 | #endif | |
c19d1205 | 3067 | } |
b99bd4ef | 3068 | |
c19d1205 ZW |
3069 | static void |
3070 | s_even (int ignore ATTRIBUTE_UNUSED) | |
3071 | { | |
3072 | /* Never make frag if expect extra pass. */ | |
3073 | if (!need_pass_2) | |
3074 | frag_align (1, 0, 0); | |
b99bd4ef | 3075 | |
c19d1205 | 3076 | record_alignment (now_seg, 1); |
b99bd4ef | 3077 | |
c19d1205 | 3078 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3079 | } |
3080 | ||
2e6976a8 DG |
3081 | /* Directives: CodeComposer Studio. */ |
3082 | ||
3083 | /* .ref (for CodeComposer Studio syntax only). */ | |
3084 | static void | |
3085 | s_ccs_ref (int unused ATTRIBUTE_UNUSED) | |
3086 | { | |
3087 | if (codecomposer_syntax) | |
3088 | ignore_rest_of_line (); | |
3089 | else | |
3090 | as_bad (_(".ref pseudo-op only available with -mccs flag.")); | |
3091 | } | |
3092 | ||
3093 | /* If name is not NULL, then it is used for marking the beginning of a | |
2b0f3761 | 3094 | function, whereas if it is NULL then it means the function end. */ |
2e6976a8 DG |
3095 | static void |
3096 | asmfunc_debug (const char * name) | |
3097 | { | |
3098 | static const char * last_name = NULL; | |
3099 | ||
3100 | if (name != NULL) | |
3101 | { | |
3102 | gas_assert (last_name == NULL); | |
3103 | last_name = name; | |
3104 | ||
3105 | if (debug_type == DEBUG_STABS) | |
3106 | stabs_generate_asm_func (name, name); | |
3107 | } | |
3108 | else | |
3109 | { | |
3110 | gas_assert (last_name != NULL); | |
3111 | ||
3112 | if (debug_type == DEBUG_STABS) | |
3113 | stabs_generate_asm_endfunc (last_name, last_name); | |
3114 | ||
3115 | last_name = NULL; | |
3116 | } | |
3117 | } | |
3118 | ||
3119 | static void | |
3120 | s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED) | |
3121 | { | |
3122 | if (codecomposer_syntax) | |
3123 | { | |
3124 | switch (asmfunc_state) | |
3125 | { | |
3126 | case OUTSIDE_ASMFUNC: | |
3127 | asmfunc_state = WAITING_ASMFUNC_NAME; | |
3128 | break; | |
3129 | ||
3130 | case WAITING_ASMFUNC_NAME: | |
3131 | as_bad (_(".asmfunc repeated.")); | |
3132 | break; | |
3133 | ||
3134 | case WAITING_ENDASMFUNC: | |
3135 | as_bad (_(".asmfunc without function.")); | |
3136 | break; | |
3137 | } | |
3138 | demand_empty_rest_of_line (); | |
3139 | } | |
3140 | else | |
3141 | as_bad (_(".asmfunc pseudo-op only available with -mccs flag.")); | |
3142 | } | |
3143 | ||
3144 | static void | |
3145 | s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED) | |
3146 | { | |
3147 | if (codecomposer_syntax) | |
3148 | { | |
3149 | switch (asmfunc_state) | |
3150 | { | |
3151 | case OUTSIDE_ASMFUNC: | |
3152 | as_bad (_(".endasmfunc without a .asmfunc.")); | |
3153 | break; | |
3154 | ||
3155 | case WAITING_ASMFUNC_NAME: | |
3156 | as_bad (_(".endasmfunc without function.")); | |
3157 | break; | |
3158 | ||
3159 | case WAITING_ENDASMFUNC: | |
3160 | asmfunc_state = OUTSIDE_ASMFUNC; | |
3161 | asmfunc_debug (NULL); | |
3162 | break; | |
3163 | } | |
3164 | demand_empty_rest_of_line (); | |
3165 | } | |
3166 | else | |
3167 | as_bad (_(".endasmfunc pseudo-op only available with -mccs flag.")); | |
3168 | } | |
3169 | ||
3170 | static void | |
3171 | s_ccs_def (int name) | |
3172 | { | |
3173 | if (codecomposer_syntax) | |
3174 | s_globl (name); | |
3175 | else | |
3176 | as_bad (_(".def pseudo-op only available with -mccs flag.")); | |
3177 | } | |
3178 | ||
c19d1205 | 3179 | /* Directives: Literal pools. */ |
a737bd4d | 3180 | |
c19d1205 ZW |
3181 | static literal_pool * |
3182 | find_literal_pool (void) | |
a737bd4d | 3183 | { |
c19d1205 | 3184 | literal_pool * pool; |
a737bd4d | 3185 | |
c19d1205 | 3186 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3187 | { |
c19d1205 ZW |
3188 | if (pool->section == now_seg |
3189 | && pool->sub_section == now_subseg) | |
3190 | break; | |
a737bd4d NC |
3191 | } |
3192 | ||
c19d1205 | 3193 | return pool; |
a737bd4d NC |
3194 | } |
3195 | ||
c19d1205 ZW |
3196 | static literal_pool * |
3197 | find_or_make_literal_pool (void) | |
a737bd4d | 3198 | { |
c19d1205 ZW |
3199 | /* Next literal pool ID number. */ |
3200 | static unsigned int latest_pool_num = 1; | |
3201 | literal_pool * pool; | |
a737bd4d | 3202 | |
c19d1205 | 3203 | pool = find_literal_pool (); |
a737bd4d | 3204 | |
c19d1205 | 3205 | if (pool == NULL) |
a737bd4d | 3206 | { |
c19d1205 | 3207 | /* Create a new pool. */ |
325801bd | 3208 | pool = XNEW (literal_pool); |
c19d1205 ZW |
3209 | if (! pool) |
3210 | return NULL; | |
a737bd4d | 3211 | |
c19d1205 ZW |
3212 | pool->next_free_entry = 0; |
3213 | pool->section = now_seg; | |
3214 | pool->sub_section = now_subseg; | |
3215 | pool->next = list_of_pools; | |
3216 | pool->symbol = NULL; | |
8335d6aa | 3217 | pool->alignment = 2; |
c19d1205 ZW |
3218 | |
3219 | /* Add it to the list. */ | |
3220 | list_of_pools = pool; | |
a737bd4d | 3221 | } |
a737bd4d | 3222 | |
c19d1205 ZW |
3223 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3224 | if (pool->symbol == NULL) | |
a737bd4d | 3225 | { |
c19d1205 ZW |
3226 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
3227 | (valueT) 0, &zero_address_frag); | |
3228 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
3229 | } |
3230 | ||
c19d1205 ZW |
3231 | /* Done. */ |
3232 | return pool; | |
a737bd4d NC |
3233 | } |
3234 | ||
c19d1205 | 3235 | /* Add the literal in the global 'inst' |
5f4273c7 | 3236 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3237 | |
3238 | static int | |
8335d6aa | 3239 | add_to_lit_pool (unsigned int nbytes) |
b99bd4ef | 3240 | { |
8335d6aa JW |
3241 | #define PADDING_SLOT 0x1 |
3242 | #define LIT_ENTRY_SIZE_MASK 0xFF | |
c19d1205 | 3243 | literal_pool * pool; |
8335d6aa JW |
3244 | unsigned int entry, pool_size = 0; |
3245 | bfd_boolean padding_slot_p = FALSE; | |
e56c722b | 3246 | unsigned imm1 = 0; |
8335d6aa JW |
3247 | unsigned imm2 = 0; |
3248 | ||
3249 | if (nbytes == 8) | |
3250 | { | |
3251 | imm1 = inst.operands[1].imm; | |
3252 | imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg | |
e2b0ab59 | 3253 | : inst.relocs[0].exp.X_unsigned ? 0 |
2569ceb0 | 3254 | : ((bfd_int64_t) inst.operands[1].imm) >> 32); |
8335d6aa JW |
3255 | if (target_big_endian) |
3256 | { | |
3257 | imm1 = imm2; | |
3258 | imm2 = inst.operands[1].imm; | |
3259 | } | |
3260 | } | |
b99bd4ef | 3261 | |
c19d1205 ZW |
3262 | pool = find_or_make_literal_pool (); |
3263 | ||
3264 | /* Check if this literal value is already in the pool. */ | |
3265 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3266 | { |
8335d6aa JW |
3267 | if (nbytes == 4) |
3268 | { | |
e2b0ab59 AV |
3269 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3270 | && (inst.relocs[0].exp.X_op == O_constant) | |
8335d6aa | 3271 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3272 | == inst.relocs[0].exp.X_add_number) |
8335d6aa JW |
3273 | && (pool->literals[entry].X_md == nbytes) |
3274 | && (pool->literals[entry].X_unsigned | |
e2b0ab59 | 3275 | == inst.relocs[0].exp.X_unsigned)) |
8335d6aa JW |
3276 | break; |
3277 | ||
e2b0ab59 AV |
3278 | if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op) |
3279 | && (inst.relocs[0].exp.X_op == O_symbol) | |
8335d6aa | 3280 | && (pool->literals[entry].X_add_number |
e2b0ab59 | 3281 | == inst.relocs[0].exp.X_add_number) |
8335d6aa | 3282 | && (pool->literals[entry].X_add_symbol |
e2b0ab59 | 3283 | == inst.relocs[0].exp.X_add_symbol) |
8335d6aa | 3284 | && (pool->literals[entry].X_op_symbol |
e2b0ab59 | 3285 | == inst.relocs[0].exp.X_op_symbol) |
8335d6aa JW |
3286 | && (pool->literals[entry].X_md == nbytes)) |
3287 | break; | |
3288 | } | |
3289 | else if ((nbytes == 8) | |
3290 | && !(pool_size & 0x7) | |
3291 | && ((entry + 1) != pool->next_free_entry) | |
3292 | && (pool->literals[entry].X_op == O_constant) | |
19f2f6a9 | 3293 | && (pool->literals[entry].X_add_number == (offsetT) imm1) |
8335d6aa | 3294 | && (pool->literals[entry].X_unsigned |
e2b0ab59 | 3295 | == inst.relocs[0].exp.X_unsigned) |
8335d6aa | 3296 | && (pool->literals[entry + 1].X_op == O_constant) |
19f2f6a9 | 3297 | && (pool->literals[entry + 1].X_add_number == (offsetT) imm2) |
8335d6aa | 3298 | && (pool->literals[entry + 1].X_unsigned |
e2b0ab59 | 3299 | == inst.relocs[0].exp.X_unsigned)) |
c19d1205 ZW |
3300 | break; |
3301 | ||
8335d6aa JW |
3302 | padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT); |
3303 | if (padding_slot_p && (nbytes == 4)) | |
c19d1205 | 3304 | break; |
8335d6aa JW |
3305 | |
3306 | pool_size += 4; | |
b99bd4ef NC |
3307 | } |
3308 | ||
c19d1205 ZW |
3309 | /* Do we need to create a new entry? */ |
3310 | if (entry == pool->next_free_entry) | |
3311 | { | |
3312 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3313 | { | |
3314 | inst.error = _("literal pool overflow"); | |
3315 | return FAIL; | |
3316 | } | |
3317 | ||
8335d6aa JW |
3318 | if (nbytes == 8) |
3319 | { | |
3320 | /* For 8-byte entries, we align to an 8-byte boundary, | |
3321 | and split it into two 4-byte entries, because on 32-bit | |
3322 | host, 8-byte constants are treated as big num, thus | |
3323 | saved in "generic_bignum" which will be overwritten | |
3324 | by later assignments. | |
3325 | ||
3326 | We also need to make sure there is enough space for | |
3327 | the split. | |
3328 | ||
3329 | We also check to make sure the literal operand is a | |
3330 | constant number. */ | |
e2b0ab59 AV |
3331 | if (!(inst.relocs[0].exp.X_op == O_constant |
3332 | || inst.relocs[0].exp.X_op == O_big)) | |
8335d6aa JW |
3333 | { |
3334 | inst.error = _("invalid type for literal pool"); | |
3335 | return FAIL; | |
3336 | } | |
3337 | else if (pool_size & 0x7) | |
3338 | { | |
3339 | if ((entry + 2) >= MAX_LITERAL_POOL_SIZE) | |
3340 | { | |
3341 | inst.error = _("literal pool overflow"); | |
3342 | return FAIL; | |
3343 | } | |
3344 | ||
e2b0ab59 | 3345 | pool->literals[entry] = inst.relocs[0].exp; |
a6684f0d | 3346 | pool->literals[entry].X_op = O_constant; |
8335d6aa JW |
3347 | pool->literals[entry].X_add_number = 0; |
3348 | pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4; | |
3349 | pool->next_free_entry += 1; | |
3350 | pool_size += 4; | |
3351 | } | |
3352 | else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE) | |
3353 | { | |
3354 | inst.error = _("literal pool overflow"); | |
3355 | return FAIL; | |
3356 | } | |
3357 | ||
e2b0ab59 | 3358 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3359 | pool->literals[entry].X_op = O_constant; |
3360 | pool->literals[entry].X_add_number = imm1; | |
e2b0ab59 | 3361 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa | 3362 | pool->literals[entry++].X_md = 4; |
e2b0ab59 | 3363 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3364 | pool->literals[entry].X_op = O_constant; |
3365 | pool->literals[entry].X_add_number = imm2; | |
e2b0ab59 | 3366 | pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned; |
8335d6aa JW |
3367 | pool->literals[entry].X_md = 4; |
3368 | pool->alignment = 3; | |
3369 | pool->next_free_entry += 1; | |
3370 | } | |
3371 | else | |
3372 | { | |
e2b0ab59 | 3373 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3374 | pool->literals[entry].X_md = 4; |
3375 | } | |
3376 | ||
a8040cf2 NC |
3377 | #ifdef OBJ_ELF |
3378 | /* PR ld/12974: Record the location of the first source line to reference | |
3379 | this entry in the literal pool. If it turns out during linking that the | |
3380 | symbol does not exist we will be able to give an accurate line number for | |
3381 | the (first use of the) missing reference. */ | |
3382 | if (debug_type == DEBUG_DWARF2) | |
3383 | dwarf2_where (pool->locs + entry); | |
3384 | #endif | |
c19d1205 ZW |
3385 | pool->next_free_entry += 1; |
3386 | } | |
8335d6aa JW |
3387 | else if (padding_slot_p) |
3388 | { | |
e2b0ab59 | 3389 | pool->literals[entry] = inst.relocs[0].exp; |
8335d6aa JW |
3390 | pool->literals[entry].X_md = nbytes; |
3391 | } | |
b99bd4ef | 3392 | |
e2b0ab59 AV |
3393 | inst.relocs[0].exp.X_op = O_symbol; |
3394 | inst.relocs[0].exp.X_add_number = pool_size; | |
3395 | inst.relocs[0].exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 3396 | |
c19d1205 | 3397 | return SUCCESS; |
b99bd4ef NC |
3398 | } |
3399 | ||
2e6976a8 | 3400 | bfd_boolean |
2e57ce7b | 3401 | tc_start_label_without_colon (void) |
2e6976a8 DG |
3402 | { |
3403 | bfd_boolean ret = TRUE; | |
3404 | ||
3405 | if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME) | |
3406 | { | |
2e57ce7b | 3407 | const char *label = input_line_pointer; |
2e6976a8 DG |
3408 | |
3409 | while (!is_end_of_line[(int) label[-1]]) | |
3410 | --label; | |
3411 | ||
3412 | if (*label == '.') | |
3413 | { | |
3414 | as_bad (_("Invalid label '%s'"), label); | |
3415 | ret = FALSE; | |
3416 | } | |
3417 | ||
3418 | asmfunc_debug (label); | |
3419 | ||
3420 | asmfunc_state = WAITING_ENDASMFUNC; | |
3421 | } | |
3422 | ||
3423 | return ret; | |
3424 | } | |
3425 | ||
c19d1205 | 3426 | /* Can't use symbol_new here, so have to create a symbol and then at |
33eaf5de | 3427 | a later date assign it a value. That's what these functions do. */ |
e16bb312 | 3428 | |
c19d1205 ZW |
3429 | static void |
3430 | symbol_locate (symbolS * symbolP, | |
3431 | const char * name, /* It is copied, the caller can modify. */ | |
3432 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3433 | valueT valu, /* Symbol value. */ | |
3434 | fragS * frag) /* Associated fragment. */ | |
3435 | { | |
e57e6ddc | 3436 | size_t name_length; |
c19d1205 | 3437 | char * preserved_copy_of_name; |
e16bb312 | 3438 | |
c19d1205 ZW |
3439 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3440 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3441 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3442 | |
c19d1205 ZW |
3443 | #ifdef tc_canonicalize_symbol_name |
3444 | preserved_copy_of_name = | |
3445 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3446 | #endif | |
b99bd4ef | 3447 | |
c19d1205 | 3448 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3449 | |
c19d1205 ZW |
3450 | S_SET_SEGMENT (symbolP, segment); |
3451 | S_SET_VALUE (symbolP, valu); | |
3452 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3453 | |
c19d1205 | 3454 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3455 | |
c19d1205 ZW |
3456 | /* Link to end of symbol chain. */ |
3457 | { | |
3458 | extern int symbol_table_frozen; | |
b99bd4ef | 3459 | |
c19d1205 ZW |
3460 | if (symbol_table_frozen) |
3461 | abort (); | |
3462 | } | |
b99bd4ef | 3463 | |
c19d1205 | 3464 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3465 | |
c19d1205 | 3466 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3467 | |
c19d1205 ZW |
3468 | #ifdef tc_symbol_new_hook |
3469 | tc_symbol_new_hook (symbolP); | |
3470 | #endif | |
3471 | ||
3472 | #ifdef DEBUG_SYMS | |
3473 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3474 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3475 | } |
3476 | ||
c19d1205 ZW |
3477 | static void |
3478 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3479 | { |
c19d1205 ZW |
3480 | unsigned int entry; |
3481 | literal_pool * pool; | |
3482 | char sym_name[20]; | |
b99bd4ef | 3483 | |
c19d1205 ZW |
3484 | pool = find_literal_pool (); |
3485 | if (pool == NULL | |
3486 | || pool->symbol == NULL | |
3487 | || pool->next_free_entry == 0) | |
3488 | return; | |
b99bd4ef | 3489 | |
c19d1205 ZW |
3490 | /* Align pool as you have word accesses. |
3491 | Only make a frag if we have to. */ | |
3492 | if (!need_pass_2) | |
8335d6aa | 3493 | frag_align (pool->alignment, 0, 0); |
b99bd4ef | 3494 | |
c19d1205 | 3495 | record_alignment (now_seg, 2); |
b99bd4ef | 3496 | |
aaca88ef | 3497 | #ifdef OBJ_ELF |
47fc6e36 WN |
3498 | seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA; |
3499 | make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now); | |
aaca88ef | 3500 | #endif |
c19d1205 | 3501 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3502 | |
c19d1205 ZW |
3503 | symbol_locate (pool->symbol, sym_name, now_seg, |
3504 | (valueT) frag_now_fix (), frag_now); | |
3505 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3506 | |
c19d1205 | 3507 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3508 | |
c19d1205 ZW |
3509 | #if defined OBJ_COFF || defined OBJ_ELF |
3510 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3511 | #endif | |
6c43fab6 | 3512 | |
c19d1205 | 3513 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
3514 | { |
3515 | #ifdef OBJ_ELF | |
3516 | if (debug_type == DEBUG_DWARF2) | |
3517 | dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry); | |
3518 | #endif | |
3519 | /* First output the expression in the instruction to the pool. */ | |
8335d6aa JW |
3520 | emit_expr (&(pool->literals[entry]), |
3521 | pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK); | |
a8040cf2 | 3522 | } |
b99bd4ef | 3523 | |
c19d1205 ZW |
3524 | /* Mark the pool as empty. */ |
3525 | pool->next_free_entry = 0; | |
3526 | pool->symbol = NULL; | |
b99bd4ef NC |
3527 | } |
3528 | ||
c19d1205 ZW |
3529 | #ifdef OBJ_ELF |
3530 | /* Forward declarations for functions below, in the MD interface | |
3531 | section. */ | |
3532 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3533 | static valueT create_unwind_entry (int); | |
3534 | static void start_unwind_section (const segT, int); | |
3535 | static void add_unwind_opcode (valueT, int); | |
3536 | static void flush_pending_unwind (void); | |
b99bd4ef | 3537 | |
c19d1205 | 3538 | /* Directives: Data. */ |
b99bd4ef | 3539 | |
c19d1205 ZW |
3540 | static void |
3541 | s_arm_elf_cons (int nbytes) | |
3542 | { | |
3543 | expressionS exp; | |
b99bd4ef | 3544 | |
c19d1205 ZW |
3545 | #ifdef md_flush_pending_output |
3546 | md_flush_pending_output (); | |
3547 | #endif | |
b99bd4ef | 3548 | |
c19d1205 | 3549 | if (is_it_end_of_statement ()) |
b99bd4ef | 3550 | { |
c19d1205 ZW |
3551 | demand_empty_rest_of_line (); |
3552 | return; | |
b99bd4ef NC |
3553 | } |
3554 | ||
c19d1205 ZW |
3555 | #ifdef md_cons_align |
3556 | md_cons_align (nbytes); | |
3557 | #endif | |
b99bd4ef | 3558 | |
c19d1205 ZW |
3559 | mapping_state (MAP_DATA); |
3560 | do | |
b99bd4ef | 3561 | { |
c19d1205 ZW |
3562 | int reloc; |
3563 | char *base = input_line_pointer; | |
b99bd4ef | 3564 | |
c19d1205 | 3565 | expression (& exp); |
b99bd4ef | 3566 | |
c19d1205 ZW |
3567 | if (exp.X_op != O_symbol) |
3568 | emit_expr (&exp, (unsigned int) nbytes); | |
3569 | else | |
3570 | { | |
3571 | char *before_reloc = input_line_pointer; | |
3572 | reloc = parse_reloc (&input_line_pointer); | |
3573 | if (reloc == -1) | |
3574 | { | |
3575 | as_bad (_("unrecognized relocation suffix")); | |
3576 | ignore_rest_of_line (); | |
3577 | return; | |
3578 | } | |
3579 | else if (reloc == BFD_RELOC_UNUSED) | |
3580 | emit_expr (&exp, (unsigned int) nbytes); | |
3581 | else | |
3582 | { | |
21d799b5 | 3583 | reloc_howto_type *howto = (reloc_howto_type *) |
477330fc RM |
3584 | bfd_reloc_type_lookup (stdoutput, |
3585 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3586 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3587 | |
2fc8bdac ZW |
3588 | if (reloc == BFD_RELOC_ARM_PLT32) |
3589 | { | |
3590 | as_bad (_("(plt) is only valid on branch targets")); | |
3591 | reloc = BFD_RELOC_UNUSED; | |
3592 | size = 0; | |
3593 | } | |
3594 | ||
c19d1205 | 3595 | if (size > nbytes) |
992a06ee AM |
3596 | as_bad (ngettext ("%s relocations do not fit in %d byte", |
3597 | "%s relocations do not fit in %d bytes", | |
3598 | nbytes), | |
c19d1205 ZW |
3599 | howto->name, nbytes); |
3600 | else | |
3601 | { | |
3602 | /* We've parsed an expression stopping at O_symbol. | |
3603 | But there may be more expression left now that we | |
3604 | have parsed the relocation marker. Parse it again. | |
3605 | XXX Surely there is a cleaner way to do this. */ | |
3606 | char *p = input_line_pointer; | |
3607 | int offset; | |
325801bd | 3608 | char *save_buf = XNEWVEC (char, input_line_pointer - base); |
e1fa0163 | 3609 | |
c19d1205 ZW |
3610 | memcpy (save_buf, base, input_line_pointer - base); |
3611 | memmove (base + (input_line_pointer - before_reloc), | |
3612 | base, before_reloc - base); | |
3613 | ||
3614 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3615 | expression (&exp); | |
3616 | memcpy (base, save_buf, p - base); | |
3617 | ||
3618 | offset = nbytes - size; | |
4b1a927e AM |
3619 | p = frag_more (nbytes); |
3620 | memset (p, 0, nbytes); | |
c19d1205 | 3621 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, |
21d799b5 | 3622 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
e1fa0163 | 3623 | free (save_buf); |
c19d1205 ZW |
3624 | } |
3625 | } | |
3626 | } | |
b99bd4ef | 3627 | } |
c19d1205 | 3628 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3629 | |
c19d1205 ZW |
3630 | /* Put terminator back into stream. */ |
3631 | input_line_pointer --; | |
3632 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3633 | } |
3634 | ||
c921be7d NC |
3635 | /* Emit an expression containing a 32-bit thumb instruction. |
3636 | Implementation based on put_thumb32_insn. */ | |
3637 | ||
3638 | static void | |
3639 | emit_thumb32_expr (expressionS * exp) | |
3640 | { | |
3641 | expressionS exp_high = *exp; | |
3642 | ||
3643 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3644 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3645 | exp->X_add_number &= 0xffff; | |
3646 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3647 | } | |
3648 | ||
3649 | /* Guess the instruction size based on the opcode. */ | |
3650 | ||
3651 | static int | |
3652 | thumb_insn_size (int opcode) | |
3653 | { | |
3654 | if ((unsigned int) opcode < 0xe800u) | |
3655 | return 2; | |
3656 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3657 | return 4; | |
3658 | else | |
3659 | return 0; | |
3660 | } | |
3661 | ||
3662 | static bfd_boolean | |
3663 | emit_insn (expressionS *exp, int nbytes) | |
3664 | { | |
3665 | int size = 0; | |
3666 | ||
3667 | if (exp->X_op == O_constant) | |
3668 | { | |
3669 | size = nbytes; | |
3670 | ||
3671 | if (size == 0) | |
3672 | size = thumb_insn_size (exp->X_add_number); | |
3673 | ||
3674 | if (size != 0) | |
3675 | { | |
3676 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3677 | { | |
3678 | as_bad (_(".inst.n operand too big. "\ | |
3679 | "Use .inst.w instead")); | |
3680 | size = 0; | |
3681 | } | |
3682 | else | |
3683 | { | |
3684 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3685 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3686 | else | |
3687 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3688 | ||
3689 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3690 | emit_thumb32_expr (exp); | |
3691 | else | |
3692 | emit_expr (exp, (unsigned int) size); | |
3693 | ||
3694 | it_fsm_post_encode (); | |
3695 | } | |
3696 | } | |
3697 | else | |
3698 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3699 | "Use .inst.n/.inst.w instead")); | |
3700 | } | |
3701 | else | |
3702 | as_bad (_("constant expression required")); | |
3703 | ||
3704 | return (size != 0); | |
3705 | } | |
3706 | ||
3707 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3708 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3709 | ||
3710 | static void | |
3711 | s_arm_elf_inst (int nbytes) | |
3712 | { | |
3713 | if (is_it_end_of_statement ()) | |
3714 | { | |
3715 | demand_empty_rest_of_line (); | |
3716 | return; | |
3717 | } | |
3718 | ||
3719 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3720 | but will ensure not to be in DATA state. */ | |
3721 | ||
3722 | if (thumb_mode) | |
3723 | mapping_state (MAP_THUMB); | |
3724 | else | |
3725 | { | |
3726 | if (nbytes != 0) | |
3727 | { | |
3728 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3729 | ignore_rest_of_line (); | |
3730 | return; | |
3731 | } | |
3732 | ||
3733 | nbytes = 4; | |
3734 | ||
3735 | mapping_state (MAP_ARM); | |
3736 | } | |
3737 | ||
3738 | do | |
3739 | { | |
3740 | expressionS exp; | |
3741 | ||
3742 | expression (& exp); | |
3743 | ||
3744 | if (! emit_insn (& exp, nbytes)) | |
3745 | { | |
3746 | ignore_rest_of_line (); | |
3747 | return; | |
3748 | } | |
3749 | } | |
3750 | while (*input_line_pointer++ == ','); | |
3751 | ||
3752 | /* Put terminator back into stream. */ | |
3753 | input_line_pointer --; | |
3754 | demand_empty_rest_of_line (); | |
3755 | } | |
b99bd4ef | 3756 | |
c19d1205 | 3757 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3758 | |
c19d1205 ZW |
3759 | static void |
3760 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3761 | { | |
3762 | expressionS exp; | |
3763 | char *p; | |
3764 | valueT highbit; | |
b99bd4ef | 3765 | |
c19d1205 ZW |
3766 | highbit = 0; |
3767 | if (*input_line_pointer == '1') | |
3768 | highbit = 0x80000000; | |
3769 | else if (*input_line_pointer != '0') | |
3770 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3771 | |
c19d1205 ZW |
3772 | input_line_pointer++; |
3773 | if (*input_line_pointer != ',') | |
3774 | as_bad (_("missing comma")); | |
3775 | input_line_pointer++; | |
b99bd4ef | 3776 | |
c19d1205 ZW |
3777 | #ifdef md_flush_pending_output |
3778 | md_flush_pending_output (); | |
3779 | #endif | |
b99bd4ef | 3780 | |
c19d1205 ZW |
3781 | #ifdef md_cons_align |
3782 | md_cons_align (4); | |
3783 | #endif | |
b99bd4ef | 3784 | |
c19d1205 | 3785 | mapping_state (MAP_DATA); |
b99bd4ef | 3786 | |
c19d1205 | 3787 | expression (&exp); |
b99bd4ef | 3788 | |
c19d1205 ZW |
3789 | p = frag_more (4); |
3790 | md_number_to_chars (p, highbit, 4); | |
3791 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3792 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3793 | |
c19d1205 | 3794 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3795 | } |
3796 | ||
c19d1205 | 3797 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3798 | |
c19d1205 | 3799 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3800 | |
c19d1205 ZW |
3801 | static void |
3802 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3803 | { | |
3804 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3805 | if (unwind.proc_start) |
3806 | { | |
c921be7d | 3807 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3808 | return; |
3809 | } | |
3810 | ||
c19d1205 ZW |
3811 | /* Mark the start of the function. */ |
3812 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3813 | |
c19d1205 ZW |
3814 | /* Reset the rest of the unwind info. */ |
3815 | unwind.opcode_count = 0; | |
3816 | unwind.table_entry = NULL; | |
3817 | unwind.personality_routine = NULL; | |
3818 | unwind.personality_index = -1; | |
3819 | unwind.frame_size = 0; | |
3820 | unwind.fp_offset = 0; | |
fdfde340 | 3821 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3822 | unwind.fp_used = 0; |
3823 | unwind.sp_restored = 0; | |
3824 | } | |
b99bd4ef | 3825 | |
b99bd4ef | 3826 | |
c19d1205 ZW |
3827 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3828 | for the function. */ | |
b99bd4ef | 3829 | |
c19d1205 ZW |
3830 | static void |
3831 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3832 | { | |
3833 | demand_empty_rest_of_line (); | |
921e5f0a | 3834 | if (!unwind.proc_start) |
c921be7d | 3835 | as_bad (MISSING_FNSTART); |
921e5f0a | 3836 | |
c19d1205 | 3837 | if (unwind.table_entry) |
6decc662 | 3838 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3839 | |
c19d1205 ZW |
3840 | create_unwind_entry (1); |
3841 | } | |
a737bd4d | 3842 | |
c19d1205 | 3843 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3844 | |
c19d1205 ZW |
3845 | static void |
3846 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3847 | { | |
3848 | long where; | |
3849 | char *ptr; | |
3850 | valueT val; | |
940b5ce0 | 3851 | unsigned int marked_pr_dependency; |
f02232aa | 3852 | |
c19d1205 | 3853 | demand_empty_rest_of_line (); |
f02232aa | 3854 | |
921e5f0a PB |
3855 | if (!unwind.proc_start) |
3856 | { | |
c921be7d | 3857 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3858 | return; |
3859 | } | |
3860 | ||
c19d1205 ZW |
3861 | /* Add eh table entry. */ |
3862 | if (unwind.table_entry == NULL) | |
3863 | val = create_unwind_entry (0); | |
3864 | else | |
3865 | val = 0; | |
f02232aa | 3866 | |
c19d1205 ZW |
3867 | /* Add index table entry. This is two words. */ |
3868 | start_unwind_section (unwind.saved_seg, 1); | |
3869 | frag_align (2, 0, 0); | |
3870 | record_alignment (now_seg, 2); | |
b99bd4ef | 3871 | |
c19d1205 | 3872 | ptr = frag_more (8); |
5011093d | 3873 | memset (ptr, 0, 8); |
c19d1205 | 3874 | where = frag_now_fix () - 8; |
f02232aa | 3875 | |
c19d1205 ZW |
3876 | /* Self relative offset of the function start. */ |
3877 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3878 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3879 | |
c19d1205 ZW |
3880 | /* Indicate dependency on EHABI-defined personality routines to the |
3881 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3882 | marked_pr_dependency |
3883 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3884 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3885 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3886 | { | |
5f4273c7 NC |
3887 | static const char *const name[] = |
3888 | { | |
3889 | "__aeabi_unwind_cpp_pr0", | |
3890 | "__aeabi_unwind_cpp_pr1", | |
3891 | "__aeabi_unwind_cpp_pr2" | |
3892 | }; | |
c19d1205 ZW |
3893 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3894 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3895 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3896 | |= 1 << unwind.personality_index; |
c19d1205 | 3897 | } |
f02232aa | 3898 | |
c19d1205 ZW |
3899 | if (val) |
3900 | /* Inline exception table entry. */ | |
3901 | md_number_to_chars (ptr + 4, val, 4); | |
3902 | else | |
3903 | /* Self relative offset of the table entry. */ | |
3904 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3905 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3906 | |
c19d1205 ZW |
3907 | /* Restore the original section. */ |
3908 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3909 | |
3910 | unwind.proc_start = NULL; | |
c19d1205 | 3911 | } |
f02232aa | 3912 | |
f02232aa | 3913 | |
c19d1205 | 3914 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3915 | |
c19d1205 ZW |
3916 | static void |
3917 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3918 | { | |
3919 | demand_empty_rest_of_line (); | |
921e5f0a | 3920 | if (!unwind.proc_start) |
c921be7d | 3921 | as_bad (MISSING_FNSTART); |
921e5f0a | 3922 | |
c19d1205 ZW |
3923 | if (unwind.personality_routine || unwind.personality_index != -1) |
3924 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3925 | |
c19d1205 ZW |
3926 | unwind.personality_index = -2; |
3927 | } | |
b99bd4ef | 3928 | |
b99bd4ef | 3929 | |
c19d1205 | 3930 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3931 | |
c19d1205 ZW |
3932 | static void |
3933 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3934 | { | |
3935 | expressionS exp; | |
b99bd4ef | 3936 | |
921e5f0a | 3937 | if (!unwind.proc_start) |
c921be7d | 3938 | as_bad (MISSING_FNSTART); |
921e5f0a | 3939 | |
c19d1205 ZW |
3940 | if (unwind.personality_routine || unwind.personality_index != -1) |
3941 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3942 | |
c19d1205 | 3943 | expression (&exp); |
b99bd4ef | 3944 | |
c19d1205 ZW |
3945 | if (exp.X_op != O_constant |
3946 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3947 | { |
c19d1205 ZW |
3948 | as_bad (_("bad personality routine number")); |
3949 | ignore_rest_of_line (); | |
3950 | return; | |
b99bd4ef NC |
3951 | } |
3952 | ||
c19d1205 | 3953 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3954 | |
c19d1205 ZW |
3955 | demand_empty_rest_of_line (); |
3956 | } | |
e16bb312 | 3957 | |
e16bb312 | 3958 | |
c19d1205 | 3959 | /* Parse a personality directive. */ |
e16bb312 | 3960 | |
c19d1205 ZW |
3961 | static void |
3962 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3963 | { | |
3964 | char *name, *p, c; | |
a737bd4d | 3965 | |
921e5f0a | 3966 | if (!unwind.proc_start) |
c921be7d | 3967 | as_bad (MISSING_FNSTART); |
921e5f0a | 3968 | |
c19d1205 ZW |
3969 | if (unwind.personality_routine || unwind.personality_index != -1) |
3970 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3971 | |
d02603dc | 3972 | c = get_symbol_name (& name); |
c19d1205 | 3973 | p = input_line_pointer; |
d02603dc NC |
3974 | if (c == '"') |
3975 | ++ input_line_pointer; | |
c19d1205 ZW |
3976 | unwind.personality_routine = symbol_find_or_make (name); |
3977 | *p = c; | |
3978 | demand_empty_rest_of_line (); | |
3979 | } | |
e16bb312 | 3980 | |
e16bb312 | 3981 | |
c19d1205 | 3982 | /* Parse a directive saving core registers. */ |
e16bb312 | 3983 | |
c19d1205 ZW |
3984 | static void |
3985 | s_arm_unwind_save_core (void) | |
e16bb312 | 3986 | { |
c19d1205 ZW |
3987 | valueT op; |
3988 | long range; | |
3989 | int n; | |
e16bb312 | 3990 | |
c19d1205 ZW |
3991 | range = parse_reg_list (&input_line_pointer); |
3992 | if (range == FAIL) | |
e16bb312 | 3993 | { |
c19d1205 ZW |
3994 | as_bad (_("expected register list")); |
3995 | ignore_rest_of_line (); | |
3996 | return; | |
3997 | } | |
e16bb312 | 3998 | |
c19d1205 | 3999 | demand_empty_rest_of_line (); |
e16bb312 | 4000 | |
c19d1205 ZW |
4001 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
4002 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
4003 | ip because it is clobbered by calls. */ | |
4004 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
4005 | && (range & 0x3000) == 0x1000) | |
4006 | { | |
4007 | unwind.opcode_count--; | |
4008 | unwind.sp_restored = 0; | |
4009 | range = (range | 0x2000) & ~0x1000; | |
4010 | unwind.pending_offset = 0; | |
4011 | } | |
e16bb312 | 4012 | |
01ae4198 DJ |
4013 | /* Pop r4-r15. */ |
4014 | if (range & 0xfff0) | |
c19d1205 | 4015 | { |
01ae4198 DJ |
4016 | /* See if we can use the short opcodes. These pop a block of up to 8 |
4017 | registers starting with r4, plus maybe r14. */ | |
4018 | for (n = 0; n < 8; n++) | |
4019 | { | |
4020 | /* Break at the first non-saved register. */ | |
4021 | if ((range & (1 << (n + 4))) == 0) | |
4022 | break; | |
4023 | } | |
4024 | /* See if there are any other bits set. */ | |
4025 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
4026 | { | |
4027 | /* Use the long form. */ | |
4028 | op = 0x8000 | ((range >> 4) & 0xfff); | |
4029 | add_unwind_opcode (op, 2); | |
4030 | } | |
0dd132b6 | 4031 | else |
01ae4198 DJ |
4032 | { |
4033 | /* Use the short form. */ | |
4034 | if (range & 0x4000) | |
4035 | op = 0xa8; /* Pop r14. */ | |
4036 | else | |
4037 | op = 0xa0; /* Do not pop r14. */ | |
4038 | op |= (n - 1); | |
4039 | add_unwind_opcode (op, 1); | |
4040 | } | |
c19d1205 | 4041 | } |
0dd132b6 | 4042 | |
c19d1205 ZW |
4043 | /* Pop r0-r3. */ |
4044 | if (range & 0xf) | |
4045 | { | |
4046 | op = 0xb100 | (range & 0xf); | |
4047 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
4048 | } |
4049 | ||
c19d1205 ZW |
4050 | /* Record the number of bytes pushed. */ |
4051 | for (n = 0; n < 16; n++) | |
4052 | { | |
4053 | if (range & (1 << n)) | |
4054 | unwind.frame_size += 4; | |
4055 | } | |
0dd132b6 NC |
4056 | } |
4057 | ||
c19d1205 ZW |
4058 | |
4059 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
4060 | |
4061 | static void | |
c19d1205 | 4062 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 4063 | { |
c19d1205 ZW |
4064 | expressionS exp; |
4065 | int num_regs; | |
4066 | valueT op; | |
b99bd4ef | 4067 | |
c19d1205 ZW |
4068 | /* Get Number of registers to transfer. */ |
4069 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4070 | expression (&exp); | |
4071 | else | |
4072 | exp.X_op = O_illegal; | |
b99bd4ef | 4073 | |
c19d1205 | 4074 | if (exp.X_op != O_constant) |
b99bd4ef | 4075 | { |
c19d1205 ZW |
4076 | as_bad (_("expected , <constant>")); |
4077 | ignore_rest_of_line (); | |
b99bd4ef NC |
4078 | return; |
4079 | } | |
4080 | ||
c19d1205 ZW |
4081 | num_regs = exp.X_add_number; |
4082 | ||
4083 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 4084 | { |
c19d1205 ZW |
4085 | as_bad (_("number of registers must be in the range [1:4]")); |
4086 | ignore_rest_of_line (); | |
b99bd4ef NC |
4087 | return; |
4088 | } | |
4089 | ||
c19d1205 | 4090 | demand_empty_rest_of_line (); |
b99bd4ef | 4091 | |
c19d1205 ZW |
4092 | if (reg == 4) |
4093 | { | |
4094 | /* Short form. */ | |
4095 | op = 0xb4 | (num_regs - 1); | |
4096 | add_unwind_opcode (op, 1); | |
4097 | } | |
b99bd4ef NC |
4098 | else |
4099 | { | |
c19d1205 ZW |
4100 | /* Long form. */ |
4101 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
4102 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4103 | } |
c19d1205 | 4104 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
4105 | } |
4106 | ||
c19d1205 | 4107 | |
fa073d69 MS |
4108 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
4109 | ||
4110 | static void | |
4111 | s_arm_unwind_save_vfp_armv6 (void) | |
4112 | { | |
4113 | int count; | |
4114 | unsigned int start; | |
4115 | valueT op; | |
4116 | int num_vfpv3_regs = 0; | |
4117 | int num_regs_below_16; | |
4118 | ||
4119 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
4120 | if (count == FAIL) | |
4121 | { | |
4122 | as_bad (_("expected register list")); | |
4123 | ignore_rest_of_line (); | |
4124 | return; | |
4125 | } | |
4126 | ||
4127 | demand_empty_rest_of_line (); | |
4128 | ||
4129 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
4130 | than FSTMX/FLDMX-style ones). */ | |
4131 | ||
4132 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
4133 | if (start >= 16) | |
4134 | num_vfpv3_regs = count; | |
4135 | else if (start + count > 16) | |
4136 | num_vfpv3_regs = start + count - 16; | |
4137 | ||
4138 | if (num_vfpv3_regs > 0) | |
4139 | { | |
4140 | int start_offset = start > 16 ? start - 16 : 0; | |
4141 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
4142 | add_unwind_opcode (op, 2); | |
4143 | } | |
4144 | ||
4145 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
4146 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 4147 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
4148 | if (num_regs_below_16 > 0) |
4149 | { | |
4150 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
4151 | add_unwind_opcode (op, 2); | |
4152 | } | |
4153 | ||
4154 | unwind.frame_size += count * 8; | |
4155 | } | |
4156 | ||
4157 | ||
4158 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
4159 | |
4160 | static void | |
c19d1205 | 4161 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 4162 | { |
c19d1205 | 4163 | int count; |
ca3f61f7 | 4164 | unsigned int reg; |
c19d1205 | 4165 | valueT op; |
b99bd4ef | 4166 | |
5287ad62 | 4167 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 4168 | if (count == FAIL) |
b99bd4ef | 4169 | { |
c19d1205 ZW |
4170 | as_bad (_("expected register list")); |
4171 | ignore_rest_of_line (); | |
b99bd4ef NC |
4172 | return; |
4173 | } | |
4174 | ||
c19d1205 | 4175 | demand_empty_rest_of_line (); |
b99bd4ef | 4176 | |
c19d1205 | 4177 | if (reg == 8) |
b99bd4ef | 4178 | { |
c19d1205 ZW |
4179 | /* Short form. */ |
4180 | op = 0xb8 | (count - 1); | |
4181 | add_unwind_opcode (op, 1); | |
b99bd4ef | 4182 | } |
c19d1205 | 4183 | else |
b99bd4ef | 4184 | { |
c19d1205 ZW |
4185 | /* Long form. */ |
4186 | op = 0xb300 | (reg << 4) | (count - 1); | |
4187 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4188 | } |
c19d1205 ZW |
4189 | unwind.frame_size += count * 8 + 4; |
4190 | } | |
b99bd4ef | 4191 | |
b99bd4ef | 4192 | |
c19d1205 ZW |
4193 | /* Parse a directive saving iWMMXt data registers. */ |
4194 | ||
4195 | static void | |
4196 | s_arm_unwind_save_mmxwr (void) | |
4197 | { | |
4198 | int reg; | |
4199 | int hi_reg; | |
4200 | int i; | |
4201 | unsigned mask = 0; | |
4202 | valueT op; | |
b99bd4ef | 4203 | |
c19d1205 ZW |
4204 | if (*input_line_pointer == '{') |
4205 | input_line_pointer++; | |
b99bd4ef | 4206 | |
c19d1205 | 4207 | do |
b99bd4ef | 4208 | { |
dcbf9037 | 4209 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 4210 | |
c19d1205 | 4211 | if (reg == FAIL) |
b99bd4ef | 4212 | { |
9b7132d3 | 4213 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 4214 | goto error; |
b99bd4ef NC |
4215 | } |
4216 | ||
c19d1205 ZW |
4217 | if (mask >> reg) |
4218 | as_tsktsk (_("register list not in ascending order")); | |
4219 | mask |= 1 << reg; | |
b99bd4ef | 4220 | |
c19d1205 ZW |
4221 | if (*input_line_pointer == '-') |
4222 | { | |
4223 | input_line_pointer++; | |
dcbf9037 | 4224 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
4225 | if (hi_reg == FAIL) |
4226 | { | |
9b7132d3 | 4227 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
4228 | goto error; |
4229 | } | |
4230 | else if (reg >= hi_reg) | |
4231 | { | |
4232 | as_bad (_("bad register range")); | |
4233 | goto error; | |
4234 | } | |
4235 | for (; reg < hi_reg; reg++) | |
4236 | mask |= 1 << reg; | |
4237 | } | |
4238 | } | |
4239 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 4240 | |
d996d970 | 4241 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4242 | |
c19d1205 | 4243 | demand_empty_rest_of_line (); |
b99bd4ef | 4244 | |
708587a4 | 4245 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4246 | the list. */ |
4247 | flush_pending_unwind (); | |
b99bd4ef | 4248 | |
c19d1205 | 4249 | for (i = 0; i < 16; i++) |
b99bd4ef | 4250 | { |
c19d1205 ZW |
4251 | if (mask & (1 << i)) |
4252 | unwind.frame_size += 8; | |
b99bd4ef NC |
4253 | } |
4254 | ||
c19d1205 ZW |
4255 | /* Attempt to combine with a previous opcode. We do this because gcc |
4256 | likes to output separate unwind directives for a single block of | |
4257 | registers. */ | |
4258 | if (unwind.opcode_count > 0) | |
b99bd4ef | 4259 | { |
c19d1205 ZW |
4260 | i = unwind.opcodes[unwind.opcode_count - 1]; |
4261 | if ((i & 0xf8) == 0xc0) | |
4262 | { | |
4263 | i &= 7; | |
4264 | /* Only merge if the blocks are contiguous. */ | |
4265 | if (i < 6) | |
4266 | { | |
4267 | if ((mask & 0xfe00) == (1 << 9)) | |
4268 | { | |
4269 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
4270 | unwind.opcode_count--; | |
4271 | } | |
4272 | } | |
4273 | else if (i == 6 && unwind.opcode_count >= 2) | |
4274 | { | |
4275 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
4276 | reg = i >> 4; | |
4277 | i &= 0xf; | |
b99bd4ef | 4278 | |
c19d1205 ZW |
4279 | op = 0xffff << (reg - 1); |
4280 | if (reg > 0 | |
87a1fd79 | 4281 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
4282 | { |
4283 | op = (1 << (reg + i + 1)) - 1; | |
4284 | op &= ~((1 << reg) - 1); | |
4285 | mask |= op; | |
4286 | unwind.opcode_count -= 2; | |
4287 | } | |
4288 | } | |
4289 | } | |
b99bd4ef NC |
4290 | } |
4291 | ||
c19d1205 ZW |
4292 | hi_reg = 15; |
4293 | /* We want to generate opcodes in the order the registers have been | |
4294 | saved, ie. descending order. */ | |
4295 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 4296 | { |
c19d1205 ZW |
4297 | /* Save registers in blocks. */ |
4298 | if (reg < 0 | |
4299 | || !(mask & (1 << reg))) | |
4300 | { | |
4301 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 4302 | preceding block. */ |
c19d1205 ZW |
4303 | if (reg != hi_reg) |
4304 | { | |
4305 | if (reg == 9) | |
4306 | { | |
4307 | /* Short form. */ | |
4308 | op = 0xc0 | (hi_reg - 10); | |
4309 | add_unwind_opcode (op, 1); | |
4310 | } | |
4311 | else | |
4312 | { | |
4313 | /* Long form. */ | |
4314 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
4315 | add_unwind_opcode (op, 2); | |
4316 | } | |
4317 | } | |
4318 | hi_reg = reg - 1; | |
4319 | } | |
b99bd4ef NC |
4320 | } |
4321 | ||
c19d1205 ZW |
4322 | return; |
4323 | error: | |
4324 | ignore_rest_of_line (); | |
b99bd4ef NC |
4325 | } |
4326 | ||
4327 | static void | |
c19d1205 | 4328 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4329 | { |
c19d1205 ZW |
4330 | int reg; |
4331 | int hi_reg; | |
4332 | unsigned mask = 0; | |
4333 | valueT op; | |
b99bd4ef | 4334 | |
c19d1205 ZW |
4335 | if (*input_line_pointer == '{') |
4336 | input_line_pointer++; | |
b99bd4ef | 4337 | |
477330fc RM |
4338 | skip_whitespace (input_line_pointer); |
4339 | ||
c19d1205 | 4340 | do |
b99bd4ef | 4341 | { |
dcbf9037 | 4342 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4343 | |
c19d1205 ZW |
4344 | if (reg == FAIL) |
4345 | { | |
9b7132d3 | 4346 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4347 | goto error; |
4348 | } | |
b99bd4ef | 4349 | |
c19d1205 ZW |
4350 | reg -= 8; |
4351 | if (mask >> reg) | |
4352 | as_tsktsk (_("register list not in ascending order")); | |
4353 | mask |= 1 << reg; | |
b99bd4ef | 4354 | |
c19d1205 ZW |
4355 | if (*input_line_pointer == '-') |
4356 | { | |
4357 | input_line_pointer++; | |
dcbf9037 | 4358 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4359 | if (hi_reg == FAIL) |
4360 | { | |
9b7132d3 | 4361 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4362 | goto error; |
4363 | } | |
4364 | else if (reg >= hi_reg) | |
4365 | { | |
4366 | as_bad (_("bad register range")); | |
4367 | goto error; | |
4368 | } | |
4369 | for (; reg < hi_reg; reg++) | |
4370 | mask |= 1 << reg; | |
4371 | } | |
b99bd4ef | 4372 | } |
c19d1205 | 4373 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4374 | |
d996d970 | 4375 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4376 | |
c19d1205 ZW |
4377 | demand_empty_rest_of_line (); |
4378 | ||
708587a4 | 4379 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4380 | the list. */ |
4381 | flush_pending_unwind (); | |
b99bd4ef | 4382 | |
c19d1205 | 4383 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4384 | { |
c19d1205 ZW |
4385 | if (mask & (1 << reg)) |
4386 | unwind.frame_size += 4; | |
b99bd4ef | 4387 | } |
c19d1205 ZW |
4388 | op = 0xc700 | mask; |
4389 | add_unwind_opcode (op, 2); | |
4390 | return; | |
4391 | error: | |
4392 | ignore_rest_of_line (); | |
b99bd4ef NC |
4393 | } |
4394 | ||
c19d1205 | 4395 | |
fa073d69 MS |
4396 | /* Parse an unwind_save directive. |
4397 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4398 | |
b99bd4ef | 4399 | static void |
fa073d69 | 4400 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4401 | { |
c19d1205 ZW |
4402 | char *peek; |
4403 | struct reg_entry *reg; | |
4404 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4405 | |
921e5f0a | 4406 | if (!unwind.proc_start) |
c921be7d | 4407 | as_bad (MISSING_FNSTART); |
921e5f0a | 4408 | |
c19d1205 ZW |
4409 | /* Figure out what sort of save we have. */ |
4410 | peek = input_line_pointer; | |
b99bd4ef | 4411 | |
c19d1205 | 4412 | if (*peek == '{') |
b99bd4ef | 4413 | { |
c19d1205 ZW |
4414 | had_brace = TRUE; |
4415 | peek++; | |
b99bd4ef NC |
4416 | } |
4417 | ||
c19d1205 | 4418 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4419 | |
c19d1205 | 4420 | if (!reg) |
b99bd4ef | 4421 | { |
c19d1205 ZW |
4422 | as_bad (_("register expected")); |
4423 | ignore_rest_of_line (); | |
b99bd4ef NC |
4424 | return; |
4425 | } | |
4426 | ||
c19d1205 | 4427 | switch (reg->type) |
b99bd4ef | 4428 | { |
c19d1205 ZW |
4429 | case REG_TYPE_FN: |
4430 | if (had_brace) | |
4431 | { | |
4432 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4433 | ignore_rest_of_line (); | |
4434 | return; | |
4435 | } | |
93ac2687 | 4436 | input_line_pointer = peek; |
c19d1205 | 4437 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4438 | return; |
c19d1205 | 4439 | |
1f5afe1c NC |
4440 | case REG_TYPE_RN: |
4441 | s_arm_unwind_save_core (); | |
4442 | return; | |
4443 | ||
fa073d69 MS |
4444 | case REG_TYPE_VFD: |
4445 | if (arch_v6) | |
477330fc | 4446 | s_arm_unwind_save_vfp_armv6 (); |
fa073d69 | 4447 | else |
477330fc | 4448 | s_arm_unwind_save_vfp (); |
fa073d69 | 4449 | return; |
1f5afe1c NC |
4450 | |
4451 | case REG_TYPE_MMXWR: | |
4452 | s_arm_unwind_save_mmxwr (); | |
4453 | return; | |
4454 | ||
4455 | case REG_TYPE_MMXWCG: | |
4456 | s_arm_unwind_save_mmxwcg (); | |
4457 | return; | |
c19d1205 ZW |
4458 | |
4459 | default: | |
4460 | as_bad (_(".unwind_save does not support this kind of register")); | |
4461 | ignore_rest_of_line (); | |
b99bd4ef | 4462 | } |
c19d1205 | 4463 | } |
b99bd4ef | 4464 | |
b99bd4ef | 4465 | |
c19d1205 ZW |
4466 | /* Parse an unwind_movsp directive. */ |
4467 | ||
4468 | static void | |
4469 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4470 | { | |
4471 | int reg; | |
4472 | valueT op; | |
4fa3602b | 4473 | int offset; |
c19d1205 | 4474 | |
921e5f0a | 4475 | if (!unwind.proc_start) |
c921be7d | 4476 | as_bad (MISSING_FNSTART); |
921e5f0a | 4477 | |
dcbf9037 | 4478 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4479 | if (reg == FAIL) |
b99bd4ef | 4480 | { |
9b7132d3 | 4481 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4482 | ignore_rest_of_line (); |
b99bd4ef NC |
4483 | return; |
4484 | } | |
4fa3602b PB |
4485 | |
4486 | /* Optional constant. */ | |
4487 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4488 | { | |
4489 | if (immediate_for_directive (&offset) == FAIL) | |
4490 | return; | |
4491 | } | |
4492 | else | |
4493 | offset = 0; | |
4494 | ||
c19d1205 | 4495 | demand_empty_rest_of_line (); |
b99bd4ef | 4496 | |
c19d1205 | 4497 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4498 | { |
c19d1205 | 4499 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4500 | return; |
4501 | } | |
4502 | ||
c19d1205 ZW |
4503 | if (unwind.fp_reg != REG_SP) |
4504 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4505 | |
c19d1205 ZW |
4506 | /* Generate opcode to restore the value. */ |
4507 | op = 0x90 | reg; | |
4508 | add_unwind_opcode (op, 1); | |
4509 | ||
4510 | /* Record the information for later. */ | |
4511 | unwind.fp_reg = reg; | |
4fa3602b | 4512 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4513 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4514 | } |
4515 | ||
c19d1205 ZW |
4516 | /* Parse an unwind_pad directive. */ |
4517 | ||
b05fe5cf | 4518 | static void |
c19d1205 | 4519 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4520 | { |
c19d1205 | 4521 | int offset; |
b05fe5cf | 4522 | |
921e5f0a | 4523 | if (!unwind.proc_start) |
c921be7d | 4524 | as_bad (MISSING_FNSTART); |
921e5f0a | 4525 | |
c19d1205 ZW |
4526 | if (immediate_for_directive (&offset) == FAIL) |
4527 | return; | |
b99bd4ef | 4528 | |
c19d1205 ZW |
4529 | if (offset & 3) |
4530 | { | |
4531 | as_bad (_("stack increment must be multiple of 4")); | |
4532 | ignore_rest_of_line (); | |
4533 | return; | |
4534 | } | |
b99bd4ef | 4535 | |
c19d1205 ZW |
4536 | /* Don't generate any opcodes, just record the details for later. */ |
4537 | unwind.frame_size += offset; | |
4538 | unwind.pending_offset += offset; | |
4539 | ||
4540 | demand_empty_rest_of_line (); | |
4541 | } | |
4542 | ||
4543 | /* Parse an unwind_setfp directive. */ | |
4544 | ||
4545 | static void | |
4546 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4547 | { |
c19d1205 ZW |
4548 | int sp_reg; |
4549 | int fp_reg; | |
4550 | int offset; | |
4551 | ||
921e5f0a | 4552 | if (!unwind.proc_start) |
c921be7d | 4553 | as_bad (MISSING_FNSTART); |
921e5f0a | 4554 | |
dcbf9037 | 4555 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4556 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4557 | sp_reg = FAIL; | |
4558 | else | |
dcbf9037 | 4559 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4560 | |
c19d1205 ZW |
4561 | if (fp_reg == FAIL || sp_reg == FAIL) |
4562 | { | |
4563 | as_bad (_("expected <reg>, <reg>")); | |
4564 | ignore_rest_of_line (); | |
4565 | return; | |
4566 | } | |
b99bd4ef | 4567 | |
c19d1205 ZW |
4568 | /* Optional constant. */ |
4569 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4570 | { | |
4571 | if (immediate_for_directive (&offset) == FAIL) | |
4572 | return; | |
4573 | } | |
4574 | else | |
4575 | offset = 0; | |
a737bd4d | 4576 | |
c19d1205 | 4577 | demand_empty_rest_of_line (); |
a737bd4d | 4578 | |
fdfde340 | 4579 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4580 | { |
c19d1205 ZW |
4581 | as_bad (_("register must be either sp or set by a previous" |
4582 | "unwind_movsp directive")); | |
4583 | return; | |
a737bd4d NC |
4584 | } |
4585 | ||
c19d1205 ZW |
4586 | /* Don't generate any opcodes, just record the information for later. */ |
4587 | unwind.fp_reg = fp_reg; | |
4588 | unwind.fp_used = 1; | |
fdfde340 | 4589 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4590 | unwind.fp_offset = unwind.frame_size - offset; |
4591 | else | |
4592 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4593 | } |
4594 | ||
c19d1205 ZW |
4595 | /* Parse an unwind_raw directive. */ |
4596 | ||
4597 | static void | |
4598 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4599 | { |
c19d1205 | 4600 | expressionS exp; |
708587a4 | 4601 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4602 | unsigned char op[16]; |
4603 | int count; | |
a737bd4d | 4604 | |
921e5f0a | 4605 | if (!unwind.proc_start) |
c921be7d | 4606 | as_bad (MISSING_FNSTART); |
921e5f0a | 4607 | |
c19d1205 ZW |
4608 | expression (&exp); |
4609 | if (exp.X_op == O_constant | |
4610 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4611 | { |
c19d1205 ZW |
4612 | unwind.frame_size += exp.X_add_number; |
4613 | expression (&exp); | |
4614 | } | |
4615 | else | |
4616 | exp.X_op = O_illegal; | |
a737bd4d | 4617 | |
c19d1205 ZW |
4618 | if (exp.X_op != O_constant) |
4619 | { | |
4620 | as_bad (_("expected <offset>, <opcode>")); | |
4621 | ignore_rest_of_line (); | |
4622 | return; | |
4623 | } | |
a737bd4d | 4624 | |
c19d1205 | 4625 | count = 0; |
a737bd4d | 4626 | |
c19d1205 ZW |
4627 | /* Parse the opcode. */ |
4628 | for (;;) | |
4629 | { | |
4630 | if (count >= 16) | |
4631 | { | |
4632 | as_bad (_("unwind opcode too long")); | |
4633 | ignore_rest_of_line (); | |
a737bd4d | 4634 | } |
c19d1205 | 4635 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4636 | { |
c19d1205 ZW |
4637 | as_bad (_("invalid unwind opcode")); |
4638 | ignore_rest_of_line (); | |
4639 | return; | |
a737bd4d | 4640 | } |
c19d1205 | 4641 | op[count++] = exp.X_add_number; |
a737bd4d | 4642 | |
c19d1205 ZW |
4643 | /* Parse the next byte. */ |
4644 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4645 | break; | |
a737bd4d | 4646 | |
c19d1205 ZW |
4647 | expression (&exp); |
4648 | } | |
b99bd4ef | 4649 | |
c19d1205 ZW |
4650 | /* Add the opcode bytes in reverse order. */ |
4651 | while (count--) | |
4652 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4653 | |
c19d1205 | 4654 | demand_empty_rest_of_line (); |
b99bd4ef | 4655 | } |
ee065d83 PB |
4656 | |
4657 | ||
4658 | /* Parse a .eabi_attribute directive. */ | |
4659 | ||
4660 | static void | |
4661 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4662 | { | |
0420f52b | 4663 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 AS |
4664 | |
4665 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4666 | attributes_set_explicitly[tag] = 1; | |
ee065d83 PB |
4667 | } |
4668 | ||
0855e32b NS |
4669 | /* Emit a tls fix for the symbol. */ |
4670 | ||
4671 | static void | |
4672 | s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED) | |
4673 | { | |
4674 | char *p; | |
4675 | expressionS exp; | |
4676 | #ifdef md_flush_pending_output | |
4677 | md_flush_pending_output (); | |
4678 | #endif | |
4679 | ||
4680 | #ifdef md_cons_align | |
4681 | md_cons_align (4); | |
4682 | #endif | |
4683 | ||
4684 | /* Since we're just labelling the code, there's no need to define a | |
4685 | mapping symbol. */ | |
4686 | expression (&exp); | |
4687 | p = obstack_next_free (&frchain_now->frch_obstack); | |
4688 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0, | |
4689 | thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
4690 | : BFD_RELOC_ARM_TLS_DESCSEQ); | |
4691 | } | |
cdf9ccec | 4692 | #endif /* OBJ_ELF */ |
0855e32b | 4693 | |
ee065d83 | 4694 | static void s_arm_arch (int); |
7a1d4c38 | 4695 | static void s_arm_object_arch (int); |
ee065d83 PB |
4696 | static void s_arm_cpu (int); |
4697 | static void s_arm_fpu (int); | |
69133863 | 4698 | static void s_arm_arch_extension (int); |
b99bd4ef | 4699 | |
f0927246 NC |
4700 | #ifdef TE_PE |
4701 | ||
4702 | static void | |
5f4273c7 | 4703 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4704 | { |
4705 | expressionS exp; | |
4706 | ||
4707 | do | |
4708 | { | |
4709 | expression (&exp); | |
4710 | if (exp.X_op == O_symbol) | |
4711 | exp.X_op = O_secrel; | |
4712 | ||
4713 | emit_expr (&exp, 4); | |
4714 | } | |
4715 | while (*input_line_pointer++ == ','); | |
4716 | ||
4717 | input_line_pointer--; | |
4718 | demand_empty_rest_of_line (); | |
4719 | } | |
4720 | #endif /* TE_PE */ | |
4721 | ||
c19d1205 ZW |
4722 | /* This table describes all the machine specific pseudo-ops the assembler |
4723 | has to support. The fields are: | |
4724 | pseudo-op name without dot | |
4725 | function to call to execute this pseudo-op | |
4726 | Integer arg to pass to the function. */ | |
b99bd4ef | 4727 | |
c19d1205 | 4728 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4729 | { |
c19d1205 ZW |
4730 | /* Never called because '.req' does not start a line. */ |
4731 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4732 | /* Following two are likewise never called. */ |
4733 | { "dn", s_dn, 0 }, | |
4734 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4735 | { "unreq", s_unreq, 0 }, |
4736 | { "bss", s_bss, 0 }, | |
db2ed2e0 | 4737 | { "align", s_align_ptwo, 2 }, |
c19d1205 ZW |
4738 | { "arm", s_arm, 0 }, |
4739 | { "thumb", s_thumb, 0 }, | |
4740 | { "code", s_code, 0 }, | |
4741 | { "force_thumb", s_force_thumb, 0 }, | |
4742 | { "thumb_func", s_thumb_func, 0 }, | |
4743 | { "thumb_set", s_thumb_set, 0 }, | |
4744 | { "even", s_even, 0 }, | |
4745 | { "ltorg", s_ltorg, 0 }, | |
4746 | { "pool", s_ltorg, 0 }, | |
4747 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4748 | { "cpu", s_arm_cpu, 0 }, |
4749 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4750 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4751 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 4752 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 4753 | #ifdef OBJ_ELF |
c921be7d NC |
4754 | { "word", s_arm_elf_cons, 4 }, |
4755 | { "long", s_arm_elf_cons, 4 }, | |
4756 | { "inst.n", s_arm_elf_inst, 2 }, | |
4757 | { "inst.w", s_arm_elf_inst, 4 }, | |
4758 | { "inst", s_arm_elf_inst, 0 }, | |
4759 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4760 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4761 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4762 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4763 | { "personality", s_arm_unwind_personality, 0 }, | |
4764 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4765 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4766 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4767 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4768 | { "movsp", s_arm_unwind_movsp, 0 }, |
4769 | { "pad", s_arm_unwind_pad, 0 }, | |
4770 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4771 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4772 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 4773 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
4774 | #else |
4775 | { "word", cons, 4}, | |
f0927246 NC |
4776 | |
4777 | /* These are used for dwarf. */ | |
4778 | {"2byte", cons, 2}, | |
4779 | {"4byte", cons, 4}, | |
4780 | {"8byte", cons, 8}, | |
4781 | /* These are used for dwarf2. */ | |
68d20676 | 4782 | { "file", dwarf2_directive_file, 0 }, |
f0927246 NC |
4783 | { "loc", dwarf2_directive_loc, 0 }, |
4784 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4785 | #endif |
4786 | { "extend", float_cons, 'x' }, | |
4787 | { "ldouble", float_cons, 'x' }, | |
4788 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4789 | #ifdef TE_PE |
4790 | {"secrel32", pe_directive_secrel, 0}, | |
4791 | #endif | |
2e6976a8 DG |
4792 | |
4793 | /* These are for compatibility with CodeComposer Studio. */ | |
4794 | {"ref", s_ccs_ref, 0}, | |
4795 | {"def", s_ccs_def, 0}, | |
4796 | {"asmfunc", s_ccs_asmfunc, 0}, | |
4797 | {"endasmfunc", s_ccs_endasmfunc, 0}, | |
4798 | ||
c19d1205 ZW |
4799 | { 0, 0, 0 } |
4800 | }; | |
4801 | \f | |
4802 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4803 | |
c19d1205 ZW |
4804 | /* Generic immediate-value read function for use in insn parsing. |
4805 | STR points to the beginning of the immediate (the leading #); | |
4806 | VAL receives the value; if the value is outside [MIN, MAX] | |
4807 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4808 | optional. */ | |
b99bd4ef | 4809 | |
c19d1205 ZW |
4810 | static int |
4811 | parse_immediate (char **str, int *val, int min, int max, | |
4812 | bfd_boolean prefix_opt) | |
4813 | { | |
4814 | expressionS exp; | |
0198d5e6 | 4815 | |
c19d1205 ZW |
4816 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); |
4817 | if (exp.X_op != O_constant) | |
b99bd4ef | 4818 | { |
c19d1205 ZW |
4819 | inst.error = _("constant expression required"); |
4820 | return FAIL; | |
4821 | } | |
b99bd4ef | 4822 | |
c19d1205 ZW |
4823 | if (exp.X_add_number < min || exp.X_add_number > max) |
4824 | { | |
4825 | inst.error = _("immediate value out of range"); | |
4826 | return FAIL; | |
4827 | } | |
b99bd4ef | 4828 | |
c19d1205 ZW |
4829 | *val = exp.X_add_number; |
4830 | return SUCCESS; | |
4831 | } | |
b99bd4ef | 4832 | |
5287ad62 | 4833 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4834 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4835 | instructions. Puts the result directly in inst.operands[i]. */ |
4836 | ||
4837 | static int | |
8335d6aa JW |
4838 | parse_big_immediate (char **str, int i, expressionS *in_exp, |
4839 | bfd_boolean allow_symbol_p) | |
5287ad62 JB |
4840 | { |
4841 | expressionS exp; | |
8335d6aa | 4842 | expressionS *exp_p = in_exp ? in_exp : &exp; |
5287ad62 JB |
4843 | char *ptr = *str; |
4844 | ||
8335d6aa | 4845 | my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG); |
5287ad62 | 4846 | |
8335d6aa | 4847 | if (exp_p->X_op == O_constant) |
036dc3f7 | 4848 | { |
8335d6aa | 4849 | inst.operands[i].imm = exp_p->X_add_number & 0xffffffff; |
036dc3f7 PB |
4850 | /* If we're on a 64-bit host, then a 64-bit number can be returned using |
4851 | O_constant. We have to be careful not to break compilation for | |
4852 | 32-bit X_add_number, though. */ | |
8335d6aa | 4853 | if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 | 4854 | { |
8335d6aa JW |
4855 | /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */ |
4856 | inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16) | |
4857 | & 0xffffffff); | |
036dc3f7 PB |
4858 | inst.operands[i].regisimm = 1; |
4859 | } | |
4860 | } | |
8335d6aa JW |
4861 | else if (exp_p->X_op == O_big |
4862 | && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32) | |
5287ad62 JB |
4863 | { |
4864 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 4865 | |
5287ad62 | 4866 | /* Bignums have their least significant bits in |
477330fc RM |
4867 | generic_bignum[0]. Make sure we put 32 bits in imm and |
4868 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4869 | gas_assert (parts != 0); |
95b75c01 NC |
4870 | |
4871 | /* Make sure that the number is not too big. | |
4872 | PR 11972: Bignums can now be sign-extended to the | |
4873 | size of a .octa so check that the out of range bits | |
4874 | are all zero or all one. */ | |
8335d6aa | 4875 | if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64) |
95b75c01 NC |
4876 | { |
4877 | LITTLENUM_TYPE m = -1; | |
4878 | ||
4879 | if (generic_bignum[parts * 2] != 0 | |
4880 | && generic_bignum[parts * 2] != m) | |
4881 | return FAIL; | |
4882 | ||
8335d6aa | 4883 | for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++) |
95b75c01 NC |
4884 | if (generic_bignum[j] != generic_bignum[j-1]) |
4885 | return FAIL; | |
4886 | } | |
4887 | ||
5287ad62 JB |
4888 | inst.operands[i].imm = 0; |
4889 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4890 | inst.operands[i].imm |= generic_bignum[idx] |
4891 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4892 | inst.operands[i].reg = 0; |
4893 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4894 | inst.operands[i].reg |= generic_bignum[idx] |
4895 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4896 | inst.operands[i].regisimm = 1; |
4897 | } | |
8335d6aa | 4898 | else if (!(exp_p->X_op == O_symbol && allow_symbol_p)) |
5287ad62 | 4899 | return FAIL; |
5f4273c7 | 4900 | |
5287ad62 JB |
4901 | *str = ptr; |
4902 | ||
4903 | return SUCCESS; | |
4904 | } | |
4905 | ||
c19d1205 ZW |
4906 | /* Returns the pseudo-register number of an FPA immediate constant, |
4907 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4908 | |
c19d1205 ZW |
4909 | static int |
4910 | parse_fpa_immediate (char ** str) | |
4911 | { | |
4912 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4913 | char * save_in; | |
4914 | expressionS exp; | |
4915 | int i; | |
4916 | int j; | |
b99bd4ef | 4917 | |
c19d1205 ZW |
4918 | /* First try and match exact strings, this is to guarantee |
4919 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4920 | |
c19d1205 ZW |
4921 | for (i = 0; fp_const[i]; i++) |
4922 | { | |
4923 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4924 | { |
c19d1205 | 4925 | char *start = *str; |
b99bd4ef | 4926 | |
c19d1205 ZW |
4927 | *str += strlen (fp_const[i]); |
4928 | if (is_end_of_line[(unsigned char) **str]) | |
4929 | return i + 8; | |
4930 | *str = start; | |
4931 | } | |
4932 | } | |
b99bd4ef | 4933 | |
c19d1205 ZW |
4934 | /* Just because we didn't get a match doesn't mean that the constant |
4935 | isn't valid, just that it is in a format that we don't | |
4936 | automatically recognize. Try parsing it with the standard | |
4937 | expression routines. */ | |
b99bd4ef | 4938 | |
c19d1205 | 4939 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4940 | |
c19d1205 ZW |
4941 | /* Look for a raw floating point number. */ |
4942 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4943 | && is_end_of_line[(unsigned char) *save_in]) | |
4944 | { | |
4945 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4946 | { | |
4947 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4948 | { |
c19d1205 ZW |
4949 | if (words[j] != fp_values[i][j]) |
4950 | break; | |
b99bd4ef NC |
4951 | } |
4952 | ||
c19d1205 | 4953 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4954 | { |
c19d1205 ZW |
4955 | *str = save_in; |
4956 | return i + 8; | |
b99bd4ef NC |
4957 | } |
4958 | } | |
4959 | } | |
b99bd4ef | 4960 | |
c19d1205 ZW |
4961 | /* Try and parse a more complex expression, this will probably fail |
4962 | unless the code uses a floating point prefix (eg "0f"). */ | |
4963 | save_in = input_line_pointer; | |
4964 | input_line_pointer = *str; | |
4965 | if (expression (&exp) == absolute_section | |
4966 | && exp.X_op == O_big | |
4967 | && exp.X_add_number < 0) | |
4968 | { | |
4969 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4970 | Ditto for 15. */ | |
ba592044 AM |
4971 | #define X_PRECISION 5 |
4972 | #define E_PRECISION 15L | |
4973 | if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0) | |
c19d1205 ZW |
4974 | { |
4975 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4976 | { | |
4977 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4978 | { | |
4979 | if (words[j] != fp_values[i][j]) | |
4980 | break; | |
4981 | } | |
b99bd4ef | 4982 | |
c19d1205 ZW |
4983 | if (j == MAX_LITTLENUMS) |
4984 | { | |
4985 | *str = input_line_pointer; | |
4986 | input_line_pointer = save_in; | |
4987 | return i + 8; | |
4988 | } | |
4989 | } | |
4990 | } | |
b99bd4ef NC |
4991 | } |
4992 | ||
c19d1205 ZW |
4993 | *str = input_line_pointer; |
4994 | input_line_pointer = save_in; | |
4995 | inst.error = _("invalid FPA immediate expression"); | |
4996 | return FAIL; | |
b99bd4ef NC |
4997 | } |
4998 | ||
136da414 JB |
4999 | /* Returns 1 if a number has "quarter-precision" float format |
5000 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
5001 | ||
5002 | static int | |
5003 | is_quarter_float (unsigned imm) | |
5004 | { | |
5005 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
5006 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
5007 | } | |
5008 | ||
aacf0b33 KT |
5009 | |
5010 | /* Detect the presence of a floating point or integer zero constant, | |
5011 | i.e. #0.0 or #0. */ | |
5012 | ||
5013 | static bfd_boolean | |
5014 | parse_ifimm_zero (char **in) | |
5015 | { | |
5016 | int error_code; | |
5017 | ||
5018 | if (!is_immediate_prefix (**in)) | |
3c6452ae TP |
5019 | { |
5020 | /* In unified syntax, all prefixes are optional. */ | |
5021 | if (!unified_syntax) | |
5022 | return FALSE; | |
5023 | } | |
5024 | else | |
5025 | ++*in; | |
0900a05b JW |
5026 | |
5027 | /* Accept #0x0 as a synonym for #0. */ | |
5028 | if (strncmp (*in, "0x", 2) == 0) | |
5029 | { | |
5030 | int val; | |
5031 | if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL) | |
5032 | return FALSE; | |
5033 | return TRUE; | |
5034 | } | |
5035 | ||
aacf0b33 KT |
5036 | error_code = atof_generic (in, ".", EXP_CHARS, |
5037 | &generic_floating_point_number); | |
5038 | ||
5039 | if (!error_code | |
5040 | && generic_floating_point_number.sign == '+' | |
5041 | && (generic_floating_point_number.low | |
5042 | > generic_floating_point_number.leader)) | |
5043 | return TRUE; | |
5044 | ||
5045 | return FALSE; | |
5046 | } | |
5047 | ||
136da414 JB |
5048 | /* Parse an 8-bit "quarter-precision" floating point number of the form: |
5049 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
5050 | The zero and minus-zero cases need special handling, since they can't be |
5051 | encoded in the "quarter-precision" float format, but can nonetheless be | |
5052 | loaded as integer constants. */ | |
136da414 JB |
5053 | |
5054 | static unsigned | |
5055 | parse_qfloat_immediate (char **ccp, int *immed) | |
5056 | { | |
5057 | char *str = *ccp; | |
c96612cc | 5058 | char *fpnum; |
136da414 | 5059 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 5060 | int found_fpchar = 0; |
5f4273c7 | 5061 | |
136da414 | 5062 | skip_past_char (&str, '#'); |
5f4273c7 | 5063 | |
c96612cc JB |
5064 | /* We must not accidentally parse an integer as a floating-point number. Make |
5065 | sure that the value we parse is not an integer by checking for special | |
5066 | characters '.' or 'e'. | |
5067 | FIXME: This is a horrible hack, but doing better is tricky because type | |
5068 | information isn't in a very usable state at parse time. */ | |
5069 | fpnum = str; | |
5070 | skip_whitespace (fpnum); | |
5071 | ||
5072 | if (strncmp (fpnum, "0x", 2) == 0) | |
5073 | return FAIL; | |
5074 | else | |
5075 | { | |
5076 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
477330fc RM |
5077 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
5078 | { | |
5079 | found_fpchar = 1; | |
5080 | break; | |
5081 | } | |
c96612cc JB |
5082 | |
5083 | if (!found_fpchar) | |
477330fc | 5084 | return FAIL; |
c96612cc | 5085 | } |
5f4273c7 | 5086 | |
136da414 JB |
5087 | if ((str = atof_ieee (str, 's', words)) != NULL) |
5088 | { | |
5089 | unsigned fpword = 0; | |
5090 | int i; | |
5f4273c7 | 5091 | |
136da414 JB |
5092 | /* Our FP word must be 32 bits (single-precision FP). */ |
5093 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
477330fc RM |
5094 | { |
5095 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
5096 | fpword |= words[i]; | |
5097 | } | |
5f4273c7 | 5098 | |
c96612cc | 5099 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
477330fc | 5100 | *immed = fpword; |
136da414 | 5101 | else |
477330fc | 5102 | return FAIL; |
136da414 JB |
5103 | |
5104 | *ccp = str; | |
5f4273c7 | 5105 | |
136da414 JB |
5106 | return SUCCESS; |
5107 | } | |
5f4273c7 | 5108 | |
136da414 JB |
5109 | return FAIL; |
5110 | } | |
5111 | ||
c19d1205 ZW |
5112 | /* Shift operands. */ |
5113 | enum shift_kind | |
b99bd4ef | 5114 | { |
c19d1205 ZW |
5115 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
5116 | }; | |
b99bd4ef | 5117 | |
c19d1205 ZW |
5118 | struct asm_shift_name |
5119 | { | |
5120 | const char *name; | |
5121 | enum shift_kind kind; | |
5122 | }; | |
b99bd4ef | 5123 | |
c19d1205 ZW |
5124 | /* Third argument to parse_shift. */ |
5125 | enum parse_shift_mode | |
5126 | { | |
5127 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
5128 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
5129 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
5130 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
5131 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
5132 | }; | |
b99bd4ef | 5133 | |
c19d1205 ZW |
5134 | /* Parse a <shift> specifier on an ARM data processing instruction. |
5135 | This has three forms: | |
b99bd4ef | 5136 | |
c19d1205 ZW |
5137 | (LSL|LSR|ASL|ASR|ROR) Rs |
5138 | (LSL|LSR|ASL|ASR|ROR) #imm | |
5139 | RRX | |
b99bd4ef | 5140 | |
c19d1205 ZW |
5141 | Note that ASL is assimilated to LSL in the instruction encoding, and |
5142 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 5143 | |
c19d1205 ZW |
5144 | static int |
5145 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 5146 | { |
c19d1205 ZW |
5147 | const struct asm_shift_name *shift_name; |
5148 | enum shift_kind shift; | |
5149 | char *s = *str; | |
5150 | char *p = s; | |
5151 | int reg; | |
b99bd4ef | 5152 | |
c19d1205 ZW |
5153 | for (p = *str; ISALPHA (*p); p++) |
5154 | ; | |
b99bd4ef | 5155 | |
c19d1205 | 5156 | if (p == *str) |
b99bd4ef | 5157 | { |
c19d1205 ZW |
5158 | inst.error = _("shift expression expected"); |
5159 | return FAIL; | |
b99bd4ef NC |
5160 | } |
5161 | ||
21d799b5 | 5162 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
477330fc | 5163 | p - *str); |
c19d1205 ZW |
5164 | |
5165 | if (shift_name == NULL) | |
b99bd4ef | 5166 | { |
c19d1205 ZW |
5167 | inst.error = _("shift expression expected"); |
5168 | return FAIL; | |
b99bd4ef NC |
5169 | } |
5170 | ||
c19d1205 | 5171 | shift = shift_name->kind; |
b99bd4ef | 5172 | |
c19d1205 ZW |
5173 | switch (mode) |
5174 | { | |
5175 | case NO_SHIFT_RESTRICT: | |
5176 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 5177 | |
c19d1205 ZW |
5178 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
5179 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
5180 | { | |
5181 | inst.error = _("'LSL' or 'ASR' required"); | |
5182 | return FAIL; | |
5183 | } | |
5184 | break; | |
b99bd4ef | 5185 | |
c19d1205 ZW |
5186 | case SHIFT_LSL_IMMEDIATE: |
5187 | if (shift != SHIFT_LSL) | |
5188 | { | |
5189 | inst.error = _("'LSL' required"); | |
5190 | return FAIL; | |
5191 | } | |
5192 | break; | |
b99bd4ef | 5193 | |
c19d1205 ZW |
5194 | case SHIFT_ASR_IMMEDIATE: |
5195 | if (shift != SHIFT_ASR) | |
5196 | { | |
5197 | inst.error = _("'ASR' required"); | |
5198 | return FAIL; | |
5199 | } | |
5200 | break; | |
b99bd4ef | 5201 | |
c19d1205 ZW |
5202 | default: abort (); |
5203 | } | |
b99bd4ef | 5204 | |
c19d1205 ZW |
5205 | if (shift != SHIFT_RRX) |
5206 | { | |
5207 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
5208 | skip_whitespace (p); | |
b99bd4ef | 5209 | |
c19d1205 | 5210 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 5211 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5212 | { |
5213 | inst.operands[i].imm = reg; | |
5214 | inst.operands[i].immisreg = 1; | |
5215 | } | |
e2b0ab59 | 5216 | else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
c19d1205 ZW |
5217 | return FAIL; |
5218 | } | |
5219 | inst.operands[i].shift_kind = shift; | |
5220 | inst.operands[i].shifted = 1; | |
5221 | *str = p; | |
5222 | return SUCCESS; | |
b99bd4ef NC |
5223 | } |
5224 | ||
c19d1205 | 5225 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 5226 | |
c19d1205 ZW |
5227 | #<immediate> |
5228 | #<immediate>, <rotate> | |
5229 | <Rm> | |
5230 | <Rm>, <shift> | |
b99bd4ef | 5231 | |
c19d1205 ZW |
5232 | where <shift> is defined by parse_shift above, and <rotate> is a |
5233 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 5234 | is deferred to md_apply_fix. */ |
b99bd4ef | 5235 | |
c19d1205 ZW |
5236 | static int |
5237 | parse_shifter_operand (char **str, int i) | |
5238 | { | |
5239 | int value; | |
91d6fa6a | 5240 | expressionS exp; |
b99bd4ef | 5241 | |
dcbf9037 | 5242 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5243 | { |
5244 | inst.operands[i].reg = value; | |
5245 | inst.operands[i].isreg = 1; | |
b99bd4ef | 5246 | |
c19d1205 | 5247 | /* parse_shift will override this if appropriate */ |
e2b0ab59 AV |
5248 | inst.relocs[0].exp.X_op = O_constant; |
5249 | inst.relocs[0].exp.X_add_number = 0; | |
b99bd4ef | 5250 | |
c19d1205 ZW |
5251 | if (skip_past_comma (str) == FAIL) |
5252 | return SUCCESS; | |
b99bd4ef | 5253 | |
c19d1205 ZW |
5254 | /* Shift operation on register. */ |
5255 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
5256 | } |
5257 | ||
e2b0ab59 | 5258 | if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX)) |
c19d1205 | 5259 | return FAIL; |
b99bd4ef | 5260 | |
c19d1205 | 5261 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 5262 | { |
c19d1205 | 5263 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 5264 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 5265 | return FAIL; |
b99bd4ef | 5266 | |
e2b0ab59 | 5267 | if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant) |
c19d1205 ZW |
5268 | { |
5269 | inst.error = _("constant expression expected"); | |
5270 | return FAIL; | |
5271 | } | |
b99bd4ef | 5272 | |
91d6fa6a | 5273 | value = exp.X_add_number; |
c19d1205 ZW |
5274 | if (value < 0 || value > 30 || value % 2 != 0) |
5275 | { | |
5276 | inst.error = _("invalid rotation"); | |
5277 | return FAIL; | |
5278 | } | |
e2b0ab59 AV |
5279 | if (inst.relocs[0].exp.X_add_number < 0 |
5280 | || inst.relocs[0].exp.X_add_number > 255) | |
c19d1205 ZW |
5281 | { |
5282 | inst.error = _("invalid constant"); | |
5283 | return FAIL; | |
5284 | } | |
09d92015 | 5285 | |
a415b1cd | 5286 | /* Encode as specified. */ |
e2b0ab59 | 5287 | inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7; |
a415b1cd | 5288 | return SUCCESS; |
09d92015 MM |
5289 | } |
5290 | ||
e2b0ab59 AV |
5291 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
5292 | inst.relocs[0].pc_rel = 0; | |
c19d1205 | 5293 | return SUCCESS; |
09d92015 MM |
5294 | } |
5295 | ||
4962c51a MS |
5296 | /* Group relocation information. Each entry in the table contains the |
5297 | textual name of the relocation as may appear in assembler source | |
5298 | and must end with a colon. | |
5299 | Along with this textual name are the relocation codes to be used if | |
5300 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
5301 | an LDR, an LDRS, or an LDC. */ | |
5302 | ||
5303 | struct group_reloc_table_entry | |
5304 | { | |
5305 | const char *name; | |
5306 | int alu_code; | |
5307 | int ldr_code; | |
5308 | int ldrs_code; | |
5309 | int ldc_code; | |
5310 | }; | |
5311 | ||
5312 | typedef enum | |
5313 | { | |
5314 | /* Varieties of non-ALU group relocation. */ | |
5315 | ||
5316 | GROUP_LDR, | |
5317 | GROUP_LDRS, | |
5318 | GROUP_LDC | |
5319 | } group_reloc_type; | |
5320 | ||
5321 | static struct group_reloc_table_entry group_reloc_table[] = | |
5322 | { /* Program counter relative: */ | |
5323 | { "pc_g0_nc", | |
5324 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
5325 | 0, /* LDR */ | |
5326 | 0, /* LDRS */ | |
5327 | 0 }, /* LDC */ | |
5328 | { "pc_g0", | |
5329 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
5330 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
5331 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
5332 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
5333 | { "pc_g1_nc", | |
5334 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
5335 | 0, /* LDR */ | |
5336 | 0, /* LDRS */ | |
5337 | 0 }, /* LDC */ | |
5338 | { "pc_g1", | |
5339 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
5340 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
5341 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
5342 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
5343 | { "pc_g2", | |
5344 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
5345 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
5346 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
5347 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
5348 | /* Section base relative */ | |
5349 | { "sb_g0_nc", | |
5350 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
5351 | 0, /* LDR */ | |
5352 | 0, /* LDRS */ | |
5353 | 0 }, /* LDC */ | |
5354 | { "sb_g0", | |
5355 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
5356 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
5357 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
5358 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
5359 | { "sb_g1_nc", | |
5360 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
5361 | 0, /* LDR */ | |
5362 | 0, /* LDRS */ | |
5363 | 0 }, /* LDC */ | |
5364 | { "sb_g1", | |
5365 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
5366 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
5367 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
5368 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
5369 | { "sb_g2", | |
5370 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
5371 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
5372 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
72d98d16 MG |
5373 | BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */ |
5374 | /* Absolute thumb alu relocations. */ | |
5375 | { "lower0_7", | |
5376 | BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */ | |
5377 | 0, /* LDR. */ | |
5378 | 0, /* LDRS. */ | |
5379 | 0 }, /* LDC. */ | |
5380 | { "lower8_15", | |
5381 | BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */ | |
5382 | 0, /* LDR. */ | |
5383 | 0, /* LDRS. */ | |
5384 | 0 }, /* LDC. */ | |
5385 | { "upper0_7", | |
5386 | BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */ | |
5387 | 0, /* LDR. */ | |
5388 | 0, /* LDRS. */ | |
5389 | 0 }, /* LDC. */ | |
5390 | { "upper8_15", | |
5391 | BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */ | |
5392 | 0, /* LDR. */ | |
5393 | 0, /* LDRS. */ | |
5394 | 0 } }; /* LDC. */ | |
4962c51a MS |
5395 | |
5396 | /* Given the address of a pointer pointing to the textual name of a group | |
5397 | relocation as may appear in assembler source, attempt to find its details | |
5398 | in group_reloc_table. The pointer will be updated to the character after | |
5399 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
5400 | otherwise. On success, *entry will be updated to point at the relevant | |
5401 | group_reloc_table entry. */ | |
5402 | ||
5403 | static int | |
5404 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
5405 | { | |
5406 | unsigned int i; | |
5407 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
5408 | { | |
5409 | int length = strlen (group_reloc_table[i].name); | |
5410 | ||
5f4273c7 NC |
5411 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5412 | && (*str)[length] == ':') | |
477330fc RM |
5413 | { |
5414 | *out = &group_reloc_table[i]; | |
5415 | *str += (length + 1); | |
5416 | return SUCCESS; | |
5417 | } | |
4962c51a MS |
5418 | } |
5419 | ||
5420 | return FAIL; | |
5421 | } | |
5422 | ||
5423 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
5424 | (as for parse_shifter_operand) where group relocations are allowed: | |
5425 | ||
5426 | #<immediate> | |
5427 | #<immediate>, <rotate> | |
5428 | #:<group_reloc>:<expression> | |
5429 | <Rm> | |
5430 | <Rm>, <shift> | |
5431 | ||
5432 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
5433 | The hashes are optional. | |
5434 | ||
5435 | Everything else is as for parse_shifter_operand. */ | |
5436 | ||
5437 | static parse_operand_result | |
5438 | parse_shifter_operand_group_reloc (char **str, int i) | |
5439 | { | |
5440 | /* Determine if we have the sequence of characters #: or just : | |
5441 | coming next. If we do, then we check for a group relocation. | |
5442 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
5443 | ||
5444 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
5445 | || (*str)[0] == ':') | |
5446 | { | |
5447 | struct group_reloc_table_entry *entry; | |
5448 | ||
5449 | if ((*str)[0] == '#') | |
477330fc | 5450 | (*str) += 2; |
4962c51a | 5451 | else |
477330fc | 5452 | (*str)++; |
4962c51a MS |
5453 | |
5454 | /* Try to parse a group relocation. Anything else is an error. */ | |
5455 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
477330fc RM |
5456 | { |
5457 | inst.error = _("unknown group relocation"); | |
5458 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5459 | } | |
4962c51a MS |
5460 | |
5461 | /* We now have the group relocation table entry corresponding to | |
477330fc | 5462 | the name in the assembler source. Next, we parse the expression. */ |
e2b0ab59 | 5463 | if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX)) |
477330fc | 5464 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
4962c51a MS |
5465 | |
5466 | /* Record the relocation type (always the ALU variant here). */ | |
e2b0ab59 AV |
5467 | inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code; |
5468 | gas_assert (inst.relocs[0].type != 0); | |
4962c51a MS |
5469 | |
5470 | return PARSE_OPERAND_SUCCESS; | |
5471 | } | |
5472 | else | |
5473 | return parse_shifter_operand (str, i) == SUCCESS | |
477330fc | 5474 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; |
4962c51a MS |
5475 | |
5476 | /* Never reached. */ | |
5477 | } | |
5478 | ||
8e560766 MGD |
5479 | /* Parse a Neon alignment expression. Information is written to |
5480 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5481 | |
8e560766 MGD |
5482 | align .imm = align << 8, .immisalign=1, .preind=0 */ |
5483 | static parse_operand_result | |
5484 | parse_neon_alignment (char **str, int i) | |
5485 | { | |
5486 | char *p = *str; | |
5487 | expressionS exp; | |
5488 | ||
5489 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5490 | ||
5491 | if (exp.X_op != O_constant) | |
5492 | { | |
5493 | inst.error = _("alignment must be constant"); | |
5494 | return PARSE_OPERAND_FAIL; | |
5495 | } | |
5496 | ||
5497 | inst.operands[i].imm = exp.X_add_number << 8; | |
5498 | inst.operands[i].immisalign = 1; | |
5499 | /* Alignments are not pre-indexes. */ | |
5500 | inst.operands[i].preind = 0; | |
5501 | ||
5502 | *str = p; | |
5503 | return PARSE_OPERAND_SUCCESS; | |
5504 | } | |
5505 | ||
c19d1205 | 5506 | /* Parse all forms of an ARM address expression. Information is written |
e2b0ab59 | 5507 | to inst.operands[i] and/or inst.relocs[0]. |
09d92015 | 5508 | |
c19d1205 | 5509 | Preindexed addressing (.preind=1): |
09d92015 | 5510 | |
e2b0ab59 | 5511 | [Rn, #offset] .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
5512 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 |
5513 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
e2b0ab59 | 5514 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5515 | |
c19d1205 | 5516 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5517 | |
c19d1205 | 5518 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5519 | |
e2b0ab59 | 5520 | [Rn], #offset .reg=Rn .relocs[0].exp=offset |
c19d1205 ZW |
5521 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 |
5522 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
e2b0ab59 | 5523 | .shift_kind=shift .relocs[0].exp=shift_imm |
09d92015 | 5524 | |
c19d1205 | 5525 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5526 | |
c19d1205 | 5527 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5528 | |
c19d1205 | 5529 | Other: |
09d92015 | 5530 | |
c19d1205 | 5531 | [Rn]{!} shorthand for [Rn,#0]{!} |
e2b0ab59 AV |
5532 | =immediate .isreg=0 .relocs[0].exp=immediate |
5533 | label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label | |
09d92015 | 5534 | |
c19d1205 | 5535 | It is the caller's responsibility to check for addressing modes not |
e2b0ab59 | 5536 | supported by the instruction, and to set inst.relocs[0].type. */ |
c19d1205 | 5537 | |
4962c51a MS |
5538 | static parse_operand_result |
5539 | parse_address_main (char **str, int i, int group_relocations, | |
477330fc | 5540 | group_reloc_type group_type) |
09d92015 | 5541 | { |
c19d1205 ZW |
5542 | char *p = *str; |
5543 | int reg; | |
09d92015 | 5544 | |
c19d1205 | 5545 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5546 | { |
c19d1205 ZW |
5547 | if (skip_past_char (&p, '=') == FAIL) |
5548 | { | |
974da60d | 5549 | /* Bare address - translate to PC-relative offset. */ |
e2b0ab59 | 5550 | inst.relocs[0].pc_rel = 1; |
c19d1205 ZW |
5551 | inst.operands[i].reg = REG_PC; |
5552 | inst.operands[i].isreg = 1; | |
5553 | inst.operands[i].preind = 1; | |
09d92015 | 5554 | |
e2b0ab59 | 5555 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG)) |
8335d6aa JW |
5556 | return PARSE_OPERAND_FAIL; |
5557 | } | |
e2b0ab59 | 5558 | else if (parse_big_immediate (&p, i, &inst.relocs[0].exp, |
8335d6aa | 5559 | /*allow_symbol_p=*/TRUE)) |
4962c51a | 5560 | return PARSE_OPERAND_FAIL; |
09d92015 | 5561 | |
c19d1205 | 5562 | *str = p; |
4962c51a | 5563 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5564 | } |
5565 | ||
8ab8155f NC |
5566 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5567 | skip_whitespace (p); | |
5568 | ||
dcbf9037 | 5569 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 5570 | { |
c19d1205 | 5571 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 5572 | return PARSE_OPERAND_FAIL; |
09d92015 | 5573 | } |
c19d1205 ZW |
5574 | inst.operands[i].reg = reg; |
5575 | inst.operands[i].isreg = 1; | |
09d92015 | 5576 | |
c19d1205 | 5577 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5578 | { |
c19d1205 | 5579 | inst.operands[i].preind = 1; |
09d92015 | 5580 | |
c19d1205 ZW |
5581 | if (*p == '+') p++; |
5582 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5583 | ||
dcbf9037 | 5584 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5585 | { |
c19d1205 ZW |
5586 | inst.operands[i].imm = reg; |
5587 | inst.operands[i].immisreg = 1; | |
5588 | ||
5589 | if (skip_past_comma (&p) == SUCCESS) | |
5590 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5591 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5592 | } |
5287ad62 | 5593 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5594 | { |
5595 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5596 | code before we get to see it here. This may be subject to | |
5597 | change. */ | |
5598 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5599 | |
8e560766 MGD |
5600 | if (result != PARSE_OPERAND_SUCCESS) |
5601 | return result; | |
5602 | } | |
c19d1205 ZW |
5603 | else |
5604 | { | |
5605 | if (inst.operands[i].negative) | |
5606 | { | |
5607 | inst.operands[i].negative = 0; | |
5608 | p--; | |
5609 | } | |
4962c51a | 5610 | |
5f4273c7 NC |
5611 | if (group_relocations |
5612 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5613 | { |
5614 | struct group_reloc_table_entry *entry; | |
5615 | ||
477330fc RM |
5616 | /* Skip over the #: or : sequence. */ |
5617 | if (*p == '#') | |
5618 | p += 2; | |
5619 | else | |
5620 | p++; | |
4962c51a MS |
5621 | |
5622 | /* Try to parse a group relocation. Anything else is an | |
477330fc | 5623 | error. */ |
4962c51a MS |
5624 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) |
5625 | { | |
5626 | inst.error = _("unknown group relocation"); | |
5627 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5628 | } | |
5629 | ||
5630 | /* We now have the group relocation table entry corresponding to | |
5631 | the name in the assembler source. Next, we parse the | |
477330fc | 5632 | expression. */ |
e2b0ab59 | 5633 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
4962c51a MS |
5634 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
5635 | ||
5636 | /* Record the relocation type. */ | |
477330fc RM |
5637 | switch (group_type) |
5638 | { | |
5639 | case GROUP_LDR: | |
e2b0ab59 AV |
5640 | inst.relocs[0].type |
5641 | = (bfd_reloc_code_real_type) entry->ldr_code; | |
477330fc | 5642 | break; |
4962c51a | 5643 | |
477330fc | 5644 | case GROUP_LDRS: |
e2b0ab59 AV |
5645 | inst.relocs[0].type |
5646 | = (bfd_reloc_code_real_type) entry->ldrs_code; | |
477330fc | 5647 | break; |
4962c51a | 5648 | |
477330fc | 5649 | case GROUP_LDC: |
e2b0ab59 AV |
5650 | inst.relocs[0].type |
5651 | = (bfd_reloc_code_real_type) entry->ldc_code; | |
477330fc | 5652 | break; |
4962c51a | 5653 | |
477330fc RM |
5654 | default: |
5655 | gas_assert (0); | |
5656 | } | |
4962c51a | 5657 | |
e2b0ab59 | 5658 | if (inst.relocs[0].type == 0) |
4962c51a MS |
5659 | { |
5660 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5661 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5662 | } | |
477330fc RM |
5663 | } |
5664 | else | |
26d97720 NS |
5665 | { |
5666 | char *q = p; | |
0198d5e6 | 5667 | |
e2b0ab59 | 5668 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
26d97720 NS |
5669 | return PARSE_OPERAND_FAIL; |
5670 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
e2b0ab59 AV |
5671 | if (inst.relocs[0].exp.X_op == O_constant |
5672 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
5673 | { |
5674 | skip_whitespace (q); | |
5675 | if (*q == '#') | |
5676 | { | |
5677 | q++; | |
5678 | skip_whitespace (q); | |
5679 | } | |
5680 | if (*q == '-') | |
5681 | inst.operands[i].negative = 1; | |
5682 | } | |
5683 | } | |
09d92015 MM |
5684 | } |
5685 | } | |
8e560766 MGD |
5686 | else if (skip_past_char (&p, ':') == SUCCESS) |
5687 | { | |
5688 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
5689 | before we get to see it here. This may be subject to change. */ | |
5690 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5691 | |
8e560766 MGD |
5692 | if (result != PARSE_OPERAND_SUCCESS) |
5693 | return result; | |
5694 | } | |
09d92015 | 5695 | |
c19d1205 | 5696 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5697 | { |
c19d1205 | 5698 | inst.error = _("']' expected"); |
4962c51a | 5699 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5700 | } |
5701 | ||
c19d1205 ZW |
5702 | if (skip_past_char (&p, '!') == SUCCESS) |
5703 | inst.operands[i].writeback = 1; | |
09d92015 | 5704 | |
c19d1205 | 5705 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5706 | { |
c19d1205 ZW |
5707 | if (skip_past_char (&p, '{') == SUCCESS) |
5708 | { | |
5709 | /* [Rn], {expr} - unindexed, with option */ | |
5710 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5711 | 0, 255, TRUE) == FAIL) |
4962c51a | 5712 | return PARSE_OPERAND_FAIL; |
09d92015 | 5713 | |
c19d1205 ZW |
5714 | if (skip_past_char (&p, '}') == FAIL) |
5715 | { | |
5716 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5717 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5718 | } |
5719 | if (inst.operands[i].preind) | |
5720 | { | |
5721 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5722 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5723 | } |
5724 | *str = p; | |
4962c51a | 5725 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5726 | } |
c19d1205 ZW |
5727 | else |
5728 | { | |
5729 | inst.operands[i].postind = 1; | |
5730 | inst.operands[i].writeback = 1; | |
09d92015 | 5731 | |
c19d1205 ZW |
5732 | if (inst.operands[i].preind) |
5733 | { | |
5734 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5735 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5736 | } |
09d92015 | 5737 | |
c19d1205 ZW |
5738 | if (*p == '+') p++; |
5739 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5740 | |
dcbf9037 | 5741 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5742 | { |
477330fc RM |
5743 | /* We might be using the immediate for alignment already. If we |
5744 | are, OR the register number into the low-order bits. */ | |
5745 | if (inst.operands[i].immisalign) | |
5746 | inst.operands[i].imm |= reg; | |
5747 | else | |
5748 | inst.operands[i].imm = reg; | |
c19d1205 | 5749 | inst.operands[i].immisreg = 1; |
a737bd4d | 5750 | |
c19d1205 ZW |
5751 | if (skip_past_comma (&p) == SUCCESS) |
5752 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5753 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5754 | } |
5755 | else | |
5756 | { | |
26d97720 | 5757 | char *q = p; |
0198d5e6 | 5758 | |
c19d1205 ZW |
5759 | if (inst.operands[i].negative) |
5760 | { | |
5761 | inst.operands[i].negative = 0; | |
5762 | p--; | |
5763 | } | |
e2b0ab59 | 5764 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX)) |
4962c51a | 5765 | return PARSE_OPERAND_FAIL; |
26d97720 | 5766 | /* If the offset is 0, find out if it's a +0 or -0. */ |
e2b0ab59 AV |
5767 | if (inst.relocs[0].exp.X_op == O_constant |
5768 | && inst.relocs[0].exp.X_add_number == 0) | |
26d97720 NS |
5769 | { |
5770 | skip_whitespace (q); | |
5771 | if (*q == '#') | |
5772 | { | |
5773 | q++; | |
5774 | skip_whitespace (q); | |
5775 | } | |
5776 | if (*q == '-') | |
5777 | inst.operands[i].negative = 1; | |
5778 | } | |
c19d1205 ZW |
5779 | } |
5780 | } | |
a737bd4d NC |
5781 | } |
5782 | ||
c19d1205 ZW |
5783 | /* If at this point neither .preind nor .postind is set, we have a |
5784 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5785 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5786 | { | |
5787 | inst.operands[i].preind = 1; | |
e2b0ab59 AV |
5788 | inst.relocs[0].exp.X_op = O_constant; |
5789 | inst.relocs[0].exp.X_add_number = 0; | |
c19d1205 ZW |
5790 | } |
5791 | *str = p; | |
4962c51a MS |
5792 | return PARSE_OPERAND_SUCCESS; |
5793 | } | |
5794 | ||
5795 | static int | |
5796 | parse_address (char **str, int i) | |
5797 | { | |
21d799b5 | 5798 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
477330fc | 5799 | ? SUCCESS : FAIL; |
4962c51a MS |
5800 | } |
5801 | ||
5802 | static parse_operand_result | |
5803 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5804 | { | |
5805 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5806 | } |
5807 | ||
b6895b4f PB |
5808 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5809 | static int | |
5810 | parse_half (char **str) | |
5811 | { | |
5812 | char * p; | |
5f4273c7 | 5813 | |
b6895b4f PB |
5814 | p = *str; |
5815 | skip_past_char (&p, '#'); | |
5f4273c7 | 5816 | if (strncasecmp (p, ":lower16:", 9) == 0) |
e2b0ab59 | 5817 | inst.relocs[0].type = BFD_RELOC_ARM_MOVW; |
b6895b4f | 5818 | else if (strncasecmp (p, ":upper16:", 9) == 0) |
e2b0ab59 | 5819 | inst.relocs[0].type = BFD_RELOC_ARM_MOVT; |
b6895b4f | 5820 | |
e2b0ab59 | 5821 | if (inst.relocs[0].type != BFD_RELOC_UNUSED) |
b6895b4f PB |
5822 | { |
5823 | p += 9; | |
5f4273c7 | 5824 | skip_whitespace (p); |
b6895b4f PB |
5825 | } |
5826 | ||
e2b0ab59 | 5827 | if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX)) |
b6895b4f PB |
5828 | return FAIL; |
5829 | ||
e2b0ab59 | 5830 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 5831 | { |
e2b0ab59 | 5832 | if (inst.relocs[0].exp.X_op != O_constant) |
b6895b4f PB |
5833 | { |
5834 | inst.error = _("constant expression expected"); | |
5835 | return FAIL; | |
5836 | } | |
e2b0ab59 AV |
5837 | if (inst.relocs[0].exp.X_add_number < 0 |
5838 | || inst.relocs[0].exp.X_add_number > 0xffff) | |
b6895b4f PB |
5839 | { |
5840 | inst.error = _("immediate value out of range"); | |
5841 | return FAIL; | |
5842 | } | |
5843 | } | |
5844 | *str = p; | |
5845 | return SUCCESS; | |
5846 | } | |
5847 | ||
c19d1205 | 5848 | /* Miscellaneous. */ |
a737bd4d | 5849 | |
c19d1205 ZW |
5850 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5851 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5852 | static int | |
d2cd1205 | 5853 | parse_psr (char **str, bfd_boolean lhs) |
09d92015 | 5854 | { |
c19d1205 ZW |
5855 | char *p; |
5856 | unsigned long psr_field; | |
62b3e311 PB |
5857 | const struct asm_psr *psr; |
5858 | char *start; | |
d2cd1205 | 5859 | bfd_boolean is_apsr = FALSE; |
ac7f631b | 5860 | bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); |
09d92015 | 5861 | |
a4482bb6 NC |
5862 | /* PR gas/12698: If the user has specified -march=all then m_profile will |
5863 | be TRUE, but we want to ignore it in this case as we are building for any | |
5864 | CPU type, including non-m variants. */ | |
823d2571 | 5865 | if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) |
a4482bb6 NC |
5866 | m_profile = FALSE; |
5867 | ||
c19d1205 ZW |
5868 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5869 | feature for ease of use and backwards compatibility. */ | |
5870 | p = *str; | |
62b3e311 | 5871 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
5872 | { |
5873 | if (m_profile) | |
5874 | goto unsupported_psr; | |
fa94de6b | 5875 | |
d2cd1205 JB |
5876 | psr_field = SPSR_BIT; |
5877 | } | |
5878 | else if (strncasecmp (p, "CPSR", 4) == 0) | |
5879 | { | |
5880 | if (m_profile) | |
5881 | goto unsupported_psr; | |
5882 | ||
5883 | psr_field = 0; | |
5884 | } | |
5885 | else if (strncasecmp (p, "APSR", 4) == 0) | |
5886 | { | |
5887 | /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A | |
5888 | and ARMv7-R architecture CPUs. */ | |
5889 | is_apsr = TRUE; | |
5890 | psr_field = 0; | |
5891 | } | |
5892 | else if (m_profile) | |
62b3e311 PB |
5893 | { |
5894 | start = p; | |
5895 | do | |
5896 | p++; | |
5897 | while (ISALNUM (*p) || *p == '_'); | |
5898 | ||
d2cd1205 JB |
5899 | if (strncasecmp (start, "iapsr", 5) == 0 |
5900 | || strncasecmp (start, "eapsr", 5) == 0 | |
5901 | || strncasecmp (start, "xpsr", 4) == 0 | |
5902 | || strncasecmp (start, "psr", 3) == 0) | |
5903 | p = start + strcspn (start, "rR") + 1; | |
5904 | ||
21d799b5 | 5905 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
477330fc | 5906 | p - start); |
d2cd1205 | 5907 | |
62b3e311 PB |
5908 | if (!psr) |
5909 | return FAIL; | |
09d92015 | 5910 | |
d2cd1205 JB |
5911 | /* If APSR is being written, a bitfield may be specified. Note that |
5912 | APSR itself is handled above. */ | |
5913 | if (psr->field <= 3) | |
5914 | { | |
5915 | psr_field = psr->field; | |
5916 | is_apsr = TRUE; | |
5917 | goto check_suffix; | |
5918 | } | |
5919 | ||
62b3e311 | 5920 | *str = p; |
d2cd1205 JB |
5921 | /* M-profile MSR instructions have the mask field set to "10", except |
5922 | *PSR variants which modify APSR, which may use a different mask (and | |
5923 | have been handled already). Do that by setting the PSR_f field | |
5924 | here. */ | |
5925 | return psr->field | (lhs ? PSR_f : 0); | |
62b3e311 | 5926 | } |
d2cd1205 JB |
5927 | else |
5928 | goto unsupported_psr; | |
09d92015 | 5929 | |
62b3e311 | 5930 | p += 4; |
d2cd1205 | 5931 | check_suffix: |
c19d1205 ZW |
5932 | if (*p == '_') |
5933 | { | |
5934 | /* A suffix follows. */ | |
c19d1205 ZW |
5935 | p++; |
5936 | start = p; | |
a737bd4d | 5937 | |
c19d1205 ZW |
5938 | do |
5939 | p++; | |
5940 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5941 | |
d2cd1205 JB |
5942 | if (is_apsr) |
5943 | { | |
5944 | /* APSR uses a notation for bits, rather than fields. */ | |
5945 | unsigned int nzcvq_bits = 0; | |
5946 | unsigned int g_bit = 0; | |
5947 | char *bit; | |
fa94de6b | 5948 | |
d2cd1205 JB |
5949 | for (bit = start; bit != p; bit++) |
5950 | { | |
5951 | switch (TOLOWER (*bit)) | |
477330fc | 5952 | { |
d2cd1205 JB |
5953 | case 'n': |
5954 | nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01; | |
5955 | break; | |
5956 | ||
5957 | case 'z': | |
5958 | nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02; | |
5959 | break; | |
5960 | ||
5961 | case 'c': | |
5962 | nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04; | |
5963 | break; | |
5964 | ||
5965 | case 'v': | |
5966 | nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08; | |
5967 | break; | |
fa94de6b | 5968 | |
d2cd1205 JB |
5969 | case 'q': |
5970 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
5971 | break; | |
fa94de6b | 5972 | |
d2cd1205 JB |
5973 | case 'g': |
5974 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
5975 | break; | |
fa94de6b | 5976 | |
d2cd1205 JB |
5977 | default: |
5978 | inst.error = _("unexpected bit specified after APSR"); | |
5979 | return FAIL; | |
5980 | } | |
5981 | } | |
fa94de6b | 5982 | |
d2cd1205 JB |
5983 | if (nzcvq_bits == 0x1f) |
5984 | psr_field |= PSR_f; | |
fa94de6b | 5985 | |
d2cd1205 JB |
5986 | if (g_bit == 0x1) |
5987 | { | |
5988 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
477330fc | 5989 | { |
d2cd1205 JB |
5990 | inst.error = _("selected processor does not " |
5991 | "support DSP extension"); | |
5992 | return FAIL; | |
5993 | } | |
5994 | ||
5995 | psr_field |= PSR_s; | |
5996 | } | |
fa94de6b | 5997 | |
d2cd1205 JB |
5998 | if ((nzcvq_bits & 0x20) != 0 |
5999 | || (nzcvq_bits != 0x1f && nzcvq_bits != 0) | |
6000 | || (g_bit & 0x2) != 0) | |
6001 | { | |
6002 | inst.error = _("bad bitmask specified after APSR"); | |
6003 | return FAIL; | |
6004 | } | |
6005 | } | |
6006 | else | |
477330fc | 6007 | { |
d2cd1205 | 6008 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
477330fc | 6009 | p - start); |
d2cd1205 | 6010 | if (!psr) |
477330fc | 6011 | goto error; |
a737bd4d | 6012 | |
d2cd1205 JB |
6013 | psr_field |= psr->field; |
6014 | } | |
a737bd4d | 6015 | } |
c19d1205 | 6016 | else |
a737bd4d | 6017 | { |
c19d1205 ZW |
6018 | if (ISALNUM (*p)) |
6019 | goto error; /* Garbage after "[CS]PSR". */ | |
6020 | ||
d2cd1205 | 6021 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
477330fc | 6022 | is deprecated, but allow it anyway. */ |
d2cd1205 JB |
6023 | if (is_apsr && lhs) |
6024 | { | |
6025 | psr_field |= PSR_f; | |
6026 | as_tsktsk (_("writing to APSR without specifying a bitmask is " | |
6027 | "deprecated")); | |
6028 | } | |
6029 | else if (!m_profile) | |
6030 | /* These bits are never right for M-profile devices: don't set them | |
6031 | (only code paths which read/write APSR reach here). */ | |
6032 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 6033 | } |
c19d1205 ZW |
6034 | *str = p; |
6035 | return psr_field; | |
a737bd4d | 6036 | |
d2cd1205 JB |
6037 | unsupported_psr: |
6038 | inst.error = _("selected processor does not support requested special " | |
6039 | "purpose register"); | |
6040 | return FAIL; | |
6041 | ||
c19d1205 ZW |
6042 | error: |
6043 | inst.error = _("flag for {c}psr instruction expected"); | |
6044 | return FAIL; | |
a737bd4d NC |
6045 | } |
6046 | ||
c19d1205 ZW |
6047 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
6048 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 6049 | |
c19d1205 ZW |
6050 | static int |
6051 | parse_cps_flags (char **str) | |
a737bd4d | 6052 | { |
c19d1205 ZW |
6053 | int val = 0; |
6054 | int saw_a_flag = 0; | |
6055 | char *s = *str; | |
a737bd4d | 6056 | |
c19d1205 ZW |
6057 | for (;;) |
6058 | switch (*s++) | |
6059 | { | |
6060 | case '\0': case ',': | |
6061 | goto done; | |
a737bd4d | 6062 | |
c19d1205 ZW |
6063 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
6064 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
6065 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 6066 | |
c19d1205 ZW |
6067 | default: |
6068 | inst.error = _("unrecognized CPS flag"); | |
6069 | return FAIL; | |
6070 | } | |
a737bd4d | 6071 | |
c19d1205 ZW |
6072 | done: |
6073 | if (saw_a_flag == 0) | |
a737bd4d | 6074 | { |
c19d1205 ZW |
6075 | inst.error = _("missing CPS flags"); |
6076 | return FAIL; | |
a737bd4d | 6077 | } |
a737bd4d | 6078 | |
c19d1205 ZW |
6079 | *str = s - 1; |
6080 | return val; | |
a737bd4d NC |
6081 | } |
6082 | ||
c19d1205 ZW |
6083 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
6084 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
6085 | |
6086 | static int | |
c19d1205 | 6087 | parse_endian_specifier (char **str) |
a737bd4d | 6088 | { |
c19d1205 ZW |
6089 | int little_endian; |
6090 | char *s = *str; | |
a737bd4d | 6091 | |
c19d1205 ZW |
6092 | if (strncasecmp (s, "BE", 2)) |
6093 | little_endian = 0; | |
6094 | else if (strncasecmp (s, "LE", 2)) | |
6095 | little_endian = 1; | |
6096 | else | |
a737bd4d | 6097 | { |
c19d1205 | 6098 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6099 | return FAIL; |
6100 | } | |
6101 | ||
c19d1205 | 6102 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 6103 | { |
c19d1205 | 6104 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6105 | return FAIL; |
6106 | } | |
6107 | ||
c19d1205 ZW |
6108 | *str = s + 2; |
6109 | return little_endian; | |
6110 | } | |
a737bd4d | 6111 | |
c19d1205 ZW |
6112 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
6113 | value suitable for poking into the rotate field of an sxt or sxta | |
6114 | instruction, or FAIL on error. */ | |
6115 | ||
6116 | static int | |
6117 | parse_ror (char **str) | |
6118 | { | |
6119 | int rot; | |
6120 | char *s = *str; | |
6121 | ||
6122 | if (strncasecmp (s, "ROR", 3) == 0) | |
6123 | s += 3; | |
6124 | else | |
a737bd4d | 6125 | { |
c19d1205 | 6126 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
6127 | return FAIL; |
6128 | } | |
c19d1205 ZW |
6129 | |
6130 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
6131 | return FAIL; | |
6132 | ||
6133 | switch (rot) | |
a737bd4d | 6134 | { |
c19d1205 ZW |
6135 | case 0: *str = s; return 0x0; |
6136 | case 8: *str = s; return 0x1; | |
6137 | case 16: *str = s; return 0x2; | |
6138 | case 24: *str = s; return 0x3; | |
6139 | ||
6140 | default: | |
6141 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
6142 | return FAIL; |
6143 | } | |
c19d1205 | 6144 | } |
a737bd4d | 6145 | |
c19d1205 ZW |
6146 | /* Parse a conditional code (from conds[] below). The value returned is in the |
6147 | range 0 .. 14, or FAIL. */ | |
6148 | static int | |
6149 | parse_cond (char **str) | |
6150 | { | |
c462b453 | 6151 | char *q; |
c19d1205 | 6152 | const struct asm_cond *c; |
c462b453 PB |
6153 | int n; |
6154 | /* Condition codes are always 2 characters, so matching up to | |
6155 | 3 characters is sufficient. */ | |
6156 | char cond[3]; | |
a737bd4d | 6157 | |
c462b453 PB |
6158 | q = *str; |
6159 | n = 0; | |
6160 | while (ISALPHA (*q) && n < 3) | |
6161 | { | |
e07e6e58 | 6162 | cond[n] = TOLOWER (*q); |
c462b453 PB |
6163 | q++; |
6164 | n++; | |
6165 | } | |
a737bd4d | 6166 | |
21d799b5 | 6167 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 6168 | if (!c) |
a737bd4d | 6169 | { |
c19d1205 | 6170 | inst.error = _("condition required"); |
a737bd4d NC |
6171 | return FAIL; |
6172 | } | |
6173 | ||
c19d1205 ZW |
6174 | *str = q; |
6175 | return c->value; | |
6176 | } | |
6177 | ||
643afb90 MW |
6178 | /* Record a use of the given feature. */ |
6179 | static void | |
6180 | record_feature_use (const arm_feature_set *feature) | |
6181 | { | |
6182 | if (thumb_mode) | |
6183 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature); | |
6184 | else | |
6185 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature); | |
6186 | } | |
6187 | ||
4d354d8b TP |
6188 | /* If the given feature is currently allowed, mark it as used and return TRUE. |
6189 | Return FALSE otherwise. */ | |
e797f7e0 MGD |
6190 | static bfd_boolean |
6191 | mark_feature_used (const arm_feature_set *feature) | |
6192 | { | |
4d354d8b | 6193 | /* Ensure the option is currently allowed. */ |
e797f7e0 MGD |
6194 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) |
6195 | return FALSE; | |
6196 | ||
4d354d8b | 6197 | /* Add the appropriate architecture feature for the barrier option used. */ |
643afb90 | 6198 | record_feature_use (feature); |
e797f7e0 MGD |
6199 | |
6200 | return TRUE; | |
6201 | } | |
6202 | ||
62b3e311 PB |
6203 | /* Parse an option for a barrier instruction. Returns the encoding for the |
6204 | option, or FAIL. */ | |
6205 | static int | |
6206 | parse_barrier (char **str) | |
6207 | { | |
6208 | char *p, *q; | |
6209 | const struct asm_barrier_opt *o; | |
6210 | ||
6211 | p = q = *str; | |
6212 | while (ISALPHA (*q)) | |
6213 | q++; | |
6214 | ||
21d799b5 | 6215 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
477330fc | 6216 | q - p); |
62b3e311 PB |
6217 | if (!o) |
6218 | return FAIL; | |
6219 | ||
e797f7e0 MGD |
6220 | if (!mark_feature_used (&o->arch)) |
6221 | return FAIL; | |
6222 | ||
62b3e311 PB |
6223 | *str = q; |
6224 | return o->value; | |
6225 | } | |
6226 | ||
92e90b6e PB |
6227 | /* Parse the operands of a table branch instruction. Similar to a memory |
6228 | operand. */ | |
6229 | static int | |
6230 | parse_tb (char **str) | |
6231 | { | |
6232 | char * p = *str; | |
6233 | int reg; | |
6234 | ||
6235 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
6236 | { |
6237 | inst.error = _("'[' expected"); | |
6238 | return FAIL; | |
6239 | } | |
92e90b6e | 6240 | |
dcbf9037 | 6241 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6242 | { |
6243 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6244 | return FAIL; | |
6245 | } | |
6246 | inst.operands[0].reg = reg; | |
6247 | ||
6248 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
6249 | { |
6250 | inst.error = _("',' expected"); | |
6251 | return FAIL; | |
6252 | } | |
5f4273c7 | 6253 | |
dcbf9037 | 6254 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6255 | { |
6256 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6257 | return FAIL; | |
6258 | } | |
6259 | inst.operands[0].imm = reg; | |
6260 | ||
6261 | if (skip_past_comma (&p) == SUCCESS) | |
6262 | { | |
6263 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
6264 | return FAIL; | |
e2b0ab59 | 6265 | if (inst.relocs[0].exp.X_add_number != 1) |
92e90b6e PB |
6266 | { |
6267 | inst.error = _("invalid shift"); | |
6268 | return FAIL; | |
6269 | } | |
6270 | inst.operands[0].shifted = 1; | |
6271 | } | |
6272 | ||
6273 | if (skip_past_char (&p, ']') == FAIL) | |
6274 | { | |
6275 | inst.error = _("']' expected"); | |
6276 | return FAIL; | |
6277 | } | |
6278 | *str = p; | |
6279 | return SUCCESS; | |
6280 | } | |
6281 | ||
5287ad62 JB |
6282 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
6283 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
6284 | Up to four operands may be read; this function handles setting the |
6285 | ".present" field for each read operand itself. | |
5287ad62 JB |
6286 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
6287 | else returns FAIL. */ | |
6288 | ||
6289 | static int | |
6290 | parse_neon_mov (char **str, int *which_operand) | |
6291 | { | |
6292 | int i = *which_operand, val; | |
6293 | enum arm_reg_type rtype; | |
6294 | char *ptr = *str; | |
dcbf9037 | 6295 | struct neon_type_el optype; |
5f4273c7 | 6296 | |
dcbf9037 | 6297 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
6298 | { |
6299 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
6300 | inst.operands[i].reg = val; | |
6301 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 6302 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6303 | inst.operands[i++].present = 1; |
6304 | ||
6305 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6306 | goto wanted_comma; |
5f4273c7 | 6307 | |
dcbf9037 | 6308 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
477330fc | 6309 | goto wanted_arm; |
5f4273c7 | 6310 | |
5287ad62 JB |
6311 | inst.operands[i].reg = val; |
6312 | inst.operands[i].isreg = 1; | |
6313 | inst.operands[i].present = 1; | |
6314 | } | |
037e8744 | 6315 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
477330fc | 6316 | != FAIL) |
5287ad62 JB |
6317 | { |
6318 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
6319 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6320 | goto wanted_comma; |
5f4273c7 | 6321 | |
5287ad62 JB |
6322 | inst.operands[i].reg = val; |
6323 | inst.operands[i].isreg = 1; | |
6324 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
6325 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
6326 | inst.operands[i].isvec = 1; | |
dcbf9037 | 6327 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6328 | inst.operands[i++].present = 1; |
6329 | ||
dcbf9037 | 6330 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6331 | { |
6332 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. | |
6333 | Case 13: VMOV <Sd>, <Rm> */ | |
6334 | inst.operands[i].reg = val; | |
6335 | inst.operands[i].isreg = 1; | |
6336 | inst.operands[i].present = 1; | |
6337 | ||
6338 | if (rtype == REG_TYPE_NQ) | |
6339 | { | |
6340 | first_error (_("can't use Neon quad register here")); | |
6341 | return FAIL; | |
6342 | } | |
6343 | else if (rtype != REG_TYPE_VFS) | |
6344 | { | |
6345 | i++; | |
6346 | if (skip_past_comma (&ptr) == FAIL) | |
6347 | goto wanted_comma; | |
6348 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6349 | goto wanted_arm; | |
6350 | inst.operands[i].reg = val; | |
6351 | inst.operands[i].isreg = 1; | |
6352 | inst.operands[i].present = 1; | |
6353 | } | |
6354 | } | |
037e8744 | 6355 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
477330fc RM |
6356 | &optype)) != FAIL) |
6357 | { | |
6358 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
6359 | Case 1: VMOV<c><q> <Dd>, <Dm> | |
6360 | Case 8: VMOV.F32 <Sd>, <Sm> | |
6361 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
6362 | ||
6363 | inst.operands[i].reg = val; | |
6364 | inst.operands[i].isreg = 1; | |
6365 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
6366 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6367 | inst.operands[i].isvec = 1; | |
6368 | inst.operands[i].vectype = optype; | |
6369 | inst.operands[i].present = 1; | |
6370 | ||
6371 | if (skip_past_comma (&ptr) == SUCCESS) | |
6372 | { | |
6373 | /* Case 15. */ | |
6374 | i++; | |
6375 | ||
6376 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6377 | goto wanted_arm; | |
6378 | ||
6379 | inst.operands[i].reg = val; | |
6380 | inst.operands[i].isreg = 1; | |
6381 | inst.operands[i++].present = 1; | |
6382 | ||
6383 | if (skip_past_comma (&ptr) == FAIL) | |
6384 | goto wanted_comma; | |
6385 | ||
6386 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6387 | goto wanted_arm; | |
6388 | ||
6389 | inst.operands[i].reg = val; | |
6390 | inst.operands[i].isreg = 1; | |
6391 | inst.operands[i].present = 1; | |
6392 | } | |
6393 | } | |
4641781c | 6394 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
477330fc RM |
6395 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
6396 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
6397 | Case 10: VMOV.F32 <Sd>, #<imm> | |
6398 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
6399 | inst.operands[i].immisfloat = 1; | |
8335d6aa JW |
6400 | else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE) |
6401 | == SUCCESS) | |
477330fc RM |
6402 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
6403 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
6404 | ; | |
5287ad62 | 6405 | else |
477330fc RM |
6406 | { |
6407 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); | |
6408 | return FAIL; | |
6409 | } | |
5287ad62 | 6410 | } |
dcbf9037 | 6411 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
6412 | { |
6413 | /* Cases 6, 7. */ | |
6414 | inst.operands[i].reg = val; | |
6415 | inst.operands[i].isreg = 1; | |
6416 | inst.operands[i++].present = 1; | |
5f4273c7 | 6417 | |
5287ad62 | 6418 | if (skip_past_comma (&ptr) == FAIL) |
477330fc | 6419 | goto wanted_comma; |
5f4273c7 | 6420 | |
dcbf9037 | 6421 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
477330fc RM |
6422 | { |
6423 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
6424 | inst.operands[i].reg = val; | |
6425 | inst.operands[i].isscalar = 1; | |
6426 | inst.operands[i].present = 1; | |
6427 | inst.operands[i].vectype = optype; | |
6428 | } | |
dcbf9037 | 6429 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6430 | { |
6431 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
6432 | inst.operands[i].reg = val; | |
6433 | inst.operands[i].isreg = 1; | |
6434 | inst.operands[i++].present = 1; | |
6435 | ||
6436 | if (skip_past_comma (&ptr) == FAIL) | |
6437 | goto wanted_comma; | |
6438 | ||
6439 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) | |
6440 | == FAIL) | |
6441 | { | |
6442 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); | |
6443 | return FAIL; | |
6444 | } | |
6445 | ||
6446 | inst.operands[i].reg = val; | |
6447 | inst.operands[i].isreg = 1; | |
6448 | inst.operands[i].isvec = 1; | |
6449 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6450 | inst.operands[i].vectype = optype; | |
6451 | inst.operands[i].present = 1; | |
6452 | ||
6453 | if (rtype == REG_TYPE_VFS) | |
6454 | { | |
6455 | /* Case 14. */ | |
6456 | i++; | |
6457 | if (skip_past_comma (&ptr) == FAIL) | |
6458 | goto wanted_comma; | |
6459 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
6460 | &optype)) == FAIL) | |
6461 | { | |
6462 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
6463 | return FAIL; | |
6464 | } | |
6465 | inst.operands[i].reg = val; | |
6466 | inst.operands[i].isreg = 1; | |
6467 | inst.operands[i].isvec = 1; | |
6468 | inst.operands[i].issingle = 1; | |
6469 | inst.operands[i].vectype = optype; | |
6470 | inst.operands[i].present = 1; | |
6471 | } | |
6472 | } | |
037e8744 | 6473 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) |
477330fc RM |
6474 | != FAIL) |
6475 | { | |
6476 | /* Case 13. */ | |
6477 | inst.operands[i].reg = val; | |
6478 | inst.operands[i].isreg = 1; | |
6479 | inst.operands[i].isvec = 1; | |
6480 | inst.operands[i].issingle = 1; | |
6481 | inst.operands[i].vectype = optype; | |
6482 | inst.operands[i].present = 1; | |
6483 | } | |
5287ad62 JB |
6484 | } |
6485 | else | |
6486 | { | |
dcbf9037 | 6487 | first_error (_("parse error")); |
5287ad62 JB |
6488 | return FAIL; |
6489 | } | |
6490 | ||
6491 | /* Successfully parsed the operands. Update args. */ | |
6492 | *which_operand = i; | |
6493 | *str = ptr; | |
6494 | return SUCCESS; | |
6495 | ||
5f4273c7 | 6496 | wanted_comma: |
dcbf9037 | 6497 | first_error (_("expected comma")); |
5287ad62 | 6498 | return FAIL; |
5f4273c7 NC |
6499 | |
6500 | wanted_arm: | |
dcbf9037 | 6501 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 6502 | return FAIL; |
5287ad62 JB |
6503 | } |
6504 | ||
5be8be5d DG |
6505 | /* Use this macro when the operand constraints are different |
6506 | for ARM and THUMB (e.g. ldrd). */ | |
6507 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
6508 | ((arm_operand) | ((thumb_operand) << 16)) | |
6509 | ||
c19d1205 ZW |
6510 | /* Matcher codes for parse_operands. */ |
6511 | enum operand_parse_code | |
6512 | { | |
6513 | OP_stop, /* end of line */ | |
6514 | ||
6515 | OP_RR, /* ARM register */ | |
6516 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 6517 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 6518 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 6519 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 6520 | optional trailing ! */ |
c19d1205 ZW |
6521 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
6522 | OP_RCP, /* Coprocessor number */ | |
6523 | OP_RCN, /* Coprocessor register */ | |
6524 | OP_RF, /* FPA register */ | |
6525 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
6526 | OP_RVD, /* VFP double precision register (0..15) */ |
6527 | OP_RND, /* Neon double precision register (0..31) */ | |
6528 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 6529 | OP_RVSD, /* VFP single or double precision register */ |
dec41383 | 6530 | OP_RNSD, /* Neon single or double precision register */ |
5287ad62 | 6531 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 6532 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 6533 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
6534 | OP_RVC, /* VFP control register */ |
6535 | OP_RMF, /* Maverick F register */ | |
6536 | OP_RMD, /* Maverick D register */ | |
6537 | OP_RMFX, /* Maverick FX register */ | |
6538 | OP_RMDX, /* Maverick DX register */ | |
6539 | OP_RMAX, /* Maverick AX register */ | |
6540 | OP_RMDS, /* Maverick DSPSC register */ | |
6541 | OP_RIWR, /* iWMMXt wR register */ | |
6542 | OP_RIWC, /* iWMMXt wC register */ | |
6543 | OP_RIWG, /* iWMMXt wCG register */ | |
6544 | OP_RXA, /* XScale accumulator register */ | |
6545 | ||
6546 | OP_REGLST, /* ARM register list */ | |
6547 | OP_VRSLST, /* VFP single-precision register list */ | |
6548 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 6549 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
6550 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
6551 | OP_NSTRLST, /* Neon element/structure list */ | |
6552 | ||
5287ad62 | 6553 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 6554 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
aacf0b33 | 6555 | OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */ |
5287ad62 | 6556 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
dec41383 | 6557 | OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */ |
037e8744 | 6558 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
6559 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
6560 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
6561 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 6562 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
5287ad62 | 6563 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
2d447fca | 6564 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
6565 | |
6566 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
6567 | OP_I7, /* immediate value 0 .. 7 */ |
6568 | OP_I15, /* 0 .. 15 */ | |
6569 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 6570 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
6571 | OP_I31, /* 0 .. 31 */ |
6572 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
6573 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
6574 | OP_I32z, /* 0 .. 32 */ |
6575 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 6576 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
6577 | OP_I64, /* 1 .. 64 */ |
6578 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 6579 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
6580 | |
6581 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
6582 | OP_I7b, /* 0 .. 7 */ | |
6583 | OP_I15b, /* 0 .. 15 */ | |
6584 | OP_I31b, /* 0 .. 31 */ | |
6585 | ||
6586 | OP_SH, /* shifter operand */ | |
4962c51a | 6587 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 6588 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
6589 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
6590 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
6591 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
6592 | OP_EXP, /* arbitrary expression */ |
6593 | OP_EXPi, /* same, with optional immediate prefix */ | |
6594 | OP_EXPr, /* same, with optional relocation suffix */ | |
e2b0ab59 | 6595 | OP_EXPs, /* same, with optional non-first operand relocation suffix */ |
b6895b4f | 6596 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c28eeff2 SN |
6597 | OP_IROT1, /* VCADD rotate immediate: 90, 270. */ |
6598 | OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */ | |
c19d1205 ZW |
6599 | |
6600 | OP_CPSF, /* CPS flags */ | |
6601 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
6602 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
6603 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 6604 | OP_COND, /* conditional code */ |
92e90b6e | 6605 | OP_TB, /* Table branch. */ |
c19d1205 | 6606 | |
037e8744 JB |
6607 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
6608 | ||
c19d1205 | 6609 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
33eaf5de | 6610 | OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */ |
c19d1205 ZW |
6611 | OP_RR_EXi, /* ARM register or expression with imm prefix */ |
6612 | OP_RF_IF, /* FPA register or immediate */ | |
6613 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 6614 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
6615 | |
6616 | /* Optional operands. */ | |
6617 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
6618 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 6619 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 6620 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
6621 | OP_oIffffb, /* 0 .. 65535 */ |
6622 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
6623 | ||
6624 | OP_oRR, /* ARM register */ | |
6625 | OP_oRRnpc, /* ARM register, not the PC */ | |
5be8be5d | 6626 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 6627 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
6628 | OP_oRND, /* Optional Neon double precision register */ |
6629 | OP_oRNQ, /* Optional Neon quad precision register */ | |
6630 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 6631 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
6632 | OP_oSHll, /* LSL immediate */ |
6633 | OP_oSHar, /* ASR immediate */ | |
6634 | OP_oSHllar, /* LSL or ASR immediate */ | |
6635 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 6636 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 6637 | |
5be8be5d DG |
6638 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
6639 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
6640 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
6641 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
6642 | ||
c19d1205 ZW |
6643 | OP_FIRST_OPTIONAL = OP_oI7b |
6644 | }; | |
a737bd4d | 6645 | |
c19d1205 ZW |
6646 | /* Generic instruction operand parser. This does no encoding and no |
6647 | semantic validation; it merely squirrels values away in the inst | |
6648 | structure. Returns SUCCESS or FAIL depending on whether the | |
6649 | specified grammar matched. */ | |
6650 | static int | |
5be8be5d | 6651 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 6652 | { |
5be8be5d | 6653 | unsigned const int *upat = pattern; |
c19d1205 ZW |
6654 | char *backtrack_pos = 0; |
6655 | const char *backtrack_error = 0; | |
99aad254 | 6656 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 6657 | enum arm_reg_type rtype; |
4962c51a | 6658 | parse_operand_result result; |
5be8be5d | 6659 | unsigned int op_parse_code; |
c19d1205 | 6660 | |
e07e6e58 NC |
6661 | #define po_char_or_fail(chr) \ |
6662 | do \ | |
6663 | { \ | |
6664 | if (skip_past_char (&str, chr) == FAIL) \ | |
477330fc | 6665 | goto bad_args; \ |
e07e6e58 NC |
6666 | } \ |
6667 | while (0) | |
c19d1205 | 6668 | |
e07e6e58 NC |
6669 | #define po_reg_or_fail(regtype) \ |
6670 | do \ | |
dcbf9037 | 6671 | { \ |
e07e6e58 | 6672 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
477330fc | 6673 | & inst.operands[i].vectype); \ |
e07e6e58 | 6674 | if (val == FAIL) \ |
477330fc RM |
6675 | { \ |
6676 | first_error (_(reg_expected_msgs[regtype])); \ | |
6677 | goto failure; \ | |
6678 | } \ | |
e07e6e58 NC |
6679 | inst.operands[i].reg = val; \ |
6680 | inst.operands[i].isreg = 1; \ | |
6681 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6682 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6683 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc RM |
6684 | || rtype == REG_TYPE_VFD \ |
6685 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 6686 | } \ |
e07e6e58 NC |
6687 | while (0) |
6688 | ||
6689 | #define po_reg_or_goto(regtype, label) \ | |
6690 | do \ | |
6691 | { \ | |
6692 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
6693 | & inst.operands[i].vectype); \ | |
6694 | if (val == FAIL) \ | |
6695 | goto label; \ | |
dcbf9037 | 6696 | \ |
e07e6e58 NC |
6697 | inst.operands[i].reg = val; \ |
6698 | inst.operands[i].isreg = 1; \ | |
6699 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6700 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6701 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc | 6702 | || rtype == REG_TYPE_VFD \ |
e07e6e58 NC |
6703 | || rtype == REG_TYPE_NQ); \ |
6704 | } \ | |
6705 | while (0) | |
6706 | ||
6707 | #define po_imm_or_fail(min, max, popt) \ | |
6708 | do \ | |
6709 | { \ | |
6710 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
6711 | goto failure; \ | |
6712 | inst.operands[i].imm = val; \ | |
6713 | } \ | |
6714 | while (0) | |
6715 | ||
6716 | #define po_scalar_or_goto(elsz, label) \ | |
6717 | do \ | |
6718 | { \ | |
6719 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
6720 | if (val == FAIL) \ | |
6721 | goto label; \ | |
6722 | inst.operands[i].reg = val; \ | |
6723 | inst.operands[i].isscalar = 1; \ | |
6724 | } \ | |
6725 | while (0) | |
6726 | ||
6727 | #define po_misc_or_fail(expr) \ | |
6728 | do \ | |
6729 | { \ | |
6730 | if (expr) \ | |
6731 | goto failure; \ | |
6732 | } \ | |
6733 | while (0) | |
6734 | ||
6735 | #define po_misc_or_fail_no_backtrack(expr) \ | |
6736 | do \ | |
6737 | { \ | |
6738 | result = expr; \ | |
6739 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
6740 | backtrack_pos = 0; \ | |
6741 | if (result != PARSE_OPERAND_SUCCESS) \ | |
6742 | goto failure; \ | |
6743 | } \ | |
6744 | while (0) | |
4962c51a | 6745 | |
52e7f43d RE |
6746 | #define po_barrier_or_imm(str) \ |
6747 | do \ | |
6748 | { \ | |
6749 | val = parse_barrier (&str); \ | |
ccb84d65 JB |
6750 | if (val == FAIL && ! ISALPHA (*str)) \ |
6751 | goto immediate; \ | |
6752 | if (val == FAIL \ | |
6753 | /* ISB can only take SY as an option. */ \ | |
6754 | || ((inst.instruction & 0xf0) == 0x60 \ | |
6755 | && val != 0xf)) \ | |
52e7f43d | 6756 | { \ |
ccb84d65 JB |
6757 | inst.error = _("invalid barrier type"); \ |
6758 | backtrack_pos = 0; \ | |
6759 | goto failure; \ | |
52e7f43d RE |
6760 | } \ |
6761 | } \ | |
6762 | while (0) | |
6763 | ||
c19d1205 ZW |
6764 | skip_whitespace (str); |
6765 | ||
6766 | for (i = 0; upat[i] != OP_stop; i++) | |
6767 | { | |
5be8be5d DG |
6768 | op_parse_code = upat[i]; |
6769 | if (op_parse_code >= 1<<16) | |
6770 | op_parse_code = thumb ? (op_parse_code >> 16) | |
6771 | : (op_parse_code & ((1<<16)-1)); | |
6772 | ||
6773 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
6774 | { |
6775 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 6776 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
6777 | backtrack_pos = str; |
6778 | backtrack_error = inst.error; | |
6779 | backtrack_index = i; | |
6780 | } | |
6781 | ||
b6702015 | 6782 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
6783 | po_char_or_fail (','); |
6784 | ||
5be8be5d | 6785 | switch (op_parse_code) |
c19d1205 ZW |
6786 | { |
6787 | /* Registers */ | |
6788 | case OP_oRRnpc: | |
5be8be5d | 6789 | case OP_oRRnpcsp: |
c19d1205 | 6790 | case OP_RRnpc: |
5be8be5d | 6791 | case OP_RRnpcsp: |
c19d1205 ZW |
6792 | case OP_oRR: |
6793 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
6794 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
6795 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
6796 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
6797 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
6798 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
477330fc | 6799 | case OP_oRND: |
5287ad62 | 6800 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; |
cd2cf30b PB |
6801 | case OP_RVC: |
6802 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
6803 | break; | |
6804 | /* Also accept generic coprocessor regs for unknown registers. */ | |
6805 | coproc_reg: | |
6806 | po_reg_or_fail (REG_TYPE_CN); | |
6807 | break; | |
c19d1205 ZW |
6808 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
6809 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
6810 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
6811 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
6812 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
6813 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
6814 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
6815 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
6816 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
6817 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
477330fc | 6818 | case OP_oRNQ: |
5287ad62 | 6819 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; |
dec41383 | 6820 | case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break; |
477330fc | 6821 | case OP_oRNDQ: |
5287ad62 | 6822 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; |
477330fc RM |
6823 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
6824 | case OP_oRNSDQ: | |
6825 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
6826 | ||
6827 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6828 | scalars are accepted here, so deal with those in later code. */ | |
6829 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6830 | ||
6831 | case OP_RNDQ_I0: | |
6832 | { | |
6833 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6834 | break; | |
6835 | try_imm0: | |
6836 | po_imm_or_fail (0, 0, TRUE); | |
6837 | } | |
6838 | break; | |
6839 | ||
6840 | case OP_RVSD_I0: | |
6841 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6842 | break; | |
6843 | ||
aacf0b33 KT |
6844 | case OP_RSVD_FI0: |
6845 | { | |
6846 | po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0); | |
6847 | break; | |
6848 | try_ifimm0: | |
6849 | if (parse_ifimm_zero (&str)) | |
6850 | inst.operands[i].imm = 0; | |
6851 | else | |
6852 | { | |
6853 | inst.error | |
6854 | = _("only floating point zero is allowed as immediate value"); | |
6855 | goto failure; | |
6856 | } | |
6857 | } | |
6858 | break; | |
6859 | ||
477330fc RM |
6860 | case OP_RR_RNSC: |
6861 | { | |
6862 | po_scalar_or_goto (8, try_rr); | |
6863 | break; | |
6864 | try_rr: | |
6865 | po_reg_or_fail (REG_TYPE_RN); | |
6866 | } | |
6867 | break; | |
6868 | ||
6869 | case OP_RNSDQ_RNSC: | |
6870 | { | |
6871 | po_scalar_or_goto (8, try_nsdq); | |
6872 | break; | |
6873 | try_nsdq: | |
6874 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6875 | } | |
6876 | break; | |
6877 | ||
dec41383 JW |
6878 | case OP_RNSD_RNSC: |
6879 | { | |
6880 | po_scalar_or_goto (8, try_s_scalar); | |
6881 | break; | |
6882 | try_s_scalar: | |
6883 | po_scalar_or_goto (4, try_nsd); | |
6884 | break; | |
6885 | try_nsd: | |
6886 | po_reg_or_fail (REG_TYPE_NSD); | |
6887 | } | |
6888 | break; | |
6889 | ||
477330fc RM |
6890 | case OP_RNDQ_RNSC: |
6891 | { | |
6892 | po_scalar_or_goto (8, try_ndq); | |
6893 | break; | |
6894 | try_ndq: | |
6895 | po_reg_or_fail (REG_TYPE_NDQ); | |
6896 | } | |
6897 | break; | |
6898 | ||
6899 | case OP_RND_RNSC: | |
6900 | { | |
6901 | po_scalar_or_goto (8, try_vfd); | |
6902 | break; | |
6903 | try_vfd: | |
6904 | po_reg_or_fail (REG_TYPE_VFD); | |
6905 | } | |
6906 | break; | |
6907 | ||
6908 | case OP_VMOV: | |
6909 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6910 | not careful then bad things might happen. */ | |
6911 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6912 | break; | |
6913 | ||
6914 | case OP_RNDQ_Ibig: | |
6915 | { | |
6916 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); | |
6917 | break; | |
6918 | try_immbig: | |
6919 | /* There's a possibility of getting a 64-bit immediate here, so | |
6920 | we need special handling. */ | |
8335d6aa JW |
6921 | if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE) |
6922 | == FAIL) | |
477330fc RM |
6923 | { |
6924 | inst.error = _("immediate value is out of range"); | |
6925 | goto failure; | |
6926 | } | |
6927 | } | |
6928 | break; | |
6929 | ||
6930 | case OP_RNDQ_I63b: | |
6931 | { | |
6932 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6933 | break; | |
6934 | try_shimm: | |
6935 | po_imm_or_fail (0, 63, TRUE); | |
6936 | } | |
6937 | break; | |
c19d1205 ZW |
6938 | |
6939 | case OP_RRnpcb: | |
6940 | po_char_or_fail ('['); | |
6941 | po_reg_or_fail (REG_TYPE_RN); | |
6942 | po_char_or_fail (']'); | |
6943 | break; | |
a737bd4d | 6944 | |
55881a11 | 6945 | case OP_RRnpctw: |
c19d1205 | 6946 | case OP_RRw: |
b6702015 | 6947 | case OP_oRRw: |
c19d1205 ZW |
6948 | po_reg_or_fail (REG_TYPE_RN); |
6949 | if (skip_past_char (&str, '!') == SUCCESS) | |
6950 | inst.operands[i].writeback = 1; | |
6951 | break; | |
6952 | ||
6953 | /* Immediates */ | |
6954 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6955 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6956 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
477330fc | 6957 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6958 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6959 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
477330fc | 6960 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6961 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
477330fc RM |
6962 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6963 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6964 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6965 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6966 | |
6967 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6968 | case OP_oI7b: | |
6969 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6970 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6971 | case OP_oI31b: | |
6972 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
477330fc RM |
6973 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
6974 | case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break; | |
c19d1205 ZW |
6975 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6976 | ||
6977 | /* Immediate variants */ | |
6978 | case OP_oI255c: | |
6979 | po_char_or_fail ('{'); | |
6980 | po_imm_or_fail (0, 255, TRUE); | |
6981 | po_char_or_fail ('}'); | |
6982 | break; | |
6983 | ||
6984 | case OP_I31w: | |
6985 | /* The expression parser chokes on a trailing !, so we have | |
6986 | to find it first and zap it. */ | |
6987 | { | |
6988 | char *s = str; | |
6989 | while (*s && *s != ',') | |
6990 | s++; | |
6991 | if (s[-1] == '!') | |
6992 | { | |
6993 | s[-1] = '\0'; | |
6994 | inst.operands[i].writeback = 1; | |
6995 | } | |
6996 | po_imm_or_fail (0, 31, TRUE); | |
6997 | if (str == s - 1) | |
6998 | str = s; | |
6999 | } | |
7000 | break; | |
7001 | ||
7002 | /* Expressions */ | |
7003 | case OP_EXPi: EXPi: | |
e2b0ab59 | 7004 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7005 | GE_OPT_PREFIX)); |
7006 | break; | |
7007 | ||
7008 | case OP_EXP: | |
e2b0ab59 | 7009 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 ZW |
7010 | GE_NO_PREFIX)); |
7011 | break; | |
7012 | ||
7013 | case OP_EXPr: EXPr: | |
e2b0ab59 | 7014 | po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str, |
c19d1205 | 7015 | GE_NO_PREFIX)); |
e2b0ab59 | 7016 | if (inst.relocs[0].exp.X_op == O_symbol) |
a737bd4d | 7017 | { |
c19d1205 ZW |
7018 | val = parse_reloc (&str); |
7019 | if (val == -1) | |
7020 | { | |
7021 | inst.error = _("unrecognized relocation suffix"); | |
7022 | goto failure; | |
7023 | } | |
7024 | else if (val != BFD_RELOC_UNUSED) | |
7025 | { | |
7026 | inst.operands[i].imm = val; | |
7027 | inst.operands[i].hasreloc = 1; | |
7028 | } | |
a737bd4d | 7029 | } |
c19d1205 | 7030 | break; |
a737bd4d | 7031 | |
e2b0ab59 AV |
7032 | case OP_EXPs: |
7033 | po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str, | |
7034 | GE_NO_PREFIX)); | |
7035 | if (inst.relocs[i].exp.X_op == O_symbol) | |
7036 | { | |
7037 | inst.operands[i].hasreloc = 1; | |
7038 | } | |
7039 | else if (inst.relocs[i].exp.X_op == O_constant) | |
7040 | { | |
7041 | inst.operands[i].imm = inst.relocs[i].exp.X_add_number; | |
7042 | inst.operands[i].hasreloc = 0; | |
7043 | } | |
7044 | break; | |
7045 | ||
b6895b4f PB |
7046 | /* Operand for MOVW or MOVT. */ |
7047 | case OP_HALF: | |
7048 | po_misc_or_fail (parse_half (&str)); | |
7049 | break; | |
7050 | ||
e07e6e58 | 7051 | /* Register or expression. */ |
c19d1205 ZW |
7052 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
7053 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 7054 | |
e07e6e58 | 7055 | /* Register or immediate. */ |
c19d1205 ZW |
7056 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
7057 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 7058 | |
c19d1205 ZW |
7059 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
7060 | IF: | |
7061 | if (!is_immediate_prefix (*str)) | |
7062 | goto bad_args; | |
7063 | str++; | |
7064 | val = parse_fpa_immediate (&str); | |
7065 | if (val == FAIL) | |
7066 | goto failure; | |
7067 | /* FPA immediates are encoded as registers 8-15. | |
7068 | parse_fpa_immediate has already applied the offset. */ | |
7069 | inst.operands[i].reg = val; | |
7070 | inst.operands[i].isreg = 1; | |
7071 | break; | |
09d92015 | 7072 | |
2d447fca JM |
7073 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
7074 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
7075 | ||
e07e6e58 | 7076 | /* Two kinds of register. */ |
c19d1205 ZW |
7077 | case OP_RIWR_RIWC: |
7078 | { | |
7079 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
7080 | if (!rege |
7081 | || (rege->type != REG_TYPE_MMXWR | |
7082 | && rege->type != REG_TYPE_MMXWC | |
7083 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
7084 | { |
7085 | inst.error = _("iWMMXt data or control register expected"); | |
7086 | goto failure; | |
7087 | } | |
7088 | inst.operands[i].reg = rege->number; | |
7089 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
7090 | } | |
7091 | break; | |
09d92015 | 7092 | |
41adaa5c JM |
7093 | case OP_RIWC_RIWG: |
7094 | { | |
7095 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
7096 | if (!rege | |
7097 | || (rege->type != REG_TYPE_MMXWC | |
7098 | && rege->type != REG_TYPE_MMXWCG)) | |
7099 | { | |
7100 | inst.error = _("iWMMXt control register expected"); | |
7101 | goto failure; | |
7102 | } | |
7103 | inst.operands[i].reg = rege->number; | |
7104 | inst.operands[i].isreg = 1; | |
7105 | } | |
7106 | break; | |
7107 | ||
c19d1205 ZW |
7108 | /* Misc */ |
7109 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
7110 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
7111 | case OP_oROR: val = parse_ror (&str); break; | |
c19d1205 | 7112 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
7113 | case OP_oBARRIER_I15: |
7114 | po_barrier_or_imm (str); break; | |
7115 | immediate: | |
7116 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
477330fc | 7117 | goto failure; |
52e7f43d | 7118 | break; |
c19d1205 | 7119 | |
fa94de6b | 7120 | case OP_wPSR: |
d2cd1205 | 7121 | case OP_rPSR: |
90ec0d68 MGD |
7122 | po_reg_or_goto (REG_TYPE_RNB, try_psr); |
7123 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
7124 | { | |
7125 | inst.error = _("Banked registers are not available with this " | |
7126 | "architecture."); | |
7127 | goto failure; | |
7128 | } | |
7129 | break; | |
d2cd1205 JB |
7130 | try_psr: |
7131 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
7132 | break; | |
037e8744 | 7133 | |
477330fc RM |
7134 | case OP_APSR_RR: |
7135 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
7136 | break; | |
7137 | try_apsr: | |
7138 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
7139 | instruction). */ | |
7140 | if (strncasecmp (str, "APSR_", 5) == 0) | |
7141 | { | |
7142 | unsigned found = 0; | |
7143 | str += 5; | |
7144 | while (found < 15) | |
7145 | switch (*str++) | |
7146 | { | |
7147 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
7148 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
7149 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
7150 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
7151 | default: found = 16; | |
7152 | } | |
7153 | if (found != 15) | |
7154 | goto failure; | |
7155 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
7156 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
7157 | inst.operands[i].reg = REG_PC; | |
477330fc RM |
7158 | } |
7159 | else | |
7160 | goto failure; | |
7161 | break; | |
037e8744 | 7162 | |
92e90b6e PB |
7163 | case OP_TB: |
7164 | po_misc_or_fail (parse_tb (&str)); | |
7165 | break; | |
7166 | ||
e07e6e58 | 7167 | /* Register lists. */ |
c19d1205 ZW |
7168 | case OP_REGLST: |
7169 | val = parse_reg_list (&str); | |
7170 | if (*str == '^') | |
7171 | { | |
5e0d7f77 | 7172 | inst.operands[i].writeback = 1; |
c19d1205 ZW |
7173 | str++; |
7174 | } | |
7175 | break; | |
09d92015 | 7176 | |
c19d1205 | 7177 | case OP_VRSLST: |
5287ad62 | 7178 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 7179 | break; |
09d92015 | 7180 | |
c19d1205 | 7181 | case OP_VRDLST: |
5287ad62 | 7182 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 7183 | break; |
a737bd4d | 7184 | |
477330fc RM |
7185 | case OP_VRSDLST: |
7186 | /* Allow Q registers too. */ | |
7187 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7188 | REGLIST_NEON_D); | |
7189 | if (val == FAIL) | |
7190 | { | |
7191 | inst.error = NULL; | |
7192 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7193 | REGLIST_VFP_S); | |
7194 | inst.operands[i].issingle = 1; | |
7195 | } | |
7196 | break; | |
7197 | ||
7198 | case OP_NRDLST: | |
7199 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7200 | REGLIST_NEON_D); | |
7201 | break; | |
5287ad62 JB |
7202 | |
7203 | case OP_NSTRLST: | |
477330fc RM |
7204 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
7205 | &inst.operands[i].vectype); | |
7206 | break; | |
5287ad62 | 7207 | |
c19d1205 ZW |
7208 | /* Addressing modes */ |
7209 | case OP_ADDR: | |
7210 | po_misc_or_fail (parse_address (&str, i)); | |
7211 | break; | |
09d92015 | 7212 | |
4962c51a MS |
7213 | case OP_ADDRGLDR: |
7214 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7215 | parse_address_group_reloc (&str, i, GROUP_LDR)); |
4962c51a MS |
7216 | break; |
7217 | ||
7218 | case OP_ADDRGLDRS: | |
7219 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7220 | parse_address_group_reloc (&str, i, GROUP_LDRS)); |
4962c51a MS |
7221 | break; |
7222 | ||
7223 | case OP_ADDRGLDC: | |
7224 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7225 | parse_address_group_reloc (&str, i, GROUP_LDC)); |
4962c51a MS |
7226 | break; |
7227 | ||
c19d1205 ZW |
7228 | case OP_SH: |
7229 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
7230 | break; | |
09d92015 | 7231 | |
4962c51a MS |
7232 | case OP_SHG: |
7233 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7234 | parse_shifter_operand_group_reloc (&str, i)); |
4962c51a MS |
7235 | break; |
7236 | ||
c19d1205 ZW |
7237 | case OP_oSHll: |
7238 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
7239 | break; | |
09d92015 | 7240 | |
c19d1205 ZW |
7241 | case OP_oSHar: |
7242 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
7243 | break; | |
09d92015 | 7244 | |
c19d1205 ZW |
7245 | case OP_oSHllar: |
7246 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
7247 | break; | |
09d92015 | 7248 | |
c19d1205 | 7249 | default: |
5be8be5d | 7250 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 7251 | } |
09d92015 | 7252 | |
c19d1205 ZW |
7253 | /* Various value-based sanity checks and shared operations. We |
7254 | do not signal immediate failures for the register constraints; | |
7255 | this allows a syntax error to take precedence. */ | |
5be8be5d | 7256 | switch (op_parse_code) |
c19d1205 ZW |
7257 | { |
7258 | case OP_oRRnpc: | |
7259 | case OP_RRnpc: | |
7260 | case OP_RRnpcb: | |
7261 | case OP_RRw: | |
b6702015 | 7262 | case OP_oRRw: |
c19d1205 ZW |
7263 | case OP_RRnpc_I0: |
7264 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
7265 | inst.error = BAD_PC; | |
7266 | break; | |
09d92015 | 7267 | |
5be8be5d DG |
7268 | case OP_oRRnpcsp: |
7269 | case OP_RRnpcsp: | |
7270 | if (inst.operands[i].isreg) | |
7271 | { | |
7272 | if (inst.operands[i].reg == REG_PC) | |
7273 | inst.error = BAD_PC; | |
5c8ed6a4 JW |
7274 | else if (inst.operands[i].reg == REG_SP |
7275 | /* The restriction on Rd/Rt/Rt2 on Thumb mode has been | |
7276 | relaxed since ARMv8-A. */ | |
7277 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
7278 | { | |
7279 | gas_assert (thumb); | |
7280 | inst.error = BAD_SP; | |
7281 | } | |
5be8be5d DG |
7282 | } |
7283 | break; | |
7284 | ||
55881a11 | 7285 | case OP_RRnpctw: |
fa94de6b RM |
7286 | if (inst.operands[i].isreg |
7287 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
7288 | && (inst.operands[i].writeback || thumb)) |
7289 | inst.error = BAD_PC; | |
7290 | break; | |
7291 | ||
c19d1205 ZW |
7292 | case OP_CPSF: |
7293 | case OP_ENDI: | |
7294 | case OP_oROR: | |
d2cd1205 JB |
7295 | case OP_wPSR: |
7296 | case OP_rPSR: | |
c19d1205 | 7297 | case OP_COND: |
52e7f43d | 7298 | case OP_oBARRIER_I15: |
c19d1205 ZW |
7299 | case OP_REGLST: |
7300 | case OP_VRSLST: | |
7301 | case OP_VRDLST: | |
477330fc RM |
7302 | case OP_VRSDLST: |
7303 | case OP_NRDLST: | |
7304 | case OP_NSTRLST: | |
c19d1205 ZW |
7305 | if (val == FAIL) |
7306 | goto failure; | |
7307 | inst.operands[i].imm = val; | |
7308 | break; | |
a737bd4d | 7309 | |
c19d1205 ZW |
7310 | default: |
7311 | break; | |
7312 | } | |
09d92015 | 7313 | |
c19d1205 ZW |
7314 | /* If we get here, this operand was successfully parsed. */ |
7315 | inst.operands[i].present = 1; | |
7316 | continue; | |
09d92015 | 7317 | |
c19d1205 | 7318 | bad_args: |
09d92015 | 7319 | inst.error = BAD_ARGS; |
c19d1205 ZW |
7320 | |
7321 | failure: | |
7322 | if (!backtrack_pos) | |
d252fdde PB |
7323 | { |
7324 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 7325 | default here just in case. */ |
d252fdde PB |
7326 | if (!inst.error) |
7327 | inst.error = _("syntax error"); | |
7328 | return FAIL; | |
7329 | } | |
c19d1205 ZW |
7330 | |
7331 | /* Do not backtrack over a trailing optional argument that | |
7332 | absorbed some text. We will only fail again, with the | |
7333 | 'garbage following instruction' error message, which is | |
7334 | probably less helpful than the current one. */ | |
7335 | if (backtrack_index == i && backtrack_pos != str | |
7336 | && upat[i+1] == OP_stop) | |
d252fdde PB |
7337 | { |
7338 | if (!inst.error) | |
7339 | inst.error = _("syntax error"); | |
7340 | return FAIL; | |
7341 | } | |
c19d1205 ZW |
7342 | |
7343 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
7344 | str = backtrack_pos; | |
7345 | inst.error = backtrack_error; | |
7346 | inst.operands[backtrack_index].present = 0; | |
7347 | i = backtrack_index; | |
7348 | backtrack_pos = 0; | |
09d92015 | 7349 | } |
09d92015 | 7350 | |
c19d1205 ZW |
7351 | /* Check that we have parsed all the arguments. */ |
7352 | if (*str != '\0' && !inst.error) | |
7353 | inst.error = _("garbage following instruction"); | |
09d92015 | 7354 | |
c19d1205 | 7355 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
7356 | } |
7357 | ||
c19d1205 ZW |
7358 | #undef po_char_or_fail |
7359 | #undef po_reg_or_fail | |
7360 | #undef po_reg_or_goto | |
7361 | #undef po_imm_or_fail | |
5287ad62 | 7362 | #undef po_scalar_or_fail |
52e7f43d | 7363 | #undef po_barrier_or_imm |
e07e6e58 | 7364 | |
c19d1205 | 7365 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
7366 | #define constraint(expr, err) \ |
7367 | do \ | |
c19d1205 | 7368 | { \ |
e07e6e58 NC |
7369 | if (expr) \ |
7370 | { \ | |
7371 | inst.error = err; \ | |
7372 | return; \ | |
7373 | } \ | |
c19d1205 | 7374 | } \ |
e07e6e58 | 7375 | while (0) |
c19d1205 | 7376 | |
fdfde340 JM |
7377 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
7378 | instructions are unpredictable if these registers are used. This | |
5c8ed6a4 JW |
7379 | is the BadReg predicate in ARM's Thumb-2 documentation. |
7380 | ||
7381 | Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few | |
7382 | places, while the restriction on REG_SP was relaxed since ARMv8-A. */ | |
7383 | #define reject_bad_reg(reg) \ | |
7384 | do \ | |
7385 | if (reg == REG_PC) \ | |
7386 | { \ | |
7387 | inst.error = BAD_PC; \ | |
7388 | return; \ | |
7389 | } \ | |
7390 | else if (reg == REG_SP \ | |
7391 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \ | |
7392 | { \ | |
7393 | inst.error = BAD_SP; \ | |
7394 | return; \ | |
7395 | } \ | |
fdfde340 JM |
7396 | while (0) |
7397 | ||
94206790 MM |
7398 | /* If REG is R13 (the stack pointer), warn that its use is |
7399 | deprecated. */ | |
7400 | #define warn_deprecated_sp(reg) \ | |
7401 | do \ | |
7402 | if (warn_on_deprecated && reg == REG_SP) \ | |
5c3696f8 | 7403 | as_tsktsk (_("use of r13 is deprecated")); \ |
94206790 MM |
7404 | while (0) |
7405 | ||
c19d1205 ZW |
7406 | /* Functions for operand encoding. ARM, then Thumb. */ |
7407 | ||
d840c081 | 7408 | #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31)) |
c19d1205 | 7409 | |
9db2f6b4 RL |
7410 | /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding. |
7411 | ||
7412 | The only binary encoding difference is the Coprocessor number. Coprocessor | |
7413 | 9 is used for half-precision calculations or conversions. The format of the | |
2b0f3761 | 7414 | instruction is the same as the equivalent Coprocessor 10 instruction that |
9db2f6b4 RL |
7415 | exists for Single-Precision operation. */ |
7416 | ||
7417 | static void | |
7418 | do_scalar_fp16_v82_encode (void) | |
7419 | { | |
7420 | if (inst.cond != COND_ALWAYS) | |
7421 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," | |
7422 | " the behaviour is UNPREDICTABLE")); | |
7423 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
7424 | _(BAD_FP16)); | |
7425 | ||
7426 | inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900; | |
7427 | mark_feature_used (&arm_ext_fp16); | |
7428 | } | |
7429 | ||
c19d1205 ZW |
7430 | /* If VAL can be encoded in the immediate field of an ARM instruction, |
7431 | return the encoded form. Otherwise, return FAIL. */ | |
7432 | ||
7433 | static unsigned int | |
7434 | encode_arm_immediate (unsigned int val) | |
09d92015 | 7435 | { |
c19d1205 ZW |
7436 | unsigned int a, i; |
7437 | ||
4f1d6205 L |
7438 | if (val <= 0xff) |
7439 | return val; | |
7440 | ||
7441 | for (i = 2; i < 32; i += 2) | |
c19d1205 ZW |
7442 | if ((a = rotate_left (val, i)) <= 0xff) |
7443 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
7444 | ||
7445 | return FAIL; | |
09d92015 MM |
7446 | } |
7447 | ||
c19d1205 ZW |
7448 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
7449 | return the encoded form. Otherwise, return FAIL. */ | |
7450 | static unsigned int | |
7451 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 7452 | { |
c19d1205 | 7453 | unsigned int a, i; |
09d92015 | 7454 | |
9c3c69f2 | 7455 | if (val <= 0xff) |
c19d1205 | 7456 | return val; |
a737bd4d | 7457 | |
9c3c69f2 | 7458 | for (i = 1; i <= 24; i++) |
09d92015 | 7459 | { |
9c3c69f2 PB |
7460 | a = val >> i; |
7461 | if ((val & ~(0xff << i)) == 0) | |
7462 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 7463 | } |
a737bd4d | 7464 | |
c19d1205 ZW |
7465 | a = val & 0xff; |
7466 | if (val == ((a << 16) | a)) | |
7467 | return 0x100 | a; | |
7468 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
7469 | return 0x300 | a; | |
09d92015 | 7470 | |
c19d1205 ZW |
7471 | a = val & 0xff00; |
7472 | if (val == ((a << 16) | a)) | |
7473 | return 0x200 | (a >> 8); | |
a737bd4d | 7474 | |
c19d1205 | 7475 | return FAIL; |
09d92015 | 7476 | } |
5287ad62 | 7477 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
7478 | |
7479 | static void | |
5287ad62 JB |
7480 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
7481 | { | |
7482 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
7483 | && reg > 15) | |
7484 | { | |
b1cc4aeb | 7485 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
477330fc RM |
7486 | { |
7487 | if (thumb_mode) | |
7488 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
7489 | fpu_vfp_ext_d32); | |
7490 | else | |
7491 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
7492 | fpu_vfp_ext_d32); | |
7493 | } | |
5287ad62 | 7494 | else |
477330fc RM |
7495 | { |
7496 | first_error (_("D register out of range for selected VFP version")); | |
7497 | return; | |
7498 | } | |
5287ad62 JB |
7499 | } |
7500 | ||
c19d1205 | 7501 | switch (pos) |
09d92015 | 7502 | { |
c19d1205 ZW |
7503 | case VFP_REG_Sd: |
7504 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
7505 | break; | |
7506 | ||
7507 | case VFP_REG_Sn: | |
7508 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
7509 | break; | |
7510 | ||
7511 | case VFP_REG_Sm: | |
7512 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
7513 | break; | |
7514 | ||
5287ad62 JB |
7515 | case VFP_REG_Dd: |
7516 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
7517 | break; | |
5f4273c7 | 7518 | |
5287ad62 JB |
7519 | case VFP_REG_Dn: |
7520 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
7521 | break; | |
5f4273c7 | 7522 | |
5287ad62 JB |
7523 | case VFP_REG_Dm: |
7524 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
7525 | break; | |
7526 | ||
c19d1205 ZW |
7527 | default: |
7528 | abort (); | |
09d92015 | 7529 | } |
09d92015 MM |
7530 | } |
7531 | ||
c19d1205 | 7532 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 7533 | if any, is handled by md_apply_fix. */ |
09d92015 | 7534 | static void |
c19d1205 | 7535 | encode_arm_shift (int i) |
09d92015 | 7536 | { |
008a97ef RL |
7537 | /* register-shifted register. */ |
7538 | if (inst.operands[i].immisreg) | |
7539 | { | |
bf355b69 MR |
7540 | int op_index; |
7541 | for (op_index = 0; op_index <= i; ++op_index) | |
008a97ef | 7542 | { |
5689c942 RL |
7543 | /* Check the operand only when it's presented. In pre-UAL syntax, |
7544 | if the destination register is the same as the first operand, two | |
7545 | register form of the instruction can be used. */ | |
bf355b69 MR |
7546 | if (inst.operands[op_index].present && inst.operands[op_index].isreg |
7547 | && inst.operands[op_index].reg == REG_PC) | |
008a97ef RL |
7548 | as_warn (UNPRED_REG ("r15")); |
7549 | } | |
7550 | ||
7551 | if (inst.operands[i].imm == REG_PC) | |
7552 | as_warn (UNPRED_REG ("r15")); | |
7553 | } | |
7554 | ||
c19d1205 ZW |
7555 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
7556 | inst.instruction |= SHIFT_ROR << 5; | |
7557 | else | |
09d92015 | 7558 | { |
c19d1205 ZW |
7559 | inst.instruction |= inst.operands[i].shift_kind << 5; |
7560 | if (inst.operands[i].immisreg) | |
7561 | { | |
7562 | inst.instruction |= SHIFT_BY_REG; | |
7563 | inst.instruction |= inst.operands[i].imm << 8; | |
7564 | } | |
7565 | else | |
e2b0ab59 | 7566 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
09d92015 | 7567 | } |
c19d1205 | 7568 | } |
09d92015 | 7569 | |
c19d1205 ZW |
7570 | static void |
7571 | encode_arm_shifter_operand (int i) | |
7572 | { | |
7573 | if (inst.operands[i].isreg) | |
09d92015 | 7574 | { |
c19d1205 ZW |
7575 | inst.instruction |= inst.operands[i].reg; |
7576 | encode_arm_shift (i); | |
09d92015 | 7577 | } |
c19d1205 | 7578 | else |
a415b1cd JB |
7579 | { |
7580 | inst.instruction |= INST_IMMEDIATE; | |
e2b0ab59 | 7581 | if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE) |
a415b1cd JB |
7582 | inst.instruction |= inst.operands[i].imm; |
7583 | } | |
09d92015 MM |
7584 | } |
7585 | ||
c19d1205 | 7586 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 7587 | static void |
c19d1205 | 7588 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 7589 | { |
2b2f5df9 NC |
7590 | /* PR 14260: |
7591 | Generate an error if the operand is not a register. */ | |
7592 | constraint (!inst.operands[i].isreg, | |
7593 | _("Instruction does not support =N addresses")); | |
7594 | ||
c19d1205 | 7595 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 7596 | |
c19d1205 | 7597 | if (inst.operands[i].preind) |
09d92015 | 7598 | { |
c19d1205 ZW |
7599 | if (is_t) |
7600 | { | |
7601 | inst.error = _("instruction does not accept preindexed addressing"); | |
7602 | return; | |
7603 | } | |
7604 | inst.instruction |= PRE_INDEX; | |
7605 | if (inst.operands[i].writeback) | |
7606 | inst.instruction |= WRITE_BACK; | |
09d92015 | 7607 | |
c19d1205 ZW |
7608 | } |
7609 | else if (inst.operands[i].postind) | |
7610 | { | |
9c2799c2 | 7611 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
7612 | if (is_t) |
7613 | inst.instruction |= WRITE_BACK; | |
7614 | } | |
7615 | else /* unindexed - only for coprocessor */ | |
09d92015 | 7616 | { |
c19d1205 | 7617 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
7618 | return; |
7619 | } | |
7620 | ||
c19d1205 ZW |
7621 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
7622 | && (((inst.instruction & 0x000f0000) >> 16) | |
7623 | == ((inst.instruction & 0x0000f000) >> 12))) | |
7624 | as_warn ((inst.instruction & LOAD_BIT) | |
7625 | ? _("destination register same as write-back base") | |
7626 | : _("source register same as write-back base")); | |
09d92015 MM |
7627 | } |
7628 | ||
c19d1205 ZW |
7629 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7630 | ARM-format mode 2 load or store instruction. If is_t is true, | |
7631 | reject forms that cannot be used with a T instruction (i.e. not | |
7632 | post-indexed). */ | |
a737bd4d | 7633 | static void |
c19d1205 | 7634 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 7635 | { |
5be8be5d DG |
7636 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
7637 | ||
c19d1205 | 7638 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7639 | |
c19d1205 | 7640 | if (inst.operands[i].immisreg) |
09d92015 | 7641 | { |
5be8be5d DG |
7642 | constraint ((inst.operands[i].imm == REG_PC |
7643 | || (is_pc && inst.operands[i].writeback)), | |
7644 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
7645 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
7646 | inst.instruction |= inst.operands[i].imm; | |
7647 | if (!inst.operands[i].negative) | |
7648 | inst.instruction |= INDEX_UP; | |
7649 | if (inst.operands[i].shifted) | |
7650 | { | |
7651 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
7652 | inst.instruction |= SHIFT_ROR << 5; | |
7653 | else | |
7654 | { | |
7655 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
e2b0ab59 | 7656 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
c19d1205 ZW |
7657 | } |
7658 | } | |
09d92015 | 7659 | } |
e2b0ab59 | 7660 | else /* immediate offset in inst.relocs[0] */ |
09d92015 | 7661 | { |
e2b0ab59 | 7662 | if (is_pc && !inst.relocs[0].pc_rel) |
5be8be5d DG |
7663 | { |
7664 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
7665 | |
7666 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
7667 | cannot use PC in addressing. | |
7668 | PC cannot be used in writeback addressing, either. */ | |
7669 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 7670 | BAD_PC_ADDRESSING); |
23a10334 | 7671 | |
dc5ec521 | 7672 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
7673 | if (warn_on_deprecated |
7674 | && !is_load | |
7675 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
5c3696f8 | 7676 | as_tsktsk (_("use of PC in this instruction is deprecated")); |
5be8be5d DG |
7677 | } |
7678 | ||
e2b0ab59 | 7679 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
7680 | { |
7681 | /* Prefer + for zero encoded value. */ | |
7682 | if (!inst.operands[i].negative) | |
7683 | inst.instruction |= INDEX_UP; | |
e2b0ab59 | 7684 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM; |
26d97720 | 7685 | } |
09d92015 | 7686 | } |
09d92015 MM |
7687 | } |
7688 | ||
c19d1205 ZW |
7689 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7690 | ARM-format mode 3 load or store instruction. Reject forms that | |
7691 | cannot be used with such instructions. If is_t is true, reject | |
7692 | forms that cannot be used with a T instruction (i.e. not | |
7693 | post-indexed). */ | |
7694 | static void | |
7695 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 7696 | { |
c19d1205 | 7697 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 7698 | { |
c19d1205 ZW |
7699 | inst.error = _("instruction does not accept scaled register index"); |
7700 | return; | |
09d92015 | 7701 | } |
a737bd4d | 7702 | |
c19d1205 | 7703 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7704 | |
c19d1205 ZW |
7705 | if (inst.operands[i].immisreg) |
7706 | { | |
5be8be5d | 7707 | constraint ((inst.operands[i].imm == REG_PC |
eb9f3f00 | 7708 | || (is_t && inst.operands[i].reg == REG_PC)), |
5be8be5d | 7709 | BAD_PC_ADDRESSING); |
eb9f3f00 JB |
7710 | constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback, |
7711 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7712 | inst.instruction |= inst.operands[i].imm; |
7713 | if (!inst.operands[i].negative) | |
7714 | inst.instruction |= INDEX_UP; | |
7715 | } | |
e2b0ab59 | 7716 | else /* immediate offset in inst.relocs[0] */ |
c19d1205 | 7717 | { |
e2b0ab59 | 7718 | constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel |
5be8be5d DG |
7719 | && inst.operands[i].writeback), |
7720 | BAD_PC_WRITEBACK); | |
c19d1205 | 7721 | inst.instruction |= HWOFFSET_IMM; |
e2b0ab59 | 7722 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
26d97720 NS |
7723 | { |
7724 | /* Prefer + for zero encoded value. */ | |
7725 | if (!inst.operands[i].negative) | |
7726 | inst.instruction |= INDEX_UP; | |
7727 | ||
e2b0ab59 | 7728 | inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8; |
26d97720 | 7729 | } |
c19d1205 | 7730 | } |
a737bd4d NC |
7731 | } |
7732 | ||
8335d6aa JW |
7733 | /* Write immediate bits [7:0] to the following locations: |
7734 | ||
7735 | |28/24|23 19|18 16|15 4|3 0| | |
7736 | | 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| | |
7737 | ||
7738 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
7739 | ||
7740 | static void | |
7741 | neon_write_immbits (unsigned immbits) | |
7742 | { | |
7743 | inst.instruction |= immbits & 0xf; | |
7744 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
7745 | inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24); | |
7746 | } | |
7747 | ||
7748 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
7749 | ||
7750 | static void | |
7751 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
7752 | { | |
7753 | unsigned immlo = xlo ? *xlo : 0; | |
7754 | unsigned immhi = xhi ? *xhi : 0; | |
7755 | ||
7756 | switch (size) | |
7757 | { | |
7758 | case 8: | |
7759 | immlo = (~immlo) & 0xff; | |
7760 | break; | |
7761 | ||
7762 | case 16: | |
7763 | immlo = (~immlo) & 0xffff; | |
7764 | break; | |
7765 | ||
7766 | case 64: | |
7767 | immhi = (~immhi) & 0xffffffff; | |
7768 | /* fall through. */ | |
7769 | ||
7770 | case 32: | |
7771 | immlo = (~immlo) & 0xffffffff; | |
7772 | break; | |
7773 | ||
7774 | default: | |
7775 | abort (); | |
7776 | } | |
7777 | ||
7778 | if (xlo) | |
7779 | *xlo = immlo; | |
7780 | ||
7781 | if (xhi) | |
7782 | *xhi = immhi; | |
7783 | } | |
7784 | ||
7785 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
7786 | A, B, C, D. */ | |
09d92015 | 7787 | |
c19d1205 | 7788 | static int |
8335d6aa | 7789 | neon_bits_same_in_bytes (unsigned imm) |
09d92015 | 7790 | { |
8335d6aa JW |
7791 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) |
7792 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
7793 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
7794 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
7795 | } | |
a737bd4d | 7796 | |
8335d6aa | 7797 | /* For immediate of above form, return 0bABCD. */ |
09d92015 | 7798 | |
8335d6aa JW |
7799 | static unsigned |
7800 | neon_squash_bits (unsigned imm) | |
7801 | { | |
7802 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
7803 | | ((imm & 0x01000000) >> 21); | |
7804 | } | |
7805 | ||
7806 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ | |
7807 | ||
7808 | static unsigned | |
7809 | neon_qfloat_bits (unsigned imm) | |
7810 | { | |
7811 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); | |
7812 | } | |
7813 | ||
7814 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
7815 | the instruction. *OP is passed as the initial value of the op field, and | |
7816 | may be set to a different value depending on the constant (i.e. | |
7817 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
7818 | MVN). If the immediate looks like a repeated pattern then also | |
7819 | try smaller element sizes. */ | |
7820 | ||
7821 | static int | |
7822 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, | |
7823 | unsigned *immbits, int *op, int size, | |
7824 | enum neon_el_type type) | |
7825 | { | |
7826 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is | |
7827 | float. */ | |
7828 | if (type == NT_float && !float_p) | |
7829 | return FAIL; | |
7830 | ||
7831 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) | |
09d92015 | 7832 | { |
8335d6aa JW |
7833 | if (size != 32 || *op == 1) |
7834 | return FAIL; | |
7835 | *immbits = neon_qfloat_bits (immlo); | |
7836 | return 0xf; | |
7837 | } | |
7838 | ||
7839 | if (size == 64) | |
7840 | { | |
7841 | if (neon_bits_same_in_bytes (immhi) | |
7842 | && neon_bits_same_in_bytes (immlo)) | |
c19d1205 | 7843 | { |
8335d6aa JW |
7844 | if (*op == 1) |
7845 | return FAIL; | |
7846 | *immbits = (neon_squash_bits (immhi) << 4) | |
7847 | | neon_squash_bits (immlo); | |
7848 | *op = 1; | |
7849 | return 0xe; | |
c19d1205 | 7850 | } |
a737bd4d | 7851 | |
8335d6aa JW |
7852 | if (immhi != immlo) |
7853 | return FAIL; | |
7854 | } | |
a737bd4d | 7855 | |
8335d6aa | 7856 | if (size >= 32) |
09d92015 | 7857 | { |
8335d6aa | 7858 | if (immlo == (immlo & 0x000000ff)) |
c19d1205 | 7859 | { |
8335d6aa JW |
7860 | *immbits = immlo; |
7861 | return 0x0; | |
c19d1205 | 7862 | } |
8335d6aa | 7863 | else if (immlo == (immlo & 0x0000ff00)) |
c19d1205 | 7864 | { |
8335d6aa JW |
7865 | *immbits = immlo >> 8; |
7866 | return 0x2; | |
c19d1205 | 7867 | } |
8335d6aa JW |
7868 | else if (immlo == (immlo & 0x00ff0000)) |
7869 | { | |
7870 | *immbits = immlo >> 16; | |
7871 | return 0x4; | |
7872 | } | |
7873 | else if (immlo == (immlo & 0xff000000)) | |
7874 | { | |
7875 | *immbits = immlo >> 24; | |
7876 | return 0x6; | |
7877 | } | |
7878 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
7879 | { | |
7880 | *immbits = (immlo >> 8) & 0xff; | |
7881 | return 0xc; | |
7882 | } | |
7883 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
7884 | { | |
7885 | *immbits = (immlo >> 16) & 0xff; | |
7886 | return 0xd; | |
7887 | } | |
7888 | ||
7889 | if ((immlo & 0xffff) != (immlo >> 16)) | |
7890 | return FAIL; | |
7891 | immlo &= 0xffff; | |
09d92015 | 7892 | } |
a737bd4d | 7893 | |
8335d6aa | 7894 | if (size >= 16) |
4962c51a | 7895 | { |
8335d6aa JW |
7896 | if (immlo == (immlo & 0x000000ff)) |
7897 | { | |
7898 | *immbits = immlo; | |
7899 | return 0x8; | |
7900 | } | |
7901 | else if (immlo == (immlo & 0x0000ff00)) | |
7902 | { | |
7903 | *immbits = immlo >> 8; | |
7904 | return 0xa; | |
7905 | } | |
7906 | ||
7907 | if ((immlo & 0xff) != (immlo >> 8)) | |
7908 | return FAIL; | |
7909 | immlo &= 0xff; | |
4962c51a MS |
7910 | } |
7911 | ||
8335d6aa JW |
7912 | if (immlo == (immlo & 0x000000ff)) |
7913 | { | |
7914 | /* Don't allow MVN with 8-bit immediate. */ | |
7915 | if (*op == 1) | |
7916 | return FAIL; | |
7917 | *immbits = immlo; | |
7918 | return 0xe; | |
7919 | } | |
26d97720 | 7920 | |
8335d6aa | 7921 | return FAIL; |
c19d1205 | 7922 | } |
a737bd4d | 7923 | |
5fc177c8 | 7924 | #if defined BFD_HOST_64_BIT |
ba592044 AM |
7925 | /* Returns TRUE if double precision value V may be cast |
7926 | to single precision without loss of accuracy. */ | |
7927 | ||
7928 | static bfd_boolean | |
5fc177c8 | 7929 | is_double_a_single (bfd_int64_t v) |
ba592044 | 7930 | { |
5fc177c8 | 7931 | int exp = (int)((v >> 52) & 0x7FF); |
8fe3f3d6 | 7932 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
7933 | |
7934 | return (exp == 0 || exp == 0x7FF | |
7935 | || (exp >= 1023 - 126 && exp <= 1023 + 127)) | |
7936 | && (mantissa & 0x1FFFFFFFl) == 0; | |
7937 | } | |
7938 | ||
3739860c | 7939 | /* Returns a double precision value casted to single precision |
ba592044 AM |
7940 | (ignoring the least significant bits in exponent and mantissa). */ |
7941 | ||
7942 | static int | |
5fc177c8 | 7943 | double_to_single (bfd_int64_t v) |
ba592044 AM |
7944 | { |
7945 | int sign = (int) ((v >> 63) & 1l); | |
5fc177c8 | 7946 | int exp = (int) ((v >> 52) & 0x7FF); |
8fe3f3d6 | 7947 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
7948 | |
7949 | if (exp == 0x7FF) | |
7950 | exp = 0xFF; | |
7951 | else | |
7952 | { | |
7953 | exp = exp - 1023 + 127; | |
7954 | if (exp >= 0xFF) | |
7955 | { | |
7956 | /* Infinity. */ | |
7957 | exp = 0x7F; | |
7958 | mantissa = 0; | |
7959 | } | |
7960 | else if (exp < 0) | |
7961 | { | |
7962 | /* No denormalized numbers. */ | |
7963 | exp = 0; | |
7964 | mantissa = 0; | |
7965 | } | |
7966 | } | |
7967 | mantissa >>= 29; | |
7968 | return (sign << 31) | (exp << 23) | mantissa; | |
7969 | } | |
5fc177c8 | 7970 | #endif /* BFD_HOST_64_BIT */ |
ba592044 | 7971 | |
8335d6aa JW |
7972 | enum lit_type |
7973 | { | |
7974 | CONST_THUMB, | |
7975 | CONST_ARM, | |
7976 | CONST_VEC | |
7977 | }; | |
7978 | ||
ba592044 AM |
7979 | static void do_vfp_nsyn_opcode (const char *); |
7980 | ||
e2b0ab59 | 7981 | /* inst.relocs[0].exp describes an "=expr" load pseudo-operation. |
c19d1205 ZW |
7982 | Determine whether it can be performed with a move instruction; if |
7983 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
7984 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
7985 | load and return FALSE. If this is not a valid thing to do in the | |
7986 | current context, set inst.error and return TRUE. | |
a737bd4d | 7987 | |
c19d1205 ZW |
7988 | inst.operands[i] describes the destination register. */ |
7989 | ||
c921be7d | 7990 | static bfd_boolean |
8335d6aa | 7991 | move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3) |
c19d1205 | 7992 | { |
53365c0d | 7993 | unsigned long tbit; |
8335d6aa JW |
7994 | bfd_boolean thumb_p = (t == CONST_THUMB); |
7995 | bfd_boolean arm_p = (t == CONST_ARM); | |
53365c0d PB |
7996 | |
7997 | if (thumb_p) | |
7998 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
7999 | else | |
8000 | tbit = LOAD_BIT; | |
8001 | ||
8002 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 8003 | { |
c19d1205 | 8004 | inst.error = _("invalid pseudo operation"); |
c921be7d | 8005 | return TRUE; |
09d92015 | 8006 | } |
ba592044 | 8007 | |
e2b0ab59 AV |
8008 | if (inst.relocs[0].exp.X_op != O_constant |
8009 | && inst.relocs[0].exp.X_op != O_symbol | |
8010 | && inst.relocs[0].exp.X_op != O_big) | |
09d92015 MM |
8011 | { |
8012 | inst.error = _("constant expression expected"); | |
c921be7d | 8013 | return TRUE; |
09d92015 | 8014 | } |
ba592044 | 8015 | |
e2b0ab59 AV |
8016 | if (inst.relocs[0].exp.X_op == O_constant |
8017 | || inst.relocs[0].exp.X_op == O_big) | |
8335d6aa | 8018 | { |
5fc177c8 NC |
8019 | #if defined BFD_HOST_64_BIT |
8020 | bfd_int64_t v; | |
8021 | #else | |
ba592044 | 8022 | offsetT v; |
5fc177c8 | 8023 | #endif |
e2b0ab59 | 8024 | if (inst.relocs[0].exp.X_op == O_big) |
8335d6aa | 8025 | { |
ba592044 AM |
8026 | LITTLENUM_TYPE w[X_PRECISION]; |
8027 | LITTLENUM_TYPE * l; | |
8028 | ||
e2b0ab59 | 8029 | if (inst.relocs[0].exp.X_add_number == -1) |
8335d6aa | 8030 | { |
ba592044 AM |
8031 | gen_to_words (w, X_PRECISION, E_PRECISION); |
8032 | l = w; | |
8033 | /* FIXME: Should we check words w[2..5] ? */ | |
8335d6aa | 8034 | } |
ba592044 AM |
8035 | else |
8036 | l = generic_bignum; | |
3739860c | 8037 | |
5fc177c8 NC |
8038 | #if defined BFD_HOST_64_BIT |
8039 | v = | |
8040 | ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK) | |
8041 | << LITTLENUM_NUMBER_OF_BITS) | |
8042 | | ((bfd_int64_t) l[2] & LITTLENUM_MASK)) | |
8043 | << LITTLENUM_NUMBER_OF_BITS) | |
8044 | | ((bfd_int64_t) l[1] & LITTLENUM_MASK)) | |
8045 | << LITTLENUM_NUMBER_OF_BITS) | |
8046 | | ((bfd_int64_t) l[0] & LITTLENUM_MASK)); | |
8047 | #else | |
ba592044 AM |
8048 | v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) |
8049 | | (l[0] & LITTLENUM_MASK); | |
5fc177c8 | 8050 | #endif |
8335d6aa | 8051 | } |
ba592044 | 8052 | else |
e2b0ab59 | 8053 | v = inst.relocs[0].exp.X_add_number; |
ba592044 AM |
8054 | |
8055 | if (!inst.operands[i].issingle) | |
8335d6aa | 8056 | { |
12569877 | 8057 | if (thumb_p) |
8335d6aa | 8058 | { |
53445554 TP |
8059 | /* LDR should not use lead in a flag-setting instruction being |
8060 | chosen so we do not check whether movs can be used. */ | |
12569877 | 8061 | |
53445554 | 8062 | if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) |
ff8646ee | 8063 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) |
53445554 TP |
8064 | && inst.operands[i].reg != 13 |
8065 | && inst.operands[i].reg != 15) | |
12569877 | 8066 | { |
fc289b0a TP |
8067 | /* Check if on thumb2 it can be done with a mov.w, mvn or |
8068 | movw instruction. */ | |
12569877 AM |
8069 | unsigned int newimm; |
8070 | bfd_boolean isNegated; | |
8071 | ||
8072 | newimm = encode_thumb32_immediate (v); | |
8073 | if (newimm != (unsigned int) FAIL) | |
8074 | isNegated = FALSE; | |
8075 | else | |
8076 | { | |
582cfe03 | 8077 | newimm = encode_thumb32_immediate (~v); |
12569877 AM |
8078 | if (newimm != (unsigned int) FAIL) |
8079 | isNegated = TRUE; | |
8080 | } | |
8081 | ||
fc289b0a TP |
8082 | /* The number can be loaded with a mov.w or mvn |
8083 | instruction. */ | |
ff8646ee TP |
8084 | if (newimm != (unsigned int) FAIL |
8085 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
12569877 | 8086 | { |
fc289b0a | 8087 | inst.instruction = (0xf04f0000 /* MOV.W. */ |
582cfe03 | 8088 | | (inst.operands[i].reg << 8)); |
fc289b0a | 8089 | /* Change to MOVN. */ |
582cfe03 | 8090 | inst.instruction |= (isNegated ? 0x200000 : 0); |
12569877 AM |
8091 | inst.instruction |= (newimm & 0x800) << 15; |
8092 | inst.instruction |= (newimm & 0x700) << 4; | |
8093 | inst.instruction |= (newimm & 0x0ff); | |
8094 | return TRUE; | |
8095 | } | |
fc289b0a | 8096 | /* The number can be loaded with a movw instruction. */ |
ff8646ee TP |
8097 | else if ((v & ~0xFFFF) == 0 |
8098 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
3739860c | 8099 | { |
582cfe03 | 8100 | int imm = v & 0xFFFF; |
12569877 | 8101 | |
582cfe03 | 8102 | inst.instruction = 0xf2400000; /* MOVW. */ |
12569877 AM |
8103 | inst.instruction |= (inst.operands[i].reg << 8); |
8104 | inst.instruction |= (imm & 0xf000) << 4; | |
8105 | inst.instruction |= (imm & 0x0800) << 15; | |
8106 | inst.instruction |= (imm & 0x0700) << 4; | |
8107 | inst.instruction |= (imm & 0x00ff); | |
8108 | return TRUE; | |
8109 | } | |
8110 | } | |
8335d6aa | 8111 | } |
12569877 | 8112 | else if (arm_p) |
ba592044 AM |
8113 | { |
8114 | int value = encode_arm_immediate (v); | |
12569877 | 8115 | |
ba592044 AM |
8116 | if (value != FAIL) |
8117 | { | |
8118 | /* This can be done with a mov instruction. */ | |
8119 | inst.instruction &= LITERAL_MASK; | |
8120 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
8121 | inst.instruction |= value & 0xfff; | |
8122 | return TRUE; | |
8123 | } | |
8335d6aa | 8124 | |
ba592044 AM |
8125 | value = encode_arm_immediate (~ v); |
8126 | if (value != FAIL) | |
8127 | { | |
8128 | /* This can be done with a mvn instruction. */ | |
8129 | inst.instruction &= LITERAL_MASK; | |
8130 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
8131 | inst.instruction |= value & 0xfff; | |
8132 | return TRUE; | |
8133 | } | |
8134 | } | |
934c2632 | 8135 | else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)) |
8335d6aa | 8136 | { |
ba592044 AM |
8137 | int op = 0; |
8138 | unsigned immbits = 0; | |
8139 | unsigned immlo = inst.operands[1].imm; | |
8140 | unsigned immhi = inst.operands[1].regisimm | |
8141 | ? inst.operands[1].reg | |
e2b0ab59 | 8142 | : inst.relocs[0].exp.X_unsigned |
ba592044 AM |
8143 | ? 0 |
8144 | : ((bfd_int64_t)((int) immlo)) >> 32; | |
8145 | int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8146 | &op, 64, NT_invtype); | |
8147 | ||
8148 | if (cmode == FAIL) | |
8149 | { | |
8150 | neon_invert_size (&immlo, &immhi, 64); | |
8151 | op = !op; | |
8152 | cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8153 | &op, 64, NT_invtype); | |
8154 | } | |
8155 | ||
8156 | if (cmode != FAIL) | |
8157 | { | |
8158 | inst.instruction = (inst.instruction & VLDR_VMOV_SAME) | |
8159 | | (1 << 23) | |
8160 | | (cmode << 8) | |
8161 | | (op << 5) | |
8162 | | (1 << 4); | |
8163 | ||
8164 | /* Fill other bits in vmov encoding for both thumb and arm. */ | |
8165 | if (thumb_mode) | |
eff0bc54 | 8166 | inst.instruction |= (0x7U << 29) | (0xF << 24); |
ba592044 | 8167 | else |
eff0bc54 | 8168 | inst.instruction |= (0xFU << 28) | (0x1 << 25); |
ba592044 AM |
8169 | neon_write_immbits (immbits); |
8170 | return TRUE; | |
8171 | } | |
8335d6aa JW |
8172 | } |
8173 | } | |
8335d6aa | 8174 | |
ba592044 AM |
8175 | if (t == CONST_VEC) |
8176 | { | |
8177 | /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */ | |
8178 | if (inst.operands[i].issingle | |
8179 | && is_quarter_float (inst.operands[1].imm) | |
8180 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd)) | |
8335d6aa | 8181 | { |
ba592044 AM |
8182 | inst.operands[1].imm = |
8183 | neon_qfloat_bits (v); | |
8184 | do_vfp_nsyn_opcode ("fconsts"); | |
8185 | return TRUE; | |
8335d6aa | 8186 | } |
5fc177c8 NC |
8187 | |
8188 | /* If our host does not support a 64-bit type then we cannot perform | |
8189 | the following optimization. This mean that there will be a | |
8190 | discrepancy between the output produced by an assembler built for | |
8191 | a 32-bit-only host and the output produced from a 64-bit host, but | |
8192 | this cannot be helped. */ | |
8193 | #if defined BFD_HOST_64_BIT | |
ba592044 AM |
8194 | else if (!inst.operands[1].issingle |
8195 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
8335d6aa | 8196 | { |
ba592044 AM |
8197 | if (is_double_a_single (v) |
8198 | && is_quarter_float (double_to_single (v))) | |
8199 | { | |
8200 | inst.operands[1].imm = | |
8201 | neon_qfloat_bits (double_to_single (v)); | |
8202 | do_vfp_nsyn_opcode ("fconstd"); | |
8203 | return TRUE; | |
8204 | } | |
8335d6aa | 8205 | } |
5fc177c8 | 8206 | #endif |
8335d6aa JW |
8207 | } |
8208 | } | |
8209 | ||
8210 | if (add_to_lit_pool ((!inst.operands[i].isvec | |
8211 | || inst.operands[i].issingle) ? 4 : 8) == FAIL) | |
8212 | return TRUE; | |
8213 | ||
8214 | inst.operands[1].reg = REG_PC; | |
8215 | inst.operands[1].isreg = 1; | |
8216 | inst.operands[1].preind = 1; | |
e2b0ab59 AV |
8217 | inst.relocs[0].pc_rel = 1; |
8218 | inst.relocs[0].type = (thumb_p | |
8335d6aa JW |
8219 | ? BFD_RELOC_ARM_THUMB_OFFSET |
8220 | : (mode_3 | |
8221 | ? BFD_RELOC_ARM_HWLITERAL | |
8222 | : BFD_RELOC_ARM_LITERAL)); | |
8223 | return FALSE; | |
8224 | } | |
8225 | ||
8226 | /* inst.operands[i] was set up by parse_address. Encode it into an | |
8227 | ARM-format instruction. Reject all forms which cannot be encoded | |
8228 | into a coprocessor load/store instruction. If wb_ok is false, | |
8229 | reject use of writeback; if unind_ok is false, reject use of | |
8230 | unindexed addressing. If reloc_override is not 0, use it instead | |
8231 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one | |
8232 | (in which case it is preserved). */ | |
8233 | ||
8234 | static int | |
8235 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
8236 | { | |
8237 | if (!inst.operands[i].isreg) | |
8238 | { | |
99b2a2dd NC |
8239 | /* PR 18256 */ |
8240 | if (! inst.operands[0].isvec) | |
8241 | { | |
8242 | inst.error = _("invalid co-processor operand"); | |
8243 | return FAIL; | |
8244 | } | |
8335d6aa JW |
8245 | if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE)) |
8246 | return SUCCESS; | |
8247 | } | |
8248 | ||
8249 | inst.instruction |= inst.operands[i].reg << 16; | |
8250 | ||
8251 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); | |
8252 | ||
8253 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ | |
8254 | { | |
8255 | gas_assert (!inst.operands[i].writeback); | |
8256 | if (!unind_ok) | |
8257 | { | |
8258 | inst.error = _("instruction does not support unindexed addressing"); | |
8259 | return FAIL; | |
8260 | } | |
8261 | inst.instruction |= inst.operands[i].imm; | |
8262 | inst.instruction |= INDEX_UP; | |
8263 | return SUCCESS; | |
8264 | } | |
8265 | ||
8266 | if (inst.operands[i].preind) | |
8267 | inst.instruction |= PRE_INDEX; | |
8268 | ||
8269 | if (inst.operands[i].writeback) | |
09d92015 | 8270 | { |
8335d6aa | 8271 | if (inst.operands[i].reg == REG_PC) |
c19d1205 | 8272 | { |
8335d6aa JW |
8273 | inst.error = _("pc may not be used with write-back"); |
8274 | return FAIL; | |
c19d1205 | 8275 | } |
8335d6aa | 8276 | if (!wb_ok) |
c19d1205 | 8277 | { |
8335d6aa JW |
8278 | inst.error = _("instruction does not support writeback"); |
8279 | return FAIL; | |
c19d1205 | 8280 | } |
8335d6aa | 8281 | inst.instruction |= WRITE_BACK; |
09d92015 MM |
8282 | } |
8283 | ||
8335d6aa | 8284 | if (reloc_override) |
e2b0ab59 AV |
8285 | inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override; |
8286 | else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC | |
8287 | || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2) | |
8288 | && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0) | |
c19d1205 | 8289 | { |
8335d6aa | 8290 | if (thumb_mode) |
e2b0ab59 | 8291 | inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM; |
8335d6aa | 8292 | else |
e2b0ab59 | 8293 | inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM; |
c19d1205 | 8294 | } |
8335d6aa JW |
8295 | |
8296 | /* Prefer + for zero encoded value. */ | |
8297 | if (!inst.operands[i].negative) | |
8298 | inst.instruction |= INDEX_UP; | |
8299 | ||
8300 | return SUCCESS; | |
09d92015 MM |
8301 | } |
8302 | ||
5f4273c7 | 8303 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
8304 | First some generics; their names are taken from the conventional |
8305 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 8306 | |
a737bd4d | 8307 | static void |
c19d1205 | 8308 | do_noargs (void) |
09d92015 | 8309 | { |
c19d1205 | 8310 | } |
a737bd4d | 8311 | |
c19d1205 ZW |
8312 | static void |
8313 | do_rd (void) | |
8314 | { | |
8315 | inst.instruction |= inst.operands[0].reg << 12; | |
8316 | } | |
a737bd4d | 8317 | |
16a1fa25 TP |
8318 | static void |
8319 | do_rn (void) | |
8320 | { | |
8321 | inst.instruction |= inst.operands[0].reg << 16; | |
8322 | } | |
8323 | ||
c19d1205 ZW |
8324 | static void |
8325 | do_rd_rm (void) | |
8326 | { | |
8327 | inst.instruction |= inst.operands[0].reg << 12; | |
8328 | inst.instruction |= inst.operands[1].reg; | |
8329 | } | |
09d92015 | 8330 | |
9eb6c0f1 MGD |
8331 | static void |
8332 | do_rm_rn (void) | |
8333 | { | |
8334 | inst.instruction |= inst.operands[0].reg; | |
8335 | inst.instruction |= inst.operands[1].reg << 16; | |
8336 | } | |
8337 | ||
c19d1205 ZW |
8338 | static void |
8339 | do_rd_rn (void) | |
8340 | { | |
8341 | inst.instruction |= inst.operands[0].reg << 12; | |
8342 | inst.instruction |= inst.operands[1].reg << 16; | |
8343 | } | |
a737bd4d | 8344 | |
c19d1205 ZW |
8345 | static void |
8346 | do_rn_rd (void) | |
8347 | { | |
8348 | inst.instruction |= inst.operands[0].reg << 16; | |
8349 | inst.instruction |= inst.operands[1].reg << 12; | |
8350 | } | |
09d92015 | 8351 | |
4ed7ed8d TP |
8352 | static void |
8353 | do_tt (void) | |
8354 | { | |
8355 | inst.instruction |= inst.operands[0].reg << 8; | |
8356 | inst.instruction |= inst.operands[1].reg << 16; | |
8357 | } | |
8358 | ||
59d09be6 MGD |
8359 | static bfd_boolean |
8360 | check_obsolete (const arm_feature_set *feature, const char *msg) | |
8361 | { | |
8362 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
8363 | { | |
5c3696f8 | 8364 | as_tsktsk ("%s", msg); |
59d09be6 MGD |
8365 | return TRUE; |
8366 | } | |
8367 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
8368 | { | |
8369 | as_bad ("%s", msg); | |
8370 | return TRUE; | |
8371 | } | |
8372 | ||
8373 | return FALSE; | |
8374 | } | |
8375 | ||
c19d1205 ZW |
8376 | static void |
8377 | do_rd_rm_rn (void) | |
8378 | { | |
9a64e435 | 8379 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 8380 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 8381 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
8382 | { |
8383 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
8384 | _("Rn must not overlap other operands")); | |
8385 | ||
59d09be6 MGD |
8386 | /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7. |
8387 | */ | |
8388 | if (!check_obsolete (&arm_ext_v8, | |
8389 | _("swp{b} use is obsoleted for ARMv8 and later")) | |
8390 | && warn_on_deprecated | |
8391 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6)) | |
5c3696f8 | 8392 | as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7")); |
56adecf4 | 8393 | } |
59d09be6 | 8394 | |
c19d1205 ZW |
8395 | inst.instruction |= inst.operands[0].reg << 12; |
8396 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 8397 | inst.instruction |= Rn << 16; |
c19d1205 | 8398 | } |
09d92015 | 8399 | |
c19d1205 ZW |
8400 | static void |
8401 | do_rd_rn_rm (void) | |
8402 | { | |
8403 | inst.instruction |= inst.operands[0].reg << 12; | |
8404 | inst.instruction |= inst.operands[1].reg << 16; | |
8405 | inst.instruction |= inst.operands[2].reg; | |
8406 | } | |
a737bd4d | 8407 | |
c19d1205 ZW |
8408 | static void |
8409 | do_rm_rd_rn (void) | |
8410 | { | |
5be8be5d | 8411 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
e2b0ab59 AV |
8412 | constraint (((inst.relocs[0].exp.X_op != O_constant |
8413 | && inst.relocs[0].exp.X_op != O_illegal) | |
8414 | || inst.relocs[0].exp.X_add_number != 0), | |
5be8be5d | 8415 | BAD_ADDR_MODE); |
c19d1205 ZW |
8416 | inst.instruction |= inst.operands[0].reg; |
8417 | inst.instruction |= inst.operands[1].reg << 12; | |
8418 | inst.instruction |= inst.operands[2].reg << 16; | |
8419 | } | |
09d92015 | 8420 | |
c19d1205 ZW |
8421 | static void |
8422 | do_imm0 (void) | |
8423 | { | |
8424 | inst.instruction |= inst.operands[0].imm; | |
8425 | } | |
09d92015 | 8426 | |
c19d1205 ZW |
8427 | static void |
8428 | do_rd_cpaddr (void) | |
8429 | { | |
8430 | inst.instruction |= inst.operands[0].reg << 12; | |
8431 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 8432 | } |
a737bd4d | 8433 | |
c19d1205 ZW |
8434 | /* ARM instructions, in alphabetical order by function name (except |
8435 | that wrapper functions appear immediately after the function they | |
8436 | wrap). */ | |
09d92015 | 8437 | |
c19d1205 ZW |
8438 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
8439 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
8440 | |
8441 | static void | |
c19d1205 | 8442 | do_adr (void) |
09d92015 | 8443 | { |
c19d1205 | 8444 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 8445 | |
c19d1205 ZW |
8446 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8447 | out to be negative. */ | |
e2b0ab59 AV |
8448 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
8449 | inst.relocs[0].pc_rel = 1; | |
8450 | inst.relocs[0].exp.X_add_number -= 8; | |
52a86f84 | 8451 | |
fc6141f0 | 8452 | if (support_interwork |
e2b0ab59 AV |
8453 | && inst.relocs[0].exp.X_op == O_symbol |
8454 | && inst.relocs[0].exp.X_add_symbol != NULL | |
8455 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
8456 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
8457 | inst.relocs[0].exp.X_add_number |= 1; | |
c19d1205 | 8458 | } |
b99bd4ef | 8459 | |
c19d1205 ZW |
8460 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
8461 | into a relative address of the form: | |
8462 | add rd, pc, #low(label-.-8)" | |
8463 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 8464 | |
c19d1205 ZW |
8465 | static void |
8466 | do_adrl (void) | |
8467 | { | |
8468 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 8469 | |
c19d1205 ZW |
8470 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8471 | out to be negative. */ | |
e2b0ab59 AV |
8472 | inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE; |
8473 | inst.relocs[0].pc_rel = 1; | |
c19d1205 | 8474 | inst.size = INSN_SIZE * 2; |
e2b0ab59 | 8475 | inst.relocs[0].exp.X_add_number -= 8; |
52a86f84 | 8476 | |
fc6141f0 | 8477 | if (support_interwork |
e2b0ab59 AV |
8478 | && inst.relocs[0].exp.X_op == O_symbol |
8479 | && inst.relocs[0].exp.X_add_symbol != NULL | |
8480 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
8481 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
8482 | inst.relocs[0].exp.X_add_number |= 1; | |
b99bd4ef NC |
8483 | } |
8484 | ||
b99bd4ef | 8485 | static void |
c19d1205 | 8486 | do_arit (void) |
b99bd4ef | 8487 | { |
e2b0ab59 AV |
8488 | constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
8489 | && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
a9f02af8 | 8490 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
8491 | if (!inst.operands[1].present) |
8492 | inst.operands[1].reg = inst.operands[0].reg; | |
8493 | inst.instruction |= inst.operands[0].reg << 12; | |
8494 | inst.instruction |= inst.operands[1].reg << 16; | |
8495 | encode_arm_shifter_operand (2); | |
8496 | } | |
b99bd4ef | 8497 | |
62b3e311 PB |
8498 | static void |
8499 | do_barrier (void) | |
8500 | { | |
8501 | if (inst.operands[0].present) | |
ccb84d65 | 8502 | inst.instruction |= inst.operands[0].imm; |
62b3e311 PB |
8503 | else |
8504 | inst.instruction |= 0xf; | |
8505 | } | |
8506 | ||
c19d1205 ZW |
8507 | static void |
8508 | do_bfc (void) | |
8509 | { | |
8510 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
8511 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8512 | /* The instruction encoding stores the LSB and MSB, | |
8513 | not the LSB and width. */ | |
8514 | inst.instruction |= inst.operands[0].reg << 12; | |
8515 | inst.instruction |= inst.operands[1].imm << 7; | |
8516 | inst.instruction |= (msb - 1) << 16; | |
8517 | } | |
b99bd4ef | 8518 | |
c19d1205 ZW |
8519 | static void |
8520 | do_bfi (void) | |
8521 | { | |
8522 | unsigned int msb; | |
b99bd4ef | 8523 | |
c19d1205 ZW |
8524 | /* #0 in second position is alternative syntax for bfc, which is |
8525 | the same instruction but with REG_PC in the Rm field. */ | |
8526 | if (!inst.operands[1].isreg) | |
8527 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 8528 | |
c19d1205 ZW |
8529 | msb = inst.operands[2].imm + inst.operands[3].imm; |
8530 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8531 | /* The instruction encoding stores the LSB and MSB, | |
8532 | not the LSB and width. */ | |
8533 | inst.instruction |= inst.operands[0].reg << 12; | |
8534 | inst.instruction |= inst.operands[1].reg; | |
8535 | inst.instruction |= inst.operands[2].imm << 7; | |
8536 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
8537 | } |
8538 | ||
b99bd4ef | 8539 | static void |
c19d1205 | 8540 | do_bfx (void) |
b99bd4ef | 8541 | { |
c19d1205 ZW |
8542 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
8543 | _("bit-field extends past end of register")); | |
8544 | inst.instruction |= inst.operands[0].reg << 12; | |
8545 | inst.instruction |= inst.operands[1].reg; | |
8546 | inst.instruction |= inst.operands[2].imm << 7; | |
8547 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
8548 | } | |
09d92015 | 8549 | |
c19d1205 ZW |
8550 | /* ARM V5 breakpoint instruction (argument parse) |
8551 | BKPT <16 bit unsigned immediate> | |
8552 | Instruction is not conditional. | |
8553 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
8554 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 8555 | |
c19d1205 ZW |
8556 | static void |
8557 | do_bkpt (void) | |
8558 | { | |
8559 | /* Top 12 of 16 bits to bits 19:8. */ | |
8560 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 8561 | |
c19d1205 ZW |
8562 | /* Bottom 4 of 16 bits to bits 3:0. */ |
8563 | inst.instruction |= inst.operands[0].imm & 0xf; | |
8564 | } | |
09d92015 | 8565 | |
c19d1205 ZW |
8566 | static void |
8567 | encode_branch (int default_reloc) | |
8568 | { | |
8569 | if (inst.operands[0].hasreloc) | |
8570 | { | |
0855e32b NS |
8571 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32 |
8572 | && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL, | |
8573 | _("the only valid suffixes here are '(plt)' and '(tlscall)'")); | |
e2b0ab59 | 8574 | inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 |
0855e32b NS |
8575 | ? BFD_RELOC_ARM_PLT32 |
8576 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 8577 | } |
b99bd4ef | 8578 | else |
e2b0ab59 AV |
8579 | inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc; |
8580 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
8581 | } |
8582 | ||
b99bd4ef | 8583 | static void |
c19d1205 | 8584 | do_branch (void) |
b99bd4ef | 8585 | { |
39b41c9c PB |
8586 | #ifdef OBJ_ELF |
8587 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8588 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8589 | else | |
8590 | #endif | |
8591 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
8592 | } | |
8593 | ||
8594 | static void | |
8595 | do_bl (void) | |
8596 | { | |
8597 | #ifdef OBJ_ELF | |
8598 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8599 | { | |
8600 | if (inst.cond == COND_ALWAYS) | |
8601 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
8602 | else | |
8603 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8604 | } | |
8605 | else | |
8606 | #endif | |
8607 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 8608 | } |
b99bd4ef | 8609 | |
c19d1205 ZW |
8610 | /* ARM V5 branch-link-exchange instruction (argument parse) |
8611 | BLX <target_addr> ie BLX(1) | |
8612 | BLX{<condition>} <Rm> ie BLX(2) | |
8613 | Unfortunately, there are two different opcodes for this mnemonic. | |
8614 | So, the insns[].value is not used, and the code here zaps values | |
8615 | into inst.instruction. | |
8616 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 8617 | |
c19d1205 ZW |
8618 | static void |
8619 | do_blx (void) | |
8620 | { | |
8621 | if (inst.operands[0].isreg) | |
b99bd4ef | 8622 | { |
c19d1205 ZW |
8623 | /* Arg is a register; the opcode provided by insns[] is correct. |
8624 | It is not illegal to do "blx pc", just useless. */ | |
8625 | if (inst.operands[0].reg == REG_PC) | |
8626 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 8627 | |
c19d1205 ZW |
8628 | inst.instruction |= inst.operands[0].reg; |
8629 | } | |
8630 | else | |
b99bd4ef | 8631 | { |
c19d1205 | 8632 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
8633 | conditionally, and the opcode must be adjusted. |
8634 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
8635 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 8636 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 8637 | inst.instruction = 0xfa000000; |
267bf995 | 8638 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 8639 | } |
c19d1205 ZW |
8640 | } |
8641 | ||
8642 | static void | |
8643 | do_bx (void) | |
8644 | { | |
845b51d6 PB |
8645 | bfd_boolean want_reloc; |
8646 | ||
c19d1205 ZW |
8647 | if (inst.operands[0].reg == REG_PC) |
8648 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 8649 | |
c19d1205 | 8650 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
8651 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
8652 | it is for ARMv4t or earlier. */ | |
8653 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
4d354d8b TP |
8654 | if (!ARM_FEATURE_ZERO (selected_object_arch) |
8655 | && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5)) | |
845b51d6 PB |
8656 | want_reloc = TRUE; |
8657 | ||
5ad34203 | 8658 | #ifdef OBJ_ELF |
845b51d6 | 8659 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 8660 | #endif |
584206db | 8661 | want_reloc = FALSE; |
845b51d6 PB |
8662 | |
8663 | if (want_reloc) | |
e2b0ab59 | 8664 | inst.relocs[0].type = BFD_RELOC_ARM_V4BX; |
09d92015 MM |
8665 | } |
8666 | ||
c19d1205 ZW |
8667 | |
8668 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
8669 | |
8670 | static void | |
c19d1205 | 8671 | do_bxj (void) |
a737bd4d | 8672 | { |
c19d1205 ZW |
8673 | if (inst.operands[0].reg == REG_PC) |
8674 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
8675 | ||
8676 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
8677 | } |
8678 | ||
c19d1205 ZW |
8679 | /* Co-processor data operation: |
8680 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
8681 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
8682 | static void | |
8683 | do_cdp (void) | |
8684 | { | |
8685 | inst.instruction |= inst.operands[0].reg << 8; | |
8686 | inst.instruction |= inst.operands[1].imm << 20; | |
8687 | inst.instruction |= inst.operands[2].reg << 12; | |
8688 | inst.instruction |= inst.operands[3].reg << 16; | |
8689 | inst.instruction |= inst.operands[4].reg; | |
8690 | inst.instruction |= inst.operands[5].imm << 5; | |
8691 | } | |
a737bd4d NC |
8692 | |
8693 | static void | |
c19d1205 | 8694 | do_cmp (void) |
a737bd4d | 8695 | { |
c19d1205 ZW |
8696 | inst.instruction |= inst.operands[0].reg << 16; |
8697 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
8698 | } |
8699 | ||
c19d1205 ZW |
8700 | /* Transfer between coprocessor and ARM registers. |
8701 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
8702 | MRC2 | |
8703 | MCR{cond} | |
8704 | MCR2 | |
8705 | ||
8706 | No special properties. */ | |
09d92015 | 8707 | |
dcbd0d71 MGD |
8708 | struct deprecated_coproc_regs_s |
8709 | { | |
8710 | unsigned cp; | |
8711 | int opc1; | |
8712 | unsigned crn; | |
8713 | unsigned crm; | |
8714 | int opc2; | |
8715 | arm_feature_set deprecated; | |
8716 | arm_feature_set obsoleted; | |
8717 | const char *dep_msg; | |
8718 | const char *obs_msg; | |
8719 | }; | |
8720 | ||
8721 | #define DEPR_ACCESS_V8 \ | |
8722 | N_("This coprocessor register access is deprecated in ARMv8") | |
8723 | ||
8724 | /* Table of all deprecated coprocessor registers. */ | |
8725 | static struct deprecated_coproc_regs_s deprecated_coproc_regs[] = | |
8726 | { | |
8727 | {15, 0, 7, 10, 5, /* CP15DMB. */ | |
823d2571 | 8728 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8729 | DEPR_ACCESS_V8, NULL}, |
8730 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
823d2571 | 8731 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8732 | DEPR_ACCESS_V8, NULL}, |
8733 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
823d2571 | 8734 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8735 | DEPR_ACCESS_V8, NULL}, |
8736 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
823d2571 | 8737 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8738 | DEPR_ACCESS_V8, NULL}, |
8739 | {14, 6, 0, 0, 0, /* TEECR. */ | |
823d2571 | 8740 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8741 | DEPR_ACCESS_V8, NULL}, |
8742 | }; | |
8743 | ||
8744 | #undef DEPR_ACCESS_V8 | |
8745 | ||
8746 | static const size_t deprecated_coproc_reg_count = | |
8747 | sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]); | |
8748 | ||
09d92015 | 8749 | static void |
c19d1205 | 8750 | do_co_reg (void) |
09d92015 | 8751 | { |
fdfde340 | 8752 | unsigned Rd; |
dcbd0d71 | 8753 | size_t i; |
fdfde340 JM |
8754 | |
8755 | Rd = inst.operands[2].reg; | |
8756 | if (thumb_mode) | |
8757 | { | |
8758 | if (inst.instruction == 0xee000010 | |
8759 | || inst.instruction == 0xfe000010) | |
8760 | /* MCR, MCR2 */ | |
8761 | reject_bad_reg (Rd); | |
5c8ed6a4 | 8762 | else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
fdfde340 JM |
8763 | /* MRC, MRC2 */ |
8764 | constraint (Rd == REG_SP, BAD_SP); | |
8765 | } | |
8766 | else | |
8767 | { | |
8768 | /* MCR */ | |
8769 | if (inst.instruction == 0xe000010) | |
8770 | constraint (Rd == REG_PC, BAD_PC); | |
8771 | } | |
8772 | ||
dcbd0d71 MGD |
8773 | for (i = 0; i < deprecated_coproc_reg_count; ++i) |
8774 | { | |
8775 | const struct deprecated_coproc_regs_s *r = | |
8776 | deprecated_coproc_regs + i; | |
8777 | ||
8778 | if (inst.operands[0].reg == r->cp | |
8779 | && inst.operands[1].imm == r->opc1 | |
8780 | && inst.operands[3].reg == r->crn | |
8781 | && inst.operands[4].reg == r->crm | |
8782 | && inst.operands[5].imm == r->opc2) | |
8783 | { | |
b10bf8c5 | 8784 | if (! ARM_CPU_IS_ANY (cpu_variant) |
477330fc | 8785 | && warn_on_deprecated |
dcbd0d71 | 8786 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) |
5c3696f8 | 8787 | as_tsktsk ("%s", r->dep_msg); |
dcbd0d71 MGD |
8788 | } |
8789 | } | |
fdfde340 | 8790 | |
c19d1205 ZW |
8791 | inst.instruction |= inst.operands[0].reg << 8; |
8792 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 8793 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
8794 | inst.instruction |= inst.operands[3].reg << 16; |
8795 | inst.instruction |= inst.operands[4].reg; | |
8796 | inst.instruction |= inst.operands[5].imm << 5; | |
8797 | } | |
09d92015 | 8798 | |
c19d1205 ZW |
8799 | /* Transfer between coprocessor register and pair of ARM registers. |
8800 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
8801 | MCRR2 | |
8802 | MRRC{cond} | |
8803 | MRRC2 | |
b99bd4ef | 8804 | |
c19d1205 | 8805 | Two XScale instructions are special cases of these: |
09d92015 | 8806 | |
c19d1205 ZW |
8807 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
8808 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 8809 | |
5f4273c7 | 8810 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 8811 | |
c19d1205 ZW |
8812 | static void |
8813 | do_co_reg2c (void) | |
8814 | { | |
fdfde340 JM |
8815 | unsigned Rd, Rn; |
8816 | ||
8817 | Rd = inst.operands[2].reg; | |
8818 | Rn = inst.operands[3].reg; | |
8819 | ||
8820 | if (thumb_mode) | |
8821 | { | |
8822 | reject_bad_reg (Rd); | |
8823 | reject_bad_reg (Rn); | |
8824 | } | |
8825 | else | |
8826 | { | |
8827 | constraint (Rd == REG_PC, BAD_PC); | |
8828 | constraint (Rn == REG_PC, BAD_PC); | |
8829 | } | |
8830 | ||
873f10f0 TC |
8831 | /* Only check the MRRC{2} variants. */ |
8832 | if ((inst.instruction & 0x0FF00000) == 0x0C500000) | |
8833 | { | |
8834 | /* If Rd == Rn, error that the operation is | |
8835 | unpredictable (example MRRC p3,#1,r1,r1,c4). */ | |
8836 | constraint (Rd == Rn, BAD_OVERLAP); | |
8837 | } | |
8838 | ||
c19d1205 ZW |
8839 | inst.instruction |= inst.operands[0].reg << 8; |
8840 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
8841 | inst.instruction |= Rd << 12; |
8842 | inst.instruction |= Rn << 16; | |
c19d1205 | 8843 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
8844 | } |
8845 | ||
c19d1205 ZW |
8846 | static void |
8847 | do_cpsi (void) | |
8848 | { | |
8849 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
8850 | if (inst.operands[1].present) |
8851 | { | |
8852 | inst.instruction |= CPSI_MMOD; | |
8853 | inst.instruction |= inst.operands[1].imm; | |
8854 | } | |
c19d1205 | 8855 | } |
b99bd4ef | 8856 | |
62b3e311 PB |
8857 | static void |
8858 | do_dbg (void) | |
8859 | { | |
8860 | inst.instruction |= inst.operands[0].imm; | |
8861 | } | |
8862 | ||
eea54501 MGD |
8863 | static void |
8864 | do_div (void) | |
8865 | { | |
8866 | unsigned Rd, Rn, Rm; | |
8867 | ||
8868 | Rd = inst.operands[0].reg; | |
8869 | Rn = (inst.operands[1].present | |
8870 | ? inst.operands[1].reg : Rd); | |
8871 | Rm = inst.operands[2].reg; | |
8872 | ||
8873 | constraint ((Rd == REG_PC), BAD_PC); | |
8874 | constraint ((Rn == REG_PC), BAD_PC); | |
8875 | constraint ((Rm == REG_PC), BAD_PC); | |
8876 | ||
8877 | inst.instruction |= Rd << 16; | |
8878 | inst.instruction |= Rn << 0; | |
8879 | inst.instruction |= Rm << 8; | |
8880 | } | |
8881 | ||
b99bd4ef | 8882 | static void |
c19d1205 | 8883 | do_it (void) |
b99bd4ef | 8884 | { |
c19d1205 | 8885 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
8886 | process it to do the validation as if in |
8887 | thumb mode, just in case the code gets | |
8888 | assembled for thumb using the unified syntax. */ | |
8889 | ||
c19d1205 | 8890 | inst.size = 0; |
e07e6e58 NC |
8891 | if (unified_syntax) |
8892 | { | |
8893 | set_it_insn_type (IT_INSN); | |
8894 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
8895 | now_it.cc = inst.operands[0].imm; | |
8896 | } | |
09d92015 | 8897 | } |
b99bd4ef | 8898 | |
6530b175 NC |
8899 | /* If there is only one register in the register list, |
8900 | then return its register number. Otherwise return -1. */ | |
8901 | static int | |
8902 | only_one_reg_in_list (int range) | |
8903 | { | |
8904 | int i = ffs (range) - 1; | |
8905 | return (i > 15 || range != (1 << i)) ? -1 : i; | |
8906 | } | |
8907 | ||
09d92015 | 8908 | static void |
6530b175 | 8909 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 8910 | { |
c19d1205 ZW |
8911 | int base_reg = inst.operands[0].reg; |
8912 | int range = inst.operands[1].imm; | |
6530b175 | 8913 | int one_reg; |
ea6ef066 | 8914 | |
c19d1205 ZW |
8915 | inst.instruction |= base_reg << 16; |
8916 | inst.instruction |= range; | |
ea6ef066 | 8917 | |
c19d1205 ZW |
8918 | if (inst.operands[1].writeback) |
8919 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 8920 | |
c19d1205 | 8921 | if (inst.operands[0].writeback) |
ea6ef066 | 8922 | { |
c19d1205 ZW |
8923 | inst.instruction |= WRITE_BACK; |
8924 | /* Check for unpredictable uses of writeback. */ | |
8925 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 8926 | { |
c19d1205 ZW |
8927 | /* Not allowed in LDM type 2. */ |
8928 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
8929 | && ((range & (1 << REG_PC)) == 0)) | |
8930 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
8931 | /* Only allowed if base reg not in list for other types. */ | |
8932 | else if (range & (1 << base_reg)) | |
8933 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
8934 | } | |
8935 | else /* STM. */ | |
8936 | { | |
8937 | /* Not allowed for type 2. */ | |
8938 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
8939 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
8940 | /* Only allowed if base reg not in list, or first in list. */ | |
8941 | else if ((range & (1 << base_reg)) | |
8942 | && (range & ((1 << base_reg) - 1))) | |
8943 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 8944 | } |
ea6ef066 | 8945 | } |
6530b175 NC |
8946 | |
8947 | /* If PUSH/POP has only one register, then use the A2 encoding. */ | |
8948 | one_reg = only_one_reg_in_list (range); | |
8949 | if (from_push_pop_mnem && one_reg >= 0) | |
8950 | { | |
8951 | int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH; | |
8952 | ||
4f588891 NC |
8953 | if (is_push && one_reg == 13 /* SP */) |
8954 | /* PR 22483: The A2 encoding cannot be used when | |
8955 | pushing the stack pointer as this is UNPREDICTABLE. */ | |
8956 | return; | |
8957 | ||
6530b175 NC |
8958 | inst.instruction &= A_COND_MASK; |
8959 | inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP; | |
8960 | inst.instruction |= one_reg << 12; | |
8961 | } | |
8962 | } | |
8963 | ||
8964 | static void | |
8965 | do_ldmstm (void) | |
8966 | { | |
8967 | encode_ldmstm (/*from_push_pop_mnem=*/FALSE); | |
a737bd4d NC |
8968 | } |
8969 | ||
c19d1205 ZW |
8970 | /* ARMv5TE load-consecutive (argument parse) |
8971 | Mode is like LDRH. | |
8972 | ||
8973 | LDRccD R, mode | |
8974 | STRccD R, mode. */ | |
8975 | ||
a737bd4d | 8976 | static void |
c19d1205 | 8977 | do_ldrd (void) |
a737bd4d | 8978 | { |
c19d1205 | 8979 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 8980 | _("first transfer register must be even")); |
c19d1205 ZW |
8981 | constraint (inst.operands[1].present |
8982 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 8983 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
8984 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
8985 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 8986 | |
c19d1205 ZW |
8987 | if (!inst.operands[1].present) |
8988 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 8989 | |
c56791bb RE |
8990 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
8991 | register and the first register written; we have to diagnose | |
8992 | overlap between the base and the second register written here. */ | |
ea6ef066 | 8993 | |
c56791bb RE |
8994 | if (inst.operands[2].reg == inst.operands[1].reg |
8995 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
8996 | as_warn (_("base register written back, and overlaps " | |
8997 | "second transfer register")); | |
b05fe5cf | 8998 | |
c56791bb RE |
8999 | if (!(inst.instruction & V4_STR_BIT)) |
9000 | { | |
c19d1205 | 9001 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
9002 | destination (even if not write-back). */ |
9003 | if (inst.operands[2].immisreg | |
9004 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg | |
9005 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
9006 | as_warn (_("index register overlaps transfer register")); | |
b05fe5cf | 9007 | } |
c19d1205 ZW |
9008 | inst.instruction |= inst.operands[0].reg << 12; |
9009 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
9010 | } |
9011 | ||
9012 | static void | |
c19d1205 | 9013 | do_ldrex (void) |
b05fe5cf | 9014 | { |
c19d1205 ZW |
9015 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
9016 | || inst.operands[1].postind || inst.operands[1].writeback | |
9017 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
9018 | || inst.operands[1].negative |
9019 | /* This can arise if the programmer has written | |
9020 | strex rN, rM, foo | |
9021 | or if they have mistakenly used a register name as the last | |
9022 | operand, eg: | |
9023 | strex rN, rM, rX | |
9024 | It is very difficult to distinguish between these two cases | |
9025 | because "rX" might actually be a label. ie the register | |
9026 | name has been occluded by a symbol of the same name. So we | |
9027 | just generate a general 'bad addressing mode' type error | |
9028 | message and leave it up to the programmer to discover the | |
9029 | true cause and fix their mistake. */ | |
9030 | || (inst.operands[1].reg == REG_PC), | |
9031 | BAD_ADDR_MODE); | |
b05fe5cf | 9032 | |
e2b0ab59 AV |
9033 | constraint (inst.relocs[0].exp.X_op != O_constant |
9034 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9035 | _("offset must be zero in ARM encoding")); |
b05fe5cf | 9036 | |
5be8be5d DG |
9037 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
9038 | ||
c19d1205 ZW |
9039 | inst.instruction |= inst.operands[0].reg << 12; |
9040 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 9041 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b05fe5cf ZW |
9042 | } |
9043 | ||
9044 | static void | |
c19d1205 | 9045 | do_ldrexd (void) |
b05fe5cf | 9046 | { |
c19d1205 ZW |
9047 | constraint (inst.operands[0].reg % 2 != 0, |
9048 | _("even register required")); | |
9049 | constraint (inst.operands[1].present | |
9050 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
9051 | _("can only load two consecutive registers")); | |
9052 | /* If op 1 were present and equal to PC, this function wouldn't | |
9053 | have been called in the first place. */ | |
9054 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 9055 | |
c19d1205 ZW |
9056 | inst.instruction |= inst.operands[0].reg << 12; |
9057 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
9058 | } |
9059 | ||
1be5fd2e NC |
9060 | /* In both ARM and thumb state 'ldr pc, #imm' with an immediate |
9061 | which is not a multiple of four is UNPREDICTABLE. */ | |
9062 | static void | |
9063 | check_ldr_r15_aligned (void) | |
9064 | { | |
9065 | constraint (!(inst.operands[1].immisreg) | |
9066 | && (inst.operands[0].reg == REG_PC | |
9067 | && inst.operands[1].reg == REG_PC | |
e2b0ab59 | 9068 | && (inst.relocs[0].exp.X_add_number & 0x3)), |
de194d85 | 9069 | _("ldr to register 15 must be 4-byte aligned")); |
1be5fd2e NC |
9070 | } |
9071 | ||
b05fe5cf | 9072 | static void |
c19d1205 | 9073 | do_ldst (void) |
b05fe5cf | 9074 | { |
c19d1205 ZW |
9075 | inst.instruction |= inst.operands[0].reg << 12; |
9076 | if (!inst.operands[1].isreg) | |
8335d6aa | 9077 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE)) |
b05fe5cf | 9078 | return; |
c19d1205 | 9079 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
1be5fd2e | 9080 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
9081 | } |
9082 | ||
9083 | static void | |
c19d1205 | 9084 | do_ldstt (void) |
b05fe5cf | 9085 | { |
c19d1205 ZW |
9086 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9087 | reject [Rn,...]. */ | |
9088 | if (inst.operands[1].preind) | |
b05fe5cf | 9089 | { |
e2b0ab59 AV |
9090 | constraint (inst.relocs[0].exp.X_op != O_constant |
9091 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9092 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9093 | |
c19d1205 ZW |
9094 | inst.operands[1].preind = 0; |
9095 | inst.operands[1].postind = 1; | |
9096 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9097 | } |
c19d1205 ZW |
9098 | inst.instruction |= inst.operands[0].reg << 12; |
9099 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
9100 | } | |
b05fe5cf | 9101 | |
c19d1205 | 9102 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 9103 | |
c19d1205 ZW |
9104 | static void |
9105 | do_ldstv4 (void) | |
9106 | { | |
ff4a8d2b | 9107 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
9108 | inst.instruction |= inst.operands[0].reg << 12; |
9109 | if (!inst.operands[1].isreg) | |
8335d6aa | 9110 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE)) |
b05fe5cf | 9111 | return; |
c19d1205 | 9112 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
9113 | } |
9114 | ||
9115 | static void | |
c19d1205 | 9116 | do_ldsttv4 (void) |
b05fe5cf | 9117 | { |
c19d1205 ZW |
9118 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
9119 | reject [Rn,...]. */ | |
9120 | if (inst.operands[1].preind) | |
b05fe5cf | 9121 | { |
e2b0ab59 AV |
9122 | constraint (inst.relocs[0].exp.X_op != O_constant |
9123 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9124 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 9125 | |
c19d1205 ZW |
9126 | inst.operands[1].preind = 0; |
9127 | inst.operands[1].postind = 1; | |
9128 | inst.operands[1].writeback = 1; | |
b05fe5cf | 9129 | } |
c19d1205 ZW |
9130 | inst.instruction |= inst.operands[0].reg << 12; |
9131 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
9132 | } | |
b05fe5cf | 9133 | |
c19d1205 ZW |
9134 | /* Co-processor register load/store. |
9135 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
9136 | static void | |
9137 | do_lstc (void) | |
9138 | { | |
9139 | inst.instruction |= inst.operands[0].reg << 8; | |
9140 | inst.instruction |= inst.operands[1].reg << 12; | |
9141 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
9142 | } |
9143 | ||
b05fe5cf | 9144 | static void |
c19d1205 | 9145 | do_mlas (void) |
b05fe5cf | 9146 | { |
8fb9d7b9 | 9147 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 9148 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 9149 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 9150 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 9151 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 9152 | |
c19d1205 ZW |
9153 | inst.instruction |= inst.operands[0].reg << 16; |
9154 | inst.instruction |= inst.operands[1].reg; | |
9155 | inst.instruction |= inst.operands[2].reg << 8; | |
9156 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 9157 | } |
b05fe5cf | 9158 | |
c19d1205 ZW |
9159 | static void |
9160 | do_mov (void) | |
9161 | { | |
e2b0ab59 AV |
9162 | constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
9163 | && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
a9f02af8 | 9164 | THUMB1_RELOC_ONLY); |
c19d1205 ZW |
9165 | inst.instruction |= inst.operands[0].reg << 12; |
9166 | encode_arm_shifter_operand (1); | |
9167 | } | |
b05fe5cf | 9168 | |
c19d1205 ZW |
9169 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
9170 | static void | |
9171 | do_mov16 (void) | |
9172 | { | |
b6895b4f PB |
9173 | bfd_vma imm; |
9174 | bfd_boolean top; | |
9175 | ||
9176 | top = (inst.instruction & 0x00400000) != 0; | |
e2b0ab59 | 9177 | constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW, |
33eaf5de | 9178 | _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 9179 | constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT, |
33eaf5de | 9180 | _(":upper16: not allowed in this instruction")); |
c19d1205 | 9181 | inst.instruction |= inst.operands[0].reg << 12; |
e2b0ab59 | 9182 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 9183 | { |
e2b0ab59 | 9184 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
9185 | /* The value is in two pieces: 0:11, 16:19. */ |
9186 | inst.instruction |= (imm & 0x00000fff); | |
9187 | inst.instruction |= (imm & 0x0000f000) << 4; | |
9188 | } | |
b05fe5cf | 9189 | } |
b99bd4ef | 9190 | |
037e8744 JB |
9191 | static int |
9192 | do_vfp_nsyn_mrs (void) | |
9193 | { | |
9194 | if (inst.operands[0].isvec) | |
9195 | { | |
9196 | if (inst.operands[1].reg != 1) | |
477330fc | 9197 | first_error (_("operand 1 must be FPSCR")); |
037e8744 JB |
9198 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); |
9199 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
9200 | do_vfp_nsyn_opcode ("fmstat"); | |
9201 | } | |
9202 | else if (inst.operands[1].isvec) | |
9203 | do_vfp_nsyn_opcode ("fmrx"); | |
9204 | else | |
9205 | return FAIL; | |
5f4273c7 | 9206 | |
037e8744 JB |
9207 | return SUCCESS; |
9208 | } | |
9209 | ||
9210 | static int | |
9211 | do_vfp_nsyn_msr (void) | |
9212 | { | |
9213 | if (inst.operands[0].isvec) | |
9214 | do_vfp_nsyn_opcode ("fmxr"); | |
9215 | else | |
9216 | return FAIL; | |
9217 | ||
9218 | return SUCCESS; | |
9219 | } | |
9220 | ||
f7c21dc7 NC |
9221 | static void |
9222 | do_vmrs (void) | |
9223 | { | |
9224 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 9225 | |
16d02dc9 | 9226 | if (thumb_mode && Rt == REG_SP) |
f7c21dc7 NC |
9227 | { |
9228 | inst.error = BAD_SP; | |
9229 | return; | |
9230 | } | |
9231 | ||
40c7d507 RR |
9232 | /* MVFR2 is only valid at ARMv8-A. */ |
9233 | if (inst.operands[1].reg == 5) | |
9234 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
9235 | _(BAD_FPU)); | |
9236 | ||
f7c21dc7 | 9237 | /* APSR_ sets isvec. All other refs to PC are illegal. */ |
16d02dc9 | 9238 | if (!inst.operands[0].isvec && Rt == REG_PC) |
f7c21dc7 NC |
9239 | { |
9240 | inst.error = BAD_PC; | |
9241 | return; | |
9242 | } | |
9243 | ||
16d02dc9 JB |
9244 | /* If we get through parsing the register name, we just insert the number |
9245 | generated into the instruction without further validation. */ | |
9246 | inst.instruction |= (inst.operands[1].reg << 16); | |
f7c21dc7 NC |
9247 | inst.instruction |= (Rt << 12); |
9248 | } | |
9249 | ||
9250 | static void | |
9251 | do_vmsr (void) | |
9252 | { | |
9253 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 9254 | |
f7c21dc7 NC |
9255 | if (thumb_mode) |
9256 | reject_bad_reg (Rt); | |
9257 | else if (Rt == REG_PC) | |
9258 | { | |
9259 | inst.error = BAD_PC; | |
9260 | return; | |
9261 | } | |
9262 | ||
40c7d507 RR |
9263 | /* MVFR2 is only valid for ARMv8-A. */ |
9264 | if (inst.operands[0].reg == 5) | |
9265 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
9266 | _(BAD_FPU)); | |
9267 | ||
16d02dc9 JB |
9268 | /* If we get through parsing the register name, we just insert the number |
9269 | generated into the instruction without further validation. */ | |
9270 | inst.instruction |= (inst.operands[0].reg << 16); | |
f7c21dc7 NC |
9271 | inst.instruction |= (Rt << 12); |
9272 | } | |
9273 | ||
b99bd4ef | 9274 | static void |
c19d1205 | 9275 | do_mrs (void) |
b99bd4ef | 9276 | { |
90ec0d68 MGD |
9277 | unsigned br; |
9278 | ||
037e8744 JB |
9279 | if (do_vfp_nsyn_mrs () == SUCCESS) |
9280 | return; | |
9281 | ||
ff4a8d2b | 9282 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 9283 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
9284 | |
9285 | if (inst.operands[1].isreg) | |
9286 | { | |
9287 | br = inst.operands[1].reg; | |
806ab1c0 | 9288 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000)) |
90ec0d68 MGD |
9289 | as_bad (_("bad register for mrs")); |
9290 | } | |
9291 | else | |
9292 | { | |
9293 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
9294 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
9295 | != (PSR_c|PSR_f), | |
d2cd1205 | 9296 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
9297 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
9298 | } | |
9299 | ||
9300 | inst.instruction |= br; | |
c19d1205 | 9301 | } |
b99bd4ef | 9302 | |
c19d1205 ZW |
9303 | /* Two possible forms: |
9304 | "{C|S}PSR_<field>, Rm", | |
9305 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 9306 | |
c19d1205 ZW |
9307 | static void |
9308 | do_msr (void) | |
9309 | { | |
037e8744 JB |
9310 | if (do_vfp_nsyn_msr () == SUCCESS) |
9311 | return; | |
9312 | ||
c19d1205 ZW |
9313 | inst.instruction |= inst.operands[0].imm; |
9314 | if (inst.operands[1].isreg) | |
9315 | inst.instruction |= inst.operands[1].reg; | |
9316 | else | |
b99bd4ef | 9317 | { |
c19d1205 | 9318 | inst.instruction |= INST_IMMEDIATE; |
e2b0ab59 AV |
9319 | inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE; |
9320 | inst.relocs[0].pc_rel = 0; | |
b99bd4ef | 9321 | } |
b99bd4ef NC |
9322 | } |
9323 | ||
c19d1205 ZW |
9324 | static void |
9325 | do_mul (void) | |
a737bd4d | 9326 | { |
ff4a8d2b NC |
9327 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
9328 | ||
c19d1205 ZW |
9329 | if (!inst.operands[2].present) |
9330 | inst.operands[2].reg = inst.operands[0].reg; | |
9331 | inst.instruction |= inst.operands[0].reg << 16; | |
9332 | inst.instruction |= inst.operands[1].reg; | |
9333 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 9334 | |
8fb9d7b9 MS |
9335 | if (inst.operands[0].reg == inst.operands[1].reg |
9336 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
9337 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
9338 | } |
9339 | ||
c19d1205 ZW |
9340 | /* Long Multiply Parser |
9341 | UMULL RdLo, RdHi, Rm, Rs | |
9342 | SMULL RdLo, RdHi, Rm, Rs | |
9343 | UMLAL RdLo, RdHi, Rm, Rs | |
9344 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
9345 | |
9346 | static void | |
c19d1205 | 9347 | do_mull (void) |
b99bd4ef | 9348 | { |
c19d1205 ZW |
9349 | inst.instruction |= inst.operands[0].reg << 12; |
9350 | inst.instruction |= inst.operands[1].reg << 16; | |
9351 | inst.instruction |= inst.operands[2].reg; | |
9352 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 9353 | |
682b27ad PB |
9354 | /* rdhi and rdlo must be different. */ |
9355 | if (inst.operands[0].reg == inst.operands[1].reg) | |
9356 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9357 | ||
9358 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
9359 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 9360 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 9361 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
9362 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
9363 | } | |
b99bd4ef | 9364 | |
c19d1205 ZW |
9365 | static void |
9366 | do_nop (void) | |
9367 | { | |
e7495e45 NS |
9368 | if (inst.operands[0].present |
9369 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
9370 | { |
9371 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
9372 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
9373 | inst.instruction |= 0x0320f000; |
9374 | if (inst.operands[0].present) | |
9375 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 9376 | } |
b99bd4ef NC |
9377 | } |
9378 | ||
c19d1205 ZW |
9379 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
9380 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
9381 | Condition defaults to COND_ALWAYS. | |
9382 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
9383 | |
9384 | static void | |
c19d1205 | 9385 | do_pkhbt (void) |
b99bd4ef | 9386 | { |
c19d1205 ZW |
9387 | inst.instruction |= inst.operands[0].reg << 12; |
9388 | inst.instruction |= inst.operands[1].reg << 16; | |
9389 | inst.instruction |= inst.operands[2].reg; | |
9390 | if (inst.operands[3].present) | |
9391 | encode_arm_shift (3); | |
9392 | } | |
b99bd4ef | 9393 | |
c19d1205 | 9394 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 9395 | |
c19d1205 ZW |
9396 | static void |
9397 | do_pkhtb (void) | |
9398 | { | |
9399 | if (!inst.operands[3].present) | |
b99bd4ef | 9400 | { |
c19d1205 ZW |
9401 | /* If the shift specifier is omitted, turn the instruction |
9402 | into pkhbt rd, rm, rn. */ | |
9403 | inst.instruction &= 0xfff00010; | |
9404 | inst.instruction |= inst.operands[0].reg << 12; | |
9405 | inst.instruction |= inst.operands[1].reg; | |
9406 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9407 | } |
9408 | else | |
9409 | { | |
c19d1205 ZW |
9410 | inst.instruction |= inst.operands[0].reg << 12; |
9411 | inst.instruction |= inst.operands[1].reg << 16; | |
9412 | inst.instruction |= inst.operands[2].reg; | |
9413 | encode_arm_shift (3); | |
b99bd4ef NC |
9414 | } |
9415 | } | |
9416 | ||
c19d1205 | 9417 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 9418 | MP Extensions: Preload for write |
c19d1205 | 9419 | |
60e5ef9f | 9420 | PLD(W) <addr_mode> |
c19d1205 ZW |
9421 | |
9422 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
9423 | |
9424 | static void | |
c19d1205 | 9425 | do_pld (void) |
b99bd4ef | 9426 | { |
c19d1205 ZW |
9427 | constraint (!inst.operands[0].isreg, |
9428 | _("'[' expected after PLD mnemonic")); | |
9429 | constraint (inst.operands[0].postind, | |
9430 | _("post-indexed expression used in preload instruction")); | |
9431 | constraint (inst.operands[0].writeback, | |
9432 | _("writeback used in preload instruction")); | |
9433 | constraint (!inst.operands[0].preind, | |
9434 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
9435 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
9436 | } | |
b99bd4ef | 9437 | |
62b3e311 PB |
9438 | /* ARMv7: PLI <addr_mode> */ |
9439 | static void | |
9440 | do_pli (void) | |
9441 | { | |
9442 | constraint (!inst.operands[0].isreg, | |
9443 | _("'[' expected after PLI mnemonic")); | |
9444 | constraint (inst.operands[0].postind, | |
9445 | _("post-indexed expression used in preload instruction")); | |
9446 | constraint (inst.operands[0].writeback, | |
9447 | _("writeback used in preload instruction")); | |
9448 | constraint (!inst.operands[0].preind, | |
9449 | _("unindexed addressing used in preload instruction")); | |
9450 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
9451 | inst.instruction &= ~PRE_INDEX; | |
9452 | } | |
9453 | ||
c19d1205 ZW |
9454 | static void |
9455 | do_push_pop (void) | |
9456 | { | |
5e0d7f77 MP |
9457 | constraint (inst.operands[0].writeback, |
9458 | _("push/pop do not support {reglist}^")); | |
c19d1205 ZW |
9459 | inst.operands[1] = inst.operands[0]; |
9460 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
9461 | inst.operands[0].isreg = 1; | |
9462 | inst.operands[0].writeback = 1; | |
9463 | inst.operands[0].reg = REG_SP; | |
6530b175 | 9464 | encode_ldmstm (/*from_push_pop_mnem=*/TRUE); |
c19d1205 | 9465 | } |
b99bd4ef | 9466 | |
c19d1205 ZW |
9467 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
9468 | word at the specified address and the following word | |
9469 | respectively. | |
9470 | Unconditionally executed. | |
9471 | Error if Rn is R15. */ | |
b99bd4ef | 9472 | |
c19d1205 ZW |
9473 | static void |
9474 | do_rfe (void) | |
9475 | { | |
9476 | inst.instruction |= inst.operands[0].reg << 16; | |
9477 | if (inst.operands[0].writeback) | |
9478 | inst.instruction |= WRITE_BACK; | |
9479 | } | |
b99bd4ef | 9480 | |
c19d1205 | 9481 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 9482 | |
c19d1205 ZW |
9483 | static void |
9484 | do_ssat (void) | |
9485 | { | |
9486 | inst.instruction |= inst.operands[0].reg << 12; | |
9487 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
9488 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9489 | |
c19d1205 ZW |
9490 | if (inst.operands[3].present) |
9491 | encode_arm_shift (3); | |
b99bd4ef NC |
9492 | } |
9493 | ||
c19d1205 | 9494 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
9495 | |
9496 | static void | |
c19d1205 | 9497 | do_usat (void) |
b99bd4ef | 9498 | { |
c19d1205 ZW |
9499 | inst.instruction |= inst.operands[0].reg << 12; |
9500 | inst.instruction |= inst.operands[1].imm << 16; | |
9501 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9502 | |
c19d1205 ZW |
9503 | if (inst.operands[3].present) |
9504 | encode_arm_shift (3); | |
b99bd4ef NC |
9505 | } |
9506 | ||
c19d1205 | 9507 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
9508 | |
9509 | static void | |
c19d1205 | 9510 | do_ssat16 (void) |
09d92015 | 9511 | { |
c19d1205 ZW |
9512 | inst.instruction |= inst.operands[0].reg << 12; |
9513 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
9514 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
9515 | } |
9516 | ||
c19d1205 ZW |
9517 | static void |
9518 | do_usat16 (void) | |
a737bd4d | 9519 | { |
c19d1205 ZW |
9520 | inst.instruction |= inst.operands[0].reg << 12; |
9521 | inst.instruction |= inst.operands[1].imm << 16; | |
9522 | inst.instruction |= inst.operands[2].reg; | |
9523 | } | |
a737bd4d | 9524 | |
c19d1205 ZW |
9525 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
9526 | preserving the other bits. | |
a737bd4d | 9527 | |
c19d1205 ZW |
9528 | setend <endian_specifier>, where <endian_specifier> is either |
9529 | BE or LE. */ | |
a737bd4d | 9530 | |
c19d1205 ZW |
9531 | static void |
9532 | do_setend (void) | |
9533 | { | |
12e37cbc MGD |
9534 | if (warn_on_deprecated |
9535 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 9536 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 9537 | |
c19d1205 ZW |
9538 | if (inst.operands[0].imm) |
9539 | inst.instruction |= 0x200; | |
a737bd4d NC |
9540 | } |
9541 | ||
9542 | static void | |
c19d1205 | 9543 | do_shift (void) |
a737bd4d | 9544 | { |
c19d1205 ZW |
9545 | unsigned int Rm = (inst.operands[1].present |
9546 | ? inst.operands[1].reg | |
9547 | : inst.operands[0].reg); | |
a737bd4d | 9548 | |
c19d1205 ZW |
9549 | inst.instruction |= inst.operands[0].reg << 12; |
9550 | inst.instruction |= Rm; | |
9551 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 9552 | { |
c19d1205 ZW |
9553 | inst.instruction |= inst.operands[2].reg << 8; |
9554 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
9555 | /* PR 12854: Error on extraneous shifts. */ |
9556 | constraint (inst.operands[2].shifted, | |
9557 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
9558 | } |
9559 | else | |
e2b0ab59 | 9560 | inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
9561 | } |
9562 | ||
09d92015 | 9563 | static void |
3eb17e6b | 9564 | do_smc (void) |
09d92015 | 9565 | { |
e2b0ab59 AV |
9566 | inst.relocs[0].type = BFD_RELOC_ARM_SMC; |
9567 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
9568 | } |
9569 | ||
90ec0d68 MGD |
9570 | static void |
9571 | do_hvc (void) | |
9572 | { | |
e2b0ab59 AV |
9573 | inst.relocs[0].type = BFD_RELOC_ARM_HVC; |
9574 | inst.relocs[0].pc_rel = 0; | |
90ec0d68 MGD |
9575 | } |
9576 | ||
09d92015 | 9577 | static void |
c19d1205 | 9578 | do_swi (void) |
09d92015 | 9579 | { |
e2b0ab59 AV |
9580 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
9581 | inst.relocs[0].pc_rel = 0; | |
09d92015 MM |
9582 | } |
9583 | ||
ddfded2f MW |
9584 | static void |
9585 | do_setpan (void) | |
9586 | { | |
9587 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9588 | _("selected processor does not support SETPAN instruction")); | |
9589 | ||
9590 | inst.instruction |= ((inst.operands[0].imm & 1) << 9); | |
9591 | } | |
9592 | ||
9593 | static void | |
9594 | do_t_setpan (void) | |
9595 | { | |
9596 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9597 | _("selected processor does not support SETPAN instruction")); | |
9598 | ||
9599 | inst.instruction |= (inst.operands[0].imm << 3); | |
9600 | } | |
9601 | ||
c19d1205 ZW |
9602 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
9603 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
9604 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
9605 | Error if any register is R15. */ | |
e16bb312 | 9606 | |
c19d1205 ZW |
9607 | static void |
9608 | do_smla (void) | |
e16bb312 | 9609 | { |
c19d1205 ZW |
9610 | inst.instruction |= inst.operands[0].reg << 16; |
9611 | inst.instruction |= inst.operands[1].reg; | |
9612 | inst.instruction |= inst.operands[2].reg << 8; | |
9613 | inst.instruction |= inst.operands[3].reg << 12; | |
9614 | } | |
a737bd4d | 9615 | |
c19d1205 ZW |
9616 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
9617 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
9618 | Error if any register is R15. | |
9619 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 9620 | |
c19d1205 ZW |
9621 | static void |
9622 | do_smlal (void) | |
9623 | { | |
9624 | inst.instruction |= inst.operands[0].reg << 12; | |
9625 | inst.instruction |= inst.operands[1].reg << 16; | |
9626 | inst.instruction |= inst.operands[2].reg; | |
9627 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 9628 | |
c19d1205 ZW |
9629 | if (inst.operands[0].reg == inst.operands[1].reg) |
9630 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9631 | } | |
a737bd4d | 9632 | |
c19d1205 ZW |
9633 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
9634 | SMULxy{cond} Rd,Rm,Rs | |
9635 | Error if any register is R15. */ | |
a737bd4d | 9636 | |
c19d1205 ZW |
9637 | static void |
9638 | do_smul (void) | |
9639 | { | |
9640 | inst.instruction |= inst.operands[0].reg << 16; | |
9641 | inst.instruction |= inst.operands[1].reg; | |
9642 | inst.instruction |= inst.operands[2].reg << 8; | |
9643 | } | |
a737bd4d | 9644 | |
b6702015 PB |
9645 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
9646 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 9647 | |
c19d1205 ZW |
9648 | static void |
9649 | do_srs (void) | |
9650 | { | |
b6702015 PB |
9651 | int reg; |
9652 | ||
9653 | if (inst.operands[0].present) | |
9654 | { | |
9655 | reg = inst.operands[0].reg; | |
fdfde340 | 9656 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
9657 | } |
9658 | else | |
fdfde340 | 9659 | reg = REG_SP; |
b6702015 PB |
9660 | |
9661 | inst.instruction |= reg << 16; | |
9662 | inst.instruction |= inst.operands[1].imm; | |
9663 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
9664 | inst.instruction |= WRITE_BACK; |
9665 | } | |
a737bd4d | 9666 | |
c19d1205 | 9667 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 9668 | |
c19d1205 ZW |
9669 | static void |
9670 | do_strex (void) | |
9671 | { | |
9672 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9673 | || inst.operands[2].postind || inst.operands[2].writeback | |
9674 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
9675 | || inst.operands[2].negative |
9676 | /* See comment in do_ldrex(). */ | |
9677 | || (inst.operands[2].reg == REG_PC), | |
9678 | BAD_ADDR_MODE); | |
a737bd4d | 9679 | |
c19d1205 ZW |
9680 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9681 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 9682 | |
e2b0ab59 AV |
9683 | constraint (inst.relocs[0].exp.X_op != O_constant |
9684 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 9685 | _("offset must be zero in ARM encoding")); |
a737bd4d | 9686 | |
c19d1205 ZW |
9687 | inst.instruction |= inst.operands[0].reg << 12; |
9688 | inst.instruction |= inst.operands[1].reg; | |
9689 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 9690 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
e16bb312 NC |
9691 | } |
9692 | ||
877807f8 NC |
9693 | static void |
9694 | do_t_strexbh (void) | |
9695 | { | |
9696 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9697 | || inst.operands[2].postind || inst.operands[2].writeback | |
9698 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
9699 | || inst.operands[2].negative, | |
9700 | BAD_ADDR_MODE); | |
9701 | ||
9702 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9703 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9704 | ||
9705 | do_rm_rd_rn (); | |
9706 | } | |
9707 | ||
e16bb312 | 9708 | static void |
c19d1205 | 9709 | do_strexd (void) |
e16bb312 | 9710 | { |
c19d1205 ZW |
9711 | constraint (inst.operands[1].reg % 2 != 0, |
9712 | _("even register required")); | |
9713 | constraint (inst.operands[2].present | |
9714 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
9715 | _("can only store two consecutive registers")); | |
9716 | /* If op 2 were present and equal to PC, this function wouldn't | |
9717 | have been called in the first place. */ | |
9718 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 9719 | |
c19d1205 ZW |
9720 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9721 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
9722 | || inst.operands[0].reg == inst.operands[3].reg, | |
9723 | BAD_OVERLAP); | |
e16bb312 | 9724 | |
c19d1205 ZW |
9725 | inst.instruction |= inst.operands[0].reg << 12; |
9726 | inst.instruction |= inst.operands[1].reg; | |
9727 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
9728 | } |
9729 | ||
9eb6c0f1 MGD |
9730 | /* ARM V8 STRL. */ |
9731 | static void | |
4b8c8c02 | 9732 | do_stlex (void) |
9eb6c0f1 MGD |
9733 | { |
9734 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9735 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9736 | ||
9737 | do_rd_rm_rn (); | |
9738 | } | |
9739 | ||
9740 | static void | |
4b8c8c02 | 9741 | do_t_stlex (void) |
9eb6c0f1 MGD |
9742 | { |
9743 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9744 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9745 | ||
9746 | do_rm_rd_rn (); | |
9747 | } | |
9748 | ||
c19d1205 ZW |
9749 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
9750 | extends it to 32-bits, and adds the result to a value in another | |
9751 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
9752 | before extracting the 16-bit value. | |
9753 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
9754 | Condition defaults to COND_ALWAYS. | |
9755 | Error if any register uses R15. */ | |
9756 | ||
e16bb312 | 9757 | static void |
c19d1205 | 9758 | do_sxtah (void) |
e16bb312 | 9759 | { |
c19d1205 ZW |
9760 | inst.instruction |= inst.operands[0].reg << 12; |
9761 | inst.instruction |= inst.operands[1].reg << 16; | |
9762 | inst.instruction |= inst.operands[2].reg; | |
9763 | inst.instruction |= inst.operands[3].imm << 10; | |
9764 | } | |
e16bb312 | 9765 | |
c19d1205 | 9766 | /* ARM V6 SXTH. |
e16bb312 | 9767 | |
c19d1205 ZW |
9768 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
9769 | Condition defaults to COND_ALWAYS. | |
9770 | Error if any register uses R15. */ | |
e16bb312 NC |
9771 | |
9772 | static void | |
c19d1205 | 9773 | do_sxth (void) |
e16bb312 | 9774 | { |
c19d1205 ZW |
9775 | inst.instruction |= inst.operands[0].reg << 12; |
9776 | inst.instruction |= inst.operands[1].reg; | |
9777 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 9778 | } |
c19d1205 ZW |
9779 | \f |
9780 | /* VFP instructions. In a logical order: SP variant first, monad | |
9781 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
9782 | |
9783 | static void | |
c19d1205 | 9784 | do_vfp_sp_monadic (void) |
e16bb312 | 9785 | { |
5287ad62 JB |
9786 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9787 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9788 | } |
9789 | ||
9790 | static void | |
c19d1205 | 9791 | do_vfp_sp_dyadic (void) |
e16bb312 | 9792 | { |
5287ad62 JB |
9793 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9794 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
9795 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
9796 | } |
9797 | ||
9798 | static void | |
c19d1205 | 9799 | do_vfp_sp_compare_z (void) |
e16bb312 | 9800 | { |
5287ad62 | 9801 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
9802 | } |
9803 | ||
9804 | static void | |
c19d1205 | 9805 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 9806 | { |
5287ad62 JB |
9807 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
9808 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9809 | } |
9810 | ||
9811 | static void | |
c19d1205 | 9812 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 9813 | { |
5287ad62 JB |
9814 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9815 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
9816 | } |
9817 | ||
9818 | static void | |
c19d1205 | 9819 | do_vfp_reg_from_sp (void) |
e16bb312 | 9820 | { |
c19d1205 | 9821 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 9822 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
9823 | } |
9824 | ||
9825 | static void | |
c19d1205 | 9826 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 9827 | { |
c19d1205 ZW |
9828 | constraint (inst.operands[2].imm != 2, |
9829 | _("only two consecutive VFP SP registers allowed here")); | |
9830 | inst.instruction |= inst.operands[0].reg << 12; | |
9831 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 9832 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
9833 | } |
9834 | ||
9835 | static void | |
c19d1205 | 9836 | do_vfp_sp_from_reg (void) |
e16bb312 | 9837 | { |
5287ad62 | 9838 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 9839 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
9840 | } |
9841 | ||
9842 | static void | |
c19d1205 | 9843 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 9844 | { |
c19d1205 ZW |
9845 | constraint (inst.operands[0].imm != 2, |
9846 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 9847 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
9848 | inst.instruction |= inst.operands[1].reg << 12; |
9849 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
9850 | } |
9851 | ||
9852 | static void | |
c19d1205 | 9853 | do_vfp_sp_ldst (void) |
e16bb312 | 9854 | { |
5287ad62 | 9855 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 9856 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
9857 | } |
9858 | ||
9859 | static void | |
c19d1205 | 9860 | do_vfp_dp_ldst (void) |
e16bb312 | 9861 | { |
5287ad62 | 9862 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 9863 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
9864 | } |
9865 | ||
c19d1205 | 9866 | |
e16bb312 | 9867 | static void |
c19d1205 | 9868 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 9869 | { |
c19d1205 ZW |
9870 | if (inst.operands[0].writeback) |
9871 | inst.instruction |= WRITE_BACK; | |
9872 | else | |
9873 | constraint (ldstm_type != VFP_LDSTMIA, | |
9874 | _("this addressing mode requires base-register writeback")); | |
9875 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 9876 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 9877 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
9878 | } |
9879 | ||
9880 | static void | |
c19d1205 | 9881 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 9882 | { |
c19d1205 | 9883 | int count; |
e16bb312 | 9884 | |
c19d1205 ZW |
9885 | if (inst.operands[0].writeback) |
9886 | inst.instruction |= WRITE_BACK; | |
9887 | else | |
9888 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
9889 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 9890 | |
c19d1205 | 9891 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 9892 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 9893 | |
c19d1205 ZW |
9894 | count = inst.operands[1].imm << 1; |
9895 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
9896 | count += 1; | |
e16bb312 | 9897 | |
c19d1205 | 9898 | inst.instruction |= count; |
e16bb312 NC |
9899 | } |
9900 | ||
9901 | static void | |
c19d1205 | 9902 | do_vfp_sp_ldstmia (void) |
e16bb312 | 9903 | { |
c19d1205 | 9904 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
9905 | } |
9906 | ||
9907 | static void | |
c19d1205 | 9908 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 9909 | { |
c19d1205 | 9910 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
9911 | } |
9912 | ||
9913 | static void | |
c19d1205 | 9914 | do_vfp_dp_ldstmia (void) |
e16bb312 | 9915 | { |
c19d1205 | 9916 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
9917 | } |
9918 | ||
9919 | static void | |
c19d1205 | 9920 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 9921 | { |
c19d1205 | 9922 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
9923 | } |
9924 | ||
9925 | static void | |
c19d1205 | 9926 | do_vfp_xp_ldstmia (void) |
e16bb312 | 9927 | { |
c19d1205 ZW |
9928 | vfp_dp_ldstm (VFP_LDSTMIAX); |
9929 | } | |
e16bb312 | 9930 | |
c19d1205 ZW |
9931 | static void |
9932 | do_vfp_xp_ldstmdb (void) | |
9933 | { | |
9934 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 9935 | } |
5287ad62 JB |
9936 | |
9937 | static void | |
9938 | do_vfp_dp_rd_rm (void) | |
9939 | { | |
9940 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9941 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
9942 | } | |
9943 | ||
9944 | static void | |
9945 | do_vfp_dp_rn_rd (void) | |
9946 | { | |
9947 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
9948 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
9949 | } | |
9950 | ||
9951 | static void | |
9952 | do_vfp_dp_rd_rn (void) | |
9953 | { | |
9954 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9955 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
9956 | } | |
9957 | ||
9958 | static void | |
9959 | do_vfp_dp_rd_rn_rm (void) | |
9960 | { | |
9961 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9962 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
9963 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
9964 | } | |
9965 | ||
9966 | static void | |
9967 | do_vfp_dp_rd (void) | |
9968 | { | |
9969 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9970 | } | |
9971 | ||
9972 | static void | |
9973 | do_vfp_dp_rm_rd_rn (void) | |
9974 | { | |
9975 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
9976 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
9977 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
9978 | } | |
9979 | ||
9980 | /* VFPv3 instructions. */ | |
9981 | static void | |
9982 | do_vfp_sp_const (void) | |
9983 | { | |
9984 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
9985 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9986 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9987 | } |
9988 | ||
9989 | static void | |
9990 | do_vfp_dp_const (void) | |
9991 | { | |
9992 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
9993 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9994 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9995 | } |
9996 | ||
9997 | static void | |
9998 | vfp_conv (int srcsize) | |
9999 | { | |
5f1af56b MGD |
10000 | int immbits = srcsize - inst.operands[1].imm; |
10001 | ||
fa94de6b RM |
10002 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
10003 | { | |
5f1af56b | 10004 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
477330fc | 10005 | i.e. immbits must be in range 0 - 16. */ |
5f1af56b MGD |
10006 | inst.error = _("immediate value out of range, expected range [0, 16]"); |
10007 | return; | |
10008 | } | |
fa94de6b | 10009 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
10010 | { |
10011 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
477330fc | 10012 | i.e. immbits must be in range 0 - 31. */ |
5f1af56b MGD |
10013 | inst.error = _("immediate value out of range, expected range [1, 32]"); |
10014 | return; | |
10015 | } | |
10016 | ||
5287ad62 JB |
10017 | inst.instruction |= (immbits & 1) << 5; |
10018 | inst.instruction |= (immbits >> 1); | |
10019 | } | |
10020 | ||
10021 | static void | |
10022 | do_vfp_sp_conv_16 (void) | |
10023 | { | |
10024 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
10025 | vfp_conv (16); | |
10026 | } | |
10027 | ||
10028 | static void | |
10029 | do_vfp_dp_conv_16 (void) | |
10030 | { | |
10031 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10032 | vfp_conv (16); | |
10033 | } | |
10034 | ||
10035 | static void | |
10036 | do_vfp_sp_conv_32 (void) | |
10037 | { | |
10038 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
10039 | vfp_conv (32); | |
10040 | } | |
10041 | ||
10042 | static void | |
10043 | do_vfp_dp_conv_32 (void) | |
10044 | { | |
10045 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
10046 | vfp_conv (32); | |
10047 | } | |
c19d1205 ZW |
10048 | \f |
10049 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 10050 | |
c19d1205 ZW |
10051 | static void |
10052 | do_fpa_cmp (void) | |
10053 | { | |
10054 | inst.instruction |= inst.operands[0].reg << 16; | |
10055 | inst.instruction |= inst.operands[1].reg; | |
10056 | } | |
b99bd4ef NC |
10057 | |
10058 | static void | |
c19d1205 | 10059 | do_fpa_ldmstm (void) |
b99bd4ef | 10060 | { |
c19d1205 ZW |
10061 | inst.instruction |= inst.operands[0].reg << 12; |
10062 | switch (inst.operands[1].imm) | |
10063 | { | |
10064 | case 1: inst.instruction |= CP_T_X; break; | |
10065 | case 2: inst.instruction |= CP_T_Y; break; | |
10066 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
10067 | case 4: break; | |
10068 | default: abort (); | |
10069 | } | |
b99bd4ef | 10070 | |
c19d1205 ZW |
10071 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
10072 | { | |
10073 | /* The instruction specified "ea" or "fd", so we can only accept | |
10074 | [Rn]{!}. The instruction does not really support stacking or | |
10075 | unstacking, so we have to emulate these by setting appropriate | |
10076 | bits and offsets. */ | |
e2b0ab59 AV |
10077 | constraint (inst.relocs[0].exp.X_op != O_constant |
10078 | || inst.relocs[0].exp.X_add_number != 0, | |
c19d1205 | 10079 | _("this instruction does not support indexing")); |
b99bd4ef | 10080 | |
c19d1205 | 10081 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
e2b0ab59 | 10082 | inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm; |
b99bd4ef | 10083 | |
c19d1205 | 10084 | if (!(inst.instruction & INDEX_UP)) |
e2b0ab59 | 10085 | inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number; |
b99bd4ef | 10086 | |
c19d1205 ZW |
10087 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
10088 | { | |
10089 | inst.operands[2].preind = 0; | |
10090 | inst.operands[2].postind = 1; | |
10091 | } | |
10092 | } | |
b99bd4ef | 10093 | |
c19d1205 | 10094 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 10095 | } |
c19d1205 ZW |
10096 | \f |
10097 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 10098 | |
c19d1205 ZW |
10099 | static void |
10100 | do_iwmmxt_tandorc (void) | |
10101 | { | |
10102 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
10103 | } | |
b99bd4ef | 10104 | |
c19d1205 ZW |
10105 | static void |
10106 | do_iwmmxt_textrc (void) | |
10107 | { | |
10108 | inst.instruction |= inst.operands[0].reg << 12; | |
10109 | inst.instruction |= inst.operands[1].imm; | |
10110 | } | |
b99bd4ef NC |
10111 | |
10112 | static void | |
c19d1205 | 10113 | do_iwmmxt_textrm (void) |
b99bd4ef | 10114 | { |
c19d1205 ZW |
10115 | inst.instruction |= inst.operands[0].reg << 12; |
10116 | inst.instruction |= inst.operands[1].reg << 16; | |
10117 | inst.instruction |= inst.operands[2].imm; | |
10118 | } | |
b99bd4ef | 10119 | |
c19d1205 ZW |
10120 | static void |
10121 | do_iwmmxt_tinsr (void) | |
10122 | { | |
10123 | inst.instruction |= inst.operands[0].reg << 16; | |
10124 | inst.instruction |= inst.operands[1].reg << 12; | |
10125 | inst.instruction |= inst.operands[2].imm; | |
10126 | } | |
b99bd4ef | 10127 | |
c19d1205 ZW |
10128 | static void |
10129 | do_iwmmxt_tmia (void) | |
10130 | { | |
10131 | inst.instruction |= inst.operands[0].reg << 5; | |
10132 | inst.instruction |= inst.operands[1].reg; | |
10133 | inst.instruction |= inst.operands[2].reg << 12; | |
10134 | } | |
b99bd4ef | 10135 | |
c19d1205 ZW |
10136 | static void |
10137 | do_iwmmxt_waligni (void) | |
10138 | { | |
10139 | inst.instruction |= inst.operands[0].reg << 12; | |
10140 | inst.instruction |= inst.operands[1].reg << 16; | |
10141 | inst.instruction |= inst.operands[2].reg; | |
10142 | inst.instruction |= inst.operands[3].imm << 20; | |
10143 | } | |
b99bd4ef | 10144 | |
2d447fca JM |
10145 | static void |
10146 | do_iwmmxt_wmerge (void) | |
10147 | { | |
10148 | inst.instruction |= inst.operands[0].reg << 12; | |
10149 | inst.instruction |= inst.operands[1].reg << 16; | |
10150 | inst.instruction |= inst.operands[2].reg; | |
10151 | inst.instruction |= inst.operands[3].imm << 21; | |
10152 | } | |
10153 | ||
c19d1205 ZW |
10154 | static void |
10155 | do_iwmmxt_wmov (void) | |
10156 | { | |
10157 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
10158 | inst.instruction |= inst.operands[0].reg << 12; | |
10159 | inst.instruction |= inst.operands[1].reg << 16; | |
10160 | inst.instruction |= inst.operands[1].reg; | |
10161 | } | |
b99bd4ef | 10162 | |
c19d1205 ZW |
10163 | static void |
10164 | do_iwmmxt_wldstbh (void) | |
10165 | { | |
8f06b2d8 | 10166 | int reloc; |
c19d1205 | 10167 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
10168 | if (thumb_mode) |
10169 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
10170 | else | |
10171 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
10172 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
10173 | } |
10174 | ||
c19d1205 ZW |
10175 | static void |
10176 | do_iwmmxt_wldstw (void) | |
10177 | { | |
10178 | /* RIWR_RIWC clears .isreg for a control register. */ | |
10179 | if (!inst.operands[0].isreg) | |
10180 | { | |
10181 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
10182 | inst.instruction |= 0xf0000000; | |
10183 | } | |
b99bd4ef | 10184 | |
c19d1205 ZW |
10185 | inst.instruction |= inst.operands[0].reg << 12; |
10186 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
10187 | } | |
b99bd4ef NC |
10188 | |
10189 | static void | |
c19d1205 | 10190 | do_iwmmxt_wldstd (void) |
b99bd4ef | 10191 | { |
c19d1205 | 10192 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
10193 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
10194 | && inst.operands[1].immisreg) | |
10195 | { | |
10196 | inst.instruction &= ~0x1a000ff; | |
eff0bc54 | 10197 | inst.instruction |= (0xfU << 28); |
2d447fca JM |
10198 | if (inst.operands[1].preind) |
10199 | inst.instruction |= PRE_INDEX; | |
10200 | if (!inst.operands[1].negative) | |
10201 | inst.instruction |= INDEX_UP; | |
10202 | if (inst.operands[1].writeback) | |
10203 | inst.instruction |= WRITE_BACK; | |
10204 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 10205 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
2d447fca JM |
10206 | inst.instruction |= inst.operands[1].imm; |
10207 | } | |
10208 | else | |
10209 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 10210 | } |
b99bd4ef | 10211 | |
c19d1205 ZW |
10212 | static void |
10213 | do_iwmmxt_wshufh (void) | |
10214 | { | |
10215 | inst.instruction |= inst.operands[0].reg << 12; | |
10216 | inst.instruction |= inst.operands[1].reg << 16; | |
10217 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
10218 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
10219 | } | |
b99bd4ef | 10220 | |
c19d1205 ZW |
10221 | static void |
10222 | do_iwmmxt_wzero (void) | |
10223 | { | |
10224 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
10225 | inst.instruction |= inst.operands[0].reg; | |
10226 | inst.instruction |= inst.operands[0].reg << 12; | |
10227 | inst.instruction |= inst.operands[0].reg << 16; | |
10228 | } | |
2d447fca JM |
10229 | |
10230 | static void | |
10231 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
10232 | { | |
10233 | if (inst.operands[2].isreg) | |
10234 | do_rd_rn_rm (); | |
10235 | else { | |
10236 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
10237 | _("immediate operand requires iWMMXt2")); | |
10238 | do_rd_rn (); | |
10239 | if (inst.operands[2].imm == 0) | |
10240 | { | |
10241 | switch ((inst.instruction >> 20) & 0xf) | |
10242 | { | |
10243 | case 4: | |
10244 | case 5: | |
10245 | case 6: | |
5f4273c7 | 10246 | case 7: |
2d447fca JM |
10247 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
10248 | inst.operands[2].imm = 16; | |
10249 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
10250 | break; | |
10251 | case 8: | |
10252 | case 9: | |
10253 | case 10: | |
10254 | case 11: | |
10255 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
10256 | inst.operands[2].imm = 32; | |
10257 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
10258 | break; | |
10259 | case 12: | |
10260 | case 13: | |
10261 | case 14: | |
10262 | case 15: | |
10263 | { | |
10264 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
10265 | unsigned long wrn; | |
10266 | wrn = (inst.instruction >> 16) & 0xf; | |
10267 | inst.instruction &= 0xff0fff0f; | |
10268 | inst.instruction |= wrn; | |
10269 | /* Bail out here; the instruction is now assembled. */ | |
10270 | return; | |
10271 | } | |
10272 | } | |
10273 | } | |
10274 | /* Map 32 -> 0, etc. */ | |
10275 | inst.operands[2].imm &= 0x1f; | |
eff0bc54 | 10276 | inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); |
2d447fca JM |
10277 | } |
10278 | } | |
c19d1205 ZW |
10279 | \f |
10280 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
10281 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 10282 | |
c19d1205 | 10283 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 10284 | |
c19d1205 ZW |
10285 | static void |
10286 | do_mav_triple (void) | |
10287 | { | |
10288 | inst.instruction |= inst.operands[0].reg << 16; | |
10289 | inst.instruction |= inst.operands[1].reg; | |
10290 | inst.instruction |= inst.operands[2].reg << 12; | |
10291 | } | |
b99bd4ef | 10292 | |
c19d1205 ZW |
10293 | /* Insns like "foo W,X,Y,Z". |
10294 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 10295 | |
c19d1205 ZW |
10296 | static void |
10297 | do_mav_quad (void) | |
10298 | { | |
10299 | inst.instruction |= inst.operands[0].reg << 5; | |
10300 | inst.instruction |= inst.operands[1].reg << 12; | |
10301 | inst.instruction |= inst.operands[2].reg << 16; | |
10302 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
10303 | } |
10304 | ||
c19d1205 ZW |
10305 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
10306 | static void | |
10307 | do_mav_dspsc (void) | |
a737bd4d | 10308 | { |
c19d1205 ZW |
10309 | inst.instruction |= inst.operands[1].reg << 12; |
10310 | } | |
a737bd4d | 10311 | |
c19d1205 ZW |
10312 | /* Maverick shift immediate instructions. |
10313 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
10314 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 10315 | |
c19d1205 ZW |
10316 | static void |
10317 | do_mav_shift (void) | |
10318 | { | |
10319 | int imm = inst.operands[2].imm; | |
a737bd4d | 10320 | |
c19d1205 ZW |
10321 | inst.instruction |= inst.operands[0].reg << 12; |
10322 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 10323 | |
c19d1205 ZW |
10324 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
10325 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
10326 | Bit 4 should be 0. */ | |
10327 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 10328 | |
c19d1205 ZW |
10329 | inst.instruction |= imm; |
10330 | } | |
10331 | \f | |
10332 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 10333 | |
c19d1205 ZW |
10334 | /* Xscale multiply-accumulate (argument parse) |
10335 | MIAcc acc0,Rm,Rs | |
10336 | MIAPHcc acc0,Rm,Rs | |
10337 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 10338 | |
c19d1205 ZW |
10339 | static void |
10340 | do_xsc_mia (void) | |
10341 | { | |
10342 | inst.instruction |= inst.operands[1].reg; | |
10343 | inst.instruction |= inst.operands[2].reg << 12; | |
10344 | } | |
a737bd4d | 10345 | |
c19d1205 | 10346 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 10347 | |
c19d1205 | 10348 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 10349 | |
c19d1205 ZW |
10350 | static void |
10351 | do_xsc_mar (void) | |
10352 | { | |
10353 | inst.instruction |= inst.operands[1].reg << 12; | |
10354 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10355 | } |
10356 | ||
c19d1205 | 10357 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 10358 | |
c19d1205 | 10359 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
10360 | |
10361 | static void | |
c19d1205 | 10362 | do_xsc_mra (void) |
b99bd4ef | 10363 | { |
c19d1205 ZW |
10364 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
10365 | inst.instruction |= inst.operands[0].reg << 12; | |
10366 | inst.instruction |= inst.operands[1].reg << 16; | |
10367 | } | |
10368 | \f | |
10369 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 10370 | |
c19d1205 ZW |
10371 | /* inst.operands[i] is a shifted-register operand; encode |
10372 | it into inst.instruction in the format used by Thumb32. */ | |
10373 | ||
10374 | static void | |
10375 | encode_thumb32_shifted_operand (int i) | |
10376 | { | |
e2b0ab59 | 10377 | unsigned int value = inst.relocs[0].exp.X_add_number; |
c19d1205 | 10378 | unsigned int shift = inst.operands[i].shift_kind; |
b99bd4ef | 10379 | |
9c3c69f2 PB |
10380 | constraint (inst.operands[i].immisreg, |
10381 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
10382 | inst.instruction |= inst.operands[i].reg; |
10383 | if (shift == SHIFT_RRX) | |
10384 | inst.instruction |= SHIFT_ROR << 4; | |
10385 | else | |
b99bd4ef | 10386 | { |
e2b0ab59 | 10387 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 ZW |
10388 | _("expression too complex")); |
10389 | ||
10390 | constraint (value > 32 | |
10391 | || (value == 32 && (shift == SHIFT_LSL | |
10392 | || shift == SHIFT_ROR)), | |
10393 | _("shift expression is too large")); | |
10394 | ||
10395 | if (value == 0) | |
10396 | shift = SHIFT_LSL; | |
10397 | else if (value == 32) | |
10398 | value = 0; | |
10399 | ||
10400 | inst.instruction |= shift << 4; | |
10401 | inst.instruction |= (value & 0x1c) << 10; | |
10402 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 10403 | } |
c19d1205 | 10404 | } |
b99bd4ef | 10405 | |
b99bd4ef | 10406 | |
c19d1205 ZW |
10407 | /* inst.operands[i] was set up by parse_address. Encode it into a |
10408 | Thumb32 format load or store instruction. Reject forms that cannot | |
10409 | be used with such instructions. If is_t is true, reject forms that | |
10410 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
10411 | that cannot be used with a D instruction. If it is a store insn, |
10412 | reject PC in Rn. */ | |
b99bd4ef | 10413 | |
c19d1205 ZW |
10414 | static void |
10415 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
10416 | { | |
5be8be5d | 10417 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
10418 | |
10419 | constraint (!inst.operands[i].isreg, | |
53365c0d | 10420 | _("Instruction does not support =N addresses")); |
b99bd4ef | 10421 | |
c19d1205 ZW |
10422 | inst.instruction |= inst.operands[i].reg << 16; |
10423 | if (inst.operands[i].immisreg) | |
b99bd4ef | 10424 | { |
5be8be5d | 10425 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
10426 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
10427 | constraint (inst.operands[i].negative, | |
10428 | _("Thumb does not support negative register indexing")); | |
10429 | constraint (inst.operands[i].postind, | |
10430 | _("Thumb does not support register post-indexing")); | |
10431 | constraint (inst.operands[i].writeback, | |
10432 | _("Thumb does not support register indexing with writeback")); | |
10433 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
10434 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 10435 | |
f40d1643 | 10436 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 10437 | if (inst.operands[i].shifted) |
b99bd4ef | 10438 | { |
e2b0ab59 | 10439 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 10440 | _("expression too complex")); |
e2b0ab59 AV |
10441 | constraint (inst.relocs[0].exp.X_add_number < 0 |
10442 | || inst.relocs[0].exp.X_add_number > 3, | |
c19d1205 | 10443 | _("shift out of range")); |
e2b0ab59 | 10444 | inst.instruction |= inst.relocs[0].exp.X_add_number << 4; |
c19d1205 | 10445 | } |
e2b0ab59 | 10446 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 ZW |
10447 | } |
10448 | else if (inst.operands[i].preind) | |
10449 | { | |
5be8be5d | 10450 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 10451 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 10452 | _("cannot use writeback with this instruction")); |
4755303e WN |
10453 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0), |
10454 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
10455 | |
10456 | if (is_d) | |
10457 | { | |
10458 | inst.instruction |= 0x01000000; | |
10459 | if (inst.operands[i].writeback) | |
10460 | inst.instruction |= 0x00200000; | |
b99bd4ef | 10461 | } |
c19d1205 | 10462 | else |
b99bd4ef | 10463 | { |
c19d1205 ZW |
10464 | inst.instruction |= 0x00000c00; |
10465 | if (inst.operands[i].writeback) | |
10466 | inst.instruction |= 0x00000100; | |
b99bd4ef | 10467 | } |
e2b0ab59 | 10468 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 10469 | } |
c19d1205 | 10470 | else if (inst.operands[i].postind) |
b99bd4ef | 10471 | { |
9c2799c2 | 10472 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
10473 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
10474 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
10475 | ||
10476 | if (is_d) | |
10477 | inst.instruction |= 0x00200000; | |
10478 | else | |
10479 | inst.instruction |= 0x00000900; | |
e2b0ab59 | 10480 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
c19d1205 ZW |
10481 | } |
10482 | else /* unindexed - only for coprocessor */ | |
10483 | inst.error = _("instruction does not accept unindexed addressing"); | |
10484 | } | |
10485 | ||
10486 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
10487 | encodings (the latter only in post-V6T2 cores). The index is the | |
10488 | value used in the insns table below. When there is more than one | |
10489 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
10490 | holds variant (1). |
10491 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 10492 | #define T16_32_TAB \ |
21d799b5 NC |
10493 | X(_adc, 4140, eb400000), \ |
10494 | X(_adcs, 4140, eb500000), \ | |
10495 | X(_add, 1c00, eb000000), \ | |
10496 | X(_adds, 1c00, eb100000), \ | |
10497 | X(_addi, 0000, f1000000), \ | |
10498 | X(_addis, 0000, f1100000), \ | |
10499 | X(_add_pc,000f, f20f0000), \ | |
10500 | X(_add_sp,000d, f10d0000), \ | |
10501 | X(_adr, 000f, f20f0000), \ | |
10502 | X(_and, 4000, ea000000), \ | |
10503 | X(_ands, 4000, ea100000), \ | |
10504 | X(_asr, 1000, fa40f000), \ | |
10505 | X(_asrs, 1000, fa50f000), \ | |
10506 | X(_b, e000, f000b000), \ | |
10507 | X(_bcond, d000, f0008000), \ | |
4389b29a | 10508 | X(_bf, 0000, f040e001), \ |
f1c7f421 | 10509 | X(_bfx, 0000, f060e001), \ |
65d1bc05 | 10510 | X(_bfl, 0000, f000c001), \ |
f1c7f421 | 10511 | X(_bflx, 0000, f070e001), \ |
21d799b5 NC |
10512 | X(_bic, 4380, ea200000), \ |
10513 | X(_bics, 4380, ea300000), \ | |
10514 | X(_cmn, 42c0, eb100f00), \ | |
10515 | X(_cmp, 2800, ebb00f00), \ | |
10516 | X(_cpsie, b660, f3af8400), \ | |
10517 | X(_cpsid, b670, f3af8600), \ | |
10518 | X(_cpy, 4600, ea4f0000), \ | |
10519 | X(_dec_sp,80dd, f1ad0d00), \ | |
10520 | X(_eor, 4040, ea800000), \ | |
10521 | X(_eors, 4040, ea900000), \ | |
10522 | X(_inc_sp,00dd, f10d0d00), \ | |
10523 | X(_ldmia, c800, e8900000), \ | |
10524 | X(_ldr, 6800, f8500000), \ | |
10525 | X(_ldrb, 7800, f8100000), \ | |
10526 | X(_ldrh, 8800, f8300000), \ | |
10527 | X(_ldrsb, 5600, f9100000), \ | |
10528 | X(_ldrsh, 5e00, f9300000), \ | |
10529 | X(_ldr_pc,4800, f85f0000), \ | |
10530 | X(_ldr_pc2,4800, f85f0000), \ | |
10531 | X(_ldr_sp,9800, f85d0000), \ | |
10532 | X(_lsl, 0000, fa00f000), \ | |
10533 | X(_lsls, 0000, fa10f000), \ | |
10534 | X(_lsr, 0800, fa20f000), \ | |
10535 | X(_lsrs, 0800, fa30f000), \ | |
10536 | X(_mov, 2000, ea4f0000), \ | |
10537 | X(_movs, 2000, ea5f0000), \ | |
10538 | X(_mul, 4340, fb00f000), \ | |
10539 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
10540 | X(_mvn, 43c0, ea6f0000), \ | |
10541 | X(_mvns, 43c0, ea7f0000), \ | |
10542 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
10543 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
10544 | X(_orr, 4300, ea400000), \ | |
10545 | X(_orrs, 4300, ea500000), \ | |
10546 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
10547 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
10548 | X(_rev, ba00, fa90f080), \ | |
10549 | X(_rev16, ba40, fa90f090), \ | |
10550 | X(_revsh, bac0, fa90f0b0), \ | |
10551 | X(_ror, 41c0, fa60f000), \ | |
10552 | X(_rors, 41c0, fa70f000), \ | |
10553 | X(_sbc, 4180, eb600000), \ | |
10554 | X(_sbcs, 4180, eb700000), \ | |
10555 | X(_stmia, c000, e8800000), \ | |
10556 | X(_str, 6000, f8400000), \ | |
10557 | X(_strb, 7000, f8000000), \ | |
10558 | X(_strh, 8000, f8200000), \ | |
10559 | X(_str_sp,9000, f84d0000), \ | |
10560 | X(_sub, 1e00, eba00000), \ | |
10561 | X(_subs, 1e00, ebb00000), \ | |
10562 | X(_subi, 8000, f1a00000), \ | |
10563 | X(_subis, 8000, f1b00000), \ | |
10564 | X(_sxtb, b240, fa4ff080), \ | |
10565 | X(_sxth, b200, fa0ff080), \ | |
10566 | X(_tst, 4200, ea100f00), \ | |
10567 | X(_uxtb, b2c0, fa5ff080), \ | |
10568 | X(_uxth, b280, fa1ff080), \ | |
10569 | X(_nop, bf00, f3af8000), \ | |
10570 | X(_yield, bf10, f3af8001), \ | |
10571 | X(_wfe, bf20, f3af8002), \ | |
10572 | X(_wfi, bf30, f3af8003), \ | |
53c4b28b | 10573 | X(_sev, bf40, f3af8004), \ |
74db7efb NC |
10574 | X(_sevl, bf50, f3af8005), \ |
10575 | X(_udf, de00, f7f0a000) | |
c19d1205 ZW |
10576 | |
10577 | /* To catch errors in encoding functions, the codes are all offset by | |
10578 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
10579 | as 16-bit instructions. */ | |
21d799b5 | 10580 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
10581 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
10582 | #undef X | |
10583 | ||
10584 | #define X(a,b,c) 0x##b | |
10585 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
10586 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
10587 | #undef X | |
10588 | ||
10589 | #define X(a,b,c) 0x##c | |
10590 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
10591 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
10592 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
10593 | #undef X |
10594 | #undef T16_32_TAB | |
10595 | ||
10596 | /* Thumb instruction encoders, in alphabetical order. */ | |
10597 | ||
92e90b6e | 10598 | /* ADDW or SUBW. */ |
c921be7d | 10599 | |
92e90b6e PB |
10600 | static void |
10601 | do_t_add_sub_w (void) | |
10602 | { | |
10603 | int Rd, Rn; | |
10604 | ||
10605 | Rd = inst.operands[0].reg; | |
10606 | Rn = inst.operands[1].reg; | |
10607 | ||
539d4391 NC |
10608 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
10609 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
10610 | if (Rn == REG_SP) | |
10611 | constraint (Rd == REG_PC, BAD_PC); | |
10612 | else | |
10613 | reject_bad_reg (Rd); | |
fdfde340 | 10614 | |
92e90b6e | 10615 | inst.instruction |= (Rn << 16) | (Rd << 8); |
e2b0ab59 | 10616 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
92e90b6e PB |
10617 | } |
10618 | ||
c19d1205 | 10619 | /* Parse an add or subtract instruction. We get here with inst.instruction |
33eaf5de | 10620 | equaling any of THUMB_OPCODE_add, adds, sub, or subs. */ |
c19d1205 ZW |
10621 | |
10622 | static void | |
10623 | do_t_add_sub (void) | |
10624 | { | |
10625 | int Rd, Rs, Rn; | |
10626 | ||
10627 | Rd = inst.operands[0].reg; | |
10628 | Rs = (inst.operands[1].present | |
10629 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10630 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10631 | ||
e07e6e58 NC |
10632 | if (Rd == REG_PC) |
10633 | set_it_insn_type_last (); | |
10634 | ||
c19d1205 ZW |
10635 | if (unified_syntax) |
10636 | { | |
0110f2b8 PB |
10637 | bfd_boolean flags; |
10638 | bfd_boolean narrow; | |
10639 | int opcode; | |
10640 | ||
10641 | flags = (inst.instruction == T_MNEM_adds | |
10642 | || inst.instruction == T_MNEM_subs); | |
10643 | if (flags) | |
e07e6e58 | 10644 | narrow = !in_it_block (); |
0110f2b8 | 10645 | else |
e07e6e58 | 10646 | narrow = in_it_block (); |
c19d1205 | 10647 | if (!inst.operands[2].isreg) |
b99bd4ef | 10648 | { |
16805f35 PB |
10649 | int add; |
10650 | ||
5c8ed6a4 JW |
10651 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
10652 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 | 10653 | |
16805f35 PB |
10654 | add = (inst.instruction == T_MNEM_add |
10655 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
10656 | opcode = 0; |
10657 | if (inst.size_req != 4) | |
10658 | { | |
0110f2b8 | 10659 | /* Attempt to use a narrow opcode, with relaxation if |
477330fc | 10660 | appropriate. */ |
0110f2b8 PB |
10661 | if (Rd == REG_SP && Rs == REG_SP && !flags) |
10662 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
10663 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
10664 | opcode = T_MNEM_add_sp; | |
10665 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
10666 | opcode = T_MNEM_add_pc; | |
10667 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
10668 | { | |
10669 | if (flags) | |
10670 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
10671 | else | |
10672 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
10673 | } | |
10674 | if (opcode) | |
10675 | { | |
10676 | inst.instruction = THUMB_OP16(opcode); | |
10677 | inst.instruction |= (Rd << 4) | Rs; | |
e2b0ab59 AV |
10678 | if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
10679 | || (inst.relocs[0].type | |
10680 | > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)) | |
a9f02af8 MG |
10681 | { |
10682 | if (inst.size_req == 2) | |
e2b0ab59 | 10683 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
a9f02af8 MG |
10684 | else |
10685 | inst.relax = opcode; | |
10686 | } | |
0110f2b8 PB |
10687 | } |
10688 | else | |
10689 | constraint (inst.size_req == 2, BAD_HIREG); | |
10690 | } | |
10691 | if (inst.size_req == 4 | |
10692 | || (inst.size_req != 2 && !opcode)) | |
10693 | { | |
e2b0ab59 AV |
10694 | constraint ((inst.relocs[0].type |
10695 | >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC) | |
10696 | && (inst.relocs[0].type | |
10697 | <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) , | |
a9f02af8 | 10698 | THUMB1_RELOC_ONLY); |
efd81785 PB |
10699 | if (Rd == REG_PC) |
10700 | { | |
fdfde340 | 10701 | constraint (add, BAD_PC); |
efd81785 PB |
10702 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
10703 | _("only SUBS PC, LR, #const allowed")); | |
e2b0ab59 | 10704 | constraint (inst.relocs[0].exp.X_op != O_constant, |
efd81785 | 10705 | _("expression too complex")); |
e2b0ab59 AV |
10706 | constraint (inst.relocs[0].exp.X_add_number < 0 |
10707 | || inst.relocs[0].exp.X_add_number > 0xff, | |
efd81785 PB |
10708 | _("immediate value out of range")); |
10709 | inst.instruction = T2_SUBS_PC_LR | |
e2b0ab59 AV |
10710 | | inst.relocs[0].exp.X_add_number; |
10711 | inst.relocs[0].type = BFD_RELOC_UNUSED; | |
efd81785 PB |
10712 | return; |
10713 | } | |
10714 | else if (Rs == REG_PC) | |
16805f35 PB |
10715 | { |
10716 | /* Always use addw/subw. */ | |
10717 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
e2b0ab59 | 10718 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12; |
16805f35 PB |
10719 | } |
10720 | else | |
10721 | { | |
10722 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10723 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
10724 | | 0x10000000; | |
10725 | if (flags) | |
e2b0ab59 | 10726 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
16805f35 | 10727 | else |
e2b0ab59 | 10728 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM; |
16805f35 | 10729 | } |
dc4503c6 PB |
10730 | inst.instruction |= Rd << 8; |
10731 | inst.instruction |= Rs << 16; | |
0110f2b8 | 10732 | } |
b99bd4ef | 10733 | } |
c19d1205 ZW |
10734 | else |
10735 | { | |
e2b0ab59 | 10736 | unsigned int value = inst.relocs[0].exp.X_add_number; |
5f4cb198 NC |
10737 | unsigned int shift = inst.operands[2].shift_kind; |
10738 | ||
c19d1205 ZW |
10739 | Rn = inst.operands[2].reg; |
10740 | /* See if we can do this with a 16-bit instruction. */ | |
10741 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
10742 | { | |
e27ec89e PB |
10743 | if (Rd > 7 || Rs > 7 || Rn > 7) |
10744 | narrow = FALSE; | |
10745 | ||
10746 | if (narrow) | |
c19d1205 | 10747 | { |
e27ec89e PB |
10748 | inst.instruction = ((inst.instruction == T_MNEM_adds |
10749 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
10750 | ? T_OPCODE_ADD_R3 |
10751 | : T_OPCODE_SUB_R3); | |
10752 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
10753 | return; | |
10754 | } | |
b99bd4ef | 10755 | |
7e806470 | 10756 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 10757 | { |
7e806470 PB |
10758 | /* Thumb-1 cores (except v6-M) require at least one high |
10759 | register in a narrow non flag setting add. */ | |
10760 | if (Rd > 7 || Rn > 7 | |
10761 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
10762 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 10763 | { |
7e806470 PB |
10764 | if (Rd == Rn) |
10765 | { | |
10766 | Rn = Rs; | |
10767 | Rs = Rd; | |
10768 | } | |
c19d1205 ZW |
10769 | inst.instruction = T_OPCODE_ADD_HI; |
10770 | inst.instruction |= (Rd & 8) << 4; | |
10771 | inst.instruction |= (Rd & 7); | |
10772 | inst.instruction |= Rn << 3; | |
10773 | return; | |
10774 | } | |
c19d1205 ZW |
10775 | } |
10776 | } | |
c921be7d | 10777 | |
fdfde340 | 10778 | constraint (Rd == REG_PC, BAD_PC); |
5c8ed6a4 JW |
10779 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
10780 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
fdfde340 JM |
10781 | constraint (Rs == REG_PC, BAD_PC); |
10782 | reject_bad_reg (Rn); | |
10783 | ||
c19d1205 ZW |
10784 | /* If we get here, it can't be done in 16 bits. */ |
10785 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
10786 | _("shift must be constant")); | |
10787 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10788 | inst.instruction |= Rd << 8; | |
10789 | inst.instruction |= Rs << 16; | |
5f4cb198 NC |
10790 | constraint (Rd == REG_SP && Rs == REG_SP && value > 3, |
10791 | _("shift value over 3 not allowed in thumb mode")); | |
10792 | constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL, | |
10793 | _("only LSL shift allowed in thumb mode")); | |
c19d1205 ZW |
10794 | encode_thumb32_shifted_operand (2); |
10795 | } | |
10796 | } | |
10797 | else | |
10798 | { | |
10799 | constraint (inst.instruction == T_MNEM_adds | |
10800 | || inst.instruction == T_MNEM_subs, | |
10801 | BAD_THUMB32); | |
b99bd4ef | 10802 | |
c19d1205 | 10803 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 10804 | { |
c19d1205 ZW |
10805 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
10806 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
10807 | BAD_HIREG); | |
10808 | ||
10809 | inst.instruction = (inst.instruction == T_MNEM_add | |
10810 | ? 0x0000 : 0x8000); | |
10811 | inst.instruction |= (Rd << 4) | Rs; | |
e2b0ab59 | 10812 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
b99bd4ef NC |
10813 | return; |
10814 | } | |
10815 | ||
c19d1205 ZW |
10816 | Rn = inst.operands[2].reg; |
10817 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 10818 | |
c19d1205 ZW |
10819 | /* We now have Rd, Rs, and Rn set to registers. */ |
10820 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 10821 | { |
c19d1205 ZW |
10822 | /* Can't do this for SUB. */ |
10823 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
10824 | inst.instruction = T_OPCODE_ADD_HI; | |
10825 | inst.instruction |= (Rd & 8) << 4; | |
10826 | inst.instruction |= (Rd & 7); | |
10827 | if (Rs == Rd) | |
10828 | inst.instruction |= Rn << 3; | |
10829 | else if (Rn == Rd) | |
10830 | inst.instruction |= Rs << 3; | |
10831 | else | |
10832 | constraint (1, _("dest must overlap one source register")); | |
10833 | } | |
10834 | else | |
10835 | { | |
10836 | inst.instruction = (inst.instruction == T_MNEM_add | |
10837 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
10838 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 10839 | } |
b99bd4ef | 10840 | } |
b99bd4ef NC |
10841 | } |
10842 | ||
c19d1205 ZW |
10843 | static void |
10844 | do_t_adr (void) | |
10845 | { | |
fdfde340 JM |
10846 | unsigned Rd; |
10847 | ||
10848 | Rd = inst.operands[0].reg; | |
10849 | reject_bad_reg (Rd); | |
10850 | ||
10851 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
10852 | { |
10853 | /* Defer to section relaxation. */ | |
10854 | inst.relax = inst.instruction; | |
10855 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 10856 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
10857 | } |
10858 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 10859 | { |
0110f2b8 | 10860 | /* Generate a 32-bit opcode. */ |
e9f89963 | 10861 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 10862 | inst.instruction |= Rd << 8; |
e2b0ab59 AV |
10863 | inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12; |
10864 | inst.relocs[0].pc_rel = 1; | |
e9f89963 PB |
10865 | } |
10866 | else | |
10867 | { | |
0110f2b8 | 10868 | /* Generate a 16-bit opcode. */ |
e9f89963 | 10869 | inst.instruction = THUMB_OP16 (inst.instruction); |
e2b0ab59 AV |
10870 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD; |
10871 | inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */ | |
10872 | inst.relocs[0].pc_rel = 1; | |
fdfde340 | 10873 | inst.instruction |= Rd << 4; |
e9f89963 | 10874 | } |
52a86f84 | 10875 | |
e2b0ab59 AV |
10876 | if (inst.relocs[0].exp.X_op == O_symbol |
10877 | && inst.relocs[0].exp.X_add_symbol != NULL | |
10878 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
10879 | && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
10880 | inst.relocs[0].exp.X_add_number += 1; | |
c19d1205 | 10881 | } |
b99bd4ef | 10882 | |
c19d1205 ZW |
10883 | /* Arithmetic instructions for which there is just one 16-bit |
10884 | instruction encoding, and it allows only two low registers. | |
10885 | For maximal compatibility with ARM syntax, we allow three register | |
10886 | operands even when Thumb-32 instructions are not available, as long | |
10887 | as the first two are identical. For instance, both "sbc r0,r1" and | |
10888 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 10889 | static void |
c19d1205 | 10890 | do_t_arit3 (void) |
b99bd4ef | 10891 | { |
c19d1205 | 10892 | int Rd, Rs, Rn; |
b99bd4ef | 10893 | |
c19d1205 ZW |
10894 | Rd = inst.operands[0].reg; |
10895 | Rs = (inst.operands[1].present | |
10896 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10897 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10898 | Rn = inst.operands[2].reg; | |
b99bd4ef | 10899 | |
fdfde340 JM |
10900 | reject_bad_reg (Rd); |
10901 | reject_bad_reg (Rs); | |
10902 | if (inst.operands[2].isreg) | |
10903 | reject_bad_reg (Rn); | |
10904 | ||
c19d1205 | 10905 | if (unified_syntax) |
b99bd4ef | 10906 | { |
c19d1205 ZW |
10907 | if (!inst.operands[2].isreg) |
10908 | { | |
10909 | /* For an immediate, we always generate a 32-bit opcode; | |
10910 | section relaxation will shrink it later if possible. */ | |
10911 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10912 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10913 | inst.instruction |= Rd << 8; | |
10914 | inst.instruction |= Rs << 16; | |
e2b0ab59 | 10915 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
c19d1205 ZW |
10916 | } |
10917 | else | |
10918 | { | |
e27ec89e PB |
10919 | bfd_boolean narrow; |
10920 | ||
c19d1205 | 10921 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 10922 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 10923 | narrow = !in_it_block (); |
e27ec89e | 10924 | else |
e07e6e58 | 10925 | narrow = in_it_block (); |
e27ec89e PB |
10926 | |
10927 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
10928 | narrow = FALSE; | |
10929 | if (inst.operands[2].shifted) | |
10930 | narrow = FALSE; | |
10931 | if (inst.size_req == 4) | |
10932 | narrow = FALSE; | |
10933 | ||
10934 | if (narrow | |
c19d1205 ZW |
10935 | && Rd == Rs) |
10936 | { | |
10937 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10938 | inst.instruction |= Rd; | |
10939 | inst.instruction |= Rn << 3; | |
10940 | return; | |
10941 | } | |
b99bd4ef | 10942 | |
c19d1205 ZW |
10943 | /* If we get here, it can't be done in 16 bits. */ |
10944 | constraint (inst.operands[2].shifted | |
10945 | && inst.operands[2].immisreg, | |
10946 | _("shift must be constant")); | |
10947 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10948 | inst.instruction |= Rd << 8; | |
10949 | inst.instruction |= Rs << 16; | |
10950 | encode_thumb32_shifted_operand (2); | |
10951 | } | |
a737bd4d | 10952 | } |
c19d1205 | 10953 | else |
b99bd4ef | 10954 | { |
c19d1205 ZW |
10955 | /* On its face this is a lie - the instruction does set the |
10956 | flags. However, the only supported mnemonic in this mode | |
10957 | says it doesn't. */ | |
10958 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 10959 | |
c19d1205 ZW |
10960 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
10961 | _("unshifted register required")); | |
10962 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
10963 | constraint (Rd != Rs, | |
10964 | _("dest and source1 must be the same register")); | |
a737bd4d | 10965 | |
c19d1205 ZW |
10966 | inst.instruction = THUMB_OP16 (inst.instruction); |
10967 | inst.instruction |= Rd; | |
10968 | inst.instruction |= Rn << 3; | |
b99bd4ef | 10969 | } |
a737bd4d | 10970 | } |
b99bd4ef | 10971 | |
c19d1205 ZW |
10972 | /* Similarly, but for instructions where the arithmetic operation is |
10973 | commutative, so we can allow either of them to be different from | |
10974 | the destination operand in a 16-bit instruction. For instance, all | |
10975 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
10976 | accepted. */ | |
10977 | static void | |
10978 | do_t_arit3c (void) | |
a737bd4d | 10979 | { |
c19d1205 | 10980 | int Rd, Rs, Rn; |
b99bd4ef | 10981 | |
c19d1205 ZW |
10982 | Rd = inst.operands[0].reg; |
10983 | Rs = (inst.operands[1].present | |
10984 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10985 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10986 | Rn = inst.operands[2].reg; | |
c921be7d | 10987 | |
fdfde340 JM |
10988 | reject_bad_reg (Rd); |
10989 | reject_bad_reg (Rs); | |
10990 | if (inst.operands[2].isreg) | |
10991 | reject_bad_reg (Rn); | |
a737bd4d | 10992 | |
c19d1205 | 10993 | if (unified_syntax) |
a737bd4d | 10994 | { |
c19d1205 | 10995 | if (!inst.operands[2].isreg) |
b99bd4ef | 10996 | { |
c19d1205 ZW |
10997 | /* For an immediate, we always generate a 32-bit opcode; |
10998 | section relaxation will shrink it later if possible. */ | |
10999 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11000 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
11001 | inst.instruction |= Rd << 8; | |
11002 | inst.instruction |= Rs << 16; | |
e2b0ab59 | 11003 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 11004 | } |
c19d1205 | 11005 | else |
a737bd4d | 11006 | { |
e27ec89e PB |
11007 | bfd_boolean narrow; |
11008 | ||
c19d1205 | 11009 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 11010 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 11011 | narrow = !in_it_block (); |
e27ec89e | 11012 | else |
e07e6e58 | 11013 | narrow = in_it_block (); |
e27ec89e PB |
11014 | |
11015 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
11016 | narrow = FALSE; | |
11017 | if (inst.operands[2].shifted) | |
11018 | narrow = FALSE; | |
11019 | if (inst.size_req == 4) | |
11020 | narrow = FALSE; | |
11021 | ||
11022 | if (narrow) | |
a737bd4d | 11023 | { |
c19d1205 | 11024 | if (Rd == Rs) |
a737bd4d | 11025 | { |
c19d1205 ZW |
11026 | inst.instruction = THUMB_OP16 (inst.instruction); |
11027 | inst.instruction |= Rd; | |
11028 | inst.instruction |= Rn << 3; | |
11029 | return; | |
a737bd4d | 11030 | } |
c19d1205 | 11031 | if (Rd == Rn) |
a737bd4d | 11032 | { |
c19d1205 ZW |
11033 | inst.instruction = THUMB_OP16 (inst.instruction); |
11034 | inst.instruction |= Rd; | |
11035 | inst.instruction |= Rs << 3; | |
11036 | return; | |
a737bd4d NC |
11037 | } |
11038 | } | |
c19d1205 ZW |
11039 | |
11040 | /* If we get here, it can't be done in 16 bits. */ | |
11041 | constraint (inst.operands[2].shifted | |
11042 | && inst.operands[2].immisreg, | |
11043 | _("shift must be constant")); | |
11044 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11045 | inst.instruction |= Rd << 8; | |
11046 | inst.instruction |= Rs << 16; | |
11047 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 11048 | } |
b99bd4ef | 11049 | } |
c19d1205 ZW |
11050 | else |
11051 | { | |
11052 | /* On its face this is a lie - the instruction does set the | |
11053 | flags. However, the only supported mnemonic in this mode | |
11054 | says it doesn't. */ | |
11055 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 11056 | |
c19d1205 ZW |
11057 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
11058 | _("unshifted register required")); | |
11059 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
11060 | ||
11061 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11062 | inst.instruction |= Rd; | |
11063 | ||
11064 | if (Rd == Rs) | |
11065 | inst.instruction |= Rn << 3; | |
11066 | else if (Rd == Rn) | |
11067 | inst.instruction |= Rs << 3; | |
11068 | else | |
11069 | constraint (1, _("dest must overlap one source register")); | |
11070 | } | |
a737bd4d NC |
11071 | } |
11072 | ||
c19d1205 ZW |
11073 | static void |
11074 | do_t_bfc (void) | |
a737bd4d | 11075 | { |
fdfde340 | 11076 | unsigned Rd; |
c19d1205 ZW |
11077 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
11078 | constraint (msb > 32, _("bit-field extends past end of register")); | |
11079 | /* The instruction encoding stores the LSB and MSB, | |
11080 | not the LSB and width. */ | |
fdfde340 JM |
11081 | Rd = inst.operands[0].reg; |
11082 | reject_bad_reg (Rd); | |
11083 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
11084 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
11085 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
11086 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
11087 | } |
11088 | ||
c19d1205 ZW |
11089 | static void |
11090 | do_t_bfi (void) | |
b99bd4ef | 11091 | { |
fdfde340 | 11092 | int Rd, Rn; |
c19d1205 | 11093 | unsigned int msb; |
b99bd4ef | 11094 | |
fdfde340 JM |
11095 | Rd = inst.operands[0].reg; |
11096 | reject_bad_reg (Rd); | |
11097 | ||
c19d1205 ZW |
11098 | /* #0 in second position is alternative syntax for bfc, which is |
11099 | the same instruction but with REG_PC in the Rm field. */ | |
11100 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
11101 | Rn = REG_PC; |
11102 | else | |
11103 | { | |
11104 | Rn = inst.operands[1].reg; | |
11105 | reject_bad_reg (Rn); | |
11106 | } | |
b99bd4ef | 11107 | |
c19d1205 ZW |
11108 | msb = inst.operands[2].imm + inst.operands[3].imm; |
11109 | constraint (msb > 32, _("bit-field extends past end of register")); | |
11110 | /* The instruction encoding stores the LSB and MSB, | |
11111 | not the LSB and width. */ | |
fdfde340 JM |
11112 | inst.instruction |= Rd << 8; |
11113 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
11114 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
11115 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
11116 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
11117 | } |
11118 | ||
c19d1205 ZW |
11119 | static void |
11120 | do_t_bfx (void) | |
b99bd4ef | 11121 | { |
fdfde340 JM |
11122 | unsigned Rd, Rn; |
11123 | ||
11124 | Rd = inst.operands[0].reg; | |
11125 | Rn = inst.operands[1].reg; | |
11126 | ||
11127 | reject_bad_reg (Rd); | |
11128 | reject_bad_reg (Rn); | |
11129 | ||
c19d1205 ZW |
11130 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
11131 | _("bit-field extends past end of register")); | |
fdfde340 JM |
11132 | inst.instruction |= Rd << 8; |
11133 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
11134 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
11135 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
11136 | inst.instruction |= inst.operands[3].imm - 1; | |
11137 | } | |
b99bd4ef | 11138 | |
c19d1205 ZW |
11139 | /* ARM V5 Thumb BLX (argument parse) |
11140 | BLX <target_addr> which is BLX(1) | |
11141 | BLX <Rm> which is BLX(2) | |
11142 | Unfortunately, there are two different opcodes for this mnemonic. | |
11143 | So, the insns[].value is not used, and the code here zaps values | |
11144 | into inst.instruction. | |
b99bd4ef | 11145 | |
c19d1205 ZW |
11146 | ??? How to take advantage of the additional two bits of displacement |
11147 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 11148 | |
c19d1205 ZW |
11149 | static void |
11150 | do_t_blx (void) | |
11151 | { | |
e07e6e58 NC |
11152 | set_it_insn_type_last (); |
11153 | ||
c19d1205 | 11154 | if (inst.operands[0].isreg) |
fdfde340 JM |
11155 | { |
11156 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
11157 | /* We have a register, so this is BLX(2). */ | |
11158 | inst.instruction |= inst.operands[0].reg << 3; | |
11159 | } | |
b99bd4ef NC |
11160 | else |
11161 | { | |
c19d1205 | 11162 | /* No register. This must be BLX(1). */ |
2fc8bdac | 11163 | inst.instruction = 0xf000e800; |
0855e32b | 11164 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
11165 | } |
11166 | } | |
11167 | ||
c19d1205 ZW |
11168 | static void |
11169 | do_t_branch (void) | |
b99bd4ef | 11170 | { |
0110f2b8 | 11171 | int opcode; |
dfa9f0d5 | 11172 | int cond; |
2fe88214 | 11173 | bfd_reloc_code_real_type reloc; |
dfa9f0d5 | 11174 | |
e07e6e58 NC |
11175 | cond = inst.cond; |
11176 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
11177 | ||
11178 | if (in_it_block ()) | |
dfa9f0d5 PB |
11179 | { |
11180 | /* Conditional branches inside IT blocks are encoded as unconditional | |
477330fc | 11181 | branches. */ |
dfa9f0d5 | 11182 | cond = COND_ALWAYS; |
dfa9f0d5 PB |
11183 | } |
11184 | else | |
11185 | cond = inst.cond; | |
11186 | ||
11187 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
11188 | opcode = T_MNEM_bcond; |
11189 | else | |
11190 | opcode = inst.instruction; | |
11191 | ||
12d6b0b7 RS |
11192 | if (unified_syntax |
11193 | && (inst.size_req == 4 | |
10960bfb PB |
11194 | || (inst.size_req != 2 |
11195 | && (inst.operands[0].hasreloc | |
e2b0ab59 | 11196 | || inst.relocs[0].exp.X_op == O_constant)))) |
c19d1205 | 11197 | { |
0110f2b8 | 11198 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 11199 | if (cond == COND_ALWAYS) |
9ae92b05 | 11200 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
11201 | else |
11202 | { | |
ff8646ee TP |
11203 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2), |
11204 | _("selected architecture does not support " | |
11205 | "wide conditional branch instruction")); | |
11206 | ||
9c2799c2 | 11207 | gas_assert (cond != 0xF); |
dfa9f0d5 | 11208 | inst.instruction |= cond << 22; |
9ae92b05 | 11209 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
11210 | } |
11211 | } | |
b99bd4ef NC |
11212 | else |
11213 | { | |
0110f2b8 | 11214 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 11215 | if (cond == COND_ALWAYS) |
9ae92b05 | 11216 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 11217 | else |
b99bd4ef | 11218 | { |
dfa9f0d5 | 11219 | inst.instruction |= cond << 8; |
9ae92b05 | 11220 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 11221 | } |
0110f2b8 PB |
11222 | /* Allow section relaxation. */ |
11223 | if (unified_syntax && inst.size_req != 2) | |
11224 | inst.relax = opcode; | |
b99bd4ef | 11225 | } |
e2b0ab59 AV |
11226 | inst.relocs[0].type = reloc; |
11227 | inst.relocs[0].pc_rel = 1; | |
b99bd4ef NC |
11228 | } |
11229 | ||
8884b720 | 11230 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 11231 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 11232 | RANGE. */ |
b99bd4ef | 11233 | static void |
8884b720 | 11234 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 11235 | { |
dfa9f0d5 PB |
11236 | constraint (inst.cond != COND_ALWAYS, |
11237 | _("instruction is always unconditional")); | |
c19d1205 | 11238 | if (inst.operands[0].present) |
b99bd4ef | 11239 | { |
8884b720 | 11240 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
11241 | _("immediate value out of range")); |
11242 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 11243 | } |
8884b720 MGD |
11244 | |
11245 | set_it_insn_type (NEUTRAL_IT_INSN); | |
11246 | } | |
11247 | ||
11248 | static void | |
11249 | do_t_hlt (void) | |
11250 | { | |
11251 | do_t_bkpt_hlt1 (63); | |
11252 | } | |
11253 | ||
11254 | static void | |
11255 | do_t_bkpt (void) | |
11256 | { | |
11257 | do_t_bkpt_hlt1 (255); | |
b99bd4ef NC |
11258 | } |
11259 | ||
11260 | static void | |
c19d1205 | 11261 | do_t_branch23 (void) |
b99bd4ef | 11262 | { |
e07e6e58 | 11263 | set_it_insn_type_last (); |
0855e32b | 11264 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 11265 | |
0855e32b NS |
11266 | /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in |
11267 | this file. We used to simply ignore the PLT reloc type here -- | |
11268 | the branch encoding is now needed to deal with TLSCALL relocs. | |
11269 | So if we see a PLT reloc now, put it back to how it used to be to | |
11270 | keep the preexisting behaviour. */ | |
e2b0ab59 AV |
11271 | if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32) |
11272 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 11273 | |
4343666d | 11274 | #if defined(OBJ_COFF) |
c19d1205 ZW |
11275 | /* If the destination of the branch is a defined symbol which does not have |
11276 | the THUMB_FUNC attribute, then we must be calling a function which has | |
11277 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
11278 | function and change the branch to refer to that function instead. */ | |
e2b0ab59 AV |
11279 | if ( inst.relocs[0].exp.X_op == O_symbol |
11280 | && inst.relocs[0].exp.X_add_symbol != NULL | |
11281 | && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol) | |
11282 | && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol)) | |
11283 | inst.relocs[0].exp.X_add_symbol | |
11284 | = find_real_start (inst.relocs[0].exp.X_add_symbol); | |
4343666d | 11285 | #endif |
90e4755a RE |
11286 | } |
11287 | ||
11288 | static void | |
c19d1205 | 11289 | do_t_bx (void) |
90e4755a | 11290 | { |
e07e6e58 | 11291 | set_it_insn_type_last (); |
c19d1205 ZW |
11292 | inst.instruction |= inst.operands[0].reg << 3; |
11293 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
11294 | should cause the alignment to be checked once it is known. This is | |
11295 | because BX PC only works if the instruction is word aligned. */ | |
11296 | } | |
90e4755a | 11297 | |
c19d1205 ZW |
11298 | static void |
11299 | do_t_bxj (void) | |
11300 | { | |
fdfde340 | 11301 | int Rm; |
90e4755a | 11302 | |
e07e6e58 | 11303 | set_it_insn_type_last (); |
fdfde340 JM |
11304 | Rm = inst.operands[0].reg; |
11305 | reject_bad_reg (Rm); | |
11306 | inst.instruction |= Rm << 16; | |
90e4755a RE |
11307 | } |
11308 | ||
11309 | static void | |
c19d1205 | 11310 | do_t_clz (void) |
90e4755a | 11311 | { |
fdfde340 JM |
11312 | unsigned Rd; |
11313 | unsigned Rm; | |
11314 | ||
11315 | Rd = inst.operands[0].reg; | |
11316 | Rm = inst.operands[1].reg; | |
11317 | ||
11318 | reject_bad_reg (Rd); | |
11319 | reject_bad_reg (Rm); | |
11320 | ||
11321 | inst.instruction |= Rd << 8; | |
11322 | inst.instruction |= Rm << 16; | |
11323 | inst.instruction |= Rm; | |
c19d1205 | 11324 | } |
90e4755a | 11325 | |
91d8b670 JG |
11326 | static void |
11327 | do_t_csdb (void) | |
11328 | { | |
11329 | set_it_insn_type (OUTSIDE_IT_INSN); | |
11330 | } | |
11331 | ||
dfa9f0d5 PB |
11332 | static void |
11333 | do_t_cps (void) | |
11334 | { | |
e07e6e58 | 11335 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
11336 | inst.instruction |= inst.operands[0].imm; |
11337 | } | |
11338 | ||
c19d1205 ZW |
11339 | static void |
11340 | do_t_cpsi (void) | |
11341 | { | |
e07e6e58 | 11342 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 11343 | if (unified_syntax |
62b3e311 PB |
11344 | && (inst.operands[1].present || inst.size_req == 4) |
11345 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 11346 | { |
c19d1205 ZW |
11347 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
11348 | inst.instruction = 0xf3af8000; | |
11349 | inst.instruction |= imod << 9; | |
11350 | inst.instruction |= inst.operands[0].imm << 5; | |
11351 | if (inst.operands[1].present) | |
11352 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 11353 | } |
c19d1205 | 11354 | else |
90e4755a | 11355 | { |
62b3e311 PB |
11356 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
11357 | && (inst.operands[0].imm & 4), | |
11358 | _("selected processor does not support 'A' form " | |
11359 | "of this instruction")); | |
11360 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
11361 | _("Thumb does not support the 2-argument " |
11362 | "form of this instruction")); | |
11363 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 11364 | } |
90e4755a RE |
11365 | } |
11366 | ||
c19d1205 ZW |
11367 | /* THUMB CPY instruction (argument parse). */ |
11368 | ||
90e4755a | 11369 | static void |
c19d1205 | 11370 | do_t_cpy (void) |
90e4755a | 11371 | { |
c19d1205 | 11372 | if (inst.size_req == 4) |
90e4755a | 11373 | { |
c19d1205 ZW |
11374 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
11375 | inst.instruction |= inst.operands[0].reg << 8; | |
11376 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 11377 | } |
c19d1205 | 11378 | else |
90e4755a | 11379 | { |
c19d1205 ZW |
11380 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
11381 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
11382 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 11383 | } |
90e4755a RE |
11384 | } |
11385 | ||
90e4755a | 11386 | static void |
25fe350b | 11387 | do_t_cbz (void) |
90e4755a | 11388 | { |
e07e6e58 | 11389 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
11390 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11391 | inst.instruction |= inst.operands[0].reg; | |
e2b0ab59 AV |
11392 | inst.relocs[0].pc_rel = 1; |
11393 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
c19d1205 | 11394 | } |
90e4755a | 11395 | |
62b3e311 PB |
11396 | static void |
11397 | do_t_dbg (void) | |
11398 | { | |
11399 | inst.instruction |= inst.operands[0].imm; | |
11400 | } | |
11401 | ||
11402 | static void | |
11403 | do_t_div (void) | |
11404 | { | |
fdfde340 JM |
11405 | unsigned Rd, Rn, Rm; |
11406 | ||
11407 | Rd = inst.operands[0].reg; | |
11408 | Rn = (inst.operands[1].present | |
11409 | ? inst.operands[1].reg : Rd); | |
11410 | Rm = inst.operands[2].reg; | |
11411 | ||
11412 | reject_bad_reg (Rd); | |
11413 | reject_bad_reg (Rn); | |
11414 | reject_bad_reg (Rm); | |
11415 | ||
11416 | inst.instruction |= Rd << 8; | |
11417 | inst.instruction |= Rn << 16; | |
11418 | inst.instruction |= Rm; | |
62b3e311 PB |
11419 | } |
11420 | ||
c19d1205 ZW |
11421 | static void |
11422 | do_t_hint (void) | |
11423 | { | |
11424 | if (unified_syntax && inst.size_req == 4) | |
11425 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11426 | else | |
11427 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11428 | } | |
90e4755a | 11429 | |
c19d1205 ZW |
11430 | static void |
11431 | do_t_it (void) | |
11432 | { | |
11433 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 11434 | |
e07e6e58 NC |
11435 | set_it_insn_type (IT_INSN); |
11436 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
11437 | now_it.cc = cond; | |
5a01bb1d | 11438 | now_it.warn_deprecated = FALSE; |
e27ec89e PB |
11439 | |
11440 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 11441 | if ((cond & 0x1) == 0x0) |
90e4755a | 11442 | { |
c19d1205 | 11443 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 11444 | |
c19d1205 | 11445 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
11446 | { |
11447 | /* No conversion needed. */ | |
11448 | now_it.block_length = 1; | |
11449 | } | |
c19d1205 | 11450 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
11451 | { |
11452 | mask ^= 0x8; | |
11453 | now_it.block_length = 2; | |
11454 | } | |
e27ec89e | 11455 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
11456 | { |
11457 | mask ^= 0xC; | |
11458 | now_it.block_length = 3; | |
11459 | } | |
c19d1205 | 11460 | else |
5a01bb1d MGD |
11461 | { |
11462 | mask ^= 0xE; | |
11463 | now_it.block_length = 4; | |
11464 | } | |
90e4755a | 11465 | |
e27ec89e PB |
11466 | inst.instruction &= 0xfff0; |
11467 | inst.instruction |= mask; | |
c19d1205 | 11468 | } |
90e4755a | 11469 | |
c19d1205 ZW |
11470 | inst.instruction |= cond << 4; |
11471 | } | |
90e4755a | 11472 | |
3c707909 PB |
11473 | /* Helper function used for both push/pop and ldm/stm. */ |
11474 | static void | |
11475 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
11476 | { | |
11477 | bfd_boolean load; | |
11478 | ||
11479 | load = (inst.instruction & (1 << 20)) != 0; | |
11480 | ||
11481 | if (mask & (1 << 13)) | |
11482 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 NC |
11483 | |
11484 | if ((mask & (1 << base)) != 0 | |
11485 | && writeback) | |
11486 | inst.error = _("having the base register in the register list when " | |
11487 | "using write back is UNPREDICTABLE"); | |
11488 | ||
3c707909 PB |
11489 | if (load) |
11490 | { | |
e07e6e58 | 11491 | if (mask & (1 << 15)) |
477330fc RM |
11492 | { |
11493 | if (mask & (1 << 14)) | |
11494 | inst.error = _("LR and PC should not both be in register list"); | |
11495 | else | |
11496 | set_it_insn_type_last (); | |
11497 | } | |
3c707909 PB |
11498 | } |
11499 | else | |
11500 | { | |
11501 | if (mask & (1 << 15)) | |
11502 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
11503 | } |
11504 | ||
11505 | if ((mask & (mask - 1)) == 0) | |
11506 | { | |
11507 | /* Single register transfers implemented as str/ldr. */ | |
11508 | if (writeback) | |
11509 | { | |
11510 | if (inst.instruction & (1 << 23)) | |
11511 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
11512 | else | |
11513 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
11514 | } | |
11515 | else | |
11516 | { | |
11517 | if (inst.instruction & (1 << 23)) | |
11518 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
11519 | else | |
11520 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
11521 | } | |
11522 | ||
11523 | inst.instruction |= 0xf8400000; | |
11524 | if (load) | |
11525 | inst.instruction |= 0x00100000; | |
11526 | ||
5f4273c7 | 11527 | mask = ffs (mask) - 1; |
3c707909 PB |
11528 | mask <<= 12; |
11529 | } | |
11530 | else if (writeback) | |
11531 | inst.instruction |= WRITE_BACK; | |
11532 | ||
11533 | inst.instruction |= mask; | |
11534 | inst.instruction |= base << 16; | |
11535 | } | |
11536 | ||
c19d1205 ZW |
11537 | static void |
11538 | do_t_ldmstm (void) | |
11539 | { | |
11540 | /* This really doesn't seem worth it. */ | |
e2b0ab59 | 11541 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 ZW |
11542 | _("expression too complex")); |
11543 | constraint (inst.operands[1].writeback, | |
11544 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 11545 | |
c19d1205 ZW |
11546 | if (unified_syntax) |
11547 | { | |
3c707909 PB |
11548 | bfd_boolean narrow; |
11549 | unsigned mask; | |
11550 | ||
11551 | narrow = FALSE; | |
c19d1205 ZW |
11552 | /* See if we can use a 16-bit instruction. */ |
11553 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
11554 | && inst.size_req != 4 | |
3c707909 | 11555 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 11556 | { |
3c707909 | 11557 | mask = 1 << inst.operands[0].reg; |
90e4755a | 11558 | |
eab4f823 | 11559 | if (inst.operands[0].reg <= 7) |
90e4755a | 11560 | { |
3c707909 | 11561 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
11562 | ? inst.operands[0].writeback |
11563 | : (inst.operands[0].writeback | |
11564 | == !(inst.operands[1].imm & mask))) | |
477330fc | 11565 | { |
eab4f823 MGD |
11566 | if (inst.instruction == T_MNEM_stmia |
11567 | && (inst.operands[1].imm & mask) | |
11568 | && (inst.operands[1].imm & (mask - 1))) | |
11569 | as_warn (_("value stored for r%d is UNKNOWN"), | |
11570 | inst.operands[0].reg); | |
3c707909 | 11571 | |
eab4f823 MGD |
11572 | inst.instruction = THUMB_OP16 (inst.instruction); |
11573 | inst.instruction |= inst.operands[0].reg << 8; | |
11574 | inst.instruction |= inst.operands[1].imm; | |
11575 | narrow = TRUE; | |
11576 | } | |
11577 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11578 | { | |
11579 | /* This means 1 register in reg list one of 3 situations: | |
11580 | 1. Instruction is stmia, but without writeback. | |
11581 | 2. lmdia without writeback, but with Rn not in | |
477330fc | 11582 | reglist. |
eab4f823 MGD |
11583 | 3. ldmia with writeback, but with Rn in reglist. |
11584 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
11585 | case 1 and 2 which can be converted into a 16-bit | |
11586 | str or ldr. The SP cases are handled below. */ | |
11587 | unsigned long opcode; | |
11588 | /* First, record an error for Case 3. */ | |
11589 | if (inst.operands[1].imm & mask | |
11590 | && inst.operands[0].writeback) | |
fa94de6b | 11591 | inst.error = |
eab4f823 MGD |
11592 | _("having the base register in the register list when " |
11593 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
11594 | |
11595 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
11596 | : T_MNEM_ldr); |
11597 | inst.instruction = THUMB_OP16 (opcode); | |
11598 | inst.instruction |= inst.operands[0].reg << 3; | |
11599 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
11600 | narrow = TRUE; | |
11601 | } | |
90e4755a | 11602 | } |
eab4f823 | 11603 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 11604 | { |
eab4f823 MGD |
11605 | if (inst.operands[0].writeback) |
11606 | { | |
fa94de6b | 11607 | inst.instruction = |
eab4f823 | 11608 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11609 | ? T_MNEM_push : T_MNEM_pop); |
eab4f823 | 11610 | inst.instruction |= inst.operands[1].imm; |
477330fc | 11611 | narrow = TRUE; |
eab4f823 MGD |
11612 | } |
11613 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11614 | { | |
fa94de6b | 11615 | inst.instruction = |
eab4f823 | 11616 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11617 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); |
eab4f823 | 11618 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); |
477330fc | 11619 | narrow = TRUE; |
eab4f823 | 11620 | } |
90e4755a | 11621 | } |
3c707909 PB |
11622 | } |
11623 | ||
11624 | if (!narrow) | |
11625 | { | |
c19d1205 ZW |
11626 | if (inst.instruction < 0xffff) |
11627 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 11628 | |
5f4273c7 NC |
11629 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
11630 | inst.operands[0].writeback); | |
90e4755a RE |
11631 | } |
11632 | } | |
c19d1205 | 11633 | else |
90e4755a | 11634 | { |
c19d1205 ZW |
11635 | constraint (inst.operands[0].reg > 7 |
11636 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
11637 | constraint (inst.instruction != T_MNEM_ldmia |
11638 | && inst.instruction != T_MNEM_stmia, | |
11639 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 11640 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 11641 | { |
c19d1205 ZW |
11642 | if (!inst.operands[0].writeback) |
11643 | as_warn (_("this instruction will write back the base register")); | |
11644 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
11645 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 11646 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 11647 | inst.operands[0].reg); |
f03698e6 | 11648 | } |
c19d1205 | 11649 | else |
90e4755a | 11650 | { |
c19d1205 ZW |
11651 | if (!inst.operands[0].writeback |
11652 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11653 | as_warn (_("this instruction will write back the base register")); | |
11654 | else if (inst.operands[0].writeback | |
11655 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11656 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
11657 | } |
11658 | ||
c19d1205 ZW |
11659 | inst.instruction = THUMB_OP16 (inst.instruction); |
11660 | inst.instruction |= inst.operands[0].reg << 8; | |
11661 | inst.instruction |= inst.operands[1].imm; | |
11662 | } | |
11663 | } | |
e28cd48c | 11664 | |
c19d1205 ZW |
11665 | static void |
11666 | do_t_ldrex (void) | |
11667 | { | |
11668 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
11669 | || inst.operands[1].postind || inst.operands[1].writeback | |
11670 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
11671 | || inst.operands[1].negative, | |
01cfc07f | 11672 | BAD_ADDR_MODE); |
e28cd48c | 11673 | |
5be8be5d DG |
11674 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
11675 | ||
c19d1205 ZW |
11676 | inst.instruction |= inst.operands[0].reg << 12; |
11677 | inst.instruction |= inst.operands[1].reg << 16; | |
e2b0ab59 | 11678 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
c19d1205 | 11679 | } |
e28cd48c | 11680 | |
c19d1205 ZW |
11681 | static void |
11682 | do_t_ldrexd (void) | |
11683 | { | |
11684 | if (!inst.operands[1].present) | |
1cac9012 | 11685 | { |
c19d1205 ZW |
11686 | constraint (inst.operands[0].reg == REG_LR, |
11687 | _("r14 not allowed as first register " | |
11688 | "when second register is omitted")); | |
11689 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 11690 | } |
c19d1205 ZW |
11691 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
11692 | BAD_OVERLAP); | |
b99bd4ef | 11693 | |
c19d1205 ZW |
11694 | inst.instruction |= inst.operands[0].reg << 12; |
11695 | inst.instruction |= inst.operands[1].reg << 8; | |
11696 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
11697 | } |
11698 | ||
11699 | static void | |
c19d1205 | 11700 | do_t_ldst (void) |
b99bd4ef | 11701 | { |
0110f2b8 PB |
11702 | unsigned long opcode; |
11703 | int Rn; | |
11704 | ||
e07e6e58 NC |
11705 | if (inst.operands[0].isreg |
11706 | && !inst.operands[0].preind | |
11707 | && inst.operands[0].reg == REG_PC) | |
11708 | set_it_insn_type_last (); | |
11709 | ||
0110f2b8 | 11710 | opcode = inst.instruction; |
c19d1205 | 11711 | if (unified_syntax) |
b99bd4ef | 11712 | { |
53365c0d PB |
11713 | if (!inst.operands[1].isreg) |
11714 | { | |
11715 | if (opcode <= 0xffff) | |
11716 | inst.instruction = THUMB_OP32 (opcode); | |
8335d6aa | 11717 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
53365c0d PB |
11718 | return; |
11719 | } | |
0110f2b8 PB |
11720 | if (inst.operands[1].isreg |
11721 | && !inst.operands[1].writeback | |
c19d1205 ZW |
11722 | && !inst.operands[1].shifted && !inst.operands[1].postind |
11723 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
11724 | && opcode <= 0xffff |
11725 | && inst.size_req != 4) | |
c19d1205 | 11726 | { |
0110f2b8 PB |
11727 | /* Insn may have a 16-bit form. */ |
11728 | Rn = inst.operands[1].reg; | |
11729 | if (inst.operands[1].immisreg) | |
11730 | { | |
11731 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 11732 | /* [Rn, Rik] */ |
0110f2b8 PB |
11733 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
11734 | goto op16; | |
5be8be5d DG |
11735 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
11736 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
11737 | } |
11738 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
11739 | && opcode != T_MNEM_ldrsb) | |
11740 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
11741 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
11742 | { | |
11743 | /* [Rn, #const] */ | |
11744 | if (Rn > 7) | |
11745 | { | |
11746 | if (Rn == REG_PC) | |
11747 | { | |
e2b0ab59 | 11748 | if (inst.relocs[0].pc_rel) |
0110f2b8 PB |
11749 | opcode = T_MNEM_ldr_pc2; |
11750 | else | |
11751 | opcode = T_MNEM_ldr_pc; | |
11752 | } | |
11753 | else | |
11754 | { | |
11755 | if (opcode == T_MNEM_ldr) | |
11756 | opcode = T_MNEM_ldr_sp; | |
11757 | else | |
11758 | opcode = T_MNEM_str_sp; | |
11759 | } | |
11760 | inst.instruction = inst.operands[0].reg << 8; | |
11761 | } | |
11762 | else | |
11763 | { | |
11764 | inst.instruction = inst.operands[0].reg; | |
11765 | inst.instruction |= inst.operands[1].reg << 3; | |
11766 | } | |
11767 | inst.instruction |= THUMB_OP16 (opcode); | |
11768 | if (inst.size_req == 2) | |
e2b0ab59 | 11769 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
0110f2b8 PB |
11770 | else |
11771 | inst.relax = opcode; | |
11772 | return; | |
11773 | } | |
c19d1205 | 11774 | } |
0110f2b8 | 11775 | /* Definitely a 32-bit variant. */ |
5be8be5d | 11776 | |
8d67f500 NC |
11777 | /* Warning for Erratum 752419. */ |
11778 | if (opcode == T_MNEM_ldr | |
11779 | && inst.operands[0].reg == REG_SP | |
11780 | && inst.operands[1].writeback == 1 | |
11781 | && !inst.operands[1].immisreg) | |
11782 | { | |
11783 | if (no_cpu_selected () | |
11784 | || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7) | |
477330fc RM |
11785 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) |
11786 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
8d67f500 NC |
11787 | as_warn (_("This instruction may be unpredictable " |
11788 | "if executed on M-profile cores " | |
11789 | "with interrupts enabled.")); | |
11790 | } | |
11791 | ||
5be8be5d | 11792 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 11793 | if (inst.operands[1].immisreg) |
5be8be5d DG |
11794 | reject_bad_reg (inst.operands[1].imm); |
11795 | ||
1be5fd2e NC |
11796 | constraint (inst.operands[1].writeback == 1 |
11797 | && inst.operands[0].reg == inst.operands[1].reg, | |
11798 | BAD_OVERLAP); | |
11799 | ||
0110f2b8 | 11800 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
11801 | inst.instruction |= inst.operands[0].reg << 12; |
11802 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
1be5fd2e | 11803 | check_ldr_r15_aligned (); |
b99bd4ef NC |
11804 | return; |
11805 | } | |
11806 | ||
c19d1205 ZW |
11807 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11808 | ||
11809 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 11810 | { |
c19d1205 ZW |
11811 | /* Only [Rn,Rm] is acceptable. */ |
11812 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
11813 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
11814 | || inst.operands[1].postind || inst.operands[1].shifted | |
11815 | || inst.operands[1].negative, | |
11816 | _("Thumb does not support this addressing mode")); | |
11817 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11818 | goto op16; | |
b99bd4ef | 11819 | } |
5f4273c7 | 11820 | |
c19d1205 ZW |
11821 | inst.instruction = THUMB_OP16 (inst.instruction); |
11822 | if (!inst.operands[1].isreg) | |
8335d6aa | 11823 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
c19d1205 | 11824 | return; |
b99bd4ef | 11825 | |
c19d1205 ZW |
11826 | constraint (!inst.operands[1].preind |
11827 | || inst.operands[1].shifted | |
11828 | || inst.operands[1].writeback, | |
11829 | _("Thumb does not support this addressing mode")); | |
11830 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 11831 | { |
c19d1205 ZW |
11832 | constraint (inst.instruction & 0x0600, |
11833 | _("byte or halfword not valid for base register")); | |
11834 | constraint (inst.operands[1].reg == REG_PC | |
11835 | && !(inst.instruction & THUMB_LOAD_BIT), | |
11836 | _("r15 based store not allowed")); | |
11837 | constraint (inst.operands[1].immisreg, | |
11838 | _("invalid base register for register offset")); | |
b99bd4ef | 11839 | |
c19d1205 ZW |
11840 | if (inst.operands[1].reg == REG_PC) |
11841 | inst.instruction = T_OPCODE_LDR_PC; | |
11842 | else if (inst.instruction & THUMB_LOAD_BIT) | |
11843 | inst.instruction = T_OPCODE_LDR_SP; | |
11844 | else | |
11845 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 11846 | |
c19d1205 | 11847 | inst.instruction |= inst.operands[0].reg << 8; |
e2b0ab59 | 11848 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
11849 | return; |
11850 | } | |
90e4755a | 11851 | |
c19d1205 ZW |
11852 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
11853 | if (!inst.operands[1].immisreg) | |
11854 | { | |
11855 | /* Immediate offset. */ | |
11856 | inst.instruction |= inst.operands[0].reg; | |
11857 | inst.instruction |= inst.operands[1].reg << 3; | |
e2b0ab59 | 11858 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET; |
c19d1205 ZW |
11859 | return; |
11860 | } | |
90e4755a | 11861 | |
c19d1205 ZW |
11862 | /* Register offset. */ |
11863 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
11864 | constraint (inst.operands[1].negative, | |
11865 | _("Thumb does not support this addressing mode")); | |
90e4755a | 11866 | |
c19d1205 ZW |
11867 | op16: |
11868 | switch (inst.instruction) | |
11869 | { | |
11870 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
11871 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
11872 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
11873 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
11874 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
11875 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
11876 | case 0x5600 /* ldrsb */: | |
11877 | case 0x5e00 /* ldrsh */: break; | |
11878 | default: abort (); | |
11879 | } | |
90e4755a | 11880 | |
c19d1205 ZW |
11881 | inst.instruction |= inst.operands[0].reg; |
11882 | inst.instruction |= inst.operands[1].reg << 3; | |
11883 | inst.instruction |= inst.operands[1].imm << 6; | |
11884 | } | |
90e4755a | 11885 | |
c19d1205 ZW |
11886 | static void |
11887 | do_t_ldstd (void) | |
11888 | { | |
11889 | if (!inst.operands[1].present) | |
b99bd4ef | 11890 | { |
c19d1205 ZW |
11891 | inst.operands[1].reg = inst.operands[0].reg + 1; |
11892 | constraint (inst.operands[0].reg == REG_LR, | |
11893 | _("r14 not allowed here")); | |
bd340a04 | 11894 | constraint (inst.operands[0].reg == REG_R12, |
477330fc | 11895 | _("r12 not allowed here")); |
b99bd4ef | 11896 | } |
bd340a04 MGD |
11897 | |
11898 | if (inst.operands[2].writeback | |
11899 | && (inst.operands[0].reg == inst.operands[2].reg | |
11900 | || inst.operands[1].reg == inst.operands[2].reg)) | |
11901 | as_warn (_("base register written back, and overlaps " | |
477330fc | 11902 | "one of transfer registers")); |
bd340a04 | 11903 | |
c19d1205 ZW |
11904 | inst.instruction |= inst.operands[0].reg << 12; |
11905 | inst.instruction |= inst.operands[1].reg << 8; | |
11906 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
11907 | } |
11908 | ||
c19d1205 ZW |
11909 | static void |
11910 | do_t_ldstt (void) | |
11911 | { | |
11912 | inst.instruction |= inst.operands[0].reg << 12; | |
11913 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
11914 | } | |
a737bd4d | 11915 | |
b99bd4ef | 11916 | static void |
c19d1205 | 11917 | do_t_mla (void) |
b99bd4ef | 11918 | { |
fdfde340 | 11919 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 11920 | |
fdfde340 JM |
11921 | Rd = inst.operands[0].reg; |
11922 | Rn = inst.operands[1].reg; | |
11923 | Rm = inst.operands[2].reg; | |
11924 | Ra = inst.operands[3].reg; | |
11925 | ||
11926 | reject_bad_reg (Rd); | |
11927 | reject_bad_reg (Rn); | |
11928 | reject_bad_reg (Rm); | |
11929 | reject_bad_reg (Ra); | |
11930 | ||
11931 | inst.instruction |= Rd << 8; | |
11932 | inst.instruction |= Rn << 16; | |
11933 | inst.instruction |= Rm; | |
11934 | inst.instruction |= Ra << 12; | |
c19d1205 | 11935 | } |
b99bd4ef | 11936 | |
c19d1205 ZW |
11937 | static void |
11938 | do_t_mlal (void) | |
11939 | { | |
fdfde340 JM |
11940 | unsigned RdLo, RdHi, Rn, Rm; |
11941 | ||
11942 | RdLo = inst.operands[0].reg; | |
11943 | RdHi = inst.operands[1].reg; | |
11944 | Rn = inst.operands[2].reg; | |
11945 | Rm = inst.operands[3].reg; | |
11946 | ||
11947 | reject_bad_reg (RdLo); | |
11948 | reject_bad_reg (RdHi); | |
11949 | reject_bad_reg (Rn); | |
11950 | reject_bad_reg (Rm); | |
11951 | ||
11952 | inst.instruction |= RdLo << 12; | |
11953 | inst.instruction |= RdHi << 8; | |
11954 | inst.instruction |= Rn << 16; | |
11955 | inst.instruction |= Rm; | |
c19d1205 | 11956 | } |
b99bd4ef | 11957 | |
c19d1205 ZW |
11958 | static void |
11959 | do_t_mov_cmp (void) | |
11960 | { | |
fdfde340 JM |
11961 | unsigned Rn, Rm; |
11962 | ||
11963 | Rn = inst.operands[0].reg; | |
11964 | Rm = inst.operands[1].reg; | |
11965 | ||
e07e6e58 NC |
11966 | if (Rn == REG_PC) |
11967 | set_it_insn_type_last (); | |
11968 | ||
c19d1205 | 11969 | if (unified_syntax) |
b99bd4ef | 11970 | { |
c19d1205 ZW |
11971 | int r0off = (inst.instruction == T_MNEM_mov |
11972 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 11973 | unsigned long opcode; |
3d388997 PB |
11974 | bfd_boolean narrow; |
11975 | bfd_boolean low_regs; | |
11976 | ||
fdfde340 | 11977 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 11978 | opcode = inst.instruction; |
e07e6e58 | 11979 | if (in_it_block ()) |
0110f2b8 | 11980 | narrow = opcode != T_MNEM_movs; |
3d388997 | 11981 | else |
0110f2b8 | 11982 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
11983 | if (inst.size_req == 4 |
11984 | || inst.operands[1].shifted) | |
11985 | narrow = FALSE; | |
11986 | ||
efd81785 PB |
11987 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
11988 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
11989 | && !inst.operands[1].shifted | |
fdfde340 JM |
11990 | && Rn == REG_PC |
11991 | && Rm == REG_LR) | |
efd81785 PB |
11992 | { |
11993 | inst.instruction = T2_SUBS_PC_LR; | |
11994 | return; | |
11995 | } | |
11996 | ||
fdfde340 JM |
11997 | if (opcode == T_MNEM_cmp) |
11998 | { | |
11999 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
12000 | if (narrow) |
12001 | { | |
12002 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
12003 | but valid. */ | |
12004 | warn_deprecated_sp (Rm); | |
12005 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
12006 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
12007 | tools reject R15, so we do too. */ | |
12008 | constraint (Rm == REG_PC, BAD_PC); | |
12009 | } | |
12010 | else | |
12011 | reject_bad_reg (Rm); | |
fdfde340 JM |
12012 | } |
12013 | else if (opcode == T_MNEM_mov | |
12014 | || opcode == T_MNEM_movs) | |
12015 | { | |
12016 | if (inst.operands[1].isreg) | |
12017 | { | |
12018 | if (opcode == T_MNEM_movs) | |
12019 | { | |
12020 | reject_bad_reg (Rn); | |
12021 | reject_bad_reg (Rm); | |
12022 | } | |
76fa04a4 MGD |
12023 | else if (narrow) |
12024 | { | |
12025 | /* This is mov.n. */ | |
12026 | if ((Rn == REG_SP || Rn == REG_PC) | |
12027 | && (Rm == REG_SP || Rm == REG_PC)) | |
12028 | { | |
5c3696f8 | 12029 | as_tsktsk (_("Use of r%u as a source register is " |
76fa04a4 MGD |
12030 | "deprecated when r%u is the destination " |
12031 | "register."), Rm, Rn); | |
12032 | } | |
12033 | } | |
12034 | else | |
12035 | { | |
12036 | /* This is mov.w. */ | |
12037 | constraint (Rn == REG_PC, BAD_PC); | |
12038 | constraint (Rm == REG_PC, BAD_PC); | |
5c8ed6a4 JW |
12039 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
12040 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
76fa04a4 | 12041 | } |
fdfde340 JM |
12042 | } |
12043 | else | |
12044 | reject_bad_reg (Rn); | |
12045 | } | |
12046 | ||
c19d1205 ZW |
12047 | if (!inst.operands[1].isreg) |
12048 | { | |
0110f2b8 | 12049 | /* Immediate operand. */ |
e07e6e58 | 12050 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
12051 | narrow = 0; |
12052 | if (low_regs && narrow) | |
12053 | { | |
12054 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 12055 | inst.instruction |= Rn << 8; |
e2b0ab59 AV |
12056 | if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
12057 | || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
72d98d16 | 12058 | { |
a9f02af8 | 12059 | if (inst.size_req == 2) |
e2b0ab59 | 12060 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
a9f02af8 MG |
12061 | else |
12062 | inst.relax = opcode; | |
72d98d16 | 12063 | } |
0110f2b8 PB |
12064 | } |
12065 | else | |
12066 | { | |
e2b0ab59 AV |
12067 | constraint ((inst.relocs[0].type |
12068 | >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC) | |
12069 | && (inst.relocs[0].type | |
12070 | <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) , | |
a9f02af8 MG |
12071 | THUMB1_RELOC_ONLY); |
12072 | ||
0110f2b8 PB |
12073 | inst.instruction = THUMB_OP32 (inst.instruction); |
12074 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12075 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 12076 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
0110f2b8 | 12077 | } |
c19d1205 | 12078 | } |
728ca7c9 PB |
12079 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
12080 | && (inst.instruction == T_MNEM_mov | |
12081 | || inst.instruction == T_MNEM_movs)) | |
12082 | { | |
12083 | /* Register shifts are encoded as separate shift instructions. */ | |
12084 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
12085 | ||
e07e6e58 | 12086 | if (in_it_block ()) |
728ca7c9 PB |
12087 | narrow = !flags; |
12088 | else | |
12089 | narrow = flags; | |
12090 | ||
12091 | if (inst.size_req == 4) | |
12092 | narrow = FALSE; | |
12093 | ||
12094 | if (!low_regs || inst.operands[1].imm > 7) | |
12095 | narrow = FALSE; | |
12096 | ||
fdfde340 | 12097 | if (Rn != Rm) |
728ca7c9 PB |
12098 | narrow = FALSE; |
12099 | ||
12100 | switch (inst.operands[1].shift_kind) | |
12101 | { | |
12102 | case SHIFT_LSL: | |
12103 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
12104 | break; | |
12105 | case SHIFT_ASR: | |
12106 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
12107 | break; | |
12108 | case SHIFT_LSR: | |
12109 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
12110 | break; | |
12111 | case SHIFT_ROR: | |
12112 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
12113 | break; | |
12114 | default: | |
5f4273c7 | 12115 | abort (); |
728ca7c9 PB |
12116 | } |
12117 | ||
12118 | inst.instruction = opcode; | |
12119 | if (narrow) | |
12120 | { | |
fdfde340 | 12121 | inst.instruction |= Rn; |
728ca7c9 PB |
12122 | inst.instruction |= inst.operands[1].imm << 3; |
12123 | } | |
12124 | else | |
12125 | { | |
12126 | if (flags) | |
12127 | inst.instruction |= CONDS_BIT; | |
12128 | ||
fdfde340 JM |
12129 | inst.instruction |= Rn << 8; |
12130 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
12131 | inst.instruction |= inst.operands[1].imm; |
12132 | } | |
12133 | } | |
3d388997 | 12134 | else if (!narrow) |
c19d1205 | 12135 | { |
728ca7c9 PB |
12136 | /* Some mov with immediate shift have narrow variants. |
12137 | Register shifts are handled above. */ | |
12138 | if (low_regs && inst.operands[1].shifted | |
12139 | && (inst.instruction == T_MNEM_mov | |
12140 | || inst.instruction == T_MNEM_movs)) | |
12141 | { | |
e07e6e58 | 12142 | if (in_it_block ()) |
728ca7c9 PB |
12143 | narrow = (inst.instruction == T_MNEM_mov); |
12144 | else | |
12145 | narrow = (inst.instruction == T_MNEM_movs); | |
12146 | } | |
12147 | ||
12148 | if (narrow) | |
12149 | { | |
12150 | switch (inst.operands[1].shift_kind) | |
12151 | { | |
12152 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
12153 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
12154 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
12155 | default: narrow = FALSE; break; | |
12156 | } | |
12157 | } | |
12158 | ||
12159 | if (narrow) | |
12160 | { | |
fdfde340 JM |
12161 | inst.instruction |= Rn; |
12162 | inst.instruction |= Rm << 3; | |
e2b0ab59 | 12163 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
728ca7c9 PB |
12164 | } |
12165 | else | |
12166 | { | |
12167 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 12168 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
12169 | encode_thumb32_shifted_operand (1); |
12170 | } | |
c19d1205 ZW |
12171 | } |
12172 | else | |
12173 | switch (inst.instruction) | |
12174 | { | |
12175 | case T_MNEM_mov: | |
837b3435 | 12176 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
12177 | results. Don't allow this. */ |
12178 | if (low_regs) | |
12179 | { | |
12180 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6), | |
12181 | "MOV Rd, Rs with two low registers is not " | |
12182 | "permitted on this architecture"); | |
fa94de6b | 12183 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
12184 | arm_ext_v6); |
12185 | } | |
12186 | ||
c19d1205 | 12187 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
12188 | inst.instruction |= (Rn & 0x8) << 4; |
12189 | inst.instruction |= (Rn & 0x7); | |
12190 | inst.instruction |= Rm << 3; | |
c19d1205 | 12191 | break; |
b99bd4ef | 12192 | |
c19d1205 ZW |
12193 | case T_MNEM_movs: |
12194 | /* We know we have low registers at this point. | |
941a8a52 MGD |
12195 | Generate LSLS Rd, Rs, #0. */ |
12196 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
12197 | inst.instruction |= Rn; |
12198 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12199 | break; |
12200 | ||
12201 | case T_MNEM_cmp: | |
3d388997 | 12202 | if (low_regs) |
c19d1205 ZW |
12203 | { |
12204 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
12205 | inst.instruction |= Rn; |
12206 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12207 | } |
12208 | else | |
12209 | { | |
12210 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
12211 | inst.instruction |= (Rn & 0x8) << 4; |
12212 | inst.instruction |= (Rn & 0x7); | |
12213 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12214 | } |
12215 | break; | |
12216 | } | |
b99bd4ef NC |
12217 | return; |
12218 | } | |
12219 | ||
c19d1205 | 12220 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
12221 | |
12222 | /* PR 10443: Do not silently ignore shifted operands. */ | |
12223 | constraint (inst.operands[1].shifted, | |
12224 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
12225 | ||
c19d1205 | 12226 | if (inst.operands[1].isreg) |
b99bd4ef | 12227 | { |
fdfde340 | 12228 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 12229 | { |
c19d1205 ZW |
12230 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
12231 | since a MOV instruction produces unpredictable results. */ | |
12232 | if (inst.instruction == T_OPCODE_MOV_I8) | |
12233 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 12234 | else |
c19d1205 | 12235 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 12236 | |
fdfde340 JM |
12237 | inst.instruction |= Rn; |
12238 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
12239 | } |
12240 | else | |
12241 | { | |
c19d1205 ZW |
12242 | if (inst.instruction == T_OPCODE_MOV_I8) |
12243 | inst.instruction = T_OPCODE_MOV_HR; | |
12244 | else | |
12245 | inst.instruction = T_OPCODE_CMP_HR; | |
12246 | do_t_cpy (); | |
b99bd4ef NC |
12247 | } |
12248 | } | |
c19d1205 | 12249 | else |
b99bd4ef | 12250 | { |
fdfde340 | 12251 | constraint (Rn > 7, |
c19d1205 | 12252 | _("only lo regs allowed with immediate")); |
fdfde340 | 12253 | inst.instruction |= Rn << 8; |
e2b0ab59 | 12254 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM; |
c19d1205 ZW |
12255 | } |
12256 | } | |
b99bd4ef | 12257 | |
c19d1205 ZW |
12258 | static void |
12259 | do_t_mov16 (void) | |
12260 | { | |
fdfde340 | 12261 | unsigned Rd; |
b6895b4f PB |
12262 | bfd_vma imm; |
12263 | bfd_boolean top; | |
12264 | ||
12265 | top = (inst.instruction & 0x00800000) != 0; | |
e2b0ab59 | 12266 | if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW) |
b6895b4f | 12267 | { |
33eaf5de | 12268 | constraint (top, _(":lower16: not allowed in this instruction")); |
e2b0ab59 | 12269 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW; |
b6895b4f | 12270 | } |
e2b0ab59 | 12271 | else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT) |
b6895b4f | 12272 | { |
33eaf5de | 12273 | constraint (!top, _(":upper16: not allowed in this instruction")); |
e2b0ab59 | 12274 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT; |
b6895b4f PB |
12275 | } |
12276 | ||
fdfde340 JM |
12277 | Rd = inst.operands[0].reg; |
12278 | reject_bad_reg (Rd); | |
12279 | ||
12280 | inst.instruction |= Rd << 8; | |
e2b0ab59 | 12281 | if (inst.relocs[0].type == BFD_RELOC_UNUSED) |
b6895b4f | 12282 | { |
e2b0ab59 | 12283 | imm = inst.relocs[0].exp.X_add_number; |
b6895b4f PB |
12284 | inst.instruction |= (imm & 0xf000) << 4; |
12285 | inst.instruction |= (imm & 0x0800) << 15; | |
12286 | inst.instruction |= (imm & 0x0700) << 4; | |
12287 | inst.instruction |= (imm & 0x00ff); | |
12288 | } | |
c19d1205 | 12289 | } |
b99bd4ef | 12290 | |
c19d1205 ZW |
12291 | static void |
12292 | do_t_mvn_tst (void) | |
12293 | { | |
fdfde340 | 12294 | unsigned Rn, Rm; |
c921be7d | 12295 | |
fdfde340 JM |
12296 | Rn = inst.operands[0].reg; |
12297 | Rm = inst.operands[1].reg; | |
12298 | ||
12299 | if (inst.instruction == T_MNEM_cmp | |
12300 | || inst.instruction == T_MNEM_cmn) | |
12301 | constraint (Rn == REG_PC, BAD_PC); | |
12302 | else | |
12303 | reject_bad_reg (Rn); | |
12304 | reject_bad_reg (Rm); | |
12305 | ||
c19d1205 ZW |
12306 | if (unified_syntax) |
12307 | { | |
12308 | int r0off = (inst.instruction == T_MNEM_mvn | |
12309 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
12310 | bfd_boolean narrow; |
12311 | ||
12312 | if (inst.size_req == 4 | |
12313 | || inst.instruction > 0xffff | |
12314 | || inst.operands[1].shifted | |
fdfde340 | 12315 | || Rn > 7 || Rm > 7) |
3d388997 | 12316 | narrow = FALSE; |
fe8b4cc3 KT |
12317 | else if (inst.instruction == T_MNEM_cmn |
12318 | || inst.instruction == T_MNEM_tst) | |
3d388997 PB |
12319 | narrow = TRUE; |
12320 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12321 | narrow = !in_it_block (); |
3d388997 | 12322 | else |
e07e6e58 | 12323 | narrow = in_it_block (); |
3d388997 | 12324 | |
c19d1205 | 12325 | if (!inst.operands[1].isreg) |
b99bd4ef | 12326 | { |
c19d1205 ZW |
12327 | /* For an immediate, we always generate a 32-bit opcode; |
12328 | section relaxation will shrink it later if possible. */ | |
12329 | if (inst.instruction < 0xffff) | |
12330 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12331 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12332 | inst.instruction |= Rn << r0off; |
e2b0ab59 | 12333 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 12334 | } |
c19d1205 | 12335 | else |
b99bd4ef | 12336 | { |
c19d1205 | 12337 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 12338 | if (narrow) |
b99bd4ef | 12339 | { |
c19d1205 | 12340 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12341 | inst.instruction |= Rn; |
12342 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12343 | } |
c19d1205 | 12344 | else |
b99bd4ef | 12345 | { |
c19d1205 ZW |
12346 | constraint (inst.operands[1].shifted |
12347 | && inst.operands[1].immisreg, | |
12348 | _("shift must be constant")); | |
12349 | if (inst.instruction < 0xffff) | |
12350 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 12351 | inst.instruction |= Rn << r0off; |
c19d1205 | 12352 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 12353 | } |
b99bd4ef NC |
12354 | } |
12355 | } | |
12356 | else | |
12357 | { | |
c19d1205 ZW |
12358 | constraint (inst.instruction > 0xffff |
12359 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
12360 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
12361 | _("unshifted register required")); | |
fdfde340 | 12362 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12363 | BAD_HIREG); |
b99bd4ef | 12364 | |
c19d1205 | 12365 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12366 | inst.instruction |= Rn; |
12367 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12368 | } |
b99bd4ef NC |
12369 | } |
12370 | ||
b05fe5cf | 12371 | static void |
c19d1205 | 12372 | do_t_mrs (void) |
b05fe5cf | 12373 | { |
fdfde340 | 12374 | unsigned Rd; |
037e8744 JB |
12375 | |
12376 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
12377 | return; | |
12378 | ||
90ec0d68 MGD |
12379 | Rd = inst.operands[0].reg; |
12380 | reject_bad_reg (Rd); | |
12381 | inst.instruction |= Rd << 8; | |
12382 | ||
12383 | if (inst.operands[1].isreg) | |
62b3e311 | 12384 | { |
90ec0d68 MGD |
12385 | unsigned br = inst.operands[1].reg; |
12386 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
12387 | as_bad (_("bad register for mrs")); | |
12388 | ||
12389 | inst.instruction |= br & (0xf << 16); | |
12390 | inst.instruction |= (br & 0x300) >> 4; | |
12391 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
12392 | } |
12393 | else | |
12394 | { | |
90ec0d68 | 12395 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 12396 | |
d2cd1205 | 12397 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
12398 | { |
12399 | /* PR gas/12698: The constraint is only applied for m_profile. | |
12400 | If the user has specified -march=all, we want to ignore it as | |
12401 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12402 | bfd_boolean m_profile = |
12403 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf NC |
12404 | constraint ((flags != 0) && m_profile, _("selected processor does " |
12405 | "not support requested special purpose register")); | |
12406 | } | |
90ec0d68 | 12407 | else |
d2cd1205 JB |
12408 | /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile |
12409 | devices). */ | |
12410 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
12411 | _("'APSR', 'CPSR' or 'SPSR' expected")); | |
fdfde340 | 12412 | |
90ec0d68 MGD |
12413 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
12414 | inst.instruction |= inst.operands[1].imm & 0xff; | |
12415 | inst.instruction |= 0xf0000; | |
12416 | } | |
c19d1205 | 12417 | } |
b05fe5cf | 12418 | |
c19d1205 ZW |
12419 | static void |
12420 | do_t_msr (void) | |
12421 | { | |
62b3e311 | 12422 | int flags; |
fdfde340 | 12423 | unsigned Rn; |
62b3e311 | 12424 | |
037e8744 JB |
12425 | if (do_vfp_nsyn_msr () == SUCCESS) |
12426 | return; | |
12427 | ||
c19d1205 ZW |
12428 | constraint (!inst.operands[1].isreg, |
12429 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
12430 | |
12431 | if (inst.operands[0].isreg) | |
12432 | flags = (int)(inst.operands[0].reg); | |
12433 | else | |
12434 | flags = inst.operands[0].imm; | |
12435 | ||
d2cd1205 | 12436 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 12437 | { |
d2cd1205 JB |
12438 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
12439 | ||
1a43faaf | 12440 | /* PR gas/12698: The constraint is only applied for m_profile. |
477330fc RM |
12441 | If the user has specified -march=all, we want to ignore it as |
12442 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12443 | bfd_boolean m_profile = |
12444 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf | 12445 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) |
477330fc RM |
12446 | && (bits & ~(PSR_s | PSR_f)) != 0) |
12447 | || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
12448 | && bits != PSR_f)) && m_profile, | |
12449 | _("selected processor does not support requested special " | |
12450 | "purpose register")); | |
62b3e311 PB |
12451 | } |
12452 | else | |
d2cd1205 JB |
12453 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
12454 | "requested special purpose register")); | |
c921be7d | 12455 | |
fdfde340 JM |
12456 | Rn = inst.operands[1].reg; |
12457 | reject_bad_reg (Rn); | |
12458 | ||
62b3e311 | 12459 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
12460 | inst.instruction |= (flags & 0xf0000) >> 8; |
12461 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 12462 | inst.instruction |= (flags & 0xff); |
fdfde340 | 12463 | inst.instruction |= Rn << 16; |
c19d1205 | 12464 | } |
b05fe5cf | 12465 | |
c19d1205 ZW |
12466 | static void |
12467 | do_t_mul (void) | |
12468 | { | |
17828f45 | 12469 | bfd_boolean narrow; |
fdfde340 | 12470 | unsigned Rd, Rn, Rm; |
17828f45 | 12471 | |
c19d1205 ZW |
12472 | if (!inst.operands[2].present) |
12473 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 12474 | |
fdfde340 JM |
12475 | Rd = inst.operands[0].reg; |
12476 | Rn = inst.operands[1].reg; | |
12477 | Rm = inst.operands[2].reg; | |
12478 | ||
17828f45 | 12479 | if (unified_syntax) |
b05fe5cf | 12480 | { |
17828f45 | 12481 | if (inst.size_req == 4 |
fdfde340 JM |
12482 | || (Rd != Rn |
12483 | && Rd != Rm) | |
12484 | || Rn > 7 | |
12485 | || Rm > 7) | |
17828f45 JM |
12486 | narrow = FALSE; |
12487 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 12488 | narrow = !in_it_block (); |
17828f45 | 12489 | else |
e07e6e58 | 12490 | narrow = in_it_block (); |
b05fe5cf | 12491 | } |
c19d1205 | 12492 | else |
b05fe5cf | 12493 | { |
17828f45 | 12494 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 12495 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12496 | BAD_HIREG); |
17828f45 JM |
12497 | narrow = TRUE; |
12498 | } | |
b05fe5cf | 12499 | |
17828f45 JM |
12500 | if (narrow) |
12501 | { | |
12502 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 12503 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 12504 | inst.instruction |= Rd; |
b05fe5cf | 12505 | |
fdfde340 JM |
12506 | if (Rd == Rn) |
12507 | inst.instruction |= Rm << 3; | |
12508 | else if (Rd == Rm) | |
12509 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
12510 | else |
12511 | constraint (1, _("dest must overlap one source register")); | |
12512 | } | |
17828f45 JM |
12513 | else |
12514 | { | |
e07e6e58 NC |
12515 | constraint (inst.instruction != T_MNEM_mul, |
12516 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
12517 | /* 32-bit MUL. */ |
12518 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12519 | inst.instruction |= Rd << 8; |
12520 | inst.instruction |= Rn << 16; | |
12521 | inst.instruction |= Rm << 0; | |
12522 | ||
12523 | reject_bad_reg (Rd); | |
12524 | reject_bad_reg (Rn); | |
12525 | reject_bad_reg (Rm); | |
17828f45 | 12526 | } |
c19d1205 | 12527 | } |
b05fe5cf | 12528 | |
c19d1205 ZW |
12529 | static void |
12530 | do_t_mull (void) | |
12531 | { | |
fdfde340 | 12532 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 12533 | |
fdfde340 JM |
12534 | RdLo = inst.operands[0].reg; |
12535 | RdHi = inst.operands[1].reg; | |
12536 | Rn = inst.operands[2].reg; | |
12537 | Rm = inst.operands[3].reg; | |
12538 | ||
12539 | reject_bad_reg (RdLo); | |
12540 | reject_bad_reg (RdHi); | |
12541 | reject_bad_reg (Rn); | |
12542 | reject_bad_reg (Rm); | |
12543 | ||
12544 | inst.instruction |= RdLo << 12; | |
12545 | inst.instruction |= RdHi << 8; | |
12546 | inst.instruction |= Rn << 16; | |
12547 | inst.instruction |= Rm; | |
12548 | ||
12549 | if (RdLo == RdHi) | |
c19d1205 ZW |
12550 | as_tsktsk (_("rdhi and rdlo must be different")); |
12551 | } | |
b05fe5cf | 12552 | |
c19d1205 ZW |
12553 | static void |
12554 | do_t_nop (void) | |
12555 | { | |
e07e6e58 NC |
12556 | set_it_insn_type (NEUTRAL_IT_INSN); |
12557 | ||
c19d1205 ZW |
12558 | if (unified_syntax) |
12559 | { | |
12560 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 12561 | { |
c19d1205 ZW |
12562 | inst.instruction = THUMB_OP32 (inst.instruction); |
12563 | inst.instruction |= inst.operands[0].imm; | |
12564 | } | |
12565 | else | |
12566 | { | |
bc2d1808 NC |
12567 | /* PR9722: Check for Thumb2 availability before |
12568 | generating a thumb2 nop instruction. */ | |
afa62d5e | 12569 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
12570 | { |
12571 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12572 | inst.instruction |= inst.operands[0].imm << 4; | |
12573 | } | |
12574 | else | |
12575 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
12576 | } |
12577 | } | |
12578 | else | |
12579 | { | |
12580 | constraint (inst.operands[0].present, | |
12581 | _("Thumb does not support NOP with hints")); | |
12582 | inst.instruction = 0x46c0; | |
12583 | } | |
12584 | } | |
b05fe5cf | 12585 | |
c19d1205 ZW |
12586 | static void |
12587 | do_t_neg (void) | |
12588 | { | |
12589 | if (unified_syntax) | |
12590 | { | |
3d388997 PB |
12591 | bfd_boolean narrow; |
12592 | ||
12593 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12594 | narrow = !in_it_block (); |
3d388997 | 12595 | else |
e07e6e58 | 12596 | narrow = in_it_block (); |
3d388997 PB |
12597 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12598 | narrow = FALSE; | |
12599 | if (inst.size_req == 4) | |
12600 | narrow = FALSE; | |
12601 | ||
12602 | if (!narrow) | |
c19d1205 ZW |
12603 | { |
12604 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12605 | inst.instruction |= inst.operands[0].reg << 8; | |
12606 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
12607 | } |
12608 | else | |
12609 | { | |
c19d1205 ZW |
12610 | inst.instruction = THUMB_OP16 (inst.instruction); |
12611 | inst.instruction |= inst.operands[0].reg; | |
12612 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
12613 | } |
12614 | } | |
12615 | else | |
12616 | { | |
c19d1205 ZW |
12617 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
12618 | BAD_HIREG); | |
12619 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
12620 | ||
12621 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12622 | inst.instruction |= inst.operands[0].reg; | |
12623 | inst.instruction |= inst.operands[1].reg << 3; | |
12624 | } | |
12625 | } | |
12626 | ||
1c444d06 JM |
12627 | static void |
12628 | do_t_orn (void) | |
12629 | { | |
12630 | unsigned Rd, Rn; | |
12631 | ||
12632 | Rd = inst.operands[0].reg; | |
12633 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
12634 | ||
fdfde340 JM |
12635 | reject_bad_reg (Rd); |
12636 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
12637 | reject_bad_reg (Rn); | |
12638 | ||
1c444d06 JM |
12639 | inst.instruction |= Rd << 8; |
12640 | inst.instruction |= Rn << 16; | |
12641 | ||
12642 | if (!inst.operands[2].isreg) | |
12643 | { | |
12644 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
e2b0ab59 | 12645 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
1c444d06 JM |
12646 | } |
12647 | else | |
12648 | { | |
12649 | unsigned Rm; | |
12650 | ||
12651 | Rm = inst.operands[2].reg; | |
fdfde340 | 12652 | reject_bad_reg (Rm); |
1c444d06 JM |
12653 | |
12654 | constraint (inst.operands[2].shifted | |
12655 | && inst.operands[2].immisreg, | |
12656 | _("shift must be constant")); | |
12657 | encode_thumb32_shifted_operand (2); | |
12658 | } | |
12659 | } | |
12660 | ||
c19d1205 ZW |
12661 | static void |
12662 | do_t_pkhbt (void) | |
12663 | { | |
fdfde340 JM |
12664 | unsigned Rd, Rn, Rm; |
12665 | ||
12666 | Rd = inst.operands[0].reg; | |
12667 | Rn = inst.operands[1].reg; | |
12668 | Rm = inst.operands[2].reg; | |
12669 | ||
12670 | reject_bad_reg (Rd); | |
12671 | reject_bad_reg (Rn); | |
12672 | reject_bad_reg (Rm); | |
12673 | ||
12674 | inst.instruction |= Rd << 8; | |
12675 | inst.instruction |= Rn << 16; | |
12676 | inst.instruction |= Rm; | |
c19d1205 ZW |
12677 | if (inst.operands[3].present) |
12678 | { | |
e2b0ab59 AV |
12679 | unsigned int val = inst.relocs[0].exp.X_add_number; |
12680 | constraint (inst.relocs[0].exp.X_op != O_constant, | |
c19d1205 ZW |
12681 | _("expression too complex")); |
12682 | inst.instruction |= (val & 0x1c) << 10; | |
12683 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 12684 | } |
c19d1205 | 12685 | } |
b05fe5cf | 12686 | |
c19d1205 ZW |
12687 | static void |
12688 | do_t_pkhtb (void) | |
12689 | { | |
12690 | if (!inst.operands[3].present) | |
1ef52f49 NC |
12691 | { |
12692 | unsigned Rtmp; | |
12693 | ||
12694 | inst.instruction &= ~0x00000020; | |
12695 | ||
12696 | /* PR 10168. Swap the Rm and Rn registers. */ | |
12697 | Rtmp = inst.operands[1].reg; | |
12698 | inst.operands[1].reg = inst.operands[2].reg; | |
12699 | inst.operands[2].reg = Rtmp; | |
12700 | } | |
c19d1205 | 12701 | do_t_pkhbt (); |
b05fe5cf ZW |
12702 | } |
12703 | ||
c19d1205 ZW |
12704 | static void |
12705 | do_t_pld (void) | |
12706 | { | |
fdfde340 JM |
12707 | if (inst.operands[0].immisreg) |
12708 | reject_bad_reg (inst.operands[0].imm); | |
12709 | ||
c19d1205 ZW |
12710 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
12711 | } | |
b05fe5cf | 12712 | |
c19d1205 ZW |
12713 | static void |
12714 | do_t_push_pop (void) | |
b99bd4ef | 12715 | { |
e9f89963 | 12716 | unsigned mask; |
5f4273c7 | 12717 | |
c19d1205 ZW |
12718 | constraint (inst.operands[0].writeback, |
12719 | _("push/pop do not support {reglist}^")); | |
e2b0ab59 | 12720 | constraint (inst.relocs[0].type != BFD_RELOC_UNUSED, |
c19d1205 | 12721 | _("expression too complex")); |
b99bd4ef | 12722 | |
e9f89963 | 12723 | mask = inst.operands[0].imm; |
d3bfe16e | 12724 | if (inst.size_req != 4 && (mask & ~0xff) == 0) |
3c707909 | 12725 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
d3bfe16e | 12726 | else if (inst.size_req != 4 |
c6025a80 | 12727 | && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push |
d3bfe16e | 12728 | ? REG_LR : REG_PC))) |
b99bd4ef | 12729 | { |
c19d1205 ZW |
12730 | inst.instruction = THUMB_OP16 (inst.instruction); |
12731 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 12732 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
12733 | } |
12734 | else if (unified_syntax) | |
12735 | { | |
3c707909 | 12736 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 12737 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
12738 | } |
12739 | else | |
12740 | { | |
12741 | inst.error = _("invalid register list to push/pop instruction"); | |
12742 | return; | |
12743 | } | |
c19d1205 | 12744 | } |
b99bd4ef | 12745 | |
c19d1205 ZW |
12746 | static void |
12747 | do_t_rbit (void) | |
12748 | { | |
fdfde340 JM |
12749 | unsigned Rd, Rm; |
12750 | ||
12751 | Rd = inst.operands[0].reg; | |
12752 | Rm = inst.operands[1].reg; | |
12753 | ||
12754 | reject_bad_reg (Rd); | |
12755 | reject_bad_reg (Rm); | |
12756 | ||
12757 | inst.instruction |= Rd << 8; | |
12758 | inst.instruction |= Rm << 16; | |
12759 | inst.instruction |= Rm; | |
c19d1205 | 12760 | } |
b99bd4ef | 12761 | |
c19d1205 ZW |
12762 | static void |
12763 | do_t_rev (void) | |
12764 | { | |
fdfde340 JM |
12765 | unsigned Rd, Rm; |
12766 | ||
12767 | Rd = inst.operands[0].reg; | |
12768 | Rm = inst.operands[1].reg; | |
12769 | ||
12770 | reject_bad_reg (Rd); | |
12771 | reject_bad_reg (Rm); | |
12772 | ||
12773 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
12774 | && inst.size_req != 4) |
12775 | { | |
12776 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
12777 | inst.instruction |= Rd; |
12778 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12779 | } |
12780 | else if (unified_syntax) | |
12781 | { | |
12782 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12783 | inst.instruction |= Rd << 8; |
12784 | inst.instruction |= Rm << 16; | |
12785 | inst.instruction |= Rm; | |
c19d1205 ZW |
12786 | } |
12787 | else | |
12788 | inst.error = BAD_HIREG; | |
12789 | } | |
b99bd4ef | 12790 | |
1c444d06 JM |
12791 | static void |
12792 | do_t_rrx (void) | |
12793 | { | |
12794 | unsigned Rd, Rm; | |
12795 | ||
12796 | Rd = inst.operands[0].reg; | |
12797 | Rm = inst.operands[1].reg; | |
12798 | ||
fdfde340 JM |
12799 | reject_bad_reg (Rd); |
12800 | reject_bad_reg (Rm); | |
c921be7d | 12801 | |
1c444d06 JM |
12802 | inst.instruction |= Rd << 8; |
12803 | inst.instruction |= Rm; | |
12804 | } | |
12805 | ||
c19d1205 ZW |
12806 | static void |
12807 | do_t_rsb (void) | |
12808 | { | |
fdfde340 | 12809 | unsigned Rd, Rs; |
b99bd4ef | 12810 | |
c19d1205 ZW |
12811 | Rd = inst.operands[0].reg; |
12812 | Rs = (inst.operands[1].present | |
12813 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
12814 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 12815 | |
fdfde340 JM |
12816 | reject_bad_reg (Rd); |
12817 | reject_bad_reg (Rs); | |
12818 | if (inst.operands[2].isreg) | |
12819 | reject_bad_reg (inst.operands[2].reg); | |
12820 | ||
c19d1205 ZW |
12821 | inst.instruction |= Rd << 8; |
12822 | inst.instruction |= Rs << 16; | |
12823 | if (!inst.operands[2].isreg) | |
12824 | { | |
026d3abb PB |
12825 | bfd_boolean narrow; |
12826 | ||
12827 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 12828 | narrow = !in_it_block (); |
026d3abb | 12829 | else |
e07e6e58 | 12830 | narrow = in_it_block (); |
026d3abb PB |
12831 | |
12832 | if (Rd > 7 || Rs > 7) | |
12833 | narrow = FALSE; | |
12834 | ||
12835 | if (inst.size_req == 4 || !unified_syntax) | |
12836 | narrow = FALSE; | |
12837 | ||
e2b0ab59 AV |
12838 | if (inst.relocs[0].exp.X_op != O_constant |
12839 | || inst.relocs[0].exp.X_add_number != 0) | |
026d3abb PB |
12840 | narrow = FALSE; |
12841 | ||
12842 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
477330fc | 12843 | relaxation, but it doesn't seem worth the hassle. */ |
026d3abb PB |
12844 | if (narrow) |
12845 | { | |
e2b0ab59 | 12846 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
026d3abb PB |
12847 | inst.instruction = THUMB_OP16 (T_MNEM_negs); |
12848 | inst.instruction |= Rs << 3; | |
12849 | inst.instruction |= Rd; | |
12850 | } | |
12851 | else | |
12852 | { | |
12853 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
e2b0ab59 | 12854 | inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE; |
026d3abb | 12855 | } |
c19d1205 ZW |
12856 | } |
12857 | else | |
12858 | encode_thumb32_shifted_operand (2); | |
12859 | } | |
b99bd4ef | 12860 | |
c19d1205 ZW |
12861 | static void |
12862 | do_t_setend (void) | |
12863 | { | |
12e37cbc MGD |
12864 | if (warn_on_deprecated |
12865 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 12866 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 12867 | |
e07e6e58 | 12868 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
12869 | if (inst.operands[0].imm) |
12870 | inst.instruction |= 0x8; | |
12871 | } | |
b99bd4ef | 12872 | |
c19d1205 ZW |
12873 | static void |
12874 | do_t_shift (void) | |
12875 | { | |
12876 | if (!inst.operands[1].present) | |
12877 | inst.operands[1].reg = inst.operands[0].reg; | |
12878 | ||
12879 | if (unified_syntax) | |
12880 | { | |
3d388997 PB |
12881 | bfd_boolean narrow; |
12882 | int shift_kind; | |
12883 | ||
12884 | switch (inst.instruction) | |
12885 | { | |
12886 | case T_MNEM_asr: | |
12887 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
12888 | case T_MNEM_lsl: | |
12889 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
12890 | case T_MNEM_lsr: | |
12891 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
12892 | case T_MNEM_ror: | |
12893 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
12894 | default: abort (); | |
12895 | } | |
12896 | ||
12897 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12898 | narrow = !in_it_block (); |
3d388997 | 12899 | else |
e07e6e58 | 12900 | narrow = in_it_block (); |
3d388997 PB |
12901 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12902 | narrow = FALSE; | |
12903 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
12904 | narrow = FALSE; | |
12905 | if (inst.operands[2].isreg | |
12906 | && (inst.operands[1].reg != inst.operands[0].reg | |
12907 | || inst.operands[2].reg > 7)) | |
12908 | narrow = FALSE; | |
12909 | if (inst.size_req == 4) | |
12910 | narrow = FALSE; | |
12911 | ||
fdfde340 JM |
12912 | reject_bad_reg (inst.operands[0].reg); |
12913 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 12914 | |
3d388997 | 12915 | if (!narrow) |
c19d1205 ZW |
12916 | { |
12917 | if (inst.operands[2].isreg) | |
b99bd4ef | 12918 | { |
fdfde340 | 12919 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
12920 | inst.instruction = THUMB_OP32 (inst.instruction); |
12921 | inst.instruction |= inst.operands[0].reg << 8; | |
12922 | inst.instruction |= inst.operands[1].reg << 16; | |
12923 | inst.instruction |= inst.operands[2].reg; | |
94342ec3 NC |
12924 | |
12925 | /* PR 12854: Error on extraneous shifts. */ | |
12926 | constraint (inst.operands[2].shifted, | |
12927 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
12928 | } |
12929 | else | |
12930 | { | |
12931 | inst.operands[1].shifted = 1; | |
3d388997 | 12932 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
12933 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
12934 | ? T_MNEM_movs : T_MNEM_mov); | |
12935 | inst.instruction |= inst.operands[0].reg << 8; | |
12936 | encode_thumb32_shifted_operand (1); | |
12937 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
e2b0ab59 | 12938 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
b99bd4ef NC |
12939 | } |
12940 | } | |
12941 | else | |
12942 | { | |
c19d1205 | 12943 | if (inst.operands[2].isreg) |
b99bd4ef | 12944 | { |
3d388997 | 12945 | switch (shift_kind) |
b99bd4ef | 12946 | { |
3d388997 PB |
12947 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
12948 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
12949 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
12950 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 12951 | default: abort (); |
b99bd4ef | 12952 | } |
5f4273c7 | 12953 | |
c19d1205 ZW |
12954 | inst.instruction |= inst.operands[0].reg; |
12955 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
12956 | |
12957 | /* PR 12854: Error on extraneous shifts. */ | |
12958 | constraint (inst.operands[2].shifted, | |
12959 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
12960 | } |
12961 | else | |
12962 | { | |
3d388997 | 12963 | switch (shift_kind) |
b99bd4ef | 12964 | { |
3d388997 PB |
12965 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
12966 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
12967 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 12968 | default: abort (); |
b99bd4ef | 12969 | } |
e2b0ab59 | 12970 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
12971 | inst.instruction |= inst.operands[0].reg; |
12972 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
12973 | } |
12974 | } | |
c19d1205 ZW |
12975 | } |
12976 | else | |
12977 | { | |
12978 | constraint (inst.operands[0].reg > 7 | |
12979 | || inst.operands[1].reg > 7, BAD_HIREG); | |
12980 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 12981 | |
c19d1205 ZW |
12982 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
12983 | { | |
12984 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
12985 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
12986 | _("source1 and dest must be same register")); | |
b99bd4ef | 12987 | |
c19d1205 ZW |
12988 | switch (inst.instruction) |
12989 | { | |
12990 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
12991 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
12992 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
12993 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
12994 | default: abort (); | |
12995 | } | |
5f4273c7 | 12996 | |
c19d1205 ZW |
12997 | inst.instruction |= inst.operands[0].reg; |
12998 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
12999 | |
13000 | /* PR 12854: Error on extraneous shifts. */ | |
13001 | constraint (inst.operands[2].shifted, | |
13002 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
13003 | } |
13004 | else | |
b99bd4ef | 13005 | { |
c19d1205 ZW |
13006 | switch (inst.instruction) |
13007 | { | |
13008 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
13009 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
13010 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
13011 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
13012 | default: abort (); | |
13013 | } | |
e2b0ab59 | 13014 | inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT; |
c19d1205 ZW |
13015 | inst.instruction |= inst.operands[0].reg; |
13016 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
13017 | } |
13018 | } | |
b99bd4ef NC |
13019 | } |
13020 | ||
13021 | static void | |
c19d1205 | 13022 | do_t_simd (void) |
b99bd4ef | 13023 | { |
fdfde340 JM |
13024 | unsigned Rd, Rn, Rm; |
13025 | ||
13026 | Rd = inst.operands[0].reg; | |
13027 | Rn = inst.operands[1].reg; | |
13028 | Rm = inst.operands[2].reg; | |
13029 | ||
13030 | reject_bad_reg (Rd); | |
13031 | reject_bad_reg (Rn); | |
13032 | reject_bad_reg (Rm); | |
13033 | ||
13034 | inst.instruction |= Rd << 8; | |
13035 | inst.instruction |= Rn << 16; | |
13036 | inst.instruction |= Rm; | |
c19d1205 | 13037 | } |
b99bd4ef | 13038 | |
03ee1b7f NC |
13039 | static void |
13040 | do_t_simd2 (void) | |
13041 | { | |
13042 | unsigned Rd, Rn, Rm; | |
13043 | ||
13044 | Rd = inst.operands[0].reg; | |
13045 | Rm = inst.operands[1].reg; | |
13046 | Rn = inst.operands[2].reg; | |
13047 | ||
13048 | reject_bad_reg (Rd); | |
13049 | reject_bad_reg (Rn); | |
13050 | reject_bad_reg (Rm); | |
13051 | ||
13052 | inst.instruction |= Rd << 8; | |
13053 | inst.instruction |= Rn << 16; | |
13054 | inst.instruction |= Rm; | |
13055 | } | |
13056 | ||
c19d1205 | 13057 | static void |
3eb17e6b | 13058 | do_t_smc (void) |
c19d1205 | 13059 | { |
e2b0ab59 | 13060 | unsigned int value = inst.relocs[0].exp.X_add_number; |
f4c65163 MGD |
13061 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
13062 | _("SMC is not permitted on this architecture")); | |
e2b0ab59 | 13063 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 13064 | _("expression too complex")); |
e2b0ab59 | 13065 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
c19d1205 ZW |
13066 | inst.instruction |= (value & 0xf000) >> 12; |
13067 | inst.instruction |= (value & 0x0ff0); | |
13068 | inst.instruction |= (value & 0x000f) << 16; | |
24382199 NC |
13069 | /* PR gas/15623: SMC instructions must be last in an IT block. */ |
13070 | set_it_insn_type_last (); | |
c19d1205 | 13071 | } |
b99bd4ef | 13072 | |
90ec0d68 MGD |
13073 | static void |
13074 | do_t_hvc (void) | |
13075 | { | |
e2b0ab59 | 13076 | unsigned int value = inst.relocs[0].exp.X_add_number; |
90ec0d68 | 13077 | |
e2b0ab59 | 13078 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
90ec0d68 MGD |
13079 | inst.instruction |= (value & 0x0fff); |
13080 | inst.instruction |= (value & 0xf000) << 4; | |
13081 | } | |
13082 | ||
c19d1205 | 13083 | static void |
3a21c15a | 13084 | do_t_ssat_usat (int bias) |
c19d1205 | 13085 | { |
fdfde340 JM |
13086 | unsigned Rd, Rn; |
13087 | ||
13088 | Rd = inst.operands[0].reg; | |
13089 | Rn = inst.operands[2].reg; | |
13090 | ||
13091 | reject_bad_reg (Rd); | |
13092 | reject_bad_reg (Rn); | |
13093 | ||
13094 | inst.instruction |= Rd << 8; | |
3a21c15a | 13095 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 13096 | inst.instruction |= Rn << 16; |
b99bd4ef | 13097 | |
c19d1205 | 13098 | if (inst.operands[3].present) |
b99bd4ef | 13099 | { |
e2b0ab59 | 13100 | offsetT shift_amount = inst.relocs[0].exp.X_add_number; |
3a21c15a | 13101 | |
e2b0ab59 | 13102 | inst.relocs[0].type = BFD_RELOC_UNUSED; |
3a21c15a | 13103 | |
e2b0ab59 | 13104 | constraint (inst.relocs[0].exp.X_op != O_constant, |
c19d1205 | 13105 | _("expression too complex")); |
b99bd4ef | 13106 | |
3a21c15a | 13107 | if (shift_amount != 0) |
6189168b | 13108 | { |
3a21c15a NC |
13109 | constraint (shift_amount > 31, |
13110 | _("shift expression is too large")); | |
13111 | ||
c19d1205 | 13112 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
13113 | inst.instruction |= 0x00200000; /* sh bit. */ |
13114 | ||
13115 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
13116 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
13117 | } |
13118 | } | |
b99bd4ef | 13119 | } |
c921be7d | 13120 | |
3a21c15a NC |
13121 | static void |
13122 | do_t_ssat (void) | |
13123 | { | |
13124 | do_t_ssat_usat (1); | |
13125 | } | |
b99bd4ef | 13126 | |
0dd132b6 | 13127 | static void |
c19d1205 | 13128 | do_t_ssat16 (void) |
0dd132b6 | 13129 | { |
fdfde340 JM |
13130 | unsigned Rd, Rn; |
13131 | ||
13132 | Rd = inst.operands[0].reg; | |
13133 | Rn = inst.operands[2].reg; | |
13134 | ||
13135 | reject_bad_reg (Rd); | |
13136 | reject_bad_reg (Rn); | |
13137 | ||
13138 | inst.instruction |= Rd << 8; | |
c19d1205 | 13139 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 13140 | inst.instruction |= Rn << 16; |
c19d1205 | 13141 | } |
0dd132b6 | 13142 | |
c19d1205 ZW |
13143 | static void |
13144 | do_t_strex (void) | |
13145 | { | |
13146 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
13147 | || inst.operands[2].postind || inst.operands[2].writeback | |
13148 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
13149 | || inst.operands[2].negative, | |
01cfc07f | 13150 | BAD_ADDR_MODE); |
0dd132b6 | 13151 | |
5be8be5d DG |
13152 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
13153 | ||
c19d1205 ZW |
13154 | inst.instruction |= inst.operands[0].reg << 8; |
13155 | inst.instruction |= inst.operands[1].reg << 12; | |
13156 | inst.instruction |= inst.operands[2].reg << 16; | |
e2b0ab59 | 13157 | inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8; |
0dd132b6 NC |
13158 | } |
13159 | ||
b99bd4ef | 13160 | static void |
c19d1205 | 13161 | do_t_strexd (void) |
b99bd4ef | 13162 | { |
c19d1205 ZW |
13163 | if (!inst.operands[2].present) |
13164 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 13165 | |
c19d1205 ZW |
13166 | constraint (inst.operands[0].reg == inst.operands[1].reg |
13167 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 13168 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 13169 | BAD_OVERLAP); |
b99bd4ef | 13170 | |
c19d1205 ZW |
13171 | inst.instruction |= inst.operands[0].reg; |
13172 | inst.instruction |= inst.operands[1].reg << 12; | |
13173 | inst.instruction |= inst.operands[2].reg << 8; | |
13174 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
13175 | } |
13176 | ||
13177 | static void | |
c19d1205 | 13178 | do_t_sxtah (void) |
b99bd4ef | 13179 | { |
fdfde340 JM |
13180 | unsigned Rd, Rn, Rm; |
13181 | ||
13182 | Rd = inst.operands[0].reg; | |
13183 | Rn = inst.operands[1].reg; | |
13184 | Rm = inst.operands[2].reg; | |
13185 | ||
13186 | reject_bad_reg (Rd); | |
13187 | reject_bad_reg (Rn); | |
13188 | reject_bad_reg (Rm); | |
13189 | ||
13190 | inst.instruction |= Rd << 8; | |
13191 | inst.instruction |= Rn << 16; | |
13192 | inst.instruction |= Rm; | |
c19d1205 ZW |
13193 | inst.instruction |= inst.operands[3].imm << 4; |
13194 | } | |
b99bd4ef | 13195 | |
c19d1205 ZW |
13196 | static void |
13197 | do_t_sxth (void) | |
13198 | { | |
fdfde340 JM |
13199 | unsigned Rd, Rm; |
13200 | ||
13201 | Rd = inst.operands[0].reg; | |
13202 | Rm = inst.operands[1].reg; | |
13203 | ||
13204 | reject_bad_reg (Rd); | |
13205 | reject_bad_reg (Rm); | |
c921be7d NC |
13206 | |
13207 | if (inst.instruction <= 0xffff | |
13208 | && inst.size_req != 4 | |
fdfde340 | 13209 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 13210 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 13211 | { |
c19d1205 | 13212 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13213 | inst.instruction |= Rd; |
13214 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13215 | } |
c19d1205 | 13216 | else if (unified_syntax) |
b99bd4ef | 13217 | { |
c19d1205 ZW |
13218 | if (inst.instruction <= 0xffff) |
13219 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
13220 | inst.instruction |= Rd << 8; |
13221 | inst.instruction |= Rm; | |
c19d1205 | 13222 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 13223 | } |
c19d1205 | 13224 | else |
b99bd4ef | 13225 | { |
c19d1205 ZW |
13226 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
13227 | _("Thumb encoding does not support rotation")); | |
13228 | constraint (1, BAD_HIREG); | |
b99bd4ef | 13229 | } |
c19d1205 | 13230 | } |
b99bd4ef | 13231 | |
c19d1205 ZW |
13232 | static void |
13233 | do_t_swi (void) | |
13234 | { | |
e2b0ab59 | 13235 | inst.relocs[0].type = BFD_RELOC_ARM_SWI; |
c19d1205 | 13236 | } |
b99bd4ef | 13237 | |
92e90b6e PB |
13238 | static void |
13239 | do_t_tb (void) | |
13240 | { | |
fdfde340 | 13241 | unsigned Rn, Rm; |
92e90b6e PB |
13242 | int half; |
13243 | ||
13244 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 13245 | set_it_insn_type_last (); |
dfa9f0d5 PB |
13246 | constraint (inst.operands[0].immisreg, |
13247 | _("instruction requires register index")); | |
fdfde340 JM |
13248 | |
13249 | Rn = inst.operands[0].reg; | |
13250 | Rm = inst.operands[0].imm; | |
c921be7d | 13251 | |
5c8ed6a4 JW |
13252 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) |
13253 | constraint (Rn == REG_SP, BAD_SP); | |
fdfde340 JM |
13254 | reject_bad_reg (Rm); |
13255 | ||
92e90b6e PB |
13256 | constraint (!half && inst.operands[0].shifted, |
13257 | _("instruction does not allow shifted index")); | |
fdfde340 | 13258 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
13259 | } |
13260 | ||
74db7efb NC |
13261 | static void |
13262 | do_t_udf (void) | |
13263 | { | |
13264 | if (!inst.operands[0].present) | |
13265 | inst.operands[0].imm = 0; | |
13266 | ||
13267 | if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4) | |
13268 | { | |
13269 | constraint (inst.size_req == 2, | |
13270 | _("immediate value out of range")); | |
13271 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13272 | inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4; | |
13273 | inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0; | |
13274 | } | |
13275 | else | |
13276 | { | |
13277 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13278 | inst.instruction |= inst.operands[0].imm; | |
13279 | } | |
13280 | ||
13281 | set_it_insn_type (NEUTRAL_IT_INSN); | |
13282 | } | |
13283 | ||
13284 | ||
c19d1205 ZW |
13285 | static void |
13286 | do_t_usat (void) | |
13287 | { | |
3a21c15a | 13288 | do_t_ssat_usat (0); |
b99bd4ef NC |
13289 | } |
13290 | ||
13291 | static void | |
c19d1205 | 13292 | do_t_usat16 (void) |
b99bd4ef | 13293 | { |
fdfde340 JM |
13294 | unsigned Rd, Rn; |
13295 | ||
13296 | Rd = inst.operands[0].reg; | |
13297 | Rn = inst.operands[2].reg; | |
13298 | ||
13299 | reject_bad_reg (Rd); | |
13300 | reject_bad_reg (Rn); | |
13301 | ||
13302 | inst.instruction |= Rd << 8; | |
c19d1205 | 13303 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 13304 | inst.instruction |= Rn << 16; |
b99bd4ef | 13305 | } |
c19d1205 | 13306 | |
e12437dc AV |
13307 | /* Checking the range of the branch offset (VAL) with NBITS bits |
13308 | and IS_SIGNED signedness. Also checks the LSB to be 0. */ | |
13309 | static int | |
13310 | v8_1_branch_value_check (int val, int nbits, int is_signed) | |
13311 | { | |
13312 | gas_assert (nbits > 0 && nbits <= 32); | |
13313 | if (is_signed) | |
13314 | { | |
13315 | int cmp = (1 << (nbits - 1)); | |
13316 | if ((val < -cmp) || (val >= cmp) || (val & 0x01)) | |
13317 | return FAIL; | |
13318 | } | |
13319 | else | |
13320 | { | |
13321 | if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1)) | |
13322 | return FAIL; | |
13323 | } | |
13324 | return SUCCESS; | |
13325 | } | |
13326 | ||
4389b29a AV |
13327 | /* For branches in Armv8.1-M Mainline. */ |
13328 | static void | |
13329 | do_t_branch_future (void) | |
13330 | { | |
13331 | unsigned long insn = inst.instruction; | |
13332 | ||
13333 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13334 | if (inst.operands[0].hasreloc == 0) | |
13335 | { | |
13336 | if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL) | |
13337 | as_bad (BAD_BRANCH_OFF); | |
13338 | ||
13339 | inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23; | |
13340 | } | |
13341 | else | |
13342 | { | |
13343 | inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5; | |
13344 | inst.relocs[0].pc_rel = 1; | |
13345 | } | |
13346 | ||
13347 | switch (insn) | |
13348 | { | |
13349 | case T_MNEM_bf: | |
13350 | if (inst.operands[1].hasreloc == 0) | |
13351 | { | |
13352 | int val = inst.operands[1].imm; | |
13353 | if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL) | |
13354 | as_bad (BAD_BRANCH_OFF); | |
13355 | ||
13356 | int immA = (val & 0x0001f000) >> 12; | |
13357 | int immB = (val & 0x00000ffc) >> 2; | |
13358 | int immC = (val & 0x00000002) >> 1; | |
13359 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
13360 | } | |
13361 | else | |
13362 | { | |
13363 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17; | |
13364 | inst.relocs[1].pc_rel = 1; | |
13365 | } | |
13366 | break; | |
13367 | ||
65d1bc05 AV |
13368 | case T_MNEM_bfl: |
13369 | if (inst.operands[1].hasreloc == 0) | |
13370 | { | |
13371 | int val = inst.operands[1].imm; | |
13372 | if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL) | |
13373 | as_bad (BAD_BRANCH_OFF); | |
13374 | ||
13375 | int immA = (val & 0x0007f000) >> 12; | |
13376 | int immB = (val & 0x00000ffc) >> 2; | |
13377 | int immC = (val & 0x00000002) >> 1; | |
13378 | inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11); | |
13379 | } | |
13380 | else | |
13381 | { | |
13382 | inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19; | |
13383 | inst.relocs[1].pc_rel = 1; | |
13384 | } | |
13385 | break; | |
13386 | ||
f1c7f421 AV |
13387 | case T_MNEM_bfx: |
13388 | case T_MNEM_bflx: | |
13389 | inst.instruction |= inst.operands[1].reg << 16; | |
13390 | break; | |
13391 | ||
4389b29a AV |
13392 | default: abort (); |
13393 | } | |
13394 | } | |
13395 | ||
5287ad62 | 13396 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 13397 | |
5287ad62 | 13398 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 13399 | |
5287ad62 JB |
13400 | /* An "invalid" code for the following tables. */ |
13401 | #define N_INV -1u | |
13402 | ||
13403 | struct neon_tab_entry | |
b99bd4ef | 13404 | { |
5287ad62 JB |
13405 | unsigned integer; |
13406 | unsigned float_or_poly; | |
13407 | unsigned scalar_or_imm; | |
13408 | }; | |
5f4273c7 | 13409 | |
5287ad62 JB |
13410 | /* Map overloaded Neon opcodes to their respective encodings. */ |
13411 | #define NEON_ENC_TAB \ | |
13412 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
13413 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
13414 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
13415 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
13416 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
13417 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
13418 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
13419 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
13420 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
13421 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
13422 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
13423 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 13424 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
13425 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
13426 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
13427 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
13428 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
13429 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
13430 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
13431 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
13432 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
13433 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
13434 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
13435 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
13436 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
13437 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
13438 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
13439 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
d6b4b13e MW |
13440 | X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \ |
13441 | X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \ | |
5287ad62 JB |
13442 | X(vshl, 0x0000400, N_INV, 0x0800510), \ |
13443 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
13444 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
13445 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
13446 | X(veor, 0x1000110, N_INV, N_INV), \ | |
13447 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
13448 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
13449 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
13450 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
13451 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
13452 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
13453 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
13454 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
13455 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
13456 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
13457 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
13458 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
13459 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
13460 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
13461 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
13462 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
13463 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
13464 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
13465 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
13466 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
13467 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
13468 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
13469 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
13470 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
13471 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
13472 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
13473 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \ |
13474 | X(vseleq, 0xe000a00, N_INV, N_INV), \ | |
13475 | X(vselvs, 0xe100a00, N_INV, N_INV), \ | |
13476 | X(vselge, 0xe200a00, N_INV, N_INV), \ | |
73924fbc MGD |
13477 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
13478 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 13479 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
13480 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
13481 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 13482 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 13483 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
13484 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
13485 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
13486 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
13487 | |
13488 | enum neon_opc | |
13489 | { | |
13490 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
13491 | NEON_ENC_TAB | |
13492 | #undef X | |
13493 | }; | |
b99bd4ef | 13494 | |
5287ad62 JB |
13495 | static const struct neon_tab_entry neon_enc_tab[] = |
13496 | { | |
13497 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
13498 | NEON_ENC_TAB | |
13499 | #undef X | |
13500 | }; | |
b99bd4ef | 13501 | |
88714cb8 DG |
13502 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
13503 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13504 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13505 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13506 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13507 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13508 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13509 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13510 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13511 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13512 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 13513 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 13514 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 13515 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
13516 | #define NEON_ENC_FPV8_(X) \ |
13517 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 13518 | |
88714cb8 DG |
13519 | #define NEON_ENCODE(type, inst) \ |
13520 | do \ | |
13521 | { \ | |
13522 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
13523 | inst.is_neon = 1; \ | |
13524 | } \ | |
13525 | while (0) | |
13526 | ||
13527 | #define check_neon_suffixes \ | |
13528 | do \ | |
13529 | { \ | |
13530 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
13531 | { \ | |
13532 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
13533 | return; \ | |
13534 | } \ | |
13535 | } \ | |
13536 | while (0) | |
13537 | ||
037e8744 JB |
13538 | /* Define shapes for instruction operands. The following mnemonic characters |
13539 | are used in this table: | |
5287ad62 | 13540 | |
037e8744 | 13541 | F - VFP S<n> register |
5287ad62 JB |
13542 | D - Neon D<n> register |
13543 | Q - Neon Q<n> register | |
13544 | I - Immediate | |
13545 | S - Scalar | |
13546 | R - ARM register | |
13547 | L - D<n> register list | |
5f4273c7 | 13548 | |
037e8744 JB |
13549 | This table is used to generate various data: |
13550 | - enumerations of the form NS_DDR to be used as arguments to | |
13551 | neon_select_shape. | |
13552 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 13553 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 13554 | |
037e8744 JB |
13555 | #define NEON_SHAPE_DEF \ |
13556 | X(3, (D, D, D), DOUBLE), \ | |
13557 | X(3, (Q, Q, Q), QUAD), \ | |
13558 | X(3, (D, D, I), DOUBLE), \ | |
13559 | X(3, (Q, Q, I), QUAD), \ | |
13560 | X(3, (D, D, S), DOUBLE), \ | |
13561 | X(3, (Q, Q, S), QUAD), \ | |
13562 | X(2, (D, D), DOUBLE), \ | |
13563 | X(2, (Q, Q), QUAD), \ | |
13564 | X(2, (D, S), DOUBLE), \ | |
13565 | X(2, (Q, S), QUAD), \ | |
13566 | X(2, (D, R), DOUBLE), \ | |
13567 | X(2, (Q, R), QUAD), \ | |
13568 | X(2, (D, I), DOUBLE), \ | |
13569 | X(2, (Q, I), QUAD), \ | |
13570 | X(3, (D, L, D), DOUBLE), \ | |
13571 | X(2, (D, Q), MIXED), \ | |
13572 | X(2, (Q, D), MIXED), \ | |
13573 | X(3, (D, Q, I), MIXED), \ | |
13574 | X(3, (Q, D, I), MIXED), \ | |
13575 | X(3, (Q, D, D), MIXED), \ | |
13576 | X(3, (D, Q, Q), MIXED), \ | |
13577 | X(3, (Q, Q, D), MIXED), \ | |
13578 | X(3, (Q, D, S), MIXED), \ | |
13579 | X(3, (D, Q, S), MIXED), \ | |
13580 | X(4, (D, D, D, I), DOUBLE), \ | |
13581 | X(4, (Q, Q, Q, I), QUAD), \ | |
c28eeff2 SN |
13582 | X(4, (D, D, S, I), DOUBLE), \ |
13583 | X(4, (Q, Q, S, I), QUAD), \ | |
037e8744 JB |
13584 | X(2, (F, F), SINGLE), \ |
13585 | X(3, (F, F, F), SINGLE), \ | |
13586 | X(2, (F, I), SINGLE), \ | |
13587 | X(2, (F, D), MIXED), \ | |
13588 | X(2, (D, F), MIXED), \ | |
13589 | X(3, (F, F, I), MIXED), \ | |
13590 | X(4, (R, R, F, F), SINGLE), \ | |
13591 | X(4, (F, F, R, R), SINGLE), \ | |
13592 | X(3, (D, R, R), DOUBLE), \ | |
13593 | X(3, (R, R, D), DOUBLE), \ | |
13594 | X(2, (S, R), SINGLE), \ | |
13595 | X(2, (R, S), SINGLE), \ | |
13596 | X(2, (F, R), SINGLE), \ | |
d54af2d0 RL |
13597 | X(2, (R, F), SINGLE), \ |
13598 | /* Half float shape supported so far. */\ | |
13599 | X (2, (H, D), MIXED), \ | |
13600 | X (2, (D, H), MIXED), \ | |
13601 | X (2, (H, F), MIXED), \ | |
13602 | X (2, (F, H), MIXED), \ | |
13603 | X (2, (H, H), HALF), \ | |
13604 | X (2, (H, R), HALF), \ | |
13605 | X (2, (R, H), HALF), \ | |
13606 | X (2, (H, I), HALF), \ | |
13607 | X (3, (H, H, H), HALF), \ | |
13608 | X (3, (H, F, I), MIXED), \ | |
dec41383 JW |
13609 | X (3, (F, H, I), MIXED), \ |
13610 | X (3, (D, H, H), MIXED), \ | |
13611 | X (3, (D, H, S), MIXED) | |
037e8744 JB |
13612 | |
13613 | #define S2(A,B) NS_##A##B | |
13614 | #define S3(A,B,C) NS_##A##B##C | |
13615 | #define S4(A,B,C,D) NS_##A##B##C##D | |
13616 | ||
13617 | #define X(N, L, C) S##N L | |
13618 | ||
5287ad62 JB |
13619 | enum neon_shape |
13620 | { | |
037e8744 JB |
13621 | NEON_SHAPE_DEF, |
13622 | NS_NULL | |
5287ad62 | 13623 | }; |
b99bd4ef | 13624 | |
037e8744 JB |
13625 | #undef X |
13626 | #undef S2 | |
13627 | #undef S3 | |
13628 | #undef S4 | |
13629 | ||
13630 | enum neon_shape_class | |
13631 | { | |
d54af2d0 | 13632 | SC_HALF, |
037e8744 JB |
13633 | SC_SINGLE, |
13634 | SC_DOUBLE, | |
13635 | SC_QUAD, | |
13636 | SC_MIXED | |
13637 | }; | |
13638 | ||
13639 | #define X(N, L, C) SC_##C | |
13640 | ||
13641 | static enum neon_shape_class neon_shape_class[] = | |
13642 | { | |
13643 | NEON_SHAPE_DEF | |
13644 | }; | |
13645 | ||
13646 | #undef X | |
13647 | ||
13648 | enum neon_shape_el | |
13649 | { | |
d54af2d0 | 13650 | SE_H, |
037e8744 JB |
13651 | SE_F, |
13652 | SE_D, | |
13653 | SE_Q, | |
13654 | SE_I, | |
13655 | SE_S, | |
13656 | SE_R, | |
13657 | SE_L | |
13658 | }; | |
13659 | ||
13660 | /* Register widths of above. */ | |
13661 | static unsigned neon_shape_el_size[] = | |
13662 | { | |
d54af2d0 | 13663 | 16, |
037e8744 JB |
13664 | 32, |
13665 | 64, | |
13666 | 128, | |
13667 | 0, | |
13668 | 32, | |
13669 | 32, | |
13670 | 0 | |
13671 | }; | |
13672 | ||
13673 | struct neon_shape_info | |
13674 | { | |
13675 | unsigned els; | |
13676 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
13677 | }; | |
13678 | ||
13679 | #define S2(A,B) { SE_##A, SE_##B } | |
13680 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
13681 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
13682 | ||
13683 | #define X(N, L, C) { N, S##N L } | |
13684 | ||
13685 | static struct neon_shape_info neon_shape_tab[] = | |
13686 | { | |
13687 | NEON_SHAPE_DEF | |
13688 | }; | |
13689 | ||
13690 | #undef X | |
13691 | #undef S2 | |
13692 | #undef S3 | |
13693 | #undef S4 | |
13694 | ||
5287ad62 JB |
13695 | /* Bit masks used in type checking given instructions. |
13696 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
13697 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
13698 | set, various other bits can be set as well in order to modify the meaning of | |
13699 | the type constraint. */ | |
13700 | ||
13701 | enum neon_type_mask | |
13702 | { | |
8e79c3df CM |
13703 | N_S8 = 0x0000001, |
13704 | N_S16 = 0x0000002, | |
13705 | N_S32 = 0x0000004, | |
13706 | N_S64 = 0x0000008, | |
13707 | N_U8 = 0x0000010, | |
13708 | N_U16 = 0x0000020, | |
13709 | N_U32 = 0x0000040, | |
13710 | N_U64 = 0x0000080, | |
13711 | N_I8 = 0x0000100, | |
13712 | N_I16 = 0x0000200, | |
13713 | N_I32 = 0x0000400, | |
13714 | N_I64 = 0x0000800, | |
13715 | N_8 = 0x0001000, | |
13716 | N_16 = 0x0002000, | |
13717 | N_32 = 0x0004000, | |
13718 | N_64 = 0x0008000, | |
13719 | N_P8 = 0x0010000, | |
13720 | N_P16 = 0x0020000, | |
13721 | N_F16 = 0x0040000, | |
13722 | N_F32 = 0x0080000, | |
13723 | N_F64 = 0x0100000, | |
4f51b4bd | 13724 | N_P64 = 0x0200000, |
c921be7d NC |
13725 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
13726 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 13727 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 13728 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
13729 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
13730 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
13731 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
13732 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
13733 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
13734 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
13735 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 13736 | N_UTYP = 0, |
4f51b4bd | 13737 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
13738 | }; |
13739 | ||
dcbf9037 JB |
13740 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
13741 | ||
5287ad62 JB |
13742 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
13743 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
13744 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
cc933301 JW |
13745 | #define N_S_32 (N_S8 | N_S16 | N_S32) |
13746 | #define N_F_16_32 (N_F16 | N_F32) | |
13747 | #define N_SUF_32 (N_SU_32 | N_F_16_32) | |
5287ad62 | 13748 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) |
cc933301 | 13749 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32) |
d54af2d0 | 13750 | #define N_F_ALL (N_F16 | N_F32 | N_F64) |
5287ad62 JB |
13751 | |
13752 | /* Pass this as the first type argument to neon_check_type to ignore types | |
13753 | altogether. */ | |
13754 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
13755 | ||
037e8744 JB |
13756 | /* Select a "shape" for the current instruction (describing register types or |
13757 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
13758 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
13759 | function of operand parsing, so this function doesn't need to be called. | |
13760 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
13761 | |
13762 | static enum neon_shape | |
037e8744 | 13763 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 13764 | { |
037e8744 JB |
13765 | va_list ap; |
13766 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
13767 | |
13768 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
13769 | many arguments we should have, so this makes the assumption that we have | |
13770 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
13771 | true in the future. */ | |
13772 | if (!inst.operands[1].present) | |
13773 | inst.operands[1] = inst.operands[0]; | |
13774 | ||
037e8744 | 13775 | va_start (ap, shape); |
5f4273c7 | 13776 | |
21d799b5 | 13777 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
13778 | { |
13779 | unsigned j; | |
13780 | int matches = 1; | |
13781 | ||
13782 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
477330fc RM |
13783 | { |
13784 | if (!inst.operands[j].present) | |
13785 | { | |
13786 | matches = 0; | |
13787 | break; | |
13788 | } | |
13789 | ||
13790 | switch (neon_shape_tab[shape].el[j]) | |
13791 | { | |
d54af2d0 RL |
13792 | /* If a .f16, .16, .u16, .s16 type specifier is given over |
13793 | a VFP single precision register operand, it's essentially | |
13794 | means only half of the register is used. | |
13795 | ||
13796 | If the type specifier is given after the mnemonics, the | |
13797 | information is stored in inst.vectype. If the type specifier | |
13798 | is given after register operand, the information is stored | |
13799 | in inst.operands[].vectype. | |
13800 | ||
13801 | When there is only one type specifier, and all the register | |
13802 | operands are the same type of hardware register, the type | |
13803 | specifier applies to all register operands. | |
13804 | ||
13805 | If no type specifier is given, the shape is inferred from | |
13806 | operand information. | |
13807 | ||
13808 | for example: | |
13809 | vadd.f16 s0, s1, s2: NS_HHH | |
13810 | vabs.f16 s0, s1: NS_HH | |
13811 | vmov.f16 s0, r1: NS_HR | |
13812 | vmov.f16 r0, s1: NS_RH | |
13813 | vcvt.f16 r0, s1: NS_RH | |
13814 | vcvt.f16.s32 s2, s2, #29: NS_HFI | |
13815 | vcvt.f16.s32 s2, s2: NS_HF | |
13816 | */ | |
13817 | case SE_H: | |
13818 | if (!(inst.operands[j].isreg | |
13819 | && inst.operands[j].isvec | |
13820 | && inst.operands[j].issingle | |
13821 | && !inst.operands[j].isquad | |
13822 | && ((inst.vectype.elems == 1 | |
13823 | && inst.vectype.el[0].size == 16) | |
13824 | || (inst.vectype.elems > 1 | |
13825 | && inst.vectype.el[j].size == 16) | |
13826 | || (inst.vectype.elems == 0 | |
13827 | && inst.operands[j].vectype.type != NT_invtype | |
13828 | && inst.operands[j].vectype.size == 16)))) | |
13829 | matches = 0; | |
13830 | break; | |
13831 | ||
477330fc RM |
13832 | case SE_F: |
13833 | if (!(inst.operands[j].isreg | |
13834 | && inst.operands[j].isvec | |
13835 | && inst.operands[j].issingle | |
d54af2d0 RL |
13836 | && !inst.operands[j].isquad |
13837 | && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32) | |
13838 | || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32) | |
13839 | || (inst.vectype.elems == 0 | |
13840 | && (inst.operands[j].vectype.size == 32 | |
13841 | || inst.operands[j].vectype.type == NT_invtype))))) | |
477330fc RM |
13842 | matches = 0; |
13843 | break; | |
13844 | ||
13845 | case SE_D: | |
13846 | if (!(inst.operands[j].isreg | |
13847 | && inst.operands[j].isvec | |
13848 | && !inst.operands[j].isquad | |
13849 | && !inst.operands[j].issingle)) | |
13850 | matches = 0; | |
13851 | break; | |
13852 | ||
13853 | case SE_R: | |
13854 | if (!(inst.operands[j].isreg | |
13855 | && !inst.operands[j].isvec)) | |
13856 | matches = 0; | |
13857 | break; | |
13858 | ||
13859 | case SE_Q: | |
13860 | if (!(inst.operands[j].isreg | |
13861 | && inst.operands[j].isvec | |
13862 | && inst.operands[j].isquad | |
13863 | && !inst.operands[j].issingle)) | |
13864 | matches = 0; | |
13865 | break; | |
13866 | ||
13867 | case SE_I: | |
13868 | if (!(!inst.operands[j].isreg | |
13869 | && !inst.operands[j].isscalar)) | |
13870 | matches = 0; | |
13871 | break; | |
13872 | ||
13873 | case SE_S: | |
13874 | if (!(!inst.operands[j].isreg | |
13875 | && inst.operands[j].isscalar)) | |
13876 | matches = 0; | |
13877 | break; | |
13878 | ||
13879 | case SE_L: | |
13880 | break; | |
13881 | } | |
3fde54a2 JZ |
13882 | if (!matches) |
13883 | break; | |
477330fc | 13884 | } |
ad6cec43 MGD |
13885 | if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present)) |
13886 | /* We've matched all the entries in the shape table, and we don't | |
13887 | have any left over operands which have not been matched. */ | |
477330fc | 13888 | break; |
037e8744 | 13889 | } |
5f4273c7 | 13890 | |
037e8744 | 13891 | va_end (ap); |
5287ad62 | 13892 | |
037e8744 JB |
13893 | if (shape == NS_NULL && first_shape != NS_NULL) |
13894 | first_error (_("invalid instruction shape")); | |
5287ad62 | 13895 | |
037e8744 JB |
13896 | return shape; |
13897 | } | |
5287ad62 | 13898 | |
037e8744 JB |
13899 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
13900 | means the Q bit should be set). */ | |
13901 | ||
13902 | static int | |
13903 | neon_quad (enum neon_shape shape) | |
13904 | { | |
13905 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 13906 | } |
037e8744 | 13907 | |
5287ad62 JB |
13908 | static void |
13909 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
477330fc | 13910 | unsigned *g_size) |
5287ad62 JB |
13911 | { |
13912 | /* Allow modification to be made to types which are constrained to be | |
13913 | based on the key element, based on bits set alongside N_EQK. */ | |
13914 | if ((typebits & N_EQK) != 0) | |
13915 | { | |
13916 | if ((typebits & N_HLF) != 0) | |
13917 | *g_size /= 2; | |
13918 | else if ((typebits & N_DBL) != 0) | |
13919 | *g_size *= 2; | |
13920 | if ((typebits & N_SGN) != 0) | |
13921 | *g_type = NT_signed; | |
13922 | else if ((typebits & N_UNS) != 0) | |
477330fc | 13923 | *g_type = NT_unsigned; |
5287ad62 | 13924 | else if ((typebits & N_INT) != 0) |
477330fc | 13925 | *g_type = NT_integer; |
5287ad62 | 13926 | else if ((typebits & N_FLT) != 0) |
477330fc | 13927 | *g_type = NT_float; |
dcbf9037 | 13928 | else if ((typebits & N_SIZ) != 0) |
477330fc | 13929 | *g_type = NT_untyped; |
5287ad62 JB |
13930 | } |
13931 | } | |
5f4273c7 | 13932 | |
5287ad62 JB |
13933 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
13934 | operand type, i.e. the single type specified in a Neon instruction when it | |
13935 | is the only one given. */ | |
13936 | ||
13937 | static struct neon_type_el | |
13938 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
13939 | { | |
13940 | struct neon_type_el dest = *key; | |
5f4273c7 | 13941 | |
9c2799c2 | 13942 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 13943 | |
5287ad62 JB |
13944 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
13945 | ||
13946 | return dest; | |
13947 | } | |
13948 | ||
13949 | /* Convert Neon type and size into compact bitmask representation. */ | |
13950 | ||
13951 | static enum neon_type_mask | |
13952 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
13953 | { | |
13954 | switch (type) | |
13955 | { | |
13956 | case NT_untyped: | |
13957 | switch (size) | |
477330fc RM |
13958 | { |
13959 | case 8: return N_8; | |
13960 | case 16: return N_16; | |
13961 | case 32: return N_32; | |
13962 | case 64: return N_64; | |
13963 | default: ; | |
13964 | } | |
5287ad62 JB |
13965 | break; |
13966 | ||
13967 | case NT_integer: | |
13968 | switch (size) | |
477330fc RM |
13969 | { |
13970 | case 8: return N_I8; | |
13971 | case 16: return N_I16; | |
13972 | case 32: return N_I32; | |
13973 | case 64: return N_I64; | |
13974 | default: ; | |
13975 | } | |
5287ad62 JB |
13976 | break; |
13977 | ||
13978 | case NT_float: | |
037e8744 | 13979 | switch (size) |
477330fc | 13980 | { |
8e79c3df | 13981 | case 16: return N_F16; |
477330fc RM |
13982 | case 32: return N_F32; |
13983 | case 64: return N_F64; | |
13984 | default: ; | |
13985 | } | |
5287ad62 JB |
13986 | break; |
13987 | ||
13988 | case NT_poly: | |
13989 | switch (size) | |
477330fc RM |
13990 | { |
13991 | case 8: return N_P8; | |
13992 | case 16: return N_P16; | |
4f51b4bd | 13993 | case 64: return N_P64; |
477330fc RM |
13994 | default: ; |
13995 | } | |
5287ad62 JB |
13996 | break; |
13997 | ||
13998 | case NT_signed: | |
13999 | switch (size) | |
477330fc RM |
14000 | { |
14001 | case 8: return N_S8; | |
14002 | case 16: return N_S16; | |
14003 | case 32: return N_S32; | |
14004 | case 64: return N_S64; | |
14005 | default: ; | |
14006 | } | |
5287ad62 JB |
14007 | break; |
14008 | ||
14009 | case NT_unsigned: | |
14010 | switch (size) | |
477330fc RM |
14011 | { |
14012 | case 8: return N_U8; | |
14013 | case 16: return N_U16; | |
14014 | case 32: return N_U32; | |
14015 | case 64: return N_U64; | |
14016 | default: ; | |
14017 | } | |
5287ad62 JB |
14018 | break; |
14019 | ||
14020 | default: ; | |
14021 | } | |
5f4273c7 | 14022 | |
5287ad62 JB |
14023 | return N_UTYP; |
14024 | } | |
14025 | ||
14026 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
14027 | handles the case where a single bit is set in the mask. */ | |
14028 | ||
dcbf9037 | 14029 | static int |
5287ad62 | 14030 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
477330fc | 14031 | enum neon_type_mask mask) |
5287ad62 | 14032 | { |
dcbf9037 JB |
14033 | if ((mask & N_EQK) != 0) |
14034 | return FAIL; | |
14035 | ||
5287ad62 JB |
14036 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
14037 | *size = 8; | |
c70a8987 | 14038 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0) |
5287ad62 | 14039 | *size = 16; |
dcbf9037 | 14040 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 14041 | *size = 32; |
4f51b4bd | 14042 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 14043 | *size = 64; |
dcbf9037 JB |
14044 | else |
14045 | return FAIL; | |
14046 | ||
5287ad62 JB |
14047 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
14048 | *type = NT_signed; | |
dcbf9037 | 14049 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 14050 | *type = NT_unsigned; |
dcbf9037 | 14051 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 14052 | *type = NT_integer; |
dcbf9037 | 14053 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 14054 | *type = NT_untyped; |
4f51b4bd | 14055 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 14056 | *type = NT_poly; |
d54af2d0 | 14057 | else if ((mask & (N_F_ALL)) != 0) |
5287ad62 | 14058 | *type = NT_float; |
dcbf9037 JB |
14059 | else |
14060 | return FAIL; | |
5f4273c7 | 14061 | |
dcbf9037 | 14062 | return SUCCESS; |
5287ad62 JB |
14063 | } |
14064 | ||
14065 | /* Modify a bitmask of allowed types. This is only needed for type | |
14066 | relaxation. */ | |
14067 | ||
14068 | static unsigned | |
14069 | modify_types_allowed (unsigned allowed, unsigned mods) | |
14070 | { | |
14071 | unsigned size; | |
14072 | enum neon_el_type type; | |
14073 | unsigned destmask; | |
14074 | int i; | |
5f4273c7 | 14075 | |
5287ad62 | 14076 | destmask = 0; |
5f4273c7 | 14077 | |
5287ad62 JB |
14078 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
14079 | { | |
21d799b5 | 14080 | if (el_type_of_type_chk (&type, &size, |
477330fc RM |
14081 | (enum neon_type_mask) (allowed & i)) == SUCCESS) |
14082 | { | |
14083 | neon_modify_type_size (mods, &type, &size); | |
14084 | destmask |= type_chk_of_el_type (type, size); | |
14085 | } | |
5287ad62 | 14086 | } |
5f4273c7 | 14087 | |
5287ad62 JB |
14088 | return destmask; |
14089 | } | |
14090 | ||
14091 | /* Check type and return type classification. | |
14092 | The manual states (paraphrase): If one datatype is given, it indicates the | |
14093 | type given in: | |
14094 | - the second operand, if there is one | |
14095 | - the operand, if there is no second operand | |
14096 | - the result, if there are no operands. | |
14097 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
14098 | which is set on a per-instruction basis, which is the one which matters when | |
14099 | only one data type is written. | |
14100 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 14101 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
14102 | |
14103 | static struct neon_type_el | |
14104 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
14105 | { | |
14106 | va_list ap; | |
14107 | unsigned i, pass, key_el = 0; | |
14108 | unsigned types[NEON_MAX_TYPE_ELS]; | |
14109 | enum neon_el_type k_type = NT_invtype; | |
14110 | unsigned k_size = -1u; | |
14111 | struct neon_type_el badtype = {NT_invtype, -1}; | |
14112 | unsigned key_allowed = 0; | |
14113 | ||
14114 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
14115 | Fill in the missing operand here, if it was omitted. */ | |
14116 | if (els > 1 && !inst.operands[1].present) | |
14117 | inst.operands[1] = inst.operands[0]; | |
14118 | ||
14119 | /* Suck up all the varargs. */ | |
14120 | va_start (ap, ns); | |
14121 | for (i = 0; i < els; i++) | |
14122 | { | |
14123 | unsigned thisarg = va_arg (ap, unsigned); | |
14124 | if (thisarg == N_IGNORE_TYPE) | |
477330fc RM |
14125 | { |
14126 | va_end (ap); | |
14127 | return badtype; | |
14128 | } | |
5287ad62 JB |
14129 | types[i] = thisarg; |
14130 | if ((thisarg & N_KEY) != 0) | |
477330fc | 14131 | key_el = i; |
5287ad62 JB |
14132 | } |
14133 | va_end (ap); | |
14134 | ||
dcbf9037 JB |
14135 | if (inst.vectype.elems > 0) |
14136 | for (i = 0; i < els; i++) | |
14137 | if (inst.operands[i].vectype.type != NT_invtype) | |
477330fc RM |
14138 | { |
14139 | first_error (_("types specified in both the mnemonic and operands")); | |
14140 | return badtype; | |
14141 | } | |
dcbf9037 | 14142 | |
5287ad62 JB |
14143 | /* Duplicate inst.vectype elements here as necessary. |
14144 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
14145 | particularly when an insn takes one register and one non-register | |
14146 | operand. */ | |
14147 | if (inst.vectype.elems == 1 && els > 1) | |
14148 | { | |
14149 | unsigned j; | |
14150 | inst.vectype.elems = els; | |
14151 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
14152 | for (j = 0; j < els; j++) | |
477330fc RM |
14153 | if (j != key_el) |
14154 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
14155 | types[j]); | |
dcbf9037 JB |
14156 | } |
14157 | else if (inst.vectype.elems == 0 && els > 0) | |
14158 | { | |
14159 | unsigned j; | |
14160 | /* No types were given after the mnemonic, so look for types specified | |
477330fc RM |
14161 | after each operand. We allow some flexibility here; as long as the |
14162 | "key" operand has a type, we can infer the others. */ | |
dcbf9037 | 14163 | for (j = 0; j < els; j++) |
477330fc RM |
14164 | if (inst.operands[j].vectype.type != NT_invtype) |
14165 | inst.vectype.el[j] = inst.operands[j].vectype; | |
dcbf9037 JB |
14166 | |
14167 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
477330fc RM |
14168 | { |
14169 | for (j = 0; j < els; j++) | |
14170 | if (inst.operands[j].vectype.type == NT_invtype) | |
14171 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
14172 | types[j]); | |
14173 | } | |
dcbf9037 | 14174 | else |
477330fc RM |
14175 | { |
14176 | first_error (_("operand types can't be inferred")); | |
14177 | return badtype; | |
14178 | } | |
5287ad62 JB |
14179 | } |
14180 | else if (inst.vectype.elems != els) | |
14181 | { | |
dcbf9037 | 14182 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
14183 | return badtype; |
14184 | } | |
14185 | ||
14186 | for (pass = 0; pass < 2; pass++) | |
14187 | { | |
14188 | for (i = 0; i < els; i++) | |
477330fc RM |
14189 | { |
14190 | unsigned thisarg = types[i]; | |
14191 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
14192 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
14193 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
14194 | unsigned g_size = inst.vectype.el[i].size; | |
14195 | ||
14196 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
5287ad62 | 14197 | integer types if sign-specific variants are unavailable. */ |
477330fc | 14198 | if ((g_type == NT_signed || g_type == NT_unsigned) |
5287ad62 JB |
14199 | && (types_allowed & N_SU_ALL) == 0) |
14200 | g_type = NT_integer; | |
14201 | ||
477330fc | 14202 | /* If only untyped args are allowed, decay any more specific types to |
5287ad62 JB |
14203 | them. Some instructions only care about signs for some element |
14204 | sizes, so handle that properly. */ | |
477330fc | 14205 | if (((types_allowed & N_UNT) == 0) |
91ff7894 MGD |
14206 | && ((g_size == 8 && (types_allowed & N_8) != 0) |
14207 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
14208 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
14209 | || (g_size == 64 && (types_allowed & N_64) != 0))) | |
5287ad62 JB |
14210 | g_type = NT_untyped; |
14211 | ||
477330fc RM |
14212 | if (pass == 0) |
14213 | { | |
14214 | if ((thisarg & N_KEY) != 0) | |
14215 | { | |
14216 | k_type = g_type; | |
14217 | k_size = g_size; | |
14218 | key_allowed = thisarg & ~N_KEY; | |
cc933301 JW |
14219 | |
14220 | /* Check architecture constraint on FP16 extension. */ | |
14221 | if (k_size == 16 | |
14222 | && k_type == NT_float | |
14223 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
14224 | { | |
14225 | inst.error = _(BAD_FP16); | |
14226 | return badtype; | |
14227 | } | |
477330fc RM |
14228 | } |
14229 | } | |
14230 | else | |
14231 | { | |
14232 | if ((thisarg & N_VFP) != 0) | |
14233 | { | |
14234 | enum neon_shape_el regshape; | |
14235 | unsigned regwidth, match; | |
99b253c5 NC |
14236 | |
14237 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
14238 | if (ns == NS_NULL) | |
14239 | { | |
14240 | first_error (_("invalid instruction shape")); | |
14241 | return badtype; | |
14242 | } | |
477330fc RM |
14243 | regshape = neon_shape_tab[ns].el[i]; |
14244 | regwidth = neon_shape_el_size[regshape]; | |
14245 | ||
14246 | /* In VFP mode, operands must match register widths. If we | |
14247 | have a key operand, use its width, else use the width of | |
14248 | the current operand. */ | |
14249 | if (k_size != -1u) | |
14250 | match = k_size; | |
14251 | else | |
14252 | match = g_size; | |
14253 | ||
9db2f6b4 RL |
14254 | /* FP16 will use a single precision register. */ |
14255 | if (regwidth == 32 && match == 16) | |
14256 | { | |
14257 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
14258 | match = regwidth; | |
14259 | else | |
14260 | { | |
14261 | inst.error = _(BAD_FP16); | |
14262 | return badtype; | |
14263 | } | |
14264 | } | |
14265 | ||
477330fc RM |
14266 | if (regwidth != match) |
14267 | { | |
14268 | first_error (_("operand size must match register width")); | |
14269 | return badtype; | |
14270 | } | |
14271 | } | |
14272 | ||
14273 | if ((thisarg & N_EQK) == 0) | |
14274 | { | |
14275 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
14276 | ||
14277 | if ((given_type & types_allowed) == 0) | |
14278 | { | |
14279 | first_error (_("bad type in Neon instruction")); | |
14280 | return badtype; | |
14281 | } | |
14282 | } | |
14283 | else | |
14284 | { | |
14285 | enum neon_el_type mod_k_type = k_type; | |
14286 | unsigned mod_k_size = k_size; | |
14287 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
14288 | if (g_type != mod_k_type || g_size != mod_k_size) | |
14289 | { | |
14290 | first_error (_("inconsistent types in Neon instruction")); | |
14291 | return badtype; | |
14292 | } | |
14293 | } | |
14294 | } | |
14295 | } | |
5287ad62 JB |
14296 | } |
14297 | ||
14298 | return inst.vectype.el[key_el]; | |
14299 | } | |
14300 | ||
037e8744 | 14301 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 14302 | |
037e8744 JB |
14303 | /* Thumb VFP instructions have 0xE in the condition field. */ |
14304 | ||
14305 | static void | |
14306 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 14307 | { |
88714cb8 DG |
14308 | inst.is_neon = 1; |
14309 | ||
5287ad62 | 14310 | if (thumb_mode) |
037e8744 | 14311 | inst.instruction |= 0xe0000000; |
5287ad62 | 14312 | else |
037e8744 | 14313 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
14314 | } |
14315 | ||
037e8744 JB |
14316 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
14317 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
14318 | etc. It is assumed that operand parsing has already been done, and that the | |
14319 | operands are in the form expected by the given opcode (this isn't necessarily | |
14320 | the same as the form in which they were parsed, hence some massaging must | |
14321 | take place before this function is called). | |
14322 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 14323 | |
037e8744 JB |
14324 | static void |
14325 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 14326 | { |
037e8744 | 14327 | const struct asm_opcode *opcode; |
5f4273c7 | 14328 | |
21d799b5 | 14329 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 14330 | |
037e8744 JB |
14331 | if (!opcode) |
14332 | abort (); | |
5287ad62 | 14333 | |
037e8744 | 14334 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
477330fc RM |
14335 | thumb_mode ? *opcode->tvariant : *opcode->avariant), |
14336 | _(BAD_FPU)); | |
5287ad62 | 14337 | |
88714cb8 DG |
14338 | inst.is_neon = 1; |
14339 | ||
037e8744 JB |
14340 | if (thumb_mode) |
14341 | { | |
14342 | inst.instruction = opcode->tvalue; | |
14343 | opcode->tencode (); | |
14344 | } | |
14345 | else | |
14346 | { | |
14347 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
14348 | opcode->aencode (); | |
14349 | } | |
14350 | } | |
5287ad62 JB |
14351 | |
14352 | static void | |
037e8744 | 14353 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 14354 | { |
037e8744 JB |
14355 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
14356 | ||
9db2f6b4 | 14357 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
14358 | { |
14359 | if (is_add) | |
477330fc | 14360 | do_vfp_nsyn_opcode ("fadds"); |
037e8744 | 14361 | else |
477330fc | 14362 | do_vfp_nsyn_opcode ("fsubs"); |
9db2f6b4 RL |
14363 | |
14364 | /* ARMv8.2 fp16 instruction. */ | |
14365 | if (rs == NS_HHH) | |
14366 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14367 | } |
14368 | else | |
14369 | { | |
14370 | if (is_add) | |
477330fc | 14371 | do_vfp_nsyn_opcode ("faddd"); |
037e8744 | 14372 | else |
477330fc | 14373 | do_vfp_nsyn_opcode ("fsubd"); |
037e8744 JB |
14374 | } |
14375 | } | |
14376 | ||
14377 | /* Check operand types to see if this is a VFP instruction, and if so call | |
14378 | PFN (). */ | |
14379 | ||
14380 | static int | |
14381 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
14382 | { | |
14383 | enum neon_shape rs; | |
14384 | struct neon_type_el et; | |
14385 | ||
14386 | switch (args) | |
14387 | { | |
14388 | case 2: | |
9db2f6b4 RL |
14389 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14390 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
037e8744 | 14391 | break; |
5f4273c7 | 14392 | |
037e8744 | 14393 | case 3: |
9db2f6b4 RL |
14394 | rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
14395 | et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
14396 | N_F_ALL | N_KEY | N_VFP); | |
037e8744 JB |
14397 | break; |
14398 | ||
14399 | default: | |
14400 | abort (); | |
14401 | } | |
14402 | ||
14403 | if (et.type != NT_invtype) | |
14404 | { | |
14405 | pfn (rs); | |
14406 | return SUCCESS; | |
14407 | } | |
037e8744 | 14408 | |
99b253c5 | 14409 | inst.error = NULL; |
037e8744 JB |
14410 | return FAIL; |
14411 | } | |
14412 | ||
14413 | static void | |
14414 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
14415 | { | |
14416 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 14417 | |
9db2f6b4 | 14418 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
14419 | { |
14420 | if (is_mla) | |
477330fc | 14421 | do_vfp_nsyn_opcode ("fmacs"); |
037e8744 | 14422 | else |
477330fc | 14423 | do_vfp_nsyn_opcode ("fnmacs"); |
9db2f6b4 RL |
14424 | |
14425 | /* ARMv8.2 fp16 instruction. */ | |
14426 | if (rs == NS_HHH) | |
14427 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14428 | } |
14429 | else | |
14430 | { | |
14431 | if (is_mla) | |
477330fc | 14432 | do_vfp_nsyn_opcode ("fmacd"); |
037e8744 | 14433 | else |
477330fc | 14434 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
14435 | } |
14436 | } | |
14437 | ||
62f3b8c8 PB |
14438 | static void |
14439 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
14440 | { | |
14441 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
14442 | ||
9db2f6b4 | 14443 | if (rs == NS_FFF || rs == NS_HHH) |
62f3b8c8 PB |
14444 | { |
14445 | if (is_fma) | |
477330fc | 14446 | do_vfp_nsyn_opcode ("ffmas"); |
62f3b8c8 | 14447 | else |
477330fc | 14448 | do_vfp_nsyn_opcode ("ffnmas"); |
9db2f6b4 RL |
14449 | |
14450 | /* ARMv8.2 fp16 instruction. */ | |
14451 | if (rs == NS_HHH) | |
14452 | do_scalar_fp16_v82_encode (); | |
62f3b8c8 PB |
14453 | } |
14454 | else | |
14455 | { | |
14456 | if (is_fma) | |
477330fc | 14457 | do_vfp_nsyn_opcode ("ffmad"); |
62f3b8c8 | 14458 | else |
477330fc | 14459 | do_vfp_nsyn_opcode ("ffnmad"); |
62f3b8c8 PB |
14460 | } |
14461 | } | |
14462 | ||
037e8744 JB |
14463 | static void |
14464 | do_vfp_nsyn_mul (enum neon_shape rs) | |
14465 | { | |
9db2f6b4 RL |
14466 | if (rs == NS_FFF || rs == NS_HHH) |
14467 | { | |
14468 | do_vfp_nsyn_opcode ("fmuls"); | |
14469 | ||
14470 | /* ARMv8.2 fp16 instruction. */ | |
14471 | if (rs == NS_HHH) | |
14472 | do_scalar_fp16_v82_encode (); | |
14473 | } | |
037e8744 JB |
14474 | else |
14475 | do_vfp_nsyn_opcode ("fmuld"); | |
14476 | } | |
14477 | ||
14478 | static void | |
14479 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
14480 | { | |
14481 | int is_neg = (inst.instruction & 0x80) != 0; | |
9db2f6b4 | 14482 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY); |
037e8744 | 14483 | |
9db2f6b4 | 14484 | if (rs == NS_FF || rs == NS_HH) |
037e8744 JB |
14485 | { |
14486 | if (is_neg) | |
477330fc | 14487 | do_vfp_nsyn_opcode ("fnegs"); |
037e8744 | 14488 | else |
477330fc | 14489 | do_vfp_nsyn_opcode ("fabss"); |
9db2f6b4 RL |
14490 | |
14491 | /* ARMv8.2 fp16 instruction. */ | |
14492 | if (rs == NS_HH) | |
14493 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14494 | } |
14495 | else | |
14496 | { | |
14497 | if (is_neg) | |
477330fc | 14498 | do_vfp_nsyn_opcode ("fnegd"); |
037e8744 | 14499 | else |
477330fc | 14500 | do_vfp_nsyn_opcode ("fabsd"); |
037e8744 JB |
14501 | } |
14502 | } | |
14503 | ||
14504 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
14505 | insns belong to Neon, and are handled elsewhere. */ | |
14506 | ||
14507 | static void | |
14508 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
14509 | { | |
14510 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
14511 | if (is_ldm) | |
14512 | { | |
14513 | if (is_dbmode) | |
477330fc | 14514 | do_vfp_nsyn_opcode ("fldmdbs"); |
037e8744 | 14515 | else |
477330fc | 14516 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 JB |
14517 | } |
14518 | else | |
14519 | { | |
14520 | if (is_dbmode) | |
477330fc | 14521 | do_vfp_nsyn_opcode ("fstmdbs"); |
037e8744 | 14522 | else |
477330fc | 14523 | do_vfp_nsyn_opcode ("fstmias"); |
037e8744 JB |
14524 | } |
14525 | } | |
14526 | ||
037e8744 JB |
14527 | static void |
14528 | do_vfp_nsyn_sqrt (void) | |
14529 | { | |
9db2f6b4 RL |
14530 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14531 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 14532 | |
9db2f6b4 RL |
14533 | if (rs == NS_FF || rs == NS_HH) |
14534 | { | |
14535 | do_vfp_nsyn_opcode ("fsqrts"); | |
14536 | ||
14537 | /* ARMv8.2 fp16 instruction. */ | |
14538 | if (rs == NS_HH) | |
14539 | do_scalar_fp16_v82_encode (); | |
14540 | } | |
037e8744 JB |
14541 | else |
14542 | do_vfp_nsyn_opcode ("fsqrtd"); | |
14543 | } | |
14544 | ||
14545 | static void | |
14546 | do_vfp_nsyn_div (void) | |
14547 | { | |
9db2f6b4 | 14548 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 14549 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 14550 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 14551 | |
9db2f6b4 RL |
14552 | if (rs == NS_FFF || rs == NS_HHH) |
14553 | { | |
14554 | do_vfp_nsyn_opcode ("fdivs"); | |
14555 | ||
14556 | /* ARMv8.2 fp16 instruction. */ | |
14557 | if (rs == NS_HHH) | |
14558 | do_scalar_fp16_v82_encode (); | |
14559 | } | |
037e8744 JB |
14560 | else |
14561 | do_vfp_nsyn_opcode ("fdivd"); | |
14562 | } | |
14563 | ||
14564 | static void | |
14565 | do_vfp_nsyn_nmul (void) | |
14566 | { | |
9db2f6b4 | 14567 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 14568 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 14569 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 14570 | |
9db2f6b4 | 14571 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 | 14572 | { |
88714cb8 | 14573 | NEON_ENCODE (SINGLE, inst); |
037e8744 | 14574 | do_vfp_sp_dyadic (); |
9db2f6b4 RL |
14575 | |
14576 | /* ARMv8.2 fp16 instruction. */ | |
14577 | if (rs == NS_HHH) | |
14578 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14579 | } |
14580 | else | |
14581 | { | |
88714cb8 | 14582 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
14583 | do_vfp_dp_rd_rn_rm (); |
14584 | } | |
14585 | do_vfp_cond_or_thumb (); | |
9db2f6b4 | 14586 | |
037e8744 JB |
14587 | } |
14588 | ||
14589 | static void | |
14590 | do_vfp_nsyn_cmp (void) | |
14591 | { | |
9db2f6b4 | 14592 | enum neon_shape rs; |
037e8744 JB |
14593 | if (inst.operands[1].isreg) |
14594 | { | |
9db2f6b4 RL |
14595 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14596 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 14597 | |
9db2f6b4 | 14598 | if (rs == NS_FF || rs == NS_HH) |
477330fc RM |
14599 | { |
14600 | NEON_ENCODE (SINGLE, inst); | |
14601 | do_vfp_sp_monadic (); | |
14602 | } | |
037e8744 | 14603 | else |
477330fc RM |
14604 | { |
14605 | NEON_ENCODE (DOUBLE, inst); | |
14606 | do_vfp_dp_rd_rm (); | |
14607 | } | |
037e8744 JB |
14608 | } |
14609 | else | |
14610 | { | |
9db2f6b4 RL |
14611 | rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL); |
14612 | neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK); | |
037e8744 JB |
14613 | |
14614 | switch (inst.instruction & 0x0fffffff) | |
477330fc RM |
14615 | { |
14616 | case N_MNEM_vcmp: | |
14617 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
14618 | break; | |
14619 | case N_MNEM_vcmpe: | |
14620 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
14621 | break; | |
14622 | default: | |
14623 | abort (); | |
14624 | } | |
5f4273c7 | 14625 | |
9db2f6b4 | 14626 | if (rs == NS_FI || rs == NS_HI) |
477330fc RM |
14627 | { |
14628 | NEON_ENCODE (SINGLE, inst); | |
14629 | do_vfp_sp_compare_z (); | |
14630 | } | |
037e8744 | 14631 | else |
477330fc RM |
14632 | { |
14633 | NEON_ENCODE (DOUBLE, inst); | |
14634 | do_vfp_dp_rd (); | |
14635 | } | |
037e8744 JB |
14636 | } |
14637 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
14638 | |
14639 | /* ARMv8.2 fp16 instruction. */ | |
14640 | if (rs == NS_HI || rs == NS_HH) | |
14641 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14642 | } |
14643 | ||
14644 | static void | |
14645 | nsyn_insert_sp (void) | |
14646 | { | |
14647 | inst.operands[1] = inst.operands[0]; | |
14648 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 14649 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
14650 | inst.operands[0].isreg = 1; |
14651 | inst.operands[0].writeback = 1; | |
14652 | inst.operands[0].present = 1; | |
14653 | } | |
14654 | ||
14655 | static void | |
14656 | do_vfp_nsyn_push (void) | |
14657 | { | |
14658 | nsyn_insert_sp (); | |
b126985e NC |
14659 | |
14660 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14661 | _("register list must contain at least 1 and at most 16 " | |
14662 | "registers")); | |
14663 | ||
037e8744 JB |
14664 | if (inst.operands[1].issingle) |
14665 | do_vfp_nsyn_opcode ("fstmdbs"); | |
14666 | else | |
14667 | do_vfp_nsyn_opcode ("fstmdbd"); | |
14668 | } | |
14669 | ||
14670 | static void | |
14671 | do_vfp_nsyn_pop (void) | |
14672 | { | |
14673 | nsyn_insert_sp (); | |
b126985e NC |
14674 | |
14675 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
14676 | _("register list must contain at least 1 and at most 16 " | |
14677 | "registers")); | |
14678 | ||
037e8744 | 14679 | if (inst.operands[1].issingle) |
22b5b651 | 14680 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 14681 | else |
22b5b651 | 14682 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
14683 | } |
14684 | ||
14685 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
14686 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
14687 | ||
88714cb8 DG |
14688 | static void |
14689 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 14690 | { |
88714cb8 DG |
14691 | unsigned int i = insn->instruction; |
14692 | insn->is_neon = 1; | |
14693 | ||
037e8744 JB |
14694 | if (thumb_mode) |
14695 | { | |
14696 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
14697 | if (i & (1 << 24)) | |
477330fc | 14698 | i |= 1 << 28; |
5f4273c7 | 14699 | |
037e8744 | 14700 | i &= ~(1 << 24); |
5f4273c7 | 14701 | |
037e8744 JB |
14702 | i |= 0xef000000; |
14703 | } | |
14704 | else | |
14705 | i |= 0xf2000000; | |
5f4273c7 | 14706 | |
88714cb8 | 14707 | insn->instruction = i; |
037e8744 JB |
14708 | } |
14709 | ||
14710 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
14711 | (0, 1, 2, 3). */ | |
14712 | ||
14713 | static unsigned | |
14714 | neon_logbits (unsigned x) | |
14715 | { | |
14716 | return ffs (x) - 4; | |
14717 | } | |
14718 | ||
14719 | #define LOW4(R) ((R) & 0xf) | |
14720 | #define HI1(R) (((R) >> 4) & 1) | |
14721 | ||
14722 | /* Encode insns with bit pattern: | |
14723 | ||
14724 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
14725 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 14726 | |
037e8744 JB |
14727 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
14728 | different meaning for some instruction. */ | |
14729 | ||
14730 | static void | |
14731 | neon_three_same (int isquad, int ubit, int size) | |
14732 | { | |
14733 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14734 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14735 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14736 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14737 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14738 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14739 | inst.instruction |= (isquad != 0) << 6; | |
14740 | inst.instruction |= (ubit != 0) << 24; | |
14741 | if (size != -1) | |
14742 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 14743 | |
88714cb8 | 14744 | neon_dp_fixup (&inst); |
037e8744 JB |
14745 | } |
14746 | ||
14747 | /* Encode instructions of the form: | |
14748 | ||
14749 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
14750 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
14751 | |
14752 | Don't write size if SIZE == -1. */ | |
14753 | ||
14754 | static void | |
14755 | neon_two_same (int qbit, int ubit, int size) | |
14756 | { | |
14757 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14758 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14759 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14760 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14761 | inst.instruction |= (qbit != 0) << 6; | |
14762 | inst.instruction |= (ubit != 0) << 24; | |
14763 | ||
14764 | if (size != -1) | |
14765 | inst.instruction |= neon_logbits (size) << 18; | |
14766 | ||
88714cb8 | 14767 | neon_dp_fixup (&inst); |
5287ad62 JB |
14768 | } |
14769 | ||
14770 | /* Neon instruction encoders, in approximate order of appearance. */ | |
14771 | ||
14772 | static void | |
14773 | do_neon_dyadic_i_su (void) | |
14774 | { | |
037e8744 | 14775 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14776 | struct neon_type_el et = neon_check_type (3, rs, |
14777 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 14778 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14779 | } |
14780 | ||
14781 | static void | |
14782 | do_neon_dyadic_i64_su (void) | |
14783 | { | |
037e8744 | 14784 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14785 | struct neon_type_el et = neon_check_type (3, rs, |
14786 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 14787 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14788 | } |
14789 | ||
14790 | static void | |
14791 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
477330fc | 14792 | unsigned immbits) |
5287ad62 JB |
14793 | { |
14794 | unsigned size = et.size >> 3; | |
14795 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14796 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14797 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14798 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14799 | inst.instruction |= (isquad != 0) << 6; | |
14800 | inst.instruction |= immbits << 16; | |
14801 | inst.instruction |= (size >> 3) << 7; | |
14802 | inst.instruction |= (size & 0x7) << 19; | |
14803 | if (write_ubit) | |
14804 | inst.instruction |= (uval != 0) << 24; | |
14805 | ||
88714cb8 | 14806 | neon_dp_fixup (&inst); |
5287ad62 JB |
14807 | } |
14808 | ||
14809 | static void | |
14810 | do_neon_shl_imm (void) | |
14811 | { | |
14812 | if (!inst.operands[2].isreg) | |
14813 | { | |
037e8744 | 14814 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 14815 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
cb3b1e65 JB |
14816 | int imm = inst.operands[2].imm; |
14817 | ||
14818 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
14819 | _("immediate out of range for shift")); | |
88714cb8 | 14820 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 14821 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14822 | } |
14823 | else | |
14824 | { | |
037e8744 | 14825 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14826 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14827 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
14828 | unsigned int tmp; |
14829 | ||
14830 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
477330fc RM |
14831 | vshl.xx Dd, Dm, Dn |
14832 | whereas other 3-register operations encoded by neon_three_same have | |
14833 | syntax like: | |
14834 | vadd.xx Dd, Dn, Dm | |
14835 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
14836 | here. */ | |
627907b7 JB |
14837 | tmp = inst.operands[2].reg; |
14838 | inst.operands[2].reg = inst.operands[1].reg; | |
14839 | inst.operands[1].reg = tmp; | |
88714cb8 | 14840 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14841 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14842 | } |
14843 | } | |
14844 | ||
14845 | static void | |
14846 | do_neon_qshl_imm (void) | |
14847 | { | |
14848 | if (!inst.operands[2].isreg) | |
14849 | { | |
037e8744 | 14850 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 14851 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
cb3b1e65 | 14852 | int imm = inst.operands[2].imm; |
627907b7 | 14853 | |
cb3b1e65 JB |
14854 | constraint (imm < 0 || (unsigned)imm >= et.size, |
14855 | _("immediate out of range for shift")); | |
88714cb8 | 14856 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 14857 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm); |
5287ad62 JB |
14858 | } |
14859 | else | |
14860 | { | |
037e8744 | 14861 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14862 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14863 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
14864 | unsigned int tmp; |
14865 | ||
14866 | /* See note in do_neon_shl_imm. */ | |
14867 | tmp = inst.operands[2].reg; | |
14868 | inst.operands[2].reg = inst.operands[1].reg; | |
14869 | inst.operands[1].reg = tmp; | |
88714cb8 | 14870 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14871 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14872 | } |
14873 | } | |
14874 | ||
627907b7 JB |
14875 | static void |
14876 | do_neon_rshl (void) | |
14877 | { | |
14878 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
14879 | struct neon_type_el et = neon_check_type (3, rs, | |
14880 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
14881 | unsigned int tmp; | |
14882 | ||
14883 | tmp = inst.operands[2].reg; | |
14884 | inst.operands[2].reg = inst.operands[1].reg; | |
14885 | inst.operands[1].reg = tmp; | |
14886 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
14887 | } | |
14888 | ||
5287ad62 JB |
14889 | static int |
14890 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
14891 | { | |
036dc3f7 PB |
14892 | /* Handle .I8 pseudo-instructions. */ |
14893 | if (size == 8) | |
5287ad62 | 14894 | { |
5287ad62 | 14895 | /* Unfortunately, this will make everything apart from zero out-of-range. |
477330fc RM |
14896 | FIXME is this the intended semantics? There doesn't seem much point in |
14897 | accepting .I8 if so. */ | |
5287ad62 JB |
14898 | immediate |= immediate << 8; |
14899 | size = 16; | |
036dc3f7 PB |
14900 | } |
14901 | ||
14902 | if (size >= 32) | |
14903 | { | |
14904 | if (immediate == (immediate & 0x000000ff)) | |
14905 | { | |
14906 | *immbits = immediate; | |
14907 | return 0x1; | |
14908 | } | |
14909 | else if (immediate == (immediate & 0x0000ff00)) | |
14910 | { | |
14911 | *immbits = immediate >> 8; | |
14912 | return 0x3; | |
14913 | } | |
14914 | else if (immediate == (immediate & 0x00ff0000)) | |
14915 | { | |
14916 | *immbits = immediate >> 16; | |
14917 | return 0x5; | |
14918 | } | |
14919 | else if (immediate == (immediate & 0xff000000)) | |
14920 | { | |
14921 | *immbits = immediate >> 24; | |
14922 | return 0x7; | |
14923 | } | |
14924 | if ((immediate & 0xffff) != (immediate >> 16)) | |
14925 | goto bad_immediate; | |
14926 | immediate &= 0xffff; | |
5287ad62 JB |
14927 | } |
14928 | ||
14929 | if (immediate == (immediate & 0x000000ff)) | |
14930 | { | |
14931 | *immbits = immediate; | |
036dc3f7 | 14932 | return 0x9; |
5287ad62 JB |
14933 | } |
14934 | else if (immediate == (immediate & 0x0000ff00)) | |
14935 | { | |
14936 | *immbits = immediate >> 8; | |
036dc3f7 | 14937 | return 0xb; |
5287ad62 JB |
14938 | } |
14939 | ||
14940 | bad_immediate: | |
dcbf9037 | 14941 | first_error (_("immediate value out of range")); |
5287ad62 JB |
14942 | return FAIL; |
14943 | } | |
14944 | ||
5287ad62 JB |
14945 | static void |
14946 | do_neon_logic (void) | |
14947 | { | |
14948 | if (inst.operands[2].present && inst.operands[2].isreg) | |
14949 | { | |
037e8744 | 14950 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14951 | neon_check_type (3, rs, N_IGNORE_TYPE); |
14952 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 14953 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14954 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14955 | } |
14956 | else | |
14957 | { | |
4316f0d2 DG |
14958 | const int three_ops_form = (inst.operands[2].present |
14959 | && !inst.operands[2].isreg); | |
14960 | const int immoperand = (three_ops_form ? 2 : 1); | |
14961 | enum neon_shape rs = (three_ops_form | |
14962 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
14963 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
037e8744 | 14964 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 14965 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); |
21d799b5 | 14966 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
14967 | unsigned immbits; |
14968 | int cmode; | |
5f4273c7 | 14969 | |
5287ad62 | 14970 | if (et.type == NT_invtype) |
477330fc | 14971 | return; |
5f4273c7 | 14972 | |
4316f0d2 DG |
14973 | if (three_ops_form) |
14974 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
14975 | _("first and second operands shall be the same register")); | |
14976 | ||
88714cb8 | 14977 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 14978 | |
4316f0d2 | 14979 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
14980 | if (et.size == 64) |
14981 | { | |
14982 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
14983 | pattern. */ | |
4316f0d2 DG |
14984 | if (immbits != (inst.operands[immoperand].regisimm ? |
14985 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
14986 | { |
14987 | /* Set immbits to an invalid constant. */ | |
14988 | immbits = 0xdeadbeef; | |
14989 | } | |
14990 | } | |
14991 | ||
5287ad62 | 14992 | switch (opcode) |
477330fc RM |
14993 | { |
14994 | case N_MNEM_vbic: | |
14995 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14996 | break; | |
14997 | ||
14998 | case N_MNEM_vorr: | |
14999 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15000 | break; | |
15001 | ||
15002 | case N_MNEM_vand: | |
15003 | /* Pseudo-instruction for VBIC. */ | |
15004 | neon_invert_size (&immbits, 0, et.size); | |
15005 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15006 | break; | |
15007 | ||
15008 | case N_MNEM_vorn: | |
15009 | /* Pseudo-instruction for VORR. */ | |
15010 | neon_invert_size (&immbits, 0, et.size); | |
15011 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
15012 | break; | |
15013 | ||
15014 | default: | |
15015 | abort (); | |
15016 | } | |
5287ad62 JB |
15017 | |
15018 | if (cmode == FAIL) | |
477330fc | 15019 | return; |
5287ad62 | 15020 | |
037e8744 | 15021 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15022 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15023 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15024 | inst.instruction |= cmode << 8; | |
15025 | neon_write_immbits (immbits); | |
5f4273c7 | 15026 | |
88714cb8 | 15027 | neon_dp_fixup (&inst); |
5287ad62 JB |
15028 | } |
15029 | } | |
15030 | ||
15031 | static void | |
15032 | do_neon_bitfield (void) | |
15033 | { | |
037e8744 | 15034 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 15035 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 15036 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
15037 | } |
15038 | ||
15039 | static void | |
dcbf9037 | 15040 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
477330fc | 15041 | unsigned destbits) |
5287ad62 | 15042 | { |
037e8744 | 15043 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 15044 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
477330fc | 15045 | types | N_KEY); |
5287ad62 JB |
15046 | if (et.type == NT_float) |
15047 | { | |
88714cb8 | 15048 | NEON_ENCODE (FLOAT, inst); |
cc933301 | 15049 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
15050 | } |
15051 | else | |
15052 | { | |
88714cb8 | 15053 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15054 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
15055 | } |
15056 | } | |
15057 | ||
15058 | static void | |
15059 | do_neon_dyadic_if_su (void) | |
15060 | { | |
dcbf9037 | 15061 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
15062 | } |
15063 | ||
15064 | static void | |
15065 | do_neon_dyadic_if_su_d (void) | |
15066 | { | |
15067 | /* This version only allow D registers, but that constraint is enforced during | |
15068 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 15069 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
15070 | } |
15071 | ||
5287ad62 JB |
15072 | static void |
15073 | do_neon_dyadic_if_i_d (void) | |
15074 | { | |
428e3f1f PB |
15075 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
15076 | affected if we specify unsigned args. */ | |
15077 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
15078 | } |
15079 | ||
037e8744 JB |
15080 | enum vfp_or_neon_is_neon_bits |
15081 | { | |
15082 | NEON_CHECK_CC = 1, | |
73924fbc MGD |
15083 | NEON_CHECK_ARCH = 2, |
15084 | NEON_CHECK_ARCH8 = 4 | |
037e8744 JB |
15085 | }; |
15086 | ||
15087 | /* Call this function if an instruction which may have belonged to the VFP or | |
15088 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
15089 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
15090 | things: | |
15091 | ||
15092 | - Make sure the user hasn't attempted to make a Neon instruction | |
15093 | conditional. | |
15094 | - Alter the value in the condition code field if necessary. | |
15095 | - Make sure that the arch supports Neon instructions. | |
15096 | ||
15097 | Which of these operations take place depends on bits from enum | |
15098 | vfp_or_neon_is_neon_bits. | |
15099 | ||
15100 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
15101 | current instruction's condition is COND_ALWAYS, the condition field is | |
15102 | changed to inst.uncond_value. This is necessary because instructions shared | |
15103 | between VFP and Neon may be conditional for the VFP variants only, and the | |
15104 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
15105 | ||
15106 | static int | |
15107 | vfp_or_neon_is_neon (unsigned check) | |
15108 | { | |
15109 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
15110 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
15111 | { | |
15112 | if (inst.cond != COND_ALWAYS) | |
477330fc RM |
15113 | { |
15114 | first_error (_(BAD_COND)); | |
15115 | return FAIL; | |
15116 | } | |
037e8744 | 15117 | if (inst.uncond_value != -1) |
477330fc | 15118 | inst.instruction |= inst.uncond_value << 28; |
037e8744 | 15119 | } |
5f4273c7 | 15120 | |
037e8744 | 15121 | if ((check & NEON_CHECK_ARCH) |
73924fbc MGD |
15122 | && !mark_feature_used (&fpu_neon_ext_v1)) |
15123 | { | |
15124 | first_error (_(BAD_FPU)); | |
15125 | return FAIL; | |
15126 | } | |
15127 | ||
15128 | if ((check & NEON_CHECK_ARCH8) | |
15129 | && !mark_feature_used (&fpu_neon_ext_armv8)) | |
037e8744 JB |
15130 | { |
15131 | first_error (_(BAD_FPU)); | |
15132 | return FAIL; | |
15133 | } | |
5f4273c7 | 15134 | |
037e8744 JB |
15135 | return SUCCESS; |
15136 | } | |
15137 | ||
5287ad62 JB |
15138 | static void |
15139 | do_neon_addsub_if_i (void) | |
15140 | { | |
037e8744 JB |
15141 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
15142 | return; | |
15143 | ||
15144 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15145 | return; | |
15146 | ||
5287ad62 JB |
15147 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
15148 | affected if we specify unsigned args. */ | |
dcbf9037 | 15149 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
15150 | } |
15151 | ||
15152 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
15153 | result to be: | |
15154 | V<op> A,B (A is operand 0, B is operand 2) | |
15155 | to mean: | |
15156 | V<op> A,B,A | |
15157 | not: | |
15158 | V<op> A,B,B | |
15159 | so handle that case specially. */ | |
15160 | ||
15161 | static void | |
15162 | neon_exchange_operands (void) | |
15163 | { | |
5287ad62 JB |
15164 | if (inst.operands[1].present) |
15165 | { | |
e1fa0163 NC |
15166 | void *scratch = xmalloc (sizeof (inst.operands[0])); |
15167 | ||
5287ad62 JB |
15168 | /* Swap operands[1] and operands[2]. */ |
15169 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
15170 | inst.operands[1] = inst.operands[2]; | |
15171 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
e1fa0163 | 15172 | free (scratch); |
5287ad62 JB |
15173 | } |
15174 | else | |
15175 | { | |
15176 | inst.operands[1] = inst.operands[2]; | |
15177 | inst.operands[2] = inst.operands[0]; | |
15178 | } | |
15179 | } | |
15180 | ||
15181 | static void | |
15182 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
15183 | { | |
15184 | if (inst.operands[2].isreg) | |
15185 | { | |
15186 | if (invert) | |
477330fc | 15187 | neon_exchange_operands (); |
dcbf9037 | 15188 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
15189 | } |
15190 | else | |
15191 | { | |
037e8744 | 15192 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 | 15193 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 15194 | N_EQK | N_SIZ, immtypes | N_KEY); |
5287ad62 | 15195 | |
88714cb8 | 15196 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15197 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15198 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15199 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15200 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15201 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15202 | inst.instruction |= (et.type == NT_float) << 10; |
15203 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15204 | |
88714cb8 | 15205 | neon_dp_fixup (&inst); |
5287ad62 JB |
15206 | } |
15207 | } | |
15208 | ||
15209 | static void | |
15210 | do_neon_cmp (void) | |
15211 | { | |
cc933301 | 15212 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE); |
5287ad62 JB |
15213 | } |
15214 | ||
15215 | static void | |
15216 | do_neon_cmp_inv (void) | |
15217 | { | |
cc933301 | 15218 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE); |
5287ad62 JB |
15219 | } |
15220 | ||
15221 | static void | |
15222 | do_neon_ceq (void) | |
15223 | { | |
15224 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
15225 | } | |
15226 | ||
15227 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
15228 | scalars, which are encoded in 5 bits, M : Rm. | |
15229 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
15230 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
c604a79a JW |
15231 | index in M. |
15232 | ||
15233 | Dot Product instructions are similar to multiply instructions except elsize | |
15234 | should always be 32. | |
15235 | ||
15236 | This function translates SCALAR, which is GAS's internal encoding of indexed | |
15237 | scalar register, to raw encoding. There is also register and index range | |
15238 | check based on ELSIZE. */ | |
5287ad62 JB |
15239 | |
15240 | static unsigned | |
15241 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
15242 | { | |
dcbf9037 JB |
15243 | unsigned regno = NEON_SCALAR_REG (scalar); |
15244 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
15245 | |
15246 | switch (elsize) | |
15247 | { | |
15248 | case 16: | |
15249 | if (regno > 7 || elno > 3) | |
477330fc | 15250 | goto bad_scalar; |
5287ad62 | 15251 | return regno | (elno << 3); |
5f4273c7 | 15252 | |
5287ad62 JB |
15253 | case 32: |
15254 | if (regno > 15 || elno > 1) | |
477330fc | 15255 | goto bad_scalar; |
5287ad62 JB |
15256 | return regno | (elno << 4); |
15257 | ||
15258 | default: | |
15259 | bad_scalar: | |
dcbf9037 | 15260 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
15261 | } |
15262 | ||
15263 | return 0; | |
15264 | } | |
15265 | ||
15266 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
15267 | ||
15268 | static void | |
15269 | neon_mul_mac (struct neon_type_el et, int ubit) | |
15270 | { | |
dcbf9037 JB |
15271 | unsigned scalar; |
15272 | ||
15273 | /* Give a more helpful error message if we have an invalid type. */ | |
15274 | if (et.type == NT_invtype) | |
15275 | return; | |
5f4273c7 | 15276 | |
dcbf9037 | 15277 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
15278 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15279 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15280 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15281 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15282 | inst.instruction |= LOW4 (scalar); | |
15283 | inst.instruction |= HI1 (scalar) << 5; | |
15284 | inst.instruction |= (et.type == NT_float) << 8; | |
15285 | inst.instruction |= neon_logbits (et.size) << 20; | |
15286 | inst.instruction |= (ubit != 0) << 24; | |
15287 | ||
88714cb8 | 15288 | neon_dp_fixup (&inst); |
5287ad62 JB |
15289 | } |
15290 | ||
15291 | static void | |
15292 | do_neon_mac_maybe_scalar (void) | |
15293 | { | |
037e8744 JB |
15294 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
15295 | return; | |
15296 | ||
15297 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15298 | return; | |
15299 | ||
5287ad62 JB |
15300 | if (inst.operands[2].isscalar) |
15301 | { | |
037e8744 | 15302 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 15303 | struct neon_type_el et = neon_check_type (3, rs, |
589a7d88 | 15304 | N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY); |
88714cb8 | 15305 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 15306 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
15307 | } |
15308 | else | |
428e3f1f PB |
15309 | { |
15310 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
15311 | affected if we specify unsigned args. */ | |
15312 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
15313 | } | |
5287ad62 JB |
15314 | } |
15315 | ||
62f3b8c8 PB |
15316 | static void |
15317 | do_neon_fmac (void) | |
15318 | { | |
15319 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
15320 | return; | |
15321 | ||
15322 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15323 | return; | |
15324 | ||
15325 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
15326 | } | |
15327 | ||
5287ad62 JB |
15328 | static void |
15329 | do_neon_tst (void) | |
15330 | { | |
037e8744 | 15331 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
15332 | struct neon_type_el et = neon_check_type (3, rs, |
15333 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 15334 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
15335 | } |
15336 | ||
15337 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
15338 | same types as the MAC equivalents. The polynomial type for this instruction | |
15339 | is encoded the same as the integer type. */ | |
15340 | ||
15341 | static void | |
15342 | do_neon_mul (void) | |
15343 | { | |
037e8744 JB |
15344 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
15345 | return; | |
15346 | ||
15347 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15348 | return; | |
15349 | ||
5287ad62 JB |
15350 | if (inst.operands[2].isscalar) |
15351 | do_neon_mac_maybe_scalar (); | |
15352 | else | |
cc933301 | 15353 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0); |
5287ad62 JB |
15354 | } |
15355 | ||
15356 | static void | |
15357 | do_neon_qdmulh (void) | |
15358 | { | |
15359 | if (inst.operands[2].isscalar) | |
15360 | { | |
037e8744 | 15361 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 15362 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15363 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 15364 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 15365 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
15366 | } |
15367 | else | |
15368 | { | |
037e8744 | 15369 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 15370 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15371 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 15372 | NEON_ENCODE (INTEGER, inst); |
5287ad62 | 15373 | /* The U bit (rounding) comes from bit mask. */ |
037e8744 | 15374 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
15375 | } |
15376 | } | |
15377 | ||
643afb90 MW |
15378 | static void |
15379 | do_neon_qrdmlah (void) | |
15380 | { | |
15381 | /* Check we're on the correct architecture. */ | |
15382 | if (!mark_feature_used (&fpu_neon_ext_armv8)) | |
15383 | inst.error = | |
15384 | _("instruction form not available on this architecture."); | |
15385 | else if (!mark_feature_used (&fpu_neon_ext_v8_1)) | |
15386 | { | |
15387 | as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD.")); | |
15388 | record_feature_use (&fpu_neon_ext_v8_1); | |
15389 | } | |
15390 | ||
15391 | if (inst.operands[2].isscalar) | |
15392 | { | |
15393 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
15394 | struct neon_type_el et = neon_check_type (3, rs, | |
15395 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
15396 | NEON_ENCODE (SCALAR, inst); | |
15397 | neon_mul_mac (et, neon_quad (rs)); | |
15398 | } | |
15399 | else | |
15400 | { | |
15401 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
15402 | struct neon_type_el et = neon_check_type (3, rs, | |
15403 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
15404 | NEON_ENCODE (INTEGER, inst); | |
15405 | /* The U bit (rounding) comes from bit mask. */ | |
15406 | neon_three_same (neon_quad (rs), 0, et.size); | |
15407 | } | |
15408 | } | |
15409 | ||
5287ad62 JB |
15410 | static void |
15411 | do_neon_fcmp_absolute (void) | |
15412 | { | |
037e8744 | 15413 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
15414 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
15415 | N_F_16_32 | N_KEY); | |
5287ad62 | 15416 | /* Size field comes from bit mask. */ |
cc933301 | 15417 | neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
15418 | } |
15419 | ||
15420 | static void | |
15421 | do_neon_fcmp_absolute_inv (void) | |
15422 | { | |
15423 | neon_exchange_operands (); | |
15424 | do_neon_fcmp_absolute (); | |
15425 | } | |
15426 | ||
15427 | static void | |
15428 | do_neon_step (void) | |
15429 | { | |
037e8744 | 15430 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
15431 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
15432 | N_F_16_32 | N_KEY); | |
15433 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); | |
5287ad62 JB |
15434 | } |
15435 | ||
15436 | static void | |
15437 | do_neon_abs_neg (void) | |
15438 | { | |
037e8744 JB |
15439 | enum neon_shape rs; |
15440 | struct neon_type_el et; | |
5f4273c7 | 15441 | |
037e8744 JB |
15442 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
15443 | return; | |
15444 | ||
15445 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15446 | return; | |
15447 | ||
15448 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
cc933301 | 15449 | et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY); |
5f4273c7 | 15450 | |
5287ad62 JB |
15451 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15452 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15453 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15454 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15455 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15456 | inst.instruction |= (et.type == NT_float) << 10; |
15457 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15458 | |
88714cb8 | 15459 | neon_dp_fixup (&inst); |
5287ad62 JB |
15460 | } |
15461 | ||
15462 | static void | |
15463 | do_neon_sli (void) | |
15464 | { | |
037e8744 | 15465 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15466 | struct neon_type_el et = neon_check_type (2, rs, |
15467 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15468 | int imm = inst.operands[2].imm; | |
15469 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 15470 | _("immediate out of range for insert")); |
037e8744 | 15471 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15472 | } |
15473 | ||
15474 | static void | |
15475 | do_neon_sri (void) | |
15476 | { | |
037e8744 | 15477 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15478 | struct neon_type_el et = neon_check_type (2, rs, |
15479 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15480 | int imm = inst.operands[2].imm; | |
15481 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15482 | _("immediate out of range for insert")); |
037e8744 | 15483 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
15484 | } |
15485 | ||
15486 | static void | |
15487 | do_neon_qshlu_imm (void) | |
15488 | { | |
037e8744 | 15489 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15490 | struct neon_type_el et = neon_check_type (2, rs, |
15491 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
15492 | int imm = inst.operands[2].imm; | |
15493 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 15494 | _("immediate out of range for shift")); |
5287ad62 JB |
15495 | /* Only encodes the 'U present' variant of the instruction. |
15496 | In this case, signed types have OP (bit 8) set to 0. | |
15497 | Unsigned types have OP set to 1. */ | |
15498 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
15499 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 15500 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15501 | } |
15502 | ||
15503 | static void | |
15504 | do_neon_qmovn (void) | |
15505 | { | |
15506 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15507 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15508 | /* Saturating move where operands can be signed or unsigned, and the | |
15509 | destination has the same signedness. */ | |
88714cb8 | 15510 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15511 | if (et.type == NT_unsigned) |
15512 | inst.instruction |= 0xc0; | |
15513 | else | |
15514 | inst.instruction |= 0x80; | |
15515 | neon_two_same (0, 1, et.size / 2); | |
15516 | } | |
15517 | ||
15518 | static void | |
15519 | do_neon_qmovun (void) | |
15520 | { | |
15521 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15522 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15523 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 15524 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15525 | neon_two_same (0, 1, et.size / 2); |
15526 | } | |
15527 | ||
15528 | static void | |
15529 | do_neon_rshift_sat_narrow (void) | |
15530 | { | |
15531 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15532 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15533 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15534 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15535 | int imm = inst.operands[2].imm; | |
15536 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15537 | right. */ | |
15538 | et.size /= 2; | |
5f4273c7 | 15539 | |
5287ad62 JB |
15540 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
15541 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
15542 | if (imm == 0) | |
15543 | { | |
15544 | inst.operands[2].present = 0; | |
15545 | inst.instruction = N_MNEM_vqmovn; | |
15546 | do_neon_qmovn (); | |
15547 | return; | |
15548 | } | |
5f4273c7 | 15549 | |
5287ad62 | 15550 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15551 | _("immediate out of range")); |
5287ad62 JB |
15552 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); |
15553 | } | |
15554 | ||
15555 | static void | |
15556 | do_neon_rshift_sat_narrow_u (void) | |
15557 | { | |
15558 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15559 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15560 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15561 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15562 | int imm = inst.operands[2].imm; | |
15563 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15564 | right. */ | |
15565 | et.size /= 2; | |
15566 | ||
15567 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
15568 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
15569 | if (imm == 0) | |
15570 | { | |
15571 | inst.operands[2].present = 0; | |
15572 | inst.instruction = N_MNEM_vqmovun; | |
15573 | do_neon_qmovun (); | |
15574 | return; | |
15575 | } | |
15576 | ||
15577 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15578 | _("immediate out of range")); |
5287ad62 JB |
15579 | /* FIXME: The manual is kind of unclear about what value U should have in |
15580 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
15581 | must be 1. */ | |
15582 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
15583 | } | |
15584 | ||
15585 | static void | |
15586 | do_neon_movn (void) | |
15587 | { | |
15588 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15589 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 15590 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15591 | neon_two_same (0, 1, et.size / 2); |
15592 | } | |
15593 | ||
15594 | static void | |
15595 | do_neon_rshift_narrow (void) | |
15596 | { | |
15597 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15598 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
15599 | int imm = inst.operands[2].imm; | |
15600 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15601 | right. */ | |
15602 | et.size /= 2; | |
5f4273c7 | 15603 | |
5287ad62 JB |
15604 | /* If immediate is zero then we are a pseudo-instruction for |
15605 | VMOVN.I<size> <Dd>, <Qm> */ | |
15606 | if (imm == 0) | |
15607 | { | |
15608 | inst.operands[2].present = 0; | |
15609 | inst.instruction = N_MNEM_vmovn; | |
15610 | do_neon_movn (); | |
15611 | return; | |
15612 | } | |
5f4273c7 | 15613 | |
5287ad62 | 15614 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15615 | _("immediate out of range for narrowing operation")); |
5287ad62 JB |
15616 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); |
15617 | } | |
15618 | ||
15619 | static void | |
15620 | do_neon_shll (void) | |
15621 | { | |
15622 | /* FIXME: Type checking when lengthening. */ | |
15623 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
15624 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
15625 | unsigned imm = inst.operands[2].imm; | |
15626 | ||
15627 | if (imm == et.size) | |
15628 | { | |
15629 | /* Maximum shift variant. */ | |
88714cb8 | 15630 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15631 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15632 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15633 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15634 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15635 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15636 | |
88714cb8 | 15637 | neon_dp_fixup (&inst); |
5287ad62 JB |
15638 | } |
15639 | else | |
15640 | { | |
15641 | /* A more-specific type check for non-max versions. */ | |
15642 | et = neon_check_type (2, NS_QDI, | |
477330fc | 15643 | N_EQK | N_DBL, N_SU_32 | N_KEY); |
88714cb8 | 15644 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15645 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
15646 | } | |
15647 | } | |
15648 | ||
037e8744 | 15649 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
15650 | the current instruction is. */ |
15651 | ||
6b9a8b67 MGD |
15652 | #define CVT_FLAVOUR_VAR \ |
15653 | CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \ | |
15654 | CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \ | |
15655 | CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \ | |
15656 | CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \ | |
15657 | /* Half-precision conversions. */ \ | |
cc933301 JW |
15658 | CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ |
15659 | CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ | |
15660 | CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \ | |
15661 | CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \ | |
6b9a8b67 MGD |
15662 | CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \ |
15663 | CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \ | |
9db2f6b4 RL |
15664 | /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \ |
15665 | Compared with single/double precision variants, only the co-processor \ | |
15666 | field is different, so the encoding flow is reused here. */ \ | |
15667 | CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \ | |
15668 | CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \ | |
15669 | CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\ | |
15670 | CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\ | |
6b9a8b67 MGD |
15671 | /* VFP instructions. */ \ |
15672 | CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \ | |
15673 | CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \ | |
15674 | CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \ | |
15675 | CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \ | |
15676 | CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \ | |
15677 | CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \ | |
15678 | /* VFP instructions with bitshift. */ \ | |
15679 | CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \ | |
15680 | CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \ | |
15681 | CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \ | |
15682 | CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \ | |
15683 | CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \ | |
15684 | CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \ | |
15685 | CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \ | |
15686 | CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL) | |
15687 | ||
15688 | #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \ | |
15689 | neon_cvt_flavour_##C, | |
15690 | ||
15691 | /* The different types of conversions we can do. */ | |
15692 | enum neon_cvt_flavour | |
15693 | { | |
15694 | CVT_FLAVOUR_VAR | |
15695 | neon_cvt_flavour_invalid, | |
15696 | neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64 | |
15697 | }; | |
15698 | ||
15699 | #undef CVT_VAR | |
15700 | ||
15701 | static enum neon_cvt_flavour | |
15702 | get_neon_cvt_flavour (enum neon_shape rs) | |
5287ad62 | 15703 | { |
6b9a8b67 MGD |
15704 | #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \ |
15705 | et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \ | |
15706 | if (et.type != NT_invtype) \ | |
15707 | { \ | |
15708 | inst.error = NULL; \ | |
15709 | return (neon_cvt_flavour_##C); \ | |
5287ad62 | 15710 | } |
6b9a8b67 | 15711 | |
5287ad62 | 15712 | struct neon_type_el et; |
037e8744 | 15713 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
477330fc | 15714 | || rs == NS_FF) ? N_VFP : 0; |
037e8744 JB |
15715 | /* The instruction versions which take an immediate take one register |
15716 | argument, which is extended to the width of the full register. Thus the | |
15717 | "source" and "destination" registers must have the same width. Hack that | |
15718 | here by making the size equal to the key (wider, in this case) operand. */ | |
15719 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 15720 | |
6b9a8b67 MGD |
15721 | CVT_FLAVOUR_VAR; |
15722 | ||
15723 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
15724 | #undef CVT_VAR |
15725 | } | |
15726 | ||
7e8e6784 MGD |
15727 | enum neon_cvt_mode |
15728 | { | |
15729 | neon_cvt_mode_a, | |
15730 | neon_cvt_mode_n, | |
15731 | neon_cvt_mode_p, | |
15732 | neon_cvt_mode_m, | |
15733 | neon_cvt_mode_z, | |
30bdf752 MGD |
15734 | neon_cvt_mode_x, |
15735 | neon_cvt_mode_r | |
7e8e6784 MGD |
15736 | }; |
15737 | ||
037e8744 JB |
15738 | /* Neon-syntax VFP conversions. */ |
15739 | ||
5287ad62 | 15740 | static void |
6b9a8b67 | 15741 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 15742 | { |
037e8744 | 15743 | const char *opname = 0; |
5f4273c7 | 15744 | |
d54af2d0 RL |
15745 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI |
15746 | || rs == NS_FHI || rs == NS_HFI) | |
5287ad62 | 15747 | { |
037e8744 JB |
15748 | /* Conversions with immediate bitshift. */ |
15749 | const char *enc[] = | |
477330fc | 15750 | { |
6b9a8b67 MGD |
15751 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
15752 | CVT_FLAVOUR_VAR | |
15753 | NULL | |
15754 | #undef CVT_VAR | |
477330fc | 15755 | }; |
037e8744 | 15756 | |
6b9a8b67 | 15757 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc RM |
15758 | { |
15759 | opname = enc[flavour]; | |
15760 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
15761 | _("operands 0 and 1 must be the same register")); | |
15762 | inst.operands[1] = inst.operands[2]; | |
15763 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
15764 | } | |
5287ad62 JB |
15765 | } |
15766 | else | |
15767 | { | |
037e8744 JB |
15768 | /* Conversions without bitshift. */ |
15769 | const char *enc[] = | |
477330fc | 15770 | { |
6b9a8b67 MGD |
15771 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
15772 | CVT_FLAVOUR_VAR | |
15773 | NULL | |
15774 | #undef CVT_VAR | |
477330fc | 15775 | }; |
037e8744 | 15776 | |
6b9a8b67 | 15777 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc | 15778 | opname = enc[flavour]; |
037e8744 JB |
15779 | } |
15780 | ||
15781 | if (opname) | |
15782 | do_vfp_nsyn_opcode (opname); | |
9db2f6b4 RL |
15783 | |
15784 | /* ARMv8.2 fp16 VCVT instruction. */ | |
15785 | if (flavour == neon_cvt_flavour_s32_f16 | |
15786 | || flavour == neon_cvt_flavour_u32_f16 | |
15787 | || flavour == neon_cvt_flavour_f16_u32 | |
15788 | || flavour == neon_cvt_flavour_f16_s32) | |
15789 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15790 | } |
15791 | ||
15792 | static void | |
15793 | do_vfp_nsyn_cvtz (void) | |
15794 | { | |
d54af2d0 | 15795 | enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL); |
6b9a8b67 | 15796 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
15797 | const char *enc[] = |
15798 | { | |
6b9a8b67 MGD |
15799 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
15800 | CVT_FLAVOUR_VAR | |
15801 | NULL | |
15802 | #undef CVT_VAR | |
037e8744 JB |
15803 | }; |
15804 | ||
6b9a8b67 | 15805 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
15806 | do_vfp_nsyn_opcode (enc[flavour]); |
15807 | } | |
f31fef98 | 15808 | |
037e8744 | 15809 | static void |
bacebabc | 15810 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
15811 | enum neon_cvt_mode mode) |
15812 | { | |
15813 | int sz, op; | |
15814 | int rm; | |
15815 | ||
a715796b TG |
15816 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
15817 | D register operands. */ | |
15818 | if (flavour == neon_cvt_flavour_s32_f64 | |
15819 | || flavour == neon_cvt_flavour_u32_f64) | |
15820 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15821 | _(BAD_FPU)); | |
15822 | ||
9db2f6b4 RL |
15823 | if (flavour == neon_cvt_flavour_s32_f16 |
15824 | || flavour == neon_cvt_flavour_u32_f16) | |
15825 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
15826 | _(BAD_FP16)); | |
15827 | ||
7e8e6784 MGD |
15828 | set_it_insn_type (OUTSIDE_IT_INSN); |
15829 | ||
15830 | switch (flavour) | |
15831 | { | |
15832 | case neon_cvt_flavour_s32_f64: | |
15833 | sz = 1; | |
827f64ff | 15834 | op = 1; |
7e8e6784 MGD |
15835 | break; |
15836 | case neon_cvt_flavour_s32_f32: | |
15837 | sz = 0; | |
15838 | op = 1; | |
15839 | break; | |
9db2f6b4 RL |
15840 | case neon_cvt_flavour_s32_f16: |
15841 | sz = 0; | |
15842 | op = 1; | |
15843 | break; | |
7e8e6784 MGD |
15844 | case neon_cvt_flavour_u32_f64: |
15845 | sz = 1; | |
15846 | op = 0; | |
15847 | break; | |
15848 | case neon_cvt_flavour_u32_f32: | |
15849 | sz = 0; | |
15850 | op = 0; | |
15851 | break; | |
9db2f6b4 RL |
15852 | case neon_cvt_flavour_u32_f16: |
15853 | sz = 0; | |
15854 | op = 0; | |
15855 | break; | |
7e8e6784 MGD |
15856 | default: |
15857 | first_error (_("invalid instruction shape")); | |
15858 | return; | |
15859 | } | |
15860 | ||
15861 | switch (mode) | |
15862 | { | |
15863 | case neon_cvt_mode_a: rm = 0; break; | |
15864 | case neon_cvt_mode_n: rm = 1; break; | |
15865 | case neon_cvt_mode_p: rm = 2; break; | |
15866 | case neon_cvt_mode_m: rm = 3; break; | |
15867 | default: first_error (_("invalid rounding mode")); return; | |
15868 | } | |
15869 | ||
15870 | NEON_ENCODE (FPV8, inst); | |
15871 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
15872 | encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm); | |
15873 | inst.instruction |= sz << 8; | |
9db2f6b4 RL |
15874 | |
15875 | /* ARMv8.2 fp16 VCVT instruction. */ | |
15876 | if (flavour == neon_cvt_flavour_s32_f16 | |
15877 | ||flavour == neon_cvt_flavour_u32_f16) | |
15878 | do_scalar_fp16_v82_encode (); | |
7e8e6784 MGD |
15879 | inst.instruction |= op << 7; |
15880 | inst.instruction |= rm << 16; | |
15881 | inst.instruction |= 0xf0000000; | |
15882 | inst.is_neon = TRUE; | |
15883 | } | |
15884 | ||
15885 | static void | |
15886 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
15887 | { |
15888 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
d54af2d0 RL |
15889 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, |
15890 | NS_FH, NS_HF, NS_FHI, NS_HFI, | |
15891 | NS_NULL); | |
6b9a8b67 | 15892 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 15893 | |
cc933301 JW |
15894 | if (flavour == neon_cvt_flavour_invalid) |
15895 | return; | |
15896 | ||
e3e535bc | 15897 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 15898 | if (mode == neon_cvt_mode_z |
e3e535bc | 15899 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
cc933301 JW |
15900 | && (flavour == neon_cvt_flavour_s16_f16 |
15901 | || flavour == neon_cvt_flavour_u16_f16 | |
15902 | || flavour == neon_cvt_flavour_s32_f32 | |
bacebabc RM |
15903 | || flavour == neon_cvt_flavour_u32_f32 |
15904 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 15905 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
15906 | && (rs == NS_FD || rs == NS_FF)) |
15907 | { | |
15908 | do_vfp_nsyn_cvtz (); | |
15909 | return; | |
15910 | } | |
15911 | ||
9db2f6b4 RL |
15912 | /* ARMv8.2 fp16 VCVT conversions. */ |
15913 | if (mode == neon_cvt_mode_z | |
15914 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16) | |
15915 | && (flavour == neon_cvt_flavour_s32_f16 | |
15916 | || flavour == neon_cvt_flavour_u32_f16) | |
15917 | && (rs == NS_FH)) | |
15918 | { | |
15919 | do_vfp_nsyn_cvtz (); | |
15920 | do_scalar_fp16_v82_encode (); | |
15921 | return; | |
15922 | } | |
15923 | ||
037e8744 | 15924 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 15925 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 15926 | { |
7e8e6784 MGD |
15927 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
15928 | do_vfp_nsyn_cvt (rs, flavour); | |
15929 | else | |
15930 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
15931 | ||
037e8744 JB |
15932 | return; |
15933 | } | |
15934 | ||
15935 | switch (rs) | |
15936 | { | |
15937 | case NS_DDI: | |
15938 | case NS_QQI: | |
15939 | { | |
477330fc | 15940 | unsigned immbits; |
cc933301 JW |
15941 | unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000, |
15942 | 0x0000100, 0x1000100, 0x0, 0x1000000}; | |
35997600 | 15943 | |
477330fc RM |
15944 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
15945 | return; | |
037e8744 | 15946 | |
477330fc RM |
15947 | /* Fixed-point conversion with #0 immediate is encoded as an |
15948 | integer conversion. */ | |
15949 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
15950 | goto int_encode; | |
477330fc RM |
15951 | NEON_ENCODE (IMMED, inst); |
15952 | if (flavour != neon_cvt_flavour_invalid) | |
15953 | inst.instruction |= enctab[flavour]; | |
15954 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15955 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15956 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15957 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15958 | inst.instruction |= neon_quad (rs) << 6; | |
15959 | inst.instruction |= 1 << 21; | |
cc933301 JW |
15960 | if (flavour < neon_cvt_flavour_s16_f16) |
15961 | { | |
15962 | inst.instruction |= 1 << 21; | |
15963 | immbits = 32 - inst.operands[2].imm; | |
15964 | inst.instruction |= immbits << 16; | |
15965 | } | |
15966 | else | |
15967 | { | |
15968 | inst.instruction |= 3 << 20; | |
15969 | immbits = 16 - inst.operands[2].imm; | |
15970 | inst.instruction |= immbits << 16; | |
15971 | inst.instruction &= ~(1 << 9); | |
15972 | } | |
477330fc RM |
15973 | |
15974 | neon_dp_fixup (&inst); | |
037e8744 JB |
15975 | } |
15976 | break; | |
15977 | ||
15978 | case NS_DD: | |
15979 | case NS_QQ: | |
7e8e6784 MGD |
15980 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
15981 | { | |
15982 | NEON_ENCODE (FLOAT, inst); | |
15983 | set_it_insn_type (OUTSIDE_IT_INSN); | |
15984 | ||
15985 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
15986 | return; | |
15987 | ||
15988 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15989 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15990 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15991 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15992 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
15993 | inst.instruction |= (flavour == neon_cvt_flavour_u16_f16 |
15994 | || flavour == neon_cvt_flavour_u32_f32) << 7; | |
7e8e6784 | 15995 | inst.instruction |= mode << 8; |
cc933301 JW |
15996 | if (flavour == neon_cvt_flavour_u16_f16 |
15997 | || flavour == neon_cvt_flavour_s16_f16) | |
15998 | /* Mask off the original size bits and reencode them. */ | |
15999 | inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18)); | |
16000 | ||
7e8e6784 MGD |
16001 | if (thumb_mode) |
16002 | inst.instruction |= 0xfc000000; | |
16003 | else | |
16004 | inst.instruction |= 0xf0000000; | |
16005 | } | |
16006 | else | |
16007 | { | |
037e8744 | 16008 | int_encode: |
7e8e6784 | 16009 | { |
cc933301 JW |
16010 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080, |
16011 | 0x100, 0x180, 0x0, 0x080}; | |
037e8744 | 16012 | |
7e8e6784 | 16013 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 16014 | |
7e8e6784 MGD |
16015 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16016 | return; | |
037e8744 | 16017 | |
7e8e6784 MGD |
16018 | if (flavour != neon_cvt_flavour_invalid) |
16019 | inst.instruction |= enctab[flavour]; | |
037e8744 | 16020 | |
7e8e6784 MGD |
16021 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16022 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16023 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16024 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16025 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
16026 | if (flavour >= neon_cvt_flavour_s16_f16 |
16027 | && flavour <= neon_cvt_flavour_f16_u16) | |
16028 | /* Half precision. */ | |
16029 | inst.instruction |= 1 << 18; | |
16030 | else | |
16031 | inst.instruction |= 2 << 18; | |
037e8744 | 16032 | |
7e8e6784 MGD |
16033 | neon_dp_fixup (&inst); |
16034 | } | |
16035 | } | |
16036 | break; | |
037e8744 | 16037 | |
8e79c3df CM |
16038 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
16039 | case NS_QD: | |
16040 | case NS_DQ: | |
bc52d49c MM |
16041 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16042 | return; | |
8e79c3df CM |
16043 | |
16044 | if ((rs == NS_DQ) | |
16045 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
16046 | { | |
16047 | as_bad (_("operand size must match register width")); | |
16048 | break; | |
16049 | } | |
16050 | ||
16051 | if ((rs == NS_QD) | |
16052 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
16053 | { | |
16054 | as_bad (_("operand size must match register width")); | |
16055 | break; | |
16056 | } | |
16057 | ||
16058 | if (rs == NS_DQ) | |
477330fc | 16059 | inst.instruction = 0x3b60600; |
8e79c3df CM |
16060 | else |
16061 | inst.instruction = 0x3b60700; | |
16062 | ||
16063 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16064 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16065 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16066 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 16067 | neon_dp_fixup (&inst); |
8e79c3df CM |
16068 | break; |
16069 | ||
037e8744 JB |
16070 | default: |
16071 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
16072 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
16073 | do_vfp_nsyn_cvt (rs, flavour); | |
16074 | else | |
16075 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
5287ad62 | 16076 | } |
5287ad62 JB |
16077 | } |
16078 | ||
e3e535bc NC |
16079 | static void |
16080 | do_neon_cvtr (void) | |
16081 | { | |
7e8e6784 | 16082 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
16083 | } |
16084 | ||
16085 | static void | |
16086 | do_neon_cvt (void) | |
16087 | { | |
7e8e6784 MGD |
16088 | do_neon_cvt_1 (neon_cvt_mode_z); |
16089 | } | |
16090 | ||
16091 | static void | |
16092 | do_neon_cvta (void) | |
16093 | { | |
16094 | do_neon_cvt_1 (neon_cvt_mode_a); | |
16095 | } | |
16096 | ||
16097 | static void | |
16098 | do_neon_cvtn (void) | |
16099 | { | |
16100 | do_neon_cvt_1 (neon_cvt_mode_n); | |
16101 | } | |
16102 | ||
16103 | static void | |
16104 | do_neon_cvtp (void) | |
16105 | { | |
16106 | do_neon_cvt_1 (neon_cvt_mode_p); | |
16107 | } | |
16108 | ||
16109 | static void | |
16110 | do_neon_cvtm (void) | |
16111 | { | |
16112 | do_neon_cvt_1 (neon_cvt_mode_m); | |
e3e535bc NC |
16113 | } |
16114 | ||
8e79c3df | 16115 | static void |
c70a8987 | 16116 | do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double) |
8e79c3df | 16117 | { |
c70a8987 MGD |
16118 | if (is_double) |
16119 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 16120 | |
c70a8987 MGD |
16121 | encode_arm_vfp_reg (inst.operands[0].reg, |
16122 | (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd); | |
16123 | encode_arm_vfp_reg (inst.operands[1].reg, | |
16124 | (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm); | |
16125 | inst.instruction |= to ? 0x10000 : 0; | |
16126 | inst.instruction |= t ? 0x80 : 0; | |
16127 | inst.instruction |= is_double ? 0x100 : 0; | |
16128 | do_vfp_cond_or_thumb (); | |
16129 | } | |
8e79c3df | 16130 | |
c70a8987 MGD |
16131 | static void |
16132 | do_neon_cvttb_1 (bfd_boolean t) | |
16133 | { | |
d54af2d0 RL |
16134 | enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD, |
16135 | NS_DF, NS_DH, NS_NULL); | |
8e79c3df | 16136 | |
c70a8987 MGD |
16137 | if (rs == NS_NULL) |
16138 | return; | |
16139 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) | |
16140 | { | |
16141 | inst.error = NULL; | |
16142 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE); | |
16143 | } | |
16144 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
16145 | { | |
16146 | inst.error = NULL; | |
16147 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE); | |
16148 | } | |
16149 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
16150 | { | |
a715796b TG |
16151 | /* The VCVTB and VCVTT instructions with D-register operands |
16152 | don't work for SP only targets. */ | |
16153 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16154 | _(BAD_FPU)); | |
16155 | ||
c70a8987 MGD |
16156 | inst.error = NULL; |
16157 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE); | |
16158 | } | |
16159 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
16160 | { | |
a715796b TG |
16161 | /* The VCVTB and VCVTT instructions with D-register operands |
16162 | don't work for SP only targets. */ | |
16163 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16164 | _(BAD_FPU)); | |
16165 | ||
c70a8987 MGD |
16166 | inst.error = NULL; |
16167 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE); | |
16168 | } | |
16169 | else | |
16170 | return; | |
16171 | } | |
16172 | ||
16173 | static void | |
16174 | do_neon_cvtb (void) | |
16175 | { | |
16176 | do_neon_cvttb_1 (FALSE); | |
8e79c3df CM |
16177 | } |
16178 | ||
16179 | ||
16180 | static void | |
16181 | do_neon_cvtt (void) | |
16182 | { | |
c70a8987 | 16183 | do_neon_cvttb_1 (TRUE); |
8e79c3df CM |
16184 | } |
16185 | ||
5287ad62 JB |
16186 | static void |
16187 | neon_move_immediate (void) | |
16188 | { | |
037e8744 JB |
16189 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
16190 | struct neon_type_el et = neon_check_type (2, rs, | |
16191 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 16192 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 16193 | int op, cmode, float_p; |
5287ad62 | 16194 | |
037e8744 | 16195 | constraint (et.type == NT_invtype, |
477330fc | 16196 | _("operand size must be specified for immediate VMOV")); |
037e8744 | 16197 | |
5287ad62 JB |
16198 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
16199 | op = (inst.instruction & (1 << 5)) != 0; | |
16200 | ||
16201 | immlo = inst.operands[1].imm; | |
16202 | if (inst.operands[1].regisimm) | |
16203 | immhi = inst.operands[1].reg; | |
16204 | ||
16205 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
477330fc | 16206 | _("immediate has bits set outside the operand size")); |
5287ad62 | 16207 | |
c96612cc JB |
16208 | float_p = inst.operands[1].immisfloat; |
16209 | ||
16210 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
477330fc | 16211 | et.size, et.type)) == FAIL) |
5287ad62 JB |
16212 | { |
16213 | /* Invert relevant bits only. */ | |
16214 | neon_invert_size (&immlo, &immhi, et.size); | |
16215 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
477330fc RM |
16216 | with one or the other; those cases are caught by |
16217 | neon_cmode_for_move_imm. */ | |
5287ad62 | 16218 | op = !op; |
c96612cc JB |
16219 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
16220 | &op, et.size, et.type)) == FAIL) | |
477330fc RM |
16221 | { |
16222 | first_error (_("immediate out of range")); | |
16223 | return; | |
16224 | } | |
5287ad62 JB |
16225 | } |
16226 | ||
16227 | inst.instruction &= ~(1 << 5); | |
16228 | inst.instruction |= op << 5; | |
16229 | ||
16230 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16231 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 16232 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16233 | inst.instruction |= cmode << 8; |
16234 | ||
16235 | neon_write_immbits (immbits); | |
16236 | } | |
16237 | ||
16238 | static void | |
16239 | do_neon_mvn (void) | |
16240 | { | |
16241 | if (inst.operands[1].isreg) | |
16242 | { | |
037e8744 | 16243 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 16244 | |
88714cb8 | 16245 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
16246 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16247 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16248 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16249 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 16250 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16251 | } |
16252 | else | |
16253 | { | |
88714cb8 | 16254 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
16255 | neon_move_immediate (); |
16256 | } | |
16257 | ||
88714cb8 | 16258 | neon_dp_fixup (&inst); |
5287ad62 JB |
16259 | } |
16260 | ||
16261 | /* Encode instructions of form: | |
16262 | ||
16263 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 16264 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
16265 | |
16266 | static void | |
16267 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
16268 | { | |
16269 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16270 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16271 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16272 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16273 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16274 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16275 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
16276 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 16277 | |
88714cb8 | 16278 | neon_dp_fixup (&inst); |
5287ad62 JB |
16279 | } |
16280 | ||
16281 | static void | |
16282 | do_neon_dyadic_long (void) | |
16283 | { | |
16284 | /* FIXME: Type checking for lengthening op. */ | |
16285 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16286 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
16287 | neon_mixed_length (et, et.size); | |
16288 | } | |
16289 | ||
16290 | static void | |
16291 | do_neon_abal (void) | |
16292 | { | |
16293 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16294 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
16295 | neon_mixed_length (et, et.size); | |
16296 | } | |
16297 | ||
16298 | static void | |
16299 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
16300 | { | |
16301 | if (inst.operands[2].isscalar) | |
16302 | { | |
dcbf9037 | 16303 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
477330fc | 16304 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); |
88714cb8 | 16305 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
16306 | neon_mul_mac (et, et.type == NT_unsigned); |
16307 | } | |
16308 | else | |
16309 | { | |
16310 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 16311 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); |
88714cb8 | 16312 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
16313 | neon_mixed_length (et, et.size); |
16314 | } | |
16315 | } | |
16316 | ||
16317 | static void | |
16318 | do_neon_mac_maybe_scalar_long (void) | |
16319 | { | |
16320 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
16321 | } | |
16322 | ||
dec41383 JW |
16323 | /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's |
16324 | internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */ | |
16325 | ||
16326 | static unsigned | |
16327 | neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p) | |
16328 | { | |
16329 | unsigned regno = NEON_SCALAR_REG (scalar); | |
16330 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
16331 | ||
16332 | if (quad_p) | |
16333 | { | |
16334 | if (regno > 7 || elno > 3) | |
16335 | goto bad_scalar; | |
16336 | ||
16337 | return ((regno & 0x7) | |
16338 | | ((elno & 0x1) << 3) | |
16339 | | (((elno >> 1) & 0x1) << 5)); | |
16340 | } | |
16341 | else | |
16342 | { | |
16343 | if (regno > 15 || elno > 1) | |
16344 | goto bad_scalar; | |
16345 | ||
16346 | return (((regno & 0x1) << 5) | |
16347 | | ((regno >> 1) & 0x7) | |
16348 | | ((elno & 0x1) << 3)); | |
16349 | } | |
16350 | ||
16351 | bad_scalar: | |
16352 | first_error (_("scalar out of range for multiply instruction")); | |
16353 | return 0; | |
16354 | } | |
16355 | ||
16356 | static void | |
16357 | do_neon_fmac_maybe_scalar_long (int subtype) | |
16358 | { | |
16359 | enum neon_shape rs; | |
16360 | int high8; | |
16361 | /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size" | |
16362 | field (bits[21:20]) has different meaning. For scalar index variant, it's | |
16363 | used to differentiate add and subtract, otherwise it's with fixed value | |
16364 | 0x2. */ | |
16365 | int size = -1; | |
16366 | ||
16367 | if (inst.cond != COND_ALWAYS) | |
16368 | as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the " | |
16369 | "behaviour is UNPREDICTABLE")); | |
16370 | ||
01f48020 | 16371 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml), |
dec41383 JW |
16372 | _(BAD_FP16)); |
16373 | ||
16374 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
16375 | _(BAD_FPU)); | |
16376 | ||
16377 | /* vfmal/vfmsl are in three-same D/Q register format or the third operand can | |
16378 | be a scalar index register. */ | |
16379 | if (inst.operands[2].isscalar) | |
16380 | { | |
16381 | high8 = 0xfe000000; | |
16382 | if (subtype) | |
16383 | size = 16; | |
16384 | rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL); | |
16385 | } | |
16386 | else | |
16387 | { | |
16388 | high8 = 0xfc000000; | |
16389 | size = 32; | |
16390 | if (subtype) | |
16391 | inst.instruction |= (0x1 << 23); | |
16392 | rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL); | |
16393 | } | |
16394 | ||
16395 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16); | |
16396 | ||
16397 | /* "opcode" from template has included "ubit", so simply pass 0 here. Also, | |
16398 | the "S" bit in size field has been reused to differentiate vfmal and vfmsl, | |
16399 | so we simply pass -1 as size. */ | |
16400 | unsigned quad_p = (rs == NS_QDD || rs == NS_QDS); | |
16401 | neon_three_same (quad_p, 0, size); | |
16402 | ||
16403 | /* Undo neon_dp_fixup. Redo the high eight bits. */ | |
16404 | inst.instruction &= 0x00ffffff; | |
16405 | inst.instruction |= high8; | |
16406 | ||
16407 | #define LOW1(R) ((R) & 0x1) | |
16408 | #define HI4(R) (((R) >> 1) & 0xf) | |
16409 | /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on | |
16410 | whether the instruction is in Q form and whether Vm is a scalar indexed | |
16411 | operand. */ | |
16412 | if (inst.operands[2].isscalar) | |
16413 | { | |
16414 | unsigned rm | |
16415 | = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p); | |
16416 | inst.instruction &= 0xffffffd0; | |
16417 | inst.instruction |= rm; | |
16418 | ||
16419 | if (!quad_p) | |
16420 | { | |
16421 | /* Redo Rn as well. */ | |
16422 | inst.instruction &= 0xfff0ff7f; | |
16423 | inst.instruction |= HI4 (inst.operands[1].reg) << 16; | |
16424 | inst.instruction |= LOW1 (inst.operands[1].reg) << 7; | |
16425 | } | |
16426 | } | |
16427 | else if (!quad_p) | |
16428 | { | |
16429 | /* Redo Rn and Rm. */ | |
16430 | inst.instruction &= 0xfff0ff50; | |
16431 | inst.instruction |= HI4 (inst.operands[1].reg) << 16; | |
16432 | inst.instruction |= LOW1 (inst.operands[1].reg) << 7; | |
16433 | inst.instruction |= HI4 (inst.operands[2].reg); | |
16434 | inst.instruction |= LOW1 (inst.operands[2].reg) << 5; | |
16435 | } | |
16436 | } | |
16437 | ||
16438 | static void | |
16439 | do_neon_vfmal (void) | |
16440 | { | |
16441 | return do_neon_fmac_maybe_scalar_long (0); | |
16442 | } | |
16443 | ||
16444 | static void | |
16445 | do_neon_vfmsl (void) | |
16446 | { | |
16447 | return do_neon_fmac_maybe_scalar_long (1); | |
16448 | } | |
16449 | ||
5287ad62 JB |
16450 | static void |
16451 | do_neon_dyadic_wide (void) | |
16452 | { | |
16453 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
16454 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
16455 | neon_mixed_length (et, et.size); | |
16456 | } | |
16457 | ||
16458 | static void | |
16459 | do_neon_dyadic_narrow (void) | |
16460 | { | |
16461 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16462 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
16463 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
16464 | so force the operand type to integer. */ | |
16465 | et.type = NT_integer; | |
5287ad62 JB |
16466 | neon_mixed_length (et, et.size / 2); |
16467 | } | |
16468 | ||
16469 | static void | |
16470 | do_neon_mul_sat_scalar_long (void) | |
16471 | { | |
16472 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
16473 | } | |
16474 | ||
16475 | static void | |
16476 | do_neon_vmull (void) | |
16477 | { | |
16478 | if (inst.operands[2].isscalar) | |
16479 | do_neon_mac_maybe_scalar_long (); | |
16480 | else | |
16481 | { | |
16482 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 16483 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
4f51b4bd | 16484 | |
5287ad62 | 16485 | if (et.type == NT_poly) |
477330fc | 16486 | NEON_ENCODE (POLY, inst); |
5287ad62 | 16487 | else |
477330fc | 16488 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
16489 | |
16490 | /* For polynomial encoding the U bit must be zero, and the size must | |
16491 | be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non | |
16492 | obviously, as 0b10). */ | |
16493 | if (et.size == 64) | |
16494 | { | |
16495 | /* Check we're on the correct architecture. */ | |
16496 | if (!mark_feature_used (&fpu_crypto_ext_armv8)) | |
16497 | inst.error = | |
16498 | _("Instruction form not available on this architecture."); | |
16499 | ||
16500 | et.size = 32; | |
16501 | } | |
16502 | ||
5287ad62 JB |
16503 | neon_mixed_length (et, et.size); |
16504 | } | |
16505 | } | |
16506 | ||
16507 | static void | |
16508 | do_neon_ext (void) | |
16509 | { | |
037e8744 | 16510 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
16511 | struct neon_type_el et = neon_check_type (3, rs, |
16512 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
16513 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
16514 | |
16515 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
16516 | _("shift out of range")); | |
5287ad62 JB |
16517 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16518 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16519 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16520 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16521 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16522 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 16523 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 16524 | inst.instruction |= imm << 8; |
5f4273c7 | 16525 | |
88714cb8 | 16526 | neon_dp_fixup (&inst); |
5287ad62 JB |
16527 | } |
16528 | ||
16529 | static void | |
16530 | do_neon_rev (void) | |
16531 | { | |
037e8744 | 16532 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16533 | struct neon_type_el et = neon_check_type (2, rs, |
16534 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
16535 | unsigned op = (inst.instruction >> 7) & 3; | |
16536 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
16537 | extract it here to check the elements to be reversed are smaller. | |
16538 | Otherwise we'd get a reserved instruction. */ | |
16539 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 16540 | gas_assert (elsize != 0); |
5287ad62 | 16541 | constraint (et.size >= elsize, |
477330fc | 16542 | _("elements must be smaller than reversal region")); |
037e8744 | 16543 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16544 | } |
16545 | ||
16546 | static void | |
16547 | do_neon_dup (void) | |
16548 | { | |
16549 | if (inst.operands[1].isscalar) | |
16550 | { | |
037e8744 | 16551 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 | 16552 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 16553 | N_EQK, N_8 | N_16 | N_32 | N_KEY); |
5287ad62 | 16554 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 16555 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 16556 | int logsize = neon_logbits (et.size); |
dcbf9037 | 16557 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
16558 | |
16559 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
477330fc | 16560 | return; |
037e8744 | 16561 | |
88714cb8 | 16562 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
16563 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16564 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16565 | inst.instruction |= LOW4 (dm); | |
16566 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 16567 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16568 | inst.instruction |= x << 17; |
16569 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 16570 | |
88714cb8 | 16571 | neon_dp_fixup (&inst); |
5287ad62 JB |
16572 | } |
16573 | else | |
16574 | { | |
037e8744 JB |
16575 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
16576 | struct neon_type_el et = neon_check_type (2, rs, | |
477330fc | 16577 | N_8 | N_16 | N_32 | N_KEY, N_EQK); |
5287ad62 | 16578 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 16579 | NEON_ENCODE (ARMREG, inst); |
5287ad62 | 16580 | switch (et.size) |
477330fc RM |
16581 | { |
16582 | case 8: inst.instruction |= 0x400000; break; | |
16583 | case 16: inst.instruction |= 0x000020; break; | |
16584 | case 32: inst.instruction |= 0x000000; break; | |
16585 | default: break; | |
16586 | } | |
5287ad62 JB |
16587 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; |
16588 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
16589 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 16590 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 | 16591 | /* The encoding for this instruction is identical for the ARM and Thumb |
477330fc | 16592 | variants, except for the condition field. */ |
037e8744 | 16593 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
16594 | } |
16595 | } | |
16596 | ||
16597 | /* VMOV has particularly many variations. It can be one of: | |
16598 | 0. VMOV<c><q> <Qd>, <Qm> | |
16599 | 1. VMOV<c><q> <Dd>, <Dm> | |
16600 | (Register operations, which are VORR with Rm = Rn.) | |
16601 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
16602 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
16603 | (Immediate loads.) | |
16604 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
16605 | (ARM register to scalar.) | |
16606 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
16607 | (Two ARM registers to vector.) | |
16608 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
16609 | (Scalar to ARM register.) | |
16610 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
16611 | (Vector to two ARM registers.) | |
037e8744 JB |
16612 | 8. VMOV.F32 <Sd>, <Sm> |
16613 | 9. VMOV.F64 <Dd>, <Dm> | |
16614 | (VFP register moves.) | |
16615 | 10. VMOV.F32 <Sd>, #imm | |
16616 | 11. VMOV.F64 <Dd>, #imm | |
16617 | (VFP float immediate load.) | |
16618 | 12. VMOV <Rd>, <Sm> | |
16619 | (VFP single to ARM reg.) | |
16620 | 13. VMOV <Sd>, <Rm> | |
16621 | (ARM reg to VFP single.) | |
16622 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
16623 | (Two ARM regs to two VFP singles.) | |
16624 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
16625 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 16626 | |
037e8744 JB |
16627 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
16628 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 16629 | |
5287ad62 | 16630 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 16631 | |
b7fc2769 JB |
16632 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
16633 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 16634 | |
5287ad62 | 16635 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 16636 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
16637 | |
16638 | static void | |
16639 | do_neon_mov (void) | |
16640 | { | |
037e8744 | 16641 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
9db2f6b4 RL |
16642 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, |
16643 | NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
16644 | NS_HR, NS_RH, NS_HI, NS_NULL); | |
037e8744 JB |
16645 | struct neon_type_el et; |
16646 | const char *ldconst = 0; | |
5287ad62 | 16647 | |
037e8744 | 16648 | switch (rs) |
5287ad62 | 16649 | { |
037e8744 JB |
16650 | case NS_DD: /* case 1/9. */ |
16651 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
16652 | /* It is not an error here if no type is given. */ | |
16653 | inst.error = NULL; | |
16654 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
16655 | { |
16656 | do_vfp_nsyn_opcode ("fcpyd"); | |
16657 | break; | |
16658 | } | |
037e8744 | 16659 | /* fall through. */ |
5287ad62 | 16660 | |
037e8744 JB |
16661 | case NS_QQ: /* case 0/1. */ |
16662 | { | |
477330fc RM |
16663 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16664 | return; | |
16665 | /* The architecture manual I have doesn't explicitly state which | |
16666 | value the U bit should have for register->register moves, but | |
16667 | the equivalent VORR instruction has U = 0, so do that. */ | |
16668 | inst.instruction = 0x0200110; | |
16669 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16670 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16671 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16672 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16673 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16674 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16675 | inst.instruction |= neon_quad (rs) << 6; | |
16676 | ||
16677 | neon_dp_fixup (&inst); | |
037e8744 JB |
16678 | } |
16679 | break; | |
5f4273c7 | 16680 | |
037e8744 JB |
16681 | case NS_DI: /* case 3/11. */ |
16682 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
16683 | inst.error = NULL; | |
16684 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
16685 | { |
16686 | /* case 11 (fconstd). */ | |
16687 | ldconst = "fconstd"; | |
16688 | goto encode_fconstd; | |
16689 | } | |
037e8744 JB |
16690 | /* fall through. */ |
16691 | ||
16692 | case NS_QI: /* case 2/3. */ | |
16693 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
477330fc | 16694 | return; |
037e8744 JB |
16695 | inst.instruction = 0x0800010; |
16696 | neon_move_immediate (); | |
88714cb8 | 16697 | neon_dp_fixup (&inst); |
5287ad62 | 16698 | break; |
5f4273c7 | 16699 | |
037e8744 JB |
16700 | case NS_SR: /* case 4. */ |
16701 | { | |
477330fc RM |
16702 | unsigned bcdebits = 0; |
16703 | int logsize; | |
16704 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
16705 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
037e8744 | 16706 | |
05ac0ffb JB |
16707 | /* .<size> is optional here, defaulting to .32. */ |
16708 | if (inst.vectype.elems == 0 | |
16709 | && inst.operands[0].vectype.type == NT_invtype | |
16710 | && inst.operands[1].vectype.type == NT_invtype) | |
16711 | { | |
16712 | inst.vectype.el[0].type = NT_untyped; | |
16713 | inst.vectype.el[0].size = 32; | |
16714 | inst.vectype.elems = 1; | |
16715 | } | |
16716 | ||
477330fc RM |
16717 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
16718 | logsize = neon_logbits (et.size); | |
16719 | ||
16720 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
16721 | _(BAD_FPU)); | |
16722 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
16723 | && et.size != 32, _(BAD_FPU)); | |
16724 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
16725 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
16726 | ||
16727 | switch (et.size) | |
16728 | { | |
16729 | case 8: bcdebits = 0x8; break; | |
16730 | case 16: bcdebits = 0x1; break; | |
16731 | case 32: bcdebits = 0x0; break; | |
16732 | default: ; | |
16733 | } | |
16734 | ||
16735 | bcdebits |= x << logsize; | |
16736 | ||
16737 | inst.instruction = 0xe000b10; | |
16738 | do_vfp_cond_or_thumb (); | |
16739 | inst.instruction |= LOW4 (dn) << 16; | |
16740 | inst.instruction |= HI1 (dn) << 7; | |
16741 | inst.instruction |= inst.operands[1].reg << 12; | |
16742 | inst.instruction |= (bcdebits & 3) << 5; | |
16743 | inst.instruction |= (bcdebits >> 2) << 21; | |
037e8744 JB |
16744 | } |
16745 | break; | |
5f4273c7 | 16746 | |
037e8744 | 16747 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 16748 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
477330fc | 16749 | _(BAD_FPU)); |
b7fc2769 | 16750 | |
037e8744 JB |
16751 | inst.instruction = 0xc400b10; |
16752 | do_vfp_cond_or_thumb (); | |
16753 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
16754 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
16755 | inst.instruction |= inst.operands[1].reg << 12; | |
16756 | inst.instruction |= inst.operands[2].reg << 16; | |
16757 | break; | |
5f4273c7 | 16758 | |
037e8744 JB |
16759 | case NS_RS: /* case 6. */ |
16760 | { | |
477330fc RM |
16761 | unsigned logsize; |
16762 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
16763 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
16764 | unsigned abcdebits = 0; | |
037e8744 | 16765 | |
05ac0ffb JB |
16766 | /* .<dt> is optional here, defaulting to .32. */ |
16767 | if (inst.vectype.elems == 0 | |
16768 | && inst.operands[0].vectype.type == NT_invtype | |
16769 | && inst.operands[1].vectype.type == NT_invtype) | |
16770 | { | |
16771 | inst.vectype.el[0].type = NT_untyped; | |
16772 | inst.vectype.el[0].size = 32; | |
16773 | inst.vectype.elems = 1; | |
16774 | } | |
16775 | ||
91d6fa6a NC |
16776 | et = neon_check_type (2, NS_NULL, |
16777 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
477330fc RM |
16778 | logsize = neon_logbits (et.size); |
16779 | ||
16780 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
16781 | _(BAD_FPU)); | |
16782 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
16783 | && et.size != 32, _(BAD_FPU)); | |
16784 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
16785 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
16786 | ||
16787 | switch (et.size) | |
16788 | { | |
16789 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
16790 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
16791 | case 32: abcdebits = 0x00; break; | |
16792 | default: ; | |
16793 | } | |
16794 | ||
16795 | abcdebits |= x << logsize; | |
16796 | inst.instruction = 0xe100b10; | |
16797 | do_vfp_cond_or_thumb (); | |
16798 | inst.instruction |= LOW4 (dn) << 16; | |
16799 | inst.instruction |= HI1 (dn) << 7; | |
16800 | inst.instruction |= inst.operands[0].reg << 12; | |
16801 | inst.instruction |= (abcdebits & 3) << 5; | |
16802 | inst.instruction |= (abcdebits >> 2) << 21; | |
037e8744 JB |
16803 | } |
16804 | break; | |
5f4273c7 | 16805 | |
037e8744 JB |
16806 | case NS_RRD: /* case 7 (fmrrd). */ |
16807 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
477330fc | 16808 | _(BAD_FPU)); |
037e8744 JB |
16809 | |
16810 | inst.instruction = 0xc500b10; | |
16811 | do_vfp_cond_or_thumb (); | |
16812 | inst.instruction |= inst.operands[0].reg << 12; | |
16813 | inst.instruction |= inst.operands[1].reg << 16; | |
16814 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16815 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16816 | break; | |
5f4273c7 | 16817 | |
037e8744 JB |
16818 | case NS_FF: /* case 8 (fcpys). */ |
16819 | do_vfp_nsyn_opcode ("fcpys"); | |
16820 | break; | |
5f4273c7 | 16821 | |
9db2f6b4 | 16822 | case NS_HI: |
037e8744 JB |
16823 | case NS_FI: /* case 10 (fconsts). */ |
16824 | ldconst = "fconsts"; | |
4ef4710f | 16825 | encode_fconstd: |
58ed5c38 TC |
16826 | if (!inst.operands[1].immisfloat) |
16827 | { | |
4ef4710f | 16828 | unsigned new_imm; |
58ed5c38 | 16829 | /* Immediate has to fit in 8 bits so float is enough. */ |
4ef4710f NC |
16830 | float imm = (float) inst.operands[1].imm; |
16831 | memcpy (&new_imm, &imm, sizeof (float)); | |
16832 | /* But the assembly may have been written to provide an integer | |
16833 | bit pattern that equates to a float, so check that the | |
16834 | conversion has worked. */ | |
16835 | if (is_quarter_float (new_imm)) | |
16836 | { | |
16837 | if (is_quarter_float (inst.operands[1].imm)) | |
16838 | as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)")); | |
16839 | ||
16840 | inst.operands[1].imm = new_imm; | |
16841 | inst.operands[1].immisfloat = 1; | |
16842 | } | |
58ed5c38 TC |
16843 | } |
16844 | ||
037e8744 | 16845 | if (is_quarter_float (inst.operands[1].imm)) |
477330fc RM |
16846 | { |
16847 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); | |
16848 | do_vfp_nsyn_opcode (ldconst); | |
9db2f6b4 RL |
16849 | |
16850 | /* ARMv8.2 fp16 vmov.f16 instruction. */ | |
16851 | if (rs == NS_HI) | |
16852 | do_scalar_fp16_v82_encode (); | |
477330fc | 16853 | } |
5287ad62 | 16854 | else |
477330fc | 16855 | first_error (_("immediate out of range")); |
037e8744 | 16856 | break; |
5f4273c7 | 16857 | |
9db2f6b4 | 16858 | case NS_RH: |
037e8744 JB |
16859 | case NS_RF: /* case 12 (fmrs). */ |
16860 | do_vfp_nsyn_opcode ("fmrs"); | |
9db2f6b4 RL |
16861 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
16862 | if (rs == NS_RH) | |
16863 | do_scalar_fp16_v82_encode (); | |
037e8744 | 16864 | break; |
5f4273c7 | 16865 | |
9db2f6b4 | 16866 | case NS_HR: |
037e8744 JB |
16867 | case NS_FR: /* case 13 (fmsr). */ |
16868 | do_vfp_nsyn_opcode ("fmsr"); | |
9db2f6b4 RL |
16869 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
16870 | if (rs == NS_HR) | |
16871 | do_scalar_fp16_v82_encode (); | |
037e8744 | 16872 | break; |
5f4273c7 | 16873 | |
037e8744 JB |
16874 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
16875 | (one of which is a list), but we have parsed four. Do some fiddling to | |
16876 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
16877 | expect. */ | |
16878 | case NS_RRFF: /* case 14 (fmrrs). */ | |
16879 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
477330fc | 16880 | _("VFP registers must be adjacent")); |
037e8744 JB |
16881 | inst.operands[2].imm = 2; |
16882 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
16883 | do_vfp_nsyn_opcode ("fmrrs"); | |
16884 | break; | |
5f4273c7 | 16885 | |
037e8744 JB |
16886 | case NS_FFRR: /* case 15 (fmsrr). */ |
16887 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
477330fc | 16888 | _("VFP registers must be adjacent")); |
037e8744 JB |
16889 | inst.operands[1] = inst.operands[2]; |
16890 | inst.operands[2] = inst.operands[3]; | |
16891 | inst.operands[0].imm = 2; | |
16892 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
16893 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 16894 | break; |
5f4273c7 | 16895 | |
4c261dff NC |
16896 | case NS_NULL: |
16897 | /* neon_select_shape has determined that the instruction | |
16898 | shape is wrong and has already set the error message. */ | |
16899 | break; | |
16900 | ||
5287ad62 JB |
16901 | default: |
16902 | abort (); | |
16903 | } | |
16904 | } | |
16905 | ||
16906 | static void | |
16907 | do_neon_rshift_round_imm (void) | |
16908 | { | |
037e8744 | 16909 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
16910 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
16911 | int imm = inst.operands[2].imm; | |
16912 | ||
16913 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
16914 | if (imm == 0) | |
16915 | { | |
16916 | inst.operands[2].present = 0; | |
16917 | do_neon_mov (); | |
16918 | return; | |
16919 | } | |
16920 | ||
16921 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 16922 | _("immediate out of range for shift")); |
037e8744 | 16923 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
477330fc | 16924 | et.size - imm); |
5287ad62 JB |
16925 | } |
16926 | ||
9db2f6b4 RL |
16927 | static void |
16928 | do_neon_movhf (void) | |
16929 | { | |
16930 | enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL); | |
16931 | constraint (rs != NS_HH, _("invalid suffix")); | |
16932 | ||
7bdf778b ASDV |
16933 | if (inst.cond != COND_ALWAYS) |
16934 | { | |
16935 | if (thumb_mode) | |
16936 | { | |
16937 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," | |
16938 | " the behaviour is UNPREDICTABLE")); | |
16939 | } | |
16940 | else | |
16941 | { | |
16942 | inst.error = BAD_COND; | |
16943 | return; | |
16944 | } | |
16945 | } | |
16946 | ||
9db2f6b4 RL |
16947 | do_vfp_sp_monadic (); |
16948 | ||
16949 | inst.is_neon = 1; | |
16950 | inst.instruction |= 0xf0000000; | |
16951 | } | |
16952 | ||
5287ad62 JB |
16953 | static void |
16954 | do_neon_movl (void) | |
16955 | { | |
16956 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
16957 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
16958 | unsigned sizebits = et.size >> 3; | |
16959 | inst.instruction |= sizebits << 19; | |
16960 | neon_two_same (0, et.type == NT_unsigned, -1); | |
16961 | } | |
16962 | ||
16963 | static void | |
16964 | do_neon_trn (void) | |
16965 | { | |
037e8744 | 16966 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16967 | struct neon_type_el et = neon_check_type (2, rs, |
16968 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 16969 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 16970 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16971 | } |
16972 | ||
16973 | static void | |
16974 | do_neon_zip_uzp (void) | |
16975 | { | |
037e8744 | 16976 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16977 | struct neon_type_el et = neon_check_type (2, rs, |
16978 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
16979 | if (rs == NS_DD && et.size == 32) | |
16980 | { | |
16981 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
16982 | inst.instruction = N_MNEM_vtrn; | |
16983 | do_neon_trn (); | |
16984 | return; | |
16985 | } | |
037e8744 | 16986 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16987 | } |
16988 | ||
16989 | static void | |
16990 | do_neon_sat_abs_neg (void) | |
16991 | { | |
037e8744 | 16992 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16993 | struct neon_type_el et = neon_check_type (2, rs, |
16994 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 16995 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16996 | } |
16997 | ||
16998 | static void | |
16999 | do_neon_pair_long (void) | |
17000 | { | |
037e8744 | 17001 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17002 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
17003 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
17004 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 17005 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17006 | } |
17007 | ||
17008 | static void | |
17009 | do_neon_recip_est (void) | |
17010 | { | |
037e8744 | 17011 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 | 17012 | struct neon_type_el et = neon_check_type (2, rs, |
cc933301 | 17013 | N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY); |
5287ad62 | 17014 | inst.instruction |= (et.type == NT_float) << 8; |
037e8744 | 17015 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17016 | } |
17017 | ||
17018 | static void | |
17019 | do_neon_cls (void) | |
17020 | { | |
037e8744 | 17021 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17022 | struct neon_type_el et = neon_check_type (2, rs, |
17023 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 17024 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17025 | } |
17026 | ||
17027 | static void | |
17028 | do_neon_clz (void) | |
17029 | { | |
037e8744 | 17030 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17031 | struct neon_type_el et = neon_check_type (2, rs, |
17032 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 17033 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17034 | } |
17035 | ||
17036 | static void | |
17037 | do_neon_cnt (void) | |
17038 | { | |
037e8744 | 17039 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
17040 | struct neon_type_el et = neon_check_type (2, rs, |
17041 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 17042 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
17043 | } |
17044 | ||
17045 | static void | |
17046 | do_neon_swp (void) | |
17047 | { | |
037e8744 JB |
17048 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
17049 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
17050 | } |
17051 | ||
17052 | static void | |
17053 | do_neon_tbl_tbx (void) | |
17054 | { | |
17055 | unsigned listlenbits; | |
dcbf9037 | 17056 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 17057 | |
5287ad62 JB |
17058 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
17059 | { | |
dcbf9037 | 17060 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
17061 | return; |
17062 | } | |
5f4273c7 | 17063 | |
5287ad62 JB |
17064 | listlenbits = inst.operands[1].imm - 1; |
17065 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17066 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17067 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
17068 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
17069 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
17070 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
17071 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 17072 | |
88714cb8 | 17073 | neon_dp_fixup (&inst); |
5287ad62 JB |
17074 | } |
17075 | ||
17076 | static void | |
17077 | do_neon_ldm_stm (void) | |
17078 | { | |
17079 | /* P, U and L bits are part of bitmask. */ | |
17080 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
17081 | unsigned offsetbits = inst.operands[1].imm * 2; | |
17082 | ||
037e8744 JB |
17083 | if (inst.operands[1].issingle) |
17084 | { | |
17085 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
17086 | return; | |
17087 | } | |
17088 | ||
5287ad62 | 17089 | constraint (is_dbmode && !inst.operands[0].writeback, |
477330fc | 17090 | _("writeback (!) must be used for VLDMDB and VSTMDB")); |
5287ad62 JB |
17091 | |
17092 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
477330fc RM |
17093 | _("register list must contain at least 1 and at most 16 " |
17094 | "registers")); | |
5287ad62 JB |
17095 | |
17096 | inst.instruction |= inst.operands[0].reg << 16; | |
17097 | inst.instruction |= inst.operands[0].writeback << 21; | |
17098 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
17099 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
17100 | ||
17101 | inst.instruction |= offsetbits; | |
5f4273c7 | 17102 | |
037e8744 | 17103 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
17104 | } |
17105 | ||
17106 | static void | |
17107 | do_neon_ldr_str (void) | |
17108 | { | |
5287ad62 | 17109 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 17110 | |
6844b2c2 MGD |
17111 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
17112 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 17113 | if (!is_ldr |
6844b2c2 | 17114 | && inst.operands[1].reg == REG_PC |
ba86b375 | 17115 | && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode)) |
6844b2c2 | 17116 | { |
94dcf8bf | 17117 | if (thumb_mode) |
6844b2c2 | 17118 | inst.error = _("Use of PC here is UNPREDICTABLE"); |
94dcf8bf | 17119 | else if (warn_on_deprecated) |
5c3696f8 | 17120 | as_tsktsk (_("Use of PC here is deprecated")); |
6844b2c2 MGD |
17121 | } |
17122 | ||
037e8744 JB |
17123 | if (inst.operands[0].issingle) |
17124 | { | |
cd2f129f | 17125 | if (is_ldr) |
477330fc | 17126 | do_vfp_nsyn_opcode ("flds"); |
cd2f129f | 17127 | else |
477330fc | 17128 | do_vfp_nsyn_opcode ("fsts"); |
9db2f6b4 RL |
17129 | |
17130 | /* ARMv8.2 vldr.16/vstr.16 instruction. */ | |
17131 | if (inst.vectype.el[0].size == 16) | |
17132 | do_scalar_fp16_v82_encode (); | |
5287ad62 JB |
17133 | } |
17134 | else | |
5287ad62 | 17135 | { |
cd2f129f | 17136 | if (is_ldr) |
477330fc | 17137 | do_vfp_nsyn_opcode ("fldd"); |
5287ad62 | 17138 | else |
477330fc | 17139 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 17140 | } |
5287ad62 JB |
17141 | } |
17142 | ||
17143 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
17144 | instructions. */ | |
17145 | ||
17146 | static void | |
17147 | do_neon_ld_st_interleave (void) | |
17148 | { | |
037e8744 | 17149 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
477330fc | 17150 | N_8 | N_16 | N_32 | N_64); |
5287ad62 JB |
17151 | unsigned alignbits = 0; |
17152 | unsigned idx; | |
17153 | /* The bits in this table go: | |
17154 | 0: register stride of one (0) or two (1) | |
17155 | 1,2: register list length, minus one (1, 2, 3, 4). | |
17156 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
17157 | We use -1 for invalid entries. */ | |
17158 | const int typetable[] = | |
17159 | { | |
17160 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
17161 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
17162 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
17163 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
17164 | }; | |
17165 | int typebits; | |
17166 | ||
dcbf9037 JB |
17167 | if (et.type == NT_invtype) |
17168 | return; | |
17169 | ||
5287ad62 JB |
17170 | if (inst.operands[1].immisalign) |
17171 | switch (inst.operands[1].imm >> 8) | |
17172 | { | |
17173 | case 64: alignbits = 1; break; | |
17174 | case 128: | |
477330fc | 17175 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
e23c0ad8 | 17176 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
477330fc RM |
17177 | goto bad_alignment; |
17178 | alignbits = 2; | |
17179 | break; | |
5287ad62 | 17180 | case 256: |
477330fc RM |
17181 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
17182 | goto bad_alignment; | |
17183 | alignbits = 3; | |
17184 | break; | |
5287ad62 JB |
17185 | default: |
17186 | bad_alignment: | |
477330fc RM |
17187 | first_error (_("bad alignment")); |
17188 | return; | |
5287ad62 JB |
17189 | } |
17190 | ||
17191 | inst.instruction |= alignbits << 4; | |
17192 | inst.instruction |= neon_logbits (et.size) << 6; | |
17193 | ||
17194 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
17195 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
17196 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
17197 | up the right value for "type" in a table based on this value and the given | |
17198 | list style, then stick it back. */ | |
17199 | idx = ((inst.operands[0].imm >> 4) & 7) | |
477330fc | 17200 | | (((inst.instruction >> 8) & 3) << 3); |
5287ad62 JB |
17201 | |
17202 | typebits = typetable[idx]; | |
5f4273c7 | 17203 | |
5287ad62 | 17204 | constraint (typebits == -1, _("bad list type for instruction")); |
1d50d57c WN |
17205 | constraint (((inst.instruction >> 8) & 3) && et.size == 64, |
17206 | _("bad element type for instruction")); | |
5287ad62 JB |
17207 | |
17208 | inst.instruction &= ~0xf00; | |
17209 | inst.instruction |= typebits << 8; | |
17210 | } | |
17211 | ||
17212 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
17213 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
17214 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
17215 | values, terminated with -1. */ | |
17216 | ||
17217 | static int | |
aa8a0863 | 17218 | neon_alignment_bit (int size, int align, int *do_alignment, ...) |
5287ad62 JB |
17219 | { |
17220 | va_list ap; | |
17221 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 17222 | |
5287ad62 JB |
17223 | if (!inst.operands[1].immisalign) |
17224 | { | |
aa8a0863 | 17225 | *do_alignment = 0; |
5287ad62 JB |
17226 | return SUCCESS; |
17227 | } | |
5f4273c7 | 17228 | |
aa8a0863 | 17229 | va_start (ap, do_alignment); |
5287ad62 JB |
17230 | |
17231 | do | |
17232 | { | |
17233 | thissize = va_arg (ap, int); | |
17234 | if (thissize == -1) | |
477330fc | 17235 | break; |
5287ad62 JB |
17236 | thisalign = va_arg (ap, int); |
17237 | ||
17238 | if (size == thissize && align == thisalign) | |
477330fc | 17239 | result = SUCCESS; |
5287ad62 JB |
17240 | } |
17241 | while (result != SUCCESS); | |
17242 | ||
17243 | va_end (ap); | |
17244 | ||
17245 | if (result == SUCCESS) | |
aa8a0863 | 17246 | *do_alignment = 1; |
5287ad62 | 17247 | else |
dcbf9037 | 17248 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 17249 | |
5287ad62 JB |
17250 | return result; |
17251 | } | |
17252 | ||
17253 | static void | |
17254 | do_neon_ld_st_lane (void) | |
17255 | { | |
037e8744 | 17256 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 17257 | int align_good, do_alignment = 0; |
5287ad62 JB |
17258 | int logsize = neon_logbits (et.size); |
17259 | int align = inst.operands[1].imm >> 8; | |
17260 | int n = (inst.instruction >> 8) & 3; | |
17261 | int max_el = 64 / et.size; | |
5f4273c7 | 17262 | |
dcbf9037 JB |
17263 | if (et.type == NT_invtype) |
17264 | return; | |
5f4273c7 | 17265 | |
5287ad62 | 17266 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
477330fc | 17267 | _("bad list length")); |
5287ad62 | 17268 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, |
477330fc | 17269 | _("scalar index out of range")); |
5287ad62 | 17270 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 |
477330fc RM |
17271 | && et.size == 8, |
17272 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 17273 | |
5287ad62 JB |
17274 | switch (n) |
17275 | { | |
17276 | case 0: /* VLD1 / VST1. */ | |
aa8a0863 | 17277 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16, |
477330fc | 17278 | 32, 32, -1); |
5287ad62 | 17279 | if (align_good == FAIL) |
477330fc | 17280 | return; |
aa8a0863 | 17281 | if (do_alignment) |
477330fc RM |
17282 | { |
17283 | unsigned alignbits = 0; | |
17284 | switch (et.size) | |
17285 | { | |
17286 | case 16: alignbits = 0x1; break; | |
17287 | case 32: alignbits = 0x3; break; | |
17288 | default: ; | |
17289 | } | |
17290 | inst.instruction |= alignbits << 4; | |
17291 | } | |
5287ad62 JB |
17292 | break; |
17293 | ||
17294 | case 1: /* VLD2 / VST2. */ | |
aa8a0863 TS |
17295 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16, |
17296 | 16, 32, 32, 64, -1); | |
5287ad62 | 17297 | if (align_good == FAIL) |
477330fc | 17298 | return; |
aa8a0863 | 17299 | if (do_alignment) |
477330fc | 17300 | inst.instruction |= 1 << 4; |
5287ad62 JB |
17301 | break; |
17302 | ||
17303 | case 2: /* VLD3 / VST3. */ | |
17304 | constraint (inst.operands[1].immisalign, | |
477330fc | 17305 | _("can't use alignment with this instruction")); |
5287ad62 JB |
17306 | break; |
17307 | ||
17308 | case 3: /* VLD4 / VST4. */ | |
aa8a0863 | 17309 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc | 17310 | 16, 64, 32, 64, 32, 128, -1); |
5287ad62 | 17311 | if (align_good == FAIL) |
477330fc | 17312 | return; |
aa8a0863 | 17313 | if (do_alignment) |
477330fc RM |
17314 | { |
17315 | unsigned alignbits = 0; | |
17316 | switch (et.size) | |
17317 | { | |
17318 | case 8: alignbits = 0x1; break; | |
17319 | case 16: alignbits = 0x1; break; | |
17320 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
17321 | default: ; | |
17322 | } | |
17323 | inst.instruction |= alignbits << 4; | |
17324 | } | |
5287ad62 JB |
17325 | break; |
17326 | ||
17327 | default: ; | |
17328 | } | |
17329 | ||
17330 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
17331 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
17332 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 17333 | |
5287ad62 JB |
17334 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
17335 | inst.instruction |= logsize << 10; | |
17336 | } | |
17337 | ||
17338 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
17339 | ||
17340 | static void | |
17341 | do_neon_ld_dup (void) | |
17342 | { | |
037e8744 | 17343 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 17344 | int align_good, do_alignment = 0; |
5287ad62 | 17345 | |
dcbf9037 JB |
17346 | if (et.type == NT_invtype) |
17347 | return; | |
17348 | ||
5287ad62 JB |
17349 | switch ((inst.instruction >> 8) & 3) |
17350 | { | |
17351 | case 0: /* VLD1. */ | |
9c2799c2 | 17352 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 | 17353 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
aa8a0863 | 17354 | &do_alignment, 16, 16, 32, 32, -1); |
5287ad62 | 17355 | if (align_good == FAIL) |
477330fc | 17356 | return; |
5287ad62 | 17357 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) |
477330fc RM |
17358 | { |
17359 | case 1: break; | |
17360 | case 2: inst.instruction |= 1 << 5; break; | |
17361 | default: first_error (_("bad list length")); return; | |
17362 | } | |
5287ad62 JB |
17363 | inst.instruction |= neon_logbits (et.size) << 6; |
17364 | break; | |
17365 | ||
17366 | case 1: /* VLD2. */ | |
17367 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
aa8a0863 TS |
17368 | &do_alignment, 8, 16, 16, 32, 32, 64, |
17369 | -1); | |
5287ad62 | 17370 | if (align_good == FAIL) |
477330fc | 17371 | return; |
5287ad62 | 17372 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, |
477330fc | 17373 | _("bad list length")); |
5287ad62 | 17374 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 17375 | inst.instruction |= 1 << 5; |
5287ad62 JB |
17376 | inst.instruction |= neon_logbits (et.size) << 6; |
17377 | break; | |
17378 | ||
17379 | case 2: /* VLD3. */ | |
17380 | constraint (inst.operands[1].immisalign, | |
477330fc | 17381 | _("can't use alignment with this instruction")); |
5287ad62 | 17382 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, |
477330fc | 17383 | _("bad list length")); |
5287ad62 | 17384 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 17385 | inst.instruction |= 1 << 5; |
5287ad62 JB |
17386 | inst.instruction |= neon_logbits (et.size) << 6; |
17387 | break; | |
17388 | ||
17389 | case 3: /* VLD4. */ | |
17390 | { | |
477330fc | 17391 | int align = inst.operands[1].imm >> 8; |
aa8a0863 | 17392 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc RM |
17393 | 16, 64, 32, 64, 32, 128, -1); |
17394 | if (align_good == FAIL) | |
17395 | return; | |
17396 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
17397 | _("bad list length")); | |
17398 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
17399 | inst.instruction |= 1 << 5; | |
17400 | if (et.size == 32 && align == 128) | |
17401 | inst.instruction |= 0x3 << 6; | |
17402 | else | |
17403 | inst.instruction |= neon_logbits (et.size) << 6; | |
5287ad62 JB |
17404 | } |
17405 | break; | |
17406 | ||
17407 | default: ; | |
17408 | } | |
17409 | ||
aa8a0863 | 17410 | inst.instruction |= do_alignment << 4; |
5287ad62 JB |
17411 | } |
17412 | ||
17413 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
17414 | apart from bits [11:4]. */ | |
17415 | ||
17416 | static void | |
17417 | do_neon_ldx_stx (void) | |
17418 | { | |
b1a769ed DG |
17419 | if (inst.operands[1].isreg) |
17420 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
17421 | ||
5287ad62 JB |
17422 | switch (NEON_LANE (inst.operands[0].imm)) |
17423 | { | |
17424 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 17425 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
17426 | do_neon_ld_st_interleave (); |
17427 | break; | |
5f4273c7 | 17428 | |
5287ad62 | 17429 | case NEON_ALL_LANES: |
88714cb8 | 17430 | NEON_ENCODE (DUP, inst); |
2d51fb74 JB |
17431 | if (inst.instruction == N_INV) |
17432 | { | |
17433 | first_error ("only loads support such operands"); | |
17434 | break; | |
17435 | } | |
5287ad62 JB |
17436 | do_neon_ld_dup (); |
17437 | break; | |
5f4273c7 | 17438 | |
5287ad62 | 17439 | default: |
88714cb8 | 17440 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
17441 | do_neon_ld_st_lane (); |
17442 | } | |
17443 | ||
17444 | /* L bit comes from bit mask. */ | |
17445 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17446 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17447 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 17448 | |
5287ad62 JB |
17449 | if (inst.operands[1].postind) |
17450 | { | |
17451 | int postreg = inst.operands[1].imm & 0xf; | |
17452 | constraint (!inst.operands[1].immisreg, | |
477330fc | 17453 | _("post-index must be a register")); |
5287ad62 | 17454 | constraint (postreg == 0xd || postreg == 0xf, |
477330fc | 17455 | _("bad register for post-index")); |
5287ad62 JB |
17456 | inst.instruction |= postreg; |
17457 | } | |
4f2374c7 | 17458 | else |
5287ad62 | 17459 | { |
4f2374c7 | 17460 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); |
e2b0ab59 AV |
17461 | constraint (inst.relocs[0].exp.X_op != O_constant |
17462 | || inst.relocs[0].exp.X_add_number != 0, | |
4f2374c7 WN |
17463 | BAD_ADDR_MODE); |
17464 | ||
17465 | if (inst.operands[1].writeback) | |
17466 | { | |
17467 | inst.instruction |= 0xd; | |
17468 | } | |
17469 | else | |
17470 | inst.instruction |= 0xf; | |
5287ad62 | 17471 | } |
5f4273c7 | 17472 | |
5287ad62 JB |
17473 | if (thumb_mode) |
17474 | inst.instruction |= 0xf9000000; | |
17475 | else | |
17476 | inst.instruction |= 0xf4000000; | |
17477 | } | |
33399f07 MGD |
17478 | |
17479 | /* FP v8. */ | |
17480 | static void | |
17481 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
17482 | { | |
a715796b TG |
17483 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
17484 | D register operands. */ | |
17485 | if (neon_shape_class[rs] == SC_DOUBLE) | |
17486 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17487 | _(BAD_FPU)); | |
17488 | ||
33399f07 MGD |
17489 | NEON_ENCODE (FPV8, inst); |
17490 | ||
9db2f6b4 RL |
17491 | if (rs == NS_FFF || rs == NS_HHH) |
17492 | { | |
17493 | do_vfp_sp_dyadic (); | |
17494 | ||
17495 | /* ARMv8.2 fp16 instruction. */ | |
17496 | if (rs == NS_HHH) | |
17497 | do_scalar_fp16_v82_encode (); | |
17498 | } | |
33399f07 MGD |
17499 | else |
17500 | do_vfp_dp_rd_rn_rm (); | |
17501 | ||
17502 | if (rs == NS_DDD) | |
17503 | inst.instruction |= 0x100; | |
17504 | ||
17505 | inst.instruction |= 0xf0000000; | |
17506 | } | |
17507 | ||
17508 | static void | |
17509 | do_vsel (void) | |
17510 | { | |
17511 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17512 | ||
17513 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
17514 | first_error (_("invalid instruction shape")); | |
17515 | } | |
17516 | ||
73924fbc MGD |
17517 | static void |
17518 | do_vmaxnm (void) | |
17519 | { | |
17520 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17521 | ||
17522 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
17523 | return; | |
17524 | ||
17525 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
17526 | return; | |
17527 | ||
cc933301 | 17528 | neon_dyadic_misc (NT_untyped, N_F_16_32, 0); |
73924fbc MGD |
17529 | } |
17530 | ||
30bdf752 MGD |
17531 | static void |
17532 | do_vrint_1 (enum neon_cvt_mode mode) | |
17533 | { | |
9db2f6b4 | 17534 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL); |
30bdf752 MGD |
17535 | struct neon_type_el et; |
17536 | ||
17537 | if (rs == NS_NULL) | |
17538 | return; | |
17539 | ||
a715796b TG |
17540 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
17541 | D register operands. */ | |
17542 | if (neon_shape_class[rs] == SC_DOUBLE) | |
17543 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17544 | _(BAD_FPU)); | |
17545 | ||
9db2f6b4 RL |
17546 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY |
17547 | | N_VFP); | |
30bdf752 MGD |
17548 | if (et.type != NT_invtype) |
17549 | { | |
17550 | /* VFP encodings. */ | |
17551 | if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n | |
17552 | || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m) | |
17553 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17554 | ||
17555 | NEON_ENCODE (FPV8, inst); | |
9db2f6b4 | 17556 | if (rs == NS_FF || rs == NS_HH) |
30bdf752 MGD |
17557 | do_vfp_sp_monadic (); |
17558 | else | |
17559 | do_vfp_dp_rd_rm (); | |
17560 | ||
17561 | switch (mode) | |
17562 | { | |
17563 | case neon_cvt_mode_r: inst.instruction |= 0x00000000; break; | |
17564 | case neon_cvt_mode_z: inst.instruction |= 0x00000080; break; | |
17565 | case neon_cvt_mode_x: inst.instruction |= 0x00010000; break; | |
17566 | case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break; | |
17567 | case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break; | |
17568 | case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break; | |
17569 | case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break; | |
17570 | default: abort (); | |
17571 | } | |
17572 | ||
17573 | inst.instruction |= (rs == NS_DD) << 8; | |
17574 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
17575 | |
17576 | /* ARMv8.2 fp16 vrint instruction. */ | |
17577 | if (rs == NS_HH) | |
17578 | do_scalar_fp16_v82_encode (); | |
30bdf752 MGD |
17579 | } |
17580 | else | |
17581 | { | |
17582 | /* Neon encodings (or something broken...). */ | |
17583 | inst.error = NULL; | |
cc933301 | 17584 | et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY); |
30bdf752 MGD |
17585 | |
17586 | if (et.type == NT_invtype) | |
17587 | return; | |
17588 | ||
17589 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17590 | NEON_ENCODE (FLOAT, inst); | |
17591 | ||
17592 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
17593 | return; | |
17594 | ||
17595 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17596 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17597 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
17598 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
17599 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
17600 | /* Mask off the original size bits and reencode them. */ |
17601 | inst.instruction = ((inst.instruction & 0xfff3ffff) | |
17602 | | neon_logbits (et.size) << 18); | |
17603 | ||
30bdf752 MGD |
17604 | switch (mode) |
17605 | { | |
17606 | case neon_cvt_mode_z: inst.instruction |= 3 << 7; break; | |
17607 | case neon_cvt_mode_x: inst.instruction |= 1 << 7; break; | |
17608 | case neon_cvt_mode_a: inst.instruction |= 2 << 7; break; | |
17609 | case neon_cvt_mode_n: inst.instruction |= 0 << 7; break; | |
17610 | case neon_cvt_mode_p: inst.instruction |= 7 << 7; break; | |
17611 | case neon_cvt_mode_m: inst.instruction |= 5 << 7; break; | |
17612 | case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break; | |
17613 | default: abort (); | |
17614 | } | |
17615 | ||
17616 | if (thumb_mode) | |
17617 | inst.instruction |= 0xfc000000; | |
17618 | else | |
17619 | inst.instruction |= 0xf0000000; | |
17620 | } | |
17621 | } | |
17622 | ||
17623 | static void | |
17624 | do_vrintx (void) | |
17625 | { | |
17626 | do_vrint_1 (neon_cvt_mode_x); | |
17627 | } | |
17628 | ||
17629 | static void | |
17630 | do_vrintz (void) | |
17631 | { | |
17632 | do_vrint_1 (neon_cvt_mode_z); | |
17633 | } | |
17634 | ||
17635 | static void | |
17636 | do_vrintr (void) | |
17637 | { | |
17638 | do_vrint_1 (neon_cvt_mode_r); | |
17639 | } | |
17640 | ||
17641 | static void | |
17642 | do_vrinta (void) | |
17643 | { | |
17644 | do_vrint_1 (neon_cvt_mode_a); | |
17645 | } | |
17646 | ||
17647 | static void | |
17648 | do_vrintn (void) | |
17649 | { | |
17650 | do_vrint_1 (neon_cvt_mode_n); | |
17651 | } | |
17652 | ||
17653 | static void | |
17654 | do_vrintp (void) | |
17655 | { | |
17656 | do_vrint_1 (neon_cvt_mode_p); | |
17657 | } | |
17658 | ||
17659 | static void | |
17660 | do_vrintm (void) | |
17661 | { | |
17662 | do_vrint_1 (neon_cvt_mode_m); | |
17663 | } | |
17664 | ||
c28eeff2 SN |
17665 | static unsigned |
17666 | neon_scalar_for_vcmla (unsigned opnd, unsigned elsize) | |
17667 | { | |
17668 | unsigned regno = NEON_SCALAR_REG (opnd); | |
17669 | unsigned elno = NEON_SCALAR_INDEX (opnd); | |
17670 | ||
17671 | if (elsize == 16 && elno < 2 && regno < 16) | |
17672 | return regno | (elno << 4); | |
17673 | else if (elsize == 32 && elno == 0) | |
17674 | return regno; | |
17675 | ||
17676 | first_error (_("scalar out of range")); | |
17677 | return 0; | |
17678 | } | |
17679 | ||
17680 | static void | |
17681 | do_vcmla (void) | |
17682 | { | |
17683 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
17684 | _(BAD_FPU)); | |
e2b0ab59 AV |
17685 | constraint (inst.relocs[0].exp.X_op != O_constant, |
17686 | _("expression too complex")); | |
17687 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
c28eeff2 SN |
17688 | constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270, |
17689 | _("immediate out of range")); | |
17690 | rot /= 90; | |
17691 | if (inst.operands[2].isscalar) | |
17692 | { | |
17693 | enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL); | |
17694 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
17695 | N_KEY | N_F16 | N_F32).size; | |
17696 | unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size); | |
17697 | inst.is_neon = 1; | |
17698 | inst.instruction = 0xfe000800; | |
17699 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17700 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17701 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
17702 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
17703 | inst.instruction |= LOW4 (m); | |
17704 | inst.instruction |= HI1 (m) << 5; | |
17705 | inst.instruction |= neon_quad (rs) << 6; | |
17706 | inst.instruction |= rot << 20; | |
17707 | inst.instruction |= (size == 32) << 23; | |
17708 | } | |
17709 | else | |
17710 | { | |
17711 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); | |
17712 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
17713 | N_KEY | N_F16 | N_F32).size; | |
17714 | neon_three_same (neon_quad (rs), 0, -1); | |
17715 | inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */ | |
17716 | inst.instruction |= 0xfc200800; | |
17717 | inst.instruction |= rot << 23; | |
17718 | inst.instruction |= (size == 32) << 20; | |
17719 | } | |
17720 | } | |
17721 | ||
17722 | static void | |
17723 | do_vcadd (void) | |
17724 | { | |
17725 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
17726 | _(BAD_FPU)); | |
e2b0ab59 AV |
17727 | constraint (inst.relocs[0].exp.X_op != O_constant, |
17728 | _("expression too complex")); | |
17729 | unsigned rot = inst.relocs[0].exp.X_add_number; | |
c28eeff2 SN |
17730 | constraint (rot != 90 && rot != 270, _("immediate out of range")); |
17731 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); | |
17732 | unsigned size = neon_check_type (3, rs, N_EQK, N_EQK, | |
17733 | N_KEY | N_F16 | N_F32).size; | |
17734 | neon_three_same (neon_quad (rs), 0, -1); | |
17735 | inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */ | |
17736 | inst.instruction |= 0xfc800800; | |
17737 | inst.instruction |= (rot == 270) << 24; | |
17738 | inst.instruction |= (size == 32) << 20; | |
17739 | } | |
17740 | ||
c604a79a JW |
17741 | /* Dot Product instructions encoding support. */ |
17742 | ||
17743 | static void | |
17744 | do_neon_dotproduct (int unsigned_p) | |
17745 | { | |
17746 | enum neon_shape rs; | |
17747 | unsigned scalar_oprd2 = 0; | |
17748 | int high8; | |
17749 | ||
17750 | if (inst.cond != COND_ALWAYS) | |
17751 | as_warn (_("Dot Product instructions cannot be conditional, the behaviour " | |
17752 | "is UNPREDICTABLE")); | |
17753 | ||
17754 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8), | |
17755 | _(BAD_FPU)); | |
17756 | ||
17757 | /* Dot Product instructions are in three-same D/Q register format or the third | |
17758 | operand can be a scalar index register. */ | |
17759 | if (inst.operands[2].isscalar) | |
17760 | { | |
17761 | scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32); | |
17762 | high8 = 0xfe000000; | |
17763 | rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
17764 | } | |
17765 | else | |
17766 | { | |
17767 | high8 = 0xfc000000; | |
17768 | rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
17769 | } | |
17770 | ||
17771 | if (unsigned_p) | |
17772 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8); | |
17773 | else | |
17774 | neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8); | |
17775 | ||
17776 | /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot | |
17777 | Product instruction, so we pass 0 as the "ubit" parameter. And the | |
17778 | "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */ | |
17779 | neon_three_same (neon_quad (rs), 0, 32); | |
17780 | ||
17781 | /* Undo neon_dp_fixup. Dot Product instructions are using a slightly | |
17782 | different NEON three-same encoding. */ | |
17783 | inst.instruction &= 0x00ffffff; | |
17784 | inst.instruction |= high8; | |
17785 | /* Encode 'U' bit which indicates signedness. */ | |
17786 | inst.instruction |= (unsigned_p ? 1 : 0) << 4; | |
17787 | /* Re-encode operand2 if it's indexed scalar operand. What has been encoded | |
17788 | from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not | |
17789 | the instruction encoding. */ | |
17790 | if (inst.operands[2].isscalar) | |
17791 | { | |
17792 | inst.instruction &= 0xffffffd0; | |
17793 | inst.instruction |= LOW4 (scalar_oprd2); | |
17794 | inst.instruction |= HI1 (scalar_oprd2) << 5; | |
17795 | } | |
17796 | } | |
17797 | ||
17798 | /* Dot Product instructions for signed integer. */ | |
17799 | ||
17800 | static void | |
17801 | do_neon_dotproduct_s (void) | |
17802 | { | |
17803 | return do_neon_dotproduct (0); | |
17804 | } | |
17805 | ||
17806 | /* Dot Product instructions for unsigned integer. */ | |
17807 | ||
17808 | static void | |
17809 | do_neon_dotproduct_u (void) | |
17810 | { | |
17811 | return do_neon_dotproduct (1); | |
17812 | } | |
17813 | ||
91ff7894 MGD |
17814 | /* Crypto v1 instructions. */ |
17815 | static void | |
17816 | do_crypto_2op_1 (unsigned elttype, int op) | |
17817 | { | |
17818 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17819 | ||
17820 | if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type | |
17821 | == NT_invtype) | |
17822 | return; | |
17823 | ||
17824 | inst.error = NULL; | |
17825 | ||
17826 | NEON_ENCODE (INTEGER, inst); | |
17827 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17828 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17829 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
17830 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
17831 | if (op != -1) | |
17832 | inst.instruction |= op << 6; | |
17833 | ||
17834 | if (thumb_mode) | |
17835 | inst.instruction |= 0xfc000000; | |
17836 | else | |
17837 | inst.instruction |= 0xf0000000; | |
17838 | } | |
17839 | ||
48adcd8e MGD |
17840 | static void |
17841 | do_crypto_3op_1 (int u, int op) | |
17842 | { | |
17843 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17844 | ||
17845 | if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT, | |
17846 | N_32 | N_UNT | N_KEY).type == NT_invtype) | |
17847 | return; | |
17848 | ||
17849 | inst.error = NULL; | |
17850 | ||
17851 | NEON_ENCODE (INTEGER, inst); | |
17852 | neon_three_same (1, u, 8 << op); | |
17853 | } | |
17854 | ||
91ff7894 MGD |
17855 | static void |
17856 | do_aese (void) | |
17857 | { | |
17858 | do_crypto_2op_1 (N_8, 0); | |
17859 | } | |
17860 | ||
17861 | static void | |
17862 | do_aesd (void) | |
17863 | { | |
17864 | do_crypto_2op_1 (N_8, 1); | |
17865 | } | |
17866 | ||
17867 | static void | |
17868 | do_aesmc (void) | |
17869 | { | |
17870 | do_crypto_2op_1 (N_8, 2); | |
17871 | } | |
17872 | ||
17873 | static void | |
17874 | do_aesimc (void) | |
17875 | { | |
17876 | do_crypto_2op_1 (N_8, 3); | |
17877 | } | |
17878 | ||
48adcd8e MGD |
17879 | static void |
17880 | do_sha1c (void) | |
17881 | { | |
17882 | do_crypto_3op_1 (0, 0); | |
17883 | } | |
17884 | ||
17885 | static void | |
17886 | do_sha1p (void) | |
17887 | { | |
17888 | do_crypto_3op_1 (0, 1); | |
17889 | } | |
17890 | ||
17891 | static void | |
17892 | do_sha1m (void) | |
17893 | { | |
17894 | do_crypto_3op_1 (0, 2); | |
17895 | } | |
17896 | ||
17897 | static void | |
17898 | do_sha1su0 (void) | |
17899 | { | |
17900 | do_crypto_3op_1 (0, 3); | |
17901 | } | |
91ff7894 | 17902 | |
48adcd8e MGD |
17903 | static void |
17904 | do_sha256h (void) | |
17905 | { | |
17906 | do_crypto_3op_1 (1, 0); | |
17907 | } | |
17908 | ||
17909 | static void | |
17910 | do_sha256h2 (void) | |
17911 | { | |
17912 | do_crypto_3op_1 (1, 1); | |
17913 | } | |
17914 | ||
17915 | static void | |
17916 | do_sha256su1 (void) | |
17917 | { | |
17918 | do_crypto_3op_1 (1, 2); | |
17919 | } | |
3c9017d2 MGD |
17920 | |
17921 | static void | |
17922 | do_sha1h (void) | |
17923 | { | |
17924 | do_crypto_2op_1 (N_32, -1); | |
17925 | } | |
17926 | ||
17927 | static void | |
17928 | do_sha1su1 (void) | |
17929 | { | |
17930 | do_crypto_2op_1 (N_32, 0); | |
17931 | } | |
17932 | ||
17933 | static void | |
17934 | do_sha256su0 (void) | |
17935 | { | |
17936 | do_crypto_2op_1 (N_32, 1); | |
17937 | } | |
dd5181d5 KT |
17938 | |
17939 | static void | |
17940 | do_crc32_1 (unsigned int poly, unsigned int sz) | |
17941 | { | |
17942 | unsigned int Rd = inst.operands[0].reg; | |
17943 | unsigned int Rn = inst.operands[1].reg; | |
17944 | unsigned int Rm = inst.operands[2].reg; | |
17945 | ||
17946 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17947 | inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12); | |
17948 | inst.instruction |= LOW4 (Rn) << 16; | |
17949 | inst.instruction |= LOW4 (Rm); | |
17950 | inst.instruction |= sz << (thumb_mode ? 4 : 21); | |
17951 | inst.instruction |= poly << (thumb_mode ? 20 : 9); | |
17952 | ||
17953 | if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC) | |
17954 | as_warn (UNPRED_REG ("r15")); | |
dd5181d5 KT |
17955 | } |
17956 | ||
17957 | static void | |
17958 | do_crc32b (void) | |
17959 | { | |
17960 | do_crc32_1 (0, 0); | |
17961 | } | |
17962 | ||
17963 | static void | |
17964 | do_crc32h (void) | |
17965 | { | |
17966 | do_crc32_1 (0, 1); | |
17967 | } | |
17968 | ||
17969 | static void | |
17970 | do_crc32w (void) | |
17971 | { | |
17972 | do_crc32_1 (0, 2); | |
17973 | } | |
17974 | ||
17975 | static void | |
17976 | do_crc32cb (void) | |
17977 | { | |
17978 | do_crc32_1 (1, 0); | |
17979 | } | |
17980 | ||
17981 | static void | |
17982 | do_crc32ch (void) | |
17983 | { | |
17984 | do_crc32_1 (1, 1); | |
17985 | } | |
17986 | ||
17987 | static void | |
17988 | do_crc32cw (void) | |
17989 | { | |
17990 | do_crc32_1 (1, 2); | |
17991 | } | |
17992 | ||
49e8a725 SN |
17993 | static void |
17994 | do_vjcvt (void) | |
17995 | { | |
17996 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17997 | _(BAD_FPU)); | |
17998 | neon_check_type (2, NS_FD, N_S32, N_F64); | |
17999 | do_vfp_sp_dp_cvt (); | |
18000 | do_vfp_cond_or_thumb (); | |
18001 | } | |
18002 | ||
5287ad62 JB |
18003 | \f |
18004 | /* Overall per-instruction processing. */ | |
18005 | ||
18006 | /* We need to be able to fix up arbitrary expressions in some statements. | |
18007 | This is so that we can handle symbols that are an arbitrary distance from | |
18008 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
18009 | which returns part of an address in a form which will be valid for | |
18010 | a data instruction. We do this by pushing the expression into a symbol | |
18011 | in the expr_section, and creating a fix for that. */ | |
18012 | ||
18013 | static void | |
18014 | fix_new_arm (fragS * frag, | |
18015 | int where, | |
18016 | short int size, | |
18017 | expressionS * exp, | |
18018 | int pc_rel, | |
18019 | int reloc) | |
18020 | { | |
18021 | fixS * new_fix; | |
18022 | ||
18023 | switch (exp->X_op) | |
18024 | { | |
18025 | case O_constant: | |
6e7ce2cd PB |
18026 | if (pc_rel) |
18027 | { | |
18028 | /* Create an absolute valued symbol, so we have something to | |
477330fc RM |
18029 | refer to in the object file. Unfortunately for us, gas's |
18030 | generic expression parsing will already have folded out | |
18031 | any use of .set foo/.type foo %function that may have | |
18032 | been used to set type information of the target location, | |
18033 | that's being specified symbolically. We have to presume | |
18034 | the user knows what they are doing. */ | |
6e7ce2cd PB |
18035 | char name[16 + 8]; |
18036 | symbolS *symbol; | |
18037 | ||
18038 | sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number); | |
18039 | ||
18040 | symbol = symbol_find_or_make (name); | |
18041 | S_SET_SEGMENT (symbol, absolute_section); | |
18042 | symbol_set_frag (symbol, &zero_address_frag); | |
18043 | S_SET_VALUE (symbol, exp->X_add_number); | |
18044 | exp->X_op = O_symbol; | |
18045 | exp->X_add_symbol = symbol; | |
18046 | exp->X_add_number = 0; | |
18047 | } | |
18048 | /* FALLTHROUGH */ | |
5287ad62 JB |
18049 | case O_symbol: |
18050 | case O_add: | |
18051 | case O_subtract: | |
21d799b5 | 18052 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
477330fc | 18053 | (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
18054 | break; |
18055 | ||
18056 | default: | |
21d799b5 | 18057 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
477330fc | 18058 | pc_rel, (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
18059 | break; |
18060 | } | |
18061 | ||
18062 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
18063 | instruction. */ | |
18064 | new_fix->tc_fix_data = thumb_mode; | |
18065 | } | |
18066 | ||
18067 | /* Create a frg for an instruction requiring relaxation. */ | |
18068 | static void | |
18069 | output_relax_insn (void) | |
18070 | { | |
18071 | char * to; | |
18072 | symbolS *sym; | |
0110f2b8 PB |
18073 | int offset; |
18074 | ||
6e1cb1a6 PB |
18075 | /* The size of the instruction is unknown, so tie the debug info to the |
18076 | start of the instruction. */ | |
18077 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 18078 | |
e2b0ab59 | 18079 | switch (inst.relocs[0].exp.X_op) |
0110f2b8 PB |
18080 | { |
18081 | case O_symbol: | |
e2b0ab59 AV |
18082 | sym = inst.relocs[0].exp.X_add_symbol; |
18083 | offset = inst.relocs[0].exp.X_add_number; | |
0110f2b8 PB |
18084 | break; |
18085 | case O_constant: | |
18086 | sym = NULL; | |
e2b0ab59 | 18087 | offset = inst.relocs[0].exp.X_add_number; |
0110f2b8 PB |
18088 | break; |
18089 | default: | |
e2b0ab59 | 18090 | sym = make_expr_symbol (&inst.relocs[0].exp); |
0110f2b8 PB |
18091 | offset = 0; |
18092 | break; | |
18093 | } | |
18094 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
18095 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
18096 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
18097 | } |
18098 | ||
18099 | /* Write a 32-bit thumb instruction to buf. */ | |
18100 | static void | |
18101 | put_thumb32_insn (char * buf, unsigned long insn) | |
18102 | { | |
18103 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
18104 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
18105 | } | |
18106 | ||
b99bd4ef | 18107 | static void |
c19d1205 | 18108 | output_inst (const char * str) |
b99bd4ef | 18109 | { |
c19d1205 | 18110 | char * to = NULL; |
b99bd4ef | 18111 | |
c19d1205 | 18112 | if (inst.error) |
b99bd4ef | 18113 | { |
c19d1205 | 18114 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
18115 | return; |
18116 | } | |
5f4273c7 NC |
18117 | if (inst.relax) |
18118 | { | |
18119 | output_relax_insn (); | |
0110f2b8 | 18120 | return; |
5f4273c7 | 18121 | } |
c19d1205 ZW |
18122 | if (inst.size == 0) |
18123 | return; | |
b99bd4ef | 18124 | |
c19d1205 | 18125 | to = frag_more (inst.size); |
8dc2430f NC |
18126 | /* PR 9814: Record the thumb mode into the current frag so that we know |
18127 | what type of NOP padding to use, if necessary. We override any previous | |
18128 | setting so that if the mode has changed then the NOPS that we use will | |
18129 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 18130 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
18131 | |
18132 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 18133 | { |
9c2799c2 | 18134 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 18135 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 18136 | } |
c19d1205 | 18137 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 18138 | { |
9c2799c2 | 18139 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
18140 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
18141 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 18142 | } |
c19d1205 ZW |
18143 | else |
18144 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 18145 | |
e2b0ab59 AV |
18146 | int r; |
18147 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
18148 | { | |
18149 | if (inst.relocs[r].type != BFD_RELOC_UNUSED) | |
18150 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
18151 | inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel, | |
18152 | inst.relocs[r].type); | |
18153 | } | |
b99bd4ef | 18154 | |
c19d1205 | 18155 | dwarf2_emit_insn (inst.size); |
c19d1205 | 18156 | } |
b99bd4ef | 18157 | |
e07e6e58 NC |
18158 | static char * |
18159 | output_it_inst (int cond, int mask, char * to) | |
18160 | { | |
18161 | unsigned long instruction = 0xbf00; | |
18162 | ||
18163 | mask &= 0xf; | |
18164 | instruction |= mask; | |
18165 | instruction |= cond << 4; | |
18166 | ||
18167 | if (to == NULL) | |
18168 | { | |
18169 | to = frag_more (2); | |
18170 | #ifdef OBJ_ELF | |
18171 | dwarf2_emit_insn (2); | |
18172 | #endif | |
18173 | } | |
18174 | ||
18175 | md_number_to_chars (to, instruction, 2); | |
18176 | ||
18177 | return to; | |
18178 | } | |
18179 | ||
c19d1205 ZW |
18180 | /* Tag values used in struct asm_opcode's tag field. */ |
18181 | enum opcode_tag | |
18182 | { | |
18183 | OT_unconditional, /* Instruction cannot be conditionalized. | |
18184 | The ARM condition field is still 0xE. */ | |
18185 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
18186 | and carries 0xF in its ARM condition field. */ | |
18187 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 | 18188 | OT_csuffixF, /* Some forms of the instruction take a conditional |
477330fc RM |
18189 | suffix, others place 0xF where the condition field |
18190 | would be. */ | |
c19d1205 ZW |
18191 | OT_cinfix3, /* Instruction takes a conditional infix, |
18192 | beginning at character index 3. (In | |
18193 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
18194 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
18195 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
18196 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
18197 | character index 3, even in unified mode. Used for | |
18198 | legacy instructions where suffix and infix forms | |
18199 | may be ambiguous. */ | |
c19d1205 | 18200 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 18201 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
18202 | OT_odd_infix_unc, /* This is the unconditional variant of an |
18203 | instruction that takes a conditional infix | |
18204 | at an unusual position. In unified mode, | |
18205 | this variant will accept a suffix. */ | |
18206 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
18207 | are the conditional variants of instructions that | |
18208 | take conditional infixes in unusual positions. | |
18209 | The infix appears at character index | |
18210 | (tag - OT_odd_infix_0). These are not accepted | |
18211 | in unified mode. */ | |
18212 | }; | |
b99bd4ef | 18213 | |
c19d1205 ZW |
18214 | /* Subroutine of md_assemble, responsible for looking up the primary |
18215 | opcode from the mnemonic the user wrote. STR points to the | |
18216 | beginning of the mnemonic. | |
18217 | ||
18218 | This is not simply a hash table lookup, because of conditional | |
18219 | variants. Most instructions have conditional variants, which are | |
18220 | expressed with a _conditional affix_ to the mnemonic. If we were | |
18221 | to encode each conditional variant as a literal string in the opcode | |
18222 | table, it would have approximately 20,000 entries. | |
18223 | ||
18224 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
18225 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
18226 | instructions take the affix as an infix, notably the s-variants of | |
18227 | the arithmetic instructions. Of those instructions, all but six | |
18228 | have the infix appear after the third character of the mnemonic. | |
18229 | ||
18230 | Accordingly, the algorithm for looking up primary opcodes given | |
18231 | an identifier is: | |
18232 | ||
18233 | 1. Look up the identifier in the opcode table. | |
18234 | If we find a match, go to step U. | |
18235 | ||
18236 | 2. Look up the last two characters of the identifier in the | |
18237 | conditions table. If we find a match, look up the first N-2 | |
18238 | characters of the identifier in the opcode table. If we | |
18239 | find a match, go to step CE. | |
18240 | ||
18241 | 3. Look up the fourth and fifth characters of the identifier in | |
18242 | the conditions table. If we find a match, extract those | |
18243 | characters from the identifier, and look up the remaining | |
18244 | characters in the opcode table. If we find a match, go | |
18245 | to step CM. | |
18246 | ||
18247 | 4. Fail. | |
18248 | ||
18249 | U. Examine the tag field of the opcode structure, in case this is | |
18250 | one of the six instructions with its conditional infix in an | |
18251 | unusual place. If it is, the tag tells us where to find the | |
18252 | infix; look it up in the conditions table and set inst.cond | |
18253 | accordingly. Otherwise, this is an unconditional instruction. | |
18254 | Again set inst.cond accordingly. Return the opcode structure. | |
18255 | ||
18256 | CE. Examine the tag field to make sure this is an instruction that | |
18257 | should receive a conditional suffix. If it is not, fail. | |
18258 | Otherwise, set inst.cond from the suffix we already looked up, | |
18259 | and return the opcode structure. | |
18260 | ||
18261 | CM. Examine the tag field to make sure this is an instruction that | |
18262 | should receive a conditional infix after the third character. | |
18263 | If it is not, fail. Otherwise, undo the edits to the current | |
18264 | line of input and proceed as for case CE. */ | |
18265 | ||
18266 | static const struct asm_opcode * | |
18267 | opcode_lookup (char **str) | |
18268 | { | |
18269 | char *end, *base; | |
18270 | char *affix; | |
18271 | const struct asm_opcode *opcode; | |
18272 | const struct asm_cond *cond; | |
e3cb604e | 18273 | char save[2]; |
c19d1205 ZW |
18274 | |
18275 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 18276 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 18277 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 18278 | if (*end == ' ' || *end == '.') |
c19d1205 | 18279 | break; |
b99bd4ef | 18280 | |
c19d1205 | 18281 | if (end == base) |
c921be7d | 18282 | return NULL; |
b99bd4ef | 18283 | |
5287ad62 | 18284 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 18285 | if (end[0] == '.') |
b99bd4ef | 18286 | { |
5287ad62 | 18287 | int offset = 2; |
5f4273c7 | 18288 | |
267d2029 | 18289 | /* The .w and .n suffixes are only valid if the unified syntax is in |
477330fc | 18290 | use. */ |
267d2029 | 18291 | if (unified_syntax && end[1] == 'w') |
c19d1205 | 18292 | inst.size_req = 4; |
267d2029 | 18293 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
18294 | inst.size_req = 2; |
18295 | else | |
477330fc | 18296 | offset = 0; |
5287ad62 JB |
18297 | |
18298 | inst.vectype.elems = 0; | |
18299 | ||
18300 | *str = end + offset; | |
b99bd4ef | 18301 | |
5f4273c7 | 18302 | if (end[offset] == '.') |
5287ad62 | 18303 | { |
267d2029 | 18304 | /* See if we have a Neon type suffix (possible in either unified or |
477330fc RM |
18305 | non-unified ARM syntax mode). */ |
18306 | if (parse_neon_type (&inst.vectype, str) == FAIL) | |
c921be7d | 18307 | return NULL; |
477330fc | 18308 | } |
5287ad62 | 18309 | else if (end[offset] != '\0' && end[offset] != ' ') |
477330fc | 18310 | return NULL; |
b99bd4ef | 18311 | } |
c19d1205 ZW |
18312 | else |
18313 | *str = end; | |
b99bd4ef | 18314 | |
c19d1205 | 18315 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 | 18316 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 18317 | end - base); |
c19d1205 | 18318 | if (opcode) |
b99bd4ef | 18319 | { |
c19d1205 ZW |
18320 | /* step U */ |
18321 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 18322 | { |
c19d1205 ZW |
18323 | inst.cond = COND_ALWAYS; |
18324 | return opcode; | |
b99bd4ef | 18325 | } |
b99bd4ef | 18326 | |
278df34e | 18327 | if (warn_on_deprecated && unified_syntax) |
5c3696f8 | 18328 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 | 18329 | affix = base + (opcode->tag - OT_odd_infix_0); |
21d799b5 | 18330 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 18331 | gas_assert (cond); |
b99bd4ef | 18332 | |
c19d1205 ZW |
18333 | inst.cond = cond->value; |
18334 | return opcode; | |
18335 | } | |
b99bd4ef | 18336 | |
c19d1205 ZW |
18337 | /* Cannot have a conditional suffix on a mnemonic of less than two |
18338 | characters. */ | |
18339 | if (end - base < 3) | |
c921be7d | 18340 | return NULL; |
b99bd4ef | 18341 | |
c19d1205 ZW |
18342 | /* Look for suffixed mnemonic. */ |
18343 | affix = end - 2; | |
21d799b5 NC |
18344 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
18345 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
477330fc | 18346 | affix - base); |
c19d1205 ZW |
18347 | if (opcode && cond) |
18348 | { | |
18349 | /* step CE */ | |
18350 | switch (opcode->tag) | |
18351 | { | |
e3cb604e PB |
18352 | case OT_cinfix3_legacy: |
18353 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
18354 | break; | |
18355 | ||
c19d1205 | 18356 | case OT_cinfix3: |
088fa78e | 18357 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
18358 | case OT_odd_infix_unc: |
18359 | if (!unified_syntax) | |
0198d5e6 | 18360 | return NULL; |
1a0670f3 | 18361 | /* Fall through. */ |
c19d1205 ZW |
18362 | |
18363 | case OT_csuffix: | |
477330fc | 18364 | case OT_csuffixF: |
c19d1205 ZW |
18365 | case OT_csuf_or_in3: |
18366 | inst.cond = cond->value; | |
18367 | return opcode; | |
18368 | ||
18369 | case OT_unconditional: | |
18370 | case OT_unconditionalF: | |
dfa9f0d5 | 18371 | if (thumb_mode) |
c921be7d | 18372 | inst.cond = cond->value; |
dfa9f0d5 PB |
18373 | else |
18374 | { | |
c921be7d | 18375 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
18376 | inst.error = BAD_COND; |
18377 | inst.cond = COND_ALWAYS; | |
18378 | } | |
c19d1205 | 18379 | return opcode; |
b99bd4ef | 18380 | |
c19d1205 | 18381 | default: |
c921be7d | 18382 | return NULL; |
c19d1205 ZW |
18383 | } |
18384 | } | |
b99bd4ef | 18385 | |
c19d1205 ZW |
18386 | /* Cannot have a usual-position infix on a mnemonic of less than |
18387 | six characters (five would be a suffix). */ | |
18388 | if (end - base < 6) | |
c921be7d | 18389 | return NULL; |
b99bd4ef | 18390 | |
c19d1205 ZW |
18391 | /* Look for infixed mnemonic in the usual position. */ |
18392 | affix = base + 3; | |
21d799b5 | 18393 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 18394 | if (!cond) |
c921be7d | 18395 | return NULL; |
e3cb604e PB |
18396 | |
18397 | memcpy (save, affix, 2); | |
18398 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 | 18399 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 18400 | (end - base) - 2); |
e3cb604e PB |
18401 | memmove (affix + 2, affix, (end - affix) - 2); |
18402 | memcpy (affix, save, 2); | |
18403 | ||
088fa78e KH |
18404 | if (opcode |
18405 | && (opcode->tag == OT_cinfix3 | |
18406 | || opcode->tag == OT_cinfix3_deprecated | |
18407 | || opcode->tag == OT_csuf_or_in3 | |
18408 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 18409 | { |
c921be7d | 18410 | /* Step CM. */ |
278df34e | 18411 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
18412 | && (opcode->tag == OT_cinfix3 |
18413 | || opcode->tag == OT_cinfix3_deprecated)) | |
5c3696f8 | 18414 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 ZW |
18415 | |
18416 | inst.cond = cond->value; | |
18417 | return opcode; | |
b99bd4ef NC |
18418 | } |
18419 | ||
c921be7d | 18420 | return NULL; |
b99bd4ef NC |
18421 | } |
18422 | ||
e07e6e58 NC |
18423 | /* This function generates an initial IT instruction, leaving its block |
18424 | virtually open for the new instructions. Eventually, | |
18425 | the mask will be updated by now_it_add_mask () each time | |
18426 | a new instruction needs to be included in the IT block. | |
18427 | Finally, the block is closed with close_automatic_it_block (). | |
18428 | The block closure can be requested either from md_assemble (), | |
18429 | a tencode (), or due to a label hook. */ | |
18430 | ||
18431 | static void | |
18432 | new_automatic_it_block (int cond) | |
18433 | { | |
18434 | now_it.state = AUTOMATIC_IT_BLOCK; | |
18435 | now_it.mask = 0x18; | |
18436 | now_it.cc = cond; | |
18437 | now_it.block_length = 1; | |
cd000bff | 18438 | mapping_state (MAP_THUMB); |
e07e6e58 | 18439 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
5a01bb1d MGD |
18440 | now_it.warn_deprecated = FALSE; |
18441 | now_it.insn_cond = TRUE; | |
e07e6e58 NC |
18442 | } |
18443 | ||
18444 | /* Close an automatic IT block. | |
18445 | See comments in new_automatic_it_block (). */ | |
18446 | ||
18447 | static void | |
18448 | close_automatic_it_block (void) | |
18449 | { | |
18450 | now_it.mask = 0x10; | |
18451 | now_it.block_length = 0; | |
18452 | } | |
18453 | ||
18454 | /* Update the mask of the current automatically-generated IT | |
18455 | instruction. See comments in new_automatic_it_block (). */ | |
18456 | ||
18457 | static void | |
18458 | now_it_add_mask (int cond) | |
18459 | { | |
18460 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
18461 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
477330fc | 18462 | | ((bitvalue) << (nbit))) |
e07e6e58 | 18463 | const int resulting_bit = (cond & 1); |
c921be7d | 18464 | |
e07e6e58 NC |
18465 | now_it.mask &= 0xf; |
18466 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
477330fc RM |
18467 | resulting_bit, |
18468 | (5 - now_it.block_length)); | |
e07e6e58 | 18469 | now_it.mask = SET_BIT_VALUE (now_it.mask, |
477330fc RM |
18470 | 1, |
18471 | ((5 - now_it.block_length) - 1) ); | |
e07e6e58 NC |
18472 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); |
18473 | ||
18474 | #undef CLEAR_BIT | |
18475 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
18476 | } |
18477 | ||
18478 | /* The IT blocks handling machinery is accessed through the these functions: | |
18479 | it_fsm_pre_encode () from md_assemble () | |
18480 | set_it_insn_type () optional, from the tencode functions | |
18481 | set_it_insn_type_last () ditto | |
18482 | in_it_block () ditto | |
18483 | it_fsm_post_encode () from md_assemble () | |
33eaf5de | 18484 | force_automatic_it_block_close () from label handling functions |
e07e6e58 NC |
18485 | |
18486 | Rationale: | |
18487 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
477330fc RM |
18488 | initializing the IT insn type with a generic initial value depending |
18489 | on the inst.condition. | |
e07e6e58 | 18490 | 2) During the tencode function, two things may happen: |
477330fc RM |
18491 | a) The tencode function overrides the IT insn type by |
18492 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
18493 | b) The tencode function queries the IT block state by | |
18494 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
18495 | ||
18496 | Both set_it_insn_type and in_it_block run the internal FSM state | |
18497 | handling function (handle_it_state), because: a) setting the IT insn | |
18498 | type may incur in an invalid state (exiting the function), | |
18499 | and b) querying the state requires the FSM to be updated. | |
18500 | Specifically we want to avoid creating an IT block for conditional | |
18501 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
18502 | determine whether an IT block is required until the tencode () routine | |
18503 | has decided what type of instruction this actually it. | |
18504 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
18505 | set_it_insn_type has to be called first. | |
18506 | ||
18507 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
18508 | determines the insn IT type depending on the inst.cond code. | |
18509 | When a tencode () routine encodes an instruction that can be | |
18510 | either outside an IT block, or, in the case of being inside, has to be | |
18511 | the last one, set_it_insn_type_last () will determine the proper | |
18512 | IT instruction type based on the inst.cond code. Otherwise, | |
18513 | set_it_insn_type can be called for overriding that logic or | |
18514 | for covering other cases. | |
18515 | ||
18516 | Calling handle_it_state () may not transition the IT block state to | |
2b0f3761 | 18517 | OUTSIDE_IT_BLOCK immediately, since the (current) state could be |
477330fc RM |
18518 | still queried. Instead, if the FSM determines that the state should |
18519 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
18520 | after the tencode () function: that's what it_fsm_post_encode () does. | |
18521 | ||
18522 | Since in_it_block () calls the state handling function to get an | |
18523 | updated state, an error may occur (due to invalid insns combination). | |
18524 | In that case, inst.error is set. | |
18525 | Therefore, inst.error has to be checked after the execution of | |
18526 | the tencode () routine. | |
e07e6e58 NC |
18527 | |
18528 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
477330fc RM |
18529 | any pending state change (if any) that didn't take place in |
18530 | handle_it_state () as explained above. */ | |
e07e6e58 NC |
18531 | |
18532 | static void | |
18533 | it_fsm_pre_encode (void) | |
18534 | { | |
18535 | if (inst.cond != COND_ALWAYS) | |
18536 | inst.it_insn_type = INSIDE_IT_INSN; | |
18537 | else | |
18538 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
18539 | ||
18540 | now_it.state_handled = 0; | |
18541 | } | |
18542 | ||
18543 | /* IT state FSM handling function. */ | |
18544 | ||
18545 | static int | |
18546 | handle_it_state (void) | |
18547 | { | |
18548 | now_it.state_handled = 1; | |
5a01bb1d | 18549 | now_it.insn_cond = FALSE; |
e07e6e58 NC |
18550 | |
18551 | switch (now_it.state) | |
18552 | { | |
18553 | case OUTSIDE_IT_BLOCK: | |
18554 | switch (inst.it_insn_type) | |
18555 | { | |
18556 | case OUTSIDE_IT_INSN: | |
18557 | break; | |
18558 | ||
18559 | case INSIDE_IT_INSN: | |
18560 | case INSIDE_IT_LAST_INSN: | |
18561 | if (thumb_mode == 0) | |
18562 | { | |
c921be7d | 18563 | if (unified_syntax |
e07e6e58 NC |
18564 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
18565 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
18566 | " for Thumb.")); | |
18567 | } | |
18568 | else | |
18569 | { | |
18570 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
fc289b0a | 18571 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) |
e07e6e58 NC |
18572 | { |
18573 | /* Automatically generate the IT instruction. */ | |
18574 | new_automatic_it_block (inst.cond); | |
18575 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
18576 | close_automatic_it_block (); | |
18577 | } | |
18578 | else | |
18579 | { | |
18580 | inst.error = BAD_OUT_IT; | |
18581 | return FAIL; | |
18582 | } | |
18583 | } | |
18584 | break; | |
18585 | ||
18586 | case IF_INSIDE_IT_LAST_INSN: | |
18587 | case NEUTRAL_IT_INSN: | |
18588 | break; | |
18589 | ||
18590 | case IT_INSN: | |
18591 | now_it.state = MANUAL_IT_BLOCK; | |
18592 | now_it.block_length = 0; | |
18593 | break; | |
18594 | } | |
18595 | break; | |
18596 | ||
18597 | case AUTOMATIC_IT_BLOCK: | |
18598 | /* Three things may happen now: | |
18599 | a) We should increment current it block size; | |
18600 | b) We should close current it block (closing insn or 4 insns); | |
18601 | c) We should close current it block and start a new one (due | |
18602 | to incompatible conditions or | |
18603 | 4 insns-length block reached). */ | |
18604 | ||
18605 | switch (inst.it_insn_type) | |
18606 | { | |
18607 | case OUTSIDE_IT_INSN: | |
2b0f3761 | 18608 | /* The closure of the block shall happen immediately, |
e07e6e58 NC |
18609 | so any in_it_block () call reports the block as closed. */ |
18610 | force_automatic_it_block_close (); | |
18611 | break; | |
18612 | ||
18613 | case INSIDE_IT_INSN: | |
18614 | case INSIDE_IT_LAST_INSN: | |
18615 | case IF_INSIDE_IT_LAST_INSN: | |
18616 | now_it.block_length++; | |
18617 | ||
18618 | if (now_it.block_length > 4 | |
18619 | || !now_it_compatible (inst.cond)) | |
18620 | { | |
18621 | force_automatic_it_block_close (); | |
18622 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
18623 | new_automatic_it_block (inst.cond); | |
18624 | } | |
18625 | else | |
18626 | { | |
5a01bb1d | 18627 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18628 | now_it_add_mask (inst.cond); |
18629 | } | |
18630 | ||
18631 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
18632 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
18633 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
18634 | close_automatic_it_block (); | |
18635 | break; | |
18636 | ||
18637 | case NEUTRAL_IT_INSN: | |
18638 | now_it.block_length++; | |
5a01bb1d | 18639 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18640 | |
18641 | if (now_it.block_length > 4) | |
18642 | force_automatic_it_block_close (); | |
18643 | else | |
18644 | now_it_add_mask (now_it.cc & 1); | |
18645 | break; | |
18646 | ||
18647 | case IT_INSN: | |
18648 | close_automatic_it_block (); | |
18649 | now_it.state = MANUAL_IT_BLOCK; | |
18650 | break; | |
18651 | } | |
18652 | break; | |
18653 | ||
18654 | case MANUAL_IT_BLOCK: | |
18655 | { | |
18656 | /* Check conditional suffixes. */ | |
18657 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
18658 | int is_last; | |
18659 | now_it.mask <<= 1; | |
18660 | now_it.mask &= 0x1f; | |
18661 | is_last = (now_it.mask == 0x10); | |
5a01bb1d | 18662 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18663 | |
18664 | switch (inst.it_insn_type) | |
18665 | { | |
18666 | case OUTSIDE_IT_INSN: | |
18667 | inst.error = BAD_NOT_IT; | |
18668 | return FAIL; | |
18669 | ||
18670 | case INSIDE_IT_INSN: | |
18671 | if (cond != inst.cond) | |
18672 | { | |
18673 | inst.error = BAD_IT_COND; | |
18674 | return FAIL; | |
18675 | } | |
18676 | break; | |
18677 | ||
18678 | case INSIDE_IT_LAST_INSN: | |
18679 | case IF_INSIDE_IT_LAST_INSN: | |
18680 | if (cond != inst.cond) | |
18681 | { | |
18682 | inst.error = BAD_IT_COND; | |
18683 | return FAIL; | |
18684 | } | |
18685 | if (!is_last) | |
18686 | { | |
18687 | inst.error = BAD_BRANCH; | |
18688 | return FAIL; | |
18689 | } | |
18690 | break; | |
18691 | ||
18692 | case NEUTRAL_IT_INSN: | |
18693 | /* The BKPT instruction is unconditional even in an IT block. */ | |
18694 | break; | |
18695 | ||
18696 | case IT_INSN: | |
18697 | inst.error = BAD_IT_IT; | |
18698 | return FAIL; | |
18699 | } | |
18700 | } | |
18701 | break; | |
18702 | } | |
18703 | ||
18704 | return SUCCESS; | |
18705 | } | |
18706 | ||
5a01bb1d MGD |
18707 | struct depr_insn_mask |
18708 | { | |
18709 | unsigned long pattern; | |
18710 | unsigned long mask; | |
18711 | const char* description; | |
18712 | }; | |
18713 | ||
18714 | /* List of 16-bit instruction patterns deprecated in an IT block in | |
18715 | ARMv8. */ | |
18716 | static const struct depr_insn_mask depr_it_insns[] = { | |
18717 | { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") }, | |
18718 | { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") }, | |
18719 | { 0xa000, 0xb800, N_("ADR") }, | |
18720 | { 0x4800, 0xf800, N_("Literal loads") }, | |
18721 | { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") }, | |
18722 | { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") }, | |
c8de034b JW |
18723 | /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue' |
18724 | field in asm_opcode. 'tvalue' is used at the stage this check happen. */ | |
18725 | { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") }, | |
5a01bb1d MGD |
18726 | { 0, 0, NULL } |
18727 | }; | |
18728 | ||
e07e6e58 NC |
18729 | static void |
18730 | it_fsm_post_encode (void) | |
18731 | { | |
18732 | int is_last; | |
18733 | ||
18734 | if (!now_it.state_handled) | |
18735 | handle_it_state (); | |
18736 | ||
5a01bb1d MGD |
18737 | if (now_it.insn_cond |
18738 | && !now_it.warn_deprecated | |
18739 | && warn_on_deprecated | |
df9909b8 TP |
18740 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8) |
18741 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m)) | |
5a01bb1d MGD |
18742 | { |
18743 | if (inst.instruction >= 0x10000) | |
18744 | { | |
5c3696f8 | 18745 | as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are " |
df9909b8 | 18746 | "performance deprecated in ARMv8-A and ARMv8-R")); |
5a01bb1d MGD |
18747 | now_it.warn_deprecated = TRUE; |
18748 | } | |
18749 | else | |
18750 | { | |
18751 | const struct depr_insn_mask *p = depr_it_insns; | |
18752 | ||
18753 | while (p->mask != 0) | |
18754 | { | |
18755 | if ((inst.instruction & p->mask) == p->pattern) | |
18756 | { | |
df9909b8 TP |
18757 | as_tsktsk (_("IT blocks containing 16-bit Thumb " |
18758 | "instructions of the following class are " | |
18759 | "performance deprecated in ARMv8-A and " | |
18760 | "ARMv8-R: %s"), p->description); | |
5a01bb1d MGD |
18761 | now_it.warn_deprecated = TRUE; |
18762 | break; | |
18763 | } | |
18764 | ||
18765 | ++p; | |
18766 | } | |
18767 | } | |
18768 | ||
18769 | if (now_it.block_length > 1) | |
18770 | { | |
5c3696f8 | 18771 | as_tsktsk (_("IT blocks containing more than one conditional " |
df9909b8 TP |
18772 | "instruction are performance deprecated in ARMv8-A and " |
18773 | "ARMv8-R")); | |
5a01bb1d MGD |
18774 | now_it.warn_deprecated = TRUE; |
18775 | } | |
18776 | } | |
18777 | ||
e07e6e58 NC |
18778 | is_last = (now_it.mask == 0x10); |
18779 | if (is_last) | |
18780 | { | |
18781 | now_it.state = OUTSIDE_IT_BLOCK; | |
18782 | now_it.mask = 0; | |
18783 | } | |
18784 | } | |
18785 | ||
18786 | static void | |
18787 | force_automatic_it_block_close (void) | |
18788 | { | |
18789 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
18790 | { | |
18791 | close_automatic_it_block (); | |
18792 | now_it.state = OUTSIDE_IT_BLOCK; | |
18793 | now_it.mask = 0; | |
18794 | } | |
18795 | } | |
18796 | ||
18797 | static int | |
18798 | in_it_block (void) | |
18799 | { | |
18800 | if (!now_it.state_handled) | |
18801 | handle_it_state (); | |
18802 | ||
18803 | return now_it.state != OUTSIDE_IT_BLOCK; | |
18804 | } | |
18805 | ||
ff8646ee TP |
18806 | /* Whether OPCODE only has T32 encoding. Since this function is only used by |
18807 | t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed | |
18808 | here, hence the "known" in the function name. */ | |
fc289b0a TP |
18809 | |
18810 | static bfd_boolean | |
ff8646ee | 18811 | known_t32_only_insn (const struct asm_opcode *opcode) |
fc289b0a TP |
18812 | { |
18813 | /* Original Thumb-1 wide instruction. */ | |
18814 | if (opcode->tencode == do_t_blx | |
18815 | || opcode->tencode == do_t_branch23 | |
18816 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) | |
18817 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)) | |
18818 | return TRUE; | |
18819 | ||
16a1fa25 TP |
18820 | /* Wide-only instruction added to ARMv8-M Baseline. */ |
18821 | if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only) | |
ff8646ee TP |
18822 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics) |
18823 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m) | |
18824 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div)) | |
18825 | return TRUE; | |
18826 | ||
18827 | return FALSE; | |
18828 | } | |
18829 | ||
18830 | /* Whether wide instruction variant can be used if available for a valid OPCODE | |
18831 | in ARCH. */ | |
18832 | ||
18833 | static bfd_boolean | |
18834 | t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode) | |
18835 | { | |
18836 | if (known_t32_only_insn (opcode)) | |
18837 | return TRUE; | |
18838 | ||
18839 | /* Instruction with narrow and wide encoding added to ARMv8-M. Availability | |
18840 | of variant T3 of B.W is checked in do_t_branch. */ | |
18841 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
18842 | && opcode->tencode == do_t_branch) | |
18843 | return TRUE; | |
18844 | ||
bada4342 JW |
18845 | /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */ |
18846 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
18847 | && opcode->tencode == do_t_mov_cmp | |
18848 | /* Make sure CMP instruction is not affected. */ | |
18849 | && opcode->aencode == do_mov) | |
18850 | return TRUE; | |
18851 | ||
ff8646ee TP |
18852 | /* Wide instruction variants of all instructions with narrow *and* wide |
18853 | variants become available with ARMv6t2. Other opcodes are either | |
18854 | narrow-only or wide-only and are thus available if OPCODE is valid. */ | |
18855 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2)) | |
18856 | return TRUE; | |
18857 | ||
18858 | /* OPCODE with narrow only instruction variant or wide variant not | |
18859 | available. */ | |
fc289b0a TP |
18860 | return FALSE; |
18861 | } | |
18862 | ||
c19d1205 ZW |
18863 | void |
18864 | md_assemble (char *str) | |
b99bd4ef | 18865 | { |
c19d1205 ZW |
18866 | char *p = str; |
18867 | const struct asm_opcode * opcode; | |
b99bd4ef | 18868 | |
c19d1205 ZW |
18869 | /* Align the previous label if needed. */ |
18870 | if (last_label_seen != NULL) | |
b99bd4ef | 18871 | { |
c19d1205 ZW |
18872 | symbol_set_frag (last_label_seen, frag_now); |
18873 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
18874 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
18875 | } |
18876 | ||
c19d1205 | 18877 | memset (&inst, '\0', sizeof (inst)); |
e2b0ab59 AV |
18878 | int r; |
18879 | for (r = 0; r < ARM_IT_MAX_RELOCS; r++) | |
18880 | inst.relocs[r].type = BFD_RELOC_UNUSED; | |
b99bd4ef | 18881 | |
c19d1205 ZW |
18882 | opcode = opcode_lookup (&p); |
18883 | if (!opcode) | |
b99bd4ef | 18884 | { |
c19d1205 | 18885 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 18886 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d | 18887 | if (! create_register_alias (str, p) |
477330fc | 18888 | && ! create_neon_reg_alias (str, p)) |
c19d1205 | 18889 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 18890 | |
b99bd4ef NC |
18891 | return; |
18892 | } | |
18893 | ||
278df34e | 18894 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
5c3696f8 | 18895 | as_tsktsk (_("s suffix on comparison instruction is deprecated")); |
088fa78e | 18896 | |
037e8744 JB |
18897 | /* The value which unconditional instructions should have in place of the |
18898 | condition field. */ | |
18899 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
18900 | ||
c19d1205 | 18901 | if (thumb_mode) |
b99bd4ef | 18902 | { |
e74cfd16 | 18903 | arm_feature_set variant; |
8f06b2d8 PB |
18904 | |
18905 | variant = cpu_variant; | |
18906 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
18907 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
18908 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 18909 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
18910 | if (!opcode->tvariant |
18911 | || (thumb_mode == 1 | |
18912 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 18913 | { |
173205ca TP |
18914 | if (opcode->tencode == do_t_swi) |
18915 | as_bad (_("SVC is not permitted on this architecture")); | |
18916 | else | |
18917 | as_bad (_("selected processor does not support `%s' in Thumb mode"), str); | |
b99bd4ef NC |
18918 | return; |
18919 | } | |
c19d1205 ZW |
18920 | if (inst.cond != COND_ALWAYS && !unified_syntax |
18921 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 18922 | { |
c19d1205 | 18923 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
18924 | return; |
18925 | } | |
18926 | ||
fc289b0a TP |
18927 | /* Two things are addressed here: |
18928 | 1) Implicit require narrow instructions on Thumb-1. | |
18929 | This avoids relaxation accidentally introducing Thumb-2 | |
18930 | instructions. | |
18931 | 2) Reject wide instructions in non Thumb-2 cores. | |
18932 | ||
18933 | Only instructions with narrow and wide variants need to be handled | |
18934 | but selecting all non wide-only instructions is easier. */ | |
18935 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) | |
ff8646ee | 18936 | && !t32_insn_ok (variant, opcode)) |
076d447c | 18937 | { |
fc289b0a TP |
18938 | if (inst.size_req == 0) |
18939 | inst.size_req = 2; | |
18940 | else if (inst.size_req == 4) | |
752d5da4 | 18941 | { |
ff8646ee TP |
18942 | if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m)) |
18943 | as_bad (_("selected processor does not support 32bit wide " | |
18944 | "variant of instruction `%s'"), str); | |
18945 | else | |
18946 | as_bad (_("selected processor does not support `%s' in " | |
18947 | "Thumb-2 mode"), str); | |
fc289b0a | 18948 | return; |
752d5da4 | 18949 | } |
076d447c PB |
18950 | } |
18951 | ||
c19d1205 ZW |
18952 | inst.instruction = opcode->tvalue; |
18953 | ||
5be8be5d | 18954 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
477330fc RM |
18955 | { |
18956 | /* Prepare the it_insn_type for those encodings that don't set | |
18957 | it. */ | |
18958 | it_fsm_pre_encode (); | |
c19d1205 | 18959 | |
477330fc | 18960 | opcode->tencode (); |
e07e6e58 | 18961 | |
477330fc RM |
18962 | it_fsm_post_encode (); |
18963 | } | |
e27ec89e | 18964 | |
0110f2b8 | 18965 | if (!(inst.error || inst.relax)) |
b99bd4ef | 18966 | { |
9c2799c2 | 18967 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
18968 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
18969 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 18970 | { |
c19d1205 | 18971 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
18972 | return; |
18973 | } | |
18974 | } | |
076d447c PB |
18975 | |
18976 | /* Something has gone badly wrong if we try to relax a fixed size | |
477330fc | 18977 | instruction. */ |
9c2799c2 | 18978 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 18979 | |
e74cfd16 PB |
18980 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
18981 | *opcode->tvariant); | |
ee065d83 | 18982 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
fc289b0a TP |
18983 | set those bits when Thumb-2 32-bit instructions are seen. The impact |
18984 | of relaxable instructions will be considered later after we finish all | |
18985 | relaxation. */ | |
ff8646ee TP |
18986 | if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any)) |
18987 | variant = arm_arch_none; | |
18988 | else | |
18989 | variant = cpu_variant; | |
18990 | if (inst.size == 4 && !t32_insn_ok (variant, opcode)) | |
e74cfd16 PB |
18991 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
18992 | arm_ext_v6t2); | |
cd000bff | 18993 | |
88714cb8 DG |
18994 | check_neon_suffixes; |
18995 | ||
cd000bff | 18996 | if (!inst.error) |
c877a2f2 NC |
18997 | { |
18998 | mapping_state (MAP_THUMB); | |
18999 | } | |
c19d1205 | 19000 | } |
3e9e4fcf | 19001 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 19002 | { |
845b51d6 PB |
19003 | bfd_boolean is_bx; |
19004 | ||
19005 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
19006 | is_bx = (opcode->aencode == do_bx); | |
19007 | ||
c19d1205 | 19008 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
19009 | if (!(is_bx && fix_v4bx) |
19010 | && !(opcode->avariant && | |
19011 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 19012 | { |
84b52b66 | 19013 | as_bad (_("selected processor does not support `%s' in ARM mode"), str); |
c19d1205 | 19014 | return; |
b99bd4ef | 19015 | } |
c19d1205 | 19016 | if (inst.size_req) |
b99bd4ef | 19017 | { |
c19d1205 ZW |
19018 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
19019 | return; | |
b99bd4ef NC |
19020 | } |
19021 | ||
c19d1205 ZW |
19022 | inst.instruction = opcode->avalue; |
19023 | if (opcode->tag == OT_unconditionalF) | |
eff0bc54 | 19024 | inst.instruction |= 0xFU << 28; |
c19d1205 ZW |
19025 | else |
19026 | inst.instruction |= inst.cond << 28; | |
19027 | inst.size = INSN_SIZE; | |
5be8be5d | 19028 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
477330fc RM |
19029 | { |
19030 | it_fsm_pre_encode (); | |
19031 | opcode->aencode (); | |
19032 | it_fsm_post_encode (); | |
19033 | } | |
ee065d83 | 19034 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
477330fc | 19035 | on a hypothetical non-thumb v5 core. */ |
845b51d6 | 19036 | if (is_bx) |
e74cfd16 | 19037 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 19038 | else |
e74cfd16 PB |
19039 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
19040 | *opcode->avariant); | |
88714cb8 DG |
19041 | |
19042 | check_neon_suffixes; | |
19043 | ||
cd000bff | 19044 | if (!inst.error) |
c877a2f2 NC |
19045 | { |
19046 | mapping_state (MAP_ARM); | |
19047 | } | |
b99bd4ef | 19048 | } |
3e9e4fcf JB |
19049 | else |
19050 | { | |
19051 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
19052 | "-- `%s'"), str); | |
19053 | return; | |
19054 | } | |
c19d1205 ZW |
19055 | output_inst (str); |
19056 | } | |
b99bd4ef | 19057 | |
e07e6e58 NC |
19058 | static void |
19059 | check_it_blocks_finished (void) | |
19060 | { | |
19061 | #ifdef OBJ_ELF | |
19062 | asection *sect; | |
19063 | ||
19064 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
19065 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
19066 | == MANUAL_IT_BLOCK) | |
19067 | { | |
19068 | as_warn (_("section '%s' finished with an open IT block."), | |
19069 | sect->name); | |
19070 | } | |
19071 | #else | |
19072 | if (now_it.state == MANUAL_IT_BLOCK) | |
19073 | as_warn (_("file finished with an open IT block.")); | |
19074 | #endif | |
19075 | } | |
19076 | ||
c19d1205 ZW |
19077 | /* Various frobbings of labels and their addresses. */ |
19078 | ||
19079 | void | |
19080 | arm_start_line_hook (void) | |
19081 | { | |
19082 | last_label_seen = NULL; | |
b99bd4ef NC |
19083 | } |
19084 | ||
c19d1205 ZW |
19085 | void |
19086 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 19087 | { |
c19d1205 | 19088 | last_label_seen = sym; |
b99bd4ef | 19089 | |
c19d1205 | 19090 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 19091 | |
c19d1205 ZW |
19092 | #if defined OBJ_COFF || defined OBJ_ELF |
19093 | ARM_SET_INTERWORK (sym, support_interwork); | |
19094 | #endif | |
b99bd4ef | 19095 | |
e07e6e58 NC |
19096 | force_automatic_it_block_close (); |
19097 | ||
5f4273c7 | 19098 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
19099 | as Thumb functions. This is because these labels, whilst |
19100 | they exist inside Thumb code, are not the entry points for | |
19101 | possible ARM->Thumb calls. Also, these labels can be used | |
19102 | as part of a computed goto or switch statement. eg gcc | |
19103 | can generate code that looks like this: | |
b99bd4ef | 19104 | |
c19d1205 ZW |
19105 | ldr r2, [pc, .Laaa] |
19106 | lsl r3, r3, #2 | |
19107 | ldr r2, [r3, r2] | |
19108 | mov pc, r2 | |
b99bd4ef | 19109 | |
c19d1205 ZW |
19110 | .Lbbb: .word .Lxxx |
19111 | .Lccc: .word .Lyyy | |
19112 | ..etc... | |
19113 | .Laaa: .word Lbbb | |
b99bd4ef | 19114 | |
c19d1205 ZW |
19115 | The first instruction loads the address of the jump table. |
19116 | The second instruction converts a table index into a byte offset. | |
19117 | The third instruction gets the jump address out of the table. | |
19118 | The fourth instruction performs the jump. | |
b99bd4ef | 19119 | |
c19d1205 ZW |
19120 | If the address stored at .Laaa is that of a symbol which has the |
19121 | Thumb_Func bit set, then the linker will arrange for this address | |
19122 | to have the bottom bit set, which in turn would mean that the | |
19123 | address computation performed by the third instruction would end | |
19124 | up with the bottom bit set. Since the ARM is capable of unaligned | |
19125 | word loads, the instruction would then load the incorrect address | |
19126 | out of the jump table, and chaos would ensue. */ | |
19127 | if (label_is_thumb_function_name | |
19128 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
19129 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 19130 | { |
c19d1205 ZW |
19131 | /* When the address of a Thumb function is taken the bottom |
19132 | bit of that address should be set. This will allow | |
19133 | interworking between Arm and Thumb functions to work | |
19134 | correctly. */ | |
b99bd4ef | 19135 | |
c19d1205 | 19136 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 19137 | |
c19d1205 | 19138 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 19139 | } |
07a53e5c | 19140 | |
07a53e5c | 19141 | dwarf2_emit_label (sym); |
b99bd4ef NC |
19142 | } |
19143 | ||
c921be7d | 19144 | bfd_boolean |
c19d1205 | 19145 | arm_data_in_code (void) |
b99bd4ef | 19146 | { |
c19d1205 | 19147 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 19148 | { |
c19d1205 ZW |
19149 | *input_line_pointer = '/'; |
19150 | input_line_pointer += 5; | |
19151 | *input_line_pointer = 0; | |
c921be7d | 19152 | return TRUE; |
b99bd4ef NC |
19153 | } |
19154 | ||
c921be7d | 19155 | return FALSE; |
b99bd4ef NC |
19156 | } |
19157 | ||
c19d1205 ZW |
19158 | char * |
19159 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 19160 | { |
c19d1205 | 19161 | int len; |
b99bd4ef | 19162 | |
c19d1205 ZW |
19163 | if (thumb_mode && (len = strlen (name)) > 5 |
19164 | && streq (name + len - 5, "/data")) | |
19165 | *(name + len - 5) = 0; | |
b99bd4ef | 19166 | |
c19d1205 | 19167 | return name; |
b99bd4ef | 19168 | } |
c19d1205 ZW |
19169 | \f |
19170 | /* Table of all register names defined by default. The user can | |
19171 | define additional names with .req. Note that all register names | |
19172 | should appear in both upper and lowercase variants. Some registers | |
19173 | also have mixed-case names. */ | |
b99bd4ef | 19174 | |
dcbf9037 | 19175 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 19176 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 19177 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
19178 | #define REGSET(p,t) \ |
19179 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
19180 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
19181 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
19182 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
19183 | #define REGSETH(p,t) \ |
19184 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
19185 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
19186 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
19187 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
19188 | #define REGSET2(p,t) \ | |
19189 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
19190 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
19191 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
19192 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
19193 | #define SPLRBANK(base,bank,t) \ |
19194 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
19195 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
19196 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
19197 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
19198 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
19199 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 19200 | |
c19d1205 | 19201 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 19202 | { |
c19d1205 ZW |
19203 | /* ARM integer registers. */ |
19204 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 19205 | |
c19d1205 ZW |
19206 | /* ATPCS synonyms. */ |
19207 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
19208 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
19209 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 19210 | |
c19d1205 ZW |
19211 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
19212 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
19213 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 19214 | |
c19d1205 ZW |
19215 | /* Well-known aliases. */ |
19216 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
19217 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
19218 | ||
19219 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
19220 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
19221 | ||
19222 | /* Coprocessor numbers. */ | |
19223 | REGSET(p, CP), REGSET(P, CP), | |
19224 | ||
19225 | /* Coprocessor register numbers. The "cr" variants are for backward | |
19226 | compatibility. */ | |
19227 | REGSET(c, CN), REGSET(C, CN), | |
19228 | REGSET(cr, CN), REGSET(CR, CN), | |
19229 | ||
90ec0d68 MGD |
19230 | /* ARM banked registers. */ |
19231 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
19232 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
19233 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
19234 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
19235 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
19236 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
19237 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
19238 | ||
19239 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
19240 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
19241 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
19242 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
19243 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
1472d06f | 19244 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB), |
90ec0d68 MGD |
19245 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), |
19246 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
19247 | ||
19248 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
19249 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
19250 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
19251 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
19252 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
19253 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
19254 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
fa94de6b | 19255 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
19256 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
19257 | ||
c19d1205 ZW |
19258 | /* FPA registers. */ |
19259 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
19260 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
19261 | ||
19262 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
19263 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
19264 | ||
19265 | /* VFP SP registers. */ | |
5287ad62 JB |
19266 | REGSET(s,VFS), REGSET(S,VFS), |
19267 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
19268 | |
19269 | /* VFP DP Registers. */ | |
5287ad62 JB |
19270 | REGSET(d,VFD), REGSET(D,VFD), |
19271 | /* Extra Neon DP registers. */ | |
19272 | REGSETH(d,VFD), REGSETH(D,VFD), | |
19273 | ||
19274 | /* Neon QP registers. */ | |
19275 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
19276 | |
19277 | /* VFP control registers. */ | |
19278 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
19279 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
19280 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
19281 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
19282 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
19283 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
40c7d507 | 19284 | REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC), |
c19d1205 ZW |
19285 | |
19286 | /* Maverick DSP coprocessor registers. */ | |
19287 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
19288 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
19289 | ||
19290 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
19291 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
19292 | REGDEF(dspsc,0,DSPSC), | |
19293 | ||
19294 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
19295 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
19296 | REGDEF(DSPSC,0,DSPSC), | |
19297 | ||
19298 | /* iWMMXt data registers - p0, c0-15. */ | |
19299 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
19300 | ||
19301 | /* iWMMXt control registers - p1, c0-3. */ | |
19302 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
19303 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
19304 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
19305 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
19306 | ||
19307 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
19308 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
19309 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
19310 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
19311 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
19312 | ||
19313 | /* XScale accumulator registers. */ | |
19314 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
19315 | }; | |
19316 | #undef REGDEF | |
19317 | #undef REGNUM | |
19318 | #undef REGSET | |
7ed4c4c5 | 19319 | |
c19d1205 ZW |
19320 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
19321 | within psr_required_here. */ | |
19322 | static const struct asm_psr psrs[] = | |
19323 | { | |
19324 | /* Backward compatibility notation. Note that "all" is no longer | |
19325 | truly all possible PSR bits. */ | |
19326 | {"all", PSR_c | PSR_f}, | |
19327 | {"flg", PSR_f}, | |
19328 | {"ctl", PSR_c}, | |
19329 | ||
19330 | /* Individual flags. */ | |
19331 | {"f", PSR_f}, | |
19332 | {"c", PSR_c}, | |
19333 | {"x", PSR_x}, | |
19334 | {"s", PSR_s}, | |
59b42a0d | 19335 | |
c19d1205 ZW |
19336 | /* Combinations of flags. */ |
19337 | {"fs", PSR_f | PSR_s}, | |
19338 | {"fx", PSR_f | PSR_x}, | |
19339 | {"fc", PSR_f | PSR_c}, | |
19340 | {"sf", PSR_s | PSR_f}, | |
19341 | {"sx", PSR_s | PSR_x}, | |
19342 | {"sc", PSR_s | PSR_c}, | |
19343 | {"xf", PSR_x | PSR_f}, | |
19344 | {"xs", PSR_x | PSR_s}, | |
19345 | {"xc", PSR_x | PSR_c}, | |
19346 | {"cf", PSR_c | PSR_f}, | |
19347 | {"cs", PSR_c | PSR_s}, | |
19348 | {"cx", PSR_c | PSR_x}, | |
19349 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
19350 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
19351 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
19352 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
19353 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
19354 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
19355 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
19356 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
19357 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
19358 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
19359 | {"scf", PSR_s | PSR_c | PSR_f}, | |
19360 | {"scx", PSR_s | PSR_c | PSR_x}, | |
19361 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
19362 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
19363 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
19364 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
19365 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
19366 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
19367 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
19368 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
19369 | {"csf", PSR_c | PSR_s | PSR_f}, | |
19370 | {"csx", PSR_c | PSR_s | PSR_x}, | |
19371 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
19372 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
19373 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
19374 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
19375 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
19376 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
19377 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
19378 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
19379 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
19380 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
19381 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
19382 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
19383 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
19384 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
19385 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
19386 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
19387 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
19388 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
19389 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
19390 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
19391 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
19392 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
19393 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
19394 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
19395 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
19396 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
19397 | }; | |
19398 | ||
62b3e311 PB |
19399 | /* Table of V7M psr names. */ |
19400 | static const struct asm_psr v7m_psrs[] = | |
19401 | { | |
1a336194 TP |
19402 | {"apsr", 0x0 }, {"APSR", 0x0 }, |
19403 | {"iapsr", 0x1 }, {"IAPSR", 0x1 }, | |
19404 | {"eapsr", 0x2 }, {"EAPSR", 0x2 }, | |
19405 | {"psr", 0x3 }, {"PSR", 0x3 }, | |
19406 | {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 }, | |
19407 | {"ipsr", 0x5 }, {"IPSR", 0x5 }, | |
19408 | {"epsr", 0x6 }, {"EPSR", 0x6 }, | |
19409 | {"iepsr", 0x7 }, {"IEPSR", 0x7 }, | |
19410 | {"msp", 0x8 }, {"MSP", 0x8 }, | |
19411 | {"psp", 0x9 }, {"PSP", 0x9 }, | |
19412 | {"msplim", 0xa }, {"MSPLIM", 0xa }, | |
19413 | {"psplim", 0xb }, {"PSPLIM", 0xb }, | |
19414 | {"primask", 0x10}, {"PRIMASK", 0x10}, | |
19415 | {"basepri", 0x11}, {"BASEPRI", 0x11}, | |
19416 | {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12}, | |
1a336194 TP |
19417 | {"faultmask", 0x13}, {"FAULTMASK", 0x13}, |
19418 | {"control", 0x14}, {"CONTROL", 0x14}, | |
19419 | {"msp_ns", 0x88}, {"MSP_NS", 0x88}, | |
19420 | {"psp_ns", 0x89}, {"PSP_NS", 0x89}, | |
19421 | {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a}, | |
19422 | {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b}, | |
19423 | {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90}, | |
19424 | {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91}, | |
19425 | {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93}, | |
19426 | {"control_ns", 0x94}, {"CONTROL_NS", 0x94}, | |
19427 | {"sp_ns", 0x98}, {"SP_NS", 0x98 } | |
62b3e311 PB |
19428 | }; |
19429 | ||
c19d1205 ZW |
19430 | /* Table of all shift-in-operand names. */ |
19431 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 19432 | { |
c19d1205 ZW |
19433 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
19434 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
19435 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
19436 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
19437 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
19438 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
19439 | }; | |
b99bd4ef | 19440 | |
c19d1205 ZW |
19441 | /* Table of all explicit relocation names. */ |
19442 | #ifdef OBJ_ELF | |
19443 | static struct reloc_entry reloc_names[] = | |
19444 | { | |
19445 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
19446 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
19447 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
19448 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
19449 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
19450 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
19451 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
19452 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
19453 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
19454 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 | 19455 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
19456 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
19457 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
477330fc | 19458 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, |
0855e32b | 19459 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, |
477330fc | 19460 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, |
0855e32b | 19461 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, |
188fd7ae CL |
19462 | { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}, |
19463 | { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC }, | |
19464 | { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC }, | |
19465 | { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC }, | |
19466 | { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC }, | |
19467 | { "funcdesc", BFD_RELOC_ARM_FUNCDESC }, | |
5c5a4843 CL |
19468 | { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC }, |
19469 | { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC }, | |
19470 | { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, | |
19471 | { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC }, | |
c19d1205 ZW |
19472 | }; |
19473 | #endif | |
b99bd4ef | 19474 | |
c19d1205 ZW |
19475 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
19476 | static const struct asm_cond conds[] = | |
19477 | { | |
19478 | {"eq", 0x0}, | |
19479 | {"ne", 0x1}, | |
19480 | {"cs", 0x2}, {"hs", 0x2}, | |
19481 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
19482 | {"mi", 0x4}, | |
19483 | {"pl", 0x5}, | |
19484 | {"vs", 0x6}, | |
19485 | {"vc", 0x7}, | |
19486 | {"hi", 0x8}, | |
19487 | {"ls", 0x9}, | |
19488 | {"ge", 0xa}, | |
19489 | {"lt", 0xb}, | |
19490 | {"gt", 0xc}, | |
19491 | {"le", 0xd}, | |
19492 | {"al", 0xe} | |
19493 | }; | |
bfae80f2 | 19494 | |
e797f7e0 | 19495 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
823d2571 TG |
19496 | { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \ |
19497 | { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) } | |
e797f7e0 | 19498 | |
62b3e311 PB |
19499 | static struct asm_barrier_opt barrier_opt_names[] = |
19500 | { | |
e797f7e0 MGD |
19501 | UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER), |
19502 | UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER), | |
19503 | UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8), | |
19504 | UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER), | |
19505 | UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER), | |
19506 | UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER), | |
19507 | UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER), | |
19508 | UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8), | |
19509 | UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER), | |
19510 | UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER), | |
19511 | UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER), | |
19512 | UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER), | |
19513 | UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8), | |
19514 | UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER), | |
19515 | UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER), | |
19516 | UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8) | |
62b3e311 PB |
19517 | }; |
19518 | ||
e797f7e0 MGD |
19519 | #undef UL_BARRIER |
19520 | ||
c19d1205 ZW |
19521 | /* Table of ARM-format instructions. */ |
19522 | ||
19523 | /* Macros for gluing together operand strings. N.B. In all cases | |
19524 | other than OPS0, the trailing OP_stop comes from default | |
19525 | zero-initialization of the unspecified elements of the array. */ | |
19526 | #define OPS0() { OP_stop, } | |
19527 | #define OPS1(a) { OP_##a, } | |
19528 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
19529 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
19530 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
19531 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
19532 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
19533 | ||
5be8be5d DG |
19534 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
19535 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
19536 | MIX_ARM_THUMB_OPERANDS macro. | |
19537 | In order to use these macros, prefix the number of operands with _ | |
19538 | e.g. _3. */ | |
19539 | #define OPS_1(a) { a, } | |
19540 | #define OPS_2(a,b) { a,b, } | |
19541 | #define OPS_3(a,b,c) { a,b,c, } | |
19542 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
19543 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
19544 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
19545 | ||
c19d1205 ZW |
19546 | /* These macros abstract out the exact format of the mnemonic table and |
19547 | save some repeated characters. */ | |
19548 | ||
19549 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
19550 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 19551 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 19552 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
19553 | |
19554 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
19555 | a T_MNEM_xyz enumerator. */ | |
19556 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 19557 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 19558 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 19559 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
19560 | |
19561 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
19562 | infix after the third character. */ | |
19563 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 19564 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 19565 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 19566 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 19567 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 19568 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 19569 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 19570 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 19571 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 19572 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 19573 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 19574 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 19575 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 19576 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 19577 | |
c19d1205 | 19578 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
19579 | field is still 0xE. Many of the Thumb variants can be executed |
19580 | conditionally, so this is checked separately. */ | |
c19d1205 | 19581 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 19582 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 19583 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 19584 | |
dd5181d5 KT |
19585 | /* Same as TUE but the encoding function for ARM and Thumb modes is the same. |
19586 | Used by mnemonics that have very minimal differences in the encoding for | |
19587 | ARM and Thumb variants and can be handled in a common function. */ | |
19588 | #define TUEc(mnem, op, top, nops, ops, en) \ | |
19589 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
19590 | THUMB_VARIANT, do_##en, do_##en } | |
19591 | ||
c19d1205 ZW |
19592 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM |
19593 | condition code field. */ | |
19594 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 19595 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 19596 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
19597 | |
19598 | /* ARM-only variants of all the above. */ | |
6a86118a | 19599 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 19600 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
19601 | |
19602 | #define C3(mnem, op, nops, ops, ae) \ | |
19603 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
19604 | ||
cf3cf39d TP |
19605 | /* Thumb-only variants of TCE and TUE. */ |
19606 | #define ToC(mnem, top, nops, ops, te) \ | |
19607 | { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \ | |
19608 | do_##te } | |
cf3cf39d TP |
19609 | |
19610 | #define ToU(mnem, top, nops, ops, te) \ | |
19611 | { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \ | |
19612 | NULL, do_##te } | |
cf3cf39d | 19613 | |
4389b29a AV |
19614 | /* T_MNEM_xyz enumerator variants of ToC. */ |
19615 | #define toC(mnem, top, nops, ops, te) \ | |
19616 | { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \ | |
19617 | do_##te } | |
19618 | ||
e3cb604e PB |
19619 | /* Legacy mnemonics that always have conditional infix after the third |
19620 | character. */ | |
19621 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19622 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
19623 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
19624 | ||
8f06b2d8 PB |
19625 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
19626 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19627 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 19628 | |
e3cb604e PB |
19629 | /* Legacy coprocessor instructions where conditional infix and conditional |
19630 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
19631 | not just the potentially ambiguous ones. */ | |
19632 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19633 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
19634 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
19635 | ||
19636 | /* Coprocessor, takes either a suffix or a position-3 infix | |
19637 | (for an FPA corner case). */ | |
19638 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 19639 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 19640 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 19641 | |
6a86118a | 19642 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
19643 | { m1 #m2 m3, OPS##nops ops, \ |
19644 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
19645 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
19646 | ||
19647 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
19648 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
19649 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
19650 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
19651 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
19652 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
19653 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
19654 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
19655 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
19656 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
19657 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
19658 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
19659 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
19660 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
19661 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
19662 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
19663 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
19664 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
19665 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
19666 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
19667 | |
19668 | #define UE(mnem, op, nops, ops, ae) \ | |
19669 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
19670 | ||
19671 | #define UF(mnem, op, nops, ops, ae) \ | |
19672 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
19673 | ||
5287ad62 JB |
19674 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
19675 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
19676 | use the same encoding function for each. */ | |
19677 | #define NUF(mnem, op, nops, ops, enc) \ | |
19678 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
19679 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
19680 | ||
19681 | /* Neon data processing, version which indirects through neon_enc_tab for | |
19682 | the various overloaded versions of opcodes. */ | |
19683 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 19684 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
19685 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
19686 | ||
19687 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
19688 | version. */ | |
037e8744 JB |
19689 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
19690 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
19691 | THUMB_VARIANT, do_##enc, do_##enc } |
19692 | ||
037e8744 | 19693 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 19694 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
19695 | |
19696 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 19697 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 19698 | |
5287ad62 | 19699 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 19700 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 19701 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
19702 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
19703 | ||
037e8744 | 19704 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 19705 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
19706 | |
19707 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 19708 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 19709 | |
c19d1205 ZW |
19710 | #define do_0 0 |
19711 | ||
c19d1205 | 19712 | static const struct asm_opcode insns[] = |
bfae80f2 | 19713 | { |
74db7efb NC |
19714 | #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */ |
19715 | #define THUMB_VARIANT & arm_ext_v4t | |
21d799b5 NC |
19716 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
19717 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
19718 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
19719 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
19720 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
19721 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
19722 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
19723 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
19724 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
19725 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
19726 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
19727 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
19728 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
19729 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
19730 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
19731 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
19732 | |
19733 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
19734 | for setting PSR flag bits. They are obsolete in V6 and do not | |
19735 | have Thumb equivalents. */ | |
21d799b5 NC |
19736 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
19737 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
19738 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
19739 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
19740 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
19741 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
19742 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
19743 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
19744 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
19745 | ||
19746 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
72d98d16 | 19747 | tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp), |
21d799b5 NC |
19748 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), |
19749 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
19750 | ||
19751 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
19752 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
19753 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
19754 | OP_RRnpc), | |
19755 | OP_ADDRGLDR),ldst, t_ldst), | |
19756 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
19757 | |
19758 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19759 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19760 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19761 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19762 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19763 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19764 | ||
21d799b5 NC |
19765 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), |
19766 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 19767 | |
c19d1205 | 19768 | /* Pseudo ops. */ |
21d799b5 | 19769 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 19770 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 19771 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
74db7efb | 19772 | tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf), |
c19d1205 ZW |
19773 | |
19774 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
19775 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
19776 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
19777 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
19778 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
19779 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
19780 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
19781 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
19782 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
19783 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
19784 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
19785 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
19786 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 19787 | |
16a4cf17 | 19788 | /* These may simplify to neg. */ |
21d799b5 NC |
19789 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
19790 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 19791 | |
173205ca TP |
19792 | #undef THUMB_VARIANT |
19793 | #define THUMB_VARIANT & arm_ext_os | |
19794 | ||
19795 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
19796 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
19797 | ||
c921be7d NC |
19798 | #undef THUMB_VARIANT |
19799 | #define THUMB_VARIANT & arm_ext_v6 | |
19800 | ||
21d799b5 | 19801 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
19802 | |
19803 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
19804 | #undef THUMB_VARIANT |
19805 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19806 | ||
21d799b5 NC |
19807 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
19808 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
19809 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 19810 | |
5be8be5d DG |
19811 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
19812 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
19813 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
19814 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 19815 | |
21d799b5 NC |
19816 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
19817 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 19818 | |
21d799b5 NC |
19819 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
19820 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
19821 | |
19822 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 19823 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
19824 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
19825 | ||
19826 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
19827 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
19828 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
19829 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
19830 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
19831 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
19832 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
19833 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
19834 | ||
c921be7d NC |
19835 | #undef ARM_VARIANT |
19836 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
19837 | #undef THUMB_VARIANT | |
19838 | #define THUMB_VARIANT & arm_ext_v4t | |
19839 | ||
21d799b5 NC |
19840 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
19841 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 19842 | |
c921be7d NC |
19843 | #undef THUMB_VARIANT |
19844 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19845 | ||
21d799b5 | 19846 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
19847 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
19848 | ||
19849 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
19850 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
19851 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19852 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19853 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19854 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19855 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 19856 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 19857 | |
c921be7d NC |
19858 | #undef ARM_VARIANT |
19859 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
19860 | ||
21d799b5 | 19861 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
19862 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
19863 | ||
c921be7d NC |
19864 | #undef ARM_VARIANT |
19865 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
19866 | #undef THUMB_VARIANT | |
19867 | #define THUMB_VARIANT & arm_ext_msr | |
19868 | ||
d2cd1205 JB |
19869 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
19870 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 19871 | |
c921be7d NC |
19872 | #undef ARM_VARIANT |
19873 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
19874 | #undef THUMB_VARIANT | |
19875 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19876 | ||
21d799b5 NC |
19877 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
19878 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
19879 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
19880 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
19881 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
19882 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
19883 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
19884 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 19885 | |
c921be7d NC |
19886 | #undef ARM_VARIANT |
19887 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
19888 | #undef THUMB_VARIANT | |
19889 | #define THUMB_VARIANT & arm_ext_v4t | |
19890 | ||
5be8be5d DG |
19891 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
19892 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
19893 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
19894 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
56c0a61f RE |
19895 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
19896 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 19897 | |
c921be7d NC |
19898 | #undef ARM_VARIANT |
19899 | #define ARM_VARIANT & arm_ext_v4t_5 | |
19900 | ||
c19d1205 ZW |
19901 | /* ARM Architecture 4T. */ |
19902 | /* Note: bx (and blx) are required on V5, even if the processor does | |
19903 | not support Thumb. */ | |
21d799b5 | 19904 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 19905 | |
c921be7d NC |
19906 | #undef ARM_VARIANT |
19907 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
19908 | #undef THUMB_VARIANT | |
19909 | #define THUMB_VARIANT & arm_ext_v5t | |
19910 | ||
c19d1205 ZW |
19911 | /* Note: blx has 2 variants; the .value coded here is for |
19912 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
19913 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
19914 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 19915 | |
c921be7d NC |
19916 | #undef THUMB_VARIANT |
19917 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19918 | ||
21d799b5 NC |
19919 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
19920 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19921 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19922 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19923 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19924 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
19925 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
19926 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 19927 | |
c921be7d | 19928 | #undef ARM_VARIANT |
74db7efb NC |
19929 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ |
19930 | #undef THUMB_VARIANT | |
19931 | #define THUMB_VARIANT & arm_ext_v5exp | |
c921be7d | 19932 | |
21d799b5 NC |
19933 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
19934 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
19935 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
19936 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 19937 | |
21d799b5 NC |
19938 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
19939 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 19940 | |
21d799b5 NC |
19941 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
19942 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
19943 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
19944 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 19945 | |
21d799b5 NC |
19946 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
19947 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19948 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19949 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 19950 | |
21d799b5 NC |
19951 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
19952 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 19953 | |
03ee1b7f NC |
19954 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
19955 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
19956 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
19957 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 19958 | |
c921be7d | 19959 | #undef ARM_VARIANT |
74db7efb NC |
19960 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ |
19961 | #undef THUMB_VARIANT | |
19962 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 19963 | |
21d799b5 | 19964 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
19965 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
19966 | ldrd, t_ldstd), | |
19967 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
19968 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 19969 | |
21d799b5 NC |
19970 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
19971 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 19972 | |
c921be7d NC |
19973 | #undef ARM_VARIANT |
19974 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
19975 | ||
21d799b5 | 19976 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 19977 | |
c921be7d NC |
19978 | #undef ARM_VARIANT |
19979 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
19980 | #undef THUMB_VARIANT | |
19981 | #define THUMB_VARIANT & arm_ext_v6 | |
19982 | ||
21d799b5 NC |
19983 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
19984 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
19985 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
19986 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
19987 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
19988 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19989 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19990 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19991 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19992 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 19993 | |
c921be7d | 19994 | #undef THUMB_VARIANT |
ff8646ee | 19995 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
c921be7d | 19996 | |
5be8be5d DG |
19997 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
19998 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
19999 | strex, t_strex), | |
ff8646ee TP |
20000 | #undef THUMB_VARIANT |
20001 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20002 | ||
21d799b5 NC |
20003 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
20004 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 20005 | |
21d799b5 NC |
20006 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
20007 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 20008 | |
9e3c6df6 | 20009 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
20010 | #undef THUMB_VARIANT |
20011 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 20012 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 20013 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
20014 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
20015 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
20016 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
20017 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
d709e4e6 RE |
20018 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
20019 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
20020 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 20021 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
20022 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
20023 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 20024 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 20025 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 20026 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 20027 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 20028 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 20029 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
941c9cad | 20030 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c921be7d | 20031 | |
9e3c6df6 PB |
20032 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
20033 | #undef THUMB_VARIANT | |
20034 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
20035 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
20036 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
20037 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20038 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20039 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20040 | /* Old name for QASX. */ |
74db7efb | 20041 | TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 20042 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20043 | /* Old name for QSAX. */ |
74db7efb | 20044 | TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20045 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20046 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20047 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20048 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20049 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20050 | /* Old name for SASX. */ |
74db7efb | 20051 | TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20052 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20053 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 20054 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20055 | /* Old name for SHASX. */ |
21d799b5 | 20056 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
74db7efb | 20057 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20058 | /* Old name for SHSAX. */ |
21d799b5 NC |
20059 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20060 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20061 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20062 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20063 | /* Old name for SSAX. */ |
74db7efb | 20064 | TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20065 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20066 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20067 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20068 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20069 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20070 | /* Old name for UASX. */ |
74db7efb | 20071 | TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20072 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20073 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 20074 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20075 | /* Old name for UHASX. */ |
21d799b5 NC |
20076 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20077 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20078 | /* Old name for UHSAX. */ |
21d799b5 NC |
20079 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20080 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20081 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20082 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20083 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 20084 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 20085 | /* Old name for UQASX. */ |
21d799b5 NC |
20086 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20087 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20088 | /* Old name for UQSAX. */ |
21d799b5 NC |
20089 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
20090 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20091 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20092 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20093 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 20094 | /* Old name for USAX. */ |
74db7efb | 20095 | TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 20096 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
20097 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
20098 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20099 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20100 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20101 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20102 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20103 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
20104 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
20105 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
20106 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20107 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20108 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20109 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20110 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20111 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20112 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20113 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
20114 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20115 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20116 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20117 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20118 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20119 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20120 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20121 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20122 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20123 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
20124 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
20125 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
20126 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
20127 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
20128 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 20129 | |
c921be7d | 20130 | #undef ARM_VARIANT |
55e8aae7 | 20131 | #define ARM_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 20132 | #undef THUMB_VARIANT |
55e8aae7 | 20133 | #define THUMB_VARIANT & arm_ext_v6k_v6t2 |
c921be7d | 20134 | |
21d799b5 NC |
20135 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
20136 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
20137 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
20138 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 20139 | |
c921be7d NC |
20140 | #undef THUMB_VARIANT |
20141 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
20142 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
20143 | ldrexd, t_ldrexd), | |
20144 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
20145 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 20146 | |
c921be7d | 20147 | #undef THUMB_VARIANT |
ff8646ee | 20148 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
5be8be5d DG |
20149 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
20150 | rd_rn, rd_rn), | |
20151 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
20152 | rd_rn, rd_rn), | |
20153 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
877807f8 | 20154 | strex, t_strexbh), |
5be8be5d | 20155 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 20156 | strex, t_strexbh), |
21d799b5 | 20157 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 20158 | |
c921be7d | 20159 | #undef ARM_VARIANT |
f4c65163 | 20160 | #define ARM_VARIANT & arm_ext_sec |
74db7efb | 20161 | #undef THUMB_VARIANT |
f4c65163 | 20162 | #define THUMB_VARIANT & arm_ext_sec |
c921be7d | 20163 | |
21d799b5 | 20164 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 20165 | |
90ec0d68 MGD |
20166 | #undef ARM_VARIANT |
20167 | #define ARM_VARIANT & arm_ext_virt | |
20168 | #undef THUMB_VARIANT | |
20169 | #define THUMB_VARIANT & arm_ext_virt | |
20170 | ||
20171 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
20172 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
20173 | ||
ddfded2f MW |
20174 | #undef ARM_VARIANT |
20175 | #define ARM_VARIANT & arm_ext_pan | |
20176 | #undef THUMB_VARIANT | |
20177 | #define THUMB_VARIANT & arm_ext_pan | |
20178 | ||
20179 | TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan), | |
20180 | ||
c921be7d | 20181 | #undef ARM_VARIANT |
74db7efb | 20182 | #define ARM_VARIANT & arm_ext_v6t2 |
f4c65163 MGD |
20183 | #undef THUMB_VARIANT |
20184 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 20185 | |
21d799b5 NC |
20186 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
20187 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
20188 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
20189 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 20190 | |
21d799b5 | 20191 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
21d799b5 | 20192 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 | 20193 | |
5be8be5d DG |
20194 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
20195 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
20196 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
20197 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 20198 | |
91d8b670 JG |
20199 | #undef ARM_VARIANT |
20200 | #define ARM_VARIANT & arm_ext_v3 | |
20201 | #undef THUMB_VARIANT | |
20202 | #define THUMB_VARIANT & arm_ext_v6t2 | |
20203 | ||
20204 | TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb), | |
c597cc3d SD |
20205 | TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb), |
20206 | TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb), | |
91d8b670 JG |
20207 | |
20208 | #undef ARM_VARIANT | |
20209 | #define ARM_VARIANT & arm_ext_v6t2 | |
ff8646ee TP |
20210 | #undef THUMB_VARIANT |
20211 | #define THUMB_VARIANT & arm_ext_v6t2_v8m | |
20212 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
20213 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
20214 | ||
bf3eeda7 | 20215 | /* Thumb-only instructions. */ |
74db7efb | 20216 | #undef ARM_VARIANT |
bf3eeda7 NS |
20217 | #define ARM_VARIANT NULL |
20218 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
20219 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
20220 | |
20221 | /* ARM does not really have an IT instruction, so always allow it. | |
20222 | The opcode is copied from Thumb in order to allow warnings in | |
20223 | -mimplicit-it=[never | arm] modes. */ | |
20224 | #undef ARM_VARIANT | |
20225 | #define ARM_VARIANT & arm_ext_v1 | |
ff8646ee TP |
20226 | #undef THUMB_VARIANT |
20227 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 20228 | |
21d799b5 NC |
20229 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
20230 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
20231 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
20232 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
20233 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
20234 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
20235 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
20236 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
20237 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
20238 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
20239 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
20240 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
20241 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
20242 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
20243 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 20244 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
20245 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
20246 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 20247 | |
92e90b6e | 20248 | /* Thumb2 only instructions. */ |
c921be7d NC |
20249 | #undef ARM_VARIANT |
20250 | #define ARM_VARIANT NULL | |
92e90b6e | 20251 | |
21d799b5 NC |
20252 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
20253 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
20254 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
20255 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
20256 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
20257 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 20258 | |
eea54501 MGD |
20259 | /* Hardware division instructions. */ |
20260 | #undef ARM_VARIANT | |
20261 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
20262 | #undef THUMB_VARIANT |
20263 | #define THUMB_VARIANT & arm_ext_div | |
20264 | ||
eea54501 MGD |
20265 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
20266 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 20267 | |
7e806470 | 20268 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
20269 | #undef ARM_VARIANT |
20270 | #define ARM_VARIANT & arm_ext_barrier | |
20271 | #undef THUMB_VARIANT | |
20272 | #define THUMB_VARIANT & arm_ext_barrier | |
20273 | ||
ccb84d65 JB |
20274 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier), |
20275 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier), | |
20276 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier), | |
7e806470 | 20277 | |
62b3e311 | 20278 | /* ARM V7 instructions. */ |
c921be7d NC |
20279 | #undef ARM_VARIANT |
20280 | #define ARM_VARIANT & arm_ext_v7 | |
20281 | #undef THUMB_VARIANT | |
20282 | #define THUMB_VARIANT & arm_ext_v7 | |
20283 | ||
21d799b5 NC |
20284 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
20285 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 20286 | |
74db7efb | 20287 | #undef ARM_VARIANT |
60e5ef9f | 20288 | #define ARM_VARIANT & arm_ext_mp |
74db7efb | 20289 | #undef THUMB_VARIANT |
60e5ef9f MGD |
20290 | #define THUMB_VARIANT & arm_ext_mp |
20291 | ||
20292 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
20293 | ||
53c4b28b MGD |
20294 | /* AArchv8 instructions. */ |
20295 | #undef ARM_VARIANT | |
20296 | #define ARM_VARIANT & arm_ext_v8 | |
4ed7ed8d TP |
20297 | |
20298 | /* Instructions shared between armv8-a and armv8-m. */ | |
53c4b28b | 20299 | #undef THUMB_VARIANT |
4ed7ed8d | 20300 | #define THUMB_VARIANT & arm_ext_atomics |
53c4b28b | 20301 | |
4ed7ed8d TP |
20302 | TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
20303 | TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
20304 | TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
20305 | TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
20306 | TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
20307 | TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
4b8c8c02 | 20308 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
4b8c8c02 RE |
20309 | TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn), |
20310 | TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
20311 | TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb), | |
20312 | stlex, t_stlex), | |
4b8c8c02 RE |
20313 | TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb), |
20314 | stlex, t_stlex), | |
20315 | TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb), | |
20316 | stlex, t_stlex), | |
4ed7ed8d TP |
20317 | #undef THUMB_VARIANT |
20318 | #define THUMB_VARIANT & arm_ext_v8 | |
53c4b28b | 20319 | |
4ed7ed8d | 20320 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), |
4ed7ed8d TP |
20321 | TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb), |
20322 | ldrexd, t_ldrexd), | |
20323 | TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), | |
20324 | strexd, t_strexd), | |
f7dd2fb2 TC |
20325 | |
20326 | /* Defined in V8 but is in undefined encoding space for earlier | |
20327 | architectures. However earlier architectures are required to treat | |
20328 | this instuction as a semihosting trap as well. Hence while not explicitly | |
20329 | defined as such, it is in fact correct to define the instruction for all | |
20330 | architectures. */ | |
20331 | #undef THUMB_VARIANT | |
20332 | #define THUMB_VARIANT & arm_ext_v1 | |
20333 | #undef ARM_VARIANT | |
20334 | #define ARM_VARIANT & arm_ext_v1 | |
20335 | TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt), | |
20336 | ||
8884b720 | 20337 | /* ARMv8 T32 only. */ |
74db7efb | 20338 | #undef ARM_VARIANT |
b79f7053 MGD |
20339 | #define ARM_VARIANT NULL |
20340 | TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs), | |
20341 | TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs), | |
20342 | TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs), | |
20343 | ||
33399f07 MGD |
20344 | /* FP for ARMv8. */ |
20345 | #undef ARM_VARIANT | |
a715796b | 20346 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 | 20347 | #undef THUMB_VARIANT |
a715796b | 20348 | #define THUMB_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 MGD |
20349 | |
20350 | nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel), | |
20351 | nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel), | |
20352 | nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel), | |
20353 | nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel), | |
73924fbc MGD |
20354 | nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), |
20355 | nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), | |
7e8e6784 MGD |
20356 | nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta), |
20357 | nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn), | |
20358 | nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp), | |
20359 | nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm), | |
30bdf752 MGD |
20360 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
20361 | nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz), | |
20362 | nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx), | |
20363 | nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta), | |
20364 | nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn), | |
20365 | nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp), | |
20366 | nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm), | |
33399f07 | 20367 | |
91ff7894 MGD |
20368 | /* Crypto v1 extensions. */ |
20369 | #undef ARM_VARIANT | |
20370 | #define ARM_VARIANT & fpu_crypto_ext_armv8 | |
20371 | #undef THUMB_VARIANT | |
20372 | #define THUMB_VARIANT & fpu_crypto_ext_armv8 | |
20373 | ||
20374 | nUF(aese, _aes, 2, (RNQ, RNQ), aese), | |
20375 | nUF(aesd, _aes, 2, (RNQ, RNQ), aesd), | |
20376 | nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc), | |
20377 | nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc), | |
48adcd8e MGD |
20378 | nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c), |
20379 | nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p), | |
20380 | nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m), | |
20381 | nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0), | |
20382 | nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h), | |
20383 | nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2), | |
20384 | nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1), | |
3c9017d2 MGD |
20385 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
20386 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
20387 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 20388 | |
dd5181d5 | 20389 | #undef ARM_VARIANT |
74db7efb | 20390 | #define ARM_VARIANT & crc_ext_armv8 |
dd5181d5 KT |
20391 | #undef THUMB_VARIANT |
20392 | #define THUMB_VARIANT & crc_ext_armv8 | |
20393 | TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b), | |
20394 | TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h), | |
20395 | TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w), | |
20396 | TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb), | |
20397 | TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch), | |
20398 | TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw), | |
20399 | ||
105bde57 MW |
20400 | /* ARMv8.2 RAS extension. */ |
20401 | #undef ARM_VARIANT | |
4d1464f2 | 20402 | #define ARM_VARIANT & arm_ext_ras |
105bde57 | 20403 | #undef THUMB_VARIANT |
4d1464f2 | 20404 | #define THUMB_VARIANT & arm_ext_ras |
105bde57 MW |
20405 | TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs), |
20406 | ||
49e8a725 SN |
20407 | #undef ARM_VARIANT |
20408 | #define ARM_VARIANT & arm_ext_v8_3 | |
20409 | #undef THUMB_VARIANT | |
20410 | #define THUMB_VARIANT & arm_ext_v8_3 | |
20411 | NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt), | |
c28eeff2 SN |
20412 | NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla), |
20413 | NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd), | |
49e8a725 | 20414 | |
c604a79a JW |
20415 | #undef ARM_VARIANT |
20416 | #define ARM_VARIANT & fpu_neon_ext_dotprod | |
20417 | #undef THUMB_VARIANT | |
20418 | #define THUMB_VARIANT & fpu_neon_ext_dotprod | |
20419 | NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s), | |
20420 | NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u), | |
20421 | ||
c921be7d NC |
20422 | #undef ARM_VARIANT |
20423 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
20424 | #undef THUMB_VARIANT |
20425 | #define THUMB_VARIANT NULL | |
c921be7d | 20426 | |
21d799b5 NC |
20427 | cCE("wfs", e200110, 1, (RR), rd), |
20428 | cCE("rfs", e300110, 1, (RR), rd), | |
20429 | cCE("wfc", e400110, 1, (RR), rd), | |
20430 | cCE("rfc", e500110, 1, (RR), rd), | |
20431 | ||
20432 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20433 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20434 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20435 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20436 | ||
20437 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20438 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20439 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20440 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
20441 | ||
20442 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
20443 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
20444 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
20445 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
20446 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
20447 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
20448 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
20449 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
20450 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
20451 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
20452 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
20453 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
20454 | ||
20455 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
20456 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
20457 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
20458 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
20459 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
20460 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
20461 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
20462 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
20463 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
20464 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
20465 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
20466 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
20467 | ||
20468 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
20469 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
20470 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
20471 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
20472 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
20473 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
20474 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
20475 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
20476 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
20477 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
20478 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
20479 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
20480 | ||
20481 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
20482 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
20483 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
20484 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
20485 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
20486 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
20487 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
20488 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
20489 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
20490 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
20491 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
20492 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
20493 | ||
20494 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
20495 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
20496 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
20497 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
20498 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
20499 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
20500 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
20501 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
20502 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
20503 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
20504 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
20505 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
20506 | ||
20507 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
20508 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
20509 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
20510 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
20511 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
20512 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
20513 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
20514 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
20515 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
20516 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
20517 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
20518 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
20519 | ||
20520 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
20521 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
20522 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
20523 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
20524 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
20525 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
20526 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
20527 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
20528 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
20529 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
20530 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
20531 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
20532 | ||
20533 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
20534 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
20535 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
20536 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
20537 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
20538 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
20539 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
20540 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
20541 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
20542 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
20543 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
20544 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
20545 | ||
20546 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
20547 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
20548 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
20549 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
20550 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
20551 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
20552 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
20553 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
20554 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
20555 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
20556 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
20557 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
20558 | ||
20559 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
20560 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
20561 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
20562 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
20563 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
20564 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
20565 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
20566 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
20567 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
20568 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
20569 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
20570 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
20571 | ||
20572 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
20573 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
20574 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
20575 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
20576 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
20577 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
20578 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
20579 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
20580 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
20581 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
20582 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
20583 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
20584 | ||
20585 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
20586 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
20587 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
20588 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
20589 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
20590 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
20591 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
20592 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
20593 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
20594 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
20595 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
20596 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
20597 | ||
20598 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
20599 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
20600 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
20601 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
20602 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
20603 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
20604 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
20605 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
20606 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
20607 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
20608 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
20609 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
20610 | ||
20611 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
20612 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
20613 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
20614 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
20615 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
20616 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
20617 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
20618 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
20619 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
20620 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
20621 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
20622 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
20623 | ||
20624 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
20625 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
20626 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
20627 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
20628 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
20629 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
20630 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
20631 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
20632 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
20633 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
20634 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
20635 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
20636 | ||
20637 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
20638 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
20639 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
20640 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
20641 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
20642 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
20643 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
20644 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
20645 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
20646 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
20647 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
20648 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
20649 | ||
20650 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20651 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20652 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20653 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20654 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20655 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20656 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20657 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20658 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20659 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20660 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20661 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20662 | ||
20663 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20664 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20665 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20666 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20667 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20668 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20669 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20670 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20671 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20672 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20673 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20674 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20675 | ||
20676 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20677 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20678 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20679 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20680 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20681 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20682 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20683 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20684 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20685 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20686 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20687 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20688 | ||
20689 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20690 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20691 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20692 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20693 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20694 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20695 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20696 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20697 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20698 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20699 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20700 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20701 | ||
20702 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20703 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20704 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20705 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20706 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20707 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20708 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20709 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20710 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20711 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20712 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20713 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20714 | ||
20715 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20716 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20717 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20718 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20719 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20720 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20721 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20722 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20723 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20724 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20725 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20726 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20727 | ||
20728 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20729 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20730 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20731 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20732 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20733 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20734 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20735 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20736 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20737 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20738 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20739 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20740 | ||
20741 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20742 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20743 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20744 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20745 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20746 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20747 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20748 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20749 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20750 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20751 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20752 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20753 | ||
20754 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20755 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20756 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20757 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20758 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20759 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20760 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20761 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20762 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20763 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20764 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20765 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20766 | ||
20767 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20768 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20769 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20770 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20771 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20772 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20773 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20774 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20775 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20776 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20777 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20778 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20779 | ||
20780 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20781 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20782 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20783 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20784 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20785 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20786 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20787 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20788 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20789 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20790 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20791 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20792 | ||
20793 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20794 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20795 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20796 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20797 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20798 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20799 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20800 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20801 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20802 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20803 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20804 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20805 | ||
20806 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20807 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20808 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20809 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20810 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20811 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20812 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20813 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20814 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20815 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20816 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20817 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20818 | ||
20819 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
20820 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
20821 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
20822 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
20823 | ||
20824 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
20825 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
20826 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
20827 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
20828 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
20829 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
20830 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
20831 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
20832 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
20833 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
20834 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
20835 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 20836 | |
c19d1205 ZW |
20837 | /* The implementation of the FIX instruction is broken on some |
20838 | assemblers, in that it accepts a precision specifier as well as a | |
20839 | rounding specifier, despite the fact that this is meaningless. | |
20840 | To be more compatible, we accept it as well, though of course it | |
20841 | does not set any bits. */ | |
21d799b5 NC |
20842 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
20843 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
20844 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
20845 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
20846 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
20847 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
20848 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
20849 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
20850 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
20851 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
20852 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
20853 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
20854 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 20855 | |
c19d1205 | 20856 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
20857 | #undef ARM_VARIANT |
20858 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
20859 | ||
21d799b5 NC |
20860 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
20861 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20862 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20863 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20864 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20865 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 20866 | |
c921be7d NC |
20867 | #undef ARM_VARIANT |
20868 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
20869 | ||
c19d1205 | 20870 | /* Moves and type conversions. */ |
21d799b5 NC |
20871 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
20872 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
20873 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
20874 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
7465e07a NC |
20875 | cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs), |
20876 | cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr), | |
21d799b5 NC |
20877 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), |
20878 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20879 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20880 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
20881 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20882 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
20883 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
20884 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
20885 | |
20886 | /* Memory operations. */ | |
21d799b5 NC |
20887 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
20888 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
20889 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
20890 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
20891 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20892 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20893 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20894 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20895 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
20896 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
20897 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
20898 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
20899 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20900 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20901 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20902 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20903 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
20904 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 20905 | |
c19d1205 | 20906 | /* Monadic operations. */ |
21d799b5 NC |
20907 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
20908 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20909 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
20910 | |
20911 | /* Dyadic operations. */ | |
21d799b5 NC |
20912 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
20913 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20914 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20915 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20916 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20917 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20918 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20919 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20920 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 20921 | |
c19d1205 | 20922 | /* Comparisons. */ |
21d799b5 NC |
20923 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
20924 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
20925 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
20926 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 20927 | |
62f3b8c8 PB |
20928 | /* Double precision load/store are still present on single precision |
20929 | implementations. */ | |
20930 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
20931 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
20932 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
20933 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
20934 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
20935 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
20936 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
20937 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
20938 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
20939 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 20940 | |
c921be7d NC |
20941 | #undef ARM_VARIANT |
20942 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
20943 | ||
c19d1205 | 20944 | /* Moves and type conversions. */ |
21d799b5 NC |
20945 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
20946 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
20947 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20948 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
20949 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
20950 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
20951 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
20952 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
20953 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
20954 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20955 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20956 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20957 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 20958 | |
c19d1205 | 20959 | /* Monadic operations. */ |
21d799b5 NC |
20960 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
20961 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
20962 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
20963 | |
20964 | /* Dyadic operations. */ | |
21d799b5 NC |
20965 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
20966 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20967 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20968 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20969 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20970 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20971 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20972 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20973 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 20974 | |
c19d1205 | 20975 | /* Comparisons. */ |
21d799b5 NC |
20976 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
20977 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
20978 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
20979 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 20980 | |
c921be7d NC |
20981 | #undef ARM_VARIANT |
20982 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
20983 | ||
21d799b5 NC |
20984 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
20985 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
20986 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
20987 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 20988 | |
037e8744 JB |
20989 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
20990 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
20991 | #undef ARM_VARIANT |
20992 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
20993 | #undef THUMB_VARIANT | |
20994 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
20995 | ||
037e8744 JB |
20996 | /* These mnemonics are unique to VFP. */ |
20997 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
20998 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
20999 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
21000 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
21001 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
aacf0b33 KT |
21002 | nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), |
21003 | nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), | |
037e8744 JB |
21004 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
21005 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
21006 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
21007 | ||
21008 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
21009 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
21010 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
21011 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 21012 | |
21d799b5 NC |
21013 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
21014 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
21015 | |
21016 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
21017 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
21018 | ||
55881a11 MGD |
21019 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
21020 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21021 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21022 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21023 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
21024 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
21025 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
21026 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 | 21027 | |
5f1af56b | 21028 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt), |
e3e535bc | 21029 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
c70a8987 MGD |
21030 | NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb), |
21031 | NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt), | |
f31fef98 | 21032 | |
037e8744 JB |
21033 | |
21034 | /* NOTE: All VMOV encoding is special-cased! */ | |
21035 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
21036 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
21037 | ||
9db2f6b4 RL |
21038 | #undef ARM_VARIANT |
21039 | #define ARM_VARIANT & arm_ext_fp16 | |
21040 | #undef THUMB_VARIANT | |
21041 | #define THUMB_VARIANT & arm_ext_fp16 | |
21042 | /* New instructions added from v8.2, allowing the extraction and insertion of | |
21043 | the upper 16 bits of a 32-bit vector register. */ | |
21044 | NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf), | |
21045 | NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf), | |
21046 | ||
dec41383 JW |
21047 | /* New backported fma/fms instructions optional in v8.2. */ |
21048 | NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal), | |
21049 | NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl), | |
21050 | ||
c921be7d NC |
21051 | #undef THUMB_VARIANT |
21052 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
21053 | #undef ARM_VARIANT | |
21054 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
21055 | ||
5287ad62 JB |
21056 | /* Data processing with three registers of the same length. */ |
21057 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
21058 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
21059 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
21060 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
21061 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
21062 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
21063 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
21064 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
21065 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
21066 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21067 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
21068 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
21069 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
21070 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
21071 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
21072 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
21073 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
21074 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
21075 | /* If not immediate, fall back to neon_dyadic_i64_su. |
21076 | shl_imm should accept I8 I16 I32 I64, | |
21077 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
21078 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
21079 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
21080 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
21081 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 21082 | /* Logic ops, types optional & ignored. */ |
4316f0d2 DG |
21083 | nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), |
21084 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21085 | nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
21086 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21087 | nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
21088 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21089 | nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
21090 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
21091 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
21092 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
21093 | /* Bitfield ops, untyped. */ |
21094 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
21095 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
21096 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
21097 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
21098 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
21099 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
cc933301 | 21100 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */ |
21d799b5 NC |
21101 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
21102 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
21103 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
21104 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
21105 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
21106 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
21107 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
21108 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
21109 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
21110 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
21111 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
21112 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
21113 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
21114 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
21115 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
21116 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 21117 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
21118 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
21119 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 21120 | /* As above, D registers only. */ |
21d799b5 NC |
21121 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
21122 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 21123 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
21124 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
21125 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
21126 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 21127 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
21128 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
21129 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
21130 | /* vtst takes sizes 8, 16, 32. */ |
21131 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
21132 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
21133 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 21134 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 21135 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
21136 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
21137 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
21138 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
21139 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
21140 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
21141 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
21142 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
21143 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
21144 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
21145 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
21146 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
21147 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
21148 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
21149 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
21150 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
21151 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
d6b4b13e | 21152 | /* ARM v8.1 extension. */ |
643afb90 MW |
21153 | nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), |
21154 | nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
21155 | nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), | |
21156 | nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
5287ad62 JB |
21157 | |
21158 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 21159 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
21160 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
21161 | ||
21162 | /* Data processing with two registers and a shift amount. */ | |
21163 | /* Right shifts, and variants with rounding. | |
21164 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21165 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
21166 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
21167 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
21168 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
21169 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
21170 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
21171 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
21172 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
21173 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
21174 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
21175 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
21176 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
21177 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
21178 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21179 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
21180 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
21181 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
21182 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
21183 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
21184 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
21185 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
21186 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
21187 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
21188 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
21189 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
21190 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
21191 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 21192 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 21193 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 21194 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 21195 | |
4316f0d2 DG |
21196 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn), |
21197 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), | |
5287ad62 JB |
21198 | |
21199 | /* Data processing, three registers of different lengths. */ | |
21200 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
21201 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
21202 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
21203 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
21204 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
21205 | /* If not scalar, fall back to neon_dyadic_long. | |
21206 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
21207 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
21208 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
21209 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
21210 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
21211 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
21212 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
21213 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21214 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21215 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21216 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
21217 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
21218 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
21219 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
21220 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
21221 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
21222 | S16 S32 U16 U32. */ | |
21d799b5 | 21223 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
21224 | |
21225 | /* Extract. Size 8. */ | |
3b8d421e PB |
21226 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
21227 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
21228 | |
21229 | /* Two registers, miscellaneous. */ | |
21230 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
21231 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
21232 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
21233 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
21234 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
21235 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
21236 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
21237 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
21238 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
21239 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
21240 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
21241 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
21242 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 21243 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 21244 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 21245 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 21246 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 21247 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
21248 | /* VZIP / VUZP. Sizes 8 16 32. */ |
21249 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
21250 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
21251 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
21252 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
21253 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
21254 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
21255 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
21256 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
21257 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
21258 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
21259 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
21260 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
21261 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
21262 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
cc933301 | 21263 | /* Reciprocal estimates. Types U32 F16 F32. */ |
5287ad62 JB |
21264 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), |
21265 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
21266 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
21267 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
21268 | /* VCLS. Types S8 S16 S32. */ | |
21269 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
21270 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
21271 | /* VCLZ. Types I8 I16 I32. */ | |
21272 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
21273 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
21274 | /* VCNT. Size 8. */ | |
21275 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
21276 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
21277 | /* Two address, untyped. */ | |
21278 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
21279 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
21280 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
21281 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
21282 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
21283 | |
21284 | /* Table lookup. Size 8. */ | |
21285 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
21286 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
21287 | ||
c921be7d NC |
21288 | #undef THUMB_VARIANT |
21289 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
21290 | #undef ARM_VARIANT | |
21291 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
21292 | ||
5287ad62 | 21293 | /* Neon element/structure load/store. */ |
21d799b5 NC |
21294 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
21295 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21296 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21297 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21298 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21299 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21300 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
21301 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 21302 | |
c921be7d | 21303 | #undef THUMB_VARIANT |
74db7efb NC |
21304 | #define THUMB_VARIANT & fpu_vfp_ext_v3xd |
21305 | #undef ARM_VARIANT | |
21306 | #define ARM_VARIANT & fpu_vfp_ext_v3xd | |
62f3b8c8 PB |
21307 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), |
21308 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21309 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21310 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21311 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21312 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21313 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21314 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
21315 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
21316 | ||
74db7efb | 21317 | #undef THUMB_VARIANT |
c921be7d NC |
21318 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
21319 | #undef ARM_VARIANT | |
21320 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
21321 | ||
21d799b5 | 21322 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 21323 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21324 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 21325 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21326 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 21327 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21328 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 21329 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 21330 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 21331 | |
74db7efb NC |
21332 | #undef ARM_VARIANT |
21333 | #define ARM_VARIANT & fpu_vfp_ext_fma | |
21334 | #undef THUMB_VARIANT | |
21335 | #define THUMB_VARIANT & fpu_vfp_ext_fma | |
62f3b8c8 PB |
21336 | /* Mnemonics shared by Neon and VFP. These are included in the |
21337 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
21338 | FMA instructions. */ | |
21339 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
21340 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
21341 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
21342 | the v form should always be used. */ | |
21343 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21344 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
21345 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21346 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
21347 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
21348 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
21349 | ||
5287ad62 | 21350 | #undef THUMB_VARIANT |
c921be7d NC |
21351 | #undef ARM_VARIANT |
21352 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
21353 | ||
21d799b5 NC |
21354 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
21355 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21356 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21357 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21358 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21359 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
21360 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
21361 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 21362 | |
c921be7d NC |
21363 | #undef ARM_VARIANT |
21364 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
21365 | ||
21d799b5 NC |
21366 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
21367 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
21368 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
21369 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
21370 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
21371 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
21372 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
21373 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
21374 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
74db7efb NC |
21375 | cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), |
21376 | cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21377 | cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21378 | cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21379 | cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21380 | cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21d799b5 NC |
21381 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), |
21382 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
21383 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
21384 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
21385 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
21386 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21387 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21388 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21389 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21390 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
21391 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
74db7efb NC |
21392 | cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn), |
21393 | cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn), | |
21394 | cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn), | |
21d799b5 NC |
21395 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), |
21396 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
21397 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
21398 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
21399 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
21400 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
21401 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
21402 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
21403 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21404 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21405 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21406 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21407 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21408 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21409 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21410 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21411 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21412 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
74db7efb NC |
21413 | cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21414 | cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21415 | cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21416 | cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
21417 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21418 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21419 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21420 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21421 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21422 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21423 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21424 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21425 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
21426 | cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21427 | cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21428 | cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21429 | cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21430 | cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21431 | cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
21432 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), |
21433 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
21434 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
21435 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
21436 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21437 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21438 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21439 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21440 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21441 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21442 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21443 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21444 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21445 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21446 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21447 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21448 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21449 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21450 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21451 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21452 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21453 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21454 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
21455 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21456 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21457 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21458 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21459 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
21460 | cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
21461 | cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21462 | cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21463 | cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21464 | cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21465 | cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
21466 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
21467 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21468 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21469 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21470 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21471 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21472 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21473 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21474 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21475 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21476 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
21477 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21478 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21479 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21480 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21481 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21482 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21483 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21484 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21485 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21486 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21487 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21488 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21489 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21490 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21491 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21492 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21493 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
21494 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
21495 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
21496 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
21497 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
21498 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
21499 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21500 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21501 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21502 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21503 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21504 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21505 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21506 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21507 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21508 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
21509 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
21510 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
21511 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
21512 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
21513 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
21514 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21515 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21516 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21517 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
21518 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
21519 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
21520 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
21521 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
21522 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
21523 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21524 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21525 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21526 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21527 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 21528 | |
c921be7d NC |
21529 | #undef ARM_VARIANT |
21530 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
21531 | ||
21d799b5 NC |
21532 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
21533 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
21534 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
21535 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
21536 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
21537 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
21538 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21539 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21540 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21541 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21542 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21543 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21544 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21545 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21546 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21547 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21548 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21549 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21550 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21551 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21552 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
21553 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21554 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21555 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21556 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21557 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21558 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21559 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21560 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21561 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21562 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21563 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21564 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21565 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21566 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21567 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21568 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21569 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21570 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21571 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21572 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21573 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21574 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21575 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21576 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21577 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21578 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21579 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21580 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21581 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21582 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21583 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21584 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21585 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21586 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21587 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21588 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 21589 | |
c921be7d NC |
21590 | #undef ARM_VARIANT |
21591 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
21592 | ||
21d799b5 NC |
21593 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
21594 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
21595 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
21596 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
21597 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
21598 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
21599 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
21600 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
21601 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
21602 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
21603 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
21604 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
21605 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
21606 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
74db7efb NC |
21607 | cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd), |
21608 | cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn), | |
21609 | cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd), | |
21610 | cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn), | |
21611 | cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn), | |
21612 | cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn), | |
21613 | cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn), | |
21614 | cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn), | |
21615 | cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn), | |
21616 | cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn), | |
21d799b5 NC |
21617 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), |
21618 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
21619 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
21620 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
74db7efb NC |
21621 | cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc), |
21622 | cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd), | |
21d799b5 NC |
21623 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), |
21624 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
21625 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
21626 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
74db7efb NC |
21627 | cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn), |
21628 | cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn), | |
21629 | cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn), | |
21630 | cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn), | |
21631 | cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn), | |
21632 | cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn), | |
21d799b5 NC |
21633 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), |
21634 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
74db7efb NC |
21635 | cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple), |
21636 | cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
21d799b5 NC |
21637 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), |
21638 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
21639 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
21640 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
21641 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
21642 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
21643 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
21644 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
21645 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
21646 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
21647 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
21648 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
21649 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
21650 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
21651 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
21652 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
21653 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
21654 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
21655 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
21656 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
21657 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
21658 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
21659 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
21660 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
21661 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
21662 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
21663 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
21664 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
74db7efb NC |
21665 | cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), |
21666 | cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
21d799b5 NC |
21667 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), |
21668 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
4ed7ed8d | 21669 | |
7fadb25d SD |
21670 | /* ARMv8.5-A instructions. */ |
21671 | #undef ARM_VARIANT | |
21672 | #define ARM_VARIANT & arm_ext_sb | |
21673 | #undef THUMB_VARIANT | |
21674 | #define THUMB_VARIANT & arm_ext_sb | |
21675 | TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs), | |
21676 | ||
dad0c3bf SD |
21677 | #undef ARM_VARIANT |
21678 | #define ARM_VARIANT & arm_ext_predres | |
21679 | #undef THUMB_VARIANT | |
21680 | #define THUMB_VARIANT & arm_ext_predres | |
21681 | CE("cfprctx", e070f93, 1, (RRnpc), rd), | |
21682 | CE("dvprctx", e070fb3, 1, (RRnpc), rd), | |
21683 | CE("cpprctx", e070ff3, 1, (RRnpc), rd), | |
21684 | ||
16a1fa25 | 21685 | /* ARMv8-M instructions. */ |
4ed7ed8d TP |
21686 | #undef ARM_VARIANT |
21687 | #define ARM_VARIANT NULL | |
21688 | #undef THUMB_VARIANT | |
21689 | #define THUMB_VARIANT & arm_ext_v8m | |
cf3cf39d TP |
21690 | ToU("sg", e97fe97f, 0, (), noargs), |
21691 | ToC("blxns", 4784, 1, (RRnpc), t_blx), | |
21692 | ToC("bxns", 4704, 1, (RRnpc), t_bx), | |
21693 | ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt), | |
21694 | ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt), | |
21695 | ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt), | |
21696 | ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt), | |
16a1fa25 TP |
21697 | |
21698 | /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the | |
21699 | instructions behave as nop if no VFP is present. */ | |
21700 | #undef THUMB_VARIANT | |
21701 | #define THUMB_VARIANT & arm_ext_v8m_main | |
cf3cf39d TP |
21702 | ToC("vlldm", ec300a00, 1, (RRnpc), rn), |
21703 | ToC("vlstm", ec200a00, 1, (RRnpc), rn), | |
4389b29a AV |
21704 | |
21705 | /* Armv8.1-M Mainline instructions. */ | |
21706 | #undef THUMB_VARIANT | |
21707 | #define THUMB_VARIANT & arm_ext_v8_1m_main | |
21708 | toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future), | |
f1c7f421 | 21709 | toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future), |
65d1bc05 | 21710 | toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future), |
f1c7f421 | 21711 | toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future), |
c19d1205 ZW |
21712 | }; |
21713 | #undef ARM_VARIANT | |
21714 | #undef THUMB_VARIANT | |
21715 | #undef TCE | |
c19d1205 ZW |
21716 | #undef TUE |
21717 | #undef TUF | |
21718 | #undef TCC | |
8f06b2d8 | 21719 | #undef cCE |
e3cb604e PB |
21720 | #undef cCL |
21721 | #undef C3E | |
4389b29a | 21722 | #undef C3 |
c19d1205 ZW |
21723 | #undef CE |
21724 | #undef CM | |
4389b29a | 21725 | #undef CL |
c19d1205 ZW |
21726 | #undef UE |
21727 | #undef UF | |
21728 | #undef UT | |
5287ad62 JB |
21729 | #undef NUF |
21730 | #undef nUF | |
21731 | #undef NCE | |
21732 | #undef nCE | |
c19d1205 ZW |
21733 | #undef OPS0 |
21734 | #undef OPS1 | |
21735 | #undef OPS2 | |
21736 | #undef OPS3 | |
21737 | #undef OPS4 | |
21738 | #undef OPS5 | |
21739 | #undef OPS6 | |
21740 | #undef do_0 | |
4389b29a AV |
21741 | #undef ToC |
21742 | #undef toC | |
21743 | #undef ToU | |
c19d1205 ZW |
21744 | \f |
21745 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 21746 | |
c19d1205 ZW |
21747 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
21748 | for use in the a.out file, and stores them in the array pointed to by buf. | |
21749 | This knows about the endian-ness of the target machine and does | |
21750 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
21751 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
21752 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 21753 | |
c19d1205 ZW |
21754 | void |
21755 | md_number_to_chars (char * buf, valueT val, int n) | |
21756 | { | |
21757 | if (target_big_endian) | |
21758 | number_to_chars_bigendian (buf, val, n); | |
21759 | else | |
21760 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
21761 | } |
21762 | ||
c19d1205 ZW |
21763 | static valueT |
21764 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 21765 | { |
c19d1205 ZW |
21766 | valueT result = 0; |
21767 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 21768 | |
c19d1205 | 21769 | if (target_big_endian) |
b99bd4ef | 21770 | { |
c19d1205 ZW |
21771 | while (n--) |
21772 | { | |
21773 | result <<= 8; | |
21774 | result |= (*where++ & 255); | |
21775 | } | |
b99bd4ef | 21776 | } |
c19d1205 | 21777 | else |
b99bd4ef | 21778 | { |
c19d1205 ZW |
21779 | while (n--) |
21780 | { | |
21781 | result <<= 8; | |
21782 | result |= (where[n] & 255); | |
21783 | } | |
bfae80f2 | 21784 | } |
b99bd4ef | 21785 | |
c19d1205 | 21786 | return result; |
bfae80f2 | 21787 | } |
b99bd4ef | 21788 | |
c19d1205 | 21789 | /* MD interface: Sections. */ |
b99bd4ef | 21790 | |
fa94de6b RM |
21791 | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
21792 | that an rs_machine_dependent frag may reach. */ | |
21793 | ||
21794 | unsigned int | |
21795 | arm_frag_max_var (fragS *fragp) | |
21796 | { | |
21797 | /* We only use rs_machine_dependent for variable-size Thumb instructions, | |
21798 | which are either THUMB_SIZE (2) or INSN_SIZE (4). | |
21799 | ||
21800 | Note that we generate relaxable instructions even for cases that don't | |
21801 | really need it, like an immediate that's a trivial constant. So we're | |
21802 | overestimating the instruction size for some of those cases. Rather | |
21803 | than putting more intelligence here, it would probably be better to | |
21804 | avoid generating a relaxation frag in the first place when it can be | |
21805 | determined up front that a short instruction will suffice. */ | |
21806 | ||
21807 | gas_assert (fragp->fr_type == rs_machine_dependent); | |
21808 | return INSN_SIZE; | |
21809 | } | |
21810 | ||
0110f2b8 PB |
21811 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
21812 | 2 bytes. */ | |
21813 | ||
c19d1205 | 21814 | int |
0110f2b8 | 21815 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
21816 | segT segtype ATTRIBUTE_UNUSED) |
21817 | { | |
0110f2b8 PB |
21818 | fragp->fr_var = 2; |
21819 | return 2; | |
21820 | } | |
21821 | ||
21822 | /* Convert a machine dependent frag. */ | |
21823 | ||
21824 | void | |
21825 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
21826 | { | |
21827 | unsigned long insn; | |
21828 | unsigned long old_op; | |
21829 | char *buf; | |
21830 | expressionS exp; | |
21831 | fixS *fixp; | |
21832 | int reloc_type; | |
21833 | int pc_rel; | |
21834 | int opcode; | |
21835 | ||
21836 | buf = fragp->fr_literal + fragp->fr_fix; | |
21837 | ||
21838 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
21839 | if (fragp->fr_symbol) |
21840 | { | |
0110f2b8 PB |
21841 | exp.X_op = O_symbol; |
21842 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
21843 | } |
21844 | else | |
21845 | { | |
0110f2b8 | 21846 | exp.X_op = O_constant; |
5f4273c7 | 21847 | } |
0110f2b8 PB |
21848 | exp.X_add_number = fragp->fr_offset; |
21849 | opcode = fragp->fr_subtype; | |
21850 | switch (opcode) | |
21851 | { | |
21852 | case T_MNEM_ldr_pc: | |
21853 | case T_MNEM_ldr_pc2: | |
21854 | case T_MNEM_ldr_sp: | |
21855 | case T_MNEM_str_sp: | |
21856 | case T_MNEM_ldr: | |
21857 | case T_MNEM_ldrb: | |
21858 | case T_MNEM_ldrh: | |
21859 | case T_MNEM_str: | |
21860 | case T_MNEM_strb: | |
21861 | case T_MNEM_strh: | |
21862 | if (fragp->fr_var == 4) | |
21863 | { | |
5f4273c7 | 21864 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
21865 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
21866 | { | |
21867 | insn |= (old_op & 0x700) << 4; | |
21868 | } | |
21869 | else | |
21870 | { | |
21871 | insn |= (old_op & 7) << 12; | |
21872 | insn |= (old_op & 0x38) << 13; | |
21873 | } | |
21874 | insn |= 0x00000c00; | |
21875 | put_thumb32_insn (buf, insn); | |
21876 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
21877 | } | |
21878 | else | |
21879 | { | |
21880 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
21881 | } | |
21882 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
21883 | break; | |
21884 | case T_MNEM_adr: | |
21885 | if (fragp->fr_var == 4) | |
21886 | { | |
21887 | insn = THUMB_OP32 (opcode); | |
21888 | insn |= (old_op & 0xf0) << 4; | |
21889 | put_thumb32_insn (buf, insn); | |
21890 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
21891 | } | |
21892 | else | |
21893 | { | |
21894 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
21895 | exp.X_add_number -= 4; | |
21896 | } | |
21897 | pc_rel = 1; | |
21898 | break; | |
21899 | case T_MNEM_mov: | |
21900 | case T_MNEM_movs: | |
21901 | case T_MNEM_cmp: | |
21902 | case T_MNEM_cmn: | |
21903 | if (fragp->fr_var == 4) | |
21904 | { | |
21905 | int r0off = (opcode == T_MNEM_mov | |
21906 | || opcode == T_MNEM_movs) ? 0 : 8; | |
21907 | insn = THUMB_OP32 (opcode); | |
21908 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
21909 | insn |= (old_op & 0x700) << r0off; | |
21910 | put_thumb32_insn (buf, insn); | |
21911 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
21912 | } | |
21913 | else | |
21914 | { | |
21915 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
21916 | } | |
21917 | pc_rel = 0; | |
21918 | break; | |
21919 | case T_MNEM_b: | |
21920 | if (fragp->fr_var == 4) | |
21921 | { | |
21922 | insn = THUMB_OP32(opcode); | |
21923 | put_thumb32_insn (buf, insn); | |
21924 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
21925 | } | |
21926 | else | |
21927 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
21928 | pc_rel = 1; | |
21929 | break; | |
21930 | case T_MNEM_bcond: | |
21931 | if (fragp->fr_var == 4) | |
21932 | { | |
21933 | insn = THUMB_OP32(opcode); | |
21934 | insn |= (old_op & 0xf00) << 14; | |
21935 | put_thumb32_insn (buf, insn); | |
21936 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
21937 | } | |
21938 | else | |
21939 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
21940 | pc_rel = 1; | |
21941 | break; | |
21942 | case T_MNEM_add_sp: | |
21943 | case T_MNEM_add_pc: | |
21944 | case T_MNEM_inc_sp: | |
21945 | case T_MNEM_dec_sp: | |
21946 | if (fragp->fr_var == 4) | |
21947 | { | |
21948 | /* ??? Choose between add and addw. */ | |
21949 | insn = THUMB_OP32 (opcode); | |
21950 | insn |= (old_op & 0xf0) << 4; | |
21951 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
21952 | if (opcode == T_MNEM_add_pc) |
21953 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
21954 | else | |
21955 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
21956 | } |
21957 | else | |
21958 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
21959 | pc_rel = 0; | |
21960 | break; | |
21961 | ||
21962 | case T_MNEM_addi: | |
21963 | case T_MNEM_addis: | |
21964 | case T_MNEM_subi: | |
21965 | case T_MNEM_subis: | |
21966 | if (fragp->fr_var == 4) | |
21967 | { | |
21968 | insn = THUMB_OP32 (opcode); | |
21969 | insn |= (old_op & 0xf0) << 4; | |
21970 | insn |= (old_op & 0xf) << 16; | |
21971 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
21972 | if (insn & (1 << 20)) |
21973 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
21974 | else | |
21975 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
21976 | } |
21977 | else | |
21978 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
21979 | pc_rel = 0; | |
21980 | break; | |
21981 | default: | |
5f4273c7 | 21982 | abort (); |
0110f2b8 PB |
21983 | } |
21984 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 21985 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
21986 | fixp->fx_file = fragp->fr_file; |
21987 | fixp->fx_line = fragp->fr_line; | |
21988 | fragp->fr_fix += fragp->fr_var; | |
3cfdb781 TG |
21989 | |
21990 | /* Set whether we use thumb-2 ISA based on final relaxation results. */ | |
21991 | if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected () | |
21992 | && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2)) | |
21993 | ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2); | |
0110f2b8 PB |
21994 | } |
21995 | ||
21996 | /* Return the size of a relaxable immediate operand instruction. | |
21997 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
21998 | static int | |
21999 | relax_immediate (fragS *fragp, int size, int shift) | |
22000 | { | |
22001 | offsetT offset; | |
22002 | offsetT mask; | |
22003 | offsetT low; | |
22004 | ||
22005 | /* ??? Should be able to do better than this. */ | |
22006 | if (fragp->fr_symbol) | |
22007 | return 4; | |
22008 | ||
22009 | low = (1 << shift) - 1; | |
22010 | mask = (1 << (shift + size)) - (1 << shift); | |
22011 | offset = fragp->fr_offset; | |
22012 | /* Force misaligned offsets to 32-bit variant. */ | |
22013 | if (offset & low) | |
5e77afaa | 22014 | return 4; |
0110f2b8 PB |
22015 | if (offset & ~mask) |
22016 | return 4; | |
22017 | return 2; | |
22018 | } | |
22019 | ||
5e77afaa PB |
22020 | /* Get the address of a symbol during relaxation. */ |
22021 | static addressT | |
5f4273c7 | 22022 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
22023 | { |
22024 | fragS *sym_frag; | |
22025 | addressT addr; | |
22026 | symbolS *sym; | |
22027 | ||
22028 | sym = fragp->fr_symbol; | |
22029 | sym_frag = symbol_get_frag (sym); | |
22030 | know (S_GET_SEGMENT (sym) != absolute_section | |
22031 | || sym_frag == &zero_address_frag); | |
22032 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
22033 | ||
22034 | /* If frag has yet to be reached on this pass, assume it will | |
22035 | move by STRETCH just as we did. If this is not so, it will | |
22036 | be because some frag between grows, and that will force | |
22037 | another pass. */ | |
22038 | ||
22039 | if (stretch != 0 | |
22040 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
22041 | { |
22042 | fragS *f; | |
22043 | ||
22044 | /* Adjust stretch for any alignment frag. Note that if have | |
22045 | been expanding the earlier code, the symbol may be | |
22046 | defined in what appears to be an earlier frag. FIXME: | |
22047 | This doesn't handle the fr_subtype field, which specifies | |
22048 | a maximum number of bytes to skip when doing an | |
22049 | alignment. */ | |
22050 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
22051 | { | |
22052 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
22053 | { | |
22054 | if (stretch < 0) | |
22055 | stretch = - ((- stretch) | |
22056 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
22057 | else | |
22058 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
22059 | if (stretch == 0) | |
22060 | break; | |
22061 | } | |
22062 | } | |
22063 | if (f != NULL) | |
22064 | addr += stretch; | |
22065 | } | |
5e77afaa PB |
22066 | |
22067 | return addr; | |
22068 | } | |
22069 | ||
0110f2b8 PB |
22070 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
22071 | load. */ | |
22072 | static int | |
5e77afaa | 22073 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
22074 | { |
22075 | addressT addr; | |
22076 | offsetT val; | |
22077 | ||
22078 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
22079 | if (fragp->fr_symbol == NULL |
22080 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
22081 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
22082 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
22083 | return 4; |
22084 | ||
5f4273c7 | 22085 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
22086 | addr = fragp->fr_address + fragp->fr_fix; |
22087 | addr = (addr + 4) & ~3; | |
5e77afaa | 22088 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 22089 | if (val & 3) |
5e77afaa | 22090 | return 4; |
0110f2b8 PB |
22091 | val -= addr; |
22092 | if (val < 0 || val > 1020) | |
22093 | return 4; | |
22094 | return 2; | |
22095 | } | |
22096 | ||
22097 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
22098 | static int | |
22099 | relax_addsub (fragS *fragp, asection *sec) | |
22100 | { | |
22101 | char *buf; | |
22102 | int op; | |
22103 | ||
22104 | buf = fragp->fr_literal + fragp->fr_fix; | |
22105 | op = bfd_get_16(sec->owner, buf); | |
22106 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
22107 | return relax_immediate (fragp, 8, 0); | |
22108 | else | |
22109 | return relax_immediate (fragp, 3, 0); | |
22110 | } | |
22111 | ||
e83a675f RE |
22112 | /* Return TRUE iff the definition of symbol S could be pre-empted |
22113 | (overridden) at link or load time. */ | |
22114 | static bfd_boolean | |
22115 | symbol_preemptible (symbolS *s) | |
22116 | { | |
22117 | /* Weak symbols can always be pre-empted. */ | |
22118 | if (S_IS_WEAK (s)) | |
22119 | return TRUE; | |
22120 | ||
22121 | /* Non-global symbols cannot be pre-empted. */ | |
22122 | if (! S_IS_EXTERNAL (s)) | |
22123 | return FALSE; | |
22124 | ||
22125 | #ifdef OBJ_ELF | |
22126 | /* In ELF, a global symbol can be marked protected, or private. In that | |
22127 | case it can't be pre-empted (other definitions in the same link unit | |
22128 | would violate the ODR). */ | |
22129 | if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT) | |
22130 | return FALSE; | |
22131 | #endif | |
22132 | ||
22133 | /* Other global symbols might be pre-empted. */ | |
22134 | return TRUE; | |
22135 | } | |
0110f2b8 PB |
22136 | |
22137 | /* Return the size of a relaxable branch instruction. BITS is the | |
22138 | size of the offset field in the narrow instruction. */ | |
22139 | ||
22140 | static int | |
5e77afaa | 22141 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
22142 | { |
22143 | addressT addr; | |
22144 | offsetT val; | |
22145 | offsetT limit; | |
22146 | ||
22147 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 22148 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
22149 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
22150 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
22151 | return 4; |
22152 | ||
267bf995 | 22153 | #ifdef OBJ_ELF |
e83a675f | 22154 | /* A branch to a function in ARM state will require interworking. */ |
267bf995 RR |
22155 | if (S_IS_DEFINED (fragp->fr_symbol) |
22156 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
22157 | return 4; | |
e83a675f | 22158 | #endif |
0d9b4b55 | 22159 | |
e83a675f | 22160 | if (symbol_preemptible (fragp->fr_symbol)) |
0d9b4b55 | 22161 | return 4; |
267bf995 | 22162 | |
5f4273c7 | 22163 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
22164 | addr = fragp->fr_address + fragp->fr_fix + 4; |
22165 | val -= addr; | |
22166 | ||
22167 | /* Offset is a signed value *2 */ | |
22168 | limit = 1 << bits; | |
22169 | if (val >= limit || val < -limit) | |
22170 | return 4; | |
22171 | return 2; | |
22172 | } | |
22173 | ||
22174 | ||
22175 | /* Relax a machine dependent frag. This returns the amount by which | |
22176 | the current size of the frag should change. */ | |
22177 | ||
22178 | int | |
5e77afaa | 22179 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
22180 | { |
22181 | int oldsize; | |
22182 | int newsize; | |
22183 | ||
22184 | oldsize = fragp->fr_var; | |
22185 | switch (fragp->fr_subtype) | |
22186 | { | |
22187 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 22188 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
22189 | break; |
22190 | case T_MNEM_ldr_pc: | |
22191 | case T_MNEM_ldr_sp: | |
22192 | case T_MNEM_str_sp: | |
5f4273c7 | 22193 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
22194 | break; |
22195 | case T_MNEM_ldr: | |
22196 | case T_MNEM_str: | |
5f4273c7 | 22197 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
22198 | break; |
22199 | case T_MNEM_ldrh: | |
22200 | case T_MNEM_strh: | |
5f4273c7 | 22201 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
22202 | break; |
22203 | case T_MNEM_ldrb: | |
22204 | case T_MNEM_strb: | |
5f4273c7 | 22205 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
22206 | break; |
22207 | case T_MNEM_adr: | |
5f4273c7 | 22208 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
22209 | break; |
22210 | case T_MNEM_mov: | |
22211 | case T_MNEM_movs: | |
22212 | case T_MNEM_cmp: | |
22213 | case T_MNEM_cmn: | |
5f4273c7 | 22214 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
22215 | break; |
22216 | case T_MNEM_b: | |
5f4273c7 | 22217 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
22218 | break; |
22219 | case T_MNEM_bcond: | |
5f4273c7 | 22220 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
22221 | break; |
22222 | case T_MNEM_add_sp: | |
22223 | case T_MNEM_add_pc: | |
22224 | newsize = relax_immediate (fragp, 8, 2); | |
22225 | break; | |
22226 | case T_MNEM_inc_sp: | |
22227 | case T_MNEM_dec_sp: | |
22228 | newsize = relax_immediate (fragp, 7, 2); | |
22229 | break; | |
22230 | case T_MNEM_addi: | |
22231 | case T_MNEM_addis: | |
22232 | case T_MNEM_subi: | |
22233 | case T_MNEM_subis: | |
22234 | newsize = relax_addsub (fragp, sec); | |
22235 | break; | |
22236 | default: | |
5f4273c7 | 22237 | abort (); |
0110f2b8 | 22238 | } |
5e77afaa PB |
22239 | |
22240 | fragp->fr_var = newsize; | |
22241 | /* Freeze wide instructions that are at or before the same location as | |
22242 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
22243 | Don't freeze them unconditionally because targets may be artificially |
22244 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 22245 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 22246 | { |
0110f2b8 | 22247 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 22248 | frag_wane (fragp); |
0110f2b8 | 22249 | } |
5e77afaa | 22250 | |
0110f2b8 | 22251 | return newsize - oldsize; |
c19d1205 | 22252 | } |
b99bd4ef | 22253 | |
c19d1205 | 22254 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 22255 | |
c19d1205 ZW |
22256 | valueT |
22257 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
22258 | valueT size) | |
22259 | { | |
6844c0cc | 22260 | return size; |
bfae80f2 | 22261 | } |
b99bd4ef | 22262 | |
c19d1205 ZW |
22263 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
22264 | of an rs_align_code fragment. */ | |
22265 | ||
22266 | void | |
22267 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 22268 | { |
d9235011 | 22269 | static unsigned char const arm_noop[2][2][4] = |
e7495e45 NS |
22270 | { |
22271 | { /* ARMv1 */ | |
22272 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
22273 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
22274 | }, | |
22275 | { /* ARMv6k */ | |
22276 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
22277 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
22278 | }, | |
22279 | }; | |
d9235011 | 22280 | static unsigned char const thumb_noop[2][2][2] = |
e7495e45 NS |
22281 | { |
22282 | { /* Thumb-1 */ | |
22283 | {0xc0, 0x46}, /* LE */ | |
22284 | {0x46, 0xc0}, /* BE */ | |
22285 | }, | |
22286 | { /* Thumb-2 */ | |
22287 | {0x00, 0xbf}, /* LE */ | |
22288 | {0xbf, 0x00} /* BE */ | |
22289 | } | |
22290 | }; | |
d9235011 | 22291 | static unsigned char const wide_thumb_noop[2][4] = |
e7495e45 NS |
22292 | { /* Wide Thumb-2 */ |
22293 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
22294 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
22295 | }; | |
c921be7d | 22296 | |
e7495e45 | 22297 | unsigned bytes, fix, noop_size; |
c19d1205 | 22298 | char * p; |
d9235011 TS |
22299 | const unsigned char * noop; |
22300 | const unsigned char *narrow_noop = NULL; | |
cd000bff DJ |
22301 | #ifdef OBJ_ELF |
22302 | enum mstate state; | |
22303 | #endif | |
bfae80f2 | 22304 | |
c19d1205 | 22305 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
22306 | return; |
22307 | ||
c19d1205 ZW |
22308 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
22309 | p = fragP->fr_literal + fragP->fr_fix; | |
22310 | fix = 0; | |
bfae80f2 | 22311 | |
c19d1205 ZW |
22312 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
22313 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 22314 | |
cd000bff | 22315 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 22316 | |
cd000bff | 22317 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 22318 | { |
7f78eb34 JW |
22319 | if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
22320 | ? selected_cpu : arm_arch_none, arm_ext_v6t2)) | |
e7495e45 NS |
22321 | { |
22322 | narrow_noop = thumb_noop[1][target_big_endian]; | |
22323 | noop = wide_thumb_noop[target_big_endian]; | |
22324 | } | |
c19d1205 | 22325 | else |
e7495e45 NS |
22326 | noop = thumb_noop[0][target_big_endian]; |
22327 | noop_size = 2; | |
cd000bff DJ |
22328 | #ifdef OBJ_ELF |
22329 | state = MAP_THUMB; | |
22330 | #endif | |
7ed4c4c5 NC |
22331 | } |
22332 | else | |
22333 | { | |
7f78eb34 JW |
22334 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
22335 | ? selected_cpu : arm_arch_none, | |
22336 | arm_ext_v6k) != 0] | |
e7495e45 NS |
22337 | [target_big_endian]; |
22338 | noop_size = 4; | |
cd000bff DJ |
22339 | #ifdef OBJ_ELF |
22340 | state = MAP_ARM; | |
22341 | #endif | |
7ed4c4c5 | 22342 | } |
c921be7d | 22343 | |
e7495e45 | 22344 | fragP->fr_var = noop_size; |
c921be7d | 22345 | |
c19d1205 | 22346 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 22347 | { |
c19d1205 | 22348 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
22349 | #ifdef OBJ_ELF |
22350 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
22351 | #endif | |
c19d1205 ZW |
22352 | memset (p, 0, fix); |
22353 | p += fix; | |
22354 | bytes -= fix; | |
a737bd4d | 22355 | } |
a737bd4d | 22356 | |
e7495e45 NS |
22357 | if (narrow_noop) |
22358 | { | |
22359 | if (bytes & noop_size) | |
22360 | { | |
22361 | /* Insert a narrow noop. */ | |
22362 | memcpy (p, narrow_noop, noop_size); | |
22363 | p += noop_size; | |
22364 | bytes -= noop_size; | |
22365 | fix += noop_size; | |
22366 | } | |
22367 | ||
22368 | /* Use wide noops for the remainder */ | |
22369 | noop_size = 4; | |
22370 | } | |
22371 | ||
c19d1205 | 22372 | while (bytes >= noop_size) |
a737bd4d | 22373 | { |
c19d1205 ZW |
22374 | memcpy (p, noop, noop_size); |
22375 | p += noop_size; | |
22376 | bytes -= noop_size; | |
22377 | fix += noop_size; | |
a737bd4d NC |
22378 | } |
22379 | ||
c19d1205 | 22380 | fragP->fr_fix += fix; |
a737bd4d NC |
22381 | } |
22382 | ||
c19d1205 ZW |
22383 | /* Called from md_do_align. Used to create an alignment |
22384 | frag in a code section. */ | |
22385 | ||
22386 | void | |
22387 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 22388 | { |
c19d1205 | 22389 | char * p; |
7ed4c4c5 | 22390 | |
c19d1205 | 22391 | /* We assume that there will never be a requirement |
6ec8e702 | 22392 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 22393 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
22394 | { |
22395 | char err_msg[128]; | |
22396 | ||
fa94de6b | 22397 | sprintf (err_msg, |
477330fc RM |
22398 | _("alignments greater than %d bytes not supported in .text sections."), |
22399 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 22400 | as_fatal ("%s", err_msg); |
6ec8e702 | 22401 | } |
bfae80f2 | 22402 | |
c19d1205 ZW |
22403 | p = frag_var (rs_align_code, |
22404 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
22405 | 1, | |
22406 | (relax_substateT) max, | |
22407 | (symbolS *) NULL, | |
22408 | (offsetT) n, | |
22409 | (char *) NULL); | |
22410 | *p = 0; | |
22411 | } | |
bfae80f2 | 22412 | |
8dc2430f NC |
22413 | /* Perform target specific initialisation of a frag. |
22414 | Note - despite the name this initialisation is not done when the frag | |
22415 | is created, but only when its type is assigned. A frag can be created | |
22416 | and used a long time before its type is set, so beware of assuming that | |
33eaf5de | 22417 | this initialisation is performed first. */ |
bfae80f2 | 22418 | |
cd000bff DJ |
22419 | #ifndef OBJ_ELF |
22420 | void | |
22421 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
22422 | { | |
22423 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 22424 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
22425 | } |
22426 | ||
22427 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 22428 | void |
cd000bff | 22429 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 22430 | { |
e8d84ca1 | 22431 | bfd_boolean frag_thumb_mode; |
b968d18a | 22432 | |
8dc2430f NC |
22433 | /* If the current ARM vs THUMB mode has not already |
22434 | been recorded into this frag then do so now. */ | |
cd000bff | 22435 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
b968d18a JW |
22436 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
22437 | ||
e8d84ca1 NC |
22438 | /* PR 21809: Do not set a mapping state for debug sections |
22439 | - it just confuses other tools. */ | |
22440 | if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING) | |
22441 | return; | |
22442 | ||
b968d18a | 22443 | frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED; |
cd000bff | 22444 | |
f9c1b181 RL |
22445 | /* Record a mapping symbol for alignment frags. We will delete this |
22446 | later if the alignment ends up empty. */ | |
22447 | switch (fragP->fr_type) | |
22448 | { | |
22449 | case rs_align: | |
22450 | case rs_align_test: | |
22451 | case rs_fill: | |
22452 | mapping_state_2 (MAP_DATA, max_chars); | |
22453 | break; | |
22454 | case rs_align_code: | |
b968d18a | 22455 | mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); |
f9c1b181 RL |
22456 | break; |
22457 | default: | |
22458 | break; | |
cd000bff | 22459 | } |
bfae80f2 RE |
22460 | } |
22461 | ||
c19d1205 ZW |
22462 | /* When we change sections we need to issue a new mapping symbol. */ |
22463 | ||
22464 | void | |
22465 | arm_elf_change_section (void) | |
bfae80f2 | 22466 | { |
c19d1205 ZW |
22467 | /* Link an unlinked unwind index table section to the .text section. */ |
22468 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
22469 | && elf_linked_to_section (now_seg) == NULL) | |
22470 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
22471 | } |
22472 | ||
c19d1205 ZW |
22473 | int |
22474 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 22475 | { |
c19d1205 ZW |
22476 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
22477 | return SHT_ARM_EXIDX; | |
e45d0630 | 22478 | |
c19d1205 ZW |
22479 | return -1; |
22480 | } | |
22481 | \f | |
22482 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 22483 | |
c19d1205 | 22484 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 22485 | |
5f4273c7 | 22486 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 22487 | |
bfae80f2 | 22488 | static void |
c19d1205 | 22489 | flush_pending_unwind (void) |
bfae80f2 | 22490 | { |
c19d1205 | 22491 | offsetT offset; |
bfae80f2 | 22492 | |
c19d1205 ZW |
22493 | offset = unwind.pending_offset; |
22494 | unwind.pending_offset = 0; | |
22495 | if (offset != 0) | |
22496 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
22497 | } |
22498 | ||
c19d1205 ZW |
22499 | /* Add an opcode to this list for this function. Two-byte opcodes should |
22500 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
22501 | order. */ | |
22502 | ||
bfae80f2 | 22503 | static void |
c19d1205 | 22504 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 22505 | { |
c19d1205 ZW |
22506 | /* Add any deferred stack adjustment. */ |
22507 | if (unwind.pending_offset) | |
22508 | flush_pending_unwind (); | |
bfae80f2 | 22509 | |
c19d1205 | 22510 | unwind.sp_restored = 0; |
bfae80f2 | 22511 | |
c19d1205 | 22512 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 22513 | { |
c19d1205 ZW |
22514 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
22515 | if (unwind.opcodes) | |
325801bd TS |
22516 | unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes, |
22517 | unwind.opcode_alloc); | |
c19d1205 | 22518 | else |
325801bd | 22519 | unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc); |
bfae80f2 | 22520 | } |
c19d1205 | 22521 | while (length > 0) |
bfae80f2 | 22522 | { |
c19d1205 ZW |
22523 | length--; |
22524 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
22525 | op >>= 8; | |
22526 | unwind.opcode_count++; | |
bfae80f2 | 22527 | } |
bfae80f2 RE |
22528 | } |
22529 | ||
c19d1205 ZW |
22530 | /* Add unwind opcodes to adjust the stack pointer. */ |
22531 | ||
bfae80f2 | 22532 | static void |
c19d1205 | 22533 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 22534 | { |
c19d1205 | 22535 | valueT op; |
bfae80f2 | 22536 | |
c19d1205 | 22537 | if (offset > 0x200) |
bfae80f2 | 22538 | { |
c19d1205 ZW |
22539 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
22540 | char bytes[5]; | |
22541 | int n; | |
22542 | valueT o; | |
bfae80f2 | 22543 | |
c19d1205 ZW |
22544 | /* Long form: 0xb2, uleb128. */ |
22545 | /* This might not fit in a word so add the individual bytes, | |
22546 | remembering the list is built in reverse order. */ | |
22547 | o = (valueT) ((offset - 0x204) >> 2); | |
22548 | if (o == 0) | |
22549 | add_unwind_opcode (0, 1); | |
bfae80f2 | 22550 | |
c19d1205 ZW |
22551 | /* Calculate the uleb128 encoding of the offset. */ |
22552 | n = 0; | |
22553 | while (o) | |
22554 | { | |
22555 | bytes[n] = o & 0x7f; | |
22556 | o >>= 7; | |
22557 | if (o) | |
22558 | bytes[n] |= 0x80; | |
22559 | n++; | |
22560 | } | |
22561 | /* Add the insn. */ | |
22562 | for (; n; n--) | |
22563 | add_unwind_opcode (bytes[n - 1], 1); | |
22564 | add_unwind_opcode (0xb2, 1); | |
22565 | } | |
22566 | else if (offset > 0x100) | |
bfae80f2 | 22567 | { |
c19d1205 ZW |
22568 | /* Two short opcodes. */ |
22569 | add_unwind_opcode (0x3f, 1); | |
22570 | op = (offset - 0x104) >> 2; | |
22571 | add_unwind_opcode (op, 1); | |
bfae80f2 | 22572 | } |
c19d1205 ZW |
22573 | else if (offset > 0) |
22574 | { | |
22575 | /* Short opcode. */ | |
22576 | op = (offset - 4) >> 2; | |
22577 | add_unwind_opcode (op, 1); | |
22578 | } | |
22579 | else if (offset < 0) | |
bfae80f2 | 22580 | { |
c19d1205 ZW |
22581 | offset = -offset; |
22582 | while (offset > 0x100) | |
bfae80f2 | 22583 | { |
c19d1205 ZW |
22584 | add_unwind_opcode (0x7f, 1); |
22585 | offset -= 0x100; | |
bfae80f2 | 22586 | } |
c19d1205 ZW |
22587 | op = ((offset - 4) >> 2) | 0x40; |
22588 | add_unwind_opcode (op, 1); | |
bfae80f2 | 22589 | } |
bfae80f2 RE |
22590 | } |
22591 | ||
c19d1205 | 22592 | /* Finish the list of unwind opcodes for this function. */ |
0198d5e6 | 22593 | |
c19d1205 ZW |
22594 | static void |
22595 | finish_unwind_opcodes (void) | |
bfae80f2 | 22596 | { |
c19d1205 | 22597 | valueT op; |
bfae80f2 | 22598 | |
c19d1205 | 22599 | if (unwind.fp_used) |
bfae80f2 | 22600 | { |
708587a4 | 22601 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
22602 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
22603 | flush_pending_unwind (); | |
bfae80f2 | 22604 | |
c19d1205 ZW |
22605 | /* After restoring sp from the frame pointer. */ |
22606 | op = 0x90 | unwind.fp_reg; | |
22607 | add_unwind_opcode (op, 1); | |
22608 | } | |
22609 | else | |
22610 | flush_pending_unwind (); | |
bfae80f2 RE |
22611 | } |
22612 | ||
bfae80f2 | 22613 | |
c19d1205 ZW |
22614 | /* Start an exception table entry. If idx is nonzero this is an index table |
22615 | entry. */ | |
bfae80f2 RE |
22616 | |
22617 | static void | |
c19d1205 | 22618 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 22619 | { |
c19d1205 ZW |
22620 | const char * text_name; |
22621 | const char * prefix; | |
22622 | const char * prefix_once; | |
22623 | const char * group_name; | |
c19d1205 | 22624 | char * sec_name; |
c19d1205 ZW |
22625 | int type; |
22626 | int flags; | |
22627 | int linkonce; | |
bfae80f2 | 22628 | |
c19d1205 | 22629 | if (idx) |
bfae80f2 | 22630 | { |
c19d1205 ZW |
22631 | prefix = ELF_STRING_ARM_unwind; |
22632 | prefix_once = ELF_STRING_ARM_unwind_once; | |
22633 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 22634 | } |
c19d1205 | 22635 | else |
bfae80f2 | 22636 | { |
c19d1205 ZW |
22637 | prefix = ELF_STRING_ARM_unwind_info; |
22638 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
22639 | type = SHT_PROGBITS; | |
bfae80f2 RE |
22640 | } |
22641 | ||
c19d1205 ZW |
22642 | text_name = segment_name (text_seg); |
22643 | if (streq (text_name, ".text")) | |
22644 | text_name = ""; | |
22645 | ||
22646 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
22647 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 22648 | { |
c19d1205 ZW |
22649 | prefix = prefix_once; |
22650 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
22651 | } |
22652 | ||
29a2809e | 22653 | sec_name = concat (prefix, text_name, (char *) NULL); |
bfae80f2 | 22654 | |
c19d1205 ZW |
22655 | flags = SHF_ALLOC; |
22656 | linkonce = 0; | |
22657 | group_name = 0; | |
bfae80f2 | 22658 | |
c19d1205 ZW |
22659 | /* Handle COMDAT group. */ |
22660 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 22661 | { |
c19d1205 ZW |
22662 | group_name = elf_group_name (text_seg); |
22663 | if (group_name == NULL) | |
22664 | { | |
bd3ba5d1 | 22665 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
22666 | segment_name (text_seg)); |
22667 | ignore_rest_of_line (); | |
22668 | return; | |
22669 | } | |
22670 | flags |= SHF_GROUP; | |
22671 | linkonce = 1; | |
bfae80f2 RE |
22672 | } |
22673 | ||
a91e1603 L |
22674 | obj_elf_change_section (sec_name, type, 0, flags, 0, group_name, |
22675 | linkonce, 0); | |
bfae80f2 | 22676 | |
5f4273c7 | 22677 | /* Set the section link for index tables. */ |
c19d1205 ZW |
22678 | if (idx) |
22679 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
22680 | } |
22681 | ||
bfae80f2 | 22682 | |
c19d1205 ZW |
22683 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
22684 | personality routine data. Returns zero, or the index table value for | |
cad0da33 | 22685 | an inline entry. */ |
c19d1205 ZW |
22686 | |
22687 | static valueT | |
22688 | create_unwind_entry (int have_data) | |
bfae80f2 | 22689 | { |
c19d1205 ZW |
22690 | int size; |
22691 | addressT where; | |
22692 | char *ptr; | |
22693 | /* The current word of data. */ | |
22694 | valueT data; | |
22695 | /* The number of bytes left in this word. */ | |
22696 | int n; | |
bfae80f2 | 22697 | |
c19d1205 | 22698 | finish_unwind_opcodes (); |
bfae80f2 | 22699 | |
c19d1205 ZW |
22700 | /* Remember the current text section. */ |
22701 | unwind.saved_seg = now_seg; | |
22702 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 22703 | |
c19d1205 | 22704 | start_unwind_section (now_seg, 0); |
bfae80f2 | 22705 | |
c19d1205 | 22706 | if (unwind.personality_routine == NULL) |
bfae80f2 | 22707 | { |
c19d1205 ZW |
22708 | if (unwind.personality_index == -2) |
22709 | { | |
22710 | if (have_data) | |
5f4273c7 | 22711 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
22712 | return 1; /* EXIDX_CANTUNWIND. */ |
22713 | } | |
bfae80f2 | 22714 | |
c19d1205 ZW |
22715 | /* Use a default personality routine if none is specified. */ |
22716 | if (unwind.personality_index == -1) | |
22717 | { | |
22718 | if (unwind.opcode_count > 3) | |
22719 | unwind.personality_index = 1; | |
22720 | else | |
22721 | unwind.personality_index = 0; | |
22722 | } | |
bfae80f2 | 22723 | |
c19d1205 ZW |
22724 | /* Space for the personality routine entry. */ |
22725 | if (unwind.personality_index == 0) | |
22726 | { | |
22727 | if (unwind.opcode_count > 3) | |
22728 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 22729 | |
c19d1205 ZW |
22730 | if (!have_data) |
22731 | { | |
22732 | /* All the data is inline in the index table. */ | |
22733 | data = 0x80; | |
22734 | n = 3; | |
22735 | while (unwind.opcode_count > 0) | |
22736 | { | |
22737 | unwind.opcode_count--; | |
22738 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
22739 | n--; | |
22740 | } | |
bfae80f2 | 22741 | |
c19d1205 ZW |
22742 | /* Pad with "finish" opcodes. */ |
22743 | while (n--) | |
22744 | data = (data << 8) | 0xb0; | |
bfae80f2 | 22745 | |
c19d1205 ZW |
22746 | return data; |
22747 | } | |
22748 | size = 0; | |
22749 | } | |
22750 | else | |
22751 | /* We get two opcodes "free" in the first word. */ | |
22752 | size = unwind.opcode_count - 2; | |
22753 | } | |
22754 | else | |
5011093d | 22755 | { |
cad0da33 NC |
22756 | /* PR 16765: Missing or misplaced unwind directives can trigger this. */ |
22757 | if (unwind.personality_index != -1) | |
22758 | { | |
22759 | as_bad (_("attempt to recreate an unwind entry")); | |
22760 | return 1; | |
22761 | } | |
5011093d NC |
22762 | |
22763 | /* An extra byte is required for the opcode count. */ | |
22764 | size = unwind.opcode_count + 1; | |
22765 | } | |
bfae80f2 | 22766 | |
c19d1205 ZW |
22767 | size = (size + 3) >> 2; |
22768 | if (size > 0xff) | |
22769 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 22770 | |
c19d1205 ZW |
22771 | frag_align (2, 0, 0); |
22772 | record_alignment (now_seg, 2); | |
22773 | unwind.table_entry = expr_build_dot (); | |
22774 | ||
22775 | /* Allocate the table entry. */ | |
22776 | ptr = frag_more ((size << 2) + 4); | |
74929e7b NC |
22777 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
22778 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 22779 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 22780 | |
c19d1205 | 22781 | switch (unwind.personality_index) |
bfae80f2 | 22782 | { |
c19d1205 ZW |
22783 | case -1: |
22784 | /* ??? Should this be a PLT generating relocation? */ | |
22785 | /* Custom personality routine. */ | |
22786 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
22787 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 22788 | |
c19d1205 ZW |
22789 | where += 4; |
22790 | ptr += 4; | |
bfae80f2 | 22791 | |
c19d1205 | 22792 | /* Set the first byte to the number of additional words. */ |
5011093d | 22793 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
22794 | n = 3; |
22795 | break; | |
bfae80f2 | 22796 | |
c19d1205 ZW |
22797 | /* ABI defined personality routines. */ |
22798 | case 0: | |
22799 | /* Three opcodes bytes are packed into the first word. */ | |
22800 | data = 0x80; | |
22801 | n = 3; | |
22802 | break; | |
bfae80f2 | 22803 | |
c19d1205 ZW |
22804 | case 1: |
22805 | case 2: | |
22806 | /* The size and first two opcode bytes go in the first word. */ | |
22807 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
22808 | n = 2; | |
22809 | break; | |
bfae80f2 | 22810 | |
c19d1205 ZW |
22811 | default: |
22812 | /* Should never happen. */ | |
22813 | abort (); | |
22814 | } | |
bfae80f2 | 22815 | |
c19d1205 ZW |
22816 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
22817 | time. */ | |
22818 | while (unwind.opcode_count > 0) | |
22819 | { | |
22820 | if (n == 0) | |
22821 | { | |
22822 | md_number_to_chars (ptr, data, 4); | |
22823 | ptr += 4; | |
22824 | n = 4; | |
22825 | data = 0; | |
22826 | } | |
22827 | unwind.opcode_count--; | |
22828 | n--; | |
22829 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
22830 | } | |
22831 | ||
22832 | /* Finish off the last word. */ | |
22833 | if (n < 4) | |
22834 | { | |
22835 | /* Pad with "finish" opcodes. */ | |
22836 | while (n--) | |
22837 | data = (data << 8) | 0xb0; | |
22838 | ||
22839 | md_number_to_chars (ptr, data, 4); | |
22840 | } | |
22841 | ||
22842 | if (!have_data) | |
22843 | { | |
22844 | /* Add an empty descriptor if there is no user-specified data. */ | |
22845 | ptr = frag_more (4); | |
22846 | md_number_to_chars (ptr, 0, 4); | |
22847 | } | |
22848 | ||
22849 | return 0; | |
bfae80f2 RE |
22850 | } |
22851 | ||
f0927246 NC |
22852 | |
22853 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
22854 | ||
22855 | void | |
22856 | tc_arm_frame_initial_instructions (void) | |
22857 | { | |
22858 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
22859 | } | |
22860 | #endif /* OBJ_ELF */ | |
22861 | ||
c19d1205 ZW |
22862 | /* Convert REGNAME to a DWARF-2 register number. */ |
22863 | ||
22864 | int | |
1df69f4f | 22865 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 22866 | { |
1df69f4f | 22867 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
1f5afe1c NC |
22868 | if (reg != FAIL) |
22869 | return reg; | |
c19d1205 | 22870 | |
1f5afe1c NC |
22871 | /* PR 16694: Allow VFP registers as well. */ |
22872 | reg = arm_reg_parse (®name, REG_TYPE_VFS); | |
22873 | if (reg != FAIL) | |
22874 | return 64 + reg; | |
c19d1205 | 22875 | |
1f5afe1c NC |
22876 | reg = arm_reg_parse (®name, REG_TYPE_VFD); |
22877 | if (reg != FAIL) | |
22878 | return reg + 256; | |
22879 | ||
0198d5e6 | 22880 | return FAIL; |
bfae80f2 RE |
22881 | } |
22882 | ||
f0927246 | 22883 | #ifdef TE_PE |
c19d1205 | 22884 | void |
f0927246 | 22885 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 22886 | { |
91d6fa6a | 22887 | expressionS exp; |
bfae80f2 | 22888 | |
91d6fa6a NC |
22889 | exp.X_op = O_secrel; |
22890 | exp.X_add_symbol = symbol; | |
22891 | exp.X_add_number = 0; | |
22892 | emit_expr (&exp, size); | |
f0927246 NC |
22893 | } |
22894 | #endif | |
bfae80f2 | 22895 | |
c19d1205 | 22896 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 22897 | |
2fc8bdac ZW |
22898 | /* Return the address within the segment that a PC-relative fixup is |
22899 | relative to. For ARM, PC-relative fixups applied to instructions | |
22900 | are generally relative to the location of the fixup plus 8 bytes. | |
22901 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
22902 | require special handling. */ | |
bfae80f2 | 22903 | |
c19d1205 | 22904 | long |
2fc8bdac | 22905 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 22906 | { |
2fc8bdac ZW |
22907 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
22908 | ||
22909 | /* If this is pc-relative and we are going to emit a relocation | |
22910 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
22911 | will need. Otherwise we want to use the calculated base. |
22912 | For WinCE we skip the bias for externals as well, since this | |
22913 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 22914 | if (fixP->fx_pcrel |
2fc8bdac | 22915 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
22916 | || (arm_force_relocation (fixP) |
22917 | #ifdef TE_WINCE | |
22918 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
22919 | #endif | |
22920 | ))) | |
2fc8bdac | 22921 | base = 0; |
bfae80f2 | 22922 | |
267bf995 | 22923 | |
c19d1205 | 22924 | switch (fixP->fx_r_type) |
bfae80f2 | 22925 | { |
2fc8bdac ZW |
22926 | /* PC relative addressing on the Thumb is slightly odd as the |
22927 | bottom two bits of the PC are forced to zero for the | |
22928 | calculation. This happens *after* application of the | |
22929 | pipeline offset. However, Thumb adrl already adjusts for | |
22930 | this, so we need not do it again. */ | |
c19d1205 | 22931 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 22932 | return base & ~3; |
c19d1205 ZW |
22933 | |
22934 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
22935 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 22936 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 22937 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 22938 | return (base + 4) & ~3; |
c19d1205 | 22939 | |
2fc8bdac | 22940 | /* Thumb branches are simply offset by +4. */ |
e12437dc | 22941 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
2fc8bdac ZW |
22942 | case BFD_RELOC_THUMB_PCREL_BRANCH7: |
22943 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
22944 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
22945 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 22946 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
e5d6e09e | 22947 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 22948 | case BFD_RELOC_ARM_THUMB_BF19: |
2fc8bdac | 22949 | return base + 4; |
bfae80f2 | 22950 | |
267bf995 | 22951 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
22952 | if (fixP->fx_addsy |
22953 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22954 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 | 22955 | && ARM_IS_FUNC (fixP->fx_addsy) |
477330fc RM |
22956 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) |
22957 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
267bf995 RR |
22958 | return base + 4; |
22959 | ||
00adf2d4 JB |
22960 | /* BLX is like branches above, but forces the low two bits of PC to |
22961 | zero. */ | |
486499d0 CL |
22962 | case BFD_RELOC_THUMB_PCREL_BLX: |
22963 | if (fixP->fx_addsy | |
22964 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22965 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
22966 | && THUMB_IS_FUNC (fixP->fx_addsy) |
22967 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22968 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
22969 | return (base + 4) & ~3; |
22970 | ||
2fc8bdac ZW |
22971 | /* ARM mode branches are offset by +8. However, the Windows CE |
22972 | loader expects the relocation not to take this into account. */ | |
267bf995 | 22973 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
22974 | if (fixP->fx_addsy |
22975 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22976 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
22977 | && ARM_IS_FUNC (fixP->fx_addsy) |
22978 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22979 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 22980 | return base + 8; |
267bf995 | 22981 | |
486499d0 CL |
22982 | case BFD_RELOC_ARM_PCREL_CALL: |
22983 | if (fixP->fx_addsy | |
22984 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22985 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
22986 | && THUMB_IS_FUNC (fixP->fx_addsy) |
22987 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22988 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 22989 | return base + 8; |
267bf995 | 22990 | |
2fc8bdac | 22991 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 22992 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 22993 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 22994 | #ifdef TE_WINCE |
5f4273c7 | 22995 | /* When handling fixups immediately, because we have already |
477330fc | 22996 | discovered the value of a symbol, or the address of the frag involved |
53baae48 | 22997 | we must account for the offset by +8, as the OS loader will never see the reloc. |
477330fc RM |
22998 | see fixup_segment() in write.c |
22999 | The S_IS_EXTERNAL test handles the case of global symbols. | |
23000 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
53baae48 NC |
23001 | if (fixP->fx_pcrel |
23002 | && fixP->fx_addsy != NULL | |
23003 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
23004 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
23005 | return base + 8; | |
2fc8bdac | 23006 | return base; |
c19d1205 | 23007 | #else |
2fc8bdac | 23008 | return base + 8; |
c19d1205 | 23009 | #endif |
2fc8bdac | 23010 | |
267bf995 | 23011 | |
2fc8bdac ZW |
23012 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
23013 | branches, the Windows CE loader *does* expect the relocation | |
23014 | to take this into account. */ | |
23015 | case BFD_RELOC_ARM_OFFSET_IMM: | |
23016 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
23017 | case BFD_RELOC_ARM_HWLITERAL: | |
23018 | case BFD_RELOC_ARM_LITERAL: | |
23019 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
23020 | return base + 8; | |
23021 | ||
23022 | ||
23023 | /* Other PC-relative relocations are un-offset. */ | |
23024 | default: | |
23025 | return base; | |
23026 | } | |
bfae80f2 RE |
23027 | } |
23028 | ||
8b2d793c NC |
23029 | static bfd_boolean flag_warn_syms = TRUE; |
23030 | ||
ae8714c2 NC |
23031 | bfd_boolean |
23032 | arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) | |
bfae80f2 | 23033 | { |
8b2d793c NC |
23034 | /* PR 18347 - Warn if the user attempts to create a symbol with the same |
23035 | name as an ARM instruction. Whilst strictly speaking it is allowed, it | |
23036 | does mean that the resulting code might be very confusing to the reader. | |
23037 | Also this warning can be triggered if the user omits an operand before | |
23038 | an immediate address, eg: | |
23039 | ||
23040 | LDR =foo | |
23041 | ||
23042 | GAS treats this as an assignment of the value of the symbol foo to a | |
23043 | symbol LDR, and so (without this code) it will not issue any kind of | |
23044 | warning or error message. | |
23045 | ||
23046 | Note - ARM instructions are case-insensitive but the strings in the hash | |
23047 | table are all stored in lower case, so we must first ensure that name is | |
ae8714c2 NC |
23048 | lower case too. */ |
23049 | if (flag_warn_syms && arm_ops_hsh) | |
8b2d793c NC |
23050 | { |
23051 | char * nbuf = strdup (name); | |
23052 | char * p; | |
23053 | ||
23054 | for (p = nbuf; *p; p++) | |
23055 | *p = TOLOWER (*p); | |
23056 | if (hash_find (arm_ops_hsh, nbuf) != NULL) | |
23057 | { | |
23058 | static struct hash_control * already_warned = NULL; | |
23059 | ||
23060 | if (already_warned == NULL) | |
23061 | already_warned = hash_new (); | |
23062 | /* Only warn about the symbol once. To keep the code | |
23063 | simple we let hash_insert do the lookup for us. */ | |
23064 | if (hash_insert (already_warned, name, NULL) == NULL) | |
ae8714c2 | 23065 | as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name); |
8b2d793c NC |
23066 | } |
23067 | else | |
23068 | free (nbuf); | |
23069 | } | |
3739860c | 23070 | |
ae8714c2 NC |
23071 | return FALSE; |
23072 | } | |
23073 | ||
23074 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. | |
23075 | Otherwise we have no need to default values of symbols. */ | |
23076 | ||
23077 | symbolS * | |
23078 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
23079 | { | |
23080 | #ifdef OBJ_ELF | |
23081 | if (name[0] == '_' && name[1] == 'G' | |
23082 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
23083 | { | |
23084 | if (!GOT_symbol) | |
23085 | { | |
23086 | if (symbol_find (name)) | |
23087 | as_bad (_("GOT already in the symbol table")); | |
23088 | ||
23089 | GOT_symbol = symbol_new (name, undefined_section, | |
23090 | (valueT) 0, & zero_address_frag); | |
23091 | } | |
23092 | ||
23093 | return GOT_symbol; | |
23094 | } | |
23095 | #endif | |
23096 | ||
c921be7d | 23097 | return NULL; |
bfae80f2 RE |
23098 | } |
23099 | ||
55cf6793 | 23100 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
23101 | computed as two separate immediate values, added together. We |
23102 | already know that this value cannot be computed by just one ARM | |
23103 | instruction. */ | |
23104 | ||
23105 | static unsigned int | |
23106 | validate_immediate_twopart (unsigned int val, | |
23107 | unsigned int * highpart) | |
bfae80f2 | 23108 | { |
c19d1205 ZW |
23109 | unsigned int a; |
23110 | unsigned int i; | |
bfae80f2 | 23111 | |
c19d1205 ZW |
23112 | for (i = 0; i < 32; i += 2) |
23113 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
23114 | { | |
23115 | if (a & 0xff00) | |
23116 | { | |
23117 | if (a & ~ 0xffff) | |
23118 | continue; | |
23119 | * highpart = (a >> 8) | ((i + 24) << 7); | |
23120 | } | |
23121 | else if (a & 0xff0000) | |
23122 | { | |
23123 | if (a & 0xff000000) | |
23124 | continue; | |
23125 | * highpart = (a >> 16) | ((i + 16) << 7); | |
23126 | } | |
23127 | else | |
23128 | { | |
9c2799c2 | 23129 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
23130 | * highpart = (a >> 24) | ((i + 8) << 7); |
23131 | } | |
bfae80f2 | 23132 | |
c19d1205 ZW |
23133 | return (a & 0xff) | (i << 7); |
23134 | } | |
bfae80f2 | 23135 | |
c19d1205 | 23136 | return FAIL; |
bfae80f2 RE |
23137 | } |
23138 | ||
c19d1205 ZW |
23139 | static int |
23140 | validate_offset_imm (unsigned int val, int hwse) | |
23141 | { | |
23142 | if ((hwse && val > 255) || val > 4095) | |
23143 | return FAIL; | |
23144 | return val; | |
23145 | } | |
bfae80f2 | 23146 | |
55cf6793 | 23147 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
23148 | negative immediate constant by altering the instruction. A bit of |
23149 | a hack really. | |
23150 | MOV <-> MVN | |
23151 | AND <-> BIC | |
23152 | ADC <-> SBC | |
23153 | by inverting the second operand, and | |
23154 | ADD <-> SUB | |
23155 | CMP <-> CMN | |
23156 | by negating the second operand. */ | |
bfae80f2 | 23157 | |
c19d1205 ZW |
23158 | static int |
23159 | negate_data_op (unsigned long * instruction, | |
23160 | unsigned long value) | |
bfae80f2 | 23161 | { |
c19d1205 ZW |
23162 | int op, new_inst; |
23163 | unsigned long negated, inverted; | |
bfae80f2 | 23164 | |
c19d1205 ZW |
23165 | negated = encode_arm_immediate (-value); |
23166 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 23167 | |
c19d1205 ZW |
23168 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
23169 | switch (op) | |
bfae80f2 | 23170 | { |
c19d1205 ZW |
23171 | /* First negates. */ |
23172 | case OPCODE_SUB: /* ADD <-> SUB */ | |
23173 | new_inst = OPCODE_ADD; | |
23174 | value = negated; | |
23175 | break; | |
bfae80f2 | 23176 | |
c19d1205 ZW |
23177 | case OPCODE_ADD: |
23178 | new_inst = OPCODE_SUB; | |
23179 | value = negated; | |
23180 | break; | |
bfae80f2 | 23181 | |
c19d1205 ZW |
23182 | case OPCODE_CMP: /* CMP <-> CMN */ |
23183 | new_inst = OPCODE_CMN; | |
23184 | value = negated; | |
23185 | break; | |
bfae80f2 | 23186 | |
c19d1205 ZW |
23187 | case OPCODE_CMN: |
23188 | new_inst = OPCODE_CMP; | |
23189 | value = negated; | |
23190 | break; | |
bfae80f2 | 23191 | |
c19d1205 ZW |
23192 | /* Now Inverted ops. */ |
23193 | case OPCODE_MOV: /* MOV <-> MVN */ | |
23194 | new_inst = OPCODE_MVN; | |
23195 | value = inverted; | |
23196 | break; | |
bfae80f2 | 23197 | |
c19d1205 ZW |
23198 | case OPCODE_MVN: |
23199 | new_inst = OPCODE_MOV; | |
23200 | value = inverted; | |
23201 | break; | |
bfae80f2 | 23202 | |
c19d1205 ZW |
23203 | case OPCODE_AND: /* AND <-> BIC */ |
23204 | new_inst = OPCODE_BIC; | |
23205 | value = inverted; | |
23206 | break; | |
bfae80f2 | 23207 | |
c19d1205 ZW |
23208 | case OPCODE_BIC: |
23209 | new_inst = OPCODE_AND; | |
23210 | value = inverted; | |
23211 | break; | |
bfae80f2 | 23212 | |
c19d1205 ZW |
23213 | case OPCODE_ADC: /* ADC <-> SBC */ |
23214 | new_inst = OPCODE_SBC; | |
23215 | value = inverted; | |
23216 | break; | |
bfae80f2 | 23217 | |
c19d1205 ZW |
23218 | case OPCODE_SBC: |
23219 | new_inst = OPCODE_ADC; | |
23220 | value = inverted; | |
23221 | break; | |
bfae80f2 | 23222 | |
c19d1205 ZW |
23223 | /* We cannot do anything. */ |
23224 | default: | |
23225 | return FAIL; | |
b99bd4ef NC |
23226 | } |
23227 | ||
c19d1205 ZW |
23228 | if (value == (unsigned) FAIL) |
23229 | return FAIL; | |
23230 | ||
23231 | *instruction &= OPCODE_MASK; | |
23232 | *instruction |= new_inst << DATA_OP_SHIFT; | |
23233 | return value; | |
b99bd4ef NC |
23234 | } |
23235 | ||
ef8d22e6 PB |
23236 | /* Like negate_data_op, but for Thumb-2. */ |
23237 | ||
23238 | static unsigned int | |
16dd5e42 | 23239 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
23240 | { |
23241 | int op, new_inst; | |
23242 | int rd; | |
16dd5e42 | 23243 | unsigned int negated, inverted; |
ef8d22e6 PB |
23244 | |
23245 | negated = encode_thumb32_immediate (-value); | |
23246 | inverted = encode_thumb32_immediate (~value); | |
23247 | ||
23248 | rd = (*instruction >> 8) & 0xf; | |
23249 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
23250 | switch (op) | |
23251 | { | |
23252 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
23253 | case T2_OPCODE_SUB: | |
23254 | new_inst = T2_OPCODE_ADD; | |
23255 | value = negated; | |
23256 | break; | |
23257 | ||
23258 | case T2_OPCODE_ADD: | |
23259 | new_inst = T2_OPCODE_SUB; | |
23260 | value = negated; | |
23261 | break; | |
23262 | ||
23263 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
23264 | case T2_OPCODE_ORR: | |
23265 | new_inst = T2_OPCODE_ORN; | |
23266 | value = inverted; | |
23267 | break; | |
23268 | ||
23269 | case T2_OPCODE_ORN: | |
23270 | new_inst = T2_OPCODE_ORR; | |
23271 | value = inverted; | |
23272 | break; | |
23273 | ||
23274 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
23275 | case T2_OPCODE_AND: | |
23276 | new_inst = T2_OPCODE_BIC; | |
23277 | if (rd == 15) | |
23278 | value = FAIL; | |
23279 | else | |
23280 | value = inverted; | |
23281 | break; | |
23282 | ||
23283 | case T2_OPCODE_BIC: | |
23284 | new_inst = T2_OPCODE_AND; | |
23285 | value = inverted; | |
23286 | break; | |
23287 | ||
23288 | /* ADC <-> SBC */ | |
23289 | case T2_OPCODE_ADC: | |
23290 | new_inst = T2_OPCODE_SBC; | |
23291 | value = inverted; | |
23292 | break; | |
23293 | ||
23294 | case T2_OPCODE_SBC: | |
23295 | new_inst = T2_OPCODE_ADC; | |
23296 | value = inverted; | |
23297 | break; | |
23298 | ||
23299 | /* We cannot do anything. */ | |
23300 | default: | |
23301 | return FAIL; | |
23302 | } | |
23303 | ||
16dd5e42 | 23304 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
23305 | return FAIL; |
23306 | ||
23307 | *instruction &= T2_OPCODE_MASK; | |
23308 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
23309 | return value; | |
23310 | } | |
23311 | ||
8f06b2d8 | 23312 | /* Read a 32-bit thumb instruction from buf. */ |
0198d5e6 | 23313 | |
8f06b2d8 PB |
23314 | static unsigned long |
23315 | get_thumb32_insn (char * buf) | |
23316 | { | |
23317 | unsigned long insn; | |
23318 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
23319 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23320 | ||
23321 | return insn; | |
23322 | } | |
23323 | ||
a8bc6c78 PB |
23324 | /* We usually want to set the low bit on the address of thumb function |
23325 | symbols. In particular .word foo - . should have the low bit set. | |
23326 | Generic code tries to fold the difference of two symbols to | |
23327 | a constant. Prevent this and force a relocation when the first symbols | |
23328 | is a thumb function. */ | |
c921be7d NC |
23329 | |
23330 | bfd_boolean | |
a8bc6c78 PB |
23331 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
23332 | { | |
23333 | if (op == O_subtract | |
23334 | && l->X_op == O_symbol | |
23335 | && r->X_op == O_symbol | |
23336 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
23337 | { | |
23338 | l->X_op = O_subtract; | |
23339 | l->X_op_symbol = r->X_add_symbol; | |
23340 | l->X_add_number -= r->X_add_number; | |
c921be7d | 23341 | return TRUE; |
a8bc6c78 | 23342 | } |
c921be7d | 23343 | |
a8bc6c78 | 23344 | /* Process as normal. */ |
c921be7d | 23345 | return FALSE; |
a8bc6c78 PB |
23346 | } |
23347 | ||
4a42ebbc RR |
23348 | /* Encode Thumb2 unconditional branches and calls. The encoding |
23349 | for the 2 are identical for the immediate values. */ | |
23350 | ||
23351 | static void | |
23352 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
23353 | { | |
23354 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
23355 | offsetT newval; | |
23356 | offsetT newval2; | |
23357 | addressT S, I1, I2, lo, hi; | |
23358 | ||
23359 | S = (value >> 24) & 0x01; | |
23360 | I1 = (value >> 23) & 0x01; | |
23361 | I2 = (value >> 22) & 0x01; | |
23362 | hi = (value >> 12) & 0x3ff; | |
fa94de6b | 23363 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
23364 | newval = md_chars_to_number (buf, THUMB_SIZE); |
23365 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23366 | newval |= (S << 10) | hi; | |
23367 | newval2 &= ~T2I1I2MASK; | |
23368 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
23369 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23370 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
23371 | } | |
23372 | ||
c19d1205 | 23373 | void |
55cf6793 | 23374 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
23375 | valueT * valP, |
23376 | segT seg) | |
23377 | { | |
23378 | offsetT value = * valP; | |
23379 | offsetT newval; | |
23380 | unsigned int newimm; | |
23381 | unsigned long temp; | |
23382 | int sign; | |
23383 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 23384 | |
9c2799c2 | 23385 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 23386 | |
c19d1205 | 23387 | /* Note whether this will delete the relocation. */ |
4962c51a | 23388 | |
c19d1205 ZW |
23389 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
23390 | fixP->fx_done = 1; | |
b99bd4ef | 23391 | |
adbaf948 | 23392 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 23393 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
23394 | for emit_reloc. */ |
23395 | value &= 0xffffffff; | |
23396 | value ^= 0x80000000; | |
5f4273c7 | 23397 | value -= 0x80000000; |
adbaf948 ZW |
23398 | |
23399 | *valP = value; | |
c19d1205 | 23400 | fixP->fx_addnumber = value; |
b99bd4ef | 23401 | |
adbaf948 ZW |
23402 | /* Same treatment for fixP->fx_offset. */ |
23403 | fixP->fx_offset &= 0xffffffff; | |
23404 | fixP->fx_offset ^= 0x80000000; | |
23405 | fixP->fx_offset -= 0x80000000; | |
23406 | ||
c19d1205 | 23407 | switch (fixP->fx_r_type) |
b99bd4ef | 23408 | { |
c19d1205 ZW |
23409 | case BFD_RELOC_NONE: |
23410 | /* This will need to go in the object file. */ | |
23411 | fixP->fx_done = 0; | |
23412 | break; | |
b99bd4ef | 23413 | |
c19d1205 ZW |
23414 | case BFD_RELOC_ARM_IMMEDIATE: |
23415 | /* We claim that this fixup has been processed here, | |
23416 | even if in fact we generate an error because we do | |
23417 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
23418 | fixP->fx_done = 1; | |
b99bd4ef | 23419 | |
77db8e2e | 23420 | if (fixP->fx_addsy) |
b99bd4ef | 23421 | { |
77db8e2e | 23422 | const char *msg = 0; |
b99bd4ef | 23423 | |
77db8e2e NC |
23424 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
23425 | msg = _("undefined symbol %s used as an immediate value"); | |
23426 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
23427 | msg = _("symbol %s is in a different section"); | |
23428 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
23429 | msg = _("symbol %s is weak and may be overridden later"); | |
23430 | ||
23431 | if (msg) | |
23432 | { | |
23433 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23434 | msg, S_GET_NAME (fixP->fx_addsy)); | |
23435 | break; | |
23436 | } | |
42e5fcbf AS |
23437 | } |
23438 | ||
c19d1205 ZW |
23439 | temp = md_chars_to_number (buf, INSN_SIZE); |
23440 | ||
5e73442d SL |
23441 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
23442 | if ((temp & 0xfff0000) == 0x28f0000 && value < 0) | |
23443 | newimm = negate_data_op (&temp, value); | |
23444 | else | |
23445 | { | |
23446 | newimm = encode_arm_immediate (value); | |
23447 | ||
23448 | /* If the instruction will fail, see if we can fix things up by | |
23449 | changing the opcode. */ | |
23450 | if (newimm == (unsigned int) FAIL) | |
23451 | newimm = negate_data_op (&temp, value); | |
bada4342 JW |
23452 | /* MOV accepts both ARM modified immediate (A1 encoding) and |
23453 | UINT16 (A2 encoding) when possible, MOVW only accepts UINT16. | |
23454 | When disassembling, MOV is preferred when there is no encoding | |
23455 | overlap. */ | |
23456 | if (newimm == (unsigned int) FAIL | |
23457 | && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV | |
23458 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) | |
23459 | && !((temp >> SBIT_SHIFT) & 0x1) | |
23460 | && value >= 0 && value <= 0xffff) | |
23461 | { | |
23462 | /* Clear bits[23:20] to change encoding from A1 to A2. */ | |
23463 | temp &= 0xff0fffff; | |
23464 | /* Encoding high 4bits imm. Code below will encode the remaining | |
23465 | low 12bits. */ | |
23466 | temp |= (value & 0x0000f000) << 4; | |
23467 | newimm = value & 0x00000fff; | |
23468 | } | |
5e73442d SL |
23469 | } |
23470 | ||
23471 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 23472 | { |
c19d1205 ZW |
23473 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23474 | _("invalid constant (%lx) after fixup"), | |
23475 | (unsigned long) value); | |
23476 | break; | |
b99bd4ef | 23477 | } |
b99bd4ef | 23478 | |
c19d1205 ZW |
23479 | newimm |= (temp & 0xfffff000); |
23480 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
23481 | break; | |
b99bd4ef | 23482 | |
c19d1205 ZW |
23483 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
23484 | { | |
23485 | unsigned int highpart = 0; | |
23486 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 23487 | |
77db8e2e | 23488 | if (fixP->fx_addsy) |
42e5fcbf | 23489 | { |
77db8e2e | 23490 | const char *msg = 0; |
42e5fcbf | 23491 | |
77db8e2e NC |
23492 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
23493 | msg = _("undefined symbol %s used as an immediate value"); | |
23494 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
23495 | msg = _("symbol %s is in a different section"); | |
23496 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
23497 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 23498 | |
77db8e2e NC |
23499 | if (msg) |
23500 | { | |
23501 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23502 | msg, S_GET_NAME (fixP->fx_addsy)); | |
23503 | break; | |
23504 | } | |
23505 | } | |
fa94de6b | 23506 | |
c19d1205 ZW |
23507 | newimm = encode_arm_immediate (value); |
23508 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 23509 | |
c19d1205 ZW |
23510 | /* If the instruction will fail, see if we can fix things up by |
23511 | changing the opcode. */ | |
23512 | if (newimm == (unsigned int) FAIL | |
23513 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
23514 | { | |
23515 | /* No ? OK - try using two ADD instructions to generate | |
23516 | the value. */ | |
23517 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 23518 | |
c19d1205 ZW |
23519 | /* Yes - then make sure that the second instruction is |
23520 | also an add. */ | |
23521 | if (newimm != (unsigned int) FAIL) | |
23522 | newinsn = temp; | |
23523 | /* Still No ? Try using a negated value. */ | |
23524 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
23525 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
23526 | /* Otherwise - give up. */ | |
23527 | else | |
23528 | { | |
23529 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23530 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
23531 | (long) value); | |
23532 | break; | |
23533 | } | |
b99bd4ef | 23534 | |
c19d1205 ZW |
23535 | /* Replace the first operand in the 2nd instruction (which |
23536 | is the PC) with the destination register. We have | |
23537 | already added in the PC in the first instruction and we | |
23538 | do not want to do it again. */ | |
23539 | newinsn &= ~ 0xf0000; | |
23540 | newinsn |= ((newinsn & 0x0f000) << 4); | |
23541 | } | |
b99bd4ef | 23542 | |
c19d1205 ZW |
23543 | newimm |= (temp & 0xfffff000); |
23544 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 23545 | |
c19d1205 ZW |
23546 | highpart |= (newinsn & 0xfffff000); |
23547 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
23548 | } | |
23549 | break; | |
b99bd4ef | 23550 | |
c19d1205 | 23551 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
23552 | if (!fixP->fx_done && seg->use_rela_p) |
23553 | value = 0; | |
1a0670f3 | 23554 | /* Fall through. */ |
00a97672 | 23555 | |
c19d1205 | 23556 | case BFD_RELOC_ARM_LITERAL: |
26d97720 | 23557 | sign = value > 0; |
b99bd4ef | 23558 | |
c19d1205 ZW |
23559 | if (value < 0) |
23560 | value = - value; | |
b99bd4ef | 23561 | |
c19d1205 | 23562 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 23563 | { |
c19d1205 ZW |
23564 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
23565 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23566 | _("invalid literal constant: pool needs to be closer")); | |
23567 | else | |
23568 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23569 | _("bad immediate value for offset (%ld)"), | |
23570 | (long) value); | |
23571 | break; | |
f03698e6 RE |
23572 | } |
23573 | ||
c19d1205 | 23574 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
23575 | if (value == 0) |
23576 | newval &= 0xfffff000; | |
23577 | else | |
23578 | { | |
23579 | newval &= 0xff7ff000; | |
23580 | newval |= value | (sign ? INDEX_UP : 0); | |
23581 | } | |
c19d1205 ZW |
23582 | md_number_to_chars (buf, newval, INSN_SIZE); |
23583 | break; | |
b99bd4ef | 23584 | |
c19d1205 ZW |
23585 | case BFD_RELOC_ARM_OFFSET_IMM8: |
23586 | case BFD_RELOC_ARM_HWLITERAL: | |
26d97720 | 23587 | sign = value > 0; |
b99bd4ef | 23588 | |
c19d1205 ZW |
23589 | if (value < 0) |
23590 | value = - value; | |
b99bd4ef | 23591 | |
c19d1205 | 23592 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 23593 | { |
c19d1205 ZW |
23594 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
23595 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23596 | _("invalid literal constant: pool needs to be closer")); | |
23597 | else | |
427d0db6 RM |
23598 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23599 | _("bad immediate value for 8-bit offset (%ld)"), | |
23600 | (long) value); | |
c19d1205 | 23601 | break; |
b99bd4ef NC |
23602 | } |
23603 | ||
c19d1205 | 23604 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
23605 | if (value == 0) |
23606 | newval &= 0xfffff0f0; | |
23607 | else | |
23608 | { | |
23609 | newval &= 0xff7ff0f0; | |
23610 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
23611 | } | |
c19d1205 ZW |
23612 | md_number_to_chars (buf, newval, INSN_SIZE); |
23613 | break; | |
b99bd4ef | 23614 | |
c19d1205 ZW |
23615 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
23616 | if (value < 0 || value > 1020 || value % 4 != 0) | |
23617 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23618 | _("bad immediate value for offset (%ld)"), (long) value); | |
23619 | value /= 4; | |
b99bd4ef | 23620 | |
c19d1205 | 23621 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
23622 | newval |= value; |
23623 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
23624 | break; | |
b99bd4ef | 23625 | |
c19d1205 ZW |
23626 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
23627 | /* This is a complicated relocation used for all varieties of Thumb32 | |
23628 | load/store instruction with immediate offset: | |
23629 | ||
23630 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
477330fc | 23631 | *4, optional writeback(W) |
c19d1205 ZW |
23632 | (doubleword load/store) |
23633 | ||
23634 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
23635 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
23636 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
23637 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
23638 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
23639 | ||
23640 | Uppercase letters indicate bits that are already encoded at | |
23641 | this point. Lowercase letters are our problem. For the | |
23642 | second block of instructions, the secondary opcode nybble | |
23643 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
23644 | a PC-relative operation. */ | |
23645 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23646 | newval <<= 16; | |
23647 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 23648 | |
c19d1205 | 23649 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 23650 | { |
c19d1205 ZW |
23651 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
23652 | if (value >= 0) | |
23653 | newval |= (1 << 23); | |
23654 | else | |
23655 | value = -value; | |
23656 | if (value % 4 != 0) | |
23657 | { | |
23658 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23659 | _("offset not a multiple of 4")); | |
23660 | break; | |
23661 | } | |
23662 | value /= 4; | |
216d22bc | 23663 | if (value > 0xff) |
c19d1205 ZW |
23664 | { |
23665 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23666 | _("offset out of range")); | |
23667 | break; | |
23668 | } | |
23669 | newval &= ~0xff; | |
b99bd4ef | 23670 | } |
c19d1205 | 23671 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 23672 | { |
c19d1205 ZW |
23673 | /* PC-relative, 12-bit offset. */ |
23674 | if (value >= 0) | |
23675 | newval |= (1 << 23); | |
23676 | else | |
23677 | value = -value; | |
216d22bc | 23678 | if (value > 0xfff) |
c19d1205 ZW |
23679 | { |
23680 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23681 | _("offset out of range")); | |
23682 | break; | |
23683 | } | |
23684 | newval &= ~0xfff; | |
b99bd4ef | 23685 | } |
c19d1205 | 23686 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 23687 | { |
c19d1205 ZW |
23688 | /* Writeback: 8-bit, +/- offset. */ |
23689 | if (value >= 0) | |
23690 | newval |= (1 << 9); | |
23691 | else | |
23692 | value = -value; | |
216d22bc | 23693 | if (value > 0xff) |
c19d1205 ZW |
23694 | { |
23695 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23696 | _("offset out of range")); | |
23697 | break; | |
23698 | } | |
23699 | newval &= ~0xff; | |
b99bd4ef | 23700 | } |
c19d1205 | 23701 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 23702 | { |
c19d1205 | 23703 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 23704 | if (value < 0 || value > 0xff) |
b99bd4ef | 23705 | { |
c19d1205 ZW |
23706 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23707 | _("offset out of range")); | |
23708 | break; | |
b99bd4ef | 23709 | } |
c19d1205 ZW |
23710 | newval &= ~0xff; |
23711 | newval |= value; | |
b99bd4ef NC |
23712 | } |
23713 | else | |
b99bd4ef | 23714 | { |
c19d1205 ZW |
23715 | /* Positive 12-bit or negative 8-bit offset. */ |
23716 | int limit; | |
23717 | if (value >= 0) | |
b99bd4ef | 23718 | { |
c19d1205 ZW |
23719 | newval |= (1 << 23); |
23720 | limit = 0xfff; | |
23721 | } | |
23722 | else | |
23723 | { | |
23724 | value = -value; | |
23725 | limit = 0xff; | |
23726 | } | |
23727 | if (value > limit) | |
23728 | { | |
23729 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23730 | _("offset out of range")); | |
23731 | break; | |
b99bd4ef | 23732 | } |
c19d1205 | 23733 | newval &= ~limit; |
b99bd4ef | 23734 | } |
b99bd4ef | 23735 | |
c19d1205 ZW |
23736 | newval |= value; |
23737 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
23738 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
23739 | break; | |
404ff6b5 | 23740 | |
c19d1205 ZW |
23741 | case BFD_RELOC_ARM_SHIFT_IMM: |
23742 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23743 | if (((unsigned long) value) > 32 | |
23744 | || (value == 32 | |
23745 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
23746 | { | |
23747 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23748 | _("shift expression is too large")); | |
23749 | break; | |
23750 | } | |
404ff6b5 | 23751 | |
c19d1205 ZW |
23752 | if (value == 0) |
23753 | /* Shifts of zero must be done as lsl. */ | |
23754 | newval &= ~0x60; | |
23755 | else if (value == 32) | |
23756 | value = 0; | |
23757 | newval &= 0xfffff07f; | |
23758 | newval |= (value & 0x1f) << 7; | |
23759 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23760 | break; | |
404ff6b5 | 23761 | |
c19d1205 | 23762 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 23763 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 23764 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 23765 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
23766 | /* We claim that this fixup has been processed here, |
23767 | even if in fact we generate an error because we do | |
23768 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
23769 | fixP->fx_done = 1; | |
404ff6b5 | 23770 | |
c19d1205 ZW |
23771 | if (fixP->fx_addsy |
23772 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
23773 | { | |
23774 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23775 | _("undefined symbol %s used as an immediate value"), | |
23776 | S_GET_NAME (fixP->fx_addsy)); | |
23777 | break; | |
23778 | } | |
404ff6b5 | 23779 | |
c19d1205 ZW |
23780 | newval = md_chars_to_number (buf, THUMB_SIZE); |
23781 | newval <<= 16; | |
23782 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 23783 | |
16805f35 | 23784 | newimm = FAIL; |
bada4342 JW |
23785 | if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
23786 | /* ARMv8-M Baseline MOV will reach here, but it doesn't support | |
23787 | Thumb2 modified immediate encoding (T2). */ | |
23788 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
16805f35 | 23789 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) |
ef8d22e6 PB |
23790 | { |
23791 | newimm = encode_thumb32_immediate (value); | |
23792 | if (newimm == (unsigned int) FAIL) | |
23793 | newimm = thumb32_negate_data_op (&newval, value); | |
23794 | } | |
bada4342 | 23795 | if (newimm == (unsigned int) FAIL) |
92e90b6e | 23796 | { |
bada4342 | 23797 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE) |
e9f89963 | 23798 | { |
bada4342 JW |
23799 | /* Turn add/sum into addw/subw. */ |
23800 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
23801 | newval = (newval & 0xfeffffff) | 0x02000000; | |
23802 | /* No flat 12-bit imm encoding for addsw/subsw. */ | |
23803 | if ((newval & 0x00100000) == 0) | |
40f246e3 | 23804 | { |
bada4342 JW |
23805 | /* 12 bit immediate for addw/subw. */ |
23806 | if (value < 0) | |
23807 | { | |
23808 | value = -value; | |
23809 | newval ^= 0x00a00000; | |
23810 | } | |
23811 | if (value > 0xfff) | |
23812 | newimm = (unsigned int) FAIL; | |
23813 | else | |
23814 | newimm = value; | |
23815 | } | |
23816 | } | |
23817 | else | |
23818 | { | |
23819 | /* MOV accepts both Thumb2 modified immediate (T2 encoding) and | |
23820 | UINT16 (T3 encoding), MOVW only accepts UINT16. When | |
23821 | disassembling, MOV is preferred when there is no encoding | |
db7bf105 | 23822 | overlap. */ |
bada4342 | 23823 | if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR |
db7bf105 NC |
23824 | /* NOTE: MOV uses the ORR opcode in Thumb 2 mode |
23825 | but with the Rn field [19:16] set to 1111. */ | |
23826 | && (((newval >> 16) & 0xf) == 0xf) | |
bada4342 JW |
23827 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m) |
23828 | && !((newval >> T2_SBIT_SHIFT) & 0x1) | |
db7bf105 | 23829 | && value >= 0 && value <= 0xffff) |
bada4342 JW |
23830 | { |
23831 | /* Toggle bit[25] to change encoding from T2 to T3. */ | |
23832 | newval ^= 1 << 25; | |
23833 | /* Clear bits[19:16]. */ | |
23834 | newval &= 0xfff0ffff; | |
23835 | /* Encoding high 4bits imm. Code below will encode the | |
23836 | remaining low 12bits. */ | |
23837 | newval |= (value & 0x0000f000) << 4; | |
23838 | newimm = value & 0x00000fff; | |
40f246e3 | 23839 | } |
e9f89963 | 23840 | } |
92e90b6e | 23841 | } |
cc8a6dd0 | 23842 | |
c19d1205 | 23843 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 23844 | { |
c19d1205 ZW |
23845 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23846 | _("invalid constant (%lx) after fixup"), | |
23847 | (unsigned long) value); | |
23848 | break; | |
3631a3c8 NC |
23849 | } |
23850 | ||
c19d1205 ZW |
23851 | newval |= (newimm & 0x800) << 15; |
23852 | newval |= (newimm & 0x700) << 4; | |
23853 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 23854 | |
c19d1205 ZW |
23855 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
23856 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
23857 | break; | |
a737bd4d | 23858 | |
3eb17e6b | 23859 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
23860 | if (((unsigned long) value) > 0xffff) |
23861 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 23862 | _("invalid smc expression")); |
2fc8bdac | 23863 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
23864 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
23865 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23866 | break; | |
a737bd4d | 23867 | |
90ec0d68 MGD |
23868 | case BFD_RELOC_ARM_HVC: |
23869 | if (((unsigned long) value) > 0xffff) | |
23870 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23871 | _("invalid hvc expression")); | |
23872 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23873 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
23874 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23875 | break; | |
23876 | ||
c19d1205 | 23877 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 23878 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
23879 | { |
23880 | if (((unsigned long) value) > 0xff) | |
23881 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23882 | _("invalid swi expression")); | |
2fc8bdac | 23883 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
23884 | newval |= value; |
23885 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23886 | } | |
23887 | else | |
23888 | { | |
23889 | if (((unsigned long) value) > 0x00ffffff) | |
23890 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23891 | _("invalid swi expression")); | |
2fc8bdac | 23892 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
23893 | newval |= value; |
23894 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23895 | } | |
23896 | break; | |
a737bd4d | 23897 | |
c19d1205 ZW |
23898 | case BFD_RELOC_ARM_MULTI: |
23899 | if (((unsigned long) value) > 0xffff) | |
23900 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23901 | _("invalid expression in load/store multiple")); | |
23902 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
23903 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23904 | break; | |
a737bd4d | 23905 | |
c19d1205 | 23906 | #ifdef OBJ_ELF |
39b41c9c | 23907 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
23908 | |
23909 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
23910 | && fixP->fx_addsy | |
34e77a92 | 23911 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23912 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23913 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
23914 | /* Flip the bl to blx. This is a simple flip | |
23915 | bit here because we generate PCREL_CALL for | |
23916 | unconditional bls. */ | |
23917 | { | |
23918 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23919 | newval = newval | 0x10000000; | |
23920 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23921 | temp = 1; | |
23922 | fixP->fx_done = 1; | |
23923 | } | |
39b41c9c PB |
23924 | else |
23925 | temp = 3; | |
23926 | goto arm_branch_common; | |
23927 | ||
23928 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
23929 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
23930 | && fixP->fx_addsy | |
34e77a92 | 23931 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23932 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23933 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
23934 | { | |
23935 | /* This would map to a bl<cond>, b<cond>, | |
23936 | b<always> to a Thumb function. We | |
23937 | need to force a relocation for this particular | |
23938 | case. */ | |
23939 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23940 | fixP->fx_done = 0; | |
23941 | } | |
1a0670f3 | 23942 | /* Fall through. */ |
267bf995 | 23943 | |
2fc8bdac | 23944 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 23945 | #endif |
39b41c9c PB |
23946 | case BFD_RELOC_ARM_PCREL_BRANCH: |
23947 | temp = 3; | |
23948 | goto arm_branch_common; | |
a737bd4d | 23949 | |
39b41c9c | 23950 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 23951 | |
39b41c9c | 23952 | temp = 1; |
267bf995 RR |
23953 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
23954 | && fixP->fx_addsy | |
34e77a92 | 23955 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23956 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23957 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
23958 | { | |
23959 | /* Flip the blx to a bl and warn. */ | |
23960 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
23961 | newval = 0xeb000000; | |
23962 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
23963 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
23964 | name); | |
23965 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23966 | temp = 3; | |
23967 | fixP->fx_done = 1; | |
23968 | } | |
23969 | ||
23970 | #ifdef OBJ_ELF | |
23971 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
477330fc | 23972 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; |
267bf995 RR |
23973 | #endif |
23974 | ||
39b41c9c | 23975 | arm_branch_common: |
c19d1205 | 23976 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
23977 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
23978 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
de194d85 | 23979 | also be clear. */ |
39b41c9c | 23980 | if (value & temp) |
c19d1205 | 23981 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
23982 | _("misaligned branch destination")); |
23983 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
23984 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
08f10d51 | 23985 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 23986 | |
2fc8bdac | 23987 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 23988 | { |
2fc8bdac ZW |
23989 | newval = md_chars_to_number (buf, INSN_SIZE); |
23990 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
23991 | /* Set the H bit on BLX instructions. */ |
23992 | if (temp == 1) | |
23993 | { | |
23994 | if (value & 2) | |
23995 | newval |= 0x01000000; | |
23996 | else | |
23997 | newval &= ~0x01000000; | |
23998 | } | |
2fc8bdac | 23999 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 24000 | } |
c19d1205 | 24001 | break; |
a737bd4d | 24002 | |
25fe350b MS |
24003 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
24004 | /* CBZ can only branch forward. */ | |
a737bd4d | 24005 | |
738755b0 | 24006 | /* Attempts to use CBZ to branch to the next instruction |
477330fc RM |
24007 | (which, strictly speaking, are prohibited) will be turned into |
24008 | no-ops. | |
738755b0 MS |
24009 | |
24010 | FIXME: It may be better to remove the instruction completely and | |
24011 | perform relaxation. */ | |
24012 | if (value == -2) | |
2fc8bdac ZW |
24013 | { |
24014 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 24015 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
24016 | md_number_to_chars (buf, newval, THUMB_SIZE); |
24017 | } | |
738755b0 MS |
24018 | else |
24019 | { | |
24020 | if (value & ~0x7e) | |
08f10d51 | 24021 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 | 24022 | |
477330fc | 24023 | if (fixP->fx_done || !seg->use_rela_p) |
738755b0 MS |
24024 | { |
24025 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24026 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
24027 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24028 | } | |
24029 | } | |
c19d1205 | 24030 | break; |
a737bd4d | 24031 | |
c19d1205 | 24032 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac | 24033 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
08f10d51 | 24034 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 24035 | |
2fc8bdac ZW |
24036 | if (fixP->fx_done || !seg->use_rela_p) |
24037 | { | |
24038 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24039 | newval |= (value & 0x1ff) >> 1; | |
24040 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24041 | } | |
c19d1205 | 24042 | break; |
a737bd4d | 24043 | |
c19d1205 | 24044 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac | 24045 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
08f10d51 | 24046 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 24047 | |
2fc8bdac ZW |
24048 | if (fixP->fx_done || !seg->use_rela_p) |
24049 | { | |
24050 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24051 | newval |= (value & 0xfff) >> 1; | |
24052 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24053 | } | |
c19d1205 | 24054 | break; |
a737bd4d | 24055 | |
c19d1205 | 24056 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
24057 | if (fixP->fx_addsy |
24058 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 24059 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24060 | && ARM_IS_FUNC (fixP->fx_addsy) |
24061 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
24062 | { | |
24063 | /* Force a relocation for a branch 20 bits wide. */ | |
24064 | fixP->fx_done = 0; | |
24065 | } | |
08f10d51 | 24066 | if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff)) |
2fc8bdac ZW |
24067 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24068 | _("conditional branch out of range")); | |
404ff6b5 | 24069 | |
2fc8bdac ZW |
24070 | if (fixP->fx_done || !seg->use_rela_p) |
24071 | { | |
24072 | offsetT newval2; | |
24073 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 24074 | |
2fc8bdac ZW |
24075 | S = (value & 0x00100000) >> 20; |
24076 | J2 = (value & 0x00080000) >> 19; | |
24077 | J1 = (value & 0x00040000) >> 18; | |
24078 | hi = (value & 0x0003f000) >> 12; | |
24079 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 24080 | |
2fc8bdac ZW |
24081 | newval = md_chars_to_number (buf, THUMB_SIZE); |
24082 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24083 | newval |= (S << 10) | hi; | |
24084 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
24085 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24086 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
24087 | } | |
c19d1205 | 24088 | break; |
6c43fab6 | 24089 | |
c19d1205 | 24090 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
24091 | /* If there is a blx from a thumb state function to |
24092 | another thumb function flip this to a bl and warn | |
24093 | about it. */ | |
24094 | ||
24095 | if (fixP->fx_addsy | |
34e77a92 | 24096 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24097 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
24098 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
24099 | { | |
24100 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
24101 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
24102 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
24103 | name); | |
24104 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24105 | newval = newval | 0x1000; | |
24106 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
24107 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
24108 | fixP->fx_done = 1; | |
24109 | } | |
24110 | ||
24111 | ||
24112 | goto thumb_bl_common; | |
24113 | ||
c19d1205 | 24114 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
24115 | /* A bl from Thumb state ISA to an internal ARM state function |
24116 | is converted to a blx. */ | |
24117 | if (fixP->fx_addsy | |
24118 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 24119 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
24120 | && ARM_IS_FUNC (fixP->fx_addsy) |
24121 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
24122 | { | |
24123 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24124 | newval = newval & ~0x1000; | |
24125 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
24126 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
24127 | fixP->fx_done = 1; | |
24128 | } | |
24129 | ||
24130 | thumb_bl_common: | |
24131 | ||
2fc8bdac ZW |
24132 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
24133 | /* For a BLX instruction, make sure that the relocation is rounded up | |
24134 | to a word boundary. This follows the semantics of the instruction | |
24135 | which specifies that bit 1 of the target address will come from bit | |
24136 | 1 of the base address. */ | |
d406f3e4 JB |
24137 | value = (value + 3) & ~ 3; |
24138 | ||
24139 | #ifdef OBJ_ELF | |
24140 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 | |
24141 | && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
24142 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
24143 | #endif | |
404ff6b5 | 24144 | |
2b2f5df9 NC |
24145 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
24146 | { | |
fc289b0a | 24147 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))) |
2b2f5df9 NC |
24148 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
24149 | else if ((value & ~0x1ffffff) | |
24150 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
24151 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24152 | _("Thumb2 branch out of range")); | |
24153 | } | |
4a42ebbc RR |
24154 | |
24155 | if (fixP->fx_done || !seg->use_rela_p) | |
24156 | encode_thumb2_b_bl_offset (buf, value); | |
24157 | ||
c19d1205 | 24158 | break; |
404ff6b5 | 24159 | |
c19d1205 | 24160 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
08f10d51 NC |
24161 | if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff)) |
24162 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
6c43fab6 | 24163 | |
2fc8bdac | 24164 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 24165 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 24166 | |
2fc8bdac | 24167 | break; |
a737bd4d | 24168 | |
2fc8bdac ZW |
24169 | case BFD_RELOC_8: |
24170 | if (fixP->fx_done || !seg->use_rela_p) | |
4b1a927e | 24171 | *buf = value; |
c19d1205 | 24172 | break; |
a737bd4d | 24173 | |
c19d1205 | 24174 | case BFD_RELOC_16: |
2fc8bdac | 24175 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 24176 | md_number_to_chars (buf, value, 2); |
c19d1205 | 24177 | break; |
a737bd4d | 24178 | |
c19d1205 | 24179 | #ifdef OBJ_ELF |
0855e32b NS |
24180 | case BFD_RELOC_ARM_TLS_CALL: |
24181 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
24182 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
24183 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
0855e32b | 24184 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
24185 | case BFD_RELOC_ARM_TLS_GD32: |
24186 | case BFD_RELOC_ARM_TLS_LE32: | |
24187 | case BFD_RELOC_ARM_TLS_IE32: | |
24188 | case BFD_RELOC_ARM_TLS_LDM32: | |
24189 | case BFD_RELOC_ARM_TLS_LDO32: | |
24190 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
4b1a927e | 24191 | break; |
6c43fab6 | 24192 | |
5c5a4843 CL |
24193 | /* Same handling as above, but with the arm_fdpic guard. */ |
24194 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: | |
24195 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: | |
24196 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: | |
24197 | if (arm_fdpic) | |
24198 | { | |
24199 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
24200 | } | |
24201 | else | |
24202 | { | |
24203 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24204 | _("Relocation supported only in FDPIC mode")); | |
24205 | } | |
24206 | break; | |
24207 | ||
c19d1205 ZW |
24208 | case BFD_RELOC_ARM_GOT32: |
24209 | case BFD_RELOC_ARM_GOTOFF: | |
c19d1205 | 24210 | break; |
b43420e6 NC |
24211 | |
24212 | case BFD_RELOC_ARM_GOT_PREL: | |
24213 | if (fixP->fx_done || !seg->use_rela_p) | |
477330fc | 24214 | md_number_to_chars (buf, value, 4); |
b43420e6 NC |
24215 | break; |
24216 | ||
9a6f4e97 NS |
24217 | case BFD_RELOC_ARM_TARGET2: |
24218 | /* TARGET2 is not partial-inplace, so we need to write the | |
477330fc RM |
24219 | addend here for REL targets, because it won't be written out |
24220 | during reloc processing later. */ | |
9a6f4e97 NS |
24221 | if (fixP->fx_done || !seg->use_rela_p) |
24222 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
24223 | break; | |
188fd7ae CL |
24224 | |
24225 | /* Relocations for FDPIC. */ | |
24226 | case BFD_RELOC_ARM_GOTFUNCDESC: | |
24227 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
24228 | case BFD_RELOC_ARM_FUNCDESC: | |
24229 | if (arm_fdpic) | |
24230 | { | |
24231 | if (fixP->fx_done || !seg->use_rela_p) | |
24232 | md_number_to_chars (buf, 0, 4); | |
24233 | } | |
24234 | else | |
24235 | { | |
24236 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24237 | _("Relocation supported only in FDPIC mode")); | |
24238 | } | |
24239 | break; | |
c19d1205 | 24240 | #endif |
6c43fab6 | 24241 | |
c19d1205 ZW |
24242 | case BFD_RELOC_RVA: |
24243 | case BFD_RELOC_32: | |
24244 | case BFD_RELOC_ARM_TARGET1: | |
24245 | case BFD_RELOC_ARM_ROSEGREL32: | |
24246 | case BFD_RELOC_ARM_SBREL32: | |
24247 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
24248 | #ifdef TE_PE |
24249 | case BFD_RELOC_32_SECREL: | |
24250 | #endif | |
2fc8bdac | 24251 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
24252 | #ifdef TE_WINCE |
24253 | /* For WinCE we only do this for pcrel fixups. */ | |
24254 | if (fixP->fx_done || fixP->fx_pcrel) | |
24255 | #endif | |
24256 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 24257 | break; |
6c43fab6 | 24258 | |
c19d1205 ZW |
24259 | #ifdef OBJ_ELF |
24260 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 24261 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
24262 | { |
24263 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
24264 | if ((value ^ (value >> 1)) & 0x40000000) | |
24265 | { | |
24266 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24267 | _("rel31 relocation overflow")); | |
24268 | } | |
24269 | newval |= value & 0x7fffffff; | |
24270 | md_number_to_chars (buf, newval, 4); | |
24271 | } | |
24272 | break; | |
c19d1205 | 24273 | #endif |
a737bd4d | 24274 | |
c19d1205 | 24275 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 24276 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
9db2f6b4 RL |
24277 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM) |
24278 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24279 | else | |
24280 | newval = get_thumb32_insn (buf); | |
24281 | if ((newval & 0x0f200f00) == 0x0d000900) | |
24282 | { | |
24283 | /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic | |
24284 | has permitted values that are multiples of 2, in the range 0 | |
24285 | to 510. */ | |
24286 | if (value < -510 || value > 510 || (value & 1)) | |
24287 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24288 | _("co-processor offset out of range")); | |
24289 | } | |
24290 | else if (value < -1023 || value > 1023 || (value & 3)) | |
c19d1205 ZW |
24291 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24292 | _("co-processor offset out of range")); | |
24293 | cp_off_common: | |
26d97720 | 24294 | sign = value > 0; |
c19d1205 ZW |
24295 | if (value < 0) |
24296 | value = -value; | |
8f06b2d8 PB |
24297 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
24298 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
24299 | newval = md_chars_to_number (buf, INSN_SIZE); | |
24300 | else | |
24301 | newval = get_thumb32_insn (buf); | |
26d97720 NS |
24302 | if (value == 0) |
24303 | newval &= 0xffffff00; | |
24304 | else | |
24305 | { | |
24306 | newval &= 0xff7fff00; | |
9db2f6b4 RL |
24307 | if ((newval & 0x0f200f00) == 0x0d000900) |
24308 | { | |
24309 | /* This is a fp16 vstr/vldr. | |
24310 | ||
24311 | It requires the immediate offset in the instruction is shifted | |
24312 | left by 1 to be a half-word offset. | |
24313 | ||
24314 | Here, left shift by 1 first, and later right shift by 2 | |
24315 | should get the right offset. */ | |
24316 | value <<= 1; | |
24317 | } | |
26d97720 NS |
24318 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
24319 | } | |
8f06b2d8 PB |
24320 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
24321 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
24322 | md_number_to_chars (buf, newval, INSN_SIZE); | |
24323 | else | |
24324 | put_thumb32_insn (buf, newval); | |
c19d1205 | 24325 | break; |
a737bd4d | 24326 | |
c19d1205 | 24327 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 24328 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
24329 | if (value < -255 || value > 255) |
24330 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24331 | _("co-processor offset out of range")); | |
df7849c5 | 24332 | value *= 4; |
c19d1205 | 24333 | goto cp_off_common; |
6c43fab6 | 24334 | |
c19d1205 ZW |
24335 | case BFD_RELOC_ARM_THUMB_OFFSET: |
24336 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24337 | /* Exactly what ranges, and where the offset is inserted depends | |
24338 | on the type of instruction, we can establish this from the | |
24339 | top 4 bits. */ | |
24340 | switch (newval >> 12) | |
24341 | { | |
24342 | case 4: /* PC load. */ | |
24343 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
24344 | forced to zero for these loads; md_pcrel_from has already | |
24345 | compensated for this. */ | |
24346 | if (value & 3) | |
24347 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24348 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
24349 | (((unsigned long) fixP->fx_frag->fr_address |
24350 | + (unsigned long) fixP->fx_where) & ~3) | |
24351 | + (unsigned long) value); | |
a737bd4d | 24352 | |
c19d1205 ZW |
24353 | if (value & ~0x3fc) |
24354 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24355 | _("invalid offset, value too big (0x%08lX)"), | |
24356 | (long) value); | |
a737bd4d | 24357 | |
c19d1205 ZW |
24358 | newval |= value >> 2; |
24359 | break; | |
a737bd4d | 24360 | |
c19d1205 ZW |
24361 | case 9: /* SP load/store. */ |
24362 | if (value & ~0x3fc) | |
24363 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24364 | _("invalid offset, value too big (0x%08lX)"), | |
24365 | (long) value); | |
24366 | newval |= value >> 2; | |
24367 | break; | |
6c43fab6 | 24368 | |
c19d1205 ZW |
24369 | case 6: /* Word load/store. */ |
24370 | if (value & ~0x7c) | |
24371 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24372 | _("invalid offset, value too big (0x%08lX)"), | |
24373 | (long) value); | |
24374 | newval |= value << 4; /* 6 - 2. */ | |
24375 | break; | |
a737bd4d | 24376 | |
c19d1205 ZW |
24377 | case 7: /* Byte load/store. */ |
24378 | if (value & ~0x1f) | |
24379 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24380 | _("invalid offset, value too big (0x%08lX)"), | |
24381 | (long) value); | |
24382 | newval |= value << 6; | |
24383 | break; | |
a737bd4d | 24384 | |
c19d1205 ZW |
24385 | case 8: /* Halfword load/store. */ |
24386 | if (value & ~0x3e) | |
24387 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24388 | _("invalid offset, value too big (0x%08lX)"), | |
24389 | (long) value); | |
24390 | newval |= value << 5; /* 6 - 1. */ | |
24391 | break; | |
a737bd4d | 24392 | |
c19d1205 ZW |
24393 | default: |
24394 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24395 | "Unable to process relocation for thumb opcode: %lx", | |
24396 | (unsigned long) newval); | |
24397 | break; | |
24398 | } | |
24399 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24400 | break; | |
a737bd4d | 24401 | |
c19d1205 ZW |
24402 | case BFD_RELOC_ARM_THUMB_ADD: |
24403 | /* This is a complicated relocation, since we use it for all of | |
24404 | the following immediate relocations: | |
a737bd4d | 24405 | |
c19d1205 ZW |
24406 | 3bit ADD/SUB |
24407 | 8bit ADD/SUB | |
24408 | 9bit ADD/SUB SP word-aligned | |
24409 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 24410 | |
c19d1205 ZW |
24411 | The type of instruction being processed is encoded in the |
24412 | instruction field: | |
a737bd4d | 24413 | |
c19d1205 ZW |
24414 | 0x8000 SUB |
24415 | 0x00F0 Rd | |
24416 | 0x000F Rs | |
24417 | */ | |
24418 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24419 | { | |
24420 | int rd = (newval >> 4) & 0xf; | |
24421 | int rs = newval & 0xf; | |
24422 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 24423 | |
c19d1205 ZW |
24424 | /* Check for HI regs, only very restricted cases allowed: |
24425 | Adjusting SP, and using PC or SP to get an address. */ | |
24426 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
24427 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
24428 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24429 | _("invalid Hi register with immediate")); | |
a737bd4d | 24430 | |
c19d1205 ZW |
24431 | /* If value is negative, choose the opposite instruction. */ |
24432 | if (value < 0) | |
24433 | { | |
24434 | value = -value; | |
24435 | subtract = !subtract; | |
24436 | if (value < 0) | |
24437 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24438 | _("immediate value out of range")); | |
24439 | } | |
a737bd4d | 24440 | |
c19d1205 ZW |
24441 | if (rd == REG_SP) |
24442 | { | |
75c11999 | 24443 | if (value & ~0x1fc) |
c19d1205 ZW |
24444 | as_bad_where (fixP->fx_file, fixP->fx_line, |
24445 | _("invalid immediate for stack address calculation")); | |
24446 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
24447 | newval |= value >> 2; | |
24448 | } | |
24449 | else if (rs == REG_PC || rs == REG_SP) | |
24450 | { | |
c12d2c9d NC |
24451 | /* PR gas/18541. If the addition is for a defined symbol |
24452 | within range of an ADR instruction then accept it. */ | |
24453 | if (subtract | |
24454 | && value == 4 | |
24455 | && fixP->fx_addsy != NULL) | |
24456 | { | |
24457 | subtract = 0; | |
24458 | ||
24459 | if (! S_IS_DEFINED (fixP->fx_addsy) | |
24460 | || S_GET_SEGMENT (fixP->fx_addsy) != seg | |
24461 | || S_IS_WEAK (fixP->fx_addsy)) | |
24462 | { | |
24463 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24464 | _("address calculation needs a strongly defined nearby symbol")); | |
24465 | } | |
24466 | else | |
24467 | { | |
24468 | offsetT v = fixP->fx_where + fixP->fx_frag->fr_address; | |
24469 | ||
24470 | /* Round up to the next 4-byte boundary. */ | |
24471 | if (v & 3) | |
24472 | v = (v + 3) & ~ 3; | |
24473 | else | |
24474 | v += 4; | |
24475 | v = S_GET_VALUE (fixP->fx_addsy) - v; | |
24476 | ||
24477 | if (v & ~0x3fc) | |
24478 | { | |
24479 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24480 | _("symbol too far away")); | |
24481 | } | |
24482 | else | |
24483 | { | |
24484 | fixP->fx_done = 1; | |
24485 | value = v; | |
24486 | } | |
24487 | } | |
24488 | } | |
24489 | ||
c19d1205 ZW |
24490 | if (subtract || value & ~0x3fc) |
24491 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24492 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
5fc177c8 | 24493 | (unsigned long) (subtract ? - value : value)); |
c19d1205 ZW |
24494 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); |
24495 | newval |= rd << 8; | |
24496 | newval |= value >> 2; | |
24497 | } | |
24498 | else if (rs == rd) | |
24499 | { | |
24500 | if (value & ~0xff) | |
24501 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24502 | _("immediate value out of range")); | |
24503 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
24504 | newval |= (rd << 8) | value; | |
24505 | } | |
24506 | else | |
24507 | { | |
24508 | if (value & ~0x7) | |
24509 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24510 | _("immediate value out of range")); | |
24511 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
24512 | newval |= rd | (rs << 3) | (value << 6); | |
24513 | } | |
24514 | } | |
24515 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24516 | break; | |
a737bd4d | 24517 | |
c19d1205 ZW |
24518 | case BFD_RELOC_ARM_THUMB_IMM: |
24519 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24520 | if (value < 0 || value > 255) | |
24521 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 24522 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
24523 | (long) value); |
24524 | newval |= value; | |
24525 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24526 | break; | |
a737bd4d | 24527 | |
c19d1205 ZW |
24528 | case BFD_RELOC_ARM_THUMB_SHIFT: |
24529 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
24530 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
24531 | temp = newval & 0xf800; | |
24532 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
24533 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24534 | _("invalid shift value: %ld"), (long) value); | |
24535 | /* Shifts of zero must be encoded as LSL. */ | |
24536 | if (value == 0) | |
24537 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
24538 | /* Shifts of 32 are encoded as zero. */ | |
24539 | else if (value == 32) | |
24540 | value = 0; | |
24541 | newval |= value << 6; | |
24542 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24543 | break; | |
a737bd4d | 24544 | |
c19d1205 ZW |
24545 | case BFD_RELOC_VTABLE_INHERIT: |
24546 | case BFD_RELOC_VTABLE_ENTRY: | |
24547 | fixP->fx_done = 0; | |
24548 | return; | |
6c43fab6 | 24549 | |
b6895b4f PB |
24550 | case BFD_RELOC_ARM_MOVW: |
24551 | case BFD_RELOC_ARM_MOVT: | |
24552 | case BFD_RELOC_ARM_THUMB_MOVW: | |
24553 | case BFD_RELOC_ARM_THUMB_MOVT: | |
24554 | if (fixP->fx_done || !seg->use_rela_p) | |
24555 | { | |
24556 | /* REL format relocations are limited to a 16-bit addend. */ | |
24557 | if (!fixP->fx_done) | |
24558 | { | |
39623e12 | 24559 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 24560 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 24561 | _("offset out of range")); |
b6895b4f PB |
24562 | } |
24563 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
24564 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
24565 | { | |
24566 | value >>= 16; | |
24567 | } | |
24568 | ||
24569 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
24570 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
24571 | { | |
24572 | newval = get_thumb32_insn (buf); | |
24573 | newval &= 0xfbf08f00; | |
24574 | newval |= (value & 0xf000) << 4; | |
24575 | newval |= (value & 0x0800) << 15; | |
24576 | newval |= (value & 0x0700) << 4; | |
24577 | newval |= (value & 0x00ff); | |
24578 | put_thumb32_insn (buf, newval); | |
24579 | } | |
24580 | else | |
24581 | { | |
24582 | newval = md_chars_to_number (buf, 4); | |
24583 | newval &= 0xfff0f000; | |
24584 | newval |= value & 0x0fff; | |
24585 | newval |= (value & 0xf000) << 4; | |
24586 | md_number_to_chars (buf, newval, 4); | |
24587 | } | |
24588 | } | |
24589 | return; | |
24590 | ||
72d98d16 MG |
24591 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
24592 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
24593 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
24594 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
24595 | gas_assert (!fixP->fx_done); | |
24596 | { | |
24597 | bfd_vma insn; | |
24598 | bfd_boolean is_mov; | |
24599 | bfd_vma encoded_addend = value; | |
24600 | ||
24601 | /* Check that addend can be encoded in instruction. */ | |
24602 | if (!seg->use_rela_p && (value < 0 || value > 255)) | |
24603 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24604 | _("the offset 0x%08lX is not representable"), | |
24605 | (unsigned long) encoded_addend); | |
24606 | ||
24607 | /* Extract the instruction. */ | |
24608 | insn = md_chars_to_number (buf, THUMB_SIZE); | |
24609 | is_mov = (insn & 0xf800) == 0x2000; | |
24610 | ||
24611 | /* Encode insn. */ | |
24612 | if (is_mov) | |
24613 | { | |
24614 | if (!seg->use_rela_p) | |
24615 | insn |= encoded_addend; | |
24616 | } | |
24617 | else | |
24618 | { | |
24619 | int rd, rs; | |
24620 | ||
24621 | /* Extract the instruction. */ | |
24622 | /* Encoding is the following | |
24623 | 0x8000 SUB | |
24624 | 0x00F0 Rd | |
24625 | 0x000F Rs | |
24626 | */ | |
24627 | /* The following conditions must be true : | |
24628 | - ADD | |
24629 | - Rd == Rs | |
24630 | - Rd <= 7 | |
24631 | */ | |
24632 | rd = (insn >> 4) & 0xf; | |
24633 | rs = insn & 0xf; | |
24634 | if ((insn & 0x8000) || (rd != rs) || rd > 7) | |
24635 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24636 | _("Unable to process relocation for thumb opcode: %lx"), | |
24637 | (unsigned long) insn); | |
24638 | ||
24639 | /* Encode as ADD immediate8 thumb 1 code. */ | |
24640 | insn = 0x3000 | (rd << 8); | |
24641 | ||
24642 | /* Place the encoded addend into the first 8 bits of the | |
24643 | instruction. */ | |
24644 | if (!seg->use_rela_p) | |
24645 | insn |= encoded_addend; | |
24646 | } | |
24647 | ||
24648 | /* Update the instruction. */ | |
24649 | md_number_to_chars (buf, insn, THUMB_SIZE); | |
24650 | } | |
24651 | break; | |
24652 | ||
4962c51a MS |
24653 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
24654 | case BFD_RELOC_ARM_ALU_PC_G0: | |
24655 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
24656 | case BFD_RELOC_ARM_ALU_PC_G1: | |
24657 | case BFD_RELOC_ARM_ALU_PC_G2: | |
24658 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
24659 | case BFD_RELOC_ARM_ALU_SB_G0: | |
24660 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
24661 | case BFD_RELOC_ARM_ALU_SB_G1: | |
24662 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 24663 | gas_assert (!fixP->fx_done); |
4962c51a MS |
24664 | if (!seg->use_rela_p) |
24665 | { | |
477330fc RM |
24666 | bfd_vma insn; |
24667 | bfd_vma encoded_addend; | |
3ca4a8ec | 24668 | bfd_vma addend_abs = llabs (value); |
477330fc RM |
24669 | |
24670 | /* Check that the absolute value of the addend can be | |
24671 | expressed as an 8-bit constant plus a rotation. */ | |
24672 | encoded_addend = encode_arm_immediate (addend_abs); | |
24673 | if (encoded_addend == (unsigned int) FAIL) | |
4962c51a | 24674 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
24675 | _("the offset 0x%08lX is not representable"), |
24676 | (unsigned long) addend_abs); | |
24677 | ||
24678 | /* Extract the instruction. */ | |
24679 | insn = md_chars_to_number (buf, INSN_SIZE); | |
24680 | ||
24681 | /* If the addend is positive, use an ADD instruction. | |
24682 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
24683 | insn &= 0xff1fffff; | |
24684 | if (value < 0) | |
24685 | insn |= 1 << 22; | |
24686 | else | |
24687 | insn |= 1 << 23; | |
24688 | ||
24689 | /* Place the encoded addend into the first 12 bits of the | |
24690 | instruction. */ | |
24691 | insn &= 0xfffff000; | |
24692 | insn |= encoded_addend; | |
24693 | ||
24694 | /* Update the instruction. */ | |
24695 | md_number_to_chars (buf, insn, INSN_SIZE); | |
4962c51a MS |
24696 | } |
24697 | break; | |
24698 | ||
24699 | case BFD_RELOC_ARM_LDR_PC_G0: | |
24700 | case BFD_RELOC_ARM_LDR_PC_G1: | |
24701 | case BFD_RELOC_ARM_LDR_PC_G2: | |
24702 | case BFD_RELOC_ARM_LDR_SB_G0: | |
24703 | case BFD_RELOC_ARM_LDR_SB_G1: | |
24704 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 24705 | gas_assert (!fixP->fx_done); |
4962c51a | 24706 | if (!seg->use_rela_p) |
477330fc RM |
24707 | { |
24708 | bfd_vma insn; | |
3ca4a8ec | 24709 | bfd_vma addend_abs = llabs (value); |
4962c51a | 24710 | |
477330fc RM |
24711 | /* Check that the absolute value of the addend can be |
24712 | encoded in 12 bits. */ | |
24713 | if (addend_abs >= 0x1000) | |
4962c51a | 24714 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
24715 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), |
24716 | (unsigned long) addend_abs); | |
24717 | ||
24718 | /* Extract the instruction. */ | |
24719 | insn = md_chars_to_number (buf, INSN_SIZE); | |
24720 | ||
24721 | /* If the addend is negative, clear bit 23 of the instruction. | |
24722 | Otherwise set it. */ | |
24723 | if (value < 0) | |
24724 | insn &= ~(1 << 23); | |
24725 | else | |
24726 | insn |= 1 << 23; | |
24727 | ||
24728 | /* Place the absolute value of the addend into the first 12 bits | |
24729 | of the instruction. */ | |
24730 | insn &= 0xfffff000; | |
24731 | insn |= addend_abs; | |
24732 | ||
24733 | /* Update the instruction. */ | |
24734 | md_number_to_chars (buf, insn, INSN_SIZE); | |
24735 | } | |
4962c51a MS |
24736 | break; |
24737 | ||
24738 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
24739 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
24740 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
24741 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
24742 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
24743 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 24744 | gas_assert (!fixP->fx_done); |
4962c51a | 24745 | if (!seg->use_rela_p) |
477330fc RM |
24746 | { |
24747 | bfd_vma insn; | |
3ca4a8ec | 24748 | bfd_vma addend_abs = llabs (value); |
4962c51a | 24749 | |
477330fc RM |
24750 | /* Check that the absolute value of the addend can be |
24751 | encoded in 8 bits. */ | |
24752 | if (addend_abs >= 0x100) | |
4962c51a | 24753 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
24754 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), |
24755 | (unsigned long) addend_abs); | |
24756 | ||
24757 | /* Extract the instruction. */ | |
24758 | insn = md_chars_to_number (buf, INSN_SIZE); | |
24759 | ||
24760 | /* If the addend is negative, clear bit 23 of the instruction. | |
24761 | Otherwise set it. */ | |
24762 | if (value < 0) | |
24763 | insn &= ~(1 << 23); | |
24764 | else | |
24765 | insn |= 1 << 23; | |
24766 | ||
24767 | /* Place the first four bits of the absolute value of the addend | |
24768 | into the first 4 bits of the instruction, and the remaining | |
24769 | four into bits 8 .. 11. */ | |
24770 | insn &= 0xfffff0f0; | |
24771 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
24772 | ||
24773 | /* Update the instruction. */ | |
24774 | md_number_to_chars (buf, insn, INSN_SIZE); | |
24775 | } | |
4962c51a MS |
24776 | break; |
24777 | ||
24778 | case BFD_RELOC_ARM_LDC_PC_G0: | |
24779 | case BFD_RELOC_ARM_LDC_PC_G1: | |
24780 | case BFD_RELOC_ARM_LDC_PC_G2: | |
24781 | case BFD_RELOC_ARM_LDC_SB_G0: | |
24782 | case BFD_RELOC_ARM_LDC_SB_G1: | |
24783 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 24784 | gas_assert (!fixP->fx_done); |
4962c51a | 24785 | if (!seg->use_rela_p) |
477330fc RM |
24786 | { |
24787 | bfd_vma insn; | |
3ca4a8ec | 24788 | bfd_vma addend_abs = llabs (value); |
4962c51a | 24789 | |
477330fc RM |
24790 | /* Check that the absolute value of the addend is a multiple of |
24791 | four and, when divided by four, fits in 8 bits. */ | |
24792 | if (addend_abs & 0x3) | |
4962c51a | 24793 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
24794 | _("bad offset 0x%08lX (must be word-aligned)"), |
24795 | (unsigned long) addend_abs); | |
4962c51a | 24796 | |
477330fc | 24797 | if ((addend_abs >> 2) > 0xff) |
4962c51a | 24798 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
24799 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), |
24800 | (unsigned long) addend_abs); | |
24801 | ||
24802 | /* Extract the instruction. */ | |
24803 | insn = md_chars_to_number (buf, INSN_SIZE); | |
24804 | ||
24805 | /* If the addend is negative, clear bit 23 of the instruction. | |
24806 | Otherwise set it. */ | |
24807 | if (value < 0) | |
24808 | insn &= ~(1 << 23); | |
24809 | else | |
24810 | insn |= 1 << 23; | |
24811 | ||
24812 | /* Place the addend (divided by four) into the first eight | |
24813 | bits of the instruction. */ | |
24814 | insn &= 0xfffffff0; | |
24815 | insn |= addend_abs >> 2; | |
24816 | ||
24817 | /* Update the instruction. */ | |
24818 | md_number_to_chars (buf, insn, INSN_SIZE); | |
24819 | } | |
4962c51a MS |
24820 | break; |
24821 | ||
e12437dc AV |
24822 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
24823 | if (fixP->fx_addsy | |
24824 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
24825 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
24826 | && ARM_IS_FUNC (fixP->fx_addsy) | |
24827 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
24828 | { | |
24829 | /* Force a relocation for a branch 5 bits wide. */ | |
24830 | fixP->fx_done = 0; | |
24831 | } | |
24832 | if (v8_1_branch_value_check (value, 5, FALSE) == FAIL) | |
24833 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24834 | BAD_BRANCH_OFF); | |
24835 | ||
24836 | if (fixP->fx_done || !seg->use_rela_p) | |
24837 | { | |
24838 | addressT boff = value >> 1; | |
24839 | ||
24840 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24841 | newval |= (boff << 7); | |
24842 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24843 | } | |
24844 | break; | |
24845 | ||
e5d6e09e AV |
24846 | case BFD_RELOC_ARM_THUMB_BF17: |
24847 | if (fixP->fx_addsy | |
24848 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
24849 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
24850 | && ARM_IS_FUNC (fixP->fx_addsy) | |
24851 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
24852 | { | |
24853 | /* Force a relocation for a branch 17 bits wide. */ | |
24854 | fixP->fx_done = 0; | |
24855 | } | |
24856 | ||
24857 | if (v8_1_branch_value_check (value, 17, TRUE) == FAIL) | |
24858 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24859 | BAD_BRANCH_OFF); | |
24860 | ||
24861 | if (fixP->fx_done || !seg->use_rela_p) | |
24862 | { | |
24863 | offsetT newval2; | |
24864 | addressT immA, immB, immC; | |
24865 | ||
24866 | immA = (value & 0x0001f000) >> 12; | |
24867 | immB = (value & 0x00000ffc) >> 2; | |
24868 | immC = (value & 0x00000002) >> 1; | |
24869 | ||
24870 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24871 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24872 | newval |= immA; | |
24873 | newval2 |= (immC << 11) | (immB << 1); | |
24874 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24875 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
24876 | } | |
24877 | break; | |
24878 | ||
1caf72a5 AV |
24879 | case BFD_RELOC_ARM_THUMB_BF19: |
24880 | if (fixP->fx_addsy | |
24881 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
24882 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) | |
24883 | && ARM_IS_FUNC (fixP->fx_addsy) | |
24884 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main)) | |
24885 | { | |
24886 | /* Force a relocation for a branch 19 bits wide. */ | |
24887 | fixP->fx_done = 0; | |
24888 | } | |
24889 | ||
24890 | if (v8_1_branch_value_check (value, 19, TRUE) == FAIL) | |
24891 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24892 | BAD_BRANCH_OFF); | |
24893 | ||
24894 | if (fixP->fx_done || !seg->use_rela_p) | |
24895 | { | |
24896 | offsetT newval2; | |
24897 | addressT immA, immB, immC; | |
24898 | ||
24899 | immA = (value & 0x0007f000) >> 12; | |
24900 | immB = (value & 0x00000ffc) >> 2; | |
24901 | immC = (value & 0x00000002) >> 1; | |
24902 | ||
24903 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
24904 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
24905 | newval |= immA; | |
24906 | newval2 |= (immC << 11) | (immB << 1); | |
24907 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
24908 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
24909 | } | |
24910 | break; | |
24911 | ||
845b51d6 PB |
24912 | case BFD_RELOC_ARM_V4BX: |
24913 | /* This will need to go in the object file. */ | |
24914 | fixP->fx_done = 0; | |
24915 | break; | |
24916 | ||
c19d1205 ZW |
24917 | case BFD_RELOC_UNUSED: |
24918 | default: | |
24919 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24920 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
24921 | } | |
6c43fab6 RE |
24922 | } |
24923 | ||
c19d1205 ZW |
24924 | /* Translate internal representation of relocation info to BFD target |
24925 | format. */ | |
a737bd4d | 24926 | |
c19d1205 | 24927 | arelent * |
00a97672 | 24928 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 24929 | { |
c19d1205 ZW |
24930 | arelent * reloc; |
24931 | bfd_reloc_code_real_type code; | |
a737bd4d | 24932 | |
325801bd | 24933 | reloc = XNEW (arelent); |
a737bd4d | 24934 | |
325801bd | 24935 | reloc->sym_ptr_ptr = XNEW (asymbol *); |
c19d1205 ZW |
24936 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
24937 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 24938 | |
2fc8bdac | 24939 | if (fixp->fx_pcrel) |
00a97672 RS |
24940 | { |
24941 | if (section->use_rela_p) | |
24942 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
24943 | else | |
24944 | fixp->fx_offset = reloc->address; | |
24945 | } | |
c19d1205 | 24946 | reloc->addend = fixp->fx_offset; |
a737bd4d | 24947 | |
c19d1205 | 24948 | switch (fixp->fx_r_type) |
a737bd4d | 24949 | { |
c19d1205 ZW |
24950 | case BFD_RELOC_8: |
24951 | if (fixp->fx_pcrel) | |
24952 | { | |
24953 | code = BFD_RELOC_8_PCREL; | |
24954 | break; | |
24955 | } | |
1a0670f3 | 24956 | /* Fall through. */ |
a737bd4d | 24957 | |
c19d1205 ZW |
24958 | case BFD_RELOC_16: |
24959 | if (fixp->fx_pcrel) | |
24960 | { | |
24961 | code = BFD_RELOC_16_PCREL; | |
24962 | break; | |
24963 | } | |
1a0670f3 | 24964 | /* Fall through. */ |
6c43fab6 | 24965 | |
c19d1205 ZW |
24966 | case BFD_RELOC_32: |
24967 | if (fixp->fx_pcrel) | |
24968 | { | |
24969 | code = BFD_RELOC_32_PCREL; | |
24970 | break; | |
24971 | } | |
1a0670f3 | 24972 | /* Fall through. */ |
a737bd4d | 24973 | |
b6895b4f PB |
24974 | case BFD_RELOC_ARM_MOVW: |
24975 | if (fixp->fx_pcrel) | |
24976 | { | |
24977 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
24978 | break; | |
24979 | } | |
1a0670f3 | 24980 | /* Fall through. */ |
b6895b4f PB |
24981 | |
24982 | case BFD_RELOC_ARM_MOVT: | |
24983 | if (fixp->fx_pcrel) | |
24984 | { | |
24985 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
24986 | break; | |
24987 | } | |
1a0670f3 | 24988 | /* Fall through. */ |
b6895b4f PB |
24989 | |
24990 | case BFD_RELOC_ARM_THUMB_MOVW: | |
24991 | if (fixp->fx_pcrel) | |
24992 | { | |
24993 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
24994 | break; | |
24995 | } | |
1a0670f3 | 24996 | /* Fall through. */ |
b6895b4f PB |
24997 | |
24998 | case BFD_RELOC_ARM_THUMB_MOVT: | |
24999 | if (fixp->fx_pcrel) | |
25000 | { | |
25001 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
25002 | break; | |
25003 | } | |
1a0670f3 | 25004 | /* Fall through. */ |
b6895b4f | 25005 | |
c19d1205 ZW |
25006 | case BFD_RELOC_NONE: |
25007 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
25008 | case BFD_RELOC_ARM_PCREL_BLX: | |
25009 | case BFD_RELOC_RVA: | |
25010 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
25011 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
25012 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
25013 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
25014 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
25015 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
25016 | case BFD_RELOC_VTABLE_ENTRY: |
25017 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
25018 | #ifdef TE_PE |
25019 | case BFD_RELOC_32_SECREL: | |
25020 | #endif | |
c19d1205 ZW |
25021 | code = fixp->fx_r_type; |
25022 | break; | |
a737bd4d | 25023 | |
00adf2d4 JB |
25024 | case BFD_RELOC_THUMB_PCREL_BLX: |
25025 | #ifdef OBJ_ELF | |
25026 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
25027 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
25028 | else | |
25029 | #endif | |
25030 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
25031 | break; | |
25032 | ||
c19d1205 ZW |
25033 | case BFD_RELOC_ARM_LITERAL: |
25034 | case BFD_RELOC_ARM_HWLITERAL: | |
25035 | /* If this is called then the a literal has | |
25036 | been referenced across a section boundary. */ | |
25037 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25038 | _("literal referenced across section boundary")); | |
25039 | return NULL; | |
a737bd4d | 25040 | |
c19d1205 | 25041 | #ifdef OBJ_ELF |
0855e32b NS |
25042 | case BFD_RELOC_ARM_TLS_CALL: |
25043 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
25044 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
25045 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
c19d1205 ZW |
25046 | case BFD_RELOC_ARM_GOT32: |
25047 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 25048 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
25049 | case BFD_RELOC_ARM_PLT32: |
25050 | case BFD_RELOC_ARM_TARGET1: | |
25051 | case BFD_RELOC_ARM_ROSEGREL32: | |
25052 | case BFD_RELOC_ARM_SBREL32: | |
25053 | case BFD_RELOC_ARM_PREL31: | |
25054 | case BFD_RELOC_ARM_TARGET2: | |
c19d1205 | 25055 | case BFD_RELOC_ARM_TLS_LDO32: |
39b41c9c PB |
25056 | case BFD_RELOC_ARM_PCREL_CALL: |
25057 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
25058 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
25059 | case BFD_RELOC_ARM_ALU_PC_G0: | |
25060 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
25061 | case BFD_RELOC_ARM_ALU_PC_G1: | |
25062 | case BFD_RELOC_ARM_ALU_PC_G2: | |
25063 | case BFD_RELOC_ARM_LDR_PC_G0: | |
25064 | case BFD_RELOC_ARM_LDR_PC_G1: | |
25065 | case BFD_RELOC_ARM_LDR_PC_G2: | |
25066 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
25067 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
25068 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
25069 | case BFD_RELOC_ARM_LDC_PC_G0: | |
25070 | case BFD_RELOC_ARM_LDC_PC_G1: | |
25071 | case BFD_RELOC_ARM_LDC_PC_G2: | |
25072 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
25073 | case BFD_RELOC_ARM_ALU_SB_G0: | |
25074 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
25075 | case BFD_RELOC_ARM_ALU_SB_G1: | |
25076 | case BFD_RELOC_ARM_ALU_SB_G2: | |
25077 | case BFD_RELOC_ARM_LDR_SB_G0: | |
25078 | case BFD_RELOC_ARM_LDR_SB_G1: | |
25079 | case BFD_RELOC_ARM_LDR_SB_G2: | |
25080 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
25081 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
25082 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
25083 | case BFD_RELOC_ARM_LDC_SB_G0: | |
25084 | case BFD_RELOC_ARM_LDC_SB_G1: | |
25085 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 25086 | case BFD_RELOC_ARM_V4BX: |
72d98d16 MG |
25087 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
25088 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
25089 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
25090 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
188fd7ae CL |
25091 | case BFD_RELOC_ARM_GOTFUNCDESC: |
25092 | case BFD_RELOC_ARM_GOTOFFFUNCDESC: | |
25093 | case BFD_RELOC_ARM_FUNCDESC: | |
e5d6e09e | 25094 | case BFD_RELOC_ARM_THUMB_BF17: |
1caf72a5 | 25095 | case BFD_RELOC_ARM_THUMB_BF19: |
c19d1205 ZW |
25096 | code = fixp->fx_r_type; |
25097 | break; | |
a737bd4d | 25098 | |
0855e32b | 25099 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 | 25100 | case BFD_RELOC_ARM_TLS_GD32: |
5c5a4843 | 25101 | case BFD_RELOC_ARM_TLS_GD32_FDPIC: |
75c11999 | 25102 | case BFD_RELOC_ARM_TLS_LE32: |
c19d1205 | 25103 | case BFD_RELOC_ARM_TLS_IE32: |
5c5a4843 | 25104 | case BFD_RELOC_ARM_TLS_IE32_FDPIC: |
c19d1205 | 25105 | case BFD_RELOC_ARM_TLS_LDM32: |
5c5a4843 | 25106 | case BFD_RELOC_ARM_TLS_LDM32_FDPIC: |
c19d1205 ZW |
25107 | /* BFD will include the symbol's address in the addend. |
25108 | But we don't want that, so subtract it out again here. */ | |
25109 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
25110 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
25111 | code = fixp->fx_r_type; | |
25112 | break; | |
25113 | #endif | |
a737bd4d | 25114 | |
c19d1205 ZW |
25115 | case BFD_RELOC_ARM_IMMEDIATE: |
25116 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25117 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
25118 | return NULL; | |
a737bd4d | 25119 | |
c19d1205 ZW |
25120 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
25121 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25122 | _("ADRL used for a symbol not defined in the same file")); | |
25123 | return NULL; | |
a737bd4d | 25124 | |
e12437dc AV |
25125 | case BFD_RELOC_THUMB_PCREL_BRANCH5: |
25126 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25127 | _("%s used for a symbol not defined in the same file"), | |
25128 | bfd_get_reloc_code_name (fixp->fx_r_type)); | |
25129 | return NULL; | |
25130 | ||
c19d1205 | 25131 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
25132 | if (section->use_rela_p) |
25133 | { | |
25134 | code = fixp->fx_r_type; | |
25135 | break; | |
25136 | } | |
25137 | ||
c19d1205 ZW |
25138 | if (fixp->fx_addsy != NULL |
25139 | && !S_IS_DEFINED (fixp->fx_addsy) | |
25140 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 25141 | { |
c19d1205 ZW |
25142 | as_bad_where (fixp->fx_file, fixp->fx_line, |
25143 | _("undefined local label `%s'"), | |
25144 | S_GET_NAME (fixp->fx_addsy)); | |
25145 | return NULL; | |
a737bd4d NC |
25146 | } |
25147 | ||
c19d1205 ZW |
25148 | as_bad_where (fixp->fx_file, fixp->fx_line, |
25149 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
25150 | return NULL; | |
a737bd4d | 25151 | |
c19d1205 ZW |
25152 | default: |
25153 | { | |
e0471c16 | 25154 | const char * type; |
6c43fab6 | 25155 | |
c19d1205 ZW |
25156 | switch (fixp->fx_r_type) |
25157 | { | |
25158 | case BFD_RELOC_NONE: type = "NONE"; break; | |
25159 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
25160 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 25161 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
25162 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
25163 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
25164 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 25165 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 25166 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
25167 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
25168 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
25169 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
25170 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
25171 | default: type = _("<unknown>"); break; | |
25172 | } | |
25173 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25174 | _("cannot represent %s relocation in this object file format"), | |
25175 | type); | |
25176 | return NULL; | |
25177 | } | |
a737bd4d | 25178 | } |
6c43fab6 | 25179 | |
c19d1205 ZW |
25180 | #ifdef OBJ_ELF |
25181 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
25182 | && GOT_symbol | |
25183 | && fixp->fx_addsy == GOT_symbol) | |
25184 | { | |
25185 | code = BFD_RELOC_ARM_GOTPC; | |
25186 | reloc->addend = fixp->fx_offset = reloc->address; | |
25187 | } | |
25188 | #endif | |
6c43fab6 | 25189 | |
c19d1205 | 25190 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 25191 | |
c19d1205 ZW |
25192 | if (reloc->howto == NULL) |
25193 | { | |
25194 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
25195 | _("cannot represent %s relocation in this object file format"), | |
25196 | bfd_get_reloc_code_name (code)); | |
25197 | return NULL; | |
25198 | } | |
6c43fab6 | 25199 | |
c19d1205 ZW |
25200 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
25201 | vtable entry to be used in the relocation's section offset. */ | |
25202 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
25203 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 25204 | |
c19d1205 | 25205 | return reloc; |
6c43fab6 RE |
25206 | } |
25207 | ||
c19d1205 | 25208 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 25209 | |
c19d1205 ZW |
25210 | void |
25211 | cons_fix_new_arm (fragS * frag, | |
25212 | int where, | |
25213 | int size, | |
62ebcb5c AM |
25214 | expressionS * exp, |
25215 | bfd_reloc_code_real_type reloc) | |
6c43fab6 | 25216 | { |
c19d1205 | 25217 | int pcrel = 0; |
6c43fab6 | 25218 | |
c19d1205 ZW |
25219 | /* Pick a reloc. |
25220 | FIXME: @@ Should look at CPU word size. */ | |
25221 | switch (size) | |
25222 | { | |
25223 | case 1: | |
62ebcb5c | 25224 | reloc = BFD_RELOC_8; |
c19d1205 ZW |
25225 | break; |
25226 | case 2: | |
62ebcb5c | 25227 | reloc = BFD_RELOC_16; |
c19d1205 ZW |
25228 | break; |
25229 | case 4: | |
25230 | default: | |
62ebcb5c | 25231 | reloc = BFD_RELOC_32; |
c19d1205 ZW |
25232 | break; |
25233 | case 8: | |
62ebcb5c | 25234 | reloc = BFD_RELOC_64; |
c19d1205 ZW |
25235 | break; |
25236 | } | |
6c43fab6 | 25237 | |
f0927246 NC |
25238 | #ifdef TE_PE |
25239 | if (exp->X_op == O_secrel) | |
25240 | { | |
25241 | exp->X_op = O_symbol; | |
62ebcb5c | 25242 | reloc = BFD_RELOC_32_SECREL; |
f0927246 NC |
25243 | } |
25244 | #endif | |
25245 | ||
62ebcb5c | 25246 | fix_new_exp (frag, where, size, exp, pcrel, reloc); |
c19d1205 | 25247 | } |
6c43fab6 | 25248 | |
4343666d | 25249 | #if defined (OBJ_COFF) |
c19d1205 ZW |
25250 | void |
25251 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 25252 | { |
c19d1205 ZW |
25253 | /* If the destination of the branch is a defined symbol which does not have |
25254 | the THUMB_FUNC attribute, then we must be calling a function which has | |
25255 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
25256 | function and change the branch to refer to that function instead. */ | |
25257 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
25258 | && fixP->fx_addsy != NULL | |
25259 | && S_IS_DEFINED (fixP->fx_addsy) | |
25260 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 25261 | { |
c19d1205 | 25262 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 25263 | } |
c19d1205 ZW |
25264 | } |
25265 | #endif | |
6c43fab6 | 25266 | |
267bf995 | 25267 | |
c19d1205 ZW |
25268 | int |
25269 | arm_force_relocation (struct fix * fixp) | |
25270 | { | |
25271 | #if defined (OBJ_COFF) && defined (TE_PE) | |
25272 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
25273 | return 1; | |
25274 | #endif | |
6c43fab6 | 25275 | |
267bf995 RR |
25276 | /* In case we have a call or a branch to a function in ARM ISA mode from |
25277 | a thumb function or vice-versa force the relocation. These relocations | |
25278 | are cleared off for some cores that might have blx and simple transformations | |
25279 | are possible. */ | |
25280 | ||
25281 | #ifdef OBJ_ELF | |
25282 | switch (fixp->fx_r_type) | |
25283 | { | |
25284 | case BFD_RELOC_ARM_PCREL_JUMP: | |
25285 | case BFD_RELOC_ARM_PCREL_CALL: | |
25286 | case BFD_RELOC_THUMB_PCREL_BLX: | |
25287 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
25288 | return 1; | |
25289 | break; | |
25290 | ||
25291 | case BFD_RELOC_ARM_PCREL_BLX: | |
25292 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
25293 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
25294 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
25295 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
25296 | return 1; | |
25297 | break; | |
25298 | ||
25299 | default: | |
25300 | break; | |
25301 | } | |
25302 | #endif | |
25303 | ||
b5884301 PB |
25304 | /* Resolve these relocations even if the symbol is extern or weak. |
25305 | Technically this is probably wrong due to symbol preemption. | |
25306 | In practice these relocations do not have enough range to be useful | |
25307 | at dynamic link time, and some code (e.g. in the Linux kernel) | |
25308 | expects these references to be resolved. */ | |
c19d1205 ZW |
25309 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
25310 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 25311 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 25312 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
25313 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
25314 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2 | |
25315 | || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET | |
16805f35 | 25316 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
25317 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
25318 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
25319 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM |
25320 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12 | |
25321 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM | |
25322 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2) | |
c19d1205 | 25323 | return 0; |
a737bd4d | 25324 | |
4962c51a MS |
25325 | /* Always leave these relocations for the linker. */ |
25326 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
25327 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
25328 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
25329 | return 1; | |
25330 | ||
f0291e4c PB |
25331 | /* Always generate relocations against function symbols. */ |
25332 | if (fixp->fx_r_type == BFD_RELOC_32 | |
25333 | && fixp->fx_addsy | |
25334 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
25335 | return 1; | |
25336 | ||
c19d1205 | 25337 | return generic_force_reloc (fixp); |
404ff6b5 AH |
25338 | } |
25339 | ||
0ffdc86c | 25340 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
25341 | /* Relocations against function names must be left unadjusted, |
25342 | so that the linker can use this information to generate interworking | |
25343 | stubs. The MIPS version of this function | |
c19d1205 ZW |
25344 | also prevents relocations that are mips-16 specific, but I do not |
25345 | know why it does this. | |
404ff6b5 | 25346 | |
c19d1205 ZW |
25347 | FIXME: |
25348 | There is one other problem that ought to be addressed here, but | |
25349 | which currently is not: Taking the address of a label (rather | |
25350 | than a function) and then later jumping to that address. Such | |
25351 | addresses also ought to have their bottom bit set (assuming that | |
25352 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 25353 | |
c19d1205 ZW |
25354 | bfd_boolean |
25355 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 25356 | { |
c19d1205 ZW |
25357 | if (fixP->fx_addsy == NULL) |
25358 | return 1; | |
404ff6b5 | 25359 | |
e28387c3 PB |
25360 | /* Preserve relocations against symbols with function type. */ |
25361 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 25362 | return FALSE; |
e28387c3 | 25363 | |
c19d1205 ZW |
25364 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
25365 | && fixP->fx_subsy == NULL) | |
c921be7d | 25366 | return FALSE; |
a737bd4d | 25367 | |
c19d1205 ZW |
25368 | /* We need the symbol name for the VTABLE entries. */ |
25369 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
25370 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 25371 | return FALSE; |
404ff6b5 | 25372 | |
c19d1205 ZW |
25373 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
25374 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
25375 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
25376 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
25377 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
5c5a4843 | 25378 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC |
c19d1205 ZW |
25379 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 |
25380 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
5c5a4843 | 25381 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC |
c19d1205 | 25382 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 |
5c5a4843 | 25383 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC |
c19d1205 | 25384 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 |
0855e32b NS |
25385 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC |
25386 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL | |
25387 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL | |
25388 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ | |
25389 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
c19d1205 | 25390 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
c921be7d | 25391 | return FALSE; |
a737bd4d | 25392 | |
4962c51a MS |
25393 | /* Similarly for group relocations. */ |
25394 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
25395 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
25396 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 25397 | return FALSE; |
4962c51a | 25398 | |
79947c54 CD |
25399 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
25400 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
25401 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
25402 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
25403 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
25404 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
25405 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
25406 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
25407 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 25408 | return FALSE; |
79947c54 | 25409 | |
72d98d16 MG |
25410 | /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited |
25411 | offsets, so keep these symbols. */ | |
25412 | if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC | |
25413 | && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
25414 | return FALSE; | |
25415 | ||
c921be7d | 25416 | return TRUE; |
a737bd4d | 25417 | } |
0ffdc86c NC |
25418 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
25419 | ||
25420 | #ifdef OBJ_ELF | |
c19d1205 ZW |
25421 | const char * |
25422 | elf32_arm_target_format (void) | |
404ff6b5 | 25423 | { |
c19d1205 ZW |
25424 | #ifdef TE_SYMBIAN |
25425 | return (target_big_endian | |
25426 | ? "elf32-bigarm-symbian" | |
25427 | : "elf32-littlearm-symbian"); | |
25428 | #elif defined (TE_VXWORKS) | |
25429 | return (target_big_endian | |
25430 | ? "elf32-bigarm-vxworks" | |
25431 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
25432 | #elif defined (TE_NACL) |
25433 | return (target_big_endian | |
25434 | ? "elf32-bigarm-nacl" | |
25435 | : "elf32-littlearm-nacl"); | |
c19d1205 | 25436 | #else |
18a20338 CL |
25437 | if (arm_fdpic) |
25438 | { | |
25439 | if (target_big_endian) | |
25440 | return "elf32-bigarm-fdpic"; | |
25441 | else | |
25442 | return "elf32-littlearm-fdpic"; | |
25443 | } | |
c19d1205 | 25444 | else |
18a20338 CL |
25445 | { |
25446 | if (target_big_endian) | |
25447 | return "elf32-bigarm"; | |
25448 | else | |
25449 | return "elf32-littlearm"; | |
25450 | } | |
c19d1205 | 25451 | #endif |
404ff6b5 AH |
25452 | } |
25453 | ||
c19d1205 ZW |
25454 | void |
25455 | armelf_frob_symbol (symbolS * symp, | |
25456 | int * puntp) | |
404ff6b5 | 25457 | { |
c19d1205 ZW |
25458 | elf_frob_symbol (symp, puntp); |
25459 | } | |
25460 | #endif | |
404ff6b5 | 25461 | |
c19d1205 | 25462 | /* MD interface: Finalization. */ |
a737bd4d | 25463 | |
c19d1205 ZW |
25464 | void |
25465 | arm_cleanup (void) | |
25466 | { | |
25467 | literal_pool * pool; | |
a737bd4d | 25468 | |
e07e6e58 NC |
25469 | /* Ensure that all the IT blocks are properly closed. */ |
25470 | check_it_blocks_finished (); | |
25471 | ||
c19d1205 ZW |
25472 | for (pool = list_of_pools; pool; pool = pool->next) |
25473 | { | |
5f4273c7 | 25474 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
25475 | subseg_set (pool->section, pool->sub_section); |
25476 | #ifdef OBJ_ELF | |
25477 | arm_elf_change_section (); | |
25478 | #endif | |
25479 | s_ltorg (0); | |
25480 | } | |
404ff6b5 AH |
25481 | } |
25482 | ||
cd000bff DJ |
25483 | #ifdef OBJ_ELF |
25484 | /* Remove any excess mapping symbols generated for alignment frags in | |
25485 | SEC. We may have created a mapping symbol before a zero byte | |
25486 | alignment; remove it if there's a mapping symbol after the | |
25487 | alignment. */ | |
25488 | static void | |
25489 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
25490 | void *dummy ATTRIBUTE_UNUSED) | |
25491 | { | |
25492 | segment_info_type *seginfo = seg_info (sec); | |
25493 | fragS *fragp; | |
25494 | ||
25495 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
25496 | return; | |
25497 | ||
25498 | for (fragp = seginfo->frchainP->frch_root; | |
25499 | fragp != NULL; | |
25500 | fragp = fragp->fr_next) | |
25501 | { | |
25502 | symbolS *sym = fragp->tc_frag_data.last_map; | |
25503 | fragS *next = fragp->fr_next; | |
25504 | ||
25505 | /* Variable-sized frags have been converted to fixed size by | |
25506 | this point. But if this was variable-sized to start with, | |
25507 | there will be a fixed-size frag after it. So don't handle | |
25508 | next == NULL. */ | |
25509 | if (sym == NULL || next == NULL) | |
25510 | continue; | |
25511 | ||
25512 | if (S_GET_VALUE (sym) < next->fr_address) | |
25513 | /* Not at the end of this frag. */ | |
25514 | continue; | |
25515 | know (S_GET_VALUE (sym) == next->fr_address); | |
25516 | ||
25517 | do | |
25518 | { | |
25519 | if (next->tc_frag_data.first_map != NULL) | |
25520 | { | |
25521 | /* Next frag starts with a mapping symbol. Discard this | |
25522 | one. */ | |
25523 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
25524 | break; | |
25525 | } | |
25526 | ||
25527 | if (next->fr_next == NULL) | |
25528 | { | |
25529 | /* This mapping symbol is at the end of the section. Discard | |
25530 | it. */ | |
25531 | know (next->fr_fix == 0 && next->fr_var == 0); | |
25532 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
25533 | break; | |
25534 | } | |
25535 | ||
25536 | /* As long as we have empty frags without any mapping symbols, | |
25537 | keep looking. */ | |
25538 | /* If the next frag is non-empty and does not start with a | |
25539 | mapping symbol, then this mapping symbol is required. */ | |
25540 | if (next->fr_address != next->fr_next->fr_address) | |
25541 | break; | |
25542 | ||
25543 | next = next->fr_next; | |
25544 | } | |
25545 | while (next != NULL); | |
25546 | } | |
25547 | } | |
25548 | #endif | |
25549 | ||
c19d1205 ZW |
25550 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
25551 | ARM ones. */ | |
404ff6b5 | 25552 | |
c19d1205 ZW |
25553 | void |
25554 | arm_adjust_symtab (void) | |
404ff6b5 | 25555 | { |
c19d1205 ZW |
25556 | #ifdef OBJ_COFF |
25557 | symbolS * sym; | |
404ff6b5 | 25558 | |
c19d1205 ZW |
25559 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
25560 | { | |
25561 | if (ARM_IS_THUMB (sym)) | |
25562 | { | |
25563 | if (THUMB_IS_FUNC (sym)) | |
25564 | { | |
25565 | /* Mark the symbol as a Thumb function. */ | |
25566 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
25567 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
25568 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 25569 | |
c19d1205 ZW |
25570 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
25571 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
25572 | else | |
25573 | as_bad (_("%s: unexpected function type: %d"), | |
25574 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
25575 | } | |
25576 | else switch (S_GET_STORAGE_CLASS (sym)) | |
25577 | { | |
25578 | case C_EXT: | |
25579 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
25580 | break; | |
25581 | case C_STAT: | |
25582 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
25583 | break; | |
25584 | case C_LABEL: | |
25585 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
25586 | break; | |
25587 | default: | |
25588 | /* Do nothing. */ | |
25589 | break; | |
25590 | } | |
25591 | } | |
a737bd4d | 25592 | |
c19d1205 ZW |
25593 | if (ARM_IS_INTERWORK (sym)) |
25594 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 25595 | } |
c19d1205 ZW |
25596 | #endif |
25597 | #ifdef OBJ_ELF | |
25598 | symbolS * sym; | |
25599 | char bind; | |
404ff6b5 | 25600 | |
c19d1205 | 25601 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 25602 | { |
c19d1205 ZW |
25603 | if (ARM_IS_THUMB (sym)) |
25604 | { | |
25605 | elf_symbol_type * elf_sym; | |
404ff6b5 | 25606 | |
c19d1205 ZW |
25607 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
25608 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 25609 | |
b0796911 PB |
25610 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
25611 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
25612 | { |
25613 | /* If it's a .thumb_func, declare it as so, | |
25614 | otherwise tag label as .code 16. */ | |
25615 | if (THUMB_IS_FUNC (sym)) | |
39d911fc TP |
25616 | ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal, |
25617 | ST_BRANCH_TO_THUMB); | |
3ba67470 | 25618 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
25619 | elf_sym->internal_elf_sym.st_info = |
25620 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
25621 | } | |
25622 | } | |
25623 | } | |
cd000bff DJ |
25624 | |
25625 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
25626 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
25627 | /* Now do generic ELF adjustments. */ |
25628 | elf_adjust_symtab (); | |
c19d1205 | 25629 | #endif |
404ff6b5 AH |
25630 | } |
25631 | ||
c19d1205 | 25632 | /* MD interface: Initialization. */ |
404ff6b5 | 25633 | |
a737bd4d | 25634 | static void |
c19d1205 | 25635 | set_constant_flonums (void) |
a737bd4d | 25636 | { |
c19d1205 | 25637 | int i; |
404ff6b5 | 25638 | |
c19d1205 ZW |
25639 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
25640 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
25641 | abort (); | |
a737bd4d | 25642 | } |
404ff6b5 | 25643 | |
3e9e4fcf JB |
25644 | /* Auto-select Thumb mode if it's the only available instruction set for the |
25645 | given architecture. */ | |
25646 | ||
25647 | static void | |
25648 | autoselect_thumb_from_cpu_variant (void) | |
25649 | { | |
25650 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
25651 | opcode_select (16); | |
25652 | } | |
25653 | ||
c19d1205 ZW |
25654 | void |
25655 | md_begin (void) | |
a737bd4d | 25656 | { |
c19d1205 ZW |
25657 | unsigned mach; |
25658 | unsigned int i; | |
404ff6b5 | 25659 | |
c19d1205 ZW |
25660 | if ( (arm_ops_hsh = hash_new ()) == NULL |
25661 | || (arm_cond_hsh = hash_new ()) == NULL | |
25662 | || (arm_shift_hsh = hash_new ()) == NULL | |
25663 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 25664 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 25665 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
25666 | || (arm_reloc_hsh = hash_new ()) == NULL |
25667 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
25668 | as_fatal (_("virtual memory exhausted")); |
25669 | ||
25670 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 25671 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 25672 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 25673 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 25674 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 25675 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 25676 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 25677 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 25678 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 25679 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
477330fc | 25680 | (void *) (v7m_psrs + i)); |
c19d1205 | 25681 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 25682 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
25683 | for (i = 0; |
25684 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
25685 | i++) | |
d3ce72d0 | 25686 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 25687 | (void *) (barrier_opt_names + i)); |
c19d1205 | 25688 | #ifdef OBJ_ELF |
3da1d841 NC |
25689 | for (i = 0; i < ARRAY_SIZE (reloc_names); i++) |
25690 | { | |
25691 | struct reloc_entry * entry = reloc_names + i; | |
25692 | ||
25693 | if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32) | |
25694 | /* This makes encode_branch() use the EABI versions of this relocation. */ | |
25695 | entry->reloc = BFD_RELOC_UNUSED; | |
25696 | ||
25697 | hash_insert (arm_reloc_hsh, entry->name, (void *) entry); | |
25698 | } | |
c19d1205 ZW |
25699 | #endif |
25700 | ||
25701 | set_constant_flonums (); | |
404ff6b5 | 25702 | |
c19d1205 ZW |
25703 | /* Set the cpu variant based on the command-line options. We prefer |
25704 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
25705 | -mfpu= over any other way of setting the floating point unit. | |
25706 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 25707 | if (legacy_cpu) |
404ff6b5 | 25708 | { |
e74cfd16 | 25709 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
25710 | as_bad (_("use of old and new-style options to set CPU type")); |
25711 | ||
4d354d8b | 25712 | selected_arch = *legacy_cpu; |
404ff6b5 | 25713 | } |
4d354d8b TP |
25714 | else if (mcpu_cpu_opt) |
25715 | { | |
25716 | selected_arch = *mcpu_cpu_opt; | |
25717 | selected_ext = *mcpu_ext_opt; | |
25718 | } | |
25719 | else if (march_cpu_opt) | |
c168ce07 | 25720 | { |
4d354d8b TP |
25721 | selected_arch = *march_cpu_opt; |
25722 | selected_ext = *march_ext_opt; | |
c168ce07 | 25723 | } |
4d354d8b | 25724 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
404ff6b5 | 25725 | |
e74cfd16 | 25726 | if (legacy_fpu) |
c19d1205 | 25727 | { |
e74cfd16 | 25728 | if (mfpu_opt) |
c19d1205 | 25729 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f | 25730 | |
4d354d8b | 25731 | selected_fpu = *legacy_fpu; |
03b1477f | 25732 | } |
4d354d8b TP |
25733 | else if (mfpu_opt) |
25734 | selected_fpu = *mfpu_opt; | |
25735 | else | |
03b1477f | 25736 | { |
45eb4c1b NS |
25737 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
25738 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
25739 | /* Some environments specify a default FPU. If they don't, infer it |
25740 | from the processor. */ | |
e74cfd16 | 25741 | if (mcpu_fpu_opt) |
4d354d8b | 25742 | selected_fpu = *mcpu_fpu_opt; |
e7da50fa | 25743 | else if (march_fpu_opt) |
4d354d8b | 25744 | selected_fpu = *march_fpu_opt; |
39c2da32 | 25745 | #else |
4d354d8b | 25746 | selected_fpu = fpu_default; |
39c2da32 | 25747 | #endif |
03b1477f RE |
25748 | } |
25749 | ||
4d354d8b | 25750 | if (ARM_FEATURE_ZERO (selected_fpu)) |
03b1477f | 25751 | { |
4d354d8b TP |
25752 | if (!no_cpu_selected ()) |
25753 | selected_fpu = fpu_default; | |
03b1477f | 25754 | else |
4d354d8b | 25755 | selected_fpu = fpu_arch_fpa; |
03b1477f RE |
25756 | } |
25757 | ||
ee065d83 | 25758 | #ifdef CPU_DEFAULT |
4d354d8b | 25759 | if (ARM_FEATURE_ZERO (selected_arch)) |
ee065d83 | 25760 | { |
4d354d8b TP |
25761 | selected_arch = cpu_default; |
25762 | selected_cpu = selected_arch; | |
ee065d83 | 25763 | } |
4d354d8b | 25764 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
e74cfd16 | 25765 | #else |
4d354d8b TP |
25766 | /* Autodection of feature mode: allow all features in cpu_variant but leave |
25767 | selected_cpu unset. It will be set in aeabi_set_public_attributes () | |
25768 | after all instruction have been processed and we can decide what CPU | |
25769 | should be selected. */ | |
25770 | if (ARM_FEATURE_ZERO (selected_arch)) | |
25771 | ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu); | |
ee065d83 | 25772 | else |
4d354d8b | 25773 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 | 25774 | #endif |
03b1477f | 25775 | |
3e9e4fcf JB |
25776 | autoselect_thumb_from_cpu_variant (); |
25777 | ||
e74cfd16 | 25778 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 25779 | |
f17c130b | 25780 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 25781 | { |
7cc69913 NC |
25782 | unsigned int flags = 0; |
25783 | ||
25784 | #if defined OBJ_ELF | |
25785 | flags = meabi_flags; | |
d507cf36 PB |
25786 | |
25787 | switch (meabi_flags) | |
33a392fb | 25788 | { |
d507cf36 | 25789 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 25790 | #endif |
d507cf36 PB |
25791 | /* Set the flags in the private structure. */ |
25792 | if (uses_apcs_26) flags |= F_APCS26; | |
25793 | if (support_interwork) flags |= F_INTERWORK; | |
25794 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 25795 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 25796 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
25797 | flags |= F_SOFT_FLOAT; |
25798 | ||
d507cf36 PB |
25799 | switch (mfloat_abi_opt) |
25800 | { | |
25801 | case ARM_FLOAT_ABI_SOFT: | |
25802 | case ARM_FLOAT_ABI_SOFTFP: | |
25803 | flags |= F_SOFT_FLOAT; | |
25804 | break; | |
33a392fb | 25805 | |
d507cf36 PB |
25806 | case ARM_FLOAT_ABI_HARD: |
25807 | if (flags & F_SOFT_FLOAT) | |
25808 | as_bad (_("hard-float conflicts with specified fpu")); | |
25809 | break; | |
25810 | } | |
03b1477f | 25811 | |
e74cfd16 PB |
25812 | /* Using pure-endian doubles (even if soft-float). */ |
25813 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 25814 | flags |= F_VFP_FLOAT; |
f17c130b | 25815 | |
fde78edd | 25816 | #if defined OBJ_ELF |
e74cfd16 | 25817 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 25818 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
25819 | break; |
25820 | ||
8cb51566 | 25821 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 25822 | case EF_ARM_EABI_VER5: |
c19d1205 | 25823 | /* No additional flags to set. */ |
d507cf36 PB |
25824 | break; |
25825 | ||
25826 | default: | |
25827 | abort (); | |
25828 | } | |
7cc69913 | 25829 | #endif |
b99bd4ef NC |
25830 | bfd_set_private_flags (stdoutput, flags); |
25831 | ||
25832 | /* We have run out flags in the COFF header to encode the | |
25833 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 25834 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
25835 | if (atpcs) |
25836 | { | |
25837 | asection * sec; | |
25838 | ||
25839 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
25840 | ||
25841 | if (sec != NULL) | |
25842 | { | |
25843 | bfd_set_section_flags | |
25844 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
25845 | bfd_set_section_size (stdoutput, sec, 0); | |
25846 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
25847 | } | |
25848 | } | |
7cc69913 | 25849 | } |
f17c130b | 25850 | #endif |
b99bd4ef NC |
25851 | |
25852 | /* Record the CPU type as well. */ | |
2d447fca JM |
25853 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
25854 | mach = bfd_mach_arm_iWMMXt2; | |
25855 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 25856 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 25857 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 25858 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 25859 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 25860 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 25861 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 25862 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 25863 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 25864 | { |
e74cfd16 | 25865 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
25866 | mach = bfd_mach_arm_5T; |
25867 | else | |
25868 | mach = bfd_mach_arm_5; | |
25869 | } | |
e74cfd16 | 25870 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 25871 | { |
e74cfd16 | 25872 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
25873 | mach = bfd_mach_arm_4T; |
25874 | else | |
25875 | mach = bfd_mach_arm_4; | |
25876 | } | |
e74cfd16 | 25877 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 25878 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
25879 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
25880 | mach = bfd_mach_arm_3; | |
25881 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
25882 | mach = bfd_mach_arm_2a; | |
25883 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
25884 | mach = bfd_mach_arm_2; | |
25885 | else | |
25886 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
25887 | |
25888 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
25889 | } | |
25890 | ||
c19d1205 | 25891 | /* Command line processing. */ |
b99bd4ef | 25892 | |
c19d1205 ZW |
25893 | /* md_parse_option |
25894 | Invocation line includes a switch not recognized by the base assembler. | |
25895 | See if it's a processor-specific option. | |
b99bd4ef | 25896 | |
c19d1205 ZW |
25897 | This routine is somewhat complicated by the need for backwards |
25898 | compatibility (since older releases of gcc can't be changed). | |
25899 | The new options try to make the interface as compatible as | |
25900 | possible with GCC. | |
b99bd4ef | 25901 | |
c19d1205 | 25902 | New options (supported) are: |
b99bd4ef | 25903 | |
c19d1205 ZW |
25904 | -mcpu=<cpu name> Assemble for selected processor |
25905 | -march=<architecture name> Assemble for selected architecture | |
25906 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
25907 | -EB/-mbig-endian Big-endian | |
25908 | -EL/-mlittle-endian Little-endian | |
25909 | -k Generate PIC code | |
25910 | -mthumb Start in Thumb mode | |
25911 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 25912 | |
278df34e | 25913 | -m[no-]warn-deprecated Warn about deprecated features |
8b2d793c | 25914 | -m[no-]warn-syms Warn when symbols match instructions |
267bf995 | 25915 | |
c19d1205 | 25916 | For now we will also provide support for: |
b99bd4ef | 25917 | |
c19d1205 ZW |
25918 | -mapcs-32 32-bit Program counter |
25919 | -mapcs-26 26-bit Program counter | |
25920 | -macps-float Floats passed in FP registers | |
25921 | -mapcs-reentrant Reentrant code | |
25922 | -matpcs | |
25923 | (sometime these will probably be replaced with -mapcs=<list of options> | |
25924 | and -matpcs=<list of options>) | |
b99bd4ef | 25925 | |
c19d1205 ZW |
25926 | The remaining options are only supported for back-wards compatibility. |
25927 | Cpu variants, the arm part is optional: | |
25928 | -m[arm]1 Currently not supported. | |
25929 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
25930 | -m[arm]3 Arm 3 processor | |
25931 | -m[arm]6[xx], Arm 6 processors | |
25932 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
25933 | -m[arm]8[10] Arm 8 processors | |
25934 | -m[arm]9[20][tdmi] Arm 9 processors | |
25935 | -mstrongarm[110[0]] StrongARM processors | |
25936 | -mxscale XScale processors | |
25937 | -m[arm]v[2345[t[e]]] Arm architectures | |
25938 | -mall All (except the ARM1) | |
25939 | FP variants: | |
25940 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
25941 | -mfpe-old (No float load/store multiples) | |
25942 | -mvfpxd VFP Single precision | |
25943 | -mvfp All VFP | |
25944 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 25945 | |
c19d1205 ZW |
25946 | The following CPU names are recognized: |
25947 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
25948 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
25949 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
25950 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
25951 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
25952 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
25953 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 25954 | |
c19d1205 | 25955 | */ |
b99bd4ef | 25956 | |
c19d1205 | 25957 | const char * md_shortopts = "m:k"; |
b99bd4ef | 25958 | |
c19d1205 ZW |
25959 | #ifdef ARM_BI_ENDIAN |
25960 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
25961 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 25962 | #else |
c19d1205 ZW |
25963 | #if TARGET_BYTES_BIG_ENDIAN |
25964 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 25965 | #else |
c19d1205 ZW |
25966 | #define OPTION_EL (OPTION_MD_BASE + 1) |
25967 | #endif | |
b99bd4ef | 25968 | #endif |
845b51d6 | 25969 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
18a20338 | 25970 | #define OPTION_FDPIC (OPTION_MD_BASE + 3) |
b99bd4ef | 25971 | |
c19d1205 | 25972 | struct option md_longopts[] = |
b99bd4ef | 25973 | { |
c19d1205 ZW |
25974 | #ifdef OPTION_EB |
25975 | {"EB", no_argument, NULL, OPTION_EB}, | |
25976 | #endif | |
25977 | #ifdef OPTION_EL | |
25978 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 25979 | #endif |
845b51d6 | 25980 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
18a20338 CL |
25981 | #ifdef OBJ_ELF |
25982 | {"fdpic", no_argument, NULL, OPTION_FDPIC}, | |
25983 | #endif | |
c19d1205 ZW |
25984 | {NULL, no_argument, NULL, 0} |
25985 | }; | |
b99bd4ef | 25986 | |
c19d1205 | 25987 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 25988 | |
c19d1205 | 25989 | struct arm_option_table |
b99bd4ef | 25990 | { |
0198d5e6 TC |
25991 | const char * option; /* Option name to match. */ |
25992 | const char * help; /* Help information. */ | |
25993 | int * var; /* Variable to change. */ | |
25994 | int value; /* What to change it to. */ | |
25995 | const char * deprecated; /* If non-null, print this message. */ | |
c19d1205 | 25996 | }; |
b99bd4ef | 25997 | |
c19d1205 ZW |
25998 | struct arm_option_table arm_opts[] = |
25999 | { | |
26000 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
26001 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
26002 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
26003 | &support_interwork, 1, NULL}, | |
26004 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
26005 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
26006 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
26007 | 1, NULL}, | |
26008 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
26009 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
26010 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
26011 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
26012 | NULL}, | |
b99bd4ef | 26013 | |
c19d1205 ZW |
26014 | /* These are recognized by the assembler, but have no affect on code. */ |
26015 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
26016 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
26017 | |
26018 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
26019 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
26020 | &warn_on_deprecated, 0, NULL}, | |
8b2d793c NC |
26021 | {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL}, |
26022 | {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL}, | |
e74cfd16 PB |
26023 | {NULL, NULL, NULL, 0, NULL} |
26024 | }; | |
26025 | ||
26026 | struct arm_legacy_option_table | |
26027 | { | |
0198d5e6 TC |
26028 | const char * option; /* Option name to match. */ |
26029 | const arm_feature_set ** var; /* Variable to change. */ | |
26030 | const arm_feature_set value; /* What to change it to. */ | |
26031 | const char * deprecated; /* If non-null, print this message. */ | |
e74cfd16 | 26032 | }; |
b99bd4ef | 26033 | |
e74cfd16 PB |
26034 | const struct arm_legacy_option_table arm_legacy_opts[] = |
26035 | { | |
c19d1205 ZW |
26036 | /* DON'T add any new processors to this list -- we want the whole list |
26037 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
26038 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
26039 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
26040 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
26041 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
26042 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
26043 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
26044 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
26045 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
26046 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
26047 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
26048 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
26049 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
26050 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
26051 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
26052 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
26053 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
26054 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
26055 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
26056 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
26057 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
26058 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
26059 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
26060 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
26061 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
26062 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
26063 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
26064 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
26065 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
26066 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
26067 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
26068 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
26069 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
26070 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
26071 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
26072 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
26073 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
26074 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
26075 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
26076 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
26077 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
26078 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
26079 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
26080 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
26081 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
26082 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
26083 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
26084 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26085 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26086 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26087 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
26088 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
26089 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
26090 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
26091 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
26092 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
26093 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
26094 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
26095 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
26096 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
26097 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
26098 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
26099 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
26100 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
26101 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
26102 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
26103 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
26104 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
26105 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
26106 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
26107 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 26108 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 26109 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 26110 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 26111 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 26112 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
26113 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
26114 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
26115 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 26116 | |
c19d1205 | 26117 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
26118 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
26119 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
26120 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
26121 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
26122 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
26123 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
26124 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
26125 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
26126 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
26127 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
26128 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
26129 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
26130 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
26131 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
26132 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
26133 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
26134 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
26135 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 26136 | |
c19d1205 | 26137 | /* Floating point variants -- don't add any more to this list either. */ |
0198d5e6 TC |
26138 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
26139 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
26140 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
26141 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 26142 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 26143 | |
e74cfd16 | 26144 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 26145 | }; |
7ed4c4c5 | 26146 | |
c19d1205 | 26147 | struct arm_cpu_option_table |
7ed4c4c5 | 26148 | { |
0198d5e6 TC |
26149 | const char * name; |
26150 | size_t name_len; | |
26151 | const arm_feature_set value; | |
26152 | const arm_feature_set ext; | |
c19d1205 ZW |
26153 | /* For some CPUs we assume an FPU unless the user explicitly sets |
26154 | -mfpu=... */ | |
0198d5e6 | 26155 | const arm_feature_set default_fpu; |
ee065d83 PB |
26156 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
26157 | case. */ | |
0198d5e6 | 26158 | const char * canonical_name; |
c19d1205 | 26159 | }; |
7ed4c4c5 | 26160 | |
c19d1205 ZW |
26161 | /* This list should, at a minimum, contain all the cpu names |
26162 | recognized by GCC. */ | |
996b5569 | 26163 | #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN } |
0198d5e6 | 26164 | |
e74cfd16 | 26165 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 26166 | { |
996b5569 TP |
26167 | ARM_CPU_OPT ("all", NULL, ARM_ANY, |
26168 | ARM_ARCH_NONE, | |
26169 | FPU_ARCH_FPA), | |
26170 | ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1, | |
26171 | ARM_ARCH_NONE, | |
26172 | FPU_ARCH_FPA), | |
26173 | ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2, | |
26174 | ARM_ARCH_NONE, | |
26175 | FPU_ARCH_FPA), | |
26176 | ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S, | |
26177 | ARM_ARCH_NONE, | |
26178 | FPU_ARCH_FPA), | |
26179 | ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S, | |
26180 | ARM_ARCH_NONE, | |
26181 | FPU_ARCH_FPA), | |
26182 | ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3, | |
26183 | ARM_ARCH_NONE, | |
26184 | FPU_ARCH_FPA), | |
26185 | ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3, | |
26186 | ARM_ARCH_NONE, | |
26187 | FPU_ARCH_FPA), | |
26188 | ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3, | |
26189 | ARM_ARCH_NONE, | |
26190 | FPU_ARCH_FPA), | |
26191 | ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3, | |
26192 | ARM_ARCH_NONE, | |
26193 | FPU_ARCH_FPA), | |
26194 | ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3, | |
26195 | ARM_ARCH_NONE, | |
26196 | FPU_ARCH_FPA), | |
26197 | ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3, | |
26198 | ARM_ARCH_NONE, | |
26199 | FPU_ARCH_FPA), | |
26200 | ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M, | |
26201 | ARM_ARCH_NONE, | |
26202 | FPU_ARCH_FPA), | |
26203 | ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3, | |
26204 | ARM_ARCH_NONE, | |
26205 | FPU_ARCH_FPA), | |
26206 | ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M, | |
26207 | ARM_ARCH_NONE, | |
26208 | FPU_ARCH_FPA), | |
26209 | ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3, | |
26210 | ARM_ARCH_NONE, | |
26211 | FPU_ARCH_FPA), | |
26212 | ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M, | |
26213 | ARM_ARCH_NONE, | |
26214 | FPU_ARCH_FPA), | |
26215 | ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3, | |
26216 | ARM_ARCH_NONE, | |
26217 | FPU_ARCH_FPA), | |
26218 | ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3, | |
26219 | ARM_ARCH_NONE, | |
26220 | FPU_ARCH_FPA), | |
26221 | ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3, | |
26222 | ARM_ARCH_NONE, | |
26223 | FPU_ARCH_FPA), | |
26224 | ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3, | |
26225 | ARM_ARCH_NONE, | |
26226 | FPU_ARCH_FPA), | |
26227 | ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T, | |
26228 | ARM_ARCH_NONE, | |
26229 | FPU_ARCH_FPA), | |
26230 | ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3, | |
26231 | ARM_ARCH_NONE, | |
26232 | FPU_ARCH_FPA), | |
26233 | ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T, | |
26234 | ARM_ARCH_NONE, | |
26235 | FPU_ARCH_FPA), | |
26236 | ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T, | |
26237 | ARM_ARCH_NONE, | |
26238 | FPU_ARCH_FPA), | |
26239 | ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3, | |
26240 | ARM_ARCH_NONE, | |
26241 | FPU_ARCH_FPA), | |
26242 | ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3, | |
26243 | ARM_ARCH_NONE, | |
26244 | FPU_ARCH_FPA), | |
26245 | ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3, | |
26246 | ARM_ARCH_NONE, | |
26247 | FPU_ARCH_FPA), | |
26248 | ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3, | |
26249 | ARM_ARCH_NONE, | |
26250 | FPU_ARCH_FPA), | |
26251 | ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T, | |
26252 | ARM_ARCH_NONE, | |
26253 | FPU_ARCH_FPA), | |
26254 | ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T, | |
26255 | ARM_ARCH_NONE, | |
26256 | FPU_ARCH_FPA), | |
26257 | ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T, | |
26258 | ARM_ARCH_NONE, | |
26259 | FPU_ARCH_FPA), | |
26260 | ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4, | |
26261 | ARM_ARCH_NONE, | |
26262 | FPU_ARCH_FPA), | |
26263 | ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4, | |
26264 | ARM_ARCH_NONE, | |
26265 | FPU_ARCH_FPA), | |
26266 | ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4, | |
26267 | ARM_ARCH_NONE, | |
26268 | FPU_ARCH_FPA), | |
26269 | ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4, | |
26270 | ARM_ARCH_NONE, | |
26271 | FPU_ARCH_FPA), | |
26272 | ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4, | |
26273 | ARM_ARCH_NONE, | |
26274 | FPU_ARCH_FPA), | |
26275 | ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4, | |
26276 | ARM_ARCH_NONE, | |
26277 | FPU_ARCH_FPA), | |
26278 | ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4, | |
26279 | ARM_ARCH_NONE, | |
26280 | FPU_ARCH_FPA), | |
26281 | ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T, | |
26282 | ARM_ARCH_NONE, | |
26283 | FPU_ARCH_FPA), | |
26284 | ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T, | |
26285 | ARM_ARCH_NONE, | |
26286 | FPU_ARCH_FPA), | |
26287 | ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T, | |
26288 | ARM_ARCH_NONE, | |
26289 | FPU_ARCH_FPA), | |
26290 | ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T, | |
26291 | ARM_ARCH_NONE, | |
26292 | FPU_ARCH_FPA), | |
26293 | ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T, | |
26294 | ARM_ARCH_NONE, | |
26295 | FPU_ARCH_FPA), | |
26296 | ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T, | |
26297 | ARM_ARCH_NONE, | |
26298 | FPU_ARCH_FPA), | |
26299 | ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4, | |
26300 | ARM_ARCH_NONE, | |
26301 | FPU_ARCH_FPA), | |
26302 | ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4, | |
26303 | ARM_ARCH_NONE, | |
26304 | FPU_ARCH_FPA), | |
26305 | ||
c19d1205 ZW |
26306 | /* For V5 or later processors we default to using VFP; but the user |
26307 | should really set the FPU type explicitly. */ | |
996b5569 TP |
26308 | ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP, |
26309 | ARM_ARCH_NONE, | |
26310 | FPU_ARCH_VFP_V2), | |
26311 | ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE, | |
26312 | ARM_ARCH_NONE, | |
26313 | FPU_ARCH_VFP_V2), | |
26314 | ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ, | |
26315 | ARM_ARCH_NONE, | |
26316 | FPU_ARCH_VFP_V2), | |
26317 | ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ, | |
26318 | ARM_ARCH_NONE, | |
26319 | FPU_ARCH_VFP_V2), | |
26320 | ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ, | |
26321 | ARM_ARCH_NONE, | |
26322 | FPU_ARCH_VFP_V2), | |
26323 | ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP, | |
26324 | ARM_ARCH_NONE, | |
26325 | FPU_ARCH_VFP_V2), | |
26326 | ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE, | |
26327 | ARM_ARCH_NONE, | |
26328 | FPU_ARCH_VFP_V2), | |
26329 | ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE, | |
26330 | ARM_ARCH_NONE, | |
26331 | FPU_ARCH_VFP_V2), | |
26332 | ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP, | |
26333 | ARM_ARCH_NONE, | |
26334 | FPU_ARCH_VFP_V2), | |
26335 | ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE, | |
26336 | ARM_ARCH_NONE, | |
26337 | FPU_ARCH_VFP_V2), | |
26338 | ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE, | |
26339 | ARM_ARCH_NONE, | |
26340 | FPU_ARCH_VFP_V2), | |
26341 | ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE, | |
26342 | ARM_ARCH_NONE, | |
26343 | FPU_ARCH_VFP_V2), | |
26344 | ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T, | |
26345 | ARM_ARCH_NONE, | |
26346 | FPU_ARCH_VFP_V1), | |
26347 | ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T, | |
26348 | ARM_ARCH_NONE, | |
26349 | FPU_ARCH_VFP_V1), | |
26350 | ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE, | |
26351 | ARM_ARCH_NONE, | |
26352 | FPU_ARCH_VFP_V2), | |
26353 | ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE, | |
26354 | ARM_ARCH_NONE, | |
26355 | FPU_ARCH_VFP_V2), | |
26356 | ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T, | |
26357 | ARM_ARCH_NONE, | |
26358 | FPU_ARCH_VFP_V1), | |
26359 | ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE, | |
26360 | ARM_ARCH_NONE, | |
26361 | FPU_ARCH_VFP_V2), | |
26362 | ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE, | |
26363 | ARM_ARCH_NONE, | |
26364 | FPU_ARCH_VFP_V2), | |
26365 | ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ, | |
26366 | ARM_ARCH_NONE, | |
26367 | FPU_ARCH_VFP_V2), | |
26368 | ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ, | |
26369 | ARM_ARCH_NONE, | |
26370 | FPU_ARCH_VFP_V2), | |
26371 | ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE, | |
26372 | ARM_ARCH_NONE, | |
26373 | FPU_ARCH_VFP_V2), | |
26374 | ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE, | |
26375 | ARM_ARCH_NONE, | |
26376 | FPU_ARCH_VFP_V2), | |
26377 | ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE, | |
26378 | ARM_ARCH_NONE, | |
26379 | FPU_ARCH_VFP_V2), | |
26380 | ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE, | |
26381 | ARM_ARCH_NONE, | |
26382 | FPU_ARCH_VFP_V2), | |
26383 | ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE, | |
26384 | ARM_ARCH_NONE, | |
26385 | FPU_ARCH_VFP_V2), | |
26386 | ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6, | |
26387 | ARM_ARCH_NONE, | |
26388 | FPU_NONE), | |
26389 | ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6, | |
26390 | ARM_ARCH_NONE, | |
26391 | FPU_NONE), | |
26392 | ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6, | |
26393 | ARM_ARCH_NONE, | |
26394 | FPU_ARCH_VFP_V2), | |
26395 | ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6, | |
26396 | ARM_ARCH_NONE, | |
26397 | FPU_ARCH_VFP_V2), | |
26398 | ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K, | |
26399 | ARM_ARCH_NONE, | |
26400 | FPU_ARCH_VFP_V2), | |
26401 | ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K, | |
26402 | ARM_ARCH_NONE, | |
26403 | FPU_NONE), | |
26404 | ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2, | |
26405 | ARM_ARCH_NONE, | |
26406 | FPU_NONE), | |
26407 | ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2, | |
26408 | ARM_ARCH_NONE, | |
26409 | FPU_ARCH_VFP_V2), | |
26410 | ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ, | |
26411 | ARM_ARCH_NONE, | |
26412 | FPU_NONE), | |
26413 | ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ, | |
26414 | ARM_ARCH_NONE, | |
26415 | FPU_ARCH_VFP_V2), | |
26416 | ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A, | |
26417 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
26418 | FPU_NONE), | |
26419 | ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE, | |
26420 | ARM_ARCH_NONE, | |
26421 | FPU_ARCH_NEON_VFP_V4), | |
26422 | ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A, | |
26423 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), | |
26424 | ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)), | |
26425 | ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A, | |
26426 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
26427 | ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)), | |
26428 | ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE, | |
26429 | ARM_ARCH_NONE, | |
26430 | FPU_ARCH_NEON_VFP_V4), | |
26431 | ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE, | |
26432 | ARM_ARCH_NONE, | |
26433 | FPU_ARCH_NEON_VFP_V4), | |
26434 | ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE, | |
26435 | ARM_ARCH_NONE, | |
26436 | FPU_ARCH_NEON_VFP_V4), | |
26437 | ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A, | |
26438 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26439 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26440 | ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A, | |
26441 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26442 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26443 | ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A, | |
26444 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26445 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
15a7695f JG |
26446 | ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A, |
26447 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 26448 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
996b5569 TP |
26449 | ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A, |
26450 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26451 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26452 | ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A, | |
26453 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26454 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26455 | ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A, | |
26456 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26457 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
15a7695f JG |
26458 | ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A, |
26459 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
0198d5e6 | 26460 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), |
7ebd1359 | 26461 | ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A, |
26462 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
26463 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
ef8df4ca KT |
26464 | ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A, |
26465 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
26466 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
996b5569 TP |
26467 | ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R, |
26468 | ARM_ARCH_NONE, | |
26469 | FPU_NONE), | |
26470 | ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R, | |
26471 | ARM_ARCH_NONE, | |
26472 | FPU_ARCH_VFP_V3D16), | |
26473 | ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R, | |
26474 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
26475 | FPU_NONE), | |
26476 | ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R, | |
26477 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
26478 | FPU_ARCH_VFP_V3D16), | |
26479 | ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R, | |
26480 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV), | |
26481 | FPU_ARCH_VFP_V3D16), | |
0cda1e19 TP |
26482 | ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R, |
26483 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26484 | FPU_ARCH_NEON_VFP_ARMV8), | |
996b5569 TP |
26485 | ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN, |
26486 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
26487 | FPU_NONE), | |
26488 | ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE, | |
26489 | ARM_ARCH_NONE, | |
26490 | FPU_NONE), | |
26491 | ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM, | |
26492 | ARM_ARCH_NONE, | |
26493 | FPU_NONE), | |
26494 | ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM, | |
26495 | ARM_ARCH_NONE, | |
26496 | FPU_NONE), | |
26497 | ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M, | |
26498 | ARM_ARCH_NONE, | |
26499 | FPU_NONE), | |
26500 | ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM, | |
26501 | ARM_ARCH_NONE, | |
26502 | FPU_NONE), | |
26503 | ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM, | |
26504 | ARM_ARCH_NONE, | |
26505 | FPU_NONE), | |
26506 | ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM, | |
26507 | ARM_ARCH_NONE, | |
26508 | FPU_NONE), | |
26509 | ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A, | |
26510 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26511 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
83f43c83 KT |
26512 | ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A, |
26513 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
26514 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD), | |
c19d1205 | 26515 | /* ??? XSCALE is really an architecture. */ |
996b5569 TP |
26516 | ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE, |
26517 | ARM_ARCH_NONE, | |
26518 | FPU_ARCH_VFP_V2), | |
26519 | ||
c19d1205 | 26520 | /* ??? iwmmxt is not a processor. */ |
996b5569 TP |
26521 | ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT, |
26522 | ARM_ARCH_NONE, | |
26523 | FPU_ARCH_VFP_V2), | |
26524 | ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2, | |
26525 | ARM_ARCH_NONE, | |
26526 | FPU_ARCH_VFP_V2), | |
26527 | ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE, | |
26528 | ARM_ARCH_NONE, | |
26529 | FPU_ARCH_VFP_V2), | |
26530 | ||
0198d5e6 | 26531 | /* Maverick. */ |
996b5569 TP |
26532 | ARM_CPU_OPT ("ep9312", "ARM920T", |
26533 | ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), | |
26534 | ARM_ARCH_NONE, FPU_ARCH_MAVERICK), | |
26535 | ||
da4339ed | 26536 | /* Marvell processors. */ |
996b5569 TP |
26537 | ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A, |
26538 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
26539 | FPU_ARCH_VFP_V3D16), | |
26540 | ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A, | |
26541 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC), | |
26542 | FPU_ARCH_NEON_VFP_V4), | |
da4339ed | 26543 | |
996b5569 TP |
26544 | /* APM X-Gene family. */ |
26545 | ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A, | |
26546 | ARM_ARCH_NONE, | |
26547 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26548 | ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A, | |
26549 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8), | |
26550 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8), | |
26551 | ||
26552 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } | |
c19d1205 | 26553 | }; |
f3bad469 | 26554 | #undef ARM_CPU_OPT |
7ed4c4c5 | 26555 | |
34ef62f4 AV |
26556 | struct arm_ext_table |
26557 | { | |
26558 | const char * name; | |
26559 | size_t name_len; | |
26560 | const arm_feature_set merge; | |
26561 | const arm_feature_set clear; | |
26562 | }; | |
26563 | ||
c19d1205 | 26564 | struct arm_arch_option_table |
7ed4c4c5 | 26565 | { |
34ef62f4 AV |
26566 | const char * name; |
26567 | size_t name_len; | |
26568 | const arm_feature_set value; | |
26569 | const arm_feature_set default_fpu; | |
26570 | const struct arm_ext_table * ext_table; | |
26571 | }; | |
26572 | ||
26573 | /* Used to add support for +E and +noE extension. */ | |
26574 | #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C } | |
26575 | /* Used to add support for a +E extension. */ | |
26576 | #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE } | |
26577 | /* Used to add support for a +noE extension. */ | |
26578 | #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C } | |
26579 | ||
26580 | #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \ | |
26581 | ~0 & ~FPU_ENDIAN_PURE) | |
26582 | ||
26583 | static const struct arm_ext_table armv5te_ext_table[] = | |
26584 | { | |
26585 | ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP), | |
26586 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26587 | }; | |
26588 | ||
26589 | static const struct arm_ext_table armv7_ext_table[] = | |
26590 | { | |
26591 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
26592 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26593 | }; | |
26594 | ||
26595 | static const struct arm_ext_table armv7ve_ext_table[] = | |
26596 | { | |
26597 | ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP), | |
26598 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), | |
26599 | ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3), | |
26600 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
26601 | ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16), | |
26602 | ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */ | |
26603 | ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4), | |
26604 | ||
26605 | ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4, | |
26606 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)), | |
26607 | ||
26608 | /* Aliases for +simd. */ | |
26609 | ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4), | |
26610 | ||
26611 | ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
26612 | ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
26613 | ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16), | |
26614 | ||
26615 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26616 | }; | |
26617 | ||
26618 | static const struct arm_ext_table armv7a_ext_table[] = | |
26619 | { | |
26620 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
26621 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */ | |
26622 | ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3), | |
26623 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
26624 | ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16), | |
26625 | ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), | |
26626 | ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4), | |
26627 | ||
26628 | ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1, | |
26629 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)), | |
26630 | ||
26631 | /* Aliases for +simd. */ | |
26632 | ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
26633 | ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1), | |
26634 | ||
26635 | ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16), | |
26636 | ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4), | |
26637 | ||
26638 | ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)), | |
26639 | ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)), | |
26640 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26641 | }; | |
26642 | ||
26643 | static const struct arm_ext_table armv7r_ext_table[] = | |
26644 | { | |
26645 | ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD), | |
26646 | ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */ | |
26647 | ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP), | |
26648 | ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */ | |
26649 | ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16), | |
26650 | ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16), | |
26651 | ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), | |
26652 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)), | |
26653 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26654 | }; | |
26655 | ||
26656 | static const struct arm_ext_table armv7em_ext_table[] = | |
26657 | { | |
26658 | ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP), | |
26659 | /* Alias for +fp, used to be known as fpv4-sp-d16. */ | |
26660 | ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16), | |
26661 | ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16), | |
26662 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
26663 | ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16), | |
26664 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26665 | }; | |
26666 | ||
26667 | static const struct arm_ext_table armv8a_ext_table[] = | |
26668 | { | |
26669 | ARM_ADD ("crc", ARCH_CRC_ARMV8), | |
26670 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8), | |
26671 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
26672 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
26673 | ||
26674 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
26675 | should use the +simd option to turn on FP. */ | |
26676 | ARM_REMOVE ("fp", ALL_FP), | |
26677 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
26678 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
26679 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26680 | }; | |
26681 | ||
26682 | ||
26683 | static const struct arm_ext_table armv81a_ext_table[] = | |
26684 | { | |
26685 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1), | |
26686 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1, | |
26687 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
26688 | ||
26689 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
26690 | should use the +simd option to turn on FP. */ | |
26691 | ARM_REMOVE ("fp", ALL_FP), | |
26692 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
26693 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
26694 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26695 | }; | |
26696 | ||
26697 | static const struct arm_ext_table armv82a_ext_table[] = | |
26698 | { | |
26699 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1), | |
26700 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16), | |
26701 | ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML), | |
26702 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1, | |
26703 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
26704 | ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
26705 | ||
26706 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
26707 | should use the +simd option to turn on FP. */ | |
26708 | ARM_REMOVE ("fp", ALL_FP), | |
26709 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
26710 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
26711 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26712 | }; | |
26713 | ||
26714 | static const struct arm_ext_table armv84a_ext_table[] = | |
26715 | { | |
26716 | ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
26717 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML), | |
26718 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4, | |
26719 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
26720 | ||
26721 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
26722 | should use the +simd option to turn on FP. */ | |
26723 | ARM_REMOVE ("fp", ALL_FP), | |
26724 | ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)), | |
26725 | ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)), | |
26726 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26727 | }; | |
26728 | ||
26729 | static const struct arm_ext_table armv85a_ext_table[] = | |
26730 | { | |
26731 | ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8), | |
26732 | ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML), | |
26733 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4, | |
26734 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
26735 | ||
26736 | /* Armv8-a does not allow an FP implementation without SIMD, so the user | |
26737 | should use the +simd option to turn on FP. */ | |
26738 | ARM_REMOVE ("fp", ALL_FP), | |
26739 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26740 | }; | |
26741 | ||
26742 | static const struct arm_ext_table armv8m_main_ext_table[] = | |
26743 | { | |
26744 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
26745 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)), | |
26746 | ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP), | |
26747 | ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16), | |
26748 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26749 | }; | |
26750 | ||
e0991585 AV |
26751 | static const struct arm_ext_table armv8_1m_main_ext_table[] = |
26752 | { | |
26753 | ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
26754 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)), | |
26755 | ARM_EXT ("fp", | |
26756 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
26757 | FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA), | |
26758 | ALL_FP), | |
26759 | ARM_ADD ("fp.dp", | |
26760 | ARM_FEATURE (0, ARM_EXT2_FP16_INST, | |
26761 | FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)), | |
26762 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
26763 | }; | |
26764 | ||
34ef62f4 AV |
26765 | static const struct arm_ext_table armv8r_ext_table[] = |
26766 | { | |
26767 | ARM_ADD ("crc", ARCH_CRC_ARMV8), | |
26768 | ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8), | |
26769 | ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
26770 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)), | |
26771 | ARM_REMOVE ("fp", ALL_FP), | |
26772 | ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16), | |
26773 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
c19d1205 | 26774 | }; |
7ed4c4c5 | 26775 | |
c19d1205 ZW |
26776 | /* This list should, at a minimum, contain all the architecture names |
26777 | recognized by GCC. */ | |
34ef62f4 AV |
26778 | #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL } |
26779 | #define ARM_ARCH_OPT2(N, V, DF, ext) \ | |
26780 | { N, sizeof (N) - 1, V, DF, ext##_ext_table } | |
0198d5e6 | 26781 | |
e74cfd16 | 26782 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 26783 | { |
497d849d TP |
26784 | ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA), |
26785 | ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA), | |
26786 | ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA), | |
26787 | ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
26788 | ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
26789 | ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA), | |
26790 | ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA), | |
26791 | ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA), | |
26792 | ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA), | |
26793 | ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA), | |
26794 | ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA), | |
26795 | ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP), | |
26796 | ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP), | |
26797 | ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP), | |
34ef62f4 AV |
26798 | ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te), |
26799 | ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te), | |
26800 | ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te), | |
26801 | ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te), | |
26802 | ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te), | |
26803 | ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te), | |
26804 | ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te), | |
f33026a9 MW |
26805 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is |
26806 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
26807 | ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te), |
26808 | ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te), | |
26809 | ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te), | |
26810 | ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te), | |
26811 | ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te), | |
f33026a9 MW |
26812 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is |
26813 | kept to preserve existing behaviour. */ | |
34ef62f4 AV |
26814 | ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), |
26815 | ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te), | |
497d849d TP |
26816 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), |
26817 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
34ef62f4 | 26818 | ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7), |
c450d570 PB |
26819 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
26820 | Accept the non-dashed form for compatibility with old toolchains. */ | |
34ef62f4 AV |
26821 | ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a), |
26822 | ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve), | |
26823 | ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r), | |
497d849d | 26824 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 AV |
26825 | ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a), |
26826 | ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r), | |
497d849d | 26827 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), |
34ef62f4 | 26828 | ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em), |
497d849d | 26829 | ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP), |
34ef62f4 AV |
26830 | ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP, |
26831 | armv8m_main), | |
e0991585 AV |
26832 | ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP, |
26833 | armv8_1m_main), | |
34ef62f4 AV |
26834 | ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a), |
26835 | ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a), | |
26836 | ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a), | |
26837 | ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a), | |
26838 | ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r), | |
26839 | ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a), | |
26840 | ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a), | |
497d849d TP |
26841 | ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP), |
26842 | ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP), | |
26843 | ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP), | |
34ef62f4 | 26844 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 26845 | }; |
f3bad469 | 26846 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 26847 | |
69133863 | 26848 | /* ISA extensions in the co-processor and main instruction set space. */ |
0198d5e6 | 26849 | |
69133863 | 26850 | struct arm_option_extension_value_table |
c19d1205 | 26851 | { |
0198d5e6 TC |
26852 | const char * name; |
26853 | size_t name_len; | |
26854 | const arm_feature_set merge_value; | |
26855 | const arm_feature_set clear_value; | |
d942732e TP |
26856 | /* List of architectures for which an extension is available. ARM_ARCH_NONE |
26857 | indicates that an extension is available for all architectures while | |
26858 | ARM_ANY marks an empty entry. */ | |
0198d5e6 | 26859 | const arm_feature_set allowed_archs[2]; |
c19d1205 | 26860 | }; |
7ed4c4c5 | 26861 | |
0198d5e6 TC |
26862 | /* The following table must be in alphabetical order with a NULL last entry. */ |
26863 | ||
d942732e TP |
26864 | #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } } |
26865 | #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} } | |
0198d5e6 | 26866 | |
34ef62f4 AV |
26867 | /* DEPRECATED: Refrain from using this table to add any new extensions, instead |
26868 | use the context sensitive approach using arm_ext_table's. */ | |
69133863 | 26869 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 26870 | { |
823d2571 TG |
26871 | ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8), |
26872 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
bca38921 | 26873 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
823d2571 TG |
26874 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8), |
26875 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
c604a79a JW |
26876 | ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8, |
26877 | ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD), | |
26878 | ARM_ARCH_V8_2A), | |
15afaa63 TP |
26879 | ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), |
26880 | ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP), | |
26881 | ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)), | |
823d2571 TG |
26882 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8), |
26883 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
b8ec4e87 JW |
26884 | ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), |
26885 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
26886 | ARM_ARCH_V8_2A), | |
01f48020 TC |
26887 | ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST |
26888 | | ARM_EXT2_FP16_FML), | |
26889 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST | |
26890 | | ARM_EXT2_FP16_FML), | |
26891 | ARM_ARCH_V8_2A), | |
d942732e | 26892 | ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
823d2571 | 26893 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
d942732e TP |
26894 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
26895 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
3d030cdb TP |
26896 | /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of |
26897 | Thumb divide instruction. Due to this having the same name as the | |
26898 | previous entry, this will be ignored when doing command-line parsing and | |
26899 | only considered by build attribute selection code. */ | |
26900 | ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV), | |
26901 | ARM_FEATURE_CORE_LOW (ARM_EXT_DIV), | |
26902 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7)), | |
823d2571 | 26903 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), |
d942732e | 26904 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE), |
823d2571 | 26905 | ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), |
d942732e | 26906 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE), |
823d2571 | 26907 | ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), |
d942732e TP |
26908 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE), |
26909 | ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
823d2571 | 26910 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP), |
d942732e TP |
26911 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A), |
26912 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)), | |
823d2571 TG |
26913 | ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS), |
26914 | ARM_FEATURE_CORE_LOW (ARM_EXT_OS), | |
26915 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)), | |
ddfded2f MW |
26916 | ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN), |
26917 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0), | |
ced40572 | 26918 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
dad0c3bf SD |
26919 | ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), |
26920 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES), | |
26921 | ARM_ARCH_V8A), | |
4d1464f2 MW |
26922 | ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS), |
26923 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0), | |
ced40572 | 26924 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
643afb90 MW |
26925 | ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1, |
26926 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA), | |
ced40572 | 26927 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)), |
7fadb25d SD |
26928 | ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), |
26929 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB), | |
26930 | ARM_ARCH_V8A), | |
d942732e | 26931 | ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
823d2571 | 26932 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
d942732e TP |
26933 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K), |
26934 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
643afb90 MW |
26935 | ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8, |
26936 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8), | |
26937 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
26938 | ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV |
26939 | | ARM_EXT_DIV), | |
26940 | ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT), | |
26941 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
26942 | ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), | |
d942732e TP |
26943 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE), |
26944 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } } | |
69133863 | 26945 | }; |
f3bad469 | 26946 | #undef ARM_EXT_OPT |
69133863 MGD |
26947 | |
26948 | /* ISA floating-point and Advanced SIMD extensions. */ | |
26949 | struct arm_option_fpu_value_table | |
26950 | { | |
0198d5e6 TC |
26951 | const char * name; |
26952 | const arm_feature_set value; | |
c19d1205 | 26953 | }; |
7ed4c4c5 | 26954 | |
c19d1205 ZW |
26955 | /* This list should, at a minimum, contain all the fpu names |
26956 | recognized by GCC. */ | |
69133863 | 26957 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
26958 | { |
26959 | {"softfpa", FPU_NONE}, | |
26960 | {"fpe", FPU_ARCH_FPE}, | |
26961 | {"fpe2", FPU_ARCH_FPE}, | |
26962 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
26963 | {"fpa", FPU_ARCH_FPA}, | |
26964 | {"fpa10", FPU_ARCH_FPA}, | |
26965 | {"fpa11", FPU_ARCH_FPA}, | |
26966 | {"arm7500fe", FPU_ARCH_FPA}, | |
26967 | {"softvfp", FPU_ARCH_VFP}, | |
26968 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
26969 | {"vfp", FPU_ARCH_VFP_V2}, | |
26970 | {"vfp9", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 26971 | {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */ |
c19d1205 ZW |
26972 | {"vfp10", FPU_ARCH_VFP_V2}, |
26973 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
26974 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
26975 | {"vfpv2", FPU_ARCH_VFP_V2}, |
26976 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 26977 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 26978 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
26979 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
26980 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
26981 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
26982 | {"arm1020t", FPU_ARCH_VFP_V1}, |
26983 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
d5e0ba9c | 26984 | {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */ |
c19d1205 ZW |
26985 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, |
26986 | {"maverick", FPU_ARCH_MAVERICK}, | |
d5e0ba9c | 26987 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
d3375ddd | 26988 | {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 26989 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
26990 | {"vfpv4", FPU_ARCH_VFP_V4}, |
26991 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 26992 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
a715796b TG |
26993 | {"fpv5-d16", FPU_ARCH_VFP_V5D16}, |
26994 | {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16}, | |
62f3b8c8 | 26995 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
26996 | {"fp-armv8", FPU_ARCH_VFP_ARMV8}, |
26997 | {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8}, | |
26998 | {"crypto-neon-fp-armv8", | |
26999 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8}, | |
d6b4b13e | 27000 | {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1}, |
081e4c7d MW |
27001 | {"crypto-neon-fp-armv8.1", |
27002 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1}, | |
e74cfd16 PB |
27003 | {NULL, ARM_ARCH_NONE} |
27004 | }; | |
27005 | ||
27006 | struct arm_option_value_table | |
27007 | { | |
e0471c16 | 27008 | const char *name; |
e74cfd16 | 27009 | long value; |
c19d1205 | 27010 | }; |
7ed4c4c5 | 27011 | |
e74cfd16 | 27012 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
27013 | { |
27014 | {"hard", ARM_FLOAT_ABI_HARD}, | |
27015 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
27016 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 27017 | {NULL, 0} |
c19d1205 | 27018 | }; |
7ed4c4c5 | 27019 | |
c19d1205 | 27020 | #ifdef OBJ_ELF |
3a4a14e9 | 27021 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 27022 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
27023 | { |
27024 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
27025 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 27026 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 27027 | {NULL, 0} |
c19d1205 ZW |
27028 | }; |
27029 | #endif | |
7ed4c4c5 | 27030 | |
c19d1205 ZW |
27031 | struct arm_long_option_table |
27032 | { | |
0198d5e6 | 27033 | const char * option; /* Substring to match. */ |
e0471c16 | 27034 | const char * help; /* Help information. */ |
17b9d67d | 27035 | int (* func) (const char * subopt); /* Function to decode sub-option. */ |
e0471c16 | 27036 | const char * deprecated; /* If non-null, print this message. */ |
c19d1205 | 27037 | }; |
7ed4c4c5 | 27038 | |
c921be7d | 27039 | static bfd_boolean |
c168ce07 | 27040 | arm_parse_extension (const char *str, const arm_feature_set *opt_set, |
34ef62f4 AV |
27041 | arm_feature_set *ext_set, |
27042 | const struct arm_ext_table *ext_table) | |
7ed4c4c5 | 27043 | { |
69133863 | 27044 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
27045 | extensions being added before being removed. We achieve this by having |
27046 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 27047 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 27048 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
27049 | -1 -> 1 -> 0. */ |
27050 | const struct arm_option_extension_value_table * opt = NULL; | |
d942732e | 27051 | const arm_feature_set arm_any = ARM_ANY; |
69133863 MGD |
27052 | int adding_value = -1; |
27053 | ||
c19d1205 | 27054 | while (str != NULL && *str != 0) |
7ed4c4c5 | 27055 | { |
82b8a785 | 27056 | const char *ext; |
f3bad469 | 27057 | size_t len; |
7ed4c4c5 | 27058 | |
c19d1205 ZW |
27059 | if (*str != '+') |
27060 | { | |
27061 | as_bad (_("invalid architectural extension")); | |
c921be7d | 27062 | return FALSE; |
c19d1205 | 27063 | } |
7ed4c4c5 | 27064 | |
c19d1205 ZW |
27065 | str++; |
27066 | ext = strchr (str, '+'); | |
7ed4c4c5 | 27067 | |
c19d1205 | 27068 | if (ext != NULL) |
f3bad469 | 27069 | len = ext - str; |
c19d1205 | 27070 | else |
f3bad469 | 27071 | len = strlen (str); |
7ed4c4c5 | 27072 | |
f3bad469 | 27073 | if (len >= 2 && strncmp (str, "no", 2) == 0) |
69133863 MGD |
27074 | { |
27075 | if (adding_value != 0) | |
27076 | { | |
27077 | adding_value = 0; | |
27078 | opt = arm_extensions; | |
27079 | } | |
27080 | ||
f3bad469 | 27081 | len -= 2; |
69133863 MGD |
27082 | str += 2; |
27083 | } | |
f3bad469 | 27084 | else if (len > 0) |
69133863 MGD |
27085 | { |
27086 | if (adding_value == -1) | |
27087 | { | |
27088 | adding_value = 1; | |
27089 | opt = arm_extensions; | |
27090 | } | |
27091 | else if (adding_value != 1) | |
27092 | { | |
27093 | as_bad (_("must specify extensions to add before specifying " | |
27094 | "those to remove")); | |
27095 | return FALSE; | |
27096 | } | |
27097 | } | |
27098 | ||
f3bad469 | 27099 | if (len == 0) |
c19d1205 ZW |
27100 | { |
27101 | as_bad (_("missing architectural extension")); | |
c921be7d | 27102 | return FALSE; |
c19d1205 | 27103 | } |
7ed4c4c5 | 27104 | |
69133863 MGD |
27105 | gas_assert (adding_value != -1); |
27106 | gas_assert (opt != NULL); | |
27107 | ||
34ef62f4 AV |
27108 | if (ext_table != NULL) |
27109 | { | |
27110 | const struct arm_ext_table * ext_opt = ext_table; | |
27111 | bfd_boolean found = FALSE; | |
27112 | for (; ext_opt->name != NULL; ext_opt++) | |
27113 | if (ext_opt->name_len == len | |
27114 | && strncmp (ext_opt->name, str, len) == 0) | |
27115 | { | |
27116 | if (adding_value) | |
27117 | { | |
27118 | if (ARM_FEATURE_ZERO (ext_opt->merge)) | |
27119 | /* TODO: Option not supported. When we remove the | |
27120 | legacy table this case should error out. */ | |
27121 | continue; | |
27122 | ||
27123 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge); | |
27124 | } | |
27125 | else | |
27126 | { | |
27127 | if (ARM_FEATURE_ZERO (ext_opt->clear)) | |
27128 | /* TODO: Option not supported. When we remove the | |
27129 | legacy table this case should error out. */ | |
27130 | continue; | |
27131 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear); | |
27132 | } | |
27133 | found = TRUE; | |
27134 | break; | |
27135 | } | |
27136 | if (found) | |
27137 | { | |
27138 | str = ext; | |
27139 | continue; | |
27140 | } | |
27141 | } | |
27142 | ||
69133863 MGD |
27143 | /* Scan over the options table trying to find an exact match. */ |
27144 | for (; opt->name != NULL; opt++) | |
f3bad469 | 27145 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 27146 | { |
d942732e TP |
27147 | int i, nb_allowed_archs = |
27148 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
69133863 | 27149 | /* Check we can apply the extension to this architecture. */ |
d942732e TP |
27150 | for (i = 0; i < nb_allowed_archs; i++) |
27151 | { | |
27152 | /* Empty entry. */ | |
27153 | if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any)) | |
27154 | continue; | |
c168ce07 | 27155 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set)) |
d942732e TP |
27156 | break; |
27157 | } | |
27158 | if (i == nb_allowed_archs) | |
69133863 MGD |
27159 | { |
27160 | as_bad (_("extension does not apply to the base architecture")); | |
27161 | return FALSE; | |
27162 | } | |
27163 | ||
27164 | /* Add or remove the extension. */ | |
27165 | if (adding_value) | |
4d354d8b | 27166 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value); |
69133863 | 27167 | else |
4d354d8b | 27168 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value); |
69133863 | 27169 | |
3d030cdb TP |
27170 | /* Allowing Thumb division instructions for ARMv7 in autodetection |
27171 | rely on this break so that duplicate extensions (extensions | |
27172 | with the same name as a previous extension in the list) are not | |
27173 | considered for command-line parsing. */ | |
c19d1205 ZW |
27174 | break; |
27175 | } | |
7ed4c4c5 | 27176 | |
c19d1205 ZW |
27177 | if (opt->name == NULL) |
27178 | { | |
69133863 MGD |
27179 | /* Did we fail to find an extension because it wasn't specified in |
27180 | alphabetical order, or because it does not exist? */ | |
27181 | ||
27182 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
f3bad469 | 27183 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
27184 | break; |
27185 | ||
27186 | if (opt->name == NULL) | |
27187 | as_bad (_("unknown architectural extension `%s'"), str); | |
27188 | else | |
27189 | as_bad (_("architectural extensions must be specified in " | |
27190 | "alphabetical order")); | |
27191 | ||
c921be7d | 27192 | return FALSE; |
c19d1205 | 27193 | } |
69133863 MGD |
27194 | else |
27195 | { | |
27196 | /* We should skip the extension we've just matched the next time | |
27197 | round. */ | |
27198 | opt++; | |
27199 | } | |
7ed4c4c5 | 27200 | |
c19d1205 ZW |
27201 | str = ext; |
27202 | }; | |
7ed4c4c5 | 27203 | |
c921be7d | 27204 | return TRUE; |
c19d1205 | 27205 | } |
7ed4c4c5 | 27206 | |
c921be7d | 27207 | static bfd_boolean |
17b9d67d | 27208 | arm_parse_cpu (const char *str) |
7ed4c4c5 | 27209 | { |
f3bad469 | 27210 | const struct arm_cpu_option_table *opt; |
82b8a785 | 27211 | const char *ext = strchr (str, '+'); |
f3bad469 | 27212 | size_t len; |
7ed4c4c5 | 27213 | |
c19d1205 | 27214 | if (ext != NULL) |
f3bad469 | 27215 | len = ext - str; |
7ed4c4c5 | 27216 | else |
f3bad469 | 27217 | len = strlen (str); |
7ed4c4c5 | 27218 | |
f3bad469 | 27219 | if (len == 0) |
7ed4c4c5 | 27220 | { |
c19d1205 | 27221 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 27222 | return FALSE; |
7ed4c4c5 NC |
27223 | } |
27224 | ||
c19d1205 | 27225 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 27226 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 27227 | { |
c168ce07 | 27228 | mcpu_cpu_opt = &opt->value; |
4d354d8b TP |
27229 | if (mcpu_ext_opt == NULL) |
27230 | mcpu_ext_opt = XNEW (arm_feature_set); | |
27231 | *mcpu_ext_opt = opt->ext; | |
e74cfd16 | 27232 | mcpu_fpu_opt = &opt->default_fpu; |
ee065d83 | 27233 | if (opt->canonical_name) |
ef8e6722 JW |
27234 | { |
27235 | gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name)); | |
27236 | strcpy (selected_cpu_name, opt->canonical_name); | |
27237 | } | |
ee065d83 PB |
27238 | else |
27239 | { | |
f3bad469 | 27240 | size_t i; |
c921be7d | 27241 | |
ef8e6722 JW |
27242 | if (len >= sizeof selected_cpu_name) |
27243 | len = (sizeof selected_cpu_name) - 1; | |
27244 | ||
f3bad469 | 27245 | for (i = 0; i < len; i++) |
ee065d83 PB |
27246 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
27247 | selected_cpu_name[i] = 0; | |
27248 | } | |
7ed4c4c5 | 27249 | |
c19d1205 | 27250 | if (ext != NULL) |
34ef62f4 | 27251 | return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL); |
7ed4c4c5 | 27252 | |
c921be7d | 27253 | return TRUE; |
c19d1205 | 27254 | } |
7ed4c4c5 | 27255 | |
c19d1205 | 27256 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 27257 | return FALSE; |
7ed4c4c5 NC |
27258 | } |
27259 | ||
c921be7d | 27260 | static bfd_boolean |
17b9d67d | 27261 | arm_parse_arch (const char *str) |
7ed4c4c5 | 27262 | { |
e74cfd16 | 27263 | const struct arm_arch_option_table *opt; |
82b8a785 | 27264 | const char *ext = strchr (str, '+'); |
f3bad469 | 27265 | size_t len; |
7ed4c4c5 | 27266 | |
c19d1205 | 27267 | if (ext != NULL) |
f3bad469 | 27268 | len = ext - str; |
7ed4c4c5 | 27269 | else |
f3bad469 | 27270 | len = strlen (str); |
7ed4c4c5 | 27271 | |
f3bad469 | 27272 | if (len == 0) |
7ed4c4c5 | 27273 | { |
c19d1205 | 27274 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 27275 | return FALSE; |
7ed4c4c5 NC |
27276 | } |
27277 | ||
c19d1205 | 27278 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 27279 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 27280 | { |
e74cfd16 | 27281 | march_cpu_opt = &opt->value; |
4d354d8b TP |
27282 | if (march_ext_opt == NULL) |
27283 | march_ext_opt = XNEW (arm_feature_set); | |
27284 | *march_ext_opt = arm_arch_none; | |
e74cfd16 | 27285 | march_fpu_opt = &opt->default_fpu; |
5f4273c7 | 27286 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 27287 | |
c19d1205 | 27288 | if (ext != NULL) |
34ef62f4 AV |
27289 | return arm_parse_extension (ext, march_cpu_opt, march_ext_opt, |
27290 | opt->ext_table); | |
7ed4c4c5 | 27291 | |
c921be7d | 27292 | return TRUE; |
c19d1205 ZW |
27293 | } |
27294 | ||
27295 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 27296 | return FALSE; |
7ed4c4c5 | 27297 | } |
eb043451 | 27298 | |
c921be7d | 27299 | static bfd_boolean |
17b9d67d | 27300 | arm_parse_fpu (const char * str) |
c19d1205 | 27301 | { |
69133863 | 27302 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 27303 | |
c19d1205 ZW |
27304 | for (opt = arm_fpus; opt->name != NULL; opt++) |
27305 | if (streq (opt->name, str)) | |
27306 | { | |
e74cfd16 | 27307 | mfpu_opt = &opt->value; |
c921be7d | 27308 | return TRUE; |
c19d1205 | 27309 | } |
b99bd4ef | 27310 | |
c19d1205 | 27311 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 27312 | return FALSE; |
c19d1205 ZW |
27313 | } |
27314 | ||
c921be7d | 27315 | static bfd_boolean |
17b9d67d | 27316 | arm_parse_float_abi (const char * str) |
b99bd4ef | 27317 | { |
e74cfd16 | 27318 | const struct arm_option_value_table * opt; |
b99bd4ef | 27319 | |
c19d1205 ZW |
27320 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
27321 | if (streq (opt->name, str)) | |
27322 | { | |
27323 | mfloat_abi_opt = opt->value; | |
c921be7d | 27324 | return TRUE; |
c19d1205 | 27325 | } |
cc8a6dd0 | 27326 | |
c19d1205 | 27327 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 27328 | return FALSE; |
c19d1205 | 27329 | } |
b99bd4ef | 27330 | |
c19d1205 | 27331 | #ifdef OBJ_ELF |
c921be7d | 27332 | static bfd_boolean |
17b9d67d | 27333 | arm_parse_eabi (const char * str) |
c19d1205 | 27334 | { |
e74cfd16 | 27335 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 27336 | |
c19d1205 ZW |
27337 | for (opt = arm_eabis; opt->name != NULL; opt++) |
27338 | if (streq (opt->name, str)) | |
27339 | { | |
27340 | meabi_flags = opt->value; | |
c921be7d | 27341 | return TRUE; |
c19d1205 ZW |
27342 | } |
27343 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 27344 | return FALSE; |
c19d1205 ZW |
27345 | } |
27346 | #endif | |
cc8a6dd0 | 27347 | |
c921be7d | 27348 | static bfd_boolean |
17b9d67d | 27349 | arm_parse_it_mode (const char * str) |
e07e6e58 | 27350 | { |
c921be7d | 27351 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
27352 | |
27353 | if (streq ("arm", str)) | |
27354 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
27355 | else if (streq ("thumb", str)) | |
27356 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
27357 | else if (streq ("always", str)) | |
27358 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
27359 | else if (streq ("never", str)) | |
27360 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
27361 | else | |
27362 | { | |
27363 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
477330fc | 27364 | "arm, thumb, always, or never."), str); |
c921be7d | 27365 | ret = FALSE; |
e07e6e58 NC |
27366 | } |
27367 | ||
27368 | return ret; | |
27369 | } | |
27370 | ||
2e6976a8 | 27371 | static bfd_boolean |
17b9d67d | 27372 | arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED) |
2e6976a8 DG |
27373 | { |
27374 | codecomposer_syntax = TRUE; | |
27375 | arm_comment_chars[0] = ';'; | |
27376 | arm_line_separator_chars[0] = 0; | |
27377 | return TRUE; | |
27378 | } | |
27379 | ||
c19d1205 ZW |
27380 | struct arm_long_option_table arm_long_opts[] = |
27381 | { | |
27382 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
27383 | arm_parse_cpu, NULL}, | |
27384 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
27385 | arm_parse_arch, NULL}, | |
27386 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
27387 | arm_parse_fpu, NULL}, | |
27388 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
27389 | arm_parse_float_abi, NULL}, | |
27390 | #ifdef OBJ_ELF | |
7fac0536 | 27391 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
27392 | arm_parse_eabi, NULL}, |
27393 | #endif | |
e07e6e58 NC |
27394 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
27395 | arm_parse_it_mode, NULL}, | |
2e6976a8 DG |
27396 | {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"), |
27397 | arm_ccs_mode, NULL}, | |
c19d1205 ZW |
27398 | {NULL, NULL, 0, NULL} |
27399 | }; | |
cc8a6dd0 | 27400 | |
c19d1205 | 27401 | int |
17b9d67d | 27402 | md_parse_option (int c, const char * arg) |
c19d1205 ZW |
27403 | { |
27404 | struct arm_option_table *opt; | |
e74cfd16 | 27405 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 27406 | struct arm_long_option_table *lopt; |
b99bd4ef | 27407 | |
c19d1205 | 27408 | switch (c) |
b99bd4ef | 27409 | { |
c19d1205 ZW |
27410 | #ifdef OPTION_EB |
27411 | case OPTION_EB: | |
27412 | target_big_endian = 1; | |
27413 | break; | |
27414 | #endif | |
cc8a6dd0 | 27415 | |
c19d1205 ZW |
27416 | #ifdef OPTION_EL |
27417 | case OPTION_EL: | |
27418 | target_big_endian = 0; | |
27419 | break; | |
27420 | #endif | |
b99bd4ef | 27421 | |
845b51d6 PB |
27422 | case OPTION_FIX_V4BX: |
27423 | fix_v4bx = TRUE; | |
27424 | break; | |
27425 | ||
18a20338 CL |
27426 | #ifdef OBJ_ELF |
27427 | case OPTION_FDPIC: | |
27428 | arm_fdpic = TRUE; | |
27429 | break; | |
27430 | #endif /* OBJ_ELF */ | |
27431 | ||
c19d1205 ZW |
27432 | case 'a': |
27433 | /* Listing option. Just ignore these, we don't support additional | |
27434 | ones. */ | |
27435 | return 0; | |
b99bd4ef | 27436 | |
c19d1205 ZW |
27437 | default: |
27438 | for (opt = arm_opts; opt->option != NULL; opt++) | |
27439 | { | |
27440 | if (c == opt->option[0] | |
27441 | && ((arg == NULL && opt->option[1] == 0) | |
27442 | || streq (arg, opt->option + 1))) | |
27443 | { | |
c19d1205 | 27444 | /* If the option is deprecated, tell the user. */ |
278df34e | 27445 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
27446 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
27447 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 27448 | |
c19d1205 ZW |
27449 | if (opt->var != NULL) |
27450 | *opt->var = opt->value; | |
cc8a6dd0 | 27451 | |
c19d1205 ZW |
27452 | return 1; |
27453 | } | |
27454 | } | |
b99bd4ef | 27455 | |
e74cfd16 PB |
27456 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
27457 | { | |
27458 | if (c == fopt->option[0] | |
27459 | && ((arg == NULL && fopt->option[1] == 0) | |
27460 | || streq (arg, fopt->option + 1))) | |
27461 | { | |
e74cfd16 | 27462 | /* If the option is deprecated, tell the user. */ |
278df34e | 27463 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
27464 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
27465 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
27466 | |
27467 | if (fopt->var != NULL) | |
27468 | *fopt->var = &fopt->value; | |
27469 | ||
27470 | return 1; | |
27471 | } | |
27472 | } | |
27473 | ||
c19d1205 ZW |
27474 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
27475 | { | |
27476 | /* These options are expected to have an argument. */ | |
27477 | if (c == lopt->option[0] | |
27478 | && arg != NULL | |
27479 | && strncmp (arg, lopt->option + 1, | |
27480 | strlen (lopt->option + 1)) == 0) | |
27481 | { | |
c19d1205 | 27482 | /* If the option is deprecated, tell the user. */ |
278df34e | 27483 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
27484 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
27485 | _(lopt->deprecated)); | |
b99bd4ef | 27486 | |
c19d1205 ZW |
27487 | /* Call the sup-option parser. */ |
27488 | return lopt->func (arg + strlen (lopt->option) - 1); | |
27489 | } | |
27490 | } | |
a737bd4d | 27491 | |
c19d1205 ZW |
27492 | return 0; |
27493 | } | |
a394c00f | 27494 | |
c19d1205 ZW |
27495 | return 1; |
27496 | } | |
a394c00f | 27497 | |
c19d1205 ZW |
27498 | void |
27499 | md_show_usage (FILE * fp) | |
a394c00f | 27500 | { |
c19d1205 ZW |
27501 | struct arm_option_table *opt; |
27502 | struct arm_long_option_table *lopt; | |
a394c00f | 27503 | |
c19d1205 | 27504 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 27505 | |
c19d1205 ZW |
27506 | for (opt = arm_opts; opt->option != NULL; opt++) |
27507 | if (opt->help != NULL) | |
27508 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 27509 | |
c19d1205 ZW |
27510 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
27511 | if (lopt->help != NULL) | |
27512 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 27513 | |
c19d1205 ZW |
27514 | #ifdef OPTION_EB |
27515 | fprintf (fp, _("\ | |
27516 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
27517 | #endif |
27518 | ||
c19d1205 ZW |
27519 | #ifdef OPTION_EL |
27520 | fprintf (fp, _("\ | |
27521 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 27522 | #endif |
845b51d6 PB |
27523 | |
27524 | fprintf (fp, _("\ | |
27525 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
18a20338 CL |
27526 | |
27527 | #ifdef OBJ_ELF | |
27528 | fprintf (fp, _("\ | |
27529 | --fdpic generate an FDPIC object file\n")); | |
27530 | #endif /* OBJ_ELF */ | |
c19d1205 | 27531 | } |
ee065d83 | 27532 | |
ee065d83 | 27533 | #ifdef OBJ_ELF |
0198d5e6 | 27534 | |
62b3e311 PB |
27535 | typedef struct |
27536 | { | |
27537 | int val; | |
27538 | arm_feature_set flags; | |
27539 | } cpu_arch_ver_table; | |
27540 | ||
2c6b98ea TP |
27541 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted |
27542 | chronologically for architectures, with an exception for ARMv6-M and | |
27543 | ARMv6S-M due to legacy reasons. No new architecture should have a | |
27544 | special case. This allows for build attribute selection results to be | |
27545 | stable when new architectures are added. */ | |
62b3e311 PB |
27546 | static const cpu_arch_ver_table cpu_arch_ver[] = |
27547 | { | |
031254f2 AV |
27548 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1}, |
27549 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2}, | |
27550 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S}, | |
27551 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3}, | |
27552 | {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M}, | |
27553 | {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM}, | |
27554 | {TAG_CPU_ARCH_V4, ARM_ARCH_V4}, | |
27555 | {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM}, | |
27556 | {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T}, | |
27557 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM}, | |
27558 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5}, | |
27559 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM}, | |
27560 | {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T}, | |
27561 | {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP}, | |
27562 | {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE}, | |
27563 | {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ}, | |
27564 | {TAG_CPU_ARCH_V6, ARM_ARCH_V6}, | |
27565 | {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z}, | |
27566 | {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ}, | |
27567 | {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K}, | |
27568 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2}, | |
27569 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2}, | |
27570 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2}, | |
27571 | {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2}, | |
2c6b98ea TP |
27572 | |
27573 | /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as | |
27574 | always selected build attributes to match those of ARMv6-M | |
27575 | (resp. ARMv6S-M). However, due to these architectures being a strict | |
27576 | subset of ARMv7-M in terms of instructions available, ARMv7-M attributes | |
27577 | would be selected when fully respecting chronology of architectures. | |
27578 | It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and | |
27579 | move them before ARMv7 architectures. */ | |
031254f2 AV |
27580 | {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M}, |
27581 | {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM}, | |
27582 | ||
27583 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7}, | |
27584 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7A}, | |
27585 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7R}, | |
27586 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7M}, | |
27587 | {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE}, | |
27588 | {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM}, | |
27589 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8A}, | |
27590 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A}, | |
27591 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A}, | |
27592 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A}, | |
27593 | {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE}, | |
27594 | {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN}, | |
27595 | {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R}, | |
27596 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A}, | |
27597 | {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A}, | |
27598 | {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN}, | |
27599 | {-1, ARM_ARCH_NONE} | |
62b3e311 PB |
27600 | }; |
27601 | ||
ee3c0378 | 27602 | /* Set an attribute if it has not already been set by the user. */ |
0198d5e6 | 27603 | |
ee3c0378 AS |
27604 | static void |
27605 | aeabi_set_attribute_int (int tag, int value) | |
27606 | { | |
27607 | if (tag < 1 | |
27608 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
27609 | || !attributes_set_explicitly[tag]) | |
27610 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
27611 | } | |
27612 | ||
27613 | static void | |
27614 | aeabi_set_attribute_string (int tag, const char *value) | |
27615 | { | |
27616 | if (tag < 1 | |
27617 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
27618 | || !attributes_set_explicitly[tag]) | |
27619 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
27620 | } | |
27621 | ||
2c6b98ea TP |
27622 | /* Return whether features in the *NEEDED feature set are available via |
27623 | extensions for the architecture whose feature set is *ARCH_FSET. */ | |
0198d5e6 | 27624 | |
2c6b98ea TP |
27625 | static bfd_boolean |
27626 | have_ext_for_needed_feat_p (const arm_feature_set *arch_fset, | |
27627 | const arm_feature_set *needed) | |
27628 | { | |
27629 | int i, nb_allowed_archs; | |
27630 | arm_feature_set ext_fset; | |
27631 | const struct arm_option_extension_value_table *opt; | |
27632 | ||
27633 | ext_fset = arm_arch_none; | |
27634 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
27635 | { | |
27636 | /* Extension does not provide any feature we need. */ | |
27637 | if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value)) | |
27638 | continue; | |
27639 | ||
27640 | nb_allowed_archs = | |
27641 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]); | |
27642 | for (i = 0; i < nb_allowed_archs; i++) | |
27643 | { | |
27644 | /* Empty entry. */ | |
27645 | if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any)) | |
27646 | break; | |
27647 | ||
27648 | /* Extension is available, add it. */ | |
27649 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset)) | |
27650 | ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value); | |
27651 | } | |
27652 | } | |
27653 | ||
27654 | /* Can we enable all features in *needed? */ | |
27655 | return ARM_FSET_CPU_SUBSET (*needed, ext_fset); | |
27656 | } | |
27657 | ||
27658 | /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for | |
27659 | a given architecture feature set *ARCH_EXT_FSET including extension feature | |
27660 | set *EXT_FSET. Selection logic used depend on EXACT_MATCH: | |
27661 | - if true, check for an exact match of the architecture modulo extensions; | |
27662 | - otherwise, select build attribute value of the first superset | |
27663 | architecture released so that results remains stable when new architectures | |
27664 | are added. | |
27665 | For -march/-mcpu=all the build attribute value of the most featureful | |
27666 | architecture is returned. Tag_CPU_arch_profile result is returned in | |
27667 | PROFILE. */ | |
0198d5e6 | 27668 | |
2c6b98ea TP |
27669 | static int |
27670 | get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset, | |
27671 | const arm_feature_set *ext_fset, | |
27672 | char *profile, int exact_match) | |
27673 | { | |
27674 | arm_feature_set arch_fset; | |
27675 | const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL; | |
27676 | ||
27677 | /* Select most featureful architecture with all its extensions if building | |
27678 | for -march=all as the feature sets used to set build attributes. */ | |
27679 | if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any)) | |
27680 | { | |
27681 | /* Force revisiting of decision for each new architecture. */ | |
031254f2 | 27682 | gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN); |
2c6b98ea TP |
27683 | *profile = 'A'; |
27684 | return TAG_CPU_ARCH_V8; | |
27685 | } | |
27686 | ||
27687 | ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset); | |
27688 | ||
27689 | for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++) | |
27690 | { | |
27691 | arm_feature_set known_arch_fset; | |
27692 | ||
27693 | ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any); | |
27694 | if (exact_match) | |
27695 | { | |
27696 | /* Base architecture match user-specified architecture and | |
27697 | extensions, eg. ARMv6S-M matching -march=armv6-m+os. */ | |
27698 | if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset)) | |
27699 | { | |
27700 | p_ver_ret = p_ver; | |
27701 | goto found; | |
27702 | } | |
27703 | /* Base architecture match user-specified architecture only | |
27704 | (eg. ARMv6-M in the same case as above). Record it in case we | |
27705 | find a match with above condition. */ | |
27706 | else if (p_ver_ret == NULL | |
27707 | && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset)) | |
27708 | p_ver_ret = p_ver; | |
27709 | } | |
27710 | else | |
27711 | { | |
27712 | ||
27713 | /* Architecture has all features wanted. */ | |
27714 | if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset)) | |
27715 | { | |
27716 | arm_feature_set added_fset; | |
27717 | ||
27718 | /* Compute features added by this architecture over the one | |
27719 | recorded in p_ver_ret. */ | |
27720 | if (p_ver_ret != NULL) | |
27721 | ARM_CLEAR_FEATURE (added_fset, known_arch_fset, | |
27722 | p_ver_ret->flags); | |
27723 | /* First architecture that match incl. with extensions, or the | |
27724 | only difference in features over the recorded match is | |
27725 | features that were optional and are now mandatory. */ | |
27726 | if (p_ver_ret == NULL | |
27727 | || ARM_FSET_CPU_SUBSET (added_fset, arch_fset)) | |
27728 | { | |
27729 | p_ver_ret = p_ver; | |
27730 | goto found; | |
27731 | } | |
27732 | } | |
27733 | else if (p_ver_ret == NULL) | |
27734 | { | |
27735 | arm_feature_set needed_ext_fset; | |
27736 | ||
27737 | ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset); | |
27738 | ||
27739 | /* Architecture has all features needed when using some | |
27740 | extensions. Record it and continue searching in case there | |
27741 | exist an architecture providing all needed features without | |
27742 | the need for extensions (eg. ARMv6S-M Vs ARMv6-M with | |
27743 | OS extension). */ | |
27744 | if (have_ext_for_needed_feat_p (&known_arch_fset, | |
27745 | &needed_ext_fset)) | |
27746 | p_ver_ret = p_ver; | |
27747 | } | |
27748 | } | |
27749 | } | |
27750 | ||
27751 | if (p_ver_ret == NULL) | |
27752 | return -1; | |
27753 | ||
27754 | found: | |
27755 | /* Tag_CPU_arch_profile. */ | |
27756 | if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a) | |
27757 | || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8) | |
27758 | || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics) | |
27759 | && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only))) | |
27760 | *profile = 'A'; | |
27761 | else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r)) | |
27762 | *profile = 'R'; | |
27763 | else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m)) | |
27764 | *profile = 'M'; | |
27765 | else | |
27766 | *profile = '\0'; | |
27767 | return p_ver_ret->val; | |
27768 | } | |
27769 | ||
ee065d83 | 27770 | /* Set the public EABI object attributes. */ |
0198d5e6 | 27771 | |
c168ce07 | 27772 | static void |
ee065d83 PB |
27773 | aeabi_set_public_attributes (void) |
27774 | { | |
b90d5ba0 | 27775 | char profile = '\0'; |
2c6b98ea | 27776 | int arch = -1; |
90ec0d68 | 27777 | int virt_sec = 0; |
bca38921 | 27778 | int fp16_optional = 0; |
2c6b98ea TP |
27779 | int skip_exact_match = 0; |
27780 | arm_feature_set flags, flags_arch, flags_ext; | |
ee065d83 | 27781 | |
54bab281 TP |
27782 | /* Autodetection mode, choose the architecture based the instructions |
27783 | actually used. */ | |
27784 | if (no_cpu_selected ()) | |
27785 | { | |
27786 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); | |
ddd7f988 | 27787 | |
54bab281 TP |
27788 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) |
27789 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
ddd7f988 | 27790 | |
54bab281 TP |
27791 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) |
27792 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
ddd7f988 | 27793 | |
54bab281 | 27794 | /* Code run during relaxation relies on selected_cpu being set. */ |
4d354d8b TP |
27795 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
27796 | flags_ext = arm_arch_none; | |
27797 | ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext); | |
27798 | selected_ext = flags_ext; | |
54bab281 TP |
27799 | selected_cpu = flags; |
27800 | } | |
27801 | /* Otherwise, choose the architecture based on the capabilities of the | |
27802 | requested cpu. */ | |
27803 | else | |
4d354d8b TP |
27804 | { |
27805 | ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext); | |
27806 | ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any); | |
27807 | flags_ext = selected_ext; | |
27808 | flags = selected_cpu; | |
27809 | } | |
27810 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu); | |
7f78eb34 | 27811 | |
ddd7f988 | 27812 | /* Allow the user to override the reported architecture. */ |
4d354d8b | 27813 | if (!ARM_FEATURE_ZERO (selected_object_arch)) |
7a1d4c38 | 27814 | { |
4d354d8b | 27815 | ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any); |
2c6b98ea | 27816 | flags_ext = arm_arch_none; |
7a1d4c38 | 27817 | } |
2c6b98ea | 27818 | else |
4d354d8b | 27819 | skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any); |
2c6b98ea TP |
27820 | |
27821 | /* When this function is run again after relaxation has happened there is no | |
27822 | way to determine whether an architecture or CPU was specified by the user: | |
27823 | - selected_cpu is set above for relaxation to work; | |
27824 | - march_cpu_opt is not set if only -mcpu or .cpu is used; | |
27825 | - mcpu_cpu_opt is set to arm_arch_any for autodetection. | |
27826 | Therefore, if not in -march=all case we first try an exact match and fall | |
27827 | back to autodetection. */ | |
27828 | if (!skip_exact_match) | |
27829 | arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1); | |
27830 | if (arch == -1) | |
27831 | arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0); | |
27832 | if (arch == -1) | |
27833 | as_bad (_("no architecture contains all the instructions used\n")); | |
9e3c6df6 | 27834 | |
ee065d83 PB |
27835 | /* Tag_CPU_name. */ |
27836 | if (selected_cpu_name[0]) | |
27837 | { | |
91d6fa6a | 27838 | char *q; |
ee065d83 | 27839 | |
91d6fa6a NC |
27840 | q = selected_cpu_name; |
27841 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
27842 | { |
27843 | int i; | |
5f4273c7 | 27844 | |
91d6fa6a NC |
27845 | q += 4; |
27846 | for (i = 0; q[i]; i++) | |
27847 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 27848 | } |
91d6fa6a | 27849 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 27850 | } |
62f3b8c8 | 27851 | |
ee065d83 | 27852 | /* Tag_CPU_arch. */ |
ee3c0378 | 27853 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 27854 | |
62b3e311 | 27855 | /* Tag_CPU_arch_profile. */ |
69239280 MGD |
27856 | if (profile != '\0') |
27857 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 27858 | |
15afaa63 | 27859 | /* Tag_DSP_extension. */ |
4d354d8b | 27860 | if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp)) |
6c290d53 | 27861 | aeabi_set_attribute_int (Tag_DSP_extension, 1); |
15afaa63 | 27862 | |
2c6b98ea | 27863 | ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any); |
ee065d83 | 27864 | /* Tag_ARM_ISA_use. */ |
ee3c0378 | 27865 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
2c6b98ea | 27866 | || ARM_FEATURE_ZERO (flags_arch)) |
ee3c0378 | 27867 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); |
62f3b8c8 | 27868 | |
ee065d83 | 27869 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 | 27870 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
2c6b98ea | 27871 | || ARM_FEATURE_ZERO (flags_arch)) |
4ed7ed8d TP |
27872 | { |
27873 | int thumb_isa_use; | |
27874 | ||
27875 | if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) | |
16a1fa25 | 27876 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)) |
4ed7ed8d TP |
27877 | thumb_isa_use = 3; |
27878 | else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2)) | |
27879 | thumb_isa_use = 2; | |
27880 | else | |
27881 | thumb_isa_use = 1; | |
27882 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use); | |
27883 | } | |
62f3b8c8 | 27884 | |
ee065d83 | 27885 | /* Tag_VFP_arch. */ |
a715796b TG |
27886 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd)) |
27887 | aeabi_set_attribute_int (Tag_VFP_arch, | |
27888 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
27889 | ? 7 : 8); | |
bca38921 | 27890 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
62f3b8c8 PB |
27891 | aeabi_set_attribute_int (Tag_VFP_arch, |
27892 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
27893 | ? 5 : 6); | |
27894 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
bca38921 MGD |
27895 | { |
27896 | fp16_optional = 1; | |
27897 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
27898 | } | |
ada65aa3 | 27899 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
27900 | { |
27901 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
27902 | fp16_optional = 1; | |
27903 | } | |
ee3c0378 AS |
27904 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) |
27905 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
27906 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
477330fc | 27907 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) |
ee3c0378 | 27908 | aeabi_set_attribute_int (Tag_VFP_arch, 1); |
62f3b8c8 | 27909 | |
4547cb56 NC |
27910 | /* Tag_ABI_HardFP_use. */ |
27911 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
27912 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
27913 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
27914 | ||
ee065d83 | 27915 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
27916 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
27917 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
27918 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
27919 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 27920 | |
ee3c0378 | 27921 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
9411fd44 MW |
27922 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1)) |
27923 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4); | |
27924 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8)) | |
bca38921 MGD |
27925 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3); |
27926 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) | |
27927 | { | |
27928 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)) | |
27929 | { | |
27930 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2); | |
27931 | } | |
27932 | else | |
27933 | { | |
27934 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); | |
27935 | fp16_optional = 1; | |
27936 | } | |
27937 | } | |
fa94de6b | 27938 | |
ee3c0378 | 27939 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 27940 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 27941 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 27942 | |
69239280 MGD |
27943 | /* Tag_DIV_use. |
27944 | ||
27945 | We set Tag_DIV_use to two when integer divide instructions have been used | |
27946 | in ARM state, or when Thumb integer divide instructions have been used, | |
27947 | but we have no architecture profile set, nor have we any ARM instructions. | |
27948 | ||
4ed7ed8d TP |
27949 | For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied |
27950 | by the base architecture. | |
bca38921 | 27951 | |
69239280 | 27952 | For new architectures we will have to check these tests. */ |
031254f2 | 27953 | gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN); |
4ed7ed8d TP |
27954 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
27955 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
bca38921 MGD |
27956 | aeabi_set_attribute_int (Tag_DIV_use, 0); |
27957 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv) | |
27958 | || (profile == '\0' | |
27959 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_div) | |
27960 | && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))) | |
eea54501 | 27961 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
27962 | |
27963 | /* Tag_MP_extension_use. */ | |
27964 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
27965 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
27966 | |
27967 | /* Tag Virtualization_use. */ | |
27968 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
27969 | virt_sec |= 1; |
27970 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
27971 | virt_sec |= 2; | |
27972 | if (virt_sec != 0) | |
27973 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
ee065d83 PB |
27974 | } |
27975 | ||
c168ce07 TP |
27976 | /* Post relaxation hook. Recompute ARM attributes now that relaxation is |
27977 | finished and free extension feature bits which will not be used anymore. */ | |
0198d5e6 | 27978 | |
c168ce07 TP |
27979 | void |
27980 | arm_md_post_relax (void) | |
27981 | { | |
27982 | aeabi_set_public_attributes (); | |
4d354d8b TP |
27983 | XDELETE (mcpu_ext_opt); |
27984 | mcpu_ext_opt = NULL; | |
27985 | XDELETE (march_ext_opt); | |
27986 | march_ext_opt = NULL; | |
c168ce07 TP |
27987 | } |
27988 | ||
104d59d1 | 27989 | /* Add the default contents for the .ARM.attributes section. */ |
0198d5e6 | 27990 | |
ee065d83 PB |
27991 | void |
27992 | arm_md_end (void) | |
27993 | { | |
ee065d83 PB |
27994 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
27995 | return; | |
27996 | ||
27997 | aeabi_set_public_attributes (); | |
ee065d83 | 27998 | } |
8463be01 | 27999 | #endif /* OBJ_ELF */ |
ee065d83 | 28000 | |
ee065d83 PB |
28001 | /* Parse a .cpu directive. */ |
28002 | ||
28003 | static void | |
28004 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
28005 | { | |
e74cfd16 | 28006 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
28007 | char *name; |
28008 | char saved_char; | |
28009 | ||
28010 | name = input_line_pointer; | |
5f4273c7 | 28011 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
28012 | input_line_pointer++; |
28013 | saved_char = *input_line_pointer; | |
28014 | *input_line_pointer = 0; | |
28015 | ||
28016 | /* Skip the first "all" entry. */ | |
28017 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
28018 | if (streq (opt->name, name)) | |
28019 | { | |
4d354d8b TP |
28020 | selected_arch = opt->value; |
28021 | selected_ext = opt->ext; | |
28022 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); | |
ee065d83 | 28023 | if (opt->canonical_name) |
5f4273c7 | 28024 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
28025 | else |
28026 | { | |
28027 | int i; | |
28028 | for (i = 0; opt->name[i]; i++) | |
28029 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 28030 | |
ee065d83 PB |
28031 | selected_cpu_name[i] = 0; |
28032 | } | |
4d354d8b TP |
28033 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
28034 | ||
ee065d83 PB |
28035 | *input_line_pointer = saved_char; |
28036 | demand_empty_rest_of_line (); | |
28037 | return; | |
28038 | } | |
28039 | as_bad (_("unknown cpu `%s'"), name); | |
28040 | *input_line_pointer = saved_char; | |
28041 | ignore_rest_of_line (); | |
28042 | } | |
28043 | ||
ee065d83 PB |
28044 | /* Parse a .arch directive. */ |
28045 | ||
28046 | static void | |
28047 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
28048 | { | |
e74cfd16 | 28049 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
28050 | char saved_char; |
28051 | char *name; | |
28052 | ||
28053 | name = input_line_pointer; | |
5f4273c7 | 28054 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
28055 | input_line_pointer++; |
28056 | saved_char = *input_line_pointer; | |
28057 | *input_line_pointer = 0; | |
28058 | ||
28059 | /* Skip the first "all" entry. */ | |
28060 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
28061 | if (streq (opt->name, name)) | |
28062 | { | |
4d354d8b TP |
28063 | selected_arch = opt->value; |
28064 | selected_ext = arm_arch_none; | |
28065 | selected_cpu = selected_arch; | |
5f4273c7 | 28066 | strcpy (selected_cpu_name, opt->name); |
4d354d8b | 28067 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); |
ee065d83 PB |
28068 | *input_line_pointer = saved_char; |
28069 | demand_empty_rest_of_line (); | |
28070 | return; | |
28071 | } | |
28072 | ||
28073 | as_bad (_("unknown architecture `%s'\n"), name); | |
28074 | *input_line_pointer = saved_char; | |
28075 | ignore_rest_of_line (); | |
28076 | } | |
28077 | ||
7a1d4c38 PB |
28078 | /* Parse a .object_arch directive. */ |
28079 | ||
28080 | static void | |
28081 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
28082 | { | |
28083 | const struct arm_arch_option_table *opt; | |
28084 | char saved_char; | |
28085 | char *name; | |
28086 | ||
28087 | name = input_line_pointer; | |
5f4273c7 | 28088 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
28089 | input_line_pointer++; |
28090 | saved_char = *input_line_pointer; | |
28091 | *input_line_pointer = 0; | |
28092 | ||
28093 | /* Skip the first "all" entry. */ | |
28094 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
28095 | if (streq (opt->name, name)) | |
28096 | { | |
4d354d8b | 28097 | selected_object_arch = opt->value; |
7a1d4c38 PB |
28098 | *input_line_pointer = saved_char; |
28099 | demand_empty_rest_of_line (); | |
28100 | return; | |
28101 | } | |
28102 | ||
28103 | as_bad (_("unknown architecture `%s'\n"), name); | |
28104 | *input_line_pointer = saved_char; | |
28105 | ignore_rest_of_line (); | |
28106 | } | |
28107 | ||
69133863 MGD |
28108 | /* Parse a .arch_extension directive. */ |
28109 | ||
28110 | static void | |
28111 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
28112 | { | |
28113 | const struct arm_option_extension_value_table *opt; | |
28114 | char saved_char; | |
28115 | char *name; | |
28116 | int adding_value = 1; | |
28117 | ||
28118 | name = input_line_pointer; | |
28119 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
28120 | input_line_pointer++; | |
28121 | saved_char = *input_line_pointer; | |
28122 | *input_line_pointer = 0; | |
28123 | ||
28124 | if (strlen (name) >= 2 | |
28125 | && strncmp (name, "no", 2) == 0) | |
28126 | { | |
28127 | adding_value = 0; | |
28128 | name += 2; | |
28129 | } | |
28130 | ||
28131 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
28132 | if (streq (opt->name, name)) | |
28133 | { | |
d942732e TP |
28134 | int i, nb_allowed_archs = |
28135 | sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]); | |
28136 | for (i = 0; i < nb_allowed_archs; i++) | |
28137 | { | |
28138 | /* Empty entry. */ | |
4d354d8b | 28139 | if (ARM_CPU_IS_ANY (opt->allowed_archs[i])) |
d942732e | 28140 | continue; |
4d354d8b | 28141 | if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch)) |
d942732e TP |
28142 | break; |
28143 | } | |
28144 | ||
28145 | if (i == nb_allowed_archs) | |
69133863 MGD |
28146 | { |
28147 | as_bad (_("architectural extension `%s' is not allowed for the " | |
28148 | "current base architecture"), name); | |
28149 | break; | |
28150 | } | |
28151 | ||
28152 | if (adding_value) | |
4d354d8b | 28153 | ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext, |
5a70a223 | 28154 | opt->merge_value); |
69133863 | 28155 | else |
4d354d8b | 28156 | ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value); |
69133863 | 28157 | |
4d354d8b TP |
28158 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext); |
28159 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
69133863 MGD |
28160 | *input_line_pointer = saved_char; |
28161 | demand_empty_rest_of_line (); | |
3d030cdb TP |
28162 | /* Allowing Thumb division instructions for ARMv7 in autodetection rely |
28163 | on this return so that duplicate extensions (extensions with the | |
28164 | same name as a previous extension in the list) are not considered | |
28165 | for command-line parsing. */ | |
69133863 MGD |
28166 | return; |
28167 | } | |
28168 | ||
28169 | if (opt->name == NULL) | |
e673710a | 28170 | as_bad (_("unknown architecture extension `%s'\n"), name); |
69133863 MGD |
28171 | |
28172 | *input_line_pointer = saved_char; | |
28173 | ignore_rest_of_line (); | |
28174 | } | |
28175 | ||
ee065d83 PB |
28176 | /* Parse a .fpu directive. */ |
28177 | ||
28178 | static void | |
28179 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
28180 | { | |
69133863 | 28181 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
28182 | char saved_char; |
28183 | char *name; | |
28184 | ||
28185 | name = input_line_pointer; | |
5f4273c7 | 28186 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
28187 | input_line_pointer++; |
28188 | saved_char = *input_line_pointer; | |
28189 | *input_line_pointer = 0; | |
5f4273c7 | 28190 | |
ee065d83 PB |
28191 | for (opt = arm_fpus; opt->name != NULL; opt++) |
28192 | if (streq (opt->name, name)) | |
28193 | { | |
4d354d8b TP |
28194 | selected_fpu = opt->value; |
28195 | #ifndef CPU_DEFAULT | |
28196 | if (no_cpu_selected ()) | |
28197 | ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu); | |
28198 | else | |
28199 | #endif | |
28200 | ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu); | |
ee065d83 PB |
28201 | *input_line_pointer = saved_char; |
28202 | demand_empty_rest_of_line (); | |
28203 | return; | |
28204 | } | |
28205 | ||
28206 | as_bad (_("unknown floating point format `%s'\n"), name); | |
28207 | *input_line_pointer = saved_char; | |
28208 | ignore_rest_of_line (); | |
28209 | } | |
ee065d83 | 28210 | |
794ba86a | 28211 | /* Copy symbol information. */ |
f31fef98 | 28212 | |
794ba86a DJ |
28213 | void |
28214 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
28215 | { | |
28216 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
28217 | } | |
e04befd0 | 28218 | |
f31fef98 | 28219 | #ifdef OBJ_ELF |
e04befd0 AS |
28220 | /* Given a symbolic attribute NAME, return the proper integer value. |
28221 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 28222 | |
e04befd0 AS |
28223 | int |
28224 | arm_convert_symbolic_attribute (const char *name) | |
28225 | { | |
f31fef98 NC |
28226 | static const struct |
28227 | { | |
28228 | const char * name; | |
28229 | const int tag; | |
28230 | } | |
28231 | attribute_table[] = | |
28232 | { | |
28233 | /* When you modify this table you should | |
28234 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 28235 | #define T(tag) {#tag, tag} |
f31fef98 NC |
28236 | T (Tag_CPU_raw_name), |
28237 | T (Tag_CPU_name), | |
28238 | T (Tag_CPU_arch), | |
28239 | T (Tag_CPU_arch_profile), | |
28240 | T (Tag_ARM_ISA_use), | |
28241 | T (Tag_THUMB_ISA_use), | |
75375b3e | 28242 | T (Tag_FP_arch), |
f31fef98 NC |
28243 | T (Tag_VFP_arch), |
28244 | T (Tag_WMMX_arch), | |
28245 | T (Tag_Advanced_SIMD_arch), | |
28246 | T (Tag_PCS_config), | |
28247 | T (Tag_ABI_PCS_R9_use), | |
28248 | T (Tag_ABI_PCS_RW_data), | |
28249 | T (Tag_ABI_PCS_RO_data), | |
28250 | T (Tag_ABI_PCS_GOT_use), | |
28251 | T (Tag_ABI_PCS_wchar_t), | |
28252 | T (Tag_ABI_FP_rounding), | |
28253 | T (Tag_ABI_FP_denormal), | |
28254 | T (Tag_ABI_FP_exceptions), | |
28255 | T (Tag_ABI_FP_user_exceptions), | |
28256 | T (Tag_ABI_FP_number_model), | |
75375b3e | 28257 | T (Tag_ABI_align_needed), |
f31fef98 | 28258 | T (Tag_ABI_align8_needed), |
75375b3e | 28259 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
28260 | T (Tag_ABI_align8_preserved), |
28261 | T (Tag_ABI_enum_size), | |
28262 | T (Tag_ABI_HardFP_use), | |
28263 | T (Tag_ABI_VFP_args), | |
28264 | T (Tag_ABI_WMMX_args), | |
28265 | T (Tag_ABI_optimization_goals), | |
28266 | T (Tag_ABI_FP_optimization_goals), | |
28267 | T (Tag_compatibility), | |
28268 | T (Tag_CPU_unaligned_access), | |
75375b3e | 28269 | T (Tag_FP_HP_extension), |
f31fef98 NC |
28270 | T (Tag_VFP_HP_extension), |
28271 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
28272 | T (Tag_MPextension_use), |
28273 | T (Tag_DIV_use), | |
f31fef98 NC |
28274 | T (Tag_nodefaults), |
28275 | T (Tag_also_compatible_with), | |
28276 | T (Tag_conformance), | |
28277 | T (Tag_T2EE_use), | |
28278 | T (Tag_Virtualization_use), | |
15afaa63 | 28279 | T (Tag_DSP_extension), |
cd21e546 | 28280 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 28281 | #undef T |
f31fef98 | 28282 | }; |
e04befd0 AS |
28283 | unsigned int i; |
28284 | ||
28285 | if (name == NULL) | |
28286 | return -1; | |
28287 | ||
f31fef98 | 28288 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 28289 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
28290 | return attribute_table[i].tag; |
28291 | ||
28292 | return -1; | |
28293 | } | |
267bf995 | 28294 | |
93ef582d NC |
28295 | /* Apply sym value for relocations only in the case that they are for |
28296 | local symbols in the same segment as the fixup and you have the | |
28297 | respective architectural feature for blx and simple switches. */ | |
0198d5e6 | 28298 | |
267bf995 | 28299 | int |
93ef582d | 28300 | arm_apply_sym_value (struct fix * fixP, segT this_seg) |
267bf995 RR |
28301 | { |
28302 | if (fixP->fx_addsy | |
28303 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
93ef582d NC |
28304 | /* PR 17444: If the local symbol is in a different section then a reloc |
28305 | will always be generated for it, so applying the symbol value now | |
28306 | will result in a double offset being stored in the relocation. */ | |
28307 | && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg) | |
34e77a92 | 28308 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)) |
267bf995 RR |
28309 | { |
28310 | switch (fixP->fx_r_type) | |
28311 | { | |
28312 | case BFD_RELOC_ARM_PCREL_BLX: | |
28313 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
28314 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
28315 | return 1; | |
28316 | break; | |
28317 | ||
28318 | case BFD_RELOC_ARM_PCREL_CALL: | |
28319 | case BFD_RELOC_THUMB_PCREL_BLX: | |
28320 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
93ef582d | 28321 | return 1; |
267bf995 RR |
28322 | break; |
28323 | ||
28324 | default: | |
28325 | break; | |
28326 | } | |
28327 | ||
28328 | } | |
28329 | return 0; | |
28330 | } | |
f31fef98 | 28331 | #endif /* OBJ_ELF */ |