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); | |
e74cfd16 PB |
219 | |
220 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
823d2571 | 221 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1); |
e74cfd16 PB |
222 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; |
223 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
251665fc | 224 | static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY; |
e74cfd16 | 225 | |
2d447fca | 226 | static const arm_feature_set arm_cext_iwmmxt2 = |
823d2571 | 227 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2); |
e74cfd16 | 228 | static const arm_feature_set arm_cext_iwmmxt = |
823d2571 | 229 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT); |
e74cfd16 | 230 | static const arm_feature_set arm_cext_xscale = |
823d2571 | 231 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE); |
e74cfd16 | 232 | static const arm_feature_set arm_cext_maverick = |
823d2571 TG |
233 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK); |
234 | static const arm_feature_set fpu_fpa_ext_v1 = | |
235 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V1); | |
236 | static const arm_feature_set fpu_fpa_ext_v2 = | |
237 | ARM_FEATURE_COPROC (FPU_FPA_EXT_V2); | |
e74cfd16 | 238 | static const arm_feature_set fpu_vfp_ext_v1xd = |
823d2571 TG |
239 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD); |
240 | static const arm_feature_set fpu_vfp_ext_v1 = | |
241 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V1); | |
242 | static const arm_feature_set fpu_vfp_ext_v2 = | |
243 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V2); | |
244 | static const arm_feature_set fpu_vfp_ext_v3xd = | |
245 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD); | |
246 | static const arm_feature_set fpu_vfp_ext_v3 = | |
247 | ARM_FEATURE_COPROC (FPU_VFP_EXT_V3); | |
b1cc4aeb | 248 | static const arm_feature_set fpu_vfp_ext_d32 = |
823d2571 TG |
249 | ARM_FEATURE_COPROC (FPU_VFP_EXT_D32); |
250 | static const arm_feature_set fpu_neon_ext_v1 = | |
251 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1); | |
5287ad62 | 252 | static const arm_feature_set fpu_vfp_v3_or_neon_ext = |
823d2571 TG |
253 | ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3); |
254 | static const arm_feature_set fpu_vfp_fp16 = | |
255 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16); | |
256 | static const arm_feature_set fpu_neon_ext_fma = | |
257 | ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA); | |
258 | static const arm_feature_set fpu_vfp_ext_fma = | |
259 | ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA); | |
bca38921 | 260 | static const arm_feature_set fpu_vfp_ext_armv8 = |
823d2571 | 261 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8); |
a715796b | 262 | static const arm_feature_set fpu_vfp_ext_armv8xd = |
823d2571 | 263 | ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD); |
bca38921 | 264 | static const arm_feature_set fpu_neon_ext_armv8 = |
823d2571 | 265 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8); |
bca38921 | 266 | static const arm_feature_set fpu_crypto_ext_armv8 = |
823d2571 | 267 | ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8); |
dd5181d5 | 268 | static const arm_feature_set crc_ext_armv8 = |
823d2571 | 269 | ARM_FEATURE_COPROC (CRC_EXT_ARMV8); |
d6b4b13e MW |
270 | static const arm_feature_set fpu_neon_ext_v8_1 = |
271 | ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8 | FPU_NEON_EXT_RDMA); | |
e74cfd16 | 272 | |
33a392fb | 273 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
274 | /* Record user cpu selection for object attributes. */ |
275 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 | 276 | /* Must be long enough to hold any of the names in arm_cpus. */ |
ef8e6722 | 277 | static char selected_cpu_name[20]; |
8d67f500 | 278 | |
aacf0b33 KT |
279 | extern FLONUM_TYPE generic_floating_point_number; |
280 | ||
8d67f500 NC |
281 | /* Return if no cpu was selected on command-line. */ |
282 | static bfd_boolean | |
283 | no_cpu_selected (void) | |
284 | { | |
823d2571 | 285 | return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none); |
8d67f500 NC |
286 | } |
287 | ||
7cc69913 | 288 | #ifdef OBJ_ELF |
deeaaff8 DJ |
289 | # ifdef EABI_DEFAULT |
290 | static int meabi_flags = EABI_DEFAULT; | |
291 | # else | |
d507cf36 | 292 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 293 | # endif |
e1da3f5b | 294 | |
ee3c0378 AS |
295 | static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES]; |
296 | ||
e1da3f5b | 297 | bfd_boolean |
5f4273c7 | 298 | arm_is_eabi (void) |
e1da3f5b PB |
299 | { |
300 | return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4); | |
301 | } | |
7cc69913 | 302 | #endif |
b99bd4ef | 303 | |
b99bd4ef | 304 | #ifdef OBJ_ELF |
c19d1205 | 305 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
306 | symbolS * GOT_symbol; |
307 | #endif | |
308 | ||
b99bd4ef NC |
309 | /* 0: assemble for ARM, |
310 | 1: assemble for Thumb, | |
311 | 2: assemble for Thumb even though target CPU does not support thumb | |
312 | instructions. */ | |
313 | static int thumb_mode = 0; | |
8dc2430f NC |
314 | /* A value distinct from the possible values for thumb_mode that we |
315 | can use to record whether thumb_mode has been copied into the | |
316 | tc_frag_data field of a frag. */ | |
317 | #define MODE_RECORDED (1 << 4) | |
b99bd4ef | 318 | |
e07e6e58 NC |
319 | /* Specifies the intrinsic IT insn behavior mode. */ |
320 | enum implicit_it_mode | |
321 | { | |
322 | IMPLICIT_IT_MODE_NEVER = 0x00, | |
323 | IMPLICIT_IT_MODE_ARM = 0x01, | |
324 | IMPLICIT_IT_MODE_THUMB = 0x02, | |
325 | IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB) | |
326 | }; | |
327 | static int implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
328 | ||
c19d1205 ZW |
329 | /* If unified_syntax is true, we are processing the new unified |
330 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
331 | ||
332 | - Immediate operands do not require a # prefix. | |
333 | - Conditional affixes always appear at the end of the | |
334 | instruction. (For backward compatibility, those instructions | |
335 | that formerly had them in the middle, continue to accept them | |
336 | there.) | |
337 | - The IT instruction may appear, and if it does is validated | |
338 | against subsequent conditional affixes. It does not generate | |
339 | machine code. | |
340 | ||
341 | Important differences from the old Thumb mode: | |
342 | ||
343 | - Immediate operands do not require a # prefix. | |
344 | - Most of the V6T2 instructions are only available in unified mode. | |
345 | - The .N and .W suffixes are recognized and honored (it is an error | |
346 | if they cannot be honored). | |
347 | - All instructions set the flags if and only if they have an 's' affix. | |
348 | - Conditional affixes may be used. They are validated against | |
349 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
350 | conditional affix except in the scope of an IT instruction. */ | |
351 | ||
352 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef | 353 | |
bacebabc RM |
354 | /* An immediate operand can start with #, and ld*, st*, pld operands |
355 | can contain [ and ]. We need to tell APP not to elide whitespace | |
477330fc RM |
356 | before a [, which can appear as the first operand for pld. |
357 | Likewise, a { can appear as the first operand for push, pop, vld*, etc. */ | |
358 | const char arm_symbol_chars[] = "#[]{}"; | |
bacebabc | 359 | |
5287ad62 JB |
360 | enum neon_el_type |
361 | { | |
dcbf9037 | 362 | NT_invtype, |
5287ad62 JB |
363 | NT_untyped, |
364 | NT_integer, | |
365 | NT_float, | |
366 | NT_poly, | |
367 | NT_signed, | |
dcbf9037 | 368 | NT_unsigned |
5287ad62 JB |
369 | }; |
370 | ||
371 | struct neon_type_el | |
372 | { | |
373 | enum neon_el_type type; | |
374 | unsigned size; | |
375 | }; | |
376 | ||
377 | #define NEON_MAX_TYPE_ELS 4 | |
378 | ||
379 | struct neon_type | |
380 | { | |
381 | struct neon_type_el el[NEON_MAX_TYPE_ELS]; | |
382 | unsigned elems; | |
383 | }; | |
384 | ||
e07e6e58 NC |
385 | enum it_instruction_type |
386 | { | |
387 | OUTSIDE_IT_INSN, | |
388 | INSIDE_IT_INSN, | |
389 | INSIDE_IT_LAST_INSN, | |
390 | IF_INSIDE_IT_LAST_INSN, /* Either outside or inside; | |
477330fc | 391 | if inside, should be the last one. */ |
e07e6e58 | 392 | NEUTRAL_IT_INSN, /* This could be either inside or outside, |
477330fc | 393 | i.e. BKPT and NOP. */ |
e07e6e58 NC |
394 | IT_INSN /* The IT insn has been parsed. */ |
395 | }; | |
396 | ||
ad6cec43 MGD |
397 | /* The maximum number of operands we need. */ |
398 | #define ARM_IT_MAX_OPERANDS 6 | |
399 | ||
b99bd4ef NC |
400 | struct arm_it |
401 | { | |
c19d1205 | 402 | const char * error; |
b99bd4ef | 403 | unsigned long instruction; |
c19d1205 ZW |
404 | int size; |
405 | int size_req; | |
406 | int cond; | |
037e8744 JB |
407 | /* "uncond_value" is set to the value in place of the conditional field in |
408 | unconditional versions of the instruction, or -1 if nothing is | |
409 | appropriate. */ | |
410 | int uncond_value; | |
5287ad62 | 411 | struct neon_type vectype; |
88714cb8 DG |
412 | /* This does not indicate an actual NEON instruction, only that |
413 | the mnemonic accepts neon-style type suffixes. */ | |
414 | int is_neon; | |
0110f2b8 PB |
415 | /* Set to the opcode if the instruction needs relaxation. |
416 | Zero if the instruction is not relaxed. */ | |
417 | unsigned long relax; | |
b99bd4ef NC |
418 | struct |
419 | { | |
420 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
421 | expressionS exp; |
422 | int pc_rel; | |
b99bd4ef | 423 | } reloc; |
b99bd4ef | 424 | |
e07e6e58 NC |
425 | enum it_instruction_type it_insn_type; |
426 | ||
c19d1205 ZW |
427 | struct |
428 | { | |
429 | unsigned reg; | |
ca3f61f7 | 430 | signed int imm; |
dcbf9037 | 431 | struct neon_type_el vectype; |
ca3f61f7 NC |
432 | unsigned present : 1; /* Operand present. */ |
433 | unsigned isreg : 1; /* Operand was a register. */ | |
434 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
5287ad62 JB |
435 | unsigned isscalar : 1; /* Operand is a (Neon) scalar. */ |
436 | unsigned immisalign : 1; /* Immediate is an alignment specifier. */ | |
c96612cc | 437 | unsigned immisfloat : 1; /* Immediate was parsed as a float. */ |
5287ad62 JB |
438 | /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV |
439 | instructions. This allows us to disambiguate ARM <-> vector insns. */ | |
440 | unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */ | |
037e8744 | 441 | unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */ |
5287ad62 | 442 | unsigned isquad : 1; /* Operand is Neon quad-precision register. */ |
037e8744 | 443 | unsigned issingle : 1; /* Operand is VFP single-precision register. */ |
ca3f61f7 NC |
444 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ |
445 | unsigned writeback : 1; /* Operand has trailing ! */ | |
446 | unsigned preind : 1; /* Preindexed address. */ | |
447 | unsigned postind : 1; /* Postindexed address. */ | |
448 | unsigned negative : 1; /* Index register was negated. */ | |
449 | unsigned shifted : 1; /* Shift applied to operation. */ | |
450 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
ad6cec43 | 451 | } operands[ARM_IT_MAX_OPERANDS]; |
b99bd4ef NC |
452 | }; |
453 | ||
c19d1205 | 454 | static struct arm_it inst; |
b99bd4ef NC |
455 | |
456 | #define NUM_FLOAT_VALS 8 | |
457 | ||
05d2d07e | 458 | const char * fp_const[] = |
b99bd4ef NC |
459 | { |
460 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
461 | }; | |
462 | ||
c19d1205 | 463 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
464 | #define MAX_LITTLENUMS 6 |
465 | ||
466 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
467 | ||
468 | #define FAIL (-1) | |
469 | #define SUCCESS (0) | |
470 | ||
471 | #define SUFF_S 1 | |
472 | #define SUFF_D 2 | |
473 | #define SUFF_E 3 | |
474 | #define SUFF_P 4 | |
475 | ||
c19d1205 ZW |
476 | #define CP_T_X 0x00008000 |
477 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 478 | |
c19d1205 ZW |
479 | #define CONDS_BIT 0x00100000 |
480 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
481 | |
482 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
483 | ||
484 | struct asm_cond | |
485 | { | |
d3ce72d0 | 486 | const char * template_name; |
c921be7d | 487 | unsigned long value; |
b99bd4ef NC |
488 | }; |
489 | ||
c19d1205 | 490 | #define COND_ALWAYS 0xE |
b99bd4ef | 491 | |
b99bd4ef NC |
492 | struct asm_psr |
493 | { | |
d3ce72d0 | 494 | const char * template_name; |
c921be7d | 495 | unsigned long field; |
b99bd4ef NC |
496 | }; |
497 | ||
62b3e311 PB |
498 | struct asm_barrier_opt |
499 | { | |
e797f7e0 MGD |
500 | const char * template_name; |
501 | unsigned long value; | |
502 | const arm_feature_set arch; | |
62b3e311 PB |
503 | }; |
504 | ||
2d2255b5 | 505 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
506 | #define SPSR_BIT (1 << 22) |
507 | ||
c19d1205 ZW |
508 | /* The individual PSR flag bits. */ |
509 | #define PSR_c (1 << 16) | |
510 | #define PSR_x (1 << 17) | |
511 | #define PSR_s (1 << 18) | |
512 | #define PSR_f (1 << 19) | |
b99bd4ef | 513 | |
c19d1205 | 514 | struct reloc_entry |
bfae80f2 | 515 | { |
c921be7d NC |
516 | char * name; |
517 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
518 | }; |
519 | ||
5287ad62 | 520 | enum vfp_reg_pos |
bfae80f2 | 521 | { |
5287ad62 JB |
522 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn, |
523 | VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn | |
bfae80f2 RE |
524 | }; |
525 | ||
526 | enum vfp_ldstm_type | |
527 | { | |
528 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
529 | }; | |
530 | ||
dcbf9037 JB |
531 | /* Bits for DEFINED field in neon_typed_alias. */ |
532 | #define NTA_HASTYPE 1 | |
533 | #define NTA_HASINDEX 2 | |
534 | ||
535 | struct neon_typed_alias | |
536 | { | |
c921be7d NC |
537 | unsigned char defined; |
538 | unsigned char index; | |
539 | struct neon_type_el eltype; | |
dcbf9037 JB |
540 | }; |
541 | ||
c19d1205 ZW |
542 | /* ARM register categories. This includes coprocessor numbers and various |
543 | architecture extensions' registers. */ | |
544 | enum arm_reg_type | |
bfae80f2 | 545 | { |
c19d1205 ZW |
546 | REG_TYPE_RN, |
547 | REG_TYPE_CP, | |
548 | REG_TYPE_CN, | |
549 | REG_TYPE_FN, | |
550 | REG_TYPE_VFS, | |
551 | REG_TYPE_VFD, | |
5287ad62 | 552 | REG_TYPE_NQ, |
037e8744 | 553 | REG_TYPE_VFSD, |
5287ad62 | 554 | REG_TYPE_NDQ, |
037e8744 | 555 | REG_TYPE_NSDQ, |
c19d1205 ZW |
556 | REG_TYPE_VFC, |
557 | REG_TYPE_MVF, | |
558 | REG_TYPE_MVD, | |
559 | REG_TYPE_MVFX, | |
560 | REG_TYPE_MVDX, | |
561 | REG_TYPE_MVAX, | |
562 | REG_TYPE_DSPSC, | |
563 | REG_TYPE_MMXWR, | |
564 | REG_TYPE_MMXWC, | |
565 | REG_TYPE_MMXWCG, | |
566 | REG_TYPE_XSCALE, | |
90ec0d68 | 567 | REG_TYPE_RNB |
bfae80f2 RE |
568 | }; |
569 | ||
dcbf9037 JB |
570 | /* Structure for a hash table entry for a register. |
571 | If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra | |
572 | information which states whether a vector type or index is specified (for a | |
573 | register alias created with .dn or .qn). Otherwise NEON should be NULL. */ | |
6c43fab6 RE |
574 | struct reg_entry |
575 | { | |
c921be7d | 576 | const char * name; |
90ec0d68 | 577 | unsigned int number; |
c921be7d NC |
578 | unsigned char type; |
579 | unsigned char builtin; | |
580 | struct neon_typed_alias * neon; | |
6c43fab6 RE |
581 | }; |
582 | ||
c19d1205 | 583 | /* Diagnostics used when we don't get a register of the expected type. */ |
c921be7d | 584 | const char * const reg_expected_msgs[] = |
c19d1205 ZW |
585 | { |
586 | N_("ARM register expected"), | |
587 | N_("bad or missing co-processor number"), | |
588 | N_("co-processor register expected"), | |
589 | N_("FPA register expected"), | |
590 | N_("VFP single precision register expected"), | |
5287ad62 JB |
591 | N_("VFP/Neon double precision register expected"), |
592 | N_("Neon quad precision register expected"), | |
037e8744 | 593 | N_("VFP single or double precision register expected"), |
5287ad62 | 594 | N_("Neon double or quad precision register expected"), |
037e8744 | 595 | N_("VFP single, double or Neon quad precision register expected"), |
c19d1205 ZW |
596 | N_("VFP system register expected"), |
597 | N_("Maverick MVF register expected"), | |
598 | N_("Maverick MVD register expected"), | |
599 | N_("Maverick MVFX register expected"), | |
600 | N_("Maverick MVDX register expected"), | |
601 | N_("Maverick MVAX register expected"), | |
602 | N_("Maverick DSPSC register expected"), | |
603 | N_("iWMMXt data register expected"), | |
604 | N_("iWMMXt control register expected"), | |
605 | N_("iWMMXt scalar register expected"), | |
606 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
607 | }; |
608 | ||
c19d1205 | 609 | /* Some well known registers that we refer to directly elsewhere. */ |
bd340a04 | 610 | #define REG_R12 12 |
c19d1205 ZW |
611 | #define REG_SP 13 |
612 | #define REG_LR 14 | |
613 | #define REG_PC 15 | |
404ff6b5 | 614 | |
b99bd4ef NC |
615 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
616 | take 2: */ | |
c19d1205 | 617 | #define INSN_SIZE 4 |
b99bd4ef NC |
618 | |
619 | struct asm_opcode | |
620 | { | |
621 | /* Basic string to match. */ | |
d3ce72d0 | 622 | const char * template_name; |
c19d1205 ZW |
623 | |
624 | /* Parameters to instruction. */ | |
5be8be5d | 625 | unsigned int operands[8]; |
c19d1205 ZW |
626 | |
627 | /* Conditional tag - see opcode_lookup. */ | |
628 | unsigned int tag : 4; | |
b99bd4ef NC |
629 | |
630 | /* Basic instruction code. */ | |
c19d1205 | 631 | unsigned int avalue : 28; |
b99bd4ef | 632 | |
c19d1205 ZW |
633 | /* Thumb-format instruction code. */ |
634 | unsigned int tvalue; | |
b99bd4ef | 635 | |
90e4755a | 636 | /* Which architecture variant provides this instruction. */ |
c921be7d NC |
637 | const arm_feature_set * avariant; |
638 | const arm_feature_set * tvariant; | |
c19d1205 ZW |
639 | |
640 | /* Function to call to encode instruction in ARM format. */ | |
641 | void (* aencode) (void); | |
b99bd4ef | 642 | |
c19d1205 ZW |
643 | /* Function to call to encode instruction in Thumb format. */ |
644 | void (* tencode) (void); | |
b99bd4ef NC |
645 | }; |
646 | ||
a737bd4d NC |
647 | /* Defines for various bits that we will want to toggle. */ |
648 | #define INST_IMMEDIATE 0x02000000 | |
649 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 650 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
651 | #define SHIFT_BY_REG 0x00000010 |
652 | #define PRE_INDEX 0x01000000 | |
653 | #define INDEX_UP 0x00800000 | |
654 | #define WRITE_BACK 0x00200000 | |
655 | #define LDM_TYPE_2_OR_3 0x00400000 | |
a028a6f5 | 656 | #define CPSI_MMOD 0x00020000 |
90e4755a | 657 | |
a737bd4d NC |
658 | #define LITERAL_MASK 0xf000f000 |
659 | #define OPCODE_MASK 0xfe1fffff | |
660 | #define V4_STR_BIT 0x00000020 | |
8335d6aa | 661 | #define VLDR_VMOV_SAME 0x0040f000 |
90e4755a | 662 | |
efd81785 PB |
663 | #define T2_SUBS_PC_LR 0xf3de8f00 |
664 | ||
a737bd4d | 665 | #define DATA_OP_SHIFT 21 |
90e4755a | 666 | |
ef8d22e6 PB |
667 | #define T2_OPCODE_MASK 0xfe1fffff |
668 | #define T2_DATA_OP_SHIFT 21 | |
669 | ||
6530b175 NC |
670 | #define A_COND_MASK 0xf0000000 |
671 | #define A_PUSH_POP_OP_MASK 0x0fff0000 | |
672 | ||
673 | /* Opcodes for pushing/poping registers to/from the stack. */ | |
674 | #define A1_OPCODE_PUSH 0x092d0000 | |
675 | #define A2_OPCODE_PUSH 0x052d0004 | |
676 | #define A2_OPCODE_POP 0x049d0004 | |
677 | ||
a737bd4d NC |
678 | /* Codes to distinguish the arithmetic instructions. */ |
679 | #define OPCODE_AND 0 | |
680 | #define OPCODE_EOR 1 | |
681 | #define OPCODE_SUB 2 | |
682 | #define OPCODE_RSB 3 | |
683 | #define OPCODE_ADD 4 | |
684 | #define OPCODE_ADC 5 | |
685 | #define OPCODE_SBC 6 | |
686 | #define OPCODE_RSC 7 | |
687 | #define OPCODE_TST 8 | |
688 | #define OPCODE_TEQ 9 | |
689 | #define OPCODE_CMP 10 | |
690 | #define OPCODE_CMN 11 | |
691 | #define OPCODE_ORR 12 | |
692 | #define OPCODE_MOV 13 | |
693 | #define OPCODE_BIC 14 | |
694 | #define OPCODE_MVN 15 | |
90e4755a | 695 | |
ef8d22e6 PB |
696 | #define T2_OPCODE_AND 0 |
697 | #define T2_OPCODE_BIC 1 | |
698 | #define T2_OPCODE_ORR 2 | |
699 | #define T2_OPCODE_ORN 3 | |
700 | #define T2_OPCODE_EOR 4 | |
701 | #define T2_OPCODE_ADD 8 | |
702 | #define T2_OPCODE_ADC 10 | |
703 | #define T2_OPCODE_SBC 11 | |
704 | #define T2_OPCODE_SUB 13 | |
705 | #define T2_OPCODE_RSB 14 | |
706 | ||
a737bd4d NC |
707 | #define T_OPCODE_MUL 0x4340 |
708 | #define T_OPCODE_TST 0x4200 | |
709 | #define T_OPCODE_CMN 0x42c0 | |
710 | #define T_OPCODE_NEG 0x4240 | |
711 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 712 | |
a737bd4d NC |
713 | #define T_OPCODE_ADD_R3 0x1800 |
714 | #define T_OPCODE_SUB_R3 0x1a00 | |
715 | #define T_OPCODE_ADD_HI 0x4400 | |
716 | #define T_OPCODE_ADD_ST 0xb000 | |
717 | #define T_OPCODE_SUB_ST 0xb080 | |
718 | #define T_OPCODE_ADD_SP 0xa800 | |
719 | #define T_OPCODE_ADD_PC 0xa000 | |
720 | #define T_OPCODE_ADD_I8 0x3000 | |
721 | #define T_OPCODE_SUB_I8 0x3800 | |
722 | #define T_OPCODE_ADD_I3 0x1c00 | |
723 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 724 | |
a737bd4d NC |
725 | #define T_OPCODE_ASR_R 0x4100 |
726 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
727 | #define T_OPCODE_LSR_R 0x40c0 |
728 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
729 | #define T_OPCODE_ASR_I 0x1000 |
730 | #define T_OPCODE_LSL_I 0x0000 | |
731 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 732 | |
a737bd4d NC |
733 | #define T_OPCODE_MOV_I8 0x2000 |
734 | #define T_OPCODE_CMP_I8 0x2800 | |
735 | #define T_OPCODE_CMP_LR 0x4280 | |
736 | #define T_OPCODE_MOV_HR 0x4600 | |
737 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 738 | |
a737bd4d NC |
739 | #define T_OPCODE_LDR_PC 0x4800 |
740 | #define T_OPCODE_LDR_SP 0x9800 | |
741 | #define T_OPCODE_STR_SP 0x9000 | |
742 | #define T_OPCODE_LDR_IW 0x6800 | |
743 | #define T_OPCODE_STR_IW 0x6000 | |
744 | #define T_OPCODE_LDR_IH 0x8800 | |
745 | #define T_OPCODE_STR_IH 0x8000 | |
746 | #define T_OPCODE_LDR_IB 0x7800 | |
747 | #define T_OPCODE_STR_IB 0x7000 | |
748 | #define T_OPCODE_LDR_RW 0x5800 | |
749 | #define T_OPCODE_STR_RW 0x5000 | |
750 | #define T_OPCODE_LDR_RH 0x5a00 | |
751 | #define T_OPCODE_STR_RH 0x5200 | |
752 | #define T_OPCODE_LDR_RB 0x5c00 | |
753 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 754 | |
a737bd4d NC |
755 | #define T_OPCODE_PUSH 0xb400 |
756 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 757 | |
2fc8bdac | 758 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 759 | |
a737bd4d | 760 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 761 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 762 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 763 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
764 | |
765 | #define BAD_ARGS _("bad arguments to instruction") | |
fdfde340 | 766 | #define BAD_SP _("r13 not allowed here") |
c19d1205 ZW |
767 | #define BAD_PC _("r15 not allowed here") |
768 | #define BAD_COND _("instruction cannot be conditional") | |
769 | #define BAD_OVERLAP _("registers may not be the same") | |
770 | #define BAD_HIREG _("lo register required") | |
771 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 772 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
773 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
774 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
037e8744 | 775 | #define BAD_FPU _("selected FPU does not support instruction") |
e07e6e58 NC |
776 | #define BAD_OUT_IT _("thumb conditional instruction should be in IT block") |
777 | #define BAD_IT_COND _("incorrect condition in IT block") | |
778 | #define BAD_IT_IT _("IT falling in the range of a previous IT block") | |
921e5f0a | 779 | #define MISSING_FNSTART _("missing .fnstart before unwinding directive") |
5be8be5d DG |
780 | #define BAD_PC_ADDRESSING \ |
781 | _("cannot use register index with PC-relative addressing") | |
782 | #define BAD_PC_WRITEBACK \ | |
783 | _("cannot use writeback with PC-relative addressing") | |
08f10d51 | 784 | #define BAD_RANGE _("branch out of range") |
dd5181d5 | 785 | #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour") |
c19d1205 | 786 | |
c921be7d NC |
787 | static struct hash_control * arm_ops_hsh; |
788 | static struct hash_control * arm_cond_hsh; | |
789 | static struct hash_control * arm_shift_hsh; | |
790 | static struct hash_control * arm_psr_hsh; | |
791 | static struct hash_control * arm_v7m_psr_hsh; | |
792 | static struct hash_control * arm_reg_hsh; | |
793 | static struct hash_control * arm_reloc_hsh; | |
794 | static struct hash_control * arm_barrier_opt_hsh; | |
b99bd4ef | 795 | |
b99bd4ef NC |
796 | /* Stuff needed to resolve the label ambiguity |
797 | As: | |
798 | ... | |
799 | label: <insn> | |
800 | may differ from: | |
801 | ... | |
802 | label: | |
5f4273c7 | 803 | <insn> */ |
b99bd4ef NC |
804 | |
805 | symbolS * last_label_seen; | |
b34976b6 | 806 | static int label_is_thumb_function_name = FALSE; |
e07e6e58 | 807 | |
3d0c9500 NC |
808 | /* Literal pool structure. Held on a per-section |
809 | and per-sub-section basis. */ | |
a737bd4d | 810 | |
c19d1205 | 811 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 812 | typedef struct literal_pool |
b99bd4ef | 813 | { |
c921be7d NC |
814 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
815 | unsigned int next_free_entry; | |
816 | unsigned int id; | |
817 | symbolS * symbol; | |
818 | segT section; | |
819 | subsegT sub_section; | |
a8040cf2 NC |
820 | #ifdef OBJ_ELF |
821 | struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE]; | |
822 | #endif | |
c921be7d | 823 | struct literal_pool * next; |
8335d6aa | 824 | unsigned int alignment; |
3d0c9500 | 825 | } literal_pool; |
b99bd4ef | 826 | |
3d0c9500 NC |
827 | /* Pointer to a linked list of literal pools. */ |
828 | literal_pool * list_of_pools = NULL; | |
e27ec89e | 829 | |
2e6976a8 DG |
830 | typedef enum asmfunc_states |
831 | { | |
832 | OUTSIDE_ASMFUNC, | |
833 | WAITING_ASMFUNC_NAME, | |
834 | WAITING_ENDASMFUNC | |
835 | } asmfunc_states; | |
836 | ||
837 | static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC; | |
838 | ||
e07e6e58 NC |
839 | #ifdef OBJ_ELF |
840 | # define now_it seg_info (now_seg)->tc_segment_info_data.current_it | |
841 | #else | |
842 | static struct current_it now_it; | |
843 | #endif | |
844 | ||
845 | static inline int | |
846 | now_it_compatible (int cond) | |
847 | { | |
848 | return (cond & ~1) == (now_it.cc & ~1); | |
849 | } | |
850 | ||
851 | static inline int | |
852 | conditional_insn (void) | |
853 | { | |
854 | return inst.cond != COND_ALWAYS; | |
855 | } | |
856 | ||
857 | static int in_it_block (void); | |
858 | ||
859 | static int handle_it_state (void); | |
860 | ||
861 | static void force_automatic_it_block_close (void); | |
862 | ||
c921be7d NC |
863 | static void it_fsm_post_encode (void); |
864 | ||
e07e6e58 NC |
865 | #define set_it_insn_type(type) \ |
866 | do \ | |
867 | { \ | |
868 | inst.it_insn_type = type; \ | |
869 | if (handle_it_state () == FAIL) \ | |
477330fc | 870 | return; \ |
e07e6e58 NC |
871 | } \ |
872 | while (0) | |
873 | ||
c921be7d NC |
874 | #define set_it_insn_type_nonvoid(type, failret) \ |
875 | do \ | |
876 | { \ | |
877 | inst.it_insn_type = type; \ | |
878 | if (handle_it_state () == FAIL) \ | |
477330fc | 879 | return failret; \ |
c921be7d NC |
880 | } \ |
881 | while(0) | |
882 | ||
e07e6e58 NC |
883 | #define set_it_insn_type_last() \ |
884 | do \ | |
885 | { \ | |
886 | if (inst.cond == COND_ALWAYS) \ | |
477330fc | 887 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \ |
e07e6e58 | 888 | else \ |
477330fc | 889 | set_it_insn_type (INSIDE_IT_LAST_INSN); \ |
e07e6e58 NC |
890 | } \ |
891 | while (0) | |
892 | ||
c19d1205 | 893 | /* Pure syntax. */ |
b99bd4ef | 894 | |
c19d1205 ZW |
895 | /* This array holds the chars that always start a comment. If the |
896 | pre-processor is disabled, these aren't very useful. */ | |
2e6976a8 | 897 | char arm_comment_chars[] = "@"; |
3d0c9500 | 898 | |
c19d1205 ZW |
899 | /* This array holds the chars that only start a comment at the beginning of |
900 | a line. If the line seems to have the form '# 123 filename' | |
901 | .line and .file directives will appear in the pre-processed output. */ | |
902 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
903 | first line of the input file. This is because the compiler outputs | |
904 | #NO_APP at the beginning of its output. */ | |
905 | /* Also note that comments like this one will always work. */ | |
906 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 907 | |
2e6976a8 | 908 | char arm_line_separator_chars[] = ";"; |
b99bd4ef | 909 | |
c19d1205 ZW |
910 | /* Chars that can be used to separate mant |
911 | from exp in floating point numbers. */ | |
912 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 913 | |
c19d1205 ZW |
914 | /* Chars that mean this number is a floating point constant. */ |
915 | /* As in 0f12.456 */ | |
916 | /* or 0d1.2345e12 */ | |
b99bd4ef | 917 | |
c19d1205 | 918 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 919 | |
c19d1205 ZW |
920 | /* Prefix characters that indicate the start of an immediate |
921 | value. */ | |
922 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 923 | |
c19d1205 ZW |
924 | /* Separator character handling. */ |
925 | ||
926 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
927 | ||
928 | static inline int | |
929 | skip_past_char (char ** str, char c) | |
930 | { | |
8ab8155f NC |
931 | /* PR gas/14987: Allow for whitespace before the expected character. */ |
932 | skip_whitespace (*str); | |
427d0db6 | 933 | |
c19d1205 ZW |
934 | if (**str == c) |
935 | { | |
936 | (*str)++; | |
937 | return SUCCESS; | |
3d0c9500 | 938 | } |
c19d1205 ZW |
939 | else |
940 | return FAIL; | |
941 | } | |
c921be7d | 942 | |
c19d1205 | 943 | #define skip_past_comma(str) skip_past_char (str, ',') |
3d0c9500 | 944 | |
c19d1205 ZW |
945 | /* Arithmetic expressions (possibly involving symbols). */ |
946 | ||
947 | /* Return TRUE if anything in the expression is a bignum. */ | |
948 | ||
949 | static int | |
950 | walk_no_bignums (symbolS * sp) | |
951 | { | |
952 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
953 | return 1; | |
954 | ||
955 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 956 | { |
c19d1205 ZW |
957 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
958 | || (symbol_get_value_expression (sp)->X_op_symbol | |
959 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
960 | } |
961 | ||
c19d1205 | 962 | return 0; |
3d0c9500 NC |
963 | } |
964 | ||
c19d1205 ZW |
965 | static int in_my_get_expression = 0; |
966 | ||
967 | /* Third argument to my_get_expression. */ | |
968 | #define GE_NO_PREFIX 0 | |
969 | #define GE_IMM_PREFIX 1 | |
970 | #define GE_OPT_PREFIX 2 | |
5287ad62 JB |
971 | /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit) |
972 | immediates, as can be used in Neon VMVN and VMOV immediate instructions. */ | |
973 | #define GE_OPT_PREFIX_BIG 3 | |
a737bd4d | 974 | |
b99bd4ef | 975 | static int |
c19d1205 | 976 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 977 | { |
c19d1205 ZW |
978 | char * save_in; |
979 | segT seg; | |
b99bd4ef | 980 | |
c19d1205 ZW |
981 | /* In unified syntax, all prefixes are optional. */ |
982 | if (unified_syntax) | |
5287ad62 | 983 | prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode |
477330fc | 984 | : GE_OPT_PREFIX; |
b99bd4ef | 985 | |
c19d1205 | 986 | switch (prefix_mode) |
b99bd4ef | 987 | { |
c19d1205 ZW |
988 | case GE_NO_PREFIX: break; |
989 | case GE_IMM_PREFIX: | |
990 | if (!is_immediate_prefix (**str)) | |
991 | { | |
992 | inst.error = _("immediate expression requires a # prefix"); | |
993 | return FAIL; | |
994 | } | |
995 | (*str)++; | |
996 | break; | |
997 | case GE_OPT_PREFIX: | |
5287ad62 | 998 | case GE_OPT_PREFIX_BIG: |
c19d1205 ZW |
999 | if (is_immediate_prefix (**str)) |
1000 | (*str)++; | |
1001 | break; | |
1002 | default: abort (); | |
1003 | } | |
b99bd4ef | 1004 | |
c19d1205 | 1005 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 1006 | |
c19d1205 ZW |
1007 | save_in = input_line_pointer; |
1008 | input_line_pointer = *str; | |
1009 | in_my_get_expression = 1; | |
1010 | seg = expression (ep); | |
1011 | in_my_get_expression = 0; | |
1012 | ||
f86adc07 | 1013 | if (ep->X_op == O_illegal || ep->X_op == O_absent) |
b99bd4ef | 1014 | { |
f86adc07 | 1015 | /* We found a bad or missing expression in md_operand(). */ |
c19d1205 ZW |
1016 | *str = input_line_pointer; |
1017 | input_line_pointer = save_in; | |
1018 | if (inst.error == NULL) | |
f86adc07 NS |
1019 | inst.error = (ep->X_op == O_absent |
1020 | ? _("missing expression") :_("bad expression")); | |
c19d1205 ZW |
1021 | return 1; |
1022 | } | |
b99bd4ef | 1023 | |
c19d1205 ZW |
1024 | #ifdef OBJ_AOUT |
1025 | if (seg != absolute_section | |
1026 | && seg != text_section | |
1027 | && seg != data_section | |
1028 | && seg != bss_section | |
1029 | && seg != undefined_section) | |
1030 | { | |
1031 | inst.error = _("bad segment"); | |
1032 | *str = input_line_pointer; | |
1033 | input_line_pointer = save_in; | |
1034 | return 1; | |
b99bd4ef | 1035 | } |
87975d2a AM |
1036 | #else |
1037 | (void) seg; | |
c19d1205 | 1038 | #endif |
b99bd4ef | 1039 | |
c19d1205 ZW |
1040 | /* Get rid of any bignums now, so that we don't generate an error for which |
1041 | we can't establish a line number later on. Big numbers are never valid | |
1042 | in instructions, which is where this routine is always called. */ | |
5287ad62 JB |
1043 | if (prefix_mode != GE_OPT_PREFIX_BIG |
1044 | && (ep->X_op == O_big | |
477330fc | 1045 | || (ep->X_add_symbol |
5287ad62 | 1046 | && (walk_no_bignums (ep->X_add_symbol) |
477330fc | 1047 | || (ep->X_op_symbol |
5287ad62 | 1048 | && walk_no_bignums (ep->X_op_symbol)))))) |
c19d1205 ZW |
1049 | { |
1050 | inst.error = _("invalid constant"); | |
1051 | *str = input_line_pointer; | |
1052 | input_line_pointer = save_in; | |
1053 | return 1; | |
1054 | } | |
b99bd4ef | 1055 | |
c19d1205 ZW |
1056 | *str = input_line_pointer; |
1057 | input_line_pointer = save_in; | |
1058 | return 0; | |
b99bd4ef NC |
1059 | } |
1060 | ||
c19d1205 ZW |
1061 | /* Turn a string in input_line_pointer into a floating point constant |
1062 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1063 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1064 | returned, or NULL on OK. | |
b99bd4ef | 1065 | |
c19d1205 ZW |
1066 | Note that fp constants aren't represent in the normal way on the ARM. |
1067 | In big endian mode, things are as expected. However, in little endian | |
1068 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
1069 | within the words. For example, (double) 1.1 in big endian mode is | |
1070 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
1071 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 1072 | |
c19d1205 | 1073 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 1074 | |
c19d1205 ZW |
1075 | char * |
1076 | md_atof (int type, char * litP, int * sizeP) | |
1077 | { | |
1078 | int prec; | |
1079 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1080 | char *t; | |
1081 | int i; | |
b99bd4ef | 1082 | |
c19d1205 ZW |
1083 | switch (type) |
1084 | { | |
1085 | case 'f': | |
1086 | case 'F': | |
1087 | case 's': | |
1088 | case 'S': | |
1089 | prec = 2; | |
1090 | break; | |
b99bd4ef | 1091 | |
c19d1205 ZW |
1092 | case 'd': |
1093 | case 'D': | |
1094 | case 'r': | |
1095 | case 'R': | |
1096 | prec = 4; | |
1097 | break; | |
b99bd4ef | 1098 | |
c19d1205 ZW |
1099 | case 'x': |
1100 | case 'X': | |
499ac353 | 1101 | prec = 5; |
c19d1205 | 1102 | break; |
b99bd4ef | 1103 | |
c19d1205 ZW |
1104 | case 'p': |
1105 | case 'P': | |
499ac353 | 1106 | prec = 5; |
c19d1205 | 1107 | break; |
a737bd4d | 1108 | |
c19d1205 ZW |
1109 | default: |
1110 | *sizeP = 0; | |
499ac353 | 1111 | return _("Unrecognized or unsupported floating point constant"); |
c19d1205 | 1112 | } |
b99bd4ef | 1113 | |
c19d1205 ZW |
1114 | t = atof_ieee (input_line_pointer, type, words); |
1115 | if (t) | |
1116 | input_line_pointer = t; | |
499ac353 | 1117 | *sizeP = prec * sizeof (LITTLENUM_TYPE); |
b99bd4ef | 1118 | |
c19d1205 ZW |
1119 | if (target_big_endian) |
1120 | { | |
1121 | for (i = 0; i < prec; i++) | |
1122 | { | |
499ac353 NC |
1123 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1124 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1125 | } |
1126 | } | |
1127 | else | |
1128 | { | |
e74cfd16 | 1129 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
1130 | for (i = prec - 1; i >= 0; i--) |
1131 | { | |
499ac353 NC |
1132 | md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE)); |
1133 | litP += sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1134 | } |
1135 | else | |
1136 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
1137 | For an 8 byte float the order is 1 0 3 2. */ | |
1138 | for (i = 0; i < prec; i += 2) | |
1139 | { | |
499ac353 NC |
1140 | md_number_to_chars (litP, (valueT) words[i + 1], |
1141 | sizeof (LITTLENUM_TYPE)); | |
1142 | md_number_to_chars (litP + sizeof (LITTLENUM_TYPE), | |
1143 | (valueT) words[i], sizeof (LITTLENUM_TYPE)); | |
1144 | litP += 2 * sizeof (LITTLENUM_TYPE); | |
c19d1205 ZW |
1145 | } |
1146 | } | |
b99bd4ef | 1147 | |
499ac353 | 1148 | return NULL; |
c19d1205 | 1149 | } |
b99bd4ef | 1150 | |
c19d1205 ZW |
1151 | /* We handle all bad expressions here, so that we can report the faulty |
1152 | instruction in the error message. */ | |
1153 | void | |
91d6fa6a | 1154 | md_operand (expressionS * exp) |
c19d1205 ZW |
1155 | { |
1156 | if (in_my_get_expression) | |
91d6fa6a | 1157 | exp->X_op = O_illegal; |
b99bd4ef NC |
1158 | } |
1159 | ||
c19d1205 | 1160 | /* Immediate values. */ |
b99bd4ef | 1161 | |
c19d1205 ZW |
1162 | /* Generic immediate-value read function for use in directives. |
1163 | Accepts anything that 'expression' can fold to a constant. | |
1164 | *val receives the number. */ | |
1165 | #ifdef OBJ_ELF | |
1166 | static int | |
1167 | immediate_for_directive (int *val) | |
b99bd4ef | 1168 | { |
c19d1205 ZW |
1169 | expressionS exp; |
1170 | exp.X_op = O_illegal; | |
b99bd4ef | 1171 | |
c19d1205 ZW |
1172 | if (is_immediate_prefix (*input_line_pointer)) |
1173 | { | |
1174 | input_line_pointer++; | |
1175 | expression (&exp); | |
1176 | } | |
b99bd4ef | 1177 | |
c19d1205 ZW |
1178 | if (exp.X_op != O_constant) |
1179 | { | |
1180 | as_bad (_("expected #constant")); | |
1181 | ignore_rest_of_line (); | |
1182 | return FAIL; | |
1183 | } | |
1184 | *val = exp.X_add_number; | |
1185 | return SUCCESS; | |
b99bd4ef | 1186 | } |
c19d1205 | 1187 | #endif |
b99bd4ef | 1188 | |
c19d1205 | 1189 | /* Register parsing. */ |
b99bd4ef | 1190 | |
c19d1205 ZW |
1191 | /* Generic register parser. CCP points to what should be the |
1192 | beginning of a register name. If it is indeed a valid register | |
1193 | name, advance CCP over it and return the reg_entry structure; | |
1194 | otherwise return NULL. Does not issue diagnostics. */ | |
1195 | ||
1196 | static struct reg_entry * | |
1197 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 1198 | { |
c19d1205 ZW |
1199 | char *start = *ccp; |
1200 | char *p; | |
1201 | struct reg_entry *reg; | |
b99bd4ef | 1202 | |
477330fc RM |
1203 | skip_whitespace (start); |
1204 | ||
c19d1205 ZW |
1205 | #ifdef REGISTER_PREFIX |
1206 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 1207 | return NULL; |
c19d1205 ZW |
1208 | start++; |
1209 | #endif | |
1210 | #ifdef OPTIONAL_REGISTER_PREFIX | |
1211 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
1212 | start++; | |
1213 | #endif | |
b99bd4ef | 1214 | |
c19d1205 ZW |
1215 | p = start; |
1216 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
1217 | return NULL; | |
b99bd4ef | 1218 | |
c19d1205 ZW |
1219 | do |
1220 | p++; | |
1221 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
1222 | ||
1223 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
1224 | ||
1225 | if (!reg) | |
1226 | return NULL; | |
1227 | ||
1228 | *ccp = p; | |
1229 | return reg; | |
b99bd4ef NC |
1230 | } |
1231 | ||
1232 | static int | |
dcbf9037 | 1233 | arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg, |
477330fc | 1234 | enum arm_reg_type type) |
b99bd4ef | 1235 | { |
c19d1205 ZW |
1236 | /* Alternative syntaxes are accepted for a few register classes. */ |
1237 | switch (type) | |
1238 | { | |
1239 | case REG_TYPE_MVF: | |
1240 | case REG_TYPE_MVD: | |
1241 | case REG_TYPE_MVFX: | |
1242 | case REG_TYPE_MVDX: | |
1243 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 1244 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
1245 | return reg->number; |
1246 | break; | |
69b97547 | 1247 | |
c19d1205 ZW |
1248 | case REG_TYPE_CP: |
1249 | /* For backward compatibility, a bare number is valid here. */ | |
1250 | { | |
1251 | unsigned long processor = strtoul (start, ccp, 10); | |
1252 | if (*ccp != start && processor <= 15) | |
1253 | return processor; | |
1254 | } | |
6057a28f | 1255 | |
c19d1205 ZW |
1256 | case REG_TYPE_MMXWC: |
1257 | /* WC includes WCG. ??? I'm not sure this is true for all | |
1258 | instructions that take WC registers. */ | |
79134647 | 1259 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 1260 | return reg->number; |
6057a28f | 1261 | break; |
c19d1205 | 1262 | |
6057a28f | 1263 | default: |
c19d1205 | 1264 | break; |
6057a28f NC |
1265 | } |
1266 | ||
dcbf9037 JB |
1267 | return FAIL; |
1268 | } | |
1269 | ||
1270 | /* As arm_reg_parse_multi, but the register must be of type TYPE, and the | |
1271 | return value is the register number or FAIL. */ | |
1272 | ||
1273 | static int | |
1274 | arm_reg_parse (char **ccp, enum arm_reg_type type) | |
1275 | { | |
1276 | char *start = *ccp; | |
1277 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
1278 | int ret; | |
1279 | ||
1280 | /* Do not allow a scalar (reg+index) to parse as a register. */ | |
1281 | if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX)) | |
1282 | return FAIL; | |
1283 | ||
1284 | if (reg && reg->type == type) | |
1285 | return reg->number; | |
1286 | ||
1287 | if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL) | |
1288 | return ret; | |
1289 | ||
c19d1205 ZW |
1290 | *ccp = start; |
1291 | return FAIL; | |
1292 | } | |
69b97547 | 1293 | |
dcbf9037 JB |
1294 | /* Parse a Neon type specifier. *STR should point at the leading '.' |
1295 | character. Does no verification at this stage that the type fits the opcode | |
1296 | properly. E.g., | |
1297 | ||
1298 | .i32.i32.s16 | |
1299 | .s32.f32 | |
1300 | .u16 | |
1301 | ||
1302 | Can all be legally parsed by this function. | |
1303 | ||
1304 | Fills in neon_type struct pointer with parsed information, and updates STR | |
1305 | to point after the parsed type specifier. Returns SUCCESS if this was a legal | |
1306 | type, FAIL if not. */ | |
1307 | ||
1308 | static int | |
1309 | parse_neon_type (struct neon_type *type, char **str) | |
1310 | { | |
1311 | char *ptr = *str; | |
1312 | ||
1313 | if (type) | |
1314 | type->elems = 0; | |
1315 | ||
1316 | while (type->elems < NEON_MAX_TYPE_ELS) | |
1317 | { | |
1318 | enum neon_el_type thistype = NT_untyped; | |
1319 | unsigned thissize = -1u; | |
1320 | ||
1321 | if (*ptr != '.') | |
1322 | break; | |
1323 | ||
1324 | ptr++; | |
1325 | ||
1326 | /* Just a size without an explicit type. */ | |
1327 | if (ISDIGIT (*ptr)) | |
1328 | goto parsesize; | |
1329 | ||
1330 | switch (TOLOWER (*ptr)) | |
1331 | { | |
1332 | case 'i': thistype = NT_integer; break; | |
1333 | case 'f': thistype = NT_float; break; | |
1334 | case 'p': thistype = NT_poly; break; | |
1335 | case 's': thistype = NT_signed; break; | |
1336 | case 'u': thistype = NT_unsigned; break; | |
477330fc RM |
1337 | case 'd': |
1338 | thistype = NT_float; | |
1339 | thissize = 64; | |
1340 | ptr++; | |
1341 | goto done; | |
dcbf9037 JB |
1342 | default: |
1343 | as_bad (_("unexpected character `%c' in type specifier"), *ptr); | |
1344 | return FAIL; | |
1345 | } | |
1346 | ||
1347 | ptr++; | |
1348 | ||
1349 | /* .f is an abbreviation for .f32. */ | |
1350 | if (thistype == NT_float && !ISDIGIT (*ptr)) | |
1351 | thissize = 32; | |
1352 | else | |
1353 | { | |
1354 | parsesize: | |
1355 | thissize = strtoul (ptr, &ptr, 10); | |
1356 | ||
1357 | if (thissize != 8 && thissize != 16 && thissize != 32 | |
477330fc RM |
1358 | && thissize != 64) |
1359 | { | |
1360 | as_bad (_("bad size %d in type specifier"), thissize); | |
dcbf9037 JB |
1361 | return FAIL; |
1362 | } | |
1363 | } | |
1364 | ||
037e8744 | 1365 | done: |
dcbf9037 | 1366 | if (type) |
477330fc RM |
1367 | { |
1368 | type->el[type->elems].type = thistype; | |
dcbf9037 JB |
1369 | type->el[type->elems].size = thissize; |
1370 | type->elems++; | |
1371 | } | |
1372 | } | |
1373 | ||
1374 | /* Empty/missing type is not a successful parse. */ | |
1375 | if (type->elems == 0) | |
1376 | return FAIL; | |
1377 | ||
1378 | *str = ptr; | |
1379 | ||
1380 | return SUCCESS; | |
1381 | } | |
1382 | ||
1383 | /* Errors may be set multiple times during parsing or bit encoding | |
1384 | (particularly in the Neon bits), but usually the earliest error which is set | |
1385 | will be the most meaningful. Avoid overwriting it with later (cascading) | |
1386 | errors by calling this function. */ | |
1387 | ||
1388 | static void | |
1389 | first_error (const char *err) | |
1390 | { | |
1391 | if (!inst.error) | |
1392 | inst.error = err; | |
1393 | } | |
1394 | ||
1395 | /* Parse a single type, e.g. ".s32", leading period included. */ | |
1396 | static int | |
1397 | parse_neon_operand_type (struct neon_type_el *vectype, char **ccp) | |
1398 | { | |
1399 | char *str = *ccp; | |
1400 | struct neon_type optype; | |
1401 | ||
1402 | if (*str == '.') | |
1403 | { | |
1404 | if (parse_neon_type (&optype, &str) == SUCCESS) | |
477330fc RM |
1405 | { |
1406 | if (optype.elems == 1) | |
1407 | *vectype = optype.el[0]; | |
1408 | else | |
1409 | { | |
1410 | first_error (_("only one type should be specified for operand")); | |
1411 | return FAIL; | |
1412 | } | |
1413 | } | |
dcbf9037 | 1414 | else |
477330fc RM |
1415 | { |
1416 | first_error (_("vector type expected")); | |
1417 | return FAIL; | |
1418 | } | |
dcbf9037 JB |
1419 | } |
1420 | else | |
1421 | return FAIL; | |
5f4273c7 | 1422 | |
dcbf9037 | 1423 | *ccp = str; |
5f4273c7 | 1424 | |
dcbf9037 JB |
1425 | return SUCCESS; |
1426 | } | |
1427 | ||
1428 | /* Special meanings for indices (which have a range of 0-7), which will fit into | |
1429 | a 4-bit integer. */ | |
1430 | ||
1431 | #define NEON_ALL_LANES 15 | |
1432 | #define NEON_INTERLEAVE_LANES 14 | |
1433 | ||
1434 | /* Parse either a register or a scalar, with an optional type. Return the | |
1435 | register number, and optionally fill in the actual type of the register | |
1436 | when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and | |
1437 | type/index information in *TYPEINFO. */ | |
1438 | ||
1439 | static int | |
1440 | parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type, | |
477330fc RM |
1441 | enum arm_reg_type *rtype, |
1442 | struct neon_typed_alias *typeinfo) | |
dcbf9037 JB |
1443 | { |
1444 | char *str = *ccp; | |
1445 | struct reg_entry *reg = arm_reg_parse_multi (&str); | |
1446 | struct neon_typed_alias atype; | |
1447 | struct neon_type_el parsetype; | |
1448 | ||
1449 | atype.defined = 0; | |
1450 | atype.index = -1; | |
1451 | atype.eltype.type = NT_invtype; | |
1452 | atype.eltype.size = -1; | |
1453 | ||
1454 | /* Try alternate syntax for some types of register. Note these are mutually | |
1455 | exclusive with the Neon syntax extensions. */ | |
1456 | if (reg == NULL) | |
1457 | { | |
1458 | int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type); | |
1459 | if (altreg != FAIL) | |
477330fc | 1460 | *ccp = str; |
dcbf9037 | 1461 | if (typeinfo) |
477330fc | 1462 | *typeinfo = atype; |
dcbf9037 JB |
1463 | return altreg; |
1464 | } | |
1465 | ||
037e8744 JB |
1466 | /* Undo polymorphism when a set of register types may be accepted. */ |
1467 | if ((type == REG_TYPE_NDQ | |
1468 | && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD)) | |
1469 | || (type == REG_TYPE_VFSD | |
477330fc | 1470 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD)) |
037e8744 | 1471 | || (type == REG_TYPE_NSDQ |
477330fc RM |
1472 | && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD |
1473 | || reg->type == REG_TYPE_NQ)) | |
f512f76f NC |
1474 | || (type == REG_TYPE_MMXWC |
1475 | && (reg->type == REG_TYPE_MMXWCG))) | |
21d799b5 | 1476 | type = (enum arm_reg_type) reg->type; |
dcbf9037 JB |
1477 | |
1478 | if (type != reg->type) | |
1479 | return FAIL; | |
1480 | ||
1481 | if (reg->neon) | |
1482 | atype = *reg->neon; | |
5f4273c7 | 1483 | |
dcbf9037 JB |
1484 | if (parse_neon_operand_type (&parsetype, &str) == SUCCESS) |
1485 | { | |
1486 | if ((atype.defined & NTA_HASTYPE) != 0) | |
477330fc RM |
1487 | { |
1488 | first_error (_("can't redefine type for operand")); | |
1489 | return FAIL; | |
1490 | } | |
dcbf9037 JB |
1491 | atype.defined |= NTA_HASTYPE; |
1492 | atype.eltype = parsetype; | |
1493 | } | |
5f4273c7 | 1494 | |
dcbf9037 JB |
1495 | if (skip_past_char (&str, '[') == SUCCESS) |
1496 | { | |
1497 | if (type != REG_TYPE_VFD) | |
477330fc RM |
1498 | { |
1499 | first_error (_("only D registers may be indexed")); | |
1500 | return FAIL; | |
1501 | } | |
5f4273c7 | 1502 | |
dcbf9037 | 1503 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
1504 | { |
1505 | first_error (_("can't change index for operand")); | |
1506 | return FAIL; | |
1507 | } | |
dcbf9037 JB |
1508 | |
1509 | atype.defined |= NTA_HASINDEX; | |
1510 | ||
1511 | if (skip_past_char (&str, ']') == SUCCESS) | |
477330fc | 1512 | atype.index = NEON_ALL_LANES; |
dcbf9037 | 1513 | else |
477330fc RM |
1514 | { |
1515 | expressionS exp; | |
dcbf9037 | 1516 | |
477330fc | 1517 | my_get_expression (&exp, &str, GE_NO_PREFIX); |
dcbf9037 | 1518 | |
477330fc RM |
1519 | if (exp.X_op != O_constant) |
1520 | { | |
1521 | first_error (_("constant expression required")); | |
1522 | return FAIL; | |
1523 | } | |
dcbf9037 | 1524 | |
477330fc RM |
1525 | if (skip_past_char (&str, ']') == FAIL) |
1526 | return FAIL; | |
dcbf9037 | 1527 | |
477330fc RM |
1528 | atype.index = exp.X_add_number; |
1529 | } | |
dcbf9037 | 1530 | } |
5f4273c7 | 1531 | |
dcbf9037 JB |
1532 | if (typeinfo) |
1533 | *typeinfo = atype; | |
5f4273c7 | 1534 | |
dcbf9037 JB |
1535 | if (rtype) |
1536 | *rtype = type; | |
5f4273c7 | 1537 | |
dcbf9037 | 1538 | *ccp = str; |
5f4273c7 | 1539 | |
dcbf9037 JB |
1540 | return reg->number; |
1541 | } | |
1542 | ||
1543 | /* Like arm_reg_parse, but allow allow the following extra features: | |
1544 | - If RTYPE is non-zero, return the (possibly restricted) type of the | |
1545 | register (e.g. Neon double or quad reg when either has been requested). | |
1546 | - If this is a Neon vector type with additional type information, fill | |
1547 | in the struct pointed to by VECTYPE (if non-NULL). | |
5f4273c7 | 1548 | This function will fault on encountering a scalar. */ |
dcbf9037 JB |
1549 | |
1550 | static int | |
1551 | arm_typed_reg_parse (char **ccp, enum arm_reg_type type, | |
477330fc | 1552 | enum arm_reg_type *rtype, struct neon_type_el *vectype) |
dcbf9037 JB |
1553 | { |
1554 | struct neon_typed_alias atype; | |
1555 | char *str = *ccp; | |
1556 | int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype); | |
1557 | ||
1558 | if (reg == FAIL) | |
1559 | return FAIL; | |
1560 | ||
0855e32b NS |
1561 | /* Do not allow regname(... to parse as a register. */ |
1562 | if (*str == '(') | |
1563 | return FAIL; | |
1564 | ||
dcbf9037 JB |
1565 | /* Do not allow a scalar (reg+index) to parse as a register. */ |
1566 | if ((atype.defined & NTA_HASINDEX) != 0) | |
1567 | { | |
1568 | first_error (_("register operand expected, but got scalar")); | |
1569 | return FAIL; | |
1570 | } | |
1571 | ||
1572 | if (vectype) | |
1573 | *vectype = atype.eltype; | |
1574 | ||
1575 | *ccp = str; | |
1576 | ||
1577 | return reg; | |
1578 | } | |
1579 | ||
1580 | #define NEON_SCALAR_REG(X) ((X) >> 4) | |
1581 | #define NEON_SCALAR_INDEX(X) ((X) & 15) | |
1582 | ||
5287ad62 JB |
1583 | /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't |
1584 | have enough information to be able to do a good job bounds-checking. So, we | |
1585 | just do easy checks here, and do further checks later. */ | |
1586 | ||
1587 | static int | |
dcbf9037 | 1588 | parse_scalar (char **ccp, int elsize, struct neon_type_el *type) |
5287ad62 | 1589 | { |
dcbf9037 | 1590 | int reg; |
5287ad62 | 1591 | char *str = *ccp; |
dcbf9037 | 1592 | struct neon_typed_alias atype; |
5f4273c7 | 1593 | |
dcbf9037 | 1594 | reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype); |
5f4273c7 | 1595 | |
dcbf9037 | 1596 | if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0) |
5287ad62 | 1597 | return FAIL; |
5f4273c7 | 1598 | |
dcbf9037 | 1599 | if (atype.index == NEON_ALL_LANES) |
5287ad62 | 1600 | { |
dcbf9037 | 1601 | first_error (_("scalar must have an index")); |
5287ad62 JB |
1602 | return FAIL; |
1603 | } | |
dcbf9037 | 1604 | else if (atype.index >= 64 / elsize) |
5287ad62 | 1605 | { |
dcbf9037 | 1606 | first_error (_("scalar index out of range")); |
5287ad62 JB |
1607 | return FAIL; |
1608 | } | |
5f4273c7 | 1609 | |
dcbf9037 JB |
1610 | if (type) |
1611 | *type = atype.eltype; | |
5f4273c7 | 1612 | |
5287ad62 | 1613 | *ccp = str; |
5f4273c7 | 1614 | |
dcbf9037 | 1615 | return reg * 16 + atype.index; |
5287ad62 JB |
1616 | } |
1617 | ||
c19d1205 | 1618 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
e07e6e58 | 1619 | |
c19d1205 ZW |
1620 | static long |
1621 | parse_reg_list (char ** strp) | |
1622 | { | |
1623 | char * str = * strp; | |
1624 | long range = 0; | |
1625 | int another_range; | |
a737bd4d | 1626 | |
c19d1205 ZW |
1627 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
1628 | do | |
6057a28f | 1629 | { |
477330fc RM |
1630 | skip_whitespace (str); |
1631 | ||
c19d1205 | 1632 | another_range = 0; |
a737bd4d | 1633 | |
c19d1205 ZW |
1634 | if (*str == '{') |
1635 | { | |
1636 | int in_range = 0; | |
1637 | int cur_reg = -1; | |
a737bd4d | 1638 | |
c19d1205 ZW |
1639 | str++; |
1640 | do | |
1641 | { | |
1642 | int reg; | |
6057a28f | 1643 | |
dcbf9037 | 1644 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
c19d1205 | 1645 | { |
dcbf9037 | 1646 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 ZW |
1647 | return FAIL; |
1648 | } | |
a737bd4d | 1649 | |
c19d1205 ZW |
1650 | if (in_range) |
1651 | { | |
1652 | int i; | |
a737bd4d | 1653 | |
c19d1205 ZW |
1654 | if (reg <= cur_reg) |
1655 | { | |
dcbf9037 | 1656 | first_error (_("bad range in register list")); |
c19d1205 ZW |
1657 | return FAIL; |
1658 | } | |
40a18ebd | 1659 | |
c19d1205 ZW |
1660 | for (i = cur_reg + 1; i < reg; i++) |
1661 | { | |
1662 | if (range & (1 << i)) | |
1663 | as_tsktsk | |
1664 | (_("Warning: duplicated register (r%d) in register list"), | |
1665 | i); | |
1666 | else | |
1667 | range |= 1 << i; | |
1668 | } | |
1669 | in_range = 0; | |
1670 | } | |
a737bd4d | 1671 | |
c19d1205 ZW |
1672 | if (range & (1 << reg)) |
1673 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1674 | reg); | |
1675 | else if (reg <= cur_reg) | |
1676 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1677 | |
c19d1205 ZW |
1678 | range |= 1 << reg; |
1679 | cur_reg = reg; | |
1680 | } | |
1681 | while (skip_past_comma (&str) != FAIL | |
1682 | || (in_range = 1, *str++ == '-')); | |
1683 | str--; | |
a737bd4d | 1684 | |
d996d970 | 1685 | if (skip_past_char (&str, '}') == FAIL) |
c19d1205 | 1686 | { |
dcbf9037 | 1687 | first_error (_("missing `}'")); |
c19d1205 ZW |
1688 | return FAIL; |
1689 | } | |
1690 | } | |
1691 | else | |
1692 | { | |
91d6fa6a | 1693 | expressionS exp; |
40a18ebd | 1694 | |
91d6fa6a | 1695 | if (my_get_expression (&exp, &str, GE_NO_PREFIX)) |
c19d1205 | 1696 | return FAIL; |
40a18ebd | 1697 | |
91d6fa6a | 1698 | if (exp.X_op == O_constant) |
c19d1205 | 1699 | { |
91d6fa6a NC |
1700 | if (exp.X_add_number |
1701 | != (exp.X_add_number & 0x0000ffff)) | |
c19d1205 ZW |
1702 | { |
1703 | inst.error = _("invalid register mask"); | |
1704 | return FAIL; | |
1705 | } | |
a737bd4d | 1706 | |
91d6fa6a | 1707 | if ((range & exp.X_add_number) != 0) |
c19d1205 | 1708 | { |
91d6fa6a | 1709 | int regno = range & exp.X_add_number; |
a737bd4d | 1710 | |
c19d1205 ZW |
1711 | regno &= -regno; |
1712 | regno = (1 << regno) - 1; | |
1713 | as_tsktsk | |
1714 | (_("Warning: duplicated register (r%d) in register list"), | |
1715 | regno); | |
1716 | } | |
a737bd4d | 1717 | |
91d6fa6a | 1718 | range |= exp.X_add_number; |
c19d1205 ZW |
1719 | } |
1720 | else | |
1721 | { | |
1722 | if (inst.reloc.type != 0) | |
1723 | { | |
1724 | inst.error = _("expression too complex"); | |
1725 | return FAIL; | |
1726 | } | |
a737bd4d | 1727 | |
91d6fa6a | 1728 | memcpy (&inst.reloc.exp, &exp, sizeof (expressionS)); |
c19d1205 ZW |
1729 | inst.reloc.type = BFD_RELOC_ARM_MULTI; |
1730 | inst.reloc.pc_rel = 0; | |
1731 | } | |
1732 | } | |
a737bd4d | 1733 | |
c19d1205 ZW |
1734 | if (*str == '|' || *str == '+') |
1735 | { | |
1736 | str++; | |
1737 | another_range = 1; | |
1738 | } | |
a737bd4d | 1739 | } |
c19d1205 | 1740 | while (another_range); |
a737bd4d | 1741 | |
c19d1205 ZW |
1742 | *strp = str; |
1743 | return range; | |
a737bd4d NC |
1744 | } |
1745 | ||
5287ad62 JB |
1746 | /* Types of registers in a list. */ |
1747 | ||
1748 | enum reg_list_els | |
1749 | { | |
1750 | REGLIST_VFP_S, | |
1751 | REGLIST_VFP_D, | |
1752 | REGLIST_NEON_D | |
1753 | }; | |
1754 | ||
c19d1205 ZW |
1755 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1756 | Otherwise return the number of registers, and set PBASE to the first | |
5287ad62 JB |
1757 | register. Parses registers of type ETYPE. |
1758 | If REGLIST_NEON_D is used, several syntax enhancements are enabled: | |
1759 | - Q registers can be used to specify pairs of D registers | |
1760 | - { } can be omitted from around a singleton register list | |
477330fc RM |
1761 | FIXME: This is not implemented, as it would require backtracking in |
1762 | some cases, e.g.: | |
1763 | vtbl.8 d3,d4,d5 | |
1764 | This could be done (the meaning isn't really ambiguous), but doesn't | |
1765 | fit in well with the current parsing framework. | |
dcbf9037 JB |
1766 | - 32 D registers may be used (also true for VFPv3). |
1767 | FIXME: Types are ignored in these register lists, which is probably a | |
1768 | bug. */ | |
6057a28f | 1769 | |
c19d1205 | 1770 | static int |
037e8744 | 1771 | parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype) |
6057a28f | 1772 | { |
037e8744 | 1773 | char *str = *ccp; |
c19d1205 ZW |
1774 | int base_reg; |
1775 | int new_base; | |
21d799b5 | 1776 | enum arm_reg_type regtype = (enum arm_reg_type) 0; |
5287ad62 | 1777 | int max_regs = 0; |
c19d1205 ZW |
1778 | int count = 0; |
1779 | int warned = 0; | |
1780 | unsigned long mask = 0; | |
a737bd4d | 1781 | int i; |
6057a28f | 1782 | |
477330fc | 1783 | if (skip_past_char (&str, '{') == FAIL) |
5287ad62 JB |
1784 | { |
1785 | inst.error = _("expecting {"); | |
1786 | return FAIL; | |
1787 | } | |
6057a28f | 1788 | |
5287ad62 | 1789 | switch (etype) |
c19d1205 | 1790 | { |
5287ad62 | 1791 | case REGLIST_VFP_S: |
c19d1205 ZW |
1792 | regtype = REG_TYPE_VFS; |
1793 | max_regs = 32; | |
5287ad62 | 1794 | break; |
5f4273c7 | 1795 | |
5287ad62 JB |
1796 | case REGLIST_VFP_D: |
1797 | regtype = REG_TYPE_VFD; | |
b7fc2769 | 1798 | break; |
5f4273c7 | 1799 | |
b7fc2769 JB |
1800 | case REGLIST_NEON_D: |
1801 | regtype = REG_TYPE_NDQ; | |
1802 | break; | |
1803 | } | |
1804 | ||
1805 | if (etype != REGLIST_VFP_S) | |
1806 | { | |
b1cc4aeb PB |
1807 | /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */ |
1808 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) | |
477330fc RM |
1809 | { |
1810 | max_regs = 32; | |
1811 | if (thumb_mode) | |
1812 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
1813 | fpu_vfp_ext_d32); | |
1814 | else | |
1815 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
1816 | fpu_vfp_ext_d32); | |
1817 | } | |
5287ad62 | 1818 | else |
477330fc | 1819 | max_regs = 16; |
c19d1205 | 1820 | } |
6057a28f | 1821 | |
c19d1205 | 1822 | base_reg = max_regs; |
a737bd4d | 1823 | |
c19d1205 ZW |
1824 | do |
1825 | { | |
5287ad62 | 1826 | int setmask = 1, addregs = 1; |
dcbf9037 | 1827 | |
037e8744 | 1828 | new_base = arm_typed_reg_parse (&str, regtype, ®type, NULL); |
dcbf9037 | 1829 | |
c19d1205 | 1830 | if (new_base == FAIL) |
a737bd4d | 1831 | { |
dcbf9037 | 1832 | first_error (_(reg_expected_msgs[regtype])); |
c19d1205 ZW |
1833 | return FAIL; |
1834 | } | |
5f4273c7 | 1835 | |
b7fc2769 | 1836 | if (new_base >= max_regs) |
477330fc RM |
1837 | { |
1838 | first_error (_("register out of range in list")); | |
1839 | return FAIL; | |
1840 | } | |
5f4273c7 | 1841 | |
5287ad62 JB |
1842 | /* Note: a value of 2 * n is returned for the register Q<n>. */ |
1843 | if (regtype == REG_TYPE_NQ) | |
477330fc RM |
1844 | { |
1845 | setmask = 3; | |
1846 | addregs = 2; | |
1847 | } | |
5287ad62 | 1848 | |
c19d1205 ZW |
1849 | if (new_base < base_reg) |
1850 | base_reg = new_base; | |
a737bd4d | 1851 | |
5287ad62 | 1852 | if (mask & (setmask << new_base)) |
c19d1205 | 1853 | { |
dcbf9037 | 1854 | first_error (_("invalid register list")); |
c19d1205 | 1855 | return FAIL; |
a737bd4d | 1856 | } |
a737bd4d | 1857 | |
c19d1205 ZW |
1858 | if ((mask >> new_base) != 0 && ! warned) |
1859 | { | |
1860 | as_tsktsk (_("register list not in ascending order")); | |
1861 | warned = 1; | |
1862 | } | |
0bbf2aa4 | 1863 | |
5287ad62 JB |
1864 | mask |= setmask << new_base; |
1865 | count += addregs; | |
0bbf2aa4 | 1866 | |
037e8744 | 1867 | if (*str == '-') /* We have the start of a range expression */ |
c19d1205 ZW |
1868 | { |
1869 | int high_range; | |
0bbf2aa4 | 1870 | |
037e8744 | 1871 | str++; |
0bbf2aa4 | 1872 | |
037e8744 | 1873 | if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL)) |
477330fc | 1874 | == FAIL) |
c19d1205 ZW |
1875 | { |
1876 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1877 | return FAIL; | |
1878 | } | |
0bbf2aa4 | 1879 | |
477330fc RM |
1880 | if (high_range >= max_regs) |
1881 | { | |
1882 | first_error (_("register out of range in list")); | |
1883 | return FAIL; | |
1884 | } | |
b7fc2769 | 1885 | |
477330fc RM |
1886 | if (regtype == REG_TYPE_NQ) |
1887 | high_range = high_range + 1; | |
5287ad62 | 1888 | |
c19d1205 ZW |
1889 | if (high_range <= new_base) |
1890 | { | |
1891 | inst.error = _("register range not in ascending order"); | |
1892 | return FAIL; | |
1893 | } | |
0bbf2aa4 | 1894 | |
5287ad62 | 1895 | for (new_base += addregs; new_base <= high_range; new_base += addregs) |
0bbf2aa4 | 1896 | { |
5287ad62 | 1897 | if (mask & (setmask << new_base)) |
0bbf2aa4 | 1898 | { |
c19d1205 ZW |
1899 | inst.error = _("invalid register list"); |
1900 | return FAIL; | |
0bbf2aa4 | 1901 | } |
c19d1205 | 1902 | |
5287ad62 JB |
1903 | mask |= setmask << new_base; |
1904 | count += addregs; | |
0bbf2aa4 | 1905 | } |
0bbf2aa4 | 1906 | } |
0bbf2aa4 | 1907 | } |
037e8744 | 1908 | while (skip_past_comma (&str) != FAIL); |
0bbf2aa4 | 1909 | |
037e8744 | 1910 | str++; |
0bbf2aa4 | 1911 | |
c19d1205 ZW |
1912 | /* Sanity check -- should have raised a parse error above. */ |
1913 | if (count == 0 || count > max_regs) | |
1914 | abort (); | |
1915 | ||
1916 | *pbase = base_reg; | |
1917 | ||
1918 | /* Final test -- the registers must be consecutive. */ | |
1919 | mask >>= base_reg; | |
1920 | for (i = 0; i < count; i++) | |
1921 | { | |
1922 | if ((mask & (1u << i)) == 0) | |
1923 | { | |
1924 | inst.error = _("non-contiguous register range"); | |
1925 | return FAIL; | |
1926 | } | |
1927 | } | |
1928 | ||
037e8744 JB |
1929 | *ccp = str; |
1930 | ||
c19d1205 | 1931 | return count; |
b99bd4ef NC |
1932 | } |
1933 | ||
dcbf9037 JB |
1934 | /* True if two alias types are the same. */ |
1935 | ||
c921be7d | 1936 | static bfd_boolean |
dcbf9037 JB |
1937 | neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b) |
1938 | { | |
1939 | if (!a && !b) | |
c921be7d | 1940 | return TRUE; |
5f4273c7 | 1941 | |
dcbf9037 | 1942 | if (!a || !b) |
c921be7d | 1943 | return FALSE; |
dcbf9037 JB |
1944 | |
1945 | if (a->defined != b->defined) | |
c921be7d | 1946 | return FALSE; |
5f4273c7 | 1947 | |
dcbf9037 JB |
1948 | if ((a->defined & NTA_HASTYPE) != 0 |
1949 | && (a->eltype.type != b->eltype.type | |
477330fc | 1950 | || a->eltype.size != b->eltype.size)) |
c921be7d | 1951 | return FALSE; |
dcbf9037 JB |
1952 | |
1953 | if ((a->defined & NTA_HASINDEX) != 0 | |
1954 | && (a->index != b->index)) | |
c921be7d | 1955 | return FALSE; |
5f4273c7 | 1956 | |
c921be7d | 1957 | return TRUE; |
dcbf9037 JB |
1958 | } |
1959 | ||
5287ad62 JB |
1960 | /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions. |
1961 | The base register is put in *PBASE. | |
dcbf9037 | 1962 | The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of |
5287ad62 JB |
1963 | the return value. |
1964 | The register stride (minus one) is put in bit 4 of the return value. | |
dcbf9037 JB |
1965 | Bits [6:5] encode the list length (minus one). |
1966 | The type of the list elements is put in *ELTYPE, if non-NULL. */ | |
5287ad62 | 1967 | |
5287ad62 | 1968 | #define NEON_LANE(X) ((X) & 0xf) |
dcbf9037 | 1969 | #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1) |
5287ad62 JB |
1970 | #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1) |
1971 | ||
1972 | static int | |
dcbf9037 | 1973 | parse_neon_el_struct_list (char **str, unsigned *pbase, |
477330fc | 1974 | struct neon_type_el *eltype) |
5287ad62 JB |
1975 | { |
1976 | char *ptr = *str; | |
1977 | int base_reg = -1; | |
1978 | int reg_incr = -1; | |
1979 | int count = 0; | |
1980 | int lane = -1; | |
1981 | int leading_brace = 0; | |
1982 | enum arm_reg_type rtype = REG_TYPE_NDQ; | |
20203fb9 NC |
1983 | const char *const incr_error = _("register stride must be 1 or 2"); |
1984 | const char *const type_error = _("mismatched element/structure types in list"); | |
dcbf9037 | 1985 | struct neon_typed_alias firsttype; |
5f4273c7 | 1986 | |
5287ad62 JB |
1987 | if (skip_past_char (&ptr, '{') == SUCCESS) |
1988 | leading_brace = 1; | |
5f4273c7 | 1989 | |
5287ad62 JB |
1990 | do |
1991 | { | |
dcbf9037 JB |
1992 | struct neon_typed_alias atype; |
1993 | int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype); | |
1994 | ||
5287ad62 | 1995 | if (getreg == FAIL) |
477330fc RM |
1996 | { |
1997 | first_error (_(reg_expected_msgs[rtype])); | |
1998 | return FAIL; | |
1999 | } | |
5f4273c7 | 2000 | |
5287ad62 | 2001 | if (base_reg == -1) |
477330fc RM |
2002 | { |
2003 | base_reg = getreg; | |
2004 | if (rtype == REG_TYPE_NQ) | |
2005 | { | |
2006 | reg_incr = 1; | |
2007 | } | |
2008 | firsttype = atype; | |
2009 | } | |
5287ad62 | 2010 | else if (reg_incr == -1) |
477330fc RM |
2011 | { |
2012 | reg_incr = getreg - base_reg; | |
2013 | if (reg_incr < 1 || reg_incr > 2) | |
2014 | { | |
2015 | first_error (_(incr_error)); | |
2016 | return FAIL; | |
2017 | } | |
2018 | } | |
5287ad62 | 2019 | else if (getreg != base_reg + reg_incr * count) |
477330fc RM |
2020 | { |
2021 | first_error (_(incr_error)); | |
2022 | return FAIL; | |
2023 | } | |
dcbf9037 | 2024 | |
c921be7d | 2025 | if (! neon_alias_types_same (&atype, &firsttype)) |
477330fc RM |
2026 | { |
2027 | first_error (_(type_error)); | |
2028 | return FAIL; | |
2029 | } | |
5f4273c7 | 2030 | |
5287ad62 | 2031 | /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list |
477330fc | 2032 | modes. */ |
5287ad62 | 2033 | if (ptr[0] == '-') |
477330fc RM |
2034 | { |
2035 | struct neon_typed_alias htype; | |
2036 | int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1; | |
2037 | if (lane == -1) | |
2038 | lane = NEON_INTERLEAVE_LANES; | |
2039 | else if (lane != NEON_INTERLEAVE_LANES) | |
2040 | { | |
2041 | first_error (_(type_error)); | |
2042 | return FAIL; | |
2043 | } | |
2044 | if (reg_incr == -1) | |
2045 | reg_incr = 1; | |
2046 | else if (reg_incr != 1) | |
2047 | { | |
2048 | first_error (_("don't use Rn-Rm syntax with non-unit stride")); | |
2049 | return FAIL; | |
2050 | } | |
2051 | ptr++; | |
2052 | hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype); | |
2053 | if (hireg == FAIL) | |
2054 | { | |
2055 | first_error (_(reg_expected_msgs[rtype])); | |
2056 | return FAIL; | |
2057 | } | |
2058 | if (! neon_alias_types_same (&htype, &firsttype)) | |
2059 | { | |
2060 | first_error (_(type_error)); | |
2061 | return FAIL; | |
2062 | } | |
2063 | count += hireg + dregs - getreg; | |
2064 | continue; | |
2065 | } | |
5f4273c7 | 2066 | |
5287ad62 JB |
2067 | /* If we're using Q registers, we can't use [] or [n] syntax. */ |
2068 | if (rtype == REG_TYPE_NQ) | |
477330fc RM |
2069 | { |
2070 | count += 2; | |
2071 | continue; | |
2072 | } | |
5f4273c7 | 2073 | |
dcbf9037 | 2074 | if ((atype.defined & NTA_HASINDEX) != 0) |
477330fc RM |
2075 | { |
2076 | if (lane == -1) | |
2077 | lane = atype.index; | |
2078 | else if (lane != atype.index) | |
2079 | { | |
2080 | first_error (_(type_error)); | |
2081 | return FAIL; | |
2082 | } | |
2083 | } | |
5287ad62 | 2084 | else if (lane == -1) |
477330fc | 2085 | lane = NEON_INTERLEAVE_LANES; |
5287ad62 | 2086 | else if (lane != NEON_INTERLEAVE_LANES) |
477330fc RM |
2087 | { |
2088 | first_error (_(type_error)); | |
2089 | return FAIL; | |
2090 | } | |
5287ad62 JB |
2091 | count++; |
2092 | } | |
2093 | while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL); | |
5f4273c7 | 2094 | |
5287ad62 JB |
2095 | /* No lane set by [x]. We must be interleaving structures. */ |
2096 | if (lane == -1) | |
2097 | lane = NEON_INTERLEAVE_LANES; | |
5f4273c7 | 2098 | |
5287ad62 JB |
2099 | /* Sanity check. */ |
2100 | if (lane == -1 || base_reg == -1 || count < 1 || count > 4 | |
2101 | || (count > 1 && reg_incr == -1)) | |
2102 | { | |
dcbf9037 | 2103 | first_error (_("error parsing element/structure list")); |
5287ad62 JB |
2104 | return FAIL; |
2105 | } | |
2106 | ||
2107 | if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL) | |
2108 | { | |
dcbf9037 | 2109 | first_error (_("expected }")); |
5287ad62 JB |
2110 | return FAIL; |
2111 | } | |
5f4273c7 | 2112 | |
5287ad62 JB |
2113 | if (reg_incr == -1) |
2114 | reg_incr = 1; | |
2115 | ||
dcbf9037 JB |
2116 | if (eltype) |
2117 | *eltype = firsttype.eltype; | |
2118 | ||
5287ad62 JB |
2119 | *pbase = base_reg; |
2120 | *str = ptr; | |
5f4273c7 | 2121 | |
5287ad62 JB |
2122 | return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5); |
2123 | } | |
2124 | ||
c19d1205 ZW |
2125 | /* Parse an explicit relocation suffix on an expression. This is |
2126 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
2127 | arm_reloc_hsh contains no entries, so this function can only | |
2128 | succeed if there is no () after the word. Returns -1 on error, | |
2129 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
3da1d841 | 2130 | |
c19d1205 ZW |
2131 | static int |
2132 | parse_reloc (char **str) | |
b99bd4ef | 2133 | { |
c19d1205 ZW |
2134 | struct reloc_entry *r; |
2135 | char *p, *q; | |
b99bd4ef | 2136 | |
c19d1205 ZW |
2137 | if (**str != '(') |
2138 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 2139 | |
c19d1205 ZW |
2140 | p = *str + 1; |
2141 | q = p; | |
2142 | ||
2143 | while (*q && *q != ')' && *q != ',') | |
2144 | q++; | |
2145 | if (*q != ')') | |
2146 | return -1; | |
2147 | ||
21d799b5 NC |
2148 | if ((r = (struct reloc_entry *) |
2149 | hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
c19d1205 ZW |
2150 | return -1; |
2151 | ||
2152 | *str = q + 1; | |
2153 | return r->reloc; | |
b99bd4ef NC |
2154 | } |
2155 | ||
c19d1205 ZW |
2156 | /* Directives: register aliases. */ |
2157 | ||
dcbf9037 | 2158 | static struct reg_entry * |
90ec0d68 | 2159 | insert_reg_alias (char *str, unsigned number, int type) |
b99bd4ef | 2160 | { |
d3ce72d0 | 2161 | struct reg_entry *new_reg; |
c19d1205 | 2162 | const char *name; |
b99bd4ef | 2163 | |
d3ce72d0 | 2164 | if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0) |
c19d1205 | 2165 | { |
d3ce72d0 | 2166 | if (new_reg->builtin) |
c19d1205 | 2167 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); |
b99bd4ef | 2168 | |
c19d1205 ZW |
2169 | /* Only warn about a redefinition if it's not defined as the |
2170 | same register. */ | |
d3ce72d0 | 2171 | else if (new_reg->number != number || new_reg->type != type) |
c19d1205 | 2172 | as_warn (_("ignoring redefinition of register alias '%s'"), str); |
69b97547 | 2173 | |
d929913e | 2174 | return NULL; |
c19d1205 | 2175 | } |
b99bd4ef | 2176 | |
c19d1205 | 2177 | name = xstrdup (str); |
d3ce72d0 | 2178 | new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry)); |
b99bd4ef | 2179 | |
d3ce72d0 NC |
2180 | new_reg->name = name; |
2181 | new_reg->number = number; | |
2182 | new_reg->type = type; | |
2183 | new_reg->builtin = FALSE; | |
2184 | new_reg->neon = NULL; | |
b99bd4ef | 2185 | |
d3ce72d0 | 2186 | if (hash_insert (arm_reg_hsh, name, (void *) new_reg)) |
c19d1205 | 2187 | abort (); |
5f4273c7 | 2188 | |
d3ce72d0 | 2189 | return new_reg; |
dcbf9037 JB |
2190 | } |
2191 | ||
2192 | static void | |
2193 | insert_neon_reg_alias (char *str, int number, int type, | |
477330fc | 2194 | struct neon_typed_alias *atype) |
dcbf9037 JB |
2195 | { |
2196 | struct reg_entry *reg = insert_reg_alias (str, number, type); | |
5f4273c7 | 2197 | |
dcbf9037 JB |
2198 | if (!reg) |
2199 | { | |
2200 | first_error (_("attempt to redefine typed alias")); | |
2201 | return; | |
2202 | } | |
5f4273c7 | 2203 | |
dcbf9037 JB |
2204 | if (atype) |
2205 | { | |
21d799b5 | 2206 | reg->neon = (struct neon_typed_alias *) |
477330fc | 2207 | xmalloc (sizeof (struct neon_typed_alias)); |
dcbf9037 JB |
2208 | *reg->neon = *atype; |
2209 | } | |
c19d1205 | 2210 | } |
b99bd4ef | 2211 | |
c19d1205 | 2212 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 2213 | |
c19d1205 | 2214 | new_register_name .req existing_register_name |
b99bd4ef | 2215 | |
c19d1205 | 2216 | If we find one, or if it looks sufficiently like one that we want to |
d929913e | 2217 | handle any error here, return TRUE. Otherwise return FALSE. */ |
b99bd4ef | 2218 | |
d929913e | 2219 | static bfd_boolean |
c19d1205 ZW |
2220 | create_register_alias (char * newname, char *p) |
2221 | { | |
2222 | struct reg_entry *old; | |
2223 | char *oldname, *nbuf; | |
2224 | size_t nlen; | |
b99bd4ef | 2225 | |
c19d1205 ZW |
2226 | /* The input scrubber ensures that whitespace after the mnemonic is |
2227 | collapsed to single spaces. */ | |
2228 | oldname = p; | |
2229 | if (strncmp (oldname, " .req ", 6) != 0) | |
d929913e | 2230 | return FALSE; |
b99bd4ef | 2231 | |
c19d1205 ZW |
2232 | oldname += 6; |
2233 | if (*oldname == '\0') | |
d929913e | 2234 | return FALSE; |
b99bd4ef | 2235 | |
21d799b5 | 2236 | old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname); |
c19d1205 | 2237 | if (!old) |
b99bd4ef | 2238 | { |
c19d1205 | 2239 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
d929913e | 2240 | return TRUE; |
b99bd4ef NC |
2241 | } |
2242 | ||
c19d1205 ZW |
2243 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2244 | the desired alias name, and p points to its end. If not, then | |
2245 | the desired alias name is in the global original_case_string. */ | |
2246 | #ifdef TC_CASE_SENSITIVE | |
2247 | nlen = p - newname; | |
2248 | #else | |
2249 | newname = original_case_string; | |
2250 | nlen = strlen (newname); | |
2251 | #endif | |
b99bd4ef | 2252 | |
21d799b5 | 2253 | nbuf = (char *) alloca (nlen + 1); |
c19d1205 ZW |
2254 | memcpy (nbuf, newname, nlen); |
2255 | nbuf[nlen] = '\0'; | |
b99bd4ef | 2256 | |
c19d1205 ZW |
2257 | /* Create aliases under the new name as stated; an all-lowercase |
2258 | version of the new name; and an all-uppercase version of the new | |
2259 | name. */ | |
d929913e NC |
2260 | if (insert_reg_alias (nbuf, old->number, old->type) != NULL) |
2261 | { | |
2262 | for (p = nbuf; *p; p++) | |
2263 | *p = TOUPPER (*p); | |
c19d1205 | 2264 | |
d929913e NC |
2265 | if (strncmp (nbuf, newname, nlen)) |
2266 | { | |
2267 | /* If this attempt to create an additional alias fails, do not bother | |
2268 | trying to create the all-lower case alias. We will fail and issue | |
2269 | a second, duplicate error message. This situation arises when the | |
2270 | programmer does something like: | |
2271 | foo .req r0 | |
2272 | Foo .req r1 | |
2273 | The second .req creates the "Foo" alias but then fails to create | |
5f4273c7 | 2274 | the artificial FOO alias because it has already been created by the |
d929913e NC |
2275 | first .req. */ |
2276 | if (insert_reg_alias (nbuf, old->number, old->type) == NULL) | |
2277 | return TRUE; | |
2278 | } | |
c19d1205 | 2279 | |
d929913e NC |
2280 | for (p = nbuf; *p; p++) |
2281 | *p = TOLOWER (*p); | |
c19d1205 | 2282 | |
d929913e NC |
2283 | if (strncmp (nbuf, newname, nlen)) |
2284 | insert_reg_alias (nbuf, old->number, old->type); | |
2285 | } | |
c19d1205 | 2286 | |
d929913e | 2287 | return TRUE; |
b99bd4ef NC |
2288 | } |
2289 | ||
dcbf9037 JB |
2290 | /* Create a Neon typed/indexed register alias using directives, e.g.: |
2291 | X .dn d5.s32[1] | |
2292 | Y .qn 6.s16 | |
2293 | Z .dn d7 | |
2294 | T .dn Z[0] | |
2295 | These typed registers can be used instead of the types specified after the | |
2296 | Neon mnemonic, so long as all operands given have types. Types can also be | |
2297 | specified directly, e.g.: | |
5f4273c7 | 2298 | vadd d0.s32, d1.s32, d2.s32 */ |
dcbf9037 | 2299 | |
c921be7d | 2300 | static bfd_boolean |
dcbf9037 JB |
2301 | create_neon_reg_alias (char *newname, char *p) |
2302 | { | |
2303 | enum arm_reg_type basetype; | |
2304 | struct reg_entry *basereg; | |
2305 | struct reg_entry mybasereg; | |
2306 | struct neon_type ntype; | |
2307 | struct neon_typed_alias typeinfo; | |
12d6b0b7 | 2308 | char *namebuf, *nameend ATTRIBUTE_UNUSED; |
dcbf9037 | 2309 | int namelen; |
5f4273c7 | 2310 | |
dcbf9037 JB |
2311 | typeinfo.defined = 0; |
2312 | typeinfo.eltype.type = NT_invtype; | |
2313 | typeinfo.eltype.size = -1; | |
2314 | typeinfo.index = -1; | |
5f4273c7 | 2315 | |
dcbf9037 | 2316 | nameend = p; |
5f4273c7 | 2317 | |
dcbf9037 JB |
2318 | if (strncmp (p, " .dn ", 5) == 0) |
2319 | basetype = REG_TYPE_VFD; | |
2320 | else if (strncmp (p, " .qn ", 5) == 0) | |
2321 | basetype = REG_TYPE_NQ; | |
2322 | else | |
c921be7d | 2323 | return FALSE; |
5f4273c7 | 2324 | |
dcbf9037 | 2325 | p += 5; |
5f4273c7 | 2326 | |
dcbf9037 | 2327 | if (*p == '\0') |
c921be7d | 2328 | return FALSE; |
5f4273c7 | 2329 | |
dcbf9037 JB |
2330 | basereg = arm_reg_parse_multi (&p); |
2331 | ||
2332 | if (basereg && basereg->type != basetype) | |
2333 | { | |
2334 | as_bad (_("bad type for register")); | |
c921be7d | 2335 | return FALSE; |
dcbf9037 JB |
2336 | } |
2337 | ||
2338 | if (basereg == NULL) | |
2339 | { | |
2340 | expressionS exp; | |
2341 | /* Try parsing as an integer. */ | |
2342 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
2343 | if (exp.X_op != O_constant) | |
477330fc RM |
2344 | { |
2345 | as_bad (_("expression must be constant")); | |
2346 | return FALSE; | |
2347 | } | |
dcbf9037 JB |
2348 | basereg = &mybasereg; |
2349 | basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2 | |
477330fc | 2350 | : exp.X_add_number; |
dcbf9037 JB |
2351 | basereg->neon = 0; |
2352 | } | |
2353 | ||
2354 | if (basereg->neon) | |
2355 | typeinfo = *basereg->neon; | |
2356 | ||
2357 | if (parse_neon_type (&ntype, &p) == SUCCESS) | |
2358 | { | |
2359 | /* We got a type. */ | |
2360 | if (typeinfo.defined & NTA_HASTYPE) | |
477330fc RM |
2361 | { |
2362 | as_bad (_("can't redefine the type of a register alias")); | |
2363 | return FALSE; | |
2364 | } | |
5f4273c7 | 2365 | |
dcbf9037 JB |
2366 | typeinfo.defined |= NTA_HASTYPE; |
2367 | if (ntype.elems != 1) | |
477330fc RM |
2368 | { |
2369 | as_bad (_("you must specify a single type only")); | |
2370 | return FALSE; | |
2371 | } | |
dcbf9037 JB |
2372 | typeinfo.eltype = ntype.el[0]; |
2373 | } | |
5f4273c7 | 2374 | |
dcbf9037 JB |
2375 | if (skip_past_char (&p, '[') == SUCCESS) |
2376 | { | |
2377 | expressionS exp; | |
2378 | /* We got a scalar index. */ | |
5f4273c7 | 2379 | |
dcbf9037 | 2380 | if (typeinfo.defined & NTA_HASINDEX) |
477330fc RM |
2381 | { |
2382 | as_bad (_("can't redefine the index of a scalar alias")); | |
2383 | return FALSE; | |
2384 | } | |
5f4273c7 | 2385 | |
dcbf9037 | 2386 | my_get_expression (&exp, &p, GE_NO_PREFIX); |
5f4273c7 | 2387 | |
dcbf9037 | 2388 | if (exp.X_op != O_constant) |
477330fc RM |
2389 | { |
2390 | as_bad (_("scalar index must be constant")); | |
2391 | return FALSE; | |
2392 | } | |
5f4273c7 | 2393 | |
dcbf9037 JB |
2394 | typeinfo.defined |= NTA_HASINDEX; |
2395 | typeinfo.index = exp.X_add_number; | |
5f4273c7 | 2396 | |
dcbf9037 | 2397 | if (skip_past_char (&p, ']') == FAIL) |
477330fc RM |
2398 | { |
2399 | as_bad (_("expecting ]")); | |
2400 | return FALSE; | |
2401 | } | |
dcbf9037 JB |
2402 | } |
2403 | ||
15735687 NS |
2404 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
2405 | the desired alias name, and p points to its end. If not, then | |
2406 | the desired alias name is in the global original_case_string. */ | |
2407 | #ifdef TC_CASE_SENSITIVE | |
dcbf9037 | 2408 | namelen = nameend - newname; |
15735687 NS |
2409 | #else |
2410 | newname = original_case_string; | |
2411 | namelen = strlen (newname); | |
2412 | #endif | |
2413 | ||
21d799b5 | 2414 | namebuf = (char *) alloca (namelen + 1); |
dcbf9037 JB |
2415 | strncpy (namebuf, newname, namelen); |
2416 | namebuf[namelen] = '\0'; | |
5f4273c7 | 2417 | |
dcbf9037 | 2418 | insert_neon_reg_alias (namebuf, basereg->number, basetype, |
477330fc | 2419 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2420 | |
dcbf9037 JB |
2421 | /* Insert name in all uppercase. */ |
2422 | for (p = namebuf; *p; p++) | |
2423 | *p = TOUPPER (*p); | |
5f4273c7 | 2424 | |
dcbf9037 JB |
2425 | if (strncmp (namebuf, newname, namelen)) |
2426 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2427 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2428 | |
dcbf9037 JB |
2429 | /* Insert name in all lowercase. */ |
2430 | for (p = namebuf; *p; p++) | |
2431 | *p = TOLOWER (*p); | |
5f4273c7 | 2432 | |
dcbf9037 JB |
2433 | if (strncmp (namebuf, newname, namelen)) |
2434 | insert_neon_reg_alias (namebuf, basereg->number, basetype, | |
477330fc | 2435 | typeinfo.defined != 0 ? &typeinfo : NULL); |
5f4273c7 | 2436 | |
c921be7d | 2437 | return TRUE; |
dcbf9037 JB |
2438 | } |
2439 | ||
c19d1205 ZW |
2440 | /* Should never be called, as .req goes between the alias and the |
2441 | register name, not at the beginning of the line. */ | |
c921be7d | 2442 | |
b99bd4ef | 2443 | static void |
c19d1205 | 2444 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2445 | { |
c19d1205 ZW |
2446 | as_bad (_("invalid syntax for .req directive")); |
2447 | } | |
b99bd4ef | 2448 | |
dcbf9037 JB |
2449 | static void |
2450 | s_dn (int a ATTRIBUTE_UNUSED) | |
2451 | { | |
2452 | as_bad (_("invalid syntax for .dn directive")); | |
2453 | } | |
2454 | ||
2455 | static void | |
2456 | s_qn (int a ATTRIBUTE_UNUSED) | |
2457 | { | |
2458 | as_bad (_("invalid syntax for .qn directive")); | |
2459 | } | |
2460 | ||
c19d1205 ZW |
2461 | /* The .unreq directive deletes an alias which was previously defined |
2462 | by .req. For example: | |
b99bd4ef | 2463 | |
c19d1205 ZW |
2464 | my_alias .req r11 |
2465 | .unreq my_alias */ | |
b99bd4ef NC |
2466 | |
2467 | static void | |
c19d1205 | 2468 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 2469 | { |
c19d1205 ZW |
2470 | char * name; |
2471 | char saved_char; | |
b99bd4ef | 2472 | |
c19d1205 ZW |
2473 | name = input_line_pointer; |
2474 | ||
2475 | while (*input_line_pointer != 0 | |
2476 | && *input_line_pointer != ' ' | |
2477 | && *input_line_pointer != '\n') | |
2478 | ++input_line_pointer; | |
2479 | ||
2480 | saved_char = *input_line_pointer; | |
2481 | *input_line_pointer = 0; | |
2482 | ||
2483 | if (!*name) | |
2484 | as_bad (_("invalid syntax for .unreq directive")); | |
2485 | else | |
2486 | { | |
21d799b5 | 2487 | struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh, |
477330fc | 2488 | name); |
c19d1205 ZW |
2489 | |
2490 | if (!reg) | |
2491 | as_bad (_("unknown register alias '%s'"), name); | |
2492 | else if (reg->builtin) | |
a1727c1a | 2493 | as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"), |
c19d1205 ZW |
2494 | name); |
2495 | else | |
2496 | { | |
d929913e NC |
2497 | char * p; |
2498 | char * nbuf; | |
2499 | ||
db0bc284 | 2500 | hash_delete (arm_reg_hsh, name, FALSE); |
c19d1205 | 2501 | free ((char *) reg->name); |
477330fc RM |
2502 | if (reg->neon) |
2503 | free (reg->neon); | |
c19d1205 | 2504 | free (reg); |
d929913e NC |
2505 | |
2506 | /* Also locate the all upper case and all lower case versions. | |
2507 | Do not complain if we cannot find one or the other as it | |
2508 | was probably deleted above. */ | |
5f4273c7 | 2509 | |
d929913e NC |
2510 | nbuf = strdup (name); |
2511 | for (p = nbuf; *p; p++) | |
2512 | *p = TOUPPER (*p); | |
21d799b5 | 2513 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2514 | if (reg) |
2515 | { | |
db0bc284 | 2516 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2517 | free ((char *) reg->name); |
2518 | if (reg->neon) | |
2519 | free (reg->neon); | |
2520 | free (reg); | |
2521 | } | |
2522 | ||
2523 | for (p = nbuf; *p; p++) | |
2524 | *p = TOLOWER (*p); | |
21d799b5 | 2525 | reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf); |
d929913e NC |
2526 | if (reg) |
2527 | { | |
db0bc284 | 2528 | hash_delete (arm_reg_hsh, nbuf, FALSE); |
d929913e NC |
2529 | free ((char *) reg->name); |
2530 | if (reg->neon) | |
2531 | free (reg->neon); | |
2532 | free (reg); | |
2533 | } | |
2534 | ||
2535 | free (nbuf); | |
c19d1205 ZW |
2536 | } |
2537 | } | |
b99bd4ef | 2538 | |
c19d1205 | 2539 | *input_line_pointer = saved_char; |
b99bd4ef NC |
2540 | demand_empty_rest_of_line (); |
2541 | } | |
2542 | ||
c19d1205 ZW |
2543 | /* Directives: Instruction set selection. */ |
2544 | ||
2545 | #ifdef OBJ_ELF | |
2546 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
2547 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
2548 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
2549 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
2550 | ||
cd000bff DJ |
2551 | /* Create a new mapping symbol for the transition to STATE. */ |
2552 | ||
2553 | static void | |
2554 | make_mapping_symbol (enum mstate state, valueT value, fragS *frag) | |
b99bd4ef | 2555 | { |
a737bd4d | 2556 | symbolS * symbolP; |
c19d1205 ZW |
2557 | const char * symname; |
2558 | int type; | |
b99bd4ef | 2559 | |
c19d1205 | 2560 | switch (state) |
b99bd4ef | 2561 | { |
c19d1205 ZW |
2562 | case MAP_DATA: |
2563 | symname = "$d"; | |
2564 | type = BSF_NO_FLAGS; | |
2565 | break; | |
2566 | case MAP_ARM: | |
2567 | symname = "$a"; | |
2568 | type = BSF_NO_FLAGS; | |
2569 | break; | |
2570 | case MAP_THUMB: | |
2571 | symname = "$t"; | |
2572 | type = BSF_NO_FLAGS; | |
2573 | break; | |
c19d1205 ZW |
2574 | default: |
2575 | abort (); | |
2576 | } | |
2577 | ||
cd000bff | 2578 | symbolP = symbol_new (symname, now_seg, value, frag); |
c19d1205 ZW |
2579 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; |
2580 | ||
2581 | switch (state) | |
2582 | { | |
2583 | case MAP_ARM: | |
2584 | THUMB_SET_FUNC (symbolP, 0); | |
2585 | ARM_SET_THUMB (symbolP, 0); | |
2586 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2587 | break; | |
2588 | ||
2589 | case MAP_THUMB: | |
2590 | THUMB_SET_FUNC (symbolP, 1); | |
2591 | ARM_SET_THUMB (symbolP, 1); | |
2592 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2593 | break; | |
2594 | ||
2595 | case MAP_DATA: | |
2596 | default: | |
cd000bff DJ |
2597 | break; |
2598 | } | |
2599 | ||
2600 | /* Save the mapping symbols for future reference. Also check that | |
2601 | we do not place two mapping symbols at the same offset within a | |
2602 | frag. We'll handle overlap between frags in | |
2de7820f JZ |
2603 | check_mapping_symbols. |
2604 | ||
2605 | If .fill or other data filling directive generates zero sized data, | |
2606 | the mapping symbol for the following code will have the same value | |
2607 | as the one generated for the data filling directive. In this case, | |
2608 | we replace the old symbol with the new one at the same address. */ | |
cd000bff DJ |
2609 | if (value == 0) |
2610 | { | |
2de7820f JZ |
2611 | if (frag->tc_frag_data.first_map != NULL) |
2612 | { | |
2613 | know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0); | |
2614 | symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP); | |
2615 | } | |
cd000bff DJ |
2616 | frag->tc_frag_data.first_map = symbolP; |
2617 | } | |
2618 | if (frag->tc_frag_data.last_map != NULL) | |
0f020cef JZ |
2619 | { |
2620 | know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP)); | |
0f020cef JZ |
2621 | if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP)) |
2622 | symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP); | |
2623 | } | |
cd000bff DJ |
2624 | frag->tc_frag_data.last_map = symbolP; |
2625 | } | |
2626 | ||
2627 | /* We must sometimes convert a region marked as code to data during | |
2628 | code alignment, if an odd number of bytes have to be padded. The | |
2629 | code mapping symbol is pushed to an aligned address. */ | |
2630 | ||
2631 | static void | |
2632 | insert_data_mapping_symbol (enum mstate state, | |
2633 | valueT value, fragS *frag, offsetT bytes) | |
2634 | { | |
2635 | /* If there was already a mapping symbol, remove it. */ | |
2636 | if (frag->tc_frag_data.last_map != NULL | |
2637 | && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value) | |
2638 | { | |
2639 | symbolS *symp = frag->tc_frag_data.last_map; | |
2640 | ||
2641 | if (value == 0) | |
2642 | { | |
2643 | know (frag->tc_frag_data.first_map == symp); | |
2644 | frag->tc_frag_data.first_map = NULL; | |
2645 | } | |
2646 | frag->tc_frag_data.last_map = NULL; | |
2647 | symbol_remove (symp, &symbol_rootP, &symbol_lastP); | |
c19d1205 | 2648 | } |
cd000bff DJ |
2649 | |
2650 | make_mapping_symbol (MAP_DATA, value, frag); | |
2651 | make_mapping_symbol (state, value + bytes, frag); | |
2652 | } | |
2653 | ||
2654 | static void mapping_state_2 (enum mstate state, int max_chars); | |
2655 | ||
2656 | /* Set the mapping state to STATE. Only call this when about to | |
2657 | emit some STATE bytes to the file. */ | |
2658 | ||
4e9aaefb | 2659 | #define TRANSITION(from, to) (mapstate == (from) && state == (to)) |
cd000bff DJ |
2660 | void |
2661 | mapping_state (enum mstate state) | |
2662 | { | |
940b5ce0 DJ |
2663 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2664 | ||
cd000bff DJ |
2665 | if (mapstate == state) |
2666 | /* The mapping symbol has already been emitted. | |
2667 | There is nothing else to do. */ | |
2668 | return; | |
49c62a33 NC |
2669 | |
2670 | if (state == MAP_ARM || state == MAP_THUMB) | |
2671 | /* PR gas/12931 | |
2672 | All ARM instructions require 4-byte alignment. | |
2673 | (Almost) all Thumb instructions require 2-byte alignment. | |
2674 | ||
2675 | When emitting instructions into any section, mark the section | |
2676 | appropriately. | |
2677 | ||
2678 | Some Thumb instructions are alignment-sensitive modulo 4 bytes, | |
2679 | but themselves require 2-byte alignment; this applies to some | |
2680 | PC- relative forms. However, these cases will invovle implicit | |
2681 | literal pool generation or an explicit .align >=2, both of | |
2682 | which will cause the section to me marked with sufficient | |
2683 | alignment. Thus, we don't handle those cases here. */ | |
2684 | record_alignment (now_seg, state == MAP_ARM ? 2 : 1); | |
2685 | ||
2686 | if (TRANSITION (MAP_UNDEFINED, MAP_DATA)) | |
4e9aaefb | 2687 | /* This case will be evaluated later. */ |
cd000bff | 2688 | return; |
cd000bff DJ |
2689 | |
2690 | mapping_state_2 (state, 0); | |
cd000bff DJ |
2691 | } |
2692 | ||
2693 | /* Same as mapping_state, but MAX_CHARS bytes have already been | |
2694 | allocated. Put the mapping symbol that far back. */ | |
2695 | ||
2696 | static void | |
2697 | mapping_state_2 (enum mstate state, int max_chars) | |
2698 | { | |
940b5ce0 DJ |
2699 | enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate; |
2700 | ||
2701 | if (!SEG_NORMAL (now_seg)) | |
2702 | return; | |
2703 | ||
cd000bff DJ |
2704 | if (mapstate == state) |
2705 | /* The mapping symbol has already been emitted. | |
2706 | There is nothing else to do. */ | |
2707 | return; | |
2708 | ||
4e9aaefb SA |
2709 | if (TRANSITION (MAP_UNDEFINED, MAP_ARM) |
2710 | || TRANSITION (MAP_UNDEFINED, MAP_THUMB)) | |
2711 | { | |
2712 | struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root; | |
2713 | const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0); | |
2714 | ||
2715 | if (add_symbol) | |
2716 | make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first); | |
2717 | } | |
2718 | ||
cd000bff DJ |
2719 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; |
2720 | make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now); | |
c19d1205 | 2721 | } |
4e9aaefb | 2722 | #undef TRANSITION |
c19d1205 | 2723 | #else |
d3106081 NS |
2724 | #define mapping_state(x) ((void)0) |
2725 | #define mapping_state_2(x, y) ((void)0) | |
c19d1205 ZW |
2726 | #endif |
2727 | ||
2728 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
2729 | ||
4343666d | 2730 | #ifdef OBJ_COFF |
c19d1205 ZW |
2731 | static symbolS * |
2732 | find_real_start (symbolS * symbolP) | |
2733 | { | |
2734 | char * real_start; | |
2735 | const char * name = S_GET_NAME (symbolP); | |
2736 | symbolS * new_target; | |
2737 | ||
2738 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
2739 | #define STUB_NAME ".real_start_of" | |
2740 | ||
2741 | if (name == NULL) | |
2742 | abort (); | |
2743 | ||
37f6032b ZW |
2744 | /* The compiler may generate BL instructions to local labels because |
2745 | it needs to perform a branch to a far away location. These labels | |
2746 | do not have a corresponding ".real_start_of" label. We check | |
2747 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
2748 | the ".real_start_of" convention for nonlocal branches. */ | |
2749 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
2750 | return symbolP; |
2751 | ||
37f6032b | 2752 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
2753 | new_target = symbol_find (real_start); |
2754 | ||
2755 | if (new_target == NULL) | |
2756 | { | |
bd3ba5d1 | 2757 | as_warn (_("Failed to find real start of function: %s\n"), name); |
c19d1205 ZW |
2758 | new_target = symbolP; |
2759 | } | |
2760 | ||
c19d1205 ZW |
2761 | return new_target; |
2762 | } | |
4343666d | 2763 | #endif |
c19d1205 ZW |
2764 | |
2765 | static void | |
2766 | opcode_select (int width) | |
2767 | { | |
2768 | switch (width) | |
2769 | { | |
2770 | case 16: | |
2771 | if (! thumb_mode) | |
2772 | { | |
e74cfd16 | 2773 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
2774 | as_bad (_("selected processor does not support THUMB opcodes")); |
2775 | ||
2776 | thumb_mode = 1; | |
2777 | /* No need to force the alignment, since we will have been | |
2778 | coming from ARM mode, which is word-aligned. */ | |
2779 | record_alignment (now_seg, 1); | |
2780 | } | |
c19d1205 ZW |
2781 | break; |
2782 | ||
2783 | case 32: | |
2784 | if (thumb_mode) | |
2785 | { | |
e74cfd16 | 2786 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
2787 | as_bad (_("selected processor does not support ARM opcodes")); |
2788 | ||
2789 | thumb_mode = 0; | |
2790 | ||
2791 | if (!need_pass_2) | |
2792 | frag_align (2, 0, 0); | |
2793 | ||
2794 | record_alignment (now_seg, 1); | |
2795 | } | |
c19d1205 ZW |
2796 | break; |
2797 | ||
2798 | default: | |
2799 | as_bad (_("invalid instruction size selected (%d)"), width); | |
2800 | } | |
2801 | } | |
2802 | ||
2803 | static void | |
2804 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
2805 | { | |
2806 | opcode_select (32); | |
2807 | demand_empty_rest_of_line (); | |
2808 | } | |
2809 | ||
2810 | static void | |
2811 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
2812 | { | |
2813 | opcode_select (16); | |
2814 | demand_empty_rest_of_line (); | |
2815 | } | |
2816 | ||
2817 | static void | |
2818 | s_code (int unused ATTRIBUTE_UNUSED) | |
2819 | { | |
2820 | int temp; | |
2821 | ||
2822 | temp = get_absolute_expression (); | |
2823 | switch (temp) | |
2824 | { | |
2825 | case 16: | |
2826 | case 32: | |
2827 | opcode_select (temp); | |
2828 | break; | |
2829 | ||
2830 | default: | |
2831 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
2832 | } | |
2833 | } | |
2834 | ||
2835 | static void | |
2836 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
2837 | { | |
2838 | /* If we are not already in thumb mode go into it, EVEN if | |
2839 | the target processor does not support thumb instructions. | |
2840 | This is used by gcc/config/arm/lib1funcs.asm for example | |
2841 | to compile interworking support functions even if the | |
2842 | target processor should not support interworking. */ | |
2843 | if (! thumb_mode) | |
2844 | { | |
2845 | thumb_mode = 2; | |
2846 | record_alignment (now_seg, 1); | |
2847 | } | |
2848 | ||
2849 | demand_empty_rest_of_line (); | |
2850 | } | |
2851 | ||
2852 | static void | |
2853 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
2854 | { | |
2855 | s_thumb (0); | |
2856 | ||
2857 | /* The following label is the name/address of the start of a Thumb function. | |
2858 | We need to know this for the interworking support. */ | |
2859 | label_is_thumb_function_name = TRUE; | |
2860 | } | |
2861 | ||
2862 | /* Perform a .set directive, but also mark the alias as | |
2863 | being a thumb function. */ | |
2864 | ||
2865 | static void | |
2866 | s_thumb_set (int equiv) | |
2867 | { | |
2868 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
2869 | We cannot just call that code as we need to get at the symbol that | |
2870 | is created. */ | |
2871 | char * name; | |
2872 | char delim; | |
2873 | char * end_name; | |
2874 | symbolS * symbolP; | |
2875 | ||
2876 | /* Especial apologies for the random logic: | |
2877 | This just grew, and could be parsed much more simply! | |
2878 | Dean - in haste. */ | |
d02603dc | 2879 | delim = get_symbol_name (& name); |
c19d1205 | 2880 | end_name = input_line_pointer; |
d02603dc | 2881 | (void) restore_line_pointer (delim); |
c19d1205 ZW |
2882 | |
2883 | if (*input_line_pointer != ',') | |
2884 | { | |
2885 | *end_name = 0; | |
2886 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
2887 | *end_name = delim; |
2888 | ignore_rest_of_line (); | |
2889 | return; | |
2890 | } | |
2891 | ||
2892 | input_line_pointer++; | |
2893 | *end_name = 0; | |
2894 | ||
2895 | if (name[0] == '.' && name[1] == '\0') | |
2896 | { | |
2897 | /* XXX - this should not happen to .thumb_set. */ | |
2898 | abort (); | |
2899 | } | |
2900 | ||
2901 | if ((symbolP = symbol_find (name)) == NULL | |
2902 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2903 | { | |
2904 | #ifndef NO_LISTING | |
2905 | /* When doing symbol listings, play games with dummy fragments living | |
2906 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 2907 | for this symbol. */ |
b99bd4ef NC |
2908 | if (listing & LISTING_SYMBOLS) |
2909 | { | |
2910 | extern struct list_info_struct * listing_tail; | |
21d799b5 | 2911 | fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS)); |
b99bd4ef NC |
2912 | |
2913 | memset (dummy_frag, 0, sizeof (fragS)); | |
2914 | dummy_frag->fr_type = rs_fill; | |
2915 | dummy_frag->line = listing_tail; | |
2916 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
2917 | dummy_frag->fr_symbol = symbolP; | |
2918 | } | |
2919 | else | |
2920 | #endif | |
2921 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
2922 | ||
2923 | #ifdef OBJ_COFF | |
2924 | /* "set" symbols are local unless otherwise specified. */ | |
2925 | SF_SET_LOCAL (symbolP); | |
2926 | #endif /* OBJ_COFF */ | |
2927 | } /* Make a new symbol. */ | |
2928 | ||
2929 | symbol_table_insert (symbolP); | |
2930 | ||
2931 | * end_name = delim; | |
2932 | ||
2933 | if (equiv | |
2934 | && S_IS_DEFINED (symbolP) | |
2935 | && S_GET_SEGMENT (symbolP) != reg_section) | |
2936 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
2937 | ||
2938 | pseudo_set (symbolP); | |
2939 | ||
2940 | demand_empty_rest_of_line (); | |
2941 | ||
c19d1205 | 2942 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
2943 | |
2944 | THUMB_SET_FUNC (symbolP, 1); | |
2945 | ARM_SET_THUMB (symbolP, 1); | |
2946 | #if defined OBJ_ELF || defined OBJ_COFF | |
2947 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
2948 | #endif | |
2949 | } | |
2950 | ||
c19d1205 | 2951 | /* Directives: Mode selection. */ |
b99bd4ef | 2952 | |
c19d1205 ZW |
2953 | /* .syntax [unified|divided] - choose the new unified syntax |
2954 | (same for Arm and Thumb encoding, modulo slight differences in what | |
2955 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 2956 | static void |
c19d1205 | 2957 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 2958 | { |
c19d1205 ZW |
2959 | char *name, delim; |
2960 | ||
d02603dc | 2961 | delim = get_symbol_name (& name); |
c19d1205 ZW |
2962 | |
2963 | if (!strcasecmp (name, "unified")) | |
2964 | unified_syntax = TRUE; | |
2965 | else if (!strcasecmp (name, "divided")) | |
2966 | unified_syntax = FALSE; | |
2967 | else | |
2968 | { | |
2969 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
2970 | return; | |
2971 | } | |
d02603dc | 2972 | (void) restore_line_pointer (delim); |
b99bd4ef NC |
2973 | demand_empty_rest_of_line (); |
2974 | } | |
2975 | ||
c19d1205 ZW |
2976 | /* Directives: sectioning and alignment. */ |
2977 | ||
c19d1205 ZW |
2978 | static void |
2979 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 2980 | { |
c19d1205 ZW |
2981 | /* We don't support putting frags in the BSS segment, we fake it by |
2982 | marking in_bss, then looking at s_skip for clues. */ | |
2983 | subseg_set (bss_section, 0); | |
2984 | demand_empty_rest_of_line (); | |
cd000bff DJ |
2985 | |
2986 | #ifdef md_elf_section_change_hook | |
2987 | md_elf_section_change_hook (); | |
2988 | #endif | |
c19d1205 | 2989 | } |
b99bd4ef | 2990 | |
c19d1205 ZW |
2991 | static void |
2992 | s_even (int ignore ATTRIBUTE_UNUSED) | |
2993 | { | |
2994 | /* Never make frag if expect extra pass. */ | |
2995 | if (!need_pass_2) | |
2996 | frag_align (1, 0, 0); | |
b99bd4ef | 2997 | |
c19d1205 | 2998 | record_alignment (now_seg, 1); |
b99bd4ef | 2999 | |
c19d1205 | 3000 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3001 | } |
3002 | ||
2e6976a8 DG |
3003 | /* Directives: CodeComposer Studio. */ |
3004 | ||
3005 | /* .ref (for CodeComposer Studio syntax only). */ | |
3006 | static void | |
3007 | s_ccs_ref (int unused ATTRIBUTE_UNUSED) | |
3008 | { | |
3009 | if (codecomposer_syntax) | |
3010 | ignore_rest_of_line (); | |
3011 | else | |
3012 | as_bad (_(".ref pseudo-op only available with -mccs flag.")); | |
3013 | } | |
3014 | ||
3015 | /* If name is not NULL, then it is used for marking the beginning of a | |
3016 | function, wherease if it is NULL then it means the function end. */ | |
3017 | static void | |
3018 | asmfunc_debug (const char * name) | |
3019 | { | |
3020 | static const char * last_name = NULL; | |
3021 | ||
3022 | if (name != NULL) | |
3023 | { | |
3024 | gas_assert (last_name == NULL); | |
3025 | last_name = name; | |
3026 | ||
3027 | if (debug_type == DEBUG_STABS) | |
3028 | stabs_generate_asm_func (name, name); | |
3029 | } | |
3030 | else | |
3031 | { | |
3032 | gas_assert (last_name != NULL); | |
3033 | ||
3034 | if (debug_type == DEBUG_STABS) | |
3035 | stabs_generate_asm_endfunc (last_name, last_name); | |
3036 | ||
3037 | last_name = NULL; | |
3038 | } | |
3039 | } | |
3040 | ||
3041 | static void | |
3042 | s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED) | |
3043 | { | |
3044 | if (codecomposer_syntax) | |
3045 | { | |
3046 | switch (asmfunc_state) | |
3047 | { | |
3048 | case OUTSIDE_ASMFUNC: | |
3049 | asmfunc_state = WAITING_ASMFUNC_NAME; | |
3050 | break; | |
3051 | ||
3052 | case WAITING_ASMFUNC_NAME: | |
3053 | as_bad (_(".asmfunc repeated.")); | |
3054 | break; | |
3055 | ||
3056 | case WAITING_ENDASMFUNC: | |
3057 | as_bad (_(".asmfunc without function.")); | |
3058 | break; | |
3059 | } | |
3060 | demand_empty_rest_of_line (); | |
3061 | } | |
3062 | else | |
3063 | as_bad (_(".asmfunc pseudo-op only available with -mccs flag.")); | |
3064 | } | |
3065 | ||
3066 | static void | |
3067 | s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED) | |
3068 | { | |
3069 | if (codecomposer_syntax) | |
3070 | { | |
3071 | switch (asmfunc_state) | |
3072 | { | |
3073 | case OUTSIDE_ASMFUNC: | |
3074 | as_bad (_(".endasmfunc without a .asmfunc.")); | |
3075 | break; | |
3076 | ||
3077 | case WAITING_ASMFUNC_NAME: | |
3078 | as_bad (_(".endasmfunc without function.")); | |
3079 | break; | |
3080 | ||
3081 | case WAITING_ENDASMFUNC: | |
3082 | asmfunc_state = OUTSIDE_ASMFUNC; | |
3083 | asmfunc_debug (NULL); | |
3084 | break; | |
3085 | } | |
3086 | demand_empty_rest_of_line (); | |
3087 | } | |
3088 | else | |
3089 | as_bad (_(".endasmfunc pseudo-op only available with -mccs flag.")); | |
3090 | } | |
3091 | ||
3092 | static void | |
3093 | s_ccs_def (int name) | |
3094 | { | |
3095 | if (codecomposer_syntax) | |
3096 | s_globl (name); | |
3097 | else | |
3098 | as_bad (_(".def pseudo-op only available with -mccs flag.")); | |
3099 | } | |
3100 | ||
c19d1205 | 3101 | /* Directives: Literal pools. */ |
a737bd4d | 3102 | |
c19d1205 ZW |
3103 | static literal_pool * |
3104 | find_literal_pool (void) | |
a737bd4d | 3105 | { |
c19d1205 | 3106 | literal_pool * pool; |
a737bd4d | 3107 | |
c19d1205 | 3108 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 3109 | { |
c19d1205 ZW |
3110 | if (pool->section == now_seg |
3111 | && pool->sub_section == now_subseg) | |
3112 | break; | |
a737bd4d NC |
3113 | } |
3114 | ||
c19d1205 | 3115 | return pool; |
a737bd4d NC |
3116 | } |
3117 | ||
c19d1205 ZW |
3118 | static literal_pool * |
3119 | find_or_make_literal_pool (void) | |
a737bd4d | 3120 | { |
c19d1205 ZW |
3121 | /* Next literal pool ID number. */ |
3122 | static unsigned int latest_pool_num = 1; | |
3123 | literal_pool * pool; | |
a737bd4d | 3124 | |
c19d1205 | 3125 | pool = find_literal_pool (); |
a737bd4d | 3126 | |
c19d1205 | 3127 | if (pool == NULL) |
a737bd4d | 3128 | { |
c19d1205 | 3129 | /* Create a new pool. */ |
21d799b5 | 3130 | pool = (literal_pool *) xmalloc (sizeof (* pool)); |
c19d1205 ZW |
3131 | if (! pool) |
3132 | return NULL; | |
a737bd4d | 3133 | |
c19d1205 ZW |
3134 | pool->next_free_entry = 0; |
3135 | pool->section = now_seg; | |
3136 | pool->sub_section = now_subseg; | |
3137 | pool->next = list_of_pools; | |
3138 | pool->symbol = NULL; | |
8335d6aa | 3139 | pool->alignment = 2; |
c19d1205 ZW |
3140 | |
3141 | /* Add it to the list. */ | |
3142 | list_of_pools = pool; | |
a737bd4d | 3143 | } |
a737bd4d | 3144 | |
c19d1205 ZW |
3145 | /* New pools, and emptied pools, will have a NULL symbol. */ |
3146 | if (pool->symbol == NULL) | |
a737bd4d | 3147 | { |
c19d1205 ZW |
3148 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
3149 | (valueT) 0, &zero_address_frag); | |
3150 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
3151 | } |
3152 | ||
c19d1205 ZW |
3153 | /* Done. */ |
3154 | return pool; | |
a737bd4d NC |
3155 | } |
3156 | ||
c19d1205 | 3157 | /* Add the literal in the global 'inst' |
5f4273c7 | 3158 | structure to the relevant literal pool. */ |
b99bd4ef NC |
3159 | |
3160 | static int | |
8335d6aa | 3161 | add_to_lit_pool (unsigned int nbytes) |
b99bd4ef | 3162 | { |
8335d6aa JW |
3163 | #define PADDING_SLOT 0x1 |
3164 | #define LIT_ENTRY_SIZE_MASK 0xFF | |
c19d1205 | 3165 | literal_pool * pool; |
8335d6aa JW |
3166 | unsigned int entry, pool_size = 0; |
3167 | bfd_boolean padding_slot_p = FALSE; | |
e56c722b | 3168 | unsigned imm1 = 0; |
8335d6aa JW |
3169 | unsigned imm2 = 0; |
3170 | ||
3171 | if (nbytes == 8) | |
3172 | { | |
3173 | imm1 = inst.operands[1].imm; | |
3174 | imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg | |
3175 | : inst.reloc.exp.X_unsigned ? 0 | |
2569ceb0 | 3176 | : ((bfd_int64_t) inst.operands[1].imm) >> 32); |
8335d6aa JW |
3177 | if (target_big_endian) |
3178 | { | |
3179 | imm1 = imm2; | |
3180 | imm2 = inst.operands[1].imm; | |
3181 | } | |
3182 | } | |
b99bd4ef | 3183 | |
c19d1205 ZW |
3184 | pool = find_or_make_literal_pool (); |
3185 | ||
3186 | /* Check if this literal value is already in the pool. */ | |
3187 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 3188 | { |
8335d6aa JW |
3189 | if (nbytes == 4) |
3190 | { | |
3191 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
3192 | && (inst.reloc.exp.X_op == O_constant) | |
3193 | && (pool->literals[entry].X_add_number | |
3194 | == inst.reloc.exp.X_add_number) | |
3195 | && (pool->literals[entry].X_md == nbytes) | |
3196 | && (pool->literals[entry].X_unsigned | |
3197 | == inst.reloc.exp.X_unsigned)) | |
3198 | break; | |
3199 | ||
3200 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
3201 | && (inst.reloc.exp.X_op == O_symbol) | |
3202 | && (pool->literals[entry].X_add_number | |
3203 | == inst.reloc.exp.X_add_number) | |
3204 | && (pool->literals[entry].X_add_symbol | |
3205 | == inst.reloc.exp.X_add_symbol) | |
3206 | && (pool->literals[entry].X_op_symbol | |
3207 | == inst.reloc.exp.X_op_symbol) | |
3208 | && (pool->literals[entry].X_md == nbytes)) | |
3209 | break; | |
3210 | } | |
3211 | else if ((nbytes == 8) | |
3212 | && !(pool_size & 0x7) | |
3213 | && ((entry + 1) != pool->next_free_entry) | |
3214 | && (pool->literals[entry].X_op == O_constant) | |
19f2f6a9 | 3215 | && (pool->literals[entry].X_add_number == (offsetT) imm1) |
8335d6aa JW |
3216 | && (pool->literals[entry].X_unsigned |
3217 | == inst.reloc.exp.X_unsigned) | |
3218 | && (pool->literals[entry + 1].X_op == O_constant) | |
19f2f6a9 | 3219 | && (pool->literals[entry + 1].X_add_number == (offsetT) imm2) |
8335d6aa JW |
3220 | && (pool->literals[entry + 1].X_unsigned |
3221 | == inst.reloc.exp.X_unsigned)) | |
c19d1205 ZW |
3222 | break; |
3223 | ||
8335d6aa JW |
3224 | padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT); |
3225 | if (padding_slot_p && (nbytes == 4)) | |
c19d1205 | 3226 | break; |
8335d6aa JW |
3227 | |
3228 | pool_size += 4; | |
b99bd4ef NC |
3229 | } |
3230 | ||
c19d1205 ZW |
3231 | /* Do we need to create a new entry? */ |
3232 | if (entry == pool->next_free_entry) | |
3233 | { | |
3234 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
3235 | { | |
3236 | inst.error = _("literal pool overflow"); | |
3237 | return FAIL; | |
3238 | } | |
3239 | ||
8335d6aa JW |
3240 | if (nbytes == 8) |
3241 | { | |
3242 | /* For 8-byte entries, we align to an 8-byte boundary, | |
3243 | and split it into two 4-byte entries, because on 32-bit | |
3244 | host, 8-byte constants are treated as big num, thus | |
3245 | saved in "generic_bignum" which will be overwritten | |
3246 | by later assignments. | |
3247 | ||
3248 | We also need to make sure there is enough space for | |
3249 | the split. | |
3250 | ||
3251 | We also check to make sure the literal operand is a | |
3252 | constant number. */ | |
19f2f6a9 JW |
3253 | if (!(inst.reloc.exp.X_op == O_constant |
3254 | || inst.reloc.exp.X_op == O_big)) | |
8335d6aa JW |
3255 | { |
3256 | inst.error = _("invalid type for literal pool"); | |
3257 | return FAIL; | |
3258 | } | |
3259 | else if (pool_size & 0x7) | |
3260 | { | |
3261 | if ((entry + 2) >= MAX_LITERAL_POOL_SIZE) | |
3262 | { | |
3263 | inst.error = _("literal pool overflow"); | |
3264 | return FAIL; | |
3265 | } | |
3266 | ||
3267 | pool->literals[entry] = inst.reloc.exp; | |
3268 | pool->literals[entry].X_add_number = 0; | |
3269 | pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4; | |
3270 | pool->next_free_entry += 1; | |
3271 | pool_size += 4; | |
3272 | } | |
3273 | else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE) | |
3274 | { | |
3275 | inst.error = _("literal pool overflow"); | |
3276 | return FAIL; | |
3277 | } | |
3278 | ||
3279 | pool->literals[entry] = inst.reloc.exp; | |
3280 | pool->literals[entry].X_op = O_constant; | |
3281 | pool->literals[entry].X_add_number = imm1; | |
3282 | pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned; | |
3283 | pool->literals[entry++].X_md = 4; | |
3284 | pool->literals[entry] = inst.reloc.exp; | |
3285 | pool->literals[entry].X_op = O_constant; | |
3286 | pool->literals[entry].X_add_number = imm2; | |
3287 | pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned; | |
3288 | pool->literals[entry].X_md = 4; | |
3289 | pool->alignment = 3; | |
3290 | pool->next_free_entry += 1; | |
3291 | } | |
3292 | else | |
3293 | { | |
3294 | pool->literals[entry] = inst.reloc.exp; | |
3295 | pool->literals[entry].X_md = 4; | |
3296 | } | |
3297 | ||
a8040cf2 NC |
3298 | #ifdef OBJ_ELF |
3299 | /* PR ld/12974: Record the location of the first source line to reference | |
3300 | this entry in the literal pool. If it turns out during linking that the | |
3301 | symbol does not exist we will be able to give an accurate line number for | |
3302 | the (first use of the) missing reference. */ | |
3303 | if (debug_type == DEBUG_DWARF2) | |
3304 | dwarf2_where (pool->locs + entry); | |
3305 | #endif | |
c19d1205 ZW |
3306 | pool->next_free_entry += 1; |
3307 | } | |
8335d6aa JW |
3308 | else if (padding_slot_p) |
3309 | { | |
3310 | pool->literals[entry] = inst.reloc.exp; | |
3311 | pool->literals[entry].X_md = nbytes; | |
3312 | } | |
b99bd4ef | 3313 | |
c19d1205 | 3314 | inst.reloc.exp.X_op = O_symbol; |
8335d6aa | 3315 | inst.reloc.exp.X_add_number = pool_size; |
c19d1205 | 3316 | inst.reloc.exp.X_add_symbol = pool->symbol; |
b99bd4ef | 3317 | |
c19d1205 | 3318 | return SUCCESS; |
b99bd4ef NC |
3319 | } |
3320 | ||
2e6976a8 | 3321 | bfd_boolean |
2e57ce7b | 3322 | tc_start_label_without_colon (void) |
2e6976a8 DG |
3323 | { |
3324 | bfd_boolean ret = TRUE; | |
3325 | ||
3326 | if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME) | |
3327 | { | |
2e57ce7b | 3328 | const char *label = input_line_pointer; |
2e6976a8 DG |
3329 | |
3330 | while (!is_end_of_line[(int) label[-1]]) | |
3331 | --label; | |
3332 | ||
3333 | if (*label == '.') | |
3334 | { | |
3335 | as_bad (_("Invalid label '%s'"), label); | |
3336 | ret = FALSE; | |
3337 | } | |
3338 | ||
3339 | asmfunc_debug (label); | |
3340 | ||
3341 | asmfunc_state = WAITING_ENDASMFUNC; | |
3342 | } | |
3343 | ||
3344 | return ret; | |
3345 | } | |
3346 | ||
c19d1205 ZW |
3347 | /* Can't use symbol_new here, so have to create a symbol and then at |
3348 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 3349 | |
c19d1205 ZW |
3350 | static void |
3351 | symbol_locate (symbolS * symbolP, | |
3352 | const char * name, /* It is copied, the caller can modify. */ | |
3353 | segT segment, /* Segment identifier (SEG_<something>). */ | |
3354 | valueT valu, /* Symbol value. */ | |
3355 | fragS * frag) /* Associated fragment. */ | |
3356 | { | |
e57e6ddc | 3357 | size_t name_length; |
c19d1205 | 3358 | char * preserved_copy_of_name; |
e16bb312 | 3359 | |
c19d1205 ZW |
3360 | name_length = strlen (name) + 1; /* +1 for \0. */ |
3361 | obstack_grow (¬es, name, name_length); | |
21d799b5 | 3362 | preserved_copy_of_name = (char *) obstack_finish (¬es); |
e16bb312 | 3363 | |
c19d1205 ZW |
3364 | #ifdef tc_canonicalize_symbol_name |
3365 | preserved_copy_of_name = | |
3366 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
3367 | #endif | |
b99bd4ef | 3368 | |
c19d1205 | 3369 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 3370 | |
c19d1205 ZW |
3371 | S_SET_SEGMENT (symbolP, segment); |
3372 | S_SET_VALUE (symbolP, valu); | |
3373 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 3374 | |
c19d1205 | 3375 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 3376 | |
c19d1205 ZW |
3377 | /* Link to end of symbol chain. */ |
3378 | { | |
3379 | extern int symbol_table_frozen; | |
b99bd4ef | 3380 | |
c19d1205 ZW |
3381 | if (symbol_table_frozen) |
3382 | abort (); | |
3383 | } | |
b99bd4ef | 3384 | |
c19d1205 | 3385 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 3386 | |
c19d1205 | 3387 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 3388 | |
c19d1205 ZW |
3389 | #ifdef tc_symbol_new_hook |
3390 | tc_symbol_new_hook (symbolP); | |
3391 | #endif | |
3392 | ||
3393 | #ifdef DEBUG_SYMS | |
3394 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
3395 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
3396 | } |
3397 | ||
c19d1205 ZW |
3398 | static void |
3399 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 3400 | { |
c19d1205 ZW |
3401 | unsigned int entry; |
3402 | literal_pool * pool; | |
3403 | char sym_name[20]; | |
b99bd4ef | 3404 | |
c19d1205 ZW |
3405 | pool = find_literal_pool (); |
3406 | if (pool == NULL | |
3407 | || pool->symbol == NULL | |
3408 | || pool->next_free_entry == 0) | |
3409 | return; | |
b99bd4ef | 3410 | |
c19d1205 ZW |
3411 | /* Align pool as you have word accesses. |
3412 | Only make a frag if we have to. */ | |
3413 | if (!need_pass_2) | |
8335d6aa | 3414 | frag_align (pool->alignment, 0, 0); |
b99bd4ef | 3415 | |
c19d1205 | 3416 | record_alignment (now_seg, 2); |
b99bd4ef | 3417 | |
aaca88ef | 3418 | #ifdef OBJ_ELF |
47fc6e36 WN |
3419 | seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA; |
3420 | make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now); | |
aaca88ef | 3421 | #endif |
c19d1205 | 3422 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 3423 | |
c19d1205 ZW |
3424 | symbol_locate (pool->symbol, sym_name, now_seg, |
3425 | (valueT) frag_now_fix (), frag_now); | |
3426 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 3427 | |
c19d1205 | 3428 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 3429 | |
c19d1205 ZW |
3430 | #if defined OBJ_COFF || defined OBJ_ELF |
3431 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
3432 | #endif | |
6c43fab6 | 3433 | |
c19d1205 | 3434 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
a8040cf2 NC |
3435 | { |
3436 | #ifdef OBJ_ELF | |
3437 | if (debug_type == DEBUG_DWARF2) | |
3438 | dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry); | |
3439 | #endif | |
3440 | /* First output the expression in the instruction to the pool. */ | |
8335d6aa JW |
3441 | emit_expr (&(pool->literals[entry]), |
3442 | pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK); | |
a8040cf2 | 3443 | } |
b99bd4ef | 3444 | |
c19d1205 ZW |
3445 | /* Mark the pool as empty. */ |
3446 | pool->next_free_entry = 0; | |
3447 | pool->symbol = NULL; | |
b99bd4ef NC |
3448 | } |
3449 | ||
c19d1205 ZW |
3450 | #ifdef OBJ_ELF |
3451 | /* Forward declarations for functions below, in the MD interface | |
3452 | section. */ | |
3453 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
3454 | static valueT create_unwind_entry (int); | |
3455 | static void start_unwind_section (const segT, int); | |
3456 | static void add_unwind_opcode (valueT, int); | |
3457 | static void flush_pending_unwind (void); | |
b99bd4ef | 3458 | |
c19d1205 | 3459 | /* Directives: Data. */ |
b99bd4ef | 3460 | |
c19d1205 ZW |
3461 | static void |
3462 | s_arm_elf_cons (int nbytes) | |
3463 | { | |
3464 | expressionS exp; | |
b99bd4ef | 3465 | |
c19d1205 ZW |
3466 | #ifdef md_flush_pending_output |
3467 | md_flush_pending_output (); | |
3468 | #endif | |
b99bd4ef | 3469 | |
c19d1205 | 3470 | if (is_it_end_of_statement ()) |
b99bd4ef | 3471 | { |
c19d1205 ZW |
3472 | demand_empty_rest_of_line (); |
3473 | return; | |
b99bd4ef NC |
3474 | } |
3475 | ||
c19d1205 ZW |
3476 | #ifdef md_cons_align |
3477 | md_cons_align (nbytes); | |
3478 | #endif | |
b99bd4ef | 3479 | |
c19d1205 ZW |
3480 | mapping_state (MAP_DATA); |
3481 | do | |
b99bd4ef | 3482 | { |
c19d1205 ZW |
3483 | int reloc; |
3484 | char *base = input_line_pointer; | |
b99bd4ef | 3485 | |
c19d1205 | 3486 | expression (& exp); |
b99bd4ef | 3487 | |
c19d1205 ZW |
3488 | if (exp.X_op != O_symbol) |
3489 | emit_expr (&exp, (unsigned int) nbytes); | |
3490 | else | |
3491 | { | |
3492 | char *before_reloc = input_line_pointer; | |
3493 | reloc = parse_reloc (&input_line_pointer); | |
3494 | if (reloc == -1) | |
3495 | { | |
3496 | as_bad (_("unrecognized relocation suffix")); | |
3497 | ignore_rest_of_line (); | |
3498 | return; | |
3499 | } | |
3500 | else if (reloc == BFD_RELOC_UNUSED) | |
3501 | emit_expr (&exp, (unsigned int) nbytes); | |
3502 | else | |
3503 | { | |
21d799b5 | 3504 | reloc_howto_type *howto = (reloc_howto_type *) |
477330fc RM |
3505 | bfd_reloc_type_lookup (stdoutput, |
3506 | (bfd_reloc_code_real_type) reloc); | |
c19d1205 | 3507 | int size = bfd_get_reloc_size (howto); |
b99bd4ef | 3508 | |
2fc8bdac ZW |
3509 | if (reloc == BFD_RELOC_ARM_PLT32) |
3510 | { | |
3511 | as_bad (_("(plt) is only valid on branch targets")); | |
3512 | reloc = BFD_RELOC_UNUSED; | |
3513 | size = 0; | |
3514 | } | |
3515 | ||
c19d1205 | 3516 | if (size > nbytes) |
2fc8bdac | 3517 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
3518 | howto->name, nbytes); |
3519 | else | |
3520 | { | |
3521 | /* We've parsed an expression stopping at O_symbol. | |
3522 | But there may be more expression left now that we | |
3523 | have parsed the relocation marker. Parse it again. | |
3524 | XXX Surely there is a cleaner way to do this. */ | |
3525 | char *p = input_line_pointer; | |
3526 | int offset; | |
21d799b5 | 3527 | char *save_buf = (char *) alloca (input_line_pointer - base); |
c19d1205 ZW |
3528 | memcpy (save_buf, base, input_line_pointer - base); |
3529 | memmove (base + (input_line_pointer - before_reloc), | |
3530 | base, before_reloc - base); | |
3531 | ||
3532 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
3533 | expression (&exp); | |
3534 | memcpy (base, save_buf, p - base); | |
3535 | ||
3536 | offset = nbytes - size; | |
4b1a927e AM |
3537 | p = frag_more (nbytes); |
3538 | memset (p, 0, nbytes); | |
c19d1205 | 3539 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, |
21d799b5 | 3540 | size, &exp, 0, (enum bfd_reloc_code_real) reloc); |
c19d1205 ZW |
3541 | } |
3542 | } | |
3543 | } | |
b99bd4ef | 3544 | } |
c19d1205 | 3545 | while (*input_line_pointer++ == ','); |
b99bd4ef | 3546 | |
c19d1205 ZW |
3547 | /* Put terminator back into stream. */ |
3548 | input_line_pointer --; | |
3549 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
3550 | } |
3551 | ||
c921be7d NC |
3552 | /* Emit an expression containing a 32-bit thumb instruction. |
3553 | Implementation based on put_thumb32_insn. */ | |
3554 | ||
3555 | static void | |
3556 | emit_thumb32_expr (expressionS * exp) | |
3557 | { | |
3558 | expressionS exp_high = *exp; | |
3559 | ||
3560 | exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16; | |
3561 | emit_expr (& exp_high, (unsigned int) THUMB_SIZE); | |
3562 | exp->X_add_number &= 0xffff; | |
3563 | emit_expr (exp, (unsigned int) THUMB_SIZE); | |
3564 | } | |
3565 | ||
3566 | /* Guess the instruction size based on the opcode. */ | |
3567 | ||
3568 | static int | |
3569 | thumb_insn_size (int opcode) | |
3570 | { | |
3571 | if ((unsigned int) opcode < 0xe800u) | |
3572 | return 2; | |
3573 | else if ((unsigned int) opcode >= 0xe8000000u) | |
3574 | return 4; | |
3575 | else | |
3576 | return 0; | |
3577 | } | |
3578 | ||
3579 | static bfd_boolean | |
3580 | emit_insn (expressionS *exp, int nbytes) | |
3581 | { | |
3582 | int size = 0; | |
3583 | ||
3584 | if (exp->X_op == O_constant) | |
3585 | { | |
3586 | size = nbytes; | |
3587 | ||
3588 | if (size == 0) | |
3589 | size = thumb_insn_size (exp->X_add_number); | |
3590 | ||
3591 | if (size != 0) | |
3592 | { | |
3593 | if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu) | |
3594 | { | |
3595 | as_bad (_(".inst.n operand too big. "\ | |
3596 | "Use .inst.w instead")); | |
3597 | size = 0; | |
3598 | } | |
3599 | else | |
3600 | { | |
3601 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
3602 | set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0); | |
3603 | else | |
3604 | set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0); | |
3605 | ||
3606 | if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian) | |
3607 | emit_thumb32_expr (exp); | |
3608 | else | |
3609 | emit_expr (exp, (unsigned int) size); | |
3610 | ||
3611 | it_fsm_post_encode (); | |
3612 | } | |
3613 | } | |
3614 | else | |
3615 | as_bad (_("cannot determine Thumb instruction size. " \ | |
3616 | "Use .inst.n/.inst.w instead")); | |
3617 | } | |
3618 | else | |
3619 | as_bad (_("constant expression required")); | |
3620 | ||
3621 | return (size != 0); | |
3622 | } | |
3623 | ||
3624 | /* Like s_arm_elf_cons but do not use md_cons_align and | |
3625 | set the mapping state to MAP_ARM/MAP_THUMB. */ | |
3626 | ||
3627 | static void | |
3628 | s_arm_elf_inst (int nbytes) | |
3629 | { | |
3630 | if (is_it_end_of_statement ()) | |
3631 | { | |
3632 | demand_empty_rest_of_line (); | |
3633 | return; | |
3634 | } | |
3635 | ||
3636 | /* Calling mapping_state () here will not change ARM/THUMB, | |
3637 | but will ensure not to be in DATA state. */ | |
3638 | ||
3639 | if (thumb_mode) | |
3640 | mapping_state (MAP_THUMB); | |
3641 | else | |
3642 | { | |
3643 | if (nbytes != 0) | |
3644 | { | |
3645 | as_bad (_("width suffixes are invalid in ARM mode")); | |
3646 | ignore_rest_of_line (); | |
3647 | return; | |
3648 | } | |
3649 | ||
3650 | nbytes = 4; | |
3651 | ||
3652 | mapping_state (MAP_ARM); | |
3653 | } | |
3654 | ||
3655 | do | |
3656 | { | |
3657 | expressionS exp; | |
3658 | ||
3659 | expression (& exp); | |
3660 | ||
3661 | if (! emit_insn (& exp, nbytes)) | |
3662 | { | |
3663 | ignore_rest_of_line (); | |
3664 | return; | |
3665 | } | |
3666 | } | |
3667 | while (*input_line_pointer++ == ','); | |
3668 | ||
3669 | /* Put terminator back into stream. */ | |
3670 | input_line_pointer --; | |
3671 | demand_empty_rest_of_line (); | |
3672 | } | |
b99bd4ef | 3673 | |
c19d1205 | 3674 | /* Parse a .rel31 directive. */ |
b99bd4ef | 3675 | |
c19d1205 ZW |
3676 | static void |
3677 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
3678 | { | |
3679 | expressionS exp; | |
3680 | char *p; | |
3681 | valueT highbit; | |
b99bd4ef | 3682 | |
c19d1205 ZW |
3683 | highbit = 0; |
3684 | if (*input_line_pointer == '1') | |
3685 | highbit = 0x80000000; | |
3686 | else if (*input_line_pointer != '0') | |
3687 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 3688 | |
c19d1205 ZW |
3689 | input_line_pointer++; |
3690 | if (*input_line_pointer != ',') | |
3691 | as_bad (_("missing comma")); | |
3692 | input_line_pointer++; | |
b99bd4ef | 3693 | |
c19d1205 ZW |
3694 | #ifdef md_flush_pending_output |
3695 | md_flush_pending_output (); | |
3696 | #endif | |
b99bd4ef | 3697 | |
c19d1205 ZW |
3698 | #ifdef md_cons_align |
3699 | md_cons_align (4); | |
3700 | #endif | |
b99bd4ef | 3701 | |
c19d1205 | 3702 | mapping_state (MAP_DATA); |
b99bd4ef | 3703 | |
c19d1205 | 3704 | expression (&exp); |
b99bd4ef | 3705 | |
c19d1205 ZW |
3706 | p = frag_more (4); |
3707 | md_number_to_chars (p, highbit, 4); | |
3708 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
3709 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 3710 | |
c19d1205 | 3711 | demand_empty_rest_of_line (); |
b99bd4ef NC |
3712 | } |
3713 | ||
c19d1205 | 3714 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 3715 | |
c19d1205 | 3716 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 3717 | |
c19d1205 ZW |
3718 | static void |
3719 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
3720 | { | |
3721 | demand_empty_rest_of_line (); | |
921e5f0a PB |
3722 | if (unwind.proc_start) |
3723 | { | |
c921be7d | 3724 | as_bad (_("duplicate .fnstart directive")); |
921e5f0a PB |
3725 | return; |
3726 | } | |
3727 | ||
c19d1205 ZW |
3728 | /* Mark the start of the function. */ |
3729 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 3730 | |
c19d1205 ZW |
3731 | /* Reset the rest of the unwind info. */ |
3732 | unwind.opcode_count = 0; | |
3733 | unwind.table_entry = NULL; | |
3734 | unwind.personality_routine = NULL; | |
3735 | unwind.personality_index = -1; | |
3736 | unwind.frame_size = 0; | |
3737 | unwind.fp_offset = 0; | |
fdfde340 | 3738 | unwind.fp_reg = REG_SP; |
c19d1205 ZW |
3739 | unwind.fp_used = 0; |
3740 | unwind.sp_restored = 0; | |
3741 | } | |
b99bd4ef | 3742 | |
b99bd4ef | 3743 | |
c19d1205 ZW |
3744 | /* Parse a handlerdata directive. Creates the exception handling table entry |
3745 | for the function. */ | |
b99bd4ef | 3746 | |
c19d1205 ZW |
3747 | static void |
3748 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
3749 | { | |
3750 | demand_empty_rest_of_line (); | |
921e5f0a | 3751 | if (!unwind.proc_start) |
c921be7d | 3752 | as_bad (MISSING_FNSTART); |
921e5f0a | 3753 | |
c19d1205 | 3754 | if (unwind.table_entry) |
6decc662 | 3755 | as_bad (_("duplicate .handlerdata directive")); |
f02232aa | 3756 | |
c19d1205 ZW |
3757 | create_unwind_entry (1); |
3758 | } | |
a737bd4d | 3759 | |
c19d1205 | 3760 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 3761 | |
c19d1205 ZW |
3762 | static void |
3763 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
3764 | { | |
3765 | long where; | |
3766 | char *ptr; | |
3767 | valueT val; | |
940b5ce0 | 3768 | unsigned int marked_pr_dependency; |
f02232aa | 3769 | |
c19d1205 | 3770 | demand_empty_rest_of_line (); |
f02232aa | 3771 | |
921e5f0a PB |
3772 | if (!unwind.proc_start) |
3773 | { | |
c921be7d | 3774 | as_bad (_(".fnend directive without .fnstart")); |
921e5f0a PB |
3775 | return; |
3776 | } | |
3777 | ||
c19d1205 ZW |
3778 | /* Add eh table entry. */ |
3779 | if (unwind.table_entry == NULL) | |
3780 | val = create_unwind_entry (0); | |
3781 | else | |
3782 | val = 0; | |
f02232aa | 3783 | |
c19d1205 ZW |
3784 | /* Add index table entry. This is two words. */ |
3785 | start_unwind_section (unwind.saved_seg, 1); | |
3786 | frag_align (2, 0, 0); | |
3787 | record_alignment (now_seg, 2); | |
b99bd4ef | 3788 | |
c19d1205 | 3789 | ptr = frag_more (8); |
5011093d | 3790 | memset (ptr, 0, 8); |
c19d1205 | 3791 | where = frag_now_fix () - 8; |
f02232aa | 3792 | |
c19d1205 ZW |
3793 | /* Self relative offset of the function start. */ |
3794 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
3795 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3796 | |
c19d1205 ZW |
3797 | /* Indicate dependency on EHABI-defined personality routines to the |
3798 | linker, if it hasn't been done already. */ | |
940b5ce0 DJ |
3799 | marked_pr_dependency |
3800 | = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency; | |
c19d1205 ZW |
3801 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 |
3802 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
3803 | { | |
5f4273c7 NC |
3804 | static const char *const name[] = |
3805 | { | |
3806 | "__aeabi_unwind_cpp_pr0", | |
3807 | "__aeabi_unwind_cpp_pr1", | |
3808 | "__aeabi_unwind_cpp_pr2" | |
3809 | }; | |
c19d1205 ZW |
3810 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); |
3811 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
c19d1205 | 3812 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency |
940b5ce0 | 3813 | |= 1 << unwind.personality_index; |
c19d1205 | 3814 | } |
f02232aa | 3815 | |
c19d1205 ZW |
3816 | if (val) |
3817 | /* Inline exception table entry. */ | |
3818 | md_number_to_chars (ptr + 4, val, 4); | |
3819 | else | |
3820 | /* Self relative offset of the table entry. */ | |
3821 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
3822 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 3823 | |
c19d1205 ZW |
3824 | /* Restore the original section. */ |
3825 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
921e5f0a PB |
3826 | |
3827 | unwind.proc_start = NULL; | |
c19d1205 | 3828 | } |
f02232aa | 3829 | |
f02232aa | 3830 | |
c19d1205 | 3831 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 3832 | |
c19d1205 ZW |
3833 | static void |
3834 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
3835 | { | |
3836 | demand_empty_rest_of_line (); | |
921e5f0a | 3837 | if (!unwind.proc_start) |
c921be7d | 3838 | as_bad (MISSING_FNSTART); |
921e5f0a | 3839 | |
c19d1205 ZW |
3840 | if (unwind.personality_routine || unwind.personality_index != -1) |
3841 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 3842 | |
c19d1205 ZW |
3843 | unwind.personality_index = -2; |
3844 | } | |
b99bd4ef | 3845 | |
b99bd4ef | 3846 | |
c19d1205 | 3847 | /* Parse a personalityindex directive. */ |
b99bd4ef | 3848 | |
c19d1205 ZW |
3849 | static void |
3850 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
3851 | { | |
3852 | expressionS exp; | |
b99bd4ef | 3853 | |
921e5f0a | 3854 | if (!unwind.proc_start) |
c921be7d | 3855 | as_bad (MISSING_FNSTART); |
921e5f0a | 3856 | |
c19d1205 ZW |
3857 | if (unwind.personality_routine || unwind.personality_index != -1) |
3858 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 3859 | |
c19d1205 | 3860 | expression (&exp); |
b99bd4ef | 3861 | |
c19d1205 ZW |
3862 | if (exp.X_op != O_constant |
3863 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 3864 | { |
c19d1205 ZW |
3865 | as_bad (_("bad personality routine number")); |
3866 | ignore_rest_of_line (); | |
3867 | return; | |
b99bd4ef NC |
3868 | } |
3869 | ||
c19d1205 | 3870 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 3871 | |
c19d1205 ZW |
3872 | demand_empty_rest_of_line (); |
3873 | } | |
e16bb312 | 3874 | |
e16bb312 | 3875 | |
c19d1205 | 3876 | /* Parse a personality directive. */ |
e16bb312 | 3877 | |
c19d1205 ZW |
3878 | static void |
3879 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
3880 | { | |
3881 | char *name, *p, c; | |
a737bd4d | 3882 | |
921e5f0a | 3883 | if (!unwind.proc_start) |
c921be7d | 3884 | as_bad (MISSING_FNSTART); |
921e5f0a | 3885 | |
c19d1205 ZW |
3886 | if (unwind.personality_routine || unwind.personality_index != -1) |
3887 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 3888 | |
d02603dc | 3889 | c = get_symbol_name (& name); |
c19d1205 | 3890 | p = input_line_pointer; |
d02603dc NC |
3891 | if (c == '"') |
3892 | ++ input_line_pointer; | |
c19d1205 ZW |
3893 | unwind.personality_routine = symbol_find_or_make (name); |
3894 | *p = c; | |
3895 | demand_empty_rest_of_line (); | |
3896 | } | |
e16bb312 | 3897 | |
e16bb312 | 3898 | |
c19d1205 | 3899 | /* Parse a directive saving core registers. */ |
e16bb312 | 3900 | |
c19d1205 ZW |
3901 | static void |
3902 | s_arm_unwind_save_core (void) | |
e16bb312 | 3903 | { |
c19d1205 ZW |
3904 | valueT op; |
3905 | long range; | |
3906 | int n; | |
e16bb312 | 3907 | |
c19d1205 ZW |
3908 | range = parse_reg_list (&input_line_pointer); |
3909 | if (range == FAIL) | |
e16bb312 | 3910 | { |
c19d1205 ZW |
3911 | as_bad (_("expected register list")); |
3912 | ignore_rest_of_line (); | |
3913 | return; | |
3914 | } | |
e16bb312 | 3915 | |
c19d1205 | 3916 | demand_empty_rest_of_line (); |
e16bb312 | 3917 | |
c19d1205 ZW |
3918 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
3919 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
3920 | ip because it is clobbered by calls. */ | |
3921 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
3922 | && (range & 0x3000) == 0x1000) | |
3923 | { | |
3924 | unwind.opcode_count--; | |
3925 | unwind.sp_restored = 0; | |
3926 | range = (range | 0x2000) & ~0x1000; | |
3927 | unwind.pending_offset = 0; | |
3928 | } | |
e16bb312 | 3929 | |
01ae4198 DJ |
3930 | /* Pop r4-r15. */ |
3931 | if (range & 0xfff0) | |
c19d1205 | 3932 | { |
01ae4198 DJ |
3933 | /* See if we can use the short opcodes. These pop a block of up to 8 |
3934 | registers starting with r4, plus maybe r14. */ | |
3935 | for (n = 0; n < 8; n++) | |
3936 | { | |
3937 | /* Break at the first non-saved register. */ | |
3938 | if ((range & (1 << (n + 4))) == 0) | |
3939 | break; | |
3940 | } | |
3941 | /* See if there are any other bits set. */ | |
3942 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
3943 | { | |
3944 | /* Use the long form. */ | |
3945 | op = 0x8000 | ((range >> 4) & 0xfff); | |
3946 | add_unwind_opcode (op, 2); | |
3947 | } | |
0dd132b6 | 3948 | else |
01ae4198 DJ |
3949 | { |
3950 | /* Use the short form. */ | |
3951 | if (range & 0x4000) | |
3952 | op = 0xa8; /* Pop r14. */ | |
3953 | else | |
3954 | op = 0xa0; /* Do not pop r14. */ | |
3955 | op |= (n - 1); | |
3956 | add_unwind_opcode (op, 1); | |
3957 | } | |
c19d1205 | 3958 | } |
0dd132b6 | 3959 | |
c19d1205 ZW |
3960 | /* Pop r0-r3. */ |
3961 | if (range & 0xf) | |
3962 | { | |
3963 | op = 0xb100 | (range & 0xf); | |
3964 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
3965 | } |
3966 | ||
c19d1205 ZW |
3967 | /* Record the number of bytes pushed. */ |
3968 | for (n = 0; n < 16; n++) | |
3969 | { | |
3970 | if (range & (1 << n)) | |
3971 | unwind.frame_size += 4; | |
3972 | } | |
0dd132b6 NC |
3973 | } |
3974 | ||
c19d1205 ZW |
3975 | |
3976 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
3977 | |
3978 | static void | |
c19d1205 | 3979 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 3980 | { |
c19d1205 ZW |
3981 | expressionS exp; |
3982 | int num_regs; | |
3983 | valueT op; | |
b99bd4ef | 3984 | |
c19d1205 ZW |
3985 | /* Get Number of registers to transfer. */ |
3986 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
3987 | expression (&exp); | |
3988 | else | |
3989 | exp.X_op = O_illegal; | |
b99bd4ef | 3990 | |
c19d1205 | 3991 | if (exp.X_op != O_constant) |
b99bd4ef | 3992 | { |
c19d1205 ZW |
3993 | as_bad (_("expected , <constant>")); |
3994 | ignore_rest_of_line (); | |
b99bd4ef NC |
3995 | return; |
3996 | } | |
3997 | ||
c19d1205 ZW |
3998 | num_regs = exp.X_add_number; |
3999 | ||
4000 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 4001 | { |
c19d1205 ZW |
4002 | as_bad (_("number of registers must be in the range [1:4]")); |
4003 | ignore_rest_of_line (); | |
b99bd4ef NC |
4004 | return; |
4005 | } | |
4006 | ||
c19d1205 | 4007 | demand_empty_rest_of_line (); |
b99bd4ef | 4008 | |
c19d1205 ZW |
4009 | if (reg == 4) |
4010 | { | |
4011 | /* Short form. */ | |
4012 | op = 0xb4 | (num_regs - 1); | |
4013 | add_unwind_opcode (op, 1); | |
4014 | } | |
b99bd4ef NC |
4015 | else |
4016 | { | |
c19d1205 ZW |
4017 | /* Long form. */ |
4018 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
4019 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4020 | } |
c19d1205 | 4021 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
4022 | } |
4023 | ||
c19d1205 | 4024 | |
fa073d69 MS |
4025 | /* Parse a directive saving VFP registers for ARMv6 and above. */ |
4026 | ||
4027 | static void | |
4028 | s_arm_unwind_save_vfp_armv6 (void) | |
4029 | { | |
4030 | int count; | |
4031 | unsigned int start; | |
4032 | valueT op; | |
4033 | int num_vfpv3_regs = 0; | |
4034 | int num_regs_below_16; | |
4035 | ||
4036 | count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D); | |
4037 | if (count == FAIL) | |
4038 | { | |
4039 | as_bad (_("expected register list")); | |
4040 | ignore_rest_of_line (); | |
4041 | return; | |
4042 | } | |
4043 | ||
4044 | demand_empty_rest_of_line (); | |
4045 | ||
4046 | /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather | |
4047 | than FSTMX/FLDMX-style ones). */ | |
4048 | ||
4049 | /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */ | |
4050 | if (start >= 16) | |
4051 | num_vfpv3_regs = count; | |
4052 | else if (start + count > 16) | |
4053 | num_vfpv3_regs = start + count - 16; | |
4054 | ||
4055 | if (num_vfpv3_regs > 0) | |
4056 | { | |
4057 | int start_offset = start > 16 ? start - 16 : 0; | |
4058 | op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1); | |
4059 | add_unwind_opcode (op, 2); | |
4060 | } | |
4061 | ||
4062 | /* Generate opcode for registers numbered in the range 0 .. 15. */ | |
4063 | num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count; | |
9c2799c2 | 4064 | gas_assert (num_regs_below_16 + num_vfpv3_regs == count); |
fa073d69 MS |
4065 | if (num_regs_below_16 > 0) |
4066 | { | |
4067 | op = 0xc900 | (start << 4) | (num_regs_below_16 - 1); | |
4068 | add_unwind_opcode (op, 2); | |
4069 | } | |
4070 | ||
4071 | unwind.frame_size += count * 8; | |
4072 | } | |
4073 | ||
4074 | ||
4075 | /* Parse a directive saving VFP registers for pre-ARMv6. */ | |
b99bd4ef NC |
4076 | |
4077 | static void | |
c19d1205 | 4078 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 4079 | { |
c19d1205 | 4080 | int count; |
ca3f61f7 | 4081 | unsigned int reg; |
c19d1205 | 4082 | valueT op; |
b99bd4ef | 4083 | |
5287ad62 | 4084 | count = parse_vfp_reg_list (&input_line_pointer, ®, REGLIST_VFP_D); |
c19d1205 | 4085 | if (count == FAIL) |
b99bd4ef | 4086 | { |
c19d1205 ZW |
4087 | as_bad (_("expected register list")); |
4088 | ignore_rest_of_line (); | |
b99bd4ef NC |
4089 | return; |
4090 | } | |
4091 | ||
c19d1205 | 4092 | demand_empty_rest_of_line (); |
b99bd4ef | 4093 | |
c19d1205 | 4094 | if (reg == 8) |
b99bd4ef | 4095 | { |
c19d1205 ZW |
4096 | /* Short form. */ |
4097 | op = 0xb8 | (count - 1); | |
4098 | add_unwind_opcode (op, 1); | |
b99bd4ef | 4099 | } |
c19d1205 | 4100 | else |
b99bd4ef | 4101 | { |
c19d1205 ZW |
4102 | /* Long form. */ |
4103 | op = 0xb300 | (reg << 4) | (count - 1); | |
4104 | add_unwind_opcode (op, 2); | |
b99bd4ef | 4105 | } |
c19d1205 ZW |
4106 | unwind.frame_size += count * 8 + 4; |
4107 | } | |
b99bd4ef | 4108 | |
b99bd4ef | 4109 | |
c19d1205 ZW |
4110 | /* Parse a directive saving iWMMXt data registers. */ |
4111 | ||
4112 | static void | |
4113 | s_arm_unwind_save_mmxwr (void) | |
4114 | { | |
4115 | int reg; | |
4116 | int hi_reg; | |
4117 | int i; | |
4118 | unsigned mask = 0; | |
4119 | valueT op; | |
b99bd4ef | 4120 | |
c19d1205 ZW |
4121 | if (*input_line_pointer == '{') |
4122 | input_line_pointer++; | |
b99bd4ef | 4123 | |
c19d1205 | 4124 | do |
b99bd4ef | 4125 | { |
dcbf9037 | 4126 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 4127 | |
c19d1205 | 4128 | if (reg == FAIL) |
b99bd4ef | 4129 | { |
9b7132d3 | 4130 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 | 4131 | goto error; |
b99bd4ef NC |
4132 | } |
4133 | ||
c19d1205 ZW |
4134 | if (mask >> reg) |
4135 | as_tsktsk (_("register list not in ascending order")); | |
4136 | mask |= 1 << reg; | |
b99bd4ef | 4137 | |
c19d1205 ZW |
4138 | if (*input_line_pointer == '-') |
4139 | { | |
4140 | input_line_pointer++; | |
dcbf9037 | 4141 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
c19d1205 ZW |
4142 | if (hi_reg == FAIL) |
4143 | { | |
9b7132d3 | 4144 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR])); |
c19d1205 ZW |
4145 | goto error; |
4146 | } | |
4147 | else if (reg >= hi_reg) | |
4148 | { | |
4149 | as_bad (_("bad register range")); | |
4150 | goto error; | |
4151 | } | |
4152 | for (; reg < hi_reg; reg++) | |
4153 | mask |= 1 << reg; | |
4154 | } | |
4155 | } | |
4156 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 4157 | |
d996d970 | 4158 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4159 | |
c19d1205 | 4160 | demand_empty_rest_of_line (); |
b99bd4ef | 4161 | |
708587a4 | 4162 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4163 | the list. */ |
4164 | flush_pending_unwind (); | |
b99bd4ef | 4165 | |
c19d1205 | 4166 | for (i = 0; i < 16; i++) |
b99bd4ef | 4167 | { |
c19d1205 ZW |
4168 | if (mask & (1 << i)) |
4169 | unwind.frame_size += 8; | |
b99bd4ef NC |
4170 | } |
4171 | ||
c19d1205 ZW |
4172 | /* Attempt to combine with a previous opcode. We do this because gcc |
4173 | likes to output separate unwind directives for a single block of | |
4174 | registers. */ | |
4175 | if (unwind.opcode_count > 0) | |
b99bd4ef | 4176 | { |
c19d1205 ZW |
4177 | i = unwind.opcodes[unwind.opcode_count - 1]; |
4178 | if ((i & 0xf8) == 0xc0) | |
4179 | { | |
4180 | i &= 7; | |
4181 | /* Only merge if the blocks are contiguous. */ | |
4182 | if (i < 6) | |
4183 | { | |
4184 | if ((mask & 0xfe00) == (1 << 9)) | |
4185 | { | |
4186 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
4187 | unwind.opcode_count--; | |
4188 | } | |
4189 | } | |
4190 | else if (i == 6 && unwind.opcode_count >= 2) | |
4191 | { | |
4192 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
4193 | reg = i >> 4; | |
4194 | i &= 0xf; | |
b99bd4ef | 4195 | |
c19d1205 ZW |
4196 | op = 0xffff << (reg - 1); |
4197 | if (reg > 0 | |
87a1fd79 | 4198 | && ((mask & op) == (1u << (reg - 1)))) |
c19d1205 ZW |
4199 | { |
4200 | op = (1 << (reg + i + 1)) - 1; | |
4201 | op &= ~((1 << reg) - 1); | |
4202 | mask |= op; | |
4203 | unwind.opcode_count -= 2; | |
4204 | } | |
4205 | } | |
4206 | } | |
b99bd4ef NC |
4207 | } |
4208 | ||
c19d1205 ZW |
4209 | hi_reg = 15; |
4210 | /* We want to generate opcodes in the order the registers have been | |
4211 | saved, ie. descending order. */ | |
4212 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 4213 | { |
c19d1205 ZW |
4214 | /* Save registers in blocks. */ |
4215 | if (reg < 0 | |
4216 | || !(mask & (1 << reg))) | |
4217 | { | |
4218 | /* We found an unsaved reg. Generate opcodes to save the | |
5f4273c7 | 4219 | preceding block. */ |
c19d1205 ZW |
4220 | if (reg != hi_reg) |
4221 | { | |
4222 | if (reg == 9) | |
4223 | { | |
4224 | /* Short form. */ | |
4225 | op = 0xc0 | (hi_reg - 10); | |
4226 | add_unwind_opcode (op, 1); | |
4227 | } | |
4228 | else | |
4229 | { | |
4230 | /* Long form. */ | |
4231 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
4232 | add_unwind_opcode (op, 2); | |
4233 | } | |
4234 | } | |
4235 | hi_reg = reg - 1; | |
4236 | } | |
b99bd4ef NC |
4237 | } |
4238 | ||
c19d1205 ZW |
4239 | return; |
4240 | error: | |
4241 | ignore_rest_of_line (); | |
b99bd4ef NC |
4242 | } |
4243 | ||
4244 | static void | |
c19d1205 | 4245 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 4246 | { |
c19d1205 ZW |
4247 | int reg; |
4248 | int hi_reg; | |
4249 | unsigned mask = 0; | |
4250 | valueT op; | |
b99bd4ef | 4251 | |
c19d1205 ZW |
4252 | if (*input_line_pointer == '{') |
4253 | input_line_pointer++; | |
b99bd4ef | 4254 | |
477330fc RM |
4255 | skip_whitespace (input_line_pointer); |
4256 | ||
c19d1205 | 4257 | do |
b99bd4ef | 4258 | { |
dcbf9037 | 4259 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 4260 | |
c19d1205 ZW |
4261 | if (reg == FAIL) |
4262 | { | |
9b7132d3 | 4263 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4264 | goto error; |
4265 | } | |
b99bd4ef | 4266 | |
c19d1205 ZW |
4267 | reg -= 8; |
4268 | if (mask >> reg) | |
4269 | as_tsktsk (_("register list not in ascending order")); | |
4270 | mask |= 1 << reg; | |
b99bd4ef | 4271 | |
c19d1205 ZW |
4272 | if (*input_line_pointer == '-') |
4273 | { | |
4274 | input_line_pointer++; | |
dcbf9037 | 4275 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
c19d1205 ZW |
4276 | if (hi_reg == FAIL) |
4277 | { | |
9b7132d3 | 4278 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG])); |
c19d1205 ZW |
4279 | goto error; |
4280 | } | |
4281 | else if (reg >= hi_reg) | |
4282 | { | |
4283 | as_bad (_("bad register range")); | |
4284 | goto error; | |
4285 | } | |
4286 | for (; reg < hi_reg; reg++) | |
4287 | mask |= 1 << reg; | |
4288 | } | |
b99bd4ef | 4289 | } |
c19d1205 | 4290 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 4291 | |
d996d970 | 4292 | skip_past_char (&input_line_pointer, '}'); |
b99bd4ef | 4293 | |
c19d1205 ZW |
4294 | demand_empty_rest_of_line (); |
4295 | ||
708587a4 | 4296 | /* Generate any deferred opcodes because we're going to be looking at |
c19d1205 ZW |
4297 | the list. */ |
4298 | flush_pending_unwind (); | |
b99bd4ef | 4299 | |
c19d1205 | 4300 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 4301 | { |
c19d1205 ZW |
4302 | if (mask & (1 << reg)) |
4303 | unwind.frame_size += 4; | |
b99bd4ef | 4304 | } |
c19d1205 ZW |
4305 | op = 0xc700 | mask; |
4306 | add_unwind_opcode (op, 2); | |
4307 | return; | |
4308 | error: | |
4309 | ignore_rest_of_line (); | |
b99bd4ef NC |
4310 | } |
4311 | ||
c19d1205 | 4312 | |
fa073d69 MS |
4313 | /* Parse an unwind_save directive. |
4314 | If the argument is non-zero, this is a .vsave directive. */ | |
c19d1205 | 4315 | |
b99bd4ef | 4316 | static void |
fa073d69 | 4317 | s_arm_unwind_save (int arch_v6) |
b99bd4ef | 4318 | { |
c19d1205 ZW |
4319 | char *peek; |
4320 | struct reg_entry *reg; | |
4321 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 4322 | |
921e5f0a | 4323 | if (!unwind.proc_start) |
c921be7d | 4324 | as_bad (MISSING_FNSTART); |
921e5f0a | 4325 | |
c19d1205 ZW |
4326 | /* Figure out what sort of save we have. */ |
4327 | peek = input_line_pointer; | |
b99bd4ef | 4328 | |
c19d1205 | 4329 | if (*peek == '{') |
b99bd4ef | 4330 | { |
c19d1205 ZW |
4331 | had_brace = TRUE; |
4332 | peek++; | |
b99bd4ef NC |
4333 | } |
4334 | ||
c19d1205 | 4335 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 4336 | |
c19d1205 | 4337 | if (!reg) |
b99bd4ef | 4338 | { |
c19d1205 ZW |
4339 | as_bad (_("register expected")); |
4340 | ignore_rest_of_line (); | |
b99bd4ef NC |
4341 | return; |
4342 | } | |
4343 | ||
c19d1205 | 4344 | switch (reg->type) |
b99bd4ef | 4345 | { |
c19d1205 ZW |
4346 | case REG_TYPE_FN: |
4347 | if (had_brace) | |
4348 | { | |
4349 | as_bad (_("FPA .unwind_save does not take a register list")); | |
4350 | ignore_rest_of_line (); | |
4351 | return; | |
4352 | } | |
93ac2687 | 4353 | input_line_pointer = peek; |
c19d1205 | 4354 | s_arm_unwind_save_fpa (reg->number); |
b99bd4ef | 4355 | return; |
c19d1205 | 4356 | |
1f5afe1c NC |
4357 | case REG_TYPE_RN: |
4358 | s_arm_unwind_save_core (); | |
4359 | return; | |
4360 | ||
fa073d69 MS |
4361 | case REG_TYPE_VFD: |
4362 | if (arch_v6) | |
477330fc | 4363 | s_arm_unwind_save_vfp_armv6 (); |
fa073d69 | 4364 | else |
477330fc | 4365 | s_arm_unwind_save_vfp (); |
fa073d69 | 4366 | return; |
1f5afe1c NC |
4367 | |
4368 | case REG_TYPE_MMXWR: | |
4369 | s_arm_unwind_save_mmxwr (); | |
4370 | return; | |
4371 | ||
4372 | case REG_TYPE_MMXWCG: | |
4373 | s_arm_unwind_save_mmxwcg (); | |
4374 | return; | |
c19d1205 ZW |
4375 | |
4376 | default: | |
4377 | as_bad (_(".unwind_save does not support this kind of register")); | |
4378 | ignore_rest_of_line (); | |
b99bd4ef | 4379 | } |
c19d1205 | 4380 | } |
b99bd4ef | 4381 | |
b99bd4ef | 4382 | |
c19d1205 ZW |
4383 | /* Parse an unwind_movsp directive. */ |
4384 | ||
4385 | static void | |
4386 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
4387 | { | |
4388 | int reg; | |
4389 | valueT op; | |
4fa3602b | 4390 | int offset; |
c19d1205 | 4391 | |
921e5f0a | 4392 | if (!unwind.proc_start) |
c921be7d | 4393 | as_bad (MISSING_FNSTART); |
921e5f0a | 4394 | |
dcbf9037 | 4395 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 | 4396 | if (reg == FAIL) |
b99bd4ef | 4397 | { |
9b7132d3 | 4398 | as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN])); |
c19d1205 | 4399 | ignore_rest_of_line (); |
b99bd4ef NC |
4400 | return; |
4401 | } | |
4fa3602b PB |
4402 | |
4403 | /* Optional constant. */ | |
4404 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4405 | { | |
4406 | if (immediate_for_directive (&offset) == FAIL) | |
4407 | return; | |
4408 | } | |
4409 | else | |
4410 | offset = 0; | |
4411 | ||
c19d1205 | 4412 | demand_empty_rest_of_line (); |
b99bd4ef | 4413 | |
c19d1205 | 4414 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 4415 | { |
c19d1205 | 4416 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
4417 | return; |
4418 | } | |
4419 | ||
c19d1205 ZW |
4420 | if (unwind.fp_reg != REG_SP) |
4421 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 4422 | |
c19d1205 ZW |
4423 | /* Generate opcode to restore the value. */ |
4424 | op = 0x90 | reg; | |
4425 | add_unwind_opcode (op, 1); | |
4426 | ||
4427 | /* Record the information for later. */ | |
4428 | unwind.fp_reg = reg; | |
4fa3602b | 4429 | unwind.fp_offset = unwind.frame_size - offset; |
c19d1205 | 4430 | unwind.sp_restored = 1; |
b05fe5cf ZW |
4431 | } |
4432 | ||
c19d1205 ZW |
4433 | /* Parse an unwind_pad directive. */ |
4434 | ||
b05fe5cf | 4435 | static void |
c19d1205 | 4436 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 4437 | { |
c19d1205 | 4438 | int offset; |
b05fe5cf | 4439 | |
921e5f0a | 4440 | if (!unwind.proc_start) |
c921be7d | 4441 | as_bad (MISSING_FNSTART); |
921e5f0a | 4442 | |
c19d1205 ZW |
4443 | if (immediate_for_directive (&offset) == FAIL) |
4444 | return; | |
b99bd4ef | 4445 | |
c19d1205 ZW |
4446 | if (offset & 3) |
4447 | { | |
4448 | as_bad (_("stack increment must be multiple of 4")); | |
4449 | ignore_rest_of_line (); | |
4450 | return; | |
4451 | } | |
b99bd4ef | 4452 | |
c19d1205 ZW |
4453 | /* Don't generate any opcodes, just record the details for later. */ |
4454 | unwind.frame_size += offset; | |
4455 | unwind.pending_offset += offset; | |
4456 | ||
4457 | demand_empty_rest_of_line (); | |
4458 | } | |
4459 | ||
4460 | /* Parse an unwind_setfp directive. */ | |
4461 | ||
4462 | static void | |
4463 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 4464 | { |
c19d1205 ZW |
4465 | int sp_reg; |
4466 | int fp_reg; | |
4467 | int offset; | |
4468 | ||
921e5f0a | 4469 | if (!unwind.proc_start) |
c921be7d | 4470 | as_bad (MISSING_FNSTART); |
921e5f0a | 4471 | |
dcbf9037 | 4472 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
c19d1205 ZW |
4473 | if (skip_past_comma (&input_line_pointer) == FAIL) |
4474 | sp_reg = FAIL; | |
4475 | else | |
dcbf9037 | 4476 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); |
b99bd4ef | 4477 | |
c19d1205 ZW |
4478 | if (fp_reg == FAIL || sp_reg == FAIL) |
4479 | { | |
4480 | as_bad (_("expected <reg>, <reg>")); | |
4481 | ignore_rest_of_line (); | |
4482 | return; | |
4483 | } | |
b99bd4ef | 4484 | |
c19d1205 ZW |
4485 | /* Optional constant. */ |
4486 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
4487 | { | |
4488 | if (immediate_for_directive (&offset) == FAIL) | |
4489 | return; | |
4490 | } | |
4491 | else | |
4492 | offset = 0; | |
a737bd4d | 4493 | |
c19d1205 | 4494 | demand_empty_rest_of_line (); |
a737bd4d | 4495 | |
fdfde340 | 4496 | if (sp_reg != REG_SP && sp_reg != unwind.fp_reg) |
a737bd4d | 4497 | { |
c19d1205 ZW |
4498 | as_bad (_("register must be either sp or set by a previous" |
4499 | "unwind_movsp directive")); | |
4500 | return; | |
a737bd4d NC |
4501 | } |
4502 | ||
c19d1205 ZW |
4503 | /* Don't generate any opcodes, just record the information for later. */ |
4504 | unwind.fp_reg = fp_reg; | |
4505 | unwind.fp_used = 1; | |
fdfde340 | 4506 | if (sp_reg == REG_SP) |
c19d1205 ZW |
4507 | unwind.fp_offset = unwind.frame_size - offset; |
4508 | else | |
4509 | unwind.fp_offset -= offset; | |
a737bd4d NC |
4510 | } |
4511 | ||
c19d1205 ZW |
4512 | /* Parse an unwind_raw directive. */ |
4513 | ||
4514 | static void | |
4515 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 4516 | { |
c19d1205 | 4517 | expressionS exp; |
708587a4 | 4518 | /* This is an arbitrary limit. */ |
c19d1205 ZW |
4519 | unsigned char op[16]; |
4520 | int count; | |
a737bd4d | 4521 | |
921e5f0a | 4522 | if (!unwind.proc_start) |
c921be7d | 4523 | as_bad (MISSING_FNSTART); |
921e5f0a | 4524 | |
c19d1205 ZW |
4525 | expression (&exp); |
4526 | if (exp.X_op == O_constant | |
4527 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 4528 | { |
c19d1205 ZW |
4529 | unwind.frame_size += exp.X_add_number; |
4530 | expression (&exp); | |
4531 | } | |
4532 | else | |
4533 | exp.X_op = O_illegal; | |
a737bd4d | 4534 | |
c19d1205 ZW |
4535 | if (exp.X_op != O_constant) |
4536 | { | |
4537 | as_bad (_("expected <offset>, <opcode>")); | |
4538 | ignore_rest_of_line (); | |
4539 | return; | |
4540 | } | |
a737bd4d | 4541 | |
c19d1205 | 4542 | count = 0; |
a737bd4d | 4543 | |
c19d1205 ZW |
4544 | /* Parse the opcode. */ |
4545 | for (;;) | |
4546 | { | |
4547 | if (count >= 16) | |
4548 | { | |
4549 | as_bad (_("unwind opcode too long")); | |
4550 | ignore_rest_of_line (); | |
a737bd4d | 4551 | } |
c19d1205 | 4552 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 4553 | { |
c19d1205 ZW |
4554 | as_bad (_("invalid unwind opcode")); |
4555 | ignore_rest_of_line (); | |
4556 | return; | |
a737bd4d | 4557 | } |
c19d1205 | 4558 | op[count++] = exp.X_add_number; |
a737bd4d | 4559 | |
c19d1205 ZW |
4560 | /* Parse the next byte. */ |
4561 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
4562 | break; | |
a737bd4d | 4563 | |
c19d1205 ZW |
4564 | expression (&exp); |
4565 | } | |
b99bd4ef | 4566 | |
c19d1205 ZW |
4567 | /* Add the opcode bytes in reverse order. */ |
4568 | while (count--) | |
4569 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 4570 | |
c19d1205 | 4571 | demand_empty_rest_of_line (); |
b99bd4ef | 4572 | } |
ee065d83 PB |
4573 | |
4574 | ||
4575 | /* Parse a .eabi_attribute directive. */ | |
4576 | ||
4577 | static void | |
4578 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
4579 | { | |
0420f52b | 4580 | int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC); |
ee3c0378 AS |
4581 | |
4582 | if (tag < NUM_KNOWN_OBJ_ATTRIBUTES) | |
4583 | attributes_set_explicitly[tag] = 1; | |
ee065d83 PB |
4584 | } |
4585 | ||
0855e32b NS |
4586 | /* Emit a tls fix for the symbol. */ |
4587 | ||
4588 | static void | |
4589 | s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED) | |
4590 | { | |
4591 | char *p; | |
4592 | expressionS exp; | |
4593 | #ifdef md_flush_pending_output | |
4594 | md_flush_pending_output (); | |
4595 | #endif | |
4596 | ||
4597 | #ifdef md_cons_align | |
4598 | md_cons_align (4); | |
4599 | #endif | |
4600 | ||
4601 | /* Since we're just labelling the code, there's no need to define a | |
4602 | mapping symbol. */ | |
4603 | expression (&exp); | |
4604 | p = obstack_next_free (&frchain_now->frch_obstack); | |
4605 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0, | |
4606 | thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
4607 | : BFD_RELOC_ARM_TLS_DESCSEQ); | |
4608 | } | |
cdf9ccec | 4609 | #endif /* OBJ_ELF */ |
0855e32b | 4610 | |
ee065d83 | 4611 | static void s_arm_arch (int); |
7a1d4c38 | 4612 | static void s_arm_object_arch (int); |
ee065d83 PB |
4613 | static void s_arm_cpu (int); |
4614 | static void s_arm_fpu (int); | |
69133863 | 4615 | static void s_arm_arch_extension (int); |
b99bd4ef | 4616 | |
f0927246 NC |
4617 | #ifdef TE_PE |
4618 | ||
4619 | static void | |
5f4273c7 | 4620 | pe_directive_secrel (int dummy ATTRIBUTE_UNUSED) |
f0927246 NC |
4621 | { |
4622 | expressionS exp; | |
4623 | ||
4624 | do | |
4625 | { | |
4626 | expression (&exp); | |
4627 | if (exp.X_op == O_symbol) | |
4628 | exp.X_op = O_secrel; | |
4629 | ||
4630 | emit_expr (&exp, 4); | |
4631 | } | |
4632 | while (*input_line_pointer++ == ','); | |
4633 | ||
4634 | input_line_pointer--; | |
4635 | demand_empty_rest_of_line (); | |
4636 | } | |
4637 | #endif /* TE_PE */ | |
4638 | ||
c19d1205 ZW |
4639 | /* This table describes all the machine specific pseudo-ops the assembler |
4640 | has to support. The fields are: | |
4641 | pseudo-op name without dot | |
4642 | function to call to execute this pseudo-op | |
4643 | Integer arg to pass to the function. */ | |
b99bd4ef | 4644 | |
c19d1205 | 4645 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 4646 | { |
c19d1205 ZW |
4647 | /* Never called because '.req' does not start a line. */ |
4648 | { "req", s_req, 0 }, | |
dcbf9037 JB |
4649 | /* Following two are likewise never called. */ |
4650 | { "dn", s_dn, 0 }, | |
4651 | { "qn", s_qn, 0 }, | |
c19d1205 ZW |
4652 | { "unreq", s_unreq, 0 }, |
4653 | { "bss", s_bss, 0 }, | |
db2ed2e0 | 4654 | { "align", s_align_ptwo, 2 }, |
c19d1205 ZW |
4655 | { "arm", s_arm, 0 }, |
4656 | { "thumb", s_thumb, 0 }, | |
4657 | { "code", s_code, 0 }, | |
4658 | { "force_thumb", s_force_thumb, 0 }, | |
4659 | { "thumb_func", s_thumb_func, 0 }, | |
4660 | { "thumb_set", s_thumb_set, 0 }, | |
4661 | { "even", s_even, 0 }, | |
4662 | { "ltorg", s_ltorg, 0 }, | |
4663 | { "pool", s_ltorg, 0 }, | |
4664 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
4665 | { "cpu", s_arm_cpu, 0 }, |
4666 | { "arch", s_arm_arch, 0 }, | |
7a1d4c38 | 4667 | { "object_arch", s_arm_object_arch, 0 }, |
8463be01 | 4668 | { "fpu", s_arm_fpu, 0 }, |
69133863 | 4669 | { "arch_extension", s_arm_arch_extension, 0 }, |
c19d1205 | 4670 | #ifdef OBJ_ELF |
c921be7d NC |
4671 | { "word", s_arm_elf_cons, 4 }, |
4672 | { "long", s_arm_elf_cons, 4 }, | |
4673 | { "inst.n", s_arm_elf_inst, 2 }, | |
4674 | { "inst.w", s_arm_elf_inst, 4 }, | |
4675 | { "inst", s_arm_elf_inst, 0 }, | |
4676 | { "rel31", s_arm_rel31, 0 }, | |
c19d1205 ZW |
4677 | { "fnstart", s_arm_unwind_fnstart, 0 }, |
4678 | { "fnend", s_arm_unwind_fnend, 0 }, | |
4679 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
4680 | { "personality", s_arm_unwind_personality, 0 }, | |
4681 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
4682 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
4683 | { "save", s_arm_unwind_save, 0 }, | |
fa073d69 | 4684 | { "vsave", s_arm_unwind_save, 1 }, |
c19d1205 ZW |
4685 | { "movsp", s_arm_unwind_movsp, 0 }, |
4686 | { "pad", s_arm_unwind_pad, 0 }, | |
4687 | { "setfp", s_arm_unwind_setfp, 0 }, | |
4688 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 4689 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
0855e32b | 4690 | { "tlsdescseq", s_arm_tls_descseq, 0 }, |
c19d1205 ZW |
4691 | #else |
4692 | { "word", cons, 4}, | |
f0927246 NC |
4693 | |
4694 | /* These are used for dwarf. */ | |
4695 | {"2byte", cons, 2}, | |
4696 | {"4byte", cons, 4}, | |
4697 | {"8byte", cons, 8}, | |
4698 | /* These are used for dwarf2. */ | |
4699 | { "file", (void (*) (int)) dwarf2_directive_file, 0 }, | |
4700 | { "loc", dwarf2_directive_loc, 0 }, | |
4701 | { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 }, | |
c19d1205 ZW |
4702 | #endif |
4703 | { "extend", float_cons, 'x' }, | |
4704 | { "ldouble", float_cons, 'x' }, | |
4705 | { "packed", float_cons, 'p' }, | |
f0927246 NC |
4706 | #ifdef TE_PE |
4707 | {"secrel32", pe_directive_secrel, 0}, | |
4708 | #endif | |
2e6976a8 DG |
4709 | |
4710 | /* These are for compatibility with CodeComposer Studio. */ | |
4711 | {"ref", s_ccs_ref, 0}, | |
4712 | {"def", s_ccs_def, 0}, | |
4713 | {"asmfunc", s_ccs_asmfunc, 0}, | |
4714 | {"endasmfunc", s_ccs_endasmfunc, 0}, | |
4715 | ||
c19d1205 ZW |
4716 | { 0, 0, 0 } |
4717 | }; | |
4718 | \f | |
4719 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 4720 | |
c19d1205 ZW |
4721 | /* Generic immediate-value read function for use in insn parsing. |
4722 | STR points to the beginning of the immediate (the leading #); | |
4723 | VAL receives the value; if the value is outside [MIN, MAX] | |
4724 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
4725 | optional. */ | |
b99bd4ef | 4726 | |
c19d1205 ZW |
4727 | static int |
4728 | parse_immediate (char **str, int *val, int min, int max, | |
4729 | bfd_boolean prefix_opt) | |
4730 | { | |
4731 | expressionS exp; | |
4732 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
4733 | if (exp.X_op != O_constant) | |
b99bd4ef | 4734 | { |
c19d1205 ZW |
4735 | inst.error = _("constant expression required"); |
4736 | return FAIL; | |
4737 | } | |
b99bd4ef | 4738 | |
c19d1205 ZW |
4739 | if (exp.X_add_number < min || exp.X_add_number > max) |
4740 | { | |
4741 | inst.error = _("immediate value out of range"); | |
4742 | return FAIL; | |
4743 | } | |
b99bd4ef | 4744 | |
c19d1205 ZW |
4745 | *val = exp.X_add_number; |
4746 | return SUCCESS; | |
4747 | } | |
b99bd4ef | 4748 | |
5287ad62 | 4749 | /* Less-generic immediate-value read function with the possibility of loading a |
036dc3f7 | 4750 | big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate |
5287ad62 JB |
4751 | instructions. Puts the result directly in inst.operands[i]. */ |
4752 | ||
4753 | static int | |
8335d6aa JW |
4754 | parse_big_immediate (char **str, int i, expressionS *in_exp, |
4755 | bfd_boolean allow_symbol_p) | |
5287ad62 JB |
4756 | { |
4757 | expressionS exp; | |
8335d6aa | 4758 | expressionS *exp_p = in_exp ? in_exp : &exp; |
5287ad62 JB |
4759 | char *ptr = *str; |
4760 | ||
8335d6aa | 4761 | my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG); |
5287ad62 | 4762 | |
8335d6aa | 4763 | if (exp_p->X_op == O_constant) |
036dc3f7 | 4764 | { |
8335d6aa | 4765 | inst.operands[i].imm = exp_p->X_add_number & 0xffffffff; |
036dc3f7 PB |
4766 | /* If we're on a 64-bit host, then a 64-bit number can be returned using |
4767 | O_constant. We have to be careful not to break compilation for | |
4768 | 32-bit X_add_number, though. */ | |
8335d6aa | 4769 | if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0) |
036dc3f7 | 4770 | { |
8335d6aa JW |
4771 | /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */ |
4772 | inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16) | |
4773 | & 0xffffffff); | |
036dc3f7 PB |
4774 | inst.operands[i].regisimm = 1; |
4775 | } | |
4776 | } | |
8335d6aa JW |
4777 | else if (exp_p->X_op == O_big |
4778 | && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32) | |
5287ad62 JB |
4779 | { |
4780 | unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0; | |
95b75c01 | 4781 | |
5287ad62 | 4782 | /* Bignums have their least significant bits in |
477330fc RM |
4783 | generic_bignum[0]. Make sure we put 32 bits in imm and |
4784 | 32 bits in reg, in a (hopefully) portable way. */ | |
9c2799c2 | 4785 | gas_assert (parts != 0); |
95b75c01 NC |
4786 | |
4787 | /* Make sure that the number is not too big. | |
4788 | PR 11972: Bignums can now be sign-extended to the | |
4789 | size of a .octa so check that the out of range bits | |
4790 | are all zero or all one. */ | |
8335d6aa | 4791 | if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64) |
95b75c01 NC |
4792 | { |
4793 | LITTLENUM_TYPE m = -1; | |
4794 | ||
4795 | if (generic_bignum[parts * 2] != 0 | |
4796 | && generic_bignum[parts * 2] != m) | |
4797 | return FAIL; | |
4798 | ||
8335d6aa | 4799 | for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++) |
95b75c01 NC |
4800 | if (generic_bignum[j] != generic_bignum[j-1]) |
4801 | return FAIL; | |
4802 | } | |
4803 | ||
5287ad62 JB |
4804 | inst.operands[i].imm = 0; |
4805 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4806 | inst.operands[i].imm |= generic_bignum[idx] |
4807 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4808 | inst.operands[i].reg = 0; |
4809 | for (j = 0; j < parts; j++, idx++) | |
477330fc RM |
4810 | inst.operands[i].reg |= generic_bignum[idx] |
4811 | << (LITTLENUM_NUMBER_OF_BITS * j); | |
5287ad62 JB |
4812 | inst.operands[i].regisimm = 1; |
4813 | } | |
8335d6aa | 4814 | else if (!(exp_p->X_op == O_symbol && allow_symbol_p)) |
5287ad62 | 4815 | return FAIL; |
5f4273c7 | 4816 | |
5287ad62 JB |
4817 | *str = ptr; |
4818 | ||
4819 | return SUCCESS; | |
4820 | } | |
4821 | ||
c19d1205 ZW |
4822 | /* Returns the pseudo-register number of an FPA immediate constant, |
4823 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 4824 | |
c19d1205 ZW |
4825 | static int |
4826 | parse_fpa_immediate (char ** str) | |
4827 | { | |
4828 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
4829 | char * save_in; | |
4830 | expressionS exp; | |
4831 | int i; | |
4832 | int j; | |
b99bd4ef | 4833 | |
c19d1205 ZW |
4834 | /* First try and match exact strings, this is to guarantee |
4835 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 4836 | |
c19d1205 ZW |
4837 | for (i = 0; fp_const[i]; i++) |
4838 | { | |
4839 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 4840 | { |
c19d1205 | 4841 | char *start = *str; |
b99bd4ef | 4842 | |
c19d1205 ZW |
4843 | *str += strlen (fp_const[i]); |
4844 | if (is_end_of_line[(unsigned char) **str]) | |
4845 | return i + 8; | |
4846 | *str = start; | |
4847 | } | |
4848 | } | |
b99bd4ef | 4849 | |
c19d1205 ZW |
4850 | /* Just because we didn't get a match doesn't mean that the constant |
4851 | isn't valid, just that it is in a format that we don't | |
4852 | automatically recognize. Try parsing it with the standard | |
4853 | expression routines. */ | |
b99bd4ef | 4854 | |
c19d1205 | 4855 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 4856 | |
c19d1205 ZW |
4857 | /* Look for a raw floating point number. */ |
4858 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
4859 | && is_end_of_line[(unsigned char) *save_in]) | |
4860 | { | |
4861 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4862 | { | |
4863 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 4864 | { |
c19d1205 ZW |
4865 | if (words[j] != fp_values[i][j]) |
4866 | break; | |
b99bd4ef NC |
4867 | } |
4868 | ||
c19d1205 | 4869 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 4870 | { |
c19d1205 ZW |
4871 | *str = save_in; |
4872 | return i + 8; | |
b99bd4ef NC |
4873 | } |
4874 | } | |
4875 | } | |
b99bd4ef | 4876 | |
c19d1205 ZW |
4877 | /* Try and parse a more complex expression, this will probably fail |
4878 | unless the code uses a floating point prefix (eg "0f"). */ | |
4879 | save_in = input_line_pointer; | |
4880 | input_line_pointer = *str; | |
4881 | if (expression (&exp) == absolute_section | |
4882 | && exp.X_op == O_big | |
4883 | && exp.X_add_number < 0) | |
4884 | { | |
4885 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
4886 | Ditto for 15. */ | |
ba592044 AM |
4887 | #define X_PRECISION 5 |
4888 | #define E_PRECISION 15L | |
4889 | if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0) | |
c19d1205 ZW |
4890 | { |
4891 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
4892 | { | |
4893 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
4894 | { | |
4895 | if (words[j] != fp_values[i][j]) | |
4896 | break; | |
4897 | } | |
b99bd4ef | 4898 | |
c19d1205 ZW |
4899 | if (j == MAX_LITTLENUMS) |
4900 | { | |
4901 | *str = input_line_pointer; | |
4902 | input_line_pointer = save_in; | |
4903 | return i + 8; | |
4904 | } | |
4905 | } | |
4906 | } | |
b99bd4ef NC |
4907 | } |
4908 | ||
c19d1205 ZW |
4909 | *str = input_line_pointer; |
4910 | input_line_pointer = save_in; | |
4911 | inst.error = _("invalid FPA immediate expression"); | |
4912 | return FAIL; | |
b99bd4ef NC |
4913 | } |
4914 | ||
136da414 JB |
4915 | /* Returns 1 if a number has "quarter-precision" float format |
4916 | 0baBbbbbbc defgh000 00000000 00000000. */ | |
4917 | ||
4918 | static int | |
4919 | is_quarter_float (unsigned imm) | |
4920 | { | |
4921 | int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000; | |
4922 | return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0; | |
4923 | } | |
4924 | ||
aacf0b33 KT |
4925 | |
4926 | /* Detect the presence of a floating point or integer zero constant, | |
4927 | i.e. #0.0 or #0. */ | |
4928 | ||
4929 | static bfd_boolean | |
4930 | parse_ifimm_zero (char **in) | |
4931 | { | |
4932 | int error_code; | |
4933 | ||
4934 | if (!is_immediate_prefix (**in)) | |
4935 | return FALSE; | |
4936 | ||
4937 | ++*in; | |
0900a05b JW |
4938 | |
4939 | /* Accept #0x0 as a synonym for #0. */ | |
4940 | if (strncmp (*in, "0x", 2) == 0) | |
4941 | { | |
4942 | int val; | |
4943 | if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL) | |
4944 | return FALSE; | |
4945 | return TRUE; | |
4946 | } | |
4947 | ||
aacf0b33 KT |
4948 | error_code = atof_generic (in, ".", EXP_CHARS, |
4949 | &generic_floating_point_number); | |
4950 | ||
4951 | if (!error_code | |
4952 | && generic_floating_point_number.sign == '+' | |
4953 | && (generic_floating_point_number.low | |
4954 | > generic_floating_point_number.leader)) | |
4955 | return TRUE; | |
4956 | ||
4957 | return FALSE; | |
4958 | } | |
4959 | ||
136da414 JB |
4960 | /* Parse an 8-bit "quarter-precision" floating point number of the form: |
4961 | 0baBbbbbbc defgh000 00000000 00000000. | |
c96612cc JB |
4962 | The zero and minus-zero cases need special handling, since they can't be |
4963 | encoded in the "quarter-precision" float format, but can nonetheless be | |
4964 | loaded as integer constants. */ | |
136da414 JB |
4965 | |
4966 | static unsigned | |
4967 | parse_qfloat_immediate (char **ccp, int *immed) | |
4968 | { | |
4969 | char *str = *ccp; | |
c96612cc | 4970 | char *fpnum; |
136da414 | 4971 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
c96612cc | 4972 | int found_fpchar = 0; |
5f4273c7 | 4973 | |
136da414 | 4974 | skip_past_char (&str, '#'); |
5f4273c7 | 4975 | |
c96612cc JB |
4976 | /* We must not accidentally parse an integer as a floating-point number. Make |
4977 | sure that the value we parse is not an integer by checking for special | |
4978 | characters '.' or 'e'. | |
4979 | FIXME: This is a horrible hack, but doing better is tricky because type | |
4980 | information isn't in a very usable state at parse time. */ | |
4981 | fpnum = str; | |
4982 | skip_whitespace (fpnum); | |
4983 | ||
4984 | if (strncmp (fpnum, "0x", 2) == 0) | |
4985 | return FAIL; | |
4986 | else | |
4987 | { | |
4988 | for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++) | |
477330fc RM |
4989 | if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E') |
4990 | { | |
4991 | found_fpchar = 1; | |
4992 | break; | |
4993 | } | |
c96612cc JB |
4994 | |
4995 | if (!found_fpchar) | |
477330fc | 4996 | return FAIL; |
c96612cc | 4997 | } |
5f4273c7 | 4998 | |
136da414 JB |
4999 | if ((str = atof_ieee (str, 's', words)) != NULL) |
5000 | { | |
5001 | unsigned fpword = 0; | |
5002 | int i; | |
5f4273c7 | 5003 | |
136da414 JB |
5004 | /* Our FP word must be 32 bits (single-precision FP). */ |
5005 | for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++) | |
477330fc RM |
5006 | { |
5007 | fpword <<= LITTLENUM_NUMBER_OF_BITS; | |
5008 | fpword |= words[i]; | |
5009 | } | |
5f4273c7 | 5010 | |
c96612cc | 5011 | if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0) |
477330fc | 5012 | *immed = fpword; |
136da414 | 5013 | else |
477330fc | 5014 | return FAIL; |
136da414 JB |
5015 | |
5016 | *ccp = str; | |
5f4273c7 | 5017 | |
136da414 JB |
5018 | return SUCCESS; |
5019 | } | |
5f4273c7 | 5020 | |
136da414 JB |
5021 | return FAIL; |
5022 | } | |
5023 | ||
c19d1205 ZW |
5024 | /* Shift operands. */ |
5025 | enum shift_kind | |
b99bd4ef | 5026 | { |
c19d1205 ZW |
5027 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
5028 | }; | |
b99bd4ef | 5029 | |
c19d1205 ZW |
5030 | struct asm_shift_name |
5031 | { | |
5032 | const char *name; | |
5033 | enum shift_kind kind; | |
5034 | }; | |
b99bd4ef | 5035 | |
c19d1205 ZW |
5036 | /* Third argument to parse_shift. */ |
5037 | enum parse_shift_mode | |
5038 | { | |
5039 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
5040 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
5041 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
5042 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
5043 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
5044 | }; | |
b99bd4ef | 5045 | |
c19d1205 ZW |
5046 | /* Parse a <shift> specifier on an ARM data processing instruction. |
5047 | This has three forms: | |
b99bd4ef | 5048 | |
c19d1205 ZW |
5049 | (LSL|LSR|ASL|ASR|ROR) Rs |
5050 | (LSL|LSR|ASL|ASR|ROR) #imm | |
5051 | RRX | |
b99bd4ef | 5052 | |
c19d1205 ZW |
5053 | Note that ASL is assimilated to LSL in the instruction encoding, and |
5054 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 5055 | |
c19d1205 ZW |
5056 | static int |
5057 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 5058 | { |
c19d1205 ZW |
5059 | const struct asm_shift_name *shift_name; |
5060 | enum shift_kind shift; | |
5061 | char *s = *str; | |
5062 | char *p = s; | |
5063 | int reg; | |
b99bd4ef | 5064 | |
c19d1205 ZW |
5065 | for (p = *str; ISALPHA (*p); p++) |
5066 | ; | |
b99bd4ef | 5067 | |
c19d1205 | 5068 | if (p == *str) |
b99bd4ef | 5069 | { |
c19d1205 ZW |
5070 | inst.error = _("shift expression expected"); |
5071 | return FAIL; | |
b99bd4ef NC |
5072 | } |
5073 | ||
21d799b5 | 5074 | shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str, |
477330fc | 5075 | p - *str); |
c19d1205 ZW |
5076 | |
5077 | if (shift_name == NULL) | |
b99bd4ef | 5078 | { |
c19d1205 ZW |
5079 | inst.error = _("shift expression expected"); |
5080 | return FAIL; | |
b99bd4ef NC |
5081 | } |
5082 | ||
c19d1205 | 5083 | shift = shift_name->kind; |
b99bd4ef | 5084 | |
c19d1205 ZW |
5085 | switch (mode) |
5086 | { | |
5087 | case NO_SHIFT_RESTRICT: | |
5088 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 5089 | |
c19d1205 ZW |
5090 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
5091 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
5092 | { | |
5093 | inst.error = _("'LSL' or 'ASR' required"); | |
5094 | return FAIL; | |
5095 | } | |
5096 | break; | |
b99bd4ef | 5097 | |
c19d1205 ZW |
5098 | case SHIFT_LSL_IMMEDIATE: |
5099 | if (shift != SHIFT_LSL) | |
5100 | { | |
5101 | inst.error = _("'LSL' required"); | |
5102 | return FAIL; | |
5103 | } | |
5104 | break; | |
b99bd4ef | 5105 | |
c19d1205 ZW |
5106 | case SHIFT_ASR_IMMEDIATE: |
5107 | if (shift != SHIFT_ASR) | |
5108 | { | |
5109 | inst.error = _("'ASR' required"); | |
5110 | return FAIL; | |
5111 | } | |
5112 | break; | |
b99bd4ef | 5113 | |
c19d1205 ZW |
5114 | default: abort (); |
5115 | } | |
b99bd4ef | 5116 | |
c19d1205 ZW |
5117 | if (shift != SHIFT_RRX) |
5118 | { | |
5119 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
5120 | skip_whitespace (p); | |
b99bd4ef | 5121 | |
c19d1205 | 5122 | if (mode == NO_SHIFT_RESTRICT |
dcbf9037 | 5123 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5124 | { |
5125 | inst.operands[i].imm = reg; | |
5126 | inst.operands[i].immisreg = 1; | |
5127 | } | |
5128 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5129 | return FAIL; | |
5130 | } | |
5131 | inst.operands[i].shift_kind = shift; | |
5132 | inst.operands[i].shifted = 1; | |
5133 | *str = p; | |
5134 | return SUCCESS; | |
b99bd4ef NC |
5135 | } |
5136 | ||
c19d1205 | 5137 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 5138 | |
c19d1205 ZW |
5139 | #<immediate> |
5140 | #<immediate>, <rotate> | |
5141 | <Rm> | |
5142 | <Rm>, <shift> | |
b99bd4ef | 5143 | |
c19d1205 ZW |
5144 | where <shift> is defined by parse_shift above, and <rotate> is a |
5145 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 5146 | is deferred to md_apply_fix. */ |
b99bd4ef | 5147 | |
c19d1205 ZW |
5148 | static int |
5149 | parse_shifter_operand (char **str, int i) | |
5150 | { | |
5151 | int value; | |
91d6fa6a | 5152 | expressionS exp; |
b99bd4ef | 5153 | |
dcbf9037 | 5154 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
c19d1205 ZW |
5155 | { |
5156 | inst.operands[i].reg = value; | |
5157 | inst.operands[i].isreg = 1; | |
b99bd4ef | 5158 | |
c19d1205 ZW |
5159 | /* parse_shift will override this if appropriate */ |
5160 | inst.reloc.exp.X_op = O_constant; | |
5161 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 5162 | |
c19d1205 ZW |
5163 | if (skip_past_comma (str) == FAIL) |
5164 | return SUCCESS; | |
b99bd4ef | 5165 | |
c19d1205 ZW |
5166 | /* Shift operation on register. */ |
5167 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
5168 | } |
5169 | ||
c19d1205 ZW |
5170 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
5171 | return FAIL; | |
b99bd4ef | 5172 | |
c19d1205 | 5173 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 5174 | { |
c19d1205 | 5175 | /* #x, y -- ie explicit rotation by Y. */ |
91d6fa6a | 5176 | if (my_get_expression (&exp, str, GE_NO_PREFIX)) |
c19d1205 | 5177 | return FAIL; |
b99bd4ef | 5178 | |
91d6fa6a | 5179 | if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
c19d1205 ZW |
5180 | { |
5181 | inst.error = _("constant expression expected"); | |
5182 | return FAIL; | |
5183 | } | |
b99bd4ef | 5184 | |
91d6fa6a | 5185 | value = exp.X_add_number; |
c19d1205 ZW |
5186 | if (value < 0 || value > 30 || value % 2 != 0) |
5187 | { | |
5188 | inst.error = _("invalid rotation"); | |
5189 | return FAIL; | |
5190 | } | |
5191 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
5192 | { | |
5193 | inst.error = _("invalid constant"); | |
5194 | return FAIL; | |
5195 | } | |
09d92015 | 5196 | |
a415b1cd JB |
5197 | /* Encode as specified. */ |
5198 | inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7; | |
5199 | return SUCCESS; | |
09d92015 MM |
5200 | } |
5201 | ||
c19d1205 ZW |
5202 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
5203 | inst.reloc.pc_rel = 0; | |
5204 | return SUCCESS; | |
09d92015 MM |
5205 | } |
5206 | ||
4962c51a MS |
5207 | /* Group relocation information. Each entry in the table contains the |
5208 | textual name of the relocation as may appear in assembler source | |
5209 | and must end with a colon. | |
5210 | Along with this textual name are the relocation codes to be used if | |
5211 | the corresponding instruction is an ALU instruction (ADD or SUB only), | |
5212 | an LDR, an LDRS, or an LDC. */ | |
5213 | ||
5214 | struct group_reloc_table_entry | |
5215 | { | |
5216 | const char *name; | |
5217 | int alu_code; | |
5218 | int ldr_code; | |
5219 | int ldrs_code; | |
5220 | int ldc_code; | |
5221 | }; | |
5222 | ||
5223 | typedef enum | |
5224 | { | |
5225 | /* Varieties of non-ALU group relocation. */ | |
5226 | ||
5227 | GROUP_LDR, | |
5228 | GROUP_LDRS, | |
5229 | GROUP_LDC | |
5230 | } group_reloc_type; | |
5231 | ||
5232 | static struct group_reloc_table_entry group_reloc_table[] = | |
5233 | { /* Program counter relative: */ | |
5234 | { "pc_g0_nc", | |
5235 | BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */ | |
5236 | 0, /* LDR */ | |
5237 | 0, /* LDRS */ | |
5238 | 0 }, /* LDC */ | |
5239 | { "pc_g0", | |
5240 | BFD_RELOC_ARM_ALU_PC_G0, /* ALU */ | |
5241 | BFD_RELOC_ARM_LDR_PC_G0, /* LDR */ | |
5242 | BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */ | |
5243 | BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */ | |
5244 | { "pc_g1_nc", | |
5245 | BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */ | |
5246 | 0, /* LDR */ | |
5247 | 0, /* LDRS */ | |
5248 | 0 }, /* LDC */ | |
5249 | { "pc_g1", | |
5250 | BFD_RELOC_ARM_ALU_PC_G1, /* ALU */ | |
5251 | BFD_RELOC_ARM_LDR_PC_G1, /* LDR */ | |
5252 | BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */ | |
5253 | BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */ | |
5254 | { "pc_g2", | |
5255 | BFD_RELOC_ARM_ALU_PC_G2, /* ALU */ | |
5256 | BFD_RELOC_ARM_LDR_PC_G2, /* LDR */ | |
5257 | BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */ | |
5258 | BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */ | |
5259 | /* Section base relative */ | |
5260 | { "sb_g0_nc", | |
5261 | BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */ | |
5262 | 0, /* LDR */ | |
5263 | 0, /* LDRS */ | |
5264 | 0 }, /* LDC */ | |
5265 | { "sb_g0", | |
5266 | BFD_RELOC_ARM_ALU_SB_G0, /* ALU */ | |
5267 | BFD_RELOC_ARM_LDR_SB_G0, /* LDR */ | |
5268 | BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */ | |
5269 | BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */ | |
5270 | { "sb_g1_nc", | |
5271 | BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */ | |
5272 | 0, /* LDR */ | |
5273 | 0, /* LDRS */ | |
5274 | 0 }, /* LDC */ | |
5275 | { "sb_g1", | |
5276 | BFD_RELOC_ARM_ALU_SB_G1, /* ALU */ | |
5277 | BFD_RELOC_ARM_LDR_SB_G1, /* LDR */ | |
5278 | BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */ | |
5279 | BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */ | |
5280 | { "sb_g2", | |
5281 | BFD_RELOC_ARM_ALU_SB_G2, /* ALU */ | |
5282 | BFD_RELOC_ARM_LDR_SB_G2, /* LDR */ | |
5283 | BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */ | |
72d98d16 MG |
5284 | BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */ |
5285 | /* Absolute thumb alu relocations. */ | |
5286 | { "lower0_7", | |
5287 | BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */ | |
5288 | 0, /* LDR. */ | |
5289 | 0, /* LDRS. */ | |
5290 | 0 }, /* LDC. */ | |
5291 | { "lower8_15", | |
5292 | BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */ | |
5293 | 0, /* LDR. */ | |
5294 | 0, /* LDRS. */ | |
5295 | 0 }, /* LDC. */ | |
5296 | { "upper0_7", | |
5297 | BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */ | |
5298 | 0, /* LDR. */ | |
5299 | 0, /* LDRS. */ | |
5300 | 0 }, /* LDC. */ | |
5301 | { "upper8_15", | |
5302 | BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */ | |
5303 | 0, /* LDR. */ | |
5304 | 0, /* LDRS. */ | |
5305 | 0 } }; /* LDC. */ | |
4962c51a MS |
5306 | |
5307 | /* Given the address of a pointer pointing to the textual name of a group | |
5308 | relocation as may appear in assembler source, attempt to find its details | |
5309 | in group_reloc_table. The pointer will be updated to the character after | |
5310 | the trailing colon. On failure, FAIL will be returned; SUCCESS | |
5311 | otherwise. On success, *entry will be updated to point at the relevant | |
5312 | group_reloc_table entry. */ | |
5313 | ||
5314 | static int | |
5315 | find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out) | |
5316 | { | |
5317 | unsigned int i; | |
5318 | for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++) | |
5319 | { | |
5320 | int length = strlen (group_reloc_table[i].name); | |
5321 | ||
5f4273c7 NC |
5322 | if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 |
5323 | && (*str)[length] == ':') | |
477330fc RM |
5324 | { |
5325 | *out = &group_reloc_table[i]; | |
5326 | *str += (length + 1); | |
5327 | return SUCCESS; | |
5328 | } | |
4962c51a MS |
5329 | } |
5330 | ||
5331 | return FAIL; | |
5332 | } | |
5333 | ||
5334 | /* Parse a <shifter_operand> for an ARM data processing instruction | |
5335 | (as for parse_shifter_operand) where group relocations are allowed: | |
5336 | ||
5337 | #<immediate> | |
5338 | #<immediate>, <rotate> | |
5339 | #:<group_reloc>:<expression> | |
5340 | <Rm> | |
5341 | <Rm>, <shift> | |
5342 | ||
5343 | where <group_reloc> is one of the strings defined in group_reloc_table. | |
5344 | The hashes are optional. | |
5345 | ||
5346 | Everything else is as for parse_shifter_operand. */ | |
5347 | ||
5348 | static parse_operand_result | |
5349 | parse_shifter_operand_group_reloc (char **str, int i) | |
5350 | { | |
5351 | /* Determine if we have the sequence of characters #: or just : | |
5352 | coming next. If we do, then we check for a group relocation. | |
5353 | If we don't, punt the whole lot to parse_shifter_operand. */ | |
5354 | ||
5355 | if (((*str)[0] == '#' && (*str)[1] == ':') | |
5356 | || (*str)[0] == ':') | |
5357 | { | |
5358 | struct group_reloc_table_entry *entry; | |
5359 | ||
5360 | if ((*str)[0] == '#') | |
477330fc | 5361 | (*str) += 2; |
4962c51a | 5362 | else |
477330fc | 5363 | (*str)++; |
4962c51a MS |
5364 | |
5365 | /* Try to parse a group relocation. Anything else is an error. */ | |
5366 | if (find_group_reloc_table_entry (str, &entry) == FAIL) | |
477330fc RM |
5367 | { |
5368 | inst.error = _("unknown group relocation"); | |
5369 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5370 | } | |
4962c51a MS |
5371 | |
5372 | /* We now have the group relocation table entry corresponding to | |
477330fc | 5373 | the name in the assembler source. Next, we parse the expression. */ |
4962c51a | 5374 | if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX)) |
477330fc | 5375 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; |
4962c51a MS |
5376 | |
5377 | /* Record the relocation type (always the ALU variant here). */ | |
21d799b5 | 5378 | inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code; |
9c2799c2 | 5379 | gas_assert (inst.reloc.type != 0); |
4962c51a MS |
5380 | |
5381 | return PARSE_OPERAND_SUCCESS; | |
5382 | } | |
5383 | else | |
5384 | return parse_shifter_operand (str, i) == SUCCESS | |
477330fc | 5385 | ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL; |
4962c51a MS |
5386 | |
5387 | /* Never reached. */ | |
5388 | } | |
5389 | ||
8e560766 MGD |
5390 | /* Parse a Neon alignment expression. Information is written to |
5391 | inst.operands[i]. We assume the initial ':' has been skipped. | |
fa94de6b | 5392 | |
8e560766 MGD |
5393 | align .imm = align << 8, .immisalign=1, .preind=0 */ |
5394 | static parse_operand_result | |
5395 | parse_neon_alignment (char **str, int i) | |
5396 | { | |
5397 | char *p = *str; | |
5398 | expressionS exp; | |
5399 | ||
5400 | my_get_expression (&exp, &p, GE_NO_PREFIX); | |
5401 | ||
5402 | if (exp.X_op != O_constant) | |
5403 | { | |
5404 | inst.error = _("alignment must be constant"); | |
5405 | return PARSE_OPERAND_FAIL; | |
5406 | } | |
5407 | ||
5408 | inst.operands[i].imm = exp.X_add_number << 8; | |
5409 | inst.operands[i].immisalign = 1; | |
5410 | /* Alignments are not pre-indexes. */ | |
5411 | inst.operands[i].preind = 0; | |
5412 | ||
5413 | *str = p; | |
5414 | return PARSE_OPERAND_SUCCESS; | |
5415 | } | |
5416 | ||
c19d1205 ZW |
5417 | /* Parse all forms of an ARM address expression. Information is written |
5418 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 5419 | |
c19d1205 | 5420 | Preindexed addressing (.preind=1): |
09d92015 | 5421 | |
c19d1205 ZW |
5422 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
5423 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5424 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5425 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5426 | |
c19d1205 | 5427 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 5428 | |
c19d1205 | 5429 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 5430 | |
c19d1205 ZW |
5431 | [Rn], #offset .reg=Rn .reloc.exp=offset |
5432 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5433 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
5434 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 5435 | |
c19d1205 | 5436 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 5437 | |
c19d1205 | 5438 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 5439 | |
c19d1205 | 5440 | Other: |
09d92015 | 5441 | |
c19d1205 ZW |
5442 | [Rn]{!} shorthand for [Rn,#0]{!} |
5443 | =immediate .isreg=0 .reloc.exp=immediate | |
5444 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 5445 | |
c19d1205 ZW |
5446 | It is the caller's responsibility to check for addressing modes not |
5447 | supported by the instruction, and to set inst.reloc.type. */ | |
5448 | ||
4962c51a MS |
5449 | static parse_operand_result |
5450 | parse_address_main (char **str, int i, int group_relocations, | |
477330fc | 5451 | group_reloc_type group_type) |
09d92015 | 5452 | { |
c19d1205 ZW |
5453 | char *p = *str; |
5454 | int reg; | |
09d92015 | 5455 | |
c19d1205 | 5456 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 5457 | { |
c19d1205 ZW |
5458 | if (skip_past_char (&p, '=') == FAIL) |
5459 | { | |
974da60d | 5460 | /* Bare address - translate to PC-relative offset. */ |
c19d1205 ZW |
5461 | inst.reloc.pc_rel = 1; |
5462 | inst.operands[i].reg = REG_PC; | |
5463 | inst.operands[i].isreg = 1; | |
5464 | inst.operands[i].preind = 1; | |
09d92015 | 5465 | |
8335d6aa JW |
5466 | if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG)) |
5467 | return PARSE_OPERAND_FAIL; | |
5468 | } | |
5469 | else if (parse_big_immediate (&p, i, &inst.reloc.exp, | |
5470 | /*allow_symbol_p=*/TRUE)) | |
4962c51a | 5471 | return PARSE_OPERAND_FAIL; |
09d92015 | 5472 | |
c19d1205 | 5473 | *str = p; |
4962c51a | 5474 | return PARSE_OPERAND_SUCCESS; |
09d92015 MM |
5475 | } |
5476 | ||
8ab8155f NC |
5477 | /* PR gas/14887: Allow for whitespace after the opening bracket. */ |
5478 | skip_whitespace (p); | |
5479 | ||
dcbf9037 | 5480 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 5481 | { |
c19d1205 | 5482 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
4962c51a | 5483 | return PARSE_OPERAND_FAIL; |
09d92015 | 5484 | } |
c19d1205 ZW |
5485 | inst.operands[i].reg = reg; |
5486 | inst.operands[i].isreg = 1; | |
09d92015 | 5487 | |
c19d1205 | 5488 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5489 | { |
c19d1205 | 5490 | inst.operands[i].preind = 1; |
09d92015 | 5491 | |
c19d1205 ZW |
5492 | if (*p == '+') p++; |
5493 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
5494 | ||
dcbf9037 | 5495 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
09d92015 | 5496 | { |
c19d1205 ZW |
5497 | inst.operands[i].imm = reg; |
5498 | inst.operands[i].immisreg = 1; | |
5499 | ||
5500 | if (skip_past_comma (&p) == SUCCESS) | |
5501 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5502 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5503 | } |
5287ad62 | 5504 | else if (skip_past_char (&p, ':') == SUCCESS) |
8e560766 MGD |
5505 | { |
5506 | /* FIXME: '@' should be used here, but it's filtered out by generic | |
5507 | code before we get to see it here. This may be subject to | |
5508 | change. */ | |
5509 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5510 | |
8e560766 MGD |
5511 | if (result != PARSE_OPERAND_SUCCESS) |
5512 | return result; | |
5513 | } | |
c19d1205 ZW |
5514 | else |
5515 | { | |
5516 | if (inst.operands[i].negative) | |
5517 | { | |
5518 | inst.operands[i].negative = 0; | |
5519 | p--; | |
5520 | } | |
4962c51a | 5521 | |
5f4273c7 NC |
5522 | if (group_relocations |
5523 | && ((*p == '#' && *(p + 1) == ':') || *p == ':')) | |
4962c51a MS |
5524 | { |
5525 | struct group_reloc_table_entry *entry; | |
5526 | ||
477330fc RM |
5527 | /* Skip over the #: or : sequence. */ |
5528 | if (*p == '#') | |
5529 | p += 2; | |
5530 | else | |
5531 | p++; | |
4962c51a MS |
5532 | |
5533 | /* Try to parse a group relocation. Anything else is an | |
477330fc | 5534 | error. */ |
4962c51a MS |
5535 | if (find_group_reloc_table_entry (&p, &entry) == FAIL) |
5536 | { | |
5537 | inst.error = _("unknown group relocation"); | |
5538 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5539 | } | |
5540 | ||
5541 | /* We now have the group relocation table entry corresponding to | |
5542 | the name in the assembler source. Next, we parse the | |
477330fc | 5543 | expression. */ |
4962c51a MS |
5544 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
5545 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5546 | ||
5547 | /* Record the relocation type. */ | |
477330fc RM |
5548 | switch (group_type) |
5549 | { | |
5550 | case GROUP_LDR: | |
5551 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code; | |
5552 | break; | |
4962c51a | 5553 | |
477330fc RM |
5554 | case GROUP_LDRS: |
5555 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code; | |
5556 | break; | |
4962c51a | 5557 | |
477330fc RM |
5558 | case GROUP_LDC: |
5559 | inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code; | |
5560 | break; | |
4962c51a | 5561 | |
477330fc RM |
5562 | default: |
5563 | gas_assert (0); | |
5564 | } | |
4962c51a | 5565 | |
477330fc | 5566 | if (inst.reloc.type == 0) |
4962c51a MS |
5567 | { |
5568 | inst.error = _("this group relocation is not allowed on this instruction"); | |
5569 | return PARSE_OPERAND_FAIL_NO_BACKTRACK; | |
5570 | } | |
477330fc RM |
5571 | } |
5572 | else | |
26d97720 NS |
5573 | { |
5574 | char *q = p; | |
5575 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
5576 | return PARSE_OPERAND_FAIL; | |
5577 | /* If the offset is 0, find out if it's a +0 or -0. */ | |
5578 | if (inst.reloc.exp.X_op == O_constant | |
5579 | && inst.reloc.exp.X_add_number == 0) | |
5580 | { | |
5581 | skip_whitespace (q); | |
5582 | if (*q == '#') | |
5583 | { | |
5584 | q++; | |
5585 | skip_whitespace (q); | |
5586 | } | |
5587 | if (*q == '-') | |
5588 | inst.operands[i].negative = 1; | |
5589 | } | |
5590 | } | |
09d92015 MM |
5591 | } |
5592 | } | |
8e560766 MGD |
5593 | else if (skip_past_char (&p, ':') == SUCCESS) |
5594 | { | |
5595 | /* FIXME: '@' should be used here, but it's filtered out by generic code | |
5596 | before we get to see it here. This may be subject to change. */ | |
5597 | parse_operand_result result = parse_neon_alignment (&p, i); | |
fa94de6b | 5598 | |
8e560766 MGD |
5599 | if (result != PARSE_OPERAND_SUCCESS) |
5600 | return result; | |
5601 | } | |
09d92015 | 5602 | |
c19d1205 | 5603 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 5604 | { |
c19d1205 | 5605 | inst.error = _("']' expected"); |
4962c51a | 5606 | return PARSE_OPERAND_FAIL; |
09d92015 MM |
5607 | } |
5608 | ||
c19d1205 ZW |
5609 | if (skip_past_char (&p, '!') == SUCCESS) |
5610 | inst.operands[i].writeback = 1; | |
09d92015 | 5611 | |
c19d1205 | 5612 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 5613 | { |
c19d1205 ZW |
5614 | if (skip_past_char (&p, '{') == SUCCESS) |
5615 | { | |
5616 | /* [Rn], {expr} - unindexed, with option */ | |
5617 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 5618 | 0, 255, TRUE) == FAIL) |
4962c51a | 5619 | return PARSE_OPERAND_FAIL; |
09d92015 | 5620 | |
c19d1205 ZW |
5621 | if (skip_past_char (&p, '}') == FAIL) |
5622 | { | |
5623 | inst.error = _("'}' expected at end of 'option' field"); | |
4962c51a | 5624 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5625 | } |
5626 | if (inst.operands[i].preind) | |
5627 | { | |
5628 | inst.error = _("cannot combine index with option"); | |
4962c51a | 5629 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5630 | } |
5631 | *str = p; | |
4962c51a | 5632 | return PARSE_OPERAND_SUCCESS; |
09d92015 | 5633 | } |
c19d1205 ZW |
5634 | else |
5635 | { | |
5636 | inst.operands[i].postind = 1; | |
5637 | inst.operands[i].writeback = 1; | |
09d92015 | 5638 | |
c19d1205 ZW |
5639 | if (inst.operands[i].preind) |
5640 | { | |
5641 | inst.error = _("cannot combine pre- and post-indexing"); | |
4962c51a | 5642 | return PARSE_OPERAND_FAIL; |
c19d1205 | 5643 | } |
09d92015 | 5644 | |
c19d1205 ZW |
5645 | if (*p == '+') p++; |
5646 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 5647 | |
dcbf9037 | 5648 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
c19d1205 | 5649 | { |
477330fc RM |
5650 | /* We might be using the immediate for alignment already. If we |
5651 | are, OR the register number into the low-order bits. */ | |
5652 | if (inst.operands[i].immisalign) | |
5653 | inst.operands[i].imm |= reg; | |
5654 | else | |
5655 | inst.operands[i].imm = reg; | |
c19d1205 | 5656 | inst.operands[i].immisreg = 1; |
a737bd4d | 5657 | |
c19d1205 ZW |
5658 | if (skip_past_comma (&p) == SUCCESS) |
5659 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
4962c51a | 5660 | return PARSE_OPERAND_FAIL; |
c19d1205 ZW |
5661 | } |
5662 | else | |
5663 | { | |
26d97720 | 5664 | char *q = p; |
c19d1205 ZW |
5665 | if (inst.operands[i].negative) |
5666 | { | |
5667 | inst.operands[i].negative = 0; | |
5668 | p--; | |
5669 | } | |
5670 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
4962c51a | 5671 | return PARSE_OPERAND_FAIL; |
26d97720 NS |
5672 | /* If the offset is 0, find out if it's a +0 or -0. */ |
5673 | if (inst.reloc.exp.X_op == O_constant | |
5674 | && inst.reloc.exp.X_add_number == 0) | |
5675 | { | |
5676 | skip_whitespace (q); | |
5677 | if (*q == '#') | |
5678 | { | |
5679 | q++; | |
5680 | skip_whitespace (q); | |
5681 | } | |
5682 | if (*q == '-') | |
5683 | inst.operands[i].negative = 1; | |
5684 | } | |
c19d1205 ZW |
5685 | } |
5686 | } | |
a737bd4d NC |
5687 | } |
5688 | ||
c19d1205 ZW |
5689 | /* If at this point neither .preind nor .postind is set, we have a |
5690 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
5691 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
5692 | { | |
5693 | inst.operands[i].preind = 1; | |
5694 | inst.reloc.exp.X_op = O_constant; | |
5695 | inst.reloc.exp.X_add_number = 0; | |
5696 | } | |
5697 | *str = p; | |
4962c51a MS |
5698 | return PARSE_OPERAND_SUCCESS; |
5699 | } | |
5700 | ||
5701 | static int | |
5702 | parse_address (char **str, int i) | |
5703 | { | |
21d799b5 | 5704 | return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS |
477330fc | 5705 | ? SUCCESS : FAIL; |
4962c51a MS |
5706 | } |
5707 | ||
5708 | static parse_operand_result | |
5709 | parse_address_group_reloc (char **str, int i, group_reloc_type type) | |
5710 | { | |
5711 | return parse_address_main (str, i, 1, type); | |
a737bd4d NC |
5712 | } |
5713 | ||
b6895b4f PB |
5714 | /* Parse an operand for a MOVW or MOVT instruction. */ |
5715 | static int | |
5716 | parse_half (char **str) | |
5717 | { | |
5718 | char * p; | |
5f4273c7 | 5719 | |
b6895b4f PB |
5720 | p = *str; |
5721 | skip_past_char (&p, '#'); | |
5f4273c7 | 5722 | if (strncasecmp (p, ":lower16:", 9) == 0) |
b6895b4f PB |
5723 | inst.reloc.type = BFD_RELOC_ARM_MOVW; |
5724 | else if (strncasecmp (p, ":upper16:", 9) == 0) | |
5725 | inst.reloc.type = BFD_RELOC_ARM_MOVT; | |
5726 | ||
5727 | if (inst.reloc.type != BFD_RELOC_UNUSED) | |
5728 | { | |
5729 | p += 9; | |
5f4273c7 | 5730 | skip_whitespace (p); |
b6895b4f PB |
5731 | } |
5732 | ||
5733 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) | |
5734 | return FAIL; | |
5735 | ||
5736 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
5737 | { | |
5738 | if (inst.reloc.exp.X_op != O_constant) | |
5739 | { | |
5740 | inst.error = _("constant expression expected"); | |
5741 | return FAIL; | |
5742 | } | |
5743 | if (inst.reloc.exp.X_add_number < 0 | |
5744 | || inst.reloc.exp.X_add_number > 0xffff) | |
5745 | { | |
5746 | inst.error = _("immediate value out of range"); | |
5747 | return FAIL; | |
5748 | } | |
5749 | } | |
5750 | *str = p; | |
5751 | return SUCCESS; | |
5752 | } | |
5753 | ||
c19d1205 | 5754 | /* Miscellaneous. */ |
a737bd4d | 5755 | |
c19d1205 ZW |
5756 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
5757 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
5758 | static int | |
d2cd1205 | 5759 | parse_psr (char **str, bfd_boolean lhs) |
09d92015 | 5760 | { |
c19d1205 ZW |
5761 | char *p; |
5762 | unsigned long psr_field; | |
62b3e311 PB |
5763 | const struct asm_psr *psr; |
5764 | char *start; | |
d2cd1205 | 5765 | bfd_boolean is_apsr = FALSE; |
ac7f631b | 5766 | bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m); |
09d92015 | 5767 | |
a4482bb6 NC |
5768 | /* PR gas/12698: If the user has specified -march=all then m_profile will |
5769 | be TRUE, but we want to ignore it in this case as we are building for any | |
5770 | CPU type, including non-m variants. */ | |
823d2571 | 5771 | if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) |
a4482bb6 NC |
5772 | m_profile = FALSE; |
5773 | ||
c19d1205 ZW |
5774 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
5775 | feature for ease of use and backwards compatibility. */ | |
5776 | p = *str; | |
62b3e311 | 5777 | if (strncasecmp (p, "SPSR", 4) == 0) |
d2cd1205 JB |
5778 | { |
5779 | if (m_profile) | |
5780 | goto unsupported_psr; | |
fa94de6b | 5781 | |
d2cd1205 JB |
5782 | psr_field = SPSR_BIT; |
5783 | } | |
5784 | else if (strncasecmp (p, "CPSR", 4) == 0) | |
5785 | { | |
5786 | if (m_profile) | |
5787 | goto unsupported_psr; | |
5788 | ||
5789 | psr_field = 0; | |
5790 | } | |
5791 | else if (strncasecmp (p, "APSR", 4) == 0) | |
5792 | { | |
5793 | /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A | |
5794 | and ARMv7-R architecture CPUs. */ | |
5795 | is_apsr = TRUE; | |
5796 | psr_field = 0; | |
5797 | } | |
5798 | else if (m_profile) | |
62b3e311 PB |
5799 | { |
5800 | start = p; | |
5801 | do | |
5802 | p++; | |
5803 | while (ISALNUM (*p) || *p == '_'); | |
5804 | ||
d2cd1205 JB |
5805 | if (strncasecmp (start, "iapsr", 5) == 0 |
5806 | || strncasecmp (start, "eapsr", 5) == 0 | |
5807 | || strncasecmp (start, "xpsr", 4) == 0 | |
5808 | || strncasecmp (start, "psr", 3) == 0) | |
5809 | p = start + strcspn (start, "rR") + 1; | |
5810 | ||
21d799b5 | 5811 | psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start, |
477330fc | 5812 | p - start); |
d2cd1205 | 5813 | |
62b3e311 PB |
5814 | if (!psr) |
5815 | return FAIL; | |
09d92015 | 5816 | |
d2cd1205 JB |
5817 | /* If APSR is being written, a bitfield may be specified. Note that |
5818 | APSR itself is handled above. */ | |
5819 | if (psr->field <= 3) | |
5820 | { | |
5821 | psr_field = psr->field; | |
5822 | is_apsr = TRUE; | |
5823 | goto check_suffix; | |
5824 | } | |
5825 | ||
62b3e311 | 5826 | *str = p; |
d2cd1205 JB |
5827 | /* M-profile MSR instructions have the mask field set to "10", except |
5828 | *PSR variants which modify APSR, which may use a different mask (and | |
5829 | have been handled already). Do that by setting the PSR_f field | |
5830 | here. */ | |
5831 | return psr->field | (lhs ? PSR_f : 0); | |
62b3e311 | 5832 | } |
d2cd1205 JB |
5833 | else |
5834 | goto unsupported_psr; | |
09d92015 | 5835 | |
62b3e311 | 5836 | p += 4; |
d2cd1205 | 5837 | check_suffix: |
c19d1205 ZW |
5838 | if (*p == '_') |
5839 | { | |
5840 | /* A suffix follows. */ | |
c19d1205 ZW |
5841 | p++; |
5842 | start = p; | |
a737bd4d | 5843 | |
c19d1205 ZW |
5844 | do |
5845 | p++; | |
5846 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 5847 | |
d2cd1205 JB |
5848 | if (is_apsr) |
5849 | { | |
5850 | /* APSR uses a notation for bits, rather than fields. */ | |
5851 | unsigned int nzcvq_bits = 0; | |
5852 | unsigned int g_bit = 0; | |
5853 | char *bit; | |
fa94de6b | 5854 | |
d2cd1205 JB |
5855 | for (bit = start; bit != p; bit++) |
5856 | { | |
5857 | switch (TOLOWER (*bit)) | |
477330fc | 5858 | { |
d2cd1205 JB |
5859 | case 'n': |
5860 | nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01; | |
5861 | break; | |
5862 | ||
5863 | case 'z': | |
5864 | nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02; | |
5865 | break; | |
5866 | ||
5867 | case 'c': | |
5868 | nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04; | |
5869 | break; | |
5870 | ||
5871 | case 'v': | |
5872 | nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08; | |
5873 | break; | |
fa94de6b | 5874 | |
d2cd1205 JB |
5875 | case 'q': |
5876 | nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10; | |
5877 | break; | |
fa94de6b | 5878 | |
d2cd1205 JB |
5879 | case 'g': |
5880 | g_bit |= (g_bit & 0x1) ? 0x2 : 0x1; | |
5881 | break; | |
fa94de6b | 5882 | |
d2cd1205 JB |
5883 | default: |
5884 | inst.error = _("unexpected bit specified after APSR"); | |
5885 | return FAIL; | |
5886 | } | |
5887 | } | |
fa94de6b | 5888 | |
d2cd1205 JB |
5889 | if (nzcvq_bits == 0x1f) |
5890 | psr_field |= PSR_f; | |
fa94de6b | 5891 | |
d2cd1205 JB |
5892 | if (g_bit == 0x1) |
5893 | { | |
5894 | if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)) | |
477330fc | 5895 | { |
d2cd1205 JB |
5896 | inst.error = _("selected processor does not " |
5897 | "support DSP extension"); | |
5898 | return FAIL; | |
5899 | } | |
5900 | ||
5901 | psr_field |= PSR_s; | |
5902 | } | |
fa94de6b | 5903 | |
d2cd1205 JB |
5904 | if ((nzcvq_bits & 0x20) != 0 |
5905 | || (nzcvq_bits != 0x1f && nzcvq_bits != 0) | |
5906 | || (g_bit & 0x2) != 0) | |
5907 | { | |
5908 | inst.error = _("bad bitmask specified after APSR"); | |
5909 | return FAIL; | |
5910 | } | |
5911 | } | |
5912 | else | |
477330fc | 5913 | { |
d2cd1205 | 5914 | psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start, |
477330fc | 5915 | p - start); |
d2cd1205 | 5916 | if (!psr) |
477330fc | 5917 | goto error; |
a737bd4d | 5918 | |
d2cd1205 JB |
5919 | psr_field |= psr->field; |
5920 | } | |
a737bd4d | 5921 | } |
c19d1205 | 5922 | else |
a737bd4d | 5923 | { |
c19d1205 ZW |
5924 | if (ISALNUM (*p)) |
5925 | goto error; /* Garbage after "[CS]PSR". */ | |
5926 | ||
d2cd1205 | 5927 | /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This |
477330fc | 5928 | is deprecated, but allow it anyway. */ |
d2cd1205 JB |
5929 | if (is_apsr && lhs) |
5930 | { | |
5931 | psr_field |= PSR_f; | |
5932 | as_tsktsk (_("writing to APSR without specifying a bitmask is " | |
5933 | "deprecated")); | |
5934 | } | |
5935 | else if (!m_profile) | |
5936 | /* These bits are never right for M-profile devices: don't set them | |
5937 | (only code paths which read/write APSR reach here). */ | |
5938 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 5939 | } |
c19d1205 ZW |
5940 | *str = p; |
5941 | return psr_field; | |
a737bd4d | 5942 | |
d2cd1205 JB |
5943 | unsupported_psr: |
5944 | inst.error = _("selected processor does not support requested special " | |
5945 | "purpose register"); | |
5946 | return FAIL; | |
5947 | ||
c19d1205 ZW |
5948 | error: |
5949 | inst.error = _("flag for {c}psr instruction expected"); | |
5950 | return FAIL; | |
a737bd4d NC |
5951 | } |
5952 | ||
c19d1205 ZW |
5953 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
5954 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 5955 | |
c19d1205 ZW |
5956 | static int |
5957 | parse_cps_flags (char **str) | |
a737bd4d | 5958 | { |
c19d1205 ZW |
5959 | int val = 0; |
5960 | int saw_a_flag = 0; | |
5961 | char *s = *str; | |
a737bd4d | 5962 | |
c19d1205 ZW |
5963 | for (;;) |
5964 | switch (*s++) | |
5965 | { | |
5966 | case '\0': case ',': | |
5967 | goto done; | |
a737bd4d | 5968 | |
c19d1205 ZW |
5969 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
5970 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
5971 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 5972 | |
c19d1205 ZW |
5973 | default: |
5974 | inst.error = _("unrecognized CPS flag"); | |
5975 | return FAIL; | |
5976 | } | |
a737bd4d | 5977 | |
c19d1205 ZW |
5978 | done: |
5979 | if (saw_a_flag == 0) | |
a737bd4d | 5980 | { |
c19d1205 ZW |
5981 | inst.error = _("missing CPS flags"); |
5982 | return FAIL; | |
a737bd4d | 5983 | } |
a737bd4d | 5984 | |
c19d1205 ZW |
5985 | *str = s - 1; |
5986 | return val; | |
a737bd4d NC |
5987 | } |
5988 | ||
c19d1205 ZW |
5989 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
5990 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
5991 | |
5992 | static int | |
c19d1205 | 5993 | parse_endian_specifier (char **str) |
a737bd4d | 5994 | { |
c19d1205 ZW |
5995 | int little_endian; |
5996 | char *s = *str; | |
a737bd4d | 5997 | |
c19d1205 ZW |
5998 | if (strncasecmp (s, "BE", 2)) |
5999 | little_endian = 0; | |
6000 | else if (strncasecmp (s, "LE", 2)) | |
6001 | little_endian = 1; | |
6002 | else | |
a737bd4d | 6003 | { |
c19d1205 | 6004 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6005 | return FAIL; |
6006 | } | |
6007 | ||
c19d1205 | 6008 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 6009 | { |
c19d1205 | 6010 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
6011 | return FAIL; |
6012 | } | |
6013 | ||
c19d1205 ZW |
6014 | *str = s + 2; |
6015 | return little_endian; | |
6016 | } | |
a737bd4d | 6017 | |
c19d1205 ZW |
6018 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
6019 | value suitable for poking into the rotate field of an sxt or sxta | |
6020 | instruction, or FAIL on error. */ | |
6021 | ||
6022 | static int | |
6023 | parse_ror (char **str) | |
6024 | { | |
6025 | int rot; | |
6026 | char *s = *str; | |
6027 | ||
6028 | if (strncasecmp (s, "ROR", 3) == 0) | |
6029 | s += 3; | |
6030 | else | |
a737bd4d | 6031 | { |
c19d1205 | 6032 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
6033 | return FAIL; |
6034 | } | |
c19d1205 ZW |
6035 | |
6036 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
6037 | return FAIL; | |
6038 | ||
6039 | switch (rot) | |
a737bd4d | 6040 | { |
c19d1205 ZW |
6041 | case 0: *str = s; return 0x0; |
6042 | case 8: *str = s; return 0x1; | |
6043 | case 16: *str = s; return 0x2; | |
6044 | case 24: *str = s; return 0x3; | |
6045 | ||
6046 | default: | |
6047 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
6048 | return FAIL; |
6049 | } | |
c19d1205 | 6050 | } |
a737bd4d | 6051 | |
c19d1205 ZW |
6052 | /* Parse a conditional code (from conds[] below). The value returned is in the |
6053 | range 0 .. 14, or FAIL. */ | |
6054 | static int | |
6055 | parse_cond (char **str) | |
6056 | { | |
c462b453 | 6057 | char *q; |
c19d1205 | 6058 | const struct asm_cond *c; |
c462b453 PB |
6059 | int n; |
6060 | /* Condition codes are always 2 characters, so matching up to | |
6061 | 3 characters is sufficient. */ | |
6062 | char cond[3]; | |
a737bd4d | 6063 | |
c462b453 PB |
6064 | q = *str; |
6065 | n = 0; | |
6066 | while (ISALPHA (*q) && n < 3) | |
6067 | { | |
e07e6e58 | 6068 | cond[n] = TOLOWER (*q); |
c462b453 PB |
6069 | q++; |
6070 | n++; | |
6071 | } | |
a737bd4d | 6072 | |
21d799b5 | 6073 | c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n); |
c19d1205 | 6074 | if (!c) |
a737bd4d | 6075 | { |
c19d1205 | 6076 | inst.error = _("condition required"); |
a737bd4d NC |
6077 | return FAIL; |
6078 | } | |
6079 | ||
c19d1205 ZW |
6080 | *str = q; |
6081 | return c->value; | |
6082 | } | |
6083 | ||
e797f7e0 MGD |
6084 | /* If the given feature available in the selected CPU, mark it as used. |
6085 | Returns TRUE iff feature is available. */ | |
6086 | static bfd_boolean | |
6087 | mark_feature_used (const arm_feature_set *feature) | |
6088 | { | |
6089 | /* Ensure the option is valid on the current architecture. */ | |
6090 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
6091 | return FALSE; | |
6092 | ||
6093 | /* Add the appropriate architecture feature for the barrier option used. | |
6094 | */ | |
6095 | if (thumb_mode) | |
6096 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature); | |
6097 | else | |
6098 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature); | |
6099 | ||
6100 | return TRUE; | |
6101 | } | |
6102 | ||
62b3e311 PB |
6103 | /* Parse an option for a barrier instruction. Returns the encoding for the |
6104 | option, or FAIL. */ | |
6105 | static int | |
6106 | parse_barrier (char **str) | |
6107 | { | |
6108 | char *p, *q; | |
6109 | const struct asm_barrier_opt *o; | |
6110 | ||
6111 | p = q = *str; | |
6112 | while (ISALPHA (*q)) | |
6113 | q++; | |
6114 | ||
21d799b5 | 6115 | o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p, |
477330fc | 6116 | q - p); |
62b3e311 PB |
6117 | if (!o) |
6118 | return FAIL; | |
6119 | ||
e797f7e0 MGD |
6120 | if (!mark_feature_used (&o->arch)) |
6121 | return FAIL; | |
6122 | ||
62b3e311 PB |
6123 | *str = q; |
6124 | return o->value; | |
6125 | } | |
6126 | ||
92e90b6e PB |
6127 | /* Parse the operands of a table branch instruction. Similar to a memory |
6128 | operand. */ | |
6129 | static int | |
6130 | parse_tb (char **str) | |
6131 | { | |
6132 | char * p = *str; | |
6133 | int reg; | |
6134 | ||
6135 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
6136 | { |
6137 | inst.error = _("'[' expected"); | |
6138 | return FAIL; | |
6139 | } | |
92e90b6e | 6140 | |
dcbf9037 | 6141 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6142 | { |
6143 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6144 | return FAIL; | |
6145 | } | |
6146 | inst.operands[0].reg = reg; | |
6147 | ||
6148 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
6149 | { |
6150 | inst.error = _("',' expected"); | |
6151 | return FAIL; | |
6152 | } | |
5f4273c7 | 6153 | |
dcbf9037 | 6154 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
92e90b6e PB |
6155 | { |
6156 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
6157 | return FAIL; | |
6158 | } | |
6159 | inst.operands[0].imm = reg; | |
6160 | ||
6161 | if (skip_past_comma (&p) == SUCCESS) | |
6162 | { | |
6163 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
6164 | return FAIL; | |
6165 | if (inst.reloc.exp.X_add_number != 1) | |
6166 | { | |
6167 | inst.error = _("invalid shift"); | |
6168 | return FAIL; | |
6169 | } | |
6170 | inst.operands[0].shifted = 1; | |
6171 | } | |
6172 | ||
6173 | if (skip_past_char (&p, ']') == FAIL) | |
6174 | { | |
6175 | inst.error = _("']' expected"); | |
6176 | return FAIL; | |
6177 | } | |
6178 | *str = p; | |
6179 | return SUCCESS; | |
6180 | } | |
6181 | ||
5287ad62 JB |
6182 | /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more |
6183 | information on the types the operands can take and how they are encoded. | |
037e8744 JB |
6184 | Up to four operands may be read; this function handles setting the |
6185 | ".present" field for each read operand itself. | |
5287ad62 JB |
6186 | Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS, |
6187 | else returns FAIL. */ | |
6188 | ||
6189 | static int | |
6190 | parse_neon_mov (char **str, int *which_operand) | |
6191 | { | |
6192 | int i = *which_operand, val; | |
6193 | enum arm_reg_type rtype; | |
6194 | char *ptr = *str; | |
dcbf9037 | 6195 | struct neon_type_el optype; |
5f4273c7 | 6196 | |
dcbf9037 | 6197 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
5287ad62 JB |
6198 | { |
6199 | /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */ | |
6200 | inst.operands[i].reg = val; | |
6201 | inst.operands[i].isscalar = 1; | |
dcbf9037 | 6202 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6203 | inst.operands[i++].present = 1; |
6204 | ||
6205 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6206 | goto wanted_comma; |
5f4273c7 | 6207 | |
dcbf9037 | 6208 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) |
477330fc | 6209 | goto wanted_arm; |
5f4273c7 | 6210 | |
5287ad62 JB |
6211 | inst.operands[i].reg = val; |
6212 | inst.operands[i].isreg = 1; | |
6213 | inst.operands[i].present = 1; | |
6214 | } | |
037e8744 | 6215 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype)) |
477330fc | 6216 | != FAIL) |
5287ad62 JB |
6217 | { |
6218 | /* Cases 0, 1, 2, 3, 5 (D only). */ | |
6219 | if (skip_past_comma (&ptr) == FAIL) | |
477330fc | 6220 | goto wanted_comma; |
5f4273c7 | 6221 | |
5287ad62 JB |
6222 | inst.operands[i].reg = val; |
6223 | inst.operands[i].isreg = 1; | |
6224 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
037e8744 JB |
6225 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); |
6226 | inst.operands[i].isvec = 1; | |
dcbf9037 | 6227 | inst.operands[i].vectype = optype; |
5287ad62 JB |
6228 | inst.operands[i++].present = 1; |
6229 | ||
dcbf9037 | 6230 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6231 | { |
6232 | /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>. | |
6233 | Case 13: VMOV <Sd>, <Rm> */ | |
6234 | inst.operands[i].reg = val; | |
6235 | inst.operands[i].isreg = 1; | |
6236 | inst.operands[i].present = 1; | |
6237 | ||
6238 | if (rtype == REG_TYPE_NQ) | |
6239 | { | |
6240 | first_error (_("can't use Neon quad register here")); | |
6241 | return FAIL; | |
6242 | } | |
6243 | else if (rtype != REG_TYPE_VFS) | |
6244 | { | |
6245 | i++; | |
6246 | if (skip_past_comma (&ptr) == FAIL) | |
6247 | goto wanted_comma; | |
6248 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6249 | goto wanted_arm; | |
6250 | inst.operands[i].reg = val; | |
6251 | inst.operands[i].isreg = 1; | |
6252 | inst.operands[i].present = 1; | |
6253 | } | |
6254 | } | |
037e8744 | 6255 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, |
477330fc RM |
6256 | &optype)) != FAIL) |
6257 | { | |
6258 | /* Case 0: VMOV<c><q> <Qd>, <Qm> | |
6259 | Case 1: VMOV<c><q> <Dd>, <Dm> | |
6260 | Case 8: VMOV.F32 <Sd>, <Sm> | |
6261 | Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */ | |
6262 | ||
6263 | inst.operands[i].reg = val; | |
6264 | inst.operands[i].isreg = 1; | |
6265 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); | |
6266 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6267 | inst.operands[i].isvec = 1; | |
6268 | inst.operands[i].vectype = optype; | |
6269 | inst.operands[i].present = 1; | |
6270 | ||
6271 | if (skip_past_comma (&ptr) == SUCCESS) | |
6272 | { | |
6273 | /* Case 15. */ | |
6274 | i++; | |
6275 | ||
6276 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6277 | goto wanted_arm; | |
6278 | ||
6279 | inst.operands[i].reg = val; | |
6280 | inst.operands[i].isreg = 1; | |
6281 | inst.operands[i++].present = 1; | |
6282 | ||
6283 | if (skip_past_comma (&ptr) == FAIL) | |
6284 | goto wanted_comma; | |
6285 | ||
6286 | if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL) | |
6287 | goto wanted_arm; | |
6288 | ||
6289 | inst.operands[i].reg = val; | |
6290 | inst.operands[i].isreg = 1; | |
6291 | inst.operands[i].present = 1; | |
6292 | } | |
6293 | } | |
4641781c | 6294 | else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS) |
477330fc RM |
6295 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm> |
6296 | Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm> | |
6297 | Case 10: VMOV.F32 <Sd>, #<imm> | |
6298 | Case 11: VMOV.F64 <Dd>, #<imm> */ | |
6299 | inst.operands[i].immisfloat = 1; | |
8335d6aa JW |
6300 | else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE) |
6301 | == SUCCESS) | |
477330fc RM |
6302 | /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm> |
6303 | Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */ | |
6304 | ; | |
5287ad62 | 6305 | else |
477330fc RM |
6306 | { |
6307 | first_error (_("expected <Rm> or <Dm> or <Qm> operand")); | |
6308 | return FAIL; | |
6309 | } | |
5287ad62 | 6310 | } |
dcbf9037 | 6311 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
5287ad62 JB |
6312 | { |
6313 | /* Cases 6, 7. */ | |
6314 | inst.operands[i].reg = val; | |
6315 | inst.operands[i].isreg = 1; | |
6316 | inst.operands[i++].present = 1; | |
5f4273c7 | 6317 | |
5287ad62 | 6318 | if (skip_past_comma (&ptr) == FAIL) |
477330fc | 6319 | goto wanted_comma; |
5f4273c7 | 6320 | |
dcbf9037 | 6321 | if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL) |
477330fc RM |
6322 | { |
6323 | /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */ | |
6324 | inst.operands[i].reg = val; | |
6325 | inst.operands[i].isscalar = 1; | |
6326 | inst.operands[i].present = 1; | |
6327 | inst.operands[i].vectype = optype; | |
6328 | } | |
dcbf9037 | 6329 | else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL) |
477330fc RM |
6330 | { |
6331 | /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */ | |
6332 | inst.operands[i].reg = val; | |
6333 | inst.operands[i].isreg = 1; | |
6334 | inst.operands[i++].present = 1; | |
6335 | ||
6336 | if (skip_past_comma (&ptr) == FAIL) | |
6337 | goto wanted_comma; | |
6338 | ||
6339 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype)) | |
6340 | == FAIL) | |
6341 | { | |
6342 | first_error (_(reg_expected_msgs[REG_TYPE_VFSD])); | |
6343 | return FAIL; | |
6344 | } | |
6345 | ||
6346 | inst.operands[i].reg = val; | |
6347 | inst.operands[i].isreg = 1; | |
6348 | inst.operands[i].isvec = 1; | |
6349 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); | |
6350 | inst.operands[i].vectype = optype; | |
6351 | inst.operands[i].present = 1; | |
6352 | ||
6353 | if (rtype == REG_TYPE_VFS) | |
6354 | { | |
6355 | /* Case 14. */ | |
6356 | i++; | |
6357 | if (skip_past_comma (&ptr) == FAIL) | |
6358 | goto wanted_comma; | |
6359 | if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, | |
6360 | &optype)) == FAIL) | |
6361 | { | |
6362 | first_error (_(reg_expected_msgs[REG_TYPE_VFS])); | |
6363 | return FAIL; | |
6364 | } | |
6365 | inst.operands[i].reg = val; | |
6366 | inst.operands[i].isreg = 1; | |
6367 | inst.operands[i].isvec = 1; | |
6368 | inst.operands[i].issingle = 1; | |
6369 | inst.operands[i].vectype = optype; | |
6370 | inst.operands[i].present = 1; | |
6371 | } | |
6372 | } | |
037e8744 | 6373 | else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype)) |
477330fc RM |
6374 | != FAIL) |
6375 | { | |
6376 | /* Case 13. */ | |
6377 | inst.operands[i].reg = val; | |
6378 | inst.operands[i].isreg = 1; | |
6379 | inst.operands[i].isvec = 1; | |
6380 | inst.operands[i].issingle = 1; | |
6381 | inst.operands[i].vectype = optype; | |
6382 | inst.operands[i].present = 1; | |
6383 | } | |
5287ad62 JB |
6384 | } |
6385 | else | |
6386 | { | |
dcbf9037 | 6387 | first_error (_("parse error")); |
5287ad62 JB |
6388 | return FAIL; |
6389 | } | |
6390 | ||
6391 | /* Successfully parsed the operands. Update args. */ | |
6392 | *which_operand = i; | |
6393 | *str = ptr; | |
6394 | return SUCCESS; | |
6395 | ||
5f4273c7 | 6396 | wanted_comma: |
dcbf9037 | 6397 | first_error (_("expected comma")); |
5287ad62 | 6398 | return FAIL; |
5f4273c7 NC |
6399 | |
6400 | wanted_arm: | |
dcbf9037 | 6401 | first_error (_(reg_expected_msgs[REG_TYPE_RN])); |
5287ad62 | 6402 | return FAIL; |
5287ad62 JB |
6403 | } |
6404 | ||
5be8be5d DG |
6405 | /* Use this macro when the operand constraints are different |
6406 | for ARM and THUMB (e.g. ldrd). */ | |
6407 | #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \ | |
6408 | ((arm_operand) | ((thumb_operand) << 16)) | |
6409 | ||
c19d1205 ZW |
6410 | /* Matcher codes for parse_operands. */ |
6411 | enum operand_parse_code | |
6412 | { | |
6413 | OP_stop, /* end of line */ | |
6414 | ||
6415 | OP_RR, /* ARM register */ | |
6416 | OP_RRnpc, /* ARM register, not r15 */ | |
5be8be5d | 6417 | OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */ |
c19d1205 | 6418 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ |
fa94de6b | 6419 | OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback, |
55881a11 | 6420 | optional trailing ! */ |
c19d1205 ZW |
6421 | OP_RRw, /* ARM register, not r15, optional trailing ! */ |
6422 | OP_RCP, /* Coprocessor number */ | |
6423 | OP_RCN, /* Coprocessor register */ | |
6424 | OP_RF, /* FPA register */ | |
6425 | OP_RVS, /* VFP single precision register */ | |
5287ad62 JB |
6426 | OP_RVD, /* VFP double precision register (0..15) */ |
6427 | OP_RND, /* Neon double precision register (0..31) */ | |
6428 | OP_RNQ, /* Neon quad precision register */ | |
037e8744 | 6429 | OP_RVSD, /* VFP single or double precision register */ |
5287ad62 | 6430 | OP_RNDQ, /* Neon double or quad precision register */ |
037e8744 | 6431 | OP_RNSDQ, /* Neon single, double or quad precision register */ |
5287ad62 | 6432 | OP_RNSC, /* Neon scalar D[X] */ |
c19d1205 ZW |
6433 | OP_RVC, /* VFP control register */ |
6434 | OP_RMF, /* Maverick F register */ | |
6435 | OP_RMD, /* Maverick D register */ | |
6436 | OP_RMFX, /* Maverick FX register */ | |
6437 | OP_RMDX, /* Maverick DX register */ | |
6438 | OP_RMAX, /* Maverick AX register */ | |
6439 | OP_RMDS, /* Maverick DSPSC register */ | |
6440 | OP_RIWR, /* iWMMXt wR register */ | |
6441 | OP_RIWC, /* iWMMXt wC register */ | |
6442 | OP_RIWG, /* iWMMXt wCG register */ | |
6443 | OP_RXA, /* XScale accumulator register */ | |
6444 | ||
6445 | OP_REGLST, /* ARM register list */ | |
6446 | OP_VRSLST, /* VFP single-precision register list */ | |
6447 | OP_VRDLST, /* VFP double-precision register list */ | |
037e8744 | 6448 | OP_VRSDLST, /* VFP single or double-precision register list (& quad) */ |
5287ad62 JB |
6449 | OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */ |
6450 | OP_NSTRLST, /* Neon element/structure list */ | |
6451 | ||
5287ad62 | 6452 | OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */ |
037e8744 | 6453 | OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */ |
aacf0b33 | 6454 | OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */ |
5287ad62 | 6455 | OP_RR_RNSC, /* ARM reg or Neon scalar. */ |
037e8744 | 6456 | OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */ |
5287ad62 JB |
6457 | OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */ |
6458 | OP_RND_RNSC, /* Neon D reg, or Neon scalar. */ | |
6459 | OP_VMOV, /* Neon VMOV operands. */ | |
4316f0d2 | 6460 | OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */ |
5287ad62 | 6461 | OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */ |
2d447fca | 6462 | OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */ |
5287ad62 JB |
6463 | |
6464 | OP_I0, /* immediate zero */ | |
c19d1205 ZW |
6465 | OP_I7, /* immediate value 0 .. 7 */ |
6466 | OP_I15, /* 0 .. 15 */ | |
6467 | OP_I16, /* 1 .. 16 */ | |
5287ad62 | 6468 | OP_I16z, /* 0 .. 16 */ |
c19d1205 ZW |
6469 | OP_I31, /* 0 .. 31 */ |
6470 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
6471 | OP_I32, /* 1 .. 32 */ | |
5287ad62 JB |
6472 | OP_I32z, /* 0 .. 32 */ |
6473 | OP_I63, /* 0 .. 63 */ | |
c19d1205 | 6474 | OP_I63s, /* -64 .. 63 */ |
5287ad62 JB |
6475 | OP_I64, /* 1 .. 64 */ |
6476 | OP_I64z, /* 0 .. 64 */ | |
c19d1205 | 6477 | OP_I255, /* 0 .. 255 */ |
c19d1205 ZW |
6478 | |
6479 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
6480 | OP_I7b, /* 0 .. 7 */ | |
6481 | OP_I15b, /* 0 .. 15 */ | |
6482 | OP_I31b, /* 0 .. 31 */ | |
6483 | ||
6484 | OP_SH, /* shifter operand */ | |
4962c51a | 6485 | OP_SHG, /* shifter operand with possible group relocation */ |
c19d1205 | 6486 | OP_ADDR, /* Memory address expression (any mode) */ |
4962c51a MS |
6487 | OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */ |
6488 | OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */ | |
6489 | OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */ | |
c19d1205 ZW |
6490 | OP_EXP, /* arbitrary expression */ |
6491 | OP_EXPi, /* same, with optional immediate prefix */ | |
6492 | OP_EXPr, /* same, with optional relocation suffix */ | |
b6895b4f | 6493 | OP_HALF, /* 0 .. 65535 or low/high reloc. */ |
c19d1205 ZW |
6494 | |
6495 | OP_CPSF, /* CPS flags */ | |
6496 | OP_ENDI, /* Endianness specifier */ | |
d2cd1205 JB |
6497 | OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */ |
6498 | OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */ | |
c19d1205 | 6499 | OP_COND, /* conditional code */ |
92e90b6e | 6500 | OP_TB, /* Table branch. */ |
c19d1205 | 6501 | |
037e8744 JB |
6502 | OP_APSR_RR, /* ARM register or "APSR_nzcv". */ |
6503 | ||
c19d1205 ZW |
6504 | OP_RRnpc_I0, /* ARM register or literal 0 */ |
6505 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
6506 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
6507 | OP_RF_IF, /* FPA register or immediate */ | |
6508 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
41adaa5c | 6509 | OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */ |
c19d1205 ZW |
6510 | |
6511 | /* Optional operands. */ | |
6512 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
6513 | OP_oI31b, /* 0 .. 31 */ | |
5287ad62 | 6514 | OP_oI32b, /* 1 .. 32 */ |
5f1af56b | 6515 | OP_oI32z, /* 0 .. 32 */ |
c19d1205 ZW |
6516 | OP_oIffffb, /* 0 .. 65535 */ |
6517 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
6518 | ||
6519 | OP_oRR, /* ARM register */ | |
6520 | OP_oRRnpc, /* ARM register, not the PC */ | |
5be8be5d | 6521 | OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */ |
b6702015 | 6522 | OP_oRRw, /* ARM register, not r15, optional trailing ! */ |
5287ad62 JB |
6523 | OP_oRND, /* Optional Neon double precision register */ |
6524 | OP_oRNQ, /* Optional Neon quad precision register */ | |
6525 | OP_oRNDQ, /* Optional Neon double or quad precision register */ | |
037e8744 | 6526 | OP_oRNSDQ, /* Optional single, double or quad precision vector register */ |
c19d1205 ZW |
6527 | OP_oSHll, /* LSL immediate */ |
6528 | OP_oSHar, /* ASR immediate */ | |
6529 | OP_oSHllar, /* LSL or ASR immediate */ | |
6530 | OP_oROR, /* ROR 0/8/16/24 */ | |
52e7f43d | 6531 | OP_oBARRIER_I15, /* Option argument for a barrier instruction. */ |
c19d1205 | 6532 | |
5be8be5d DG |
6533 | /* Some pre-defined mixed (ARM/THUMB) operands. */ |
6534 | OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp), | |
6535 | OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp), | |
6536 | OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp), | |
6537 | ||
c19d1205 ZW |
6538 | OP_FIRST_OPTIONAL = OP_oI7b |
6539 | }; | |
a737bd4d | 6540 | |
c19d1205 ZW |
6541 | /* Generic instruction operand parser. This does no encoding and no |
6542 | semantic validation; it merely squirrels values away in the inst | |
6543 | structure. Returns SUCCESS or FAIL depending on whether the | |
6544 | specified grammar matched. */ | |
6545 | static int | |
5be8be5d | 6546 | parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb) |
c19d1205 | 6547 | { |
5be8be5d | 6548 | unsigned const int *upat = pattern; |
c19d1205 ZW |
6549 | char *backtrack_pos = 0; |
6550 | const char *backtrack_error = 0; | |
99aad254 | 6551 | int i, val = 0, backtrack_index = 0; |
5287ad62 | 6552 | enum arm_reg_type rtype; |
4962c51a | 6553 | parse_operand_result result; |
5be8be5d | 6554 | unsigned int op_parse_code; |
c19d1205 | 6555 | |
e07e6e58 NC |
6556 | #define po_char_or_fail(chr) \ |
6557 | do \ | |
6558 | { \ | |
6559 | if (skip_past_char (&str, chr) == FAIL) \ | |
477330fc | 6560 | goto bad_args; \ |
e07e6e58 NC |
6561 | } \ |
6562 | while (0) | |
c19d1205 | 6563 | |
e07e6e58 NC |
6564 | #define po_reg_or_fail(regtype) \ |
6565 | do \ | |
dcbf9037 | 6566 | { \ |
e07e6e58 | 6567 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ |
477330fc | 6568 | & inst.operands[i].vectype); \ |
e07e6e58 | 6569 | if (val == FAIL) \ |
477330fc RM |
6570 | { \ |
6571 | first_error (_(reg_expected_msgs[regtype])); \ | |
6572 | goto failure; \ | |
6573 | } \ | |
e07e6e58 NC |
6574 | inst.operands[i].reg = val; \ |
6575 | inst.operands[i].isreg = 1; \ | |
6576 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6577 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6578 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc RM |
6579 | || rtype == REG_TYPE_VFD \ |
6580 | || rtype == REG_TYPE_NQ); \ | |
dcbf9037 | 6581 | } \ |
e07e6e58 NC |
6582 | while (0) |
6583 | ||
6584 | #define po_reg_or_goto(regtype, label) \ | |
6585 | do \ | |
6586 | { \ | |
6587 | val = arm_typed_reg_parse (& str, regtype, & rtype, \ | |
6588 | & inst.operands[i].vectype); \ | |
6589 | if (val == FAIL) \ | |
6590 | goto label; \ | |
dcbf9037 | 6591 | \ |
e07e6e58 NC |
6592 | inst.operands[i].reg = val; \ |
6593 | inst.operands[i].isreg = 1; \ | |
6594 | inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \ | |
6595 | inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \ | |
6596 | inst.operands[i].isvec = (rtype == REG_TYPE_VFS \ | |
477330fc | 6597 | || rtype == REG_TYPE_VFD \ |
e07e6e58 NC |
6598 | || rtype == REG_TYPE_NQ); \ |
6599 | } \ | |
6600 | while (0) | |
6601 | ||
6602 | #define po_imm_or_fail(min, max, popt) \ | |
6603 | do \ | |
6604 | { \ | |
6605 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
6606 | goto failure; \ | |
6607 | inst.operands[i].imm = val; \ | |
6608 | } \ | |
6609 | while (0) | |
6610 | ||
6611 | #define po_scalar_or_goto(elsz, label) \ | |
6612 | do \ | |
6613 | { \ | |
6614 | val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \ | |
6615 | if (val == FAIL) \ | |
6616 | goto label; \ | |
6617 | inst.operands[i].reg = val; \ | |
6618 | inst.operands[i].isscalar = 1; \ | |
6619 | } \ | |
6620 | while (0) | |
6621 | ||
6622 | #define po_misc_or_fail(expr) \ | |
6623 | do \ | |
6624 | { \ | |
6625 | if (expr) \ | |
6626 | goto failure; \ | |
6627 | } \ | |
6628 | while (0) | |
6629 | ||
6630 | #define po_misc_or_fail_no_backtrack(expr) \ | |
6631 | do \ | |
6632 | { \ | |
6633 | result = expr; \ | |
6634 | if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \ | |
6635 | backtrack_pos = 0; \ | |
6636 | if (result != PARSE_OPERAND_SUCCESS) \ | |
6637 | goto failure; \ | |
6638 | } \ | |
6639 | while (0) | |
4962c51a | 6640 | |
52e7f43d RE |
6641 | #define po_barrier_or_imm(str) \ |
6642 | do \ | |
6643 | { \ | |
6644 | val = parse_barrier (&str); \ | |
ccb84d65 JB |
6645 | if (val == FAIL && ! ISALPHA (*str)) \ |
6646 | goto immediate; \ | |
6647 | if (val == FAIL \ | |
6648 | /* ISB can only take SY as an option. */ \ | |
6649 | || ((inst.instruction & 0xf0) == 0x60 \ | |
6650 | && val != 0xf)) \ | |
52e7f43d | 6651 | { \ |
ccb84d65 JB |
6652 | inst.error = _("invalid barrier type"); \ |
6653 | backtrack_pos = 0; \ | |
6654 | goto failure; \ | |
52e7f43d RE |
6655 | } \ |
6656 | } \ | |
6657 | while (0) | |
6658 | ||
c19d1205 ZW |
6659 | skip_whitespace (str); |
6660 | ||
6661 | for (i = 0; upat[i] != OP_stop; i++) | |
6662 | { | |
5be8be5d DG |
6663 | op_parse_code = upat[i]; |
6664 | if (op_parse_code >= 1<<16) | |
6665 | op_parse_code = thumb ? (op_parse_code >> 16) | |
6666 | : (op_parse_code & ((1<<16)-1)); | |
6667 | ||
6668 | if (op_parse_code >= OP_FIRST_OPTIONAL) | |
c19d1205 ZW |
6669 | { |
6670 | /* Remember where we are in case we need to backtrack. */ | |
9c2799c2 | 6671 | gas_assert (!backtrack_pos); |
c19d1205 ZW |
6672 | backtrack_pos = str; |
6673 | backtrack_error = inst.error; | |
6674 | backtrack_index = i; | |
6675 | } | |
6676 | ||
b6702015 | 6677 | if (i > 0 && (i > 1 || inst.operands[0].present)) |
c19d1205 ZW |
6678 | po_char_or_fail (','); |
6679 | ||
5be8be5d | 6680 | switch (op_parse_code) |
c19d1205 ZW |
6681 | { |
6682 | /* Registers */ | |
6683 | case OP_oRRnpc: | |
5be8be5d | 6684 | case OP_oRRnpcsp: |
c19d1205 | 6685 | case OP_RRnpc: |
5be8be5d | 6686 | case OP_RRnpcsp: |
c19d1205 ZW |
6687 | case OP_oRR: |
6688 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
6689 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
6690 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
6691 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
6692 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
6693 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
477330fc | 6694 | case OP_oRND: |
5287ad62 | 6695 | case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break; |
cd2cf30b PB |
6696 | case OP_RVC: |
6697 | po_reg_or_goto (REG_TYPE_VFC, coproc_reg); | |
6698 | break; | |
6699 | /* Also accept generic coprocessor regs for unknown registers. */ | |
6700 | coproc_reg: | |
6701 | po_reg_or_fail (REG_TYPE_CN); | |
6702 | break; | |
c19d1205 ZW |
6703 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; |
6704 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
6705 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
6706 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
6707 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
6708 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
6709 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
6710 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
6711 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
6712 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
477330fc | 6713 | case OP_oRNQ: |
5287ad62 | 6714 | case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break; |
477330fc | 6715 | case OP_oRNDQ: |
5287ad62 | 6716 | case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break; |
477330fc RM |
6717 | case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break; |
6718 | case OP_oRNSDQ: | |
6719 | case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break; | |
6720 | ||
6721 | /* Neon scalar. Using an element size of 8 means that some invalid | |
6722 | scalars are accepted here, so deal with those in later code. */ | |
6723 | case OP_RNSC: po_scalar_or_goto (8, failure); break; | |
6724 | ||
6725 | case OP_RNDQ_I0: | |
6726 | { | |
6727 | po_reg_or_goto (REG_TYPE_NDQ, try_imm0); | |
6728 | break; | |
6729 | try_imm0: | |
6730 | po_imm_or_fail (0, 0, TRUE); | |
6731 | } | |
6732 | break; | |
6733 | ||
6734 | case OP_RVSD_I0: | |
6735 | po_reg_or_goto (REG_TYPE_VFSD, try_imm0); | |
6736 | break; | |
6737 | ||
aacf0b33 KT |
6738 | case OP_RSVD_FI0: |
6739 | { | |
6740 | po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0); | |
6741 | break; | |
6742 | try_ifimm0: | |
6743 | if (parse_ifimm_zero (&str)) | |
6744 | inst.operands[i].imm = 0; | |
6745 | else | |
6746 | { | |
6747 | inst.error | |
6748 | = _("only floating point zero is allowed as immediate value"); | |
6749 | goto failure; | |
6750 | } | |
6751 | } | |
6752 | break; | |
6753 | ||
477330fc RM |
6754 | case OP_RR_RNSC: |
6755 | { | |
6756 | po_scalar_or_goto (8, try_rr); | |
6757 | break; | |
6758 | try_rr: | |
6759 | po_reg_or_fail (REG_TYPE_RN); | |
6760 | } | |
6761 | break; | |
6762 | ||
6763 | case OP_RNSDQ_RNSC: | |
6764 | { | |
6765 | po_scalar_or_goto (8, try_nsdq); | |
6766 | break; | |
6767 | try_nsdq: | |
6768 | po_reg_or_fail (REG_TYPE_NSDQ); | |
6769 | } | |
6770 | break; | |
6771 | ||
6772 | case OP_RNDQ_RNSC: | |
6773 | { | |
6774 | po_scalar_or_goto (8, try_ndq); | |
6775 | break; | |
6776 | try_ndq: | |
6777 | po_reg_or_fail (REG_TYPE_NDQ); | |
6778 | } | |
6779 | break; | |
6780 | ||
6781 | case OP_RND_RNSC: | |
6782 | { | |
6783 | po_scalar_or_goto (8, try_vfd); | |
6784 | break; | |
6785 | try_vfd: | |
6786 | po_reg_or_fail (REG_TYPE_VFD); | |
6787 | } | |
6788 | break; | |
6789 | ||
6790 | case OP_VMOV: | |
6791 | /* WARNING: parse_neon_mov can move the operand counter, i. If we're | |
6792 | not careful then bad things might happen. */ | |
6793 | po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL); | |
6794 | break; | |
6795 | ||
6796 | case OP_RNDQ_Ibig: | |
6797 | { | |
6798 | po_reg_or_goto (REG_TYPE_NDQ, try_immbig); | |
6799 | break; | |
6800 | try_immbig: | |
6801 | /* There's a possibility of getting a 64-bit immediate here, so | |
6802 | we need special handling. */ | |
8335d6aa JW |
6803 | if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE) |
6804 | == FAIL) | |
477330fc RM |
6805 | { |
6806 | inst.error = _("immediate value is out of range"); | |
6807 | goto failure; | |
6808 | } | |
6809 | } | |
6810 | break; | |
6811 | ||
6812 | case OP_RNDQ_I63b: | |
6813 | { | |
6814 | po_reg_or_goto (REG_TYPE_NDQ, try_shimm); | |
6815 | break; | |
6816 | try_shimm: | |
6817 | po_imm_or_fail (0, 63, TRUE); | |
6818 | } | |
6819 | break; | |
c19d1205 ZW |
6820 | |
6821 | case OP_RRnpcb: | |
6822 | po_char_or_fail ('['); | |
6823 | po_reg_or_fail (REG_TYPE_RN); | |
6824 | po_char_or_fail (']'); | |
6825 | break; | |
a737bd4d | 6826 | |
55881a11 | 6827 | case OP_RRnpctw: |
c19d1205 | 6828 | case OP_RRw: |
b6702015 | 6829 | case OP_oRRw: |
c19d1205 ZW |
6830 | po_reg_or_fail (REG_TYPE_RN); |
6831 | if (skip_past_char (&str, '!') == SUCCESS) | |
6832 | inst.operands[i].writeback = 1; | |
6833 | break; | |
6834 | ||
6835 | /* Immediates */ | |
6836 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
6837 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
6838 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
477330fc | 6839 | case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break; |
c19d1205 ZW |
6840 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; |
6841 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
477330fc | 6842 | case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break; |
c19d1205 | 6843 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; |
477330fc RM |
6844 | case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break; |
6845 | case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break; | |
6846 | case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break; | |
c19d1205 | 6847 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; |
c19d1205 ZW |
6848 | |
6849 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
6850 | case OP_oI7b: | |
6851 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
6852 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
6853 | case OP_oI31b: | |
6854 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
477330fc RM |
6855 | case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break; |
6856 | case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break; | |
c19d1205 ZW |
6857 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; |
6858 | ||
6859 | /* Immediate variants */ | |
6860 | case OP_oI255c: | |
6861 | po_char_or_fail ('{'); | |
6862 | po_imm_or_fail (0, 255, TRUE); | |
6863 | po_char_or_fail ('}'); | |
6864 | break; | |
6865 | ||
6866 | case OP_I31w: | |
6867 | /* The expression parser chokes on a trailing !, so we have | |
6868 | to find it first and zap it. */ | |
6869 | { | |
6870 | char *s = str; | |
6871 | while (*s && *s != ',') | |
6872 | s++; | |
6873 | if (s[-1] == '!') | |
6874 | { | |
6875 | s[-1] = '\0'; | |
6876 | inst.operands[i].writeback = 1; | |
6877 | } | |
6878 | po_imm_or_fail (0, 31, TRUE); | |
6879 | if (str == s - 1) | |
6880 | str = s; | |
6881 | } | |
6882 | break; | |
6883 | ||
6884 | /* Expressions */ | |
6885 | case OP_EXPi: EXPi: | |
6886 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6887 | GE_OPT_PREFIX)); | |
6888 | break; | |
6889 | ||
6890 | case OP_EXP: | |
6891 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6892 | GE_NO_PREFIX)); | |
6893 | break; | |
6894 | ||
6895 | case OP_EXPr: EXPr: | |
6896 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
6897 | GE_NO_PREFIX)); | |
6898 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 6899 | { |
c19d1205 ZW |
6900 | val = parse_reloc (&str); |
6901 | if (val == -1) | |
6902 | { | |
6903 | inst.error = _("unrecognized relocation suffix"); | |
6904 | goto failure; | |
6905 | } | |
6906 | else if (val != BFD_RELOC_UNUSED) | |
6907 | { | |
6908 | inst.operands[i].imm = val; | |
6909 | inst.operands[i].hasreloc = 1; | |
6910 | } | |
a737bd4d | 6911 | } |
c19d1205 | 6912 | break; |
a737bd4d | 6913 | |
b6895b4f PB |
6914 | /* Operand for MOVW or MOVT. */ |
6915 | case OP_HALF: | |
6916 | po_misc_or_fail (parse_half (&str)); | |
6917 | break; | |
6918 | ||
e07e6e58 | 6919 | /* Register or expression. */ |
c19d1205 ZW |
6920 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; |
6921 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 6922 | |
e07e6e58 | 6923 | /* Register or immediate. */ |
c19d1205 ZW |
6924 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; |
6925 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 6926 | |
c19d1205 ZW |
6927 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
6928 | IF: | |
6929 | if (!is_immediate_prefix (*str)) | |
6930 | goto bad_args; | |
6931 | str++; | |
6932 | val = parse_fpa_immediate (&str); | |
6933 | if (val == FAIL) | |
6934 | goto failure; | |
6935 | /* FPA immediates are encoded as registers 8-15. | |
6936 | parse_fpa_immediate has already applied the offset. */ | |
6937 | inst.operands[i].reg = val; | |
6938 | inst.operands[i].isreg = 1; | |
6939 | break; | |
09d92015 | 6940 | |
2d447fca JM |
6941 | case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break; |
6942 | I32z: po_imm_or_fail (0, 32, FALSE); break; | |
6943 | ||
e07e6e58 | 6944 | /* Two kinds of register. */ |
c19d1205 ZW |
6945 | case OP_RIWR_RIWC: |
6946 | { | |
6947 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
97f87066 JM |
6948 | if (!rege |
6949 | || (rege->type != REG_TYPE_MMXWR | |
6950 | && rege->type != REG_TYPE_MMXWC | |
6951 | && rege->type != REG_TYPE_MMXWCG)) | |
c19d1205 ZW |
6952 | { |
6953 | inst.error = _("iWMMXt data or control register expected"); | |
6954 | goto failure; | |
6955 | } | |
6956 | inst.operands[i].reg = rege->number; | |
6957 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
6958 | } | |
6959 | break; | |
09d92015 | 6960 | |
41adaa5c JM |
6961 | case OP_RIWC_RIWG: |
6962 | { | |
6963 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
6964 | if (!rege | |
6965 | || (rege->type != REG_TYPE_MMXWC | |
6966 | && rege->type != REG_TYPE_MMXWCG)) | |
6967 | { | |
6968 | inst.error = _("iWMMXt control register expected"); | |
6969 | goto failure; | |
6970 | } | |
6971 | inst.operands[i].reg = rege->number; | |
6972 | inst.operands[i].isreg = 1; | |
6973 | } | |
6974 | break; | |
6975 | ||
c19d1205 ZW |
6976 | /* Misc */ |
6977 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
6978 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
6979 | case OP_oROR: val = parse_ror (&str); break; | |
c19d1205 | 6980 | case OP_COND: val = parse_cond (&str); break; |
52e7f43d RE |
6981 | case OP_oBARRIER_I15: |
6982 | po_barrier_or_imm (str); break; | |
6983 | immediate: | |
6984 | if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL) | |
477330fc | 6985 | goto failure; |
52e7f43d | 6986 | break; |
c19d1205 | 6987 | |
fa94de6b | 6988 | case OP_wPSR: |
d2cd1205 | 6989 | case OP_rPSR: |
90ec0d68 MGD |
6990 | po_reg_or_goto (REG_TYPE_RNB, try_psr); |
6991 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt)) | |
6992 | { | |
6993 | inst.error = _("Banked registers are not available with this " | |
6994 | "architecture."); | |
6995 | goto failure; | |
6996 | } | |
6997 | break; | |
d2cd1205 JB |
6998 | try_psr: |
6999 | val = parse_psr (&str, op_parse_code == OP_wPSR); | |
7000 | break; | |
037e8744 | 7001 | |
477330fc RM |
7002 | case OP_APSR_RR: |
7003 | po_reg_or_goto (REG_TYPE_RN, try_apsr); | |
7004 | break; | |
7005 | try_apsr: | |
7006 | /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS | |
7007 | instruction). */ | |
7008 | if (strncasecmp (str, "APSR_", 5) == 0) | |
7009 | { | |
7010 | unsigned found = 0; | |
7011 | str += 5; | |
7012 | while (found < 15) | |
7013 | switch (*str++) | |
7014 | { | |
7015 | case 'c': found = (found & 1) ? 16 : found | 1; break; | |
7016 | case 'n': found = (found & 2) ? 16 : found | 2; break; | |
7017 | case 'z': found = (found & 4) ? 16 : found | 4; break; | |
7018 | case 'v': found = (found & 8) ? 16 : found | 8; break; | |
7019 | default: found = 16; | |
7020 | } | |
7021 | if (found != 15) | |
7022 | goto failure; | |
7023 | inst.operands[i].isvec = 1; | |
f7c21dc7 NC |
7024 | /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */ |
7025 | inst.operands[i].reg = REG_PC; | |
477330fc RM |
7026 | } |
7027 | else | |
7028 | goto failure; | |
7029 | break; | |
037e8744 | 7030 | |
92e90b6e PB |
7031 | case OP_TB: |
7032 | po_misc_or_fail (parse_tb (&str)); | |
7033 | break; | |
7034 | ||
e07e6e58 | 7035 | /* Register lists. */ |
c19d1205 ZW |
7036 | case OP_REGLST: |
7037 | val = parse_reg_list (&str); | |
7038 | if (*str == '^') | |
7039 | { | |
5e0d7f77 | 7040 | inst.operands[i].writeback = 1; |
c19d1205 ZW |
7041 | str++; |
7042 | } | |
7043 | break; | |
09d92015 | 7044 | |
c19d1205 | 7045 | case OP_VRSLST: |
5287ad62 | 7046 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S); |
c19d1205 | 7047 | break; |
09d92015 | 7048 | |
c19d1205 | 7049 | case OP_VRDLST: |
5287ad62 | 7050 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D); |
c19d1205 | 7051 | break; |
a737bd4d | 7052 | |
477330fc RM |
7053 | case OP_VRSDLST: |
7054 | /* Allow Q registers too. */ | |
7055 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7056 | REGLIST_NEON_D); | |
7057 | if (val == FAIL) | |
7058 | { | |
7059 | inst.error = NULL; | |
7060 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7061 | REGLIST_VFP_S); | |
7062 | inst.operands[i].issingle = 1; | |
7063 | } | |
7064 | break; | |
7065 | ||
7066 | case OP_NRDLST: | |
7067 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, | |
7068 | REGLIST_NEON_D); | |
7069 | break; | |
5287ad62 JB |
7070 | |
7071 | case OP_NSTRLST: | |
477330fc RM |
7072 | val = parse_neon_el_struct_list (&str, &inst.operands[i].reg, |
7073 | &inst.operands[i].vectype); | |
7074 | break; | |
5287ad62 | 7075 | |
c19d1205 ZW |
7076 | /* Addressing modes */ |
7077 | case OP_ADDR: | |
7078 | po_misc_or_fail (parse_address (&str, i)); | |
7079 | break; | |
09d92015 | 7080 | |
4962c51a MS |
7081 | case OP_ADDRGLDR: |
7082 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7083 | parse_address_group_reloc (&str, i, GROUP_LDR)); |
4962c51a MS |
7084 | break; |
7085 | ||
7086 | case OP_ADDRGLDRS: | |
7087 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7088 | parse_address_group_reloc (&str, i, GROUP_LDRS)); |
4962c51a MS |
7089 | break; |
7090 | ||
7091 | case OP_ADDRGLDC: | |
7092 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7093 | parse_address_group_reloc (&str, i, GROUP_LDC)); |
4962c51a MS |
7094 | break; |
7095 | ||
c19d1205 ZW |
7096 | case OP_SH: |
7097 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
7098 | break; | |
09d92015 | 7099 | |
4962c51a MS |
7100 | case OP_SHG: |
7101 | po_misc_or_fail_no_backtrack ( | |
477330fc | 7102 | parse_shifter_operand_group_reloc (&str, i)); |
4962c51a MS |
7103 | break; |
7104 | ||
c19d1205 ZW |
7105 | case OP_oSHll: |
7106 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
7107 | break; | |
09d92015 | 7108 | |
c19d1205 ZW |
7109 | case OP_oSHar: |
7110 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
7111 | break; | |
09d92015 | 7112 | |
c19d1205 ZW |
7113 | case OP_oSHllar: |
7114 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
7115 | break; | |
09d92015 | 7116 | |
c19d1205 | 7117 | default: |
5be8be5d | 7118 | as_fatal (_("unhandled operand code %d"), op_parse_code); |
c19d1205 | 7119 | } |
09d92015 | 7120 | |
c19d1205 ZW |
7121 | /* Various value-based sanity checks and shared operations. We |
7122 | do not signal immediate failures for the register constraints; | |
7123 | this allows a syntax error to take precedence. */ | |
5be8be5d | 7124 | switch (op_parse_code) |
c19d1205 ZW |
7125 | { |
7126 | case OP_oRRnpc: | |
7127 | case OP_RRnpc: | |
7128 | case OP_RRnpcb: | |
7129 | case OP_RRw: | |
b6702015 | 7130 | case OP_oRRw: |
c19d1205 ZW |
7131 | case OP_RRnpc_I0: |
7132 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
7133 | inst.error = BAD_PC; | |
7134 | break; | |
09d92015 | 7135 | |
5be8be5d DG |
7136 | case OP_oRRnpcsp: |
7137 | case OP_RRnpcsp: | |
7138 | if (inst.operands[i].isreg) | |
7139 | { | |
7140 | if (inst.operands[i].reg == REG_PC) | |
7141 | inst.error = BAD_PC; | |
7142 | else if (inst.operands[i].reg == REG_SP) | |
7143 | inst.error = BAD_SP; | |
7144 | } | |
7145 | break; | |
7146 | ||
55881a11 | 7147 | case OP_RRnpctw: |
fa94de6b RM |
7148 | if (inst.operands[i].isreg |
7149 | && inst.operands[i].reg == REG_PC | |
55881a11 MGD |
7150 | && (inst.operands[i].writeback || thumb)) |
7151 | inst.error = BAD_PC; | |
7152 | break; | |
7153 | ||
c19d1205 ZW |
7154 | case OP_CPSF: |
7155 | case OP_ENDI: | |
7156 | case OP_oROR: | |
d2cd1205 JB |
7157 | case OP_wPSR: |
7158 | case OP_rPSR: | |
c19d1205 | 7159 | case OP_COND: |
52e7f43d | 7160 | case OP_oBARRIER_I15: |
c19d1205 ZW |
7161 | case OP_REGLST: |
7162 | case OP_VRSLST: | |
7163 | case OP_VRDLST: | |
477330fc RM |
7164 | case OP_VRSDLST: |
7165 | case OP_NRDLST: | |
7166 | case OP_NSTRLST: | |
c19d1205 ZW |
7167 | if (val == FAIL) |
7168 | goto failure; | |
7169 | inst.operands[i].imm = val; | |
7170 | break; | |
a737bd4d | 7171 | |
c19d1205 ZW |
7172 | default: |
7173 | break; | |
7174 | } | |
09d92015 | 7175 | |
c19d1205 ZW |
7176 | /* If we get here, this operand was successfully parsed. */ |
7177 | inst.operands[i].present = 1; | |
7178 | continue; | |
09d92015 | 7179 | |
c19d1205 | 7180 | bad_args: |
09d92015 | 7181 | inst.error = BAD_ARGS; |
c19d1205 ZW |
7182 | |
7183 | failure: | |
7184 | if (!backtrack_pos) | |
d252fdde PB |
7185 | { |
7186 | /* The parse routine should already have set inst.error, but set a | |
5f4273c7 | 7187 | default here just in case. */ |
d252fdde PB |
7188 | if (!inst.error) |
7189 | inst.error = _("syntax error"); | |
7190 | return FAIL; | |
7191 | } | |
c19d1205 ZW |
7192 | |
7193 | /* Do not backtrack over a trailing optional argument that | |
7194 | absorbed some text. We will only fail again, with the | |
7195 | 'garbage following instruction' error message, which is | |
7196 | probably less helpful than the current one. */ | |
7197 | if (backtrack_index == i && backtrack_pos != str | |
7198 | && upat[i+1] == OP_stop) | |
d252fdde PB |
7199 | { |
7200 | if (!inst.error) | |
7201 | inst.error = _("syntax error"); | |
7202 | return FAIL; | |
7203 | } | |
c19d1205 ZW |
7204 | |
7205 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
7206 | str = backtrack_pos; | |
7207 | inst.error = backtrack_error; | |
7208 | inst.operands[backtrack_index].present = 0; | |
7209 | i = backtrack_index; | |
7210 | backtrack_pos = 0; | |
09d92015 | 7211 | } |
09d92015 | 7212 | |
c19d1205 ZW |
7213 | /* Check that we have parsed all the arguments. */ |
7214 | if (*str != '\0' && !inst.error) | |
7215 | inst.error = _("garbage following instruction"); | |
09d92015 | 7216 | |
c19d1205 | 7217 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
7218 | } |
7219 | ||
c19d1205 ZW |
7220 | #undef po_char_or_fail |
7221 | #undef po_reg_or_fail | |
7222 | #undef po_reg_or_goto | |
7223 | #undef po_imm_or_fail | |
5287ad62 | 7224 | #undef po_scalar_or_fail |
52e7f43d | 7225 | #undef po_barrier_or_imm |
e07e6e58 | 7226 | |
c19d1205 | 7227 | /* Shorthand macro for instruction encoding functions issuing errors. */ |
e07e6e58 NC |
7228 | #define constraint(expr, err) \ |
7229 | do \ | |
c19d1205 | 7230 | { \ |
e07e6e58 NC |
7231 | if (expr) \ |
7232 | { \ | |
7233 | inst.error = err; \ | |
7234 | return; \ | |
7235 | } \ | |
c19d1205 | 7236 | } \ |
e07e6e58 | 7237 | while (0) |
c19d1205 | 7238 | |
fdfde340 JM |
7239 | /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2 |
7240 | instructions are unpredictable if these registers are used. This | |
7241 | is the BadReg predicate in ARM's Thumb-2 documentation. */ | |
7242 | #define reject_bad_reg(reg) \ | |
7243 | do \ | |
7244 | if (reg == REG_SP || reg == REG_PC) \ | |
7245 | { \ | |
7246 | inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \ | |
7247 | return; \ | |
7248 | } \ | |
7249 | while (0) | |
7250 | ||
94206790 MM |
7251 | /* If REG is R13 (the stack pointer), warn that its use is |
7252 | deprecated. */ | |
7253 | #define warn_deprecated_sp(reg) \ | |
7254 | do \ | |
7255 | if (warn_on_deprecated && reg == REG_SP) \ | |
5c3696f8 | 7256 | as_tsktsk (_("use of r13 is deprecated")); \ |
94206790 MM |
7257 | while (0) |
7258 | ||
c19d1205 ZW |
7259 | /* Functions for operand encoding. ARM, then Thumb. */ |
7260 | ||
d840c081 | 7261 | #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31)) |
c19d1205 ZW |
7262 | |
7263 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
7264 | return the encoded form. Otherwise, return FAIL. */ | |
7265 | ||
7266 | static unsigned int | |
7267 | encode_arm_immediate (unsigned int val) | |
09d92015 | 7268 | { |
c19d1205 ZW |
7269 | unsigned int a, i; |
7270 | ||
7271 | for (i = 0; i < 32; i += 2) | |
7272 | if ((a = rotate_left (val, i)) <= 0xff) | |
7273 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
7274 | ||
7275 | return FAIL; | |
09d92015 MM |
7276 | } |
7277 | ||
c19d1205 ZW |
7278 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
7279 | return the encoded form. Otherwise, return FAIL. */ | |
7280 | static unsigned int | |
7281 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 7282 | { |
c19d1205 | 7283 | unsigned int a, i; |
09d92015 | 7284 | |
9c3c69f2 | 7285 | if (val <= 0xff) |
c19d1205 | 7286 | return val; |
a737bd4d | 7287 | |
9c3c69f2 | 7288 | for (i = 1; i <= 24; i++) |
09d92015 | 7289 | { |
9c3c69f2 PB |
7290 | a = val >> i; |
7291 | if ((val & ~(0xff << i)) == 0) | |
7292 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 7293 | } |
a737bd4d | 7294 | |
c19d1205 ZW |
7295 | a = val & 0xff; |
7296 | if (val == ((a << 16) | a)) | |
7297 | return 0x100 | a; | |
7298 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
7299 | return 0x300 | a; | |
09d92015 | 7300 | |
c19d1205 ZW |
7301 | a = val & 0xff00; |
7302 | if (val == ((a << 16) | a)) | |
7303 | return 0x200 | (a >> 8); | |
a737bd4d | 7304 | |
c19d1205 | 7305 | return FAIL; |
09d92015 | 7306 | } |
5287ad62 | 7307 | /* Encode a VFP SP or DP register number into inst.instruction. */ |
09d92015 MM |
7308 | |
7309 | static void | |
5287ad62 JB |
7310 | encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos) |
7311 | { | |
7312 | if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm) | |
7313 | && reg > 15) | |
7314 | { | |
b1cc4aeb | 7315 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32)) |
477330fc RM |
7316 | { |
7317 | if (thumb_mode) | |
7318 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, | |
7319 | fpu_vfp_ext_d32); | |
7320 | else | |
7321 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, | |
7322 | fpu_vfp_ext_d32); | |
7323 | } | |
5287ad62 | 7324 | else |
477330fc RM |
7325 | { |
7326 | first_error (_("D register out of range for selected VFP version")); | |
7327 | return; | |
7328 | } | |
5287ad62 JB |
7329 | } |
7330 | ||
c19d1205 | 7331 | switch (pos) |
09d92015 | 7332 | { |
c19d1205 ZW |
7333 | case VFP_REG_Sd: |
7334 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
7335 | break; | |
7336 | ||
7337 | case VFP_REG_Sn: | |
7338 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
7339 | break; | |
7340 | ||
7341 | case VFP_REG_Sm: | |
7342 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
7343 | break; | |
7344 | ||
5287ad62 JB |
7345 | case VFP_REG_Dd: |
7346 | inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22); | |
7347 | break; | |
5f4273c7 | 7348 | |
5287ad62 JB |
7349 | case VFP_REG_Dn: |
7350 | inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7); | |
7351 | break; | |
5f4273c7 | 7352 | |
5287ad62 JB |
7353 | case VFP_REG_Dm: |
7354 | inst.instruction |= (reg & 15) | ((reg >> 4) << 5); | |
7355 | break; | |
7356 | ||
c19d1205 ZW |
7357 | default: |
7358 | abort (); | |
09d92015 | 7359 | } |
09d92015 MM |
7360 | } |
7361 | ||
c19d1205 | 7362 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 7363 | if any, is handled by md_apply_fix. */ |
09d92015 | 7364 | static void |
c19d1205 | 7365 | encode_arm_shift (int i) |
09d92015 | 7366 | { |
c19d1205 ZW |
7367 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
7368 | inst.instruction |= SHIFT_ROR << 5; | |
7369 | else | |
09d92015 | 7370 | { |
c19d1205 ZW |
7371 | inst.instruction |= inst.operands[i].shift_kind << 5; |
7372 | if (inst.operands[i].immisreg) | |
7373 | { | |
7374 | inst.instruction |= SHIFT_BY_REG; | |
7375 | inst.instruction |= inst.operands[i].imm << 8; | |
7376 | } | |
7377 | else | |
7378 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 7379 | } |
c19d1205 | 7380 | } |
09d92015 | 7381 | |
c19d1205 ZW |
7382 | static void |
7383 | encode_arm_shifter_operand (int i) | |
7384 | { | |
7385 | if (inst.operands[i].isreg) | |
09d92015 | 7386 | { |
c19d1205 ZW |
7387 | inst.instruction |= inst.operands[i].reg; |
7388 | encode_arm_shift (i); | |
09d92015 | 7389 | } |
c19d1205 | 7390 | else |
a415b1cd JB |
7391 | { |
7392 | inst.instruction |= INST_IMMEDIATE; | |
7393 | if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE) | |
7394 | inst.instruction |= inst.operands[i].imm; | |
7395 | } | |
09d92015 MM |
7396 | } |
7397 | ||
c19d1205 | 7398 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 7399 | static void |
c19d1205 | 7400 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 7401 | { |
2b2f5df9 NC |
7402 | /* PR 14260: |
7403 | Generate an error if the operand is not a register. */ | |
7404 | constraint (!inst.operands[i].isreg, | |
7405 | _("Instruction does not support =N addresses")); | |
7406 | ||
c19d1205 | 7407 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 7408 | |
c19d1205 | 7409 | if (inst.operands[i].preind) |
09d92015 | 7410 | { |
c19d1205 ZW |
7411 | if (is_t) |
7412 | { | |
7413 | inst.error = _("instruction does not accept preindexed addressing"); | |
7414 | return; | |
7415 | } | |
7416 | inst.instruction |= PRE_INDEX; | |
7417 | if (inst.operands[i].writeback) | |
7418 | inst.instruction |= WRITE_BACK; | |
09d92015 | 7419 | |
c19d1205 ZW |
7420 | } |
7421 | else if (inst.operands[i].postind) | |
7422 | { | |
9c2799c2 | 7423 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
7424 | if (is_t) |
7425 | inst.instruction |= WRITE_BACK; | |
7426 | } | |
7427 | else /* unindexed - only for coprocessor */ | |
09d92015 | 7428 | { |
c19d1205 | 7429 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
7430 | return; |
7431 | } | |
7432 | ||
c19d1205 ZW |
7433 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
7434 | && (((inst.instruction & 0x000f0000) >> 16) | |
7435 | == ((inst.instruction & 0x0000f000) >> 12))) | |
7436 | as_warn ((inst.instruction & LOAD_BIT) | |
7437 | ? _("destination register same as write-back base") | |
7438 | : _("source register same as write-back base")); | |
09d92015 MM |
7439 | } |
7440 | ||
c19d1205 ZW |
7441 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7442 | ARM-format mode 2 load or store instruction. If is_t is true, | |
7443 | reject forms that cannot be used with a T instruction (i.e. not | |
7444 | post-indexed). */ | |
a737bd4d | 7445 | static void |
c19d1205 | 7446 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 7447 | { |
5be8be5d DG |
7448 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
7449 | ||
c19d1205 | 7450 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7451 | |
c19d1205 | 7452 | if (inst.operands[i].immisreg) |
09d92015 | 7453 | { |
5be8be5d DG |
7454 | constraint ((inst.operands[i].imm == REG_PC |
7455 | || (is_pc && inst.operands[i].writeback)), | |
7456 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
7457 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
7458 | inst.instruction |= inst.operands[i].imm; | |
7459 | if (!inst.operands[i].negative) | |
7460 | inst.instruction |= INDEX_UP; | |
7461 | if (inst.operands[i].shifted) | |
7462 | { | |
7463 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
7464 | inst.instruction |= SHIFT_ROR << 5; | |
7465 | else | |
7466 | { | |
7467 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
7468 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
7469 | } | |
7470 | } | |
09d92015 | 7471 | } |
c19d1205 | 7472 | else /* immediate offset in inst.reloc */ |
09d92015 | 7473 | { |
5be8be5d DG |
7474 | if (is_pc && !inst.reloc.pc_rel) |
7475 | { | |
7476 | const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0); | |
23a10334 JZ |
7477 | |
7478 | /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt | |
7479 | cannot use PC in addressing. | |
7480 | PC cannot be used in writeback addressing, either. */ | |
7481 | constraint ((is_t || inst.operands[i].writeback), | |
5be8be5d | 7482 | BAD_PC_ADDRESSING); |
23a10334 | 7483 | |
dc5ec521 | 7484 | /* Use of PC in str is deprecated for ARMv7. */ |
23a10334 JZ |
7485 | if (warn_on_deprecated |
7486 | && !is_load | |
7487 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7)) | |
5c3696f8 | 7488 | as_tsktsk (_("use of PC in this instruction is deprecated")); |
5be8be5d DG |
7489 | } |
7490 | ||
c19d1205 | 7491 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
26d97720 NS |
7492 | { |
7493 | /* Prefer + for zero encoded value. */ | |
7494 | if (!inst.operands[i].negative) | |
7495 | inst.instruction |= INDEX_UP; | |
7496 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
7497 | } | |
09d92015 | 7498 | } |
09d92015 MM |
7499 | } |
7500 | ||
c19d1205 ZW |
7501 | /* inst.operands[i] was set up by parse_address. Encode it into an |
7502 | ARM-format mode 3 load or store instruction. Reject forms that | |
7503 | cannot be used with such instructions. If is_t is true, reject | |
7504 | forms that cannot be used with a T instruction (i.e. not | |
7505 | post-indexed). */ | |
7506 | static void | |
7507 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 7508 | { |
c19d1205 | 7509 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 7510 | { |
c19d1205 ZW |
7511 | inst.error = _("instruction does not accept scaled register index"); |
7512 | return; | |
09d92015 | 7513 | } |
a737bd4d | 7514 | |
c19d1205 | 7515 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 7516 | |
c19d1205 ZW |
7517 | if (inst.operands[i].immisreg) |
7518 | { | |
5be8be5d | 7519 | constraint ((inst.operands[i].imm == REG_PC |
eb9f3f00 | 7520 | || (is_t && inst.operands[i].reg == REG_PC)), |
5be8be5d | 7521 | BAD_PC_ADDRESSING); |
eb9f3f00 JB |
7522 | constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback, |
7523 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7524 | inst.instruction |= inst.operands[i].imm; |
7525 | if (!inst.operands[i].negative) | |
7526 | inst.instruction |= INDEX_UP; | |
7527 | } | |
7528 | else /* immediate offset in inst.reloc */ | |
7529 | { | |
5be8be5d DG |
7530 | constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel |
7531 | && inst.operands[i].writeback), | |
7532 | BAD_PC_WRITEBACK); | |
c19d1205 ZW |
7533 | inst.instruction |= HWOFFSET_IMM; |
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 | ||
7540 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
7541 | } | |
c19d1205 | 7542 | } |
a737bd4d NC |
7543 | } |
7544 | ||
8335d6aa JW |
7545 | /* Write immediate bits [7:0] to the following locations: |
7546 | ||
7547 | |28/24|23 19|18 16|15 4|3 0| | |
7548 | | 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| | |
7549 | ||
7550 | This function is used by VMOV/VMVN/VORR/VBIC. */ | |
7551 | ||
7552 | static void | |
7553 | neon_write_immbits (unsigned immbits) | |
7554 | { | |
7555 | inst.instruction |= immbits & 0xf; | |
7556 | inst.instruction |= ((immbits >> 4) & 0x7) << 16; | |
7557 | inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24); | |
7558 | } | |
7559 | ||
7560 | /* Invert low-order SIZE bits of XHI:XLO. */ | |
7561 | ||
7562 | static void | |
7563 | neon_invert_size (unsigned *xlo, unsigned *xhi, int size) | |
7564 | { | |
7565 | unsigned immlo = xlo ? *xlo : 0; | |
7566 | unsigned immhi = xhi ? *xhi : 0; | |
7567 | ||
7568 | switch (size) | |
7569 | { | |
7570 | case 8: | |
7571 | immlo = (~immlo) & 0xff; | |
7572 | break; | |
7573 | ||
7574 | case 16: | |
7575 | immlo = (~immlo) & 0xffff; | |
7576 | break; | |
7577 | ||
7578 | case 64: | |
7579 | immhi = (~immhi) & 0xffffffff; | |
7580 | /* fall through. */ | |
7581 | ||
7582 | case 32: | |
7583 | immlo = (~immlo) & 0xffffffff; | |
7584 | break; | |
7585 | ||
7586 | default: | |
7587 | abort (); | |
7588 | } | |
7589 | ||
7590 | if (xlo) | |
7591 | *xlo = immlo; | |
7592 | ||
7593 | if (xhi) | |
7594 | *xhi = immhi; | |
7595 | } | |
7596 | ||
7597 | /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits | |
7598 | A, B, C, D. */ | |
09d92015 | 7599 | |
c19d1205 | 7600 | static int |
8335d6aa | 7601 | neon_bits_same_in_bytes (unsigned imm) |
09d92015 | 7602 | { |
8335d6aa JW |
7603 | return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff) |
7604 | && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00) | |
7605 | && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000) | |
7606 | && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000); | |
7607 | } | |
a737bd4d | 7608 | |
8335d6aa | 7609 | /* For immediate of above form, return 0bABCD. */ |
09d92015 | 7610 | |
8335d6aa JW |
7611 | static unsigned |
7612 | neon_squash_bits (unsigned imm) | |
7613 | { | |
7614 | return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14) | |
7615 | | ((imm & 0x01000000) >> 21); | |
7616 | } | |
7617 | ||
7618 | /* Compress quarter-float representation to 0b...000 abcdefgh. */ | |
7619 | ||
7620 | static unsigned | |
7621 | neon_qfloat_bits (unsigned imm) | |
7622 | { | |
7623 | return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80); | |
7624 | } | |
7625 | ||
7626 | /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into | |
7627 | the instruction. *OP is passed as the initial value of the op field, and | |
7628 | may be set to a different value depending on the constant (i.e. | |
7629 | "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not | |
7630 | MVN). If the immediate looks like a repeated pattern then also | |
7631 | try smaller element sizes. */ | |
7632 | ||
7633 | static int | |
7634 | neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p, | |
7635 | unsigned *immbits, int *op, int size, | |
7636 | enum neon_el_type type) | |
7637 | { | |
7638 | /* Only permit float immediates (including 0.0/-0.0) if the operand type is | |
7639 | float. */ | |
7640 | if (type == NT_float && !float_p) | |
7641 | return FAIL; | |
7642 | ||
7643 | if (type == NT_float && is_quarter_float (immlo) && immhi == 0) | |
09d92015 | 7644 | { |
8335d6aa JW |
7645 | if (size != 32 || *op == 1) |
7646 | return FAIL; | |
7647 | *immbits = neon_qfloat_bits (immlo); | |
7648 | return 0xf; | |
7649 | } | |
7650 | ||
7651 | if (size == 64) | |
7652 | { | |
7653 | if (neon_bits_same_in_bytes (immhi) | |
7654 | && neon_bits_same_in_bytes (immlo)) | |
c19d1205 | 7655 | { |
8335d6aa JW |
7656 | if (*op == 1) |
7657 | return FAIL; | |
7658 | *immbits = (neon_squash_bits (immhi) << 4) | |
7659 | | neon_squash_bits (immlo); | |
7660 | *op = 1; | |
7661 | return 0xe; | |
c19d1205 | 7662 | } |
a737bd4d | 7663 | |
8335d6aa JW |
7664 | if (immhi != immlo) |
7665 | return FAIL; | |
7666 | } | |
a737bd4d | 7667 | |
8335d6aa | 7668 | if (size >= 32) |
09d92015 | 7669 | { |
8335d6aa | 7670 | if (immlo == (immlo & 0x000000ff)) |
c19d1205 | 7671 | { |
8335d6aa JW |
7672 | *immbits = immlo; |
7673 | return 0x0; | |
c19d1205 | 7674 | } |
8335d6aa | 7675 | else if (immlo == (immlo & 0x0000ff00)) |
c19d1205 | 7676 | { |
8335d6aa JW |
7677 | *immbits = immlo >> 8; |
7678 | return 0x2; | |
c19d1205 | 7679 | } |
8335d6aa JW |
7680 | else if (immlo == (immlo & 0x00ff0000)) |
7681 | { | |
7682 | *immbits = immlo >> 16; | |
7683 | return 0x4; | |
7684 | } | |
7685 | else if (immlo == (immlo & 0xff000000)) | |
7686 | { | |
7687 | *immbits = immlo >> 24; | |
7688 | return 0x6; | |
7689 | } | |
7690 | else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff)) | |
7691 | { | |
7692 | *immbits = (immlo >> 8) & 0xff; | |
7693 | return 0xc; | |
7694 | } | |
7695 | else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff)) | |
7696 | { | |
7697 | *immbits = (immlo >> 16) & 0xff; | |
7698 | return 0xd; | |
7699 | } | |
7700 | ||
7701 | if ((immlo & 0xffff) != (immlo >> 16)) | |
7702 | return FAIL; | |
7703 | immlo &= 0xffff; | |
09d92015 | 7704 | } |
a737bd4d | 7705 | |
8335d6aa | 7706 | if (size >= 16) |
4962c51a | 7707 | { |
8335d6aa JW |
7708 | if (immlo == (immlo & 0x000000ff)) |
7709 | { | |
7710 | *immbits = immlo; | |
7711 | return 0x8; | |
7712 | } | |
7713 | else if (immlo == (immlo & 0x0000ff00)) | |
7714 | { | |
7715 | *immbits = immlo >> 8; | |
7716 | return 0xa; | |
7717 | } | |
7718 | ||
7719 | if ((immlo & 0xff) != (immlo >> 8)) | |
7720 | return FAIL; | |
7721 | immlo &= 0xff; | |
4962c51a MS |
7722 | } |
7723 | ||
8335d6aa JW |
7724 | if (immlo == (immlo & 0x000000ff)) |
7725 | { | |
7726 | /* Don't allow MVN with 8-bit immediate. */ | |
7727 | if (*op == 1) | |
7728 | return FAIL; | |
7729 | *immbits = immlo; | |
7730 | return 0xe; | |
7731 | } | |
26d97720 | 7732 | |
8335d6aa | 7733 | return FAIL; |
c19d1205 | 7734 | } |
a737bd4d | 7735 | |
5fc177c8 | 7736 | #if defined BFD_HOST_64_BIT |
ba592044 AM |
7737 | /* Returns TRUE if double precision value V may be cast |
7738 | to single precision without loss of accuracy. */ | |
7739 | ||
7740 | static bfd_boolean | |
5fc177c8 | 7741 | is_double_a_single (bfd_int64_t v) |
ba592044 | 7742 | { |
5fc177c8 | 7743 | int exp = (int)((v >> 52) & 0x7FF); |
8fe3f3d6 | 7744 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
7745 | |
7746 | return (exp == 0 || exp == 0x7FF | |
7747 | || (exp >= 1023 - 126 && exp <= 1023 + 127)) | |
7748 | && (mantissa & 0x1FFFFFFFl) == 0; | |
7749 | } | |
7750 | ||
3739860c | 7751 | /* Returns a double precision value casted to single precision |
ba592044 AM |
7752 | (ignoring the least significant bits in exponent and mantissa). */ |
7753 | ||
7754 | static int | |
5fc177c8 | 7755 | double_to_single (bfd_int64_t v) |
ba592044 AM |
7756 | { |
7757 | int sign = (int) ((v >> 63) & 1l); | |
5fc177c8 | 7758 | int exp = (int) ((v >> 52) & 0x7FF); |
8fe3f3d6 | 7759 | bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL); |
ba592044 AM |
7760 | |
7761 | if (exp == 0x7FF) | |
7762 | exp = 0xFF; | |
7763 | else | |
7764 | { | |
7765 | exp = exp - 1023 + 127; | |
7766 | if (exp >= 0xFF) | |
7767 | { | |
7768 | /* Infinity. */ | |
7769 | exp = 0x7F; | |
7770 | mantissa = 0; | |
7771 | } | |
7772 | else if (exp < 0) | |
7773 | { | |
7774 | /* No denormalized numbers. */ | |
7775 | exp = 0; | |
7776 | mantissa = 0; | |
7777 | } | |
7778 | } | |
7779 | mantissa >>= 29; | |
7780 | return (sign << 31) | (exp << 23) | mantissa; | |
7781 | } | |
5fc177c8 | 7782 | #endif /* BFD_HOST_64_BIT */ |
ba592044 | 7783 | |
8335d6aa JW |
7784 | enum lit_type |
7785 | { | |
7786 | CONST_THUMB, | |
7787 | CONST_ARM, | |
7788 | CONST_VEC | |
7789 | }; | |
7790 | ||
ba592044 AM |
7791 | static void do_vfp_nsyn_opcode (const char *); |
7792 | ||
c19d1205 ZW |
7793 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
7794 | Determine whether it can be performed with a move instruction; if | |
7795 | it can, convert inst.instruction to that move instruction and | |
c921be7d NC |
7796 | return TRUE; if it can't, convert inst.instruction to a literal-pool |
7797 | load and return FALSE. If this is not a valid thing to do in the | |
7798 | current context, set inst.error and return TRUE. | |
a737bd4d | 7799 | |
c19d1205 ZW |
7800 | inst.operands[i] describes the destination register. */ |
7801 | ||
c921be7d | 7802 | static bfd_boolean |
8335d6aa | 7803 | move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3) |
c19d1205 | 7804 | { |
53365c0d | 7805 | unsigned long tbit; |
8335d6aa JW |
7806 | bfd_boolean thumb_p = (t == CONST_THUMB); |
7807 | bfd_boolean arm_p = (t == CONST_ARM); | |
53365c0d PB |
7808 | |
7809 | if (thumb_p) | |
7810 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
7811 | else | |
7812 | tbit = LOAD_BIT; | |
7813 | ||
7814 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 7815 | { |
c19d1205 | 7816 | inst.error = _("invalid pseudo operation"); |
c921be7d | 7817 | return TRUE; |
09d92015 | 7818 | } |
ba592044 | 7819 | |
8335d6aa JW |
7820 | if (inst.reloc.exp.X_op != O_constant |
7821 | && inst.reloc.exp.X_op != O_symbol | |
7822 | && inst.reloc.exp.X_op != O_big) | |
09d92015 MM |
7823 | { |
7824 | inst.error = _("constant expression expected"); | |
c921be7d | 7825 | return TRUE; |
09d92015 | 7826 | } |
ba592044 AM |
7827 | |
7828 | if (inst.reloc.exp.X_op == O_constant | |
7829 | || inst.reloc.exp.X_op == O_big) | |
8335d6aa | 7830 | { |
5fc177c8 NC |
7831 | #if defined BFD_HOST_64_BIT |
7832 | bfd_int64_t v; | |
7833 | #else | |
ba592044 | 7834 | offsetT v; |
5fc177c8 | 7835 | #endif |
ba592044 | 7836 | if (inst.reloc.exp.X_op == O_big) |
8335d6aa | 7837 | { |
ba592044 AM |
7838 | LITTLENUM_TYPE w[X_PRECISION]; |
7839 | LITTLENUM_TYPE * l; | |
7840 | ||
7841 | if (inst.reloc.exp.X_add_number == -1) | |
8335d6aa | 7842 | { |
ba592044 AM |
7843 | gen_to_words (w, X_PRECISION, E_PRECISION); |
7844 | l = w; | |
7845 | /* FIXME: Should we check words w[2..5] ? */ | |
8335d6aa | 7846 | } |
ba592044 AM |
7847 | else |
7848 | l = generic_bignum; | |
3739860c | 7849 | |
5fc177c8 NC |
7850 | #if defined BFD_HOST_64_BIT |
7851 | v = | |
7852 | ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK) | |
7853 | << LITTLENUM_NUMBER_OF_BITS) | |
7854 | | ((bfd_int64_t) l[2] & LITTLENUM_MASK)) | |
7855 | << LITTLENUM_NUMBER_OF_BITS) | |
7856 | | ((bfd_int64_t) l[1] & LITTLENUM_MASK)) | |
7857 | << LITTLENUM_NUMBER_OF_BITS) | |
7858 | | ((bfd_int64_t) l[0] & LITTLENUM_MASK)); | |
7859 | #else | |
ba592044 AM |
7860 | v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS) |
7861 | | (l[0] & LITTLENUM_MASK); | |
5fc177c8 | 7862 | #endif |
8335d6aa | 7863 | } |
ba592044 AM |
7864 | else |
7865 | v = inst.reloc.exp.X_add_number; | |
7866 | ||
7867 | if (!inst.operands[i].issingle) | |
8335d6aa | 7868 | { |
12569877 | 7869 | if (thumb_p) |
8335d6aa | 7870 | { |
2c32be70 CM |
7871 | /* This can be encoded only for a low register. */ |
7872 | if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8)) | |
ba592044 AM |
7873 | { |
7874 | /* This can be done with a mov(1) instruction. */ | |
7875 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
7876 | inst.instruction |= v; | |
7877 | return TRUE; | |
7878 | } | |
12569877 | 7879 | |
ff8646ee TP |
7880 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2) |
7881 | || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
12569877 | 7882 | { |
fc289b0a TP |
7883 | /* Check if on thumb2 it can be done with a mov.w, mvn or |
7884 | movw instruction. */ | |
12569877 AM |
7885 | unsigned int newimm; |
7886 | bfd_boolean isNegated; | |
7887 | ||
7888 | newimm = encode_thumb32_immediate (v); | |
7889 | if (newimm != (unsigned int) FAIL) | |
7890 | isNegated = FALSE; | |
7891 | else | |
7892 | { | |
582cfe03 | 7893 | newimm = encode_thumb32_immediate (~v); |
12569877 AM |
7894 | if (newimm != (unsigned int) FAIL) |
7895 | isNegated = TRUE; | |
7896 | } | |
7897 | ||
fc289b0a TP |
7898 | /* The number can be loaded with a mov.w or mvn |
7899 | instruction. */ | |
ff8646ee TP |
7900 | if (newimm != (unsigned int) FAIL |
7901 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) | |
12569877 | 7902 | { |
fc289b0a | 7903 | inst.instruction = (0xf04f0000 /* MOV.W. */ |
582cfe03 | 7904 | | (inst.operands[i].reg << 8)); |
fc289b0a | 7905 | /* Change to MOVN. */ |
582cfe03 | 7906 | inst.instruction |= (isNegated ? 0x200000 : 0); |
12569877 AM |
7907 | inst.instruction |= (newimm & 0x800) << 15; |
7908 | inst.instruction |= (newimm & 0x700) << 4; | |
7909 | inst.instruction |= (newimm & 0x0ff); | |
7910 | return TRUE; | |
7911 | } | |
fc289b0a | 7912 | /* The number can be loaded with a movw instruction. */ |
ff8646ee TP |
7913 | else if ((v & ~0xFFFF) == 0 |
7914 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)) | |
3739860c | 7915 | { |
582cfe03 | 7916 | int imm = v & 0xFFFF; |
12569877 | 7917 | |
582cfe03 | 7918 | inst.instruction = 0xf2400000; /* MOVW. */ |
12569877 AM |
7919 | inst.instruction |= (inst.operands[i].reg << 8); |
7920 | inst.instruction |= (imm & 0xf000) << 4; | |
7921 | inst.instruction |= (imm & 0x0800) << 15; | |
7922 | inst.instruction |= (imm & 0x0700) << 4; | |
7923 | inst.instruction |= (imm & 0x00ff); | |
7924 | return TRUE; | |
7925 | } | |
7926 | } | |
8335d6aa | 7927 | } |
12569877 | 7928 | else if (arm_p) |
ba592044 AM |
7929 | { |
7930 | int value = encode_arm_immediate (v); | |
12569877 | 7931 | |
ba592044 AM |
7932 | if (value != FAIL) |
7933 | { | |
7934 | /* This can be done with a mov instruction. */ | |
7935 | inst.instruction &= LITERAL_MASK; | |
7936 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
7937 | inst.instruction |= value & 0xfff; | |
7938 | return TRUE; | |
7939 | } | |
8335d6aa | 7940 | |
ba592044 AM |
7941 | value = encode_arm_immediate (~ v); |
7942 | if (value != FAIL) | |
7943 | { | |
7944 | /* This can be done with a mvn instruction. */ | |
7945 | inst.instruction &= LITERAL_MASK; | |
7946 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
7947 | inst.instruction |= value & 0xfff; | |
7948 | return TRUE; | |
7949 | } | |
7950 | } | |
7951 | else if (t == CONST_VEC) | |
8335d6aa | 7952 | { |
ba592044 AM |
7953 | int op = 0; |
7954 | unsigned immbits = 0; | |
7955 | unsigned immlo = inst.operands[1].imm; | |
7956 | unsigned immhi = inst.operands[1].regisimm | |
7957 | ? inst.operands[1].reg | |
7958 | : inst.reloc.exp.X_unsigned | |
7959 | ? 0 | |
7960 | : ((bfd_int64_t)((int) immlo)) >> 32; | |
7961 | int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
7962 | &op, 64, NT_invtype); | |
7963 | ||
7964 | if (cmode == FAIL) | |
7965 | { | |
7966 | neon_invert_size (&immlo, &immhi, 64); | |
7967 | op = !op; | |
7968 | cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits, | |
7969 | &op, 64, NT_invtype); | |
7970 | } | |
7971 | ||
7972 | if (cmode != FAIL) | |
7973 | { | |
7974 | inst.instruction = (inst.instruction & VLDR_VMOV_SAME) | |
7975 | | (1 << 23) | |
7976 | | (cmode << 8) | |
7977 | | (op << 5) | |
7978 | | (1 << 4); | |
7979 | ||
7980 | /* Fill other bits in vmov encoding for both thumb and arm. */ | |
7981 | if (thumb_mode) | |
eff0bc54 | 7982 | inst.instruction |= (0x7U << 29) | (0xF << 24); |
ba592044 | 7983 | else |
eff0bc54 | 7984 | inst.instruction |= (0xFU << 28) | (0x1 << 25); |
ba592044 AM |
7985 | neon_write_immbits (immbits); |
7986 | return TRUE; | |
7987 | } | |
8335d6aa JW |
7988 | } |
7989 | } | |
8335d6aa | 7990 | |
ba592044 AM |
7991 | if (t == CONST_VEC) |
7992 | { | |
7993 | /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */ | |
7994 | if (inst.operands[i].issingle | |
7995 | && is_quarter_float (inst.operands[1].imm) | |
7996 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd)) | |
8335d6aa | 7997 | { |
ba592044 AM |
7998 | inst.operands[1].imm = |
7999 | neon_qfloat_bits (v); | |
8000 | do_vfp_nsyn_opcode ("fconsts"); | |
8001 | return TRUE; | |
8335d6aa | 8002 | } |
5fc177c8 NC |
8003 | |
8004 | /* If our host does not support a 64-bit type then we cannot perform | |
8005 | the following optimization. This mean that there will be a | |
8006 | discrepancy between the output produced by an assembler built for | |
8007 | a 32-bit-only host and the output produced from a 64-bit host, but | |
8008 | this cannot be helped. */ | |
8009 | #if defined BFD_HOST_64_BIT | |
ba592044 AM |
8010 | else if (!inst.operands[1].issingle |
8011 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3)) | |
8335d6aa | 8012 | { |
ba592044 AM |
8013 | if (is_double_a_single (v) |
8014 | && is_quarter_float (double_to_single (v))) | |
8015 | { | |
8016 | inst.operands[1].imm = | |
8017 | neon_qfloat_bits (double_to_single (v)); | |
8018 | do_vfp_nsyn_opcode ("fconstd"); | |
8019 | return TRUE; | |
8020 | } | |
8335d6aa | 8021 | } |
5fc177c8 | 8022 | #endif |
8335d6aa JW |
8023 | } |
8024 | } | |
8025 | ||
8026 | if (add_to_lit_pool ((!inst.operands[i].isvec | |
8027 | || inst.operands[i].issingle) ? 4 : 8) == FAIL) | |
8028 | return TRUE; | |
8029 | ||
8030 | inst.operands[1].reg = REG_PC; | |
8031 | inst.operands[1].isreg = 1; | |
8032 | inst.operands[1].preind = 1; | |
8033 | inst.reloc.pc_rel = 1; | |
8034 | inst.reloc.type = (thumb_p | |
8035 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
8036 | : (mode_3 | |
8037 | ? BFD_RELOC_ARM_HWLITERAL | |
8038 | : BFD_RELOC_ARM_LITERAL)); | |
8039 | return FALSE; | |
8040 | } | |
8041 | ||
8042 | /* inst.operands[i] was set up by parse_address. Encode it into an | |
8043 | ARM-format instruction. Reject all forms which cannot be encoded | |
8044 | into a coprocessor load/store instruction. If wb_ok is false, | |
8045 | reject use of writeback; if unind_ok is false, reject use of | |
8046 | unindexed addressing. If reloc_override is not 0, use it instead | |
8047 | of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one | |
8048 | (in which case it is preserved). */ | |
8049 | ||
8050 | static int | |
8051 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
8052 | { | |
8053 | if (!inst.operands[i].isreg) | |
8054 | { | |
99b2a2dd NC |
8055 | /* PR 18256 */ |
8056 | if (! inst.operands[0].isvec) | |
8057 | { | |
8058 | inst.error = _("invalid co-processor operand"); | |
8059 | return FAIL; | |
8060 | } | |
8335d6aa JW |
8061 | if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE)) |
8062 | return SUCCESS; | |
8063 | } | |
8064 | ||
8065 | inst.instruction |= inst.operands[i].reg << 16; | |
8066 | ||
8067 | gas_assert (!(inst.operands[i].preind && inst.operands[i].postind)); | |
8068 | ||
8069 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ | |
8070 | { | |
8071 | gas_assert (!inst.operands[i].writeback); | |
8072 | if (!unind_ok) | |
8073 | { | |
8074 | inst.error = _("instruction does not support unindexed addressing"); | |
8075 | return FAIL; | |
8076 | } | |
8077 | inst.instruction |= inst.operands[i].imm; | |
8078 | inst.instruction |= INDEX_UP; | |
8079 | return SUCCESS; | |
8080 | } | |
8081 | ||
8082 | if (inst.operands[i].preind) | |
8083 | inst.instruction |= PRE_INDEX; | |
8084 | ||
8085 | if (inst.operands[i].writeback) | |
09d92015 | 8086 | { |
8335d6aa | 8087 | if (inst.operands[i].reg == REG_PC) |
c19d1205 | 8088 | { |
8335d6aa JW |
8089 | inst.error = _("pc may not be used with write-back"); |
8090 | return FAIL; | |
c19d1205 | 8091 | } |
8335d6aa | 8092 | if (!wb_ok) |
c19d1205 | 8093 | { |
8335d6aa JW |
8094 | inst.error = _("instruction does not support writeback"); |
8095 | return FAIL; | |
c19d1205 | 8096 | } |
8335d6aa | 8097 | inst.instruction |= WRITE_BACK; |
09d92015 MM |
8098 | } |
8099 | ||
8335d6aa JW |
8100 | if (reloc_override) |
8101 | inst.reloc.type = (bfd_reloc_code_real_type) reloc_override; | |
8102 | else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC | |
8103 | || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2) | |
8104 | && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0) | |
c19d1205 | 8105 | { |
8335d6aa JW |
8106 | if (thumb_mode) |
8107 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
8108 | else | |
8109 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; | |
c19d1205 | 8110 | } |
8335d6aa JW |
8111 | |
8112 | /* Prefer + for zero encoded value. */ | |
8113 | if (!inst.operands[i].negative) | |
8114 | inst.instruction |= INDEX_UP; | |
8115 | ||
8116 | return SUCCESS; | |
09d92015 MM |
8117 | } |
8118 | ||
5f4273c7 | 8119 | /* Functions for instruction encoding, sorted by sub-architecture. |
c19d1205 ZW |
8120 | First some generics; their names are taken from the conventional |
8121 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 8122 | |
a737bd4d | 8123 | static void |
c19d1205 | 8124 | do_noargs (void) |
09d92015 | 8125 | { |
c19d1205 | 8126 | } |
a737bd4d | 8127 | |
c19d1205 ZW |
8128 | static void |
8129 | do_rd (void) | |
8130 | { | |
8131 | inst.instruction |= inst.operands[0].reg << 12; | |
8132 | } | |
a737bd4d | 8133 | |
c19d1205 ZW |
8134 | static void |
8135 | do_rd_rm (void) | |
8136 | { | |
8137 | inst.instruction |= inst.operands[0].reg << 12; | |
8138 | inst.instruction |= inst.operands[1].reg; | |
8139 | } | |
09d92015 | 8140 | |
9eb6c0f1 MGD |
8141 | static void |
8142 | do_rm_rn (void) | |
8143 | { | |
8144 | inst.instruction |= inst.operands[0].reg; | |
8145 | inst.instruction |= inst.operands[1].reg << 16; | |
8146 | } | |
8147 | ||
c19d1205 ZW |
8148 | static void |
8149 | do_rd_rn (void) | |
8150 | { | |
8151 | inst.instruction |= inst.operands[0].reg << 12; | |
8152 | inst.instruction |= inst.operands[1].reg << 16; | |
8153 | } | |
a737bd4d | 8154 | |
c19d1205 ZW |
8155 | static void |
8156 | do_rn_rd (void) | |
8157 | { | |
8158 | inst.instruction |= inst.operands[0].reg << 16; | |
8159 | inst.instruction |= inst.operands[1].reg << 12; | |
8160 | } | |
09d92015 | 8161 | |
4ed7ed8d TP |
8162 | static void |
8163 | do_tt (void) | |
8164 | { | |
8165 | inst.instruction |= inst.operands[0].reg << 8; | |
8166 | inst.instruction |= inst.operands[1].reg << 16; | |
8167 | } | |
8168 | ||
59d09be6 MGD |
8169 | static bfd_boolean |
8170 | check_obsolete (const arm_feature_set *feature, const char *msg) | |
8171 | { | |
8172 | if (ARM_CPU_IS_ANY (cpu_variant)) | |
8173 | { | |
5c3696f8 | 8174 | as_tsktsk ("%s", msg); |
59d09be6 MGD |
8175 | return TRUE; |
8176 | } | |
8177 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature)) | |
8178 | { | |
8179 | as_bad ("%s", msg); | |
8180 | return TRUE; | |
8181 | } | |
8182 | ||
8183 | return FALSE; | |
8184 | } | |
8185 | ||
c19d1205 ZW |
8186 | static void |
8187 | do_rd_rm_rn (void) | |
8188 | { | |
9a64e435 | 8189 | unsigned Rn = inst.operands[2].reg; |
708587a4 | 8190 | /* Enforce restrictions on SWP instruction. */ |
9a64e435 | 8191 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) |
56adecf4 DG |
8192 | { |
8193 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
8194 | _("Rn must not overlap other operands")); | |
8195 | ||
59d09be6 MGD |
8196 | /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7. |
8197 | */ | |
8198 | if (!check_obsolete (&arm_ext_v8, | |
8199 | _("swp{b} use is obsoleted for ARMv8 and later")) | |
8200 | && warn_on_deprecated | |
8201 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6)) | |
5c3696f8 | 8202 | as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7")); |
56adecf4 | 8203 | } |
59d09be6 | 8204 | |
c19d1205 ZW |
8205 | inst.instruction |= inst.operands[0].reg << 12; |
8206 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 8207 | inst.instruction |= Rn << 16; |
c19d1205 | 8208 | } |
09d92015 | 8209 | |
c19d1205 ZW |
8210 | static void |
8211 | do_rd_rn_rm (void) | |
8212 | { | |
8213 | inst.instruction |= inst.operands[0].reg << 12; | |
8214 | inst.instruction |= inst.operands[1].reg << 16; | |
8215 | inst.instruction |= inst.operands[2].reg; | |
8216 | } | |
a737bd4d | 8217 | |
c19d1205 ZW |
8218 | static void |
8219 | do_rm_rd_rn (void) | |
8220 | { | |
5be8be5d DG |
8221 | constraint ((inst.operands[2].reg == REG_PC), BAD_PC); |
8222 | constraint (((inst.reloc.exp.X_op != O_constant | |
8223 | && inst.reloc.exp.X_op != O_illegal) | |
8224 | || inst.reloc.exp.X_add_number != 0), | |
8225 | BAD_ADDR_MODE); | |
c19d1205 ZW |
8226 | inst.instruction |= inst.operands[0].reg; |
8227 | inst.instruction |= inst.operands[1].reg << 12; | |
8228 | inst.instruction |= inst.operands[2].reg << 16; | |
8229 | } | |
09d92015 | 8230 | |
c19d1205 ZW |
8231 | static void |
8232 | do_imm0 (void) | |
8233 | { | |
8234 | inst.instruction |= inst.operands[0].imm; | |
8235 | } | |
09d92015 | 8236 | |
c19d1205 ZW |
8237 | static void |
8238 | do_rd_cpaddr (void) | |
8239 | { | |
8240 | inst.instruction |= inst.operands[0].reg << 12; | |
8241 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 8242 | } |
a737bd4d | 8243 | |
c19d1205 ZW |
8244 | /* ARM instructions, in alphabetical order by function name (except |
8245 | that wrapper functions appear immediately after the function they | |
8246 | wrap). */ | |
09d92015 | 8247 | |
c19d1205 ZW |
8248 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
8249 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
8250 | |
8251 | static void | |
c19d1205 | 8252 | do_adr (void) |
09d92015 | 8253 | { |
c19d1205 | 8254 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 8255 | |
c19d1205 ZW |
8256 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8257 | out to be negative. */ | |
8258 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 8259 | inst.reloc.pc_rel = 1; |
2fc8bdac | 8260 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 8261 | } |
b99bd4ef | 8262 | |
c19d1205 ZW |
8263 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
8264 | into a relative address of the form: | |
8265 | add rd, pc, #low(label-.-8)" | |
8266 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 8267 | |
c19d1205 ZW |
8268 | static void |
8269 | do_adrl (void) | |
8270 | { | |
8271 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 8272 | |
c19d1205 ZW |
8273 | /* Frag hacking will turn this into a sub instruction if the offset turns |
8274 | out to be negative. */ | |
8275 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
8276 | inst.reloc.pc_rel = 1; |
8277 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 8278 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
8279 | } |
8280 | ||
b99bd4ef | 8281 | static void |
c19d1205 | 8282 | do_arit (void) |
b99bd4ef | 8283 | { |
c19d1205 ZW |
8284 | if (!inst.operands[1].present) |
8285 | inst.operands[1].reg = inst.operands[0].reg; | |
8286 | inst.instruction |= inst.operands[0].reg << 12; | |
8287 | inst.instruction |= inst.operands[1].reg << 16; | |
8288 | encode_arm_shifter_operand (2); | |
8289 | } | |
b99bd4ef | 8290 | |
62b3e311 PB |
8291 | static void |
8292 | do_barrier (void) | |
8293 | { | |
8294 | if (inst.operands[0].present) | |
ccb84d65 | 8295 | inst.instruction |= inst.operands[0].imm; |
62b3e311 PB |
8296 | else |
8297 | inst.instruction |= 0xf; | |
8298 | } | |
8299 | ||
c19d1205 ZW |
8300 | static void |
8301 | do_bfc (void) | |
8302 | { | |
8303 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
8304 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8305 | /* The instruction encoding stores the LSB and MSB, | |
8306 | not the LSB and width. */ | |
8307 | inst.instruction |= inst.operands[0].reg << 12; | |
8308 | inst.instruction |= inst.operands[1].imm << 7; | |
8309 | inst.instruction |= (msb - 1) << 16; | |
8310 | } | |
b99bd4ef | 8311 | |
c19d1205 ZW |
8312 | static void |
8313 | do_bfi (void) | |
8314 | { | |
8315 | unsigned int msb; | |
b99bd4ef | 8316 | |
c19d1205 ZW |
8317 | /* #0 in second position is alternative syntax for bfc, which is |
8318 | the same instruction but with REG_PC in the Rm field. */ | |
8319 | if (!inst.operands[1].isreg) | |
8320 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 8321 | |
c19d1205 ZW |
8322 | msb = inst.operands[2].imm + inst.operands[3].imm; |
8323 | constraint (msb > 32, _("bit-field extends past end of register")); | |
8324 | /* The instruction encoding stores the LSB and MSB, | |
8325 | not the LSB and width. */ | |
8326 | inst.instruction |= inst.operands[0].reg << 12; | |
8327 | inst.instruction |= inst.operands[1].reg; | |
8328 | inst.instruction |= inst.operands[2].imm << 7; | |
8329 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
8330 | } |
8331 | ||
b99bd4ef | 8332 | static void |
c19d1205 | 8333 | do_bfx (void) |
b99bd4ef | 8334 | { |
c19d1205 ZW |
8335 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
8336 | _("bit-field extends past end of register")); | |
8337 | inst.instruction |= inst.operands[0].reg << 12; | |
8338 | inst.instruction |= inst.operands[1].reg; | |
8339 | inst.instruction |= inst.operands[2].imm << 7; | |
8340 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
8341 | } | |
09d92015 | 8342 | |
c19d1205 ZW |
8343 | /* ARM V5 breakpoint instruction (argument parse) |
8344 | BKPT <16 bit unsigned immediate> | |
8345 | Instruction is not conditional. | |
8346 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
8347 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 8348 | |
c19d1205 ZW |
8349 | static void |
8350 | do_bkpt (void) | |
8351 | { | |
8352 | /* Top 12 of 16 bits to bits 19:8. */ | |
8353 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 8354 | |
c19d1205 ZW |
8355 | /* Bottom 4 of 16 bits to bits 3:0. */ |
8356 | inst.instruction |= inst.operands[0].imm & 0xf; | |
8357 | } | |
09d92015 | 8358 | |
c19d1205 ZW |
8359 | static void |
8360 | encode_branch (int default_reloc) | |
8361 | { | |
8362 | if (inst.operands[0].hasreloc) | |
8363 | { | |
0855e32b NS |
8364 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32 |
8365 | && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL, | |
8366 | _("the only valid suffixes here are '(plt)' and '(tlscall)'")); | |
8367 | inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32 | |
8368 | ? BFD_RELOC_ARM_PLT32 | |
8369 | : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL; | |
c19d1205 | 8370 | } |
b99bd4ef | 8371 | else |
9ae92b05 | 8372 | inst.reloc.type = (bfd_reloc_code_real_type) default_reloc; |
2fc8bdac | 8373 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
8374 | } |
8375 | ||
b99bd4ef | 8376 | static void |
c19d1205 | 8377 | do_branch (void) |
b99bd4ef | 8378 | { |
39b41c9c PB |
8379 | #ifdef OBJ_ELF |
8380 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8381 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8382 | else | |
8383 | #endif | |
8384 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
8385 | } | |
8386 | ||
8387 | static void | |
8388 | do_bl (void) | |
8389 | { | |
8390 | #ifdef OBJ_ELF | |
8391 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
8392 | { | |
8393 | if (inst.cond == COND_ALWAYS) | |
8394 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
8395 | else | |
8396 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
8397 | } | |
8398 | else | |
8399 | #endif | |
8400 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 8401 | } |
b99bd4ef | 8402 | |
c19d1205 ZW |
8403 | /* ARM V5 branch-link-exchange instruction (argument parse) |
8404 | BLX <target_addr> ie BLX(1) | |
8405 | BLX{<condition>} <Rm> ie BLX(2) | |
8406 | Unfortunately, there are two different opcodes for this mnemonic. | |
8407 | So, the insns[].value is not used, and the code here zaps values | |
8408 | into inst.instruction. | |
8409 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 8410 | |
c19d1205 ZW |
8411 | static void |
8412 | do_blx (void) | |
8413 | { | |
8414 | if (inst.operands[0].isreg) | |
b99bd4ef | 8415 | { |
c19d1205 ZW |
8416 | /* Arg is a register; the opcode provided by insns[] is correct. |
8417 | It is not illegal to do "blx pc", just useless. */ | |
8418 | if (inst.operands[0].reg == REG_PC) | |
8419 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 8420 | |
c19d1205 ZW |
8421 | inst.instruction |= inst.operands[0].reg; |
8422 | } | |
8423 | else | |
b99bd4ef | 8424 | { |
c19d1205 | 8425 | /* Arg is an address; this instruction cannot be executed |
267bf995 RR |
8426 | conditionally, and the opcode must be adjusted. |
8427 | We retain the BFD_RELOC_ARM_PCREL_BLX till the very end | |
8428 | where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */ | |
c19d1205 | 8429 | constraint (inst.cond != COND_ALWAYS, BAD_COND); |
2fc8bdac | 8430 | inst.instruction = 0xfa000000; |
267bf995 | 8431 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); |
b99bd4ef | 8432 | } |
c19d1205 ZW |
8433 | } |
8434 | ||
8435 | static void | |
8436 | do_bx (void) | |
8437 | { | |
845b51d6 PB |
8438 | bfd_boolean want_reloc; |
8439 | ||
c19d1205 ZW |
8440 | if (inst.operands[0].reg == REG_PC) |
8441 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 8442 | |
c19d1205 | 8443 | inst.instruction |= inst.operands[0].reg; |
845b51d6 PB |
8444 | /* Output R_ARM_V4BX relocations if is an EABI object that looks like |
8445 | it is for ARMv4t or earlier. */ | |
8446 | want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5); | |
8447 | if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5)) | |
8448 | want_reloc = TRUE; | |
8449 | ||
5ad34203 | 8450 | #ifdef OBJ_ELF |
845b51d6 | 8451 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
5ad34203 | 8452 | #endif |
584206db | 8453 | want_reloc = FALSE; |
845b51d6 PB |
8454 | |
8455 | if (want_reloc) | |
8456 | inst.reloc.type = BFD_RELOC_ARM_V4BX; | |
09d92015 MM |
8457 | } |
8458 | ||
c19d1205 ZW |
8459 | |
8460 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
8461 | |
8462 | static void | |
c19d1205 | 8463 | do_bxj (void) |
a737bd4d | 8464 | { |
c19d1205 ZW |
8465 | if (inst.operands[0].reg == REG_PC) |
8466 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
8467 | ||
8468 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
8469 | } |
8470 | ||
c19d1205 ZW |
8471 | /* Co-processor data operation: |
8472 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
8473 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
8474 | static void | |
8475 | do_cdp (void) | |
8476 | { | |
8477 | inst.instruction |= inst.operands[0].reg << 8; | |
8478 | inst.instruction |= inst.operands[1].imm << 20; | |
8479 | inst.instruction |= inst.operands[2].reg << 12; | |
8480 | inst.instruction |= inst.operands[3].reg << 16; | |
8481 | inst.instruction |= inst.operands[4].reg; | |
8482 | inst.instruction |= inst.operands[5].imm << 5; | |
8483 | } | |
a737bd4d NC |
8484 | |
8485 | static void | |
c19d1205 | 8486 | do_cmp (void) |
a737bd4d | 8487 | { |
c19d1205 ZW |
8488 | inst.instruction |= inst.operands[0].reg << 16; |
8489 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
8490 | } |
8491 | ||
c19d1205 ZW |
8492 | /* Transfer between coprocessor and ARM registers. |
8493 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
8494 | MRC2 | |
8495 | MCR{cond} | |
8496 | MCR2 | |
8497 | ||
8498 | No special properties. */ | |
09d92015 | 8499 | |
dcbd0d71 MGD |
8500 | struct deprecated_coproc_regs_s |
8501 | { | |
8502 | unsigned cp; | |
8503 | int opc1; | |
8504 | unsigned crn; | |
8505 | unsigned crm; | |
8506 | int opc2; | |
8507 | arm_feature_set deprecated; | |
8508 | arm_feature_set obsoleted; | |
8509 | const char *dep_msg; | |
8510 | const char *obs_msg; | |
8511 | }; | |
8512 | ||
8513 | #define DEPR_ACCESS_V8 \ | |
8514 | N_("This coprocessor register access is deprecated in ARMv8") | |
8515 | ||
8516 | /* Table of all deprecated coprocessor registers. */ | |
8517 | static struct deprecated_coproc_regs_s deprecated_coproc_regs[] = | |
8518 | { | |
8519 | {15, 0, 7, 10, 5, /* CP15DMB. */ | |
823d2571 | 8520 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8521 | DEPR_ACCESS_V8, NULL}, |
8522 | {15, 0, 7, 10, 4, /* CP15DSB. */ | |
823d2571 | 8523 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8524 | DEPR_ACCESS_V8, NULL}, |
8525 | {15, 0, 7, 5, 4, /* CP15ISB. */ | |
823d2571 | 8526 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8527 | DEPR_ACCESS_V8, NULL}, |
8528 | {14, 6, 1, 0, 0, /* TEEHBR. */ | |
823d2571 | 8529 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8530 | DEPR_ACCESS_V8, NULL}, |
8531 | {14, 6, 0, 0, 0, /* TEECR. */ | |
823d2571 | 8532 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE, |
dcbd0d71 MGD |
8533 | DEPR_ACCESS_V8, NULL}, |
8534 | }; | |
8535 | ||
8536 | #undef DEPR_ACCESS_V8 | |
8537 | ||
8538 | static const size_t deprecated_coproc_reg_count = | |
8539 | sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]); | |
8540 | ||
09d92015 | 8541 | static void |
c19d1205 | 8542 | do_co_reg (void) |
09d92015 | 8543 | { |
fdfde340 | 8544 | unsigned Rd; |
dcbd0d71 | 8545 | size_t i; |
fdfde340 JM |
8546 | |
8547 | Rd = inst.operands[2].reg; | |
8548 | if (thumb_mode) | |
8549 | { | |
8550 | if (inst.instruction == 0xee000010 | |
8551 | || inst.instruction == 0xfe000010) | |
8552 | /* MCR, MCR2 */ | |
8553 | reject_bad_reg (Rd); | |
8554 | else | |
8555 | /* MRC, MRC2 */ | |
8556 | constraint (Rd == REG_SP, BAD_SP); | |
8557 | } | |
8558 | else | |
8559 | { | |
8560 | /* MCR */ | |
8561 | if (inst.instruction == 0xe000010) | |
8562 | constraint (Rd == REG_PC, BAD_PC); | |
8563 | } | |
8564 | ||
dcbd0d71 MGD |
8565 | for (i = 0; i < deprecated_coproc_reg_count; ++i) |
8566 | { | |
8567 | const struct deprecated_coproc_regs_s *r = | |
8568 | deprecated_coproc_regs + i; | |
8569 | ||
8570 | if (inst.operands[0].reg == r->cp | |
8571 | && inst.operands[1].imm == r->opc1 | |
8572 | && inst.operands[3].reg == r->crn | |
8573 | && inst.operands[4].reg == r->crm | |
8574 | && inst.operands[5].imm == r->opc2) | |
8575 | { | |
b10bf8c5 | 8576 | if (! ARM_CPU_IS_ANY (cpu_variant) |
477330fc | 8577 | && warn_on_deprecated |
dcbd0d71 | 8578 | && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated)) |
5c3696f8 | 8579 | as_tsktsk ("%s", r->dep_msg); |
dcbd0d71 MGD |
8580 | } |
8581 | } | |
fdfde340 | 8582 | |
c19d1205 ZW |
8583 | inst.instruction |= inst.operands[0].reg << 8; |
8584 | inst.instruction |= inst.operands[1].imm << 21; | |
fdfde340 | 8585 | inst.instruction |= Rd << 12; |
c19d1205 ZW |
8586 | inst.instruction |= inst.operands[3].reg << 16; |
8587 | inst.instruction |= inst.operands[4].reg; | |
8588 | inst.instruction |= inst.operands[5].imm << 5; | |
8589 | } | |
09d92015 | 8590 | |
c19d1205 ZW |
8591 | /* Transfer between coprocessor register and pair of ARM registers. |
8592 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
8593 | MCRR2 | |
8594 | MRRC{cond} | |
8595 | MRRC2 | |
b99bd4ef | 8596 | |
c19d1205 | 8597 | Two XScale instructions are special cases of these: |
09d92015 | 8598 | |
c19d1205 ZW |
8599 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
8600 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 8601 | |
5f4273c7 | 8602 | Result unpredictable if Rd or Rn is R15. */ |
a737bd4d | 8603 | |
c19d1205 ZW |
8604 | static void |
8605 | do_co_reg2c (void) | |
8606 | { | |
fdfde340 JM |
8607 | unsigned Rd, Rn; |
8608 | ||
8609 | Rd = inst.operands[2].reg; | |
8610 | Rn = inst.operands[3].reg; | |
8611 | ||
8612 | if (thumb_mode) | |
8613 | { | |
8614 | reject_bad_reg (Rd); | |
8615 | reject_bad_reg (Rn); | |
8616 | } | |
8617 | else | |
8618 | { | |
8619 | constraint (Rd == REG_PC, BAD_PC); | |
8620 | constraint (Rn == REG_PC, BAD_PC); | |
8621 | } | |
8622 | ||
c19d1205 ZW |
8623 | inst.instruction |= inst.operands[0].reg << 8; |
8624 | inst.instruction |= inst.operands[1].imm << 4; | |
fdfde340 JM |
8625 | inst.instruction |= Rd << 12; |
8626 | inst.instruction |= Rn << 16; | |
c19d1205 | 8627 | inst.instruction |= inst.operands[4].reg; |
b99bd4ef NC |
8628 | } |
8629 | ||
c19d1205 ZW |
8630 | static void |
8631 | do_cpsi (void) | |
8632 | { | |
8633 | inst.instruction |= inst.operands[0].imm << 6; | |
a028a6f5 PB |
8634 | if (inst.operands[1].present) |
8635 | { | |
8636 | inst.instruction |= CPSI_MMOD; | |
8637 | inst.instruction |= inst.operands[1].imm; | |
8638 | } | |
c19d1205 | 8639 | } |
b99bd4ef | 8640 | |
62b3e311 PB |
8641 | static void |
8642 | do_dbg (void) | |
8643 | { | |
8644 | inst.instruction |= inst.operands[0].imm; | |
8645 | } | |
8646 | ||
eea54501 MGD |
8647 | static void |
8648 | do_div (void) | |
8649 | { | |
8650 | unsigned Rd, Rn, Rm; | |
8651 | ||
8652 | Rd = inst.operands[0].reg; | |
8653 | Rn = (inst.operands[1].present | |
8654 | ? inst.operands[1].reg : Rd); | |
8655 | Rm = inst.operands[2].reg; | |
8656 | ||
8657 | constraint ((Rd == REG_PC), BAD_PC); | |
8658 | constraint ((Rn == REG_PC), BAD_PC); | |
8659 | constraint ((Rm == REG_PC), BAD_PC); | |
8660 | ||
8661 | inst.instruction |= Rd << 16; | |
8662 | inst.instruction |= Rn << 0; | |
8663 | inst.instruction |= Rm << 8; | |
8664 | } | |
8665 | ||
b99bd4ef | 8666 | static void |
c19d1205 | 8667 | do_it (void) |
b99bd4ef | 8668 | { |
c19d1205 | 8669 | /* There is no IT instruction in ARM mode. We |
e07e6e58 NC |
8670 | process it to do the validation as if in |
8671 | thumb mode, just in case the code gets | |
8672 | assembled for thumb using the unified syntax. */ | |
8673 | ||
c19d1205 | 8674 | inst.size = 0; |
e07e6e58 NC |
8675 | if (unified_syntax) |
8676 | { | |
8677 | set_it_insn_type (IT_INSN); | |
8678 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
8679 | now_it.cc = inst.operands[0].imm; | |
8680 | } | |
09d92015 | 8681 | } |
b99bd4ef | 8682 | |
6530b175 NC |
8683 | /* If there is only one register in the register list, |
8684 | then return its register number. Otherwise return -1. */ | |
8685 | static int | |
8686 | only_one_reg_in_list (int range) | |
8687 | { | |
8688 | int i = ffs (range) - 1; | |
8689 | return (i > 15 || range != (1 << i)) ? -1 : i; | |
8690 | } | |
8691 | ||
09d92015 | 8692 | static void |
6530b175 | 8693 | encode_ldmstm(int from_push_pop_mnem) |
ea6ef066 | 8694 | { |
c19d1205 ZW |
8695 | int base_reg = inst.operands[0].reg; |
8696 | int range = inst.operands[1].imm; | |
6530b175 | 8697 | int one_reg; |
ea6ef066 | 8698 | |
c19d1205 ZW |
8699 | inst.instruction |= base_reg << 16; |
8700 | inst.instruction |= range; | |
ea6ef066 | 8701 | |
c19d1205 ZW |
8702 | if (inst.operands[1].writeback) |
8703 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 8704 | |
c19d1205 | 8705 | if (inst.operands[0].writeback) |
ea6ef066 | 8706 | { |
c19d1205 ZW |
8707 | inst.instruction |= WRITE_BACK; |
8708 | /* Check for unpredictable uses of writeback. */ | |
8709 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 8710 | { |
c19d1205 ZW |
8711 | /* Not allowed in LDM type 2. */ |
8712 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
8713 | && ((range & (1 << REG_PC)) == 0)) | |
8714 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
8715 | /* Only allowed if base reg not in list for other types. */ | |
8716 | else if (range & (1 << base_reg)) | |
8717 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
8718 | } | |
8719 | else /* STM. */ | |
8720 | { | |
8721 | /* Not allowed for type 2. */ | |
8722 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
8723 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
8724 | /* Only allowed if base reg not in list, or first in list. */ | |
8725 | else if ((range & (1 << base_reg)) | |
8726 | && (range & ((1 << base_reg) - 1))) | |
8727 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 8728 | } |
ea6ef066 | 8729 | } |
6530b175 NC |
8730 | |
8731 | /* If PUSH/POP has only one register, then use the A2 encoding. */ | |
8732 | one_reg = only_one_reg_in_list (range); | |
8733 | if (from_push_pop_mnem && one_reg >= 0) | |
8734 | { | |
8735 | int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH; | |
8736 | ||
8737 | inst.instruction &= A_COND_MASK; | |
8738 | inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP; | |
8739 | inst.instruction |= one_reg << 12; | |
8740 | } | |
8741 | } | |
8742 | ||
8743 | static void | |
8744 | do_ldmstm (void) | |
8745 | { | |
8746 | encode_ldmstm (/*from_push_pop_mnem=*/FALSE); | |
a737bd4d NC |
8747 | } |
8748 | ||
c19d1205 ZW |
8749 | /* ARMv5TE load-consecutive (argument parse) |
8750 | Mode is like LDRH. | |
8751 | ||
8752 | LDRccD R, mode | |
8753 | STRccD R, mode. */ | |
8754 | ||
a737bd4d | 8755 | static void |
c19d1205 | 8756 | do_ldrd (void) |
a737bd4d | 8757 | { |
c19d1205 | 8758 | constraint (inst.operands[0].reg % 2 != 0, |
c56791bb | 8759 | _("first transfer register must be even")); |
c19d1205 ZW |
8760 | constraint (inst.operands[1].present |
8761 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
c56791bb | 8762 | _("can only transfer two consecutive registers")); |
c19d1205 ZW |
8763 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); |
8764 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 8765 | |
c19d1205 ZW |
8766 | if (!inst.operands[1].present) |
8767 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
5f4273c7 | 8768 | |
c56791bb RE |
8769 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
8770 | register and the first register written; we have to diagnose | |
8771 | overlap between the base and the second register written here. */ | |
ea6ef066 | 8772 | |
c56791bb RE |
8773 | if (inst.operands[2].reg == inst.operands[1].reg |
8774 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
8775 | as_warn (_("base register written back, and overlaps " | |
8776 | "second transfer register")); | |
b05fe5cf | 8777 | |
c56791bb RE |
8778 | if (!(inst.instruction & V4_STR_BIT)) |
8779 | { | |
c19d1205 | 8780 | /* For an index-register load, the index register must not overlap the |
c56791bb RE |
8781 | destination (even if not write-back). */ |
8782 | if (inst.operands[2].immisreg | |
8783 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg | |
8784 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
8785 | as_warn (_("index register overlaps transfer register")); | |
b05fe5cf | 8786 | } |
c19d1205 ZW |
8787 | inst.instruction |= inst.operands[0].reg << 12; |
8788 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
8789 | } |
8790 | ||
8791 | static void | |
c19d1205 | 8792 | do_ldrex (void) |
b05fe5cf | 8793 | { |
c19d1205 ZW |
8794 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
8795 | || inst.operands[1].postind || inst.operands[1].writeback | |
8796 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
8797 | || inst.operands[1].negative |
8798 | /* This can arise if the programmer has written | |
8799 | strex rN, rM, foo | |
8800 | or if they have mistakenly used a register name as the last | |
8801 | operand, eg: | |
8802 | strex rN, rM, rX | |
8803 | It is very difficult to distinguish between these two cases | |
8804 | because "rX" might actually be a label. ie the register | |
8805 | name has been occluded by a symbol of the same name. So we | |
8806 | just generate a general 'bad addressing mode' type error | |
8807 | message and leave it up to the programmer to discover the | |
8808 | true cause and fix their mistake. */ | |
8809 | || (inst.operands[1].reg == REG_PC), | |
8810 | BAD_ADDR_MODE); | |
b05fe5cf | 8811 | |
c19d1205 ZW |
8812 | constraint (inst.reloc.exp.X_op != O_constant |
8813 | || inst.reloc.exp.X_add_number != 0, | |
8814 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 8815 | |
5be8be5d DG |
8816 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
8817 | ||
c19d1205 ZW |
8818 | inst.instruction |= inst.operands[0].reg << 12; |
8819 | inst.instruction |= inst.operands[1].reg << 16; | |
8820 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
8821 | } |
8822 | ||
8823 | static void | |
c19d1205 | 8824 | do_ldrexd (void) |
b05fe5cf | 8825 | { |
c19d1205 ZW |
8826 | constraint (inst.operands[0].reg % 2 != 0, |
8827 | _("even register required")); | |
8828 | constraint (inst.operands[1].present | |
8829 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
8830 | _("can only load two consecutive registers")); | |
8831 | /* If op 1 were present and equal to PC, this function wouldn't | |
8832 | have been called in the first place. */ | |
8833 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 8834 | |
c19d1205 ZW |
8835 | inst.instruction |= inst.operands[0].reg << 12; |
8836 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
8837 | } |
8838 | ||
1be5fd2e NC |
8839 | /* In both ARM and thumb state 'ldr pc, #imm' with an immediate |
8840 | which is not a multiple of four is UNPREDICTABLE. */ | |
8841 | static void | |
8842 | check_ldr_r15_aligned (void) | |
8843 | { | |
8844 | constraint (!(inst.operands[1].immisreg) | |
8845 | && (inst.operands[0].reg == REG_PC | |
8846 | && inst.operands[1].reg == REG_PC | |
8847 | && (inst.reloc.exp.X_add_number & 0x3)), | |
8848 | _("ldr to register 15 must be 4-byte alligned")); | |
8849 | } | |
8850 | ||
b05fe5cf | 8851 | static void |
c19d1205 | 8852 | do_ldst (void) |
b05fe5cf | 8853 | { |
c19d1205 ZW |
8854 | inst.instruction |= inst.operands[0].reg << 12; |
8855 | if (!inst.operands[1].isreg) | |
8335d6aa | 8856 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE)) |
b05fe5cf | 8857 | return; |
c19d1205 | 8858 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
1be5fd2e | 8859 | check_ldr_r15_aligned (); |
b05fe5cf ZW |
8860 | } |
8861 | ||
8862 | static void | |
c19d1205 | 8863 | do_ldstt (void) |
b05fe5cf | 8864 | { |
c19d1205 ZW |
8865 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
8866 | reject [Rn,...]. */ | |
8867 | if (inst.operands[1].preind) | |
b05fe5cf | 8868 | { |
bd3ba5d1 NC |
8869 | constraint (inst.reloc.exp.X_op != O_constant |
8870 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 8871 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 8872 | |
c19d1205 ZW |
8873 | inst.operands[1].preind = 0; |
8874 | inst.operands[1].postind = 1; | |
8875 | inst.operands[1].writeback = 1; | |
b05fe5cf | 8876 | } |
c19d1205 ZW |
8877 | inst.instruction |= inst.operands[0].reg << 12; |
8878 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
8879 | } | |
b05fe5cf | 8880 | |
c19d1205 | 8881 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 8882 | |
c19d1205 ZW |
8883 | static void |
8884 | do_ldstv4 (void) | |
8885 | { | |
ff4a8d2b | 8886 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 ZW |
8887 | inst.instruction |= inst.operands[0].reg << 12; |
8888 | if (!inst.operands[1].isreg) | |
8335d6aa | 8889 | if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE)) |
b05fe5cf | 8890 | return; |
c19d1205 | 8891 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
8892 | } |
8893 | ||
8894 | static void | |
c19d1205 | 8895 | do_ldsttv4 (void) |
b05fe5cf | 8896 | { |
c19d1205 ZW |
8897 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
8898 | reject [Rn,...]. */ | |
8899 | if (inst.operands[1].preind) | |
b05fe5cf | 8900 | { |
bd3ba5d1 NC |
8901 | constraint (inst.reloc.exp.X_op != O_constant |
8902 | || inst.reloc.exp.X_add_number != 0, | |
c19d1205 | 8903 | _("this instruction requires a post-indexed address")); |
b05fe5cf | 8904 | |
c19d1205 ZW |
8905 | inst.operands[1].preind = 0; |
8906 | inst.operands[1].postind = 1; | |
8907 | inst.operands[1].writeback = 1; | |
b05fe5cf | 8908 | } |
c19d1205 ZW |
8909 | inst.instruction |= inst.operands[0].reg << 12; |
8910 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
8911 | } | |
b05fe5cf | 8912 | |
c19d1205 ZW |
8913 | /* Co-processor register load/store. |
8914 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
8915 | static void | |
8916 | do_lstc (void) | |
8917 | { | |
8918 | inst.instruction |= inst.operands[0].reg << 8; | |
8919 | inst.instruction |= inst.operands[1].reg << 12; | |
8920 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
8921 | } |
8922 | ||
b05fe5cf | 8923 | static void |
c19d1205 | 8924 | do_mlas (void) |
b05fe5cf | 8925 | { |
8fb9d7b9 | 8926 | /* This restriction does not apply to mls (nor to mla in v6 or later). */ |
c19d1205 | 8927 | if (inst.operands[0].reg == inst.operands[1].reg |
8fb9d7b9 | 8928 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6) |
c19d1205 | 8929 | && !(inst.instruction & 0x00400000)) |
8fb9d7b9 | 8930 | as_tsktsk (_("Rd and Rm should be different in mla")); |
b05fe5cf | 8931 | |
c19d1205 ZW |
8932 | inst.instruction |= inst.operands[0].reg << 16; |
8933 | inst.instruction |= inst.operands[1].reg; | |
8934 | inst.instruction |= inst.operands[2].reg << 8; | |
8935 | inst.instruction |= inst.operands[3].reg << 12; | |
c19d1205 | 8936 | } |
b05fe5cf | 8937 | |
c19d1205 ZW |
8938 | static void |
8939 | do_mov (void) | |
8940 | { | |
8941 | inst.instruction |= inst.operands[0].reg << 12; | |
8942 | encode_arm_shifter_operand (1); | |
8943 | } | |
b05fe5cf | 8944 | |
c19d1205 ZW |
8945 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
8946 | static void | |
8947 | do_mov16 (void) | |
8948 | { | |
b6895b4f PB |
8949 | bfd_vma imm; |
8950 | bfd_boolean top; | |
8951 | ||
8952 | top = (inst.instruction & 0x00400000) != 0; | |
8953 | constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW, | |
8954 | _(":lower16: not allowed this instruction")); | |
8955 | constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT, | |
8956 | _(":upper16: not allowed instruction")); | |
c19d1205 | 8957 | inst.instruction |= inst.operands[0].reg << 12; |
b6895b4f PB |
8958 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
8959 | { | |
8960 | imm = inst.reloc.exp.X_add_number; | |
8961 | /* The value is in two pieces: 0:11, 16:19. */ | |
8962 | inst.instruction |= (imm & 0x00000fff); | |
8963 | inst.instruction |= (imm & 0x0000f000) << 4; | |
8964 | } | |
b05fe5cf | 8965 | } |
b99bd4ef | 8966 | |
037e8744 JB |
8967 | static int |
8968 | do_vfp_nsyn_mrs (void) | |
8969 | { | |
8970 | if (inst.operands[0].isvec) | |
8971 | { | |
8972 | if (inst.operands[1].reg != 1) | |
477330fc | 8973 | first_error (_("operand 1 must be FPSCR")); |
037e8744 JB |
8974 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); |
8975 | memset (&inst.operands[1], '\0', sizeof (inst.operands[1])); | |
8976 | do_vfp_nsyn_opcode ("fmstat"); | |
8977 | } | |
8978 | else if (inst.operands[1].isvec) | |
8979 | do_vfp_nsyn_opcode ("fmrx"); | |
8980 | else | |
8981 | return FAIL; | |
5f4273c7 | 8982 | |
037e8744 JB |
8983 | return SUCCESS; |
8984 | } | |
8985 | ||
8986 | static int | |
8987 | do_vfp_nsyn_msr (void) | |
8988 | { | |
8989 | if (inst.operands[0].isvec) | |
8990 | do_vfp_nsyn_opcode ("fmxr"); | |
8991 | else | |
8992 | return FAIL; | |
8993 | ||
8994 | return SUCCESS; | |
8995 | } | |
8996 | ||
f7c21dc7 NC |
8997 | static void |
8998 | do_vmrs (void) | |
8999 | { | |
9000 | unsigned Rt = inst.operands[0].reg; | |
fa94de6b | 9001 | |
16d02dc9 | 9002 | if (thumb_mode && Rt == REG_SP) |
f7c21dc7 NC |
9003 | { |
9004 | inst.error = BAD_SP; | |
9005 | return; | |
9006 | } | |
9007 | ||
9008 | /* APSR_ sets isvec. All other refs to PC are illegal. */ | |
16d02dc9 | 9009 | if (!inst.operands[0].isvec && Rt == REG_PC) |
f7c21dc7 NC |
9010 | { |
9011 | inst.error = BAD_PC; | |
9012 | return; | |
9013 | } | |
9014 | ||
16d02dc9 JB |
9015 | /* If we get through parsing the register name, we just insert the number |
9016 | generated into the instruction without further validation. */ | |
9017 | inst.instruction |= (inst.operands[1].reg << 16); | |
f7c21dc7 NC |
9018 | inst.instruction |= (Rt << 12); |
9019 | } | |
9020 | ||
9021 | static void | |
9022 | do_vmsr (void) | |
9023 | { | |
9024 | unsigned Rt = inst.operands[1].reg; | |
fa94de6b | 9025 | |
f7c21dc7 NC |
9026 | if (thumb_mode) |
9027 | reject_bad_reg (Rt); | |
9028 | else if (Rt == REG_PC) | |
9029 | { | |
9030 | inst.error = BAD_PC; | |
9031 | return; | |
9032 | } | |
9033 | ||
16d02dc9 JB |
9034 | /* If we get through parsing the register name, we just insert the number |
9035 | generated into the instruction without further validation. */ | |
9036 | inst.instruction |= (inst.operands[0].reg << 16); | |
f7c21dc7 NC |
9037 | inst.instruction |= (Rt << 12); |
9038 | } | |
9039 | ||
b99bd4ef | 9040 | static void |
c19d1205 | 9041 | do_mrs (void) |
b99bd4ef | 9042 | { |
90ec0d68 MGD |
9043 | unsigned br; |
9044 | ||
037e8744 JB |
9045 | if (do_vfp_nsyn_mrs () == SUCCESS) |
9046 | return; | |
9047 | ||
ff4a8d2b | 9048 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); |
c19d1205 | 9049 | inst.instruction |= inst.operands[0].reg << 12; |
90ec0d68 MGD |
9050 | |
9051 | if (inst.operands[1].isreg) | |
9052 | { | |
9053 | br = inst.operands[1].reg; | |
9054 | if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000)) | |
9055 | as_bad (_("bad register for mrs")); | |
9056 | } | |
9057 | else | |
9058 | { | |
9059 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
9060 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
9061 | != (PSR_c|PSR_f), | |
d2cd1205 | 9062 | _("'APSR', 'CPSR' or 'SPSR' expected")); |
90ec0d68 MGD |
9063 | br = (15<<16) | (inst.operands[1].imm & SPSR_BIT); |
9064 | } | |
9065 | ||
9066 | inst.instruction |= br; | |
c19d1205 | 9067 | } |
b99bd4ef | 9068 | |
c19d1205 ZW |
9069 | /* Two possible forms: |
9070 | "{C|S}PSR_<field>, Rm", | |
9071 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 9072 | |
c19d1205 ZW |
9073 | static void |
9074 | do_msr (void) | |
9075 | { | |
037e8744 JB |
9076 | if (do_vfp_nsyn_msr () == SUCCESS) |
9077 | return; | |
9078 | ||
c19d1205 ZW |
9079 | inst.instruction |= inst.operands[0].imm; |
9080 | if (inst.operands[1].isreg) | |
9081 | inst.instruction |= inst.operands[1].reg; | |
9082 | else | |
b99bd4ef | 9083 | { |
c19d1205 ZW |
9084 | inst.instruction |= INST_IMMEDIATE; |
9085 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
9086 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 9087 | } |
b99bd4ef NC |
9088 | } |
9089 | ||
c19d1205 ZW |
9090 | static void |
9091 | do_mul (void) | |
a737bd4d | 9092 | { |
ff4a8d2b NC |
9093 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
9094 | ||
c19d1205 ZW |
9095 | if (!inst.operands[2].present) |
9096 | inst.operands[2].reg = inst.operands[0].reg; | |
9097 | inst.instruction |= inst.operands[0].reg << 16; | |
9098 | inst.instruction |= inst.operands[1].reg; | |
9099 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 9100 | |
8fb9d7b9 MS |
9101 | if (inst.operands[0].reg == inst.operands[1].reg |
9102 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) | |
9103 | as_tsktsk (_("Rd and Rm should be different in mul")); | |
a737bd4d NC |
9104 | } |
9105 | ||
c19d1205 ZW |
9106 | /* Long Multiply Parser |
9107 | UMULL RdLo, RdHi, Rm, Rs | |
9108 | SMULL RdLo, RdHi, Rm, Rs | |
9109 | UMLAL RdLo, RdHi, Rm, Rs | |
9110 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
9111 | |
9112 | static void | |
c19d1205 | 9113 | do_mull (void) |
b99bd4ef | 9114 | { |
c19d1205 ZW |
9115 | inst.instruction |= inst.operands[0].reg << 12; |
9116 | inst.instruction |= inst.operands[1].reg << 16; | |
9117 | inst.instruction |= inst.operands[2].reg; | |
9118 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 9119 | |
682b27ad PB |
9120 | /* rdhi and rdlo must be different. */ |
9121 | if (inst.operands[0].reg == inst.operands[1].reg) | |
9122 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9123 | ||
9124 | /* rdhi, rdlo and rm must all be different before armv6. */ | |
9125 | if ((inst.operands[0].reg == inst.operands[2].reg | |
c19d1205 | 9126 | || inst.operands[1].reg == inst.operands[2].reg) |
682b27ad | 9127 | && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)) |
c19d1205 ZW |
9128 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); |
9129 | } | |
b99bd4ef | 9130 | |
c19d1205 ZW |
9131 | static void |
9132 | do_nop (void) | |
9133 | { | |
e7495e45 NS |
9134 | if (inst.operands[0].present |
9135 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k)) | |
c19d1205 ZW |
9136 | { |
9137 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
9138 | inst.instruction &= 0xf0000000; | |
e7495e45 NS |
9139 | inst.instruction |= 0x0320f000; |
9140 | if (inst.operands[0].present) | |
9141 | inst.instruction |= inst.operands[0].imm; | |
c19d1205 | 9142 | } |
b99bd4ef NC |
9143 | } |
9144 | ||
c19d1205 ZW |
9145 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
9146 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
9147 | Condition defaults to COND_ALWAYS. | |
9148 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
9149 | |
9150 | static void | |
c19d1205 | 9151 | do_pkhbt (void) |
b99bd4ef | 9152 | { |
c19d1205 ZW |
9153 | inst.instruction |= inst.operands[0].reg << 12; |
9154 | inst.instruction |= inst.operands[1].reg << 16; | |
9155 | inst.instruction |= inst.operands[2].reg; | |
9156 | if (inst.operands[3].present) | |
9157 | encode_arm_shift (3); | |
9158 | } | |
b99bd4ef | 9159 | |
c19d1205 | 9160 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 9161 | |
c19d1205 ZW |
9162 | static void |
9163 | do_pkhtb (void) | |
9164 | { | |
9165 | if (!inst.operands[3].present) | |
b99bd4ef | 9166 | { |
c19d1205 ZW |
9167 | /* If the shift specifier is omitted, turn the instruction |
9168 | into pkhbt rd, rm, rn. */ | |
9169 | inst.instruction &= 0xfff00010; | |
9170 | inst.instruction |= inst.operands[0].reg << 12; | |
9171 | inst.instruction |= inst.operands[1].reg; | |
9172 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
9173 | } |
9174 | else | |
9175 | { | |
c19d1205 ZW |
9176 | inst.instruction |= inst.operands[0].reg << 12; |
9177 | inst.instruction |= inst.operands[1].reg << 16; | |
9178 | inst.instruction |= inst.operands[2].reg; | |
9179 | encode_arm_shift (3); | |
b99bd4ef NC |
9180 | } |
9181 | } | |
9182 | ||
c19d1205 | 9183 | /* ARMv5TE: Preload-Cache |
60e5ef9f | 9184 | MP Extensions: Preload for write |
c19d1205 | 9185 | |
60e5ef9f | 9186 | PLD(W) <addr_mode> |
c19d1205 ZW |
9187 | |
9188 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
9189 | |
9190 | static void | |
c19d1205 | 9191 | do_pld (void) |
b99bd4ef | 9192 | { |
c19d1205 ZW |
9193 | constraint (!inst.operands[0].isreg, |
9194 | _("'[' expected after PLD mnemonic")); | |
9195 | constraint (inst.operands[0].postind, | |
9196 | _("post-indexed expression used in preload instruction")); | |
9197 | constraint (inst.operands[0].writeback, | |
9198 | _("writeback used in preload instruction")); | |
9199 | constraint (!inst.operands[0].preind, | |
9200 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
9201 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
9202 | } | |
b99bd4ef | 9203 | |
62b3e311 PB |
9204 | /* ARMv7: PLI <addr_mode> */ |
9205 | static void | |
9206 | do_pli (void) | |
9207 | { | |
9208 | constraint (!inst.operands[0].isreg, | |
9209 | _("'[' expected after PLI mnemonic")); | |
9210 | constraint (inst.operands[0].postind, | |
9211 | _("post-indexed expression used in preload instruction")); | |
9212 | constraint (inst.operands[0].writeback, | |
9213 | _("writeback used in preload instruction")); | |
9214 | constraint (!inst.operands[0].preind, | |
9215 | _("unindexed addressing used in preload instruction")); | |
9216 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
9217 | inst.instruction &= ~PRE_INDEX; | |
9218 | } | |
9219 | ||
c19d1205 ZW |
9220 | static void |
9221 | do_push_pop (void) | |
9222 | { | |
5e0d7f77 MP |
9223 | constraint (inst.operands[0].writeback, |
9224 | _("push/pop do not support {reglist}^")); | |
c19d1205 ZW |
9225 | inst.operands[1] = inst.operands[0]; |
9226 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
9227 | inst.operands[0].isreg = 1; | |
9228 | inst.operands[0].writeback = 1; | |
9229 | inst.operands[0].reg = REG_SP; | |
6530b175 | 9230 | encode_ldmstm (/*from_push_pop_mnem=*/TRUE); |
c19d1205 | 9231 | } |
b99bd4ef | 9232 | |
c19d1205 ZW |
9233 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
9234 | word at the specified address and the following word | |
9235 | respectively. | |
9236 | Unconditionally executed. | |
9237 | Error if Rn is R15. */ | |
b99bd4ef | 9238 | |
c19d1205 ZW |
9239 | static void |
9240 | do_rfe (void) | |
9241 | { | |
9242 | inst.instruction |= inst.operands[0].reg << 16; | |
9243 | if (inst.operands[0].writeback) | |
9244 | inst.instruction |= WRITE_BACK; | |
9245 | } | |
b99bd4ef | 9246 | |
c19d1205 | 9247 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 9248 | |
c19d1205 ZW |
9249 | static void |
9250 | do_ssat (void) | |
9251 | { | |
9252 | inst.instruction |= inst.operands[0].reg << 12; | |
9253 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
9254 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9255 | |
c19d1205 ZW |
9256 | if (inst.operands[3].present) |
9257 | encode_arm_shift (3); | |
b99bd4ef NC |
9258 | } |
9259 | ||
c19d1205 | 9260 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
9261 | |
9262 | static void | |
c19d1205 | 9263 | do_usat (void) |
b99bd4ef | 9264 | { |
c19d1205 ZW |
9265 | inst.instruction |= inst.operands[0].reg << 12; |
9266 | inst.instruction |= inst.operands[1].imm << 16; | |
9267 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 9268 | |
c19d1205 ZW |
9269 | if (inst.operands[3].present) |
9270 | encode_arm_shift (3); | |
b99bd4ef NC |
9271 | } |
9272 | ||
c19d1205 | 9273 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
9274 | |
9275 | static void | |
c19d1205 | 9276 | do_ssat16 (void) |
09d92015 | 9277 | { |
c19d1205 ZW |
9278 | inst.instruction |= inst.operands[0].reg << 12; |
9279 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
9280 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
9281 | } |
9282 | ||
c19d1205 ZW |
9283 | static void |
9284 | do_usat16 (void) | |
a737bd4d | 9285 | { |
c19d1205 ZW |
9286 | inst.instruction |= inst.operands[0].reg << 12; |
9287 | inst.instruction |= inst.operands[1].imm << 16; | |
9288 | inst.instruction |= inst.operands[2].reg; | |
9289 | } | |
a737bd4d | 9290 | |
c19d1205 ZW |
9291 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
9292 | preserving the other bits. | |
a737bd4d | 9293 | |
c19d1205 ZW |
9294 | setend <endian_specifier>, where <endian_specifier> is either |
9295 | BE or LE. */ | |
a737bd4d | 9296 | |
c19d1205 ZW |
9297 | static void |
9298 | do_setend (void) | |
9299 | { | |
12e37cbc MGD |
9300 | if (warn_on_deprecated |
9301 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 9302 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 9303 | |
c19d1205 ZW |
9304 | if (inst.operands[0].imm) |
9305 | inst.instruction |= 0x200; | |
a737bd4d NC |
9306 | } |
9307 | ||
9308 | static void | |
c19d1205 | 9309 | do_shift (void) |
a737bd4d | 9310 | { |
c19d1205 ZW |
9311 | unsigned int Rm = (inst.operands[1].present |
9312 | ? inst.operands[1].reg | |
9313 | : inst.operands[0].reg); | |
a737bd4d | 9314 | |
c19d1205 ZW |
9315 | inst.instruction |= inst.operands[0].reg << 12; |
9316 | inst.instruction |= Rm; | |
9317 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 9318 | { |
c19d1205 ZW |
9319 | inst.instruction |= inst.operands[2].reg << 8; |
9320 | inst.instruction |= SHIFT_BY_REG; | |
94342ec3 NC |
9321 | /* PR 12854: Error on extraneous shifts. */ |
9322 | constraint (inst.operands[2].shifted, | |
9323 | _("extraneous shift as part of operand to shift insn")); | |
a737bd4d NC |
9324 | } |
9325 | else | |
c19d1205 | 9326 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
9327 | } |
9328 | ||
09d92015 | 9329 | static void |
3eb17e6b | 9330 | do_smc (void) |
09d92015 | 9331 | { |
3eb17e6b | 9332 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 9333 | inst.reloc.pc_rel = 0; |
09d92015 MM |
9334 | } |
9335 | ||
90ec0d68 MGD |
9336 | static void |
9337 | do_hvc (void) | |
9338 | { | |
9339 | inst.reloc.type = BFD_RELOC_ARM_HVC; | |
9340 | inst.reloc.pc_rel = 0; | |
9341 | } | |
9342 | ||
09d92015 | 9343 | static void |
c19d1205 | 9344 | do_swi (void) |
09d92015 | 9345 | { |
c19d1205 ZW |
9346 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
9347 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
9348 | } |
9349 | ||
ddfded2f MW |
9350 | static void |
9351 | do_setpan (void) | |
9352 | { | |
9353 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9354 | _("selected processor does not support SETPAN instruction")); | |
9355 | ||
9356 | inst.instruction |= ((inst.operands[0].imm & 1) << 9); | |
9357 | } | |
9358 | ||
9359 | static void | |
9360 | do_t_setpan (void) | |
9361 | { | |
9362 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan), | |
9363 | _("selected processor does not support SETPAN instruction")); | |
9364 | ||
9365 | inst.instruction |= (inst.operands[0].imm << 3); | |
9366 | } | |
9367 | ||
c19d1205 ZW |
9368 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
9369 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
9370 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
9371 | Error if any register is R15. */ | |
e16bb312 | 9372 | |
c19d1205 ZW |
9373 | static void |
9374 | do_smla (void) | |
e16bb312 | 9375 | { |
c19d1205 ZW |
9376 | inst.instruction |= inst.operands[0].reg << 16; |
9377 | inst.instruction |= inst.operands[1].reg; | |
9378 | inst.instruction |= inst.operands[2].reg << 8; | |
9379 | inst.instruction |= inst.operands[3].reg << 12; | |
9380 | } | |
a737bd4d | 9381 | |
c19d1205 ZW |
9382 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
9383 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
9384 | Error if any register is R15. | |
9385 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 9386 | |
c19d1205 ZW |
9387 | static void |
9388 | do_smlal (void) | |
9389 | { | |
9390 | inst.instruction |= inst.operands[0].reg << 12; | |
9391 | inst.instruction |= inst.operands[1].reg << 16; | |
9392 | inst.instruction |= inst.operands[2].reg; | |
9393 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 9394 | |
c19d1205 ZW |
9395 | if (inst.operands[0].reg == inst.operands[1].reg) |
9396 | as_tsktsk (_("rdhi and rdlo must be different")); | |
9397 | } | |
a737bd4d | 9398 | |
c19d1205 ZW |
9399 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
9400 | SMULxy{cond} Rd,Rm,Rs | |
9401 | Error if any register is R15. */ | |
a737bd4d | 9402 | |
c19d1205 ZW |
9403 | static void |
9404 | do_smul (void) | |
9405 | { | |
9406 | inst.instruction |= inst.operands[0].reg << 16; | |
9407 | inst.instruction |= inst.operands[1].reg; | |
9408 | inst.instruction |= inst.operands[2].reg << 8; | |
9409 | } | |
a737bd4d | 9410 | |
b6702015 PB |
9411 | /* ARM V6 srs (argument parse). The variable fields in the encoding are |
9412 | the same for both ARM and Thumb-2. */ | |
a737bd4d | 9413 | |
c19d1205 ZW |
9414 | static void |
9415 | do_srs (void) | |
9416 | { | |
b6702015 PB |
9417 | int reg; |
9418 | ||
9419 | if (inst.operands[0].present) | |
9420 | { | |
9421 | reg = inst.operands[0].reg; | |
fdfde340 | 9422 | constraint (reg != REG_SP, _("SRS base register must be r13")); |
b6702015 PB |
9423 | } |
9424 | else | |
fdfde340 | 9425 | reg = REG_SP; |
b6702015 PB |
9426 | |
9427 | inst.instruction |= reg << 16; | |
9428 | inst.instruction |= inst.operands[1].imm; | |
9429 | if (inst.operands[0].writeback || inst.operands[1].writeback) | |
c19d1205 ZW |
9430 | inst.instruction |= WRITE_BACK; |
9431 | } | |
a737bd4d | 9432 | |
c19d1205 | 9433 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 9434 | |
c19d1205 ZW |
9435 | static void |
9436 | do_strex (void) | |
9437 | { | |
9438 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9439 | || inst.operands[2].postind || inst.operands[2].writeback | |
9440 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
9441 | || inst.operands[2].negative |
9442 | /* See comment in do_ldrex(). */ | |
9443 | || (inst.operands[2].reg == REG_PC), | |
9444 | BAD_ADDR_MODE); | |
a737bd4d | 9445 | |
c19d1205 ZW |
9446 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9447 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 9448 | |
c19d1205 ZW |
9449 | constraint (inst.reloc.exp.X_op != O_constant |
9450 | || inst.reloc.exp.X_add_number != 0, | |
9451 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 9452 | |
c19d1205 ZW |
9453 | inst.instruction |= inst.operands[0].reg << 12; |
9454 | inst.instruction |= inst.operands[1].reg; | |
9455 | inst.instruction |= inst.operands[2].reg << 16; | |
9456 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
9457 | } |
9458 | ||
877807f8 NC |
9459 | static void |
9460 | do_t_strexbh (void) | |
9461 | { | |
9462 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
9463 | || inst.operands[2].postind || inst.operands[2].writeback | |
9464 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
9465 | || inst.operands[2].negative, | |
9466 | BAD_ADDR_MODE); | |
9467 | ||
9468 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9469 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9470 | ||
9471 | do_rm_rd_rn (); | |
9472 | } | |
9473 | ||
e16bb312 | 9474 | static void |
c19d1205 | 9475 | do_strexd (void) |
e16bb312 | 9476 | { |
c19d1205 ZW |
9477 | constraint (inst.operands[1].reg % 2 != 0, |
9478 | _("even register required")); | |
9479 | constraint (inst.operands[2].present | |
9480 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
9481 | _("can only store two consecutive registers")); | |
9482 | /* If op 2 were present and equal to PC, this function wouldn't | |
9483 | have been called in the first place. */ | |
9484 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 9485 | |
c19d1205 ZW |
9486 | constraint (inst.operands[0].reg == inst.operands[1].reg |
9487 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
9488 | || inst.operands[0].reg == inst.operands[3].reg, | |
9489 | BAD_OVERLAP); | |
e16bb312 | 9490 | |
c19d1205 ZW |
9491 | inst.instruction |= inst.operands[0].reg << 12; |
9492 | inst.instruction |= inst.operands[1].reg; | |
9493 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
9494 | } |
9495 | ||
9eb6c0f1 MGD |
9496 | /* ARM V8 STRL. */ |
9497 | static void | |
4b8c8c02 | 9498 | do_stlex (void) |
9eb6c0f1 MGD |
9499 | { |
9500 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9501 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9502 | ||
9503 | do_rd_rm_rn (); | |
9504 | } | |
9505 | ||
9506 | static void | |
4b8c8c02 | 9507 | do_t_stlex (void) |
9eb6c0f1 MGD |
9508 | { |
9509 | constraint (inst.operands[0].reg == inst.operands[1].reg | |
9510 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
9511 | ||
9512 | do_rm_rd_rn (); | |
9513 | } | |
9514 | ||
c19d1205 ZW |
9515 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
9516 | extends it to 32-bits, and adds the result to a value in another | |
9517 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
9518 | before extracting the 16-bit value. | |
9519 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
9520 | Condition defaults to COND_ALWAYS. | |
9521 | Error if any register uses R15. */ | |
9522 | ||
e16bb312 | 9523 | static void |
c19d1205 | 9524 | do_sxtah (void) |
e16bb312 | 9525 | { |
c19d1205 ZW |
9526 | inst.instruction |= inst.operands[0].reg << 12; |
9527 | inst.instruction |= inst.operands[1].reg << 16; | |
9528 | inst.instruction |= inst.operands[2].reg; | |
9529 | inst.instruction |= inst.operands[3].imm << 10; | |
9530 | } | |
e16bb312 | 9531 | |
c19d1205 | 9532 | /* ARM V6 SXTH. |
e16bb312 | 9533 | |
c19d1205 ZW |
9534 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
9535 | Condition defaults to COND_ALWAYS. | |
9536 | Error if any register uses R15. */ | |
e16bb312 NC |
9537 | |
9538 | static void | |
c19d1205 | 9539 | do_sxth (void) |
e16bb312 | 9540 | { |
c19d1205 ZW |
9541 | inst.instruction |= inst.operands[0].reg << 12; |
9542 | inst.instruction |= inst.operands[1].reg; | |
9543 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 9544 | } |
c19d1205 ZW |
9545 | \f |
9546 | /* VFP instructions. In a logical order: SP variant first, monad | |
9547 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
9548 | |
9549 | static void | |
c19d1205 | 9550 | do_vfp_sp_monadic (void) |
e16bb312 | 9551 | { |
5287ad62 JB |
9552 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9553 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9554 | } |
9555 | ||
9556 | static void | |
c19d1205 | 9557 | do_vfp_sp_dyadic (void) |
e16bb312 | 9558 | { |
5287ad62 JB |
9559 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9560 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
9561 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
9562 | } |
9563 | ||
9564 | static void | |
c19d1205 | 9565 | do_vfp_sp_compare_z (void) |
e16bb312 | 9566 | { |
5287ad62 | 9567 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
9568 | } |
9569 | ||
9570 | static void | |
c19d1205 | 9571 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 9572 | { |
5287ad62 JB |
9573 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
9574 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
9575 | } |
9576 | ||
9577 | static void | |
c19d1205 | 9578 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 9579 | { |
5287ad62 JB |
9580 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
9581 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
e16bb312 NC |
9582 | } |
9583 | ||
9584 | static void | |
c19d1205 | 9585 | do_vfp_reg_from_sp (void) |
e16bb312 | 9586 | { |
c19d1205 | 9587 | inst.instruction |= inst.operands[0].reg << 12; |
5287ad62 | 9588 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn); |
e16bb312 NC |
9589 | } |
9590 | ||
9591 | static void | |
c19d1205 | 9592 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 9593 | { |
c19d1205 ZW |
9594 | constraint (inst.operands[2].imm != 2, |
9595 | _("only two consecutive VFP SP registers allowed here")); | |
9596 | inst.instruction |= inst.operands[0].reg << 12; | |
9597 | inst.instruction |= inst.operands[1].reg << 16; | |
5287ad62 | 9598 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm); |
e16bb312 NC |
9599 | } |
9600 | ||
9601 | static void | |
c19d1205 | 9602 | do_vfp_sp_from_reg (void) |
e16bb312 | 9603 | { |
5287ad62 | 9604 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn); |
c19d1205 | 9605 | inst.instruction |= inst.operands[1].reg << 12; |
e16bb312 NC |
9606 | } |
9607 | ||
9608 | static void | |
c19d1205 | 9609 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 9610 | { |
c19d1205 ZW |
9611 | constraint (inst.operands[0].imm != 2, |
9612 | _("only two consecutive VFP SP registers allowed here")); | |
5287ad62 | 9613 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm); |
c19d1205 ZW |
9614 | inst.instruction |= inst.operands[1].reg << 12; |
9615 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
9616 | } |
9617 | ||
9618 | static void | |
c19d1205 | 9619 | do_vfp_sp_ldst (void) |
e16bb312 | 9620 | { |
5287ad62 | 9621 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); |
c19d1205 | 9622 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
9623 | } |
9624 | ||
9625 | static void | |
c19d1205 | 9626 | do_vfp_dp_ldst (void) |
e16bb312 | 9627 | { |
5287ad62 | 9628 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); |
c19d1205 | 9629 | encode_arm_cp_address (1, FALSE, TRUE, 0); |
e16bb312 NC |
9630 | } |
9631 | ||
c19d1205 | 9632 | |
e16bb312 | 9633 | static void |
c19d1205 | 9634 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 9635 | { |
c19d1205 ZW |
9636 | if (inst.operands[0].writeback) |
9637 | inst.instruction |= WRITE_BACK; | |
9638 | else | |
9639 | constraint (ldstm_type != VFP_LDSTMIA, | |
9640 | _("this addressing mode requires base-register writeback")); | |
9641 | inst.instruction |= inst.operands[0].reg << 16; | |
5287ad62 | 9642 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd); |
c19d1205 | 9643 | inst.instruction |= inst.operands[1].imm; |
e16bb312 NC |
9644 | } |
9645 | ||
9646 | static void | |
c19d1205 | 9647 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 9648 | { |
c19d1205 | 9649 | int count; |
e16bb312 | 9650 | |
c19d1205 ZW |
9651 | if (inst.operands[0].writeback) |
9652 | inst.instruction |= WRITE_BACK; | |
9653 | else | |
9654 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
9655 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 9656 | |
c19d1205 | 9657 | inst.instruction |= inst.operands[0].reg << 16; |
5287ad62 | 9658 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); |
e16bb312 | 9659 | |
c19d1205 ZW |
9660 | count = inst.operands[1].imm << 1; |
9661 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
9662 | count += 1; | |
e16bb312 | 9663 | |
c19d1205 | 9664 | inst.instruction |= count; |
e16bb312 NC |
9665 | } |
9666 | ||
9667 | static void | |
c19d1205 | 9668 | do_vfp_sp_ldstmia (void) |
e16bb312 | 9669 | { |
c19d1205 | 9670 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
9671 | } |
9672 | ||
9673 | static void | |
c19d1205 | 9674 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 9675 | { |
c19d1205 | 9676 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
9677 | } |
9678 | ||
9679 | static void | |
c19d1205 | 9680 | do_vfp_dp_ldstmia (void) |
e16bb312 | 9681 | { |
c19d1205 | 9682 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
9683 | } |
9684 | ||
9685 | static void | |
c19d1205 | 9686 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 9687 | { |
c19d1205 | 9688 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
9689 | } |
9690 | ||
9691 | static void | |
c19d1205 | 9692 | do_vfp_xp_ldstmia (void) |
e16bb312 | 9693 | { |
c19d1205 ZW |
9694 | vfp_dp_ldstm (VFP_LDSTMIAX); |
9695 | } | |
e16bb312 | 9696 | |
c19d1205 ZW |
9697 | static void |
9698 | do_vfp_xp_ldstmdb (void) | |
9699 | { | |
9700 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 9701 | } |
5287ad62 JB |
9702 | |
9703 | static void | |
9704 | do_vfp_dp_rd_rm (void) | |
9705 | { | |
9706 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9707 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm); | |
9708 | } | |
9709 | ||
9710 | static void | |
9711 | do_vfp_dp_rn_rd (void) | |
9712 | { | |
9713 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn); | |
9714 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
9715 | } | |
9716 | ||
9717 | static void | |
9718 | do_vfp_dp_rd_rn (void) | |
9719 | { | |
9720 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9721 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
9722 | } | |
9723 | ||
9724 | static void | |
9725 | do_vfp_dp_rd_rn_rm (void) | |
9726 | { | |
9727 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9728 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn); | |
9729 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm); | |
9730 | } | |
9731 | ||
9732 | static void | |
9733 | do_vfp_dp_rd (void) | |
9734 | { | |
9735 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9736 | } | |
9737 | ||
9738 | static void | |
9739 | do_vfp_dp_rm_rd_rn (void) | |
9740 | { | |
9741 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm); | |
9742 | encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd); | |
9743 | encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn); | |
9744 | } | |
9745 | ||
9746 | /* VFPv3 instructions. */ | |
9747 | static void | |
9748 | do_vfp_sp_const (void) | |
9749 | { | |
9750 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
00249aaa PB |
9751 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9752 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9753 | } |
9754 | ||
9755 | static void | |
9756 | do_vfp_dp_const (void) | |
9757 | { | |
9758 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
00249aaa PB |
9759 | inst.instruction |= (inst.operands[1].imm & 0xf0) << 12; |
9760 | inst.instruction |= (inst.operands[1].imm & 0x0f); | |
5287ad62 JB |
9761 | } |
9762 | ||
9763 | static void | |
9764 | vfp_conv (int srcsize) | |
9765 | { | |
5f1af56b MGD |
9766 | int immbits = srcsize - inst.operands[1].imm; |
9767 | ||
fa94de6b RM |
9768 | if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize)) |
9769 | { | |
5f1af56b | 9770 | /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16. |
477330fc | 9771 | i.e. immbits must be in range 0 - 16. */ |
5f1af56b MGD |
9772 | inst.error = _("immediate value out of range, expected range [0, 16]"); |
9773 | return; | |
9774 | } | |
fa94de6b | 9775 | else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize)) |
5f1af56b MGD |
9776 | { |
9777 | /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32. | |
477330fc | 9778 | i.e. immbits must be in range 0 - 31. */ |
5f1af56b MGD |
9779 | inst.error = _("immediate value out of range, expected range [1, 32]"); |
9780 | return; | |
9781 | } | |
9782 | ||
5287ad62 JB |
9783 | inst.instruction |= (immbits & 1) << 5; |
9784 | inst.instruction |= (immbits >> 1); | |
9785 | } | |
9786 | ||
9787 | static void | |
9788 | do_vfp_sp_conv_16 (void) | |
9789 | { | |
9790 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
9791 | vfp_conv (16); | |
9792 | } | |
9793 | ||
9794 | static void | |
9795 | do_vfp_dp_conv_16 (void) | |
9796 | { | |
9797 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9798 | vfp_conv (16); | |
9799 | } | |
9800 | ||
9801 | static void | |
9802 | do_vfp_sp_conv_32 (void) | |
9803 | { | |
9804 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
9805 | vfp_conv (32); | |
9806 | } | |
9807 | ||
9808 | static void | |
9809 | do_vfp_dp_conv_32 (void) | |
9810 | { | |
9811 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd); | |
9812 | vfp_conv (32); | |
9813 | } | |
c19d1205 ZW |
9814 | \f |
9815 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 9816 | |
c19d1205 ZW |
9817 | static void |
9818 | do_fpa_cmp (void) | |
9819 | { | |
9820 | inst.instruction |= inst.operands[0].reg << 16; | |
9821 | inst.instruction |= inst.operands[1].reg; | |
9822 | } | |
b99bd4ef NC |
9823 | |
9824 | static void | |
c19d1205 | 9825 | do_fpa_ldmstm (void) |
b99bd4ef | 9826 | { |
c19d1205 ZW |
9827 | inst.instruction |= inst.operands[0].reg << 12; |
9828 | switch (inst.operands[1].imm) | |
9829 | { | |
9830 | case 1: inst.instruction |= CP_T_X; break; | |
9831 | case 2: inst.instruction |= CP_T_Y; break; | |
9832 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
9833 | case 4: break; | |
9834 | default: abort (); | |
9835 | } | |
b99bd4ef | 9836 | |
c19d1205 ZW |
9837 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
9838 | { | |
9839 | /* The instruction specified "ea" or "fd", so we can only accept | |
9840 | [Rn]{!}. The instruction does not really support stacking or | |
9841 | unstacking, so we have to emulate these by setting appropriate | |
9842 | bits and offsets. */ | |
9843 | constraint (inst.reloc.exp.X_op != O_constant | |
9844 | || inst.reloc.exp.X_add_number != 0, | |
9845 | _("this instruction does not support indexing")); | |
b99bd4ef | 9846 | |
c19d1205 ZW |
9847 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
9848 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 9849 | |
c19d1205 ZW |
9850 | if (!(inst.instruction & INDEX_UP)) |
9851 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 9852 | |
c19d1205 ZW |
9853 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
9854 | { | |
9855 | inst.operands[2].preind = 0; | |
9856 | inst.operands[2].postind = 1; | |
9857 | } | |
9858 | } | |
b99bd4ef | 9859 | |
c19d1205 | 9860 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 9861 | } |
c19d1205 ZW |
9862 | \f |
9863 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 9864 | |
c19d1205 ZW |
9865 | static void |
9866 | do_iwmmxt_tandorc (void) | |
9867 | { | |
9868 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
9869 | } | |
b99bd4ef | 9870 | |
c19d1205 ZW |
9871 | static void |
9872 | do_iwmmxt_textrc (void) | |
9873 | { | |
9874 | inst.instruction |= inst.operands[0].reg << 12; | |
9875 | inst.instruction |= inst.operands[1].imm; | |
9876 | } | |
b99bd4ef NC |
9877 | |
9878 | static void | |
c19d1205 | 9879 | do_iwmmxt_textrm (void) |
b99bd4ef | 9880 | { |
c19d1205 ZW |
9881 | inst.instruction |= inst.operands[0].reg << 12; |
9882 | inst.instruction |= inst.operands[1].reg << 16; | |
9883 | inst.instruction |= inst.operands[2].imm; | |
9884 | } | |
b99bd4ef | 9885 | |
c19d1205 ZW |
9886 | static void |
9887 | do_iwmmxt_tinsr (void) | |
9888 | { | |
9889 | inst.instruction |= inst.operands[0].reg << 16; | |
9890 | inst.instruction |= inst.operands[1].reg << 12; | |
9891 | inst.instruction |= inst.operands[2].imm; | |
9892 | } | |
b99bd4ef | 9893 | |
c19d1205 ZW |
9894 | static void |
9895 | do_iwmmxt_tmia (void) | |
9896 | { | |
9897 | inst.instruction |= inst.operands[0].reg << 5; | |
9898 | inst.instruction |= inst.operands[1].reg; | |
9899 | inst.instruction |= inst.operands[2].reg << 12; | |
9900 | } | |
b99bd4ef | 9901 | |
c19d1205 ZW |
9902 | static void |
9903 | do_iwmmxt_waligni (void) | |
9904 | { | |
9905 | inst.instruction |= inst.operands[0].reg << 12; | |
9906 | inst.instruction |= inst.operands[1].reg << 16; | |
9907 | inst.instruction |= inst.operands[2].reg; | |
9908 | inst.instruction |= inst.operands[3].imm << 20; | |
9909 | } | |
b99bd4ef | 9910 | |
2d447fca JM |
9911 | static void |
9912 | do_iwmmxt_wmerge (void) | |
9913 | { | |
9914 | inst.instruction |= inst.operands[0].reg << 12; | |
9915 | inst.instruction |= inst.operands[1].reg << 16; | |
9916 | inst.instruction |= inst.operands[2].reg; | |
9917 | inst.instruction |= inst.operands[3].imm << 21; | |
9918 | } | |
9919 | ||
c19d1205 ZW |
9920 | static void |
9921 | do_iwmmxt_wmov (void) | |
9922 | { | |
9923 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
9924 | inst.instruction |= inst.operands[0].reg << 12; | |
9925 | inst.instruction |= inst.operands[1].reg << 16; | |
9926 | inst.instruction |= inst.operands[1].reg; | |
9927 | } | |
b99bd4ef | 9928 | |
c19d1205 ZW |
9929 | static void |
9930 | do_iwmmxt_wldstbh (void) | |
9931 | { | |
8f06b2d8 | 9932 | int reloc; |
c19d1205 | 9933 | inst.instruction |= inst.operands[0].reg << 12; |
8f06b2d8 PB |
9934 | if (thumb_mode) |
9935 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
9936 | else | |
9937 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
9938 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
9939 | } |
9940 | ||
c19d1205 ZW |
9941 | static void |
9942 | do_iwmmxt_wldstw (void) | |
9943 | { | |
9944 | /* RIWR_RIWC clears .isreg for a control register. */ | |
9945 | if (!inst.operands[0].isreg) | |
9946 | { | |
9947 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
9948 | inst.instruction |= 0xf0000000; | |
9949 | } | |
b99bd4ef | 9950 | |
c19d1205 ZW |
9951 | inst.instruction |= inst.operands[0].reg << 12; |
9952 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
9953 | } | |
b99bd4ef NC |
9954 | |
9955 | static void | |
c19d1205 | 9956 | do_iwmmxt_wldstd (void) |
b99bd4ef | 9957 | { |
c19d1205 | 9958 | inst.instruction |= inst.operands[0].reg << 12; |
2d447fca JM |
9959 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2) |
9960 | && inst.operands[1].immisreg) | |
9961 | { | |
9962 | inst.instruction &= ~0x1a000ff; | |
eff0bc54 | 9963 | inst.instruction |= (0xfU << 28); |
2d447fca JM |
9964 | if (inst.operands[1].preind) |
9965 | inst.instruction |= PRE_INDEX; | |
9966 | if (!inst.operands[1].negative) | |
9967 | inst.instruction |= INDEX_UP; | |
9968 | if (inst.operands[1].writeback) | |
9969 | inst.instruction |= WRITE_BACK; | |
9970 | inst.instruction |= inst.operands[1].reg << 16; | |
9971 | inst.instruction |= inst.reloc.exp.X_add_number << 4; | |
9972 | inst.instruction |= inst.operands[1].imm; | |
9973 | } | |
9974 | else | |
9975 | encode_arm_cp_address (1, TRUE, FALSE, 0); | |
c19d1205 | 9976 | } |
b99bd4ef | 9977 | |
c19d1205 ZW |
9978 | static void |
9979 | do_iwmmxt_wshufh (void) | |
9980 | { | |
9981 | inst.instruction |= inst.operands[0].reg << 12; | |
9982 | inst.instruction |= inst.operands[1].reg << 16; | |
9983 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
9984 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
9985 | } | |
b99bd4ef | 9986 | |
c19d1205 ZW |
9987 | static void |
9988 | do_iwmmxt_wzero (void) | |
9989 | { | |
9990 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
9991 | inst.instruction |= inst.operands[0].reg; | |
9992 | inst.instruction |= inst.operands[0].reg << 12; | |
9993 | inst.instruction |= inst.operands[0].reg << 16; | |
9994 | } | |
2d447fca JM |
9995 | |
9996 | static void | |
9997 | do_iwmmxt_wrwrwr_or_imm5 (void) | |
9998 | { | |
9999 | if (inst.operands[2].isreg) | |
10000 | do_rd_rn_rm (); | |
10001 | else { | |
10002 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2), | |
10003 | _("immediate operand requires iWMMXt2")); | |
10004 | do_rd_rn (); | |
10005 | if (inst.operands[2].imm == 0) | |
10006 | { | |
10007 | switch ((inst.instruction >> 20) & 0xf) | |
10008 | { | |
10009 | case 4: | |
10010 | case 5: | |
10011 | case 6: | |
5f4273c7 | 10012 | case 7: |
2d447fca JM |
10013 | /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */ |
10014 | inst.operands[2].imm = 16; | |
10015 | inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20); | |
10016 | break; | |
10017 | case 8: | |
10018 | case 9: | |
10019 | case 10: | |
10020 | case 11: | |
10021 | /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */ | |
10022 | inst.operands[2].imm = 32; | |
10023 | inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20); | |
10024 | break; | |
10025 | case 12: | |
10026 | case 13: | |
10027 | case 14: | |
10028 | case 15: | |
10029 | { | |
10030 | /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */ | |
10031 | unsigned long wrn; | |
10032 | wrn = (inst.instruction >> 16) & 0xf; | |
10033 | inst.instruction &= 0xff0fff0f; | |
10034 | inst.instruction |= wrn; | |
10035 | /* Bail out here; the instruction is now assembled. */ | |
10036 | return; | |
10037 | } | |
10038 | } | |
10039 | } | |
10040 | /* Map 32 -> 0, etc. */ | |
10041 | inst.operands[2].imm &= 0x1f; | |
eff0bc54 | 10042 | inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf); |
2d447fca JM |
10043 | } |
10044 | } | |
c19d1205 ZW |
10045 | \f |
10046 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
10047 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 10048 | |
c19d1205 | 10049 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 10050 | |
c19d1205 ZW |
10051 | static void |
10052 | do_mav_triple (void) | |
10053 | { | |
10054 | inst.instruction |= inst.operands[0].reg << 16; | |
10055 | inst.instruction |= inst.operands[1].reg; | |
10056 | inst.instruction |= inst.operands[2].reg << 12; | |
10057 | } | |
b99bd4ef | 10058 | |
c19d1205 ZW |
10059 | /* Insns like "foo W,X,Y,Z". |
10060 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 10061 | |
c19d1205 ZW |
10062 | static void |
10063 | do_mav_quad (void) | |
10064 | { | |
10065 | inst.instruction |= inst.operands[0].reg << 5; | |
10066 | inst.instruction |= inst.operands[1].reg << 12; | |
10067 | inst.instruction |= inst.operands[2].reg << 16; | |
10068 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
10069 | } |
10070 | ||
c19d1205 ZW |
10071 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
10072 | static void | |
10073 | do_mav_dspsc (void) | |
a737bd4d | 10074 | { |
c19d1205 ZW |
10075 | inst.instruction |= inst.operands[1].reg << 12; |
10076 | } | |
a737bd4d | 10077 | |
c19d1205 ZW |
10078 | /* Maverick shift immediate instructions. |
10079 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
10080 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 10081 | |
c19d1205 ZW |
10082 | static void |
10083 | do_mav_shift (void) | |
10084 | { | |
10085 | int imm = inst.operands[2].imm; | |
a737bd4d | 10086 | |
c19d1205 ZW |
10087 | inst.instruction |= inst.operands[0].reg << 12; |
10088 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 10089 | |
c19d1205 ZW |
10090 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
10091 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
10092 | Bit 4 should be 0. */ | |
10093 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 10094 | |
c19d1205 ZW |
10095 | inst.instruction |= imm; |
10096 | } | |
10097 | \f | |
10098 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 10099 | |
c19d1205 ZW |
10100 | /* Xscale multiply-accumulate (argument parse) |
10101 | MIAcc acc0,Rm,Rs | |
10102 | MIAPHcc acc0,Rm,Rs | |
10103 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 10104 | |
c19d1205 ZW |
10105 | static void |
10106 | do_xsc_mia (void) | |
10107 | { | |
10108 | inst.instruction |= inst.operands[1].reg; | |
10109 | inst.instruction |= inst.operands[2].reg << 12; | |
10110 | } | |
a737bd4d | 10111 | |
c19d1205 | 10112 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 10113 | |
c19d1205 | 10114 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 10115 | |
c19d1205 ZW |
10116 | static void |
10117 | do_xsc_mar (void) | |
10118 | { | |
10119 | inst.instruction |= inst.operands[1].reg << 12; | |
10120 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
10121 | } |
10122 | ||
c19d1205 | 10123 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 10124 | |
c19d1205 | 10125 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
10126 | |
10127 | static void | |
c19d1205 | 10128 | do_xsc_mra (void) |
b99bd4ef | 10129 | { |
c19d1205 ZW |
10130 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
10131 | inst.instruction |= inst.operands[0].reg << 12; | |
10132 | inst.instruction |= inst.operands[1].reg << 16; | |
10133 | } | |
10134 | \f | |
10135 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 10136 | |
c19d1205 ZW |
10137 | /* inst.operands[i] is a shifted-register operand; encode |
10138 | it into inst.instruction in the format used by Thumb32. */ | |
10139 | ||
10140 | static void | |
10141 | encode_thumb32_shifted_operand (int i) | |
10142 | { | |
10143 | unsigned int value = inst.reloc.exp.X_add_number; | |
10144 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 10145 | |
9c3c69f2 PB |
10146 | constraint (inst.operands[i].immisreg, |
10147 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
10148 | inst.instruction |= inst.operands[i].reg; |
10149 | if (shift == SHIFT_RRX) | |
10150 | inst.instruction |= SHIFT_ROR << 4; | |
10151 | else | |
b99bd4ef | 10152 | { |
c19d1205 ZW |
10153 | constraint (inst.reloc.exp.X_op != O_constant, |
10154 | _("expression too complex")); | |
10155 | ||
10156 | constraint (value > 32 | |
10157 | || (value == 32 && (shift == SHIFT_LSL | |
10158 | || shift == SHIFT_ROR)), | |
10159 | _("shift expression is too large")); | |
10160 | ||
10161 | if (value == 0) | |
10162 | shift = SHIFT_LSL; | |
10163 | else if (value == 32) | |
10164 | value = 0; | |
10165 | ||
10166 | inst.instruction |= shift << 4; | |
10167 | inst.instruction |= (value & 0x1c) << 10; | |
10168 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 10169 | } |
c19d1205 | 10170 | } |
b99bd4ef | 10171 | |
b99bd4ef | 10172 | |
c19d1205 ZW |
10173 | /* inst.operands[i] was set up by parse_address. Encode it into a |
10174 | Thumb32 format load or store instruction. Reject forms that cannot | |
10175 | be used with such instructions. If is_t is true, reject forms that | |
10176 | cannot be used with a T instruction; if is_d is true, reject forms | |
5be8be5d DG |
10177 | that cannot be used with a D instruction. If it is a store insn, |
10178 | reject PC in Rn. */ | |
b99bd4ef | 10179 | |
c19d1205 ZW |
10180 | static void |
10181 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
10182 | { | |
5be8be5d | 10183 | const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); |
c19d1205 ZW |
10184 | |
10185 | constraint (!inst.operands[i].isreg, | |
53365c0d | 10186 | _("Instruction does not support =N addresses")); |
b99bd4ef | 10187 | |
c19d1205 ZW |
10188 | inst.instruction |= inst.operands[i].reg << 16; |
10189 | if (inst.operands[i].immisreg) | |
b99bd4ef | 10190 | { |
5be8be5d | 10191 | constraint (is_pc, BAD_PC_ADDRESSING); |
c19d1205 ZW |
10192 | constraint (is_t || is_d, _("cannot use register index with this instruction")); |
10193 | constraint (inst.operands[i].negative, | |
10194 | _("Thumb does not support negative register indexing")); | |
10195 | constraint (inst.operands[i].postind, | |
10196 | _("Thumb does not support register post-indexing")); | |
10197 | constraint (inst.operands[i].writeback, | |
10198 | _("Thumb does not support register indexing with writeback")); | |
10199 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
10200 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 10201 | |
f40d1643 | 10202 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 10203 | if (inst.operands[i].shifted) |
b99bd4ef | 10204 | { |
c19d1205 ZW |
10205 | constraint (inst.reloc.exp.X_op != O_constant, |
10206 | _("expression too complex")); | |
9c3c69f2 PB |
10207 | constraint (inst.reloc.exp.X_add_number < 0 |
10208 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 10209 | _("shift out of range")); |
9c3c69f2 | 10210 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
10211 | } |
10212 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10213 | } | |
10214 | else if (inst.operands[i].preind) | |
10215 | { | |
5be8be5d | 10216 | constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK); |
f40d1643 | 10217 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 | 10218 | _("cannot use writeback with this instruction")); |
4755303e WN |
10219 | constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0), |
10220 | BAD_PC_ADDRESSING); | |
c19d1205 ZW |
10221 | |
10222 | if (is_d) | |
10223 | { | |
10224 | inst.instruction |= 0x01000000; | |
10225 | if (inst.operands[i].writeback) | |
10226 | inst.instruction |= 0x00200000; | |
b99bd4ef | 10227 | } |
c19d1205 | 10228 | else |
b99bd4ef | 10229 | { |
c19d1205 ZW |
10230 | inst.instruction |= 0x00000c00; |
10231 | if (inst.operands[i].writeback) | |
10232 | inst.instruction |= 0x00000100; | |
b99bd4ef | 10233 | } |
c19d1205 | 10234 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 10235 | } |
c19d1205 | 10236 | else if (inst.operands[i].postind) |
b99bd4ef | 10237 | { |
9c2799c2 | 10238 | gas_assert (inst.operands[i].writeback); |
c19d1205 ZW |
10239 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); |
10240 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
10241 | ||
10242 | if (is_d) | |
10243 | inst.instruction |= 0x00200000; | |
10244 | else | |
10245 | inst.instruction |= 0x00000900; | |
10246 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
10247 | } | |
10248 | else /* unindexed - only for coprocessor */ | |
10249 | inst.error = _("instruction does not accept unindexed addressing"); | |
10250 | } | |
10251 | ||
10252 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
10253 | encodings (the latter only in post-V6T2 cores). The index is the | |
10254 | value used in the insns table below. When there is more than one | |
10255 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
10256 | holds variant (1). |
10257 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 | 10258 | #define T16_32_TAB \ |
21d799b5 NC |
10259 | X(_adc, 4140, eb400000), \ |
10260 | X(_adcs, 4140, eb500000), \ | |
10261 | X(_add, 1c00, eb000000), \ | |
10262 | X(_adds, 1c00, eb100000), \ | |
10263 | X(_addi, 0000, f1000000), \ | |
10264 | X(_addis, 0000, f1100000), \ | |
10265 | X(_add_pc,000f, f20f0000), \ | |
10266 | X(_add_sp,000d, f10d0000), \ | |
10267 | X(_adr, 000f, f20f0000), \ | |
10268 | X(_and, 4000, ea000000), \ | |
10269 | X(_ands, 4000, ea100000), \ | |
10270 | X(_asr, 1000, fa40f000), \ | |
10271 | X(_asrs, 1000, fa50f000), \ | |
10272 | X(_b, e000, f000b000), \ | |
10273 | X(_bcond, d000, f0008000), \ | |
10274 | X(_bic, 4380, ea200000), \ | |
10275 | X(_bics, 4380, ea300000), \ | |
10276 | X(_cmn, 42c0, eb100f00), \ | |
10277 | X(_cmp, 2800, ebb00f00), \ | |
10278 | X(_cpsie, b660, f3af8400), \ | |
10279 | X(_cpsid, b670, f3af8600), \ | |
10280 | X(_cpy, 4600, ea4f0000), \ | |
10281 | X(_dec_sp,80dd, f1ad0d00), \ | |
10282 | X(_eor, 4040, ea800000), \ | |
10283 | X(_eors, 4040, ea900000), \ | |
10284 | X(_inc_sp,00dd, f10d0d00), \ | |
10285 | X(_ldmia, c800, e8900000), \ | |
10286 | X(_ldr, 6800, f8500000), \ | |
10287 | X(_ldrb, 7800, f8100000), \ | |
10288 | X(_ldrh, 8800, f8300000), \ | |
10289 | X(_ldrsb, 5600, f9100000), \ | |
10290 | X(_ldrsh, 5e00, f9300000), \ | |
10291 | X(_ldr_pc,4800, f85f0000), \ | |
10292 | X(_ldr_pc2,4800, f85f0000), \ | |
10293 | X(_ldr_sp,9800, f85d0000), \ | |
10294 | X(_lsl, 0000, fa00f000), \ | |
10295 | X(_lsls, 0000, fa10f000), \ | |
10296 | X(_lsr, 0800, fa20f000), \ | |
10297 | X(_lsrs, 0800, fa30f000), \ | |
10298 | X(_mov, 2000, ea4f0000), \ | |
10299 | X(_movs, 2000, ea5f0000), \ | |
10300 | X(_mul, 4340, fb00f000), \ | |
10301 | X(_muls, 4340, ffffffff), /* no 32b muls */ \ | |
10302 | X(_mvn, 43c0, ea6f0000), \ | |
10303 | X(_mvns, 43c0, ea7f0000), \ | |
10304 | X(_neg, 4240, f1c00000), /* rsb #0 */ \ | |
10305 | X(_negs, 4240, f1d00000), /* rsbs #0 */ \ | |
10306 | X(_orr, 4300, ea400000), \ | |
10307 | X(_orrs, 4300, ea500000), \ | |
10308 | X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \ | |
10309 | X(_push, b400, e92d0000), /* stmdb sp!,... */ \ | |
10310 | X(_rev, ba00, fa90f080), \ | |
10311 | X(_rev16, ba40, fa90f090), \ | |
10312 | X(_revsh, bac0, fa90f0b0), \ | |
10313 | X(_ror, 41c0, fa60f000), \ | |
10314 | X(_rors, 41c0, fa70f000), \ | |
10315 | X(_sbc, 4180, eb600000), \ | |
10316 | X(_sbcs, 4180, eb700000), \ | |
10317 | X(_stmia, c000, e8800000), \ | |
10318 | X(_str, 6000, f8400000), \ | |
10319 | X(_strb, 7000, f8000000), \ | |
10320 | X(_strh, 8000, f8200000), \ | |
10321 | X(_str_sp,9000, f84d0000), \ | |
10322 | X(_sub, 1e00, eba00000), \ | |
10323 | X(_subs, 1e00, ebb00000), \ | |
10324 | X(_subi, 8000, f1a00000), \ | |
10325 | X(_subis, 8000, f1b00000), \ | |
10326 | X(_sxtb, b240, fa4ff080), \ | |
10327 | X(_sxth, b200, fa0ff080), \ | |
10328 | X(_tst, 4200, ea100f00), \ | |
10329 | X(_uxtb, b2c0, fa5ff080), \ | |
10330 | X(_uxth, b280, fa1ff080), \ | |
10331 | X(_nop, bf00, f3af8000), \ | |
10332 | X(_yield, bf10, f3af8001), \ | |
10333 | X(_wfe, bf20, f3af8002), \ | |
10334 | X(_wfi, bf30, f3af8003), \ | |
53c4b28b | 10335 | X(_sev, bf40, f3af8004), \ |
74db7efb NC |
10336 | X(_sevl, bf50, f3af8005), \ |
10337 | X(_udf, de00, f7f0a000) | |
c19d1205 ZW |
10338 | |
10339 | /* To catch errors in encoding functions, the codes are all offset by | |
10340 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
10341 | as 16-bit instructions. */ | |
21d799b5 | 10342 | #define X(a,b,c) T_MNEM##a |
c19d1205 ZW |
10343 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; |
10344 | #undef X | |
10345 | ||
10346 | #define X(a,b,c) 0x##b | |
10347 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
10348 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
10349 | #undef X | |
10350 | ||
10351 | #define X(a,b,c) 0x##c | |
10352 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
c921be7d NC |
10353 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) |
10354 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
c19d1205 ZW |
10355 | #undef X |
10356 | #undef T16_32_TAB | |
10357 | ||
10358 | /* Thumb instruction encoders, in alphabetical order. */ | |
10359 | ||
92e90b6e | 10360 | /* ADDW or SUBW. */ |
c921be7d | 10361 | |
92e90b6e PB |
10362 | static void |
10363 | do_t_add_sub_w (void) | |
10364 | { | |
10365 | int Rd, Rn; | |
10366 | ||
10367 | Rd = inst.operands[0].reg; | |
10368 | Rn = inst.operands[1].reg; | |
10369 | ||
539d4391 NC |
10370 | /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this |
10371 | is the SP-{plus,minus}-immediate form of the instruction. */ | |
10372 | if (Rn == REG_SP) | |
10373 | constraint (Rd == REG_PC, BAD_PC); | |
10374 | else | |
10375 | reject_bad_reg (Rd); | |
fdfde340 | 10376 | |
92e90b6e PB |
10377 | inst.instruction |= (Rn << 16) | (Rd << 8); |
10378 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
10379 | } | |
10380 | ||
c19d1205 ZW |
10381 | /* Parse an add or subtract instruction. We get here with inst.instruction |
10382 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
10383 | ||
10384 | static void | |
10385 | do_t_add_sub (void) | |
10386 | { | |
10387 | int Rd, Rs, Rn; | |
10388 | ||
10389 | Rd = inst.operands[0].reg; | |
10390 | Rs = (inst.operands[1].present | |
10391 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10392 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10393 | ||
e07e6e58 NC |
10394 | if (Rd == REG_PC) |
10395 | set_it_insn_type_last (); | |
10396 | ||
c19d1205 ZW |
10397 | if (unified_syntax) |
10398 | { | |
0110f2b8 PB |
10399 | bfd_boolean flags; |
10400 | bfd_boolean narrow; | |
10401 | int opcode; | |
10402 | ||
10403 | flags = (inst.instruction == T_MNEM_adds | |
10404 | || inst.instruction == T_MNEM_subs); | |
10405 | if (flags) | |
e07e6e58 | 10406 | narrow = !in_it_block (); |
0110f2b8 | 10407 | else |
e07e6e58 | 10408 | narrow = in_it_block (); |
c19d1205 | 10409 | if (!inst.operands[2].isreg) |
b99bd4ef | 10410 | { |
16805f35 PB |
10411 | int add; |
10412 | ||
fdfde340 JM |
10413 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); |
10414 | ||
16805f35 PB |
10415 | add = (inst.instruction == T_MNEM_add |
10416 | || inst.instruction == T_MNEM_adds); | |
0110f2b8 PB |
10417 | opcode = 0; |
10418 | if (inst.size_req != 4) | |
10419 | { | |
0110f2b8 | 10420 | /* Attempt to use a narrow opcode, with relaxation if |
477330fc | 10421 | appropriate. */ |
0110f2b8 PB |
10422 | if (Rd == REG_SP && Rs == REG_SP && !flags) |
10423 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
10424 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
10425 | opcode = T_MNEM_add_sp; | |
10426 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
10427 | opcode = T_MNEM_add_pc; | |
10428 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
10429 | { | |
10430 | if (flags) | |
10431 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
10432 | else | |
10433 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
10434 | } | |
10435 | if (opcode) | |
10436 | { | |
10437 | inst.instruction = THUMB_OP16(opcode); | |
10438 | inst.instruction |= (Rd << 4) | Rs; | |
72d98d16 MG |
10439 | if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC |
10440 | || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
10441 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
0110f2b8 PB |
10442 | if (inst.size_req != 2) |
10443 | inst.relax = opcode; | |
10444 | } | |
10445 | else | |
10446 | constraint (inst.size_req == 2, BAD_HIREG); | |
10447 | } | |
10448 | if (inst.size_req == 4 | |
10449 | || (inst.size_req != 2 && !opcode)) | |
10450 | { | |
efd81785 PB |
10451 | if (Rd == REG_PC) |
10452 | { | |
fdfde340 | 10453 | constraint (add, BAD_PC); |
efd81785 PB |
10454 | constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs, |
10455 | _("only SUBS PC, LR, #const allowed")); | |
10456 | constraint (inst.reloc.exp.X_op != O_constant, | |
10457 | _("expression too complex")); | |
10458 | constraint (inst.reloc.exp.X_add_number < 0 | |
10459 | || inst.reloc.exp.X_add_number > 0xff, | |
10460 | _("immediate value out of range")); | |
10461 | inst.instruction = T2_SUBS_PC_LR | |
10462 | | inst.reloc.exp.X_add_number; | |
10463 | inst.reloc.type = BFD_RELOC_UNUSED; | |
10464 | return; | |
10465 | } | |
10466 | else if (Rs == REG_PC) | |
16805f35 PB |
10467 | { |
10468 | /* Always use addw/subw. */ | |
10469 | inst.instruction = add ? 0xf20f0000 : 0xf2af0000; | |
10470 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
10471 | } | |
10472 | else | |
10473 | { | |
10474 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10475 | inst.instruction = (inst.instruction & 0xe1ffffff) | |
10476 | | 0x10000000; | |
10477 | if (flags) | |
10478 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10479 | else | |
10480 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM; | |
10481 | } | |
dc4503c6 PB |
10482 | inst.instruction |= Rd << 8; |
10483 | inst.instruction |= Rs << 16; | |
0110f2b8 | 10484 | } |
b99bd4ef | 10485 | } |
c19d1205 ZW |
10486 | else |
10487 | { | |
5f4cb198 NC |
10488 | unsigned int value = inst.reloc.exp.X_add_number; |
10489 | unsigned int shift = inst.operands[2].shift_kind; | |
10490 | ||
c19d1205 ZW |
10491 | Rn = inst.operands[2].reg; |
10492 | /* See if we can do this with a 16-bit instruction. */ | |
10493 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
10494 | { | |
e27ec89e PB |
10495 | if (Rd > 7 || Rs > 7 || Rn > 7) |
10496 | narrow = FALSE; | |
10497 | ||
10498 | if (narrow) | |
c19d1205 | 10499 | { |
e27ec89e PB |
10500 | inst.instruction = ((inst.instruction == T_MNEM_adds |
10501 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
10502 | ? T_OPCODE_ADD_R3 |
10503 | : T_OPCODE_SUB_R3); | |
10504 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
10505 | return; | |
10506 | } | |
b99bd4ef | 10507 | |
7e806470 | 10508 | if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn)) |
c19d1205 | 10509 | { |
7e806470 PB |
10510 | /* Thumb-1 cores (except v6-M) require at least one high |
10511 | register in a narrow non flag setting add. */ | |
10512 | if (Rd > 7 || Rn > 7 | |
10513 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2) | |
10514 | || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr)) | |
c19d1205 | 10515 | { |
7e806470 PB |
10516 | if (Rd == Rn) |
10517 | { | |
10518 | Rn = Rs; | |
10519 | Rs = Rd; | |
10520 | } | |
c19d1205 ZW |
10521 | inst.instruction = T_OPCODE_ADD_HI; |
10522 | inst.instruction |= (Rd & 8) << 4; | |
10523 | inst.instruction |= (Rd & 7); | |
10524 | inst.instruction |= Rn << 3; | |
10525 | return; | |
10526 | } | |
c19d1205 ZW |
10527 | } |
10528 | } | |
c921be7d | 10529 | |
fdfde340 JM |
10530 | constraint (Rd == REG_PC, BAD_PC); |
10531 | constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP); | |
10532 | constraint (Rs == REG_PC, BAD_PC); | |
10533 | reject_bad_reg (Rn); | |
10534 | ||
c19d1205 ZW |
10535 | /* If we get here, it can't be done in 16 bits. */ |
10536 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
10537 | _("shift must be constant")); | |
10538 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10539 | inst.instruction |= Rd << 8; | |
10540 | inst.instruction |= Rs << 16; | |
5f4cb198 NC |
10541 | constraint (Rd == REG_SP && Rs == REG_SP && value > 3, |
10542 | _("shift value over 3 not allowed in thumb mode")); | |
10543 | constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL, | |
10544 | _("only LSL shift allowed in thumb mode")); | |
c19d1205 ZW |
10545 | encode_thumb32_shifted_operand (2); |
10546 | } | |
10547 | } | |
10548 | else | |
10549 | { | |
10550 | constraint (inst.instruction == T_MNEM_adds | |
10551 | || inst.instruction == T_MNEM_subs, | |
10552 | BAD_THUMB32); | |
b99bd4ef | 10553 | |
c19d1205 | 10554 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 10555 | { |
c19d1205 ZW |
10556 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
10557 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
10558 | BAD_HIREG); | |
10559 | ||
10560 | inst.instruction = (inst.instruction == T_MNEM_add | |
10561 | ? 0x0000 : 0x8000); | |
10562 | inst.instruction |= (Rd << 4) | Rs; | |
10563 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
10564 | return; |
10565 | } | |
10566 | ||
c19d1205 ZW |
10567 | Rn = inst.operands[2].reg; |
10568 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 10569 | |
c19d1205 ZW |
10570 | /* We now have Rd, Rs, and Rn set to registers. */ |
10571 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 10572 | { |
c19d1205 ZW |
10573 | /* Can't do this for SUB. */ |
10574 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
10575 | inst.instruction = T_OPCODE_ADD_HI; | |
10576 | inst.instruction |= (Rd & 8) << 4; | |
10577 | inst.instruction |= (Rd & 7); | |
10578 | if (Rs == Rd) | |
10579 | inst.instruction |= Rn << 3; | |
10580 | else if (Rn == Rd) | |
10581 | inst.instruction |= Rs << 3; | |
10582 | else | |
10583 | constraint (1, _("dest must overlap one source register")); | |
10584 | } | |
10585 | else | |
10586 | { | |
10587 | inst.instruction = (inst.instruction == T_MNEM_add | |
10588 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
10589 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 10590 | } |
b99bd4ef | 10591 | } |
b99bd4ef NC |
10592 | } |
10593 | ||
c19d1205 ZW |
10594 | static void |
10595 | do_t_adr (void) | |
10596 | { | |
fdfde340 JM |
10597 | unsigned Rd; |
10598 | ||
10599 | Rd = inst.operands[0].reg; | |
10600 | reject_bad_reg (Rd); | |
10601 | ||
10602 | if (unified_syntax && inst.size_req == 0 && Rd <= 7) | |
0110f2b8 PB |
10603 | { |
10604 | /* Defer to section relaxation. */ | |
10605 | inst.relax = inst.instruction; | |
10606 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 | 10607 | inst.instruction |= Rd << 4; |
0110f2b8 PB |
10608 | } |
10609 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 10610 | { |
0110f2b8 | 10611 | /* Generate a 32-bit opcode. */ |
e9f89963 | 10612 | inst.instruction = THUMB_OP32 (inst.instruction); |
fdfde340 | 10613 | inst.instruction |= Rd << 8; |
e9f89963 PB |
10614 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; |
10615 | inst.reloc.pc_rel = 1; | |
10616 | } | |
10617 | else | |
10618 | { | |
0110f2b8 | 10619 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
10620 | inst.instruction = THUMB_OP16 (inst.instruction); |
10621 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
10622 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
10623 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 10624 | |
fdfde340 | 10625 | inst.instruction |= Rd << 4; |
e9f89963 | 10626 | } |
c19d1205 | 10627 | } |
b99bd4ef | 10628 | |
c19d1205 ZW |
10629 | /* Arithmetic instructions for which there is just one 16-bit |
10630 | instruction encoding, and it allows only two low registers. | |
10631 | For maximal compatibility with ARM syntax, we allow three register | |
10632 | operands even when Thumb-32 instructions are not available, as long | |
10633 | as the first two are identical. For instance, both "sbc r0,r1" and | |
10634 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 10635 | static void |
c19d1205 | 10636 | do_t_arit3 (void) |
b99bd4ef | 10637 | { |
c19d1205 | 10638 | int Rd, Rs, Rn; |
b99bd4ef | 10639 | |
c19d1205 ZW |
10640 | Rd = inst.operands[0].reg; |
10641 | Rs = (inst.operands[1].present | |
10642 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10643 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10644 | Rn = inst.operands[2].reg; | |
b99bd4ef | 10645 | |
fdfde340 JM |
10646 | reject_bad_reg (Rd); |
10647 | reject_bad_reg (Rs); | |
10648 | if (inst.operands[2].isreg) | |
10649 | reject_bad_reg (Rn); | |
10650 | ||
c19d1205 | 10651 | if (unified_syntax) |
b99bd4ef | 10652 | { |
c19d1205 ZW |
10653 | if (!inst.operands[2].isreg) |
10654 | { | |
10655 | /* For an immediate, we always generate a 32-bit opcode; | |
10656 | section relaxation will shrink it later if possible. */ | |
10657 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10658 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10659 | inst.instruction |= Rd << 8; | |
10660 | inst.instruction |= Rs << 16; | |
10661 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10662 | } | |
10663 | else | |
10664 | { | |
e27ec89e PB |
10665 | bfd_boolean narrow; |
10666 | ||
c19d1205 | 10667 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 10668 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 10669 | narrow = !in_it_block (); |
e27ec89e | 10670 | else |
e07e6e58 | 10671 | narrow = in_it_block (); |
e27ec89e PB |
10672 | |
10673 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
10674 | narrow = FALSE; | |
10675 | if (inst.operands[2].shifted) | |
10676 | narrow = FALSE; | |
10677 | if (inst.size_req == 4) | |
10678 | narrow = FALSE; | |
10679 | ||
10680 | if (narrow | |
c19d1205 ZW |
10681 | && Rd == Rs) |
10682 | { | |
10683 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10684 | inst.instruction |= Rd; | |
10685 | inst.instruction |= Rn << 3; | |
10686 | return; | |
10687 | } | |
b99bd4ef | 10688 | |
c19d1205 ZW |
10689 | /* If we get here, it can't be done in 16 bits. */ |
10690 | constraint (inst.operands[2].shifted | |
10691 | && inst.operands[2].immisreg, | |
10692 | _("shift must be constant")); | |
10693 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10694 | inst.instruction |= Rd << 8; | |
10695 | inst.instruction |= Rs << 16; | |
10696 | encode_thumb32_shifted_operand (2); | |
10697 | } | |
a737bd4d | 10698 | } |
c19d1205 | 10699 | else |
b99bd4ef | 10700 | { |
c19d1205 ZW |
10701 | /* On its face this is a lie - the instruction does set the |
10702 | flags. However, the only supported mnemonic in this mode | |
10703 | says it doesn't. */ | |
10704 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 10705 | |
c19d1205 ZW |
10706 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
10707 | _("unshifted register required")); | |
10708 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
10709 | constraint (Rd != Rs, | |
10710 | _("dest and source1 must be the same register")); | |
a737bd4d | 10711 | |
c19d1205 ZW |
10712 | inst.instruction = THUMB_OP16 (inst.instruction); |
10713 | inst.instruction |= Rd; | |
10714 | inst.instruction |= Rn << 3; | |
b99bd4ef | 10715 | } |
a737bd4d | 10716 | } |
b99bd4ef | 10717 | |
c19d1205 ZW |
10718 | /* Similarly, but for instructions where the arithmetic operation is |
10719 | commutative, so we can allow either of them to be different from | |
10720 | the destination operand in a 16-bit instruction. For instance, all | |
10721 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
10722 | accepted. */ | |
10723 | static void | |
10724 | do_t_arit3c (void) | |
a737bd4d | 10725 | { |
c19d1205 | 10726 | int Rd, Rs, Rn; |
b99bd4ef | 10727 | |
c19d1205 ZW |
10728 | Rd = inst.operands[0].reg; |
10729 | Rs = (inst.operands[1].present | |
10730 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
10731 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
10732 | Rn = inst.operands[2].reg; | |
c921be7d | 10733 | |
fdfde340 JM |
10734 | reject_bad_reg (Rd); |
10735 | reject_bad_reg (Rs); | |
10736 | if (inst.operands[2].isreg) | |
10737 | reject_bad_reg (Rn); | |
a737bd4d | 10738 | |
c19d1205 | 10739 | if (unified_syntax) |
a737bd4d | 10740 | { |
c19d1205 | 10741 | if (!inst.operands[2].isreg) |
b99bd4ef | 10742 | { |
c19d1205 ZW |
10743 | /* For an immediate, we always generate a 32-bit opcode; |
10744 | section relaxation will shrink it later if possible. */ | |
10745 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10746 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
10747 | inst.instruction |= Rd << 8; | |
10748 | inst.instruction |= Rs << 16; | |
10749 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 10750 | } |
c19d1205 | 10751 | else |
a737bd4d | 10752 | { |
e27ec89e PB |
10753 | bfd_boolean narrow; |
10754 | ||
c19d1205 | 10755 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e | 10756 | if (THUMB_SETS_FLAGS (inst.instruction)) |
e07e6e58 | 10757 | narrow = !in_it_block (); |
e27ec89e | 10758 | else |
e07e6e58 | 10759 | narrow = in_it_block (); |
e27ec89e PB |
10760 | |
10761 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
10762 | narrow = FALSE; | |
10763 | if (inst.operands[2].shifted) | |
10764 | narrow = FALSE; | |
10765 | if (inst.size_req == 4) | |
10766 | narrow = FALSE; | |
10767 | ||
10768 | if (narrow) | |
a737bd4d | 10769 | { |
c19d1205 | 10770 | if (Rd == Rs) |
a737bd4d | 10771 | { |
c19d1205 ZW |
10772 | inst.instruction = THUMB_OP16 (inst.instruction); |
10773 | inst.instruction |= Rd; | |
10774 | inst.instruction |= Rn << 3; | |
10775 | return; | |
a737bd4d | 10776 | } |
c19d1205 | 10777 | if (Rd == Rn) |
a737bd4d | 10778 | { |
c19d1205 ZW |
10779 | inst.instruction = THUMB_OP16 (inst.instruction); |
10780 | inst.instruction |= Rd; | |
10781 | inst.instruction |= Rs << 3; | |
10782 | return; | |
a737bd4d NC |
10783 | } |
10784 | } | |
c19d1205 ZW |
10785 | |
10786 | /* If we get here, it can't be done in 16 bits. */ | |
10787 | constraint (inst.operands[2].shifted | |
10788 | && inst.operands[2].immisreg, | |
10789 | _("shift must be constant")); | |
10790 | inst.instruction = THUMB_OP32 (inst.instruction); | |
10791 | inst.instruction |= Rd << 8; | |
10792 | inst.instruction |= Rs << 16; | |
10793 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 10794 | } |
b99bd4ef | 10795 | } |
c19d1205 ZW |
10796 | else |
10797 | { | |
10798 | /* On its face this is a lie - the instruction does set the | |
10799 | flags. However, the only supported mnemonic in this mode | |
10800 | says it doesn't. */ | |
10801 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 10802 | |
c19d1205 ZW |
10803 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
10804 | _("unshifted register required")); | |
10805 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
10806 | ||
10807 | inst.instruction = THUMB_OP16 (inst.instruction); | |
10808 | inst.instruction |= Rd; | |
10809 | ||
10810 | if (Rd == Rs) | |
10811 | inst.instruction |= Rn << 3; | |
10812 | else if (Rd == Rn) | |
10813 | inst.instruction |= Rs << 3; | |
10814 | else | |
10815 | constraint (1, _("dest must overlap one source register")); | |
10816 | } | |
a737bd4d NC |
10817 | } |
10818 | ||
c19d1205 ZW |
10819 | static void |
10820 | do_t_bfc (void) | |
a737bd4d | 10821 | { |
fdfde340 | 10822 | unsigned Rd; |
c19d1205 ZW |
10823 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
10824 | constraint (msb > 32, _("bit-field extends past end of register")); | |
10825 | /* The instruction encoding stores the LSB and MSB, | |
10826 | not the LSB and width. */ | |
fdfde340 JM |
10827 | Rd = inst.operands[0].reg; |
10828 | reject_bad_reg (Rd); | |
10829 | inst.instruction |= Rd << 8; | |
c19d1205 ZW |
10830 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; |
10831 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
10832 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
10833 | } |
10834 | ||
c19d1205 ZW |
10835 | static void |
10836 | do_t_bfi (void) | |
b99bd4ef | 10837 | { |
fdfde340 | 10838 | int Rd, Rn; |
c19d1205 | 10839 | unsigned int msb; |
b99bd4ef | 10840 | |
fdfde340 JM |
10841 | Rd = inst.operands[0].reg; |
10842 | reject_bad_reg (Rd); | |
10843 | ||
c19d1205 ZW |
10844 | /* #0 in second position is alternative syntax for bfc, which is |
10845 | the same instruction but with REG_PC in the Rm field. */ | |
10846 | if (!inst.operands[1].isreg) | |
fdfde340 JM |
10847 | Rn = REG_PC; |
10848 | else | |
10849 | { | |
10850 | Rn = inst.operands[1].reg; | |
10851 | reject_bad_reg (Rn); | |
10852 | } | |
b99bd4ef | 10853 | |
c19d1205 ZW |
10854 | msb = inst.operands[2].imm + inst.operands[3].imm; |
10855 | constraint (msb > 32, _("bit-field extends past end of register")); | |
10856 | /* The instruction encoding stores the LSB and MSB, | |
10857 | not the LSB and width. */ | |
fdfde340 JM |
10858 | inst.instruction |= Rd << 8; |
10859 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
10860 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
10861 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
10862 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
10863 | } |
10864 | ||
c19d1205 ZW |
10865 | static void |
10866 | do_t_bfx (void) | |
b99bd4ef | 10867 | { |
fdfde340 JM |
10868 | unsigned Rd, Rn; |
10869 | ||
10870 | Rd = inst.operands[0].reg; | |
10871 | Rn = inst.operands[1].reg; | |
10872 | ||
10873 | reject_bad_reg (Rd); | |
10874 | reject_bad_reg (Rn); | |
10875 | ||
c19d1205 ZW |
10876 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
10877 | _("bit-field extends past end of register")); | |
fdfde340 JM |
10878 | inst.instruction |= Rd << 8; |
10879 | inst.instruction |= Rn << 16; | |
c19d1205 ZW |
10880 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; |
10881 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
10882 | inst.instruction |= inst.operands[3].imm - 1; | |
10883 | } | |
b99bd4ef | 10884 | |
c19d1205 ZW |
10885 | /* ARM V5 Thumb BLX (argument parse) |
10886 | BLX <target_addr> which is BLX(1) | |
10887 | BLX <Rm> which is BLX(2) | |
10888 | Unfortunately, there are two different opcodes for this mnemonic. | |
10889 | So, the insns[].value is not used, and the code here zaps values | |
10890 | into inst.instruction. | |
b99bd4ef | 10891 | |
c19d1205 ZW |
10892 | ??? How to take advantage of the additional two bits of displacement |
10893 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 10894 | |
c19d1205 ZW |
10895 | static void |
10896 | do_t_blx (void) | |
10897 | { | |
e07e6e58 NC |
10898 | set_it_insn_type_last (); |
10899 | ||
c19d1205 | 10900 | if (inst.operands[0].isreg) |
fdfde340 JM |
10901 | { |
10902 | constraint (inst.operands[0].reg == REG_PC, BAD_PC); | |
10903 | /* We have a register, so this is BLX(2). */ | |
10904 | inst.instruction |= inst.operands[0].reg << 3; | |
10905 | } | |
b99bd4ef NC |
10906 | else |
10907 | { | |
c19d1205 | 10908 | /* No register. This must be BLX(1). */ |
2fc8bdac | 10909 | inst.instruction = 0xf000e800; |
0855e32b | 10910 | encode_branch (BFD_RELOC_THUMB_PCREL_BLX); |
b99bd4ef NC |
10911 | } |
10912 | } | |
10913 | ||
c19d1205 ZW |
10914 | static void |
10915 | do_t_branch (void) | |
b99bd4ef | 10916 | { |
0110f2b8 | 10917 | int opcode; |
dfa9f0d5 | 10918 | int cond; |
9ae92b05 | 10919 | int reloc; |
dfa9f0d5 | 10920 | |
e07e6e58 NC |
10921 | cond = inst.cond; |
10922 | set_it_insn_type (IF_INSIDE_IT_LAST_INSN); | |
10923 | ||
10924 | if (in_it_block ()) | |
dfa9f0d5 PB |
10925 | { |
10926 | /* Conditional branches inside IT blocks are encoded as unconditional | |
477330fc | 10927 | branches. */ |
dfa9f0d5 | 10928 | cond = COND_ALWAYS; |
dfa9f0d5 PB |
10929 | } |
10930 | else | |
10931 | cond = inst.cond; | |
10932 | ||
10933 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
10934 | opcode = T_MNEM_bcond; |
10935 | else | |
10936 | opcode = inst.instruction; | |
10937 | ||
12d6b0b7 RS |
10938 | if (unified_syntax |
10939 | && (inst.size_req == 4 | |
10960bfb PB |
10940 | || (inst.size_req != 2 |
10941 | && (inst.operands[0].hasreloc | |
10942 | || inst.reloc.exp.X_op == O_constant)))) | |
c19d1205 | 10943 | { |
0110f2b8 | 10944 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 10945 | if (cond == COND_ALWAYS) |
9ae92b05 | 10946 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
10947 | else |
10948 | { | |
ff8646ee TP |
10949 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2), |
10950 | _("selected architecture does not support " | |
10951 | "wide conditional branch instruction")); | |
10952 | ||
9c2799c2 | 10953 | gas_assert (cond != 0xF); |
dfa9f0d5 | 10954 | inst.instruction |= cond << 22; |
9ae92b05 | 10955 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH20; |
c19d1205 ZW |
10956 | } |
10957 | } | |
b99bd4ef NC |
10958 | else |
10959 | { | |
0110f2b8 | 10960 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 10961 | if (cond == COND_ALWAYS) |
9ae92b05 | 10962 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH12; |
c19d1205 | 10963 | else |
b99bd4ef | 10964 | { |
dfa9f0d5 | 10965 | inst.instruction |= cond << 8; |
9ae92b05 | 10966 | reloc = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 10967 | } |
0110f2b8 PB |
10968 | /* Allow section relaxation. */ |
10969 | if (unified_syntax && inst.size_req != 2) | |
10970 | inst.relax = opcode; | |
b99bd4ef | 10971 | } |
9ae92b05 | 10972 | inst.reloc.type = reloc; |
c19d1205 | 10973 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
10974 | } |
10975 | ||
8884b720 | 10976 | /* Actually do the work for Thumb state bkpt and hlt. The only difference |
bacebabc | 10977 | between the two is the maximum immediate allowed - which is passed in |
8884b720 | 10978 | RANGE. */ |
b99bd4ef | 10979 | static void |
8884b720 | 10980 | do_t_bkpt_hlt1 (int range) |
b99bd4ef | 10981 | { |
dfa9f0d5 PB |
10982 | constraint (inst.cond != COND_ALWAYS, |
10983 | _("instruction is always unconditional")); | |
c19d1205 | 10984 | if (inst.operands[0].present) |
b99bd4ef | 10985 | { |
8884b720 | 10986 | constraint (inst.operands[0].imm > range, |
c19d1205 ZW |
10987 | _("immediate value out of range")); |
10988 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 10989 | } |
8884b720 MGD |
10990 | |
10991 | set_it_insn_type (NEUTRAL_IT_INSN); | |
10992 | } | |
10993 | ||
10994 | static void | |
10995 | do_t_hlt (void) | |
10996 | { | |
10997 | do_t_bkpt_hlt1 (63); | |
10998 | } | |
10999 | ||
11000 | static void | |
11001 | do_t_bkpt (void) | |
11002 | { | |
11003 | do_t_bkpt_hlt1 (255); | |
b99bd4ef NC |
11004 | } |
11005 | ||
11006 | static void | |
c19d1205 | 11007 | do_t_branch23 (void) |
b99bd4ef | 11008 | { |
e07e6e58 | 11009 | set_it_insn_type_last (); |
0855e32b | 11010 | encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23); |
fa94de6b | 11011 | |
0855e32b NS |
11012 | /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in |
11013 | this file. We used to simply ignore the PLT reloc type here -- | |
11014 | the branch encoding is now needed to deal with TLSCALL relocs. | |
11015 | So if we see a PLT reloc now, put it back to how it used to be to | |
11016 | keep the preexisting behaviour. */ | |
11017 | if (inst.reloc.type == BFD_RELOC_ARM_PLT32) | |
11018 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
90e4755a | 11019 | |
4343666d | 11020 | #if defined(OBJ_COFF) |
c19d1205 ZW |
11021 | /* If the destination of the branch is a defined symbol which does not have |
11022 | the THUMB_FUNC attribute, then we must be calling a function which has | |
11023 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
11024 | function and change the branch to refer to that function instead. */ | |
11025 | if ( inst.reloc.exp.X_op == O_symbol | |
11026 | && inst.reloc.exp.X_add_symbol != NULL | |
11027 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
11028 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
11029 | inst.reloc.exp.X_add_symbol = | |
11030 | find_real_start (inst.reloc.exp.X_add_symbol); | |
4343666d | 11031 | #endif |
90e4755a RE |
11032 | } |
11033 | ||
11034 | static void | |
c19d1205 | 11035 | do_t_bx (void) |
90e4755a | 11036 | { |
e07e6e58 | 11037 | set_it_insn_type_last (); |
c19d1205 ZW |
11038 | inst.instruction |= inst.operands[0].reg << 3; |
11039 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
11040 | should cause the alignment to be checked once it is known. This is | |
11041 | because BX PC only works if the instruction is word aligned. */ | |
11042 | } | |
90e4755a | 11043 | |
c19d1205 ZW |
11044 | static void |
11045 | do_t_bxj (void) | |
11046 | { | |
fdfde340 | 11047 | int Rm; |
90e4755a | 11048 | |
e07e6e58 | 11049 | set_it_insn_type_last (); |
fdfde340 JM |
11050 | Rm = inst.operands[0].reg; |
11051 | reject_bad_reg (Rm); | |
11052 | inst.instruction |= Rm << 16; | |
90e4755a RE |
11053 | } |
11054 | ||
11055 | static void | |
c19d1205 | 11056 | do_t_clz (void) |
90e4755a | 11057 | { |
fdfde340 JM |
11058 | unsigned Rd; |
11059 | unsigned Rm; | |
11060 | ||
11061 | Rd = inst.operands[0].reg; | |
11062 | Rm = inst.operands[1].reg; | |
11063 | ||
11064 | reject_bad_reg (Rd); | |
11065 | reject_bad_reg (Rm); | |
11066 | ||
11067 | inst.instruction |= Rd << 8; | |
11068 | inst.instruction |= Rm << 16; | |
11069 | inst.instruction |= Rm; | |
c19d1205 | 11070 | } |
90e4755a | 11071 | |
dfa9f0d5 PB |
11072 | static void |
11073 | do_t_cps (void) | |
11074 | { | |
e07e6e58 | 11075 | set_it_insn_type (OUTSIDE_IT_INSN); |
dfa9f0d5 PB |
11076 | inst.instruction |= inst.operands[0].imm; |
11077 | } | |
11078 | ||
c19d1205 ZW |
11079 | static void |
11080 | do_t_cpsi (void) | |
11081 | { | |
e07e6e58 | 11082 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 | 11083 | if (unified_syntax |
62b3e311 PB |
11084 | && (inst.operands[1].present || inst.size_req == 4) |
11085 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 11086 | { |
c19d1205 ZW |
11087 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
11088 | inst.instruction = 0xf3af8000; | |
11089 | inst.instruction |= imod << 9; | |
11090 | inst.instruction |= inst.operands[0].imm << 5; | |
11091 | if (inst.operands[1].present) | |
11092 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 11093 | } |
c19d1205 | 11094 | else |
90e4755a | 11095 | { |
62b3e311 PB |
11096 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
11097 | && (inst.operands[0].imm & 4), | |
11098 | _("selected processor does not support 'A' form " | |
11099 | "of this instruction")); | |
11100 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
11101 | _("Thumb does not support the 2-argument " |
11102 | "form of this instruction")); | |
11103 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 11104 | } |
90e4755a RE |
11105 | } |
11106 | ||
c19d1205 ZW |
11107 | /* THUMB CPY instruction (argument parse). */ |
11108 | ||
90e4755a | 11109 | static void |
c19d1205 | 11110 | do_t_cpy (void) |
90e4755a | 11111 | { |
c19d1205 | 11112 | if (inst.size_req == 4) |
90e4755a | 11113 | { |
c19d1205 ZW |
11114 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
11115 | inst.instruction |= inst.operands[0].reg << 8; | |
11116 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 11117 | } |
c19d1205 | 11118 | else |
90e4755a | 11119 | { |
c19d1205 ZW |
11120 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
11121 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
11122 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 11123 | } |
90e4755a RE |
11124 | } |
11125 | ||
90e4755a | 11126 | static void |
25fe350b | 11127 | do_t_cbz (void) |
90e4755a | 11128 | { |
e07e6e58 | 11129 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
11130 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11131 | inst.instruction |= inst.operands[0].reg; | |
11132 | inst.reloc.pc_rel = 1; | |
11133 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
11134 | } | |
90e4755a | 11135 | |
62b3e311 PB |
11136 | static void |
11137 | do_t_dbg (void) | |
11138 | { | |
11139 | inst.instruction |= inst.operands[0].imm; | |
11140 | } | |
11141 | ||
11142 | static void | |
11143 | do_t_div (void) | |
11144 | { | |
fdfde340 JM |
11145 | unsigned Rd, Rn, Rm; |
11146 | ||
11147 | Rd = inst.operands[0].reg; | |
11148 | Rn = (inst.operands[1].present | |
11149 | ? inst.operands[1].reg : Rd); | |
11150 | Rm = inst.operands[2].reg; | |
11151 | ||
11152 | reject_bad_reg (Rd); | |
11153 | reject_bad_reg (Rn); | |
11154 | reject_bad_reg (Rm); | |
11155 | ||
11156 | inst.instruction |= Rd << 8; | |
11157 | inst.instruction |= Rn << 16; | |
11158 | inst.instruction |= Rm; | |
62b3e311 PB |
11159 | } |
11160 | ||
c19d1205 ZW |
11161 | static void |
11162 | do_t_hint (void) | |
11163 | { | |
11164 | if (unified_syntax && inst.size_req == 4) | |
11165 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11166 | else | |
11167 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11168 | } | |
90e4755a | 11169 | |
c19d1205 ZW |
11170 | static void |
11171 | do_t_it (void) | |
11172 | { | |
11173 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 11174 | |
e07e6e58 NC |
11175 | set_it_insn_type (IT_INSN); |
11176 | now_it.mask = (inst.instruction & 0xf) | 0x10; | |
11177 | now_it.cc = cond; | |
5a01bb1d | 11178 | now_it.warn_deprecated = FALSE; |
e27ec89e PB |
11179 | |
11180 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 11181 | if ((cond & 0x1) == 0x0) |
90e4755a | 11182 | { |
c19d1205 | 11183 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 11184 | |
c19d1205 | 11185 | if ((mask & 0x7) == 0) |
5a01bb1d MGD |
11186 | { |
11187 | /* No conversion needed. */ | |
11188 | now_it.block_length = 1; | |
11189 | } | |
c19d1205 | 11190 | else if ((mask & 0x3) == 0) |
5a01bb1d MGD |
11191 | { |
11192 | mask ^= 0x8; | |
11193 | now_it.block_length = 2; | |
11194 | } | |
e27ec89e | 11195 | else if ((mask & 0x1) == 0) |
5a01bb1d MGD |
11196 | { |
11197 | mask ^= 0xC; | |
11198 | now_it.block_length = 3; | |
11199 | } | |
c19d1205 | 11200 | else |
5a01bb1d MGD |
11201 | { |
11202 | mask ^= 0xE; | |
11203 | now_it.block_length = 4; | |
11204 | } | |
90e4755a | 11205 | |
e27ec89e PB |
11206 | inst.instruction &= 0xfff0; |
11207 | inst.instruction |= mask; | |
c19d1205 | 11208 | } |
90e4755a | 11209 | |
c19d1205 ZW |
11210 | inst.instruction |= cond << 4; |
11211 | } | |
90e4755a | 11212 | |
3c707909 PB |
11213 | /* Helper function used for both push/pop and ldm/stm. */ |
11214 | static void | |
11215 | encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback) | |
11216 | { | |
11217 | bfd_boolean load; | |
11218 | ||
11219 | load = (inst.instruction & (1 << 20)) != 0; | |
11220 | ||
11221 | if (mask & (1 << 13)) | |
11222 | inst.error = _("SP not allowed in register list"); | |
1e5b0379 NC |
11223 | |
11224 | if ((mask & (1 << base)) != 0 | |
11225 | && writeback) | |
11226 | inst.error = _("having the base register in the register list when " | |
11227 | "using write back is UNPREDICTABLE"); | |
11228 | ||
3c707909 PB |
11229 | if (load) |
11230 | { | |
e07e6e58 | 11231 | if (mask & (1 << 15)) |
477330fc RM |
11232 | { |
11233 | if (mask & (1 << 14)) | |
11234 | inst.error = _("LR and PC should not both be in register list"); | |
11235 | else | |
11236 | set_it_insn_type_last (); | |
11237 | } | |
3c707909 PB |
11238 | } |
11239 | else | |
11240 | { | |
11241 | if (mask & (1 << 15)) | |
11242 | inst.error = _("PC not allowed in register list"); | |
3c707909 PB |
11243 | } |
11244 | ||
11245 | if ((mask & (mask - 1)) == 0) | |
11246 | { | |
11247 | /* Single register transfers implemented as str/ldr. */ | |
11248 | if (writeback) | |
11249 | { | |
11250 | if (inst.instruction & (1 << 23)) | |
11251 | inst.instruction = 0x00000b04; /* ia! -> [base], #4 */ | |
11252 | else | |
11253 | inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */ | |
11254 | } | |
11255 | else | |
11256 | { | |
11257 | if (inst.instruction & (1 << 23)) | |
11258 | inst.instruction = 0x00800000; /* ia -> [base] */ | |
11259 | else | |
11260 | inst.instruction = 0x00000c04; /* db -> [base, #-4] */ | |
11261 | } | |
11262 | ||
11263 | inst.instruction |= 0xf8400000; | |
11264 | if (load) | |
11265 | inst.instruction |= 0x00100000; | |
11266 | ||
5f4273c7 | 11267 | mask = ffs (mask) - 1; |
3c707909 PB |
11268 | mask <<= 12; |
11269 | } | |
11270 | else if (writeback) | |
11271 | inst.instruction |= WRITE_BACK; | |
11272 | ||
11273 | inst.instruction |= mask; | |
11274 | inst.instruction |= base << 16; | |
11275 | } | |
11276 | ||
c19d1205 ZW |
11277 | static void |
11278 | do_t_ldmstm (void) | |
11279 | { | |
11280 | /* This really doesn't seem worth it. */ | |
11281 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
11282 | _("expression too complex")); | |
11283 | constraint (inst.operands[1].writeback, | |
11284 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 11285 | |
c19d1205 ZW |
11286 | if (unified_syntax) |
11287 | { | |
3c707909 PB |
11288 | bfd_boolean narrow; |
11289 | unsigned mask; | |
11290 | ||
11291 | narrow = FALSE; | |
c19d1205 ZW |
11292 | /* See if we can use a 16-bit instruction. */ |
11293 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
11294 | && inst.size_req != 4 | |
3c707909 | 11295 | && !(inst.operands[1].imm & ~0xff)) |
90e4755a | 11296 | { |
3c707909 | 11297 | mask = 1 << inst.operands[0].reg; |
90e4755a | 11298 | |
eab4f823 | 11299 | if (inst.operands[0].reg <= 7) |
90e4755a | 11300 | { |
3c707909 | 11301 | if (inst.instruction == T_MNEM_stmia |
eab4f823 MGD |
11302 | ? inst.operands[0].writeback |
11303 | : (inst.operands[0].writeback | |
11304 | == !(inst.operands[1].imm & mask))) | |
477330fc | 11305 | { |
eab4f823 MGD |
11306 | if (inst.instruction == T_MNEM_stmia |
11307 | && (inst.operands[1].imm & mask) | |
11308 | && (inst.operands[1].imm & (mask - 1))) | |
11309 | as_warn (_("value stored for r%d is UNKNOWN"), | |
11310 | inst.operands[0].reg); | |
3c707909 | 11311 | |
eab4f823 MGD |
11312 | inst.instruction = THUMB_OP16 (inst.instruction); |
11313 | inst.instruction |= inst.operands[0].reg << 8; | |
11314 | inst.instruction |= inst.operands[1].imm; | |
11315 | narrow = TRUE; | |
11316 | } | |
11317 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11318 | { | |
11319 | /* This means 1 register in reg list one of 3 situations: | |
11320 | 1. Instruction is stmia, but without writeback. | |
11321 | 2. lmdia without writeback, but with Rn not in | |
477330fc | 11322 | reglist. |
eab4f823 MGD |
11323 | 3. ldmia with writeback, but with Rn in reglist. |
11324 | Case 3 is UNPREDICTABLE behaviour, so we handle | |
11325 | case 1 and 2 which can be converted into a 16-bit | |
11326 | str or ldr. The SP cases are handled below. */ | |
11327 | unsigned long opcode; | |
11328 | /* First, record an error for Case 3. */ | |
11329 | if (inst.operands[1].imm & mask | |
11330 | && inst.operands[0].writeback) | |
fa94de6b | 11331 | inst.error = |
eab4f823 MGD |
11332 | _("having the base register in the register list when " |
11333 | "using write back is UNPREDICTABLE"); | |
fa94de6b RM |
11334 | |
11335 | opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str | |
eab4f823 MGD |
11336 | : T_MNEM_ldr); |
11337 | inst.instruction = THUMB_OP16 (opcode); | |
11338 | inst.instruction |= inst.operands[0].reg << 3; | |
11339 | inst.instruction |= (ffs (inst.operands[1].imm)-1); | |
11340 | narrow = TRUE; | |
11341 | } | |
90e4755a | 11342 | } |
eab4f823 | 11343 | else if (inst.operands[0] .reg == REG_SP) |
90e4755a | 11344 | { |
eab4f823 MGD |
11345 | if (inst.operands[0].writeback) |
11346 | { | |
fa94de6b | 11347 | inst.instruction = |
eab4f823 | 11348 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11349 | ? T_MNEM_push : T_MNEM_pop); |
eab4f823 | 11350 | inst.instruction |= inst.operands[1].imm; |
477330fc | 11351 | narrow = TRUE; |
eab4f823 MGD |
11352 | } |
11353 | else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0) | |
11354 | { | |
fa94de6b | 11355 | inst.instruction = |
eab4f823 | 11356 | THUMB_OP16 (inst.instruction == T_MNEM_stmia |
477330fc | 11357 | ? T_MNEM_str_sp : T_MNEM_ldr_sp); |
eab4f823 | 11358 | inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8); |
477330fc | 11359 | narrow = TRUE; |
eab4f823 | 11360 | } |
90e4755a | 11361 | } |
3c707909 PB |
11362 | } |
11363 | ||
11364 | if (!narrow) | |
11365 | { | |
c19d1205 ZW |
11366 | if (inst.instruction < 0xffff) |
11367 | inst.instruction = THUMB_OP32 (inst.instruction); | |
3c707909 | 11368 | |
5f4273c7 NC |
11369 | encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm, |
11370 | inst.operands[0].writeback); | |
90e4755a RE |
11371 | } |
11372 | } | |
c19d1205 | 11373 | else |
90e4755a | 11374 | { |
c19d1205 ZW |
11375 | constraint (inst.operands[0].reg > 7 |
11376 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
1198ca51 PB |
11377 | constraint (inst.instruction != T_MNEM_ldmia |
11378 | && inst.instruction != T_MNEM_stmia, | |
11379 | _("Thumb-2 instruction only valid in unified syntax")); | |
c19d1205 | 11380 | if (inst.instruction == T_MNEM_stmia) |
f03698e6 | 11381 | { |
c19d1205 ZW |
11382 | if (!inst.operands[0].writeback) |
11383 | as_warn (_("this instruction will write back the base register")); | |
11384 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
11385 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
1e5b0379 | 11386 | as_warn (_("value stored for r%d is UNKNOWN"), |
c19d1205 | 11387 | inst.operands[0].reg); |
f03698e6 | 11388 | } |
c19d1205 | 11389 | else |
90e4755a | 11390 | { |
c19d1205 ZW |
11391 | if (!inst.operands[0].writeback |
11392 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11393 | as_warn (_("this instruction will write back the base register")); | |
11394 | else if (inst.operands[0].writeback | |
11395 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
11396 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
11397 | } |
11398 | ||
c19d1205 ZW |
11399 | inst.instruction = THUMB_OP16 (inst.instruction); |
11400 | inst.instruction |= inst.operands[0].reg << 8; | |
11401 | inst.instruction |= inst.operands[1].imm; | |
11402 | } | |
11403 | } | |
e28cd48c | 11404 | |
c19d1205 ZW |
11405 | static void |
11406 | do_t_ldrex (void) | |
11407 | { | |
11408 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
11409 | || inst.operands[1].postind || inst.operands[1].writeback | |
11410 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
11411 | || inst.operands[1].negative, | |
01cfc07f | 11412 | BAD_ADDR_MODE); |
e28cd48c | 11413 | |
5be8be5d DG |
11414 | constraint ((inst.operands[1].reg == REG_PC), BAD_PC); |
11415 | ||
c19d1205 ZW |
11416 | inst.instruction |= inst.operands[0].reg << 12; |
11417 | inst.instruction |= inst.operands[1].reg << 16; | |
11418 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
11419 | } | |
e28cd48c | 11420 | |
c19d1205 ZW |
11421 | static void |
11422 | do_t_ldrexd (void) | |
11423 | { | |
11424 | if (!inst.operands[1].present) | |
1cac9012 | 11425 | { |
c19d1205 ZW |
11426 | constraint (inst.operands[0].reg == REG_LR, |
11427 | _("r14 not allowed as first register " | |
11428 | "when second register is omitted")); | |
11429 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 11430 | } |
c19d1205 ZW |
11431 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
11432 | BAD_OVERLAP); | |
b99bd4ef | 11433 | |
c19d1205 ZW |
11434 | inst.instruction |= inst.operands[0].reg << 12; |
11435 | inst.instruction |= inst.operands[1].reg << 8; | |
11436 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
11437 | } |
11438 | ||
11439 | static void | |
c19d1205 | 11440 | do_t_ldst (void) |
b99bd4ef | 11441 | { |
0110f2b8 PB |
11442 | unsigned long opcode; |
11443 | int Rn; | |
11444 | ||
e07e6e58 NC |
11445 | if (inst.operands[0].isreg |
11446 | && !inst.operands[0].preind | |
11447 | && inst.operands[0].reg == REG_PC) | |
11448 | set_it_insn_type_last (); | |
11449 | ||
0110f2b8 | 11450 | opcode = inst.instruction; |
c19d1205 | 11451 | if (unified_syntax) |
b99bd4ef | 11452 | { |
53365c0d PB |
11453 | if (!inst.operands[1].isreg) |
11454 | { | |
11455 | if (opcode <= 0xffff) | |
11456 | inst.instruction = THUMB_OP32 (opcode); | |
8335d6aa | 11457 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
53365c0d PB |
11458 | return; |
11459 | } | |
0110f2b8 PB |
11460 | if (inst.operands[1].isreg |
11461 | && !inst.operands[1].writeback | |
c19d1205 ZW |
11462 | && !inst.operands[1].shifted && !inst.operands[1].postind |
11463 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
11464 | && opcode <= 0xffff |
11465 | && inst.size_req != 4) | |
c19d1205 | 11466 | { |
0110f2b8 PB |
11467 | /* Insn may have a 16-bit form. */ |
11468 | Rn = inst.operands[1].reg; | |
11469 | if (inst.operands[1].immisreg) | |
11470 | { | |
11471 | inst.instruction = THUMB_OP16 (opcode); | |
5f4273c7 | 11472 | /* [Rn, Rik] */ |
0110f2b8 PB |
11473 | if (Rn <= 7 && inst.operands[1].imm <= 7) |
11474 | goto op16; | |
5be8be5d DG |
11475 | else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str) |
11476 | reject_bad_reg (inst.operands[1].imm); | |
0110f2b8 PB |
11477 | } |
11478 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
11479 | && opcode != T_MNEM_ldrsb) | |
11480 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
11481 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
11482 | { | |
11483 | /* [Rn, #const] */ | |
11484 | if (Rn > 7) | |
11485 | { | |
11486 | if (Rn == REG_PC) | |
11487 | { | |
11488 | if (inst.reloc.pc_rel) | |
11489 | opcode = T_MNEM_ldr_pc2; | |
11490 | else | |
11491 | opcode = T_MNEM_ldr_pc; | |
11492 | } | |
11493 | else | |
11494 | { | |
11495 | if (opcode == T_MNEM_ldr) | |
11496 | opcode = T_MNEM_ldr_sp; | |
11497 | else | |
11498 | opcode = T_MNEM_str_sp; | |
11499 | } | |
11500 | inst.instruction = inst.operands[0].reg << 8; | |
11501 | } | |
11502 | else | |
11503 | { | |
11504 | inst.instruction = inst.operands[0].reg; | |
11505 | inst.instruction |= inst.operands[1].reg << 3; | |
11506 | } | |
11507 | inst.instruction |= THUMB_OP16 (opcode); | |
11508 | if (inst.size_req == 2) | |
11509 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
11510 | else | |
11511 | inst.relax = opcode; | |
11512 | return; | |
11513 | } | |
c19d1205 | 11514 | } |
0110f2b8 | 11515 | /* Definitely a 32-bit variant. */ |
5be8be5d | 11516 | |
8d67f500 NC |
11517 | /* Warning for Erratum 752419. */ |
11518 | if (opcode == T_MNEM_ldr | |
11519 | && inst.operands[0].reg == REG_SP | |
11520 | && inst.operands[1].writeback == 1 | |
11521 | && !inst.operands[1].immisreg) | |
11522 | { | |
11523 | if (no_cpu_selected () | |
11524 | || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7) | |
477330fc RM |
11525 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a) |
11526 | && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r))) | |
8d67f500 NC |
11527 | as_warn (_("This instruction may be unpredictable " |
11528 | "if executed on M-profile cores " | |
11529 | "with interrupts enabled.")); | |
11530 | } | |
11531 | ||
5be8be5d | 11532 | /* Do some validations regarding addressing modes. */ |
1be5fd2e | 11533 | if (inst.operands[1].immisreg) |
5be8be5d DG |
11534 | reject_bad_reg (inst.operands[1].imm); |
11535 | ||
1be5fd2e NC |
11536 | constraint (inst.operands[1].writeback == 1 |
11537 | && inst.operands[0].reg == inst.operands[1].reg, | |
11538 | BAD_OVERLAP); | |
11539 | ||
0110f2b8 | 11540 | inst.instruction = THUMB_OP32 (opcode); |
c19d1205 ZW |
11541 | inst.instruction |= inst.operands[0].reg << 12; |
11542 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
1be5fd2e | 11543 | check_ldr_r15_aligned (); |
b99bd4ef NC |
11544 | return; |
11545 | } | |
11546 | ||
c19d1205 ZW |
11547 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
11548 | ||
11549 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 11550 | { |
c19d1205 ZW |
11551 | /* Only [Rn,Rm] is acceptable. */ |
11552 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
11553 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
11554 | || inst.operands[1].postind || inst.operands[1].shifted | |
11555 | || inst.operands[1].negative, | |
11556 | _("Thumb does not support this addressing mode")); | |
11557 | inst.instruction = THUMB_OP16 (inst.instruction); | |
11558 | goto op16; | |
b99bd4ef | 11559 | } |
5f4273c7 | 11560 | |
c19d1205 ZW |
11561 | inst.instruction = THUMB_OP16 (inst.instruction); |
11562 | if (!inst.operands[1].isreg) | |
8335d6aa | 11563 | if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE)) |
c19d1205 | 11564 | return; |
b99bd4ef | 11565 | |
c19d1205 ZW |
11566 | constraint (!inst.operands[1].preind |
11567 | || inst.operands[1].shifted | |
11568 | || inst.operands[1].writeback, | |
11569 | _("Thumb does not support this addressing mode")); | |
11570 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 11571 | { |
c19d1205 ZW |
11572 | constraint (inst.instruction & 0x0600, |
11573 | _("byte or halfword not valid for base register")); | |
11574 | constraint (inst.operands[1].reg == REG_PC | |
11575 | && !(inst.instruction & THUMB_LOAD_BIT), | |
11576 | _("r15 based store not allowed")); | |
11577 | constraint (inst.operands[1].immisreg, | |
11578 | _("invalid base register for register offset")); | |
b99bd4ef | 11579 | |
c19d1205 ZW |
11580 | if (inst.operands[1].reg == REG_PC) |
11581 | inst.instruction = T_OPCODE_LDR_PC; | |
11582 | else if (inst.instruction & THUMB_LOAD_BIT) | |
11583 | inst.instruction = T_OPCODE_LDR_SP; | |
11584 | else | |
11585 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 11586 | |
c19d1205 ZW |
11587 | inst.instruction |= inst.operands[0].reg << 8; |
11588 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
11589 | return; | |
11590 | } | |
90e4755a | 11591 | |
c19d1205 ZW |
11592 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
11593 | if (!inst.operands[1].immisreg) | |
11594 | { | |
11595 | /* Immediate offset. */ | |
11596 | inst.instruction |= inst.operands[0].reg; | |
11597 | inst.instruction |= inst.operands[1].reg << 3; | |
11598 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
11599 | return; | |
11600 | } | |
90e4755a | 11601 | |
c19d1205 ZW |
11602 | /* Register offset. */ |
11603 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
11604 | constraint (inst.operands[1].negative, | |
11605 | _("Thumb does not support this addressing mode")); | |
90e4755a | 11606 | |
c19d1205 ZW |
11607 | op16: |
11608 | switch (inst.instruction) | |
11609 | { | |
11610 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
11611 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
11612 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
11613 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
11614 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
11615 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
11616 | case 0x5600 /* ldrsb */: | |
11617 | case 0x5e00 /* ldrsh */: break; | |
11618 | default: abort (); | |
11619 | } | |
90e4755a | 11620 | |
c19d1205 ZW |
11621 | inst.instruction |= inst.operands[0].reg; |
11622 | inst.instruction |= inst.operands[1].reg << 3; | |
11623 | inst.instruction |= inst.operands[1].imm << 6; | |
11624 | } | |
90e4755a | 11625 | |
c19d1205 ZW |
11626 | static void |
11627 | do_t_ldstd (void) | |
11628 | { | |
11629 | if (!inst.operands[1].present) | |
b99bd4ef | 11630 | { |
c19d1205 ZW |
11631 | inst.operands[1].reg = inst.operands[0].reg + 1; |
11632 | constraint (inst.operands[0].reg == REG_LR, | |
11633 | _("r14 not allowed here")); | |
bd340a04 | 11634 | constraint (inst.operands[0].reg == REG_R12, |
477330fc | 11635 | _("r12 not allowed here")); |
b99bd4ef | 11636 | } |
bd340a04 MGD |
11637 | |
11638 | if (inst.operands[2].writeback | |
11639 | && (inst.operands[0].reg == inst.operands[2].reg | |
11640 | || inst.operands[1].reg == inst.operands[2].reg)) | |
11641 | as_warn (_("base register written back, and overlaps " | |
477330fc | 11642 | "one of transfer registers")); |
bd340a04 | 11643 | |
c19d1205 ZW |
11644 | inst.instruction |= inst.operands[0].reg << 12; |
11645 | inst.instruction |= inst.operands[1].reg << 8; | |
11646 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
b99bd4ef NC |
11647 | } |
11648 | ||
c19d1205 ZW |
11649 | static void |
11650 | do_t_ldstt (void) | |
11651 | { | |
11652 | inst.instruction |= inst.operands[0].reg << 12; | |
11653 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
11654 | } | |
a737bd4d | 11655 | |
b99bd4ef | 11656 | static void |
c19d1205 | 11657 | do_t_mla (void) |
b99bd4ef | 11658 | { |
fdfde340 | 11659 | unsigned Rd, Rn, Rm, Ra; |
c921be7d | 11660 | |
fdfde340 JM |
11661 | Rd = inst.operands[0].reg; |
11662 | Rn = inst.operands[1].reg; | |
11663 | Rm = inst.operands[2].reg; | |
11664 | Ra = inst.operands[3].reg; | |
11665 | ||
11666 | reject_bad_reg (Rd); | |
11667 | reject_bad_reg (Rn); | |
11668 | reject_bad_reg (Rm); | |
11669 | reject_bad_reg (Ra); | |
11670 | ||
11671 | inst.instruction |= Rd << 8; | |
11672 | inst.instruction |= Rn << 16; | |
11673 | inst.instruction |= Rm; | |
11674 | inst.instruction |= Ra << 12; | |
c19d1205 | 11675 | } |
b99bd4ef | 11676 | |
c19d1205 ZW |
11677 | static void |
11678 | do_t_mlal (void) | |
11679 | { | |
fdfde340 JM |
11680 | unsigned RdLo, RdHi, Rn, Rm; |
11681 | ||
11682 | RdLo = inst.operands[0].reg; | |
11683 | RdHi = inst.operands[1].reg; | |
11684 | Rn = inst.operands[2].reg; | |
11685 | Rm = inst.operands[3].reg; | |
11686 | ||
11687 | reject_bad_reg (RdLo); | |
11688 | reject_bad_reg (RdHi); | |
11689 | reject_bad_reg (Rn); | |
11690 | reject_bad_reg (Rm); | |
11691 | ||
11692 | inst.instruction |= RdLo << 12; | |
11693 | inst.instruction |= RdHi << 8; | |
11694 | inst.instruction |= Rn << 16; | |
11695 | inst.instruction |= Rm; | |
c19d1205 | 11696 | } |
b99bd4ef | 11697 | |
c19d1205 ZW |
11698 | static void |
11699 | do_t_mov_cmp (void) | |
11700 | { | |
fdfde340 JM |
11701 | unsigned Rn, Rm; |
11702 | ||
11703 | Rn = inst.operands[0].reg; | |
11704 | Rm = inst.operands[1].reg; | |
11705 | ||
e07e6e58 NC |
11706 | if (Rn == REG_PC) |
11707 | set_it_insn_type_last (); | |
11708 | ||
c19d1205 | 11709 | if (unified_syntax) |
b99bd4ef | 11710 | { |
c19d1205 ZW |
11711 | int r0off = (inst.instruction == T_MNEM_mov |
11712 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 11713 | unsigned long opcode; |
3d388997 PB |
11714 | bfd_boolean narrow; |
11715 | bfd_boolean low_regs; | |
11716 | ||
fdfde340 | 11717 | low_regs = (Rn <= 7 && Rm <= 7); |
0110f2b8 | 11718 | opcode = inst.instruction; |
e07e6e58 | 11719 | if (in_it_block ()) |
0110f2b8 | 11720 | narrow = opcode != T_MNEM_movs; |
3d388997 | 11721 | else |
0110f2b8 | 11722 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
11723 | if (inst.size_req == 4 |
11724 | || inst.operands[1].shifted) | |
11725 | narrow = FALSE; | |
11726 | ||
efd81785 PB |
11727 | /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */ |
11728 | if (opcode == T_MNEM_movs && inst.operands[1].isreg | |
11729 | && !inst.operands[1].shifted | |
fdfde340 JM |
11730 | && Rn == REG_PC |
11731 | && Rm == REG_LR) | |
efd81785 PB |
11732 | { |
11733 | inst.instruction = T2_SUBS_PC_LR; | |
11734 | return; | |
11735 | } | |
11736 | ||
fdfde340 JM |
11737 | if (opcode == T_MNEM_cmp) |
11738 | { | |
11739 | constraint (Rn == REG_PC, BAD_PC); | |
94206790 MM |
11740 | if (narrow) |
11741 | { | |
11742 | /* In the Thumb-2 ISA, use of R13 as Rm is deprecated, | |
11743 | but valid. */ | |
11744 | warn_deprecated_sp (Rm); | |
11745 | /* R15 was documented as a valid choice for Rm in ARMv6, | |
11746 | but as UNPREDICTABLE in ARMv7. ARM's proprietary | |
11747 | tools reject R15, so we do too. */ | |
11748 | constraint (Rm == REG_PC, BAD_PC); | |
11749 | } | |
11750 | else | |
11751 | reject_bad_reg (Rm); | |
fdfde340 JM |
11752 | } |
11753 | else if (opcode == T_MNEM_mov | |
11754 | || opcode == T_MNEM_movs) | |
11755 | { | |
11756 | if (inst.operands[1].isreg) | |
11757 | { | |
11758 | if (opcode == T_MNEM_movs) | |
11759 | { | |
11760 | reject_bad_reg (Rn); | |
11761 | reject_bad_reg (Rm); | |
11762 | } | |
76fa04a4 MGD |
11763 | else if (narrow) |
11764 | { | |
11765 | /* This is mov.n. */ | |
11766 | if ((Rn == REG_SP || Rn == REG_PC) | |
11767 | && (Rm == REG_SP || Rm == REG_PC)) | |
11768 | { | |
5c3696f8 | 11769 | as_tsktsk (_("Use of r%u as a source register is " |
76fa04a4 MGD |
11770 | "deprecated when r%u is the destination " |
11771 | "register."), Rm, Rn); | |
11772 | } | |
11773 | } | |
11774 | else | |
11775 | { | |
11776 | /* This is mov.w. */ | |
11777 | constraint (Rn == REG_PC, BAD_PC); | |
11778 | constraint (Rm == REG_PC, BAD_PC); | |
11779 | constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP); | |
11780 | } | |
fdfde340 JM |
11781 | } |
11782 | else | |
11783 | reject_bad_reg (Rn); | |
11784 | } | |
11785 | ||
c19d1205 ZW |
11786 | if (!inst.operands[1].isreg) |
11787 | { | |
0110f2b8 | 11788 | /* Immediate operand. */ |
e07e6e58 | 11789 | if (!in_it_block () && opcode == T_MNEM_mov) |
0110f2b8 PB |
11790 | narrow = 0; |
11791 | if (low_regs && narrow) | |
11792 | { | |
11793 | inst.instruction = THUMB_OP16 (opcode); | |
fdfde340 | 11794 | inst.instruction |= Rn << 8; |
0110f2b8 | 11795 | if (inst.size_req == 2) |
72d98d16 MG |
11796 | { |
11797 | if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC | |
11798 | || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
11799 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
11800 | } | |
0110f2b8 | 11801 | else |
72d98d16 | 11802 | inst.relax = opcode; |
0110f2b8 PB |
11803 | } |
11804 | else | |
11805 | { | |
11806 | inst.instruction = THUMB_OP32 (inst.instruction); | |
11807 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 11808 | inst.instruction |= Rn << r0off; |
0110f2b8 PB |
11809 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
11810 | } | |
c19d1205 | 11811 | } |
728ca7c9 PB |
11812 | else if (inst.operands[1].shifted && inst.operands[1].immisreg |
11813 | && (inst.instruction == T_MNEM_mov | |
11814 | || inst.instruction == T_MNEM_movs)) | |
11815 | { | |
11816 | /* Register shifts are encoded as separate shift instructions. */ | |
11817 | bfd_boolean flags = (inst.instruction == T_MNEM_movs); | |
11818 | ||
e07e6e58 | 11819 | if (in_it_block ()) |
728ca7c9 PB |
11820 | narrow = !flags; |
11821 | else | |
11822 | narrow = flags; | |
11823 | ||
11824 | if (inst.size_req == 4) | |
11825 | narrow = FALSE; | |
11826 | ||
11827 | if (!low_regs || inst.operands[1].imm > 7) | |
11828 | narrow = FALSE; | |
11829 | ||
fdfde340 | 11830 | if (Rn != Rm) |
728ca7c9 PB |
11831 | narrow = FALSE; |
11832 | ||
11833 | switch (inst.operands[1].shift_kind) | |
11834 | { | |
11835 | case SHIFT_LSL: | |
11836 | opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl); | |
11837 | break; | |
11838 | case SHIFT_ASR: | |
11839 | opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr); | |
11840 | break; | |
11841 | case SHIFT_LSR: | |
11842 | opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr); | |
11843 | break; | |
11844 | case SHIFT_ROR: | |
11845 | opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror); | |
11846 | break; | |
11847 | default: | |
5f4273c7 | 11848 | abort (); |
728ca7c9 PB |
11849 | } |
11850 | ||
11851 | inst.instruction = opcode; | |
11852 | if (narrow) | |
11853 | { | |
fdfde340 | 11854 | inst.instruction |= Rn; |
728ca7c9 PB |
11855 | inst.instruction |= inst.operands[1].imm << 3; |
11856 | } | |
11857 | else | |
11858 | { | |
11859 | if (flags) | |
11860 | inst.instruction |= CONDS_BIT; | |
11861 | ||
fdfde340 JM |
11862 | inst.instruction |= Rn << 8; |
11863 | inst.instruction |= Rm << 16; | |
728ca7c9 PB |
11864 | inst.instruction |= inst.operands[1].imm; |
11865 | } | |
11866 | } | |
3d388997 | 11867 | else if (!narrow) |
c19d1205 | 11868 | { |
728ca7c9 PB |
11869 | /* Some mov with immediate shift have narrow variants. |
11870 | Register shifts are handled above. */ | |
11871 | if (low_regs && inst.operands[1].shifted | |
11872 | && (inst.instruction == T_MNEM_mov | |
11873 | || inst.instruction == T_MNEM_movs)) | |
11874 | { | |
e07e6e58 | 11875 | if (in_it_block ()) |
728ca7c9 PB |
11876 | narrow = (inst.instruction == T_MNEM_mov); |
11877 | else | |
11878 | narrow = (inst.instruction == T_MNEM_movs); | |
11879 | } | |
11880 | ||
11881 | if (narrow) | |
11882 | { | |
11883 | switch (inst.operands[1].shift_kind) | |
11884 | { | |
11885 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
11886 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
11887 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; | |
11888 | default: narrow = FALSE; break; | |
11889 | } | |
11890 | } | |
11891 | ||
11892 | if (narrow) | |
11893 | { | |
fdfde340 JM |
11894 | inst.instruction |= Rn; |
11895 | inst.instruction |= Rm << 3; | |
728ca7c9 PB |
11896 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
11897 | } | |
11898 | else | |
11899 | { | |
11900 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 11901 | inst.instruction |= Rn << r0off; |
728ca7c9 PB |
11902 | encode_thumb32_shifted_operand (1); |
11903 | } | |
c19d1205 ZW |
11904 | } |
11905 | else | |
11906 | switch (inst.instruction) | |
11907 | { | |
11908 | case T_MNEM_mov: | |
837b3435 | 11909 | /* In v4t or v5t a move of two lowregs produces unpredictable |
c6400f8a MGD |
11910 | results. Don't allow this. */ |
11911 | if (low_regs) | |
11912 | { | |
11913 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6), | |
11914 | "MOV Rd, Rs with two low registers is not " | |
11915 | "permitted on this architecture"); | |
fa94de6b | 11916 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
c6400f8a MGD |
11917 | arm_ext_v6); |
11918 | } | |
11919 | ||
c19d1205 | 11920 | inst.instruction = T_OPCODE_MOV_HR; |
fdfde340 JM |
11921 | inst.instruction |= (Rn & 0x8) << 4; |
11922 | inst.instruction |= (Rn & 0x7); | |
11923 | inst.instruction |= Rm << 3; | |
c19d1205 | 11924 | break; |
b99bd4ef | 11925 | |
c19d1205 ZW |
11926 | case T_MNEM_movs: |
11927 | /* We know we have low registers at this point. | |
941a8a52 MGD |
11928 | Generate LSLS Rd, Rs, #0. */ |
11929 | inst.instruction = T_OPCODE_LSL_I; | |
fdfde340 JM |
11930 | inst.instruction |= Rn; |
11931 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11932 | break; |
11933 | ||
11934 | case T_MNEM_cmp: | |
3d388997 | 11935 | if (low_regs) |
c19d1205 ZW |
11936 | { |
11937 | inst.instruction = T_OPCODE_CMP_LR; | |
fdfde340 JM |
11938 | inst.instruction |= Rn; |
11939 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11940 | } |
11941 | else | |
11942 | { | |
11943 | inst.instruction = T_OPCODE_CMP_HR; | |
fdfde340 JM |
11944 | inst.instruction |= (Rn & 0x8) << 4; |
11945 | inst.instruction |= (Rn & 0x7); | |
11946 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
11947 | } |
11948 | break; | |
11949 | } | |
b99bd4ef NC |
11950 | return; |
11951 | } | |
11952 | ||
c19d1205 | 11953 | inst.instruction = THUMB_OP16 (inst.instruction); |
539d4391 NC |
11954 | |
11955 | /* PR 10443: Do not silently ignore shifted operands. */ | |
11956 | constraint (inst.operands[1].shifted, | |
11957 | _("shifts in CMP/MOV instructions are only supported in unified syntax")); | |
11958 | ||
c19d1205 | 11959 | if (inst.operands[1].isreg) |
b99bd4ef | 11960 | { |
fdfde340 | 11961 | if (Rn < 8 && Rm < 8) |
b99bd4ef | 11962 | { |
c19d1205 ZW |
11963 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
11964 | since a MOV instruction produces unpredictable results. */ | |
11965 | if (inst.instruction == T_OPCODE_MOV_I8) | |
11966 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 11967 | else |
c19d1205 | 11968 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 11969 | |
fdfde340 JM |
11970 | inst.instruction |= Rn; |
11971 | inst.instruction |= Rm << 3; | |
b99bd4ef NC |
11972 | } |
11973 | else | |
11974 | { | |
c19d1205 ZW |
11975 | if (inst.instruction == T_OPCODE_MOV_I8) |
11976 | inst.instruction = T_OPCODE_MOV_HR; | |
11977 | else | |
11978 | inst.instruction = T_OPCODE_CMP_HR; | |
11979 | do_t_cpy (); | |
b99bd4ef NC |
11980 | } |
11981 | } | |
c19d1205 | 11982 | else |
b99bd4ef | 11983 | { |
fdfde340 | 11984 | constraint (Rn > 7, |
c19d1205 | 11985 | _("only lo regs allowed with immediate")); |
fdfde340 | 11986 | inst.instruction |= Rn << 8; |
c19d1205 ZW |
11987 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; |
11988 | } | |
11989 | } | |
b99bd4ef | 11990 | |
c19d1205 ZW |
11991 | static void |
11992 | do_t_mov16 (void) | |
11993 | { | |
fdfde340 | 11994 | unsigned Rd; |
b6895b4f PB |
11995 | bfd_vma imm; |
11996 | bfd_boolean top; | |
11997 | ||
11998 | top = (inst.instruction & 0x00800000) != 0; | |
11999 | if (inst.reloc.type == BFD_RELOC_ARM_MOVW) | |
12000 | { | |
12001 | constraint (top, _(":lower16: not allowed this instruction")); | |
12002 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW; | |
12003 | } | |
12004 | else if (inst.reloc.type == BFD_RELOC_ARM_MOVT) | |
12005 | { | |
12006 | constraint (!top, _(":upper16: not allowed this instruction")); | |
12007 | inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT; | |
12008 | } | |
12009 | ||
fdfde340 JM |
12010 | Rd = inst.operands[0].reg; |
12011 | reject_bad_reg (Rd); | |
12012 | ||
12013 | inst.instruction |= Rd << 8; | |
b6895b4f PB |
12014 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
12015 | { | |
12016 | imm = inst.reloc.exp.X_add_number; | |
12017 | inst.instruction |= (imm & 0xf000) << 4; | |
12018 | inst.instruction |= (imm & 0x0800) << 15; | |
12019 | inst.instruction |= (imm & 0x0700) << 4; | |
12020 | inst.instruction |= (imm & 0x00ff); | |
12021 | } | |
c19d1205 | 12022 | } |
b99bd4ef | 12023 | |
c19d1205 ZW |
12024 | static void |
12025 | do_t_mvn_tst (void) | |
12026 | { | |
fdfde340 | 12027 | unsigned Rn, Rm; |
c921be7d | 12028 | |
fdfde340 JM |
12029 | Rn = inst.operands[0].reg; |
12030 | Rm = inst.operands[1].reg; | |
12031 | ||
12032 | if (inst.instruction == T_MNEM_cmp | |
12033 | || inst.instruction == T_MNEM_cmn) | |
12034 | constraint (Rn == REG_PC, BAD_PC); | |
12035 | else | |
12036 | reject_bad_reg (Rn); | |
12037 | reject_bad_reg (Rm); | |
12038 | ||
c19d1205 ZW |
12039 | if (unified_syntax) |
12040 | { | |
12041 | int r0off = (inst.instruction == T_MNEM_mvn | |
12042 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
12043 | bfd_boolean narrow; |
12044 | ||
12045 | if (inst.size_req == 4 | |
12046 | || inst.instruction > 0xffff | |
12047 | || inst.operands[1].shifted | |
fdfde340 | 12048 | || Rn > 7 || Rm > 7) |
3d388997 | 12049 | narrow = FALSE; |
fe8b4cc3 KT |
12050 | else if (inst.instruction == T_MNEM_cmn |
12051 | || inst.instruction == T_MNEM_tst) | |
3d388997 PB |
12052 | narrow = TRUE; |
12053 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12054 | narrow = !in_it_block (); |
3d388997 | 12055 | else |
e07e6e58 | 12056 | narrow = in_it_block (); |
3d388997 | 12057 | |
c19d1205 | 12058 | if (!inst.operands[1].isreg) |
b99bd4ef | 12059 | { |
c19d1205 ZW |
12060 | /* For an immediate, we always generate a 32-bit opcode; |
12061 | section relaxation will shrink it later if possible. */ | |
12062 | if (inst.instruction < 0xffff) | |
12063 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12064 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
fdfde340 | 12065 | inst.instruction |= Rn << r0off; |
c19d1205 | 12066 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; |
b99bd4ef | 12067 | } |
c19d1205 | 12068 | else |
b99bd4ef | 12069 | { |
c19d1205 | 12070 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 12071 | if (narrow) |
b99bd4ef | 12072 | { |
c19d1205 | 12073 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12074 | inst.instruction |= Rn; |
12075 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12076 | } |
c19d1205 | 12077 | else |
b99bd4ef | 12078 | { |
c19d1205 ZW |
12079 | constraint (inst.operands[1].shifted |
12080 | && inst.operands[1].immisreg, | |
12081 | _("shift must be constant")); | |
12082 | if (inst.instruction < 0xffff) | |
12083 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 | 12084 | inst.instruction |= Rn << r0off; |
c19d1205 | 12085 | encode_thumb32_shifted_operand (1); |
b99bd4ef | 12086 | } |
b99bd4ef NC |
12087 | } |
12088 | } | |
12089 | else | |
12090 | { | |
c19d1205 ZW |
12091 | constraint (inst.instruction > 0xffff |
12092 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
12093 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
12094 | _("unshifted register required")); | |
fdfde340 | 12095 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12096 | BAD_HIREG); |
b99bd4ef | 12097 | |
c19d1205 | 12098 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12099 | inst.instruction |= Rn; |
12100 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12101 | } |
b99bd4ef NC |
12102 | } |
12103 | ||
b05fe5cf | 12104 | static void |
c19d1205 | 12105 | do_t_mrs (void) |
b05fe5cf | 12106 | { |
fdfde340 | 12107 | unsigned Rd; |
037e8744 JB |
12108 | |
12109 | if (do_vfp_nsyn_mrs () == SUCCESS) | |
12110 | return; | |
12111 | ||
90ec0d68 MGD |
12112 | Rd = inst.operands[0].reg; |
12113 | reject_bad_reg (Rd); | |
12114 | inst.instruction |= Rd << 8; | |
12115 | ||
12116 | if (inst.operands[1].isreg) | |
62b3e311 | 12117 | { |
90ec0d68 MGD |
12118 | unsigned br = inst.operands[1].reg; |
12119 | if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000)) | |
12120 | as_bad (_("bad register for mrs")); | |
12121 | ||
12122 | inst.instruction |= br & (0xf << 16); | |
12123 | inst.instruction |= (br & 0x300) >> 4; | |
12124 | inst.instruction |= (br & SPSR_BIT) >> 2; | |
62b3e311 PB |
12125 | } |
12126 | else | |
12127 | { | |
90ec0d68 | 12128 | int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
5f4273c7 | 12129 | |
d2cd1205 | 12130 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
1a43faaf NC |
12131 | { |
12132 | /* PR gas/12698: The constraint is only applied for m_profile. | |
12133 | If the user has specified -march=all, we want to ignore it as | |
12134 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12135 | bfd_boolean m_profile = |
12136 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf NC |
12137 | constraint ((flags != 0) && m_profile, _("selected processor does " |
12138 | "not support requested special purpose register")); | |
12139 | } | |
90ec0d68 | 12140 | else |
d2cd1205 JB |
12141 | /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile |
12142 | devices). */ | |
12143 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
12144 | _("'APSR', 'CPSR' or 'SPSR' expected")); | |
fdfde340 | 12145 | |
90ec0d68 MGD |
12146 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
12147 | inst.instruction |= inst.operands[1].imm & 0xff; | |
12148 | inst.instruction |= 0xf0000; | |
12149 | } | |
c19d1205 | 12150 | } |
b05fe5cf | 12151 | |
c19d1205 ZW |
12152 | static void |
12153 | do_t_msr (void) | |
12154 | { | |
62b3e311 | 12155 | int flags; |
fdfde340 | 12156 | unsigned Rn; |
62b3e311 | 12157 | |
037e8744 JB |
12158 | if (do_vfp_nsyn_msr () == SUCCESS) |
12159 | return; | |
12160 | ||
c19d1205 ZW |
12161 | constraint (!inst.operands[1].isreg, |
12162 | _("Thumb encoding does not support an immediate here")); | |
90ec0d68 MGD |
12163 | |
12164 | if (inst.operands[0].isreg) | |
12165 | flags = (int)(inst.operands[0].reg); | |
12166 | else | |
12167 | flags = inst.operands[0].imm; | |
12168 | ||
d2cd1205 | 12169 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m)) |
62b3e311 | 12170 | { |
d2cd1205 JB |
12171 | int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); |
12172 | ||
1a43faaf | 12173 | /* PR gas/12698: The constraint is only applied for m_profile. |
477330fc RM |
12174 | If the user has specified -march=all, we want to ignore it as |
12175 | we are building for any CPU type, including non-m variants. */ | |
823d2571 TG |
12176 | bfd_boolean m_profile = |
12177 | !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any); | |
1a43faaf | 12178 | constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) |
477330fc RM |
12179 | && (bits & ~(PSR_s | PSR_f)) != 0) |
12180 | || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp) | |
12181 | && bits != PSR_f)) && m_profile, | |
12182 | _("selected processor does not support requested special " | |
12183 | "purpose register")); | |
62b3e311 PB |
12184 | } |
12185 | else | |
d2cd1205 JB |
12186 | constraint ((flags & 0xff) != 0, _("selected processor does not support " |
12187 | "requested special purpose register")); | |
c921be7d | 12188 | |
fdfde340 JM |
12189 | Rn = inst.operands[1].reg; |
12190 | reject_bad_reg (Rn); | |
12191 | ||
62b3e311 | 12192 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
90ec0d68 MGD |
12193 | inst.instruction |= (flags & 0xf0000) >> 8; |
12194 | inst.instruction |= (flags & 0x300) >> 4; | |
62b3e311 | 12195 | inst.instruction |= (flags & 0xff); |
fdfde340 | 12196 | inst.instruction |= Rn << 16; |
c19d1205 | 12197 | } |
b05fe5cf | 12198 | |
c19d1205 ZW |
12199 | static void |
12200 | do_t_mul (void) | |
12201 | { | |
17828f45 | 12202 | bfd_boolean narrow; |
fdfde340 | 12203 | unsigned Rd, Rn, Rm; |
17828f45 | 12204 | |
c19d1205 ZW |
12205 | if (!inst.operands[2].present) |
12206 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 12207 | |
fdfde340 JM |
12208 | Rd = inst.operands[0].reg; |
12209 | Rn = inst.operands[1].reg; | |
12210 | Rm = inst.operands[2].reg; | |
12211 | ||
17828f45 | 12212 | if (unified_syntax) |
b05fe5cf | 12213 | { |
17828f45 | 12214 | if (inst.size_req == 4 |
fdfde340 JM |
12215 | || (Rd != Rn |
12216 | && Rd != Rm) | |
12217 | || Rn > 7 | |
12218 | || Rm > 7) | |
17828f45 JM |
12219 | narrow = FALSE; |
12220 | else if (inst.instruction == T_MNEM_muls) | |
e07e6e58 | 12221 | narrow = !in_it_block (); |
17828f45 | 12222 | else |
e07e6e58 | 12223 | narrow = in_it_block (); |
b05fe5cf | 12224 | } |
c19d1205 | 12225 | else |
b05fe5cf | 12226 | { |
17828f45 | 12227 | constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32); |
fdfde340 | 12228 | constraint (Rn > 7 || Rm > 7, |
c19d1205 | 12229 | BAD_HIREG); |
17828f45 JM |
12230 | narrow = TRUE; |
12231 | } | |
b05fe5cf | 12232 | |
17828f45 JM |
12233 | if (narrow) |
12234 | { | |
12235 | /* 16-bit MULS/Conditional MUL. */ | |
c19d1205 | 12236 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 | 12237 | inst.instruction |= Rd; |
b05fe5cf | 12238 | |
fdfde340 JM |
12239 | if (Rd == Rn) |
12240 | inst.instruction |= Rm << 3; | |
12241 | else if (Rd == Rm) | |
12242 | inst.instruction |= Rn << 3; | |
c19d1205 ZW |
12243 | else |
12244 | constraint (1, _("dest must overlap one source register")); | |
12245 | } | |
17828f45 JM |
12246 | else |
12247 | { | |
e07e6e58 NC |
12248 | constraint (inst.instruction != T_MNEM_mul, |
12249 | _("Thumb-2 MUL must not set flags")); | |
17828f45 JM |
12250 | /* 32-bit MUL. */ |
12251 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12252 | inst.instruction |= Rd << 8; |
12253 | inst.instruction |= Rn << 16; | |
12254 | inst.instruction |= Rm << 0; | |
12255 | ||
12256 | reject_bad_reg (Rd); | |
12257 | reject_bad_reg (Rn); | |
12258 | reject_bad_reg (Rm); | |
17828f45 | 12259 | } |
c19d1205 | 12260 | } |
b05fe5cf | 12261 | |
c19d1205 ZW |
12262 | static void |
12263 | do_t_mull (void) | |
12264 | { | |
fdfde340 | 12265 | unsigned RdLo, RdHi, Rn, Rm; |
b05fe5cf | 12266 | |
fdfde340 JM |
12267 | RdLo = inst.operands[0].reg; |
12268 | RdHi = inst.operands[1].reg; | |
12269 | Rn = inst.operands[2].reg; | |
12270 | Rm = inst.operands[3].reg; | |
12271 | ||
12272 | reject_bad_reg (RdLo); | |
12273 | reject_bad_reg (RdHi); | |
12274 | reject_bad_reg (Rn); | |
12275 | reject_bad_reg (Rm); | |
12276 | ||
12277 | inst.instruction |= RdLo << 12; | |
12278 | inst.instruction |= RdHi << 8; | |
12279 | inst.instruction |= Rn << 16; | |
12280 | inst.instruction |= Rm; | |
12281 | ||
12282 | if (RdLo == RdHi) | |
c19d1205 ZW |
12283 | as_tsktsk (_("rdhi and rdlo must be different")); |
12284 | } | |
b05fe5cf | 12285 | |
c19d1205 ZW |
12286 | static void |
12287 | do_t_nop (void) | |
12288 | { | |
e07e6e58 NC |
12289 | set_it_insn_type (NEUTRAL_IT_INSN); |
12290 | ||
c19d1205 ZW |
12291 | if (unified_syntax) |
12292 | { | |
12293 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 12294 | { |
c19d1205 ZW |
12295 | inst.instruction = THUMB_OP32 (inst.instruction); |
12296 | inst.instruction |= inst.operands[0].imm; | |
12297 | } | |
12298 | else | |
12299 | { | |
bc2d1808 NC |
12300 | /* PR9722: Check for Thumb2 availability before |
12301 | generating a thumb2 nop instruction. */ | |
afa62d5e | 12302 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)) |
bc2d1808 NC |
12303 | { |
12304 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12305 | inst.instruction |= inst.operands[0].imm << 4; | |
12306 | } | |
12307 | else | |
12308 | inst.instruction = 0x46c0; | |
c19d1205 ZW |
12309 | } |
12310 | } | |
12311 | else | |
12312 | { | |
12313 | constraint (inst.operands[0].present, | |
12314 | _("Thumb does not support NOP with hints")); | |
12315 | inst.instruction = 0x46c0; | |
12316 | } | |
12317 | } | |
b05fe5cf | 12318 | |
c19d1205 ZW |
12319 | static void |
12320 | do_t_neg (void) | |
12321 | { | |
12322 | if (unified_syntax) | |
12323 | { | |
3d388997 PB |
12324 | bfd_boolean narrow; |
12325 | ||
12326 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12327 | narrow = !in_it_block (); |
3d388997 | 12328 | else |
e07e6e58 | 12329 | narrow = in_it_block (); |
3d388997 PB |
12330 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12331 | narrow = FALSE; | |
12332 | if (inst.size_req == 4) | |
12333 | narrow = FALSE; | |
12334 | ||
12335 | if (!narrow) | |
c19d1205 ZW |
12336 | { |
12337 | inst.instruction = THUMB_OP32 (inst.instruction); | |
12338 | inst.instruction |= inst.operands[0].reg << 8; | |
12339 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
12340 | } |
12341 | else | |
12342 | { | |
c19d1205 ZW |
12343 | inst.instruction = THUMB_OP16 (inst.instruction); |
12344 | inst.instruction |= inst.operands[0].reg; | |
12345 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
12346 | } |
12347 | } | |
12348 | else | |
12349 | { | |
c19d1205 ZW |
12350 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
12351 | BAD_HIREG); | |
12352 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
12353 | ||
12354 | inst.instruction = THUMB_OP16 (inst.instruction); | |
12355 | inst.instruction |= inst.operands[0].reg; | |
12356 | inst.instruction |= inst.operands[1].reg << 3; | |
12357 | } | |
12358 | } | |
12359 | ||
1c444d06 JM |
12360 | static void |
12361 | do_t_orn (void) | |
12362 | { | |
12363 | unsigned Rd, Rn; | |
12364 | ||
12365 | Rd = inst.operands[0].reg; | |
12366 | Rn = inst.operands[1].present ? inst.operands[1].reg : Rd; | |
12367 | ||
fdfde340 JM |
12368 | reject_bad_reg (Rd); |
12369 | /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */ | |
12370 | reject_bad_reg (Rn); | |
12371 | ||
1c444d06 JM |
12372 | inst.instruction |= Rd << 8; |
12373 | inst.instruction |= Rn << 16; | |
12374 | ||
12375 | if (!inst.operands[2].isreg) | |
12376 | { | |
12377 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
12378 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
12379 | } | |
12380 | else | |
12381 | { | |
12382 | unsigned Rm; | |
12383 | ||
12384 | Rm = inst.operands[2].reg; | |
fdfde340 | 12385 | reject_bad_reg (Rm); |
1c444d06 JM |
12386 | |
12387 | constraint (inst.operands[2].shifted | |
12388 | && inst.operands[2].immisreg, | |
12389 | _("shift must be constant")); | |
12390 | encode_thumb32_shifted_operand (2); | |
12391 | } | |
12392 | } | |
12393 | ||
c19d1205 ZW |
12394 | static void |
12395 | do_t_pkhbt (void) | |
12396 | { | |
fdfde340 JM |
12397 | unsigned Rd, Rn, Rm; |
12398 | ||
12399 | Rd = inst.operands[0].reg; | |
12400 | Rn = inst.operands[1].reg; | |
12401 | Rm = inst.operands[2].reg; | |
12402 | ||
12403 | reject_bad_reg (Rd); | |
12404 | reject_bad_reg (Rn); | |
12405 | reject_bad_reg (Rm); | |
12406 | ||
12407 | inst.instruction |= Rd << 8; | |
12408 | inst.instruction |= Rn << 16; | |
12409 | inst.instruction |= Rm; | |
c19d1205 ZW |
12410 | if (inst.operands[3].present) |
12411 | { | |
12412 | unsigned int val = inst.reloc.exp.X_add_number; | |
12413 | constraint (inst.reloc.exp.X_op != O_constant, | |
12414 | _("expression too complex")); | |
12415 | inst.instruction |= (val & 0x1c) << 10; | |
12416 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 12417 | } |
c19d1205 | 12418 | } |
b05fe5cf | 12419 | |
c19d1205 ZW |
12420 | static void |
12421 | do_t_pkhtb (void) | |
12422 | { | |
12423 | if (!inst.operands[3].present) | |
1ef52f49 NC |
12424 | { |
12425 | unsigned Rtmp; | |
12426 | ||
12427 | inst.instruction &= ~0x00000020; | |
12428 | ||
12429 | /* PR 10168. Swap the Rm and Rn registers. */ | |
12430 | Rtmp = inst.operands[1].reg; | |
12431 | inst.operands[1].reg = inst.operands[2].reg; | |
12432 | inst.operands[2].reg = Rtmp; | |
12433 | } | |
c19d1205 | 12434 | do_t_pkhbt (); |
b05fe5cf ZW |
12435 | } |
12436 | ||
c19d1205 ZW |
12437 | static void |
12438 | do_t_pld (void) | |
12439 | { | |
fdfde340 JM |
12440 | if (inst.operands[0].immisreg) |
12441 | reject_bad_reg (inst.operands[0].imm); | |
12442 | ||
c19d1205 ZW |
12443 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); |
12444 | } | |
b05fe5cf | 12445 | |
c19d1205 ZW |
12446 | static void |
12447 | do_t_push_pop (void) | |
b99bd4ef | 12448 | { |
e9f89963 | 12449 | unsigned mask; |
5f4273c7 | 12450 | |
c19d1205 ZW |
12451 | constraint (inst.operands[0].writeback, |
12452 | _("push/pop do not support {reglist}^")); | |
12453 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
12454 | _("expression too complex")); | |
b99bd4ef | 12455 | |
e9f89963 | 12456 | mask = inst.operands[0].imm; |
d3bfe16e | 12457 | if (inst.size_req != 4 && (mask & ~0xff) == 0) |
3c707909 | 12458 | inst.instruction = THUMB_OP16 (inst.instruction) | mask; |
d3bfe16e JB |
12459 | else if (inst.size_req != 4 |
12460 | && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push | |
12461 | ? REG_LR : REG_PC))) | |
b99bd4ef | 12462 | { |
c19d1205 ZW |
12463 | inst.instruction = THUMB_OP16 (inst.instruction); |
12464 | inst.instruction |= THUMB_PP_PC_LR; | |
3c707909 | 12465 | inst.instruction |= mask & 0xff; |
c19d1205 ZW |
12466 | } |
12467 | else if (unified_syntax) | |
12468 | { | |
3c707909 | 12469 | inst.instruction = THUMB_OP32 (inst.instruction); |
5f4273c7 | 12470 | encode_thumb2_ldmstm (13, mask, TRUE); |
c19d1205 ZW |
12471 | } |
12472 | else | |
12473 | { | |
12474 | inst.error = _("invalid register list to push/pop instruction"); | |
12475 | return; | |
12476 | } | |
c19d1205 | 12477 | } |
b99bd4ef | 12478 | |
c19d1205 ZW |
12479 | static void |
12480 | do_t_rbit (void) | |
12481 | { | |
fdfde340 JM |
12482 | unsigned Rd, Rm; |
12483 | ||
12484 | Rd = inst.operands[0].reg; | |
12485 | Rm = inst.operands[1].reg; | |
12486 | ||
12487 | reject_bad_reg (Rd); | |
12488 | reject_bad_reg (Rm); | |
12489 | ||
12490 | inst.instruction |= Rd << 8; | |
12491 | inst.instruction |= Rm << 16; | |
12492 | inst.instruction |= Rm; | |
c19d1205 | 12493 | } |
b99bd4ef | 12494 | |
c19d1205 ZW |
12495 | static void |
12496 | do_t_rev (void) | |
12497 | { | |
fdfde340 JM |
12498 | unsigned Rd, Rm; |
12499 | ||
12500 | Rd = inst.operands[0].reg; | |
12501 | Rm = inst.operands[1].reg; | |
12502 | ||
12503 | reject_bad_reg (Rd); | |
12504 | reject_bad_reg (Rm); | |
12505 | ||
12506 | if (Rd <= 7 && Rm <= 7 | |
c19d1205 ZW |
12507 | && inst.size_req != 4) |
12508 | { | |
12509 | inst.instruction = THUMB_OP16 (inst.instruction); | |
fdfde340 JM |
12510 | inst.instruction |= Rd; |
12511 | inst.instruction |= Rm << 3; | |
c19d1205 ZW |
12512 | } |
12513 | else if (unified_syntax) | |
12514 | { | |
12515 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12516 | inst.instruction |= Rd << 8; |
12517 | inst.instruction |= Rm << 16; | |
12518 | inst.instruction |= Rm; | |
c19d1205 ZW |
12519 | } |
12520 | else | |
12521 | inst.error = BAD_HIREG; | |
12522 | } | |
b99bd4ef | 12523 | |
1c444d06 JM |
12524 | static void |
12525 | do_t_rrx (void) | |
12526 | { | |
12527 | unsigned Rd, Rm; | |
12528 | ||
12529 | Rd = inst.operands[0].reg; | |
12530 | Rm = inst.operands[1].reg; | |
12531 | ||
fdfde340 JM |
12532 | reject_bad_reg (Rd); |
12533 | reject_bad_reg (Rm); | |
c921be7d | 12534 | |
1c444d06 JM |
12535 | inst.instruction |= Rd << 8; |
12536 | inst.instruction |= Rm; | |
12537 | } | |
12538 | ||
c19d1205 ZW |
12539 | static void |
12540 | do_t_rsb (void) | |
12541 | { | |
fdfde340 | 12542 | unsigned Rd, Rs; |
b99bd4ef | 12543 | |
c19d1205 ZW |
12544 | Rd = inst.operands[0].reg; |
12545 | Rs = (inst.operands[1].present | |
12546 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
12547 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 12548 | |
fdfde340 JM |
12549 | reject_bad_reg (Rd); |
12550 | reject_bad_reg (Rs); | |
12551 | if (inst.operands[2].isreg) | |
12552 | reject_bad_reg (inst.operands[2].reg); | |
12553 | ||
c19d1205 ZW |
12554 | inst.instruction |= Rd << 8; |
12555 | inst.instruction |= Rs << 16; | |
12556 | if (!inst.operands[2].isreg) | |
12557 | { | |
026d3abb PB |
12558 | bfd_boolean narrow; |
12559 | ||
12560 | if ((inst.instruction & 0x00100000) != 0) | |
e07e6e58 | 12561 | narrow = !in_it_block (); |
026d3abb | 12562 | else |
e07e6e58 | 12563 | narrow = in_it_block (); |
026d3abb PB |
12564 | |
12565 | if (Rd > 7 || Rs > 7) | |
12566 | narrow = FALSE; | |
12567 | ||
12568 | if (inst.size_req == 4 || !unified_syntax) | |
12569 | narrow = FALSE; | |
12570 | ||
12571 | if (inst.reloc.exp.X_op != O_constant | |
12572 | || inst.reloc.exp.X_add_number != 0) | |
12573 | narrow = FALSE; | |
12574 | ||
12575 | /* Turn rsb #0 into 16-bit neg. We should probably do this via | |
477330fc | 12576 | relaxation, but it doesn't seem worth the hassle. */ |
026d3abb PB |
12577 | if (narrow) |
12578 | { | |
12579 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12580 | inst.instruction = THUMB_OP16 (T_MNEM_negs); | |
12581 | inst.instruction |= Rs << 3; | |
12582 | inst.instruction |= Rd; | |
12583 | } | |
12584 | else | |
12585 | { | |
12586 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
12587 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
12588 | } | |
c19d1205 ZW |
12589 | } |
12590 | else | |
12591 | encode_thumb32_shifted_operand (2); | |
12592 | } | |
b99bd4ef | 12593 | |
c19d1205 ZW |
12594 | static void |
12595 | do_t_setend (void) | |
12596 | { | |
12e37cbc MGD |
12597 | if (warn_on_deprecated |
12598 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
5c3696f8 | 12599 | as_tsktsk (_("setend use is deprecated for ARMv8")); |
12e37cbc | 12600 | |
e07e6e58 | 12601 | set_it_insn_type (OUTSIDE_IT_INSN); |
c19d1205 ZW |
12602 | if (inst.operands[0].imm) |
12603 | inst.instruction |= 0x8; | |
12604 | } | |
b99bd4ef | 12605 | |
c19d1205 ZW |
12606 | static void |
12607 | do_t_shift (void) | |
12608 | { | |
12609 | if (!inst.operands[1].present) | |
12610 | inst.operands[1].reg = inst.operands[0].reg; | |
12611 | ||
12612 | if (unified_syntax) | |
12613 | { | |
3d388997 PB |
12614 | bfd_boolean narrow; |
12615 | int shift_kind; | |
12616 | ||
12617 | switch (inst.instruction) | |
12618 | { | |
12619 | case T_MNEM_asr: | |
12620 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
12621 | case T_MNEM_lsl: | |
12622 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
12623 | case T_MNEM_lsr: | |
12624 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
12625 | case T_MNEM_ror: | |
12626 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
12627 | default: abort (); | |
12628 | } | |
12629 | ||
12630 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
e07e6e58 | 12631 | narrow = !in_it_block (); |
3d388997 | 12632 | else |
e07e6e58 | 12633 | narrow = in_it_block (); |
3d388997 PB |
12634 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) |
12635 | narrow = FALSE; | |
12636 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
12637 | narrow = FALSE; | |
12638 | if (inst.operands[2].isreg | |
12639 | && (inst.operands[1].reg != inst.operands[0].reg | |
12640 | || inst.operands[2].reg > 7)) | |
12641 | narrow = FALSE; | |
12642 | if (inst.size_req == 4) | |
12643 | narrow = FALSE; | |
12644 | ||
fdfde340 JM |
12645 | reject_bad_reg (inst.operands[0].reg); |
12646 | reject_bad_reg (inst.operands[1].reg); | |
c921be7d | 12647 | |
3d388997 | 12648 | if (!narrow) |
c19d1205 ZW |
12649 | { |
12650 | if (inst.operands[2].isreg) | |
b99bd4ef | 12651 | { |
fdfde340 | 12652 | reject_bad_reg (inst.operands[2].reg); |
c19d1205 ZW |
12653 | inst.instruction = THUMB_OP32 (inst.instruction); |
12654 | inst.instruction |= inst.operands[0].reg << 8; | |
12655 | inst.instruction |= inst.operands[1].reg << 16; | |
12656 | inst.instruction |= inst.operands[2].reg; | |
94342ec3 NC |
12657 | |
12658 | /* PR 12854: Error on extraneous shifts. */ | |
12659 | constraint (inst.operands[2].shifted, | |
12660 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
12661 | } |
12662 | else | |
12663 | { | |
12664 | inst.operands[1].shifted = 1; | |
3d388997 | 12665 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
12666 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
12667 | ? T_MNEM_movs : T_MNEM_mov); | |
12668 | inst.instruction |= inst.operands[0].reg << 8; | |
12669 | encode_thumb32_shifted_operand (1); | |
12670 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
12671 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
12672 | } |
12673 | } | |
12674 | else | |
12675 | { | |
c19d1205 | 12676 | if (inst.operands[2].isreg) |
b99bd4ef | 12677 | { |
3d388997 | 12678 | switch (shift_kind) |
b99bd4ef | 12679 | { |
3d388997 PB |
12680 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
12681 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
12682 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
12683 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 12684 | default: abort (); |
b99bd4ef | 12685 | } |
5f4273c7 | 12686 | |
c19d1205 ZW |
12687 | inst.instruction |= inst.operands[0].reg; |
12688 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
12689 | |
12690 | /* PR 12854: Error on extraneous shifts. */ | |
12691 | constraint (inst.operands[2].shifted, | |
12692 | _("extraneous shift as part of operand to shift insn")); | |
b99bd4ef NC |
12693 | } |
12694 | else | |
12695 | { | |
3d388997 | 12696 | switch (shift_kind) |
b99bd4ef | 12697 | { |
3d388997 PB |
12698 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
12699 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
12700 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 12701 | default: abort (); |
b99bd4ef | 12702 | } |
c19d1205 ZW |
12703 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
12704 | inst.instruction |= inst.operands[0].reg; | |
12705 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
12706 | } |
12707 | } | |
c19d1205 ZW |
12708 | } |
12709 | else | |
12710 | { | |
12711 | constraint (inst.operands[0].reg > 7 | |
12712 | || inst.operands[1].reg > 7, BAD_HIREG); | |
12713 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 12714 | |
c19d1205 ZW |
12715 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
12716 | { | |
12717 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
12718 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
12719 | _("source1 and dest must be same register")); | |
b99bd4ef | 12720 | |
c19d1205 ZW |
12721 | switch (inst.instruction) |
12722 | { | |
12723 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
12724 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
12725 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
12726 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
12727 | default: abort (); | |
12728 | } | |
5f4273c7 | 12729 | |
c19d1205 ZW |
12730 | inst.instruction |= inst.operands[0].reg; |
12731 | inst.instruction |= inst.operands[2].reg << 3; | |
af199b06 NC |
12732 | |
12733 | /* PR 12854: Error on extraneous shifts. */ | |
12734 | constraint (inst.operands[2].shifted, | |
12735 | _("extraneous shift as part of operand to shift insn")); | |
c19d1205 ZW |
12736 | } |
12737 | else | |
b99bd4ef | 12738 | { |
c19d1205 ZW |
12739 | switch (inst.instruction) |
12740 | { | |
12741 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
12742 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
12743 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
12744 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
12745 | default: abort (); | |
12746 | } | |
12747 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
12748 | inst.instruction |= inst.operands[0].reg; | |
12749 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
12750 | } |
12751 | } | |
b99bd4ef NC |
12752 | } |
12753 | ||
12754 | static void | |
c19d1205 | 12755 | do_t_simd (void) |
b99bd4ef | 12756 | { |
fdfde340 JM |
12757 | unsigned Rd, Rn, Rm; |
12758 | ||
12759 | Rd = inst.operands[0].reg; | |
12760 | Rn = inst.operands[1].reg; | |
12761 | Rm = inst.operands[2].reg; | |
12762 | ||
12763 | reject_bad_reg (Rd); | |
12764 | reject_bad_reg (Rn); | |
12765 | reject_bad_reg (Rm); | |
12766 | ||
12767 | inst.instruction |= Rd << 8; | |
12768 | inst.instruction |= Rn << 16; | |
12769 | inst.instruction |= Rm; | |
c19d1205 | 12770 | } |
b99bd4ef | 12771 | |
03ee1b7f NC |
12772 | static void |
12773 | do_t_simd2 (void) | |
12774 | { | |
12775 | unsigned Rd, Rn, Rm; | |
12776 | ||
12777 | Rd = inst.operands[0].reg; | |
12778 | Rm = inst.operands[1].reg; | |
12779 | Rn = inst.operands[2].reg; | |
12780 | ||
12781 | reject_bad_reg (Rd); | |
12782 | reject_bad_reg (Rn); | |
12783 | reject_bad_reg (Rm); | |
12784 | ||
12785 | inst.instruction |= Rd << 8; | |
12786 | inst.instruction |= Rn << 16; | |
12787 | inst.instruction |= Rm; | |
12788 | } | |
12789 | ||
c19d1205 | 12790 | static void |
3eb17e6b | 12791 | do_t_smc (void) |
c19d1205 ZW |
12792 | { |
12793 | unsigned int value = inst.reloc.exp.X_add_number; | |
f4c65163 MGD |
12794 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a), |
12795 | _("SMC is not permitted on this architecture")); | |
c19d1205 ZW |
12796 | constraint (inst.reloc.exp.X_op != O_constant, |
12797 | _("expression too complex")); | |
12798 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12799 | inst.instruction |= (value & 0xf000) >> 12; | |
12800 | inst.instruction |= (value & 0x0ff0); | |
12801 | inst.instruction |= (value & 0x000f) << 16; | |
24382199 NC |
12802 | /* PR gas/15623: SMC instructions must be last in an IT block. */ |
12803 | set_it_insn_type_last (); | |
c19d1205 | 12804 | } |
b99bd4ef | 12805 | |
90ec0d68 MGD |
12806 | static void |
12807 | do_t_hvc (void) | |
12808 | { | |
12809 | unsigned int value = inst.reloc.exp.X_add_number; | |
12810 | ||
12811 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12812 | inst.instruction |= (value & 0x0fff); | |
12813 | inst.instruction |= (value & 0xf000) << 4; | |
12814 | } | |
12815 | ||
c19d1205 | 12816 | static void |
3a21c15a | 12817 | do_t_ssat_usat (int bias) |
c19d1205 | 12818 | { |
fdfde340 JM |
12819 | unsigned Rd, Rn; |
12820 | ||
12821 | Rd = inst.operands[0].reg; | |
12822 | Rn = inst.operands[2].reg; | |
12823 | ||
12824 | reject_bad_reg (Rd); | |
12825 | reject_bad_reg (Rn); | |
12826 | ||
12827 | inst.instruction |= Rd << 8; | |
3a21c15a | 12828 | inst.instruction |= inst.operands[1].imm - bias; |
fdfde340 | 12829 | inst.instruction |= Rn << 16; |
b99bd4ef | 12830 | |
c19d1205 | 12831 | if (inst.operands[3].present) |
b99bd4ef | 12832 | { |
3a21c15a NC |
12833 | offsetT shift_amount = inst.reloc.exp.X_add_number; |
12834 | ||
12835 | inst.reloc.type = BFD_RELOC_UNUSED; | |
12836 | ||
c19d1205 ZW |
12837 | constraint (inst.reloc.exp.X_op != O_constant, |
12838 | _("expression too complex")); | |
b99bd4ef | 12839 | |
3a21c15a | 12840 | if (shift_amount != 0) |
6189168b | 12841 | { |
3a21c15a NC |
12842 | constraint (shift_amount > 31, |
12843 | _("shift expression is too large")); | |
12844 | ||
c19d1205 | 12845 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
3a21c15a NC |
12846 | inst.instruction |= 0x00200000; /* sh bit. */ |
12847 | ||
12848 | inst.instruction |= (shift_amount & 0x1c) << 10; | |
12849 | inst.instruction |= (shift_amount & 0x03) << 6; | |
6189168b NC |
12850 | } |
12851 | } | |
b99bd4ef | 12852 | } |
c921be7d | 12853 | |
3a21c15a NC |
12854 | static void |
12855 | do_t_ssat (void) | |
12856 | { | |
12857 | do_t_ssat_usat (1); | |
12858 | } | |
b99bd4ef | 12859 | |
0dd132b6 | 12860 | static void |
c19d1205 | 12861 | do_t_ssat16 (void) |
0dd132b6 | 12862 | { |
fdfde340 JM |
12863 | unsigned Rd, Rn; |
12864 | ||
12865 | Rd = inst.operands[0].reg; | |
12866 | Rn = inst.operands[2].reg; | |
12867 | ||
12868 | reject_bad_reg (Rd); | |
12869 | reject_bad_reg (Rn); | |
12870 | ||
12871 | inst.instruction |= Rd << 8; | |
c19d1205 | 12872 | inst.instruction |= inst.operands[1].imm - 1; |
fdfde340 | 12873 | inst.instruction |= Rn << 16; |
c19d1205 | 12874 | } |
0dd132b6 | 12875 | |
c19d1205 ZW |
12876 | static void |
12877 | do_t_strex (void) | |
12878 | { | |
12879 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
12880 | || inst.operands[2].postind || inst.operands[2].writeback | |
12881 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
12882 | || inst.operands[2].negative, | |
01cfc07f | 12883 | BAD_ADDR_MODE); |
0dd132b6 | 12884 | |
5be8be5d DG |
12885 | constraint (inst.operands[2].reg == REG_PC, BAD_PC); |
12886 | ||
c19d1205 ZW |
12887 | inst.instruction |= inst.operands[0].reg << 8; |
12888 | inst.instruction |= inst.operands[1].reg << 12; | |
12889 | inst.instruction |= inst.operands[2].reg << 16; | |
12890 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
12891 | } |
12892 | ||
b99bd4ef | 12893 | static void |
c19d1205 | 12894 | do_t_strexd (void) |
b99bd4ef | 12895 | { |
c19d1205 ZW |
12896 | if (!inst.operands[2].present) |
12897 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 12898 | |
c19d1205 ZW |
12899 | constraint (inst.operands[0].reg == inst.operands[1].reg |
12900 | || inst.operands[0].reg == inst.operands[2].reg | |
f8a8e9d6 | 12901 | || inst.operands[0].reg == inst.operands[3].reg, |
c19d1205 | 12902 | BAD_OVERLAP); |
b99bd4ef | 12903 | |
c19d1205 ZW |
12904 | inst.instruction |= inst.operands[0].reg; |
12905 | inst.instruction |= inst.operands[1].reg << 12; | |
12906 | inst.instruction |= inst.operands[2].reg << 8; | |
12907 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
12908 | } |
12909 | ||
12910 | static void | |
c19d1205 | 12911 | do_t_sxtah (void) |
b99bd4ef | 12912 | { |
fdfde340 JM |
12913 | unsigned Rd, Rn, Rm; |
12914 | ||
12915 | Rd = inst.operands[0].reg; | |
12916 | Rn = inst.operands[1].reg; | |
12917 | Rm = inst.operands[2].reg; | |
12918 | ||
12919 | reject_bad_reg (Rd); | |
12920 | reject_bad_reg (Rn); | |
12921 | reject_bad_reg (Rm); | |
12922 | ||
12923 | inst.instruction |= Rd << 8; | |
12924 | inst.instruction |= Rn << 16; | |
12925 | inst.instruction |= Rm; | |
c19d1205 ZW |
12926 | inst.instruction |= inst.operands[3].imm << 4; |
12927 | } | |
b99bd4ef | 12928 | |
c19d1205 ZW |
12929 | static void |
12930 | do_t_sxth (void) | |
12931 | { | |
fdfde340 JM |
12932 | unsigned Rd, Rm; |
12933 | ||
12934 | Rd = inst.operands[0].reg; | |
12935 | Rm = inst.operands[1].reg; | |
12936 | ||
12937 | reject_bad_reg (Rd); | |
12938 | reject_bad_reg (Rm); | |
c921be7d NC |
12939 | |
12940 | if (inst.instruction <= 0xffff | |
12941 | && inst.size_req != 4 | |
fdfde340 | 12942 | && Rd <= 7 && Rm <= 7 |
c19d1205 | 12943 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) |
b99bd4ef | 12944 | { |
c19d1205 | 12945 | inst.instruction = THUMB_OP16 (inst.instruction); |
fdfde340 JM |
12946 | inst.instruction |= Rd; |
12947 | inst.instruction |= Rm << 3; | |
b99bd4ef | 12948 | } |
c19d1205 | 12949 | else if (unified_syntax) |
b99bd4ef | 12950 | { |
c19d1205 ZW |
12951 | if (inst.instruction <= 0xffff) |
12952 | inst.instruction = THUMB_OP32 (inst.instruction); | |
fdfde340 JM |
12953 | inst.instruction |= Rd << 8; |
12954 | inst.instruction |= Rm; | |
c19d1205 | 12955 | inst.instruction |= inst.operands[2].imm << 4; |
b99bd4ef | 12956 | } |
c19d1205 | 12957 | else |
b99bd4ef | 12958 | { |
c19d1205 ZW |
12959 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
12960 | _("Thumb encoding does not support rotation")); | |
12961 | constraint (1, BAD_HIREG); | |
b99bd4ef | 12962 | } |
c19d1205 | 12963 | } |
b99bd4ef | 12964 | |
c19d1205 ZW |
12965 | static void |
12966 | do_t_swi (void) | |
12967 | { | |
b2a5fbdc MGD |
12968 | /* We have to do the following check manually as ARM_EXT_OS only applies |
12969 | to ARM_EXT_V6M. */ | |
12970 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m)) | |
12971 | { | |
ac7f631b NC |
12972 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os) |
12973 | /* This only applies to the v6m howver, not later architectures. */ | |
12974 | && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)) | |
b2a5fbdc MGD |
12975 | as_bad (_("SVC is not permitted on this architecture")); |
12976 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os); | |
12977 | } | |
12978 | ||
c19d1205 ZW |
12979 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
12980 | } | |
b99bd4ef | 12981 | |
92e90b6e PB |
12982 | static void |
12983 | do_t_tb (void) | |
12984 | { | |
fdfde340 | 12985 | unsigned Rn, Rm; |
92e90b6e PB |
12986 | int half; |
12987 | ||
12988 | half = (inst.instruction & 0x10) != 0; | |
e07e6e58 | 12989 | set_it_insn_type_last (); |
dfa9f0d5 PB |
12990 | constraint (inst.operands[0].immisreg, |
12991 | _("instruction requires register index")); | |
fdfde340 JM |
12992 | |
12993 | Rn = inst.operands[0].reg; | |
12994 | Rm = inst.operands[0].imm; | |
c921be7d | 12995 | |
fdfde340 JM |
12996 | constraint (Rn == REG_SP, BAD_SP); |
12997 | reject_bad_reg (Rm); | |
12998 | ||
92e90b6e PB |
12999 | constraint (!half && inst.operands[0].shifted, |
13000 | _("instruction does not allow shifted index")); | |
fdfde340 | 13001 | inst.instruction |= (Rn << 16) | Rm; |
92e90b6e PB |
13002 | } |
13003 | ||
74db7efb NC |
13004 | static void |
13005 | do_t_udf (void) | |
13006 | { | |
13007 | if (!inst.operands[0].present) | |
13008 | inst.operands[0].imm = 0; | |
13009 | ||
13010 | if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4) | |
13011 | { | |
13012 | constraint (inst.size_req == 2, | |
13013 | _("immediate value out of range")); | |
13014 | inst.instruction = THUMB_OP32 (inst.instruction); | |
13015 | inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4; | |
13016 | inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0; | |
13017 | } | |
13018 | else | |
13019 | { | |
13020 | inst.instruction = THUMB_OP16 (inst.instruction); | |
13021 | inst.instruction |= inst.operands[0].imm; | |
13022 | } | |
13023 | ||
13024 | set_it_insn_type (NEUTRAL_IT_INSN); | |
13025 | } | |
13026 | ||
13027 | ||
c19d1205 ZW |
13028 | static void |
13029 | do_t_usat (void) | |
13030 | { | |
3a21c15a | 13031 | do_t_ssat_usat (0); |
b99bd4ef NC |
13032 | } |
13033 | ||
13034 | static void | |
c19d1205 | 13035 | do_t_usat16 (void) |
b99bd4ef | 13036 | { |
fdfde340 JM |
13037 | unsigned Rd, Rn; |
13038 | ||
13039 | Rd = inst.operands[0].reg; | |
13040 | Rn = inst.operands[2].reg; | |
13041 | ||
13042 | reject_bad_reg (Rd); | |
13043 | reject_bad_reg (Rn); | |
13044 | ||
13045 | inst.instruction |= Rd << 8; | |
c19d1205 | 13046 | inst.instruction |= inst.operands[1].imm; |
fdfde340 | 13047 | inst.instruction |= Rn << 16; |
b99bd4ef | 13048 | } |
c19d1205 | 13049 | |
5287ad62 | 13050 | /* Neon instruction encoder helpers. */ |
5f4273c7 | 13051 | |
5287ad62 | 13052 | /* Encodings for the different types for various Neon opcodes. */ |
b99bd4ef | 13053 | |
5287ad62 JB |
13054 | /* An "invalid" code for the following tables. */ |
13055 | #define N_INV -1u | |
13056 | ||
13057 | struct neon_tab_entry | |
b99bd4ef | 13058 | { |
5287ad62 JB |
13059 | unsigned integer; |
13060 | unsigned float_or_poly; | |
13061 | unsigned scalar_or_imm; | |
13062 | }; | |
5f4273c7 | 13063 | |
5287ad62 JB |
13064 | /* Map overloaded Neon opcodes to their respective encodings. */ |
13065 | #define NEON_ENC_TAB \ | |
13066 | X(vabd, 0x0000700, 0x1200d00, N_INV), \ | |
13067 | X(vmax, 0x0000600, 0x0000f00, N_INV), \ | |
13068 | X(vmin, 0x0000610, 0x0200f00, N_INV), \ | |
13069 | X(vpadd, 0x0000b10, 0x1000d00, N_INV), \ | |
13070 | X(vpmax, 0x0000a00, 0x1000f00, N_INV), \ | |
13071 | X(vpmin, 0x0000a10, 0x1200f00, N_INV), \ | |
13072 | X(vadd, 0x0000800, 0x0000d00, N_INV), \ | |
13073 | X(vsub, 0x1000800, 0x0200d00, N_INV), \ | |
13074 | X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \ | |
13075 | X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \ | |
13076 | X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \ | |
13077 | /* Register variants of the following two instructions are encoded as | |
e07e6e58 | 13078 | vcge / vcgt with the operands reversed. */ \ |
92559b5b PB |
13079 | X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \ |
13080 | X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \ | |
62f3b8c8 PB |
13081 | X(vfma, N_INV, 0x0000c10, N_INV), \ |
13082 | X(vfms, N_INV, 0x0200c10, N_INV), \ | |
5287ad62 JB |
13083 | X(vmla, 0x0000900, 0x0000d10, 0x0800040), \ |
13084 | X(vmls, 0x1000900, 0x0200d10, 0x0800440), \ | |
13085 | X(vmul, 0x0000910, 0x1000d10, 0x0800840), \ | |
13086 | X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \ | |
13087 | X(vmlal, 0x0800800, N_INV, 0x0800240), \ | |
13088 | X(vmlsl, 0x0800a00, N_INV, 0x0800640), \ | |
13089 | X(vqdmlal, 0x0800900, N_INV, 0x0800340), \ | |
13090 | X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \ | |
13091 | X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \ | |
13092 | X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \ | |
13093 | X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \ | |
d6b4b13e MW |
13094 | X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \ |
13095 | X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \ | |
5287ad62 JB |
13096 | X(vshl, 0x0000400, N_INV, 0x0800510), \ |
13097 | X(vqshl, 0x0000410, N_INV, 0x0800710), \ | |
13098 | X(vand, 0x0000110, N_INV, 0x0800030), \ | |
13099 | X(vbic, 0x0100110, N_INV, 0x0800030), \ | |
13100 | X(veor, 0x1000110, N_INV, N_INV), \ | |
13101 | X(vorn, 0x0300110, N_INV, 0x0800010), \ | |
13102 | X(vorr, 0x0200110, N_INV, 0x0800010), \ | |
13103 | X(vmvn, 0x1b00580, N_INV, 0x0800030), \ | |
13104 | X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \ | |
13105 | X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \ | |
13106 | X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \ | |
13107 | X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \ | |
13108 | X(vst1, 0x0000000, 0x0800000, N_INV), \ | |
13109 | X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \ | |
13110 | X(vst2, 0x0000100, 0x0800100, N_INV), \ | |
13111 | X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \ | |
13112 | X(vst3, 0x0000200, 0x0800200, N_INV), \ | |
13113 | X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \ | |
13114 | X(vst4, 0x0000300, 0x0800300, N_INV), \ | |
13115 | X(vmovn, 0x1b20200, N_INV, N_INV), \ | |
13116 | X(vtrn, 0x1b20080, N_INV, N_INV), \ | |
13117 | X(vqmovn, 0x1b20200, N_INV, N_INV), \ | |
037e8744 JB |
13118 | X(vqmovun, 0x1b20240, N_INV, N_INV), \ |
13119 | X(vnmul, 0xe200a40, 0xe200b40, N_INV), \ | |
e6655fda PB |
13120 | X(vnmla, 0xe100a40, 0xe100b40, N_INV), \ |
13121 | X(vnmls, 0xe100a00, 0xe100b00, N_INV), \ | |
62f3b8c8 PB |
13122 | X(vfnma, 0xe900a40, 0xe900b40, N_INV), \ |
13123 | X(vfnms, 0xe900a00, 0xe900b00, N_INV), \ | |
037e8744 JB |
13124 | X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \ |
13125 | X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \ | |
13126 | X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \ | |
33399f07 MGD |
13127 | X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \ |
13128 | X(vseleq, 0xe000a00, N_INV, N_INV), \ | |
13129 | X(vselvs, 0xe100a00, N_INV, N_INV), \ | |
13130 | X(vselge, 0xe200a00, N_INV, N_INV), \ | |
73924fbc MGD |
13131 | X(vselgt, 0xe300a00, N_INV, N_INV), \ |
13132 | X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \ | |
7e8e6784 | 13133 | X(vminnm, 0xe800a40, 0x3200f10, N_INV), \ |
30bdf752 MGD |
13134 | X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \ |
13135 | X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \ | |
91ff7894 | 13136 | X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \ |
48adcd8e | 13137 | X(aes, 0x3b00300, N_INV, N_INV), \ |
3c9017d2 MGD |
13138 | X(sha3op, 0x2000c00, N_INV, N_INV), \ |
13139 | X(sha1h, 0x3b902c0, N_INV, N_INV), \ | |
13140 | X(sha2op, 0x3ba0380, N_INV, N_INV) | |
5287ad62 JB |
13141 | |
13142 | enum neon_opc | |
13143 | { | |
13144 | #define X(OPC,I,F,S) N_MNEM_##OPC | |
13145 | NEON_ENC_TAB | |
13146 | #undef X | |
13147 | }; | |
b99bd4ef | 13148 | |
5287ad62 JB |
13149 | static const struct neon_tab_entry neon_enc_tab[] = |
13150 | { | |
13151 | #define X(OPC,I,F,S) { (I), (F), (S) } | |
13152 | NEON_ENC_TAB | |
13153 | #undef X | |
13154 | }; | |
b99bd4ef | 13155 | |
88714cb8 DG |
13156 | /* Do not use these macros; instead, use NEON_ENCODE defined below. */ |
13157 | #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13158 | #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13159 | #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13160 | #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13161 | #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13162 | #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13163 | #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer) | |
13164 | #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | |
13165 | #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm) | |
13166 | #define NEON_ENC_SINGLE_(X) \ | |
037e8744 | 13167 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000)) |
88714cb8 | 13168 | #define NEON_ENC_DOUBLE_(X) \ |
037e8744 | 13169 | ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000)) |
33399f07 MGD |
13170 | #define NEON_ENC_FPV8_(X) \ |
13171 | ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000)) | |
5287ad62 | 13172 | |
88714cb8 DG |
13173 | #define NEON_ENCODE(type, inst) \ |
13174 | do \ | |
13175 | { \ | |
13176 | inst.instruction = NEON_ENC_##type##_ (inst.instruction); \ | |
13177 | inst.is_neon = 1; \ | |
13178 | } \ | |
13179 | while (0) | |
13180 | ||
13181 | #define check_neon_suffixes \ | |
13182 | do \ | |
13183 | { \ | |
13184 | if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \ | |
13185 | { \ | |
13186 | as_bad (_("invalid neon suffix for non neon instruction")); \ | |
13187 | return; \ | |
13188 | } \ | |
13189 | } \ | |
13190 | while (0) | |
13191 | ||
037e8744 JB |
13192 | /* Define shapes for instruction operands. The following mnemonic characters |
13193 | are used in this table: | |
5287ad62 | 13194 | |
037e8744 | 13195 | F - VFP S<n> register |
5287ad62 JB |
13196 | D - Neon D<n> register |
13197 | Q - Neon Q<n> register | |
13198 | I - Immediate | |
13199 | S - Scalar | |
13200 | R - ARM register | |
13201 | L - D<n> register list | |
5f4273c7 | 13202 | |
037e8744 JB |
13203 | This table is used to generate various data: |
13204 | - enumerations of the form NS_DDR to be used as arguments to | |
13205 | neon_select_shape. | |
13206 | - a table classifying shapes into single, double, quad, mixed. | |
5f4273c7 | 13207 | - a table used to drive neon_select_shape. */ |
b99bd4ef | 13208 | |
037e8744 JB |
13209 | #define NEON_SHAPE_DEF \ |
13210 | X(3, (D, D, D), DOUBLE), \ | |
13211 | X(3, (Q, Q, Q), QUAD), \ | |
13212 | X(3, (D, D, I), DOUBLE), \ | |
13213 | X(3, (Q, Q, I), QUAD), \ | |
13214 | X(3, (D, D, S), DOUBLE), \ | |
13215 | X(3, (Q, Q, S), QUAD), \ | |
13216 | X(2, (D, D), DOUBLE), \ | |
13217 | X(2, (Q, Q), QUAD), \ | |
13218 | X(2, (D, S), DOUBLE), \ | |
13219 | X(2, (Q, S), QUAD), \ | |
13220 | X(2, (D, R), DOUBLE), \ | |
13221 | X(2, (Q, R), QUAD), \ | |
13222 | X(2, (D, I), DOUBLE), \ | |
13223 | X(2, (Q, I), QUAD), \ | |
13224 | X(3, (D, L, D), DOUBLE), \ | |
13225 | X(2, (D, Q), MIXED), \ | |
13226 | X(2, (Q, D), MIXED), \ | |
13227 | X(3, (D, Q, I), MIXED), \ | |
13228 | X(3, (Q, D, I), MIXED), \ | |
13229 | X(3, (Q, D, D), MIXED), \ | |
13230 | X(3, (D, Q, Q), MIXED), \ | |
13231 | X(3, (Q, Q, D), MIXED), \ | |
13232 | X(3, (Q, D, S), MIXED), \ | |
13233 | X(3, (D, Q, S), MIXED), \ | |
13234 | X(4, (D, D, D, I), DOUBLE), \ | |
13235 | X(4, (Q, Q, Q, I), QUAD), \ | |
13236 | X(2, (F, F), SINGLE), \ | |
13237 | X(3, (F, F, F), SINGLE), \ | |
13238 | X(2, (F, I), SINGLE), \ | |
13239 | X(2, (F, D), MIXED), \ | |
13240 | X(2, (D, F), MIXED), \ | |
13241 | X(3, (F, F, I), MIXED), \ | |
13242 | X(4, (R, R, F, F), SINGLE), \ | |
13243 | X(4, (F, F, R, R), SINGLE), \ | |
13244 | X(3, (D, R, R), DOUBLE), \ | |
13245 | X(3, (R, R, D), DOUBLE), \ | |
13246 | X(2, (S, R), SINGLE), \ | |
13247 | X(2, (R, S), SINGLE), \ | |
13248 | X(2, (F, R), SINGLE), \ | |
13249 | X(2, (R, F), SINGLE) | |
13250 | ||
13251 | #define S2(A,B) NS_##A##B | |
13252 | #define S3(A,B,C) NS_##A##B##C | |
13253 | #define S4(A,B,C,D) NS_##A##B##C##D | |
13254 | ||
13255 | #define X(N, L, C) S##N L | |
13256 | ||
5287ad62 JB |
13257 | enum neon_shape |
13258 | { | |
037e8744 JB |
13259 | NEON_SHAPE_DEF, |
13260 | NS_NULL | |
5287ad62 | 13261 | }; |
b99bd4ef | 13262 | |
037e8744 JB |
13263 | #undef X |
13264 | #undef S2 | |
13265 | #undef S3 | |
13266 | #undef S4 | |
13267 | ||
13268 | enum neon_shape_class | |
13269 | { | |
13270 | SC_SINGLE, | |
13271 | SC_DOUBLE, | |
13272 | SC_QUAD, | |
13273 | SC_MIXED | |
13274 | }; | |
13275 | ||
13276 | #define X(N, L, C) SC_##C | |
13277 | ||
13278 | static enum neon_shape_class neon_shape_class[] = | |
13279 | { | |
13280 | NEON_SHAPE_DEF | |
13281 | }; | |
13282 | ||
13283 | #undef X | |
13284 | ||
13285 | enum neon_shape_el | |
13286 | { | |
13287 | SE_F, | |
13288 | SE_D, | |
13289 | SE_Q, | |
13290 | SE_I, | |
13291 | SE_S, | |
13292 | SE_R, | |
13293 | SE_L | |
13294 | }; | |
13295 | ||
13296 | /* Register widths of above. */ | |
13297 | static unsigned neon_shape_el_size[] = | |
13298 | { | |
13299 | 32, | |
13300 | 64, | |
13301 | 128, | |
13302 | 0, | |
13303 | 32, | |
13304 | 32, | |
13305 | 0 | |
13306 | }; | |
13307 | ||
13308 | struct neon_shape_info | |
13309 | { | |
13310 | unsigned els; | |
13311 | enum neon_shape_el el[NEON_MAX_TYPE_ELS]; | |
13312 | }; | |
13313 | ||
13314 | #define S2(A,B) { SE_##A, SE_##B } | |
13315 | #define S3(A,B,C) { SE_##A, SE_##B, SE_##C } | |
13316 | #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D } | |
13317 | ||
13318 | #define X(N, L, C) { N, S##N L } | |
13319 | ||
13320 | static struct neon_shape_info neon_shape_tab[] = | |
13321 | { | |
13322 | NEON_SHAPE_DEF | |
13323 | }; | |
13324 | ||
13325 | #undef X | |
13326 | #undef S2 | |
13327 | #undef S3 | |
13328 | #undef S4 | |
13329 | ||
5287ad62 JB |
13330 | /* Bit masks used in type checking given instructions. |
13331 | 'N_EQK' means the type must be the same as (or based on in some way) the key | |
13332 | type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is | |
13333 | set, various other bits can be set as well in order to modify the meaning of | |
13334 | the type constraint. */ | |
13335 | ||
13336 | enum neon_type_mask | |
13337 | { | |
8e79c3df CM |
13338 | N_S8 = 0x0000001, |
13339 | N_S16 = 0x0000002, | |
13340 | N_S32 = 0x0000004, | |
13341 | N_S64 = 0x0000008, | |
13342 | N_U8 = 0x0000010, | |
13343 | N_U16 = 0x0000020, | |
13344 | N_U32 = 0x0000040, | |
13345 | N_U64 = 0x0000080, | |
13346 | N_I8 = 0x0000100, | |
13347 | N_I16 = 0x0000200, | |
13348 | N_I32 = 0x0000400, | |
13349 | N_I64 = 0x0000800, | |
13350 | N_8 = 0x0001000, | |
13351 | N_16 = 0x0002000, | |
13352 | N_32 = 0x0004000, | |
13353 | N_64 = 0x0008000, | |
13354 | N_P8 = 0x0010000, | |
13355 | N_P16 = 0x0020000, | |
13356 | N_F16 = 0x0040000, | |
13357 | N_F32 = 0x0080000, | |
13358 | N_F64 = 0x0100000, | |
4f51b4bd | 13359 | N_P64 = 0x0200000, |
c921be7d NC |
13360 | N_KEY = 0x1000000, /* Key element (main type specifier). */ |
13361 | N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */ | |
8e79c3df | 13362 | N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */ |
91ff7894 | 13363 | N_UNT = 0x8000000, /* Must be explicitly untyped. */ |
c921be7d NC |
13364 | N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */ |
13365 | N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */ | |
13366 | N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */ | |
13367 | N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */ | |
13368 | N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */ | |
13369 | N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */ | |
13370 | N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */ | |
5287ad62 | 13371 | N_UTYP = 0, |
4f51b4bd | 13372 | N_MAX_NONSPECIAL = N_P64 |
5287ad62 JB |
13373 | }; |
13374 | ||
dcbf9037 JB |
13375 | #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ) |
13376 | ||
5287ad62 JB |
13377 | #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64) |
13378 | #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32) | |
13379 | #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64) | |
13380 | #define N_SUF_32 (N_SU_32 | N_F32) | |
13381 | #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64) | |
13382 | #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32) | |
13383 | ||
13384 | /* Pass this as the first type argument to neon_check_type to ignore types | |
13385 | altogether. */ | |
13386 | #define N_IGNORE_TYPE (N_KEY | N_EQK) | |
13387 | ||
037e8744 JB |
13388 | /* Select a "shape" for the current instruction (describing register types or |
13389 | sizes) from a list of alternatives. Return NS_NULL if the current instruction | |
13390 | doesn't fit. For non-polymorphic shapes, checking is usually done as a | |
13391 | function of operand parsing, so this function doesn't need to be called. | |
13392 | Shapes should be listed in order of decreasing length. */ | |
5287ad62 JB |
13393 | |
13394 | static enum neon_shape | |
037e8744 | 13395 | neon_select_shape (enum neon_shape shape, ...) |
5287ad62 | 13396 | { |
037e8744 JB |
13397 | va_list ap; |
13398 | enum neon_shape first_shape = shape; | |
5287ad62 JB |
13399 | |
13400 | /* Fix missing optional operands. FIXME: we don't know at this point how | |
13401 | many arguments we should have, so this makes the assumption that we have | |
13402 | > 1. This is true of all current Neon opcodes, I think, but may not be | |
13403 | true in the future. */ | |
13404 | if (!inst.operands[1].present) | |
13405 | inst.operands[1] = inst.operands[0]; | |
13406 | ||
037e8744 | 13407 | va_start (ap, shape); |
5f4273c7 | 13408 | |
21d799b5 | 13409 | for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int)) |
037e8744 JB |
13410 | { |
13411 | unsigned j; | |
13412 | int matches = 1; | |
13413 | ||
13414 | for (j = 0; j < neon_shape_tab[shape].els; j++) | |
477330fc RM |
13415 | { |
13416 | if (!inst.operands[j].present) | |
13417 | { | |
13418 | matches = 0; | |
13419 | break; | |
13420 | } | |
13421 | ||
13422 | switch (neon_shape_tab[shape].el[j]) | |
13423 | { | |
13424 | case SE_F: | |
13425 | if (!(inst.operands[j].isreg | |
13426 | && inst.operands[j].isvec | |
13427 | && inst.operands[j].issingle | |
13428 | && !inst.operands[j].isquad)) | |
13429 | matches = 0; | |
13430 | break; | |
13431 | ||
13432 | case SE_D: | |
13433 | if (!(inst.operands[j].isreg | |
13434 | && inst.operands[j].isvec | |
13435 | && !inst.operands[j].isquad | |
13436 | && !inst.operands[j].issingle)) | |
13437 | matches = 0; | |
13438 | break; | |
13439 | ||
13440 | case SE_R: | |
13441 | if (!(inst.operands[j].isreg | |
13442 | && !inst.operands[j].isvec)) | |
13443 | matches = 0; | |
13444 | break; | |
13445 | ||
13446 | case SE_Q: | |
13447 | if (!(inst.operands[j].isreg | |
13448 | && inst.operands[j].isvec | |
13449 | && inst.operands[j].isquad | |
13450 | && !inst.operands[j].issingle)) | |
13451 | matches = 0; | |
13452 | break; | |
13453 | ||
13454 | case SE_I: | |
13455 | if (!(!inst.operands[j].isreg | |
13456 | && !inst.operands[j].isscalar)) | |
13457 | matches = 0; | |
13458 | break; | |
13459 | ||
13460 | case SE_S: | |
13461 | if (!(!inst.operands[j].isreg | |
13462 | && inst.operands[j].isscalar)) | |
13463 | matches = 0; | |
13464 | break; | |
13465 | ||
13466 | case SE_L: | |
13467 | break; | |
13468 | } | |
3fde54a2 JZ |
13469 | if (!matches) |
13470 | break; | |
477330fc | 13471 | } |
ad6cec43 MGD |
13472 | if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present)) |
13473 | /* We've matched all the entries in the shape table, and we don't | |
13474 | have any left over operands which have not been matched. */ | |
477330fc | 13475 | break; |
037e8744 | 13476 | } |
5f4273c7 | 13477 | |
037e8744 | 13478 | va_end (ap); |
5287ad62 | 13479 | |
037e8744 JB |
13480 | if (shape == NS_NULL && first_shape != NS_NULL) |
13481 | first_error (_("invalid instruction shape")); | |
5287ad62 | 13482 | |
037e8744 JB |
13483 | return shape; |
13484 | } | |
5287ad62 | 13485 | |
037e8744 JB |
13486 | /* True if SHAPE is predominantly a quadword operation (most of the time, this |
13487 | means the Q bit should be set). */ | |
13488 | ||
13489 | static int | |
13490 | neon_quad (enum neon_shape shape) | |
13491 | { | |
13492 | return neon_shape_class[shape] == SC_QUAD; | |
5287ad62 | 13493 | } |
037e8744 | 13494 | |
5287ad62 JB |
13495 | static void |
13496 | neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type, | |
477330fc | 13497 | unsigned *g_size) |
5287ad62 JB |
13498 | { |
13499 | /* Allow modification to be made to types which are constrained to be | |
13500 | based on the key element, based on bits set alongside N_EQK. */ | |
13501 | if ((typebits & N_EQK) != 0) | |
13502 | { | |
13503 | if ((typebits & N_HLF) != 0) | |
13504 | *g_size /= 2; | |
13505 | else if ((typebits & N_DBL) != 0) | |
13506 | *g_size *= 2; | |
13507 | if ((typebits & N_SGN) != 0) | |
13508 | *g_type = NT_signed; | |
13509 | else if ((typebits & N_UNS) != 0) | |
477330fc | 13510 | *g_type = NT_unsigned; |
5287ad62 | 13511 | else if ((typebits & N_INT) != 0) |
477330fc | 13512 | *g_type = NT_integer; |
5287ad62 | 13513 | else if ((typebits & N_FLT) != 0) |
477330fc | 13514 | *g_type = NT_float; |
dcbf9037 | 13515 | else if ((typebits & N_SIZ) != 0) |
477330fc | 13516 | *g_type = NT_untyped; |
5287ad62 JB |
13517 | } |
13518 | } | |
5f4273c7 | 13519 | |
5287ad62 JB |
13520 | /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key" |
13521 | operand type, i.e. the single type specified in a Neon instruction when it | |
13522 | is the only one given. */ | |
13523 | ||
13524 | static struct neon_type_el | |
13525 | neon_type_promote (struct neon_type_el *key, unsigned thisarg) | |
13526 | { | |
13527 | struct neon_type_el dest = *key; | |
5f4273c7 | 13528 | |
9c2799c2 | 13529 | gas_assert ((thisarg & N_EQK) != 0); |
5f4273c7 | 13530 | |
5287ad62 JB |
13531 | neon_modify_type_size (thisarg, &dest.type, &dest.size); |
13532 | ||
13533 | return dest; | |
13534 | } | |
13535 | ||
13536 | /* Convert Neon type and size into compact bitmask representation. */ | |
13537 | ||
13538 | static enum neon_type_mask | |
13539 | type_chk_of_el_type (enum neon_el_type type, unsigned size) | |
13540 | { | |
13541 | switch (type) | |
13542 | { | |
13543 | case NT_untyped: | |
13544 | switch (size) | |
477330fc RM |
13545 | { |
13546 | case 8: return N_8; | |
13547 | case 16: return N_16; | |
13548 | case 32: return N_32; | |
13549 | case 64: return N_64; | |
13550 | default: ; | |
13551 | } | |
5287ad62 JB |
13552 | break; |
13553 | ||
13554 | case NT_integer: | |
13555 | switch (size) | |
477330fc RM |
13556 | { |
13557 | case 8: return N_I8; | |
13558 | case 16: return N_I16; | |
13559 | case 32: return N_I32; | |
13560 | case 64: return N_I64; | |
13561 | default: ; | |
13562 | } | |
5287ad62 JB |
13563 | break; |
13564 | ||
13565 | case NT_float: | |
037e8744 | 13566 | switch (size) |
477330fc | 13567 | { |
8e79c3df | 13568 | case 16: return N_F16; |
477330fc RM |
13569 | case 32: return N_F32; |
13570 | case 64: return N_F64; | |
13571 | default: ; | |
13572 | } | |
5287ad62 JB |
13573 | break; |
13574 | ||
13575 | case NT_poly: | |
13576 | switch (size) | |
477330fc RM |
13577 | { |
13578 | case 8: return N_P8; | |
13579 | case 16: return N_P16; | |
4f51b4bd | 13580 | case 64: return N_P64; |
477330fc RM |
13581 | default: ; |
13582 | } | |
5287ad62 JB |
13583 | break; |
13584 | ||
13585 | case NT_signed: | |
13586 | switch (size) | |
477330fc RM |
13587 | { |
13588 | case 8: return N_S8; | |
13589 | case 16: return N_S16; | |
13590 | case 32: return N_S32; | |
13591 | case 64: return N_S64; | |
13592 | default: ; | |
13593 | } | |
5287ad62 JB |
13594 | break; |
13595 | ||
13596 | case NT_unsigned: | |
13597 | switch (size) | |
477330fc RM |
13598 | { |
13599 | case 8: return N_U8; | |
13600 | case 16: return N_U16; | |
13601 | case 32: return N_U32; | |
13602 | case 64: return N_U64; | |
13603 | default: ; | |
13604 | } | |
5287ad62 JB |
13605 | break; |
13606 | ||
13607 | default: ; | |
13608 | } | |
5f4273c7 | 13609 | |
5287ad62 JB |
13610 | return N_UTYP; |
13611 | } | |
13612 | ||
13613 | /* Convert compact Neon bitmask type representation to a type and size. Only | |
13614 | handles the case where a single bit is set in the mask. */ | |
13615 | ||
dcbf9037 | 13616 | static int |
5287ad62 | 13617 | el_type_of_type_chk (enum neon_el_type *type, unsigned *size, |
477330fc | 13618 | enum neon_type_mask mask) |
5287ad62 | 13619 | { |
dcbf9037 JB |
13620 | if ((mask & N_EQK) != 0) |
13621 | return FAIL; | |
13622 | ||
5287ad62 JB |
13623 | if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0) |
13624 | *size = 8; | |
c70a8987 | 13625 | else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0) |
5287ad62 | 13626 | *size = 16; |
dcbf9037 | 13627 | else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0) |
5287ad62 | 13628 | *size = 32; |
4f51b4bd | 13629 | else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0) |
5287ad62 | 13630 | *size = 64; |
dcbf9037 JB |
13631 | else |
13632 | return FAIL; | |
13633 | ||
5287ad62 JB |
13634 | if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0) |
13635 | *type = NT_signed; | |
dcbf9037 | 13636 | else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0) |
5287ad62 | 13637 | *type = NT_unsigned; |
dcbf9037 | 13638 | else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0) |
5287ad62 | 13639 | *type = NT_integer; |
dcbf9037 | 13640 | else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0) |
5287ad62 | 13641 | *type = NT_untyped; |
4f51b4bd | 13642 | else if ((mask & (N_P8 | N_P16 | N_P64)) != 0) |
5287ad62 | 13643 | *type = NT_poly; |
c70a8987 | 13644 | else if ((mask & (N_F16 | N_F32 | N_F64)) != 0) |
5287ad62 | 13645 | *type = NT_float; |
dcbf9037 JB |
13646 | else |
13647 | return FAIL; | |
5f4273c7 | 13648 | |
dcbf9037 | 13649 | return SUCCESS; |
5287ad62 JB |
13650 | } |
13651 | ||
13652 | /* Modify a bitmask of allowed types. This is only needed for type | |
13653 | relaxation. */ | |
13654 | ||
13655 | static unsigned | |
13656 | modify_types_allowed (unsigned allowed, unsigned mods) | |
13657 | { | |
13658 | unsigned size; | |
13659 | enum neon_el_type type; | |
13660 | unsigned destmask; | |
13661 | int i; | |
5f4273c7 | 13662 | |
5287ad62 | 13663 | destmask = 0; |
5f4273c7 | 13664 | |
5287ad62 JB |
13665 | for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1) |
13666 | { | |
21d799b5 | 13667 | if (el_type_of_type_chk (&type, &size, |
477330fc RM |
13668 | (enum neon_type_mask) (allowed & i)) == SUCCESS) |
13669 | { | |
13670 | neon_modify_type_size (mods, &type, &size); | |
13671 | destmask |= type_chk_of_el_type (type, size); | |
13672 | } | |
5287ad62 | 13673 | } |
5f4273c7 | 13674 | |
5287ad62 JB |
13675 | return destmask; |
13676 | } | |
13677 | ||
13678 | /* Check type and return type classification. | |
13679 | The manual states (paraphrase): If one datatype is given, it indicates the | |
13680 | type given in: | |
13681 | - the second operand, if there is one | |
13682 | - the operand, if there is no second operand | |
13683 | - the result, if there are no operands. | |
13684 | This isn't quite good enough though, so we use a concept of a "key" datatype | |
13685 | which is set on a per-instruction basis, which is the one which matters when | |
13686 | only one data type is written. | |
13687 | Note: this function has side-effects (e.g. filling in missing operands). All | |
037e8744 | 13688 | Neon instructions should call it before performing bit encoding. */ |
5287ad62 JB |
13689 | |
13690 | static struct neon_type_el | |
13691 | neon_check_type (unsigned els, enum neon_shape ns, ...) | |
13692 | { | |
13693 | va_list ap; | |
13694 | unsigned i, pass, key_el = 0; | |
13695 | unsigned types[NEON_MAX_TYPE_ELS]; | |
13696 | enum neon_el_type k_type = NT_invtype; | |
13697 | unsigned k_size = -1u; | |
13698 | struct neon_type_el badtype = {NT_invtype, -1}; | |
13699 | unsigned key_allowed = 0; | |
13700 | ||
13701 | /* Optional registers in Neon instructions are always (not) in operand 1. | |
13702 | Fill in the missing operand here, if it was omitted. */ | |
13703 | if (els > 1 && !inst.operands[1].present) | |
13704 | inst.operands[1] = inst.operands[0]; | |
13705 | ||
13706 | /* Suck up all the varargs. */ | |
13707 | va_start (ap, ns); | |
13708 | for (i = 0; i < els; i++) | |
13709 | { | |
13710 | unsigned thisarg = va_arg (ap, unsigned); | |
13711 | if (thisarg == N_IGNORE_TYPE) | |
477330fc RM |
13712 | { |
13713 | va_end (ap); | |
13714 | return badtype; | |
13715 | } | |
5287ad62 JB |
13716 | types[i] = thisarg; |
13717 | if ((thisarg & N_KEY) != 0) | |
477330fc | 13718 | key_el = i; |
5287ad62 JB |
13719 | } |
13720 | va_end (ap); | |
13721 | ||
dcbf9037 JB |
13722 | if (inst.vectype.elems > 0) |
13723 | for (i = 0; i < els; i++) | |
13724 | if (inst.operands[i].vectype.type != NT_invtype) | |
477330fc RM |
13725 | { |
13726 | first_error (_("types specified in both the mnemonic and operands")); | |
13727 | return badtype; | |
13728 | } | |
dcbf9037 | 13729 | |
5287ad62 JB |
13730 | /* Duplicate inst.vectype elements here as necessary. |
13731 | FIXME: No idea if this is exactly the same as the ARM assembler, | |
13732 | particularly when an insn takes one register and one non-register | |
13733 | operand. */ | |
13734 | if (inst.vectype.elems == 1 && els > 1) | |
13735 | { | |
13736 | unsigned j; | |
13737 | inst.vectype.elems = els; | |
13738 | inst.vectype.el[key_el] = inst.vectype.el[0]; | |
13739 | for (j = 0; j < els; j++) | |
477330fc RM |
13740 | if (j != key_el) |
13741 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
13742 | types[j]); | |
dcbf9037 JB |
13743 | } |
13744 | else if (inst.vectype.elems == 0 && els > 0) | |
13745 | { | |
13746 | unsigned j; | |
13747 | /* No types were given after the mnemonic, so look for types specified | |
477330fc RM |
13748 | after each operand. We allow some flexibility here; as long as the |
13749 | "key" operand has a type, we can infer the others. */ | |
dcbf9037 | 13750 | for (j = 0; j < els; j++) |
477330fc RM |
13751 | if (inst.operands[j].vectype.type != NT_invtype) |
13752 | inst.vectype.el[j] = inst.operands[j].vectype; | |
dcbf9037 JB |
13753 | |
13754 | if (inst.operands[key_el].vectype.type != NT_invtype) | |
477330fc RM |
13755 | { |
13756 | for (j = 0; j < els; j++) | |
13757 | if (inst.operands[j].vectype.type == NT_invtype) | |
13758 | inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el], | |
13759 | types[j]); | |
13760 | } | |
dcbf9037 | 13761 | else |
477330fc RM |
13762 | { |
13763 | first_error (_("operand types can't be inferred")); | |
13764 | return badtype; | |
13765 | } | |
5287ad62 JB |
13766 | } |
13767 | else if (inst.vectype.elems != els) | |
13768 | { | |
dcbf9037 | 13769 | first_error (_("type specifier has the wrong number of parts")); |
5287ad62 JB |
13770 | return badtype; |
13771 | } | |
13772 | ||
13773 | for (pass = 0; pass < 2; pass++) | |
13774 | { | |
13775 | for (i = 0; i < els; i++) | |
477330fc RM |
13776 | { |
13777 | unsigned thisarg = types[i]; | |
13778 | unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0) | |
13779 | ? modify_types_allowed (key_allowed, thisarg) : thisarg; | |
13780 | enum neon_el_type g_type = inst.vectype.el[i].type; | |
13781 | unsigned g_size = inst.vectype.el[i].size; | |
13782 | ||
13783 | /* Decay more-specific signed & unsigned types to sign-insensitive | |
5287ad62 | 13784 | integer types if sign-specific variants are unavailable. */ |
477330fc | 13785 | if ((g_type == NT_signed || g_type == NT_unsigned) |
5287ad62 JB |
13786 | && (types_allowed & N_SU_ALL) == 0) |
13787 | g_type = NT_integer; | |
13788 | ||
477330fc | 13789 | /* If only untyped args are allowed, decay any more specific types to |
5287ad62 JB |
13790 | them. Some instructions only care about signs for some element |
13791 | sizes, so handle that properly. */ | |
477330fc | 13792 | if (((types_allowed & N_UNT) == 0) |
91ff7894 MGD |
13793 | && ((g_size == 8 && (types_allowed & N_8) != 0) |
13794 | || (g_size == 16 && (types_allowed & N_16) != 0) | |
13795 | || (g_size == 32 && (types_allowed & N_32) != 0) | |
13796 | || (g_size == 64 && (types_allowed & N_64) != 0))) | |
5287ad62 JB |
13797 | g_type = NT_untyped; |
13798 | ||
477330fc RM |
13799 | if (pass == 0) |
13800 | { | |
13801 | if ((thisarg & N_KEY) != 0) | |
13802 | { | |
13803 | k_type = g_type; | |
13804 | k_size = g_size; | |
13805 | key_allowed = thisarg & ~N_KEY; | |
13806 | } | |
13807 | } | |
13808 | else | |
13809 | { | |
13810 | if ((thisarg & N_VFP) != 0) | |
13811 | { | |
13812 | enum neon_shape_el regshape; | |
13813 | unsigned regwidth, match; | |
99b253c5 NC |
13814 | |
13815 | /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */ | |
13816 | if (ns == NS_NULL) | |
13817 | { | |
13818 | first_error (_("invalid instruction shape")); | |
13819 | return badtype; | |
13820 | } | |
477330fc RM |
13821 | regshape = neon_shape_tab[ns].el[i]; |
13822 | regwidth = neon_shape_el_size[regshape]; | |
13823 | ||
13824 | /* In VFP mode, operands must match register widths. If we | |
13825 | have a key operand, use its width, else use the width of | |
13826 | the current operand. */ | |
13827 | if (k_size != -1u) | |
13828 | match = k_size; | |
13829 | else | |
13830 | match = g_size; | |
13831 | ||
13832 | if (regwidth != match) | |
13833 | { | |
13834 | first_error (_("operand size must match register width")); | |
13835 | return badtype; | |
13836 | } | |
13837 | } | |
13838 | ||
13839 | if ((thisarg & N_EQK) == 0) | |
13840 | { | |
13841 | unsigned given_type = type_chk_of_el_type (g_type, g_size); | |
13842 | ||
13843 | if ((given_type & types_allowed) == 0) | |
13844 | { | |
13845 | first_error (_("bad type in Neon instruction")); | |
13846 | return badtype; | |
13847 | } | |
13848 | } | |
13849 | else | |
13850 | { | |
13851 | enum neon_el_type mod_k_type = k_type; | |
13852 | unsigned mod_k_size = k_size; | |
13853 | neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size); | |
13854 | if (g_type != mod_k_type || g_size != mod_k_size) | |
13855 | { | |
13856 | first_error (_("inconsistent types in Neon instruction")); | |
13857 | return badtype; | |
13858 | } | |
13859 | } | |
13860 | } | |
13861 | } | |
5287ad62 JB |
13862 | } |
13863 | ||
13864 | return inst.vectype.el[key_el]; | |
13865 | } | |
13866 | ||
037e8744 | 13867 | /* Neon-style VFP instruction forwarding. */ |
5287ad62 | 13868 | |
037e8744 JB |
13869 | /* Thumb VFP instructions have 0xE in the condition field. */ |
13870 | ||
13871 | static void | |
13872 | do_vfp_cond_or_thumb (void) | |
5287ad62 | 13873 | { |
88714cb8 DG |
13874 | inst.is_neon = 1; |
13875 | ||
5287ad62 | 13876 | if (thumb_mode) |
037e8744 | 13877 | inst.instruction |= 0xe0000000; |
5287ad62 | 13878 | else |
037e8744 | 13879 | inst.instruction |= inst.cond << 28; |
5287ad62 JB |
13880 | } |
13881 | ||
037e8744 JB |
13882 | /* Look up and encode a simple mnemonic, for use as a helper function for the |
13883 | Neon-style VFP syntax. This avoids duplication of bits of the insns table, | |
13884 | etc. It is assumed that operand parsing has already been done, and that the | |
13885 | operands are in the form expected by the given opcode (this isn't necessarily | |
13886 | the same as the form in which they were parsed, hence some massaging must | |
13887 | take place before this function is called). | |
13888 | Checks current arch version against that in the looked-up opcode. */ | |
5287ad62 | 13889 | |
037e8744 JB |
13890 | static void |
13891 | do_vfp_nsyn_opcode (const char *opname) | |
5287ad62 | 13892 | { |
037e8744 | 13893 | const struct asm_opcode *opcode; |
5f4273c7 | 13894 | |
21d799b5 | 13895 | opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname); |
5287ad62 | 13896 | |
037e8744 JB |
13897 | if (!opcode) |
13898 | abort (); | |
5287ad62 | 13899 | |
037e8744 | 13900 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, |
477330fc RM |
13901 | thumb_mode ? *opcode->tvariant : *opcode->avariant), |
13902 | _(BAD_FPU)); | |
5287ad62 | 13903 | |
88714cb8 DG |
13904 | inst.is_neon = 1; |
13905 | ||
037e8744 JB |
13906 | if (thumb_mode) |
13907 | { | |
13908 | inst.instruction = opcode->tvalue; | |
13909 | opcode->tencode (); | |
13910 | } | |
13911 | else | |
13912 | { | |
13913 | inst.instruction = (inst.cond << 28) | opcode->avalue; | |
13914 | opcode->aencode (); | |
13915 | } | |
13916 | } | |
5287ad62 JB |
13917 | |
13918 | static void | |
037e8744 | 13919 | do_vfp_nsyn_add_sub (enum neon_shape rs) |
5287ad62 | 13920 | { |
037e8744 JB |
13921 | int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd; |
13922 | ||
13923 | if (rs == NS_FFF) | |
13924 | { | |
13925 | if (is_add) | |
477330fc | 13926 | do_vfp_nsyn_opcode ("fadds"); |
037e8744 | 13927 | else |
477330fc | 13928 | do_vfp_nsyn_opcode ("fsubs"); |
037e8744 JB |
13929 | } |
13930 | else | |
13931 | { | |
13932 | if (is_add) | |
477330fc | 13933 | do_vfp_nsyn_opcode ("faddd"); |
037e8744 | 13934 | else |
477330fc | 13935 | do_vfp_nsyn_opcode ("fsubd"); |
037e8744 JB |
13936 | } |
13937 | } | |
13938 | ||
13939 | /* Check operand types to see if this is a VFP instruction, and if so call | |
13940 | PFN (). */ | |
13941 | ||
13942 | static int | |
13943 | try_vfp_nsyn (int args, void (*pfn) (enum neon_shape)) | |
13944 | { | |
13945 | enum neon_shape rs; | |
13946 | struct neon_type_el et; | |
13947 | ||
13948 | switch (args) | |
13949 | { | |
13950 | case 2: | |
13951 | rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
13952 | et = neon_check_type (2, rs, | |
477330fc | 13953 | N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); |
037e8744 | 13954 | break; |
5f4273c7 | 13955 | |
037e8744 JB |
13956 | case 3: |
13957 | rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
13958 | et = neon_check_type (3, rs, | |
477330fc | 13959 | N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); |
037e8744 JB |
13960 | break; |
13961 | ||
13962 | default: | |
13963 | abort (); | |
13964 | } | |
13965 | ||
13966 | if (et.type != NT_invtype) | |
13967 | { | |
13968 | pfn (rs); | |
13969 | return SUCCESS; | |
13970 | } | |
037e8744 | 13971 | |
99b253c5 | 13972 | inst.error = NULL; |
037e8744 JB |
13973 | return FAIL; |
13974 | } | |
13975 | ||
13976 | static void | |
13977 | do_vfp_nsyn_mla_mls (enum neon_shape rs) | |
13978 | { | |
13979 | int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla; | |
5f4273c7 | 13980 | |
037e8744 JB |
13981 | if (rs == NS_FFF) |
13982 | { | |
13983 | if (is_mla) | |
477330fc | 13984 | do_vfp_nsyn_opcode ("fmacs"); |
037e8744 | 13985 | else |
477330fc | 13986 | do_vfp_nsyn_opcode ("fnmacs"); |
037e8744 JB |
13987 | } |
13988 | else | |
13989 | { | |
13990 | if (is_mla) | |
477330fc | 13991 | do_vfp_nsyn_opcode ("fmacd"); |
037e8744 | 13992 | else |
477330fc | 13993 | do_vfp_nsyn_opcode ("fnmacd"); |
037e8744 JB |
13994 | } |
13995 | } | |
13996 | ||
62f3b8c8 PB |
13997 | static void |
13998 | do_vfp_nsyn_fma_fms (enum neon_shape rs) | |
13999 | { | |
14000 | int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma; | |
14001 | ||
14002 | if (rs == NS_FFF) | |
14003 | { | |
14004 | if (is_fma) | |
477330fc | 14005 | do_vfp_nsyn_opcode ("ffmas"); |
62f3b8c8 | 14006 | else |
477330fc | 14007 | do_vfp_nsyn_opcode ("ffnmas"); |
62f3b8c8 PB |
14008 | } |
14009 | else | |
14010 | { | |
14011 | if (is_fma) | |
477330fc | 14012 | do_vfp_nsyn_opcode ("ffmad"); |
62f3b8c8 | 14013 | else |
477330fc | 14014 | do_vfp_nsyn_opcode ("ffnmad"); |
62f3b8c8 PB |
14015 | } |
14016 | } | |
14017 | ||
037e8744 JB |
14018 | static void |
14019 | do_vfp_nsyn_mul (enum neon_shape rs) | |
14020 | { | |
14021 | if (rs == NS_FFF) | |
14022 | do_vfp_nsyn_opcode ("fmuls"); | |
14023 | else | |
14024 | do_vfp_nsyn_opcode ("fmuld"); | |
14025 | } | |
14026 | ||
14027 | static void | |
14028 | do_vfp_nsyn_abs_neg (enum neon_shape rs) | |
14029 | { | |
14030 | int is_neg = (inst.instruction & 0x80) != 0; | |
14031 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY); | |
14032 | ||
14033 | if (rs == NS_FF) | |
14034 | { | |
14035 | if (is_neg) | |
477330fc | 14036 | do_vfp_nsyn_opcode ("fnegs"); |
037e8744 | 14037 | else |
477330fc | 14038 | do_vfp_nsyn_opcode ("fabss"); |
037e8744 JB |
14039 | } |
14040 | else | |
14041 | { | |
14042 | if (is_neg) | |
477330fc | 14043 | do_vfp_nsyn_opcode ("fnegd"); |
037e8744 | 14044 | else |
477330fc | 14045 | do_vfp_nsyn_opcode ("fabsd"); |
037e8744 JB |
14046 | } |
14047 | } | |
14048 | ||
14049 | /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision | |
14050 | insns belong to Neon, and are handled elsewhere. */ | |
14051 | ||
14052 | static void | |
14053 | do_vfp_nsyn_ldm_stm (int is_dbmode) | |
14054 | { | |
14055 | int is_ldm = (inst.instruction & (1 << 20)) != 0; | |
14056 | if (is_ldm) | |
14057 | { | |
14058 | if (is_dbmode) | |
477330fc | 14059 | do_vfp_nsyn_opcode ("fldmdbs"); |
037e8744 | 14060 | else |
477330fc | 14061 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 JB |
14062 | } |
14063 | else | |
14064 | { | |
14065 | if (is_dbmode) | |
477330fc | 14066 | do_vfp_nsyn_opcode ("fstmdbs"); |
037e8744 | 14067 | else |
477330fc | 14068 | do_vfp_nsyn_opcode ("fstmias"); |
037e8744 JB |
14069 | } |
14070 | } | |
14071 | ||
037e8744 JB |
14072 | static void |
14073 | do_vfp_nsyn_sqrt (void) | |
14074 | { | |
14075 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
14076 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 14077 | |
037e8744 JB |
14078 | if (rs == NS_FF) |
14079 | do_vfp_nsyn_opcode ("fsqrts"); | |
14080 | else | |
14081 | do_vfp_nsyn_opcode ("fsqrtd"); | |
14082 | } | |
14083 | ||
14084 | static void | |
14085 | do_vfp_nsyn_div (void) | |
14086 | { | |
14087 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
14088 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
14089 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 14090 | |
037e8744 JB |
14091 | if (rs == NS_FFF) |
14092 | do_vfp_nsyn_opcode ("fdivs"); | |
14093 | else | |
14094 | do_vfp_nsyn_opcode ("fdivd"); | |
14095 | } | |
14096 | ||
14097 | static void | |
14098 | do_vfp_nsyn_nmul (void) | |
14099 | { | |
14100 | enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL); | |
14101 | neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP, | |
14102 | N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 14103 | |
037e8744 JB |
14104 | if (rs == NS_FFF) |
14105 | { | |
88714cb8 | 14106 | NEON_ENCODE (SINGLE, inst); |
037e8744 JB |
14107 | do_vfp_sp_dyadic (); |
14108 | } | |
14109 | else | |
14110 | { | |
88714cb8 | 14111 | NEON_ENCODE (DOUBLE, inst); |
037e8744 JB |
14112 | do_vfp_dp_rd_rn_rm (); |
14113 | } | |
14114 | do_vfp_cond_or_thumb (); | |
14115 | } | |
14116 | ||
14117 | static void | |
14118 | do_vfp_nsyn_cmp (void) | |
14119 | { | |
14120 | if (inst.operands[1].isreg) | |
14121 | { | |
14122 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL); | |
14123 | neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); | |
5f4273c7 | 14124 | |
037e8744 | 14125 | if (rs == NS_FF) |
477330fc RM |
14126 | { |
14127 | NEON_ENCODE (SINGLE, inst); | |
14128 | do_vfp_sp_monadic (); | |
14129 | } | |
037e8744 | 14130 | else |
477330fc RM |
14131 | { |
14132 | NEON_ENCODE (DOUBLE, inst); | |
14133 | do_vfp_dp_rd_rm (); | |
14134 | } | |
037e8744 JB |
14135 | } |
14136 | else | |
14137 | { | |
14138 | enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL); | |
14139 | neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK); | |
14140 | ||
14141 | switch (inst.instruction & 0x0fffffff) | |
477330fc RM |
14142 | { |
14143 | case N_MNEM_vcmp: | |
14144 | inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp; | |
14145 | break; | |
14146 | case N_MNEM_vcmpe: | |
14147 | inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe; | |
14148 | break; | |
14149 | default: | |
14150 | abort (); | |
14151 | } | |
5f4273c7 | 14152 | |
037e8744 | 14153 | if (rs == NS_FI) |
477330fc RM |
14154 | { |
14155 | NEON_ENCODE (SINGLE, inst); | |
14156 | do_vfp_sp_compare_z (); | |
14157 | } | |
037e8744 | 14158 | else |
477330fc RM |
14159 | { |
14160 | NEON_ENCODE (DOUBLE, inst); | |
14161 | do_vfp_dp_rd (); | |
14162 | } | |
037e8744 JB |
14163 | } |
14164 | do_vfp_cond_or_thumb (); | |
14165 | } | |
14166 | ||
14167 | static void | |
14168 | nsyn_insert_sp (void) | |
14169 | { | |
14170 | inst.operands[1] = inst.operands[0]; | |
14171 | memset (&inst.operands[0], '\0', sizeof (inst.operands[0])); | |
fdfde340 | 14172 | inst.operands[0].reg = REG_SP; |
037e8744 JB |
14173 | inst.operands[0].isreg = 1; |
14174 | inst.operands[0].writeback = 1; | |
14175 | inst.operands[0].present = 1; | |
14176 | } | |
14177 | ||
14178 | static void | |
14179 | do_vfp_nsyn_push (void) | |
14180 | { | |
14181 | nsyn_insert_sp (); | |
14182 | if (inst.operands[1].issingle) | |
14183 | do_vfp_nsyn_opcode ("fstmdbs"); | |
14184 | else | |
14185 | do_vfp_nsyn_opcode ("fstmdbd"); | |
14186 | } | |
14187 | ||
14188 | static void | |
14189 | do_vfp_nsyn_pop (void) | |
14190 | { | |
14191 | nsyn_insert_sp (); | |
14192 | if (inst.operands[1].issingle) | |
22b5b651 | 14193 | do_vfp_nsyn_opcode ("fldmias"); |
037e8744 | 14194 | else |
22b5b651 | 14195 | do_vfp_nsyn_opcode ("fldmiad"); |
037e8744 JB |
14196 | } |
14197 | ||
14198 | /* Fix up Neon data-processing instructions, ORing in the correct bits for | |
14199 | ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */ | |
14200 | ||
88714cb8 DG |
14201 | static void |
14202 | neon_dp_fixup (struct arm_it* insn) | |
037e8744 | 14203 | { |
88714cb8 DG |
14204 | unsigned int i = insn->instruction; |
14205 | insn->is_neon = 1; | |
14206 | ||
037e8744 JB |
14207 | if (thumb_mode) |
14208 | { | |
14209 | /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */ | |
14210 | if (i & (1 << 24)) | |
477330fc | 14211 | i |= 1 << 28; |
5f4273c7 | 14212 | |
037e8744 | 14213 | i &= ~(1 << 24); |
5f4273c7 | 14214 | |
037e8744 JB |
14215 | i |= 0xef000000; |
14216 | } | |
14217 | else | |
14218 | i |= 0xf2000000; | |
5f4273c7 | 14219 | |
88714cb8 | 14220 | insn->instruction = i; |
037e8744 JB |
14221 | } |
14222 | ||
14223 | /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3 | |
14224 | (0, 1, 2, 3). */ | |
14225 | ||
14226 | static unsigned | |
14227 | neon_logbits (unsigned x) | |
14228 | { | |
14229 | return ffs (x) - 4; | |
14230 | } | |
14231 | ||
14232 | #define LOW4(R) ((R) & 0xf) | |
14233 | #define HI1(R) (((R) >> 4) & 1) | |
14234 | ||
14235 | /* Encode insns with bit pattern: | |
14236 | ||
14237 | |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
14238 | | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm | | |
5f4273c7 | 14239 | |
037e8744 JB |
14240 | SIZE is passed in bits. -1 means size field isn't changed, in case it has a |
14241 | different meaning for some instruction. */ | |
14242 | ||
14243 | static void | |
14244 | neon_three_same (int isquad, int ubit, int size) | |
14245 | { | |
14246 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14247 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14248 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14249 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14250 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
14251 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
14252 | inst.instruction |= (isquad != 0) << 6; | |
14253 | inst.instruction |= (ubit != 0) << 24; | |
14254 | if (size != -1) | |
14255 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 14256 | |
88714cb8 | 14257 | neon_dp_fixup (&inst); |
037e8744 JB |
14258 | } |
14259 | ||
14260 | /* Encode instructions of the form: | |
14261 | ||
14262 | |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0| | |
14263 | | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm | | |
5287ad62 JB |
14264 | |
14265 | Don't write size if SIZE == -1. */ | |
14266 | ||
14267 | static void | |
14268 | neon_two_same (int qbit, int ubit, int size) | |
14269 | { | |
14270 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14271 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14272 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14273 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14274 | inst.instruction |= (qbit != 0) << 6; | |
14275 | inst.instruction |= (ubit != 0) << 24; | |
14276 | ||
14277 | if (size != -1) | |
14278 | inst.instruction |= neon_logbits (size) << 18; | |
14279 | ||
88714cb8 | 14280 | neon_dp_fixup (&inst); |
5287ad62 JB |
14281 | } |
14282 | ||
14283 | /* Neon instruction encoders, in approximate order of appearance. */ | |
14284 | ||
14285 | static void | |
14286 | do_neon_dyadic_i_su (void) | |
14287 | { | |
037e8744 | 14288 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14289 | struct neon_type_el et = neon_check_type (3, rs, |
14290 | N_EQK, N_EQK, N_SU_32 | N_KEY); | |
037e8744 | 14291 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14292 | } |
14293 | ||
14294 | static void | |
14295 | do_neon_dyadic_i64_su (void) | |
14296 | { | |
037e8744 | 14297 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14298 | struct neon_type_el et = neon_check_type (3, rs, |
14299 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
037e8744 | 14300 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14301 | } |
14302 | ||
14303 | static void | |
14304 | neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et, | |
477330fc | 14305 | unsigned immbits) |
5287ad62 JB |
14306 | { |
14307 | unsigned size = et.size >> 3; | |
14308 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
14309 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14310 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14311 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
14312 | inst.instruction |= (isquad != 0) << 6; | |
14313 | inst.instruction |= immbits << 16; | |
14314 | inst.instruction |= (size >> 3) << 7; | |
14315 | inst.instruction |= (size & 0x7) << 19; | |
14316 | if (write_ubit) | |
14317 | inst.instruction |= (uval != 0) << 24; | |
14318 | ||
88714cb8 | 14319 | neon_dp_fixup (&inst); |
5287ad62 JB |
14320 | } |
14321 | ||
14322 | static void | |
14323 | do_neon_shl_imm (void) | |
14324 | { | |
14325 | if (!inst.operands[2].isreg) | |
14326 | { | |
037e8744 | 14327 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 14328 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL); |
cb3b1e65 JB |
14329 | int imm = inst.operands[2].imm; |
14330 | ||
14331 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
14332 | _("immediate out of range for shift")); | |
88714cb8 | 14333 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 14334 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14335 | } |
14336 | else | |
14337 | { | |
037e8744 | 14338 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14339 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14340 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
14341 | unsigned int tmp; |
14342 | ||
14343 | /* VSHL/VQSHL 3-register variants have syntax such as: | |
477330fc RM |
14344 | vshl.xx Dd, Dm, Dn |
14345 | whereas other 3-register operations encoded by neon_three_same have | |
14346 | syntax like: | |
14347 | vadd.xx Dd, Dn, Dm | |
14348 | (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg | |
14349 | here. */ | |
627907b7 JB |
14350 | tmp = inst.operands[2].reg; |
14351 | inst.operands[2].reg = inst.operands[1].reg; | |
14352 | inst.operands[1].reg = tmp; | |
88714cb8 | 14353 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14354 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14355 | } |
14356 | } | |
14357 | ||
14358 | static void | |
14359 | do_neon_qshl_imm (void) | |
14360 | { | |
14361 | if (!inst.operands[2].isreg) | |
14362 | { | |
037e8744 | 14363 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 | 14364 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
cb3b1e65 | 14365 | int imm = inst.operands[2].imm; |
627907b7 | 14366 | |
cb3b1e65 JB |
14367 | constraint (imm < 0 || (unsigned)imm >= et.size, |
14368 | _("immediate out of range for shift")); | |
88714cb8 | 14369 | NEON_ENCODE (IMMED, inst); |
cb3b1e65 | 14370 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm); |
5287ad62 JB |
14371 | } |
14372 | else | |
14373 | { | |
037e8744 | 14374 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14375 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14376 | N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN); |
627907b7 JB |
14377 | unsigned int tmp; |
14378 | ||
14379 | /* See note in do_neon_shl_imm. */ | |
14380 | tmp = inst.operands[2].reg; | |
14381 | inst.operands[2].reg = inst.operands[1].reg; | |
14382 | inst.operands[1].reg = tmp; | |
88714cb8 | 14383 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14384 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); |
5287ad62 JB |
14385 | } |
14386 | } | |
14387 | ||
627907b7 JB |
14388 | static void |
14389 | do_neon_rshl (void) | |
14390 | { | |
14391 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); | |
14392 | struct neon_type_el et = neon_check_type (3, rs, | |
14393 | N_EQK, N_EQK, N_SU_ALL | N_KEY); | |
14394 | unsigned int tmp; | |
14395 | ||
14396 | tmp = inst.operands[2].reg; | |
14397 | inst.operands[2].reg = inst.operands[1].reg; | |
14398 | inst.operands[1].reg = tmp; | |
14399 | neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size); | |
14400 | } | |
14401 | ||
5287ad62 JB |
14402 | static int |
14403 | neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size) | |
14404 | { | |
036dc3f7 PB |
14405 | /* Handle .I8 pseudo-instructions. */ |
14406 | if (size == 8) | |
5287ad62 | 14407 | { |
5287ad62 | 14408 | /* Unfortunately, this will make everything apart from zero out-of-range. |
477330fc RM |
14409 | FIXME is this the intended semantics? There doesn't seem much point in |
14410 | accepting .I8 if so. */ | |
5287ad62 JB |
14411 | immediate |= immediate << 8; |
14412 | size = 16; | |
036dc3f7 PB |
14413 | } |
14414 | ||
14415 | if (size >= 32) | |
14416 | { | |
14417 | if (immediate == (immediate & 0x000000ff)) | |
14418 | { | |
14419 | *immbits = immediate; | |
14420 | return 0x1; | |
14421 | } | |
14422 | else if (immediate == (immediate & 0x0000ff00)) | |
14423 | { | |
14424 | *immbits = immediate >> 8; | |
14425 | return 0x3; | |
14426 | } | |
14427 | else if (immediate == (immediate & 0x00ff0000)) | |
14428 | { | |
14429 | *immbits = immediate >> 16; | |
14430 | return 0x5; | |
14431 | } | |
14432 | else if (immediate == (immediate & 0xff000000)) | |
14433 | { | |
14434 | *immbits = immediate >> 24; | |
14435 | return 0x7; | |
14436 | } | |
14437 | if ((immediate & 0xffff) != (immediate >> 16)) | |
14438 | goto bad_immediate; | |
14439 | immediate &= 0xffff; | |
5287ad62 JB |
14440 | } |
14441 | ||
14442 | if (immediate == (immediate & 0x000000ff)) | |
14443 | { | |
14444 | *immbits = immediate; | |
036dc3f7 | 14445 | return 0x9; |
5287ad62 JB |
14446 | } |
14447 | else if (immediate == (immediate & 0x0000ff00)) | |
14448 | { | |
14449 | *immbits = immediate >> 8; | |
036dc3f7 | 14450 | return 0xb; |
5287ad62 JB |
14451 | } |
14452 | ||
14453 | bad_immediate: | |
dcbf9037 | 14454 | first_error (_("immediate value out of range")); |
5287ad62 JB |
14455 | return FAIL; |
14456 | } | |
14457 | ||
5287ad62 JB |
14458 | static void |
14459 | do_neon_logic (void) | |
14460 | { | |
14461 | if (inst.operands[2].present && inst.operands[2].isreg) | |
14462 | { | |
037e8744 | 14463 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14464 | neon_check_type (3, rs, N_IGNORE_TYPE); |
14465 | /* U bit and size field were set as part of the bitmask. */ | |
88714cb8 | 14466 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14467 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14468 | } |
14469 | else | |
14470 | { | |
4316f0d2 DG |
14471 | const int three_ops_form = (inst.operands[2].present |
14472 | && !inst.operands[2].isreg); | |
14473 | const int immoperand = (three_ops_form ? 2 : 1); | |
14474 | enum neon_shape rs = (three_ops_form | |
14475 | ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL) | |
14476 | : neon_select_shape (NS_DI, NS_QI, NS_NULL)); | |
037e8744 | 14477 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 14478 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); |
21d799b5 | 14479 | enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff; |
5287ad62 JB |
14480 | unsigned immbits; |
14481 | int cmode; | |
5f4273c7 | 14482 | |
5287ad62 | 14483 | if (et.type == NT_invtype) |
477330fc | 14484 | return; |
5f4273c7 | 14485 | |
4316f0d2 DG |
14486 | if (three_ops_form) |
14487 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
14488 | _("first and second operands shall be the same register")); | |
14489 | ||
88714cb8 | 14490 | NEON_ENCODE (IMMED, inst); |
5287ad62 | 14491 | |
4316f0d2 | 14492 | immbits = inst.operands[immoperand].imm; |
036dc3f7 PB |
14493 | if (et.size == 64) |
14494 | { | |
14495 | /* .i64 is a pseudo-op, so the immediate must be a repeating | |
14496 | pattern. */ | |
4316f0d2 DG |
14497 | if (immbits != (inst.operands[immoperand].regisimm ? |
14498 | inst.operands[immoperand].reg : 0)) | |
036dc3f7 PB |
14499 | { |
14500 | /* Set immbits to an invalid constant. */ | |
14501 | immbits = 0xdeadbeef; | |
14502 | } | |
14503 | } | |
14504 | ||
5287ad62 | 14505 | switch (opcode) |
477330fc RM |
14506 | { |
14507 | case N_MNEM_vbic: | |
14508 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14509 | break; | |
14510 | ||
14511 | case N_MNEM_vorr: | |
14512 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14513 | break; | |
14514 | ||
14515 | case N_MNEM_vand: | |
14516 | /* Pseudo-instruction for VBIC. */ | |
14517 | neon_invert_size (&immbits, 0, et.size); | |
14518 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14519 | break; | |
14520 | ||
14521 | case N_MNEM_vorn: | |
14522 | /* Pseudo-instruction for VORR. */ | |
14523 | neon_invert_size (&immbits, 0, et.size); | |
14524 | cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size); | |
14525 | break; | |
14526 | ||
14527 | default: | |
14528 | abort (); | |
14529 | } | |
5287ad62 JB |
14530 | |
14531 | if (cmode == FAIL) | |
477330fc | 14532 | return; |
5287ad62 | 14533 | |
037e8744 | 14534 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14535 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14536 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14537 | inst.instruction |= cmode << 8; | |
14538 | neon_write_immbits (immbits); | |
5f4273c7 | 14539 | |
88714cb8 | 14540 | neon_dp_fixup (&inst); |
5287ad62 JB |
14541 | } |
14542 | } | |
14543 | ||
14544 | static void | |
14545 | do_neon_bitfield (void) | |
14546 | { | |
037e8744 | 14547 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 14548 | neon_check_type (3, rs, N_IGNORE_TYPE); |
037e8744 | 14549 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14550 | } |
14551 | ||
14552 | static void | |
dcbf9037 | 14553 | neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types, |
477330fc | 14554 | unsigned destbits) |
5287ad62 | 14555 | { |
037e8744 | 14556 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
dcbf9037 | 14557 | struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK, |
477330fc | 14558 | types | N_KEY); |
5287ad62 JB |
14559 | if (et.type == NT_float) |
14560 | { | |
88714cb8 | 14561 | NEON_ENCODE (FLOAT, inst); |
037e8744 | 14562 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14563 | } |
14564 | else | |
14565 | { | |
88714cb8 | 14566 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 14567 | neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size); |
5287ad62 JB |
14568 | } |
14569 | } | |
14570 | ||
14571 | static void | |
14572 | do_neon_dyadic_if_su (void) | |
14573 | { | |
dcbf9037 | 14574 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
14575 | } |
14576 | ||
14577 | static void | |
14578 | do_neon_dyadic_if_su_d (void) | |
14579 | { | |
14580 | /* This version only allow D registers, but that constraint is enforced during | |
14581 | operand parsing so we don't need to do anything extra here. */ | |
dcbf9037 | 14582 | neon_dyadic_misc (NT_unsigned, N_SUF_32, 0); |
5287ad62 JB |
14583 | } |
14584 | ||
5287ad62 JB |
14585 | static void |
14586 | do_neon_dyadic_if_i_d (void) | |
14587 | { | |
428e3f1f PB |
14588 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
14589 | affected if we specify unsigned args. */ | |
14590 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
5287ad62 JB |
14591 | } |
14592 | ||
037e8744 JB |
14593 | enum vfp_or_neon_is_neon_bits |
14594 | { | |
14595 | NEON_CHECK_CC = 1, | |
73924fbc MGD |
14596 | NEON_CHECK_ARCH = 2, |
14597 | NEON_CHECK_ARCH8 = 4 | |
037e8744 JB |
14598 | }; |
14599 | ||
14600 | /* Call this function if an instruction which may have belonged to the VFP or | |
14601 | Neon instruction sets, but turned out to be a Neon instruction (due to the | |
14602 | operand types involved, etc.). We have to check and/or fix-up a couple of | |
14603 | things: | |
14604 | ||
14605 | - Make sure the user hasn't attempted to make a Neon instruction | |
14606 | conditional. | |
14607 | - Alter the value in the condition code field if necessary. | |
14608 | - Make sure that the arch supports Neon instructions. | |
14609 | ||
14610 | Which of these operations take place depends on bits from enum | |
14611 | vfp_or_neon_is_neon_bits. | |
14612 | ||
14613 | WARNING: This function has side effects! If NEON_CHECK_CC is used and the | |
14614 | current instruction's condition is COND_ALWAYS, the condition field is | |
14615 | changed to inst.uncond_value. This is necessary because instructions shared | |
14616 | between VFP and Neon may be conditional for the VFP variants only, and the | |
14617 | unconditional Neon version must have, e.g., 0xF in the condition field. */ | |
14618 | ||
14619 | static int | |
14620 | vfp_or_neon_is_neon (unsigned check) | |
14621 | { | |
14622 | /* Conditions are always legal in Thumb mode (IT blocks). */ | |
14623 | if (!thumb_mode && (check & NEON_CHECK_CC)) | |
14624 | { | |
14625 | if (inst.cond != COND_ALWAYS) | |
477330fc RM |
14626 | { |
14627 | first_error (_(BAD_COND)); | |
14628 | return FAIL; | |
14629 | } | |
037e8744 | 14630 | if (inst.uncond_value != -1) |
477330fc | 14631 | inst.instruction |= inst.uncond_value << 28; |
037e8744 | 14632 | } |
5f4273c7 | 14633 | |
037e8744 | 14634 | if ((check & NEON_CHECK_ARCH) |
73924fbc MGD |
14635 | && !mark_feature_used (&fpu_neon_ext_v1)) |
14636 | { | |
14637 | first_error (_(BAD_FPU)); | |
14638 | return FAIL; | |
14639 | } | |
14640 | ||
14641 | if ((check & NEON_CHECK_ARCH8) | |
14642 | && !mark_feature_used (&fpu_neon_ext_armv8)) | |
037e8744 JB |
14643 | { |
14644 | first_error (_(BAD_FPU)); | |
14645 | return FAIL; | |
14646 | } | |
5f4273c7 | 14647 | |
037e8744 JB |
14648 | return SUCCESS; |
14649 | } | |
14650 | ||
5287ad62 JB |
14651 | static void |
14652 | do_neon_addsub_if_i (void) | |
14653 | { | |
037e8744 JB |
14654 | if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS) |
14655 | return; | |
14656 | ||
14657 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14658 | return; | |
14659 | ||
5287ad62 JB |
14660 | /* The "untyped" case can't happen. Do this to stop the "U" bit being |
14661 | affected if we specify unsigned args. */ | |
dcbf9037 | 14662 | neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0); |
5287ad62 JB |
14663 | } |
14664 | ||
14665 | /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the | |
14666 | result to be: | |
14667 | V<op> A,B (A is operand 0, B is operand 2) | |
14668 | to mean: | |
14669 | V<op> A,B,A | |
14670 | not: | |
14671 | V<op> A,B,B | |
14672 | so handle that case specially. */ | |
14673 | ||
14674 | static void | |
14675 | neon_exchange_operands (void) | |
14676 | { | |
14677 | void *scratch = alloca (sizeof (inst.operands[0])); | |
14678 | if (inst.operands[1].present) | |
14679 | { | |
14680 | /* Swap operands[1] and operands[2]. */ | |
14681 | memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0])); | |
14682 | inst.operands[1] = inst.operands[2]; | |
14683 | memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0])); | |
14684 | } | |
14685 | else | |
14686 | { | |
14687 | inst.operands[1] = inst.operands[2]; | |
14688 | inst.operands[2] = inst.operands[0]; | |
14689 | } | |
14690 | } | |
14691 | ||
14692 | static void | |
14693 | neon_compare (unsigned regtypes, unsigned immtypes, int invert) | |
14694 | { | |
14695 | if (inst.operands[2].isreg) | |
14696 | { | |
14697 | if (invert) | |
477330fc | 14698 | neon_exchange_operands (); |
dcbf9037 | 14699 | neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ); |
5287ad62 JB |
14700 | } |
14701 | else | |
14702 | { | |
037e8744 | 14703 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
dcbf9037 | 14704 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 14705 | N_EQK | N_SIZ, immtypes | N_KEY); |
5287ad62 | 14706 | |
88714cb8 | 14707 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
14708 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14709 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14710 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14711 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 14712 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14713 | inst.instruction |= (et.type == NT_float) << 10; |
14714 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 14715 | |
88714cb8 | 14716 | neon_dp_fixup (&inst); |
5287ad62 JB |
14717 | } |
14718 | } | |
14719 | ||
14720 | static void | |
14721 | do_neon_cmp (void) | |
14722 | { | |
14723 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE); | |
14724 | } | |
14725 | ||
14726 | static void | |
14727 | do_neon_cmp_inv (void) | |
14728 | { | |
14729 | neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE); | |
14730 | } | |
14731 | ||
14732 | static void | |
14733 | do_neon_ceq (void) | |
14734 | { | |
14735 | neon_compare (N_IF_32, N_IF_32, FALSE); | |
14736 | } | |
14737 | ||
14738 | /* For multiply instructions, we have the possibility of 16-bit or 32-bit | |
14739 | scalars, which are encoded in 5 bits, M : Rm. | |
14740 | For 16-bit scalars, the register is encoded in Rm[2:0] and the index in | |
14741 | M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the | |
14742 | index in M. */ | |
14743 | ||
14744 | static unsigned | |
14745 | neon_scalar_for_mul (unsigned scalar, unsigned elsize) | |
14746 | { | |
dcbf9037 JB |
14747 | unsigned regno = NEON_SCALAR_REG (scalar); |
14748 | unsigned elno = NEON_SCALAR_INDEX (scalar); | |
5287ad62 JB |
14749 | |
14750 | switch (elsize) | |
14751 | { | |
14752 | case 16: | |
14753 | if (regno > 7 || elno > 3) | |
477330fc | 14754 | goto bad_scalar; |
5287ad62 | 14755 | return regno | (elno << 3); |
5f4273c7 | 14756 | |
5287ad62 JB |
14757 | case 32: |
14758 | if (regno > 15 || elno > 1) | |
477330fc | 14759 | goto bad_scalar; |
5287ad62 JB |
14760 | return regno | (elno << 4); |
14761 | ||
14762 | default: | |
14763 | bad_scalar: | |
dcbf9037 | 14764 | first_error (_("scalar out of range for multiply instruction")); |
5287ad62 JB |
14765 | } |
14766 | ||
14767 | return 0; | |
14768 | } | |
14769 | ||
14770 | /* Encode multiply / multiply-accumulate scalar instructions. */ | |
14771 | ||
14772 | static void | |
14773 | neon_mul_mac (struct neon_type_el et, int ubit) | |
14774 | { | |
dcbf9037 JB |
14775 | unsigned scalar; |
14776 | ||
14777 | /* Give a more helpful error message if we have an invalid type. */ | |
14778 | if (et.type == NT_invtype) | |
14779 | return; | |
5f4273c7 | 14780 | |
dcbf9037 | 14781 | scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size); |
5287ad62 JB |
14782 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14783 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14784 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
14785 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
14786 | inst.instruction |= LOW4 (scalar); | |
14787 | inst.instruction |= HI1 (scalar) << 5; | |
14788 | inst.instruction |= (et.type == NT_float) << 8; | |
14789 | inst.instruction |= neon_logbits (et.size) << 20; | |
14790 | inst.instruction |= (ubit != 0) << 24; | |
14791 | ||
88714cb8 | 14792 | neon_dp_fixup (&inst); |
5287ad62 JB |
14793 | } |
14794 | ||
14795 | static void | |
14796 | do_neon_mac_maybe_scalar (void) | |
14797 | { | |
037e8744 JB |
14798 | if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS) |
14799 | return; | |
14800 | ||
14801 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14802 | return; | |
14803 | ||
5287ad62 JB |
14804 | if (inst.operands[2].isscalar) |
14805 | { | |
037e8744 | 14806 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 14807 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14808 | N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY); |
88714cb8 | 14809 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 14810 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
14811 | } |
14812 | else | |
428e3f1f PB |
14813 | { |
14814 | /* The "untyped" case can't happen. Do this to stop the "U" bit being | |
14815 | affected if we specify unsigned args. */ | |
14816 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
14817 | } | |
5287ad62 JB |
14818 | } |
14819 | ||
62f3b8c8 PB |
14820 | static void |
14821 | do_neon_fmac (void) | |
14822 | { | |
14823 | if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS) | |
14824 | return; | |
14825 | ||
14826 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14827 | return; | |
14828 | ||
14829 | neon_dyadic_misc (NT_untyped, N_IF_32, 0); | |
14830 | } | |
14831 | ||
5287ad62 JB |
14832 | static void |
14833 | do_neon_tst (void) | |
14834 | { | |
037e8744 | 14835 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14836 | struct neon_type_el et = neon_check_type (3, rs, |
14837 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
037e8744 | 14838 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
14839 | } |
14840 | ||
14841 | /* VMUL with 3 registers allows the P8 type. The scalar version supports the | |
14842 | same types as the MAC equivalents. The polynomial type for this instruction | |
14843 | is encoded the same as the integer type. */ | |
14844 | ||
14845 | static void | |
14846 | do_neon_mul (void) | |
14847 | { | |
037e8744 JB |
14848 | if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS) |
14849 | return; | |
14850 | ||
14851 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14852 | return; | |
14853 | ||
5287ad62 JB |
14854 | if (inst.operands[2].isscalar) |
14855 | do_neon_mac_maybe_scalar (); | |
14856 | else | |
dcbf9037 | 14857 | neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0); |
5287ad62 JB |
14858 | } |
14859 | ||
14860 | static void | |
14861 | do_neon_qdmulh (void) | |
14862 | { | |
14863 | if (inst.operands[2].isscalar) | |
14864 | { | |
037e8744 | 14865 | enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL); |
5287ad62 | 14866 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14867 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 14868 | NEON_ENCODE (SCALAR, inst); |
037e8744 | 14869 | neon_mul_mac (et, neon_quad (rs)); |
5287ad62 JB |
14870 | } |
14871 | else | |
14872 | { | |
037e8744 | 14873 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14874 | struct neon_type_el et = neon_check_type (3, rs, |
477330fc | 14875 | N_EQK, N_EQK, N_S16 | N_S32 | N_KEY); |
88714cb8 | 14876 | NEON_ENCODE (INTEGER, inst); |
5287ad62 | 14877 | /* The U bit (rounding) comes from bit mask. */ |
037e8744 | 14878 | neon_three_same (neon_quad (rs), 0, et.size); |
5287ad62 JB |
14879 | } |
14880 | } | |
14881 | ||
14882 | static void | |
14883 | do_neon_fcmp_absolute (void) | |
14884 | { | |
037e8744 | 14885 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 JB |
14886 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
14887 | /* Size field comes from bit mask. */ | |
037e8744 | 14888 | neon_three_same (neon_quad (rs), 1, -1); |
5287ad62 JB |
14889 | } |
14890 | ||
14891 | static void | |
14892 | do_neon_fcmp_absolute_inv (void) | |
14893 | { | |
14894 | neon_exchange_operands (); | |
14895 | do_neon_fcmp_absolute (); | |
14896 | } | |
14897 | ||
14898 | static void | |
14899 | do_neon_step (void) | |
14900 | { | |
037e8744 | 14901 | enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL); |
5287ad62 | 14902 | neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY); |
037e8744 | 14903 | neon_three_same (neon_quad (rs), 0, -1); |
5287ad62 JB |
14904 | } |
14905 | ||
14906 | static void | |
14907 | do_neon_abs_neg (void) | |
14908 | { | |
037e8744 JB |
14909 | enum neon_shape rs; |
14910 | struct neon_type_el et; | |
5f4273c7 | 14911 | |
037e8744 JB |
14912 | if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS) |
14913 | return; | |
14914 | ||
14915 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
14916 | return; | |
14917 | ||
14918 | rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); | |
14919 | et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY); | |
5f4273c7 | 14920 | |
5287ad62 JB |
14921 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
14922 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
14923 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
14924 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 14925 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
14926 | inst.instruction |= (et.type == NT_float) << 10; |
14927 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 14928 | |
88714cb8 | 14929 | neon_dp_fixup (&inst); |
5287ad62 JB |
14930 | } |
14931 | ||
14932 | static void | |
14933 | do_neon_sli (void) | |
14934 | { | |
037e8744 | 14935 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14936 | struct neon_type_el et = neon_check_type (2, rs, |
14937 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
14938 | int imm = inst.operands[2].imm; | |
14939 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 14940 | _("immediate out of range for insert")); |
037e8744 | 14941 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14942 | } |
14943 | ||
14944 | static void | |
14945 | do_neon_sri (void) | |
14946 | { | |
037e8744 | 14947 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14948 | struct neon_type_el et = neon_check_type (2, rs, |
14949 | N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
14950 | int imm = inst.operands[2].imm; | |
14951 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 14952 | _("immediate out of range for insert")); |
037e8744 | 14953 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm); |
5287ad62 JB |
14954 | } |
14955 | ||
14956 | static void | |
14957 | do_neon_qshlu_imm (void) | |
14958 | { | |
037e8744 | 14959 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
14960 | struct neon_type_el et = neon_check_type (2, rs, |
14961 | N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY); | |
14962 | int imm = inst.operands[2].imm; | |
14963 | constraint (imm < 0 || (unsigned)imm >= et.size, | |
477330fc | 14964 | _("immediate out of range for shift")); |
5287ad62 JB |
14965 | /* Only encodes the 'U present' variant of the instruction. |
14966 | In this case, signed types have OP (bit 8) set to 0. | |
14967 | Unsigned types have OP set to 1. */ | |
14968 | inst.instruction |= (et.type == NT_unsigned) << 8; | |
14969 | /* The rest of the bits are the same as other immediate shifts. */ | |
037e8744 | 14970 | neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm); |
5287ad62 JB |
14971 | } |
14972 | ||
14973 | static void | |
14974 | do_neon_qmovn (void) | |
14975 | { | |
14976 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
14977 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
14978 | /* Saturating move where operands can be signed or unsigned, and the | |
14979 | destination has the same signedness. */ | |
88714cb8 | 14980 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14981 | if (et.type == NT_unsigned) |
14982 | inst.instruction |= 0xc0; | |
14983 | else | |
14984 | inst.instruction |= 0x80; | |
14985 | neon_two_same (0, 1, et.size / 2); | |
14986 | } | |
14987 | ||
14988 | static void | |
14989 | do_neon_qmovun (void) | |
14990 | { | |
14991 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
14992 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
14993 | /* Saturating move with unsigned results. Operands must be signed. */ | |
88714cb8 | 14994 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
14995 | neon_two_same (0, 1, et.size / 2); |
14996 | } | |
14997 | ||
14998 | static void | |
14999 | do_neon_rshift_sat_narrow (void) | |
15000 | { | |
15001 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15002 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15003 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15004 | N_EQK | N_HLF, N_SU_16_64 | N_KEY); | |
15005 | int imm = inst.operands[2].imm; | |
15006 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15007 | right. */ | |
15008 | et.size /= 2; | |
5f4273c7 | 15009 | |
5287ad62 JB |
15010 | /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for |
15011 | VQMOVN.I<size> <Dd>, <Qm>. */ | |
15012 | if (imm == 0) | |
15013 | { | |
15014 | inst.operands[2].present = 0; | |
15015 | inst.instruction = N_MNEM_vqmovn; | |
15016 | do_neon_qmovn (); | |
15017 | return; | |
15018 | } | |
5f4273c7 | 15019 | |
5287ad62 | 15020 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15021 | _("immediate out of range")); |
5287ad62 JB |
15022 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm); |
15023 | } | |
15024 | ||
15025 | static void | |
15026 | do_neon_rshift_sat_narrow_u (void) | |
15027 | { | |
15028 | /* FIXME: Types for narrowing. If operands are signed, results can be signed | |
15029 | or unsigned. If operands are unsigned, results must also be unsigned. */ | |
15030 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15031 | N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY); | |
15032 | int imm = inst.operands[2].imm; | |
15033 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15034 | right. */ | |
15035 | et.size /= 2; | |
15036 | ||
15037 | /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for | |
15038 | VQMOVUN.I<size> <Dd>, <Qm>. */ | |
15039 | if (imm == 0) | |
15040 | { | |
15041 | inst.operands[2].present = 0; | |
15042 | inst.instruction = N_MNEM_vqmovun; | |
15043 | do_neon_qmovun (); | |
15044 | return; | |
15045 | } | |
15046 | ||
15047 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 15048 | _("immediate out of range")); |
5287ad62 JB |
15049 | /* FIXME: The manual is kind of unclear about what value U should have in |
15050 | VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it | |
15051 | must be 1. */ | |
15052 | neon_imm_shift (TRUE, 1, 0, et, et.size - imm); | |
15053 | } | |
15054 | ||
15055 | static void | |
15056 | do_neon_movn (void) | |
15057 | { | |
15058 | struct neon_type_el et = neon_check_type (2, NS_DQ, | |
15059 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
88714cb8 | 15060 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15061 | neon_two_same (0, 1, et.size / 2); |
15062 | } | |
15063 | ||
15064 | static void | |
15065 | do_neon_rshift_narrow (void) | |
15066 | { | |
15067 | struct neon_type_el et = neon_check_type (2, NS_DQI, | |
15068 | N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY); | |
15069 | int imm = inst.operands[2].imm; | |
15070 | /* This gets the bounds check, size encoding and immediate bits calculation | |
15071 | right. */ | |
15072 | et.size /= 2; | |
5f4273c7 | 15073 | |
5287ad62 JB |
15074 | /* If immediate is zero then we are a pseudo-instruction for |
15075 | VMOVN.I<size> <Dd>, <Qm> */ | |
15076 | if (imm == 0) | |
15077 | { | |
15078 | inst.operands[2].present = 0; | |
15079 | inst.instruction = N_MNEM_vmovn; | |
15080 | do_neon_movn (); | |
15081 | return; | |
15082 | } | |
5f4273c7 | 15083 | |
5287ad62 | 15084 | constraint (imm < 1 || (unsigned)imm > et.size, |
477330fc | 15085 | _("immediate out of range for narrowing operation")); |
5287ad62 JB |
15086 | neon_imm_shift (FALSE, 0, 0, et, et.size - imm); |
15087 | } | |
15088 | ||
15089 | static void | |
15090 | do_neon_shll (void) | |
15091 | { | |
15092 | /* FIXME: Type checking when lengthening. */ | |
15093 | struct neon_type_el et = neon_check_type (2, NS_QDI, | |
15094 | N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY); | |
15095 | unsigned imm = inst.operands[2].imm; | |
15096 | ||
15097 | if (imm == et.size) | |
15098 | { | |
15099 | /* Maximum shift variant. */ | |
88714cb8 | 15100 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15101 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15102 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15103 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15104 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15105 | inst.instruction |= neon_logbits (et.size) << 18; | |
5f4273c7 | 15106 | |
88714cb8 | 15107 | neon_dp_fixup (&inst); |
5287ad62 JB |
15108 | } |
15109 | else | |
15110 | { | |
15111 | /* A more-specific type check for non-max versions. */ | |
15112 | et = neon_check_type (2, NS_QDI, | |
477330fc | 15113 | N_EQK | N_DBL, N_SU_32 | N_KEY); |
88714cb8 | 15114 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15115 | neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm); |
15116 | } | |
15117 | } | |
15118 | ||
037e8744 | 15119 | /* Check the various types for the VCVT instruction, and return which version |
5287ad62 JB |
15120 | the current instruction is. */ |
15121 | ||
6b9a8b67 MGD |
15122 | #define CVT_FLAVOUR_VAR \ |
15123 | CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \ | |
15124 | CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \ | |
15125 | CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \ | |
15126 | CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \ | |
15127 | /* Half-precision conversions. */ \ | |
15128 | CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \ | |
15129 | CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \ | |
15130 | /* VFP instructions. */ \ | |
15131 | CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \ | |
15132 | CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \ | |
15133 | CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \ | |
15134 | CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \ | |
15135 | CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \ | |
15136 | CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \ | |
15137 | /* VFP instructions with bitshift. */ \ | |
15138 | CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \ | |
15139 | CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \ | |
15140 | CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \ | |
15141 | CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \ | |
15142 | CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \ | |
15143 | CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \ | |
15144 | CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \ | |
15145 | CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL) | |
15146 | ||
15147 | #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \ | |
15148 | neon_cvt_flavour_##C, | |
15149 | ||
15150 | /* The different types of conversions we can do. */ | |
15151 | enum neon_cvt_flavour | |
15152 | { | |
15153 | CVT_FLAVOUR_VAR | |
15154 | neon_cvt_flavour_invalid, | |
15155 | neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64 | |
15156 | }; | |
15157 | ||
15158 | #undef CVT_VAR | |
15159 | ||
15160 | static enum neon_cvt_flavour | |
15161 | get_neon_cvt_flavour (enum neon_shape rs) | |
5287ad62 | 15162 | { |
6b9a8b67 MGD |
15163 | #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \ |
15164 | et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \ | |
15165 | if (et.type != NT_invtype) \ | |
15166 | { \ | |
15167 | inst.error = NULL; \ | |
15168 | return (neon_cvt_flavour_##C); \ | |
5287ad62 | 15169 | } |
6b9a8b67 | 15170 | |
5287ad62 | 15171 | struct neon_type_el et; |
037e8744 | 15172 | unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF |
477330fc | 15173 | || rs == NS_FF) ? N_VFP : 0; |
037e8744 JB |
15174 | /* The instruction versions which take an immediate take one register |
15175 | argument, which is extended to the width of the full register. Thus the | |
15176 | "source" and "destination" registers must have the same width. Hack that | |
15177 | here by making the size equal to the key (wider, in this case) operand. */ | |
15178 | unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0; | |
5f4273c7 | 15179 | |
6b9a8b67 MGD |
15180 | CVT_FLAVOUR_VAR; |
15181 | ||
15182 | return neon_cvt_flavour_invalid; | |
5287ad62 JB |
15183 | #undef CVT_VAR |
15184 | } | |
15185 | ||
7e8e6784 MGD |
15186 | enum neon_cvt_mode |
15187 | { | |
15188 | neon_cvt_mode_a, | |
15189 | neon_cvt_mode_n, | |
15190 | neon_cvt_mode_p, | |
15191 | neon_cvt_mode_m, | |
15192 | neon_cvt_mode_z, | |
30bdf752 MGD |
15193 | neon_cvt_mode_x, |
15194 | neon_cvt_mode_r | |
7e8e6784 MGD |
15195 | }; |
15196 | ||
037e8744 JB |
15197 | /* Neon-syntax VFP conversions. */ |
15198 | ||
5287ad62 | 15199 | static void |
6b9a8b67 | 15200 | do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour) |
5287ad62 | 15201 | { |
037e8744 | 15202 | const char *opname = 0; |
5f4273c7 | 15203 | |
037e8744 | 15204 | if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI) |
5287ad62 | 15205 | { |
037e8744 JB |
15206 | /* Conversions with immediate bitshift. */ |
15207 | const char *enc[] = | |
477330fc | 15208 | { |
6b9a8b67 MGD |
15209 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN, |
15210 | CVT_FLAVOUR_VAR | |
15211 | NULL | |
15212 | #undef CVT_VAR | |
477330fc | 15213 | }; |
037e8744 | 15214 | |
6b9a8b67 | 15215 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc RM |
15216 | { |
15217 | opname = enc[flavour]; | |
15218 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
15219 | _("operands 0 and 1 must be the same register")); | |
15220 | inst.operands[1] = inst.operands[2]; | |
15221 | memset (&inst.operands[2], '\0', sizeof (inst.operands[2])); | |
15222 | } | |
5287ad62 JB |
15223 | } |
15224 | else | |
15225 | { | |
037e8744 JB |
15226 | /* Conversions without bitshift. */ |
15227 | const char *enc[] = | |
477330fc | 15228 | { |
6b9a8b67 MGD |
15229 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN, |
15230 | CVT_FLAVOUR_VAR | |
15231 | NULL | |
15232 | #undef CVT_VAR | |
477330fc | 15233 | }; |
037e8744 | 15234 | |
6b9a8b67 | 15235 | if (flavour < (int) ARRAY_SIZE (enc)) |
477330fc | 15236 | opname = enc[flavour]; |
037e8744 JB |
15237 | } |
15238 | ||
15239 | if (opname) | |
15240 | do_vfp_nsyn_opcode (opname); | |
15241 | } | |
15242 | ||
15243 | static void | |
15244 | do_vfp_nsyn_cvtz (void) | |
15245 | { | |
15246 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL); | |
6b9a8b67 | 15247 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 JB |
15248 | const char *enc[] = |
15249 | { | |
6b9a8b67 MGD |
15250 | #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN, |
15251 | CVT_FLAVOUR_VAR | |
15252 | NULL | |
15253 | #undef CVT_VAR | |
037e8744 JB |
15254 | }; |
15255 | ||
6b9a8b67 | 15256 | if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour]) |
037e8744 JB |
15257 | do_vfp_nsyn_opcode (enc[flavour]); |
15258 | } | |
f31fef98 | 15259 | |
037e8744 | 15260 | static void |
bacebabc | 15261 | do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour, |
7e8e6784 MGD |
15262 | enum neon_cvt_mode mode) |
15263 | { | |
15264 | int sz, op; | |
15265 | int rm; | |
15266 | ||
a715796b TG |
15267 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
15268 | D register operands. */ | |
15269 | if (flavour == neon_cvt_flavour_s32_f64 | |
15270 | || flavour == neon_cvt_flavour_u32_f64) | |
15271 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15272 | _(BAD_FPU)); | |
15273 | ||
7e8e6784 MGD |
15274 | set_it_insn_type (OUTSIDE_IT_INSN); |
15275 | ||
15276 | switch (flavour) | |
15277 | { | |
15278 | case neon_cvt_flavour_s32_f64: | |
15279 | sz = 1; | |
827f64ff | 15280 | op = 1; |
7e8e6784 MGD |
15281 | break; |
15282 | case neon_cvt_flavour_s32_f32: | |
15283 | sz = 0; | |
15284 | op = 1; | |
15285 | break; | |
15286 | case neon_cvt_flavour_u32_f64: | |
15287 | sz = 1; | |
15288 | op = 0; | |
15289 | break; | |
15290 | case neon_cvt_flavour_u32_f32: | |
15291 | sz = 0; | |
15292 | op = 0; | |
15293 | break; | |
15294 | default: | |
15295 | first_error (_("invalid instruction shape")); | |
15296 | return; | |
15297 | } | |
15298 | ||
15299 | switch (mode) | |
15300 | { | |
15301 | case neon_cvt_mode_a: rm = 0; break; | |
15302 | case neon_cvt_mode_n: rm = 1; break; | |
15303 | case neon_cvt_mode_p: rm = 2; break; | |
15304 | case neon_cvt_mode_m: rm = 3; break; | |
15305 | default: first_error (_("invalid rounding mode")); return; | |
15306 | } | |
15307 | ||
15308 | NEON_ENCODE (FPV8, inst); | |
15309 | encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd); | |
15310 | encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm); | |
15311 | inst.instruction |= sz << 8; | |
15312 | inst.instruction |= op << 7; | |
15313 | inst.instruction |= rm << 16; | |
15314 | inst.instruction |= 0xf0000000; | |
15315 | inst.is_neon = TRUE; | |
15316 | } | |
15317 | ||
15318 | static void | |
15319 | do_neon_cvt_1 (enum neon_cvt_mode mode) | |
037e8744 JB |
15320 | { |
15321 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ, | |
8e79c3df | 15322 | NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL); |
6b9a8b67 | 15323 | enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs); |
037e8744 | 15324 | |
e3e535bc | 15325 | /* PR11109: Handle round-to-zero for VCVT conversions. */ |
7e8e6784 | 15326 | if (mode == neon_cvt_mode_z |
e3e535bc | 15327 | && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2) |
bacebabc RM |
15328 | && (flavour == neon_cvt_flavour_s32_f32 |
15329 | || flavour == neon_cvt_flavour_u32_f32 | |
15330 | || flavour == neon_cvt_flavour_s32_f64 | |
6b9a8b67 | 15331 | || flavour == neon_cvt_flavour_u32_f64) |
e3e535bc NC |
15332 | && (rs == NS_FD || rs == NS_FF)) |
15333 | { | |
15334 | do_vfp_nsyn_cvtz (); | |
15335 | return; | |
15336 | } | |
15337 | ||
037e8744 | 15338 | /* VFP rather than Neon conversions. */ |
6b9a8b67 | 15339 | if (flavour >= neon_cvt_flavour_first_fp) |
037e8744 | 15340 | { |
7e8e6784 MGD |
15341 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
15342 | do_vfp_nsyn_cvt (rs, flavour); | |
15343 | else | |
15344 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
15345 | ||
037e8744 JB |
15346 | return; |
15347 | } | |
15348 | ||
15349 | switch (rs) | |
15350 | { | |
15351 | case NS_DDI: | |
15352 | case NS_QQI: | |
15353 | { | |
477330fc RM |
15354 | unsigned immbits; |
15355 | unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 }; | |
35997600 | 15356 | |
477330fc RM |
15357 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
15358 | return; | |
037e8744 | 15359 | |
477330fc RM |
15360 | /* Fixed-point conversion with #0 immediate is encoded as an |
15361 | integer conversion. */ | |
15362 | if (inst.operands[2].present && inst.operands[2].imm == 0) | |
15363 | goto int_encode; | |
35997600 | 15364 | immbits = 32 - inst.operands[2].imm; |
477330fc RM |
15365 | NEON_ENCODE (IMMED, inst); |
15366 | if (flavour != neon_cvt_flavour_invalid) | |
15367 | inst.instruction |= enctab[flavour]; | |
15368 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15369 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15370 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15371 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15372 | inst.instruction |= neon_quad (rs) << 6; | |
15373 | inst.instruction |= 1 << 21; | |
15374 | inst.instruction |= immbits << 16; | |
15375 | ||
15376 | neon_dp_fixup (&inst); | |
037e8744 JB |
15377 | } |
15378 | break; | |
15379 | ||
15380 | case NS_DD: | |
15381 | case NS_QQ: | |
7e8e6784 MGD |
15382 | if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z) |
15383 | { | |
15384 | NEON_ENCODE (FLOAT, inst); | |
15385 | set_it_insn_type (OUTSIDE_IT_INSN); | |
15386 | ||
15387 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
15388 | return; | |
15389 | ||
15390 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15391 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15392 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15393 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15394 | inst.instruction |= neon_quad (rs) << 6; | |
15395 | inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7; | |
15396 | inst.instruction |= mode << 8; | |
15397 | if (thumb_mode) | |
15398 | inst.instruction |= 0xfc000000; | |
15399 | else | |
15400 | inst.instruction |= 0xf0000000; | |
15401 | } | |
15402 | else | |
15403 | { | |
037e8744 | 15404 | int_encode: |
7e8e6784 MGD |
15405 | { |
15406 | unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 }; | |
037e8744 | 15407 | |
7e8e6784 | 15408 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 15409 | |
7e8e6784 MGD |
15410 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
15411 | return; | |
037e8744 | 15412 | |
7e8e6784 MGD |
15413 | if (flavour != neon_cvt_flavour_invalid) |
15414 | inst.instruction |= enctab[flavour]; | |
037e8744 | 15415 | |
7e8e6784 MGD |
15416 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15417 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15418 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15419 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15420 | inst.instruction |= neon_quad (rs) << 6; | |
15421 | inst.instruction |= 2 << 18; | |
037e8744 | 15422 | |
7e8e6784 MGD |
15423 | neon_dp_fixup (&inst); |
15424 | } | |
15425 | } | |
15426 | break; | |
037e8744 | 15427 | |
8e79c3df CM |
15428 | /* Half-precision conversions for Advanced SIMD -- neon. */ |
15429 | case NS_QD: | |
15430 | case NS_DQ: | |
15431 | ||
15432 | if ((rs == NS_DQ) | |
15433 | && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32)) | |
15434 | { | |
15435 | as_bad (_("operand size must match register width")); | |
15436 | break; | |
15437 | } | |
15438 | ||
15439 | if ((rs == NS_QD) | |
15440 | && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16))) | |
15441 | { | |
15442 | as_bad (_("operand size must match register width")); | |
15443 | break; | |
15444 | } | |
15445 | ||
15446 | if (rs == NS_DQ) | |
477330fc | 15447 | inst.instruction = 0x3b60600; |
8e79c3df CM |
15448 | else |
15449 | inst.instruction = 0x3b60700; | |
15450 | ||
15451 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15452 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15453 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15454 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
88714cb8 | 15455 | neon_dp_fixup (&inst); |
8e79c3df CM |
15456 | break; |
15457 | ||
037e8744 JB |
15458 | default: |
15459 | /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */ | |
7e8e6784 MGD |
15460 | if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z) |
15461 | do_vfp_nsyn_cvt (rs, flavour); | |
15462 | else | |
15463 | do_vfp_nsyn_cvt_fpv8 (flavour, mode); | |
5287ad62 | 15464 | } |
5287ad62 JB |
15465 | } |
15466 | ||
e3e535bc NC |
15467 | static void |
15468 | do_neon_cvtr (void) | |
15469 | { | |
7e8e6784 | 15470 | do_neon_cvt_1 (neon_cvt_mode_x); |
e3e535bc NC |
15471 | } |
15472 | ||
15473 | static void | |
15474 | do_neon_cvt (void) | |
15475 | { | |
7e8e6784 MGD |
15476 | do_neon_cvt_1 (neon_cvt_mode_z); |
15477 | } | |
15478 | ||
15479 | static void | |
15480 | do_neon_cvta (void) | |
15481 | { | |
15482 | do_neon_cvt_1 (neon_cvt_mode_a); | |
15483 | } | |
15484 | ||
15485 | static void | |
15486 | do_neon_cvtn (void) | |
15487 | { | |
15488 | do_neon_cvt_1 (neon_cvt_mode_n); | |
15489 | } | |
15490 | ||
15491 | static void | |
15492 | do_neon_cvtp (void) | |
15493 | { | |
15494 | do_neon_cvt_1 (neon_cvt_mode_p); | |
15495 | } | |
15496 | ||
15497 | static void | |
15498 | do_neon_cvtm (void) | |
15499 | { | |
15500 | do_neon_cvt_1 (neon_cvt_mode_m); | |
e3e535bc NC |
15501 | } |
15502 | ||
8e79c3df | 15503 | static void |
c70a8987 | 15504 | do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double) |
8e79c3df | 15505 | { |
c70a8987 MGD |
15506 | if (is_double) |
15507 | mark_feature_used (&fpu_vfp_ext_armv8); | |
8e79c3df | 15508 | |
c70a8987 MGD |
15509 | encode_arm_vfp_reg (inst.operands[0].reg, |
15510 | (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd); | |
15511 | encode_arm_vfp_reg (inst.operands[1].reg, | |
15512 | (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm); | |
15513 | inst.instruction |= to ? 0x10000 : 0; | |
15514 | inst.instruction |= t ? 0x80 : 0; | |
15515 | inst.instruction |= is_double ? 0x100 : 0; | |
15516 | do_vfp_cond_or_thumb (); | |
15517 | } | |
8e79c3df | 15518 | |
c70a8987 MGD |
15519 | static void |
15520 | do_neon_cvttb_1 (bfd_boolean t) | |
15521 | { | |
15522 | enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL); | |
8e79c3df | 15523 | |
c70a8987 MGD |
15524 | if (rs == NS_NULL) |
15525 | return; | |
15526 | else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype) | |
15527 | { | |
15528 | inst.error = NULL; | |
15529 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE); | |
15530 | } | |
15531 | else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype) | |
15532 | { | |
15533 | inst.error = NULL; | |
15534 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE); | |
15535 | } | |
15536 | else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype) | |
15537 | { | |
a715796b TG |
15538 | /* The VCVTB and VCVTT instructions with D-register operands |
15539 | don't work for SP only targets. */ | |
15540 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15541 | _(BAD_FPU)); | |
15542 | ||
c70a8987 MGD |
15543 | inst.error = NULL; |
15544 | do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE); | |
15545 | } | |
15546 | else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype) | |
15547 | { | |
a715796b TG |
15548 | /* The VCVTB and VCVTT instructions with D-register operands |
15549 | don't work for SP only targets. */ | |
15550 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
15551 | _(BAD_FPU)); | |
15552 | ||
c70a8987 MGD |
15553 | inst.error = NULL; |
15554 | do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE); | |
15555 | } | |
15556 | else | |
15557 | return; | |
15558 | } | |
15559 | ||
15560 | static void | |
15561 | do_neon_cvtb (void) | |
15562 | { | |
15563 | do_neon_cvttb_1 (FALSE); | |
8e79c3df CM |
15564 | } |
15565 | ||
15566 | ||
15567 | static void | |
15568 | do_neon_cvtt (void) | |
15569 | { | |
c70a8987 | 15570 | do_neon_cvttb_1 (TRUE); |
8e79c3df CM |
15571 | } |
15572 | ||
5287ad62 JB |
15573 | static void |
15574 | neon_move_immediate (void) | |
15575 | { | |
037e8744 JB |
15576 | enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL); |
15577 | struct neon_type_el et = neon_check_type (2, rs, | |
15578 | N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK); | |
5287ad62 | 15579 | unsigned immlo, immhi = 0, immbits; |
c96612cc | 15580 | int op, cmode, float_p; |
5287ad62 | 15581 | |
037e8744 | 15582 | constraint (et.type == NT_invtype, |
477330fc | 15583 | _("operand size must be specified for immediate VMOV")); |
037e8744 | 15584 | |
5287ad62 JB |
15585 | /* We start out as an MVN instruction if OP = 1, MOV otherwise. */ |
15586 | op = (inst.instruction & (1 << 5)) != 0; | |
15587 | ||
15588 | immlo = inst.operands[1].imm; | |
15589 | if (inst.operands[1].regisimm) | |
15590 | immhi = inst.operands[1].reg; | |
15591 | ||
15592 | constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0, | |
477330fc | 15593 | _("immediate has bits set outside the operand size")); |
5287ad62 | 15594 | |
c96612cc JB |
15595 | float_p = inst.operands[1].immisfloat; |
15596 | ||
15597 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op, | |
477330fc | 15598 | et.size, et.type)) == FAIL) |
5287ad62 JB |
15599 | { |
15600 | /* Invert relevant bits only. */ | |
15601 | neon_invert_size (&immlo, &immhi, et.size); | |
15602 | /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable | |
477330fc RM |
15603 | with one or the other; those cases are caught by |
15604 | neon_cmode_for_move_imm. */ | |
5287ad62 | 15605 | op = !op; |
c96612cc JB |
15606 | if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, |
15607 | &op, et.size, et.type)) == FAIL) | |
477330fc RM |
15608 | { |
15609 | first_error (_("immediate out of range")); | |
15610 | return; | |
15611 | } | |
5287ad62 JB |
15612 | } |
15613 | ||
15614 | inst.instruction &= ~(1 << 5); | |
15615 | inst.instruction |= op << 5; | |
15616 | ||
15617 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15618 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
037e8744 | 15619 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15620 | inst.instruction |= cmode << 8; |
15621 | ||
15622 | neon_write_immbits (immbits); | |
15623 | } | |
15624 | ||
15625 | static void | |
15626 | do_neon_mvn (void) | |
15627 | { | |
15628 | if (inst.operands[1].isreg) | |
15629 | { | |
037e8744 | 15630 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5f4273c7 | 15631 | |
88714cb8 | 15632 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15633 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15634 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15635 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15636 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
037e8744 | 15637 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15638 | } |
15639 | else | |
15640 | { | |
88714cb8 | 15641 | NEON_ENCODE (IMMED, inst); |
5287ad62 JB |
15642 | neon_move_immediate (); |
15643 | } | |
15644 | ||
88714cb8 | 15645 | neon_dp_fixup (&inst); |
5287ad62 JB |
15646 | } |
15647 | ||
15648 | /* Encode instructions of form: | |
15649 | ||
15650 | |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0| | |
5f4273c7 | 15651 | | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */ |
5287ad62 JB |
15652 | |
15653 | static void | |
15654 | neon_mixed_length (struct neon_type_el et, unsigned size) | |
15655 | { | |
15656 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15657 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15658 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15659 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15660 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15661 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
15662 | inst.instruction |= (et.type == NT_unsigned) << 24; | |
15663 | inst.instruction |= neon_logbits (size) << 20; | |
5f4273c7 | 15664 | |
88714cb8 | 15665 | neon_dp_fixup (&inst); |
5287ad62 JB |
15666 | } |
15667 | ||
15668 | static void | |
15669 | do_neon_dyadic_long (void) | |
15670 | { | |
15671 | /* FIXME: Type checking for lengthening op. */ | |
15672 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15673 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
15674 | neon_mixed_length (et, et.size); | |
15675 | } | |
15676 | ||
15677 | static void | |
15678 | do_neon_abal (void) | |
15679 | { | |
15680 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15681 | N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY); | |
15682 | neon_mixed_length (et, et.size); | |
15683 | } | |
15684 | ||
15685 | static void | |
15686 | neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes) | |
15687 | { | |
15688 | if (inst.operands[2].isscalar) | |
15689 | { | |
dcbf9037 | 15690 | struct neon_type_el et = neon_check_type (3, NS_QDS, |
477330fc | 15691 | N_EQK | N_DBL, N_EQK, regtypes | N_KEY); |
88714cb8 | 15692 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
15693 | neon_mul_mac (et, et.type == NT_unsigned); |
15694 | } | |
15695 | else | |
15696 | { | |
15697 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 15698 | N_EQK | N_DBL, N_EQK, scalartypes | N_KEY); |
88714cb8 | 15699 | NEON_ENCODE (INTEGER, inst); |
5287ad62 JB |
15700 | neon_mixed_length (et, et.size); |
15701 | } | |
15702 | } | |
15703 | ||
15704 | static void | |
15705 | do_neon_mac_maybe_scalar_long (void) | |
15706 | { | |
15707 | neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32); | |
15708 | } | |
15709 | ||
15710 | static void | |
15711 | do_neon_dyadic_wide (void) | |
15712 | { | |
15713 | struct neon_type_el et = neon_check_type (3, NS_QQD, | |
15714 | N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY); | |
15715 | neon_mixed_length (et, et.size); | |
15716 | } | |
15717 | ||
15718 | static void | |
15719 | do_neon_dyadic_narrow (void) | |
15720 | { | |
15721 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
15722 | N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY); | |
428e3f1f PB |
15723 | /* Operand sign is unimportant, and the U bit is part of the opcode, |
15724 | so force the operand type to integer. */ | |
15725 | et.type = NT_integer; | |
5287ad62 JB |
15726 | neon_mixed_length (et, et.size / 2); |
15727 | } | |
15728 | ||
15729 | static void | |
15730 | do_neon_mul_sat_scalar_long (void) | |
15731 | { | |
15732 | neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32); | |
15733 | } | |
15734 | ||
15735 | static void | |
15736 | do_neon_vmull (void) | |
15737 | { | |
15738 | if (inst.operands[2].isscalar) | |
15739 | do_neon_mac_maybe_scalar_long (); | |
15740 | else | |
15741 | { | |
15742 | struct neon_type_el et = neon_check_type (3, NS_QDD, | |
477330fc | 15743 | N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY); |
4f51b4bd | 15744 | |
5287ad62 | 15745 | if (et.type == NT_poly) |
477330fc | 15746 | NEON_ENCODE (POLY, inst); |
5287ad62 | 15747 | else |
477330fc | 15748 | NEON_ENCODE (INTEGER, inst); |
4f51b4bd MGD |
15749 | |
15750 | /* For polynomial encoding the U bit must be zero, and the size must | |
15751 | be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non | |
15752 | obviously, as 0b10). */ | |
15753 | if (et.size == 64) | |
15754 | { | |
15755 | /* Check we're on the correct architecture. */ | |
15756 | if (!mark_feature_used (&fpu_crypto_ext_armv8)) | |
15757 | inst.error = | |
15758 | _("Instruction form not available on this architecture."); | |
15759 | ||
15760 | et.size = 32; | |
15761 | } | |
15762 | ||
5287ad62 JB |
15763 | neon_mixed_length (et, et.size); |
15764 | } | |
15765 | } | |
15766 | ||
15767 | static void | |
15768 | do_neon_ext (void) | |
15769 | { | |
037e8744 | 15770 | enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL); |
5287ad62 JB |
15771 | struct neon_type_el et = neon_check_type (3, rs, |
15772 | N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY); | |
15773 | unsigned imm = (inst.operands[3].imm * et.size) / 8; | |
35997600 NC |
15774 | |
15775 | constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8), | |
15776 | _("shift out of range")); | |
5287ad62 JB |
15777 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15778 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15779 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15780 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15781 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
15782 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
037e8744 | 15783 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 | 15784 | inst.instruction |= imm << 8; |
5f4273c7 | 15785 | |
88714cb8 | 15786 | neon_dp_fixup (&inst); |
5287ad62 JB |
15787 | } |
15788 | ||
15789 | static void | |
15790 | do_neon_rev (void) | |
15791 | { | |
037e8744 | 15792 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
15793 | struct neon_type_el et = neon_check_type (2, rs, |
15794 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
15795 | unsigned op = (inst.instruction >> 7) & 3; | |
15796 | /* N (width of reversed regions) is encoded as part of the bitmask. We | |
15797 | extract it here to check the elements to be reversed are smaller. | |
15798 | Otherwise we'd get a reserved instruction. */ | |
15799 | unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0; | |
9c2799c2 | 15800 | gas_assert (elsize != 0); |
5287ad62 | 15801 | constraint (et.size >= elsize, |
477330fc | 15802 | _("elements must be smaller than reversal region")); |
037e8744 | 15803 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
15804 | } |
15805 | ||
15806 | static void | |
15807 | do_neon_dup (void) | |
15808 | { | |
15809 | if (inst.operands[1].isscalar) | |
15810 | { | |
037e8744 | 15811 | enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL); |
dcbf9037 | 15812 | struct neon_type_el et = neon_check_type (2, rs, |
477330fc | 15813 | N_EQK, N_8 | N_16 | N_32 | N_KEY); |
5287ad62 | 15814 | unsigned sizebits = et.size >> 3; |
dcbf9037 | 15815 | unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg); |
5287ad62 | 15816 | int logsize = neon_logbits (et.size); |
dcbf9037 | 15817 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize; |
037e8744 JB |
15818 | |
15819 | if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL) | |
477330fc | 15820 | return; |
037e8744 | 15821 | |
88714cb8 | 15822 | NEON_ENCODE (SCALAR, inst); |
5287ad62 JB |
15823 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; |
15824 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15825 | inst.instruction |= LOW4 (dm); | |
15826 | inst.instruction |= HI1 (dm) << 5; | |
037e8744 | 15827 | inst.instruction |= neon_quad (rs) << 6; |
5287ad62 JB |
15828 | inst.instruction |= x << 17; |
15829 | inst.instruction |= sizebits << 16; | |
5f4273c7 | 15830 | |
88714cb8 | 15831 | neon_dp_fixup (&inst); |
5287ad62 JB |
15832 | } |
15833 | else | |
15834 | { | |
037e8744 JB |
15835 | enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL); |
15836 | struct neon_type_el et = neon_check_type (2, rs, | |
477330fc | 15837 | N_8 | N_16 | N_32 | N_KEY, N_EQK); |
5287ad62 | 15838 | /* Duplicate ARM register to lanes of vector. */ |
88714cb8 | 15839 | NEON_ENCODE (ARMREG, inst); |
5287ad62 | 15840 | switch (et.size) |
477330fc RM |
15841 | { |
15842 | case 8: inst.instruction |= 0x400000; break; | |
15843 | case 16: inst.instruction |= 0x000020; break; | |
15844 | case 32: inst.instruction |= 0x000000; break; | |
15845 | default: break; | |
15846 | } | |
5287ad62 JB |
15847 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; |
15848 | inst.instruction |= LOW4 (inst.operands[0].reg) << 16; | |
15849 | inst.instruction |= HI1 (inst.operands[0].reg) << 7; | |
037e8744 | 15850 | inst.instruction |= neon_quad (rs) << 21; |
5287ad62 | 15851 | /* The encoding for this instruction is identical for the ARM and Thumb |
477330fc | 15852 | variants, except for the condition field. */ |
037e8744 | 15853 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
15854 | } |
15855 | } | |
15856 | ||
15857 | /* VMOV has particularly many variations. It can be one of: | |
15858 | 0. VMOV<c><q> <Qd>, <Qm> | |
15859 | 1. VMOV<c><q> <Dd>, <Dm> | |
15860 | (Register operations, which are VORR with Rm = Rn.) | |
15861 | 2. VMOV<c><q>.<dt> <Qd>, #<imm> | |
15862 | 3. VMOV<c><q>.<dt> <Dd>, #<imm> | |
15863 | (Immediate loads.) | |
15864 | 4. VMOV<c><q>.<size> <Dn[x]>, <Rd> | |
15865 | (ARM register to scalar.) | |
15866 | 5. VMOV<c><q> <Dm>, <Rd>, <Rn> | |
15867 | (Two ARM registers to vector.) | |
15868 | 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]> | |
15869 | (Scalar to ARM register.) | |
15870 | 7. VMOV<c><q> <Rd>, <Rn>, <Dm> | |
15871 | (Vector to two ARM registers.) | |
037e8744 JB |
15872 | 8. VMOV.F32 <Sd>, <Sm> |
15873 | 9. VMOV.F64 <Dd>, <Dm> | |
15874 | (VFP register moves.) | |
15875 | 10. VMOV.F32 <Sd>, #imm | |
15876 | 11. VMOV.F64 <Dd>, #imm | |
15877 | (VFP float immediate load.) | |
15878 | 12. VMOV <Rd>, <Sm> | |
15879 | (VFP single to ARM reg.) | |
15880 | 13. VMOV <Sd>, <Rm> | |
15881 | (ARM reg to VFP single.) | |
15882 | 14. VMOV <Rd>, <Re>, <Sn>, <Sm> | |
15883 | (Two ARM regs to two VFP singles.) | |
15884 | 15. VMOV <Sd>, <Se>, <Rn>, <Rm> | |
15885 | (Two VFP singles to two ARM regs.) | |
5f4273c7 | 15886 | |
037e8744 JB |
15887 | These cases can be disambiguated using neon_select_shape, except cases 1/9 |
15888 | and 3/11 which depend on the operand type too. | |
5f4273c7 | 15889 | |
5287ad62 | 15890 | All the encoded bits are hardcoded by this function. |
5f4273c7 | 15891 | |
b7fc2769 JB |
15892 | Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!). |
15893 | Cases 5, 7 may be used with VFPv2 and above. | |
5f4273c7 | 15894 | |
5287ad62 | 15895 | FIXME: Some of the checking may be a bit sloppy (in a couple of cases you |
5f4273c7 | 15896 | can specify a type where it doesn't make sense to, and is ignored). */ |
5287ad62 JB |
15897 | |
15898 | static void | |
15899 | do_neon_mov (void) | |
15900 | { | |
037e8744 JB |
15901 | enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD, |
15902 | NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR, | |
15903 | NS_NULL); | |
15904 | struct neon_type_el et; | |
15905 | const char *ldconst = 0; | |
5287ad62 | 15906 | |
037e8744 | 15907 | switch (rs) |
5287ad62 | 15908 | { |
037e8744 JB |
15909 | case NS_DD: /* case 1/9. */ |
15910 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
15911 | /* It is not an error here if no type is given. */ | |
15912 | inst.error = NULL; | |
15913 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
15914 | { |
15915 | do_vfp_nsyn_opcode ("fcpyd"); | |
15916 | break; | |
15917 | } | |
037e8744 | 15918 | /* fall through. */ |
5287ad62 | 15919 | |
037e8744 JB |
15920 | case NS_QQ: /* case 0/1. */ |
15921 | { | |
477330fc RM |
15922 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) |
15923 | return; | |
15924 | /* The architecture manual I have doesn't explicitly state which | |
15925 | value the U bit should have for register->register moves, but | |
15926 | the equivalent VORR instruction has U = 0, so do that. */ | |
15927 | inst.instruction = 0x0200110; | |
15928 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
15929 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
15930 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
15931 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
15932 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
15933 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
15934 | inst.instruction |= neon_quad (rs) << 6; | |
15935 | ||
15936 | neon_dp_fixup (&inst); | |
037e8744 JB |
15937 | } |
15938 | break; | |
5f4273c7 | 15939 | |
037e8744 JB |
15940 | case NS_DI: /* case 3/11. */ |
15941 | et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY); | |
15942 | inst.error = NULL; | |
15943 | if (et.type == NT_float && et.size == 64) | |
477330fc RM |
15944 | { |
15945 | /* case 11 (fconstd). */ | |
15946 | ldconst = "fconstd"; | |
15947 | goto encode_fconstd; | |
15948 | } | |
037e8744 JB |
15949 | /* fall through. */ |
15950 | ||
15951 | case NS_QI: /* case 2/3. */ | |
15952 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL) | |
477330fc | 15953 | return; |
037e8744 JB |
15954 | inst.instruction = 0x0800010; |
15955 | neon_move_immediate (); | |
88714cb8 | 15956 | neon_dp_fixup (&inst); |
5287ad62 | 15957 | break; |
5f4273c7 | 15958 | |
037e8744 JB |
15959 | case NS_SR: /* case 4. */ |
15960 | { | |
477330fc RM |
15961 | unsigned bcdebits = 0; |
15962 | int logsize; | |
15963 | unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg); | |
15964 | unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg); | |
037e8744 | 15965 | |
05ac0ffb JB |
15966 | /* .<size> is optional here, defaulting to .32. */ |
15967 | if (inst.vectype.elems == 0 | |
15968 | && inst.operands[0].vectype.type == NT_invtype | |
15969 | && inst.operands[1].vectype.type == NT_invtype) | |
15970 | { | |
15971 | inst.vectype.el[0].type = NT_untyped; | |
15972 | inst.vectype.el[0].size = 32; | |
15973 | inst.vectype.elems = 1; | |
15974 | } | |
15975 | ||
477330fc RM |
15976 | et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK); |
15977 | logsize = neon_logbits (et.size); | |
15978 | ||
15979 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
15980 | _(BAD_FPU)); | |
15981 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
15982 | && et.size != 32, _(BAD_FPU)); | |
15983 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
15984 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
15985 | ||
15986 | switch (et.size) | |
15987 | { | |
15988 | case 8: bcdebits = 0x8; break; | |
15989 | case 16: bcdebits = 0x1; break; | |
15990 | case 32: bcdebits = 0x0; break; | |
15991 | default: ; | |
15992 | } | |
15993 | ||
15994 | bcdebits |= x << logsize; | |
15995 | ||
15996 | inst.instruction = 0xe000b10; | |
15997 | do_vfp_cond_or_thumb (); | |
15998 | inst.instruction |= LOW4 (dn) << 16; | |
15999 | inst.instruction |= HI1 (dn) << 7; | |
16000 | inst.instruction |= inst.operands[1].reg << 12; | |
16001 | inst.instruction |= (bcdebits & 3) << 5; | |
16002 | inst.instruction |= (bcdebits >> 2) << 21; | |
037e8744 JB |
16003 | } |
16004 | break; | |
5f4273c7 | 16005 | |
037e8744 | 16006 | case NS_DRR: /* case 5 (fmdrr). */ |
b7fc2769 | 16007 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), |
477330fc | 16008 | _(BAD_FPU)); |
b7fc2769 | 16009 | |
037e8744 JB |
16010 | inst.instruction = 0xc400b10; |
16011 | do_vfp_cond_or_thumb (); | |
16012 | inst.instruction |= LOW4 (inst.operands[0].reg); | |
16013 | inst.instruction |= HI1 (inst.operands[0].reg) << 5; | |
16014 | inst.instruction |= inst.operands[1].reg << 12; | |
16015 | inst.instruction |= inst.operands[2].reg << 16; | |
16016 | break; | |
5f4273c7 | 16017 | |
037e8744 JB |
16018 | case NS_RS: /* case 6. */ |
16019 | { | |
477330fc RM |
16020 | unsigned logsize; |
16021 | unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg); | |
16022 | unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg); | |
16023 | unsigned abcdebits = 0; | |
037e8744 | 16024 | |
05ac0ffb JB |
16025 | /* .<dt> is optional here, defaulting to .32. */ |
16026 | if (inst.vectype.elems == 0 | |
16027 | && inst.operands[0].vectype.type == NT_invtype | |
16028 | && inst.operands[1].vectype.type == NT_invtype) | |
16029 | { | |
16030 | inst.vectype.el[0].type = NT_untyped; | |
16031 | inst.vectype.el[0].size = 32; | |
16032 | inst.vectype.elems = 1; | |
16033 | } | |
16034 | ||
91d6fa6a NC |
16035 | et = neon_check_type (2, NS_NULL, |
16036 | N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY); | |
477330fc RM |
16037 | logsize = neon_logbits (et.size); |
16038 | ||
16039 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1), | |
16040 | _(BAD_FPU)); | |
16041 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1) | |
16042 | && et.size != 32, _(BAD_FPU)); | |
16043 | constraint (et.type == NT_invtype, _("bad type for scalar")); | |
16044 | constraint (x >= 64 / et.size, _("scalar index out of range")); | |
16045 | ||
16046 | switch (et.size) | |
16047 | { | |
16048 | case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break; | |
16049 | case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break; | |
16050 | case 32: abcdebits = 0x00; break; | |
16051 | default: ; | |
16052 | } | |
16053 | ||
16054 | abcdebits |= x << logsize; | |
16055 | inst.instruction = 0xe100b10; | |
16056 | do_vfp_cond_or_thumb (); | |
16057 | inst.instruction |= LOW4 (dn) << 16; | |
16058 | inst.instruction |= HI1 (dn) << 7; | |
16059 | inst.instruction |= inst.operands[0].reg << 12; | |
16060 | inst.instruction |= (abcdebits & 3) << 5; | |
16061 | inst.instruction |= (abcdebits >> 2) << 21; | |
037e8744 JB |
16062 | } |
16063 | break; | |
5f4273c7 | 16064 | |
037e8744 JB |
16065 | case NS_RRD: /* case 7 (fmrrd). */ |
16066 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2), | |
477330fc | 16067 | _(BAD_FPU)); |
037e8744 JB |
16068 | |
16069 | inst.instruction = 0xc500b10; | |
16070 | do_vfp_cond_or_thumb (); | |
16071 | inst.instruction |= inst.operands[0].reg << 12; | |
16072 | inst.instruction |= inst.operands[1].reg << 16; | |
16073 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16074 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16075 | break; | |
5f4273c7 | 16076 | |
037e8744 JB |
16077 | case NS_FF: /* case 8 (fcpys). */ |
16078 | do_vfp_nsyn_opcode ("fcpys"); | |
16079 | break; | |
5f4273c7 | 16080 | |
037e8744 JB |
16081 | case NS_FI: /* case 10 (fconsts). */ |
16082 | ldconst = "fconsts"; | |
16083 | encode_fconstd: | |
16084 | if (is_quarter_float (inst.operands[1].imm)) | |
477330fc RM |
16085 | { |
16086 | inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm); | |
16087 | do_vfp_nsyn_opcode (ldconst); | |
16088 | } | |
5287ad62 | 16089 | else |
477330fc | 16090 | first_error (_("immediate out of range")); |
037e8744 | 16091 | break; |
5f4273c7 | 16092 | |
037e8744 JB |
16093 | case NS_RF: /* case 12 (fmrs). */ |
16094 | do_vfp_nsyn_opcode ("fmrs"); | |
16095 | break; | |
5f4273c7 | 16096 | |
037e8744 JB |
16097 | case NS_FR: /* case 13 (fmsr). */ |
16098 | do_vfp_nsyn_opcode ("fmsr"); | |
16099 | break; | |
5f4273c7 | 16100 | |
037e8744 JB |
16101 | /* The encoders for the fmrrs and fmsrr instructions expect three operands |
16102 | (one of which is a list), but we have parsed four. Do some fiddling to | |
16103 | make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2 | |
16104 | expect. */ | |
16105 | case NS_RRFF: /* case 14 (fmrrs). */ | |
16106 | constraint (inst.operands[3].reg != inst.operands[2].reg + 1, | |
477330fc | 16107 | _("VFP registers must be adjacent")); |
037e8744 JB |
16108 | inst.operands[2].imm = 2; |
16109 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
16110 | do_vfp_nsyn_opcode ("fmrrs"); | |
16111 | break; | |
5f4273c7 | 16112 | |
037e8744 JB |
16113 | case NS_FFRR: /* case 15 (fmsrr). */ |
16114 | constraint (inst.operands[1].reg != inst.operands[0].reg + 1, | |
477330fc | 16115 | _("VFP registers must be adjacent")); |
037e8744 JB |
16116 | inst.operands[1] = inst.operands[2]; |
16117 | inst.operands[2] = inst.operands[3]; | |
16118 | inst.operands[0].imm = 2; | |
16119 | memset (&inst.operands[3], '\0', sizeof (inst.operands[3])); | |
16120 | do_vfp_nsyn_opcode ("fmsrr"); | |
5287ad62 | 16121 | break; |
5f4273c7 | 16122 | |
4c261dff NC |
16123 | case NS_NULL: |
16124 | /* neon_select_shape has determined that the instruction | |
16125 | shape is wrong and has already set the error message. */ | |
16126 | break; | |
16127 | ||
5287ad62 JB |
16128 | default: |
16129 | abort (); | |
16130 | } | |
16131 | } | |
16132 | ||
16133 | static void | |
16134 | do_neon_rshift_round_imm (void) | |
16135 | { | |
037e8744 | 16136 | enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL); |
5287ad62 JB |
16137 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY); |
16138 | int imm = inst.operands[2].imm; | |
16139 | ||
16140 | /* imm == 0 case is encoded as VMOV for V{R}SHR. */ | |
16141 | if (imm == 0) | |
16142 | { | |
16143 | inst.operands[2].present = 0; | |
16144 | do_neon_mov (); | |
16145 | return; | |
16146 | } | |
16147 | ||
16148 | constraint (imm < 1 || (unsigned)imm > et.size, | |
477330fc | 16149 | _("immediate out of range for shift")); |
037e8744 | 16150 | neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, |
477330fc | 16151 | et.size - imm); |
5287ad62 JB |
16152 | } |
16153 | ||
16154 | static void | |
16155 | do_neon_movl (void) | |
16156 | { | |
16157 | struct neon_type_el et = neon_check_type (2, NS_QD, | |
16158 | N_EQK | N_DBL, N_SU_32 | N_KEY); | |
16159 | unsigned sizebits = et.size >> 3; | |
16160 | inst.instruction |= sizebits << 19; | |
16161 | neon_two_same (0, et.type == NT_unsigned, -1); | |
16162 | } | |
16163 | ||
16164 | static void | |
16165 | do_neon_trn (void) | |
16166 | { | |
037e8744 | 16167 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16168 | struct neon_type_el et = neon_check_type (2, rs, |
16169 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
88714cb8 | 16170 | NEON_ENCODE (INTEGER, inst); |
037e8744 | 16171 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16172 | } |
16173 | ||
16174 | static void | |
16175 | do_neon_zip_uzp (void) | |
16176 | { | |
037e8744 | 16177 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16178 | struct neon_type_el et = neon_check_type (2, rs, |
16179 | N_EQK, N_8 | N_16 | N_32 | N_KEY); | |
16180 | if (rs == NS_DD && et.size == 32) | |
16181 | { | |
16182 | /* Special case: encode as VTRN.32 <Dd>, <Dm>. */ | |
16183 | inst.instruction = N_MNEM_vtrn; | |
16184 | do_neon_trn (); | |
16185 | return; | |
16186 | } | |
037e8744 | 16187 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16188 | } |
16189 | ||
16190 | static void | |
16191 | do_neon_sat_abs_neg (void) | |
16192 | { | |
037e8744 | 16193 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16194 | struct neon_type_el et = neon_check_type (2, rs, |
16195 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 16196 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16197 | } |
16198 | ||
16199 | static void | |
16200 | do_neon_pair_long (void) | |
16201 | { | |
037e8744 | 16202 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16203 | struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY); |
16204 | /* Unsigned is encoded in OP field (bit 7) for these instruction. */ | |
16205 | inst.instruction |= (et.type == NT_unsigned) << 7; | |
037e8744 | 16206 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16207 | } |
16208 | ||
16209 | static void | |
16210 | do_neon_recip_est (void) | |
16211 | { | |
037e8744 | 16212 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16213 | struct neon_type_el et = neon_check_type (2, rs, |
16214 | N_EQK | N_FLT, N_F32 | N_U32 | N_KEY); | |
16215 | inst.instruction |= (et.type == NT_float) << 8; | |
037e8744 | 16216 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16217 | } |
16218 | ||
16219 | static void | |
16220 | do_neon_cls (void) | |
16221 | { | |
037e8744 | 16222 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16223 | struct neon_type_el et = neon_check_type (2, rs, |
16224 | N_EQK, N_S8 | N_S16 | N_S32 | N_KEY); | |
037e8744 | 16225 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16226 | } |
16227 | ||
16228 | static void | |
16229 | do_neon_clz (void) | |
16230 | { | |
037e8744 | 16231 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16232 | struct neon_type_el et = neon_check_type (2, rs, |
16233 | N_EQK, N_I8 | N_I16 | N_I32 | N_KEY); | |
037e8744 | 16234 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16235 | } |
16236 | ||
16237 | static void | |
16238 | do_neon_cnt (void) | |
16239 | { | |
037e8744 | 16240 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
5287ad62 JB |
16241 | struct neon_type_el et = neon_check_type (2, rs, |
16242 | N_EQK | N_INT, N_8 | N_KEY); | |
037e8744 | 16243 | neon_two_same (neon_quad (rs), 1, et.size); |
5287ad62 JB |
16244 | } |
16245 | ||
16246 | static void | |
16247 | do_neon_swp (void) | |
16248 | { | |
037e8744 JB |
16249 | enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL); |
16250 | neon_two_same (neon_quad (rs), 1, -1); | |
5287ad62 JB |
16251 | } |
16252 | ||
16253 | static void | |
16254 | do_neon_tbl_tbx (void) | |
16255 | { | |
16256 | unsigned listlenbits; | |
dcbf9037 | 16257 | neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY); |
5f4273c7 | 16258 | |
5287ad62 JB |
16259 | if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4) |
16260 | { | |
dcbf9037 | 16261 | first_error (_("bad list length for table lookup")); |
5287ad62 JB |
16262 | return; |
16263 | } | |
5f4273c7 | 16264 | |
5287ad62 JB |
16265 | listlenbits = inst.operands[1].imm - 1; |
16266 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16267 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16268 | inst.instruction |= LOW4 (inst.operands[1].reg) << 16; | |
16269 | inst.instruction |= HI1 (inst.operands[1].reg) << 7; | |
16270 | inst.instruction |= LOW4 (inst.operands[2].reg); | |
16271 | inst.instruction |= HI1 (inst.operands[2].reg) << 5; | |
16272 | inst.instruction |= listlenbits << 8; | |
5f4273c7 | 16273 | |
88714cb8 | 16274 | neon_dp_fixup (&inst); |
5287ad62 JB |
16275 | } |
16276 | ||
16277 | static void | |
16278 | do_neon_ldm_stm (void) | |
16279 | { | |
16280 | /* P, U and L bits are part of bitmask. */ | |
16281 | int is_dbmode = (inst.instruction & (1 << 24)) != 0; | |
16282 | unsigned offsetbits = inst.operands[1].imm * 2; | |
16283 | ||
037e8744 JB |
16284 | if (inst.operands[1].issingle) |
16285 | { | |
16286 | do_vfp_nsyn_ldm_stm (is_dbmode); | |
16287 | return; | |
16288 | } | |
16289 | ||
5287ad62 | 16290 | constraint (is_dbmode && !inst.operands[0].writeback, |
477330fc | 16291 | _("writeback (!) must be used for VLDMDB and VSTMDB")); |
5287ad62 JB |
16292 | |
16293 | constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16, | |
477330fc RM |
16294 | _("register list must contain at least 1 and at most 16 " |
16295 | "registers")); | |
5287ad62 JB |
16296 | |
16297 | inst.instruction |= inst.operands[0].reg << 16; | |
16298 | inst.instruction |= inst.operands[0].writeback << 21; | |
16299 | inst.instruction |= LOW4 (inst.operands[1].reg) << 12; | |
16300 | inst.instruction |= HI1 (inst.operands[1].reg) << 22; | |
16301 | ||
16302 | inst.instruction |= offsetbits; | |
5f4273c7 | 16303 | |
037e8744 | 16304 | do_vfp_cond_or_thumb (); |
5287ad62 JB |
16305 | } |
16306 | ||
16307 | static void | |
16308 | do_neon_ldr_str (void) | |
16309 | { | |
5287ad62 | 16310 | int is_ldr = (inst.instruction & (1 << 20)) != 0; |
5f4273c7 | 16311 | |
6844b2c2 MGD |
16312 | /* Use of PC in vstr in ARM mode is deprecated in ARMv7. |
16313 | And is UNPREDICTABLE in thumb mode. */ | |
fa94de6b | 16314 | if (!is_ldr |
6844b2c2 | 16315 | && inst.operands[1].reg == REG_PC |
ba86b375 | 16316 | && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode)) |
6844b2c2 | 16317 | { |
94dcf8bf | 16318 | if (thumb_mode) |
6844b2c2 | 16319 | inst.error = _("Use of PC here is UNPREDICTABLE"); |
94dcf8bf | 16320 | else if (warn_on_deprecated) |
5c3696f8 | 16321 | as_tsktsk (_("Use of PC here is deprecated")); |
6844b2c2 MGD |
16322 | } |
16323 | ||
037e8744 JB |
16324 | if (inst.operands[0].issingle) |
16325 | { | |
cd2f129f | 16326 | if (is_ldr) |
477330fc | 16327 | do_vfp_nsyn_opcode ("flds"); |
cd2f129f | 16328 | else |
477330fc | 16329 | do_vfp_nsyn_opcode ("fsts"); |
5287ad62 JB |
16330 | } |
16331 | else | |
5287ad62 | 16332 | { |
cd2f129f | 16333 | if (is_ldr) |
477330fc | 16334 | do_vfp_nsyn_opcode ("fldd"); |
5287ad62 | 16335 | else |
477330fc | 16336 | do_vfp_nsyn_opcode ("fstd"); |
5287ad62 | 16337 | } |
5287ad62 JB |
16338 | } |
16339 | ||
16340 | /* "interleave" version also handles non-interleaving register VLD1/VST1 | |
16341 | instructions. */ | |
16342 | ||
16343 | static void | |
16344 | do_neon_ld_st_interleave (void) | |
16345 | { | |
037e8744 | 16346 | struct neon_type_el et = neon_check_type (1, NS_NULL, |
477330fc | 16347 | N_8 | N_16 | N_32 | N_64); |
5287ad62 JB |
16348 | unsigned alignbits = 0; |
16349 | unsigned idx; | |
16350 | /* The bits in this table go: | |
16351 | 0: register stride of one (0) or two (1) | |
16352 | 1,2: register list length, minus one (1, 2, 3, 4). | |
16353 | 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>). | |
16354 | We use -1 for invalid entries. */ | |
16355 | const int typetable[] = | |
16356 | { | |
16357 | 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */ | |
16358 | -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */ | |
16359 | -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */ | |
16360 | -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */ | |
16361 | }; | |
16362 | int typebits; | |
16363 | ||
dcbf9037 JB |
16364 | if (et.type == NT_invtype) |
16365 | return; | |
16366 | ||
5287ad62 JB |
16367 | if (inst.operands[1].immisalign) |
16368 | switch (inst.operands[1].imm >> 8) | |
16369 | { | |
16370 | case 64: alignbits = 1; break; | |
16371 | case 128: | |
477330fc | 16372 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2 |
e23c0ad8 | 16373 | && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
477330fc RM |
16374 | goto bad_alignment; |
16375 | alignbits = 2; | |
16376 | break; | |
5287ad62 | 16377 | case 256: |
477330fc RM |
16378 | if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4) |
16379 | goto bad_alignment; | |
16380 | alignbits = 3; | |
16381 | break; | |
5287ad62 JB |
16382 | default: |
16383 | bad_alignment: | |
477330fc RM |
16384 | first_error (_("bad alignment")); |
16385 | return; | |
5287ad62 JB |
16386 | } |
16387 | ||
16388 | inst.instruction |= alignbits << 4; | |
16389 | inst.instruction |= neon_logbits (et.size) << 6; | |
16390 | ||
16391 | /* Bits [4:6] of the immediate in a list specifier encode register stride | |
16392 | (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of | |
16393 | VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look | |
16394 | up the right value for "type" in a table based on this value and the given | |
16395 | list style, then stick it back. */ | |
16396 | idx = ((inst.operands[0].imm >> 4) & 7) | |
477330fc | 16397 | | (((inst.instruction >> 8) & 3) << 3); |
5287ad62 JB |
16398 | |
16399 | typebits = typetable[idx]; | |
5f4273c7 | 16400 | |
5287ad62 | 16401 | constraint (typebits == -1, _("bad list type for instruction")); |
1d50d57c WN |
16402 | constraint (((inst.instruction >> 8) & 3) && et.size == 64, |
16403 | _("bad element type for instruction")); | |
5287ad62 JB |
16404 | |
16405 | inst.instruction &= ~0xf00; | |
16406 | inst.instruction |= typebits << 8; | |
16407 | } | |
16408 | ||
16409 | /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup. | |
16410 | *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0 | |
16411 | otherwise. The variable arguments are a list of pairs of legal (size, align) | |
16412 | values, terminated with -1. */ | |
16413 | ||
16414 | static int | |
16415 | neon_alignment_bit (int size, int align, int *do_align, ...) | |
16416 | { | |
16417 | va_list ap; | |
16418 | int result = FAIL, thissize, thisalign; | |
5f4273c7 | 16419 | |
5287ad62 JB |
16420 | if (!inst.operands[1].immisalign) |
16421 | { | |
16422 | *do_align = 0; | |
16423 | return SUCCESS; | |
16424 | } | |
5f4273c7 | 16425 | |
5287ad62 JB |
16426 | va_start (ap, do_align); |
16427 | ||
16428 | do | |
16429 | { | |
16430 | thissize = va_arg (ap, int); | |
16431 | if (thissize == -1) | |
477330fc | 16432 | break; |
5287ad62 JB |
16433 | thisalign = va_arg (ap, int); |
16434 | ||
16435 | if (size == thissize && align == thisalign) | |
477330fc | 16436 | result = SUCCESS; |
5287ad62 JB |
16437 | } |
16438 | while (result != SUCCESS); | |
16439 | ||
16440 | va_end (ap); | |
16441 | ||
16442 | if (result == SUCCESS) | |
16443 | *do_align = 1; | |
16444 | else | |
dcbf9037 | 16445 | first_error (_("unsupported alignment for instruction")); |
5f4273c7 | 16446 | |
5287ad62 JB |
16447 | return result; |
16448 | } | |
16449 | ||
16450 | static void | |
16451 | do_neon_ld_st_lane (void) | |
16452 | { | |
037e8744 | 16453 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
16454 | int align_good, do_align = 0; |
16455 | int logsize = neon_logbits (et.size); | |
16456 | int align = inst.operands[1].imm >> 8; | |
16457 | int n = (inst.instruction >> 8) & 3; | |
16458 | int max_el = 64 / et.size; | |
5f4273c7 | 16459 | |
dcbf9037 JB |
16460 | if (et.type == NT_invtype) |
16461 | return; | |
5f4273c7 | 16462 | |
5287ad62 | 16463 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1, |
477330fc | 16464 | _("bad list length")); |
5287ad62 | 16465 | constraint (NEON_LANE (inst.operands[0].imm) >= max_el, |
477330fc | 16466 | _("scalar index out of range")); |
5287ad62 | 16467 | constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2 |
477330fc RM |
16468 | && et.size == 8, |
16469 | _("stride of 2 unavailable when element size is 8")); | |
5f4273c7 | 16470 | |
5287ad62 JB |
16471 | switch (n) |
16472 | { | |
16473 | case 0: /* VLD1 / VST1. */ | |
16474 | align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16, | |
477330fc | 16475 | 32, 32, -1); |
5287ad62 | 16476 | if (align_good == FAIL) |
477330fc | 16477 | return; |
5287ad62 | 16478 | if (do_align) |
477330fc RM |
16479 | { |
16480 | unsigned alignbits = 0; | |
16481 | switch (et.size) | |
16482 | { | |
16483 | case 16: alignbits = 0x1; break; | |
16484 | case 32: alignbits = 0x3; break; | |
16485 | default: ; | |
16486 | } | |
16487 | inst.instruction |= alignbits << 4; | |
16488 | } | |
5287ad62 JB |
16489 | break; |
16490 | ||
16491 | case 1: /* VLD2 / VST2. */ | |
16492 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32, | |
477330fc | 16493 | 32, 64, -1); |
5287ad62 | 16494 | if (align_good == FAIL) |
477330fc | 16495 | return; |
5287ad62 | 16496 | if (do_align) |
477330fc | 16497 | inst.instruction |= 1 << 4; |
5287ad62 JB |
16498 | break; |
16499 | ||
16500 | case 2: /* VLD3 / VST3. */ | |
16501 | constraint (inst.operands[1].immisalign, | |
477330fc | 16502 | _("can't use alignment with this instruction")); |
5287ad62 JB |
16503 | break; |
16504 | ||
16505 | case 3: /* VLD4 / VST4. */ | |
16506 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
477330fc | 16507 | 16, 64, 32, 64, 32, 128, -1); |
5287ad62 | 16508 | if (align_good == FAIL) |
477330fc | 16509 | return; |
5287ad62 | 16510 | if (do_align) |
477330fc RM |
16511 | { |
16512 | unsigned alignbits = 0; | |
16513 | switch (et.size) | |
16514 | { | |
16515 | case 8: alignbits = 0x1; break; | |
16516 | case 16: alignbits = 0x1; break; | |
16517 | case 32: alignbits = (align == 64) ? 0x1 : 0x2; break; | |
16518 | default: ; | |
16519 | } | |
16520 | inst.instruction |= alignbits << 4; | |
16521 | } | |
5287ad62 JB |
16522 | break; |
16523 | ||
16524 | default: ; | |
16525 | } | |
16526 | ||
16527 | /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */ | |
16528 | if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
16529 | inst.instruction |= 1 << (4 + logsize); | |
5f4273c7 | 16530 | |
5287ad62 JB |
16531 | inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5); |
16532 | inst.instruction |= logsize << 10; | |
16533 | } | |
16534 | ||
16535 | /* Encode single n-element structure to all lanes VLD<n> instructions. */ | |
16536 | ||
16537 | static void | |
16538 | do_neon_ld_dup (void) | |
16539 | { | |
037e8744 | 16540 | struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32); |
5287ad62 JB |
16541 | int align_good, do_align = 0; |
16542 | ||
dcbf9037 JB |
16543 | if (et.type == NT_invtype) |
16544 | return; | |
16545 | ||
5287ad62 JB |
16546 | switch ((inst.instruction >> 8) & 3) |
16547 | { | |
16548 | case 0: /* VLD1. */ | |
9c2799c2 | 16549 | gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2); |
5287ad62 | 16550 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, |
477330fc | 16551 | &do_align, 16, 16, 32, 32, -1); |
5287ad62 | 16552 | if (align_good == FAIL) |
477330fc | 16553 | return; |
5287ad62 | 16554 | switch (NEON_REGLIST_LENGTH (inst.operands[0].imm)) |
477330fc RM |
16555 | { |
16556 | case 1: break; | |
16557 | case 2: inst.instruction |= 1 << 5; break; | |
16558 | default: first_error (_("bad list length")); return; | |
16559 | } | |
5287ad62 JB |
16560 | inst.instruction |= neon_logbits (et.size) << 6; |
16561 | break; | |
16562 | ||
16563 | case 1: /* VLD2. */ | |
16564 | align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8, | |
477330fc | 16565 | &do_align, 8, 16, 16, 32, 32, 64, -1); |
5287ad62 | 16566 | if (align_good == FAIL) |
477330fc | 16567 | return; |
5287ad62 | 16568 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2, |
477330fc | 16569 | _("bad list length")); |
5287ad62 | 16570 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 16571 | inst.instruction |= 1 << 5; |
5287ad62 JB |
16572 | inst.instruction |= neon_logbits (et.size) << 6; |
16573 | break; | |
16574 | ||
16575 | case 2: /* VLD3. */ | |
16576 | constraint (inst.operands[1].immisalign, | |
477330fc | 16577 | _("can't use alignment with this instruction")); |
5287ad62 | 16578 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3, |
477330fc | 16579 | _("bad list length")); |
5287ad62 | 16580 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) |
477330fc | 16581 | inst.instruction |= 1 << 5; |
5287ad62 JB |
16582 | inst.instruction |= neon_logbits (et.size) << 6; |
16583 | break; | |
16584 | ||
16585 | case 3: /* VLD4. */ | |
16586 | { | |
477330fc RM |
16587 | int align = inst.operands[1].imm >> 8; |
16588 | align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32, | |
16589 | 16, 64, 32, 64, 32, 128, -1); | |
16590 | if (align_good == FAIL) | |
16591 | return; | |
16592 | constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4, | |
16593 | _("bad list length")); | |
16594 | if (NEON_REG_STRIDE (inst.operands[0].imm) == 2) | |
16595 | inst.instruction |= 1 << 5; | |
16596 | if (et.size == 32 && align == 128) | |
16597 | inst.instruction |= 0x3 << 6; | |
16598 | else | |
16599 | inst.instruction |= neon_logbits (et.size) << 6; | |
5287ad62 JB |
16600 | } |
16601 | break; | |
16602 | ||
16603 | default: ; | |
16604 | } | |
16605 | ||
16606 | inst.instruction |= do_align << 4; | |
16607 | } | |
16608 | ||
16609 | /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those | |
16610 | apart from bits [11:4]. */ | |
16611 | ||
16612 | static void | |
16613 | do_neon_ldx_stx (void) | |
16614 | { | |
b1a769ed DG |
16615 | if (inst.operands[1].isreg) |
16616 | constraint (inst.operands[1].reg == REG_PC, BAD_PC); | |
16617 | ||
5287ad62 JB |
16618 | switch (NEON_LANE (inst.operands[0].imm)) |
16619 | { | |
16620 | case NEON_INTERLEAVE_LANES: | |
88714cb8 | 16621 | NEON_ENCODE (INTERLV, inst); |
5287ad62 JB |
16622 | do_neon_ld_st_interleave (); |
16623 | break; | |
5f4273c7 | 16624 | |
5287ad62 | 16625 | case NEON_ALL_LANES: |
88714cb8 | 16626 | NEON_ENCODE (DUP, inst); |
2d51fb74 JB |
16627 | if (inst.instruction == N_INV) |
16628 | { | |
16629 | first_error ("only loads support such operands"); | |
16630 | break; | |
16631 | } | |
5287ad62 JB |
16632 | do_neon_ld_dup (); |
16633 | break; | |
5f4273c7 | 16634 | |
5287ad62 | 16635 | default: |
88714cb8 | 16636 | NEON_ENCODE (LANE, inst); |
5287ad62 JB |
16637 | do_neon_ld_st_lane (); |
16638 | } | |
16639 | ||
16640 | /* L bit comes from bit mask. */ | |
16641 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16642 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16643 | inst.instruction |= inst.operands[1].reg << 16; | |
5f4273c7 | 16644 | |
5287ad62 JB |
16645 | if (inst.operands[1].postind) |
16646 | { | |
16647 | int postreg = inst.operands[1].imm & 0xf; | |
16648 | constraint (!inst.operands[1].immisreg, | |
477330fc | 16649 | _("post-index must be a register")); |
5287ad62 | 16650 | constraint (postreg == 0xd || postreg == 0xf, |
477330fc | 16651 | _("bad register for post-index")); |
5287ad62 JB |
16652 | inst.instruction |= postreg; |
16653 | } | |
4f2374c7 | 16654 | else |
5287ad62 | 16655 | { |
4f2374c7 WN |
16656 | constraint (inst.operands[1].immisreg, BAD_ADDR_MODE); |
16657 | constraint (inst.reloc.exp.X_op != O_constant | |
16658 | || inst.reloc.exp.X_add_number != 0, | |
16659 | BAD_ADDR_MODE); | |
16660 | ||
16661 | if (inst.operands[1].writeback) | |
16662 | { | |
16663 | inst.instruction |= 0xd; | |
16664 | } | |
16665 | else | |
16666 | inst.instruction |= 0xf; | |
5287ad62 | 16667 | } |
5f4273c7 | 16668 | |
5287ad62 JB |
16669 | if (thumb_mode) |
16670 | inst.instruction |= 0xf9000000; | |
16671 | else | |
16672 | inst.instruction |= 0xf4000000; | |
16673 | } | |
33399f07 MGD |
16674 | |
16675 | /* FP v8. */ | |
16676 | static void | |
16677 | do_vfp_nsyn_fpv8 (enum neon_shape rs) | |
16678 | { | |
a715796b TG |
16679 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
16680 | D register operands. */ | |
16681 | if (neon_shape_class[rs] == SC_DOUBLE) | |
16682 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16683 | _(BAD_FPU)); | |
16684 | ||
33399f07 MGD |
16685 | NEON_ENCODE (FPV8, inst); |
16686 | ||
16687 | if (rs == NS_FFF) | |
16688 | do_vfp_sp_dyadic (); | |
16689 | else | |
16690 | do_vfp_dp_rd_rn_rm (); | |
16691 | ||
16692 | if (rs == NS_DDD) | |
16693 | inst.instruction |= 0x100; | |
16694 | ||
16695 | inst.instruction |= 0xf0000000; | |
16696 | } | |
16697 | ||
16698 | static void | |
16699 | do_vsel (void) | |
16700 | { | |
16701 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16702 | ||
16703 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS) | |
16704 | first_error (_("invalid instruction shape")); | |
16705 | } | |
16706 | ||
73924fbc MGD |
16707 | static void |
16708 | do_vmaxnm (void) | |
16709 | { | |
16710 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16711 | ||
16712 | if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS) | |
16713 | return; | |
16714 | ||
16715 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
16716 | return; | |
16717 | ||
16718 | neon_dyadic_misc (NT_untyped, N_F32, 0); | |
16719 | } | |
16720 | ||
30bdf752 MGD |
16721 | static void |
16722 | do_vrint_1 (enum neon_cvt_mode mode) | |
16723 | { | |
16724 | enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL); | |
16725 | struct neon_type_el et; | |
16726 | ||
16727 | if (rs == NS_NULL) | |
16728 | return; | |
16729 | ||
a715796b TG |
16730 | /* Targets like FPv5-SP-D16 don't support FP v8 instructions with |
16731 | D register operands. */ | |
16732 | if (neon_shape_class[rs] == SC_DOUBLE) | |
16733 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8), | |
16734 | _(BAD_FPU)); | |
16735 | ||
30bdf752 MGD |
16736 | et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP); |
16737 | if (et.type != NT_invtype) | |
16738 | { | |
16739 | /* VFP encodings. */ | |
16740 | if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n | |
16741 | || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m) | |
16742 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16743 | ||
16744 | NEON_ENCODE (FPV8, inst); | |
16745 | if (rs == NS_FF) | |
16746 | do_vfp_sp_monadic (); | |
16747 | else | |
16748 | do_vfp_dp_rd_rm (); | |
16749 | ||
16750 | switch (mode) | |
16751 | { | |
16752 | case neon_cvt_mode_r: inst.instruction |= 0x00000000; break; | |
16753 | case neon_cvt_mode_z: inst.instruction |= 0x00000080; break; | |
16754 | case neon_cvt_mode_x: inst.instruction |= 0x00010000; break; | |
16755 | case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break; | |
16756 | case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break; | |
16757 | case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break; | |
16758 | case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break; | |
16759 | default: abort (); | |
16760 | } | |
16761 | ||
16762 | inst.instruction |= (rs == NS_DD) << 8; | |
16763 | do_vfp_cond_or_thumb (); | |
16764 | } | |
16765 | else | |
16766 | { | |
16767 | /* Neon encodings (or something broken...). */ | |
16768 | inst.error = NULL; | |
16769 | et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY); | |
16770 | ||
16771 | if (et.type == NT_invtype) | |
16772 | return; | |
16773 | ||
16774 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16775 | NEON_ENCODE (FLOAT, inst); | |
16776 | ||
16777 | if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL) | |
16778 | return; | |
16779 | ||
16780 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16781 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16782 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16783 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16784 | inst.instruction |= neon_quad (rs) << 6; | |
16785 | switch (mode) | |
16786 | { | |
16787 | case neon_cvt_mode_z: inst.instruction |= 3 << 7; break; | |
16788 | case neon_cvt_mode_x: inst.instruction |= 1 << 7; break; | |
16789 | case neon_cvt_mode_a: inst.instruction |= 2 << 7; break; | |
16790 | case neon_cvt_mode_n: inst.instruction |= 0 << 7; break; | |
16791 | case neon_cvt_mode_p: inst.instruction |= 7 << 7; break; | |
16792 | case neon_cvt_mode_m: inst.instruction |= 5 << 7; break; | |
16793 | case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break; | |
16794 | default: abort (); | |
16795 | } | |
16796 | ||
16797 | if (thumb_mode) | |
16798 | inst.instruction |= 0xfc000000; | |
16799 | else | |
16800 | inst.instruction |= 0xf0000000; | |
16801 | } | |
16802 | } | |
16803 | ||
16804 | static void | |
16805 | do_vrintx (void) | |
16806 | { | |
16807 | do_vrint_1 (neon_cvt_mode_x); | |
16808 | } | |
16809 | ||
16810 | static void | |
16811 | do_vrintz (void) | |
16812 | { | |
16813 | do_vrint_1 (neon_cvt_mode_z); | |
16814 | } | |
16815 | ||
16816 | static void | |
16817 | do_vrintr (void) | |
16818 | { | |
16819 | do_vrint_1 (neon_cvt_mode_r); | |
16820 | } | |
16821 | ||
16822 | static void | |
16823 | do_vrinta (void) | |
16824 | { | |
16825 | do_vrint_1 (neon_cvt_mode_a); | |
16826 | } | |
16827 | ||
16828 | static void | |
16829 | do_vrintn (void) | |
16830 | { | |
16831 | do_vrint_1 (neon_cvt_mode_n); | |
16832 | } | |
16833 | ||
16834 | static void | |
16835 | do_vrintp (void) | |
16836 | { | |
16837 | do_vrint_1 (neon_cvt_mode_p); | |
16838 | } | |
16839 | ||
16840 | static void | |
16841 | do_vrintm (void) | |
16842 | { | |
16843 | do_vrint_1 (neon_cvt_mode_m); | |
16844 | } | |
16845 | ||
91ff7894 MGD |
16846 | /* Crypto v1 instructions. */ |
16847 | static void | |
16848 | do_crypto_2op_1 (unsigned elttype, int op) | |
16849 | { | |
16850 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16851 | ||
16852 | if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type | |
16853 | == NT_invtype) | |
16854 | return; | |
16855 | ||
16856 | inst.error = NULL; | |
16857 | ||
16858 | NEON_ENCODE (INTEGER, inst); | |
16859 | inst.instruction |= LOW4 (inst.operands[0].reg) << 12; | |
16860 | inst.instruction |= HI1 (inst.operands[0].reg) << 22; | |
16861 | inst.instruction |= LOW4 (inst.operands[1].reg); | |
16862 | inst.instruction |= HI1 (inst.operands[1].reg) << 5; | |
16863 | if (op != -1) | |
16864 | inst.instruction |= op << 6; | |
16865 | ||
16866 | if (thumb_mode) | |
16867 | inst.instruction |= 0xfc000000; | |
16868 | else | |
16869 | inst.instruction |= 0xf0000000; | |
16870 | } | |
16871 | ||
48adcd8e MGD |
16872 | static void |
16873 | do_crypto_3op_1 (int u, int op) | |
16874 | { | |
16875 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16876 | ||
16877 | if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT, | |
16878 | N_32 | N_UNT | N_KEY).type == NT_invtype) | |
16879 | return; | |
16880 | ||
16881 | inst.error = NULL; | |
16882 | ||
16883 | NEON_ENCODE (INTEGER, inst); | |
16884 | neon_three_same (1, u, 8 << op); | |
16885 | } | |
16886 | ||
91ff7894 MGD |
16887 | static void |
16888 | do_aese (void) | |
16889 | { | |
16890 | do_crypto_2op_1 (N_8, 0); | |
16891 | } | |
16892 | ||
16893 | static void | |
16894 | do_aesd (void) | |
16895 | { | |
16896 | do_crypto_2op_1 (N_8, 1); | |
16897 | } | |
16898 | ||
16899 | static void | |
16900 | do_aesmc (void) | |
16901 | { | |
16902 | do_crypto_2op_1 (N_8, 2); | |
16903 | } | |
16904 | ||
16905 | static void | |
16906 | do_aesimc (void) | |
16907 | { | |
16908 | do_crypto_2op_1 (N_8, 3); | |
16909 | } | |
16910 | ||
48adcd8e MGD |
16911 | static void |
16912 | do_sha1c (void) | |
16913 | { | |
16914 | do_crypto_3op_1 (0, 0); | |
16915 | } | |
16916 | ||
16917 | static void | |
16918 | do_sha1p (void) | |
16919 | { | |
16920 | do_crypto_3op_1 (0, 1); | |
16921 | } | |
16922 | ||
16923 | static void | |
16924 | do_sha1m (void) | |
16925 | { | |
16926 | do_crypto_3op_1 (0, 2); | |
16927 | } | |
16928 | ||
16929 | static void | |
16930 | do_sha1su0 (void) | |
16931 | { | |
16932 | do_crypto_3op_1 (0, 3); | |
16933 | } | |
91ff7894 | 16934 | |
48adcd8e MGD |
16935 | static void |
16936 | do_sha256h (void) | |
16937 | { | |
16938 | do_crypto_3op_1 (1, 0); | |
16939 | } | |
16940 | ||
16941 | static void | |
16942 | do_sha256h2 (void) | |
16943 | { | |
16944 | do_crypto_3op_1 (1, 1); | |
16945 | } | |
16946 | ||
16947 | static void | |
16948 | do_sha256su1 (void) | |
16949 | { | |
16950 | do_crypto_3op_1 (1, 2); | |
16951 | } | |
3c9017d2 MGD |
16952 | |
16953 | static void | |
16954 | do_sha1h (void) | |
16955 | { | |
16956 | do_crypto_2op_1 (N_32, -1); | |
16957 | } | |
16958 | ||
16959 | static void | |
16960 | do_sha1su1 (void) | |
16961 | { | |
16962 | do_crypto_2op_1 (N_32, 0); | |
16963 | } | |
16964 | ||
16965 | static void | |
16966 | do_sha256su0 (void) | |
16967 | { | |
16968 | do_crypto_2op_1 (N_32, 1); | |
16969 | } | |
dd5181d5 KT |
16970 | |
16971 | static void | |
16972 | do_crc32_1 (unsigned int poly, unsigned int sz) | |
16973 | { | |
16974 | unsigned int Rd = inst.operands[0].reg; | |
16975 | unsigned int Rn = inst.operands[1].reg; | |
16976 | unsigned int Rm = inst.operands[2].reg; | |
16977 | ||
16978 | set_it_insn_type (OUTSIDE_IT_INSN); | |
16979 | inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12); | |
16980 | inst.instruction |= LOW4 (Rn) << 16; | |
16981 | inst.instruction |= LOW4 (Rm); | |
16982 | inst.instruction |= sz << (thumb_mode ? 4 : 21); | |
16983 | inst.instruction |= poly << (thumb_mode ? 20 : 9); | |
16984 | ||
16985 | if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC) | |
16986 | as_warn (UNPRED_REG ("r15")); | |
16987 | if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP)) | |
16988 | as_warn (UNPRED_REG ("r13")); | |
16989 | } | |
16990 | ||
16991 | static void | |
16992 | do_crc32b (void) | |
16993 | { | |
16994 | do_crc32_1 (0, 0); | |
16995 | } | |
16996 | ||
16997 | static void | |
16998 | do_crc32h (void) | |
16999 | { | |
17000 | do_crc32_1 (0, 1); | |
17001 | } | |
17002 | ||
17003 | static void | |
17004 | do_crc32w (void) | |
17005 | { | |
17006 | do_crc32_1 (0, 2); | |
17007 | } | |
17008 | ||
17009 | static void | |
17010 | do_crc32cb (void) | |
17011 | { | |
17012 | do_crc32_1 (1, 0); | |
17013 | } | |
17014 | ||
17015 | static void | |
17016 | do_crc32ch (void) | |
17017 | { | |
17018 | do_crc32_1 (1, 1); | |
17019 | } | |
17020 | ||
17021 | static void | |
17022 | do_crc32cw (void) | |
17023 | { | |
17024 | do_crc32_1 (1, 2); | |
17025 | } | |
17026 | ||
5287ad62 JB |
17027 | \f |
17028 | /* Overall per-instruction processing. */ | |
17029 | ||
17030 | /* We need to be able to fix up arbitrary expressions in some statements. | |
17031 | This is so that we can handle symbols that are an arbitrary distance from | |
17032 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
17033 | which returns part of an address in a form which will be valid for | |
17034 | a data instruction. We do this by pushing the expression into a symbol | |
17035 | in the expr_section, and creating a fix for that. */ | |
17036 | ||
17037 | static void | |
17038 | fix_new_arm (fragS * frag, | |
17039 | int where, | |
17040 | short int size, | |
17041 | expressionS * exp, | |
17042 | int pc_rel, | |
17043 | int reloc) | |
17044 | { | |
17045 | fixS * new_fix; | |
17046 | ||
17047 | switch (exp->X_op) | |
17048 | { | |
17049 | case O_constant: | |
6e7ce2cd PB |
17050 | if (pc_rel) |
17051 | { | |
17052 | /* Create an absolute valued symbol, so we have something to | |
477330fc RM |
17053 | refer to in the object file. Unfortunately for us, gas's |
17054 | generic expression parsing will already have folded out | |
17055 | any use of .set foo/.type foo %function that may have | |
17056 | been used to set type information of the target location, | |
17057 | that's being specified symbolically. We have to presume | |
17058 | the user knows what they are doing. */ | |
6e7ce2cd PB |
17059 | char name[16 + 8]; |
17060 | symbolS *symbol; | |
17061 | ||
17062 | sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number); | |
17063 | ||
17064 | symbol = symbol_find_or_make (name); | |
17065 | S_SET_SEGMENT (symbol, absolute_section); | |
17066 | symbol_set_frag (symbol, &zero_address_frag); | |
17067 | S_SET_VALUE (symbol, exp->X_add_number); | |
17068 | exp->X_op = O_symbol; | |
17069 | exp->X_add_symbol = symbol; | |
17070 | exp->X_add_number = 0; | |
17071 | } | |
17072 | /* FALLTHROUGH */ | |
5287ad62 JB |
17073 | case O_symbol: |
17074 | case O_add: | |
17075 | case O_subtract: | |
21d799b5 | 17076 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, |
477330fc | 17077 | (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
17078 | break; |
17079 | ||
17080 | default: | |
21d799b5 | 17081 | new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0, |
477330fc | 17082 | pc_rel, (enum bfd_reloc_code_real) reloc); |
5287ad62 JB |
17083 | break; |
17084 | } | |
17085 | ||
17086 | /* Mark whether the fix is to a THUMB instruction, or an ARM | |
17087 | instruction. */ | |
17088 | new_fix->tc_fix_data = thumb_mode; | |
17089 | } | |
17090 | ||
17091 | /* Create a frg for an instruction requiring relaxation. */ | |
17092 | static void | |
17093 | output_relax_insn (void) | |
17094 | { | |
17095 | char * to; | |
17096 | symbolS *sym; | |
0110f2b8 PB |
17097 | int offset; |
17098 | ||
6e1cb1a6 PB |
17099 | /* The size of the instruction is unknown, so tie the debug info to the |
17100 | start of the instruction. */ | |
17101 | dwarf2_emit_insn (0); | |
6e1cb1a6 | 17102 | |
0110f2b8 PB |
17103 | switch (inst.reloc.exp.X_op) |
17104 | { | |
17105 | case O_symbol: | |
17106 | sym = inst.reloc.exp.X_add_symbol; | |
17107 | offset = inst.reloc.exp.X_add_number; | |
17108 | break; | |
17109 | case O_constant: | |
17110 | sym = NULL; | |
17111 | offset = inst.reloc.exp.X_add_number; | |
17112 | break; | |
17113 | default: | |
17114 | sym = make_expr_symbol (&inst.reloc.exp); | |
17115 | offset = 0; | |
17116 | break; | |
17117 | } | |
17118 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
17119 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
17120 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
17121 | } |
17122 | ||
17123 | /* Write a 32-bit thumb instruction to buf. */ | |
17124 | static void | |
17125 | put_thumb32_insn (char * buf, unsigned long insn) | |
17126 | { | |
17127 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
17128 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
17129 | } | |
17130 | ||
b99bd4ef | 17131 | static void |
c19d1205 | 17132 | output_inst (const char * str) |
b99bd4ef | 17133 | { |
c19d1205 | 17134 | char * to = NULL; |
b99bd4ef | 17135 | |
c19d1205 | 17136 | if (inst.error) |
b99bd4ef | 17137 | { |
c19d1205 | 17138 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
17139 | return; |
17140 | } | |
5f4273c7 NC |
17141 | if (inst.relax) |
17142 | { | |
17143 | output_relax_insn (); | |
0110f2b8 | 17144 | return; |
5f4273c7 | 17145 | } |
c19d1205 ZW |
17146 | if (inst.size == 0) |
17147 | return; | |
b99bd4ef | 17148 | |
c19d1205 | 17149 | to = frag_more (inst.size); |
8dc2430f NC |
17150 | /* PR 9814: Record the thumb mode into the current frag so that we know |
17151 | what type of NOP padding to use, if necessary. We override any previous | |
17152 | setting so that if the mode has changed then the NOPS that we use will | |
17153 | match the encoding of the last instruction in the frag. */ | |
cd000bff | 17154 | frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
c19d1205 ZW |
17155 | |
17156 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 17157 | { |
9c2799c2 | 17158 | gas_assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 17159 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 17160 | } |
c19d1205 | 17161 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 17162 | { |
9c2799c2 | 17163 | gas_assert (inst.size == (2 * INSN_SIZE)); |
c19d1205 ZW |
17164 | md_number_to_chars (to, inst.instruction, INSN_SIZE); |
17165 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 17166 | } |
c19d1205 ZW |
17167 | else |
17168 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 17169 | |
c19d1205 ZW |
17170 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
17171 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
17172 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
17173 | inst.reloc.type); | |
b99bd4ef | 17174 | |
c19d1205 | 17175 | dwarf2_emit_insn (inst.size); |
c19d1205 | 17176 | } |
b99bd4ef | 17177 | |
e07e6e58 NC |
17178 | static char * |
17179 | output_it_inst (int cond, int mask, char * to) | |
17180 | { | |
17181 | unsigned long instruction = 0xbf00; | |
17182 | ||
17183 | mask &= 0xf; | |
17184 | instruction |= mask; | |
17185 | instruction |= cond << 4; | |
17186 | ||
17187 | if (to == NULL) | |
17188 | { | |
17189 | to = frag_more (2); | |
17190 | #ifdef OBJ_ELF | |
17191 | dwarf2_emit_insn (2); | |
17192 | #endif | |
17193 | } | |
17194 | ||
17195 | md_number_to_chars (to, instruction, 2); | |
17196 | ||
17197 | return to; | |
17198 | } | |
17199 | ||
c19d1205 ZW |
17200 | /* Tag values used in struct asm_opcode's tag field. */ |
17201 | enum opcode_tag | |
17202 | { | |
17203 | OT_unconditional, /* Instruction cannot be conditionalized. | |
17204 | The ARM condition field is still 0xE. */ | |
17205 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
17206 | and carries 0xF in its ARM condition field. */ | |
17207 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
037e8744 | 17208 | OT_csuffixF, /* Some forms of the instruction take a conditional |
477330fc RM |
17209 | suffix, others place 0xF where the condition field |
17210 | would be. */ | |
c19d1205 ZW |
17211 | OT_cinfix3, /* Instruction takes a conditional infix, |
17212 | beginning at character index 3. (In | |
17213 | unified mode, it becomes a suffix.) */ | |
088fa78e KH |
17214 | OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for |
17215 | tsts, cmps, cmns, and teqs. */ | |
e3cb604e PB |
17216 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
17217 | character index 3, even in unified mode. Used for | |
17218 | legacy instructions where suffix and infix forms | |
17219 | may be ambiguous. */ | |
c19d1205 | 17220 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 17221 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
17222 | OT_odd_infix_unc, /* This is the unconditional variant of an |
17223 | instruction that takes a conditional infix | |
17224 | at an unusual position. In unified mode, | |
17225 | this variant will accept a suffix. */ | |
17226 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
17227 | are the conditional variants of instructions that | |
17228 | take conditional infixes in unusual positions. | |
17229 | The infix appears at character index | |
17230 | (tag - OT_odd_infix_0). These are not accepted | |
17231 | in unified mode. */ | |
17232 | }; | |
b99bd4ef | 17233 | |
c19d1205 ZW |
17234 | /* Subroutine of md_assemble, responsible for looking up the primary |
17235 | opcode from the mnemonic the user wrote. STR points to the | |
17236 | beginning of the mnemonic. | |
17237 | ||
17238 | This is not simply a hash table lookup, because of conditional | |
17239 | variants. Most instructions have conditional variants, which are | |
17240 | expressed with a _conditional affix_ to the mnemonic. If we were | |
17241 | to encode each conditional variant as a literal string in the opcode | |
17242 | table, it would have approximately 20,000 entries. | |
17243 | ||
17244 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
17245 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
17246 | instructions take the affix as an infix, notably the s-variants of | |
17247 | the arithmetic instructions. Of those instructions, all but six | |
17248 | have the infix appear after the third character of the mnemonic. | |
17249 | ||
17250 | Accordingly, the algorithm for looking up primary opcodes given | |
17251 | an identifier is: | |
17252 | ||
17253 | 1. Look up the identifier in the opcode table. | |
17254 | If we find a match, go to step U. | |
17255 | ||
17256 | 2. Look up the last two characters of the identifier in the | |
17257 | conditions table. If we find a match, look up the first N-2 | |
17258 | characters of the identifier in the opcode table. If we | |
17259 | find a match, go to step CE. | |
17260 | ||
17261 | 3. Look up the fourth and fifth characters of the identifier in | |
17262 | the conditions table. If we find a match, extract those | |
17263 | characters from the identifier, and look up the remaining | |
17264 | characters in the opcode table. If we find a match, go | |
17265 | to step CM. | |
17266 | ||
17267 | 4. Fail. | |
17268 | ||
17269 | U. Examine the tag field of the opcode structure, in case this is | |
17270 | one of the six instructions with its conditional infix in an | |
17271 | unusual place. If it is, the tag tells us where to find the | |
17272 | infix; look it up in the conditions table and set inst.cond | |
17273 | accordingly. Otherwise, this is an unconditional instruction. | |
17274 | Again set inst.cond accordingly. Return the opcode structure. | |
17275 | ||
17276 | CE. Examine the tag field to make sure this is an instruction that | |
17277 | should receive a conditional suffix. If it is not, fail. | |
17278 | Otherwise, set inst.cond from the suffix we already looked up, | |
17279 | and return the opcode structure. | |
17280 | ||
17281 | CM. Examine the tag field to make sure this is an instruction that | |
17282 | should receive a conditional infix after the third character. | |
17283 | If it is not, fail. Otherwise, undo the edits to the current | |
17284 | line of input and proceed as for case CE. */ | |
17285 | ||
17286 | static const struct asm_opcode * | |
17287 | opcode_lookup (char **str) | |
17288 | { | |
17289 | char *end, *base; | |
17290 | char *affix; | |
17291 | const struct asm_opcode *opcode; | |
17292 | const struct asm_cond *cond; | |
e3cb604e | 17293 | char save[2]; |
c19d1205 ZW |
17294 | |
17295 | /* Scan up to the end of the mnemonic, which must end in white space, | |
721a8186 | 17296 | '.' (in unified mode, or for Neon/VFP instructions), or end of string. */ |
c19d1205 | 17297 | for (base = end = *str; *end != '\0'; end++) |
721a8186 | 17298 | if (*end == ' ' || *end == '.') |
c19d1205 | 17299 | break; |
b99bd4ef | 17300 | |
c19d1205 | 17301 | if (end == base) |
c921be7d | 17302 | return NULL; |
b99bd4ef | 17303 | |
5287ad62 | 17304 | /* Handle a possible width suffix and/or Neon type suffix. */ |
c19d1205 | 17305 | if (end[0] == '.') |
b99bd4ef | 17306 | { |
5287ad62 | 17307 | int offset = 2; |
5f4273c7 | 17308 | |
267d2029 | 17309 | /* The .w and .n suffixes are only valid if the unified syntax is in |
477330fc | 17310 | use. */ |
267d2029 | 17311 | if (unified_syntax && end[1] == 'w') |
c19d1205 | 17312 | inst.size_req = 4; |
267d2029 | 17313 | else if (unified_syntax && end[1] == 'n') |
c19d1205 ZW |
17314 | inst.size_req = 2; |
17315 | else | |
477330fc | 17316 | offset = 0; |
5287ad62 JB |
17317 | |
17318 | inst.vectype.elems = 0; | |
17319 | ||
17320 | *str = end + offset; | |
b99bd4ef | 17321 | |
5f4273c7 | 17322 | if (end[offset] == '.') |
5287ad62 | 17323 | { |
267d2029 | 17324 | /* See if we have a Neon type suffix (possible in either unified or |
477330fc RM |
17325 | non-unified ARM syntax mode). */ |
17326 | if (parse_neon_type (&inst.vectype, str) == FAIL) | |
c921be7d | 17327 | return NULL; |
477330fc | 17328 | } |
5287ad62 | 17329 | else if (end[offset] != '\0' && end[offset] != ' ') |
477330fc | 17330 | return NULL; |
b99bd4ef | 17331 | } |
c19d1205 ZW |
17332 | else |
17333 | *str = end; | |
b99bd4ef | 17334 | |
c19d1205 | 17335 | /* Look for unaffixed or special-case affixed mnemonic. */ |
21d799b5 | 17336 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 17337 | end - base); |
c19d1205 | 17338 | if (opcode) |
b99bd4ef | 17339 | { |
c19d1205 ZW |
17340 | /* step U */ |
17341 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 17342 | { |
c19d1205 ZW |
17343 | inst.cond = COND_ALWAYS; |
17344 | return opcode; | |
b99bd4ef | 17345 | } |
b99bd4ef | 17346 | |
278df34e | 17347 | if (warn_on_deprecated && unified_syntax) |
5c3696f8 | 17348 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 | 17349 | affix = base + (opcode->tag - OT_odd_infix_0); |
21d799b5 | 17350 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
9c2799c2 | 17351 | gas_assert (cond); |
b99bd4ef | 17352 | |
c19d1205 ZW |
17353 | inst.cond = cond->value; |
17354 | return opcode; | |
17355 | } | |
b99bd4ef | 17356 | |
c19d1205 ZW |
17357 | /* Cannot have a conditional suffix on a mnemonic of less than two |
17358 | characters. */ | |
17359 | if (end - base < 3) | |
c921be7d | 17360 | return NULL; |
b99bd4ef | 17361 | |
c19d1205 ZW |
17362 | /* Look for suffixed mnemonic. */ |
17363 | affix = end - 2; | |
21d799b5 NC |
17364 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
17365 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, | |
477330fc | 17366 | affix - base); |
c19d1205 ZW |
17367 | if (opcode && cond) |
17368 | { | |
17369 | /* step CE */ | |
17370 | switch (opcode->tag) | |
17371 | { | |
e3cb604e PB |
17372 | case OT_cinfix3_legacy: |
17373 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
17374 | break; | |
17375 | ||
c19d1205 | 17376 | case OT_cinfix3: |
088fa78e | 17377 | case OT_cinfix3_deprecated: |
c19d1205 ZW |
17378 | case OT_odd_infix_unc: |
17379 | if (!unified_syntax) | |
e3cb604e | 17380 | return 0; |
c19d1205 ZW |
17381 | /* else fall through */ |
17382 | ||
17383 | case OT_csuffix: | |
477330fc | 17384 | case OT_csuffixF: |
c19d1205 ZW |
17385 | case OT_csuf_or_in3: |
17386 | inst.cond = cond->value; | |
17387 | return opcode; | |
17388 | ||
17389 | case OT_unconditional: | |
17390 | case OT_unconditionalF: | |
dfa9f0d5 | 17391 | if (thumb_mode) |
c921be7d | 17392 | inst.cond = cond->value; |
dfa9f0d5 PB |
17393 | else |
17394 | { | |
c921be7d | 17395 | /* Delayed diagnostic. */ |
dfa9f0d5 PB |
17396 | inst.error = BAD_COND; |
17397 | inst.cond = COND_ALWAYS; | |
17398 | } | |
c19d1205 | 17399 | return opcode; |
b99bd4ef | 17400 | |
c19d1205 | 17401 | default: |
c921be7d | 17402 | return NULL; |
c19d1205 ZW |
17403 | } |
17404 | } | |
b99bd4ef | 17405 | |
c19d1205 ZW |
17406 | /* Cannot have a usual-position infix on a mnemonic of less than |
17407 | six characters (five would be a suffix). */ | |
17408 | if (end - base < 6) | |
c921be7d | 17409 | return NULL; |
b99bd4ef | 17410 | |
c19d1205 ZW |
17411 | /* Look for infixed mnemonic in the usual position. */ |
17412 | affix = base + 3; | |
21d799b5 | 17413 | cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2); |
e3cb604e | 17414 | if (!cond) |
c921be7d | 17415 | return NULL; |
e3cb604e PB |
17416 | |
17417 | memcpy (save, affix, 2); | |
17418 | memmove (affix, affix + 2, (end - affix) - 2); | |
21d799b5 | 17419 | opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base, |
477330fc | 17420 | (end - base) - 2); |
e3cb604e PB |
17421 | memmove (affix + 2, affix, (end - affix) - 2); |
17422 | memcpy (affix, save, 2); | |
17423 | ||
088fa78e KH |
17424 | if (opcode |
17425 | && (opcode->tag == OT_cinfix3 | |
17426 | || opcode->tag == OT_cinfix3_deprecated | |
17427 | || opcode->tag == OT_csuf_or_in3 | |
17428 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 17429 | { |
c921be7d | 17430 | /* Step CM. */ |
278df34e | 17431 | if (warn_on_deprecated && unified_syntax |
088fa78e KH |
17432 | && (opcode->tag == OT_cinfix3 |
17433 | || opcode->tag == OT_cinfix3_deprecated)) | |
5c3696f8 | 17434 | as_tsktsk (_("conditional infixes are deprecated in unified syntax")); |
c19d1205 ZW |
17435 | |
17436 | inst.cond = cond->value; | |
17437 | return opcode; | |
b99bd4ef NC |
17438 | } |
17439 | ||
c921be7d | 17440 | return NULL; |
b99bd4ef NC |
17441 | } |
17442 | ||
e07e6e58 NC |
17443 | /* This function generates an initial IT instruction, leaving its block |
17444 | virtually open for the new instructions. Eventually, | |
17445 | the mask will be updated by now_it_add_mask () each time | |
17446 | a new instruction needs to be included in the IT block. | |
17447 | Finally, the block is closed with close_automatic_it_block (). | |
17448 | The block closure can be requested either from md_assemble (), | |
17449 | a tencode (), or due to a label hook. */ | |
17450 | ||
17451 | static void | |
17452 | new_automatic_it_block (int cond) | |
17453 | { | |
17454 | now_it.state = AUTOMATIC_IT_BLOCK; | |
17455 | now_it.mask = 0x18; | |
17456 | now_it.cc = cond; | |
17457 | now_it.block_length = 1; | |
cd000bff | 17458 | mapping_state (MAP_THUMB); |
e07e6e58 | 17459 | now_it.insn = output_it_inst (cond, now_it.mask, NULL); |
5a01bb1d MGD |
17460 | now_it.warn_deprecated = FALSE; |
17461 | now_it.insn_cond = TRUE; | |
e07e6e58 NC |
17462 | } |
17463 | ||
17464 | /* Close an automatic IT block. | |
17465 | See comments in new_automatic_it_block (). */ | |
17466 | ||
17467 | static void | |
17468 | close_automatic_it_block (void) | |
17469 | { | |
17470 | now_it.mask = 0x10; | |
17471 | now_it.block_length = 0; | |
17472 | } | |
17473 | ||
17474 | /* Update the mask of the current automatically-generated IT | |
17475 | instruction. See comments in new_automatic_it_block (). */ | |
17476 | ||
17477 | static void | |
17478 | now_it_add_mask (int cond) | |
17479 | { | |
17480 | #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit))) | |
17481 | #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \ | |
477330fc | 17482 | | ((bitvalue) << (nbit))) |
e07e6e58 | 17483 | const int resulting_bit = (cond & 1); |
c921be7d | 17484 | |
e07e6e58 NC |
17485 | now_it.mask &= 0xf; |
17486 | now_it.mask = SET_BIT_VALUE (now_it.mask, | |
477330fc RM |
17487 | resulting_bit, |
17488 | (5 - now_it.block_length)); | |
e07e6e58 | 17489 | now_it.mask = SET_BIT_VALUE (now_it.mask, |
477330fc RM |
17490 | 1, |
17491 | ((5 - now_it.block_length) - 1) ); | |
e07e6e58 NC |
17492 | output_it_inst (now_it.cc, now_it.mask, now_it.insn); |
17493 | ||
17494 | #undef CLEAR_BIT | |
17495 | #undef SET_BIT_VALUE | |
e07e6e58 NC |
17496 | } |
17497 | ||
17498 | /* The IT blocks handling machinery is accessed through the these functions: | |
17499 | it_fsm_pre_encode () from md_assemble () | |
17500 | set_it_insn_type () optional, from the tencode functions | |
17501 | set_it_insn_type_last () ditto | |
17502 | in_it_block () ditto | |
17503 | it_fsm_post_encode () from md_assemble () | |
17504 | force_automatic_it_block_close () from label habdling functions | |
17505 | ||
17506 | Rationale: | |
17507 | 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (), | |
477330fc RM |
17508 | initializing the IT insn type with a generic initial value depending |
17509 | on the inst.condition. | |
e07e6e58 | 17510 | 2) During the tencode function, two things may happen: |
477330fc RM |
17511 | a) The tencode function overrides the IT insn type by |
17512 | calling either set_it_insn_type (type) or set_it_insn_type_last (). | |
17513 | b) The tencode function queries the IT block state by | |
17514 | calling in_it_block () (i.e. to determine narrow/not narrow mode). | |
17515 | ||
17516 | Both set_it_insn_type and in_it_block run the internal FSM state | |
17517 | handling function (handle_it_state), because: a) setting the IT insn | |
17518 | type may incur in an invalid state (exiting the function), | |
17519 | and b) querying the state requires the FSM to be updated. | |
17520 | Specifically we want to avoid creating an IT block for conditional | |
17521 | branches, so it_fsm_pre_encode is actually a guess and we can't | |
17522 | determine whether an IT block is required until the tencode () routine | |
17523 | has decided what type of instruction this actually it. | |
17524 | Because of this, if set_it_insn_type and in_it_block have to be used, | |
17525 | set_it_insn_type has to be called first. | |
17526 | ||
17527 | set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that | |
17528 | determines the insn IT type depending on the inst.cond code. | |
17529 | When a tencode () routine encodes an instruction that can be | |
17530 | either outside an IT block, or, in the case of being inside, has to be | |
17531 | the last one, set_it_insn_type_last () will determine the proper | |
17532 | IT instruction type based on the inst.cond code. Otherwise, | |
17533 | set_it_insn_type can be called for overriding that logic or | |
17534 | for covering other cases. | |
17535 | ||
17536 | Calling handle_it_state () may not transition the IT block state to | |
17537 | OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be | |
17538 | still queried. Instead, if the FSM determines that the state should | |
17539 | be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed | |
17540 | after the tencode () function: that's what it_fsm_post_encode () does. | |
17541 | ||
17542 | Since in_it_block () calls the state handling function to get an | |
17543 | updated state, an error may occur (due to invalid insns combination). | |
17544 | In that case, inst.error is set. | |
17545 | Therefore, inst.error has to be checked after the execution of | |
17546 | the tencode () routine. | |
e07e6e58 NC |
17547 | |
17548 | 3) Back in md_assemble(), it_fsm_post_encode () is called to commit | |
477330fc RM |
17549 | any pending state change (if any) that didn't take place in |
17550 | handle_it_state () as explained above. */ | |
e07e6e58 NC |
17551 | |
17552 | static void | |
17553 | it_fsm_pre_encode (void) | |
17554 | { | |
17555 | if (inst.cond != COND_ALWAYS) | |
17556 | inst.it_insn_type = INSIDE_IT_INSN; | |
17557 | else | |
17558 | inst.it_insn_type = OUTSIDE_IT_INSN; | |
17559 | ||
17560 | now_it.state_handled = 0; | |
17561 | } | |
17562 | ||
17563 | /* IT state FSM handling function. */ | |
17564 | ||
17565 | static int | |
17566 | handle_it_state (void) | |
17567 | { | |
17568 | now_it.state_handled = 1; | |
5a01bb1d | 17569 | now_it.insn_cond = FALSE; |
e07e6e58 NC |
17570 | |
17571 | switch (now_it.state) | |
17572 | { | |
17573 | case OUTSIDE_IT_BLOCK: | |
17574 | switch (inst.it_insn_type) | |
17575 | { | |
17576 | case OUTSIDE_IT_INSN: | |
17577 | break; | |
17578 | ||
17579 | case INSIDE_IT_INSN: | |
17580 | case INSIDE_IT_LAST_INSN: | |
17581 | if (thumb_mode == 0) | |
17582 | { | |
c921be7d | 17583 | if (unified_syntax |
e07e6e58 NC |
17584 | && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM)) |
17585 | as_tsktsk (_("Warning: conditional outside an IT block"\ | |
17586 | " for Thumb.")); | |
17587 | } | |
17588 | else | |
17589 | { | |
17590 | if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB) | |
fc289b0a | 17591 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)) |
e07e6e58 NC |
17592 | { |
17593 | /* Automatically generate the IT instruction. */ | |
17594 | new_automatic_it_block (inst.cond); | |
17595 | if (inst.it_insn_type == INSIDE_IT_LAST_INSN) | |
17596 | close_automatic_it_block (); | |
17597 | } | |
17598 | else | |
17599 | { | |
17600 | inst.error = BAD_OUT_IT; | |
17601 | return FAIL; | |
17602 | } | |
17603 | } | |
17604 | break; | |
17605 | ||
17606 | case IF_INSIDE_IT_LAST_INSN: | |
17607 | case NEUTRAL_IT_INSN: | |
17608 | break; | |
17609 | ||
17610 | case IT_INSN: | |
17611 | now_it.state = MANUAL_IT_BLOCK; | |
17612 | now_it.block_length = 0; | |
17613 | break; | |
17614 | } | |
17615 | break; | |
17616 | ||
17617 | case AUTOMATIC_IT_BLOCK: | |
17618 | /* Three things may happen now: | |
17619 | a) We should increment current it block size; | |
17620 | b) We should close current it block (closing insn or 4 insns); | |
17621 | c) We should close current it block and start a new one (due | |
17622 | to incompatible conditions or | |
17623 | 4 insns-length block reached). */ | |
17624 | ||
17625 | switch (inst.it_insn_type) | |
17626 | { | |
17627 | case OUTSIDE_IT_INSN: | |
17628 | /* The closure of the block shall happen immediatelly, | |
17629 | so any in_it_block () call reports the block as closed. */ | |
17630 | force_automatic_it_block_close (); | |
17631 | break; | |
17632 | ||
17633 | case INSIDE_IT_INSN: | |
17634 | case INSIDE_IT_LAST_INSN: | |
17635 | case IF_INSIDE_IT_LAST_INSN: | |
17636 | now_it.block_length++; | |
17637 | ||
17638 | if (now_it.block_length > 4 | |
17639 | || !now_it_compatible (inst.cond)) | |
17640 | { | |
17641 | force_automatic_it_block_close (); | |
17642 | if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN) | |
17643 | new_automatic_it_block (inst.cond); | |
17644 | } | |
17645 | else | |
17646 | { | |
5a01bb1d | 17647 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
17648 | now_it_add_mask (inst.cond); |
17649 | } | |
17650 | ||
17651 | if (now_it.state == AUTOMATIC_IT_BLOCK | |
17652 | && (inst.it_insn_type == INSIDE_IT_LAST_INSN | |
17653 | || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN)) | |
17654 | close_automatic_it_block (); | |
17655 | break; | |
17656 | ||
17657 | case NEUTRAL_IT_INSN: | |
17658 | now_it.block_length++; | |
5a01bb1d | 17659 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
17660 | |
17661 | if (now_it.block_length > 4) | |
17662 | force_automatic_it_block_close (); | |
17663 | else | |
17664 | now_it_add_mask (now_it.cc & 1); | |
17665 | break; | |
17666 | ||
17667 | case IT_INSN: | |
17668 | close_automatic_it_block (); | |
17669 | now_it.state = MANUAL_IT_BLOCK; | |
17670 | break; | |
17671 | } | |
17672 | break; | |
17673 | ||
17674 | case MANUAL_IT_BLOCK: | |
17675 | { | |
17676 | /* Check conditional suffixes. */ | |
17677 | const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1; | |
17678 | int is_last; | |
17679 | now_it.mask <<= 1; | |
17680 | now_it.mask &= 0x1f; | |
17681 | is_last = (now_it.mask == 0x10); | |
5a01bb1d | 17682 | now_it.insn_cond = TRUE; |
e07e6e58 NC |
17683 | |
17684 | switch (inst.it_insn_type) | |
17685 | { | |
17686 | case OUTSIDE_IT_INSN: | |
17687 | inst.error = BAD_NOT_IT; | |
17688 | return FAIL; | |
17689 | ||
17690 | case INSIDE_IT_INSN: | |
17691 | if (cond != inst.cond) | |
17692 | { | |
17693 | inst.error = BAD_IT_COND; | |
17694 | return FAIL; | |
17695 | } | |
17696 | break; | |
17697 | ||
17698 | case INSIDE_IT_LAST_INSN: | |
17699 | case IF_INSIDE_IT_LAST_INSN: | |
17700 | if (cond != inst.cond) | |
17701 | { | |
17702 | inst.error = BAD_IT_COND; | |
17703 | return FAIL; | |
17704 | } | |
17705 | if (!is_last) | |
17706 | { | |
17707 | inst.error = BAD_BRANCH; | |
17708 | return FAIL; | |
17709 | } | |
17710 | break; | |
17711 | ||
17712 | case NEUTRAL_IT_INSN: | |
17713 | /* The BKPT instruction is unconditional even in an IT block. */ | |
17714 | break; | |
17715 | ||
17716 | case IT_INSN: | |
17717 | inst.error = BAD_IT_IT; | |
17718 | return FAIL; | |
17719 | } | |
17720 | } | |
17721 | break; | |
17722 | } | |
17723 | ||
17724 | return SUCCESS; | |
17725 | } | |
17726 | ||
5a01bb1d MGD |
17727 | struct depr_insn_mask |
17728 | { | |
17729 | unsigned long pattern; | |
17730 | unsigned long mask; | |
17731 | const char* description; | |
17732 | }; | |
17733 | ||
17734 | /* List of 16-bit instruction patterns deprecated in an IT block in | |
17735 | ARMv8. */ | |
17736 | static const struct depr_insn_mask depr_it_insns[] = { | |
17737 | { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") }, | |
17738 | { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") }, | |
17739 | { 0xa000, 0xb800, N_("ADR") }, | |
17740 | { 0x4800, 0xf800, N_("Literal loads") }, | |
17741 | { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") }, | |
17742 | { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") }, | |
c8de034b JW |
17743 | /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue' |
17744 | field in asm_opcode. 'tvalue' is used at the stage this check happen. */ | |
17745 | { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") }, | |
5a01bb1d MGD |
17746 | { 0, 0, NULL } |
17747 | }; | |
17748 | ||
e07e6e58 NC |
17749 | static void |
17750 | it_fsm_post_encode (void) | |
17751 | { | |
17752 | int is_last; | |
17753 | ||
17754 | if (!now_it.state_handled) | |
17755 | handle_it_state (); | |
17756 | ||
5a01bb1d MGD |
17757 | if (now_it.insn_cond |
17758 | && !now_it.warn_deprecated | |
17759 | && warn_on_deprecated | |
17760 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) | |
17761 | { | |
17762 | if (inst.instruction >= 0x10000) | |
17763 | { | |
5c3696f8 | 17764 | as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are " |
5a01bb1d MGD |
17765 | "deprecated in ARMv8")); |
17766 | now_it.warn_deprecated = TRUE; | |
17767 | } | |
17768 | else | |
17769 | { | |
17770 | const struct depr_insn_mask *p = depr_it_insns; | |
17771 | ||
17772 | while (p->mask != 0) | |
17773 | { | |
17774 | if ((inst.instruction & p->mask) == p->pattern) | |
17775 | { | |
5c3696f8 | 17776 | as_tsktsk (_("IT blocks containing 16-bit Thumb instructions " |
5a01bb1d MGD |
17777 | "of the following class are deprecated in ARMv8: " |
17778 | "%s"), p->description); | |
17779 | now_it.warn_deprecated = TRUE; | |
17780 | break; | |
17781 | } | |
17782 | ||
17783 | ++p; | |
17784 | } | |
17785 | } | |
17786 | ||
17787 | if (now_it.block_length > 1) | |
17788 | { | |
5c3696f8 | 17789 | as_tsktsk (_("IT blocks containing more than one conditional " |
0a8897c7 | 17790 | "instruction are deprecated in ARMv8")); |
5a01bb1d MGD |
17791 | now_it.warn_deprecated = TRUE; |
17792 | } | |
17793 | } | |
17794 | ||
e07e6e58 NC |
17795 | is_last = (now_it.mask == 0x10); |
17796 | if (is_last) | |
17797 | { | |
17798 | now_it.state = OUTSIDE_IT_BLOCK; | |
17799 | now_it.mask = 0; | |
17800 | } | |
17801 | } | |
17802 | ||
17803 | static void | |
17804 | force_automatic_it_block_close (void) | |
17805 | { | |
17806 | if (now_it.state == AUTOMATIC_IT_BLOCK) | |
17807 | { | |
17808 | close_automatic_it_block (); | |
17809 | now_it.state = OUTSIDE_IT_BLOCK; | |
17810 | now_it.mask = 0; | |
17811 | } | |
17812 | } | |
17813 | ||
17814 | static int | |
17815 | in_it_block (void) | |
17816 | { | |
17817 | if (!now_it.state_handled) | |
17818 | handle_it_state (); | |
17819 | ||
17820 | return now_it.state != OUTSIDE_IT_BLOCK; | |
17821 | } | |
17822 | ||
ff8646ee TP |
17823 | /* Whether OPCODE only has T32 encoding. Since this function is only used by |
17824 | t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed | |
17825 | here, hence the "known" in the function name. */ | |
fc289b0a TP |
17826 | |
17827 | static bfd_boolean | |
ff8646ee | 17828 | known_t32_only_insn (const struct asm_opcode *opcode) |
fc289b0a TP |
17829 | { |
17830 | /* Original Thumb-1 wide instruction. */ | |
17831 | if (opcode->tencode == do_t_blx | |
17832 | || opcode->tencode == do_t_branch23 | |
17833 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr) | |
17834 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)) | |
17835 | return TRUE; | |
17836 | ||
ff8646ee TP |
17837 | /* Wide-only instruction added to ARMv8-M. */ |
17838 | if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m) | |
17839 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics) | |
17840 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m) | |
17841 | || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div)) | |
17842 | return TRUE; | |
17843 | ||
17844 | return FALSE; | |
17845 | } | |
17846 | ||
17847 | /* Whether wide instruction variant can be used if available for a valid OPCODE | |
17848 | in ARCH. */ | |
17849 | ||
17850 | static bfd_boolean | |
17851 | t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode) | |
17852 | { | |
17853 | if (known_t32_only_insn (opcode)) | |
17854 | return TRUE; | |
17855 | ||
17856 | /* Instruction with narrow and wide encoding added to ARMv8-M. Availability | |
17857 | of variant T3 of B.W is checked in do_t_branch. */ | |
17858 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m) | |
17859 | && opcode->tencode == do_t_branch) | |
17860 | return TRUE; | |
17861 | ||
17862 | /* Wide instruction variants of all instructions with narrow *and* wide | |
17863 | variants become available with ARMv6t2. Other opcodes are either | |
17864 | narrow-only or wide-only and are thus available if OPCODE is valid. */ | |
17865 | if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2)) | |
17866 | return TRUE; | |
17867 | ||
17868 | /* OPCODE with narrow only instruction variant or wide variant not | |
17869 | available. */ | |
fc289b0a TP |
17870 | return FALSE; |
17871 | } | |
17872 | ||
c19d1205 ZW |
17873 | void |
17874 | md_assemble (char *str) | |
b99bd4ef | 17875 | { |
c19d1205 ZW |
17876 | char *p = str; |
17877 | const struct asm_opcode * opcode; | |
b99bd4ef | 17878 | |
c19d1205 ZW |
17879 | /* Align the previous label if needed. */ |
17880 | if (last_label_seen != NULL) | |
b99bd4ef | 17881 | { |
c19d1205 ZW |
17882 | symbol_set_frag (last_label_seen, frag_now); |
17883 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
17884 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
17885 | } |
17886 | ||
c19d1205 ZW |
17887 | memset (&inst, '\0', sizeof (inst)); |
17888 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 17889 | |
c19d1205 ZW |
17890 | opcode = opcode_lookup (&p); |
17891 | if (!opcode) | |
b99bd4ef | 17892 | { |
c19d1205 | 17893 | /* It wasn't an instruction, but it might be a register alias of |
dcbf9037 | 17894 | the form alias .req reg, or a Neon .dn/.qn directive. */ |
c921be7d | 17895 | if (! create_register_alias (str, p) |
477330fc | 17896 | && ! create_neon_reg_alias (str, p)) |
c19d1205 | 17897 | as_bad (_("bad instruction `%s'"), str); |
b99bd4ef | 17898 | |
b99bd4ef NC |
17899 | return; |
17900 | } | |
17901 | ||
278df34e | 17902 | if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated) |
5c3696f8 | 17903 | as_tsktsk (_("s suffix on comparison instruction is deprecated")); |
088fa78e | 17904 | |
037e8744 JB |
17905 | /* The value which unconditional instructions should have in place of the |
17906 | condition field. */ | |
17907 | inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1; | |
17908 | ||
c19d1205 | 17909 | if (thumb_mode) |
b99bd4ef | 17910 | { |
e74cfd16 | 17911 | arm_feature_set variant; |
8f06b2d8 PB |
17912 | |
17913 | variant = cpu_variant; | |
17914 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
17915 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
17916 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 17917 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
17918 | if (!opcode->tvariant |
17919 | || (thumb_mode == 1 | |
17920 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 17921 | { |
84b52b66 | 17922 | as_bad (_("selected processor does not support `%s' in Thumb mode"), str); |
b99bd4ef NC |
17923 | return; |
17924 | } | |
c19d1205 ZW |
17925 | if (inst.cond != COND_ALWAYS && !unified_syntax |
17926 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 17927 | { |
c19d1205 | 17928 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
17929 | return; |
17930 | } | |
17931 | ||
fc289b0a TP |
17932 | /* Two things are addressed here: |
17933 | 1) Implicit require narrow instructions on Thumb-1. | |
17934 | This avoids relaxation accidentally introducing Thumb-2 | |
17935 | instructions. | |
17936 | 2) Reject wide instructions in non Thumb-2 cores. | |
17937 | ||
17938 | Only instructions with narrow and wide variants need to be handled | |
17939 | but selecting all non wide-only instructions is easier. */ | |
17940 | if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) | |
ff8646ee | 17941 | && !t32_insn_ok (variant, opcode)) |
076d447c | 17942 | { |
fc289b0a TP |
17943 | if (inst.size_req == 0) |
17944 | inst.size_req = 2; | |
17945 | else if (inst.size_req == 4) | |
752d5da4 | 17946 | { |
ff8646ee TP |
17947 | if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m)) |
17948 | as_bad (_("selected processor does not support 32bit wide " | |
17949 | "variant of instruction `%s'"), str); | |
17950 | else | |
17951 | as_bad (_("selected processor does not support `%s' in " | |
17952 | "Thumb-2 mode"), str); | |
fc289b0a | 17953 | return; |
752d5da4 | 17954 | } |
076d447c PB |
17955 | } |
17956 | ||
c19d1205 ZW |
17957 | inst.instruction = opcode->tvalue; |
17958 | ||
5be8be5d | 17959 | if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE)) |
477330fc RM |
17960 | { |
17961 | /* Prepare the it_insn_type for those encodings that don't set | |
17962 | it. */ | |
17963 | it_fsm_pre_encode (); | |
c19d1205 | 17964 | |
477330fc | 17965 | opcode->tencode (); |
e07e6e58 | 17966 | |
477330fc RM |
17967 | it_fsm_post_encode (); |
17968 | } | |
e27ec89e | 17969 | |
0110f2b8 | 17970 | if (!(inst.error || inst.relax)) |
b99bd4ef | 17971 | { |
9c2799c2 | 17972 | gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
c19d1205 ZW |
17973 | inst.size = (inst.instruction > 0xffff ? 4 : 2); |
17974 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 17975 | { |
c19d1205 | 17976 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
17977 | return; |
17978 | } | |
17979 | } | |
076d447c PB |
17980 | |
17981 | /* Something has gone badly wrong if we try to relax a fixed size | |
477330fc | 17982 | instruction. */ |
9c2799c2 | 17983 | gas_assert (inst.size_req == 0 || !inst.relax); |
076d447c | 17984 | |
e74cfd16 PB |
17985 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
17986 | *opcode->tvariant); | |
ee065d83 | 17987 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
fc289b0a TP |
17988 | set those bits when Thumb-2 32-bit instructions are seen. The impact |
17989 | of relaxable instructions will be considered later after we finish all | |
17990 | relaxation. */ | |
ff8646ee TP |
17991 | if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any)) |
17992 | variant = arm_arch_none; | |
17993 | else | |
17994 | variant = cpu_variant; | |
17995 | if (inst.size == 4 && !t32_insn_ok (variant, opcode)) | |
e74cfd16 PB |
17996 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
17997 | arm_ext_v6t2); | |
cd000bff | 17998 | |
88714cb8 DG |
17999 | check_neon_suffixes; |
18000 | ||
cd000bff | 18001 | if (!inst.error) |
c877a2f2 NC |
18002 | { |
18003 | mapping_state (MAP_THUMB); | |
18004 | } | |
c19d1205 | 18005 | } |
3e9e4fcf | 18006 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 | 18007 | { |
845b51d6 PB |
18008 | bfd_boolean is_bx; |
18009 | ||
18010 | /* bx is allowed on v5 cores, and sometimes on v4 cores. */ | |
18011 | is_bx = (opcode->aencode == do_bx); | |
18012 | ||
c19d1205 | 18013 | /* Check that this instruction is supported for this CPU. */ |
845b51d6 PB |
18014 | if (!(is_bx && fix_v4bx) |
18015 | && !(opcode->avariant && | |
18016 | ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))) | |
b99bd4ef | 18017 | { |
84b52b66 | 18018 | as_bad (_("selected processor does not support `%s' in ARM mode"), str); |
c19d1205 | 18019 | return; |
b99bd4ef | 18020 | } |
c19d1205 | 18021 | if (inst.size_req) |
b99bd4ef | 18022 | { |
c19d1205 ZW |
18023 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
18024 | return; | |
b99bd4ef NC |
18025 | } |
18026 | ||
c19d1205 ZW |
18027 | inst.instruction = opcode->avalue; |
18028 | if (opcode->tag == OT_unconditionalF) | |
eff0bc54 | 18029 | inst.instruction |= 0xFU << 28; |
c19d1205 ZW |
18030 | else |
18031 | inst.instruction |= inst.cond << 28; | |
18032 | inst.size = INSN_SIZE; | |
5be8be5d | 18033 | if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE)) |
477330fc RM |
18034 | { |
18035 | it_fsm_pre_encode (); | |
18036 | opcode->aencode (); | |
18037 | it_fsm_post_encode (); | |
18038 | } | |
ee065d83 | 18039 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
477330fc | 18040 | on a hypothetical non-thumb v5 core. */ |
845b51d6 | 18041 | if (is_bx) |
e74cfd16 | 18042 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); |
ee065d83 | 18043 | else |
e74cfd16 PB |
18044 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
18045 | *opcode->avariant); | |
88714cb8 DG |
18046 | |
18047 | check_neon_suffixes; | |
18048 | ||
cd000bff | 18049 | if (!inst.error) |
c877a2f2 NC |
18050 | { |
18051 | mapping_state (MAP_ARM); | |
18052 | } | |
b99bd4ef | 18053 | } |
3e9e4fcf JB |
18054 | else |
18055 | { | |
18056 | as_bad (_("attempt to use an ARM instruction on a Thumb-only processor " | |
18057 | "-- `%s'"), str); | |
18058 | return; | |
18059 | } | |
c19d1205 ZW |
18060 | output_inst (str); |
18061 | } | |
b99bd4ef | 18062 | |
e07e6e58 NC |
18063 | static void |
18064 | check_it_blocks_finished (void) | |
18065 | { | |
18066 | #ifdef OBJ_ELF | |
18067 | asection *sect; | |
18068 | ||
18069 | for (sect = stdoutput->sections; sect != NULL; sect = sect->next) | |
18070 | if (seg_info (sect)->tc_segment_info_data.current_it.state | |
18071 | == MANUAL_IT_BLOCK) | |
18072 | { | |
18073 | as_warn (_("section '%s' finished with an open IT block."), | |
18074 | sect->name); | |
18075 | } | |
18076 | #else | |
18077 | if (now_it.state == MANUAL_IT_BLOCK) | |
18078 | as_warn (_("file finished with an open IT block.")); | |
18079 | #endif | |
18080 | } | |
18081 | ||
c19d1205 ZW |
18082 | /* Various frobbings of labels and their addresses. */ |
18083 | ||
18084 | void | |
18085 | arm_start_line_hook (void) | |
18086 | { | |
18087 | last_label_seen = NULL; | |
b99bd4ef NC |
18088 | } |
18089 | ||
c19d1205 ZW |
18090 | void |
18091 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 18092 | { |
c19d1205 | 18093 | last_label_seen = sym; |
b99bd4ef | 18094 | |
c19d1205 | 18095 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 18096 | |
c19d1205 ZW |
18097 | #if defined OBJ_COFF || defined OBJ_ELF |
18098 | ARM_SET_INTERWORK (sym, support_interwork); | |
18099 | #endif | |
b99bd4ef | 18100 | |
e07e6e58 NC |
18101 | force_automatic_it_block_close (); |
18102 | ||
5f4273c7 | 18103 | /* Note - do not allow local symbols (.Lxxx) to be labelled |
c19d1205 ZW |
18104 | as Thumb functions. This is because these labels, whilst |
18105 | they exist inside Thumb code, are not the entry points for | |
18106 | possible ARM->Thumb calls. Also, these labels can be used | |
18107 | as part of a computed goto or switch statement. eg gcc | |
18108 | can generate code that looks like this: | |
b99bd4ef | 18109 | |
c19d1205 ZW |
18110 | ldr r2, [pc, .Laaa] |
18111 | lsl r3, r3, #2 | |
18112 | ldr r2, [r3, r2] | |
18113 | mov pc, r2 | |
b99bd4ef | 18114 | |
c19d1205 ZW |
18115 | .Lbbb: .word .Lxxx |
18116 | .Lccc: .word .Lyyy | |
18117 | ..etc... | |
18118 | .Laaa: .word Lbbb | |
b99bd4ef | 18119 | |
c19d1205 ZW |
18120 | The first instruction loads the address of the jump table. |
18121 | The second instruction converts a table index into a byte offset. | |
18122 | The third instruction gets the jump address out of the table. | |
18123 | The fourth instruction performs the jump. | |
b99bd4ef | 18124 | |
c19d1205 ZW |
18125 | If the address stored at .Laaa is that of a symbol which has the |
18126 | Thumb_Func bit set, then the linker will arrange for this address | |
18127 | to have the bottom bit set, which in turn would mean that the | |
18128 | address computation performed by the third instruction would end | |
18129 | up with the bottom bit set. Since the ARM is capable of unaligned | |
18130 | word loads, the instruction would then load the incorrect address | |
18131 | out of the jump table, and chaos would ensue. */ | |
18132 | if (label_is_thumb_function_name | |
18133 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
18134 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 18135 | { |
c19d1205 ZW |
18136 | /* When the address of a Thumb function is taken the bottom |
18137 | bit of that address should be set. This will allow | |
18138 | interworking between Arm and Thumb functions to work | |
18139 | correctly. */ | |
b99bd4ef | 18140 | |
c19d1205 | 18141 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 18142 | |
c19d1205 | 18143 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 18144 | } |
07a53e5c | 18145 | |
07a53e5c | 18146 | dwarf2_emit_label (sym); |
b99bd4ef NC |
18147 | } |
18148 | ||
c921be7d | 18149 | bfd_boolean |
c19d1205 | 18150 | arm_data_in_code (void) |
b99bd4ef | 18151 | { |
c19d1205 | 18152 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 18153 | { |
c19d1205 ZW |
18154 | *input_line_pointer = '/'; |
18155 | input_line_pointer += 5; | |
18156 | *input_line_pointer = 0; | |
c921be7d | 18157 | return TRUE; |
b99bd4ef NC |
18158 | } |
18159 | ||
c921be7d | 18160 | return FALSE; |
b99bd4ef NC |
18161 | } |
18162 | ||
c19d1205 ZW |
18163 | char * |
18164 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 18165 | { |
c19d1205 | 18166 | int len; |
b99bd4ef | 18167 | |
c19d1205 ZW |
18168 | if (thumb_mode && (len = strlen (name)) > 5 |
18169 | && streq (name + len - 5, "/data")) | |
18170 | *(name + len - 5) = 0; | |
b99bd4ef | 18171 | |
c19d1205 | 18172 | return name; |
b99bd4ef | 18173 | } |
c19d1205 ZW |
18174 | \f |
18175 | /* Table of all register names defined by default. The user can | |
18176 | define additional names with .req. Note that all register names | |
18177 | should appear in both upper and lowercase variants. Some registers | |
18178 | also have mixed-case names. */ | |
b99bd4ef | 18179 | |
dcbf9037 | 18180 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 } |
c19d1205 | 18181 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) |
5287ad62 | 18182 | #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t) |
c19d1205 ZW |
18183 | #define REGSET(p,t) \ |
18184 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
18185 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
18186 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
18187 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
5287ad62 JB |
18188 | #define REGSETH(p,t) \ |
18189 | REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \ | |
18190 | REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \ | |
18191 | REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \ | |
18192 | REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t) | |
18193 | #define REGSET2(p,t) \ | |
18194 | REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \ | |
18195 | REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \ | |
18196 | REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \ | |
18197 | REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t) | |
90ec0d68 MGD |
18198 | #define SPLRBANK(base,bank,t) \ |
18199 | REGDEF(lr_##bank, 768|((base+0)<<16), t), \ | |
18200 | REGDEF(sp_##bank, 768|((base+1)<<16), t), \ | |
18201 | REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \ | |
18202 | REGDEF(LR_##bank, 768|((base+0)<<16), t), \ | |
18203 | REGDEF(SP_##bank, 768|((base+1)<<16), t), \ | |
18204 | REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t) | |
7ed4c4c5 | 18205 | |
c19d1205 | 18206 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 18207 | { |
c19d1205 ZW |
18208 | /* ARM integer registers. */ |
18209 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 18210 | |
c19d1205 ZW |
18211 | /* ATPCS synonyms. */ |
18212 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
18213 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
18214 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 18215 | |
c19d1205 ZW |
18216 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
18217 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
18218 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 18219 | |
c19d1205 ZW |
18220 | /* Well-known aliases. */ |
18221 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
18222 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
18223 | ||
18224 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
18225 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
18226 | ||
18227 | /* Coprocessor numbers. */ | |
18228 | REGSET(p, CP), REGSET(P, CP), | |
18229 | ||
18230 | /* Coprocessor register numbers. The "cr" variants are for backward | |
18231 | compatibility. */ | |
18232 | REGSET(c, CN), REGSET(C, CN), | |
18233 | REGSET(cr, CN), REGSET(CR, CN), | |
18234 | ||
90ec0d68 MGD |
18235 | /* ARM banked registers. */ |
18236 | REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB), | |
18237 | REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB), | |
18238 | REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB), | |
18239 | REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB), | |
18240 | REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB), | |
18241 | REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB), | |
18242 | REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB), | |
18243 | ||
18244 | REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB), | |
18245 | REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB), | |
18246 | REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB), | |
18247 | REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB), | |
18248 | REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB), | |
1472d06f | 18249 | REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB), |
90ec0d68 MGD |
18250 | REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB), |
18251 | REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB), | |
18252 | ||
18253 | SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB), | |
18254 | SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB), | |
18255 | SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB), | |
18256 | SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB), | |
18257 | SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB), | |
18258 | REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB), | |
18259 | REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB), | |
fa94de6b | 18260 | REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB), |
90ec0d68 MGD |
18261 | REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB), |
18262 | ||
c19d1205 ZW |
18263 | /* FPA registers. */ |
18264 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
18265 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
18266 | ||
18267 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
18268 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
18269 | ||
18270 | /* VFP SP registers. */ | |
5287ad62 JB |
18271 | REGSET(s,VFS), REGSET(S,VFS), |
18272 | REGSETH(s,VFS), REGSETH(S,VFS), | |
c19d1205 ZW |
18273 | |
18274 | /* VFP DP Registers. */ | |
5287ad62 JB |
18275 | REGSET(d,VFD), REGSET(D,VFD), |
18276 | /* Extra Neon DP registers. */ | |
18277 | REGSETH(d,VFD), REGSETH(D,VFD), | |
18278 | ||
18279 | /* Neon QP registers. */ | |
18280 | REGSET2(q,NQ), REGSET2(Q,NQ), | |
c19d1205 ZW |
18281 | |
18282 | /* VFP control registers. */ | |
18283 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
18284 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
cd2cf30b PB |
18285 | REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC), |
18286 | REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC), | |
18287 | REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC), | |
18288 | REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC), | |
c19d1205 ZW |
18289 | |
18290 | /* Maverick DSP coprocessor registers. */ | |
18291 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
18292 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
18293 | ||
18294 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
18295 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
18296 | REGDEF(dspsc,0,DSPSC), | |
18297 | ||
18298 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
18299 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
18300 | REGDEF(DSPSC,0,DSPSC), | |
18301 | ||
18302 | /* iWMMXt data registers - p0, c0-15. */ | |
18303 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
18304 | ||
18305 | /* iWMMXt control registers - p1, c0-3. */ | |
18306 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
18307 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
18308 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
18309 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
18310 | ||
18311 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
18312 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
18313 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
18314 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
18315 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
18316 | ||
18317 | /* XScale accumulator registers. */ | |
18318 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
18319 | }; | |
18320 | #undef REGDEF | |
18321 | #undef REGNUM | |
18322 | #undef REGSET | |
7ed4c4c5 | 18323 | |
c19d1205 ZW |
18324 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
18325 | within psr_required_here. */ | |
18326 | static const struct asm_psr psrs[] = | |
18327 | { | |
18328 | /* Backward compatibility notation. Note that "all" is no longer | |
18329 | truly all possible PSR bits. */ | |
18330 | {"all", PSR_c | PSR_f}, | |
18331 | {"flg", PSR_f}, | |
18332 | {"ctl", PSR_c}, | |
18333 | ||
18334 | /* Individual flags. */ | |
18335 | {"f", PSR_f}, | |
18336 | {"c", PSR_c}, | |
18337 | {"x", PSR_x}, | |
18338 | {"s", PSR_s}, | |
59b42a0d | 18339 | |
c19d1205 ZW |
18340 | /* Combinations of flags. */ |
18341 | {"fs", PSR_f | PSR_s}, | |
18342 | {"fx", PSR_f | PSR_x}, | |
18343 | {"fc", PSR_f | PSR_c}, | |
18344 | {"sf", PSR_s | PSR_f}, | |
18345 | {"sx", PSR_s | PSR_x}, | |
18346 | {"sc", PSR_s | PSR_c}, | |
18347 | {"xf", PSR_x | PSR_f}, | |
18348 | {"xs", PSR_x | PSR_s}, | |
18349 | {"xc", PSR_x | PSR_c}, | |
18350 | {"cf", PSR_c | PSR_f}, | |
18351 | {"cs", PSR_c | PSR_s}, | |
18352 | {"cx", PSR_c | PSR_x}, | |
18353 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
18354 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
18355 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
18356 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
18357 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
18358 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
18359 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
18360 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
18361 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
18362 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
18363 | {"scf", PSR_s | PSR_c | PSR_f}, | |
18364 | {"scx", PSR_s | PSR_c | PSR_x}, | |
18365 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
18366 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
18367 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
18368 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
18369 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
18370 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
18371 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
18372 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
18373 | {"csf", PSR_c | PSR_s | PSR_f}, | |
18374 | {"csx", PSR_c | PSR_s | PSR_x}, | |
18375 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
18376 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
18377 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
18378 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
18379 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
18380 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
18381 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
18382 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
18383 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
18384 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
18385 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
18386 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
18387 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
18388 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
18389 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
18390 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
18391 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
18392 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
18393 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
18394 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
18395 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
18396 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
18397 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
18398 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
18399 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
18400 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
18401 | }; | |
18402 | ||
62b3e311 PB |
18403 | /* Table of V7M psr names. */ |
18404 | static const struct asm_psr v7m_psrs[] = | |
18405 | { | |
2b744c99 PB |
18406 | {"apsr", 0 }, {"APSR", 0 }, |
18407 | {"iapsr", 1 }, {"IAPSR", 1 }, | |
18408 | {"eapsr", 2 }, {"EAPSR", 2 }, | |
18409 | {"psr", 3 }, {"PSR", 3 }, | |
18410 | {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 }, | |
18411 | {"ipsr", 5 }, {"IPSR", 5 }, | |
18412 | {"epsr", 6 }, {"EPSR", 6 }, | |
18413 | {"iepsr", 7 }, {"IEPSR", 7 }, | |
18414 | {"msp", 8 }, {"MSP", 8 }, | |
18415 | {"psp", 9 }, {"PSP", 9 }, | |
18416 | {"primask", 16}, {"PRIMASK", 16}, | |
18417 | {"basepri", 17}, {"BASEPRI", 17}, | |
00bbc0bd NC |
18418 | {"basepri_max", 18}, {"BASEPRI_MAX", 18}, |
18419 | {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */ | |
2b744c99 PB |
18420 | {"faultmask", 19}, {"FAULTMASK", 19}, |
18421 | {"control", 20}, {"CONTROL", 20} | |
62b3e311 PB |
18422 | }; |
18423 | ||
c19d1205 ZW |
18424 | /* Table of all shift-in-operand names. */ |
18425 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 18426 | { |
c19d1205 ZW |
18427 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
18428 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
18429 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
18430 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
18431 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
18432 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
18433 | }; | |
b99bd4ef | 18434 | |
c19d1205 ZW |
18435 | /* Table of all explicit relocation names. */ |
18436 | #ifdef OBJ_ELF | |
18437 | static struct reloc_entry reloc_names[] = | |
18438 | { | |
18439 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
18440 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
18441 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
18442 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
18443 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
18444 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
18445 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
18446 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
18447 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
18448 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
b43420e6 | 18449 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}, |
0855e32b NS |
18450 | { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}, |
18451 | { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC}, | |
477330fc | 18452 | { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC}, |
0855e32b | 18453 | { "tlscall", BFD_RELOC_ARM_TLS_CALL}, |
477330fc | 18454 | { "TLSCALL", BFD_RELOC_ARM_TLS_CALL}, |
0855e32b | 18455 | { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ}, |
477330fc | 18456 | { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ} |
c19d1205 ZW |
18457 | }; |
18458 | #endif | |
b99bd4ef | 18459 | |
c19d1205 ZW |
18460 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
18461 | static const struct asm_cond conds[] = | |
18462 | { | |
18463 | {"eq", 0x0}, | |
18464 | {"ne", 0x1}, | |
18465 | {"cs", 0x2}, {"hs", 0x2}, | |
18466 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
18467 | {"mi", 0x4}, | |
18468 | {"pl", 0x5}, | |
18469 | {"vs", 0x6}, | |
18470 | {"vc", 0x7}, | |
18471 | {"hi", 0x8}, | |
18472 | {"ls", 0x9}, | |
18473 | {"ge", 0xa}, | |
18474 | {"lt", 0xb}, | |
18475 | {"gt", 0xc}, | |
18476 | {"le", 0xd}, | |
18477 | {"al", 0xe} | |
18478 | }; | |
bfae80f2 | 18479 | |
e797f7e0 | 18480 | #define UL_BARRIER(L,U,CODE,FEAT) \ |
823d2571 TG |
18481 | { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \ |
18482 | { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) } | |
e797f7e0 | 18483 | |
62b3e311 PB |
18484 | static struct asm_barrier_opt barrier_opt_names[] = |
18485 | { | |
e797f7e0 MGD |
18486 | UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER), |
18487 | UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER), | |
18488 | UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8), | |
18489 | UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER), | |
18490 | UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER), | |
18491 | UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER), | |
18492 | UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER), | |
18493 | UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8), | |
18494 | UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER), | |
18495 | UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER), | |
18496 | UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER), | |
18497 | UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER), | |
18498 | UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8), | |
18499 | UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER), | |
18500 | UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER), | |
18501 | UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8) | |
62b3e311 PB |
18502 | }; |
18503 | ||
e797f7e0 MGD |
18504 | #undef UL_BARRIER |
18505 | ||
c19d1205 ZW |
18506 | /* Table of ARM-format instructions. */ |
18507 | ||
18508 | /* Macros for gluing together operand strings. N.B. In all cases | |
18509 | other than OPS0, the trailing OP_stop comes from default | |
18510 | zero-initialization of the unspecified elements of the array. */ | |
18511 | #define OPS0() { OP_stop, } | |
18512 | #define OPS1(a) { OP_##a, } | |
18513 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
18514 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
18515 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
18516 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
18517 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
18518 | ||
5be8be5d DG |
18519 | /* These macros are similar to the OPSn, but do not prepend the OP_ prefix. |
18520 | This is useful when mixing operands for ARM and THUMB, i.e. using the | |
18521 | MIX_ARM_THUMB_OPERANDS macro. | |
18522 | In order to use these macros, prefix the number of operands with _ | |
18523 | e.g. _3. */ | |
18524 | #define OPS_1(a) { a, } | |
18525 | #define OPS_2(a,b) { a,b, } | |
18526 | #define OPS_3(a,b,c) { a,b,c, } | |
18527 | #define OPS_4(a,b,c,d) { a,b,c,d, } | |
18528 | #define OPS_5(a,b,c,d,e) { a,b,c,d,e, } | |
18529 | #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, } | |
18530 | ||
c19d1205 ZW |
18531 | /* These macros abstract out the exact format of the mnemonic table and |
18532 | save some repeated characters. */ | |
18533 | ||
18534 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
18535 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 18536 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 18537 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
18538 | |
18539 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
18540 | a T_MNEM_xyz enumerator. */ | |
18541 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
e07e6e58 | 18542 | TxCE (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 18543 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 18544 | TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 ZW |
18545 | |
18546 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
18547 | infix after the third character. */ | |
18548 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 18549 | { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ |
1887dd22 | 18550 | THUMB_VARIANT, do_##ae, do_##te } |
088fa78e | 18551 | #define TxC3w(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 18552 | { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \ |
088fa78e | 18553 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 18554 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 18555 | TxC3 (mnem, aop, 0x##top, nops, ops, ae, te) |
088fa78e | 18556 | #define TC3w(mnem, aop, top, nops, ops, ae, te) \ |
e07e6e58 | 18557 | TxC3w (mnem, aop, 0x##top, nops, ops, ae, te) |
c19d1205 | 18558 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 18559 | TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
088fa78e | 18560 | #define tC3w(mnem, aop, top, nops, ops, ae, te) \ |
21d799b5 | 18561 | TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te) |
c19d1205 | 18562 | |
c19d1205 | 18563 | /* Mnemonic that cannot be conditionalized. The ARM condition-code |
dfa9f0d5 PB |
18564 | field is still 0xE. Many of the Thumb variants can be executed |
18565 | conditionally, so this is checked separately. */ | |
c19d1205 | 18566 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
21d799b5 | 18567 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 18568 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 | 18569 | |
dd5181d5 KT |
18570 | /* Same as TUE but the encoding function for ARM and Thumb modes is the same. |
18571 | Used by mnemonics that have very minimal differences in the encoding for | |
18572 | ARM and Thumb variants and can be handled in a common function. */ | |
18573 | #define TUEc(mnem, op, top, nops, ops, en) \ | |
18574 | { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
18575 | THUMB_VARIANT, do_##en, do_##en } | |
18576 | ||
c19d1205 ZW |
18577 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM |
18578 | condition code field. */ | |
18579 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
21d799b5 | 18580 | { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ |
1887dd22 | 18581 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
18582 | |
18583 | /* ARM-only variants of all the above. */ | |
6a86118a | 18584 | #define CE(mnem, op, nops, ops, ae) \ |
21d799b5 | 18585 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
6a86118a NC |
18586 | |
18587 | #define C3(mnem, op, nops, ops, ae) \ | |
18588 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
18589 | ||
e3cb604e PB |
18590 | /* Legacy mnemonics that always have conditional infix after the third |
18591 | character. */ | |
18592 | #define CL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18593 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
18594 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
18595 | ||
8f06b2d8 PB |
18596 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
18597 | #define cCE(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18598 | { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 18599 | |
e3cb604e PB |
18600 | /* Legacy coprocessor instructions where conditional infix and conditional |
18601 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
18602 | not just the potentially ambiguous ones. */ | |
18603 | #define cCL(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18604 | { mnem, OPS##nops ops, OT_cinfix3_legacy, \ |
e3cb604e PB |
18605 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
18606 | ||
18607 | /* Coprocessor, takes either a suffix or a position-3 infix | |
18608 | (for an FPA corner case). */ | |
18609 | #define C3E(mnem, op, nops, ops, ae) \ | |
21d799b5 | 18610 | { mnem, OPS##nops ops, OT_csuf_or_in3, \ |
e3cb604e | 18611 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } |
8f06b2d8 | 18612 | |
6a86118a | 18613 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
21d799b5 NC |
18614 | { m1 #m2 m3, OPS##nops ops, \ |
18615 | sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \ | |
6a86118a NC |
18616 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } |
18617 | ||
18618 | #define CM(m1, m2, op, nops, ops, ae) \ | |
e07e6e58 NC |
18619 | xCM_ (m1, , m2, op, nops, ops, ae), \ |
18620 | xCM_ (m1, eq, m2, op, nops, ops, ae), \ | |
18621 | xCM_ (m1, ne, m2, op, nops, ops, ae), \ | |
18622 | xCM_ (m1, cs, m2, op, nops, ops, ae), \ | |
18623 | xCM_ (m1, hs, m2, op, nops, ops, ae), \ | |
18624 | xCM_ (m1, cc, m2, op, nops, ops, ae), \ | |
18625 | xCM_ (m1, ul, m2, op, nops, ops, ae), \ | |
18626 | xCM_ (m1, lo, m2, op, nops, ops, ae), \ | |
18627 | xCM_ (m1, mi, m2, op, nops, ops, ae), \ | |
18628 | xCM_ (m1, pl, m2, op, nops, ops, ae), \ | |
18629 | xCM_ (m1, vs, m2, op, nops, ops, ae), \ | |
18630 | xCM_ (m1, vc, m2, op, nops, ops, ae), \ | |
18631 | xCM_ (m1, hi, m2, op, nops, ops, ae), \ | |
18632 | xCM_ (m1, ls, m2, op, nops, ops, ae), \ | |
18633 | xCM_ (m1, ge, m2, op, nops, ops, ae), \ | |
18634 | xCM_ (m1, lt, m2, op, nops, ops, ae), \ | |
18635 | xCM_ (m1, gt, m2, op, nops, ops, ae), \ | |
18636 | xCM_ (m1, le, m2, op, nops, ops, ae), \ | |
18637 | xCM_ (m1, al, m2, op, nops, ops, ae) | |
6a86118a NC |
18638 | |
18639 | #define UE(mnem, op, nops, ops, ae) \ | |
18640 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
18641 | ||
18642 | #define UF(mnem, op, nops, ops, ae) \ | |
18643 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
18644 | ||
5287ad62 JB |
18645 | /* Neon data-processing. ARM versions are unconditional with cond=0xf. |
18646 | The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we | |
18647 | use the same encoding function for each. */ | |
18648 | #define NUF(mnem, op, nops, ops, enc) \ | |
18649 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \ | |
18650 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } | |
18651 | ||
18652 | /* Neon data processing, version which indirects through neon_enc_tab for | |
18653 | the various overloaded versions of opcodes. */ | |
18654 | #define nUF(mnem, op, nops, ops, enc) \ | |
21d799b5 | 18655 | { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
18656 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
18657 | ||
18658 | /* Neon insn with conditional suffix for the ARM version, non-overloaded | |
18659 | version. */ | |
037e8744 JB |
18660 | #define NCE_tag(mnem, op, nops, ops, enc, tag) \ |
18661 | { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \ | |
5287ad62 JB |
18662 | THUMB_VARIANT, do_##enc, do_##enc } |
18663 | ||
037e8744 | 18664 | #define NCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 18665 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
18666 | |
18667 | #define NCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 18668 | NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 18669 | |
5287ad62 | 18670 | /* Neon insn with conditional suffix for the ARM version, overloaded types. */ |
037e8744 | 18671 | #define nCE_tag(mnem, op, nops, ops, enc, tag) \ |
21d799b5 | 18672 | { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \ |
5287ad62 JB |
18673 | ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc } |
18674 | ||
037e8744 | 18675 | #define nCE(mnem, op, nops, ops, enc) \ |
e07e6e58 | 18676 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffix) |
037e8744 JB |
18677 | |
18678 | #define nCEF(mnem, op, nops, ops, enc) \ | |
e07e6e58 | 18679 | nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF) |
037e8744 | 18680 | |
c19d1205 ZW |
18681 | #define do_0 0 |
18682 | ||
c19d1205 | 18683 | static const struct asm_opcode insns[] = |
bfae80f2 | 18684 | { |
74db7efb NC |
18685 | #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */ |
18686 | #define THUMB_VARIANT & arm_ext_v4t | |
21d799b5 NC |
18687 | tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c), |
18688 | tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
18689 | tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
18690 | tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
18691 | tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
18692 | tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
18693 | tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub), | |
18694 | tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub), | |
18695 | tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
18696 | tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
18697 | tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
18698 | tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
18699 | tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
18700 | tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
18701 | tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3), | |
18702 | tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3), | |
c19d1205 ZW |
18703 | |
18704 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
18705 | for setting PSR flag bits. They are obsolete in V6 and do not | |
18706 | have Thumb equivalents. */ | |
21d799b5 NC |
18707 | tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), |
18708 | tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst), | |
18709 | CL("tstp", 110f000, 2, (RR, SH), cmp), | |
18710 | tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
18711 | tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
18712 | CL("cmpp", 150f000, 2, (RR, SH), cmp), | |
18713 | tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
18714 | tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
18715 | CL("cmnp", 170f000, 2, (RR, SH), cmp), | |
18716 | ||
18717 | tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp), | |
72d98d16 | 18718 | tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp), |
21d799b5 NC |
18719 | tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst), |
18720 | tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst), | |
18721 | ||
18722 | tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst), | |
5be8be5d DG |
18723 | tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), |
18724 | tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR, | |
18725 | OP_RRnpc), | |
18726 | OP_ADDRGLDR),ldst, t_ldst), | |
18727 | tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst), | |
21d799b5 NC |
18728 | |
18729 | tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
18730 | tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
18731 | tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
18732 | tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
18733 | tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
18734 | tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
18735 | ||
18736 | TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi), | |
18737 | TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi), | |
18738 | tCE("b", a000000, _b, 1, (EXPr), branch, t_branch), | |
18739 | TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23), | |
bfae80f2 | 18740 | |
c19d1205 | 18741 | /* Pseudo ops. */ |
21d799b5 | 18742 | tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac | 18743 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
21d799b5 | 18744 | tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop), |
74db7efb | 18745 | tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf), |
c19d1205 ZW |
18746 | |
18747 | /* Thumb-compatibility pseudo ops. */ | |
21d799b5 NC |
18748 | tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift), |
18749 | tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift), | |
18750 | tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift), | |
18751 | tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
18752 | tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift), | |
18753 | tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift), | |
18754 | tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift), | |
18755 | tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift), | |
18756 | tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg), | |
18757 | tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg), | |
18758 | tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop), | |
18759 | tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop), | |
c19d1205 | 18760 | |
16a4cf17 | 18761 | /* These may simplify to neg. */ |
21d799b5 NC |
18762 | TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
18763 | TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
16a4cf17 | 18764 | |
c921be7d NC |
18765 | #undef THUMB_VARIANT |
18766 | #define THUMB_VARIANT & arm_ext_v6 | |
18767 | ||
21d799b5 | 18768 | TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
18769 | |
18770 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
c921be7d NC |
18771 | #undef THUMB_VARIANT |
18772 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18773 | ||
21d799b5 NC |
18774 | TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), |
18775 | TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
18776 | CL("teqp", 130f000, 2, (RR, SH), cmp), | |
c19d1205 | 18777 | |
5be8be5d DG |
18778 | TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), |
18779 | TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
18780 | TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt), | |
18781 | TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt), | |
c19d1205 | 18782 | |
21d799b5 NC |
18783 | TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
18784 | TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 18785 | |
21d799b5 NC |
18786 | TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
18787 | TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
18788 | |
18789 | /* V1 instructions with no Thumb analogue at all. */ | |
21d799b5 | 18790 | CE("rsc", 0e00000, 3, (RR, oRR, SH), arit), |
c19d1205 ZW |
18791 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), |
18792 | ||
18793 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
18794 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
18795 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
18796 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
18797 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
18798 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
18799 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
18800 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
18801 | ||
c921be7d NC |
18802 | #undef ARM_VARIANT |
18803 | #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */ | |
18804 | #undef THUMB_VARIANT | |
18805 | #define THUMB_VARIANT & arm_ext_v4t | |
18806 | ||
21d799b5 NC |
18807 | tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
18808 | tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
c19d1205 | 18809 | |
c921be7d NC |
18810 | #undef THUMB_VARIANT |
18811 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18812 | ||
21d799b5 | 18813 | TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
c19d1205 ZW |
18814 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), |
18815 | ||
18816 | /* Generic coprocessor instructions. */ | |
21d799b5 NC |
18817 | TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), |
18818 | TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18819 | TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18820 | TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18821 | TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18822 | TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
db472d6f | 18823 | TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg), |
c19d1205 | 18824 | |
c921be7d NC |
18825 | #undef ARM_VARIANT |
18826 | #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */ | |
18827 | ||
21d799b5 | 18828 | CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
c19d1205 ZW |
18829 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
18830 | ||
c921be7d NC |
18831 | #undef ARM_VARIANT |
18832 | #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */ | |
18833 | #undef THUMB_VARIANT | |
18834 | #define THUMB_VARIANT & arm_ext_msr | |
18835 | ||
d2cd1205 JB |
18836 | TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs), |
18837 | TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr), | |
c19d1205 | 18838 | |
c921be7d NC |
18839 | #undef ARM_VARIANT |
18840 | #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */ | |
18841 | #undef THUMB_VARIANT | |
18842 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18843 | ||
21d799b5 NC |
18844 | TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
18845 | CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
18846 | TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
18847 | CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
18848 | TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
18849 | CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
18850 | TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
18851 | CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
c19d1205 | 18852 | |
c921be7d NC |
18853 | #undef ARM_VARIANT |
18854 | #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */ | |
18855 | #undef THUMB_VARIANT | |
18856 | #define THUMB_VARIANT & arm_ext_v4t | |
18857 | ||
5be8be5d DG |
18858 | tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
18859 | tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
18860 | tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
18861 | tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
56c0a61f RE |
18862 | tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), |
18863 | tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst), | |
c19d1205 | 18864 | |
c921be7d NC |
18865 | #undef ARM_VARIANT |
18866 | #define ARM_VARIANT & arm_ext_v4t_5 | |
18867 | ||
c19d1205 ZW |
18868 | /* ARM Architecture 4T. */ |
18869 | /* Note: bx (and blx) are required on V5, even if the processor does | |
18870 | not support Thumb. */ | |
21d799b5 | 18871 | TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx), |
c19d1205 | 18872 | |
c921be7d NC |
18873 | #undef ARM_VARIANT |
18874 | #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */ | |
18875 | #undef THUMB_VARIANT | |
18876 | #define THUMB_VARIANT & arm_ext_v5t | |
18877 | ||
c19d1205 ZW |
18878 | /* Note: blx has 2 variants; the .value coded here is for |
18879 | BLX(2). Only this variant has conditional execution. */ | |
21d799b5 NC |
18880 | TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx), |
18881 | TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
c19d1205 | 18882 | |
c921be7d NC |
18883 | #undef THUMB_VARIANT |
18884 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18885 | ||
21d799b5 NC |
18886 | TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
18887 | TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18888 | TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18889 | TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18890 | TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc), | |
18891 | TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
18892 | TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
18893 | TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
c19d1205 | 18894 | |
c921be7d | 18895 | #undef ARM_VARIANT |
74db7efb NC |
18896 | #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */ |
18897 | #undef THUMB_VARIANT | |
18898 | #define THUMB_VARIANT & arm_ext_v5exp | |
c921be7d | 18899 | |
21d799b5 NC |
18900 | TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
18901 | TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
18902 | TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
18903 | TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 18904 | |
21d799b5 NC |
18905 | TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
18906 | TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
c19d1205 | 18907 | |
21d799b5 NC |
18908 | TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), |
18909 | TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
18910 | TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
18911 | TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
c19d1205 | 18912 | |
21d799b5 NC |
18913 | TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
18914 | TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18915 | TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
18916 | TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 18917 | |
21d799b5 NC |
18918 | TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), |
18919 | TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
c19d1205 | 18920 | |
03ee1b7f NC |
18921 | TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), |
18922 | TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
18923 | TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
18924 | TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2), | |
c19d1205 | 18925 | |
c921be7d | 18926 | #undef ARM_VARIANT |
74db7efb NC |
18927 | #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */ |
18928 | #undef THUMB_VARIANT | |
18929 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 18930 | |
21d799b5 | 18931 | TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld), |
5be8be5d DG |
18932 | TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS), |
18933 | ldrd, t_ldstd), | |
18934 | TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp, | |
18935 | ADDRGLDRS), ldrd, t_ldstd), | |
c19d1205 | 18936 | |
21d799b5 NC |
18937 | TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
18938 | TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
c19d1205 | 18939 | |
c921be7d NC |
18940 | #undef ARM_VARIANT |
18941 | #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */ | |
18942 | ||
21d799b5 | 18943 | TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
c19d1205 | 18944 | |
c921be7d NC |
18945 | #undef ARM_VARIANT |
18946 | #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */ | |
18947 | #undef THUMB_VARIANT | |
18948 | #define THUMB_VARIANT & arm_ext_v6 | |
18949 | ||
21d799b5 NC |
18950 | TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
18951 | TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
18952 | tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
18953 | tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
18954 | tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
18955 | tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18956 | tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18957 | tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18958 | tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
18959 | TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend), | |
c19d1205 | 18960 | |
c921be7d | 18961 | #undef THUMB_VARIANT |
ff8646ee | 18962 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
c921be7d | 18963 | |
5be8be5d DG |
18964 | TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex), |
18965 | TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
18966 | strex, t_strex), | |
ff8646ee TP |
18967 | #undef THUMB_VARIANT |
18968 | #define THUMB_VARIANT & arm_ext_v6t2 | |
18969 | ||
21d799b5 NC |
18970 | TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), |
18971 | TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 | 18972 | |
21d799b5 NC |
18973 | TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), |
18974 | TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
62b3e311 | 18975 | |
9e3c6df6 | 18976 | /* ARM V6 not included in V7M. */ |
c921be7d NC |
18977 | #undef THUMB_VARIANT |
18978 | #define THUMB_VARIANT & arm_ext_v6_notm | |
9e3c6df6 | 18979 | TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
d709e4e6 | 18980 | TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe), |
9e3c6df6 PB |
18981 | UF(rfeib, 9900a00, 1, (RRw), rfe), |
18982 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
18983 | TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
18984 | TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
d709e4e6 RE |
18985 | UF(rfefa, 8100a00, 1, (RRw), rfe), |
18986 | TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
18987 | UF(rfeed, 9900a00, 1, (RRw), rfe), | |
9e3c6df6 | 18988 | TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 RE |
18989 | TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), |
18990 | TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs), | |
9e3c6df6 | 18991 | UF(srsib, 9c00500, 2, (oRRw, I31w), srs), |
d709e4e6 | 18992 | UF(srsfa, 9c00500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 18993 | UF(srsda, 8400500, 2, (oRRw, I31w), srs), |
d709e4e6 | 18994 | UF(srsed, 8400500, 2, (oRRw, I31w), srs), |
9e3c6df6 | 18995 | TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
d709e4e6 | 18996 | TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs), |
941c9cad | 18997 | TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c921be7d | 18998 | |
9e3c6df6 PB |
18999 | /* ARM V6 not included in V7M (eg. integer SIMD). */ |
19000 | #undef THUMB_VARIANT | |
19001 | #define THUMB_VARIANT & arm_ext_v6_dsp | |
21d799b5 NC |
19002 | TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
19003 | TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
19004 | TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19005 | TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19006 | TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19007 | /* Old name for QASX. */ |
74db7efb | 19008 | TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 19009 | TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19010 | /* Old name for QSAX. */ |
74db7efb | 19011 | TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19012 | TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19013 | TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19014 | TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19015 | TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19016 | TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19017 | /* Old name for SASX. */ |
74db7efb | 19018 | TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19019 | TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19020 | TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 19021 | TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19022 | /* Old name for SHASX. */ |
21d799b5 | 19023 | TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
74db7efb | 19024 | TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19025 | /* Old name for SHSAX. */ |
21d799b5 NC |
19026 | TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19027 | TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19028 | TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19029 | TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19030 | /* Old name for SSAX. */ |
74db7efb | 19031 | TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19032 | TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19033 | TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19034 | TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19035 | TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19036 | TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19037 | /* Old name for UASX. */ |
74db7efb | 19038 | TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19039 | TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19040 | TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 19041 | TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19042 | /* Old name for UHASX. */ |
21d799b5 NC |
19043 | TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19044 | TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19045 | /* Old name for UHSAX. */ |
21d799b5 NC |
19046 | TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19047 | TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19048 | TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19049 | TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19050 | TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
74db7efb | 19051 | TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
4f80ef3e | 19052 | /* Old name for UQASX. */ |
21d799b5 NC |
19053 | TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19054 | TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19055 | /* Old name for UQSAX. */ |
21d799b5 NC |
19056 | TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
19057 | TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19058 | TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19059 | TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19060 | TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
4f80ef3e | 19061 | /* Old name for USAX. */ |
74db7efb | 19062 | TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 | 19063 | TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
21d799b5 NC |
19064 | TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), |
19065 | TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19066 | TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19067 | TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19068 | TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19069 | TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19070 | TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
19071 | TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
19072 | TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
19073 | TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19074 | TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19075 | TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19076 | TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19077 | TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19078 | TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19079 | TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19080 | TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
19081 | TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19082 | TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19083 | TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19084 | TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19085 | TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19086 | TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19087 | TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19088 | TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19089 | TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19090 | TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
21d799b5 NC |
19091 | TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
19092 | TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
19093 | TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
19094 | TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
19095 | TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
c19d1205 | 19096 | |
c921be7d NC |
19097 | #undef ARM_VARIANT |
19098 | #define ARM_VARIANT & arm_ext_v6k | |
19099 | #undef THUMB_VARIANT | |
19100 | #define THUMB_VARIANT & arm_ext_v6k | |
19101 | ||
21d799b5 NC |
19102 | tCE("yield", 320f001, _yield, 0, (), noargs, t_hint), |
19103 | tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint), | |
19104 | tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint), | |
19105 | tCE("sev", 320f004, _sev, 0, (), noargs, t_hint), | |
c19d1205 | 19106 | |
c921be7d NC |
19107 | #undef THUMB_VARIANT |
19108 | #define THUMB_VARIANT & arm_ext_v6_notm | |
5be8be5d DG |
19109 | TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb), |
19110 | ldrexd, t_ldrexd), | |
19111 | TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp, | |
19112 | RRnpcb), strexd, t_strexd), | |
ebdca51a | 19113 | |
c921be7d | 19114 | #undef THUMB_VARIANT |
ff8646ee | 19115 | #define THUMB_VARIANT & arm_ext_v6t2_v8m |
5be8be5d DG |
19116 | TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb), |
19117 | rd_rn, rd_rn), | |
19118 | TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb), | |
19119 | rd_rn, rd_rn), | |
19120 | TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), | |
877807f8 | 19121 | strex, t_strexbh), |
5be8be5d | 19122 | TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR), |
877807f8 | 19123 | strex, t_strexbh), |
21d799b5 | 19124 | TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
c19d1205 | 19125 | |
c921be7d | 19126 | #undef ARM_VARIANT |
f4c65163 | 19127 | #define ARM_VARIANT & arm_ext_sec |
74db7efb | 19128 | #undef THUMB_VARIANT |
f4c65163 | 19129 | #define THUMB_VARIANT & arm_ext_sec |
c921be7d | 19130 | |
21d799b5 | 19131 | TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 | 19132 | |
90ec0d68 MGD |
19133 | #undef ARM_VARIANT |
19134 | #define ARM_VARIANT & arm_ext_virt | |
19135 | #undef THUMB_VARIANT | |
19136 | #define THUMB_VARIANT & arm_ext_virt | |
19137 | ||
19138 | TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc), | |
19139 | TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs), | |
19140 | ||
ddfded2f MW |
19141 | #undef ARM_VARIANT |
19142 | #define ARM_VARIANT & arm_ext_pan | |
19143 | #undef THUMB_VARIANT | |
19144 | #define THUMB_VARIANT & arm_ext_pan | |
19145 | ||
19146 | TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan), | |
19147 | ||
c921be7d | 19148 | #undef ARM_VARIANT |
74db7efb | 19149 | #define ARM_VARIANT & arm_ext_v6t2 |
f4c65163 MGD |
19150 | #undef THUMB_VARIANT |
19151 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 19152 | |
21d799b5 NC |
19153 | TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
19154 | TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
19155 | TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
19156 | TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
c19d1205 | 19157 | |
21d799b5 | 19158 | TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
21d799b5 | 19159 | TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), |
c19d1205 | 19160 | |
5be8be5d DG |
19161 | TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), |
19162 | TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
19163 | TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
19164 | TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt), | |
c19d1205 | 19165 | |
ff8646ee TP |
19166 | #undef THUMB_VARIANT |
19167 | #define THUMB_VARIANT & arm_ext_v6t2_v8m | |
19168 | TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16), | |
19169 | TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16), | |
19170 | ||
bf3eeda7 | 19171 | /* Thumb-only instructions. */ |
74db7efb | 19172 | #undef ARM_VARIANT |
bf3eeda7 NS |
19173 | #define ARM_VARIANT NULL |
19174 | TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz), | |
19175 | TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz), | |
c921be7d NC |
19176 | |
19177 | /* ARM does not really have an IT instruction, so always allow it. | |
19178 | The opcode is copied from Thumb in order to allow warnings in | |
19179 | -mimplicit-it=[never | arm] modes. */ | |
19180 | #undef ARM_VARIANT | |
19181 | #define ARM_VARIANT & arm_ext_v1 | |
ff8646ee TP |
19182 | #undef THUMB_VARIANT |
19183 | #define THUMB_VARIANT & arm_ext_v6t2 | |
c921be7d | 19184 | |
21d799b5 NC |
19185 | TUE("it", bf08, bf08, 1, (COND), it, t_it), |
19186 | TUE("itt", bf0c, bf0c, 1, (COND), it, t_it), | |
19187 | TUE("ite", bf04, bf04, 1, (COND), it, t_it), | |
19188 | TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it), | |
19189 | TUE("itet", bf06, bf06, 1, (COND), it, t_it), | |
19190 | TUE("itte", bf0a, bf0a, 1, (COND), it, t_it), | |
19191 | TUE("itee", bf02, bf02, 1, (COND), it, t_it), | |
19192 | TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it), | |
19193 | TUE("itett", bf07, bf07, 1, (COND), it, t_it), | |
19194 | TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it), | |
19195 | TUE("iteet", bf03, bf03, 1, (COND), it, t_it), | |
19196 | TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it), | |
19197 | TUE("itete", bf05, bf05, 1, (COND), it, t_it), | |
19198 | TUE("ittee", bf09, bf09, 1, (COND), it, t_it), | |
19199 | TUE("iteee", bf01, bf01, 1, (COND), it, t_it), | |
1c444d06 | 19200 | /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */ |
21d799b5 NC |
19201 | TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx), |
19202 | TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx), | |
c19d1205 | 19203 | |
92e90b6e | 19204 | /* Thumb2 only instructions. */ |
c921be7d NC |
19205 | #undef ARM_VARIANT |
19206 | #define ARM_VARIANT NULL | |
92e90b6e | 19207 | |
21d799b5 NC |
19208 | TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), |
19209 | TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
19210 | TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn), | |
19211 | TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn), | |
19212 | TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb), | |
19213 | TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb), | |
92e90b6e | 19214 | |
eea54501 MGD |
19215 | /* Hardware division instructions. */ |
19216 | #undef ARM_VARIANT | |
19217 | #define ARM_VARIANT & arm_ext_adiv | |
c921be7d NC |
19218 | #undef THUMB_VARIANT |
19219 | #define THUMB_VARIANT & arm_ext_div | |
19220 | ||
eea54501 MGD |
19221 | TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div), |
19222 | TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div), | |
62b3e311 | 19223 | |
7e806470 | 19224 | /* ARM V6M/V7 instructions. */ |
c921be7d NC |
19225 | #undef ARM_VARIANT |
19226 | #define ARM_VARIANT & arm_ext_barrier | |
19227 | #undef THUMB_VARIANT | |
19228 | #define THUMB_VARIANT & arm_ext_barrier | |
19229 | ||
ccb84d65 JB |
19230 | TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier), |
19231 | TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier), | |
19232 | TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier), | |
7e806470 | 19233 | |
62b3e311 | 19234 | /* ARM V7 instructions. */ |
c921be7d NC |
19235 | #undef ARM_VARIANT |
19236 | #define ARM_VARIANT & arm_ext_v7 | |
19237 | #undef THUMB_VARIANT | |
19238 | #define THUMB_VARIANT & arm_ext_v7 | |
19239 | ||
21d799b5 NC |
19240 | TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld), |
19241 | TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
62b3e311 | 19242 | |
74db7efb | 19243 | #undef ARM_VARIANT |
60e5ef9f | 19244 | #define ARM_VARIANT & arm_ext_mp |
74db7efb | 19245 | #undef THUMB_VARIANT |
60e5ef9f MGD |
19246 | #define THUMB_VARIANT & arm_ext_mp |
19247 | ||
19248 | TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld), | |
19249 | ||
53c4b28b MGD |
19250 | /* AArchv8 instructions. */ |
19251 | #undef ARM_VARIANT | |
19252 | #define ARM_VARIANT & arm_ext_v8 | |
4ed7ed8d TP |
19253 | |
19254 | /* Instructions shared between armv8-a and armv8-m. */ | |
53c4b28b | 19255 | #undef THUMB_VARIANT |
4ed7ed8d | 19256 | #define THUMB_VARIANT & arm_ext_atomics |
53c4b28b | 19257 | |
4ed7ed8d TP |
19258 | TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
19259 | TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
19260 | TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
19261 | TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
19262 | TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
19263 | TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn), | |
4b8c8c02 | 19264 | TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
4b8c8c02 RE |
19265 | TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn), |
19266 | TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
19267 | TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb), | |
19268 | stlex, t_stlex), | |
4b8c8c02 RE |
19269 | TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb), |
19270 | stlex, t_stlex), | |
19271 | TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb), | |
19272 | stlex, t_stlex), | |
4ed7ed8d TP |
19273 | #undef THUMB_VARIANT |
19274 | #define THUMB_VARIANT & arm_ext_v8 | |
53c4b28b | 19275 | |
4ed7ed8d TP |
19276 | tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint), |
19277 | TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt), | |
19278 | TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb), | |
19279 | ldrexd, t_ldrexd), | |
19280 | TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), | |
19281 | strexd, t_strexd), | |
8884b720 | 19282 | /* ARMv8 T32 only. */ |
74db7efb | 19283 | #undef ARM_VARIANT |
b79f7053 MGD |
19284 | #define ARM_VARIANT NULL |
19285 | TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs), | |
19286 | TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs), | |
19287 | TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs), | |
19288 | ||
33399f07 MGD |
19289 | /* FP for ARMv8. */ |
19290 | #undef ARM_VARIANT | |
a715796b | 19291 | #define ARM_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 | 19292 | #undef THUMB_VARIANT |
a715796b | 19293 | #define THUMB_VARIANT & fpu_vfp_ext_armv8xd |
33399f07 MGD |
19294 | |
19295 | nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel), | |
19296 | nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel), | |
19297 | nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel), | |
19298 | nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel), | |
73924fbc MGD |
19299 | nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), |
19300 | nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm), | |
7e8e6784 MGD |
19301 | nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta), |
19302 | nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn), | |
19303 | nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp), | |
19304 | nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm), | |
30bdf752 MGD |
19305 | nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr), |
19306 | nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz), | |
19307 | nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx), | |
19308 | nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta), | |
19309 | nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn), | |
19310 | nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp), | |
19311 | nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm), | |
33399f07 | 19312 | |
91ff7894 MGD |
19313 | /* Crypto v1 extensions. */ |
19314 | #undef ARM_VARIANT | |
19315 | #define ARM_VARIANT & fpu_crypto_ext_armv8 | |
19316 | #undef THUMB_VARIANT | |
19317 | #define THUMB_VARIANT & fpu_crypto_ext_armv8 | |
19318 | ||
19319 | nUF(aese, _aes, 2, (RNQ, RNQ), aese), | |
19320 | nUF(aesd, _aes, 2, (RNQ, RNQ), aesd), | |
19321 | nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc), | |
19322 | nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc), | |
48adcd8e MGD |
19323 | nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c), |
19324 | nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p), | |
19325 | nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m), | |
19326 | nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0), | |
19327 | nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h), | |
19328 | nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2), | |
19329 | nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1), | |
3c9017d2 MGD |
19330 | nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h), |
19331 | nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1), | |
19332 | nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0), | |
91ff7894 | 19333 | |
dd5181d5 | 19334 | #undef ARM_VARIANT |
74db7efb | 19335 | #define ARM_VARIANT & crc_ext_armv8 |
dd5181d5 KT |
19336 | #undef THUMB_VARIANT |
19337 | #define THUMB_VARIANT & crc_ext_armv8 | |
19338 | TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b), | |
19339 | TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h), | |
19340 | TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w), | |
19341 | TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb), | |
19342 | TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch), | |
19343 | TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw), | |
19344 | ||
105bde57 MW |
19345 | /* ARMv8.2 RAS extension. */ |
19346 | #undef ARM_VARIANT | |
19347 | #define ARM_VARIANT & arm_ext_v8_2 | |
19348 | #undef THUMB_VARIANT | |
19349 | #define THUMB_VARIANT & arm_ext_v8_2 | |
19350 | TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs), | |
19351 | ||
c921be7d NC |
19352 | #undef ARM_VARIANT |
19353 | #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ | |
53c4b28b MGD |
19354 | #undef THUMB_VARIANT |
19355 | #define THUMB_VARIANT NULL | |
c921be7d | 19356 | |
21d799b5 NC |
19357 | cCE("wfs", e200110, 1, (RR), rd), |
19358 | cCE("rfs", e300110, 1, (RR), rd), | |
19359 | cCE("wfc", e400110, 1, (RR), rd), | |
19360 | cCE("rfc", e500110, 1, (RR), rd), | |
19361 | ||
19362 | cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19363 | cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19364 | cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19365 | cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19366 | ||
19367 | cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19368 | cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19369 | cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19370 | cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr), | |
19371 | ||
19372 | cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm), | |
19373 | cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm), | |
19374 | cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm), | |
19375 | cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm), | |
19376 | cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm), | |
19377 | cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm), | |
19378 | cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm), | |
19379 | cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm), | |
19380 | cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm), | |
19381 | cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm), | |
19382 | cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm), | |
19383 | cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm), | |
19384 | ||
19385 | cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm), | |
19386 | cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm), | |
19387 | cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm), | |
19388 | cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm), | |
19389 | cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm), | |
19390 | cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm), | |
19391 | cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm), | |
19392 | cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm), | |
19393 | cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm), | |
19394 | cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm), | |
19395 | cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm), | |
19396 | cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm), | |
19397 | ||
19398 | cCL("abss", e208100, 2, (RF, RF_IF), rd_rm), | |
19399 | cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm), | |
19400 | cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm), | |
19401 | cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm), | |
19402 | cCL("absd", e208180, 2, (RF, RF_IF), rd_rm), | |
19403 | cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm), | |
19404 | cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm), | |
19405 | cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm), | |
19406 | cCL("abse", e288100, 2, (RF, RF_IF), rd_rm), | |
19407 | cCL("absep", e288120, 2, (RF, RF_IF), rd_rm), | |
19408 | cCL("absem", e288140, 2, (RF, RF_IF), rd_rm), | |
19409 | cCL("absez", e288160, 2, (RF, RF_IF), rd_rm), | |
19410 | ||
19411 | cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm), | |
19412 | cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm), | |
19413 | cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm), | |
19414 | cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm), | |
19415 | cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm), | |
19416 | cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm), | |
19417 | cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm), | |
19418 | cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm), | |
19419 | cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm), | |
19420 | cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm), | |
19421 | cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm), | |
19422 | cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm), | |
19423 | ||
19424 | cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm), | |
19425 | cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm), | |
19426 | cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm), | |
19427 | cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm), | |
19428 | cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm), | |
19429 | cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm), | |
19430 | cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm), | |
19431 | cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm), | |
19432 | cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm), | |
19433 | cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm), | |
19434 | cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm), | |
19435 | cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm), | |
19436 | ||
19437 | cCL("logs", e508100, 2, (RF, RF_IF), rd_rm), | |
19438 | cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm), | |
19439 | cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm), | |
19440 | cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm), | |
19441 | cCL("logd", e508180, 2, (RF, RF_IF), rd_rm), | |
19442 | cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm), | |
19443 | cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm), | |
19444 | cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm), | |
19445 | cCL("loge", e588100, 2, (RF, RF_IF), rd_rm), | |
19446 | cCL("logep", e588120, 2, (RF, RF_IF), rd_rm), | |
19447 | cCL("logem", e588140, 2, (RF, RF_IF), rd_rm), | |
19448 | cCL("logez", e588160, 2, (RF, RF_IF), rd_rm), | |
19449 | ||
19450 | cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm), | |
19451 | cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm), | |
19452 | cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm), | |
19453 | cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm), | |
19454 | cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm), | |
19455 | cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm), | |
19456 | cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm), | |
19457 | cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm), | |
19458 | cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm), | |
19459 | cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm), | |
19460 | cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm), | |
19461 | cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm), | |
19462 | ||
19463 | cCL("exps", e708100, 2, (RF, RF_IF), rd_rm), | |
19464 | cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm), | |
19465 | cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm), | |
19466 | cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm), | |
19467 | cCL("expd", e708180, 2, (RF, RF_IF), rd_rm), | |
19468 | cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm), | |
19469 | cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm), | |
19470 | cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm), | |
19471 | cCL("expe", e788100, 2, (RF, RF_IF), rd_rm), | |
19472 | cCL("expep", e788120, 2, (RF, RF_IF), rd_rm), | |
19473 | cCL("expem", e788140, 2, (RF, RF_IF), rd_rm), | |
19474 | cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm), | |
19475 | ||
19476 | cCL("sins", e808100, 2, (RF, RF_IF), rd_rm), | |
19477 | cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm), | |
19478 | cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm), | |
19479 | cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm), | |
19480 | cCL("sind", e808180, 2, (RF, RF_IF), rd_rm), | |
19481 | cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm), | |
19482 | cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm), | |
19483 | cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm), | |
19484 | cCL("sine", e888100, 2, (RF, RF_IF), rd_rm), | |
19485 | cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm), | |
19486 | cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm), | |
19487 | cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm), | |
19488 | ||
19489 | cCL("coss", e908100, 2, (RF, RF_IF), rd_rm), | |
19490 | cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm), | |
19491 | cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm), | |
19492 | cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm), | |
19493 | cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm), | |
19494 | cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm), | |
19495 | cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm), | |
19496 | cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm), | |
19497 | cCL("cose", e988100, 2, (RF, RF_IF), rd_rm), | |
19498 | cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm), | |
19499 | cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm), | |
19500 | cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm), | |
19501 | ||
19502 | cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm), | |
19503 | cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm), | |
19504 | cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm), | |
19505 | cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm), | |
19506 | cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm), | |
19507 | cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm), | |
19508 | cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm), | |
19509 | cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm), | |
19510 | cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm), | |
19511 | cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm), | |
19512 | cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm), | |
19513 | cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm), | |
19514 | ||
19515 | cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm), | |
19516 | cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm), | |
19517 | cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm), | |
19518 | cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm), | |
19519 | cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm), | |
19520 | cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm), | |
19521 | cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm), | |
19522 | cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm), | |
19523 | cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm), | |
19524 | cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm), | |
19525 | cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm), | |
19526 | cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm), | |
19527 | ||
19528 | cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm), | |
19529 | cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm), | |
19530 | cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm), | |
19531 | cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm), | |
19532 | cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm), | |
19533 | cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm), | |
19534 | cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm), | |
19535 | cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm), | |
19536 | cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm), | |
19537 | cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm), | |
19538 | cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm), | |
19539 | cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm), | |
19540 | ||
19541 | cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm), | |
19542 | cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm), | |
19543 | cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm), | |
19544 | cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm), | |
19545 | cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm), | |
19546 | cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm), | |
19547 | cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm), | |
19548 | cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm), | |
19549 | cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm), | |
19550 | cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm), | |
19551 | cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm), | |
19552 | cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm), | |
19553 | ||
19554 | cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm), | |
19555 | cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm), | |
19556 | cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm), | |
19557 | cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm), | |
19558 | cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm), | |
19559 | cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm), | |
19560 | cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm), | |
19561 | cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm), | |
19562 | cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm), | |
19563 | cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm), | |
19564 | cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm), | |
19565 | cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm), | |
19566 | ||
19567 | cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm), | |
19568 | cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm), | |
19569 | cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm), | |
19570 | cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm), | |
19571 | cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm), | |
19572 | cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm), | |
19573 | cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm), | |
19574 | cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm), | |
19575 | cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm), | |
19576 | cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm), | |
19577 | cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm), | |
19578 | cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm), | |
19579 | ||
19580 | cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19581 | cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19582 | cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19583 | cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19584 | cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19585 | cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19586 | cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19587 | cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19588 | cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19589 | cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19590 | cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19591 | cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19592 | ||
19593 | cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19594 | cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19595 | cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19596 | cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19597 | cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19598 | cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19599 | cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19600 | cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19601 | cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19602 | cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19603 | cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19604 | cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19605 | ||
19606 | cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19607 | cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19608 | cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19609 | cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19610 | cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19611 | cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19612 | cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19613 | cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19614 | cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19615 | cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19616 | cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19617 | cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19618 | ||
19619 | cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19620 | cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19621 | cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19622 | cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19623 | cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19624 | cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19625 | cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19626 | cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19627 | cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19628 | cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19629 | cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19630 | cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19631 | ||
19632 | cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19633 | cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19634 | cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19635 | cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19636 | cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19637 | cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19638 | cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19639 | cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19640 | cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19641 | cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19642 | cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19643 | cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19644 | ||
19645 | cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19646 | cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19647 | cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19648 | cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19649 | cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19650 | cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19651 | cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19652 | cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19653 | cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19654 | cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19655 | cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19656 | cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19657 | ||
19658 | cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19659 | cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19660 | cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19661 | cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19662 | cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19663 | cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19664 | cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19665 | cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19666 | cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19667 | cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19668 | cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19669 | cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19670 | ||
19671 | cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19672 | cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19673 | cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19674 | cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19675 | cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19676 | cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19677 | cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19678 | cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19679 | cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19680 | cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19681 | cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19682 | cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19683 | ||
19684 | cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19685 | cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19686 | cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19687 | cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19688 | cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19689 | cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19690 | cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19691 | cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19692 | cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19693 | cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19694 | cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19695 | cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19696 | ||
19697 | cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19698 | cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19699 | cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19700 | cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19701 | cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19702 | cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19703 | cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19704 | cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19705 | cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19706 | cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19707 | cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19708 | cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19709 | ||
19710 | cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19711 | cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19712 | cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19713 | cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19714 | cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19715 | cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19716 | cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19717 | cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19718 | cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19719 | cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19720 | cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19721 | cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19722 | ||
19723 | cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19724 | cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19725 | cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19726 | cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19727 | cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19728 | cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19729 | cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19730 | cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19731 | cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19732 | cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19733 | cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19734 | cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19735 | ||
19736 | cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19737 | cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19738 | cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19739 | cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19740 | cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19741 | cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19742 | cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19743 | cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19744 | cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19745 | cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19746 | cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19747 | cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
19748 | ||
19749 | cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp), | |
19750 | C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp), | |
19751 | cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp), | |
19752 | C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp), | |
19753 | ||
19754 | cCL("flts", e000110, 2, (RF, RR), rn_rd), | |
19755 | cCL("fltsp", e000130, 2, (RF, RR), rn_rd), | |
19756 | cCL("fltsm", e000150, 2, (RF, RR), rn_rd), | |
19757 | cCL("fltsz", e000170, 2, (RF, RR), rn_rd), | |
19758 | cCL("fltd", e000190, 2, (RF, RR), rn_rd), | |
19759 | cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd), | |
19760 | cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd), | |
19761 | cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd), | |
19762 | cCL("flte", e080110, 2, (RF, RR), rn_rd), | |
19763 | cCL("fltep", e080130, 2, (RF, RR), rn_rd), | |
19764 | cCL("fltem", e080150, 2, (RF, RR), rn_rd), | |
19765 | cCL("fltez", e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 19766 | |
c19d1205 ZW |
19767 | /* The implementation of the FIX instruction is broken on some |
19768 | assemblers, in that it accepts a precision specifier as well as a | |
19769 | rounding specifier, despite the fact that this is meaningless. | |
19770 | To be more compatible, we accept it as well, though of course it | |
19771 | does not set any bits. */ | |
21d799b5 NC |
19772 | cCE("fix", e100110, 2, (RR, RF), rd_rm), |
19773 | cCL("fixp", e100130, 2, (RR, RF), rd_rm), | |
19774 | cCL("fixm", e100150, 2, (RR, RF), rd_rm), | |
19775 | cCL("fixz", e100170, 2, (RR, RF), rd_rm), | |
19776 | cCL("fixsp", e100130, 2, (RR, RF), rd_rm), | |
19777 | cCL("fixsm", e100150, 2, (RR, RF), rd_rm), | |
19778 | cCL("fixsz", e100170, 2, (RR, RF), rd_rm), | |
19779 | cCL("fixdp", e100130, 2, (RR, RF), rd_rm), | |
19780 | cCL("fixdm", e100150, 2, (RR, RF), rd_rm), | |
19781 | cCL("fixdz", e100170, 2, (RR, RF), rd_rm), | |
19782 | cCL("fixep", e100130, 2, (RR, RF), rd_rm), | |
19783 | cCL("fixem", e100150, 2, (RR, RF), rd_rm), | |
19784 | cCL("fixez", e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 19785 | |
c19d1205 | 19786 | /* Instructions that were new with the real FPA, call them V2. */ |
c921be7d NC |
19787 | #undef ARM_VARIANT |
19788 | #define ARM_VARIANT & fpu_fpa_ext_v2 | |
19789 | ||
21d799b5 NC |
19790 | cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
19791 | cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
19792 | cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
19793 | cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
19794 | cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
19795 | cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 | 19796 | |
c921be7d NC |
19797 | #undef ARM_VARIANT |
19798 | #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ | |
19799 | ||
c19d1205 | 19800 | /* Moves and type conversions. */ |
21d799b5 NC |
19801 | cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
19802 | cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
19803 | cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
19804 | cCE("fmstat", ef1fa10, 0, (), noargs), | |
7465e07a NC |
19805 | cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs), |
19806 | cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr), | |
21d799b5 NC |
19807 | cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), |
19808 | cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
19809 | cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
19810 | cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
19811 | cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
19812 | cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
19813 | cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn), | |
19814 | cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
19815 | |
19816 | /* Memory operations. */ | |
21d799b5 NC |
19817 | cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), |
19818 | cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst), | |
55881a11 MGD |
19819 | cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), |
19820 | cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
19821 | cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19822 | cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19823 | cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19824 | cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19825 | cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
19826 | cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
19827 | cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
19828 | cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia), | |
19829 | cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19830 | cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb), | |
19831 | cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19832 | cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia), | |
19833 | cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
19834 | cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 19835 | |
c19d1205 | 19836 | /* Monadic operations. */ |
21d799b5 NC |
19837 | cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
19838 | cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
19839 | cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
19840 | |
19841 | /* Dyadic operations. */ | |
21d799b5 NC |
19842 | cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
19843 | cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19844 | cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19845 | cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19846 | cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19847 | cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19848 | cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19849 | cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
19850 | cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 19851 | |
c19d1205 | 19852 | /* Comparisons. */ |
21d799b5 NC |
19853 | cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
19854 | cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z), | |
19855 | cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
19856 | cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 19857 | |
62f3b8c8 PB |
19858 | /* Double precision load/store are still present on single precision |
19859 | implementations. */ | |
19860 | cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
19861 | cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst), | |
55881a11 MGD |
19862 | cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), |
19863 | cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
19864 | cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
19865 | cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
19866 | cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
19867 | cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia), | |
19868 | cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
19869 | cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb), | |
62f3b8c8 | 19870 | |
c921be7d NC |
19871 | #undef ARM_VARIANT |
19872 | #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ | |
19873 | ||
c19d1205 | 19874 | /* Moves and type conversions. */ |
21d799b5 NC |
19875 | cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
19876 | cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
19877 | cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19878 | cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
19879 | cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd), | |
19880 | cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
19881 | cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn), | |
19882 | cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
19883 | cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
19884 | cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19885 | cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19886 | cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
19887 | cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 | 19888 | |
c19d1205 | 19889 | /* Monadic operations. */ |
21d799b5 NC |
19890 | cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm), |
19891 | cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm), | |
19892 | cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
c19d1205 ZW |
19893 | |
19894 | /* Dyadic operations. */ | |
21d799b5 NC |
19895 | cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), |
19896 | cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19897 | cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19898 | cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19899 | cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19900 | cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19901 | cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19902 | cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
19903 | cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
b99bd4ef | 19904 | |
c19d1205 | 19905 | /* Comparisons. */ |
21d799b5 NC |
19906 | cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm), |
19907 | cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd), | |
19908 | cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm), | |
19909 | cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd), | |
c19d1205 | 19910 | |
c921be7d NC |
19911 | #undef ARM_VARIANT |
19912 | #define ARM_VARIANT & fpu_vfp_ext_v2 | |
19913 | ||
21d799b5 NC |
19914 | cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
19915 | cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
19916 | cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn), | |
19917 | cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm), | |
5287ad62 | 19918 | |
037e8744 JB |
19919 | /* Instructions which may belong to either the Neon or VFP instruction sets. |
19920 | Individual encoder functions perform additional architecture checks. */ | |
c921be7d NC |
19921 | #undef ARM_VARIANT |
19922 | #define ARM_VARIANT & fpu_vfp_ext_v1xd | |
19923 | #undef THUMB_VARIANT | |
19924 | #define THUMB_VARIANT & fpu_vfp_ext_v1xd | |
19925 | ||
037e8744 JB |
19926 | /* These mnemonics are unique to VFP. */ |
19927 | NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt), | |
19928 | NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div), | |
21d799b5 NC |
19929 | nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), |
19930 | nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
19931 | nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
aacf0b33 KT |
19932 | nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), |
19933 | nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp), | |
037e8744 JB |
19934 | NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push), |
19935 | NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop), | |
19936 | NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz), | |
19937 | ||
19938 | /* Mnemonics shared by Neon and VFP. */ | |
21d799b5 NC |
19939 | nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul), |
19940 | nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
19941 | nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar), | |
037e8744 | 19942 | |
21d799b5 NC |
19943 | nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), |
19944 | nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i), | |
037e8744 JB |
19945 | |
19946 | NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
19947 | NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg), | |
19948 | ||
55881a11 MGD |
19949 | NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), |
19950 | NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19951 | NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19952 | NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19953 | NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
19954 | NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm), | |
4962c51a MS |
19955 | NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), |
19956 | NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str), | |
037e8744 | 19957 | |
5f1af56b | 19958 | nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt), |
e3e535bc | 19959 | nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr), |
c70a8987 MGD |
19960 | NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb), |
19961 | NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt), | |
f31fef98 | 19962 | |
037e8744 JB |
19963 | |
19964 | /* NOTE: All VMOV encoding is special-cased! */ | |
19965 | NCE(vmov, 0, 1, (VMOV), neon_mov), | |
19966 | NCE(vmovq, 0, 1, (VMOV), neon_mov), | |
19967 | ||
c921be7d NC |
19968 | #undef THUMB_VARIANT |
19969 | #define THUMB_VARIANT & fpu_neon_ext_v1 | |
19970 | #undef ARM_VARIANT | |
19971 | #define ARM_VARIANT & fpu_neon_ext_v1 | |
19972 | ||
5287ad62 JB |
19973 | /* Data processing with three registers of the same length. */ |
19974 | /* integer ops, valid types S8 S16 S32 U8 U16 U32. */ | |
19975 | NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su), | |
19976 | NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su), | |
19977 | NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
19978 | NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
19979 | NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
19980 | NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
19981 | NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su), | |
19982 | NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su), | |
19983 | /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */ | |
19984 | NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
19985 | NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
19986 | NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su), | |
19987 | NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su), | |
627907b7 JB |
19988 | NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), |
19989 | NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
19990 | NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl), | |
19991 | NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl), | |
5287ad62 JB |
19992 | /* If not immediate, fall back to neon_dyadic_i64_su. |
19993 | shl_imm should accept I8 I16 I32 I64, | |
19994 | qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */ | |
21d799b5 NC |
19995 | nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm), |
19996 | nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm), | |
19997 | nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm), | |
19998 | nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm), | |
5287ad62 | 19999 | /* Logic ops, types optional & ignored. */ |
4316f0d2 DG |
20000 | nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), |
20001 | nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20002 | nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
20003 | nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20004 | nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
20005 | nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20006 | nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic), | |
20007 | nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic), | |
20008 | nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic), | |
20009 | nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic), | |
5287ad62 JB |
20010 | /* Bitfield ops, untyped. */ |
20011 | NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
20012 | NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
20013 | NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
20014 | NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
20015 | NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield), | |
20016 | NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield), | |
20017 | /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */ | |
21d799b5 NC |
20018 | nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), |
20019 | nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
20020 | nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
20021 | nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
20022 | nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su), | |
20023 | nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su), | |
5287ad62 JB |
20024 | /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall |
20025 | back to neon_dyadic_if_su. */ | |
21d799b5 NC |
20026 | nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), |
20027 | nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
20028 | nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp), | |
20029 | nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp), | |
20030 | nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
20031 | nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
20032 | nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv), | |
20033 | nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv), | |
428e3f1f | 20034 | /* Comparison. Type I8 I16 I32 F32. */ |
21d799b5 NC |
20035 | nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq), |
20036 | nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq), | |
5287ad62 | 20037 | /* As above, D registers only. */ |
21d799b5 NC |
20038 | nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d), |
20039 | nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d), | |
5287ad62 | 20040 | /* Int and float variants, signedness unimportant. */ |
21d799b5 NC |
20041 | nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), |
20042 | nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar), | |
20043 | nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d), | |
5287ad62 | 20044 | /* Add/sub take types I8 I16 I32 I64 F32. */ |
21d799b5 NC |
20045 | nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), |
20046 | nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i), | |
5287ad62 JB |
20047 | /* vtst takes sizes 8, 16, 32. */ |
20048 | NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst), | |
20049 | NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst), | |
20050 | /* VMUL takes I8 I16 I32 F32 P8. */ | |
21d799b5 | 20051 | nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul), |
5287ad62 | 20052 | /* VQD{R}MULH takes S16 S32. */ |
21d799b5 NC |
20053 | nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), |
20054 | nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
20055 | nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
20056 | nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
20057 | NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), |
20058 | NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
20059 | NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute), | |
20060 | NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute), | |
92559b5b PB |
20061 | NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), |
20062 | NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
20063 | NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv), | |
20064 | NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv), | |
5287ad62 JB |
20065 | NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), |
20066 | NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
20067 | NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step), | |
20068 | NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step), | |
d6b4b13e MW |
20069 | /* ARM v8.1 extension. */ |
20070 | nUF(vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
20071 | nUF(vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
20072 | nUF(vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh), | |
20073 | nUF(vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh), | |
5287ad62 JB |
20074 | |
20075 | /* Two address, int/float. Types S8 S16 S32 F32. */ | |
5287ad62 | 20076 | NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg), |
5287ad62 JB |
20077 | NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg), |
20078 | ||
20079 | /* Data processing with two registers and a shift amount. */ | |
20080 | /* Right shifts, and variants with rounding. | |
20081 | Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */ | |
20082 | NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
20083 | NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
20084 | NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm), | |
20085 | NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm), | |
20086 | NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
20087 | NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
20088 | NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm), | |
20089 | NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm), | |
20090 | /* Shift and insert. Sizes accepted 8 16 32 64. */ | |
20091 | NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli), | |
20092 | NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli), | |
20093 | NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri), | |
20094 | NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri), | |
20095 | /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */ | |
20096 | NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm), | |
20097 | NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm), | |
20098 | /* Right shift immediate, saturating & narrowing, with rounding variants. | |
20099 | Types accepted S16 S32 S64 U16 U32 U64. */ | |
20100 | NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
20101 | NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow), | |
20102 | /* As above, unsigned. Types accepted S16 S32 S64. */ | |
20103 | NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
20104 | NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u), | |
20105 | /* Right shift narrowing. Types accepted I16 I32 I64. */ | |
20106 | NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
20107 | NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow), | |
20108 | /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */ | |
21d799b5 | 20109 | nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll), |
5287ad62 | 20110 | /* CVT with optional immediate for fixed-point variant. */ |
21d799b5 | 20111 | nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt), |
b7fc2769 | 20112 | |
4316f0d2 DG |
20113 | nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn), |
20114 | nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn), | |
5287ad62 JB |
20115 | |
20116 | /* Data processing, three registers of different lengths. */ | |
20117 | /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */ | |
20118 | NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal), | |
20119 | NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long), | |
20120 | NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long), | |
20121 | NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long), | |
20122 | /* If not scalar, fall back to neon_dyadic_long. | |
20123 | Vector types as above, scalar types S16 S32 U16 U32. */ | |
21d799b5 NC |
20124 | nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), |
20125 | nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long), | |
5287ad62 JB |
20126 | /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */ |
20127 | NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
20128 | NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide), | |
20129 | /* Dyadic, narrowing insns. Types I16 I32 I64. */ | |
20130 | NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20131 | NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20132 | NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20133 | NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow), | |
20134 | /* Saturating doubling multiplies. Types S16 S32. */ | |
21d799b5 NC |
20135 | nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), |
20136 | nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
20137 | nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long), | |
5287ad62 JB |
20138 | /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types |
20139 | S16 S32 U16 U32. */ | |
21d799b5 | 20140 | nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull), |
5287ad62 JB |
20141 | |
20142 | /* Extract. Size 8. */ | |
3b8d421e PB |
20143 | NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext), |
20144 | NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext), | |
5287ad62 JB |
20145 | |
20146 | /* Two registers, miscellaneous. */ | |
20147 | /* Reverse. Sizes 8 16 32 (must be < size in opcode). */ | |
20148 | NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev), | |
20149 | NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev), | |
20150 | NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev), | |
20151 | NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev), | |
20152 | NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev), | |
20153 | NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev), | |
20154 | /* Vector replicate. Sizes 8 16 32. */ | |
21d799b5 NC |
20155 | nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup), |
20156 | nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup), | |
5287ad62 JB |
20157 | /* VMOVL. Types S8 S16 S32 U8 U16 U32. */ |
20158 | NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl), | |
20159 | /* VMOVN. Types I16 I32 I64. */ | |
21d799b5 | 20160 | nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn), |
5287ad62 | 20161 | /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */ |
21d799b5 | 20162 | nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn), |
5287ad62 | 20163 | /* VQMOVUN. Types S16 S32 S64. */ |
21d799b5 | 20164 | nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun), |
5287ad62 JB |
20165 | /* VZIP / VUZP. Sizes 8 16 32. */ |
20166 | NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
20167 | NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp), | |
20168 | NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp), | |
20169 | NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp), | |
20170 | /* VQABS / VQNEG. Types S8 S16 S32. */ | |
20171 | NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
20172 | NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
20173 | NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg), | |
20174 | NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg), | |
20175 | /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */ | |
20176 | NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long), | |
20177 | NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long), | |
20178 | NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long), | |
20179 | NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long), | |
20180 | /* Reciprocal estimates. Types U32 F32. */ | |
20181 | NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est), | |
20182 | NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est), | |
20183 | NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est), | |
20184 | NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est), | |
20185 | /* VCLS. Types S8 S16 S32. */ | |
20186 | NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls), | |
20187 | NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls), | |
20188 | /* VCLZ. Types I8 I16 I32. */ | |
20189 | NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz), | |
20190 | NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz), | |
20191 | /* VCNT. Size 8. */ | |
20192 | NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt), | |
20193 | NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt), | |
20194 | /* Two address, untyped. */ | |
20195 | NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp), | |
20196 | NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp), | |
20197 | /* VTRN. Sizes 8 16 32. */ | |
21d799b5 NC |
20198 | nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn), |
20199 | nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn), | |
5287ad62 JB |
20200 | |
20201 | /* Table lookup. Size 8. */ | |
20202 | NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
20203 | NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx), | |
20204 | ||
c921be7d NC |
20205 | #undef THUMB_VARIANT |
20206 | #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext | |
20207 | #undef ARM_VARIANT | |
20208 | #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext | |
20209 | ||
5287ad62 | 20210 | /* Neon element/structure load/store. */ |
21d799b5 NC |
20211 | nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx), |
20212 | nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20213 | nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20214 | nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20215 | nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20216 | nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20217 | nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
20218 | nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx), | |
5287ad62 | 20219 | |
c921be7d | 20220 | #undef THUMB_VARIANT |
74db7efb NC |
20221 | #define THUMB_VARIANT & fpu_vfp_ext_v3xd |
20222 | #undef ARM_VARIANT | |
20223 | #define ARM_VARIANT & fpu_vfp_ext_v3xd | |
62f3b8c8 PB |
20224 | cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const), |
20225 | cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20226 | cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20227 | cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20228 | cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20229 | cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20230 | cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20231 | cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16), | |
20232 | cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32), | |
20233 | ||
74db7efb | 20234 | #undef THUMB_VARIANT |
c921be7d NC |
20235 | #define THUMB_VARIANT & fpu_vfp_ext_v3 |
20236 | #undef ARM_VARIANT | |
20237 | #define ARM_VARIANT & fpu_vfp_ext_v3 | |
20238 | ||
21d799b5 | 20239 | cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const), |
21d799b5 | 20240 | cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20241 | cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 20242 | cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20243 | cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 20244 | cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20245 | cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
21d799b5 | 20246 | cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16), |
21d799b5 | 20247 | cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32), |
c19d1205 | 20248 | |
74db7efb NC |
20249 | #undef ARM_VARIANT |
20250 | #define ARM_VARIANT & fpu_vfp_ext_fma | |
20251 | #undef THUMB_VARIANT | |
20252 | #define THUMB_VARIANT & fpu_vfp_ext_fma | |
62f3b8c8 PB |
20253 | /* Mnemonics shared by Neon and VFP. These are included in the |
20254 | VFP FMA variant; NEON and VFP FMA always includes the NEON | |
20255 | FMA instructions. */ | |
20256 | nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
20257 | nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac), | |
20258 | /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas; | |
20259 | the v form should always be used. */ | |
20260 | cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20261 | cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
20262 | cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20263 | cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm), | |
20264 | nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
20265 | nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul), | |
20266 | ||
5287ad62 | 20267 | #undef THUMB_VARIANT |
c921be7d NC |
20268 | #undef ARM_VARIANT |
20269 | #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */ | |
20270 | ||
21d799b5 NC |
20271 | cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
20272 | cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20273 | cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20274 | cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20275 | cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20276 | cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
20277 | cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
20278 | cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 | 20279 | |
c921be7d NC |
20280 | #undef ARM_VARIANT |
20281 | #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */ | |
20282 | ||
21d799b5 NC |
20283 | cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc), |
20284 | cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc), | |
20285 | cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc), | |
20286 | cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd), | |
20287 | cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd), | |
20288 | cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd), | |
20289 | cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc), | |
20290 | cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc), | |
20291 | cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc), | |
74db7efb NC |
20292 | cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), |
20293 | cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20294 | cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20295 | cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20296 | cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
20297 | cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
21d799b5 NC |
20298 | cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), |
20299 | cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
20300 | cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
20301 | cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd), | |
20302 | cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
20303 | cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20304 | cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20305 | cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20306 | cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20307 | cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
20308 | cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
74db7efb NC |
20309 | cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn), |
20310 | cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn), | |
20311 | cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn), | |
21d799b5 NC |
20312 | cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn), |
20313 | cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
20314 | cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc), | |
20315 | cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc), | |
20316 | cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc), | |
20317 | cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn), | |
20318 | cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn), | |
20319 | cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn), | |
20320 | cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20321 | cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20322 | cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20323 | cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20324 | cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20325 | cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20326 | cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20327 | cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20328 | cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20329 | cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
74db7efb NC |
20330 | cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20331 | cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20332 | cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20333 | cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
20334 | cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20335 | cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20336 | cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20337 | cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20338 | cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20339 | cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20340 | cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20341 | cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20342 | cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
20343 | cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20344 | cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20345 | cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20346 | cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20347 | cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20348 | cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
20349 | cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), |
20350 | cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
20351 | cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
20352 | cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
20353 | cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20354 | cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20355 | cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20356 | cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20357 | cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20358 | cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20359 | cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20360 | cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20361 | cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20362 | cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20363 | cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20364 | cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20365 | cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20366 | cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20367 | cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20368 | cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20369 | cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20370 | cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20371 | cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
20372 | cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20373 | cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20374 | cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20375 | cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20376 | cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
74db7efb NC |
20377 | cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), |
20378 | cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20379 | cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20380 | cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20381 | cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20382 | cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
21d799b5 NC |
20383 | cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), |
20384 | cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20385 | cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20386 | cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20387 | cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20388 | cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20389 | cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20390 | cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20391 | cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20392 | cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20393 | cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
20394 | cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20395 | cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20396 | cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20397 | cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20398 | cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20399 | cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20400 | cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20401 | cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20402 | cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20403 | cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20404 | cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20405 | cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20406 | cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20407 | cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20408 | cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20409 | cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20410 | cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5), | |
20411 | cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
20412 | cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
20413 | cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
20414 | cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
20415 | cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
20416 | cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20417 | cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20418 | cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20419 | cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20420 | cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20421 | cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20422 | cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20423 | cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20424 | cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20425 | cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn), | |
20426 | cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn), | |
20427 | cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn), | |
20428 | cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn), | |
20429 | cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn), | |
20430 | cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn), | |
20431 | cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20432 | cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20433 | cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20434 | cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn), | |
20435 | cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn), | |
20436 | cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn), | |
20437 | cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn), | |
20438 | cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn), | |
20439 | cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn), | |
20440 | cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20441 | cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20442 | cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20443 | cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20444 | cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 | 20445 | |
c921be7d NC |
20446 | #undef ARM_VARIANT |
20447 | #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */ | |
20448 | ||
21d799b5 NC |
20449 | cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc), |
20450 | cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc), | |
20451 | cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc), | |
20452 | cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn), | |
20453 | cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn), | |
20454 | cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn), | |
20455 | cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20456 | cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20457 | cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20458 | cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20459 | cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20460 | cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20461 | cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20462 | cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20463 | cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20464 | cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20465 | cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20466 | cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20467 | cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20468 | cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20469 | cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge), | |
20470 | cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20471 | cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20472 | cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20473 | cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20474 | cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20475 | cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20476 | cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20477 | cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20478 | cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20479 | cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20480 | cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20481 | cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20482 | cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20483 | cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20484 | cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20485 | cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20486 | cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20487 | cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20488 | cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20489 | cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20490 | cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20491 | cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20492 | cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20493 | cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20494 | cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20495 | cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20496 | cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20497 | cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20498 | cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20499 | cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20500 | cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20501 | cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20502 | cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20503 | cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20504 | cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
20505 | cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
2d447fca | 20506 | |
c921be7d NC |
20507 | #undef ARM_VARIANT |
20508 | #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */ | |
20509 | ||
21d799b5 NC |
20510 | cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr), |
20511 | cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
20512 | cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
20513 | cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
20514 | cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr), | |
20515 | cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr), | |
20516 | cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr), | |
20517 | cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr), | |
20518 | cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd), | |
20519 | cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn), | |
20520 | cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd), | |
20521 | cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn), | |
20522 | cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd), | |
20523 | cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn), | |
74db7efb NC |
20524 | cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd), |
20525 | cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn), | |
20526 | cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd), | |
20527 | cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn), | |
20528 | cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn), | |
20529 | cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn), | |
20530 | cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn), | |
20531 | cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn), | |
20532 | cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn), | |
20533 | cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn), | |
21d799b5 NC |
20534 | cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn), |
20535 | cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn), | |
20536 | cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn), | |
20537 | cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn), | |
74db7efb NC |
20538 | cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc), |
20539 | cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd), | |
21d799b5 NC |
20540 | cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn), |
20541 | cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn), | |
20542 | cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn), | |
20543 | cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn), | |
74db7efb NC |
20544 | cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn), |
20545 | cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn), | |
20546 | cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn), | |
20547 | cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn), | |
20548 | cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn), | |
20549 | cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn), | |
21d799b5 NC |
20550 | cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn), |
20551 | cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn), | |
74db7efb NC |
20552 | cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple), |
20553 | cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
21d799b5 NC |
20554 | cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift), |
20555 | cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
20556 | cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
20557 | cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
20558 | cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
20559 | cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
20560 | cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn), | |
20561 | cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn), | |
20562 | cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn), | |
20563 | cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn), | |
20564 | cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
20565 | cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
20566 | cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
20567 | cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
20568 | cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
20569 | cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
20570 | cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn), | |
20571 | cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn), | |
20572 | cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn), | |
20573 | cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn), | |
20574 | cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20575 | cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
20576 | cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20577 | cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
20578 | cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20579 | cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
20580 | cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
20581 | cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
74db7efb NC |
20582 | cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), |
20583 | cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
21d799b5 NC |
20584 | cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), |
20585 | cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
4ed7ed8d TP |
20586 | |
20587 | #undef ARM_VARIANT | |
20588 | #define ARM_VARIANT NULL | |
20589 | #undef THUMB_VARIANT | |
20590 | #define THUMB_VARIANT & arm_ext_v8m | |
20591 | TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt), | |
20592 | TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt), | |
c19d1205 ZW |
20593 | }; |
20594 | #undef ARM_VARIANT | |
20595 | #undef THUMB_VARIANT | |
20596 | #undef TCE | |
c19d1205 ZW |
20597 | #undef TUE |
20598 | #undef TUF | |
20599 | #undef TCC | |
8f06b2d8 | 20600 | #undef cCE |
e3cb604e PB |
20601 | #undef cCL |
20602 | #undef C3E | |
c19d1205 ZW |
20603 | #undef CE |
20604 | #undef CM | |
20605 | #undef UE | |
20606 | #undef UF | |
20607 | #undef UT | |
5287ad62 JB |
20608 | #undef NUF |
20609 | #undef nUF | |
20610 | #undef NCE | |
20611 | #undef nCE | |
c19d1205 ZW |
20612 | #undef OPS0 |
20613 | #undef OPS1 | |
20614 | #undef OPS2 | |
20615 | #undef OPS3 | |
20616 | #undef OPS4 | |
20617 | #undef OPS5 | |
20618 | #undef OPS6 | |
20619 | #undef do_0 | |
20620 | \f | |
20621 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 20622 | |
c19d1205 ZW |
20623 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
20624 | for use in the a.out file, and stores them in the array pointed to by buf. | |
20625 | This knows about the endian-ness of the target machine and does | |
20626 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
20627 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
20628 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 20629 | |
c19d1205 ZW |
20630 | void |
20631 | md_number_to_chars (char * buf, valueT val, int n) | |
20632 | { | |
20633 | if (target_big_endian) | |
20634 | number_to_chars_bigendian (buf, val, n); | |
20635 | else | |
20636 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
20637 | } |
20638 | ||
c19d1205 ZW |
20639 | static valueT |
20640 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 20641 | { |
c19d1205 ZW |
20642 | valueT result = 0; |
20643 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 20644 | |
c19d1205 | 20645 | if (target_big_endian) |
b99bd4ef | 20646 | { |
c19d1205 ZW |
20647 | while (n--) |
20648 | { | |
20649 | result <<= 8; | |
20650 | result |= (*where++ & 255); | |
20651 | } | |
b99bd4ef | 20652 | } |
c19d1205 | 20653 | else |
b99bd4ef | 20654 | { |
c19d1205 ZW |
20655 | while (n--) |
20656 | { | |
20657 | result <<= 8; | |
20658 | result |= (where[n] & 255); | |
20659 | } | |
bfae80f2 | 20660 | } |
b99bd4ef | 20661 | |
c19d1205 | 20662 | return result; |
bfae80f2 | 20663 | } |
b99bd4ef | 20664 | |
c19d1205 | 20665 | /* MD interface: Sections. */ |
b99bd4ef | 20666 | |
fa94de6b RM |
20667 | /* Calculate the maximum variable size (i.e., excluding fr_fix) |
20668 | that an rs_machine_dependent frag may reach. */ | |
20669 | ||
20670 | unsigned int | |
20671 | arm_frag_max_var (fragS *fragp) | |
20672 | { | |
20673 | /* We only use rs_machine_dependent for variable-size Thumb instructions, | |
20674 | which are either THUMB_SIZE (2) or INSN_SIZE (4). | |
20675 | ||
20676 | Note that we generate relaxable instructions even for cases that don't | |
20677 | really need it, like an immediate that's a trivial constant. So we're | |
20678 | overestimating the instruction size for some of those cases. Rather | |
20679 | than putting more intelligence here, it would probably be better to | |
20680 | avoid generating a relaxation frag in the first place when it can be | |
20681 | determined up front that a short instruction will suffice. */ | |
20682 | ||
20683 | gas_assert (fragp->fr_type == rs_machine_dependent); | |
20684 | return INSN_SIZE; | |
20685 | } | |
20686 | ||
0110f2b8 PB |
20687 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
20688 | 2 bytes. */ | |
20689 | ||
c19d1205 | 20690 | int |
0110f2b8 | 20691 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
20692 | segT segtype ATTRIBUTE_UNUSED) |
20693 | { | |
0110f2b8 PB |
20694 | fragp->fr_var = 2; |
20695 | return 2; | |
20696 | } | |
20697 | ||
20698 | /* Convert a machine dependent frag. */ | |
20699 | ||
20700 | void | |
20701 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
20702 | { | |
20703 | unsigned long insn; | |
20704 | unsigned long old_op; | |
20705 | char *buf; | |
20706 | expressionS exp; | |
20707 | fixS *fixp; | |
20708 | int reloc_type; | |
20709 | int pc_rel; | |
20710 | int opcode; | |
20711 | ||
20712 | buf = fragp->fr_literal + fragp->fr_fix; | |
20713 | ||
20714 | old_op = bfd_get_16(abfd, buf); | |
5f4273c7 NC |
20715 | if (fragp->fr_symbol) |
20716 | { | |
0110f2b8 PB |
20717 | exp.X_op = O_symbol; |
20718 | exp.X_add_symbol = fragp->fr_symbol; | |
5f4273c7 NC |
20719 | } |
20720 | else | |
20721 | { | |
0110f2b8 | 20722 | exp.X_op = O_constant; |
5f4273c7 | 20723 | } |
0110f2b8 PB |
20724 | exp.X_add_number = fragp->fr_offset; |
20725 | opcode = fragp->fr_subtype; | |
20726 | switch (opcode) | |
20727 | { | |
20728 | case T_MNEM_ldr_pc: | |
20729 | case T_MNEM_ldr_pc2: | |
20730 | case T_MNEM_ldr_sp: | |
20731 | case T_MNEM_str_sp: | |
20732 | case T_MNEM_ldr: | |
20733 | case T_MNEM_ldrb: | |
20734 | case T_MNEM_ldrh: | |
20735 | case T_MNEM_str: | |
20736 | case T_MNEM_strb: | |
20737 | case T_MNEM_strh: | |
20738 | if (fragp->fr_var == 4) | |
20739 | { | |
5f4273c7 | 20740 | insn = THUMB_OP32 (opcode); |
0110f2b8 PB |
20741 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) |
20742 | { | |
20743 | insn |= (old_op & 0x700) << 4; | |
20744 | } | |
20745 | else | |
20746 | { | |
20747 | insn |= (old_op & 7) << 12; | |
20748 | insn |= (old_op & 0x38) << 13; | |
20749 | } | |
20750 | insn |= 0x00000c00; | |
20751 | put_thumb32_insn (buf, insn); | |
20752 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
20753 | } | |
20754 | else | |
20755 | { | |
20756 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
20757 | } | |
20758 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
20759 | break; | |
20760 | case T_MNEM_adr: | |
20761 | if (fragp->fr_var == 4) | |
20762 | { | |
20763 | insn = THUMB_OP32 (opcode); | |
20764 | insn |= (old_op & 0xf0) << 4; | |
20765 | put_thumb32_insn (buf, insn); | |
20766 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
20767 | } | |
20768 | else | |
20769 | { | |
20770 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
20771 | exp.X_add_number -= 4; | |
20772 | } | |
20773 | pc_rel = 1; | |
20774 | break; | |
20775 | case T_MNEM_mov: | |
20776 | case T_MNEM_movs: | |
20777 | case T_MNEM_cmp: | |
20778 | case T_MNEM_cmn: | |
20779 | if (fragp->fr_var == 4) | |
20780 | { | |
20781 | int r0off = (opcode == T_MNEM_mov | |
20782 | || opcode == T_MNEM_movs) ? 0 : 8; | |
20783 | insn = THUMB_OP32 (opcode); | |
20784 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
20785 | insn |= (old_op & 0x700) << r0off; | |
20786 | put_thumb32_insn (buf, insn); | |
20787 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
20788 | } | |
20789 | else | |
20790 | { | |
20791 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
20792 | } | |
20793 | pc_rel = 0; | |
20794 | break; | |
20795 | case T_MNEM_b: | |
20796 | if (fragp->fr_var == 4) | |
20797 | { | |
20798 | insn = THUMB_OP32(opcode); | |
20799 | put_thumb32_insn (buf, insn); | |
20800 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
20801 | } | |
20802 | else | |
20803 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
20804 | pc_rel = 1; | |
20805 | break; | |
20806 | case T_MNEM_bcond: | |
20807 | if (fragp->fr_var == 4) | |
20808 | { | |
20809 | insn = THUMB_OP32(opcode); | |
20810 | insn |= (old_op & 0xf00) << 14; | |
20811 | put_thumb32_insn (buf, insn); | |
20812 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
20813 | } | |
20814 | else | |
20815 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
20816 | pc_rel = 1; | |
20817 | break; | |
20818 | case T_MNEM_add_sp: | |
20819 | case T_MNEM_add_pc: | |
20820 | case T_MNEM_inc_sp: | |
20821 | case T_MNEM_dec_sp: | |
20822 | if (fragp->fr_var == 4) | |
20823 | { | |
20824 | /* ??? Choose between add and addw. */ | |
20825 | insn = THUMB_OP32 (opcode); | |
20826 | insn |= (old_op & 0xf0) << 4; | |
20827 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
20828 | if (opcode == T_MNEM_add_pc) |
20829 | reloc_type = BFD_RELOC_ARM_T32_IMM12; | |
20830 | else | |
20831 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
0110f2b8 PB |
20832 | } |
20833 | else | |
20834 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
20835 | pc_rel = 0; | |
20836 | break; | |
20837 | ||
20838 | case T_MNEM_addi: | |
20839 | case T_MNEM_addis: | |
20840 | case T_MNEM_subi: | |
20841 | case T_MNEM_subis: | |
20842 | if (fragp->fr_var == 4) | |
20843 | { | |
20844 | insn = THUMB_OP32 (opcode); | |
20845 | insn |= (old_op & 0xf0) << 4; | |
20846 | insn |= (old_op & 0xf) << 16; | |
20847 | put_thumb32_insn (buf, insn); | |
16805f35 PB |
20848 | if (insn & (1 << 20)) |
20849 | reloc_type = BFD_RELOC_ARM_T32_ADD_IMM; | |
20850 | else | |
20851 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
0110f2b8 PB |
20852 | } |
20853 | else | |
20854 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
20855 | pc_rel = 0; | |
20856 | break; | |
20857 | default: | |
5f4273c7 | 20858 | abort (); |
0110f2b8 PB |
20859 | } |
20860 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
21d799b5 | 20861 | (enum bfd_reloc_code_real) reloc_type); |
0110f2b8 PB |
20862 | fixp->fx_file = fragp->fr_file; |
20863 | fixp->fx_line = fragp->fr_line; | |
20864 | fragp->fr_fix += fragp->fr_var; | |
3cfdb781 TG |
20865 | |
20866 | /* Set whether we use thumb-2 ISA based on final relaxation results. */ | |
20867 | if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected () | |
20868 | && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2)) | |
20869 | ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2); | |
0110f2b8 PB |
20870 | } |
20871 | ||
20872 | /* Return the size of a relaxable immediate operand instruction. | |
20873 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
20874 | static int | |
20875 | relax_immediate (fragS *fragp, int size, int shift) | |
20876 | { | |
20877 | offsetT offset; | |
20878 | offsetT mask; | |
20879 | offsetT low; | |
20880 | ||
20881 | /* ??? Should be able to do better than this. */ | |
20882 | if (fragp->fr_symbol) | |
20883 | return 4; | |
20884 | ||
20885 | low = (1 << shift) - 1; | |
20886 | mask = (1 << (shift + size)) - (1 << shift); | |
20887 | offset = fragp->fr_offset; | |
20888 | /* Force misaligned offsets to 32-bit variant. */ | |
20889 | if (offset & low) | |
5e77afaa | 20890 | return 4; |
0110f2b8 PB |
20891 | if (offset & ~mask) |
20892 | return 4; | |
20893 | return 2; | |
20894 | } | |
20895 | ||
5e77afaa PB |
20896 | /* Get the address of a symbol during relaxation. */ |
20897 | static addressT | |
5f4273c7 | 20898 | relaxed_symbol_addr (fragS *fragp, long stretch) |
5e77afaa PB |
20899 | { |
20900 | fragS *sym_frag; | |
20901 | addressT addr; | |
20902 | symbolS *sym; | |
20903 | ||
20904 | sym = fragp->fr_symbol; | |
20905 | sym_frag = symbol_get_frag (sym); | |
20906 | know (S_GET_SEGMENT (sym) != absolute_section | |
20907 | || sym_frag == &zero_address_frag); | |
20908 | addr = S_GET_VALUE (sym) + fragp->fr_offset; | |
20909 | ||
20910 | /* If frag has yet to be reached on this pass, assume it will | |
20911 | move by STRETCH just as we did. If this is not so, it will | |
20912 | be because some frag between grows, and that will force | |
20913 | another pass. */ | |
20914 | ||
20915 | if (stretch != 0 | |
20916 | && sym_frag->relax_marker != fragp->relax_marker) | |
4396b686 PB |
20917 | { |
20918 | fragS *f; | |
20919 | ||
20920 | /* Adjust stretch for any alignment frag. Note that if have | |
20921 | been expanding the earlier code, the symbol may be | |
20922 | defined in what appears to be an earlier frag. FIXME: | |
20923 | This doesn't handle the fr_subtype field, which specifies | |
20924 | a maximum number of bytes to skip when doing an | |
20925 | alignment. */ | |
20926 | for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next) | |
20927 | { | |
20928 | if (f->fr_type == rs_align || f->fr_type == rs_align_code) | |
20929 | { | |
20930 | if (stretch < 0) | |
20931 | stretch = - ((- stretch) | |
20932 | & ~ ((1 << (int) f->fr_offset) - 1)); | |
20933 | else | |
20934 | stretch &= ~ ((1 << (int) f->fr_offset) - 1); | |
20935 | if (stretch == 0) | |
20936 | break; | |
20937 | } | |
20938 | } | |
20939 | if (f != NULL) | |
20940 | addr += stretch; | |
20941 | } | |
5e77afaa PB |
20942 | |
20943 | return addr; | |
20944 | } | |
20945 | ||
0110f2b8 PB |
20946 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative |
20947 | load. */ | |
20948 | static int | |
5e77afaa | 20949 | relax_adr (fragS *fragp, asection *sec, long stretch) |
0110f2b8 PB |
20950 | { |
20951 | addressT addr; | |
20952 | offsetT val; | |
20953 | ||
20954 | /* Assume worst case for symbols not known to be in the same section. */ | |
974da60d NC |
20955 | if (fragp->fr_symbol == NULL |
20956 | || !S_IS_DEFINED (fragp->fr_symbol) | |
77db8e2e NC |
20957 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
20958 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
20959 | return 4; |
20960 | ||
5f4273c7 | 20961 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
20962 | addr = fragp->fr_address + fragp->fr_fix; |
20963 | addr = (addr + 4) & ~3; | |
5e77afaa | 20964 | /* Force misaligned targets to 32-bit variant. */ |
0110f2b8 | 20965 | if (val & 3) |
5e77afaa | 20966 | return 4; |
0110f2b8 PB |
20967 | val -= addr; |
20968 | if (val < 0 || val > 1020) | |
20969 | return 4; | |
20970 | return 2; | |
20971 | } | |
20972 | ||
20973 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
20974 | static int | |
20975 | relax_addsub (fragS *fragp, asection *sec) | |
20976 | { | |
20977 | char *buf; | |
20978 | int op; | |
20979 | ||
20980 | buf = fragp->fr_literal + fragp->fr_fix; | |
20981 | op = bfd_get_16(sec->owner, buf); | |
20982 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
20983 | return relax_immediate (fragp, 8, 0); | |
20984 | else | |
20985 | return relax_immediate (fragp, 3, 0); | |
20986 | } | |
20987 | ||
e83a675f RE |
20988 | /* Return TRUE iff the definition of symbol S could be pre-empted |
20989 | (overridden) at link or load time. */ | |
20990 | static bfd_boolean | |
20991 | symbol_preemptible (symbolS *s) | |
20992 | { | |
20993 | /* Weak symbols can always be pre-empted. */ | |
20994 | if (S_IS_WEAK (s)) | |
20995 | return TRUE; | |
20996 | ||
20997 | /* Non-global symbols cannot be pre-empted. */ | |
20998 | if (! S_IS_EXTERNAL (s)) | |
20999 | return FALSE; | |
21000 | ||
21001 | #ifdef OBJ_ELF | |
21002 | /* In ELF, a global symbol can be marked protected, or private. In that | |
21003 | case it can't be pre-empted (other definitions in the same link unit | |
21004 | would violate the ODR). */ | |
21005 | if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT) | |
21006 | return FALSE; | |
21007 | #endif | |
21008 | ||
21009 | /* Other global symbols might be pre-empted. */ | |
21010 | return TRUE; | |
21011 | } | |
0110f2b8 PB |
21012 | |
21013 | /* Return the size of a relaxable branch instruction. BITS is the | |
21014 | size of the offset field in the narrow instruction. */ | |
21015 | ||
21016 | static int | |
5e77afaa | 21017 | relax_branch (fragS *fragp, asection *sec, int bits, long stretch) |
0110f2b8 PB |
21018 | { |
21019 | addressT addr; | |
21020 | offsetT val; | |
21021 | offsetT limit; | |
21022 | ||
21023 | /* Assume worst case for symbols not known to be in the same section. */ | |
5f4273c7 | 21024 | if (!S_IS_DEFINED (fragp->fr_symbol) |
77db8e2e NC |
21025 | || sec != S_GET_SEGMENT (fragp->fr_symbol) |
21026 | || S_IS_WEAK (fragp->fr_symbol)) | |
0110f2b8 PB |
21027 | return 4; |
21028 | ||
267bf995 | 21029 | #ifdef OBJ_ELF |
e83a675f | 21030 | /* A branch to a function in ARM state will require interworking. */ |
267bf995 RR |
21031 | if (S_IS_DEFINED (fragp->fr_symbol) |
21032 | && ARM_IS_FUNC (fragp->fr_symbol)) | |
21033 | return 4; | |
e83a675f | 21034 | #endif |
0d9b4b55 | 21035 | |
e83a675f | 21036 | if (symbol_preemptible (fragp->fr_symbol)) |
0d9b4b55 | 21037 | return 4; |
267bf995 | 21038 | |
5f4273c7 | 21039 | val = relaxed_symbol_addr (fragp, stretch); |
0110f2b8 PB |
21040 | addr = fragp->fr_address + fragp->fr_fix + 4; |
21041 | val -= addr; | |
21042 | ||
21043 | /* Offset is a signed value *2 */ | |
21044 | limit = 1 << bits; | |
21045 | if (val >= limit || val < -limit) | |
21046 | return 4; | |
21047 | return 2; | |
21048 | } | |
21049 | ||
21050 | ||
21051 | /* Relax a machine dependent frag. This returns the amount by which | |
21052 | the current size of the frag should change. */ | |
21053 | ||
21054 | int | |
5e77afaa | 21055 | arm_relax_frag (asection *sec, fragS *fragp, long stretch) |
0110f2b8 PB |
21056 | { |
21057 | int oldsize; | |
21058 | int newsize; | |
21059 | ||
21060 | oldsize = fragp->fr_var; | |
21061 | switch (fragp->fr_subtype) | |
21062 | { | |
21063 | case T_MNEM_ldr_pc2: | |
5f4273c7 | 21064 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
21065 | break; |
21066 | case T_MNEM_ldr_pc: | |
21067 | case T_MNEM_ldr_sp: | |
21068 | case T_MNEM_str_sp: | |
5f4273c7 | 21069 | newsize = relax_immediate (fragp, 8, 2); |
0110f2b8 PB |
21070 | break; |
21071 | case T_MNEM_ldr: | |
21072 | case T_MNEM_str: | |
5f4273c7 | 21073 | newsize = relax_immediate (fragp, 5, 2); |
0110f2b8 PB |
21074 | break; |
21075 | case T_MNEM_ldrh: | |
21076 | case T_MNEM_strh: | |
5f4273c7 | 21077 | newsize = relax_immediate (fragp, 5, 1); |
0110f2b8 PB |
21078 | break; |
21079 | case T_MNEM_ldrb: | |
21080 | case T_MNEM_strb: | |
5f4273c7 | 21081 | newsize = relax_immediate (fragp, 5, 0); |
0110f2b8 PB |
21082 | break; |
21083 | case T_MNEM_adr: | |
5f4273c7 | 21084 | newsize = relax_adr (fragp, sec, stretch); |
0110f2b8 PB |
21085 | break; |
21086 | case T_MNEM_mov: | |
21087 | case T_MNEM_movs: | |
21088 | case T_MNEM_cmp: | |
21089 | case T_MNEM_cmn: | |
5f4273c7 | 21090 | newsize = relax_immediate (fragp, 8, 0); |
0110f2b8 PB |
21091 | break; |
21092 | case T_MNEM_b: | |
5f4273c7 | 21093 | newsize = relax_branch (fragp, sec, 11, stretch); |
0110f2b8 PB |
21094 | break; |
21095 | case T_MNEM_bcond: | |
5f4273c7 | 21096 | newsize = relax_branch (fragp, sec, 8, stretch); |
0110f2b8 PB |
21097 | break; |
21098 | case T_MNEM_add_sp: | |
21099 | case T_MNEM_add_pc: | |
21100 | newsize = relax_immediate (fragp, 8, 2); | |
21101 | break; | |
21102 | case T_MNEM_inc_sp: | |
21103 | case T_MNEM_dec_sp: | |
21104 | newsize = relax_immediate (fragp, 7, 2); | |
21105 | break; | |
21106 | case T_MNEM_addi: | |
21107 | case T_MNEM_addis: | |
21108 | case T_MNEM_subi: | |
21109 | case T_MNEM_subis: | |
21110 | newsize = relax_addsub (fragp, sec); | |
21111 | break; | |
21112 | default: | |
5f4273c7 | 21113 | abort (); |
0110f2b8 | 21114 | } |
5e77afaa PB |
21115 | |
21116 | fragp->fr_var = newsize; | |
21117 | /* Freeze wide instructions that are at or before the same location as | |
21118 | in the previous pass. This avoids infinite loops. | |
5f4273c7 NC |
21119 | Don't freeze them unconditionally because targets may be artificially |
21120 | misaligned by the expansion of preceding frags. */ | |
5e77afaa | 21121 | if (stretch <= 0 && newsize > 2) |
0110f2b8 | 21122 | { |
0110f2b8 | 21123 | md_convert_frag (sec->owner, sec, fragp); |
5f4273c7 | 21124 | frag_wane (fragp); |
0110f2b8 | 21125 | } |
5e77afaa | 21126 | |
0110f2b8 | 21127 | return newsize - oldsize; |
c19d1205 | 21128 | } |
b99bd4ef | 21129 | |
c19d1205 | 21130 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 21131 | |
c19d1205 ZW |
21132 | valueT |
21133 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
21134 | valueT size) | |
21135 | { | |
f0927246 NC |
21136 | #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT)) |
21137 | if (OUTPUT_FLAVOR == bfd_target_aout_flavour) | |
21138 | { | |
21139 | /* For a.out, force the section size to be aligned. If we don't do | |
21140 | this, BFD will align it for us, but it will not write out the | |
21141 | final bytes of the section. This may be a bug in BFD, but it is | |
21142 | easier to fix it here since that is how the other a.out targets | |
21143 | work. */ | |
21144 | int align; | |
21145 | ||
21146 | align = bfd_get_section_alignment (stdoutput, segment); | |
8d3842cd | 21147 | size = ((size + (1 << align) - 1) & (-((valueT) 1 << align))); |
f0927246 | 21148 | } |
c19d1205 | 21149 | #endif |
f0927246 NC |
21150 | |
21151 | return size; | |
bfae80f2 | 21152 | } |
b99bd4ef | 21153 | |
c19d1205 ZW |
21154 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
21155 | of an rs_align_code fragment. */ | |
21156 | ||
21157 | void | |
21158 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 21159 | { |
e7495e45 NS |
21160 | static char const arm_noop[2][2][4] = |
21161 | { | |
21162 | { /* ARMv1 */ | |
21163 | {0x00, 0x00, 0xa0, 0xe1}, /* LE */ | |
21164 | {0xe1, 0xa0, 0x00, 0x00}, /* BE */ | |
21165 | }, | |
21166 | { /* ARMv6k */ | |
21167 | {0x00, 0xf0, 0x20, 0xe3}, /* LE */ | |
21168 | {0xe3, 0x20, 0xf0, 0x00}, /* BE */ | |
21169 | }, | |
21170 | }; | |
21171 | static char const thumb_noop[2][2][2] = | |
21172 | { | |
21173 | { /* Thumb-1 */ | |
21174 | {0xc0, 0x46}, /* LE */ | |
21175 | {0x46, 0xc0}, /* BE */ | |
21176 | }, | |
21177 | { /* Thumb-2 */ | |
21178 | {0x00, 0xbf}, /* LE */ | |
21179 | {0xbf, 0x00} /* BE */ | |
21180 | } | |
21181 | }; | |
21182 | static char const wide_thumb_noop[2][4] = | |
21183 | { /* Wide Thumb-2 */ | |
21184 | {0xaf, 0xf3, 0x00, 0x80}, /* LE */ | |
21185 | {0xf3, 0xaf, 0x80, 0x00}, /* BE */ | |
21186 | }; | |
c921be7d | 21187 | |
e7495e45 | 21188 | unsigned bytes, fix, noop_size; |
c19d1205 ZW |
21189 | char * p; |
21190 | const char * noop; | |
e7495e45 | 21191 | const char *narrow_noop = NULL; |
cd000bff DJ |
21192 | #ifdef OBJ_ELF |
21193 | enum mstate state; | |
21194 | #endif | |
bfae80f2 | 21195 | |
c19d1205 | 21196 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
21197 | return; |
21198 | ||
c19d1205 ZW |
21199 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
21200 | p = fragP->fr_literal + fragP->fr_fix; | |
21201 | fix = 0; | |
bfae80f2 | 21202 | |
c19d1205 ZW |
21203 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
21204 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 21205 | |
cd000bff | 21206 | gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0); |
8dc2430f | 21207 | |
cd000bff | 21208 | if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED)) |
a737bd4d | 21209 | { |
7f78eb34 JW |
21210 | if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
21211 | ? selected_cpu : arm_arch_none, arm_ext_v6t2)) | |
e7495e45 NS |
21212 | { |
21213 | narrow_noop = thumb_noop[1][target_big_endian]; | |
21214 | noop = wide_thumb_noop[target_big_endian]; | |
21215 | } | |
c19d1205 | 21216 | else |
e7495e45 NS |
21217 | noop = thumb_noop[0][target_big_endian]; |
21218 | noop_size = 2; | |
cd000bff DJ |
21219 | #ifdef OBJ_ELF |
21220 | state = MAP_THUMB; | |
21221 | #endif | |
7ed4c4c5 NC |
21222 | } |
21223 | else | |
21224 | { | |
7f78eb34 JW |
21225 | noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0] |
21226 | ? selected_cpu : arm_arch_none, | |
21227 | arm_ext_v6k) != 0] | |
e7495e45 NS |
21228 | [target_big_endian]; |
21229 | noop_size = 4; | |
cd000bff DJ |
21230 | #ifdef OBJ_ELF |
21231 | state = MAP_ARM; | |
21232 | #endif | |
7ed4c4c5 | 21233 | } |
c921be7d | 21234 | |
e7495e45 | 21235 | fragP->fr_var = noop_size; |
c921be7d | 21236 | |
c19d1205 | 21237 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 21238 | { |
c19d1205 | 21239 | fix = bytes & (noop_size - 1); |
cd000bff DJ |
21240 | #ifdef OBJ_ELF |
21241 | insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix); | |
21242 | #endif | |
c19d1205 ZW |
21243 | memset (p, 0, fix); |
21244 | p += fix; | |
21245 | bytes -= fix; | |
a737bd4d | 21246 | } |
a737bd4d | 21247 | |
e7495e45 NS |
21248 | if (narrow_noop) |
21249 | { | |
21250 | if (bytes & noop_size) | |
21251 | { | |
21252 | /* Insert a narrow noop. */ | |
21253 | memcpy (p, narrow_noop, noop_size); | |
21254 | p += noop_size; | |
21255 | bytes -= noop_size; | |
21256 | fix += noop_size; | |
21257 | } | |
21258 | ||
21259 | /* Use wide noops for the remainder */ | |
21260 | noop_size = 4; | |
21261 | } | |
21262 | ||
c19d1205 | 21263 | while (bytes >= noop_size) |
a737bd4d | 21264 | { |
c19d1205 ZW |
21265 | memcpy (p, noop, noop_size); |
21266 | p += noop_size; | |
21267 | bytes -= noop_size; | |
21268 | fix += noop_size; | |
a737bd4d NC |
21269 | } |
21270 | ||
c19d1205 | 21271 | fragP->fr_fix += fix; |
a737bd4d NC |
21272 | } |
21273 | ||
c19d1205 ZW |
21274 | /* Called from md_do_align. Used to create an alignment |
21275 | frag in a code section. */ | |
21276 | ||
21277 | void | |
21278 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 21279 | { |
c19d1205 | 21280 | char * p; |
7ed4c4c5 | 21281 | |
c19d1205 | 21282 | /* We assume that there will never be a requirement |
6ec8e702 | 21283 | to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */ |
c19d1205 | 21284 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) |
6ec8e702 NC |
21285 | { |
21286 | char err_msg[128]; | |
21287 | ||
fa94de6b | 21288 | sprintf (err_msg, |
477330fc RM |
21289 | _("alignments greater than %d bytes not supported in .text sections."), |
21290 | MAX_MEM_FOR_RS_ALIGN_CODE + 1); | |
20203fb9 | 21291 | as_fatal ("%s", err_msg); |
6ec8e702 | 21292 | } |
bfae80f2 | 21293 | |
c19d1205 ZW |
21294 | p = frag_var (rs_align_code, |
21295 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
21296 | 1, | |
21297 | (relax_substateT) max, | |
21298 | (symbolS *) NULL, | |
21299 | (offsetT) n, | |
21300 | (char *) NULL); | |
21301 | *p = 0; | |
21302 | } | |
bfae80f2 | 21303 | |
8dc2430f NC |
21304 | /* Perform target specific initialisation of a frag. |
21305 | Note - despite the name this initialisation is not done when the frag | |
21306 | is created, but only when its type is assigned. A frag can be created | |
21307 | and used a long time before its type is set, so beware of assuming that | |
21308 | this initialisationis performed first. */ | |
bfae80f2 | 21309 | |
cd000bff DJ |
21310 | #ifndef OBJ_ELF |
21311 | void | |
21312 | arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED) | |
21313 | { | |
21314 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
2e98972e | 21315 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
cd000bff DJ |
21316 | } |
21317 | ||
21318 | #else /* OBJ_ELF is defined. */ | |
c19d1205 | 21319 | void |
cd000bff | 21320 | arm_init_frag (fragS * fragP, int max_chars) |
c19d1205 | 21321 | { |
b968d18a JW |
21322 | int frag_thumb_mode; |
21323 | ||
8dc2430f NC |
21324 | /* If the current ARM vs THUMB mode has not already |
21325 | been recorded into this frag then do so now. */ | |
cd000bff | 21326 | if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0) |
b968d18a JW |
21327 | fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED; |
21328 | ||
21329 | frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED; | |
cd000bff | 21330 | |
f9c1b181 RL |
21331 | /* Record a mapping symbol for alignment frags. We will delete this |
21332 | later if the alignment ends up empty. */ | |
21333 | switch (fragP->fr_type) | |
21334 | { | |
21335 | case rs_align: | |
21336 | case rs_align_test: | |
21337 | case rs_fill: | |
21338 | mapping_state_2 (MAP_DATA, max_chars); | |
21339 | break; | |
21340 | case rs_align_code: | |
b968d18a | 21341 | mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars); |
f9c1b181 RL |
21342 | break; |
21343 | default: | |
21344 | break; | |
cd000bff | 21345 | } |
bfae80f2 RE |
21346 | } |
21347 | ||
c19d1205 ZW |
21348 | /* When we change sections we need to issue a new mapping symbol. */ |
21349 | ||
21350 | void | |
21351 | arm_elf_change_section (void) | |
bfae80f2 | 21352 | { |
c19d1205 ZW |
21353 | /* Link an unlinked unwind index table section to the .text section. */ |
21354 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
21355 | && elf_linked_to_section (now_seg) == NULL) | |
21356 | elf_linked_to_section (now_seg) = text_section; | |
bfae80f2 RE |
21357 | } |
21358 | ||
c19d1205 ZW |
21359 | int |
21360 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 21361 | { |
c19d1205 ZW |
21362 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
21363 | return SHT_ARM_EXIDX; | |
e45d0630 | 21364 | |
c19d1205 ZW |
21365 | return -1; |
21366 | } | |
21367 | \f | |
21368 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 21369 | |
c19d1205 | 21370 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 21371 | |
5f4273c7 | 21372 | /* Generate any deferred unwind frame offset. */ |
e45d0630 | 21373 | |
bfae80f2 | 21374 | static void |
c19d1205 | 21375 | flush_pending_unwind (void) |
bfae80f2 | 21376 | { |
c19d1205 | 21377 | offsetT offset; |
bfae80f2 | 21378 | |
c19d1205 ZW |
21379 | offset = unwind.pending_offset; |
21380 | unwind.pending_offset = 0; | |
21381 | if (offset != 0) | |
21382 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
21383 | } |
21384 | ||
c19d1205 ZW |
21385 | /* Add an opcode to this list for this function. Two-byte opcodes should |
21386 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
21387 | order. */ | |
21388 | ||
bfae80f2 | 21389 | static void |
c19d1205 | 21390 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 21391 | { |
c19d1205 ZW |
21392 | /* Add any deferred stack adjustment. */ |
21393 | if (unwind.pending_offset) | |
21394 | flush_pending_unwind (); | |
bfae80f2 | 21395 | |
c19d1205 | 21396 | unwind.sp_restored = 0; |
bfae80f2 | 21397 | |
c19d1205 | 21398 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 21399 | { |
c19d1205 ZW |
21400 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
21401 | if (unwind.opcodes) | |
21d799b5 | 21402 | unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes, |
477330fc | 21403 | unwind.opcode_alloc); |
c19d1205 | 21404 | else |
21d799b5 | 21405 | unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc); |
bfae80f2 | 21406 | } |
c19d1205 | 21407 | while (length > 0) |
bfae80f2 | 21408 | { |
c19d1205 ZW |
21409 | length--; |
21410 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
21411 | op >>= 8; | |
21412 | unwind.opcode_count++; | |
bfae80f2 | 21413 | } |
bfae80f2 RE |
21414 | } |
21415 | ||
c19d1205 ZW |
21416 | /* Add unwind opcodes to adjust the stack pointer. */ |
21417 | ||
bfae80f2 | 21418 | static void |
c19d1205 | 21419 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 21420 | { |
c19d1205 | 21421 | valueT op; |
bfae80f2 | 21422 | |
c19d1205 | 21423 | if (offset > 0x200) |
bfae80f2 | 21424 | { |
c19d1205 ZW |
21425 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
21426 | char bytes[5]; | |
21427 | int n; | |
21428 | valueT o; | |
bfae80f2 | 21429 | |
c19d1205 ZW |
21430 | /* Long form: 0xb2, uleb128. */ |
21431 | /* This might not fit in a word so add the individual bytes, | |
21432 | remembering the list is built in reverse order. */ | |
21433 | o = (valueT) ((offset - 0x204) >> 2); | |
21434 | if (o == 0) | |
21435 | add_unwind_opcode (0, 1); | |
bfae80f2 | 21436 | |
c19d1205 ZW |
21437 | /* Calculate the uleb128 encoding of the offset. */ |
21438 | n = 0; | |
21439 | while (o) | |
21440 | { | |
21441 | bytes[n] = o & 0x7f; | |
21442 | o >>= 7; | |
21443 | if (o) | |
21444 | bytes[n] |= 0x80; | |
21445 | n++; | |
21446 | } | |
21447 | /* Add the insn. */ | |
21448 | for (; n; n--) | |
21449 | add_unwind_opcode (bytes[n - 1], 1); | |
21450 | add_unwind_opcode (0xb2, 1); | |
21451 | } | |
21452 | else if (offset > 0x100) | |
bfae80f2 | 21453 | { |
c19d1205 ZW |
21454 | /* Two short opcodes. */ |
21455 | add_unwind_opcode (0x3f, 1); | |
21456 | op = (offset - 0x104) >> 2; | |
21457 | add_unwind_opcode (op, 1); | |
bfae80f2 | 21458 | } |
c19d1205 ZW |
21459 | else if (offset > 0) |
21460 | { | |
21461 | /* Short opcode. */ | |
21462 | op = (offset - 4) >> 2; | |
21463 | add_unwind_opcode (op, 1); | |
21464 | } | |
21465 | else if (offset < 0) | |
bfae80f2 | 21466 | { |
c19d1205 ZW |
21467 | offset = -offset; |
21468 | while (offset > 0x100) | |
bfae80f2 | 21469 | { |
c19d1205 ZW |
21470 | add_unwind_opcode (0x7f, 1); |
21471 | offset -= 0x100; | |
bfae80f2 | 21472 | } |
c19d1205 ZW |
21473 | op = ((offset - 4) >> 2) | 0x40; |
21474 | add_unwind_opcode (op, 1); | |
bfae80f2 | 21475 | } |
bfae80f2 RE |
21476 | } |
21477 | ||
c19d1205 ZW |
21478 | /* Finish the list of unwind opcodes for this function. */ |
21479 | static void | |
21480 | finish_unwind_opcodes (void) | |
bfae80f2 | 21481 | { |
c19d1205 | 21482 | valueT op; |
bfae80f2 | 21483 | |
c19d1205 | 21484 | if (unwind.fp_used) |
bfae80f2 | 21485 | { |
708587a4 | 21486 | /* Adjust sp as necessary. */ |
c19d1205 ZW |
21487 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; |
21488 | flush_pending_unwind (); | |
bfae80f2 | 21489 | |
c19d1205 ZW |
21490 | /* After restoring sp from the frame pointer. */ |
21491 | op = 0x90 | unwind.fp_reg; | |
21492 | add_unwind_opcode (op, 1); | |
21493 | } | |
21494 | else | |
21495 | flush_pending_unwind (); | |
bfae80f2 RE |
21496 | } |
21497 | ||
bfae80f2 | 21498 | |
c19d1205 ZW |
21499 | /* Start an exception table entry. If idx is nonzero this is an index table |
21500 | entry. */ | |
bfae80f2 RE |
21501 | |
21502 | static void | |
c19d1205 | 21503 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 21504 | { |
c19d1205 ZW |
21505 | const char * text_name; |
21506 | const char * prefix; | |
21507 | const char * prefix_once; | |
21508 | const char * group_name; | |
21509 | size_t prefix_len; | |
21510 | size_t text_len; | |
21511 | char * sec_name; | |
21512 | size_t sec_name_len; | |
21513 | int type; | |
21514 | int flags; | |
21515 | int linkonce; | |
bfae80f2 | 21516 | |
c19d1205 | 21517 | if (idx) |
bfae80f2 | 21518 | { |
c19d1205 ZW |
21519 | prefix = ELF_STRING_ARM_unwind; |
21520 | prefix_once = ELF_STRING_ARM_unwind_once; | |
21521 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 21522 | } |
c19d1205 | 21523 | else |
bfae80f2 | 21524 | { |
c19d1205 ZW |
21525 | prefix = ELF_STRING_ARM_unwind_info; |
21526 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
21527 | type = SHT_PROGBITS; | |
bfae80f2 RE |
21528 | } |
21529 | ||
c19d1205 ZW |
21530 | text_name = segment_name (text_seg); |
21531 | if (streq (text_name, ".text")) | |
21532 | text_name = ""; | |
21533 | ||
21534 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
21535 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 21536 | { |
c19d1205 ZW |
21537 | prefix = prefix_once; |
21538 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
21539 | } |
21540 | ||
c19d1205 ZW |
21541 | prefix_len = strlen (prefix); |
21542 | text_len = strlen (text_name); | |
21543 | sec_name_len = prefix_len + text_len; | |
21d799b5 | 21544 | sec_name = (char *) xmalloc (sec_name_len + 1); |
c19d1205 ZW |
21545 | memcpy (sec_name, prefix, prefix_len); |
21546 | memcpy (sec_name + prefix_len, text_name, text_len); | |
21547 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 21548 | |
c19d1205 ZW |
21549 | flags = SHF_ALLOC; |
21550 | linkonce = 0; | |
21551 | group_name = 0; | |
bfae80f2 | 21552 | |
c19d1205 ZW |
21553 | /* Handle COMDAT group. */ |
21554 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 21555 | { |
c19d1205 ZW |
21556 | group_name = elf_group_name (text_seg); |
21557 | if (group_name == NULL) | |
21558 | { | |
bd3ba5d1 | 21559 | as_bad (_("Group section `%s' has no group signature"), |
c19d1205 ZW |
21560 | segment_name (text_seg)); |
21561 | ignore_rest_of_line (); | |
21562 | return; | |
21563 | } | |
21564 | flags |= SHF_GROUP; | |
21565 | linkonce = 1; | |
bfae80f2 RE |
21566 | } |
21567 | ||
c19d1205 | 21568 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 21569 | |
5f4273c7 | 21570 | /* Set the section link for index tables. */ |
c19d1205 ZW |
21571 | if (idx) |
21572 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
21573 | } |
21574 | ||
bfae80f2 | 21575 | |
c19d1205 ZW |
21576 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
21577 | personality routine data. Returns zero, or the index table value for | |
cad0da33 | 21578 | an inline entry. */ |
c19d1205 ZW |
21579 | |
21580 | static valueT | |
21581 | create_unwind_entry (int have_data) | |
bfae80f2 | 21582 | { |
c19d1205 ZW |
21583 | int size; |
21584 | addressT where; | |
21585 | char *ptr; | |
21586 | /* The current word of data. */ | |
21587 | valueT data; | |
21588 | /* The number of bytes left in this word. */ | |
21589 | int n; | |
bfae80f2 | 21590 | |
c19d1205 | 21591 | finish_unwind_opcodes (); |
bfae80f2 | 21592 | |
c19d1205 ZW |
21593 | /* Remember the current text section. */ |
21594 | unwind.saved_seg = now_seg; | |
21595 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 21596 | |
c19d1205 | 21597 | start_unwind_section (now_seg, 0); |
bfae80f2 | 21598 | |
c19d1205 | 21599 | if (unwind.personality_routine == NULL) |
bfae80f2 | 21600 | { |
c19d1205 ZW |
21601 | if (unwind.personality_index == -2) |
21602 | { | |
21603 | if (have_data) | |
5f4273c7 | 21604 | as_bad (_("handlerdata in cantunwind frame")); |
c19d1205 ZW |
21605 | return 1; /* EXIDX_CANTUNWIND. */ |
21606 | } | |
bfae80f2 | 21607 | |
c19d1205 ZW |
21608 | /* Use a default personality routine if none is specified. */ |
21609 | if (unwind.personality_index == -1) | |
21610 | { | |
21611 | if (unwind.opcode_count > 3) | |
21612 | unwind.personality_index = 1; | |
21613 | else | |
21614 | unwind.personality_index = 0; | |
21615 | } | |
bfae80f2 | 21616 | |
c19d1205 ZW |
21617 | /* Space for the personality routine entry. */ |
21618 | if (unwind.personality_index == 0) | |
21619 | { | |
21620 | if (unwind.opcode_count > 3) | |
21621 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 21622 | |
c19d1205 ZW |
21623 | if (!have_data) |
21624 | { | |
21625 | /* All the data is inline in the index table. */ | |
21626 | data = 0x80; | |
21627 | n = 3; | |
21628 | while (unwind.opcode_count > 0) | |
21629 | { | |
21630 | unwind.opcode_count--; | |
21631 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
21632 | n--; | |
21633 | } | |
bfae80f2 | 21634 | |
c19d1205 ZW |
21635 | /* Pad with "finish" opcodes. */ |
21636 | while (n--) | |
21637 | data = (data << 8) | 0xb0; | |
bfae80f2 | 21638 | |
c19d1205 ZW |
21639 | return data; |
21640 | } | |
21641 | size = 0; | |
21642 | } | |
21643 | else | |
21644 | /* We get two opcodes "free" in the first word. */ | |
21645 | size = unwind.opcode_count - 2; | |
21646 | } | |
21647 | else | |
5011093d | 21648 | { |
cad0da33 NC |
21649 | /* PR 16765: Missing or misplaced unwind directives can trigger this. */ |
21650 | if (unwind.personality_index != -1) | |
21651 | { | |
21652 | as_bad (_("attempt to recreate an unwind entry")); | |
21653 | return 1; | |
21654 | } | |
5011093d NC |
21655 | |
21656 | /* An extra byte is required for the opcode count. */ | |
21657 | size = unwind.opcode_count + 1; | |
21658 | } | |
bfae80f2 | 21659 | |
c19d1205 ZW |
21660 | size = (size + 3) >> 2; |
21661 | if (size > 0xff) | |
21662 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 21663 | |
c19d1205 ZW |
21664 | frag_align (2, 0, 0); |
21665 | record_alignment (now_seg, 2); | |
21666 | unwind.table_entry = expr_build_dot (); | |
21667 | ||
21668 | /* Allocate the table entry. */ | |
21669 | ptr = frag_more ((size << 2) + 4); | |
74929e7b NC |
21670 | /* PR 13449: Zero the table entries in case some of them are not used. */ |
21671 | memset (ptr, 0, (size << 2) + 4); | |
c19d1205 | 21672 | where = frag_now_fix () - ((size << 2) + 4); |
bfae80f2 | 21673 | |
c19d1205 | 21674 | switch (unwind.personality_index) |
bfae80f2 | 21675 | { |
c19d1205 ZW |
21676 | case -1: |
21677 | /* ??? Should this be a PLT generating relocation? */ | |
21678 | /* Custom personality routine. */ | |
21679 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
21680 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 21681 | |
c19d1205 ZW |
21682 | where += 4; |
21683 | ptr += 4; | |
bfae80f2 | 21684 | |
c19d1205 | 21685 | /* Set the first byte to the number of additional words. */ |
5011093d | 21686 | data = size > 0 ? size - 1 : 0; |
c19d1205 ZW |
21687 | n = 3; |
21688 | break; | |
bfae80f2 | 21689 | |
c19d1205 ZW |
21690 | /* ABI defined personality routines. */ |
21691 | case 0: | |
21692 | /* Three opcodes bytes are packed into the first word. */ | |
21693 | data = 0x80; | |
21694 | n = 3; | |
21695 | break; | |
bfae80f2 | 21696 | |
c19d1205 ZW |
21697 | case 1: |
21698 | case 2: | |
21699 | /* The size and first two opcode bytes go in the first word. */ | |
21700 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
21701 | n = 2; | |
21702 | break; | |
bfae80f2 | 21703 | |
c19d1205 ZW |
21704 | default: |
21705 | /* Should never happen. */ | |
21706 | abort (); | |
21707 | } | |
bfae80f2 | 21708 | |
c19d1205 ZW |
21709 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
21710 | time. */ | |
21711 | while (unwind.opcode_count > 0) | |
21712 | { | |
21713 | if (n == 0) | |
21714 | { | |
21715 | md_number_to_chars (ptr, data, 4); | |
21716 | ptr += 4; | |
21717 | n = 4; | |
21718 | data = 0; | |
21719 | } | |
21720 | unwind.opcode_count--; | |
21721 | n--; | |
21722 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
21723 | } | |
21724 | ||
21725 | /* Finish off the last word. */ | |
21726 | if (n < 4) | |
21727 | { | |
21728 | /* Pad with "finish" opcodes. */ | |
21729 | while (n--) | |
21730 | data = (data << 8) | 0xb0; | |
21731 | ||
21732 | md_number_to_chars (ptr, data, 4); | |
21733 | } | |
21734 | ||
21735 | if (!have_data) | |
21736 | { | |
21737 | /* Add an empty descriptor if there is no user-specified data. */ | |
21738 | ptr = frag_more (4); | |
21739 | md_number_to_chars (ptr, 0, 4); | |
21740 | } | |
21741 | ||
21742 | return 0; | |
bfae80f2 RE |
21743 | } |
21744 | ||
f0927246 NC |
21745 | |
21746 | /* Initialize the DWARF-2 unwind information for this procedure. */ | |
21747 | ||
21748 | void | |
21749 | tc_arm_frame_initial_instructions (void) | |
21750 | { | |
21751 | cfi_add_CFA_def_cfa (REG_SP, 0); | |
21752 | } | |
21753 | #endif /* OBJ_ELF */ | |
21754 | ||
c19d1205 ZW |
21755 | /* Convert REGNAME to a DWARF-2 register number. */ |
21756 | ||
21757 | int | |
1df69f4f | 21758 | tc_arm_regname_to_dw2regnum (char *regname) |
bfae80f2 | 21759 | { |
1df69f4f | 21760 | int reg = arm_reg_parse (®name, REG_TYPE_RN); |
1f5afe1c NC |
21761 | if (reg != FAIL) |
21762 | return reg; | |
c19d1205 | 21763 | |
1f5afe1c NC |
21764 | /* PR 16694: Allow VFP registers as well. */ |
21765 | reg = arm_reg_parse (®name, REG_TYPE_VFS); | |
21766 | if (reg != FAIL) | |
21767 | return 64 + reg; | |
c19d1205 | 21768 | |
1f5afe1c NC |
21769 | reg = arm_reg_parse (®name, REG_TYPE_VFD); |
21770 | if (reg != FAIL) | |
21771 | return reg + 256; | |
21772 | ||
21773 | return -1; | |
bfae80f2 RE |
21774 | } |
21775 | ||
f0927246 | 21776 | #ifdef TE_PE |
c19d1205 | 21777 | void |
f0927246 | 21778 | tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size) |
bfae80f2 | 21779 | { |
91d6fa6a | 21780 | expressionS exp; |
bfae80f2 | 21781 | |
91d6fa6a NC |
21782 | exp.X_op = O_secrel; |
21783 | exp.X_add_symbol = symbol; | |
21784 | exp.X_add_number = 0; | |
21785 | emit_expr (&exp, size); | |
f0927246 NC |
21786 | } |
21787 | #endif | |
bfae80f2 | 21788 | |
c19d1205 | 21789 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 21790 | |
2fc8bdac ZW |
21791 | /* Return the address within the segment that a PC-relative fixup is |
21792 | relative to. For ARM, PC-relative fixups applied to instructions | |
21793 | are generally relative to the location of the fixup plus 8 bytes. | |
21794 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
21795 | require special handling. */ | |
bfae80f2 | 21796 | |
c19d1205 | 21797 | long |
2fc8bdac | 21798 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 21799 | { |
2fc8bdac ZW |
21800 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
21801 | ||
21802 | /* If this is pc-relative and we are going to emit a relocation | |
21803 | then we just want to put out any pipeline compensation that the linker | |
53baae48 NC |
21804 | will need. Otherwise we want to use the calculated base. |
21805 | For WinCE we skip the bias for externals as well, since this | |
21806 | is how the MS ARM-CE assembler behaves and we want to be compatible. */ | |
5f4273c7 | 21807 | if (fixP->fx_pcrel |
2fc8bdac | 21808 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) |
53baae48 NC |
21809 | || (arm_force_relocation (fixP) |
21810 | #ifdef TE_WINCE | |
21811 | && !S_IS_EXTERNAL (fixP->fx_addsy) | |
21812 | #endif | |
21813 | ))) | |
2fc8bdac | 21814 | base = 0; |
bfae80f2 | 21815 | |
267bf995 | 21816 | |
c19d1205 | 21817 | switch (fixP->fx_r_type) |
bfae80f2 | 21818 | { |
2fc8bdac ZW |
21819 | /* PC relative addressing on the Thumb is slightly odd as the |
21820 | bottom two bits of the PC are forced to zero for the | |
21821 | calculation. This happens *after* application of the | |
21822 | pipeline offset. However, Thumb adrl already adjusts for | |
21823 | this, so we need not do it again. */ | |
c19d1205 | 21824 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 21825 | return base & ~3; |
c19d1205 ZW |
21826 | |
21827 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
21828 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 21829 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 21830 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 21831 | return (base + 4) & ~3; |
c19d1205 | 21832 | |
2fc8bdac ZW |
21833 | /* Thumb branches are simply offset by +4. */ |
21834 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
21835 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
21836 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
21837 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
2fc8bdac | 21838 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac | 21839 | return base + 4; |
bfae80f2 | 21840 | |
267bf995 | 21841 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
486499d0 CL |
21842 | if (fixP->fx_addsy |
21843 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 21844 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 | 21845 | && ARM_IS_FUNC (fixP->fx_addsy) |
477330fc RM |
21846 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) |
21847 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
267bf995 RR |
21848 | return base + 4; |
21849 | ||
00adf2d4 JB |
21850 | /* BLX is like branches above, but forces the low two bits of PC to |
21851 | zero. */ | |
486499d0 CL |
21852 | case BFD_RELOC_THUMB_PCREL_BLX: |
21853 | if (fixP->fx_addsy | |
21854 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 21855 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
21856 | && THUMB_IS_FUNC (fixP->fx_addsy) |
21857 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
21858 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
00adf2d4 JB |
21859 | return (base + 4) & ~3; |
21860 | ||
2fc8bdac ZW |
21861 | /* ARM mode branches are offset by +8. However, the Windows CE |
21862 | loader expects the relocation not to take this into account. */ | |
267bf995 | 21863 | case BFD_RELOC_ARM_PCREL_BLX: |
486499d0 CL |
21864 | if (fixP->fx_addsy |
21865 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 21866 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
21867 | && ARM_IS_FUNC (fixP->fx_addsy) |
21868 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
21869 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 21870 | return base + 8; |
267bf995 | 21871 | |
486499d0 CL |
21872 | case BFD_RELOC_ARM_PCREL_CALL: |
21873 | if (fixP->fx_addsy | |
21874 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 21875 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
477330fc RM |
21876 | && THUMB_IS_FUNC (fixP->fx_addsy) |
21877 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
21878 | base = fixP->fx_where + fixP->fx_frag->fr_address; | |
486499d0 | 21879 | return base + 8; |
267bf995 | 21880 | |
2fc8bdac | 21881 | case BFD_RELOC_ARM_PCREL_BRANCH: |
39b41c9c | 21882 | case BFD_RELOC_ARM_PCREL_JUMP: |
2fc8bdac | 21883 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 21884 | #ifdef TE_WINCE |
5f4273c7 | 21885 | /* When handling fixups immediately, because we have already |
477330fc | 21886 | discovered the value of a symbol, or the address of the frag involved |
53baae48 | 21887 | we must account for the offset by +8, as the OS loader will never see the reloc. |
477330fc RM |
21888 | see fixup_segment() in write.c |
21889 | The S_IS_EXTERNAL test handles the case of global symbols. | |
21890 | Those need the calculated base, not just the pipe compensation the linker will need. */ | |
53baae48 NC |
21891 | if (fixP->fx_pcrel |
21892 | && fixP->fx_addsy != NULL | |
21893 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
21894 | && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP))) | |
21895 | return base + 8; | |
2fc8bdac | 21896 | return base; |
c19d1205 | 21897 | #else |
2fc8bdac | 21898 | return base + 8; |
c19d1205 | 21899 | #endif |
2fc8bdac | 21900 | |
267bf995 | 21901 | |
2fc8bdac ZW |
21902 | /* ARM mode loads relative to PC are also offset by +8. Unlike |
21903 | branches, the Windows CE loader *does* expect the relocation | |
21904 | to take this into account. */ | |
21905 | case BFD_RELOC_ARM_OFFSET_IMM: | |
21906 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
21907 | case BFD_RELOC_ARM_HWLITERAL: | |
21908 | case BFD_RELOC_ARM_LITERAL: | |
21909 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
21910 | return base + 8; | |
21911 | ||
21912 | ||
21913 | /* Other PC-relative relocations are un-offset. */ | |
21914 | default: | |
21915 | return base; | |
21916 | } | |
bfae80f2 RE |
21917 | } |
21918 | ||
8b2d793c NC |
21919 | static bfd_boolean flag_warn_syms = TRUE; |
21920 | ||
ae8714c2 NC |
21921 | bfd_boolean |
21922 | arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name) | |
bfae80f2 | 21923 | { |
8b2d793c NC |
21924 | /* PR 18347 - Warn if the user attempts to create a symbol with the same |
21925 | name as an ARM instruction. Whilst strictly speaking it is allowed, it | |
21926 | does mean that the resulting code might be very confusing to the reader. | |
21927 | Also this warning can be triggered if the user omits an operand before | |
21928 | an immediate address, eg: | |
21929 | ||
21930 | LDR =foo | |
21931 | ||
21932 | GAS treats this as an assignment of the value of the symbol foo to a | |
21933 | symbol LDR, and so (without this code) it will not issue any kind of | |
21934 | warning or error message. | |
21935 | ||
21936 | Note - ARM instructions are case-insensitive but the strings in the hash | |
21937 | table are all stored in lower case, so we must first ensure that name is | |
ae8714c2 NC |
21938 | lower case too. */ |
21939 | if (flag_warn_syms && arm_ops_hsh) | |
8b2d793c NC |
21940 | { |
21941 | char * nbuf = strdup (name); | |
21942 | char * p; | |
21943 | ||
21944 | for (p = nbuf; *p; p++) | |
21945 | *p = TOLOWER (*p); | |
21946 | if (hash_find (arm_ops_hsh, nbuf) != NULL) | |
21947 | { | |
21948 | static struct hash_control * already_warned = NULL; | |
21949 | ||
21950 | if (already_warned == NULL) | |
21951 | already_warned = hash_new (); | |
21952 | /* Only warn about the symbol once. To keep the code | |
21953 | simple we let hash_insert do the lookup for us. */ | |
21954 | if (hash_insert (already_warned, name, NULL) == NULL) | |
ae8714c2 | 21955 | as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name); |
8b2d793c NC |
21956 | } |
21957 | else | |
21958 | free (nbuf); | |
21959 | } | |
3739860c | 21960 | |
ae8714c2 NC |
21961 | return FALSE; |
21962 | } | |
21963 | ||
21964 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. | |
21965 | Otherwise we have no need to default values of symbols. */ | |
21966 | ||
21967 | symbolS * | |
21968 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
21969 | { | |
21970 | #ifdef OBJ_ELF | |
21971 | if (name[0] == '_' && name[1] == 'G' | |
21972 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
21973 | { | |
21974 | if (!GOT_symbol) | |
21975 | { | |
21976 | if (symbol_find (name)) | |
21977 | as_bad (_("GOT already in the symbol table")); | |
21978 | ||
21979 | GOT_symbol = symbol_new (name, undefined_section, | |
21980 | (valueT) 0, & zero_address_frag); | |
21981 | } | |
21982 | ||
21983 | return GOT_symbol; | |
21984 | } | |
21985 | #endif | |
21986 | ||
c921be7d | 21987 | return NULL; |
bfae80f2 RE |
21988 | } |
21989 | ||
55cf6793 | 21990 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
21991 | computed as two separate immediate values, added together. We |
21992 | already know that this value cannot be computed by just one ARM | |
21993 | instruction. */ | |
21994 | ||
21995 | static unsigned int | |
21996 | validate_immediate_twopart (unsigned int val, | |
21997 | unsigned int * highpart) | |
bfae80f2 | 21998 | { |
c19d1205 ZW |
21999 | unsigned int a; |
22000 | unsigned int i; | |
bfae80f2 | 22001 | |
c19d1205 ZW |
22002 | for (i = 0; i < 32; i += 2) |
22003 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
22004 | { | |
22005 | if (a & 0xff00) | |
22006 | { | |
22007 | if (a & ~ 0xffff) | |
22008 | continue; | |
22009 | * highpart = (a >> 8) | ((i + 24) << 7); | |
22010 | } | |
22011 | else if (a & 0xff0000) | |
22012 | { | |
22013 | if (a & 0xff000000) | |
22014 | continue; | |
22015 | * highpart = (a >> 16) | ((i + 16) << 7); | |
22016 | } | |
22017 | else | |
22018 | { | |
9c2799c2 | 22019 | gas_assert (a & 0xff000000); |
c19d1205 ZW |
22020 | * highpart = (a >> 24) | ((i + 8) << 7); |
22021 | } | |
bfae80f2 | 22022 | |
c19d1205 ZW |
22023 | return (a & 0xff) | (i << 7); |
22024 | } | |
bfae80f2 | 22025 | |
c19d1205 | 22026 | return FAIL; |
bfae80f2 RE |
22027 | } |
22028 | ||
c19d1205 ZW |
22029 | static int |
22030 | validate_offset_imm (unsigned int val, int hwse) | |
22031 | { | |
22032 | if ((hwse && val > 255) || val > 4095) | |
22033 | return FAIL; | |
22034 | return val; | |
22035 | } | |
bfae80f2 | 22036 | |
55cf6793 | 22037 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
22038 | negative immediate constant by altering the instruction. A bit of |
22039 | a hack really. | |
22040 | MOV <-> MVN | |
22041 | AND <-> BIC | |
22042 | ADC <-> SBC | |
22043 | by inverting the second operand, and | |
22044 | ADD <-> SUB | |
22045 | CMP <-> CMN | |
22046 | by negating the second operand. */ | |
bfae80f2 | 22047 | |
c19d1205 ZW |
22048 | static int |
22049 | negate_data_op (unsigned long * instruction, | |
22050 | unsigned long value) | |
bfae80f2 | 22051 | { |
c19d1205 ZW |
22052 | int op, new_inst; |
22053 | unsigned long negated, inverted; | |
bfae80f2 | 22054 | |
c19d1205 ZW |
22055 | negated = encode_arm_immediate (-value); |
22056 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 22057 | |
c19d1205 ZW |
22058 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
22059 | switch (op) | |
bfae80f2 | 22060 | { |
c19d1205 ZW |
22061 | /* First negates. */ |
22062 | case OPCODE_SUB: /* ADD <-> SUB */ | |
22063 | new_inst = OPCODE_ADD; | |
22064 | value = negated; | |
22065 | break; | |
bfae80f2 | 22066 | |
c19d1205 ZW |
22067 | case OPCODE_ADD: |
22068 | new_inst = OPCODE_SUB; | |
22069 | value = negated; | |
22070 | break; | |
bfae80f2 | 22071 | |
c19d1205 ZW |
22072 | case OPCODE_CMP: /* CMP <-> CMN */ |
22073 | new_inst = OPCODE_CMN; | |
22074 | value = negated; | |
22075 | break; | |
bfae80f2 | 22076 | |
c19d1205 ZW |
22077 | case OPCODE_CMN: |
22078 | new_inst = OPCODE_CMP; | |
22079 | value = negated; | |
22080 | break; | |
bfae80f2 | 22081 | |
c19d1205 ZW |
22082 | /* Now Inverted ops. */ |
22083 | case OPCODE_MOV: /* MOV <-> MVN */ | |
22084 | new_inst = OPCODE_MVN; | |
22085 | value = inverted; | |
22086 | break; | |
bfae80f2 | 22087 | |
c19d1205 ZW |
22088 | case OPCODE_MVN: |
22089 | new_inst = OPCODE_MOV; | |
22090 | value = inverted; | |
22091 | break; | |
bfae80f2 | 22092 | |
c19d1205 ZW |
22093 | case OPCODE_AND: /* AND <-> BIC */ |
22094 | new_inst = OPCODE_BIC; | |
22095 | value = inverted; | |
22096 | break; | |
bfae80f2 | 22097 | |
c19d1205 ZW |
22098 | case OPCODE_BIC: |
22099 | new_inst = OPCODE_AND; | |
22100 | value = inverted; | |
22101 | break; | |
bfae80f2 | 22102 | |
c19d1205 ZW |
22103 | case OPCODE_ADC: /* ADC <-> SBC */ |
22104 | new_inst = OPCODE_SBC; | |
22105 | value = inverted; | |
22106 | break; | |
bfae80f2 | 22107 | |
c19d1205 ZW |
22108 | case OPCODE_SBC: |
22109 | new_inst = OPCODE_ADC; | |
22110 | value = inverted; | |
22111 | break; | |
bfae80f2 | 22112 | |
c19d1205 ZW |
22113 | /* We cannot do anything. */ |
22114 | default: | |
22115 | return FAIL; | |
b99bd4ef NC |
22116 | } |
22117 | ||
c19d1205 ZW |
22118 | if (value == (unsigned) FAIL) |
22119 | return FAIL; | |
22120 | ||
22121 | *instruction &= OPCODE_MASK; | |
22122 | *instruction |= new_inst << DATA_OP_SHIFT; | |
22123 | return value; | |
b99bd4ef NC |
22124 | } |
22125 | ||
ef8d22e6 PB |
22126 | /* Like negate_data_op, but for Thumb-2. */ |
22127 | ||
22128 | static unsigned int | |
16dd5e42 | 22129 | thumb32_negate_data_op (offsetT *instruction, unsigned int value) |
ef8d22e6 PB |
22130 | { |
22131 | int op, new_inst; | |
22132 | int rd; | |
16dd5e42 | 22133 | unsigned int negated, inverted; |
ef8d22e6 PB |
22134 | |
22135 | negated = encode_thumb32_immediate (-value); | |
22136 | inverted = encode_thumb32_immediate (~value); | |
22137 | ||
22138 | rd = (*instruction >> 8) & 0xf; | |
22139 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
22140 | switch (op) | |
22141 | { | |
22142 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
22143 | case T2_OPCODE_SUB: | |
22144 | new_inst = T2_OPCODE_ADD; | |
22145 | value = negated; | |
22146 | break; | |
22147 | ||
22148 | case T2_OPCODE_ADD: | |
22149 | new_inst = T2_OPCODE_SUB; | |
22150 | value = negated; | |
22151 | break; | |
22152 | ||
22153 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
22154 | case T2_OPCODE_ORR: | |
22155 | new_inst = T2_OPCODE_ORN; | |
22156 | value = inverted; | |
22157 | break; | |
22158 | ||
22159 | case T2_OPCODE_ORN: | |
22160 | new_inst = T2_OPCODE_ORR; | |
22161 | value = inverted; | |
22162 | break; | |
22163 | ||
22164 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
22165 | case T2_OPCODE_AND: | |
22166 | new_inst = T2_OPCODE_BIC; | |
22167 | if (rd == 15) | |
22168 | value = FAIL; | |
22169 | else | |
22170 | value = inverted; | |
22171 | break; | |
22172 | ||
22173 | case T2_OPCODE_BIC: | |
22174 | new_inst = T2_OPCODE_AND; | |
22175 | value = inverted; | |
22176 | break; | |
22177 | ||
22178 | /* ADC <-> SBC */ | |
22179 | case T2_OPCODE_ADC: | |
22180 | new_inst = T2_OPCODE_SBC; | |
22181 | value = inverted; | |
22182 | break; | |
22183 | ||
22184 | case T2_OPCODE_SBC: | |
22185 | new_inst = T2_OPCODE_ADC; | |
22186 | value = inverted; | |
22187 | break; | |
22188 | ||
22189 | /* We cannot do anything. */ | |
22190 | default: | |
22191 | return FAIL; | |
22192 | } | |
22193 | ||
16dd5e42 | 22194 | if (value == (unsigned int)FAIL) |
ef8d22e6 PB |
22195 | return FAIL; |
22196 | ||
22197 | *instruction &= T2_OPCODE_MASK; | |
22198 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
22199 | return value; | |
22200 | } | |
22201 | ||
8f06b2d8 PB |
22202 | /* Read a 32-bit thumb instruction from buf. */ |
22203 | static unsigned long | |
22204 | get_thumb32_insn (char * buf) | |
22205 | { | |
22206 | unsigned long insn; | |
22207 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
22208 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22209 | ||
22210 | return insn; | |
22211 | } | |
22212 | ||
a8bc6c78 PB |
22213 | |
22214 | /* We usually want to set the low bit on the address of thumb function | |
22215 | symbols. In particular .word foo - . should have the low bit set. | |
22216 | Generic code tries to fold the difference of two symbols to | |
22217 | a constant. Prevent this and force a relocation when the first symbols | |
22218 | is a thumb function. */ | |
c921be7d NC |
22219 | |
22220 | bfd_boolean | |
a8bc6c78 PB |
22221 | arm_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
22222 | { | |
22223 | if (op == O_subtract | |
22224 | && l->X_op == O_symbol | |
22225 | && r->X_op == O_symbol | |
22226 | && THUMB_IS_FUNC (l->X_add_symbol)) | |
22227 | { | |
22228 | l->X_op = O_subtract; | |
22229 | l->X_op_symbol = r->X_add_symbol; | |
22230 | l->X_add_number -= r->X_add_number; | |
c921be7d | 22231 | return TRUE; |
a8bc6c78 | 22232 | } |
c921be7d | 22233 | |
a8bc6c78 | 22234 | /* Process as normal. */ |
c921be7d | 22235 | return FALSE; |
a8bc6c78 PB |
22236 | } |
22237 | ||
4a42ebbc RR |
22238 | /* Encode Thumb2 unconditional branches and calls. The encoding |
22239 | for the 2 are identical for the immediate values. */ | |
22240 | ||
22241 | static void | |
22242 | encode_thumb2_b_bl_offset (char * buf, offsetT value) | |
22243 | { | |
22244 | #define T2I1I2MASK ((1 << 13) | (1 << 11)) | |
22245 | offsetT newval; | |
22246 | offsetT newval2; | |
22247 | addressT S, I1, I2, lo, hi; | |
22248 | ||
22249 | S = (value >> 24) & 0x01; | |
22250 | I1 = (value >> 23) & 0x01; | |
22251 | I2 = (value >> 22) & 0x01; | |
22252 | hi = (value >> 12) & 0x3ff; | |
fa94de6b | 22253 | lo = (value >> 1) & 0x7ff; |
4a42ebbc RR |
22254 | newval = md_chars_to_number (buf, THUMB_SIZE); |
22255 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22256 | newval |= (S << 10) | hi; | |
22257 | newval2 &= ~T2I1I2MASK; | |
22258 | newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK; | |
22259 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22260 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
22261 | } | |
22262 | ||
c19d1205 | 22263 | void |
55cf6793 | 22264 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
22265 | valueT * valP, |
22266 | segT seg) | |
22267 | { | |
22268 | offsetT value = * valP; | |
22269 | offsetT newval; | |
22270 | unsigned int newimm; | |
22271 | unsigned long temp; | |
22272 | int sign; | |
22273 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 22274 | |
9c2799c2 | 22275 | gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 22276 | |
c19d1205 | 22277 | /* Note whether this will delete the relocation. */ |
4962c51a | 22278 | |
c19d1205 ZW |
22279 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) |
22280 | fixP->fx_done = 1; | |
b99bd4ef | 22281 | |
adbaf948 | 22282 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
5f4273c7 | 22283 | consistency with the behaviour on 32-bit hosts. Remember value |
adbaf948 ZW |
22284 | for emit_reloc. */ |
22285 | value &= 0xffffffff; | |
22286 | value ^= 0x80000000; | |
5f4273c7 | 22287 | value -= 0x80000000; |
adbaf948 ZW |
22288 | |
22289 | *valP = value; | |
c19d1205 | 22290 | fixP->fx_addnumber = value; |
b99bd4ef | 22291 | |
adbaf948 ZW |
22292 | /* Same treatment for fixP->fx_offset. */ |
22293 | fixP->fx_offset &= 0xffffffff; | |
22294 | fixP->fx_offset ^= 0x80000000; | |
22295 | fixP->fx_offset -= 0x80000000; | |
22296 | ||
c19d1205 | 22297 | switch (fixP->fx_r_type) |
b99bd4ef | 22298 | { |
c19d1205 ZW |
22299 | case BFD_RELOC_NONE: |
22300 | /* This will need to go in the object file. */ | |
22301 | fixP->fx_done = 0; | |
22302 | break; | |
b99bd4ef | 22303 | |
c19d1205 ZW |
22304 | case BFD_RELOC_ARM_IMMEDIATE: |
22305 | /* We claim that this fixup has been processed here, | |
22306 | even if in fact we generate an error because we do | |
22307 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
22308 | fixP->fx_done = 1; | |
b99bd4ef | 22309 | |
77db8e2e | 22310 | if (fixP->fx_addsy) |
b99bd4ef | 22311 | { |
77db8e2e | 22312 | const char *msg = 0; |
b99bd4ef | 22313 | |
77db8e2e NC |
22314 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
22315 | msg = _("undefined symbol %s used as an immediate value"); | |
22316 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
22317 | msg = _("symbol %s is in a different section"); | |
22318 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
22319 | msg = _("symbol %s is weak and may be overridden later"); | |
22320 | ||
22321 | if (msg) | |
22322 | { | |
22323 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22324 | msg, S_GET_NAME (fixP->fx_addsy)); | |
22325 | break; | |
22326 | } | |
42e5fcbf AS |
22327 | } |
22328 | ||
c19d1205 ZW |
22329 | temp = md_chars_to_number (buf, INSN_SIZE); |
22330 | ||
5e73442d SL |
22331 | /* If the offset is negative, we should use encoding A2 for ADR. */ |
22332 | if ((temp & 0xfff0000) == 0x28f0000 && value < 0) | |
22333 | newimm = negate_data_op (&temp, value); | |
22334 | else | |
22335 | { | |
22336 | newimm = encode_arm_immediate (value); | |
22337 | ||
22338 | /* If the instruction will fail, see if we can fix things up by | |
22339 | changing the opcode. */ | |
22340 | if (newimm == (unsigned int) FAIL) | |
22341 | newimm = negate_data_op (&temp, value); | |
22342 | } | |
22343 | ||
22344 | if (newimm == (unsigned int) FAIL) | |
b99bd4ef | 22345 | { |
c19d1205 ZW |
22346 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22347 | _("invalid constant (%lx) after fixup"), | |
22348 | (unsigned long) value); | |
22349 | break; | |
b99bd4ef | 22350 | } |
b99bd4ef | 22351 | |
c19d1205 ZW |
22352 | newimm |= (temp & 0xfffff000); |
22353 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
22354 | break; | |
b99bd4ef | 22355 | |
c19d1205 ZW |
22356 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
22357 | { | |
22358 | unsigned int highpart = 0; | |
22359 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 22360 | |
77db8e2e | 22361 | if (fixP->fx_addsy) |
42e5fcbf | 22362 | { |
77db8e2e | 22363 | const char *msg = 0; |
42e5fcbf | 22364 | |
77db8e2e NC |
22365 | if (! S_IS_DEFINED (fixP->fx_addsy)) |
22366 | msg = _("undefined symbol %s used as an immediate value"); | |
22367 | else if (S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
22368 | msg = _("symbol %s is in a different section"); | |
22369 | else if (S_IS_WEAK (fixP->fx_addsy)) | |
22370 | msg = _("symbol %s is weak and may be overridden later"); | |
42e5fcbf | 22371 | |
77db8e2e NC |
22372 | if (msg) |
22373 | { | |
22374 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22375 | msg, S_GET_NAME (fixP->fx_addsy)); | |
22376 | break; | |
22377 | } | |
22378 | } | |
fa94de6b | 22379 | |
c19d1205 ZW |
22380 | newimm = encode_arm_immediate (value); |
22381 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 22382 | |
c19d1205 ZW |
22383 | /* If the instruction will fail, see if we can fix things up by |
22384 | changing the opcode. */ | |
22385 | if (newimm == (unsigned int) FAIL | |
22386 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
22387 | { | |
22388 | /* No ? OK - try using two ADD instructions to generate | |
22389 | the value. */ | |
22390 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 22391 | |
c19d1205 ZW |
22392 | /* Yes - then make sure that the second instruction is |
22393 | also an add. */ | |
22394 | if (newimm != (unsigned int) FAIL) | |
22395 | newinsn = temp; | |
22396 | /* Still No ? Try using a negated value. */ | |
22397 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
22398 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
22399 | /* Otherwise - give up. */ | |
22400 | else | |
22401 | { | |
22402 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22403 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
22404 | (long) value); | |
22405 | break; | |
22406 | } | |
b99bd4ef | 22407 | |
c19d1205 ZW |
22408 | /* Replace the first operand in the 2nd instruction (which |
22409 | is the PC) with the destination register. We have | |
22410 | already added in the PC in the first instruction and we | |
22411 | do not want to do it again. */ | |
22412 | newinsn &= ~ 0xf0000; | |
22413 | newinsn |= ((newinsn & 0x0f000) << 4); | |
22414 | } | |
b99bd4ef | 22415 | |
c19d1205 ZW |
22416 | newimm |= (temp & 0xfffff000); |
22417 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 22418 | |
c19d1205 ZW |
22419 | highpart |= (newinsn & 0xfffff000); |
22420 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
22421 | } | |
22422 | break; | |
b99bd4ef | 22423 | |
c19d1205 | 22424 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
22425 | if (!fixP->fx_done && seg->use_rela_p) |
22426 | value = 0; | |
22427 | ||
c19d1205 | 22428 | case BFD_RELOC_ARM_LITERAL: |
26d97720 | 22429 | sign = value > 0; |
b99bd4ef | 22430 | |
c19d1205 ZW |
22431 | if (value < 0) |
22432 | value = - value; | |
b99bd4ef | 22433 | |
c19d1205 | 22434 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 22435 | { |
c19d1205 ZW |
22436 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
22437 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22438 | _("invalid literal constant: pool needs to be closer")); | |
22439 | else | |
22440 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22441 | _("bad immediate value for offset (%ld)"), | |
22442 | (long) value); | |
22443 | break; | |
f03698e6 RE |
22444 | } |
22445 | ||
c19d1205 | 22446 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
22447 | if (value == 0) |
22448 | newval &= 0xfffff000; | |
22449 | else | |
22450 | { | |
22451 | newval &= 0xff7ff000; | |
22452 | newval |= value | (sign ? INDEX_UP : 0); | |
22453 | } | |
c19d1205 ZW |
22454 | md_number_to_chars (buf, newval, INSN_SIZE); |
22455 | break; | |
b99bd4ef | 22456 | |
c19d1205 ZW |
22457 | case BFD_RELOC_ARM_OFFSET_IMM8: |
22458 | case BFD_RELOC_ARM_HWLITERAL: | |
26d97720 | 22459 | sign = value > 0; |
b99bd4ef | 22460 | |
c19d1205 ZW |
22461 | if (value < 0) |
22462 | value = - value; | |
b99bd4ef | 22463 | |
c19d1205 | 22464 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 22465 | { |
c19d1205 ZW |
22466 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
22467 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22468 | _("invalid literal constant: pool needs to be closer")); | |
22469 | else | |
427d0db6 RM |
22470 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22471 | _("bad immediate value for 8-bit offset (%ld)"), | |
22472 | (long) value); | |
c19d1205 | 22473 | break; |
b99bd4ef NC |
22474 | } |
22475 | ||
c19d1205 | 22476 | newval = md_chars_to_number (buf, INSN_SIZE); |
26d97720 NS |
22477 | if (value == 0) |
22478 | newval &= 0xfffff0f0; | |
22479 | else | |
22480 | { | |
22481 | newval &= 0xff7ff0f0; | |
22482 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
22483 | } | |
c19d1205 ZW |
22484 | md_number_to_chars (buf, newval, INSN_SIZE); |
22485 | break; | |
b99bd4ef | 22486 | |
c19d1205 ZW |
22487 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
22488 | if (value < 0 || value > 1020 || value % 4 != 0) | |
22489 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22490 | _("bad immediate value for offset (%ld)"), (long) value); | |
22491 | value /= 4; | |
b99bd4ef | 22492 | |
c19d1205 | 22493 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
22494 | newval |= value; |
22495 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
22496 | break; | |
b99bd4ef | 22497 | |
c19d1205 ZW |
22498 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
22499 | /* This is a complicated relocation used for all varieties of Thumb32 | |
22500 | load/store instruction with immediate offset: | |
22501 | ||
22502 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
477330fc | 22503 | *4, optional writeback(W) |
c19d1205 ZW |
22504 | (doubleword load/store) |
22505 | ||
22506 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
22507 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
22508 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
22509 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
22510 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
22511 | ||
22512 | Uppercase letters indicate bits that are already encoded at | |
22513 | this point. Lowercase letters are our problem. For the | |
22514 | second block of instructions, the secondary opcode nybble | |
22515 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
22516 | a PC-relative operation. */ | |
22517 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22518 | newval <<= 16; | |
22519 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 22520 | |
c19d1205 | 22521 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 22522 | { |
c19d1205 ZW |
22523 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
22524 | if (value >= 0) | |
22525 | newval |= (1 << 23); | |
22526 | else | |
22527 | value = -value; | |
22528 | if (value % 4 != 0) | |
22529 | { | |
22530 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22531 | _("offset not a multiple of 4")); | |
22532 | break; | |
22533 | } | |
22534 | value /= 4; | |
216d22bc | 22535 | if (value > 0xff) |
c19d1205 ZW |
22536 | { |
22537 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22538 | _("offset out of range")); | |
22539 | break; | |
22540 | } | |
22541 | newval &= ~0xff; | |
b99bd4ef | 22542 | } |
c19d1205 | 22543 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 22544 | { |
c19d1205 ZW |
22545 | /* PC-relative, 12-bit offset. */ |
22546 | if (value >= 0) | |
22547 | newval |= (1 << 23); | |
22548 | else | |
22549 | value = -value; | |
216d22bc | 22550 | if (value > 0xfff) |
c19d1205 ZW |
22551 | { |
22552 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22553 | _("offset out of range")); | |
22554 | break; | |
22555 | } | |
22556 | newval &= ~0xfff; | |
b99bd4ef | 22557 | } |
c19d1205 | 22558 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 22559 | { |
c19d1205 ZW |
22560 | /* Writeback: 8-bit, +/- offset. */ |
22561 | if (value >= 0) | |
22562 | newval |= (1 << 9); | |
22563 | else | |
22564 | value = -value; | |
216d22bc | 22565 | if (value > 0xff) |
c19d1205 ZW |
22566 | { |
22567 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22568 | _("offset out of range")); | |
22569 | break; | |
22570 | } | |
22571 | newval &= ~0xff; | |
b99bd4ef | 22572 | } |
c19d1205 | 22573 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 22574 | { |
c19d1205 | 22575 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 22576 | if (value < 0 || value > 0xff) |
b99bd4ef | 22577 | { |
c19d1205 ZW |
22578 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22579 | _("offset out of range")); | |
22580 | break; | |
b99bd4ef | 22581 | } |
c19d1205 ZW |
22582 | newval &= ~0xff; |
22583 | newval |= value; | |
b99bd4ef NC |
22584 | } |
22585 | else | |
b99bd4ef | 22586 | { |
c19d1205 ZW |
22587 | /* Positive 12-bit or negative 8-bit offset. */ |
22588 | int limit; | |
22589 | if (value >= 0) | |
b99bd4ef | 22590 | { |
c19d1205 ZW |
22591 | newval |= (1 << 23); |
22592 | limit = 0xfff; | |
22593 | } | |
22594 | else | |
22595 | { | |
22596 | value = -value; | |
22597 | limit = 0xff; | |
22598 | } | |
22599 | if (value > limit) | |
22600 | { | |
22601 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22602 | _("offset out of range")); | |
22603 | break; | |
b99bd4ef | 22604 | } |
c19d1205 | 22605 | newval &= ~limit; |
b99bd4ef | 22606 | } |
b99bd4ef | 22607 | |
c19d1205 ZW |
22608 | newval |= value; |
22609 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
22610 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
22611 | break; | |
404ff6b5 | 22612 | |
c19d1205 ZW |
22613 | case BFD_RELOC_ARM_SHIFT_IMM: |
22614 | newval = md_chars_to_number (buf, INSN_SIZE); | |
22615 | if (((unsigned long) value) > 32 | |
22616 | || (value == 32 | |
22617 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
22618 | { | |
22619 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22620 | _("shift expression is too large")); | |
22621 | break; | |
22622 | } | |
404ff6b5 | 22623 | |
c19d1205 ZW |
22624 | if (value == 0) |
22625 | /* Shifts of zero must be done as lsl. */ | |
22626 | newval &= ~0x60; | |
22627 | else if (value == 32) | |
22628 | value = 0; | |
22629 | newval &= 0xfffff07f; | |
22630 | newval |= (value & 0x1f) << 7; | |
22631 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22632 | break; | |
404ff6b5 | 22633 | |
c19d1205 | 22634 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
16805f35 | 22635 | case BFD_RELOC_ARM_T32_ADD_IMM: |
92e90b6e | 22636 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 22637 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
22638 | /* We claim that this fixup has been processed here, |
22639 | even if in fact we generate an error because we do | |
22640 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
22641 | fixP->fx_done = 1; | |
404ff6b5 | 22642 | |
c19d1205 ZW |
22643 | if (fixP->fx_addsy |
22644 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
22645 | { | |
22646 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22647 | _("undefined symbol %s used as an immediate value"), | |
22648 | S_GET_NAME (fixP->fx_addsy)); | |
22649 | break; | |
22650 | } | |
404ff6b5 | 22651 | |
c19d1205 ZW |
22652 | newval = md_chars_to_number (buf, THUMB_SIZE); |
22653 | newval <<= 16; | |
22654 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 22655 | |
16805f35 PB |
22656 | newimm = FAIL; |
22657 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
22658 | || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
ef8d22e6 PB |
22659 | { |
22660 | newimm = encode_thumb32_immediate (value); | |
22661 | if (newimm == (unsigned int) FAIL) | |
22662 | newimm = thumb32_negate_data_op (&newval, value); | |
22663 | } | |
16805f35 PB |
22664 | if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE |
22665 | && newimm == (unsigned int) FAIL) | |
92e90b6e | 22666 | { |
16805f35 PB |
22667 | /* Turn add/sum into addw/subw. */ |
22668 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM) | |
22669 | newval = (newval & 0xfeffffff) | 0x02000000; | |
40f246e3 NC |
22670 | /* No flat 12-bit imm encoding for addsw/subsw. */ |
22671 | if ((newval & 0x00100000) == 0) | |
e9f89963 | 22672 | { |
40f246e3 NC |
22673 | /* 12 bit immediate for addw/subw. */ |
22674 | if (value < 0) | |
22675 | { | |
22676 | value = -value; | |
22677 | newval ^= 0x00a00000; | |
22678 | } | |
22679 | if (value > 0xfff) | |
22680 | newimm = (unsigned int) FAIL; | |
22681 | else | |
22682 | newimm = value; | |
e9f89963 | 22683 | } |
92e90b6e | 22684 | } |
cc8a6dd0 | 22685 | |
c19d1205 | 22686 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 22687 | { |
c19d1205 ZW |
22688 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22689 | _("invalid constant (%lx) after fixup"), | |
22690 | (unsigned long) value); | |
22691 | break; | |
3631a3c8 NC |
22692 | } |
22693 | ||
c19d1205 ZW |
22694 | newval |= (newimm & 0x800) << 15; |
22695 | newval |= (newimm & 0x700) << 4; | |
22696 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 22697 | |
c19d1205 ZW |
22698 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
22699 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
22700 | break; | |
a737bd4d | 22701 | |
3eb17e6b | 22702 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
22703 | if (((unsigned long) value) > 0xffff) |
22704 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 22705 | _("invalid smc expression")); |
2fc8bdac | 22706 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
22707 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
22708 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22709 | break; | |
a737bd4d | 22710 | |
90ec0d68 MGD |
22711 | case BFD_RELOC_ARM_HVC: |
22712 | if (((unsigned long) value) > 0xffff) | |
22713 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22714 | _("invalid hvc expression")); | |
22715 | newval = md_chars_to_number (buf, INSN_SIZE); | |
22716 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); | |
22717 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22718 | break; | |
22719 | ||
c19d1205 | 22720 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 22721 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
22722 | { |
22723 | if (((unsigned long) value) > 0xff) | |
22724 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22725 | _("invalid swi expression")); | |
2fc8bdac | 22726 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
22727 | newval |= value; |
22728 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22729 | } | |
22730 | else | |
22731 | { | |
22732 | if (((unsigned long) value) > 0x00ffffff) | |
22733 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22734 | _("invalid swi expression")); | |
2fc8bdac | 22735 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
22736 | newval |= value; |
22737 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22738 | } | |
22739 | break; | |
a737bd4d | 22740 | |
c19d1205 ZW |
22741 | case BFD_RELOC_ARM_MULTI: |
22742 | if (((unsigned long) value) > 0xffff) | |
22743 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22744 | _("invalid expression in load/store multiple")); | |
22745 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
22746 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22747 | break; | |
a737bd4d | 22748 | |
c19d1205 | 22749 | #ifdef OBJ_ELF |
39b41c9c | 22750 | case BFD_RELOC_ARM_PCREL_CALL: |
267bf995 RR |
22751 | |
22752 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
22753 | && fixP->fx_addsy | |
34e77a92 | 22754 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22755 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
22756 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
22757 | /* Flip the bl to blx. This is a simple flip | |
22758 | bit here because we generate PCREL_CALL for | |
22759 | unconditional bls. */ | |
22760 | { | |
22761 | newval = md_chars_to_number (buf, INSN_SIZE); | |
22762 | newval = newval | 0x10000000; | |
22763 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22764 | temp = 1; | |
22765 | fixP->fx_done = 1; | |
22766 | } | |
39b41c9c PB |
22767 | else |
22768 | temp = 3; | |
22769 | goto arm_branch_common; | |
22770 | ||
22771 | case BFD_RELOC_ARM_PCREL_JUMP: | |
267bf995 RR |
22772 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
22773 | && fixP->fx_addsy | |
34e77a92 | 22774 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22775 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
22776 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
22777 | { | |
22778 | /* This would map to a bl<cond>, b<cond>, | |
22779 | b<always> to a Thumb function. We | |
22780 | need to force a relocation for this particular | |
22781 | case. */ | |
22782 | newval = md_chars_to_number (buf, INSN_SIZE); | |
22783 | fixP->fx_done = 0; | |
22784 | } | |
22785 | ||
2fc8bdac | 22786 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 22787 | #endif |
39b41c9c PB |
22788 | case BFD_RELOC_ARM_PCREL_BRANCH: |
22789 | temp = 3; | |
22790 | goto arm_branch_common; | |
a737bd4d | 22791 | |
39b41c9c | 22792 | case BFD_RELOC_ARM_PCREL_BLX: |
267bf995 | 22793 | |
39b41c9c | 22794 | temp = 1; |
267bf995 RR |
22795 | if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) |
22796 | && fixP->fx_addsy | |
34e77a92 | 22797 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22798 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
22799 | && ARM_IS_FUNC (fixP->fx_addsy)) | |
22800 | { | |
22801 | /* Flip the blx to a bl and warn. */ | |
22802 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
22803 | newval = 0xeb000000; | |
22804 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
22805 | _("blx to '%s' an ARM ISA state function changed to bl"), | |
22806 | name); | |
22807 | md_number_to_chars (buf, newval, INSN_SIZE); | |
22808 | temp = 3; | |
22809 | fixP->fx_done = 1; | |
22810 | } | |
22811 | ||
22812 | #ifdef OBJ_ELF | |
22813 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
477330fc | 22814 | fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL; |
267bf995 RR |
22815 | #endif |
22816 | ||
39b41c9c | 22817 | arm_branch_common: |
c19d1205 | 22818 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
22819 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
22820 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
22821 | also be be clear. */ | |
22822 | if (value & temp) | |
c19d1205 | 22823 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
22824 | _("misaligned branch destination")); |
22825 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
22826 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
08f10d51 | 22827 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 22828 | |
2fc8bdac | 22829 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 22830 | { |
2fc8bdac ZW |
22831 | newval = md_chars_to_number (buf, INSN_SIZE); |
22832 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
22833 | /* Set the H bit on BLX instructions. */ |
22834 | if (temp == 1) | |
22835 | { | |
22836 | if (value & 2) | |
22837 | newval |= 0x01000000; | |
22838 | else | |
22839 | newval &= ~0x01000000; | |
22840 | } | |
2fc8bdac | 22841 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 22842 | } |
c19d1205 | 22843 | break; |
a737bd4d | 22844 | |
25fe350b MS |
22845 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */ |
22846 | /* CBZ can only branch forward. */ | |
a737bd4d | 22847 | |
738755b0 | 22848 | /* Attempts to use CBZ to branch to the next instruction |
477330fc RM |
22849 | (which, strictly speaking, are prohibited) will be turned into |
22850 | no-ops. | |
738755b0 MS |
22851 | |
22852 | FIXME: It may be better to remove the instruction completely and | |
22853 | perform relaxation. */ | |
22854 | if (value == -2) | |
2fc8bdac ZW |
22855 | { |
22856 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
738755b0 | 22857 | newval = 0xbf00; /* NOP encoding T1 */ |
2fc8bdac ZW |
22858 | md_number_to_chars (buf, newval, THUMB_SIZE); |
22859 | } | |
738755b0 MS |
22860 | else |
22861 | { | |
22862 | if (value & ~0x7e) | |
08f10d51 | 22863 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
738755b0 | 22864 | |
477330fc | 22865 | if (fixP->fx_done || !seg->use_rela_p) |
738755b0 MS |
22866 | { |
22867 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22868 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); | |
22869 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22870 | } | |
22871 | } | |
c19d1205 | 22872 | break; |
a737bd4d | 22873 | |
c19d1205 | 22874 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac | 22875 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
08f10d51 | 22876 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 22877 | |
2fc8bdac ZW |
22878 | if (fixP->fx_done || !seg->use_rela_p) |
22879 | { | |
22880 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22881 | newval |= (value & 0x1ff) >> 1; | |
22882 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22883 | } | |
c19d1205 | 22884 | break; |
a737bd4d | 22885 | |
c19d1205 | 22886 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac | 22887 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
08f10d51 | 22888 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
a737bd4d | 22889 | |
2fc8bdac ZW |
22890 | if (fixP->fx_done || !seg->use_rela_p) |
22891 | { | |
22892 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
22893 | newval |= (value & 0xfff) >> 1; | |
22894 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22895 | } | |
c19d1205 | 22896 | break; |
a737bd4d | 22897 | |
c19d1205 | 22898 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
267bf995 RR |
22899 | if (fixP->fx_addsy |
22900 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22901 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22902 | && ARM_IS_FUNC (fixP->fx_addsy) |
22903 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22904 | { | |
22905 | /* Force a relocation for a branch 20 bits wide. */ | |
22906 | fixP->fx_done = 0; | |
22907 | } | |
08f10d51 | 22908 | if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff)) |
2fc8bdac ZW |
22909 | as_bad_where (fixP->fx_file, fixP->fx_line, |
22910 | _("conditional branch out of range")); | |
404ff6b5 | 22911 | |
2fc8bdac ZW |
22912 | if (fixP->fx_done || !seg->use_rela_p) |
22913 | { | |
22914 | offsetT newval2; | |
22915 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 22916 | |
2fc8bdac ZW |
22917 | S = (value & 0x00100000) >> 20; |
22918 | J2 = (value & 0x00080000) >> 19; | |
22919 | J1 = (value & 0x00040000) >> 18; | |
22920 | hi = (value & 0x0003f000) >> 12; | |
22921 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 22922 | |
2fc8bdac ZW |
22923 | newval = md_chars_to_number (buf, THUMB_SIZE); |
22924 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22925 | newval |= (S << 10) | hi; | |
22926 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
22927 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
22928 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
22929 | } | |
c19d1205 | 22930 | break; |
6c43fab6 | 22931 | |
c19d1205 | 22932 | case BFD_RELOC_THUMB_PCREL_BLX: |
267bf995 RR |
22933 | /* If there is a blx from a thumb state function to |
22934 | another thumb function flip this to a bl and warn | |
22935 | about it. */ | |
22936 | ||
22937 | if (fixP->fx_addsy | |
34e77a92 | 22938 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22939 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) |
22940 | && THUMB_IS_FUNC (fixP->fx_addsy)) | |
22941 | { | |
22942 | const char *name = S_GET_NAME (fixP->fx_addsy); | |
22943 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
22944 | _("blx to Thumb func '%s' from Thumb ISA state changed to bl"), | |
22945 | name); | |
22946 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22947 | newval = newval | 0x1000; | |
22948 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
22949 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
22950 | fixP->fx_done = 1; | |
22951 | } | |
22952 | ||
22953 | ||
22954 | goto thumb_bl_common; | |
22955 | ||
c19d1205 | 22956 | case BFD_RELOC_THUMB_PCREL_BRANCH23: |
267bf995 RR |
22957 | /* A bl from Thumb state ISA to an internal ARM state function |
22958 | is converted to a blx. */ | |
22959 | if (fixP->fx_addsy | |
22960 | && (S_GET_SEGMENT (fixP->fx_addsy) == seg) | |
34e77a92 | 22961 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE) |
267bf995 RR |
22962 | && ARM_IS_FUNC (fixP->fx_addsy) |
22963 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)) | |
22964 | { | |
22965 | newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
22966 | newval = newval & ~0x1000; | |
22967 | md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE); | |
22968 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX; | |
22969 | fixP->fx_done = 1; | |
22970 | } | |
22971 | ||
22972 | thumb_bl_common: | |
22973 | ||
2fc8bdac ZW |
22974 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
22975 | /* For a BLX instruction, make sure that the relocation is rounded up | |
22976 | to a word boundary. This follows the semantics of the instruction | |
22977 | which specifies that bit 1 of the target address will come from bit | |
22978 | 1 of the base address. */ | |
d406f3e4 JB |
22979 | value = (value + 3) & ~ 3; |
22980 | ||
22981 | #ifdef OBJ_ELF | |
22982 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 | |
22983 | && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) | |
22984 | fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
22985 | #endif | |
404ff6b5 | 22986 | |
2b2f5df9 NC |
22987 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
22988 | { | |
fc289b0a | 22989 | if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))) |
2b2f5df9 NC |
22990 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); |
22991 | else if ((value & ~0x1ffffff) | |
22992 | && ((value & ~0x1ffffff) != ~0x1ffffff)) | |
22993 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
22994 | _("Thumb2 branch out of range")); | |
22995 | } | |
4a42ebbc RR |
22996 | |
22997 | if (fixP->fx_done || !seg->use_rela_p) | |
22998 | encode_thumb2_b_bl_offset (buf, value); | |
22999 | ||
c19d1205 | 23000 | break; |
404ff6b5 | 23001 | |
c19d1205 | 23002 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
08f10d51 NC |
23003 | if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff)) |
23004 | as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE); | |
6c43fab6 | 23005 | |
2fc8bdac | 23006 | if (fixP->fx_done || !seg->use_rela_p) |
4a42ebbc | 23007 | encode_thumb2_b_bl_offset (buf, value); |
6c43fab6 | 23008 | |
2fc8bdac | 23009 | break; |
a737bd4d | 23010 | |
2fc8bdac ZW |
23011 | case BFD_RELOC_8: |
23012 | if (fixP->fx_done || !seg->use_rela_p) | |
4b1a927e | 23013 | *buf = value; |
c19d1205 | 23014 | break; |
a737bd4d | 23015 | |
c19d1205 | 23016 | case BFD_RELOC_16: |
2fc8bdac | 23017 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 23018 | md_number_to_chars (buf, value, 2); |
c19d1205 | 23019 | break; |
a737bd4d | 23020 | |
c19d1205 | 23021 | #ifdef OBJ_ELF |
0855e32b NS |
23022 | case BFD_RELOC_ARM_TLS_CALL: |
23023 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
23024 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
23025 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
0855e32b | 23026 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 ZW |
23027 | case BFD_RELOC_ARM_TLS_GD32: |
23028 | case BFD_RELOC_ARM_TLS_LE32: | |
23029 | case BFD_RELOC_ARM_TLS_IE32: | |
23030 | case BFD_RELOC_ARM_TLS_LDM32: | |
23031 | case BFD_RELOC_ARM_TLS_LDO32: | |
23032 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
4b1a927e | 23033 | break; |
6c43fab6 | 23034 | |
c19d1205 ZW |
23035 | case BFD_RELOC_ARM_GOT32: |
23036 | case BFD_RELOC_ARM_GOTOFF: | |
c19d1205 | 23037 | break; |
b43420e6 NC |
23038 | |
23039 | case BFD_RELOC_ARM_GOT_PREL: | |
23040 | if (fixP->fx_done || !seg->use_rela_p) | |
477330fc | 23041 | md_number_to_chars (buf, value, 4); |
b43420e6 NC |
23042 | break; |
23043 | ||
9a6f4e97 NS |
23044 | case BFD_RELOC_ARM_TARGET2: |
23045 | /* TARGET2 is not partial-inplace, so we need to write the | |
477330fc RM |
23046 | addend here for REL targets, because it won't be written out |
23047 | during reloc processing later. */ | |
9a6f4e97 NS |
23048 | if (fixP->fx_done || !seg->use_rela_p) |
23049 | md_number_to_chars (buf, fixP->fx_offset, 4); | |
23050 | break; | |
c19d1205 | 23051 | #endif |
6c43fab6 | 23052 | |
c19d1205 ZW |
23053 | case BFD_RELOC_RVA: |
23054 | case BFD_RELOC_32: | |
23055 | case BFD_RELOC_ARM_TARGET1: | |
23056 | case BFD_RELOC_ARM_ROSEGREL32: | |
23057 | case BFD_RELOC_ARM_SBREL32: | |
23058 | case BFD_RELOC_32_PCREL: | |
f0927246 NC |
23059 | #ifdef TE_PE |
23060 | case BFD_RELOC_32_SECREL: | |
23061 | #endif | |
2fc8bdac | 23062 | if (fixP->fx_done || !seg->use_rela_p) |
53baae48 NC |
23063 | #ifdef TE_WINCE |
23064 | /* For WinCE we only do this for pcrel fixups. */ | |
23065 | if (fixP->fx_done || fixP->fx_pcrel) | |
23066 | #endif | |
23067 | md_number_to_chars (buf, value, 4); | |
c19d1205 | 23068 | break; |
6c43fab6 | 23069 | |
c19d1205 ZW |
23070 | #ifdef OBJ_ELF |
23071 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 23072 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
23073 | { |
23074 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
23075 | if ((value ^ (value >> 1)) & 0x40000000) | |
23076 | { | |
23077 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23078 | _("rel31 relocation overflow")); | |
23079 | } | |
23080 | newval |= value & 0x7fffffff; | |
23081 | md_number_to_chars (buf, newval, 4); | |
23082 | } | |
23083 | break; | |
c19d1205 | 23084 | #endif |
a737bd4d | 23085 | |
c19d1205 | 23086 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 23087 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
23088 | if (value < -1023 || value > 1023 || (value & 3)) |
23089 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23090 | _("co-processor offset out of range")); | |
23091 | cp_off_common: | |
26d97720 | 23092 | sign = value > 0; |
c19d1205 ZW |
23093 | if (value < 0) |
23094 | value = -value; | |
8f06b2d8 PB |
23095 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
23096 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
23097 | newval = md_chars_to_number (buf, INSN_SIZE); | |
23098 | else | |
23099 | newval = get_thumb32_insn (buf); | |
26d97720 NS |
23100 | if (value == 0) |
23101 | newval &= 0xffffff00; | |
23102 | else | |
23103 | { | |
23104 | newval &= 0xff7fff00; | |
23105 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); | |
23106 | } | |
8f06b2d8 PB |
23107 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
23108 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
23109 | md_number_to_chars (buf, newval, INSN_SIZE); | |
23110 | else | |
23111 | put_thumb32_insn (buf, newval); | |
c19d1205 | 23112 | break; |
a737bd4d | 23113 | |
c19d1205 | 23114 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 23115 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
23116 | if (value < -255 || value > 255) |
23117 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23118 | _("co-processor offset out of range")); | |
df7849c5 | 23119 | value *= 4; |
c19d1205 | 23120 | goto cp_off_common; |
6c43fab6 | 23121 | |
c19d1205 ZW |
23122 | case BFD_RELOC_ARM_THUMB_OFFSET: |
23123 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23124 | /* Exactly what ranges, and where the offset is inserted depends | |
23125 | on the type of instruction, we can establish this from the | |
23126 | top 4 bits. */ | |
23127 | switch (newval >> 12) | |
23128 | { | |
23129 | case 4: /* PC load. */ | |
23130 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
23131 | forced to zero for these loads; md_pcrel_from has already | |
23132 | compensated for this. */ | |
23133 | if (value & 3) | |
23134 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23135 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
23136 | (((unsigned long) fixP->fx_frag->fr_address |
23137 | + (unsigned long) fixP->fx_where) & ~3) | |
23138 | + (unsigned long) value); | |
a737bd4d | 23139 | |
c19d1205 ZW |
23140 | if (value & ~0x3fc) |
23141 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23142 | _("invalid offset, value too big (0x%08lX)"), | |
23143 | (long) value); | |
a737bd4d | 23144 | |
c19d1205 ZW |
23145 | newval |= value >> 2; |
23146 | break; | |
a737bd4d | 23147 | |
c19d1205 ZW |
23148 | case 9: /* SP load/store. */ |
23149 | if (value & ~0x3fc) | |
23150 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23151 | _("invalid offset, value too big (0x%08lX)"), | |
23152 | (long) value); | |
23153 | newval |= value >> 2; | |
23154 | break; | |
6c43fab6 | 23155 | |
c19d1205 ZW |
23156 | case 6: /* Word load/store. */ |
23157 | if (value & ~0x7c) | |
23158 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23159 | _("invalid offset, value too big (0x%08lX)"), | |
23160 | (long) value); | |
23161 | newval |= value << 4; /* 6 - 2. */ | |
23162 | break; | |
a737bd4d | 23163 | |
c19d1205 ZW |
23164 | case 7: /* Byte load/store. */ |
23165 | if (value & ~0x1f) | |
23166 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23167 | _("invalid offset, value too big (0x%08lX)"), | |
23168 | (long) value); | |
23169 | newval |= value << 6; | |
23170 | break; | |
a737bd4d | 23171 | |
c19d1205 ZW |
23172 | case 8: /* Halfword load/store. */ |
23173 | if (value & ~0x3e) | |
23174 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23175 | _("invalid offset, value too big (0x%08lX)"), | |
23176 | (long) value); | |
23177 | newval |= value << 5; /* 6 - 1. */ | |
23178 | break; | |
a737bd4d | 23179 | |
c19d1205 ZW |
23180 | default: |
23181 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23182 | "Unable to process relocation for thumb opcode: %lx", | |
23183 | (unsigned long) newval); | |
23184 | break; | |
23185 | } | |
23186 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23187 | break; | |
a737bd4d | 23188 | |
c19d1205 ZW |
23189 | case BFD_RELOC_ARM_THUMB_ADD: |
23190 | /* This is a complicated relocation, since we use it for all of | |
23191 | the following immediate relocations: | |
a737bd4d | 23192 | |
c19d1205 ZW |
23193 | 3bit ADD/SUB |
23194 | 8bit ADD/SUB | |
23195 | 9bit ADD/SUB SP word-aligned | |
23196 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 23197 | |
c19d1205 ZW |
23198 | The type of instruction being processed is encoded in the |
23199 | instruction field: | |
a737bd4d | 23200 | |
c19d1205 ZW |
23201 | 0x8000 SUB |
23202 | 0x00F0 Rd | |
23203 | 0x000F Rs | |
23204 | */ | |
23205 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23206 | { | |
23207 | int rd = (newval >> 4) & 0xf; | |
23208 | int rs = newval & 0xf; | |
23209 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 23210 | |
c19d1205 ZW |
23211 | /* Check for HI regs, only very restricted cases allowed: |
23212 | Adjusting SP, and using PC or SP to get an address. */ | |
23213 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
23214 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
23215 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23216 | _("invalid Hi register with immediate")); | |
a737bd4d | 23217 | |
c19d1205 ZW |
23218 | /* If value is negative, choose the opposite instruction. */ |
23219 | if (value < 0) | |
23220 | { | |
23221 | value = -value; | |
23222 | subtract = !subtract; | |
23223 | if (value < 0) | |
23224 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23225 | _("immediate value out of range")); | |
23226 | } | |
a737bd4d | 23227 | |
c19d1205 ZW |
23228 | if (rd == REG_SP) |
23229 | { | |
75c11999 | 23230 | if (value & ~0x1fc) |
c19d1205 ZW |
23231 | as_bad_where (fixP->fx_file, fixP->fx_line, |
23232 | _("invalid immediate for stack address calculation")); | |
23233 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
23234 | newval |= value >> 2; | |
23235 | } | |
23236 | else if (rs == REG_PC || rs == REG_SP) | |
23237 | { | |
c12d2c9d NC |
23238 | /* PR gas/18541. If the addition is for a defined symbol |
23239 | within range of an ADR instruction then accept it. */ | |
23240 | if (subtract | |
23241 | && value == 4 | |
23242 | && fixP->fx_addsy != NULL) | |
23243 | { | |
23244 | subtract = 0; | |
23245 | ||
23246 | if (! S_IS_DEFINED (fixP->fx_addsy) | |
23247 | || S_GET_SEGMENT (fixP->fx_addsy) != seg | |
23248 | || S_IS_WEAK (fixP->fx_addsy)) | |
23249 | { | |
23250 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23251 | _("address calculation needs a strongly defined nearby symbol")); | |
23252 | } | |
23253 | else | |
23254 | { | |
23255 | offsetT v = fixP->fx_where + fixP->fx_frag->fr_address; | |
23256 | ||
23257 | /* Round up to the next 4-byte boundary. */ | |
23258 | if (v & 3) | |
23259 | v = (v + 3) & ~ 3; | |
23260 | else | |
23261 | v += 4; | |
23262 | v = S_GET_VALUE (fixP->fx_addsy) - v; | |
23263 | ||
23264 | if (v & ~0x3fc) | |
23265 | { | |
23266 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23267 | _("symbol too far away")); | |
23268 | } | |
23269 | else | |
23270 | { | |
23271 | fixP->fx_done = 1; | |
23272 | value = v; | |
23273 | } | |
23274 | } | |
23275 | } | |
23276 | ||
c19d1205 ZW |
23277 | if (subtract || value & ~0x3fc) |
23278 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23279 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
5fc177c8 | 23280 | (unsigned long) (subtract ? - value : value)); |
c19d1205 ZW |
23281 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); |
23282 | newval |= rd << 8; | |
23283 | newval |= value >> 2; | |
23284 | } | |
23285 | else if (rs == rd) | |
23286 | { | |
23287 | if (value & ~0xff) | |
23288 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23289 | _("immediate value out of range")); | |
23290 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
23291 | newval |= (rd << 8) | value; | |
23292 | } | |
23293 | else | |
23294 | { | |
23295 | if (value & ~0x7) | |
23296 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23297 | _("immediate value out of range")); | |
23298 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
23299 | newval |= rd | (rs << 3) | (value << 6); | |
23300 | } | |
23301 | } | |
23302 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23303 | break; | |
a737bd4d | 23304 | |
c19d1205 ZW |
23305 | case BFD_RELOC_ARM_THUMB_IMM: |
23306 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
23307 | if (value < 0 || value > 255) | |
23308 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
4e6e072b | 23309 | _("invalid immediate: %ld is out of range"), |
c19d1205 ZW |
23310 | (long) value); |
23311 | newval |= value; | |
23312 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23313 | break; | |
a737bd4d | 23314 | |
c19d1205 ZW |
23315 | case BFD_RELOC_ARM_THUMB_SHIFT: |
23316 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
23317 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
23318 | temp = newval & 0xf800; | |
23319 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
23320 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23321 | _("invalid shift value: %ld"), (long) value); | |
23322 | /* Shifts of zero must be encoded as LSL. */ | |
23323 | if (value == 0) | |
23324 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
23325 | /* Shifts of 32 are encoded as zero. */ | |
23326 | else if (value == 32) | |
23327 | value = 0; | |
23328 | newval |= value << 6; | |
23329 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
23330 | break; | |
a737bd4d | 23331 | |
c19d1205 ZW |
23332 | case BFD_RELOC_VTABLE_INHERIT: |
23333 | case BFD_RELOC_VTABLE_ENTRY: | |
23334 | fixP->fx_done = 0; | |
23335 | return; | |
6c43fab6 | 23336 | |
b6895b4f PB |
23337 | case BFD_RELOC_ARM_MOVW: |
23338 | case BFD_RELOC_ARM_MOVT: | |
23339 | case BFD_RELOC_ARM_THUMB_MOVW: | |
23340 | case BFD_RELOC_ARM_THUMB_MOVT: | |
23341 | if (fixP->fx_done || !seg->use_rela_p) | |
23342 | { | |
23343 | /* REL format relocations are limited to a 16-bit addend. */ | |
23344 | if (!fixP->fx_done) | |
23345 | { | |
39623e12 | 23346 | if (value < -0x8000 || value > 0x7fff) |
b6895b4f | 23347 | as_bad_where (fixP->fx_file, fixP->fx_line, |
ff5075ca | 23348 | _("offset out of range")); |
b6895b4f PB |
23349 | } |
23350 | else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
23351 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
23352 | { | |
23353 | value >>= 16; | |
23354 | } | |
23355 | ||
23356 | if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
23357 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT) | |
23358 | { | |
23359 | newval = get_thumb32_insn (buf); | |
23360 | newval &= 0xfbf08f00; | |
23361 | newval |= (value & 0xf000) << 4; | |
23362 | newval |= (value & 0x0800) << 15; | |
23363 | newval |= (value & 0x0700) << 4; | |
23364 | newval |= (value & 0x00ff); | |
23365 | put_thumb32_insn (buf, newval); | |
23366 | } | |
23367 | else | |
23368 | { | |
23369 | newval = md_chars_to_number (buf, 4); | |
23370 | newval &= 0xfff0f000; | |
23371 | newval |= value & 0x0fff; | |
23372 | newval |= (value & 0xf000) << 4; | |
23373 | md_number_to_chars (buf, newval, 4); | |
23374 | } | |
23375 | } | |
23376 | return; | |
23377 | ||
72d98d16 MG |
23378 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
23379 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
23380 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
23381 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
23382 | gas_assert (!fixP->fx_done); | |
23383 | { | |
23384 | bfd_vma insn; | |
23385 | bfd_boolean is_mov; | |
23386 | bfd_vma encoded_addend = value; | |
23387 | ||
23388 | /* Check that addend can be encoded in instruction. */ | |
23389 | if (!seg->use_rela_p && (value < 0 || value > 255)) | |
23390 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23391 | _("the offset 0x%08lX is not representable"), | |
23392 | (unsigned long) encoded_addend); | |
23393 | ||
23394 | /* Extract the instruction. */ | |
23395 | insn = md_chars_to_number (buf, THUMB_SIZE); | |
23396 | is_mov = (insn & 0xf800) == 0x2000; | |
23397 | ||
23398 | /* Encode insn. */ | |
23399 | if (is_mov) | |
23400 | { | |
23401 | if (!seg->use_rela_p) | |
23402 | insn |= encoded_addend; | |
23403 | } | |
23404 | else | |
23405 | { | |
23406 | int rd, rs; | |
23407 | ||
23408 | /* Extract the instruction. */ | |
23409 | /* Encoding is the following | |
23410 | 0x8000 SUB | |
23411 | 0x00F0 Rd | |
23412 | 0x000F Rs | |
23413 | */ | |
23414 | /* The following conditions must be true : | |
23415 | - ADD | |
23416 | - Rd == Rs | |
23417 | - Rd <= 7 | |
23418 | */ | |
23419 | rd = (insn >> 4) & 0xf; | |
23420 | rs = insn & 0xf; | |
23421 | if ((insn & 0x8000) || (rd != rs) || rd > 7) | |
23422 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23423 | _("Unable to process relocation for thumb opcode: %lx"), | |
23424 | (unsigned long) insn); | |
23425 | ||
23426 | /* Encode as ADD immediate8 thumb 1 code. */ | |
23427 | insn = 0x3000 | (rd << 8); | |
23428 | ||
23429 | /* Place the encoded addend into the first 8 bits of the | |
23430 | instruction. */ | |
23431 | if (!seg->use_rela_p) | |
23432 | insn |= encoded_addend; | |
23433 | } | |
23434 | ||
23435 | /* Update the instruction. */ | |
23436 | md_number_to_chars (buf, insn, THUMB_SIZE); | |
23437 | } | |
23438 | break; | |
23439 | ||
4962c51a MS |
23440 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
23441 | case BFD_RELOC_ARM_ALU_PC_G0: | |
23442 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
23443 | case BFD_RELOC_ARM_ALU_PC_G1: | |
23444 | case BFD_RELOC_ARM_ALU_PC_G2: | |
23445 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
23446 | case BFD_RELOC_ARM_ALU_SB_G0: | |
23447 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
23448 | case BFD_RELOC_ARM_ALU_SB_G1: | |
23449 | case BFD_RELOC_ARM_ALU_SB_G2: | |
9c2799c2 | 23450 | gas_assert (!fixP->fx_done); |
4962c51a MS |
23451 | if (!seg->use_rela_p) |
23452 | { | |
477330fc RM |
23453 | bfd_vma insn; |
23454 | bfd_vma encoded_addend; | |
23455 | bfd_vma addend_abs = abs (value); | |
23456 | ||
23457 | /* Check that the absolute value of the addend can be | |
23458 | expressed as an 8-bit constant plus a rotation. */ | |
23459 | encoded_addend = encode_arm_immediate (addend_abs); | |
23460 | if (encoded_addend == (unsigned int) FAIL) | |
4962c51a | 23461 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23462 | _("the offset 0x%08lX is not representable"), |
23463 | (unsigned long) addend_abs); | |
23464 | ||
23465 | /* Extract the instruction. */ | |
23466 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23467 | ||
23468 | /* If the addend is positive, use an ADD instruction. | |
23469 | Otherwise use a SUB. Take care not to destroy the S bit. */ | |
23470 | insn &= 0xff1fffff; | |
23471 | if (value < 0) | |
23472 | insn |= 1 << 22; | |
23473 | else | |
23474 | insn |= 1 << 23; | |
23475 | ||
23476 | /* Place the encoded addend into the first 12 bits of the | |
23477 | instruction. */ | |
23478 | insn &= 0xfffff000; | |
23479 | insn |= encoded_addend; | |
23480 | ||
23481 | /* Update the instruction. */ | |
23482 | md_number_to_chars (buf, insn, INSN_SIZE); | |
4962c51a MS |
23483 | } |
23484 | break; | |
23485 | ||
23486 | case BFD_RELOC_ARM_LDR_PC_G0: | |
23487 | case BFD_RELOC_ARM_LDR_PC_G1: | |
23488 | case BFD_RELOC_ARM_LDR_PC_G2: | |
23489 | case BFD_RELOC_ARM_LDR_SB_G0: | |
23490 | case BFD_RELOC_ARM_LDR_SB_G1: | |
23491 | case BFD_RELOC_ARM_LDR_SB_G2: | |
9c2799c2 | 23492 | gas_assert (!fixP->fx_done); |
4962c51a | 23493 | if (!seg->use_rela_p) |
477330fc RM |
23494 | { |
23495 | bfd_vma insn; | |
23496 | bfd_vma addend_abs = abs (value); | |
4962c51a | 23497 | |
477330fc RM |
23498 | /* Check that the absolute value of the addend can be |
23499 | encoded in 12 bits. */ | |
23500 | if (addend_abs >= 0x1000) | |
4962c51a | 23501 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23502 | _("bad offset 0x%08lX (only 12 bits available for the magnitude)"), |
23503 | (unsigned long) addend_abs); | |
23504 | ||
23505 | /* Extract the instruction. */ | |
23506 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23507 | ||
23508 | /* If the addend is negative, clear bit 23 of the instruction. | |
23509 | Otherwise set it. */ | |
23510 | if (value < 0) | |
23511 | insn &= ~(1 << 23); | |
23512 | else | |
23513 | insn |= 1 << 23; | |
23514 | ||
23515 | /* Place the absolute value of the addend into the first 12 bits | |
23516 | of the instruction. */ | |
23517 | insn &= 0xfffff000; | |
23518 | insn |= addend_abs; | |
23519 | ||
23520 | /* Update the instruction. */ | |
23521 | md_number_to_chars (buf, insn, INSN_SIZE); | |
23522 | } | |
4962c51a MS |
23523 | break; |
23524 | ||
23525 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
23526 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
23527 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
23528 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
23529 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
23530 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
9c2799c2 | 23531 | gas_assert (!fixP->fx_done); |
4962c51a | 23532 | if (!seg->use_rela_p) |
477330fc RM |
23533 | { |
23534 | bfd_vma insn; | |
23535 | bfd_vma addend_abs = abs (value); | |
4962c51a | 23536 | |
477330fc RM |
23537 | /* Check that the absolute value of the addend can be |
23538 | encoded in 8 bits. */ | |
23539 | if (addend_abs >= 0x100) | |
4962c51a | 23540 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23541 | _("bad offset 0x%08lX (only 8 bits available for the magnitude)"), |
23542 | (unsigned long) addend_abs); | |
23543 | ||
23544 | /* Extract the instruction. */ | |
23545 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23546 | ||
23547 | /* If the addend is negative, clear bit 23 of the instruction. | |
23548 | Otherwise set it. */ | |
23549 | if (value < 0) | |
23550 | insn &= ~(1 << 23); | |
23551 | else | |
23552 | insn |= 1 << 23; | |
23553 | ||
23554 | /* Place the first four bits of the absolute value of the addend | |
23555 | into the first 4 bits of the instruction, and the remaining | |
23556 | four into bits 8 .. 11. */ | |
23557 | insn &= 0xfffff0f0; | |
23558 | insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4); | |
23559 | ||
23560 | /* Update the instruction. */ | |
23561 | md_number_to_chars (buf, insn, INSN_SIZE); | |
23562 | } | |
4962c51a MS |
23563 | break; |
23564 | ||
23565 | case BFD_RELOC_ARM_LDC_PC_G0: | |
23566 | case BFD_RELOC_ARM_LDC_PC_G1: | |
23567 | case BFD_RELOC_ARM_LDC_PC_G2: | |
23568 | case BFD_RELOC_ARM_LDC_SB_G0: | |
23569 | case BFD_RELOC_ARM_LDC_SB_G1: | |
23570 | case BFD_RELOC_ARM_LDC_SB_G2: | |
9c2799c2 | 23571 | gas_assert (!fixP->fx_done); |
4962c51a | 23572 | if (!seg->use_rela_p) |
477330fc RM |
23573 | { |
23574 | bfd_vma insn; | |
23575 | bfd_vma addend_abs = abs (value); | |
4962c51a | 23576 | |
477330fc RM |
23577 | /* Check that the absolute value of the addend is a multiple of |
23578 | four and, when divided by four, fits in 8 bits. */ | |
23579 | if (addend_abs & 0x3) | |
4962c51a | 23580 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23581 | _("bad offset 0x%08lX (must be word-aligned)"), |
23582 | (unsigned long) addend_abs); | |
4962c51a | 23583 | |
477330fc | 23584 | if ((addend_abs >> 2) > 0xff) |
4962c51a | 23585 | as_bad_where (fixP->fx_file, fixP->fx_line, |
477330fc RM |
23586 | _("bad offset 0x%08lX (must be an 8-bit number of words)"), |
23587 | (unsigned long) addend_abs); | |
23588 | ||
23589 | /* Extract the instruction. */ | |
23590 | insn = md_chars_to_number (buf, INSN_SIZE); | |
23591 | ||
23592 | /* If the addend is negative, clear bit 23 of the instruction. | |
23593 | Otherwise set it. */ | |
23594 | if (value < 0) | |
23595 | insn &= ~(1 << 23); | |
23596 | else | |
23597 | insn |= 1 << 23; | |
23598 | ||
23599 | /* Place the addend (divided by four) into the first eight | |
23600 | bits of the instruction. */ | |
23601 | insn &= 0xfffffff0; | |
23602 | insn |= addend_abs >> 2; | |
23603 | ||
23604 | /* Update the instruction. */ | |
23605 | md_number_to_chars (buf, insn, INSN_SIZE); | |
23606 | } | |
4962c51a MS |
23607 | break; |
23608 | ||
845b51d6 PB |
23609 | case BFD_RELOC_ARM_V4BX: |
23610 | /* This will need to go in the object file. */ | |
23611 | fixP->fx_done = 0; | |
23612 | break; | |
23613 | ||
c19d1205 ZW |
23614 | case BFD_RELOC_UNUSED: |
23615 | default: | |
23616 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
23617 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
23618 | } | |
6c43fab6 RE |
23619 | } |
23620 | ||
c19d1205 ZW |
23621 | /* Translate internal representation of relocation info to BFD target |
23622 | format. */ | |
a737bd4d | 23623 | |
c19d1205 | 23624 | arelent * |
00a97672 | 23625 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 23626 | { |
c19d1205 ZW |
23627 | arelent * reloc; |
23628 | bfd_reloc_code_real_type code; | |
a737bd4d | 23629 | |
21d799b5 | 23630 | reloc = (arelent *) xmalloc (sizeof (arelent)); |
a737bd4d | 23631 | |
21d799b5 | 23632 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
c19d1205 ZW |
23633 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
23634 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 23635 | |
2fc8bdac | 23636 | if (fixp->fx_pcrel) |
00a97672 RS |
23637 | { |
23638 | if (section->use_rela_p) | |
23639 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
23640 | else | |
23641 | fixp->fx_offset = reloc->address; | |
23642 | } | |
c19d1205 | 23643 | reloc->addend = fixp->fx_offset; |
a737bd4d | 23644 | |
c19d1205 | 23645 | switch (fixp->fx_r_type) |
a737bd4d | 23646 | { |
c19d1205 ZW |
23647 | case BFD_RELOC_8: |
23648 | if (fixp->fx_pcrel) | |
23649 | { | |
23650 | code = BFD_RELOC_8_PCREL; | |
23651 | break; | |
23652 | } | |
a737bd4d | 23653 | |
c19d1205 ZW |
23654 | case BFD_RELOC_16: |
23655 | if (fixp->fx_pcrel) | |
23656 | { | |
23657 | code = BFD_RELOC_16_PCREL; | |
23658 | break; | |
23659 | } | |
6c43fab6 | 23660 | |
c19d1205 ZW |
23661 | case BFD_RELOC_32: |
23662 | if (fixp->fx_pcrel) | |
23663 | { | |
23664 | code = BFD_RELOC_32_PCREL; | |
23665 | break; | |
23666 | } | |
a737bd4d | 23667 | |
b6895b4f PB |
23668 | case BFD_RELOC_ARM_MOVW: |
23669 | if (fixp->fx_pcrel) | |
23670 | { | |
23671 | code = BFD_RELOC_ARM_MOVW_PCREL; | |
23672 | break; | |
23673 | } | |
23674 | ||
23675 | case BFD_RELOC_ARM_MOVT: | |
23676 | if (fixp->fx_pcrel) | |
23677 | { | |
23678 | code = BFD_RELOC_ARM_MOVT_PCREL; | |
23679 | break; | |
23680 | } | |
23681 | ||
23682 | case BFD_RELOC_ARM_THUMB_MOVW: | |
23683 | if (fixp->fx_pcrel) | |
23684 | { | |
23685 | code = BFD_RELOC_ARM_THUMB_MOVW_PCREL; | |
23686 | break; | |
23687 | } | |
23688 | ||
23689 | case BFD_RELOC_ARM_THUMB_MOVT: | |
23690 | if (fixp->fx_pcrel) | |
23691 | { | |
23692 | code = BFD_RELOC_ARM_THUMB_MOVT_PCREL; | |
23693 | break; | |
23694 | } | |
23695 | ||
c19d1205 ZW |
23696 | case BFD_RELOC_NONE: |
23697 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
23698 | case BFD_RELOC_ARM_PCREL_BLX: | |
23699 | case BFD_RELOC_RVA: | |
23700 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
23701 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
23702 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
23703 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
23704 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
23705 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
c19d1205 ZW |
23706 | case BFD_RELOC_VTABLE_ENTRY: |
23707 | case BFD_RELOC_VTABLE_INHERIT: | |
f0927246 NC |
23708 | #ifdef TE_PE |
23709 | case BFD_RELOC_32_SECREL: | |
23710 | #endif | |
c19d1205 ZW |
23711 | code = fixp->fx_r_type; |
23712 | break; | |
a737bd4d | 23713 | |
00adf2d4 JB |
23714 | case BFD_RELOC_THUMB_PCREL_BLX: |
23715 | #ifdef OBJ_ELF | |
23716 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
23717 | code = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
23718 | else | |
23719 | #endif | |
23720 | code = BFD_RELOC_THUMB_PCREL_BLX; | |
23721 | break; | |
23722 | ||
c19d1205 ZW |
23723 | case BFD_RELOC_ARM_LITERAL: |
23724 | case BFD_RELOC_ARM_HWLITERAL: | |
23725 | /* If this is called then the a literal has | |
23726 | been referenced across a section boundary. */ | |
23727 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
23728 | _("literal referenced across section boundary")); | |
23729 | return NULL; | |
a737bd4d | 23730 | |
c19d1205 | 23731 | #ifdef OBJ_ELF |
0855e32b NS |
23732 | case BFD_RELOC_ARM_TLS_CALL: |
23733 | case BFD_RELOC_ARM_THM_TLS_CALL: | |
23734 | case BFD_RELOC_ARM_TLS_DESCSEQ: | |
23735 | case BFD_RELOC_ARM_THM_TLS_DESCSEQ: | |
c19d1205 ZW |
23736 | case BFD_RELOC_ARM_GOT32: |
23737 | case BFD_RELOC_ARM_GOTOFF: | |
b43420e6 | 23738 | case BFD_RELOC_ARM_GOT_PREL: |
c19d1205 ZW |
23739 | case BFD_RELOC_ARM_PLT32: |
23740 | case BFD_RELOC_ARM_TARGET1: | |
23741 | case BFD_RELOC_ARM_ROSEGREL32: | |
23742 | case BFD_RELOC_ARM_SBREL32: | |
23743 | case BFD_RELOC_ARM_PREL31: | |
23744 | case BFD_RELOC_ARM_TARGET2: | |
c19d1205 | 23745 | case BFD_RELOC_ARM_TLS_LDO32: |
39b41c9c PB |
23746 | case BFD_RELOC_ARM_PCREL_CALL: |
23747 | case BFD_RELOC_ARM_PCREL_JUMP: | |
4962c51a MS |
23748 | case BFD_RELOC_ARM_ALU_PC_G0_NC: |
23749 | case BFD_RELOC_ARM_ALU_PC_G0: | |
23750 | case BFD_RELOC_ARM_ALU_PC_G1_NC: | |
23751 | case BFD_RELOC_ARM_ALU_PC_G1: | |
23752 | case BFD_RELOC_ARM_ALU_PC_G2: | |
23753 | case BFD_RELOC_ARM_LDR_PC_G0: | |
23754 | case BFD_RELOC_ARM_LDR_PC_G1: | |
23755 | case BFD_RELOC_ARM_LDR_PC_G2: | |
23756 | case BFD_RELOC_ARM_LDRS_PC_G0: | |
23757 | case BFD_RELOC_ARM_LDRS_PC_G1: | |
23758 | case BFD_RELOC_ARM_LDRS_PC_G2: | |
23759 | case BFD_RELOC_ARM_LDC_PC_G0: | |
23760 | case BFD_RELOC_ARM_LDC_PC_G1: | |
23761 | case BFD_RELOC_ARM_LDC_PC_G2: | |
23762 | case BFD_RELOC_ARM_ALU_SB_G0_NC: | |
23763 | case BFD_RELOC_ARM_ALU_SB_G0: | |
23764 | case BFD_RELOC_ARM_ALU_SB_G1_NC: | |
23765 | case BFD_RELOC_ARM_ALU_SB_G1: | |
23766 | case BFD_RELOC_ARM_ALU_SB_G2: | |
23767 | case BFD_RELOC_ARM_LDR_SB_G0: | |
23768 | case BFD_RELOC_ARM_LDR_SB_G1: | |
23769 | case BFD_RELOC_ARM_LDR_SB_G2: | |
23770 | case BFD_RELOC_ARM_LDRS_SB_G0: | |
23771 | case BFD_RELOC_ARM_LDRS_SB_G1: | |
23772 | case BFD_RELOC_ARM_LDRS_SB_G2: | |
23773 | case BFD_RELOC_ARM_LDC_SB_G0: | |
23774 | case BFD_RELOC_ARM_LDC_SB_G1: | |
23775 | case BFD_RELOC_ARM_LDC_SB_G2: | |
845b51d6 | 23776 | case BFD_RELOC_ARM_V4BX: |
72d98d16 MG |
23777 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC: |
23778 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC: | |
23779 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC: | |
23780 | case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC: | |
c19d1205 ZW |
23781 | code = fixp->fx_r_type; |
23782 | break; | |
a737bd4d | 23783 | |
0855e32b | 23784 | case BFD_RELOC_ARM_TLS_GOTDESC: |
c19d1205 | 23785 | case BFD_RELOC_ARM_TLS_GD32: |
75c11999 | 23786 | case BFD_RELOC_ARM_TLS_LE32: |
c19d1205 ZW |
23787 | case BFD_RELOC_ARM_TLS_IE32: |
23788 | case BFD_RELOC_ARM_TLS_LDM32: | |
23789 | /* BFD will include the symbol's address in the addend. | |
23790 | But we don't want that, so subtract it out again here. */ | |
23791 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
23792 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
23793 | code = fixp->fx_r_type; | |
23794 | break; | |
23795 | #endif | |
a737bd4d | 23796 | |
c19d1205 ZW |
23797 | case BFD_RELOC_ARM_IMMEDIATE: |
23798 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
23799 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
23800 | return NULL; | |
a737bd4d | 23801 | |
c19d1205 ZW |
23802 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
23803 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
23804 | _("ADRL used for a symbol not defined in the same file")); | |
23805 | return NULL; | |
a737bd4d | 23806 | |
c19d1205 | 23807 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
23808 | if (section->use_rela_p) |
23809 | { | |
23810 | code = fixp->fx_r_type; | |
23811 | break; | |
23812 | } | |
23813 | ||
c19d1205 ZW |
23814 | if (fixp->fx_addsy != NULL |
23815 | && !S_IS_DEFINED (fixp->fx_addsy) | |
23816 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 23817 | { |
c19d1205 ZW |
23818 | as_bad_where (fixp->fx_file, fixp->fx_line, |
23819 | _("undefined local label `%s'"), | |
23820 | S_GET_NAME (fixp->fx_addsy)); | |
23821 | return NULL; | |
a737bd4d NC |
23822 | } |
23823 | ||
c19d1205 ZW |
23824 | as_bad_where (fixp->fx_file, fixp->fx_line, |
23825 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
23826 | return NULL; | |
a737bd4d | 23827 | |
c19d1205 ZW |
23828 | default: |
23829 | { | |
23830 | char * type; | |
6c43fab6 | 23831 | |
c19d1205 ZW |
23832 | switch (fixp->fx_r_type) |
23833 | { | |
23834 | case BFD_RELOC_NONE: type = "NONE"; break; | |
23835 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
23836 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 23837 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
23838 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
23839 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
23840 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
db187cb9 | 23841 | case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break; |
8f06b2d8 | 23842 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
23843 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
23844 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
23845 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
23846 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
23847 | default: type = _("<unknown>"); break; | |
23848 | } | |
23849 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
23850 | _("cannot represent %s relocation in this object file format"), | |
23851 | type); | |
23852 | return NULL; | |
23853 | } | |
a737bd4d | 23854 | } |
6c43fab6 | 23855 | |
c19d1205 ZW |
23856 | #ifdef OBJ_ELF |
23857 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
23858 | && GOT_symbol | |
23859 | && fixp->fx_addsy == GOT_symbol) | |
23860 | { | |
23861 | code = BFD_RELOC_ARM_GOTPC; | |
23862 | reloc->addend = fixp->fx_offset = reloc->address; | |
23863 | } | |
23864 | #endif | |
6c43fab6 | 23865 | |
c19d1205 | 23866 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 23867 | |
c19d1205 ZW |
23868 | if (reloc->howto == NULL) |
23869 | { | |
23870 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
23871 | _("cannot represent %s relocation in this object file format"), | |
23872 | bfd_get_reloc_code_name (code)); | |
23873 | return NULL; | |
23874 | } | |
6c43fab6 | 23875 | |
c19d1205 ZW |
23876 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
23877 | vtable entry to be used in the relocation's section offset. */ | |
23878 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
23879 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 23880 | |
c19d1205 | 23881 | return reloc; |
6c43fab6 RE |
23882 | } |
23883 | ||
c19d1205 | 23884 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 23885 | |
c19d1205 ZW |
23886 | void |
23887 | cons_fix_new_arm (fragS * frag, | |
23888 | int where, | |
23889 | int size, | |
62ebcb5c AM |
23890 | expressionS * exp, |
23891 | bfd_reloc_code_real_type reloc) | |
6c43fab6 | 23892 | { |
c19d1205 | 23893 | int pcrel = 0; |
6c43fab6 | 23894 | |
c19d1205 ZW |
23895 | /* Pick a reloc. |
23896 | FIXME: @@ Should look at CPU word size. */ | |
23897 | switch (size) | |
23898 | { | |
23899 | case 1: | |
62ebcb5c | 23900 | reloc = BFD_RELOC_8; |
c19d1205 ZW |
23901 | break; |
23902 | case 2: | |
62ebcb5c | 23903 | reloc = BFD_RELOC_16; |
c19d1205 ZW |
23904 | break; |
23905 | case 4: | |
23906 | default: | |
62ebcb5c | 23907 | reloc = BFD_RELOC_32; |
c19d1205 ZW |
23908 | break; |
23909 | case 8: | |
62ebcb5c | 23910 | reloc = BFD_RELOC_64; |
c19d1205 ZW |
23911 | break; |
23912 | } | |
6c43fab6 | 23913 | |
f0927246 NC |
23914 | #ifdef TE_PE |
23915 | if (exp->X_op == O_secrel) | |
23916 | { | |
23917 | exp->X_op = O_symbol; | |
62ebcb5c | 23918 | reloc = BFD_RELOC_32_SECREL; |
f0927246 NC |
23919 | } |
23920 | #endif | |
23921 | ||
62ebcb5c | 23922 | fix_new_exp (frag, where, size, exp, pcrel, reloc); |
c19d1205 | 23923 | } |
6c43fab6 | 23924 | |
4343666d | 23925 | #if defined (OBJ_COFF) |
c19d1205 ZW |
23926 | void |
23927 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 23928 | { |
c19d1205 ZW |
23929 | /* If the destination of the branch is a defined symbol which does not have |
23930 | the THUMB_FUNC attribute, then we must be calling a function which has | |
23931 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
23932 | function and change the branch to refer to that function instead. */ | |
23933 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
23934 | && fixP->fx_addsy != NULL | |
23935 | && S_IS_DEFINED (fixP->fx_addsy) | |
23936 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 23937 | { |
c19d1205 | 23938 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 23939 | } |
c19d1205 ZW |
23940 | } |
23941 | #endif | |
6c43fab6 | 23942 | |
267bf995 | 23943 | |
c19d1205 ZW |
23944 | int |
23945 | arm_force_relocation (struct fix * fixp) | |
23946 | { | |
23947 | #if defined (OBJ_COFF) && defined (TE_PE) | |
23948 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
23949 | return 1; | |
23950 | #endif | |
6c43fab6 | 23951 | |
267bf995 RR |
23952 | /* In case we have a call or a branch to a function in ARM ISA mode from |
23953 | a thumb function or vice-versa force the relocation. These relocations | |
23954 | are cleared off for some cores that might have blx and simple transformations | |
23955 | are possible. */ | |
23956 | ||
23957 | #ifdef OBJ_ELF | |
23958 | switch (fixp->fx_r_type) | |
23959 | { | |
23960 | case BFD_RELOC_ARM_PCREL_JUMP: | |
23961 | case BFD_RELOC_ARM_PCREL_CALL: | |
23962 | case BFD_RELOC_THUMB_PCREL_BLX: | |
23963 | if (THUMB_IS_FUNC (fixp->fx_addsy)) | |
23964 | return 1; | |
23965 | break; | |
23966 | ||
23967 | case BFD_RELOC_ARM_PCREL_BLX: | |
23968 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
23969 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
23970 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
23971 | if (ARM_IS_FUNC (fixp->fx_addsy)) | |
23972 | return 1; | |
23973 | break; | |
23974 | ||
23975 | default: | |
23976 | break; | |
23977 | } | |
23978 | #endif | |
23979 | ||
b5884301 PB |
23980 | /* Resolve these relocations even if the symbol is extern or weak. |
23981 | Technically this is probably wrong due to symbol preemption. | |
23982 | In practice these relocations do not have enough range to be useful | |
23983 | at dynamic link time, and some code (e.g. in the Linux kernel) | |
23984 | expects these references to be resolved. */ | |
c19d1205 ZW |
23985 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE |
23986 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
b5884301 | 23987 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8 |
0110f2b8 | 23988 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
b5884301 PB |
23989 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
23990 | || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2 | |
23991 | || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET | |
16805f35 | 23992 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM |
0110f2b8 PB |
23993 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE |
23994 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
b5884301 PB |
23995 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM |
23996 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12 | |
23997 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM | |
23998 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2) | |
c19d1205 | 23999 | return 0; |
a737bd4d | 24000 | |
4962c51a MS |
24001 | /* Always leave these relocations for the linker. */ |
24002 | if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
24003 | && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
24004 | || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
24005 | return 1; | |
24006 | ||
f0291e4c PB |
24007 | /* Always generate relocations against function symbols. */ |
24008 | if (fixp->fx_r_type == BFD_RELOC_32 | |
24009 | && fixp->fx_addsy | |
24010 | && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION)) | |
24011 | return 1; | |
24012 | ||
c19d1205 | 24013 | return generic_force_reloc (fixp); |
404ff6b5 AH |
24014 | } |
24015 | ||
0ffdc86c | 24016 | #if defined (OBJ_ELF) || defined (OBJ_COFF) |
e28387c3 PB |
24017 | /* Relocations against function names must be left unadjusted, |
24018 | so that the linker can use this information to generate interworking | |
24019 | stubs. The MIPS version of this function | |
c19d1205 ZW |
24020 | also prevents relocations that are mips-16 specific, but I do not |
24021 | know why it does this. | |
404ff6b5 | 24022 | |
c19d1205 ZW |
24023 | FIXME: |
24024 | There is one other problem that ought to be addressed here, but | |
24025 | which currently is not: Taking the address of a label (rather | |
24026 | than a function) and then later jumping to that address. Such | |
24027 | addresses also ought to have their bottom bit set (assuming that | |
24028 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 24029 | |
c19d1205 ZW |
24030 | bfd_boolean |
24031 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 24032 | { |
c19d1205 ZW |
24033 | if (fixP->fx_addsy == NULL) |
24034 | return 1; | |
404ff6b5 | 24035 | |
e28387c3 PB |
24036 | /* Preserve relocations against symbols with function type. */ |
24037 | if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION) | |
c921be7d | 24038 | return FALSE; |
e28387c3 | 24039 | |
c19d1205 ZW |
24040 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
24041 | && fixP->fx_subsy == NULL) | |
c921be7d | 24042 | return FALSE; |
a737bd4d | 24043 | |
c19d1205 ZW |
24044 | /* We need the symbol name for the VTABLE entries. */ |
24045 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
24046 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
c921be7d | 24047 | return FALSE; |
404ff6b5 | 24048 | |
c19d1205 ZW |
24049 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
24050 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
24051 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
24052 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
24053 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
24054 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
24055 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
24056 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
24057 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
0855e32b NS |
24058 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC |
24059 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL | |
24060 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL | |
24061 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ | |
24062 | || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ | |
c19d1205 | 24063 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) |
c921be7d | 24064 | return FALSE; |
a737bd4d | 24065 | |
4962c51a MS |
24066 | /* Similarly for group relocations. */ |
24067 | if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC | |
24068 | && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2) | |
24069 | || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0) | |
c921be7d | 24070 | return FALSE; |
4962c51a | 24071 | |
79947c54 CD |
24072 | /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */ |
24073 | if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW | |
24074 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT | |
24075 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL | |
24076 | || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL | |
24077 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW | |
24078 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT | |
24079 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL | |
24080 | || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL) | |
c921be7d | 24081 | return FALSE; |
79947c54 | 24082 | |
72d98d16 MG |
24083 | /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited |
24084 | offsets, so keep these symbols. */ | |
24085 | if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC | |
24086 | && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) | |
24087 | return FALSE; | |
24088 | ||
c921be7d | 24089 | return TRUE; |
a737bd4d | 24090 | } |
0ffdc86c NC |
24091 | #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */ |
24092 | ||
24093 | #ifdef OBJ_ELF | |
404ff6b5 | 24094 | |
c19d1205 ZW |
24095 | const char * |
24096 | elf32_arm_target_format (void) | |
404ff6b5 | 24097 | { |
c19d1205 ZW |
24098 | #ifdef TE_SYMBIAN |
24099 | return (target_big_endian | |
24100 | ? "elf32-bigarm-symbian" | |
24101 | : "elf32-littlearm-symbian"); | |
24102 | #elif defined (TE_VXWORKS) | |
24103 | return (target_big_endian | |
24104 | ? "elf32-bigarm-vxworks" | |
24105 | : "elf32-littlearm-vxworks"); | |
b38cadfb NC |
24106 | #elif defined (TE_NACL) |
24107 | return (target_big_endian | |
24108 | ? "elf32-bigarm-nacl" | |
24109 | : "elf32-littlearm-nacl"); | |
c19d1205 ZW |
24110 | #else |
24111 | if (target_big_endian) | |
24112 | return "elf32-bigarm"; | |
24113 | else | |
24114 | return "elf32-littlearm"; | |
24115 | #endif | |
404ff6b5 AH |
24116 | } |
24117 | ||
c19d1205 ZW |
24118 | void |
24119 | armelf_frob_symbol (symbolS * symp, | |
24120 | int * puntp) | |
404ff6b5 | 24121 | { |
c19d1205 ZW |
24122 | elf_frob_symbol (symp, puntp); |
24123 | } | |
24124 | #endif | |
404ff6b5 | 24125 | |
c19d1205 | 24126 | /* MD interface: Finalization. */ |
a737bd4d | 24127 | |
c19d1205 ZW |
24128 | void |
24129 | arm_cleanup (void) | |
24130 | { | |
24131 | literal_pool * pool; | |
a737bd4d | 24132 | |
e07e6e58 NC |
24133 | /* Ensure that all the IT blocks are properly closed. */ |
24134 | check_it_blocks_finished (); | |
24135 | ||
c19d1205 ZW |
24136 | for (pool = list_of_pools; pool; pool = pool->next) |
24137 | { | |
5f4273c7 | 24138 | /* Put it at the end of the relevant section. */ |
c19d1205 ZW |
24139 | subseg_set (pool->section, pool->sub_section); |
24140 | #ifdef OBJ_ELF | |
24141 | arm_elf_change_section (); | |
24142 | #endif | |
24143 | s_ltorg (0); | |
24144 | } | |
404ff6b5 AH |
24145 | } |
24146 | ||
cd000bff DJ |
24147 | #ifdef OBJ_ELF |
24148 | /* Remove any excess mapping symbols generated for alignment frags in | |
24149 | SEC. We may have created a mapping symbol before a zero byte | |
24150 | alignment; remove it if there's a mapping symbol after the | |
24151 | alignment. */ | |
24152 | static void | |
24153 | check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, | |
24154 | void *dummy ATTRIBUTE_UNUSED) | |
24155 | { | |
24156 | segment_info_type *seginfo = seg_info (sec); | |
24157 | fragS *fragp; | |
24158 | ||
24159 | if (seginfo == NULL || seginfo->frchainP == NULL) | |
24160 | return; | |
24161 | ||
24162 | for (fragp = seginfo->frchainP->frch_root; | |
24163 | fragp != NULL; | |
24164 | fragp = fragp->fr_next) | |
24165 | { | |
24166 | symbolS *sym = fragp->tc_frag_data.last_map; | |
24167 | fragS *next = fragp->fr_next; | |
24168 | ||
24169 | /* Variable-sized frags have been converted to fixed size by | |
24170 | this point. But if this was variable-sized to start with, | |
24171 | there will be a fixed-size frag after it. So don't handle | |
24172 | next == NULL. */ | |
24173 | if (sym == NULL || next == NULL) | |
24174 | continue; | |
24175 | ||
24176 | if (S_GET_VALUE (sym) < next->fr_address) | |
24177 | /* Not at the end of this frag. */ | |
24178 | continue; | |
24179 | know (S_GET_VALUE (sym) == next->fr_address); | |
24180 | ||
24181 | do | |
24182 | { | |
24183 | if (next->tc_frag_data.first_map != NULL) | |
24184 | { | |
24185 | /* Next frag starts with a mapping symbol. Discard this | |
24186 | one. */ | |
24187 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
24188 | break; | |
24189 | } | |
24190 | ||
24191 | if (next->fr_next == NULL) | |
24192 | { | |
24193 | /* This mapping symbol is at the end of the section. Discard | |
24194 | it. */ | |
24195 | know (next->fr_fix == 0 && next->fr_var == 0); | |
24196 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); | |
24197 | break; | |
24198 | } | |
24199 | ||
24200 | /* As long as we have empty frags without any mapping symbols, | |
24201 | keep looking. */ | |
24202 | /* If the next frag is non-empty and does not start with a | |
24203 | mapping symbol, then this mapping symbol is required. */ | |
24204 | if (next->fr_address != next->fr_next->fr_address) | |
24205 | break; | |
24206 | ||
24207 | next = next->fr_next; | |
24208 | } | |
24209 | while (next != NULL); | |
24210 | } | |
24211 | } | |
24212 | #endif | |
24213 | ||
c19d1205 ZW |
24214 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
24215 | ARM ones. */ | |
404ff6b5 | 24216 | |
c19d1205 ZW |
24217 | void |
24218 | arm_adjust_symtab (void) | |
404ff6b5 | 24219 | { |
c19d1205 ZW |
24220 | #ifdef OBJ_COFF |
24221 | symbolS * sym; | |
404ff6b5 | 24222 | |
c19d1205 ZW |
24223 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
24224 | { | |
24225 | if (ARM_IS_THUMB (sym)) | |
24226 | { | |
24227 | if (THUMB_IS_FUNC (sym)) | |
24228 | { | |
24229 | /* Mark the symbol as a Thumb function. */ | |
24230 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
24231 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
24232 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 24233 | |
c19d1205 ZW |
24234 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
24235 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
24236 | else | |
24237 | as_bad (_("%s: unexpected function type: %d"), | |
24238 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
24239 | } | |
24240 | else switch (S_GET_STORAGE_CLASS (sym)) | |
24241 | { | |
24242 | case C_EXT: | |
24243 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
24244 | break; | |
24245 | case C_STAT: | |
24246 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
24247 | break; | |
24248 | case C_LABEL: | |
24249 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
24250 | break; | |
24251 | default: | |
24252 | /* Do nothing. */ | |
24253 | break; | |
24254 | } | |
24255 | } | |
a737bd4d | 24256 | |
c19d1205 ZW |
24257 | if (ARM_IS_INTERWORK (sym)) |
24258 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 24259 | } |
c19d1205 ZW |
24260 | #endif |
24261 | #ifdef OBJ_ELF | |
24262 | symbolS * sym; | |
24263 | char bind; | |
404ff6b5 | 24264 | |
c19d1205 | 24265 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 24266 | { |
c19d1205 ZW |
24267 | if (ARM_IS_THUMB (sym)) |
24268 | { | |
24269 | elf_symbol_type * elf_sym; | |
404ff6b5 | 24270 | |
c19d1205 ZW |
24271 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
24272 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 24273 | |
b0796911 PB |
24274 | if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name, |
24275 | BFD_ARM_SPECIAL_SYM_TYPE_ANY)) | |
c19d1205 ZW |
24276 | { |
24277 | /* If it's a .thumb_func, declare it as so, | |
24278 | otherwise tag label as .code 16. */ | |
24279 | if (THUMB_IS_FUNC (sym)) | |
35fc36a8 RS |
24280 | elf_sym->internal_elf_sym.st_target_internal |
24281 | = ST_BRANCH_TO_THUMB; | |
3ba67470 | 24282 | else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
c19d1205 ZW |
24283 | elf_sym->internal_elf_sym.st_info = |
24284 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
24285 | } | |
24286 | } | |
24287 | } | |
cd000bff DJ |
24288 | |
24289 | /* Remove any overlapping mapping symbols generated by alignment frags. */ | |
24290 | bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0); | |
709001e9 MM |
24291 | /* Now do generic ELF adjustments. */ |
24292 | elf_adjust_symtab (); | |
c19d1205 | 24293 | #endif |
404ff6b5 AH |
24294 | } |
24295 | ||
c19d1205 | 24296 | /* MD interface: Initialization. */ |
404ff6b5 | 24297 | |
a737bd4d | 24298 | static void |
c19d1205 | 24299 | set_constant_flonums (void) |
a737bd4d | 24300 | { |
c19d1205 | 24301 | int i; |
404ff6b5 | 24302 | |
c19d1205 ZW |
24303 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
24304 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
24305 | abort (); | |
a737bd4d | 24306 | } |
404ff6b5 | 24307 | |
3e9e4fcf JB |
24308 | /* Auto-select Thumb mode if it's the only available instruction set for the |
24309 | given architecture. */ | |
24310 | ||
24311 | static void | |
24312 | autoselect_thumb_from_cpu_variant (void) | |
24313 | { | |
24314 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) | |
24315 | opcode_select (16); | |
24316 | } | |
24317 | ||
c19d1205 ZW |
24318 | void |
24319 | md_begin (void) | |
a737bd4d | 24320 | { |
c19d1205 ZW |
24321 | unsigned mach; |
24322 | unsigned int i; | |
404ff6b5 | 24323 | |
c19d1205 ZW |
24324 | if ( (arm_ops_hsh = hash_new ()) == NULL |
24325 | || (arm_cond_hsh = hash_new ()) == NULL | |
24326 | || (arm_shift_hsh = hash_new ()) == NULL | |
24327 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 24328 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 24329 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
24330 | || (arm_reloc_hsh = hash_new ()) == NULL |
24331 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
24332 | as_fatal (_("virtual memory exhausted")); |
24333 | ||
24334 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
d3ce72d0 | 24335 | hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i)); |
c19d1205 | 24336 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) |
d3ce72d0 | 24337 | hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i)); |
c19d1205 | 24338 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) |
5a49b8ac | 24339 | hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i)); |
c19d1205 | 24340 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 24341 | hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i)); |
62b3e311 | 24342 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
d3ce72d0 | 24343 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name, |
477330fc | 24344 | (void *) (v7m_psrs + i)); |
c19d1205 | 24345 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
5a49b8ac | 24346 | hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i)); |
62b3e311 PB |
24347 | for (i = 0; |
24348 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
24349 | i++) | |
d3ce72d0 | 24350 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name, |
5a49b8ac | 24351 | (void *) (barrier_opt_names + i)); |
c19d1205 | 24352 | #ifdef OBJ_ELF |
3da1d841 NC |
24353 | for (i = 0; i < ARRAY_SIZE (reloc_names); i++) |
24354 | { | |
24355 | struct reloc_entry * entry = reloc_names + i; | |
24356 | ||
24357 | if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32) | |
24358 | /* This makes encode_branch() use the EABI versions of this relocation. */ | |
24359 | entry->reloc = BFD_RELOC_UNUSED; | |
24360 | ||
24361 | hash_insert (arm_reloc_hsh, entry->name, (void *) entry); | |
24362 | } | |
c19d1205 ZW |
24363 | #endif |
24364 | ||
24365 | set_constant_flonums (); | |
404ff6b5 | 24366 | |
c19d1205 ZW |
24367 | /* Set the cpu variant based on the command-line options. We prefer |
24368 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
24369 | -mfpu= over any other way of setting the floating point unit. | |
24370 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 24371 | if (legacy_cpu) |
404ff6b5 | 24372 | { |
e74cfd16 | 24373 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
24374 | as_bad (_("use of old and new-style options to set CPU type")); |
24375 | ||
24376 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 24377 | } |
e74cfd16 | 24378 | else if (!mcpu_cpu_opt) |
c19d1205 | 24379 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 24380 | |
e74cfd16 | 24381 | if (legacy_fpu) |
c19d1205 | 24382 | { |
e74cfd16 | 24383 | if (mfpu_opt) |
c19d1205 | 24384 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
24385 | |
24386 | mfpu_opt = legacy_fpu; | |
24387 | } | |
e74cfd16 | 24388 | else if (!mfpu_opt) |
03b1477f | 24389 | { |
45eb4c1b NS |
24390 | #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \ |
24391 | || defined (TE_NetBSD) || defined (TE_VXWORKS)) | |
39c2da32 RE |
24392 | /* Some environments specify a default FPU. If they don't, infer it |
24393 | from the processor. */ | |
e74cfd16 | 24394 | if (mcpu_fpu_opt) |
03b1477f RE |
24395 | mfpu_opt = mcpu_fpu_opt; |
24396 | else | |
24397 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 24398 | #else |
e74cfd16 | 24399 | mfpu_opt = &fpu_default; |
39c2da32 | 24400 | #endif |
03b1477f RE |
24401 | } |
24402 | ||
e74cfd16 | 24403 | if (!mfpu_opt) |
03b1477f | 24404 | { |
493cb6ef | 24405 | if (mcpu_cpu_opt != NULL) |
e74cfd16 | 24406 | mfpu_opt = &fpu_default; |
493cb6ef | 24407 | else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) |
e74cfd16 | 24408 | mfpu_opt = &fpu_arch_vfp_v2; |
03b1477f | 24409 | else |
e74cfd16 | 24410 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
24411 | } |
24412 | ||
ee065d83 | 24413 | #ifdef CPU_DEFAULT |
e74cfd16 | 24414 | if (!mcpu_cpu_opt) |
ee065d83 | 24415 | { |
e74cfd16 PB |
24416 | mcpu_cpu_opt = &cpu_default; |
24417 | selected_cpu = cpu_default; | |
ee065d83 | 24418 | } |
73f43896 NC |
24419 | else if (no_cpu_selected ()) |
24420 | selected_cpu = cpu_default; | |
e74cfd16 PB |
24421 | #else |
24422 | if (mcpu_cpu_opt) | |
24423 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 24424 | else |
e74cfd16 | 24425 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 24426 | #endif |
03b1477f | 24427 | |
e74cfd16 | 24428 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 24429 | |
3e9e4fcf JB |
24430 | autoselect_thumb_from_cpu_variant (); |
24431 | ||
e74cfd16 | 24432 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 24433 | |
f17c130b | 24434 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 24435 | { |
7cc69913 NC |
24436 | unsigned int flags = 0; |
24437 | ||
24438 | #if defined OBJ_ELF | |
24439 | flags = meabi_flags; | |
d507cf36 PB |
24440 | |
24441 | switch (meabi_flags) | |
33a392fb | 24442 | { |
d507cf36 | 24443 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 24444 | #endif |
d507cf36 PB |
24445 | /* Set the flags in the private structure. */ |
24446 | if (uses_apcs_26) flags |= F_APCS26; | |
24447 | if (support_interwork) flags |= F_INTERWORK; | |
24448 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 24449 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 24450 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
24451 | flags |= F_SOFT_FLOAT; |
24452 | ||
d507cf36 PB |
24453 | switch (mfloat_abi_opt) |
24454 | { | |
24455 | case ARM_FLOAT_ABI_SOFT: | |
24456 | case ARM_FLOAT_ABI_SOFTFP: | |
24457 | flags |= F_SOFT_FLOAT; | |
24458 | break; | |
33a392fb | 24459 | |
d507cf36 PB |
24460 | case ARM_FLOAT_ABI_HARD: |
24461 | if (flags & F_SOFT_FLOAT) | |
24462 | as_bad (_("hard-float conflicts with specified fpu")); | |
24463 | break; | |
24464 | } | |
03b1477f | 24465 | |
e74cfd16 PB |
24466 | /* Using pure-endian doubles (even if soft-float). */ |
24467 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 24468 | flags |= F_VFP_FLOAT; |
f17c130b | 24469 | |
fde78edd | 24470 | #if defined OBJ_ELF |
e74cfd16 | 24471 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 24472 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
24473 | break; |
24474 | ||
8cb51566 | 24475 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 24476 | case EF_ARM_EABI_VER5: |
c19d1205 | 24477 | /* No additional flags to set. */ |
d507cf36 PB |
24478 | break; |
24479 | ||
24480 | default: | |
24481 | abort (); | |
24482 | } | |
7cc69913 | 24483 | #endif |
b99bd4ef NC |
24484 | bfd_set_private_flags (stdoutput, flags); |
24485 | ||
24486 | /* We have run out flags in the COFF header to encode the | |
24487 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 24488 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
24489 | if (atpcs) |
24490 | { | |
24491 | asection * sec; | |
24492 | ||
24493 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
24494 | ||
24495 | if (sec != NULL) | |
24496 | { | |
24497 | bfd_set_section_flags | |
24498 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
24499 | bfd_set_section_size (stdoutput, sec, 0); | |
24500 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
24501 | } | |
24502 | } | |
7cc69913 | 24503 | } |
f17c130b | 24504 | #endif |
b99bd4ef NC |
24505 | |
24506 | /* Record the CPU type as well. */ | |
2d447fca JM |
24507 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)) |
24508 | mach = bfd_mach_arm_iWMMXt2; | |
24509 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) | |
e16bb312 | 24510 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 24511 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 24512 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 24513 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 24514 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 24515 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 24516 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 24517 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 24518 | { |
e74cfd16 | 24519 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
24520 | mach = bfd_mach_arm_5T; |
24521 | else | |
24522 | mach = bfd_mach_arm_5; | |
24523 | } | |
e74cfd16 | 24524 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 24525 | { |
e74cfd16 | 24526 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
24527 | mach = bfd_mach_arm_4T; |
24528 | else | |
24529 | mach = bfd_mach_arm_4; | |
24530 | } | |
e74cfd16 | 24531 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 24532 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
24533 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
24534 | mach = bfd_mach_arm_3; | |
24535 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
24536 | mach = bfd_mach_arm_2a; | |
24537 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
24538 | mach = bfd_mach_arm_2; | |
24539 | else | |
24540 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
24541 | |
24542 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
24543 | } | |
24544 | ||
c19d1205 | 24545 | /* Command line processing. */ |
b99bd4ef | 24546 | |
c19d1205 ZW |
24547 | /* md_parse_option |
24548 | Invocation line includes a switch not recognized by the base assembler. | |
24549 | See if it's a processor-specific option. | |
b99bd4ef | 24550 | |
c19d1205 ZW |
24551 | This routine is somewhat complicated by the need for backwards |
24552 | compatibility (since older releases of gcc can't be changed). | |
24553 | The new options try to make the interface as compatible as | |
24554 | possible with GCC. | |
b99bd4ef | 24555 | |
c19d1205 | 24556 | New options (supported) are: |
b99bd4ef | 24557 | |
c19d1205 ZW |
24558 | -mcpu=<cpu name> Assemble for selected processor |
24559 | -march=<architecture name> Assemble for selected architecture | |
24560 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
24561 | -EB/-mbig-endian Big-endian | |
24562 | -EL/-mlittle-endian Little-endian | |
24563 | -k Generate PIC code | |
24564 | -mthumb Start in Thumb mode | |
24565 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 24566 | |
278df34e | 24567 | -m[no-]warn-deprecated Warn about deprecated features |
8b2d793c | 24568 | -m[no-]warn-syms Warn when symbols match instructions |
267bf995 | 24569 | |
c19d1205 | 24570 | For now we will also provide support for: |
b99bd4ef | 24571 | |
c19d1205 ZW |
24572 | -mapcs-32 32-bit Program counter |
24573 | -mapcs-26 26-bit Program counter | |
24574 | -macps-float Floats passed in FP registers | |
24575 | -mapcs-reentrant Reentrant code | |
24576 | -matpcs | |
24577 | (sometime these will probably be replaced with -mapcs=<list of options> | |
24578 | and -matpcs=<list of options>) | |
b99bd4ef | 24579 | |
c19d1205 ZW |
24580 | The remaining options are only supported for back-wards compatibility. |
24581 | Cpu variants, the arm part is optional: | |
24582 | -m[arm]1 Currently not supported. | |
24583 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
24584 | -m[arm]3 Arm 3 processor | |
24585 | -m[arm]6[xx], Arm 6 processors | |
24586 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
24587 | -m[arm]8[10] Arm 8 processors | |
24588 | -m[arm]9[20][tdmi] Arm 9 processors | |
24589 | -mstrongarm[110[0]] StrongARM processors | |
24590 | -mxscale XScale processors | |
24591 | -m[arm]v[2345[t[e]]] Arm architectures | |
24592 | -mall All (except the ARM1) | |
24593 | FP variants: | |
24594 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
24595 | -mfpe-old (No float load/store multiples) | |
24596 | -mvfpxd VFP Single precision | |
24597 | -mvfp All VFP | |
24598 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 24599 | |
c19d1205 ZW |
24600 | The following CPU names are recognized: |
24601 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
24602 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
24603 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
24604 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
24605 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
24606 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
24607 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 24608 | |
c19d1205 | 24609 | */ |
b99bd4ef | 24610 | |
c19d1205 | 24611 | const char * md_shortopts = "m:k"; |
b99bd4ef | 24612 | |
c19d1205 ZW |
24613 | #ifdef ARM_BI_ENDIAN |
24614 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
24615 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 24616 | #else |
c19d1205 ZW |
24617 | #if TARGET_BYTES_BIG_ENDIAN |
24618 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 24619 | #else |
c19d1205 ZW |
24620 | #define OPTION_EL (OPTION_MD_BASE + 1) |
24621 | #endif | |
b99bd4ef | 24622 | #endif |
845b51d6 | 24623 | #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2) |
b99bd4ef | 24624 | |
c19d1205 | 24625 | struct option md_longopts[] = |
b99bd4ef | 24626 | { |
c19d1205 ZW |
24627 | #ifdef OPTION_EB |
24628 | {"EB", no_argument, NULL, OPTION_EB}, | |
24629 | #endif | |
24630 | #ifdef OPTION_EL | |
24631 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 24632 | #endif |
845b51d6 | 24633 | {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX}, |
c19d1205 ZW |
24634 | {NULL, no_argument, NULL, 0} |
24635 | }; | |
b99bd4ef | 24636 | |
8b2d793c | 24637 | |
c19d1205 | 24638 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 24639 | |
c19d1205 | 24640 | struct arm_option_table |
b99bd4ef | 24641 | { |
c19d1205 ZW |
24642 | char *option; /* Option name to match. */ |
24643 | char *help; /* Help information. */ | |
24644 | int *var; /* Variable to change. */ | |
24645 | int value; /* What to change it to. */ | |
24646 | char *deprecated; /* If non-null, print this message. */ | |
24647 | }; | |
b99bd4ef | 24648 | |
c19d1205 ZW |
24649 | struct arm_option_table arm_opts[] = |
24650 | { | |
24651 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
24652 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
24653 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
24654 | &support_interwork, 1, NULL}, | |
24655 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
24656 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
24657 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
24658 | 1, NULL}, | |
24659 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
24660 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
24661 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
24662 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
24663 | NULL}, | |
b99bd4ef | 24664 | |
c19d1205 ZW |
24665 | /* These are recognized by the assembler, but have no affect on code. */ |
24666 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
24667 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
278df34e NS |
24668 | |
24669 | {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL}, | |
24670 | {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"), | |
24671 | &warn_on_deprecated, 0, NULL}, | |
8b2d793c NC |
24672 | {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL}, |
24673 | {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL}, | |
e74cfd16 PB |
24674 | {NULL, NULL, NULL, 0, NULL} |
24675 | }; | |
24676 | ||
24677 | struct arm_legacy_option_table | |
24678 | { | |
24679 | char *option; /* Option name to match. */ | |
24680 | const arm_feature_set **var; /* Variable to change. */ | |
24681 | const arm_feature_set value; /* What to change it to. */ | |
24682 | char *deprecated; /* If non-null, print this message. */ | |
24683 | }; | |
b99bd4ef | 24684 | |
e74cfd16 PB |
24685 | const struct arm_legacy_option_table arm_legacy_opts[] = |
24686 | { | |
c19d1205 ZW |
24687 | /* DON'T add any new processors to this list -- we want the whole list |
24688 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
24689 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
24690 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
24691 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
24692 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
24693 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
24694 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
24695 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
24696 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
24697 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
24698 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
24699 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
24700 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
24701 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
24702 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
24703 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
24704 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
24705 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
24706 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
24707 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
24708 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
24709 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
24710 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
24711 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
24712 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
24713 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
24714 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
24715 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
24716 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
24717 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
24718 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
24719 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
24720 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
24721 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
24722 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
24723 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
24724 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
24725 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
24726 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
24727 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
24728 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
24729 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
24730 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
24731 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
24732 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
24733 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
24734 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
24735 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
24736 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
24737 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
24738 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
24739 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
24740 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
24741 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
24742 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
24743 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
24744 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
24745 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
24746 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
24747 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
24748 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
24749 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
24750 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
24751 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
24752 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
24753 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
24754 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
24755 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
24756 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
24757 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
24758 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 24759 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 24760 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 24761 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 24762 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 24763 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
24764 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
24765 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
24766 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 24767 | |
c19d1205 | 24768 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
24769 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
24770 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
24771 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
24772 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
24773 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
24774 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
24775 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
24776 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
24777 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
24778 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
24779 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
24780 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
24781 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
24782 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
24783 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
24784 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
24785 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
24786 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 24787 | |
c19d1205 | 24788 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
24789 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
24790 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
24791 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
24792 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 24793 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 24794 | |
e74cfd16 | 24795 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 24796 | }; |
7ed4c4c5 | 24797 | |
c19d1205 | 24798 | struct arm_cpu_option_table |
7ed4c4c5 | 24799 | { |
c19d1205 | 24800 | char *name; |
f3bad469 | 24801 | size_t name_len; |
e74cfd16 | 24802 | const arm_feature_set value; |
c19d1205 ZW |
24803 | /* For some CPUs we assume an FPU unless the user explicitly sets |
24804 | -mfpu=... */ | |
e74cfd16 | 24805 | const arm_feature_set default_fpu; |
ee065d83 PB |
24806 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
24807 | case. */ | |
24808 | const char *canonical_name; | |
c19d1205 | 24809 | }; |
7ed4c4c5 | 24810 | |
c19d1205 ZW |
24811 | /* This list should, at a minimum, contain all the cpu names |
24812 | recognized by GCC. */ | |
f3bad469 | 24813 | #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN } |
e74cfd16 | 24814 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 24815 | { |
f3bad469 MGD |
24816 | ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL), |
24817 | ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL), | |
24818 | ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL), | |
24819 | ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL), | |
24820 | ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL), | |
24821 | ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24822 | ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24823 | ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24824 | ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24825 | ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24826 | ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24827 | ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
24828 | ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24829 | ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
24830 | ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24831 | ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL), | |
24832 | ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24833 | ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24834 | ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24835 | ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24836 | ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24837 | ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24838 | ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24839 | ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24840 | ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24841 | ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24842 | ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24843 | ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL), | |
24844 | ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24845 | ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24846 | ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24847 | ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24848 | ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24849 | ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24850 | ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24851 | ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24852 | ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24853 | ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24854 | ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24855 | ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"), | |
24856 | ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24857 | ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24858 | ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24859 | ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL), | |
24860 | ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
24861 | ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL), | |
c19d1205 ZW |
24862 | /* For V5 or later processors we default to using VFP; but the user |
24863 | should really set the FPU type explicitly. */ | |
f3bad469 MGD |
24864 | ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), |
24865 | ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24866 | ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"), | |
24867 | ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"), | |
24868 | ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL), | |
24869 | ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), | |
24870 | ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"), | |
24871 | ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24872 | ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL), | |
24873 | ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"), | |
24874 | ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24875 | ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24876 | ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
24877 | ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
24878 | ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24879 | ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"), | |
24880 | ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL), | |
24881 | ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24882 | ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24883 | ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, | |
24884 | "ARM1026EJ-S"), | |
24885 | ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL), | |
24886 | ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24887 | ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24888 | ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24889 | ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24890 | ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL), | |
24891 | ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"), | |
24892 | ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL), | |
24893 | ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, | |
24894 | "ARM1136JF-S"), | |
24895 | ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL), | |
24896 | ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"), | |
24897 | ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"), | |
24898 | ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL), | |
24899 | ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL), | |
f33026a9 MW |
24900 | ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL), |
24901 | ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL), | |
f3bad469 MGD |
24902 | ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC, |
24903 | FPU_NONE, "Cortex-A5"), | |
c9fb6e58 | 24904 | ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
f3bad469 MGD |
24905 | "Cortex-A7"), |
24906 | ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC, | |
823d2571 | 24907 | ARM_FEATURE_COPROC (FPU_VFP_V3 |
477330fc | 24908 | | FPU_NEON_EXT_V1), |
f3bad469 MGD |
24909 | "Cortex-A8"), |
24910 | ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC, | |
823d2571 | 24911 | ARM_FEATURE_COPROC (FPU_VFP_V3 |
477330fc | 24912 | | FPU_NEON_EXT_V1), |
f3bad469 | 24913 | "Cortex-A9"), |
c9fb6e58 | 24914 | ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
63a4bc21 | 24915 | "Cortex-A12"), |
c9fb6e58 | 24916 | ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
f3bad469 | 24917 | "Cortex-A15"), |
d7adf960 KT |
24918 | ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4, |
24919 | "Cortex-A17"), | |
43cdc0a8 RR |
24920 | ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
24921 | "Cortex-A35"), | |
92eb40d9 | 24922 | ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
477330fc | 24923 | "Cortex-A53"), |
92eb40d9 | 24924 | ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
477330fc | 24925 | "Cortex-A57"), |
b19f47ad JW |
24926 | ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
24927 | "Cortex-A72"), | |
f3bad469 MGD |
24928 | ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"), |
24929 | ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, | |
24930 | "Cortex-R4F"), | |
24931 | ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV, | |
24932 | FPU_NONE, "Cortex-R5"), | |
70a8bc5b | 24933 | ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV, |
24934 | FPU_ARCH_VFP_V3D16, | |
24935 | "Cortex-R7"), | |
a715796b | 24936 | ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"), |
f3bad469 MGD |
24937 | ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"), |
24938 | ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"), | |
24939 | ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"), | |
24940 | ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"), | |
ce32bd10 | 24941 | ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"), |
246496bb EM |
24942 | ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
24943 | "Samsung " \ | |
24944 | "Exynos M1"), | |
6b21c2bf JW |
24945 | ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
24946 | "Qualcomm " | |
24947 | "QDF24XX"), | |
24948 | ||
c19d1205 | 24949 | /* ??? XSCALE is really an architecture. */ |
f3bad469 | 24950 | ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL), |
c19d1205 | 24951 | /* ??? iwmmxt is not a processor. */ |
f3bad469 MGD |
24952 | ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL), |
24953 | ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL), | |
24954 | ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL), | |
c19d1205 | 24955 | /* Maverick */ |
823d2571 | 24956 | ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), |
da4339ed NC |
24957 | FPU_ARCH_MAVERICK, "ARM920T"), |
24958 | /* Marvell processors. */ | |
ff8646ee TP |
24959 | ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP |
24960 | | ARM_EXT_SEC, | |
24961 | ARM_EXT2_V6T2_V8M), | |
477330fc | 24962 | FPU_ARCH_VFP_V3D16, NULL), |
ff8646ee TP |
24963 | ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP |
24964 | | ARM_EXT_SEC, | |
24965 | ARM_EXT2_V6T2_V8M), | |
4347085a | 24966 | FPU_ARCH_NEON_VFP_V4, NULL), |
ea0d6bb9 PT |
24967 | /* APM X-Gene family. */ |
24968 | ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
24969 | "APM X-Gene 1"), | |
24970 | ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, | |
24971 | "APM X-Gene 2"), | |
da4339ed | 24972 | |
f3bad469 | 24973 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL } |
c19d1205 | 24974 | }; |
f3bad469 | 24975 | #undef ARM_CPU_OPT |
7ed4c4c5 | 24976 | |
c19d1205 | 24977 | struct arm_arch_option_table |
7ed4c4c5 | 24978 | { |
c19d1205 | 24979 | char *name; |
f3bad469 | 24980 | size_t name_len; |
e74cfd16 PB |
24981 | const arm_feature_set value; |
24982 | const arm_feature_set default_fpu; | |
c19d1205 | 24983 | }; |
7ed4c4c5 | 24984 | |
c19d1205 ZW |
24985 | /* This list should, at a minimum, contain all the architecture names |
24986 | recognized by GCC. */ | |
f3bad469 | 24987 | #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF } |
e74cfd16 | 24988 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 | 24989 | { |
f3bad469 MGD |
24990 | ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA), |
24991 | ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA), | |
24992 | ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA), | |
24993 | ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
24994 | ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA), | |
24995 | ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA), | |
24996 | ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA), | |
24997 | ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA), | |
24998 | ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA), | |
24999 | ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA), | |
25000 | ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA), | |
25001 | ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP), | |
25002 | ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP), | |
25003 | ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP), | |
25004 | ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP), | |
25005 | ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP), | |
25006 | ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP), | |
25007 | ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP), | |
25008 | ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP), | |
25009 | ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP), | |
25010 | ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP), | |
f33026a9 MW |
25011 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is |
25012 | kept to preserve existing behaviour. */ | |
25013 | ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP), | |
25014 | ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP), | |
f3bad469 MGD |
25015 | ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP), |
25016 | ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP), | |
25017 | ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP), | |
f33026a9 MW |
25018 | /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is |
25019 | kept to preserve existing behaviour. */ | |
25020 | ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP), | |
25021 | ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP), | |
f3bad469 MGD |
25022 | ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP), |
25023 | ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP), | |
25024 | ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP), | |
c450d570 PB |
25025 | /* The official spelling of the ARMv7 profile variants is the dashed form. |
25026 | Accept the non-dashed form for compatibility with old toolchains. */ | |
f3bad469 | 25027 | ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP), |
c9fb6e58 | 25028 | ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP), |
f3bad469 MGD |
25029 | ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP), |
25030 | ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP), | |
25031 | ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP), | |
25032 | ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP), | |
25033 | ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP), | |
25034 | ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP), | |
ff8646ee | 25035 | ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP), |
4ed7ed8d | 25036 | ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP), |
bca38921 | 25037 | ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP), |
a5932920 | 25038 | ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP), |
56a1b672 | 25039 | ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP), |
f3bad469 MGD |
25040 | ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP), |
25041 | ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP), | |
25042 | ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP), | |
25043 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE } | |
c19d1205 | 25044 | }; |
f3bad469 | 25045 | #undef ARM_ARCH_OPT |
7ed4c4c5 | 25046 | |
69133863 MGD |
25047 | /* ISA extensions in the co-processor and main instruction set space. */ |
25048 | struct arm_option_extension_value_table | |
c19d1205 ZW |
25049 | { |
25050 | char *name; | |
f3bad469 | 25051 | size_t name_len; |
5a70a223 JB |
25052 | const arm_feature_set merge_value; |
25053 | const arm_feature_set clear_value; | |
69133863 | 25054 | const arm_feature_set allowed_archs; |
c19d1205 | 25055 | }; |
7ed4c4c5 | 25056 | |
69133863 MGD |
25057 | /* The following table must be in alphabetical order with a NULL last entry. |
25058 | */ | |
5a70a223 | 25059 | #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA } |
69133863 | 25060 | static const struct arm_option_extension_value_table arm_extensions[] = |
c19d1205 | 25061 | { |
823d2571 TG |
25062 | ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8), |
25063 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
bca38921 | 25064 | ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8, |
823d2571 TG |
25065 | ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8), |
25066 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
25067 | ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8), | |
25068 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
25069 | ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), | |
25070 | ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV), | |
25071 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)), | |
25072 | ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), | |
25073 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY), | |
25074 | ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), | |
25075 | ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY), | |
25076 | ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), | |
25077 | ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY), | |
25078 | ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
25079 | ARM_FEATURE_CORE_LOW (ARM_EXT_MP), | |
25080 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)), | |
bca38921 | 25081 | ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8, |
823d2571 TG |
25082 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8), |
25083 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
25084 | ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS), | |
25085 | ARM_FEATURE_CORE_LOW (ARM_EXT_OS), | |
25086 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)), | |
ddfded2f MW |
25087 | ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN), |
25088 | ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0), | |
25089 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
25090 | ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), |
25091 | ARM_FEATURE_CORE_LOW (ARM_EXT_SEC), | |
25092 | ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)), | |
25093 | ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV | |
25094 | | ARM_EXT_DIV), | |
25095 | ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT), | |
25096 | ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)), | |
d6b4b13e MW |
25097 | ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8, |
25098 | ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA), | |
25099 | ARM_FEATURE_CORE_LOW (ARM_EXT_V8)), | |
823d2571 TG |
25100 | ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), |
25101 | ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY), | |
5a70a223 | 25102 | { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE } |
69133863 | 25103 | }; |
f3bad469 | 25104 | #undef ARM_EXT_OPT |
69133863 MGD |
25105 | |
25106 | /* ISA floating-point and Advanced SIMD extensions. */ | |
25107 | struct arm_option_fpu_value_table | |
25108 | { | |
25109 | char *name; | |
25110 | const arm_feature_set value; | |
c19d1205 | 25111 | }; |
7ed4c4c5 | 25112 | |
c19d1205 ZW |
25113 | /* This list should, at a minimum, contain all the fpu names |
25114 | recognized by GCC. */ | |
69133863 | 25115 | static const struct arm_option_fpu_value_table arm_fpus[] = |
c19d1205 ZW |
25116 | { |
25117 | {"softfpa", FPU_NONE}, | |
25118 | {"fpe", FPU_ARCH_FPE}, | |
25119 | {"fpe2", FPU_ARCH_FPE}, | |
25120 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
25121 | {"fpa", FPU_ARCH_FPA}, | |
25122 | {"fpa10", FPU_ARCH_FPA}, | |
25123 | {"fpa11", FPU_ARCH_FPA}, | |
25124 | {"arm7500fe", FPU_ARCH_FPA}, | |
25125 | {"softvfp", FPU_ARCH_VFP}, | |
25126 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
25127 | {"vfp", FPU_ARCH_VFP_V2}, | |
25128 | {"vfp9", FPU_ARCH_VFP_V2}, | |
b1cc4aeb | 25129 | {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */ |
c19d1205 ZW |
25130 | {"vfp10", FPU_ARCH_VFP_V2}, |
25131 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
25132 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
b1cc4aeb PB |
25133 | {"vfpv2", FPU_ARCH_VFP_V2}, |
25134 | {"vfpv3", FPU_ARCH_VFP_V3}, | |
62f3b8c8 | 25135 | {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, |
b1cc4aeb | 25136 | {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, |
62f3b8c8 PB |
25137 | {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, |
25138 | {"vfpv3xd", FPU_ARCH_VFP_V3xD}, | |
25139 | {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, | |
c19d1205 ZW |
25140 | {"arm1020t", FPU_ARCH_VFP_V1}, |
25141 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
25142 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
25143 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
25144 | {"maverick", FPU_ARCH_MAVERICK}, | |
5287ad62 | 25145 | {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, |
8e79c3df | 25146 | {"neon-fp16", FPU_ARCH_NEON_FP16}, |
62f3b8c8 PB |
25147 | {"vfpv4", FPU_ARCH_VFP_V4}, |
25148 | {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, | |
ada65aa3 | 25149 | {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, |
a715796b TG |
25150 | {"fpv5-d16", FPU_ARCH_VFP_V5D16}, |
25151 | {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16}, | |
62f3b8c8 | 25152 | {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, |
bca38921 MGD |
25153 | {"fp-armv8", FPU_ARCH_VFP_ARMV8}, |
25154 | {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8}, | |
25155 | {"crypto-neon-fp-armv8", | |
25156 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8}, | |
d6b4b13e | 25157 | {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1}, |
081e4c7d MW |
25158 | {"crypto-neon-fp-armv8.1", |
25159 | FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1}, | |
e74cfd16 PB |
25160 | {NULL, ARM_ARCH_NONE} |
25161 | }; | |
25162 | ||
25163 | struct arm_option_value_table | |
25164 | { | |
25165 | char *name; | |
25166 | long value; | |
c19d1205 | 25167 | }; |
7ed4c4c5 | 25168 | |
e74cfd16 | 25169 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
25170 | { |
25171 | {"hard", ARM_FLOAT_ABI_HARD}, | |
25172 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
25173 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 25174 | {NULL, 0} |
c19d1205 | 25175 | }; |
7ed4c4c5 | 25176 | |
c19d1205 | 25177 | #ifdef OBJ_ELF |
3a4a14e9 | 25178 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 25179 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
25180 | { |
25181 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
25182 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 25183 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 25184 | {NULL, 0} |
c19d1205 ZW |
25185 | }; |
25186 | #endif | |
7ed4c4c5 | 25187 | |
c19d1205 ZW |
25188 | struct arm_long_option_table |
25189 | { | |
25190 | char * option; /* Substring to match. */ | |
25191 | char * help; /* Help information. */ | |
25192 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
25193 | char * deprecated; /* If non-null, print this message. */ | |
25194 | }; | |
7ed4c4c5 | 25195 | |
c921be7d | 25196 | static bfd_boolean |
f3bad469 | 25197 | arm_parse_extension (char *str, const arm_feature_set **opt_p) |
7ed4c4c5 | 25198 | { |
21d799b5 NC |
25199 | arm_feature_set *ext_set = (arm_feature_set *) |
25200 | xmalloc (sizeof (arm_feature_set)); | |
e74cfd16 | 25201 | |
69133863 | 25202 | /* We insist on extensions being specified in alphabetical order, and with |
fa94de6b RM |
25203 | extensions being added before being removed. We achieve this by having |
25204 | the global ARM_EXTENSIONS table in alphabetical order, and using the | |
69133863 | 25205 | ADDING_VALUE variable to indicate whether we are adding an extension (1) |
fa94de6b | 25206 | or removing it (0) and only allowing it to change in the order |
69133863 MGD |
25207 | -1 -> 1 -> 0. */ |
25208 | const struct arm_option_extension_value_table * opt = NULL; | |
25209 | int adding_value = -1; | |
25210 | ||
e74cfd16 PB |
25211 | /* Copy the feature set, so that we can modify it. */ |
25212 | *ext_set = **opt_p; | |
25213 | *opt_p = ext_set; | |
25214 | ||
c19d1205 | 25215 | while (str != NULL && *str != 0) |
7ed4c4c5 | 25216 | { |
f3bad469 MGD |
25217 | char *ext; |
25218 | size_t len; | |
7ed4c4c5 | 25219 | |
c19d1205 ZW |
25220 | if (*str != '+') |
25221 | { | |
25222 | as_bad (_("invalid architectural extension")); | |
c921be7d | 25223 | return FALSE; |
c19d1205 | 25224 | } |
7ed4c4c5 | 25225 | |
c19d1205 ZW |
25226 | str++; |
25227 | ext = strchr (str, '+'); | |
7ed4c4c5 | 25228 | |
c19d1205 | 25229 | if (ext != NULL) |
f3bad469 | 25230 | len = ext - str; |
c19d1205 | 25231 | else |
f3bad469 | 25232 | len = strlen (str); |
7ed4c4c5 | 25233 | |
f3bad469 | 25234 | if (len >= 2 && strncmp (str, "no", 2) == 0) |
69133863 MGD |
25235 | { |
25236 | if (adding_value != 0) | |
25237 | { | |
25238 | adding_value = 0; | |
25239 | opt = arm_extensions; | |
25240 | } | |
25241 | ||
f3bad469 | 25242 | len -= 2; |
69133863 MGD |
25243 | str += 2; |
25244 | } | |
f3bad469 | 25245 | else if (len > 0) |
69133863 MGD |
25246 | { |
25247 | if (adding_value == -1) | |
25248 | { | |
25249 | adding_value = 1; | |
25250 | opt = arm_extensions; | |
25251 | } | |
25252 | else if (adding_value != 1) | |
25253 | { | |
25254 | as_bad (_("must specify extensions to add before specifying " | |
25255 | "those to remove")); | |
25256 | return FALSE; | |
25257 | } | |
25258 | } | |
25259 | ||
f3bad469 | 25260 | if (len == 0) |
c19d1205 ZW |
25261 | { |
25262 | as_bad (_("missing architectural extension")); | |
c921be7d | 25263 | return FALSE; |
c19d1205 | 25264 | } |
7ed4c4c5 | 25265 | |
69133863 MGD |
25266 | gas_assert (adding_value != -1); |
25267 | gas_assert (opt != NULL); | |
25268 | ||
25269 | /* Scan over the options table trying to find an exact match. */ | |
25270 | for (; opt->name != NULL; opt++) | |
f3bad469 | 25271 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 25272 | { |
69133863 MGD |
25273 | /* Check we can apply the extension to this architecture. */ |
25274 | if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs)) | |
25275 | { | |
25276 | as_bad (_("extension does not apply to the base architecture")); | |
25277 | return FALSE; | |
25278 | } | |
25279 | ||
25280 | /* Add or remove the extension. */ | |
25281 | if (adding_value) | |
5a70a223 | 25282 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value); |
69133863 | 25283 | else |
5a70a223 | 25284 | ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value); |
69133863 | 25285 | |
c19d1205 ZW |
25286 | break; |
25287 | } | |
7ed4c4c5 | 25288 | |
c19d1205 ZW |
25289 | if (opt->name == NULL) |
25290 | { | |
69133863 MGD |
25291 | /* Did we fail to find an extension because it wasn't specified in |
25292 | alphabetical order, or because it does not exist? */ | |
25293 | ||
25294 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
f3bad469 | 25295 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
69133863 MGD |
25296 | break; |
25297 | ||
25298 | if (opt->name == NULL) | |
25299 | as_bad (_("unknown architectural extension `%s'"), str); | |
25300 | else | |
25301 | as_bad (_("architectural extensions must be specified in " | |
25302 | "alphabetical order")); | |
25303 | ||
c921be7d | 25304 | return FALSE; |
c19d1205 | 25305 | } |
69133863 MGD |
25306 | else |
25307 | { | |
25308 | /* We should skip the extension we've just matched the next time | |
25309 | round. */ | |
25310 | opt++; | |
25311 | } | |
7ed4c4c5 | 25312 | |
c19d1205 ZW |
25313 | str = ext; |
25314 | }; | |
7ed4c4c5 | 25315 | |
c921be7d | 25316 | return TRUE; |
c19d1205 | 25317 | } |
7ed4c4c5 | 25318 | |
c921be7d | 25319 | static bfd_boolean |
f3bad469 | 25320 | arm_parse_cpu (char *str) |
7ed4c4c5 | 25321 | { |
f3bad469 MGD |
25322 | const struct arm_cpu_option_table *opt; |
25323 | char *ext = strchr (str, '+'); | |
25324 | size_t len; | |
7ed4c4c5 | 25325 | |
c19d1205 | 25326 | if (ext != NULL) |
f3bad469 | 25327 | len = ext - str; |
7ed4c4c5 | 25328 | else |
f3bad469 | 25329 | len = strlen (str); |
7ed4c4c5 | 25330 | |
f3bad469 | 25331 | if (len == 0) |
7ed4c4c5 | 25332 | { |
c19d1205 | 25333 | as_bad (_("missing cpu name `%s'"), str); |
c921be7d | 25334 | return FALSE; |
7ed4c4c5 NC |
25335 | } |
25336 | ||
c19d1205 | 25337 | for (opt = arm_cpus; opt->name != NULL; opt++) |
f3bad469 | 25338 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 25339 | { |
e74cfd16 PB |
25340 | mcpu_cpu_opt = &opt->value; |
25341 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 | 25342 | if (opt->canonical_name) |
ef8e6722 JW |
25343 | { |
25344 | gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name)); | |
25345 | strcpy (selected_cpu_name, opt->canonical_name); | |
25346 | } | |
ee065d83 PB |
25347 | else |
25348 | { | |
f3bad469 | 25349 | size_t i; |
c921be7d | 25350 | |
ef8e6722 JW |
25351 | if (len >= sizeof selected_cpu_name) |
25352 | len = (sizeof selected_cpu_name) - 1; | |
25353 | ||
f3bad469 | 25354 | for (i = 0; i < len; i++) |
ee065d83 PB |
25355 | selected_cpu_name[i] = TOUPPER (opt->name[i]); |
25356 | selected_cpu_name[i] = 0; | |
25357 | } | |
7ed4c4c5 | 25358 | |
c19d1205 ZW |
25359 | if (ext != NULL) |
25360 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 25361 | |
c921be7d | 25362 | return TRUE; |
c19d1205 | 25363 | } |
7ed4c4c5 | 25364 | |
c19d1205 | 25365 | as_bad (_("unknown cpu `%s'"), str); |
c921be7d | 25366 | return FALSE; |
7ed4c4c5 NC |
25367 | } |
25368 | ||
c921be7d | 25369 | static bfd_boolean |
f3bad469 | 25370 | arm_parse_arch (char *str) |
7ed4c4c5 | 25371 | { |
e74cfd16 | 25372 | const struct arm_arch_option_table *opt; |
c19d1205 | 25373 | char *ext = strchr (str, '+'); |
f3bad469 | 25374 | size_t len; |
7ed4c4c5 | 25375 | |
c19d1205 | 25376 | if (ext != NULL) |
f3bad469 | 25377 | len = ext - str; |
7ed4c4c5 | 25378 | else |
f3bad469 | 25379 | len = strlen (str); |
7ed4c4c5 | 25380 | |
f3bad469 | 25381 | if (len == 0) |
7ed4c4c5 | 25382 | { |
c19d1205 | 25383 | as_bad (_("missing architecture name `%s'"), str); |
c921be7d | 25384 | return FALSE; |
7ed4c4c5 NC |
25385 | } |
25386 | ||
c19d1205 | 25387 | for (opt = arm_archs; opt->name != NULL; opt++) |
f3bad469 | 25388 | if (opt->name_len == len && strncmp (opt->name, str, len) == 0) |
c19d1205 | 25389 | { |
e74cfd16 PB |
25390 | march_cpu_opt = &opt->value; |
25391 | march_fpu_opt = &opt->default_fpu; | |
5f4273c7 | 25392 | strcpy (selected_cpu_name, opt->name); |
7ed4c4c5 | 25393 | |
c19d1205 ZW |
25394 | if (ext != NULL) |
25395 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 25396 | |
c921be7d | 25397 | return TRUE; |
c19d1205 ZW |
25398 | } |
25399 | ||
25400 | as_bad (_("unknown architecture `%s'\n"), str); | |
c921be7d | 25401 | return FALSE; |
7ed4c4c5 | 25402 | } |
eb043451 | 25403 | |
c921be7d | 25404 | static bfd_boolean |
c19d1205 ZW |
25405 | arm_parse_fpu (char * str) |
25406 | { | |
69133863 | 25407 | const struct arm_option_fpu_value_table * opt; |
b99bd4ef | 25408 | |
c19d1205 ZW |
25409 | for (opt = arm_fpus; opt->name != NULL; opt++) |
25410 | if (streq (opt->name, str)) | |
25411 | { | |
e74cfd16 | 25412 | mfpu_opt = &opt->value; |
c921be7d | 25413 | return TRUE; |
c19d1205 | 25414 | } |
b99bd4ef | 25415 | |
c19d1205 | 25416 | as_bad (_("unknown floating point format `%s'\n"), str); |
c921be7d | 25417 | return FALSE; |
c19d1205 ZW |
25418 | } |
25419 | ||
c921be7d | 25420 | static bfd_boolean |
c19d1205 | 25421 | arm_parse_float_abi (char * str) |
b99bd4ef | 25422 | { |
e74cfd16 | 25423 | const struct arm_option_value_table * opt; |
b99bd4ef | 25424 | |
c19d1205 ZW |
25425 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
25426 | if (streq (opt->name, str)) | |
25427 | { | |
25428 | mfloat_abi_opt = opt->value; | |
c921be7d | 25429 | return TRUE; |
c19d1205 | 25430 | } |
cc8a6dd0 | 25431 | |
c19d1205 | 25432 | as_bad (_("unknown floating point abi `%s'\n"), str); |
c921be7d | 25433 | return FALSE; |
c19d1205 | 25434 | } |
b99bd4ef | 25435 | |
c19d1205 | 25436 | #ifdef OBJ_ELF |
c921be7d | 25437 | static bfd_boolean |
c19d1205 ZW |
25438 | arm_parse_eabi (char * str) |
25439 | { | |
e74cfd16 | 25440 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 25441 | |
c19d1205 ZW |
25442 | for (opt = arm_eabis; opt->name != NULL; opt++) |
25443 | if (streq (opt->name, str)) | |
25444 | { | |
25445 | meabi_flags = opt->value; | |
c921be7d | 25446 | return TRUE; |
c19d1205 ZW |
25447 | } |
25448 | as_bad (_("unknown EABI `%s'\n"), str); | |
c921be7d | 25449 | return FALSE; |
c19d1205 ZW |
25450 | } |
25451 | #endif | |
cc8a6dd0 | 25452 | |
c921be7d | 25453 | static bfd_boolean |
e07e6e58 NC |
25454 | arm_parse_it_mode (char * str) |
25455 | { | |
c921be7d | 25456 | bfd_boolean ret = TRUE; |
e07e6e58 NC |
25457 | |
25458 | if (streq ("arm", str)) | |
25459 | implicit_it_mode = IMPLICIT_IT_MODE_ARM; | |
25460 | else if (streq ("thumb", str)) | |
25461 | implicit_it_mode = IMPLICIT_IT_MODE_THUMB; | |
25462 | else if (streq ("always", str)) | |
25463 | implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS; | |
25464 | else if (streq ("never", str)) | |
25465 | implicit_it_mode = IMPLICIT_IT_MODE_NEVER; | |
25466 | else | |
25467 | { | |
25468 | as_bad (_("unknown implicit IT mode `%s', should be "\ | |
477330fc | 25469 | "arm, thumb, always, or never."), str); |
c921be7d | 25470 | ret = FALSE; |
e07e6e58 NC |
25471 | } |
25472 | ||
25473 | return ret; | |
25474 | } | |
25475 | ||
2e6976a8 DG |
25476 | static bfd_boolean |
25477 | arm_ccs_mode (char * unused ATTRIBUTE_UNUSED) | |
25478 | { | |
25479 | codecomposer_syntax = TRUE; | |
25480 | arm_comment_chars[0] = ';'; | |
25481 | arm_line_separator_chars[0] = 0; | |
25482 | return TRUE; | |
25483 | } | |
25484 | ||
c19d1205 ZW |
25485 | struct arm_long_option_table arm_long_opts[] = |
25486 | { | |
25487 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
25488 | arm_parse_cpu, NULL}, | |
25489 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
25490 | arm_parse_arch, NULL}, | |
25491 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
25492 | arm_parse_fpu, NULL}, | |
25493 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
25494 | arm_parse_float_abi, NULL}, | |
25495 | #ifdef OBJ_ELF | |
7fac0536 | 25496 | {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"), |
c19d1205 ZW |
25497 | arm_parse_eabi, NULL}, |
25498 | #endif | |
e07e6e58 NC |
25499 | {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"), |
25500 | arm_parse_it_mode, NULL}, | |
2e6976a8 DG |
25501 | {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"), |
25502 | arm_ccs_mode, NULL}, | |
c19d1205 ZW |
25503 | {NULL, NULL, 0, NULL} |
25504 | }; | |
cc8a6dd0 | 25505 | |
c19d1205 ZW |
25506 | int |
25507 | md_parse_option (int c, char * arg) | |
25508 | { | |
25509 | struct arm_option_table *opt; | |
e74cfd16 | 25510 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 25511 | struct arm_long_option_table *lopt; |
b99bd4ef | 25512 | |
c19d1205 | 25513 | switch (c) |
b99bd4ef | 25514 | { |
c19d1205 ZW |
25515 | #ifdef OPTION_EB |
25516 | case OPTION_EB: | |
25517 | target_big_endian = 1; | |
25518 | break; | |
25519 | #endif | |
cc8a6dd0 | 25520 | |
c19d1205 ZW |
25521 | #ifdef OPTION_EL |
25522 | case OPTION_EL: | |
25523 | target_big_endian = 0; | |
25524 | break; | |
25525 | #endif | |
b99bd4ef | 25526 | |
845b51d6 PB |
25527 | case OPTION_FIX_V4BX: |
25528 | fix_v4bx = TRUE; | |
25529 | break; | |
25530 | ||
c19d1205 ZW |
25531 | case 'a': |
25532 | /* Listing option. Just ignore these, we don't support additional | |
25533 | ones. */ | |
25534 | return 0; | |
b99bd4ef | 25535 | |
c19d1205 ZW |
25536 | default: |
25537 | for (opt = arm_opts; opt->option != NULL; opt++) | |
25538 | { | |
25539 | if (c == opt->option[0] | |
25540 | && ((arg == NULL && opt->option[1] == 0) | |
25541 | || streq (arg, opt->option + 1))) | |
25542 | { | |
c19d1205 | 25543 | /* If the option is deprecated, tell the user. */ |
278df34e | 25544 | if (warn_on_deprecated && opt->deprecated != NULL) |
c19d1205 ZW |
25545 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
25546 | arg ? arg : "", _(opt->deprecated)); | |
b99bd4ef | 25547 | |
c19d1205 ZW |
25548 | if (opt->var != NULL) |
25549 | *opt->var = opt->value; | |
cc8a6dd0 | 25550 | |
c19d1205 ZW |
25551 | return 1; |
25552 | } | |
25553 | } | |
b99bd4ef | 25554 | |
e74cfd16 PB |
25555 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
25556 | { | |
25557 | if (c == fopt->option[0] | |
25558 | && ((arg == NULL && fopt->option[1] == 0) | |
25559 | || streq (arg, fopt->option + 1))) | |
25560 | { | |
e74cfd16 | 25561 | /* If the option is deprecated, tell the user. */ |
278df34e | 25562 | if (warn_on_deprecated && fopt->deprecated != NULL) |
e74cfd16 PB |
25563 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, |
25564 | arg ? arg : "", _(fopt->deprecated)); | |
e74cfd16 PB |
25565 | |
25566 | if (fopt->var != NULL) | |
25567 | *fopt->var = &fopt->value; | |
25568 | ||
25569 | return 1; | |
25570 | } | |
25571 | } | |
25572 | ||
c19d1205 ZW |
25573 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
25574 | { | |
25575 | /* These options are expected to have an argument. */ | |
25576 | if (c == lopt->option[0] | |
25577 | && arg != NULL | |
25578 | && strncmp (arg, lopt->option + 1, | |
25579 | strlen (lopt->option + 1)) == 0) | |
25580 | { | |
c19d1205 | 25581 | /* If the option is deprecated, tell the user. */ |
278df34e | 25582 | if (warn_on_deprecated && lopt->deprecated != NULL) |
c19d1205 ZW |
25583 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, |
25584 | _(lopt->deprecated)); | |
b99bd4ef | 25585 | |
c19d1205 ZW |
25586 | /* Call the sup-option parser. */ |
25587 | return lopt->func (arg + strlen (lopt->option) - 1); | |
25588 | } | |
25589 | } | |
a737bd4d | 25590 | |
c19d1205 ZW |
25591 | return 0; |
25592 | } | |
a394c00f | 25593 | |
c19d1205 ZW |
25594 | return 1; |
25595 | } | |
a394c00f | 25596 | |
c19d1205 ZW |
25597 | void |
25598 | md_show_usage (FILE * fp) | |
a394c00f | 25599 | { |
c19d1205 ZW |
25600 | struct arm_option_table *opt; |
25601 | struct arm_long_option_table *lopt; | |
a394c00f | 25602 | |
c19d1205 | 25603 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 25604 | |
c19d1205 ZW |
25605 | for (opt = arm_opts; opt->option != NULL; opt++) |
25606 | if (opt->help != NULL) | |
25607 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 25608 | |
c19d1205 ZW |
25609 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
25610 | if (lopt->help != NULL) | |
25611 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 25612 | |
c19d1205 ZW |
25613 | #ifdef OPTION_EB |
25614 | fprintf (fp, _("\ | |
25615 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
25616 | #endif |
25617 | ||
c19d1205 ZW |
25618 | #ifdef OPTION_EL |
25619 | fprintf (fp, _("\ | |
25620 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 25621 | #endif |
845b51d6 PB |
25622 | |
25623 | fprintf (fp, _("\ | |
25624 | --fix-v4bx Allow BX in ARMv4 code\n")); | |
c19d1205 | 25625 | } |
ee065d83 PB |
25626 | |
25627 | ||
25628 | #ifdef OBJ_ELF | |
62b3e311 PB |
25629 | typedef struct |
25630 | { | |
25631 | int val; | |
25632 | arm_feature_set flags; | |
25633 | } cpu_arch_ver_table; | |
25634 | ||
4ed7ed8d TP |
25635 | /* Mapping from CPU features to EABI CPU arch values. As a general rule, table |
25636 | must be sorted least features first but some reordering is needed, eg. for | |
25637 | Thumb-2 instructions to be detected as coming from ARMv6T2. */ | |
62b3e311 PB |
25638 | static const cpu_arch_ver_table cpu_arch_ver[] = |
25639 | { | |
25640 | {1, ARM_ARCH_V4}, | |
25641 | {2, ARM_ARCH_V4T}, | |
25642 | {3, ARM_ARCH_V5}, | |
ee3c0378 | 25643 | {3, ARM_ARCH_V5T}, |
62b3e311 PB |
25644 | {4, ARM_ARCH_V5TE}, |
25645 | {5, ARM_ARCH_V5TEJ}, | |
25646 | {6, ARM_ARCH_V6}, | |
7e806470 | 25647 | {9, ARM_ARCH_V6K}, |
f4c65163 | 25648 | {7, ARM_ARCH_V6Z}, |
91e22acd | 25649 | {11, ARM_ARCH_V6M}, |
b2a5fbdc | 25650 | {12, ARM_ARCH_V6SM}, |
7e806470 | 25651 | {8, ARM_ARCH_V6T2}, |
c9fb6e58 | 25652 | {10, ARM_ARCH_V7VE}, |
62b3e311 PB |
25653 | {10, ARM_ARCH_V7R}, |
25654 | {10, ARM_ARCH_V7M}, | |
bca38921 | 25655 | {14, ARM_ARCH_V8A}, |
ff8646ee | 25656 | {16, ARM_ARCH_V8M_BASE}, |
4ed7ed8d | 25657 | {17, ARM_ARCH_V8M_MAIN}, |
62b3e311 PB |
25658 | {0, ARM_ARCH_NONE} |
25659 | }; | |
25660 | ||
ee3c0378 AS |
25661 | /* Set an attribute if it has not already been set by the user. */ |
25662 | static void | |
25663 | aeabi_set_attribute_int (int tag, int value) | |
25664 | { | |
25665 | if (tag < 1 | |
25666 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
25667 | || !attributes_set_explicitly[tag]) | |
25668 | bfd_elf_add_proc_attr_int (stdoutput, tag, value); | |
25669 | } | |
25670 | ||
25671 | static void | |
25672 | aeabi_set_attribute_string (int tag, const char *value) | |
25673 | { | |
25674 | if (tag < 1 | |
25675 | || tag >= NUM_KNOWN_OBJ_ATTRIBUTES | |
25676 | || !attributes_set_explicitly[tag]) | |
25677 | bfd_elf_add_proc_attr_string (stdoutput, tag, value); | |
25678 | } | |
25679 | ||
ee065d83 | 25680 | /* Set the public EABI object attributes. */ |
3cfdb781 | 25681 | void |
ee065d83 PB |
25682 | aeabi_set_public_attributes (void) |
25683 | { | |
25684 | int arch; | |
69239280 | 25685 | char profile; |
90ec0d68 | 25686 | int virt_sec = 0; |
bca38921 | 25687 | int fp16_optional = 0; |
e74cfd16 | 25688 | arm_feature_set flags; |
62b3e311 | 25689 | arm_feature_set tmp; |
ff8646ee | 25690 | arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE; |
62b3e311 | 25691 | const cpu_arch_ver_table *p; |
ee065d83 PB |
25692 | |
25693 | /* Choose the architecture based on the capabilities of the requested cpu | |
25694 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
25695 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
25696 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
25697 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
ddd7f988 RE |
25698 | |
25699 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)) | |
25700 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1); | |
25701 | ||
25702 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any)) | |
25703 | ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t); | |
25704 | ||
7f78eb34 JW |
25705 | selected_cpu = flags; |
25706 | ||
ddd7f988 | 25707 | /* Allow the user to override the reported architecture. */ |
7a1d4c38 PB |
25708 | if (object_arch) |
25709 | { | |
25710 | ARM_CLEAR_FEATURE (flags, flags, arm_arch_any); | |
25711 | ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch); | |
25712 | } | |
25713 | ||
251665fc MGD |
25714 | /* We need to make sure that the attributes do not identify us as v6S-M |
25715 | when the only v6S-M feature in use is the Operating System Extensions. */ | |
25716 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os)) | |
25717 | if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only)) | |
477330fc | 25718 | ARM_CLEAR_FEATURE (flags, flags, arm_ext_os); |
251665fc | 25719 | |
62b3e311 PB |
25720 | tmp = flags; |
25721 | arch = 0; | |
25722 | for (p = cpu_arch_ver; p->val; p++) | |
25723 | { | |
25724 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
25725 | { | |
25726 | arch = p->val; | |
25727 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
25728 | } | |
25729 | } | |
ee065d83 | 25730 | |
9e3c6df6 PB |
25731 | /* The table lookup above finds the last architecture to contribute |
25732 | a new feature. Unfortunately, Tag13 is a subset of the union of | |
25733 | v6T2 and v7-M, so it is never seen as contributing a new feature. | |
25734 | We can not search for the last entry which is entirely used, | |
25735 | because if no CPU is specified we build up only those flags | |
25736 | actually used. Perhaps we should separate out the specified | |
25737 | and implicit cases. Avoid taking this path for -march=all by | |
25738 | checking for contradictory v7-A / v7-M features. */ | |
4ed7ed8d | 25739 | if (arch == TAG_CPU_ARCH_V7 |
9e3c6df6 PB |
25740 | && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a) |
25741 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m) | |
25742 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp)) | |
4ed7ed8d TP |
25743 | arch = TAG_CPU_ARCH_V7E_M; |
25744 | ||
ff8646ee TP |
25745 | ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base); |
25746 | if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any)) | |
25747 | arch = TAG_CPU_ARCH_V8M_MAIN; | |
25748 | ||
4ed7ed8d TP |
25749 | /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as |
25750 | coming from ARMv8-A. However, since ARMv8-A has more instructions than | |
25751 | ARMv8-M, -march=all must be detected as ARMv8-A. */ | |
25752 | if (arch == TAG_CPU_ARCH_V8M_MAIN | |
25753 | && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any)) | |
25754 | arch = TAG_CPU_ARCH_V8; | |
9e3c6df6 | 25755 | |
ee065d83 PB |
25756 | /* Tag_CPU_name. */ |
25757 | if (selected_cpu_name[0]) | |
25758 | { | |
91d6fa6a | 25759 | char *q; |
ee065d83 | 25760 | |
91d6fa6a NC |
25761 | q = selected_cpu_name; |
25762 | if (strncmp (q, "armv", 4) == 0) | |
ee065d83 PB |
25763 | { |
25764 | int i; | |
5f4273c7 | 25765 | |
91d6fa6a NC |
25766 | q += 4; |
25767 | for (i = 0; q[i]; i++) | |
25768 | q[i] = TOUPPER (q[i]); | |
ee065d83 | 25769 | } |
91d6fa6a | 25770 | aeabi_set_attribute_string (Tag_CPU_name, q); |
ee065d83 | 25771 | } |
62f3b8c8 | 25772 | |
ee065d83 | 25773 | /* Tag_CPU_arch. */ |
ee3c0378 | 25774 | aeabi_set_attribute_int (Tag_CPU_arch, arch); |
62f3b8c8 | 25775 | |
62b3e311 | 25776 | /* Tag_CPU_arch_profile. */ |
10c9892b | 25777 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a) |
4ed7ed8d TP |
25778 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
25779 | || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics) | |
25780 | && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))) | |
69239280 | 25781 | profile = 'A'; |
62b3e311 | 25782 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) |
69239280 | 25783 | profile = 'R'; |
7e806470 | 25784 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m)) |
69239280 MGD |
25785 | profile = 'M'; |
25786 | else | |
25787 | profile = '\0'; | |
25788 | ||
25789 | if (profile != '\0') | |
25790 | aeabi_set_attribute_int (Tag_CPU_arch_profile, profile); | |
62f3b8c8 | 25791 | |
ee065d83 | 25792 | /* Tag_ARM_ISA_use. */ |
ee3c0378 AS |
25793 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1) |
25794 | || arch == 0) | |
25795 | aeabi_set_attribute_int (Tag_ARM_ISA_use, 1); | |
62f3b8c8 | 25796 | |
ee065d83 | 25797 | /* Tag_THUMB_ISA_use. */ |
ee3c0378 AS |
25798 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t) |
25799 | || arch == 0) | |
4ed7ed8d TP |
25800 | { |
25801 | int thumb_isa_use; | |
25802 | ||
25803 | if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) | |
25804 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
25805 | thumb_isa_use = 3; | |
25806 | else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2)) | |
25807 | thumb_isa_use = 2; | |
25808 | else | |
25809 | thumb_isa_use = 1; | |
25810 | aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use); | |
25811 | } | |
62f3b8c8 | 25812 | |
ee065d83 | 25813 | /* Tag_VFP_arch. */ |
a715796b TG |
25814 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd)) |
25815 | aeabi_set_attribute_int (Tag_VFP_arch, | |
25816 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
25817 | ? 7 : 8); | |
bca38921 | 25818 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma)) |
62f3b8c8 PB |
25819 | aeabi_set_attribute_int (Tag_VFP_arch, |
25820 | ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32) | |
25821 | ? 5 : 6); | |
25822 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)) | |
bca38921 MGD |
25823 | { |
25824 | fp16_optional = 1; | |
25825 | aeabi_set_attribute_int (Tag_VFP_arch, 3); | |
25826 | } | |
ada65aa3 | 25827 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd)) |
bca38921 MGD |
25828 | { |
25829 | aeabi_set_attribute_int (Tag_VFP_arch, 4); | |
25830 | fp16_optional = 1; | |
25831 | } | |
ee3c0378 AS |
25832 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2)) |
25833 | aeabi_set_attribute_int (Tag_VFP_arch, 2); | |
25834 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1) | |
477330fc | 25835 | || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)) |
ee3c0378 | 25836 | aeabi_set_attribute_int (Tag_VFP_arch, 1); |
62f3b8c8 | 25837 | |
4547cb56 NC |
25838 | /* Tag_ABI_HardFP_use. */ |
25839 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd) | |
25840 | && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)) | |
25841 | aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1); | |
25842 | ||
ee065d83 | 25843 | /* Tag_WMMX_arch. */ |
ee3c0378 AS |
25844 | if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2)) |
25845 | aeabi_set_attribute_int (Tag_WMMX_arch, 2); | |
25846 | else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt)) | |
25847 | aeabi_set_attribute_int (Tag_WMMX_arch, 1); | |
62f3b8c8 | 25848 | |
ee3c0378 | 25849 | /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */ |
bca38921 MGD |
25850 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8)) |
25851 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3); | |
25852 | else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1)) | |
25853 | { | |
25854 | if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)) | |
25855 | { | |
25856 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2); | |
25857 | } | |
25858 | else | |
25859 | { | |
25860 | aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1); | |
25861 | fp16_optional = 1; | |
25862 | } | |
25863 | } | |
fa94de6b | 25864 | |
ee3c0378 | 25865 | /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */ |
bca38921 | 25866 | if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional) |
ee3c0378 | 25867 | aeabi_set_attribute_int (Tag_VFP_HP_extension, 1); |
4547cb56 | 25868 | |
69239280 MGD |
25869 | /* Tag_DIV_use. |
25870 | ||
25871 | We set Tag_DIV_use to two when integer divide instructions have been used | |
25872 | in ARM state, or when Thumb integer divide instructions have been used, | |
25873 | but we have no architecture profile set, nor have we any ARM instructions. | |
25874 | ||
4ed7ed8d TP |
25875 | For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied |
25876 | by the base architecture. | |
bca38921 | 25877 | |
69239280 | 25878 | For new architectures we will have to check these tests. */ |
ff8646ee TP |
25879 | gas_assert (arch <= TAG_CPU_ARCH_V8 |
25880 | || (arch >= TAG_CPU_ARCH_V8M_BASE | |
25881 | && arch <= TAG_CPU_ARCH_V8M_MAIN)); | |
4ed7ed8d TP |
25882 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8) |
25883 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m)) | |
bca38921 MGD |
25884 | aeabi_set_attribute_int (Tag_DIV_use, 0); |
25885 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv) | |
25886 | || (profile == '\0' | |
25887 | && ARM_CPU_HAS_FEATURE (flags, arm_ext_div) | |
25888 | && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))) | |
eea54501 | 25889 | aeabi_set_attribute_int (Tag_DIV_use, 2); |
60e5ef9f MGD |
25890 | |
25891 | /* Tag_MP_extension_use. */ | |
25892 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp)) | |
25893 | aeabi_set_attribute_int (Tag_MPextension_use, 1); | |
f4c65163 MGD |
25894 | |
25895 | /* Tag Virtualization_use. */ | |
25896 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec)) | |
90ec0d68 MGD |
25897 | virt_sec |= 1; |
25898 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt)) | |
25899 | virt_sec |= 2; | |
25900 | if (virt_sec != 0) | |
25901 | aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec); | |
ee065d83 PB |
25902 | } |
25903 | ||
104d59d1 | 25904 | /* Add the default contents for the .ARM.attributes section. */ |
ee065d83 PB |
25905 | void |
25906 | arm_md_end (void) | |
25907 | { | |
ee065d83 PB |
25908 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) |
25909 | return; | |
25910 | ||
25911 | aeabi_set_public_attributes (); | |
ee065d83 | 25912 | } |
8463be01 | 25913 | #endif /* OBJ_ELF */ |
ee065d83 PB |
25914 | |
25915 | ||
25916 | /* Parse a .cpu directive. */ | |
25917 | ||
25918 | static void | |
25919 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
25920 | { | |
e74cfd16 | 25921 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
25922 | char *name; |
25923 | char saved_char; | |
25924 | ||
25925 | name = input_line_pointer; | |
5f4273c7 | 25926 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
25927 | input_line_pointer++; |
25928 | saved_char = *input_line_pointer; | |
25929 | *input_line_pointer = 0; | |
25930 | ||
25931 | /* Skip the first "all" entry. */ | |
25932 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
25933 | if (streq (opt->name, name)) | |
25934 | { | |
e74cfd16 PB |
25935 | mcpu_cpu_opt = &opt->value; |
25936 | selected_cpu = opt->value; | |
ee065d83 | 25937 | if (opt->canonical_name) |
5f4273c7 | 25938 | strcpy (selected_cpu_name, opt->canonical_name); |
ee065d83 PB |
25939 | else |
25940 | { | |
25941 | int i; | |
25942 | for (i = 0; opt->name[i]; i++) | |
25943 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
f3bad469 | 25944 | |
ee065d83 PB |
25945 | selected_cpu_name[i] = 0; |
25946 | } | |
e74cfd16 | 25947 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
25948 | *input_line_pointer = saved_char; |
25949 | demand_empty_rest_of_line (); | |
25950 | return; | |
25951 | } | |
25952 | as_bad (_("unknown cpu `%s'"), name); | |
25953 | *input_line_pointer = saved_char; | |
25954 | ignore_rest_of_line (); | |
25955 | } | |
25956 | ||
25957 | ||
25958 | /* Parse a .arch directive. */ | |
25959 | ||
25960 | static void | |
25961 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
25962 | { | |
e74cfd16 | 25963 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
25964 | char saved_char; |
25965 | char *name; | |
25966 | ||
25967 | name = input_line_pointer; | |
5f4273c7 | 25968 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
25969 | input_line_pointer++; |
25970 | saved_char = *input_line_pointer; | |
25971 | *input_line_pointer = 0; | |
25972 | ||
25973 | /* Skip the first "all" entry. */ | |
25974 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
25975 | if (streq (opt->name, name)) | |
25976 | { | |
e74cfd16 PB |
25977 | mcpu_cpu_opt = &opt->value; |
25978 | selected_cpu = opt->value; | |
5f4273c7 | 25979 | strcpy (selected_cpu_name, opt->name); |
e74cfd16 | 25980 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
25981 | *input_line_pointer = saved_char; |
25982 | demand_empty_rest_of_line (); | |
25983 | return; | |
25984 | } | |
25985 | ||
25986 | as_bad (_("unknown architecture `%s'\n"), name); | |
25987 | *input_line_pointer = saved_char; | |
25988 | ignore_rest_of_line (); | |
25989 | } | |
25990 | ||
25991 | ||
7a1d4c38 PB |
25992 | /* Parse a .object_arch directive. */ |
25993 | ||
25994 | static void | |
25995 | s_arm_object_arch (int ignored ATTRIBUTE_UNUSED) | |
25996 | { | |
25997 | const struct arm_arch_option_table *opt; | |
25998 | char saved_char; | |
25999 | char *name; | |
26000 | ||
26001 | name = input_line_pointer; | |
5f4273c7 | 26002 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
7a1d4c38 PB |
26003 | input_line_pointer++; |
26004 | saved_char = *input_line_pointer; | |
26005 | *input_line_pointer = 0; | |
26006 | ||
26007 | /* Skip the first "all" entry. */ | |
26008 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
26009 | if (streq (opt->name, name)) | |
26010 | { | |
26011 | object_arch = &opt->value; | |
26012 | *input_line_pointer = saved_char; | |
26013 | demand_empty_rest_of_line (); | |
26014 | return; | |
26015 | } | |
26016 | ||
26017 | as_bad (_("unknown architecture `%s'\n"), name); | |
26018 | *input_line_pointer = saved_char; | |
26019 | ignore_rest_of_line (); | |
26020 | } | |
26021 | ||
69133863 MGD |
26022 | /* Parse a .arch_extension directive. */ |
26023 | ||
26024 | static void | |
26025 | s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED) | |
26026 | { | |
26027 | const struct arm_option_extension_value_table *opt; | |
26028 | char saved_char; | |
26029 | char *name; | |
26030 | int adding_value = 1; | |
26031 | ||
26032 | name = input_line_pointer; | |
26033 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) | |
26034 | input_line_pointer++; | |
26035 | saved_char = *input_line_pointer; | |
26036 | *input_line_pointer = 0; | |
26037 | ||
26038 | if (strlen (name) >= 2 | |
26039 | && strncmp (name, "no", 2) == 0) | |
26040 | { | |
26041 | adding_value = 0; | |
26042 | name += 2; | |
26043 | } | |
26044 | ||
26045 | for (opt = arm_extensions; opt->name != NULL; opt++) | |
26046 | if (streq (opt->name, name)) | |
26047 | { | |
26048 | if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs)) | |
26049 | { | |
26050 | as_bad (_("architectural extension `%s' is not allowed for the " | |
26051 | "current base architecture"), name); | |
26052 | break; | |
26053 | } | |
26054 | ||
26055 | if (adding_value) | |
5a70a223 JB |
26056 | ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, |
26057 | opt->merge_value); | |
69133863 | 26058 | else |
5a70a223 | 26059 | ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value); |
69133863 MGD |
26060 | |
26061 | mcpu_cpu_opt = &selected_cpu; | |
26062 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
26063 | *input_line_pointer = saved_char; | |
26064 | demand_empty_rest_of_line (); | |
26065 | return; | |
26066 | } | |
26067 | ||
26068 | if (opt->name == NULL) | |
e673710a | 26069 | as_bad (_("unknown architecture extension `%s'\n"), name); |
69133863 MGD |
26070 | |
26071 | *input_line_pointer = saved_char; | |
26072 | ignore_rest_of_line (); | |
26073 | } | |
26074 | ||
ee065d83 PB |
26075 | /* Parse a .fpu directive. */ |
26076 | ||
26077 | static void | |
26078 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
26079 | { | |
69133863 | 26080 | const struct arm_option_fpu_value_table *opt; |
ee065d83 PB |
26081 | char saved_char; |
26082 | char *name; | |
26083 | ||
26084 | name = input_line_pointer; | |
5f4273c7 | 26085 | while (*input_line_pointer && !ISSPACE (*input_line_pointer)) |
ee065d83 PB |
26086 | input_line_pointer++; |
26087 | saved_char = *input_line_pointer; | |
26088 | *input_line_pointer = 0; | |
5f4273c7 | 26089 | |
ee065d83 PB |
26090 | for (opt = arm_fpus; opt->name != NULL; opt++) |
26091 | if (streq (opt->name, name)) | |
26092 | { | |
e74cfd16 PB |
26093 | mfpu_opt = &opt->value; |
26094 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
26095 | *input_line_pointer = saved_char; |
26096 | demand_empty_rest_of_line (); | |
26097 | return; | |
26098 | } | |
26099 | ||
26100 | as_bad (_("unknown floating point format `%s'\n"), name); | |
26101 | *input_line_pointer = saved_char; | |
26102 | ignore_rest_of_line (); | |
26103 | } | |
ee065d83 | 26104 | |
794ba86a | 26105 | /* Copy symbol information. */ |
f31fef98 | 26106 | |
794ba86a DJ |
26107 | void |
26108 | arm_copy_symbol_attributes (symbolS *dest, symbolS *src) | |
26109 | { | |
26110 | ARM_GET_FLAG (dest) = ARM_GET_FLAG (src); | |
26111 | } | |
e04befd0 | 26112 | |
f31fef98 | 26113 | #ifdef OBJ_ELF |
e04befd0 AS |
26114 | /* Given a symbolic attribute NAME, return the proper integer value. |
26115 | Returns -1 if the attribute is not known. */ | |
f31fef98 | 26116 | |
e04befd0 AS |
26117 | int |
26118 | arm_convert_symbolic_attribute (const char *name) | |
26119 | { | |
f31fef98 NC |
26120 | static const struct |
26121 | { | |
26122 | const char * name; | |
26123 | const int tag; | |
26124 | } | |
26125 | attribute_table[] = | |
26126 | { | |
26127 | /* When you modify this table you should | |
26128 | also modify the list in doc/c-arm.texi. */ | |
e04befd0 | 26129 | #define T(tag) {#tag, tag} |
f31fef98 NC |
26130 | T (Tag_CPU_raw_name), |
26131 | T (Tag_CPU_name), | |
26132 | T (Tag_CPU_arch), | |
26133 | T (Tag_CPU_arch_profile), | |
26134 | T (Tag_ARM_ISA_use), | |
26135 | T (Tag_THUMB_ISA_use), | |
75375b3e | 26136 | T (Tag_FP_arch), |
f31fef98 NC |
26137 | T (Tag_VFP_arch), |
26138 | T (Tag_WMMX_arch), | |
26139 | T (Tag_Advanced_SIMD_arch), | |
26140 | T (Tag_PCS_config), | |
26141 | T (Tag_ABI_PCS_R9_use), | |
26142 | T (Tag_ABI_PCS_RW_data), | |
26143 | T (Tag_ABI_PCS_RO_data), | |
26144 | T (Tag_ABI_PCS_GOT_use), | |
26145 | T (Tag_ABI_PCS_wchar_t), | |
26146 | T (Tag_ABI_FP_rounding), | |
26147 | T (Tag_ABI_FP_denormal), | |
26148 | T (Tag_ABI_FP_exceptions), | |
26149 | T (Tag_ABI_FP_user_exceptions), | |
26150 | T (Tag_ABI_FP_number_model), | |
75375b3e | 26151 | T (Tag_ABI_align_needed), |
f31fef98 | 26152 | T (Tag_ABI_align8_needed), |
75375b3e | 26153 | T (Tag_ABI_align_preserved), |
f31fef98 NC |
26154 | T (Tag_ABI_align8_preserved), |
26155 | T (Tag_ABI_enum_size), | |
26156 | T (Tag_ABI_HardFP_use), | |
26157 | T (Tag_ABI_VFP_args), | |
26158 | T (Tag_ABI_WMMX_args), | |
26159 | T (Tag_ABI_optimization_goals), | |
26160 | T (Tag_ABI_FP_optimization_goals), | |
26161 | T (Tag_compatibility), | |
26162 | T (Tag_CPU_unaligned_access), | |
75375b3e | 26163 | T (Tag_FP_HP_extension), |
f31fef98 NC |
26164 | T (Tag_VFP_HP_extension), |
26165 | T (Tag_ABI_FP_16bit_format), | |
cd21e546 MGD |
26166 | T (Tag_MPextension_use), |
26167 | T (Tag_DIV_use), | |
f31fef98 NC |
26168 | T (Tag_nodefaults), |
26169 | T (Tag_also_compatible_with), | |
26170 | T (Tag_conformance), | |
26171 | T (Tag_T2EE_use), | |
26172 | T (Tag_Virtualization_use), | |
cd21e546 | 26173 | /* We deliberately do not include Tag_MPextension_use_legacy. */ |
e04befd0 | 26174 | #undef T |
f31fef98 | 26175 | }; |
e04befd0 AS |
26176 | unsigned int i; |
26177 | ||
26178 | if (name == NULL) | |
26179 | return -1; | |
26180 | ||
f31fef98 | 26181 | for (i = 0; i < ARRAY_SIZE (attribute_table); i++) |
c921be7d | 26182 | if (streq (name, attribute_table[i].name)) |
e04befd0 AS |
26183 | return attribute_table[i].tag; |
26184 | ||
26185 | return -1; | |
26186 | } | |
267bf995 RR |
26187 | |
26188 | ||
93ef582d NC |
26189 | /* Apply sym value for relocations only in the case that they are for |
26190 | local symbols in the same segment as the fixup and you have the | |
26191 | respective architectural feature for blx and simple switches. */ | |
267bf995 | 26192 | int |
93ef582d | 26193 | arm_apply_sym_value (struct fix * fixP, segT this_seg) |
267bf995 RR |
26194 | { |
26195 | if (fixP->fx_addsy | |
26196 | && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t) | |
93ef582d NC |
26197 | /* PR 17444: If the local symbol is in a different section then a reloc |
26198 | will always be generated for it, so applying the symbol value now | |
26199 | will result in a double offset being stored in the relocation. */ | |
26200 | && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg) | |
34e77a92 | 26201 | && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)) |
267bf995 RR |
26202 | { |
26203 | switch (fixP->fx_r_type) | |
26204 | { | |
26205 | case BFD_RELOC_ARM_PCREL_BLX: | |
26206 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
26207 | if (ARM_IS_FUNC (fixP->fx_addsy)) | |
26208 | return 1; | |
26209 | break; | |
26210 | ||
26211 | case BFD_RELOC_ARM_PCREL_CALL: | |
26212 | case BFD_RELOC_THUMB_PCREL_BLX: | |
26213 | if (THUMB_IS_FUNC (fixP->fx_addsy)) | |
93ef582d | 26214 | return 1; |
267bf995 RR |
26215 | break; |
26216 | ||
26217 | default: | |
26218 | break; | |
26219 | } | |
26220 | ||
26221 | } | |
26222 | return 0; | |
26223 | } | |
f31fef98 | 26224 | #endif /* OBJ_ELF */ |