Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
6f2750fe | 2 | Copyright (C) 1994-2016 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 | ||
8b1ad454 NC |
78 | #endif /* OBJ_ELF */ |
79 | ||
4962c51a MS |
80 | /* Results from operand parsing worker functions. */ |
81 | ||
82 | typedef enum | |
83 | { | |
84 | PARSE_OPERAND_SUCCESS, | |
85 | PARSE_OPERAND_FAIL, | |
86 | PARSE_OPERAND_FAIL_NO_BACKTRACK | |
87 | } parse_operand_result; | |
88 | ||
33a392fb PB |
89 | enum arm_float_abi |
90 | { | |
91 | ARM_FLOAT_ABI_HARD, | |
92 | ARM_FLOAT_ABI_SOFTFP, | |
93 | ARM_FLOAT_ABI_SOFT | |
94 | }; | |
95 | ||
c19d1205 | 96 | /* Types of processor to assemble for. */ |
b99bd4ef | 97 | #ifndef CPU_DEFAULT |
8a59fff3 | 98 | /* The code that was here used to select a default CPU depending on compiler |
fa94de6b | 99 | pre-defines which were only present when doing native builds, thus |
8a59fff3 MGD |
100 | changing gas' default behaviour depending upon the build host. |
101 | ||
102 | If you have a target that requires a default CPU option then the you | |
103 | should define CPU_DEFAULT here. */ | |
b99bd4ef NC |
104 | #endif |
105 | ||
106 | #ifndef FPU_DEFAULT | |
c820d418 MM |
107 | # ifdef TE_LINUX |
108 | # define FPU_DEFAULT FPU_ARCH_FPA | |
109 | # elif defined (TE_NetBSD) | |
110 | # ifdef OBJ_ELF | |
111 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
112 | # else | |
113 | /* Legacy a.out format. */ | |
114 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
115 | # endif | |
4e7fd91e PB |
116 | # elif defined (TE_VXWORKS) |
117 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
118 | # else |
119 | /* For backwards compatibility, default to FPA. */ | |
120 | # define FPU_DEFAULT FPU_ARCH_FPA | |
121 | # endif | |
122 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 123 | |
c19d1205 | 124 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 125 | |
e74cfd16 PB |
126 | static arm_feature_set cpu_variant; |
127 | static arm_feature_set arm_arch_used; | |
128 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 129 | |
b99bd4ef | 130 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
131 | static int uses_apcs_26 = FALSE; |
132 | static int atpcs = FALSE; | |
b34976b6 AM |
133 | static int support_interwork = FALSE; |
134 | static int uses_apcs_float = FALSE; | |
c19d1205 | 135 | static int pic_code = FALSE; |
845b51d6 | 136 | static int fix_v4bx = FALSE; |
278df34e NS |
137 | /* Warn on using deprecated features. */ |
138 | static int warn_on_deprecated = TRUE; | |
139 | ||
2e6976a8 DG |
140 | /* Understand CodeComposer Studio assembly syntax. */ |
141 | bfd_boolean codecomposer_syntax = FALSE; | |
03b1477f RE |
142 | |
143 | /* Variables that we set while parsing command-line options. Once all | |
144 | options have been read we re-process these values to set the real | |
145 | assembly flags. */ | |
e74cfd16 PB |
146 | static const arm_feature_set *legacy_cpu = NULL; |
147 | static const arm_feature_set *legacy_fpu = NULL; | |
148 | ||
149 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
150 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
151 | static const arm_feature_set *march_cpu_opt = NULL; | |
152 | static const arm_feature_set *march_fpu_opt = NULL; | |
153 | static const arm_feature_set *mfpu_opt = NULL; | |
7a1d4c38 | 154 | static const arm_feature_set *object_arch = NULL; |
e74cfd16 PB |
155 | |
156 | /* Constants for known architecture features. */ | |
157 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
158 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
159 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
5287ad62 JB |
160 | static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3; |
161 | static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1; | |
e74cfd16 PB |
162 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; |
163 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
164 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
165 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
166 | ||
167 | #ifdef CPU_DEFAULT | |
168 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
169 | #endif | |
170 | ||
823d2571 TG |
171 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1); |
172 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1); | |
173 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S); | |
174 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3); | |
175 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M); | |
176 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4); | |
177 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T); | |
178 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5); | |
e74cfd16 | 179 | static const arm_feature_set arm_ext_v4t_5 = |
823d2571 TG |
180 | ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5); |
181 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T); | |
182 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E); | |
183 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP); | |
184 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J); | |
185 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6); | |
186 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K); | |
187 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2); | |
188 | static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M); | |
189 | static const arm_feature_set arm_ext_v6_notm = | |
190 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM); | |
191 | static const arm_feature_set arm_ext_v6_dsp = | |
192 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP); | |
193 | static const arm_feature_set arm_ext_barrier = | |
194 | ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER); | |
195 | static const arm_feature_set arm_ext_msr = | |
196 | ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR); | |
197 | static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV); | |
198 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7); | |
199 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A); | |
200 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R); | |
201 | static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M); | |
202 | static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8); | |
7e806470 | 203 | static const arm_feature_set arm_ext_m = |
4ed7ed8d | 204 | ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, ARM_EXT2_V8M); |
823d2571 TG |
205 | static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP); |
206 | static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC); | |
207 | static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS); | |
208 | static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV); | |
209 | static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT); | |
ddfded2f | 210 | static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN); |
4ed7ed8d | 211 | static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M); |
ff8646ee TP |
212 | static const arm_feature_set arm_ext_v6t2_v8m = |
213 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M); | |
4ed7ed8d TP |
214 | /* Instructions shared between ARMv8-A and ARMv8-M. */ |
215 | static const arm_feature_set arm_ext_atomics = | |
216 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS); | |
105bde57 MW |
217 | static const arm_feature_set arm_ext_v8_2 = |
218 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A); | |
b8ec4e87 JW |
219 | /* FP16 instructions. */ |
220 | static const arm_feature_set arm_ext_fp16 = | |
221 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST); | |
e74cfd16 PB |
222 | |
223 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
823d2571 | 224 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1); |
e74cfd16 PB |
225 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; |
226 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
251665fc | 227 | static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY; |
e74cfd16 | 228 | |
2d447fca | 229 | static const arm_feature_set arm_cext_iwmmxt2 = |
823d2571 | 230 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2); |
e74cfd16 | 231 | static const arm_feature_set arm_cext_iwmmxt = |
823d2571 | 232 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT); |
e74cfd16 | 233 | static const arm_feature_set arm_cext_xscale = |
823d2571 | 234 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE); |
e74cfd16 | 235 | static const arm_feature_set arm_cext_maverick = |
823d2571 TG |
236 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK); |
237 | static const arm_feature_set fpu_fpa_ext_v1 = | |
238 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V1); | |
239 | static const arm_feature_set fpu_fpa_ext_v2 = | |
240 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V2); | |
e74cfd16 | 241 | static const arm_feature_set fpu_vfp_ext_v1xd = |
823d2571 TG |
242 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD); |
243 | static const arm_feature_set fpu_vfp_ext_v1 = | |
244 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1); | |
245 | static const arm_feature_set fpu_vfp_ext_v2 = | |
246 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V2); | |
247 | static const arm_feature_set fpu_vfp_ext_v3xd = | |
248 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD); | |
249 | static const arm_feature_set fpu_vfp_ext_v3 = | |
250 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3); | |
b1cc4aeb | 251 | static const arm_feature_set fpu_vfp_ext_d32 = |
823d2571 TG |
252 | ARM_FEATURE_COPROC (FPU_VFP_EXT_D32); |
253 | static const arm_feature_set fpu_neon_ext_v1 = | |
254 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1); | |
5287ad62 | 255 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = |
823d2571 TG |
256 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); |
257 | static const arm_feature_set fpu_vfp_fp16 = | |
258 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16); | |
259 | static const arm_feature_set fpu_neon_ext_fma = | |
260 | ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA); | |
261 | static const arm_feature_set fpu_vfp_ext_fma = | |
262 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA); | |
bca38921 | 263 | static const arm_feature_set fpu_vfp_ext_armv8 = |
823d2571 | 264 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8); |
a715796b | 265 | static const arm_feature_set fpu_vfp_ext_armv8xd = |
823d2571 | 266 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD); |
bca38921 | 267 | static const arm_feature_set fpu_neon_ext_armv8 = |
823d2571 | 268 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8); |
bca38921 | 269 | static const arm_feature_set fpu_crypto_ext_armv8 = |
823d2571 | 270 | ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8); |
dd5181d5 | 271 | static const arm_feature_set crc_ext_armv8 = |
823d2571 | 272 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8); |
d6b4b13e | 273 | static const arm_feature_set fpu_neon_ext_v8_1 = |
643afb90 | 274 | ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA); |
e74cfd16 | 275 | |
33a392fb | 276 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
277 | /* Record user cpu selection for object attributes. */ |
278 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 | 279 | /* Must be long enough to hold any of the names in arm_cpus. */ |
ef8e6722 | 280 | static char selected_cpu_name[20]; |
8d67f500 | 281 | |
aacf0b33 KT |
282 | extern FLONUM_TYPE generic_floating_point_number; |
283 | ||
8d67f500 NC |
284 | /* Return if no cpu was selected on command-line. */ |
285 | static bfd_boolean | |
286 | no_cpu_selected (void) | |
287 | { | |
823d2571 | 288 | return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none); |
8d67f500 NC |
289 | } |
290 | ||
7cc69913 | 291 | #ifdef OBJ_ELF |
deeaaff8 DJ |
292 | # ifdef EABI_DEFAULT |
293 | static int meabi_flags = EABI_DEFAULT; | |
294 | # else | |
d507cf36 | 295 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 296 | # endif |
e1da3f5b | 297 | |
ee3c0378 AS |
298 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
299 | ||
e1da3f5b | 300 | bfd_boolean |
5f4273c7 | 301 | arm_is_eabi (void) |
e1da3f5b PB |
302 | { |
303 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
304 | } | |
7cc69913 | 305 | #endif |
b99bd4ef | 306 | |
b99bd4ef | 307 | #ifdef OBJ_ELF |
c19d1205 | 308 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
309 | symbolS * GOT_symbol; |
310 | #endif | |
311 | ||
b99bd4ef NC |
312 | /* 0: assemble for ARM, |
313 | 1: assemble for Thumb, | |
314 | 2: assemble for Thumb even though target CPU does not support thumb | |
315 | instructions. */ | |
316 | static int thumb_mode = 0; | |
8dc2430f NC |
317 | /* A value distinct from the possible values for thumb_mode that we |
318 | can use to record whether thumb_mode has been copied into the | |
319 | tc_frag_data field of a frag. */ | |
320 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 321 | |
e07e6e58 NC |
322 | /* Specifies the intrinsic IT insn behavior mode. */ |
323 | enum implicit_it_mode | |
324 | { | |
325 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
326 | IMPLICIT_IT_MODE_ARM = 0x01, | |
327 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
328 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
329 | }; | |
330 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
331 | ||
c19d1205 ZW |
332 | /* If unified_syntax is true, we are processing the new unified |
333 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
334 | ||
335 | - Immediate operands do not require a # prefix. | |
336 | - Conditional affixes always appear at the end of the | |
337 | instruction. (For backward compatibility, those instructions | |
338 | that formerly had them in the middle, continue to accept them | |
339 | there.) | |
340 | - The IT instruction may appear, and if it does is validated | |
341 | against subsequent conditional affixes. It does not generate | |
342 | machine code. | |
343 | ||
344 | Important differences from the old Thumb mode: | |
345 | ||
346 | - Immediate operands do not require a # prefix. | |
347 | - Most of the V6T2 instructions are only available in unified mode. | |
348 | - The .N and .W suffixes are recognized and honored (it is an error | |
349 | if they cannot be honored). | |
350 | - All instructions set the flags if and only if they have an 's' affix. | |
351 | - Conditional affixes may be used. They are validated against | |
352 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
353 | conditional affix except in the scope of an IT instruction. */ | |
354 | ||
355 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 356 | |
bacebabc RM |
357 | /* An immediate operand can start with #, and ld*, st*, pld operands |
358 | can contain [ and ]. We need to tell APP not to elide whitespace | |
477330fc RM |
359 | before a [, which can appear as the first operand for pld. |
360 | Likewise, a { can appear as the first operand for push, pop, vld*, etc. */ | |
361 | const char arm_symbol_chars[] = "#[]{}"; | |
bacebabc | 362 | |
5287ad62 JB |
363 | enum neon_el_type |
364 | { | |
dcbf9037 | 365 | NT_invtype, |
5287ad62 JB |
366 | NT_untyped, |
367 | NT_integer, | |
368 | NT_float, | |
369 | NT_poly, | |
370 | NT_signed, | |
dcbf9037 | 371 | NT_unsigned |
5287ad62 JB |
372 | }; |
373 | ||
374 | struct neon_type_el | |
375 | { | |
376 | enum neon_el_type type; | |
377 | unsigned size; | |
378 | }; | |
379 | ||
380 | #define NEON_MAX_TYPE_ELS 4 | |
381 | ||
382 | struct neon_type | |
383 | { | |
384 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
385 | unsigned elems; | |
386 | }; | |
387 | ||
e07e6e58 NC |
388 | enum it_instruction_type |
389 | { | |
390 | OUTSIDE_IT_INSN, | |
391 | INSIDE_IT_INSN, | |
392 | INSIDE_IT_LAST_INSN, | |
393 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
477330fc | 394 | if inside, should be the last one. */ |
e07e6e58 | 395 | NEUTRAL_IT_INSN, /* This could be either inside or outside, |
477330fc | 396 | i.e. BKPT and NOP. */ |
e07e6e58 NC |
397 | IT_INSN /* The IT insn has been parsed. */ |
398 | }; | |
399 | ||
ad6cec43 MGD |
400 | /* The maximum number of operands we need. */ |
401 | #define ARM_IT_MAX_OPERANDS 6 | |
402 | ||
b99bd4ef NC |
403 | struct arm_it |
404 | { | |
c19d1205 | 405 | const char * error; |
b99bd4ef | 406 | unsigned long instruction; |
c19d1205 ZW |
407 | int size; |
408 | int size_req; | |
409 | int cond; | |
037e8744 JB |
410 | /* "uncond_value" is set to the value in place of the conditional field in |
411 | unconditional versions of the instruction, or -1 if nothing is | |
412 | appropriate. */ | |
413 | int uncond_value; | |
5287ad62 | 414 | struct neon_type vectype; |
88714cb8 DG |
415 | /* This does not indicate an actual NEON instruction, only that |
416 | the mnemonic accepts neon-style type suffixes. */ | |
417 | int is_neon; | |
0110f2b8 PB |
418 | /* Set to the opcode if the instruction needs relaxation. |
419 | Zero if the instruction is not relaxed. */ | |
420 | unsigned long relax; | |
b99bd4ef NC |
421 | struct |
422 | { | |
423 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
424 | expressionS exp; |
425 | int pc_rel; | |
b99bd4ef | 426 | } reloc; |
b99bd4ef | 427 | |
e07e6e58 NC |
428 | enum it_instruction_type it_insn_type; |
429 | ||
c19d1205 ZW |
430 | struct |
431 | { | |
432 | unsigned reg; | |
ca3f61f7 | 433 | signed int imm; |
dcbf9037 | 434 | struct neon_type_el vectype; |
ca3f61f7 NC |
435 | unsigned present : 1; /* Operand present. */ |
436 | unsigned isreg : 1; /* Operand was a register. */ | |
437 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
438 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
439 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 440 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
441 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
442 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
443 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 444 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 445 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 446 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
447 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
448 | unsigned writeback : 1; /* Operand has trailing ! */ | |
449 | unsigned preind : 1; /* Preindexed address. */ | |
450 | unsigned postind : 1; /* Postindexed address. */ | |
451 | unsigned negative : 1; /* Index register was negated. */ | |
452 | unsigned shifted : 1; /* Shift applied to operation. */ | |
453 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
ad6cec43 | 454 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
455 | }; |
456 | ||
c19d1205 | 457 | static struct arm_it inst; |
b99bd4ef NC |
458 | |
459 | #define NUM_FLOAT_VALS 8 | |
460 | ||
05d2d07e | 461 | const char * fp_const[] = |
b99bd4ef NC |
462 | { |
463 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
464 | }; | |
465 | ||
c19d1205 | 466 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
467 | #define MAX_LITTLENUMS 6 |
468 | ||
469 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
470 | ||
471 | #define FAIL (-1) | |
472 | #define SUCCESS (0) | |
473 | ||
474 | #define SUFF_S 1 | |
475 | #define SUFF_D 2 | |
476 | #define SUFF_E 3 | |
477 | #define SUFF_P 4 | |
478 | ||
c19d1205 ZW |
479 | #define CP_T_X 0x00008000 |
480 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 481 | |
c19d1205 ZW |
482 | #define CONDS_BIT 0x00100000 |
483 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
484 | |
485 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
486 | ||
487 | struct asm_cond | |
488 | { | |
d3ce72d0 | 489 | const char * template_name; |
c921be7d | 490 | unsigned long value; |
b99bd4ef NC |
491 | }; |
492 | ||
c19d1205 | 493 | #define COND_ALWAYS 0xE |
b99bd4ef | 494 | |
b99bd4ef NC |
495 | struct asm_psr |
496 | { | |
d3ce72d0 | 497 | const char * template_name; |
c921be7d | 498 | unsigned long field; |
b99bd4ef NC |
499 | }; |
500 | ||
62b3e311 PB |
501 | struct asm_barrier_opt |
502 | { | |
e797f7e0 MGD |
503 | const char * template_name; |
504 | unsigned long value; | |
505 | const arm_feature_set arch; | |
62b3e311 PB |
506 | }; |
507 | ||
2d2255b5 | 508 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
509 | #define SPSR_BIT (1 << 22) |
510 | ||
c19d1205 ZW |
511 | /* The individual PSR flag bits. */ |
512 | #define PSR_c (1 << 16) | |
513 | #define PSR_x (1 << 17) | |
514 | #define PSR_s (1 << 18) | |
515 | #define PSR_f (1 << 19) | |
b99bd4ef | 516 | |
c19d1205 | 517 | struct reloc_entry |
bfae80f2 | 518 | { |
e0471c16 | 519 | const char * name; |
c921be7d | 520 | bfd_reloc_code_real_type reloc; |
bfae80f2 RE |
521 | }; |
522 | ||
5287ad62 | 523 | enum vfp_reg_pos |
bfae80f2 | 524 | { |
5287ad62 JB |
525 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
526 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
527 | }; |
528 | ||
529 | enum vfp_ldstm_type | |
530 | { | |
531 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
532 | }; | |
533 | ||
dcbf9037 JB |
534 | /* Bits for DEFINED field in neon_typed_alias. */ |
535 | #define NTA_HASTYPE 1 | |
536 | #define NTA_HASINDEX 2 | |
537 | ||
538 | struct neon_typed_alias | |
539 | { | |
c921be7d NC |
540 | unsigned char defined; |
541 | unsigned char index; | |
542 | struct neon_type_el eltype; | |
dcbf9037 JB |
543 | }; |
544 | ||
c19d1205 ZW |
545 | /* ARM register categories. This includes coprocessor numbers and various |
546 | architecture extensions' registers. */ | |
547 | enum arm_reg_type | |
bfae80f2 | 548 | { |
c19d1205 ZW |
549 | REG_TYPE_RN, |
550 | REG_TYPE_CP, | |
551 | REG_TYPE_CN, | |
552 | REG_TYPE_FN, | |
553 | REG_TYPE_VFS, | |
554 | REG_TYPE_VFD, | |
5287ad62 | 555 | REG_TYPE_NQ, |
037e8744 | 556 | REG_TYPE_VFSD, |
5287ad62 | 557 | REG_TYPE_NDQ, |
037e8744 | 558 | REG_TYPE_NSDQ, |
c19d1205 ZW |
559 | REG_TYPE_VFC, |
560 | REG_TYPE_MVF, | |
561 | REG_TYPE_MVD, | |
562 | REG_TYPE_MVFX, | |
563 | REG_TYPE_MVDX, | |
564 | REG_TYPE_MVAX, | |
565 | REG_TYPE_DSPSC, | |
566 | REG_TYPE_MMXWR, | |
567 | REG_TYPE_MMXWC, | |
568 | REG_TYPE_MMXWCG, | |
569 | REG_TYPE_XSCALE, | |
90ec0d68 | 570 | REG_TYPE_RNB |
bfae80f2 RE |
571 | }; |
572 | ||
dcbf9037 JB |
573 | /* Structure for a hash table entry for a register. |
574 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
575 | information which states whether a vector type or index is specified (for a | |
576 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
577 | struct reg_entry |
578 | { | |
c921be7d | 579 | const char * name; |
90ec0d68 | 580 | unsigned int number; |
c921be7d NC |
581 | unsigned char type; |
582 | unsigned char builtin; | |
583 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
584 | }; |
585 | ||
c19d1205 | 586 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 587 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
588 | { |
589 | N_("ARM register expected"), | |
590 | N_("bad or missing co-processor number"), | |
591 | N_("co-processor register expected"), | |
592 | N_("FPA register expected"), | |
593 | N_("VFP single precision register expected"), | |
5287ad62 JB |
594 | N_("VFP/Neon double precision register expected"), |
595 | N_("Neon quad precision register expected"), | |
037e8744 | 596 | N_("VFP single or double precision register expected"), |
5287ad62 | 597 | N_("Neon double or quad precision register expected"), |
037e8744 | 598 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
599 | N_("VFP system register expected"), |
600 | N_("Maverick MVF register expected"), | |
601 | N_("Maverick MVD register expected"), | |
602 | N_("Maverick MVFX register expected"), | |
603 | N_("Maverick MVDX register expected"), | |
604 | N_("Maverick MVAX register expected"), | |
605 | N_("Maverick DSPSC register expected"), | |
606 | N_("iWMMXt data register expected"), | |
607 | N_("iWMMXt control register expected"), | |
608 | N_("iWMMXt scalar register expected"), | |
609 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
610 | }; |
611 | ||
c19d1205 | 612 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 613 | #define REG_R12 12 |
c19d1205 ZW |
614 | #define REG_SP 13 |
615 | #define REG_LR 14 | |
616 | #define REG_PC 15 | |
404ff6b5 | 617 | |
b99bd4ef NC |
618 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
619 | take 2: */ | |
c19d1205 | 620 | #define INSN_SIZE 4 |
b99bd4ef NC |
621 | |
622 | struct asm_opcode | |
623 | { | |
624 | /* Basic string to match. */ | |
d3ce72d0 | 625 | const char * template_name; |
c19d1205 ZW |
626 | |
627 | /* Parameters to instruction. */ | |
5be8be5d | 628 | unsigned int operands[8]; |
c19d1205 ZW |
629 | |
630 | /* Conditional tag - see opcode_lookup. */ | |
631 | unsigned int tag : 4; | |
b99bd4ef NC |
632 | |
633 | /* Basic instruction code. */ | |
c19d1205 | 634 | unsigned int avalue : 28; |
b99bd4ef | 635 | |
c19d1205 ZW |
636 | /* Thumb-format instruction code. */ |
637 | unsigned int tvalue; | |
b99bd4ef | 638 | |
90e4755a | 639 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
640 | const arm_feature_set * avariant; |
641 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
642 | |
643 | /* Function to call to encode instruction in ARM format. */ | |
644 | void (* aencode) (void); | |
b99bd4ef | 645 | |
c19d1205 ZW |
646 | /* Function to call to encode instruction in Thumb format. */ |
647 | void (* tencode) (void); | |
b99bd4ef NC |
648 | }; |
649 | ||
a737bd4d NC |
650 | /* Defines for various bits that we will want to toggle. */ |
651 | #define INST_IMMEDIATE 0x02000000 | |
652 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 653 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
654 | #define SHIFT_BY_REG 0x00000010 |
655 | #define PRE_INDEX 0x01000000 | |
656 | #define INDEX_UP 0x00800000 | |
657 | #define WRITE_BACK 0x00200000 | |
658 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 659 | #define CPSI_MMOD 0x00020000 |
90e4755a | 660 | |
a737bd4d NC |
661 | #define LITERAL_MASK 0xf000f000 |
662 | #define OPCODE_MASK 0xfe1fffff | |
663 | #define V4_STR_BIT 0x00000020 | |
8335d6aa | 664 | #define VLDR_VMOV_SAME 0x0040f000 |
90e4755a | 665 | |
efd81785 PB |
666 | #define T2_SUBS_PC_LR 0xf3de8f00 |
667 | ||
a737bd4d | 668 | #define DATA_OP_SHIFT 21 |
90e4755a | 669 | |
ef8d22e6 PB |
670 | #define T2_OPCODE_MASK 0xfe1fffff |
671 | #define T2_DATA_OP_SHIFT 21 | |
672 | ||
6530b175 NC |
673 | #define A_COND_MASK 0xf0000000 |
674 | #define A_PUSH_POP_OP_MASK 0x0fff0000 | |
675 | ||
676 | /* Opcodes for pushing/poping registers to/from the stack. */ | |
677 | #define A1_OPCODE_PUSH 0x092d0000 | |
678 | #define A2_OPCODE_PUSH 0x052d0004 | |
679 | #define A2_OPCODE_POP 0x049d0004 | |
680 | ||
a737bd4d NC |
681 | /* Codes to distinguish the arithmetic instructions. */ |
682 | #define OPCODE_AND 0 | |
683 | #define OPCODE_EOR 1 | |
684 | #define OPCODE_SUB 2 | |
685 | #define OPCODE_RSB 3 | |
686 | #define OPCODE_ADD 4 | |
687 | #define OPCODE_ADC 5 | |
688 | #define OPCODE_SBC 6 | |
689 | #define OPCODE_RSC 7 | |
690 | #define OPCODE_TST 8 | |
691 | #define OPCODE_TEQ 9 | |
692 | #define OPCODE_CMP 10 | |
693 | #define OPCODE_CMN 11 | |
694 | #define OPCODE_ORR 12 | |
695 | #define OPCODE_MOV 13 | |
696 | #define OPCODE_BIC 14 | |
697 | #define OPCODE_MVN 15 | |
90e4755a | 698 | |
ef8d22e6 PB |
699 | #define T2_OPCODE_AND 0 |
700 | #define T2_OPCODE_BIC 1 | |
701 | #define T2_OPCODE_ORR 2 | |
702 | #define T2_OPCODE_ORN 3 | |
703 | #define T2_OPCODE_EOR 4 | |
704 | #define T2_OPCODE_ADD 8 | |
705 | #define T2_OPCODE_ADC 10 | |
706 | #define T2_OPCODE_SBC 11 | |
707 | #define T2_OPCODE_SUB 13 | |
708 | #define T2_OPCODE_RSB 14 | |
709 | ||
a737bd4d NC |
710 | #define T_OPCODE_MUL 0x4340 |
711 | #define T_OPCODE_TST 0x4200 | |
712 | #define T_OPCODE_CMN 0x42c0 | |
713 | #define T_OPCODE_NEG 0x4240 | |
714 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 715 | |
a737bd4d NC |
716 | #define T_OPCODE_ADD_R3 0x1800 |
717 | #define T_OPCODE_SUB_R3 0x1a00 | |
718 | #define T_OPCODE_ADD_HI 0x4400 | |
719 | #define T_OPCODE_ADD_ST 0xb000 | |
720 | #define T_OPCODE_SUB_ST 0xb080 | |
721 | #define T_OPCODE_ADD_SP 0xa800 | |
722 | #define T_OPCODE_ADD_PC 0xa000 | |
723 | #define T_OPCODE_ADD_I8 0x3000 | |
724 | #define T_OPCODE_SUB_I8 0x3800 | |
725 | #define T_OPCODE_ADD_I3 0x1c00 | |
726 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 727 | |
a737bd4d NC |
728 | #define T_OPCODE_ASR_R 0x4100 |
729 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
730 | #define T_OPCODE_LSR_R 0x40c0 |
731 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
732 | #define T_OPCODE_ASR_I 0x1000 |
733 | #define T_OPCODE_LSL_I 0x0000 | |
734 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 735 | |
a737bd4d NC |
736 | #define T_OPCODE_MOV_I8 0x2000 |
737 | #define T_OPCODE_CMP_I8 0x2800 | |
738 | #define T_OPCODE_CMP_LR 0x4280 | |
739 | #define T_OPCODE_MOV_HR 0x4600 | |
740 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 741 | |
a737bd4d NC |
742 | #define T_OPCODE_LDR_PC 0x4800 |
743 | #define T_OPCODE_LDR_SP 0x9800 | |
744 | #define T_OPCODE_STR_SP 0x9000 | |
745 | #define T_OPCODE_LDR_IW 0x6800 | |
746 | #define T_OPCODE_STR_IW 0x6000 | |
747 | #define T_OPCODE_LDR_IH 0x8800 | |
748 | #define T_OPCODE_STR_IH 0x8000 | |
749 | #define T_OPCODE_LDR_IB 0x7800 | |
750 | #define T_OPCODE_STR_IB 0x7000 | |
751 | #define T_OPCODE_LDR_RW 0x5800 | |
752 | #define T_OPCODE_STR_RW 0x5000 | |
753 | #define T_OPCODE_LDR_RH 0x5a00 | |
754 | #define T_OPCODE_STR_RH 0x5200 | |
755 | #define T_OPCODE_LDR_RB 0x5c00 | |
756 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 757 | |
a737bd4d NC |
758 | #define T_OPCODE_PUSH 0xb400 |
759 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 760 | |
2fc8bdac | 761 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 762 | |
a737bd4d | 763 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 764 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 765 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 766 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
767 | |
768 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 769 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
770 | #define BAD_PC _("r15 not allowed here") |
771 | #define BAD_COND _("instruction cannot be conditional") | |
772 | #define BAD_OVERLAP _("registers may not be the same") | |
773 | #define BAD_HIREG _("lo register required") | |
774 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 775 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
776 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
777 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 778 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
779 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
780 | #define BAD_IT_COND _("incorrect condition in IT block") | |
781 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 782 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
783 | #define BAD_PC_ADDRESSING \ |
784 | _("cannot use register index with PC-relative addressing") | |
785 | #define BAD_PC_WRITEBACK \ | |
786 | _("cannot use writeback with PC-relative addressing") | |
9db2f6b4 RL |
787 | #define BAD_RANGE _("branch out of range") |
788 | #define BAD_FP16 _("selected processor does not support fp16 instruction") | |
dd5181d5 | 789 | #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour") |
a9f02af8 | 790 | #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only") |
c19d1205 | 791 | |
c921be7d NC |
792 | static struct hash_control * arm_ops_hsh; |
793 | static struct hash_control * arm_cond_hsh; | |
794 | static struct hash_control * arm_shift_hsh; | |
795 | static struct hash_control * arm_psr_hsh; | |
796 | static struct hash_control * arm_v7m_psr_hsh; | |
797 | static struct hash_control * arm_reg_hsh; | |
798 | static struct hash_control * arm_reloc_hsh; | |
799 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 800 | |
b99bd4ef NC |
801 | /* Stuff needed to resolve the label ambiguity |
802 | As: | |
803 | ... | |
804 | label: <insn> | |
805 | may differ from: | |
806 | ... | |
807 | label: | |
5f4273c7 | 808 | <insn> */ |
b99bd4ef NC |
809 | |
810 | symbolS * last_label_seen; | |
b34976b6 | 811 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 812 | |
3d0c9500 NC |
813 | /* Literal pool structure. Held on a per-section |
814 | and per-sub-section basis. */ | |
a737bd4d | 815 | |
c19d1205 | 816 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 817 | typedef struct literal_pool |
b99bd4ef | 818 | { |
c921be7d NC |
819 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
820 | unsigned int next_free_entry; | |
821 | unsigned int id; | |
822 | symbolS * symbol; | |
823 | segT section; | |
824 | subsegT sub_section; | |
a8040cf2 NC |
825 | #ifdef OBJ_ELF |
826 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
827 | #endif | |
c921be7d | 828 | struct literal_pool * next; |
8335d6aa | 829 | unsigned int alignment; |
3d0c9500 | 830 | } literal_pool; |
b99bd4ef | 831 | |
3d0c9500 NC |
832 | /* Pointer to a linked list of literal pools. */ |
833 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 834 | |
2e6976a8 DG |
835 | typedef enum asmfunc_states |
836 | { | |
837 | OUTSIDE_ASMFUNC, | |
838 | WAITING_ASMFUNC_NAME, | |
839 | WAITING_ENDASMFUNC | |
840 | } asmfunc_states; | |
841 | ||
842 | static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC; | |
843 | ||
e07e6e58 NC |
844 | #ifdef OBJ_ELF |
845 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
846 | #else | |
847 | static struct current_it now_it; | |
848 | #endif | |
849 | ||
850 | static inline int | |
851 | now_it_compatible (int cond) | |
852 | { | |
853 | return (cond & ~1) == (now_it.cc & ~1); | |
854 | } | |
855 | ||
856 | static inline int | |
857 | conditional_insn (void) | |
858 | { | |
859 | return inst.cond != COND_ALWAYS; | |
860 | } | |
861 | ||
862 | static int in_it_block (void); | |
863 | ||
864 | static int handle_it_state (void); | |
865 | ||
866 | static void force_automatic_it_block_close (void); | |
867 | ||
c921be7d NC |
868 | static void it_fsm_post_encode (void); |
869 | ||
e07e6e58 NC |
870 | #define set_it_insn_type(type) \ |
871 | do \ | |
872 | { \ | |
873 | inst.it_insn_type = type; \ | |
874 | if (handle_it_state () == FAIL) \ | |
477330fc | 875 | return; \ |
e07e6e58 NC |
876 | } \ |
877 | while (0) | |
878 | ||
c921be7d NC |
879 | #define set_it_insn_type_nonvoid(type, failret) \ |
880 | do \ | |
881 | { \ | |
882 | inst.it_insn_type = type; \ | |
883 | if (handle_it_state () == FAIL) \ | |
477330fc | 884 | return failret; \ |
c921be7d NC |
885 | } \ |
886 | while(0) | |
887 | ||
e07e6e58 NC |
888 | #define set_it_insn_type_last() \ |
889 | do \ | |
890 | { \ | |
891 | if (inst.cond == COND_ALWAYS) \ | |
477330fc | 892 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ |
e07e6e58 | 893 | else \ |
477330fc | 894 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ |
e07e6e58 NC |
895 | } \ |
896 | while (0) | |
897 | ||
c19d1205 | 898 | /* Pure syntax. */ |
b99bd4ef | 899 | |
c19d1205 ZW |
900 | /* This array holds the chars that always start a comment. If the |
901 | pre-processor is disabled, these aren't very useful. */ | |
2e6976a8 | 902 | char arm_comment_chars[] = "@"; |
3d0c9500 | 903 | |
c19d1205 ZW |
904 | /* This array holds the chars that only start a comment at the beginning of |
905 | a line. If the line seems to have the form '# 123 filename' | |
906 | .line and .file directives will appear in the pre-processed output. */ | |
907 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
908 | first line of the input file. This is because the compiler outputs | |
909 | #NO_APP at the beginning of its output. */ | |
910 | /* Also note that comments like this one will always work. */ | |
911 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 912 | |
2e6976a8 | 913 | char arm_line_separator_chars[] = ";"; |
b99bd4ef | 914 | |
c19d1205 ZW |
915 | /* Chars that can be used to separate mant |
916 | from exp in floating point numbers. */ | |
917 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 918 | |
c19d1205 ZW |
919 | /* Chars that mean this number is a floating point constant. */ |
920 | /* As in 0f12.456 */ | |
921 | /* or 0d1.2345e12 */ | |
b99bd4ef | 922 | |
c19d1205 | 923 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 924 | |
c19d1205 ZW |
925 | /* Prefix characters that indicate the start of an immediate |
926 | value. */ | |
927 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 928 | |
c19d1205 ZW |
929 | /* Separator character handling. */ |
930 | ||
931 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
932 | ||
933 | static inline int | |
934 | skip_past_char (char ** str, char c) | |
935 | { | |
8ab8155f NC |
936 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
937 | skip_whitespace (*str); | |
427d0db6 | 938 | |
c19d1205 ZW |
939 | if (**str == c) |
940 | { | |
941 | (*str)++; | |
942 | return SUCCESS; | |
3d0c9500 | 943 | } |
c19d1205 ZW |
944 | else |
945 | return FAIL; | |
946 | } | |
c921be7d | 947 | |
c19d1205 | 948 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 949 | |
c19d1205 ZW |
950 | /* Arithmetic expressions (possibly involving symbols). */ |
951 | ||
952 | /* Return TRUE if anything in the expression is a bignum. */ | |
953 | ||
954 | static int | |
955 | walk_no_bignums (symbolS * sp) | |
956 | { | |
957 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
958 | return 1; | |
959 | ||
960 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 961 | { |
c19d1205 ZW |
962 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
963 | || (symbol_get_value_expression (sp)->X_op_symbol | |
964 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
965 | } |
966 | ||
c19d1205 | 967 | return 0; |
3d0c9500 NC |
968 | } |
969 | ||
c19d1205 ZW |
970 | static int in_my_get_expression = 0; |
971 | ||
972 | /* Third argument to my_get_expression. */ | |
973 | #define GE_NO_PREFIX 0 | |
974 | #define GE_IMM_PREFIX 1 | |
975 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
976 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
977 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
978 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 979 | |
b99bd4ef | 980 | static int |
c19d1205 | 981 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 982 | { |
c19d1205 ZW |
983 | char * save_in; |
984 | segT seg; | |
b99bd4ef | 985 | |
c19d1205 ZW |
986 | /* In unified syntax, all prefixes are optional. */ |
987 | if (unified_syntax) | |
5287ad62 | 988 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
477330fc | 989 | : GE_OPT_PREFIX; |
b99bd4ef | 990 | |
c19d1205 | 991 | switch (prefix_mode) |
b99bd4ef | 992 | { |
c19d1205 ZW |
993 | case GE_NO_PREFIX: break; |
994 | case GE_IMM_PREFIX: | |
995 | if (!is_immediate_prefix (**str)) | |
996 | { | |
997 | inst.error = _("immediate expression requires a # prefix"); | |
998 | return FAIL; | |
999 | } | |
1000 | (*str)++; | |
1001 | break; | |
1002 | case GE_OPT_PREFIX: | |
5287ad62 | 1003 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
1004 | if (is_immediate_prefix (**str)) |
1005 | (*str)++; | |
1006 | break; | |
1007 | default: abort (); | |
1008 | } | |
b99bd4ef | 1009 | |
c19d1205 | 1010 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 1011 | |
c19d1205 ZW |
1012 | save_in = input_line_pointer; |
1013 | input_line_pointer = *str; | |
1014 | in_my_get_expression = 1; | |
1015 | seg = expression (ep); | |
1016 | in_my_get_expression = 0; | |
1017 | ||
f86adc07 | 1018 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 1019 | { |
f86adc07 | 1020 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
1021 | *str = input_line_pointer; |
1022 | input_line_pointer = save_in; | |
1023 | if (inst.error == NULL) | |
f86adc07 NS |
1024 | inst.error = (ep->X_op == O_absent |
1025 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
1026 | return 1; |
1027 | } | |
b99bd4ef | 1028 | |
c19d1205 ZW |
1029 | #ifdef OBJ_AOUT |
1030 | if (seg != absolute_section | |
1031 | && seg != text_section | |
1032 | && seg != data_section | |
1033 | && seg != bss_section | |
1034 | && seg != undefined_section) | |
1035 | { | |
1036 | inst.error = _("bad segment"); | |
1037 | *str = input_line_pointer; | |
1038 | input_line_pointer = save_in; | |
1039 | return 1; | |
b99bd4ef | 1040 | } |
87975d2a AM |
1041 | #else |
1042 | (void) seg; | |
c19d1205 | 1043 | #endif |
b99bd4ef | 1044 | |
c19d1205 ZW |
1045 | /* Get rid of any bignums now, so that we don't generate an error for which |
1046 | we can't establish a line number later on. Big numbers are never valid | |
1047 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
1048 | if (prefix_mode != GE_OPT_PREFIX_BIG |
1049 | && (ep->X_op == O_big | |
477330fc | 1050 | || (ep->X_add_symbol |
5287ad62 | 1051 | && (walk_no_bignums (ep->X_add_symbol) |
477330fc | 1052 | || (ep->X_op_symbol |
5287ad62 | 1053 | && walk_no_bignums (ep->X_op_symbol)))))) |
c19d1205 ZW |
1054 | { |
1055 | inst.error = _("invalid constant"); | |
1056 | *str = input_line_pointer; | |
1057 | input_line_pointer = save_in; | |
1058 | return 1; | |
1059 | } | |
b99bd4ef | 1060 | |
c19d1205 ZW |
1061 | *str = input_line_pointer; |
1062 | input_line_pointer = save_in; | |
1063 | return 0; | |
b99bd4ef NC |
1064 | } |
1065 | ||
c19d1205 ZW |
1066 | /* Turn a string in input_line_pointer into a floating point constant |
1067 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1068 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1069 | returned, or NULL on OK. | |
b99bd4ef | 1070 | |
c19d1205 ZW |
1071 | Note that fp constants aren't represent in the normal way on the ARM. |
1072 | In big endian mode, things are as expected. However, in little endian | |
1073 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
1074 | within the words. For example, (double) 1.1 in big endian mode is | |
1075 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
1076 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 1077 | |
c19d1205 | 1078 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1079 | |
c19d1205 ZW |
1080 | char * |
1081 | md_atof (int type, char * litP, int * sizeP) | |
1082 | { | |
1083 | int prec; | |
1084 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1085 | char *t; | |
1086 | int i; | |
b99bd4ef | 1087 | |
c19d1205 ZW |
1088 | switch (type) |
1089 | { | |
1090 | case 'f': | |
1091 | case 'F': | |
1092 | case 's': | |
1093 | case 'S': | |
1094 | prec = 2; | |
1095 | break; | |
b99bd4ef | 1096 | |
c19d1205 ZW |
1097 | case 'd': |
1098 | case 'D': | |
1099 | case 'r': | |
1100 | case 'R': | |
1101 | prec = 4; | |
1102 | break; | |
b99bd4ef | 1103 | |
c19d1205 ZW |
1104 | case 'x': |
1105 | case 'X': | |
499ac353 | 1106 | prec = 5; |
c19d1205 | 1107 | break; |
b99bd4ef | 1108 | |
c19d1205 ZW |
1109 | case 'p': |
1110 | case 'P': | |
499ac353 | 1111 | prec = 5; |
c19d1205 | 1112 | break; |
a737bd4d | 1113 | |
c19d1205 ZW |
1114 | default: |
1115 | *sizeP = 0; | |
499ac353 | 1116 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1117 | } |
b99bd4ef | 1118 | |
c19d1205 ZW |
1119 | t = atof_ieee (input_line_pointer, type, words); |
1120 | if (t) | |
1121 | input_line_pointer = t; | |
499ac353 | 1122 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1123 | |
c19d1205 ZW |
1124 | if (target_big_endian) |
1125 | { | |
1126 | for (i = 0; i < prec; i++) | |
1127 | { | |
499ac353 NC |
1128 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1129 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1130 | } |
1131 | } | |
1132 | else | |
1133 | { | |
e74cfd16 | 1134 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1135 | for (i = prec - 1; i >= 0; i--) |
1136 | { | |
499ac353 NC |
1137 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1138 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1139 | } |
1140 | else | |
1141 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1142 | For an 8 byte float the order is 1 0 3 2. */ | |
1143 | for (i = 0; i < prec; i += 2) | |
1144 | { | |
499ac353 NC |
1145 | md_number_to_chars (litP, (valueT) words[i + 1], |
1146 | sizeof (LITTLENUM_TYPE)); | |
1147 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1148 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1149 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1150 | } |
1151 | } | |
b99bd4ef | 1152 | |
499ac353 | 1153 | return NULL; |
c19d1205 | 1154 | } |
b99bd4ef | 1155 | |
c19d1205 ZW |
1156 | /* We handle all bad expressions here, so that we can report the faulty |
1157 | instruction in the error message. */ | |
1158 | void | |
91d6fa6a | 1159 | md_operand (expressionS * exp) |
c19d1205 ZW |
1160 | { |
1161 | if (in_my_get_expression) | |
91d6fa6a | 1162 | exp->X_op = O_illegal; |
b99bd4ef NC |
1163 | } |
1164 | ||
c19d1205 | 1165 | /* Immediate values. */ |
b99bd4ef | 1166 | |
c19d1205 ZW |
1167 | /* Generic immediate-value read function for use in directives. |
1168 | Accepts anything that 'expression' can fold to a constant. | |
1169 | *val receives the number. */ | |
1170 | #ifdef OBJ_ELF | |
1171 | static int | |
1172 | immediate_for_directive (int *val) | |
b99bd4ef | 1173 | { |
c19d1205 ZW |
1174 | expressionS exp; |
1175 | exp.X_op = O_illegal; | |
b99bd4ef | 1176 | |
c19d1205 ZW |
1177 | if (is_immediate_prefix (*input_line_pointer)) |
1178 | { | |
1179 | input_line_pointer++; | |
1180 | expression (&exp); | |
1181 | } | |
b99bd4ef | 1182 | |
c19d1205 ZW |
1183 | if (exp.X_op != O_constant) |
1184 | { | |
1185 | as_bad (_("expected #constant")); | |
1186 | ignore_rest_of_line (); | |
1187 | return FAIL; | |
1188 | } | |
1189 | *val = exp.X_add_number; | |
1190 | return SUCCESS; | |
b99bd4ef | 1191 | } |
c19d1205 | 1192 | #endif |
b99bd4ef | 1193 | |
c19d1205 | 1194 | /* Register parsing. */ |
b99bd4ef | 1195 | |
c19d1205 ZW |
1196 | /* Generic register parser. CCP points to what should be the |
1197 | beginning of a register name. If it is indeed a valid register | |
1198 | name, advance CCP over it and return the reg_entry structure; | |
1199 | otherwise return NULL. Does not issue diagnostics. */ | |
1200 | ||
1201 | static struct reg_entry * | |
1202 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1203 | { |
c19d1205 ZW |
1204 | char *start = *ccp; |
1205 | char *p; | |
1206 | struct reg_entry *reg; | |
b99bd4ef | 1207 | |
477330fc RM |
1208 | skip_whitespace (start); |
1209 | ||
c19d1205 ZW |
1210 | #ifdef REGISTER_PREFIX |
1211 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1212 | return NULL; |
c19d1205 ZW |
1213 | start++; |
1214 | #endif | |
1215 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1216 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1217 | start++; | |
1218 | #endif | |
b99bd4ef | 1219 | |
c19d1205 ZW |
1220 | p = start; |
1221 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1222 | return NULL; | |
b99bd4ef | 1223 | |
c19d1205 ZW |
1224 | do |
1225 | p++; | |
1226 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1227 | ||
1228 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1229 | ||
1230 | if (!reg) | |
1231 | return NULL; | |
1232 | ||
1233 | *ccp = p; | |
1234 | return reg; | |
b99bd4ef NC |
1235 | } |
1236 | ||
1237 | static int | |
dcbf9037 | 1238 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
477330fc | 1239 | enum arm_reg_type type) |
b99bd4ef | 1240 | { |
c19d1205 ZW |
1241 | /* Alternative syntaxes are accepted for a few register classes. */ |
1242 | switch (type) | |
1243 | { | |
1244 | case REG_TYPE_MVF: | |
1245 | case REG_TYPE_MVD: | |
1246 | case REG_TYPE_MVFX: | |
1247 | case REG_TYPE_MVDX: | |
1248 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1249 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1250 | return reg->number; |
1251 | break; | |
69b97547 | 1252 | |
c19d1205 ZW |
1253 | case REG_TYPE_CP: |
1254 | /* For backward compatibility, a bare number is valid here. */ | |
1255 | { | |
1256 | unsigned long processor = strtoul (start, ccp, 10); | |
1257 | if (*ccp != start && processor <= 15) | |
1258 | return processor; | |
1259 | } | |
6057a28f | 1260 | |
c19d1205 ZW |
1261 | case REG_TYPE_MMXWC: |
1262 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1263 | instructions that take WC registers. */ | |
79134647 | 1264 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1265 | return reg->number; |
6057a28f | 1266 | break; |
c19d1205 | 1267 | |
6057a28f | 1268 | default: |
c19d1205 | 1269 | break; |
6057a28f NC |
1270 | } |
1271 | ||
dcbf9037 JB |
1272 | return FAIL; |
1273 | } | |
1274 | ||
1275 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1276 | return value is the register number or FAIL. */ | |
1277 | ||
1278 | static int | |
1279 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1280 | { | |
1281 | char *start = *ccp; | |
1282 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1283 | int ret; | |
1284 | ||
1285 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1286 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1287 | return FAIL; | |
1288 | ||
1289 | if (reg && reg->type == type) | |
1290 | return reg->number; | |
1291 | ||
1292 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1293 | return ret; | |
1294 | ||
c19d1205 ZW |
1295 | *ccp = start; |
1296 | return FAIL; | |
1297 | } | |
69b97547 | 1298 | |
dcbf9037 JB |
1299 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1300 | character. Does no verification at this stage that the type fits the opcode | |
1301 | properly. E.g., | |
1302 | ||
1303 | .i32.i32.s16 | |
1304 | .s32.f32 | |
1305 | .u16 | |
1306 | ||
1307 | Can all be legally parsed by this function. | |
1308 | ||
1309 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1310 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1311 | type, FAIL if not. */ | |
1312 | ||
1313 | static int | |
1314 | parse_neon_type (struct neon_type *type, char **str) | |
1315 | { | |
1316 | char *ptr = *str; | |
1317 | ||
1318 | if (type) | |
1319 | type->elems = 0; | |
1320 | ||
1321 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1322 | { | |
1323 | enum neon_el_type thistype = NT_untyped; | |
1324 | unsigned thissize = -1u; | |
1325 | ||
1326 | if (*ptr != '.') | |
1327 | break; | |
1328 | ||
1329 | ptr++; | |
1330 | ||
1331 | /* Just a size without an explicit type. */ | |
1332 | if (ISDIGIT (*ptr)) | |
1333 | goto parsesize; | |
1334 | ||
1335 | switch (TOLOWER (*ptr)) | |
1336 | { | |
1337 | case 'i': thistype = NT_integer; break; | |
1338 | case 'f': thistype = NT_float; break; | |
1339 | case 'p': thistype = NT_poly; break; | |
1340 | case 's': thistype = NT_signed; break; | |
1341 | case 'u': thistype = NT_unsigned; break; | |
477330fc RM |
1342 | case 'd': |
1343 | thistype = NT_float; | |
1344 | thissize = 64; | |
1345 | ptr++; | |
1346 | goto done; | |
dcbf9037 JB |
1347 | default: |
1348 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1349 | return FAIL; | |
1350 | } | |
1351 | ||
1352 | ptr++; | |
1353 | ||
1354 | /* .f is an abbreviation for .f32. */ | |
1355 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1356 | thissize = 32; | |
1357 | else | |
1358 | { | |
1359 | parsesize: | |
1360 | thissize = strtoul (ptr, &ptr, 10); | |
1361 | ||
1362 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
477330fc RM |
1363 | && thissize != 64) |
1364 | { | |
1365 | as_bad (_("bad size %d in type specifier"), thissize); | |
dcbf9037 JB |
1366 | return FAIL; |
1367 | } | |
1368 | } | |
1369 | ||
037e8744 | 1370 | done: |
dcbf9037 | 1371 | if (type) |
477330fc RM |
1372 | { |
1373 | type->el[type->elems].type = thistype; | |
dcbf9037 JB |
1374 | type->el[type->elems].size = thissize; |
1375 | type->elems++; | |
1376 | } | |
1377 | } | |
1378 | ||
1379 | /* Empty/missing type is not a successful parse. */ | |
1380 | if (type->elems == 0) | |
1381 | return FAIL; | |
1382 | ||
1383 | *str = ptr; | |
1384 | ||
1385 | return SUCCESS; | |
1386 | } | |
1387 | ||
1388 | /* Errors may be set multiple times during parsing or bit encoding | |
1389 | (particularly in the Neon bits), but usually the earliest error which is set | |
1390 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1391 | errors by calling this function. */ | |
1392 | ||
1393 | static void | |
1394 | first_error (const char *err) | |
1395 | { | |
1396 | if (!inst.error) | |
1397 | inst.error = err; | |
1398 | } | |
1399 | ||
1400 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1401 | static int | |
1402 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1403 | { | |
1404 | char *str = *ccp; | |
1405 | struct neon_type optype; | |
1406 | ||
1407 | if (*str == '.') | |
1408 | { | |
1409 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
477330fc RM |
1410 | { |
1411 | if (optype.elems == 1) | |
1412 | *vectype = optype.el[0]; | |
1413 | else | |
1414 | { | |
1415 | first_error (_("only one type should be specified for operand")); | |
1416 | return FAIL; | |
1417 | } | |
1418 | } | |
dcbf9037 | 1419 | else |
477330fc RM |
1420 | { |
1421 | first_error (_("vector type expected")); | |
1422 | return FAIL; | |
1423 | } | |
dcbf9037 JB |
1424 | } |
1425 | else | |
1426 | return FAIL; | |
5f4273c7 | 1427 | |
dcbf9037 | 1428 | *ccp = str; |
5f4273c7 | 1429 | |
dcbf9037 JB |
1430 | return SUCCESS; |
1431 | } | |
1432 | ||
1433 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1434 | a 4-bit integer. */ | |
1435 | ||
1436 | #define NEON_ALL_LANES 15 | |
1437 | #define NEON_INTERLEAVE_LANES 14 | |
1438 | ||
1439 | /* Parse either a register or a scalar, with an optional type. Return the | |
1440 | register number, and optionally fill in the actual type of the register | |
1441 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1442 | type/index information in *TYPEINFO. */ | |
1443 | ||
1444 | static int | |
1445 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
477330fc RM |
1446 | enum arm_reg_type *rtype, |
1447 | struct neon_typed_alias *typeinfo) | |
dcbf9037 JB |
1448 | { |
1449 | char *str = *ccp; | |
1450 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1451 | struct neon_typed_alias atype; | |
1452 | struct neon_type_el parsetype; | |
1453 | ||
1454 | atype.defined = 0; | |
1455 | atype.index = -1; | |
1456 | atype.eltype.type = NT_invtype; | |
1457 | atype.eltype.size = -1; | |
1458 | ||
1459 | /* Try alternate syntax for some types of register. Note these are mutually | |
1460 | exclusive with the Neon syntax extensions. */ | |
1461 | if (reg == NULL) | |
1462 | { | |
1463 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1464 | if (altreg != FAIL) | |
477330fc | 1465 | *ccp = str; |
dcbf9037 | 1466 | if (typeinfo) |
477330fc | 1467 | *typeinfo = atype; |
dcbf9037 JB |
1468 | return altreg; |
1469 | } | |
1470 | ||
037e8744 JB |
1471 | /* Undo polymorphism when a set of register types may be accepted. */ |
1472 | if ((type == REG_TYPE_NDQ | |
1473 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1474 | || (type == REG_TYPE_VFSD | |
477330fc | 1475 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) |
037e8744 | 1476 | || (type == REG_TYPE_NSDQ |
477330fc RM |
1477 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD |
1478 | || reg->type == REG_TYPE_NQ)) | |
f512f76f NC |
1479 | || (type == REG_TYPE_MMXWC |
1480 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1481 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1482 | |
1483 | if (type != reg->type) | |
1484 | return FAIL; | |
1485 | ||
1486 | if (reg->neon) | |
1487 | atype = *reg->neon; | |
5f4273c7 | 1488 | |
dcbf9037 JB |
1489 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1490 | { | |
1491 | if ((atype.defined & NTA_HASTYPE) != 0) | |
477330fc RM |
1492 | { |
1493 | first_error (_("can't redefine type for operand")); | |
1494 | return FAIL; | |
1495 | } | |
dcbf9037 JB |
1496 | atype.defined |= NTA_HASTYPE; |
1497 | atype.eltype = parsetype; | |
1498 | } | |
5f4273c7 | 1499 | |
dcbf9037 JB |
1500 | if (skip_past_char (&str, '[') == SUCCESS) |
1501 | { | |
1502 | if (type != REG_TYPE_VFD) | |
477330fc RM |
1503 | { |
1504 | first_error (_("only D registers may be indexed")); | |
1505 | return FAIL; | |
1506 | } | |
5f4273c7 | 1507 | |
dcbf9037 | 1508 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
1509 | { |
1510 | first_error (_("can't change index for operand")); | |
1511 | return FAIL; | |
1512 | } | |
dcbf9037 JB |
1513 | |
1514 | atype.defined |= NTA_HASINDEX; | |
1515 | ||
1516 | if (skip_past_char (&str, ']') == SUCCESS) | |
477330fc | 1517 | atype.index = NEON_ALL_LANES; |
dcbf9037 | 1518 | else |
477330fc RM |
1519 | { |
1520 | expressionS exp; | |
dcbf9037 | 1521 | |
477330fc | 1522 | my_get_expression (&exp, &str, GE_NO_PREFIX); |
dcbf9037 | 1523 | |
477330fc RM |
1524 | if (exp.X_op != O_constant) |
1525 | { | |
1526 | first_error (_("constant expression required")); | |
1527 | return FAIL; | |
1528 | } | |
dcbf9037 | 1529 | |
477330fc RM |
1530 | if (skip_past_char (&str, ']') == FAIL) |
1531 | return FAIL; | |
dcbf9037 | 1532 | |
477330fc RM |
1533 | atype.index = exp.X_add_number; |
1534 | } | |
dcbf9037 | 1535 | } |
5f4273c7 | 1536 | |
dcbf9037 JB |
1537 | if (typeinfo) |
1538 | *typeinfo = atype; | |
5f4273c7 | 1539 | |
dcbf9037 JB |
1540 | if (rtype) |
1541 | *rtype = type; | |
5f4273c7 | 1542 | |
dcbf9037 | 1543 | *ccp = str; |
5f4273c7 | 1544 | |
dcbf9037 JB |
1545 | return reg->number; |
1546 | } | |
1547 | ||
1548 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1549 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1550 | register (e.g. Neon double or quad reg when either has been requested). | |
1551 | - If this is a Neon vector type with additional type information, fill | |
1552 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1553 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1554 | |
1555 | static int | |
1556 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
477330fc | 1557 | enum arm_reg_type *rtype, struct neon_type_el *vectype) |
dcbf9037 JB |
1558 | { |
1559 | struct neon_typed_alias atype; | |
1560 | char *str = *ccp; | |
1561 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1562 | ||
1563 | if (reg == FAIL) | |
1564 | return FAIL; | |
1565 | ||
0855e32b NS |
1566 | /* Do not allow regname(... to parse as a register. */ |
1567 | if (*str == '(') | |
1568 | return FAIL; | |
1569 | ||
dcbf9037 JB |
1570 | /* Do not allow a scalar (reg+index) to parse as a register. */ |
1571 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1572 | { | |
1573 | first_error (_("register operand expected, but got scalar")); | |
1574 | return FAIL; | |
1575 | } | |
1576 | ||
1577 | if (vectype) | |
1578 | *vectype = atype.eltype; | |
1579 | ||
1580 | *ccp = str; | |
1581 | ||
1582 | return reg; | |
1583 | } | |
1584 | ||
1585 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1586 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1587 | ||
5287ad62 JB |
1588 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1589 | have enough information to be able to do a good job bounds-checking. So, we | |
1590 | just do easy checks here, and do further checks later. */ | |
1591 | ||
1592 | static int | |
dcbf9037 | 1593 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1594 | { |
dcbf9037 | 1595 | int reg; |
5287ad62 | 1596 | char *str = *ccp; |
dcbf9037 | 1597 | struct neon_typed_alias atype; |
5f4273c7 | 1598 | |
dcbf9037 | 1599 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1600 | |
dcbf9037 | 1601 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1602 | return FAIL; |
5f4273c7 | 1603 | |
dcbf9037 | 1604 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1605 | { |
dcbf9037 | 1606 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1607 | return FAIL; |
1608 | } | |
dcbf9037 | 1609 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1610 | { |
dcbf9037 | 1611 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1612 | return FAIL; |
1613 | } | |
5f4273c7 | 1614 | |
dcbf9037 JB |
1615 | if (type) |
1616 | *type = atype.eltype; | |
5f4273c7 | 1617 | |
5287ad62 | 1618 | *ccp = str; |
5f4273c7 | 1619 | |
dcbf9037 | 1620 | return reg * 16 + atype.index; |
5287ad62 JB |
1621 | } |
1622 | ||
c19d1205 | 1623 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1624 | |
c19d1205 ZW |
1625 | static long |
1626 | parse_reg_list (char ** strp) | |
1627 | { | |
1628 | char * str = * strp; | |
1629 | long range = 0; | |
1630 | int another_range; | |
a737bd4d | 1631 | |
c19d1205 ZW |
1632 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1633 | do | |
6057a28f | 1634 | { |
477330fc RM |
1635 | skip_whitespace (str); |
1636 | ||
c19d1205 | 1637 | another_range = 0; |
a737bd4d | 1638 | |
c19d1205 ZW |
1639 | if (*str == '{') |
1640 | { | |
1641 | int in_range = 0; | |
1642 | int cur_reg = -1; | |
a737bd4d | 1643 | |
c19d1205 ZW |
1644 | str++; |
1645 | do | |
1646 | { | |
1647 | int reg; | |
6057a28f | 1648 | |
dcbf9037 | 1649 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1650 | { |
dcbf9037 | 1651 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1652 | return FAIL; |
1653 | } | |
a737bd4d | 1654 | |
c19d1205 ZW |
1655 | if (in_range) |
1656 | { | |
1657 | int i; | |
a737bd4d | 1658 | |
c19d1205 ZW |
1659 | if (reg <= cur_reg) |
1660 | { | |
dcbf9037 | 1661 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1662 | return FAIL; |
1663 | } | |
40a18ebd | 1664 | |
c19d1205 ZW |
1665 | for (i = cur_reg + 1; i < reg; i++) |
1666 | { | |
1667 | if (range & (1 << i)) | |
1668 | as_tsktsk | |
1669 | (_("Warning: duplicated register (r%d) in register list"), | |
1670 | i); | |
1671 | else | |
1672 | range |= 1 << i; | |
1673 | } | |
1674 | in_range = 0; | |
1675 | } | |
a737bd4d | 1676 | |
c19d1205 ZW |
1677 | if (range & (1 << reg)) |
1678 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1679 | reg); | |
1680 | else if (reg <= cur_reg) | |
1681 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1682 | |
c19d1205 ZW |
1683 | range |= 1 << reg; |
1684 | cur_reg = reg; | |
1685 | } | |
1686 | while (skip_past_comma (&str) != FAIL | |
1687 | || (in_range = 1, *str++ == '-')); | |
1688 | str--; | |
a737bd4d | 1689 | |
d996d970 | 1690 | if (skip_past_char (&str, '}') == FAIL) |
c19d1205 | 1691 | { |
dcbf9037 | 1692 | first_error (_("missing `}'")); |
c19d1205 ZW |
1693 | return FAIL; |
1694 | } | |
1695 | } | |
1696 | else | |
1697 | { | |
91d6fa6a | 1698 | expressionS exp; |
40a18ebd | 1699 | |
91d6fa6a | 1700 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1701 | return FAIL; |
40a18ebd | 1702 | |
91d6fa6a | 1703 | if (exp.X_op == O_constant) |
c19d1205 | 1704 | { |
91d6fa6a NC |
1705 | if (exp.X_add_number |
1706 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1707 | { |
1708 | inst.error = _("invalid register mask"); | |
1709 | return FAIL; | |
1710 | } | |
a737bd4d | 1711 | |
91d6fa6a | 1712 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1713 | { |
91d6fa6a | 1714 | int regno = range & exp.X_add_number; |
a737bd4d | 1715 | |
c19d1205 ZW |
1716 | regno &= -regno; |
1717 | regno = (1 << regno) - 1; | |
1718 | as_tsktsk | |
1719 | (_("Warning: duplicated register (r%d) in register list"), | |
1720 | regno); | |
1721 | } | |
a737bd4d | 1722 | |
91d6fa6a | 1723 | range |= exp.X_add_number; |
c19d1205 ZW |
1724 | } |
1725 | else | |
1726 | { | |
1727 | if (inst.reloc.type != 0) | |
1728 | { | |
1729 | inst.error = _("expression too complex"); | |
1730 | return FAIL; | |
1731 | } | |
a737bd4d | 1732 | |
91d6fa6a | 1733 | memcpy (&inst.reloc.exp, &exp, sizeof (expressionS)); |
c19d1205 ZW |
1734 | inst.reloc.type = BFD_RELOC_ARM_MULTI; |
1735 | inst.reloc.pc_rel = 0; | |
1736 | } | |
1737 | } | |
a737bd4d | 1738 | |
c19d1205 ZW |
1739 | if (*str == '|' || *str == '+') |
1740 | { | |
1741 | str++; | |
1742 | another_range = 1; | |
1743 | } | |
a737bd4d | 1744 | } |
c19d1205 | 1745 | while (another_range); |
a737bd4d | 1746 | |
c19d1205 ZW |
1747 | *strp = str; |
1748 | return range; | |
a737bd4d NC |
1749 | } |
1750 | ||
5287ad62 JB |
1751 | /* Types of registers in a list. */ |
1752 | ||
1753 | enum reg_list_els | |
1754 | { | |
1755 | REGLIST_VFP_S, | |
1756 | REGLIST_VFP_D, | |
1757 | REGLIST_NEON_D | |
1758 | }; | |
1759 | ||
c19d1205 ZW |
1760 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1761 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1762 | register. Parses registers of type ETYPE. |
1763 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1764 | - Q registers can be used to specify pairs of D registers | |
1765 | - { } can be omitted from around a singleton register list | |
477330fc RM |
1766 | FIXME: This is not implemented, as it would require backtracking in |
1767 | some cases, e.g.: | |
1768 | vtbl.8 d3,d4,d5 | |
1769 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1770 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1771 | - 32 D registers may be used (also true for VFPv3). |
1772 | FIXME: Types are ignored in these register lists, which is probably a | |
1773 | bug. */ | |
6057a28f | 1774 | |
c19d1205 | 1775 | static int |
037e8744 | 1776 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1777 | { |
037e8744 | 1778 | char *str = *ccp; |
c19d1205 ZW |
1779 | int base_reg; |
1780 | int new_base; | |
21d799b5 | 1781 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1782 | int max_regs = 0; |
c19d1205 ZW |
1783 | int count = 0; |
1784 | int warned = 0; | |
1785 | unsigned long mask = 0; | |
a737bd4d | 1786 | int i; |
6057a28f | 1787 | |
477330fc | 1788 | if (skip_past_char (&str, '{') == FAIL) |
5287ad62 JB |
1789 | { |
1790 | inst.error = _("expecting {"); | |
1791 | return FAIL; | |
1792 | } | |
6057a28f | 1793 | |
5287ad62 | 1794 | switch (etype) |
c19d1205 | 1795 | { |
5287ad62 | 1796 | case REGLIST_VFP_S: |
c19d1205 ZW |
1797 | regtype = REG_TYPE_VFS; |
1798 | max_regs = 32; | |
5287ad62 | 1799 | break; |
5f4273c7 | 1800 | |
5287ad62 JB |
1801 | case REGLIST_VFP_D: |
1802 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1803 | break; |
5f4273c7 | 1804 | |
b7fc2769 JB |
1805 | case REGLIST_NEON_D: |
1806 | regtype = REG_TYPE_NDQ; | |
1807 | break; | |
1808 | } | |
1809 | ||
1810 | if (etype != REGLIST_VFP_S) | |
1811 | { | |
b1cc4aeb PB |
1812 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1813 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
477330fc RM |
1814 | { |
1815 | max_regs = 32; | |
1816 | if (thumb_mode) | |
1817 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
1818 | fpu_vfp_ext_d32); | |
1819 | else | |
1820 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
1821 | fpu_vfp_ext_d32); | |
1822 | } | |
5287ad62 | 1823 | else |
477330fc | 1824 | max_regs = 16; |
c19d1205 | 1825 | } |
6057a28f | 1826 | |
c19d1205 | 1827 | base_reg = max_regs; |
a737bd4d | 1828 | |
c19d1205 ZW |
1829 | do |
1830 | { | |
5287ad62 | 1831 | int setmask = 1, addregs = 1; |
dcbf9037 | 1832 | |
037e8744 | 1833 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1834 | |
c19d1205 | 1835 | if (new_base == FAIL) |
a737bd4d | 1836 | { |
dcbf9037 | 1837 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1838 | return FAIL; |
1839 | } | |
5f4273c7 | 1840 | |
b7fc2769 | 1841 | if (new_base >= max_regs) |
477330fc RM |
1842 | { |
1843 | first_error (_("register out of range in list")); | |
1844 | return FAIL; | |
1845 | } | |
5f4273c7 | 1846 | |
5287ad62 JB |
1847 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1848 | if (regtype == REG_TYPE_NQ) | |
477330fc RM |
1849 | { |
1850 | setmask = 3; | |
1851 | addregs = 2; | |
1852 | } | |
5287ad62 | 1853 | |
c19d1205 ZW |
1854 | if (new_base < base_reg) |
1855 | base_reg = new_base; | |
a737bd4d | 1856 | |
5287ad62 | 1857 | if (mask & (setmask << new_base)) |
c19d1205 | 1858 | { |
dcbf9037 | 1859 | first_error (_("invalid register list")); |
c19d1205 | 1860 | return FAIL; |
a737bd4d | 1861 | } |
a737bd4d | 1862 | |
c19d1205 ZW |
1863 | if ((mask >> new_base) != 0 && ! warned) |
1864 | { | |
1865 | as_tsktsk (_("register list not in ascending order")); | |
1866 | warned = 1; | |
1867 | } | |
0bbf2aa4 | 1868 | |
5287ad62 JB |
1869 | mask |= setmask << new_base; |
1870 | count += addregs; | |
0bbf2aa4 | 1871 | |
037e8744 | 1872 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1873 | { |
1874 | int high_range; | |
0bbf2aa4 | 1875 | |
037e8744 | 1876 | str++; |
0bbf2aa4 | 1877 | |
037e8744 | 1878 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
477330fc | 1879 | == FAIL) |
c19d1205 ZW |
1880 | { |
1881 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1882 | return FAIL; | |
1883 | } | |
0bbf2aa4 | 1884 | |
477330fc RM |
1885 | if (high_range >= max_regs) |
1886 | { | |
1887 | first_error (_("register out of range in list")); | |
1888 | return FAIL; | |
1889 | } | |
b7fc2769 | 1890 | |
477330fc RM |
1891 | if (regtype == REG_TYPE_NQ) |
1892 | high_range = high_range + 1; | |
5287ad62 | 1893 | |
c19d1205 ZW |
1894 | if (high_range <= new_base) |
1895 | { | |
1896 | inst.error = _("register range not in ascending order"); | |
1897 | return FAIL; | |
1898 | } | |
0bbf2aa4 | 1899 | |
5287ad62 | 1900 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1901 | { |
5287ad62 | 1902 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1903 | { |
c19d1205 ZW |
1904 | inst.error = _("invalid register list"); |
1905 | return FAIL; | |
0bbf2aa4 | 1906 | } |
c19d1205 | 1907 | |
5287ad62 JB |
1908 | mask |= setmask << new_base; |
1909 | count += addregs; | |
0bbf2aa4 | 1910 | } |
0bbf2aa4 | 1911 | } |
0bbf2aa4 | 1912 | } |
037e8744 | 1913 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1914 | |
037e8744 | 1915 | str++; |
0bbf2aa4 | 1916 | |
c19d1205 ZW |
1917 | /* Sanity check -- should have raised a parse error above. */ |
1918 | if (count == 0 || count > max_regs) | |
1919 | abort (); | |
1920 | ||
1921 | *pbase = base_reg; | |
1922 | ||
1923 | /* Final test -- the registers must be consecutive. */ | |
1924 | mask >>= base_reg; | |
1925 | for (i = 0; i < count; i++) | |
1926 | { | |
1927 | if ((mask & (1u << i)) == 0) | |
1928 | { | |
1929 | inst.error = _("non-contiguous register range"); | |
1930 | return FAIL; | |
1931 | } | |
1932 | } | |
1933 | ||
037e8744 JB |
1934 | *ccp = str; |
1935 | ||
c19d1205 | 1936 | return count; |
b99bd4ef NC |
1937 | } |
1938 | ||
dcbf9037 JB |
1939 | /* True if two alias types are the same. */ |
1940 | ||
c921be7d | 1941 | static bfd_boolean |
dcbf9037 JB |
1942 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1943 | { | |
1944 | if (!a && !b) | |
c921be7d | 1945 | return TRUE; |
5f4273c7 | 1946 | |
dcbf9037 | 1947 | if (!a || !b) |
c921be7d | 1948 | return FALSE; |
dcbf9037 JB |
1949 | |
1950 | if (a->defined != b->defined) | |
c921be7d | 1951 | return FALSE; |
5f4273c7 | 1952 | |
dcbf9037 JB |
1953 | if ((a->defined & NTA_HASTYPE) != 0 |
1954 | && (a->eltype.type != b->eltype.type | |
477330fc | 1955 | || a->eltype.size != b->eltype.size)) |
c921be7d | 1956 | return FALSE; |
dcbf9037 JB |
1957 | |
1958 | if ((a->defined & NTA_HASINDEX) != 0 | |
1959 | && (a->index != b->index)) | |
c921be7d | 1960 | return FALSE; |
5f4273c7 | 1961 | |
c921be7d | 1962 | return TRUE; |
dcbf9037 JB |
1963 | } |
1964 | ||
5287ad62 JB |
1965 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1966 | The base register is put in *PBASE. | |
dcbf9037 | 1967 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1968 | the return value. |
1969 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1970 | Bits [6:5] encode the list length (minus one). |
1971 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1972 | |
5287ad62 | 1973 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1974 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1975 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1976 | ||
1977 | static int | |
dcbf9037 | 1978 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
477330fc | 1979 | struct neon_type_el *eltype) |
5287ad62 JB |
1980 | { |
1981 | char *ptr = *str; | |
1982 | int base_reg = -1; | |
1983 | int reg_incr = -1; | |
1984 | int count = 0; | |
1985 | int lane = -1; | |
1986 | int leading_brace = 0; | |
1987 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
20203fb9 NC |
1988 | const char *const incr_error = _("register stride must be 1 or 2"); |
1989 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 1990 | struct neon_typed_alias firsttype; |
5f4273c7 | 1991 | |
5287ad62 JB |
1992 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1993 | leading_brace = 1; | |
5f4273c7 | 1994 | |
5287ad62 JB |
1995 | do |
1996 | { | |
dcbf9037 JB |
1997 | struct neon_typed_alias atype; |
1998 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1999 | ||
5287ad62 | 2000 | if (getreg == FAIL) |
477330fc RM |
2001 | { |
2002 | first_error (_(reg_expected_msgs[rtype])); | |
2003 | return FAIL; | |
2004 | } | |
5f4273c7 | 2005 | |
5287ad62 | 2006 | if (base_reg == -1) |
477330fc RM |
2007 | { |
2008 | base_reg = getreg; | |
2009 | if (rtype == REG_TYPE_NQ) | |
2010 | { | |
2011 | reg_incr = 1; | |
2012 | } | |
2013 | firsttype = atype; | |
2014 | } | |
5287ad62 | 2015 | else if (reg_incr == -1) |
477330fc RM |
2016 | { |
2017 | reg_incr = getreg - base_reg; | |
2018 | if (reg_incr < 1 || reg_incr > 2) | |
2019 | { | |
2020 | first_error (_(incr_error)); | |
2021 | return FAIL; | |
2022 | } | |
2023 | } | |
5287ad62 | 2024 | else if (getreg != base_reg + reg_incr * count) |
477330fc RM |
2025 | { |
2026 | first_error (_(incr_error)); | |
2027 | return FAIL; | |
2028 | } | |
dcbf9037 | 2029 | |
c921be7d | 2030 | if (! neon_alias_types_same (&atype, &firsttype)) |
477330fc RM |
2031 | { |
2032 | first_error (_(type_error)); | |
2033 | return FAIL; | |
2034 | } | |
5f4273c7 | 2035 | |
5287ad62 | 2036 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
477330fc | 2037 | modes. */ |
5287ad62 | 2038 | if (ptr[0] == '-') |
477330fc RM |
2039 | { |
2040 | struct neon_typed_alias htype; | |
2041 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; | |
2042 | if (lane == -1) | |
2043 | lane = NEON_INTERLEAVE_LANES; | |
2044 | else if (lane != NEON_INTERLEAVE_LANES) | |
2045 | { | |
2046 | first_error (_(type_error)); | |
2047 | return FAIL; | |
2048 | } | |
2049 | if (reg_incr == -1) | |
2050 | reg_incr = 1; | |
2051 | else if (reg_incr != 1) | |
2052 | { | |
2053 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); | |
2054 | return FAIL; | |
2055 | } | |
2056 | ptr++; | |
2057 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); | |
2058 | if (hireg == FAIL) | |
2059 | { | |
2060 | first_error (_(reg_expected_msgs[rtype])); | |
2061 | return FAIL; | |
2062 | } | |
2063 | if (! neon_alias_types_same (&htype, &firsttype)) | |
2064 | { | |
2065 | first_error (_(type_error)); | |
2066 | return FAIL; | |
2067 | } | |
2068 | count += hireg + dregs - getreg; | |
2069 | continue; | |
2070 | } | |
5f4273c7 | 2071 | |
5287ad62 JB |
2072 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2073 | if (rtype == REG_TYPE_NQ) | |
477330fc RM |
2074 | { |
2075 | count += 2; | |
2076 | continue; | |
2077 | } | |
5f4273c7 | 2078 | |
dcbf9037 | 2079 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
2080 | { |
2081 | if (lane == -1) | |
2082 | lane = atype.index; | |
2083 | else if (lane != atype.index) | |
2084 | { | |
2085 | first_error (_(type_error)); | |
2086 | return FAIL; | |
2087 | } | |
2088 | } | |
5287ad62 | 2089 | else if (lane == -1) |
477330fc | 2090 | lane = NEON_INTERLEAVE_LANES; |
5287ad62 | 2091 | else if (lane != NEON_INTERLEAVE_LANES) |
477330fc RM |
2092 | { |
2093 | first_error (_(type_error)); | |
2094 | return FAIL; | |
2095 | } | |
5287ad62 JB |
2096 | count++; |
2097 | } | |
2098 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2099 | |
5287ad62 JB |
2100 | /* No lane set by [x]. We must be interleaving structures. */ |
2101 | if (lane == -1) | |
2102 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2103 | |
5287ad62 JB |
2104 | /* Sanity check. */ |
2105 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
2106 | || (count > 1 && reg_incr == -1)) | |
2107 | { | |
dcbf9037 | 2108 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2109 | return FAIL; |
2110 | } | |
2111 | ||
2112 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2113 | { | |
dcbf9037 | 2114 | first_error (_("expected }")); |
5287ad62 JB |
2115 | return FAIL; |
2116 | } | |
5f4273c7 | 2117 | |
5287ad62 JB |
2118 | if (reg_incr == -1) |
2119 | reg_incr = 1; | |
2120 | ||
dcbf9037 JB |
2121 | if (eltype) |
2122 | *eltype = firsttype.eltype; | |
2123 | ||
5287ad62 JB |
2124 | *pbase = base_reg; |
2125 | *str = ptr; | |
5f4273c7 | 2126 | |
5287ad62 JB |
2127 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2128 | } | |
2129 | ||
c19d1205 ZW |
2130 | /* Parse an explicit relocation suffix on an expression. This is |
2131 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2132 | arm_reloc_hsh contains no entries, so this function can only | |
2133 | succeed if there is no () after the word. Returns -1 on error, | |
2134 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
3da1d841 | 2135 | |
c19d1205 ZW |
2136 | static int |
2137 | parse_reloc (char **str) | |
b99bd4ef | 2138 | { |
c19d1205 ZW |
2139 | struct reloc_entry *r; |
2140 | char *p, *q; | |
b99bd4ef | 2141 | |
c19d1205 ZW |
2142 | if (**str != '(') |
2143 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2144 | |
c19d1205 ZW |
2145 | p = *str + 1; |
2146 | q = p; | |
2147 | ||
2148 | while (*q && *q != ')' && *q != ',') | |
2149 | q++; | |
2150 | if (*q != ')') | |
2151 | return -1; | |
2152 | ||
21d799b5 NC |
2153 | if ((r = (struct reloc_entry *) |
2154 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2155 | return -1; |
2156 | ||
2157 | *str = q + 1; | |
2158 | return r->reloc; | |
b99bd4ef NC |
2159 | } |
2160 | ||
c19d1205 ZW |
2161 | /* Directives: register aliases. */ |
2162 | ||
dcbf9037 | 2163 | static struct reg_entry * |
90ec0d68 | 2164 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2165 | { |
d3ce72d0 | 2166 | struct reg_entry *new_reg; |
c19d1205 | 2167 | const char *name; |
b99bd4ef | 2168 | |
d3ce72d0 | 2169 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2170 | { |
d3ce72d0 | 2171 | if (new_reg->builtin) |
c19d1205 | 2172 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2173 | |
c19d1205 ZW |
2174 | /* Only warn about a redefinition if it's not defined as the |
2175 | same register. */ | |
d3ce72d0 | 2176 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2177 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2178 | |
d929913e | 2179 | return NULL; |
c19d1205 | 2180 | } |
b99bd4ef | 2181 | |
c19d1205 | 2182 | name = xstrdup (str); |
d3ce72d0 | 2183 | new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry)); |
b99bd4ef | 2184 | |
d3ce72d0 NC |
2185 | new_reg->name = name; |
2186 | new_reg->number = number; | |
2187 | new_reg->type = type; | |
2188 | new_reg->builtin = FALSE; | |
2189 | new_reg->neon = NULL; | |
b99bd4ef | 2190 | |
d3ce72d0 | 2191 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2192 | abort (); |
5f4273c7 | 2193 | |
d3ce72d0 | 2194 | return new_reg; |
dcbf9037 JB |
2195 | } |
2196 | ||
2197 | static void | |
2198 | insert_neon_reg_alias (char *str, int number, int type, | |
477330fc | 2199 | struct neon_typed_alias *atype) |
dcbf9037 JB |
2200 | { |
2201 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2202 | |
dcbf9037 JB |
2203 | if (!reg) |
2204 | { | |
2205 | first_error (_("attempt to redefine typed alias")); | |
2206 | return; | |
2207 | } | |
5f4273c7 | 2208 | |
dcbf9037 JB |
2209 | if (atype) |
2210 | { | |
21d799b5 | 2211 | reg->neon = (struct neon_typed_alias *) |
477330fc | 2212 | xmalloc (sizeof (struct neon_typed_alias)); |
dcbf9037 JB |
2213 | *reg->neon = *atype; |
2214 | } | |
c19d1205 | 2215 | } |
b99bd4ef | 2216 | |
c19d1205 | 2217 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2218 | |
c19d1205 | 2219 | new_register_name .req existing_register_name |
b99bd4ef | 2220 | |
c19d1205 | 2221 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2222 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2223 | |
d929913e | 2224 | static bfd_boolean |
c19d1205 ZW |
2225 | create_register_alias (char * newname, char *p) |
2226 | { | |
2227 | struct reg_entry *old; | |
2228 | char *oldname, *nbuf; | |
2229 | size_t nlen; | |
b99bd4ef | 2230 | |
c19d1205 ZW |
2231 | /* The input scrubber ensures that whitespace after the mnemonic is |
2232 | collapsed to single spaces. */ | |
2233 | oldname = p; | |
2234 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2235 | return FALSE; |
b99bd4ef | 2236 | |
c19d1205 ZW |
2237 | oldname += 6; |
2238 | if (*oldname == '\0') | |
d929913e | 2239 | return FALSE; |
b99bd4ef | 2240 | |
21d799b5 | 2241 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2242 | if (!old) |
b99bd4ef | 2243 | { |
c19d1205 | 2244 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2245 | return TRUE; |
b99bd4ef NC |
2246 | } |
2247 | ||
c19d1205 ZW |
2248 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2249 | the desired alias name, and p points to its end. If not, then | |
2250 | the desired alias name is in the global original_case_string. */ | |
2251 | #ifdef TC_CASE_SENSITIVE | |
2252 | nlen = p - newname; | |
2253 | #else | |
2254 | newname = original_case_string; | |
2255 | nlen = strlen (newname); | |
2256 | #endif | |
b99bd4ef | 2257 | |
e1fa0163 | 2258 | nbuf = xmalloc (nlen + 1); |
c19d1205 ZW |
2259 | memcpy (nbuf, newname, nlen); |
2260 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2261 | |
c19d1205 ZW |
2262 | /* Create aliases under the new name as stated; an all-lowercase |
2263 | version of the new name; and an all-uppercase version of the new | |
2264 | name. */ | |
d929913e NC |
2265 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2266 | { | |
2267 | for (p = nbuf; *p; p++) | |
2268 | *p = TOUPPER (*p); | |
c19d1205 | 2269 | |
d929913e NC |
2270 | if (strncmp (nbuf, newname, nlen)) |
2271 | { | |
2272 | /* If this attempt to create an additional alias fails, do not bother | |
2273 | trying to create the all-lower case alias. We will fail and issue | |
2274 | a second, duplicate error message. This situation arises when the | |
2275 | programmer does something like: | |
2276 | foo .req r0 | |
2277 | Foo .req r1 | |
2278 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2279 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2280 | first .req. */ |
2281 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
e1fa0163 NC |
2282 | { |
2283 | free (nbuf); | |
2284 | return TRUE; | |
2285 | } | |
d929913e | 2286 | } |
c19d1205 | 2287 | |
d929913e NC |
2288 | for (p = nbuf; *p; p++) |
2289 | *p = TOLOWER (*p); | |
c19d1205 | 2290 | |
d929913e NC |
2291 | if (strncmp (nbuf, newname, nlen)) |
2292 | insert_reg_alias (nbuf, old->number, old->type); | |
2293 | } | |
c19d1205 | 2294 | |
e1fa0163 | 2295 | free (nbuf); |
d929913e | 2296 | return TRUE; |
b99bd4ef NC |
2297 | } |
2298 | ||
dcbf9037 JB |
2299 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2300 | X .dn d5.s32[1] | |
2301 | Y .qn 6.s16 | |
2302 | Z .dn d7 | |
2303 | T .dn Z[0] | |
2304 | These typed registers can be used instead of the types specified after the | |
2305 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2306 | specified directly, e.g.: | |
5f4273c7 | 2307 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2308 | |
c921be7d | 2309 | static bfd_boolean |
dcbf9037 JB |
2310 | create_neon_reg_alias (char *newname, char *p) |
2311 | { | |
2312 | enum arm_reg_type basetype; | |
2313 | struct reg_entry *basereg; | |
2314 | struct reg_entry mybasereg; | |
2315 | struct neon_type ntype; | |
2316 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2317 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2318 | int namelen; |
5f4273c7 | 2319 | |
dcbf9037 JB |
2320 | typeinfo.defined = 0; |
2321 | typeinfo.eltype.type = NT_invtype; | |
2322 | typeinfo.eltype.size = -1; | |
2323 | typeinfo.index = -1; | |
5f4273c7 | 2324 | |
dcbf9037 | 2325 | nameend = p; |
5f4273c7 | 2326 | |
dcbf9037 JB |
2327 | if (strncmp (p, " .dn ", 5) == 0) |
2328 | basetype = REG_TYPE_VFD; | |
2329 | else if (strncmp (p, " .qn ", 5) == 0) | |
2330 | basetype = REG_TYPE_NQ; | |
2331 | else | |
c921be7d | 2332 | return FALSE; |
5f4273c7 | 2333 | |
dcbf9037 | 2334 | p += 5; |
5f4273c7 | 2335 | |
dcbf9037 | 2336 | if (*p == '\0') |
c921be7d | 2337 | return FALSE; |
5f4273c7 | 2338 | |
dcbf9037 JB |
2339 | basereg = arm_reg_parse_multi (&p); |
2340 | ||
2341 | if (basereg && basereg->type != basetype) | |
2342 | { | |
2343 | as_bad (_("bad type for register")); | |
c921be7d | 2344 | return FALSE; |
dcbf9037 JB |
2345 | } |
2346 | ||
2347 | if (basereg == NULL) | |
2348 | { | |
2349 | expressionS exp; | |
2350 | /* Try parsing as an integer. */ | |
2351 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2352 | if (exp.X_op != O_constant) | |
477330fc RM |
2353 | { |
2354 | as_bad (_("expression must be constant")); | |
2355 | return FALSE; | |
2356 | } | |
dcbf9037 JB |
2357 | basereg = &mybasereg; |
2358 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
477330fc | 2359 | : exp.X_add_number; |
dcbf9037 JB |
2360 | basereg->neon = 0; |
2361 | } | |
2362 | ||
2363 | if (basereg->neon) | |
2364 | typeinfo = *basereg->neon; | |
2365 | ||
2366 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2367 | { | |
2368 | /* We got a type. */ | |
2369 | if (typeinfo.defined & NTA_HASTYPE) | |
477330fc RM |
2370 | { |
2371 | as_bad (_("can't redefine the type of a register alias")); | |
2372 | return FALSE; | |
2373 | } | |
5f4273c7 | 2374 | |
dcbf9037 JB |
2375 | typeinfo.defined |= NTA_HASTYPE; |
2376 | if (ntype.elems != 1) | |
477330fc RM |
2377 | { |
2378 | as_bad (_("you must specify a single type only")); | |
2379 | return FALSE; | |
2380 | } | |
dcbf9037 JB |
2381 | typeinfo.eltype = ntype.el[0]; |
2382 | } | |
5f4273c7 | 2383 | |
dcbf9037 JB |
2384 | if (skip_past_char (&p, '[') == SUCCESS) |
2385 | { | |
2386 | expressionS exp; | |
2387 | /* We got a scalar index. */ | |
5f4273c7 | 2388 | |
dcbf9037 | 2389 | if (typeinfo.defined & NTA_HASINDEX) |
477330fc RM |
2390 | { |
2391 | as_bad (_("can't redefine the index of a scalar alias")); | |
2392 | return FALSE; | |
2393 | } | |
5f4273c7 | 2394 | |
dcbf9037 | 2395 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2396 | |
dcbf9037 | 2397 | if (exp.X_op != O_constant) |
477330fc RM |
2398 | { |
2399 | as_bad (_("scalar index must be constant")); | |
2400 | return FALSE; | |
2401 | } | |
5f4273c7 | 2402 | |
dcbf9037 JB |
2403 | typeinfo.defined |= NTA_HASINDEX; |
2404 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2405 | |
dcbf9037 | 2406 | if (skip_past_char (&p, ']') == FAIL) |
477330fc RM |
2407 | { |
2408 | as_bad (_("expecting ]")); | |
2409 | return FALSE; | |
2410 | } | |
dcbf9037 JB |
2411 | } |
2412 | ||
15735687 NS |
2413 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2414 | the desired alias name, and p points to its end. If not, then | |
2415 | the desired alias name is in the global original_case_string. */ | |
2416 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2417 | namelen = nameend - newname; |
15735687 NS |
2418 | #else |
2419 | newname = original_case_string; | |
2420 | namelen = strlen (newname); | |
2421 | #endif | |
2422 | ||
e1fa0163 | 2423 | namebuf = xmalloc (namelen + 1); |
dcbf9037 JB |
2424 | strncpy (namebuf, newname, namelen); |
2425 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2426 | |
dcbf9037 | 2427 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
477330fc | 2428 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2429 | |
dcbf9037 JB |
2430 | /* Insert name in all uppercase. */ |
2431 | for (p = namebuf; *p; p++) | |
2432 | *p = TOUPPER (*p); | |
5f4273c7 | 2433 | |
dcbf9037 JB |
2434 | if (strncmp (namebuf, newname, namelen)) |
2435 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2436 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2437 | |
dcbf9037 JB |
2438 | /* Insert name in all lowercase. */ |
2439 | for (p = namebuf; *p; p++) | |
2440 | *p = TOLOWER (*p); | |
5f4273c7 | 2441 | |
dcbf9037 JB |
2442 | if (strncmp (namebuf, newname, namelen)) |
2443 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2444 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2445 | |
e1fa0163 | 2446 | free (namebuf); |
c921be7d | 2447 | return TRUE; |
dcbf9037 JB |
2448 | } |
2449 | ||
c19d1205 ZW |
2450 | /* Should never be called, as .req goes between the alias and the |
2451 | register name, not at the beginning of the line. */ | |
c921be7d | 2452 | |
b99bd4ef | 2453 | static void |
c19d1205 | 2454 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2455 | { |
c19d1205 ZW |
2456 | as_bad (_("invalid syntax for .req directive")); |
2457 | } | |
b99bd4ef | 2458 | |
dcbf9037 JB |
2459 | static void |
2460 | s_dn (int a ATTRIBUTE_UNUSED) | |
2461 | { | |
2462 | as_bad (_("invalid syntax for .dn directive")); | |
2463 | } | |
2464 | ||
2465 | static void | |
2466 | s_qn (int a ATTRIBUTE_UNUSED) | |
2467 | { | |
2468 | as_bad (_("invalid syntax for .qn directive")); | |
2469 | } | |
2470 | ||
c19d1205 ZW |
2471 | /* The .unreq directive deletes an alias which was previously defined |
2472 | by .req. For example: | |
b99bd4ef | 2473 | |
c19d1205 ZW |
2474 | my_alias .req r11 |
2475 | .unreq my_alias */ | |
b99bd4ef NC |
2476 | |
2477 | static void | |
c19d1205 | 2478 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2479 | { |
c19d1205 ZW |
2480 | char * name; |
2481 | char saved_char; | |
b99bd4ef | 2482 | |
c19d1205 ZW |
2483 | name = input_line_pointer; |
2484 | ||
2485 | while (*input_line_pointer != 0 | |
2486 | && *input_line_pointer != ' ' | |
2487 | && *input_line_pointer != '\n') | |
2488 | ++input_line_pointer; | |
2489 | ||
2490 | saved_char = *input_line_pointer; | |
2491 | *input_line_pointer = 0; | |
2492 | ||
2493 | if (!*name) | |
2494 | as_bad (_("invalid syntax for .unreq directive")); | |
2495 | else | |
2496 | { | |
21d799b5 | 2497 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
477330fc | 2498 | name); |
c19d1205 ZW |
2499 | |
2500 | if (!reg) | |
2501 | as_bad (_("unknown register alias '%s'"), name); | |
2502 | else if (reg->builtin) | |
a1727c1a | 2503 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2504 | name); |
2505 | else | |
2506 | { | |
d929913e NC |
2507 | char * p; |
2508 | char * nbuf; | |
2509 | ||
db0bc284 | 2510 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2511 | free ((char *) reg->name); |
477330fc RM |
2512 | if (reg->neon) |
2513 | free (reg->neon); | |
c19d1205 | 2514 | free (reg); |
d929913e NC |
2515 | |
2516 | /* Also locate the all upper case and all lower case versions. | |
2517 | Do not complain if we cannot find one or the other as it | |
2518 | was probably deleted above. */ | |
5f4273c7 | 2519 | |
d929913e NC |
2520 | nbuf = strdup (name); |
2521 | for (p = nbuf; *p; p++) | |
2522 | *p = TOUPPER (*p); | |
21d799b5 | 2523 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2524 | if (reg) |
2525 | { | |
db0bc284 | 2526 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2527 | free ((char *) reg->name); |
2528 | if (reg->neon) | |
2529 | free (reg->neon); | |
2530 | free (reg); | |
2531 | } | |
2532 | ||
2533 | for (p = nbuf; *p; p++) | |
2534 | *p = TOLOWER (*p); | |
21d799b5 | 2535 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2536 | if (reg) |
2537 | { | |
db0bc284 | 2538 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2539 | free ((char *) reg->name); |
2540 | if (reg->neon) | |
2541 | free (reg->neon); | |
2542 | free (reg); | |
2543 | } | |
2544 | ||
2545 | free (nbuf); | |
c19d1205 ZW |
2546 | } |
2547 | } | |
b99bd4ef | 2548 | |
c19d1205 | 2549 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2550 | demand_empty_rest_of_line (); |
2551 | } | |
2552 | ||
c19d1205 ZW |
2553 | /* Directives: Instruction set selection. */ |
2554 | ||
2555 | #ifdef OBJ_ELF | |
2556 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2557 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2558 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2559 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2560 | ||
cd000bff DJ |
2561 | /* Create a new mapping symbol for the transition to STATE. */ |
2562 | ||
2563 | static void | |
2564 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2565 | { |
a737bd4d | 2566 | symbolS * symbolP; |
c19d1205 ZW |
2567 | const char * symname; |
2568 | int type; | |
b99bd4ef | 2569 | |
c19d1205 | 2570 | switch (state) |
b99bd4ef | 2571 | { |
c19d1205 ZW |
2572 | case MAP_DATA: |
2573 | symname = "$d"; | |
2574 | type = BSF_NO_FLAGS; | |
2575 | break; | |
2576 | case MAP_ARM: | |
2577 | symname = "$a"; | |
2578 | type = BSF_NO_FLAGS; | |
2579 | break; | |
2580 | case MAP_THUMB: | |
2581 | symname = "$t"; | |
2582 | type = BSF_NO_FLAGS; | |
2583 | break; | |
c19d1205 ZW |
2584 | default: |
2585 | abort (); | |
2586 | } | |
2587 | ||
cd000bff | 2588 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2589 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2590 | ||
2591 | switch (state) | |
2592 | { | |
2593 | case MAP_ARM: | |
2594 | THUMB_SET_FUNC (symbolP, 0); | |
2595 | ARM_SET_THUMB (symbolP, 0); | |
2596 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2597 | break; | |
2598 | ||
2599 | case MAP_THUMB: | |
2600 | THUMB_SET_FUNC (symbolP, 1); | |
2601 | ARM_SET_THUMB (symbolP, 1); | |
2602 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2603 | break; | |
2604 | ||
2605 | case MAP_DATA: | |
2606 | default: | |
cd000bff DJ |
2607 | break; |
2608 | } | |
2609 | ||
2610 | /* Save the mapping symbols for future reference. Also check that | |
2611 | we do not place two mapping symbols at the same offset within a | |
2612 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2613 | check_mapping_symbols. |
2614 | ||
2615 | If .fill or other data filling directive generates zero sized data, | |
2616 | the mapping symbol for the following code will have the same value | |
2617 | as the one generated for the data filling directive. In this case, | |
2618 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2619 | if (value == 0) |
2620 | { | |
2de7820f JZ |
2621 | if (frag->tc_frag_data.first_map != NULL) |
2622 | { | |
2623 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2624 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2625 | } | |
cd000bff DJ |
2626 | frag->tc_frag_data.first_map = symbolP; |
2627 | } | |
2628 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2629 | { |
2630 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2631 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2632 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2633 | } | |
cd000bff DJ |
2634 | frag->tc_frag_data.last_map = symbolP; |
2635 | } | |
2636 | ||
2637 | /* We must sometimes convert a region marked as code to data during | |
2638 | code alignment, if an odd number of bytes have to be padded. The | |
2639 | code mapping symbol is pushed to an aligned address. */ | |
2640 | ||
2641 | static void | |
2642 | insert_data_mapping_symbol (enum mstate state, | |
2643 | valueT value, fragS *frag, offsetT bytes) | |
2644 | { | |
2645 | /* If there was already a mapping symbol, remove it. */ | |
2646 | if (frag->tc_frag_data.last_map != NULL | |
2647 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2648 | { | |
2649 | symbolS *symp = frag->tc_frag_data.last_map; | |
2650 | ||
2651 | if (value == 0) | |
2652 | { | |
2653 | know (frag->tc_frag_data.first_map == symp); | |
2654 | frag->tc_frag_data.first_map = NULL; | |
2655 | } | |
2656 | frag->tc_frag_data.last_map = NULL; | |
2657 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2658 | } |
cd000bff DJ |
2659 | |
2660 | make_mapping_symbol (MAP_DATA, value, frag); | |
2661 | make_mapping_symbol (state, value + bytes, frag); | |
2662 | } | |
2663 | ||
2664 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2665 | ||
2666 | /* Set the mapping state to STATE. Only call this when about to | |
2667 | emit some STATE bytes to the file. */ | |
2668 | ||
4e9aaefb | 2669 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
cd000bff DJ |
2670 | void |
2671 | mapping_state (enum mstate state) | |
2672 | { | |
940b5ce0 DJ |
2673 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2674 | ||
cd000bff DJ |
2675 | if (mapstate == state) |
2676 | /* The mapping symbol has already been emitted. | |
2677 | There is nothing else to do. */ | |
2678 | return; | |
49c62a33 NC |
2679 | |
2680 | if (state == MAP_ARM || state == MAP_THUMB) | |
2681 | /* PR gas/12931 | |
2682 | All ARM instructions require 4-byte alignment. | |
2683 | (Almost) all Thumb instructions require 2-byte alignment. | |
2684 | ||
2685 | When emitting instructions into any section, mark the section | |
2686 | appropriately. | |
2687 | ||
2688 | Some Thumb instructions are alignment-sensitive modulo 4 bytes, | |
2689 | but themselves require 2-byte alignment; this applies to some | |
2690 | PC- relative forms. However, these cases will invovle implicit | |
2691 | literal pool generation or an explicit .align >=2, both of | |
2692 | which will cause the section to me marked with sufficient | |
2693 | alignment. Thus, we don't handle those cases here. */ | |
2694 | record_alignment (now_seg, state == MAP_ARM ? 2 : 1); | |
2695 | ||
2696 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
4e9aaefb | 2697 | /* This case will be evaluated later. */ |
cd000bff | 2698 | return; |
cd000bff DJ |
2699 | |
2700 | mapping_state_2 (state, 0); | |
cd000bff DJ |
2701 | } |
2702 | ||
2703 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2704 | allocated. Put the mapping symbol that far back. */ | |
2705 | ||
2706 | static void | |
2707 | mapping_state_2 (enum mstate state, int max_chars) | |
2708 | { | |
940b5ce0 DJ |
2709 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2710 | ||
2711 | if (!SEG_NORMAL (now_seg)) | |
2712 | return; | |
2713 | ||
cd000bff DJ |
2714 | if (mapstate == state) |
2715 | /* The mapping symbol has already been emitted. | |
2716 | There is nothing else to do. */ | |
2717 | return; | |
2718 | ||
4e9aaefb SA |
2719 | if (TRANSITION (MAP_UNDEFINED, MAP_ARM) |
2720 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2721 | { | |
2722 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2723 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2724 | ||
2725 | if (add_symbol) | |
2726 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2727 | } | |
2728 | ||
cd000bff DJ |
2729 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2730 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 | 2731 | } |
4e9aaefb | 2732 | #undef TRANSITION |
c19d1205 | 2733 | #else |
d3106081 NS |
2734 | #define mapping_state(x) ((void)0) |
2735 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2736 | #endif |
2737 | ||
2738 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2739 | ||
4343666d | 2740 | #ifdef OBJ_COFF |
c19d1205 ZW |
2741 | static symbolS * |
2742 | find_real_start (symbolS * symbolP) | |
2743 | { | |
2744 | char * real_start; | |
2745 | const char * name = S_GET_NAME (symbolP); | |
2746 | symbolS * new_target; | |
2747 | ||
2748 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2749 | #define STUB_NAME ".real_start_of" | |
2750 | ||
2751 | if (name == NULL) | |
2752 | abort (); | |
2753 | ||
37f6032b ZW |
2754 | /* The compiler may generate BL instructions to local labels because |
2755 | it needs to perform a branch to a far away location. These labels | |
2756 | do not have a corresponding ".real_start_of" label. We check | |
2757 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2758 | the ".real_start_of" convention for nonlocal branches. */ | |
2759 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2760 | return symbolP; |
2761 | ||
e1fa0163 | 2762 | real_start = concat (STUB_NAME, name, NULL); |
c19d1205 | 2763 | new_target = symbol_find (real_start); |
e1fa0163 | 2764 | free (real_start); |
c19d1205 ZW |
2765 | |
2766 | if (new_target == NULL) | |
2767 | { | |
bd3ba5d1 | 2768 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2769 | new_target = symbolP; |
2770 | } | |
2771 | ||
c19d1205 ZW |
2772 | return new_target; |
2773 | } | |
4343666d | 2774 | #endif |
c19d1205 ZW |
2775 | |
2776 | static void | |
2777 | opcode_select (int width) | |
2778 | { | |
2779 | switch (width) | |
2780 | { | |
2781 | case 16: | |
2782 | if (! thumb_mode) | |
2783 | { | |
e74cfd16 | 2784 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2785 | as_bad (_("selected processor does not support THUMB opcodes")); |
2786 | ||
2787 | thumb_mode = 1; | |
2788 | /* No need to force the alignment, since we will have been | |
2789 | coming from ARM mode, which is word-aligned. */ | |
2790 | record_alignment (now_seg, 1); | |
2791 | } | |
c19d1205 ZW |
2792 | break; |
2793 | ||
2794 | case 32: | |
2795 | if (thumb_mode) | |
2796 | { | |
e74cfd16 | 2797 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2798 | as_bad (_("selected processor does not support ARM opcodes")); |
2799 | ||
2800 | thumb_mode = 0; | |
2801 | ||
2802 | if (!need_pass_2) | |
2803 | frag_align (2, 0, 0); | |
2804 | ||
2805 | record_alignment (now_seg, 1); | |
2806 | } | |
c19d1205 ZW |
2807 | break; |
2808 | ||
2809 | default: | |
2810 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2811 | } | |
2812 | } | |
2813 | ||
2814 | static void | |
2815 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2816 | { | |
2817 | opcode_select (32); | |
2818 | demand_empty_rest_of_line (); | |
2819 | } | |
2820 | ||
2821 | static void | |
2822 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2823 | { | |
2824 | opcode_select (16); | |
2825 | demand_empty_rest_of_line (); | |
2826 | } | |
2827 | ||
2828 | static void | |
2829 | s_code (int unused ATTRIBUTE_UNUSED) | |
2830 | { | |
2831 | int temp; | |
2832 | ||
2833 | temp = get_absolute_expression (); | |
2834 | switch (temp) | |
2835 | { | |
2836 | case 16: | |
2837 | case 32: | |
2838 | opcode_select (temp); | |
2839 | break; | |
2840 | ||
2841 | default: | |
2842 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2843 | } | |
2844 | } | |
2845 | ||
2846 | static void | |
2847 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2848 | { | |
2849 | /* If we are not already in thumb mode go into it, EVEN if | |
2850 | the target processor does not support thumb instructions. | |
2851 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2852 | to compile interworking support functions even if the | |
2853 | target processor should not support interworking. */ | |
2854 | if (! thumb_mode) | |
2855 | { | |
2856 | thumb_mode = 2; | |
2857 | record_alignment (now_seg, 1); | |
2858 | } | |
2859 | ||
2860 | demand_empty_rest_of_line (); | |
2861 | } | |
2862 | ||
2863 | static void | |
2864 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2865 | { | |
2866 | s_thumb (0); | |
2867 | ||
2868 | /* The following label is the name/address of the start of a Thumb function. | |
2869 | We need to know this for the interworking support. */ | |
2870 | label_is_thumb_function_name = TRUE; | |
2871 | } | |
2872 | ||
2873 | /* Perform a .set directive, but also mark the alias as | |
2874 | being a thumb function. */ | |
2875 | ||
2876 | static void | |
2877 | s_thumb_set (int equiv) | |
2878 | { | |
2879 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2880 | We cannot just call that code as we need to get at the symbol that | |
2881 | is created. */ | |
2882 | char * name; | |
2883 | char delim; | |
2884 | char * end_name; | |
2885 | symbolS * symbolP; | |
2886 | ||
2887 | /* Especial apologies for the random logic: | |
2888 | This just grew, and could be parsed much more simply! | |
2889 | Dean - in haste. */ | |
d02603dc | 2890 | delim = get_symbol_name (& name); |
c19d1205 | 2891 | end_name = input_line_pointer; |
d02603dc | 2892 | (void) restore_line_pointer (delim); |
c19d1205 ZW |
2893 | |
2894 | if (*input_line_pointer != ',') | |
2895 | { | |
2896 | *end_name = 0; | |
2897 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2898 | *end_name = delim; |
2899 | ignore_rest_of_line (); | |
2900 | return; | |
2901 | } | |
2902 | ||
2903 | input_line_pointer++; | |
2904 | *end_name = 0; | |
2905 | ||
2906 | if (name[0] == '.' && name[1] == '\0') | |
2907 | { | |
2908 | /* XXX - this should not happen to .thumb_set. */ | |
2909 | abort (); | |
2910 | } | |
2911 | ||
2912 | if ((symbolP = symbol_find (name)) == NULL | |
2913 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2914 | { | |
2915 | #ifndef NO_LISTING | |
2916 | /* When doing symbol listings, play games with dummy fragments living | |
2917 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2918 | for this symbol. */ |
b99bd4ef NC |
2919 | if (listing & LISTING_SYMBOLS) |
2920 | { | |
2921 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 2922 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2923 | |
2924 | memset (dummy_frag, 0, sizeof (fragS)); | |
2925 | dummy_frag->fr_type = rs_fill; | |
2926 | dummy_frag->line = listing_tail; | |
2927 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2928 | dummy_frag->fr_symbol = symbolP; | |
2929 | } | |
2930 | else | |
2931 | #endif | |
2932 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2933 | ||
2934 | #ifdef OBJ_COFF | |
2935 | /* "set" symbols are local unless otherwise specified. */ | |
2936 | SF_SET_LOCAL (symbolP); | |
2937 | #endif /* OBJ_COFF */ | |
2938 | } /* Make a new symbol. */ | |
2939 | ||
2940 | symbol_table_insert (symbolP); | |
2941 | ||
2942 | * end_name = delim; | |
2943 | ||
2944 | if (equiv | |
2945 | && S_IS_DEFINED (symbolP) | |
2946 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2947 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2948 | ||
2949 | pseudo_set (symbolP); | |
2950 | ||
2951 | demand_empty_rest_of_line (); | |
2952 | ||
c19d1205 | 2953 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2954 | |
2955 | THUMB_SET_FUNC (symbolP, 1); | |
2956 | ARM_SET_THUMB (symbolP, 1); | |
2957 | #if defined OBJ_ELF || defined OBJ_COFF | |
2958 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2959 | #endif | |
2960 | } | |
2961 | ||
c19d1205 | 2962 | /* Directives: Mode selection. */ |
b99bd4ef | 2963 | |
c19d1205 ZW |
2964 | /* .syntax [unified|divided] - choose the new unified syntax |
2965 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2966 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2967 | static void |
c19d1205 | 2968 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2969 | { |
c19d1205 ZW |
2970 | char *name, delim; |
2971 | ||
d02603dc | 2972 | delim = get_symbol_name (& name); |
c19d1205 ZW |
2973 | |
2974 | if (!strcasecmp (name, "unified")) | |
2975 | unified_syntax = TRUE; | |
2976 | else if (!strcasecmp (name, "divided")) | |
2977 | unified_syntax = FALSE; | |
2978 | else | |
2979 | { | |
2980 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2981 | return; | |
2982 | } | |
d02603dc | 2983 | (void) restore_line_pointer (delim); |
b99bd4ef NC |
2984 | demand_empty_rest_of_line (); |
2985 | } | |
2986 | ||
c19d1205 ZW |
2987 | /* Directives: sectioning and alignment. */ |
2988 | ||
c19d1205 ZW |
2989 | static void |
2990 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2991 | { |
c19d1205 ZW |
2992 | /* We don't support putting frags in the BSS segment, we fake it by |
2993 | marking in_bss, then looking at s_skip for clues. */ | |
2994 | subseg_set (bss_section, 0); | |
2995 | demand_empty_rest_of_line (); | |
cd000bff DJ |
2996 | |
2997 | #ifdef md_elf_section_change_hook | |
2998 | md_elf_section_change_hook (); | |
2999 | #endif | |
c19d1205 | 3000 | } |
b99bd4ef | 3001 | |
c19d1205 ZW |
3002 | static void |
3003 | s_even (int ignore ATTRIBUTE_UNUSED) | |
3004 | { | |
3005 | /* Never make frag if expect extra pass. */ | |
3006 | if (!need_pass_2) | |
3007 | frag_align (1, 0, 0); | |
b99bd4ef | 3008 | |
c19d1205 | 3009 | record_alignment (now_seg, 1); |
b99bd4ef | 3010 | |
c19d1205 | 3011 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3012 | } |
3013 | ||
2e6976a8 DG |
3014 | /* Directives: CodeComposer Studio. */ |
3015 | ||
3016 | /* .ref (for CodeComposer Studio syntax only). */ | |
3017 | static void | |
3018 | s_ccs_ref (int unused ATTRIBUTE_UNUSED) | |
3019 | { | |
3020 | if (codecomposer_syntax) | |
3021 | ignore_rest_of_line (); | |
3022 | else | |
3023 | as_bad (_(".ref pseudo-op only available with -mccs flag.")); | |
3024 | } | |
3025 | ||
3026 | /* If name is not NULL, then it is used for marking the beginning of a | |
3027 | function, wherease if it is NULL then it means the function end. */ | |
3028 | static void | |
3029 | asmfunc_debug (const char * name) | |
3030 | { | |
3031 | static const char * last_name = NULL; | |
3032 | ||
3033 | if (name != NULL) | |
3034 | { | |
3035 | gas_assert (last_name == NULL); | |
3036 | last_name = name; | |
3037 | ||
3038 | if (debug_type == DEBUG_STABS) | |
3039 | stabs_generate_asm_func (name, name); | |
3040 | } | |
3041 | else | |
3042 | { | |
3043 | gas_assert (last_name != NULL); | |
3044 | ||
3045 | if (debug_type == DEBUG_STABS) | |
3046 | stabs_generate_asm_endfunc (last_name, last_name); | |
3047 | ||
3048 | last_name = NULL; | |
3049 | } | |
3050 | } | |
3051 | ||
3052 | static void | |
3053 | s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED) | |
3054 | { | |
3055 | if (codecomposer_syntax) | |
3056 | { | |
3057 | switch (asmfunc_state) | |
3058 | { | |
3059 | case OUTSIDE_ASMFUNC: | |
3060 | asmfunc_state = WAITING_ASMFUNC_NAME; | |
3061 | break; | |
3062 | ||
3063 | case WAITING_ASMFUNC_NAME: | |
3064 | as_bad (_(".asmfunc repeated.")); | |
3065 | break; | |
3066 | ||
3067 | case WAITING_ENDASMFUNC: | |
3068 | as_bad (_(".asmfunc without function.")); | |
3069 | break; | |
3070 | } | |
3071 | demand_empty_rest_of_line (); | |
3072 | } | |
3073 | else | |
3074 | as_bad (_(".asmfunc pseudo-op only available with -mccs flag.")); | |
3075 | } | |
3076 | ||
3077 | static void | |
3078 | s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED) | |
3079 | { | |
3080 | if (codecomposer_syntax) | |
3081 | { | |
3082 | switch (asmfunc_state) | |
3083 | { | |
3084 | case OUTSIDE_ASMFUNC: | |
3085 | as_bad (_(".endasmfunc without a .asmfunc.")); | |
3086 | break; | |
3087 | ||
3088 | case WAITING_ASMFUNC_NAME: | |
3089 | as_bad (_(".endasmfunc without function.")); | |
3090 | break; | |
3091 | ||
3092 | case WAITING_ENDASMFUNC: | |
3093 | asmfunc_state = OUTSIDE_ASMFUNC; | |
3094 | asmfunc_debug (NULL); | |
3095 | break; | |
3096 | } | |
3097 | demand_empty_rest_of_line (); | |
3098 | } | |
3099 | else | |
3100 | as_bad (_(".endasmfunc pseudo-op only available with -mccs flag.")); | |
3101 | } | |
3102 | ||
3103 | static void | |
3104 | s_ccs_def (int name) | |
3105 | { | |
3106 | if (codecomposer_syntax) | |
3107 | s_globl (name); | |
3108 | else | |
3109 | as_bad (_(".def pseudo-op only available with -mccs flag.")); | |
3110 | } | |
3111 | ||
c19d1205 | 3112 | /* Directives: Literal pools. */ |
a737bd4d | 3113 | |
c19d1205 ZW |
3114 | static literal_pool * |
3115 | find_literal_pool (void) | |
a737bd4d | 3116 | { |
c19d1205 | 3117 | literal_pool * pool; |
a737bd4d | 3118 | |
c19d1205 | 3119 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3120 | { |
c19d1205 ZW |
3121 | if (pool->section == now_seg |
3122 | && pool->sub_section == now_subseg) | |
3123 | break; | |
a737bd4d NC |
3124 | } |
3125 | ||
c19d1205 | 3126 | return pool; |
a737bd4d NC |
3127 | } |
3128 | ||
c19d1205 ZW |
3129 | static literal_pool * |
3130 | find_or_make_literal_pool (void) | |
a737bd4d | 3131 | { |
c19d1205 ZW |
3132 | /* Next literal pool ID number. */ |
3133 | static unsigned int latest_pool_num = 1; | |
3134 | literal_pool * pool; | |
a737bd4d | 3135 | |
c19d1205 | 3136 | pool = find_literal_pool (); |
a737bd4d | 3137 | |
c19d1205 | 3138 | if (pool == NULL) |
a737bd4d | 3139 | { |
c19d1205 | 3140 | /* Create a new pool. */ |
21d799b5 | 3141 | pool = (literal_pool *) xmalloc (sizeof (* pool)); |
c19d1205 ZW |
3142 | if (! pool) |
3143 | return NULL; | |
a737bd4d | 3144 | |
c19d1205 ZW |
3145 | pool->next_free_entry = 0; |
3146 | pool->section = now_seg; | |
3147 | pool->sub_section = now_subseg; | |
3148 | pool->next = list_of_pools; | |
3149 | pool->symbol = NULL; | |
8335d6aa | 3150 | pool->alignment = 2; |
c19d1205 ZW |
3151 | |
3152 | /* Add it to the list. */ | |
3153 | list_of_pools = pool; | |
a737bd4d | 3154 | } |
a737bd4d | 3155 | |
c19d1205 ZW |
3156 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3157 | if (pool->symbol == NULL) | |
a737bd4d | 3158 | { |
c19d1205 ZW |
3159 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
3160 | (valueT) 0, &zero_address_frag); | |
3161 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
3162 | } |
3163 | ||
c19d1205 ZW |
3164 | /* Done. */ |
3165 | return pool; | |
a737bd4d NC |
3166 | } |
3167 | ||
c19d1205 | 3168 | /* Add the literal in the global 'inst' |
5f4273c7 | 3169 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3170 | |
3171 | static int | |
8335d6aa | 3172 | add_to_lit_pool (unsigned int nbytes) |
b99bd4ef | 3173 | { |
8335d6aa JW |
3174 | #define PADDING_SLOT 0x1 |
3175 | #define LIT_ENTRY_SIZE_MASK 0xFF | |
c19d1205 | 3176 | literal_pool * pool; |
8335d6aa JW |
3177 | unsigned int entry, pool_size = 0; |
3178 | bfd_boolean padding_slot_p = FALSE; | |
e56c722b | 3179 | unsigned imm1 = 0; |
8335d6aa JW |
3180 | unsigned imm2 = 0; |
3181 | ||
3182 | if (nbytes == 8) | |
3183 | { | |
3184 | imm1 = inst.operands[1].imm; | |
3185 | imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg | |
3186 | : inst.reloc.exp.X_unsigned ? 0 | |
2569ceb0 | 3187 | : ((bfd_int64_t) inst.operands[1].imm) >> 32); |
8335d6aa JW |
3188 | if (target_big_endian) |
3189 | { | |
3190 | imm1 = imm2; | |
3191 | imm2 = inst.operands[1].imm; | |
3192 | } | |
3193 | } | |
b99bd4ef | 3194 | |
c19d1205 ZW |
3195 | pool = find_or_make_literal_pool (); |
3196 | ||
3197 | /* Check if this literal value is already in the pool. */ | |
3198 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3199 | { |
8335d6aa JW |
3200 | if (nbytes == 4) |
3201 | { | |
3202 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
3203 | && (inst.reloc.exp.X_op == O_constant) | |
3204 | && (pool->literals[entry].X_add_number | |
3205 | == inst.reloc.exp.X_add_number) | |
3206 | && (pool->literals[entry].X_md == nbytes) | |
3207 | && (pool->literals[entry].X_unsigned | |
3208 | == inst.reloc.exp.X_unsigned)) | |
3209 | break; | |
3210 | ||
3211 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
3212 | && (inst.reloc.exp.X_op == O_symbol) | |
3213 | && (pool->literals[entry].X_add_number | |
3214 | == inst.reloc.exp.X_add_number) | |
3215 | && (pool->literals[entry].X_add_symbol | |
3216 | == inst.reloc.exp.X_add_symbol) | |
3217 | && (pool->literals[entry].X_op_symbol | |
3218 | == inst.reloc.exp.X_op_symbol) | |
3219 | && (pool->literals[entry].X_md == nbytes)) | |
3220 | break; | |
3221 | } | |
3222 | else if ((nbytes == 8) | |
3223 | && !(pool_size & 0x7) | |
3224 | && ((entry + 1) != pool->next_free_entry) | |
3225 | && (pool->literals[entry].X_op == O_constant) | |
19f2f6a9 | 3226 | && (pool->literals[entry].X_add_number == (offsetT) imm1) |
8335d6aa JW |
3227 | && (pool->literals[entry].X_unsigned |
3228 | == inst.reloc.exp.X_unsigned) | |
3229 | && (pool->literals[entry + 1].X_op == O_constant) | |
19f2f6a9 | 3230 | && (pool->literals[entry + 1].X_add_number == (offsetT) imm2) |
8335d6aa JW |
3231 | && (pool->literals[entry + 1].X_unsigned |
3232 | == inst.reloc.exp.X_unsigned)) | |
c19d1205 ZW |
3233 | break; |
3234 | ||
8335d6aa JW |
3235 | padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT); |
3236 | if (padding_slot_p && (nbytes == 4)) | |
c19d1205 | 3237 | break; |
8335d6aa JW |
3238 | |
3239 | pool_size += 4; | |
b99bd4ef NC |
3240 | } |
3241 | ||
c19d1205 ZW |
3242 | /* Do we need to create a new entry? */ |
3243 | if (entry == pool->next_free_entry) | |
3244 | { | |
3245 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3246 | { | |
3247 | inst.error = _("literal pool overflow"); | |
3248 | return FAIL; | |
3249 | } | |
3250 | ||
8335d6aa JW |
3251 | if (nbytes == 8) |
3252 | { | |
3253 | /* For 8-byte entries, we align to an 8-byte boundary, | |
3254 | and split it into two 4-byte entries, because on 32-bit | |
3255 | host, 8-byte constants are treated as big num, thus | |
3256 | saved in "generic_bignum" which will be overwritten | |
3257 | by later assignments. | |
3258 | ||
3259 | We also need to make sure there is enough space for | |
3260 | the split. | |
3261 | ||
3262 | We also check to make sure the literal operand is a | |
3263 | constant number. */ | |
19f2f6a9 JW |
3264 | if (!(inst.reloc.exp.X_op == O_constant |
3265 | || inst.reloc.exp.X_op == O_big)) | |
8335d6aa JW |
3266 | { |
3267 | inst.error = _("invalid type for literal pool"); | |
3268 | return FAIL; | |
3269 | } | |
3270 | else if (pool_size & 0x7) | |
3271 | { | |
3272 | if ((entry + 2) >= MAX_LITERAL_POOL_SIZE) | |
3273 | { | |
3274 | inst.error = _("literal pool overflow"); | |
3275 | return FAIL; | |
3276 | } | |
3277 | ||
3278 | pool->literals[entry] = inst.reloc.exp; | |
3279 | pool->literals[entry].X_add_number = 0; | |
3280 | pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4; | |
3281 | pool->next_free_entry += 1; | |
3282 | pool_size += 4; | |
3283 | } | |
3284 | else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE) | |
3285 | { | |
3286 | inst.error = _("literal pool overflow"); | |
3287 | return FAIL; | |
3288 | } | |
3289 | ||
3290 | pool->literals[entry] = inst.reloc.exp; | |
3291 | pool->literals[entry].X_op = O_constant; | |
3292 | pool->literals[entry].X_add_number = imm1; | |
3293 | pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned; | |
3294 | pool->literals[entry++].X_md = 4; | |
3295 | pool->literals[entry] = inst.reloc.exp; | |
3296 | pool->literals[entry].X_op = O_constant; | |
3297 | pool->literals[entry].X_add_number = imm2; | |
3298 | pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned; | |
3299 | pool->literals[entry].X_md = 4; | |
3300 | pool->alignment = 3; | |
3301 | pool->next_free_entry += 1; | |
3302 | } | |
3303 | else | |
3304 | { | |
3305 | pool->literals[entry] = inst.reloc.exp; | |
3306 | pool->literals[entry].X_md = 4; | |
3307 | } | |
3308 | ||
a8040cf2 NC |
3309 | #ifdef OBJ_ELF |
3310 | /* PR ld/12974: Record the location of the first source line to reference | |
3311 | this entry in the literal pool. If it turns out during linking that the | |
3312 | symbol does not exist we will be able to give an accurate line number for | |
3313 | the (first use of the) missing reference. */ | |
3314 | if (debug_type == DEBUG_DWARF2) | |
3315 | dwarf2_where (pool->locs + entry); | |
3316 | #endif | |
c19d1205 ZW |
3317 | pool->next_free_entry += 1; |
3318 | } | |
8335d6aa JW |
3319 | else if (padding_slot_p) |
3320 | { | |
3321 | pool->literals[entry] = inst.reloc.exp; | |
3322 | pool->literals[entry].X_md = nbytes; | |
3323 | } | |
b99bd4ef | 3324 | |
c19d1205 | 3325 | inst.reloc.exp.X_op = O_symbol; |
8335d6aa | 3326 | inst.reloc.exp.X_add_number = pool_size; |
c19d1205 | 3327 | inst.reloc.exp.X_add_symbol = pool->symbol; |
b99bd4ef | 3328 | |
c19d1205 | 3329 | return SUCCESS; |
b99bd4ef NC |
3330 | } |
3331 | ||
2e6976a8 | 3332 | bfd_boolean |
2e57ce7b | 3333 | tc_start_label_without_colon (void) |
2e6976a8 DG |
3334 | { |
3335 | bfd_boolean ret = TRUE; | |
3336 | ||
3337 | if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME) | |
3338 | { | |
2e57ce7b | 3339 | const char *label = input_line_pointer; |
2e6976a8 DG |
3340 | |
3341 | while (!is_end_of_line[(int) label[-1]]) | |
3342 | --label; | |
3343 | ||
3344 | if (*label == '.') | |
3345 | { | |
3346 | as_bad (_("Invalid label '%s'"), label); | |
3347 | ret = FALSE; | |
3348 | } | |
3349 | ||
3350 | asmfunc_debug (label); | |
3351 | ||
3352 | asmfunc_state = WAITING_ENDASMFUNC; | |
3353 | } | |
3354 | ||
3355 | return ret; | |
3356 | } | |
3357 | ||
c19d1205 ZW |
3358 | /* Can't use symbol_new here, so have to create a symbol and then at |
3359 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 3360 | |
c19d1205 ZW |
3361 | static void |
3362 | symbol_locate (symbolS * symbolP, | |
3363 | const char * name, /* It is copied, the caller can modify. */ | |
3364 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3365 | valueT valu, /* Symbol value. */ | |
3366 | fragS * frag) /* Associated fragment. */ | |
3367 | { | |
e57e6ddc | 3368 | size_t name_length; |
c19d1205 | 3369 | char * preserved_copy_of_name; |
e16bb312 | 3370 | |
c19d1205 ZW |
3371 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3372 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3373 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3374 | |
c19d1205 ZW |
3375 | #ifdef tc_canonicalize_symbol_name |
3376 | preserved_copy_of_name = | |
3377 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3378 | #endif | |
b99bd4ef | 3379 | |
c19d1205 | 3380 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3381 | |
c19d1205 ZW |
3382 | S_SET_SEGMENT (symbolP, segment); |
3383 | S_SET_VALUE (symbolP, valu); | |
3384 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3385 | |
c19d1205 | 3386 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3387 | |
c19d1205 ZW |
3388 | /* Link to end of symbol chain. */ |
3389 | { | |
3390 | extern int symbol_table_frozen; | |
b99bd4ef | 3391 | |
c19d1205 ZW |
3392 | if (symbol_table_frozen) |
3393 | abort (); | |
3394 | } | |
b99bd4ef | 3395 | |
c19d1205 | 3396 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3397 | |
c19d1205 | 3398 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3399 | |
c19d1205 ZW |
3400 | #ifdef tc_symbol_new_hook |
3401 | tc_symbol_new_hook (symbolP); | |
3402 | #endif | |
3403 | ||
3404 | #ifdef DEBUG_SYMS | |
3405 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3406 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3407 | } |
3408 | ||
c19d1205 ZW |
3409 | static void |
3410 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3411 | { |
c19d1205 ZW |
3412 | unsigned int entry; |
3413 | literal_pool * pool; | |
3414 | char sym_name[20]; | |
b99bd4ef | 3415 | |
c19d1205 ZW |
3416 | pool = find_literal_pool (); |
3417 | if (pool == NULL | |
3418 | || pool->symbol == NULL | |
3419 | || pool->next_free_entry == 0) | |
3420 | return; | |
b99bd4ef | 3421 | |
c19d1205 ZW |
3422 | /* Align pool as you have word accesses. |
3423 | Only make a frag if we have to. */ | |
3424 | if (!need_pass_2) | |
8335d6aa | 3425 | frag_align (pool->alignment, 0, 0); |
b99bd4ef | 3426 | |
c19d1205 | 3427 | record_alignment (now_seg, 2); |
b99bd4ef | 3428 | |
aaca88ef | 3429 | #ifdef OBJ_ELF |
47fc6e36 WN |
3430 | seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA; |
3431 | make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now); | |
aaca88ef | 3432 | #endif |
c19d1205 | 3433 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3434 | |
c19d1205 ZW |
3435 | symbol_locate (pool->symbol, sym_name, now_seg, |
3436 | (valueT) frag_now_fix (), frag_now); | |
3437 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3438 | |
c19d1205 | 3439 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3440 | |
c19d1205 ZW |
3441 | #if defined OBJ_COFF || defined OBJ_ELF |
3442 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3443 | #endif | |
6c43fab6 | 3444 | |
c19d1205 | 3445 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
3446 | { |
3447 | #ifdef OBJ_ELF | |
3448 | if (debug_type == DEBUG_DWARF2) | |
3449 | dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry); | |
3450 | #endif | |
3451 | /* First output the expression in the instruction to the pool. */ | |
8335d6aa JW |
3452 | emit_expr (&(pool->literals[entry]), |
3453 | pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK); | |
a8040cf2 | 3454 | } |
b99bd4ef | 3455 | |
c19d1205 ZW |
3456 | /* Mark the pool as empty. */ |
3457 | pool->next_free_entry = 0; | |
3458 | pool->symbol = NULL; | |
b99bd4ef NC |
3459 | } |
3460 | ||
c19d1205 ZW |
3461 | #ifdef OBJ_ELF |
3462 | /* Forward declarations for functions below, in the MD interface | |
3463 | section. */ | |
3464 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3465 | static valueT create_unwind_entry (int); | |
3466 | static void start_unwind_section (const segT, int); | |
3467 | static void add_unwind_opcode (valueT, int); | |
3468 | static void flush_pending_unwind (void); | |
b99bd4ef | 3469 | |
c19d1205 | 3470 | /* Directives: Data. */ |
b99bd4ef | 3471 | |
c19d1205 ZW |
3472 | static void |
3473 | s_arm_elf_cons (int nbytes) | |
3474 | { | |
3475 | expressionS exp; | |
b99bd4ef | 3476 | |
c19d1205 ZW |
3477 | #ifdef md_flush_pending_output |
3478 | md_flush_pending_output (); | |
3479 | #endif | |
b99bd4ef | 3480 | |
c19d1205 | 3481 | if (is_it_end_of_statement ()) |
b99bd4ef | 3482 | { |
c19d1205 ZW |
3483 | demand_empty_rest_of_line (); |
3484 | return; | |
b99bd4ef NC |
3485 | } |
3486 | ||
c19d1205 ZW |
3487 | #ifdef md_cons_align |
3488 | md_cons_align (nbytes); | |
3489 | #endif | |
b99bd4ef | 3490 | |
c19d1205 ZW |
3491 | mapping_state (MAP_DATA); |
3492 | do | |
b99bd4ef | 3493 | { |
c19d1205 ZW |
3494 | int reloc; |
3495 | char *base = input_line_pointer; | |
b99bd4ef | 3496 | |
c19d1205 | 3497 | expression (& exp); |
b99bd4ef | 3498 | |
c19d1205 ZW |
3499 | if (exp.X_op != O_symbol) |
3500 | emit_expr (&exp, (unsigned int) nbytes); | |
3501 | else | |
3502 | { | |
3503 | char *before_reloc = input_line_pointer; | |
3504 | reloc = parse_reloc (&input_line_pointer); | |
3505 | if (reloc == -1) | |
3506 | { | |
3507 | as_bad (_("unrecognized relocation suffix")); | |
3508 | ignore_rest_of_line (); | |
3509 | return; | |
3510 | } | |
3511 | else if (reloc == BFD_RELOC_UNUSED) | |
3512 | emit_expr (&exp, (unsigned int) nbytes); | |
3513 | else | |
3514 | { | |
21d799b5 | 3515 | reloc_howto_type *howto = (reloc_howto_type *) |
477330fc RM |
3516 | bfd_reloc_type_lookup (stdoutput, |
3517 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3518 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3519 | |
2fc8bdac ZW |
3520 | if (reloc == BFD_RELOC_ARM_PLT32) |
3521 | { | |
3522 | as_bad (_("(plt) is only valid on branch targets")); | |
3523 | reloc = BFD_RELOC_UNUSED; | |
3524 | size = 0; | |
3525 | } | |
3526 | ||
c19d1205 | 3527 | if (size > nbytes) |
2fc8bdac | 3528 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3529 | howto->name, nbytes); |
3530 | else | |
3531 | { | |
3532 | /* We've parsed an expression stopping at O_symbol. | |
3533 | But there may be more expression left now that we | |
3534 | have parsed the relocation marker. Parse it again. | |
3535 | XXX Surely there is a cleaner way to do this. */ | |
3536 | char *p = input_line_pointer; | |
3537 | int offset; | |
e1fa0163 NC |
3538 | char *save_buf = xmalloc (input_line_pointer - base); |
3539 | ||
c19d1205 ZW |
3540 | memcpy (save_buf, base, input_line_pointer - base); |
3541 | memmove (base + (input_line_pointer - before_reloc), | |
3542 | base, before_reloc - base); | |
3543 | ||
3544 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3545 | expression (&exp); | |
3546 | memcpy (base, save_buf, p - base); | |
3547 | ||
3548 | offset = nbytes - size; | |
4b1a927e AM |
3549 | p = frag_more (nbytes); |
3550 | memset (p, 0, nbytes); | |
c19d1205 | 3551 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, |
21d799b5 | 3552 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
e1fa0163 | 3553 | free (save_buf); |
c19d1205 ZW |
3554 | } |
3555 | } | |
3556 | } | |
b99bd4ef | 3557 | } |
c19d1205 | 3558 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3559 | |
c19d1205 ZW |
3560 | /* Put terminator back into stream. */ |
3561 | input_line_pointer --; | |
3562 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3563 | } |
3564 | ||
c921be7d NC |
3565 | /* Emit an expression containing a 32-bit thumb instruction. |
3566 | Implementation based on put_thumb32_insn. */ | |
3567 | ||
3568 | static void | |
3569 | emit_thumb32_expr (expressionS * exp) | |
3570 | { | |
3571 | expressionS exp_high = *exp; | |
3572 | ||
3573 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3574 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3575 | exp->X_add_number &= 0xffff; | |
3576 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3577 | } | |
3578 | ||
3579 | /* Guess the instruction size based on the opcode. */ | |
3580 | ||
3581 | static int | |
3582 | thumb_insn_size (int opcode) | |
3583 | { | |
3584 | if ((unsigned int) opcode < 0xe800u) | |
3585 | return 2; | |
3586 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3587 | return 4; | |
3588 | else | |
3589 | return 0; | |
3590 | } | |
3591 | ||
3592 | static bfd_boolean | |
3593 | emit_insn (expressionS *exp, int nbytes) | |
3594 | { | |
3595 | int size = 0; | |
3596 | ||
3597 | if (exp->X_op == O_constant) | |
3598 | { | |
3599 | size = nbytes; | |
3600 | ||
3601 | if (size == 0) | |
3602 | size = thumb_insn_size (exp->X_add_number); | |
3603 | ||
3604 | if (size != 0) | |
3605 | { | |
3606 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3607 | { | |
3608 | as_bad (_(".inst.n operand too big. "\ | |
3609 | "Use .inst.w instead")); | |
3610 | size = 0; | |
3611 | } | |
3612 | else | |
3613 | { | |
3614 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3615 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3616 | else | |
3617 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3618 | ||
3619 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3620 | emit_thumb32_expr (exp); | |
3621 | else | |
3622 | emit_expr (exp, (unsigned int) size); | |
3623 | ||
3624 | it_fsm_post_encode (); | |
3625 | } | |
3626 | } | |
3627 | else | |
3628 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3629 | "Use .inst.n/.inst.w instead")); | |
3630 | } | |
3631 | else | |
3632 | as_bad (_("constant expression required")); | |
3633 | ||
3634 | return (size != 0); | |
3635 | } | |
3636 | ||
3637 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3638 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3639 | ||
3640 | static void | |
3641 | s_arm_elf_inst (int nbytes) | |
3642 | { | |
3643 | if (is_it_end_of_statement ()) | |
3644 | { | |
3645 | demand_empty_rest_of_line (); | |
3646 | return; | |
3647 | } | |
3648 | ||
3649 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3650 | but will ensure not to be in DATA state. */ | |
3651 | ||
3652 | if (thumb_mode) | |
3653 | mapping_state (MAP_THUMB); | |
3654 | else | |
3655 | { | |
3656 | if (nbytes != 0) | |
3657 | { | |
3658 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3659 | ignore_rest_of_line (); | |
3660 | return; | |
3661 | } | |
3662 | ||
3663 | nbytes = 4; | |
3664 | ||
3665 | mapping_state (MAP_ARM); | |
3666 | } | |
3667 | ||
3668 | do | |
3669 | { | |
3670 | expressionS exp; | |
3671 | ||
3672 | expression (& exp); | |
3673 | ||
3674 | if (! emit_insn (& exp, nbytes)) | |
3675 | { | |
3676 | ignore_rest_of_line (); | |
3677 | return; | |
3678 | } | |
3679 | } | |
3680 | while (*input_line_pointer++ == ','); | |
3681 | ||
3682 | /* Put terminator back into stream. */ | |
3683 | input_line_pointer --; | |
3684 | demand_empty_rest_of_line (); | |
3685 | } | |
b99bd4ef | 3686 | |
c19d1205 | 3687 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3688 | |
c19d1205 ZW |
3689 | static void |
3690 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3691 | { | |
3692 | expressionS exp; | |
3693 | char *p; | |
3694 | valueT highbit; | |
b99bd4ef | 3695 | |
c19d1205 ZW |
3696 | highbit = 0; |
3697 | if (*input_line_pointer == '1') | |
3698 | highbit = 0x80000000; | |
3699 | else if (*input_line_pointer != '0') | |
3700 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3701 | |
c19d1205 ZW |
3702 | input_line_pointer++; |
3703 | if (*input_line_pointer != ',') | |
3704 | as_bad (_("missing comma")); | |
3705 | input_line_pointer++; | |
b99bd4ef | 3706 | |
c19d1205 ZW |
3707 | #ifdef md_flush_pending_output |
3708 | md_flush_pending_output (); | |
3709 | #endif | |
b99bd4ef | 3710 | |
c19d1205 ZW |
3711 | #ifdef md_cons_align |
3712 | md_cons_align (4); | |
3713 | #endif | |
b99bd4ef | 3714 | |
c19d1205 | 3715 | mapping_state (MAP_DATA); |
b99bd4ef | 3716 | |
c19d1205 | 3717 | expression (&exp); |
b99bd4ef | 3718 | |
c19d1205 ZW |
3719 | p = frag_more (4); |
3720 | md_number_to_chars (p, highbit, 4); | |
3721 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3722 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3723 | |
c19d1205 | 3724 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3725 | } |
3726 | ||
c19d1205 | 3727 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3728 | |
c19d1205 | 3729 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3730 | |
c19d1205 ZW |
3731 | static void |
3732 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3733 | { | |
3734 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3735 | if (unwind.proc_start) |
3736 | { | |
c921be7d | 3737 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3738 | return; |
3739 | } | |
3740 | ||
c19d1205 ZW |
3741 | /* Mark the start of the function. */ |
3742 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3743 | |
c19d1205 ZW |
3744 | /* Reset the rest of the unwind info. */ |
3745 | unwind.opcode_count = 0; | |
3746 | unwind.table_entry = NULL; | |
3747 | unwind.personality_routine = NULL; | |
3748 | unwind.personality_index = -1; | |
3749 | unwind.frame_size = 0; | |
3750 | unwind.fp_offset = 0; | |
fdfde340 | 3751 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3752 | unwind.fp_used = 0; |
3753 | unwind.sp_restored = 0; | |
3754 | } | |
b99bd4ef | 3755 | |
b99bd4ef | 3756 | |
c19d1205 ZW |
3757 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3758 | for the function. */ | |
b99bd4ef | 3759 | |
c19d1205 ZW |
3760 | static void |
3761 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3762 | { | |
3763 | demand_empty_rest_of_line (); | |
921e5f0a | 3764 | if (!unwind.proc_start) |
c921be7d | 3765 | as_bad (MISSING_FNSTART); |
921e5f0a | 3766 | |
c19d1205 | 3767 | if (unwind.table_entry) |
6decc662 | 3768 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3769 | |
c19d1205 ZW |
3770 | create_unwind_entry (1); |
3771 | } | |
a737bd4d | 3772 | |
c19d1205 | 3773 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3774 | |
c19d1205 ZW |
3775 | static void |
3776 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3777 | { | |
3778 | long where; | |
3779 | char *ptr; | |
3780 | valueT val; | |
940b5ce0 | 3781 | unsigned int marked_pr_dependency; |
f02232aa | 3782 | |
c19d1205 | 3783 | demand_empty_rest_of_line (); |
f02232aa | 3784 | |
921e5f0a PB |
3785 | if (!unwind.proc_start) |
3786 | { | |
c921be7d | 3787 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3788 | return; |
3789 | } | |
3790 | ||
c19d1205 ZW |
3791 | /* Add eh table entry. */ |
3792 | if (unwind.table_entry == NULL) | |
3793 | val = create_unwind_entry (0); | |
3794 | else | |
3795 | val = 0; | |
f02232aa | 3796 | |
c19d1205 ZW |
3797 | /* Add index table entry. This is two words. */ |
3798 | start_unwind_section (unwind.saved_seg, 1); | |
3799 | frag_align (2, 0, 0); | |
3800 | record_alignment (now_seg, 2); | |
b99bd4ef | 3801 | |
c19d1205 | 3802 | ptr = frag_more (8); |
5011093d | 3803 | memset (ptr, 0, 8); |
c19d1205 | 3804 | where = frag_now_fix () - 8; |
f02232aa | 3805 | |
c19d1205 ZW |
3806 | /* Self relative offset of the function start. */ |
3807 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3808 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3809 | |
c19d1205 ZW |
3810 | /* Indicate dependency on EHABI-defined personality routines to the |
3811 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3812 | marked_pr_dependency |
3813 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3814 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3815 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3816 | { | |
5f4273c7 NC |
3817 | static const char *const name[] = |
3818 | { | |
3819 | "__aeabi_unwind_cpp_pr0", | |
3820 | "__aeabi_unwind_cpp_pr1", | |
3821 | "__aeabi_unwind_cpp_pr2" | |
3822 | }; | |
c19d1205 ZW |
3823 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3824 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3825 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3826 | |= 1 << unwind.personality_index; |
c19d1205 | 3827 | } |
f02232aa | 3828 | |
c19d1205 ZW |
3829 | if (val) |
3830 | /* Inline exception table entry. */ | |
3831 | md_number_to_chars (ptr + 4, val, 4); | |
3832 | else | |
3833 | /* Self relative offset of the table entry. */ | |
3834 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3835 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3836 | |
c19d1205 ZW |
3837 | /* Restore the original section. */ |
3838 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3839 | |
3840 | unwind.proc_start = NULL; | |
c19d1205 | 3841 | } |
f02232aa | 3842 | |
f02232aa | 3843 | |
c19d1205 | 3844 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3845 | |
c19d1205 ZW |
3846 | static void |
3847 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3848 | { | |
3849 | demand_empty_rest_of_line (); | |
921e5f0a | 3850 | if (!unwind.proc_start) |
c921be7d | 3851 | as_bad (MISSING_FNSTART); |
921e5f0a | 3852 | |
c19d1205 ZW |
3853 | if (unwind.personality_routine || unwind.personality_index != -1) |
3854 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3855 | |
c19d1205 ZW |
3856 | unwind.personality_index = -2; |
3857 | } | |
b99bd4ef | 3858 | |
b99bd4ef | 3859 | |
c19d1205 | 3860 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3861 | |
c19d1205 ZW |
3862 | static void |
3863 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3864 | { | |
3865 | expressionS exp; | |
b99bd4ef | 3866 | |
921e5f0a | 3867 | if (!unwind.proc_start) |
c921be7d | 3868 | as_bad (MISSING_FNSTART); |
921e5f0a | 3869 | |
c19d1205 ZW |
3870 | if (unwind.personality_routine || unwind.personality_index != -1) |
3871 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3872 | |
c19d1205 | 3873 | expression (&exp); |
b99bd4ef | 3874 | |
c19d1205 ZW |
3875 | if (exp.X_op != O_constant |
3876 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3877 | { |
c19d1205 ZW |
3878 | as_bad (_("bad personality routine number")); |
3879 | ignore_rest_of_line (); | |
3880 | return; | |
b99bd4ef NC |
3881 | } |
3882 | ||
c19d1205 | 3883 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3884 | |
c19d1205 ZW |
3885 | demand_empty_rest_of_line (); |
3886 | } | |
e16bb312 | 3887 | |
e16bb312 | 3888 | |
c19d1205 | 3889 | /* Parse a personality directive. */ |
e16bb312 | 3890 | |
c19d1205 ZW |
3891 | static void |
3892 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3893 | { | |
3894 | char *name, *p, c; | |
a737bd4d | 3895 | |
921e5f0a | 3896 | if (!unwind.proc_start) |
c921be7d | 3897 | as_bad (MISSING_FNSTART); |
921e5f0a | 3898 | |
c19d1205 ZW |
3899 | if (unwind.personality_routine || unwind.personality_index != -1) |
3900 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3901 | |
d02603dc | 3902 | c = get_symbol_name (& name); |
c19d1205 | 3903 | p = input_line_pointer; |
d02603dc NC |
3904 | if (c == '"') |
3905 | ++ input_line_pointer; | |
c19d1205 ZW |
3906 | unwind.personality_routine = symbol_find_or_make (name); |
3907 | *p = c; | |
3908 | demand_empty_rest_of_line (); | |
3909 | } | |
e16bb312 | 3910 | |
e16bb312 | 3911 | |
c19d1205 | 3912 | /* Parse a directive saving core registers. */ |
e16bb312 | 3913 | |
c19d1205 ZW |
3914 | static void |
3915 | s_arm_unwind_save_core (void) | |
e16bb312 | 3916 | { |
c19d1205 ZW |
3917 | valueT op; |
3918 | long range; | |
3919 | int n; | |
e16bb312 | 3920 | |
c19d1205 ZW |
3921 | range = parse_reg_list (&input_line_pointer); |
3922 | if (range == FAIL) | |
e16bb312 | 3923 | { |
c19d1205 ZW |
3924 | as_bad (_("expected register list")); |
3925 | ignore_rest_of_line (); | |
3926 | return; | |
3927 | } | |
e16bb312 | 3928 | |
c19d1205 | 3929 | demand_empty_rest_of_line (); |
e16bb312 | 3930 | |
c19d1205 ZW |
3931 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3932 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3933 | ip because it is clobbered by calls. */ | |
3934 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3935 | && (range & 0x3000) == 0x1000) | |
3936 | { | |
3937 | unwind.opcode_count--; | |
3938 | unwind.sp_restored = 0; | |
3939 | range = (range | 0x2000) & ~0x1000; | |
3940 | unwind.pending_offset = 0; | |
3941 | } | |
e16bb312 | 3942 | |
01ae4198 DJ |
3943 | /* Pop r4-r15. */ |
3944 | if (range & 0xfff0) | |
c19d1205 | 3945 | { |
01ae4198 DJ |
3946 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3947 | registers starting with r4, plus maybe r14. */ | |
3948 | for (n = 0; n < 8; n++) | |
3949 | { | |
3950 | /* Break at the first non-saved register. */ | |
3951 | if ((range & (1 << (n + 4))) == 0) | |
3952 | break; | |
3953 | } | |
3954 | /* See if there are any other bits set. */ | |
3955 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3956 | { | |
3957 | /* Use the long form. */ | |
3958 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3959 | add_unwind_opcode (op, 2); | |
3960 | } | |
0dd132b6 | 3961 | else |
01ae4198 DJ |
3962 | { |
3963 | /* Use the short form. */ | |
3964 | if (range & 0x4000) | |
3965 | op = 0xa8; /* Pop r14. */ | |
3966 | else | |
3967 | op = 0xa0; /* Do not pop r14. */ | |
3968 | op |= (n - 1); | |
3969 | add_unwind_opcode (op, 1); | |
3970 | } | |
c19d1205 | 3971 | } |
0dd132b6 | 3972 | |
c19d1205 ZW |
3973 | /* Pop r0-r3. */ |
3974 | if (range & 0xf) | |
3975 | { | |
3976 | op = 0xb100 | (range & 0xf); | |
3977 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3978 | } |
3979 | ||
c19d1205 ZW |
3980 | /* Record the number of bytes pushed. */ |
3981 | for (n = 0; n < 16; n++) | |
3982 | { | |
3983 | if (range & (1 << n)) | |
3984 | unwind.frame_size += 4; | |
3985 | } | |
0dd132b6 NC |
3986 | } |
3987 | ||
c19d1205 ZW |
3988 | |
3989 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3990 | |
3991 | static void | |
c19d1205 | 3992 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3993 | { |
c19d1205 ZW |
3994 | expressionS exp; |
3995 | int num_regs; | |
3996 | valueT op; | |
b99bd4ef | 3997 | |
c19d1205 ZW |
3998 | /* Get Number of registers to transfer. */ |
3999 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4000 | expression (&exp); | |
4001 | else | |
4002 | exp.X_op = O_illegal; | |
b99bd4ef | 4003 | |
c19d1205 | 4004 | if (exp.X_op != O_constant) |
b99bd4ef | 4005 | { |
c19d1205 ZW |
4006 | as_bad (_("expected , <constant>")); |
4007 | ignore_rest_of_line (); | |
b99bd4ef NC |
4008 | return; |
4009 | } | |
4010 | ||
c19d1205 ZW |
4011 | num_regs = exp.X_add_number; |
4012 | ||
4013 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 4014 | { |
c19d1205 ZW |
4015 | as_bad (_("number of registers must be in the range [1:4]")); |
4016 | ignore_rest_of_line (); | |
b99bd4ef NC |
4017 | return; |
4018 | } | |
4019 | ||
c19d1205 | 4020 | demand_empty_rest_of_line (); |
b99bd4ef | 4021 | |
c19d1205 ZW |
4022 | if (reg == 4) |
4023 | { | |
4024 | /* Short form. */ | |
4025 | op = 0xb4 | (num_regs - 1); | |
4026 | add_unwind_opcode (op, 1); | |
4027 | } | |
b99bd4ef NC |
4028 | else |
4029 | { | |
c19d1205 ZW |
4030 | /* Long form. */ |
4031 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
4032 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4033 | } |
c19d1205 | 4034 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
4035 | } |
4036 | ||
c19d1205 | 4037 | |
fa073d69 MS |
4038 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
4039 | ||
4040 | static void | |
4041 | s_arm_unwind_save_vfp_armv6 (void) | |
4042 | { | |
4043 | int count; | |
4044 | unsigned int start; | |
4045 | valueT op; | |
4046 | int num_vfpv3_regs = 0; | |
4047 | int num_regs_below_16; | |
4048 | ||
4049 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
4050 | if (count == FAIL) | |
4051 | { | |
4052 | as_bad (_("expected register list")); | |
4053 | ignore_rest_of_line (); | |
4054 | return; | |
4055 | } | |
4056 | ||
4057 | demand_empty_rest_of_line (); | |
4058 | ||
4059 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
4060 | than FSTMX/FLDMX-style ones). */ | |
4061 | ||
4062 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
4063 | if (start >= 16) | |
4064 | num_vfpv3_regs = count; | |
4065 | else if (start + count > 16) | |
4066 | num_vfpv3_regs = start + count - 16; | |
4067 | ||
4068 | if (num_vfpv3_regs > 0) | |
4069 | { | |
4070 | int start_offset = start > 16 ? start - 16 : 0; | |
4071 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
4072 | add_unwind_opcode (op, 2); | |
4073 | } | |
4074 | ||
4075 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
4076 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 4077 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
4078 | if (num_regs_below_16 > 0) |
4079 | { | |
4080 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
4081 | add_unwind_opcode (op, 2); | |
4082 | } | |
4083 | ||
4084 | unwind.frame_size += count * 8; | |
4085 | } | |
4086 | ||
4087 | ||
4088 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
4089 | |
4090 | static void | |
c19d1205 | 4091 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 4092 | { |
c19d1205 | 4093 | int count; |
ca3f61f7 | 4094 | unsigned int reg; |
c19d1205 | 4095 | valueT op; |
b99bd4ef | 4096 | |
5287ad62 | 4097 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 4098 | if (count == FAIL) |
b99bd4ef | 4099 | { |
c19d1205 ZW |
4100 | as_bad (_("expected register list")); |
4101 | ignore_rest_of_line (); | |
b99bd4ef NC |
4102 | return; |
4103 | } | |
4104 | ||
c19d1205 | 4105 | demand_empty_rest_of_line (); |
b99bd4ef | 4106 | |
c19d1205 | 4107 | if (reg == 8) |
b99bd4ef | 4108 | { |
c19d1205 ZW |
4109 | /* Short form. */ |
4110 | op = 0xb8 | (count - 1); | |
4111 | add_unwind_opcode (op, 1); | |
b99bd4ef | 4112 | } |
c19d1205 | 4113 | else |
b99bd4ef | 4114 | { |
c19d1205 ZW |
4115 | /* Long form. */ |
4116 | op = 0xb300 | (reg << 4) | (count - 1); | |
4117 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4118 | } |
c19d1205 ZW |
4119 | unwind.frame_size += count * 8 + 4; |
4120 | } | |
b99bd4ef | 4121 | |
b99bd4ef | 4122 | |
c19d1205 ZW |
4123 | /* Parse a directive saving iWMMXt data registers. */ |
4124 | ||
4125 | static void | |
4126 | s_arm_unwind_save_mmxwr (void) | |
4127 | { | |
4128 | int reg; | |
4129 | int hi_reg; | |
4130 | int i; | |
4131 | unsigned mask = 0; | |
4132 | valueT op; | |
b99bd4ef | 4133 | |
c19d1205 ZW |
4134 | if (*input_line_pointer == '{') |
4135 | input_line_pointer++; | |
b99bd4ef | 4136 | |
c19d1205 | 4137 | do |
b99bd4ef | 4138 | { |
dcbf9037 | 4139 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 4140 | |
c19d1205 | 4141 | if (reg == FAIL) |
b99bd4ef | 4142 | { |
9b7132d3 | 4143 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 4144 | goto error; |
b99bd4ef NC |
4145 | } |
4146 | ||
c19d1205 ZW |
4147 | if (mask >> reg) |
4148 | as_tsktsk (_("register list not in ascending order")); | |
4149 | mask |= 1 << reg; | |
b99bd4ef | 4150 | |
c19d1205 ZW |
4151 | if (*input_line_pointer == '-') |
4152 | { | |
4153 | input_line_pointer++; | |
dcbf9037 | 4154 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
4155 | if (hi_reg == FAIL) |
4156 | { | |
9b7132d3 | 4157 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
4158 | goto error; |
4159 | } | |
4160 | else if (reg >= hi_reg) | |
4161 | { | |
4162 | as_bad (_("bad register range")); | |
4163 | goto error; | |
4164 | } | |
4165 | for (; reg < hi_reg; reg++) | |
4166 | mask |= 1 << reg; | |
4167 | } | |
4168 | } | |
4169 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 4170 | |
d996d970 | 4171 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4172 | |
c19d1205 | 4173 | demand_empty_rest_of_line (); |
b99bd4ef | 4174 | |
708587a4 | 4175 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4176 | the list. */ |
4177 | flush_pending_unwind (); | |
b99bd4ef | 4178 | |
c19d1205 | 4179 | for (i = 0; i < 16; i++) |
b99bd4ef | 4180 | { |
c19d1205 ZW |
4181 | if (mask & (1 << i)) |
4182 | unwind.frame_size += 8; | |
b99bd4ef NC |
4183 | } |
4184 | ||
c19d1205 ZW |
4185 | /* Attempt to combine with a previous opcode. We do this because gcc |
4186 | likes to output separate unwind directives for a single block of | |
4187 | registers. */ | |
4188 | if (unwind.opcode_count > 0) | |
b99bd4ef | 4189 | { |
c19d1205 ZW |
4190 | i = unwind.opcodes[unwind.opcode_count - 1]; |
4191 | if ((i & 0xf8) == 0xc0) | |
4192 | { | |
4193 | i &= 7; | |
4194 | /* Only merge if the blocks are contiguous. */ | |
4195 | if (i < 6) | |
4196 | { | |
4197 | if ((mask & 0xfe00) == (1 << 9)) | |
4198 | { | |
4199 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
4200 | unwind.opcode_count--; | |
4201 | } | |
4202 | } | |
4203 | else if (i == 6 && unwind.opcode_count >= 2) | |
4204 | { | |
4205 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
4206 | reg = i >> 4; | |
4207 | i &= 0xf; | |
b99bd4ef | 4208 | |
c19d1205 ZW |
4209 | op = 0xffff << (reg - 1); |
4210 | if (reg > 0 | |
87a1fd79 | 4211 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
4212 | { |
4213 | op = (1 << (reg + i + 1)) - 1; | |
4214 | op &= ~((1 << reg) - 1); | |
4215 | mask |= op; | |
4216 | unwind.opcode_count -= 2; | |
4217 | } | |
4218 | } | |
4219 | } | |
b99bd4ef NC |
4220 | } |
4221 | ||
c19d1205 ZW |
4222 | hi_reg = 15; |
4223 | /* We want to generate opcodes in the order the registers have been | |
4224 | saved, ie. descending order. */ | |
4225 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 4226 | { |
c19d1205 ZW |
4227 | /* Save registers in blocks. */ |
4228 | if (reg < 0 | |
4229 | || !(mask & (1 << reg))) | |
4230 | { | |
4231 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 4232 | preceding block. */ |
c19d1205 ZW |
4233 | if (reg != hi_reg) |
4234 | { | |
4235 | if (reg == 9) | |
4236 | { | |
4237 | /* Short form. */ | |
4238 | op = 0xc0 | (hi_reg - 10); | |
4239 | add_unwind_opcode (op, 1); | |
4240 | } | |
4241 | else | |
4242 | { | |
4243 | /* Long form. */ | |
4244 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
4245 | add_unwind_opcode (op, 2); | |
4246 | } | |
4247 | } | |
4248 | hi_reg = reg - 1; | |
4249 | } | |
b99bd4ef NC |
4250 | } |
4251 | ||
c19d1205 ZW |
4252 | return; |
4253 | error: | |
4254 | ignore_rest_of_line (); | |
b99bd4ef NC |
4255 | } |
4256 | ||
4257 | static void | |
c19d1205 | 4258 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4259 | { |
c19d1205 ZW |
4260 | int reg; |
4261 | int hi_reg; | |
4262 | unsigned mask = 0; | |
4263 | valueT op; | |
b99bd4ef | 4264 | |
c19d1205 ZW |
4265 | if (*input_line_pointer == '{') |
4266 | input_line_pointer++; | |
b99bd4ef | 4267 | |
477330fc RM |
4268 | skip_whitespace (input_line_pointer); |
4269 | ||
c19d1205 | 4270 | do |
b99bd4ef | 4271 | { |
dcbf9037 | 4272 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4273 | |
c19d1205 ZW |
4274 | if (reg == FAIL) |
4275 | { | |
9b7132d3 | 4276 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4277 | goto error; |
4278 | } | |
b99bd4ef | 4279 | |
c19d1205 ZW |
4280 | reg -= 8; |
4281 | if (mask >> reg) | |
4282 | as_tsktsk (_("register list not in ascending order")); | |
4283 | mask |= 1 << reg; | |
b99bd4ef | 4284 | |
c19d1205 ZW |
4285 | if (*input_line_pointer == '-') |
4286 | { | |
4287 | input_line_pointer++; | |
dcbf9037 | 4288 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4289 | if (hi_reg == FAIL) |
4290 | { | |
9b7132d3 | 4291 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4292 | goto error; |
4293 | } | |
4294 | else if (reg >= hi_reg) | |
4295 | { | |
4296 | as_bad (_("bad register range")); | |
4297 | goto error; | |
4298 | } | |
4299 | for (; reg < hi_reg; reg++) | |
4300 | mask |= 1 << reg; | |
4301 | } | |
b99bd4ef | 4302 | } |
c19d1205 | 4303 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4304 | |
d996d970 | 4305 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4306 | |
c19d1205 ZW |
4307 | demand_empty_rest_of_line (); |
4308 | ||
708587a4 | 4309 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4310 | the list. */ |
4311 | flush_pending_unwind (); | |
b99bd4ef | 4312 | |
c19d1205 | 4313 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4314 | { |
c19d1205 ZW |
4315 | if (mask & (1 << reg)) |
4316 | unwind.frame_size += 4; | |
b99bd4ef | 4317 | } |
c19d1205 ZW |
4318 | op = 0xc700 | mask; |
4319 | add_unwind_opcode (op, 2); | |
4320 | return; | |
4321 | error: | |
4322 | ignore_rest_of_line (); | |
b99bd4ef NC |
4323 | } |
4324 | ||
c19d1205 | 4325 | |
fa073d69 MS |
4326 | /* Parse an unwind_save directive. |
4327 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4328 | |
b99bd4ef | 4329 | static void |
fa073d69 | 4330 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4331 | { |
c19d1205 ZW |
4332 | char *peek; |
4333 | struct reg_entry *reg; | |
4334 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4335 | |
921e5f0a | 4336 | if (!unwind.proc_start) |
c921be7d | 4337 | as_bad (MISSING_FNSTART); |
921e5f0a | 4338 | |
c19d1205 ZW |
4339 | /* Figure out what sort of save we have. */ |
4340 | peek = input_line_pointer; | |
b99bd4ef | 4341 | |
c19d1205 | 4342 | if (*peek == '{') |
b99bd4ef | 4343 | { |
c19d1205 ZW |
4344 | had_brace = TRUE; |
4345 | peek++; | |
b99bd4ef NC |
4346 | } |
4347 | ||
c19d1205 | 4348 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4349 | |
c19d1205 | 4350 | if (!reg) |
b99bd4ef | 4351 | { |
c19d1205 ZW |
4352 | as_bad (_("register expected")); |
4353 | ignore_rest_of_line (); | |
b99bd4ef NC |
4354 | return; |
4355 | } | |
4356 | ||
c19d1205 | 4357 | switch (reg->type) |
b99bd4ef | 4358 | { |
c19d1205 ZW |
4359 | case REG_TYPE_FN: |
4360 | if (had_brace) | |
4361 | { | |
4362 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4363 | ignore_rest_of_line (); | |
4364 | return; | |
4365 | } | |
93ac2687 | 4366 | input_line_pointer = peek; |
c19d1205 | 4367 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4368 | return; |
c19d1205 | 4369 | |
1f5afe1c NC |
4370 | case REG_TYPE_RN: |
4371 | s_arm_unwind_save_core (); | |
4372 | return; | |
4373 | ||
fa073d69 MS |
4374 | case REG_TYPE_VFD: |
4375 | if (arch_v6) | |
477330fc | 4376 | s_arm_unwind_save_vfp_armv6 (); |
fa073d69 | 4377 | else |
477330fc | 4378 | s_arm_unwind_save_vfp (); |
fa073d69 | 4379 | return; |
1f5afe1c NC |
4380 | |
4381 | case REG_TYPE_MMXWR: | |
4382 | s_arm_unwind_save_mmxwr (); | |
4383 | return; | |
4384 | ||
4385 | case REG_TYPE_MMXWCG: | |
4386 | s_arm_unwind_save_mmxwcg (); | |
4387 | return; | |
c19d1205 ZW |
4388 | |
4389 | default: | |
4390 | as_bad (_(".unwind_save does not support this kind of register")); | |
4391 | ignore_rest_of_line (); | |
b99bd4ef | 4392 | } |
c19d1205 | 4393 | } |
b99bd4ef | 4394 | |
b99bd4ef | 4395 | |
c19d1205 ZW |
4396 | /* Parse an unwind_movsp directive. */ |
4397 | ||
4398 | static void | |
4399 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4400 | { | |
4401 | int reg; | |
4402 | valueT op; | |
4fa3602b | 4403 | int offset; |
c19d1205 | 4404 | |
921e5f0a | 4405 | if (!unwind.proc_start) |
c921be7d | 4406 | as_bad (MISSING_FNSTART); |
921e5f0a | 4407 | |
dcbf9037 | 4408 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4409 | if (reg == FAIL) |
b99bd4ef | 4410 | { |
9b7132d3 | 4411 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4412 | ignore_rest_of_line (); |
b99bd4ef NC |
4413 | return; |
4414 | } | |
4fa3602b PB |
4415 | |
4416 | /* Optional constant. */ | |
4417 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4418 | { | |
4419 | if (immediate_for_directive (&offset) == FAIL) | |
4420 | return; | |
4421 | } | |
4422 | else | |
4423 | offset = 0; | |
4424 | ||
c19d1205 | 4425 | demand_empty_rest_of_line (); |
b99bd4ef | 4426 | |
c19d1205 | 4427 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4428 | { |
c19d1205 | 4429 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4430 | return; |
4431 | } | |
4432 | ||
c19d1205 ZW |
4433 | if (unwind.fp_reg != REG_SP) |
4434 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4435 | |
c19d1205 ZW |
4436 | /* Generate opcode to restore the value. */ |
4437 | op = 0x90 | reg; | |
4438 | add_unwind_opcode (op, 1); | |
4439 | ||
4440 | /* Record the information for later. */ | |
4441 | unwind.fp_reg = reg; | |
4fa3602b | 4442 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4443 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4444 | } |
4445 | ||
c19d1205 ZW |
4446 | /* Parse an unwind_pad directive. */ |
4447 | ||
b05fe5cf | 4448 | static void |
c19d1205 | 4449 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4450 | { |
c19d1205 | 4451 | int offset; |
b05fe5cf | 4452 | |
921e5f0a | 4453 | if (!unwind.proc_start) |
c921be7d | 4454 | as_bad (MISSING_FNSTART); |
921e5f0a | 4455 | |
c19d1205 ZW |
4456 | if (immediate_for_directive (&offset) == FAIL) |
4457 | return; | |
b99bd4ef | 4458 | |
c19d1205 ZW |
4459 | if (offset & 3) |
4460 | { | |
4461 | as_bad (_("stack increment must be multiple of 4")); | |
4462 | ignore_rest_of_line (); | |
4463 | return; | |
4464 | } | |
b99bd4ef | 4465 | |
c19d1205 ZW |
4466 | /* Don't generate any opcodes, just record the details for later. */ |
4467 | unwind.frame_size += offset; | |
4468 | unwind.pending_offset += offset; | |
4469 | ||
4470 | demand_empty_rest_of_line (); | |
4471 | } | |
4472 | ||
4473 | /* Parse an unwind_setfp directive. */ | |
4474 | ||
4475 | static void | |
4476 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4477 | { |
c19d1205 ZW |
4478 | int sp_reg; |
4479 | int fp_reg; | |
4480 | int offset; | |
4481 | ||
921e5f0a | 4482 | if (!unwind.proc_start) |
c921be7d | 4483 | as_bad (MISSING_FNSTART); |
921e5f0a | 4484 | |
dcbf9037 | 4485 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4486 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4487 | sp_reg = FAIL; | |
4488 | else | |
dcbf9037 | 4489 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4490 | |
c19d1205 ZW |
4491 | if (fp_reg == FAIL || sp_reg == FAIL) |
4492 | { | |
4493 | as_bad (_("expected <reg>, <reg>")); | |
4494 | ignore_rest_of_line (); | |
4495 | return; | |
4496 | } | |
b99bd4ef | 4497 | |
c19d1205 ZW |
4498 | /* Optional constant. */ |
4499 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4500 | { | |
4501 | if (immediate_for_directive (&offset) == FAIL) | |
4502 | return; | |
4503 | } | |
4504 | else | |
4505 | offset = 0; | |
a737bd4d | 4506 | |
c19d1205 | 4507 | demand_empty_rest_of_line (); |
a737bd4d | 4508 | |
fdfde340 | 4509 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4510 | { |
c19d1205 ZW |
4511 | as_bad (_("register must be either sp or set by a previous" |
4512 | "unwind_movsp directive")); | |
4513 | return; | |
a737bd4d NC |
4514 | } |
4515 | ||
c19d1205 ZW |
4516 | /* Don't generate any opcodes, just record the information for later. */ |
4517 | unwind.fp_reg = fp_reg; | |
4518 | unwind.fp_used = 1; | |
fdfde340 | 4519 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4520 | unwind.fp_offset = unwind.frame_size - offset; |
4521 | else | |
4522 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4523 | } |
4524 | ||
c19d1205 ZW |
4525 | /* Parse an unwind_raw directive. */ |
4526 | ||
4527 | static void | |
4528 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4529 | { |
c19d1205 | 4530 | expressionS exp; |
708587a4 | 4531 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4532 | unsigned char op[16]; |
4533 | int count; | |
a737bd4d | 4534 | |
921e5f0a | 4535 | if (!unwind.proc_start) |
c921be7d | 4536 | as_bad (MISSING_FNSTART); |
921e5f0a | 4537 | |
c19d1205 ZW |
4538 | expression (&exp); |
4539 | if (exp.X_op == O_constant | |
4540 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4541 | { |
c19d1205 ZW |
4542 | unwind.frame_size += exp.X_add_number; |
4543 | expression (&exp); | |
4544 | } | |
4545 | else | |
4546 | exp.X_op = O_illegal; | |
a737bd4d | 4547 | |
c19d1205 ZW |
4548 | if (exp.X_op != O_constant) |
4549 | { | |
4550 | as_bad (_("expected <offset>, <opcode>")); | |
4551 | ignore_rest_of_line (); | |
4552 | return; | |
4553 | } | |
a737bd4d | 4554 | |
c19d1205 | 4555 | count = 0; |
a737bd4d | 4556 | |
c19d1205 ZW |
4557 | /* Parse the opcode. */ |
4558 | for (;;) | |
4559 | { | |
4560 | if (count >= 16) | |
4561 | { | |
4562 | as_bad (_("unwind opcode too long")); | |
4563 | ignore_rest_of_line (); | |
a737bd4d | 4564 | } |
c19d1205 | 4565 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4566 | { |
c19d1205 ZW |
4567 | as_bad (_("invalid unwind opcode")); |
4568 | ignore_rest_of_line (); | |
4569 | return; | |
a737bd4d | 4570 | } |
c19d1205 | 4571 | op[count++] = exp.X_add_number; |
a737bd4d | 4572 | |
c19d1205 ZW |
4573 | /* Parse the next byte. */ |
4574 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4575 | break; | |
a737bd4d | 4576 | |
c19d1205 ZW |
4577 | expression (&exp); |
4578 | } | |
b99bd4ef | 4579 | |
c19d1205 ZW |
4580 | /* Add the opcode bytes in reverse order. */ |
4581 | while (count--) | |
4582 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4583 | |
c19d1205 | 4584 | demand_empty_rest_of_line (); |
b99bd4ef | 4585 | } |
ee065d83 PB |
4586 | |
4587 | ||
4588 | /* Parse a .eabi_attribute directive. */ | |
4589 | ||
4590 | static void | |
4591 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4592 | { | |
0420f52b | 4593 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 AS |
4594 | |
4595 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4596 | attributes_set_explicitly[tag] = 1; | |
ee065d83 PB |
4597 | } |
4598 | ||
0855e32b NS |
4599 | /* Emit a tls fix for the symbol. */ |
4600 | ||
4601 | static void | |
4602 | s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED) | |
4603 | { | |
4604 | char *p; | |
4605 | expressionS exp; | |
4606 | #ifdef md_flush_pending_output | |
4607 | md_flush_pending_output (); | |
4608 | #endif | |
4609 | ||
4610 | #ifdef md_cons_align | |
4611 | md_cons_align (4); | |
4612 | #endif | |
4613 | ||
4614 | /* Since we're just labelling the code, there's no need to define a | |
4615 | mapping symbol. */ | |
4616 | expression (&exp); | |
4617 | p = obstack_next_free (&frchain_now->frch_obstack); | |
4618 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0, | |
4619 | thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
4620 | : BFD_RELOC_ARM_TLS_DESCSEQ); | |
4621 | } | |
cdf9ccec | 4622 | #endif /* OBJ_ELF */ |
0855e32b | 4623 | |
ee065d83 | 4624 | static void s_arm_arch (int); |
7a1d4c38 | 4625 | static void s_arm_object_arch (int); |
ee065d83 PB |
4626 | static void s_arm_cpu (int); |
4627 | static void s_arm_fpu (int); | |
69133863 | 4628 | static void s_arm_arch_extension (int); |
b99bd4ef | 4629 | |
f0927246 NC |
4630 | #ifdef TE_PE |
4631 | ||
4632 | static void | |
5f4273c7 | 4633 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4634 | { |
4635 | expressionS exp; | |
4636 | ||
4637 | do | |
4638 | { | |
4639 | expression (&exp); | |
4640 | if (exp.X_op == O_symbol) | |
4641 | exp.X_op = O_secrel; | |
4642 | ||
4643 | emit_expr (&exp, 4); | |
4644 | } | |
4645 | while (*input_line_pointer++ == ','); | |
4646 | ||
4647 | input_line_pointer--; | |
4648 | demand_empty_rest_of_line (); | |
4649 | } | |
4650 | #endif /* TE_PE */ | |
4651 | ||
c19d1205 ZW |
4652 | /* This table describes all the machine specific pseudo-ops the assembler |
4653 | has to support. The fields are: | |
4654 | pseudo-op name without dot | |
4655 | function to call to execute this pseudo-op | |
4656 | Integer arg to pass to the function. */ | |
b99bd4ef | 4657 | |
c19d1205 | 4658 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4659 | { |
c19d1205 ZW |
4660 | /* Never called because '.req' does not start a line. */ |
4661 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4662 | /* Following two are likewise never called. */ |
4663 | { "dn", s_dn, 0 }, | |
4664 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4665 | { "unreq", s_unreq, 0 }, |
4666 | { "bss", s_bss, 0 }, | |
db2ed2e0 | 4667 | { "align", s_align_ptwo, 2 }, |
c19d1205 ZW |
4668 | { "arm", s_arm, 0 }, |
4669 | { "thumb", s_thumb, 0 }, | |
4670 | { "code", s_code, 0 }, | |
4671 | { "force_thumb", s_force_thumb, 0 }, | |
4672 | { "thumb_func", s_thumb_func, 0 }, | |
4673 | { "thumb_set", s_thumb_set, 0 }, | |
4674 | { "even", s_even, 0 }, | |
4675 | { "ltorg", s_ltorg, 0 }, | |
4676 | { "pool", s_ltorg, 0 }, | |
4677 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4678 | { "cpu", s_arm_cpu, 0 }, |
4679 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4680 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4681 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 4682 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 4683 | #ifdef OBJ_ELF |
c921be7d NC |
4684 | { "word", s_arm_elf_cons, 4 }, |
4685 | { "long", s_arm_elf_cons, 4 }, | |
4686 | { "inst.n", s_arm_elf_inst, 2 }, | |
4687 | { "inst.w", s_arm_elf_inst, 4 }, | |
4688 | { "inst", s_arm_elf_inst, 0 }, | |
4689 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4690 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4691 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4692 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4693 | { "personality", s_arm_unwind_personality, 0 }, | |
4694 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4695 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4696 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4697 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4698 | { "movsp", s_arm_unwind_movsp, 0 }, |
4699 | { "pad", s_arm_unwind_pad, 0 }, | |
4700 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4701 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4702 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 4703 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
4704 | #else |
4705 | { "word", cons, 4}, | |
f0927246 NC |
4706 | |
4707 | /* These are used for dwarf. */ | |
4708 | {"2byte", cons, 2}, | |
4709 | {"4byte", cons, 4}, | |
4710 | {"8byte", cons, 8}, | |
4711 | /* These are used for dwarf2. */ | |
4712 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4713 | { "loc", dwarf2_directive_loc, 0 }, | |
4714 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4715 | #endif |
4716 | { "extend", float_cons, 'x' }, | |
4717 | { "ldouble", float_cons, 'x' }, | |
4718 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4719 | #ifdef TE_PE |
4720 | {"secrel32", pe_directive_secrel, 0}, | |
4721 | #endif | |
2e6976a8 DG |
4722 | |
4723 | /* These are for compatibility with CodeComposer Studio. */ | |
4724 | {"ref", s_ccs_ref, 0}, | |
4725 | {"def", s_ccs_def, 0}, | |
4726 | {"asmfunc", s_ccs_asmfunc, 0}, | |
4727 | {"endasmfunc", s_ccs_endasmfunc, 0}, | |
4728 | ||
c19d1205 ZW |
4729 | { 0, 0, 0 } |
4730 | }; | |
4731 | \f | |
4732 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4733 | |
c19d1205 ZW |
4734 | /* Generic immediate-value read function for use in insn parsing. |
4735 | STR points to the beginning of the immediate (the leading #); | |
4736 | VAL receives the value; if the value is outside [MIN, MAX] | |
4737 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4738 | optional. */ | |
b99bd4ef | 4739 | |
c19d1205 ZW |
4740 | static int |
4741 | parse_immediate (char **str, int *val, int min, int max, | |
4742 | bfd_boolean prefix_opt) | |
4743 | { | |
4744 | expressionS exp; | |
4745 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4746 | if (exp.X_op != O_constant) | |
b99bd4ef | 4747 | { |
c19d1205 ZW |
4748 | inst.error = _("constant expression required"); |
4749 | return FAIL; | |
4750 | } | |
b99bd4ef | 4751 | |
c19d1205 ZW |
4752 | if (exp.X_add_number < min || exp.X_add_number > max) |
4753 | { | |
4754 | inst.error = _("immediate value out of range"); | |
4755 | return FAIL; | |
4756 | } | |
b99bd4ef | 4757 | |
c19d1205 ZW |
4758 | *val = exp.X_add_number; |
4759 | return SUCCESS; | |
4760 | } | |
b99bd4ef | 4761 | |
5287ad62 | 4762 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4763 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4764 | instructions. Puts the result directly in inst.operands[i]. */ |
4765 | ||
4766 | static int | |
8335d6aa JW |
4767 | parse_big_immediate (char **str, int i, expressionS *in_exp, |
4768 | bfd_boolean allow_symbol_p) | |
5287ad62 JB |
4769 | { |
4770 | expressionS exp; | |
8335d6aa | 4771 | expressionS *exp_p = in_exp ? in_exp : &exp; |
5287ad62 JB |
4772 | char *ptr = *str; |
4773 | ||
8335d6aa | 4774 | my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG); |
5287ad62 | 4775 | |
8335d6aa | 4776 | if (exp_p->X_op == O_constant) |
036dc3f7 | 4777 | { |
8335d6aa | 4778 | inst.operands[i].imm = exp_p->X_add_number & 0xffffffff; |
036dc3f7 PB |
4779 | /* If we're on a 64-bit host, then a 64-bit number can be returned using |
4780 | O_constant. We have to be careful not to break compilation for | |
4781 | 32-bit X_add_number, though. */ | |
8335d6aa | 4782 | if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 | 4783 | { |
8335d6aa JW |
4784 | /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */ |
4785 | inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16) | |
4786 | & 0xffffffff); | |
036dc3f7 PB |
4787 | inst.operands[i].regisimm = 1; |
4788 | } | |
4789 | } | |
8335d6aa JW |
4790 | else if (exp_p->X_op == O_big |
4791 | && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32) | |
5287ad62 JB |
4792 | { |
4793 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 4794 | |
5287ad62 | 4795 | /* Bignums have their least significant bits in |
477330fc RM |
4796 | generic_bignum[0]. Make sure we put 32 bits in imm and |
4797 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4798 | gas_assert (parts != 0); |
95b75c01 NC |
4799 | |
4800 | /* Make sure that the number is not too big. | |
4801 | PR 11972: Bignums can now be sign-extended to the | |
4802 | size of a .octa so check that the out of range bits | |
4803 | are all zero or all one. */ | |
8335d6aa | 4804 | if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64) |
95b75c01 NC |
4805 | { |
4806 | LITTLENUM_TYPE m = -1; | |
4807 | ||
4808 | if (generic_bignum[parts * 2] != 0 | |
4809 | && generic_bignum[parts * 2] != m) | |
4810 | return FAIL; | |
4811 | ||
8335d6aa | 4812 | for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++) |
95b75c01 NC |
4813 | if (generic_bignum[j] != generic_bignum[j-1]) |
4814 | return FAIL; | |
4815 | } | |
4816 | ||
5287ad62 JB |
4817 | inst.operands[i].imm = 0; |
4818 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4819 | inst.operands[i].imm |= generic_bignum[idx] |
4820 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4821 | inst.operands[i].reg = 0; |
4822 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4823 | inst.operands[i].reg |= generic_bignum[idx] |
4824 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4825 | inst.operands[i].regisimm = 1; |
4826 | } | |
8335d6aa | 4827 | else if (!(exp_p->X_op == O_symbol && allow_symbol_p)) |
5287ad62 | 4828 | return FAIL; |
5f4273c7 | 4829 | |
5287ad62 JB |
4830 | *str = ptr; |
4831 | ||
4832 | return SUCCESS; | |
4833 | } | |
4834 | ||
c19d1205 ZW |
4835 | /* Returns the pseudo-register number of an FPA immediate constant, |
4836 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4837 | |
c19d1205 ZW |
4838 | static int |
4839 | parse_fpa_immediate (char ** str) | |
4840 | { | |
4841 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4842 | char * save_in; | |
4843 | expressionS exp; | |
4844 | int i; | |
4845 | int j; | |
b99bd4ef | 4846 | |
c19d1205 ZW |
4847 | /* First try and match exact strings, this is to guarantee |
4848 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4849 | |
c19d1205 ZW |
4850 | for (i = 0; fp_const[i]; i++) |
4851 | { | |
4852 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4853 | { |
c19d1205 | 4854 | char *start = *str; |
b99bd4ef | 4855 | |
c19d1205 ZW |
4856 | *str += strlen (fp_const[i]); |
4857 | if (is_end_of_line[(unsigned char) **str]) | |
4858 | return i + 8; | |
4859 | *str = start; | |
4860 | } | |
4861 | } | |
b99bd4ef | 4862 | |
c19d1205 ZW |
4863 | /* Just because we didn't get a match doesn't mean that the constant |
4864 | isn't valid, just that it is in a format that we don't | |
4865 | automatically recognize. Try parsing it with the standard | |
4866 | expression routines. */ | |
b99bd4ef | 4867 | |
c19d1205 | 4868 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4869 | |
c19d1205 ZW |
4870 | /* Look for a raw floating point number. */ |
4871 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4872 | && is_end_of_line[(unsigned char) *save_in]) | |
4873 | { | |
4874 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4875 | { | |
4876 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4877 | { |
c19d1205 ZW |
4878 | if (words[j] != fp_values[i][j]) |
4879 | break; | |
b99bd4ef NC |
4880 | } |
4881 | ||
c19d1205 | 4882 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4883 | { |
c19d1205 ZW |
4884 | *str = save_in; |
4885 | return i + 8; | |
b99bd4ef NC |
4886 | } |
4887 | } | |
4888 | } | |
b99bd4ef | 4889 | |
c19d1205 ZW |
4890 | /* Try and parse a more complex expression, this will probably fail |
4891 | unless the code uses a floating point prefix (eg "0f"). */ | |
4892 | save_in = input_line_pointer; | |
4893 | input_line_pointer = *str; | |
4894 | if (expression (&exp) == absolute_section | |
4895 | && exp.X_op == O_big | |
4896 | && exp.X_add_number < 0) | |
4897 | { | |
4898 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4899 | Ditto for 15. */ | |
ba592044 AM |
4900 | #define X_PRECISION 5 |
4901 | #define E_PRECISION 15L | |
4902 | if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0) | |
c19d1205 ZW |
4903 | { |
4904 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4905 | { | |
4906 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4907 | { | |
4908 | if (words[j] != fp_values[i][j]) | |
4909 | break; | |
4910 | } | |
b99bd4ef | 4911 | |
c19d1205 ZW |
4912 | if (j == MAX_LITTLENUMS) |
4913 | { | |
4914 | *str = input_line_pointer; | |
4915 | input_line_pointer = save_in; | |
4916 | return i + 8; | |
4917 | } | |
4918 | } | |
4919 | } | |
b99bd4ef NC |
4920 | } |
4921 | ||
c19d1205 ZW |
4922 | *str = input_line_pointer; |
4923 | input_line_pointer = save_in; | |
4924 | inst.error = _("invalid FPA immediate expression"); | |
4925 | return FAIL; | |
b99bd4ef NC |
4926 | } |
4927 | ||
136da414 JB |
4928 | /* Returns 1 if a number has "quarter-precision" float format |
4929 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4930 | ||
4931 | static int | |
4932 | is_quarter_float (unsigned imm) | |
4933 | { | |
4934 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4935 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4936 | } | |
4937 | ||
aacf0b33 KT |
4938 | |
4939 | /* Detect the presence of a floating point or integer zero constant, | |
4940 | i.e. #0.0 or #0. */ | |
4941 | ||
4942 | static bfd_boolean | |
4943 | parse_ifimm_zero (char **in) | |
4944 | { | |
4945 | int error_code; | |
4946 | ||
4947 | if (!is_immediate_prefix (**in)) | |
4948 | return FALSE; | |
4949 | ||
4950 | ++*in; | |
0900a05b JW |
4951 | |
4952 | /* Accept #0x0 as a synonym for #0. */ | |
4953 | if (strncmp (*in, "0x", 2) == 0) | |
4954 | { | |
4955 | int val; | |
4956 | if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL) | |
4957 | return FALSE; | |
4958 | return TRUE; | |
4959 | } | |
4960 | ||
aacf0b33 KT |
4961 | error_code = atof_generic (in, ".", EXP_CHARS, |
4962 | &generic_floating_point_number); | |
4963 | ||
4964 | if (!error_code | |
4965 | && generic_floating_point_number.sign == '+' | |
4966 | && (generic_floating_point_number.low | |
4967 | > generic_floating_point_number.leader)) | |
4968 | return TRUE; | |
4969 | ||
4970 | return FALSE; | |
4971 | } | |
4972 | ||
136da414 JB |
4973 | /* Parse an 8-bit "quarter-precision" floating point number of the form: |
4974 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4975 | The zero and minus-zero cases need special handling, since they can't be |
4976 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4977 | loaded as integer constants. */ | |
136da414 JB |
4978 | |
4979 | static unsigned | |
4980 | parse_qfloat_immediate (char **ccp, int *immed) | |
4981 | { | |
4982 | char *str = *ccp; | |
c96612cc | 4983 | char *fpnum; |
136da414 | 4984 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4985 | int found_fpchar = 0; |
5f4273c7 | 4986 | |
136da414 | 4987 | skip_past_char (&str, '#'); |
5f4273c7 | 4988 | |
c96612cc JB |
4989 | /* We must not accidentally parse an integer as a floating-point number. Make |
4990 | sure that the value we parse is not an integer by checking for special | |
4991 | characters '.' or 'e'. | |
4992 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4993 | information isn't in a very usable state at parse time. */ | |
4994 | fpnum = str; | |
4995 | skip_whitespace (fpnum); | |
4996 | ||
4997 | if (strncmp (fpnum, "0x", 2) == 0) | |
4998 | return FAIL; | |
4999 | else | |
5000 | { | |
5001 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
477330fc RM |
5002 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
5003 | { | |
5004 | found_fpchar = 1; | |
5005 | break; | |
5006 | } | |
c96612cc JB |
5007 | |
5008 | if (!found_fpchar) | |
477330fc | 5009 | return FAIL; |
c96612cc | 5010 | } |
5f4273c7 | 5011 | |
136da414 JB |
5012 | if ((str = atof_ieee (str, 's', words)) != NULL) |
5013 | { | |
5014 | unsigned fpword = 0; | |
5015 | int i; | |
5f4273c7 | 5016 | |
136da414 JB |
5017 | /* Our FP word must be 32 bits (single-precision FP). */ |
5018 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
477330fc RM |
5019 | { |
5020 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
5021 | fpword |= words[i]; | |
5022 | } | |
5f4273c7 | 5023 | |
c96612cc | 5024 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
477330fc | 5025 | *immed = fpword; |
136da414 | 5026 | else |
477330fc | 5027 | return FAIL; |
136da414 JB |
5028 | |
5029 | *ccp = str; | |
5f4273c7 | 5030 | |
136da414 JB |
5031 | return SUCCESS; |
5032 | } | |
5f4273c7 | 5033 | |
136da414 JB |
5034 | return FAIL; |
5035 | } | |
5036 | ||
c19d1205 ZW |
5037 | /* Shift operands. */ |
5038 | enum shift_kind | |
b99bd4ef | 5039 | { |
c19d1205 ZW |
5040 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
5041 | }; | |
b99bd4ef | 5042 | |
c19d1205 ZW |
5043 | struct asm_shift_name |
5044 | { | |
5045 | const char *name; | |
5046 | enum shift_kind kind; | |
5047 | }; | |
b99bd4ef | 5048 | |
c19d1205 ZW |
5049 | /* Third argument to parse_shift. */ |
5050 | enum parse_shift_mode | |
5051 | { | |
5052 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
5053 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
5054 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
5055 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
5056 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
5057 | }; | |
b99bd4ef | 5058 | |
c19d1205 ZW |
5059 | /* Parse a <shift> specifier on an ARM data processing instruction. |
5060 | This has three forms: | |
b99bd4ef | 5061 | |
c19d1205 ZW |
5062 | (LSL|LSR|ASL|ASR|ROR) Rs |
5063 | (LSL|LSR|ASL|ASR|ROR) #imm | |
5064 | RRX | |
b99bd4ef | 5065 | |
c19d1205 ZW |
5066 | Note that ASL is assimilated to LSL in the instruction encoding, and |
5067 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 5068 | |
c19d1205 ZW |
5069 | static int |
5070 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 5071 | { |
c19d1205 ZW |
5072 | const struct asm_shift_name *shift_name; |
5073 | enum shift_kind shift; | |
5074 | char *s = *str; | |
5075 | char *p = s; | |
5076 | int reg; | |
b99bd4ef | 5077 | |
c19d1205 ZW |
5078 | for (p = *str; ISALPHA (*p); p++) |
5079 | ; | |
b99bd4ef | 5080 | |
c19d1205 | 5081 | if (p == *str) |
b99bd4ef | 5082 | { |
c19d1205 ZW |
5083 | inst.error = _("shift expression expected"); |
5084 | return FAIL; | |
b99bd4ef NC |
5085 | } |
5086 | ||
21d799b5 | 5087 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
477330fc | 5088 | p - *str); |
c19d1205 ZW |
5089 | |
5090 | if (shift_name == NULL) | |
b99bd4ef | 5091 | { |
c19d1205 ZW |
5092 | inst.error = _("shift expression expected"); |
5093 | return FAIL; | |
b99bd4ef NC |
5094 | } |
5095 | ||
c19d1205 | 5096 | shift = shift_name->kind; |
b99bd4ef | 5097 | |
c19d1205 ZW |
5098 | switch (mode) |
5099 | { | |
5100 | case NO_SHIFT_RESTRICT: | |
5101 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 5102 | |
c19d1205 ZW |
5103 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
5104 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
5105 | { | |
5106 | inst.error = _("'LSL' or 'ASR' required"); | |
5107 | return FAIL; | |
5108 | } | |
5109 | break; | |
b99bd4ef | 5110 | |
c19d1205 ZW |
5111 | case SHIFT_LSL_IMMEDIATE: |
5112 | if (shift != SHIFT_LSL) | |
5113 | { | |
5114 | inst.error = _("'LSL' required"); | |
5115 | return FAIL; | |
5116 | } | |
5117 | break; | |
b99bd4ef | 5118 | |
c19d1205 ZW |
5119 | case SHIFT_ASR_IMMEDIATE: |
5120 | if (shift != SHIFT_ASR) | |
5121 | { | |
5122 | inst.error = _("'ASR' required"); | |
5123 | return FAIL; | |
5124 | } | |
5125 | break; | |
b99bd4ef | 5126 | |
c19d1205 ZW |
5127 | default: abort (); |
5128 | } | |
b99bd4ef | 5129 | |
c19d1205 ZW |
5130 | if (shift != SHIFT_RRX) |
5131 | { | |
5132 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
5133 | skip_whitespace (p); | |
b99bd4ef | 5134 | |
c19d1205 | 5135 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 5136 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5137 | { |
5138 | inst.operands[i].imm = reg; | |
5139 | inst.operands[i].immisreg = 1; | |
5140 | } | |
5141 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5142 | return FAIL; | |
5143 | } | |
5144 | inst.operands[i].shift_kind = shift; | |
5145 | inst.operands[i].shifted = 1; | |
5146 | *str = p; | |
5147 | return SUCCESS; | |
b99bd4ef NC |
5148 | } |
5149 | ||
c19d1205 | 5150 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 5151 | |
c19d1205 ZW |
5152 | #<immediate> |
5153 | #<immediate>, <rotate> | |
5154 | <Rm> | |
5155 | <Rm>, <shift> | |
b99bd4ef | 5156 | |
c19d1205 ZW |
5157 | where <shift> is defined by parse_shift above, and <rotate> is a |
5158 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 5159 | is deferred to md_apply_fix. */ |
b99bd4ef | 5160 | |
c19d1205 ZW |
5161 | static int |
5162 | parse_shifter_operand (char **str, int i) | |
5163 | { | |
5164 | int value; | |
91d6fa6a | 5165 | expressionS exp; |
b99bd4ef | 5166 | |
dcbf9037 | 5167 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5168 | { |
5169 | inst.operands[i].reg = value; | |
5170 | inst.operands[i].isreg = 1; | |
b99bd4ef | 5171 | |
c19d1205 ZW |
5172 | /* parse_shift will override this if appropriate */ |
5173 | inst.reloc.exp.X_op = O_constant; | |
5174 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 5175 | |
c19d1205 ZW |
5176 | if (skip_past_comma (str) == FAIL) |
5177 | return SUCCESS; | |
b99bd4ef | 5178 | |
c19d1205 ZW |
5179 | /* Shift operation on register. */ |
5180 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
5181 | } |
5182 | ||
c19d1205 ZW |
5183 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
5184 | return FAIL; | |
b99bd4ef | 5185 | |
c19d1205 | 5186 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 5187 | { |
c19d1205 | 5188 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 5189 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 5190 | return FAIL; |
b99bd4ef | 5191 | |
91d6fa6a | 5192 | if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
c19d1205 ZW |
5193 | { |
5194 | inst.error = _("constant expression expected"); | |
5195 | return FAIL; | |
5196 | } | |
b99bd4ef | 5197 | |
91d6fa6a | 5198 | value = exp.X_add_number; |
c19d1205 ZW |
5199 | if (value < 0 || value > 30 || value % 2 != 0) |
5200 | { | |
5201 | inst.error = _("invalid rotation"); | |
5202 | return FAIL; | |
5203 | } | |
5204 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
5205 | { | |
5206 | inst.error = _("invalid constant"); | |
5207 | return FAIL; | |
5208 | } | |
09d92015 | 5209 | |
a415b1cd JB |
5210 | /* Encode as specified. */ |
5211 | inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7; | |
5212 | return SUCCESS; | |
09d92015 MM |
5213 | } |
5214 | ||
c19d1205 ZW |
5215 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
5216 | inst.reloc.pc_rel = 0; | |
5217 | return SUCCESS; | |
09d92015 MM |
5218 | } |
5219 | ||
4962c51a MS |
5220 | /* Group relocation information. Each entry in the table contains the |
5221 | textual name of the relocation as may appear in assembler source | |
5222 | and must end with a colon. | |
5223 | Along with this textual name are the relocation codes to be used if | |
5224 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
5225 | an LDR, an LDRS, or an LDC. */ | |
5226 | ||
5227 | struct group_reloc_table_entry | |
5228 | { | |
5229 | const char *name; | |
5230 | int alu_code; | |
5231 | int ldr_code; | |
5232 | int ldrs_code; | |
5233 | int ldc_code; | |
5234 | }; | |
5235 | ||
5236 | typedef enum | |
5237 | { | |
5238 | /* Varieties of non-ALU group relocation. */ | |
5239 | ||
5240 | GROUP_LDR, | |
5241 | GROUP_LDRS, | |
5242 | GROUP_LDC | |
5243 | } group_reloc_type; | |
5244 | ||
5245 | static struct group_reloc_table_entry group_reloc_table[] = | |
5246 | { /* Program counter relative: */ | |
5247 | { "pc_g0_nc", | |
5248 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
5249 | 0, /* LDR */ | |
5250 | 0, /* LDRS */ | |
5251 | 0 }, /* LDC */ | |
5252 | { "pc_g0", | |
5253 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
5254 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
5255 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
5256 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
5257 | { "pc_g1_nc", | |
5258 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
5259 | 0, /* LDR */ | |
5260 | 0, /* LDRS */ | |
5261 | 0 }, /* LDC */ | |
5262 | { "pc_g1", | |
5263 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
5264 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
5265 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
5266 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
5267 | { "pc_g2", | |
5268 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
5269 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
5270 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
5271 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
5272 | /* Section base relative */ | |
5273 | { "sb_g0_nc", | |
5274 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
5275 | 0, /* LDR */ | |
5276 | 0, /* LDRS */ | |
5277 | 0 }, /* LDC */ | |
5278 | { "sb_g0", | |
5279 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
5280 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
5281 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
5282 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
5283 | { "sb_g1_nc", | |
5284 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
5285 | 0, /* LDR */ | |
5286 | 0, /* LDRS */ | |
5287 | 0 }, /* LDC */ | |
5288 | { "sb_g1", | |
5289 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
5290 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
5291 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
5292 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
5293 | { "sb_g2", | |
5294 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
5295 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
5296 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
72d98d16 MG |
5297 | BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */ |
5298 | /* Absolute thumb alu relocations. */ | |
5299 | { "lower0_7", | |
5300 | BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */ | |
5301 | 0, /* LDR. */ | |
5302 | 0, /* LDRS. */ | |
5303 | 0 }, /* LDC. */ | |
5304 | { "lower8_15", | |
5305 | BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */ | |
5306 | 0, /* LDR. */ | |
5307 | 0, /* LDRS. */ | |
5308 | 0 }, /* LDC. */ | |
5309 | { "upper0_7", | |
5310 | BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */ | |
5311 | 0, /* LDR. */ | |
5312 | 0, /* LDRS. */ | |
5313 | 0 }, /* LDC. */ | |
5314 | { "upper8_15", | |
5315 | BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */ | |
5316 | 0, /* LDR. */ | |
5317 | 0, /* LDRS. */ | |
5318 | 0 } }; /* LDC. */ | |
4962c51a MS |
5319 | |
5320 | /* Given the address of a pointer pointing to the textual name of a group | |
5321 | relocation as may appear in assembler source, attempt to find its details | |
5322 | in group_reloc_table. The pointer will be updated to the character after | |
5323 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
5324 | otherwise. On success, *entry will be updated to point at the relevant | |
5325 | group_reloc_table entry. */ | |
5326 | ||
5327 | static int | |
5328 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
5329 | { | |
5330 | unsigned int i; | |
5331 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
5332 | { | |
5333 | int length = strlen (group_reloc_table[i].name); | |
5334 | ||
5f4273c7 NC |
5335 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5336 | && (*str)[length] == ':') | |
477330fc RM |
5337 | { |
5338 | *out = &group_reloc_table[i]; | |
5339 | *str += (length + 1); | |
5340 | return SUCCESS; | |
5341 | } | |
4962c51a MS |
5342 | } |
5343 | ||
5344 | return FAIL; | |
5345 | } | |
5346 | ||
5347 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
5348 | (as for parse_shifter_operand) where group relocations are allowed: | |
5349 | ||
5350 | #<immediate> | |
5351 | #<immediate>, <rotate> | |
5352 | #:<group_reloc>:<expression> | |
5353 | <Rm> | |
5354 | <Rm>, <shift> | |
5355 | ||
5356 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
5357 | The hashes are optional. | |
5358 | ||
5359 | Everything else is as for parse_shifter_operand. */ | |
5360 | ||
5361 | static parse_operand_result | |
5362 | parse_shifter_operand_group_reloc (char **str, int i) | |
5363 | { | |
5364 | /* Determine if we have the sequence of characters #: or just : | |
5365 | coming next. If we do, then we check for a group relocation. | |
5366 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
5367 | ||
5368 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
5369 | || (*str)[0] == ':') | |
5370 | { | |
5371 | struct group_reloc_table_entry *entry; | |
5372 | ||
5373 | if ((*str)[0] == '#') | |
477330fc | 5374 | (*str) += 2; |
4962c51a | 5375 | else |
477330fc | 5376 | (*str)++; |
4962c51a MS |
5377 | |
5378 | /* Try to parse a group relocation. Anything else is an error. */ | |
5379 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
477330fc RM |
5380 | { |
5381 | inst.error = _("unknown group relocation"); | |
5382 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5383 | } | |
4962c51a MS |
5384 | |
5385 | /* We now have the group relocation table entry corresponding to | |
477330fc | 5386 | the name in the assembler source. Next, we parse the expression. */ |
4962c51a | 5387 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) |
477330fc | 5388 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
4962c51a MS |
5389 | |
5390 | /* Record the relocation type (always the ALU variant here). */ | |
21d799b5 | 5391 | inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code; |
9c2799c2 | 5392 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
5393 | |
5394 | return PARSE_OPERAND_SUCCESS; | |
5395 | } | |
5396 | else | |
5397 | return parse_shifter_operand (str, i) == SUCCESS | |
477330fc | 5398 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; |
4962c51a MS |
5399 | |
5400 | /* Never reached. */ | |
5401 | } | |
5402 | ||
8e560766 MGD |
5403 | /* Parse a Neon alignment expression. Information is written to |
5404 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5405 | |
8e560766 MGD |
5406 | align .imm = align << 8, .immisalign=1, .preind=0 */ |
5407 | static parse_operand_result | |
5408 | parse_neon_alignment (char **str, int i) | |
5409 | { | |
5410 | char *p = *str; | |
5411 | expressionS exp; | |
5412 | ||
5413 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5414 | ||
5415 | if (exp.X_op != O_constant) | |
5416 | { | |
5417 | inst.error = _("alignment must be constant"); | |
5418 | return PARSE_OPERAND_FAIL; | |
5419 | } | |
5420 | ||
5421 | inst.operands[i].imm = exp.X_add_number << 8; | |
5422 | inst.operands[i].immisalign = 1; | |
5423 | /* Alignments are not pre-indexes. */ | |
5424 | inst.operands[i].preind = 0; | |
5425 | ||
5426 | *str = p; | |
5427 | return PARSE_OPERAND_SUCCESS; | |
5428 | } | |
5429 | ||
c19d1205 ZW |
5430 | /* Parse all forms of an ARM address expression. Information is written |
5431 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 5432 | |
c19d1205 | 5433 | Preindexed addressing (.preind=1): |
09d92015 | 5434 | |
c19d1205 ZW |
5435 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
5436 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5437 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5438 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5439 | |
c19d1205 | 5440 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5441 | |
c19d1205 | 5442 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5443 | |
c19d1205 ZW |
5444 | [Rn], #offset .reg=Rn .reloc.exp=offset |
5445 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5446 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5447 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5448 | |
c19d1205 | 5449 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5450 | |
c19d1205 | 5451 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5452 | |
c19d1205 | 5453 | Other: |
09d92015 | 5454 | |
c19d1205 ZW |
5455 | [Rn]{!} shorthand for [Rn,#0]{!} |
5456 | =immediate .isreg=0 .reloc.exp=immediate | |
5457 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 5458 | |
c19d1205 ZW |
5459 | It is the caller's responsibility to check for addressing modes not |
5460 | supported by the instruction, and to set inst.reloc.type. */ | |
5461 | ||
4962c51a MS |
5462 | static parse_operand_result |
5463 | parse_address_main (char **str, int i, int group_relocations, | |
477330fc | 5464 | group_reloc_type group_type) |
09d92015 | 5465 | { |
c19d1205 ZW |
5466 | char *p = *str; |
5467 | int reg; | |
09d92015 | 5468 | |
c19d1205 | 5469 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5470 | { |
c19d1205 ZW |
5471 | if (skip_past_char (&p, '=') == FAIL) |
5472 | { | |
974da60d | 5473 | /* Bare address - translate to PC-relative offset. */ |
c19d1205 ZW |
5474 | inst.reloc.pc_rel = 1; |
5475 | inst.operands[i].reg = REG_PC; | |
5476 | inst.operands[i].isreg = 1; | |
5477 | inst.operands[i].preind = 1; | |
09d92015 | 5478 | |
8335d6aa JW |
5479 | if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG)) |
5480 | return PARSE_OPERAND_FAIL; | |
5481 | } | |
5482 | else if (parse_big_immediate (&p, i, &inst.reloc.exp, | |
5483 | /*allow_symbol_p=*/TRUE)) | |
4962c51a | 5484 | return PARSE_OPERAND_FAIL; |
09d92015 | 5485 | |
c19d1205 | 5486 | *str = p; |
4962c51a | 5487 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5488 | } |
5489 | ||
8ab8155f NC |
5490 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5491 | skip_whitespace (p); | |
5492 | ||
dcbf9037 | 5493 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 5494 | { |
c19d1205 | 5495 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 5496 | return PARSE_OPERAND_FAIL; |
09d92015 | 5497 | } |
c19d1205 ZW |
5498 | inst.operands[i].reg = reg; |
5499 | inst.operands[i].isreg = 1; | |
09d92015 | 5500 | |
c19d1205 | 5501 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5502 | { |
c19d1205 | 5503 | inst.operands[i].preind = 1; |
09d92015 | 5504 | |
c19d1205 ZW |
5505 | if (*p == '+') p++; |
5506 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5507 | ||
dcbf9037 | 5508 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5509 | { |
c19d1205 ZW |
5510 | inst.operands[i].imm = reg; |
5511 | inst.operands[i].immisreg = 1; | |
5512 | ||
5513 | if (skip_past_comma (&p) == SUCCESS) | |
5514 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5515 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5516 | } |
5287ad62 | 5517 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5518 | { |
5519 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5520 | code before we get to see it here. This may be subject to | |
5521 | change. */ | |
5522 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5523 | |
8e560766 MGD |
5524 | if (result != PARSE_OPERAND_SUCCESS) |
5525 | return result; | |
5526 | } | |
c19d1205 ZW |
5527 | else |
5528 | { | |
5529 | if (inst.operands[i].negative) | |
5530 | { | |
5531 | inst.operands[i].negative = 0; | |
5532 | p--; | |
5533 | } | |
4962c51a | 5534 | |
5f4273c7 NC |
5535 | if (group_relocations |
5536 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5537 | { |
5538 | struct group_reloc_table_entry *entry; | |
5539 | ||
477330fc RM |
5540 | /* Skip over the #: or : sequence. */ |
5541 | if (*p == '#') | |
5542 | p += 2; | |
5543 | else | |
5544 | p++; | |
4962c51a MS |
5545 | |
5546 | /* Try to parse a group relocation. Anything else is an | |
477330fc | 5547 | error. */ |
4962c51a MS |
5548 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) |
5549 | { | |
5550 | inst.error = _("unknown group relocation"); | |
5551 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5552 | } | |
5553 | ||
5554 | /* We now have the group relocation table entry corresponding to | |
5555 | the name in the assembler source. Next, we parse the | |
477330fc | 5556 | expression. */ |
4962c51a MS |
5557 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
5558 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5559 | ||
5560 | /* Record the relocation type. */ | |
477330fc RM |
5561 | switch (group_type) |
5562 | { | |
5563 | case GROUP_LDR: | |
5564 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code; | |
5565 | break; | |
4962c51a | 5566 | |
477330fc RM |
5567 | case GROUP_LDRS: |
5568 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code; | |
5569 | break; | |
4962c51a | 5570 | |
477330fc RM |
5571 | case GROUP_LDC: |
5572 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code; | |
5573 | break; | |
4962c51a | 5574 | |
477330fc RM |
5575 | default: |
5576 | gas_assert (0); | |
5577 | } | |
4962c51a | 5578 | |
477330fc | 5579 | if (inst.reloc.type == 0) |
4962c51a MS |
5580 | { |
5581 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5582 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5583 | } | |
477330fc RM |
5584 | } |
5585 | else | |
26d97720 NS |
5586 | { |
5587 | char *q = p; | |
5588 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5589 | return PARSE_OPERAND_FAIL; | |
5590 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
5591 | if (inst.reloc.exp.X_op == O_constant | |
5592 | && inst.reloc.exp.X_add_number == 0) | |
5593 | { | |
5594 | skip_whitespace (q); | |
5595 | if (*q == '#') | |
5596 | { | |
5597 | q++; | |
5598 | skip_whitespace (q); | |
5599 | } | |
5600 | if (*q == '-') | |
5601 | inst.operands[i].negative = 1; | |
5602 | } | |
5603 | } | |
09d92015 MM |
5604 | } |
5605 | } | |
8e560766 MGD |
5606 | else if (skip_past_char (&p, ':') == SUCCESS) |
5607 | { | |
5608 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
5609 | before we get to see it here. This may be subject to change. */ | |
5610 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5611 | |
8e560766 MGD |
5612 | if (result != PARSE_OPERAND_SUCCESS) |
5613 | return result; | |
5614 | } | |
09d92015 | 5615 | |
c19d1205 | 5616 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5617 | { |
c19d1205 | 5618 | inst.error = _("']' expected"); |
4962c51a | 5619 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5620 | } |
5621 | ||
c19d1205 ZW |
5622 | if (skip_past_char (&p, '!') == SUCCESS) |
5623 | inst.operands[i].writeback = 1; | |
09d92015 | 5624 | |
c19d1205 | 5625 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5626 | { |
c19d1205 ZW |
5627 | if (skip_past_char (&p, '{') == SUCCESS) |
5628 | { | |
5629 | /* [Rn], {expr} - unindexed, with option */ | |
5630 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5631 | 0, 255, TRUE) == FAIL) |
4962c51a | 5632 | return PARSE_OPERAND_FAIL; |
09d92015 | 5633 | |
c19d1205 ZW |
5634 | if (skip_past_char (&p, '}') == FAIL) |
5635 | { | |
5636 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5637 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5638 | } |
5639 | if (inst.operands[i].preind) | |
5640 | { | |
5641 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5642 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5643 | } |
5644 | *str = p; | |
4962c51a | 5645 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5646 | } |
c19d1205 ZW |
5647 | else |
5648 | { | |
5649 | inst.operands[i].postind = 1; | |
5650 | inst.operands[i].writeback = 1; | |
09d92015 | 5651 | |
c19d1205 ZW |
5652 | if (inst.operands[i].preind) |
5653 | { | |
5654 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5655 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5656 | } |
09d92015 | 5657 | |
c19d1205 ZW |
5658 | if (*p == '+') p++; |
5659 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5660 | |
dcbf9037 | 5661 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5662 | { |
477330fc RM |
5663 | /* We might be using the immediate for alignment already. If we |
5664 | are, OR the register number into the low-order bits. */ | |
5665 | if (inst.operands[i].immisalign) | |
5666 | inst.operands[i].imm |= reg; | |
5667 | else | |
5668 | inst.operands[i].imm = reg; | |
c19d1205 | 5669 | inst.operands[i].immisreg = 1; |
a737bd4d | 5670 | |
c19d1205 ZW |
5671 | if (skip_past_comma (&p) == SUCCESS) |
5672 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5673 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5674 | } |
5675 | else | |
5676 | { | |
26d97720 | 5677 | char *q = p; |
c19d1205 ZW |
5678 | if (inst.operands[i].negative) |
5679 | { | |
5680 | inst.operands[i].negative = 0; | |
5681 | p--; | |
5682 | } | |
5683 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5684 | return PARSE_OPERAND_FAIL; |
26d97720 NS |
5685 | /* If the offset is 0, find out if it's a +0 or -0. */ |
5686 | if (inst.reloc.exp.X_op == O_constant | |
5687 | && inst.reloc.exp.X_add_number == 0) | |
5688 | { | |
5689 | skip_whitespace (q); | |
5690 | if (*q == '#') | |
5691 | { | |
5692 | q++; | |
5693 | skip_whitespace (q); | |
5694 | } | |
5695 | if (*q == '-') | |
5696 | inst.operands[i].negative = 1; | |
5697 | } | |
c19d1205 ZW |
5698 | } |
5699 | } | |
a737bd4d NC |
5700 | } |
5701 | ||
c19d1205 ZW |
5702 | /* If at this point neither .preind nor .postind is set, we have a |
5703 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5704 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5705 | { | |
5706 | inst.operands[i].preind = 1; | |
5707 | inst.reloc.exp.X_op = O_constant; | |
5708 | inst.reloc.exp.X_add_number = 0; | |
5709 | } | |
5710 | *str = p; | |
4962c51a MS |
5711 | return PARSE_OPERAND_SUCCESS; |
5712 | } | |
5713 | ||
5714 | static int | |
5715 | parse_address (char **str, int i) | |
5716 | { | |
21d799b5 | 5717 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
477330fc | 5718 | ? SUCCESS : FAIL; |
4962c51a MS |
5719 | } |
5720 | ||
5721 | static parse_operand_result | |
5722 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5723 | { | |
5724 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5725 | } |
5726 | ||
b6895b4f PB |
5727 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5728 | static int | |
5729 | parse_half (char **str) | |
5730 | { | |
5731 | char * p; | |
5f4273c7 | 5732 | |
b6895b4f PB |
5733 | p = *str; |
5734 | skip_past_char (&p, '#'); | |
5f4273c7 | 5735 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5736 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5737 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5738 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5739 | ||
5740 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5741 | { | |
5742 | p += 9; | |
5f4273c7 | 5743 | skip_whitespace (p); |
b6895b4f PB |
5744 | } |
5745 | ||
5746 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5747 | return FAIL; | |
5748 | ||
5749 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5750 | { | |
5751 | if (inst.reloc.exp.X_op != O_constant) | |
5752 | { | |
5753 | inst.error = _("constant expression expected"); | |
5754 | return FAIL; | |
5755 | } | |
5756 | if (inst.reloc.exp.X_add_number < 0 | |
5757 | || inst.reloc.exp.X_add_number > 0xffff) | |
5758 | { | |
5759 | inst.error = _("immediate value out of range"); | |
5760 | return FAIL; | |
5761 | } | |
5762 | } | |
5763 | *str = p; | |
5764 | return SUCCESS; | |
5765 | } | |
5766 | ||
c19d1205 | 5767 | /* Miscellaneous. */ |
a737bd4d | 5768 | |
c19d1205 ZW |
5769 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5770 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5771 | static int | |
d2cd1205 | 5772 | parse_psr (char **str, bfd_boolean lhs) |
09d92015 | 5773 | { |
c19d1205 ZW |
5774 | char *p; |
5775 | unsigned long psr_field; | |
62b3e311 PB |
5776 | const struct asm_psr *psr; |
5777 | char *start; | |
d2cd1205 | 5778 | bfd_boolean is_apsr = FALSE; |
ac7f631b | 5779 | bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); |
09d92015 | 5780 | |
a4482bb6 NC |
5781 | /* PR gas/12698: If the user has specified -march=all then m_profile will |
5782 | be TRUE, but we want to ignore it in this case as we are building for any | |
5783 | CPU type, including non-m variants. */ | |
823d2571 | 5784 | if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) |
a4482bb6 NC |
5785 | m_profile = FALSE; |
5786 | ||
c19d1205 ZW |
5787 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5788 | feature for ease of use and backwards compatibility. */ | |
5789 | p = *str; | |
62b3e311 | 5790 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
5791 | { |
5792 | if (m_profile) | |
5793 | goto unsupported_psr; | |
fa94de6b | 5794 | |
d2cd1205 JB |
5795 | psr_field = SPSR_BIT; |
5796 | } | |
5797 | else if (strncasecmp (p, "CPSR", 4) == 0) | |
5798 | { | |
5799 | if (m_profile) | |
5800 | goto unsupported_psr; | |
5801 | ||
5802 | psr_field = 0; | |
5803 | } | |
5804 | else if (strncasecmp (p, "APSR", 4) == 0) | |
5805 | { | |
5806 | /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A | |
5807 | and ARMv7-R architecture CPUs. */ | |
5808 | is_apsr = TRUE; | |
5809 | psr_field = 0; | |
5810 | } | |
5811 | else if (m_profile) | |
62b3e311 PB |
5812 | { |
5813 | start = p; | |
5814 | do | |
5815 | p++; | |
5816 | while (ISALNUM (*p) || *p == '_'); | |
5817 | ||
d2cd1205 JB |
5818 | if (strncasecmp (start, "iapsr", 5) == 0 |
5819 | || strncasecmp (start, "eapsr", 5) == 0 | |
5820 | || strncasecmp (start, "xpsr", 4) == 0 | |
5821 | || strncasecmp (start, "psr", 3) == 0) | |
5822 | p = start + strcspn (start, "rR") + 1; | |
5823 | ||
21d799b5 | 5824 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
477330fc | 5825 | p - start); |
d2cd1205 | 5826 | |
62b3e311 PB |
5827 | if (!psr) |
5828 | return FAIL; | |
09d92015 | 5829 | |
d2cd1205 JB |
5830 | /* If APSR is being written, a bitfield may be specified. Note that |
5831 | APSR itself is handled above. */ | |
5832 | if (psr->field <= 3) | |
5833 | { | |
5834 | psr_field = psr->field; | |
5835 | is_apsr = TRUE; | |
5836 | goto check_suffix; | |
5837 | } | |
5838 | ||
62b3e311 | 5839 | *str = p; |
d2cd1205 JB |
5840 | /* M-profile MSR instructions have the mask field set to "10", except |
5841 | *PSR variants which modify APSR, which may use a different mask (and | |
5842 | have been handled already). Do that by setting the PSR_f field | |
5843 | here. */ | |
5844 | return psr->field | (lhs ? PSR_f : 0); | |
62b3e311 | 5845 | } |
d2cd1205 JB |
5846 | else |
5847 | goto unsupported_psr; | |
09d92015 | 5848 | |
62b3e311 | 5849 | p += 4; |
d2cd1205 | 5850 | check_suffix: |
c19d1205 ZW |
5851 | if (*p == '_') |
5852 | { | |
5853 | /* A suffix follows. */ | |
c19d1205 ZW |
5854 | p++; |
5855 | start = p; | |
a737bd4d | 5856 | |
c19d1205 ZW |
5857 | do |
5858 | p++; | |
5859 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5860 | |
d2cd1205 JB |
5861 | if (is_apsr) |
5862 | { | |
5863 | /* APSR uses a notation for bits, rather than fields. */ | |
5864 | unsigned int nzcvq_bits = 0; | |
5865 | unsigned int g_bit = 0; | |
5866 | char *bit; | |
fa94de6b | 5867 | |
d2cd1205 JB |
5868 | for (bit = start; bit != p; bit++) |
5869 | { | |
5870 | switch (TOLOWER (*bit)) | |
477330fc | 5871 | { |
d2cd1205 JB |
5872 | case 'n': |
5873 | nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01; | |
5874 | break; | |
5875 | ||
5876 | case 'z': | |
5877 | nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02; | |
5878 | break; | |
5879 | ||
5880 | case 'c': | |
5881 | nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04; | |
5882 | break; | |
5883 | ||
5884 | case 'v': | |
5885 | nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08; | |
5886 | break; | |
fa94de6b | 5887 | |
d2cd1205 JB |
5888 | case 'q': |
5889 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
5890 | break; | |
fa94de6b | 5891 | |
d2cd1205 JB |
5892 | case 'g': |
5893 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
5894 | break; | |
fa94de6b | 5895 | |
d2cd1205 JB |
5896 | default: |
5897 | inst.error = _("unexpected bit specified after APSR"); | |
5898 | return FAIL; | |
5899 | } | |
5900 | } | |
fa94de6b | 5901 | |
d2cd1205 JB |
5902 | if (nzcvq_bits == 0x1f) |
5903 | psr_field |= PSR_f; | |
fa94de6b | 5904 | |
d2cd1205 JB |
5905 | if (g_bit == 0x1) |
5906 | { | |
5907 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
477330fc | 5908 | { |
d2cd1205 JB |
5909 | inst.error = _("selected processor does not " |
5910 | "support DSP extension"); | |
5911 | return FAIL; | |
5912 | } | |
5913 | ||
5914 | psr_field |= PSR_s; | |
5915 | } | |
fa94de6b | 5916 | |
d2cd1205 JB |
5917 | if ((nzcvq_bits & 0x20) != 0 |
5918 | || (nzcvq_bits != 0x1f && nzcvq_bits != 0) | |
5919 | || (g_bit & 0x2) != 0) | |
5920 | { | |
5921 | inst.error = _("bad bitmask specified after APSR"); | |
5922 | return FAIL; | |
5923 | } | |
5924 | } | |
5925 | else | |
477330fc | 5926 | { |
d2cd1205 | 5927 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
477330fc | 5928 | p - start); |
d2cd1205 | 5929 | if (!psr) |
477330fc | 5930 | goto error; |
a737bd4d | 5931 | |
d2cd1205 JB |
5932 | psr_field |= psr->field; |
5933 | } | |
a737bd4d | 5934 | } |
c19d1205 | 5935 | else |
a737bd4d | 5936 | { |
c19d1205 ZW |
5937 | if (ISALNUM (*p)) |
5938 | goto error; /* Garbage after "[CS]PSR". */ | |
5939 | ||
d2cd1205 | 5940 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
477330fc | 5941 | is deprecated, but allow it anyway. */ |
d2cd1205 JB |
5942 | if (is_apsr && lhs) |
5943 | { | |
5944 | psr_field |= PSR_f; | |
5945 | as_tsktsk (_("writing to APSR without specifying a bitmask is " | |
5946 | "deprecated")); | |
5947 | } | |
5948 | else if (!m_profile) | |
5949 | /* These bits are never right for M-profile devices: don't set them | |
5950 | (only code paths which read/write APSR reach here). */ | |
5951 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5952 | } |
c19d1205 ZW |
5953 | *str = p; |
5954 | return psr_field; | |
a737bd4d | 5955 | |
d2cd1205 JB |
5956 | unsupported_psr: |
5957 | inst.error = _("selected processor does not support requested special " | |
5958 | "purpose register"); | |
5959 | return FAIL; | |
5960 | ||
c19d1205 ZW |
5961 | error: |
5962 | inst.error = _("flag for {c}psr instruction expected"); | |
5963 | return FAIL; | |
a737bd4d NC |
5964 | } |
5965 | ||
c19d1205 ZW |
5966 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5967 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5968 | |
c19d1205 ZW |
5969 | static int |
5970 | parse_cps_flags (char **str) | |
a737bd4d | 5971 | { |
c19d1205 ZW |
5972 | int val = 0; |
5973 | int saw_a_flag = 0; | |
5974 | char *s = *str; | |
a737bd4d | 5975 | |
c19d1205 ZW |
5976 | for (;;) |
5977 | switch (*s++) | |
5978 | { | |
5979 | case '\0': case ',': | |
5980 | goto done; | |
a737bd4d | 5981 | |
c19d1205 ZW |
5982 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5983 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5984 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5985 | |
c19d1205 ZW |
5986 | default: |
5987 | inst.error = _("unrecognized CPS flag"); | |
5988 | return FAIL; | |
5989 | } | |
a737bd4d | 5990 | |
c19d1205 ZW |
5991 | done: |
5992 | if (saw_a_flag == 0) | |
a737bd4d | 5993 | { |
c19d1205 ZW |
5994 | inst.error = _("missing CPS flags"); |
5995 | return FAIL; | |
a737bd4d | 5996 | } |
a737bd4d | 5997 | |
c19d1205 ZW |
5998 | *str = s - 1; |
5999 | return val; | |
a737bd4d NC |
6000 | } |
6001 | ||
c19d1205 ZW |
6002 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
6003 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
6004 | |
6005 | static int | |
c19d1205 | 6006 | parse_endian_specifier (char **str) |
a737bd4d | 6007 | { |
c19d1205 ZW |
6008 | int little_endian; |
6009 | char *s = *str; | |
a737bd4d | 6010 | |
c19d1205 ZW |
6011 | if (strncasecmp (s, "BE", 2)) |
6012 | little_endian = 0; | |
6013 | else if (strncasecmp (s, "LE", 2)) | |
6014 | little_endian = 1; | |
6015 | else | |
a737bd4d | 6016 | { |
c19d1205 | 6017 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6018 | return FAIL; |
6019 | } | |
6020 | ||
c19d1205 | 6021 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 6022 | { |
c19d1205 | 6023 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6024 | return FAIL; |
6025 | } | |
6026 | ||
c19d1205 ZW |
6027 | *str = s + 2; |
6028 | return little_endian; | |
6029 | } | |
a737bd4d | 6030 | |
c19d1205 ZW |
6031 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
6032 | value suitable for poking into the rotate field of an sxt or sxta | |
6033 | instruction, or FAIL on error. */ | |
6034 | ||
6035 | static int | |
6036 | parse_ror (char **str) | |
6037 | { | |
6038 | int rot; | |
6039 | char *s = *str; | |
6040 | ||
6041 | if (strncasecmp (s, "ROR", 3) == 0) | |
6042 | s += 3; | |
6043 | else | |
a737bd4d | 6044 | { |
c19d1205 | 6045 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
6046 | return FAIL; |
6047 | } | |
c19d1205 ZW |
6048 | |
6049 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
6050 | return FAIL; | |
6051 | ||
6052 | switch (rot) | |
a737bd4d | 6053 | { |
c19d1205 ZW |
6054 | case 0: *str = s; return 0x0; |
6055 | case 8: *str = s; return 0x1; | |
6056 | case 16: *str = s; return 0x2; | |
6057 | case 24: *str = s; return 0x3; | |
6058 | ||
6059 | default: | |
6060 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
6061 | return FAIL; |
6062 | } | |
c19d1205 | 6063 | } |
a737bd4d | 6064 | |
c19d1205 ZW |
6065 | /* Parse a conditional code (from conds[] below). The value returned is in the |
6066 | range 0 .. 14, or FAIL. */ | |
6067 | static int | |
6068 | parse_cond (char **str) | |
6069 | { | |
c462b453 | 6070 | char *q; |
c19d1205 | 6071 | const struct asm_cond *c; |
c462b453 PB |
6072 | int n; |
6073 | /* Condition codes are always 2 characters, so matching up to | |
6074 | 3 characters is sufficient. */ | |
6075 | char cond[3]; | |
a737bd4d | 6076 | |
c462b453 PB |
6077 | q = *str; |
6078 | n = 0; | |
6079 | while (ISALPHA (*q) && n < 3) | |
6080 | { | |
e07e6e58 | 6081 | cond[n] = TOLOWER (*q); |
c462b453 PB |
6082 | q++; |
6083 | n++; | |
6084 | } | |
a737bd4d | 6085 | |
21d799b5 | 6086 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 6087 | if (!c) |
a737bd4d | 6088 | { |
c19d1205 | 6089 | inst.error = _("condition required"); |
a737bd4d NC |
6090 | return FAIL; |
6091 | } | |
6092 | ||
c19d1205 ZW |
6093 | *str = q; |
6094 | return c->value; | |
6095 | } | |
6096 | ||
643afb90 MW |
6097 | /* Record a use of the given feature. */ |
6098 | static void | |
6099 | record_feature_use (const arm_feature_set *feature) | |
6100 | { | |
6101 | if (thumb_mode) | |
6102 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature); | |
6103 | else | |
6104 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature); | |
6105 | } | |
6106 | ||
e797f7e0 MGD |
6107 | /* If the given feature available in the selected CPU, mark it as used. |
6108 | Returns TRUE iff feature is available. */ | |
6109 | static bfd_boolean | |
6110 | mark_feature_used (const arm_feature_set *feature) | |
6111 | { | |
6112 | /* Ensure the option is valid on the current architecture. */ | |
6113 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
6114 | return FALSE; | |
6115 | ||
6116 | /* Add the appropriate architecture feature for the barrier option used. | |
6117 | */ | |
643afb90 | 6118 | record_feature_use (feature); |
e797f7e0 MGD |
6119 | |
6120 | return TRUE; | |
6121 | } | |
6122 | ||
62b3e311 PB |
6123 | /* Parse an option for a barrier instruction. Returns the encoding for the |
6124 | option, or FAIL. */ | |
6125 | static int | |
6126 | parse_barrier (char **str) | |
6127 | { | |
6128 | char *p, *q; | |
6129 | const struct asm_barrier_opt *o; | |
6130 | ||
6131 | p = q = *str; | |
6132 | while (ISALPHA (*q)) | |
6133 | q++; | |
6134 | ||
21d799b5 | 6135 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
477330fc | 6136 | q - p); |
62b3e311 PB |
6137 | if (!o) |
6138 | return FAIL; | |
6139 | ||
e797f7e0 MGD |
6140 | if (!mark_feature_used (&o->arch)) |
6141 | return FAIL; | |
6142 | ||
62b3e311 PB |
6143 | *str = q; |
6144 | return o->value; | |
6145 | } | |
6146 | ||
92e90b6e PB |
6147 | /* Parse the operands of a table branch instruction. Similar to a memory |
6148 | operand. */ | |
6149 | static int | |
6150 | parse_tb (char **str) | |
6151 | { | |
6152 | char * p = *str; | |
6153 | int reg; | |
6154 | ||
6155 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
6156 | { |
6157 | inst.error = _("'[' expected"); | |
6158 | return FAIL; | |
6159 | } | |
92e90b6e | 6160 | |
dcbf9037 | 6161 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6162 | { |
6163 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6164 | return FAIL; | |
6165 | } | |
6166 | inst.operands[0].reg = reg; | |
6167 | ||
6168 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
6169 | { |
6170 | inst.error = _("',' expected"); | |
6171 | return FAIL; | |
6172 | } | |
5f4273c7 | 6173 | |
dcbf9037 | 6174 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6175 | { |
6176 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6177 | return FAIL; | |
6178 | } | |
6179 | inst.operands[0].imm = reg; | |
6180 | ||
6181 | if (skip_past_comma (&p) == SUCCESS) | |
6182 | { | |
6183 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
6184 | return FAIL; | |
6185 | if (inst.reloc.exp.X_add_number != 1) | |
6186 | { | |
6187 | inst.error = _("invalid shift"); | |
6188 | return FAIL; | |
6189 | } | |
6190 | inst.operands[0].shifted = 1; | |
6191 | } | |
6192 | ||
6193 | if (skip_past_char (&p, ']') == FAIL) | |
6194 | { | |
6195 | inst.error = _("']' expected"); | |
6196 | return FAIL; | |
6197 | } | |
6198 | *str = p; | |
6199 | return SUCCESS; | |
6200 | } | |
6201 | ||
5287ad62 JB |
6202 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
6203 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
6204 | Up to four operands may be read; this function handles setting the |
6205 | ".present" field for each read operand itself. | |
5287ad62 JB |
6206 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
6207 | else returns FAIL. */ | |
6208 | ||
6209 | static int | |
6210 | parse_neon_mov (char **str, int *which_operand) | |
6211 | { | |
6212 | int i = *which_operand, val; | |
6213 | enum arm_reg_type rtype; | |
6214 | char *ptr = *str; | |
dcbf9037 | 6215 | struct neon_type_el optype; |
5f4273c7 | 6216 | |
dcbf9037 | 6217 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
6218 | { |
6219 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
6220 | inst.operands[i].reg = val; | |
6221 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 6222 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6223 | inst.operands[i++].present = 1; |
6224 | ||
6225 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6226 | goto wanted_comma; |
5f4273c7 | 6227 | |
dcbf9037 | 6228 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
477330fc | 6229 | goto wanted_arm; |
5f4273c7 | 6230 | |
5287ad62 JB |
6231 | inst.operands[i].reg = val; |
6232 | inst.operands[i].isreg = 1; | |
6233 | inst.operands[i].present = 1; | |
6234 | } | |
037e8744 | 6235 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
477330fc | 6236 | != FAIL) |
5287ad62 JB |
6237 | { |
6238 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
6239 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6240 | goto wanted_comma; |
5f4273c7 | 6241 | |
5287ad62 JB |
6242 | inst.operands[i].reg = val; |
6243 | inst.operands[i].isreg = 1; | |
6244 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
6245 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
6246 | inst.operands[i].isvec = 1; | |
dcbf9037 | 6247 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6248 | inst.operands[i++].present = 1; |
6249 | ||
dcbf9037 | 6250 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6251 | { |
6252 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. | |
6253 | Case 13: VMOV <Sd>, <Rm> */ | |
6254 | inst.operands[i].reg = val; | |
6255 | inst.operands[i].isreg = 1; | |
6256 | inst.operands[i].present = 1; | |
6257 | ||
6258 | if (rtype == REG_TYPE_NQ) | |
6259 | { | |
6260 | first_error (_("can't use Neon quad register here")); | |
6261 | return FAIL; | |
6262 | } | |
6263 | else if (rtype != REG_TYPE_VFS) | |
6264 | { | |
6265 | i++; | |
6266 | if (skip_past_comma (&ptr) == FAIL) | |
6267 | goto wanted_comma; | |
6268 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6269 | goto wanted_arm; | |
6270 | inst.operands[i].reg = val; | |
6271 | inst.operands[i].isreg = 1; | |
6272 | inst.operands[i].present = 1; | |
6273 | } | |
6274 | } | |
037e8744 | 6275 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
477330fc RM |
6276 | &optype)) != FAIL) |
6277 | { | |
6278 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
6279 | Case 1: VMOV<c><q> <Dd>, <Dm> | |
6280 | Case 8: VMOV.F32 <Sd>, <Sm> | |
6281 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
6282 | ||
6283 | inst.operands[i].reg = val; | |
6284 | inst.operands[i].isreg = 1; | |
6285 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
6286 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6287 | inst.operands[i].isvec = 1; | |
6288 | inst.operands[i].vectype = optype; | |
6289 | inst.operands[i].present = 1; | |
6290 | ||
6291 | if (skip_past_comma (&ptr) == SUCCESS) | |
6292 | { | |
6293 | /* Case 15. */ | |
6294 | i++; | |
6295 | ||
6296 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6297 | goto wanted_arm; | |
6298 | ||
6299 | inst.operands[i].reg = val; | |
6300 | inst.operands[i].isreg = 1; | |
6301 | inst.operands[i++].present = 1; | |
6302 | ||
6303 | if (skip_past_comma (&ptr) == FAIL) | |
6304 | goto wanted_comma; | |
6305 | ||
6306 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6307 | goto wanted_arm; | |
6308 | ||
6309 | inst.operands[i].reg = val; | |
6310 | inst.operands[i].isreg = 1; | |
6311 | inst.operands[i].present = 1; | |
6312 | } | |
6313 | } | |
4641781c | 6314 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
477330fc RM |
6315 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
6316 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
6317 | Case 10: VMOV.F32 <Sd>, #<imm> | |
6318 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
6319 | inst.operands[i].immisfloat = 1; | |
8335d6aa JW |
6320 | else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE) |
6321 | == SUCCESS) | |
477330fc RM |
6322 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
6323 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
6324 | ; | |
5287ad62 | 6325 | else |
477330fc RM |
6326 | { |
6327 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); | |
6328 | return FAIL; | |
6329 | } | |
5287ad62 | 6330 | } |
dcbf9037 | 6331 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
6332 | { |
6333 | /* Cases 6, 7. */ | |
6334 | inst.operands[i].reg = val; | |
6335 | inst.operands[i].isreg = 1; | |
6336 | inst.operands[i++].present = 1; | |
5f4273c7 | 6337 | |
5287ad62 | 6338 | if (skip_past_comma (&ptr) == FAIL) |
477330fc | 6339 | goto wanted_comma; |
5f4273c7 | 6340 | |
dcbf9037 | 6341 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
477330fc RM |
6342 | { |
6343 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
6344 | inst.operands[i].reg = val; | |
6345 | inst.operands[i].isscalar = 1; | |
6346 | inst.operands[i].present = 1; | |
6347 | inst.operands[i].vectype = optype; | |
6348 | } | |
dcbf9037 | 6349 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6350 | { |
6351 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
6352 | inst.operands[i].reg = val; | |
6353 | inst.operands[i].isreg = 1; | |
6354 | inst.operands[i++].present = 1; | |
6355 | ||
6356 | if (skip_past_comma (&ptr) == FAIL) | |
6357 | goto wanted_comma; | |
6358 | ||
6359 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) | |
6360 | == FAIL) | |
6361 | { | |
6362 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); | |
6363 | return FAIL; | |
6364 | } | |
6365 | ||
6366 | inst.operands[i].reg = val; | |
6367 | inst.operands[i].isreg = 1; | |
6368 | inst.operands[i].isvec = 1; | |
6369 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6370 | inst.operands[i].vectype = optype; | |
6371 | inst.operands[i].present = 1; | |
6372 | ||
6373 | if (rtype == REG_TYPE_VFS) | |
6374 | { | |
6375 | /* Case 14. */ | |
6376 | i++; | |
6377 | if (skip_past_comma (&ptr) == FAIL) | |
6378 | goto wanted_comma; | |
6379 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
6380 | &optype)) == FAIL) | |
6381 | { | |
6382 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
6383 | return FAIL; | |
6384 | } | |
6385 | inst.operands[i].reg = val; | |
6386 | inst.operands[i].isreg = 1; | |
6387 | inst.operands[i].isvec = 1; | |
6388 | inst.operands[i].issingle = 1; | |
6389 | inst.operands[i].vectype = optype; | |
6390 | inst.operands[i].present = 1; | |
6391 | } | |
6392 | } | |
037e8744 | 6393 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) |
477330fc RM |
6394 | != FAIL) |
6395 | { | |
6396 | /* Case 13. */ | |
6397 | inst.operands[i].reg = val; | |
6398 | inst.operands[i].isreg = 1; | |
6399 | inst.operands[i].isvec = 1; | |
6400 | inst.operands[i].issingle = 1; | |
6401 | inst.operands[i].vectype = optype; | |
6402 | inst.operands[i].present = 1; | |
6403 | } | |
5287ad62 JB |
6404 | } |
6405 | else | |
6406 | { | |
dcbf9037 | 6407 | first_error (_("parse error")); |
5287ad62 JB |
6408 | return FAIL; |
6409 | } | |
6410 | ||
6411 | /* Successfully parsed the operands. Update args. */ | |
6412 | *which_operand = i; | |
6413 | *str = ptr; | |
6414 | return SUCCESS; | |
6415 | ||
5f4273c7 | 6416 | wanted_comma: |
dcbf9037 | 6417 | first_error (_("expected comma")); |
5287ad62 | 6418 | return FAIL; |
5f4273c7 NC |
6419 | |
6420 | wanted_arm: | |
dcbf9037 | 6421 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 6422 | return FAIL; |
5287ad62 JB |
6423 | } |
6424 | ||
5be8be5d DG |
6425 | /* Use this macro when the operand constraints are different |
6426 | for ARM and THUMB (e.g. ldrd). */ | |
6427 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
6428 | ((arm_operand) | ((thumb_operand) << 16)) | |
6429 | ||
c19d1205 ZW |
6430 | /* Matcher codes for parse_operands. */ |
6431 | enum operand_parse_code | |
6432 | { | |
6433 | OP_stop, /* end of line */ | |
6434 | ||
6435 | OP_RR, /* ARM register */ | |
6436 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 6437 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 6438 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 6439 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 6440 | optional trailing ! */ |
c19d1205 ZW |
6441 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
6442 | OP_RCP, /* Coprocessor number */ | |
6443 | OP_RCN, /* Coprocessor register */ | |
6444 | OP_RF, /* FPA register */ | |
6445 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
6446 | OP_RVD, /* VFP double precision register (0..15) */ |
6447 | OP_RND, /* Neon double precision register (0..31) */ | |
6448 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 6449 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 6450 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 6451 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 6452 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
6453 | OP_RVC, /* VFP control register */ |
6454 | OP_RMF, /* Maverick F register */ | |
6455 | OP_RMD, /* Maverick D register */ | |
6456 | OP_RMFX, /* Maverick FX register */ | |
6457 | OP_RMDX, /* Maverick DX register */ | |
6458 | OP_RMAX, /* Maverick AX register */ | |
6459 | OP_RMDS, /* Maverick DSPSC register */ | |
6460 | OP_RIWR, /* iWMMXt wR register */ | |
6461 | OP_RIWC, /* iWMMXt wC register */ | |
6462 | OP_RIWG, /* iWMMXt wCG register */ | |
6463 | OP_RXA, /* XScale accumulator register */ | |
6464 | ||
6465 | OP_REGLST, /* ARM register list */ | |
6466 | OP_VRSLST, /* VFP single-precision register list */ | |
6467 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 6468 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
6469 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
6470 | OP_NSTRLST, /* Neon element/structure list */ | |
6471 | ||
5287ad62 | 6472 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 6473 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
aacf0b33 | 6474 | OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */ |
5287ad62 | 6475 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 6476 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
6477 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
6478 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
6479 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 6480 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
5287ad62 | 6481 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
2d447fca | 6482 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
6483 | |
6484 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
6485 | OP_I7, /* immediate value 0 .. 7 */ |
6486 | OP_I15, /* 0 .. 15 */ | |
6487 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 6488 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
6489 | OP_I31, /* 0 .. 31 */ |
6490 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
6491 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
6492 | OP_I32z, /* 0 .. 32 */ |
6493 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 6494 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
6495 | OP_I64, /* 1 .. 64 */ |
6496 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 6497 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
6498 | |
6499 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
6500 | OP_I7b, /* 0 .. 7 */ | |
6501 | OP_I15b, /* 0 .. 15 */ | |
6502 | OP_I31b, /* 0 .. 31 */ | |
6503 | ||
6504 | OP_SH, /* shifter operand */ | |
4962c51a | 6505 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 6506 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
6507 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
6508 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
6509 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
6510 | OP_EXP, /* arbitrary expression */ |
6511 | OP_EXPi, /* same, with optional immediate prefix */ | |
6512 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 6513 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
6514 | |
6515 | OP_CPSF, /* CPS flags */ | |
6516 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
6517 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
6518 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 6519 | OP_COND, /* conditional code */ |
92e90b6e | 6520 | OP_TB, /* Table branch. */ |
c19d1205 | 6521 | |
037e8744 JB |
6522 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
6523 | ||
c19d1205 ZW |
6524 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
6525 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
6526 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
6527 | OP_RF_IF, /* FPA register or immediate */ | |
6528 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 6529 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
6530 | |
6531 | /* Optional operands. */ | |
6532 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
6533 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 6534 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 6535 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
6536 | OP_oIffffb, /* 0 .. 65535 */ |
6537 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
6538 | ||
6539 | OP_oRR, /* ARM register */ | |
6540 | OP_oRRnpc, /* ARM register, not the PC */ | |
5be8be5d | 6541 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 6542 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
6543 | OP_oRND, /* Optional Neon double precision register */ |
6544 | OP_oRNQ, /* Optional Neon quad precision register */ | |
6545 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 6546 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
6547 | OP_oSHll, /* LSL immediate */ |
6548 | OP_oSHar, /* ASR immediate */ | |
6549 | OP_oSHllar, /* LSL or ASR immediate */ | |
6550 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 6551 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 6552 | |
5be8be5d DG |
6553 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
6554 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
6555 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
6556 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
6557 | ||
c19d1205 ZW |
6558 | OP_FIRST_OPTIONAL = OP_oI7b |
6559 | }; | |
a737bd4d | 6560 | |
c19d1205 ZW |
6561 | /* Generic instruction operand parser. This does no encoding and no |
6562 | semantic validation; it merely squirrels values away in the inst | |
6563 | structure. Returns SUCCESS or FAIL depending on whether the | |
6564 | specified grammar matched. */ | |
6565 | static int | |
5be8be5d | 6566 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 6567 | { |
5be8be5d | 6568 | unsigned const int *upat = pattern; |
c19d1205 ZW |
6569 | char *backtrack_pos = 0; |
6570 | const char *backtrack_error = 0; | |
99aad254 | 6571 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 6572 | enum arm_reg_type rtype; |
4962c51a | 6573 | parse_operand_result result; |
5be8be5d | 6574 | unsigned int op_parse_code; |
c19d1205 | 6575 | |
e07e6e58 NC |
6576 | #define po_char_or_fail(chr) \ |
6577 | do \ | |
6578 | { \ | |
6579 | if (skip_past_char (&str, chr) == FAIL) \ | |
477330fc | 6580 | goto bad_args; \ |
e07e6e58 NC |
6581 | } \ |
6582 | while (0) | |
c19d1205 | 6583 | |
e07e6e58 NC |
6584 | #define po_reg_or_fail(regtype) \ |
6585 | do \ | |
dcbf9037 | 6586 | { \ |
e07e6e58 | 6587 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
477330fc | 6588 | & inst.operands[i].vectype); \ |
e07e6e58 | 6589 | if (val == FAIL) \ |
477330fc RM |
6590 | { \ |
6591 | first_error (_(reg_expected_msgs[regtype])); \ | |
6592 | goto failure; \ | |
6593 | } \ | |
e07e6e58 NC |
6594 | inst.operands[i].reg = val; \ |
6595 | inst.operands[i].isreg = 1; \ | |
6596 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6597 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6598 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc RM |
6599 | || rtype == REG_TYPE_VFD \ |
6600 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 6601 | } \ |
e07e6e58 NC |
6602 | while (0) |
6603 | ||
6604 | #define po_reg_or_goto(regtype, label) \ | |
6605 | do \ | |
6606 | { \ | |
6607 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
6608 | & inst.operands[i].vectype); \ | |
6609 | if (val == FAIL) \ | |
6610 | goto label; \ | |
dcbf9037 | 6611 | \ |
e07e6e58 NC |
6612 | inst.operands[i].reg = val; \ |
6613 | inst.operands[i].isreg = 1; \ | |
6614 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6615 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6616 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc | 6617 | || rtype == REG_TYPE_VFD \ |
e07e6e58 NC |
6618 | || rtype == REG_TYPE_NQ); \ |
6619 | } \ | |
6620 | while (0) | |
6621 | ||
6622 | #define po_imm_or_fail(min, max, popt) \ | |
6623 | do \ | |
6624 | { \ | |
6625 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
6626 | goto failure; \ | |
6627 | inst.operands[i].imm = val; \ | |
6628 | } \ | |
6629 | while (0) | |
6630 | ||
6631 | #define po_scalar_or_goto(elsz, label) \ | |
6632 | do \ | |
6633 | { \ | |
6634 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
6635 | if (val == FAIL) \ | |
6636 | goto label; \ | |
6637 | inst.operands[i].reg = val; \ | |
6638 | inst.operands[i].isscalar = 1; \ | |
6639 | } \ | |
6640 | while (0) | |
6641 | ||
6642 | #define po_misc_or_fail(expr) \ | |
6643 | do \ | |
6644 | { \ | |
6645 | if (expr) \ | |
6646 | goto failure; \ | |
6647 | } \ | |
6648 | while (0) | |
6649 | ||
6650 | #define po_misc_or_fail_no_backtrack(expr) \ | |
6651 | do \ | |
6652 | { \ | |
6653 | result = expr; \ | |
6654 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
6655 | backtrack_pos = 0; \ | |
6656 | if (result != PARSE_OPERAND_SUCCESS) \ | |
6657 | goto failure; \ | |
6658 | } \ | |
6659 | while (0) | |
4962c51a | 6660 | |
52e7f43d RE |
6661 | #define po_barrier_or_imm(str) \ |
6662 | do \ | |
6663 | { \ | |
6664 | val = parse_barrier (&str); \ | |
ccb84d65 JB |
6665 | if (val == FAIL && ! ISALPHA (*str)) \ |
6666 | goto immediate; \ | |
6667 | if (val == FAIL \ | |
6668 | /* ISB can only take SY as an option. */ \ | |
6669 | || ((inst.instruction & 0xf0) == 0x60 \ | |
6670 | && val != 0xf)) \ | |
52e7f43d | 6671 | { \ |
ccb84d65 JB |
6672 | inst.error = _("invalid barrier type"); \ |
6673 | backtrack_pos = 0; \ | |
6674 | goto failure; \ | |
52e7f43d RE |
6675 | } \ |
6676 | } \ | |
6677 | while (0) | |
6678 | ||
c19d1205 ZW |
6679 | skip_whitespace (str); |
6680 | ||
6681 | for (i = 0; upat[i] != OP_stop; i++) | |
6682 | { | |
5be8be5d DG |
6683 | op_parse_code = upat[i]; |
6684 | if (op_parse_code >= 1<<16) | |
6685 | op_parse_code = thumb ? (op_parse_code >> 16) | |
6686 | : (op_parse_code & ((1<<16)-1)); | |
6687 | ||
6688 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
6689 | { |
6690 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 6691 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
6692 | backtrack_pos = str; |
6693 | backtrack_error = inst.error; | |
6694 | backtrack_index = i; | |
6695 | } | |
6696 | ||
b6702015 | 6697 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
6698 | po_char_or_fail (','); |
6699 | ||
5be8be5d | 6700 | switch (op_parse_code) |
c19d1205 ZW |
6701 | { |
6702 | /* Registers */ | |
6703 | case OP_oRRnpc: | |
5be8be5d | 6704 | case OP_oRRnpcsp: |
c19d1205 | 6705 | case OP_RRnpc: |
5be8be5d | 6706 | case OP_RRnpcsp: |
c19d1205 ZW |
6707 | case OP_oRR: |
6708 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
6709 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
6710 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
6711 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
6712 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
6713 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
477330fc | 6714 | case OP_oRND: |
5287ad62 | 6715 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; |
cd2cf30b PB |
6716 | case OP_RVC: |
6717 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
6718 | break; | |
6719 | /* Also accept generic coprocessor regs for unknown registers. */ | |
6720 | coproc_reg: | |
6721 | po_reg_or_fail (REG_TYPE_CN); | |
6722 | break; | |
c19d1205 ZW |
6723 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
6724 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
6725 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
6726 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
6727 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
6728 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
6729 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
6730 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
6731 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
6732 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
477330fc | 6733 | case OP_oRNQ: |
5287ad62 | 6734 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; |
477330fc | 6735 | case OP_oRNDQ: |
5287ad62 | 6736 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; |
477330fc RM |
6737 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
6738 | case OP_oRNSDQ: | |
6739 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
6740 | ||
6741 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6742 | scalars are accepted here, so deal with those in later code. */ | |
6743 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6744 | ||
6745 | case OP_RNDQ_I0: | |
6746 | { | |
6747 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6748 | break; | |
6749 | try_imm0: | |
6750 | po_imm_or_fail (0, 0, TRUE); | |
6751 | } | |
6752 | break; | |
6753 | ||
6754 | case OP_RVSD_I0: | |
6755 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6756 | break; | |
6757 | ||
aacf0b33 KT |
6758 | case OP_RSVD_FI0: |
6759 | { | |
6760 | po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0); | |
6761 | break; | |
6762 | try_ifimm0: | |
6763 | if (parse_ifimm_zero (&str)) | |
6764 | inst.operands[i].imm = 0; | |
6765 | else | |
6766 | { | |
6767 | inst.error | |
6768 | = _("only floating point zero is allowed as immediate value"); | |
6769 | goto failure; | |
6770 | } | |
6771 | } | |
6772 | break; | |
6773 | ||
477330fc RM |
6774 | case OP_RR_RNSC: |
6775 | { | |
6776 | po_scalar_or_goto (8, try_rr); | |
6777 | break; | |
6778 | try_rr: | |
6779 | po_reg_or_fail (REG_TYPE_RN); | |
6780 | } | |
6781 | break; | |
6782 | ||
6783 | case OP_RNSDQ_RNSC: | |
6784 | { | |
6785 | po_scalar_or_goto (8, try_nsdq); | |
6786 | break; | |
6787 | try_nsdq: | |
6788 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6789 | } | |
6790 | break; | |
6791 | ||
6792 | case OP_RNDQ_RNSC: | |
6793 | { | |
6794 | po_scalar_or_goto (8, try_ndq); | |
6795 | break; | |
6796 | try_ndq: | |
6797 | po_reg_or_fail (REG_TYPE_NDQ); | |
6798 | } | |
6799 | break; | |
6800 | ||
6801 | case OP_RND_RNSC: | |
6802 | { | |
6803 | po_scalar_or_goto (8, try_vfd); | |
6804 | break; | |
6805 | try_vfd: | |
6806 | po_reg_or_fail (REG_TYPE_VFD); | |
6807 | } | |
6808 | break; | |
6809 | ||
6810 | case OP_VMOV: | |
6811 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6812 | not careful then bad things might happen. */ | |
6813 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6814 | break; | |
6815 | ||
6816 | case OP_RNDQ_Ibig: | |
6817 | { | |
6818 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); | |
6819 | break; | |
6820 | try_immbig: | |
6821 | /* There's a possibility of getting a 64-bit immediate here, so | |
6822 | we need special handling. */ | |
8335d6aa JW |
6823 | if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE) |
6824 | == FAIL) | |
477330fc RM |
6825 | { |
6826 | inst.error = _("immediate value is out of range"); | |
6827 | goto failure; | |
6828 | } | |
6829 | } | |
6830 | break; | |
6831 | ||
6832 | case OP_RNDQ_I63b: | |
6833 | { | |
6834 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6835 | break; | |
6836 | try_shimm: | |
6837 | po_imm_or_fail (0, 63, TRUE); | |
6838 | } | |
6839 | break; | |
c19d1205 ZW |
6840 | |
6841 | case OP_RRnpcb: | |
6842 | po_char_or_fail ('['); | |
6843 | po_reg_or_fail (REG_TYPE_RN); | |
6844 | po_char_or_fail (']'); | |
6845 | break; | |
a737bd4d | 6846 | |
55881a11 | 6847 | case OP_RRnpctw: |
c19d1205 | 6848 | case OP_RRw: |
b6702015 | 6849 | case OP_oRRw: |
c19d1205 ZW |
6850 | po_reg_or_fail (REG_TYPE_RN); |
6851 | if (skip_past_char (&str, '!') == SUCCESS) | |
6852 | inst.operands[i].writeback = 1; | |
6853 | break; | |
6854 | ||
6855 | /* Immediates */ | |
6856 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6857 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6858 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
477330fc | 6859 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6860 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6861 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
477330fc | 6862 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6863 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
477330fc RM |
6864 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6865 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6866 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6867 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6868 | |
6869 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6870 | case OP_oI7b: | |
6871 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6872 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6873 | case OP_oI31b: | |
6874 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
477330fc RM |
6875 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
6876 | case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break; | |
c19d1205 ZW |
6877 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6878 | ||
6879 | /* Immediate variants */ | |
6880 | case OP_oI255c: | |
6881 | po_char_or_fail ('{'); | |
6882 | po_imm_or_fail (0, 255, TRUE); | |
6883 | po_char_or_fail ('}'); | |
6884 | break; | |
6885 | ||
6886 | case OP_I31w: | |
6887 | /* The expression parser chokes on a trailing !, so we have | |
6888 | to find it first and zap it. */ | |
6889 | { | |
6890 | char *s = str; | |
6891 | while (*s && *s != ',') | |
6892 | s++; | |
6893 | if (s[-1] == '!') | |
6894 | { | |
6895 | s[-1] = '\0'; | |
6896 | inst.operands[i].writeback = 1; | |
6897 | } | |
6898 | po_imm_or_fail (0, 31, TRUE); | |
6899 | if (str == s - 1) | |
6900 | str = s; | |
6901 | } | |
6902 | break; | |
6903 | ||
6904 | /* Expressions */ | |
6905 | case OP_EXPi: EXPi: | |
6906 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6907 | GE_OPT_PREFIX)); | |
6908 | break; | |
6909 | ||
6910 | case OP_EXP: | |
6911 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6912 | GE_NO_PREFIX)); | |
6913 | break; | |
6914 | ||
6915 | case OP_EXPr: EXPr: | |
6916 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6917 | GE_NO_PREFIX)); | |
6918 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6919 | { |
c19d1205 ZW |
6920 | val = parse_reloc (&str); |
6921 | if (val == -1) | |
6922 | { | |
6923 | inst.error = _("unrecognized relocation suffix"); | |
6924 | goto failure; | |
6925 | } | |
6926 | else if (val != BFD_RELOC_UNUSED) | |
6927 | { | |
6928 | inst.operands[i].imm = val; | |
6929 | inst.operands[i].hasreloc = 1; | |
6930 | } | |
a737bd4d | 6931 | } |
c19d1205 | 6932 | break; |
a737bd4d | 6933 | |
b6895b4f PB |
6934 | /* Operand for MOVW or MOVT. */ |
6935 | case OP_HALF: | |
6936 | po_misc_or_fail (parse_half (&str)); | |
6937 | break; | |
6938 | ||
e07e6e58 | 6939 | /* Register or expression. */ |
c19d1205 ZW |
6940 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6941 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6942 | |
e07e6e58 | 6943 | /* Register or immediate. */ |
c19d1205 ZW |
6944 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6945 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6946 | |
c19d1205 ZW |
6947 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6948 | IF: | |
6949 | if (!is_immediate_prefix (*str)) | |
6950 | goto bad_args; | |
6951 | str++; | |
6952 | val = parse_fpa_immediate (&str); | |
6953 | if (val == FAIL) | |
6954 | goto failure; | |
6955 | /* FPA immediates are encoded as registers 8-15. | |
6956 | parse_fpa_immediate has already applied the offset. */ | |
6957 | inst.operands[i].reg = val; | |
6958 | inst.operands[i].isreg = 1; | |
6959 | break; | |
09d92015 | 6960 | |
2d447fca JM |
6961 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6962 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6963 | ||
e07e6e58 | 6964 | /* Two kinds of register. */ |
c19d1205 ZW |
6965 | case OP_RIWR_RIWC: |
6966 | { | |
6967 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6968 | if (!rege |
6969 | || (rege->type != REG_TYPE_MMXWR | |
6970 | && rege->type != REG_TYPE_MMXWC | |
6971 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6972 | { |
6973 | inst.error = _("iWMMXt data or control register expected"); | |
6974 | goto failure; | |
6975 | } | |
6976 | inst.operands[i].reg = rege->number; | |
6977 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6978 | } | |
6979 | break; | |
09d92015 | 6980 | |
41adaa5c JM |
6981 | case OP_RIWC_RIWG: |
6982 | { | |
6983 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6984 | if (!rege | |
6985 | || (rege->type != REG_TYPE_MMXWC | |
6986 | && rege->type != REG_TYPE_MMXWCG)) | |
6987 | { | |
6988 | inst.error = _("iWMMXt control register expected"); | |
6989 | goto failure; | |
6990 | } | |
6991 | inst.operands[i].reg = rege->number; | |
6992 | inst.operands[i].isreg = 1; | |
6993 | } | |
6994 | break; | |
6995 | ||
c19d1205 ZW |
6996 | /* Misc */ |
6997 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6998 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6999 | case OP_oROR: val = parse_ror (&str); break; | |
c19d1205 | 7000 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
7001 | case OP_oBARRIER_I15: |
7002 | po_barrier_or_imm (str); break; | |
7003 | immediate: | |
7004 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
477330fc | 7005 | goto failure; |
52e7f43d | 7006 | break; |
c19d1205 | 7007 | |
fa94de6b | 7008 | case OP_wPSR: |
d2cd1205 | 7009 | case OP_rPSR: |
90ec0d68 MGD |
7010 | po_reg_or_goto (REG_TYPE_RNB, try_psr); |
7011 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
7012 | { | |
7013 | inst.error = _("Banked registers are not available with this " | |
7014 | "architecture."); | |
7015 | goto failure; | |
7016 | } | |
7017 | break; | |
d2cd1205 JB |
7018 | try_psr: |
7019 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
7020 | break; | |
037e8744 | 7021 | |
477330fc RM |
7022 | case OP_APSR_RR: |
7023 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
7024 | break; | |
7025 | try_apsr: | |
7026 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
7027 | instruction). */ | |
7028 | if (strncasecmp (str, "APSR_", 5) == 0) | |
7029 | { | |
7030 | unsigned found = 0; | |
7031 | str += 5; | |
7032 | while (found < 15) | |
7033 | switch (*str++) | |
7034 | { | |
7035 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
7036 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
7037 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
7038 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
7039 | default: found = 16; | |
7040 | } | |
7041 | if (found != 15) | |
7042 | goto failure; | |
7043 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
7044 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
7045 | inst.operands[i].reg = REG_PC; | |
477330fc RM |
7046 | } |
7047 | else | |
7048 | goto failure; | |
7049 | break; | |
037e8744 | 7050 | |
92e90b6e PB |
7051 | case OP_TB: |
7052 | po_misc_or_fail (parse_tb (&str)); | |
7053 | break; | |
7054 | ||
e07e6e58 | 7055 | /* Register lists. */ |
c19d1205 ZW |
7056 | case OP_REGLST: |
7057 | val = parse_reg_list (&str); | |
7058 | if (*str == '^') | |
7059 | { | |
5e0d7f77 | 7060 | inst.operands[i].writeback = 1; |
c19d1205 ZW |
7061 | str++; |
7062 | } | |
7063 | break; | |
09d92015 | 7064 | |
c19d1205 | 7065 | case OP_VRSLST: |
5287ad62 | 7066 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 7067 | break; |
09d92015 | 7068 | |
c19d1205 | 7069 | case OP_VRDLST: |
5287ad62 | 7070 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 7071 | break; |
a737bd4d | 7072 | |
477330fc RM |
7073 | case OP_VRSDLST: |
7074 | /* Allow Q registers too. */ | |
7075 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7076 | REGLIST_NEON_D); | |
7077 | if (val == FAIL) | |
7078 | { | |
7079 | inst.error = NULL; | |
7080 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7081 | REGLIST_VFP_S); | |
7082 | inst.operands[i].issingle = 1; | |
7083 | } | |
7084 | break; | |
7085 | ||
7086 | case OP_NRDLST: | |
7087 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7088 | REGLIST_NEON_D); | |
7089 | break; | |
5287ad62 JB |
7090 | |
7091 | case OP_NSTRLST: | |
477330fc RM |
7092 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
7093 | &inst.operands[i].vectype); | |
7094 | break; | |
5287ad62 | 7095 | |
c19d1205 ZW |
7096 | /* Addressing modes */ |
7097 | case OP_ADDR: | |
7098 | po_misc_or_fail (parse_address (&str, i)); | |
7099 | break; | |
09d92015 | 7100 | |
4962c51a MS |
7101 | case OP_ADDRGLDR: |
7102 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7103 | parse_address_group_reloc (&str, i, GROUP_LDR)); |
4962c51a MS |
7104 | break; |
7105 | ||
7106 | case OP_ADDRGLDRS: | |
7107 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7108 | parse_address_group_reloc (&str, i, GROUP_LDRS)); |
4962c51a MS |
7109 | break; |
7110 | ||
7111 | case OP_ADDRGLDC: | |
7112 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7113 | parse_address_group_reloc (&str, i, GROUP_LDC)); |
4962c51a MS |
7114 | break; |
7115 | ||
c19d1205 ZW |
7116 | case OP_SH: |
7117 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
7118 | break; | |
09d92015 | 7119 | |
4962c51a MS |
7120 | case OP_SHG: |
7121 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7122 | parse_shifter_operand_group_reloc (&str, i)); |
4962c51a MS |
7123 | break; |
7124 | ||
c19d1205 ZW |
7125 | case OP_oSHll: |
7126 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
7127 | break; | |
09d92015 | 7128 | |
c19d1205 ZW |
7129 | case OP_oSHar: |
7130 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
7131 | break; | |
09d92015 | 7132 | |
c19d1205 ZW |
7133 | case OP_oSHllar: |
7134 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
7135 | break; | |
09d92015 | 7136 | |
c19d1205 | 7137 | default: |
5be8be5d | 7138 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 7139 | } |
09d92015 | 7140 | |
c19d1205 ZW |
7141 | /* Various value-based sanity checks and shared operations. We |
7142 | do not signal immediate failures for the register constraints; | |
7143 | this allows a syntax error to take precedence. */ | |
5be8be5d | 7144 | switch (op_parse_code) |
c19d1205 ZW |
7145 | { |
7146 | case OP_oRRnpc: | |
7147 | case OP_RRnpc: | |
7148 | case OP_RRnpcb: | |
7149 | case OP_RRw: | |
b6702015 | 7150 | case OP_oRRw: |
c19d1205 ZW |
7151 | case OP_RRnpc_I0: |
7152 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
7153 | inst.error = BAD_PC; | |
7154 | break; | |
09d92015 | 7155 | |
5be8be5d DG |
7156 | case OP_oRRnpcsp: |
7157 | case OP_RRnpcsp: | |
7158 | if (inst.operands[i].isreg) | |
7159 | { | |
7160 | if (inst.operands[i].reg == REG_PC) | |
7161 | inst.error = BAD_PC; | |
7162 | else if (inst.operands[i].reg == REG_SP) | |
7163 | inst.error = BAD_SP; | |
7164 | } | |
7165 | break; | |
7166 | ||
55881a11 | 7167 | case OP_RRnpctw: |
fa94de6b RM |
7168 | if (inst.operands[i].isreg |
7169 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
7170 | && (inst.operands[i].writeback || thumb)) |
7171 | inst.error = BAD_PC; | |
7172 | break; | |
7173 | ||
c19d1205 ZW |
7174 | case OP_CPSF: |
7175 | case OP_ENDI: | |
7176 | case OP_oROR: | |
d2cd1205 JB |
7177 | case OP_wPSR: |
7178 | case OP_rPSR: | |
c19d1205 | 7179 | case OP_COND: |
52e7f43d | 7180 | case OP_oBARRIER_I15: |
c19d1205 ZW |
7181 | case OP_REGLST: |
7182 | case OP_VRSLST: | |
7183 | case OP_VRDLST: | |
477330fc RM |
7184 | case OP_VRSDLST: |
7185 | case OP_NRDLST: | |
7186 | case OP_NSTRLST: | |
c19d1205 ZW |
7187 | if (val == FAIL) |
7188 | goto failure; | |
7189 | inst.operands[i].imm = val; | |
7190 | break; | |
a737bd4d | 7191 | |
c19d1205 ZW |
7192 | default: |
7193 | break; | |
7194 | } | |
09d92015 | 7195 | |
c19d1205 ZW |
7196 | /* If we get here, this operand was successfully parsed. */ |
7197 | inst.operands[i].present = 1; | |
7198 | continue; | |
09d92015 | 7199 | |
c19d1205 | 7200 | bad_args: |
09d92015 | 7201 | inst.error = BAD_ARGS; |
c19d1205 ZW |
7202 | |
7203 | failure: | |
7204 | if (!backtrack_pos) | |
d252fdde PB |
7205 | { |
7206 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 7207 | default here just in case. */ |
d252fdde PB |
7208 | if (!inst.error) |
7209 | inst.error = _("syntax error"); | |
7210 | return FAIL; | |
7211 | } | |
c19d1205 ZW |
7212 | |
7213 | /* Do not backtrack over a trailing optional argument that | |
7214 | absorbed some text. We will only fail again, with the | |
7215 | 'garbage following instruction' error message, which is | |
7216 | probably less helpful than the current one. */ | |
7217 | if (backtrack_index == i && backtrack_pos != str | |
7218 | && upat[i+1] == OP_stop) | |
d252fdde PB |
7219 | { |
7220 | if (!inst.error) | |
7221 | inst.error = _("syntax error"); | |
7222 | return FAIL; | |
7223 | } | |
c19d1205 ZW |
7224 | |
7225 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
7226 | str = backtrack_pos; | |
7227 | inst.error = backtrack_error; | |
7228 | inst.operands[backtrack_index].present = 0; | |
7229 | i = backtrack_index; | |
7230 | backtrack_pos = 0; | |
09d92015 | 7231 | } |
09d92015 | 7232 | |
c19d1205 ZW |
7233 | /* Check that we have parsed all the arguments. */ |
7234 | if (*str != '\0' && !inst.error) | |
7235 | inst.error = _("garbage following instruction"); | |
09d92015 | 7236 | |
c19d1205 | 7237 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
7238 | } |
7239 | ||
c19d1205 ZW |
7240 | #undef po_char_or_fail |
7241 | #undef po_reg_or_fail | |
7242 | #undef po_reg_or_goto | |
7243 | #undef po_imm_or_fail | |
5287ad62 | 7244 | #undef po_scalar_or_fail |
52e7f43d | 7245 | #undef po_barrier_or_imm |
e07e6e58 | 7246 | |
c19d1205 | 7247 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
7248 | #define constraint(expr, err) \ |
7249 | do \ | |
c19d1205 | 7250 | { \ |
e07e6e58 NC |
7251 | if (expr) \ |
7252 | { \ | |
7253 | inst.error = err; \ | |
7254 | return; \ | |
7255 | } \ | |
c19d1205 | 7256 | } \ |
e07e6e58 | 7257 | while (0) |
c19d1205 | 7258 | |
fdfde340 JM |
7259 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
7260 | instructions are unpredictable if these registers are used. This | |
7261 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
7262 | #define reject_bad_reg(reg) \ | |
7263 | do \ | |
7264 | if (reg == REG_SP || reg == REG_PC) \ | |
7265 | { \ | |
7266 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
7267 | return; \ | |
7268 | } \ | |
7269 | while (0) | |
7270 | ||
94206790 MM |
7271 | /* If REG is R13 (the stack pointer), warn that its use is |
7272 | deprecated. */ | |
7273 | #define warn_deprecated_sp(reg) \ | |
7274 | do \ | |
7275 | if (warn_on_deprecated && reg == REG_SP) \ | |
5c3696f8 | 7276 | as_tsktsk (_("use of r13 is deprecated")); \ |
94206790 MM |
7277 | while (0) |
7278 | ||
c19d1205 ZW |
7279 | /* Functions for operand encoding. ARM, then Thumb. */ |
7280 | ||
d840c081 | 7281 | #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31)) |
c19d1205 | 7282 | |
9db2f6b4 RL |
7283 | /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding. |
7284 | ||
7285 | The only binary encoding difference is the Coprocessor number. Coprocessor | |
7286 | 9 is used for half-precision calculations or conversions. The format of the | |
7287 | instruction is the same as the equivalent Coprocessor 10 instuction that | |
7288 | exists for Single-Precision operation. */ | |
7289 | ||
7290 | static void | |
7291 | do_scalar_fp16_v82_encode (void) | |
7292 | { | |
7293 | if (inst.cond != COND_ALWAYS) | |
7294 | as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional," | |
7295 | " the behaviour is UNPREDICTABLE")); | |
7296 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
7297 | _(BAD_FP16)); | |
7298 | ||
7299 | inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900; | |
7300 | mark_feature_used (&arm_ext_fp16); | |
7301 | } | |
7302 | ||
c19d1205 ZW |
7303 | /* If VAL can be encoded in the immediate field of an ARM instruction, |
7304 | return the encoded form. Otherwise, return FAIL. */ | |
7305 | ||
7306 | static unsigned int | |
7307 | encode_arm_immediate (unsigned int val) | |
09d92015 | 7308 | { |
c19d1205 ZW |
7309 | unsigned int a, i; |
7310 | ||
4f1d6205 L |
7311 | if (val <= 0xff) |
7312 | return val; | |
7313 | ||
7314 | for (i = 2; i < 32; i += 2) | |
c19d1205 ZW |
7315 | if ((a = rotate_left (val, i)) <= 0xff) |
7316 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
7317 | ||
7318 | return FAIL; | |
09d92015 MM |
7319 | } |
7320 | ||
c19d1205 ZW |
7321 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
7322 | return the encoded form. Otherwise, return FAIL. */ | |
7323 | static unsigned int | |
7324 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 7325 | { |
c19d1205 | 7326 | unsigned int a, i; |
09d92015 | 7327 | |
9c3c69f2 | 7328 | if (val <= 0xff) |
c19d1205 | 7329 | return val; |
a737bd4d | 7330 | |
9c3c69f2 | 7331 | for (i = 1; i <= 24; i++) |
09d92015 | 7332 | { |
9c3c69f2 PB |
7333 | a = val >> i; |
7334 | if ((val & ~(0xff << i)) == 0) | |
7335 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 7336 | } |
a737bd4d | 7337 | |
c19d1205 ZW |
7338 | a = val & 0xff; |
7339 | if (val == ((a << 16) | a)) | |
7340 | return 0x100 | a; | |
7341 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
7342 | return 0x300 | a; | |
09d92015 | 7343 | |
c19d1205 ZW |
7344 | a = val & 0xff00; |
7345 | if (val == ((a << 16) | a)) | |
7346 | return 0x200 | (a >> 8); | |
a737bd4d | 7347 | |
c19d1205 | 7348 | return FAIL; |
09d92015 | 7349 | } |
5287ad62 | 7350 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
7351 | |
7352 | static void | |
5287ad62 JB |
7353 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
7354 | { | |
7355 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
7356 | && reg > 15) | |
7357 | { | |
b1cc4aeb | 7358 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
477330fc RM |
7359 | { |
7360 | if (thumb_mode) | |
7361 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
7362 | fpu_vfp_ext_d32); | |
7363 | else | |
7364 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
7365 | fpu_vfp_ext_d32); | |
7366 | } | |
5287ad62 | 7367 | else |
477330fc RM |
7368 | { |
7369 | first_error (_("D register out of range for selected VFP version")); | |
7370 | return; | |
7371 | } | |
5287ad62 JB |
7372 | } |
7373 | ||
c19d1205 | 7374 | switch (pos) |
09d92015 | 7375 | { |
c19d1205 ZW |
7376 | case VFP_REG_Sd: |
7377 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
7378 | break; | |
7379 | ||
7380 | case VFP_REG_Sn: | |
7381 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
7382 | break; | |
7383 | ||
7384 | case VFP_REG_Sm: | |
7385 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
7386 | break; | |
7387 | ||
5287ad62 JB |
7388 | case VFP_REG_Dd: |
7389 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
7390 | break; | |
5f4273c7 | 7391 | |
5287ad62 JB |
7392 | case VFP_REG_Dn: |
7393 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
7394 | break; | |
5f4273c7 | 7395 | |
5287ad62 JB |
7396 | case VFP_REG_Dm: |
7397 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
7398 | break; | |
7399 | ||
c19d1205 ZW |
7400 | default: |
7401 | abort (); | |
09d92015 | 7402 | } |
09d92015 MM |
7403 | } |
7404 | ||
c19d1205 | 7405 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 7406 | if any, is handled by md_apply_fix. */ |
09d92015 | 7407 | static void |
c19d1205 | 7408 | encode_arm_shift (int i) |
09d92015 | 7409 | { |
c19d1205 ZW |
7410 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
7411 | inst.instruction |= SHIFT_ROR << 5; | |
7412 | else | |
09d92015 | 7413 | { |
c19d1205 ZW |
7414 | inst.instruction |= inst.operands[i].shift_kind << 5; |
7415 | if (inst.operands[i].immisreg) | |
7416 | { | |
7417 | inst.instruction |= SHIFT_BY_REG; | |
7418 | inst.instruction |= inst.operands[i].imm << 8; | |
7419 | } | |
7420 | else | |
7421 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 7422 | } |
c19d1205 | 7423 | } |
09d92015 | 7424 | |
c19d1205 ZW |
7425 | static void |
7426 | encode_arm_shifter_operand (int i) | |
7427 | { | |
7428 | if (inst.operands[i].isreg) | |
09d92015 | 7429 | { |
c19d1205 ZW |
7430 | inst.instruction |= inst.operands[i].reg; |
7431 | encode_arm_shift (i); | |
09d92015 | 7432 | } |
c19d1205 | 7433 | else |
a415b1cd JB |
7434 | { |
7435 | inst.instruction |= INST_IMMEDIATE; | |
7436 | if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE) | |
7437 | inst.instruction |= inst.operands[i].imm; | |
7438 | } | |
09d92015 MM |
7439 | } |
7440 | ||
c19d1205 | 7441 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 7442 | static void |
c19d1205 | 7443 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 7444 | { |
2b2f5df9 NC |
7445 | /* PR 14260: |
7446 | Generate an error if the operand is not a register. */ | |
7447 | constraint (!inst.operands[i].isreg, | |
7448 | _("Instruction does not support =N addresses")); | |
7449 | ||
c19d1205 | 7450 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 7451 | |
c19d1205 | 7452 | if (inst.operands[i].preind) |
09d92015 | 7453 | { |
c19d1205 ZW |
7454 | if (is_t) |
7455 | { | |
7456 | inst.error = _("instruction does not accept preindexed addressing"); | |
7457 | return; | |
7458 | } | |
7459 | inst.instruction |= PRE_INDEX; | |
7460 | if (inst.operands[i].writeback) | |
7461 | inst.instruction |= WRITE_BACK; | |
09d92015 | 7462 | |
c19d1205 ZW |
7463 | } |
7464 | else if (inst.operands[i].postind) | |
7465 | { | |
9c2799c2 | 7466 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
7467 | if (is_t) |
7468 | inst.instruction |= WRITE_BACK; | |
7469 | } | |
7470 | else /* unindexed - only for coprocessor */ | |
09d92015 | 7471 | { |
c19d1205 | 7472 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
7473 | return; |
7474 | } | |
7475 | ||
c19d1205 ZW |
7476 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
7477 | && (((inst.instruction & 0x000f0000) >> 16) | |
7478 | == ((inst.instruction & 0x0000f000) >> 12))) | |
7479 | as_warn ((inst.instruction & LOAD_BIT) | |
7480 | ? _("destination register same as write-back base") | |
7481 | : _("source register same as write-back base")); | |
09d92015 MM |
7482 | } |
7483 | ||
c19d1205 ZW |
7484 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7485 | ARM-format mode 2 load or store instruction. If is_t is true, | |
7486 | reject forms that cannot be used with a T instruction (i.e. not | |
7487 | post-indexed). */ | |
a737bd4d | 7488 | static void |
c19d1205 | 7489 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 7490 | { |
5be8be5d DG |
7491 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
7492 | ||
c19d1205 | 7493 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7494 | |
c19d1205 | 7495 | if (inst.operands[i].immisreg) |
09d92015 | 7496 | { |
5be8be5d DG |
7497 | constraint ((inst.operands[i].imm == REG_PC |
7498 | || (is_pc && inst.operands[i].writeback)), | |
7499 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
7500 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
7501 | inst.instruction |= inst.operands[i].imm; | |
7502 | if (!inst.operands[i].negative) | |
7503 | inst.instruction |= INDEX_UP; | |
7504 | if (inst.operands[i].shifted) | |
7505 | { | |
7506 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
7507 | inst.instruction |= SHIFT_ROR << 5; | |
7508 | else | |
7509 | { | |
7510 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
7511 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
7512 | } | |
7513 | } | |
09d92015 | 7514 | } |
c19d1205 | 7515 | else /* immediate offset in inst.reloc */ |
09d92015 | 7516 | { |
5be8be5d DG |
7517 | if (is_pc && !inst.reloc.pc_rel) |
7518 | { | |
7519 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
7520 | |
7521 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
7522 | cannot use PC in addressing. | |
7523 | PC cannot be used in writeback addressing, either. */ | |
7524 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 7525 | BAD_PC_ADDRESSING); |
23a10334 | 7526 | |
dc5ec521 | 7527 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
7528 | if (warn_on_deprecated |
7529 | && !is_load | |
7530 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
5c3696f8 | 7531 | as_tsktsk (_("use of PC in this instruction is deprecated")); |
5be8be5d DG |
7532 | } |
7533 | ||
c19d1205 | 7534 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
26d97720 NS |
7535 | { |
7536 | /* Prefer + for zero encoded value. */ | |
7537 | if (!inst.operands[i].negative) | |
7538 | inst.instruction |= INDEX_UP; | |
7539 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
7540 | } | |
09d92015 | 7541 | } |
09d92015 MM |
7542 | } |
7543 | ||
c19d1205 ZW |
7544 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7545 | ARM-format mode 3 load or store instruction. Reject forms that | |
7546 | cannot be used with such instructions. If is_t is true, reject | |
7547 | forms that cannot be used with a T instruction (i.e. not | |
7548 | post-indexed). */ | |
7549 | static void | |
7550 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 7551 | { |
c19d1205 | 7552 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 7553 | { |
c19d1205 ZW |
7554 | inst.error = _("instruction does not accept scaled register index"); |
7555 | return; | |
09d92015 | 7556 | } |
a737bd4d | 7557 | |
c19d1205 | 7558 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7559 | |
c19d1205 ZW |
7560 | if (inst.operands[i].immisreg) |
7561 | { | |
5be8be5d | 7562 | constraint ((inst.operands[i].imm == REG_PC |
eb9f3f00 | 7563 | || (is_t && inst.operands[i].reg == REG_PC)), |
5be8be5d | 7564 | BAD_PC_ADDRESSING); |
eb9f3f00 JB |
7565 | constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback, |
7566 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7567 | inst.instruction |= inst.operands[i].imm; |
7568 | if (!inst.operands[i].negative) | |
7569 | inst.instruction |= INDEX_UP; | |
7570 | } | |
7571 | else /* immediate offset in inst.reloc */ | |
7572 | { | |
5be8be5d DG |
7573 | constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel |
7574 | && inst.operands[i].writeback), | |
7575 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7576 | inst.instruction |= HWOFFSET_IMM; |
7577 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
26d97720 NS |
7578 | { |
7579 | /* Prefer + for zero encoded value. */ | |
7580 | if (!inst.operands[i].negative) | |
7581 | inst.instruction |= INDEX_UP; | |
7582 | ||
7583 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
7584 | } | |
c19d1205 | 7585 | } |
a737bd4d NC |
7586 | } |
7587 | ||
8335d6aa JW |
7588 | /* Write immediate bits [7:0] to the following locations: |
7589 | ||
7590 | |28/24|23 19|18 16|15 4|3 0| | |
7591 | | 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| | |
7592 | ||
7593 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
7594 | ||
7595 | static void | |
7596 | neon_write_immbits (unsigned immbits) | |
7597 | { | |
7598 | inst.instruction |= immbits & 0xf; | |
7599 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
7600 | inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24); | |
7601 | } | |
7602 | ||
7603 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
7604 | ||
7605 | static void | |
7606 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
7607 | { | |
7608 | unsigned immlo = xlo ? *xlo : 0; | |
7609 | unsigned immhi = xhi ? *xhi : 0; | |
7610 | ||
7611 | switch (size) | |
7612 | { | |
7613 | case 8: | |
7614 | immlo = (~immlo) & 0xff; | |
7615 | break; | |
7616 | ||
7617 | case 16: | |
7618 | immlo = (~immlo) & 0xffff; | |
7619 | break; | |
7620 | ||
7621 | case 64: | |
7622 | immhi = (~immhi) & 0xffffffff; | |
7623 | /* fall through. */ | |
7624 | ||
7625 | case 32: | |
7626 | immlo = (~immlo) & 0xffffffff; | |
7627 | break; | |
7628 | ||
7629 | default: | |
7630 | abort (); | |
7631 | } | |
7632 | ||
7633 | if (xlo) | |
7634 | *xlo = immlo; | |
7635 | ||
7636 | if (xhi) | |
7637 | *xhi = immhi; | |
7638 | } | |
7639 | ||
7640 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
7641 | A, B, C, D. */ | |
09d92015 | 7642 | |
c19d1205 | 7643 | static int |
8335d6aa | 7644 | neon_bits_same_in_bytes (unsigned imm) |
09d92015 | 7645 | { |
8335d6aa JW |
7646 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) |
7647 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
7648 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
7649 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
7650 | } | |
a737bd4d | 7651 | |
8335d6aa | 7652 | /* For immediate of above form, return 0bABCD. */ |
09d92015 | 7653 | |
8335d6aa JW |
7654 | static unsigned |
7655 | neon_squash_bits (unsigned imm) | |
7656 | { | |
7657 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
7658 | | ((imm & 0x01000000) >> 21); | |
7659 | } | |
7660 | ||
7661 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ | |
7662 | ||
7663 | static unsigned | |
7664 | neon_qfloat_bits (unsigned imm) | |
7665 | { | |
7666 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); | |
7667 | } | |
7668 | ||
7669 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
7670 | the instruction. *OP is passed as the initial value of the op field, and | |
7671 | may be set to a different value depending on the constant (i.e. | |
7672 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
7673 | MVN). If the immediate looks like a repeated pattern then also | |
7674 | try smaller element sizes. */ | |
7675 | ||
7676 | static int | |
7677 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, | |
7678 | unsigned *immbits, int *op, int size, | |
7679 | enum neon_el_type type) | |
7680 | { | |
7681 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is | |
7682 | float. */ | |
7683 | if (type == NT_float && !float_p) | |
7684 | return FAIL; | |
7685 | ||
7686 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) | |
09d92015 | 7687 | { |
8335d6aa JW |
7688 | if (size != 32 || *op == 1) |
7689 | return FAIL; | |
7690 | *immbits = neon_qfloat_bits (immlo); | |
7691 | return 0xf; | |
7692 | } | |
7693 | ||
7694 | if (size == 64) | |
7695 | { | |
7696 | if (neon_bits_same_in_bytes (immhi) | |
7697 | && neon_bits_same_in_bytes (immlo)) | |
c19d1205 | 7698 | { |
8335d6aa JW |
7699 | if (*op == 1) |
7700 | return FAIL; | |
7701 | *immbits = (neon_squash_bits (immhi) << 4) | |
7702 | | neon_squash_bits (immlo); | |
7703 | *op = 1; | |
7704 | return 0xe; | |
c19d1205 | 7705 | } |
a737bd4d | 7706 | |
8335d6aa JW |
7707 | if (immhi != immlo) |
7708 | return FAIL; | |
7709 | } | |
a737bd4d | 7710 | |
8335d6aa | 7711 | if (size >= 32) |
09d92015 | 7712 | { |
8335d6aa | 7713 | if (immlo == (immlo & 0x000000ff)) |
c19d1205 | 7714 | { |
8335d6aa JW |
7715 | *immbits = immlo; |
7716 | return 0x0; | |
c19d1205 | 7717 | } |
8335d6aa | 7718 | else if (immlo == (immlo & 0x0000ff00)) |
c19d1205 | 7719 | { |
8335d6aa JW |
7720 | *immbits = immlo >> 8; |
7721 | return 0x2; | |
c19d1205 | 7722 | } |
8335d6aa JW |
7723 | else if (immlo == (immlo & 0x00ff0000)) |
7724 | { | |
7725 | *immbits = immlo >> 16; | |
7726 | return 0x4; | |
7727 | } | |
7728 | else if (immlo == (immlo & 0xff000000)) | |
7729 | { | |
7730 | *immbits = immlo >> 24; | |
7731 | return 0x6; | |
7732 | } | |
7733 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
7734 | { | |
7735 | *immbits = (immlo >> 8) & 0xff; | |
7736 | return 0xc; | |
7737 | } | |
7738 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
7739 | { | |
7740 | *immbits = (immlo >> 16) & 0xff; | |
7741 | return 0xd; | |
7742 | } | |
7743 | ||
7744 | if ((immlo & 0xffff) != (immlo >> 16)) | |
7745 | return FAIL; | |
7746 | immlo &= 0xffff; | |
09d92015 | 7747 | } |
a737bd4d | 7748 | |
8335d6aa | 7749 | if (size >= 16) |
4962c51a | 7750 | { |
8335d6aa JW |
7751 | if (immlo == (immlo & 0x000000ff)) |
7752 | { | |
7753 | *immbits = immlo; | |
7754 | return 0x8; | |
7755 | } | |
7756 | else if (immlo == (immlo & 0x0000ff00)) | |
7757 | { | |
7758 | *immbits = immlo >> 8; | |
7759 | return 0xa; | |
7760 | } | |
7761 | ||
7762 | if ((immlo & 0xff) != (immlo >> 8)) | |
7763 | return FAIL; | |
7764 | immlo &= 0xff; | |
4962c51a MS |
7765 | } |
7766 | ||
8335d6aa JW |
7767 | if (immlo == (immlo & 0x000000ff)) |
7768 | { | |
7769 | /* Don't allow MVN with 8-bit immediate. */ | |
7770 | if (*op == 1) | |
7771 | return FAIL; | |
7772 | *immbits = immlo; | |
7773 | return 0xe; | |
7774 | } | |
26d97720 | 7775 | |
8335d6aa | 7776 | return FAIL; |
c19d1205 | 7777 | } |
a737bd4d | 7778 | |
5fc177c8 | 7779 | #if defined BFD_HOST_64_BIT |
ba592044 AM |
7780 | /* Returns TRUE if double precision value V may be cast |
7781 | to single precision without loss of accuracy. */ | |
7782 | ||
7783 | static bfd_boolean | |
5fc177c8 | 7784 | is_double_a_single (bfd_int64_t v) |
ba592044 | 7785 | { |
5fc177c8 | 7786 | int exp = (int)((v >> 52) & 0x7FF); |
8fe3f3d6 | 7787 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
7788 | |
7789 | return (exp == 0 || exp == 0x7FF | |
7790 | || (exp >= 1023 - 126 && exp <= 1023 + 127)) | |
7791 | && (mantissa & 0x1FFFFFFFl) == 0; | |
7792 | } | |
7793 | ||
3739860c | 7794 | /* Returns a double precision value casted to single precision |
ba592044 AM |
7795 | (ignoring the least significant bits in exponent and mantissa). */ |
7796 | ||
7797 | static int | |
5fc177c8 | 7798 | double_to_single (bfd_int64_t v) |
ba592044 AM |
7799 | { |
7800 | int sign = (int) ((v >> 63) & 1l); | |
5fc177c8 | 7801 | int exp = (int) ((v >> 52) & 0x7FF); |
8fe3f3d6 | 7802 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
7803 | |
7804 | if (exp == 0x7FF) | |
7805 | exp = 0xFF; | |
7806 | else | |
7807 | { | |
7808 | exp = exp - 1023 + 127; | |
7809 | if (exp >= 0xFF) | |
7810 | { | |
7811 | /* Infinity. */ | |
7812 | exp = 0x7F; | |
7813 | mantissa = 0; | |
7814 | } | |
7815 | else if (exp < 0) | |
7816 | { | |
7817 | /* No denormalized numbers. */ | |
7818 | exp = 0; | |
7819 | mantissa = 0; | |
7820 | } | |
7821 | } | |
7822 | mantissa >>= 29; | |
7823 | return (sign << 31) | (exp << 23) | mantissa; | |
7824 | } | |
5fc177c8 | 7825 | #endif /* BFD_HOST_64_BIT */ |
ba592044 | 7826 | |
8335d6aa JW |
7827 | enum lit_type |
7828 | { | |
7829 | CONST_THUMB, | |
7830 | CONST_ARM, | |
7831 | CONST_VEC | |
7832 | }; | |
7833 | ||
ba592044 AM |
7834 | static void do_vfp_nsyn_opcode (const char *); |
7835 | ||
c19d1205 ZW |
7836 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
7837 | Determine whether it can be performed with a move instruction; if | |
7838 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
7839 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
7840 | load and return FALSE. If this is not a valid thing to do in the | |
7841 | current context, set inst.error and return TRUE. | |
a737bd4d | 7842 | |
c19d1205 ZW |
7843 | inst.operands[i] describes the destination register. */ |
7844 | ||
c921be7d | 7845 | static bfd_boolean |
8335d6aa | 7846 | move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3) |
c19d1205 | 7847 | { |
53365c0d | 7848 | unsigned long tbit; |
8335d6aa JW |
7849 | bfd_boolean thumb_p = (t == CONST_THUMB); |
7850 | bfd_boolean arm_p = (t == CONST_ARM); | |
53365c0d PB |
7851 | |
7852 | if (thumb_p) | |
7853 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
7854 | else | |
7855 | tbit = LOAD_BIT; | |
7856 | ||
7857 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 7858 | { |
c19d1205 | 7859 | inst.error = _("invalid pseudo operation"); |
c921be7d | 7860 | return TRUE; |
09d92015 | 7861 | } |
ba592044 | 7862 | |
8335d6aa JW |
7863 | if (inst.reloc.exp.X_op != O_constant |
7864 | && inst.reloc.exp.X_op != O_symbol | |
7865 | && inst.reloc.exp.X_op != O_big) | |
09d92015 MM |
7866 | { |
7867 | inst.error = _("constant expression expected"); | |
c921be7d | 7868 | return TRUE; |
09d92015 | 7869 | } |
ba592044 AM |
7870 | |
7871 | if (inst.reloc.exp.X_op == O_constant | |
7872 | || inst.reloc.exp.X_op == O_big) | |
8335d6aa | 7873 | { |
5fc177c8 NC |
7874 | #if defined BFD_HOST_64_BIT |
7875 | bfd_int64_t v; | |
7876 | #else | |
ba592044 | 7877 | offsetT v; |
5fc177c8 | 7878 | #endif |
ba592044 | 7879 | if (inst.reloc.exp.X_op == O_big) |
8335d6aa | 7880 | { |
ba592044 AM |
7881 | LITTLENUM_TYPE w[X_PRECISION]; |
7882 | LITTLENUM_TYPE * l; | |
7883 | ||
7884 | if (inst.reloc.exp.X_add_number == -1) | |
8335d6aa | 7885 | { |
ba592044 AM |
7886 | gen_to_words (w, X_PRECISION, E_PRECISION); |
7887 | l = w; | |
7888 | /* FIXME: Should we check words w[2..5] ? */ | |
8335d6aa | 7889 | } |
ba592044 AM |
7890 | else |
7891 | l = generic_bignum; | |
3739860c | 7892 | |
5fc177c8 NC |
7893 | #if defined BFD_HOST_64_BIT |
7894 | v = | |
7895 | ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK) | |
7896 | << LITTLENUM_NUMBER_OF_BITS) | |
7897 | | ((bfd_int64_t) l[2] & LITTLENUM_MASK)) | |
7898 | << LITTLENUM_NUMBER_OF_BITS) | |
7899 | | ((bfd_int64_t) l[1] & LITTLENUM_MASK)) | |
7900 | << LITTLENUM_NUMBER_OF_BITS) | |
7901 | | ((bfd_int64_t) l[0] & LITTLENUM_MASK)); | |
7902 | #else | |
ba592044 AM |
7903 | v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) |
7904 | | (l[0] & LITTLENUM_MASK); | |
5fc177c8 | 7905 | #endif |
8335d6aa | 7906 | } |
ba592044 AM |
7907 | else |
7908 | v = inst.reloc.exp.X_add_number; | |
7909 | ||
7910 | if (!inst.operands[i].issingle) | |
8335d6aa | 7911 | { |
12569877 | 7912 | if (thumb_p) |
8335d6aa | 7913 | { |
2c32be70 CM |
7914 | /* This can be encoded only for a low register. */ |
7915 | if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8)) | |
ba592044 AM |
7916 | { |
7917 | /* This can be done with a mov(1) instruction. */ | |
7918 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
7919 | inst.instruction |= v; | |
7920 | return TRUE; | |
7921 | } | |
12569877 | 7922 | |
ff8646ee TP |
7923 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) |
7924 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
12569877 | 7925 | { |
fc289b0a TP |
7926 | /* Check if on thumb2 it can be done with a mov.w, mvn or |
7927 | movw instruction. */ | |
12569877 AM |
7928 | unsigned int newimm; |
7929 | bfd_boolean isNegated; | |
7930 | ||
7931 | newimm = encode_thumb32_immediate (v); | |
7932 | if (newimm != (unsigned int) FAIL) | |
7933 | isNegated = FALSE; | |
7934 | else | |
7935 | { | |
582cfe03 | 7936 | newimm = encode_thumb32_immediate (~v); |
12569877 AM |
7937 | if (newimm != (unsigned int) FAIL) |
7938 | isNegated = TRUE; | |
7939 | } | |
7940 | ||
fc289b0a TP |
7941 | /* The number can be loaded with a mov.w or mvn |
7942 | instruction. */ | |
ff8646ee TP |
7943 | if (newimm != (unsigned int) FAIL |
7944 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
12569877 | 7945 | { |
fc289b0a | 7946 | inst.instruction = (0xf04f0000 /* MOV.W. */ |
582cfe03 | 7947 | | (inst.operands[i].reg << 8)); |
fc289b0a | 7948 | /* Change to MOVN. */ |
582cfe03 | 7949 | inst.instruction |= (isNegated ? 0x200000 : 0); |
12569877 AM |
7950 | inst.instruction |= (newimm & 0x800) << 15; |
7951 | inst.instruction |= (newimm & 0x700) << 4; | |
7952 | inst.instruction |= (newimm & 0x0ff); | |
7953 | return TRUE; | |
7954 | } | |
fc289b0a | 7955 | /* The number can be loaded with a movw instruction. */ |
ff8646ee TP |
7956 | else if ((v & ~0xFFFF) == 0 |
7957 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
3739860c | 7958 | { |
582cfe03 | 7959 | int imm = v & 0xFFFF; |
12569877 | 7960 | |
582cfe03 | 7961 | inst.instruction = 0xf2400000; /* MOVW. */ |
12569877 AM |
7962 | inst.instruction |= (inst.operands[i].reg << 8); |
7963 | inst.instruction |= (imm & 0xf000) << 4; | |
7964 | inst.instruction |= (imm & 0x0800) << 15; | |
7965 | inst.instruction |= (imm & 0x0700) << 4; | |
7966 | inst.instruction |= (imm & 0x00ff); | |
7967 | return TRUE; | |
7968 | } | |
7969 | } | |
8335d6aa | 7970 | } |
12569877 | 7971 | else if (arm_p) |
ba592044 AM |
7972 | { |
7973 | int value = encode_arm_immediate (v); | |
12569877 | 7974 | |
ba592044 AM |
7975 | if (value != FAIL) |
7976 | { | |
7977 | /* This can be done with a mov instruction. */ | |
7978 | inst.instruction &= LITERAL_MASK; | |
7979 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
7980 | inst.instruction |= value & 0xfff; | |
7981 | return TRUE; | |
7982 | } | |
8335d6aa | 7983 | |
ba592044 AM |
7984 | value = encode_arm_immediate (~ v); |
7985 | if (value != FAIL) | |
7986 | { | |
7987 | /* This can be done with a mvn instruction. */ | |
7988 | inst.instruction &= LITERAL_MASK; | |
7989 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
7990 | inst.instruction |= value & 0xfff; | |
7991 | return TRUE; | |
7992 | } | |
7993 | } | |
7994 | else if (t == CONST_VEC) | |
8335d6aa | 7995 | { |
ba592044 AM |
7996 | int op = 0; |
7997 | unsigned immbits = 0; | |
7998 | unsigned immlo = inst.operands[1].imm; | |
7999 | unsigned immhi = inst.operands[1].regisimm | |
8000 | ? inst.operands[1].reg | |
8001 | : inst.reloc.exp.X_unsigned | |
8002 | ? 0 | |
8003 | : ((bfd_int64_t)((int) immlo)) >> 32; | |
8004 | int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8005 | &op, 64, NT_invtype); | |
8006 | ||
8007 | if (cmode == FAIL) | |
8008 | { | |
8009 | neon_invert_size (&immlo, &immhi, 64); | |
8010 | op = !op; | |
8011 | cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
8012 | &op, 64, NT_invtype); | |
8013 | } | |
8014 | ||
8015 | if (cmode != FAIL) | |
8016 | { | |
8017 | inst.instruction = (inst.instruction & VLDR_VMOV_SAME) | |
8018 | | (1 << 23) | |
8019 | | (cmode << 8) | |
8020 | | (op << 5) | |
8021 | | (1 << 4); | |
8022 | ||
8023 | /* Fill other bits in vmov encoding for both thumb and arm. */ | |
8024 | if (thumb_mode) | |
eff0bc54 | 8025 | inst.instruction |= (0x7U << 29) | (0xF << 24); |
ba592044 | 8026 | else |
eff0bc54 | 8027 | inst.instruction |= (0xFU << 28) | (0x1 << 25); |
ba592044 AM |
8028 | neon_write_immbits (immbits); |
8029 | return TRUE; | |
8030 | } | |
8335d6aa JW |
8031 | } |
8032 | } | |
8335d6aa | 8033 | |
ba592044 AM |
8034 | if (t == CONST_VEC) |
8035 | { | |
8036 | /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */ | |
8037 | if (inst.operands[i].issingle | |
8038 | && is_quarter_float (inst.operands[1].imm) | |
8039 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd)) | |
8335d6aa | 8040 | { |
ba592044 AM |
8041 | inst.operands[1].imm = |
8042 | neon_qfloat_bits (v); | |
8043 | do_vfp_nsyn_opcode ("fconsts"); | |
8044 | return TRUE; | |
8335d6aa | 8045 | } |
5fc177c8 NC |
8046 | |
8047 | /* If our host does not support a 64-bit type then we cannot perform | |
8048 | the following optimization. This mean that there will be a | |
8049 | discrepancy between the output produced by an assembler built for | |
8050 | a 32-bit-only host and the output produced from a 64-bit host, but | |
8051 | this cannot be helped. */ | |
8052 | #if defined BFD_HOST_64_BIT | |
ba592044 AM |
8053 | else if (!inst.operands[1].issingle |
8054 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
8335d6aa | 8055 | { |
ba592044 AM |
8056 | if (is_double_a_single (v) |
8057 | && is_quarter_float (double_to_single (v))) | |
8058 | { | |
8059 | inst.operands[1].imm = | |
8060 | neon_qfloat_bits (double_to_single (v)); | |
8061 | do_vfp_nsyn_opcode ("fconstd"); | |
8062 | return TRUE; | |
8063 | } | |
8335d6aa | 8064 | } |
5fc177c8 | 8065 | #endif |
8335d6aa JW |
8066 | } |
8067 | } | |
8068 | ||
8069 | if (add_to_lit_pool ((!inst.operands[i].isvec | |
8070 | || inst.operands[i].issingle) ? 4 : 8) == FAIL) | |
8071 | return TRUE; | |
8072 | ||
8073 | inst.operands[1].reg = REG_PC; | |
8074 | inst.operands[1].isreg = 1; | |
8075 | inst.operands[1].preind = 1; | |
8076 | inst.reloc.pc_rel = 1; | |
8077 | inst.reloc.type = (thumb_p | |
8078 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
8079 | : (mode_3 | |
8080 | ? BFD_RELOC_ARM_HWLITERAL | |
8081 | : BFD_RELOC_ARM_LITERAL)); | |
8082 | return FALSE; | |
8083 | } | |
8084 | ||
8085 | /* inst.operands[i] was set up by parse_address. Encode it into an | |
8086 | ARM-format instruction. Reject all forms which cannot be encoded | |
8087 | into a coprocessor load/store instruction. If wb_ok is false, | |
8088 | reject use of writeback; if unind_ok is false, reject use of | |
8089 | unindexed addressing. If reloc_override is not 0, use it instead | |
8090 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one | |
8091 | (in which case it is preserved). */ | |
8092 | ||
8093 | static int | |
8094 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
8095 | { | |
8096 | if (!inst.operands[i].isreg) | |
8097 | { | |
99b2a2dd NC |
8098 | /* PR 18256 */ |
8099 | if (! inst.operands[0].isvec) | |
8100 | { | |
8101 | inst.error = _("invalid co-processor operand"); | |
8102 | return FAIL; | |
8103 | } | |
8335d6aa JW |
8104 | if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE)) |
8105 | return SUCCESS; | |
8106 | } | |
8107 | ||
8108 | inst.instruction |= inst.operands[i].reg << 16; | |
8109 | ||
8110 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); | |
8111 | ||
8112 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ | |
8113 | { | |
8114 | gas_assert (!inst.operands[i].writeback); | |
8115 | if (!unind_ok) | |
8116 | { | |
8117 | inst.error = _("instruction does not support unindexed addressing"); | |
8118 | return FAIL; | |
8119 | } | |
8120 | inst.instruction |= inst.operands[i].imm; | |
8121 | inst.instruction |= INDEX_UP; | |
8122 | return SUCCESS; | |
8123 | } | |
8124 | ||
8125 | if (inst.operands[i].preind) | |
8126 | inst.instruction |= PRE_INDEX; | |
8127 | ||
8128 | if (inst.operands[i].writeback) | |
09d92015 | 8129 | { |
8335d6aa | 8130 | if (inst.operands[i].reg == REG_PC) |
c19d1205 | 8131 | { |
8335d6aa JW |
8132 | inst.error = _("pc may not be used with write-back"); |
8133 | return FAIL; | |
c19d1205 | 8134 | } |
8335d6aa | 8135 | if (!wb_ok) |
c19d1205 | 8136 | { |
8335d6aa JW |
8137 | inst.error = _("instruction does not support writeback"); |
8138 | return FAIL; | |
c19d1205 | 8139 | } |
8335d6aa | 8140 | inst.instruction |= WRITE_BACK; |
09d92015 MM |
8141 | } |
8142 | ||
8335d6aa JW |
8143 | if (reloc_override) |
8144 | inst.reloc.type = (bfd_reloc_code_real_type) reloc_override; | |
8145 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC | |
8146 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
8147 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
c19d1205 | 8148 | { |
8335d6aa JW |
8149 | if (thumb_mode) |
8150 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
8151 | else | |
8152 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
c19d1205 | 8153 | } |
8335d6aa JW |
8154 | |
8155 | /* Prefer + for zero encoded value. */ | |
8156 | if (!inst.operands[i].negative) | |
8157 | inst.instruction |= INDEX_UP; | |
8158 | ||
8159 | return SUCCESS; | |
09d92015 MM |
8160 | } |
8161 | ||
5f4273c7 | 8162 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
8163 | First some generics; their names are taken from the conventional |
8164 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 8165 | |
a737bd4d | 8166 | static void |
c19d1205 | 8167 | do_noargs (void) |
09d92015 | 8168 | { |
c19d1205 | 8169 | } |
a737bd4d | 8170 | |
c19d1205 ZW |
8171 | static void |
8172 | do_rd (void) | |
8173 | { | |
8174 | inst.instruction |= inst.operands[0].reg << 12; | |
8175 | } | |
a737bd4d | 8176 | |
c19d1205 ZW |
8177 | static void |
8178 | do_rd_rm (void) | |
8179 | { | |
8180 | inst.instruction |= inst.operands[0].reg << 12; | |
8181 | inst.instruction |= inst.operands[1].reg; | |
8182 | } | |
09d92015 | 8183 | |
9eb6c0f1 MGD |
8184 | static void |
8185 | do_rm_rn (void) | |
8186 | { | |
8187 | inst.instruction |= inst.operands[0].reg; | |
8188 | inst.instruction |= inst.operands[1].reg << 16; | |
8189 | } | |
8190 | ||
c19d1205 ZW |
8191 | static void |
8192 | do_rd_rn (void) | |
8193 | { | |
8194 | inst.instruction |= inst.operands[0].reg << 12; | |
8195 | inst.instruction |= inst.operands[1].reg << 16; | |
8196 | } | |
a737bd4d | 8197 | |
c19d1205 ZW |
8198 | static void |
8199 | do_rn_rd (void) | |
8200 | { | |
8201 | inst.instruction |= inst.operands[0].reg << 16; | |
8202 | inst.instruction |= inst.operands[1].reg << 12; | |
8203 | } | |
09d92015 | 8204 | |
4ed7ed8d TP |
8205 | static void |
8206 | do_tt (void) | |
8207 | { | |
8208 | inst.instruction |= inst.operands[0].reg << 8; | |
8209 | inst.instruction |= inst.operands[1].reg << 16; | |
8210 | } | |
8211 | ||
59d09be6 MGD |
8212 | static bfd_boolean |
8213 | check_obsolete (const arm_feature_set *feature, const char *msg) | |
8214 | { | |
8215 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
8216 | { | |
5c3696f8 | 8217 | as_tsktsk ("%s", msg); |
59d09be6 MGD |
8218 | return TRUE; |
8219 | } | |
8220 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
8221 | { | |
8222 | as_bad ("%s", msg); | |
8223 | return TRUE; | |
8224 | } | |
8225 | ||
8226 | return FALSE; | |
8227 | } | |
8228 | ||
c19d1205 ZW |
8229 | static void |
8230 | do_rd_rm_rn (void) | |
8231 | { | |
9a64e435 | 8232 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 8233 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 8234 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
8235 | { |
8236 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
8237 | _("Rn must not overlap other operands")); | |
8238 | ||
59d09be6 MGD |
8239 | /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7. |
8240 | */ | |
8241 | if (!check_obsolete (&arm_ext_v8, | |
8242 | _("swp{b} use is obsoleted for ARMv8 and later")) | |
8243 | && warn_on_deprecated | |
8244 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6)) | |
5c3696f8 | 8245 | as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7")); |
56adecf4 | 8246 | } |
59d09be6 | 8247 | |
c19d1205 ZW |
8248 | inst.instruction |= inst.operands[0].reg << 12; |
8249 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 8250 | inst.instruction |= Rn << 16; |
c19d1205 | 8251 | } |
09d92015 | 8252 | |
c19d1205 ZW |
8253 | static void |
8254 | do_rd_rn_rm (void) | |
8255 | { | |
8256 | inst.instruction |= inst.operands[0].reg << 12; | |
8257 | inst.instruction |= inst.operands[1].reg << 16; | |
8258 | inst.instruction |= inst.operands[2].reg; | |
8259 | } | |
a737bd4d | 8260 | |
c19d1205 ZW |
8261 | static void |
8262 | do_rm_rd_rn (void) | |
8263 | { | |
5be8be5d DG |
8264 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
8265 | constraint (((inst.reloc.exp.X_op != O_constant | |
8266 | && inst.reloc.exp.X_op != O_illegal) | |
8267 | || inst.reloc.exp.X_add_number != 0), | |
8268 | BAD_ADDR_MODE); | |
c19d1205 ZW |
8269 | inst.instruction |= inst.operands[0].reg; |
8270 | inst.instruction |= inst.operands[1].reg << 12; | |
8271 | inst.instruction |= inst.operands[2].reg << 16; | |
8272 | } | |
09d92015 | 8273 | |
c19d1205 ZW |
8274 | static void |
8275 | do_imm0 (void) | |
8276 | { | |
8277 | inst.instruction |= inst.operands[0].imm; | |
8278 | } | |
09d92015 | 8279 | |
c19d1205 ZW |
8280 | static void |
8281 | do_rd_cpaddr (void) | |
8282 | { | |
8283 | inst.instruction |= inst.operands[0].reg << 12; | |
8284 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 8285 | } |
a737bd4d | 8286 | |
c19d1205 ZW |
8287 | /* ARM instructions, in alphabetical order by function name (except |
8288 | that wrapper functions appear immediately after the function they | |
8289 | wrap). */ | |
09d92015 | 8290 | |
c19d1205 ZW |
8291 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
8292 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
8293 | |
8294 | static void | |
c19d1205 | 8295 | do_adr (void) |
09d92015 | 8296 | { |
c19d1205 | 8297 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 8298 | |
c19d1205 ZW |
8299 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8300 | out to be negative. */ | |
8301 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 8302 | inst.reloc.pc_rel = 1; |
2fc8bdac | 8303 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 8304 | } |
b99bd4ef | 8305 | |
c19d1205 ZW |
8306 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
8307 | into a relative address of the form: | |
8308 | add rd, pc, #low(label-.-8)" | |
8309 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 8310 | |
c19d1205 ZW |
8311 | static void |
8312 | do_adrl (void) | |
8313 | { | |
8314 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 8315 | |
c19d1205 ZW |
8316 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8317 | out to be negative. */ | |
8318 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
8319 | inst.reloc.pc_rel = 1; |
8320 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 8321 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
8322 | } |
8323 | ||
b99bd4ef | 8324 | static void |
c19d1205 | 8325 | do_arit (void) |
b99bd4ef | 8326 | { |
a9f02af8 MG |
8327 | constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
8328 | && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
8329 | THUMB1_RELOC_ONLY); | |
c19d1205 ZW |
8330 | if (!inst.operands[1].present) |
8331 | inst.operands[1].reg = inst.operands[0].reg; | |
8332 | inst.instruction |= inst.operands[0].reg << 12; | |
8333 | inst.instruction |= inst.operands[1].reg << 16; | |
8334 | encode_arm_shifter_operand (2); | |
8335 | } | |
b99bd4ef | 8336 | |
62b3e311 PB |
8337 | static void |
8338 | do_barrier (void) | |
8339 | { | |
8340 | if (inst.operands[0].present) | |
ccb84d65 | 8341 | inst.instruction |= inst.operands[0].imm; |
62b3e311 PB |
8342 | else |
8343 | inst.instruction |= 0xf; | |
8344 | } | |
8345 | ||
c19d1205 ZW |
8346 | static void |
8347 | do_bfc (void) | |
8348 | { | |
8349 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
8350 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8351 | /* The instruction encoding stores the LSB and MSB, | |
8352 | not the LSB and width. */ | |
8353 | inst.instruction |= inst.operands[0].reg << 12; | |
8354 | inst.instruction |= inst.operands[1].imm << 7; | |
8355 | inst.instruction |= (msb - 1) << 16; | |
8356 | } | |
b99bd4ef | 8357 | |
c19d1205 ZW |
8358 | static void |
8359 | do_bfi (void) | |
8360 | { | |
8361 | unsigned int msb; | |
b99bd4ef | 8362 | |
c19d1205 ZW |
8363 | /* #0 in second position is alternative syntax for bfc, which is |
8364 | the same instruction but with REG_PC in the Rm field. */ | |
8365 | if (!inst.operands[1].isreg) | |
8366 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 8367 | |
c19d1205 ZW |
8368 | msb = inst.operands[2].imm + inst.operands[3].imm; |
8369 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8370 | /* The instruction encoding stores the LSB and MSB, | |
8371 | not the LSB and width. */ | |
8372 | inst.instruction |= inst.operands[0].reg << 12; | |
8373 | inst.instruction |= inst.operands[1].reg; | |
8374 | inst.instruction |= inst.operands[2].imm << 7; | |
8375 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
8376 | } |
8377 | ||
b99bd4ef | 8378 | static void |
c19d1205 | 8379 | do_bfx (void) |
b99bd4ef | 8380 | { |
c19d1205 ZW |
8381 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
8382 | _("bit-field extends past end of register")); | |
8383 | inst.instruction |= inst.operands[0].reg << 12; | |
8384 | inst.instruction |= inst.operands[1].reg; | |
8385 | inst.instruction |= inst.operands[2].imm << 7; | |
8386 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
8387 | } | |
09d92015 | 8388 | |
c19d1205 ZW |
8389 | /* ARM V5 breakpoint instruction (argument parse) |
8390 | BKPT <16 bit unsigned immediate> | |
8391 | Instruction is not conditional. | |
8392 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
8393 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 8394 | |
c19d1205 ZW |
8395 | static void |
8396 | do_bkpt (void) | |
8397 | { | |
8398 | /* Top 12 of 16 bits to bits 19:8. */ | |
8399 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 8400 | |
c19d1205 ZW |
8401 | /* Bottom 4 of 16 bits to bits 3:0. */ |
8402 | inst.instruction |= inst.operands[0].imm & 0xf; | |
8403 | } | |
09d92015 | 8404 | |
c19d1205 ZW |
8405 | static void |
8406 | encode_branch (int default_reloc) | |
8407 | { | |
8408 | if (inst.operands[0].hasreloc) | |
8409 | { | |
0855e32b NS |
8410 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32 |
8411 | && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL, | |
8412 | _("the only valid suffixes here are '(plt)' and '(tlscall)'")); | |
8413 | inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 | |
8414 | ? BFD_RELOC_ARM_PLT32 | |
8415 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 8416 | } |
b99bd4ef | 8417 | else |
9ae92b05 | 8418 | inst.reloc.type = (bfd_reloc_code_real_type) default_reloc; |
2fc8bdac | 8419 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
8420 | } |
8421 | ||
b99bd4ef | 8422 | static void |
c19d1205 | 8423 | do_branch (void) |
b99bd4ef | 8424 | { |
39b41c9c PB |
8425 | #ifdef OBJ_ELF |
8426 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8427 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8428 | else | |
8429 | #endif | |
8430 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
8431 | } | |
8432 | ||
8433 | static void | |
8434 | do_bl (void) | |
8435 | { | |
8436 | #ifdef OBJ_ELF | |
8437 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8438 | { | |
8439 | if (inst.cond == COND_ALWAYS) | |
8440 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
8441 | else | |
8442 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8443 | } | |
8444 | else | |
8445 | #endif | |
8446 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 8447 | } |
b99bd4ef | 8448 | |
c19d1205 ZW |
8449 | /* ARM V5 branch-link-exchange instruction (argument parse) |
8450 | BLX <target_addr> ie BLX(1) | |
8451 | BLX{<condition>} <Rm> ie BLX(2) | |
8452 | Unfortunately, there are two different opcodes for this mnemonic. | |
8453 | So, the insns[].value is not used, and the code here zaps values | |
8454 | into inst.instruction. | |
8455 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 8456 | |
c19d1205 ZW |
8457 | static void |
8458 | do_blx (void) | |
8459 | { | |
8460 | if (inst.operands[0].isreg) | |
b99bd4ef | 8461 | { |
c19d1205 ZW |
8462 | /* Arg is a register; the opcode provided by insns[] is correct. |
8463 | It is not illegal to do "blx pc", just useless. */ | |
8464 | if (inst.operands[0].reg == REG_PC) | |
8465 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 8466 | |
c19d1205 ZW |
8467 | inst.instruction |= inst.operands[0].reg; |
8468 | } | |
8469 | else | |
b99bd4ef | 8470 | { |
c19d1205 | 8471 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
8472 | conditionally, and the opcode must be adjusted. |
8473 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
8474 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 8475 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 8476 | inst.instruction = 0xfa000000; |
267bf995 | 8477 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 8478 | } |
c19d1205 ZW |
8479 | } |
8480 | ||
8481 | static void | |
8482 | do_bx (void) | |
8483 | { | |
845b51d6 PB |
8484 | bfd_boolean want_reloc; |
8485 | ||
c19d1205 ZW |
8486 | if (inst.operands[0].reg == REG_PC) |
8487 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 8488 | |
c19d1205 | 8489 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
8490 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
8491 | it is for ARMv4t or earlier. */ | |
8492 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
8493 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
8494 | want_reloc = TRUE; | |
8495 | ||
5ad34203 | 8496 | #ifdef OBJ_ELF |
845b51d6 | 8497 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 8498 | #endif |
584206db | 8499 | want_reloc = FALSE; |
845b51d6 PB |
8500 | |
8501 | if (want_reloc) | |
8502 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
8503 | } |
8504 | ||
c19d1205 ZW |
8505 | |
8506 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
8507 | |
8508 | static void | |
c19d1205 | 8509 | do_bxj (void) |
a737bd4d | 8510 | { |
c19d1205 ZW |
8511 | if (inst.operands[0].reg == REG_PC) |
8512 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
8513 | ||
8514 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
8515 | } |
8516 | ||
c19d1205 ZW |
8517 | /* Co-processor data operation: |
8518 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
8519 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
8520 | static void | |
8521 | do_cdp (void) | |
8522 | { | |
8523 | inst.instruction |= inst.operands[0].reg << 8; | |
8524 | inst.instruction |= inst.operands[1].imm << 20; | |
8525 | inst.instruction |= inst.operands[2].reg << 12; | |
8526 | inst.instruction |= inst.operands[3].reg << 16; | |
8527 | inst.instruction |= inst.operands[4].reg; | |
8528 | inst.instruction |= inst.operands[5].imm << 5; | |
8529 | } | |
a737bd4d NC |
8530 | |
8531 | static void | |
c19d1205 | 8532 | do_cmp (void) |
a737bd4d | 8533 | { |
c19d1205 ZW |
8534 | inst.instruction |= inst.operands[0].reg << 16; |
8535 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
8536 | } |
8537 | ||
c19d1205 ZW |
8538 | /* Transfer between coprocessor and ARM registers. |
8539 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
8540 | MRC2 | |
8541 | MCR{cond} | |
8542 | MCR2 | |
8543 | ||
8544 | No special properties. */ | |
09d92015 | 8545 | |
dcbd0d71 MGD |
8546 | struct deprecated_coproc_regs_s |
8547 | { | |
8548 | unsigned cp; | |
8549 | int opc1; | |
8550 | unsigned crn; | |
8551 | unsigned crm; | |
8552 | int opc2; | |
8553 | arm_feature_set deprecated; | |
8554 | arm_feature_set obsoleted; | |
8555 | const char *dep_msg; | |
8556 | const char *obs_msg; | |
8557 | }; | |
8558 | ||
8559 | #define DEPR_ACCESS_V8 \ | |
8560 | N_("This coprocessor register access is deprecated in ARMv8") | |
8561 | ||
8562 | /* Table of all deprecated coprocessor registers. */ | |
8563 | static struct deprecated_coproc_regs_s deprecated_coproc_regs[] = | |
8564 | { | |
8565 | {15, 0, 7, 10, 5, /* CP15DMB. */ | |
823d2571 | 8566 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8567 | DEPR_ACCESS_V8, NULL}, |
8568 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
823d2571 | 8569 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8570 | DEPR_ACCESS_V8, NULL}, |
8571 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
823d2571 | 8572 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8573 | DEPR_ACCESS_V8, NULL}, |
8574 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
823d2571 | 8575 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8576 | DEPR_ACCESS_V8, NULL}, |
8577 | {14, 6, 0, 0, 0, /* TEECR. */ | |
823d2571 | 8578 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8579 | DEPR_ACCESS_V8, NULL}, |
8580 | }; | |
8581 | ||
8582 | #undef DEPR_ACCESS_V8 | |
8583 | ||
8584 | static const size_t deprecated_coproc_reg_count = | |
8585 | sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]); | |
8586 | ||
09d92015 | 8587 | static void |
c19d1205 | 8588 | do_co_reg (void) |
09d92015 | 8589 | { |
fdfde340 | 8590 | unsigned Rd; |
dcbd0d71 | 8591 | size_t i; |
fdfde340 JM |
8592 | |
8593 | Rd = inst.operands[2].reg; | |
8594 | if (thumb_mode) | |
8595 | { | |
8596 | if (inst.instruction == 0xee000010 | |
8597 | || inst.instruction == 0xfe000010) | |
8598 | /* MCR, MCR2 */ | |
8599 | reject_bad_reg (Rd); | |
8600 | else | |
8601 | /* MRC, MRC2 */ | |
8602 | constraint (Rd == REG_SP, BAD_SP); | |
8603 | } | |
8604 | else | |
8605 | { | |
8606 | /* MCR */ | |
8607 | if (inst.instruction == 0xe000010) | |
8608 | constraint (Rd == REG_PC, BAD_PC); | |
8609 | } | |
8610 | ||
dcbd0d71 MGD |
8611 | for (i = 0; i < deprecated_coproc_reg_count; ++i) |
8612 | { | |
8613 | const struct deprecated_coproc_regs_s *r = | |
8614 | deprecated_coproc_regs + i; | |
8615 | ||
8616 | if (inst.operands[0].reg == r->cp | |
8617 | && inst.operands[1].imm == r->opc1 | |
8618 | && inst.operands[3].reg == r->crn | |
8619 | && inst.operands[4].reg == r->crm | |
8620 | && inst.operands[5].imm == r->opc2) | |
8621 | { | |
b10bf8c5 | 8622 | if (! ARM_CPU_IS_ANY (cpu_variant) |
477330fc | 8623 | && warn_on_deprecated |
dcbd0d71 | 8624 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) |
5c3696f8 | 8625 | as_tsktsk ("%s", r->dep_msg); |
dcbd0d71 MGD |
8626 | } |
8627 | } | |
fdfde340 | 8628 | |
c19d1205 ZW |
8629 | inst.instruction |= inst.operands[0].reg << 8; |
8630 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 8631 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
8632 | inst.instruction |= inst.operands[3].reg << 16; |
8633 | inst.instruction |= inst.operands[4].reg; | |
8634 | inst.instruction |= inst.operands[5].imm << 5; | |
8635 | } | |
09d92015 | 8636 | |
c19d1205 ZW |
8637 | /* Transfer between coprocessor register and pair of ARM registers. |
8638 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
8639 | MCRR2 | |
8640 | MRRC{cond} | |
8641 | MRRC2 | |
b99bd4ef | 8642 | |
c19d1205 | 8643 | Two XScale instructions are special cases of these: |
09d92015 | 8644 | |
c19d1205 ZW |
8645 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
8646 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 8647 | |
5f4273c7 | 8648 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 8649 | |
c19d1205 ZW |
8650 | static void |
8651 | do_co_reg2c (void) | |
8652 | { | |
fdfde340 JM |
8653 | unsigned Rd, Rn; |
8654 | ||
8655 | Rd = inst.operands[2].reg; | |
8656 | Rn = inst.operands[3].reg; | |
8657 | ||
8658 | if (thumb_mode) | |
8659 | { | |
8660 | reject_bad_reg (Rd); | |
8661 | reject_bad_reg (Rn); | |
8662 | } | |
8663 | else | |
8664 | { | |
8665 | constraint (Rd == REG_PC, BAD_PC); | |
8666 | constraint (Rn == REG_PC, BAD_PC); | |
8667 | } | |
8668 | ||
c19d1205 ZW |
8669 | inst.instruction |= inst.operands[0].reg << 8; |
8670 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
8671 | inst.instruction |= Rd << 12; |
8672 | inst.instruction |= Rn << 16; | |
c19d1205 | 8673 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
8674 | } |
8675 | ||
c19d1205 ZW |
8676 | static void |
8677 | do_cpsi (void) | |
8678 | { | |
8679 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
8680 | if (inst.operands[1].present) |
8681 | { | |
8682 | inst.instruction |= CPSI_MMOD; | |
8683 | inst.instruction |= inst.operands[1].imm; | |
8684 | } | |
c19d1205 | 8685 | } |
b99bd4ef | 8686 | |
62b3e311 PB |
8687 | static void |
8688 | do_dbg (void) | |
8689 | { | |
8690 | inst.instruction |= inst.operands[0].imm; | |
8691 | } | |
8692 | ||
eea54501 MGD |
8693 | static void |
8694 | do_div (void) | |
8695 | { | |
8696 | unsigned Rd, Rn, Rm; | |
8697 | ||
8698 | Rd = inst.operands[0].reg; | |
8699 | Rn = (inst.operands[1].present | |
8700 | ? inst.operands[1].reg : Rd); | |
8701 | Rm = inst.operands[2].reg; | |
8702 | ||
8703 | constraint ((Rd == REG_PC), BAD_PC); | |
8704 | constraint ((Rn == REG_PC), BAD_PC); | |
8705 | constraint ((Rm == REG_PC), BAD_PC); | |
8706 | ||
8707 | inst.instruction |= Rd << 16; | |
8708 | inst.instruction |= Rn << 0; | |
8709 | inst.instruction |= Rm << 8; | |
8710 | } | |
8711 | ||
b99bd4ef | 8712 | static void |
c19d1205 | 8713 | do_it (void) |
b99bd4ef | 8714 | { |
c19d1205 | 8715 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
8716 | process it to do the validation as if in |
8717 | thumb mode, just in case the code gets | |
8718 | assembled for thumb using the unified syntax. */ | |
8719 | ||
c19d1205 | 8720 | inst.size = 0; |
e07e6e58 NC |
8721 | if (unified_syntax) |
8722 | { | |
8723 | set_it_insn_type (IT_INSN); | |
8724 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
8725 | now_it.cc = inst.operands[0].imm; | |
8726 | } | |
09d92015 | 8727 | } |
b99bd4ef | 8728 | |
6530b175 NC |
8729 | /* If there is only one register in the register list, |
8730 | then return its register number. Otherwise return -1. */ | |
8731 | static int | |
8732 | only_one_reg_in_list (int range) | |
8733 | { | |
8734 | int i = ffs (range) - 1; | |
8735 | return (i > 15 || range != (1 << i)) ? -1 : i; | |
8736 | } | |
8737 | ||
09d92015 | 8738 | static void |
6530b175 | 8739 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 8740 | { |
c19d1205 ZW |
8741 | int base_reg = inst.operands[0].reg; |
8742 | int range = inst.operands[1].imm; | |
6530b175 | 8743 | int one_reg; |
ea6ef066 | 8744 | |
c19d1205 ZW |
8745 | inst.instruction |= base_reg << 16; |
8746 | inst.instruction |= range; | |
ea6ef066 | 8747 | |
c19d1205 ZW |
8748 | if (inst.operands[1].writeback) |
8749 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 8750 | |
c19d1205 | 8751 | if (inst.operands[0].writeback) |
ea6ef066 | 8752 | { |
c19d1205 ZW |
8753 | inst.instruction |= WRITE_BACK; |
8754 | /* Check for unpredictable uses of writeback. */ | |
8755 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 8756 | { |
c19d1205 ZW |
8757 | /* Not allowed in LDM type 2. */ |
8758 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
8759 | && ((range & (1 << REG_PC)) == 0)) | |
8760 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
8761 | /* Only allowed if base reg not in list for other types. */ | |
8762 | else if (range & (1 << base_reg)) | |
8763 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
8764 | } | |
8765 | else /* STM. */ | |
8766 | { | |
8767 | /* Not allowed for type 2. */ | |
8768 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
8769 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
8770 | /* Only allowed if base reg not in list, or first in list. */ | |
8771 | else if ((range & (1 << base_reg)) | |
8772 | && (range & ((1 << base_reg) - 1))) | |
8773 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 8774 | } |
ea6ef066 | 8775 | } |
6530b175 NC |
8776 | |
8777 | /* If PUSH/POP has only one register, then use the A2 encoding. */ | |
8778 | one_reg = only_one_reg_in_list (range); | |
8779 | if (from_push_pop_mnem && one_reg >= 0) | |
8780 | { | |
8781 | int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH; | |
8782 | ||
8783 | inst.instruction &= A_COND_MASK; | |
8784 | inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP; | |
8785 | inst.instruction |= one_reg << 12; | |
8786 | } | |
8787 | } | |
8788 | ||
8789 | static void | |
8790 | do_ldmstm (void) | |
8791 | { | |
8792 | encode_ldmstm (/*from_push_pop_mnem=*/FALSE); | |
a737bd4d NC |
8793 | } |
8794 | ||
c19d1205 ZW |
8795 | /* ARMv5TE load-consecutive (argument parse) |
8796 | Mode is like LDRH. | |
8797 | ||
8798 | LDRccD R, mode | |
8799 | STRccD R, mode. */ | |
8800 | ||
a737bd4d | 8801 | static void |
c19d1205 | 8802 | do_ldrd (void) |
a737bd4d | 8803 | { |
c19d1205 | 8804 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 8805 | _("first transfer register must be even")); |
c19d1205 ZW |
8806 | constraint (inst.operands[1].present |
8807 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 8808 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
8809 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
8810 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 8811 | |
c19d1205 ZW |
8812 | if (!inst.operands[1].present) |
8813 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 8814 | |
c56791bb RE |
8815 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
8816 | register and the first register written; we have to diagnose | |
8817 | overlap between the base and the second register written here. */ | |
ea6ef066 | 8818 | |
c56791bb RE |
8819 | if (inst.operands[2].reg == inst.operands[1].reg |
8820 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
8821 | as_warn (_("base register written back, and overlaps " | |
8822 | "second transfer register")); | |
b05fe5cf | 8823 | |
c56791bb RE |
8824 | if (!(inst.instruction & V4_STR_BIT)) |
8825 | { | |
c19d1205 | 8826 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
8827 | destination (even if not write-back). */ |
8828 | if (inst.operands[2].immisreg | |
8829 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg | |
8830 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
8831 | as_warn (_("index register overlaps transfer register")); | |
b05fe5cf | 8832 | } |
c19d1205 ZW |
8833 | inst.instruction |= inst.operands[0].reg << 12; |
8834 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
8835 | } |
8836 | ||
8837 | static void | |
c19d1205 | 8838 | do_ldrex (void) |
b05fe5cf | 8839 | { |
c19d1205 ZW |
8840 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
8841 | || inst.operands[1].postind || inst.operands[1].writeback | |
8842 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
8843 | || inst.operands[1].negative |
8844 | /* This can arise if the programmer has written | |
8845 | strex rN, rM, foo | |
8846 | or if they have mistakenly used a register name as the last | |
8847 | operand, eg: | |
8848 | strex rN, rM, rX | |
8849 | It is very difficult to distinguish between these two cases | |
8850 | because "rX" might actually be a label. ie the register | |
8851 | name has been occluded by a symbol of the same name. So we | |
8852 | just generate a general 'bad addressing mode' type error | |
8853 | message and leave it up to the programmer to discover the | |
8854 | true cause and fix their mistake. */ | |
8855 | || (inst.operands[1].reg == REG_PC), | |
8856 | BAD_ADDR_MODE); | |
b05fe5cf | 8857 | |
c19d1205 ZW |
8858 | constraint (inst.reloc.exp.X_op != O_constant |
8859 | || inst.reloc.exp.X_add_number != 0, | |
8860 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 8861 | |
5be8be5d DG |
8862 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
8863 | ||
c19d1205 ZW |
8864 | inst.instruction |= inst.operands[0].reg << 12; |
8865 | inst.instruction |= inst.operands[1].reg << 16; | |
8866 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
8867 | } |
8868 | ||
8869 | static void | |
c19d1205 | 8870 | do_ldrexd (void) |
b05fe5cf | 8871 | { |
c19d1205 ZW |
8872 | constraint (inst.operands[0].reg % 2 != 0, |
8873 | _("even register required")); | |
8874 | constraint (inst.operands[1].present | |
8875 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
8876 | _("can only load two consecutive registers")); | |
8877 | /* If op 1 were present and equal to PC, this function wouldn't | |
8878 | have been called in the first place. */ | |
8879 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 8880 | |
c19d1205 ZW |
8881 | inst.instruction |= inst.operands[0].reg << 12; |
8882 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
8883 | } |
8884 | ||
1be5fd2e NC |
8885 | /* In both ARM and thumb state 'ldr pc, #imm' with an immediate |
8886 | which is not a multiple of four is UNPREDICTABLE. */ | |
8887 | static void | |
8888 | check_ldr_r15_aligned (void) | |
8889 | { | |
8890 | constraint (!(inst.operands[1].immisreg) | |
8891 | && (inst.operands[0].reg == REG_PC | |
8892 | && inst.operands[1].reg == REG_PC | |
8893 | && (inst.reloc.exp.X_add_number & 0x3)), | |
8894 | _("ldr to register 15 must be 4-byte alligned")); | |
8895 | } | |
8896 | ||
b05fe5cf | 8897 | static void |
c19d1205 | 8898 | do_ldst (void) |
b05fe5cf | 8899 | { |
c19d1205 ZW |
8900 | inst.instruction |= inst.operands[0].reg << 12; |
8901 | if (!inst.operands[1].isreg) | |
8335d6aa | 8902 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE)) |
b05fe5cf | 8903 | return; |
c19d1205 | 8904 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
1be5fd2e | 8905 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
8906 | } |
8907 | ||
8908 | static void | |
c19d1205 | 8909 | do_ldstt (void) |
b05fe5cf | 8910 | { |
c19d1205 ZW |
8911 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
8912 | reject [Rn,...]. */ | |
8913 | if (inst.operands[1].preind) | |
b05fe5cf | 8914 | { |
bd3ba5d1 NC |
8915 | constraint (inst.reloc.exp.X_op != O_constant |
8916 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 8917 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 8918 | |
c19d1205 ZW |
8919 | inst.operands[1].preind = 0; |
8920 | inst.operands[1].postind = 1; | |
8921 | inst.operands[1].writeback = 1; | |
b05fe5cf | 8922 | } |
c19d1205 ZW |
8923 | inst.instruction |= inst.operands[0].reg << 12; |
8924 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
8925 | } | |
b05fe5cf | 8926 | |
c19d1205 | 8927 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 8928 | |
c19d1205 ZW |
8929 | static void |
8930 | do_ldstv4 (void) | |
8931 | { | |
ff4a8d2b | 8932 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
8933 | inst.instruction |= inst.operands[0].reg << 12; |
8934 | if (!inst.operands[1].isreg) | |
8335d6aa | 8935 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE)) |
b05fe5cf | 8936 | return; |
c19d1205 | 8937 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
8938 | } |
8939 | ||
8940 | static void | |
c19d1205 | 8941 | do_ldsttv4 (void) |
b05fe5cf | 8942 | { |
c19d1205 ZW |
8943 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
8944 | reject [Rn,...]. */ | |
8945 | if (inst.operands[1].preind) | |
b05fe5cf | 8946 | { |
bd3ba5d1 NC |
8947 | constraint (inst.reloc.exp.X_op != O_constant |
8948 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 8949 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 8950 | |
c19d1205 ZW |
8951 | inst.operands[1].preind = 0; |
8952 | inst.operands[1].postind = 1; | |
8953 | inst.operands[1].writeback = 1; | |
b05fe5cf | 8954 | } |
c19d1205 ZW |
8955 | inst.instruction |= inst.operands[0].reg << 12; |
8956 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
8957 | } | |
b05fe5cf | 8958 | |
c19d1205 ZW |
8959 | /* Co-processor register load/store. |
8960 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
8961 | static void | |
8962 | do_lstc (void) | |
8963 | { | |
8964 | inst.instruction |= inst.operands[0].reg << 8; | |
8965 | inst.instruction |= inst.operands[1].reg << 12; | |
8966 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
8967 | } |
8968 | ||
b05fe5cf | 8969 | static void |
c19d1205 | 8970 | do_mlas (void) |
b05fe5cf | 8971 | { |
8fb9d7b9 | 8972 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 8973 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 8974 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 8975 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 8976 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 8977 | |
c19d1205 ZW |
8978 | inst.instruction |= inst.operands[0].reg << 16; |
8979 | inst.instruction |= inst.operands[1].reg; | |
8980 | inst.instruction |= inst.operands[2].reg << 8; | |
8981 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 8982 | } |
b05fe5cf | 8983 | |
c19d1205 ZW |
8984 | static void |
8985 | do_mov (void) | |
8986 | { | |
a9f02af8 MG |
8987 | constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
8988 | && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
8989 | THUMB1_RELOC_ONLY); | |
c19d1205 ZW |
8990 | inst.instruction |= inst.operands[0].reg << 12; |
8991 | encode_arm_shifter_operand (1); | |
8992 | } | |
b05fe5cf | 8993 | |
c19d1205 ZW |
8994 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
8995 | static void | |
8996 | do_mov16 (void) | |
8997 | { | |
b6895b4f PB |
8998 | bfd_vma imm; |
8999 | bfd_boolean top; | |
9000 | ||
9001 | top = (inst.instruction & 0x00400000) != 0; | |
9002 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
9003 | _(":lower16: not allowed this instruction")); | |
9004 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
9005 | _(":upper16: not allowed instruction")); | |
c19d1205 | 9006 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
9007 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
9008 | { | |
9009 | imm = inst.reloc.exp.X_add_number; | |
9010 | /* The value is in two pieces: 0:11, 16:19. */ | |
9011 | inst.instruction |= (imm & 0x00000fff); | |
9012 | inst.instruction |= (imm & 0x0000f000) << 4; | |
9013 | } | |
b05fe5cf | 9014 | } |
b99bd4ef | 9015 | |
037e8744 JB |
9016 | static int |
9017 | do_vfp_nsyn_mrs (void) | |
9018 | { | |
9019 | if (inst.operands[0].isvec) | |
9020 | { | |
9021 | if (inst.operands[1].reg != 1) | |
477330fc | 9022 | first_error (_("operand 1 must be FPSCR")); |
037e8744 JB |
9023 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); |
9024 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
9025 | do_vfp_nsyn_opcode ("fmstat"); | |
9026 | } | |
9027 | else if (inst.operands[1].isvec) | |
9028 | do_vfp_nsyn_opcode ("fmrx"); | |
9029 | else | |
9030 | return FAIL; | |
5f4273c7 | 9031 | |
037e8744 JB |
9032 | return SUCCESS; |
9033 | } | |
9034 | ||
9035 | static int | |
9036 | do_vfp_nsyn_msr (void) | |
9037 | { | |
9038 | if (inst.operands[0].isvec) | |
9039 | do_vfp_nsyn_opcode ("fmxr"); | |
9040 | else | |
9041 | return FAIL; | |
9042 | ||
9043 | return SUCCESS; | |
9044 | } | |
9045 | ||
f7c21dc7 NC |
9046 | static void |
9047 | do_vmrs (void) | |
9048 | { | |
9049 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 9050 | |
16d02dc9 | 9051 | if (thumb_mode && Rt == REG_SP) |
f7c21dc7 NC |
9052 | { |
9053 | inst.error = BAD_SP; | |
9054 | return; | |
9055 | } | |
9056 | ||
9057 | /* APSR_ sets isvec. All other refs to PC are illegal. */ | |
16d02dc9 | 9058 | if (!inst.operands[0].isvec && Rt == REG_PC) |
f7c21dc7 NC |
9059 | { |
9060 | inst.error = BAD_PC; | |
9061 | return; | |
9062 | } | |
9063 | ||
16d02dc9 JB |
9064 | /* If we get through parsing the register name, we just insert the number |
9065 | generated into the instruction without further validation. */ | |
9066 | inst.instruction |= (inst.operands[1].reg << 16); | |
f7c21dc7 NC |
9067 | inst.instruction |= (Rt << 12); |
9068 | } | |
9069 | ||
9070 | static void | |
9071 | do_vmsr (void) | |
9072 | { | |
9073 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 9074 | |
f7c21dc7 NC |
9075 | if (thumb_mode) |
9076 | reject_bad_reg (Rt); | |
9077 | else if (Rt == REG_PC) | |
9078 | { | |
9079 | inst.error = BAD_PC; | |
9080 | return; | |
9081 | } | |
9082 | ||
16d02dc9 JB |
9083 | /* If we get through parsing the register name, we just insert the number |
9084 | generated into the instruction without further validation. */ | |
9085 | inst.instruction |= (inst.operands[0].reg << 16); | |
f7c21dc7 NC |
9086 | inst.instruction |= (Rt << 12); |
9087 | } | |
9088 | ||
b99bd4ef | 9089 | static void |
c19d1205 | 9090 | do_mrs (void) |
b99bd4ef | 9091 | { |
90ec0d68 MGD |
9092 | unsigned br; |
9093 | ||
037e8744 JB |
9094 | if (do_vfp_nsyn_mrs () == SUCCESS) |
9095 | return; | |
9096 | ||
ff4a8d2b | 9097 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 9098 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
9099 | |
9100 | if (inst.operands[1].isreg) | |
9101 | { | |
9102 | br = inst.operands[1].reg; | |
9103 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000)) | |
9104 | as_bad (_("bad register for mrs")); | |
9105 | } | |
9106 | else | |
9107 | { | |
9108 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
9109 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
9110 | != (PSR_c|PSR_f), | |
d2cd1205 | 9111 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
9112 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
9113 | } | |
9114 | ||
9115 | inst.instruction |= br; | |
c19d1205 | 9116 | } |
b99bd4ef | 9117 | |
c19d1205 ZW |
9118 | /* Two possible forms: |
9119 | "{C|S}PSR_<field>, Rm", | |
9120 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 9121 | |
c19d1205 ZW |
9122 | static void |
9123 | do_msr (void) | |
9124 | { | |
037e8744 JB |
9125 | if (do_vfp_nsyn_msr () == SUCCESS) |
9126 | return; | |
9127 | ||
c19d1205 ZW |
9128 | inst.instruction |= inst.operands[0].imm; |
9129 | if (inst.operands[1].isreg) | |
9130 | inst.instruction |= inst.operands[1].reg; | |
9131 | else | |
b99bd4ef | 9132 | { |
c19d1205 ZW |
9133 | inst.instruction |= INST_IMMEDIATE; |
9134 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
9135 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 9136 | } |
b99bd4ef NC |
9137 | } |
9138 | ||
c19d1205 ZW |
9139 | static void |
9140 | do_mul (void) | |
a737bd4d | 9141 | { |
ff4a8d2b NC |
9142 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
9143 | ||
c19d1205 ZW |
9144 | if (!inst.operands[2].present) |
9145 | inst.operands[2].reg = inst.operands[0].reg; | |
9146 | inst.instruction |= inst.operands[0].reg << 16; | |
9147 | inst.instruction |= inst.operands[1].reg; | |
9148 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 9149 | |
8fb9d7b9 MS |
9150 | if (inst.operands[0].reg == inst.operands[1].reg |
9151 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
9152 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
9153 | } |
9154 | ||
c19d1205 ZW |
9155 | /* Long Multiply Parser |
9156 | UMULL RdLo, RdHi, Rm, Rs | |
9157 | SMULL RdLo, RdHi, Rm, Rs | |
9158 | UMLAL RdLo, RdHi, Rm, Rs | |
9159 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
9160 | |
9161 | static void | |
c19d1205 | 9162 | do_mull (void) |
b99bd4ef | 9163 | { |
c19d1205 ZW |
9164 | inst.instruction |= inst.operands[0].reg << 12; |
9165 | inst.instruction |= inst.operands[1].reg << 16; | |
9166 | inst.instruction |= inst.operands[2].reg; | |
9167 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 9168 | |
682b27ad PB |
9169 | /* rdhi and rdlo must be different. */ |
9170 | if (inst.operands[0].reg == inst.operands[1].reg) | |
9171 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9172 | ||
9173 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
9174 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 9175 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 9176 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
9177 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
9178 | } | |
b99bd4ef | 9179 | |
c19d1205 ZW |
9180 | static void |
9181 | do_nop (void) | |
9182 | { | |
e7495e45 NS |
9183 | if (inst.operands[0].present |
9184 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
9185 | { |
9186 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
9187 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
9188 | inst.instruction |= 0x0320f000; |
9189 | if (inst.operands[0].present) | |
9190 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 9191 | } |
b99bd4ef NC |
9192 | } |
9193 | ||
c19d1205 ZW |
9194 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
9195 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
9196 | Condition defaults to COND_ALWAYS. | |
9197 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
9198 | |
9199 | static void | |
c19d1205 | 9200 | do_pkhbt (void) |
b99bd4ef | 9201 | { |
c19d1205 ZW |
9202 | inst.instruction |= inst.operands[0].reg << 12; |
9203 | inst.instruction |= inst.operands[1].reg << 16; | |
9204 | inst.instruction |= inst.operands[2].reg; | |
9205 | if (inst.operands[3].present) | |
9206 | encode_arm_shift (3); | |
9207 | } | |
b99bd4ef | 9208 | |
c19d1205 | 9209 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 9210 | |
c19d1205 ZW |
9211 | static void |
9212 | do_pkhtb (void) | |
9213 | { | |
9214 | if (!inst.operands[3].present) | |
b99bd4ef | 9215 | { |
c19d1205 ZW |
9216 | /* If the shift specifier is omitted, turn the instruction |
9217 | into pkhbt rd, rm, rn. */ | |
9218 | inst.instruction &= 0xfff00010; | |
9219 | inst.instruction |= inst.operands[0].reg << 12; | |
9220 | inst.instruction |= inst.operands[1].reg; | |
9221 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9222 | } |
9223 | else | |
9224 | { | |
c19d1205 ZW |
9225 | inst.instruction |= inst.operands[0].reg << 12; |
9226 | inst.instruction |= inst.operands[1].reg << 16; | |
9227 | inst.instruction |= inst.operands[2].reg; | |
9228 | encode_arm_shift (3); | |
b99bd4ef NC |
9229 | } |
9230 | } | |
9231 | ||
c19d1205 | 9232 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 9233 | MP Extensions: Preload for write |
c19d1205 | 9234 | |
60e5ef9f | 9235 | PLD(W) <addr_mode> |
c19d1205 ZW |
9236 | |
9237 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
9238 | |
9239 | static void | |
c19d1205 | 9240 | do_pld (void) |
b99bd4ef | 9241 | { |
c19d1205 ZW |
9242 | constraint (!inst.operands[0].isreg, |
9243 | _("'[' expected after PLD mnemonic")); | |
9244 | constraint (inst.operands[0].postind, | |
9245 | _("post-indexed expression used in preload instruction")); | |
9246 | constraint (inst.operands[0].writeback, | |
9247 | _("writeback used in preload instruction")); | |
9248 | constraint (!inst.operands[0].preind, | |
9249 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
9250 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
9251 | } | |
b99bd4ef | 9252 | |
62b3e311 PB |
9253 | /* ARMv7: PLI <addr_mode> */ |
9254 | static void | |
9255 | do_pli (void) | |
9256 | { | |
9257 | constraint (!inst.operands[0].isreg, | |
9258 | _("'[' expected after PLI mnemonic")); | |
9259 | constraint (inst.operands[0].postind, | |
9260 | _("post-indexed expression used in preload instruction")); | |
9261 | constraint (inst.operands[0].writeback, | |
9262 | _("writeback used in preload instruction")); | |
9263 | constraint (!inst.operands[0].preind, | |
9264 | _("unindexed addressing used in preload instruction")); | |
9265 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
9266 | inst.instruction &= ~PRE_INDEX; | |
9267 | } | |
9268 | ||
c19d1205 ZW |
9269 | static void |
9270 | do_push_pop (void) | |
9271 | { | |
5e0d7f77 MP |
9272 | constraint (inst.operands[0].writeback, |
9273 | _("push/pop do not support {reglist}^")); | |
c19d1205 ZW |
9274 | inst.operands[1] = inst.operands[0]; |
9275 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
9276 | inst.operands[0].isreg = 1; | |
9277 | inst.operands[0].writeback = 1; | |
9278 | inst.operands[0].reg = REG_SP; | |
6530b175 | 9279 | encode_ldmstm (/*from_push_pop_mnem=*/TRUE); |
c19d1205 | 9280 | } |
b99bd4ef | 9281 | |
c19d1205 ZW |
9282 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
9283 | word at the specified address and the following word | |
9284 | respectively. | |
9285 | Unconditionally executed. | |
9286 | Error if Rn is R15. */ | |
b99bd4ef | 9287 | |
c19d1205 ZW |
9288 | static void |
9289 | do_rfe (void) | |
9290 | { | |
9291 | inst.instruction |= inst.operands[0].reg << 16; | |
9292 | if (inst.operands[0].writeback) | |
9293 | inst.instruction |= WRITE_BACK; | |
9294 | } | |
b99bd4ef | 9295 | |
c19d1205 | 9296 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 9297 | |
c19d1205 ZW |
9298 | static void |
9299 | do_ssat (void) | |
9300 | { | |
9301 | inst.instruction |= inst.operands[0].reg << 12; | |
9302 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
9303 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9304 | |
c19d1205 ZW |
9305 | if (inst.operands[3].present) |
9306 | encode_arm_shift (3); | |
b99bd4ef NC |
9307 | } |
9308 | ||
c19d1205 | 9309 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
9310 | |
9311 | static void | |
c19d1205 | 9312 | do_usat (void) |
b99bd4ef | 9313 | { |
c19d1205 ZW |
9314 | inst.instruction |= inst.operands[0].reg << 12; |
9315 | inst.instruction |= inst.operands[1].imm << 16; | |
9316 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9317 | |
c19d1205 ZW |
9318 | if (inst.operands[3].present) |
9319 | encode_arm_shift (3); | |
b99bd4ef NC |
9320 | } |
9321 | ||
c19d1205 | 9322 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
9323 | |
9324 | static void | |
c19d1205 | 9325 | do_ssat16 (void) |
09d92015 | 9326 | { |
c19d1205 ZW |
9327 | inst.instruction |= inst.operands[0].reg << 12; |
9328 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
9329 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
9330 | } |
9331 | ||
c19d1205 ZW |
9332 | static void |
9333 | do_usat16 (void) | |
a737bd4d | 9334 | { |
c19d1205 ZW |
9335 | inst.instruction |= inst.operands[0].reg << 12; |
9336 | inst.instruction |= inst.operands[1].imm << 16; | |
9337 | inst.instruction |= inst.operands[2].reg; | |
9338 | } | |
a737bd4d | 9339 | |
c19d1205 ZW |
9340 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
9341 | preserving the other bits. | |
a737bd4d | 9342 | |
c19d1205 ZW |
9343 | setend <endian_specifier>, where <endian_specifier> is either |
9344 | BE or LE. */ | |
a737bd4d | 9345 | |
c19d1205 ZW |
9346 | static void |
9347 | do_setend (void) | |
9348 | { | |
12e37cbc MGD |
9349 | if (warn_on_deprecated |
9350 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 9351 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 9352 | |
c19d1205 ZW |
9353 | if (inst.operands[0].imm) |
9354 | inst.instruction |= 0x200; | |
a737bd4d NC |
9355 | } |
9356 | ||
9357 | static void | |
c19d1205 | 9358 | do_shift (void) |
a737bd4d | 9359 | { |
c19d1205 ZW |
9360 | unsigned int Rm = (inst.operands[1].present |
9361 | ? inst.operands[1].reg | |
9362 | : inst.operands[0].reg); | |
a737bd4d | 9363 | |
c19d1205 ZW |
9364 | inst.instruction |= inst.operands[0].reg << 12; |
9365 | inst.instruction |= Rm; | |
9366 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 9367 | { |
c19d1205 ZW |
9368 | inst.instruction |= inst.operands[2].reg << 8; |
9369 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
9370 | /* PR 12854: Error on extraneous shifts. */ |
9371 | constraint (inst.operands[2].shifted, | |
9372 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
9373 | } |
9374 | else | |
c19d1205 | 9375 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
9376 | } |
9377 | ||
09d92015 | 9378 | static void |
3eb17e6b | 9379 | do_smc (void) |
09d92015 | 9380 | { |
3eb17e6b | 9381 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 9382 | inst.reloc.pc_rel = 0; |
09d92015 MM |
9383 | } |
9384 | ||
90ec0d68 MGD |
9385 | static void |
9386 | do_hvc (void) | |
9387 | { | |
9388 | inst.reloc.type = BFD_RELOC_ARM_HVC; | |
9389 | inst.reloc.pc_rel = 0; | |
9390 | } | |
9391 | ||
09d92015 | 9392 | static void |
c19d1205 | 9393 | do_swi (void) |
09d92015 | 9394 | { |
c19d1205 ZW |
9395 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
9396 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
9397 | } |
9398 | ||
ddfded2f MW |
9399 | static void |
9400 | do_setpan (void) | |
9401 | { | |
9402 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9403 | _("selected processor does not support SETPAN instruction")); | |
9404 | ||
9405 | inst.instruction |= ((inst.operands[0].imm & 1) << 9); | |
9406 | } | |
9407 | ||
9408 | static void | |
9409 | do_t_setpan (void) | |
9410 | { | |
9411 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9412 | _("selected processor does not support SETPAN instruction")); | |
9413 | ||
9414 | inst.instruction |= (inst.operands[0].imm << 3); | |
9415 | } | |
9416 | ||
c19d1205 ZW |
9417 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
9418 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
9419 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
9420 | Error if any register is R15. */ | |
e16bb312 | 9421 | |
c19d1205 ZW |
9422 | static void |
9423 | do_smla (void) | |
e16bb312 | 9424 | { |
c19d1205 ZW |
9425 | inst.instruction |= inst.operands[0].reg << 16; |
9426 | inst.instruction |= inst.operands[1].reg; | |
9427 | inst.instruction |= inst.operands[2].reg << 8; | |
9428 | inst.instruction |= inst.operands[3].reg << 12; | |
9429 | } | |
a737bd4d | 9430 | |
c19d1205 ZW |
9431 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
9432 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
9433 | Error if any register is R15. | |
9434 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 9435 | |
c19d1205 ZW |
9436 | static void |
9437 | do_smlal (void) | |
9438 | { | |
9439 | inst.instruction |= inst.operands[0].reg << 12; | |
9440 | inst.instruction |= inst.operands[1].reg << 16; | |
9441 | inst.instruction |= inst.operands[2].reg; | |
9442 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 9443 | |
c19d1205 ZW |
9444 | if (inst.operands[0].reg == inst.operands[1].reg) |
9445 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9446 | } | |
a737bd4d | 9447 | |
c19d1205 ZW |
9448 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
9449 | SMULxy{cond} Rd,Rm,Rs | |
9450 | Error if any register is R15. */ | |
a737bd4d | 9451 | |
c19d1205 ZW |
9452 | static void |
9453 | do_smul (void) | |
9454 | { | |
9455 | inst.instruction |= inst.operands[0].reg << 16; | |
9456 | inst.instruction |= inst.operands[1].reg; | |
9457 | inst.instruction |= inst.operands[2].reg << 8; | |
9458 | } | |
a737bd4d | 9459 | |
b6702015 PB |
9460 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
9461 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 9462 | |
c19d1205 ZW |
9463 | static void |
9464 | do_srs (void) | |
9465 | { | |
b6702015 PB |
9466 | int reg; |
9467 | ||
9468 | if (inst.operands[0].present) | |
9469 | { | |
9470 | reg = inst.operands[0].reg; | |
fdfde340 | 9471 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
9472 | } |
9473 | else | |
fdfde340 | 9474 | reg = REG_SP; |
b6702015 PB |
9475 | |
9476 | inst.instruction |= reg << 16; | |
9477 | inst.instruction |= inst.operands[1].imm; | |
9478 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
9479 | inst.instruction |= WRITE_BACK; |
9480 | } | |
a737bd4d | 9481 | |
c19d1205 | 9482 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 9483 | |
c19d1205 ZW |
9484 | static void |
9485 | do_strex (void) | |
9486 | { | |
9487 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9488 | || inst.operands[2].postind || inst.operands[2].writeback | |
9489 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
9490 | || inst.operands[2].negative |
9491 | /* See comment in do_ldrex(). */ | |
9492 | || (inst.operands[2].reg == REG_PC), | |
9493 | BAD_ADDR_MODE); | |
a737bd4d | 9494 | |
c19d1205 ZW |
9495 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9496 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 9497 | |
c19d1205 ZW |
9498 | constraint (inst.reloc.exp.X_op != O_constant |
9499 | || inst.reloc.exp.X_add_number != 0, | |
9500 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 9501 | |
c19d1205 ZW |
9502 | inst.instruction |= inst.operands[0].reg << 12; |
9503 | inst.instruction |= inst.operands[1].reg; | |
9504 | inst.instruction |= inst.operands[2].reg << 16; | |
9505 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
9506 | } |
9507 | ||
877807f8 NC |
9508 | static void |
9509 | do_t_strexbh (void) | |
9510 | { | |
9511 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9512 | || inst.operands[2].postind || inst.operands[2].writeback | |
9513 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
9514 | || inst.operands[2].negative, | |
9515 | BAD_ADDR_MODE); | |
9516 | ||
9517 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9518 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9519 | ||
9520 | do_rm_rd_rn (); | |
9521 | } | |
9522 | ||
e16bb312 | 9523 | static void |
c19d1205 | 9524 | do_strexd (void) |
e16bb312 | 9525 | { |
c19d1205 ZW |
9526 | constraint (inst.operands[1].reg % 2 != 0, |
9527 | _("even register required")); | |
9528 | constraint (inst.operands[2].present | |
9529 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
9530 | _("can only store two consecutive registers")); | |
9531 | /* If op 2 were present and equal to PC, this function wouldn't | |
9532 | have been called in the first place. */ | |
9533 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 9534 | |
c19d1205 ZW |
9535 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9536 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
9537 | || inst.operands[0].reg == inst.operands[3].reg, | |
9538 | BAD_OVERLAP); | |
e16bb312 | 9539 | |
c19d1205 ZW |
9540 | inst.instruction |= inst.operands[0].reg << 12; |
9541 | inst.instruction |= inst.operands[1].reg; | |
9542 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
9543 | } |
9544 | ||
9eb6c0f1 MGD |
9545 | /* ARM V8 STRL. */ |
9546 | static void | |
4b8c8c02 | 9547 | do_stlex (void) |
9eb6c0f1 MGD |
9548 | { |
9549 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9550 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9551 | ||
9552 | do_rd_rm_rn (); | |
9553 | } | |
9554 | ||
9555 | static void | |
4b8c8c02 | 9556 | do_t_stlex (void) |
9eb6c0f1 MGD |
9557 | { |
9558 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9559 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9560 | ||
9561 | do_rm_rd_rn (); | |
9562 | } | |
9563 | ||
c19d1205 ZW |
9564 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
9565 | extends it to 32-bits, and adds the result to a value in another | |
9566 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
9567 | before extracting the 16-bit value. | |
9568 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
9569 | Condition defaults to COND_ALWAYS. | |
9570 | Error if any register uses R15. */ | |
9571 | ||
e16bb312 | 9572 | static void |
c19d1205 | 9573 | do_sxtah (void) |
e16bb312 | 9574 | { |
c19d1205 ZW |
9575 | inst.instruction |= inst.operands[0].reg << 12; |
9576 | inst.instruction |= inst.operands[1].reg << 16; | |
9577 | inst.instruction |= inst.operands[2].reg; | |
9578 | inst.instruction |= inst.operands[3].imm << 10; | |
9579 | } | |
e16bb312 | 9580 | |
c19d1205 | 9581 | /* ARM V6 SXTH. |
e16bb312 | 9582 | |
c19d1205 ZW |
9583 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
9584 | Condition defaults to COND_ALWAYS. | |
9585 | Error if any register uses R15. */ | |
e16bb312 NC |
9586 | |
9587 | static void | |
c19d1205 | 9588 | do_sxth (void) |
e16bb312 | 9589 | { |
c19d1205 ZW |
9590 | inst.instruction |= inst.operands[0].reg << 12; |
9591 | inst.instruction |= inst.operands[1].reg; | |
9592 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 9593 | } |
c19d1205 ZW |
9594 | \f |
9595 | /* VFP instructions. In a logical order: SP variant first, monad | |
9596 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
9597 | |
9598 | static void | |
c19d1205 | 9599 | do_vfp_sp_monadic (void) |
e16bb312 | 9600 | { |
5287ad62 JB |
9601 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9602 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9603 | } |
9604 | ||
9605 | static void | |
c19d1205 | 9606 | do_vfp_sp_dyadic (void) |
e16bb312 | 9607 | { |
5287ad62 JB |
9608 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9609 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
9610 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
9611 | } |
9612 | ||
9613 | static void | |
c19d1205 | 9614 | do_vfp_sp_compare_z (void) |
e16bb312 | 9615 | { |
5287ad62 | 9616 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
9617 | } |
9618 | ||
9619 | static void | |
c19d1205 | 9620 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 9621 | { |
5287ad62 JB |
9622 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
9623 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9624 | } |
9625 | ||
9626 | static void | |
c19d1205 | 9627 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 9628 | { |
5287ad62 JB |
9629 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9630 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
9631 | } |
9632 | ||
9633 | static void | |
c19d1205 | 9634 | do_vfp_reg_from_sp (void) |
e16bb312 | 9635 | { |
c19d1205 | 9636 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 9637 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
9638 | } |
9639 | ||
9640 | static void | |
c19d1205 | 9641 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 9642 | { |
c19d1205 ZW |
9643 | constraint (inst.operands[2].imm != 2, |
9644 | _("only two consecutive VFP SP registers allowed here")); | |
9645 | inst.instruction |= inst.operands[0].reg << 12; | |
9646 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 9647 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
9648 | } |
9649 | ||
9650 | static void | |
c19d1205 | 9651 | do_vfp_sp_from_reg (void) |
e16bb312 | 9652 | { |
5287ad62 | 9653 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 9654 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
9655 | } |
9656 | ||
9657 | static void | |
c19d1205 | 9658 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 9659 | { |
c19d1205 ZW |
9660 | constraint (inst.operands[0].imm != 2, |
9661 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 9662 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
9663 | inst.instruction |= inst.operands[1].reg << 12; |
9664 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
9665 | } |
9666 | ||
9667 | static void | |
c19d1205 | 9668 | do_vfp_sp_ldst (void) |
e16bb312 | 9669 | { |
5287ad62 | 9670 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 9671 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
9672 | } |
9673 | ||
9674 | static void | |
c19d1205 | 9675 | do_vfp_dp_ldst (void) |
e16bb312 | 9676 | { |
5287ad62 | 9677 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 9678 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
9679 | } |
9680 | ||
c19d1205 | 9681 | |
e16bb312 | 9682 | static void |
c19d1205 | 9683 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 9684 | { |
c19d1205 ZW |
9685 | if (inst.operands[0].writeback) |
9686 | inst.instruction |= WRITE_BACK; | |
9687 | else | |
9688 | constraint (ldstm_type != VFP_LDSTMIA, | |
9689 | _("this addressing mode requires base-register writeback")); | |
9690 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 9691 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 9692 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
9693 | } |
9694 | ||
9695 | static void | |
c19d1205 | 9696 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 9697 | { |
c19d1205 | 9698 | int count; |
e16bb312 | 9699 | |
c19d1205 ZW |
9700 | if (inst.operands[0].writeback) |
9701 | inst.instruction |= WRITE_BACK; | |
9702 | else | |
9703 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
9704 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 9705 | |
c19d1205 | 9706 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 9707 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 9708 | |
c19d1205 ZW |
9709 | count = inst.operands[1].imm << 1; |
9710 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
9711 | count += 1; | |
e16bb312 | 9712 | |
c19d1205 | 9713 | inst.instruction |= count; |
e16bb312 NC |
9714 | } |
9715 | ||
9716 | static void | |
c19d1205 | 9717 | do_vfp_sp_ldstmia (void) |
e16bb312 | 9718 | { |
c19d1205 | 9719 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
9720 | } |
9721 | ||
9722 | static void | |
c19d1205 | 9723 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 9724 | { |
c19d1205 | 9725 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
9726 | } |
9727 | ||
9728 | static void | |
c19d1205 | 9729 | do_vfp_dp_ldstmia (void) |
e16bb312 | 9730 | { |
c19d1205 | 9731 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
9732 | } |
9733 | ||
9734 | static void | |
c19d1205 | 9735 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 9736 | { |
c19d1205 | 9737 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
9738 | } |
9739 | ||
9740 | static void | |
c19d1205 | 9741 | do_vfp_xp_ldstmia (void) |
e16bb312 | 9742 | { |
c19d1205 ZW |
9743 | vfp_dp_ldstm (VFP_LDSTMIAX); |
9744 | } | |
e16bb312 | 9745 | |
c19d1205 ZW |
9746 | static void |
9747 | do_vfp_xp_ldstmdb (void) | |
9748 | { | |
9749 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 9750 | } |
5287ad62 JB |
9751 | |
9752 | static void | |
9753 | do_vfp_dp_rd_rm (void) | |
9754 | { | |
9755 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9756 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
9757 | } | |
9758 | ||
9759 | static void | |
9760 | do_vfp_dp_rn_rd (void) | |
9761 | { | |
9762 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
9763 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
9764 | } | |
9765 | ||
9766 | static void | |
9767 | do_vfp_dp_rd_rn (void) | |
9768 | { | |
9769 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9770 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
9771 | } | |
9772 | ||
9773 | static void | |
9774 | do_vfp_dp_rd_rn_rm (void) | |
9775 | { | |
9776 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9777 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
9778 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
9779 | } | |
9780 | ||
9781 | static void | |
9782 | do_vfp_dp_rd (void) | |
9783 | { | |
9784 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9785 | } | |
9786 | ||
9787 | static void | |
9788 | do_vfp_dp_rm_rd_rn (void) | |
9789 | { | |
9790 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
9791 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
9792 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
9793 | } | |
9794 | ||
9795 | /* VFPv3 instructions. */ | |
9796 | static void | |
9797 | do_vfp_sp_const (void) | |
9798 | { | |
9799 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
9800 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9801 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9802 | } |
9803 | ||
9804 | static void | |
9805 | do_vfp_dp_const (void) | |
9806 | { | |
9807 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
9808 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9809 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9810 | } |
9811 | ||
9812 | static void | |
9813 | vfp_conv (int srcsize) | |
9814 | { | |
5f1af56b MGD |
9815 | int immbits = srcsize - inst.operands[1].imm; |
9816 | ||
fa94de6b RM |
9817 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
9818 | { | |
5f1af56b | 9819 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
477330fc | 9820 | i.e. immbits must be in range 0 - 16. */ |
5f1af56b MGD |
9821 | inst.error = _("immediate value out of range, expected range [0, 16]"); |
9822 | return; | |
9823 | } | |
fa94de6b | 9824 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
9825 | { |
9826 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
477330fc | 9827 | i.e. immbits must be in range 0 - 31. */ |
5f1af56b MGD |
9828 | inst.error = _("immediate value out of range, expected range [1, 32]"); |
9829 | return; | |
9830 | } | |
9831 | ||
5287ad62 JB |
9832 | inst.instruction |= (immbits & 1) << 5; |
9833 | inst.instruction |= (immbits >> 1); | |
9834 | } | |
9835 | ||
9836 | static void | |
9837 | do_vfp_sp_conv_16 (void) | |
9838 | { | |
9839 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
9840 | vfp_conv (16); | |
9841 | } | |
9842 | ||
9843 | static void | |
9844 | do_vfp_dp_conv_16 (void) | |
9845 | { | |
9846 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9847 | vfp_conv (16); | |
9848 | } | |
9849 | ||
9850 | static void | |
9851 | do_vfp_sp_conv_32 (void) | |
9852 | { | |
9853 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
9854 | vfp_conv (32); | |
9855 | } | |
9856 | ||
9857 | static void | |
9858 | do_vfp_dp_conv_32 (void) | |
9859 | { | |
9860 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9861 | vfp_conv (32); | |
9862 | } | |
c19d1205 ZW |
9863 | \f |
9864 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 9865 | |
c19d1205 ZW |
9866 | static void |
9867 | do_fpa_cmp (void) | |
9868 | { | |
9869 | inst.instruction |= inst.operands[0].reg << 16; | |
9870 | inst.instruction |= inst.operands[1].reg; | |
9871 | } | |
b99bd4ef NC |
9872 | |
9873 | static void | |
c19d1205 | 9874 | do_fpa_ldmstm (void) |
b99bd4ef | 9875 | { |
c19d1205 ZW |
9876 | inst.instruction |= inst.operands[0].reg << 12; |
9877 | switch (inst.operands[1].imm) | |
9878 | { | |
9879 | case 1: inst.instruction |= CP_T_X; break; | |
9880 | case 2: inst.instruction |= CP_T_Y; break; | |
9881 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
9882 | case 4: break; | |
9883 | default: abort (); | |
9884 | } | |
b99bd4ef | 9885 | |
c19d1205 ZW |
9886 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
9887 | { | |
9888 | /* The instruction specified "ea" or "fd", so we can only accept | |
9889 | [Rn]{!}. The instruction does not really support stacking or | |
9890 | unstacking, so we have to emulate these by setting appropriate | |
9891 | bits and offsets. */ | |
9892 | constraint (inst.reloc.exp.X_op != O_constant | |
9893 | || inst.reloc.exp.X_add_number != 0, | |
9894 | _("this instruction does not support indexing")); | |
b99bd4ef | 9895 | |
c19d1205 ZW |
9896 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
9897 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 9898 | |
c19d1205 ZW |
9899 | if (!(inst.instruction & INDEX_UP)) |
9900 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 9901 | |
c19d1205 ZW |
9902 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
9903 | { | |
9904 | inst.operands[2].preind = 0; | |
9905 | inst.operands[2].postind = 1; | |
9906 | } | |
9907 | } | |
b99bd4ef | 9908 | |
c19d1205 | 9909 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 9910 | } |
c19d1205 ZW |
9911 | \f |
9912 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 9913 | |
c19d1205 ZW |
9914 | static void |
9915 | do_iwmmxt_tandorc (void) | |
9916 | { | |
9917 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
9918 | } | |
b99bd4ef | 9919 | |
c19d1205 ZW |
9920 | static void |
9921 | do_iwmmxt_textrc (void) | |
9922 | { | |
9923 | inst.instruction |= inst.operands[0].reg << 12; | |
9924 | inst.instruction |= inst.operands[1].imm; | |
9925 | } | |
b99bd4ef NC |
9926 | |
9927 | static void | |
c19d1205 | 9928 | do_iwmmxt_textrm (void) |
b99bd4ef | 9929 | { |
c19d1205 ZW |
9930 | inst.instruction |= inst.operands[0].reg << 12; |
9931 | inst.instruction |= inst.operands[1].reg << 16; | |
9932 | inst.instruction |= inst.operands[2].imm; | |
9933 | } | |
b99bd4ef | 9934 | |
c19d1205 ZW |
9935 | static void |
9936 | do_iwmmxt_tinsr (void) | |
9937 | { | |
9938 | inst.instruction |= inst.operands[0].reg << 16; | |
9939 | inst.instruction |= inst.operands[1].reg << 12; | |
9940 | inst.instruction |= inst.operands[2].imm; | |
9941 | } | |
b99bd4ef | 9942 | |
c19d1205 ZW |
9943 | static void |
9944 | do_iwmmxt_tmia (void) | |
9945 | { | |
9946 | inst.instruction |= inst.operands[0].reg << 5; | |
9947 | inst.instruction |= inst.operands[1].reg; | |
9948 | inst.instruction |= inst.operands[2].reg << 12; | |
9949 | } | |
b99bd4ef | 9950 | |
c19d1205 ZW |
9951 | static void |
9952 | do_iwmmxt_waligni (void) | |
9953 | { | |
9954 | inst.instruction |= inst.operands[0].reg << 12; | |
9955 | inst.instruction |= inst.operands[1].reg << 16; | |
9956 | inst.instruction |= inst.operands[2].reg; | |
9957 | inst.instruction |= inst.operands[3].imm << 20; | |
9958 | } | |
b99bd4ef | 9959 | |
2d447fca JM |
9960 | static void |
9961 | do_iwmmxt_wmerge (void) | |
9962 | { | |
9963 | inst.instruction |= inst.operands[0].reg << 12; | |
9964 | inst.instruction |= inst.operands[1].reg << 16; | |
9965 | inst.instruction |= inst.operands[2].reg; | |
9966 | inst.instruction |= inst.operands[3].imm << 21; | |
9967 | } | |
9968 | ||
c19d1205 ZW |
9969 | static void |
9970 | do_iwmmxt_wmov (void) | |
9971 | { | |
9972 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
9973 | inst.instruction |= inst.operands[0].reg << 12; | |
9974 | inst.instruction |= inst.operands[1].reg << 16; | |
9975 | inst.instruction |= inst.operands[1].reg; | |
9976 | } | |
b99bd4ef | 9977 | |
c19d1205 ZW |
9978 | static void |
9979 | do_iwmmxt_wldstbh (void) | |
9980 | { | |
8f06b2d8 | 9981 | int reloc; |
c19d1205 | 9982 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
9983 | if (thumb_mode) |
9984 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
9985 | else | |
9986 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
9987 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
9988 | } |
9989 | ||
c19d1205 ZW |
9990 | static void |
9991 | do_iwmmxt_wldstw (void) | |
9992 | { | |
9993 | /* RIWR_RIWC clears .isreg for a control register. */ | |
9994 | if (!inst.operands[0].isreg) | |
9995 | { | |
9996 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
9997 | inst.instruction |= 0xf0000000; | |
9998 | } | |
b99bd4ef | 9999 | |
c19d1205 ZW |
10000 | inst.instruction |= inst.operands[0].reg << 12; |
10001 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
10002 | } | |
b99bd4ef NC |
10003 | |
10004 | static void | |
c19d1205 | 10005 | do_iwmmxt_wldstd (void) |
b99bd4ef | 10006 | { |
c19d1205 | 10007 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
10008 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
10009 | && inst.operands[1].immisreg) | |
10010 | { | |
10011 | inst.instruction &= ~0x1a000ff; | |
eff0bc54 | 10012 | inst.instruction |= (0xfU << 28); |
2d447fca JM |
10013 | if (inst.operands[1].preind) |
10014 | inst.instruction |= PRE_INDEX; | |
10015 | if (!inst.operands[1].negative) | |
10016 | inst.instruction |= INDEX_UP; | |
10017 | if (inst.operands[1].writeback) | |
10018 | inst.instruction |= WRITE_BACK; | |
10019 | inst.instruction |= inst.operands[1].reg << 16; | |
10020 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
10021 | inst.instruction |= inst.operands[1].imm; | |
10022 | } | |
10023 | else | |
10024 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 10025 | } |
b99bd4ef | 10026 | |
c19d1205 ZW |
10027 | static void |
10028 | do_iwmmxt_wshufh (void) | |
10029 | { | |
10030 | inst.instruction |= inst.operands[0].reg << 12; | |
10031 | inst.instruction |= inst.operands[1].reg << 16; | |
10032 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
10033 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
10034 | } | |
b99bd4ef | 10035 | |
c19d1205 ZW |
10036 | static void |
10037 | do_iwmmxt_wzero (void) | |
10038 | { | |
10039 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
10040 | inst.instruction |= inst.operands[0].reg; | |
10041 | inst.instruction |= inst.operands[0].reg << 12; | |
10042 | inst.instruction |= inst.operands[0].reg << 16; | |
10043 | } | |
2d447fca JM |
10044 | |
10045 | static void | |
10046 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
10047 | { | |
10048 | if (inst.operands[2].isreg) | |
10049 | do_rd_rn_rm (); | |
10050 | else { | |
10051 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
10052 | _("immediate operand requires iWMMXt2")); | |
10053 | do_rd_rn (); | |
10054 | if (inst.operands[2].imm == 0) | |
10055 | { | |
10056 | switch ((inst.instruction >> 20) & 0xf) | |
10057 | { | |
10058 | case 4: | |
10059 | case 5: | |
10060 | case 6: | |
5f4273c7 | 10061 | case 7: |
2d447fca JM |
10062 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
10063 | inst.operands[2].imm = 16; | |
10064 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
10065 | break; | |
10066 | case 8: | |
10067 | case 9: | |
10068 | case 10: | |
10069 | case 11: | |
10070 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
10071 | inst.operands[2].imm = 32; | |
10072 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
10073 | break; | |
10074 | case 12: | |
10075 | case 13: | |
10076 | case 14: | |
10077 | case 15: | |
10078 | { | |
10079 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
10080 | unsigned long wrn; | |
10081 | wrn = (inst.instruction >> 16) & 0xf; | |
10082 | inst.instruction &= 0xff0fff0f; | |
10083 | inst.instruction |= wrn; | |
10084 | /* Bail out here; the instruction is now assembled. */ | |
10085 | return; | |
10086 | } | |
10087 | } | |
10088 | } | |
10089 | /* Map 32 -> 0, etc. */ | |
10090 | inst.operands[2].imm &= 0x1f; | |
eff0bc54 | 10091 | inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); |
2d447fca JM |
10092 | } |
10093 | } | |
c19d1205 ZW |
10094 | \f |
10095 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
10096 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 10097 | |
c19d1205 | 10098 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 10099 | |
c19d1205 ZW |
10100 | static void |
10101 | do_mav_triple (void) | |
10102 | { | |
10103 | inst.instruction |= inst.operands[0].reg << 16; | |
10104 | inst.instruction |= inst.operands[1].reg; | |
10105 | inst.instruction |= inst.operands[2].reg << 12; | |
10106 | } | |
b99bd4ef | 10107 | |
c19d1205 ZW |
10108 | /* Insns like "foo W,X,Y,Z". |
10109 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 10110 | |
c19d1205 ZW |
10111 | static void |
10112 | do_mav_quad (void) | |
10113 | { | |
10114 | inst.instruction |= inst.operands[0].reg << 5; | |
10115 | inst.instruction |= inst.operands[1].reg << 12; | |
10116 | inst.instruction |= inst.operands[2].reg << 16; | |
10117 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
10118 | } |
10119 | ||
c19d1205 ZW |
10120 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
10121 | static void | |
10122 | do_mav_dspsc (void) | |
a737bd4d | 10123 | { |
c19d1205 ZW |
10124 | inst.instruction |= inst.operands[1].reg << 12; |
10125 | } | |
a737bd4d | 10126 | |
c19d1205 ZW |
10127 | /* Maverick shift immediate instructions. |
10128 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
10129 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 10130 | |
c19d1205 ZW |
10131 | static void |
10132 | do_mav_shift (void) | |
10133 | { | |
10134 | int imm = inst.operands[2].imm; | |
a737bd4d | 10135 | |
c19d1205 ZW |
10136 | inst.instruction |= inst.operands[0].reg << 12; |
10137 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 10138 | |
c19d1205 ZW |
10139 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
10140 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
10141 | Bit 4 should be 0. */ | |
10142 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 10143 | |
c19d1205 ZW |
10144 | inst.instruction |= imm; |
10145 | } | |
10146 | \f | |
10147 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 10148 | |
c19d1205 ZW |
10149 | /* Xscale multiply-accumulate (argument parse) |
10150 | MIAcc acc0,Rm,Rs | |
10151 | MIAPHcc acc0,Rm,Rs | |
10152 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 10153 | |
c19d1205 ZW |
10154 | static void |
10155 | do_xsc_mia (void) | |
10156 | { | |
10157 | inst.instruction |= inst.operands[1].reg; | |
10158 | inst.instruction |= inst.operands[2].reg << 12; | |
10159 | } | |
a737bd4d | 10160 | |
c19d1205 | 10161 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 10162 | |
c19d1205 | 10163 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 10164 | |
c19d1205 ZW |
10165 | static void |
10166 | do_xsc_mar (void) | |
10167 | { | |
10168 | inst.instruction |= inst.operands[1].reg << 12; | |
10169 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10170 | } |
10171 | ||
c19d1205 | 10172 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 10173 | |
c19d1205 | 10174 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
10175 | |
10176 | static void | |
c19d1205 | 10177 | do_xsc_mra (void) |
b99bd4ef | 10178 | { |
c19d1205 ZW |
10179 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
10180 | inst.instruction |= inst.operands[0].reg << 12; | |
10181 | inst.instruction |= inst.operands[1].reg << 16; | |
10182 | } | |
10183 | \f | |
10184 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 10185 | |
c19d1205 ZW |
10186 | /* inst.operands[i] is a shifted-register operand; encode |
10187 | it into inst.instruction in the format used by Thumb32. */ | |
10188 | ||
10189 | static void | |
10190 | encode_thumb32_shifted_operand (int i) | |
10191 | { | |
10192 | unsigned int value = inst.reloc.exp.X_add_number; | |
10193 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 10194 | |
9c3c69f2 PB |
10195 | constraint (inst.operands[i].immisreg, |
10196 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
10197 | inst.instruction |= inst.operands[i].reg; |
10198 | if (shift == SHIFT_RRX) | |
10199 | inst.instruction |= SHIFT_ROR << 4; | |
10200 | else | |
b99bd4ef | 10201 | { |
c19d1205 ZW |
10202 | constraint (inst.reloc.exp.X_op != O_constant, |
10203 | _("expression too complex")); | |
10204 | ||
10205 | constraint (value > 32 | |
10206 | || (value == 32 && (shift == SHIFT_LSL | |
10207 | || shift == SHIFT_ROR)), | |
10208 | _("shift expression is too large")); | |
10209 | ||
10210 | if (value == 0) | |
10211 | shift = SHIFT_LSL; | |
10212 | else if (value == 32) | |
10213 | value = 0; | |
10214 | ||
10215 | inst.instruction |= shift << 4; | |
10216 | inst.instruction |= (value & 0x1c) << 10; | |
10217 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 10218 | } |
c19d1205 | 10219 | } |
b99bd4ef | 10220 | |
b99bd4ef | 10221 | |
c19d1205 ZW |
10222 | /* inst.operands[i] was set up by parse_address. Encode it into a |
10223 | Thumb32 format load or store instruction. Reject forms that cannot | |
10224 | be used with such instructions. If is_t is true, reject forms that | |
10225 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
10226 | that cannot be used with a D instruction. If it is a store insn, |
10227 | reject PC in Rn. */ | |
b99bd4ef | 10228 | |
c19d1205 ZW |
10229 | static void |
10230 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
10231 | { | |
5be8be5d | 10232 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
10233 | |
10234 | constraint (!inst.operands[i].isreg, | |
53365c0d | 10235 | _("Instruction does not support =N addresses")); |
b99bd4ef | 10236 | |
c19d1205 ZW |
10237 | inst.instruction |= inst.operands[i].reg << 16; |
10238 | if (inst.operands[i].immisreg) | |
b99bd4ef | 10239 | { |
5be8be5d | 10240 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
10241 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
10242 | constraint (inst.operands[i].negative, | |
10243 | _("Thumb does not support negative register indexing")); | |
10244 | constraint (inst.operands[i].postind, | |
10245 | _("Thumb does not support register post-indexing")); | |
10246 | constraint (inst.operands[i].writeback, | |
10247 | _("Thumb does not support register indexing with writeback")); | |
10248 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
10249 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 10250 | |
f40d1643 | 10251 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 10252 | if (inst.operands[i].shifted) |
b99bd4ef | 10253 | { |
c19d1205 ZW |
10254 | constraint (inst.reloc.exp.X_op != O_constant, |
10255 | _("expression too complex")); | |
9c3c69f2 PB |
10256 | constraint (inst.reloc.exp.X_add_number < 0 |
10257 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 10258 | _("shift out of range")); |
9c3c69f2 | 10259 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
10260 | } |
10261 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10262 | } | |
10263 | else if (inst.operands[i].preind) | |
10264 | { | |
5be8be5d | 10265 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 10266 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 10267 | _("cannot use writeback with this instruction")); |
4755303e WN |
10268 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0), |
10269 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
10270 | |
10271 | if (is_d) | |
10272 | { | |
10273 | inst.instruction |= 0x01000000; | |
10274 | if (inst.operands[i].writeback) | |
10275 | inst.instruction |= 0x00200000; | |
b99bd4ef | 10276 | } |
c19d1205 | 10277 | else |
b99bd4ef | 10278 | { |
c19d1205 ZW |
10279 | inst.instruction |= 0x00000c00; |
10280 | if (inst.operands[i].writeback) | |
10281 | inst.instruction |= 0x00000100; | |
b99bd4ef | 10282 | } |
c19d1205 | 10283 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 10284 | } |
c19d1205 | 10285 | else if (inst.operands[i].postind) |
b99bd4ef | 10286 | { |
9c2799c2 | 10287 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
10288 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
10289 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
10290 | ||
10291 | if (is_d) | |
10292 | inst.instruction |= 0x00200000; | |
10293 | else | |
10294 | inst.instruction |= 0x00000900; | |
10295 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
10296 | } | |
10297 | else /* unindexed - only for coprocessor */ | |
10298 | inst.error = _("instruction does not accept unindexed addressing"); | |
10299 | } | |
10300 | ||
10301 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
10302 | encodings (the latter only in post-V6T2 cores). The index is the | |
10303 | value used in the insns table below. When there is more than one | |
10304 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
10305 | holds variant (1). |
10306 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 10307 | #define T16_32_TAB \ |
21d799b5 NC |
10308 | X(_adc, 4140, eb400000), \ |
10309 | X(_adcs, 4140, eb500000), \ | |
10310 | X(_add, 1c00, eb000000), \ | |
10311 | X(_adds, 1c00, eb100000), \ | |
10312 | X(_addi, 0000, f1000000), \ | |
10313 | X(_addis, 0000, f1100000), \ | |
10314 | X(_add_pc,000f, f20f0000), \ | |
10315 | X(_add_sp,000d, f10d0000), \ | |
10316 | X(_adr, 000f, f20f0000), \ | |
10317 | X(_and, 4000, ea000000), \ | |
10318 | X(_ands, 4000, ea100000), \ | |
10319 | X(_asr, 1000, fa40f000), \ | |
10320 | X(_asrs, 1000, fa50f000), \ | |
10321 | X(_b, e000, f000b000), \ | |
10322 | X(_bcond, d000, f0008000), \ | |
10323 | X(_bic, 4380, ea200000), \ | |
10324 | X(_bics, 4380, ea300000), \ | |
10325 | X(_cmn, 42c0, eb100f00), \ | |
10326 | X(_cmp, 2800, ebb00f00), \ | |
10327 | X(_cpsie, b660, f3af8400), \ | |
10328 | X(_cpsid, b670, f3af8600), \ | |
10329 | X(_cpy, 4600, ea4f0000), \ | |
10330 | X(_dec_sp,80dd, f1ad0d00), \ | |
10331 | X(_eor, 4040, ea800000), \ | |
10332 | X(_eors, 4040, ea900000), \ | |
10333 | X(_inc_sp,00dd, f10d0d00), \ | |
10334 | X(_ldmia, c800, e8900000), \ | |
10335 | X(_ldr, 6800, f8500000), \ | |
10336 | X(_ldrb, 7800, f8100000), \ | |
10337 | X(_ldrh, 8800, f8300000), \ | |
10338 | X(_ldrsb, 5600, f9100000), \ | |
10339 | X(_ldrsh, 5e00, f9300000), \ | |
10340 | X(_ldr_pc,4800, f85f0000), \ | |
10341 | X(_ldr_pc2,4800, f85f0000), \ | |
10342 | X(_ldr_sp,9800, f85d0000), \ | |
10343 | X(_lsl, 0000, fa00f000), \ | |
10344 | X(_lsls, 0000, fa10f000), \ | |
10345 | X(_lsr, 0800, fa20f000), \ | |
10346 | X(_lsrs, 0800, fa30f000), \ | |
10347 | X(_mov, 2000, ea4f0000), \ | |
10348 | X(_movs, 2000, ea5f0000), \ | |
10349 | X(_mul, 4340, fb00f000), \ | |
10350 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
10351 | X(_mvn, 43c0, ea6f0000), \ | |
10352 | X(_mvns, 43c0, ea7f0000), \ | |
10353 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
10354 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
10355 | X(_orr, 4300, ea400000), \ | |
10356 | X(_orrs, 4300, ea500000), \ | |
10357 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
10358 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
10359 | X(_rev, ba00, fa90f080), \ | |
10360 | X(_rev16, ba40, fa90f090), \ | |
10361 | X(_revsh, bac0, fa90f0b0), \ | |
10362 | X(_ror, 41c0, fa60f000), \ | |
10363 | X(_rors, 41c0, fa70f000), \ | |
10364 | X(_sbc, 4180, eb600000), \ | |
10365 | X(_sbcs, 4180, eb700000), \ | |
10366 | X(_stmia, c000, e8800000), \ | |
10367 | X(_str, 6000, f8400000), \ | |
10368 | X(_strb, 7000, f8000000), \ | |
10369 | X(_strh, 8000, f8200000), \ | |
10370 | X(_str_sp,9000, f84d0000), \ | |
10371 | X(_sub, 1e00, eba00000), \ | |
10372 | X(_subs, 1e00, ebb00000), \ | |
10373 | X(_subi, 8000, f1a00000), \ | |
10374 | X(_subis, 8000, f1b00000), \ | |
10375 | X(_sxtb, b240, fa4ff080), \ | |
10376 | X(_sxth, b200, fa0ff080), \ | |
10377 | X(_tst, 4200, ea100f00), \ | |
10378 | X(_uxtb, b2c0, fa5ff080), \ | |
10379 | X(_uxth, b280, fa1ff080), \ | |
10380 | X(_nop, bf00, f3af8000), \ | |
10381 | X(_yield, bf10, f3af8001), \ | |
10382 | X(_wfe, bf20, f3af8002), \ | |
10383 | X(_wfi, bf30, f3af8003), \ | |
53c4b28b | 10384 | X(_sev, bf40, f3af8004), \ |
74db7efb NC |
10385 | X(_sevl, bf50, f3af8005), \ |
10386 | X(_udf, de00, f7f0a000) | |
c19d1205 ZW |
10387 | |
10388 | /* To catch errors in encoding functions, the codes are all offset by | |
10389 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
10390 | as 16-bit instructions. */ | |
21d799b5 | 10391 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
10392 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
10393 | #undef X | |
10394 | ||
10395 | #define X(a,b,c) 0x##b | |
10396 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
10397 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
10398 | #undef X | |
10399 | ||
10400 | #define X(a,b,c) 0x##c | |
10401 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
10402 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
10403 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
10404 | #undef X |
10405 | #undef T16_32_TAB | |
10406 | ||
10407 | /* Thumb instruction encoders, in alphabetical order. */ | |
10408 | ||
92e90b6e | 10409 | /* ADDW or SUBW. */ |
c921be7d | 10410 | |
92e90b6e PB |
10411 | static void |
10412 | do_t_add_sub_w (void) | |
10413 | { | |
10414 | int Rd, Rn; | |
10415 | ||
10416 | Rd = inst.operands[0].reg; | |
10417 | Rn = inst.operands[1].reg; | |
10418 | ||
539d4391 NC |
10419 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
10420 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
10421 | if (Rn == REG_SP) | |
10422 | constraint (Rd == REG_PC, BAD_PC); | |
10423 | else | |
10424 | reject_bad_reg (Rd); | |
fdfde340 | 10425 | |
92e90b6e PB |
10426 | inst.instruction |= (Rn << 16) | (Rd << 8); |
10427 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
10428 | } | |
10429 | ||
c19d1205 ZW |
10430 | /* Parse an add or subtract instruction. We get here with inst.instruction |
10431 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
10432 | ||
10433 | static void | |
10434 | do_t_add_sub (void) | |
10435 | { | |
10436 | int Rd, Rs, Rn; | |
10437 | ||
10438 | Rd = inst.operands[0].reg; | |
10439 | Rs = (inst.operands[1].present | |
10440 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10441 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10442 | ||
e07e6e58 NC |
10443 | if (Rd == REG_PC) |
10444 | set_it_insn_type_last (); | |
10445 | ||
c19d1205 ZW |
10446 | if (unified_syntax) |
10447 | { | |
0110f2b8 PB |
10448 | bfd_boolean flags; |
10449 | bfd_boolean narrow; | |
10450 | int opcode; | |
10451 | ||
10452 | flags = (inst.instruction == T_MNEM_adds | |
10453 | || inst.instruction == T_MNEM_subs); | |
10454 | if (flags) | |
e07e6e58 | 10455 | narrow = !in_it_block (); |
0110f2b8 | 10456 | else |
e07e6e58 | 10457 | narrow = in_it_block (); |
c19d1205 | 10458 | if (!inst.operands[2].isreg) |
b99bd4ef | 10459 | { |
16805f35 PB |
10460 | int add; |
10461 | ||
fdfde340 JM |
10462 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
10463 | ||
16805f35 PB |
10464 | add = (inst.instruction == T_MNEM_add |
10465 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
10466 | opcode = 0; |
10467 | if (inst.size_req != 4) | |
10468 | { | |
0110f2b8 | 10469 | /* Attempt to use a narrow opcode, with relaxation if |
477330fc | 10470 | appropriate. */ |
0110f2b8 PB |
10471 | if (Rd == REG_SP && Rs == REG_SP && !flags) |
10472 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
10473 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
10474 | opcode = T_MNEM_add_sp; | |
10475 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
10476 | opcode = T_MNEM_add_pc; | |
10477 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
10478 | { | |
10479 | if (flags) | |
10480 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
10481 | else | |
10482 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
10483 | } | |
10484 | if (opcode) | |
10485 | { | |
10486 | inst.instruction = THUMB_OP16(opcode); | |
10487 | inst.instruction |= (Rd << 4) | Rs; | |
72d98d16 MG |
10488 | if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
10489 | || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
a9f02af8 MG |
10490 | { |
10491 | if (inst.size_req == 2) | |
10492 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
10493 | else | |
10494 | inst.relax = opcode; | |
10495 | } | |
0110f2b8 PB |
10496 | } |
10497 | else | |
10498 | constraint (inst.size_req == 2, BAD_HIREG); | |
10499 | } | |
10500 | if (inst.size_req == 4 | |
10501 | || (inst.size_req != 2 && !opcode)) | |
10502 | { | |
a9f02af8 MG |
10503 | constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
10504 | && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
10505 | THUMB1_RELOC_ONLY); | |
efd81785 PB |
10506 | if (Rd == REG_PC) |
10507 | { | |
fdfde340 | 10508 | constraint (add, BAD_PC); |
efd81785 PB |
10509 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
10510 | _("only SUBS PC, LR, #const allowed")); | |
10511 | constraint (inst.reloc.exp.X_op != O_constant, | |
10512 | _("expression too complex")); | |
10513 | constraint (inst.reloc.exp.X_add_number < 0 | |
10514 | || inst.reloc.exp.X_add_number > 0xff, | |
10515 | _("immediate value out of range")); | |
10516 | inst.instruction = T2_SUBS_PC_LR | |
10517 | | inst.reloc.exp.X_add_number; | |
10518 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10519 | return; | |
10520 | } | |
10521 | else if (Rs == REG_PC) | |
16805f35 PB |
10522 | { |
10523 | /* Always use addw/subw. */ | |
10524 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
10525 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
10526 | } | |
10527 | else | |
10528 | { | |
10529 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10530 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
10531 | | 0x10000000; | |
10532 | if (flags) | |
10533 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10534 | else | |
10535 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
10536 | } | |
dc4503c6 PB |
10537 | inst.instruction |= Rd << 8; |
10538 | inst.instruction |= Rs << 16; | |
0110f2b8 | 10539 | } |
b99bd4ef | 10540 | } |
c19d1205 ZW |
10541 | else |
10542 | { | |
5f4cb198 NC |
10543 | unsigned int value = inst.reloc.exp.X_add_number; |
10544 | unsigned int shift = inst.operands[2].shift_kind; | |
10545 | ||
c19d1205 ZW |
10546 | Rn = inst.operands[2].reg; |
10547 | /* See if we can do this with a 16-bit instruction. */ | |
10548 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
10549 | { | |
e27ec89e PB |
10550 | if (Rd > 7 || Rs > 7 || Rn > 7) |
10551 | narrow = FALSE; | |
10552 | ||
10553 | if (narrow) | |
c19d1205 | 10554 | { |
e27ec89e PB |
10555 | inst.instruction = ((inst.instruction == T_MNEM_adds |
10556 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
10557 | ? T_OPCODE_ADD_R3 |
10558 | : T_OPCODE_SUB_R3); | |
10559 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
10560 | return; | |
10561 | } | |
b99bd4ef | 10562 | |
7e806470 | 10563 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 10564 | { |
7e806470 PB |
10565 | /* Thumb-1 cores (except v6-M) require at least one high |
10566 | register in a narrow non flag setting add. */ | |
10567 | if (Rd > 7 || Rn > 7 | |
10568 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
10569 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 10570 | { |
7e806470 PB |
10571 | if (Rd == Rn) |
10572 | { | |
10573 | Rn = Rs; | |
10574 | Rs = Rd; | |
10575 | } | |
c19d1205 ZW |
10576 | inst.instruction = T_OPCODE_ADD_HI; |
10577 | inst.instruction |= (Rd & 8) << 4; | |
10578 | inst.instruction |= (Rd & 7); | |
10579 | inst.instruction |= Rn << 3; | |
10580 | return; | |
10581 | } | |
c19d1205 ZW |
10582 | } |
10583 | } | |
c921be7d | 10584 | |
fdfde340 JM |
10585 | constraint (Rd == REG_PC, BAD_PC); |
10586 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
10587 | constraint (Rs == REG_PC, BAD_PC); | |
10588 | reject_bad_reg (Rn); | |
10589 | ||
c19d1205 ZW |
10590 | /* If we get here, it can't be done in 16 bits. */ |
10591 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
10592 | _("shift must be constant")); | |
10593 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10594 | inst.instruction |= Rd << 8; | |
10595 | inst.instruction |= Rs << 16; | |
5f4cb198 NC |
10596 | constraint (Rd == REG_SP && Rs == REG_SP && value > 3, |
10597 | _("shift value over 3 not allowed in thumb mode")); | |
10598 | constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL, | |
10599 | _("only LSL shift allowed in thumb mode")); | |
c19d1205 ZW |
10600 | encode_thumb32_shifted_operand (2); |
10601 | } | |
10602 | } | |
10603 | else | |
10604 | { | |
10605 | constraint (inst.instruction == T_MNEM_adds | |
10606 | || inst.instruction == T_MNEM_subs, | |
10607 | BAD_THUMB32); | |
b99bd4ef | 10608 | |
c19d1205 | 10609 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 10610 | { |
c19d1205 ZW |
10611 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
10612 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
10613 | BAD_HIREG); | |
10614 | ||
10615 | inst.instruction = (inst.instruction == T_MNEM_add | |
10616 | ? 0x0000 : 0x8000); | |
10617 | inst.instruction |= (Rd << 4) | Rs; | |
10618 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
10619 | return; |
10620 | } | |
10621 | ||
c19d1205 ZW |
10622 | Rn = inst.operands[2].reg; |
10623 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 10624 | |
c19d1205 ZW |
10625 | /* We now have Rd, Rs, and Rn set to registers. */ |
10626 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 10627 | { |
c19d1205 ZW |
10628 | /* Can't do this for SUB. */ |
10629 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
10630 | inst.instruction = T_OPCODE_ADD_HI; | |
10631 | inst.instruction |= (Rd & 8) << 4; | |
10632 | inst.instruction |= (Rd & 7); | |
10633 | if (Rs == Rd) | |
10634 | inst.instruction |= Rn << 3; | |
10635 | else if (Rn == Rd) | |
10636 | inst.instruction |= Rs << 3; | |
10637 | else | |
10638 | constraint (1, _("dest must overlap one source register")); | |
10639 | } | |
10640 | else | |
10641 | { | |
10642 | inst.instruction = (inst.instruction == T_MNEM_add | |
10643 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
10644 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 10645 | } |
b99bd4ef | 10646 | } |
b99bd4ef NC |
10647 | } |
10648 | ||
c19d1205 ZW |
10649 | static void |
10650 | do_t_adr (void) | |
10651 | { | |
fdfde340 JM |
10652 | unsigned Rd; |
10653 | ||
10654 | Rd = inst.operands[0].reg; | |
10655 | reject_bad_reg (Rd); | |
10656 | ||
10657 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
10658 | { |
10659 | /* Defer to section relaxation. */ | |
10660 | inst.relax = inst.instruction; | |
10661 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 10662 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
10663 | } |
10664 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 10665 | { |
0110f2b8 | 10666 | /* Generate a 32-bit opcode. */ |
e9f89963 | 10667 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 10668 | inst.instruction |= Rd << 8; |
e9f89963 PB |
10669 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
10670 | inst.reloc.pc_rel = 1; | |
10671 | } | |
10672 | else | |
10673 | { | |
0110f2b8 | 10674 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
10675 | inst.instruction = THUMB_OP16 (inst.instruction); |
10676 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
10677 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
10678 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 10679 | |
fdfde340 | 10680 | inst.instruction |= Rd << 4; |
e9f89963 | 10681 | } |
c19d1205 | 10682 | } |
b99bd4ef | 10683 | |
c19d1205 ZW |
10684 | /* Arithmetic instructions for which there is just one 16-bit |
10685 | instruction encoding, and it allows only two low registers. | |
10686 | For maximal compatibility with ARM syntax, we allow three register | |
10687 | operands even when Thumb-32 instructions are not available, as long | |
10688 | as the first two are identical. For instance, both "sbc r0,r1" and | |
10689 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 10690 | static void |
c19d1205 | 10691 | do_t_arit3 (void) |
b99bd4ef | 10692 | { |
c19d1205 | 10693 | int Rd, Rs, Rn; |
b99bd4ef | 10694 | |
c19d1205 ZW |
10695 | Rd = inst.operands[0].reg; |
10696 | Rs = (inst.operands[1].present | |
10697 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10698 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10699 | Rn = inst.operands[2].reg; | |
b99bd4ef | 10700 | |
fdfde340 JM |
10701 | reject_bad_reg (Rd); |
10702 | reject_bad_reg (Rs); | |
10703 | if (inst.operands[2].isreg) | |
10704 | reject_bad_reg (Rn); | |
10705 | ||
c19d1205 | 10706 | if (unified_syntax) |
b99bd4ef | 10707 | { |
c19d1205 ZW |
10708 | if (!inst.operands[2].isreg) |
10709 | { | |
10710 | /* For an immediate, we always generate a 32-bit opcode; | |
10711 | section relaxation will shrink it later if possible. */ | |
10712 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10713 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10714 | inst.instruction |= Rd << 8; | |
10715 | inst.instruction |= Rs << 16; | |
10716 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10717 | } | |
10718 | else | |
10719 | { | |
e27ec89e PB |
10720 | bfd_boolean narrow; |
10721 | ||
c19d1205 | 10722 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 10723 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 10724 | narrow = !in_it_block (); |
e27ec89e | 10725 | else |
e07e6e58 | 10726 | narrow = in_it_block (); |
e27ec89e PB |
10727 | |
10728 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
10729 | narrow = FALSE; | |
10730 | if (inst.operands[2].shifted) | |
10731 | narrow = FALSE; | |
10732 | if (inst.size_req == 4) | |
10733 | narrow = FALSE; | |
10734 | ||
10735 | if (narrow | |
c19d1205 ZW |
10736 | && Rd == Rs) |
10737 | { | |
10738 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10739 | inst.instruction |= Rd; | |
10740 | inst.instruction |= Rn << 3; | |
10741 | return; | |
10742 | } | |
b99bd4ef | 10743 | |
c19d1205 ZW |
10744 | /* If we get here, it can't be done in 16 bits. */ |
10745 | constraint (inst.operands[2].shifted | |
10746 | && inst.operands[2].immisreg, | |
10747 | _("shift must be constant")); | |
10748 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10749 | inst.instruction |= Rd << 8; | |
10750 | inst.instruction |= Rs << 16; | |
10751 | encode_thumb32_shifted_operand (2); | |
10752 | } | |
a737bd4d | 10753 | } |
c19d1205 | 10754 | else |
b99bd4ef | 10755 | { |
c19d1205 ZW |
10756 | /* On its face this is a lie - the instruction does set the |
10757 | flags. However, the only supported mnemonic in this mode | |
10758 | says it doesn't. */ | |
10759 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 10760 | |
c19d1205 ZW |
10761 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
10762 | _("unshifted register required")); | |
10763 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
10764 | constraint (Rd != Rs, | |
10765 | _("dest and source1 must be the same register")); | |
a737bd4d | 10766 | |
c19d1205 ZW |
10767 | inst.instruction = THUMB_OP16 (inst.instruction); |
10768 | inst.instruction |= Rd; | |
10769 | inst.instruction |= Rn << 3; | |
b99bd4ef | 10770 | } |
a737bd4d | 10771 | } |
b99bd4ef | 10772 | |
c19d1205 ZW |
10773 | /* Similarly, but for instructions where the arithmetic operation is |
10774 | commutative, so we can allow either of them to be different from | |
10775 | the destination operand in a 16-bit instruction. For instance, all | |
10776 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
10777 | accepted. */ | |
10778 | static void | |
10779 | do_t_arit3c (void) | |
a737bd4d | 10780 | { |
c19d1205 | 10781 | int Rd, Rs, Rn; |
b99bd4ef | 10782 | |
c19d1205 ZW |
10783 | Rd = inst.operands[0].reg; |
10784 | Rs = (inst.operands[1].present | |
10785 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10786 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10787 | Rn = inst.operands[2].reg; | |
c921be7d | 10788 | |
fdfde340 JM |
10789 | reject_bad_reg (Rd); |
10790 | reject_bad_reg (Rs); | |
10791 | if (inst.operands[2].isreg) | |
10792 | reject_bad_reg (Rn); | |
a737bd4d | 10793 | |
c19d1205 | 10794 | if (unified_syntax) |
a737bd4d | 10795 | { |
c19d1205 | 10796 | if (!inst.operands[2].isreg) |
b99bd4ef | 10797 | { |
c19d1205 ZW |
10798 | /* For an immediate, we always generate a 32-bit opcode; |
10799 | section relaxation will shrink it later if possible. */ | |
10800 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10801 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10802 | inst.instruction |= Rd << 8; | |
10803 | inst.instruction |= Rs << 16; | |
10804 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 10805 | } |
c19d1205 | 10806 | else |
a737bd4d | 10807 | { |
e27ec89e PB |
10808 | bfd_boolean narrow; |
10809 | ||
c19d1205 | 10810 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 10811 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 10812 | narrow = !in_it_block (); |
e27ec89e | 10813 | else |
e07e6e58 | 10814 | narrow = in_it_block (); |
e27ec89e PB |
10815 | |
10816 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
10817 | narrow = FALSE; | |
10818 | if (inst.operands[2].shifted) | |
10819 | narrow = FALSE; | |
10820 | if (inst.size_req == 4) | |
10821 | narrow = FALSE; | |
10822 | ||
10823 | if (narrow) | |
a737bd4d | 10824 | { |
c19d1205 | 10825 | if (Rd == Rs) |
a737bd4d | 10826 | { |
c19d1205 ZW |
10827 | inst.instruction = THUMB_OP16 (inst.instruction); |
10828 | inst.instruction |= Rd; | |
10829 | inst.instruction |= Rn << 3; | |
10830 | return; | |
a737bd4d | 10831 | } |
c19d1205 | 10832 | if (Rd == Rn) |
a737bd4d | 10833 | { |
c19d1205 ZW |
10834 | inst.instruction = THUMB_OP16 (inst.instruction); |
10835 | inst.instruction |= Rd; | |
10836 | inst.instruction |= Rs << 3; | |
10837 | return; | |
a737bd4d NC |
10838 | } |
10839 | } | |
c19d1205 ZW |
10840 | |
10841 | /* If we get here, it can't be done in 16 bits. */ | |
10842 | constraint (inst.operands[2].shifted | |
10843 | && inst.operands[2].immisreg, | |
10844 | _("shift must be constant")); | |
10845 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10846 | inst.instruction |= Rd << 8; | |
10847 | inst.instruction |= Rs << 16; | |
10848 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 10849 | } |
b99bd4ef | 10850 | } |
c19d1205 ZW |
10851 | else |
10852 | { | |
10853 | /* On its face this is a lie - the instruction does set the | |
10854 | flags. However, the only supported mnemonic in this mode | |
10855 | says it doesn't. */ | |
10856 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 10857 | |
c19d1205 ZW |
10858 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
10859 | _("unshifted register required")); | |
10860 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
10861 | ||
10862 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10863 | inst.instruction |= Rd; | |
10864 | ||
10865 | if (Rd == Rs) | |
10866 | inst.instruction |= Rn << 3; | |
10867 | else if (Rd == Rn) | |
10868 | inst.instruction |= Rs << 3; | |
10869 | else | |
10870 | constraint (1, _("dest must overlap one source register")); | |
10871 | } | |
a737bd4d NC |
10872 | } |
10873 | ||
c19d1205 ZW |
10874 | static void |
10875 | do_t_bfc (void) | |
a737bd4d | 10876 | { |
fdfde340 | 10877 | unsigned Rd; |
c19d1205 ZW |
10878 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
10879 | constraint (msb > 32, _("bit-field extends past end of register")); | |
10880 | /* The instruction encoding stores the LSB and MSB, | |
10881 | not the LSB and width. */ | |
fdfde340 JM |
10882 | Rd = inst.operands[0].reg; |
10883 | reject_bad_reg (Rd); | |
10884 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
10885 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
10886 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
10887 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
10888 | } |
10889 | ||
c19d1205 ZW |
10890 | static void |
10891 | do_t_bfi (void) | |
b99bd4ef | 10892 | { |
fdfde340 | 10893 | int Rd, Rn; |
c19d1205 | 10894 | unsigned int msb; |
b99bd4ef | 10895 | |
fdfde340 JM |
10896 | Rd = inst.operands[0].reg; |
10897 | reject_bad_reg (Rd); | |
10898 | ||
c19d1205 ZW |
10899 | /* #0 in second position is alternative syntax for bfc, which is |
10900 | the same instruction but with REG_PC in the Rm field. */ | |
10901 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
10902 | Rn = REG_PC; |
10903 | else | |
10904 | { | |
10905 | Rn = inst.operands[1].reg; | |
10906 | reject_bad_reg (Rn); | |
10907 | } | |
b99bd4ef | 10908 | |
c19d1205 ZW |
10909 | msb = inst.operands[2].imm + inst.operands[3].imm; |
10910 | constraint (msb > 32, _("bit-field extends past end of register")); | |
10911 | /* The instruction encoding stores the LSB and MSB, | |
10912 | not the LSB and width. */ | |
fdfde340 JM |
10913 | inst.instruction |= Rd << 8; |
10914 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
10915 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
10916 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
10917 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
10918 | } |
10919 | ||
c19d1205 ZW |
10920 | static void |
10921 | do_t_bfx (void) | |
b99bd4ef | 10922 | { |
fdfde340 JM |
10923 | unsigned Rd, Rn; |
10924 | ||
10925 | Rd = inst.operands[0].reg; | |
10926 | Rn = inst.operands[1].reg; | |
10927 | ||
10928 | reject_bad_reg (Rd); | |
10929 | reject_bad_reg (Rn); | |
10930 | ||
c19d1205 ZW |
10931 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
10932 | _("bit-field extends past end of register")); | |
fdfde340 JM |
10933 | inst.instruction |= Rd << 8; |
10934 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
10935 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
10936 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
10937 | inst.instruction |= inst.operands[3].imm - 1; | |
10938 | } | |
b99bd4ef | 10939 | |
c19d1205 ZW |
10940 | /* ARM V5 Thumb BLX (argument parse) |
10941 | BLX <target_addr> which is BLX(1) | |
10942 | BLX <Rm> which is BLX(2) | |
10943 | Unfortunately, there are two different opcodes for this mnemonic. | |
10944 | So, the insns[].value is not used, and the code here zaps values | |
10945 | into inst.instruction. | |
b99bd4ef | 10946 | |
c19d1205 ZW |
10947 | ??? How to take advantage of the additional two bits of displacement |
10948 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 10949 | |
c19d1205 ZW |
10950 | static void |
10951 | do_t_blx (void) | |
10952 | { | |
e07e6e58 NC |
10953 | set_it_insn_type_last (); |
10954 | ||
c19d1205 | 10955 | if (inst.operands[0].isreg) |
fdfde340 JM |
10956 | { |
10957 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
10958 | /* We have a register, so this is BLX(2). */ | |
10959 | inst.instruction |= inst.operands[0].reg << 3; | |
10960 | } | |
b99bd4ef NC |
10961 | else |
10962 | { | |
c19d1205 | 10963 | /* No register. This must be BLX(1). */ |
2fc8bdac | 10964 | inst.instruction = 0xf000e800; |
0855e32b | 10965 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
10966 | } |
10967 | } | |
10968 | ||
c19d1205 ZW |
10969 | static void |
10970 | do_t_branch (void) | |
b99bd4ef | 10971 | { |
0110f2b8 | 10972 | int opcode; |
dfa9f0d5 | 10973 | int cond; |
9ae92b05 | 10974 | int reloc; |
dfa9f0d5 | 10975 | |
e07e6e58 NC |
10976 | cond = inst.cond; |
10977 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
10978 | ||
10979 | if (in_it_block ()) | |
dfa9f0d5 PB |
10980 | { |
10981 | /* Conditional branches inside IT blocks are encoded as unconditional | |
477330fc | 10982 | branches. */ |
dfa9f0d5 | 10983 | cond = COND_ALWAYS; |
dfa9f0d5 PB |
10984 | } |
10985 | else | |
10986 | cond = inst.cond; | |
10987 | ||
10988 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
10989 | opcode = T_MNEM_bcond; |
10990 | else | |
10991 | opcode = inst.instruction; | |
10992 | ||
12d6b0b7 RS |
10993 | if (unified_syntax |
10994 | && (inst.size_req == 4 | |
10960bfb PB |
10995 | || (inst.size_req != 2 |
10996 | && (inst.operands[0].hasreloc | |
10997 | || inst.reloc.exp.X_op == O_constant)))) | |
c19d1205 | 10998 | { |
0110f2b8 | 10999 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 11000 | if (cond == COND_ALWAYS) |
9ae92b05 | 11001 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
11002 | else |
11003 | { | |
ff8646ee TP |
11004 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2), |
11005 | _("selected architecture does not support " | |
11006 | "wide conditional branch instruction")); | |
11007 | ||
9c2799c2 | 11008 | gas_assert (cond != 0xF); |
dfa9f0d5 | 11009 | inst.instruction |= cond << 22; |
9ae92b05 | 11010 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
11011 | } |
11012 | } | |
b99bd4ef NC |
11013 | else |
11014 | { | |
0110f2b8 | 11015 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 11016 | if (cond == COND_ALWAYS) |
9ae92b05 | 11017 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 11018 | else |
b99bd4ef | 11019 | { |
dfa9f0d5 | 11020 | inst.instruction |= cond << 8; |
9ae92b05 | 11021 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 11022 | } |
0110f2b8 PB |
11023 | /* Allow section relaxation. */ |
11024 | if (unified_syntax && inst.size_req != 2) | |
11025 | inst.relax = opcode; | |
b99bd4ef | 11026 | } |
9ae92b05 | 11027 | inst.reloc.type = reloc; |
c19d1205 | 11028 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
11029 | } |
11030 | ||
8884b720 | 11031 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 11032 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 11033 | RANGE. */ |
b99bd4ef | 11034 | static void |
8884b720 | 11035 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 11036 | { |
dfa9f0d5 PB |
11037 | constraint (inst.cond != COND_ALWAYS, |
11038 | _("instruction is always unconditional")); | |
c19d1205 | 11039 | if (inst.operands[0].present) |
b99bd4ef | 11040 | { |
8884b720 | 11041 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
11042 | _("immediate value out of range")); |
11043 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 11044 | } |
8884b720 MGD |
11045 | |
11046 | set_it_insn_type (NEUTRAL_IT_INSN); | |
11047 | } | |
11048 | ||
11049 | static void | |
11050 | do_t_hlt (void) | |
11051 | { | |
11052 | do_t_bkpt_hlt1 (63); | |
11053 | } | |
11054 | ||
11055 | static void | |
11056 | do_t_bkpt (void) | |
11057 | { | |
11058 | do_t_bkpt_hlt1 (255); | |
b99bd4ef NC |
11059 | } |
11060 | ||
11061 | static void | |
c19d1205 | 11062 | do_t_branch23 (void) |
b99bd4ef | 11063 | { |
e07e6e58 | 11064 | set_it_insn_type_last (); |
0855e32b | 11065 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 11066 | |
0855e32b NS |
11067 | /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in |
11068 | this file. We used to simply ignore the PLT reloc type here -- | |
11069 | the branch encoding is now needed to deal with TLSCALL relocs. | |
11070 | So if we see a PLT reloc now, put it back to how it used to be to | |
11071 | keep the preexisting behaviour. */ | |
11072 | if (inst.reloc.type == BFD_RELOC_ARM_PLT32) | |
11073 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 11074 | |
4343666d | 11075 | #if defined(OBJ_COFF) |
c19d1205 ZW |
11076 | /* If the destination of the branch is a defined symbol which does not have |
11077 | the THUMB_FUNC attribute, then we must be calling a function which has | |
11078 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
11079 | function and change the branch to refer to that function instead. */ | |
11080 | if ( inst.reloc.exp.X_op == O_symbol | |
11081 | && inst.reloc.exp.X_add_symbol != NULL | |
11082 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
11083 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
11084 | inst.reloc.exp.X_add_symbol = | |
11085 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 11086 | #endif |
90e4755a RE |
11087 | } |
11088 | ||
11089 | static void | |
c19d1205 | 11090 | do_t_bx (void) |
90e4755a | 11091 | { |
e07e6e58 | 11092 | set_it_insn_type_last (); |
c19d1205 ZW |
11093 | inst.instruction |= inst.operands[0].reg << 3; |
11094 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
11095 | should cause the alignment to be checked once it is known. This is | |
11096 | because BX PC only works if the instruction is word aligned. */ | |
11097 | } | |
90e4755a | 11098 | |
c19d1205 ZW |
11099 | static void |
11100 | do_t_bxj (void) | |
11101 | { | |
fdfde340 | 11102 | int Rm; |
90e4755a | 11103 | |
e07e6e58 | 11104 | set_it_insn_type_last (); |
fdfde340 JM |
11105 | Rm = inst.operands[0].reg; |
11106 | reject_bad_reg (Rm); | |
11107 | inst.instruction |= Rm << 16; | |
90e4755a RE |
11108 | } |
11109 | ||
11110 | static void | |
c19d1205 | 11111 | do_t_clz (void) |
90e4755a | 11112 | { |
fdfde340 JM |
11113 | unsigned Rd; |
11114 | unsigned Rm; | |
11115 | ||
11116 | Rd = inst.operands[0].reg; | |
11117 | Rm = inst.operands[1].reg; | |
11118 | ||
11119 | reject_bad_reg (Rd); | |
11120 | reject_bad_reg (Rm); | |
11121 | ||
11122 | inst.instruction |= Rd << 8; | |
11123 | inst.instruction |= Rm << 16; | |
11124 | inst.instruction |= Rm; | |
c19d1205 | 11125 | } |
90e4755a | 11126 | |
dfa9f0d5 PB |
11127 | static void |
11128 | do_t_cps (void) | |
11129 | { | |
e07e6e58 | 11130 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
11131 | inst.instruction |= inst.operands[0].imm; |
11132 | } | |
11133 | ||
c19d1205 ZW |
11134 | static void |
11135 | do_t_cpsi (void) | |
11136 | { | |
e07e6e58 | 11137 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 11138 | if (unified_syntax |
62b3e311 PB |
11139 | && (inst.operands[1].present || inst.size_req == 4) |
11140 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 11141 | { |
c19d1205 ZW |
11142 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
11143 | inst.instruction = 0xf3af8000; | |
11144 | inst.instruction |= imod << 9; | |
11145 | inst.instruction |= inst.operands[0].imm << 5; | |
11146 | if (inst.operands[1].present) | |
11147 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 11148 | } |
c19d1205 | 11149 | else |
90e4755a | 11150 | { |
62b3e311 PB |
11151 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
11152 | && (inst.operands[0].imm & 4), | |
11153 | _("selected processor does not support 'A' form " | |
11154 | "of this instruction")); | |
11155 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
11156 | _("Thumb does not support the 2-argument " |
11157 | "form of this instruction")); | |
11158 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 11159 | } |
90e4755a RE |
11160 | } |
11161 | ||
c19d1205 ZW |
11162 | /* THUMB CPY instruction (argument parse). */ |
11163 | ||
90e4755a | 11164 | static void |
c19d1205 | 11165 | do_t_cpy (void) |
90e4755a | 11166 | { |
c19d1205 | 11167 | if (inst.size_req == 4) |
90e4755a | 11168 | { |
c19d1205 ZW |
11169 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
11170 | inst.instruction |= inst.operands[0].reg << 8; | |
11171 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 11172 | } |
c19d1205 | 11173 | else |
90e4755a | 11174 | { |
c19d1205 ZW |
11175 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
11176 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
11177 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 11178 | } |
90e4755a RE |
11179 | } |
11180 | ||
90e4755a | 11181 | static void |
25fe350b | 11182 | do_t_cbz (void) |
90e4755a | 11183 | { |
e07e6e58 | 11184 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
11185 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11186 | inst.instruction |= inst.operands[0].reg; | |
11187 | inst.reloc.pc_rel = 1; | |
11188 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
11189 | } | |
90e4755a | 11190 | |
62b3e311 PB |
11191 | static void |
11192 | do_t_dbg (void) | |
11193 | { | |
11194 | inst.instruction |= inst.operands[0].imm; | |
11195 | } | |
11196 | ||
11197 | static void | |
11198 | do_t_div (void) | |
11199 | { | |
fdfde340 JM |
11200 | unsigned Rd, Rn, Rm; |
11201 | ||
11202 | Rd = inst.operands[0].reg; | |
11203 | Rn = (inst.operands[1].present | |
11204 | ? inst.operands[1].reg : Rd); | |
11205 | Rm = inst.operands[2].reg; | |
11206 | ||
11207 | reject_bad_reg (Rd); | |
11208 | reject_bad_reg (Rn); | |
11209 | reject_bad_reg (Rm); | |
11210 | ||
11211 | inst.instruction |= Rd << 8; | |
11212 | inst.instruction |= Rn << 16; | |
11213 | inst.instruction |= Rm; | |
62b3e311 PB |
11214 | } |
11215 | ||
c19d1205 ZW |
11216 | static void |
11217 | do_t_hint (void) | |
11218 | { | |
11219 | if (unified_syntax && inst.size_req == 4) | |
11220 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11221 | else | |
11222 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11223 | } | |
90e4755a | 11224 | |
c19d1205 ZW |
11225 | static void |
11226 | do_t_it (void) | |
11227 | { | |
11228 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 11229 | |
e07e6e58 NC |
11230 | set_it_insn_type (IT_INSN); |
11231 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
11232 | now_it.cc = cond; | |
5a01bb1d | 11233 | now_it.warn_deprecated = FALSE; |
e27ec89e PB |
11234 | |
11235 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 11236 | if ((cond & 0x1) == 0x0) |
90e4755a | 11237 | { |
c19d1205 | 11238 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 11239 | |
c19d1205 | 11240 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
11241 | { |
11242 | /* No conversion needed. */ | |
11243 | now_it.block_length = 1; | |
11244 | } | |
c19d1205 | 11245 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
11246 | { |
11247 | mask ^= 0x8; | |
11248 | now_it.block_length = 2; | |
11249 | } | |
e27ec89e | 11250 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
11251 | { |
11252 | mask ^= 0xC; | |
11253 | now_it.block_length = 3; | |
11254 | } | |
c19d1205 | 11255 | else |
5a01bb1d MGD |
11256 | { |
11257 | mask ^= 0xE; | |
11258 | now_it.block_length = 4; | |
11259 | } | |
90e4755a | 11260 | |
e27ec89e PB |
11261 | inst.instruction &= 0xfff0; |
11262 | inst.instruction |= mask; | |
c19d1205 | 11263 | } |
90e4755a | 11264 | |
c19d1205 ZW |
11265 | inst.instruction |= cond << 4; |
11266 | } | |
90e4755a | 11267 | |
3c707909 PB |
11268 | /* Helper function used for both push/pop and ldm/stm. */ |
11269 | static void | |
11270 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
11271 | { | |
11272 | bfd_boolean load; | |
11273 | ||
11274 | load = (inst.instruction & (1 << 20)) != 0; | |
11275 | ||
11276 | if (mask & (1 << 13)) | |
11277 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 NC |
11278 | |
11279 | if ((mask & (1 << base)) != 0 | |
11280 | && writeback) | |
11281 | inst.error = _("having the base register in the register list when " | |
11282 | "using write back is UNPREDICTABLE"); | |
11283 | ||
3c707909 PB |
11284 | if (load) |
11285 | { | |
e07e6e58 | 11286 | if (mask & (1 << 15)) |
477330fc RM |
11287 | { |
11288 | if (mask & (1 << 14)) | |
11289 | inst.error = _("LR and PC should not both be in register list"); | |
11290 | else | |
11291 | set_it_insn_type_last (); | |
11292 | } | |
3c707909 PB |
11293 | } |
11294 | else | |
11295 | { | |
11296 | if (mask & (1 << 15)) | |
11297 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
11298 | } |
11299 | ||
11300 | if ((mask & (mask - 1)) == 0) | |
11301 | { | |
11302 | /* Single register transfers implemented as str/ldr. */ | |
11303 | if (writeback) | |
11304 | { | |
11305 | if (inst.instruction & (1 << 23)) | |
11306 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
11307 | else | |
11308 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
11309 | } | |
11310 | else | |
11311 | { | |
11312 | if (inst.instruction & (1 << 23)) | |
11313 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
11314 | else | |
11315 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
11316 | } | |
11317 | ||
11318 | inst.instruction |= 0xf8400000; | |
11319 | if (load) | |
11320 | inst.instruction |= 0x00100000; | |
11321 | ||
5f4273c7 | 11322 | mask = ffs (mask) - 1; |
3c707909 PB |
11323 | mask <<= 12; |
11324 | } | |
11325 | else if (writeback) | |
11326 | inst.instruction |= WRITE_BACK; | |
11327 | ||
11328 | inst.instruction |= mask; | |
11329 | inst.instruction |= base << 16; | |
11330 | } | |
11331 | ||
c19d1205 ZW |
11332 | static void |
11333 | do_t_ldmstm (void) | |
11334 | { | |
11335 | /* This really doesn't seem worth it. */ | |
11336 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
11337 | _("expression too complex")); | |
11338 | constraint (inst.operands[1].writeback, | |
11339 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 11340 | |
c19d1205 ZW |
11341 | if (unified_syntax) |
11342 | { | |
3c707909 PB |
11343 | bfd_boolean narrow; |
11344 | unsigned mask; | |
11345 | ||
11346 | narrow = FALSE; | |
c19d1205 ZW |
11347 | /* See if we can use a 16-bit instruction. */ |
11348 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
11349 | && inst.size_req != 4 | |
3c707909 | 11350 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 11351 | { |
3c707909 | 11352 | mask = 1 << inst.operands[0].reg; |
90e4755a | 11353 | |
eab4f823 | 11354 | if (inst.operands[0].reg <= 7) |
90e4755a | 11355 | { |
3c707909 | 11356 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
11357 | ? inst.operands[0].writeback |
11358 | : (inst.operands[0].writeback | |
11359 | == !(inst.operands[1].imm & mask))) | |
477330fc | 11360 | { |
eab4f823 MGD |
11361 | if (inst.instruction == T_MNEM_stmia |
11362 | && (inst.operands[1].imm & mask) | |
11363 | && (inst.operands[1].imm & (mask - 1))) | |
11364 | as_warn (_("value stored for r%d is UNKNOWN"), | |
11365 | inst.operands[0].reg); | |
3c707909 | 11366 | |
eab4f823 MGD |
11367 | inst.instruction = THUMB_OP16 (inst.instruction); |
11368 | inst.instruction |= inst.operands[0].reg << 8; | |
11369 | inst.instruction |= inst.operands[1].imm; | |
11370 | narrow = TRUE; | |
11371 | } | |
11372 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11373 | { | |
11374 | /* This means 1 register in reg list one of 3 situations: | |
11375 | 1. Instruction is stmia, but without writeback. | |
11376 | 2. lmdia without writeback, but with Rn not in | |
477330fc | 11377 | reglist. |
eab4f823 MGD |
11378 | 3. ldmia with writeback, but with Rn in reglist. |
11379 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
11380 | case 1 and 2 which can be converted into a 16-bit | |
11381 | str or ldr. The SP cases are handled below. */ | |
11382 | unsigned long opcode; | |
11383 | /* First, record an error for Case 3. */ | |
11384 | if (inst.operands[1].imm & mask | |
11385 | && inst.operands[0].writeback) | |
fa94de6b | 11386 | inst.error = |
eab4f823 MGD |
11387 | _("having the base register in the register list when " |
11388 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
11389 | |
11390 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
11391 | : T_MNEM_ldr); |
11392 | inst.instruction = THUMB_OP16 (opcode); | |
11393 | inst.instruction |= inst.operands[0].reg << 3; | |
11394 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
11395 | narrow = TRUE; | |
11396 | } | |
90e4755a | 11397 | } |
eab4f823 | 11398 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 11399 | { |
eab4f823 MGD |
11400 | if (inst.operands[0].writeback) |
11401 | { | |
fa94de6b | 11402 | inst.instruction = |
eab4f823 | 11403 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11404 | ? T_MNEM_push : T_MNEM_pop); |
eab4f823 | 11405 | inst.instruction |= inst.operands[1].imm; |
477330fc | 11406 | narrow = TRUE; |
eab4f823 MGD |
11407 | } |
11408 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11409 | { | |
fa94de6b | 11410 | inst.instruction = |
eab4f823 | 11411 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11412 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); |
eab4f823 | 11413 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); |
477330fc | 11414 | narrow = TRUE; |
eab4f823 | 11415 | } |
90e4755a | 11416 | } |
3c707909 PB |
11417 | } |
11418 | ||
11419 | if (!narrow) | |
11420 | { | |
c19d1205 ZW |
11421 | if (inst.instruction < 0xffff) |
11422 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 11423 | |
5f4273c7 NC |
11424 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
11425 | inst.operands[0].writeback); | |
90e4755a RE |
11426 | } |
11427 | } | |
c19d1205 | 11428 | else |
90e4755a | 11429 | { |
c19d1205 ZW |
11430 | constraint (inst.operands[0].reg > 7 |
11431 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
11432 | constraint (inst.instruction != T_MNEM_ldmia |
11433 | && inst.instruction != T_MNEM_stmia, | |
11434 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 11435 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 11436 | { |
c19d1205 ZW |
11437 | if (!inst.operands[0].writeback) |
11438 | as_warn (_("this instruction will write back the base register")); | |
11439 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
11440 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 11441 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 11442 | inst.operands[0].reg); |
f03698e6 | 11443 | } |
c19d1205 | 11444 | else |
90e4755a | 11445 | { |
c19d1205 ZW |
11446 | if (!inst.operands[0].writeback |
11447 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11448 | as_warn (_("this instruction will write back the base register")); | |
11449 | else if (inst.operands[0].writeback | |
11450 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11451 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
11452 | } |
11453 | ||
c19d1205 ZW |
11454 | inst.instruction = THUMB_OP16 (inst.instruction); |
11455 | inst.instruction |= inst.operands[0].reg << 8; | |
11456 | inst.instruction |= inst.operands[1].imm; | |
11457 | } | |
11458 | } | |
e28cd48c | 11459 | |
c19d1205 ZW |
11460 | static void |
11461 | do_t_ldrex (void) | |
11462 | { | |
11463 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
11464 | || inst.operands[1].postind || inst.operands[1].writeback | |
11465 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
11466 | || inst.operands[1].negative, | |
01cfc07f | 11467 | BAD_ADDR_MODE); |
e28cd48c | 11468 | |
5be8be5d DG |
11469 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
11470 | ||
c19d1205 ZW |
11471 | inst.instruction |= inst.operands[0].reg << 12; |
11472 | inst.instruction |= inst.operands[1].reg << 16; | |
11473 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
11474 | } | |
e28cd48c | 11475 | |
c19d1205 ZW |
11476 | static void |
11477 | do_t_ldrexd (void) | |
11478 | { | |
11479 | if (!inst.operands[1].present) | |
1cac9012 | 11480 | { |
c19d1205 ZW |
11481 | constraint (inst.operands[0].reg == REG_LR, |
11482 | _("r14 not allowed as first register " | |
11483 | "when second register is omitted")); | |
11484 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 11485 | } |
c19d1205 ZW |
11486 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
11487 | BAD_OVERLAP); | |
b99bd4ef | 11488 | |
c19d1205 ZW |
11489 | inst.instruction |= inst.operands[0].reg << 12; |
11490 | inst.instruction |= inst.operands[1].reg << 8; | |
11491 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
11492 | } |
11493 | ||
11494 | static void | |
c19d1205 | 11495 | do_t_ldst (void) |
b99bd4ef | 11496 | { |
0110f2b8 PB |
11497 | unsigned long opcode; |
11498 | int Rn; | |
11499 | ||
e07e6e58 NC |
11500 | if (inst.operands[0].isreg |
11501 | && !inst.operands[0].preind | |
11502 | && inst.operands[0].reg == REG_PC) | |
11503 | set_it_insn_type_last (); | |
11504 | ||
0110f2b8 | 11505 | opcode = inst.instruction; |
c19d1205 | 11506 | if (unified_syntax) |
b99bd4ef | 11507 | { |
53365c0d PB |
11508 | if (!inst.operands[1].isreg) |
11509 | { | |
11510 | if (opcode <= 0xffff) | |
11511 | inst.instruction = THUMB_OP32 (opcode); | |
8335d6aa | 11512 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
53365c0d PB |
11513 | return; |
11514 | } | |
0110f2b8 PB |
11515 | if (inst.operands[1].isreg |
11516 | && !inst.operands[1].writeback | |
c19d1205 ZW |
11517 | && !inst.operands[1].shifted && !inst.operands[1].postind |
11518 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
11519 | && opcode <= 0xffff |
11520 | && inst.size_req != 4) | |
c19d1205 | 11521 | { |
0110f2b8 PB |
11522 | /* Insn may have a 16-bit form. */ |
11523 | Rn = inst.operands[1].reg; | |
11524 | if (inst.operands[1].immisreg) | |
11525 | { | |
11526 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 11527 | /* [Rn, Rik] */ |
0110f2b8 PB |
11528 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
11529 | goto op16; | |
5be8be5d DG |
11530 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
11531 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
11532 | } |
11533 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
11534 | && opcode != T_MNEM_ldrsb) | |
11535 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
11536 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
11537 | { | |
11538 | /* [Rn, #const] */ | |
11539 | if (Rn > 7) | |
11540 | { | |
11541 | if (Rn == REG_PC) | |
11542 | { | |
11543 | if (inst.reloc.pc_rel) | |
11544 | opcode = T_MNEM_ldr_pc2; | |
11545 | else | |
11546 | opcode = T_MNEM_ldr_pc; | |
11547 | } | |
11548 | else | |
11549 | { | |
11550 | if (opcode == T_MNEM_ldr) | |
11551 | opcode = T_MNEM_ldr_sp; | |
11552 | else | |
11553 | opcode = T_MNEM_str_sp; | |
11554 | } | |
11555 | inst.instruction = inst.operands[0].reg << 8; | |
11556 | } | |
11557 | else | |
11558 | { | |
11559 | inst.instruction = inst.operands[0].reg; | |
11560 | inst.instruction |= inst.operands[1].reg << 3; | |
11561 | } | |
11562 | inst.instruction |= THUMB_OP16 (opcode); | |
11563 | if (inst.size_req == 2) | |
11564 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
11565 | else | |
11566 | inst.relax = opcode; | |
11567 | return; | |
11568 | } | |
c19d1205 | 11569 | } |
0110f2b8 | 11570 | /* Definitely a 32-bit variant. */ |
5be8be5d | 11571 | |
8d67f500 NC |
11572 | /* Warning for Erratum 752419. */ |
11573 | if (opcode == T_MNEM_ldr | |
11574 | && inst.operands[0].reg == REG_SP | |
11575 | && inst.operands[1].writeback == 1 | |
11576 | && !inst.operands[1].immisreg) | |
11577 | { | |
11578 | if (no_cpu_selected () | |
11579 | || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7) | |
477330fc RM |
11580 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) |
11581 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
8d67f500 NC |
11582 | as_warn (_("This instruction may be unpredictable " |
11583 | "if executed on M-profile cores " | |
11584 | "with interrupts enabled.")); | |
11585 | } | |
11586 | ||
5be8be5d | 11587 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 11588 | if (inst.operands[1].immisreg) |
5be8be5d DG |
11589 | reject_bad_reg (inst.operands[1].imm); |
11590 | ||
1be5fd2e NC |
11591 | constraint (inst.operands[1].writeback == 1 |
11592 | && inst.operands[0].reg == inst.operands[1].reg, | |
11593 | BAD_OVERLAP); | |
11594 | ||
0110f2b8 | 11595 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
11596 | inst.instruction |= inst.operands[0].reg << 12; |
11597 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
1be5fd2e | 11598 | check_ldr_r15_aligned (); |
b99bd4ef NC |
11599 | return; |
11600 | } | |
11601 | ||
c19d1205 ZW |
11602 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11603 | ||
11604 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 11605 | { |
c19d1205 ZW |
11606 | /* Only [Rn,Rm] is acceptable. */ |
11607 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
11608 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
11609 | || inst.operands[1].postind || inst.operands[1].shifted | |
11610 | || inst.operands[1].negative, | |
11611 | _("Thumb does not support this addressing mode")); | |
11612 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11613 | goto op16; | |
b99bd4ef | 11614 | } |
5f4273c7 | 11615 | |
c19d1205 ZW |
11616 | inst.instruction = THUMB_OP16 (inst.instruction); |
11617 | if (!inst.operands[1].isreg) | |
8335d6aa | 11618 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
c19d1205 | 11619 | return; |
b99bd4ef | 11620 | |
c19d1205 ZW |
11621 | constraint (!inst.operands[1].preind |
11622 | || inst.operands[1].shifted | |
11623 | || inst.operands[1].writeback, | |
11624 | _("Thumb does not support this addressing mode")); | |
11625 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 11626 | { |
c19d1205 ZW |
11627 | constraint (inst.instruction & 0x0600, |
11628 | _("byte or halfword not valid for base register")); | |
11629 | constraint (inst.operands[1].reg == REG_PC | |
11630 | && !(inst.instruction & THUMB_LOAD_BIT), | |
11631 | _("r15 based store not allowed")); | |
11632 | constraint (inst.operands[1].immisreg, | |
11633 | _("invalid base register for register offset")); | |
b99bd4ef | 11634 | |
c19d1205 ZW |
11635 | if (inst.operands[1].reg == REG_PC) |
11636 | inst.instruction = T_OPCODE_LDR_PC; | |
11637 | else if (inst.instruction & THUMB_LOAD_BIT) | |
11638 | inst.instruction = T_OPCODE_LDR_SP; | |
11639 | else | |
11640 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 11641 | |
c19d1205 ZW |
11642 | inst.instruction |= inst.operands[0].reg << 8; |
11643 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
11644 | return; | |
11645 | } | |
90e4755a | 11646 | |
c19d1205 ZW |
11647 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
11648 | if (!inst.operands[1].immisreg) | |
11649 | { | |
11650 | /* Immediate offset. */ | |
11651 | inst.instruction |= inst.operands[0].reg; | |
11652 | inst.instruction |= inst.operands[1].reg << 3; | |
11653 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
11654 | return; | |
11655 | } | |
90e4755a | 11656 | |
c19d1205 ZW |
11657 | /* Register offset. */ |
11658 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
11659 | constraint (inst.operands[1].negative, | |
11660 | _("Thumb does not support this addressing mode")); | |
90e4755a | 11661 | |
c19d1205 ZW |
11662 | op16: |
11663 | switch (inst.instruction) | |
11664 | { | |
11665 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
11666 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
11667 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
11668 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
11669 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
11670 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
11671 | case 0x5600 /* ldrsb */: | |
11672 | case 0x5e00 /* ldrsh */: break; | |
11673 | default: abort (); | |
11674 | } | |
90e4755a | 11675 | |
c19d1205 ZW |
11676 | inst.instruction |= inst.operands[0].reg; |
11677 | inst.instruction |= inst.operands[1].reg << 3; | |
11678 | inst.instruction |= inst.operands[1].imm << 6; | |
11679 | } | |
90e4755a | 11680 | |
c19d1205 ZW |
11681 | static void |
11682 | do_t_ldstd (void) | |
11683 | { | |
11684 | if (!inst.operands[1].present) | |
b99bd4ef | 11685 | { |
c19d1205 ZW |
11686 | inst.operands[1].reg = inst.operands[0].reg + 1; |
11687 | constraint (inst.operands[0].reg == REG_LR, | |
11688 | _("r14 not allowed here")); | |
bd340a04 | 11689 | constraint (inst.operands[0].reg == REG_R12, |
477330fc | 11690 | _("r12 not allowed here")); |
b99bd4ef | 11691 | } |
bd340a04 MGD |
11692 | |
11693 | if (inst.operands[2].writeback | |
11694 | && (inst.operands[0].reg == inst.operands[2].reg | |
11695 | || inst.operands[1].reg == inst.operands[2].reg)) | |
11696 | as_warn (_("base register written back, and overlaps " | |
477330fc | 11697 | "one of transfer registers")); |
bd340a04 | 11698 | |
c19d1205 ZW |
11699 | inst.instruction |= inst.operands[0].reg << 12; |
11700 | inst.instruction |= inst.operands[1].reg << 8; | |
11701 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
11702 | } |
11703 | ||
c19d1205 ZW |
11704 | static void |
11705 | do_t_ldstt (void) | |
11706 | { | |
11707 | inst.instruction |= inst.operands[0].reg << 12; | |
11708 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
11709 | } | |
a737bd4d | 11710 | |
b99bd4ef | 11711 | static void |
c19d1205 | 11712 | do_t_mla (void) |
b99bd4ef | 11713 | { |
fdfde340 | 11714 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 11715 | |
fdfde340 JM |
11716 | Rd = inst.operands[0].reg; |
11717 | Rn = inst.operands[1].reg; | |
11718 | Rm = inst.operands[2].reg; | |
11719 | Ra = inst.operands[3].reg; | |
11720 | ||
11721 | reject_bad_reg (Rd); | |
11722 | reject_bad_reg (Rn); | |
11723 | reject_bad_reg (Rm); | |
11724 | reject_bad_reg (Ra); | |
11725 | ||
11726 | inst.instruction |= Rd << 8; | |
11727 | inst.instruction |= Rn << 16; | |
11728 | inst.instruction |= Rm; | |
11729 | inst.instruction |= Ra << 12; | |
c19d1205 | 11730 | } |
b99bd4ef | 11731 | |
c19d1205 ZW |
11732 | static void |
11733 | do_t_mlal (void) | |
11734 | { | |
fdfde340 JM |
11735 | unsigned RdLo, RdHi, Rn, Rm; |
11736 | ||
11737 | RdLo = inst.operands[0].reg; | |
11738 | RdHi = inst.operands[1].reg; | |
11739 | Rn = inst.operands[2].reg; | |
11740 | Rm = inst.operands[3].reg; | |
11741 | ||
11742 | reject_bad_reg (RdLo); | |
11743 | reject_bad_reg (RdHi); | |
11744 | reject_bad_reg (Rn); | |
11745 | reject_bad_reg (Rm); | |
11746 | ||
11747 | inst.instruction |= RdLo << 12; | |
11748 | inst.instruction |= RdHi << 8; | |
11749 | inst.instruction |= Rn << 16; | |
11750 | inst.instruction |= Rm; | |
c19d1205 | 11751 | } |
b99bd4ef | 11752 | |
c19d1205 ZW |
11753 | static void |
11754 | do_t_mov_cmp (void) | |
11755 | { | |
fdfde340 JM |
11756 | unsigned Rn, Rm; |
11757 | ||
11758 | Rn = inst.operands[0].reg; | |
11759 | Rm = inst.operands[1].reg; | |
11760 | ||
e07e6e58 NC |
11761 | if (Rn == REG_PC) |
11762 | set_it_insn_type_last (); | |
11763 | ||
c19d1205 | 11764 | if (unified_syntax) |
b99bd4ef | 11765 | { |
c19d1205 ZW |
11766 | int r0off = (inst.instruction == T_MNEM_mov |
11767 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 11768 | unsigned long opcode; |
3d388997 PB |
11769 | bfd_boolean narrow; |
11770 | bfd_boolean low_regs; | |
11771 | ||
fdfde340 | 11772 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 11773 | opcode = inst.instruction; |
e07e6e58 | 11774 | if (in_it_block ()) |
0110f2b8 | 11775 | narrow = opcode != T_MNEM_movs; |
3d388997 | 11776 | else |
0110f2b8 | 11777 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
11778 | if (inst.size_req == 4 |
11779 | || inst.operands[1].shifted) | |
11780 | narrow = FALSE; | |
11781 | ||
efd81785 PB |
11782 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
11783 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
11784 | && !inst.operands[1].shifted | |
fdfde340 JM |
11785 | && Rn == REG_PC |
11786 | && Rm == REG_LR) | |
efd81785 PB |
11787 | { |
11788 | inst.instruction = T2_SUBS_PC_LR; | |
11789 | return; | |
11790 | } | |
11791 | ||
fdfde340 JM |
11792 | if (opcode == T_MNEM_cmp) |
11793 | { | |
11794 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
11795 | if (narrow) |
11796 | { | |
11797 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
11798 | but valid. */ | |
11799 | warn_deprecated_sp (Rm); | |
11800 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
11801 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
11802 | tools reject R15, so we do too. */ | |
11803 | constraint (Rm == REG_PC, BAD_PC); | |
11804 | } | |
11805 | else | |
11806 | reject_bad_reg (Rm); | |
fdfde340 JM |
11807 | } |
11808 | else if (opcode == T_MNEM_mov | |
11809 | || opcode == T_MNEM_movs) | |
11810 | { | |
11811 | if (inst.operands[1].isreg) | |
11812 | { | |
11813 | if (opcode == T_MNEM_movs) | |
11814 | { | |
11815 | reject_bad_reg (Rn); | |
11816 | reject_bad_reg (Rm); | |
11817 | } | |
76fa04a4 MGD |
11818 | else if (narrow) |
11819 | { | |
11820 | /* This is mov.n. */ | |
11821 | if ((Rn == REG_SP || Rn == REG_PC) | |
11822 | && (Rm == REG_SP || Rm == REG_PC)) | |
11823 | { | |
5c3696f8 | 11824 | as_tsktsk (_("Use of r%u as a source register is " |
76fa04a4 MGD |
11825 | "deprecated when r%u is the destination " |
11826 | "register."), Rm, Rn); | |
11827 | } | |
11828 | } | |
11829 | else | |
11830 | { | |
11831 | /* This is mov.w. */ | |
11832 | constraint (Rn == REG_PC, BAD_PC); | |
11833 | constraint (Rm == REG_PC, BAD_PC); | |
11834 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
11835 | } | |
fdfde340 JM |
11836 | } |
11837 | else | |
11838 | reject_bad_reg (Rn); | |
11839 | } | |
11840 | ||
c19d1205 ZW |
11841 | if (!inst.operands[1].isreg) |
11842 | { | |
0110f2b8 | 11843 | /* Immediate operand. */ |
e07e6e58 | 11844 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
11845 | narrow = 0; |
11846 | if (low_regs && narrow) | |
11847 | { | |
11848 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 11849 | inst.instruction |= Rn << 8; |
a9f02af8 MG |
11850 | if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
11851 | || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
72d98d16 | 11852 | { |
a9f02af8 | 11853 | if (inst.size_req == 2) |
72d98d16 | 11854 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
a9f02af8 MG |
11855 | else |
11856 | inst.relax = opcode; | |
72d98d16 | 11857 | } |
0110f2b8 PB |
11858 | } |
11859 | else | |
11860 | { | |
a9f02af8 MG |
11861 | constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
11862 | && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC , | |
11863 | THUMB1_RELOC_ONLY); | |
11864 | ||
0110f2b8 PB |
11865 | inst.instruction = THUMB_OP32 (inst.instruction); |
11866 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 11867 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
11868 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
11869 | } | |
c19d1205 | 11870 | } |
728ca7c9 PB |
11871 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
11872 | && (inst.instruction == T_MNEM_mov | |
11873 | || inst.instruction == T_MNEM_movs)) | |
11874 | { | |
11875 | /* Register shifts are encoded as separate shift instructions. */ | |
11876 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
11877 | ||
e07e6e58 | 11878 | if (in_it_block ()) |
728ca7c9 PB |
11879 | narrow = !flags; |
11880 | else | |
11881 | narrow = flags; | |
11882 | ||
11883 | if (inst.size_req == 4) | |
11884 | narrow = FALSE; | |
11885 | ||
11886 | if (!low_regs || inst.operands[1].imm > 7) | |
11887 | narrow = FALSE; | |
11888 | ||
fdfde340 | 11889 | if (Rn != Rm) |
728ca7c9 PB |
11890 | narrow = FALSE; |
11891 | ||
11892 | switch (inst.operands[1].shift_kind) | |
11893 | { | |
11894 | case SHIFT_LSL: | |
11895 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
11896 | break; | |
11897 | case SHIFT_ASR: | |
11898 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
11899 | break; | |
11900 | case SHIFT_LSR: | |
11901 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
11902 | break; | |
11903 | case SHIFT_ROR: | |
11904 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
11905 | break; | |
11906 | default: | |
5f4273c7 | 11907 | abort (); |
728ca7c9 PB |
11908 | } |
11909 | ||
11910 | inst.instruction = opcode; | |
11911 | if (narrow) | |
11912 | { | |
fdfde340 | 11913 | inst.instruction |= Rn; |
728ca7c9 PB |
11914 | inst.instruction |= inst.operands[1].imm << 3; |
11915 | } | |
11916 | else | |
11917 | { | |
11918 | if (flags) | |
11919 | inst.instruction |= CONDS_BIT; | |
11920 | ||
fdfde340 JM |
11921 | inst.instruction |= Rn << 8; |
11922 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
11923 | inst.instruction |= inst.operands[1].imm; |
11924 | } | |
11925 | } | |
3d388997 | 11926 | else if (!narrow) |
c19d1205 | 11927 | { |
728ca7c9 PB |
11928 | /* Some mov with immediate shift have narrow variants. |
11929 | Register shifts are handled above. */ | |
11930 | if (low_regs && inst.operands[1].shifted | |
11931 | && (inst.instruction == T_MNEM_mov | |
11932 | || inst.instruction == T_MNEM_movs)) | |
11933 | { | |
e07e6e58 | 11934 | if (in_it_block ()) |
728ca7c9 PB |
11935 | narrow = (inst.instruction == T_MNEM_mov); |
11936 | else | |
11937 | narrow = (inst.instruction == T_MNEM_movs); | |
11938 | } | |
11939 | ||
11940 | if (narrow) | |
11941 | { | |
11942 | switch (inst.operands[1].shift_kind) | |
11943 | { | |
11944 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
11945 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
11946 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
11947 | default: narrow = FALSE; break; | |
11948 | } | |
11949 | } | |
11950 | ||
11951 | if (narrow) | |
11952 | { | |
fdfde340 JM |
11953 | inst.instruction |= Rn; |
11954 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
11955 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
11956 | } | |
11957 | else | |
11958 | { | |
11959 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 11960 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
11961 | encode_thumb32_shifted_operand (1); |
11962 | } | |
c19d1205 ZW |
11963 | } |
11964 | else | |
11965 | switch (inst.instruction) | |
11966 | { | |
11967 | case T_MNEM_mov: | |
837b3435 | 11968 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
11969 | results. Don't allow this. */ |
11970 | if (low_regs) | |
11971 | { | |
11972 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6), | |
11973 | "MOV Rd, Rs with two low registers is not " | |
11974 | "permitted on this architecture"); | |
fa94de6b | 11975 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
11976 | arm_ext_v6); |
11977 | } | |
11978 | ||
c19d1205 | 11979 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
11980 | inst.instruction |= (Rn & 0x8) << 4; |
11981 | inst.instruction |= (Rn & 0x7); | |
11982 | inst.instruction |= Rm << 3; | |
c19d1205 | 11983 | break; |
b99bd4ef | 11984 | |
c19d1205 ZW |
11985 | case T_MNEM_movs: |
11986 | /* We know we have low registers at this point. | |
941a8a52 MGD |
11987 | Generate LSLS Rd, Rs, #0. */ |
11988 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
11989 | inst.instruction |= Rn; |
11990 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11991 | break; |
11992 | ||
11993 | case T_MNEM_cmp: | |
3d388997 | 11994 | if (low_regs) |
c19d1205 ZW |
11995 | { |
11996 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
11997 | inst.instruction |= Rn; |
11998 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11999 | } |
12000 | else | |
12001 | { | |
12002 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
12003 | inst.instruction |= (Rn & 0x8) << 4; |
12004 | inst.instruction |= (Rn & 0x7); | |
12005 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12006 | } |
12007 | break; | |
12008 | } | |
b99bd4ef NC |
12009 | return; |
12010 | } | |
12011 | ||
c19d1205 | 12012 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
12013 | |
12014 | /* PR 10443: Do not silently ignore shifted operands. */ | |
12015 | constraint (inst.operands[1].shifted, | |
12016 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
12017 | ||
c19d1205 | 12018 | if (inst.operands[1].isreg) |
b99bd4ef | 12019 | { |
fdfde340 | 12020 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 12021 | { |
c19d1205 ZW |
12022 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
12023 | since a MOV instruction produces unpredictable results. */ | |
12024 | if (inst.instruction == T_OPCODE_MOV_I8) | |
12025 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 12026 | else |
c19d1205 | 12027 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 12028 | |
fdfde340 JM |
12029 | inst.instruction |= Rn; |
12030 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
12031 | } |
12032 | else | |
12033 | { | |
c19d1205 ZW |
12034 | if (inst.instruction == T_OPCODE_MOV_I8) |
12035 | inst.instruction = T_OPCODE_MOV_HR; | |
12036 | else | |
12037 | inst.instruction = T_OPCODE_CMP_HR; | |
12038 | do_t_cpy (); | |
b99bd4ef NC |
12039 | } |
12040 | } | |
c19d1205 | 12041 | else |
b99bd4ef | 12042 | { |
fdfde340 | 12043 | constraint (Rn > 7, |
c19d1205 | 12044 | _("only lo regs allowed with immediate")); |
fdfde340 | 12045 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
12046 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
12047 | } | |
12048 | } | |
b99bd4ef | 12049 | |
c19d1205 ZW |
12050 | static void |
12051 | do_t_mov16 (void) | |
12052 | { | |
fdfde340 | 12053 | unsigned Rd; |
b6895b4f PB |
12054 | bfd_vma imm; |
12055 | bfd_boolean top; | |
12056 | ||
12057 | top = (inst.instruction & 0x00800000) != 0; | |
12058 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
12059 | { | |
12060 | constraint (top, _(":lower16: not allowed this instruction")); | |
12061 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
12062 | } | |
12063 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
12064 | { | |
12065 | constraint (!top, _(":upper16: not allowed this instruction")); | |
12066 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
12067 | } | |
12068 | ||
fdfde340 JM |
12069 | Rd = inst.operands[0].reg; |
12070 | reject_bad_reg (Rd); | |
12071 | ||
12072 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
12073 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
12074 | { | |
12075 | imm = inst.reloc.exp.X_add_number; | |
12076 | inst.instruction |= (imm & 0xf000) << 4; | |
12077 | inst.instruction |= (imm & 0x0800) << 15; | |
12078 | inst.instruction |= (imm & 0x0700) << 4; | |
12079 | inst.instruction |= (imm & 0x00ff); | |
12080 | } | |
c19d1205 | 12081 | } |
b99bd4ef | 12082 | |
c19d1205 ZW |
12083 | static void |
12084 | do_t_mvn_tst (void) | |
12085 | { | |
fdfde340 | 12086 | unsigned Rn, Rm; |
c921be7d | 12087 | |
fdfde340 JM |
12088 | Rn = inst.operands[0].reg; |
12089 | Rm = inst.operands[1].reg; | |
12090 | ||
12091 | if (inst.instruction == T_MNEM_cmp | |
12092 | || inst.instruction == T_MNEM_cmn) | |
12093 | constraint (Rn == REG_PC, BAD_PC); | |
12094 | else | |
12095 | reject_bad_reg (Rn); | |
12096 | reject_bad_reg (Rm); | |
12097 | ||
c19d1205 ZW |
12098 | if (unified_syntax) |
12099 | { | |
12100 | int r0off = (inst.instruction == T_MNEM_mvn | |
12101 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
12102 | bfd_boolean narrow; |
12103 | ||
12104 | if (inst.size_req == 4 | |
12105 | || inst.instruction > 0xffff | |
12106 | || inst.operands[1].shifted | |
fdfde340 | 12107 | || Rn > 7 || Rm > 7) |
3d388997 | 12108 | narrow = FALSE; |
fe8b4cc3 KT |
12109 | else if (inst.instruction == T_MNEM_cmn |
12110 | || inst.instruction == T_MNEM_tst) | |
3d388997 PB |
12111 | narrow = TRUE; |
12112 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12113 | narrow = !in_it_block (); |
3d388997 | 12114 | else |
e07e6e58 | 12115 | narrow = in_it_block (); |
3d388997 | 12116 | |
c19d1205 | 12117 | if (!inst.operands[1].isreg) |
b99bd4ef | 12118 | { |
c19d1205 ZW |
12119 | /* For an immediate, we always generate a 32-bit opcode; |
12120 | section relaxation will shrink it later if possible. */ | |
12121 | if (inst.instruction < 0xffff) | |
12122 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12123 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12124 | inst.instruction |= Rn << r0off; |
c19d1205 | 12125 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 12126 | } |
c19d1205 | 12127 | else |
b99bd4ef | 12128 | { |
c19d1205 | 12129 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 12130 | if (narrow) |
b99bd4ef | 12131 | { |
c19d1205 | 12132 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12133 | inst.instruction |= Rn; |
12134 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12135 | } |
c19d1205 | 12136 | else |
b99bd4ef | 12137 | { |
c19d1205 ZW |
12138 | constraint (inst.operands[1].shifted |
12139 | && inst.operands[1].immisreg, | |
12140 | _("shift must be constant")); | |
12141 | if (inst.instruction < 0xffff) | |
12142 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 12143 | inst.instruction |= Rn << r0off; |
c19d1205 | 12144 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 12145 | } |
b99bd4ef NC |
12146 | } |
12147 | } | |
12148 | else | |
12149 | { | |
c19d1205 ZW |
12150 | constraint (inst.instruction > 0xffff |
12151 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
12152 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
12153 | _("unshifted register required")); | |
fdfde340 | 12154 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12155 | BAD_HIREG); |
b99bd4ef | 12156 | |
c19d1205 | 12157 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12158 | inst.instruction |= Rn; |
12159 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12160 | } |
b99bd4ef NC |
12161 | } |
12162 | ||
b05fe5cf | 12163 | static void |
c19d1205 | 12164 | do_t_mrs (void) |
b05fe5cf | 12165 | { |
fdfde340 | 12166 | unsigned Rd; |
037e8744 JB |
12167 | |
12168 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
12169 | return; | |
12170 | ||
90ec0d68 MGD |
12171 | Rd = inst.operands[0].reg; |
12172 | reject_bad_reg (Rd); | |
12173 | inst.instruction |= Rd << 8; | |
12174 | ||
12175 | if (inst.operands[1].isreg) | |
62b3e311 | 12176 | { |
90ec0d68 MGD |
12177 | unsigned br = inst.operands[1].reg; |
12178 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
12179 | as_bad (_("bad register for mrs")); | |
12180 | ||
12181 | inst.instruction |= br & (0xf << 16); | |
12182 | inst.instruction |= (br & 0x300) >> 4; | |
12183 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
12184 | } |
12185 | else | |
12186 | { | |
90ec0d68 | 12187 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 12188 | |
d2cd1205 | 12189 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
12190 | { |
12191 | /* PR gas/12698: The constraint is only applied for m_profile. | |
12192 | If the user has specified -march=all, we want to ignore it as | |
12193 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12194 | bfd_boolean m_profile = |
12195 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf NC |
12196 | constraint ((flags != 0) && m_profile, _("selected processor does " |
12197 | "not support requested special purpose register")); | |
12198 | } | |
90ec0d68 | 12199 | else |
d2cd1205 JB |
12200 | /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile |
12201 | devices). */ | |
12202 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
12203 | _("'APSR', 'CPSR' or 'SPSR' expected")); | |
fdfde340 | 12204 | |
90ec0d68 MGD |
12205 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
12206 | inst.instruction |= inst.operands[1].imm & 0xff; | |
12207 | inst.instruction |= 0xf0000; | |
12208 | } | |
c19d1205 | 12209 | } |
b05fe5cf | 12210 | |
c19d1205 ZW |
12211 | static void |
12212 | do_t_msr (void) | |
12213 | { | |
62b3e311 | 12214 | int flags; |
fdfde340 | 12215 | unsigned Rn; |
62b3e311 | 12216 | |
037e8744 JB |
12217 | if (do_vfp_nsyn_msr () == SUCCESS) |
12218 | return; | |
12219 | ||
c19d1205 ZW |
12220 | constraint (!inst.operands[1].isreg, |
12221 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
12222 | |
12223 | if (inst.operands[0].isreg) | |
12224 | flags = (int)(inst.operands[0].reg); | |
12225 | else | |
12226 | flags = inst.operands[0].imm; | |
12227 | ||
d2cd1205 | 12228 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 12229 | { |
d2cd1205 JB |
12230 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
12231 | ||
1a43faaf | 12232 | /* PR gas/12698: The constraint is only applied for m_profile. |
477330fc RM |
12233 | If the user has specified -march=all, we want to ignore it as |
12234 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12235 | bfd_boolean m_profile = |
12236 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf | 12237 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) |
477330fc RM |
12238 | && (bits & ~(PSR_s | PSR_f)) != 0) |
12239 | || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
12240 | && bits != PSR_f)) && m_profile, | |
12241 | _("selected processor does not support requested special " | |
12242 | "purpose register")); | |
62b3e311 PB |
12243 | } |
12244 | else | |
d2cd1205 JB |
12245 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
12246 | "requested special purpose register")); | |
c921be7d | 12247 | |
fdfde340 JM |
12248 | Rn = inst.operands[1].reg; |
12249 | reject_bad_reg (Rn); | |
12250 | ||
62b3e311 | 12251 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
12252 | inst.instruction |= (flags & 0xf0000) >> 8; |
12253 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 12254 | inst.instruction |= (flags & 0xff); |
fdfde340 | 12255 | inst.instruction |= Rn << 16; |
c19d1205 | 12256 | } |
b05fe5cf | 12257 | |
c19d1205 ZW |
12258 | static void |
12259 | do_t_mul (void) | |
12260 | { | |
17828f45 | 12261 | bfd_boolean narrow; |
fdfde340 | 12262 | unsigned Rd, Rn, Rm; |
17828f45 | 12263 | |
c19d1205 ZW |
12264 | if (!inst.operands[2].present) |
12265 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 12266 | |
fdfde340 JM |
12267 | Rd = inst.operands[0].reg; |
12268 | Rn = inst.operands[1].reg; | |
12269 | Rm = inst.operands[2].reg; | |
12270 | ||
17828f45 | 12271 | if (unified_syntax) |
b05fe5cf | 12272 | { |
17828f45 | 12273 | if (inst.size_req == 4 |
fdfde340 JM |
12274 | || (Rd != Rn |
12275 | && Rd != Rm) | |
12276 | || Rn > 7 | |
12277 | || Rm > 7) | |
17828f45 JM |
12278 | narrow = FALSE; |
12279 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 12280 | narrow = !in_it_block (); |
17828f45 | 12281 | else |
e07e6e58 | 12282 | narrow = in_it_block (); |
b05fe5cf | 12283 | } |
c19d1205 | 12284 | else |
b05fe5cf | 12285 | { |
17828f45 | 12286 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 12287 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12288 | BAD_HIREG); |
17828f45 JM |
12289 | narrow = TRUE; |
12290 | } | |
b05fe5cf | 12291 | |
17828f45 JM |
12292 | if (narrow) |
12293 | { | |
12294 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 12295 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 12296 | inst.instruction |= Rd; |
b05fe5cf | 12297 | |
fdfde340 JM |
12298 | if (Rd == Rn) |
12299 | inst.instruction |= Rm << 3; | |
12300 | else if (Rd == Rm) | |
12301 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
12302 | else |
12303 | constraint (1, _("dest must overlap one source register")); | |
12304 | } | |
17828f45 JM |
12305 | else |
12306 | { | |
e07e6e58 NC |
12307 | constraint (inst.instruction != T_MNEM_mul, |
12308 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
12309 | /* 32-bit MUL. */ |
12310 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12311 | inst.instruction |= Rd << 8; |
12312 | inst.instruction |= Rn << 16; | |
12313 | inst.instruction |= Rm << 0; | |
12314 | ||
12315 | reject_bad_reg (Rd); | |
12316 | reject_bad_reg (Rn); | |
12317 | reject_bad_reg (Rm); | |
17828f45 | 12318 | } |
c19d1205 | 12319 | } |
b05fe5cf | 12320 | |
c19d1205 ZW |
12321 | static void |
12322 | do_t_mull (void) | |
12323 | { | |
fdfde340 | 12324 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 12325 | |
fdfde340 JM |
12326 | RdLo = inst.operands[0].reg; |
12327 | RdHi = inst.operands[1].reg; | |
12328 | Rn = inst.operands[2].reg; | |
12329 | Rm = inst.operands[3].reg; | |
12330 | ||
12331 | reject_bad_reg (RdLo); | |
12332 | reject_bad_reg (RdHi); | |
12333 | reject_bad_reg (Rn); | |
12334 | reject_bad_reg (Rm); | |
12335 | ||
12336 | inst.instruction |= RdLo << 12; | |
12337 | inst.instruction |= RdHi << 8; | |
12338 | inst.instruction |= Rn << 16; | |
12339 | inst.instruction |= Rm; | |
12340 | ||
12341 | if (RdLo == RdHi) | |
c19d1205 ZW |
12342 | as_tsktsk (_("rdhi and rdlo must be different")); |
12343 | } | |
b05fe5cf | 12344 | |
c19d1205 ZW |
12345 | static void |
12346 | do_t_nop (void) | |
12347 | { | |
e07e6e58 NC |
12348 | set_it_insn_type (NEUTRAL_IT_INSN); |
12349 | ||
c19d1205 ZW |
12350 | if (unified_syntax) |
12351 | { | |
12352 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 12353 | { |
c19d1205 ZW |
12354 | inst.instruction = THUMB_OP32 (inst.instruction); |
12355 | inst.instruction |= inst.operands[0].imm; | |
12356 | } | |
12357 | else | |
12358 | { | |
bc2d1808 NC |
12359 | /* PR9722: Check for Thumb2 availability before |
12360 | generating a thumb2 nop instruction. */ | |
afa62d5e | 12361 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
12362 | { |
12363 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12364 | inst.instruction |= inst.operands[0].imm << 4; | |
12365 | } | |
12366 | else | |
12367 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
12368 | } |
12369 | } | |
12370 | else | |
12371 | { | |
12372 | constraint (inst.operands[0].present, | |
12373 | _("Thumb does not support NOP with hints")); | |
12374 | inst.instruction = 0x46c0; | |
12375 | } | |
12376 | } | |
b05fe5cf | 12377 | |
c19d1205 ZW |
12378 | static void |
12379 | do_t_neg (void) | |
12380 | { | |
12381 | if (unified_syntax) | |
12382 | { | |
3d388997 PB |
12383 | bfd_boolean narrow; |
12384 | ||
12385 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12386 | narrow = !in_it_block (); |
3d388997 | 12387 | else |
e07e6e58 | 12388 | narrow = in_it_block (); |
3d388997 PB |
12389 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12390 | narrow = FALSE; | |
12391 | if (inst.size_req == 4) | |
12392 | narrow = FALSE; | |
12393 | ||
12394 | if (!narrow) | |
c19d1205 ZW |
12395 | { |
12396 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12397 | inst.instruction |= inst.operands[0].reg << 8; | |
12398 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
12399 | } |
12400 | else | |
12401 | { | |
c19d1205 ZW |
12402 | inst.instruction = THUMB_OP16 (inst.instruction); |
12403 | inst.instruction |= inst.operands[0].reg; | |
12404 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
12405 | } |
12406 | } | |
12407 | else | |
12408 | { | |
c19d1205 ZW |
12409 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
12410 | BAD_HIREG); | |
12411 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
12412 | ||
12413 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12414 | inst.instruction |= inst.operands[0].reg; | |
12415 | inst.instruction |= inst.operands[1].reg << 3; | |
12416 | } | |
12417 | } | |
12418 | ||
1c444d06 JM |
12419 | static void |
12420 | do_t_orn (void) | |
12421 | { | |
12422 | unsigned Rd, Rn; | |
12423 | ||
12424 | Rd = inst.operands[0].reg; | |
12425 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
12426 | ||
fdfde340 JM |
12427 | reject_bad_reg (Rd); |
12428 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
12429 | reject_bad_reg (Rn); | |
12430 | ||
1c444d06 JM |
12431 | inst.instruction |= Rd << 8; |
12432 | inst.instruction |= Rn << 16; | |
12433 | ||
12434 | if (!inst.operands[2].isreg) | |
12435 | { | |
12436 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
12437 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
12438 | } | |
12439 | else | |
12440 | { | |
12441 | unsigned Rm; | |
12442 | ||
12443 | Rm = inst.operands[2].reg; | |
fdfde340 | 12444 | reject_bad_reg (Rm); |
1c444d06 JM |
12445 | |
12446 | constraint (inst.operands[2].shifted | |
12447 | && inst.operands[2].immisreg, | |
12448 | _("shift must be constant")); | |
12449 | encode_thumb32_shifted_operand (2); | |
12450 | } | |
12451 | } | |
12452 | ||
c19d1205 ZW |
12453 | static void |
12454 | do_t_pkhbt (void) | |
12455 | { | |
fdfde340 JM |
12456 | unsigned Rd, Rn, Rm; |
12457 | ||
12458 | Rd = inst.operands[0].reg; | |
12459 | Rn = inst.operands[1].reg; | |
12460 | Rm = inst.operands[2].reg; | |
12461 | ||
12462 | reject_bad_reg (Rd); | |
12463 | reject_bad_reg (Rn); | |
12464 | reject_bad_reg (Rm); | |
12465 | ||
12466 | inst.instruction |= Rd << 8; | |
12467 | inst.instruction |= Rn << 16; | |
12468 | inst.instruction |= Rm; | |
c19d1205 ZW |
12469 | if (inst.operands[3].present) |
12470 | { | |
12471 | unsigned int val = inst.reloc.exp.X_add_number; | |
12472 | constraint (inst.reloc.exp.X_op != O_constant, | |
12473 | _("expression too complex")); | |
12474 | inst.instruction |= (val & 0x1c) << 10; | |
12475 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 12476 | } |
c19d1205 | 12477 | } |
b05fe5cf | 12478 | |
c19d1205 ZW |
12479 | static void |
12480 | do_t_pkhtb (void) | |
12481 | { | |
12482 | if (!inst.operands[3].present) | |
1ef52f49 NC |
12483 | { |
12484 | unsigned Rtmp; | |
12485 | ||
12486 | inst.instruction &= ~0x00000020; | |
12487 | ||
12488 | /* PR 10168. Swap the Rm and Rn registers. */ | |
12489 | Rtmp = inst.operands[1].reg; | |
12490 | inst.operands[1].reg = inst.operands[2].reg; | |
12491 | inst.operands[2].reg = Rtmp; | |
12492 | } | |
c19d1205 | 12493 | do_t_pkhbt (); |
b05fe5cf ZW |
12494 | } |
12495 | ||
c19d1205 ZW |
12496 | static void |
12497 | do_t_pld (void) | |
12498 | { | |
fdfde340 JM |
12499 | if (inst.operands[0].immisreg) |
12500 | reject_bad_reg (inst.operands[0].imm); | |
12501 | ||
c19d1205 ZW |
12502 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
12503 | } | |
b05fe5cf | 12504 | |
c19d1205 ZW |
12505 | static void |
12506 | do_t_push_pop (void) | |
b99bd4ef | 12507 | { |
e9f89963 | 12508 | unsigned mask; |
5f4273c7 | 12509 | |
c19d1205 ZW |
12510 | constraint (inst.operands[0].writeback, |
12511 | _("push/pop do not support {reglist}^")); | |
12512 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
12513 | _("expression too complex")); | |
b99bd4ef | 12514 | |
e9f89963 | 12515 | mask = inst.operands[0].imm; |
d3bfe16e | 12516 | if (inst.size_req != 4 && (mask & ~0xff) == 0) |
3c707909 | 12517 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
d3bfe16e JB |
12518 | else if (inst.size_req != 4 |
12519 | && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push | |
12520 | ? REG_LR : REG_PC))) | |
b99bd4ef | 12521 | { |
c19d1205 ZW |
12522 | inst.instruction = THUMB_OP16 (inst.instruction); |
12523 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 12524 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
12525 | } |
12526 | else if (unified_syntax) | |
12527 | { | |
3c707909 | 12528 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 12529 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
12530 | } |
12531 | else | |
12532 | { | |
12533 | inst.error = _("invalid register list to push/pop instruction"); | |
12534 | return; | |
12535 | } | |
c19d1205 | 12536 | } |
b99bd4ef | 12537 | |
c19d1205 ZW |
12538 | static void |
12539 | do_t_rbit (void) | |
12540 | { | |
fdfde340 JM |
12541 | unsigned Rd, Rm; |
12542 | ||
12543 | Rd = inst.operands[0].reg; | |
12544 | Rm = inst.operands[1].reg; | |
12545 | ||
12546 | reject_bad_reg (Rd); | |
12547 | reject_bad_reg (Rm); | |
12548 | ||
12549 | inst.instruction |= Rd << 8; | |
12550 | inst.instruction |= Rm << 16; | |
12551 | inst.instruction |= Rm; | |
c19d1205 | 12552 | } |
b99bd4ef | 12553 | |
c19d1205 ZW |
12554 | static void |
12555 | do_t_rev (void) | |
12556 | { | |
fdfde340 JM |
12557 | unsigned Rd, Rm; |
12558 | ||
12559 | Rd = inst.operands[0].reg; | |
12560 | Rm = inst.operands[1].reg; | |
12561 | ||
12562 | reject_bad_reg (Rd); | |
12563 | reject_bad_reg (Rm); | |
12564 | ||
12565 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
12566 | && inst.size_req != 4) |
12567 | { | |
12568 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
12569 | inst.instruction |= Rd; |
12570 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12571 | } |
12572 | else if (unified_syntax) | |
12573 | { | |
12574 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12575 | inst.instruction |= Rd << 8; |
12576 | inst.instruction |= Rm << 16; | |
12577 | inst.instruction |= Rm; | |
c19d1205 ZW |
12578 | } |
12579 | else | |
12580 | inst.error = BAD_HIREG; | |
12581 | } | |
b99bd4ef | 12582 | |
1c444d06 JM |
12583 | static void |
12584 | do_t_rrx (void) | |
12585 | { | |
12586 | unsigned Rd, Rm; | |
12587 | ||
12588 | Rd = inst.operands[0].reg; | |
12589 | Rm = inst.operands[1].reg; | |
12590 | ||
fdfde340 JM |
12591 | reject_bad_reg (Rd); |
12592 | reject_bad_reg (Rm); | |
c921be7d | 12593 | |
1c444d06 JM |
12594 | inst.instruction |= Rd << 8; |
12595 | inst.instruction |= Rm; | |
12596 | } | |
12597 | ||
c19d1205 ZW |
12598 | static void |
12599 | do_t_rsb (void) | |
12600 | { | |
fdfde340 | 12601 | unsigned Rd, Rs; |
b99bd4ef | 12602 | |
c19d1205 ZW |
12603 | Rd = inst.operands[0].reg; |
12604 | Rs = (inst.operands[1].present | |
12605 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
12606 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 12607 | |
fdfde340 JM |
12608 | reject_bad_reg (Rd); |
12609 | reject_bad_reg (Rs); | |
12610 | if (inst.operands[2].isreg) | |
12611 | reject_bad_reg (inst.operands[2].reg); | |
12612 | ||
c19d1205 ZW |
12613 | inst.instruction |= Rd << 8; |
12614 | inst.instruction |= Rs << 16; | |
12615 | if (!inst.operands[2].isreg) | |
12616 | { | |
026d3abb PB |
12617 | bfd_boolean narrow; |
12618 | ||
12619 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 12620 | narrow = !in_it_block (); |
026d3abb | 12621 | else |
e07e6e58 | 12622 | narrow = in_it_block (); |
026d3abb PB |
12623 | |
12624 | if (Rd > 7 || Rs > 7) | |
12625 | narrow = FALSE; | |
12626 | ||
12627 | if (inst.size_req == 4 || !unified_syntax) | |
12628 | narrow = FALSE; | |
12629 | ||
12630 | if (inst.reloc.exp.X_op != O_constant | |
12631 | || inst.reloc.exp.X_add_number != 0) | |
12632 | narrow = FALSE; | |
12633 | ||
12634 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
477330fc | 12635 | relaxation, but it doesn't seem worth the hassle. */ |
026d3abb PB |
12636 | if (narrow) |
12637 | { | |
12638 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12639 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
12640 | inst.instruction |= Rs << 3; | |
12641 | inst.instruction |= Rd; | |
12642 | } | |
12643 | else | |
12644 | { | |
12645 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
12646 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
12647 | } | |
c19d1205 ZW |
12648 | } |
12649 | else | |
12650 | encode_thumb32_shifted_operand (2); | |
12651 | } | |
b99bd4ef | 12652 | |
c19d1205 ZW |
12653 | static void |
12654 | do_t_setend (void) | |
12655 | { | |
12e37cbc MGD |
12656 | if (warn_on_deprecated |
12657 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 12658 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 12659 | |
e07e6e58 | 12660 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
12661 | if (inst.operands[0].imm) |
12662 | inst.instruction |= 0x8; | |
12663 | } | |
b99bd4ef | 12664 | |
c19d1205 ZW |
12665 | static void |
12666 | do_t_shift (void) | |
12667 | { | |
12668 | if (!inst.operands[1].present) | |
12669 | inst.operands[1].reg = inst.operands[0].reg; | |
12670 | ||
12671 | if (unified_syntax) | |
12672 | { | |
3d388997 PB |
12673 | bfd_boolean narrow; |
12674 | int shift_kind; | |
12675 | ||
12676 | switch (inst.instruction) | |
12677 | { | |
12678 | case T_MNEM_asr: | |
12679 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
12680 | case T_MNEM_lsl: | |
12681 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
12682 | case T_MNEM_lsr: | |
12683 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
12684 | case T_MNEM_ror: | |
12685 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
12686 | default: abort (); | |
12687 | } | |
12688 | ||
12689 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12690 | narrow = !in_it_block (); |
3d388997 | 12691 | else |
e07e6e58 | 12692 | narrow = in_it_block (); |
3d388997 PB |
12693 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12694 | narrow = FALSE; | |
12695 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
12696 | narrow = FALSE; | |
12697 | if (inst.operands[2].isreg | |
12698 | && (inst.operands[1].reg != inst.operands[0].reg | |
12699 | || inst.operands[2].reg > 7)) | |
12700 | narrow = FALSE; | |
12701 | if (inst.size_req == 4) | |
12702 | narrow = FALSE; | |
12703 | ||
fdfde340 JM |
12704 | reject_bad_reg (inst.operands[0].reg); |
12705 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 12706 | |
3d388997 | 12707 | if (!narrow) |
c19d1205 ZW |
12708 | { |
12709 | if (inst.operands[2].isreg) | |
b99bd4ef | 12710 | { |
fdfde340 | 12711 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
12712 | inst.instruction = THUMB_OP32 (inst.instruction); |
12713 | inst.instruction |= inst.operands[0].reg << 8; | |
12714 | inst.instruction |= inst.operands[1].reg << 16; | |
12715 | inst.instruction |= inst.operands[2].reg; | |
94342ec3 NC |
12716 | |
12717 | /* PR 12854: Error on extraneous shifts. */ | |
12718 | constraint (inst.operands[2].shifted, | |
12719 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
12720 | } |
12721 | else | |
12722 | { | |
12723 | inst.operands[1].shifted = 1; | |
3d388997 | 12724 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
12725 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
12726 | ? T_MNEM_movs : T_MNEM_mov); | |
12727 | inst.instruction |= inst.operands[0].reg << 8; | |
12728 | encode_thumb32_shifted_operand (1); | |
12729 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
12730 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
12731 | } |
12732 | } | |
12733 | else | |
12734 | { | |
c19d1205 | 12735 | if (inst.operands[2].isreg) |
b99bd4ef | 12736 | { |
3d388997 | 12737 | switch (shift_kind) |
b99bd4ef | 12738 | { |
3d388997 PB |
12739 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
12740 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
12741 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
12742 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 12743 | default: abort (); |
b99bd4ef | 12744 | } |
5f4273c7 | 12745 | |
c19d1205 ZW |
12746 | inst.instruction |= inst.operands[0].reg; |
12747 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
12748 | |
12749 | /* PR 12854: Error on extraneous shifts. */ | |
12750 | constraint (inst.operands[2].shifted, | |
12751 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
12752 | } |
12753 | else | |
12754 | { | |
3d388997 | 12755 | switch (shift_kind) |
b99bd4ef | 12756 | { |
3d388997 PB |
12757 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
12758 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
12759 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 12760 | default: abort (); |
b99bd4ef | 12761 | } |
c19d1205 ZW |
12762 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
12763 | inst.instruction |= inst.operands[0].reg; | |
12764 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
12765 | } |
12766 | } | |
c19d1205 ZW |
12767 | } |
12768 | else | |
12769 | { | |
12770 | constraint (inst.operands[0].reg > 7 | |
12771 | || inst.operands[1].reg > 7, BAD_HIREG); | |
12772 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 12773 | |
c19d1205 ZW |
12774 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
12775 | { | |
12776 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
12777 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
12778 | _("source1 and dest must be same register")); | |
b99bd4ef | 12779 | |
c19d1205 ZW |
12780 | switch (inst.instruction) |
12781 | { | |
12782 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
12783 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
12784 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
12785 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
12786 | default: abort (); | |
12787 | } | |
5f4273c7 | 12788 | |
c19d1205 ZW |
12789 | inst.instruction |= inst.operands[0].reg; |
12790 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
12791 | |
12792 | /* PR 12854: Error on extraneous shifts. */ | |
12793 | constraint (inst.operands[2].shifted, | |
12794 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
12795 | } |
12796 | else | |
b99bd4ef | 12797 | { |
c19d1205 ZW |
12798 | switch (inst.instruction) |
12799 | { | |
12800 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
12801 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
12802 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
12803 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
12804 | default: abort (); | |
12805 | } | |
12806 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
12807 | inst.instruction |= inst.operands[0].reg; | |
12808 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
12809 | } |
12810 | } | |
b99bd4ef NC |
12811 | } |
12812 | ||
12813 | static void | |
c19d1205 | 12814 | do_t_simd (void) |
b99bd4ef | 12815 | { |
fdfde340 JM |
12816 | unsigned Rd, Rn, Rm; |
12817 | ||
12818 | Rd = inst.operands[0].reg; | |
12819 | Rn = inst.operands[1].reg; | |
12820 | Rm = inst.operands[2].reg; | |
12821 | ||
12822 | reject_bad_reg (Rd); | |
12823 | reject_bad_reg (Rn); | |
12824 | reject_bad_reg (Rm); | |
12825 | ||
12826 | inst.instruction |= Rd << 8; | |
12827 | inst.instruction |= Rn << 16; | |
12828 | inst.instruction |= Rm; | |
c19d1205 | 12829 | } |
b99bd4ef | 12830 | |
03ee1b7f NC |
12831 | static void |
12832 | do_t_simd2 (void) | |
12833 | { | |
12834 | unsigned Rd, Rn, Rm; | |
12835 | ||
12836 | Rd = inst.operands[0].reg; | |
12837 | Rm = inst.operands[1].reg; | |
12838 | Rn = inst.operands[2].reg; | |
12839 | ||
12840 | reject_bad_reg (Rd); | |
12841 | reject_bad_reg (Rn); | |
12842 | reject_bad_reg (Rm); | |
12843 | ||
12844 | inst.instruction |= Rd << 8; | |
12845 | inst.instruction |= Rn << 16; | |
12846 | inst.instruction |= Rm; | |
12847 | } | |
12848 | ||
c19d1205 | 12849 | static void |
3eb17e6b | 12850 | do_t_smc (void) |
c19d1205 ZW |
12851 | { |
12852 | unsigned int value = inst.reloc.exp.X_add_number; | |
f4c65163 MGD |
12853 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
12854 | _("SMC is not permitted on this architecture")); | |
c19d1205 ZW |
12855 | constraint (inst.reloc.exp.X_op != O_constant, |
12856 | _("expression too complex")); | |
12857 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12858 | inst.instruction |= (value & 0xf000) >> 12; | |
12859 | inst.instruction |= (value & 0x0ff0); | |
12860 | inst.instruction |= (value & 0x000f) << 16; | |
24382199 NC |
12861 | /* PR gas/15623: SMC instructions must be last in an IT block. */ |
12862 | set_it_insn_type_last (); | |
c19d1205 | 12863 | } |
b99bd4ef | 12864 | |
90ec0d68 MGD |
12865 | static void |
12866 | do_t_hvc (void) | |
12867 | { | |
12868 | unsigned int value = inst.reloc.exp.X_add_number; | |
12869 | ||
12870 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12871 | inst.instruction |= (value & 0x0fff); | |
12872 | inst.instruction |= (value & 0xf000) << 4; | |
12873 | } | |
12874 | ||
c19d1205 | 12875 | static void |
3a21c15a | 12876 | do_t_ssat_usat (int bias) |
c19d1205 | 12877 | { |
fdfde340 JM |
12878 | unsigned Rd, Rn; |
12879 | ||
12880 | Rd = inst.operands[0].reg; | |
12881 | Rn = inst.operands[2].reg; | |
12882 | ||
12883 | reject_bad_reg (Rd); | |
12884 | reject_bad_reg (Rn); | |
12885 | ||
12886 | inst.instruction |= Rd << 8; | |
3a21c15a | 12887 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 12888 | inst.instruction |= Rn << 16; |
b99bd4ef | 12889 | |
c19d1205 | 12890 | if (inst.operands[3].present) |
b99bd4ef | 12891 | { |
3a21c15a NC |
12892 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
12893 | ||
12894 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12895 | ||
c19d1205 ZW |
12896 | constraint (inst.reloc.exp.X_op != O_constant, |
12897 | _("expression too complex")); | |
b99bd4ef | 12898 | |
3a21c15a | 12899 | if (shift_amount != 0) |
6189168b | 12900 | { |
3a21c15a NC |
12901 | constraint (shift_amount > 31, |
12902 | _("shift expression is too large")); | |
12903 | ||
c19d1205 | 12904 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
12905 | inst.instruction |= 0x00200000; /* sh bit. */ |
12906 | ||
12907 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
12908 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
12909 | } |
12910 | } | |
b99bd4ef | 12911 | } |
c921be7d | 12912 | |
3a21c15a NC |
12913 | static void |
12914 | do_t_ssat (void) | |
12915 | { | |
12916 | do_t_ssat_usat (1); | |
12917 | } | |
b99bd4ef | 12918 | |
0dd132b6 | 12919 | static void |
c19d1205 | 12920 | do_t_ssat16 (void) |
0dd132b6 | 12921 | { |
fdfde340 JM |
12922 | unsigned Rd, Rn; |
12923 | ||
12924 | Rd = inst.operands[0].reg; | |
12925 | Rn = inst.operands[2].reg; | |
12926 | ||
12927 | reject_bad_reg (Rd); | |
12928 | reject_bad_reg (Rn); | |
12929 | ||
12930 | inst.instruction |= Rd << 8; | |
c19d1205 | 12931 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 12932 | inst.instruction |= Rn << 16; |
c19d1205 | 12933 | } |
0dd132b6 | 12934 | |
c19d1205 ZW |
12935 | static void |
12936 | do_t_strex (void) | |
12937 | { | |
12938 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
12939 | || inst.operands[2].postind || inst.operands[2].writeback | |
12940 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
12941 | || inst.operands[2].negative, | |
01cfc07f | 12942 | BAD_ADDR_MODE); |
0dd132b6 | 12943 | |
5be8be5d DG |
12944 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
12945 | ||
c19d1205 ZW |
12946 | inst.instruction |= inst.operands[0].reg << 8; |
12947 | inst.instruction |= inst.operands[1].reg << 12; | |
12948 | inst.instruction |= inst.operands[2].reg << 16; | |
12949 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
12950 | } |
12951 | ||
b99bd4ef | 12952 | static void |
c19d1205 | 12953 | do_t_strexd (void) |
b99bd4ef | 12954 | { |
c19d1205 ZW |
12955 | if (!inst.operands[2].present) |
12956 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 12957 | |
c19d1205 ZW |
12958 | constraint (inst.operands[0].reg == inst.operands[1].reg |
12959 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 12960 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 12961 | BAD_OVERLAP); |
b99bd4ef | 12962 | |
c19d1205 ZW |
12963 | inst.instruction |= inst.operands[0].reg; |
12964 | inst.instruction |= inst.operands[1].reg << 12; | |
12965 | inst.instruction |= inst.operands[2].reg << 8; | |
12966 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
12967 | } |
12968 | ||
12969 | static void | |
c19d1205 | 12970 | do_t_sxtah (void) |
b99bd4ef | 12971 | { |
fdfde340 JM |
12972 | unsigned Rd, Rn, Rm; |
12973 | ||
12974 | Rd = inst.operands[0].reg; | |
12975 | Rn = inst.operands[1].reg; | |
12976 | Rm = inst.operands[2].reg; | |
12977 | ||
12978 | reject_bad_reg (Rd); | |
12979 | reject_bad_reg (Rn); | |
12980 | reject_bad_reg (Rm); | |
12981 | ||
12982 | inst.instruction |= Rd << 8; | |
12983 | inst.instruction |= Rn << 16; | |
12984 | inst.instruction |= Rm; | |
c19d1205 ZW |
12985 | inst.instruction |= inst.operands[3].imm << 4; |
12986 | } | |
b99bd4ef | 12987 | |
c19d1205 ZW |
12988 | static void |
12989 | do_t_sxth (void) | |
12990 | { | |
fdfde340 JM |
12991 | unsigned Rd, Rm; |
12992 | ||
12993 | Rd = inst.operands[0].reg; | |
12994 | Rm = inst.operands[1].reg; | |
12995 | ||
12996 | reject_bad_reg (Rd); | |
12997 | reject_bad_reg (Rm); | |
c921be7d NC |
12998 | |
12999 | if (inst.instruction <= 0xffff | |
13000 | && inst.size_req != 4 | |
fdfde340 | 13001 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 13002 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 13003 | { |
c19d1205 | 13004 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
13005 | inst.instruction |= Rd; |
13006 | inst.instruction |= Rm << 3; | |
b99bd4ef | 13007 | } |
c19d1205 | 13008 | else if (unified_syntax) |
b99bd4ef | 13009 | { |
c19d1205 ZW |
13010 | if (inst.instruction <= 0xffff) |
13011 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
13012 | inst.instruction |= Rd << 8; |
13013 | inst.instruction |= Rm; | |
c19d1205 | 13014 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 13015 | } |
c19d1205 | 13016 | else |
b99bd4ef | 13017 | { |
c19d1205 ZW |
13018 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
13019 | _("Thumb encoding does not support rotation")); | |
13020 | constraint (1, BAD_HIREG); | |
b99bd4ef | 13021 | } |
c19d1205 | 13022 | } |
b99bd4ef | 13023 | |
c19d1205 ZW |
13024 | static void |
13025 | do_t_swi (void) | |
13026 | { | |
b2a5fbdc MGD |
13027 | /* We have to do the following check manually as ARM_EXT_OS only applies |
13028 | to ARM_EXT_V6M. */ | |
13029 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m)) | |
13030 | { | |
ac7f631b NC |
13031 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os) |
13032 | /* This only applies to the v6m howver, not later architectures. */ | |
13033 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)) | |
b2a5fbdc MGD |
13034 | as_bad (_("SVC is not permitted on this architecture")); |
13035 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os); | |
13036 | } | |
13037 | ||
c19d1205 ZW |
13038 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
13039 | } | |
b99bd4ef | 13040 | |
92e90b6e PB |
13041 | static void |
13042 | do_t_tb (void) | |
13043 | { | |
fdfde340 | 13044 | unsigned Rn, Rm; |
92e90b6e PB |
13045 | int half; |
13046 | ||
13047 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 13048 | set_it_insn_type_last (); |
dfa9f0d5 PB |
13049 | constraint (inst.operands[0].immisreg, |
13050 | _("instruction requires register index")); | |
fdfde340 JM |
13051 | |
13052 | Rn = inst.operands[0].reg; | |
13053 | Rm = inst.operands[0].imm; | |
c921be7d | 13054 | |
fdfde340 JM |
13055 | constraint (Rn == REG_SP, BAD_SP); |
13056 | reject_bad_reg (Rm); | |
13057 | ||
92e90b6e PB |
13058 | constraint (!half && inst.operands[0].shifted, |
13059 | _("instruction does not allow shifted index")); | |
fdfde340 | 13060 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
13061 | } |
13062 | ||
74db7efb NC |
13063 | static void |
13064 | do_t_udf (void) | |
13065 | { | |
13066 | if (!inst.operands[0].present) | |
13067 | inst.operands[0].imm = 0; | |
13068 | ||
13069 | if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4) | |
13070 | { | |
13071 | constraint (inst.size_req == 2, | |
13072 | _("immediate value out of range")); | |
13073 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13074 | inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4; | |
13075 | inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0; | |
13076 | } | |
13077 | else | |
13078 | { | |
13079 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13080 | inst.instruction |= inst.operands[0].imm; | |
13081 | } | |
13082 | ||
13083 | set_it_insn_type (NEUTRAL_IT_INSN); | |
13084 | } | |
13085 | ||
13086 | ||
c19d1205 ZW |
13087 | static void |
13088 | do_t_usat (void) | |
13089 | { | |
3a21c15a | 13090 | do_t_ssat_usat (0); |
b99bd4ef NC |
13091 | } |
13092 | ||
13093 | static void | |
c19d1205 | 13094 | do_t_usat16 (void) |
b99bd4ef | 13095 | { |
fdfde340 JM |
13096 | unsigned Rd, Rn; |
13097 | ||
13098 | Rd = inst.operands[0].reg; | |
13099 | Rn = inst.operands[2].reg; | |
13100 | ||
13101 | reject_bad_reg (Rd); | |
13102 | reject_bad_reg (Rn); | |
13103 | ||
13104 | inst.instruction |= Rd << 8; | |
c19d1205 | 13105 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 13106 | inst.instruction |= Rn << 16; |
b99bd4ef | 13107 | } |
c19d1205 | 13108 | |
5287ad62 | 13109 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 13110 | |
5287ad62 | 13111 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 13112 | |
5287ad62 JB |
13113 | /* An "invalid" code for the following tables. */ |
13114 | #define N_INV -1u | |
13115 | ||
13116 | struct neon_tab_entry | |
b99bd4ef | 13117 | { |
5287ad62 JB |
13118 | unsigned integer; |
13119 | unsigned float_or_poly; | |
13120 | unsigned scalar_or_imm; | |
13121 | }; | |
5f4273c7 | 13122 | |
5287ad62 JB |
13123 | /* Map overloaded Neon opcodes to their respective encodings. */ |
13124 | #define NEON_ENC_TAB \ | |
13125 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
13126 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
13127 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
13128 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
13129 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
13130 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
13131 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
13132 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
13133 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
13134 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
13135 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
13136 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 13137 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
13138 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
13139 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
13140 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
13141 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
13142 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
13143 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
13144 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
13145 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
13146 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
13147 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
13148 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
13149 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
13150 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
13151 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
13152 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
d6b4b13e MW |
13153 | X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \ |
13154 | X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \ | |
5287ad62 JB |
13155 | X(vshl, 0x0000400, N_INV, 0x0800510), \ |
13156 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
13157 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
13158 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
13159 | X(veor, 0x1000110, N_INV, N_INV), \ | |
13160 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
13161 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
13162 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
13163 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
13164 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
13165 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
13166 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
13167 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
13168 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
13169 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
13170 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
13171 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
13172 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
13173 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
13174 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
13175 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
13176 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
13177 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
13178 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
13179 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
13180 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
13181 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
13182 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
13183 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
13184 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
13185 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
13186 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \ |
13187 | X(vseleq, 0xe000a00, N_INV, N_INV), \ | |
13188 | X(vselvs, 0xe100a00, N_INV, N_INV), \ | |
13189 | X(vselge, 0xe200a00, N_INV, N_INV), \ | |
73924fbc MGD |
13190 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
13191 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 13192 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
13193 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
13194 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 13195 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 13196 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
13197 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
13198 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
13199 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
13200 | |
13201 | enum neon_opc | |
13202 | { | |
13203 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
13204 | NEON_ENC_TAB | |
13205 | #undef X | |
13206 | }; | |
b99bd4ef | 13207 | |
5287ad62 JB |
13208 | static const struct neon_tab_entry neon_enc_tab[] = |
13209 | { | |
13210 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
13211 | NEON_ENC_TAB | |
13212 | #undef X | |
13213 | }; | |
b99bd4ef | 13214 | |
88714cb8 DG |
13215 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
13216 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13217 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13218 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13219 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13220 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13221 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13222 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13223 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13224 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13225 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 13226 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 13227 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 13228 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
13229 | #define NEON_ENC_FPV8_(X) \ |
13230 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 13231 | |
88714cb8 DG |
13232 | #define NEON_ENCODE(type, inst) \ |
13233 | do \ | |
13234 | { \ | |
13235 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
13236 | inst.is_neon = 1; \ | |
13237 | } \ | |
13238 | while (0) | |
13239 | ||
13240 | #define check_neon_suffixes \ | |
13241 | do \ | |
13242 | { \ | |
13243 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
13244 | { \ | |
13245 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
13246 | return; \ | |
13247 | } \ | |
13248 | } \ | |
13249 | while (0) | |
13250 | ||
037e8744 JB |
13251 | /* Define shapes for instruction operands. The following mnemonic characters |
13252 | are used in this table: | |
5287ad62 | 13253 | |
037e8744 | 13254 | F - VFP S<n> register |
5287ad62 JB |
13255 | D - Neon D<n> register |
13256 | Q - Neon Q<n> register | |
13257 | I - Immediate | |
13258 | S - Scalar | |
13259 | R - ARM register | |
13260 | L - D<n> register list | |
5f4273c7 | 13261 | |
037e8744 JB |
13262 | This table is used to generate various data: |
13263 | - enumerations of the form NS_DDR to be used as arguments to | |
13264 | neon_select_shape. | |
13265 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 13266 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 13267 | |
037e8744 JB |
13268 | #define NEON_SHAPE_DEF \ |
13269 | X(3, (D, D, D), DOUBLE), \ | |
13270 | X(3, (Q, Q, Q), QUAD), \ | |
13271 | X(3, (D, D, I), DOUBLE), \ | |
13272 | X(3, (Q, Q, I), QUAD), \ | |
13273 | X(3, (D, D, S), DOUBLE), \ | |
13274 | X(3, (Q, Q, S), QUAD), \ | |
13275 | X(2, (D, D), DOUBLE), \ | |
13276 | X(2, (Q, Q), QUAD), \ | |
13277 | X(2, (D, S), DOUBLE), \ | |
13278 | X(2, (Q, S), QUAD), \ | |
13279 | X(2, (D, R), DOUBLE), \ | |
13280 | X(2, (Q, R), QUAD), \ | |
13281 | X(2, (D, I), DOUBLE), \ | |
13282 | X(2, (Q, I), QUAD), \ | |
13283 | X(3, (D, L, D), DOUBLE), \ | |
13284 | X(2, (D, Q), MIXED), \ | |
13285 | X(2, (Q, D), MIXED), \ | |
13286 | X(3, (D, Q, I), MIXED), \ | |
13287 | X(3, (Q, D, I), MIXED), \ | |
13288 | X(3, (Q, D, D), MIXED), \ | |
13289 | X(3, (D, Q, Q), MIXED), \ | |
13290 | X(3, (Q, Q, D), MIXED), \ | |
13291 | X(3, (Q, D, S), MIXED), \ | |
13292 | X(3, (D, Q, S), MIXED), \ | |
13293 | X(4, (D, D, D, I), DOUBLE), \ | |
13294 | X(4, (Q, Q, Q, I), QUAD), \ | |
13295 | X(2, (F, F), SINGLE), \ | |
13296 | X(3, (F, F, F), SINGLE), \ | |
13297 | X(2, (F, I), SINGLE), \ | |
13298 | X(2, (F, D), MIXED), \ | |
13299 | X(2, (D, F), MIXED), \ | |
13300 | X(3, (F, F, I), MIXED), \ | |
13301 | X(4, (R, R, F, F), SINGLE), \ | |
13302 | X(4, (F, F, R, R), SINGLE), \ | |
13303 | X(3, (D, R, R), DOUBLE), \ | |
13304 | X(3, (R, R, D), DOUBLE), \ | |
13305 | X(2, (S, R), SINGLE), \ | |
13306 | X(2, (R, S), SINGLE), \ | |
13307 | X(2, (F, R), SINGLE), \ | |
d54af2d0 RL |
13308 | X(2, (R, F), SINGLE), \ |
13309 | /* Half float shape supported so far. */\ | |
13310 | X (2, (H, D), MIXED), \ | |
13311 | X (2, (D, H), MIXED), \ | |
13312 | X (2, (H, F), MIXED), \ | |
13313 | X (2, (F, H), MIXED), \ | |
13314 | X (2, (H, H), HALF), \ | |
13315 | X (2, (H, R), HALF), \ | |
13316 | X (2, (R, H), HALF), \ | |
13317 | X (2, (H, I), HALF), \ | |
13318 | X (3, (H, H, H), HALF), \ | |
13319 | X (3, (H, F, I), MIXED), \ | |
13320 | X (3, (F, H, I), MIXED) | |
037e8744 JB |
13321 | |
13322 | #define S2(A,B) NS_##A##B | |
13323 | #define S3(A,B,C) NS_##A##B##C | |
13324 | #define S4(A,B,C,D) NS_##A##B##C##D | |
13325 | ||
13326 | #define X(N, L, C) S##N L | |
13327 | ||
5287ad62 JB |
13328 | enum neon_shape |
13329 | { | |
037e8744 JB |
13330 | NEON_SHAPE_DEF, |
13331 | NS_NULL | |
5287ad62 | 13332 | }; |
b99bd4ef | 13333 | |
037e8744 JB |
13334 | #undef X |
13335 | #undef S2 | |
13336 | #undef S3 | |
13337 | #undef S4 | |
13338 | ||
13339 | enum neon_shape_class | |
13340 | { | |
d54af2d0 | 13341 | SC_HALF, |
037e8744 JB |
13342 | SC_SINGLE, |
13343 | SC_DOUBLE, | |
13344 | SC_QUAD, | |
13345 | SC_MIXED | |
13346 | }; | |
13347 | ||
13348 | #define X(N, L, C) SC_##C | |
13349 | ||
13350 | static enum neon_shape_class neon_shape_class[] = | |
13351 | { | |
13352 | NEON_SHAPE_DEF | |
13353 | }; | |
13354 | ||
13355 | #undef X | |
13356 | ||
13357 | enum neon_shape_el | |
13358 | { | |
d54af2d0 | 13359 | SE_H, |
037e8744 JB |
13360 | SE_F, |
13361 | SE_D, | |
13362 | SE_Q, | |
13363 | SE_I, | |
13364 | SE_S, | |
13365 | SE_R, | |
13366 | SE_L | |
13367 | }; | |
13368 | ||
13369 | /* Register widths of above. */ | |
13370 | static unsigned neon_shape_el_size[] = | |
13371 | { | |
d54af2d0 | 13372 | 16, |
037e8744 JB |
13373 | 32, |
13374 | 64, | |
13375 | 128, | |
13376 | 0, | |
13377 | 32, | |
13378 | 32, | |
13379 | 0 | |
13380 | }; | |
13381 | ||
13382 | struct neon_shape_info | |
13383 | { | |
13384 | unsigned els; | |
13385 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
13386 | }; | |
13387 | ||
13388 | #define S2(A,B) { SE_##A, SE_##B } | |
13389 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
13390 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
13391 | ||
13392 | #define X(N, L, C) { N, S##N L } | |
13393 | ||
13394 | static struct neon_shape_info neon_shape_tab[] = | |
13395 | { | |
13396 | NEON_SHAPE_DEF | |
13397 | }; | |
13398 | ||
13399 | #undef X | |
13400 | #undef S2 | |
13401 | #undef S3 | |
13402 | #undef S4 | |
13403 | ||
5287ad62 JB |
13404 | /* Bit masks used in type checking given instructions. |
13405 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
13406 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
13407 | set, various other bits can be set as well in order to modify the meaning of | |
13408 | the type constraint. */ | |
13409 | ||
13410 | enum neon_type_mask | |
13411 | { | |
8e79c3df CM |
13412 | N_S8 = 0x0000001, |
13413 | N_S16 = 0x0000002, | |
13414 | N_S32 = 0x0000004, | |
13415 | N_S64 = 0x0000008, | |
13416 | N_U8 = 0x0000010, | |
13417 | N_U16 = 0x0000020, | |
13418 | N_U32 = 0x0000040, | |
13419 | N_U64 = 0x0000080, | |
13420 | N_I8 = 0x0000100, | |
13421 | N_I16 = 0x0000200, | |
13422 | N_I32 = 0x0000400, | |
13423 | N_I64 = 0x0000800, | |
13424 | N_8 = 0x0001000, | |
13425 | N_16 = 0x0002000, | |
13426 | N_32 = 0x0004000, | |
13427 | N_64 = 0x0008000, | |
13428 | N_P8 = 0x0010000, | |
13429 | N_P16 = 0x0020000, | |
13430 | N_F16 = 0x0040000, | |
13431 | N_F32 = 0x0080000, | |
13432 | N_F64 = 0x0100000, | |
4f51b4bd | 13433 | N_P64 = 0x0200000, |
c921be7d NC |
13434 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
13435 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 13436 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 13437 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
13438 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
13439 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
13440 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
13441 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
13442 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
13443 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
13444 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 13445 | N_UTYP = 0, |
4f51b4bd | 13446 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
13447 | }; |
13448 | ||
dcbf9037 JB |
13449 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
13450 | ||
5287ad62 JB |
13451 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
13452 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
13453 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
cc933301 JW |
13454 | #define N_S_32 (N_S8 | N_S16 | N_S32) |
13455 | #define N_F_16_32 (N_F16 | N_F32) | |
13456 | #define N_SUF_32 (N_SU_32 | N_F_16_32) | |
5287ad62 | 13457 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) |
cc933301 | 13458 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32) |
d54af2d0 | 13459 | #define N_F_ALL (N_F16 | N_F32 | N_F64) |
5287ad62 JB |
13460 | |
13461 | /* Pass this as the first type argument to neon_check_type to ignore types | |
13462 | altogether. */ | |
13463 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
13464 | ||
037e8744 JB |
13465 | /* Select a "shape" for the current instruction (describing register types or |
13466 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
13467 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
13468 | function of operand parsing, so this function doesn't need to be called. | |
13469 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
13470 | |
13471 | static enum neon_shape | |
037e8744 | 13472 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 13473 | { |
037e8744 JB |
13474 | va_list ap; |
13475 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
13476 | |
13477 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
13478 | many arguments we should have, so this makes the assumption that we have | |
13479 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
13480 | true in the future. */ | |
13481 | if (!inst.operands[1].present) | |
13482 | inst.operands[1] = inst.operands[0]; | |
13483 | ||
037e8744 | 13484 | va_start (ap, shape); |
5f4273c7 | 13485 | |
21d799b5 | 13486 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
13487 | { |
13488 | unsigned j; | |
13489 | int matches = 1; | |
13490 | ||
13491 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
477330fc RM |
13492 | { |
13493 | if (!inst.operands[j].present) | |
13494 | { | |
13495 | matches = 0; | |
13496 | break; | |
13497 | } | |
13498 | ||
13499 | switch (neon_shape_tab[shape].el[j]) | |
13500 | { | |
d54af2d0 RL |
13501 | /* If a .f16, .16, .u16, .s16 type specifier is given over |
13502 | a VFP single precision register operand, it's essentially | |
13503 | means only half of the register is used. | |
13504 | ||
13505 | If the type specifier is given after the mnemonics, the | |
13506 | information is stored in inst.vectype. If the type specifier | |
13507 | is given after register operand, the information is stored | |
13508 | in inst.operands[].vectype. | |
13509 | ||
13510 | When there is only one type specifier, and all the register | |
13511 | operands are the same type of hardware register, the type | |
13512 | specifier applies to all register operands. | |
13513 | ||
13514 | If no type specifier is given, the shape is inferred from | |
13515 | operand information. | |
13516 | ||
13517 | for example: | |
13518 | vadd.f16 s0, s1, s2: NS_HHH | |
13519 | vabs.f16 s0, s1: NS_HH | |
13520 | vmov.f16 s0, r1: NS_HR | |
13521 | vmov.f16 r0, s1: NS_RH | |
13522 | vcvt.f16 r0, s1: NS_RH | |
13523 | vcvt.f16.s32 s2, s2, #29: NS_HFI | |
13524 | vcvt.f16.s32 s2, s2: NS_HF | |
13525 | */ | |
13526 | case SE_H: | |
13527 | if (!(inst.operands[j].isreg | |
13528 | && inst.operands[j].isvec | |
13529 | && inst.operands[j].issingle | |
13530 | && !inst.operands[j].isquad | |
13531 | && ((inst.vectype.elems == 1 | |
13532 | && inst.vectype.el[0].size == 16) | |
13533 | || (inst.vectype.elems > 1 | |
13534 | && inst.vectype.el[j].size == 16) | |
13535 | || (inst.vectype.elems == 0 | |
13536 | && inst.operands[j].vectype.type != NT_invtype | |
13537 | && inst.operands[j].vectype.size == 16)))) | |
13538 | matches = 0; | |
13539 | break; | |
13540 | ||
477330fc RM |
13541 | case SE_F: |
13542 | if (!(inst.operands[j].isreg | |
13543 | && inst.operands[j].isvec | |
13544 | && inst.operands[j].issingle | |
d54af2d0 RL |
13545 | && !inst.operands[j].isquad |
13546 | && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32) | |
13547 | || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32) | |
13548 | || (inst.vectype.elems == 0 | |
13549 | && (inst.operands[j].vectype.size == 32 | |
13550 | || inst.operands[j].vectype.type == NT_invtype))))) | |
477330fc RM |
13551 | matches = 0; |
13552 | break; | |
13553 | ||
13554 | case SE_D: | |
13555 | if (!(inst.operands[j].isreg | |
13556 | && inst.operands[j].isvec | |
13557 | && !inst.operands[j].isquad | |
13558 | && !inst.operands[j].issingle)) | |
13559 | matches = 0; | |
13560 | break; | |
13561 | ||
13562 | case SE_R: | |
13563 | if (!(inst.operands[j].isreg | |
13564 | && !inst.operands[j].isvec)) | |
13565 | matches = 0; | |
13566 | break; | |
13567 | ||
13568 | case SE_Q: | |
13569 | if (!(inst.operands[j].isreg | |
13570 | && inst.operands[j].isvec | |
13571 | && inst.operands[j].isquad | |
13572 | && !inst.operands[j].issingle)) | |
13573 | matches = 0; | |
13574 | break; | |
13575 | ||
13576 | case SE_I: | |
13577 | if (!(!inst.operands[j].isreg | |
13578 | && !inst.operands[j].isscalar)) | |
13579 | matches = 0; | |
13580 | break; | |
13581 | ||
13582 | case SE_S: | |
13583 | if (!(!inst.operands[j].isreg | |
13584 | && inst.operands[j].isscalar)) | |
13585 | matches = 0; | |
13586 | break; | |
13587 | ||
13588 | case SE_L: | |
13589 | break; | |
13590 | } | |
3fde54a2 JZ |
13591 | if (!matches) |
13592 | break; | |
477330fc | 13593 | } |
ad6cec43 MGD |
13594 | if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present)) |
13595 | /* We've matched all the entries in the shape table, and we don't | |
13596 | have any left over operands which have not been matched. */ | |
477330fc | 13597 | break; |
037e8744 | 13598 | } |
5f4273c7 | 13599 | |
037e8744 | 13600 | va_end (ap); |
5287ad62 | 13601 | |
037e8744 JB |
13602 | if (shape == NS_NULL && first_shape != NS_NULL) |
13603 | first_error (_("invalid instruction shape")); | |
5287ad62 | 13604 | |
037e8744 JB |
13605 | return shape; |
13606 | } | |
5287ad62 | 13607 | |
037e8744 JB |
13608 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
13609 | means the Q bit should be set). */ | |
13610 | ||
13611 | static int | |
13612 | neon_quad (enum neon_shape shape) | |
13613 | { | |
13614 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 13615 | } |
037e8744 | 13616 | |
5287ad62 JB |
13617 | static void |
13618 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
477330fc | 13619 | unsigned *g_size) |
5287ad62 JB |
13620 | { |
13621 | /* Allow modification to be made to types which are constrained to be | |
13622 | based on the key element, based on bits set alongside N_EQK. */ | |
13623 | if ((typebits & N_EQK) != 0) | |
13624 | { | |
13625 | if ((typebits & N_HLF) != 0) | |
13626 | *g_size /= 2; | |
13627 | else if ((typebits & N_DBL) != 0) | |
13628 | *g_size *= 2; | |
13629 | if ((typebits & N_SGN) != 0) | |
13630 | *g_type = NT_signed; | |
13631 | else if ((typebits & N_UNS) != 0) | |
477330fc | 13632 | *g_type = NT_unsigned; |
5287ad62 | 13633 | else if ((typebits & N_INT) != 0) |
477330fc | 13634 | *g_type = NT_integer; |
5287ad62 | 13635 | else if ((typebits & N_FLT) != 0) |
477330fc | 13636 | *g_type = NT_float; |
dcbf9037 | 13637 | else if ((typebits & N_SIZ) != 0) |
477330fc | 13638 | *g_type = NT_untyped; |
5287ad62 JB |
13639 | } |
13640 | } | |
5f4273c7 | 13641 | |
5287ad62 JB |
13642 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
13643 | operand type, i.e. the single type specified in a Neon instruction when it | |
13644 | is the only one given. */ | |
13645 | ||
13646 | static struct neon_type_el | |
13647 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
13648 | { | |
13649 | struct neon_type_el dest = *key; | |
5f4273c7 | 13650 | |
9c2799c2 | 13651 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 13652 | |
5287ad62 JB |
13653 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
13654 | ||
13655 | return dest; | |
13656 | } | |
13657 | ||
13658 | /* Convert Neon type and size into compact bitmask representation. */ | |
13659 | ||
13660 | static enum neon_type_mask | |
13661 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
13662 | { | |
13663 | switch (type) | |
13664 | { | |
13665 | case NT_untyped: | |
13666 | switch (size) | |
477330fc RM |
13667 | { |
13668 | case 8: return N_8; | |
13669 | case 16: return N_16; | |
13670 | case 32: return N_32; | |
13671 | case 64: return N_64; | |
13672 | default: ; | |
13673 | } | |
5287ad62 JB |
13674 | break; |
13675 | ||
13676 | case NT_integer: | |
13677 | switch (size) | |
477330fc RM |
13678 | { |
13679 | case 8: return N_I8; | |
13680 | case 16: return N_I16; | |
13681 | case 32: return N_I32; | |
13682 | case 64: return N_I64; | |
13683 | default: ; | |
13684 | } | |
5287ad62 JB |
13685 | break; |
13686 | ||
13687 | case NT_float: | |
037e8744 | 13688 | switch (size) |
477330fc | 13689 | { |
8e79c3df | 13690 | case 16: return N_F16; |
477330fc RM |
13691 | case 32: return N_F32; |
13692 | case 64: return N_F64; | |
13693 | default: ; | |
13694 | } | |
5287ad62 JB |
13695 | break; |
13696 | ||
13697 | case NT_poly: | |
13698 | switch (size) | |
477330fc RM |
13699 | { |
13700 | case 8: return N_P8; | |
13701 | case 16: return N_P16; | |
4f51b4bd | 13702 | case 64: return N_P64; |
477330fc RM |
13703 | default: ; |
13704 | } | |
5287ad62 JB |
13705 | break; |
13706 | ||
13707 | case NT_signed: | |
13708 | switch (size) | |
477330fc RM |
13709 | { |
13710 | case 8: return N_S8; | |
13711 | case 16: return N_S16; | |
13712 | case 32: return N_S32; | |
13713 | case 64: return N_S64; | |
13714 | default: ; | |
13715 | } | |
5287ad62 JB |
13716 | break; |
13717 | ||
13718 | case NT_unsigned: | |
13719 | switch (size) | |
477330fc RM |
13720 | { |
13721 | case 8: return N_U8; | |
13722 | case 16: return N_U16; | |
13723 | case 32: return N_U32; | |
13724 | case 64: return N_U64; | |
13725 | default: ; | |
13726 | } | |
5287ad62 JB |
13727 | break; |
13728 | ||
13729 | default: ; | |
13730 | } | |
5f4273c7 | 13731 | |
5287ad62 JB |
13732 | return N_UTYP; |
13733 | } | |
13734 | ||
13735 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
13736 | handles the case where a single bit is set in the mask. */ | |
13737 | ||
dcbf9037 | 13738 | static int |
5287ad62 | 13739 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
477330fc | 13740 | enum neon_type_mask mask) |
5287ad62 | 13741 | { |
dcbf9037 JB |
13742 | if ((mask & N_EQK) != 0) |
13743 | return FAIL; | |
13744 | ||
5287ad62 JB |
13745 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
13746 | *size = 8; | |
c70a8987 | 13747 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0) |
5287ad62 | 13748 | *size = 16; |
dcbf9037 | 13749 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 13750 | *size = 32; |
4f51b4bd | 13751 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 13752 | *size = 64; |
dcbf9037 JB |
13753 | else |
13754 | return FAIL; | |
13755 | ||
5287ad62 JB |
13756 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
13757 | *type = NT_signed; | |
dcbf9037 | 13758 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 13759 | *type = NT_unsigned; |
dcbf9037 | 13760 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 13761 | *type = NT_integer; |
dcbf9037 | 13762 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 13763 | *type = NT_untyped; |
4f51b4bd | 13764 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 13765 | *type = NT_poly; |
d54af2d0 | 13766 | else if ((mask & (N_F_ALL)) != 0) |
5287ad62 | 13767 | *type = NT_float; |
dcbf9037 JB |
13768 | else |
13769 | return FAIL; | |
5f4273c7 | 13770 | |
dcbf9037 | 13771 | return SUCCESS; |
5287ad62 JB |
13772 | } |
13773 | ||
13774 | /* Modify a bitmask of allowed types. This is only needed for type | |
13775 | relaxation. */ | |
13776 | ||
13777 | static unsigned | |
13778 | modify_types_allowed (unsigned allowed, unsigned mods) | |
13779 | { | |
13780 | unsigned size; | |
13781 | enum neon_el_type type; | |
13782 | unsigned destmask; | |
13783 | int i; | |
5f4273c7 | 13784 | |
5287ad62 | 13785 | destmask = 0; |
5f4273c7 | 13786 | |
5287ad62 JB |
13787 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
13788 | { | |
21d799b5 | 13789 | if (el_type_of_type_chk (&type, &size, |
477330fc RM |
13790 | (enum neon_type_mask) (allowed & i)) == SUCCESS) |
13791 | { | |
13792 | neon_modify_type_size (mods, &type, &size); | |
13793 | destmask |= type_chk_of_el_type (type, size); | |
13794 | } | |
5287ad62 | 13795 | } |
5f4273c7 | 13796 | |
5287ad62 JB |
13797 | return destmask; |
13798 | } | |
13799 | ||
13800 | /* Check type and return type classification. | |
13801 | The manual states (paraphrase): If one datatype is given, it indicates the | |
13802 | type given in: | |
13803 | - the second operand, if there is one | |
13804 | - the operand, if there is no second operand | |
13805 | - the result, if there are no operands. | |
13806 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
13807 | which is set on a per-instruction basis, which is the one which matters when | |
13808 | only one data type is written. | |
13809 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 13810 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
13811 | |
13812 | static struct neon_type_el | |
13813 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
13814 | { | |
13815 | va_list ap; | |
13816 | unsigned i, pass, key_el = 0; | |
13817 | unsigned types[NEON_MAX_TYPE_ELS]; | |
13818 | enum neon_el_type k_type = NT_invtype; | |
13819 | unsigned k_size = -1u; | |
13820 | struct neon_type_el badtype = {NT_invtype, -1}; | |
13821 | unsigned key_allowed = 0; | |
13822 | ||
13823 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
13824 | Fill in the missing operand here, if it was omitted. */ | |
13825 | if (els > 1 && !inst.operands[1].present) | |
13826 | inst.operands[1] = inst.operands[0]; | |
13827 | ||
13828 | /* Suck up all the varargs. */ | |
13829 | va_start (ap, ns); | |
13830 | for (i = 0; i < els; i++) | |
13831 | { | |
13832 | unsigned thisarg = va_arg (ap, unsigned); | |
13833 | if (thisarg == N_IGNORE_TYPE) | |
477330fc RM |
13834 | { |
13835 | va_end (ap); | |
13836 | return badtype; | |
13837 | } | |
5287ad62 JB |
13838 | types[i] = thisarg; |
13839 | if ((thisarg & N_KEY) != 0) | |
477330fc | 13840 | key_el = i; |
5287ad62 JB |
13841 | } |
13842 | va_end (ap); | |
13843 | ||
dcbf9037 JB |
13844 | if (inst.vectype.elems > 0) |
13845 | for (i = 0; i < els; i++) | |
13846 | if (inst.operands[i].vectype.type != NT_invtype) | |
477330fc RM |
13847 | { |
13848 | first_error (_("types specified in both the mnemonic and operands")); | |
13849 | return badtype; | |
13850 | } | |
dcbf9037 | 13851 | |
5287ad62 JB |
13852 | /* Duplicate inst.vectype elements here as necessary. |
13853 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
13854 | particularly when an insn takes one register and one non-register | |
13855 | operand. */ | |
13856 | if (inst.vectype.elems == 1 && els > 1) | |
13857 | { | |
13858 | unsigned j; | |
13859 | inst.vectype.elems = els; | |
13860 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
13861 | for (j = 0; j < els; j++) | |
477330fc RM |
13862 | if (j != key_el) |
13863 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
13864 | types[j]); | |
dcbf9037 JB |
13865 | } |
13866 | else if (inst.vectype.elems == 0 && els > 0) | |
13867 | { | |
13868 | unsigned j; | |
13869 | /* No types were given after the mnemonic, so look for types specified | |
477330fc RM |
13870 | after each operand. We allow some flexibility here; as long as the |
13871 | "key" operand has a type, we can infer the others. */ | |
dcbf9037 | 13872 | for (j = 0; j < els; j++) |
477330fc RM |
13873 | if (inst.operands[j].vectype.type != NT_invtype) |
13874 | inst.vectype.el[j] = inst.operands[j].vectype; | |
dcbf9037 JB |
13875 | |
13876 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
477330fc RM |
13877 | { |
13878 | for (j = 0; j < els; j++) | |
13879 | if (inst.operands[j].vectype.type == NT_invtype) | |
13880 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
13881 | types[j]); | |
13882 | } | |
dcbf9037 | 13883 | else |
477330fc RM |
13884 | { |
13885 | first_error (_("operand types can't be inferred")); | |
13886 | return badtype; | |
13887 | } | |
5287ad62 JB |
13888 | } |
13889 | else if (inst.vectype.elems != els) | |
13890 | { | |
dcbf9037 | 13891 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
13892 | return badtype; |
13893 | } | |
13894 | ||
13895 | for (pass = 0; pass < 2; pass++) | |
13896 | { | |
13897 | for (i = 0; i < els; i++) | |
477330fc RM |
13898 | { |
13899 | unsigned thisarg = types[i]; | |
13900 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
13901 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
13902 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
13903 | unsigned g_size = inst.vectype.el[i].size; | |
13904 | ||
13905 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
5287ad62 | 13906 | integer types if sign-specific variants are unavailable. */ |
477330fc | 13907 | if ((g_type == NT_signed || g_type == NT_unsigned) |
5287ad62 JB |
13908 | && (types_allowed & N_SU_ALL) == 0) |
13909 | g_type = NT_integer; | |
13910 | ||
477330fc | 13911 | /* If only untyped args are allowed, decay any more specific types to |
5287ad62 JB |
13912 | them. Some instructions only care about signs for some element |
13913 | sizes, so handle that properly. */ | |
477330fc | 13914 | if (((types_allowed & N_UNT) == 0) |
91ff7894 MGD |
13915 | && ((g_size == 8 && (types_allowed & N_8) != 0) |
13916 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
13917 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
13918 | || (g_size == 64 && (types_allowed & N_64) != 0))) | |
5287ad62 JB |
13919 | g_type = NT_untyped; |
13920 | ||
477330fc RM |
13921 | if (pass == 0) |
13922 | { | |
13923 | if ((thisarg & N_KEY) != 0) | |
13924 | { | |
13925 | k_type = g_type; | |
13926 | k_size = g_size; | |
13927 | key_allowed = thisarg & ~N_KEY; | |
cc933301 JW |
13928 | |
13929 | /* Check architecture constraint on FP16 extension. */ | |
13930 | if (k_size == 16 | |
13931 | && k_type == NT_float | |
13932 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
13933 | { | |
13934 | inst.error = _(BAD_FP16); | |
13935 | return badtype; | |
13936 | } | |
477330fc RM |
13937 | } |
13938 | } | |
13939 | else | |
13940 | { | |
13941 | if ((thisarg & N_VFP) != 0) | |
13942 | { | |
13943 | enum neon_shape_el regshape; | |
13944 | unsigned regwidth, match; | |
99b253c5 NC |
13945 | |
13946 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
13947 | if (ns == NS_NULL) | |
13948 | { | |
13949 | first_error (_("invalid instruction shape")); | |
13950 | return badtype; | |
13951 | } | |
477330fc RM |
13952 | regshape = neon_shape_tab[ns].el[i]; |
13953 | regwidth = neon_shape_el_size[regshape]; | |
13954 | ||
13955 | /* In VFP mode, operands must match register widths. If we | |
13956 | have a key operand, use its width, else use the width of | |
13957 | the current operand. */ | |
13958 | if (k_size != -1u) | |
13959 | match = k_size; | |
13960 | else | |
13961 | match = g_size; | |
13962 | ||
9db2f6b4 RL |
13963 | /* FP16 will use a single precision register. */ |
13964 | if (regwidth == 32 && match == 16) | |
13965 | { | |
13966 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)) | |
13967 | match = regwidth; | |
13968 | else | |
13969 | { | |
13970 | inst.error = _(BAD_FP16); | |
13971 | return badtype; | |
13972 | } | |
13973 | } | |
13974 | ||
477330fc RM |
13975 | if (regwidth != match) |
13976 | { | |
13977 | first_error (_("operand size must match register width")); | |
13978 | return badtype; | |
13979 | } | |
13980 | } | |
13981 | ||
13982 | if ((thisarg & N_EQK) == 0) | |
13983 | { | |
13984 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
13985 | ||
13986 | if ((given_type & types_allowed) == 0) | |
13987 | { | |
13988 | first_error (_("bad type in Neon instruction")); | |
13989 | return badtype; | |
13990 | } | |
13991 | } | |
13992 | else | |
13993 | { | |
13994 | enum neon_el_type mod_k_type = k_type; | |
13995 | unsigned mod_k_size = k_size; | |
13996 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
13997 | if (g_type != mod_k_type || g_size != mod_k_size) | |
13998 | { | |
13999 | first_error (_("inconsistent types in Neon instruction")); | |
14000 | return badtype; | |
14001 | } | |
14002 | } | |
14003 | } | |
14004 | } | |
5287ad62 JB |
14005 | } |
14006 | ||
14007 | return inst.vectype.el[key_el]; | |
14008 | } | |
14009 | ||
037e8744 | 14010 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 14011 | |
037e8744 JB |
14012 | /* Thumb VFP instructions have 0xE in the condition field. */ |
14013 | ||
14014 | static void | |
14015 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 14016 | { |
88714cb8 DG |
14017 | inst.is_neon = 1; |
14018 | ||
5287ad62 | 14019 | if (thumb_mode) |
037e8744 | 14020 | inst.instruction |= 0xe0000000; |
5287ad62 | 14021 | else |
037e8744 | 14022 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
14023 | } |
14024 | ||
037e8744 JB |
14025 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
14026 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
14027 | etc. It is assumed that operand parsing has already been done, and that the | |
14028 | operands are in the form expected by the given opcode (this isn't necessarily | |
14029 | the same as the form in which they were parsed, hence some massaging must | |
14030 | take place before this function is called). | |
14031 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 14032 | |
037e8744 JB |
14033 | static void |
14034 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 14035 | { |
037e8744 | 14036 | const struct asm_opcode *opcode; |
5f4273c7 | 14037 | |
21d799b5 | 14038 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 14039 | |
037e8744 JB |
14040 | if (!opcode) |
14041 | abort (); | |
5287ad62 | 14042 | |
037e8744 | 14043 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
477330fc RM |
14044 | thumb_mode ? *opcode->tvariant : *opcode->avariant), |
14045 | _(BAD_FPU)); | |
5287ad62 | 14046 | |
88714cb8 DG |
14047 | inst.is_neon = 1; |
14048 | ||
037e8744 JB |
14049 | if (thumb_mode) |
14050 | { | |
14051 | inst.instruction = opcode->tvalue; | |
14052 | opcode->tencode (); | |
14053 | } | |
14054 | else | |
14055 | { | |
14056 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
14057 | opcode->aencode (); | |
14058 | } | |
14059 | } | |
5287ad62 JB |
14060 | |
14061 | static void | |
037e8744 | 14062 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 14063 | { |
037e8744 JB |
14064 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
14065 | ||
9db2f6b4 | 14066 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
14067 | { |
14068 | if (is_add) | |
477330fc | 14069 | do_vfp_nsyn_opcode ("fadds"); |
037e8744 | 14070 | else |
477330fc | 14071 | do_vfp_nsyn_opcode ("fsubs"); |
9db2f6b4 RL |
14072 | |
14073 | /* ARMv8.2 fp16 instruction. */ | |
14074 | if (rs == NS_HHH) | |
14075 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14076 | } |
14077 | else | |
14078 | { | |
14079 | if (is_add) | |
477330fc | 14080 | do_vfp_nsyn_opcode ("faddd"); |
037e8744 | 14081 | else |
477330fc | 14082 | do_vfp_nsyn_opcode ("fsubd"); |
037e8744 JB |
14083 | } |
14084 | } | |
14085 | ||
14086 | /* Check operand types to see if this is a VFP instruction, and if so call | |
14087 | PFN (). */ | |
14088 | ||
14089 | static int | |
14090 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
14091 | { | |
14092 | enum neon_shape rs; | |
14093 | struct neon_type_el et; | |
14094 | ||
14095 | switch (args) | |
14096 | { | |
14097 | case 2: | |
9db2f6b4 RL |
14098 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14099 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
037e8744 | 14100 | break; |
5f4273c7 | 14101 | |
037e8744 | 14102 | case 3: |
9db2f6b4 RL |
14103 | rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
14104 | et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
14105 | N_F_ALL | N_KEY | N_VFP); | |
037e8744 JB |
14106 | break; |
14107 | ||
14108 | default: | |
14109 | abort (); | |
14110 | } | |
14111 | ||
14112 | if (et.type != NT_invtype) | |
14113 | { | |
14114 | pfn (rs); | |
14115 | return SUCCESS; | |
14116 | } | |
037e8744 | 14117 | |
99b253c5 | 14118 | inst.error = NULL; |
037e8744 JB |
14119 | return FAIL; |
14120 | } | |
14121 | ||
14122 | static void | |
14123 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
14124 | { | |
14125 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 14126 | |
9db2f6b4 | 14127 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 JB |
14128 | { |
14129 | if (is_mla) | |
477330fc | 14130 | do_vfp_nsyn_opcode ("fmacs"); |
037e8744 | 14131 | else |
477330fc | 14132 | do_vfp_nsyn_opcode ("fnmacs"); |
9db2f6b4 RL |
14133 | |
14134 | /* ARMv8.2 fp16 instruction. */ | |
14135 | if (rs == NS_HHH) | |
14136 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14137 | } |
14138 | else | |
14139 | { | |
14140 | if (is_mla) | |
477330fc | 14141 | do_vfp_nsyn_opcode ("fmacd"); |
037e8744 | 14142 | else |
477330fc | 14143 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
14144 | } |
14145 | } | |
14146 | ||
62f3b8c8 PB |
14147 | static void |
14148 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
14149 | { | |
14150 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
14151 | ||
9db2f6b4 | 14152 | if (rs == NS_FFF || rs == NS_HHH) |
62f3b8c8 PB |
14153 | { |
14154 | if (is_fma) | |
477330fc | 14155 | do_vfp_nsyn_opcode ("ffmas"); |
62f3b8c8 | 14156 | else |
477330fc | 14157 | do_vfp_nsyn_opcode ("ffnmas"); |
9db2f6b4 RL |
14158 | |
14159 | /* ARMv8.2 fp16 instruction. */ | |
14160 | if (rs == NS_HHH) | |
14161 | do_scalar_fp16_v82_encode (); | |
62f3b8c8 PB |
14162 | } |
14163 | else | |
14164 | { | |
14165 | if (is_fma) | |
477330fc | 14166 | do_vfp_nsyn_opcode ("ffmad"); |
62f3b8c8 | 14167 | else |
477330fc | 14168 | do_vfp_nsyn_opcode ("ffnmad"); |
62f3b8c8 PB |
14169 | } |
14170 | } | |
14171 | ||
037e8744 JB |
14172 | static void |
14173 | do_vfp_nsyn_mul (enum neon_shape rs) | |
14174 | { | |
9db2f6b4 RL |
14175 | if (rs == NS_FFF || rs == NS_HHH) |
14176 | { | |
14177 | do_vfp_nsyn_opcode ("fmuls"); | |
14178 | ||
14179 | /* ARMv8.2 fp16 instruction. */ | |
14180 | if (rs == NS_HHH) | |
14181 | do_scalar_fp16_v82_encode (); | |
14182 | } | |
037e8744 JB |
14183 | else |
14184 | do_vfp_nsyn_opcode ("fmuld"); | |
14185 | } | |
14186 | ||
14187 | static void | |
14188 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
14189 | { | |
14190 | int is_neg = (inst.instruction & 0x80) != 0; | |
9db2f6b4 | 14191 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY); |
037e8744 | 14192 | |
9db2f6b4 | 14193 | if (rs == NS_FF || rs == NS_HH) |
037e8744 JB |
14194 | { |
14195 | if (is_neg) | |
477330fc | 14196 | do_vfp_nsyn_opcode ("fnegs"); |
037e8744 | 14197 | else |
477330fc | 14198 | do_vfp_nsyn_opcode ("fabss"); |
9db2f6b4 RL |
14199 | |
14200 | /* ARMv8.2 fp16 instruction. */ | |
14201 | if (rs == NS_HH) | |
14202 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14203 | } |
14204 | else | |
14205 | { | |
14206 | if (is_neg) | |
477330fc | 14207 | do_vfp_nsyn_opcode ("fnegd"); |
037e8744 | 14208 | else |
477330fc | 14209 | do_vfp_nsyn_opcode ("fabsd"); |
037e8744 JB |
14210 | } |
14211 | } | |
14212 | ||
14213 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
14214 | insns belong to Neon, and are handled elsewhere. */ | |
14215 | ||
14216 | static void | |
14217 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
14218 | { | |
14219 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
14220 | if (is_ldm) | |
14221 | { | |
14222 | if (is_dbmode) | |
477330fc | 14223 | do_vfp_nsyn_opcode ("fldmdbs"); |
037e8744 | 14224 | else |
477330fc | 14225 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 JB |
14226 | } |
14227 | else | |
14228 | { | |
14229 | if (is_dbmode) | |
477330fc | 14230 | do_vfp_nsyn_opcode ("fstmdbs"); |
037e8744 | 14231 | else |
477330fc | 14232 | do_vfp_nsyn_opcode ("fstmias"); |
037e8744 JB |
14233 | } |
14234 | } | |
14235 | ||
037e8744 JB |
14236 | static void |
14237 | do_vfp_nsyn_sqrt (void) | |
14238 | { | |
9db2f6b4 RL |
14239 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14240 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 14241 | |
9db2f6b4 RL |
14242 | if (rs == NS_FF || rs == NS_HH) |
14243 | { | |
14244 | do_vfp_nsyn_opcode ("fsqrts"); | |
14245 | ||
14246 | /* ARMv8.2 fp16 instruction. */ | |
14247 | if (rs == NS_HH) | |
14248 | do_scalar_fp16_v82_encode (); | |
14249 | } | |
037e8744 JB |
14250 | else |
14251 | do_vfp_nsyn_opcode ("fsqrtd"); | |
14252 | } | |
14253 | ||
14254 | static void | |
14255 | do_vfp_nsyn_div (void) | |
14256 | { | |
9db2f6b4 | 14257 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 14258 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 14259 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 14260 | |
9db2f6b4 RL |
14261 | if (rs == NS_FFF || rs == NS_HHH) |
14262 | { | |
14263 | do_vfp_nsyn_opcode ("fdivs"); | |
14264 | ||
14265 | /* ARMv8.2 fp16 instruction. */ | |
14266 | if (rs == NS_HHH) | |
14267 | do_scalar_fp16_v82_encode (); | |
14268 | } | |
037e8744 JB |
14269 | else |
14270 | do_vfp_nsyn_opcode ("fdivd"); | |
14271 | } | |
14272 | ||
14273 | static void | |
14274 | do_vfp_nsyn_nmul (void) | |
14275 | { | |
9db2f6b4 | 14276 | enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL); |
037e8744 | 14277 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, |
9db2f6b4 | 14278 | N_F_ALL | N_KEY | N_VFP); |
5f4273c7 | 14279 | |
9db2f6b4 | 14280 | if (rs == NS_FFF || rs == NS_HHH) |
037e8744 | 14281 | { |
88714cb8 | 14282 | NEON_ENCODE (SINGLE, inst); |
037e8744 | 14283 | do_vfp_sp_dyadic (); |
9db2f6b4 RL |
14284 | |
14285 | /* ARMv8.2 fp16 instruction. */ | |
14286 | if (rs == NS_HHH) | |
14287 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14288 | } |
14289 | else | |
14290 | { | |
88714cb8 | 14291 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
14292 | do_vfp_dp_rd_rn_rm (); |
14293 | } | |
14294 | do_vfp_cond_or_thumb (); | |
9db2f6b4 | 14295 | |
037e8744 JB |
14296 | } |
14297 | ||
14298 | static void | |
14299 | do_vfp_nsyn_cmp (void) | |
14300 | { | |
9db2f6b4 | 14301 | enum neon_shape rs; |
037e8744 JB |
14302 | if (inst.operands[1].isreg) |
14303 | { | |
9db2f6b4 RL |
14304 | rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL); |
14305 | neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP); | |
5f4273c7 | 14306 | |
9db2f6b4 | 14307 | if (rs == NS_FF || rs == NS_HH) |
477330fc RM |
14308 | { |
14309 | NEON_ENCODE (SINGLE, inst); | |
14310 | do_vfp_sp_monadic (); | |
14311 | } | |
037e8744 | 14312 | else |
477330fc RM |
14313 | { |
14314 | NEON_ENCODE (DOUBLE, inst); | |
14315 | do_vfp_dp_rd_rm (); | |
14316 | } | |
037e8744 JB |
14317 | } |
14318 | else | |
14319 | { | |
9db2f6b4 RL |
14320 | rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL); |
14321 | neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK); | |
037e8744 JB |
14322 | |
14323 | switch (inst.instruction & 0x0fffffff) | |
477330fc RM |
14324 | { |
14325 | case N_MNEM_vcmp: | |
14326 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
14327 | break; | |
14328 | case N_MNEM_vcmpe: | |
14329 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
14330 | break; | |
14331 | default: | |
14332 | abort (); | |
14333 | } | |
5f4273c7 | 14334 | |
9db2f6b4 | 14335 | if (rs == NS_FI || rs == NS_HI) |
477330fc RM |
14336 | { |
14337 | NEON_ENCODE (SINGLE, inst); | |
14338 | do_vfp_sp_compare_z (); | |
14339 | } | |
037e8744 | 14340 | else |
477330fc RM |
14341 | { |
14342 | NEON_ENCODE (DOUBLE, inst); | |
14343 | do_vfp_dp_rd (); | |
14344 | } | |
037e8744 JB |
14345 | } |
14346 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
14347 | |
14348 | /* ARMv8.2 fp16 instruction. */ | |
14349 | if (rs == NS_HI || rs == NS_HH) | |
14350 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
14351 | } |
14352 | ||
14353 | static void | |
14354 | nsyn_insert_sp (void) | |
14355 | { | |
14356 | inst.operands[1] = inst.operands[0]; | |
14357 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 14358 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
14359 | inst.operands[0].isreg = 1; |
14360 | inst.operands[0].writeback = 1; | |
14361 | inst.operands[0].present = 1; | |
14362 | } | |
14363 | ||
14364 | static void | |
14365 | do_vfp_nsyn_push (void) | |
14366 | { | |
14367 | nsyn_insert_sp (); | |
14368 | if (inst.operands[1].issingle) | |
14369 | do_vfp_nsyn_opcode ("fstmdbs"); | |
14370 | else | |
14371 | do_vfp_nsyn_opcode ("fstmdbd"); | |
14372 | } | |
14373 | ||
14374 | static void | |
14375 | do_vfp_nsyn_pop (void) | |
14376 | { | |
14377 | nsyn_insert_sp (); | |
14378 | if (inst.operands[1].issingle) | |
22b5b651 | 14379 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 14380 | else |
22b5b651 | 14381 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
14382 | } |
14383 | ||
14384 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
14385 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
14386 | ||
88714cb8 DG |
14387 | static void |
14388 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 14389 | { |
88714cb8 DG |
14390 | unsigned int i = insn->instruction; |
14391 | insn->is_neon = 1; | |
14392 | ||
037e8744 JB |
14393 | if (thumb_mode) |
14394 | { | |
14395 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
14396 | if (i & (1 << 24)) | |
477330fc | 14397 | i |= 1 << 28; |
5f4273c7 | 14398 | |
037e8744 | 14399 | i &= ~(1 << 24); |
5f4273c7 | 14400 | |
037e8744 JB |
14401 | i |= 0xef000000; |
14402 | } | |
14403 | else | |
14404 | i |= 0xf2000000; | |
5f4273c7 | 14405 | |
88714cb8 | 14406 | insn->instruction = i; |
037e8744 JB |
14407 | } |
14408 | ||
14409 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
14410 | (0, 1, 2, 3). */ | |
14411 | ||
14412 | static unsigned | |
14413 | neon_logbits (unsigned x) | |
14414 | { | |
14415 | return ffs (x) - 4; | |
14416 | } | |
14417 | ||
14418 | #define LOW4(R) ((R) & 0xf) | |
14419 | #define HI1(R) (((R) >> 4) & 1) | |
14420 | ||
14421 | /* Encode insns with bit pattern: | |
14422 | ||
14423 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
14424 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 14425 | |
037e8744 JB |
14426 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
14427 | different meaning for some instruction. */ | |
14428 | ||
14429 | static void | |
14430 | neon_three_same (int isquad, int ubit, int size) | |
14431 | { | |
14432 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14433 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14434 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14435 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14436 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14437 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14438 | inst.instruction |= (isquad != 0) << 6; | |
14439 | inst.instruction |= (ubit != 0) << 24; | |
14440 | if (size != -1) | |
14441 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 14442 | |
88714cb8 | 14443 | neon_dp_fixup (&inst); |
037e8744 JB |
14444 | } |
14445 | ||
14446 | /* Encode instructions of the form: | |
14447 | ||
14448 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
14449 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
14450 | |
14451 | Don't write size if SIZE == -1. */ | |
14452 | ||
14453 | static void | |
14454 | neon_two_same (int qbit, int ubit, int size) | |
14455 | { | |
14456 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14457 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14458 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14459 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14460 | inst.instruction |= (qbit != 0) << 6; | |
14461 | inst.instruction |= (ubit != 0) << 24; | |
14462 | ||
14463 | if (size != -1) | |
14464 | inst.instruction |= neon_logbits (size) << 18; | |
14465 | ||
88714cb8 | 14466 | neon_dp_fixup (&inst); |
5287ad62 JB |
14467 | } |
14468 | ||
14469 | /* Neon instruction encoders, in approximate order of appearance. */ | |
14470 | ||
14471 | static void | |
14472 | do_neon_dyadic_i_su (void) | |
14473 | { | |
037e8744 | 14474 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14475 | struct neon_type_el et = neon_check_type (3, rs, |
14476 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 14477 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14478 | } |
14479 | ||
14480 | static void | |
14481 | do_neon_dyadic_i64_su (void) | |
14482 | { | |
037e8744 | 14483 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14484 | struct neon_type_el et = neon_check_type (3, rs, |
14485 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 14486 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14487 | } |
14488 | ||
14489 | static void | |
14490 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
477330fc | 14491 | unsigned immbits) |
5287ad62 JB |
14492 | { |
14493 | unsigned size = et.size >> 3; | |
14494 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14495 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14496 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14497 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14498 | inst.instruction |= (isquad != 0) << 6; | |
14499 | inst.instruction |= immbits << 16; | |
14500 | inst.instruction |= (size >> 3) << 7; | |
14501 | inst.instruction |= (size & 0x7) << 19; | |
14502 | if (write_ubit) | |
14503 | inst.instruction |= (uval != 0) << 24; | |
14504 | ||
88714cb8 | 14505 | neon_dp_fixup (&inst); |
5287ad62 JB |
14506 | } |
14507 | ||
14508 | static void | |
14509 | do_neon_shl_imm (void) | |
14510 | { | |
14511 | if (!inst.operands[2].isreg) | |
14512 | { | |
037e8744 | 14513 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 14514 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
cb3b1e65 JB |
14515 | int imm = inst.operands[2].imm; |
14516 | ||
14517 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
14518 | _("immediate out of range for shift")); | |
88714cb8 | 14519 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 14520 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14521 | } |
14522 | else | |
14523 | { | |
037e8744 | 14524 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14525 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14526 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
14527 | unsigned int tmp; |
14528 | ||
14529 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
477330fc RM |
14530 | vshl.xx Dd, Dm, Dn |
14531 | whereas other 3-register operations encoded by neon_three_same have | |
14532 | syntax like: | |
14533 | vadd.xx Dd, Dn, Dm | |
14534 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
14535 | here. */ | |
627907b7 JB |
14536 | tmp = inst.operands[2].reg; |
14537 | inst.operands[2].reg = inst.operands[1].reg; | |
14538 | inst.operands[1].reg = tmp; | |
88714cb8 | 14539 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14540 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14541 | } |
14542 | } | |
14543 | ||
14544 | static void | |
14545 | do_neon_qshl_imm (void) | |
14546 | { | |
14547 | if (!inst.operands[2].isreg) | |
14548 | { | |
037e8744 | 14549 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 14550 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
cb3b1e65 | 14551 | int imm = inst.operands[2].imm; |
627907b7 | 14552 | |
cb3b1e65 JB |
14553 | constraint (imm < 0 || (unsigned)imm >= et.size, |
14554 | _("immediate out of range for shift")); | |
88714cb8 | 14555 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 14556 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm); |
5287ad62 JB |
14557 | } |
14558 | else | |
14559 | { | |
037e8744 | 14560 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14561 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14562 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
14563 | unsigned int tmp; |
14564 | ||
14565 | /* See note in do_neon_shl_imm. */ | |
14566 | tmp = inst.operands[2].reg; | |
14567 | inst.operands[2].reg = inst.operands[1].reg; | |
14568 | inst.operands[1].reg = tmp; | |
88714cb8 | 14569 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14570 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14571 | } |
14572 | } | |
14573 | ||
627907b7 JB |
14574 | static void |
14575 | do_neon_rshl (void) | |
14576 | { | |
14577 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
14578 | struct neon_type_el et = neon_check_type (3, rs, | |
14579 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
14580 | unsigned int tmp; | |
14581 | ||
14582 | tmp = inst.operands[2].reg; | |
14583 | inst.operands[2].reg = inst.operands[1].reg; | |
14584 | inst.operands[1].reg = tmp; | |
14585 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
14586 | } | |
14587 | ||
5287ad62 JB |
14588 | static int |
14589 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
14590 | { | |
036dc3f7 PB |
14591 | /* Handle .I8 pseudo-instructions. */ |
14592 | if (size == 8) | |
5287ad62 | 14593 | { |
5287ad62 | 14594 | /* Unfortunately, this will make everything apart from zero out-of-range. |
477330fc RM |
14595 | FIXME is this the intended semantics? There doesn't seem much point in |
14596 | accepting .I8 if so. */ | |
5287ad62 JB |
14597 | immediate |= immediate << 8; |
14598 | size = 16; | |
036dc3f7 PB |
14599 | } |
14600 | ||
14601 | if (size >= 32) | |
14602 | { | |
14603 | if (immediate == (immediate & 0x000000ff)) | |
14604 | { | |
14605 | *immbits = immediate; | |
14606 | return 0x1; | |
14607 | } | |
14608 | else if (immediate == (immediate & 0x0000ff00)) | |
14609 | { | |
14610 | *immbits = immediate >> 8; | |
14611 | return 0x3; | |
14612 | } | |
14613 | else if (immediate == (immediate & 0x00ff0000)) | |
14614 | { | |
14615 | *immbits = immediate >> 16; | |
14616 | return 0x5; | |
14617 | } | |
14618 | else if (immediate == (immediate & 0xff000000)) | |
14619 | { | |
14620 | *immbits = immediate >> 24; | |
14621 | return 0x7; | |
14622 | } | |
14623 | if ((immediate & 0xffff) != (immediate >> 16)) | |
14624 | goto bad_immediate; | |
14625 | immediate &= 0xffff; | |
5287ad62 JB |
14626 | } |
14627 | ||
14628 | if (immediate == (immediate & 0x000000ff)) | |
14629 | { | |
14630 | *immbits = immediate; | |
036dc3f7 | 14631 | return 0x9; |
5287ad62 JB |
14632 | } |
14633 | else if (immediate == (immediate & 0x0000ff00)) | |
14634 | { | |
14635 | *immbits = immediate >> 8; | |
036dc3f7 | 14636 | return 0xb; |
5287ad62 JB |
14637 | } |
14638 | ||
14639 | bad_immediate: | |
dcbf9037 | 14640 | first_error (_("immediate value out of range")); |
5287ad62 JB |
14641 | return FAIL; |
14642 | } | |
14643 | ||
5287ad62 JB |
14644 | static void |
14645 | do_neon_logic (void) | |
14646 | { | |
14647 | if (inst.operands[2].present && inst.operands[2].isreg) | |
14648 | { | |
037e8744 | 14649 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14650 | neon_check_type (3, rs, N_IGNORE_TYPE); |
14651 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 14652 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14653 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14654 | } |
14655 | else | |
14656 | { | |
4316f0d2 DG |
14657 | const int three_ops_form = (inst.operands[2].present |
14658 | && !inst.operands[2].isreg); | |
14659 | const int immoperand = (three_ops_form ? 2 : 1); | |
14660 | enum neon_shape rs = (three_ops_form | |
14661 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
14662 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
037e8744 | 14663 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 14664 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); |
21d799b5 | 14665 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
14666 | unsigned immbits; |
14667 | int cmode; | |
5f4273c7 | 14668 | |
5287ad62 | 14669 | if (et.type == NT_invtype) |
477330fc | 14670 | return; |
5f4273c7 | 14671 | |
4316f0d2 DG |
14672 | if (three_ops_form) |
14673 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
14674 | _("first and second operands shall be the same register")); | |
14675 | ||
88714cb8 | 14676 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 14677 | |
4316f0d2 | 14678 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
14679 | if (et.size == 64) |
14680 | { | |
14681 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
14682 | pattern. */ | |
4316f0d2 DG |
14683 | if (immbits != (inst.operands[immoperand].regisimm ? |
14684 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
14685 | { |
14686 | /* Set immbits to an invalid constant. */ | |
14687 | immbits = 0xdeadbeef; | |
14688 | } | |
14689 | } | |
14690 | ||
5287ad62 | 14691 | switch (opcode) |
477330fc RM |
14692 | { |
14693 | case N_MNEM_vbic: | |
14694 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14695 | break; | |
14696 | ||
14697 | case N_MNEM_vorr: | |
14698 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14699 | break; | |
14700 | ||
14701 | case N_MNEM_vand: | |
14702 | /* Pseudo-instruction for VBIC. */ | |
14703 | neon_invert_size (&immbits, 0, et.size); | |
14704 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14705 | break; | |
14706 | ||
14707 | case N_MNEM_vorn: | |
14708 | /* Pseudo-instruction for VORR. */ | |
14709 | neon_invert_size (&immbits, 0, et.size); | |
14710 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14711 | break; | |
14712 | ||
14713 | default: | |
14714 | abort (); | |
14715 | } | |
5287ad62 JB |
14716 | |
14717 | if (cmode == FAIL) | |
477330fc | 14718 | return; |
5287ad62 | 14719 | |
037e8744 | 14720 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14721 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14722 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14723 | inst.instruction |= cmode << 8; | |
14724 | neon_write_immbits (immbits); | |
5f4273c7 | 14725 | |
88714cb8 | 14726 | neon_dp_fixup (&inst); |
5287ad62 JB |
14727 | } |
14728 | } | |
14729 | ||
14730 | static void | |
14731 | do_neon_bitfield (void) | |
14732 | { | |
037e8744 | 14733 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 14734 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 14735 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14736 | } |
14737 | ||
14738 | static void | |
dcbf9037 | 14739 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
477330fc | 14740 | unsigned destbits) |
5287ad62 | 14741 | { |
037e8744 | 14742 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 14743 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
477330fc | 14744 | types | N_KEY); |
5287ad62 JB |
14745 | if (et.type == NT_float) |
14746 | { | |
88714cb8 | 14747 | NEON_ENCODE (FLOAT, inst); |
cc933301 | 14748 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
14749 | } |
14750 | else | |
14751 | { | |
88714cb8 | 14752 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14753 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
14754 | } |
14755 | } | |
14756 | ||
14757 | static void | |
14758 | do_neon_dyadic_if_su (void) | |
14759 | { | |
dcbf9037 | 14760 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
14761 | } |
14762 | ||
14763 | static void | |
14764 | do_neon_dyadic_if_su_d (void) | |
14765 | { | |
14766 | /* This version only allow D registers, but that constraint is enforced during | |
14767 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 14768 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
14769 | } |
14770 | ||
5287ad62 JB |
14771 | static void |
14772 | do_neon_dyadic_if_i_d (void) | |
14773 | { | |
428e3f1f PB |
14774 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
14775 | affected if we specify unsigned args. */ | |
14776 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
14777 | } |
14778 | ||
037e8744 JB |
14779 | enum vfp_or_neon_is_neon_bits |
14780 | { | |
14781 | NEON_CHECK_CC = 1, | |
73924fbc MGD |
14782 | NEON_CHECK_ARCH = 2, |
14783 | NEON_CHECK_ARCH8 = 4 | |
037e8744 JB |
14784 | }; |
14785 | ||
14786 | /* Call this function if an instruction which may have belonged to the VFP or | |
14787 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
14788 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
14789 | things: | |
14790 | ||
14791 | - Make sure the user hasn't attempted to make a Neon instruction | |
14792 | conditional. | |
14793 | - Alter the value in the condition code field if necessary. | |
14794 | - Make sure that the arch supports Neon instructions. | |
14795 | ||
14796 | Which of these operations take place depends on bits from enum | |
14797 | vfp_or_neon_is_neon_bits. | |
14798 | ||
14799 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
14800 | current instruction's condition is COND_ALWAYS, the condition field is | |
14801 | changed to inst.uncond_value. This is necessary because instructions shared | |
14802 | between VFP and Neon may be conditional for the VFP variants only, and the | |
14803 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
14804 | ||
14805 | static int | |
14806 | vfp_or_neon_is_neon (unsigned check) | |
14807 | { | |
14808 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
14809 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
14810 | { | |
14811 | if (inst.cond != COND_ALWAYS) | |
477330fc RM |
14812 | { |
14813 | first_error (_(BAD_COND)); | |
14814 | return FAIL; | |
14815 | } | |
037e8744 | 14816 | if (inst.uncond_value != -1) |
477330fc | 14817 | inst.instruction |= inst.uncond_value << 28; |
037e8744 | 14818 | } |
5f4273c7 | 14819 | |
037e8744 | 14820 | if ((check & NEON_CHECK_ARCH) |
73924fbc MGD |
14821 | && !mark_feature_used (&fpu_neon_ext_v1)) |
14822 | { | |
14823 | first_error (_(BAD_FPU)); | |
14824 | return FAIL; | |
14825 | } | |
14826 | ||
14827 | if ((check & NEON_CHECK_ARCH8) | |
14828 | && !mark_feature_used (&fpu_neon_ext_armv8)) | |
037e8744 JB |
14829 | { |
14830 | first_error (_(BAD_FPU)); | |
14831 | return FAIL; | |
14832 | } | |
5f4273c7 | 14833 | |
037e8744 JB |
14834 | return SUCCESS; |
14835 | } | |
14836 | ||
5287ad62 JB |
14837 | static void |
14838 | do_neon_addsub_if_i (void) | |
14839 | { | |
037e8744 JB |
14840 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
14841 | return; | |
14842 | ||
14843 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14844 | return; | |
14845 | ||
5287ad62 JB |
14846 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
14847 | affected if we specify unsigned args. */ | |
dcbf9037 | 14848 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
14849 | } |
14850 | ||
14851 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
14852 | result to be: | |
14853 | V<op> A,B (A is operand 0, B is operand 2) | |
14854 | to mean: | |
14855 | V<op> A,B,A | |
14856 | not: | |
14857 | V<op> A,B,B | |
14858 | so handle that case specially. */ | |
14859 | ||
14860 | static void | |
14861 | neon_exchange_operands (void) | |
14862 | { | |
5287ad62 JB |
14863 | if (inst.operands[1].present) |
14864 | { | |
e1fa0163 NC |
14865 | void *scratch = xmalloc (sizeof (inst.operands[0])); |
14866 | ||
5287ad62 JB |
14867 | /* Swap operands[1] and operands[2]. */ |
14868 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
14869 | inst.operands[1] = inst.operands[2]; | |
14870 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
e1fa0163 | 14871 | free (scratch); |
5287ad62 JB |
14872 | } |
14873 | else | |
14874 | { | |
14875 | inst.operands[1] = inst.operands[2]; | |
14876 | inst.operands[2] = inst.operands[0]; | |
14877 | } | |
14878 | } | |
14879 | ||
14880 | static void | |
14881 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
14882 | { | |
14883 | if (inst.operands[2].isreg) | |
14884 | { | |
14885 | if (invert) | |
477330fc | 14886 | neon_exchange_operands (); |
dcbf9037 | 14887 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
14888 | } |
14889 | else | |
14890 | { | |
037e8744 | 14891 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 | 14892 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 14893 | N_EQK | N_SIZ, immtypes | N_KEY); |
5287ad62 | 14894 | |
88714cb8 | 14895 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
14896 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14897 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14898 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14899 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 14900 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14901 | inst.instruction |= (et.type == NT_float) << 10; |
14902 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 14903 | |
88714cb8 | 14904 | neon_dp_fixup (&inst); |
5287ad62 JB |
14905 | } |
14906 | } | |
14907 | ||
14908 | static void | |
14909 | do_neon_cmp (void) | |
14910 | { | |
cc933301 | 14911 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE); |
5287ad62 JB |
14912 | } |
14913 | ||
14914 | static void | |
14915 | do_neon_cmp_inv (void) | |
14916 | { | |
cc933301 | 14917 | neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE); |
5287ad62 JB |
14918 | } |
14919 | ||
14920 | static void | |
14921 | do_neon_ceq (void) | |
14922 | { | |
14923 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
14924 | } | |
14925 | ||
14926 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
14927 | scalars, which are encoded in 5 bits, M : Rm. | |
14928 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
14929 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
14930 | index in M. */ | |
14931 | ||
14932 | static unsigned | |
14933 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
14934 | { | |
dcbf9037 JB |
14935 | unsigned regno = NEON_SCALAR_REG (scalar); |
14936 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
14937 | |
14938 | switch (elsize) | |
14939 | { | |
14940 | case 16: | |
14941 | if (regno > 7 || elno > 3) | |
477330fc | 14942 | goto bad_scalar; |
5287ad62 | 14943 | return regno | (elno << 3); |
5f4273c7 | 14944 | |
5287ad62 JB |
14945 | case 32: |
14946 | if (regno > 15 || elno > 1) | |
477330fc | 14947 | goto bad_scalar; |
5287ad62 JB |
14948 | return regno | (elno << 4); |
14949 | ||
14950 | default: | |
14951 | bad_scalar: | |
dcbf9037 | 14952 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
14953 | } |
14954 | ||
14955 | return 0; | |
14956 | } | |
14957 | ||
14958 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
14959 | ||
14960 | static void | |
14961 | neon_mul_mac (struct neon_type_el et, int ubit) | |
14962 | { | |
dcbf9037 JB |
14963 | unsigned scalar; |
14964 | ||
14965 | /* Give a more helpful error message if we have an invalid type. */ | |
14966 | if (et.type == NT_invtype) | |
14967 | return; | |
5f4273c7 | 14968 | |
dcbf9037 | 14969 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
14970 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14971 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14972 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14973 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14974 | inst.instruction |= LOW4 (scalar); | |
14975 | inst.instruction |= HI1 (scalar) << 5; | |
14976 | inst.instruction |= (et.type == NT_float) << 8; | |
14977 | inst.instruction |= neon_logbits (et.size) << 20; | |
14978 | inst.instruction |= (ubit != 0) << 24; | |
14979 | ||
88714cb8 | 14980 | neon_dp_fixup (&inst); |
5287ad62 JB |
14981 | } |
14982 | ||
14983 | static void | |
14984 | do_neon_mac_maybe_scalar (void) | |
14985 | { | |
037e8744 JB |
14986 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
14987 | return; | |
14988 | ||
14989 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14990 | return; | |
14991 | ||
5287ad62 JB |
14992 | if (inst.operands[2].isscalar) |
14993 | { | |
037e8744 | 14994 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 14995 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14996 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); |
88714cb8 | 14997 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 14998 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
14999 | } |
15000 | else | |
428e3f1f PB |
15001 | { |
15002 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
15003 | affected if we specify unsigned args. */ | |
15004 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
15005 | } | |
5287ad62 JB |
15006 | } |
15007 | ||
62f3b8c8 PB |
15008 | static void |
15009 | do_neon_fmac (void) | |
15010 | { | |
15011 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
15012 | return; | |
15013 | ||
15014 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15015 | return; | |
15016 | ||
15017 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
15018 | } | |
15019 | ||
5287ad62 JB |
15020 | static void |
15021 | do_neon_tst (void) | |
15022 | { | |
037e8744 | 15023 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
15024 | struct neon_type_el et = neon_check_type (3, rs, |
15025 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 15026 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
15027 | } |
15028 | ||
15029 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
15030 | same types as the MAC equivalents. The polynomial type for this instruction | |
15031 | is encoded the same as the integer type. */ | |
15032 | ||
15033 | static void | |
15034 | do_neon_mul (void) | |
15035 | { | |
037e8744 JB |
15036 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
15037 | return; | |
15038 | ||
15039 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15040 | return; | |
15041 | ||
5287ad62 JB |
15042 | if (inst.operands[2].isscalar) |
15043 | do_neon_mac_maybe_scalar (); | |
15044 | else | |
cc933301 | 15045 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0); |
5287ad62 JB |
15046 | } |
15047 | ||
15048 | static void | |
15049 | do_neon_qdmulh (void) | |
15050 | { | |
15051 | if (inst.operands[2].isscalar) | |
15052 | { | |
037e8744 | 15053 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 15054 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15055 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 15056 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 15057 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
15058 | } |
15059 | else | |
15060 | { | |
037e8744 | 15061 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 15062 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 15063 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 15064 | NEON_ENCODE (INTEGER, inst); |
5287ad62 | 15065 | /* The U bit (rounding) comes from bit mask. */ |
037e8744 | 15066 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
15067 | } |
15068 | } | |
15069 | ||
643afb90 MW |
15070 | static void |
15071 | do_neon_qrdmlah (void) | |
15072 | { | |
15073 | /* Check we're on the correct architecture. */ | |
15074 | if (!mark_feature_used (&fpu_neon_ext_armv8)) | |
15075 | inst.error = | |
15076 | _("instruction form not available on this architecture."); | |
15077 | else if (!mark_feature_used (&fpu_neon_ext_v8_1)) | |
15078 | { | |
15079 | as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD.")); | |
15080 | record_feature_use (&fpu_neon_ext_v8_1); | |
15081 | } | |
15082 | ||
15083 | if (inst.operands[2].isscalar) | |
15084 | { | |
15085 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); | |
15086 | struct neon_type_el et = neon_check_type (3, rs, | |
15087 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
15088 | NEON_ENCODE (SCALAR, inst); | |
15089 | neon_mul_mac (et, neon_quad (rs)); | |
15090 | } | |
15091 | else | |
15092 | { | |
15093 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
15094 | struct neon_type_el et = neon_check_type (3, rs, | |
15095 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); | |
15096 | NEON_ENCODE (INTEGER, inst); | |
15097 | /* The U bit (rounding) comes from bit mask. */ | |
15098 | neon_three_same (neon_quad (rs), 0, et.size); | |
15099 | } | |
15100 | } | |
15101 | ||
5287ad62 JB |
15102 | static void |
15103 | do_neon_fcmp_absolute (void) | |
15104 | { | |
037e8744 | 15105 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
15106 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
15107 | N_F_16_32 | N_KEY); | |
5287ad62 | 15108 | /* Size field comes from bit mask. */ |
cc933301 | 15109 | neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1); |
5287ad62 JB |
15110 | } |
15111 | ||
15112 | static void | |
15113 | do_neon_fcmp_absolute_inv (void) | |
15114 | { | |
15115 | neon_exchange_operands (); | |
15116 | do_neon_fcmp_absolute (); | |
15117 | } | |
15118 | ||
15119 | static void | |
15120 | do_neon_step (void) | |
15121 | { | |
037e8744 | 15122 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
cc933301 JW |
15123 | struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK, |
15124 | N_F_16_32 | N_KEY); | |
15125 | neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1); | |
5287ad62 JB |
15126 | } |
15127 | ||
15128 | static void | |
15129 | do_neon_abs_neg (void) | |
15130 | { | |
037e8744 JB |
15131 | enum neon_shape rs; |
15132 | struct neon_type_el et; | |
5f4273c7 | 15133 | |
037e8744 JB |
15134 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
15135 | return; | |
15136 | ||
15137 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
15138 | return; | |
15139 | ||
15140 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
cc933301 | 15141 | et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY); |
5f4273c7 | 15142 | |
5287ad62 JB |
15143 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15144 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15145 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15146 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15147 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15148 | inst.instruction |= (et.type == NT_float) << 10; |
15149 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15150 | |
88714cb8 | 15151 | neon_dp_fixup (&inst); |
5287ad62 JB |
15152 | } |
15153 | ||
15154 | static void | |
15155 | do_neon_sli (void) | |
15156 | { | |
037e8744 | 15157 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15158 | struct neon_type_el et = neon_check_type (2, rs, |
15159 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15160 | int imm = inst.operands[2].imm; | |
15161 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 15162 | _("immediate out of range for insert")); |
037e8744 | 15163 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15164 | } |
15165 | ||
15166 | static void | |
15167 | do_neon_sri (void) | |
15168 | { | |
037e8744 | 15169 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15170 | struct neon_type_el et = neon_check_type (2, rs, |
15171 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15172 | int imm = inst.operands[2].imm; | |
15173 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15174 | _("immediate out of range for insert")); |
037e8744 | 15175 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
15176 | } |
15177 | ||
15178 | static void | |
15179 | do_neon_qshlu_imm (void) | |
15180 | { | |
037e8744 | 15181 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
15182 | struct neon_type_el et = neon_check_type (2, rs, |
15183 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
15184 | int imm = inst.operands[2].imm; | |
15185 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 15186 | _("immediate out of range for shift")); |
5287ad62 JB |
15187 | /* Only encodes the 'U present' variant of the instruction. |
15188 | In this case, signed types have OP (bit 8) set to 0. | |
15189 | Unsigned types have OP set to 1. */ | |
15190 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
15191 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 15192 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
15193 | } |
15194 | ||
15195 | static void | |
15196 | do_neon_qmovn (void) | |
15197 | { | |
15198 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15199 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15200 | /* Saturating move where operands can be signed or unsigned, and the | |
15201 | destination has the same signedness. */ | |
88714cb8 | 15202 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15203 | if (et.type == NT_unsigned) |
15204 | inst.instruction |= 0xc0; | |
15205 | else | |
15206 | inst.instruction |= 0x80; | |
15207 | neon_two_same (0, 1, et.size / 2); | |
15208 | } | |
15209 | ||
15210 | static void | |
15211 | do_neon_qmovun (void) | |
15212 | { | |
15213 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15214 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15215 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 15216 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15217 | neon_two_same (0, 1, et.size / 2); |
15218 | } | |
15219 | ||
15220 | static void | |
15221 | do_neon_rshift_sat_narrow (void) | |
15222 | { | |
15223 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15224 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15225 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15226 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15227 | int imm = inst.operands[2].imm; | |
15228 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15229 | right. */ | |
15230 | et.size /= 2; | |
5f4273c7 | 15231 | |
5287ad62 JB |
15232 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
15233 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
15234 | if (imm == 0) | |
15235 | { | |
15236 | inst.operands[2].present = 0; | |
15237 | inst.instruction = N_MNEM_vqmovn; | |
15238 | do_neon_qmovn (); | |
15239 | return; | |
15240 | } | |
5f4273c7 | 15241 | |
5287ad62 | 15242 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15243 | _("immediate out of range")); |
5287ad62 JB |
15244 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); |
15245 | } | |
15246 | ||
15247 | static void | |
15248 | do_neon_rshift_sat_narrow_u (void) | |
15249 | { | |
15250 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15251 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15252 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15253 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15254 | int imm = inst.operands[2].imm; | |
15255 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15256 | right. */ | |
15257 | et.size /= 2; | |
15258 | ||
15259 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
15260 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
15261 | if (imm == 0) | |
15262 | { | |
15263 | inst.operands[2].present = 0; | |
15264 | inst.instruction = N_MNEM_vqmovun; | |
15265 | do_neon_qmovun (); | |
15266 | return; | |
15267 | } | |
15268 | ||
15269 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15270 | _("immediate out of range")); |
5287ad62 JB |
15271 | /* FIXME: The manual is kind of unclear about what value U should have in |
15272 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
15273 | must be 1. */ | |
15274 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
15275 | } | |
15276 | ||
15277 | static void | |
15278 | do_neon_movn (void) | |
15279 | { | |
15280 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15281 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 15282 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15283 | neon_two_same (0, 1, et.size / 2); |
15284 | } | |
15285 | ||
15286 | static void | |
15287 | do_neon_rshift_narrow (void) | |
15288 | { | |
15289 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15290 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
15291 | int imm = inst.operands[2].imm; | |
15292 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15293 | right. */ | |
15294 | et.size /= 2; | |
5f4273c7 | 15295 | |
5287ad62 JB |
15296 | /* If immediate is zero then we are a pseudo-instruction for |
15297 | VMOVN.I<size> <Dd>, <Qm> */ | |
15298 | if (imm == 0) | |
15299 | { | |
15300 | inst.operands[2].present = 0; | |
15301 | inst.instruction = N_MNEM_vmovn; | |
15302 | do_neon_movn (); | |
15303 | return; | |
15304 | } | |
5f4273c7 | 15305 | |
5287ad62 | 15306 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15307 | _("immediate out of range for narrowing operation")); |
5287ad62 JB |
15308 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); |
15309 | } | |
15310 | ||
15311 | static void | |
15312 | do_neon_shll (void) | |
15313 | { | |
15314 | /* FIXME: Type checking when lengthening. */ | |
15315 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
15316 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
15317 | unsigned imm = inst.operands[2].imm; | |
15318 | ||
15319 | if (imm == et.size) | |
15320 | { | |
15321 | /* Maximum shift variant. */ | |
88714cb8 | 15322 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15323 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15324 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15325 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15326 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15327 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15328 | |
88714cb8 | 15329 | neon_dp_fixup (&inst); |
5287ad62 JB |
15330 | } |
15331 | else | |
15332 | { | |
15333 | /* A more-specific type check for non-max versions. */ | |
15334 | et = neon_check_type (2, NS_QDI, | |
477330fc | 15335 | N_EQK | N_DBL, N_SU_32 | N_KEY); |
88714cb8 | 15336 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15337 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
15338 | } | |
15339 | } | |
15340 | ||
037e8744 | 15341 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
15342 | the current instruction is. */ |
15343 | ||
6b9a8b67 MGD |
15344 | #define CVT_FLAVOUR_VAR \ |
15345 | CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \ | |
15346 | CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \ | |
15347 | CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \ | |
15348 | CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \ | |
15349 | /* Half-precision conversions. */ \ | |
cc933301 JW |
15350 | CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ |
15351 | CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \ | |
15352 | CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \ | |
15353 | CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \ | |
6b9a8b67 MGD |
15354 | CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \ |
15355 | CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \ | |
9db2f6b4 RL |
15356 | /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \ |
15357 | Compared with single/double precision variants, only the co-processor \ | |
15358 | field is different, so the encoding flow is reused here. */ \ | |
15359 | CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \ | |
15360 | CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \ | |
15361 | CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\ | |
15362 | CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\ | |
6b9a8b67 MGD |
15363 | /* VFP instructions. */ \ |
15364 | CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \ | |
15365 | CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \ | |
15366 | CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \ | |
15367 | CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \ | |
15368 | CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \ | |
15369 | CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \ | |
15370 | /* VFP instructions with bitshift. */ \ | |
15371 | CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \ | |
15372 | CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \ | |
15373 | CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \ | |
15374 | CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \ | |
15375 | CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \ | |
15376 | CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \ | |
15377 | CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \ | |
15378 | CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL) | |
15379 | ||
15380 | #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \ | |
15381 | neon_cvt_flavour_##C, | |
15382 | ||
15383 | /* The different types of conversions we can do. */ | |
15384 | enum neon_cvt_flavour | |
15385 | { | |
15386 | CVT_FLAVOUR_VAR | |
15387 | neon_cvt_flavour_invalid, | |
15388 | neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64 | |
15389 | }; | |
15390 | ||
15391 | #undef CVT_VAR | |
15392 | ||
15393 | static enum neon_cvt_flavour | |
15394 | get_neon_cvt_flavour (enum neon_shape rs) | |
5287ad62 | 15395 | { |
6b9a8b67 MGD |
15396 | #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \ |
15397 | et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \ | |
15398 | if (et.type != NT_invtype) \ | |
15399 | { \ | |
15400 | inst.error = NULL; \ | |
15401 | return (neon_cvt_flavour_##C); \ | |
5287ad62 | 15402 | } |
6b9a8b67 | 15403 | |
5287ad62 | 15404 | struct neon_type_el et; |
037e8744 | 15405 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
477330fc | 15406 | || rs == NS_FF) ? N_VFP : 0; |
037e8744 JB |
15407 | /* The instruction versions which take an immediate take one register |
15408 | argument, which is extended to the width of the full register. Thus the | |
15409 | "source" and "destination" registers must have the same width. Hack that | |
15410 | here by making the size equal to the key (wider, in this case) operand. */ | |
15411 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 15412 | |
6b9a8b67 MGD |
15413 | CVT_FLAVOUR_VAR; |
15414 | ||
15415 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
15416 | #undef CVT_VAR |
15417 | } | |
15418 | ||
7e8e6784 MGD |
15419 | enum neon_cvt_mode |
15420 | { | |
15421 | neon_cvt_mode_a, | |
15422 | neon_cvt_mode_n, | |
15423 | neon_cvt_mode_p, | |
15424 | neon_cvt_mode_m, | |
15425 | neon_cvt_mode_z, | |
30bdf752 MGD |
15426 | neon_cvt_mode_x, |
15427 | neon_cvt_mode_r | |
7e8e6784 MGD |
15428 | }; |
15429 | ||
037e8744 JB |
15430 | /* Neon-syntax VFP conversions. */ |
15431 | ||
5287ad62 | 15432 | static void |
6b9a8b67 | 15433 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 15434 | { |
037e8744 | 15435 | const char *opname = 0; |
5f4273c7 | 15436 | |
d54af2d0 RL |
15437 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI |
15438 | || rs == NS_FHI || rs == NS_HFI) | |
5287ad62 | 15439 | { |
037e8744 JB |
15440 | /* Conversions with immediate bitshift. */ |
15441 | const char *enc[] = | |
477330fc | 15442 | { |
6b9a8b67 MGD |
15443 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
15444 | CVT_FLAVOUR_VAR | |
15445 | NULL | |
15446 | #undef CVT_VAR | |
477330fc | 15447 | }; |
037e8744 | 15448 | |
6b9a8b67 | 15449 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc RM |
15450 | { |
15451 | opname = enc[flavour]; | |
15452 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
15453 | _("operands 0 and 1 must be the same register")); | |
15454 | inst.operands[1] = inst.operands[2]; | |
15455 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
15456 | } | |
5287ad62 JB |
15457 | } |
15458 | else | |
15459 | { | |
037e8744 JB |
15460 | /* Conversions without bitshift. */ |
15461 | const char *enc[] = | |
477330fc | 15462 | { |
6b9a8b67 MGD |
15463 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
15464 | CVT_FLAVOUR_VAR | |
15465 | NULL | |
15466 | #undef CVT_VAR | |
477330fc | 15467 | }; |
037e8744 | 15468 | |
6b9a8b67 | 15469 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc | 15470 | opname = enc[flavour]; |
037e8744 JB |
15471 | } |
15472 | ||
15473 | if (opname) | |
15474 | do_vfp_nsyn_opcode (opname); | |
9db2f6b4 RL |
15475 | |
15476 | /* ARMv8.2 fp16 VCVT instruction. */ | |
15477 | if (flavour == neon_cvt_flavour_s32_f16 | |
15478 | || flavour == neon_cvt_flavour_u32_f16 | |
15479 | || flavour == neon_cvt_flavour_f16_u32 | |
15480 | || flavour == neon_cvt_flavour_f16_s32) | |
15481 | do_scalar_fp16_v82_encode (); | |
037e8744 JB |
15482 | } |
15483 | ||
15484 | static void | |
15485 | do_vfp_nsyn_cvtz (void) | |
15486 | { | |
d54af2d0 | 15487 | enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL); |
6b9a8b67 | 15488 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
15489 | const char *enc[] = |
15490 | { | |
6b9a8b67 MGD |
15491 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
15492 | CVT_FLAVOUR_VAR | |
15493 | NULL | |
15494 | #undef CVT_VAR | |
037e8744 JB |
15495 | }; |
15496 | ||
6b9a8b67 | 15497 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
15498 | do_vfp_nsyn_opcode (enc[flavour]); |
15499 | } | |
f31fef98 | 15500 | |
037e8744 | 15501 | static void |
bacebabc | 15502 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
15503 | enum neon_cvt_mode mode) |
15504 | { | |
15505 | int sz, op; | |
15506 | int rm; | |
15507 | ||
a715796b TG |
15508 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
15509 | D register operands. */ | |
15510 | if (flavour == neon_cvt_flavour_s32_f64 | |
15511 | || flavour == neon_cvt_flavour_u32_f64) | |
15512 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15513 | _(BAD_FPU)); | |
15514 | ||
9db2f6b4 RL |
15515 | if (flavour == neon_cvt_flavour_s32_f16 |
15516 | || flavour == neon_cvt_flavour_u32_f16) | |
15517 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16), | |
15518 | _(BAD_FP16)); | |
15519 | ||
7e8e6784 MGD |
15520 | set_it_insn_type (OUTSIDE_IT_INSN); |
15521 | ||
15522 | switch (flavour) | |
15523 | { | |
15524 | case neon_cvt_flavour_s32_f64: | |
15525 | sz = 1; | |
827f64ff | 15526 | op = 1; |
7e8e6784 MGD |
15527 | break; |
15528 | case neon_cvt_flavour_s32_f32: | |
15529 | sz = 0; | |
15530 | op = 1; | |
15531 | break; | |
9db2f6b4 RL |
15532 | case neon_cvt_flavour_s32_f16: |
15533 | sz = 0; | |
15534 | op = 1; | |
15535 | break; | |
7e8e6784 MGD |
15536 | case neon_cvt_flavour_u32_f64: |
15537 | sz = 1; | |
15538 | op = 0; | |
15539 | break; | |
15540 | case neon_cvt_flavour_u32_f32: | |
15541 | sz = 0; | |
15542 | op = 0; | |
15543 | break; | |
9db2f6b4 RL |
15544 | case neon_cvt_flavour_u32_f16: |
15545 | sz = 0; | |
15546 | op = 0; | |
15547 | break; | |
7e8e6784 MGD |
15548 | default: |
15549 | first_error (_("invalid instruction shape")); | |
15550 | return; | |
15551 | } | |
15552 | ||
15553 | switch (mode) | |
15554 | { | |
15555 | case neon_cvt_mode_a: rm = 0; break; | |
15556 | case neon_cvt_mode_n: rm = 1; break; | |
15557 | case neon_cvt_mode_p: rm = 2; break; | |
15558 | case neon_cvt_mode_m: rm = 3; break; | |
15559 | default: first_error (_("invalid rounding mode")); return; | |
15560 | } | |
15561 | ||
15562 | NEON_ENCODE (FPV8, inst); | |
15563 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
15564 | encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm); | |
15565 | inst.instruction |= sz << 8; | |
9db2f6b4 RL |
15566 | |
15567 | /* ARMv8.2 fp16 VCVT instruction. */ | |
15568 | if (flavour == neon_cvt_flavour_s32_f16 | |
15569 | ||flavour == neon_cvt_flavour_u32_f16) | |
15570 | do_scalar_fp16_v82_encode (); | |
7e8e6784 MGD |
15571 | inst.instruction |= op << 7; |
15572 | inst.instruction |= rm << 16; | |
15573 | inst.instruction |= 0xf0000000; | |
15574 | inst.is_neon = TRUE; | |
15575 | } | |
15576 | ||
15577 | static void | |
15578 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
15579 | { |
15580 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
d54af2d0 RL |
15581 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, |
15582 | NS_FH, NS_HF, NS_FHI, NS_HFI, | |
15583 | NS_NULL); | |
6b9a8b67 | 15584 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 15585 | |
cc933301 JW |
15586 | if (flavour == neon_cvt_flavour_invalid) |
15587 | return; | |
15588 | ||
e3e535bc | 15589 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 15590 | if (mode == neon_cvt_mode_z |
e3e535bc | 15591 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
cc933301 JW |
15592 | && (flavour == neon_cvt_flavour_s16_f16 |
15593 | || flavour == neon_cvt_flavour_u16_f16 | |
15594 | || flavour == neon_cvt_flavour_s32_f32 | |
bacebabc RM |
15595 | || flavour == neon_cvt_flavour_u32_f32 |
15596 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 15597 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
15598 | && (rs == NS_FD || rs == NS_FF)) |
15599 | { | |
15600 | do_vfp_nsyn_cvtz (); | |
15601 | return; | |
15602 | } | |
15603 | ||
9db2f6b4 RL |
15604 | /* ARMv8.2 fp16 VCVT conversions. */ |
15605 | if (mode == neon_cvt_mode_z | |
15606 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16) | |
15607 | && (flavour == neon_cvt_flavour_s32_f16 | |
15608 | || flavour == neon_cvt_flavour_u32_f16) | |
15609 | && (rs == NS_FH)) | |
15610 | { | |
15611 | do_vfp_nsyn_cvtz (); | |
15612 | do_scalar_fp16_v82_encode (); | |
15613 | return; | |
15614 | } | |
15615 | ||
037e8744 | 15616 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 15617 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 15618 | { |
7e8e6784 MGD |
15619 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
15620 | do_vfp_nsyn_cvt (rs, flavour); | |
15621 | else | |
15622 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
15623 | ||
037e8744 JB |
15624 | return; |
15625 | } | |
15626 | ||
15627 | switch (rs) | |
15628 | { | |
15629 | case NS_DDI: | |
15630 | case NS_QQI: | |
15631 | { | |
477330fc | 15632 | unsigned immbits; |
cc933301 JW |
15633 | unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000, |
15634 | 0x0000100, 0x1000100, 0x0, 0x1000000}; | |
35997600 | 15635 | |
477330fc RM |
15636 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
15637 | return; | |
037e8744 | 15638 | |
477330fc RM |
15639 | /* Fixed-point conversion with #0 immediate is encoded as an |
15640 | integer conversion. */ | |
15641 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
15642 | goto int_encode; | |
477330fc RM |
15643 | NEON_ENCODE (IMMED, inst); |
15644 | if (flavour != neon_cvt_flavour_invalid) | |
15645 | inst.instruction |= enctab[flavour]; | |
15646 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15647 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15648 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15649 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15650 | inst.instruction |= neon_quad (rs) << 6; | |
15651 | inst.instruction |= 1 << 21; | |
cc933301 JW |
15652 | if (flavour < neon_cvt_flavour_s16_f16) |
15653 | { | |
15654 | inst.instruction |= 1 << 21; | |
15655 | immbits = 32 - inst.operands[2].imm; | |
15656 | inst.instruction |= immbits << 16; | |
15657 | } | |
15658 | else | |
15659 | { | |
15660 | inst.instruction |= 3 << 20; | |
15661 | immbits = 16 - inst.operands[2].imm; | |
15662 | inst.instruction |= immbits << 16; | |
15663 | inst.instruction &= ~(1 << 9); | |
15664 | } | |
477330fc RM |
15665 | |
15666 | neon_dp_fixup (&inst); | |
037e8744 JB |
15667 | } |
15668 | break; | |
15669 | ||
15670 | case NS_DD: | |
15671 | case NS_QQ: | |
7e8e6784 MGD |
15672 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
15673 | { | |
15674 | NEON_ENCODE (FLOAT, inst); | |
15675 | set_it_insn_type (OUTSIDE_IT_INSN); | |
15676 | ||
15677 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
15678 | return; | |
15679 | ||
15680 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15681 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15682 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15683 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15684 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
15685 | inst.instruction |= (flavour == neon_cvt_flavour_u16_f16 |
15686 | || flavour == neon_cvt_flavour_u32_f32) << 7; | |
7e8e6784 | 15687 | inst.instruction |= mode << 8; |
cc933301 JW |
15688 | if (flavour == neon_cvt_flavour_u16_f16 |
15689 | || flavour == neon_cvt_flavour_s16_f16) | |
15690 | /* Mask off the original size bits and reencode them. */ | |
15691 | inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18)); | |
15692 | ||
7e8e6784 MGD |
15693 | if (thumb_mode) |
15694 | inst.instruction |= 0xfc000000; | |
15695 | else | |
15696 | inst.instruction |= 0xf0000000; | |
15697 | } | |
15698 | else | |
15699 | { | |
037e8744 | 15700 | int_encode: |
7e8e6784 | 15701 | { |
cc933301 JW |
15702 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080, |
15703 | 0x100, 0x180, 0x0, 0x080}; | |
037e8744 | 15704 | |
7e8e6784 | 15705 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15706 | |
7e8e6784 MGD |
15707 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
15708 | return; | |
037e8744 | 15709 | |
7e8e6784 MGD |
15710 | if (flavour != neon_cvt_flavour_invalid) |
15711 | inst.instruction |= enctab[flavour]; | |
037e8744 | 15712 | |
7e8e6784 MGD |
15713 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15714 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15715 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15716 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15717 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
15718 | if (flavour >= neon_cvt_flavour_s16_f16 |
15719 | && flavour <= neon_cvt_flavour_f16_u16) | |
15720 | /* Half precision. */ | |
15721 | inst.instruction |= 1 << 18; | |
15722 | else | |
15723 | inst.instruction |= 2 << 18; | |
037e8744 | 15724 | |
7e8e6784 MGD |
15725 | neon_dp_fixup (&inst); |
15726 | } | |
15727 | } | |
15728 | break; | |
037e8744 | 15729 | |
8e79c3df CM |
15730 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
15731 | case NS_QD: | |
15732 | case NS_DQ: | |
15733 | ||
15734 | if ((rs == NS_DQ) | |
15735 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
15736 | { | |
15737 | as_bad (_("operand size must match register width")); | |
15738 | break; | |
15739 | } | |
15740 | ||
15741 | if ((rs == NS_QD) | |
15742 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
15743 | { | |
15744 | as_bad (_("operand size must match register width")); | |
15745 | break; | |
15746 | } | |
15747 | ||
15748 | if (rs == NS_DQ) | |
477330fc | 15749 | inst.instruction = 0x3b60600; |
8e79c3df CM |
15750 | else |
15751 | inst.instruction = 0x3b60700; | |
15752 | ||
15753 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15754 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15755 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15756 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 15757 | neon_dp_fixup (&inst); |
8e79c3df CM |
15758 | break; |
15759 | ||
037e8744 JB |
15760 | default: |
15761 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
15762 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
15763 | do_vfp_nsyn_cvt (rs, flavour); | |
15764 | else | |
15765 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
5287ad62 | 15766 | } |
5287ad62 JB |
15767 | } |
15768 | ||
e3e535bc NC |
15769 | static void |
15770 | do_neon_cvtr (void) | |
15771 | { | |
7e8e6784 | 15772 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
15773 | } |
15774 | ||
15775 | static void | |
15776 | do_neon_cvt (void) | |
15777 | { | |
7e8e6784 MGD |
15778 | do_neon_cvt_1 (neon_cvt_mode_z); |
15779 | } | |
15780 | ||
15781 | static void | |
15782 | do_neon_cvta (void) | |
15783 | { | |
15784 | do_neon_cvt_1 (neon_cvt_mode_a); | |
15785 | } | |
15786 | ||
15787 | static void | |
15788 | do_neon_cvtn (void) | |
15789 | { | |
15790 | do_neon_cvt_1 (neon_cvt_mode_n); | |
15791 | } | |
15792 | ||
15793 | static void | |
15794 | do_neon_cvtp (void) | |
15795 | { | |
15796 | do_neon_cvt_1 (neon_cvt_mode_p); | |
15797 | } | |
15798 | ||
15799 | static void | |
15800 | do_neon_cvtm (void) | |
15801 | { | |
15802 | do_neon_cvt_1 (neon_cvt_mode_m); | |
e3e535bc NC |
15803 | } |
15804 | ||
8e79c3df | 15805 | static void |
c70a8987 | 15806 | do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double) |
8e79c3df | 15807 | { |
c70a8987 MGD |
15808 | if (is_double) |
15809 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 15810 | |
c70a8987 MGD |
15811 | encode_arm_vfp_reg (inst.operands[0].reg, |
15812 | (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd); | |
15813 | encode_arm_vfp_reg (inst.operands[1].reg, | |
15814 | (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm); | |
15815 | inst.instruction |= to ? 0x10000 : 0; | |
15816 | inst.instruction |= t ? 0x80 : 0; | |
15817 | inst.instruction |= is_double ? 0x100 : 0; | |
15818 | do_vfp_cond_or_thumb (); | |
15819 | } | |
8e79c3df | 15820 | |
c70a8987 MGD |
15821 | static void |
15822 | do_neon_cvttb_1 (bfd_boolean t) | |
15823 | { | |
d54af2d0 RL |
15824 | enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD, |
15825 | NS_DF, NS_DH, NS_NULL); | |
8e79c3df | 15826 | |
c70a8987 MGD |
15827 | if (rs == NS_NULL) |
15828 | return; | |
15829 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) | |
15830 | { | |
15831 | inst.error = NULL; | |
15832 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE); | |
15833 | } | |
15834 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
15835 | { | |
15836 | inst.error = NULL; | |
15837 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE); | |
15838 | } | |
15839 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
15840 | { | |
a715796b TG |
15841 | /* The VCVTB and VCVTT instructions with D-register operands |
15842 | don't work for SP only targets. */ | |
15843 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15844 | _(BAD_FPU)); | |
15845 | ||
c70a8987 MGD |
15846 | inst.error = NULL; |
15847 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE); | |
15848 | } | |
15849 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
15850 | { | |
a715796b TG |
15851 | /* The VCVTB and VCVTT instructions with D-register operands |
15852 | don't work for SP only targets. */ | |
15853 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15854 | _(BAD_FPU)); | |
15855 | ||
c70a8987 MGD |
15856 | inst.error = NULL; |
15857 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE); | |
15858 | } | |
15859 | else | |
15860 | return; | |
15861 | } | |
15862 | ||
15863 | static void | |
15864 | do_neon_cvtb (void) | |
15865 | { | |
15866 | do_neon_cvttb_1 (FALSE); | |
8e79c3df CM |
15867 | } |
15868 | ||
15869 | ||
15870 | static void | |
15871 | do_neon_cvtt (void) | |
15872 | { | |
c70a8987 | 15873 | do_neon_cvttb_1 (TRUE); |
8e79c3df CM |
15874 | } |
15875 | ||
5287ad62 JB |
15876 | static void |
15877 | neon_move_immediate (void) | |
15878 | { | |
037e8744 JB |
15879 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
15880 | struct neon_type_el et = neon_check_type (2, rs, | |
15881 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 15882 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 15883 | int op, cmode, float_p; |
5287ad62 | 15884 | |
037e8744 | 15885 | constraint (et.type == NT_invtype, |
477330fc | 15886 | _("operand size must be specified for immediate VMOV")); |
037e8744 | 15887 | |
5287ad62 JB |
15888 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
15889 | op = (inst.instruction & (1 << 5)) != 0; | |
15890 | ||
15891 | immlo = inst.operands[1].imm; | |
15892 | if (inst.operands[1].regisimm) | |
15893 | immhi = inst.operands[1].reg; | |
15894 | ||
15895 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
477330fc | 15896 | _("immediate has bits set outside the operand size")); |
5287ad62 | 15897 | |
c96612cc JB |
15898 | float_p = inst.operands[1].immisfloat; |
15899 | ||
15900 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
477330fc | 15901 | et.size, et.type)) == FAIL) |
5287ad62 JB |
15902 | { |
15903 | /* Invert relevant bits only. */ | |
15904 | neon_invert_size (&immlo, &immhi, et.size); | |
15905 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
477330fc RM |
15906 | with one or the other; those cases are caught by |
15907 | neon_cmode_for_move_imm. */ | |
5287ad62 | 15908 | op = !op; |
c96612cc JB |
15909 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
15910 | &op, et.size, et.type)) == FAIL) | |
477330fc RM |
15911 | { |
15912 | first_error (_("immediate out of range")); | |
15913 | return; | |
15914 | } | |
5287ad62 JB |
15915 | } |
15916 | ||
15917 | inst.instruction &= ~(1 << 5); | |
15918 | inst.instruction |= op << 5; | |
15919 | ||
15920 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15921 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 15922 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15923 | inst.instruction |= cmode << 8; |
15924 | ||
15925 | neon_write_immbits (immbits); | |
15926 | } | |
15927 | ||
15928 | static void | |
15929 | do_neon_mvn (void) | |
15930 | { | |
15931 | if (inst.operands[1].isreg) | |
15932 | { | |
037e8744 | 15933 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 15934 | |
88714cb8 | 15935 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15936 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15937 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15938 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15939 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15940 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15941 | } |
15942 | else | |
15943 | { | |
88714cb8 | 15944 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15945 | neon_move_immediate (); |
15946 | } | |
15947 | ||
88714cb8 | 15948 | neon_dp_fixup (&inst); |
5287ad62 JB |
15949 | } |
15950 | ||
15951 | /* Encode instructions of form: | |
15952 | ||
15953 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 15954 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
15955 | |
15956 | static void | |
15957 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
15958 | { | |
15959 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15960 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15961 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15962 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15963 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15964 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15965 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
15966 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 15967 | |
88714cb8 | 15968 | neon_dp_fixup (&inst); |
5287ad62 JB |
15969 | } |
15970 | ||
15971 | static void | |
15972 | do_neon_dyadic_long (void) | |
15973 | { | |
15974 | /* FIXME: Type checking for lengthening op. */ | |
15975 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15976 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
15977 | neon_mixed_length (et, et.size); | |
15978 | } | |
15979 | ||
15980 | static void | |
15981 | do_neon_abal (void) | |
15982 | { | |
15983 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15984 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
15985 | neon_mixed_length (et, et.size); | |
15986 | } | |
15987 | ||
15988 | static void | |
15989 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
15990 | { | |
15991 | if (inst.operands[2].isscalar) | |
15992 | { | |
dcbf9037 | 15993 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
477330fc | 15994 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); |
88714cb8 | 15995 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
15996 | neon_mul_mac (et, et.type == NT_unsigned); |
15997 | } | |
15998 | else | |
15999 | { | |
16000 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 16001 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); |
88714cb8 | 16002 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
16003 | neon_mixed_length (et, et.size); |
16004 | } | |
16005 | } | |
16006 | ||
16007 | static void | |
16008 | do_neon_mac_maybe_scalar_long (void) | |
16009 | { | |
16010 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
16011 | } | |
16012 | ||
16013 | static void | |
16014 | do_neon_dyadic_wide (void) | |
16015 | { | |
16016 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
16017 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
16018 | neon_mixed_length (et, et.size); | |
16019 | } | |
16020 | ||
16021 | static void | |
16022 | do_neon_dyadic_narrow (void) | |
16023 | { | |
16024 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
16025 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
16026 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
16027 | so force the operand type to integer. */ | |
16028 | et.type = NT_integer; | |
5287ad62 JB |
16029 | neon_mixed_length (et, et.size / 2); |
16030 | } | |
16031 | ||
16032 | static void | |
16033 | do_neon_mul_sat_scalar_long (void) | |
16034 | { | |
16035 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
16036 | } | |
16037 | ||
16038 | static void | |
16039 | do_neon_vmull (void) | |
16040 | { | |
16041 | if (inst.operands[2].isscalar) | |
16042 | do_neon_mac_maybe_scalar_long (); | |
16043 | else | |
16044 | { | |
16045 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 16046 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
4f51b4bd | 16047 | |
5287ad62 | 16048 | if (et.type == NT_poly) |
477330fc | 16049 | NEON_ENCODE (POLY, inst); |
5287ad62 | 16050 | else |
477330fc | 16051 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
16052 | |
16053 | /* For polynomial encoding the U bit must be zero, and the size must | |
16054 | be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non | |
16055 | obviously, as 0b10). */ | |
16056 | if (et.size == 64) | |
16057 | { | |
16058 | /* Check we're on the correct architecture. */ | |
16059 | if (!mark_feature_used (&fpu_crypto_ext_armv8)) | |
16060 | inst.error = | |
16061 | _("Instruction form not available on this architecture."); | |
16062 | ||
16063 | et.size = 32; | |
16064 | } | |
16065 | ||
5287ad62 JB |
16066 | neon_mixed_length (et, et.size); |
16067 | } | |
16068 | } | |
16069 | ||
16070 | static void | |
16071 | do_neon_ext (void) | |
16072 | { | |
037e8744 | 16073 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
16074 | struct neon_type_el et = neon_check_type (3, rs, |
16075 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
16076 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
16077 | |
16078 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
16079 | _("shift out of range")); | |
5287ad62 JB |
16080 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16081 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16082 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16083 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16084 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16085 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 16086 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 16087 | inst.instruction |= imm << 8; |
5f4273c7 | 16088 | |
88714cb8 | 16089 | neon_dp_fixup (&inst); |
5287ad62 JB |
16090 | } |
16091 | ||
16092 | static void | |
16093 | do_neon_rev (void) | |
16094 | { | |
037e8744 | 16095 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16096 | struct neon_type_el et = neon_check_type (2, rs, |
16097 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
16098 | unsigned op = (inst.instruction >> 7) & 3; | |
16099 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
16100 | extract it here to check the elements to be reversed are smaller. | |
16101 | Otherwise we'd get a reserved instruction. */ | |
16102 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 16103 | gas_assert (elsize != 0); |
5287ad62 | 16104 | constraint (et.size >= elsize, |
477330fc | 16105 | _("elements must be smaller than reversal region")); |
037e8744 | 16106 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16107 | } |
16108 | ||
16109 | static void | |
16110 | do_neon_dup (void) | |
16111 | { | |
16112 | if (inst.operands[1].isscalar) | |
16113 | { | |
037e8744 | 16114 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 | 16115 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 16116 | N_EQK, N_8 | N_16 | N_32 | N_KEY); |
5287ad62 | 16117 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 16118 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 16119 | int logsize = neon_logbits (et.size); |
dcbf9037 | 16120 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
16121 | |
16122 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
477330fc | 16123 | return; |
037e8744 | 16124 | |
88714cb8 | 16125 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
16126 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
16127 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16128 | inst.instruction |= LOW4 (dm); | |
16129 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 16130 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
16131 | inst.instruction |= x << 17; |
16132 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 16133 | |
88714cb8 | 16134 | neon_dp_fixup (&inst); |
5287ad62 JB |
16135 | } |
16136 | else | |
16137 | { | |
037e8744 JB |
16138 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
16139 | struct neon_type_el et = neon_check_type (2, rs, | |
477330fc | 16140 | N_8 | N_16 | N_32 | N_KEY, N_EQK); |
5287ad62 | 16141 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 16142 | NEON_ENCODE (ARMREG, inst); |
5287ad62 | 16143 | switch (et.size) |
477330fc RM |
16144 | { |
16145 | case 8: inst.instruction |= 0x400000; break; | |
16146 | case 16: inst.instruction |= 0x000020; break; | |
16147 | case 32: inst.instruction |= 0x000000; break; | |
16148 | default: break; | |
16149 | } | |
5287ad62 JB |
16150 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; |
16151 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
16152 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 16153 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 | 16154 | /* The encoding for this instruction is identical for the ARM and Thumb |
477330fc | 16155 | variants, except for the condition field. */ |
037e8744 | 16156 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
16157 | } |
16158 | } | |
16159 | ||
16160 | /* VMOV has particularly many variations. It can be one of: | |
16161 | 0. VMOV<c><q> <Qd>, <Qm> | |
16162 | 1. VMOV<c><q> <Dd>, <Dm> | |
16163 | (Register operations, which are VORR with Rm = Rn.) | |
16164 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
16165 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
16166 | (Immediate loads.) | |
16167 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
16168 | (ARM register to scalar.) | |
16169 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
16170 | (Two ARM registers to vector.) | |
16171 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
16172 | (Scalar to ARM register.) | |
16173 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
16174 | (Vector to two ARM registers.) | |
037e8744 JB |
16175 | 8. VMOV.F32 <Sd>, <Sm> |
16176 | 9. VMOV.F64 <Dd>, <Dm> | |
16177 | (VFP register moves.) | |
16178 | 10. VMOV.F32 <Sd>, #imm | |
16179 | 11. VMOV.F64 <Dd>, #imm | |
16180 | (VFP float immediate load.) | |
16181 | 12. VMOV <Rd>, <Sm> | |
16182 | (VFP single to ARM reg.) | |
16183 | 13. VMOV <Sd>, <Rm> | |
16184 | (ARM reg to VFP single.) | |
16185 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
16186 | (Two ARM regs to two VFP singles.) | |
16187 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
16188 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 16189 | |
037e8744 JB |
16190 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
16191 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 16192 | |
5287ad62 | 16193 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 16194 | |
b7fc2769 JB |
16195 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
16196 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 16197 | |
5287ad62 | 16198 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 16199 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
16200 | |
16201 | static void | |
16202 | do_neon_mov (void) | |
16203 | { | |
037e8744 | 16204 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
9db2f6b4 RL |
16205 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, |
16206 | NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
16207 | NS_HR, NS_RH, NS_HI, NS_NULL); | |
037e8744 JB |
16208 | struct neon_type_el et; |
16209 | const char *ldconst = 0; | |
5287ad62 | 16210 | |
037e8744 | 16211 | switch (rs) |
5287ad62 | 16212 | { |
037e8744 JB |
16213 | case NS_DD: /* case 1/9. */ |
16214 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
16215 | /* It is not an error here if no type is given. */ | |
16216 | inst.error = NULL; | |
16217 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
16218 | { |
16219 | do_vfp_nsyn_opcode ("fcpyd"); | |
16220 | break; | |
16221 | } | |
037e8744 | 16222 | /* fall through. */ |
5287ad62 | 16223 | |
037e8744 JB |
16224 | case NS_QQ: /* case 0/1. */ |
16225 | { | |
477330fc RM |
16226 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
16227 | return; | |
16228 | /* The architecture manual I have doesn't explicitly state which | |
16229 | value the U bit should have for register->register moves, but | |
16230 | the equivalent VORR instruction has U = 0, so do that. */ | |
16231 | inst.instruction = 0x0200110; | |
16232 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16233 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16234 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16235 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16236 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16237 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16238 | inst.instruction |= neon_quad (rs) << 6; | |
16239 | ||
16240 | neon_dp_fixup (&inst); | |
037e8744 JB |
16241 | } |
16242 | break; | |
5f4273c7 | 16243 | |
037e8744 JB |
16244 | case NS_DI: /* case 3/11. */ |
16245 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
16246 | inst.error = NULL; | |
16247 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
16248 | { |
16249 | /* case 11 (fconstd). */ | |
16250 | ldconst = "fconstd"; | |
16251 | goto encode_fconstd; | |
16252 | } | |
037e8744 JB |
16253 | /* fall through. */ |
16254 | ||
16255 | case NS_QI: /* case 2/3. */ | |
16256 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
477330fc | 16257 | return; |
037e8744 JB |
16258 | inst.instruction = 0x0800010; |
16259 | neon_move_immediate (); | |
88714cb8 | 16260 | neon_dp_fixup (&inst); |
5287ad62 | 16261 | break; |
5f4273c7 | 16262 | |
037e8744 JB |
16263 | case NS_SR: /* case 4. */ |
16264 | { | |
477330fc RM |
16265 | unsigned bcdebits = 0; |
16266 | int logsize; | |
16267 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
16268 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
037e8744 | 16269 | |
05ac0ffb JB |
16270 | /* .<size> is optional here, defaulting to .32. */ |
16271 | if (inst.vectype.elems == 0 | |
16272 | && inst.operands[0].vectype.type == NT_invtype | |
16273 | && inst.operands[1].vectype.type == NT_invtype) | |
16274 | { | |
16275 | inst.vectype.el[0].type = NT_untyped; | |
16276 | inst.vectype.el[0].size = 32; | |
16277 | inst.vectype.elems = 1; | |
16278 | } | |
16279 | ||
477330fc RM |
16280 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
16281 | logsize = neon_logbits (et.size); | |
16282 | ||
16283 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
16284 | _(BAD_FPU)); | |
16285 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
16286 | && et.size != 32, _(BAD_FPU)); | |
16287 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
16288 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
16289 | ||
16290 | switch (et.size) | |
16291 | { | |
16292 | case 8: bcdebits = 0x8; break; | |
16293 | case 16: bcdebits = 0x1; break; | |
16294 | case 32: bcdebits = 0x0; break; | |
16295 | default: ; | |
16296 | } | |
16297 | ||
16298 | bcdebits |= x << logsize; | |
16299 | ||
16300 | inst.instruction = 0xe000b10; | |
16301 | do_vfp_cond_or_thumb (); | |
16302 | inst.instruction |= LOW4 (dn) << 16; | |
16303 | inst.instruction |= HI1 (dn) << 7; | |
16304 | inst.instruction |= inst.operands[1].reg << 12; | |
16305 | inst.instruction |= (bcdebits & 3) << 5; | |
16306 | inst.instruction |= (bcdebits >> 2) << 21; | |
037e8744 JB |
16307 | } |
16308 | break; | |
5f4273c7 | 16309 | |
037e8744 | 16310 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 16311 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
477330fc | 16312 | _(BAD_FPU)); |
b7fc2769 | 16313 | |
037e8744 JB |
16314 | inst.instruction = 0xc400b10; |
16315 | do_vfp_cond_or_thumb (); | |
16316 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
16317 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
16318 | inst.instruction |= inst.operands[1].reg << 12; | |
16319 | inst.instruction |= inst.operands[2].reg << 16; | |
16320 | break; | |
5f4273c7 | 16321 | |
037e8744 JB |
16322 | case NS_RS: /* case 6. */ |
16323 | { | |
477330fc RM |
16324 | unsigned logsize; |
16325 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
16326 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
16327 | unsigned abcdebits = 0; | |
037e8744 | 16328 | |
05ac0ffb JB |
16329 | /* .<dt> is optional here, defaulting to .32. */ |
16330 | if (inst.vectype.elems == 0 | |
16331 | && inst.operands[0].vectype.type == NT_invtype | |
16332 | && inst.operands[1].vectype.type == NT_invtype) | |
16333 | { | |
16334 | inst.vectype.el[0].type = NT_untyped; | |
16335 | inst.vectype.el[0].size = 32; | |
16336 | inst.vectype.elems = 1; | |
16337 | } | |
16338 | ||
91d6fa6a NC |
16339 | et = neon_check_type (2, NS_NULL, |
16340 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
477330fc RM |
16341 | logsize = neon_logbits (et.size); |
16342 | ||
16343 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
16344 | _(BAD_FPU)); | |
16345 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
16346 | && et.size != 32, _(BAD_FPU)); | |
16347 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
16348 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
16349 | ||
16350 | switch (et.size) | |
16351 | { | |
16352 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
16353 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
16354 | case 32: abcdebits = 0x00; break; | |
16355 | default: ; | |
16356 | } | |
16357 | ||
16358 | abcdebits |= x << logsize; | |
16359 | inst.instruction = 0xe100b10; | |
16360 | do_vfp_cond_or_thumb (); | |
16361 | inst.instruction |= LOW4 (dn) << 16; | |
16362 | inst.instruction |= HI1 (dn) << 7; | |
16363 | inst.instruction |= inst.operands[0].reg << 12; | |
16364 | inst.instruction |= (abcdebits & 3) << 5; | |
16365 | inst.instruction |= (abcdebits >> 2) << 21; | |
037e8744 JB |
16366 | } |
16367 | break; | |
5f4273c7 | 16368 | |
037e8744 JB |
16369 | case NS_RRD: /* case 7 (fmrrd). */ |
16370 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
477330fc | 16371 | _(BAD_FPU)); |
037e8744 JB |
16372 | |
16373 | inst.instruction = 0xc500b10; | |
16374 | do_vfp_cond_or_thumb (); | |
16375 | inst.instruction |= inst.operands[0].reg << 12; | |
16376 | inst.instruction |= inst.operands[1].reg << 16; | |
16377 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16378 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16379 | break; | |
5f4273c7 | 16380 | |
037e8744 JB |
16381 | case NS_FF: /* case 8 (fcpys). */ |
16382 | do_vfp_nsyn_opcode ("fcpys"); | |
16383 | break; | |
5f4273c7 | 16384 | |
9db2f6b4 | 16385 | case NS_HI: |
037e8744 JB |
16386 | case NS_FI: /* case 10 (fconsts). */ |
16387 | ldconst = "fconsts"; | |
16388 | encode_fconstd: | |
16389 | if (is_quarter_float (inst.operands[1].imm)) | |
477330fc RM |
16390 | { |
16391 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); | |
16392 | do_vfp_nsyn_opcode (ldconst); | |
9db2f6b4 RL |
16393 | |
16394 | /* ARMv8.2 fp16 vmov.f16 instruction. */ | |
16395 | if (rs == NS_HI) | |
16396 | do_scalar_fp16_v82_encode (); | |
477330fc | 16397 | } |
5287ad62 | 16398 | else |
477330fc | 16399 | first_error (_("immediate out of range")); |
037e8744 | 16400 | break; |
5f4273c7 | 16401 | |
9db2f6b4 | 16402 | case NS_RH: |
037e8744 JB |
16403 | case NS_RF: /* case 12 (fmrs). */ |
16404 | do_vfp_nsyn_opcode ("fmrs"); | |
9db2f6b4 RL |
16405 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
16406 | if (rs == NS_RH) | |
16407 | do_scalar_fp16_v82_encode (); | |
037e8744 | 16408 | break; |
5f4273c7 | 16409 | |
9db2f6b4 | 16410 | case NS_HR: |
037e8744 JB |
16411 | case NS_FR: /* case 13 (fmsr). */ |
16412 | do_vfp_nsyn_opcode ("fmsr"); | |
9db2f6b4 RL |
16413 | /* ARMv8.2 fp16 vmov.f16 instruction. */ |
16414 | if (rs == NS_HR) | |
16415 | do_scalar_fp16_v82_encode (); | |
037e8744 | 16416 | break; |
5f4273c7 | 16417 | |
037e8744 JB |
16418 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
16419 | (one of which is a list), but we have parsed four. Do some fiddling to | |
16420 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
16421 | expect. */ | |
16422 | case NS_RRFF: /* case 14 (fmrrs). */ | |
16423 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
477330fc | 16424 | _("VFP registers must be adjacent")); |
037e8744 JB |
16425 | inst.operands[2].imm = 2; |
16426 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
16427 | do_vfp_nsyn_opcode ("fmrrs"); | |
16428 | break; | |
5f4273c7 | 16429 | |
037e8744 JB |
16430 | case NS_FFRR: /* case 15 (fmsrr). */ |
16431 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
477330fc | 16432 | _("VFP registers must be adjacent")); |
037e8744 JB |
16433 | inst.operands[1] = inst.operands[2]; |
16434 | inst.operands[2] = inst.operands[3]; | |
16435 | inst.operands[0].imm = 2; | |
16436 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
16437 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 16438 | break; |
5f4273c7 | 16439 | |
4c261dff NC |
16440 | case NS_NULL: |
16441 | /* neon_select_shape has determined that the instruction | |
16442 | shape is wrong and has already set the error message. */ | |
16443 | break; | |
16444 | ||
5287ad62 JB |
16445 | default: |
16446 | abort (); | |
16447 | } | |
16448 | } | |
16449 | ||
16450 | static void | |
16451 | do_neon_rshift_round_imm (void) | |
16452 | { | |
037e8744 | 16453 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
16454 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
16455 | int imm = inst.operands[2].imm; | |
16456 | ||
16457 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
16458 | if (imm == 0) | |
16459 | { | |
16460 | inst.operands[2].present = 0; | |
16461 | do_neon_mov (); | |
16462 | return; | |
16463 | } | |
16464 | ||
16465 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 16466 | _("immediate out of range for shift")); |
037e8744 | 16467 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
477330fc | 16468 | et.size - imm); |
5287ad62 JB |
16469 | } |
16470 | ||
9db2f6b4 RL |
16471 | static void |
16472 | do_neon_movhf (void) | |
16473 | { | |
16474 | enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL); | |
16475 | constraint (rs != NS_HH, _("invalid suffix")); | |
16476 | ||
16477 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16478 | _(BAD_FPU)); | |
16479 | ||
16480 | do_vfp_sp_monadic (); | |
16481 | ||
16482 | inst.is_neon = 1; | |
16483 | inst.instruction |= 0xf0000000; | |
16484 | } | |
16485 | ||
5287ad62 JB |
16486 | static void |
16487 | do_neon_movl (void) | |
16488 | { | |
16489 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
16490 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
16491 | unsigned sizebits = et.size >> 3; | |
16492 | inst.instruction |= sizebits << 19; | |
16493 | neon_two_same (0, et.type == NT_unsigned, -1); | |
16494 | } | |
16495 | ||
16496 | static void | |
16497 | do_neon_trn (void) | |
16498 | { | |
037e8744 | 16499 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16500 | struct neon_type_el et = neon_check_type (2, rs, |
16501 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 16502 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 16503 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16504 | } |
16505 | ||
16506 | static void | |
16507 | do_neon_zip_uzp (void) | |
16508 | { | |
037e8744 | 16509 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16510 | struct neon_type_el et = neon_check_type (2, rs, |
16511 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
16512 | if (rs == NS_DD && et.size == 32) | |
16513 | { | |
16514 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
16515 | inst.instruction = N_MNEM_vtrn; | |
16516 | do_neon_trn (); | |
16517 | return; | |
16518 | } | |
037e8744 | 16519 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16520 | } |
16521 | ||
16522 | static void | |
16523 | do_neon_sat_abs_neg (void) | |
16524 | { | |
037e8744 | 16525 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16526 | struct neon_type_el et = neon_check_type (2, rs, |
16527 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 16528 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16529 | } |
16530 | ||
16531 | static void | |
16532 | do_neon_pair_long (void) | |
16533 | { | |
037e8744 | 16534 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16535 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
16536 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
16537 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 16538 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16539 | } |
16540 | ||
16541 | static void | |
16542 | do_neon_recip_est (void) | |
16543 | { | |
037e8744 | 16544 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 | 16545 | struct neon_type_el et = neon_check_type (2, rs, |
cc933301 | 16546 | N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY); |
5287ad62 | 16547 | inst.instruction |= (et.type == NT_float) << 8; |
037e8744 | 16548 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16549 | } |
16550 | ||
16551 | static void | |
16552 | do_neon_cls (void) | |
16553 | { | |
037e8744 | 16554 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16555 | struct neon_type_el et = neon_check_type (2, rs, |
16556 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 16557 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16558 | } |
16559 | ||
16560 | static void | |
16561 | do_neon_clz (void) | |
16562 | { | |
037e8744 | 16563 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16564 | struct neon_type_el et = neon_check_type (2, rs, |
16565 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 16566 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16567 | } |
16568 | ||
16569 | static void | |
16570 | do_neon_cnt (void) | |
16571 | { | |
037e8744 | 16572 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16573 | struct neon_type_el et = neon_check_type (2, rs, |
16574 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 16575 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16576 | } |
16577 | ||
16578 | static void | |
16579 | do_neon_swp (void) | |
16580 | { | |
037e8744 JB |
16581 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
16582 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
16583 | } |
16584 | ||
16585 | static void | |
16586 | do_neon_tbl_tbx (void) | |
16587 | { | |
16588 | unsigned listlenbits; | |
dcbf9037 | 16589 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 16590 | |
5287ad62 JB |
16591 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
16592 | { | |
dcbf9037 | 16593 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
16594 | return; |
16595 | } | |
5f4273c7 | 16596 | |
5287ad62 JB |
16597 | listlenbits = inst.operands[1].imm - 1; |
16598 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16599 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16600 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16601 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16602 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16603 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16604 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 16605 | |
88714cb8 | 16606 | neon_dp_fixup (&inst); |
5287ad62 JB |
16607 | } |
16608 | ||
16609 | static void | |
16610 | do_neon_ldm_stm (void) | |
16611 | { | |
16612 | /* P, U and L bits are part of bitmask. */ | |
16613 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
16614 | unsigned offsetbits = inst.operands[1].imm * 2; | |
16615 | ||
037e8744 JB |
16616 | if (inst.operands[1].issingle) |
16617 | { | |
16618 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
16619 | return; | |
16620 | } | |
16621 | ||
5287ad62 | 16622 | constraint (is_dbmode && !inst.operands[0].writeback, |
477330fc | 16623 | _("writeback (!) must be used for VLDMDB and VSTMDB")); |
5287ad62 JB |
16624 | |
16625 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
477330fc RM |
16626 | _("register list must contain at least 1 and at most 16 " |
16627 | "registers")); | |
5287ad62 JB |
16628 | |
16629 | inst.instruction |= inst.operands[0].reg << 16; | |
16630 | inst.instruction |= inst.operands[0].writeback << 21; | |
16631 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
16632 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
16633 | ||
16634 | inst.instruction |= offsetbits; | |
5f4273c7 | 16635 | |
037e8744 | 16636 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
16637 | } |
16638 | ||
16639 | static void | |
16640 | do_neon_ldr_str (void) | |
16641 | { | |
5287ad62 | 16642 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 16643 | |
6844b2c2 MGD |
16644 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
16645 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 16646 | if (!is_ldr |
6844b2c2 | 16647 | && inst.operands[1].reg == REG_PC |
ba86b375 | 16648 | && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode)) |
6844b2c2 | 16649 | { |
94dcf8bf | 16650 | if (thumb_mode) |
6844b2c2 | 16651 | inst.error = _("Use of PC here is UNPREDICTABLE"); |
94dcf8bf | 16652 | else if (warn_on_deprecated) |
5c3696f8 | 16653 | as_tsktsk (_("Use of PC here is deprecated")); |
6844b2c2 MGD |
16654 | } |
16655 | ||
037e8744 JB |
16656 | if (inst.operands[0].issingle) |
16657 | { | |
cd2f129f | 16658 | if (is_ldr) |
477330fc | 16659 | do_vfp_nsyn_opcode ("flds"); |
cd2f129f | 16660 | else |
477330fc | 16661 | do_vfp_nsyn_opcode ("fsts"); |
9db2f6b4 RL |
16662 | |
16663 | /* ARMv8.2 vldr.16/vstr.16 instruction. */ | |
16664 | if (inst.vectype.el[0].size == 16) | |
16665 | do_scalar_fp16_v82_encode (); | |
5287ad62 JB |
16666 | } |
16667 | else | |
5287ad62 | 16668 | { |
cd2f129f | 16669 | if (is_ldr) |
477330fc | 16670 | do_vfp_nsyn_opcode ("fldd"); |
5287ad62 | 16671 | else |
477330fc | 16672 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 16673 | } |
5287ad62 JB |
16674 | } |
16675 | ||
16676 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
16677 | instructions. */ | |
16678 | ||
16679 | static void | |
16680 | do_neon_ld_st_interleave (void) | |
16681 | { | |
037e8744 | 16682 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
477330fc | 16683 | N_8 | N_16 | N_32 | N_64); |
5287ad62 JB |
16684 | unsigned alignbits = 0; |
16685 | unsigned idx; | |
16686 | /* The bits in this table go: | |
16687 | 0: register stride of one (0) or two (1) | |
16688 | 1,2: register list length, minus one (1, 2, 3, 4). | |
16689 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
16690 | We use -1 for invalid entries. */ | |
16691 | const int typetable[] = | |
16692 | { | |
16693 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
16694 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
16695 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
16696 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
16697 | }; | |
16698 | int typebits; | |
16699 | ||
dcbf9037 JB |
16700 | if (et.type == NT_invtype) |
16701 | return; | |
16702 | ||
5287ad62 JB |
16703 | if (inst.operands[1].immisalign) |
16704 | switch (inst.operands[1].imm >> 8) | |
16705 | { | |
16706 | case 64: alignbits = 1; break; | |
16707 | case 128: | |
477330fc | 16708 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
e23c0ad8 | 16709 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
477330fc RM |
16710 | goto bad_alignment; |
16711 | alignbits = 2; | |
16712 | break; | |
5287ad62 | 16713 | case 256: |
477330fc RM |
16714 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
16715 | goto bad_alignment; | |
16716 | alignbits = 3; | |
16717 | break; | |
5287ad62 JB |
16718 | default: |
16719 | bad_alignment: | |
477330fc RM |
16720 | first_error (_("bad alignment")); |
16721 | return; | |
5287ad62 JB |
16722 | } |
16723 | ||
16724 | inst.instruction |= alignbits << 4; | |
16725 | inst.instruction |= neon_logbits (et.size) << 6; | |
16726 | ||
16727 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
16728 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
16729 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
16730 | up the right value for "type" in a table based on this value and the given | |
16731 | list style, then stick it back. */ | |
16732 | idx = ((inst.operands[0].imm >> 4) & 7) | |
477330fc | 16733 | | (((inst.instruction >> 8) & 3) << 3); |
5287ad62 JB |
16734 | |
16735 | typebits = typetable[idx]; | |
5f4273c7 | 16736 | |
5287ad62 | 16737 | constraint (typebits == -1, _("bad list type for instruction")); |
1d50d57c WN |
16738 | constraint (((inst.instruction >> 8) & 3) && et.size == 64, |
16739 | _("bad element type for instruction")); | |
5287ad62 JB |
16740 | |
16741 | inst.instruction &= ~0xf00; | |
16742 | inst.instruction |= typebits << 8; | |
16743 | } | |
16744 | ||
16745 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
16746 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
16747 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
16748 | values, terminated with -1. */ | |
16749 | ||
16750 | static int | |
aa8a0863 | 16751 | neon_alignment_bit (int size, int align, int *do_alignment, ...) |
5287ad62 JB |
16752 | { |
16753 | va_list ap; | |
16754 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 16755 | |
5287ad62 JB |
16756 | if (!inst.operands[1].immisalign) |
16757 | { | |
aa8a0863 | 16758 | *do_alignment = 0; |
5287ad62 JB |
16759 | return SUCCESS; |
16760 | } | |
5f4273c7 | 16761 | |
aa8a0863 | 16762 | va_start (ap, do_alignment); |
5287ad62 JB |
16763 | |
16764 | do | |
16765 | { | |
16766 | thissize = va_arg (ap, int); | |
16767 | if (thissize == -1) | |
477330fc | 16768 | break; |
5287ad62 JB |
16769 | thisalign = va_arg (ap, int); |
16770 | ||
16771 | if (size == thissize && align == thisalign) | |
477330fc | 16772 | result = SUCCESS; |
5287ad62 JB |
16773 | } |
16774 | while (result != SUCCESS); | |
16775 | ||
16776 | va_end (ap); | |
16777 | ||
16778 | if (result == SUCCESS) | |
aa8a0863 | 16779 | *do_alignment = 1; |
5287ad62 | 16780 | else |
dcbf9037 | 16781 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 16782 | |
5287ad62 JB |
16783 | return result; |
16784 | } | |
16785 | ||
16786 | static void | |
16787 | do_neon_ld_st_lane (void) | |
16788 | { | |
037e8744 | 16789 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 16790 | int align_good, do_alignment = 0; |
5287ad62 JB |
16791 | int logsize = neon_logbits (et.size); |
16792 | int align = inst.operands[1].imm >> 8; | |
16793 | int n = (inst.instruction >> 8) & 3; | |
16794 | int max_el = 64 / et.size; | |
5f4273c7 | 16795 | |
dcbf9037 JB |
16796 | if (et.type == NT_invtype) |
16797 | return; | |
5f4273c7 | 16798 | |
5287ad62 | 16799 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
477330fc | 16800 | _("bad list length")); |
5287ad62 | 16801 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, |
477330fc | 16802 | _("scalar index out of range")); |
5287ad62 | 16803 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 |
477330fc RM |
16804 | && et.size == 8, |
16805 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 16806 | |
5287ad62 JB |
16807 | switch (n) |
16808 | { | |
16809 | case 0: /* VLD1 / VST1. */ | |
aa8a0863 | 16810 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16, |
477330fc | 16811 | 32, 32, -1); |
5287ad62 | 16812 | if (align_good == FAIL) |
477330fc | 16813 | return; |
aa8a0863 | 16814 | if (do_alignment) |
477330fc RM |
16815 | { |
16816 | unsigned alignbits = 0; | |
16817 | switch (et.size) | |
16818 | { | |
16819 | case 16: alignbits = 0x1; break; | |
16820 | case 32: alignbits = 0x3; break; | |
16821 | default: ; | |
16822 | } | |
16823 | inst.instruction |= alignbits << 4; | |
16824 | } | |
5287ad62 JB |
16825 | break; |
16826 | ||
16827 | case 1: /* VLD2 / VST2. */ | |
aa8a0863 TS |
16828 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16, |
16829 | 16, 32, 32, 64, -1); | |
5287ad62 | 16830 | if (align_good == FAIL) |
477330fc | 16831 | return; |
aa8a0863 | 16832 | if (do_alignment) |
477330fc | 16833 | inst.instruction |= 1 << 4; |
5287ad62 JB |
16834 | break; |
16835 | ||
16836 | case 2: /* VLD3 / VST3. */ | |
16837 | constraint (inst.operands[1].immisalign, | |
477330fc | 16838 | _("can't use alignment with this instruction")); |
5287ad62 JB |
16839 | break; |
16840 | ||
16841 | case 3: /* VLD4 / VST4. */ | |
aa8a0863 | 16842 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc | 16843 | 16, 64, 32, 64, 32, 128, -1); |
5287ad62 | 16844 | if (align_good == FAIL) |
477330fc | 16845 | return; |
aa8a0863 | 16846 | if (do_alignment) |
477330fc RM |
16847 | { |
16848 | unsigned alignbits = 0; | |
16849 | switch (et.size) | |
16850 | { | |
16851 | case 8: alignbits = 0x1; break; | |
16852 | case 16: alignbits = 0x1; break; | |
16853 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
16854 | default: ; | |
16855 | } | |
16856 | inst.instruction |= alignbits << 4; | |
16857 | } | |
5287ad62 JB |
16858 | break; |
16859 | ||
16860 | default: ; | |
16861 | } | |
16862 | ||
16863 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
16864 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
16865 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 16866 | |
5287ad62 JB |
16867 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
16868 | inst.instruction |= logsize << 10; | |
16869 | } | |
16870 | ||
16871 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
16872 | ||
16873 | static void | |
16874 | do_neon_ld_dup (void) | |
16875 | { | |
037e8744 | 16876 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
aa8a0863 | 16877 | int align_good, do_alignment = 0; |
5287ad62 | 16878 | |
dcbf9037 JB |
16879 | if (et.type == NT_invtype) |
16880 | return; | |
16881 | ||
5287ad62 JB |
16882 | switch ((inst.instruction >> 8) & 3) |
16883 | { | |
16884 | case 0: /* VLD1. */ | |
9c2799c2 | 16885 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 | 16886 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
aa8a0863 | 16887 | &do_alignment, 16, 16, 32, 32, -1); |
5287ad62 | 16888 | if (align_good == FAIL) |
477330fc | 16889 | return; |
5287ad62 | 16890 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) |
477330fc RM |
16891 | { |
16892 | case 1: break; | |
16893 | case 2: inst.instruction |= 1 << 5; break; | |
16894 | default: first_error (_("bad list length")); return; | |
16895 | } | |
5287ad62 JB |
16896 | inst.instruction |= neon_logbits (et.size) << 6; |
16897 | break; | |
16898 | ||
16899 | case 1: /* VLD2. */ | |
16900 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
aa8a0863 TS |
16901 | &do_alignment, 8, 16, 16, 32, 32, 64, |
16902 | -1); | |
5287ad62 | 16903 | if (align_good == FAIL) |
477330fc | 16904 | return; |
5287ad62 | 16905 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, |
477330fc | 16906 | _("bad list length")); |
5287ad62 | 16907 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 16908 | inst.instruction |= 1 << 5; |
5287ad62 JB |
16909 | inst.instruction |= neon_logbits (et.size) << 6; |
16910 | break; | |
16911 | ||
16912 | case 2: /* VLD3. */ | |
16913 | constraint (inst.operands[1].immisalign, | |
477330fc | 16914 | _("can't use alignment with this instruction")); |
5287ad62 | 16915 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, |
477330fc | 16916 | _("bad list length")); |
5287ad62 | 16917 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 16918 | inst.instruction |= 1 << 5; |
5287ad62 JB |
16919 | inst.instruction |= neon_logbits (et.size) << 6; |
16920 | break; | |
16921 | ||
16922 | case 3: /* VLD4. */ | |
16923 | { | |
477330fc | 16924 | int align = inst.operands[1].imm >> 8; |
aa8a0863 | 16925 | align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32, |
477330fc RM |
16926 | 16, 64, 32, 64, 32, 128, -1); |
16927 | if (align_good == FAIL) | |
16928 | return; | |
16929 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
16930 | _("bad list length")); | |
16931 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
16932 | inst.instruction |= 1 << 5; | |
16933 | if (et.size == 32 && align == 128) | |
16934 | inst.instruction |= 0x3 << 6; | |
16935 | else | |
16936 | inst.instruction |= neon_logbits (et.size) << 6; | |
5287ad62 JB |
16937 | } |
16938 | break; | |
16939 | ||
16940 | default: ; | |
16941 | } | |
16942 | ||
aa8a0863 | 16943 | inst.instruction |= do_alignment << 4; |
5287ad62 JB |
16944 | } |
16945 | ||
16946 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
16947 | apart from bits [11:4]. */ | |
16948 | ||
16949 | static void | |
16950 | do_neon_ldx_stx (void) | |
16951 | { | |
b1a769ed DG |
16952 | if (inst.operands[1].isreg) |
16953 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
16954 | ||
5287ad62 JB |
16955 | switch (NEON_LANE (inst.operands[0].imm)) |
16956 | { | |
16957 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 16958 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
16959 | do_neon_ld_st_interleave (); |
16960 | break; | |
5f4273c7 | 16961 | |
5287ad62 | 16962 | case NEON_ALL_LANES: |
88714cb8 | 16963 | NEON_ENCODE (DUP, inst); |
2d51fb74 JB |
16964 | if (inst.instruction == N_INV) |
16965 | { | |
16966 | first_error ("only loads support such operands"); | |
16967 | break; | |
16968 | } | |
5287ad62 JB |
16969 | do_neon_ld_dup (); |
16970 | break; | |
5f4273c7 | 16971 | |
5287ad62 | 16972 | default: |
88714cb8 | 16973 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
16974 | do_neon_ld_st_lane (); |
16975 | } | |
16976 | ||
16977 | /* L bit comes from bit mask. */ | |
16978 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16979 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16980 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 16981 | |
5287ad62 JB |
16982 | if (inst.operands[1].postind) |
16983 | { | |
16984 | int postreg = inst.operands[1].imm & 0xf; | |
16985 | constraint (!inst.operands[1].immisreg, | |
477330fc | 16986 | _("post-index must be a register")); |
5287ad62 | 16987 | constraint (postreg == 0xd || postreg == 0xf, |
477330fc | 16988 | _("bad register for post-index")); |
5287ad62 JB |
16989 | inst.instruction |= postreg; |
16990 | } | |
4f2374c7 | 16991 | else |
5287ad62 | 16992 | { |
4f2374c7 WN |
16993 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); |
16994 | constraint (inst.reloc.exp.X_op != O_constant | |
16995 | || inst.reloc.exp.X_add_number != 0, | |
16996 | BAD_ADDR_MODE); | |
16997 | ||
16998 | if (inst.operands[1].writeback) | |
16999 | { | |
17000 | inst.instruction |= 0xd; | |
17001 | } | |
17002 | else | |
17003 | inst.instruction |= 0xf; | |
5287ad62 | 17004 | } |
5f4273c7 | 17005 | |
5287ad62 JB |
17006 | if (thumb_mode) |
17007 | inst.instruction |= 0xf9000000; | |
17008 | else | |
17009 | inst.instruction |= 0xf4000000; | |
17010 | } | |
33399f07 MGD |
17011 | |
17012 | /* FP v8. */ | |
17013 | static void | |
17014 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
17015 | { | |
a715796b TG |
17016 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
17017 | D register operands. */ | |
17018 | if (neon_shape_class[rs] == SC_DOUBLE) | |
17019 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17020 | _(BAD_FPU)); | |
17021 | ||
33399f07 MGD |
17022 | NEON_ENCODE (FPV8, inst); |
17023 | ||
9db2f6b4 RL |
17024 | if (rs == NS_FFF || rs == NS_HHH) |
17025 | { | |
17026 | do_vfp_sp_dyadic (); | |
17027 | ||
17028 | /* ARMv8.2 fp16 instruction. */ | |
17029 | if (rs == NS_HHH) | |
17030 | do_scalar_fp16_v82_encode (); | |
17031 | } | |
33399f07 MGD |
17032 | else |
17033 | do_vfp_dp_rd_rn_rm (); | |
17034 | ||
17035 | if (rs == NS_DDD) | |
17036 | inst.instruction |= 0x100; | |
17037 | ||
17038 | inst.instruction |= 0xf0000000; | |
17039 | } | |
17040 | ||
17041 | static void | |
17042 | do_vsel (void) | |
17043 | { | |
17044 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17045 | ||
17046 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
17047 | first_error (_("invalid instruction shape")); | |
17048 | } | |
17049 | ||
73924fbc MGD |
17050 | static void |
17051 | do_vmaxnm (void) | |
17052 | { | |
17053 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17054 | ||
17055 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
17056 | return; | |
17057 | ||
17058 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
17059 | return; | |
17060 | ||
cc933301 | 17061 | neon_dyadic_misc (NT_untyped, N_F_16_32, 0); |
73924fbc MGD |
17062 | } |
17063 | ||
30bdf752 MGD |
17064 | static void |
17065 | do_vrint_1 (enum neon_cvt_mode mode) | |
17066 | { | |
9db2f6b4 | 17067 | enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL); |
30bdf752 MGD |
17068 | struct neon_type_el et; |
17069 | ||
17070 | if (rs == NS_NULL) | |
17071 | return; | |
17072 | ||
a715796b TG |
17073 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
17074 | D register operands. */ | |
17075 | if (neon_shape_class[rs] == SC_DOUBLE) | |
17076 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
17077 | _(BAD_FPU)); | |
17078 | ||
9db2f6b4 RL |
17079 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY |
17080 | | N_VFP); | |
30bdf752 MGD |
17081 | if (et.type != NT_invtype) |
17082 | { | |
17083 | /* VFP encodings. */ | |
17084 | if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n | |
17085 | || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m) | |
17086 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17087 | ||
17088 | NEON_ENCODE (FPV8, inst); | |
9db2f6b4 | 17089 | if (rs == NS_FF || rs == NS_HH) |
30bdf752 MGD |
17090 | do_vfp_sp_monadic (); |
17091 | else | |
17092 | do_vfp_dp_rd_rm (); | |
17093 | ||
17094 | switch (mode) | |
17095 | { | |
17096 | case neon_cvt_mode_r: inst.instruction |= 0x00000000; break; | |
17097 | case neon_cvt_mode_z: inst.instruction |= 0x00000080; break; | |
17098 | case neon_cvt_mode_x: inst.instruction |= 0x00010000; break; | |
17099 | case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break; | |
17100 | case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break; | |
17101 | case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break; | |
17102 | case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break; | |
17103 | default: abort (); | |
17104 | } | |
17105 | ||
17106 | inst.instruction |= (rs == NS_DD) << 8; | |
17107 | do_vfp_cond_or_thumb (); | |
9db2f6b4 RL |
17108 | |
17109 | /* ARMv8.2 fp16 vrint instruction. */ | |
17110 | if (rs == NS_HH) | |
17111 | do_scalar_fp16_v82_encode (); | |
30bdf752 MGD |
17112 | } |
17113 | else | |
17114 | { | |
17115 | /* Neon encodings (or something broken...). */ | |
17116 | inst.error = NULL; | |
cc933301 | 17117 | et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY); |
30bdf752 MGD |
17118 | |
17119 | if (et.type == NT_invtype) | |
17120 | return; | |
17121 | ||
17122 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17123 | NEON_ENCODE (FLOAT, inst); | |
17124 | ||
17125 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
17126 | return; | |
17127 | ||
17128 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17129 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17130 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
17131 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
17132 | inst.instruction |= neon_quad (rs) << 6; | |
cc933301 JW |
17133 | /* Mask off the original size bits and reencode them. */ |
17134 | inst.instruction = ((inst.instruction & 0xfff3ffff) | |
17135 | | neon_logbits (et.size) << 18); | |
17136 | ||
30bdf752 MGD |
17137 | switch (mode) |
17138 | { | |
17139 | case neon_cvt_mode_z: inst.instruction |= 3 << 7; break; | |
17140 | case neon_cvt_mode_x: inst.instruction |= 1 << 7; break; | |
17141 | case neon_cvt_mode_a: inst.instruction |= 2 << 7; break; | |
17142 | case neon_cvt_mode_n: inst.instruction |= 0 << 7; break; | |
17143 | case neon_cvt_mode_p: inst.instruction |= 7 << 7; break; | |
17144 | case neon_cvt_mode_m: inst.instruction |= 5 << 7; break; | |
17145 | case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break; | |
17146 | default: abort (); | |
17147 | } | |
17148 | ||
17149 | if (thumb_mode) | |
17150 | inst.instruction |= 0xfc000000; | |
17151 | else | |
17152 | inst.instruction |= 0xf0000000; | |
17153 | } | |
17154 | } | |
17155 | ||
17156 | static void | |
17157 | do_vrintx (void) | |
17158 | { | |
17159 | do_vrint_1 (neon_cvt_mode_x); | |
17160 | } | |
17161 | ||
17162 | static void | |
17163 | do_vrintz (void) | |
17164 | { | |
17165 | do_vrint_1 (neon_cvt_mode_z); | |
17166 | } | |
17167 | ||
17168 | static void | |
17169 | do_vrintr (void) | |
17170 | { | |
17171 | do_vrint_1 (neon_cvt_mode_r); | |
17172 | } | |
17173 | ||
17174 | static void | |
17175 | do_vrinta (void) | |
17176 | { | |
17177 | do_vrint_1 (neon_cvt_mode_a); | |
17178 | } | |
17179 | ||
17180 | static void | |
17181 | do_vrintn (void) | |
17182 | { | |
17183 | do_vrint_1 (neon_cvt_mode_n); | |
17184 | } | |
17185 | ||
17186 | static void | |
17187 | do_vrintp (void) | |
17188 | { | |
17189 | do_vrint_1 (neon_cvt_mode_p); | |
17190 | } | |
17191 | ||
17192 | static void | |
17193 | do_vrintm (void) | |
17194 | { | |
17195 | do_vrint_1 (neon_cvt_mode_m); | |
17196 | } | |
17197 | ||
91ff7894 MGD |
17198 | /* Crypto v1 instructions. */ |
17199 | static void | |
17200 | do_crypto_2op_1 (unsigned elttype, int op) | |
17201 | { | |
17202 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17203 | ||
17204 | if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type | |
17205 | == NT_invtype) | |
17206 | return; | |
17207 | ||
17208 | inst.error = NULL; | |
17209 | ||
17210 | NEON_ENCODE (INTEGER, inst); | |
17211 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
17212 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
17213 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
17214 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
17215 | if (op != -1) | |
17216 | inst.instruction |= op << 6; | |
17217 | ||
17218 | if (thumb_mode) | |
17219 | inst.instruction |= 0xfc000000; | |
17220 | else | |
17221 | inst.instruction |= 0xf0000000; | |
17222 | } | |
17223 | ||
48adcd8e MGD |
17224 | static void |
17225 | do_crypto_3op_1 (int u, int op) | |
17226 | { | |
17227 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17228 | ||
17229 | if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT, | |
17230 | N_32 | N_UNT | N_KEY).type == NT_invtype) | |
17231 | return; | |
17232 | ||
17233 | inst.error = NULL; | |
17234 | ||
17235 | NEON_ENCODE (INTEGER, inst); | |
17236 | neon_three_same (1, u, 8 << op); | |
17237 | } | |
17238 | ||
91ff7894 MGD |
17239 | static void |
17240 | do_aese (void) | |
17241 | { | |
17242 | do_crypto_2op_1 (N_8, 0); | |
17243 | } | |
17244 | ||
17245 | static void | |
17246 | do_aesd (void) | |
17247 | { | |
17248 | do_crypto_2op_1 (N_8, 1); | |
17249 | } | |
17250 | ||
17251 | static void | |
17252 | do_aesmc (void) | |
17253 | { | |
17254 | do_crypto_2op_1 (N_8, 2); | |
17255 | } | |
17256 | ||
17257 | static void | |
17258 | do_aesimc (void) | |
17259 | { | |
17260 | do_crypto_2op_1 (N_8, 3); | |
17261 | } | |
17262 | ||
48adcd8e MGD |
17263 | static void |
17264 | do_sha1c (void) | |
17265 | { | |
17266 | do_crypto_3op_1 (0, 0); | |
17267 | } | |
17268 | ||
17269 | static void | |
17270 | do_sha1p (void) | |
17271 | { | |
17272 | do_crypto_3op_1 (0, 1); | |
17273 | } | |
17274 | ||
17275 | static void | |
17276 | do_sha1m (void) | |
17277 | { | |
17278 | do_crypto_3op_1 (0, 2); | |
17279 | } | |
17280 | ||
17281 | static void | |
17282 | do_sha1su0 (void) | |
17283 | { | |
17284 | do_crypto_3op_1 (0, 3); | |
17285 | } | |
91ff7894 | 17286 | |
48adcd8e MGD |
17287 | static void |
17288 | do_sha256h (void) | |
17289 | { | |
17290 | do_crypto_3op_1 (1, 0); | |
17291 | } | |
17292 | ||
17293 | static void | |
17294 | do_sha256h2 (void) | |
17295 | { | |
17296 | do_crypto_3op_1 (1, 1); | |
17297 | } | |
17298 | ||
17299 | static void | |
17300 | do_sha256su1 (void) | |
17301 | { | |
17302 | do_crypto_3op_1 (1, 2); | |
17303 | } | |
3c9017d2 MGD |
17304 | |
17305 | static void | |
17306 | do_sha1h (void) | |
17307 | { | |
17308 | do_crypto_2op_1 (N_32, -1); | |
17309 | } | |
17310 | ||
17311 | static void | |
17312 | do_sha1su1 (void) | |
17313 | { | |
17314 | do_crypto_2op_1 (N_32, 0); | |
17315 | } | |
17316 | ||
17317 | static void | |
17318 | do_sha256su0 (void) | |
17319 | { | |
17320 | do_crypto_2op_1 (N_32, 1); | |
17321 | } | |
dd5181d5 KT |
17322 | |
17323 | static void | |
17324 | do_crc32_1 (unsigned int poly, unsigned int sz) | |
17325 | { | |
17326 | unsigned int Rd = inst.operands[0].reg; | |
17327 | unsigned int Rn = inst.operands[1].reg; | |
17328 | unsigned int Rm = inst.operands[2].reg; | |
17329 | ||
17330 | set_it_insn_type (OUTSIDE_IT_INSN); | |
17331 | inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12); | |
17332 | inst.instruction |= LOW4 (Rn) << 16; | |
17333 | inst.instruction |= LOW4 (Rm); | |
17334 | inst.instruction |= sz << (thumb_mode ? 4 : 21); | |
17335 | inst.instruction |= poly << (thumb_mode ? 20 : 9); | |
17336 | ||
17337 | if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC) | |
17338 | as_warn (UNPRED_REG ("r15")); | |
17339 | if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP)) | |
17340 | as_warn (UNPRED_REG ("r13")); | |
17341 | } | |
17342 | ||
17343 | static void | |
17344 | do_crc32b (void) | |
17345 | { | |
17346 | do_crc32_1 (0, 0); | |
17347 | } | |
17348 | ||
17349 | static void | |
17350 | do_crc32h (void) | |
17351 | { | |
17352 | do_crc32_1 (0, 1); | |
17353 | } | |
17354 | ||
17355 | static void | |
17356 | do_crc32w (void) | |
17357 | { | |
17358 | do_crc32_1 (0, 2); | |
17359 | } | |
17360 | ||
17361 | static void | |
17362 | do_crc32cb (void) | |
17363 | { | |
17364 | do_crc32_1 (1, 0); | |
17365 | } | |
17366 | ||
17367 | static void | |
17368 | do_crc32ch (void) | |
17369 | { | |
17370 | do_crc32_1 (1, 1); | |
17371 | } | |
17372 | ||
17373 | static void | |
17374 | do_crc32cw (void) | |
17375 | { | |
17376 | do_crc32_1 (1, 2); | |
17377 | } | |
17378 | ||
5287ad62 JB |
17379 | \f |
17380 | /* Overall per-instruction processing. */ | |
17381 | ||
17382 | /* We need to be able to fix up arbitrary expressions in some statements. | |
17383 | This is so that we can handle symbols that are an arbitrary distance from | |
17384 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
17385 | which returns part of an address in a form which will be valid for | |
17386 | a data instruction. We do this by pushing the expression into a symbol | |
17387 | in the expr_section, and creating a fix for that. */ | |
17388 | ||
17389 | static void | |
17390 | fix_new_arm (fragS * frag, | |
17391 | int where, | |
17392 | short int size, | |
17393 | expressionS * exp, | |
17394 | int pc_rel, | |
17395 | int reloc) | |
17396 | { | |
17397 | fixS * new_fix; | |
17398 | ||
17399 | switch (exp->X_op) | |
17400 | { | |
17401 | case O_constant: | |
6e7ce2cd PB |
17402 | if (pc_rel) |
17403 | { | |
17404 | /* Create an absolute valued symbol, so we have something to | |
477330fc RM |
17405 | refer to in the object file. Unfortunately for us, gas's |
17406 | generic expression parsing will already have folded out | |
17407 | any use of .set foo/.type foo %function that may have | |
17408 | been used to set type information of the target location, | |
17409 | that's being specified symbolically. We have to presume | |
17410 | the user knows what they are doing. */ | |
6e7ce2cd PB |
17411 | char name[16 + 8]; |
17412 | symbolS *symbol; | |
17413 | ||
17414 | sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number); | |
17415 | ||
17416 | symbol = symbol_find_or_make (name); | |
17417 | S_SET_SEGMENT (symbol, absolute_section); | |
17418 | symbol_set_frag (symbol, &zero_address_frag); | |
17419 | S_SET_VALUE (symbol, exp->X_add_number); | |
17420 | exp->X_op = O_symbol; | |
17421 | exp->X_add_symbol = symbol; | |
17422 | exp->X_add_number = 0; | |
17423 | } | |
17424 | /* FALLTHROUGH */ | |
5287ad62 JB |
17425 | case O_symbol: |
17426 | case O_add: | |
17427 | case O_subtract: | |
21d799b5 | 17428 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
477330fc | 17429 | (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
17430 | break; |
17431 | ||
17432 | default: | |
21d799b5 | 17433 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
477330fc | 17434 | pc_rel, (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
17435 | break; |
17436 | } | |
17437 | ||
17438 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
17439 | instruction. */ | |
17440 | new_fix->tc_fix_data = thumb_mode; | |
17441 | } | |
17442 | ||
17443 | /* Create a frg for an instruction requiring relaxation. */ | |
17444 | static void | |
17445 | output_relax_insn (void) | |
17446 | { | |
17447 | char * to; | |
17448 | symbolS *sym; | |
0110f2b8 PB |
17449 | int offset; |
17450 | ||
6e1cb1a6 PB |
17451 | /* The size of the instruction is unknown, so tie the debug info to the |
17452 | start of the instruction. */ | |
17453 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 17454 | |
0110f2b8 PB |
17455 | switch (inst.reloc.exp.X_op) |
17456 | { | |
17457 | case O_symbol: | |
17458 | sym = inst.reloc.exp.X_add_symbol; | |
17459 | offset = inst.reloc.exp.X_add_number; | |
17460 | break; | |
17461 | case O_constant: | |
17462 | sym = NULL; | |
17463 | offset = inst.reloc.exp.X_add_number; | |
17464 | break; | |
17465 | default: | |
17466 | sym = make_expr_symbol (&inst.reloc.exp); | |
17467 | offset = 0; | |
17468 | break; | |
17469 | } | |
17470 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
17471 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
17472 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
17473 | } |
17474 | ||
17475 | /* Write a 32-bit thumb instruction to buf. */ | |
17476 | static void | |
17477 | put_thumb32_insn (char * buf, unsigned long insn) | |
17478 | { | |
17479 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
17480 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
17481 | } | |
17482 | ||
b99bd4ef | 17483 | static void |
c19d1205 | 17484 | output_inst (const char * str) |
b99bd4ef | 17485 | { |
c19d1205 | 17486 | char * to = NULL; |
b99bd4ef | 17487 | |
c19d1205 | 17488 | if (inst.error) |
b99bd4ef | 17489 | { |
c19d1205 | 17490 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
17491 | return; |
17492 | } | |
5f4273c7 NC |
17493 | if (inst.relax) |
17494 | { | |
17495 | output_relax_insn (); | |
0110f2b8 | 17496 | return; |
5f4273c7 | 17497 | } |
c19d1205 ZW |
17498 | if (inst.size == 0) |
17499 | return; | |
b99bd4ef | 17500 | |
c19d1205 | 17501 | to = frag_more (inst.size); |
8dc2430f NC |
17502 | /* PR 9814: Record the thumb mode into the current frag so that we know |
17503 | what type of NOP padding to use, if necessary. We override any previous | |
17504 | setting so that if the mode has changed then the NOPS that we use will | |
17505 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 17506 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
17507 | |
17508 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 17509 | { |
9c2799c2 | 17510 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 17511 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 17512 | } |
c19d1205 | 17513 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 17514 | { |
9c2799c2 | 17515 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
17516 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
17517 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 17518 | } |
c19d1205 ZW |
17519 | else |
17520 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 17521 | |
c19d1205 ZW |
17522 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
17523 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
17524 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
17525 | inst.reloc.type); | |
b99bd4ef | 17526 | |
c19d1205 | 17527 | dwarf2_emit_insn (inst.size); |
c19d1205 | 17528 | } |
b99bd4ef | 17529 | |
e07e6e58 NC |
17530 | static char * |
17531 | output_it_inst (int cond, int mask, char * to) | |
17532 | { | |
17533 | unsigned long instruction = 0xbf00; | |
17534 | ||
17535 | mask &= 0xf; | |
17536 | instruction |= mask; | |
17537 | instruction |= cond << 4; | |
17538 | ||
17539 | if (to == NULL) | |
17540 | { | |
17541 | to = frag_more (2); | |
17542 | #ifdef OBJ_ELF | |
17543 | dwarf2_emit_insn (2); | |
17544 | #endif | |
17545 | } | |
17546 | ||
17547 | md_number_to_chars (to, instruction, 2); | |
17548 | ||
17549 | return to; | |
17550 | } | |
17551 | ||
c19d1205 ZW |
17552 | /* Tag values used in struct asm_opcode's tag field. */ |
17553 | enum opcode_tag | |
17554 | { | |
17555 | OT_unconditional, /* Instruction cannot be conditionalized. | |
17556 | The ARM condition field is still 0xE. */ | |
17557 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
17558 | and carries 0xF in its ARM condition field. */ | |
17559 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 | 17560 | OT_csuffixF, /* Some forms of the instruction take a conditional |
477330fc RM |
17561 | suffix, others place 0xF where the condition field |
17562 | would be. */ | |
c19d1205 ZW |
17563 | OT_cinfix3, /* Instruction takes a conditional infix, |
17564 | beginning at character index 3. (In | |
17565 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
17566 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
17567 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
17568 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
17569 | character index 3, even in unified mode. Used for | |
17570 | legacy instructions where suffix and infix forms | |
17571 | may be ambiguous. */ | |
c19d1205 | 17572 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 17573 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
17574 | OT_odd_infix_unc, /* This is the unconditional variant of an |
17575 | instruction that takes a conditional infix | |
17576 | at an unusual position. In unified mode, | |
17577 | this variant will accept a suffix. */ | |
17578 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
17579 | are the conditional variants of instructions that | |
17580 | take conditional infixes in unusual positions. | |
17581 | The infix appears at character index | |
17582 | (tag - OT_odd_infix_0). These are not accepted | |
17583 | in unified mode. */ | |
17584 | }; | |
b99bd4ef | 17585 | |
c19d1205 ZW |
17586 | /* Subroutine of md_assemble, responsible for looking up the primary |
17587 | opcode from the mnemonic the user wrote. STR points to the | |
17588 | beginning of the mnemonic. | |
17589 | ||
17590 | This is not simply a hash table lookup, because of conditional | |
17591 | variants. Most instructions have conditional variants, which are | |
17592 | expressed with a _conditional affix_ to the mnemonic. If we were | |
17593 | to encode each conditional variant as a literal string in the opcode | |
17594 | table, it would have approximately 20,000 entries. | |
17595 | ||
17596 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
17597 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
17598 | instructions take the affix as an infix, notably the s-variants of | |
17599 | the arithmetic instructions. Of those instructions, all but six | |
17600 | have the infix appear after the third character of the mnemonic. | |
17601 | ||
17602 | Accordingly, the algorithm for looking up primary opcodes given | |
17603 | an identifier is: | |
17604 | ||
17605 | 1. Look up the identifier in the opcode table. | |
17606 | If we find a match, go to step U. | |
17607 | ||
17608 | 2. Look up the last two characters of the identifier in the | |
17609 | conditions table. If we find a match, look up the first N-2 | |
17610 | characters of the identifier in the opcode table. If we | |
17611 | find a match, go to step CE. | |
17612 | ||
17613 | 3. Look up the fourth and fifth characters of the identifier in | |
17614 | the conditions table. If we find a match, extract those | |
17615 | characters from the identifier, and look up the remaining | |
17616 | characters in the opcode table. If we find a match, go | |
17617 | to step CM. | |
17618 | ||
17619 | 4. Fail. | |
17620 | ||
17621 | U. Examine the tag field of the opcode structure, in case this is | |
17622 | one of the six instructions with its conditional infix in an | |
17623 | unusual place. If it is, the tag tells us where to find the | |
17624 | infix; look it up in the conditions table and set inst.cond | |
17625 | accordingly. Otherwise, this is an unconditional instruction. | |
17626 | Again set inst.cond accordingly. Return the opcode structure. | |
17627 | ||
17628 | CE. Examine the tag field to make sure this is an instruction that | |
17629 | should receive a conditional suffix. If it is not, fail. | |
17630 | Otherwise, set inst.cond from the suffix we already looked up, | |
17631 | and return the opcode structure. | |
17632 | ||
17633 | CM. Examine the tag field to make sure this is an instruction that | |
17634 | should receive a conditional infix after the third character. | |
17635 | If it is not, fail. Otherwise, undo the edits to the current | |
17636 | line of input and proceed as for case CE. */ | |
17637 | ||
17638 | static const struct asm_opcode * | |
17639 | opcode_lookup (char **str) | |
17640 | { | |
17641 | char *end, *base; | |
17642 | char *affix; | |
17643 | const struct asm_opcode *opcode; | |
17644 | const struct asm_cond *cond; | |
e3cb604e | 17645 | char save[2]; |
c19d1205 ZW |
17646 | |
17647 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 17648 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 17649 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 17650 | if (*end == ' ' || *end == '.') |
c19d1205 | 17651 | break; |
b99bd4ef | 17652 | |
c19d1205 | 17653 | if (end == base) |
c921be7d | 17654 | return NULL; |
b99bd4ef | 17655 | |
5287ad62 | 17656 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 17657 | if (end[0] == '.') |
b99bd4ef | 17658 | { |
5287ad62 | 17659 | int offset = 2; |
5f4273c7 | 17660 | |
267d2029 | 17661 | /* The .w and .n suffixes are only valid if the unified syntax is in |
477330fc | 17662 | use. */ |
267d2029 | 17663 | if (unified_syntax && end[1] == 'w') |
c19d1205 | 17664 | inst.size_req = 4; |
267d2029 | 17665 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
17666 | inst.size_req = 2; |
17667 | else | |
477330fc | 17668 | offset = 0; |
5287ad62 JB |
17669 | |
17670 | inst.vectype.elems = 0; | |
17671 | ||
17672 | *str = end + offset; | |
b99bd4ef | 17673 | |
5f4273c7 | 17674 | if (end[offset] == '.') |
5287ad62 | 17675 | { |
267d2029 | 17676 | /* See if we have a Neon type suffix (possible in either unified or |
477330fc RM |
17677 | non-unified ARM syntax mode). */ |
17678 | if (parse_neon_type (&inst.vectype, str) == FAIL) | |
c921be7d | 17679 | return NULL; |
477330fc | 17680 | } |
5287ad62 | 17681 | else if (end[offset] != '\0' && end[offset] != ' ') |
477330fc | 17682 | return NULL; |
b99bd4ef | 17683 | } |
c19d1205 ZW |
17684 | else |
17685 | *str = end; | |
b99bd4ef | 17686 | |
c19d1205 | 17687 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 | 17688 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 17689 | end - base); |
c19d1205 | 17690 | if (opcode) |
b99bd4ef | 17691 | { |
c19d1205 ZW |
17692 | /* step U */ |
17693 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 17694 | { |
c19d1205 ZW |
17695 | inst.cond = COND_ALWAYS; |
17696 | return opcode; | |
b99bd4ef | 17697 | } |
b99bd4ef | 17698 | |
278df34e | 17699 | if (warn_on_deprecated && unified_syntax) |
5c3696f8 | 17700 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 | 17701 | affix = base + (opcode->tag - OT_odd_infix_0); |
21d799b5 | 17702 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 17703 | gas_assert (cond); |
b99bd4ef | 17704 | |
c19d1205 ZW |
17705 | inst.cond = cond->value; |
17706 | return opcode; | |
17707 | } | |
b99bd4ef | 17708 | |
c19d1205 ZW |
17709 | /* Cannot have a conditional suffix on a mnemonic of less than two |
17710 | characters. */ | |
17711 | if (end - base < 3) | |
c921be7d | 17712 | return NULL; |
b99bd4ef | 17713 | |
c19d1205 ZW |
17714 | /* Look for suffixed mnemonic. */ |
17715 | affix = end - 2; | |
21d799b5 NC |
17716 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
17717 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
477330fc | 17718 | affix - base); |
c19d1205 ZW |
17719 | if (opcode && cond) |
17720 | { | |
17721 | /* step CE */ | |
17722 | switch (opcode->tag) | |
17723 | { | |
e3cb604e PB |
17724 | case OT_cinfix3_legacy: |
17725 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
17726 | break; | |
17727 | ||
c19d1205 | 17728 | case OT_cinfix3: |
088fa78e | 17729 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
17730 | case OT_odd_infix_unc: |
17731 | if (!unified_syntax) | |
e3cb604e | 17732 | return 0; |
c19d1205 ZW |
17733 | /* else fall through */ |
17734 | ||
17735 | case OT_csuffix: | |
477330fc | 17736 | case OT_csuffixF: |
c19d1205 ZW |
17737 | case OT_csuf_or_in3: |
17738 | inst.cond = cond->value; | |
17739 | return opcode; | |
17740 | ||
17741 | case OT_unconditional: | |
17742 | case OT_unconditionalF: | |
dfa9f0d5 | 17743 | if (thumb_mode) |
c921be7d | 17744 | inst.cond = cond->value; |
dfa9f0d5 PB |
17745 | else |
17746 | { | |
c921be7d | 17747 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
17748 | inst.error = BAD_COND; |
17749 | inst.cond = COND_ALWAYS; | |
17750 | } | |
c19d1205 | 17751 | return opcode; |
b99bd4ef | 17752 | |
c19d1205 | 17753 | default: |
c921be7d | 17754 | return NULL; |
c19d1205 ZW |
17755 | } |
17756 | } | |
b99bd4ef | 17757 | |
c19d1205 ZW |
17758 | /* Cannot have a usual-position infix on a mnemonic of less than |
17759 | six characters (five would be a suffix). */ | |
17760 | if (end - base < 6) | |
c921be7d | 17761 | return NULL; |
b99bd4ef | 17762 | |
c19d1205 ZW |
17763 | /* Look for infixed mnemonic in the usual position. */ |
17764 | affix = base + 3; | |
21d799b5 | 17765 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 17766 | if (!cond) |
c921be7d | 17767 | return NULL; |
e3cb604e PB |
17768 | |
17769 | memcpy (save, affix, 2); | |
17770 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 | 17771 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 17772 | (end - base) - 2); |
e3cb604e PB |
17773 | memmove (affix + 2, affix, (end - affix) - 2); |
17774 | memcpy (affix, save, 2); | |
17775 | ||
088fa78e KH |
17776 | if (opcode |
17777 | && (opcode->tag == OT_cinfix3 | |
17778 | || opcode->tag == OT_cinfix3_deprecated | |
17779 | || opcode->tag == OT_csuf_or_in3 | |
17780 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 17781 | { |
c921be7d | 17782 | /* Step CM. */ |
278df34e | 17783 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
17784 | && (opcode->tag == OT_cinfix3 |
17785 | || opcode->tag == OT_cinfix3_deprecated)) | |
5c3696f8 | 17786 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 ZW |
17787 | |
17788 | inst.cond = cond->value; | |
17789 | return opcode; | |
b99bd4ef NC |
17790 | } |
17791 | ||
c921be7d | 17792 | return NULL; |
b99bd4ef NC |
17793 | } |
17794 | ||
e07e6e58 NC |
17795 | /* This function generates an initial IT instruction, leaving its block |
17796 | virtually open for the new instructions. Eventually, | |
17797 | the mask will be updated by now_it_add_mask () each time | |
17798 | a new instruction needs to be included in the IT block. | |
17799 | Finally, the block is closed with close_automatic_it_block (). | |
17800 | The block closure can be requested either from md_assemble (), | |
17801 | a tencode (), or due to a label hook. */ | |
17802 | ||
17803 | static void | |
17804 | new_automatic_it_block (int cond) | |
17805 | { | |
17806 | now_it.state = AUTOMATIC_IT_BLOCK; | |
17807 | now_it.mask = 0x18; | |
17808 | now_it.cc = cond; | |
17809 | now_it.block_length = 1; | |
cd000bff | 17810 | mapping_state (MAP_THUMB); |
e07e6e58 | 17811 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
5a01bb1d MGD |
17812 | now_it.warn_deprecated = FALSE; |
17813 | now_it.insn_cond = TRUE; | |
e07e6e58 NC |
17814 | } |
17815 | ||
17816 | /* Close an automatic IT block. | |
17817 | See comments in new_automatic_it_block (). */ | |
17818 | ||
17819 | static void | |
17820 | close_automatic_it_block (void) | |
17821 | { | |
17822 | now_it.mask = 0x10; | |
17823 | now_it.block_length = 0; | |
17824 | } | |
17825 | ||
17826 | /* Update the mask of the current automatically-generated IT | |
17827 | instruction. See comments in new_automatic_it_block (). */ | |
17828 | ||
17829 | static void | |
17830 | now_it_add_mask (int cond) | |
17831 | { | |
17832 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
17833 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
477330fc | 17834 | | ((bitvalue) << (nbit))) |
e07e6e58 | 17835 | const int resulting_bit = (cond & 1); |
c921be7d | 17836 | |
e07e6e58 NC |
17837 | now_it.mask &= 0xf; |
17838 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
477330fc RM |
17839 | resulting_bit, |
17840 | (5 - now_it.block_length)); | |
e07e6e58 | 17841 | now_it.mask = SET_BIT_VALUE (now_it.mask, |
477330fc RM |
17842 | 1, |
17843 | ((5 - now_it.block_length) - 1) ); | |
e07e6e58 NC |
17844 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); |
17845 | ||
17846 | #undef CLEAR_BIT | |
17847 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
17848 | } |
17849 | ||
17850 | /* The IT blocks handling machinery is accessed through the these functions: | |
17851 | it_fsm_pre_encode () from md_assemble () | |
17852 | set_it_insn_type () optional, from the tencode functions | |
17853 | set_it_insn_type_last () ditto | |
17854 | in_it_block () ditto | |
17855 | it_fsm_post_encode () from md_assemble () | |
17856 | force_automatic_it_block_close () from label habdling functions | |
17857 | ||
17858 | Rationale: | |
17859 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
477330fc RM |
17860 | initializing the IT insn type with a generic initial value depending |
17861 | on the inst.condition. | |
e07e6e58 | 17862 | 2) During the tencode function, two things may happen: |
477330fc RM |
17863 | a) The tencode function overrides the IT insn type by |
17864 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
17865 | b) The tencode function queries the IT block state by | |
17866 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
17867 | ||
17868 | Both set_it_insn_type and in_it_block run the internal FSM state | |
17869 | handling function (handle_it_state), because: a) setting the IT insn | |
17870 | type may incur in an invalid state (exiting the function), | |
17871 | and b) querying the state requires the FSM to be updated. | |
17872 | Specifically we want to avoid creating an IT block for conditional | |
17873 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
17874 | determine whether an IT block is required until the tencode () routine | |
17875 | has decided what type of instruction this actually it. | |
17876 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
17877 | set_it_insn_type has to be called first. | |
17878 | ||
17879 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
17880 | determines the insn IT type depending on the inst.cond code. | |
17881 | When a tencode () routine encodes an instruction that can be | |
17882 | either outside an IT block, or, in the case of being inside, has to be | |
17883 | the last one, set_it_insn_type_last () will determine the proper | |
17884 | IT instruction type based on the inst.cond code. Otherwise, | |
17885 | set_it_insn_type can be called for overriding that logic or | |
17886 | for covering other cases. | |
17887 | ||
17888 | Calling handle_it_state () may not transition the IT block state to | |
17889 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
17890 | still queried. Instead, if the FSM determines that the state should | |
17891 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
17892 | after the tencode () function: that's what it_fsm_post_encode () does. | |
17893 | ||
17894 | Since in_it_block () calls the state handling function to get an | |
17895 | updated state, an error may occur (due to invalid insns combination). | |
17896 | In that case, inst.error is set. | |
17897 | Therefore, inst.error has to be checked after the execution of | |
17898 | the tencode () routine. | |
e07e6e58 NC |
17899 | |
17900 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
477330fc RM |
17901 | any pending state change (if any) that didn't take place in |
17902 | handle_it_state () as explained above. */ | |
e07e6e58 NC |
17903 | |
17904 | static void | |
17905 | it_fsm_pre_encode (void) | |
17906 | { | |
17907 | if (inst.cond != COND_ALWAYS) | |
17908 | inst.it_insn_type = INSIDE_IT_INSN; | |
17909 | else | |
17910 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
17911 | ||
17912 | now_it.state_handled = 0; | |
17913 | } | |
17914 | ||
17915 | /* IT state FSM handling function. */ | |
17916 | ||
17917 | static int | |
17918 | handle_it_state (void) | |
17919 | { | |
17920 | now_it.state_handled = 1; | |
5a01bb1d | 17921 | now_it.insn_cond = FALSE; |
e07e6e58 NC |
17922 | |
17923 | switch (now_it.state) | |
17924 | { | |
17925 | case OUTSIDE_IT_BLOCK: | |
17926 | switch (inst.it_insn_type) | |
17927 | { | |
17928 | case OUTSIDE_IT_INSN: | |
17929 | break; | |
17930 | ||
17931 | case INSIDE_IT_INSN: | |
17932 | case INSIDE_IT_LAST_INSN: | |
17933 | if (thumb_mode == 0) | |
17934 | { | |
c921be7d | 17935 | if (unified_syntax |
e07e6e58 NC |
17936 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
17937 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
17938 | " for Thumb.")); | |
17939 | } | |
17940 | else | |
17941 | { | |
17942 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
fc289b0a | 17943 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) |
e07e6e58 NC |
17944 | { |
17945 | /* Automatically generate the IT instruction. */ | |
17946 | new_automatic_it_block (inst.cond); | |
17947 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
17948 | close_automatic_it_block (); | |
17949 | } | |
17950 | else | |
17951 | { | |
17952 | inst.error = BAD_OUT_IT; | |
17953 | return FAIL; | |
17954 | } | |
17955 | } | |
17956 | break; | |
17957 | ||
17958 | case IF_INSIDE_IT_LAST_INSN: | |
17959 | case NEUTRAL_IT_INSN: | |
17960 | break; | |
17961 | ||
17962 | case IT_INSN: | |
17963 | now_it.state = MANUAL_IT_BLOCK; | |
17964 | now_it.block_length = 0; | |
17965 | break; | |
17966 | } | |
17967 | break; | |
17968 | ||
17969 | case AUTOMATIC_IT_BLOCK: | |
17970 | /* Three things may happen now: | |
17971 | a) We should increment current it block size; | |
17972 | b) We should close current it block (closing insn or 4 insns); | |
17973 | c) We should close current it block and start a new one (due | |
17974 | to incompatible conditions or | |
17975 | 4 insns-length block reached). */ | |
17976 | ||
17977 | switch (inst.it_insn_type) | |
17978 | { | |
17979 | case OUTSIDE_IT_INSN: | |
17980 | /* The closure of the block shall happen immediatelly, | |
17981 | so any in_it_block () call reports the block as closed. */ | |
17982 | force_automatic_it_block_close (); | |
17983 | break; | |
17984 | ||
17985 | case INSIDE_IT_INSN: | |
17986 | case INSIDE_IT_LAST_INSN: | |
17987 | case IF_INSIDE_IT_LAST_INSN: | |
17988 | now_it.block_length++; | |
17989 | ||
17990 | if (now_it.block_length > 4 | |
17991 | || !now_it_compatible (inst.cond)) | |
17992 | { | |
17993 | force_automatic_it_block_close (); | |
17994 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
17995 | new_automatic_it_block (inst.cond); | |
17996 | } | |
17997 | else | |
17998 | { | |
5a01bb1d | 17999 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18000 | now_it_add_mask (inst.cond); |
18001 | } | |
18002 | ||
18003 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
18004 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
18005 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
18006 | close_automatic_it_block (); | |
18007 | break; | |
18008 | ||
18009 | case NEUTRAL_IT_INSN: | |
18010 | now_it.block_length++; | |
5a01bb1d | 18011 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18012 | |
18013 | if (now_it.block_length > 4) | |
18014 | force_automatic_it_block_close (); | |
18015 | else | |
18016 | now_it_add_mask (now_it.cc & 1); | |
18017 | break; | |
18018 | ||
18019 | case IT_INSN: | |
18020 | close_automatic_it_block (); | |
18021 | now_it.state = MANUAL_IT_BLOCK; | |
18022 | break; | |
18023 | } | |
18024 | break; | |
18025 | ||
18026 | case MANUAL_IT_BLOCK: | |
18027 | { | |
18028 | /* Check conditional suffixes. */ | |
18029 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
18030 | int is_last; | |
18031 | now_it.mask <<= 1; | |
18032 | now_it.mask &= 0x1f; | |
18033 | is_last = (now_it.mask == 0x10); | |
5a01bb1d | 18034 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
18035 | |
18036 | switch (inst.it_insn_type) | |
18037 | { | |
18038 | case OUTSIDE_IT_INSN: | |
18039 | inst.error = BAD_NOT_IT; | |
18040 | return FAIL; | |
18041 | ||
18042 | case INSIDE_IT_INSN: | |
18043 | if (cond != inst.cond) | |
18044 | { | |
18045 | inst.error = BAD_IT_COND; | |
18046 | return FAIL; | |
18047 | } | |
18048 | break; | |
18049 | ||
18050 | case INSIDE_IT_LAST_INSN: | |
18051 | case IF_INSIDE_IT_LAST_INSN: | |
18052 | if (cond != inst.cond) | |
18053 | { | |
18054 | inst.error = BAD_IT_COND; | |
18055 | return FAIL; | |
18056 | } | |
18057 | if (!is_last) | |
18058 | { | |
18059 | inst.error = BAD_BRANCH; | |
18060 | return FAIL; | |
18061 | } | |
18062 | break; | |
18063 | ||
18064 | case NEUTRAL_IT_INSN: | |
18065 | /* The BKPT instruction is unconditional even in an IT block. */ | |
18066 | break; | |
18067 | ||
18068 | case IT_INSN: | |
18069 | inst.error = BAD_IT_IT; | |
18070 | return FAIL; | |
18071 | } | |
18072 | } | |
18073 | break; | |
18074 | } | |
18075 | ||
18076 | return SUCCESS; | |
18077 | } | |
18078 | ||
5a01bb1d MGD |
18079 | struct depr_insn_mask |
18080 | { | |
18081 | unsigned long pattern; | |
18082 | unsigned long mask; | |
18083 | const char* description; | |
18084 | }; | |
18085 | ||
18086 | /* List of 16-bit instruction patterns deprecated in an IT block in | |
18087 | ARMv8. */ | |
18088 | static const struct depr_insn_mask depr_it_insns[] = { | |
18089 | { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") }, | |
18090 | { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") }, | |
18091 | { 0xa000, 0xb800, N_("ADR") }, | |
18092 | { 0x4800, 0xf800, N_("Literal loads") }, | |
18093 | { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") }, | |
18094 | { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") }, | |
c8de034b JW |
18095 | /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue' |
18096 | field in asm_opcode. 'tvalue' is used at the stage this check happen. */ | |
18097 | { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") }, | |
5a01bb1d MGD |
18098 | { 0, 0, NULL } |
18099 | }; | |
18100 | ||
e07e6e58 NC |
18101 | static void |
18102 | it_fsm_post_encode (void) | |
18103 | { | |
18104 | int is_last; | |
18105 | ||
18106 | if (!now_it.state_handled) | |
18107 | handle_it_state (); | |
18108 | ||
5a01bb1d MGD |
18109 | if (now_it.insn_cond |
18110 | && !now_it.warn_deprecated | |
18111 | && warn_on_deprecated | |
18112 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
18113 | { | |
18114 | if (inst.instruction >= 0x10000) | |
18115 | { | |
5c3696f8 | 18116 | as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are " |
5a01bb1d MGD |
18117 | "deprecated in ARMv8")); |
18118 | now_it.warn_deprecated = TRUE; | |
18119 | } | |
18120 | else | |
18121 | { | |
18122 | const struct depr_insn_mask *p = depr_it_insns; | |
18123 | ||
18124 | while (p->mask != 0) | |
18125 | { | |
18126 | if ((inst.instruction & p->mask) == p->pattern) | |
18127 | { | |
5c3696f8 | 18128 | as_tsktsk (_("IT blocks containing 16-bit Thumb instructions " |
5a01bb1d MGD |
18129 | "of the following class are deprecated in ARMv8: " |
18130 | "%s"), p->description); | |
18131 | now_it.warn_deprecated = TRUE; | |
18132 | break; | |
18133 | } | |
18134 | ||
18135 | ++p; | |
18136 | } | |
18137 | } | |
18138 | ||
18139 | if (now_it.block_length > 1) | |
18140 | { | |
5c3696f8 | 18141 | as_tsktsk (_("IT blocks containing more than one conditional " |
0a8897c7 | 18142 | "instruction are deprecated in ARMv8")); |
5a01bb1d MGD |
18143 | now_it.warn_deprecated = TRUE; |
18144 | } | |
18145 | } | |
18146 | ||
e07e6e58 NC |
18147 | is_last = (now_it.mask == 0x10); |
18148 | if (is_last) | |
18149 | { | |
18150 | now_it.state = OUTSIDE_IT_BLOCK; | |
18151 | now_it.mask = 0; | |
18152 | } | |
18153 | } | |
18154 | ||
18155 | static void | |
18156 | force_automatic_it_block_close (void) | |
18157 | { | |
18158 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
18159 | { | |
18160 | close_automatic_it_block (); | |
18161 | now_it.state = OUTSIDE_IT_BLOCK; | |
18162 | now_it.mask = 0; | |
18163 | } | |
18164 | } | |
18165 | ||
18166 | static int | |
18167 | in_it_block (void) | |
18168 | { | |
18169 | if (!now_it.state_handled) | |
18170 | handle_it_state (); | |
18171 | ||
18172 | return now_it.state != OUTSIDE_IT_BLOCK; | |
18173 | } | |
18174 | ||
ff8646ee TP |
18175 | /* Whether OPCODE only has T32 encoding. Since this function is only used by |
18176 | t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed | |
18177 | here, hence the "known" in the function name. */ | |
fc289b0a TP |
18178 | |
18179 | static bfd_boolean | |
ff8646ee | 18180 | known_t32_only_insn (const struct asm_opcode *opcode) |
fc289b0a TP |
18181 | { |
18182 | /* Original Thumb-1 wide instruction. */ | |
18183 | if (opcode->tencode == do_t_blx | |
18184 | || opcode->tencode == do_t_branch23 | |
18185 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) | |
18186 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)) | |
18187 | return TRUE; | |
18188 | ||
ff8646ee TP |
18189 | /* Wide-only instruction added to ARMv8-M. */ |
18190 | if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m) | |
18191 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics) | |
18192 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m) | |
18193 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div)) | |
18194 | return TRUE; | |
18195 | ||
18196 | return FALSE; | |
18197 | } | |
18198 | ||
18199 | /* Whether wide instruction variant can be used if available for a valid OPCODE | |
18200 | in ARCH. */ | |
18201 | ||
18202 | static bfd_boolean | |
18203 | t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode) | |
18204 | { | |
18205 | if (known_t32_only_insn (opcode)) | |
18206 | return TRUE; | |
18207 | ||
18208 | /* Instruction with narrow and wide encoding added to ARMv8-M. Availability | |
18209 | of variant T3 of B.W is checked in do_t_branch. */ | |
18210 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
18211 | && opcode->tencode == do_t_branch) | |
18212 | return TRUE; | |
18213 | ||
18214 | /* Wide instruction variants of all instructions with narrow *and* wide | |
18215 | variants become available with ARMv6t2. Other opcodes are either | |
18216 | narrow-only or wide-only and are thus available if OPCODE is valid. */ | |
18217 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2)) | |
18218 | return TRUE; | |
18219 | ||
18220 | /* OPCODE with narrow only instruction variant or wide variant not | |
18221 | available. */ | |
fc289b0a TP |
18222 | return FALSE; |
18223 | } | |
18224 | ||
c19d1205 ZW |
18225 | void |
18226 | md_assemble (char *str) | |
b99bd4ef | 18227 | { |
c19d1205 ZW |
18228 | char *p = str; |
18229 | const struct asm_opcode * opcode; | |
b99bd4ef | 18230 | |
c19d1205 ZW |
18231 | /* Align the previous label if needed. */ |
18232 | if (last_label_seen != NULL) | |
b99bd4ef | 18233 | { |
c19d1205 ZW |
18234 | symbol_set_frag (last_label_seen, frag_now); |
18235 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
18236 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
18237 | } |
18238 | ||
c19d1205 ZW |
18239 | memset (&inst, '\0', sizeof (inst)); |
18240 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 18241 | |
c19d1205 ZW |
18242 | opcode = opcode_lookup (&p); |
18243 | if (!opcode) | |
b99bd4ef | 18244 | { |
c19d1205 | 18245 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 18246 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d | 18247 | if (! create_register_alias (str, p) |
477330fc | 18248 | && ! create_neon_reg_alias (str, p)) |
c19d1205 | 18249 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 18250 | |
b99bd4ef NC |
18251 | return; |
18252 | } | |
18253 | ||
278df34e | 18254 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
5c3696f8 | 18255 | as_tsktsk (_("s suffix on comparison instruction is deprecated")); |
088fa78e | 18256 | |
037e8744 JB |
18257 | /* The value which unconditional instructions should have in place of the |
18258 | condition field. */ | |
18259 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
18260 | ||
c19d1205 | 18261 | if (thumb_mode) |
b99bd4ef | 18262 | { |
e74cfd16 | 18263 | arm_feature_set variant; |
8f06b2d8 PB |
18264 | |
18265 | variant = cpu_variant; | |
18266 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
18267 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
18268 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 18269 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
18270 | if (!opcode->tvariant |
18271 | || (thumb_mode == 1 | |
18272 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 18273 | { |
84b52b66 | 18274 | as_bad (_("selected processor does not support `%s' in Thumb mode"), str); |
b99bd4ef NC |
18275 | return; |
18276 | } | |
c19d1205 ZW |
18277 | if (inst.cond != COND_ALWAYS && !unified_syntax |
18278 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 18279 | { |
c19d1205 | 18280 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
18281 | return; |
18282 | } | |
18283 | ||
fc289b0a TP |
18284 | /* Two things are addressed here: |
18285 | 1) Implicit require narrow instructions on Thumb-1. | |
18286 | This avoids relaxation accidentally introducing Thumb-2 | |
18287 | instructions. | |
18288 | 2) Reject wide instructions in non Thumb-2 cores. | |
18289 | ||
18290 | Only instructions with narrow and wide variants need to be handled | |
18291 | but selecting all non wide-only instructions is easier. */ | |
18292 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) | |
ff8646ee | 18293 | && !t32_insn_ok (variant, opcode)) |
076d447c | 18294 | { |
fc289b0a TP |
18295 | if (inst.size_req == 0) |
18296 | inst.size_req = 2; | |
18297 | else if (inst.size_req == 4) | |
752d5da4 | 18298 | { |
ff8646ee TP |
18299 | if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m)) |
18300 | as_bad (_("selected processor does not support 32bit wide " | |
18301 | "variant of instruction `%s'"), str); | |
18302 | else | |
18303 | as_bad (_("selected processor does not support `%s' in " | |
18304 | "Thumb-2 mode"), str); | |
fc289b0a | 18305 | return; |
752d5da4 | 18306 | } |
076d447c PB |
18307 | } |
18308 | ||
c19d1205 ZW |
18309 | inst.instruction = opcode->tvalue; |
18310 | ||
5be8be5d | 18311 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
477330fc RM |
18312 | { |
18313 | /* Prepare the it_insn_type for those encodings that don't set | |
18314 | it. */ | |
18315 | it_fsm_pre_encode (); | |
c19d1205 | 18316 | |
477330fc | 18317 | opcode->tencode (); |
e07e6e58 | 18318 | |
477330fc RM |
18319 | it_fsm_post_encode (); |
18320 | } | |
e27ec89e | 18321 | |
0110f2b8 | 18322 | if (!(inst.error || inst.relax)) |
b99bd4ef | 18323 | { |
9c2799c2 | 18324 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
18325 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
18326 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 18327 | { |
c19d1205 | 18328 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
18329 | return; |
18330 | } | |
18331 | } | |
076d447c PB |
18332 | |
18333 | /* Something has gone badly wrong if we try to relax a fixed size | |
477330fc | 18334 | instruction. */ |
9c2799c2 | 18335 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 18336 | |
e74cfd16 PB |
18337 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
18338 | *opcode->tvariant); | |
ee065d83 | 18339 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
fc289b0a TP |
18340 | set those bits when Thumb-2 32-bit instructions are seen. The impact |
18341 | of relaxable instructions will be considered later after we finish all | |
18342 | relaxation. */ | |
ff8646ee TP |
18343 | if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any)) |
18344 | variant = arm_arch_none; | |
18345 | else | |
18346 | variant = cpu_variant; | |
18347 | if (inst.size == 4 && !t32_insn_ok (variant, opcode)) | |
e74cfd16 PB |
18348 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
18349 | arm_ext_v6t2); | |
cd000bff | 18350 | |
88714cb8 DG |
18351 | check_neon_suffixes; |
18352 | ||
cd000bff | 18353 | if (!inst.error) |
c877a2f2 NC |
18354 | { |
18355 | mapping_state (MAP_THUMB); | |
18356 | } | |
c19d1205 | 18357 | } |
3e9e4fcf | 18358 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 18359 | { |
845b51d6 PB |
18360 | bfd_boolean is_bx; |
18361 | ||
18362 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
18363 | is_bx = (opcode->aencode == do_bx); | |
18364 | ||
c19d1205 | 18365 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
18366 | if (!(is_bx && fix_v4bx) |
18367 | && !(opcode->avariant && | |
18368 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 18369 | { |
84b52b66 | 18370 | as_bad (_("selected processor does not support `%s' in ARM mode"), str); |
c19d1205 | 18371 | return; |
b99bd4ef | 18372 | } |
c19d1205 | 18373 | if (inst.size_req) |
b99bd4ef | 18374 | { |
c19d1205 ZW |
18375 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
18376 | return; | |
b99bd4ef NC |
18377 | } |
18378 | ||
c19d1205 ZW |
18379 | inst.instruction = opcode->avalue; |
18380 | if (opcode->tag == OT_unconditionalF) | |
eff0bc54 | 18381 | inst.instruction |= 0xFU << 28; |
c19d1205 ZW |
18382 | else |
18383 | inst.instruction |= inst.cond << 28; | |
18384 | inst.size = INSN_SIZE; | |
5be8be5d | 18385 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
477330fc RM |
18386 | { |
18387 | it_fsm_pre_encode (); | |
18388 | opcode->aencode (); | |
18389 | it_fsm_post_encode (); | |
18390 | } | |
ee065d83 | 18391 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
477330fc | 18392 | on a hypothetical non-thumb v5 core. */ |
845b51d6 | 18393 | if (is_bx) |
e74cfd16 | 18394 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 18395 | else |
e74cfd16 PB |
18396 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
18397 | *opcode->avariant); | |
88714cb8 DG |
18398 | |
18399 | check_neon_suffixes; | |
18400 | ||
cd000bff | 18401 | if (!inst.error) |
c877a2f2 NC |
18402 | { |
18403 | mapping_state (MAP_ARM); | |
18404 | } | |
b99bd4ef | 18405 | } |
3e9e4fcf JB |
18406 | else |
18407 | { | |
18408 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
18409 | "-- `%s'"), str); | |
18410 | return; | |
18411 | } | |
c19d1205 ZW |
18412 | output_inst (str); |
18413 | } | |
b99bd4ef | 18414 | |
e07e6e58 NC |
18415 | static void |
18416 | check_it_blocks_finished (void) | |
18417 | { | |
18418 | #ifdef OBJ_ELF | |
18419 | asection *sect; | |
18420 | ||
18421 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
18422 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
18423 | == MANUAL_IT_BLOCK) | |
18424 | { | |
18425 | as_warn (_("section '%s' finished with an open IT block."), | |
18426 | sect->name); | |
18427 | } | |
18428 | #else | |
18429 | if (now_it.state == MANUAL_IT_BLOCK) | |
18430 | as_warn (_("file finished with an open IT block.")); | |
18431 | #endif | |
18432 | } | |
18433 | ||
c19d1205 ZW |
18434 | /* Various frobbings of labels and their addresses. */ |
18435 | ||
18436 | void | |
18437 | arm_start_line_hook (void) | |
18438 | { | |
18439 | last_label_seen = NULL; | |
b99bd4ef NC |
18440 | } |
18441 | ||
c19d1205 ZW |
18442 | void |
18443 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 18444 | { |
c19d1205 | 18445 | last_label_seen = sym; |
b99bd4ef | 18446 | |
c19d1205 | 18447 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 18448 | |
c19d1205 ZW |
18449 | #if defined OBJ_COFF || defined OBJ_ELF |
18450 | ARM_SET_INTERWORK (sym, support_interwork); | |
18451 | #endif | |
b99bd4ef | 18452 | |
e07e6e58 NC |
18453 | force_automatic_it_block_close (); |
18454 | ||
5f4273c7 | 18455 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
18456 | as Thumb functions. This is because these labels, whilst |
18457 | they exist inside Thumb code, are not the entry points for | |
18458 | possible ARM->Thumb calls. Also, these labels can be used | |
18459 | as part of a computed goto or switch statement. eg gcc | |
18460 | can generate code that looks like this: | |
b99bd4ef | 18461 | |
c19d1205 ZW |
18462 | ldr r2, [pc, .Laaa] |
18463 | lsl r3, r3, #2 | |
18464 | ldr r2, [r3, r2] | |
18465 | mov pc, r2 | |
b99bd4ef | 18466 | |
c19d1205 ZW |
18467 | .Lbbb: .word .Lxxx |
18468 | .Lccc: .word .Lyyy | |
18469 | ..etc... | |
18470 | .Laaa: .word Lbbb | |
b99bd4ef | 18471 | |
c19d1205 ZW |
18472 | The first instruction loads the address of the jump table. |
18473 | The second instruction converts a table index into a byte offset. | |
18474 | The third instruction gets the jump address out of the table. | |
18475 | The fourth instruction performs the jump. | |
b99bd4ef | 18476 | |
c19d1205 ZW |
18477 | If the address stored at .Laaa is that of a symbol which has the |
18478 | Thumb_Func bit set, then the linker will arrange for this address | |
18479 | to have the bottom bit set, which in turn would mean that the | |
18480 | address computation performed by the third instruction would end | |
18481 | up with the bottom bit set. Since the ARM is capable of unaligned | |
18482 | word loads, the instruction would then load the incorrect address | |
18483 | out of the jump table, and chaos would ensue. */ | |
18484 | if (label_is_thumb_function_name | |
18485 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
18486 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 18487 | { |
c19d1205 ZW |
18488 | /* When the address of a Thumb function is taken the bottom |
18489 | bit of that address should be set. This will allow | |
18490 | interworking between Arm and Thumb functions to work | |
18491 | correctly. */ | |
b99bd4ef | 18492 | |
c19d1205 | 18493 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 18494 | |
c19d1205 | 18495 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 18496 | } |
07a53e5c | 18497 | |
07a53e5c | 18498 | dwarf2_emit_label (sym); |
b99bd4ef NC |
18499 | } |
18500 | ||
c921be7d | 18501 | bfd_boolean |
c19d1205 | 18502 | arm_data_in_code (void) |
b99bd4ef | 18503 | { |
c19d1205 | 18504 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 18505 | { |
c19d1205 ZW |
18506 | *input_line_pointer = '/'; |
18507 | input_line_pointer += 5; | |
18508 | *input_line_pointer = 0; | |
c921be7d | 18509 | return TRUE; |
b99bd4ef NC |
18510 | } |
18511 | ||
c921be7d | 18512 | return FALSE; |
b99bd4ef NC |
18513 | } |
18514 | ||
c19d1205 ZW |
18515 | char * |
18516 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 18517 | { |
c19d1205 | 18518 | int len; |
b99bd4ef | 18519 | |
c19d1205 ZW |
18520 | if (thumb_mode && (len = strlen (name)) > 5 |
18521 | && streq (name + len - 5, "/data")) | |
18522 | *(name + len - 5) = 0; | |
b99bd4ef | 18523 | |
c19d1205 | 18524 | return name; |
b99bd4ef | 18525 | } |
c19d1205 ZW |
18526 | \f |
18527 | /* Table of all register names defined by default. The user can | |
18528 | define additional names with .req. Note that all register names | |
18529 | should appear in both upper and lowercase variants. Some registers | |
18530 | also have mixed-case names. */ | |
b99bd4ef | 18531 | |
dcbf9037 | 18532 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 18533 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 18534 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
18535 | #define REGSET(p,t) \ |
18536 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
18537 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
18538 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
18539 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
18540 | #define REGSETH(p,t) \ |
18541 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
18542 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
18543 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
18544 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
18545 | #define REGSET2(p,t) \ | |
18546 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
18547 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
18548 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
18549 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
18550 | #define SPLRBANK(base,bank,t) \ |
18551 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
18552 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
18553 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
18554 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
18555 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
18556 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 18557 | |
c19d1205 | 18558 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 18559 | { |
c19d1205 ZW |
18560 | /* ARM integer registers. */ |
18561 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 18562 | |
c19d1205 ZW |
18563 | /* ATPCS synonyms. */ |
18564 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
18565 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
18566 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 18567 | |
c19d1205 ZW |
18568 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
18569 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
18570 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 18571 | |
c19d1205 ZW |
18572 | /* Well-known aliases. */ |
18573 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
18574 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
18575 | ||
18576 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
18577 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
18578 | ||
18579 | /* Coprocessor numbers. */ | |
18580 | REGSET(p, CP), REGSET(P, CP), | |
18581 | ||
18582 | /* Coprocessor register numbers. The "cr" variants are for backward | |
18583 | compatibility. */ | |
18584 | REGSET(c, CN), REGSET(C, CN), | |
18585 | REGSET(cr, CN), REGSET(CR, CN), | |
18586 | ||
90ec0d68 MGD |
18587 | /* ARM banked registers. */ |
18588 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
18589 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
18590 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
18591 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
18592 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
18593 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
18594 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
18595 | ||
18596 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
18597 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
18598 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
18599 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
18600 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
1472d06f | 18601 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB), |
90ec0d68 MGD |
18602 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), |
18603 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
18604 | ||
18605 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
18606 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
18607 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
18608 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
18609 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
18610 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
18611 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
fa94de6b | 18612 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
18613 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
18614 | ||
c19d1205 ZW |
18615 | /* FPA registers. */ |
18616 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
18617 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
18618 | ||
18619 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
18620 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
18621 | ||
18622 | /* VFP SP registers. */ | |
5287ad62 JB |
18623 | REGSET(s,VFS), REGSET(S,VFS), |
18624 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
18625 | |
18626 | /* VFP DP Registers. */ | |
5287ad62 JB |
18627 | REGSET(d,VFD), REGSET(D,VFD), |
18628 | /* Extra Neon DP registers. */ | |
18629 | REGSETH(d,VFD), REGSETH(D,VFD), | |
18630 | ||
18631 | /* Neon QP registers. */ | |
18632 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
18633 | |
18634 | /* VFP control registers. */ | |
18635 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
18636 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
18637 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
18638 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
18639 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
18640 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
18641 | |
18642 | /* Maverick DSP coprocessor registers. */ | |
18643 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
18644 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
18645 | ||
18646 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
18647 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
18648 | REGDEF(dspsc,0,DSPSC), | |
18649 | ||
18650 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
18651 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
18652 | REGDEF(DSPSC,0,DSPSC), | |
18653 | ||
18654 | /* iWMMXt data registers - p0, c0-15. */ | |
18655 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
18656 | ||
18657 | /* iWMMXt control registers - p1, c0-3. */ | |
18658 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
18659 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
18660 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
18661 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
18662 | ||
18663 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
18664 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
18665 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
18666 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
18667 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
18668 | ||
18669 | /* XScale accumulator registers. */ | |
18670 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
18671 | }; | |
18672 | #undef REGDEF | |
18673 | #undef REGNUM | |
18674 | #undef REGSET | |
7ed4c4c5 | 18675 | |
c19d1205 ZW |
18676 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
18677 | within psr_required_here. */ | |
18678 | static const struct asm_psr psrs[] = | |
18679 | { | |
18680 | /* Backward compatibility notation. Note that "all" is no longer | |
18681 | truly all possible PSR bits. */ | |
18682 | {"all", PSR_c | PSR_f}, | |
18683 | {"flg", PSR_f}, | |
18684 | {"ctl", PSR_c}, | |
18685 | ||
18686 | /* Individual flags. */ | |
18687 | {"f", PSR_f}, | |
18688 | {"c", PSR_c}, | |
18689 | {"x", PSR_x}, | |
18690 | {"s", PSR_s}, | |
59b42a0d | 18691 | |
c19d1205 ZW |
18692 | /* Combinations of flags. */ |
18693 | {"fs", PSR_f | PSR_s}, | |
18694 | {"fx", PSR_f | PSR_x}, | |
18695 | {"fc", PSR_f | PSR_c}, | |
18696 | {"sf", PSR_s | PSR_f}, | |
18697 | {"sx", PSR_s | PSR_x}, | |
18698 | {"sc", PSR_s | PSR_c}, | |
18699 | {"xf", PSR_x | PSR_f}, | |
18700 | {"xs", PSR_x | PSR_s}, | |
18701 | {"xc", PSR_x | PSR_c}, | |
18702 | {"cf", PSR_c | PSR_f}, | |
18703 | {"cs", PSR_c | PSR_s}, | |
18704 | {"cx", PSR_c | PSR_x}, | |
18705 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
18706 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
18707 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
18708 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
18709 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
18710 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
18711 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
18712 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
18713 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
18714 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
18715 | {"scf", PSR_s | PSR_c | PSR_f}, | |
18716 | {"scx", PSR_s | PSR_c | PSR_x}, | |
18717 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
18718 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
18719 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
18720 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
18721 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
18722 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
18723 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
18724 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
18725 | {"csf", PSR_c | PSR_s | PSR_f}, | |
18726 | {"csx", PSR_c | PSR_s | PSR_x}, | |
18727 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
18728 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
18729 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
18730 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
18731 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
18732 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
18733 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
18734 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
18735 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
18736 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
18737 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
18738 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
18739 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
18740 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
18741 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
18742 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
18743 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
18744 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
18745 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
18746 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
18747 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
18748 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
18749 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
18750 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
18751 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
18752 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
18753 | }; | |
18754 | ||
62b3e311 PB |
18755 | /* Table of V7M psr names. */ |
18756 | static const struct asm_psr v7m_psrs[] = | |
18757 | { | |
2b744c99 PB |
18758 | {"apsr", 0 }, {"APSR", 0 }, |
18759 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
18760 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
18761 | {"psr", 3 }, {"PSR", 3 }, | |
18762 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
18763 | {"ipsr", 5 }, {"IPSR", 5 }, | |
18764 | {"epsr", 6 }, {"EPSR", 6 }, | |
18765 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
18766 | {"msp", 8 }, {"MSP", 8 }, | |
18767 | {"psp", 9 }, {"PSP", 9 }, | |
18768 | {"primask", 16}, {"PRIMASK", 16}, | |
18769 | {"basepri", 17}, {"BASEPRI", 17}, | |
00bbc0bd NC |
18770 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, |
18771 | {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */ | |
2b744c99 PB |
18772 | {"faultmask", 19}, {"FAULTMASK", 19}, |
18773 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
18774 | }; |
18775 | ||
c19d1205 ZW |
18776 | /* Table of all shift-in-operand names. */ |
18777 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 18778 | { |
c19d1205 ZW |
18779 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
18780 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
18781 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
18782 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
18783 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
18784 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
18785 | }; | |
b99bd4ef | 18786 | |
c19d1205 ZW |
18787 | /* Table of all explicit relocation names. */ |
18788 | #ifdef OBJ_ELF | |
18789 | static struct reloc_entry reloc_names[] = | |
18790 | { | |
18791 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
18792 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
18793 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
18794 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
18795 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
18796 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
18797 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
18798 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
18799 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
18800 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 | 18801 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
18802 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
18803 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
477330fc | 18804 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, |
0855e32b | 18805 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, |
477330fc | 18806 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, |
0855e32b | 18807 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, |
477330fc | 18808 | { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ} |
c19d1205 ZW |
18809 | }; |
18810 | #endif | |
b99bd4ef | 18811 | |
c19d1205 ZW |
18812 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
18813 | static const struct asm_cond conds[] = | |
18814 | { | |
18815 | {"eq", 0x0}, | |
18816 | {"ne", 0x1}, | |
18817 | {"cs", 0x2}, {"hs", 0x2}, | |
18818 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
18819 | {"mi", 0x4}, | |
18820 | {"pl", 0x5}, | |
18821 | {"vs", 0x6}, | |
18822 | {"vc", 0x7}, | |
18823 | {"hi", 0x8}, | |
18824 | {"ls", 0x9}, | |
18825 | {"ge", 0xa}, | |
18826 | {"lt", 0xb}, | |
18827 | {"gt", 0xc}, | |
18828 | {"le", 0xd}, | |
18829 | {"al", 0xe} | |
18830 | }; | |
bfae80f2 | 18831 | |
e797f7e0 | 18832 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
823d2571 TG |
18833 | { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \ |
18834 | { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) } | |
e797f7e0 | 18835 | |
62b3e311 PB |
18836 | static struct asm_barrier_opt barrier_opt_names[] = |
18837 | { | |
e797f7e0 MGD |
18838 | UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER), |
18839 | UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER), | |
18840 | UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8), | |
18841 | UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER), | |
18842 | UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER), | |
18843 | UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER), | |
18844 | UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER), | |
18845 | UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8), | |
18846 | UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER), | |
18847 | UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER), | |
18848 | UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER), | |
18849 | UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER), | |
18850 | UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8), | |
18851 | UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER), | |
18852 | UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER), | |
18853 | UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8) | |
62b3e311 PB |
18854 | }; |
18855 | ||
e797f7e0 MGD |
18856 | #undef UL_BARRIER |
18857 | ||
c19d1205 ZW |
18858 | /* Table of ARM-format instructions. */ |
18859 | ||
18860 | /* Macros for gluing together operand strings. N.B. In all cases | |
18861 | other than OPS0, the trailing OP_stop comes from default | |
18862 | zero-initialization of the unspecified elements of the array. */ | |
18863 | #define OPS0() { OP_stop, } | |
18864 | #define OPS1(a) { OP_##a, } | |
18865 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
18866 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
18867 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
18868 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
18869 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
18870 | ||
5be8be5d DG |
18871 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
18872 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
18873 | MIX_ARM_THUMB_OPERANDS macro. | |
18874 | In order to use these macros, prefix the number of operands with _ | |
18875 | e.g. _3. */ | |
18876 | #define OPS_1(a) { a, } | |
18877 | #define OPS_2(a,b) { a,b, } | |
18878 | #define OPS_3(a,b,c) { a,b,c, } | |
18879 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
18880 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
18881 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
18882 | ||
c19d1205 ZW |
18883 | /* These macros abstract out the exact format of the mnemonic table and |
18884 | save some repeated characters. */ | |
18885 | ||
18886 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
18887 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 18888 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 18889 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
18890 | |
18891 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
18892 | a T_MNEM_xyz enumerator. */ | |
18893 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 18894 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 18895 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 18896 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
18897 | |
18898 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
18899 | infix after the third character. */ | |
18900 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 18901 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 18902 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 18903 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 18904 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 18905 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 18906 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 18907 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 18908 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 18909 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 18910 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 18911 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 18912 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 18913 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 18914 | |
c19d1205 | 18915 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
18916 | field is still 0xE. Many of the Thumb variants can be executed |
18917 | conditionally, so this is checked separately. */ | |
c19d1205 | 18918 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 18919 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 18920 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 18921 | |
dd5181d5 KT |
18922 | /* Same as TUE but the encoding function for ARM and Thumb modes is the same. |
18923 | Used by mnemonics that have very minimal differences in the encoding for | |
18924 | ARM and Thumb variants and can be handled in a common function. */ | |
18925 | #define TUEc(mnem, op, top, nops, ops, en) \ | |
18926 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
18927 | THUMB_VARIANT, do_##en, do_##en } | |
18928 | ||
c19d1205 ZW |
18929 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM |
18930 | condition code field. */ | |
18931 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 18932 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 18933 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
18934 | |
18935 | /* ARM-only variants of all the above. */ | |
6a86118a | 18936 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 18937 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
18938 | |
18939 | #define C3(mnem, op, nops, ops, ae) \ | |
18940 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
18941 | ||
e3cb604e PB |
18942 | /* Legacy mnemonics that always have conditional infix after the third |
18943 | character. */ | |
18944 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18945 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
18946 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
18947 | ||
8f06b2d8 PB |
18948 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
18949 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18950 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 18951 | |
e3cb604e PB |
18952 | /* Legacy coprocessor instructions where conditional infix and conditional |
18953 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
18954 | not just the potentially ambiguous ones. */ | |
18955 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18956 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
18957 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
18958 | ||
18959 | /* Coprocessor, takes either a suffix or a position-3 infix | |
18960 | (for an FPA corner case). */ | |
18961 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18962 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 18963 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 18964 | |
6a86118a | 18965 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
18966 | { m1 #m2 m3, OPS##nops ops, \ |
18967 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
18968 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
18969 | ||
18970 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
18971 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
18972 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
18973 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
18974 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
18975 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
18976 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
18977 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
18978 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
18979 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
18980 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
18981 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
18982 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
18983 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
18984 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
18985 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
18986 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
18987 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
18988 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
18989 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
18990 | |
18991 | #define UE(mnem, op, nops, ops, ae) \ | |
18992 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
18993 | ||
18994 | #define UF(mnem, op, nops, ops, ae) \ | |
18995 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
18996 | ||
5287ad62 JB |
18997 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
18998 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
18999 | use the same encoding function for each. */ | |
19000 | #define NUF(mnem, op, nops, ops, enc) \ | |
19001 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
19002 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
19003 | ||
19004 | /* Neon data processing, version which indirects through neon_enc_tab for | |
19005 | the various overloaded versions of opcodes. */ | |
19006 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 19007 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
19008 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
19009 | ||
19010 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
19011 | version. */ | |
037e8744 JB |
19012 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
19013 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
19014 | THUMB_VARIANT, do_##enc, do_##enc } |
19015 | ||
037e8744 | 19016 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 19017 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
19018 | |
19019 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 19020 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 19021 | |
5287ad62 | 19022 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 19023 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 19024 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
19025 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
19026 | ||
037e8744 | 19027 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 19028 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
19029 | |
19030 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 19031 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 19032 | |
c19d1205 ZW |
19033 | #define do_0 0 |
19034 | ||
c19d1205 | 19035 | static const struct asm_opcode insns[] = |
bfae80f2 | 19036 | { |
74db7efb NC |
19037 | #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */ |
19038 | #define THUMB_VARIANT & arm_ext_v4t | |
21d799b5 NC |
19039 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
19040 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
19041 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
19042 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
19043 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
19044 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
19045 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
19046 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
19047 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
19048 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
19049 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
19050 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
19051 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
19052 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
19053 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
19054 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
19055 | |
19056 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
19057 | for setting PSR flag bits. They are obsolete in V6 and do not | |
19058 | have Thumb equivalents. */ | |
21d799b5 NC |
19059 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
19060 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
19061 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
19062 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
19063 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
19064 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
19065 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
19066 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
19067 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
19068 | ||
19069 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
72d98d16 | 19070 | tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp), |
21d799b5 NC |
19071 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), |
19072 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
19073 | ||
19074 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
19075 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
19076 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
19077 | OP_RRnpc), | |
19078 | OP_ADDRGLDR),ldst, t_ldst), | |
19079 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
19080 | |
19081 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19082 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19083 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19084 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19085 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19086 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
19087 | ||
19088 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
19089 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
19090 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), | |
19091 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 19092 | |
c19d1205 | 19093 | /* Pseudo ops. */ |
21d799b5 | 19094 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 19095 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 19096 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
74db7efb | 19097 | tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf), |
c19d1205 ZW |
19098 | |
19099 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
19100 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
19101 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
19102 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
19103 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
19104 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
19105 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
19106 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
19107 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
19108 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
19109 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
19110 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
19111 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 19112 | |
16a4cf17 | 19113 | /* These may simplify to neg. */ |
21d799b5 NC |
19114 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
19115 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 19116 | |
c921be7d NC |
19117 | #undef THUMB_VARIANT |
19118 | #define THUMB_VARIANT & arm_ext_v6 | |
19119 | ||
21d799b5 | 19120 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
19121 | |
19122 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
19123 | #undef THUMB_VARIANT |
19124 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19125 | ||
21d799b5 NC |
19126 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
19127 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
19128 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 19129 | |
5be8be5d DG |
19130 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
19131 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
19132 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
19133 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 19134 | |
21d799b5 NC |
19135 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
19136 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 19137 | |
21d799b5 NC |
19138 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
19139 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
19140 | |
19141 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 19142 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
19143 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
19144 | ||
19145 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
19146 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
19147 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
19148 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
19149 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
19150 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
19151 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
19152 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
19153 | ||
c921be7d NC |
19154 | #undef ARM_VARIANT |
19155 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
19156 | #undef THUMB_VARIANT | |
19157 | #define THUMB_VARIANT & arm_ext_v4t | |
19158 | ||
21d799b5 NC |
19159 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
19160 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 19161 | |
c921be7d NC |
19162 | #undef THUMB_VARIANT |
19163 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19164 | ||
21d799b5 | 19165 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
19166 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
19167 | ||
19168 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
19169 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
19170 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19171 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19172 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19173 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19174 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 19175 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 19176 | |
c921be7d NC |
19177 | #undef ARM_VARIANT |
19178 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
19179 | ||
21d799b5 | 19180 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
19181 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
19182 | ||
c921be7d NC |
19183 | #undef ARM_VARIANT |
19184 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
19185 | #undef THUMB_VARIANT | |
19186 | #define THUMB_VARIANT & arm_ext_msr | |
19187 | ||
d2cd1205 JB |
19188 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
19189 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 19190 | |
c921be7d NC |
19191 | #undef ARM_VARIANT |
19192 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
19193 | #undef THUMB_VARIANT | |
19194 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19195 | ||
21d799b5 NC |
19196 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
19197 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
19198 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
19199 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
19200 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
19201 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
19202 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
19203 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 19204 | |
c921be7d NC |
19205 | #undef ARM_VARIANT |
19206 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
19207 | #undef THUMB_VARIANT | |
19208 | #define THUMB_VARIANT & arm_ext_v4t | |
19209 | ||
5be8be5d DG |
19210 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
19211 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
19212 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
19213 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
56c0a61f RE |
19214 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
19215 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 19216 | |
c921be7d NC |
19217 | #undef ARM_VARIANT |
19218 | #define ARM_VARIANT & arm_ext_v4t_5 | |
19219 | ||
c19d1205 ZW |
19220 | /* ARM Architecture 4T. */ |
19221 | /* Note: bx (and blx) are required on V5, even if the processor does | |
19222 | not support Thumb. */ | |
21d799b5 | 19223 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 19224 | |
c921be7d NC |
19225 | #undef ARM_VARIANT |
19226 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
19227 | #undef THUMB_VARIANT | |
19228 | #define THUMB_VARIANT & arm_ext_v5t | |
19229 | ||
c19d1205 ZW |
19230 | /* Note: blx has 2 variants; the .value coded here is for |
19231 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
19232 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
19233 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 19234 | |
c921be7d NC |
19235 | #undef THUMB_VARIANT |
19236 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19237 | ||
21d799b5 NC |
19238 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
19239 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19240 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19241 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19242 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
19243 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
19244 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
19245 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 19246 | |
c921be7d | 19247 | #undef ARM_VARIANT |
74db7efb NC |
19248 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ |
19249 | #undef THUMB_VARIANT | |
19250 | #define THUMB_VARIANT & arm_ext_v5exp | |
c921be7d | 19251 | |
21d799b5 NC |
19252 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
19253 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
19254 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
19255 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 19256 | |
21d799b5 NC |
19257 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
19258 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 19259 | |
21d799b5 NC |
19260 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
19261 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
19262 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
19263 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 19264 | |
21d799b5 NC |
19265 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
19266 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19267 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19268 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 19269 | |
21d799b5 NC |
19270 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
19271 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 19272 | |
03ee1b7f NC |
19273 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
19274 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
19275 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
19276 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 19277 | |
c921be7d | 19278 | #undef ARM_VARIANT |
74db7efb NC |
19279 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ |
19280 | #undef THUMB_VARIANT | |
19281 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 19282 | |
21d799b5 | 19283 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
19284 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
19285 | ldrd, t_ldstd), | |
19286 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
19287 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 19288 | |
21d799b5 NC |
19289 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
19290 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 19291 | |
c921be7d NC |
19292 | #undef ARM_VARIANT |
19293 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
19294 | ||
21d799b5 | 19295 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 19296 | |
c921be7d NC |
19297 | #undef ARM_VARIANT |
19298 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
19299 | #undef THUMB_VARIANT | |
19300 | #define THUMB_VARIANT & arm_ext_v6 | |
19301 | ||
21d799b5 NC |
19302 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
19303 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
19304 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
19305 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
19306 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
19307 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19308 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19309 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19310 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19311 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 19312 | |
c921be7d | 19313 | #undef THUMB_VARIANT |
ff8646ee | 19314 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
c921be7d | 19315 | |
5be8be5d DG |
19316 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
19317 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
19318 | strex, t_strex), | |
ff8646ee TP |
19319 | #undef THUMB_VARIANT |
19320 | #define THUMB_VARIANT & arm_ext_v6t2 | |
19321 | ||
21d799b5 NC |
19322 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
19323 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 19324 | |
21d799b5 NC |
19325 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
19326 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 19327 | |
9e3c6df6 | 19328 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
19329 | #undef THUMB_VARIANT |
19330 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 19331 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 19332 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
19333 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
19334 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
19335 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
19336 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
d709e4e6 RE |
19337 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
19338 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
19339 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 19340 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
19341 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
19342 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 19343 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 19344 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 19345 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 19346 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 19347 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 19348 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
941c9cad | 19349 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c921be7d | 19350 | |
9e3c6df6 PB |
19351 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
19352 | #undef THUMB_VARIANT | |
19353 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
19354 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
19355 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
19356 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19357 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19358 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19359 | /* Old name for QASX. */ |
74db7efb | 19360 | TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 19361 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19362 | /* Old name for QSAX. */ |
74db7efb | 19363 | TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19364 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19365 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19366 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19367 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19368 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19369 | /* Old name for SASX. */ |
74db7efb | 19370 | TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19371 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19372 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 19373 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19374 | /* Old name for SHASX. */ |
21d799b5 | 19375 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
74db7efb | 19376 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19377 | /* Old name for SHSAX. */ |
21d799b5 NC |
19378 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19379 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19380 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19381 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19382 | /* Old name for SSAX. */ |
74db7efb | 19383 | TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19384 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19385 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19386 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19387 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19388 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19389 | /* Old name for UASX. */ |
74db7efb | 19390 | TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19391 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19392 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 19393 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19394 | /* Old name for UHASX. */ |
21d799b5 NC |
19395 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19396 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19397 | /* Old name for UHSAX. */ |
21d799b5 NC |
19398 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19399 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19400 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19401 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19402 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 19403 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19404 | /* Old name for UQASX. */ |
21d799b5 NC |
19405 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19406 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19407 | /* Old name for UQSAX. */ |
21d799b5 NC |
19408 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19409 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19410 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19411 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19412 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19413 | /* Old name for USAX. */ |
74db7efb | 19414 | TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 19415 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19416 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
19417 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19418 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19419 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19420 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19421 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19422 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19423 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19424 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19425 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19426 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19427 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19428 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19429 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19430 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19431 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19432 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19433 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19434 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19435 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19436 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19437 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19438 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19439 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19440 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19441 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19442 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
19443 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
19444 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
19445 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19446 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19447 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 19448 | |
c921be7d NC |
19449 | #undef ARM_VARIANT |
19450 | #define ARM_VARIANT & arm_ext_v6k | |
19451 | #undef THUMB_VARIANT | |
19452 | #define THUMB_VARIANT & arm_ext_v6k | |
19453 | ||
21d799b5 NC |
19454 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
19455 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
19456 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
19457 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 19458 | |
c921be7d NC |
19459 | #undef THUMB_VARIANT |
19460 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
19461 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
19462 | ldrexd, t_ldrexd), | |
19463 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
19464 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 19465 | |
c921be7d | 19466 | #undef THUMB_VARIANT |
ff8646ee | 19467 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
5be8be5d DG |
19468 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
19469 | rd_rn, rd_rn), | |
19470 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
19471 | rd_rn, rd_rn), | |
19472 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
877807f8 | 19473 | strex, t_strexbh), |
5be8be5d | 19474 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 19475 | strex, t_strexbh), |
21d799b5 | 19476 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 19477 | |
c921be7d | 19478 | #undef ARM_VARIANT |
f4c65163 | 19479 | #define ARM_VARIANT & arm_ext_sec |
74db7efb | 19480 | #undef THUMB_VARIANT |
f4c65163 | 19481 | #define THUMB_VARIANT & arm_ext_sec |
c921be7d | 19482 | |
21d799b5 | 19483 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 19484 | |
90ec0d68 MGD |
19485 | #undef ARM_VARIANT |
19486 | #define ARM_VARIANT & arm_ext_virt | |
19487 | #undef THUMB_VARIANT | |
19488 | #define THUMB_VARIANT & arm_ext_virt | |
19489 | ||
19490 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
19491 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
19492 | ||
ddfded2f MW |
19493 | #undef ARM_VARIANT |
19494 | #define ARM_VARIANT & arm_ext_pan | |
19495 | #undef THUMB_VARIANT | |
19496 | #define THUMB_VARIANT & arm_ext_pan | |
19497 | ||
19498 | TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan), | |
19499 | ||
c921be7d | 19500 | #undef ARM_VARIANT |
74db7efb | 19501 | #define ARM_VARIANT & arm_ext_v6t2 |
f4c65163 MGD |
19502 | #undef THUMB_VARIANT |
19503 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 19504 | |
21d799b5 NC |
19505 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
19506 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
19507 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
19508 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 19509 | |
21d799b5 | 19510 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
21d799b5 | 19511 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 | 19512 | |
5be8be5d DG |
19513 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
19514 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
19515 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
19516 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 19517 | |
ff8646ee TP |
19518 | #undef THUMB_VARIANT |
19519 | #define THUMB_VARIANT & arm_ext_v6t2_v8m | |
19520 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
19521 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
19522 | ||
bf3eeda7 | 19523 | /* Thumb-only instructions. */ |
74db7efb | 19524 | #undef ARM_VARIANT |
bf3eeda7 NS |
19525 | #define ARM_VARIANT NULL |
19526 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
19527 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
19528 | |
19529 | /* ARM does not really have an IT instruction, so always allow it. | |
19530 | The opcode is copied from Thumb in order to allow warnings in | |
19531 | -mimplicit-it=[never | arm] modes. */ | |
19532 | #undef ARM_VARIANT | |
19533 | #define ARM_VARIANT & arm_ext_v1 | |
ff8646ee TP |
19534 | #undef THUMB_VARIANT |
19535 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 19536 | |
21d799b5 NC |
19537 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
19538 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
19539 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
19540 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
19541 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
19542 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
19543 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
19544 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
19545 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
19546 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
19547 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
19548 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
19549 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
19550 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
19551 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 19552 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
19553 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
19554 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 19555 | |
92e90b6e | 19556 | /* Thumb2 only instructions. */ |
c921be7d NC |
19557 | #undef ARM_VARIANT |
19558 | #define ARM_VARIANT NULL | |
92e90b6e | 19559 | |
21d799b5 NC |
19560 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
19561 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
19562 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
19563 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
19564 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
19565 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 19566 | |
eea54501 MGD |
19567 | /* Hardware division instructions. */ |
19568 | #undef ARM_VARIANT | |
19569 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
19570 | #undef THUMB_VARIANT |
19571 | #define THUMB_VARIANT & arm_ext_div | |
19572 | ||
eea54501 MGD |
19573 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
19574 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 19575 | |
7e806470 | 19576 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
19577 | #undef ARM_VARIANT |
19578 | #define ARM_VARIANT & arm_ext_barrier | |
19579 | #undef THUMB_VARIANT | |
19580 | #define THUMB_VARIANT & arm_ext_barrier | |
19581 | ||
ccb84d65 JB |
19582 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier), |
19583 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier), | |
19584 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier), | |
7e806470 | 19585 | |
62b3e311 | 19586 | /* ARM V7 instructions. */ |
c921be7d NC |
19587 | #undef ARM_VARIANT |
19588 | #define ARM_VARIANT & arm_ext_v7 | |
19589 | #undef THUMB_VARIANT | |
19590 | #define THUMB_VARIANT & arm_ext_v7 | |
19591 | ||
21d799b5 NC |
19592 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
19593 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 19594 | |
74db7efb | 19595 | #undef ARM_VARIANT |
60e5ef9f | 19596 | #define ARM_VARIANT & arm_ext_mp |
74db7efb | 19597 | #undef THUMB_VARIANT |
60e5ef9f MGD |
19598 | #define THUMB_VARIANT & arm_ext_mp |
19599 | ||
19600 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
19601 | ||
53c4b28b MGD |
19602 | /* AArchv8 instructions. */ |
19603 | #undef ARM_VARIANT | |
19604 | #define ARM_VARIANT & arm_ext_v8 | |
4ed7ed8d TP |
19605 | |
19606 | /* Instructions shared between armv8-a and armv8-m. */ | |
53c4b28b | 19607 | #undef THUMB_VARIANT |
4ed7ed8d | 19608 | #define THUMB_VARIANT & arm_ext_atomics |
53c4b28b | 19609 | |
4ed7ed8d TP |
19610 | TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
19611 | TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
19612 | TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
19613 | TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
19614 | TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
19615 | TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
4b8c8c02 | 19616 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
4b8c8c02 RE |
19617 | TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn), |
19618 | TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
19619 | TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb), | |
19620 | stlex, t_stlex), | |
4b8c8c02 RE |
19621 | TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb), |
19622 | stlex, t_stlex), | |
19623 | TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb), | |
19624 | stlex, t_stlex), | |
4ed7ed8d TP |
19625 | #undef THUMB_VARIANT |
19626 | #define THUMB_VARIANT & arm_ext_v8 | |
53c4b28b | 19627 | |
4ed7ed8d TP |
19628 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), |
19629 | TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt), | |
19630 | TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb), | |
19631 | ldrexd, t_ldrexd), | |
19632 | TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), | |
19633 | strexd, t_strexd), | |
8884b720 | 19634 | /* ARMv8 T32 only. */ |
74db7efb | 19635 | #undef ARM_VARIANT |
b79f7053 MGD |
19636 | #define ARM_VARIANT NULL |
19637 | TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs), | |
19638 | TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs), | |
19639 | TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs), | |
19640 | ||
33399f07 MGD |
19641 | /* FP for ARMv8. */ |
19642 | #undef ARM_VARIANT | |
a715796b | 19643 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 | 19644 | #undef THUMB_VARIANT |
a715796b | 19645 | #define THUMB_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 MGD |
19646 | |
19647 | nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel), | |
19648 | nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel), | |
19649 | nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel), | |
19650 | nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel), | |
73924fbc MGD |
19651 | nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), |
19652 | nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), | |
7e8e6784 MGD |
19653 | nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta), |
19654 | nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn), | |
19655 | nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp), | |
19656 | nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm), | |
30bdf752 MGD |
19657 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
19658 | nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz), | |
19659 | nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx), | |
19660 | nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta), | |
19661 | nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn), | |
19662 | nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp), | |
19663 | nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm), | |
33399f07 | 19664 | |
91ff7894 MGD |
19665 | /* Crypto v1 extensions. */ |
19666 | #undef ARM_VARIANT | |
19667 | #define ARM_VARIANT & fpu_crypto_ext_armv8 | |
19668 | #undef THUMB_VARIANT | |
19669 | #define THUMB_VARIANT & fpu_crypto_ext_armv8 | |
19670 | ||
19671 | nUF(aese, _aes, 2, (RNQ, RNQ), aese), | |
19672 | nUF(aesd, _aes, 2, (RNQ, RNQ), aesd), | |
19673 | nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc), | |
19674 | nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc), | |
48adcd8e MGD |
19675 | nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c), |
19676 | nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p), | |
19677 | nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m), | |
19678 | nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0), | |
19679 | nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h), | |
19680 | nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2), | |
19681 | nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1), | |
3c9017d2 MGD |
19682 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
19683 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
19684 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 19685 | |
dd5181d5 | 19686 | #undef ARM_VARIANT |
74db7efb | 19687 | #define ARM_VARIANT & crc_ext_armv8 |
dd5181d5 KT |
19688 | #undef THUMB_VARIANT |
19689 | #define THUMB_VARIANT & crc_ext_armv8 | |
19690 | TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b), | |
19691 | TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h), | |
19692 | TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w), | |
19693 | TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb), | |
19694 | TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch), | |
19695 | TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw), | |
19696 | ||
105bde57 MW |
19697 | /* ARMv8.2 RAS extension. */ |
19698 | #undef ARM_VARIANT | |
19699 | #define ARM_VARIANT & arm_ext_v8_2 | |
19700 | #undef THUMB_VARIANT | |
19701 | #define THUMB_VARIANT & arm_ext_v8_2 | |
19702 | TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs), | |
19703 | ||
c921be7d NC |
19704 | #undef ARM_VARIANT |
19705 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
19706 | #undef THUMB_VARIANT |
19707 | #define THUMB_VARIANT NULL | |
c921be7d | 19708 | |
21d799b5 NC |
19709 | cCE("wfs", e200110, 1, (RR), rd), |
19710 | cCE("rfs", e300110, 1, (RR), rd), | |
19711 | cCE("wfc", e400110, 1, (RR), rd), | |
19712 | cCE("rfc", e500110, 1, (RR), rd), | |
19713 | ||
19714 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19715 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19716 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19717 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19718 | ||
19719 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19720 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19721 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19722 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19723 | ||
19724 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
19725 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
19726 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
19727 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
19728 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
19729 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
19730 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
19731 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
19732 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
19733 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
19734 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
19735 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
19736 | ||
19737 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
19738 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
19739 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
19740 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
19741 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
19742 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
19743 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
19744 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
19745 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
19746 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
19747 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
19748 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
19749 | ||
19750 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
19751 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
19752 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
19753 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
19754 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
19755 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
19756 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
19757 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
19758 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
19759 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
19760 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
19761 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
19762 | ||
19763 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
19764 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
19765 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
19766 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
19767 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
19768 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
19769 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
19770 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
19771 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
19772 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
19773 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
19774 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
19775 | ||
19776 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
19777 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
19778 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
19779 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
19780 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
19781 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
19782 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
19783 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
19784 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
19785 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
19786 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
19787 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
19788 | ||
19789 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
19790 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
19791 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
19792 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
19793 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
19794 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
19795 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
19796 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
19797 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
19798 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
19799 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
19800 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
19801 | ||
19802 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
19803 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
19804 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
19805 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
19806 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
19807 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
19808 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
19809 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
19810 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
19811 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
19812 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
19813 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
19814 | ||
19815 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
19816 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
19817 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
19818 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
19819 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
19820 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
19821 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
19822 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
19823 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
19824 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
19825 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
19826 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
19827 | ||
19828 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
19829 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
19830 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
19831 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
19832 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
19833 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
19834 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
19835 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
19836 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
19837 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
19838 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
19839 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
19840 | ||
19841 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
19842 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
19843 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
19844 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
19845 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
19846 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
19847 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
19848 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
19849 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
19850 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
19851 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
19852 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
19853 | ||
19854 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
19855 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
19856 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
19857 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
19858 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
19859 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
19860 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
19861 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
19862 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
19863 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
19864 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
19865 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
19866 | ||
19867 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
19868 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
19869 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
19870 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
19871 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
19872 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
19873 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
19874 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
19875 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
19876 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
19877 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
19878 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
19879 | ||
19880 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
19881 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
19882 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
19883 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
19884 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
19885 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
19886 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
19887 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
19888 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
19889 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
19890 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
19891 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
19892 | ||
19893 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
19894 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
19895 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
19896 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
19897 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
19898 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
19899 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
19900 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
19901 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
19902 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
19903 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
19904 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
19905 | ||
19906 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
19907 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
19908 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
19909 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
19910 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
19911 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
19912 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
19913 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
19914 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
19915 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
19916 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
19917 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
19918 | ||
19919 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
19920 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
19921 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
19922 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
19923 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
19924 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
19925 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
19926 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
19927 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
19928 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
19929 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
19930 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
19931 | ||
19932 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19933 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19934 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19935 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19936 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19937 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19938 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19939 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19940 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19941 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19942 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19943 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19944 | ||
19945 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19946 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19947 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19948 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19949 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19950 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19951 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19952 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19953 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19954 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19955 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19956 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19957 | ||
19958 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19959 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19960 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19961 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19962 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19963 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19964 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19965 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19966 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19967 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19968 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19969 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19970 | ||
19971 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19972 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19973 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19974 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19975 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19976 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19977 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19978 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19979 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19980 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19981 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19982 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19983 | ||
19984 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19985 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19986 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19987 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19988 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19989 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19990 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19991 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19992 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19993 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19994 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19995 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19996 | ||
19997 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19998 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19999 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20000 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20001 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20002 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20003 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20004 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20005 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20006 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20007 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20008 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20009 | ||
20010 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20011 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20012 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20013 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20014 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20015 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20016 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20017 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20018 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20019 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20020 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20021 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20022 | ||
20023 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20024 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20025 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20026 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20027 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20028 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20029 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20030 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20031 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20032 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20033 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20034 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20035 | ||
20036 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20037 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20038 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20039 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20040 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20041 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20042 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20043 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20044 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20045 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20046 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20047 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20048 | ||
20049 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20050 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20051 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20052 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20053 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20054 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20055 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20056 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20057 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20058 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20059 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20060 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20061 | ||
20062 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20063 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20064 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20065 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20066 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20067 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20068 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20069 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20070 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20071 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20072 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20073 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20074 | ||
20075 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20076 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20077 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20078 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20079 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20080 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20081 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20082 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20083 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20084 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20085 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20086 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20087 | ||
20088 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20089 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20090 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20091 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20092 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20093 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20094 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20095 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20096 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20097 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20098 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20099 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
20100 | ||
20101 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
20102 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
20103 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
20104 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
20105 | ||
20106 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
20107 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
20108 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
20109 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
20110 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
20111 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
20112 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
20113 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
20114 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
20115 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
20116 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
20117 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 20118 | |
c19d1205 ZW |
20119 | /* The implementation of the FIX instruction is broken on some |
20120 | assemblers, in that it accepts a precision specifier as well as a | |
20121 | rounding specifier, despite the fact that this is meaningless. | |
20122 | To be more compatible, we accept it as well, though of course it | |
20123 | does not set any bits. */ | |
21d799b5 NC |
20124 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
20125 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
20126 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
20127 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
20128 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
20129 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
20130 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
20131 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
20132 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
20133 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
20134 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
20135 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
20136 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 20137 | |
c19d1205 | 20138 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
20139 | #undef ARM_VARIANT |
20140 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
20141 | ||
21d799b5 NC |
20142 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
20143 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20144 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20145 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20146 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
20147 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 20148 | |
c921be7d NC |
20149 | #undef ARM_VARIANT |
20150 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
20151 | ||
c19d1205 | 20152 | /* Moves and type conversions. */ |
21d799b5 NC |
20153 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
20154 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
20155 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
20156 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
7465e07a NC |
20157 | cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs), |
20158 | cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr), | |
21d799b5 NC |
20159 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), |
20160 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20161 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20162 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
20163 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20164 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
20165 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
20166 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
20167 | |
20168 | /* Memory operations. */ | |
21d799b5 NC |
20169 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
20170 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
20171 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
20172 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
20173 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20174 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20175 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20176 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20177 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
20178 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
20179 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
20180 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
20181 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20182 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
20183 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20184 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
20185 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
20186 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 20187 | |
c19d1205 | 20188 | /* Monadic operations. */ |
21d799b5 NC |
20189 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
20190 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
20191 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
20192 | |
20193 | /* Dyadic operations. */ | |
21d799b5 NC |
20194 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
20195 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20196 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20197 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20198 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20199 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20200 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20201 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20202 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 20203 | |
c19d1205 | 20204 | /* Comparisons. */ |
21d799b5 NC |
20205 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
20206 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
20207 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
20208 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 20209 | |
62f3b8c8 PB |
20210 | /* Double precision load/store are still present on single precision |
20211 | implementations. */ | |
20212 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
20213 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
20214 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
20215 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
20216 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
20217 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
20218 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
20219 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
20220 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
20221 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 20222 | |
c921be7d NC |
20223 | #undef ARM_VARIANT |
20224 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
20225 | ||
c19d1205 | 20226 | /* Moves and type conversions. */ |
21d799b5 NC |
20227 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
20228 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
20229 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20230 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
20231 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
20232 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
20233 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
20234 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
20235 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
20236 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20237 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20238 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
20239 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 20240 | |
c19d1205 | 20241 | /* Monadic operations. */ |
21d799b5 NC |
20242 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
20243 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
20244 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
20245 | |
20246 | /* Dyadic operations. */ | |
21d799b5 NC |
20247 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
20248 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20249 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20250 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20251 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20252 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20253 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20254 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20255 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 20256 | |
c19d1205 | 20257 | /* Comparisons. */ |
21d799b5 NC |
20258 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
20259 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
20260 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
20261 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 20262 | |
c921be7d NC |
20263 | #undef ARM_VARIANT |
20264 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
20265 | ||
21d799b5 NC |
20266 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
20267 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
20268 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
20269 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 20270 | |
037e8744 JB |
20271 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
20272 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
20273 | #undef ARM_VARIANT |
20274 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
20275 | #undef THUMB_VARIANT | |
20276 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
20277 | ||
037e8744 JB |
20278 | /* These mnemonics are unique to VFP. */ |
20279 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
20280 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
20281 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
20282 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
20283 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
aacf0b33 KT |
20284 | nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), |
20285 | nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), | |
037e8744 JB |
20286 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
20287 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
20288 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
20289 | ||
20290 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
20291 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
20292 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
20293 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 20294 | |
21d799b5 NC |
20295 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
20296 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
20297 | |
20298 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
20299 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
20300 | ||
55881a11 MGD |
20301 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
20302 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
20303 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
20304 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
20305 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
20306 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
20307 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
20308 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 | 20309 | |
5f1af56b | 20310 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt), |
e3e535bc | 20311 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
c70a8987 MGD |
20312 | NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb), |
20313 | NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt), | |
f31fef98 | 20314 | |
037e8744 JB |
20315 | |
20316 | /* NOTE: All VMOV encoding is special-cased! */ | |
20317 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
20318 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
20319 | ||
9db2f6b4 RL |
20320 | #undef ARM_VARIANT |
20321 | #define ARM_VARIANT & arm_ext_fp16 | |
20322 | #undef THUMB_VARIANT | |
20323 | #define THUMB_VARIANT & arm_ext_fp16 | |
20324 | /* New instructions added from v8.2, allowing the extraction and insertion of | |
20325 | the upper 16 bits of a 32-bit vector register. */ | |
20326 | NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf), | |
20327 | NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf), | |
20328 | ||
c921be7d NC |
20329 | #undef THUMB_VARIANT |
20330 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
20331 | #undef ARM_VARIANT | |
20332 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
20333 | ||
5287ad62 JB |
20334 | /* Data processing with three registers of the same length. */ |
20335 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
20336 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
20337 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
20338 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
20339 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
20340 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
20341 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
20342 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
20343 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
20344 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
20345 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
20346 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
20347 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
20348 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
20349 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
20350 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
20351 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
20352 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
20353 | /* If not immediate, fall back to neon_dyadic_i64_su. |
20354 | shl_imm should accept I8 I16 I32 I64, | |
20355 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
20356 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
20357 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
20358 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
20359 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 20360 | /* Logic ops, types optional & ignored. */ |
4316f0d2 DG |
20361 | nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), |
20362 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20363 | nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
20364 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20365 | nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
20366 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20367 | nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
20368 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20369 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
20370 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
20371 | /* Bitfield ops, untyped. */ |
20372 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
20373 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
20374 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
20375 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
20376 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
20377 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
cc933301 | 20378 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */ |
21d799b5 NC |
20379 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
20380 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
20381 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
20382 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
20383 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
20384 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
20385 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
20386 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
20387 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
20388 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
20389 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
20390 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
20391 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
20392 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
20393 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
20394 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 20395 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
20396 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
20397 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 20398 | /* As above, D registers only. */ |
21d799b5 NC |
20399 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
20400 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 20401 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
20402 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
20403 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
20404 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 20405 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
20406 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
20407 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
20408 | /* vtst takes sizes 8, 16, 32. */ |
20409 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
20410 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
20411 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 20412 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 20413 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
20414 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
20415 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
20416 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
20417 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
20418 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
20419 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
20420 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
20421 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
20422 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
20423 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
20424 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
20425 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
20426 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
20427 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
20428 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
20429 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
d6b4b13e | 20430 | /* ARM v8.1 extension. */ |
643afb90 MW |
20431 | nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), |
20432 | nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
20433 | nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah), | |
20434 | nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah), | |
5287ad62 JB |
20435 | |
20436 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 20437 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
20438 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
20439 | ||
20440 | /* Data processing with two registers and a shift amount. */ | |
20441 | /* Right shifts, and variants with rounding. | |
20442 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
20443 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
20444 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
20445 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
20446 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
20447 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
20448 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
20449 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
20450 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
20451 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
20452 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
20453 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
20454 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
20455 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
20456 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
20457 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
20458 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
20459 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
20460 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
20461 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
20462 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
20463 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
20464 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
20465 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
20466 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
20467 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
20468 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
20469 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 20470 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 20471 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 20472 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 20473 | |
4316f0d2 DG |
20474 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn), |
20475 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), | |
5287ad62 JB |
20476 | |
20477 | /* Data processing, three registers of different lengths. */ | |
20478 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
20479 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
20480 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
20481 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
20482 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
20483 | /* If not scalar, fall back to neon_dyadic_long. | |
20484 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
20485 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
20486 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
20487 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
20488 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
20489 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
20490 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
20491 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20492 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20493 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20494 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20495 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
20496 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
20497 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
20498 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
20499 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
20500 | S16 S32 U16 U32. */ | |
21d799b5 | 20501 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
20502 | |
20503 | /* Extract. Size 8. */ | |
3b8d421e PB |
20504 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
20505 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
20506 | |
20507 | /* Two registers, miscellaneous. */ | |
20508 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
20509 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
20510 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
20511 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
20512 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
20513 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
20514 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
20515 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
20516 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
20517 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
20518 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
20519 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
20520 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 20521 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 20522 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 20523 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 20524 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 20525 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
20526 | /* VZIP / VUZP. Sizes 8 16 32. */ |
20527 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
20528 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
20529 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
20530 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
20531 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
20532 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
20533 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
20534 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
20535 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
20536 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
20537 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
20538 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
20539 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
20540 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
cc933301 | 20541 | /* Reciprocal estimates. Types U32 F16 F32. */ |
5287ad62 JB |
20542 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), |
20543 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
20544 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
20545 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
20546 | /* VCLS. Types S8 S16 S32. */ | |
20547 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
20548 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
20549 | /* VCLZ. Types I8 I16 I32. */ | |
20550 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
20551 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
20552 | /* VCNT. Size 8. */ | |
20553 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
20554 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
20555 | /* Two address, untyped. */ | |
20556 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
20557 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
20558 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
20559 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
20560 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
20561 | |
20562 | /* Table lookup. Size 8. */ | |
20563 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
20564 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
20565 | ||
c921be7d NC |
20566 | #undef THUMB_VARIANT |
20567 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
20568 | #undef ARM_VARIANT | |
20569 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
20570 | ||
5287ad62 | 20571 | /* Neon element/structure load/store. */ |
21d799b5 NC |
20572 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
20573 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20574 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20575 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20576 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20577 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20578 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20579 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 20580 | |
c921be7d | 20581 | #undef THUMB_VARIANT |
74db7efb NC |
20582 | #define THUMB_VARIANT & fpu_vfp_ext_v3xd |
20583 | #undef ARM_VARIANT | |
20584 | #define ARM_VARIANT & fpu_vfp_ext_v3xd | |
62f3b8c8 PB |
20585 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), |
20586 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20587 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20588 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20589 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20590 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20591 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20592 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20593 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20594 | ||
74db7efb | 20595 | #undef THUMB_VARIANT |
c921be7d NC |
20596 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
20597 | #undef ARM_VARIANT | |
20598 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
20599 | ||
21d799b5 | 20600 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 20601 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20602 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 20603 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20604 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 20605 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20606 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 20607 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20608 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 20609 | |
74db7efb NC |
20610 | #undef ARM_VARIANT |
20611 | #define ARM_VARIANT & fpu_vfp_ext_fma | |
20612 | #undef THUMB_VARIANT | |
20613 | #define THUMB_VARIANT & fpu_vfp_ext_fma | |
62f3b8c8 PB |
20614 | /* Mnemonics shared by Neon and VFP. These are included in the |
20615 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
20616 | FMA instructions. */ | |
20617 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
20618 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
20619 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
20620 | the v form should always be used. */ | |
20621 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20622 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20623 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20624 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20625 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
20626 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
20627 | ||
5287ad62 | 20628 | #undef THUMB_VARIANT |
c921be7d NC |
20629 | #undef ARM_VARIANT |
20630 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
20631 | ||
21d799b5 NC |
20632 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
20633 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20634 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20635 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20636 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20637 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20638 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
20639 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 20640 | |
c921be7d NC |
20641 | #undef ARM_VARIANT |
20642 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
20643 | ||
21d799b5 NC |
20644 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
20645 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
20646 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
20647 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
20648 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
20649 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
20650 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
20651 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
20652 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
74db7efb NC |
20653 | cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), |
20654 | cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20655 | cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20656 | cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20657 | cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20658 | cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21d799b5 NC |
20659 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), |
20660 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
20661 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
20662 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
20663 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
20664 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20665 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20666 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20667 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20668 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20669 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
74db7efb NC |
20670 | cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn), |
20671 | cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn), | |
20672 | cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn), | |
21d799b5 NC |
20673 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), |
20674 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
20675 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
20676 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
20677 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
20678 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
20679 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
20680 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
20681 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20682 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20683 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20684 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20685 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20686 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20687 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20688 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20689 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20690 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
74db7efb NC |
20691 | cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20692 | cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20693 | cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20694 | cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
20695 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20696 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20697 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20698 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20699 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20700 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20701 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20702 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20703 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
20704 | cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20705 | cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20706 | cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20707 | cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20708 | cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20709 | cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
20710 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), |
20711 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
20712 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
20713 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
20714 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20715 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20716 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20717 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20718 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20719 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20720 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20721 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20722 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20723 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20724 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20725 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20726 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20727 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20728 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20729 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20730 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20731 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20732 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
20733 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20734 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20735 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20736 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20737 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
20738 | cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20739 | cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20740 | cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20741 | cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20742 | cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20743 | cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
20744 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
20745 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20746 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20747 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20748 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20749 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20750 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20751 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20752 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20753 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20754 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
20755 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20756 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20757 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20758 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20759 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20760 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20761 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20762 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20763 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20764 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20765 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20766 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20767 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20768 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20769 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20770 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20771 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20772 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20773 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
20774 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
20775 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
20776 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
20777 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20778 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20779 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20780 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20781 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20782 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20783 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20784 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20785 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20786 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
20787 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
20788 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
20789 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
20790 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
20791 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
20792 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20793 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20794 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20795 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
20796 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
20797 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
20798 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
20799 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
20800 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
20801 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20802 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20803 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20804 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20805 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 20806 | |
c921be7d NC |
20807 | #undef ARM_VARIANT |
20808 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
20809 | ||
21d799b5 NC |
20810 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
20811 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
20812 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
20813 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
20814 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
20815 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
20816 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20817 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20818 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20819 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20820 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20821 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20822 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20823 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20824 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20825 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20826 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20827 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20828 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20829 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20830 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
20831 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20832 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20833 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20834 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20835 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20836 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20837 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20838 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20839 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20840 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20841 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20842 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20843 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20844 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20845 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20846 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20847 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20848 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20849 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20850 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20851 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20852 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20853 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20854 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20855 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20856 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20857 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20858 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20859 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20860 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20861 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20862 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20863 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20864 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20865 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20866 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 20867 | |
c921be7d NC |
20868 | #undef ARM_VARIANT |
20869 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
20870 | ||
21d799b5 NC |
20871 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
20872 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
20873 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
20874 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
20875 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
20876 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
20877 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
20878 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
20879 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
20880 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
20881 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
20882 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
20883 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
20884 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
74db7efb NC |
20885 | cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd), |
20886 | cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn), | |
20887 | cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd), | |
20888 | cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn), | |
20889 | cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn), | |
20890 | cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn), | |
20891 | cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn), | |
20892 | cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn), | |
20893 | cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn), | |
20894 | cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn), | |
21d799b5 NC |
20895 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), |
20896 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
20897 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
20898 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
74db7efb NC |
20899 | cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc), |
20900 | cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd), | |
21d799b5 NC |
20901 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), |
20902 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
20903 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
20904 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
74db7efb NC |
20905 | cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn), |
20906 | cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn), | |
20907 | cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn), | |
20908 | cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn), | |
20909 | cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn), | |
20910 | cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn), | |
21d799b5 NC |
20911 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), |
20912 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
74db7efb NC |
20913 | cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple), |
20914 | cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
21d799b5 NC |
20915 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), |
20916 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
20917 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
20918 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
20919 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
20920 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
20921 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
20922 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
20923 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
20924 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
20925 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
20926 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
20927 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
20928 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
20929 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
20930 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
20931 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
20932 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
20933 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
20934 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
20935 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20936 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
20937 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20938 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
20939 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20940 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
20941 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20942 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
74db7efb NC |
20943 | cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), |
20944 | cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
21d799b5 NC |
20945 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), |
20946 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
4ed7ed8d TP |
20947 | |
20948 | #undef ARM_VARIANT | |
20949 | #define ARM_VARIANT NULL | |
20950 | #undef THUMB_VARIANT | |
20951 | #define THUMB_VARIANT & arm_ext_v8m | |
20952 | TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt), | |
20953 | TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt), | |
c19d1205 ZW |
20954 | }; |
20955 | #undef ARM_VARIANT | |
20956 | #undef THUMB_VARIANT | |
20957 | #undef TCE | |
c19d1205 ZW |
20958 | #undef TUE |
20959 | #undef TUF | |
20960 | #undef TCC | |
8f06b2d8 | 20961 | #undef cCE |
e3cb604e PB |
20962 | #undef cCL |
20963 | #undef C3E | |
c19d1205 ZW |
20964 | #undef CE |
20965 | #undef CM | |
20966 | #undef UE | |
20967 | #undef UF | |
20968 | #undef UT | |
5287ad62 JB |
20969 | #undef NUF |
20970 | #undef nUF | |
20971 | #undef NCE | |
20972 | #undef nCE | |
c19d1205 ZW |
20973 | #undef OPS0 |
20974 | #undef OPS1 | |
20975 | #undef OPS2 | |
20976 | #undef OPS3 | |
20977 | #undef OPS4 | |
20978 | #undef OPS5 | |
20979 | #undef OPS6 | |
20980 | #undef do_0 | |
20981 | \f | |
20982 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 20983 | |
c19d1205 ZW |
20984 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
20985 | for use in the a.out file, and stores them in the array pointed to by buf. | |
20986 | This knows about the endian-ness of the target machine and does | |
20987 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
20988 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
20989 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 20990 | |
c19d1205 ZW |
20991 | void |
20992 | md_number_to_chars (char * buf, valueT val, int n) | |
20993 | { | |
20994 | if (target_big_endian) | |
20995 | number_to_chars_bigendian (buf, val, n); | |
20996 | else | |
20997 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
20998 | } |
20999 | ||
c19d1205 ZW |
21000 | static valueT |
21001 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 21002 | { |
c19d1205 ZW |
21003 | valueT result = 0; |
21004 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 21005 | |
c19d1205 | 21006 | if (target_big_endian) |
b99bd4ef | 21007 | { |
c19d1205 ZW |
21008 | while (n--) |
21009 | { | |
21010 | result <<= 8; | |
21011 | result |= (*where++ & 255); | |
21012 | } | |
b99bd4ef | 21013 | } |
c19d1205 | 21014 | else |
b99bd4ef | 21015 | { |
c19d1205 ZW |
21016 | while (n--) |
21017 | { | |
21018 | result <<= 8; | |
21019 | result |= (where[n] & 255); | |
21020 | } | |
bfae80f2 | 21021 | } |
b99bd4ef | 21022 | |
c19d1205 | 21023 | return result; |
bfae80f2 | 21024 | } |
b99bd4ef | 21025 | |
c19d1205 | 21026 | /* MD interface: Sections. */ |
b99bd4ef | 21027 | |
fa94de6b RM |
21028 | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
21029 | that an rs_machine_dependent frag may reach. */ | |
21030 | ||
21031 | unsigned int | |
21032 | arm_frag_max_var (fragS *fragp) | |
21033 | { | |
21034 | /* We only use rs_machine_dependent for variable-size Thumb instructions, | |
21035 | which are either THUMB_SIZE (2) or INSN_SIZE (4). | |
21036 | ||
21037 | Note that we generate relaxable instructions even for cases that don't | |
21038 | really need it, like an immediate that's a trivial constant. So we're | |
21039 | overestimating the instruction size for some of those cases. Rather | |
21040 | than putting more intelligence here, it would probably be better to | |
21041 | avoid generating a relaxation frag in the first place when it can be | |
21042 | determined up front that a short instruction will suffice. */ | |
21043 | ||
21044 | gas_assert (fragp->fr_type == rs_machine_dependent); | |
21045 | return INSN_SIZE; | |
21046 | } | |
21047 | ||
0110f2b8 PB |
21048 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
21049 | 2 bytes. */ | |
21050 | ||
c19d1205 | 21051 | int |
0110f2b8 | 21052 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
21053 | segT segtype ATTRIBUTE_UNUSED) |
21054 | { | |
0110f2b8 PB |
21055 | fragp->fr_var = 2; |
21056 | return 2; | |
21057 | } | |
21058 | ||
21059 | /* Convert a machine dependent frag. */ | |
21060 | ||
21061 | void | |
21062 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
21063 | { | |
21064 | unsigned long insn; | |
21065 | unsigned long old_op; | |
21066 | char *buf; | |
21067 | expressionS exp; | |
21068 | fixS *fixp; | |
21069 | int reloc_type; | |
21070 | int pc_rel; | |
21071 | int opcode; | |
21072 | ||
21073 | buf = fragp->fr_literal + fragp->fr_fix; | |
21074 | ||
21075 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
21076 | if (fragp->fr_symbol) |
21077 | { | |
0110f2b8 PB |
21078 | exp.X_op = O_symbol; |
21079 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
21080 | } |
21081 | else | |
21082 | { | |
0110f2b8 | 21083 | exp.X_op = O_constant; |
5f4273c7 | 21084 | } |
0110f2b8 PB |
21085 | exp.X_add_number = fragp->fr_offset; |
21086 | opcode = fragp->fr_subtype; | |
21087 | switch (opcode) | |
21088 | { | |
21089 | case T_MNEM_ldr_pc: | |
21090 | case T_MNEM_ldr_pc2: | |
21091 | case T_MNEM_ldr_sp: | |
21092 | case T_MNEM_str_sp: | |
21093 | case T_MNEM_ldr: | |
21094 | case T_MNEM_ldrb: | |
21095 | case T_MNEM_ldrh: | |
21096 | case T_MNEM_str: | |
21097 | case T_MNEM_strb: | |
21098 | case T_MNEM_strh: | |
21099 | if (fragp->fr_var == 4) | |
21100 | { | |
5f4273c7 | 21101 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
21102 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
21103 | { | |
21104 | insn |= (old_op & 0x700) << 4; | |
21105 | } | |
21106 | else | |
21107 | { | |
21108 | insn |= (old_op & 7) << 12; | |
21109 | insn |= (old_op & 0x38) << 13; | |
21110 | } | |
21111 | insn |= 0x00000c00; | |
21112 | put_thumb32_insn (buf, insn); | |
21113 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
21114 | } | |
21115 | else | |
21116 | { | |
21117 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
21118 | } | |
21119 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
21120 | break; | |
21121 | case T_MNEM_adr: | |
21122 | if (fragp->fr_var == 4) | |
21123 | { | |
21124 | insn = THUMB_OP32 (opcode); | |
21125 | insn |= (old_op & 0xf0) << 4; | |
21126 | put_thumb32_insn (buf, insn); | |
21127 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
21128 | } | |
21129 | else | |
21130 | { | |
21131 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
21132 | exp.X_add_number -= 4; | |
21133 | } | |
21134 | pc_rel = 1; | |
21135 | break; | |
21136 | case T_MNEM_mov: | |
21137 | case T_MNEM_movs: | |
21138 | case T_MNEM_cmp: | |
21139 | case T_MNEM_cmn: | |
21140 | if (fragp->fr_var == 4) | |
21141 | { | |
21142 | int r0off = (opcode == T_MNEM_mov | |
21143 | || opcode == T_MNEM_movs) ? 0 : 8; | |
21144 | insn = THUMB_OP32 (opcode); | |
21145 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
21146 | insn |= (old_op & 0x700) << r0off; | |
21147 | put_thumb32_insn (buf, insn); | |
21148 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
21149 | } | |
21150 | else | |
21151 | { | |
21152 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
21153 | } | |
21154 | pc_rel = 0; | |
21155 | break; | |
21156 | case T_MNEM_b: | |
21157 | if (fragp->fr_var == 4) | |
21158 | { | |
21159 | insn = THUMB_OP32(opcode); | |
21160 | put_thumb32_insn (buf, insn); | |
21161 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
21162 | } | |
21163 | else | |
21164 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
21165 | pc_rel = 1; | |
21166 | break; | |
21167 | case T_MNEM_bcond: | |
21168 | if (fragp->fr_var == 4) | |
21169 | { | |
21170 | insn = THUMB_OP32(opcode); | |
21171 | insn |= (old_op & 0xf00) << 14; | |
21172 | put_thumb32_insn (buf, insn); | |
21173 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
21174 | } | |
21175 | else | |
21176 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
21177 | pc_rel = 1; | |
21178 | break; | |
21179 | case T_MNEM_add_sp: | |
21180 | case T_MNEM_add_pc: | |
21181 | case T_MNEM_inc_sp: | |
21182 | case T_MNEM_dec_sp: | |
21183 | if (fragp->fr_var == 4) | |
21184 | { | |
21185 | /* ??? Choose between add and addw. */ | |
21186 | insn = THUMB_OP32 (opcode); | |
21187 | insn |= (old_op & 0xf0) << 4; | |
21188 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
21189 | if (opcode == T_MNEM_add_pc) |
21190 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
21191 | else | |
21192 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
21193 | } |
21194 | else | |
21195 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
21196 | pc_rel = 0; | |
21197 | break; | |
21198 | ||
21199 | case T_MNEM_addi: | |
21200 | case T_MNEM_addis: | |
21201 | case T_MNEM_subi: | |
21202 | case T_MNEM_subis: | |
21203 | if (fragp->fr_var == 4) | |
21204 | { | |
21205 | insn = THUMB_OP32 (opcode); | |
21206 | insn |= (old_op & 0xf0) << 4; | |
21207 | insn |= (old_op & 0xf) << 16; | |
21208 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
21209 | if (insn & (1 << 20)) |
21210 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
21211 | else | |
21212 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
21213 | } |
21214 | else | |
21215 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
21216 | pc_rel = 0; | |
21217 | break; | |
21218 | default: | |
5f4273c7 | 21219 | abort (); |
0110f2b8 PB |
21220 | } |
21221 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 21222 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
21223 | fixp->fx_file = fragp->fr_file; |
21224 | fixp->fx_line = fragp->fr_line; | |
21225 | fragp->fr_fix += fragp->fr_var; | |
3cfdb781 TG |
21226 | |
21227 | /* Set whether we use thumb-2 ISA based on final relaxation results. */ | |
21228 | if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected () | |
21229 | && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2)) | |
21230 | ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2); | |
0110f2b8 PB |
21231 | } |
21232 | ||
21233 | /* Return the size of a relaxable immediate operand instruction. | |
21234 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
21235 | static int | |
21236 | relax_immediate (fragS *fragp, int size, int shift) | |
21237 | { | |
21238 | offsetT offset; | |
21239 | offsetT mask; | |
21240 | offsetT low; | |
21241 | ||
21242 | /* ??? Should be able to do better than this. */ | |
21243 | if (fragp->fr_symbol) | |
21244 | return 4; | |
21245 | ||
21246 | low = (1 << shift) - 1; | |
21247 | mask = (1 << (shift + size)) - (1 << shift); | |
21248 | offset = fragp->fr_offset; | |
21249 | /* Force misaligned offsets to 32-bit variant. */ | |
21250 | if (offset & low) | |
5e77afaa | 21251 | return 4; |
0110f2b8 PB |
21252 | if (offset & ~mask) |
21253 | return 4; | |
21254 | return 2; | |
21255 | } | |
21256 | ||
5e77afaa PB |
21257 | /* Get the address of a symbol during relaxation. */ |
21258 | static addressT | |
5f4273c7 | 21259 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
21260 | { |
21261 | fragS *sym_frag; | |
21262 | addressT addr; | |
21263 | symbolS *sym; | |
21264 | ||
21265 | sym = fragp->fr_symbol; | |
21266 | sym_frag = symbol_get_frag (sym); | |
21267 | know (S_GET_SEGMENT (sym) != absolute_section | |
21268 | || sym_frag == &zero_address_frag); | |
21269 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
21270 | ||
21271 | /* If frag has yet to be reached on this pass, assume it will | |
21272 | move by STRETCH just as we did. If this is not so, it will | |
21273 | be because some frag between grows, and that will force | |
21274 | another pass. */ | |
21275 | ||
21276 | if (stretch != 0 | |
21277 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
21278 | { |
21279 | fragS *f; | |
21280 | ||
21281 | /* Adjust stretch for any alignment frag. Note that if have | |
21282 | been expanding the earlier code, the symbol may be | |
21283 | defined in what appears to be an earlier frag. FIXME: | |
21284 | This doesn't handle the fr_subtype field, which specifies | |
21285 | a maximum number of bytes to skip when doing an | |
21286 | alignment. */ | |
21287 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
21288 | { | |
21289 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
21290 | { | |
21291 | if (stretch < 0) | |
21292 | stretch = - ((- stretch) | |
21293 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
21294 | else | |
21295 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
21296 | if (stretch == 0) | |
21297 | break; | |
21298 | } | |
21299 | } | |
21300 | if (f != NULL) | |
21301 | addr += stretch; | |
21302 | } | |
5e77afaa PB |
21303 | |
21304 | return addr; | |
21305 | } | |
21306 | ||
0110f2b8 PB |
21307 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
21308 | load. */ | |
21309 | static int | |
5e77afaa | 21310 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
21311 | { |
21312 | addressT addr; | |
21313 | offsetT val; | |
21314 | ||
21315 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
21316 | if (fragp->fr_symbol == NULL |
21317 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
21318 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
21319 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
21320 | return 4; |
21321 | ||
5f4273c7 | 21322 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
21323 | addr = fragp->fr_address + fragp->fr_fix; |
21324 | addr = (addr + 4) & ~3; | |
5e77afaa | 21325 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 21326 | if (val & 3) |
5e77afaa | 21327 | return 4; |
0110f2b8 PB |
21328 | val -= addr; |
21329 | if (val < 0 || val > 1020) | |
21330 | return 4; | |
21331 | return 2; | |
21332 | } | |
21333 | ||
21334 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
21335 | static int | |
21336 | relax_addsub (fragS *fragp, asection *sec) | |
21337 | { | |
21338 | char *buf; | |
21339 | int op; | |
21340 | ||
21341 | buf = fragp->fr_literal + fragp->fr_fix; | |
21342 | op = bfd_get_16(sec->owner, buf); | |
21343 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
21344 | return relax_immediate (fragp, 8, 0); | |
21345 | else | |
21346 | return relax_immediate (fragp, 3, 0); | |
21347 | } | |
21348 | ||
e83a675f RE |
21349 | /* Return TRUE iff the definition of symbol S could be pre-empted |
21350 | (overridden) at link or load time. */ | |
21351 | static bfd_boolean | |
21352 | symbol_preemptible (symbolS *s) | |
21353 | { | |
21354 | /* Weak symbols can always be pre-empted. */ | |
21355 | if (S_IS_WEAK (s)) | |
21356 | return TRUE; | |
21357 | ||
21358 | /* Non-global symbols cannot be pre-empted. */ | |
21359 | if (! S_IS_EXTERNAL (s)) | |
21360 | return FALSE; | |
21361 | ||
21362 | #ifdef OBJ_ELF | |
21363 | /* In ELF, a global symbol can be marked protected, or private. In that | |
21364 | case it can't be pre-empted (other definitions in the same link unit | |
21365 | would violate the ODR). */ | |
21366 | if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT) | |
21367 | return FALSE; | |
21368 | #endif | |
21369 | ||
21370 | /* Other global symbols might be pre-empted. */ | |
21371 | return TRUE; | |
21372 | } | |
0110f2b8 PB |
21373 | |
21374 | /* Return the size of a relaxable branch instruction. BITS is the | |
21375 | size of the offset field in the narrow instruction. */ | |
21376 | ||
21377 | static int | |
5e77afaa | 21378 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
21379 | { |
21380 | addressT addr; | |
21381 | offsetT val; | |
21382 | offsetT limit; | |
21383 | ||
21384 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 21385 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
21386 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
21387 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
21388 | return 4; |
21389 | ||
267bf995 | 21390 | #ifdef OBJ_ELF |
e83a675f | 21391 | /* A branch to a function in ARM state will require interworking. */ |
267bf995 RR |
21392 | if (S_IS_DEFINED (fragp->fr_symbol) |
21393 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
21394 | return 4; | |
e83a675f | 21395 | #endif |
0d9b4b55 | 21396 | |
e83a675f | 21397 | if (symbol_preemptible (fragp->fr_symbol)) |
0d9b4b55 | 21398 | return 4; |
267bf995 | 21399 | |
5f4273c7 | 21400 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
21401 | addr = fragp->fr_address + fragp->fr_fix + 4; |
21402 | val -= addr; | |
21403 | ||
21404 | /* Offset is a signed value *2 */ | |
21405 | limit = 1 << bits; | |
21406 | if (val >= limit || val < -limit) | |
21407 | return 4; | |
21408 | return 2; | |
21409 | } | |
21410 | ||
21411 | ||
21412 | /* Relax a machine dependent frag. This returns the amount by which | |
21413 | the current size of the frag should change. */ | |
21414 | ||
21415 | int | |
5e77afaa | 21416 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
21417 | { |
21418 | int oldsize; | |
21419 | int newsize; | |
21420 | ||
21421 | oldsize = fragp->fr_var; | |
21422 | switch (fragp->fr_subtype) | |
21423 | { | |
21424 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 21425 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
21426 | break; |
21427 | case T_MNEM_ldr_pc: | |
21428 | case T_MNEM_ldr_sp: | |
21429 | case T_MNEM_str_sp: | |
5f4273c7 | 21430 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
21431 | break; |
21432 | case T_MNEM_ldr: | |
21433 | case T_MNEM_str: | |
5f4273c7 | 21434 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
21435 | break; |
21436 | case T_MNEM_ldrh: | |
21437 | case T_MNEM_strh: | |
5f4273c7 | 21438 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
21439 | break; |
21440 | case T_MNEM_ldrb: | |
21441 | case T_MNEM_strb: | |
5f4273c7 | 21442 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
21443 | break; |
21444 | case T_MNEM_adr: | |
5f4273c7 | 21445 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
21446 | break; |
21447 | case T_MNEM_mov: | |
21448 | case T_MNEM_movs: | |
21449 | case T_MNEM_cmp: | |
21450 | case T_MNEM_cmn: | |
5f4273c7 | 21451 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
21452 | break; |
21453 | case T_MNEM_b: | |
5f4273c7 | 21454 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
21455 | break; |
21456 | case T_MNEM_bcond: | |
5f4273c7 | 21457 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
21458 | break; |
21459 | case T_MNEM_add_sp: | |
21460 | case T_MNEM_add_pc: | |
21461 | newsize = relax_immediate (fragp, 8, 2); | |
21462 | break; | |
21463 | case T_MNEM_inc_sp: | |
21464 | case T_MNEM_dec_sp: | |
21465 | newsize = relax_immediate (fragp, 7, 2); | |
21466 | break; | |
21467 | case T_MNEM_addi: | |
21468 | case T_MNEM_addis: | |
21469 | case T_MNEM_subi: | |
21470 | case T_MNEM_subis: | |
21471 | newsize = relax_addsub (fragp, sec); | |
21472 | break; | |
21473 | default: | |
5f4273c7 | 21474 | abort (); |
0110f2b8 | 21475 | } |
5e77afaa PB |
21476 | |
21477 | fragp->fr_var = newsize; | |
21478 | /* Freeze wide instructions that are at or before the same location as | |
21479 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
21480 | Don't freeze them unconditionally because targets may be artificially |
21481 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 21482 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 21483 | { |
0110f2b8 | 21484 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 21485 | frag_wane (fragp); |
0110f2b8 | 21486 | } |
5e77afaa | 21487 | |
0110f2b8 | 21488 | return newsize - oldsize; |
c19d1205 | 21489 | } |
b99bd4ef | 21490 | |
c19d1205 | 21491 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 21492 | |
c19d1205 ZW |
21493 | valueT |
21494 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
21495 | valueT size) | |
21496 | { | |
f0927246 NC |
21497 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
21498 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
21499 | { | |
21500 | /* For a.out, force the section size to be aligned. If we don't do | |
21501 | this, BFD will align it for us, but it will not write out the | |
21502 | final bytes of the section. This may be a bug in BFD, but it is | |
21503 | easier to fix it here since that is how the other a.out targets | |
21504 | work. */ | |
21505 | int align; | |
21506 | ||
21507 | align = bfd_get_section_alignment (stdoutput, segment); | |
8d3842cd | 21508 | size = ((size + (1 << align) - 1) & (-((valueT) 1 << align))); |
f0927246 | 21509 | } |
c19d1205 | 21510 | #endif |
f0927246 NC |
21511 | |
21512 | return size; | |
bfae80f2 | 21513 | } |
b99bd4ef | 21514 | |
c19d1205 ZW |
21515 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
21516 | of an rs_align_code fragment. */ | |
21517 | ||
21518 | void | |
21519 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 21520 | { |
e7495e45 NS |
21521 | static char const arm_noop[2][2][4] = |
21522 | { | |
21523 | { /* ARMv1 */ | |
21524 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
21525 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
21526 | }, | |
21527 | { /* ARMv6k */ | |
21528 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
21529 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
21530 | }, | |
21531 | }; | |
21532 | static char const thumb_noop[2][2][2] = | |
21533 | { | |
21534 | { /* Thumb-1 */ | |
21535 | {0xc0, 0x46}, /* LE */ | |
21536 | {0x46, 0xc0}, /* BE */ | |
21537 | }, | |
21538 | { /* Thumb-2 */ | |
21539 | {0x00, 0xbf}, /* LE */ | |
21540 | {0xbf, 0x00} /* BE */ | |
21541 | } | |
21542 | }; | |
21543 | static char const wide_thumb_noop[2][4] = | |
21544 | { /* Wide Thumb-2 */ | |
21545 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
21546 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
21547 | }; | |
c921be7d | 21548 | |
e7495e45 | 21549 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
21550 | char * p; |
21551 | const char * noop; | |
e7495e45 | 21552 | const char *narrow_noop = NULL; |
cd000bff DJ |
21553 | #ifdef OBJ_ELF |
21554 | enum mstate state; | |
21555 | #endif | |
bfae80f2 | 21556 | |
c19d1205 | 21557 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
21558 | return; |
21559 | ||
c19d1205 ZW |
21560 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
21561 | p = fragP->fr_literal + fragP->fr_fix; | |
21562 | fix = 0; | |
bfae80f2 | 21563 | |
c19d1205 ZW |
21564 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
21565 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 21566 | |
cd000bff | 21567 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 21568 | |
cd000bff | 21569 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 21570 | { |
7f78eb34 JW |
21571 | if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
21572 | ? selected_cpu : arm_arch_none, arm_ext_v6t2)) | |
e7495e45 NS |
21573 | { |
21574 | narrow_noop = thumb_noop[1][target_big_endian]; | |
21575 | noop = wide_thumb_noop[target_big_endian]; | |
21576 | } | |
c19d1205 | 21577 | else |
e7495e45 NS |
21578 | noop = thumb_noop[0][target_big_endian]; |
21579 | noop_size = 2; | |
cd000bff DJ |
21580 | #ifdef OBJ_ELF |
21581 | state = MAP_THUMB; | |
21582 | #endif | |
7ed4c4c5 NC |
21583 | } |
21584 | else | |
21585 | { | |
7f78eb34 JW |
21586 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
21587 | ? selected_cpu : arm_arch_none, | |
21588 | arm_ext_v6k) != 0] | |
e7495e45 NS |
21589 | [target_big_endian]; |
21590 | noop_size = 4; | |
cd000bff DJ |
21591 | #ifdef OBJ_ELF |
21592 | state = MAP_ARM; | |
21593 | #endif | |
7ed4c4c5 | 21594 | } |
c921be7d | 21595 | |
e7495e45 | 21596 | fragP->fr_var = noop_size; |
c921be7d | 21597 | |
c19d1205 | 21598 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 21599 | { |
c19d1205 | 21600 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
21601 | #ifdef OBJ_ELF |
21602 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
21603 | #endif | |
c19d1205 ZW |
21604 | memset (p, 0, fix); |
21605 | p += fix; | |
21606 | bytes -= fix; | |
a737bd4d | 21607 | } |
a737bd4d | 21608 | |
e7495e45 NS |
21609 | if (narrow_noop) |
21610 | { | |
21611 | if (bytes & noop_size) | |
21612 | { | |
21613 | /* Insert a narrow noop. */ | |
21614 | memcpy (p, narrow_noop, noop_size); | |
21615 | p += noop_size; | |
21616 | bytes -= noop_size; | |
21617 | fix += noop_size; | |
21618 | } | |
21619 | ||
21620 | /* Use wide noops for the remainder */ | |
21621 | noop_size = 4; | |
21622 | } | |
21623 | ||
c19d1205 | 21624 | while (bytes >= noop_size) |
a737bd4d | 21625 | { |
c19d1205 ZW |
21626 | memcpy (p, noop, noop_size); |
21627 | p += noop_size; | |
21628 | bytes -= noop_size; | |
21629 | fix += noop_size; | |
a737bd4d NC |
21630 | } |
21631 | ||
c19d1205 | 21632 | fragP->fr_fix += fix; |
a737bd4d NC |
21633 | } |
21634 | ||
c19d1205 ZW |
21635 | /* Called from md_do_align. Used to create an alignment |
21636 | frag in a code section. */ | |
21637 | ||
21638 | void | |
21639 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 21640 | { |
c19d1205 | 21641 | char * p; |
7ed4c4c5 | 21642 | |
c19d1205 | 21643 | /* We assume that there will never be a requirement |
6ec8e702 | 21644 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 21645 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
21646 | { |
21647 | char err_msg[128]; | |
21648 | ||
fa94de6b | 21649 | sprintf (err_msg, |
477330fc RM |
21650 | _("alignments greater than %d bytes not supported in .text sections."), |
21651 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 21652 | as_fatal ("%s", err_msg); |
6ec8e702 | 21653 | } |
bfae80f2 | 21654 | |
c19d1205 ZW |
21655 | p = frag_var (rs_align_code, |
21656 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
21657 | 1, | |
21658 | (relax_substateT) max, | |
21659 | (symbolS *) NULL, | |
21660 | (offsetT) n, | |
21661 | (char *) NULL); | |
21662 | *p = 0; | |
21663 | } | |
bfae80f2 | 21664 | |
8dc2430f NC |
21665 | /* Perform target specific initialisation of a frag. |
21666 | Note - despite the name this initialisation is not done when the frag | |
21667 | is created, but only when its type is assigned. A frag can be created | |
21668 | and used a long time before its type is set, so beware of assuming that | |
21669 | this initialisationis performed first. */ | |
bfae80f2 | 21670 | |
cd000bff DJ |
21671 | #ifndef OBJ_ELF |
21672 | void | |
21673 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
21674 | { | |
21675 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 21676 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
21677 | } |
21678 | ||
21679 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 21680 | void |
cd000bff | 21681 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 21682 | { |
b968d18a JW |
21683 | int frag_thumb_mode; |
21684 | ||
8dc2430f NC |
21685 | /* If the current ARM vs THUMB mode has not already |
21686 | been recorded into this frag then do so now. */ | |
cd000bff | 21687 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
b968d18a JW |
21688 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
21689 | ||
21690 | frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED; | |
cd000bff | 21691 | |
f9c1b181 RL |
21692 | /* Record a mapping symbol for alignment frags. We will delete this |
21693 | later if the alignment ends up empty. */ | |
21694 | switch (fragP->fr_type) | |
21695 | { | |
21696 | case rs_align: | |
21697 | case rs_align_test: | |
21698 | case rs_fill: | |
21699 | mapping_state_2 (MAP_DATA, max_chars); | |
21700 | break; | |
21701 | case rs_align_code: | |
b968d18a | 21702 | mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); |
f9c1b181 RL |
21703 | break; |
21704 | default: | |
21705 | break; | |
cd000bff | 21706 | } |
bfae80f2 RE |
21707 | } |
21708 | ||
c19d1205 ZW |
21709 | /* When we change sections we need to issue a new mapping symbol. */ |
21710 | ||
21711 | void | |
21712 | arm_elf_change_section (void) | |
bfae80f2 | 21713 | { |
c19d1205 ZW |
21714 | /* Link an unlinked unwind index table section to the .text section. */ |
21715 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
21716 | && elf_linked_to_section (now_seg) == NULL) | |
21717 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
21718 | } |
21719 | ||
c19d1205 ZW |
21720 | int |
21721 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 21722 | { |
c19d1205 ZW |
21723 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
21724 | return SHT_ARM_EXIDX; | |
e45d0630 | 21725 | |
c19d1205 ZW |
21726 | return -1; |
21727 | } | |
21728 | \f | |
21729 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 21730 | |
c19d1205 | 21731 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 21732 | |
5f4273c7 | 21733 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 21734 | |
bfae80f2 | 21735 | static void |
c19d1205 | 21736 | flush_pending_unwind (void) |
bfae80f2 | 21737 | { |
c19d1205 | 21738 | offsetT offset; |
bfae80f2 | 21739 | |
c19d1205 ZW |
21740 | offset = unwind.pending_offset; |
21741 | unwind.pending_offset = 0; | |
21742 | if (offset != 0) | |
21743 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
21744 | } |
21745 | ||
c19d1205 ZW |
21746 | /* Add an opcode to this list for this function. Two-byte opcodes should |
21747 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
21748 | order. */ | |
21749 | ||
bfae80f2 | 21750 | static void |
c19d1205 | 21751 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 21752 | { |
c19d1205 ZW |
21753 | /* Add any deferred stack adjustment. */ |
21754 | if (unwind.pending_offset) | |
21755 | flush_pending_unwind (); | |
bfae80f2 | 21756 | |
c19d1205 | 21757 | unwind.sp_restored = 0; |
bfae80f2 | 21758 | |
c19d1205 | 21759 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 21760 | { |
c19d1205 ZW |
21761 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
21762 | if (unwind.opcodes) | |
21d799b5 | 21763 | unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes, |
477330fc | 21764 | unwind.opcode_alloc); |
c19d1205 | 21765 | else |
21d799b5 | 21766 | unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc); |
bfae80f2 | 21767 | } |
c19d1205 | 21768 | while (length > 0) |
bfae80f2 | 21769 | { |
c19d1205 ZW |
21770 | length--; |
21771 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
21772 | op >>= 8; | |
21773 | unwind.opcode_count++; | |
bfae80f2 | 21774 | } |
bfae80f2 RE |
21775 | } |
21776 | ||
c19d1205 ZW |
21777 | /* Add unwind opcodes to adjust the stack pointer. */ |
21778 | ||
bfae80f2 | 21779 | static void |
c19d1205 | 21780 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 21781 | { |
c19d1205 | 21782 | valueT op; |
bfae80f2 | 21783 | |
c19d1205 | 21784 | if (offset > 0x200) |
bfae80f2 | 21785 | { |
c19d1205 ZW |
21786 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
21787 | char bytes[5]; | |
21788 | int n; | |
21789 | valueT o; | |
bfae80f2 | 21790 | |
c19d1205 ZW |
21791 | /* Long form: 0xb2, uleb128. */ |
21792 | /* This might not fit in a word so add the individual bytes, | |
21793 | remembering the list is built in reverse order. */ | |
21794 | o = (valueT) ((offset - 0x204) >> 2); | |
21795 | if (o == 0) | |
21796 | add_unwind_opcode (0, 1); | |
bfae80f2 | 21797 | |
c19d1205 ZW |
21798 | /* Calculate the uleb128 encoding of the offset. */ |
21799 | n = 0; | |
21800 | while (o) | |
21801 | { | |
21802 | bytes[n] = o & 0x7f; | |
21803 | o >>= 7; | |
21804 | if (o) | |
21805 | bytes[n] |= 0x80; | |
21806 | n++; | |
21807 | } | |
21808 | /* Add the insn. */ | |
21809 | for (; n; n--) | |
21810 | add_unwind_opcode (bytes[n - 1], 1); | |
21811 | add_unwind_opcode (0xb2, 1); | |
21812 | } | |
21813 | else if (offset > 0x100) | |
bfae80f2 | 21814 | { |
c19d1205 ZW |
21815 | /* Two short opcodes. */ |
21816 | add_unwind_opcode (0x3f, 1); | |
21817 | op = (offset - 0x104) >> 2; | |
21818 | add_unwind_opcode (op, 1); | |
bfae80f2 | 21819 | } |
c19d1205 ZW |
21820 | else if (offset > 0) |
21821 | { | |
21822 | /* Short opcode. */ | |
21823 | op = (offset - 4) >> 2; | |
21824 | add_unwind_opcode (op, 1); | |
21825 | } | |
21826 | else if (offset < 0) | |
bfae80f2 | 21827 | { |
c19d1205 ZW |
21828 | offset = -offset; |
21829 | while (offset > 0x100) | |
bfae80f2 | 21830 | { |
c19d1205 ZW |
21831 | add_unwind_opcode (0x7f, 1); |
21832 | offset -= 0x100; | |
bfae80f2 | 21833 | } |
c19d1205 ZW |
21834 | op = ((offset - 4) >> 2) | 0x40; |
21835 | add_unwind_opcode (op, 1); | |
bfae80f2 | 21836 | } |
bfae80f2 RE |
21837 | } |
21838 | ||
c19d1205 ZW |
21839 | /* Finish the list of unwind opcodes for this function. */ |
21840 | static void | |
21841 | finish_unwind_opcodes (void) | |
bfae80f2 | 21842 | { |
c19d1205 | 21843 | valueT op; |
bfae80f2 | 21844 | |
c19d1205 | 21845 | if (unwind.fp_used) |
bfae80f2 | 21846 | { |
708587a4 | 21847 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
21848 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
21849 | flush_pending_unwind (); | |
bfae80f2 | 21850 | |
c19d1205 ZW |
21851 | /* After restoring sp from the frame pointer. */ |
21852 | op = 0x90 | unwind.fp_reg; | |
21853 | add_unwind_opcode (op, 1); | |
21854 | } | |
21855 | else | |
21856 | flush_pending_unwind (); | |
bfae80f2 RE |
21857 | } |
21858 | ||
bfae80f2 | 21859 | |
c19d1205 ZW |
21860 | /* Start an exception table entry. If idx is nonzero this is an index table |
21861 | entry. */ | |
bfae80f2 RE |
21862 | |
21863 | static void | |
c19d1205 | 21864 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 21865 | { |
c19d1205 ZW |
21866 | const char * text_name; |
21867 | const char * prefix; | |
21868 | const char * prefix_once; | |
21869 | const char * group_name; | |
21870 | size_t prefix_len; | |
21871 | size_t text_len; | |
21872 | char * sec_name; | |
21873 | size_t sec_name_len; | |
21874 | int type; | |
21875 | int flags; | |
21876 | int linkonce; | |
bfae80f2 | 21877 | |
c19d1205 | 21878 | if (idx) |
bfae80f2 | 21879 | { |
c19d1205 ZW |
21880 | prefix = ELF_STRING_ARM_unwind; |
21881 | prefix_once = ELF_STRING_ARM_unwind_once; | |
21882 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 21883 | } |
c19d1205 | 21884 | else |
bfae80f2 | 21885 | { |
c19d1205 ZW |
21886 | prefix = ELF_STRING_ARM_unwind_info; |
21887 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
21888 | type = SHT_PROGBITS; | |
bfae80f2 RE |
21889 | } |
21890 | ||
c19d1205 ZW |
21891 | text_name = segment_name (text_seg); |
21892 | if (streq (text_name, ".text")) | |
21893 | text_name = ""; | |
21894 | ||
21895 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
21896 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 21897 | { |
c19d1205 ZW |
21898 | prefix = prefix_once; |
21899 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
21900 | } |
21901 | ||
c19d1205 ZW |
21902 | prefix_len = strlen (prefix); |
21903 | text_len = strlen (text_name); | |
21904 | sec_name_len = prefix_len + text_len; | |
21d799b5 | 21905 | sec_name = (char *) xmalloc (sec_name_len + 1); |
c19d1205 ZW |
21906 | memcpy (sec_name, prefix, prefix_len); |
21907 | memcpy (sec_name + prefix_len, text_name, text_len); | |
21908 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 21909 | |
c19d1205 ZW |
21910 | flags = SHF_ALLOC; |
21911 | linkonce = 0; | |
21912 | group_name = 0; | |
bfae80f2 | 21913 | |
c19d1205 ZW |
21914 | /* Handle COMDAT group. */ |
21915 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 21916 | { |
c19d1205 ZW |
21917 | group_name = elf_group_name (text_seg); |
21918 | if (group_name == NULL) | |
21919 | { | |
bd3ba5d1 | 21920 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
21921 | segment_name (text_seg)); |
21922 | ignore_rest_of_line (); | |
21923 | return; | |
21924 | } | |
21925 | flags |= SHF_GROUP; | |
21926 | linkonce = 1; | |
bfae80f2 RE |
21927 | } |
21928 | ||
c19d1205 | 21929 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 21930 | |
5f4273c7 | 21931 | /* Set the section link for index tables. */ |
c19d1205 ZW |
21932 | if (idx) |
21933 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
21934 | } |
21935 | ||
bfae80f2 | 21936 | |
c19d1205 ZW |
21937 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
21938 | personality routine data. Returns zero, or the index table value for | |
cad0da33 | 21939 | an inline entry. */ |
c19d1205 ZW |
21940 | |
21941 | static valueT | |
21942 | create_unwind_entry (int have_data) | |
bfae80f2 | 21943 | { |
c19d1205 ZW |
21944 | int size; |
21945 | addressT where; | |
21946 | char *ptr; | |
21947 | /* The current word of data. */ | |
21948 | valueT data; | |
21949 | /* The number of bytes left in this word. */ | |
21950 | int n; | |
bfae80f2 | 21951 | |
c19d1205 | 21952 | finish_unwind_opcodes (); |
bfae80f2 | 21953 | |
c19d1205 ZW |
21954 | /* Remember the current text section. */ |
21955 | unwind.saved_seg = now_seg; | |
21956 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 21957 | |
c19d1205 | 21958 | start_unwind_section (now_seg, 0); |
bfae80f2 | 21959 | |
c19d1205 | 21960 | if (unwind.personality_routine == NULL) |
bfae80f2 | 21961 | { |
c19d1205 ZW |
21962 | if (unwind.personality_index == -2) |
21963 | { | |
21964 | if (have_data) | |
5f4273c7 | 21965 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
21966 | return 1; /* EXIDX_CANTUNWIND. */ |
21967 | } | |
bfae80f2 | 21968 | |
c19d1205 ZW |
21969 | /* Use a default personality routine if none is specified. */ |
21970 | if (unwind.personality_index == -1) | |
21971 | { | |
21972 | if (unwind.opcode_count > 3) | |
21973 | unwind.personality_index = 1; | |
21974 | else | |
21975 | unwind.personality_index = 0; | |
21976 | } | |
bfae80f2 | 21977 | |
c19d1205 ZW |
21978 | /* Space for the personality routine entry. */ |
21979 | if (unwind.personality_index == 0) | |
21980 | { | |
21981 | if (unwind.opcode_count > 3) | |
21982 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 21983 | |
c19d1205 ZW |
21984 | if (!have_data) |
21985 | { | |
21986 | /* All the data is inline in the index table. */ | |
21987 | data = 0x80; | |
21988 | n = 3; | |
21989 | while (unwind.opcode_count > 0) | |
21990 | { | |
21991 | unwind.opcode_count--; | |
21992 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
21993 | n--; | |
21994 | } | |
bfae80f2 | 21995 | |
c19d1205 ZW |
21996 | /* Pad with "finish" opcodes. */ |
21997 | while (n--) | |
21998 | data = (data << 8) | 0xb0; | |
bfae80f2 | 21999 | |
c19d1205 ZW |
22000 | return data; |
22001 | } | |
22002 | size = 0; | |
22003 | } | |
22004 | else | |
22005 | /* We get two opcodes "free" in the first word. */ | |
22006 | size = unwind.opcode_count - 2; | |
22007 | } | |
22008 | else | |
5011093d | 22009 | { |
cad0da33 NC |
22010 | /* PR 16765: Missing or misplaced unwind directives can trigger this. */ |
22011 | if (unwind.personality_index != -1) | |
22012 | { | |
22013 | as_bad (_("attempt to recreate an unwind entry")); | |
22014 | return 1; | |
22015 | } | |
5011093d NC |
22016 | |
22017 | /* An extra byte is required for the opcode count. */ | |
22018 | size = unwind.opcode_count + 1; | |
22019 | } | |
bfae80f2 | 22020 | |
c19d1205 ZW |
22021 | size = (size + 3) >> 2; |
22022 | if (size > 0xff) | |
22023 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 22024 | |
c19d1205 ZW |
22025 | frag_align (2, 0, 0); |
22026 | record_alignment (now_seg, 2); | |
22027 | unwind.table_entry = expr_build_dot (); | |
22028 | ||
22029 | /* Allocate the table entry. */ | |
22030 | ptr = frag_more ((size << 2) + 4); | |
74929e7b NC |
22031 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
22032 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 22033 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 22034 | |
c19d1205 | 22035 | switch (unwind.personality_index) |
bfae80f2 | 22036 | { |
c19d1205 ZW |
22037 | case -1: |
22038 | /* ??? Should this be a PLT generating relocation? */ | |
22039 | /* Custom personality routine. */ | |
22040 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
22041 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 22042 | |
c19d1205 ZW |
22043 | where += 4; |
22044 | ptr += 4; | |
bfae80f2 | 22045 | |
c19d1205 | 22046 | /* Set the first byte to the number of additional words. */ |
5011093d | 22047 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
22048 | n = 3; |
22049 | break; | |
bfae80f2 | 22050 | |
c19d1205 ZW |
22051 | /* ABI defined personality routines. */ |
22052 | case 0: | |
22053 | /* Three opcodes bytes are packed into the first word. */ | |
22054 | data = 0x80; | |
22055 | n = 3; | |
22056 | break; | |
bfae80f2 | 22057 | |
c19d1205 ZW |
22058 | case 1: |
22059 | case 2: | |
22060 | /* The size and first two opcode bytes go in the first word. */ | |
22061 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
22062 | n = 2; | |
22063 | break; | |
bfae80f2 | 22064 | |
c19d1205 ZW |
22065 | default: |
22066 | /* Should never happen. */ | |
22067 | abort (); | |
22068 | } | |
bfae80f2 | 22069 | |
c19d1205 ZW |
22070 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
22071 | time. */ | |
22072 | while (unwind.opcode_count > 0) | |
22073 | { | |
22074 | if (n == 0) | |
22075 | { | |
22076 | md_number_to_chars (ptr, data, 4); | |
22077 | ptr += 4; | |
22078 | n = 4; | |
22079 | data = 0; | |
22080 | } | |
22081 | unwind.opcode_count--; | |
22082 | n--; | |
22083 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
22084 | } | |
22085 | ||
22086 | /* Finish off the last word. */ | |
22087 | if (n < 4) | |
22088 | { | |
22089 | /* Pad with "finish" opcodes. */ | |
22090 | while (n--) | |
22091 | data = (data << 8) | 0xb0; | |
22092 | ||
22093 | md_number_to_chars (ptr, data, 4); | |
22094 | } | |
22095 | ||
22096 | if (!have_data) | |
22097 | { | |
22098 | /* Add an empty descriptor if there is no user-specified data. */ | |
22099 | ptr = frag_more (4); | |
22100 | md_number_to_chars (ptr, 0, 4); | |
22101 | } | |
22102 | ||
22103 | return 0; | |
bfae80f2 RE |
22104 | } |
22105 | ||
f0927246 NC |
22106 | |
22107 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
22108 | ||
22109 | void | |
22110 | tc_arm_frame_initial_instructions (void) | |
22111 | { | |
22112 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
22113 | } | |
22114 | #endif /* OBJ_ELF */ | |
22115 | ||
c19d1205 ZW |
22116 | /* Convert REGNAME to a DWARF-2 register number. */ |
22117 | ||
22118 | int | |
1df69f4f | 22119 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 22120 | { |
1df69f4f | 22121 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
1f5afe1c NC |
22122 | if (reg != FAIL) |
22123 | return reg; | |
c19d1205 | 22124 | |
1f5afe1c NC |
22125 | /* PR 16694: Allow VFP registers as well. */ |
22126 | reg = arm_reg_parse (®name, REG_TYPE_VFS); | |
22127 | if (reg != FAIL) | |
22128 | return 64 + reg; | |
c19d1205 | 22129 | |
1f5afe1c NC |
22130 | reg = arm_reg_parse (®name, REG_TYPE_VFD); |
22131 | if (reg != FAIL) | |
22132 | return reg + 256; | |
22133 | ||
22134 | return -1; | |
bfae80f2 RE |
22135 | } |
22136 | ||
f0927246 | 22137 | #ifdef TE_PE |
c19d1205 | 22138 | void |
f0927246 | 22139 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 22140 | { |
91d6fa6a | 22141 | expressionS exp; |
bfae80f2 | 22142 | |
91d6fa6a NC |
22143 | exp.X_op = O_secrel; |
22144 | exp.X_add_symbol = symbol; | |
22145 | exp.X_add_number = 0; | |
22146 | emit_expr (&exp, size); | |
f0927246 NC |
22147 | } |
22148 | #endif | |
bfae80f2 | 22149 | |
c19d1205 | 22150 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 22151 | |
2fc8bdac ZW |
22152 | /* Return the address within the segment that a PC-relative fixup is |
22153 | relative to. For ARM, PC-relative fixups applied to instructions | |
22154 | are generally relative to the location of the fixup plus 8 bytes. | |
22155 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
22156 | require special handling. */ | |
bfae80f2 | 22157 | |
c19d1205 | 22158 | long |
2fc8bdac | 22159 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 22160 | { |
2fc8bdac ZW |
22161 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
22162 | ||
22163 | /* If this is pc-relative and we are going to emit a relocation | |
22164 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
22165 | will need. Otherwise we want to use the calculated base. |
22166 | For WinCE we skip the bias for externals as well, since this | |
22167 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 22168 | if (fixP->fx_pcrel |
2fc8bdac | 22169 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
22170 | || (arm_force_relocation (fixP) |
22171 | #ifdef TE_WINCE | |
22172 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
22173 | #endif | |
22174 | ))) | |
2fc8bdac | 22175 | base = 0; |
bfae80f2 | 22176 | |
267bf995 | 22177 | |
c19d1205 | 22178 | switch (fixP->fx_r_type) |
bfae80f2 | 22179 | { |
2fc8bdac ZW |
22180 | /* PC relative addressing on the Thumb is slightly odd as the |
22181 | bottom two bits of the PC are forced to zero for the | |
22182 | calculation. This happens *after* application of the | |
22183 | pipeline offset. However, Thumb adrl already adjusts for | |
22184 | this, so we need not do it again. */ | |
c19d1205 | 22185 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 22186 | return base & ~3; |
c19d1205 ZW |
22187 | |
22188 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
22189 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 22190 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 22191 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 22192 | return (base + 4) & ~3; |
c19d1205 | 22193 | |
2fc8bdac ZW |
22194 | /* Thumb branches are simply offset by +4. */ |
22195 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
22196 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
22197 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
22198 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 22199 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 22200 | return base + 4; |
bfae80f2 | 22201 | |
267bf995 | 22202 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
22203 | if (fixP->fx_addsy |
22204 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22205 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 | 22206 | && ARM_IS_FUNC (fixP->fx_addsy) |
477330fc RM |
22207 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) |
22208 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
267bf995 RR |
22209 | return base + 4; |
22210 | ||
00adf2d4 JB |
22211 | /* BLX is like branches above, but forces the low two bits of PC to |
22212 | zero. */ | |
486499d0 CL |
22213 | case BFD_RELOC_THUMB_PCREL_BLX: |
22214 | if (fixP->fx_addsy | |
22215 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22216 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
22217 | && THUMB_IS_FUNC (fixP->fx_addsy) |
22218 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22219 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
22220 | return (base + 4) & ~3; |
22221 | ||
2fc8bdac ZW |
22222 | /* ARM mode branches are offset by +8. However, the Windows CE |
22223 | loader expects the relocation not to take this into account. */ | |
267bf995 | 22224 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
22225 | if (fixP->fx_addsy |
22226 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22227 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
22228 | && ARM_IS_FUNC (fixP->fx_addsy) |
22229 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22230 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 22231 | return base + 8; |
267bf995 | 22232 | |
486499d0 CL |
22233 | case BFD_RELOC_ARM_PCREL_CALL: |
22234 | if (fixP->fx_addsy | |
22235 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22236 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
22237 | && THUMB_IS_FUNC (fixP->fx_addsy) |
22238 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22239 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 22240 | return base + 8; |
267bf995 | 22241 | |
2fc8bdac | 22242 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 22243 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 22244 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 22245 | #ifdef TE_WINCE |
5f4273c7 | 22246 | /* When handling fixups immediately, because we have already |
477330fc | 22247 | discovered the value of a symbol, or the address of the frag involved |
53baae48 | 22248 | we must account for the offset by +8, as the OS loader will never see the reloc. |
477330fc RM |
22249 | see fixup_segment() in write.c |
22250 | The S_IS_EXTERNAL test handles the case of global symbols. | |
22251 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
53baae48 NC |
22252 | if (fixP->fx_pcrel |
22253 | && fixP->fx_addsy != NULL | |
22254 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
22255 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
22256 | return base + 8; | |
2fc8bdac | 22257 | return base; |
c19d1205 | 22258 | #else |
2fc8bdac | 22259 | return base + 8; |
c19d1205 | 22260 | #endif |
2fc8bdac | 22261 | |
267bf995 | 22262 | |
2fc8bdac ZW |
22263 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
22264 | branches, the Windows CE loader *does* expect the relocation | |
22265 | to take this into account. */ | |
22266 | case BFD_RELOC_ARM_OFFSET_IMM: | |
22267 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
22268 | case BFD_RELOC_ARM_HWLITERAL: | |
22269 | case BFD_RELOC_ARM_LITERAL: | |
22270 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
22271 | return base + 8; | |
22272 | ||
22273 | ||
22274 | /* Other PC-relative relocations are un-offset. */ | |
22275 | default: | |
22276 | return base; | |
22277 | } | |
bfae80f2 RE |
22278 | } |
22279 | ||
8b2d793c NC |
22280 | static bfd_boolean flag_warn_syms = TRUE; |
22281 | ||
ae8714c2 NC |
22282 | bfd_boolean |
22283 | arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) | |
bfae80f2 | 22284 | { |
8b2d793c NC |
22285 | /* PR 18347 - Warn if the user attempts to create a symbol with the same |
22286 | name as an ARM instruction. Whilst strictly speaking it is allowed, it | |
22287 | does mean that the resulting code might be very confusing to the reader. | |
22288 | Also this warning can be triggered if the user omits an operand before | |
22289 | an immediate address, eg: | |
22290 | ||
22291 | LDR =foo | |
22292 | ||
22293 | GAS treats this as an assignment of the value of the symbol foo to a | |
22294 | symbol LDR, and so (without this code) it will not issue any kind of | |
22295 | warning or error message. | |
22296 | ||
22297 | Note - ARM instructions are case-insensitive but the strings in the hash | |
22298 | table are all stored in lower case, so we must first ensure that name is | |
ae8714c2 NC |
22299 | lower case too. */ |
22300 | if (flag_warn_syms && arm_ops_hsh) | |
8b2d793c NC |
22301 | { |
22302 | char * nbuf = strdup (name); | |
22303 | char * p; | |
22304 | ||
22305 | for (p = nbuf; *p; p++) | |
22306 | *p = TOLOWER (*p); | |
22307 | if (hash_find (arm_ops_hsh, nbuf) != NULL) | |
22308 | { | |
22309 | static struct hash_control * already_warned = NULL; | |
22310 | ||
22311 | if (already_warned == NULL) | |
22312 | already_warned = hash_new (); | |
22313 | /* Only warn about the symbol once. To keep the code | |
22314 | simple we let hash_insert do the lookup for us. */ | |
22315 | if (hash_insert (already_warned, name, NULL) == NULL) | |
ae8714c2 | 22316 | as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name); |
8b2d793c NC |
22317 | } |
22318 | else | |
22319 | free (nbuf); | |
22320 | } | |
3739860c | 22321 | |
ae8714c2 NC |
22322 | return FALSE; |
22323 | } | |
22324 | ||
22325 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. | |
22326 | Otherwise we have no need to default values of symbols. */ | |
22327 | ||
22328 | symbolS * | |
22329 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
22330 | { | |
22331 | #ifdef OBJ_ELF | |
22332 | if (name[0] == '_' && name[1] == 'G' | |
22333 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
22334 | { | |
22335 | if (!GOT_symbol) | |
22336 | { | |
22337 | if (symbol_find (name)) | |
22338 | as_bad (_("GOT already in the symbol table")); | |
22339 | ||
22340 | GOT_symbol = symbol_new (name, undefined_section, | |
22341 | (valueT) 0, & zero_address_frag); | |
22342 | } | |
22343 | ||
22344 | return GOT_symbol; | |
22345 | } | |
22346 | #endif | |
22347 | ||
c921be7d | 22348 | return NULL; |
bfae80f2 RE |
22349 | } |
22350 | ||
55cf6793 | 22351 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
22352 | computed as two separate immediate values, added together. We |
22353 | already know that this value cannot be computed by just one ARM | |
22354 | instruction. */ | |
22355 | ||
22356 | static unsigned int | |
22357 | validate_immediate_twopart (unsigned int val, | |
22358 | unsigned int * highpart) | |
bfae80f2 | 22359 | { |
c19d1205 ZW |
22360 | unsigned int a; |
22361 | unsigned int i; | |
bfae80f2 | 22362 | |
c19d1205 ZW |
22363 | for (i = 0; i < 32; i += 2) |
22364 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
22365 | { | |
22366 | if (a & 0xff00) | |
22367 | { | |
22368 | if (a & ~ 0xffff) | |
22369 | continue; | |
22370 | * highpart = (a >> 8) | ((i + 24) << 7); | |
22371 | } | |
22372 | else if (a & 0xff0000) | |
22373 | { | |
22374 | if (a & 0xff000000) | |
22375 | continue; | |
22376 | * highpart = (a >> 16) | ((i + 16) << 7); | |
22377 | } | |
22378 | else | |
22379 | { | |
9c2799c2 | 22380 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
22381 | * highpart = (a >> 24) | ((i + 8) << 7); |
22382 | } | |
bfae80f2 | 22383 | |
c19d1205 ZW |
22384 | return (a & 0xff) | (i << 7); |
22385 | } | |
bfae80f2 | 22386 | |
c19d1205 | 22387 | return FAIL; |
bfae80f2 RE |
22388 | } |
22389 | ||
c19d1205 ZW |
22390 | static int |
22391 | validate_offset_imm (unsigned int val, int hwse) | |
22392 | { | |
22393 | if ((hwse && val > 255) || val > 4095) | |
22394 | return FAIL; | |
22395 | return val; | |
22396 | } | |
bfae80f2 | 22397 | |
55cf6793 | 22398 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
22399 | negative immediate constant by altering the instruction. A bit of |
22400 | a hack really. | |
22401 | MOV <-> MVN | |
22402 | AND <-> BIC | |
22403 | ADC <-> SBC | |
22404 | by inverting the second operand, and | |
22405 | ADD <-> SUB | |
22406 | CMP <-> CMN | |
22407 | by negating the second operand. */ | |
bfae80f2 | 22408 | |
c19d1205 ZW |
22409 | static int |
22410 | negate_data_op (unsigned long * instruction, | |
22411 | unsigned long value) | |
bfae80f2 | 22412 | { |
c19d1205 ZW |
22413 | int op, new_inst; |
22414 | unsigned long negated, inverted; | |
bfae80f2 | 22415 | |
c19d1205 ZW |
22416 | negated = encode_arm_immediate (-value); |
22417 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 22418 | |
c19d1205 ZW |
22419 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
22420 | switch (op) | |
bfae80f2 | 22421 | { |
c19d1205 ZW |
22422 | /* First negates. */ |
22423 | case OPCODE_SUB: /* ADD <-> SUB */ | |
22424 | new_inst = OPCODE_ADD; | |
22425 | value = negated; | |
22426 | break; | |
bfae80f2 | 22427 | |
c19d1205 ZW |
22428 | case OPCODE_ADD: |
22429 | new_inst = OPCODE_SUB; | |
22430 | value = negated; | |
22431 | break; | |
bfae80f2 | 22432 | |
c19d1205 ZW |
22433 | case OPCODE_CMP: /* CMP <-> CMN */ |
22434 | new_inst = OPCODE_CMN; | |
22435 | value = negated; | |
22436 | break; | |
bfae80f2 | 22437 | |
c19d1205 ZW |
22438 | case OPCODE_CMN: |
22439 | new_inst = OPCODE_CMP; | |
22440 | value = negated; | |
22441 | break; | |
bfae80f2 | 22442 | |
c19d1205 ZW |
22443 | /* Now Inverted ops. */ |
22444 | case OPCODE_MOV: /* MOV <-> MVN */ | |
22445 | new_inst = OPCODE_MVN; | |
22446 | value = inverted; | |
22447 | break; | |
bfae80f2 | 22448 | |
c19d1205 ZW |
22449 | case OPCODE_MVN: |
22450 | new_inst = OPCODE_MOV; | |
22451 | value = inverted; | |
22452 | break; | |
bfae80f2 | 22453 | |
c19d1205 ZW |
22454 | case OPCODE_AND: /* AND <-> BIC */ |
22455 | new_inst = OPCODE_BIC; | |
22456 | value = inverted; | |
22457 | break; | |
bfae80f2 | 22458 | |
c19d1205 ZW |
22459 | case OPCODE_BIC: |
22460 | new_inst = OPCODE_AND; | |
22461 | value = inverted; | |
22462 | break; | |
bfae80f2 | 22463 | |
c19d1205 ZW |
22464 | case OPCODE_ADC: /* ADC <-> SBC */ |
22465 | new_inst = OPCODE_SBC; | |
22466 | value = inverted; | |
22467 | break; | |
bfae80f2 | 22468 | |
c19d1205 ZW |
22469 | case OPCODE_SBC: |
22470 | new_inst = OPCODE_ADC; | |
22471 | value = inverted; | |
22472 | break; | |
bfae80f2 | 22473 | |
c19d1205 ZW |
22474 | /* We cannot do anything. */ |
22475 | default: | |
22476 | return FAIL; | |
b99bd4ef NC |
22477 | } |
22478 | ||
c19d1205 ZW |
22479 | if (value == (unsigned) FAIL) |
22480 | return FAIL; | |
22481 | ||
22482 | *instruction &= OPCODE_MASK; | |
22483 | *instruction |= new_inst << DATA_OP_SHIFT; | |
22484 | return value; | |
b99bd4ef NC |
22485 | } |
22486 | ||
ef8d22e6 PB |
22487 | /* Like negate_data_op, but for Thumb-2. */ |
22488 | ||
22489 | static unsigned int | |
16dd5e42 | 22490 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
22491 | { |
22492 | int op, new_inst; | |
22493 | int rd; | |
16dd5e42 | 22494 | unsigned int negated, inverted; |
ef8d22e6 PB |
22495 | |
22496 | negated = encode_thumb32_immediate (-value); | |
22497 | inverted = encode_thumb32_immediate (~value); | |
22498 | ||
22499 | rd = (*instruction >> 8) & 0xf; | |
22500 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
22501 | switch (op) | |
22502 | { | |
22503 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
22504 | case T2_OPCODE_SUB: | |
22505 | new_inst = T2_OPCODE_ADD; | |
22506 | value = negated; | |
22507 | break; | |
22508 | ||
22509 | case T2_OPCODE_ADD: | |
22510 | new_inst = T2_OPCODE_SUB; | |
22511 | value = negated; | |
22512 | break; | |
22513 | ||
22514 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
22515 | case T2_OPCODE_ORR: | |
22516 | new_inst = T2_OPCODE_ORN; | |
22517 | value = inverted; | |
22518 | break; | |
22519 | ||
22520 | case T2_OPCODE_ORN: | |
22521 | new_inst = T2_OPCODE_ORR; | |
22522 | value = inverted; | |
22523 | break; | |
22524 | ||
22525 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
22526 | case T2_OPCODE_AND: | |
22527 | new_inst = T2_OPCODE_BIC; | |
22528 | if (rd == 15) | |
22529 | value = FAIL; | |
22530 | else | |
22531 | value = inverted; | |
22532 | break; | |
22533 | ||
22534 | case T2_OPCODE_BIC: | |
22535 | new_inst = T2_OPCODE_AND; | |
22536 | value = inverted; | |
22537 | break; | |
22538 | ||
22539 | /* ADC <-> SBC */ | |
22540 | case T2_OPCODE_ADC: | |
22541 | new_inst = T2_OPCODE_SBC; | |
22542 | value = inverted; | |
22543 | break; | |
22544 | ||
22545 | case T2_OPCODE_SBC: | |
22546 | new_inst = T2_OPCODE_ADC; | |
22547 | value = inverted; | |
22548 | break; | |
22549 | ||
22550 | /* We cannot do anything. */ | |
22551 | default: | |
22552 | return FAIL; | |
22553 | } | |
22554 | ||
16dd5e42 | 22555 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
22556 | return FAIL; |
22557 | ||
22558 | *instruction &= T2_OPCODE_MASK; | |
22559 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
22560 | return value; | |
22561 | } | |
22562 | ||
8f06b2d8 PB |
22563 | /* Read a 32-bit thumb instruction from buf. */ |
22564 | static unsigned long | |
22565 | get_thumb32_insn (char * buf) | |
22566 | { | |
22567 | unsigned long insn; | |
22568 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
22569 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22570 | ||
22571 | return insn; | |
22572 | } | |
22573 | ||
a8bc6c78 PB |
22574 | |
22575 | /* We usually want to set the low bit on the address of thumb function | |
22576 | symbols. In particular .word foo - . should have the low bit set. | |
22577 | Generic code tries to fold the difference of two symbols to | |
22578 | a constant. Prevent this and force a relocation when the first symbols | |
22579 | is a thumb function. */ | |
c921be7d NC |
22580 | |
22581 | bfd_boolean | |
a8bc6c78 PB |
22582 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
22583 | { | |
22584 | if (op == O_subtract | |
22585 | && l->X_op == O_symbol | |
22586 | && r->X_op == O_symbol | |
22587 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
22588 | { | |
22589 | l->X_op = O_subtract; | |
22590 | l->X_op_symbol = r->X_add_symbol; | |
22591 | l->X_add_number -= r->X_add_number; | |
c921be7d | 22592 | return TRUE; |
a8bc6c78 | 22593 | } |
c921be7d | 22594 | |
a8bc6c78 | 22595 | /* Process as normal. */ |
c921be7d | 22596 | return FALSE; |
a8bc6c78 PB |
22597 | } |
22598 | ||
4a42ebbc RR |
22599 | /* Encode Thumb2 unconditional branches and calls. The encoding |
22600 | for the 2 are identical for the immediate values. */ | |
22601 | ||
22602 | static void | |
22603 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
22604 | { | |
22605 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
22606 | offsetT newval; | |
22607 | offsetT newval2; | |
22608 | addressT S, I1, I2, lo, hi; | |
22609 | ||
22610 | S = (value >> 24) & 0x01; | |
22611 | I1 = (value >> 23) & 0x01; | |
22612 | I2 = (value >> 22) & 0x01; | |
22613 | hi = (value >> 12) & 0x3ff; | |
fa94de6b | 22614 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
22615 | newval = md_chars_to_number (buf, THUMB_SIZE); |
22616 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22617 | newval |= (S << 10) | hi; | |
22618 | newval2 &= ~T2I1I2MASK; | |
22619 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
22620 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22621 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
22622 | } | |
22623 | ||
c19d1205 | 22624 | void |
55cf6793 | 22625 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
22626 | valueT * valP, |
22627 | segT seg) | |
22628 | { | |
22629 | offsetT value = * valP; | |
22630 | offsetT newval; | |
22631 | unsigned int newimm; | |
22632 | unsigned long temp; | |
22633 | int sign; | |
22634 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 22635 | |
9c2799c2 | 22636 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 22637 | |
c19d1205 | 22638 | /* Note whether this will delete the relocation. */ |
4962c51a | 22639 | |
c19d1205 ZW |
22640 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
22641 | fixP->fx_done = 1; | |
b99bd4ef | 22642 | |
adbaf948 | 22643 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 22644 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
22645 | for emit_reloc. */ |
22646 | value &= 0xffffffff; | |
22647 | value ^= 0x80000000; | |
5f4273c7 | 22648 | value -= 0x80000000; |
adbaf948 ZW |
22649 | |
22650 | *valP = value; | |
c19d1205 | 22651 | fixP->fx_addnumber = value; |
b99bd4ef | 22652 | |
adbaf948 ZW |
22653 | /* Same treatment for fixP->fx_offset. */ |
22654 | fixP->fx_offset &= 0xffffffff; | |
22655 | fixP->fx_offset ^= 0x80000000; | |
22656 | fixP->fx_offset -= 0x80000000; | |
22657 | ||
c19d1205 | 22658 | switch (fixP->fx_r_type) |
b99bd4ef | 22659 | { |
c19d1205 ZW |
22660 | case BFD_RELOC_NONE: |
22661 | /* This will need to go in the object file. */ | |
22662 | fixP->fx_done = 0; | |
22663 | break; | |
b99bd4ef | 22664 | |
c19d1205 ZW |
22665 | case BFD_RELOC_ARM_IMMEDIATE: |
22666 | /* We claim that this fixup has been processed here, | |
22667 | even if in fact we generate an error because we do | |
22668 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
22669 | fixP->fx_done = 1; | |
b99bd4ef | 22670 | |
77db8e2e | 22671 | if (fixP->fx_addsy) |
b99bd4ef | 22672 | { |
77db8e2e | 22673 | const char *msg = 0; |
b99bd4ef | 22674 | |
77db8e2e NC |
22675 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
22676 | msg = _("undefined symbol %s used as an immediate value"); | |
22677 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
22678 | msg = _("symbol %s is in a different section"); | |
22679 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
22680 | msg = _("symbol %s is weak and may be overridden later"); | |
22681 | ||
22682 | if (msg) | |
22683 | { | |
22684 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22685 | msg, S_GET_NAME (fixP->fx_addsy)); | |
22686 | break; | |
22687 | } | |
42e5fcbf AS |
22688 | } |
22689 | ||
c19d1205 ZW |
22690 | temp = md_chars_to_number (buf, INSN_SIZE); |
22691 | ||
5e73442d SL |
22692 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
22693 | if ((temp & 0xfff0000) == 0x28f0000 && value < 0) | |
22694 | newimm = negate_data_op (&temp, value); | |
22695 | else | |
22696 | { | |
22697 | newimm = encode_arm_immediate (value); | |
22698 | ||
22699 | /* If the instruction will fail, see if we can fix things up by | |
22700 | changing the opcode. */ | |
22701 | if (newimm == (unsigned int) FAIL) | |
22702 | newimm = negate_data_op (&temp, value); | |
22703 | } | |
22704 | ||
22705 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 22706 | { |
c19d1205 ZW |
22707 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22708 | _("invalid constant (%lx) after fixup"), | |
22709 | (unsigned long) value); | |
22710 | break; | |
b99bd4ef | 22711 | } |
b99bd4ef | 22712 | |
c19d1205 ZW |
22713 | newimm |= (temp & 0xfffff000); |
22714 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
22715 | break; | |
b99bd4ef | 22716 | |
c19d1205 ZW |
22717 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
22718 | { | |
22719 | unsigned int highpart = 0; | |
22720 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 22721 | |
77db8e2e | 22722 | if (fixP->fx_addsy) |
42e5fcbf | 22723 | { |
77db8e2e | 22724 | const char *msg = 0; |
42e5fcbf | 22725 | |
77db8e2e NC |
22726 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
22727 | msg = _("undefined symbol %s used as an immediate value"); | |
22728 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
22729 | msg = _("symbol %s is in a different section"); | |
22730 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
22731 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 22732 | |
77db8e2e NC |
22733 | if (msg) |
22734 | { | |
22735 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22736 | msg, S_GET_NAME (fixP->fx_addsy)); | |
22737 | break; | |
22738 | } | |
22739 | } | |
fa94de6b | 22740 | |
c19d1205 ZW |
22741 | newimm = encode_arm_immediate (value); |
22742 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 22743 | |
c19d1205 ZW |
22744 | /* If the instruction will fail, see if we can fix things up by |
22745 | changing the opcode. */ | |
22746 | if (newimm == (unsigned int) FAIL | |
22747 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
22748 | { | |
22749 | /* No ? OK - try using two ADD instructions to generate | |
22750 | the value. */ | |
22751 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 22752 | |
c19d1205 ZW |
22753 | /* Yes - then make sure that the second instruction is |
22754 | also an add. */ | |
22755 | if (newimm != (unsigned int) FAIL) | |
22756 | newinsn = temp; | |
22757 | /* Still No ? Try using a negated value. */ | |
22758 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
22759 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
22760 | /* Otherwise - give up. */ | |
22761 | else | |
22762 | { | |
22763 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22764 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
22765 | (long) value); | |
22766 | break; | |
22767 | } | |
b99bd4ef | 22768 | |
c19d1205 ZW |
22769 | /* Replace the first operand in the 2nd instruction (which |
22770 | is the PC) with the destination register. We have | |
22771 | already added in the PC in the first instruction and we | |
22772 | do not want to do it again. */ | |
22773 | newinsn &= ~ 0xf0000; | |
22774 | newinsn |= ((newinsn & 0x0f000) << 4); | |
22775 | } | |
b99bd4ef | 22776 | |
c19d1205 ZW |
22777 | newimm |= (temp & 0xfffff000); |
22778 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 22779 | |
c19d1205 ZW |
22780 | highpart |= (newinsn & 0xfffff000); |
22781 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
22782 | } | |
22783 | break; | |
b99bd4ef | 22784 | |
c19d1205 | 22785 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
22786 | if (!fixP->fx_done && seg->use_rela_p) |
22787 | value = 0; | |
22788 | ||
c19d1205 | 22789 | case BFD_RELOC_ARM_LITERAL: |
26d97720 | 22790 | sign = value > 0; |
b99bd4ef | 22791 | |
c19d1205 ZW |
22792 | if (value < 0) |
22793 | value = - value; | |
b99bd4ef | 22794 | |
c19d1205 | 22795 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 22796 | { |
c19d1205 ZW |
22797 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
22798 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22799 | _("invalid literal constant: pool needs to be closer")); | |
22800 | else | |
22801 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22802 | _("bad immediate value for offset (%ld)"), | |
22803 | (long) value); | |
22804 | break; | |
f03698e6 RE |
22805 | } |
22806 | ||
c19d1205 | 22807 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
22808 | if (value == 0) |
22809 | newval &= 0xfffff000; | |
22810 | else | |
22811 | { | |
22812 | newval &= 0xff7ff000; | |
22813 | newval |= value | (sign ? INDEX_UP : 0); | |
22814 | } | |
c19d1205 ZW |
22815 | md_number_to_chars (buf, newval, INSN_SIZE); |
22816 | break; | |
b99bd4ef | 22817 | |
c19d1205 ZW |
22818 | case BFD_RELOC_ARM_OFFSET_IMM8: |
22819 | case BFD_RELOC_ARM_HWLITERAL: | |
26d97720 | 22820 | sign = value > 0; |
b99bd4ef | 22821 | |
c19d1205 ZW |
22822 | if (value < 0) |
22823 | value = - value; | |
b99bd4ef | 22824 | |
c19d1205 | 22825 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 22826 | { |
c19d1205 ZW |
22827 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
22828 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22829 | _("invalid literal constant: pool needs to be closer")); | |
22830 | else | |
427d0db6 RM |
22831 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22832 | _("bad immediate value for 8-bit offset (%ld)"), | |
22833 | (long) value); | |
c19d1205 | 22834 | break; |
b99bd4ef NC |
22835 | } |
22836 | ||
c19d1205 | 22837 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
22838 | if (value == 0) |
22839 | newval &= 0xfffff0f0; | |
22840 | else | |
22841 | { | |
22842 | newval &= 0xff7ff0f0; | |
22843 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
22844 | } | |
c19d1205 ZW |
22845 | md_number_to_chars (buf, newval, INSN_SIZE); |
22846 | break; | |
b99bd4ef | 22847 | |
c19d1205 ZW |
22848 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
22849 | if (value < 0 || value > 1020 || value % 4 != 0) | |
22850 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22851 | _("bad immediate value for offset (%ld)"), (long) value); | |
22852 | value /= 4; | |
b99bd4ef | 22853 | |
c19d1205 | 22854 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
22855 | newval |= value; |
22856 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
22857 | break; | |
b99bd4ef | 22858 | |
c19d1205 ZW |
22859 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
22860 | /* This is a complicated relocation used for all varieties of Thumb32 | |
22861 | load/store instruction with immediate offset: | |
22862 | ||
22863 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
477330fc | 22864 | *4, optional writeback(W) |
c19d1205 ZW |
22865 | (doubleword load/store) |
22866 | ||
22867 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
22868 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
22869 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
22870 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
22871 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
22872 | ||
22873 | Uppercase letters indicate bits that are already encoded at | |
22874 | this point. Lowercase letters are our problem. For the | |
22875 | second block of instructions, the secondary opcode nybble | |
22876 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
22877 | a PC-relative operation. */ | |
22878 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22879 | newval <<= 16; | |
22880 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 22881 | |
c19d1205 | 22882 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 22883 | { |
c19d1205 ZW |
22884 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
22885 | if (value >= 0) | |
22886 | newval |= (1 << 23); | |
22887 | else | |
22888 | value = -value; | |
22889 | if (value % 4 != 0) | |
22890 | { | |
22891 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22892 | _("offset not a multiple of 4")); | |
22893 | break; | |
22894 | } | |
22895 | value /= 4; | |
216d22bc | 22896 | if (value > 0xff) |
c19d1205 ZW |
22897 | { |
22898 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22899 | _("offset out of range")); | |
22900 | break; | |
22901 | } | |
22902 | newval &= ~0xff; | |
b99bd4ef | 22903 | } |
c19d1205 | 22904 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 22905 | { |
c19d1205 ZW |
22906 | /* PC-relative, 12-bit offset. */ |
22907 | if (value >= 0) | |
22908 | newval |= (1 << 23); | |
22909 | else | |
22910 | value = -value; | |
216d22bc | 22911 | if (value > 0xfff) |
c19d1205 ZW |
22912 | { |
22913 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22914 | _("offset out of range")); | |
22915 | break; | |
22916 | } | |
22917 | newval &= ~0xfff; | |
b99bd4ef | 22918 | } |
c19d1205 | 22919 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 22920 | { |
c19d1205 ZW |
22921 | /* Writeback: 8-bit, +/- offset. */ |
22922 | if (value >= 0) | |
22923 | newval |= (1 << 9); | |
22924 | else | |
22925 | value = -value; | |
216d22bc | 22926 | if (value > 0xff) |
c19d1205 ZW |
22927 | { |
22928 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22929 | _("offset out of range")); | |
22930 | break; | |
22931 | } | |
22932 | newval &= ~0xff; | |
b99bd4ef | 22933 | } |
c19d1205 | 22934 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 22935 | { |
c19d1205 | 22936 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 22937 | if (value < 0 || value > 0xff) |
b99bd4ef | 22938 | { |
c19d1205 ZW |
22939 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22940 | _("offset out of range")); | |
22941 | break; | |
b99bd4ef | 22942 | } |
c19d1205 ZW |
22943 | newval &= ~0xff; |
22944 | newval |= value; | |
b99bd4ef NC |
22945 | } |
22946 | else | |
b99bd4ef | 22947 | { |
c19d1205 ZW |
22948 | /* Positive 12-bit or negative 8-bit offset. */ |
22949 | int limit; | |
22950 | if (value >= 0) | |
b99bd4ef | 22951 | { |
c19d1205 ZW |
22952 | newval |= (1 << 23); |
22953 | limit = 0xfff; | |
22954 | } | |
22955 | else | |
22956 | { | |
22957 | value = -value; | |
22958 | limit = 0xff; | |
22959 | } | |
22960 | if (value > limit) | |
22961 | { | |
22962 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22963 | _("offset out of range")); | |
22964 | break; | |
b99bd4ef | 22965 | } |
c19d1205 | 22966 | newval &= ~limit; |
b99bd4ef | 22967 | } |
b99bd4ef | 22968 | |
c19d1205 ZW |
22969 | newval |= value; |
22970 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
22971 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
22972 | break; | |
404ff6b5 | 22973 | |
c19d1205 ZW |
22974 | case BFD_RELOC_ARM_SHIFT_IMM: |
22975 | newval = md_chars_to_number (buf, INSN_SIZE); | |
22976 | if (((unsigned long) value) > 32 | |
22977 | || (value == 32 | |
22978 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
22979 | { | |
22980 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22981 | _("shift expression is too large")); | |
22982 | break; | |
22983 | } | |
404ff6b5 | 22984 | |
c19d1205 ZW |
22985 | if (value == 0) |
22986 | /* Shifts of zero must be done as lsl. */ | |
22987 | newval &= ~0x60; | |
22988 | else if (value == 32) | |
22989 | value = 0; | |
22990 | newval &= 0xfffff07f; | |
22991 | newval |= (value & 0x1f) << 7; | |
22992 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22993 | break; | |
404ff6b5 | 22994 | |
c19d1205 | 22995 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 22996 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 22997 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 22998 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
22999 | /* We claim that this fixup has been processed here, |
23000 | even if in fact we generate an error because we do | |
23001 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
23002 | fixP->fx_done = 1; | |
404ff6b5 | 23003 | |
c19d1205 ZW |
23004 | if (fixP->fx_addsy |
23005 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
23006 | { | |
23007 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23008 | _("undefined symbol %s used as an immediate value"), | |
23009 | S_GET_NAME (fixP->fx_addsy)); | |
23010 | break; | |
23011 | } | |
404ff6b5 | 23012 | |
c19d1205 ZW |
23013 | newval = md_chars_to_number (buf, THUMB_SIZE); |
23014 | newval <<= 16; | |
23015 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 23016 | |
16805f35 PB |
23017 | newimm = FAIL; |
23018 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
23019 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
23020 | { |
23021 | newimm = encode_thumb32_immediate (value); | |
23022 | if (newimm == (unsigned int) FAIL) | |
23023 | newimm = thumb32_negate_data_op (&newval, value); | |
23024 | } | |
16805f35 PB |
23025 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
23026 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 23027 | { |
16805f35 PB |
23028 | /* Turn add/sum into addw/subw. */ |
23029 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
23030 | newval = (newval & 0xfeffffff) | 0x02000000; | |
40f246e3 NC |
23031 | /* No flat 12-bit imm encoding for addsw/subsw. */ |
23032 | if ((newval & 0x00100000) == 0) | |
e9f89963 | 23033 | { |
40f246e3 NC |
23034 | /* 12 bit immediate for addw/subw. */ |
23035 | if (value < 0) | |
23036 | { | |
23037 | value = -value; | |
23038 | newval ^= 0x00a00000; | |
23039 | } | |
23040 | if (value > 0xfff) | |
23041 | newimm = (unsigned int) FAIL; | |
23042 | else | |
23043 | newimm = value; | |
e9f89963 | 23044 | } |
92e90b6e | 23045 | } |
cc8a6dd0 | 23046 | |
c19d1205 | 23047 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 23048 | { |
c19d1205 ZW |
23049 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23050 | _("invalid constant (%lx) after fixup"), | |
23051 | (unsigned long) value); | |
23052 | break; | |
3631a3c8 NC |
23053 | } |
23054 | ||
c19d1205 ZW |
23055 | newval |= (newimm & 0x800) << 15; |
23056 | newval |= (newimm & 0x700) << 4; | |
23057 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 23058 | |
c19d1205 ZW |
23059 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
23060 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
23061 | break; | |
a737bd4d | 23062 | |
3eb17e6b | 23063 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
23064 | if (((unsigned long) value) > 0xffff) |
23065 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 23066 | _("invalid smc expression")); |
2fc8bdac | 23067 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
23068 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
23069 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23070 | break; | |
a737bd4d | 23071 | |
90ec0d68 MGD |
23072 | case BFD_RELOC_ARM_HVC: |
23073 | if (((unsigned long) value) > 0xffff) | |
23074 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23075 | _("invalid hvc expression")); | |
23076 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23077 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
23078 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23079 | break; | |
23080 | ||
c19d1205 | 23081 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 23082 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
23083 | { |
23084 | if (((unsigned long) value) > 0xff) | |
23085 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23086 | _("invalid swi expression")); | |
2fc8bdac | 23087 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
23088 | newval |= value; |
23089 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23090 | } | |
23091 | else | |
23092 | { | |
23093 | if (((unsigned long) value) > 0x00ffffff) | |
23094 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23095 | _("invalid swi expression")); | |
2fc8bdac | 23096 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
23097 | newval |= value; |
23098 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23099 | } | |
23100 | break; | |
a737bd4d | 23101 | |
c19d1205 ZW |
23102 | case BFD_RELOC_ARM_MULTI: |
23103 | if (((unsigned long) value) > 0xffff) | |
23104 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23105 | _("invalid expression in load/store multiple")); | |
23106 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
23107 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23108 | break; | |
a737bd4d | 23109 | |
c19d1205 | 23110 | #ifdef OBJ_ELF |
39b41c9c | 23111 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
23112 | |
23113 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
23114 | && fixP->fx_addsy | |
34e77a92 | 23115 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23116 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23117 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
23118 | /* Flip the bl to blx. This is a simple flip | |
23119 | bit here because we generate PCREL_CALL for | |
23120 | unconditional bls. */ | |
23121 | { | |
23122 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23123 | newval = newval | 0x10000000; | |
23124 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23125 | temp = 1; | |
23126 | fixP->fx_done = 1; | |
23127 | } | |
39b41c9c PB |
23128 | else |
23129 | temp = 3; | |
23130 | goto arm_branch_common; | |
23131 | ||
23132 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
23133 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
23134 | && fixP->fx_addsy | |
34e77a92 | 23135 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23136 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23137 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
23138 | { | |
23139 | /* This would map to a bl<cond>, b<cond>, | |
23140 | b<always> to a Thumb function. We | |
23141 | need to force a relocation for this particular | |
23142 | case. */ | |
23143 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23144 | fixP->fx_done = 0; | |
23145 | } | |
23146 | ||
2fc8bdac | 23147 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 23148 | #endif |
39b41c9c PB |
23149 | case BFD_RELOC_ARM_PCREL_BRANCH: |
23150 | temp = 3; | |
23151 | goto arm_branch_common; | |
a737bd4d | 23152 | |
39b41c9c | 23153 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 23154 | |
39b41c9c | 23155 | temp = 1; |
267bf995 RR |
23156 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
23157 | && fixP->fx_addsy | |
34e77a92 | 23158 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23159 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23160 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
23161 | { | |
23162 | /* Flip the blx to a bl and warn. */ | |
23163 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
23164 | newval = 0xeb000000; | |
23165 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
23166 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
23167 | name); | |
23168 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23169 | temp = 3; | |
23170 | fixP->fx_done = 1; | |
23171 | } | |
23172 | ||
23173 | #ifdef OBJ_ELF | |
23174 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
477330fc | 23175 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; |
267bf995 RR |
23176 | #endif |
23177 | ||
39b41c9c | 23178 | arm_branch_common: |
c19d1205 | 23179 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
23180 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
23181 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
23182 | also be be clear. */ | |
23183 | if (value & temp) | |
c19d1205 | 23184 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
23185 | _("misaligned branch destination")); |
23186 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
23187 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
08f10d51 | 23188 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 23189 | |
2fc8bdac | 23190 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 23191 | { |
2fc8bdac ZW |
23192 | newval = md_chars_to_number (buf, INSN_SIZE); |
23193 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
23194 | /* Set the H bit on BLX instructions. */ |
23195 | if (temp == 1) | |
23196 | { | |
23197 | if (value & 2) | |
23198 | newval |= 0x01000000; | |
23199 | else | |
23200 | newval &= ~0x01000000; | |
23201 | } | |
2fc8bdac | 23202 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 23203 | } |
c19d1205 | 23204 | break; |
a737bd4d | 23205 | |
25fe350b MS |
23206 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
23207 | /* CBZ can only branch forward. */ | |
a737bd4d | 23208 | |
738755b0 | 23209 | /* Attempts to use CBZ to branch to the next instruction |
477330fc RM |
23210 | (which, strictly speaking, are prohibited) will be turned into |
23211 | no-ops. | |
738755b0 MS |
23212 | |
23213 | FIXME: It may be better to remove the instruction completely and | |
23214 | perform relaxation. */ | |
23215 | if (value == -2) | |
2fc8bdac ZW |
23216 | { |
23217 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 23218 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
23219 | md_number_to_chars (buf, newval, THUMB_SIZE); |
23220 | } | |
738755b0 MS |
23221 | else |
23222 | { | |
23223 | if (value & ~0x7e) | |
08f10d51 | 23224 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 | 23225 | |
477330fc | 23226 | if (fixP->fx_done || !seg->use_rela_p) |
738755b0 MS |
23227 | { |
23228 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23229 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
23230 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23231 | } | |
23232 | } | |
c19d1205 | 23233 | break; |
a737bd4d | 23234 | |
c19d1205 | 23235 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac | 23236 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
08f10d51 | 23237 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 23238 | |
2fc8bdac ZW |
23239 | if (fixP->fx_done || !seg->use_rela_p) |
23240 | { | |
23241 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23242 | newval |= (value & 0x1ff) >> 1; | |
23243 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23244 | } | |
c19d1205 | 23245 | break; |
a737bd4d | 23246 | |
c19d1205 | 23247 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac | 23248 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
08f10d51 | 23249 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 23250 | |
2fc8bdac ZW |
23251 | if (fixP->fx_done || !seg->use_rela_p) |
23252 | { | |
23253 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23254 | newval |= (value & 0xfff) >> 1; | |
23255 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23256 | } | |
c19d1205 | 23257 | break; |
a737bd4d | 23258 | |
c19d1205 | 23259 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
23260 | if (fixP->fx_addsy |
23261 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 23262 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23263 | && ARM_IS_FUNC (fixP->fx_addsy) |
23264 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
23265 | { | |
23266 | /* Force a relocation for a branch 20 bits wide. */ | |
23267 | fixP->fx_done = 0; | |
23268 | } | |
08f10d51 | 23269 | if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff)) |
2fc8bdac ZW |
23270 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23271 | _("conditional branch out of range")); | |
404ff6b5 | 23272 | |
2fc8bdac ZW |
23273 | if (fixP->fx_done || !seg->use_rela_p) |
23274 | { | |
23275 | offsetT newval2; | |
23276 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 23277 | |
2fc8bdac ZW |
23278 | S = (value & 0x00100000) >> 20; |
23279 | J2 = (value & 0x00080000) >> 19; | |
23280 | J1 = (value & 0x00040000) >> 18; | |
23281 | hi = (value & 0x0003f000) >> 12; | |
23282 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 23283 | |
2fc8bdac ZW |
23284 | newval = md_chars_to_number (buf, THUMB_SIZE); |
23285 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23286 | newval |= (S << 10) | hi; | |
23287 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
23288 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23289 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
23290 | } | |
c19d1205 | 23291 | break; |
6c43fab6 | 23292 | |
c19d1205 | 23293 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
23294 | /* If there is a blx from a thumb state function to |
23295 | another thumb function flip this to a bl and warn | |
23296 | about it. */ | |
23297 | ||
23298 | if (fixP->fx_addsy | |
34e77a92 | 23299 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23300 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
23301 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
23302 | { | |
23303 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
23304 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
23305 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
23306 | name); | |
23307 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23308 | newval = newval | 0x1000; | |
23309 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
23310 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
23311 | fixP->fx_done = 1; | |
23312 | } | |
23313 | ||
23314 | ||
23315 | goto thumb_bl_common; | |
23316 | ||
c19d1205 | 23317 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
23318 | /* A bl from Thumb state ISA to an internal ARM state function |
23319 | is converted to a blx. */ | |
23320 | if (fixP->fx_addsy | |
23321 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 23322 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
23323 | && ARM_IS_FUNC (fixP->fx_addsy) |
23324 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
23325 | { | |
23326 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
23327 | newval = newval & ~0x1000; | |
23328 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
23329 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
23330 | fixP->fx_done = 1; | |
23331 | } | |
23332 | ||
23333 | thumb_bl_common: | |
23334 | ||
2fc8bdac ZW |
23335 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
23336 | /* For a BLX instruction, make sure that the relocation is rounded up | |
23337 | to a word boundary. This follows the semantics of the instruction | |
23338 | which specifies that bit 1 of the target address will come from bit | |
23339 | 1 of the base address. */ | |
d406f3e4 JB |
23340 | value = (value + 3) & ~ 3; |
23341 | ||
23342 | #ifdef OBJ_ELF | |
23343 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 | |
23344 | && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
23345 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
23346 | #endif | |
404ff6b5 | 23347 | |
2b2f5df9 NC |
23348 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
23349 | { | |
fc289b0a | 23350 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))) |
2b2f5df9 NC |
23351 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
23352 | else if ((value & ~0x1ffffff) | |
23353 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
23354 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23355 | _("Thumb2 branch out of range")); | |
23356 | } | |
4a42ebbc RR |
23357 | |
23358 | if (fixP->fx_done || !seg->use_rela_p) | |
23359 | encode_thumb2_b_bl_offset (buf, value); | |
23360 | ||
c19d1205 | 23361 | break; |
404ff6b5 | 23362 | |
c19d1205 | 23363 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
08f10d51 NC |
23364 | if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff)) |
23365 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
6c43fab6 | 23366 | |
2fc8bdac | 23367 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 23368 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 23369 | |
2fc8bdac | 23370 | break; |
a737bd4d | 23371 | |
2fc8bdac ZW |
23372 | case BFD_RELOC_8: |
23373 | if (fixP->fx_done || !seg->use_rela_p) | |
4b1a927e | 23374 | *buf = value; |
c19d1205 | 23375 | break; |
a737bd4d | 23376 | |
c19d1205 | 23377 | case BFD_RELOC_16: |
2fc8bdac | 23378 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 23379 | md_number_to_chars (buf, value, 2); |
c19d1205 | 23380 | break; |
a737bd4d | 23381 | |
c19d1205 | 23382 | #ifdef OBJ_ELF |
0855e32b NS |
23383 | case BFD_RELOC_ARM_TLS_CALL: |
23384 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
23385 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
23386 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
0855e32b | 23387 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
23388 | case BFD_RELOC_ARM_TLS_GD32: |
23389 | case BFD_RELOC_ARM_TLS_LE32: | |
23390 | case BFD_RELOC_ARM_TLS_IE32: | |
23391 | case BFD_RELOC_ARM_TLS_LDM32: | |
23392 | case BFD_RELOC_ARM_TLS_LDO32: | |
23393 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
4b1a927e | 23394 | break; |
6c43fab6 | 23395 | |
c19d1205 ZW |
23396 | case BFD_RELOC_ARM_GOT32: |
23397 | case BFD_RELOC_ARM_GOTOFF: | |
c19d1205 | 23398 | break; |
b43420e6 NC |
23399 | |
23400 | case BFD_RELOC_ARM_GOT_PREL: | |
23401 | if (fixP->fx_done || !seg->use_rela_p) | |
477330fc | 23402 | md_number_to_chars (buf, value, 4); |
b43420e6 NC |
23403 | break; |
23404 | ||
9a6f4e97 NS |
23405 | case BFD_RELOC_ARM_TARGET2: |
23406 | /* TARGET2 is not partial-inplace, so we need to write the | |
477330fc RM |
23407 | addend here for REL targets, because it won't be written out |
23408 | during reloc processing later. */ | |
9a6f4e97 NS |
23409 | if (fixP->fx_done || !seg->use_rela_p) |
23410 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
23411 | break; | |
c19d1205 | 23412 | #endif |
6c43fab6 | 23413 | |
c19d1205 ZW |
23414 | case BFD_RELOC_RVA: |
23415 | case BFD_RELOC_32: | |
23416 | case BFD_RELOC_ARM_TARGET1: | |
23417 | case BFD_RELOC_ARM_ROSEGREL32: | |
23418 | case BFD_RELOC_ARM_SBREL32: | |
23419 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
23420 | #ifdef TE_PE |
23421 | case BFD_RELOC_32_SECREL: | |
23422 | #endif | |
2fc8bdac | 23423 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
23424 | #ifdef TE_WINCE |
23425 | /* For WinCE we only do this for pcrel fixups. */ | |
23426 | if (fixP->fx_done || fixP->fx_pcrel) | |
23427 | #endif | |
23428 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 23429 | break; |
6c43fab6 | 23430 | |
c19d1205 ZW |
23431 | #ifdef OBJ_ELF |
23432 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 23433 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
23434 | { |
23435 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
23436 | if ((value ^ (value >> 1)) & 0x40000000) | |
23437 | { | |
23438 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23439 | _("rel31 relocation overflow")); | |
23440 | } | |
23441 | newval |= value & 0x7fffffff; | |
23442 | md_number_to_chars (buf, newval, 4); | |
23443 | } | |
23444 | break; | |
c19d1205 | 23445 | #endif |
a737bd4d | 23446 | |
c19d1205 | 23447 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 23448 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
9db2f6b4 RL |
23449 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM) |
23450 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23451 | else | |
23452 | newval = get_thumb32_insn (buf); | |
23453 | if ((newval & 0x0f200f00) == 0x0d000900) | |
23454 | { | |
23455 | /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic | |
23456 | has permitted values that are multiples of 2, in the range 0 | |
23457 | to 510. */ | |
23458 | if (value < -510 || value > 510 || (value & 1)) | |
23459 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23460 | _("co-processor offset out of range")); | |
23461 | } | |
23462 | else if (value < -1023 || value > 1023 || (value & 3)) | |
c19d1205 ZW |
23463 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23464 | _("co-processor offset out of range")); | |
23465 | cp_off_common: | |
26d97720 | 23466 | sign = value > 0; |
c19d1205 ZW |
23467 | if (value < 0) |
23468 | value = -value; | |
8f06b2d8 PB |
23469 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
23470 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
23471 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23472 | else | |
23473 | newval = get_thumb32_insn (buf); | |
26d97720 NS |
23474 | if (value == 0) |
23475 | newval &= 0xffffff00; | |
23476 | else | |
23477 | { | |
23478 | newval &= 0xff7fff00; | |
9db2f6b4 RL |
23479 | if ((newval & 0x0f200f00) == 0x0d000900) |
23480 | { | |
23481 | /* This is a fp16 vstr/vldr. | |
23482 | ||
23483 | It requires the immediate offset in the instruction is shifted | |
23484 | left by 1 to be a half-word offset. | |
23485 | ||
23486 | Here, left shift by 1 first, and later right shift by 2 | |
23487 | should get the right offset. */ | |
23488 | value <<= 1; | |
23489 | } | |
26d97720 NS |
23490 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
23491 | } | |
8f06b2d8 PB |
23492 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
23493 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
23494 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23495 | else | |
23496 | put_thumb32_insn (buf, newval); | |
c19d1205 | 23497 | break; |
a737bd4d | 23498 | |
c19d1205 | 23499 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 23500 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
23501 | if (value < -255 || value > 255) |
23502 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23503 | _("co-processor offset out of range")); | |
df7849c5 | 23504 | value *= 4; |
c19d1205 | 23505 | goto cp_off_common; |
6c43fab6 | 23506 | |
c19d1205 ZW |
23507 | case BFD_RELOC_ARM_THUMB_OFFSET: |
23508 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23509 | /* Exactly what ranges, and where the offset is inserted depends | |
23510 | on the type of instruction, we can establish this from the | |
23511 | top 4 bits. */ | |
23512 | switch (newval >> 12) | |
23513 | { | |
23514 | case 4: /* PC load. */ | |
23515 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
23516 | forced to zero for these loads; md_pcrel_from has already | |
23517 | compensated for this. */ | |
23518 | if (value & 3) | |
23519 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23520 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
23521 | (((unsigned long) fixP->fx_frag->fr_address |
23522 | + (unsigned long) fixP->fx_where) & ~3) | |
23523 | + (unsigned long) value); | |
a737bd4d | 23524 | |
c19d1205 ZW |
23525 | if (value & ~0x3fc) |
23526 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23527 | _("invalid offset, value too big (0x%08lX)"), | |
23528 | (long) value); | |
a737bd4d | 23529 | |
c19d1205 ZW |
23530 | newval |= value >> 2; |
23531 | break; | |
a737bd4d | 23532 | |
c19d1205 ZW |
23533 | case 9: /* SP load/store. */ |
23534 | if (value & ~0x3fc) | |
23535 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23536 | _("invalid offset, value too big (0x%08lX)"), | |
23537 | (long) value); | |
23538 | newval |= value >> 2; | |
23539 | break; | |
6c43fab6 | 23540 | |
c19d1205 ZW |
23541 | case 6: /* Word load/store. */ |
23542 | if (value & ~0x7c) | |
23543 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23544 | _("invalid offset, value too big (0x%08lX)"), | |
23545 | (long) value); | |
23546 | newval |= value << 4; /* 6 - 2. */ | |
23547 | break; | |
a737bd4d | 23548 | |
c19d1205 ZW |
23549 | case 7: /* Byte load/store. */ |
23550 | if (value & ~0x1f) | |
23551 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23552 | _("invalid offset, value too big (0x%08lX)"), | |
23553 | (long) value); | |
23554 | newval |= value << 6; | |
23555 | break; | |
a737bd4d | 23556 | |
c19d1205 ZW |
23557 | case 8: /* Halfword load/store. */ |
23558 | if (value & ~0x3e) | |
23559 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23560 | _("invalid offset, value too big (0x%08lX)"), | |
23561 | (long) value); | |
23562 | newval |= value << 5; /* 6 - 1. */ | |
23563 | break; | |
a737bd4d | 23564 | |
c19d1205 ZW |
23565 | default: |
23566 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23567 | "Unable to process relocation for thumb opcode: %lx", | |
23568 | (unsigned long) newval); | |
23569 | break; | |
23570 | } | |
23571 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23572 | break; | |
a737bd4d | 23573 | |
c19d1205 ZW |
23574 | case BFD_RELOC_ARM_THUMB_ADD: |
23575 | /* This is a complicated relocation, since we use it for all of | |
23576 | the following immediate relocations: | |
a737bd4d | 23577 | |
c19d1205 ZW |
23578 | 3bit ADD/SUB |
23579 | 8bit ADD/SUB | |
23580 | 9bit ADD/SUB SP word-aligned | |
23581 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 23582 | |
c19d1205 ZW |
23583 | The type of instruction being processed is encoded in the |
23584 | instruction field: | |
a737bd4d | 23585 | |
c19d1205 ZW |
23586 | 0x8000 SUB |
23587 | 0x00F0 Rd | |
23588 | 0x000F Rs | |
23589 | */ | |
23590 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23591 | { | |
23592 | int rd = (newval >> 4) & 0xf; | |
23593 | int rs = newval & 0xf; | |
23594 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 23595 | |
c19d1205 ZW |
23596 | /* Check for HI regs, only very restricted cases allowed: |
23597 | Adjusting SP, and using PC or SP to get an address. */ | |
23598 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
23599 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
23600 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23601 | _("invalid Hi register with immediate")); | |
a737bd4d | 23602 | |
c19d1205 ZW |
23603 | /* If value is negative, choose the opposite instruction. */ |
23604 | if (value < 0) | |
23605 | { | |
23606 | value = -value; | |
23607 | subtract = !subtract; | |
23608 | if (value < 0) | |
23609 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23610 | _("immediate value out of range")); | |
23611 | } | |
a737bd4d | 23612 | |
c19d1205 ZW |
23613 | if (rd == REG_SP) |
23614 | { | |
75c11999 | 23615 | if (value & ~0x1fc) |
c19d1205 ZW |
23616 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23617 | _("invalid immediate for stack address calculation")); | |
23618 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
23619 | newval |= value >> 2; | |
23620 | } | |
23621 | else if (rs == REG_PC || rs == REG_SP) | |
23622 | { | |
c12d2c9d NC |
23623 | /* PR gas/18541. If the addition is for a defined symbol |
23624 | within range of an ADR instruction then accept it. */ | |
23625 | if (subtract | |
23626 | && value == 4 | |
23627 | && fixP->fx_addsy != NULL) | |
23628 | { | |
23629 | subtract = 0; | |
23630 | ||
23631 | if (! S_IS_DEFINED (fixP->fx_addsy) | |
23632 | || S_GET_SEGMENT (fixP->fx_addsy) != seg | |
23633 | || S_IS_WEAK (fixP->fx_addsy)) | |
23634 | { | |
23635 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23636 | _("address calculation needs a strongly defined nearby symbol")); | |
23637 | } | |
23638 | else | |
23639 | { | |
23640 | offsetT v = fixP->fx_where + fixP->fx_frag->fr_address; | |
23641 | ||
23642 | /* Round up to the next 4-byte boundary. */ | |
23643 | if (v & 3) | |
23644 | v = (v + 3) & ~ 3; | |
23645 | else | |
23646 | v += 4; | |
23647 | v = S_GET_VALUE (fixP->fx_addsy) - v; | |
23648 | ||
23649 | if (v & ~0x3fc) | |
23650 | { | |
23651 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23652 | _("symbol too far away")); | |
23653 | } | |
23654 | else | |
23655 | { | |
23656 | fixP->fx_done = 1; | |
23657 | value = v; | |
23658 | } | |
23659 | } | |
23660 | } | |
23661 | ||
c19d1205 ZW |
23662 | if (subtract || value & ~0x3fc) |
23663 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23664 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
5fc177c8 | 23665 | (unsigned long) (subtract ? - value : value)); |
c19d1205 ZW |
23666 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); |
23667 | newval |= rd << 8; | |
23668 | newval |= value >> 2; | |
23669 | } | |
23670 | else if (rs == rd) | |
23671 | { | |
23672 | if (value & ~0xff) | |
23673 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23674 | _("immediate value out of range")); | |
23675 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
23676 | newval |= (rd << 8) | value; | |
23677 | } | |
23678 | else | |
23679 | { | |
23680 | if (value & ~0x7) | |
23681 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23682 | _("immediate value out of range")); | |
23683 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
23684 | newval |= rd | (rs << 3) | (value << 6); | |
23685 | } | |
23686 | } | |
23687 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23688 | break; | |
a737bd4d | 23689 | |
c19d1205 ZW |
23690 | case BFD_RELOC_ARM_THUMB_IMM: |
23691 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23692 | if (value < 0 || value > 255) | |
23693 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 23694 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
23695 | (long) value); |
23696 | newval |= value; | |
23697 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23698 | break; | |
a737bd4d | 23699 | |
c19d1205 ZW |
23700 | case BFD_RELOC_ARM_THUMB_SHIFT: |
23701 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
23702 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
23703 | temp = newval & 0xf800; | |
23704 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
23705 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23706 | _("invalid shift value: %ld"), (long) value); | |
23707 | /* Shifts of zero must be encoded as LSL. */ | |
23708 | if (value == 0) | |
23709 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
23710 | /* Shifts of 32 are encoded as zero. */ | |
23711 | else if (value == 32) | |
23712 | value = 0; | |
23713 | newval |= value << 6; | |
23714 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23715 | break; | |
a737bd4d | 23716 | |
c19d1205 ZW |
23717 | case BFD_RELOC_VTABLE_INHERIT: |
23718 | case BFD_RELOC_VTABLE_ENTRY: | |
23719 | fixP->fx_done = 0; | |
23720 | return; | |
6c43fab6 | 23721 | |
b6895b4f PB |
23722 | case BFD_RELOC_ARM_MOVW: |
23723 | case BFD_RELOC_ARM_MOVT: | |
23724 | case BFD_RELOC_ARM_THUMB_MOVW: | |
23725 | case BFD_RELOC_ARM_THUMB_MOVT: | |
23726 | if (fixP->fx_done || !seg->use_rela_p) | |
23727 | { | |
23728 | /* REL format relocations are limited to a 16-bit addend. */ | |
23729 | if (!fixP->fx_done) | |
23730 | { | |
39623e12 | 23731 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 23732 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 23733 | _("offset out of range")); |
b6895b4f PB |
23734 | } |
23735 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
23736 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
23737 | { | |
23738 | value >>= 16; | |
23739 | } | |
23740 | ||
23741 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
23742 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
23743 | { | |
23744 | newval = get_thumb32_insn (buf); | |
23745 | newval &= 0xfbf08f00; | |
23746 | newval |= (value & 0xf000) << 4; | |
23747 | newval |= (value & 0x0800) << 15; | |
23748 | newval |= (value & 0x0700) << 4; | |
23749 | newval |= (value & 0x00ff); | |
23750 | put_thumb32_insn (buf, newval); | |
23751 | } | |
23752 | else | |
23753 | { | |
23754 | newval = md_chars_to_number (buf, 4); | |
23755 | newval &= 0xfff0f000; | |
23756 | newval |= value & 0x0fff; | |
23757 | newval |= (value & 0xf000) << 4; | |
23758 | md_number_to_chars (buf, newval, 4); | |
23759 | } | |
23760 | } | |
23761 | return; | |
23762 | ||
72d98d16 MG |
23763 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
23764 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
23765 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
23766 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
23767 | gas_assert (!fixP->fx_done); | |
23768 | { | |
23769 | bfd_vma insn; | |
23770 | bfd_boolean is_mov; | |
23771 | bfd_vma encoded_addend = value; | |
23772 | ||
23773 | /* Check that addend can be encoded in instruction. */ | |
23774 | if (!seg->use_rela_p && (value < 0 || value > 255)) | |
23775 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23776 | _("the offset 0x%08lX is not representable"), | |
23777 | (unsigned long) encoded_addend); | |
23778 | ||
23779 | /* Extract the instruction. */ | |
23780 | insn = md_chars_to_number (buf, THUMB_SIZE); | |
23781 | is_mov = (insn & 0xf800) == 0x2000; | |
23782 | ||
23783 | /* Encode insn. */ | |
23784 | if (is_mov) | |
23785 | { | |
23786 | if (!seg->use_rela_p) | |
23787 | insn |= encoded_addend; | |
23788 | } | |
23789 | else | |
23790 | { | |
23791 | int rd, rs; | |
23792 | ||
23793 | /* Extract the instruction. */ | |
23794 | /* Encoding is the following | |
23795 | 0x8000 SUB | |
23796 | 0x00F0 Rd | |
23797 | 0x000F Rs | |
23798 | */ | |
23799 | /* The following conditions must be true : | |
23800 | - ADD | |
23801 | - Rd == Rs | |
23802 | - Rd <= 7 | |
23803 | */ | |
23804 | rd = (insn >> 4) & 0xf; | |
23805 | rs = insn & 0xf; | |
23806 | if ((insn & 0x8000) || (rd != rs) || rd > 7) | |
23807 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23808 | _("Unable to process relocation for thumb opcode: %lx"), | |
23809 | (unsigned long) insn); | |
23810 | ||
23811 | /* Encode as ADD immediate8 thumb 1 code. */ | |
23812 | insn = 0x3000 | (rd << 8); | |
23813 | ||
23814 | /* Place the encoded addend into the first 8 bits of the | |
23815 | instruction. */ | |
23816 | if (!seg->use_rela_p) | |
23817 | insn |= encoded_addend; | |
23818 | } | |
23819 | ||
23820 | /* Update the instruction. */ | |
23821 | md_number_to_chars (buf, insn, THUMB_SIZE); | |
23822 | } | |
23823 | break; | |
23824 | ||
4962c51a MS |
23825 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
23826 | case BFD_RELOC_ARM_ALU_PC_G0: | |
23827 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
23828 | case BFD_RELOC_ARM_ALU_PC_G1: | |
23829 | case BFD_RELOC_ARM_ALU_PC_G2: | |
23830 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
23831 | case BFD_RELOC_ARM_ALU_SB_G0: | |
23832 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
23833 | case BFD_RELOC_ARM_ALU_SB_G1: | |
23834 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 23835 | gas_assert (!fixP->fx_done); |
4962c51a MS |
23836 | if (!seg->use_rela_p) |
23837 | { | |
477330fc RM |
23838 | bfd_vma insn; |
23839 | bfd_vma encoded_addend; | |
23840 | bfd_vma addend_abs = abs (value); | |
23841 | ||
23842 | /* Check that the absolute value of the addend can be | |
23843 | expressed as an 8-bit constant plus a rotation. */ | |
23844 | encoded_addend = encode_arm_immediate (addend_abs); | |
23845 | if (encoded_addend == (unsigned int) FAIL) | |
4962c51a | 23846 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23847 | _("the offset 0x%08lX is not representable"), |
23848 | (unsigned long) addend_abs); | |
23849 | ||
23850 | /* Extract the instruction. */ | |
23851 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23852 | ||
23853 | /* If the addend is positive, use an ADD instruction. | |
23854 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
23855 | insn &= 0xff1fffff; | |
23856 | if (value < 0) | |
23857 | insn |= 1 << 22; | |
23858 | else | |
23859 | insn |= 1 << 23; | |
23860 | ||
23861 | /* Place the encoded addend into the first 12 bits of the | |
23862 | instruction. */ | |
23863 | insn &= 0xfffff000; | |
23864 | insn |= encoded_addend; | |
23865 | ||
23866 | /* Update the instruction. */ | |
23867 | md_number_to_chars (buf, insn, INSN_SIZE); | |
4962c51a MS |
23868 | } |
23869 | break; | |
23870 | ||
23871 | case BFD_RELOC_ARM_LDR_PC_G0: | |
23872 | case BFD_RELOC_ARM_LDR_PC_G1: | |
23873 | case BFD_RELOC_ARM_LDR_PC_G2: | |
23874 | case BFD_RELOC_ARM_LDR_SB_G0: | |
23875 | case BFD_RELOC_ARM_LDR_SB_G1: | |
23876 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 23877 | gas_assert (!fixP->fx_done); |
4962c51a | 23878 | if (!seg->use_rela_p) |
477330fc RM |
23879 | { |
23880 | bfd_vma insn; | |
23881 | bfd_vma addend_abs = abs (value); | |
4962c51a | 23882 | |
477330fc RM |
23883 | /* Check that the absolute value of the addend can be |
23884 | encoded in 12 bits. */ | |
23885 | if (addend_abs >= 0x1000) | |
4962c51a | 23886 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23887 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), |
23888 | (unsigned long) addend_abs); | |
23889 | ||
23890 | /* Extract the instruction. */ | |
23891 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23892 | ||
23893 | /* If the addend is negative, clear bit 23 of the instruction. | |
23894 | Otherwise set it. */ | |
23895 | if (value < 0) | |
23896 | insn &= ~(1 << 23); | |
23897 | else | |
23898 | insn |= 1 << 23; | |
23899 | ||
23900 | /* Place the absolute value of the addend into the first 12 bits | |
23901 | of the instruction. */ | |
23902 | insn &= 0xfffff000; | |
23903 | insn |= addend_abs; | |
23904 | ||
23905 | /* Update the instruction. */ | |
23906 | md_number_to_chars (buf, insn, INSN_SIZE); | |
23907 | } | |
4962c51a MS |
23908 | break; |
23909 | ||
23910 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
23911 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
23912 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
23913 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
23914 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
23915 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 23916 | gas_assert (!fixP->fx_done); |
4962c51a | 23917 | if (!seg->use_rela_p) |
477330fc RM |
23918 | { |
23919 | bfd_vma insn; | |
23920 | bfd_vma addend_abs = abs (value); | |
4962c51a | 23921 | |
477330fc RM |
23922 | /* Check that the absolute value of the addend can be |
23923 | encoded in 8 bits. */ | |
23924 | if (addend_abs >= 0x100) | |
4962c51a | 23925 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23926 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), |
23927 | (unsigned long) addend_abs); | |
23928 | ||
23929 | /* Extract the instruction. */ | |
23930 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23931 | ||
23932 | /* If the addend is negative, clear bit 23 of the instruction. | |
23933 | Otherwise set it. */ | |
23934 | if (value < 0) | |
23935 | insn &= ~(1 << 23); | |
23936 | else | |
23937 | insn |= 1 << 23; | |
23938 | ||
23939 | /* Place the first four bits of the absolute value of the addend | |
23940 | into the first 4 bits of the instruction, and the remaining | |
23941 | four into bits 8 .. 11. */ | |
23942 | insn &= 0xfffff0f0; | |
23943 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
23944 | ||
23945 | /* Update the instruction. */ | |
23946 | md_number_to_chars (buf, insn, INSN_SIZE); | |
23947 | } | |
4962c51a MS |
23948 | break; |
23949 | ||
23950 | case BFD_RELOC_ARM_LDC_PC_G0: | |
23951 | case BFD_RELOC_ARM_LDC_PC_G1: | |
23952 | case BFD_RELOC_ARM_LDC_PC_G2: | |
23953 | case BFD_RELOC_ARM_LDC_SB_G0: | |
23954 | case BFD_RELOC_ARM_LDC_SB_G1: | |
23955 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 23956 | gas_assert (!fixP->fx_done); |
4962c51a | 23957 | if (!seg->use_rela_p) |
477330fc RM |
23958 | { |
23959 | bfd_vma insn; | |
23960 | bfd_vma addend_abs = abs (value); | |
4962c51a | 23961 | |
477330fc RM |
23962 | /* Check that the absolute value of the addend is a multiple of |
23963 | four and, when divided by four, fits in 8 bits. */ | |
23964 | if (addend_abs & 0x3) | |
4962c51a | 23965 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23966 | _("bad offset 0x%08lX (must be word-aligned)"), |
23967 | (unsigned long) addend_abs); | |
4962c51a | 23968 | |
477330fc | 23969 | if ((addend_abs >> 2) > 0xff) |
4962c51a | 23970 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23971 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), |
23972 | (unsigned long) addend_abs); | |
23973 | ||
23974 | /* Extract the instruction. */ | |
23975 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23976 | ||
23977 | /* If the addend is negative, clear bit 23 of the instruction. | |
23978 | Otherwise set it. */ | |
23979 | if (value < 0) | |
23980 | insn &= ~(1 << 23); | |
23981 | else | |
23982 | insn |= 1 << 23; | |
23983 | ||
23984 | /* Place the addend (divided by four) into the first eight | |
23985 | bits of the instruction. */ | |
23986 | insn &= 0xfffffff0; | |
23987 | insn |= addend_abs >> 2; | |
23988 | ||
23989 | /* Update the instruction. */ | |
23990 | md_number_to_chars (buf, insn, INSN_SIZE); | |
23991 | } | |
4962c51a MS |
23992 | break; |
23993 | ||
845b51d6 PB |
23994 | case BFD_RELOC_ARM_V4BX: |
23995 | /* This will need to go in the object file. */ | |
23996 | fixP->fx_done = 0; | |
23997 | break; | |
23998 | ||
c19d1205 ZW |
23999 | case BFD_RELOC_UNUSED: |
24000 | default: | |
24001 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
24002 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
24003 | } | |
6c43fab6 RE |
24004 | } |
24005 | ||
c19d1205 ZW |
24006 | /* Translate internal representation of relocation info to BFD target |
24007 | format. */ | |
a737bd4d | 24008 | |
c19d1205 | 24009 | arelent * |
00a97672 | 24010 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 24011 | { |
c19d1205 ZW |
24012 | arelent * reloc; |
24013 | bfd_reloc_code_real_type code; | |
a737bd4d | 24014 | |
21d799b5 | 24015 | reloc = (arelent *) xmalloc (sizeof (arelent)); |
a737bd4d | 24016 | |
21d799b5 | 24017 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
c19d1205 ZW |
24018 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
24019 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 24020 | |
2fc8bdac | 24021 | if (fixp->fx_pcrel) |
00a97672 RS |
24022 | { |
24023 | if (section->use_rela_p) | |
24024 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
24025 | else | |
24026 | fixp->fx_offset = reloc->address; | |
24027 | } | |
c19d1205 | 24028 | reloc->addend = fixp->fx_offset; |
a737bd4d | 24029 | |
c19d1205 | 24030 | switch (fixp->fx_r_type) |
a737bd4d | 24031 | { |
c19d1205 ZW |
24032 | case BFD_RELOC_8: |
24033 | if (fixp->fx_pcrel) | |
24034 | { | |
24035 | code = BFD_RELOC_8_PCREL; | |
24036 | break; | |
24037 | } | |
a737bd4d | 24038 | |
c19d1205 ZW |
24039 | case BFD_RELOC_16: |
24040 | if (fixp->fx_pcrel) | |
24041 | { | |
24042 | code = BFD_RELOC_16_PCREL; | |
24043 | break; | |
24044 | } | |
6c43fab6 | 24045 | |
c19d1205 ZW |
24046 | case BFD_RELOC_32: |
24047 | if (fixp->fx_pcrel) | |
24048 | { | |
24049 | code = BFD_RELOC_32_PCREL; | |
24050 | break; | |
24051 | } | |
a737bd4d | 24052 | |
b6895b4f PB |
24053 | case BFD_RELOC_ARM_MOVW: |
24054 | if (fixp->fx_pcrel) | |
24055 | { | |
24056 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
24057 | break; | |
24058 | } | |
24059 | ||
24060 | case BFD_RELOC_ARM_MOVT: | |
24061 | if (fixp->fx_pcrel) | |
24062 | { | |
24063 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
24064 | break; | |
24065 | } | |
24066 | ||
24067 | case BFD_RELOC_ARM_THUMB_MOVW: | |
24068 | if (fixp->fx_pcrel) | |
24069 | { | |
24070 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
24071 | break; | |
24072 | } | |
24073 | ||
24074 | case BFD_RELOC_ARM_THUMB_MOVT: | |
24075 | if (fixp->fx_pcrel) | |
24076 | { | |
24077 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
24078 | break; | |
24079 | } | |
24080 | ||
c19d1205 ZW |
24081 | case BFD_RELOC_NONE: |
24082 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
24083 | case BFD_RELOC_ARM_PCREL_BLX: | |
24084 | case BFD_RELOC_RVA: | |
24085 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
24086 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
24087 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
24088 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
24089 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
24090 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
24091 | case BFD_RELOC_VTABLE_ENTRY: |
24092 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
24093 | #ifdef TE_PE |
24094 | case BFD_RELOC_32_SECREL: | |
24095 | #endif | |
c19d1205 ZW |
24096 | code = fixp->fx_r_type; |
24097 | break; | |
a737bd4d | 24098 | |
00adf2d4 JB |
24099 | case BFD_RELOC_THUMB_PCREL_BLX: |
24100 | #ifdef OBJ_ELF | |
24101 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
24102 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
24103 | else | |
24104 | #endif | |
24105 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
24106 | break; | |
24107 | ||
c19d1205 ZW |
24108 | case BFD_RELOC_ARM_LITERAL: |
24109 | case BFD_RELOC_ARM_HWLITERAL: | |
24110 | /* If this is called then the a literal has | |
24111 | been referenced across a section boundary. */ | |
24112 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
24113 | _("literal referenced across section boundary")); | |
24114 | return NULL; | |
a737bd4d | 24115 | |
c19d1205 | 24116 | #ifdef OBJ_ELF |
0855e32b NS |
24117 | case BFD_RELOC_ARM_TLS_CALL: |
24118 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
24119 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
24120 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
c19d1205 ZW |
24121 | case BFD_RELOC_ARM_GOT32: |
24122 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 24123 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
24124 | case BFD_RELOC_ARM_PLT32: |
24125 | case BFD_RELOC_ARM_TARGET1: | |
24126 | case BFD_RELOC_ARM_ROSEGREL32: | |
24127 | case BFD_RELOC_ARM_SBREL32: | |
24128 | case BFD_RELOC_ARM_PREL31: | |
24129 | case BFD_RELOC_ARM_TARGET2: | |
c19d1205 | 24130 | case BFD_RELOC_ARM_TLS_LDO32: |
39b41c9c PB |
24131 | case BFD_RELOC_ARM_PCREL_CALL: |
24132 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
24133 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
24134 | case BFD_RELOC_ARM_ALU_PC_G0: | |
24135 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
24136 | case BFD_RELOC_ARM_ALU_PC_G1: | |
24137 | case BFD_RELOC_ARM_ALU_PC_G2: | |
24138 | case BFD_RELOC_ARM_LDR_PC_G0: | |
24139 | case BFD_RELOC_ARM_LDR_PC_G1: | |
24140 | case BFD_RELOC_ARM_LDR_PC_G2: | |
24141 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
24142 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
24143 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
24144 | case BFD_RELOC_ARM_LDC_PC_G0: | |
24145 | case BFD_RELOC_ARM_LDC_PC_G1: | |
24146 | case BFD_RELOC_ARM_LDC_PC_G2: | |
24147 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
24148 | case BFD_RELOC_ARM_ALU_SB_G0: | |
24149 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
24150 | case BFD_RELOC_ARM_ALU_SB_G1: | |
24151 | case BFD_RELOC_ARM_ALU_SB_G2: | |
24152 | case BFD_RELOC_ARM_LDR_SB_G0: | |
24153 | case BFD_RELOC_ARM_LDR_SB_G1: | |
24154 | case BFD_RELOC_ARM_LDR_SB_G2: | |
24155 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
24156 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
24157 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
24158 | case BFD_RELOC_ARM_LDC_SB_G0: | |
24159 | case BFD_RELOC_ARM_LDC_SB_G1: | |
24160 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 24161 | case BFD_RELOC_ARM_V4BX: |
72d98d16 MG |
24162 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
24163 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
24164 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
24165 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
c19d1205 ZW |
24166 | code = fixp->fx_r_type; |
24167 | break; | |
a737bd4d | 24168 | |
0855e32b | 24169 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 | 24170 | case BFD_RELOC_ARM_TLS_GD32: |
75c11999 | 24171 | case BFD_RELOC_ARM_TLS_LE32: |
c19d1205 ZW |
24172 | case BFD_RELOC_ARM_TLS_IE32: |
24173 | case BFD_RELOC_ARM_TLS_LDM32: | |
24174 | /* BFD will include the symbol's address in the addend. | |
24175 | But we don't want that, so subtract it out again here. */ | |
24176 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
24177 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
24178 | code = fixp->fx_r_type; | |
24179 | break; | |
24180 | #endif | |
a737bd4d | 24181 | |
c19d1205 ZW |
24182 | case BFD_RELOC_ARM_IMMEDIATE: |
24183 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
24184 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
24185 | return NULL; | |
a737bd4d | 24186 | |
c19d1205 ZW |
24187 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
24188 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
24189 | _("ADRL used for a symbol not defined in the same file")); | |
24190 | return NULL; | |
a737bd4d | 24191 | |
c19d1205 | 24192 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
24193 | if (section->use_rela_p) |
24194 | { | |
24195 | code = fixp->fx_r_type; | |
24196 | break; | |
24197 | } | |
24198 | ||
c19d1205 ZW |
24199 | if (fixp->fx_addsy != NULL |
24200 | && !S_IS_DEFINED (fixp->fx_addsy) | |
24201 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 24202 | { |
c19d1205 ZW |
24203 | as_bad_where (fixp->fx_file, fixp->fx_line, |
24204 | _("undefined local label `%s'"), | |
24205 | S_GET_NAME (fixp->fx_addsy)); | |
24206 | return NULL; | |
a737bd4d NC |
24207 | } |
24208 | ||
c19d1205 ZW |
24209 | as_bad_where (fixp->fx_file, fixp->fx_line, |
24210 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
24211 | return NULL; | |
a737bd4d | 24212 | |
c19d1205 ZW |
24213 | default: |
24214 | { | |
e0471c16 | 24215 | const char * type; |
6c43fab6 | 24216 | |
c19d1205 ZW |
24217 | switch (fixp->fx_r_type) |
24218 | { | |
24219 | case BFD_RELOC_NONE: type = "NONE"; break; | |
24220 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
24221 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 24222 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
24223 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
24224 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
24225 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 24226 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 24227 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
24228 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
24229 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
24230 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
24231 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
24232 | default: type = _("<unknown>"); break; | |
24233 | } | |
24234 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
24235 | _("cannot represent %s relocation in this object file format"), | |
24236 | type); | |
24237 | return NULL; | |
24238 | } | |
a737bd4d | 24239 | } |
6c43fab6 | 24240 | |
c19d1205 ZW |
24241 | #ifdef OBJ_ELF |
24242 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
24243 | && GOT_symbol | |
24244 | && fixp->fx_addsy == GOT_symbol) | |
24245 | { | |
24246 | code = BFD_RELOC_ARM_GOTPC; | |
24247 | reloc->addend = fixp->fx_offset = reloc->address; | |
24248 | } | |
24249 | #endif | |
6c43fab6 | 24250 | |
c19d1205 | 24251 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 24252 | |
c19d1205 ZW |
24253 | if (reloc->howto == NULL) |
24254 | { | |
24255 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
24256 | _("cannot represent %s relocation in this object file format"), | |
24257 | bfd_get_reloc_code_name (code)); | |
24258 | return NULL; | |
24259 | } | |
6c43fab6 | 24260 | |
c19d1205 ZW |
24261 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
24262 | vtable entry to be used in the relocation's section offset. */ | |
24263 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
24264 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 24265 | |
c19d1205 | 24266 | return reloc; |
6c43fab6 RE |
24267 | } |
24268 | ||
c19d1205 | 24269 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 24270 | |
c19d1205 ZW |
24271 | void |
24272 | cons_fix_new_arm (fragS * frag, | |
24273 | int where, | |
24274 | int size, | |
62ebcb5c AM |
24275 | expressionS * exp, |
24276 | bfd_reloc_code_real_type reloc) | |
6c43fab6 | 24277 | { |
c19d1205 | 24278 | int pcrel = 0; |
6c43fab6 | 24279 | |
c19d1205 ZW |
24280 | /* Pick a reloc. |
24281 | FIXME: @@ Should look at CPU word size. */ | |
24282 | switch (size) | |
24283 | { | |
24284 | case 1: | |
62ebcb5c | 24285 | reloc = BFD_RELOC_8; |
c19d1205 ZW |
24286 | break; |
24287 | case 2: | |
62ebcb5c | 24288 | reloc = BFD_RELOC_16; |
c19d1205 ZW |
24289 | break; |
24290 | case 4: | |
24291 | default: | |
62ebcb5c | 24292 | reloc = BFD_RELOC_32; |
c19d1205 ZW |
24293 | break; |
24294 | case 8: | |
62ebcb5c | 24295 | reloc = BFD_RELOC_64; |
c19d1205 ZW |
24296 | break; |
24297 | } | |
6c43fab6 | 24298 | |
f0927246 NC |
24299 | #ifdef TE_PE |
24300 | if (exp->X_op == O_secrel) | |
24301 | { | |
24302 | exp->X_op = O_symbol; | |
62ebcb5c | 24303 | reloc = BFD_RELOC_32_SECREL; |
f0927246 NC |
24304 | } |
24305 | #endif | |
24306 | ||
62ebcb5c | 24307 | fix_new_exp (frag, where, size, exp, pcrel, reloc); |
c19d1205 | 24308 | } |
6c43fab6 | 24309 | |
4343666d | 24310 | #if defined (OBJ_COFF) |
c19d1205 ZW |
24311 | void |
24312 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 24313 | { |
c19d1205 ZW |
24314 | /* If the destination of the branch is a defined symbol which does not have |
24315 | the THUMB_FUNC attribute, then we must be calling a function which has | |
24316 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
24317 | function and change the branch to refer to that function instead. */ | |
24318 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
24319 | && fixP->fx_addsy != NULL | |
24320 | && S_IS_DEFINED (fixP->fx_addsy) | |
24321 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 24322 | { |
c19d1205 | 24323 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 24324 | } |
c19d1205 ZW |
24325 | } |
24326 | #endif | |
6c43fab6 | 24327 | |
267bf995 | 24328 | |
c19d1205 ZW |
24329 | int |
24330 | arm_force_relocation (struct fix * fixp) | |
24331 | { | |
24332 | #if defined (OBJ_COFF) && defined (TE_PE) | |
24333 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
24334 | return 1; | |
24335 | #endif | |
6c43fab6 | 24336 | |
267bf995 RR |
24337 | /* In case we have a call or a branch to a function in ARM ISA mode from |
24338 | a thumb function or vice-versa force the relocation. These relocations | |
24339 | are cleared off for some cores that might have blx and simple transformations | |
24340 | are possible. */ | |
24341 | ||
24342 | #ifdef OBJ_ELF | |
24343 | switch (fixp->fx_r_type) | |
24344 | { | |
24345 | case BFD_RELOC_ARM_PCREL_JUMP: | |
24346 | case BFD_RELOC_ARM_PCREL_CALL: | |
24347 | case BFD_RELOC_THUMB_PCREL_BLX: | |
24348 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
24349 | return 1; | |
24350 | break; | |
24351 | ||
24352 | case BFD_RELOC_ARM_PCREL_BLX: | |
24353 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
24354 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
24355 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
24356 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
24357 | return 1; | |
24358 | break; | |
24359 | ||
24360 | default: | |
24361 | break; | |
24362 | } | |
24363 | #endif | |
24364 | ||
b5884301 PB |
24365 | /* Resolve these relocations even if the symbol is extern or weak. |
24366 | Technically this is probably wrong due to symbol preemption. | |
24367 | In practice these relocations do not have enough range to be useful | |
24368 | at dynamic link time, and some code (e.g. in the Linux kernel) | |
24369 | expects these references to be resolved. */ | |
c19d1205 ZW |
24370 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
24371 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 24372 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 24373 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
24374 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
24375 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2 | |
24376 | || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET | |
16805f35 | 24377 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
24378 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
24379 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
24380 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM |
24381 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12 | |
24382 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM | |
24383 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2) | |
c19d1205 | 24384 | return 0; |
a737bd4d | 24385 | |
4962c51a MS |
24386 | /* Always leave these relocations for the linker. */ |
24387 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
24388 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
24389 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
24390 | return 1; | |
24391 | ||
f0291e4c PB |
24392 | /* Always generate relocations against function symbols. */ |
24393 | if (fixp->fx_r_type == BFD_RELOC_32 | |
24394 | && fixp->fx_addsy | |
24395 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
24396 | return 1; | |
24397 | ||
c19d1205 | 24398 | return generic_force_reloc (fixp); |
404ff6b5 AH |
24399 | } |
24400 | ||
0ffdc86c | 24401 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
24402 | /* Relocations against function names must be left unadjusted, |
24403 | so that the linker can use this information to generate interworking | |
24404 | stubs. The MIPS version of this function | |
c19d1205 ZW |
24405 | also prevents relocations that are mips-16 specific, but I do not |
24406 | know why it does this. | |
404ff6b5 | 24407 | |
c19d1205 ZW |
24408 | FIXME: |
24409 | There is one other problem that ought to be addressed here, but | |
24410 | which currently is not: Taking the address of a label (rather | |
24411 | than a function) and then later jumping to that address. Such | |
24412 | addresses also ought to have their bottom bit set (assuming that | |
24413 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 24414 | |
c19d1205 ZW |
24415 | bfd_boolean |
24416 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 24417 | { |
c19d1205 ZW |
24418 | if (fixP->fx_addsy == NULL) |
24419 | return 1; | |
404ff6b5 | 24420 | |
e28387c3 PB |
24421 | /* Preserve relocations against symbols with function type. */ |
24422 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 24423 | return FALSE; |
e28387c3 | 24424 | |
c19d1205 ZW |
24425 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
24426 | && fixP->fx_subsy == NULL) | |
c921be7d | 24427 | return FALSE; |
a737bd4d | 24428 | |
c19d1205 ZW |
24429 | /* We need the symbol name for the VTABLE entries. */ |
24430 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
24431 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 24432 | return FALSE; |
404ff6b5 | 24433 | |
c19d1205 ZW |
24434 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
24435 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
24436 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
24437 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
24438 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
24439 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
24440 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
24441 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
24442 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
0855e32b NS |
24443 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC |
24444 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL | |
24445 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL | |
24446 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ | |
24447 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
c19d1205 | 24448 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
c921be7d | 24449 | return FALSE; |
a737bd4d | 24450 | |
4962c51a MS |
24451 | /* Similarly for group relocations. */ |
24452 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
24453 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
24454 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 24455 | return FALSE; |
4962c51a | 24456 | |
79947c54 CD |
24457 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
24458 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
24459 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
24460 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
24461 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
24462 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
24463 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
24464 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
24465 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 24466 | return FALSE; |
79947c54 | 24467 | |
72d98d16 MG |
24468 | /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited |
24469 | offsets, so keep these symbols. */ | |
24470 | if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC | |
24471 | && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
24472 | return FALSE; | |
24473 | ||
c921be7d | 24474 | return TRUE; |
a737bd4d | 24475 | } |
0ffdc86c NC |
24476 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
24477 | ||
24478 | #ifdef OBJ_ELF | |
c19d1205 ZW |
24479 | const char * |
24480 | elf32_arm_target_format (void) | |
404ff6b5 | 24481 | { |
c19d1205 ZW |
24482 | #ifdef TE_SYMBIAN |
24483 | return (target_big_endian | |
24484 | ? "elf32-bigarm-symbian" | |
24485 | : "elf32-littlearm-symbian"); | |
24486 | #elif defined (TE_VXWORKS) | |
24487 | return (target_big_endian | |
24488 | ? "elf32-bigarm-vxworks" | |
24489 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
24490 | #elif defined (TE_NACL) |
24491 | return (target_big_endian | |
24492 | ? "elf32-bigarm-nacl" | |
24493 | : "elf32-littlearm-nacl"); | |
c19d1205 ZW |
24494 | #else |
24495 | if (target_big_endian) | |
24496 | return "elf32-bigarm"; | |
24497 | else | |
24498 | return "elf32-littlearm"; | |
24499 | #endif | |
404ff6b5 AH |
24500 | } |
24501 | ||
c19d1205 ZW |
24502 | void |
24503 | armelf_frob_symbol (symbolS * symp, | |
24504 | int * puntp) | |
404ff6b5 | 24505 | { |
c19d1205 ZW |
24506 | elf_frob_symbol (symp, puntp); |
24507 | } | |
24508 | #endif | |
404ff6b5 | 24509 | |
c19d1205 | 24510 | /* MD interface: Finalization. */ |
a737bd4d | 24511 | |
c19d1205 ZW |
24512 | void |
24513 | arm_cleanup (void) | |
24514 | { | |
24515 | literal_pool * pool; | |
a737bd4d | 24516 | |
e07e6e58 NC |
24517 | /* Ensure that all the IT blocks are properly closed. */ |
24518 | check_it_blocks_finished (); | |
24519 | ||
c19d1205 ZW |
24520 | for (pool = list_of_pools; pool; pool = pool->next) |
24521 | { | |
5f4273c7 | 24522 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
24523 | subseg_set (pool->section, pool->sub_section); |
24524 | #ifdef OBJ_ELF | |
24525 | arm_elf_change_section (); | |
24526 | #endif | |
24527 | s_ltorg (0); | |
24528 | } | |
404ff6b5 AH |
24529 | } |
24530 | ||
cd000bff DJ |
24531 | #ifdef OBJ_ELF |
24532 | /* Remove any excess mapping symbols generated for alignment frags in | |
24533 | SEC. We may have created a mapping symbol before a zero byte | |
24534 | alignment; remove it if there's a mapping symbol after the | |
24535 | alignment. */ | |
24536 | static void | |
24537 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
24538 | void *dummy ATTRIBUTE_UNUSED) | |
24539 | { | |
24540 | segment_info_type *seginfo = seg_info (sec); | |
24541 | fragS *fragp; | |
24542 | ||
24543 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
24544 | return; | |
24545 | ||
24546 | for (fragp = seginfo->frchainP->frch_root; | |
24547 | fragp != NULL; | |
24548 | fragp = fragp->fr_next) | |
24549 | { | |
24550 | symbolS *sym = fragp->tc_frag_data.last_map; | |
24551 | fragS *next = fragp->fr_next; | |
24552 | ||
24553 | /* Variable-sized frags have been converted to fixed size by | |
24554 | this point. But if this was variable-sized to start with, | |
24555 | there will be a fixed-size frag after it. So don't handle | |
24556 | next == NULL. */ | |
24557 | if (sym == NULL || next == NULL) | |
24558 | continue; | |
24559 | ||
24560 | if (S_GET_VALUE (sym) < next->fr_address) | |
24561 | /* Not at the end of this frag. */ | |
24562 | continue; | |
24563 | know (S_GET_VALUE (sym) == next->fr_address); | |
24564 | ||
24565 | do | |
24566 | { | |
24567 | if (next->tc_frag_data.first_map != NULL) | |
24568 | { | |
24569 | /* Next frag starts with a mapping symbol. Discard this | |
24570 | one. */ | |
24571 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
24572 | break; | |
24573 | } | |
24574 | ||
24575 | if (next->fr_next == NULL) | |
24576 | { | |
24577 | /* This mapping symbol is at the end of the section. Discard | |
24578 | it. */ | |
24579 | know (next->fr_fix == 0 && next->fr_var == 0); | |
24580 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
24581 | break; | |
24582 | } | |
24583 | ||
24584 | /* As long as we have empty frags without any mapping symbols, | |
24585 | keep looking. */ | |
24586 | /* If the next frag is non-empty and does not start with a | |
24587 | mapping symbol, then this mapping symbol is required. */ | |
24588 | if (next->fr_address != next->fr_next->fr_address) | |
24589 | break; | |
24590 | ||
24591 | next = next->fr_next; | |
24592 | } | |
24593 | while (next != NULL); | |
24594 | } | |
24595 | } | |
24596 | #endif | |
24597 | ||
c19d1205 ZW |
24598 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
24599 | ARM ones. */ | |
404ff6b5 | 24600 | |
c19d1205 ZW |
24601 | void |
24602 | arm_adjust_symtab (void) | |
404ff6b5 | 24603 | { |
c19d1205 ZW |
24604 | #ifdef OBJ_COFF |
24605 | symbolS * sym; | |
404ff6b5 | 24606 | |
c19d1205 ZW |
24607 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
24608 | { | |
24609 | if (ARM_IS_THUMB (sym)) | |
24610 | { | |
24611 | if (THUMB_IS_FUNC (sym)) | |
24612 | { | |
24613 | /* Mark the symbol as a Thumb function. */ | |
24614 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
24615 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
24616 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 24617 | |
c19d1205 ZW |
24618 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
24619 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
24620 | else | |
24621 | as_bad (_("%s: unexpected function type: %d"), | |
24622 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
24623 | } | |
24624 | else switch (S_GET_STORAGE_CLASS (sym)) | |
24625 | { | |
24626 | case C_EXT: | |
24627 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
24628 | break; | |
24629 | case C_STAT: | |
24630 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
24631 | break; | |
24632 | case C_LABEL: | |
24633 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
24634 | break; | |
24635 | default: | |
24636 | /* Do nothing. */ | |
24637 | break; | |
24638 | } | |
24639 | } | |
a737bd4d | 24640 | |
c19d1205 ZW |
24641 | if (ARM_IS_INTERWORK (sym)) |
24642 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 24643 | } |
c19d1205 ZW |
24644 | #endif |
24645 | #ifdef OBJ_ELF | |
24646 | symbolS * sym; | |
24647 | char bind; | |
404ff6b5 | 24648 | |
c19d1205 | 24649 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 24650 | { |
c19d1205 ZW |
24651 | if (ARM_IS_THUMB (sym)) |
24652 | { | |
24653 | elf_symbol_type * elf_sym; | |
404ff6b5 | 24654 | |
c19d1205 ZW |
24655 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
24656 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 24657 | |
b0796911 PB |
24658 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
24659 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
24660 | { |
24661 | /* If it's a .thumb_func, declare it as so, | |
24662 | otherwise tag label as .code 16. */ | |
24663 | if (THUMB_IS_FUNC (sym)) | |
35fc36a8 RS |
24664 | elf_sym->internal_elf_sym.st_target_internal |
24665 | = ST_BRANCH_TO_THUMB; | |
3ba67470 | 24666 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
24667 | elf_sym->internal_elf_sym.st_info = |
24668 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
24669 | } | |
24670 | } | |
24671 | } | |
cd000bff DJ |
24672 | |
24673 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
24674 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
24675 | /* Now do generic ELF adjustments. */ |
24676 | elf_adjust_symtab (); | |
c19d1205 | 24677 | #endif |
404ff6b5 AH |
24678 | } |
24679 | ||
c19d1205 | 24680 | /* MD interface: Initialization. */ |
404ff6b5 | 24681 | |
a737bd4d | 24682 | static void |
c19d1205 | 24683 | set_constant_flonums (void) |
a737bd4d | 24684 | { |
c19d1205 | 24685 | int i; |
404ff6b5 | 24686 | |
c19d1205 ZW |
24687 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
24688 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
24689 | abort (); | |
a737bd4d | 24690 | } |
404ff6b5 | 24691 | |
3e9e4fcf JB |
24692 | /* Auto-select Thumb mode if it's the only available instruction set for the |
24693 | given architecture. */ | |
24694 | ||
24695 | static void | |
24696 | autoselect_thumb_from_cpu_variant (void) | |
24697 | { | |
24698 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
24699 | opcode_select (16); | |
24700 | } | |
24701 | ||
c19d1205 ZW |
24702 | void |
24703 | md_begin (void) | |
a737bd4d | 24704 | { |
c19d1205 ZW |
24705 | unsigned mach; |
24706 | unsigned int i; | |
404ff6b5 | 24707 | |
c19d1205 ZW |
24708 | if ( (arm_ops_hsh = hash_new ()) == NULL |
24709 | || (arm_cond_hsh = hash_new ()) == NULL | |
24710 | || (arm_shift_hsh = hash_new ()) == NULL | |
24711 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 24712 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 24713 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
24714 | || (arm_reloc_hsh = hash_new ()) == NULL |
24715 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
24716 | as_fatal (_("virtual memory exhausted")); |
24717 | ||
24718 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 24719 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 24720 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 24721 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 24722 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 24723 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 24724 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 24725 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 24726 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 24727 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
477330fc | 24728 | (void *) (v7m_psrs + i)); |
c19d1205 | 24729 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 24730 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
24731 | for (i = 0; |
24732 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
24733 | i++) | |
d3ce72d0 | 24734 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 24735 | (void *) (barrier_opt_names + i)); |
c19d1205 | 24736 | #ifdef OBJ_ELF |
3da1d841 NC |
24737 | for (i = 0; i < ARRAY_SIZE (reloc_names); i++) |
24738 | { | |
24739 | struct reloc_entry * entry = reloc_names + i; | |
24740 | ||
24741 | if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32) | |
24742 | /* This makes encode_branch() use the EABI versions of this relocation. */ | |
24743 | entry->reloc = BFD_RELOC_UNUSED; | |
24744 | ||
24745 | hash_insert (arm_reloc_hsh, entry->name, (void *) entry); | |
24746 | } | |
c19d1205 ZW |
24747 | #endif |
24748 | ||
24749 | set_constant_flonums (); | |
404ff6b5 | 24750 | |
c19d1205 ZW |
24751 | /* Set the cpu variant based on the command-line options. We prefer |
24752 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
24753 | -mfpu= over any other way of setting the floating point unit. | |
24754 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 24755 | if (legacy_cpu) |
404ff6b5 | 24756 | { |
e74cfd16 | 24757 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
24758 | as_bad (_("use of old and new-style options to set CPU type")); |
24759 | ||
24760 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 24761 | } |
e74cfd16 | 24762 | else if (!mcpu_cpu_opt) |
c19d1205 | 24763 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 24764 | |
e74cfd16 | 24765 | if (legacy_fpu) |
c19d1205 | 24766 | { |
e74cfd16 | 24767 | if (mfpu_opt) |
c19d1205 | 24768 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
24769 | |
24770 | mfpu_opt = legacy_fpu; | |
24771 | } | |
e74cfd16 | 24772 | else if (!mfpu_opt) |
03b1477f | 24773 | { |
45eb4c1b NS |
24774 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
24775 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
24776 | /* Some environments specify a default FPU. If they don't, infer it |
24777 | from the processor. */ | |
e74cfd16 | 24778 | if (mcpu_fpu_opt) |
03b1477f RE |
24779 | mfpu_opt = mcpu_fpu_opt; |
24780 | else | |
24781 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 24782 | #else |
e74cfd16 | 24783 | mfpu_opt = &fpu_default; |
39c2da32 | 24784 | #endif |
03b1477f RE |
24785 | } |
24786 | ||
e74cfd16 | 24787 | if (!mfpu_opt) |
03b1477f | 24788 | { |
493cb6ef | 24789 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 24790 | mfpu_opt = &fpu_default; |
493cb6ef | 24791 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 24792 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 24793 | else |
e74cfd16 | 24794 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
24795 | } |
24796 | ||
ee065d83 | 24797 | #ifdef CPU_DEFAULT |
e74cfd16 | 24798 | if (!mcpu_cpu_opt) |
ee065d83 | 24799 | { |
e74cfd16 PB |
24800 | mcpu_cpu_opt = &cpu_default; |
24801 | selected_cpu = cpu_default; | |
ee065d83 | 24802 | } |
73f43896 NC |
24803 | else if (no_cpu_selected ()) |
24804 | selected_cpu = cpu_default; | |
e74cfd16 PB |
24805 | #else |
24806 | if (mcpu_cpu_opt) | |
24807 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 24808 | else |
e74cfd16 | 24809 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 24810 | #endif |
03b1477f | 24811 | |
e74cfd16 | 24812 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 24813 | |
3e9e4fcf JB |
24814 | autoselect_thumb_from_cpu_variant (); |
24815 | ||
e74cfd16 | 24816 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 24817 | |
f17c130b | 24818 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 24819 | { |
7cc69913 NC |
24820 | unsigned int flags = 0; |
24821 | ||
24822 | #if defined OBJ_ELF | |
24823 | flags = meabi_flags; | |
d507cf36 PB |
24824 | |
24825 | switch (meabi_flags) | |
33a392fb | 24826 | { |
d507cf36 | 24827 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 24828 | #endif |
d507cf36 PB |
24829 | /* Set the flags in the private structure. */ |
24830 | if (uses_apcs_26) flags |= F_APCS26; | |
24831 | if (support_interwork) flags |= F_INTERWORK; | |
24832 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 24833 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 24834 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
24835 | flags |= F_SOFT_FLOAT; |
24836 | ||
d507cf36 PB |
24837 | switch (mfloat_abi_opt) |
24838 | { | |
24839 | case ARM_FLOAT_ABI_SOFT: | |
24840 | case ARM_FLOAT_ABI_SOFTFP: | |
24841 | flags |= F_SOFT_FLOAT; | |
24842 | break; | |
33a392fb | 24843 | |
d507cf36 PB |
24844 | case ARM_FLOAT_ABI_HARD: |
24845 | if (flags & F_SOFT_FLOAT) | |
24846 | as_bad (_("hard-float conflicts with specified fpu")); | |
24847 | break; | |
24848 | } | |
03b1477f | 24849 | |
e74cfd16 PB |
24850 | /* Using pure-endian doubles (even if soft-float). */ |
24851 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 24852 | flags |= F_VFP_FLOAT; |
f17c130b | 24853 | |
fde78edd | 24854 | #if defined OBJ_ELF |
e74cfd16 | 24855 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 24856 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
24857 | break; |
24858 | ||
8cb51566 | 24859 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 24860 | case EF_ARM_EABI_VER5: |
c19d1205 | 24861 | /* No additional flags to set. */ |
d507cf36 PB |
24862 | break; |
24863 | ||
24864 | default: | |
24865 | abort (); | |
24866 | } | |
7cc69913 | 24867 | #endif |
b99bd4ef NC |
24868 | bfd_set_private_flags (stdoutput, flags); |
24869 | ||
24870 | /* We have run out flags in the COFF header to encode the | |
24871 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 24872 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
24873 | if (atpcs) |
24874 | { | |
24875 | asection * sec; | |
24876 | ||
24877 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
24878 | ||
24879 | if (sec != NULL) | |
24880 | { | |
24881 | bfd_set_section_flags | |
24882 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
24883 | bfd_set_section_size (stdoutput, sec, 0); | |
24884 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
24885 | } | |
24886 | } | |
7cc69913 | 24887 | } |
f17c130b | 24888 | #endif |
b99bd4ef NC |
24889 | |
24890 | /* Record the CPU type as well. */ | |
2d447fca JM |
24891 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
24892 | mach = bfd_mach_arm_iWMMXt2; | |
24893 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 24894 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 24895 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 24896 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 24897 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 24898 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 24899 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 24900 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 24901 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 24902 | { |
e74cfd16 | 24903 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
24904 | mach = bfd_mach_arm_5T; |
24905 | else | |
24906 | mach = bfd_mach_arm_5; | |
24907 | } | |
e74cfd16 | 24908 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 24909 | { |
e74cfd16 | 24910 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
24911 | mach = bfd_mach_arm_4T; |
24912 | else | |
24913 | mach = bfd_mach_arm_4; | |
24914 | } | |
e74cfd16 | 24915 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 24916 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
24917 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
24918 | mach = bfd_mach_arm_3; | |
24919 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
24920 | mach = bfd_mach_arm_2a; | |
24921 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
24922 | mach = bfd_mach_arm_2; | |
24923 | else | |
24924 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
24925 | |
24926 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
24927 | } | |
24928 | ||
c19d1205 | 24929 | /* Command line processing. */ |
b99bd4ef | 24930 | |
c19d1205 ZW |
24931 | /* md_parse_option |
24932 | Invocation line includes a switch not recognized by the base assembler. | |
24933 | See if it's a processor-specific option. | |
b99bd4ef | 24934 | |
c19d1205 ZW |
24935 | This routine is somewhat complicated by the need for backwards |
24936 | compatibility (since older releases of gcc can't be changed). | |
24937 | The new options try to make the interface as compatible as | |
24938 | possible with GCC. | |
b99bd4ef | 24939 | |
c19d1205 | 24940 | New options (supported) are: |
b99bd4ef | 24941 | |
c19d1205 ZW |
24942 | -mcpu=<cpu name> Assemble for selected processor |
24943 | -march=<architecture name> Assemble for selected architecture | |
24944 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
24945 | -EB/-mbig-endian Big-endian | |
24946 | -EL/-mlittle-endian Little-endian | |
24947 | -k Generate PIC code | |
24948 | -mthumb Start in Thumb mode | |
24949 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 24950 | |
278df34e | 24951 | -m[no-]warn-deprecated Warn about deprecated features |
8b2d793c | 24952 | -m[no-]warn-syms Warn when symbols match instructions |
267bf995 | 24953 | |
c19d1205 | 24954 | For now we will also provide support for: |
b99bd4ef | 24955 | |
c19d1205 ZW |
24956 | -mapcs-32 32-bit Program counter |
24957 | -mapcs-26 26-bit Program counter | |
24958 | -macps-float Floats passed in FP registers | |
24959 | -mapcs-reentrant Reentrant code | |
24960 | -matpcs | |
24961 | (sometime these will probably be replaced with -mapcs=<list of options> | |
24962 | and -matpcs=<list of options>) | |
b99bd4ef | 24963 | |
c19d1205 ZW |
24964 | The remaining options are only supported for back-wards compatibility. |
24965 | Cpu variants, the arm part is optional: | |
24966 | -m[arm]1 Currently not supported. | |
24967 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
24968 | -m[arm]3 Arm 3 processor | |
24969 | -m[arm]6[xx], Arm 6 processors | |
24970 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
24971 | -m[arm]8[10] Arm 8 processors | |
24972 | -m[arm]9[20][tdmi] Arm 9 processors | |
24973 | -mstrongarm[110[0]] StrongARM processors | |
24974 | -mxscale XScale processors | |
24975 | -m[arm]v[2345[t[e]]] Arm architectures | |
24976 | -mall All (except the ARM1) | |
24977 | FP variants: | |
24978 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
24979 | -mfpe-old (No float load/store multiples) | |
24980 | -mvfpxd VFP Single precision | |
24981 | -mvfp All VFP | |
24982 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 24983 | |
c19d1205 ZW |
24984 | The following CPU names are recognized: |
24985 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
24986 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
24987 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
24988 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
24989 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
24990 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
24991 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 24992 | |
c19d1205 | 24993 | */ |
b99bd4ef | 24994 | |
c19d1205 | 24995 | const char * md_shortopts = "m:k"; |
b99bd4ef | 24996 | |
c19d1205 ZW |
24997 | #ifdef ARM_BI_ENDIAN |
24998 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
24999 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 25000 | #else |
c19d1205 ZW |
25001 | #if TARGET_BYTES_BIG_ENDIAN |
25002 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 25003 | #else |
c19d1205 ZW |
25004 | #define OPTION_EL (OPTION_MD_BASE + 1) |
25005 | #endif | |
b99bd4ef | 25006 | #endif |
845b51d6 | 25007 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 25008 | |
c19d1205 | 25009 | struct option md_longopts[] = |
b99bd4ef | 25010 | { |
c19d1205 ZW |
25011 | #ifdef OPTION_EB |
25012 | {"EB", no_argument, NULL, OPTION_EB}, | |
25013 | #endif | |
25014 | #ifdef OPTION_EL | |
25015 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 25016 | #endif |
845b51d6 | 25017 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
25018 | {NULL, no_argument, NULL, 0} |
25019 | }; | |
b99bd4ef | 25020 | |
8b2d793c | 25021 | |
c19d1205 | 25022 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 25023 | |
c19d1205 | 25024 | struct arm_option_table |
b99bd4ef | 25025 | { |
e0471c16 TS |
25026 | const char *option; /* Option name to match. */ |
25027 | const char *help; /* Help information. */ | |
c19d1205 ZW |
25028 | int *var; /* Variable to change. */ |
25029 | int value; /* What to change it to. */ | |
e0471c16 | 25030 | const char *deprecated; /* If non-null, print this message. */ |
c19d1205 | 25031 | }; |
b99bd4ef | 25032 | |
c19d1205 ZW |
25033 | struct arm_option_table arm_opts[] = |
25034 | { | |
25035 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
25036 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
25037 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
25038 | &support_interwork, 1, NULL}, | |
25039 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
25040 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
25041 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
25042 | 1, NULL}, | |
25043 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
25044 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
25045 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
25046 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
25047 | NULL}, | |
b99bd4ef | 25048 | |
c19d1205 ZW |
25049 | /* These are recognized by the assembler, but have no affect on code. */ |
25050 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
25051 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
25052 | |
25053 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
25054 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
25055 | &warn_on_deprecated, 0, NULL}, | |
8b2d793c NC |
25056 | {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL}, |
25057 | {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL}, | |
e74cfd16 PB |
25058 | {NULL, NULL, NULL, 0, NULL} |
25059 | }; | |
25060 | ||
25061 | struct arm_legacy_option_table | |
25062 | { | |
e0471c16 | 25063 | const char *option; /* Option name to match. */ |
e74cfd16 PB |
25064 | const arm_feature_set **var; /* Variable to change. */ |
25065 | const arm_feature_set value; /* What to change it to. */ | |
e0471c16 | 25066 | const char *deprecated; /* If non-null, print this message. */ |
e74cfd16 | 25067 | }; |
b99bd4ef | 25068 | |
e74cfd16 PB |
25069 | const struct arm_legacy_option_table arm_legacy_opts[] = |
25070 | { | |
c19d1205 ZW |
25071 | /* DON'T add any new processors to this list -- we want the whole list |
25072 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
25073 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
25074 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
25075 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
25076 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
25077 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
25078 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
25079 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
25080 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
25081 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
25082 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
25083 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
25084 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
25085 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
25086 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
25087 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
25088 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
25089 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
25090 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
25091 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
25092 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
25093 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
25094 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
25095 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
25096 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
25097 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
25098 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
25099 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
25100 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
25101 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
25102 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
25103 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
25104 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
25105 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
25106 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
25107 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
25108 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
25109 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
25110 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
25111 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
25112 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
25113 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
25114 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
25115 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
25116 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
25117 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
25118 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
25119 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
25120 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
25121 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
25122 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
25123 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
25124 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
25125 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
25126 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
25127 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
25128 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
25129 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
25130 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
25131 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
25132 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
25133 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
25134 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
25135 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
25136 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
25137 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
25138 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
25139 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
25140 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
25141 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
25142 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 25143 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 25144 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 25145 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 25146 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 25147 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
25148 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
25149 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
25150 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 25151 | |
c19d1205 | 25152 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
25153 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
25154 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
25155 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
25156 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
25157 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
25158 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
25159 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
25160 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
25161 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
25162 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
25163 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
25164 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
25165 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
25166 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
25167 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
25168 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
25169 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
25170 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 25171 | |
c19d1205 | 25172 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
25173 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
25174 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
25175 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
25176 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 25177 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 25178 | |
e74cfd16 | 25179 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 25180 | }; |
7ed4c4c5 | 25181 | |
c19d1205 | 25182 | struct arm_cpu_option_table |
7ed4c4c5 | 25183 | { |
e0471c16 | 25184 | const char *name; |
f3bad469 | 25185 | size_t name_len; |
e74cfd16 | 25186 | const arm_feature_set value; |
c19d1205 ZW |
25187 | /* For some CPUs we assume an FPU unless the user explicitly sets |
25188 | -mfpu=... */ | |
e74cfd16 | 25189 | const arm_feature_set default_fpu; |
ee065d83 PB |
25190 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
25191 | case. */ | |
25192 | const char *canonical_name; | |
c19d1205 | 25193 | }; |
7ed4c4c5 | 25194 | |
c19d1205 ZW |
25195 | /* This list should, at a minimum, contain all the cpu names |
25196 | recognized by GCC. */ | |
f3bad469 | 25197 | #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN } |
e74cfd16 | 25198 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 25199 | { |
f3bad469 MGD |
25200 | ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL), |
25201 | ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL), | |
25202 | ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL), | |
25203 | ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL), | |
25204 | ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL), | |
25205 | ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25206 | ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25207 | ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25208 | ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25209 | ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25210 | ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25211 | ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
25212 | ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25213 | ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
25214 | ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25215 | ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
25216 | ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25217 | ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25218 | ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25219 | ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25220 | ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25221 | ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25222 | ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25223 | ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25224 | ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25225 | ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25226 | ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25227 | ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
25228 | ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25229 | ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25230 | ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25231 | ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25232 | ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25233 | ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25234 | ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25235 | ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25236 | ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25237 | ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25238 | ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25239 | ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"), | |
25240 | ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25241 | ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25242 | ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25243 | ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
25244 | ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
25245 | ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
c19d1205 ZW |
25246 | /* For V5 or later processors we default to using VFP; but the user |
25247 | should really set the FPU type explicitly. */ | |
f3bad469 MGD |
25248 | ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), |
25249 | ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25250 | ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"), | |
25251 | ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"), | |
25252 | ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL), | |
25253 | ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), | |
25254 | ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"), | |
25255 | ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25256 | ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), | |
25257 | ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"), | |
25258 | ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25259 | ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25260 | ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
25261 | ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
25262 | ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25263 | ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"), | |
25264 | ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
25265 | ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25266 | ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25267 | ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, | |
25268 | "ARM1026EJ-S"), | |
25269 | ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL), | |
25270 | ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25271 | ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25272 | ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25273 | ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25274 | ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
25275 | ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"), | |
25276 | ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL), | |
25277 | ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, | |
25278 | "ARM1136JF-S"), | |
25279 | ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL), | |
25280 | ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"), | |
25281 | ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"), | |
25282 | ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL), | |
25283 | ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL), | |
f33026a9 MW |
25284 | ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL), |
25285 | ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL), | |
f3bad469 MGD |
25286 | ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC, |
25287 | FPU_NONE, "Cortex-A5"), | |
c9fb6e58 | 25288 | ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
f3bad469 MGD |
25289 | "Cortex-A7"), |
25290 | ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC, | |
823d2571 | 25291 | ARM_FEATURE_COPROC (FPU_VFP_V3 |
477330fc | 25292 | | FPU_NEON_EXT_V1), |
f3bad469 MGD |
25293 | "Cortex-A8"), |
25294 | ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC, | |
823d2571 | 25295 | ARM_FEATURE_COPROC (FPU_VFP_V3 |
477330fc | 25296 | | FPU_NEON_EXT_V1), |
f3bad469 | 25297 | "Cortex-A9"), |
c9fb6e58 | 25298 | ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
63a4bc21 | 25299 | "Cortex-A12"), |
c9fb6e58 | 25300 | ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
f3bad469 | 25301 | "Cortex-A15"), |
d7adf960 KT |
25302 | ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
25303 | "Cortex-A17"), | |
6735952f KT |
25304 | ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
25305 | "Cortex-A32"), | |
43cdc0a8 RR |
25306 | ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
25307 | "Cortex-A35"), | |
92eb40d9 | 25308 | ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
477330fc | 25309 | "Cortex-A53"), |
92eb40d9 | 25310 | ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
477330fc | 25311 | "Cortex-A57"), |
b19f47ad JW |
25312 | ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
25313 | "Cortex-A72"), | |
f3bad469 MGD |
25314 | ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"), |
25315 | ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, | |
25316 | "Cortex-R4F"), | |
25317 | ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV, | |
25318 | FPU_NONE, "Cortex-R5"), | |
70a8bc5b | 25319 | ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV, |
25320 | FPU_ARCH_VFP_V3D16, | |
25321 | "Cortex-R7"), | |
5f474010 TP |
25322 | ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV, |
25323 | FPU_ARCH_VFP_V3D16, | |
25324 | "Cortex-R8"), | |
a715796b | 25325 | ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"), |
f3bad469 MGD |
25326 | ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"), |
25327 | ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"), | |
25328 | ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"), | |
25329 | ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"), | |
ce32bd10 | 25330 | ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"), |
246496bb EM |
25331 | ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
25332 | "Samsung " \ | |
25333 | "Exynos M1"), | |
6b21c2bf JW |
25334 | ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
25335 | "Qualcomm " | |
25336 | "QDF24XX"), | |
25337 | ||
c19d1205 | 25338 | /* ??? XSCALE is really an architecture. */ |
f3bad469 | 25339 | ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL), |
c19d1205 | 25340 | /* ??? iwmmxt is not a processor. */ |
f3bad469 MGD |
25341 | ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL), |
25342 | ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL), | |
25343 | ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL), | |
c19d1205 | 25344 | /* Maverick */ |
823d2571 | 25345 | ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), |
da4339ed NC |
25346 | FPU_ARCH_MAVERICK, "ARM920T"), |
25347 | /* Marvell processors. */ | |
ff8646ee TP |
25348 | ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP |
25349 | | ARM_EXT_SEC, | |
25350 | ARM_EXT2_V6T2_V8M), | |
477330fc | 25351 | FPU_ARCH_VFP_V3D16, NULL), |
ff8646ee TP |
25352 | ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP |
25353 | | ARM_EXT_SEC, | |
25354 | ARM_EXT2_V6T2_V8M), | |
4347085a | 25355 | FPU_ARCH_NEON_VFP_V4, NULL), |
ea0d6bb9 PT |
25356 | /* APM X-Gene family. */ |
25357 | ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
25358 | "APM X-Gene 1"), | |
25359 | ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
25360 | "APM X-Gene 2"), | |
da4339ed | 25361 | |
f3bad469 | 25362 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 25363 | }; |
f3bad469 | 25364 | #undef ARM_CPU_OPT |
7ed4c4c5 | 25365 | |
c19d1205 | 25366 | struct arm_arch_option_table |
7ed4c4c5 | 25367 | { |
e0471c16 | 25368 | const char *name; |
f3bad469 | 25369 | size_t name_len; |
e74cfd16 PB |
25370 | const arm_feature_set value; |
25371 | const arm_feature_set default_fpu; | |
c19d1205 | 25372 | }; |
7ed4c4c5 | 25373 | |
c19d1205 ZW |
25374 | /* This list should, at a minimum, contain all the architecture names |
25375 | recognized by GCC. */ | |
f3bad469 | 25376 | #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF } |
e74cfd16 | 25377 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 25378 | { |
f3bad469 MGD |
25379 | ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA), |
25380 | ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA), | |
25381 | ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA), | |
25382 | ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
25383 | ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
25384 | ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA), | |
25385 | ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA), | |
25386 | ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA), | |
25387 | ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA), | |
25388 | ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA), | |
25389 | ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA), | |
25390 | ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP), | |
25391 | ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP), | |
25392 | ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP), | |
25393 | ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP), | |
25394 | ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP), | |
25395 | ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP), | |
25396 | ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP), | |
25397 | ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP), | |
25398 | ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP), | |
25399 | ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP), | |
f33026a9 MW |
25400 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is |
25401 | kept to preserve existing behaviour. */ | |
25402 | ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP), | |
25403 | ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP), | |
f3bad469 MGD |
25404 | ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP), |
25405 | ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP), | |
25406 | ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP), | |
f33026a9 MW |
25407 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is |
25408 | kept to preserve existing behaviour. */ | |
25409 | ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP), | |
25410 | ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP), | |
f3bad469 MGD |
25411 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), |
25412 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
25413 | ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP), | |
c450d570 PB |
25414 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
25415 | Accept the non-dashed form for compatibility with old toolchains. */ | |
f3bad469 | 25416 | ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP), |
c9fb6e58 | 25417 | ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP), |
f3bad469 MGD |
25418 | ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP), |
25419 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), | |
25420 | ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP), | |
25421 | ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP), | |
25422 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), | |
25423 | ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP), | |
ff8646ee | 25424 | ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP), |
4ed7ed8d | 25425 | ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP), |
bca38921 | 25426 | ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP), |
a5932920 | 25427 | ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP), |
56a1b672 | 25428 | ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP), |
f3bad469 MGD |
25429 | ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP), |
25430 | ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP), | |
25431 | ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP), | |
25432 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
c19d1205 | 25433 | }; |
f3bad469 | 25434 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 25435 | |
69133863 MGD |
25436 | /* ISA extensions in the co-processor and main instruction set space. */ |
25437 | struct arm_option_extension_value_table | |
c19d1205 | 25438 | { |
e0471c16 | 25439 | const char *name; |
f3bad469 | 25440 | size_t name_len; |
5a70a223 JB |
25441 | const arm_feature_set merge_value; |
25442 | const arm_feature_set clear_value; | |
69133863 | 25443 | const arm_feature_set allowed_archs; |
c19d1205 | 25444 | }; |
7ed4c4c5 | 25445 | |
69133863 MGD |
25446 | /* The following table must be in alphabetical order with a NULL last entry. |
25447 | */ | |
5a70a223 | 25448 | #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA } |
69133863 | 25449 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 25450 | { |
823d2571 TG |
25451 | ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8), |
25452 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
bca38921 | 25453 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
823d2571 TG |
25454 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8), |
25455 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
25456 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8), | |
25457 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
b8ec4e87 JW |
25458 | ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), |
25459 | ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST), | |
25460 | ARM_ARCH_V8_2A), | |
823d2571 TG |
25461 | ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), |
25462 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), | |
25463 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)), | |
25464 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), | |
25465 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY), | |
25466 | ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), | |
25467 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY), | |
25468 | ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), | |
25469 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY), | |
25470 | ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
25471 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
25472 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)), | |
823d2571 TG |
25473 | ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS), |
25474 | ARM_FEATURE_CORE_LOW (ARM_EXT_OS), | |
25475 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)), | |
ddfded2f MW |
25476 | ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN), |
25477 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0), | |
25478 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
643afb90 MW |
25479 | ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1, |
25480 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA), | |
25481 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
25482 | ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
25483 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), | |
25484 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)), | |
643afb90 MW |
25485 | ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8, |
25486 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8), | |
25487 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
25488 | ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV |
25489 | | ARM_EXT_DIV), | |
25490 | ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT), | |
25491 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
25492 | ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), | |
25493 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY), | |
5a70a223 | 25494 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE } |
69133863 | 25495 | }; |
f3bad469 | 25496 | #undef ARM_EXT_OPT |
69133863 MGD |
25497 | |
25498 | /* ISA floating-point and Advanced SIMD extensions. */ | |
25499 | struct arm_option_fpu_value_table | |
25500 | { | |
e0471c16 | 25501 | const char *name; |
69133863 | 25502 | const arm_feature_set value; |
c19d1205 | 25503 | }; |
7ed4c4c5 | 25504 | |
c19d1205 ZW |
25505 | /* This list should, at a minimum, contain all the fpu names |
25506 | recognized by GCC. */ | |
69133863 | 25507 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
25508 | { |
25509 | {"softfpa", FPU_NONE}, | |
25510 | {"fpe", FPU_ARCH_FPE}, | |
25511 | {"fpe2", FPU_ARCH_FPE}, | |
25512 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
25513 | {"fpa", FPU_ARCH_FPA}, | |
25514 | {"fpa10", FPU_ARCH_FPA}, | |
25515 | {"fpa11", FPU_ARCH_FPA}, | |
25516 | {"arm7500fe", FPU_ARCH_FPA}, | |
25517 | {"softvfp", FPU_ARCH_VFP}, | |
25518 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
25519 | {"vfp", FPU_ARCH_VFP_V2}, | |
25520 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 25521 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
25522 | {"vfp10", FPU_ARCH_VFP_V2}, |
25523 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
25524 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
25525 | {"vfpv2", FPU_ARCH_VFP_V2}, |
25526 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 25527 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 25528 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
25529 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
25530 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
25531 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
25532 | {"arm1020t", FPU_ARCH_VFP_V1}, |
25533 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
25534 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
25535 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
25536 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 25537 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 25538 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
25539 | {"vfpv4", FPU_ARCH_VFP_V4}, |
25540 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 25541 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
a715796b TG |
25542 | {"fpv5-d16", FPU_ARCH_VFP_V5D16}, |
25543 | {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16}, | |
62f3b8c8 | 25544 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
25545 | {"fp-armv8", FPU_ARCH_VFP_ARMV8}, |
25546 | {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8}, | |
25547 | {"crypto-neon-fp-armv8", | |
25548 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8}, | |
d6b4b13e | 25549 | {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1}, |
081e4c7d MW |
25550 | {"crypto-neon-fp-armv8.1", |
25551 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1}, | |
e74cfd16 PB |
25552 | {NULL, ARM_ARCH_NONE} |
25553 | }; | |
25554 | ||
25555 | struct arm_option_value_table | |
25556 | { | |
e0471c16 | 25557 | const char *name; |
e74cfd16 | 25558 | long value; |
c19d1205 | 25559 | }; |
7ed4c4c5 | 25560 | |
e74cfd16 | 25561 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
25562 | { |
25563 | {"hard", ARM_FLOAT_ABI_HARD}, | |
25564 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
25565 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 25566 | {NULL, 0} |
c19d1205 | 25567 | }; |
7ed4c4c5 | 25568 | |
c19d1205 | 25569 | #ifdef OBJ_ELF |
3a4a14e9 | 25570 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 25571 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
25572 | { |
25573 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
25574 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 25575 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 25576 | {NULL, 0} |
c19d1205 ZW |
25577 | }; |
25578 | #endif | |
7ed4c4c5 | 25579 | |
c19d1205 ZW |
25580 | struct arm_long_option_table |
25581 | { | |
e0471c16 TS |
25582 | const char * option; /* Substring to match. */ |
25583 | const char * help; /* Help information. */ | |
17b9d67d | 25584 | int (* func) (const char * subopt); /* Function to decode sub-option. */ |
e0471c16 | 25585 | const char * deprecated; /* If non-null, print this message. */ |
c19d1205 | 25586 | }; |
7ed4c4c5 | 25587 | |
c921be7d | 25588 | static bfd_boolean |
82b8a785 | 25589 | arm_parse_extension (const char *str, const arm_feature_set **opt_p) |
7ed4c4c5 | 25590 | { |
21d799b5 NC |
25591 | arm_feature_set *ext_set = (arm_feature_set *) |
25592 | xmalloc (sizeof (arm_feature_set)); | |
e74cfd16 | 25593 | |
69133863 | 25594 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
25595 | extensions being added before being removed. We achieve this by having |
25596 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 25597 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 25598 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
25599 | -1 -> 1 -> 0. */ |
25600 | const struct arm_option_extension_value_table * opt = NULL; | |
25601 | int adding_value = -1; | |
25602 | ||
e74cfd16 PB |
25603 | /* Copy the feature set, so that we can modify it. */ |
25604 | *ext_set = **opt_p; | |
25605 | *opt_p = ext_set; | |
25606 | ||
c19d1205 | 25607 | while (str != NULL && *str != 0) |
7ed4c4c5 | 25608 | { |
82b8a785 | 25609 | const char *ext; |
f3bad469 | 25610 | size_t len; |
7ed4c4c5 | 25611 | |
c19d1205 ZW |
25612 | if (*str != '+') |
25613 | { | |
25614 | as_bad (_("invalid architectural extension")); | |
c921be7d | 25615 | return FALSE; |
c19d1205 | 25616 | } |
7ed4c4c5 | 25617 | |
c19d1205 ZW |
25618 | str++; |
25619 | ext = strchr (str, '+'); | |
7ed4c4c5 | 25620 | |
c19d1205 | 25621 | if (ext != NULL) |
f3bad469 | 25622 | len = ext - str; |
c19d1205 | 25623 | else |
f3bad469 | 25624 | len = strlen (str); |
7ed4c4c5 | 25625 | |
f3bad469 | 25626 | if (len >= 2 && strncmp (str, "no", 2) == 0) |
69133863 MGD |
25627 | { |
25628 | if (adding_value != 0) | |
25629 | { | |
25630 | adding_value = 0; | |
25631 | opt = arm_extensions; | |
25632 | } | |
25633 | ||
f3bad469 | 25634 | len -= 2; |
69133863 MGD |
25635 | str += 2; |
25636 | } | |
f3bad469 | 25637 | else if (len > 0) |
69133863 MGD |
25638 | { |
25639 | if (adding_value == -1) | |
25640 | { | |
25641 | adding_value = 1; | |
25642 | opt = arm_extensions; | |
25643 | } | |
25644 | else if (adding_value != 1) | |
25645 | { | |
25646 | as_bad (_("must specify extensions to add before specifying " | |
25647 | "those to remove")); | |
25648 | return FALSE; | |
25649 | } | |
25650 | } | |
25651 | ||
f3bad469 | 25652 | if (len == 0) |
c19d1205 ZW |
25653 | { |
25654 | as_bad (_("missing architectural extension")); | |
c921be7d | 25655 | return FALSE; |
c19d1205 | 25656 | } |
7ed4c4c5 | 25657 | |
69133863 MGD |
25658 | gas_assert (adding_value != -1); |
25659 | gas_assert (opt != NULL); | |
25660 | ||
25661 | /* Scan over the options table trying to find an exact match. */ | |
25662 | for (; opt->name != NULL; opt++) | |
f3bad469 | 25663 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 25664 | { |
69133863 MGD |
25665 | /* Check we can apply the extension to this architecture. */ |
25666 | if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs)) | |
25667 | { | |
25668 | as_bad (_("extension does not apply to the base architecture")); | |
25669 | return FALSE; | |
25670 | } | |
25671 | ||
25672 | /* Add or remove the extension. */ | |
25673 | if (adding_value) | |
5a70a223 | 25674 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value); |
69133863 | 25675 | else |
5a70a223 | 25676 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value); |
69133863 | 25677 | |
c19d1205 ZW |
25678 | break; |
25679 | } | |
7ed4c4c5 | 25680 | |
c19d1205 ZW |
25681 | if (opt->name == NULL) |
25682 | { | |
69133863 MGD |
25683 | /* Did we fail to find an extension because it wasn't specified in |
25684 | alphabetical order, or because it does not exist? */ | |
25685 | ||
25686 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
f3bad469 | 25687 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
25688 | break; |
25689 | ||
25690 | if (opt->name == NULL) | |
25691 | as_bad (_("unknown architectural extension `%s'"), str); | |
25692 | else | |
25693 | as_bad (_("architectural extensions must be specified in " | |
25694 | "alphabetical order")); | |
25695 | ||
c921be7d | 25696 | return FALSE; |
c19d1205 | 25697 | } |
69133863 MGD |
25698 | else |
25699 | { | |
25700 | /* We should skip the extension we've just matched the next time | |
25701 | round. */ | |
25702 | opt++; | |
25703 | } | |
7ed4c4c5 | 25704 | |
c19d1205 ZW |
25705 | str = ext; |
25706 | }; | |
7ed4c4c5 | 25707 | |
c921be7d | 25708 | return TRUE; |
c19d1205 | 25709 | } |
7ed4c4c5 | 25710 | |
c921be7d | 25711 | static bfd_boolean |
17b9d67d | 25712 | arm_parse_cpu (const char *str) |
7ed4c4c5 | 25713 | { |
f3bad469 | 25714 | const struct arm_cpu_option_table *opt; |
82b8a785 | 25715 | const char *ext = strchr (str, '+'); |
f3bad469 | 25716 | size_t len; |
7ed4c4c5 | 25717 | |
c19d1205 | 25718 | if (ext != NULL) |
f3bad469 | 25719 | len = ext - str; |
7ed4c4c5 | 25720 | else |
f3bad469 | 25721 | len = strlen (str); |
7ed4c4c5 | 25722 | |
f3bad469 | 25723 | if (len == 0) |
7ed4c4c5 | 25724 | { |
c19d1205 | 25725 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 25726 | return FALSE; |
7ed4c4c5 NC |
25727 | } |
25728 | ||
c19d1205 | 25729 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 25730 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 25731 | { |
e74cfd16 PB |
25732 | mcpu_cpu_opt = &opt->value; |
25733 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 25734 | if (opt->canonical_name) |
ef8e6722 JW |
25735 | { |
25736 | gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name)); | |
25737 | strcpy (selected_cpu_name, opt->canonical_name); | |
25738 | } | |
ee065d83 PB |
25739 | else |
25740 | { | |
f3bad469 | 25741 | size_t i; |
c921be7d | 25742 | |
ef8e6722 JW |
25743 | if (len >= sizeof selected_cpu_name) |
25744 | len = (sizeof selected_cpu_name) - 1; | |
25745 | ||
f3bad469 | 25746 | for (i = 0; i < len; i++) |
ee065d83 PB |
25747 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
25748 | selected_cpu_name[i] = 0; | |
25749 | } | |
7ed4c4c5 | 25750 | |
c19d1205 ZW |
25751 | if (ext != NULL) |
25752 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 25753 | |
c921be7d | 25754 | return TRUE; |
c19d1205 | 25755 | } |
7ed4c4c5 | 25756 | |
c19d1205 | 25757 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 25758 | return FALSE; |
7ed4c4c5 NC |
25759 | } |
25760 | ||
c921be7d | 25761 | static bfd_boolean |
17b9d67d | 25762 | arm_parse_arch (const char *str) |
7ed4c4c5 | 25763 | { |
e74cfd16 | 25764 | const struct arm_arch_option_table *opt; |
82b8a785 | 25765 | const char *ext = strchr (str, '+'); |
f3bad469 | 25766 | size_t len; |
7ed4c4c5 | 25767 | |
c19d1205 | 25768 | if (ext != NULL) |
f3bad469 | 25769 | len = ext - str; |
7ed4c4c5 | 25770 | else |
f3bad469 | 25771 | len = strlen (str); |
7ed4c4c5 | 25772 | |
f3bad469 | 25773 | if (len == 0) |
7ed4c4c5 | 25774 | { |
c19d1205 | 25775 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 25776 | return FALSE; |
7ed4c4c5 NC |
25777 | } |
25778 | ||
c19d1205 | 25779 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 25780 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 25781 | { |
e74cfd16 PB |
25782 | march_cpu_opt = &opt->value; |
25783 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 25784 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 25785 | |
c19d1205 ZW |
25786 | if (ext != NULL) |
25787 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 25788 | |
c921be7d | 25789 | return TRUE; |
c19d1205 ZW |
25790 | } |
25791 | ||
25792 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 25793 | return FALSE; |
7ed4c4c5 | 25794 | } |
eb043451 | 25795 | |
c921be7d | 25796 | static bfd_boolean |
17b9d67d | 25797 | arm_parse_fpu (const char * str) |
c19d1205 | 25798 | { |
69133863 | 25799 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 25800 | |
c19d1205 ZW |
25801 | for (opt = arm_fpus; opt->name != NULL; opt++) |
25802 | if (streq (opt->name, str)) | |
25803 | { | |
e74cfd16 | 25804 | mfpu_opt = &opt->value; |
c921be7d | 25805 | return TRUE; |
c19d1205 | 25806 | } |
b99bd4ef | 25807 | |
c19d1205 | 25808 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 25809 | return FALSE; |
c19d1205 ZW |
25810 | } |
25811 | ||
c921be7d | 25812 | static bfd_boolean |
17b9d67d | 25813 | arm_parse_float_abi (const char * str) |
b99bd4ef | 25814 | { |
e74cfd16 | 25815 | const struct arm_option_value_table * opt; |
b99bd4ef | 25816 | |
c19d1205 ZW |
25817 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
25818 | if (streq (opt->name, str)) | |
25819 | { | |
25820 | mfloat_abi_opt = opt->value; | |
c921be7d | 25821 | return TRUE; |
c19d1205 | 25822 | } |
cc8a6dd0 | 25823 | |
c19d1205 | 25824 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 25825 | return FALSE; |
c19d1205 | 25826 | } |
b99bd4ef | 25827 | |
c19d1205 | 25828 | #ifdef OBJ_ELF |
c921be7d | 25829 | static bfd_boolean |
17b9d67d | 25830 | arm_parse_eabi (const char * str) |
c19d1205 | 25831 | { |
e74cfd16 | 25832 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 25833 | |
c19d1205 ZW |
25834 | for (opt = arm_eabis; opt->name != NULL; opt++) |
25835 | if (streq (opt->name, str)) | |
25836 | { | |
25837 | meabi_flags = opt->value; | |
c921be7d | 25838 | return TRUE; |
c19d1205 ZW |
25839 | } |
25840 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 25841 | return FALSE; |
c19d1205 ZW |
25842 | } |
25843 | #endif | |
cc8a6dd0 | 25844 | |
c921be7d | 25845 | static bfd_boolean |
17b9d67d | 25846 | arm_parse_it_mode (const char * str) |
e07e6e58 | 25847 | { |
c921be7d | 25848 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
25849 | |
25850 | if (streq ("arm", str)) | |
25851 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
25852 | else if (streq ("thumb", str)) | |
25853 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
25854 | else if (streq ("always", str)) | |
25855 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
25856 | else if (streq ("never", str)) | |
25857 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
25858 | else | |
25859 | { | |
25860 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
477330fc | 25861 | "arm, thumb, always, or never."), str); |
c921be7d | 25862 | ret = FALSE; |
e07e6e58 NC |
25863 | } |
25864 | ||
25865 | return ret; | |
25866 | } | |
25867 | ||
2e6976a8 | 25868 | static bfd_boolean |
17b9d67d | 25869 | arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED) |
2e6976a8 DG |
25870 | { |
25871 | codecomposer_syntax = TRUE; | |
25872 | arm_comment_chars[0] = ';'; | |
25873 | arm_line_separator_chars[0] = 0; | |
25874 | return TRUE; | |
25875 | } | |
25876 | ||
c19d1205 ZW |
25877 | struct arm_long_option_table arm_long_opts[] = |
25878 | { | |
25879 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
25880 | arm_parse_cpu, NULL}, | |
25881 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
25882 | arm_parse_arch, NULL}, | |
25883 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
25884 | arm_parse_fpu, NULL}, | |
25885 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
25886 | arm_parse_float_abi, NULL}, | |
25887 | #ifdef OBJ_ELF | |
7fac0536 | 25888 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
25889 | arm_parse_eabi, NULL}, |
25890 | #endif | |
e07e6e58 NC |
25891 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
25892 | arm_parse_it_mode, NULL}, | |
2e6976a8 DG |
25893 | {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"), |
25894 | arm_ccs_mode, NULL}, | |
c19d1205 ZW |
25895 | {NULL, NULL, 0, NULL} |
25896 | }; | |
cc8a6dd0 | 25897 | |
c19d1205 | 25898 | int |
17b9d67d | 25899 | md_parse_option (int c, const char * arg) |
c19d1205 ZW |
25900 | { |
25901 | struct arm_option_table *opt; | |
e74cfd16 | 25902 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 25903 | struct arm_long_option_table *lopt; |
b99bd4ef | 25904 | |
c19d1205 | 25905 | switch (c) |
b99bd4ef | 25906 | { |
c19d1205 ZW |
25907 | #ifdef OPTION_EB |
25908 | case OPTION_EB: | |
25909 | target_big_endian = 1; | |
25910 | break; | |
25911 | #endif | |
cc8a6dd0 | 25912 | |
c19d1205 ZW |
25913 | #ifdef OPTION_EL |
25914 | case OPTION_EL: | |
25915 | target_big_endian = 0; | |
25916 | break; | |
25917 | #endif | |
b99bd4ef | 25918 | |
845b51d6 PB |
25919 | case OPTION_FIX_V4BX: |
25920 | fix_v4bx = TRUE; | |
25921 | break; | |
25922 | ||
c19d1205 ZW |
25923 | case 'a': |
25924 | /* Listing option. Just ignore these, we don't support additional | |
25925 | ones. */ | |
25926 | return 0; | |
b99bd4ef | 25927 | |
c19d1205 ZW |
25928 | default: |
25929 | for (opt = arm_opts; opt->option != NULL; opt++) | |
25930 | { | |
25931 | if (c == opt->option[0] | |
25932 | && ((arg == NULL && opt->option[1] == 0) | |
25933 | || streq (arg, opt->option + 1))) | |
25934 | { | |
c19d1205 | 25935 | /* If the option is deprecated, tell the user. */ |
278df34e | 25936 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
25937 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
25938 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 25939 | |
c19d1205 ZW |
25940 | if (opt->var != NULL) |
25941 | *opt->var = opt->value; | |
cc8a6dd0 | 25942 | |
c19d1205 ZW |
25943 | return 1; |
25944 | } | |
25945 | } | |
b99bd4ef | 25946 | |
e74cfd16 PB |
25947 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
25948 | { | |
25949 | if (c == fopt->option[0] | |
25950 | && ((arg == NULL && fopt->option[1] == 0) | |
25951 | || streq (arg, fopt->option + 1))) | |
25952 | { | |
e74cfd16 | 25953 | /* If the option is deprecated, tell the user. */ |
278df34e | 25954 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
25955 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
25956 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
25957 | |
25958 | if (fopt->var != NULL) | |
25959 | *fopt->var = &fopt->value; | |
25960 | ||
25961 | return 1; | |
25962 | } | |
25963 | } | |
25964 | ||
c19d1205 ZW |
25965 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
25966 | { | |
25967 | /* These options are expected to have an argument. */ | |
25968 | if (c == lopt->option[0] | |
25969 | && arg != NULL | |
25970 | && strncmp (arg, lopt->option + 1, | |
25971 | strlen (lopt->option + 1)) == 0) | |
25972 | { | |
c19d1205 | 25973 | /* If the option is deprecated, tell the user. */ |
278df34e | 25974 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
25975 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
25976 | _(lopt->deprecated)); | |
b99bd4ef | 25977 | |
c19d1205 ZW |
25978 | /* Call the sup-option parser. */ |
25979 | return lopt->func (arg + strlen (lopt->option) - 1); | |
25980 | } | |
25981 | } | |
a737bd4d | 25982 | |
c19d1205 ZW |
25983 | return 0; |
25984 | } | |
a394c00f | 25985 | |
c19d1205 ZW |
25986 | return 1; |
25987 | } | |
a394c00f | 25988 | |
c19d1205 ZW |
25989 | void |
25990 | md_show_usage (FILE * fp) | |
a394c00f | 25991 | { |
c19d1205 ZW |
25992 | struct arm_option_table *opt; |
25993 | struct arm_long_option_table *lopt; | |
a394c00f | 25994 | |
c19d1205 | 25995 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 25996 | |
c19d1205 ZW |
25997 | for (opt = arm_opts; opt->option != NULL; opt++) |
25998 | if (opt->help != NULL) | |
25999 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 26000 | |
c19d1205 ZW |
26001 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
26002 | if (lopt->help != NULL) | |
26003 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 26004 | |
c19d1205 ZW |
26005 | #ifdef OPTION_EB |
26006 | fprintf (fp, _("\ | |
26007 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
26008 | #endif |
26009 | ||
c19d1205 ZW |
26010 | #ifdef OPTION_EL |
26011 | fprintf (fp, _("\ | |
26012 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 26013 | #endif |
845b51d6 PB |
26014 | |
26015 | fprintf (fp, _("\ | |
26016 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 26017 | } |
ee065d83 PB |
26018 | |
26019 | ||
26020 | #ifdef OBJ_ELF | |
62b3e311 PB |
26021 | typedef struct |
26022 | { | |
26023 | int val; | |
26024 | arm_feature_set flags; | |
26025 | } cpu_arch_ver_table; | |
26026 | ||
4ed7ed8d TP |
26027 | /* Mapping from CPU features to EABI CPU arch values. As a general rule, table |
26028 | must be sorted least features first but some reordering is needed, eg. for | |
26029 | Thumb-2 instructions to be detected as coming from ARMv6T2. */ | |
62b3e311 PB |
26030 | static const cpu_arch_ver_table cpu_arch_ver[] = |
26031 | { | |
26032 | {1, ARM_ARCH_V4}, | |
26033 | {2, ARM_ARCH_V4T}, | |
26034 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 26035 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
26036 | {4, ARM_ARCH_V5TE}, |
26037 | {5, ARM_ARCH_V5TEJ}, | |
26038 | {6, ARM_ARCH_V6}, | |
7e806470 | 26039 | {9, ARM_ARCH_V6K}, |
f4c65163 | 26040 | {7, ARM_ARCH_V6Z}, |
91e22acd | 26041 | {11, ARM_ARCH_V6M}, |
b2a5fbdc | 26042 | {12, ARM_ARCH_V6SM}, |
7e806470 | 26043 | {8, ARM_ARCH_V6T2}, |
c9fb6e58 | 26044 | {10, ARM_ARCH_V7VE}, |
62b3e311 PB |
26045 | {10, ARM_ARCH_V7R}, |
26046 | {10, ARM_ARCH_V7M}, | |
bca38921 | 26047 | {14, ARM_ARCH_V8A}, |
ff8646ee | 26048 | {16, ARM_ARCH_V8M_BASE}, |
4ed7ed8d | 26049 | {17, ARM_ARCH_V8M_MAIN}, |
62b3e311 PB |
26050 | {0, ARM_ARCH_NONE} |
26051 | }; | |
26052 | ||
ee3c0378 AS |
26053 | /* Set an attribute if it has not already been set by the user. */ |
26054 | static void | |
26055 | aeabi_set_attribute_int (int tag, int value) | |
26056 | { | |
26057 | if (tag < 1 | |
26058 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
26059 | || !attributes_set_explicitly[tag]) | |
26060 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
26061 | } | |
26062 | ||
26063 | static void | |
26064 | aeabi_set_attribute_string (int tag, const char *value) | |
26065 | { | |
26066 | if (tag < 1 | |
26067 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
26068 | || !attributes_set_explicitly[tag]) | |
26069 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
26070 | } | |
26071 | ||
ee065d83 | 26072 | /* Set the public EABI object attributes. */ |
3cfdb781 | 26073 | void |
ee065d83 PB |
26074 | aeabi_set_public_attributes (void) |
26075 | { | |
26076 | int arch; | |
69239280 | 26077 | char profile; |
90ec0d68 | 26078 | int virt_sec = 0; |
bca38921 | 26079 | int fp16_optional = 0; |
e74cfd16 | 26080 | arm_feature_set flags; |
62b3e311 | 26081 | arm_feature_set tmp; |
ff8646ee | 26082 | arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE; |
62b3e311 | 26083 | const cpu_arch_ver_table *p; |
ee065d83 PB |
26084 | |
26085 | /* Choose the architecture based on the capabilities of the requested cpu | |
26086 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
26087 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
26088 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
26089 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
ddd7f988 RE |
26090 | |
26091 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) | |
26092 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
26093 | ||
26094 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) | |
26095 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
26096 | ||
7f78eb34 JW |
26097 | selected_cpu = flags; |
26098 | ||
ddd7f988 | 26099 | /* Allow the user to override the reported architecture. */ |
7a1d4c38 PB |
26100 | if (object_arch) |
26101 | { | |
26102 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
26103 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
26104 | } | |
26105 | ||
251665fc MGD |
26106 | /* We need to make sure that the attributes do not identify us as v6S-M |
26107 | when the only v6S-M feature in use is the Operating System Extensions. */ | |
26108 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os)) | |
26109 | if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only)) | |
477330fc | 26110 | ARM_CLEAR_FEATURE (flags, flags, arm_ext_os); |
251665fc | 26111 | |
62b3e311 PB |
26112 | tmp = flags; |
26113 | arch = 0; | |
26114 | for (p = cpu_arch_ver; p->val; p++) | |
26115 | { | |
26116 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
26117 | { | |
26118 | arch = p->val; | |
26119 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
26120 | } | |
26121 | } | |
ee065d83 | 26122 | |
9e3c6df6 PB |
26123 | /* The table lookup above finds the last architecture to contribute |
26124 | a new feature. Unfortunately, Tag13 is a subset of the union of | |
26125 | v6T2 and v7-M, so it is never seen as contributing a new feature. | |
26126 | We can not search for the last entry which is entirely used, | |
26127 | because if no CPU is specified we build up only those flags | |
26128 | actually used. Perhaps we should separate out the specified | |
26129 | and implicit cases. Avoid taking this path for -march=all by | |
26130 | checking for contradictory v7-A / v7-M features. */ | |
4ed7ed8d | 26131 | if (arch == TAG_CPU_ARCH_V7 |
9e3c6df6 PB |
26132 | && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a) |
26133 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m) | |
26134 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp)) | |
4ed7ed8d TP |
26135 | arch = TAG_CPU_ARCH_V7E_M; |
26136 | ||
ff8646ee TP |
26137 | ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base); |
26138 | if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any)) | |
26139 | arch = TAG_CPU_ARCH_V8M_MAIN; | |
26140 | ||
4ed7ed8d TP |
26141 | /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as |
26142 | coming from ARMv8-A. However, since ARMv8-A has more instructions than | |
26143 | ARMv8-M, -march=all must be detected as ARMv8-A. */ | |
26144 | if (arch == TAG_CPU_ARCH_V8M_MAIN | |
26145 | && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) | |
26146 | arch = TAG_CPU_ARCH_V8; | |
9e3c6df6 | 26147 | |
ee065d83 PB |
26148 | /* Tag_CPU_name. */ |
26149 | if (selected_cpu_name[0]) | |
26150 | { | |
91d6fa6a | 26151 | char *q; |
ee065d83 | 26152 | |
91d6fa6a NC |
26153 | q = selected_cpu_name; |
26154 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
26155 | { |
26156 | int i; | |
5f4273c7 | 26157 | |
91d6fa6a NC |
26158 | q += 4; |
26159 | for (i = 0; q[i]; i++) | |
26160 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 26161 | } |
91d6fa6a | 26162 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 26163 | } |
62f3b8c8 | 26164 | |
ee065d83 | 26165 | /* Tag_CPU_arch. */ |
ee3c0378 | 26166 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 26167 | |
62b3e311 | 26168 | /* Tag_CPU_arch_profile. */ |
10c9892b | 26169 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a) |
4ed7ed8d TP |
26170 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
26171 | || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics) | |
26172 | && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))) | |
69239280 | 26173 | profile = 'A'; |
62b3e311 | 26174 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
69239280 | 26175 | profile = 'R'; |
7e806470 | 26176 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
69239280 MGD |
26177 | profile = 'M'; |
26178 | else | |
26179 | profile = '\0'; | |
26180 | ||
26181 | if (profile != '\0') | |
26182 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 26183 | |
ee065d83 | 26184 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
26185 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
26186 | || arch == 0) | |
26187 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
62f3b8c8 | 26188 | |
ee065d83 | 26189 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
26190 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
26191 | || arch == 0) | |
4ed7ed8d TP |
26192 | { |
26193 | int thumb_isa_use; | |
26194 | ||
26195 | if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) | |
26196 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
26197 | thumb_isa_use = 3; | |
26198 | else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2)) | |
26199 | thumb_isa_use = 2; | |
26200 | else | |
26201 | thumb_isa_use = 1; | |
26202 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use); | |
26203 | } | |
62f3b8c8 | 26204 | |
ee065d83 | 26205 | /* Tag_VFP_arch. */ |
a715796b TG |
26206 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd)) |
26207 | aeabi_set_attribute_int (Tag_VFP_arch, | |
26208 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
26209 | ? 7 : 8); | |
bca38921 | 26210 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
62f3b8c8 PB |
26211 | aeabi_set_attribute_int (Tag_VFP_arch, |
26212 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
26213 | ? 5 : 6); | |
26214 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
bca38921 MGD |
26215 | { |
26216 | fp16_optional = 1; | |
26217 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
26218 | } | |
ada65aa3 | 26219 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
26220 | { |
26221 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
26222 | fp16_optional = 1; | |
26223 | } | |
ee3c0378 AS |
26224 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) |
26225 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
26226 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
477330fc | 26227 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) |
ee3c0378 | 26228 | aeabi_set_attribute_int (Tag_VFP_arch, 1); |
62f3b8c8 | 26229 | |
4547cb56 NC |
26230 | /* Tag_ABI_HardFP_use. */ |
26231 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
26232 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
26233 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
26234 | ||
ee065d83 | 26235 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
26236 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
26237 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
26238 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
26239 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 26240 | |
ee3c0378 | 26241 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
9411fd44 MW |
26242 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1)) |
26243 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4); | |
26244 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8)) | |
bca38921 MGD |
26245 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3); |
26246 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) | |
26247 | { | |
26248 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)) | |
26249 | { | |
26250 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2); | |
26251 | } | |
26252 | else | |
26253 | { | |
26254 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); | |
26255 | fp16_optional = 1; | |
26256 | } | |
26257 | } | |
fa94de6b | 26258 | |
ee3c0378 | 26259 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 26260 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 26261 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 26262 | |
69239280 MGD |
26263 | /* Tag_DIV_use. |
26264 | ||
26265 | We set Tag_DIV_use to two when integer divide instructions have been used | |
26266 | in ARM state, or when Thumb integer divide instructions have been used, | |
26267 | but we have no architecture profile set, nor have we any ARM instructions. | |
26268 | ||
4ed7ed8d TP |
26269 | For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied |
26270 | by the base architecture. | |
bca38921 | 26271 | |
69239280 | 26272 | For new architectures we will have to check these tests. */ |
ff8646ee TP |
26273 | gas_assert (arch <= TAG_CPU_ARCH_V8 |
26274 | || (arch >= TAG_CPU_ARCH_V8M_BASE | |
26275 | && arch <= TAG_CPU_ARCH_V8M_MAIN)); | |
4ed7ed8d TP |
26276 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
26277 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
bca38921 MGD |
26278 | aeabi_set_attribute_int (Tag_DIV_use, 0); |
26279 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv) | |
26280 | || (profile == '\0' | |
26281 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_div) | |
26282 | && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))) | |
eea54501 | 26283 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
26284 | |
26285 | /* Tag_MP_extension_use. */ | |
26286 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
26287 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
26288 | |
26289 | /* Tag Virtualization_use. */ | |
26290 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
26291 | virt_sec |= 1; |
26292 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
26293 | virt_sec |= 2; | |
26294 | if (virt_sec != 0) | |
26295 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
ee065d83 PB |
26296 | } |
26297 | ||
104d59d1 | 26298 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
26299 | void |
26300 | arm_md_end (void) | |
26301 | { | |
ee065d83 PB |
26302 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
26303 | return; | |
26304 | ||
26305 | aeabi_set_public_attributes (); | |
ee065d83 | 26306 | } |
8463be01 | 26307 | #endif /* OBJ_ELF */ |
ee065d83 PB |
26308 | |
26309 | ||
26310 | /* Parse a .cpu directive. */ | |
26311 | ||
26312 | static void | |
26313 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
26314 | { | |
e74cfd16 | 26315 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
26316 | char *name; |
26317 | char saved_char; | |
26318 | ||
26319 | name = input_line_pointer; | |
5f4273c7 | 26320 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
26321 | input_line_pointer++; |
26322 | saved_char = *input_line_pointer; | |
26323 | *input_line_pointer = 0; | |
26324 | ||
26325 | /* Skip the first "all" entry. */ | |
26326 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
26327 | if (streq (opt->name, name)) | |
26328 | { | |
e74cfd16 PB |
26329 | mcpu_cpu_opt = &opt->value; |
26330 | selected_cpu = opt->value; | |
ee065d83 | 26331 | if (opt->canonical_name) |
5f4273c7 | 26332 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
26333 | else |
26334 | { | |
26335 | int i; | |
26336 | for (i = 0; opt->name[i]; i++) | |
26337 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 26338 | |
ee065d83 PB |
26339 | selected_cpu_name[i] = 0; |
26340 | } | |
e74cfd16 | 26341 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
26342 | *input_line_pointer = saved_char; |
26343 | demand_empty_rest_of_line (); | |
26344 | return; | |
26345 | } | |
26346 | as_bad (_("unknown cpu `%s'"), name); | |
26347 | *input_line_pointer = saved_char; | |
26348 | ignore_rest_of_line (); | |
26349 | } | |
26350 | ||
26351 | ||
26352 | /* Parse a .arch directive. */ | |
26353 | ||
26354 | static void | |
26355 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
26356 | { | |
e74cfd16 | 26357 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
26358 | char saved_char; |
26359 | char *name; | |
26360 | ||
26361 | name = input_line_pointer; | |
5f4273c7 | 26362 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
26363 | input_line_pointer++; |
26364 | saved_char = *input_line_pointer; | |
26365 | *input_line_pointer = 0; | |
26366 | ||
26367 | /* Skip the first "all" entry. */ | |
26368 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
26369 | if (streq (opt->name, name)) | |
26370 | { | |
e74cfd16 PB |
26371 | mcpu_cpu_opt = &opt->value; |
26372 | selected_cpu = opt->value; | |
5f4273c7 | 26373 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 26374 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
26375 | *input_line_pointer = saved_char; |
26376 | demand_empty_rest_of_line (); | |
26377 | return; | |
26378 | } | |
26379 | ||
26380 | as_bad (_("unknown architecture `%s'\n"), name); | |
26381 | *input_line_pointer = saved_char; | |
26382 | ignore_rest_of_line (); | |
26383 | } | |
26384 | ||
26385 | ||
7a1d4c38 PB |
26386 | /* Parse a .object_arch directive. */ |
26387 | ||
26388 | static void | |
26389 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
26390 | { | |
26391 | const struct arm_arch_option_table *opt; | |
26392 | char saved_char; | |
26393 | char *name; | |
26394 | ||
26395 | name = input_line_pointer; | |
5f4273c7 | 26396 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
26397 | input_line_pointer++; |
26398 | saved_char = *input_line_pointer; | |
26399 | *input_line_pointer = 0; | |
26400 | ||
26401 | /* Skip the first "all" entry. */ | |
26402 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
26403 | if (streq (opt->name, name)) | |
26404 | { | |
26405 | object_arch = &opt->value; | |
26406 | *input_line_pointer = saved_char; | |
26407 | demand_empty_rest_of_line (); | |
26408 | return; | |
26409 | } | |
26410 | ||
26411 | as_bad (_("unknown architecture `%s'\n"), name); | |
26412 | *input_line_pointer = saved_char; | |
26413 | ignore_rest_of_line (); | |
26414 | } | |
26415 | ||
69133863 MGD |
26416 | /* Parse a .arch_extension directive. */ |
26417 | ||
26418 | static void | |
26419 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
26420 | { | |
26421 | const struct arm_option_extension_value_table *opt; | |
26422 | char saved_char; | |
26423 | char *name; | |
26424 | int adding_value = 1; | |
26425 | ||
26426 | name = input_line_pointer; | |
26427 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
26428 | input_line_pointer++; | |
26429 | saved_char = *input_line_pointer; | |
26430 | *input_line_pointer = 0; | |
26431 | ||
26432 | if (strlen (name) >= 2 | |
26433 | && strncmp (name, "no", 2) == 0) | |
26434 | { | |
26435 | adding_value = 0; | |
26436 | name += 2; | |
26437 | } | |
26438 | ||
26439 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
26440 | if (streq (opt->name, name)) | |
26441 | { | |
26442 | if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs)) | |
26443 | { | |
26444 | as_bad (_("architectural extension `%s' is not allowed for the " | |
26445 | "current base architecture"), name); | |
26446 | break; | |
26447 | } | |
26448 | ||
26449 | if (adding_value) | |
5a70a223 JB |
26450 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, |
26451 | opt->merge_value); | |
69133863 | 26452 | else |
5a70a223 | 26453 | ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value); |
69133863 MGD |
26454 | |
26455 | mcpu_cpu_opt = &selected_cpu; | |
26456 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
26457 | *input_line_pointer = saved_char; | |
26458 | demand_empty_rest_of_line (); | |
26459 | return; | |
26460 | } | |
26461 | ||
26462 | if (opt->name == NULL) | |
e673710a | 26463 | as_bad (_("unknown architecture extension `%s'\n"), name); |
69133863 MGD |
26464 | |
26465 | *input_line_pointer = saved_char; | |
26466 | ignore_rest_of_line (); | |
26467 | } | |
26468 | ||
ee065d83 PB |
26469 | /* Parse a .fpu directive. */ |
26470 | ||
26471 | static void | |
26472 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
26473 | { | |
69133863 | 26474 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
26475 | char saved_char; |
26476 | char *name; | |
26477 | ||
26478 | name = input_line_pointer; | |
5f4273c7 | 26479 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
26480 | input_line_pointer++; |
26481 | saved_char = *input_line_pointer; | |
26482 | *input_line_pointer = 0; | |
5f4273c7 | 26483 | |
ee065d83 PB |
26484 | for (opt = arm_fpus; opt->name != NULL; opt++) |
26485 | if (streq (opt->name, name)) | |
26486 | { | |
e74cfd16 PB |
26487 | mfpu_opt = &opt->value; |
26488 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
26489 | *input_line_pointer = saved_char; |
26490 | demand_empty_rest_of_line (); | |
26491 | return; | |
26492 | } | |
26493 | ||
26494 | as_bad (_("unknown floating point format `%s'\n"), name); | |
26495 | *input_line_pointer = saved_char; | |
26496 | ignore_rest_of_line (); | |
26497 | } | |
ee065d83 | 26498 | |
794ba86a | 26499 | /* Copy symbol information. */ |
f31fef98 | 26500 | |
794ba86a DJ |
26501 | void |
26502 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
26503 | { | |
26504 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
26505 | } | |
e04befd0 | 26506 | |
f31fef98 | 26507 | #ifdef OBJ_ELF |
e04befd0 AS |
26508 | /* Given a symbolic attribute NAME, return the proper integer value. |
26509 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 26510 | |
e04befd0 AS |
26511 | int |
26512 | arm_convert_symbolic_attribute (const char *name) | |
26513 | { | |
f31fef98 NC |
26514 | static const struct |
26515 | { | |
26516 | const char * name; | |
26517 | const int tag; | |
26518 | } | |
26519 | attribute_table[] = | |
26520 | { | |
26521 | /* When you modify this table you should | |
26522 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 26523 | #define T(tag) {#tag, tag} |
f31fef98 NC |
26524 | T (Tag_CPU_raw_name), |
26525 | T (Tag_CPU_name), | |
26526 | T (Tag_CPU_arch), | |
26527 | T (Tag_CPU_arch_profile), | |
26528 | T (Tag_ARM_ISA_use), | |
26529 | T (Tag_THUMB_ISA_use), | |
75375b3e | 26530 | T (Tag_FP_arch), |
f31fef98 NC |
26531 | T (Tag_VFP_arch), |
26532 | T (Tag_WMMX_arch), | |
26533 | T (Tag_Advanced_SIMD_arch), | |
26534 | T (Tag_PCS_config), | |
26535 | T (Tag_ABI_PCS_R9_use), | |
26536 | T (Tag_ABI_PCS_RW_data), | |
26537 | T (Tag_ABI_PCS_RO_data), | |
26538 | T (Tag_ABI_PCS_GOT_use), | |
26539 | T (Tag_ABI_PCS_wchar_t), | |
26540 | T (Tag_ABI_FP_rounding), | |
26541 | T (Tag_ABI_FP_denormal), | |
26542 | T (Tag_ABI_FP_exceptions), | |
26543 | T (Tag_ABI_FP_user_exceptions), | |
26544 | T (Tag_ABI_FP_number_model), | |
75375b3e | 26545 | T (Tag_ABI_align_needed), |
f31fef98 | 26546 | T (Tag_ABI_align8_needed), |
75375b3e | 26547 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
26548 | T (Tag_ABI_align8_preserved), |
26549 | T (Tag_ABI_enum_size), | |
26550 | T (Tag_ABI_HardFP_use), | |
26551 | T (Tag_ABI_VFP_args), | |
26552 | T (Tag_ABI_WMMX_args), | |
26553 | T (Tag_ABI_optimization_goals), | |
26554 | T (Tag_ABI_FP_optimization_goals), | |
26555 | T (Tag_compatibility), | |
26556 | T (Tag_CPU_unaligned_access), | |
75375b3e | 26557 | T (Tag_FP_HP_extension), |
f31fef98 NC |
26558 | T (Tag_VFP_HP_extension), |
26559 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
26560 | T (Tag_MPextension_use), |
26561 | T (Tag_DIV_use), | |
f31fef98 NC |
26562 | T (Tag_nodefaults), |
26563 | T (Tag_also_compatible_with), | |
26564 | T (Tag_conformance), | |
26565 | T (Tag_T2EE_use), | |
26566 | T (Tag_Virtualization_use), | |
cd21e546 | 26567 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 26568 | #undef T |
f31fef98 | 26569 | }; |
e04befd0 AS |
26570 | unsigned int i; |
26571 | ||
26572 | if (name == NULL) | |
26573 | return -1; | |
26574 | ||
f31fef98 | 26575 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 26576 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
26577 | return attribute_table[i].tag; |
26578 | ||
26579 | return -1; | |
26580 | } | |
267bf995 RR |
26581 | |
26582 | ||
93ef582d NC |
26583 | /* Apply sym value for relocations only in the case that they are for |
26584 | local symbols in the same segment as the fixup and you have the | |
26585 | respective architectural feature for blx and simple switches. */ | |
267bf995 | 26586 | int |
93ef582d | 26587 | arm_apply_sym_value (struct fix * fixP, segT this_seg) |
267bf995 RR |
26588 | { |
26589 | if (fixP->fx_addsy | |
26590 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
93ef582d NC |
26591 | /* PR 17444: If the local symbol is in a different section then a reloc |
26592 | will always be generated for it, so applying the symbol value now | |
26593 | will result in a double offset being stored in the relocation. */ | |
26594 | && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg) | |
34e77a92 | 26595 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)) |
267bf995 RR |
26596 | { |
26597 | switch (fixP->fx_r_type) | |
26598 | { | |
26599 | case BFD_RELOC_ARM_PCREL_BLX: | |
26600 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
26601 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
26602 | return 1; | |
26603 | break; | |
26604 | ||
26605 | case BFD_RELOC_ARM_PCREL_CALL: | |
26606 | case BFD_RELOC_THUMB_PCREL_BLX: | |
26607 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
93ef582d | 26608 | return 1; |
267bf995 RR |
26609 | break; |
26610 | ||
26611 | default: | |
26612 | break; | |
26613 | } | |
26614 | ||
26615 | } | |
26616 | return 0; | |
26617 | } | |
f31fef98 | 26618 | #endif /* OBJ_ELF */ |