Commit | Line | Data |
---|---|---|
b99bd4ef | 1 | /* tc-arm.c -- Assemble for the ARM |
f17c130b AM |
2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
3 | 2004, 2005 | |
b99bd4ef NC |
4 | Free Software Foundation, Inc. |
5 | Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org) | |
6 | Modified by David Taylor (dtaylor@armltd.co.uk) | |
22d9c8c5 | 7 | Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com) |
34920d91 NC |
8 | Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com) |
9 | Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com) | |
b99bd4ef NC |
10 | |
11 | This file is part of GAS, the GNU Assembler. | |
12 | ||
13 | GAS is free software; you can redistribute it and/or modify | |
14 | it under the terms of the GNU General Public License as published by | |
15 | the Free Software Foundation; either version 2, or (at your option) | |
16 | any later version. | |
17 | ||
18 | GAS is distributed in the hope that it will be useful, | |
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c19d1205 | 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b99bd4ef NC |
21 | GNU General Public License for more details. |
22 | ||
23 | You should have received a copy of the GNU General Public License | |
24 | along with GAS; see the file COPYING. If not, write to the Free | |
699d2810 NC |
25 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
26 | 02110-1301, USA. */ | |
b99bd4ef | 27 | |
b99bd4ef | 28 | #include <string.h> |
c19d1205 | 29 | #define NO_RELOC 0 |
b99bd4ef | 30 | #include "as.h" |
3882b010 | 31 | #include "safe-ctype.h" |
b99bd4ef NC |
32 | |
33 | /* Need TARGET_CPU. */ | |
34 | #include "config.h" | |
35 | #include "subsegs.h" | |
36 | #include "obstack.h" | |
37 | #include "symbols.h" | |
38 | #include "listing.h" | |
39 | ||
f263249b RE |
40 | #include "opcode/arm.h" |
41 | ||
b99bd4ef NC |
42 | #ifdef OBJ_ELF |
43 | #include "elf/arm.h" | |
44 | #include "dwarf2dbg.h" | |
a394c00f | 45 | #include "dw2gencfi.h" |
b99bd4ef NC |
46 | #endif |
47 | ||
7ed4c4c5 | 48 | /* XXX Set this to 1 after the next binutils release. */ |
03b1477f RE |
49 | #define WARN_DEPRECATED 0 |
50 | ||
7ed4c4c5 NC |
51 | #ifdef OBJ_ELF |
52 | /* Must be at least the size of the largest unwind opcode (currently two). */ | |
53 | #define ARM_OPCODE_CHUNK_SIZE 8 | |
54 | ||
55 | /* This structure holds the unwinding state. */ | |
56 | ||
57 | static struct | |
58 | { | |
c19d1205 ZW |
59 | symbolS * proc_start; |
60 | symbolS * table_entry; | |
61 | symbolS * personality_routine; | |
62 | int personality_index; | |
7ed4c4c5 | 63 | /* The segment containing the function. */ |
c19d1205 ZW |
64 | segT saved_seg; |
65 | subsegT saved_subseg; | |
7ed4c4c5 NC |
66 | /* Opcodes generated from this function. */ |
67 | unsigned char * opcodes; | |
c19d1205 ZW |
68 | int opcode_count; |
69 | int opcode_alloc; | |
7ed4c4c5 | 70 | /* The number of bytes pushed to the stack. */ |
c19d1205 | 71 | offsetT frame_size; |
7ed4c4c5 NC |
72 | /* We don't add stack adjustment opcodes immediately so that we can merge |
73 | multiple adjustments. We can also omit the final adjustment | |
74 | when using a frame pointer. */ | |
c19d1205 | 75 | offsetT pending_offset; |
7ed4c4c5 | 76 | /* These two fields are set by both unwind_movsp and unwind_setfp. They |
c19d1205 ZW |
77 | hold the reg+offset to use when restoring sp from a frame pointer. */ |
78 | offsetT fp_offset; | |
79 | int fp_reg; | |
7ed4c4c5 | 80 | /* Nonzero if an unwind_setfp directive has been seen. */ |
c19d1205 | 81 | unsigned fp_used:1; |
7ed4c4c5 | 82 | /* Nonzero if the last opcode restores sp from fp_reg. */ |
c19d1205 | 83 | unsigned sp_restored:1; |
7ed4c4c5 NC |
84 | } unwind; |
85 | ||
84798bd6 JB |
86 | /* Bit N indicates that an R_ARM_NONE relocation has been output for |
87 | __aeabi_unwind_cpp_prN already if set. This enables dependencies to be | |
88 | emitted only once per section, to save unnecessary bloat. */ | |
89 | static unsigned int marked_pr_dependency = 0; | |
90 | ||
7ed4c4c5 NC |
91 | #endif /* OBJ_ELF */ |
92 | ||
33a392fb PB |
93 | enum arm_float_abi |
94 | { | |
95 | ARM_FLOAT_ABI_HARD, | |
96 | ARM_FLOAT_ABI_SOFTFP, | |
97 | ARM_FLOAT_ABI_SOFT | |
98 | }; | |
99 | ||
c19d1205 | 100 | /* Types of processor to assemble for. */ |
b99bd4ef NC |
101 | #ifndef CPU_DEFAULT |
102 | #if defined __XSCALE__ | |
e74cfd16 | 103 | #define CPU_DEFAULT ARM_ARCH_XSCALE |
b99bd4ef NC |
104 | #else |
105 | #if defined __thumb__ | |
e74cfd16 | 106 | #define CPU_DEFAULT ARM_ARCH_V5T |
b99bd4ef NC |
107 | #endif |
108 | #endif | |
109 | #endif | |
110 | ||
111 | #ifndef FPU_DEFAULT | |
c820d418 MM |
112 | # ifdef TE_LINUX |
113 | # define FPU_DEFAULT FPU_ARCH_FPA | |
114 | # elif defined (TE_NetBSD) | |
115 | # ifdef OBJ_ELF | |
116 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */ | |
117 | # else | |
118 | /* Legacy a.out format. */ | |
119 | # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */ | |
120 | # endif | |
4e7fd91e PB |
121 | # elif defined (TE_VXWORKS) |
122 | # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */ | |
c820d418 MM |
123 | # else |
124 | /* For backwards compatibility, default to FPA. */ | |
125 | # define FPU_DEFAULT FPU_ARCH_FPA | |
126 | # endif | |
127 | #endif /* ifndef FPU_DEFAULT */ | |
b99bd4ef | 128 | |
c19d1205 | 129 | #define streq(a, b) (strcmp (a, b) == 0) |
b99bd4ef | 130 | |
e74cfd16 PB |
131 | static arm_feature_set cpu_variant; |
132 | static arm_feature_set arm_arch_used; | |
133 | static arm_feature_set thumb_arch_used; | |
b99bd4ef | 134 | |
b99bd4ef | 135 | /* Flags stored in private area of BFD structure. */ |
c19d1205 ZW |
136 | static int uses_apcs_26 = FALSE; |
137 | static int atpcs = FALSE; | |
b34976b6 AM |
138 | static int support_interwork = FALSE; |
139 | static int uses_apcs_float = FALSE; | |
c19d1205 | 140 | static int pic_code = FALSE; |
03b1477f RE |
141 | |
142 | /* Variables that we set while parsing command-line options. Once all | |
143 | options have been read we re-process these values to set the real | |
144 | assembly flags. */ | |
e74cfd16 PB |
145 | static const arm_feature_set *legacy_cpu = NULL; |
146 | static const arm_feature_set *legacy_fpu = NULL; | |
147 | ||
148 | static const arm_feature_set *mcpu_cpu_opt = NULL; | |
149 | static const arm_feature_set *mcpu_fpu_opt = NULL; | |
150 | static const arm_feature_set *march_cpu_opt = NULL; | |
151 | static const arm_feature_set *march_fpu_opt = NULL; | |
152 | static const arm_feature_set *mfpu_opt = NULL; | |
153 | ||
154 | /* Constants for known architecture features. */ | |
155 | static const arm_feature_set fpu_default = FPU_DEFAULT; | |
156 | static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1; | |
157 | static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2; | |
158 | static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA; | |
159 | static const arm_feature_set fpu_any_hard = FPU_ANY_HARD; | |
160 | static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK; | |
161 | static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE; | |
162 | ||
163 | #ifdef CPU_DEFAULT | |
164 | static const arm_feature_set cpu_default = CPU_DEFAULT; | |
165 | #endif | |
166 | ||
167 | static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0); | |
168 | static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0); | |
169 | static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0); | |
170 | static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0); | |
171 | static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0); | |
172 | static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0); | |
173 | static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0); | |
174 | static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0); | |
175 | static const arm_feature_set arm_ext_v4t_5 = | |
176 | ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0); | |
177 | static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0); | |
178 | static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0); | |
179 | static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0); | |
180 | static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0); | |
181 | static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0); | |
182 | static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0); | |
183 | static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0); | |
184 | static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0); | |
62b3e311 PB |
185 | static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0); |
186 | static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0); | |
187 | static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0); | |
188 | static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0); | |
189 | static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0); | |
190 | static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0); | |
e74cfd16 PB |
191 | |
192 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
193 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
194 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
195 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
196 | ||
197 | static const arm_feature_set arm_cext_iwmmxt = | |
198 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
199 | static const arm_feature_set arm_cext_xscale = | |
200 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
201 | static const arm_feature_set arm_cext_maverick = | |
202 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
203 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
204 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
205 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
206 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
207 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
208 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
209 | ||
33a392fb | 210 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
211 | /* Record user cpu selection for object attributes. */ |
212 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
213 | /* Must be long enough to hold any of the names in arm_cpus. */ |
214 | static char selected_cpu_name[16]; | |
7cc69913 | 215 | #ifdef OBJ_ELF |
deeaaff8 DJ |
216 | # ifdef EABI_DEFAULT |
217 | static int meabi_flags = EABI_DEFAULT; | |
218 | # else | |
d507cf36 | 219 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 220 | # endif |
7cc69913 | 221 | #endif |
b99bd4ef | 222 | |
b99bd4ef | 223 | #ifdef OBJ_ELF |
c19d1205 | 224 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
225 | symbolS * GOT_symbol; |
226 | #endif | |
227 | ||
b99bd4ef NC |
228 | /* 0: assemble for ARM, |
229 | 1: assemble for Thumb, | |
230 | 2: assemble for Thumb even though target CPU does not support thumb | |
231 | instructions. */ | |
232 | static int thumb_mode = 0; | |
233 | ||
c19d1205 ZW |
234 | /* If unified_syntax is true, we are processing the new unified |
235 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
236 | ||
237 | - Immediate operands do not require a # prefix. | |
238 | - Conditional affixes always appear at the end of the | |
239 | instruction. (For backward compatibility, those instructions | |
240 | that formerly had them in the middle, continue to accept them | |
241 | there.) | |
242 | - The IT instruction may appear, and if it does is validated | |
243 | against subsequent conditional affixes. It does not generate | |
244 | machine code. | |
245 | ||
246 | Important differences from the old Thumb mode: | |
247 | ||
248 | - Immediate operands do not require a # prefix. | |
249 | - Most of the V6T2 instructions are only available in unified mode. | |
250 | - The .N and .W suffixes are recognized and honored (it is an error | |
251 | if they cannot be honored). | |
252 | - All instructions set the flags if and only if they have an 's' affix. | |
253 | - Conditional affixes may be used. They are validated against | |
254 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
255 | conditional affix except in the scope of an IT instruction. */ | |
256 | ||
257 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef NC |
258 | |
259 | struct arm_it | |
260 | { | |
c19d1205 | 261 | const char * error; |
b99bd4ef | 262 | unsigned long instruction; |
c19d1205 ZW |
263 | int size; |
264 | int size_req; | |
265 | int cond; | |
0110f2b8 PB |
266 | /* Set to the opcode if the instruction needs relaxation. |
267 | Zero if the instruction is not relaxed. */ | |
268 | unsigned long relax; | |
b99bd4ef NC |
269 | struct |
270 | { | |
271 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
272 | expressionS exp; |
273 | int pc_rel; | |
b99bd4ef | 274 | } reloc; |
b99bd4ef | 275 | |
c19d1205 ZW |
276 | struct |
277 | { | |
278 | unsigned reg; | |
ca3f61f7 NC |
279 | signed int imm; |
280 | unsigned present : 1; /* Operand present. */ | |
281 | unsigned isreg : 1; /* Operand was a register. */ | |
282 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
283 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ | |
284 | unsigned writeback : 1; /* Operand has trailing ! */ | |
285 | unsigned preind : 1; /* Preindexed address. */ | |
286 | unsigned postind : 1; /* Postindexed address. */ | |
287 | unsigned negative : 1; /* Index register was negated. */ | |
288 | unsigned shifted : 1; /* Shift applied to operation. */ | |
289 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 290 | } operands[6]; |
b99bd4ef NC |
291 | }; |
292 | ||
c19d1205 | 293 | static struct arm_it inst; |
b99bd4ef NC |
294 | |
295 | #define NUM_FLOAT_VALS 8 | |
296 | ||
05d2d07e | 297 | const char * fp_const[] = |
b99bd4ef NC |
298 | { |
299 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
300 | }; | |
301 | ||
c19d1205 | 302 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
303 | #define MAX_LITTLENUMS 6 |
304 | ||
305 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
306 | ||
307 | #define FAIL (-1) | |
308 | #define SUCCESS (0) | |
309 | ||
310 | #define SUFF_S 1 | |
311 | #define SUFF_D 2 | |
312 | #define SUFF_E 3 | |
313 | #define SUFF_P 4 | |
314 | ||
c19d1205 ZW |
315 | #define CP_T_X 0x00008000 |
316 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 317 | |
c19d1205 ZW |
318 | #define CONDS_BIT 0x00100000 |
319 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
320 | |
321 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
322 | ||
323 | struct asm_cond | |
324 | { | |
c19d1205 | 325 | const char * template; |
b99bd4ef NC |
326 | unsigned long value; |
327 | }; | |
328 | ||
c19d1205 | 329 | #define COND_ALWAYS 0xE |
b99bd4ef | 330 | |
b99bd4ef NC |
331 | struct asm_psr |
332 | { | |
b34976b6 | 333 | const char *template; |
b99bd4ef NC |
334 | unsigned long field; |
335 | }; | |
336 | ||
62b3e311 PB |
337 | struct asm_barrier_opt |
338 | { | |
339 | const char *template; | |
340 | unsigned long value; | |
341 | }; | |
342 | ||
2d2255b5 | 343 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
344 | #define SPSR_BIT (1 << 22) |
345 | ||
c19d1205 ZW |
346 | /* The individual PSR flag bits. */ |
347 | #define PSR_c (1 << 16) | |
348 | #define PSR_x (1 << 17) | |
349 | #define PSR_s (1 << 18) | |
350 | #define PSR_f (1 << 19) | |
b99bd4ef | 351 | |
c19d1205 | 352 | struct reloc_entry |
bfae80f2 | 353 | { |
c19d1205 ZW |
354 | char *name; |
355 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
356 | }; |
357 | ||
358 | enum vfp_sp_reg_pos | |
359 | { | |
360 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn | |
361 | }; | |
362 | ||
363 | enum vfp_ldstm_type | |
364 | { | |
365 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
366 | }; | |
367 | ||
c19d1205 ZW |
368 | /* ARM register categories. This includes coprocessor numbers and various |
369 | architecture extensions' registers. */ | |
370 | enum arm_reg_type | |
bfae80f2 | 371 | { |
c19d1205 ZW |
372 | REG_TYPE_RN, |
373 | REG_TYPE_CP, | |
374 | REG_TYPE_CN, | |
375 | REG_TYPE_FN, | |
376 | REG_TYPE_VFS, | |
377 | REG_TYPE_VFD, | |
378 | REG_TYPE_VFC, | |
379 | REG_TYPE_MVF, | |
380 | REG_TYPE_MVD, | |
381 | REG_TYPE_MVFX, | |
382 | REG_TYPE_MVDX, | |
383 | REG_TYPE_MVAX, | |
384 | REG_TYPE_DSPSC, | |
385 | REG_TYPE_MMXWR, | |
386 | REG_TYPE_MMXWC, | |
387 | REG_TYPE_MMXWCG, | |
388 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
389 | }; |
390 | ||
6c43fab6 RE |
391 | /* Structure for a hash table entry for a register. */ |
392 | struct reg_entry | |
393 | { | |
c19d1205 ZW |
394 | const char *name; |
395 | unsigned char number; | |
396 | unsigned char type; | |
397 | unsigned char builtin; | |
6c43fab6 RE |
398 | }; |
399 | ||
c19d1205 ZW |
400 | /* Diagnostics used when we don't get a register of the expected type. */ |
401 | const char *const reg_expected_msgs[] = | |
402 | { | |
403 | N_("ARM register expected"), | |
404 | N_("bad or missing co-processor number"), | |
405 | N_("co-processor register expected"), | |
406 | N_("FPA register expected"), | |
407 | N_("VFP single precision register expected"), | |
408 | N_("VFP double precision register expected"), | |
409 | N_("VFP system register expected"), | |
410 | N_("Maverick MVF register expected"), | |
411 | N_("Maverick MVD register expected"), | |
412 | N_("Maverick MVFX register expected"), | |
413 | N_("Maverick MVDX register expected"), | |
414 | N_("Maverick MVAX register expected"), | |
415 | N_("Maverick DSPSC register expected"), | |
416 | N_("iWMMXt data register expected"), | |
417 | N_("iWMMXt control register expected"), | |
418 | N_("iWMMXt scalar register expected"), | |
419 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
420 | }; |
421 | ||
c19d1205 ZW |
422 | /* Some well known registers that we refer to directly elsewhere. */ |
423 | #define REG_SP 13 | |
424 | #define REG_LR 14 | |
425 | #define REG_PC 15 | |
404ff6b5 | 426 | |
b99bd4ef NC |
427 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
428 | take 2: */ | |
c19d1205 | 429 | #define INSN_SIZE 4 |
b99bd4ef NC |
430 | |
431 | struct asm_opcode | |
432 | { | |
433 | /* Basic string to match. */ | |
c19d1205 ZW |
434 | const char *template; |
435 | ||
436 | /* Parameters to instruction. */ | |
437 | unsigned char operands[8]; | |
438 | ||
439 | /* Conditional tag - see opcode_lookup. */ | |
440 | unsigned int tag : 4; | |
b99bd4ef NC |
441 | |
442 | /* Basic instruction code. */ | |
c19d1205 | 443 | unsigned int avalue : 28; |
b99bd4ef | 444 | |
c19d1205 ZW |
445 | /* Thumb-format instruction code. */ |
446 | unsigned int tvalue; | |
b99bd4ef | 447 | |
90e4755a | 448 | /* Which architecture variant provides this instruction. */ |
e74cfd16 PB |
449 | const arm_feature_set *avariant; |
450 | const arm_feature_set *tvariant; | |
c19d1205 ZW |
451 | |
452 | /* Function to call to encode instruction in ARM format. */ | |
453 | void (* aencode) (void); | |
b99bd4ef | 454 | |
c19d1205 ZW |
455 | /* Function to call to encode instruction in Thumb format. */ |
456 | void (* tencode) (void); | |
b99bd4ef NC |
457 | }; |
458 | ||
a737bd4d NC |
459 | /* Defines for various bits that we will want to toggle. */ |
460 | #define INST_IMMEDIATE 0x02000000 | |
461 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 462 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
463 | #define SHIFT_BY_REG 0x00000010 |
464 | #define PRE_INDEX 0x01000000 | |
465 | #define INDEX_UP 0x00800000 | |
466 | #define WRITE_BACK 0x00200000 | |
467 | #define LDM_TYPE_2_OR_3 0x00400000 | |
90e4755a | 468 | |
a737bd4d NC |
469 | #define LITERAL_MASK 0xf000f000 |
470 | #define OPCODE_MASK 0xfe1fffff | |
471 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 472 | |
a737bd4d | 473 | #define DATA_OP_SHIFT 21 |
90e4755a | 474 | |
ef8d22e6 PB |
475 | #define T2_OPCODE_MASK 0xfe1fffff |
476 | #define T2_DATA_OP_SHIFT 21 | |
477 | ||
a737bd4d NC |
478 | /* Codes to distinguish the arithmetic instructions. */ |
479 | #define OPCODE_AND 0 | |
480 | #define OPCODE_EOR 1 | |
481 | #define OPCODE_SUB 2 | |
482 | #define OPCODE_RSB 3 | |
483 | #define OPCODE_ADD 4 | |
484 | #define OPCODE_ADC 5 | |
485 | #define OPCODE_SBC 6 | |
486 | #define OPCODE_RSC 7 | |
487 | #define OPCODE_TST 8 | |
488 | #define OPCODE_TEQ 9 | |
489 | #define OPCODE_CMP 10 | |
490 | #define OPCODE_CMN 11 | |
491 | #define OPCODE_ORR 12 | |
492 | #define OPCODE_MOV 13 | |
493 | #define OPCODE_BIC 14 | |
494 | #define OPCODE_MVN 15 | |
90e4755a | 495 | |
ef8d22e6 PB |
496 | #define T2_OPCODE_AND 0 |
497 | #define T2_OPCODE_BIC 1 | |
498 | #define T2_OPCODE_ORR 2 | |
499 | #define T2_OPCODE_ORN 3 | |
500 | #define T2_OPCODE_EOR 4 | |
501 | #define T2_OPCODE_ADD 8 | |
502 | #define T2_OPCODE_ADC 10 | |
503 | #define T2_OPCODE_SBC 11 | |
504 | #define T2_OPCODE_SUB 13 | |
505 | #define T2_OPCODE_RSB 14 | |
506 | ||
a737bd4d NC |
507 | #define T_OPCODE_MUL 0x4340 |
508 | #define T_OPCODE_TST 0x4200 | |
509 | #define T_OPCODE_CMN 0x42c0 | |
510 | #define T_OPCODE_NEG 0x4240 | |
511 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 512 | |
a737bd4d NC |
513 | #define T_OPCODE_ADD_R3 0x1800 |
514 | #define T_OPCODE_SUB_R3 0x1a00 | |
515 | #define T_OPCODE_ADD_HI 0x4400 | |
516 | #define T_OPCODE_ADD_ST 0xb000 | |
517 | #define T_OPCODE_SUB_ST 0xb080 | |
518 | #define T_OPCODE_ADD_SP 0xa800 | |
519 | #define T_OPCODE_ADD_PC 0xa000 | |
520 | #define T_OPCODE_ADD_I8 0x3000 | |
521 | #define T_OPCODE_SUB_I8 0x3800 | |
522 | #define T_OPCODE_ADD_I3 0x1c00 | |
523 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 524 | |
a737bd4d NC |
525 | #define T_OPCODE_ASR_R 0x4100 |
526 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
527 | #define T_OPCODE_LSR_R 0x40c0 |
528 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
529 | #define T_OPCODE_ASR_I 0x1000 |
530 | #define T_OPCODE_LSL_I 0x0000 | |
531 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 532 | |
a737bd4d NC |
533 | #define T_OPCODE_MOV_I8 0x2000 |
534 | #define T_OPCODE_CMP_I8 0x2800 | |
535 | #define T_OPCODE_CMP_LR 0x4280 | |
536 | #define T_OPCODE_MOV_HR 0x4600 | |
537 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 538 | |
a737bd4d NC |
539 | #define T_OPCODE_LDR_PC 0x4800 |
540 | #define T_OPCODE_LDR_SP 0x9800 | |
541 | #define T_OPCODE_STR_SP 0x9000 | |
542 | #define T_OPCODE_LDR_IW 0x6800 | |
543 | #define T_OPCODE_STR_IW 0x6000 | |
544 | #define T_OPCODE_LDR_IH 0x8800 | |
545 | #define T_OPCODE_STR_IH 0x8000 | |
546 | #define T_OPCODE_LDR_IB 0x7800 | |
547 | #define T_OPCODE_STR_IB 0x7000 | |
548 | #define T_OPCODE_LDR_RW 0x5800 | |
549 | #define T_OPCODE_STR_RW 0x5000 | |
550 | #define T_OPCODE_LDR_RH 0x5a00 | |
551 | #define T_OPCODE_STR_RH 0x5200 | |
552 | #define T_OPCODE_LDR_RB 0x5c00 | |
553 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 554 | |
a737bd4d NC |
555 | #define T_OPCODE_PUSH 0xb400 |
556 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 557 | |
2fc8bdac | 558 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 559 | |
a737bd4d | 560 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 561 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 | 562 | #define THUMB_LOAD_BIT 0x0800 |
53365c0d | 563 | #define THUMB2_LOAD_BIT 0x00100000 |
c19d1205 ZW |
564 | |
565 | #define BAD_ARGS _("bad arguments to instruction") | |
566 | #define BAD_PC _("r15 not allowed here") | |
567 | #define BAD_COND _("instruction cannot be conditional") | |
568 | #define BAD_OVERLAP _("registers may not be the same") | |
569 | #define BAD_HIREG _("lo register required") | |
570 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 571 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
dfa9f0d5 PB |
572 | #define BAD_BRANCH _("branch must be last instruction in IT block") |
573 | #define BAD_NOT_IT _("instruction not allowed in IT block") | |
c19d1205 ZW |
574 | |
575 | static struct hash_control *arm_ops_hsh; | |
576 | static struct hash_control *arm_cond_hsh; | |
577 | static struct hash_control *arm_shift_hsh; | |
578 | static struct hash_control *arm_psr_hsh; | |
62b3e311 | 579 | static struct hash_control *arm_v7m_psr_hsh; |
c19d1205 ZW |
580 | static struct hash_control *arm_reg_hsh; |
581 | static struct hash_control *arm_reloc_hsh; | |
62b3e311 | 582 | static struct hash_control *arm_barrier_opt_hsh; |
b99bd4ef | 583 | |
b99bd4ef NC |
584 | /* Stuff needed to resolve the label ambiguity |
585 | As: | |
586 | ... | |
587 | label: <insn> | |
588 | may differ from: | |
589 | ... | |
590 | label: | |
c19d1205 | 591 | <insn> |
b99bd4ef NC |
592 | */ |
593 | ||
594 | symbolS * last_label_seen; | |
b34976b6 | 595 | static int label_is_thumb_function_name = FALSE; |
a737bd4d | 596 | \f |
3d0c9500 NC |
597 | /* Literal pool structure. Held on a per-section |
598 | and per-sub-section basis. */ | |
a737bd4d | 599 | |
c19d1205 | 600 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 601 | typedef struct literal_pool |
b99bd4ef | 602 | { |
c19d1205 ZW |
603 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
604 | unsigned int next_free_entry; | |
605 | unsigned int id; | |
606 | symbolS * symbol; | |
607 | segT section; | |
608 | subsegT sub_section; | |
61b5f74b | 609 | struct literal_pool * next; |
3d0c9500 | 610 | } literal_pool; |
b99bd4ef | 611 | |
3d0c9500 NC |
612 | /* Pointer to a linked list of literal pools. */ |
613 | literal_pool * list_of_pools = NULL; | |
e27ec89e PB |
614 | |
615 | /* State variables for IT block handling. */ | |
616 | static bfd_boolean current_it_mask = 0; | |
617 | static int current_cc; | |
618 | ||
c19d1205 ZW |
619 | \f |
620 | /* Pure syntax. */ | |
b99bd4ef | 621 | |
c19d1205 ZW |
622 | /* This array holds the chars that always start a comment. If the |
623 | pre-processor is disabled, these aren't very useful. */ | |
624 | const char comment_chars[] = "@"; | |
3d0c9500 | 625 | |
c19d1205 ZW |
626 | /* This array holds the chars that only start a comment at the beginning of |
627 | a line. If the line seems to have the form '# 123 filename' | |
628 | .line and .file directives will appear in the pre-processed output. */ | |
629 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
630 | first line of the input file. This is because the compiler outputs | |
631 | #NO_APP at the beginning of its output. */ | |
632 | /* Also note that comments like this one will always work. */ | |
633 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 634 | |
c19d1205 | 635 | const char line_separator_chars[] = ";"; |
b99bd4ef | 636 | |
c19d1205 ZW |
637 | /* Chars that can be used to separate mant |
638 | from exp in floating point numbers. */ | |
639 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 640 | |
c19d1205 ZW |
641 | /* Chars that mean this number is a floating point constant. */ |
642 | /* As in 0f12.456 */ | |
643 | /* or 0d1.2345e12 */ | |
b99bd4ef | 644 | |
c19d1205 | 645 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 646 | |
c19d1205 ZW |
647 | /* Prefix characters that indicate the start of an immediate |
648 | value. */ | |
649 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 650 | |
c19d1205 ZW |
651 | /* Separator character handling. */ |
652 | ||
653 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
654 | ||
655 | static inline int | |
656 | skip_past_char (char ** str, char c) | |
657 | { | |
658 | if (**str == c) | |
659 | { | |
660 | (*str)++; | |
661 | return SUCCESS; | |
3d0c9500 | 662 | } |
c19d1205 ZW |
663 | else |
664 | return FAIL; | |
665 | } | |
666 | #define skip_past_comma(str) skip_past_char (str, ',') | |
3d0c9500 | 667 | |
c19d1205 ZW |
668 | /* Arithmetic expressions (possibly involving symbols). */ |
669 | ||
670 | /* Return TRUE if anything in the expression is a bignum. */ | |
671 | ||
672 | static int | |
673 | walk_no_bignums (symbolS * sp) | |
674 | { | |
675 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
676 | return 1; | |
677 | ||
678 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 679 | { |
c19d1205 ZW |
680 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
681 | || (symbol_get_value_expression (sp)->X_op_symbol | |
682 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
683 | } |
684 | ||
c19d1205 | 685 | return 0; |
3d0c9500 NC |
686 | } |
687 | ||
c19d1205 ZW |
688 | static int in_my_get_expression = 0; |
689 | ||
690 | /* Third argument to my_get_expression. */ | |
691 | #define GE_NO_PREFIX 0 | |
692 | #define GE_IMM_PREFIX 1 | |
693 | #define GE_OPT_PREFIX 2 | |
a737bd4d | 694 | |
b99bd4ef | 695 | static int |
c19d1205 | 696 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 697 | { |
c19d1205 ZW |
698 | char * save_in; |
699 | segT seg; | |
b99bd4ef | 700 | |
c19d1205 ZW |
701 | /* In unified syntax, all prefixes are optional. */ |
702 | if (unified_syntax) | |
703 | prefix_mode = GE_OPT_PREFIX; | |
b99bd4ef | 704 | |
c19d1205 | 705 | switch (prefix_mode) |
b99bd4ef | 706 | { |
c19d1205 ZW |
707 | case GE_NO_PREFIX: break; |
708 | case GE_IMM_PREFIX: | |
709 | if (!is_immediate_prefix (**str)) | |
710 | { | |
711 | inst.error = _("immediate expression requires a # prefix"); | |
712 | return FAIL; | |
713 | } | |
714 | (*str)++; | |
715 | break; | |
716 | case GE_OPT_PREFIX: | |
717 | if (is_immediate_prefix (**str)) | |
718 | (*str)++; | |
719 | break; | |
720 | default: abort (); | |
721 | } | |
b99bd4ef | 722 | |
c19d1205 | 723 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 724 | |
c19d1205 ZW |
725 | save_in = input_line_pointer; |
726 | input_line_pointer = *str; | |
727 | in_my_get_expression = 1; | |
728 | seg = expression (ep); | |
729 | in_my_get_expression = 0; | |
730 | ||
731 | if (ep->X_op == O_illegal) | |
b99bd4ef | 732 | { |
c19d1205 ZW |
733 | /* We found a bad expression in md_operand(). */ |
734 | *str = input_line_pointer; | |
735 | input_line_pointer = save_in; | |
736 | if (inst.error == NULL) | |
737 | inst.error = _("bad expression"); | |
738 | return 1; | |
739 | } | |
b99bd4ef | 740 | |
c19d1205 ZW |
741 | #ifdef OBJ_AOUT |
742 | if (seg != absolute_section | |
743 | && seg != text_section | |
744 | && seg != data_section | |
745 | && seg != bss_section | |
746 | && seg != undefined_section) | |
747 | { | |
748 | inst.error = _("bad segment"); | |
749 | *str = input_line_pointer; | |
750 | input_line_pointer = save_in; | |
751 | return 1; | |
b99bd4ef | 752 | } |
c19d1205 | 753 | #endif |
b99bd4ef | 754 | |
c19d1205 ZW |
755 | /* Get rid of any bignums now, so that we don't generate an error for which |
756 | we can't establish a line number later on. Big numbers are never valid | |
757 | in instructions, which is where this routine is always called. */ | |
758 | if (ep->X_op == O_big | |
759 | || (ep->X_add_symbol | |
760 | && (walk_no_bignums (ep->X_add_symbol) | |
761 | || (ep->X_op_symbol | |
762 | && walk_no_bignums (ep->X_op_symbol))))) | |
763 | { | |
764 | inst.error = _("invalid constant"); | |
765 | *str = input_line_pointer; | |
766 | input_line_pointer = save_in; | |
767 | return 1; | |
768 | } | |
b99bd4ef | 769 | |
c19d1205 ZW |
770 | *str = input_line_pointer; |
771 | input_line_pointer = save_in; | |
772 | return 0; | |
b99bd4ef NC |
773 | } |
774 | ||
c19d1205 ZW |
775 | /* Turn a string in input_line_pointer into a floating point constant |
776 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
777 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
778 | returned, or NULL on OK. | |
b99bd4ef | 779 | |
c19d1205 ZW |
780 | Note that fp constants aren't represent in the normal way on the ARM. |
781 | In big endian mode, things are as expected. However, in little endian | |
782 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
783 | within the words. For example, (double) 1.1 in big endian mode is | |
784 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
785 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 786 | |
c19d1205 | 787 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 788 | |
c19d1205 ZW |
789 | char * |
790 | md_atof (int type, char * litP, int * sizeP) | |
791 | { | |
792 | int prec; | |
793 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
794 | char *t; | |
795 | int i; | |
b99bd4ef | 796 | |
c19d1205 ZW |
797 | switch (type) |
798 | { | |
799 | case 'f': | |
800 | case 'F': | |
801 | case 's': | |
802 | case 'S': | |
803 | prec = 2; | |
804 | break; | |
b99bd4ef | 805 | |
c19d1205 ZW |
806 | case 'd': |
807 | case 'D': | |
808 | case 'r': | |
809 | case 'R': | |
810 | prec = 4; | |
811 | break; | |
b99bd4ef | 812 | |
c19d1205 ZW |
813 | case 'x': |
814 | case 'X': | |
815 | prec = 6; | |
816 | break; | |
b99bd4ef | 817 | |
c19d1205 ZW |
818 | case 'p': |
819 | case 'P': | |
820 | prec = 6; | |
821 | break; | |
a737bd4d | 822 | |
c19d1205 ZW |
823 | default: |
824 | *sizeP = 0; | |
825 | return _("bad call to MD_ATOF()"); | |
826 | } | |
b99bd4ef | 827 | |
c19d1205 ZW |
828 | t = atof_ieee (input_line_pointer, type, words); |
829 | if (t) | |
830 | input_line_pointer = t; | |
831 | *sizeP = prec * 2; | |
b99bd4ef | 832 | |
c19d1205 ZW |
833 | if (target_big_endian) |
834 | { | |
835 | for (i = 0; i < prec; i++) | |
836 | { | |
837 | md_number_to_chars (litP, (valueT) words[i], 2); | |
838 | litP += 2; | |
839 | } | |
840 | } | |
841 | else | |
842 | { | |
e74cfd16 | 843 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
844 | for (i = prec - 1; i >= 0; i--) |
845 | { | |
846 | md_number_to_chars (litP, (valueT) words[i], 2); | |
847 | litP += 2; | |
848 | } | |
849 | else | |
850 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
851 | For an 8 byte float the order is 1 0 3 2. */ | |
852 | for (i = 0; i < prec; i += 2) | |
853 | { | |
854 | md_number_to_chars (litP, (valueT) words[i + 1], 2); | |
855 | md_number_to_chars (litP + 2, (valueT) words[i], 2); | |
856 | litP += 4; | |
857 | } | |
858 | } | |
b99bd4ef | 859 | |
c19d1205 ZW |
860 | return 0; |
861 | } | |
b99bd4ef | 862 | |
c19d1205 ZW |
863 | /* We handle all bad expressions here, so that we can report the faulty |
864 | instruction in the error message. */ | |
865 | void | |
866 | md_operand (expressionS * expr) | |
867 | { | |
868 | if (in_my_get_expression) | |
869 | expr->X_op = O_illegal; | |
b99bd4ef NC |
870 | } |
871 | ||
c19d1205 | 872 | /* Immediate values. */ |
b99bd4ef | 873 | |
c19d1205 ZW |
874 | /* Generic immediate-value read function for use in directives. |
875 | Accepts anything that 'expression' can fold to a constant. | |
876 | *val receives the number. */ | |
877 | #ifdef OBJ_ELF | |
878 | static int | |
879 | immediate_for_directive (int *val) | |
b99bd4ef | 880 | { |
c19d1205 ZW |
881 | expressionS exp; |
882 | exp.X_op = O_illegal; | |
b99bd4ef | 883 | |
c19d1205 ZW |
884 | if (is_immediate_prefix (*input_line_pointer)) |
885 | { | |
886 | input_line_pointer++; | |
887 | expression (&exp); | |
888 | } | |
b99bd4ef | 889 | |
c19d1205 ZW |
890 | if (exp.X_op != O_constant) |
891 | { | |
892 | as_bad (_("expected #constant")); | |
893 | ignore_rest_of_line (); | |
894 | return FAIL; | |
895 | } | |
896 | *val = exp.X_add_number; | |
897 | return SUCCESS; | |
b99bd4ef | 898 | } |
c19d1205 | 899 | #endif |
b99bd4ef | 900 | |
c19d1205 | 901 | /* Register parsing. */ |
b99bd4ef | 902 | |
c19d1205 ZW |
903 | /* Generic register parser. CCP points to what should be the |
904 | beginning of a register name. If it is indeed a valid register | |
905 | name, advance CCP over it and return the reg_entry structure; | |
906 | otherwise return NULL. Does not issue diagnostics. */ | |
907 | ||
908 | static struct reg_entry * | |
909 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 910 | { |
c19d1205 ZW |
911 | char *start = *ccp; |
912 | char *p; | |
913 | struct reg_entry *reg; | |
b99bd4ef | 914 | |
c19d1205 ZW |
915 | #ifdef REGISTER_PREFIX |
916 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 917 | return NULL; |
c19d1205 ZW |
918 | start++; |
919 | #endif | |
920 | #ifdef OPTIONAL_REGISTER_PREFIX | |
921 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
922 | start++; | |
923 | #endif | |
b99bd4ef | 924 | |
c19d1205 ZW |
925 | p = start; |
926 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
927 | return NULL; | |
b99bd4ef | 928 | |
c19d1205 ZW |
929 | do |
930 | p++; | |
931 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
932 | ||
933 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
934 | ||
935 | if (!reg) | |
936 | return NULL; | |
937 | ||
938 | *ccp = p; | |
939 | return reg; | |
b99bd4ef NC |
940 | } |
941 | ||
c19d1205 | 942 | /* As above, but the register must be of type TYPE, and the return |
01cfc07f | 943 | value is the register number or FAIL. */ |
c19d1205 | 944 | |
b99bd4ef | 945 | static int |
c19d1205 | 946 | arm_reg_parse (char **ccp, enum arm_reg_type type) |
b99bd4ef | 947 | { |
c19d1205 ZW |
948 | char *start = *ccp; |
949 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
b99bd4ef | 950 | |
c19d1205 ZW |
951 | if (reg && reg->type == type) |
952 | return reg->number; | |
6057a28f | 953 | |
c19d1205 ZW |
954 | /* Alternative syntaxes are accepted for a few register classes. */ |
955 | switch (type) | |
956 | { | |
957 | case REG_TYPE_MVF: | |
958 | case REG_TYPE_MVD: | |
959 | case REG_TYPE_MVFX: | |
960 | case REG_TYPE_MVDX: | |
961 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 962 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
963 | return reg->number; |
964 | break; | |
69b97547 | 965 | |
c19d1205 ZW |
966 | case REG_TYPE_CP: |
967 | /* For backward compatibility, a bare number is valid here. */ | |
968 | { | |
969 | unsigned long processor = strtoul (start, ccp, 10); | |
970 | if (*ccp != start && processor <= 15) | |
971 | return processor; | |
972 | } | |
6057a28f | 973 | |
c19d1205 ZW |
974 | case REG_TYPE_MMXWC: |
975 | /* WC includes WCG. ??? I'm not sure this is true for all | |
976 | instructions that take WC registers. */ | |
79134647 | 977 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 978 | return reg->number; |
6057a28f | 979 | break; |
c19d1205 | 980 | |
6057a28f | 981 | default: |
c19d1205 | 982 | break; |
6057a28f NC |
983 | } |
984 | ||
c19d1205 ZW |
985 | *ccp = start; |
986 | return FAIL; | |
987 | } | |
69b97547 | 988 | |
c19d1205 ZW |
989 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
990 | static long | |
991 | parse_reg_list (char ** strp) | |
992 | { | |
993 | char * str = * strp; | |
994 | long range = 0; | |
995 | int another_range; | |
a737bd4d | 996 | |
c19d1205 ZW |
997 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
998 | do | |
6057a28f | 999 | { |
c19d1205 | 1000 | another_range = 0; |
a737bd4d | 1001 | |
c19d1205 ZW |
1002 | if (*str == '{') |
1003 | { | |
1004 | int in_range = 0; | |
1005 | int cur_reg = -1; | |
a737bd4d | 1006 | |
c19d1205 ZW |
1007 | str++; |
1008 | do | |
1009 | { | |
1010 | int reg; | |
6057a28f | 1011 | |
c19d1205 ZW |
1012 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
1013 | { | |
1014 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
1015 | return FAIL; | |
1016 | } | |
a737bd4d | 1017 | |
c19d1205 ZW |
1018 | if (in_range) |
1019 | { | |
1020 | int i; | |
a737bd4d | 1021 | |
c19d1205 ZW |
1022 | if (reg <= cur_reg) |
1023 | { | |
1024 | inst.error = _("bad range in register list"); | |
1025 | return FAIL; | |
1026 | } | |
40a18ebd | 1027 | |
c19d1205 ZW |
1028 | for (i = cur_reg + 1; i < reg; i++) |
1029 | { | |
1030 | if (range & (1 << i)) | |
1031 | as_tsktsk | |
1032 | (_("Warning: duplicated register (r%d) in register list"), | |
1033 | i); | |
1034 | else | |
1035 | range |= 1 << i; | |
1036 | } | |
1037 | in_range = 0; | |
1038 | } | |
a737bd4d | 1039 | |
c19d1205 ZW |
1040 | if (range & (1 << reg)) |
1041 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1042 | reg); | |
1043 | else if (reg <= cur_reg) | |
1044 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1045 | |
c19d1205 ZW |
1046 | range |= 1 << reg; |
1047 | cur_reg = reg; | |
1048 | } | |
1049 | while (skip_past_comma (&str) != FAIL | |
1050 | || (in_range = 1, *str++ == '-')); | |
1051 | str--; | |
a737bd4d | 1052 | |
c19d1205 ZW |
1053 | if (*str++ != '}') |
1054 | { | |
1055 | inst.error = _("missing `}'"); | |
1056 | return FAIL; | |
1057 | } | |
1058 | } | |
1059 | else | |
1060 | { | |
1061 | expressionS expr; | |
40a18ebd | 1062 | |
c19d1205 ZW |
1063 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1064 | return FAIL; | |
40a18ebd | 1065 | |
c19d1205 ZW |
1066 | if (expr.X_op == O_constant) |
1067 | { | |
1068 | if (expr.X_add_number | |
1069 | != (expr.X_add_number & 0x0000ffff)) | |
1070 | { | |
1071 | inst.error = _("invalid register mask"); | |
1072 | return FAIL; | |
1073 | } | |
a737bd4d | 1074 | |
c19d1205 ZW |
1075 | if ((range & expr.X_add_number) != 0) |
1076 | { | |
1077 | int regno = range & expr.X_add_number; | |
a737bd4d | 1078 | |
c19d1205 ZW |
1079 | regno &= -regno; |
1080 | regno = (1 << regno) - 1; | |
1081 | as_tsktsk | |
1082 | (_("Warning: duplicated register (r%d) in register list"), | |
1083 | regno); | |
1084 | } | |
a737bd4d | 1085 | |
c19d1205 ZW |
1086 | range |= expr.X_add_number; |
1087 | } | |
1088 | else | |
1089 | { | |
1090 | if (inst.reloc.type != 0) | |
1091 | { | |
1092 | inst.error = _("expression too complex"); | |
1093 | return FAIL; | |
1094 | } | |
a737bd4d | 1095 | |
c19d1205 ZW |
1096 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1097 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1098 | inst.reloc.pc_rel = 0; | |
1099 | } | |
1100 | } | |
a737bd4d | 1101 | |
c19d1205 ZW |
1102 | if (*str == '|' || *str == '+') |
1103 | { | |
1104 | str++; | |
1105 | another_range = 1; | |
1106 | } | |
a737bd4d | 1107 | } |
c19d1205 | 1108 | while (another_range); |
a737bd4d | 1109 | |
c19d1205 ZW |
1110 | *strp = str; |
1111 | return range; | |
a737bd4d NC |
1112 | } |
1113 | ||
c19d1205 ZW |
1114 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1115 | Otherwise return the number of registers, and set PBASE to the first | |
1116 | register. Double precision registers are matched if DP is nonzero. */ | |
6057a28f | 1117 | |
c19d1205 | 1118 | static int |
ca3f61f7 | 1119 | parse_vfp_reg_list (char **str, unsigned int *pbase, int dp) |
6057a28f | 1120 | { |
c19d1205 ZW |
1121 | int base_reg; |
1122 | int new_base; | |
1123 | int regtype; | |
1124 | int max_regs; | |
1125 | int count = 0; | |
1126 | int warned = 0; | |
1127 | unsigned long mask = 0; | |
a737bd4d | 1128 | int i; |
6057a28f | 1129 | |
c19d1205 ZW |
1130 | if (**str != '{') |
1131 | return FAIL; | |
6057a28f | 1132 | |
c19d1205 | 1133 | (*str)++; |
6057a28f | 1134 | |
c19d1205 | 1135 | if (dp) |
a737bd4d | 1136 | { |
c19d1205 ZW |
1137 | regtype = REG_TYPE_VFD; |
1138 | max_regs = 16; | |
1139 | } | |
1140 | else | |
1141 | { | |
1142 | regtype = REG_TYPE_VFS; | |
1143 | max_regs = 32; | |
1144 | } | |
6057a28f | 1145 | |
c19d1205 | 1146 | base_reg = max_regs; |
a737bd4d | 1147 | |
c19d1205 ZW |
1148 | do |
1149 | { | |
1150 | new_base = arm_reg_parse (str, regtype); | |
1151 | if (new_base == FAIL) | |
a737bd4d | 1152 | { |
c19d1205 ZW |
1153 | inst.error = gettext (reg_expected_msgs[regtype]); |
1154 | return FAIL; | |
1155 | } | |
a737bd4d | 1156 | |
c19d1205 ZW |
1157 | if (new_base < base_reg) |
1158 | base_reg = new_base; | |
a737bd4d | 1159 | |
c19d1205 ZW |
1160 | if (mask & (1 << new_base)) |
1161 | { | |
1162 | inst.error = _("invalid register list"); | |
1163 | return FAIL; | |
a737bd4d | 1164 | } |
a737bd4d | 1165 | |
c19d1205 ZW |
1166 | if ((mask >> new_base) != 0 && ! warned) |
1167 | { | |
1168 | as_tsktsk (_("register list not in ascending order")); | |
1169 | warned = 1; | |
1170 | } | |
0bbf2aa4 | 1171 | |
c19d1205 ZW |
1172 | mask |= 1 << new_base; |
1173 | count++; | |
0bbf2aa4 | 1174 | |
c19d1205 ZW |
1175 | if (**str == '-') /* We have the start of a range expression */ |
1176 | { | |
1177 | int high_range; | |
0bbf2aa4 | 1178 | |
c19d1205 | 1179 | (*str)++; |
0bbf2aa4 | 1180 | |
c19d1205 ZW |
1181 | if ((high_range = arm_reg_parse (str, regtype)) == FAIL) |
1182 | { | |
1183 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1184 | return FAIL; | |
1185 | } | |
0bbf2aa4 | 1186 | |
c19d1205 ZW |
1187 | if (high_range <= new_base) |
1188 | { | |
1189 | inst.error = _("register range not in ascending order"); | |
1190 | return FAIL; | |
1191 | } | |
0bbf2aa4 | 1192 | |
c19d1205 | 1193 | for (new_base++; new_base <= high_range; new_base++) |
0bbf2aa4 | 1194 | { |
c19d1205 | 1195 | if (mask & (1 << new_base)) |
0bbf2aa4 | 1196 | { |
c19d1205 ZW |
1197 | inst.error = _("invalid register list"); |
1198 | return FAIL; | |
0bbf2aa4 | 1199 | } |
c19d1205 ZW |
1200 | |
1201 | mask |= 1 << new_base; | |
1202 | count++; | |
0bbf2aa4 | 1203 | } |
0bbf2aa4 | 1204 | } |
0bbf2aa4 | 1205 | } |
c19d1205 | 1206 | while (skip_past_comma (str) != FAIL); |
0bbf2aa4 | 1207 | |
c19d1205 | 1208 | (*str)++; |
0bbf2aa4 | 1209 | |
c19d1205 ZW |
1210 | /* Sanity check -- should have raised a parse error above. */ |
1211 | if (count == 0 || count > max_regs) | |
1212 | abort (); | |
1213 | ||
1214 | *pbase = base_reg; | |
1215 | ||
1216 | /* Final test -- the registers must be consecutive. */ | |
1217 | mask >>= base_reg; | |
1218 | for (i = 0; i < count; i++) | |
1219 | { | |
1220 | if ((mask & (1u << i)) == 0) | |
1221 | { | |
1222 | inst.error = _("non-contiguous register range"); | |
1223 | return FAIL; | |
1224 | } | |
1225 | } | |
1226 | ||
1227 | return count; | |
b99bd4ef NC |
1228 | } |
1229 | ||
c19d1205 ZW |
1230 | /* Parse an explicit relocation suffix on an expression. This is |
1231 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
1232 | arm_reloc_hsh contains no entries, so this function can only | |
1233 | succeed if there is no () after the word. Returns -1 on error, | |
1234 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
1235 | static int | |
1236 | parse_reloc (char **str) | |
b99bd4ef | 1237 | { |
c19d1205 ZW |
1238 | struct reloc_entry *r; |
1239 | char *p, *q; | |
b99bd4ef | 1240 | |
c19d1205 ZW |
1241 | if (**str != '(') |
1242 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 1243 | |
c19d1205 ZW |
1244 | p = *str + 1; |
1245 | q = p; | |
1246 | ||
1247 | while (*q && *q != ')' && *q != ',') | |
1248 | q++; | |
1249 | if (*q != ')') | |
1250 | return -1; | |
1251 | ||
1252 | if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
1253 | return -1; | |
1254 | ||
1255 | *str = q + 1; | |
1256 | return r->reloc; | |
b99bd4ef NC |
1257 | } |
1258 | ||
c19d1205 ZW |
1259 | /* Directives: register aliases. */ |
1260 | ||
b99bd4ef | 1261 | static void |
c19d1205 | 1262 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 1263 | { |
c19d1205 ZW |
1264 | struct reg_entry *new; |
1265 | const char *name; | |
b99bd4ef | 1266 | |
c19d1205 ZW |
1267 | if ((new = hash_find (arm_reg_hsh, str)) != 0) |
1268 | { | |
1269 | if (new->builtin) | |
1270 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); | |
b99bd4ef | 1271 | |
c19d1205 ZW |
1272 | /* Only warn about a redefinition if it's not defined as the |
1273 | same register. */ | |
1274 | else if (new->number != number || new->type != type) | |
1275 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
69b97547 | 1276 | |
c19d1205 ZW |
1277 | return; |
1278 | } | |
b99bd4ef | 1279 | |
c19d1205 ZW |
1280 | name = xstrdup (str); |
1281 | new = xmalloc (sizeof (struct reg_entry)); | |
b99bd4ef | 1282 | |
c19d1205 ZW |
1283 | new->name = name; |
1284 | new->number = number; | |
1285 | new->type = type; | |
1286 | new->builtin = FALSE; | |
b99bd4ef | 1287 | |
c19d1205 ZW |
1288 | if (hash_insert (arm_reg_hsh, name, (PTR) new)) |
1289 | abort (); | |
1290 | } | |
b99bd4ef | 1291 | |
c19d1205 | 1292 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 1293 | |
c19d1205 | 1294 | new_register_name .req existing_register_name |
b99bd4ef | 1295 | |
c19d1205 ZW |
1296 | If we find one, or if it looks sufficiently like one that we want to |
1297 | handle any error here, return non-zero. Otherwise return zero. */ | |
b99bd4ef | 1298 | |
c19d1205 ZW |
1299 | static int |
1300 | create_register_alias (char * newname, char *p) | |
1301 | { | |
1302 | struct reg_entry *old; | |
1303 | char *oldname, *nbuf; | |
1304 | size_t nlen; | |
b99bd4ef | 1305 | |
c19d1205 ZW |
1306 | /* The input scrubber ensures that whitespace after the mnemonic is |
1307 | collapsed to single spaces. */ | |
1308 | oldname = p; | |
1309 | if (strncmp (oldname, " .req ", 6) != 0) | |
1310 | return 0; | |
b99bd4ef | 1311 | |
c19d1205 ZW |
1312 | oldname += 6; |
1313 | if (*oldname == '\0') | |
1314 | return 0; | |
b99bd4ef | 1315 | |
c19d1205 ZW |
1316 | old = hash_find (arm_reg_hsh, oldname); |
1317 | if (!old) | |
b99bd4ef | 1318 | { |
c19d1205 ZW |
1319 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
1320 | return 1; | |
b99bd4ef NC |
1321 | } |
1322 | ||
c19d1205 ZW |
1323 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
1324 | the desired alias name, and p points to its end. If not, then | |
1325 | the desired alias name is in the global original_case_string. */ | |
1326 | #ifdef TC_CASE_SENSITIVE | |
1327 | nlen = p - newname; | |
1328 | #else | |
1329 | newname = original_case_string; | |
1330 | nlen = strlen (newname); | |
1331 | #endif | |
b99bd4ef | 1332 | |
c19d1205 ZW |
1333 | nbuf = alloca (nlen + 1); |
1334 | memcpy (nbuf, newname, nlen); | |
1335 | nbuf[nlen] = '\0'; | |
b99bd4ef | 1336 | |
c19d1205 ZW |
1337 | /* Create aliases under the new name as stated; an all-lowercase |
1338 | version of the new name; and an all-uppercase version of the new | |
1339 | name. */ | |
1340 | insert_reg_alias (nbuf, old->number, old->type); | |
b99bd4ef | 1341 | |
c19d1205 ZW |
1342 | for (p = nbuf; *p; p++) |
1343 | *p = TOUPPER (*p); | |
1344 | ||
1345 | if (strncmp (nbuf, newname, nlen)) | |
1346 | insert_reg_alias (nbuf, old->number, old->type); | |
1347 | ||
1348 | for (p = nbuf; *p; p++) | |
1349 | *p = TOLOWER (*p); | |
1350 | ||
1351 | if (strncmp (nbuf, newname, nlen)) | |
1352 | insert_reg_alias (nbuf, old->number, old->type); | |
1353 | ||
1354 | return 1; | |
b99bd4ef NC |
1355 | } |
1356 | ||
c19d1205 ZW |
1357 | /* Should never be called, as .req goes between the alias and the |
1358 | register name, not at the beginning of the line. */ | |
b99bd4ef | 1359 | static void |
c19d1205 | 1360 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 1361 | { |
c19d1205 ZW |
1362 | as_bad (_("invalid syntax for .req directive")); |
1363 | } | |
b99bd4ef | 1364 | |
c19d1205 ZW |
1365 | /* The .unreq directive deletes an alias which was previously defined |
1366 | by .req. For example: | |
b99bd4ef | 1367 | |
c19d1205 ZW |
1368 | my_alias .req r11 |
1369 | .unreq my_alias */ | |
b99bd4ef NC |
1370 | |
1371 | static void | |
c19d1205 | 1372 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 1373 | { |
c19d1205 ZW |
1374 | char * name; |
1375 | char saved_char; | |
b99bd4ef | 1376 | |
c19d1205 ZW |
1377 | name = input_line_pointer; |
1378 | ||
1379 | while (*input_line_pointer != 0 | |
1380 | && *input_line_pointer != ' ' | |
1381 | && *input_line_pointer != '\n') | |
1382 | ++input_line_pointer; | |
1383 | ||
1384 | saved_char = *input_line_pointer; | |
1385 | *input_line_pointer = 0; | |
1386 | ||
1387 | if (!*name) | |
1388 | as_bad (_("invalid syntax for .unreq directive")); | |
1389 | else | |
1390 | { | |
1391 | struct reg_entry *reg = hash_find (arm_reg_hsh, name); | |
1392 | ||
1393 | if (!reg) | |
1394 | as_bad (_("unknown register alias '%s'"), name); | |
1395 | else if (reg->builtin) | |
1396 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
1397 | name); | |
1398 | else | |
1399 | { | |
1400 | hash_delete (arm_reg_hsh, name); | |
1401 | free ((char *) reg->name); | |
1402 | free (reg); | |
1403 | } | |
1404 | } | |
b99bd4ef | 1405 | |
c19d1205 | 1406 | *input_line_pointer = saved_char; |
b99bd4ef NC |
1407 | demand_empty_rest_of_line (); |
1408 | } | |
1409 | ||
c19d1205 ZW |
1410 | /* Directives: Instruction set selection. */ |
1411 | ||
1412 | #ifdef OBJ_ELF | |
1413 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
1414 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
1415 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
1416 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
1417 | ||
1418 | static enum mstate mapstate = MAP_UNDEFINED; | |
b99bd4ef NC |
1419 | |
1420 | static void | |
c19d1205 | 1421 | mapping_state (enum mstate state) |
b99bd4ef | 1422 | { |
a737bd4d | 1423 | symbolS * symbolP; |
c19d1205 ZW |
1424 | const char * symname; |
1425 | int type; | |
b99bd4ef | 1426 | |
c19d1205 ZW |
1427 | if (mapstate == state) |
1428 | /* The mapping symbol has already been emitted. | |
1429 | There is nothing else to do. */ | |
1430 | return; | |
b99bd4ef | 1431 | |
c19d1205 | 1432 | mapstate = state; |
b99bd4ef | 1433 | |
c19d1205 | 1434 | switch (state) |
b99bd4ef | 1435 | { |
c19d1205 ZW |
1436 | case MAP_DATA: |
1437 | symname = "$d"; | |
1438 | type = BSF_NO_FLAGS; | |
1439 | break; | |
1440 | case MAP_ARM: | |
1441 | symname = "$a"; | |
1442 | type = BSF_NO_FLAGS; | |
1443 | break; | |
1444 | case MAP_THUMB: | |
1445 | symname = "$t"; | |
1446 | type = BSF_NO_FLAGS; | |
1447 | break; | |
1448 | case MAP_UNDEFINED: | |
1449 | return; | |
1450 | default: | |
1451 | abort (); | |
1452 | } | |
1453 | ||
1454 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; | |
1455 | ||
1456 | symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now); | |
1457 | symbol_table_insert (symbolP); | |
1458 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; | |
1459 | ||
1460 | switch (state) | |
1461 | { | |
1462 | case MAP_ARM: | |
1463 | THUMB_SET_FUNC (symbolP, 0); | |
1464 | ARM_SET_THUMB (symbolP, 0); | |
1465 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
1466 | break; | |
1467 | ||
1468 | case MAP_THUMB: | |
1469 | THUMB_SET_FUNC (symbolP, 1); | |
1470 | ARM_SET_THUMB (symbolP, 1); | |
1471 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
1472 | break; | |
1473 | ||
1474 | case MAP_DATA: | |
1475 | default: | |
1476 | return; | |
1477 | } | |
1478 | } | |
1479 | #else | |
1480 | #define mapping_state(x) /* nothing */ | |
1481 | #endif | |
1482 | ||
1483 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
1484 | ||
1485 | static symbolS * | |
1486 | find_real_start (symbolS * symbolP) | |
1487 | { | |
1488 | char * real_start; | |
1489 | const char * name = S_GET_NAME (symbolP); | |
1490 | symbolS * new_target; | |
1491 | ||
1492 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
1493 | #define STUB_NAME ".real_start_of" | |
1494 | ||
1495 | if (name == NULL) | |
1496 | abort (); | |
1497 | ||
37f6032b ZW |
1498 | /* The compiler may generate BL instructions to local labels because |
1499 | it needs to perform a branch to a far away location. These labels | |
1500 | do not have a corresponding ".real_start_of" label. We check | |
1501 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
1502 | the ".real_start_of" convention for nonlocal branches. */ | |
1503 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
1504 | return symbolP; |
1505 | ||
37f6032b | 1506 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
1507 | new_target = symbol_find (real_start); |
1508 | ||
1509 | if (new_target == NULL) | |
1510 | { | |
1511 | as_warn ("Failed to find real start of function: %s\n", name); | |
1512 | new_target = symbolP; | |
1513 | } | |
1514 | ||
c19d1205 ZW |
1515 | return new_target; |
1516 | } | |
1517 | ||
1518 | static void | |
1519 | opcode_select (int width) | |
1520 | { | |
1521 | switch (width) | |
1522 | { | |
1523 | case 16: | |
1524 | if (! thumb_mode) | |
1525 | { | |
e74cfd16 | 1526 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
1527 | as_bad (_("selected processor does not support THUMB opcodes")); |
1528 | ||
1529 | thumb_mode = 1; | |
1530 | /* No need to force the alignment, since we will have been | |
1531 | coming from ARM mode, which is word-aligned. */ | |
1532 | record_alignment (now_seg, 1); | |
1533 | } | |
1534 | mapping_state (MAP_THUMB); | |
1535 | break; | |
1536 | ||
1537 | case 32: | |
1538 | if (thumb_mode) | |
1539 | { | |
e74cfd16 | 1540 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
1541 | as_bad (_("selected processor does not support ARM opcodes")); |
1542 | ||
1543 | thumb_mode = 0; | |
1544 | ||
1545 | if (!need_pass_2) | |
1546 | frag_align (2, 0, 0); | |
1547 | ||
1548 | record_alignment (now_seg, 1); | |
1549 | } | |
1550 | mapping_state (MAP_ARM); | |
1551 | break; | |
1552 | ||
1553 | default: | |
1554 | as_bad (_("invalid instruction size selected (%d)"), width); | |
1555 | } | |
1556 | } | |
1557 | ||
1558 | static void | |
1559 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
1560 | { | |
1561 | opcode_select (32); | |
1562 | demand_empty_rest_of_line (); | |
1563 | } | |
1564 | ||
1565 | static void | |
1566 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
1567 | { | |
1568 | opcode_select (16); | |
1569 | demand_empty_rest_of_line (); | |
1570 | } | |
1571 | ||
1572 | static void | |
1573 | s_code (int unused ATTRIBUTE_UNUSED) | |
1574 | { | |
1575 | int temp; | |
1576 | ||
1577 | temp = get_absolute_expression (); | |
1578 | switch (temp) | |
1579 | { | |
1580 | case 16: | |
1581 | case 32: | |
1582 | opcode_select (temp); | |
1583 | break; | |
1584 | ||
1585 | default: | |
1586 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
1587 | } | |
1588 | } | |
1589 | ||
1590 | static void | |
1591 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
1592 | { | |
1593 | /* If we are not already in thumb mode go into it, EVEN if | |
1594 | the target processor does not support thumb instructions. | |
1595 | This is used by gcc/config/arm/lib1funcs.asm for example | |
1596 | to compile interworking support functions even if the | |
1597 | target processor should not support interworking. */ | |
1598 | if (! thumb_mode) | |
1599 | { | |
1600 | thumb_mode = 2; | |
1601 | record_alignment (now_seg, 1); | |
1602 | } | |
1603 | ||
1604 | demand_empty_rest_of_line (); | |
1605 | } | |
1606 | ||
1607 | static void | |
1608 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
1609 | { | |
1610 | s_thumb (0); | |
1611 | ||
1612 | /* The following label is the name/address of the start of a Thumb function. | |
1613 | We need to know this for the interworking support. */ | |
1614 | label_is_thumb_function_name = TRUE; | |
1615 | } | |
1616 | ||
1617 | /* Perform a .set directive, but also mark the alias as | |
1618 | being a thumb function. */ | |
1619 | ||
1620 | static void | |
1621 | s_thumb_set (int equiv) | |
1622 | { | |
1623 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
1624 | We cannot just call that code as we need to get at the symbol that | |
1625 | is created. */ | |
1626 | char * name; | |
1627 | char delim; | |
1628 | char * end_name; | |
1629 | symbolS * symbolP; | |
1630 | ||
1631 | /* Especial apologies for the random logic: | |
1632 | This just grew, and could be parsed much more simply! | |
1633 | Dean - in haste. */ | |
1634 | name = input_line_pointer; | |
1635 | delim = get_symbol_end (); | |
1636 | end_name = input_line_pointer; | |
1637 | *end_name = delim; | |
1638 | ||
1639 | if (*input_line_pointer != ',') | |
1640 | { | |
1641 | *end_name = 0; | |
1642 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
1643 | *end_name = delim; |
1644 | ignore_rest_of_line (); | |
1645 | return; | |
1646 | } | |
1647 | ||
1648 | input_line_pointer++; | |
1649 | *end_name = 0; | |
1650 | ||
1651 | if (name[0] == '.' && name[1] == '\0') | |
1652 | { | |
1653 | /* XXX - this should not happen to .thumb_set. */ | |
1654 | abort (); | |
1655 | } | |
1656 | ||
1657 | if ((symbolP = symbol_find (name)) == NULL | |
1658 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
1659 | { | |
1660 | #ifndef NO_LISTING | |
1661 | /* When doing symbol listings, play games with dummy fragments living | |
1662 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 1663 | for this symbol. */ |
b99bd4ef NC |
1664 | if (listing & LISTING_SYMBOLS) |
1665 | { | |
1666 | extern struct list_info_struct * listing_tail; | |
a737bd4d | 1667 | fragS * dummy_frag = xmalloc (sizeof (fragS)); |
b99bd4ef NC |
1668 | |
1669 | memset (dummy_frag, 0, sizeof (fragS)); | |
1670 | dummy_frag->fr_type = rs_fill; | |
1671 | dummy_frag->line = listing_tail; | |
1672 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
1673 | dummy_frag->fr_symbol = symbolP; | |
1674 | } | |
1675 | else | |
1676 | #endif | |
1677 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
1678 | ||
1679 | #ifdef OBJ_COFF | |
1680 | /* "set" symbols are local unless otherwise specified. */ | |
1681 | SF_SET_LOCAL (symbolP); | |
1682 | #endif /* OBJ_COFF */ | |
1683 | } /* Make a new symbol. */ | |
1684 | ||
1685 | symbol_table_insert (symbolP); | |
1686 | ||
1687 | * end_name = delim; | |
1688 | ||
1689 | if (equiv | |
1690 | && S_IS_DEFINED (symbolP) | |
1691 | && S_GET_SEGMENT (symbolP) != reg_section) | |
1692 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
1693 | ||
1694 | pseudo_set (symbolP); | |
1695 | ||
1696 | demand_empty_rest_of_line (); | |
1697 | ||
c19d1205 | 1698 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
1699 | |
1700 | THUMB_SET_FUNC (symbolP, 1); | |
1701 | ARM_SET_THUMB (symbolP, 1); | |
1702 | #if defined OBJ_ELF || defined OBJ_COFF | |
1703 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
1704 | #endif | |
1705 | } | |
1706 | ||
c19d1205 | 1707 | /* Directives: Mode selection. */ |
b99bd4ef | 1708 | |
c19d1205 ZW |
1709 | /* .syntax [unified|divided] - choose the new unified syntax |
1710 | (same for Arm and Thumb encoding, modulo slight differences in what | |
1711 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 1712 | static void |
c19d1205 | 1713 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 1714 | { |
c19d1205 ZW |
1715 | char *name, delim; |
1716 | ||
1717 | name = input_line_pointer; | |
1718 | delim = get_symbol_end (); | |
1719 | ||
1720 | if (!strcasecmp (name, "unified")) | |
1721 | unified_syntax = TRUE; | |
1722 | else if (!strcasecmp (name, "divided")) | |
1723 | unified_syntax = FALSE; | |
1724 | else | |
1725 | { | |
1726 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
1727 | return; | |
1728 | } | |
1729 | *input_line_pointer = delim; | |
b99bd4ef NC |
1730 | demand_empty_rest_of_line (); |
1731 | } | |
1732 | ||
c19d1205 ZW |
1733 | /* Directives: sectioning and alignment. */ |
1734 | ||
1735 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
1736 | ||
b99bd4ef | 1737 | static void |
c19d1205 | 1738 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 1739 | { |
a737bd4d | 1740 | int temp; |
c19d1205 ZW |
1741 | long temp_fill; |
1742 | long max_alignment = 15; | |
b99bd4ef NC |
1743 | |
1744 | temp = get_absolute_expression (); | |
c19d1205 ZW |
1745 | if (temp > max_alignment) |
1746 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
1747 | else if (temp < 0) | |
b99bd4ef | 1748 | { |
c19d1205 ZW |
1749 | as_bad (_("alignment negative. 0 assumed.")); |
1750 | temp = 0; | |
1751 | } | |
b99bd4ef | 1752 | |
c19d1205 ZW |
1753 | if (*input_line_pointer == ',') |
1754 | { | |
1755 | input_line_pointer++; | |
1756 | temp_fill = get_absolute_expression (); | |
b99bd4ef | 1757 | } |
c19d1205 ZW |
1758 | else |
1759 | temp_fill = 0; | |
b99bd4ef | 1760 | |
c19d1205 ZW |
1761 | if (!temp) |
1762 | temp = 2; | |
b99bd4ef | 1763 | |
c19d1205 ZW |
1764 | /* Only make a frag if we HAVE to. */ |
1765 | if (temp && !need_pass_2) | |
1766 | frag_align (temp, (int) temp_fill, 0); | |
1767 | demand_empty_rest_of_line (); | |
1768 | ||
1769 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
1770 | } |
1771 | ||
c19d1205 ZW |
1772 | static void |
1773 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 1774 | { |
c19d1205 ZW |
1775 | /* We don't support putting frags in the BSS segment, we fake it by |
1776 | marking in_bss, then looking at s_skip for clues. */ | |
1777 | subseg_set (bss_section, 0); | |
1778 | demand_empty_rest_of_line (); | |
1779 | mapping_state (MAP_DATA); | |
1780 | } | |
b99bd4ef | 1781 | |
c19d1205 ZW |
1782 | static void |
1783 | s_even (int ignore ATTRIBUTE_UNUSED) | |
1784 | { | |
1785 | /* Never make frag if expect extra pass. */ | |
1786 | if (!need_pass_2) | |
1787 | frag_align (1, 0, 0); | |
b99bd4ef | 1788 | |
c19d1205 | 1789 | record_alignment (now_seg, 1); |
b99bd4ef | 1790 | |
c19d1205 | 1791 | demand_empty_rest_of_line (); |
b99bd4ef NC |
1792 | } |
1793 | ||
c19d1205 | 1794 | /* Directives: Literal pools. */ |
a737bd4d | 1795 | |
c19d1205 ZW |
1796 | static literal_pool * |
1797 | find_literal_pool (void) | |
a737bd4d | 1798 | { |
c19d1205 | 1799 | literal_pool * pool; |
a737bd4d | 1800 | |
c19d1205 | 1801 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 1802 | { |
c19d1205 ZW |
1803 | if (pool->section == now_seg |
1804 | && pool->sub_section == now_subseg) | |
1805 | break; | |
a737bd4d NC |
1806 | } |
1807 | ||
c19d1205 | 1808 | return pool; |
a737bd4d NC |
1809 | } |
1810 | ||
c19d1205 ZW |
1811 | static literal_pool * |
1812 | find_or_make_literal_pool (void) | |
a737bd4d | 1813 | { |
c19d1205 ZW |
1814 | /* Next literal pool ID number. */ |
1815 | static unsigned int latest_pool_num = 1; | |
1816 | literal_pool * pool; | |
a737bd4d | 1817 | |
c19d1205 | 1818 | pool = find_literal_pool (); |
a737bd4d | 1819 | |
c19d1205 | 1820 | if (pool == NULL) |
a737bd4d | 1821 | { |
c19d1205 ZW |
1822 | /* Create a new pool. */ |
1823 | pool = xmalloc (sizeof (* pool)); | |
1824 | if (! pool) | |
1825 | return NULL; | |
a737bd4d | 1826 | |
c19d1205 ZW |
1827 | pool->next_free_entry = 0; |
1828 | pool->section = now_seg; | |
1829 | pool->sub_section = now_subseg; | |
1830 | pool->next = list_of_pools; | |
1831 | pool->symbol = NULL; | |
1832 | ||
1833 | /* Add it to the list. */ | |
1834 | list_of_pools = pool; | |
a737bd4d | 1835 | } |
a737bd4d | 1836 | |
c19d1205 ZW |
1837 | /* New pools, and emptied pools, will have a NULL symbol. */ |
1838 | if (pool->symbol == NULL) | |
a737bd4d | 1839 | { |
c19d1205 ZW |
1840 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
1841 | (valueT) 0, &zero_address_frag); | |
1842 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
1843 | } |
1844 | ||
c19d1205 ZW |
1845 | /* Done. */ |
1846 | return pool; | |
a737bd4d NC |
1847 | } |
1848 | ||
c19d1205 ZW |
1849 | /* Add the literal in the global 'inst' |
1850 | structure to the relevent literal pool. */ | |
b99bd4ef NC |
1851 | |
1852 | static int | |
c19d1205 | 1853 | add_to_lit_pool (void) |
b99bd4ef | 1854 | { |
c19d1205 ZW |
1855 | literal_pool * pool; |
1856 | unsigned int entry; | |
b99bd4ef | 1857 | |
c19d1205 ZW |
1858 | pool = find_or_make_literal_pool (); |
1859 | ||
1860 | /* Check if this literal value is already in the pool. */ | |
1861 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 1862 | { |
c19d1205 ZW |
1863 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
1864 | && (inst.reloc.exp.X_op == O_constant) | |
1865 | && (pool->literals[entry].X_add_number | |
1866 | == inst.reloc.exp.X_add_number) | |
1867 | && (pool->literals[entry].X_unsigned | |
1868 | == inst.reloc.exp.X_unsigned)) | |
1869 | break; | |
1870 | ||
1871 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
1872 | && (inst.reloc.exp.X_op == O_symbol) | |
1873 | && (pool->literals[entry].X_add_number | |
1874 | == inst.reloc.exp.X_add_number) | |
1875 | && (pool->literals[entry].X_add_symbol | |
1876 | == inst.reloc.exp.X_add_symbol) | |
1877 | && (pool->literals[entry].X_op_symbol | |
1878 | == inst.reloc.exp.X_op_symbol)) | |
1879 | break; | |
b99bd4ef NC |
1880 | } |
1881 | ||
c19d1205 ZW |
1882 | /* Do we need to create a new entry? */ |
1883 | if (entry == pool->next_free_entry) | |
1884 | { | |
1885 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
1886 | { | |
1887 | inst.error = _("literal pool overflow"); | |
1888 | return FAIL; | |
1889 | } | |
1890 | ||
1891 | pool->literals[entry] = inst.reloc.exp; | |
1892 | pool->next_free_entry += 1; | |
1893 | } | |
b99bd4ef | 1894 | |
c19d1205 ZW |
1895 | inst.reloc.exp.X_op = O_symbol; |
1896 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
1897 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 1898 | |
c19d1205 | 1899 | return SUCCESS; |
b99bd4ef NC |
1900 | } |
1901 | ||
c19d1205 ZW |
1902 | /* Can't use symbol_new here, so have to create a symbol and then at |
1903 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 1904 | |
c19d1205 ZW |
1905 | static void |
1906 | symbol_locate (symbolS * symbolP, | |
1907 | const char * name, /* It is copied, the caller can modify. */ | |
1908 | segT segment, /* Segment identifier (SEG_<something>). */ | |
1909 | valueT valu, /* Symbol value. */ | |
1910 | fragS * frag) /* Associated fragment. */ | |
1911 | { | |
1912 | unsigned int name_length; | |
1913 | char * preserved_copy_of_name; | |
e16bb312 | 1914 | |
c19d1205 ZW |
1915 | name_length = strlen (name) + 1; /* +1 for \0. */ |
1916 | obstack_grow (¬es, name, name_length); | |
1917 | preserved_copy_of_name = obstack_finish (¬es); | |
e16bb312 | 1918 | |
c19d1205 ZW |
1919 | #ifdef tc_canonicalize_symbol_name |
1920 | preserved_copy_of_name = | |
1921 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
1922 | #endif | |
b99bd4ef | 1923 | |
c19d1205 | 1924 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 1925 | |
c19d1205 ZW |
1926 | S_SET_SEGMENT (symbolP, segment); |
1927 | S_SET_VALUE (symbolP, valu); | |
1928 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 1929 | |
c19d1205 | 1930 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 1931 | |
c19d1205 ZW |
1932 | /* Link to end of symbol chain. */ |
1933 | { | |
1934 | extern int symbol_table_frozen; | |
b99bd4ef | 1935 | |
c19d1205 ZW |
1936 | if (symbol_table_frozen) |
1937 | abort (); | |
1938 | } | |
b99bd4ef | 1939 | |
c19d1205 | 1940 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 1941 | |
c19d1205 | 1942 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 1943 | |
c19d1205 ZW |
1944 | #ifdef tc_symbol_new_hook |
1945 | tc_symbol_new_hook (symbolP); | |
1946 | #endif | |
1947 | ||
1948 | #ifdef DEBUG_SYMS | |
1949 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
1950 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
1951 | } |
1952 | ||
b99bd4ef | 1953 | |
c19d1205 ZW |
1954 | static void |
1955 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 1956 | { |
c19d1205 ZW |
1957 | unsigned int entry; |
1958 | literal_pool * pool; | |
1959 | char sym_name[20]; | |
b99bd4ef | 1960 | |
c19d1205 ZW |
1961 | pool = find_literal_pool (); |
1962 | if (pool == NULL | |
1963 | || pool->symbol == NULL | |
1964 | || pool->next_free_entry == 0) | |
1965 | return; | |
b99bd4ef | 1966 | |
c19d1205 | 1967 | mapping_state (MAP_DATA); |
b99bd4ef | 1968 | |
c19d1205 ZW |
1969 | /* Align pool as you have word accesses. |
1970 | Only make a frag if we have to. */ | |
1971 | if (!need_pass_2) | |
1972 | frag_align (2, 0, 0); | |
b99bd4ef | 1973 | |
c19d1205 | 1974 | record_alignment (now_seg, 2); |
b99bd4ef | 1975 | |
c19d1205 | 1976 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 1977 | |
c19d1205 ZW |
1978 | symbol_locate (pool->symbol, sym_name, now_seg, |
1979 | (valueT) frag_now_fix (), frag_now); | |
1980 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 1981 | |
c19d1205 | 1982 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 1983 | |
c19d1205 ZW |
1984 | #if defined OBJ_COFF || defined OBJ_ELF |
1985 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
1986 | #endif | |
6c43fab6 | 1987 | |
c19d1205 ZW |
1988 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
1989 | /* First output the expression in the instruction to the pool. */ | |
1990 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 1991 | |
c19d1205 ZW |
1992 | /* Mark the pool as empty. */ |
1993 | pool->next_free_entry = 0; | |
1994 | pool->symbol = NULL; | |
b99bd4ef NC |
1995 | } |
1996 | ||
c19d1205 ZW |
1997 | #ifdef OBJ_ELF |
1998 | /* Forward declarations for functions below, in the MD interface | |
1999 | section. */ | |
2000 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
2001 | static valueT create_unwind_entry (int); | |
2002 | static void start_unwind_section (const segT, int); | |
2003 | static void add_unwind_opcode (valueT, int); | |
2004 | static void flush_pending_unwind (void); | |
b99bd4ef | 2005 | |
c19d1205 | 2006 | /* Directives: Data. */ |
b99bd4ef | 2007 | |
c19d1205 ZW |
2008 | static void |
2009 | s_arm_elf_cons (int nbytes) | |
2010 | { | |
2011 | expressionS exp; | |
b99bd4ef | 2012 | |
c19d1205 ZW |
2013 | #ifdef md_flush_pending_output |
2014 | md_flush_pending_output (); | |
2015 | #endif | |
b99bd4ef | 2016 | |
c19d1205 | 2017 | if (is_it_end_of_statement ()) |
b99bd4ef | 2018 | { |
c19d1205 ZW |
2019 | demand_empty_rest_of_line (); |
2020 | return; | |
b99bd4ef NC |
2021 | } |
2022 | ||
c19d1205 ZW |
2023 | #ifdef md_cons_align |
2024 | md_cons_align (nbytes); | |
2025 | #endif | |
b99bd4ef | 2026 | |
c19d1205 ZW |
2027 | mapping_state (MAP_DATA); |
2028 | do | |
b99bd4ef | 2029 | { |
c19d1205 ZW |
2030 | int reloc; |
2031 | char *base = input_line_pointer; | |
b99bd4ef | 2032 | |
c19d1205 | 2033 | expression (& exp); |
b99bd4ef | 2034 | |
c19d1205 ZW |
2035 | if (exp.X_op != O_symbol) |
2036 | emit_expr (&exp, (unsigned int) nbytes); | |
2037 | else | |
2038 | { | |
2039 | char *before_reloc = input_line_pointer; | |
2040 | reloc = parse_reloc (&input_line_pointer); | |
2041 | if (reloc == -1) | |
2042 | { | |
2043 | as_bad (_("unrecognized relocation suffix")); | |
2044 | ignore_rest_of_line (); | |
2045 | return; | |
2046 | } | |
2047 | else if (reloc == BFD_RELOC_UNUSED) | |
2048 | emit_expr (&exp, (unsigned int) nbytes); | |
2049 | else | |
2050 | { | |
2051 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
2052 | int size = bfd_get_reloc_size (howto); | |
b99bd4ef | 2053 | |
2fc8bdac ZW |
2054 | if (reloc == BFD_RELOC_ARM_PLT32) |
2055 | { | |
2056 | as_bad (_("(plt) is only valid on branch targets")); | |
2057 | reloc = BFD_RELOC_UNUSED; | |
2058 | size = 0; | |
2059 | } | |
2060 | ||
c19d1205 | 2061 | if (size > nbytes) |
2fc8bdac | 2062 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
2063 | howto->name, nbytes); |
2064 | else | |
2065 | { | |
2066 | /* We've parsed an expression stopping at O_symbol. | |
2067 | But there may be more expression left now that we | |
2068 | have parsed the relocation marker. Parse it again. | |
2069 | XXX Surely there is a cleaner way to do this. */ | |
2070 | char *p = input_line_pointer; | |
2071 | int offset; | |
2072 | char *save_buf = alloca (input_line_pointer - base); | |
2073 | memcpy (save_buf, base, input_line_pointer - base); | |
2074 | memmove (base + (input_line_pointer - before_reloc), | |
2075 | base, before_reloc - base); | |
2076 | ||
2077 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
2078 | expression (&exp); | |
2079 | memcpy (base, save_buf, p - base); | |
2080 | ||
2081 | offset = nbytes - size; | |
2082 | p = frag_more ((int) nbytes); | |
2083 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
2084 | size, &exp, 0, reloc); | |
2085 | } | |
2086 | } | |
2087 | } | |
b99bd4ef | 2088 | } |
c19d1205 | 2089 | while (*input_line_pointer++ == ','); |
b99bd4ef | 2090 | |
c19d1205 ZW |
2091 | /* Put terminator back into stream. */ |
2092 | input_line_pointer --; | |
2093 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
2094 | } |
2095 | ||
b99bd4ef | 2096 | |
c19d1205 | 2097 | /* Parse a .rel31 directive. */ |
b99bd4ef | 2098 | |
c19d1205 ZW |
2099 | static void |
2100 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
2101 | { | |
2102 | expressionS exp; | |
2103 | char *p; | |
2104 | valueT highbit; | |
b99bd4ef | 2105 | |
c19d1205 ZW |
2106 | highbit = 0; |
2107 | if (*input_line_pointer == '1') | |
2108 | highbit = 0x80000000; | |
2109 | else if (*input_line_pointer != '0') | |
2110 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 2111 | |
c19d1205 ZW |
2112 | input_line_pointer++; |
2113 | if (*input_line_pointer != ',') | |
2114 | as_bad (_("missing comma")); | |
2115 | input_line_pointer++; | |
b99bd4ef | 2116 | |
c19d1205 ZW |
2117 | #ifdef md_flush_pending_output |
2118 | md_flush_pending_output (); | |
2119 | #endif | |
b99bd4ef | 2120 | |
c19d1205 ZW |
2121 | #ifdef md_cons_align |
2122 | md_cons_align (4); | |
2123 | #endif | |
b99bd4ef | 2124 | |
c19d1205 | 2125 | mapping_state (MAP_DATA); |
b99bd4ef | 2126 | |
c19d1205 | 2127 | expression (&exp); |
b99bd4ef | 2128 | |
c19d1205 ZW |
2129 | p = frag_more (4); |
2130 | md_number_to_chars (p, highbit, 4); | |
2131 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
2132 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 2133 | |
c19d1205 | 2134 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2135 | } |
2136 | ||
c19d1205 | 2137 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 2138 | |
c19d1205 | 2139 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 2140 | |
c19d1205 ZW |
2141 | static void |
2142 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
2143 | { | |
2144 | demand_empty_rest_of_line (); | |
2145 | /* Mark the start of the function. */ | |
2146 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 2147 | |
c19d1205 ZW |
2148 | /* Reset the rest of the unwind info. */ |
2149 | unwind.opcode_count = 0; | |
2150 | unwind.table_entry = NULL; | |
2151 | unwind.personality_routine = NULL; | |
2152 | unwind.personality_index = -1; | |
2153 | unwind.frame_size = 0; | |
2154 | unwind.fp_offset = 0; | |
2155 | unwind.fp_reg = 13; | |
2156 | unwind.fp_used = 0; | |
2157 | unwind.sp_restored = 0; | |
2158 | } | |
b99bd4ef | 2159 | |
b99bd4ef | 2160 | |
c19d1205 ZW |
2161 | /* Parse a handlerdata directive. Creates the exception handling table entry |
2162 | for the function. */ | |
b99bd4ef | 2163 | |
c19d1205 ZW |
2164 | static void |
2165 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
2166 | { | |
2167 | demand_empty_rest_of_line (); | |
2168 | if (unwind.table_entry) | |
2169 | as_bad (_("dupicate .handlerdata directive")); | |
f02232aa | 2170 | |
c19d1205 ZW |
2171 | create_unwind_entry (1); |
2172 | } | |
a737bd4d | 2173 | |
c19d1205 | 2174 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 2175 | |
c19d1205 ZW |
2176 | static void |
2177 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
2178 | { | |
2179 | long where; | |
2180 | char *ptr; | |
2181 | valueT val; | |
f02232aa | 2182 | |
c19d1205 | 2183 | demand_empty_rest_of_line (); |
f02232aa | 2184 | |
c19d1205 ZW |
2185 | /* Add eh table entry. */ |
2186 | if (unwind.table_entry == NULL) | |
2187 | val = create_unwind_entry (0); | |
2188 | else | |
2189 | val = 0; | |
f02232aa | 2190 | |
c19d1205 ZW |
2191 | /* Add index table entry. This is two words. */ |
2192 | start_unwind_section (unwind.saved_seg, 1); | |
2193 | frag_align (2, 0, 0); | |
2194 | record_alignment (now_seg, 2); | |
b99bd4ef | 2195 | |
c19d1205 ZW |
2196 | ptr = frag_more (8); |
2197 | where = frag_now_fix () - 8; | |
f02232aa | 2198 | |
c19d1205 ZW |
2199 | /* Self relative offset of the function start. */ |
2200 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
2201 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 2202 | |
c19d1205 ZW |
2203 | /* Indicate dependency on EHABI-defined personality routines to the |
2204 | linker, if it hasn't been done already. */ | |
2205 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 | |
2206 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
2207 | { | |
2208 | static const char *const name[] = { | |
2209 | "__aeabi_unwind_cpp_pr0", | |
2210 | "__aeabi_unwind_cpp_pr1", | |
2211 | "__aeabi_unwind_cpp_pr2" | |
2212 | }; | |
2213 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); | |
2214 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
2215 | marked_pr_dependency |= 1 << unwind.personality_index; | |
2216 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency | |
2217 | = marked_pr_dependency; | |
2218 | } | |
f02232aa | 2219 | |
c19d1205 ZW |
2220 | if (val) |
2221 | /* Inline exception table entry. */ | |
2222 | md_number_to_chars (ptr + 4, val, 4); | |
2223 | else | |
2224 | /* Self relative offset of the table entry. */ | |
2225 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
2226 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 2227 | |
c19d1205 ZW |
2228 | /* Restore the original section. */ |
2229 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
2230 | } | |
f02232aa | 2231 | |
f02232aa | 2232 | |
c19d1205 | 2233 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 2234 | |
c19d1205 ZW |
2235 | static void |
2236 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
2237 | { | |
2238 | demand_empty_rest_of_line (); | |
2239 | if (unwind.personality_routine || unwind.personality_index != -1) | |
2240 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 2241 | |
c19d1205 ZW |
2242 | unwind.personality_index = -2; |
2243 | } | |
b99bd4ef | 2244 | |
b99bd4ef | 2245 | |
c19d1205 | 2246 | /* Parse a personalityindex directive. */ |
b99bd4ef | 2247 | |
c19d1205 ZW |
2248 | static void |
2249 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
2250 | { | |
2251 | expressionS exp; | |
b99bd4ef | 2252 | |
c19d1205 ZW |
2253 | if (unwind.personality_routine || unwind.personality_index != -1) |
2254 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 2255 | |
c19d1205 | 2256 | expression (&exp); |
b99bd4ef | 2257 | |
c19d1205 ZW |
2258 | if (exp.X_op != O_constant |
2259 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 2260 | { |
c19d1205 ZW |
2261 | as_bad (_("bad personality routine number")); |
2262 | ignore_rest_of_line (); | |
2263 | return; | |
b99bd4ef NC |
2264 | } |
2265 | ||
c19d1205 | 2266 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 2267 | |
c19d1205 ZW |
2268 | demand_empty_rest_of_line (); |
2269 | } | |
e16bb312 | 2270 | |
e16bb312 | 2271 | |
c19d1205 | 2272 | /* Parse a personality directive. */ |
e16bb312 | 2273 | |
c19d1205 ZW |
2274 | static void |
2275 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
2276 | { | |
2277 | char *name, *p, c; | |
a737bd4d | 2278 | |
c19d1205 ZW |
2279 | if (unwind.personality_routine || unwind.personality_index != -1) |
2280 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 2281 | |
c19d1205 ZW |
2282 | name = input_line_pointer; |
2283 | c = get_symbol_end (); | |
2284 | p = input_line_pointer; | |
2285 | unwind.personality_routine = symbol_find_or_make (name); | |
2286 | *p = c; | |
2287 | demand_empty_rest_of_line (); | |
2288 | } | |
e16bb312 | 2289 | |
e16bb312 | 2290 | |
c19d1205 | 2291 | /* Parse a directive saving core registers. */ |
e16bb312 | 2292 | |
c19d1205 ZW |
2293 | static void |
2294 | s_arm_unwind_save_core (void) | |
e16bb312 | 2295 | { |
c19d1205 ZW |
2296 | valueT op; |
2297 | long range; | |
2298 | int n; | |
e16bb312 | 2299 | |
c19d1205 ZW |
2300 | range = parse_reg_list (&input_line_pointer); |
2301 | if (range == FAIL) | |
e16bb312 | 2302 | { |
c19d1205 ZW |
2303 | as_bad (_("expected register list")); |
2304 | ignore_rest_of_line (); | |
2305 | return; | |
2306 | } | |
e16bb312 | 2307 | |
c19d1205 | 2308 | demand_empty_rest_of_line (); |
e16bb312 | 2309 | |
c19d1205 ZW |
2310 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
2311 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
2312 | ip because it is clobbered by calls. */ | |
2313 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
2314 | && (range & 0x3000) == 0x1000) | |
2315 | { | |
2316 | unwind.opcode_count--; | |
2317 | unwind.sp_restored = 0; | |
2318 | range = (range | 0x2000) & ~0x1000; | |
2319 | unwind.pending_offset = 0; | |
2320 | } | |
e16bb312 | 2321 | |
01ae4198 DJ |
2322 | /* Pop r4-r15. */ |
2323 | if (range & 0xfff0) | |
c19d1205 | 2324 | { |
01ae4198 DJ |
2325 | /* See if we can use the short opcodes. These pop a block of up to 8 |
2326 | registers starting with r4, plus maybe r14. */ | |
2327 | for (n = 0; n < 8; n++) | |
2328 | { | |
2329 | /* Break at the first non-saved register. */ | |
2330 | if ((range & (1 << (n + 4))) == 0) | |
2331 | break; | |
2332 | } | |
2333 | /* See if there are any other bits set. */ | |
2334 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
2335 | { | |
2336 | /* Use the long form. */ | |
2337 | op = 0x8000 | ((range >> 4) & 0xfff); | |
2338 | add_unwind_opcode (op, 2); | |
2339 | } | |
0dd132b6 | 2340 | else |
01ae4198 DJ |
2341 | { |
2342 | /* Use the short form. */ | |
2343 | if (range & 0x4000) | |
2344 | op = 0xa8; /* Pop r14. */ | |
2345 | else | |
2346 | op = 0xa0; /* Do not pop r14. */ | |
2347 | op |= (n - 1); | |
2348 | add_unwind_opcode (op, 1); | |
2349 | } | |
c19d1205 | 2350 | } |
0dd132b6 | 2351 | |
c19d1205 ZW |
2352 | /* Pop r0-r3. */ |
2353 | if (range & 0xf) | |
2354 | { | |
2355 | op = 0xb100 | (range & 0xf); | |
2356 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
2357 | } |
2358 | ||
c19d1205 ZW |
2359 | /* Record the number of bytes pushed. */ |
2360 | for (n = 0; n < 16; n++) | |
2361 | { | |
2362 | if (range & (1 << n)) | |
2363 | unwind.frame_size += 4; | |
2364 | } | |
0dd132b6 NC |
2365 | } |
2366 | ||
c19d1205 ZW |
2367 | |
2368 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
2369 | |
2370 | static void | |
c19d1205 | 2371 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 2372 | { |
c19d1205 ZW |
2373 | expressionS exp; |
2374 | int num_regs; | |
2375 | valueT op; | |
b99bd4ef | 2376 | |
c19d1205 ZW |
2377 | /* Get Number of registers to transfer. */ |
2378 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
2379 | expression (&exp); | |
2380 | else | |
2381 | exp.X_op = O_illegal; | |
b99bd4ef | 2382 | |
c19d1205 | 2383 | if (exp.X_op != O_constant) |
b99bd4ef | 2384 | { |
c19d1205 ZW |
2385 | as_bad (_("expected , <constant>")); |
2386 | ignore_rest_of_line (); | |
b99bd4ef NC |
2387 | return; |
2388 | } | |
2389 | ||
c19d1205 ZW |
2390 | num_regs = exp.X_add_number; |
2391 | ||
2392 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 2393 | { |
c19d1205 ZW |
2394 | as_bad (_("number of registers must be in the range [1:4]")); |
2395 | ignore_rest_of_line (); | |
b99bd4ef NC |
2396 | return; |
2397 | } | |
2398 | ||
c19d1205 | 2399 | demand_empty_rest_of_line (); |
b99bd4ef | 2400 | |
c19d1205 ZW |
2401 | if (reg == 4) |
2402 | { | |
2403 | /* Short form. */ | |
2404 | op = 0xb4 | (num_regs - 1); | |
2405 | add_unwind_opcode (op, 1); | |
2406 | } | |
b99bd4ef NC |
2407 | else |
2408 | { | |
c19d1205 ZW |
2409 | /* Long form. */ |
2410 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
2411 | add_unwind_opcode (op, 2); | |
b99bd4ef | 2412 | } |
c19d1205 | 2413 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
2414 | } |
2415 | ||
c19d1205 ZW |
2416 | |
2417 | /* Parse a directive saving VFP registers. */ | |
b99bd4ef NC |
2418 | |
2419 | static void | |
c19d1205 | 2420 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 2421 | { |
c19d1205 | 2422 | int count; |
ca3f61f7 | 2423 | unsigned int reg; |
c19d1205 | 2424 | valueT op; |
b99bd4ef | 2425 | |
c19d1205 ZW |
2426 | count = parse_vfp_reg_list (&input_line_pointer, ®, 1); |
2427 | if (count == FAIL) | |
b99bd4ef | 2428 | { |
c19d1205 ZW |
2429 | as_bad (_("expected register list")); |
2430 | ignore_rest_of_line (); | |
b99bd4ef NC |
2431 | return; |
2432 | } | |
2433 | ||
c19d1205 | 2434 | demand_empty_rest_of_line (); |
b99bd4ef | 2435 | |
c19d1205 | 2436 | if (reg == 8) |
b99bd4ef | 2437 | { |
c19d1205 ZW |
2438 | /* Short form. */ |
2439 | op = 0xb8 | (count - 1); | |
2440 | add_unwind_opcode (op, 1); | |
b99bd4ef | 2441 | } |
c19d1205 | 2442 | else |
b99bd4ef | 2443 | { |
c19d1205 ZW |
2444 | /* Long form. */ |
2445 | op = 0xb300 | (reg << 4) | (count - 1); | |
2446 | add_unwind_opcode (op, 2); | |
b99bd4ef | 2447 | } |
c19d1205 ZW |
2448 | unwind.frame_size += count * 8 + 4; |
2449 | } | |
b99bd4ef | 2450 | |
b99bd4ef | 2451 | |
c19d1205 ZW |
2452 | /* Parse a directive saving iWMMXt data registers. */ |
2453 | ||
2454 | static void | |
2455 | s_arm_unwind_save_mmxwr (void) | |
2456 | { | |
2457 | int reg; | |
2458 | int hi_reg; | |
2459 | int i; | |
2460 | unsigned mask = 0; | |
2461 | valueT op; | |
b99bd4ef | 2462 | |
c19d1205 ZW |
2463 | if (*input_line_pointer == '{') |
2464 | input_line_pointer++; | |
b99bd4ef | 2465 | |
c19d1205 | 2466 | do |
b99bd4ef | 2467 | { |
c19d1205 | 2468 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 2469 | |
c19d1205 | 2470 | if (reg == FAIL) |
b99bd4ef | 2471 | { |
c19d1205 ZW |
2472 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); |
2473 | goto error; | |
b99bd4ef NC |
2474 | } |
2475 | ||
c19d1205 ZW |
2476 | if (mask >> reg) |
2477 | as_tsktsk (_("register list not in ascending order")); | |
2478 | mask |= 1 << reg; | |
b99bd4ef | 2479 | |
c19d1205 ZW |
2480 | if (*input_line_pointer == '-') |
2481 | { | |
2482 | input_line_pointer++; | |
2483 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); | |
2484 | if (hi_reg == FAIL) | |
2485 | { | |
2486 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); | |
2487 | goto error; | |
2488 | } | |
2489 | else if (reg >= hi_reg) | |
2490 | { | |
2491 | as_bad (_("bad register range")); | |
2492 | goto error; | |
2493 | } | |
2494 | for (; reg < hi_reg; reg++) | |
2495 | mask |= 1 << reg; | |
2496 | } | |
2497 | } | |
2498 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 2499 | |
c19d1205 ZW |
2500 | if (*input_line_pointer == '}') |
2501 | input_line_pointer++; | |
b99bd4ef | 2502 | |
c19d1205 | 2503 | demand_empty_rest_of_line (); |
b99bd4ef | 2504 | |
c19d1205 ZW |
2505 | /* Generate any deferred opcodes becuuse we're going to be looking at |
2506 | the list. */ | |
2507 | flush_pending_unwind (); | |
b99bd4ef | 2508 | |
c19d1205 | 2509 | for (i = 0; i < 16; i++) |
b99bd4ef | 2510 | { |
c19d1205 ZW |
2511 | if (mask & (1 << i)) |
2512 | unwind.frame_size += 8; | |
b99bd4ef NC |
2513 | } |
2514 | ||
c19d1205 ZW |
2515 | /* Attempt to combine with a previous opcode. We do this because gcc |
2516 | likes to output separate unwind directives for a single block of | |
2517 | registers. */ | |
2518 | if (unwind.opcode_count > 0) | |
b99bd4ef | 2519 | { |
c19d1205 ZW |
2520 | i = unwind.opcodes[unwind.opcode_count - 1]; |
2521 | if ((i & 0xf8) == 0xc0) | |
2522 | { | |
2523 | i &= 7; | |
2524 | /* Only merge if the blocks are contiguous. */ | |
2525 | if (i < 6) | |
2526 | { | |
2527 | if ((mask & 0xfe00) == (1 << 9)) | |
2528 | { | |
2529 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
2530 | unwind.opcode_count--; | |
2531 | } | |
2532 | } | |
2533 | else if (i == 6 && unwind.opcode_count >= 2) | |
2534 | { | |
2535 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
2536 | reg = i >> 4; | |
2537 | i &= 0xf; | |
b99bd4ef | 2538 | |
c19d1205 ZW |
2539 | op = 0xffff << (reg - 1); |
2540 | if (reg > 0 | |
2541 | || ((mask & op) == (1u << (reg - 1)))) | |
2542 | { | |
2543 | op = (1 << (reg + i + 1)) - 1; | |
2544 | op &= ~((1 << reg) - 1); | |
2545 | mask |= op; | |
2546 | unwind.opcode_count -= 2; | |
2547 | } | |
2548 | } | |
2549 | } | |
b99bd4ef NC |
2550 | } |
2551 | ||
c19d1205 ZW |
2552 | hi_reg = 15; |
2553 | /* We want to generate opcodes in the order the registers have been | |
2554 | saved, ie. descending order. */ | |
2555 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 2556 | { |
c19d1205 ZW |
2557 | /* Save registers in blocks. */ |
2558 | if (reg < 0 | |
2559 | || !(mask & (1 << reg))) | |
2560 | { | |
2561 | /* We found an unsaved reg. Generate opcodes to save the | |
2562 | preceeding block. */ | |
2563 | if (reg != hi_reg) | |
2564 | { | |
2565 | if (reg == 9) | |
2566 | { | |
2567 | /* Short form. */ | |
2568 | op = 0xc0 | (hi_reg - 10); | |
2569 | add_unwind_opcode (op, 1); | |
2570 | } | |
2571 | else | |
2572 | { | |
2573 | /* Long form. */ | |
2574 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
2575 | add_unwind_opcode (op, 2); | |
2576 | } | |
2577 | } | |
2578 | hi_reg = reg - 1; | |
2579 | } | |
b99bd4ef NC |
2580 | } |
2581 | ||
c19d1205 ZW |
2582 | return; |
2583 | error: | |
2584 | ignore_rest_of_line (); | |
b99bd4ef NC |
2585 | } |
2586 | ||
2587 | static void | |
c19d1205 | 2588 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 2589 | { |
c19d1205 ZW |
2590 | int reg; |
2591 | int hi_reg; | |
2592 | unsigned mask = 0; | |
2593 | valueT op; | |
b99bd4ef | 2594 | |
c19d1205 ZW |
2595 | if (*input_line_pointer == '{') |
2596 | input_line_pointer++; | |
b99bd4ef | 2597 | |
c19d1205 | 2598 | do |
b99bd4ef | 2599 | { |
c19d1205 | 2600 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 2601 | |
c19d1205 ZW |
2602 | if (reg == FAIL) |
2603 | { | |
2604 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
2605 | goto error; | |
2606 | } | |
b99bd4ef | 2607 | |
c19d1205 ZW |
2608 | reg -= 8; |
2609 | if (mask >> reg) | |
2610 | as_tsktsk (_("register list not in ascending order")); | |
2611 | mask |= 1 << reg; | |
b99bd4ef | 2612 | |
c19d1205 ZW |
2613 | if (*input_line_pointer == '-') |
2614 | { | |
2615 | input_line_pointer++; | |
2616 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); | |
2617 | if (hi_reg == FAIL) | |
2618 | { | |
2619 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
2620 | goto error; | |
2621 | } | |
2622 | else if (reg >= hi_reg) | |
2623 | { | |
2624 | as_bad (_("bad register range")); | |
2625 | goto error; | |
2626 | } | |
2627 | for (; reg < hi_reg; reg++) | |
2628 | mask |= 1 << reg; | |
2629 | } | |
b99bd4ef | 2630 | } |
c19d1205 | 2631 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 2632 | |
c19d1205 ZW |
2633 | if (*input_line_pointer == '}') |
2634 | input_line_pointer++; | |
b99bd4ef | 2635 | |
c19d1205 ZW |
2636 | demand_empty_rest_of_line (); |
2637 | ||
2638 | /* Generate any deferred opcodes becuuse we're going to be looking at | |
2639 | the list. */ | |
2640 | flush_pending_unwind (); | |
b99bd4ef | 2641 | |
c19d1205 | 2642 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 2643 | { |
c19d1205 ZW |
2644 | if (mask & (1 << reg)) |
2645 | unwind.frame_size += 4; | |
b99bd4ef | 2646 | } |
c19d1205 ZW |
2647 | op = 0xc700 | mask; |
2648 | add_unwind_opcode (op, 2); | |
2649 | return; | |
2650 | error: | |
2651 | ignore_rest_of_line (); | |
b99bd4ef NC |
2652 | } |
2653 | ||
c19d1205 ZW |
2654 | |
2655 | /* Parse an unwind_save directive. */ | |
2656 | ||
b99bd4ef | 2657 | static void |
c19d1205 | 2658 | s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED) |
b99bd4ef | 2659 | { |
c19d1205 ZW |
2660 | char *peek; |
2661 | struct reg_entry *reg; | |
2662 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 2663 | |
c19d1205 ZW |
2664 | /* Figure out what sort of save we have. */ |
2665 | peek = input_line_pointer; | |
b99bd4ef | 2666 | |
c19d1205 | 2667 | if (*peek == '{') |
b99bd4ef | 2668 | { |
c19d1205 ZW |
2669 | had_brace = TRUE; |
2670 | peek++; | |
b99bd4ef NC |
2671 | } |
2672 | ||
c19d1205 | 2673 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 2674 | |
c19d1205 | 2675 | if (!reg) |
b99bd4ef | 2676 | { |
c19d1205 ZW |
2677 | as_bad (_("register expected")); |
2678 | ignore_rest_of_line (); | |
b99bd4ef NC |
2679 | return; |
2680 | } | |
2681 | ||
c19d1205 | 2682 | switch (reg->type) |
b99bd4ef | 2683 | { |
c19d1205 ZW |
2684 | case REG_TYPE_FN: |
2685 | if (had_brace) | |
2686 | { | |
2687 | as_bad (_("FPA .unwind_save does not take a register list")); | |
2688 | ignore_rest_of_line (); | |
2689 | return; | |
2690 | } | |
2691 | s_arm_unwind_save_fpa (reg->number); | |
b99bd4ef | 2692 | return; |
c19d1205 ZW |
2693 | |
2694 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
2695 | case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return; | |
2696 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; | |
2697 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
2698 | ||
2699 | default: | |
2700 | as_bad (_(".unwind_save does not support this kind of register")); | |
2701 | ignore_rest_of_line (); | |
b99bd4ef | 2702 | } |
c19d1205 | 2703 | } |
b99bd4ef | 2704 | |
b99bd4ef | 2705 | |
c19d1205 ZW |
2706 | /* Parse an unwind_movsp directive. */ |
2707 | ||
2708 | static void | |
2709 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
2710 | { | |
2711 | int reg; | |
2712 | valueT op; | |
2713 | ||
2714 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); | |
2715 | if (reg == FAIL) | |
b99bd4ef | 2716 | { |
c19d1205 ZW |
2717 | as_bad (_(reg_expected_msgs[REG_TYPE_RN])); |
2718 | ignore_rest_of_line (); | |
b99bd4ef NC |
2719 | return; |
2720 | } | |
c19d1205 | 2721 | demand_empty_rest_of_line (); |
b99bd4ef | 2722 | |
c19d1205 | 2723 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 2724 | { |
c19d1205 | 2725 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
2726 | return; |
2727 | } | |
2728 | ||
c19d1205 ZW |
2729 | if (unwind.fp_reg != REG_SP) |
2730 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 2731 | |
c19d1205 ZW |
2732 | /* Generate opcode to restore the value. */ |
2733 | op = 0x90 | reg; | |
2734 | add_unwind_opcode (op, 1); | |
2735 | ||
2736 | /* Record the information for later. */ | |
2737 | unwind.fp_reg = reg; | |
2738 | unwind.fp_offset = unwind.frame_size; | |
2739 | unwind.sp_restored = 1; | |
b05fe5cf ZW |
2740 | } |
2741 | ||
c19d1205 ZW |
2742 | /* Parse an unwind_pad directive. */ |
2743 | ||
b05fe5cf | 2744 | static void |
c19d1205 | 2745 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 2746 | { |
c19d1205 | 2747 | int offset; |
b05fe5cf | 2748 | |
c19d1205 ZW |
2749 | if (immediate_for_directive (&offset) == FAIL) |
2750 | return; | |
b99bd4ef | 2751 | |
c19d1205 ZW |
2752 | if (offset & 3) |
2753 | { | |
2754 | as_bad (_("stack increment must be multiple of 4")); | |
2755 | ignore_rest_of_line (); | |
2756 | return; | |
2757 | } | |
b99bd4ef | 2758 | |
c19d1205 ZW |
2759 | /* Don't generate any opcodes, just record the details for later. */ |
2760 | unwind.frame_size += offset; | |
2761 | unwind.pending_offset += offset; | |
2762 | ||
2763 | demand_empty_rest_of_line (); | |
2764 | } | |
2765 | ||
2766 | /* Parse an unwind_setfp directive. */ | |
2767 | ||
2768 | static void | |
2769 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 2770 | { |
c19d1205 ZW |
2771 | int sp_reg; |
2772 | int fp_reg; | |
2773 | int offset; | |
2774 | ||
2775 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); | |
2776 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
2777 | sp_reg = FAIL; | |
2778 | else | |
2779 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); | |
b99bd4ef | 2780 | |
c19d1205 ZW |
2781 | if (fp_reg == FAIL || sp_reg == FAIL) |
2782 | { | |
2783 | as_bad (_("expected <reg>, <reg>")); | |
2784 | ignore_rest_of_line (); | |
2785 | return; | |
2786 | } | |
b99bd4ef | 2787 | |
c19d1205 ZW |
2788 | /* Optional constant. */ |
2789 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
2790 | { | |
2791 | if (immediate_for_directive (&offset) == FAIL) | |
2792 | return; | |
2793 | } | |
2794 | else | |
2795 | offset = 0; | |
a737bd4d | 2796 | |
c19d1205 | 2797 | demand_empty_rest_of_line (); |
a737bd4d | 2798 | |
c19d1205 | 2799 | if (sp_reg != 13 && sp_reg != unwind.fp_reg) |
a737bd4d | 2800 | { |
c19d1205 ZW |
2801 | as_bad (_("register must be either sp or set by a previous" |
2802 | "unwind_movsp directive")); | |
2803 | return; | |
a737bd4d NC |
2804 | } |
2805 | ||
c19d1205 ZW |
2806 | /* Don't generate any opcodes, just record the information for later. */ |
2807 | unwind.fp_reg = fp_reg; | |
2808 | unwind.fp_used = 1; | |
2809 | if (sp_reg == 13) | |
2810 | unwind.fp_offset = unwind.frame_size - offset; | |
2811 | else | |
2812 | unwind.fp_offset -= offset; | |
a737bd4d NC |
2813 | } |
2814 | ||
c19d1205 ZW |
2815 | /* Parse an unwind_raw directive. */ |
2816 | ||
2817 | static void | |
2818 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 2819 | { |
c19d1205 ZW |
2820 | expressionS exp; |
2821 | /* This is an arbitary limit. */ | |
2822 | unsigned char op[16]; | |
2823 | int count; | |
a737bd4d | 2824 | |
c19d1205 ZW |
2825 | expression (&exp); |
2826 | if (exp.X_op == O_constant | |
2827 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 2828 | { |
c19d1205 ZW |
2829 | unwind.frame_size += exp.X_add_number; |
2830 | expression (&exp); | |
2831 | } | |
2832 | else | |
2833 | exp.X_op = O_illegal; | |
a737bd4d | 2834 | |
c19d1205 ZW |
2835 | if (exp.X_op != O_constant) |
2836 | { | |
2837 | as_bad (_("expected <offset>, <opcode>")); | |
2838 | ignore_rest_of_line (); | |
2839 | return; | |
2840 | } | |
a737bd4d | 2841 | |
c19d1205 | 2842 | count = 0; |
a737bd4d | 2843 | |
c19d1205 ZW |
2844 | /* Parse the opcode. */ |
2845 | for (;;) | |
2846 | { | |
2847 | if (count >= 16) | |
2848 | { | |
2849 | as_bad (_("unwind opcode too long")); | |
2850 | ignore_rest_of_line (); | |
a737bd4d | 2851 | } |
c19d1205 | 2852 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 2853 | { |
c19d1205 ZW |
2854 | as_bad (_("invalid unwind opcode")); |
2855 | ignore_rest_of_line (); | |
2856 | return; | |
a737bd4d | 2857 | } |
c19d1205 | 2858 | op[count++] = exp.X_add_number; |
a737bd4d | 2859 | |
c19d1205 ZW |
2860 | /* Parse the next byte. */ |
2861 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
2862 | break; | |
a737bd4d | 2863 | |
c19d1205 ZW |
2864 | expression (&exp); |
2865 | } | |
b99bd4ef | 2866 | |
c19d1205 ZW |
2867 | /* Add the opcode bytes in reverse order. */ |
2868 | while (count--) | |
2869 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 2870 | |
c19d1205 | 2871 | demand_empty_rest_of_line (); |
b99bd4ef | 2872 | } |
ee065d83 PB |
2873 | |
2874 | ||
2875 | /* Parse a .eabi_attribute directive. */ | |
2876 | ||
2877 | static void | |
2878 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
2879 | { | |
2880 | expressionS exp; | |
2881 | bfd_boolean is_string; | |
2882 | int tag; | |
2883 | unsigned int i = 0; | |
2884 | char *s = NULL; | |
2885 | char saved_char; | |
2886 | ||
2887 | expression (& exp); | |
2888 | if (exp.X_op != O_constant) | |
2889 | goto bad; | |
2890 | ||
2891 | tag = exp.X_add_number; | |
2892 | if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0)) | |
2893 | is_string = 1; | |
2894 | else | |
2895 | is_string = 0; | |
2896 | ||
2897 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
2898 | goto bad; | |
2899 | if (tag == 32 || !is_string) | |
2900 | { | |
2901 | expression (& exp); | |
2902 | if (exp.X_op != O_constant) | |
2903 | { | |
2904 | as_bad (_("expected numeric constant")); | |
2905 | ignore_rest_of_line (); | |
2906 | return; | |
2907 | } | |
2908 | i = exp.X_add_number; | |
2909 | } | |
2910 | if (tag == Tag_compatibility | |
2911 | && skip_past_comma (&input_line_pointer) == FAIL) | |
2912 | { | |
2913 | as_bad (_("expected comma")); | |
2914 | ignore_rest_of_line (); | |
2915 | return; | |
2916 | } | |
2917 | if (is_string) | |
2918 | { | |
2919 | skip_whitespace(input_line_pointer); | |
2920 | if (*input_line_pointer != '"') | |
2921 | goto bad_string; | |
2922 | input_line_pointer++; | |
2923 | s = input_line_pointer; | |
2924 | while (*input_line_pointer && *input_line_pointer != '"') | |
2925 | input_line_pointer++; | |
2926 | if (*input_line_pointer != '"') | |
2927 | goto bad_string; | |
2928 | saved_char = *input_line_pointer; | |
2929 | *input_line_pointer = 0; | |
2930 | } | |
2931 | else | |
2932 | { | |
2933 | s = NULL; | |
2934 | saved_char = 0; | |
2935 | } | |
2936 | ||
2937 | if (tag == Tag_compatibility) | |
2938 | elf32_arm_add_eabi_attr_compat (stdoutput, i, s); | |
2939 | else if (is_string) | |
2940 | elf32_arm_add_eabi_attr_string (stdoutput, tag, s); | |
2941 | else | |
2942 | elf32_arm_add_eabi_attr_int (stdoutput, tag, i); | |
2943 | ||
2944 | if (s) | |
2945 | { | |
2946 | *input_line_pointer = saved_char; | |
2947 | input_line_pointer++; | |
2948 | } | |
2949 | demand_empty_rest_of_line (); | |
2950 | return; | |
2951 | bad_string: | |
2952 | as_bad (_("bad string constant")); | |
2953 | ignore_rest_of_line (); | |
2954 | return; | |
2955 | bad: | |
2956 | as_bad (_("expected <tag> , <value>")); | |
2957 | ignore_rest_of_line (); | |
2958 | } | |
8463be01 | 2959 | #endif /* OBJ_ELF */ |
ee065d83 PB |
2960 | |
2961 | static void s_arm_arch (int); | |
2962 | static void s_arm_cpu (int); | |
2963 | static void s_arm_fpu (int); | |
b99bd4ef | 2964 | |
c19d1205 ZW |
2965 | /* This table describes all the machine specific pseudo-ops the assembler |
2966 | has to support. The fields are: | |
2967 | pseudo-op name without dot | |
2968 | function to call to execute this pseudo-op | |
2969 | Integer arg to pass to the function. */ | |
b99bd4ef | 2970 | |
c19d1205 | 2971 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 2972 | { |
c19d1205 ZW |
2973 | /* Never called because '.req' does not start a line. */ |
2974 | { "req", s_req, 0 }, | |
2975 | { "unreq", s_unreq, 0 }, | |
2976 | { "bss", s_bss, 0 }, | |
2977 | { "align", s_align, 0 }, | |
2978 | { "arm", s_arm, 0 }, | |
2979 | { "thumb", s_thumb, 0 }, | |
2980 | { "code", s_code, 0 }, | |
2981 | { "force_thumb", s_force_thumb, 0 }, | |
2982 | { "thumb_func", s_thumb_func, 0 }, | |
2983 | { "thumb_set", s_thumb_set, 0 }, | |
2984 | { "even", s_even, 0 }, | |
2985 | { "ltorg", s_ltorg, 0 }, | |
2986 | { "pool", s_ltorg, 0 }, | |
2987 | { "syntax", s_syntax, 0 }, | |
8463be01 PB |
2988 | { "cpu", s_arm_cpu, 0 }, |
2989 | { "arch", s_arm_arch, 0 }, | |
2990 | { "fpu", s_arm_fpu, 0 }, | |
c19d1205 ZW |
2991 | #ifdef OBJ_ELF |
2992 | { "word", s_arm_elf_cons, 4 }, | |
2993 | { "long", s_arm_elf_cons, 4 }, | |
2994 | { "rel31", s_arm_rel31, 0 }, | |
2995 | { "fnstart", s_arm_unwind_fnstart, 0 }, | |
2996 | { "fnend", s_arm_unwind_fnend, 0 }, | |
2997 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
2998 | { "personality", s_arm_unwind_personality, 0 }, | |
2999 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
3000 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
3001 | { "save", s_arm_unwind_save, 0 }, | |
3002 | { "movsp", s_arm_unwind_movsp, 0 }, | |
3003 | { "pad", s_arm_unwind_pad, 0 }, | |
3004 | { "setfp", s_arm_unwind_setfp, 0 }, | |
3005 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 | 3006 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, |
c19d1205 ZW |
3007 | #else |
3008 | { "word", cons, 4}, | |
3009 | #endif | |
3010 | { "extend", float_cons, 'x' }, | |
3011 | { "ldouble", float_cons, 'x' }, | |
3012 | { "packed", float_cons, 'p' }, | |
3013 | { 0, 0, 0 } | |
3014 | }; | |
3015 | \f | |
3016 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 3017 | |
c19d1205 ZW |
3018 | /* Generic immediate-value read function for use in insn parsing. |
3019 | STR points to the beginning of the immediate (the leading #); | |
3020 | VAL receives the value; if the value is outside [MIN, MAX] | |
3021 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
3022 | optional. */ | |
b99bd4ef | 3023 | |
c19d1205 ZW |
3024 | static int |
3025 | parse_immediate (char **str, int *val, int min, int max, | |
3026 | bfd_boolean prefix_opt) | |
3027 | { | |
3028 | expressionS exp; | |
3029 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
3030 | if (exp.X_op != O_constant) | |
b99bd4ef | 3031 | { |
c19d1205 ZW |
3032 | inst.error = _("constant expression required"); |
3033 | return FAIL; | |
3034 | } | |
b99bd4ef | 3035 | |
c19d1205 ZW |
3036 | if (exp.X_add_number < min || exp.X_add_number > max) |
3037 | { | |
3038 | inst.error = _("immediate value out of range"); | |
3039 | return FAIL; | |
3040 | } | |
b99bd4ef | 3041 | |
c19d1205 ZW |
3042 | *val = exp.X_add_number; |
3043 | return SUCCESS; | |
3044 | } | |
b99bd4ef | 3045 | |
c19d1205 ZW |
3046 | /* Returns the pseudo-register number of an FPA immediate constant, |
3047 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 3048 | |
c19d1205 ZW |
3049 | static int |
3050 | parse_fpa_immediate (char ** str) | |
3051 | { | |
3052 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
3053 | char * save_in; | |
3054 | expressionS exp; | |
3055 | int i; | |
3056 | int j; | |
b99bd4ef | 3057 | |
c19d1205 ZW |
3058 | /* First try and match exact strings, this is to guarantee |
3059 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 3060 | |
c19d1205 ZW |
3061 | for (i = 0; fp_const[i]; i++) |
3062 | { | |
3063 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 3064 | { |
c19d1205 | 3065 | char *start = *str; |
b99bd4ef | 3066 | |
c19d1205 ZW |
3067 | *str += strlen (fp_const[i]); |
3068 | if (is_end_of_line[(unsigned char) **str]) | |
3069 | return i + 8; | |
3070 | *str = start; | |
3071 | } | |
3072 | } | |
b99bd4ef | 3073 | |
c19d1205 ZW |
3074 | /* Just because we didn't get a match doesn't mean that the constant |
3075 | isn't valid, just that it is in a format that we don't | |
3076 | automatically recognize. Try parsing it with the standard | |
3077 | expression routines. */ | |
b99bd4ef | 3078 | |
c19d1205 | 3079 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 3080 | |
c19d1205 ZW |
3081 | /* Look for a raw floating point number. */ |
3082 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
3083 | && is_end_of_line[(unsigned char) *save_in]) | |
3084 | { | |
3085 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
3086 | { | |
3087 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 3088 | { |
c19d1205 ZW |
3089 | if (words[j] != fp_values[i][j]) |
3090 | break; | |
b99bd4ef NC |
3091 | } |
3092 | ||
c19d1205 | 3093 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 3094 | { |
c19d1205 ZW |
3095 | *str = save_in; |
3096 | return i + 8; | |
b99bd4ef NC |
3097 | } |
3098 | } | |
3099 | } | |
b99bd4ef | 3100 | |
c19d1205 ZW |
3101 | /* Try and parse a more complex expression, this will probably fail |
3102 | unless the code uses a floating point prefix (eg "0f"). */ | |
3103 | save_in = input_line_pointer; | |
3104 | input_line_pointer = *str; | |
3105 | if (expression (&exp) == absolute_section | |
3106 | && exp.X_op == O_big | |
3107 | && exp.X_add_number < 0) | |
3108 | { | |
3109 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
3110 | Ditto for 15. */ | |
3111 | if (gen_to_words (words, 5, (long) 15) == 0) | |
3112 | { | |
3113 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
3114 | { | |
3115 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
3116 | { | |
3117 | if (words[j] != fp_values[i][j]) | |
3118 | break; | |
3119 | } | |
b99bd4ef | 3120 | |
c19d1205 ZW |
3121 | if (j == MAX_LITTLENUMS) |
3122 | { | |
3123 | *str = input_line_pointer; | |
3124 | input_line_pointer = save_in; | |
3125 | return i + 8; | |
3126 | } | |
3127 | } | |
3128 | } | |
b99bd4ef NC |
3129 | } |
3130 | ||
c19d1205 ZW |
3131 | *str = input_line_pointer; |
3132 | input_line_pointer = save_in; | |
3133 | inst.error = _("invalid FPA immediate expression"); | |
3134 | return FAIL; | |
b99bd4ef NC |
3135 | } |
3136 | ||
c19d1205 ZW |
3137 | /* Shift operands. */ |
3138 | enum shift_kind | |
b99bd4ef | 3139 | { |
c19d1205 ZW |
3140 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
3141 | }; | |
b99bd4ef | 3142 | |
c19d1205 ZW |
3143 | struct asm_shift_name |
3144 | { | |
3145 | const char *name; | |
3146 | enum shift_kind kind; | |
3147 | }; | |
b99bd4ef | 3148 | |
c19d1205 ZW |
3149 | /* Third argument to parse_shift. */ |
3150 | enum parse_shift_mode | |
3151 | { | |
3152 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
3153 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
3154 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
3155 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
3156 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
3157 | }; | |
b99bd4ef | 3158 | |
c19d1205 ZW |
3159 | /* Parse a <shift> specifier on an ARM data processing instruction. |
3160 | This has three forms: | |
b99bd4ef | 3161 | |
c19d1205 ZW |
3162 | (LSL|LSR|ASL|ASR|ROR) Rs |
3163 | (LSL|LSR|ASL|ASR|ROR) #imm | |
3164 | RRX | |
b99bd4ef | 3165 | |
c19d1205 ZW |
3166 | Note that ASL is assimilated to LSL in the instruction encoding, and |
3167 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 3168 | |
c19d1205 ZW |
3169 | static int |
3170 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 3171 | { |
c19d1205 ZW |
3172 | const struct asm_shift_name *shift_name; |
3173 | enum shift_kind shift; | |
3174 | char *s = *str; | |
3175 | char *p = s; | |
3176 | int reg; | |
b99bd4ef | 3177 | |
c19d1205 ZW |
3178 | for (p = *str; ISALPHA (*p); p++) |
3179 | ; | |
b99bd4ef | 3180 | |
c19d1205 | 3181 | if (p == *str) |
b99bd4ef | 3182 | { |
c19d1205 ZW |
3183 | inst.error = _("shift expression expected"); |
3184 | return FAIL; | |
b99bd4ef NC |
3185 | } |
3186 | ||
c19d1205 ZW |
3187 | shift_name = hash_find_n (arm_shift_hsh, *str, p - *str); |
3188 | ||
3189 | if (shift_name == NULL) | |
b99bd4ef | 3190 | { |
c19d1205 ZW |
3191 | inst.error = _("shift expression expected"); |
3192 | return FAIL; | |
b99bd4ef NC |
3193 | } |
3194 | ||
c19d1205 | 3195 | shift = shift_name->kind; |
b99bd4ef | 3196 | |
c19d1205 ZW |
3197 | switch (mode) |
3198 | { | |
3199 | case NO_SHIFT_RESTRICT: | |
3200 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 3201 | |
c19d1205 ZW |
3202 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
3203 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
3204 | { | |
3205 | inst.error = _("'LSL' or 'ASR' required"); | |
3206 | return FAIL; | |
3207 | } | |
3208 | break; | |
b99bd4ef | 3209 | |
c19d1205 ZW |
3210 | case SHIFT_LSL_IMMEDIATE: |
3211 | if (shift != SHIFT_LSL) | |
3212 | { | |
3213 | inst.error = _("'LSL' required"); | |
3214 | return FAIL; | |
3215 | } | |
3216 | break; | |
b99bd4ef | 3217 | |
c19d1205 ZW |
3218 | case SHIFT_ASR_IMMEDIATE: |
3219 | if (shift != SHIFT_ASR) | |
3220 | { | |
3221 | inst.error = _("'ASR' required"); | |
3222 | return FAIL; | |
3223 | } | |
3224 | break; | |
b99bd4ef | 3225 | |
c19d1205 ZW |
3226 | default: abort (); |
3227 | } | |
b99bd4ef | 3228 | |
c19d1205 ZW |
3229 | if (shift != SHIFT_RRX) |
3230 | { | |
3231 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
3232 | skip_whitespace (p); | |
b99bd4ef | 3233 | |
c19d1205 ZW |
3234 | if (mode == NO_SHIFT_RESTRICT |
3235 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) | |
3236 | { | |
3237 | inst.operands[i].imm = reg; | |
3238 | inst.operands[i].immisreg = 1; | |
3239 | } | |
3240 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
3241 | return FAIL; | |
3242 | } | |
3243 | inst.operands[i].shift_kind = shift; | |
3244 | inst.operands[i].shifted = 1; | |
3245 | *str = p; | |
3246 | return SUCCESS; | |
b99bd4ef NC |
3247 | } |
3248 | ||
c19d1205 | 3249 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 3250 | |
c19d1205 ZW |
3251 | #<immediate> |
3252 | #<immediate>, <rotate> | |
3253 | <Rm> | |
3254 | <Rm>, <shift> | |
b99bd4ef | 3255 | |
c19d1205 ZW |
3256 | where <shift> is defined by parse_shift above, and <rotate> is a |
3257 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 3258 | is deferred to md_apply_fix. */ |
b99bd4ef | 3259 | |
c19d1205 ZW |
3260 | static int |
3261 | parse_shifter_operand (char **str, int i) | |
3262 | { | |
3263 | int value; | |
3264 | expressionS expr; | |
b99bd4ef | 3265 | |
c19d1205 ZW |
3266 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
3267 | { | |
3268 | inst.operands[i].reg = value; | |
3269 | inst.operands[i].isreg = 1; | |
b99bd4ef | 3270 | |
c19d1205 ZW |
3271 | /* parse_shift will override this if appropriate */ |
3272 | inst.reloc.exp.X_op = O_constant; | |
3273 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 3274 | |
c19d1205 ZW |
3275 | if (skip_past_comma (str) == FAIL) |
3276 | return SUCCESS; | |
b99bd4ef | 3277 | |
c19d1205 ZW |
3278 | /* Shift operation on register. */ |
3279 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
3280 | } |
3281 | ||
c19d1205 ZW |
3282 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
3283 | return FAIL; | |
b99bd4ef | 3284 | |
c19d1205 | 3285 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 3286 | { |
c19d1205 ZW |
3287 | /* #x, y -- ie explicit rotation by Y. */ |
3288 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
3289 | return FAIL; | |
b99bd4ef | 3290 | |
c19d1205 ZW |
3291 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
3292 | { | |
3293 | inst.error = _("constant expression expected"); | |
3294 | return FAIL; | |
3295 | } | |
b99bd4ef | 3296 | |
c19d1205 ZW |
3297 | value = expr.X_add_number; |
3298 | if (value < 0 || value > 30 || value % 2 != 0) | |
3299 | { | |
3300 | inst.error = _("invalid rotation"); | |
3301 | return FAIL; | |
3302 | } | |
3303 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
3304 | { | |
3305 | inst.error = _("invalid constant"); | |
3306 | return FAIL; | |
3307 | } | |
09d92015 | 3308 | |
55cf6793 | 3309 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
3310 | inst.reloc.exp.X_add_number |
3311 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
3312 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
3313 | } |
3314 | ||
c19d1205 ZW |
3315 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
3316 | inst.reloc.pc_rel = 0; | |
3317 | return SUCCESS; | |
09d92015 MM |
3318 | } |
3319 | ||
c19d1205 ZW |
3320 | /* Parse all forms of an ARM address expression. Information is written |
3321 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 3322 | |
c19d1205 | 3323 | Preindexed addressing (.preind=1): |
09d92015 | 3324 | |
c19d1205 ZW |
3325 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
3326 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3327 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3328 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 3329 | |
c19d1205 | 3330 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 3331 | |
c19d1205 | 3332 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 3333 | |
c19d1205 ZW |
3334 | [Rn], #offset .reg=Rn .reloc.exp=offset |
3335 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3336 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3337 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 3338 | |
c19d1205 | 3339 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 3340 | |
c19d1205 | 3341 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 3342 | |
c19d1205 | 3343 | Other: |
09d92015 | 3344 | |
c19d1205 ZW |
3345 | [Rn]{!} shorthand for [Rn,#0]{!} |
3346 | =immediate .isreg=0 .reloc.exp=immediate | |
3347 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 3348 | |
c19d1205 ZW |
3349 | It is the caller's responsibility to check for addressing modes not |
3350 | supported by the instruction, and to set inst.reloc.type. */ | |
3351 | ||
3352 | static int | |
3353 | parse_address (char **str, int i) | |
09d92015 | 3354 | { |
c19d1205 ZW |
3355 | char *p = *str; |
3356 | int reg; | |
09d92015 | 3357 | |
c19d1205 | 3358 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 3359 | { |
c19d1205 ZW |
3360 | if (skip_past_char (&p, '=') == FAIL) |
3361 | { | |
3362 | /* bare address - translate to PC-relative offset */ | |
3363 | inst.reloc.pc_rel = 1; | |
3364 | inst.operands[i].reg = REG_PC; | |
3365 | inst.operands[i].isreg = 1; | |
3366 | inst.operands[i].preind = 1; | |
3367 | } | |
3368 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 3369 | |
c19d1205 ZW |
3370 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
3371 | return FAIL; | |
09d92015 | 3372 | |
c19d1205 ZW |
3373 | *str = p; |
3374 | return SUCCESS; | |
09d92015 MM |
3375 | } |
3376 | ||
c19d1205 | 3377 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 3378 | { |
c19d1205 ZW |
3379 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
3380 | return FAIL; | |
09d92015 | 3381 | } |
c19d1205 ZW |
3382 | inst.operands[i].reg = reg; |
3383 | inst.operands[i].isreg = 1; | |
09d92015 | 3384 | |
c19d1205 | 3385 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 3386 | { |
c19d1205 | 3387 | inst.operands[i].preind = 1; |
09d92015 | 3388 | |
c19d1205 ZW |
3389 | if (*p == '+') p++; |
3390 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
3391 | ||
3392 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) | |
09d92015 | 3393 | { |
c19d1205 ZW |
3394 | inst.operands[i].imm = reg; |
3395 | inst.operands[i].immisreg = 1; | |
3396 | ||
3397 | if (skip_past_comma (&p) == SUCCESS) | |
3398 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
3399 | return FAIL; | |
3400 | } | |
3401 | else | |
3402 | { | |
3403 | if (inst.operands[i].negative) | |
3404 | { | |
3405 | inst.operands[i].negative = 0; | |
3406 | p--; | |
3407 | } | |
3408 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
3409 | return FAIL; | |
09d92015 MM |
3410 | } |
3411 | } | |
3412 | ||
c19d1205 | 3413 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 3414 | { |
c19d1205 ZW |
3415 | inst.error = _("']' expected"); |
3416 | return FAIL; | |
09d92015 MM |
3417 | } |
3418 | ||
c19d1205 ZW |
3419 | if (skip_past_char (&p, '!') == SUCCESS) |
3420 | inst.operands[i].writeback = 1; | |
09d92015 | 3421 | |
c19d1205 | 3422 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 3423 | { |
c19d1205 ZW |
3424 | if (skip_past_char (&p, '{') == SUCCESS) |
3425 | { | |
3426 | /* [Rn], {expr} - unindexed, with option */ | |
3427 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 3428 | 0, 255, TRUE) == FAIL) |
c19d1205 | 3429 | return FAIL; |
09d92015 | 3430 | |
c19d1205 ZW |
3431 | if (skip_past_char (&p, '}') == FAIL) |
3432 | { | |
3433 | inst.error = _("'}' expected at end of 'option' field"); | |
3434 | return FAIL; | |
3435 | } | |
3436 | if (inst.operands[i].preind) | |
3437 | { | |
3438 | inst.error = _("cannot combine index with option"); | |
3439 | return FAIL; | |
3440 | } | |
3441 | *str = p; | |
3442 | return SUCCESS; | |
09d92015 | 3443 | } |
c19d1205 ZW |
3444 | else |
3445 | { | |
3446 | inst.operands[i].postind = 1; | |
3447 | inst.operands[i].writeback = 1; | |
09d92015 | 3448 | |
c19d1205 ZW |
3449 | if (inst.operands[i].preind) |
3450 | { | |
3451 | inst.error = _("cannot combine pre- and post-indexing"); | |
3452 | return FAIL; | |
3453 | } | |
09d92015 | 3454 | |
c19d1205 ZW |
3455 | if (*p == '+') p++; |
3456 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 3457 | |
c19d1205 ZW |
3458 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
3459 | { | |
3460 | inst.operands[i].imm = reg; | |
3461 | inst.operands[i].immisreg = 1; | |
a737bd4d | 3462 | |
c19d1205 ZW |
3463 | if (skip_past_comma (&p) == SUCCESS) |
3464 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
3465 | return FAIL; | |
3466 | } | |
3467 | else | |
3468 | { | |
3469 | if (inst.operands[i].negative) | |
3470 | { | |
3471 | inst.operands[i].negative = 0; | |
3472 | p--; | |
3473 | } | |
3474 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
3475 | return FAIL; | |
3476 | } | |
3477 | } | |
a737bd4d NC |
3478 | } |
3479 | ||
c19d1205 ZW |
3480 | /* If at this point neither .preind nor .postind is set, we have a |
3481 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
3482 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
3483 | { | |
3484 | inst.operands[i].preind = 1; | |
3485 | inst.reloc.exp.X_op = O_constant; | |
3486 | inst.reloc.exp.X_add_number = 0; | |
3487 | } | |
3488 | *str = p; | |
3489 | return SUCCESS; | |
a737bd4d NC |
3490 | } |
3491 | ||
c19d1205 | 3492 | /* Miscellaneous. */ |
a737bd4d | 3493 | |
c19d1205 ZW |
3494 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
3495 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
3496 | static int | |
3497 | parse_psr (char **str) | |
09d92015 | 3498 | { |
c19d1205 ZW |
3499 | char *p; |
3500 | unsigned long psr_field; | |
62b3e311 PB |
3501 | const struct asm_psr *psr; |
3502 | char *start; | |
09d92015 | 3503 | |
c19d1205 ZW |
3504 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
3505 | feature for ease of use and backwards compatibility. */ | |
3506 | p = *str; | |
62b3e311 | 3507 | if (strncasecmp (p, "SPSR", 4) == 0) |
c19d1205 | 3508 | psr_field = SPSR_BIT; |
62b3e311 | 3509 | else if (strncasecmp (p, "CPSR", 4) == 0) |
c19d1205 ZW |
3510 | psr_field = 0; |
3511 | else | |
62b3e311 PB |
3512 | { |
3513 | start = p; | |
3514 | do | |
3515 | p++; | |
3516 | while (ISALNUM (*p) || *p == '_'); | |
3517 | ||
3518 | psr = hash_find_n (arm_v7m_psr_hsh, start, p - start); | |
3519 | if (!psr) | |
3520 | return FAIL; | |
09d92015 | 3521 | |
62b3e311 PB |
3522 | *str = p; |
3523 | return psr->field; | |
3524 | } | |
09d92015 | 3525 | |
62b3e311 | 3526 | p += 4; |
c19d1205 ZW |
3527 | if (*p == '_') |
3528 | { | |
3529 | /* A suffix follows. */ | |
c19d1205 ZW |
3530 | p++; |
3531 | start = p; | |
a737bd4d | 3532 | |
c19d1205 ZW |
3533 | do |
3534 | p++; | |
3535 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 3536 | |
c19d1205 ZW |
3537 | psr = hash_find_n (arm_psr_hsh, start, p - start); |
3538 | if (!psr) | |
3539 | goto error; | |
a737bd4d | 3540 | |
c19d1205 | 3541 | psr_field |= psr->field; |
a737bd4d | 3542 | } |
c19d1205 | 3543 | else |
a737bd4d | 3544 | { |
c19d1205 ZW |
3545 | if (ISALNUM (*p)) |
3546 | goto error; /* Garbage after "[CS]PSR". */ | |
3547 | ||
3548 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 3549 | } |
c19d1205 ZW |
3550 | *str = p; |
3551 | return psr_field; | |
a737bd4d | 3552 | |
c19d1205 ZW |
3553 | error: |
3554 | inst.error = _("flag for {c}psr instruction expected"); | |
3555 | return FAIL; | |
a737bd4d NC |
3556 | } |
3557 | ||
c19d1205 ZW |
3558 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
3559 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 3560 | |
c19d1205 ZW |
3561 | static int |
3562 | parse_cps_flags (char **str) | |
a737bd4d | 3563 | { |
c19d1205 ZW |
3564 | int val = 0; |
3565 | int saw_a_flag = 0; | |
3566 | char *s = *str; | |
a737bd4d | 3567 | |
c19d1205 ZW |
3568 | for (;;) |
3569 | switch (*s++) | |
3570 | { | |
3571 | case '\0': case ',': | |
3572 | goto done; | |
a737bd4d | 3573 | |
c19d1205 ZW |
3574 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
3575 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
3576 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 3577 | |
c19d1205 ZW |
3578 | default: |
3579 | inst.error = _("unrecognized CPS flag"); | |
3580 | return FAIL; | |
3581 | } | |
a737bd4d | 3582 | |
c19d1205 ZW |
3583 | done: |
3584 | if (saw_a_flag == 0) | |
a737bd4d | 3585 | { |
c19d1205 ZW |
3586 | inst.error = _("missing CPS flags"); |
3587 | return FAIL; | |
a737bd4d | 3588 | } |
a737bd4d | 3589 | |
c19d1205 ZW |
3590 | *str = s - 1; |
3591 | return val; | |
a737bd4d NC |
3592 | } |
3593 | ||
c19d1205 ZW |
3594 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
3595 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
3596 | |
3597 | static int | |
c19d1205 | 3598 | parse_endian_specifier (char **str) |
a737bd4d | 3599 | { |
c19d1205 ZW |
3600 | int little_endian; |
3601 | char *s = *str; | |
a737bd4d | 3602 | |
c19d1205 ZW |
3603 | if (strncasecmp (s, "BE", 2)) |
3604 | little_endian = 0; | |
3605 | else if (strncasecmp (s, "LE", 2)) | |
3606 | little_endian = 1; | |
3607 | else | |
a737bd4d | 3608 | { |
c19d1205 | 3609 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
3610 | return FAIL; |
3611 | } | |
3612 | ||
c19d1205 | 3613 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 3614 | { |
c19d1205 | 3615 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
3616 | return FAIL; |
3617 | } | |
3618 | ||
c19d1205 ZW |
3619 | *str = s + 2; |
3620 | return little_endian; | |
3621 | } | |
a737bd4d | 3622 | |
c19d1205 ZW |
3623 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
3624 | value suitable for poking into the rotate field of an sxt or sxta | |
3625 | instruction, or FAIL on error. */ | |
3626 | ||
3627 | static int | |
3628 | parse_ror (char **str) | |
3629 | { | |
3630 | int rot; | |
3631 | char *s = *str; | |
3632 | ||
3633 | if (strncasecmp (s, "ROR", 3) == 0) | |
3634 | s += 3; | |
3635 | else | |
a737bd4d | 3636 | { |
c19d1205 | 3637 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
3638 | return FAIL; |
3639 | } | |
c19d1205 ZW |
3640 | |
3641 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
3642 | return FAIL; | |
3643 | ||
3644 | switch (rot) | |
a737bd4d | 3645 | { |
c19d1205 ZW |
3646 | case 0: *str = s; return 0x0; |
3647 | case 8: *str = s; return 0x1; | |
3648 | case 16: *str = s; return 0x2; | |
3649 | case 24: *str = s; return 0x3; | |
3650 | ||
3651 | default: | |
3652 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
3653 | return FAIL; |
3654 | } | |
c19d1205 | 3655 | } |
a737bd4d | 3656 | |
c19d1205 ZW |
3657 | /* Parse a conditional code (from conds[] below). The value returned is in the |
3658 | range 0 .. 14, or FAIL. */ | |
3659 | static int | |
3660 | parse_cond (char **str) | |
3661 | { | |
3662 | char *p, *q; | |
3663 | const struct asm_cond *c; | |
a737bd4d | 3664 | |
c19d1205 ZW |
3665 | p = q = *str; |
3666 | while (ISALPHA (*q)) | |
3667 | q++; | |
a737bd4d | 3668 | |
c19d1205 ZW |
3669 | c = hash_find_n (arm_cond_hsh, p, q - p); |
3670 | if (!c) | |
a737bd4d | 3671 | { |
c19d1205 | 3672 | inst.error = _("condition required"); |
a737bd4d NC |
3673 | return FAIL; |
3674 | } | |
3675 | ||
c19d1205 ZW |
3676 | *str = q; |
3677 | return c->value; | |
3678 | } | |
3679 | ||
62b3e311 PB |
3680 | /* Parse an option for a barrier instruction. Returns the encoding for the |
3681 | option, or FAIL. */ | |
3682 | static int | |
3683 | parse_barrier (char **str) | |
3684 | { | |
3685 | char *p, *q; | |
3686 | const struct asm_barrier_opt *o; | |
3687 | ||
3688 | p = q = *str; | |
3689 | while (ISALPHA (*q)) | |
3690 | q++; | |
3691 | ||
3692 | o = hash_find_n (arm_barrier_opt_hsh, p, q - p); | |
3693 | if (!o) | |
3694 | return FAIL; | |
3695 | ||
3696 | *str = q; | |
3697 | return o->value; | |
3698 | } | |
3699 | ||
92e90b6e PB |
3700 | /* Parse the operands of a table branch instruction. Similar to a memory |
3701 | operand. */ | |
3702 | static int | |
3703 | parse_tb (char **str) | |
3704 | { | |
3705 | char * p = *str; | |
3706 | int reg; | |
3707 | ||
3708 | if (skip_past_char (&p, '[') == FAIL) | |
ab1eb5fe PB |
3709 | { |
3710 | inst.error = _("'[' expected"); | |
3711 | return FAIL; | |
3712 | } | |
92e90b6e PB |
3713 | |
3714 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) | |
3715 | { | |
3716 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
3717 | return FAIL; | |
3718 | } | |
3719 | inst.operands[0].reg = reg; | |
3720 | ||
3721 | if (skip_past_comma (&p) == FAIL) | |
ab1eb5fe PB |
3722 | { |
3723 | inst.error = _("',' expected"); | |
3724 | return FAIL; | |
3725 | } | |
92e90b6e PB |
3726 | |
3727 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) | |
3728 | { | |
3729 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
3730 | return FAIL; | |
3731 | } | |
3732 | inst.operands[0].imm = reg; | |
3733 | ||
3734 | if (skip_past_comma (&p) == SUCCESS) | |
3735 | { | |
3736 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
3737 | return FAIL; | |
3738 | if (inst.reloc.exp.X_add_number != 1) | |
3739 | { | |
3740 | inst.error = _("invalid shift"); | |
3741 | return FAIL; | |
3742 | } | |
3743 | inst.operands[0].shifted = 1; | |
3744 | } | |
3745 | ||
3746 | if (skip_past_char (&p, ']') == FAIL) | |
3747 | { | |
3748 | inst.error = _("']' expected"); | |
3749 | return FAIL; | |
3750 | } | |
3751 | *str = p; | |
3752 | return SUCCESS; | |
3753 | } | |
3754 | ||
c19d1205 ZW |
3755 | /* Matcher codes for parse_operands. */ |
3756 | enum operand_parse_code | |
3757 | { | |
3758 | OP_stop, /* end of line */ | |
3759 | ||
3760 | OP_RR, /* ARM register */ | |
3761 | OP_RRnpc, /* ARM register, not r15 */ | |
3762 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
3763 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
3764 | OP_RCP, /* Coprocessor number */ | |
3765 | OP_RCN, /* Coprocessor register */ | |
3766 | OP_RF, /* FPA register */ | |
3767 | OP_RVS, /* VFP single precision register */ | |
3768 | OP_RVD, /* VFP double precision register */ | |
3769 | OP_RVC, /* VFP control register */ | |
3770 | OP_RMF, /* Maverick F register */ | |
3771 | OP_RMD, /* Maverick D register */ | |
3772 | OP_RMFX, /* Maverick FX register */ | |
3773 | OP_RMDX, /* Maverick DX register */ | |
3774 | OP_RMAX, /* Maverick AX register */ | |
3775 | OP_RMDS, /* Maverick DSPSC register */ | |
3776 | OP_RIWR, /* iWMMXt wR register */ | |
3777 | OP_RIWC, /* iWMMXt wC register */ | |
3778 | OP_RIWG, /* iWMMXt wCG register */ | |
3779 | OP_RXA, /* XScale accumulator register */ | |
3780 | ||
3781 | OP_REGLST, /* ARM register list */ | |
3782 | OP_VRSLST, /* VFP single-precision register list */ | |
3783 | OP_VRDLST, /* VFP double-precision register list */ | |
3784 | ||
3785 | OP_I7, /* immediate value 0 .. 7 */ | |
3786 | OP_I15, /* 0 .. 15 */ | |
3787 | OP_I16, /* 1 .. 16 */ | |
3788 | OP_I31, /* 0 .. 31 */ | |
3789 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
3790 | OP_I32, /* 1 .. 32 */ | |
3791 | OP_I63s, /* -64 .. 63 */ | |
3792 | OP_I255, /* 0 .. 255 */ | |
3793 | OP_Iffff, /* 0 .. 65535 */ | |
3794 | ||
3795 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
3796 | OP_I7b, /* 0 .. 7 */ | |
3797 | OP_I15b, /* 0 .. 15 */ | |
3798 | OP_I31b, /* 0 .. 31 */ | |
3799 | ||
3800 | OP_SH, /* shifter operand */ | |
3801 | OP_ADDR, /* Memory address expression (any mode) */ | |
3802 | OP_EXP, /* arbitrary expression */ | |
3803 | OP_EXPi, /* same, with optional immediate prefix */ | |
3804 | OP_EXPr, /* same, with optional relocation suffix */ | |
3805 | ||
3806 | OP_CPSF, /* CPS flags */ | |
3807 | OP_ENDI, /* Endianness specifier */ | |
3808 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
3809 | OP_COND, /* conditional code */ | |
92e90b6e | 3810 | OP_TB, /* Table branch. */ |
c19d1205 ZW |
3811 | |
3812 | OP_RRnpc_I0, /* ARM register or literal 0 */ | |
3813 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
3814 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
3815 | OP_RF_IF, /* FPA register or immediate */ | |
3816 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
3817 | ||
3818 | /* Optional operands. */ | |
3819 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
3820 | OP_oI31b, /* 0 .. 31 */ | |
3821 | OP_oIffffb, /* 0 .. 65535 */ | |
3822 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
3823 | ||
3824 | OP_oRR, /* ARM register */ | |
3825 | OP_oRRnpc, /* ARM register, not the PC */ | |
3826 | OP_oSHll, /* LSL immediate */ | |
3827 | OP_oSHar, /* ASR immediate */ | |
3828 | OP_oSHllar, /* LSL or ASR immediate */ | |
3829 | OP_oROR, /* ROR 0/8/16/24 */ | |
62b3e311 | 3830 | OP_oBARRIER, /* Option argument for a barrier instruction. */ |
c19d1205 ZW |
3831 | |
3832 | OP_FIRST_OPTIONAL = OP_oI7b | |
3833 | }; | |
a737bd4d | 3834 | |
c19d1205 ZW |
3835 | /* Generic instruction operand parser. This does no encoding and no |
3836 | semantic validation; it merely squirrels values away in the inst | |
3837 | structure. Returns SUCCESS or FAIL depending on whether the | |
3838 | specified grammar matched. */ | |
3839 | static int | |
ca3f61f7 | 3840 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
3841 | { |
3842 | unsigned const char *upat = pattern; | |
3843 | char *backtrack_pos = 0; | |
3844 | const char *backtrack_error = 0; | |
3845 | int i, val, backtrack_index = 0; | |
3846 | ||
3847 | #define po_char_or_fail(chr) do { \ | |
3848 | if (skip_past_char (&str, chr) == FAIL) \ | |
3849 | goto bad_args; \ | |
3850 | } while (0) | |
3851 | ||
3852 | #define po_reg_or_fail(regtype) do { \ | |
3853 | val = arm_reg_parse (&str, regtype); \ | |
3854 | if (val == FAIL) \ | |
3855 | { \ | |
3856 | inst.error = _(reg_expected_msgs[regtype]); \ | |
3857 | goto failure; \ | |
3858 | } \ | |
3859 | inst.operands[i].reg = val; \ | |
3860 | inst.operands[i].isreg = 1; \ | |
3861 | } while (0) | |
3862 | ||
3863 | #define po_reg_or_goto(regtype, label) do { \ | |
3864 | val = arm_reg_parse (&str, regtype); \ | |
3865 | if (val == FAIL) \ | |
3866 | goto label; \ | |
3867 | \ | |
3868 | inst.operands[i].reg = val; \ | |
3869 | inst.operands[i].isreg = 1; \ | |
3870 | } while (0) | |
3871 | ||
3872 | #define po_imm_or_fail(min, max, popt) do { \ | |
3873 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
3874 | goto failure; \ | |
3875 | inst.operands[i].imm = val; \ | |
3876 | } while (0) | |
3877 | ||
3878 | #define po_misc_or_fail(expr) do { \ | |
3879 | if (expr) \ | |
3880 | goto failure; \ | |
3881 | } while (0) | |
3882 | ||
3883 | skip_whitespace (str); | |
3884 | ||
3885 | for (i = 0; upat[i] != OP_stop; i++) | |
3886 | { | |
3887 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
3888 | { | |
3889 | /* Remember where we are in case we need to backtrack. */ | |
3890 | assert (!backtrack_pos); | |
3891 | backtrack_pos = str; | |
3892 | backtrack_error = inst.error; | |
3893 | backtrack_index = i; | |
3894 | } | |
3895 | ||
3896 | if (i > 0) | |
3897 | po_char_or_fail (','); | |
3898 | ||
3899 | switch (upat[i]) | |
3900 | { | |
3901 | /* Registers */ | |
3902 | case OP_oRRnpc: | |
3903 | case OP_RRnpc: | |
3904 | case OP_oRR: | |
3905 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
3906 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
3907 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
3908 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
3909 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
3910 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
3911 | case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break; | |
3912 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; | |
3913 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
3914 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
3915 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
3916 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
3917 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
3918 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
3919 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
3920 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
3921 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
3922 | ||
3923 | case OP_RRnpcb: | |
3924 | po_char_or_fail ('['); | |
3925 | po_reg_or_fail (REG_TYPE_RN); | |
3926 | po_char_or_fail (']'); | |
3927 | break; | |
a737bd4d | 3928 | |
c19d1205 ZW |
3929 | case OP_RRw: |
3930 | po_reg_or_fail (REG_TYPE_RN); | |
3931 | if (skip_past_char (&str, '!') == SUCCESS) | |
3932 | inst.operands[i].writeback = 1; | |
3933 | break; | |
3934 | ||
3935 | /* Immediates */ | |
3936 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
3937 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
3938 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
3939 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; | |
3940 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
3941 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; | |
3942 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; | |
3943 | case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break; | |
3944 | ||
3945 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
3946 | case OP_oI7b: | |
3947 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
3948 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
3949 | case OP_oI31b: | |
3950 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
3951 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; | |
3952 | ||
3953 | /* Immediate variants */ | |
3954 | case OP_oI255c: | |
3955 | po_char_or_fail ('{'); | |
3956 | po_imm_or_fail (0, 255, TRUE); | |
3957 | po_char_or_fail ('}'); | |
3958 | break; | |
3959 | ||
3960 | case OP_I31w: | |
3961 | /* The expression parser chokes on a trailing !, so we have | |
3962 | to find it first and zap it. */ | |
3963 | { | |
3964 | char *s = str; | |
3965 | while (*s && *s != ',') | |
3966 | s++; | |
3967 | if (s[-1] == '!') | |
3968 | { | |
3969 | s[-1] = '\0'; | |
3970 | inst.operands[i].writeback = 1; | |
3971 | } | |
3972 | po_imm_or_fail (0, 31, TRUE); | |
3973 | if (str == s - 1) | |
3974 | str = s; | |
3975 | } | |
3976 | break; | |
3977 | ||
3978 | /* Expressions */ | |
3979 | case OP_EXPi: EXPi: | |
3980 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
3981 | GE_OPT_PREFIX)); | |
3982 | break; | |
3983 | ||
3984 | case OP_EXP: | |
3985 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
3986 | GE_NO_PREFIX)); | |
3987 | break; | |
3988 | ||
3989 | case OP_EXPr: EXPr: | |
3990 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
3991 | GE_NO_PREFIX)); | |
3992 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 3993 | { |
c19d1205 ZW |
3994 | val = parse_reloc (&str); |
3995 | if (val == -1) | |
3996 | { | |
3997 | inst.error = _("unrecognized relocation suffix"); | |
3998 | goto failure; | |
3999 | } | |
4000 | else if (val != BFD_RELOC_UNUSED) | |
4001 | { | |
4002 | inst.operands[i].imm = val; | |
4003 | inst.operands[i].hasreloc = 1; | |
4004 | } | |
a737bd4d | 4005 | } |
c19d1205 | 4006 | break; |
a737bd4d | 4007 | |
c19d1205 ZW |
4008 | /* Register or expression */ |
4009 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; | |
4010 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 4011 | |
c19d1205 ZW |
4012 | /* Register or immediate */ |
4013 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; | |
4014 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 4015 | |
c19d1205 ZW |
4016 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
4017 | IF: | |
4018 | if (!is_immediate_prefix (*str)) | |
4019 | goto bad_args; | |
4020 | str++; | |
4021 | val = parse_fpa_immediate (&str); | |
4022 | if (val == FAIL) | |
4023 | goto failure; | |
4024 | /* FPA immediates are encoded as registers 8-15. | |
4025 | parse_fpa_immediate has already applied the offset. */ | |
4026 | inst.operands[i].reg = val; | |
4027 | inst.operands[i].isreg = 1; | |
4028 | break; | |
09d92015 | 4029 | |
c19d1205 ZW |
4030 | /* Two kinds of register */ |
4031 | case OP_RIWR_RIWC: | |
4032 | { | |
4033 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
4034 | if (rege->type != REG_TYPE_MMXWR | |
4035 | && rege->type != REG_TYPE_MMXWC | |
4036 | && rege->type != REG_TYPE_MMXWCG) | |
4037 | { | |
4038 | inst.error = _("iWMMXt data or control register expected"); | |
4039 | goto failure; | |
4040 | } | |
4041 | inst.operands[i].reg = rege->number; | |
4042 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
4043 | } | |
4044 | break; | |
09d92015 | 4045 | |
c19d1205 ZW |
4046 | /* Misc */ |
4047 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
4048 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
4049 | case OP_oROR: val = parse_ror (&str); break; | |
4050 | case OP_PSR: val = parse_psr (&str); break; | |
4051 | case OP_COND: val = parse_cond (&str); break; | |
62b3e311 | 4052 | case OP_oBARRIER:val = parse_barrier (&str); break; |
c19d1205 | 4053 | |
92e90b6e PB |
4054 | case OP_TB: |
4055 | po_misc_or_fail (parse_tb (&str)); | |
4056 | break; | |
4057 | ||
c19d1205 ZW |
4058 | /* Register lists */ |
4059 | case OP_REGLST: | |
4060 | val = parse_reg_list (&str); | |
4061 | if (*str == '^') | |
4062 | { | |
4063 | inst.operands[1].writeback = 1; | |
4064 | str++; | |
4065 | } | |
4066 | break; | |
09d92015 | 4067 | |
c19d1205 ZW |
4068 | case OP_VRSLST: |
4069 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0); | |
4070 | break; | |
09d92015 | 4071 | |
c19d1205 ZW |
4072 | case OP_VRDLST: |
4073 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1); | |
4074 | break; | |
a737bd4d | 4075 | |
c19d1205 ZW |
4076 | /* Addressing modes */ |
4077 | case OP_ADDR: | |
4078 | po_misc_or_fail (parse_address (&str, i)); | |
4079 | break; | |
09d92015 | 4080 | |
c19d1205 ZW |
4081 | case OP_SH: |
4082 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
4083 | break; | |
09d92015 | 4084 | |
c19d1205 ZW |
4085 | case OP_oSHll: |
4086 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
4087 | break; | |
09d92015 | 4088 | |
c19d1205 ZW |
4089 | case OP_oSHar: |
4090 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
4091 | break; | |
09d92015 | 4092 | |
c19d1205 ZW |
4093 | case OP_oSHllar: |
4094 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
4095 | break; | |
09d92015 | 4096 | |
c19d1205 ZW |
4097 | default: |
4098 | as_fatal ("unhandled operand code %d", upat[i]); | |
4099 | } | |
09d92015 | 4100 | |
c19d1205 ZW |
4101 | /* Various value-based sanity checks and shared operations. We |
4102 | do not signal immediate failures for the register constraints; | |
4103 | this allows a syntax error to take precedence. */ | |
4104 | switch (upat[i]) | |
4105 | { | |
4106 | case OP_oRRnpc: | |
4107 | case OP_RRnpc: | |
4108 | case OP_RRnpcb: | |
4109 | case OP_RRw: | |
4110 | case OP_RRnpc_I0: | |
4111 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
4112 | inst.error = BAD_PC; | |
4113 | break; | |
09d92015 | 4114 | |
c19d1205 ZW |
4115 | case OP_CPSF: |
4116 | case OP_ENDI: | |
4117 | case OP_oROR: | |
4118 | case OP_PSR: | |
4119 | case OP_COND: | |
62b3e311 | 4120 | case OP_oBARRIER: |
c19d1205 ZW |
4121 | case OP_REGLST: |
4122 | case OP_VRSLST: | |
4123 | case OP_VRDLST: | |
4124 | if (val == FAIL) | |
4125 | goto failure; | |
4126 | inst.operands[i].imm = val; | |
4127 | break; | |
a737bd4d | 4128 | |
c19d1205 ZW |
4129 | default: |
4130 | break; | |
4131 | } | |
09d92015 | 4132 | |
c19d1205 ZW |
4133 | /* If we get here, this operand was successfully parsed. */ |
4134 | inst.operands[i].present = 1; | |
4135 | continue; | |
09d92015 | 4136 | |
c19d1205 | 4137 | bad_args: |
09d92015 | 4138 | inst.error = BAD_ARGS; |
c19d1205 ZW |
4139 | |
4140 | failure: | |
4141 | if (!backtrack_pos) | |
d252fdde PB |
4142 | { |
4143 | /* The parse routine should already have set inst.error, but set a | |
4144 | defaut here just in case. */ | |
4145 | if (!inst.error) | |
4146 | inst.error = _("syntax error"); | |
4147 | return FAIL; | |
4148 | } | |
c19d1205 ZW |
4149 | |
4150 | /* Do not backtrack over a trailing optional argument that | |
4151 | absorbed some text. We will only fail again, with the | |
4152 | 'garbage following instruction' error message, which is | |
4153 | probably less helpful than the current one. */ | |
4154 | if (backtrack_index == i && backtrack_pos != str | |
4155 | && upat[i+1] == OP_stop) | |
d252fdde PB |
4156 | { |
4157 | if (!inst.error) | |
4158 | inst.error = _("syntax error"); | |
4159 | return FAIL; | |
4160 | } | |
c19d1205 ZW |
4161 | |
4162 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
4163 | str = backtrack_pos; | |
4164 | inst.error = backtrack_error; | |
4165 | inst.operands[backtrack_index].present = 0; | |
4166 | i = backtrack_index; | |
4167 | backtrack_pos = 0; | |
09d92015 | 4168 | } |
09d92015 | 4169 | |
c19d1205 ZW |
4170 | /* Check that we have parsed all the arguments. */ |
4171 | if (*str != '\0' && !inst.error) | |
4172 | inst.error = _("garbage following instruction"); | |
09d92015 | 4173 | |
c19d1205 | 4174 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
4175 | } |
4176 | ||
c19d1205 ZW |
4177 | #undef po_char_or_fail |
4178 | #undef po_reg_or_fail | |
4179 | #undef po_reg_or_goto | |
4180 | #undef po_imm_or_fail | |
4181 | \f | |
4182 | /* Shorthand macro for instruction encoding functions issuing errors. */ | |
4183 | #define constraint(expr, err) do { \ | |
4184 | if (expr) \ | |
4185 | { \ | |
4186 | inst.error = err; \ | |
4187 | return; \ | |
4188 | } \ | |
4189 | } while (0) | |
4190 | ||
4191 | /* Functions for operand encoding. ARM, then Thumb. */ | |
4192 | ||
4193 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
4194 | ||
4195 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
4196 | return the encoded form. Otherwise, return FAIL. */ | |
4197 | ||
4198 | static unsigned int | |
4199 | encode_arm_immediate (unsigned int val) | |
09d92015 | 4200 | { |
c19d1205 ZW |
4201 | unsigned int a, i; |
4202 | ||
4203 | for (i = 0; i < 32; i += 2) | |
4204 | if ((a = rotate_left (val, i)) <= 0xff) | |
4205 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
4206 | ||
4207 | return FAIL; | |
09d92015 MM |
4208 | } |
4209 | ||
c19d1205 ZW |
4210 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
4211 | return the encoded form. Otherwise, return FAIL. */ | |
4212 | static unsigned int | |
4213 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 4214 | { |
c19d1205 | 4215 | unsigned int a, i; |
09d92015 | 4216 | |
9c3c69f2 | 4217 | if (val <= 0xff) |
c19d1205 | 4218 | return val; |
a737bd4d | 4219 | |
9c3c69f2 | 4220 | for (i = 1; i <= 24; i++) |
09d92015 | 4221 | { |
9c3c69f2 PB |
4222 | a = val >> i; |
4223 | if ((val & ~(0xff << i)) == 0) | |
4224 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 4225 | } |
a737bd4d | 4226 | |
c19d1205 ZW |
4227 | a = val & 0xff; |
4228 | if (val == ((a << 16) | a)) | |
4229 | return 0x100 | a; | |
4230 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
4231 | return 0x300 | a; | |
09d92015 | 4232 | |
c19d1205 ZW |
4233 | a = val & 0xff00; |
4234 | if (val == ((a << 16) | a)) | |
4235 | return 0x200 | (a >> 8); | |
a737bd4d | 4236 | |
c19d1205 | 4237 | return FAIL; |
09d92015 | 4238 | } |
c19d1205 | 4239 | /* Encode a VFP SP register number into inst.instruction. */ |
09d92015 MM |
4240 | |
4241 | static void | |
c19d1205 | 4242 | encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos) |
09d92015 | 4243 | { |
c19d1205 | 4244 | switch (pos) |
09d92015 | 4245 | { |
c19d1205 ZW |
4246 | case VFP_REG_Sd: |
4247 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
4248 | break; | |
4249 | ||
4250 | case VFP_REG_Sn: | |
4251 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
4252 | break; | |
4253 | ||
4254 | case VFP_REG_Sm: | |
4255 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
4256 | break; | |
4257 | ||
4258 | default: | |
4259 | abort (); | |
09d92015 | 4260 | } |
09d92015 MM |
4261 | } |
4262 | ||
c19d1205 | 4263 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 4264 | if any, is handled by md_apply_fix. */ |
09d92015 | 4265 | static void |
c19d1205 | 4266 | encode_arm_shift (int i) |
09d92015 | 4267 | { |
c19d1205 ZW |
4268 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
4269 | inst.instruction |= SHIFT_ROR << 5; | |
4270 | else | |
09d92015 | 4271 | { |
c19d1205 ZW |
4272 | inst.instruction |= inst.operands[i].shift_kind << 5; |
4273 | if (inst.operands[i].immisreg) | |
4274 | { | |
4275 | inst.instruction |= SHIFT_BY_REG; | |
4276 | inst.instruction |= inst.operands[i].imm << 8; | |
4277 | } | |
4278 | else | |
4279 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 4280 | } |
c19d1205 | 4281 | } |
09d92015 | 4282 | |
c19d1205 ZW |
4283 | static void |
4284 | encode_arm_shifter_operand (int i) | |
4285 | { | |
4286 | if (inst.operands[i].isreg) | |
09d92015 | 4287 | { |
c19d1205 ZW |
4288 | inst.instruction |= inst.operands[i].reg; |
4289 | encode_arm_shift (i); | |
09d92015 | 4290 | } |
c19d1205 ZW |
4291 | else |
4292 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
4293 | } |
4294 | ||
c19d1205 | 4295 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 4296 | static void |
c19d1205 | 4297 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 4298 | { |
c19d1205 ZW |
4299 | assert (inst.operands[i].isreg); |
4300 | inst.instruction |= inst.operands[i].reg << 16; | |
a737bd4d | 4301 | |
c19d1205 | 4302 | if (inst.operands[i].preind) |
09d92015 | 4303 | { |
c19d1205 ZW |
4304 | if (is_t) |
4305 | { | |
4306 | inst.error = _("instruction does not accept preindexed addressing"); | |
4307 | return; | |
4308 | } | |
4309 | inst.instruction |= PRE_INDEX; | |
4310 | if (inst.operands[i].writeback) | |
4311 | inst.instruction |= WRITE_BACK; | |
09d92015 | 4312 | |
c19d1205 ZW |
4313 | } |
4314 | else if (inst.operands[i].postind) | |
4315 | { | |
4316 | assert (inst.operands[i].writeback); | |
4317 | if (is_t) | |
4318 | inst.instruction |= WRITE_BACK; | |
4319 | } | |
4320 | else /* unindexed - only for coprocessor */ | |
09d92015 | 4321 | { |
c19d1205 | 4322 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
4323 | return; |
4324 | } | |
4325 | ||
c19d1205 ZW |
4326 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
4327 | && (((inst.instruction & 0x000f0000) >> 16) | |
4328 | == ((inst.instruction & 0x0000f000) >> 12))) | |
4329 | as_warn ((inst.instruction & LOAD_BIT) | |
4330 | ? _("destination register same as write-back base") | |
4331 | : _("source register same as write-back base")); | |
09d92015 MM |
4332 | } |
4333 | ||
c19d1205 ZW |
4334 | /* inst.operands[i] was set up by parse_address. Encode it into an |
4335 | ARM-format mode 2 load or store instruction. If is_t is true, | |
4336 | reject forms that cannot be used with a T instruction (i.e. not | |
4337 | post-indexed). */ | |
a737bd4d | 4338 | static void |
c19d1205 | 4339 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 4340 | { |
c19d1205 | 4341 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 4342 | |
c19d1205 | 4343 | if (inst.operands[i].immisreg) |
09d92015 | 4344 | { |
c19d1205 ZW |
4345 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
4346 | inst.instruction |= inst.operands[i].imm; | |
4347 | if (!inst.operands[i].negative) | |
4348 | inst.instruction |= INDEX_UP; | |
4349 | if (inst.operands[i].shifted) | |
4350 | { | |
4351 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
4352 | inst.instruction |= SHIFT_ROR << 5; | |
4353 | else | |
4354 | { | |
4355 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
4356 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
4357 | } | |
4358 | } | |
09d92015 | 4359 | } |
c19d1205 | 4360 | else /* immediate offset in inst.reloc */ |
09d92015 | 4361 | { |
c19d1205 ZW |
4362 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
4363 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 4364 | } |
09d92015 MM |
4365 | } |
4366 | ||
c19d1205 ZW |
4367 | /* inst.operands[i] was set up by parse_address. Encode it into an |
4368 | ARM-format mode 3 load or store instruction. Reject forms that | |
4369 | cannot be used with such instructions. If is_t is true, reject | |
4370 | forms that cannot be used with a T instruction (i.e. not | |
4371 | post-indexed). */ | |
4372 | static void | |
4373 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 4374 | { |
c19d1205 | 4375 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 4376 | { |
c19d1205 ZW |
4377 | inst.error = _("instruction does not accept scaled register index"); |
4378 | return; | |
09d92015 | 4379 | } |
a737bd4d | 4380 | |
c19d1205 | 4381 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 4382 | |
c19d1205 ZW |
4383 | if (inst.operands[i].immisreg) |
4384 | { | |
4385 | inst.instruction |= inst.operands[i].imm; | |
4386 | if (!inst.operands[i].negative) | |
4387 | inst.instruction |= INDEX_UP; | |
4388 | } | |
4389 | else /* immediate offset in inst.reloc */ | |
4390 | { | |
4391 | inst.instruction |= HWOFFSET_IMM; | |
4392 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
4393 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 4394 | } |
a737bd4d NC |
4395 | } |
4396 | ||
c19d1205 ZW |
4397 | /* inst.operands[i] was set up by parse_address. Encode it into an |
4398 | ARM-format instruction. Reject all forms which cannot be encoded | |
4399 | into a coprocessor load/store instruction. If wb_ok is false, | |
4400 | reject use of writeback; if unind_ok is false, reject use of | |
4401 | unindexed addressing. If reloc_override is not 0, use it instead | |
4402 | of BFD_ARM_CP_OFF_IMM. */ | |
09d92015 | 4403 | |
c19d1205 ZW |
4404 | static int |
4405 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 4406 | { |
c19d1205 | 4407 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 4408 | |
c19d1205 | 4409 | assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 4410 | |
c19d1205 | 4411 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 4412 | { |
c19d1205 ZW |
4413 | assert (!inst.operands[i].writeback); |
4414 | if (!unind_ok) | |
4415 | { | |
4416 | inst.error = _("instruction does not support unindexed addressing"); | |
4417 | return FAIL; | |
4418 | } | |
4419 | inst.instruction |= inst.operands[i].imm; | |
4420 | inst.instruction |= INDEX_UP; | |
4421 | return SUCCESS; | |
09d92015 | 4422 | } |
a737bd4d | 4423 | |
c19d1205 ZW |
4424 | if (inst.operands[i].preind) |
4425 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 4426 | |
c19d1205 | 4427 | if (inst.operands[i].writeback) |
09d92015 | 4428 | { |
c19d1205 ZW |
4429 | if (inst.operands[i].reg == REG_PC) |
4430 | { | |
4431 | inst.error = _("pc may not be used with write-back"); | |
4432 | return FAIL; | |
4433 | } | |
4434 | if (!wb_ok) | |
4435 | { | |
4436 | inst.error = _("instruction does not support writeback"); | |
4437 | return FAIL; | |
4438 | } | |
4439 | inst.instruction |= WRITE_BACK; | |
09d92015 | 4440 | } |
a737bd4d | 4441 | |
c19d1205 ZW |
4442 | if (reloc_override) |
4443 | inst.reloc.type = reloc_override; | |
8f06b2d8 PB |
4444 | else if (thumb_mode) |
4445 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
09d92015 | 4446 | else |
c19d1205 | 4447 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; |
c19d1205 ZW |
4448 | return SUCCESS; |
4449 | } | |
a737bd4d | 4450 | |
c19d1205 ZW |
4451 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
4452 | Determine whether it can be performed with a move instruction; if | |
4453 | it can, convert inst.instruction to that move instruction and | |
4454 | return 1; if it can't, convert inst.instruction to a literal-pool | |
4455 | load and return 0. If this is not a valid thing to do in the | |
4456 | current context, set inst.error and return 1. | |
a737bd4d | 4457 | |
c19d1205 ZW |
4458 | inst.operands[i] describes the destination register. */ |
4459 | ||
4460 | static int | |
4461 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) | |
4462 | { | |
53365c0d PB |
4463 | unsigned long tbit; |
4464 | ||
4465 | if (thumb_p) | |
4466 | tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT; | |
4467 | else | |
4468 | tbit = LOAD_BIT; | |
4469 | ||
4470 | if ((inst.instruction & tbit) == 0) | |
09d92015 | 4471 | { |
c19d1205 ZW |
4472 | inst.error = _("invalid pseudo operation"); |
4473 | return 1; | |
09d92015 | 4474 | } |
c19d1205 | 4475 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
4476 | { |
4477 | inst.error = _("constant expression expected"); | |
c19d1205 | 4478 | return 1; |
09d92015 | 4479 | } |
c19d1205 | 4480 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 4481 | { |
c19d1205 ZW |
4482 | if (thumb_p) |
4483 | { | |
53365c0d | 4484 | if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0) |
c19d1205 ZW |
4485 | { |
4486 | /* This can be done with a mov(1) instruction. */ | |
4487 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
4488 | inst.instruction |= inst.reloc.exp.X_add_number; | |
4489 | return 1; | |
4490 | } | |
4491 | } | |
4492 | else | |
4493 | { | |
4494 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
4495 | if (value != FAIL) | |
4496 | { | |
4497 | /* This can be done with a mov instruction. */ | |
4498 | inst.instruction &= LITERAL_MASK; | |
4499 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
4500 | inst.instruction |= value & 0xfff; | |
4501 | return 1; | |
4502 | } | |
09d92015 | 4503 | |
c19d1205 ZW |
4504 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
4505 | if (value != FAIL) | |
4506 | { | |
4507 | /* This can be done with a mvn instruction. */ | |
4508 | inst.instruction &= LITERAL_MASK; | |
4509 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
4510 | inst.instruction |= value & 0xfff; | |
4511 | return 1; | |
4512 | } | |
4513 | } | |
09d92015 MM |
4514 | } |
4515 | ||
c19d1205 ZW |
4516 | if (add_to_lit_pool () == FAIL) |
4517 | { | |
4518 | inst.error = _("literal pool insertion failed"); | |
4519 | return 1; | |
4520 | } | |
4521 | inst.operands[1].reg = REG_PC; | |
4522 | inst.operands[1].isreg = 1; | |
4523 | inst.operands[1].preind = 1; | |
4524 | inst.reloc.pc_rel = 1; | |
4525 | inst.reloc.type = (thumb_p | |
4526 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
4527 | : (mode_3 | |
4528 | ? BFD_RELOC_ARM_HWLITERAL | |
4529 | : BFD_RELOC_ARM_LITERAL)); | |
4530 | return 0; | |
09d92015 MM |
4531 | } |
4532 | ||
c19d1205 ZW |
4533 | /* Functions for instruction encoding, sorted by subarchitecture. |
4534 | First some generics; their names are taken from the conventional | |
4535 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 4536 | |
a737bd4d | 4537 | static void |
c19d1205 | 4538 | do_noargs (void) |
09d92015 | 4539 | { |
c19d1205 | 4540 | } |
a737bd4d | 4541 | |
c19d1205 ZW |
4542 | static void |
4543 | do_rd (void) | |
4544 | { | |
4545 | inst.instruction |= inst.operands[0].reg << 12; | |
4546 | } | |
a737bd4d | 4547 | |
c19d1205 ZW |
4548 | static void |
4549 | do_rd_rm (void) | |
4550 | { | |
4551 | inst.instruction |= inst.operands[0].reg << 12; | |
4552 | inst.instruction |= inst.operands[1].reg; | |
4553 | } | |
09d92015 | 4554 | |
c19d1205 ZW |
4555 | static void |
4556 | do_rd_rn (void) | |
4557 | { | |
4558 | inst.instruction |= inst.operands[0].reg << 12; | |
4559 | inst.instruction |= inst.operands[1].reg << 16; | |
4560 | } | |
a737bd4d | 4561 | |
c19d1205 ZW |
4562 | static void |
4563 | do_rn_rd (void) | |
4564 | { | |
4565 | inst.instruction |= inst.operands[0].reg << 16; | |
4566 | inst.instruction |= inst.operands[1].reg << 12; | |
4567 | } | |
09d92015 | 4568 | |
c19d1205 ZW |
4569 | static void |
4570 | do_rd_rm_rn (void) | |
4571 | { | |
9a64e435 PB |
4572 | unsigned Rn = inst.operands[2].reg; |
4573 | /* Enforce resutrictions on SWP instruction. */ | |
4574 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) | |
4575 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
4576 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
4577 | inst.instruction |= inst.operands[0].reg << 12; |
4578 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 4579 | inst.instruction |= Rn << 16; |
c19d1205 | 4580 | } |
09d92015 | 4581 | |
c19d1205 ZW |
4582 | static void |
4583 | do_rd_rn_rm (void) | |
4584 | { | |
4585 | inst.instruction |= inst.operands[0].reg << 12; | |
4586 | inst.instruction |= inst.operands[1].reg << 16; | |
4587 | inst.instruction |= inst.operands[2].reg; | |
4588 | } | |
a737bd4d | 4589 | |
c19d1205 ZW |
4590 | static void |
4591 | do_rm_rd_rn (void) | |
4592 | { | |
4593 | inst.instruction |= inst.operands[0].reg; | |
4594 | inst.instruction |= inst.operands[1].reg << 12; | |
4595 | inst.instruction |= inst.operands[2].reg << 16; | |
4596 | } | |
09d92015 | 4597 | |
c19d1205 ZW |
4598 | static void |
4599 | do_imm0 (void) | |
4600 | { | |
4601 | inst.instruction |= inst.operands[0].imm; | |
4602 | } | |
09d92015 | 4603 | |
c19d1205 ZW |
4604 | static void |
4605 | do_rd_cpaddr (void) | |
4606 | { | |
4607 | inst.instruction |= inst.operands[0].reg << 12; | |
4608 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 4609 | } |
a737bd4d | 4610 | |
c19d1205 ZW |
4611 | /* ARM instructions, in alphabetical order by function name (except |
4612 | that wrapper functions appear immediately after the function they | |
4613 | wrap). */ | |
09d92015 | 4614 | |
c19d1205 ZW |
4615 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
4616 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
4617 | |
4618 | static void | |
c19d1205 | 4619 | do_adr (void) |
09d92015 | 4620 | { |
c19d1205 | 4621 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 4622 | |
c19d1205 ZW |
4623 | /* Frag hacking will turn this into a sub instruction if the offset turns |
4624 | out to be negative. */ | |
4625 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 4626 | inst.reloc.pc_rel = 1; |
2fc8bdac | 4627 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 4628 | } |
b99bd4ef | 4629 | |
c19d1205 ZW |
4630 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
4631 | into a relative address of the form: | |
4632 | add rd, pc, #low(label-.-8)" | |
4633 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 4634 | |
c19d1205 ZW |
4635 | static void |
4636 | do_adrl (void) | |
4637 | { | |
4638 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 4639 | |
c19d1205 ZW |
4640 | /* Frag hacking will turn this into a sub instruction if the offset turns |
4641 | out to be negative. */ | |
4642 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
4643 | inst.reloc.pc_rel = 1; |
4644 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 4645 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
4646 | } |
4647 | ||
b99bd4ef | 4648 | static void |
c19d1205 | 4649 | do_arit (void) |
b99bd4ef | 4650 | { |
c19d1205 ZW |
4651 | if (!inst.operands[1].present) |
4652 | inst.operands[1].reg = inst.operands[0].reg; | |
4653 | inst.instruction |= inst.operands[0].reg << 12; | |
4654 | inst.instruction |= inst.operands[1].reg << 16; | |
4655 | encode_arm_shifter_operand (2); | |
4656 | } | |
b99bd4ef | 4657 | |
62b3e311 PB |
4658 | static void |
4659 | do_barrier (void) | |
4660 | { | |
4661 | if (inst.operands[0].present) | |
4662 | { | |
4663 | constraint ((inst.instruction & 0xf0) != 0x40 | |
4664 | && inst.operands[0].imm != 0xf, | |
4665 | "bad barrier type"); | |
4666 | inst.instruction |= inst.operands[0].imm; | |
4667 | } | |
4668 | else | |
4669 | inst.instruction |= 0xf; | |
4670 | } | |
4671 | ||
c19d1205 ZW |
4672 | static void |
4673 | do_bfc (void) | |
4674 | { | |
4675 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
4676 | constraint (msb > 32, _("bit-field extends past end of register")); | |
4677 | /* The instruction encoding stores the LSB and MSB, | |
4678 | not the LSB and width. */ | |
4679 | inst.instruction |= inst.operands[0].reg << 12; | |
4680 | inst.instruction |= inst.operands[1].imm << 7; | |
4681 | inst.instruction |= (msb - 1) << 16; | |
4682 | } | |
b99bd4ef | 4683 | |
c19d1205 ZW |
4684 | static void |
4685 | do_bfi (void) | |
4686 | { | |
4687 | unsigned int msb; | |
b99bd4ef | 4688 | |
c19d1205 ZW |
4689 | /* #0 in second position is alternative syntax for bfc, which is |
4690 | the same instruction but with REG_PC in the Rm field. */ | |
4691 | if (!inst.operands[1].isreg) | |
4692 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 4693 | |
c19d1205 ZW |
4694 | msb = inst.operands[2].imm + inst.operands[3].imm; |
4695 | constraint (msb > 32, _("bit-field extends past end of register")); | |
4696 | /* The instruction encoding stores the LSB and MSB, | |
4697 | not the LSB and width. */ | |
4698 | inst.instruction |= inst.operands[0].reg << 12; | |
4699 | inst.instruction |= inst.operands[1].reg; | |
4700 | inst.instruction |= inst.operands[2].imm << 7; | |
4701 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
4702 | } |
4703 | ||
b99bd4ef | 4704 | static void |
c19d1205 | 4705 | do_bfx (void) |
b99bd4ef | 4706 | { |
c19d1205 ZW |
4707 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
4708 | _("bit-field extends past end of register")); | |
4709 | inst.instruction |= inst.operands[0].reg << 12; | |
4710 | inst.instruction |= inst.operands[1].reg; | |
4711 | inst.instruction |= inst.operands[2].imm << 7; | |
4712 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
4713 | } | |
09d92015 | 4714 | |
c19d1205 ZW |
4715 | /* ARM V5 breakpoint instruction (argument parse) |
4716 | BKPT <16 bit unsigned immediate> | |
4717 | Instruction is not conditional. | |
4718 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
4719 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 4720 | |
c19d1205 ZW |
4721 | static void |
4722 | do_bkpt (void) | |
4723 | { | |
4724 | /* Top 12 of 16 bits to bits 19:8. */ | |
4725 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 4726 | |
c19d1205 ZW |
4727 | /* Bottom 4 of 16 bits to bits 3:0. */ |
4728 | inst.instruction |= inst.operands[0].imm & 0xf; | |
4729 | } | |
09d92015 | 4730 | |
c19d1205 ZW |
4731 | static void |
4732 | encode_branch (int default_reloc) | |
4733 | { | |
4734 | if (inst.operands[0].hasreloc) | |
4735 | { | |
4736 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
4737 | _("the only suffix valid here is '(plt)'")); | |
4738 | inst.reloc.type = BFD_RELOC_ARM_PLT32; | |
c19d1205 | 4739 | } |
b99bd4ef | 4740 | else |
c19d1205 ZW |
4741 | { |
4742 | inst.reloc.type = default_reloc; | |
c19d1205 | 4743 | } |
2fc8bdac | 4744 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
4745 | } |
4746 | ||
b99bd4ef | 4747 | static void |
c19d1205 | 4748 | do_branch (void) |
b99bd4ef | 4749 | { |
39b41c9c PB |
4750 | #ifdef OBJ_ELF |
4751 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
4752 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
4753 | else | |
4754 | #endif | |
4755 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
4756 | } | |
4757 | ||
4758 | static void | |
4759 | do_bl (void) | |
4760 | { | |
4761 | #ifdef OBJ_ELF | |
4762 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
4763 | { | |
4764 | if (inst.cond == COND_ALWAYS) | |
4765 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
4766 | else | |
4767 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
4768 | } | |
4769 | else | |
4770 | #endif | |
4771 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 4772 | } |
b99bd4ef | 4773 | |
c19d1205 ZW |
4774 | /* ARM V5 branch-link-exchange instruction (argument parse) |
4775 | BLX <target_addr> ie BLX(1) | |
4776 | BLX{<condition>} <Rm> ie BLX(2) | |
4777 | Unfortunately, there are two different opcodes for this mnemonic. | |
4778 | So, the insns[].value is not used, and the code here zaps values | |
4779 | into inst.instruction. | |
4780 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 4781 | |
c19d1205 ZW |
4782 | static void |
4783 | do_blx (void) | |
4784 | { | |
4785 | if (inst.operands[0].isreg) | |
b99bd4ef | 4786 | { |
c19d1205 ZW |
4787 | /* Arg is a register; the opcode provided by insns[] is correct. |
4788 | It is not illegal to do "blx pc", just useless. */ | |
4789 | if (inst.operands[0].reg == REG_PC) | |
4790 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 4791 | |
c19d1205 ZW |
4792 | inst.instruction |= inst.operands[0].reg; |
4793 | } | |
4794 | else | |
b99bd4ef | 4795 | { |
c19d1205 ZW |
4796 | /* Arg is an address; this instruction cannot be executed |
4797 | conditionally, and the opcode must be adjusted. */ | |
4798 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
2fc8bdac | 4799 | inst.instruction = 0xfa000000; |
39b41c9c PB |
4800 | #ifdef OBJ_ELF |
4801 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
4802 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
4803 | else | |
4804 | #endif | |
4805 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); | |
b99bd4ef | 4806 | } |
c19d1205 ZW |
4807 | } |
4808 | ||
4809 | static void | |
4810 | do_bx (void) | |
4811 | { | |
4812 | if (inst.operands[0].reg == REG_PC) | |
4813 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 4814 | |
c19d1205 | 4815 | inst.instruction |= inst.operands[0].reg; |
09d92015 MM |
4816 | } |
4817 | ||
c19d1205 ZW |
4818 | |
4819 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
4820 | |
4821 | static void | |
c19d1205 | 4822 | do_bxj (void) |
a737bd4d | 4823 | { |
c19d1205 ZW |
4824 | if (inst.operands[0].reg == REG_PC) |
4825 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
4826 | ||
4827 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
4828 | } |
4829 | ||
c19d1205 ZW |
4830 | /* Co-processor data operation: |
4831 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
4832 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
4833 | static void | |
4834 | do_cdp (void) | |
4835 | { | |
4836 | inst.instruction |= inst.operands[0].reg << 8; | |
4837 | inst.instruction |= inst.operands[1].imm << 20; | |
4838 | inst.instruction |= inst.operands[2].reg << 12; | |
4839 | inst.instruction |= inst.operands[3].reg << 16; | |
4840 | inst.instruction |= inst.operands[4].reg; | |
4841 | inst.instruction |= inst.operands[5].imm << 5; | |
4842 | } | |
a737bd4d NC |
4843 | |
4844 | static void | |
c19d1205 | 4845 | do_cmp (void) |
a737bd4d | 4846 | { |
c19d1205 ZW |
4847 | inst.instruction |= inst.operands[0].reg << 16; |
4848 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
4849 | } |
4850 | ||
c19d1205 ZW |
4851 | /* Transfer between coprocessor and ARM registers. |
4852 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
4853 | MRC2 | |
4854 | MCR{cond} | |
4855 | MCR2 | |
4856 | ||
4857 | No special properties. */ | |
09d92015 MM |
4858 | |
4859 | static void | |
c19d1205 | 4860 | do_co_reg (void) |
09d92015 | 4861 | { |
c19d1205 ZW |
4862 | inst.instruction |= inst.operands[0].reg << 8; |
4863 | inst.instruction |= inst.operands[1].imm << 21; | |
4864 | inst.instruction |= inst.operands[2].reg << 12; | |
4865 | inst.instruction |= inst.operands[3].reg << 16; | |
4866 | inst.instruction |= inst.operands[4].reg; | |
4867 | inst.instruction |= inst.operands[5].imm << 5; | |
4868 | } | |
09d92015 | 4869 | |
c19d1205 ZW |
4870 | /* Transfer between coprocessor register and pair of ARM registers. |
4871 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
4872 | MCRR2 | |
4873 | MRRC{cond} | |
4874 | MRRC2 | |
b99bd4ef | 4875 | |
c19d1205 | 4876 | Two XScale instructions are special cases of these: |
09d92015 | 4877 | |
c19d1205 ZW |
4878 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
4879 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 4880 | |
c19d1205 | 4881 | Result unpredicatable if Rd or Rn is R15. */ |
a737bd4d | 4882 | |
c19d1205 ZW |
4883 | static void |
4884 | do_co_reg2c (void) | |
4885 | { | |
4886 | inst.instruction |= inst.operands[0].reg << 8; | |
4887 | inst.instruction |= inst.operands[1].imm << 4; | |
4888 | inst.instruction |= inst.operands[2].reg << 12; | |
4889 | inst.instruction |= inst.operands[3].reg << 16; | |
4890 | inst.instruction |= inst.operands[4].reg; | |
b99bd4ef NC |
4891 | } |
4892 | ||
c19d1205 ZW |
4893 | static void |
4894 | do_cpsi (void) | |
4895 | { | |
4896 | inst.instruction |= inst.operands[0].imm << 6; | |
4897 | inst.instruction |= inst.operands[1].imm; | |
4898 | } | |
b99bd4ef | 4899 | |
62b3e311 PB |
4900 | static void |
4901 | do_dbg (void) | |
4902 | { | |
4903 | inst.instruction |= inst.operands[0].imm; | |
4904 | } | |
4905 | ||
b99bd4ef | 4906 | static void |
c19d1205 | 4907 | do_it (void) |
b99bd4ef | 4908 | { |
c19d1205 ZW |
4909 | /* There is no IT instruction in ARM mode. We |
4910 | process it but do not generate code for it. */ | |
4911 | inst.size = 0; | |
09d92015 | 4912 | } |
b99bd4ef | 4913 | |
09d92015 | 4914 | static void |
c19d1205 | 4915 | do_ldmstm (void) |
ea6ef066 | 4916 | { |
c19d1205 ZW |
4917 | int base_reg = inst.operands[0].reg; |
4918 | int range = inst.operands[1].imm; | |
ea6ef066 | 4919 | |
c19d1205 ZW |
4920 | inst.instruction |= base_reg << 16; |
4921 | inst.instruction |= range; | |
ea6ef066 | 4922 | |
c19d1205 ZW |
4923 | if (inst.operands[1].writeback) |
4924 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 4925 | |
c19d1205 | 4926 | if (inst.operands[0].writeback) |
ea6ef066 | 4927 | { |
c19d1205 ZW |
4928 | inst.instruction |= WRITE_BACK; |
4929 | /* Check for unpredictable uses of writeback. */ | |
4930 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 4931 | { |
c19d1205 ZW |
4932 | /* Not allowed in LDM type 2. */ |
4933 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
4934 | && ((range & (1 << REG_PC)) == 0)) | |
4935 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
4936 | /* Only allowed if base reg not in list for other types. */ | |
4937 | else if (range & (1 << base_reg)) | |
4938 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
4939 | } | |
4940 | else /* STM. */ | |
4941 | { | |
4942 | /* Not allowed for type 2. */ | |
4943 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
4944 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
4945 | /* Only allowed if base reg not in list, or first in list. */ | |
4946 | else if ((range & (1 << base_reg)) | |
4947 | && (range & ((1 << base_reg) - 1))) | |
4948 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 4949 | } |
ea6ef066 | 4950 | } |
a737bd4d NC |
4951 | } |
4952 | ||
c19d1205 ZW |
4953 | /* ARMv5TE load-consecutive (argument parse) |
4954 | Mode is like LDRH. | |
4955 | ||
4956 | LDRccD R, mode | |
4957 | STRccD R, mode. */ | |
4958 | ||
a737bd4d | 4959 | static void |
c19d1205 | 4960 | do_ldrd (void) |
a737bd4d | 4961 | { |
c19d1205 ZW |
4962 | constraint (inst.operands[0].reg % 2 != 0, |
4963 | _("first destination register must be even")); | |
4964 | constraint (inst.operands[1].present | |
4965 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
4966 | _("can only load two consecutive registers")); | |
4967 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
4968 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 4969 | |
c19d1205 ZW |
4970 | if (!inst.operands[1].present) |
4971 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
4972 | ||
4973 | if (inst.instruction & LOAD_BIT) | |
a737bd4d | 4974 | { |
c19d1205 ZW |
4975 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
4976 | register and the first register written; we have to diagnose | |
4977 | overlap between the base and the second register written here. */ | |
ea6ef066 | 4978 | |
c19d1205 ZW |
4979 | if (inst.operands[2].reg == inst.operands[1].reg |
4980 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
4981 | as_warn (_("base register written back, and overlaps " | |
4982 | "second destination register")); | |
b05fe5cf | 4983 | |
c19d1205 ZW |
4984 | /* For an index-register load, the index register must not overlap the |
4985 | destination (even if not write-back). */ | |
4986 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
4987 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
4988 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 4989 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 4990 | } |
c19d1205 ZW |
4991 | |
4992 | inst.instruction |= inst.operands[0].reg << 12; | |
4993 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
4994 | } |
4995 | ||
4996 | static void | |
c19d1205 | 4997 | do_ldrex (void) |
b05fe5cf | 4998 | { |
c19d1205 ZW |
4999 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
5000 | || inst.operands[1].postind || inst.operands[1].writeback | |
5001 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
5002 | || inst.operands[1].negative |
5003 | /* This can arise if the programmer has written | |
5004 | strex rN, rM, foo | |
5005 | or if they have mistakenly used a register name as the last | |
5006 | operand, eg: | |
5007 | strex rN, rM, rX | |
5008 | It is very difficult to distinguish between these two cases | |
5009 | because "rX" might actually be a label. ie the register | |
5010 | name has been occluded by a symbol of the same name. So we | |
5011 | just generate a general 'bad addressing mode' type error | |
5012 | message and leave it up to the programmer to discover the | |
5013 | true cause and fix their mistake. */ | |
5014 | || (inst.operands[1].reg == REG_PC), | |
5015 | BAD_ADDR_MODE); | |
b05fe5cf | 5016 | |
c19d1205 ZW |
5017 | constraint (inst.reloc.exp.X_op != O_constant |
5018 | || inst.reloc.exp.X_add_number != 0, | |
5019 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 5020 | |
c19d1205 ZW |
5021 | inst.instruction |= inst.operands[0].reg << 12; |
5022 | inst.instruction |= inst.operands[1].reg << 16; | |
5023 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
5024 | } |
5025 | ||
5026 | static void | |
c19d1205 | 5027 | do_ldrexd (void) |
b05fe5cf | 5028 | { |
c19d1205 ZW |
5029 | constraint (inst.operands[0].reg % 2 != 0, |
5030 | _("even register required")); | |
5031 | constraint (inst.operands[1].present | |
5032 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
5033 | _("can only load two consecutive registers")); | |
5034 | /* If op 1 were present and equal to PC, this function wouldn't | |
5035 | have been called in the first place. */ | |
5036 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 5037 | |
c19d1205 ZW |
5038 | inst.instruction |= inst.operands[0].reg << 12; |
5039 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
5040 | } |
5041 | ||
5042 | static void | |
c19d1205 | 5043 | do_ldst (void) |
b05fe5cf | 5044 | { |
c19d1205 ZW |
5045 | inst.instruction |= inst.operands[0].reg << 12; |
5046 | if (!inst.operands[1].isreg) | |
5047 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 5048 | return; |
c19d1205 | 5049 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
5050 | } |
5051 | ||
5052 | static void | |
c19d1205 | 5053 | do_ldstt (void) |
b05fe5cf | 5054 | { |
c19d1205 ZW |
5055 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
5056 | reject [Rn,...]. */ | |
5057 | if (inst.operands[1].preind) | |
b05fe5cf | 5058 | { |
c19d1205 ZW |
5059 | constraint (inst.reloc.exp.X_op != O_constant || |
5060 | inst.reloc.exp.X_add_number != 0, | |
5061 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 5062 | |
c19d1205 ZW |
5063 | inst.operands[1].preind = 0; |
5064 | inst.operands[1].postind = 1; | |
5065 | inst.operands[1].writeback = 1; | |
b05fe5cf | 5066 | } |
c19d1205 ZW |
5067 | inst.instruction |= inst.operands[0].reg << 12; |
5068 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
5069 | } | |
b05fe5cf | 5070 | |
c19d1205 | 5071 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 5072 | |
c19d1205 ZW |
5073 | static void |
5074 | do_ldstv4 (void) | |
5075 | { | |
5076 | inst.instruction |= inst.operands[0].reg << 12; | |
5077 | if (!inst.operands[1].isreg) | |
5078 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 5079 | return; |
c19d1205 | 5080 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
5081 | } |
5082 | ||
5083 | static void | |
c19d1205 | 5084 | do_ldsttv4 (void) |
b05fe5cf | 5085 | { |
c19d1205 ZW |
5086 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
5087 | reject [Rn,...]. */ | |
5088 | if (inst.operands[1].preind) | |
b05fe5cf | 5089 | { |
c19d1205 ZW |
5090 | constraint (inst.reloc.exp.X_op != O_constant || |
5091 | inst.reloc.exp.X_add_number != 0, | |
5092 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 5093 | |
c19d1205 ZW |
5094 | inst.operands[1].preind = 0; |
5095 | inst.operands[1].postind = 1; | |
5096 | inst.operands[1].writeback = 1; | |
b05fe5cf | 5097 | } |
c19d1205 ZW |
5098 | inst.instruction |= inst.operands[0].reg << 12; |
5099 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
5100 | } | |
b05fe5cf | 5101 | |
c19d1205 ZW |
5102 | /* Co-processor register load/store. |
5103 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
5104 | static void | |
5105 | do_lstc (void) | |
5106 | { | |
5107 | inst.instruction |= inst.operands[0].reg << 8; | |
5108 | inst.instruction |= inst.operands[1].reg << 12; | |
5109 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
5110 | } |
5111 | ||
b05fe5cf | 5112 | static void |
c19d1205 | 5113 | do_mlas (void) |
b05fe5cf | 5114 | { |
c19d1205 ZW |
5115 | /* This restriction does not apply to mls (nor to mla in v6, but |
5116 | that's hard to detect at present). */ | |
5117 | if (inst.operands[0].reg == inst.operands[1].reg | |
5118 | && !(inst.instruction & 0x00400000)) | |
5119 | as_tsktsk (_("rd and rm should be different in mla")); | |
b05fe5cf | 5120 | |
c19d1205 ZW |
5121 | inst.instruction |= inst.operands[0].reg << 16; |
5122 | inst.instruction |= inst.operands[1].reg; | |
5123 | inst.instruction |= inst.operands[2].reg << 8; | |
5124 | inst.instruction |= inst.operands[3].reg << 12; | |
b05fe5cf | 5125 | |
c19d1205 | 5126 | } |
b05fe5cf | 5127 | |
c19d1205 ZW |
5128 | static void |
5129 | do_mov (void) | |
5130 | { | |
5131 | inst.instruction |= inst.operands[0].reg << 12; | |
5132 | encode_arm_shifter_operand (1); | |
5133 | } | |
b05fe5cf | 5134 | |
c19d1205 ZW |
5135 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
5136 | static void | |
5137 | do_mov16 (void) | |
5138 | { | |
5139 | inst.instruction |= inst.operands[0].reg << 12; | |
b05fe5cf | 5140 | /* The value is in two pieces: 0:11, 16:19. */ |
c19d1205 ZW |
5141 | inst.instruction |= (inst.operands[1].imm & 0x00000fff); |
5142 | inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4; | |
b05fe5cf | 5143 | } |
b99bd4ef NC |
5144 | |
5145 | static void | |
c19d1205 | 5146 | do_mrs (void) |
b99bd4ef | 5147 | { |
c19d1205 ZW |
5148 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
5149 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
5150 | != (PSR_c|PSR_f), | |
5151 | _("'CPSR' or 'SPSR' expected")); | |
5152 | inst.instruction |= inst.operands[0].reg << 12; | |
5153 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
5154 | } | |
b99bd4ef | 5155 | |
c19d1205 ZW |
5156 | /* Two possible forms: |
5157 | "{C|S}PSR_<field>, Rm", | |
5158 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 5159 | |
c19d1205 ZW |
5160 | static void |
5161 | do_msr (void) | |
5162 | { | |
5163 | inst.instruction |= inst.operands[0].imm; | |
5164 | if (inst.operands[1].isreg) | |
5165 | inst.instruction |= inst.operands[1].reg; | |
5166 | else | |
b99bd4ef | 5167 | { |
c19d1205 ZW |
5168 | inst.instruction |= INST_IMMEDIATE; |
5169 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
5170 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 5171 | } |
b99bd4ef NC |
5172 | } |
5173 | ||
c19d1205 ZW |
5174 | static void |
5175 | do_mul (void) | |
a737bd4d | 5176 | { |
c19d1205 ZW |
5177 | if (!inst.operands[2].present) |
5178 | inst.operands[2].reg = inst.operands[0].reg; | |
5179 | inst.instruction |= inst.operands[0].reg << 16; | |
5180 | inst.instruction |= inst.operands[1].reg; | |
5181 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 5182 | |
c19d1205 ZW |
5183 | if (inst.operands[0].reg == inst.operands[1].reg) |
5184 | as_tsktsk (_("rd and rm should be different in mul")); | |
a737bd4d NC |
5185 | } |
5186 | ||
c19d1205 ZW |
5187 | /* Long Multiply Parser |
5188 | UMULL RdLo, RdHi, Rm, Rs | |
5189 | SMULL RdLo, RdHi, Rm, Rs | |
5190 | UMLAL RdLo, RdHi, Rm, Rs | |
5191 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
5192 | |
5193 | static void | |
c19d1205 | 5194 | do_mull (void) |
b99bd4ef | 5195 | { |
c19d1205 ZW |
5196 | inst.instruction |= inst.operands[0].reg << 12; |
5197 | inst.instruction |= inst.operands[1].reg << 16; | |
5198 | inst.instruction |= inst.operands[2].reg; | |
5199 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 5200 | |
c19d1205 ZW |
5201 | /* rdhi, rdlo and rm must all be different. */ |
5202 | if (inst.operands[0].reg == inst.operands[1].reg | |
5203 | || inst.operands[0].reg == inst.operands[2].reg | |
5204 | || inst.operands[1].reg == inst.operands[2].reg) | |
5205 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); | |
5206 | } | |
b99bd4ef | 5207 | |
c19d1205 ZW |
5208 | static void |
5209 | do_nop (void) | |
5210 | { | |
5211 | if (inst.operands[0].present) | |
5212 | { | |
5213 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
5214 | inst.instruction &= 0xf0000000; | |
5215 | inst.instruction |= 0x0320f000 + inst.operands[0].imm; | |
5216 | } | |
b99bd4ef NC |
5217 | } |
5218 | ||
c19d1205 ZW |
5219 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
5220 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
5221 | Condition defaults to COND_ALWAYS. | |
5222 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
5223 | |
5224 | static void | |
c19d1205 | 5225 | do_pkhbt (void) |
b99bd4ef | 5226 | { |
c19d1205 ZW |
5227 | inst.instruction |= inst.operands[0].reg << 12; |
5228 | inst.instruction |= inst.operands[1].reg << 16; | |
5229 | inst.instruction |= inst.operands[2].reg; | |
5230 | if (inst.operands[3].present) | |
5231 | encode_arm_shift (3); | |
5232 | } | |
b99bd4ef | 5233 | |
c19d1205 | 5234 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 5235 | |
c19d1205 ZW |
5236 | static void |
5237 | do_pkhtb (void) | |
5238 | { | |
5239 | if (!inst.operands[3].present) | |
b99bd4ef | 5240 | { |
c19d1205 ZW |
5241 | /* If the shift specifier is omitted, turn the instruction |
5242 | into pkhbt rd, rm, rn. */ | |
5243 | inst.instruction &= 0xfff00010; | |
5244 | inst.instruction |= inst.operands[0].reg << 12; | |
5245 | inst.instruction |= inst.operands[1].reg; | |
5246 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
5247 | } |
5248 | else | |
5249 | { | |
c19d1205 ZW |
5250 | inst.instruction |= inst.operands[0].reg << 12; |
5251 | inst.instruction |= inst.operands[1].reg << 16; | |
5252 | inst.instruction |= inst.operands[2].reg; | |
5253 | encode_arm_shift (3); | |
b99bd4ef NC |
5254 | } |
5255 | } | |
5256 | ||
c19d1205 ZW |
5257 | /* ARMv5TE: Preload-Cache |
5258 | ||
5259 | PLD <addr_mode> | |
5260 | ||
5261 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
5262 | |
5263 | static void | |
c19d1205 | 5264 | do_pld (void) |
b99bd4ef | 5265 | { |
c19d1205 ZW |
5266 | constraint (!inst.operands[0].isreg, |
5267 | _("'[' expected after PLD mnemonic")); | |
5268 | constraint (inst.operands[0].postind, | |
5269 | _("post-indexed expression used in preload instruction")); | |
5270 | constraint (inst.operands[0].writeback, | |
5271 | _("writeback used in preload instruction")); | |
5272 | constraint (!inst.operands[0].preind, | |
5273 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
5274 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
5275 | } | |
b99bd4ef | 5276 | |
62b3e311 PB |
5277 | /* ARMv7: PLI <addr_mode> */ |
5278 | static void | |
5279 | do_pli (void) | |
5280 | { | |
5281 | constraint (!inst.operands[0].isreg, | |
5282 | _("'[' expected after PLI mnemonic")); | |
5283 | constraint (inst.operands[0].postind, | |
5284 | _("post-indexed expression used in preload instruction")); | |
5285 | constraint (inst.operands[0].writeback, | |
5286 | _("writeback used in preload instruction")); | |
5287 | constraint (!inst.operands[0].preind, | |
5288 | _("unindexed addressing used in preload instruction")); | |
5289 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); | |
5290 | inst.instruction &= ~PRE_INDEX; | |
5291 | } | |
5292 | ||
c19d1205 ZW |
5293 | static void |
5294 | do_push_pop (void) | |
5295 | { | |
5296 | inst.operands[1] = inst.operands[0]; | |
5297 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
5298 | inst.operands[0].isreg = 1; | |
5299 | inst.operands[0].writeback = 1; | |
5300 | inst.operands[0].reg = REG_SP; | |
5301 | do_ldmstm (); | |
5302 | } | |
b99bd4ef | 5303 | |
c19d1205 ZW |
5304 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
5305 | word at the specified address and the following word | |
5306 | respectively. | |
5307 | Unconditionally executed. | |
5308 | Error if Rn is R15. */ | |
b99bd4ef | 5309 | |
c19d1205 ZW |
5310 | static void |
5311 | do_rfe (void) | |
5312 | { | |
5313 | inst.instruction |= inst.operands[0].reg << 16; | |
5314 | if (inst.operands[0].writeback) | |
5315 | inst.instruction |= WRITE_BACK; | |
5316 | } | |
b99bd4ef | 5317 | |
c19d1205 | 5318 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 5319 | |
c19d1205 ZW |
5320 | static void |
5321 | do_ssat (void) | |
5322 | { | |
5323 | inst.instruction |= inst.operands[0].reg << 12; | |
5324 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
5325 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 5326 | |
c19d1205 ZW |
5327 | if (inst.operands[3].present) |
5328 | encode_arm_shift (3); | |
b99bd4ef NC |
5329 | } |
5330 | ||
c19d1205 | 5331 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
5332 | |
5333 | static void | |
c19d1205 | 5334 | do_usat (void) |
b99bd4ef | 5335 | { |
c19d1205 ZW |
5336 | inst.instruction |= inst.operands[0].reg << 12; |
5337 | inst.instruction |= inst.operands[1].imm << 16; | |
5338 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 5339 | |
c19d1205 ZW |
5340 | if (inst.operands[3].present) |
5341 | encode_arm_shift (3); | |
b99bd4ef NC |
5342 | } |
5343 | ||
c19d1205 | 5344 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
5345 | |
5346 | static void | |
c19d1205 | 5347 | do_ssat16 (void) |
09d92015 | 5348 | { |
c19d1205 ZW |
5349 | inst.instruction |= inst.operands[0].reg << 12; |
5350 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
5351 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
5352 | } |
5353 | ||
c19d1205 ZW |
5354 | static void |
5355 | do_usat16 (void) | |
a737bd4d | 5356 | { |
c19d1205 ZW |
5357 | inst.instruction |= inst.operands[0].reg << 12; |
5358 | inst.instruction |= inst.operands[1].imm << 16; | |
5359 | inst.instruction |= inst.operands[2].reg; | |
5360 | } | |
a737bd4d | 5361 | |
c19d1205 ZW |
5362 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
5363 | preserving the other bits. | |
a737bd4d | 5364 | |
c19d1205 ZW |
5365 | setend <endian_specifier>, where <endian_specifier> is either |
5366 | BE or LE. */ | |
a737bd4d | 5367 | |
c19d1205 ZW |
5368 | static void |
5369 | do_setend (void) | |
5370 | { | |
5371 | if (inst.operands[0].imm) | |
5372 | inst.instruction |= 0x200; | |
a737bd4d NC |
5373 | } |
5374 | ||
5375 | static void | |
c19d1205 | 5376 | do_shift (void) |
a737bd4d | 5377 | { |
c19d1205 ZW |
5378 | unsigned int Rm = (inst.operands[1].present |
5379 | ? inst.operands[1].reg | |
5380 | : inst.operands[0].reg); | |
a737bd4d | 5381 | |
c19d1205 ZW |
5382 | inst.instruction |= inst.operands[0].reg << 12; |
5383 | inst.instruction |= Rm; | |
5384 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 5385 | { |
c19d1205 ZW |
5386 | inst.instruction |= inst.operands[2].reg << 8; |
5387 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
5388 | } |
5389 | else | |
c19d1205 | 5390 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
5391 | } |
5392 | ||
09d92015 | 5393 | static void |
3eb17e6b | 5394 | do_smc (void) |
09d92015 | 5395 | { |
3eb17e6b | 5396 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 5397 | inst.reloc.pc_rel = 0; |
09d92015 MM |
5398 | } |
5399 | ||
09d92015 | 5400 | static void |
c19d1205 | 5401 | do_swi (void) |
09d92015 | 5402 | { |
c19d1205 ZW |
5403 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
5404 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
5405 | } |
5406 | ||
c19d1205 ZW |
5407 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
5408 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
5409 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
5410 | Error if any register is R15. */ | |
e16bb312 | 5411 | |
c19d1205 ZW |
5412 | static void |
5413 | do_smla (void) | |
e16bb312 | 5414 | { |
c19d1205 ZW |
5415 | inst.instruction |= inst.operands[0].reg << 16; |
5416 | inst.instruction |= inst.operands[1].reg; | |
5417 | inst.instruction |= inst.operands[2].reg << 8; | |
5418 | inst.instruction |= inst.operands[3].reg << 12; | |
5419 | } | |
a737bd4d | 5420 | |
c19d1205 ZW |
5421 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
5422 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
5423 | Error if any register is R15. | |
5424 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 5425 | |
c19d1205 ZW |
5426 | static void |
5427 | do_smlal (void) | |
5428 | { | |
5429 | inst.instruction |= inst.operands[0].reg << 12; | |
5430 | inst.instruction |= inst.operands[1].reg << 16; | |
5431 | inst.instruction |= inst.operands[2].reg; | |
5432 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 5433 | |
c19d1205 ZW |
5434 | if (inst.operands[0].reg == inst.operands[1].reg) |
5435 | as_tsktsk (_("rdhi and rdlo must be different")); | |
5436 | } | |
a737bd4d | 5437 | |
c19d1205 ZW |
5438 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
5439 | SMULxy{cond} Rd,Rm,Rs | |
5440 | Error if any register is R15. */ | |
a737bd4d | 5441 | |
c19d1205 ZW |
5442 | static void |
5443 | do_smul (void) | |
5444 | { | |
5445 | inst.instruction |= inst.operands[0].reg << 16; | |
5446 | inst.instruction |= inst.operands[1].reg; | |
5447 | inst.instruction |= inst.operands[2].reg << 8; | |
5448 | } | |
a737bd4d | 5449 | |
c19d1205 | 5450 | /* ARM V6 srs (argument parse). */ |
a737bd4d | 5451 | |
c19d1205 ZW |
5452 | static void |
5453 | do_srs (void) | |
5454 | { | |
5455 | inst.instruction |= inst.operands[0].imm; | |
5456 | if (inst.operands[0].writeback) | |
5457 | inst.instruction |= WRITE_BACK; | |
5458 | } | |
a737bd4d | 5459 | |
c19d1205 | 5460 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 5461 | |
c19d1205 ZW |
5462 | static void |
5463 | do_strex (void) | |
5464 | { | |
5465 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
5466 | || inst.operands[2].postind || inst.operands[2].writeback | |
5467 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
5468 | || inst.operands[2].negative |
5469 | /* See comment in do_ldrex(). */ | |
5470 | || (inst.operands[2].reg == REG_PC), | |
5471 | BAD_ADDR_MODE); | |
a737bd4d | 5472 | |
c19d1205 ZW |
5473 | constraint (inst.operands[0].reg == inst.operands[1].reg |
5474 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 5475 | |
c19d1205 ZW |
5476 | constraint (inst.reloc.exp.X_op != O_constant |
5477 | || inst.reloc.exp.X_add_number != 0, | |
5478 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 5479 | |
c19d1205 ZW |
5480 | inst.instruction |= inst.operands[0].reg << 12; |
5481 | inst.instruction |= inst.operands[1].reg; | |
5482 | inst.instruction |= inst.operands[2].reg << 16; | |
5483 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
5484 | } |
5485 | ||
5486 | static void | |
c19d1205 | 5487 | do_strexd (void) |
e16bb312 | 5488 | { |
c19d1205 ZW |
5489 | constraint (inst.operands[1].reg % 2 != 0, |
5490 | _("even register required")); | |
5491 | constraint (inst.operands[2].present | |
5492 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
5493 | _("can only store two consecutive registers")); | |
5494 | /* If op 2 were present and equal to PC, this function wouldn't | |
5495 | have been called in the first place. */ | |
5496 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 5497 | |
c19d1205 ZW |
5498 | constraint (inst.operands[0].reg == inst.operands[1].reg |
5499 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
5500 | || inst.operands[0].reg == inst.operands[3].reg, | |
5501 | BAD_OVERLAP); | |
e16bb312 | 5502 | |
c19d1205 ZW |
5503 | inst.instruction |= inst.operands[0].reg << 12; |
5504 | inst.instruction |= inst.operands[1].reg; | |
5505 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
5506 | } |
5507 | ||
c19d1205 ZW |
5508 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
5509 | extends it to 32-bits, and adds the result to a value in another | |
5510 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
5511 | before extracting the 16-bit value. | |
5512 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
5513 | Condition defaults to COND_ALWAYS. | |
5514 | Error if any register uses R15. */ | |
5515 | ||
e16bb312 | 5516 | static void |
c19d1205 | 5517 | do_sxtah (void) |
e16bb312 | 5518 | { |
c19d1205 ZW |
5519 | inst.instruction |= inst.operands[0].reg << 12; |
5520 | inst.instruction |= inst.operands[1].reg << 16; | |
5521 | inst.instruction |= inst.operands[2].reg; | |
5522 | inst.instruction |= inst.operands[3].imm << 10; | |
5523 | } | |
e16bb312 | 5524 | |
c19d1205 | 5525 | /* ARM V6 SXTH. |
e16bb312 | 5526 | |
c19d1205 ZW |
5527 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
5528 | Condition defaults to COND_ALWAYS. | |
5529 | Error if any register uses R15. */ | |
e16bb312 NC |
5530 | |
5531 | static void | |
c19d1205 | 5532 | do_sxth (void) |
e16bb312 | 5533 | { |
c19d1205 ZW |
5534 | inst.instruction |= inst.operands[0].reg << 12; |
5535 | inst.instruction |= inst.operands[1].reg; | |
5536 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 5537 | } |
c19d1205 ZW |
5538 | \f |
5539 | /* VFP instructions. In a logical order: SP variant first, monad | |
5540 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
5541 | |
5542 | static void | |
c19d1205 | 5543 | do_vfp_sp_monadic (void) |
e16bb312 | 5544 | { |
c19d1205 ZW |
5545 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5546 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
5547 | } |
5548 | ||
5549 | static void | |
c19d1205 | 5550 | do_vfp_sp_dyadic (void) |
e16bb312 | 5551 | { |
c19d1205 ZW |
5552 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5553 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
5554 | encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
5555 | } |
5556 | ||
5557 | static void | |
c19d1205 | 5558 | do_vfp_sp_compare_z (void) |
e16bb312 | 5559 | { |
c19d1205 | 5560 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
5561 | } |
5562 | ||
5563 | static void | |
c19d1205 | 5564 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 5565 | { |
c19d1205 ZW |
5566 | inst.instruction |= inst.operands[0].reg << 12; |
5567 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
5568 | } |
5569 | ||
5570 | static void | |
c19d1205 | 5571 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 5572 | { |
c19d1205 ZW |
5573 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5574 | inst.instruction |= inst.operands[1].reg; | |
e16bb312 NC |
5575 | } |
5576 | ||
5577 | static void | |
c19d1205 | 5578 | do_vfp_reg_from_sp (void) |
e16bb312 | 5579 | { |
c19d1205 ZW |
5580 | inst.instruction |= inst.operands[0].reg << 12; |
5581 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
e16bb312 NC |
5582 | } |
5583 | ||
5584 | static void | |
c19d1205 | 5585 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 5586 | { |
c19d1205 ZW |
5587 | constraint (inst.operands[2].imm != 2, |
5588 | _("only two consecutive VFP SP registers allowed here")); | |
5589 | inst.instruction |= inst.operands[0].reg << 12; | |
5590 | inst.instruction |= inst.operands[1].reg << 16; | |
5591 | encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
5592 | } |
5593 | ||
5594 | static void | |
c19d1205 | 5595 | do_vfp_sp_from_reg (void) |
e16bb312 | 5596 | { |
c19d1205 ZW |
5597 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn); |
5598 | inst.instruction |= inst.operands[1].reg << 12; | |
e16bb312 NC |
5599 | } |
5600 | ||
5601 | static void | |
c19d1205 | 5602 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 5603 | { |
c19d1205 ZW |
5604 | constraint (inst.operands[0].imm != 2, |
5605 | _("only two consecutive VFP SP registers allowed here")); | |
5606 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm); | |
5607 | inst.instruction |= inst.operands[1].reg << 12; | |
5608 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
5609 | } |
5610 | ||
5611 | static void | |
c19d1205 | 5612 | do_vfp_sp_ldst (void) |
e16bb312 | 5613 | { |
c19d1205 ZW |
5614 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5615 | encode_arm_cp_address (1, FALSE, TRUE, 0); | |
e16bb312 NC |
5616 | } |
5617 | ||
5618 | static void | |
c19d1205 | 5619 | do_vfp_dp_ldst (void) |
e16bb312 | 5620 | { |
c19d1205 ZW |
5621 | inst.instruction |= inst.operands[0].reg << 12; |
5622 | encode_arm_cp_address (1, FALSE, TRUE, 0); | |
e16bb312 NC |
5623 | } |
5624 | ||
c19d1205 | 5625 | |
e16bb312 | 5626 | static void |
c19d1205 | 5627 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 5628 | { |
c19d1205 ZW |
5629 | if (inst.operands[0].writeback) |
5630 | inst.instruction |= WRITE_BACK; | |
5631 | else | |
5632 | constraint (ldstm_type != VFP_LDSTMIA, | |
5633 | _("this addressing mode requires base-register writeback")); | |
5634 | inst.instruction |= inst.operands[0].reg << 16; | |
5635 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd); | |
5636 | inst.instruction |= inst.operands[1].imm; | |
e16bb312 NC |
5637 | } |
5638 | ||
5639 | static void | |
c19d1205 | 5640 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 5641 | { |
c19d1205 | 5642 | int count; |
e16bb312 | 5643 | |
c19d1205 ZW |
5644 | if (inst.operands[0].writeback) |
5645 | inst.instruction |= WRITE_BACK; | |
5646 | else | |
5647 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
5648 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 5649 | |
c19d1205 ZW |
5650 | inst.instruction |= inst.operands[0].reg << 16; |
5651 | inst.instruction |= inst.operands[1].reg << 12; | |
e16bb312 | 5652 | |
c19d1205 ZW |
5653 | count = inst.operands[1].imm << 1; |
5654 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
5655 | count += 1; | |
e16bb312 | 5656 | |
c19d1205 | 5657 | inst.instruction |= count; |
e16bb312 NC |
5658 | } |
5659 | ||
5660 | static void | |
c19d1205 | 5661 | do_vfp_sp_ldstmia (void) |
e16bb312 | 5662 | { |
c19d1205 | 5663 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
5664 | } |
5665 | ||
5666 | static void | |
c19d1205 | 5667 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 5668 | { |
c19d1205 | 5669 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
5670 | } |
5671 | ||
5672 | static void | |
c19d1205 | 5673 | do_vfp_dp_ldstmia (void) |
e16bb312 | 5674 | { |
c19d1205 | 5675 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
5676 | } |
5677 | ||
5678 | static void | |
c19d1205 | 5679 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 5680 | { |
c19d1205 | 5681 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
5682 | } |
5683 | ||
5684 | static void | |
c19d1205 | 5685 | do_vfp_xp_ldstmia (void) |
e16bb312 | 5686 | { |
c19d1205 ZW |
5687 | vfp_dp_ldstm (VFP_LDSTMIAX); |
5688 | } | |
e16bb312 | 5689 | |
c19d1205 ZW |
5690 | static void |
5691 | do_vfp_xp_ldstmdb (void) | |
5692 | { | |
5693 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 5694 | } |
c19d1205 ZW |
5695 | \f |
5696 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 5697 | |
c19d1205 ZW |
5698 | static void |
5699 | do_fpa_cmp (void) | |
5700 | { | |
5701 | inst.instruction |= inst.operands[0].reg << 16; | |
5702 | inst.instruction |= inst.operands[1].reg; | |
5703 | } | |
b99bd4ef NC |
5704 | |
5705 | static void | |
c19d1205 | 5706 | do_fpa_ldmstm (void) |
b99bd4ef | 5707 | { |
c19d1205 ZW |
5708 | inst.instruction |= inst.operands[0].reg << 12; |
5709 | switch (inst.operands[1].imm) | |
5710 | { | |
5711 | case 1: inst.instruction |= CP_T_X; break; | |
5712 | case 2: inst.instruction |= CP_T_Y; break; | |
5713 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
5714 | case 4: break; | |
5715 | default: abort (); | |
5716 | } | |
b99bd4ef | 5717 | |
c19d1205 ZW |
5718 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
5719 | { | |
5720 | /* The instruction specified "ea" or "fd", so we can only accept | |
5721 | [Rn]{!}. The instruction does not really support stacking or | |
5722 | unstacking, so we have to emulate these by setting appropriate | |
5723 | bits and offsets. */ | |
5724 | constraint (inst.reloc.exp.X_op != O_constant | |
5725 | || inst.reloc.exp.X_add_number != 0, | |
5726 | _("this instruction does not support indexing")); | |
b99bd4ef | 5727 | |
c19d1205 ZW |
5728 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
5729 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 5730 | |
c19d1205 ZW |
5731 | if (!(inst.instruction & INDEX_UP)) |
5732 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 5733 | |
c19d1205 ZW |
5734 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
5735 | { | |
5736 | inst.operands[2].preind = 0; | |
5737 | inst.operands[2].postind = 1; | |
5738 | } | |
5739 | } | |
b99bd4ef | 5740 | |
c19d1205 | 5741 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 5742 | } |
c19d1205 ZW |
5743 | \f |
5744 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 5745 | |
c19d1205 ZW |
5746 | static void |
5747 | do_iwmmxt_tandorc (void) | |
5748 | { | |
5749 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
5750 | } | |
b99bd4ef | 5751 | |
c19d1205 ZW |
5752 | static void |
5753 | do_iwmmxt_textrc (void) | |
5754 | { | |
5755 | inst.instruction |= inst.operands[0].reg << 12; | |
5756 | inst.instruction |= inst.operands[1].imm; | |
5757 | } | |
b99bd4ef NC |
5758 | |
5759 | static void | |
c19d1205 | 5760 | do_iwmmxt_textrm (void) |
b99bd4ef | 5761 | { |
c19d1205 ZW |
5762 | inst.instruction |= inst.operands[0].reg << 12; |
5763 | inst.instruction |= inst.operands[1].reg << 16; | |
5764 | inst.instruction |= inst.operands[2].imm; | |
5765 | } | |
b99bd4ef | 5766 | |
c19d1205 ZW |
5767 | static void |
5768 | do_iwmmxt_tinsr (void) | |
5769 | { | |
5770 | inst.instruction |= inst.operands[0].reg << 16; | |
5771 | inst.instruction |= inst.operands[1].reg << 12; | |
5772 | inst.instruction |= inst.operands[2].imm; | |
5773 | } | |
b99bd4ef | 5774 | |
c19d1205 ZW |
5775 | static void |
5776 | do_iwmmxt_tmia (void) | |
5777 | { | |
5778 | inst.instruction |= inst.operands[0].reg << 5; | |
5779 | inst.instruction |= inst.operands[1].reg; | |
5780 | inst.instruction |= inst.operands[2].reg << 12; | |
5781 | } | |
b99bd4ef | 5782 | |
c19d1205 ZW |
5783 | static void |
5784 | do_iwmmxt_waligni (void) | |
5785 | { | |
5786 | inst.instruction |= inst.operands[0].reg << 12; | |
5787 | inst.instruction |= inst.operands[1].reg << 16; | |
5788 | inst.instruction |= inst.operands[2].reg; | |
5789 | inst.instruction |= inst.operands[3].imm << 20; | |
5790 | } | |
b99bd4ef | 5791 | |
c19d1205 ZW |
5792 | static void |
5793 | do_iwmmxt_wmov (void) | |
5794 | { | |
5795 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
5796 | inst.instruction |= inst.operands[0].reg << 12; | |
5797 | inst.instruction |= inst.operands[1].reg << 16; | |
5798 | inst.instruction |= inst.operands[1].reg; | |
5799 | } | |
b99bd4ef | 5800 | |
c19d1205 ZW |
5801 | static void |
5802 | do_iwmmxt_wldstbh (void) | |
5803 | { | |
8f06b2d8 | 5804 | int reloc; |
c19d1205 ZW |
5805 | inst.instruction |= inst.operands[0].reg << 12; |
5806 | inst.reloc.exp.X_add_number *= 4; | |
8f06b2d8 PB |
5807 | if (thumb_mode) |
5808 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
5809 | else | |
5810 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
5811 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
5812 | } |
5813 | ||
c19d1205 ZW |
5814 | static void |
5815 | do_iwmmxt_wldstw (void) | |
5816 | { | |
5817 | /* RIWR_RIWC clears .isreg for a control register. */ | |
5818 | if (!inst.operands[0].isreg) | |
5819 | { | |
5820 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
5821 | inst.instruction |= 0xf0000000; | |
5822 | } | |
b99bd4ef | 5823 | |
c19d1205 ZW |
5824 | inst.instruction |= inst.operands[0].reg << 12; |
5825 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
5826 | } | |
b99bd4ef NC |
5827 | |
5828 | static void | |
c19d1205 | 5829 | do_iwmmxt_wldstd (void) |
b99bd4ef | 5830 | { |
c19d1205 | 5831 | inst.instruction |= inst.operands[0].reg << 12; |
f2184508 | 5832 | encode_arm_cp_address (1, TRUE, FALSE, 0); |
c19d1205 | 5833 | } |
b99bd4ef | 5834 | |
c19d1205 ZW |
5835 | static void |
5836 | do_iwmmxt_wshufh (void) | |
5837 | { | |
5838 | inst.instruction |= inst.operands[0].reg << 12; | |
5839 | inst.instruction |= inst.operands[1].reg << 16; | |
5840 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
5841 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
5842 | } | |
b99bd4ef | 5843 | |
c19d1205 ZW |
5844 | static void |
5845 | do_iwmmxt_wzero (void) | |
5846 | { | |
5847 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
5848 | inst.instruction |= inst.operands[0].reg; | |
5849 | inst.instruction |= inst.operands[0].reg << 12; | |
5850 | inst.instruction |= inst.operands[0].reg << 16; | |
5851 | } | |
5852 | \f | |
5853 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
5854 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 5855 | |
c19d1205 | 5856 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 5857 | |
c19d1205 ZW |
5858 | static void |
5859 | do_mav_triple (void) | |
5860 | { | |
5861 | inst.instruction |= inst.operands[0].reg << 16; | |
5862 | inst.instruction |= inst.operands[1].reg; | |
5863 | inst.instruction |= inst.operands[2].reg << 12; | |
5864 | } | |
b99bd4ef | 5865 | |
c19d1205 ZW |
5866 | /* Insns like "foo W,X,Y,Z". |
5867 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 5868 | |
c19d1205 ZW |
5869 | static void |
5870 | do_mav_quad (void) | |
5871 | { | |
5872 | inst.instruction |= inst.operands[0].reg << 5; | |
5873 | inst.instruction |= inst.operands[1].reg << 12; | |
5874 | inst.instruction |= inst.operands[2].reg << 16; | |
5875 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
5876 | } |
5877 | ||
c19d1205 ZW |
5878 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
5879 | static void | |
5880 | do_mav_dspsc (void) | |
a737bd4d | 5881 | { |
c19d1205 ZW |
5882 | inst.instruction |= inst.operands[1].reg << 12; |
5883 | } | |
a737bd4d | 5884 | |
c19d1205 ZW |
5885 | /* Maverick shift immediate instructions. |
5886 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
5887 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 5888 | |
c19d1205 ZW |
5889 | static void |
5890 | do_mav_shift (void) | |
5891 | { | |
5892 | int imm = inst.operands[2].imm; | |
a737bd4d | 5893 | |
c19d1205 ZW |
5894 | inst.instruction |= inst.operands[0].reg << 12; |
5895 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 5896 | |
c19d1205 ZW |
5897 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
5898 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
5899 | Bit 4 should be 0. */ | |
5900 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 5901 | |
c19d1205 ZW |
5902 | inst.instruction |= imm; |
5903 | } | |
5904 | \f | |
5905 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 5906 | |
c19d1205 ZW |
5907 | /* Xscale multiply-accumulate (argument parse) |
5908 | MIAcc acc0,Rm,Rs | |
5909 | MIAPHcc acc0,Rm,Rs | |
5910 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 5911 | |
c19d1205 ZW |
5912 | static void |
5913 | do_xsc_mia (void) | |
5914 | { | |
5915 | inst.instruction |= inst.operands[1].reg; | |
5916 | inst.instruction |= inst.operands[2].reg << 12; | |
5917 | } | |
a737bd4d | 5918 | |
c19d1205 | 5919 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 5920 | |
c19d1205 | 5921 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 5922 | |
c19d1205 ZW |
5923 | static void |
5924 | do_xsc_mar (void) | |
5925 | { | |
5926 | inst.instruction |= inst.operands[1].reg << 12; | |
5927 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
5928 | } |
5929 | ||
c19d1205 | 5930 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 5931 | |
c19d1205 | 5932 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
5933 | |
5934 | static void | |
c19d1205 | 5935 | do_xsc_mra (void) |
b99bd4ef | 5936 | { |
c19d1205 ZW |
5937 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
5938 | inst.instruction |= inst.operands[0].reg << 12; | |
5939 | inst.instruction |= inst.operands[1].reg << 16; | |
5940 | } | |
5941 | \f | |
5942 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 5943 | |
c19d1205 ZW |
5944 | /* inst.operands[i] is a shifted-register operand; encode |
5945 | it into inst.instruction in the format used by Thumb32. */ | |
5946 | ||
5947 | static void | |
5948 | encode_thumb32_shifted_operand (int i) | |
5949 | { | |
5950 | unsigned int value = inst.reloc.exp.X_add_number; | |
5951 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 5952 | |
9c3c69f2 PB |
5953 | constraint (inst.operands[i].immisreg, |
5954 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
5955 | inst.instruction |= inst.operands[i].reg; |
5956 | if (shift == SHIFT_RRX) | |
5957 | inst.instruction |= SHIFT_ROR << 4; | |
5958 | else | |
b99bd4ef | 5959 | { |
c19d1205 ZW |
5960 | constraint (inst.reloc.exp.X_op != O_constant, |
5961 | _("expression too complex")); | |
5962 | ||
5963 | constraint (value > 32 | |
5964 | || (value == 32 && (shift == SHIFT_LSL | |
5965 | || shift == SHIFT_ROR)), | |
5966 | _("shift expression is too large")); | |
5967 | ||
5968 | if (value == 0) | |
5969 | shift = SHIFT_LSL; | |
5970 | else if (value == 32) | |
5971 | value = 0; | |
5972 | ||
5973 | inst.instruction |= shift << 4; | |
5974 | inst.instruction |= (value & 0x1c) << 10; | |
5975 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 5976 | } |
c19d1205 | 5977 | } |
b99bd4ef | 5978 | |
b99bd4ef | 5979 | |
c19d1205 ZW |
5980 | /* inst.operands[i] was set up by parse_address. Encode it into a |
5981 | Thumb32 format load or store instruction. Reject forms that cannot | |
5982 | be used with such instructions. If is_t is true, reject forms that | |
5983 | cannot be used with a T instruction; if is_d is true, reject forms | |
5984 | that cannot be used with a D instruction. */ | |
b99bd4ef | 5985 | |
c19d1205 ZW |
5986 | static void |
5987 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
5988 | { | |
5989 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
5990 | ||
5991 | constraint (!inst.operands[i].isreg, | |
53365c0d | 5992 | _("Instruction does not support =N addresses")); |
b99bd4ef | 5993 | |
c19d1205 ZW |
5994 | inst.instruction |= inst.operands[i].reg << 16; |
5995 | if (inst.operands[i].immisreg) | |
b99bd4ef | 5996 | { |
c19d1205 ZW |
5997 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
5998 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
5999 | constraint (inst.operands[i].negative, | |
6000 | _("Thumb does not support negative register indexing")); | |
6001 | constraint (inst.operands[i].postind, | |
6002 | _("Thumb does not support register post-indexing")); | |
6003 | constraint (inst.operands[i].writeback, | |
6004 | _("Thumb does not support register indexing with writeback")); | |
6005 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
6006 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 6007 | |
f40d1643 | 6008 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 6009 | if (inst.operands[i].shifted) |
b99bd4ef | 6010 | { |
c19d1205 ZW |
6011 | constraint (inst.reloc.exp.X_op != O_constant, |
6012 | _("expression too complex")); | |
9c3c69f2 PB |
6013 | constraint (inst.reloc.exp.X_add_number < 0 |
6014 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 6015 | _("shift out of range")); |
9c3c69f2 | 6016 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
6017 | } |
6018 | inst.reloc.type = BFD_RELOC_UNUSED; | |
6019 | } | |
6020 | else if (inst.operands[i].preind) | |
6021 | { | |
6022 | constraint (is_pc && inst.operands[i].writeback, | |
6023 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 6024 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
6025 | _("cannot use writeback with this instruction")); |
6026 | ||
6027 | if (is_d) | |
6028 | { | |
6029 | inst.instruction |= 0x01000000; | |
6030 | if (inst.operands[i].writeback) | |
6031 | inst.instruction |= 0x00200000; | |
b99bd4ef | 6032 | } |
c19d1205 | 6033 | else |
b99bd4ef | 6034 | { |
c19d1205 ZW |
6035 | inst.instruction |= 0x00000c00; |
6036 | if (inst.operands[i].writeback) | |
6037 | inst.instruction |= 0x00000100; | |
b99bd4ef | 6038 | } |
c19d1205 | 6039 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 6040 | } |
c19d1205 | 6041 | else if (inst.operands[i].postind) |
b99bd4ef | 6042 | { |
c19d1205 ZW |
6043 | assert (inst.operands[i].writeback); |
6044 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); | |
6045 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
6046 | ||
6047 | if (is_d) | |
6048 | inst.instruction |= 0x00200000; | |
6049 | else | |
6050 | inst.instruction |= 0x00000900; | |
6051 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
6052 | } | |
6053 | else /* unindexed - only for coprocessor */ | |
6054 | inst.error = _("instruction does not accept unindexed addressing"); | |
6055 | } | |
6056 | ||
6057 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
6058 | encodings (the latter only in post-V6T2 cores). The index is the | |
6059 | value used in the insns table below. When there is more than one | |
6060 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
6061 | holds variant (1). |
6062 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 ZW |
6063 | #define T16_32_TAB \ |
6064 | X(adc, 4140, eb400000), \ | |
6065 | X(adcs, 4140, eb500000), \ | |
6066 | X(add, 1c00, eb000000), \ | |
6067 | X(adds, 1c00, eb100000), \ | |
0110f2b8 PB |
6068 | X(addi, 0000, f1000000), \ |
6069 | X(addis, 0000, f1100000), \ | |
6070 | X(add_pc,000f, f20f0000), \ | |
6071 | X(add_sp,000d, f10d0000), \ | |
e9f89963 | 6072 | X(adr, 000f, f20f0000), \ |
c19d1205 ZW |
6073 | X(and, 4000, ea000000), \ |
6074 | X(ands, 4000, ea100000), \ | |
6075 | X(asr, 1000, fa40f000), \ | |
6076 | X(asrs, 1000, fa50f000), \ | |
0110f2b8 PB |
6077 | X(b, e000, f000b000), \ |
6078 | X(bcond, d000, f0008000), \ | |
c19d1205 ZW |
6079 | X(bic, 4380, ea200000), \ |
6080 | X(bics, 4380, ea300000), \ | |
6081 | X(cmn, 42c0, eb100f00), \ | |
6082 | X(cmp, 2800, ebb00f00), \ | |
6083 | X(cpsie, b660, f3af8400), \ | |
6084 | X(cpsid, b670, f3af8600), \ | |
6085 | X(cpy, 4600, ea4f0000), \ | |
0110f2b8 | 6086 | X(dec_sp,80dd, f1bd0d00), \ |
c19d1205 ZW |
6087 | X(eor, 4040, ea800000), \ |
6088 | X(eors, 4040, ea900000), \ | |
0110f2b8 | 6089 | X(inc_sp,00dd, f10d0d00), \ |
c19d1205 ZW |
6090 | X(ldmia, c800, e8900000), \ |
6091 | X(ldr, 6800, f8500000), \ | |
6092 | X(ldrb, 7800, f8100000), \ | |
6093 | X(ldrh, 8800, f8300000), \ | |
6094 | X(ldrsb, 5600, f9100000), \ | |
6095 | X(ldrsh, 5e00, f9300000), \ | |
0110f2b8 PB |
6096 | X(ldr_pc,4800, f85f0000), \ |
6097 | X(ldr_pc2,4800, f85f0000), \ | |
6098 | X(ldr_sp,9800, f85d0000), \ | |
c19d1205 ZW |
6099 | X(lsl, 0000, fa00f000), \ |
6100 | X(lsls, 0000, fa10f000), \ | |
6101 | X(lsr, 0800, fa20f000), \ | |
6102 | X(lsrs, 0800, fa30f000), \ | |
6103 | X(mov, 2000, ea4f0000), \ | |
6104 | X(movs, 2000, ea5f0000), \ | |
6105 | X(mul, 4340, fb00f000), \ | |
6106 | X(muls, 4340, ffffffff), /* no 32b muls */ \ | |
6107 | X(mvn, 43c0, ea6f0000), \ | |
6108 | X(mvns, 43c0, ea7f0000), \ | |
6109 | X(neg, 4240, f1c00000), /* rsb #0 */ \ | |
6110 | X(negs, 4240, f1d00000), /* rsbs #0 */ \ | |
6111 | X(orr, 4300, ea400000), \ | |
6112 | X(orrs, 4300, ea500000), \ | |
e9f89963 PB |
6113 | X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \ |
6114 | X(push, b400, e92d0000), /* stmdb sp!,... */ \ | |
c19d1205 ZW |
6115 | X(rev, ba00, fa90f080), \ |
6116 | X(rev16, ba40, fa90f090), \ | |
6117 | X(revsh, bac0, fa90f0b0), \ | |
6118 | X(ror, 41c0, fa60f000), \ | |
6119 | X(rors, 41c0, fa70f000), \ | |
6120 | X(sbc, 4180, eb600000), \ | |
6121 | X(sbcs, 4180, eb700000), \ | |
6122 | X(stmia, c000, e8800000), \ | |
6123 | X(str, 6000, f8400000), \ | |
6124 | X(strb, 7000, f8000000), \ | |
6125 | X(strh, 8000, f8200000), \ | |
0110f2b8 | 6126 | X(str_sp,9000, f84d0000), \ |
c19d1205 ZW |
6127 | X(sub, 1e00, eba00000), \ |
6128 | X(subs, 1e00, ebb00000), \ | |
0110f2b8 PB |
6129 | X(subi, 8000, f1a00000), \ |
6130 | X(subis, 8000, f1b00000), \ | |
c19d1205 ZW |
6131 | X(sxtb, b240, fa4ff080), \ |
6132 | X(sxth, b200, fa0ff080), \ | |
6133 | X(tst, 4200, ea100f00), \ | |
6134 | X(uxtb, b2c0, fa5ff080), \ | |
6135 | X(uxth, b280, fa1ff080), \ | |
6136 | X(nop, bf00, f3af8000), \ | |
6137 | X(yield, bf10, f3af8001), \ | |
6138 | X(wfe, bf20, f3af8002), \ | |
6139 | X(wfi, bf30, f3af8003), \ | |
6140 | X(sev, bf40, f3af9004), /* typo, 8004? */ | |
6141 | ||
6142 | /* To catch errors in encoding functions, the codes are all offset by | |
6143 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
6144 | as 16-bit instructions. */ | |
6145 | #define X(a,b,c) T_MNEM_##a | |
6146 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; | |
6147 | #undef X | |
6148 | ||
6149 | #define X(a,b,c) 0x##b | |
6150 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
6151 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
6152 | #undef X | |
6153 | ||
6154 | #define X(a,b,c) 0x##c | |
6155 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
6156 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) | |
6157 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
6158 | #undef X | |
6159 | #undef T16_32_TAB | |
6160 | ||
6161 | /* Thumb instruction encoders, in alphabetical order. */ | |
6162 | ||
92e90b6e PB |
6163 | /* ADDW or SUBW. */ |
6164 | static void | |
6165 | do_t_add_sub_w (void) | |
6166 | { | |
6167 | int Rd, Rn; | |
6168 | ||
6169 | Rd = inst.operands[0].reg; | |
6170 | Rn = inst.operands[1].reg; | |
6171 | ||
6172 | constraint (Rd == 15, _("PC not allowed as destination")); | |
6173 | inst.instruction |= (Rn << 16) | (Rd << 8); | |
6174 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
6175 | } | |
6176 | ||
c19d1205 ZW |
6177 | /* Parse an add or subtract instruction. We get here with inst.instruction |
6178 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
6179 | ||
6180 | static void | |
6181 | do_t_add_sub (void) | |
6182 | { | |
6183 | int Rd, Rs, Rn; | |
6184 | ||
6185 | Rd = inst.operands[0].reg; | |
6186 | Rs = (inst.operands[1].present | |
6187 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
6188 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
6189 | ||
6190 | if (unified_syntax) | |
6191 | { | |
0110f2b8 PB |
6192 | bfd_boolean flags; |
6193 | bfd_boolean narrow; | |
6194 | int opcode; | |
6195 | ||
6196 | flags = (inst.instruction == T_MNEM_adds | |
6197 | || inst.instruction == T_MNEM_subs); | |
6198 | if (flags) | |
6199 | narrow = (current_it_mask == 0); | |
6200 | else | |
6201 | narrow = (current_it_mask != 0); | |
c19d1205 | 6202 | if (!inst.operands[2].isreg) |
b99bd4ef | 6203 | { |
0110f2b8 PB |
6204 | opcode = 0; |
6205 | if (inst.size_req != 4) | |
6206 | { | |
6207 | int add; | |
6208 | ||
6209 | add = (inst.instruction == T_MNEM_add | |
6210 | || inst.instruction == T_MNEM_adds); | |
6211 | /* Attempt to use a narrow opcode, with relaxation if | |
6212 | appropriate. */ | |
6213 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
6214 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
6215 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
6216 | opcode = T_MNEM_add_sp; | |
6217 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
6218 | opcode = T_MNEM_add_pc; | |
6219 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
6220 | { | |
6221 | if (flags) | |
6222 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
6223 | else | |
6224 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
6225 | } | |
6226 | if (opcode) | |
6227 | { | |
6228 | inst.instruction = THUMB_OP16(opcode); | |
6229 | inst.instruction |= (Rd << 4) | Rs; | |
6230 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
6231 | if (inst.size_req != 2) | |
6232 | inst.relax = opcode; | |
6233 | } | |
6234 | else | |
6235 | constraint (inst.size_req == 2, BAD_HIREG); | |
6236 | } | |
6237 | if (inst.size_req == 4 | |
6238 | || (inst.size_req != 2 && !opcode)) | |
6239 | { | |
6240 | /* ??? Convert large immediates to addw/subw. */ | |
6241 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6242 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
6243 | inst.instruction |= inst.operands[0].reg << 8; | |
6244 | inst.instruction |= inst.operands[1].reg << 16; | |
6245 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
6246 | } | |
b99bd4ef | 6247 | } |
c19d1205 ZW |
6248 | else |
6249 | { | |
6250 | Rn = inst.operands[2].reg; | |
6251 | /* See if we can do this with a 16-bit instruction. */ | |
6252 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
6253 | { | |
e27ec89e PB |
6254 | if (Rd > 7 || Rs > 7 || Rn > 7) |
6255 | narrow = FALSE; | |
6256 | ||
6257 | if (narrow) | |
c19d1205 | 6258 | { |
e27ec89e PB |
6259 | inst.instruction = ((inst.instruction == T_MNEM_adds |
6260 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
6261 | ? T_OPCODE_ADD_R3 |
6262 | : T_OPCODE_SUB_R3); | |
6263 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
6264 | return; | |
6265 | } | |
b99bd4ef | 6266 | |
c19d1205 ZW |
6267 | if (inst.instruction == T_MNEM_add) |
6268 | { | |
6269 | if (Rd == Rs) | |
6270 | { | |
6271 | inst.instruction = T_OPCODE_ADD_HI; | |
6272 | inst.instruction |= (Rd & 8) << 4; | |
6273 | inst.instruction |= (Rd & 7); | |
6274 | inst.instruction |= Rn << 3; | |
6275 | return; | |
6276 | } | |
6277 | /* ... because addition is commutative! */ | |
6278 | else if (Rd == Rn) | |
6279 | { | |
6280 | inst.instruction = T_OPCODE_ADD_HI; | |
6281 | inst.instruction |= (Rd & 8) << 4; | |
6282 | inst.instruction |= (Rd & 7); | |
6283 | inst.instruction |= Rs << 3; | |
6284 | return; | |
6285 | } | |
6286 | } | |
6287 | } | |
6288 | /* If we get here, it can't be done in 16 bits. */ | |
6289 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
6290 | _("shift must be constant")); | |
6291 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6292 | inst.instruction |= Rd << 8; | |
6293 | inst.instruction |= Rs << 16; | |
6294 | encode_thumb32_shifted_operand (2); | |
6295 | } | |
6296 | } | |
6297 | else | |
6298 | { | |
6299 | constraint (inst.instruction == T_MNEM_adds | |
6300 | || inst.instruction == T_MNEM_subs, | |
6301 | BAD_THUMB32); | |
b99bd4ef | 6302 | |
c19d1205 | 6303 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 6304 | { |
c19d1205 ZW |
6305 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
6306 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
6307 | BAD_HIREG); | |
6308 | ||
6309 | inst.instruction = (inst.instruction == T_MNEM_add | |
6310 | ? 0x0000 : 0x8000); | |
6311 | inst.instruction |= (Rd << 4) | Rs; | |
6312 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
6313 | return; |
6314 | } | |
6315 | ||
c19d1205 ZW |
6316 | Rn = inst.operands[2].reg; |
6317 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 6318 | |
c19d1205 ZW |
6319 | /* We now have Rd, Rs, and Rn set to registers. */ |
6320 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 6321 | { |
c19d1205 ZW |
6322 | /* Can't do this for SUB. */ |
6323 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
6324 | inst.instruction = T_OPCODE_ADD_HI; | |
6325 | inst.instruction |= (Rd & 8) << 4; | |
6326 | inst.instruction |= (Rd & 7); | |
6327 | if (Rs == Rd) | |
6328 | inst.instruction |= Rn << 3; | |
6329 | else if (Rn == Rd) | |
6330 | inst.instruction |= Rs << 3; | |
6331 | else | |
6332 | constraint (1, _("dest must overlap one source register")); | |
6333 | } | |
6334 | else | |
6335 | { | |
6336 | inst.instruction = (inst.instruction == T_MNEM_add | |
6337 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
6338 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 6339 | } |
b99bd4ef | 6340 | } |
b99bd4ef NC |
6341 | } |
6342 | ||
c19d1205 ZW |
6343 | static void |
6344 | do_t_adr (void) | |
6345 | { | |
0110f2b8 PB |
6346 | if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7) |
6347 | { | |
6348 | /* Defer to section relaxation. */ | |
6349 | inst.relax = inst.instruction; | |
6350 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6351 | inst.instruction |= inst.operands[0].reg << 4; | |
6352 | } | |
6353 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 6354 | { |
0110f2b8 | 6355 | /* Generate a 32-bit opcode. */ |
e9f89963 PB |
6356 | inst.instruction = THUMB_OP32 (inst.instruction); |
6357 | inst.instruction |= inst.operands[0].reg << 8; | |
6358 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; | |
6359 | inst.reloc.pc_rel = 1; | |
6360 | } | |
6361 | else | |
6362 | { | |
0110f2b8 | 6363 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
6364 | inst.instruction = THUMB_OP16 (inst.instruction); |
6365 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
6366 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
6367 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 6368 | |
e9f89963 PB |
6369 | inst.instruction |= inst.operands[0].reg << 4; |
6370 | } | |
c19d1205 | 6371 | } |
b99bd4ef | 6372 | |
c19d1205 ZW |
6373 | /* Arithmetic instructions for which there is just one 16-bit |
6374 | instruction encoding, and it allows only two low registers. | |
6375 | For maximal compatibility with ARM syntax, we allow three register | |
6376 | operands even when Thumb-32 instructions are not available, as long | |
6377 | as the first two are identical. For instance, both "sbc r0,r1" and | |
6378 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 6379 | static void |
c19d1205 | 6380 | do_t_arit3 (void) |
b99bd4ef | 6381 | { |
c19d1205 | 6382 | int Rd, Rs, Rn; |
b99bd4ef | 6383 | |
c19d1205 ZW |
6384 | Rd = inst.operands[0].reg; |
6385 | Rs = (inst.operands[1].present | |
6386 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
6387 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
6388 | Rn = inst.operands[2].reg; | |
b99bd4ef | 6389 | |
c19d1205 | 6390 | if (unified_syntax) |
b99bd4ef | 6391 | { |
c19d1205 ZW |
6392 | if (!inst.operands[2].isreg) |
6393 | { | |
6394 | /* For an immediate, we always generate a 32-bit opcode; | |
6395 | section relaxation will shrink it later if possible. */ | |
6396 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6397 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
6398 | inst.instruction |= Rd << 8; | |
6399 | inst.instruction |= Rs << 16; | |
6400 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
6401 | } | |
6402 | else | |
6403 | { | |
e27ec89e PB |
6404 | bfd_boolean narrow; |
6405 | ||
c19d1205 | 6406 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
6407 | if (THUMB_SETS_FLAGS (inst.instruction)) |
6408 | narrow = current_it_mask == 0; | |
6409 | else | |
6410 | narrow = current_it_mask != 0; | |
6411 | ||
6412 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
6413 | narrow = FALSE; | |
6414 | if (inst.operands[2].shifted) | |
6415 | narrow = FALSE; | |
6416 | if (inst.size_req == 4) | |
6417 | narrow = FALSE; | |
6418 | ||
6419 | if (narrow | |
c19d1205 ZW |
6420 | && Rd == Rs) |
6421 | { | |
6422 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6423 | inst.instruction |= Rd; | |
6424 | inst.instruction |= Rn << 3; | |
6425 | return; | |
6426 | } | |
b99bd4ef | 6427 | |
c19d1205 ZW |
6428 | /* If we get here, it can't be done in 16 bits. */ |
6429 | constraint (inst.operands[2].shifted | |
6430 | && inst.operands[2].immisreg, | |
6431 | _("shift must be constant")); | |
6432 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6433 | inst.instruction |= Rd << 8; | |
6434 | inst.instruction |= Rs << 16; | |
6435 | encode_thumb32_shifted_operand (2); | |
6436 | } | |
a737bd4d | 6437 | } |
c19d1205 | 6438 | else |
b99bd4ef | 6439 | { |
c19d1205 ZW |
6440 | /* On its face this is a lie - the instruction does set the |
6441 | flags. However, the only supported mnemonic in this mode | |
6442 | says it doesn't. */ | |
6443 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 6444 | |
c19d1205 ZW |
6445 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
6446 | _("unshifted register required")); | |
6447 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
6448 | constraint (Rd != Rs, | |
6449 | _("dest and source1 must be the same register")); | |
a737bd4d | 6450 | |
c19d1205 ZW |
6451 | inst.instruction = THUMB_OP16 (inst.instruction); |
6452 | inst.instruction |= Rd; | |
6453 | inst.instruction |= Rn << 3; | |
b99bd4ef | 6454 | } |
a737bd4d | 6455 | } |
b99bd4ef | 6456 | |
c19d1205 ZW |
6457 | /* Similarly, but for instructions where the arithmetic operation is |
6458 | commutative, so we can allow either of them to be different from | |
6459 | the destination operand in a 16-bit instruction. For instance, all | |
6460 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
6461 | accepted. */ | |
6462 | static void | |
6463 | do_t_arit3c (void) | |
a737bd4d | 6464 | { |
c19d1205 | 6465 | int Rd, Rs, Rn; |
b99bd4ef | 6466 | |
c19d1205 ZW |
6467 | Rd = inst.operands[0].reg; |
6468 | Rs = (inst.operands[1].present | |
6469 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
6470 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
6471 | Rn = inst.operands[2].reg; | |
a737bd4d | 6472 | |
c19d1205 | 6473 | if (unified_syntax) |
a737bd4d | 6474 | { |
c19d1205 | 6475 | if (!inst.operands[2].isreg) |
b99bd4ef | 6476 | { |
c19d1205 ZW |
6477 | /* For an immediate, we always generate a 32-bit opcode; |
6478 | section relaxation will shrink it later if possible. */ | |
6479 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6480 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
6481 | inst.instruction |= Rd << 8; | |
6482 | inst.instruction |= Rs << 16; | |
6483 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 6484 | } |
c19d1205 | 6485 | else |
a737bd4d | 6486 | { |
e27ec89e PB |
6487 | bfd_boolean narrow; |
6488 | ||
c19d1205 | 6489 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
6490 | if (THUMB_SETS_FLAGS (inst.instruction)) |
6491 | narrow = current_it_mask == 0; | |
6492 | else | |
6493 | narrow = current_it_mask != 0; | |
6494 | ||
6495 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
6496 | narrow = FALSE; | |
6497 | if (inst.operands[2].shifted) | |
6498 | narrow = FALSE; | |
6499 | if (inst.size_req == 4) | |
6500 | narrow = FALSE; | |
6501 | ||
6502 | if (narrow) | |
a737bd4d | 6503 | { |
c19d1205 | 6504 | if (Rd == Rs) |
a737bd4d | 6505 | { |
c19d1205 ZW |
6506 | inst.instruction = THUMB_OP16 (inst.instruction); |
6507 | inst.instruction |= Rd; | |
6508 | inst.instruction |= Rn << 3; | |
6509 | return; | |
a737bd4d | 6510 | } |
c19d1205 | 6511 | if (Rd == Rn) |
a737bd4d | 6512 | { |
c19d1205 ZW |
6513 | inst.instruction = THUMB_OP16 (inst.instruction); |
6514 | inst.instruction |= Rd; | |
6515 | inst.instruction |= Rs << 3; | |
6516 | return; | |
a737bd4d NC |
6517 | } |
6518 | } | |
c19d1205 ZW |
6519 | |
6520 | /* If we get here, it can't be done in 16 bits. */ | |
6521 | constraint (inst.operands[2].shifted | |
6522 | && inst.operands[2].immisreg, | |
6523 | _("shift must be constant")); | |
6524 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6525 | inst.instruction |= Rd << 8; | |
6526 | inst.instruction |= Rs << 16; | |
6527 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 6528 | } |
b99bd4ef | 6529 | } |
c19d1205 ZW |
6530 | else |
6531 | { | |
6532 | /* On its face this is a lie - the instruction does set the | |
6533 | flags. However, the only supported mnemonic in this mode | |
6534 | says it doesn't. */ | |
6535 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 6536 | |
c19d1205 ZW |
6537 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
6538 | _("unshifted register required")); | |
6539 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
6540 | ||
6541 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6542 | inst.instruction |= Rd; | |
6543 | ||
6544 | if (Rd == Rs) | |
6545 | inst.instruction |= Rn << 3; | |
6546 | else if (Rd == Rn) | |
6547 | inst.instruction |= Rs << 3; | |
6548 | else | |
6549 | constraint (1, _("dest must overlap one source register")); | |
6550 | } | |
a737bd4d NC |
6551 | } |
6552 | ||
62b3e311 PB |
6553 | static void |
6554 | do_t_barrier (void) | |
6555 | { | |
6556 | if (inst.operands[0].present) | |
6557 | { | |
6558 | constraint ((inst.instruction & 0xf0) != 0x40 | |
6559 | && inst.operands[0].imm != 0xf, | |
6560 | "bad barrier type"); | |
6561 | inst.instruction |= inst.operands[0].imm; | |
6562 | } | |
6563 | else | |
6564 | inst.instruction |= 0xf; | |
6565 | } | |
6566 | ||
c19d1205 ZW |
6567 | static void |
6568 | do_t_bfc (void) | |
a737bd4d | 6569 | { |
c19d1205 ZW |
6570 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
6571 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6572 | /* The instruction encoding stores the LSB and MSB, | |
6573 | not the LSB and width. */ | |
6574 | inst.instruction |= inst.operands[0].reg << 8; | |
6575 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; | |
6576 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
6577 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
6578 | } |
6579 | ||
c19d1205 ZW |
6580 | static void |
6581 | do_t_bfi (void) | |
b99bd4ef | 6582 | { |
c19d1205 | 6583 | unsigned int msb; |
b99bd4ef | 6584 | |
c19d1205 ZW |
6585 | /* #0 in second position is alternative syntax for bfc, which is |
6586 | the same instruction but with REG_PC in the Rm field. */ | |
6587 | if (!inst.operands[1].isreg) | |
6588 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 6589 | |
c19d1205 ZW |
6590 | msb = inst.operands[2].imm + inst.operands[3].imm; |
6591 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6592 | /* The instruction encoding stores the LSB and MSB, | |
6593 | not the LSB and width. */ | |
6594 | inst.instruction |= inst.operands[0].reg << 8; | |
6595 | inst.instruction |= inst.operands[1].reg << 16; | |
6596 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
6597 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
6598 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
6599 | } |
6600 | ||
c19d1205 ZW |
6601 | static void |
6602 | do_t_bfx (void) | |
b99bd4ef | 6603 | { |
c19d1205 ZW |
6604 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
6605 | _("bit-field extends past end of register")); | |
6606 | inst.instruction |= inst.operands[0].reg << 8; | |
6607 | inst.instruction |= inst.operands[1].reg << 16; | |
6608 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
6609 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
6610 | inst.instruction |= inst.operands[3].imm - 1; | |
6611 | } | |
b99bd4ef | 6612 | |
c19d1205 ZW |
6613 | /* ARM V5 Thumb BLX (argument parse) |
6614 | BLX <target_addr> which is BLX(1) | |
6615 | BLX <Rm> which is BLX(2) | |
6616 | Unfortunately, there are two different opcodes for this mnemonic. | |
6617 | So, the insns[].value is not used, and the code here zaps values | |
6618 | into inst.instruction. | |
b99bd4ef | 6619 | |
c19d1205 ZW |
6620 | ??? How to take advantage of the additional two bits of displacement |
6621 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 6622 | |
c19d1205 ZW |
6623 | static void |
6624 | do_t_blx (void) | |
6625 | { | |
dfa9f0d5 | 6626 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
6627 | if (inst.operands[0].isreg) |
6628 | /* We have a register, so this is BLX(2). */ | |
6629 | inst.instruction |= inst.operands[0].reg << 3; | |
b99bd4ef NC |
6630 | else |
6631 | { | |
c19d1205 | 6632 | /* No register. This must be BLX(1). */ |
2fc8bdac | 6633 | inst.instruction = 0xf000e800; |
39b41c9c PB |
6634 | #ifdef OBJ_ELF |
6635 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6636 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
6637 | else | |
6638 | #endif | |
6639 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; | |
c19d1205 | 6640 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
6641 | } |
6642 | } | |
6643 | ||
c19d1205 ZW |
6644 | static void |
6645 | do_t_branch (void) | |
b99bd4ef | 6646 | { |
0110f2b8 | 6647 | int opcode; |
dfa9f0d5 PB |
6648 | int cond; |
6649 | ||
6650 | if (current_it_mask) | |
6651 | { | |
6652 | /* Conditional branches inside IT blocks are encoded as unconditional | |
6653 | branches. */ | |
6654 | cond = COND_ALWAYS; | |
6655 | /* A branch must be the last instruction in an IT block. */ | |
6656 | constraint (current_it_mask != 0x10, BAD_BRANCH); | |
6657 | } | |
6658 | else | |
6659 | cond = inst.cond; | |
6660 | ||
6661 | if (cond != COND_ALWAYS) | |
0110f2b8 PB |
6662 | opcode = T_MNEM_bcond; |
6663 | else | |
6664 | opcode = inst.instruction; | |
6665 | ||
6666 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 6667 | { |
0110f2b8 | 6668 | inst.instruction = THUMB_OP32(opcode); |
dfa9f0d5 | 6669 | if (cond == COND_ALWAYS) |
0110f2b8 | 6670 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
6671 | else |
6672 | { | |
dfa9f0d5 PB |
6673 | assert (cond != 0xF); |
6674 | inst.instruction |= cond << 22; | |
c19d1205 ZW |
6675 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
6676 | } | |
6677 | } | |
b99bd4ef NC |
6678 | else |
6679 | { | |
0110f2b8 | 6680 | inst.instruction = THUMB_OP16(opcode); |
dfa9f0d5 | 6681 | if (cond == COND_ALWAYS) |
c19d1205 ZW |
6682 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; |
6683 | else | |
b99bd4ef | 6684 | { |
dfa9f0d5 | 6685 | inst.instruction |= cond << 8; |
c19d1205 | 6686 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 6687 | } |
0110f2b8 PB |
6688 | /* Allow section relaxation. */ |
6689 | if (unified_syntax && inst.size_req != 2) | |
6690 | inst.relax = opcode; | |
b99bd4ef | 6691 | } |
c19d1205 ZW |
6692 | |
6693 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
6694 | } |
6695 | ||
6696 | static void | |
c19d1205 | 6697 | do_t_bkpt (void) |
b99bd4ef | 6698 | { |
dfa9f0d5 PB |
6699 | constraint (inst.cond != COND_ALWAYS, |
6700 | _("instruction is always unconditional")); | |
c19d1205 | 6701 | if (inst.operands[0].present) |
b99bd4ef | 6702 | { |
c19d1205 ZW |
6703 | constraint (inst.operands[0].imm > 255, |
6704 | _("immediate value out of range")); | |
6705 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 6706 | } |
b99bd4ef NC |
6707 | } |
6708 | ||
6709 | static void | |
c19d1205 | 6710 | do_t_branch23 (void) |
b99bd4ef | 6711 | { |
dfa9f0d5 | 6712 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 | 6713 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
6714 | inst.reloc.pc_rel = 1; |
6715 | ||
c19d1205 ZW |
6716 | /* If the destination of the branch is a defined symbol which does not have |
6717 | the THUMB_FUNC attribute, then we must be calling a function which has | |
6718 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
6719 | function and change the branch to refer to that function instead. */ | |
6720 | if ( inst.reloc.exp.X_op == O_symbol | |
6721 | && inst.reloc.exp.X_add_symbol != NULL | |
6722 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
6723 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
6724 | inst.reloc.exp.X_add_symbol = | |
6725 | find_real_start (inst.reloc.exp.X_add_symbol); | |
90e4755a RE |
6726 | } |
6727 | ||
6728 | static void | |
c19d1205 | 6729 | do_t_bx (void) |
90e4755a | 6730 | { |
dfa9f0d5 | 6731 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
6732 | inst.instruction |= inst.operands[0].reg << 3; |
6733 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
6734 | should cause the alignment to be checked once it is known. This is | |
6735 | because BX PC only works if the instruction is word aligned. */ | |
6736 | } | |
90e4755a | 6737 | |
c19d1205 ZW |
6738 | static void |
6739 | do_t_bxj (void) | |
6740 | { | |
dfa9f0d5 | 6741 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
c19d1205 ZW |
6742 | if (inst.operands[0].reg == REG_PC) |
6743 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
90e4755a | 6744 | |
c19d1205 | 6745 | inst.instruction |= inst.operands[0].reg << 16; |
90e4755a RE |
6746 | } |
6747 | ||
6748 | static void | |
c19d1205 | 6749 | do_t_clz (void) |
90e4755a | 6750 | { |
c19d1205 ZW |
6751 | inst.instruction |= inst.operands[0].reg << 8; |
6752 | inst.instruction |= inst.operands[1].reg << 16; | |
6753 | inst.instruction |= inst.operands[1].reg; | |
6754 | } | |
90e4755a | 6755 | |
dfa9f0d5 PB |
6756 | static void |
6757 | do_t_cps (void) | |
6758 | { | |
6759 | constraint (current_it_mask, BAD_NOT_IT); | |
6760 | inst.instruction |= inst.operands[0].imm; | |
6761 | } | |
6762 | ||
c19d1205 ZW |
6763 | static void |
6764 | do_t_cpsi (void) | |
6765 | { | |
dfa9f0d5 | 6766 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 | 6767 | if (unified_syntax |
62b3e311 PB |
6768 | && (inst.operands[1].present || inst.size_req == 4) |
6769 | && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm)) | |
90e4755a | 6770 | { |
c19d1205 ZW |
6771 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
6772 | inst.instruction = 0xf3af8000; | |
6773 | inst.instruction |= imod << 9; | |
6774 | inst.instruction |= inst.operands[0].imm << 5; | |
6775 | if (inst.operands[1].present) | |
6776 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 6777 | } |
c19d1205 | 6778 | else |
90e4755a | 6779 | { |
62b3e311 PB |
6780 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1) |
6781 | && (inst.operands[0].imm & 4), | |
6782 | _("selected processor does not support 'A' form " | |
6783 | "of this instruction")); | |
6784 | constraint (inst.operands[1].present || inst.size_req == 4, | |
c19d1205 ZW |
6785 | _("Thumb does not support the 2-argument " |
6786 | "form of this instruction")); | |
6787 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 6788 | } |
90e4755a RE |
6789 | } |
6790 | ||
c19d1205 ZW |
6791 | /* THUMB CPY instruction (argument parse). */ |
6792 | ||
90e4755a | 6793 | static void |
c19d1205 | 6794 | do_t_cpy (void) |
90e4755a | 6795 | { |
c19d1205 | 6796 | if (inst.size_req == 4) |
90e4755a | 6797 | { |
c19d1205 ZW |
6798 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
6799 | inst.instruction |= inst.operands[0].reg << 8; | |
6800 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 6801 | } |
c19d1205 | 6802 | else |
90e4755a | 6803 | { |
c19d1205 ZW |
6804 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
6805 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
6806 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 6807 | } |
90e4755a RE |
6808 | } |
6809 | ||
90e4755a | 6810 | static void |
c19d1205 | 6811 | do_t_czb (void) |
90e4755a | 6812 | { |
dfa9f0d5 | 6813 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 ZW |
6814 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
6815 | inst.instruction |= inst.operands[0].reg; | |
6816 | inst.reloc.pc_rel = 1; | |
6817 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
6818 | } | |
90e4755a | 6819 | |
62b3e311 PB |
6820 | static void |
6821 | do_t_dbg (void) | |
6822 | { | |
6823 | inst.instruction |= inst.operands[0].imm; | |
6824 | } | |
6825 | ||
6826 | static void | |
6827 | do_t_div (void) | |
6828 | { | |
6829 | if (!inst.operands[1].present) | |
6830 | inst.operands[1].reg = inst.operands[0].reg; | |
6831 | inst.instruction |= inst.operands[0].reg << 8; | |
6832 | inst.instruction |= inst.operands[1].reg << 16; | |
6833 | inst.instruction |= inst.operands[2].reg; | |
6834 | } | |
6835 | ||
c19d1205 ZW |
6836 | static void |
6837 | do_t_hint (void) | |
6838 | { | |
6839 | if (unified_syntax && inst.size_req == 4) | |
6840 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6841 | else | |
6842 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6843 | } | |
90e4755a | 6844 | |
c19d1205 ZW |
6845 | static void |
6846 | do_t_it (void) | |
6847 | { | |
6848 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e | 6849 | |
dfa9f0d5 | 6850 | constraint (current_it_mask, BAD_NOT_IT); |
e27ec89e PB |
6851 | current_it_mask = (inst.instruction & 0xf) | 0x10; |
6852 | current_cc = cond; | |
6853 | ||
6854 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 6855 | if ((cond & 0x1) == 0x0) |
90e4755a | 6856 | { |
c19d1205 | 6857 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 6858 | |
c19d1205 ZW |
6859 | if ((mask & 0x7) == 0) |
6860 | /* no conversion needed */; | |
6861 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
6862 | mask ^= 0x8; |
6863 | else if ((mask & 0x1) == 0) | |
6864 | mask ^= 0xC; | |
c19d1205 | 6865 | else |
e27ec89e | 6866 | mask ^= 0xE; |
90e4755a | 6867 | |
e27ec89e PB |
6868 | inst.instruction &= 0xfff0; |
6869 | inst.instruction |= mask; | |
c19d1205 | 6870 | } |
90e4755a | 6871 | |
c19d1205 ZW |
6872 | inst.instruction |= cond << 4; |
6873 | } | |
90e4755a | 6874 | |
c19d1205 ZW |
6875 | static void |
6876 | do_t_ldmstm (void) | |
6877 | { | |
6878 | /* This really doesn't seem worth it. */ | |
6879 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
6880 | _("expression too complex")); | |
6881 | constraint (inst.operands[1].writeback, | |
6882 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 6883 | |
c19d1205 ZW |
6884 | if (unified_syntax) |
6885 | { | |
6886 | /* See if we can use a 16-bit instruction. */ | |
6887 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
6888 | && inst.size_req != 4 | |
6889 | && inst.operands[0].reg <= 7 | |
6890 | && !(inst.operands[1].imm & ~0xff) | |
6891 | && (inst.instruction == T_MNEM_stmia | |
6892 | ? inst.operands[0].writeback | |
6893 | : (inst.operands[0].writeback | |
6894 | == !(inst.operands[1].imm & (1 << inst.operands[0].reg))))) | |
90e4755a | 6895 | { |
c19d1205 ZW |
6896 | if (inst.instruction == T_MNEM_stmia |
6897 | && (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6898 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
6899 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
6900 | inst.operands[0].reg); | |
90e4755a | 6901 | |
c19d1205 ZW |
6902 | inst.instruction = THUMB_OP16 (inst.instruction); |
6903 | inst.instruction |= inst.operands[0].reg << 8; | |
6904 | inst.instruction |= inst.operands[1].imm; | |
6905 | } | |
6906 | else | |
6907 | { | |
6908 | if (inst.operands[1].imm & (1 << 13)) | |
6909 | as_warn (_("SP should not be in register list")); | |
6910 | if (inst.instruction == T_MNEM_stmia) | |
90e4755a | 6911 | { |
c19d1205 ZW |
6912 | if (inst.operands[1].imm & (1 << 15)) |
6913 | as_warn (_("PC should not be in register list")); | |
6914 | if (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6915 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
6916 | inst.operands[0].reg); | |
90e4755a RE |
6917 | } |
6918 | else | |
6919 | { | |
c19d1205 ZW |
6920 | if (inst.operands[1].imm & (1 << 14) |
6921 | && inst.operands[1].imm & (1 << 15)) | |
6922 | as_warn (_("LR and PC should not both be in register list")); | |
6923 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6924 | && inst.operands[0].writeback) | |
6925 | as_warn (_("base register should not be in register list " | |
6926 | "when written back")); | |
90e4755a | 6927 | } |
c19d1205 ZW |
6928 | if (inst.instruction < 0xffff) |
6929 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6930 | inst.instruction |= inst.operands[0].reg << 16; | |
6931 | inst.instruction |= inst.operands[1].imm; | |
6932 | if (inst.operands[0].writeback) | |
6933 | inst.instruction |= WRITE_BACK; | |
90e4755a RE |
6934 | } |
6935 | } | |
c19d1205 | 6936 | else |
90e4755a | 6937 | { |
c19d1205 ZW |
6938 | constraint (inst.operands[0].reg > 7 |
6939 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
6940 | if (inst.instruction == T_MNEM_stmia) | |
f03698e6 | 6941 | { |
c19d1205 ZW |
6942 | if (!inst.operands[0].writeback) |
6943 | as_warn (_("this instruction will write back the base register")); | |
6944 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6945 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
6946 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
6947 | inst.operands[0].reg); | |
f03698e6 | 6948 | } |
c19d1205 | 6949 | else |
90e4755a | 6950 | { |
c19d1205 ZW |
6951 | if (!inst.operands[0].writeback |
6952 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
6953 | as_warn (_("this instruction will write back the base register")); | |
6954 | else if (inst.operands[0].writeback | |
6955 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
6956 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
6957 | } |
6958 | ||
c19d1205 ZW |
6959 | inst.instruction = THUMB_OP16 (inst.instruction); |
6960 | inst.instruction |= inst.operands[0].reg << 8; | |
6961 | inst.instruction |= inst.operands[1].imm; | |
6962 | } | |
6963 | } | |
e28cd48c | 6964 | |
c19d1205 ZW |
6965 | static void |
6966 | do_t_ldrex (void) | |
6967 | { | |
6968 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
6969 | || inst.operands[1].postind || inst.operands[1].writeback | |
6970 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
6971 | || inst.operands[1].negative, | |
01cfc07f | 6972 | BAD_ADDR_MODE); |
e28cd48c | 6973 | |
c19d1205 ZW |
6974 | inst.instruction |= inst.operands[0].reg << 12; |
6975 | inst.instruction |= inst.operands[1].reg << 16; | |
6976 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
6977 | } | |
e28cd48c | 6978 | |
c19d1205 ZW |
6979 | static void |
6980 | do_t_ldrexd (void) | |
6981 | { | |
6982 | if (!inst.operands[1].present) | |
1cac9012 | 6983 | { |
c19d1205 ZW |
6984 | constraint (inst.operands[0].reg == REG_LR, |
6985 | _("r14 not allowed as first register " | |
6986 | "when second register is omitted")); | |
6987 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 6988 | } |
c19d1205 ZW |
6989 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
6990 | BAD_OVERLAP); | |
b99bd4ef | 6991 | |
c19d1205 ZW |
6992 | inst.instruction |= inst.operands[0].reg << 12; |
6993 | inst.instruction |= inst.operands[1].reg << 8; | |
6994 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
6995 | } |
6996 | ||
6997 | static void | |
c19d1205 | 6998 | do_t_ldst (void) |
b99bd4ef | 6999 | { |
0110f2b8 PB |
7000 | unsigned long opcode; |
7001 | int Rn; | |
7002 | ||
7003 | opcode = inst.instruction; | |
c19d1205 | 7004 | if (unified_syntax) |
b99bd4ef | 7005 | { |
53365c0d PB |
7006 | if (!inst.operands[1].isreg) |
7007 | { | |
7008 | if (opcode <= 0xffff) | |
7009 | inst.instruction = THUMB_OP32 (opcode); | |
7010 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
7011 | return; | |
7012 | } | |
0110f2b8 PB |
7013 | if (inst.operands[1].isreg |
7014 | && !inst.operands[1].writeback | |
c19d1205 ZW |
7015 | && !inst.operands[1].shifted && !inst.operands[1].postind |
7016 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
7017 | && opcode <= 0xffff |
7018 | && inst.size_req != 4) | |
c19d1205 | 7019 | { |
0110f2b8 PB |
7020 | /* Insn may have a 16-bit form. */ |
7021 | Rn = inst.operands[1].reg; | |
7022 | if (inst.operands[1].immisreg) | |
7023 | { | |
7024 | inst.instruction = THUMB_OP16 (opcode); | |
7025 | /* [Rn, Ri] */ | |
7026 | if (Rn <= 7 && inst.operands[1].imm <= 7) | |
7027 | goto op16; | |
7028 | } | |
7029 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
7030 | && opcode != T_MNEM_ldrsb) | |
7031 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
7032 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
7033 | { | |
7034 | /* [Rn, #const] */ | |
7035 | if (Rn > 7) | |
7036 | { | |
7037 | if (Rn == REG_PC) | |
7038 | { | |
7039 | if (inst.reloc.pc_rel) | |
7040 | opcode = T_MNEM_ldr_pc2; | |
7041 | else | |
7042 | opcode = T_MNEM_ldr_pc; | |
7043 | } | |
7044 | else | |
7045 | { | |
7046 | if (opcode == T_MNEM_ldr) | |
7047 | opcode = T_MNEM_ldr_sp; | |
7048 | else | |
7049 | opcode = T_MNEM_str_sp; | |
7050 | } | |
7051 | inst.instruction = inst.operands[0].reg << 8; | |
7052 | } | |
7053 | else | |
7054 | { | |
7055 | inst.instruction = inst.operands[0].reg; | |
7056 | inst.instruction |= inst.operands[1].reg << 3; | |
7057 | } | |
7058 | inst.instruction |= THUMB_OP16 (opcode); | |
7059 | if (inst.size_req == 2) | |
7060 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
7061 | else | |
7062 | inst.relax = opcode; | |
7063 | return; | |
7064 | } | |
c19d1205 | 7065 | } |
0110f2b8 PB |
7066 | /* Definitely a 32-bit variant. */ |
7067 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
7068 | inst.instruction |= inst.operands[0].reg << 12; |
7069 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
7070 | return; |
7071 | } | |
7072 | ||
c19d1205 ZW |
7073 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
7074 | ||
7075 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 7076 | { |
c19d1205 ZW |
7077 | /* Only [Rn,Rm] is acceptable. */ |
7078 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
7079 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
7080 | || inst.operands[1].postind || inst.operands[1].shifted | |
7081 | || inst.operands[1].negative, | |
7082 | _("Thumb does not support this addressing mode")); | |
7083 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7084 | goto op16; | |
b99bd4ef | 7085 | } |
c19d1205 ZW |
7086 | |
7087 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7088 | if (!inst.operands[1].isreg) | |
7089 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
7090 | return; | |
b99bd4ef | 7091 | |
c19d1205 ZW |
7092 | constraint (!inst.operands[1].preind |
7093 | || inst.operands[1].shifted | |
7094 | || inst.operands[1].writeback, | |
7095 | _("Thumb does not support this addressing mode")); | |
7096 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 7097 | { |
c19d1205 ZW |
7098 | constraint (inst.instruction & 0x0600, |
7099 | _("byte or halfword not valid for base register")); | |
7100 | constraint (inst.operands[1].reg == REG_PC | |
7101 | && !(inst.instruction & THUMB_LOAD_BIT), | |
7102 | _("r15 based store not allowed")); | |
7103 | constraint (inst.operands[1].immisreg, | |
7104 | _("invalid base register for register offset")); | |
b99bd4ef | 7105 | |
c19d1205 ZW |
7106 | if (inst.operands[1].reg == REG_PC) |
7107 | inst.instruction = T_OPCODE_LDR_PC; | |
7108 | else if (inst.instruction & THUMB_LOAD_BIT) | |
7109 | inst.instruction = T_OPCODE_LDR_SP; | |
7110 | else | |
7111 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 7112 | |
c19d1205 ZW |
7113 | inst.instruction |= inst.operands[0].reg << 8; |
7114 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
7115 | return; | |
7116 | } | |
90e4755a | 7117 | |
c19d1205 ZW |
7118 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
7119 | if (!inst.operands[1].immisreg) | |
7120 | { | |
7121 | /* Immediate offset. */ | |
7122 | inst.instruction |= inst.operands[0].reg; | |
7123 | inst.instruction |= inst.operands[1].reg << 3; | |
7124 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
7125 | return; | |
7126 | } | |
90e4755a | 7127 | |
c19d1205 ZW |
7128 | /* Register offset. */ |
7129 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
7130 | constraint (inst.operands[1].negative, | |
7131 | _("Thumb does not support this addressing mode")); | |
90e4755a | 7132 | |
c19d1205 ZW |
7133 | op16: |
7134 | switch (inst.instruction) | |
7135 | { | |
7136 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
7137 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
7138 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
7139 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
7140 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
7141 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
7142 | case 0x5600 /* ldrsb */: | |
7143 | case 0x5e00 /* ldrsh */: break; | |
7144 | default: abort (); | |
7145 | } | |
90e4755a | 7146 | |
c19d1205 ZW |
7147 | inst.instruction |= inst.operands[0].reg; |
7148 | inst.instruction |= inst.operands[1].reg << 3; | |
7149 | inst.instruction |= inst.operands[1].imm << 6; | |
7150 | } | |
90e4755a | 7151 | |
c19d1205 ZW |
7152 | static void |
7153 | do_t_ldstd (void) | |
7154 | { | |
7155 | if (!inst.operands[1].present) | |
b99bd4ef | 7156 | { |
c19d1205 ZW |
7157 | inst.operands[1].reg = inst.operands[0].reg + 1; |
7158 | constraint (inst.operands[0].reg == REG_LR, | |
7159 | _("r14 not allowed here")); | |
b99bd4ef | 7160 | } |
c19d1205 ZW |
7161 | inst.instruction |= inst.operands[0].reg << 12; |
7162 | inst.instruction |= inst.operands[1].reg << 8; | |
7163 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
7164 | ||
b99bd4ef NC |
7165 | } |
7166 | ||
c19d1205 ZW |
7167 | static void |
7168 | do_t_ldstt (void) | |
7169 | { | |
7170 | inst.instruction |= inst.operands[0].reg << 12; | |
7171 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
7172 | } | |
a737bd4d | 7173 | |
b99bd4ef | 7174 | static void |
c19d1205 | 7175 | do_t_mla (void) |
b99bd4ef | 7176 | { |
c19d1205 ZW |
7177 | inst.instruction |= inst.operands[0].reg << 8; |
7178 | inst.instruction |= inst.operands[1].reg << 16; | |
7179 | inst.instruction |= inst.operands[2].reg; | |
7180 | inst.instruction |= inst.operands[3].reg << 12; | |
7181 | } | |
b99bd4ef | 7182 | |
c19d1205 ZW |
7183 | static void |
7184 | do_t_mlal (void) | |
7185 | { | |
7186 | inst.instruction |= inst.operands[0].reg << 12; | |
7187 | inst.instruction |= inst.operands[1].reg << 8; | |
7188 | inst.instruction |= inst.operands[2].reg << 16; | |
7189 | inst.instruction |= inst.operands[3].reg; | |
7190 | } | |
b99bd4ef | 7191 | |
c19d1205 ZW |
7192 | static void |
7193 | do_t_mov_cmp (void) | |
7194 | { | |
7195 | if (unified_syntax) | |
b99bd4ef | 7196 | { |
c19d1205 ZW |
7197 | int r0off = (inst.instruction == T_MNEM_mov |
7198 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 7199 | unsigned long opcode; |
3d388997 PB |
7200 | bfd_boolean narrow; |
7201 | bfd_boolean low_regs; | |
7202 | ||
7203 | low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7); | |
0110f2b8 | 7204 | opcode = inst.instruction; |
3d388997 | 7205 | if (current_it_mask) |
0110f2b8 | 7206 | narrow = opcode != T_MNEM_movs; |
3d388997 | 7207 | else |
0110f2b8 | 7208 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
7209 | if (inst.size_req == 4 |
7210 | || inst.operands[1].shifted) | |
7211 | narrow = FALSE; | |
7212 | ||
c19d1205 ZW |
7213 | if (!inst.operands[1].isreg) |
7214 | { | |
0110f2b8 PB |
7215 | /* Immediate operand. */ |
7216 | if (current_it_mask == 0 && opcode == T_MNEM_mov) | |
7217 | narrow = 0; | |
7218 | if (low_regs && narrow) | |
7219 | { | |
7220 | inst.instruction = THUMB_OP16 (opcode); | |
7221 | inst.instruction |= inst.operands[0].reg << 8; | |
7222 | if (inst.size_req == 2) | |
7223 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
7224 | else | |
7225 | inst.relax = opcode; | |
7226 | } | |
7227 | else | |
7228 | { | |
7229 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7230 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
7231 | inst.instruction |= inst.operands[0].reg << r0off; | |
7232 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
7233 | } | |
c19d1205 | 7234 | } |
3d388997 | 7235 | else if (!narrow) |
c19d1205 ZW |
7236 | { |
7237 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7238 | inst.instruction |= inst.operands[0].reg << r0off; | |
7239 | encode_thumb32_shifted_operand (1); | |
7240 | } | |
7241 | else | |
7242 | switch (inst.instruction) | |
7243 | { | |
7244 | case T_MNEM_mov: | |
7245 | inst.instruction = T_OPCODE_MOV_HR; | |
7246 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
7247 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
7248 | inst.instruction |= inst.operands[1].reg << 3; | |
7249 | break; | |
b99bd4ef | 7250 | |
c19d1205 ZW |
7251 | case T_MNEM_movs: |
7252 | /* We know we have low registers at this point. | |
7253 | Generate ADD Rd, Rs, #0. */ | |
7254 | inst.instruction = T_OPCODE_ADD_I3; | |
7255 | inst.instruction |= inst.operands[0].reg; | |
7256 | inst.instruction |= inst.operands[1].reg << 3; | |
7257 | break; | |
7258 | ||
7259 | case T_MNEM_cmp: | |
3d388997 | 7260 | if (low_regs) |
c19d1205 ZW |
7261 | { |
7262 | inst.instruction = T_OPCODE_CMP_LR; | |
7263 | inst.instruction |= inst.operands[0].reg; | |
7264 | inst.instruction |= inst.operands[1].reg << 3; | |
7265 | } | |
7266 | else | |
7267 | { | |
7268 | inst.instruction = T_OPCODE_CMP_HR; | |
7269 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
7270 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
7271 | inst.instruction |= inst.operands[1].reg << 3; | |
7272 | } | |
7273 | break; | |
7274 | } | |
b99bd4ef NC |
7275 | return; |
7276 | } | |
7277 | ||
c19d1205 ZW |
7278 | inst.instruction = THUMB_OP16 (inst.instruction); |
7279 | if (inst.operands[1].isreg) | |
b99bd4ef | 7280 | { |
c19d1205 | 7281 | if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8) |
b99bd4ef | 7282 | { |
c19d1205 ZW |
7283 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
7284 | since a MOV instruction produces unpredictable results. */ | |
7285 | if (inst.instruction == T_OPCODE_MOV_I8) | |
7286 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 7287 | else |
c19d1205 | 7288 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 7289 | |
c19d1205 ZW |
7290 | inst.instruction |= inst.operands[0].reg; |
7291 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
7292 | } |
7293 | else | |
7294 | { | |
c19d1205 ZW |
7295 | if (inst.instruction == T_OPCODE_MOV_I8) |
7296 | inst.instruction = T_OPCODE_MOV_HR; | |
7297 | else | |
7298 | inst.instruction = T_OPCODE_CMP_HR; | |
7299 | do_t_cpy (); | |
b99bd4ef NC |
7300 | } |
7301 | } | |
c19d1205 | 7302 | else |
b99bd4ef | 7303 | { |
c19d1205 ZW |
7304 | constraint (inst.operands[0].reg > 7, |
7305 | _("only lo regs allowed with immediate")); | |
7306 | inst.instruction |= inst.operands[0].reg << 8; | |
7307 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
7308 | } | |
7309 | } | |
b99bd4ef | 7310 | |
c19d1205 ZW |
7311 | static void |
7312 | do_t_mov16 (void) | |
7313 | { | |
7314 | inst.instruction |= inst.operands[0].reg << 8; | |
7315 | inst.instruction |= (inst.operands[1].imm & 0xf000) << 4; | |
7316 | inst.instruction |= (inst.operands[1].imm & 0x0800) << 15; | |
7317 | inst.instruction |= (inst.operands[1].imm & 0x0700) << 4; | |
7318 | inst.instruction |= (inst.operands[1].imm & 0x00ff); | |
7319 | } | |
b99bd4ef | 7320 | |
c19d1205 ZW |
7321 | static void |
7322 | do_t_mvn_tst (void) | |
7323 | { | |
7324 | if (unified_syntax) | |
7325 | { | |
7326 | int r0off = (inst.instruction == T_MNEM_mvn | |
7327 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
7328 | bfd_boolean narrow; |
7329 | ||
7330 | if (inst.size_req == 4 | |
7331 | || inst.instruction > 0xffff | |
7332 | || inst.operands[1].shifted | |
7333 | || inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
7334 | narrow = FALSE; | |
7335 | else if (inst.instruction == T_MNEM_cmn) | |
7336 | narrow = TRUE; | |
7337 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
7338 | narrow = (current_it_mask == 0); | |
7339 | else | |
7340 | narrow = (current_it_mask != 0); | |
7341 | ||
c19d1205 | 7342 | if (!inst.operands[1].isreg) |
b99bd4ef | 7343 | { |
c19d1205 ZW |
7344 | /* For an immediate, we always generate a 32-bit opcode; |
7345 | section relaxation will shrink it later if possible. */ | |
7346 | if (inst.instruction < 0xffff) | |
7347 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7348 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
7349 | inst.instruction |= inst.operands[0].reg << r0off; | |
7350 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 7351 | } |
c19d1205 | 7352 | else |
b99bd4ef | 7353 | { |
c19d1205 | 7354 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 7355 | if (narrow) |
b99bd4ef | 7356 | { |
c19d1205 ZW |
7357 | inst.instruction = THUMB_OP16 (inst.instruction); |
7358 | inst.instruction |= inst.operands[0].reg; | |
7359 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 7360 | } |
c19d1205 | 7361 | else |
b99bd4ef | 7362 | { |
c19d1205 ZW |
7363 | constraint (inst.operands[1].shifted |
7364 | && inst.operands[1].immisreg, | |
7365 | _("shift must be constant")); | |
7366 | if (inst.instruction < 0xffff) | |
7367 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7368 | inst.instruction |= inst.operands[0].reg << r0off; | |
7369 | encode_thumb32_shifted_operand (1); | |
b99bd4ef | 7370 | } |
b99bd4ef NC |
7371 | } |
7372 | } | |
7373 | else | |
7374 | { | |
c19d1205 ZW |
7375 | constraint (inst.instruction > 0xffff |
7376 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
7377 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
7378 | _("unshifted register required")); | |
7379 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
7380 | BAD_HIREG); | |
b99bd4ef | 7381 | |
c19d1205 ZW |
7382 | inst.instruction = THUMB_OP16 (inst.instruction); |
7383 | inst.instruction |= inst.operands[0].reg; | |
7384 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 7385 | } |
b99bd4ef NC |
7386 | } |
7387 | ||
b05fe5cf | 7388 | static void |
c19d1205 | 7389 | do_t_mrs (void) |
b05fe5cf | 7390 | { |
62b3e311 PB |
7391 | int flags; |
7392 | flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT); | |
7393 | if (flags == 0) | |
7394 | { | |
7395 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m), | |
7396 | _("selected processor does not support " | |
7397 | "requested special purpose register")); | |
7398 | } | |
7399 | else | |
7400 | { | |
7401 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
7402 | _("selected processor does not support " | |
7403 | "requested special purpose register %x")); | |
7404 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ | |
7405 | constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f), | |
7406 | _("'CPSR' or 'SPSR' expected")); | |
7407 | } | |
7408 | ||
c19d1205 | 7409 | inst.instruction |= inst.operands[0].reg << 8; |
62b3e311 PB |
7410 | inst.instruction |= (flags & SPSR_BIT) >> 2; |
7411 | inst.instruction |= inst.operands[1].imm & 0xff; | |
c19d1205 | 7412 | } |
b05fe5cf | 7413 | |
c19d1205 ZW |
7414 | static void |
7415 | do_t_msr (void) | |
7416 | { | |
62b3e311 PB |
7417 | int flags; |
7418 | ||
c19d1205 ZW |
7419 | constraint (!inst.operands[1].isreg, |
7420 | _("Thumb encoding does not support an immediate here")); | |
62b3e311 PB |
7421 | flags = inst.operands[0].imm; |
7422 | if (flags & ~0xff) | |
7423 | { | |
7424 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1), | |
7425 | _("selected processor does not support " | |
7426 | "requested special purpose register")); | |
7427 | } | |
7428 | else | |
7429 | { | |
7430 | constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m), | |
7431 | _("selected processor does not support " | |
7432 | "requested special purpose register")); | |
7433 | flags |= PSR_f; | |
7434 | } | |
7435 | inst.instruction |= (flags & SPSR_BIT) >> 2; | |
7436 | inst.instruction |= (flags & ~SPSR_BIT) >> 8; | |
7437 | inst.instruction |= (flags & 0xff); | |
c19d1205 ZW |
7438 | inst.instruction |= inst.operands[1].reg << 16; |
7439 | } | |
b05fe5cf | 7440 | |
c19d1205 ZW |
7441 | static void |
7442 | do_t_mul (void) | |
7443 | { | |
7444 | if (!inst.operands[2].present) | |
7445 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 7446 | |
c19d1205 ZW |
7447 | /* There is no 32-bit MULS and no 16-bit MUL. */ |
7448 | if (unified_syntax && inst.instruction == T_MNEM_mul) | |
b05fe5cf | 7449 | { |
c19d1205 ZW |
7450 | inst.instruction = THUMB_OP32 (inst.instruction); |
7451 | inst.instruction |= inst.operands[0].reg << 8; | |
7452 | inst.instruction |= inst.operands[1].reg << 16; | |
7453 | inst.instruction |= inst.operands[2].reg << 0; | |
b05fe5cf | 7454 | } |
c19d1205 | 7455 | else |
b05fe5cf | 7456 | { |
c19d1205 ZW |
7457 | constraint (!unified_syntax |
7458 | && inst.instruction == T_MNEM_muls, BAD_THUMB32); | |
7459 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
7460 | BAD_HIREG); | |
b05fe5cf | 7461 | |
c19d1205 ZW |
7462 | inst.instruction = THUMB_OP16 (inst.instruction); |
7463 | inst.instruction |= inst.operands[0].reg; | |
b05fe5cf | 7464 | |
c19d1205 ZW |
7465 | if (inst.operands[0].reg == inst.operands[1].reg) |
7466 | inst.instruction |= inst.operands[2].reg << 3; | |
7467 | else if (inst.operands[0].reg == inst.operands[2].reg) | |
7468 | inst.instruction |= inst.operands[1].reg << 3; | |
7469 | else | |
7470 | constraint (1, _("dest must overlap one source register")); | |
7471 | } | |
7472 | } | |
b05fe5cf | 7473 | |
c19d1205 ZW |
7474 | static void |
7475 | do_t_mull (void) | |
7476 | { | |
7477 | inst.instruction |= inst.operands[0].reg << 12; | |
7478 | inst.instruction |= inst.operands[1].reg << 8; | |
7479 | inst.instruction |= inst.operands[2].reg << 16; | |
7480 | inst.instruction |= inst.operands[3].reg; | |
b05fe5cf | 7481 | |
c19d1205 ZW |
7482 | if (inst.operands[0].reg == inst.operands[1].reg) |
7483 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7484 | } | |
b05fe5cf | 7485 | |
c19d1205 ZW |
7486 | static void |
7487 | do_t_nop (void) | |
7488 | { | |
7489 | if (unified_syntax) | |
7490 | { | |
7491 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 7492 | { |
c19d1205 ZW |
7493 | inst.instruction = THUMB_OP32 (inst.instruction); |
7494 | inst.instruction |= inst.operands[0].imm; | |
7495 | } | |
7496 | else | |
7497 | { | |
7498 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7499 | inst.instruction |= inst.operands[0].imm << 4; | |
7500 | } | |
7501 | } | |
7502 | else | |
7503 | { | |
7504 | constraint (inst.operands[0].present, | |
7505 | _("Thumb does not support NOP with hints")); | |
7506 | inst.instruction = 0x46c0; | |
7507 | } | |
7508 | } | |
b05fe5cf | 7509 | |
c19d1205 ZW |
7510 | static void |
7511 | do_t_neg (void) | |
7512 | { | |
7513 | if (unified_syntax) | |
7514 | { | |
3d388997 PB |
7515 | bfd_boolean narrow; |
7516 | ||
7517 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
7518 | narrow = (current_it_mask == 0); | |
7519 | else | |
7520 | narrow = (current_it_mask != 0); | |
7521 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
7522 | narrow = FALSE; | |
7523 | if (inst.size_req == 4) | |
7524 | narrow = FALSE; | |
7525 | ||
7526 | if (!narrow) | |
c19d1205 ZW |
7527 | { |
7528 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7529 | inst.instruction |= inst.operands[0].reg << 8; | |
7530 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
7531 | } |
7532 | else | |
7533 | { | |
c19d1205 ZW |
7534 | inst.instruction = THUMB_OP16 (inst.instruction); |
7535 | inst.instruction |= inst.operands[0].reg; | |
7536 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
7537 | } |
7538 | } | |
7539 | else | |
7540 | { | |
c19d1205 ZW |
7541 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
7542 | BAD_HIREG); | |
7543 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
7544 | ||
7545 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7546 | inst.instruction |= inst.operands[0].reg; | |
7547 | inst.instruction |= inst.operands[1].reg << 3; | |
7548 | } | |
7549 | } | |
7550 | ||
7551 | static void | |
7552 | do_t_pkhbt (void) | |
7553 | { | |
7554 | inst.instruction |= inst.operands[0].reg << 8; | |
7555 | inst.instruction |= inst.operands[1].reg << 16; | |
7556 | inst.instruction |= inst.operands[2].reg; | |
7557 | if (inst.operands[3].present) | |
7558 | { | |
7559 | unsigned int val = inst.reloc.exp.X_add_number; | |
7560 | constraint (inst.reloc.exp.X_op != O_constant, | |
7561 | _("expression too complex")); | |
7562 | inst.instruction |= (val & 0x1c) << 10; | |
7563 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 7564 | } |
c19d1205 | 7565 | } |
b05fe5cf | 7566 | |
c19d1205 ZW |
7567 | static void |
7568 | do_t_pkhtb (void) | |
7569 | { | |
7570 | if (!inst.operands[3].present) | |
7571 | inst.instruction &= ~0x00000020; | |
7572 | do_t_pkhbt (); | |
b05fe5cf ZW |
7573 | } |
7574 | ||
c19d1205 ZW |
7575 | static void |
7576 | do_t_pld (void) | |
7577 | { | |
7578 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
7579 | } | |
b05fe5cf | 7580 | |
c19d1205 ZW |
7581 | static void |
7582 | do_t_push_pop (void) | |
b99bd4ef | 7583 | { |
e9f89963 PB |
7584 | unsigned mask; |
7585 | ||
c19d1205 ZW |
7586 | constraint (inst.operands[0].writeback, |
7587 | _("push/pop do not support {reglist}^")); | |
7588 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
7589 | _("expression too complex")); | |
b99bd4ef | 7590 | |
e9f89963 PB |
7591 | mask = inst.operands[0].imm; |
7592 | if ((mask & ~0xff) == 0) | |
c19d1205 ZW |
7593 | inst.instruction = THUMB_OP16 (inst.instruction); |
7594 | else if ((inst.instruction == T_MNEM_push | |
e9f89963 | 7595 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 7596 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 7597 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 7598 | { |
c19d1205 ZW |
7599 | inst.instruction = THUMB_OP16 (inst.instruction); |
7600 | inst.instruction |= THUMB_PP_PC_LR; | |
e9f89963 | 7601 | mask &= 0xff; |
c19d1205 ZW |
7602 | } |
7603 | else if (unified_syntax) | |
7604 | { | |
e9f89963 PB |
7605 | if (mask & (1 << 13)) |
7606 | inst.error = _("SP not allowed in register list"); | |
c19d1205 | 7607 | if (inst.instruction == T_MNEM_push) |
b99bd4ef | 7608 | { |
e9f89963 PB |
7609 | if (mask & (1 << 15)) |
7610 | inst.error = _("PC not allowed in register list"); | |
c19d1205 ZW |
7611 | } |
7612 | else | |
7613 | { | |
e9f89963 PB |
7614 | if (mask & (1 << 14) |
7615 | && mask & (1 << 15)) | |
7616 | inst.error = _("LR and PC should not both be in register list"); | |
c19d1205 | 7617 | } |
e9f89963 PB |
7618 | if ((mask & (mask - 1)) == 0) |
7619 | { | |
7620 | /* Single register push/pop implemented as str/ldr. */ | |
7621 | if (inst.instruction == T_MNEM_push) | |
7622 | inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */ | |
7623 | else | |
7624 | inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */ | |
7625 | mask = ffs(mask) - 1; | |
7626 | mask <<= 12; | |
7627 | } | |
7628 | else | |
7629 | inst.instruction = THUMB_OP32 (inst.instruction); | |
c19d1205 ZW |
7630 | } |
7631 | else | |
7632 | { | |
7633 | inst.error = _("invalid register list to push/pop instruction"); | |
7634 | return; | |
7635 | } | |
b99bd4ef | 7636 | |
e9f89963 | 7637 | inst.instruction |= mask; |
c19d1205 | 7638 | } |
b99bd4ef | 7639 | |
c19d1205 ZW |
7640 | static void |
7641 | do_t_rbit (void) | |
7642 | { | |
7643 | inst.instruction |= inst.operands[0].reg << 8; | |
7644 | inst.instruction |= inst.operands[1].reg << 16; | |
7645 | } | |
b99bd4ef | 7646 | |
c19d1205 ZW |
7647 | static void |
7648 | do_t_rev (void) | |
7649 | { | |
7650 | if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
7651 | && inst.size_req != 4) | |
7652 | { | |
7653 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7654 | inst.instruction |= inst.operands[0].reg; | |
7655 | inst.instruction |= inst.operands[1].reg << 3; | |
7656 | } | |
7657 | else if (unified_syntax) | |
7658 | { | |
7659 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7660 | inst.instruction |= inst.operands[0].reg << 8; | |
7661 | inst.instruction |= inst.operands[1].reg << 16; | |
7662 | inst.instruction |= inst.operands[1].reg; | |
7663 | } | |
7664 | else | |
7665 | inst.error = BAD_HIREG; | |
7666 | } | |
b99bd4ef | 7667 | |
c19d1205 ZW |
7668 | static void |
7669 | do_t_rsb (void) | |
7670 | { | |
7671 | int Rd, Rs; | |
b99bd4ef | 7672 | |
c19d1205 ZW |
7673 | Rd = inst.operands[0].reg; |
7674 | Rs = (inst.operands[1].present | |
7675 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
7676 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 7677 | |
c19d1205 ZW |
7678 | inst.instruction |= Rd << 8; |
7679 | inst.instruction |= Rs << 16; | |
7680 | if (!inst.operands[2].isreg) | |
7681 | { | |
7682 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
7683 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
7684 | } | |
7685 | else | |
7686 | encode_thumb32_shifted_operand (2); | |
7687 | } | |
b99bd4ef | 7688 | |
c19d1205 ZW |
7689 | static void |
7690 | do_t_setend (void) | |
7691 | { | |
dfa9f0d5 | 7692 | constraint (current_it_mask, BAD_NOT_IT); |
c19d1205 ZW |
7693 | if (inst.operands[0].imm) |
7694 | inst.instruction |= 0x8; | |
7695 | } | |
b99bd4ef | 7696 | |
c19d1205 ZW |
7697 | static void |
7698 | do_t_shift (void) | |
7699 | { | |
7700 | if (!inst.operands[1].present) | |
7701 | inst.operands[1].reg = inst.operands[0].reg; | |
7702 | ||
7703 | if (unified_syntax) | |
7704 | { | |
3d388997 PB |
7705 | bfd_boolean narrow; |
7706 | int shift_kind; | |
7707 | ||
7708 | switch (inst.instruction) | |
7709 | { | |
7710 | case T_MNEM_asr: | |
7711 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
7712 | case T_MNEM_lsl: | |
7713 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
7714 | case T_MNEM_lsr: | |
7715 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
7716 | case T_MNEM_ror: | |
7717 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
7718 | default: abort (); | |
7719 | } | |
7720 | ||
7721 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
7722 | narrow = (current_it_mask == 0); | |
7723 | else | |
7724 | narrow = (current_it_mask != 0); | |
7725 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
7726 | narrow = FALSE; | |
7727 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
7728 | narrow = FALSE; | |
7729 | if (inst.operands[2].isreg | |
7730 | && (inst.operands[1].reg != inst.operands[0].reg | |
7731 | || inst.operands[2].reg > 7)) | |
7732 | narrow = FALSE; | |
7733 | if (inst.size_req == 4) | |
7734 | narrow = FALSE; | |
7735 | ||
7736 | if (!narrow) | |
c19d1205 ZW |
7737 | { |
7738 | if (inst.operands[2].isreg) | |
b99bd4ef | 7739 | { |
c19d1205 ZW |
7740 | inst.instruction = THUMB_OP32 (inst.instruction); |
7741 | inst.instruction |= inst.operands[0].reg << 8; | |
7742 | inst.instruction |= inst.operands[1].reg << 16; | |
7743 | inst.instruction |= inst.operands[2].reg; | |
7744 | } | |
7745 | else | |
7746 | { | |
7747 | inst.operands[1].shifted = 1; | |
3d388997 | 7748 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
7749 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
7750 | ? T_MNEM_movs : T_MNEM_mov); | |
7751 | inst.instruction |= inst.operands[0].reg << 8; | |
7752 | encode_thumb32_shifted_operand (1); | |
7753 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
7754 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
7755 | } |
7756 | } | |
7757 | else | |
7758 | { | |
c19d1205 | 7759 | if (inst.operands[2].isreg) |
b99bd4ef | 7760 | { |
3d388997 | 7761 | switch (shift_kind) |
b99bd4ef | 7762 | { |
3d388997 PB |
7763 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
7764 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
7765 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
7766 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 7767 | default: abort (); |
b99bd4ef | 7768 | } |
c19d1205 ZW |
7769 | |
7770 | inst.instruction |= inst.operands[0].reg; | |
7771 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
7772 | } |
7773 | else | |
7774 | { | |
3d388997 | 7775 | switch (shift_kind) |
b99bd4ef | 7776 | { |
3d388997 PB |
7777 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
7778 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
7779 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 7780 | default: abort (); |
b99bd4ef | 7781 | } |
c19d1205 ZW |
7782 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
7783 | inst.instruction |= inst.operands[0].reg; | |
7784 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
7785 | } |
7786 | } | |
c19d1205 ZW |
7787 | } |
7788 | else | |
7789 | { | |
7790 | constraint (inst.operands[0].reg > 7 | |
7791 | || inst.operands[1].reg > 7, BAD_HIREG); | |
7792 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 7793 | |
c19d1205 ZW |
7794 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
7795 | { | |
7796 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
7797 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
7798 | _("source1 and dest must be same register")); | |
b99bd4ef | 7799 | |
c19d1205 ZW |
7800 | switch (inst.instruction) |
7801 | { | |
7802 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
7803 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
7804 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
7805 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
7806 | default: abort (); | |
7807 | } | |
7808 | ||
7809 | inst.instruction |= inst.operands[0].reg; | |
7810 | inst.instruction |= inst.operands[2].reg << 3; | |
7811 | } | |
7812 | else | |
b99bd4ef | 7813 | { |
c19d1205 ZW |
7814 | switch (inst.instruction) |
7815 | { | |
7816 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
7817 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
7818 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
7819 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
7820 | default: abort (); | |
7821 | } | |
7822 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
7823 | inst.instruction |= inst.operands[0].reg; | |
7824 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
7825 | } |
7826 | } | |
b99bd4ef NC |
7827 | } |
7828 | ||
7829 | static void | |
c19d1205 | 7830 | do_t_simd (void) |
b99bd4ef | 7831 | { |
c19d1205 ZW |
7832 | inst.instruction |= inst.operands[0].reg << 8; |
7833 | inst.instruction |= inst.operands[1].reg << 16; | |
7834 | inst.instruction |= inst.operands[2].reg; | |
7835 | } | |
b99bd4ef | 7836 | |
c19d1205 | 7837 | static void |
3eb17e6b | 7838 | do_t_smc (void) |
c19d1205 ZW |
7839 | { |
7840 | unsigned int value = inst.reloc.exp.X_add_number; | |
7841 | constraint (inst.reloc.exp.X_op != O_constant, | |
7842 | _("expression too complex")); | |
7843 | inst.reloc.type = BFD_RELOC_UNUSED; | |
7844 | inst.instruction |= (value & 0xf000) >> 12; | |
7845 | inst.instruction |= (value & 0x0ff0); | |
7846 | inst.instruction |= (value & 0x000f) << 16; | |
7847 | } | |
b99bd4ef | 7848 | |
c19d1205 ZW |
7849 | static void |
7850 | do_t_ssat (void) | |
7851 | { | |
7852 | inst.instruction |= inst.operands[0].reg << 8; | |
7853 | inst.instruction |= inst.operands[1].imm - 1; | |
7854 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 7855 | |
c19d1205 | 7856 | if (inst.operands[3].present) |
b99bd4ef | 7857 | { |
c19d1205 ZW |
7858 | constraint (inst.reloc.exp.X_op != O_constant, |
7859 | _("expression too complex")); | |
b99bd4ef | 7860 | |
c19d1205 | 7861 | if (inst.reloc.exp.X_add_number != 0) |
6189168b | 7862 | { |
c19d1205 ZW |
7863 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
7864 | inst.instruction |= 0x00200000; /* sh bit */ | |
7865 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; | |
7866 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
6189168b | 7867 | } |
c19d1205 | 7868 | inst.reloc.type = BFD_RELOC_UNUSED; |
6189168b | 7869 | } |
b99bd4ef NC |
7870 | } |
7871 | ||
0dd132b6 | 7872 | static void |
c19d1205 | 7873 | do_t_ssat16 (void) |
0dd132b6 | 7874 | { |
c19d1205 ZW |
7875 | inst.instruction |= inst.operands[0].reg << 8; |
7876 | inst.instruction |= inst.operands[1].imm - 1; | |
7877 | inst.instruction |= inst.operands[2].reg << 16; | |
7878 | } | |
0dd132b6 | 7879 | |
c19d1205 ZW |
7880 | static void |
7881 | do_t_strex (void) | |
7882 | { | |
7883 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7884 | || inst.operands[2].postind || inst.operands[2].writeback | |
7885 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
7886 | || inst.operands[2].negative, | |
01cfc07f | 7887 | BAD_ADDR_MODE); |
0dd132b6 | 7888 | |
c19d1205 ZW |
7889 | inst.instruction |= inst.operands[0].reg << 8; |
7890 | inst.instruction |= inst.operands[1].reg << 12; | |
7891 | inst.instruction |= inst.operands[2].reg << 16; | |
7892 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
7893 | } |
7894 | ||
b99bd4ef | 7895 | static void |
c19d1205 | 7896 | do_t_strexd (void) |
b99bd4ef | 7897 | { |
c19d1205 ZW |
7898 | if (!inst.operands[2].present) |
7899 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 7900 | |
c19d1205 ZW |
7901 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7902 | || inst.operands[0].reg == inst.operands[2].reg | |
7903 | || inst.operands[0].reg == inst.operands[3].reg | |
7904 | || inst.operands[1].reg == inst.operands[2].reg, | |
7905 | BAD_OVERLAP); | |
b99bd4ef | 7906 | |
c19d1205 ZW |
7907 | inst.instruction |= inst.operands[0].reg; |
7908 | inst.instruction |= inst.operands[1].reg << 12; | |
7909 | inst.instruction |= inst.operands[2].reg << 8; | |
7910 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
7911 | } |
7912 | ||
7913 | static void | |
c19d1205 | 7914 | do_t_sxtah (void) |
b99bd4ef | 7915 | { |
c19d1205 ZW |
7916 | inst.instruction |= inst.operands[0].reg << 8; |
7917 | inst.instruction |= inst.operands[1].reg << 16; | |
7918 | inst.instruction |= inst.operands[2].reg; | |
7919 | inst.instruction |= inst.operands[3].imm << 4; | |
7920 | } | |
b99bd4ef | 7921 | |
c19d1205 ZW |
7922 | static void |
7923 | do_t_sxth (void) | |
7924 | { | |
7925 | if (inst.instruction <= 0xffff && inst.size_req != 4 | |
7926 | && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
7927 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) | |
b99bd4ef | 7928 | { |
c19d1205 ZW |
7929 | inst.instruction = THUMB_OP16 (inst.instruction); |
7930 | inst.instruction |= inst.operands[0].reg; | |
7931 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 7932 | } |
c19d1205 | 7933 | else if (unified_syntax) |
b99bd4ef | 7934 | { |
c19d1205 ZW |
7935 | if (inst.instruction <= 0xffff) |
7936 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7937 | inst.instruction |= inst.operands[0].reg << 8; | |
7938 | inst.instruction |= inst.operands[1].reg; | |
7939 | inst.instruction |= inst.operands[2].imm << 4; | |
b99bd4ef | 7940 | } |
c19d1205 | 7941 | else |
b99bd4ef | 7942 | { |
c19d1205 ZW |
7943 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
7944 | _("Thumb encoding does not support rotation")); | |
7945 | constraint (1, BAD_HIREG); | |
b99bd4ef | 7946 | } |
c19d1205 | 7947 | } |
b99bd4ef | 7948 | |
c19d1205 ZW |
7949 | static void |
7950 | do_t_swi (void) | |
7951 | { | |
7952 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
7953 | } | |
b99bd4ef | 7954 | |
92e90b6e PB |
7955 | static void |
7956 | do_t_tb (void) | |
7957 | { | |
7958 | int half; | |
7959 | ||
7960 | half = (inst.instruction & 0x10) != 0; | |
dfa9f0d5 PB |
7961 | constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH); |
7962 | constraint (inst.operands[0].immisreg, | |
7963 | _("instruction requires register index")); | |
92e90b6e PB |
7964 | constraint (inst.operands[0].imm == 15, |
7965 | _("PC is not a valid index register")); | |
7966 | constraint (!half && inst.operands[0].shifted, | |
7967 | _("instruction does not allow shifted index")); | |
92e90b6e PB |
7968 | inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm; |
7969 | } | |
7970 | ||
c19d1205 ZW |
7971 | static void |
7972 | do_t_usat (void) | |
7973 | { | |
7974 | inst.instruction |= inst.operands[0].reg << 8; | |
7975 | inst.instruction |= inst.operands[1].imm; | |
7976 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 7977 | |
c19d1205 | 7978 | if (inst.operands[3].present) |
b99bd4ef | 7979 | { |
c19d1205 ZW |
7980 | constraint (inst.reloc.exp.X_op != O_constant, |
7981 | _("expression too complex")); | |
7982 | if (inst.reloc.exp.X_add_number != 0) | |
7983 | { | |
7984 | if (inst.operands[3].shift_kind == SHIFT_ASR) | |
7985 | inst.instruction |= 0x00200000; /* sh bit */ | |
b99bd4ef | 7986 | |
c19d1205 ZW |
7987 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; |
7988 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
7989 | } | |
7990 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 7991 | } |
b99bd4ef NC |
7992 | } |
7993 | ||
7994 | static void | |
c19d1205 | 7995 | do_t_usat16 (void) |
b99bd4ef | 7996 | { |
c19d1205 ZW |
7997 | inst.instruction |= inst.operands[0].reg << 8; |
7998 | inst.instruction |= inst.operands[1].imm; | |
7999 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 8000 | } |
c19d1205 ZW |
8001 | \f |
8002 | /* Overall per-instruction processing. */ | |
8003 | ||
8004 | /* We need to be able to fix up arbitrary expressions in some statements. | |
8005 | This is so that we can handle symbols that are an arbitrary distance from | |
8006 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
8007 | which returns part of an address in a form which will be valid for | |
8008 | a data instruction. We do this by pushing the expression into a symbol | |
8009 | in the expr_section, and creating a fix for that. */ | |
b99bd4ef NC |
8010 | |
8011 | static void | |
c19d1205 ZW |
8012 | fix_new_arm (fragS * frag, |
8013 | int where, | |
8014 | short int size, | |
8015 | expressionS * exp, | |
8016 | int pc_rel, | |
8017 | int reloc) | |
b99bd4ef | 8018 | { |
c19d1205 | 8019 | fixS * new_fix; |
b99bd4ef | 8020 | |
c19d1205 | 8021 | switch (exp->X_op) |
b99bd4ef | 8022 | { |
c19d1205 ZW |
8023 | case O_constant: |
8024 | case O_symbol: | |
8025 | case O_add: | |
8026 | case O_subtract: | |
8027 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
8028 | break; | |
b99bd4ef | 8029 | |
c19d1205 ZW |
8030 | default: |
8031 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
8032 | pc_rel, reloc); | |
8033 | break; | |
b99bd4ef NC |
8034 | } |
8035 | ||
c19d1205 ZW |
8036 | /* Mark whether the fix is to a THUMB instruction, or an ARM |
8037 | instruction. */ | |
adbaf948 | 8038 | new_fix->tc_fix_data = thumb_mode; |
b99bd4ef NC |
8039 | } |
8040 | ||
0110f2b8 PB |
8041 | /* Create a frg for an instruction requiring relaxation. */ |
8042 | static void | |
8043 | output_relax_insn (void) | |
8044 | { | |
8045 | char * to; | |
8046 | symbolS *sym; | |
8047 | int offset; | |
8048 | ||
6e1cb1a6 PB |
8049 | #ifdef OBJ_ELF |
8050 | /* The size of the instruction is unknown, so tie the debug info to the | |
8051 | start of the instruction. */ | |
8052 | dwarf2_emit_insn (0); | |
8053 | #endif | |
8054 | ||
0110f2b8 PB |
8055 | switch (inst.reloc.exp.X_op) |
8056 | { | |
8057 | case O_symbol: | |
8058 | sym = inst.reloc.exp.X_add_symbol; | |
8059 | offset = inst.reloc.exp.X_add_number; | |
8060 | break; | |
8061 | case O_constant: | |
8062 | sym = NULL; | |
8063 | offset = inst.reloc.exp.X_add_number; | |
8064 | break; | |
8065 | default: | |
8066 | sym = make_expr_symbol (&inst.reloc.exp); | |
8067 | offset = 0; | |
8068 | break; | |
8069 | } | |
8070 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
8071 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
8072 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
0110f2b8 PB |
8073 | } |
8074 | ||
8075 | /* Write a 32-bit thumb instruction to buf. */ | |
8076 | static void | |
8077 | put_thumb32_insn (char * buf, unsigned long insn) | |
8078 | { | |
8079 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
8080 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
8081 | } | |
8082 | ||
b99bd4ef | 8083 | static void |
c19d1205 | 8084 | output_inst (const char * str) |
b99bd4ef | 8085 | { |
c19d1205 | 8086 | char * to = NULL; |
b99bd4ef | 8087 | |
c19d1205 | 8088 | if (inst.error) |
b99bd4ef | 8089 | { |
c19d1205 | 8090 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
8091 | return; |
8092 | } | |
0110f2b8 PB |
8093 | if (inst.relax) { |
8094 | output_relax_insn(); | |
8095 | return; | |
8096 | } | |
c19d1205 ZW |
8097 | if (inst.size == 0) |
8098 | return; | |
b99bd4ef | 8099 | |
c19d1205 ZW |
8100 | to = frag_more (inst.size); |
8101 | ||
8102 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 8103 | { |
c19d1205 | 8104 | assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 8105 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 8106 | } |
c19d1205 | 8107 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 8108 | { |
c19d1205 ZW |
8109 | assert (inst.size == (2 * INSN_SIZE)); |
8110 | md_number_to_chars (to, inst.instruction, INSN_SIZE); | |
8111 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 8112 | } |
c19d1205 ZW |
8113 | else |
8114 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 8115 | |
c19d1205 ZW |
8116 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
8117 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
8118 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
8119 | inst.reloc.type); | |
b99bd4ef | 8120 | |
c19d1205 ZW |
8121 | #ifdef OBJ_ELF |
8122 | dwarf2_emit_insn (inst.size); | |
8123 | #endif | |
8124 | } | |
b99bd4ef | 8125 | |
c19d1205 ZW |
8126 | /* Tag values used in struct asm_opcode's tag field. */ |
8127 | enum opcode_tag | |
8128 | { | |
8129 | OT_unconditional, /* Instruction cannot be conditionalized. | |
8130 | The ARM condition field is still 0xE. */ | |
8131 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
8132 | and carries 0xF in its ARM condition field. */ | |
8133 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
8134 | OT_cinfix3, /* Instruction takes a conditional infix, | |
8135 | beginning at character index 3. (In | |
8136 | unified mode, it becomes a suffix.) */ | |
e3cb604e PB |
8137 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
8138 | character index 3, even in unified mode. Used for | |
8139 | legacy instructions where suffix and infix forms | |
8140 | may be ambiguous. */ | |
c19d1205 | 8141 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 8142 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
8143 | OT_odd_infix_unc, /* This is the unconditional variant of an |
8144 | instruction that takes a conditional infix | |
8145 | at an unusual position. In unified mode, | |
8146 | this variant will accept a suffix. */ | |
8147 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
8148 | are the conditional variants of instructions that | |
8149 | take conditional infixes in unusual positions. | |
8150 | The infix appears at character index | |
8151 | (tag - OT_odd_infix_0). These are not accepted | |
8152 | in unified mode. */ | |
8153 | }; | |
b99bd4ef | 8154 | |
c19d1205 ZW |
8155 | /* Subroutine of md_assemble, responsible for looking up the primary |
8156 | opcode from the mnemonic the user wrote. STR points to the | |
8157 | beginning of the mnemonic. | |
8158 | ||
8159 | This is not simply a hash table lookup, because of conditional | |
8160 | variants. Most instructions have conditional variants, which are | |
8161 | expressed with a _conditional affix_ to the mnemonic. If we were | |
8162 | to encode each conditional variant as a literal string in the opcode | |
8163 | table, it would have approximately 20,000 entries. | |
8164 | ||
8165 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
8166 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
8167 | instructions take the affix as an infix, notably the s-variants of | |
8168 | the arithmetic instructions. Of those instructions, all but six | |
8169 | have the infix appear after the third character of the mnemonic. | |
8170 | ||
8171 | Accordingly, the algorithm for looking up primary opcodes given | |
8172 | an identifier is: | |
8173 | ||
8174 | 1. Look up the identifier in the opcode table. | |
8175 | If we find a match, go to step U. | |
8176 | ||
8177 | 2. Look up the last two characters of the identifier in the | |
8178 | conditions table. If we find a match, look up the first N-2 | |
8179 | characters of the identifier in the opcode table. If we | |
8180 | find a match, go to step CE. | |
8181 | ||
8182 | 3. Look up the fourth and fifth characters of the identifier in | |
8183 | the conditions table. If we find a match, extract those | |
8184 | characters from the identifier, and look up the remaining | |
8185 | characters in the opcode table. If we find a match, go | |
8186 | to step CM. | |
8187 | ||
8188 | 4. Fail. | |
8189 | ||
8190 | U. Examine the tag field of the opcode structure, in case this is | |
8191 | one of the six instructions with its conditional infix in an | |
8192 | unusual place. If it is, the tag tells us where to find the | |
8193 | infix; look it up in the conditions table and set inst.cond | |
8194 | accordingly. Otherwise, this is an unconditional instruction. | |
8195 | Again set inst.cond accordingly. Return the opcode structure. | |
8196 | ||
8197 | CE. Examine the tag field to make sure this is an instruction that | |
8198 | should receive a conditional suffix. If it is not, fail. | |
8199 | Otherwise, set inst.cond from the suffix we already looked up, | |
8200 | and return the opcode structure. | |
8201 | ||
8202 | CM. Examine the tag field to make sure this is an instruction that | |
8203 | should receive a conditional infix after the third character. | |
8204 | If it is not, fail. Otherwise, undo the edits to the current | |
8205 | line of input and proceed as for case CE. */ | |
8206 | ||
8207 | static const struct asm_opcode * | |
8208 | opcode_lookup (char **str) | |
8209 | { | |
8210 | char *end, *base; | |
8211 | char *affix; | |
8212 | const struct asm_opcode *opcode; | |
8213 | const struct asm_cond *cond; | |
e3cb604e | 8214 | char save[2]; |
c19d1205 ZW |
8215 | |
8216 | /* Scan up to the end of the mnemonic, which must end in white space, | |
8217 | '.' (in unified mode only), or end of string. */ | |
8218 | for (base = end = *str; *end != '\0'; end++) | |
8219 | if (*end == ' ' || (unified_syntax && *end == '.')) | |
8220 | break; | |
b99bd4ef | 8221 | |
c19d1205 ZW |
8222 | if (end == base) |
8223 | return 0; | |
b99bd4ef | 8224 | |
c19d1205 ZW |
8225 | /* Handle a possible width suffix. */ |
8226 | if (end[0] == '.') | |
b99bd4ef | 8227 | { |
c19d1205 ZW |
8228 | if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0')) |
8229 | inst.size_req = 4; | |
8230 | else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0')) | |
8231 | inst.size_req = 2; | |
8232 | else | |
8233 | return 0; | |
b99bd4ef | 8234 | |
c19d1205 | 8235 | *str = end + 2; |
b99bd4ef | 8236 | } |
c19d1205 ZW |
8237 | else |
8238 | *str = end; | |
b99bd4ef | 8239 | |
c19d1205 ZW |
8240 | /* Look for unaffixed or special-case affixed mnemonic. */ |
8241 | opcode = hash_find_n (arm_ops_hsh, base, end - base); | |
8242 | if (opcode) | |
b99bd4ef | 8243 | { |
c19d1205 ZW |
8244 | /* step U */ |
8245 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 8246 | { |
c19d1205 ZW |
8247 | inst.cond = COND_ALWAYS; |
8248 | return opcode; | |
b99bd4ef | 8249 | } |
b99bd4ef | 8250 | |
c19d1205 ZW |
8251 | if (unified_syntax) |
8252 | as_warn (_("conditional infixes are deprecated in unified syntax")); | |
8253 | affix = base + (opcode->tag - OT_odd_infix_0); | |
8254 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
8255 | assert (cond); | |
b99bd4ef | 8256 | |
c19d1205 ZW |
8257 | inst.cond = cond->value; |
8258 | return opcode; | |
8259 | } | |
b99bd4ef | 8260 | |
c19d1205 ZW |
8261 | /* Cannot have a conditional suffix on a mnemonic of less than two |
8262 | characters. */ | |
8263 | if (end - base < 3) | |
8264 | return 0; | |
b99bd4ef | 8265 | |
c19d1205 ZW |
8266 | /* Look for suffixed mnemonic. */ |
8267 | affix = end - 2; | |
8268 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
8269 | opcode = hash_find_n (arm_ops_hsh, base, affix - base); | |
8270 | if (opcode && cond) | |
8271 | { | |
8272 | /* step CE */ | |
8273 | switch (opcode->tag) | |
8274 | { | |
e3cb604e PB |
8275 | case OT_cinfix3_legacy: |
8276 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
8277 | break; | |
8278 | ||
c19d1205 ZW |
8279 | case OT_cinfix3: |
8280 | case OT_odd_infix_unc: | |
8281 | if (!unified_syntax) | |
e3cb604e | 8282 | return 0; |
c19d1205 ZW |
8283 | /* else fall through */ |
8284 | ||
8285 | case OT_csuffix: | |
8286 | case OT_csuf_or_in3: | |
8287 | inst.cond = cond->value; | |
8288 | return opcode; | |
8289 | ||
8290 | case OT_unconditional: | |
8291 | case OT_unconditionalF: | |
dfa9f0d5 PB |
8292 | if (thumb_mode) |
8293 | { | |
8294 | inst.cond = cond->value; | |
8295 | } | |
8296 | else | |
8297 | { | |
8298 | /* delayed diagnostic */ | |
8299 | inst.error = BAD_COND; | |
8300 | inst.cond = COND_ALWAYS; | |
8301 | } | |
c19d1205 | 8302 | return opcode; |
b99bd4ef | 8303 | |
c19d1205 ZW |
8304 | default: |
8305 | return 0; | |
8306 | } | |
8307 | } | |
b99bd4ef | 8308 | |
c19d1205 ZW |
8309 | /* Cannot have a usual-position infix on a mnemonic of less than |
8310 | six characters (five would be a suffix). */ | |
8311 | if (end - base < 6) | |
8312 | return 0; | |
b99bd4ef | 8313 | |
c19d1205 ZW |
8314 | /* Look for infixed mnemonic in the usual position. */ |
8315 | affix = base + 3; | |
8316 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
e3cb604e PB |
8317 | if (!cond) |
8318 | return 0; | |
8319 | ||
8320 | memcpy (save, affix, 2); | |
8321 | memmove (affix, affix + 2, (end - affix) - 2); | |
8322 | opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2); | |
8323 | memmove (affix + 2, affix, (end - affix) - 2); | |
8324 | memcpy (affix, save, 2); | |
8325 | ||
8326 | if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3 | |
8327 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 8328 | { |
c19d1205 | 8329 | /* step CM */ |
e3cb604e | 8330 | if (unified_syntax && opcode->tag == OT_cinfix3) |
c19d1205 ZW |
8331 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
8332 | ||
8333 | inst.cond = cond->value; | |
8334 | return opcode; | |
b99bd4ef NC |
8335 | } |
8336 | ||
c19d1205 | 8337 | return 0; |
b99bd4ef NC |
8338 | } |
8339 | ||
c19d1205 ZW |
8340 | void |
8341 | md_assemble (char *str) | |
b99bd4ef | 8342 | { |
c19d1205 ZW |
8343 | char *p = str; |
8344 | const struct asm_opcode * opcode; | |
b99bd4ef | 8345 | |
c19d1205 ZW |
8346 | /* Align the previous label if needed. */ |
8347 | if (last_label_seen != NULL) | |
b99bd4ef | 8348 | { |
c19d1205 ZW |
8349 | symbol_set_frag (last_label_seen, frag_now); |
8350 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
8351 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
8352 | } |
8353 | ||
c19d1205 ZW |
8354 | memset (&inst, '\0', sizeof (inst)); |
8355 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 8356 | |
c19d1205 ZW |
8357 | opcode = opcode_lookup (&p); |
8358 | if (!opcode) | |
b99bd4ef | 8359 | { |
c19d1205 ZW |
8360 | /* It wasn't an instruction, but it might be a register alias of |
8361 | the form alias .req reg. */ | |
8362 | if (!create_register_alias (str, p)) | |
8363 | as_bad (_("bad instruction `%s'"), str); | |
b99bd4ef | 8364 | |
b99bd4ef NC |
8365 | return; |
8366 | } | |
8367 | ||
c19d1205 | 8368 | if (thumb_mode) |
b99bd4ef | 8369 | { |
e74cfd16 | 8370 | arm_feature_set variant; |
8f06b2d8 PB |
8371 | |
8372 | variant = cpu_variant; | |
8373 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
8374 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
8375 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 8376 | /* Check that this instruction is supported for this CPU. */ |
62b3e311 PB |
8377 | if (!opcode->tvariant |
8378 | || (thumb_mode == 1 | |
8379 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant))) | |
b99bd4ef | 8380 | { |
c19d1205 | 8381 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
8382 | return; |
8383 | } | |
c19d1205 ZW |
8384 | if (inst.cond != COND_ALWAYS && !unified_syntax |
8385 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 8386 | { |
c19d1205 | 8387 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
8388 | return; |
8389 | } | |
8390 | ||
e27ec89e PB |
8391 | /* Check conditional suffixes. */ |
8392 | if (current_it_mask) | |
8393 | { | |
8394 | int cond; | |
8395 | cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1; | |
dfa9f0d5 PB |
8396 | current_it_mask <<= 1; |
8397 | current_it_mask &= 0x1f; | |
8398 | /* The BKPT instruction is unconditional even in an IT block. */ | |
8399 | if (!inst.error | |
8400 | && cond != inst.cond && opcode->tencode != do_t_bkpt) | |
e27ec89e PB |
8401 | { |
8402 | as_bad (_("incorrect condition in IT block")); | |
8403 | return; | |
8404 | } | |
e27ec89e PB |
8405 | } |
8406 | else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch) | |
8407 | { | |
8408 | as_bad (_("thumb conditional instrunction not in IT block")); | |
8409 | return; | |
8410 | } | |
8411 | ||
c19d1205 ZW |
8412 | mapping_state (MAP_THUMB); |
8413 | inst.instruction = opcode->tvalue; | |
8414 | ||
8415 | if (!parse_operands (p, opcode->operands)) | |
8416 | opcode->tencode (); | |
8417 | ||
e27ec89e PB |
8418 | /* Clear current_it_mask at the end of an IT block. */ |
8419 | if (current_it_mask == 0x10) | |
8420 | current_it_mask = 0; | |
8421 | ||
0110f2b8 | 8422 | if (!(inst.error || inst.relax)) |
b99bd4ef | 8423 | { |
c19d1205 ZW |
8424 | assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
8425 | inst.size = (inst.instruction > 0xffff ? 4 : 2); | |
8426 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 8427 | { |
c19d1205 | 8428 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
8429 | return; |
8430 | } | |
8431 | } | |
e74cfd16 PB |
8432 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
8433 | *opcode->tvariant); | |
ee065d83 | 8434 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
e74cfd16 | 8435 | set those bits when Thumb-2 32-bit instuctions are seen. ie. |
ee065d83 PB |
8436 | anything other than bl/blx. |
8437 | This is overly pessimistic for relaxable instructions. */ | |
8438 | if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) | |
8439 | || inst.relax) | |
e74cfd16 PB |
8440 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
8441 | arm_ext_v6t2); | |
c19d1205 ZW |
8442 | } |
8443 | else | |
8444 | { | |
8445 | /* Check that this instruction is supported for this CPU. */ | |
62b3e311 PB |
8446 | if (!opcode->avariant || |
8447 | !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)) | |
b99bd4ef | 8448 | { |
c19d1205 ZW |
8449 | as_bad (_("selected processor does not support `%s'"), str); |
8450 | return; | |
b99bd4ef | 8451 | } |
c19d1205 | 8452 | if (inst.size_req) |
b99bd4ef | 8453 | { |
c19d1205 ZW |
8454 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
8455 | return; | |
b99bd4ef NC |
8456 | } |
8457 | ||
c19d1205 ZW |
8458 | mapping_state (MAP_ARM); |
8459 | inst.instruction = opcode->avalue; | |
8460 | if (opcode->tag == OT_unconditionalF) | |
8461 | inst.instruction |= 0xF << 28; | |
8462 | else | |
8463 | inst.instruction |= inst.cond << 28; | |
8464 | inst.size = INSN_SIZE; | |
8465 | if (!parse_operands (p, opcode->operands)) | |
8466 | opcode->aencode (); | |
ee065d83 PB |
8467 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
8468 | on a hypothetical non-thumb v5 core. */ | |
e74cfd16 PB |
8469 | if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t) |
8470 | || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5)) | |
8471 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); | |
ee065d83 | 8472 | else |
e74cfd16 PB |
8473 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
8474 | *opcode->avariant); | |
b99bd4ef | 8475 | } |
c19d1205 ZW |
8476 | output_inst (str); |
8477 | } | |
b99bd4ef | 8478 | |
c19d1205 ZW |
8479 | /* Various frobbings of labels and their addresses. */ |
8480 | ||
8481 | void | |
8482 | arm_start_line_hook (void) | |
8483 | { | |
8484 | last_label_seen = NULL; | |
b99bd4ef NC |
8485 | } |
8486 | ||
c19d1205 ZW |
8487 | void |
8488 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 8489 | { |
c19d1205 | 8490 | last_label_seen = sym; |
b99bd4ef | 8491 | |
c19d1205 | 8492 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 8493 | |
c19d1205 ZW |
8494 | #if defined OBJ_COFF || defined OBJ_ELF |
8495 | ARM_SET_INTERWORK (sym, support_interwork); | |
8496 | #endif | |
b99bd4ef | 8497 | |
c19d1205 ZW |
8498 | /* Note - do not allow local symbols (.Lxxx) to be labeled |
8499 | as Thumb functions. This is because these labels, whilst | |
8500 | they exist inside Thumb code, are not the entry points for | |
8501 | possible ARM->Thumb calls. Also, these labels can be used | |
8502 | as part of a computed goto or switch statement. eg gcc | |
8503 | can generate code that looks like this: | |
b99bd4ef | 8504 | |
c19d1205 ZW |
8505 | ldr r2, [pc, .Laaa] |
8506 | lsl r3, r3, #2 | |
8507 | ldr r2, [r3, r2] | |
8508 | mov pc, r2 | |
b99bd4ef | 8509 | |
c19d1205 ZW |
8510 | .Lbbb: .word .Lxxx |
8511 | .Lccc: .word .Lyyy | |
8512 | ..etc... | |
8513 | .Laaa: .word Lbbb | |
b99bd4ef | 8514 | |
c19d1205 ZW |
8515 | The first instruction loads the address of the jump table. |
8516 | The second instruction converts a table index into a byte offset. | |
8517 | The third instruction gets the jump address out of the table. | |
8518 | The fourth instruction performs the jump. | |
b99bd4ef | 8519 | |
c19d1205 ZW |
8520 | If the address stored at .Laaa is that of a symbol which has the |
8521 | Thumb_Func bit set, then the linker will arrange for this address | |
8522 | to have the bottom bit set, which in turn would mean that the | |
8523 | address computation performed by the third instruction would end | |
8524 | up with the bottom bit set. Since the ARM is capable of unaligned | |
8525 | word loads, the instruction would then load the incorrect address | |
8526 | out of the jump table, and chaos would ensue. */ | |
8527 | if (label_is_thumb_function_name | |
8528 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
8529 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 8530 | { |
c19d1205 ZW |
8531 | /* When the address of a Thumb function is taken the bottom |
8532 | bit of that address should be set. This will allow | |
8533 | interworking between Arm and Thumb functions to work | |
8534 | correctly. */ | |
b99bd4ef | 8535 | |
c19d1205 | 8536 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 8537 | |
c19d1205 | 8538 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 8539 | } |
07a53e5c RH |
8540 | |
8541 | #ifdef OBJ_ELF | |
8542 | dwarf2_emit_label (sym); | |
8543 | #endif | |
b99bd4ef NC |
8544 | } |
8545 | ||
c19d1205 ZW |
8546 | int |
8547 | arm_data_in_code (void) | |
b99bd4ef | 8548 | { |
c19d1205 | 8549 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 8550 | { |
c19d1205 ZW |
8551 | *input_line_pointer = '/'; |
8552 | input_line_pointer += 5; | |
8553 | *input_line_pointer = 0; | |
8554 | return 1; | |
b99bd4ef NC |
8555 | } |
8556 | ||
c19d1205 | 8557 | return 0; |
b99bd4ef NC |
8558 | } |
8559 | ||
c19d1205 ZW |
8560 | char * |
8561 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 8562 | { |
c19d1205 | 8563 | int len; |
b99bd4ef | 8564 | |
c19d1205 ZW |
8565 | if (thumb_mode && (len = strlen (name)) > 5 |
8566 | && streq (name + len - 5, "/data")) | |
8567 | *(name + len - 5) = 0; | |
b99bd4ef | 8568 | |
c19d1205 | 8569 | return name; |
b99bd4ef | 8570 | } |
c19d1205 ZW |
8571 | \f |
8572 | /* Table of all register names defined by default. The user can | |
8573 | define additional names with .req. Note that all register names | |
8574 | should appear in both upper and lowercase variants. Some registers | |
8575 | also have mixed-case names. */ | |
b99bd4ef | 8576 | |
c19d1205 ZW |
8577 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE } |
8578 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) | |
8579 | #define REGSET(p,t) \ | |
8580 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
8581 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
8582 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
8583 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
7ed4c4c5 | 8584 | |
c19d1205 | 8585 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 8586 | { |
c19d1205 ZW |
8587 | /* ARM integer registers. */ |
8588 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 8589 | |
c19d1205 ZW |
8590 | /* ATPCS synonyms. */ |
8591 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
8592 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
8593 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 8594 | |
c19d1205 ZW |
8595 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
8596 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
8597 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 8598 | |
c19d1205 ZW |
8599 | /* Well-known aliases. */ |
8600 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
8601 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
8602 | ||
8603 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
8604 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
8605 | ||
8606 | /* Coprocessor numbers. */ | |
8607 | REGSET(p, CP), REGSET(P, CP), | |
8608 | ||
8609 | /* Coprocessor register numbers. The "cr" variants are for backward | |
8610 | compatibility. */ | |
8611 | REGSET(c, CN), REGSET(C, CN), | |
8612 | REGSET(cr, CN), REGSET(CR, CN), | |
8613 | ||
8614 | /* FPA registers. */ | |
8615 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
8616 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
8617 | ||
8618 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
8619 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
8620 | ||
8621 | /* VFP SP registers. */ | |
8622 | REGSET(s,VFS), | |
8623 | REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS), | |
8624 | REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS), | |
8625 | REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS), | |
8626 | REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS), | |
8627 | ||
8628 | REGSET(S,VFS), | |
8629 | REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS), | |
8630 | REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS), | |
8631 | REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS), | |
8632 | REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS), | |
8633 | ||
8634 | /* VFP DP Registers. */ | |
8635 | REGSET(d,VFD), REGSET(D,VFS), | |
8636 | ||
8637 | /* VFP control registers. */ | |
8638 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
8639 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
8640 | ||
8641 | /* Maverick DSP coprocessor registers. */ | |
8642 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
8643 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
8644 | ||
8645 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
8646 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
8647 | REGDEF(dspsc,0,DSPSC), | |
8648 | ||
8649 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
8650 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
8651 | REGDEF(DSPSC,0,DSPSC), | |
8652 | ||
8653 | /* iWMMXt data registers - p0, c0-15. */ | |
8654 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
8655 | ||
8656 | /* iWMMXt control registers - p1, c0-3. */ | |
8657 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
8658 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
8659 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
8660 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
8661 | ||
8662 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
8663 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
8664 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
8665 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
8666 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
8667 | ||
8668 | /* XScale accumulator registers. */ | |
8669 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
8670 | }; | |
8671 | #undef REGDEF | |
8672 | #undef REGNUM | |
8673 | #undef REGSET | |
7ed4c4c5 | 8674 | |
c19d1205 ZW |
8675 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
8676 | within psr_required_here. */ | |
8677 | static const struct asm_psr psrs[] = | |
8678 | { | |
8679 | /* Backward compatibility notation. Note that "all" is no longer | |
8680 | truly all possible PSR bits. */ | |
8681 | {"all", PSR_c | PSR_f}, | |
8682 | {"flg", PSR_f}, | |
8683 | {"ctl", PSR_c}, | |
8684 | ||
8685 | /* Individual flags. */ | |
8686 | {"f", PSR_f}, | |
8687 | {"c", PSR_c}, | |
8688 | {"x", PSR_x}, | |
8689 | {"s", PSR_s}, | |
8690 | /* Combinations of flags. */ | |
8691 | {"fs", PSR_f | PSR_s}, | |
8692 | {"fx", PSR_f | PSR_x}, | |
8693 | {"fc", PSR_f | PSR_c}, | |
8694 | {"sf", PSR_s | PSR_f}, | |
8695 | {"sx", PSR_s | PSR_x}, | |
8696 | {"sc", PSR_s | PSR_c}, | |
8697 | {"xf", PSR_x | PSR_f}, | |
8698 | {"xs", PSR_x | PSR_s}, | |
8699 | {"xc", PSR_x | PSR_c}, | |
8700 | {"cf", PSR_c | PSR_f}, | |
8701 | {"cs", PSR_c | PSR_s}, | |
8702 | {"cx", PSR_c | PSR_x}, | |
8703 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
8704 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
8705 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
8706 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
8707 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
8708 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
8709 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
8710 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
8711 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
8712 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
8713 | {"scf", PSR_s | PSR_c | PSR_f}, | |
8714 | {"scx", PSR_s | PSR_c | PSR_x}, | |
8715 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
8716 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
8717 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
8718 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
8719 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
8720 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
8721 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
8722 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
8723 | {"csf", PSR_c | PSR_s | PSR_f}, | |
8724 | {"csx", PSR_c | PSR_s | PSR_x}, | |
8725 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
8726 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
8727 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
8728 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
8729 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
8730 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
8731 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
8732 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
8733 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
8734 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
8735 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
8736 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
8737 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
8738 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
8739 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
8740 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
8741 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
8742 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
8743 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
8744 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
8745 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
8746 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
8747 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
8748 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
8749 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
8750 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
8751 | }; | |
8752 | ||
62b3e311 PB |
8753 | /* Table of V7M psr names. */ |
8754 | static const struct asm_psr v7m_psrs[] = | |
8755 | { | |
8756 | {"apsr", 0 }, | |
8757 | {"iapsr", 1 }, | |
8758 | {"eapsr", 2 }, | |
8759 | {"psr", 3 }, | |
8760 | {"ipsr", 5 }, | |
8761 | {"epsr", 6 }, | |
8762 | {"iepsr", 7 }, | |
8763 | {"msp", 8 }, | |
8764 | {"psp", 9 }, | |
8765 | {"primask", 16}, | |
8766 | {"basepri", 17}, | |
8767 | {"basepri_max", 18}, | |
8768 | {"faultmask", 19}, | |
8769 | {"control", 20} | |
8770 | }; | |
8771 | ||
c19d1205 ZW |
8772 | /* Table of all shift-in-operand names. */ |
8773 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 8774 | { |
c19d1205 ZW |
8775 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
8776 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
8777 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
8778 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
8779 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
8780 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
8781 | }; | |
b99bd4ef | 8782 | |
c19d1205 ZW |
8783 | /* Table of all explicit relocation names. */ |
8784 | #ifdef OBJ_ELF | |
8785 | static struct reloc_entry reloc_names[] = | |
8786 | { | |
8787 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
8788 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
8789 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
8790 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
8791 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
8792 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
8793 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
8794 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
8795 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
8796 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
8797 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
8798 | }; | |
8799 | #endif | |
b99bd4ef | 8800 | |
c19d1205 ZW |
8801 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
8802 | static const struct asm_cond conds[] = | |
8803 | { | |
8804 | {"eq", 0x0}, | |
8805 | {"ne", 0x1}, | |
8806 | {"cs", 0x2}, {"hs", 0x2}, | |
8807 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
8808 | {"mi", 0x4}, | |
8809 | {"pl", 0x5}, | |
8810 | {"vs", 0x6}, | |
8811 | {"vc", 0x7}, | |
8812 | {"hi", 0x8}, | |
8813 | {"ls", 0x9}, | |
8814 | {"ge", 0xa}, | |
8815 | {"lt", 0xb}, | |
8816 | {"gt", 0xc}, | |
8817 | {"le", 0xd}, | |
8818 | {"al", 0xe} | |
8819 | }; | |
bfae80f2 | 8820 | |
62b3e311 PB |
8821 | static struct asm_barrier_opt barrier_opt_names[] = |
8822 | { | |
8823 | { "sy", 0xf }, | |
8824 | { "un", 0x7 }, | |
8825 | { "st", 0xe }, | |
8826 | { "unst", 0x6 } | |
8827 | }; | |
8828 | ||
c19d1205 ZW |
8829 | /* Table of ARM-format instructions. */ |
8830 | ||
8831 | /* Macros for gluing together operand strings. N.B. In all cases | |
8832 | other than OPS0, the trailing OP_stop comes from default | |
8833 | zero-initialization of the unspecified elements of the array. */ | |
8834 | #define OPS0() { OP_stop, } | |
8835 | #define OPS1(a) { OP_##a, } | |
8836 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
8837 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
8838 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
8839 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
8840 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
8841 | ||
8842 | /* These macros abstract out the exact format of the mnemonic table and | |
8843 | save some repeated characters. */ | |
8844 | ||
8845 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
8846 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
8847 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 8848 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8849 | |
8850 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
8851 | a T_MNEM_xyz enumerator. */ | |
8852 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
8853 | TxCE(mnem, aop, 0x##top, nops, ops, ae, te) | |
8854 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ | |
8855 | TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
8856 | ||
8857 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
8858 | infix after the third character. */ | |
8859 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
8860 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 8861 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8862 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
8863 | TxC3(mnem, aop, 0x##top, nops, ops, ae, te) | |
8864 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ | |
8865 | TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
8866 | ||
8867 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
8868 | appear in the condition table. */ | |
8869 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
8870 | { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
1887dd22 | 8871 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8872 | |
8873 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
8874 | TxCM_(m1, , m2, op, top, nops, ops, ae, te), \ | |
8875 | TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \ | |
8876 | TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \ | |
8877 | TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \ | |
8878 | TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \ | |
8879 | TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \ | |
8880 | TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \ | |
8881 | TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \ | |
8882 | TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \ | |
8883 | TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \ | |
8884 | TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \ | |
8885 | TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \ | |
8886 | TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \ | |
8887 | TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \ | |
8888 | TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \ | |
8889 | TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \ | |
8890 | TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \ | |
8891 | TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \ | |
8892 | TxCM_(m1, al, m2, op, top, nops, ops, ae, te) | |
8893 | ||
8894 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
8895 | TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te) | |
8896 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
8897 | TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
8898 | ||
8899 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
dfa9f0d5 PB |
8900 | field is still 0xE. Many of the Thumb variants can be executed |
8901 | conditionally, so this is checked separately. */ | |
c19d1205 ZW |
8902 | #define TUE(mnem, op, top, nops, ops, ae, te) \ |
8903 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 8904 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8905 | |
8906 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
8907 | condition code field. */ | |
8908 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
8909 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 8910 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8911 | |
8912 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
8913 | #define CE(mnem, op, nops, ops, ae) \ |
8914 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8915 | ||
8916 | #define C3(mnem, op, nops, ops, ae) \ | |
8917 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8918 | ||
e3cb604e PB |
8919 | /* Legacy mnemonics that always have conditional infix after the third |
8920 | character. */ | |
8921 | #define CL(mnem, op, nops, ops, ae) \ | |
8922 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
8923 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8924 | ||
8f06b2d8 PB |
8925 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
8926 | #define cCE(mnem, op, nops, ops, ae) \ | |
8927 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8928 | ||
e3cb604e PB |
8929 | /* Legacy coprocessor instructions where conditional infix and conditional |
8930 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
8931 | not just the potentially ambiguous ones. */ | |
8932 | #define cCL(mnem, op, nops, ops, ae) \ | |
8933 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
8934 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8935 | ||
8936 | /* Coprocessor, takes either a suffix or a position-3 infix | |
8937 | (for an FPA corner case). */ | |
8938 | #define C3E(mnem, op, nops, ops, ae) \ | |
8939 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
8940 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 8941 | |
6a86118a NC |
8942 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
8943 | { #m1 #m2 #m3, OPS##nops ops, \ | |
8944 | sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
8945 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8946 | ||
8947 | #define CM(m1, m2, op, nops, ops, ae) \ | |
8948 | xCM_(m1, , m2, op, nops, ops, ae), \ | |
8949 | xCM_(m1, eq, m2, op, nops, ops, ae), \ | |
8950 | xCM_(m1, ne, m2, op, nops, ops, ae), \ | |
8951 | xCM_(m1, cs, m2, op, nops, ops, ae), \ | |
8952 | xCM_(m1, hs, m2, op, nops, ops, ae), \ | |
8953 | xCM_(m1, cc, m2, op, nops, ops, ae), \ | |
8954 | xCM_(m1, ul, m2, op, nops, ops, ae), \ | |
8955 | xCM_(m1, lo, m2, op, nops, ops, ae), \ | |
8956 | xCM_(m1, mi, m2, op, nops, ops, ae), \ | |
8957 | xCM_(m1, pl, m2, op, nops, ops, ae), \ | |
8958 | xCM_(m1, vs, m2, op, nops, ops, ae), \ | |
8959 | xCM_(m1, vc, m2, op, nops, ops, ae), \ | |
8960 | xCM_(m1, hi, m2, op, nops, ops, ae), \ | |
8961 | xCM_(m1, ls, m2, op, nops, ops, ae), \ | |
8962 | xCM_(m1, ge, m2, op, nops, ops, ae), \ | |
8963 | xCM_(m1, lt, m2, op, nops, ops, ae), \ | |
8964 | xCM_(m1, gt, m2, op, nops, ops, ae), \ | |
8965 | xCM_(m1, le, m2, op, nops, ops, ae), \ | |
8966 | xCM_(m1, al, m2, op, nops, ops, ae) | |
8967 | ||
8968 | #define UE(mnem, op, nops, ops, ae) \ | |
8969 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
8970 | ||
8971 | #define UF(mnem, op, nops, ops, ae) \ | |
8972 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
8973 | ||
c19d1205 ZW |
8974 | #define do_0 0 |
8975 | ||
8976 | /* Thumb-only, unconditional. */ | |
8977 | #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te) | |
8978 | ||
c19d1205 | 8979 | static const struct asm_opcode insns[] = |
bfae80f2 | 8980 | { |
e74cfd16 PB |
8981 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
8982 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
8983 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
8984 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
8985 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
8986 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
8987 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
8988 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
8989 | tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub), | |
8990 | tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub), | |
8991 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
8992 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
8993 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
8994 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
8995 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
8996 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
8997 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
8998 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
8999 | ||
9000 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
9001 | for setting PSR flag bits. They are obsolete in V6 and do not | |
9002 | have Thumb equivalents. */ | |
9003 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
9004 | tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
e3cb604e | 9005 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
9006 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
9007 | tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
e3cb604e | 9008 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
9009 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
9010 | tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
e3cb604e | 9011 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
9012 | |
9013 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
9014 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
9015 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
9016 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
9017 | ||
9018 | tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst), | |
9019 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst), | |
9020 | tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst), | |
9021 | tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst), | |
9022 | ||
f5208ef2 | 9023 | tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
9024 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
9025 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
f5208ef2 | 9026 | tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
c19d1205 ZW |
9027 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
9028 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
9029 | ||
9030 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
c16d2bf0 | 9031 | TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi), |
0110f2b8 | 9032 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 9033 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 9034 | |
c19d1205 | 9035 | /* Pseudo ops. */ |
e9f89963 | 9036 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
9037 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
9038 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
9039 | |
9040 | /* Thumb-compatibility pseudo ops. */ | |
9041 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
9042 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
9043 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
9044 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
9045 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 9046 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
9047 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
9048 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
9049 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
9050 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
9051 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
9052 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
9053 | ||
9054 | #undef THUMB_VARIANT | |
e74cfd16 | 9055 | #define THUMB_VARIANT &arm_ext_v6 |
2fc8bdac | 9056 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
9057 | |
9058 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
9059 | #undef THUMB_VARIANT | |
e74cfd16 | 9060 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9061 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
9062 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
9063 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
9064 | TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
e3cb604e | 9065 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
9066 | |
9067 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
3e94bf1a | 9068 | TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 9069 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), |
3e94bf1a | 9070 | TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt), |
c19d1205 | 9071 | |
9c3c69f2 PB |
9072 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
9073 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 9074 | |
9c3c69f2 PB |
9075 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
9076 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
9077 | |
9078 | /* V1 instructions with no Thumb analogue at all. */ | |
9079 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
9080 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
9081 | ||
9082 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
9083 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
9084 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
9085 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
9086 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
9087 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
9088 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
9089 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
9090 | ||
9091 | #undef ARM_VARIANT | |
e74cfd16 | 9092 | #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */ |
c19d1205 | 9093 | #undef THUMB_VARIANT |
e74cfd16 | 9094 | #define THUMB_VARIANT &arm_ext_v4t |
c19d1205 ZW |
9095 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
9096 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
9097 | ||
9098 | #undef THUMB_VARIANT | |
e74cfd16 | 9099 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9100 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
9101 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
9102 | ||
9103 | /* Generic coprocessor instructions. */ | |
9104 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
9105 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9106 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9107 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9108 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9109 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
9110 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
9111 | ||
9112 | #undef ARM_VARIANT | |
e74cfd16 | 9113 | #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */ |
c19d1205 ZW |
9114 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
9115 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
9116 | ||
9117 | #undef ARM_VARIANT | |
e74cfd16 | 9118 | #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */ |
c19d1205 ZW |
9119 | TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs), |
9120 | TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr), | |
9121 | ||
9122 | #undef ARM_VARIANT | |
e74cfd16 | 9123 | #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */ |
c19d1205 ZW |
9124 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
9125 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
9126 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
9127 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
9128 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
9129 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
9130 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
9131 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
9132 | ||
9133 | #undef ARM_VARIANT | |
e74cfd16 | 9134 | #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */ |
c19d1205 | 9135 | #undef THUMB_VARIANT |
e74cfd16 | 9136 | #define THUMB_VARIANT &arm_ext_v4t |
c19d1205 ZW |
9137 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst), |
9138 | tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst), | |
9139 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst), | |
9140 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst), | |
9141 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst), | |
9142 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst), | |
9143 | ||
9144 | #undef ARM_VARIANT | |
e74cfd16 | 9145 | #define ARM_VARIANT &arm_ext_v4t_5 |
c19d1205 ZW |
9146 | /* ARM Architecture 4T. */ |
9147 | /* Note: bx (and blx) are required on V5, even if the processor does | |
9148 | not support Thumb. */ | |
9149 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
9150 | ||
9151 | #undef ARM_VARIANT | |
e74cfd16 | 9152 | #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */ |
c19d1205 | 9153 | #undef THUMB_VARIANT |
e74cfd16 | 9154 | #define THUMB_VARIANT &arm_ext_v5t |
c19d1205 ZW |
9155 | /* Note: blx has 2 variants; the .value coded here is for |
9156 | BLX(2). Only this variant has conditional execution. */ | |
9157 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
9158 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
9159 | ||
9160 | #undef THUMB_VARIANT | |
e74cfd16 | 9161 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9162 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
9163 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9164 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9165 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9166 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
9167 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
9168 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
9169 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
9170 | ||
9171 | #undef ARM_VARIANT | |
e74cfd16 | 9172 | #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */ |
c19d1205 ZW |
9173 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
9174 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
9175 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
9176 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
9177 | ||
9178 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
9179 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
9180 | ||
9181 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
9182 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
9183 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
9184 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
9185 | ||
9186 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9187 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9188 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9189 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9190 | ||
9191 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9192 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9193 | ||
9194 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
9195 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
9196 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
9197 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
9198 | ||
9199 | #undef ARM_VARIANT | |
e74cfd16 | 9200 | #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */ |
c19d1205 ZW |
9201 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
9202 | TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd), | |
9203 | TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd), | |
9204 | ||
9205 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
9206 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
9207 | ||
9208 | #undef ARM_VARIANT | |
e74cfd16 | 9209 | #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */ |
c19d1205 ZW |
9210 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
9211 | ||
9212 | #undef ARM_VARIANT | |
e74cfd16 | 9213 | #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */ |
c19d1205 | 9214 | #undef THUMB_VARIANT |
e74cfd16 | 9215 | #define THUMB_VARIANT &arm_ext_v6 |
c19d1205 ZW |
9216 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
9217 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
9218 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
9219 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
9220 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
9221 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
9222 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
9223 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
9224 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
9225 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
9226 | ||
9227 | #undef THUMB_VARIANT | |
e74cfd16 | 9228 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9229 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), |
9230 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
9231 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
62b3e311 PB |
9232 | |
9233 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
9234 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
9235 | ||
9236 | /* ARM V6 not included in V7M (eg. integer SIMD). */ | |
9237 | #undef THUMB_VARIANT | |
9238 | #define THUMB_VARIANT &arm_ext_v6_notm | |
dfa9f0d5 | 9239 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps), |
c19d1205 ZW |
9240 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), |
9241 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
9242 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9243 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9244 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9245 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9246 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9247 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9248 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9249 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9250 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9251 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9252 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9253 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9254 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9255 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9256 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9257 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9258 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9259 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9260 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9261 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9262 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9263 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9264 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9265 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9266 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9267 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9268 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9269 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9270 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9271 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9272 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9273 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9274 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9275 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9276 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9277 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9278 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
9279 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
9280 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
9281 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
9282 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
9283 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
9284 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
9285 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
9286 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9287 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9288 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9289 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
9290 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9291 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9292 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9293 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 9294 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
9295 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
9296 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9297 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9298 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9299 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9300 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9301 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9302 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9303 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9304 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9305 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9306 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9307 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9308 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9309 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9310 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9311 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9312 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9313 | TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs), | |
9314 | UF(srsib, 9cd0500, 1, (I31w), srs), | |
9315 | UF(srsda, 84d0500, 1, (I31w), srs), | |
9316 | TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs), | |
c19d1205 ZW |
9317 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), |
9318 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), | |
9319 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
9320 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9321 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
c19d1205 ZW |
9322 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), |
9323 | ||
9324 | #undef ARM_VARIANT | |
e74cfd16 | 9325 | #define ARM_VARIANT &arm_ext_v6k |
c19d1205 | 9326 | #undef THUMB_VARIANT |
e74cfd16 | 9327 | #define THUMB_VARIANT &arm_ext_v6k |
c19d1205 ZW |
9328 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
9329 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
9330 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
9331 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
9332 | ||
ebdca51a PB |
9333 | #undef THUMB_VARIANT |
9334 | #define THUMB_VARIANT &arm_ext_v6_notm | |
9335 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), | |
9336 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
9337 | ||
c19d1205 | 9338 | #undef THUMB_VARIANT |
e74cfd16 | 9339 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9340 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
9341 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
c19d1205 ZW |
9342 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), |
9343 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
c19d1205 ZW |
9344 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), |
9345 | ||
9346 | #undef ARM_VARIANT | |
e74cfd16 | 9347 | #define ARM_VARIANT &arm_ext_v6z |
3eb17e6b | 9348 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 ZW |
9349 | |
9350 | #undef ARM_VARIANT | |
e74cfd16 | 9351 | #define ARM_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9352 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
9353 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
9354 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
9355 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
9356 | ||
9357 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
9358 | TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16), | |
9359 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16), | |
9360 | TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), | |
9361 | ||
9362 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9363 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9364 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9365 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9366 | ||
9367 | UT(cbnz, b900, 2, (RR, EXP), t_czb), | |
9368 | UT(cbz, b100, 2, (RR, EXP), t_czb), | |
9369 | /* ARM does not really have an IT instruction. */ | |
9370 | TUE(it, 0, bf08, 1, (COND), it, t_it), | |
9371 | TUE(itt, 0, bf0c, 1, (COND), it, t_it), | |
9372 | TUE(ite, 0, bf04, 1, (COND), it, t_it), | |
9373 | TUE(ittt, 0, bf0e, 1, (COND), it, t_it), | |
9374 | TUE(itet, 0, bf06, 1, (COND), it, t_it), | |
9375 | TUE(itte, 0, bf0a, 1, (COND), it, t_it), | |
9376 | TUE(itee, 0, bf02, 1, (COND), it, t_it), | |
9377 | TUE(itttt, 0, bf0f, 1, (COND), it, t_it), | |
9378 | TUE(itett, 0, bf07, 1, (COND), it, t_it), | |
9379 | TUE(ittet, 0, bf0b, 1, (COND), it, t_it), | |
9380 | TUE(iteet, 0, bf03, 1, (COND), it, t_it), | |
9381 | TUE(ittte, 0, bf0d, 1, (COND), it, t_it), | |
9382 | TUE(itete, 0, bf05, 1, (COND), it, t_it), | |
9383 | TUE(ittee, 0, bf09, 1, (COND), it, t_it), | |
9384 | TUE(iteee, 0, bf01, 1, (COND), it, t_it), | |
9385 | ||
92e90b6e PB |
9386 | /* Thumb2 only instructions. */ |
9387 | #undef ARM_VARIANT | |
e74cfd16 | 9388 | #define ARM_VARIANT NULL |
92e90b6e PB |
9389 | |
9390 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
9391 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
9392 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), | |
9393 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
9394 | ||
62b3e311 PB |
9395 | /* Thumb-2 hardware division instructions (R and M profiles only). */ |
9396 | #undef THUMB_VARIANT | |
9397 | #define THUMB_VARIANT &arm_ext_div | |
9398 | TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div), | |
9399 | TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div), | |
9400 | ||
9401 | /* ARM V7 instructions. */ | |
9402 | #undef ARM_VARIANT | |
9403 | #define ARM_VARIANT &arm_ext_v7 | |
9404 | #undef THUMB_VARIANT | |
9405 | #define THUMB_VARIANT &arm_ext_v7 | |
9406 | TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld), | |
9407 | TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg), | |
9408 | TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier), | |
9409 | TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier), | |
9410 | TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier), | |
9411 | ||
c19d1205 | 9412 | #undef ARM_VARIANT |
e74cfd16 | 9413 | #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ |
8f06b2d8 PB |
9414 | cCE(wfs, e200110, 1, (RR), rd), |
9415 | cCE(rfs, e300110, 1, (RR), rd), | |
9416 | cCE(wfc, e400110, 1, (RR), rd), | |
9417 | cCE(rfc, e500110, 1, (RR), rd), | |
9418 | ||
e3cb604e PB |
9419 | cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr), |
9420 | cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr), | |
9421 | cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr), | |
9422 | cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr), | |
9423 | ||
9424 | cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr), | |
9425 | cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr), | |
9426 | cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr), | |
9427 | cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr), | |
9428 | ||
9429 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
9430 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
9431 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
9432 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
9433 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
9434 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
9435 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
9436 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
9437 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
9438 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
9439 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
9440 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
9441 | ||
9442 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
9443 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
9444 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
9445 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
9446 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
9447 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
9448 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
9449 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
9450 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
9451 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
9452 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
9453 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
9454 | ||
9455 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
9456 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
9457 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
9458 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
9459 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
9460 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
9461 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
9462 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
9463 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
9464 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
9465 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
9466 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
9467 | ||
9468 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
9469 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
9470 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
9471 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
9472 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
9473 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
9474 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
9475 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
9476 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
9477 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
9478 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
9479 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
9480 | ||
9481 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
9482 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
9483 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
9484 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
9485 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
9486 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
9487 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
9488 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
9489 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
9490 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
9491 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
9492 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
9493 | ||
9494 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
9495 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
9496 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
9497 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
9498 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
9499 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
9500 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
9501 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
9502 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
9503 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
9504 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
9505 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
9506 | ||
9507 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
9508 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
9509 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
9510 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
9511 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
9512 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
9513 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
9514 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
9515 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
9516 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
9517 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
9518 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
9519 | ||
9520 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
9521 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
9522 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
9523 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
9524 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
9525 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
9526 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
9527 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
9528 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
9529 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
9530 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
9531 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
9532 | ||
9533 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
9534 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
9535 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
9536 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
9537 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
9538 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
9539 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
9540 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
9541 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
9542 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
9543 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
9544 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
9545 | ||
9546 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
9547 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
9548 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
9549 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
9550 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
9551 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
9552 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
9553 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
9554 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
9555 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
9556 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
9557 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
9558 | ||
9559 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
9560 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
9561 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
9562 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
9563 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
9564 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
9565 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
9566 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
9567 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
9568 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
9569 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
9570 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
9571 | ||
9572 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
9573 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
9574 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
9575 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
9576 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
9577 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
9578 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
9579 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
9580 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
9581 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
9582 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
9583 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
9584 | ||
9585 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
9586 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
9587 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
9588 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
9589 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
9590 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
9591 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
9592 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
9593 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
9594 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
9595 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
9596 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
9597 | ||
9598 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
9599 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
9600 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
9601 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
9602 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
9603 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
9604 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
9605 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
9606 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
9607 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
9608 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
9609 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
9610 | ||
9611 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
9612 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
9613 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
9614 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
9615 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
9616 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
9617 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
9618 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
9619 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
9620 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
9621 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
9622 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
9623 | ||
9624 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
9625 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
9626 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
9627 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
9628 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
9629 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
9630 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
9631 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
9632 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
9633 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
9634 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
9635 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
9636 | ||
9637 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9638 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9639 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9640 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9641 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9642 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9643 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9644 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9645 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9646 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9647 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9648 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9649 | ||
9650 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9651 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9652 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9653 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9654 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9655 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9656 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9657 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9658 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9659 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9660 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9661 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9662 | ||
9663 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9664 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9665 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9666 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9667 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9668 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9669 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9670 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9671 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9672 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9673 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9674 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9675 | ||
9676 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9677 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9678 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9679 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9680 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9681 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9682 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9683 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9684 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9685 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9686 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9687 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9688 | ||
9689 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9690 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9691 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9692 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9693 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9694 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9695 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9696 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9697 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9698 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9699 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9700 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9701 | ||
9702 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9703 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9704 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9705 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9706 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9707 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9708 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9709 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9710 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9711 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9712 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9713 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9714 | ||
9715 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9716 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9717 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9718 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9719 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9720 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9721 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9722 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9723 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9724 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9725 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9726 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9727 | ||
9728 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9729 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9730 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9731 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9732 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9733 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9734 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9735 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9736 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9737 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9738 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9739 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9740 | ||
9741 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9742 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9743 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9744 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9745 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9746 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9747 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9748 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9749 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9750 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9751 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9752 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9753 | ||
9754 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9755 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9756 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9757 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9758 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9759 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9760 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9761 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9762 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9763 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9764 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9765 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9766 | ||
9767 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9768 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9769 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9770 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9771 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9772 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9773 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9774 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9775 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9776 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9777 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9778 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9779 | ||
9780 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9781 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9782 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9783 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9784 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9785 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9786 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9787 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9788 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9789 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9790 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9791 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9792 | ||
9793 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9794 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9795 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9796 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9797 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9798 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9799 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9800 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9801 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9802 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9803 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9804 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
9805 | |
9806 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 9807 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 9808 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
9809 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
9810 | ||
e3cb604e PB |
9811 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
9812 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
9813 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
9814 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
9815 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
9816 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
9817 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
9818 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
9819 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
9820 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
9821 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
9822 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 9823 | |
c19d1205 ZW |
9824 | /* The implementation of the FIX instruction is broken on some |
9825 | assemblers, in that it accepts a precision specifier as well as a | |
9826 | rounding specifier, despite the fact that this is meaningless. | |
9827 | To be more compatible, we accept it as well, though of course it | |
9828 | does not set any bits. */ | |
8f06b2d8 | 9829 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
9830 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
9831 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
9832 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
9833 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
9834 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
9835 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
9836 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
9837 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
9838 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
9839 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
9840 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
9841 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 9842 | |
c19d1205 ZW |
9843 | /* Instructions that were new with the real FPA, call them V2. */ |
9844 | #undef ARM_VARIANT | |
e74cfd16 | 9845 | #define ARM_VARIANT &fpu_fpa_ext_v2 |
8f06b2d8 | 9846 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
9847 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
9848 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 9849 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
9850 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
9851 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 ZW |
9852 | |
9853 | #undef ARM_VARIANT | |
e74cfd16 | 9854 | #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ |
c19d1205 | 9855 | /* Moves and type conversions. */ |
8f06b2d8 PB |
9856 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
9857 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
9858 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
9859 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
9860 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9861 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9862 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9863 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9864 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9865 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9866 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
9867 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
9868 | |
9869 | /* Memory operations. */ | |
8f06b2d8 PB |
9870 | cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst), |
9871 | cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst), | |
9872 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9873 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9874 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9875 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9876 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9877 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9878 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
9879 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
9880 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9881 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9882 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9883 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9884 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9885 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9886 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
9887 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 9888 | |
c19d1205 | 9889 | /* Monadic operations. */ |
8f06b2d8 PB |
9890 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
9891 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9892 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
9893 | |
9894 | /* Dyadic operations. */ | |
8f06b2d8 PB |
9895 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
9896 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9897 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9898 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9899 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9900 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9901 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9902 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9903 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 9904 | |
c19d1205 | 9905 | /* Comparisons. */ |
8f06b2d8 PB |
9906 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
9907 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
9908 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9909 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 9910 | |
c19d1205 | 9911 | #undef ARM_VARIANT |
e74cfd16 | 9912 | #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ |
c19d1205 | 9913 | /* Moves and type conversions. */ |
8f06b2d8 PB |
9914 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm), |
9915 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
9916 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9917 | cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd), | |
9918 | cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd), | |
9919 | cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn), | |
9920 | cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn), | |
9921 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
9922 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
9923 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9924 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9925 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9926 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
9927 | |
9928 | /* Memory operations. */ | |
8f06b2d8 PB |
9929 | cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst), |
9930 | cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst), | |
9931 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9932 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9933 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
9934 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
9935 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9936 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9937 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
9938 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 9939 | |
c19d1205 | 9940 | /* Monadic operations. */ |
8f06b2d8 PB |
9941 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm), |
9942 | cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm), | |
9943 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm), | |
c19d1205 ZW |
9944 | |
9945 | /* Dyadic operations. */ | |
8f06b2d8 PB |
9946 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm), |
9947 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9948 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9949 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9950 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9951 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9952 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9953 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9954 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
b99bd4ef | 9955 | |
c19d1205 | 9956 | /* Comparisons. */ |
8f06b2d8 PB |
9957 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm), |
9958 | cCE(fcmpzd, eb50b40, 1, (RVD), rd), | |
9959 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm), | |
9960 | cCE(fcmpezd, eb50bc0, 1, (RVD), rd), | |
c19d1205 ZW |
9961 | |
9962 | #undef ARM_VARIANT | |
e74cfd16 | 9963 | #define ARM_VARIANT &fpu_vfp_ext_v2 |
8f06b2d8 PB |
9964 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
9965 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
9966 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn), | |
9967 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm), | |
c19d1205 ZW |
9968 | |
9969 | #undef ARM_VARIANT | |
e74cfd16 | 9970 | #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */ |
8f06b2d8 PB |
9971 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
9972 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9973 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9974 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9975 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9976 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9977 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
9978 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 ZW |
9979 | |
9980 | #undef ARM_VARIANT | |
e74cfd16 | 9981 | #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */ |
8f06b2d8 PB |
9982 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
9983 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
9984 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
9985 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
9986 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
9987 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
9988 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
9989 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
9990 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
9991 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9992 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9993 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9994 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9995 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9996 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9997 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
9998 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
9999 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
10000 | cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd), | |
10001 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
10002 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
10003 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
10004 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
10005 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
10006 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
10007 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
10008 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
10009 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
10010 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
10011 | cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn), | |
10012 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
10013 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
10014 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
10015 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
10016 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
10017 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
10018 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
10019 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10020 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10021 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10022 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10023 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10024 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10025 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10026 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10027 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10028 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
10029 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10030 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10031 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10032 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10033 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10034 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10035 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10036 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10037 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10038 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10039 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10040 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10041 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10042 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10043 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10044 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10045 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10046 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10047 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10048 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
10049 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
10050 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
10051 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
10052 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10053 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10054 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10055 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10056 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10057 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10058 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10059 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10060 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10061 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10062 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10063 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10064 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10065 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10066 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10067 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10068 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10069 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10070 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
10071 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10072 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10073 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10074 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10075 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10076 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10077 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10078 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10079 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10080 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10081 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10082 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10083 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10084 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10085 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10086 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10087 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10088 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10089 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10090 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10091 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10092 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
10093 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10094 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10095 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10096 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10097 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10098 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10099 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10100 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10101 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10102 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10103 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10104 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10105 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10106 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10107 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10108 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10109 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10110 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
10111 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
10112 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
10113 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
10114 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
10115 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10116 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10117 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10118 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10119 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10120 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10121 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10122 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10123 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10124 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
10125 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
10126 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
10127 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
10128 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
10129 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
10130 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10131 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10132 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10133 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
10134 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
10135 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
10136 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
10137 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
10138 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
10139 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10140 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10141 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10142 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
10143 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 ZW |
10144 | |
10145 | #undef ARM_VARIANT | |
e74cfd16 | 10146 | #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */ |
8f06b2d8 PB |
10147 | cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr), |
10148 | cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr), | |
10149 | cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr), | |
10150 | cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr), | |
10151 | cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr), | |
10152 | cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr), | |
10153 | cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr), | |
10154 | cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr), | |
10155 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), | |
10156 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
10157 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
10158 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
10159 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
10160 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
10161 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
10162 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
10163 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
10164 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
10165 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
10166 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
10167 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
10168 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
10169 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
10170 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
10171 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
10172 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
10173 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
10174 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
10175 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
10176 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
10177 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
10178 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
10179 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
10180 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
10181 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
10182 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
10183 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
10184 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
10185 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
10186 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
10187 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
10188 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
10189 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
10190 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
10191 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
10192 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
10193 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
10194 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
10195 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
10196 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
10197 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
10198 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
10199 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
10200 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
10201 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
10202 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
10203 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
10204 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
10205 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
10206 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
10207 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
10208 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
10209 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
10210 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
10211 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
10212 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
10213 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
10214 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
10215 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
10216 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
10217 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
10218 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
10219 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
10220 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
10221 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
10222 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
10223 | }; |
10224 | #undef ARM_VARIANT | |
10225 | #undef THUMB_VARIANT | |
10226 | #undef TCE | |
10227 | #undef TCM | |
10228 | #undef TUE | |
10229 | #undef TUF | |
10230 | #undef TCC | |
8f06b2d8 | 10231 | #undef cCE |
e3cb604e PB |
10232 | #undef cCL |
10233 | #undef C3E | |
c19d1205 ZW |
10234 | #undef CE |
10235 | #undef CM | |
10236 | #undef UE | |
10237 | #undef UF | |
10238 | #undef UT | |
10239 | #undef OPS0 | |
10240 | #undef OPS1 | |
10241 | #undef OPS2 | |
10242 | #undef OPS3 | |
10243 | #undef OPS4 | |
10244 | #undef OPS5 | |
10245 | #undef OPS6 | |
10246 | #undef do_0 | |
10247 | \f | |
10248 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 10249 | |
c19d1205 ZW |
10250 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
10251 | for use in the a.out file, and stores them in the array pointed to by buf. | |
10252 | This knows about the endian-ness of the target machine and does | |
10253 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
10254 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
10255 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 10256 | |
c19d1205 ZW |
10257 | void |
10258 | md_number_to_chars (char * buf, valueT val, int n) | |
10259 | { | |
10260 | if (target_big_endian) | |
10261 | number_to_chars_bigendian (buf, val, n); | |
10262 | else | |
10263 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
10264 | } |
10265 | ||
c19d1205 ZW |
10266 | static valueT |
10267 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 10268 | { |
c19d1205 ZW |
10269 | valueT result = 0; |
10270 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 10271 | |
c19d1205 | 10272 | if (target_big_endian) |
b99bd4ef | 10273 | { |
c19d1205 ZW |
10274 | while (n--) |
10275 | { | |
10276 | result <<= 8; | |
10277 | result |= (*where++ & 255); | |
10278 | } | |
b99bd4ef | 10279 | } |
c19d1205 | 10280 | else |
b99bd4ef | 10281 | { |
c19d1205 ZW |
10282 | while (n--) |
10283 | { | |
10284 | result <<= 8; | |
10285 | result |= (where[n] & 255); | |
10286 | } | |
bfae80f2 | 10287 | } |
b99bd4ef | 10288 | |
c19d1205 | 10289 | return result; |
bfae80f2 | 10290 | } |
b99bd4ef | 10291 | |
c19d1205 | 10292 | /* MD interface: Sections. */ |
b99bd4ef | 10293 | |
0110f2b8 PB |
10294 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
10295 | 2 bytes. */ | |
10296 | ||
c19d1205 | 10297 | int |
0110f2b8 | 10298 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
10299 | segT segtype ATTRIBUTE_UNUSED) |
10300 | { | |
0110f2b8 PB |
10301 | fragp->fr_var = 2; |
10302 | return 2; | |
10303 | } | |
10304 | ||
10305 | /* Convert a machine dependent frag. */ | |
10306 | ||
10307 | void | |
10308 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
10309 | { | |
10310 | unsigned long insn; | |
10311 | unsigned long old_op; | |
10312 | char *buf; | |
10313 | expressionS exp; | |
10314 | fixS *fixp; | |
10315 | int reloc_type; | |
10316 | int pc_rel; | |
10317 | int opcode; | |
10318 | ||
10319 | buf = fragp->fr_literal + fragp->fr_fix; | |
10320 | ||
10321 | old_op = bfd_get_16(abfd, buf); | |
10322 | if (fragp->fr_symbol) { | |
10323 | exp.X_op = O_symbol; | |
10324 | exp.X_add_symbol = fragp->fr_symbol; | |
10325 | } else { | |
10326 | exp.X_op = O_constant; | |
10327 | } | |
10328 | exp.X_add_number = fragp->fr_offset; | |
10329 | opcode = fragp->fr_subtype; | |
10330 | switch (opcode) | |
10331 | { | |
10332 | case T_MNEM_ldr_pc: | |
10333 | case T_MNEM_ldr_pc2: | |
10334 | case T_MNEM_ldr_sp: | |
10335 | case T_MNEM_str_sp: | |
10336 | case T_MNEM_ldr: | |
10337 | case T_MNEM_ldrb: | |
10338 | case T_MNEM_ldrh: | |
10339 | case T_MNEM_str: | |
10340 | case T_MNEM_strb: | |
10341 | case T_MNEM_strh: | |
10342 | if (fragp->fr_var == 4) | |
10343 | { | |
10344 | insn = THUMB_OP32(opcode); | |
10345 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) | |
10346 | { | |
10347 | insn |= (old_op & 0x700) << 4; | |
10348 | } | |
10349 | else | |
10350 | { | |
10351 | insn |= (old_op & 7) << 12; | |
10352 | insn |= (old_op & 0x38) << 13; | |
10353 | } | |
10354 | insn |= 0x00000c00; | |
10355 | put_thumb32_insn (buf, insn); | |
10356 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
10357 | } | |
10358 | else | |
10359 | { | |
10360 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10361 | } | |
10362 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
10363 | break; | |
10364 | case T_MNEM_adr: | |
10365 | if (fragp->fr_var == 4) | |
10366 | { | |
10367 | insn = THUMB_OP32 (opcode); | |
10368 | insn |= (old_op & 0xf0) << 4; | |
10369 | put_thumb32_insn (buf, insn); | |
10370 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
10371 | } | |
10372 | else | |
10373 | { | |
10374 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
10375 | exp.X_add_number -= 4; | |
10376 | } | |
10377 | pc_rel = 1; | |
10378 | break; | |
10379 | case T_MNEM_mov: | |
10380 | case T_MNEM_movs: | |
10381 | case T_MNEM_cmp: | |
10382 | case T_MNEM_cmn: | |
10383 | if (fragp->fr_var == 4) | |
10384 | { | |
10385 | int r0off = (opcode == T_MNEM_mov | |
10386 | || opcode == T_MNEM_movs) ? 0 : 8; | |
10387 | insn = THUMB_OP32 (opcode); | |
10388 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
10389 | insn |= (old_op & 0x700) << r0off; | |
10390 | put_thumb32_insn (buf, insn); | |
10391 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10392 | } | |
10393 | else | |
10394 | { | |
10395 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
10396 | } | |
10397 | pc_rel = 0; | |
10398 | break; | |
10399 | case T_MNEM_b: | |
10400 | if (fragp->fr_var == 4) | |
10401 | { | |
10402 | insn = THUMB_OP32(opcode); | |
10403 | put_thumb32_insn (buf, insn); | |
10404 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
10405 | } | |
10406 | else | |
10407 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
10408 | pc_rel = 1; | |
10409 | break; | |
10410 | case T_MNEM_bcond: | |
10411 | if (fragp->fr_var == 4) | |
10412 | { | |
10413 | insn = THUMB_OP32(opcode); | |
10414 | insn |= (old_op & 0xf00) << 14; | |
10415 | put_thumb32_insn (buf, insn); | |
10416 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
10417 | } | |
10418 | else | |
10419 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
10420 | pc_rel = 1; | |
10421 | break; | |
10422 | case T_MNEM_add_sp: | |
10423 | case T_MNEM_add_pc: | |
10424 | case T_MNEM_inc_sp: | |
10425 | case T_MNEM_dec_sp: | |
10426 | if (fragp->fr_var == 4) | |
10427 | { | |
10428 | /* ??? Choose between add and addw. */ | |
10429 | insn = THUMB_OP32 (opcode); | |
10430 | insn |= (old_op & 0xf0) << 4; | |
10431 | put_thumb32_insn (buf, insn); | |
10432 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10433 | } | |
10434 | else | |
10435 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
10436 | pc_rel = 0; | |
10437 | break; | |
10438 | ||
10439 | case T_MNEM_addi: | |
10440 | case T_MNEM_addis: | |
10441 | case T_MNEM_subi: | |
10442 | case T_MNEM_subis: | |
10443 | if (fragp->fr_var == 4) | |
10444 | { | |
10445 | insn = THUMB_OP32 (opcode); | |
10446 | insn |= (old_op & 0xf0) << 4; | |
10447 | insn |= (old_op & 0xf) << 16; | |
10448 | put_thumb32_insn (buf, insn); | |
10449 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10450 | } | |
10451 | else | |
10452 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
10453 | pc_rel = 0; | |
10454 | break; | |
10455 | default: | |
10456 | abort(); | |
10457 | } | |
10458 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
10459 | reloc_type); | |
10460 | fixp->fx_file = fragp->fr_file; | |
10461 | fixp->fx_line = fragp->fr_line; | |
10462 | fragp->fr_fix += fragp->fr_var; | |
10463 | } | |
10464 | ||
10465 | /* Return the size of a relaxable immediate operand instruction. | |
10466 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
10467 | static int | |
10468 | relax_immediate (fragS *fragp, int size, int shift) | |
10469 | { | |
10470 | offsetT offset; | |
10471 | offsetT mask; | |
10472 | offsetT low; | |
10473 | ||
10474 | /* ??? Should be able to do better than this. */ | |
10475 | if (fragp->fr_symbol) | |
10476 | return 4; | |
10477 | ||
10478 | low = (1 << shift) - 1; | |
10479 | mask = (1 << (shift + size)) - (1 << shift); | |
10480 | offset = fragp->fr_offset; | |
10481 | /* Force misaligned offsets to 32-bit variant. */ | |
10482 | if (offset & low) | |
10483 | return -4; | |
10484 | if (offset & ~mask) | |
10485 | return 4; | |
10486 | return 2; | |
10487 | } | |
10488 | ||
10489 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative | |
10490 | load. */ | |
10491 | static int | |
10492 | relax_adr (fragS *fragp, asection *sec) | |
10493 | { | |
10494 | addressT addr; | |
10495 | offsetT val; | |
10496 | ||
10497 | /* Assume worst case for symbols not known to be in the same section. */ | |
10498 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
10499 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
10500 | return 4; | |
10501 | ||
10502 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
10503 | addr = fragp->fr_address + fragp->fr_fix; | |
10504 | addr = (addr + 4) & ~3; | |
10505 | /* Fix the insn as the 4-byte version if the target address is not | |
10506 | sufficiently aligned. This is prevents an infinite loop when two | |
10507 | instructions have contradictory range/alignment requirements. */ | |
10508 | if (val & 3) | |
10509 | return -4; | |
10510 | val -= addr; | |
10511 | if (val < 0 || val > 1020) | |
10512 | return 4; | |
10513 | return 2; | |
10514 | } | |
10515 | ||
10516 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
10517 | static int | |
10518 | relax_addsub (fragS *fragp, asection *sec) | |
10519 | { | |
10520 | char *buf; | |
10521 | int op; | |
10522 | ||
10523 | buf = fragp->fr_literal + fragp->fr_fix; | |
10524 | op = bfd_get_16(sec->owner, buf); | |
10525 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
10526 | return relax_immediate (fragp, 8, 0); | |
10527 | else | |
10528 | return relax_immediate (fragp, 3, 0); | |
10529 | } | |
10530 | ||
10531 | ||
10532 | /* Return the size of a relaxable branch instruction. BITS is the | |
10533 | size of the offset field in the narrow instruction. */ | |
10534 | ||
10535 | static int | |
10536 | relax_branch (fragS *fragp, asection *sec, int bits) | |
10537 | { | |
10538 | addressT addr; | |
10539 | offsetT val; | |
10540 | offsetT limit; | |
10541 | ||
10542 | /* Assume worst case for symbols not known to be in the same section. */ | |
10543 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
10544 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
10545 | return 4; | |
10546 | ||
10547 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
10548 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
10549 | val -= addr; | |
10550 | ||
10551 | /* Offset is a signed value *2 */ | |
10552 | limit = 1 << bits; | |
10553 | if (val >= limit || val < -limit) | |
10554 | return 4; | |
10555 | return 2; | |
10556 | } | |
10557 | ||
10558 | ||
10559 | /* Relax a machine dependent frag. This returns the amount by which | |
10560 | the current size of the frag should change. */ | |
10561 | ||
10562 | int | |
10563 | arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED) | |
10564 | { | |
10565 | int oldsize; | |
10566 | int newsize; | |
10567 | ||
10568 | oldsize = fragp->fr_var; | |
10569 | switch (fragp->fr_subtype) | |
10570 | { | |
10571 | case T_MNEM_ldr_pc2: | |
10572 | newsize = relax_adr(fragp, sec); | |
10573 | break; | |
10574 | case T_MNEM_ldr_pc: | |
10575 | case T_MNEM_ldr_sp: | |
10576 | case T_MNEM_str_sp: | |
10577 | newsize = relax_immediate(fragp, 8, 2); | |
10578 | break; | |
10579 | case T_MNEM_ldr: | |
10580 | case T_MNEM_str: | |
10581 | newsize = relax_immediate(fragp, 5, 2); | |
10582 | break; | |
10583 | case T_MNEM_ldrh: | |
10584 | case T_MNEM_strh: | |
10585 | newsize = relax_immediate(fragp, 5, 1); | |
10586 | break; | |
10587 | case T_MNEM_ldrb: | |
10588 | case T_MNEM_strb: | |
10589 | newsize = relax_immediate(fragp, 5, 0); | |
10590 | break; | |
10591 | case T_MNEM_adr: | |
10592 | newsize = relax_adr(fragp, sec); | |
10593 | break; | |
10594 | case T_MNEM_mov: | |
10595 | case T_MNEM_movs: | |
10596 | case T_MNEM_cmp: | |
10597 | case T_MNEM_cmn: | |
10598 | newsize = relax_immediate(fragp, 8, 0); | |
10599 | break; | |
10600 | case T_MNEM_b: | |
10601 | newsize = relax_branch(fragp, sec, 11); | |
10602 | break; | |
10603 | case T_MNEM_bcond: | |
10604 | newsize = relax_branch(fragp, sec, 8); | |
10605 | break; | |
10606 | case T_MNEM_add_sp: | |
10607 | case T_MNEM_add_pc: | |
10608 | newsize = relax_immediate (fragp, 8, 2); | |
10609 | break; | |
10610 | case T_MNEM_inc_sp: | |
10611 | case T_MNEM_dec_sp: | |
10612 | newsize = relax_immediate (fragp, 7, 2); | |
10613 | break; | |
10614 | case T_MNEM_addi: | |
10615 | case T_MNEM_addis: | |
10616 | case T_MNEM_subi: | |
10617 | case T_MNEM_subis: | |
10618 | newsize = relax_addsub (fragp, sec); | |
10619 | break; | |
10620 | default: | |
10621 | abort(); | |
10622 | } | |
10623 | if (newsize < 0) | |
10624 | { | |
10625 | fragp->fr_var = -newsize; | |
10626 | md_convert_frag (sec->owner, sec, fragp); | |
10627 | frag_wane(fragp); | |
10628 | return -(newsize + oldsize); | |
10629 | } | |
10630 | fragp->fr_var = newsize; | |
10631 | return newsize - oldsize; | |
c19d1205 | 10632 | } |
b99bd4ef | 10633 | |
c19d1205 | 10634 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 10635 | |
c19d1205 ZW |
10636 | valueT |
10637 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
10638 | valueT size) | |
10639 | { | |
10640 | #ifdef OBJ_ELF | |
10641 | return size; | |
10642 | #else | |
10643 | /* Round all sects to multiple of 4. */ | |
10644 | return (size + 3) & ~3; | |
10645 | #endif | |
bfae80f2 | 10646 | } |
b99bd4ef | 10647 | |
c19d1205 ZW |
10648 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
10649 | of an rs_align_code fragment. */ | |
10650 | ||
10651 | void | |
10652 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 10653 | { |
c19d1205 ZW |
10654 | static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 }; |
10655 | static char const thumb_noop[2] = { 0xc0, 0x46 }; | |
10656 | static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 }; | |
10657 | static char const thumb_bigend_noop[2] = { 0x46, 0xc0 }; | |
10658 | ||
10659 | int bytes, fix, noop_size; | |
10660 | char * p; | |
10661 | const char * noop; | |
bfae80f2 | 10662 | |
c19d1205 | 10663 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
10664 | return; |
10665 | ||
c19d1205 ZW |
10666 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
10667 | p = fragP->fr_literal + fragP->fr_fix; | |
10668 | fix = 0; | |
bfae80f2 | 10669 | |
c19d1205 ZW |
10670 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
10671 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 10672 | |
c19d1205 | 10673 | if (fragP->tc_frag_data) |
a737bd4d | 10674 | { |
c19d1205 ZW |
10675 | if (target_big_endian) |
10676 | noop = thumb_bigend_noop; | |
10677 | else | |
10678 | noop = thumb_noop; | |
10679 | noop_size = sizeof (thumb_noop); | |
7ed4c4c5 NC |
10680 | } |
10681 | else | |
10682 | { | |
c19d1205 ZW |
10683 | if (target_big_endian) |
10684 | noop = arm_bigend_noop; | |
10685 | else | |
10686 | noop = arm_noop; | |
10687 | noop_size = sizeof (arm_noop); | |
7ed4c4c5 | 10688 | } |
a737bd4d | 10689 | |
c19d1205 | 10690 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 10691 | { |
c19d1205 ZW |
10692 | fix = bytes & (noop_size - 1); |
10693 | memset (p, 0, fix); | |
10694 | p += fix; | |
10695 | bytes -= fix; | |
a737bd4d | 10696 | } |
a737bd4d | 10697 | |
c19d1205 | 10698 | while (bytes >= noop_size) |
a737bd4d | 10699 | { |
c19d1205 ZW |
10700 | memcpy (p, noop, noop_size); |
10701 | p += noop_size; | |
10702 | bytes -= noop_size; | |
10703 | fix += noop_size; | |
a737bd4d NC |
10704 | } |
10705 | ||
c19d1205 ZW |
10706 | fragP->fr_fix += fix; |
10707 | fragP->fr_var = noop_size; | |
a737bd4d NC |
10708 | } |
10709 | ||
c19d1205 ZW |
10710 | /* Called from md_do_align. Used to create an alignment |
10711 | frag in a code section. */ | |
10712 | ||
10713 | void | |
10714 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 10715 | { |
c19d1205 | 10716 | char * p; |
7ed4c4c5 | 10717 | |
c19d1205 ZW |
10718 | /* We assume that there will never be a requirement |
10719 | to support alignments greater than 32 bytes. */ | |
10720 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) | |
10721 | as_fatal (_("alignments greater than 32 bytes not supported in .text sections.")); | |
bfae80f2 | 10722 | |
c19d1205 ZW |
10723 | p = frag_var (rs_align_code, |
10724 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
10725 | 1, | |
10726 | (relax_substateT) max, | |
10727 | (symbolS *) NULL, | |
10728 | (offsetT) n, | |
10729 | (char *) NULL); | |
10730 | *p = 0; | |
10731 | } | |
bfae80f2 | 10732 | |
c19d1205 | 10733 | /* Perform target specific initialisation of a frag. */ |
bfae80f2 | 10734 | |
c19d1205 ZW |
10735 | void |
10736 | arm_init_frag (fragS * fragP) | |
10737 | { | |
10738 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
10739 | fragP->tc_frag_data = thumb_mode; | |
bfae80f2 RE |
10740 | } |
10741 | ||
c19d1205 ZW |
10742 | #ifdef OBJ_ELF |
10743 | /* When we change sections we need to issue a new mapping symbol. */ | |
10744 | ||
10745 | void | |
10746 | arm_elf_change_section (void) | |
bfae80f2 | 10747 | { |
c19d1205 ZW |
10748 | flagword flags; |
10749 | segment_info_type *seginfo; | |
bfae80f2 | 10750 | |
c19d1205 ZW |
10751 | /* Link an unlinked unwind index table section to the .text section. */ |
10752 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
10753 | && elf_linked_to_section (now_seg) == NULL) | |
10754 | elf_linked_to_section (now_seg) = text_section; | |
10755 | ||
10756 | if (!SEG_NORMAL (now_seg)) | |
bfae80f2 RE |
10757 | return; |
10758 | ||
c19d1205 ZW |
10759 | flags = bfd_get_section_flags (stdoutput, now_seg); |
10760 | ||
10761 | /* We can ignore sections that only contain debug info. */ | |
10762 | if ((flags & SEC_ALLOC) == 0) | |
10763 | return; | |
bfae80f2 | 10764 | |
c19d1205 ZW |
10765 | seginfo = seg_info (now_seg); |
10766 | mapstate = seginfo->tc_segment_info_data.mapstate; | |
10767 | marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency; | |
bfae80f2 RE |
10768 | } |
10769 | ||
c19d1205 ZW |
10770 | int |
10771 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 10772 | { |
c19d1205 ZW |
10773 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
10774 | return SHT_ARM_EXIDX; | |
e45d0630 | 10775 | |
c19d1205 ZW |
10776 | return -1; |
10777 | } | |
10778 | \f | |
10779 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 10780 | |
c19d1205 | 10781 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 10782 | |
c19d1205 | 10783 | /* Cenerate and deferred unwind frame offset. */ |
e45d0630 | 10784 | |
bfae80f2 | 10785 | static void |
c19d1205 | 10786 | flush_pending_unwind (void) |
bfae80f2 | 10787 | { |
c19d1205 | 10788 | offsetT offset; |
bfae80f2 | 10789 | |
c19d1205 ZW |
10790 | offset = unwind.pending_offset; |
10791 | unwind.pending_offset = 0; | |
10792 | if (offset != 0) | |
10793 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
10794 | } |
10795 | ||
c19d1205 ZW |
10796 | /* Add an opcode to this list for this function. Two-byte opcodes should |
10797 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
10798 | order. */ | |
10799 | ||
bfae80f2 | 10800 | static void |
c19d1205 | 10801 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 10802 | { |
c19d1205 ZW |
10803 | /* Add any deferred stack adjustment. */ |
10804 | if (unwind.pending_offset) | |
10805 | flush_pending_unwind (); | |
bfae80f2 | 10806 | |
c19d1205 | 10807 | unwind.sp_restored = 0; |
bfae80f2 | 10808 | |
c19d1205 | 10809 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 10810 | { |
c19d1205 ZW |
10811 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
10812 | if (unwind.opcodes) | |
10813 | unwind.opcodes = xrealloc (unwind.opcodes, | |
10814 | unwind.opcode_alloc); | |
10815 | else | |
10816 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 10817 | } |
c19d1205 | 10818 | while (length > 0) |
bfae80f2 | 10819 | { |
c19d1205 ZW |
10820 | length--; |
10821 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
10822 | op >>= 8; | |
10823 | unwind.opcode_count++; | |
bfae80f2 | 10824 | } |
bfae80f2 RE |
10825 | } |
10826 | ||
c19d1205 ZW |
10827 | /* Add unwind opcodes to adjust the stack pointer. */ |
10828 | ||
bfae80f2 | 10829 | static void |
c19d1205 | 10830 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 10831 | { |
c19d1205 | 10832 | valueT op; |
bfae80f2 | 10833 | |
c19d1205 | 10834 | if (offset > 0x200) |
bfae80f2 | 10835 | { |
c19d1205 ZW |
10836 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
10837 | char bytes[5]; | |
10838 | int n; | |
10839 | valueT o; | |
bfae80f2 | 10840 | |
c19d1205 ZW |
10841 | /* Long form: 0xb2, uleb128. */ |
10842 | /* This might not fit in a word so add the individual bytes, | |
10843 | remembering the list is built in reverse order. */ | |
10844 | o = (valueT) ((offset - 0x204) >> 2); | |
10845 | if (o == 0) | |
10846 | add_unwind_opcode (0, 1); | |
bfae80f2 | 10847 | |
c19d1205 ZW |
10848 | /* Calculate the uleb128 encoding of the offset. */ |
10849 | n = 0; | |
10850 | while (o) | |
10851 | { | |
10852 | bytes[n] = o & 0x7f; | |
10853 | o >>= 7; | |
10854 | if (o) | |
10855 | bytes[n] |= 0x80; | |
10856 | n++; | |
10857 | } | |
10858 | /* Add the insn. */ | |
10859 | for (; n; n--) | |
10860 | add_unwind_opcode (bytes[n - 1], 1); | |
10861 | add_unwind_opcode (0xb2, 1); | |
10862 | } | |
10863 | else if (offset > 0x100) | |
bfae80f2 | 10864 | { |
c19d1205 ZW |
10865 | /* Two short opcodes. */ |
10866 | add_unwind_opcode (0x3f, 1); | |
10867 | op = (offset - 0x104) >> 2; | |
10868 | add_unwind_opcode (op, 1); | |
bfae80f2 | 10869 | } |
c19d1205 ZW |
10870 | else if (offset > 0) |
10871 | { | |
10872 | /* Short opcode. */ | |
10873 | op = (offset - 4) >> 2; | |
10874 | add_unwind_opcode (op, 1); | |
10875 | } | |
10876 | else if (offset < 0) | |
bfae80f2 | 10877 | { |
c19d1205 ZW |
10878 | offset = -offset; |
10879 | while (offset > 0x100) | |
bfae80f2 | 10880 | { |
c19d1205 ZW |
10881 | add_unwind_opcode (0x7f, 1); |
10882 | offset -= 0x100; | |
bfae80f2 | 10883 | } |
c19d1205 ZW |
10884 | op = ((offset - 4) >> 2) | 0x40; |
10885 | add_unwind_opcode (op, 1); | |
bfae80f2 | 10886 | } |
bfae80f2 RE |
10887 | } |
10888 | ||
c19d1205 ZW |
10889 | /* Finish the list of unwind opcodes for this function. */ |
10890 | static void | |
10891 | finish_unwind_opcodes (void) | |
bfae80f2 | 10892 | { |
c19d1205 | 10893 | valueT op; |
bfae80f2 | 10894 | |
c19d1205 | 10895 | if (unwind.fp_used) |
bfae80f2 | 10896 | { |
c19d1205 ZW |
10897 | /* Adjust sp as neccessary. */ |
10898 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; | |
10899 | flush_pending_unwind (); | |
bfae80f2 | 10900 | |
c19d1205 ZW |
10901 | /* After restoring sp from the frame pointer. */ |
10902 | op = 0x90 | unwind.fp_reg; | |
10903 | add_unwind_opcode (op, 1); | |
10904 | } | |
10905 | else | |
10906 | flush_pending_unwind (); | |
bfae80f2 RE |
10907 | } |
10908 | ||
bfae80f2 | 10909 | |
c19d1205 ZW |
10910 | /* Start an exception table entry. If idx is nonzero this is an index table |
10911 | entry. */ | |
bfae80f2 RE |
10912 | |
10913 | static void | |
c19d1205 | 10914 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 10915 | { |
c19d1205 ZW |
10916 | const char * text_name; |
10917 | const char * prefix; | |
10918 | const char * prefix_once; | |
10919 | const char * group_name; | |
10920 | size_t prefix_len; | |
10921 | size_t text_len; | |
10922 | char * sec_name; | |
10923 | size_t sec_name_len; | |
10924 | int type; | |
10925 | int flags; | |
10926 | int linkonce; | |
bfae80f2 | 10927 | |
c19d1205 | 10928 | if (idx) |
bfae80f2 | 10929 | { |
c19d1205 ZW |
10930 | prefix = ELF_STRING_ARM_unwind; |
10931 | prefix_once = ELF_STRING_ARM_unwind_once; | |
10932 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 10933 | } |
c19d1205 | 10934 | else |
bfae80f2 | 10935 | { |
c19d1205 ZW |
10936 | prefix = ELF_STRING_ARM_unwind_info; |
10937 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
10938 | type = SHT_PROGBITS; | |
bfae80f2 RE |
10939 | } |
10940 | ||
c19d1205 ZW |
10941 | text_name = segment_name (text_seg); |
10942 | if (streq (text_name, ".text")) | |
10943 | text_name = ""; | |
10944 | ||
10945 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
10946 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 10947 | { |
c19d1205 ZW |
10948 | prefix = prefix_once; |
10949 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
10950 | } |
10951 | ||
c19d1205 ZW |
10952 | prefix_len = strlen (prefix); |
10953 | text_len = strlen (text_name); | |
10954 | sec_name_len = prefix_len + text_len; | |
10955 | sec_name = xmalloc (sec_name_len + 1); | |
10956 | memcpy (sec_name, prefix, prefix_len); | |
10957 | memcpy (sec_name + prefix_len, text_name, text_len); | |
10958 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 10959 | |
c19d1205 ZW |
10960 | flags = SHF_ALLOC; |
10961 | linkonce = 0; | |
10962 | group_name = 0; | |
bfae80f2 | 10963 | |
c19d1205 ZW |
10964 | /* Handle COMDAT group. */ |
10965 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 10966 | { |
c19d1205 ZW |
10967 | group_name = elf_group_name (text_seg); |
10968 | if (group_name == NULL) | |
10969 | { | |
10970 | as_bad ("Group section `%s' has no group signature", | |
10971 | segment_name (text_seg)); | |
10972 | ignore_rest_of_line (); | |
10973 | return; | |
10974 | } | |
10975 | flags |= SHF_GROUP; | |
10976 | linkonce = 1; | |
bfae80f2 RE |
10977 | } |
10978 | ||
c19d1205 | 10979 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 10980 | |
c19d1205 ZW |
10981 | /* Set the setion link for index tables. */ |
10982 | if (idx) | |
10983 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
10984 | } |
10985 | ||
bfae80f2 | 10986 | |
c19d1205 ZW |
10987 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
10988 | personality routine data. Returns zero, or the index table value for | |
10989 | and inline entry. */ | |
10990 | ||
10991 | static valueT | |
10992 | create_unwind_entry (int have_data) | |
bfae80f2 | 10993 | { |
c19d1205 ZW |
10994 | int size; |
10995 | addressT where; | |
10996 | char *ptr; | |
10997 | /* The current word of data. */ | |
10998 | valueT data; | |
10999 | /* The number of bytes left in this word. */ | |
11000 | int n; | |
bfae80f2 | 11001 | |
c19d1205 | 11002 | finish_unwind_opcodes (); |
bfae80f2 | 11003 | |
c19d1205 ZW |
11004 | /* Remember the current text section. */ |
11005 | unwind.saved_seg = now_seg; | |
11006 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 11007 | |
c19d1205 | 11008 | start_unwind_section (now_seg, 0); |
bfae80f2 | 11009 | |
c19d1205 | 11010 | if (unwind.personality_routine == NULL) |
bfae80f2 | 11011 | { |
c19d1205 ZW |
11012 | if (unwind.personality_index == -2) |
11013 | { | |
11014 | if (have_data) | |
11015 | as_bad (_("handerdata in cantunwind frame")); | |
11016 | return 1; /* EXIDX_CANTUNWIND. */ | |
11017 | } | |
bfae80f2 | 11018 | |
c19d1205 ZW |
11019 | /* Use a default personality routine if none is specified. */ |
11020 | if (unwind.personality_index == -1) | |
11021 | { | |
11022 | if (unwind.opcode_count > 3) | |
11023 | unwind.personality_index = 1; | |
11024 | else | |
11025 | unwind.personality_index = 0; | |
11026 | } | |
bfae80f2 | 11027 | |
c19d1205 ZW |
11028 | /* Space for the personality routine entry. */ |
11029 | if (unwind.personality_index == 0) | |
11030 | { | |
11031 | if (unwind.opcode_count > 3) | |
11032 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 11033 | |
c19d1205 ZW |
11034 | if (!have_data) |
11035 | { | |
11036 | /* All the data is inline in the index table. */ | |
11037 | data = 0x80; | |
11038 | n = 3; | |
11039 | while (unwind.opcode_count > 0) | |
11040 | { | |
11041 | unwind.opcode_count--; | |
11042 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
11043 | n--; | |
11044 | } | |
bfae80f2 | 11045 | |
c19d1205 ZW |
11046 | /* Pad with "finish" opcodes. */ |
11047 | while (n--) | |
11048 | data = (data << 8) | 0xb0; | |
bfae80f2 | 11049 | |
c19d1205 ZW |
11050 | return data; |
11051 | } | |
11052 | size = 0; | |
11053 | } | |
11054 | else | |
11055 | /* We get two opcodes "free" in the first word. */ | |
11056 | size = unwind.opcode_count - 2; | |
11057 | } | |
11058 | else | |
11059 | /* An extra byte is required for the opcode count. */ | |
11060 | size = unwind.opcode_count + 1; | |
bfae80f2 | 11061 | |
c19d1205 ZW |
11062 | size = (size + 3) >> 2; |
11063 | if (size > 0xff) | |
11064 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 11065 | |
c19d1205 ZW |
11066 | frag_align (2, 0, 0); |
11067 | record_alignment (now_seg, 2); | |
11068 | unwind.table_entry = expr_build_dot (); | |
11069 | ||
11070 | /* Allocate the table entry. */ | |
11071 | ptr = frag_more ((size << 2) + 4); | |
11072 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 11073 | |
c19d1205 | 11074 | switch (unwind.personality_index) |
bfae80f2 | 11075 | { |
c19d1205 ZW |
11076 | case -1: |
11077 | /* ??? Should this be a PLT generating relocation? */ | |
11078 | /* Custom personality routine. */ | |
11079 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
11080 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 11081 | |
c19d1205 ZW |
11082 | where += 4; |
11083 | ptr += 4; | |
bfae80f2 | 11084 | |
c19d1205 ZW |
11085 | /* Set the first byte to the number of additional words. */ |
11086 | data = size - 1; | |
11087 | n = 3; | |
11088 | break; | |
bfae80f2 | 11089 | |
c19d1205 ZW |
11090 | /* ABI defined personality routines. */ |
11091 | case 0: | |
11092 | /* Three opcodes bytes are packed into the first word. */ | |
11093 | data = 0x80; | |
11094 | n = 3; | |
11095 | break; | |
bfae80f2 | 11096 | |
c19d1205 ZW |
11097 | case 1: |
11098 | case 2: | |
11099 | /* The size and first two opcode bytes go in the first word. */ | |
11100 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
11101 | n = 2; | |
11102 | break; | |
bfae80f2 | 11103 | |
c19d1205 ZW |
11104 | default: |
11105 | /* Should never happen. */ | |
11106 | abort (); | |
11107 | } | |
bfae80f2 | 11108 | |
c19d1205 ZW |
11109 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
11110 | time. */ | |
11111 | while (unwind.opcode_count > 0) | |
11112 | { | |
11113 | if (n == 0) | |
11114 | { | |
11115 | md_number_to_chars (ptr, data, 4); | |
11116 | ptr += 4; | |
11117 | n = 4; | |
11118 | data = 0; | |
11119 | } | |
11120 | unwind.opcode_count--; | |
11121 | n--; | |
11122 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
11123 | } | |
11124 | ||
11125 | /* Finish off the last word. */ | |
11126 | if (n < 4) | |
11127 | { | |
11128 | /* Pad with "finish" opcodes. */ | |
11129 | while (n--) | |
11130 | data = (data << 8) | 0xb0; | |
11131 | ||
11132 | md_number_to_chars (ptr, data, 4); | |
11133 | } | |
11134 | ||
11135 | if (!have_data) | |
11136 | { | |
11137 | /* Add an empty descriptor if there is no user-specified data. */ | |
11138 | ptr = frag_more (4); | |
11139 | md_number_to_chars (ptr, 0, 4); | |
11140 | } | |
11141 | ||
11142 | return 0; | |
bfae80f2 RE |
11143 | } |
11144 | ||
c19d1205 ZW |
11145 | /* Convert REGNAME to a DWARF-2 register number. */ |
11146 | ||
11147 | int | |
11148 | tc_arm_regname_to_dw2regnum (const char *regname) | |
bfae80f2 | 11149 | { |
c19d1205 ZW |
11150 | int reg = arm_reg_parse ((char **) ®name, REG_TYPE_RN); |
11151 | ||
11152 | if (reg == FAIL) | |
11153 | return -1; | |
11154 | ||
11155 | return reg; | |
bfae80f2 RE |
11156 | } |
11157 | ||
c19d1205 ZW |
11158 | /* Initialize the DWARF-2 unwind information for this procedure. */ |
11159 | ||
11160 | void | |
11161 | tc_arm_frame_initial_instructions (void) | |
bfae80f2 | 11162 | { |
c19d1205 | 11163 | cfi_add_CFA_def_cfa (REG_SP, 0); |
bfae80f2 | 11164 | } |
c19d1205 | 11165 | #endif /* OBJ_ELF */ |
bfae80f2 | 11166 | |
bfae80f2 | 11167 | |
c19d1205 | 11168 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 11169 | |
2fc8bdac ZW |
11170 | /* Return the address within the segment that a PC-relative fixup is |
11171 | relative to. For ARM, PC-relative fixups applied to instructions | |
11172 | are generally relative to the location of the fixup plus 8 bytes. | |
11173 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
11174 | require special handling. */ | |
bfae80f2 | 11175 | |
c19d1205 | 11176 | long |
2fc8bdac | 11177 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 11178 | { |
2fc8bdac ZW |
11179 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
11180 | ||
11181 | /* If this is pc-relative and we are going to emit a relocation | |
11182 | then we just want to put out any pipeline compensation that the linker | |
11183 | will need. Otherwise we want to use the calculated base. */ | |
11184 | if (fixP->fx_pcrel | |
11185 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
11186 | || arm_force_relocation (fixP))) | |
11187 | base = 0; | |
bfae80f2 | 11188 | |
c19d1205 | 11189 | switch (fixP->fx_r_type) |
bfae80f2 | 11190 | { |
2fc8bdac ZW |
11191 | /* PC relative addressing on the Thumb is slightly odd as the |
11192 | bottom two bits of the PC are forced to zero for the | |
11193 | calculation. This happens *after* application of the | |
11194 | pipeline offset. However, Thumb adrl already adjusts for | |
11195 | this, so we need not do it again. */ | |
c19d1205 | 11196 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 11197 | return base & ~3; |
c19d1205 ZW |
11198 | |
11199 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
11200 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 11201 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 11202 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 11203 | return (base + 4) & ~3; |
c19d1205 | 11204 | |
2fc8bdac ZW |
11205 | /* Thumb branches are simply offset by +4. */ |
11206 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
11207 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
11208 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
11209 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
11210 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
11211 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
11212 | case BFD_RELOC_THUMB_PCREL_BLX: | |
11213 | return base + 4; | |
bfae80f2 | 11214 | |
2fc8bdac ZW |
11215 | /* ARM mode branches are offset by +8. However, the Windows CE |
11216 | loader expects the relocation not to take this into account. */ | |
11217 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
39b41c9c PB |
11218 | case BFD_RELOC_ARM_PCREL_CALL: |
11219 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac ZW |
11220 | case BFD_RELOC_ARM_PCREL_BLX: |
11221 | case BFD_RELOC_ARM_PLT32: | |
c19d1205 | 11222 | #ifdef TE_WINCE |
2fc8bdac | 11223 | return base; |
c19d1205 | 11224 | #else |
2fc8bdac | 11225 | return base + 8; |
c19d1205 | 11226 | #endif |
2fc8bdac ZW |
11227 | |
11228 | /* ARM mode loads relative to PC are also offset by +8. Unlike | |
11229 | branches, the Windows CE loader *does* expect the relocation | |
11230 | to take this into account. */ | |
11231 | case BFD_RELOC_ARM_OFFSET_IMM: | |
11232 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
11233 | case BFD_RELOC_ARM_HWLITERAL: | |
11234 | case BFD_RELOC_ARM_LITERAL: | |
11235 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
11236 | return base + 8; | |
11237 | ||
11238 | ||
11239 | /* Other PC-relative relocations are un-offset. */ | |
11240 | default: | |
11241 | return base; | |
11242 | } | |
bfae80f2 RE |
11243 | } |
11244 | ||
c19d1205 ZW |
11245 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
11246 | Otherwise we have no need to default values of symbols. */ | |
11247 | ||
11248 | symbolS * | |
11249 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 11250 | { |
c19d1205 ZW |
11251 | #ifdef OBJ_ELF |
11252 | if (name[0] == '_' && name[1] == 'G' | |
11253 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
11254 | { | |
11255 | if (!GOT_symbol) | |
11256 | { | |
11257 | if (symbol_find (name)) | |
11258 | as_bad ("GOT already in the symbol table"); | |
bfae80f2 | 11259 | |
c19d1205 ZW |
11260 | GOT_symbol = symbol_new (name, undefined_section, |
11261 | (valueT) 0, & zero_address_frag); | |
11262 | } | |
bfae80f2 | 11263 | |
c19d1205 | 11264 | return GOT_symbol; |
bfae80f2 | 11265 | } |
c19d1205 | 11266 | #endif |
bfae80f2 | 11267 | |
c19d1205 | 11268 | return 0; |
bfae80f2 RE |
11269 | } |
11270 | ||
55cf6793 | 11271 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
11272 | computed as two separate immediate values, added together. We |
11273 | already know that this value cannot be computed by just one ARM | |
11274 | instruction. */ | |
11275 | ||
11276 | static unsigned int | |
11277 | validate_immediate_twopart (unsigned int val, | |
11278 | unsigned int * highpart) | |
bfae80f2 | 11279 | { |
c19d1205 ZW |
11280 | unsigned int a; |
11281 | unsigned int i; | |
bfae80f2 | 11282 | |
c19d1205 ZW |
11283 | for (i = 0; i < 32; i += 2) |
11284 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
11285 | { | |
11286 | if (a & 0xff00) | |
11287 | { | |
11288 | if (a & ~ 0xffff) | |
11289 | continue; | |
11290 | * highpart = (a >> 8) | ((i + 24) << 7); | |
11291 | } | |
11292 | else if (a & 0xff0000) | |
11293 | { | |
11294 | if (a & 0xff000000) | |
11295 | continue; | |
11296 | * highpart = (a >> 16) | ((i + 16) << 7); | |
11297 | } | |
11298 | else | |
11299 | { | |
11300 | assert (a & 0xff000000); | |
11301 | * highpart = (a >> 24) | ((i + 8) << 7); | |
11302 | } | |
bfae80f2 | 11303 | |
c19d1205 ZW |
11304 | return (a & 0xff) | (i << 7); |
11305 | } | |
bfae80f2 | 11306 | |
c19d1205 | 11307 | return FAIL; |
bfae80f2 RE |
11308 | } |
11309 | ||
c19d1205 ZW |
11310 | static int |
11311 | validate_offset_imm (unsigned int val, int hwse) | |
11312 | { | |
11313 | if ((hwse && val > 255) || val > 4095) | |
11314 | return FAIL; | |
11315 | return val; | |
11316 | } | |
bfae80f2 | 11317 | |
55cf6793 | 11318 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
11319 | negative immediate constant by altering the instruction. A bit of |
11320 | a hack really. | |
11321 | MOV <-> MVN | |
11322 | AND <-> BIC | |
11323 | ADC <-> SBC | |
11324 | by inverting the second operand, and | |
11325 | ADD <-> SUB | |
11326 | CMP <-> CMN | |
11327 | by negating the second operand. */ | |
bfae80f2 | 11328 | |
c19d1205 ZW |
11329 | static int |
11330 | negate_data_op (unsigned long * instruction, | |
11331 | unsigned long value) | |
bfae80f2 | 11332 | { |
c19d1205 ZW |
11333 | int op, new_inst; |
11334 | unsigned long negated, inverted; | |
bfae80f2 | 11335 | |
c19d1205 ZW |
11336 | negated = encode_arm_immediate (-value); |
11337 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 11338 | |
c19d1205 ZW |
11339 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
11340 | switch (op) | |
bfae80f2 | 11341 | { |
c19d1205 ZW |
11342 | /* First negates. */ |
11343 | case OPCODE_SUB: /* ADD <-> SUB */ | |
11344 | new_inst = OPCODE_ADD; | |
11345 | value = negated; | |
11346 | break; | |
bfae80f2 | 11347 | |
c19d1205 ZW |
11348 | case OPCODE_ADD: |
11349 | new_inst = OPCODE_SUB; | |
11350 | value = negated; | |
11351 | break; | |
bfae80f2 | 11352 | |
c19d1205 ZW |
11353 | case OPCODE_CMP: /* CMP <-> CMN */ |
11354 | new_inst = OPCODE_CMN; | |
11355 | value = negated; | |
11356 | break; | |
bfae80f2 | 11357 | |
c19d1205 ZW |
11358 | case OPCODE_CMN: |
11359 | new_inst = OPCODE_CMP; | |
11360 | value = negated; | |
11361 | break; | |
bfae80f2 | 11362 | |
c19d1205 ZW |
11363 | /* Now Inverted ops. */ |
11364 | case OPCODE_MOV: /* MOV <-> MVN */ | |
11365 | new_inst = OPCODE_MVN; | |
11366 | value = inverted; | |
11367 | break; | |
bfae80f2 | 11368 | |
c19d1205 ZW |
11369 | case OPCODE_MVN: |
11370 | new_inst = OPCODE_MOV; | |
11371 | value = inverted; | |
11372 | break; | |
bfae80f2 | 11373 | |
c19d1205 ZW |
11374 | case OPCODE_AND: /* AND <-> BIC */ |
11375 | new_inst = OPCODE_BIC; | |
11376 | value = inverted; | |
11377 | break; | |
bfae80f2 | 11378 | |
c19d1205 ZW |
11379 | case OPCODE_BIC: |
11380 | new_inst = OPCODE_AND; | |
11381 | value = inverted; | |
11382 | break; | |
bfae80f2 | 11383 | |
c19d1205 ZW |
11384 | case OPCODE_ADC: /* ADC <-> SBC */ |
11385 | new_inst = OPCODE_SBC; | |
11386 | value = inverted; | |
11387 | break; | |
bfae80f2 | 11388 | |
c19d1205 ZW |
11389 | case OPCODE_SBC: |
11390 | new_inst = OPCODE_ADC; | |
11391 | value = inverted; | |
11392 | break; | |
bfae80f2 | 11393 | |
c19d1205 ZW |
11394 | /* We cannot do anything. */ |
11395 | default: | |
11396 | return FAIL; | |
b99bd4ef NC |
11397 | } |
11398 | ||
c19d1205 ZW |
11399 | if (value == (unsigned) FAIL) |
11400 | return FAIL; | |
11401 | ||
11402 | *instruction &= OPCODE_MASK; | |
11403 | *instruction |= new_inst << DATA_OP_SHIFT; | |
11404 | return value; | |
b99bd4ef NC |
11405 | } |
11406 | ||
ef8d22e6 PB |
11407 | /* Like negate_data_op, but for Thumb-2. */ |
11408 | ||
11409 | static unsigned int | |
11410 | thumb32_negate_data_op (offsetT *instruction, offsetT value) | |
11411 | { | |
11412 | int op, new_inst; | |
11413 | int rd; | |
11414 | offsetT negated, inverted; | |
11415 | ||
11416 | negated = encode_thumb32_immediate (-value); | |
11417 | inverted = encode_thumb32_immediate (~value); | |
11418 | ||
11419 | rd = (*instruction >> 8) & 0xf; | |
11420 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
11421 | switch (op) | |
11422 | { | |
11423 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
11424 | case T2_OPCODE_SUB: | |
11425 | new_inst = T2_OPCODE_ADD; | |
11426 | value = negated; | |
11427 | break; | |
11428 | ||
11429 | case T2_OPCODE_ADD: | |
11430 | new_inst = T2_OPCODE_SUB; | |
11431 | value = negated; | |
11432 | break; | |
11433 | ||
11434 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
11435 | case T2_OPCODE_ORR: | |
11436 | new_inst = T2_OPCODE_ORN; | |
11437 | value = inverted; | |
11438 | break; | |
11439 | ||
11440 | case T2_OPCODE_ORN: | |
11441 | new_inst = T2_OPCODE_ORR; | |
11442 | value = inverted; | |
11443 | break; | |
11444 | ||
11445 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
11446 | case T2_OPCODE_AND: | |
11447 | new_inst = T2_OPCODE_BIC; | |
11448 | if (rd == 15) | |
11449 | value = FAIL; | |
11450 | else | |
11451 | value = inverted; | |
11452 | break; | |
11453 | ||
11454 | case T2_OPCODE_BIC: | |
11455 | new_inst = T2_OPCODE_AND; | |
11456 | value = inverted; | |
11457 | break; | |
11458 | ||
11459 | /* ADC <-> SBC */ | |
11460 | case T2_OPCODE_ADC: | |
11461 | new_inst = T2_OPCODE_SBC; | |
11462 | value = inverted; | |
11463 | break; | |
11464 | ||
11465 | case T2_OPCODE_SBC: | |
11466 | new_inst = T2_OPCODE_ADC; | |
11467 | value = inverted; | |
11468 | break; | |
11469 | ||
11470 | /* We cannot do anything. */ | |
11471 | default: | |
11472 | return FAIL; | |
11473 | } | |
11474 | ||
11475 | if (value == FAIL) | |
11476 | return FAIL; | |
11477 | ||
11478 | *instruction &= T2_OPCODE_MASK; | |
11479 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
11480 | return value; | |
11481 | } | |
11482 | ||
8f06b2d8 PB |
11483 | /* Read a 32-bit thumb instruction from buf. */ |
11484 | static unsigned long | |
11485 | get_thumb32_insn (char * buf) | |
11486 | { | |
11487 | unsigned long insn; | |
11488 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
11489 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
11490 | ||
11491 | return insn; | |
11492 | } | |
11493 | ||
c19d1205 | 11494 | void |
55cf6793 | 11495 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
11496 | valueT * valP, |
11497 | segT seg) | |
11498 | { | |
11499 | offsetT value = * valP; | |
11500 | offsetT newval; | |
11501 | unsigned int newimm; | |
11502 | unsigned long temp; | |
11503 | int sign; | |
11504 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 11505 | |
c19d1205 | 11506 | assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 11507 | |
c19d1205 ZW |
11508 | /* Note whether this will delete the relocation. */ |
11509 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) | |
11510 | fixP->fx_done = 1; | |
b99bd4ef | 11511 | |
adbaf948 ZW |
11512 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
11513 | consistency with the behavior on 32-bit hosts. Remember value | |
11514 | for emit_reloc. */ | |
11515 | value &= 0xffffffff; | |
11516 | value ^= 0x80000000; | |
11517 | value -= 0x80000000; | |
11518 | ||
11519 | *valP = value; | |
c19d1205 | 11520 | fixP->fx_addnumber = value; |
b99bd4ef | 11521 | |
adbaf948 ZW |
11522 | /* Same treatment for fixP->fx_offset. */ |
11523 | fixP->fx_offset &= 0xffffffff; | |
11524 | fixP->fx_offset ^= 0x80000000; | |
11525 | fixP->fx_offset -= 0x80000000; | |
11526 | ||
c19d1205 | 11527 | switch (fixP->fx_r_type) |
b99bd4ef | 11528 | { |
c19d1205 ZW |
11529 | case BFD_RELOC_NONE: |
11530 | /* This will need to go in the object file. */ | |
11531 | fixP->fx_done = 0; | |
11532 | break; | |
b99bd4ef | 11533 | |
c19d1205 ZW |
11534 | case BFD_RELOC_ARM_IMMEDIATE: |
11535 | /* We claim that this fixup has been processed here, | |
11536 | even if in fact we generate an error because we do | |
11537 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
11538 | fixP->fx_done = 1; | |
b99bd4ef | 11539 | |
c19d1205 ZW |
11540 | if (fixP->fx_addsy |
11541 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 11542 | { |
c19d1205 ZW |
11543 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11544 | _("undefined symbol %s used as an immediate value"), | |
11545 | S_GET_NAME (fixP->fx_addsy)); | |
11546 | break; | |
b99bd4ef NC |
11547 | } |
11548 | ||
c19d1205 ZW |
11549 | newimm = encode_arm_immediate (value); |
11550 | temp = md_chars_to_number (buf, INSN_SIZE); | |
11551 | ||
11552 | /* If the instruction will fail, see if we can fix things up by | |
11553 | changing the opcode. */ | |
11554 | if (newimm == (unsigned int) FAIL | |
11555 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 11556 | { |
c19d1205 ZW |
11557 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11558 | _("invalid constant (%lx) after fixup"), | |
11559 | (unsigned long) value); | |
11560 | break; | |
b99bd4ef | 11561 | } |
b99bd4ef | 11562 | |
c19d1205 ZW |
11563 | newimm |= (temp & 0xfffff000); |
11564 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
11565 | break; | |
b99bd4ef | 11566 | |
c19d1205 ZW |
11567 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
11568 | { | |
11569 | unsigned int highpart = 0; | |
11570 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 11571 | |
c19d1205 ZW |
11572 | newimm = encode_arm_immediate (value); |
11573 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 11574 | |
c19d1205 ZW |
11575 | /* If the instruction will fail, see if we can fix things up by |
11576 | changing the opcode. */ | |
11577 | if (newimm == (unsigned int) FAIL | |
11578 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
11579 | { | |
11580 | /* No ? OK - try using two ADD instructions to generate | |
11581 | the value. */ | |
11582 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 11583 | |
c19d1205 ZW |
11584 | /* Yes - then make sure that the second instruction is |
11585 | also an add. */ | |
11586 | if (newimm != (unsigned int) FAIL) | |
11587 | newinsn = temp; | |
11588 | /* Still No ? Try using a negated value. */ | |
11589 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
11590 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
11591 | /* Otherwise - give up. */ | |
11592 | else | |
11593 | { | |
11594 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11595 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
11596 | (long) value); | |
11597 | break; | |
11598 | } | |
b99bd4ef | 11599 | |
c19d1205 ZW |
11600 | /* Replace the first operand in the 2nd instruction (which |
11601 | is the PC) with the destination register. We have | |
11602 | already added in the PC in the first instruction and we | |
11603 | do not want to do it again. */ | |
11604 | newinsn &= ~ 0xf0000; | |
11605 | newinsn |= ((newinsn & 0x0f000) << 4); | |
11606 | } | |
b99bd4ef | 11607 | |
c19d1205 ZW |
11608 | newimm |= (temp & 0xfffff000); |
11609 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 11610 | |
c19d1205 ZW |
11611 | highpart |= (newinsn & 0xfffff000); |
11612 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
11613 | } | |
11614 | break; | |
b99bd4ef | 11615 | |
c19d1205 | 11616 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
11617 | if (!fixP->fx_done && seg->use_rela_p) |
11618 | value = 0; | |
11619 | ||
c19d1205 ZW |
11620 | case BFD_RELOC_ARM_LITERAL: |
11621 | sign = value >= 0; | |
b99bd4ef | 11622 | |
c19d1205 ZW |
11623 | if (value < 0) |
11624 | value = - value; | |
b99bd4ef | 11625 | |
c19d1205 | 11626 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 11627 | { |
c19d1205 ZW |
11628 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
11629 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11630 | _("invalid literal constant: pool needs to be closer")); | |
11631 | else | |
11632 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11633 | _("bad immediate value for offset (%ld)"), | |
11634 | (long) value); | |
11635 | break; | |
f03698e6 RE |
11636 | } |
11637 | ||
c19d1205 ZW |
11638 | newval = md_chars_to_number (buf, INSN_SIZE); |
11639 | newval &= 0xff7ff000; | |
11640 | newval |= value | (sign ? INDEX_UP : 0); | |
11641 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11642 | break; | |
b99bd4ef | 11643 | |
c19d1205 ZW |
11644 | case BFD_RELOC_ARM_OFFSET_IMM8: |
11645 | case BFD_RELOC_ARM_HWLITERAL: | |
11646 | sign = value >= 0; | |
b99bd4ef | 11647 | |
c19d1205 ZW |
11648 | if (value < 0) |
11649 | value = - value; | |
b99bd4ef | 11650 | |
c19d1205 | 11651 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 11652 | { |
c19d1205 ZW |
11653 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
11654 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11655 | _("invalid literal constant: pool needs to be closer")); | |
11656 | else | |
11657 | as_bad (_("bad immediate value for half-word offset (%ld)"), | |
11658 | (long) value); | |
11659 | break; | |
b99bd4ef NC |
11660 | } |
11661 | ||
c19d1205 ZW |
11662 | newval = md_chars_to_number (buf, INSN_SIZE); |
11663 | newval &= 0xff7ff0f0; | |
11664 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
11665 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11666 | break; | |
b99bd4ef | 11667 | |
c19d1205 ZW |
11668 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
11669 | if (value < 0 || value > 1020 || value % 4 != 0) | |
11670 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11671 | _("bad immediate value for offset (%ld)"), (long) value); | |
11672 | value /= 4; | |
b99bd4ef | 11673 | |
c19d1205 | 11674 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
11675 | newval |= value; |
11676 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
11677 | break; | |
b99bd4ef | 11678 | |
c19d1205 ZW |
11679 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
11680 | /* This is a complicated relocation used for all varieties of Thumb32 | |
11681 | load/store instruction with immediate offset: | |
11682 | ||
11683 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
11684 | *4, optional writeback(W) | |
11685 | (doubleword load/store) | |
11686 | ||
11687 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
11688 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
11689 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
11690 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
11691 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
11692 | ||
11693 | Uppercase letters indicate bits that are already encoded at | |
11694 | this point. Lowercase letters are our problem. For the | |
11695 | second block of instructions, the secondary opcode nybble | |
11696 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
11697 | a PC-relative operation. */ | |
11698 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11699 | newval <<= 16; | |
11700 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 11701 | |
c19d1205 | 11702 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 11703 | { |
c19d1205 ZW |
11704 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
11705 | if (value >= 0) | |
11706 | newval |= (1 << 23); | |
11707 | else | |
11708 | value = -value; | |
11709 | if (value % 4 != 0) | |
11710 | { | |
11711 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11712 | _("offset not a multiple of 4")); | |
11713 | break; | |
11714 | } | |
11715 | value /= 4; | |
216d22bc | 11716 | if (value > 0xff) |
c19d1205 ZW |
11717 | { |
11718 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11719 | _("offset out of range")); | |
11720 | break; | |
11721 | } | |
11722 | newval &= ~0xff; | |
b99bd4ef | 11723 | } |
c19d1205 | 11724 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 11725 | { |
c19d1205 ZW |
11726 | /* PC-relative, 12-bit offset. */ |
11727 | if (value >= 0) | |
11728 | newval |= (1 << 23); | |
11729 | else | |
11730 | value = -value; | |
216d22bc | 11731 | if (value > 0xfff) |
c19d1205 ZW |
11732 | { |
11733 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11734 | _("offset out of range")); | |
11735 | break; | |
11736 | } | |
11737 | newval &= ~0xfff; | |
b99bd4ef | 11738 | } |
c19d1205 | 11739 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 11740 | { |
c19d1205 ZW |
11741 | /* Writeback: 8-bit, +/- offset. */ |
11742 | if (value >= 0) | |
11743 | newval |= (1 << 9); | |
11744 | else | |
11745 | value = -value; | |
216d22bc | 11746 | if (value > 0xff) |
c19d1205 ZW |
11747 | { |
11748 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11749 | _("offset out of range")); | |
11750 | break; | |
11751 | } | |
11752 | newval &= ~0xff; | |
b99bd4ef | 11753 | } |
c19d1205 | 11754 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 11755 | { |
c19d1205 | 11756 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 11757 | if (value < 0 || value > 0xff) |
b99bd4ef | 11758 | { |
c19d1205 ZW |
11759 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11760 | _("offset out of range")); | |
11761 | break; | |
b99bd4ef | 11762 | } |
c19d1205 ZW |
11763 | newval &= ~0xff; |
11764 | newval |= value; | |
b99bd4ef NC |
11765 | } |
11766 | else | |
b99bd4ef | 11767 | { |
c19d1205 ZW |
11768 | /* Positive 12-bit or negative 8-bit offset. */ |
11769 | int limit; | |
11770 | if (value >= 0) | |
b99bd4ef | 11771 | { |
c19d1205 ZW |
11772 | newval |= (1 << 23); |
11773 | limit = 0xfff; | |
11774 | } | |
11775 | else | |
11776 | { | |
11777 | value = -value; | |
11778 | limit = 0xff; | |
11779 | } | |
11780 | if (value > limit) | |
11781 | { | |
11782 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11783 | _("offset out of range")); | |
11784 | break; | |
b99bd4ef | 11785 | } |
c19d1205 | 11786 | newval &= ~limit; |
b99bd4ef | 11787 | } |
b99bd4ef | 11788 | |
c19d1205 ZW |
11789 | newval |= value; |
11790 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
11791 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
11792 | break; | |
404ff6b5 | 11793 | |
c19d1205 ZW |
11794 | case BFD_RELOC_ARM_SHIFT_IMM: |
11795 | newval = md_chars_to_number (buf, INSN_SIZE); | |
11796 | if (((unsigned long) value) > 32 | |
11797 | || (value == 32 | |
11798 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
11799 | { | |
11800 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11801 | _("shift expression is too large")); | |
11802 | break; | |
11803 | } | |
404ff6b5 | 11804 | |
c19d1205 ZW |
11805 | if (value == 0) |
11806 | /* Shifts of zero must be done as lsl. */ | |
11807 | newval &= ~0x60; | |
11808 | else if (value == 32) | |
11809 | value = 0; | |
11810 | newval &= 0xfffff07f; | |
11811 | newval |= (value & 0x1f) << 7; | |
11812 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11813 | break; | |
404ff6b5 | 11814 | |
c19d1205 | 11815 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
92e90b6e | 11816 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 11817 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
11818 | /* We claim that this fixup has been processed here, |
11819 | even if in fact we generate an error because we do | |
11820 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
11821 | fixP->fx_done = 1; | |
404ff6b5 | 11822 | |
c19d1205 ZW |
11823 | if (fixP->fx_addsy |
11824 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
11825 | { | |
11826 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11827 | _("undefined symbol %s used as an immediate value"), | |
11828 | S_GET_NAME (fixP->fx_addsy)); | |
11829 | break; | |
11830 | } | |
404ff6b5 | 11831 | |
c19d1205 ZW |
11832 | newval = md_chars_to_number (buf, THUMB_SIZE); |
11833 | newval <<= 16; | |
11834 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 11835 | |
e9f89963 PB |
11836 | /* FUTURE: Implement analogue of negate_data_op for T32. */ |
11837 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE) | |
ef8d22e6 PB |
11838 | { |
11839 | newimm = encode_thumb32_immediate (value); | |
11840 | if (newimm == (unsigned int) FAIL) | |
11841 | newimm = thumb32_negate_data_op (&newval, value); | |
11842 | } | |
e9f89963 | 11843 | else |
92e90b6e | 11844 | { |
e9f89963 PB |
11845 | /* 12 bit immediate for addw/subw. */ |
11846 | if (value < 0) | |
11847 | { | |
11848 | value = -value; | |
11849 | newval ^= 0x00a00000; | |
11850 | } | |
92e90b6e PB |
11851 | if (value > 0xfff) |
11852 | newimm = (unsigned int) FAIL; | |
11853 | else | |
11854 | newimm = value; | |
11855 | } | |
cc8a6dd0 | 11856 | |
c19d1205 | 11857 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 11858 | { |
c19d1205 ZW |
11859 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11860 | _("invalid constant (%lx) after fixup"), | |
11861 | (unsigned long) value); | |
11862 | break; | |
3631a3c8 NC |
11863 | } |
11864 | ||
c19d1205 ZW |
11865 | newval |= (newimm & 0x800) << 15; |
11866 | newval |= (newimm & 0x700) << 4; | |
11867 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 11868 | |
c19d1205 ZW |
11869 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
11870 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
11871 | break; | |
a737bd4d | 11872 | |
3eb17e6b | 11873 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
11874 | if (((unsigned long) value) > 0xffff) |
11875 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 11876 | _("invalid smc expression")); |
2fc8bdac | 11877 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
11878 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
11879 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11880 | break; | |
a737bd4d | 11881 | |
c19d1205 | 11882 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 11883 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
11884 | { |
11885 | if (((unsigned long) value) > 0xff) | |
11886 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11887 | _("invalid swi expression")); | |
2fc8bdac | 11888 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
11889 | newval |= value; |
11890 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11891 | } | |
11892 | else | |
11893 | { | |
11894 | if (((unsigned long) value) > 0x00ffffff) | |
11895 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11896 | _("invalid swi expression")); | |
2fc8bdac | 11897 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
11898 | newval |= value; |
11899 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11900 | } | |
11901 | break; | |
a737bd4d | 11902 | |
c19d1205 ZW |
11903 | case BFD_RELOC_ARM_MULTI: |
11904 | if (((unsigned long) value) > 0xffff) | |
11905 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11906 | _("invalid expression in load/store multiple")); | |
11907 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
11908 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11909 | break; | |
a737bd4d | 11910 | |
c19d1205 | 11911 | #ifdef OBJ_ELF |
39b41c9c PB |
11912 | case BFD_RELOC_ARM_PCREL_CALL: |
11913 | newval = md_chars_to_number (buf, INSN_SIZE); | |
11914 | if ((newval & 0xf0000000) == 0xf0000000) | |
11915 | temp = 1; | |
11916 | else | |
11917 | temp = 3; | |
11918 | goto arm_branch_common; | |
11919 | ||
11920 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac | 11921 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 11922 | #endif |
39b41c9c PB |
11923 | case BFD_RELOC_ARM_PCREL_BRANCH: |
11924 | temp = 3; | |
11925 | goto arm_branch_common; | |
a737bd4d | 11926 | |
39b41c9c PB |
11927 | case BFD_RELOC_ARM_PCREL_BLX: |
11928 | temp = 1; | |
11929 | arm_branch_common: | |
c19d1205 | 11930 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
11931 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
11932 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
11933 | also be be clear. */ | |
11934 | if (value & temp) | |
c19d1205 | 11935 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
11936 | _("misaligned branch destination")); |
11937 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
11938 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
11939 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11940 | _("branch out of range")); | |
a737bd4d | 11941 | |
2fc8bdac | 11942 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 11943 | { |
2fc8bdac ZW |
11944 | newval = md_chars_to_number (buf, INSN_SIZE); |
11945 | newval |= (value >> 2) & 0x00ffffff; | |
7ae2971b PB |
11946 | /* Set the H bit on BLX instructions. */ |
11947 | if (temp == 1) | |
11948 | { | |
11949 | if (value & 2) | |
11950 | newval |= 0x01000000; | |
11951 | else | |
11952 | newval &= ~0x01000000; | |
11953 | } | |
2fc8bdac | 11954 | md_number_to_chars (buf, newval, INSN_SIZE); |
c19d1205 | 11955 | } |
c19d1205 | 11956 | break; |
a737bd4d | 11957 | |
c19d1205 | 11958 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */ |
2fc8bdac ZW |
11959 | /* CZB can only branch forward. */ |
11960 | if (value & ~0x7e) | |
11961 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11962 | _("branch out of range")); | |
a737bd4d | 11963 | |
2fc8bdac ZW |
11964 | if (fixP->fx_done || !seg->use_rela_p) |
11965 | { | |
11966 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
080eb7fe | 11967 | newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3); |
2fc8bdac ZW |
11968 | md_number_to_chars (buf, newval, THUMB_SIZE); |
11969 | } | |
c19d1205 | 11970 | break; |
a737bd4d | 11971 | |
c19d1205 | 11972 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
11973 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
11974 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11975 | _("branch out of range")); | |
a737bd4d | 11976 | |
2fc8bdac ZW |
11977 | if (fixP->fx_done || !seg->use_rela_p) |
11978 | { | |
11979 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11980 | newval |= (value & 0x1ff) >> 1; | |
11981 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11982 | } | |
c19d1205 | 11983 | break; |
a737bd4d | 11984 | |
c19d1205 | 11985 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
11986 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
11987 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11988 | _("branch out of range")); | |
a737bd4d | 11989 | |
2fc8bdac ZW |
11990 | if (fixP->fx_done || !seg->use_rela_p) |
11991 | { | |
11992 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11993 | newval |= (value & 0xfff) >> 1; | |
11994 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11995 | } | |
c19d1205 | 11996 | break; |
a737bd4d | 11997 | |
c19d1205 | 11998 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
2fc8bdac ZW |
11999 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
12000 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12001 | _("conditional branch out of range")); | |
404ff6b5 | 12002 | |
2fc8bdac ZW |
12003 | if (fixP->fx_done || !seg->use_rela_p) |
12004 | { | |
12005 | offsetT newval2; | |
12006 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 12007 | |
2fc8bdac ZW |
12008 | S = (value & 0x00100000) >> 20; |
12009 | J2 = (value & 0x00080000) >> 19; | |
12010 | J1 = (value & 0x00040000) >> 18; | |
12011 | hi = (value & 0x0003f000) >> 12; | |
12012 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 12013 | |
2fc8bdac ZW |
12014 | newval = md_chars_to_number (buf, THUMB_SIZE); |
12015 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
12016 | newval |= (S << 10) | hi; | |
12017 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
12018 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12019 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
12020 | } | |
c19d1205 | 12021 | break; |
6c43fab6 | 12022 | |
c19d1205 ZW |
12023 | case BFD_RELOC_THUMB_PCREL_BLX: |
12024 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
2fc8bdac ZW |
12025 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
12026 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12027 | _("branch out of range")); | |
404ff6b5 | 12028 | |
2fc8bdac ZW |
12029 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
12030 | /* For a BLX instruction, make sure that the relocation is rounded up | |
12031 | to a word boundary. This follows the semantics of the instruction | |
12032 | which specifies that bit 1 of the target address will come from bit | |
12033 | 1 of the base address. */ | |
12034 | value = (value + 1) & ~ 1; | |
404ff6b5 | 12035 | |
2fc8bdac | 12036 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 12037 | { |
2fc8bdac ZW |
12038 | offsetT newval2; |
12039 | ||
12040 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
12041 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
12042 | newval |= (value & 0x7fffff) >> 12; | |
12043 | newval2 |= (value & 0xfff) >> 1; | |
12044 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12045 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 12046 | } |
c19d1205 | 12047 | break; |
404ff6b5 | 12048 | |
c19d1205 | 12049 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
12050 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
12051 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12052 | _("branch out of range")); | |
6c43fab6 | 12053 | |
2fc8bdac ZW |
12054 | if (fixP->fx_done || !seg->use_rela_p) |
12055 | { | |
12056 | offsetT newval2; | |
12057 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 12058 | |
2fc8bdac ZW |
12059 | S = (value & 0x01000000) >> 24; |
12060 | I1 = (value & 0x00800000) >> 23; | |
12061 | I2 = (value & 0x00400000) >> 22; | |
12062 | hi = (value & 0x003ff000) >> 12; | |
12063 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 12064 | |
2fc8bdac ZW |
12065 | I1 = !(I1 ^ S); |
12066 | I2 = !(I2 ^ S); | |
a737bd4d | 12067 | |
2fc8bdac ZW |
12068 | newval = md_chars_to_number (buf, THUMB_SIZE); |
12069 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
12070 | newval |= (S << 10) | hi; | |
12071 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
12072 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12073 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
12074 | } | |
12075 | break; | |
a737bd4d | 12076 | |
2fc8bdac ZW |
12077 | case BFD_RELOC_8: |
12078 | if (fixP->fx_done || !seg->use_rela_p) | |
12079 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 12080 | break; |
a737bd4d | 12081 | |
c19d1205 | 12082 | case BFD_RELOC_16: |
2fc8bdac | 12083 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 12084 | md_number_to_chars (buf, value, 2); |
c19d1205 | 12085 | break; |
a737bd4d | 12086 | |
c19d1205 ZW |
12087 | #ifdef OBJ_ELF |
12088 | case BFD_RELOC_ARM_TLS_GD32: | |
12089 | case BFD_RELOC_ARM_TLS_LE32: | |
12090 | case BFD_RELOC_ARM_TLS_IE32: | |
12091 | case BFD_RELOC_ARM_TLS_LDM32: | |
12092 | case BFD_RELOC_ARM_TLS_LDO32: | |
12093 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
12094 | /* fall through */ | |
6c43fab6 | 12095 | |
c19d1205 ZW |
12096 | case BFD_RELOC_ARM_GOT32: |
12097 | case BFD_RELOC_ARM_GOTOFF: | |
12098 | case BFD_RELOC_ARM_TARGET2: | |
2fc8bdac ZW |
12099 | if (fixP->fx_done || !seg->use_rela_p) |
12100 | md_number_to_chars (buf, 0, 4); | |
c19d1205 ZW |
12101 | break; |
12102 | #endif | |
6c43fab6 | 12103 | |
c19d1205 ZW |
12104 | case BFD_RELOC_RVA: |
12105 | case BFD_RELOC_32: | |
12106 | case BFD_RELOC_ARM_TARGET1: | |
12107 | case BFD_RELOC_ARM_ROSEGREL32: | |
12108 | case BFD_RELOC_ARM_SBREL32: | |
12109 | case BFD_RELOC_32_PCREL: | |
2fc8bdac | 12110 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 12111 | md_number_to_chars (buf, value, 4); |
c19d1205 | 12112 | break; |
6c43fab6 | 12113 | |
c19d1205 ZW |
12114 | #ifdef OBJ_ELF |
12115 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 12116 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
12117 | { |
12118 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
12119 | if ((value ^ (value >> 1)) & 0x40000000) | |
12120 | { | |
12121 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12122 | _("rel31 relocation overflow")); | |
12123 | } | |
12124 | newval |= value & 0x7fffffff; | |
12125 | md_number_to_chars (buf, newval, 4); | |
12126 | } | |
12127 | break; | |
c19d1205 | 12128 | #endif |
a737bd4d | 12129 | |
c19d1205 | 12130 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 12131 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
12132 | if (value < -1023 || value > 1023 || (value & 3)) |
12133 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12134 | _("co-processor offset out of range")); | |
12135 | cp_off_common: | |
12136 | sign = value >= 0; | |
12137 | if (value < 0) | |
12138 | value = -value; | |
8f06b2d8 PB |
12139 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
12140 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
12141 | newval = md_chars_to_number (buf, INSN_SIZE); | |
12142 | else | |
12143 | newval = get_thumb32_insn (buf); | |
12144 | newval &= 0xff7fff00; | |
c19d1205 ZW |
12145 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
12146 | if (value == 0) | |
12147 | newval &= ~WRITE_BACK; | |
8f06b2d8 PB |
12148 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
12149 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
12150 | md_number_to_chars (buf, newval, INSN_SIZE); | |
12151 | else | |
12152 | put_thumb32_insn (buf, newval); | |
c19d1205 | 12153 | break; |
a737bd4d | 12154 | |
c19d1205 | 12155 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 12156 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
12157 | if (value < -255 || value > 255) |
12158 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12159 | _("co-processor offset out of range")); | |
12160 | goto cp_off_common; | |
6c43fab6 | 12161 | |
c19d1205 ZW |
12162 | case BFD_RELOC_ARM_THUMB_OFFSET: |
12163 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
12164 | /* Exactly what ranges, and where the offset is inserted depends | |
12165 | on the type of instruction, we can establish this from the | |
12166 | top 4 bits. */ | |
12167 | switch (newval >> 12) | |
12168 | { | |
12169 | case 4: /* PC load. */ | |
12170 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
12171 | forced to zero for these loads; md_pcrel_from has already | |
12172 | compensated for this. */ | |
12173 | if (value & 3) | |
12174 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12175 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
12176 | (((unsigned long) fixP->fx_frag->fr_address |
12177 | + (unsigned long) fixP->fx_where) & ~3) | |
12178 | + (unsigned long) value); | |
a737bd4d | 12179 | |
c19d1205 ZW |
12180 | if (value & ~0x3fc) |
12181 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12182 | _("invalid offset, value too big (0x%08lX)"), | |
12183 | (long) value); | |
a737bd4d | 12184 | |
c19d1205 ZW |
12185 | newval |= value >> 2; |
12186 | break; | |
a737bd4d | 12187 | |
c19d1205 ZW |
12188 | case 9: /* SP load/store. */ |
12189 | if (value & ~0x3fc) | |
12190 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12191 | _("invalid offset, value too big (0x%08lX)"), | |
12192 | (long) value); | |
12193 | newval |= value >> 2; | |
12194 | break; | |
6c43fab6 | 12195 | |
c19d1205 ZW |
12196 | case 6: /* Word load/store. */ |
12197 | if (value & ~0x7c) | |
12198 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12199 | _("invalid offset, value too big (0x%08lX)"), | |
12200 | (long) value); | |
12201 | newval |= value << 4; /* 6 - 2. */ | |
12202 | break; | |
a737bd4d | 12203 | |
c19d1205 ZW |
12204 | case 7: /* Byte load/store. */ |
12205 | if (value & ~0x1f) | |
12206 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12207 | _("invalid offset, value too big (0x%08lX)"), | |
12208 | (long) value); | |
12209 | newval |= value << 6; | |
12210 | break; | |
a737bd4d | 12211 | |
c19d1205 ZW |
12212 | case 8: /* Halfword load/store. */ |
12213 | if (value & ~0x3e) | |
12214 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12215 | _("invalid offset, value too big (0x%08lX)"), | |
12216 | (long) value); | |
12217 | newval |= value << 5; /* 6 - 1. */ | |
12218 | break; | |
a737bd4d | 12219 | |
c19d1205 ZW |
12220 | default: |
12221 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12222 | "Unable to process relocation for thumb opcode: %lx", | |
12223 | (unsigned long) newval); | |
12224 | break; | |
12225 | } | |
12226 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12227 | break; | |
a737bd4d | 12228 | |
c19d1205 ZW |
12229 | case BFD_RELOC_ARM_THUMB_ADD: |
12230 | /* This is a complicated relocation, since we use it for all of | |
12231 | the following immediate relocations: | |
a737bd4d | 12232 | |
c19d1205 ZW |
12233 | 3bit ADD/SUB |
12234 | 8bit ADD/SUB | |
12235 | 9bit ADD/SUB SP word-aligned | |
12236 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 12237 | |
c19d1205 ZW |
12238 | The type of instruction being processed is encoded in the |
12239 | instruction field: | |
a737bd4d | 12240 | |
c19d1205 ZW |
12241 | 0x8000 SUB |
12242 | 0x00F0 Rd | |
12243 | 0x000F Rs | |
12244 | */ | |
12245 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
12246 | { | |
12247 | int rd = (newval >> 4) & 0xf; | |
12248 | int rs = newval & 0xf; | |
12249 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 12250 | |
c19d1205 ZW |
12251 | /* Check for HI regs, only very restricted cases allowed: |
12252 | Adjusting SP, and using PC or SP to get an address. */ | |
12253 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
12254 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
12255 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12256 | _("invalid Hi register with immediate")); | |
a737bd4d | 12257 | |
c19d1205 ZW |
12258 | /* If value is negative, choose the opposite instruction. */ |
12259 | if (value < 0) | |
12260 | { | |
12261 | value = -value; | |
12262 | subtract = !subtract; | |
12263 | if (value < 0) | |
12264 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12265 | _("immediate value out of range")); | |
12266 | } | |
a737bd4d | 12267 | |
c19d1205 ZW |
12268 | if (rd == REG_SP) |
12269 | { | |
12270 | if (value & ~0x1fc) | |
12271 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12272 | _("invalid immediate for stack address calculation")); | |
12273 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
12274 | newval |= value >> 2; | |
12275 | } | |
12276 | else if (rs == REG_PC || rs == REG_SP) | |
12277 | { | |
12278 | if (subtract || value & ~0x3fc) | |
12279 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12280 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
12281 | (unsigned long) value); | |
12282 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
12283 | newval |= rd << 8; | |
12284 | newval |= value >> 2; | |
12285 | } | |
12286 | else if (rs == rd) | |
12287 | { | |
12288 | if (value & ~0xff) | |
12289 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12290 | _("immediate value out of range")); | |
12291 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
12292 | newval |= (rd << 8) | value; | |
12293 | } | |
12294 | else | |
12295 | { | |
12296 | if (value & ~0x7) | |
12297 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12298 | _("immediate value out of range")); | |
12299 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
12300 | newval |= rd | (rs << 3) | (value << 6); | |
12301 | } | |
12302 | } | |
12303 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12304 | break; | |
a737bd4d | 12305 | |
c19d1205 ZW |
12306 | case BFD_RELOC_ARM_THUMB_IMM: |
12307 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
12308 | if (value < 0 || value > 255) | |
12309 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12310 | _("invalid immediate: %ld is too large"), | |
12311 | (long) value); | |
12312 | newval |= value; | |
12313 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12314 | break; | |
a737bd4d | 12315 | |
c19d1205 ZW |
12316 | case BFD_RELOC_ARM_THUMB_SHIFT: |
12317 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
12318 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
12319 | temp = newval & 0xf800; | |
12320 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
12321 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12322 | _("invalid shift value: %ld"), (long) value); | |
12323 | /* Shifts of zero must be encoded as LSL. */ | |
12324 | if (value == 0) | |
12325 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
12326 | /* Shifts of 32 are encoded as zero. */ | |
12327 | else if (value == 32) | |
12328 | value = 0; | |
12329 | newval |= value << 6; | |
12330 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12331 | break; | |
a737bd4d | 12332 | |
c19d1205 ZW |
12333 | case BFD_RELOC_VTABLE_INHERIT: |
12334 | case BFD_RELOC_VTABLE_ENTRY: | |
12335 | fixP->fx_done = 0; | |
12336 | return; | |
6c43fab6 | 12337 | |
c19d1205 ZW |
12338 | case BFD_RELOC_UNUSED: |
12339 | default: | |
12340 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12341 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
12342 | } | |
6c43fab6 RE |
12343 | } |
12344 | ||
c19d1205 ZW |
12345 | /* Translate internal representation of relocation info to BFD target |
12346 | format. */ | |
a737bd4d | 12347 | |
c19d1205 | 12348 | arelent * |
00a97672 | 12349 | tc_gen_reloc (asection *section, fixS *fixp) |
a737bd4d | 12350 | { |
c19d1205 ZW |
12351 | arelent * reloc; |
12352 | bfd_reloc_code_real_type code; | |
a737bd4d | 12353 | |
c19d1205 | 12354 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 12355 | |
c19d1205 ZW |
12356 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
12357 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
12358 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 12359 | |
2fc8bdac | 12360 | if (fixp->fx_pcrel) |
00a97672 RS |
12361 | { |
12362 | if (section->use_rela_p) | |
12363 | fixp->fx_offset -= md_pcrel_from_section (fixp, section); | |
12364 | else | |
12365 | fixp->fx_offset = reloc->address; | |
12366 | } | |
c19d1205 | 12367 | reloc->addend = fixp->fx_offset; |
a737bd4d | 12368 | |
c19d1205 | 12369 | switch (fixp->fx_r_type) |
a737bd4d | 12370 | { |
c19d1205 ZW |
12371 | case BFD_RELOC_8: |
12372 | if (fixp->fx_pcrel) | |
12373 | { | |
12374 | code = BFD_RELOC_8_PCREL; | |
12375 | break; | |
12376 | } | |
a737bd4d | 12377 | |
c19d1205 ZW |
12378 | case BFD_RELOC_16: |
12379 | if (fixp->fx_pcrel) | |
12380 | { | |
12381 | code = BFD_RELOC_16_PCREL; | |
12382 | break; | |
12383 | } | |
6c43fab6 | 12384 | |
c19d1205 ZW |
12385 | case BFD_RELOC_32: |
12386 | if (fixp->fx_pcrel) | |
12387 | { | |
12388 | code = BFD_RELOC_32_PCREL; | |
12389 | break; | |
12390 | } | |
a737bd4d | 12391 | |
c19d1205 ZW |
12392 | case BFD_RELOC_NONE: |
12393 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
12394 | case BFD_RELOC_ARM_PCREL_BLX: | |
12395 | case BFD_RELOC_RVA: | |
12396 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
12397 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
12398 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
12399 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
12400 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
12401 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
12402 | case BFD_RELOC_THUMB_PCREL_BLX: | |
12403 | case BFD_RELOC_VTABLE_ENTRY: | |
12404 | case BFD_RELOC_VTABLE_INHERIT: | |
12405 | code = fixp->fx_r_type; | |
12406 | break; | |
a737bd4d | 12407 | |
c19d1205 ZW |
12408 | case BFD_RELOC_ARM_LITERAL: |
12409 | case BFD_RELOC_ARM_HWLITERAL: | |
12410 | /* If this is called then the a literal has | |
12411 | been referenced across a section boundary. */ | |
12412 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12413 | _("literal referenced across section boundary")); | |
12414 | return NULL; | |
a737bd4d | 12415 | |
c19d1205 ZW |
12416 | #ifdef OBJ_ELF |
12417 | case BFD_RELOC_ARM_GOT32: | |
12418 | case BFD_RELOC_ARM_GOTOFF: | |
12419 | case BFD_RELOC_ARM_PLT32: | |
12420 | case BFD_RELOC_ARM_TARGET1: | |
12421 | case BFD_RELOC_ARM_ROSEGREL32: | |
12422 | case BFD_RELOC_ARM_SBREL32: | |
12423 | case BFD_RELOC_ARM_PREL31: | |
12424 | case BFD_RELOC_ARM_TARGET2: | |
12425 | case BFD_RELOC_ARM_TLS_LE32: | |
12426 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
12427 | case BFD_RELOC_ARM_PCREL_CALL: |
12428 | case BFD_RELOC_ARM_PCREL_JUMP: | |
c19d1205 ZW |
12429 | code = fixp->fx_r_type; |
12430 | break; | |
a737bd4d | 12431 | |
c19d1205 ZW |
12432 | case BFD_RELOC_ARM_TLS_GD32: |
12433 | case BFD_RELOC_ARM_TLS_IE32: | |
12434 | case BFD_RELOC_ARM_TLS_LDM32: | |
12435 | /* BFD will include the symbol's address in the addend. | |
12436 | But we don't want that, so subtract it out again here. */ | |
12437 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
12438 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
12439 | code = fixp->fx_r_type; | |
12440 | break; | |
12441 | #endif | |
a737bd4d | 12442 | |
c19d1205 ZW |
12443 | case BFD_RELOC_ARM_IMMEDIATE: |
12444 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12445 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
12446 | return NULL; | |
a737bd4d | 12447 | |
c19d1205 ZW |
12448 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
12449 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12450 | _("ADRL used for a symbol not defined in the same file")); | |
12451 | return NULL; | |
a737bd4d | 12452 | |
c19d1205 | 12453 | case BFD_RELOC_ARM_OFFSET_IMM: |
00a97672 RS |
12454 | if (section->use_rela_p) |
12455 | { | |
12456 | code = fixp->fx_r_type; | |
12457 | break; | |
12458 | } | |
12459 | ||
c19d1205 ZW |
12460 | if (fixp->fx_addsy != NULL |
12461 | && !S_IS_DEFINED (fixp->fx_addsy) | |
12462 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 12463 | { |
c19d1205 ZW |
12464 | as_bad_where (fixp->fx_file, fixp->fx_line, |
12465 | _("undefined local label `%s'"), | |
12466 | S_GET_NAME (fixp->fx_addsy)); | |
12467 | return NULL; | |
a737bd4d NC |
12468 | } |
12469 | ||
c19d1205 ZW |
12470 | as_bad_where (fixp->fx_file, fixp->fx_line, |
12471 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
12472 | return NULL; | |
a737bd4d | 12473 | |
c19d1205 ZW |
12474 | default: |
12475 | { | |
12476 | char * type; | |
6c43fab6 | 12477 | |
c19d1205 ZW |
12478 | switch (fixp->fx_r_type) |
12479 | { | |
12480 | case BFD_RELOC_NONE: type = "NONE"; break; | |
12481 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
12482 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 12483 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
12484 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
12485 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
12486 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 12487 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
12488 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
12489 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
12490 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
12491 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
12492 | default: type = _("<unknown>"); break; | |
12493 | } | |
12494 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12495 | _("cannot represent %s relocation in this object file format"), | |
12496 | type); | |
12497 | return NULL; | |
12498 | } | |
a737bd4d | 12499 | } |
6c43fab6 | 12500 | |
c19d1205 ZW |
12501 | #ifdef OBJ_ELF |
12502 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
12503 | && GOT_symbol | |
12504 | && fixp->fx_addsy == GOT_symbol) | |
12505 | { | |
12506 | code = BFD_RELOC_ARM_GOTPC; | |
12507 | reloc->addend = fixp->fx_offset = reloc->address; | |
12508 | } | |
12509 | #endif | |
6c43fab6 | 12510 | |
c19d1205 | 12511 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 12512 | |
c19d1205 ZW |
12513 | if (reloc->howto == NULL) |
12514 | { | |
12515 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12516 | _("cannot represent %s relocation in this object file format"), | |
12517 | bfd_get_reloc_code_name (code)); | |
12518 | return NULL; | |
12519 | } | |
6c43fab6 | 12520 | |
c19d1205 ZW |
12521 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
12522 | vtable entry to be used in the relocation's section offset. */ | |
12523 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12524 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 12525 | |
c19d1205 | 12526 | return reloc; |
6c43fab6 RE |
12527 | } |
12528 | ||
c19d1205 | 12529 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 12530 | |
c19d1205 ZW |
12531 | void |
12532 | cons_fix_new_arm (fragS * frag, | |
12533 | int where, | |
12534 | int size, | |
12535 | expressionS * exp) | |
6c43fab6 | 12536 | { |
c19d1205 ZW |
12537 | bfd_reloc_code_real_type type; |
12538 | int pcrel = 0; | |
6c43fab6 | 12539 | |
c19d1205 ZW |
12540 | /* Pick a reloc. |
12541 | FIXME: @@ Should look at CPU word size. */ | |
12542 | switch (size) | |
12543 | { | |
12544 | case 1: | |
12545 | type = BFD_RELOC_8; | |
12546 | break; | |
12547 | case 2: | |
12548 | type = BFD_RELOC_16; | |
12549 | break; | |
12550 | case 4: | |
12551 | default: | |
12552 | type = BFD_RELOC_32; | |
12553 | break; | |
12554 | case 8: | |
12555 | type = BFD_RELOC_64; | |
12556 | break; | |
12557 | } | |
6c43fab6 | 12558 | |
c19d1205 ZW |
12559 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
12560 | } | |
6c43fab6 | 12561 | |
c19d1205 ZW |
12562 | #if defined OBJ_COFF || defined OBJ_ELF |
12563 | void | |
12564 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 12565 | { |
c19d1205 ZW |
12566 | /* If the destination of the branch is a defined symbol which does not have |
12567 | the THUMB_FUNC attribute, then we must be calling a function which has | |
12568 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
12569 | function and change the branch to refer to that function instead. */ | |
12570 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
12571 | && fixP->fx_addsy != NULL | |
12572 | && S_IS_DEFINED (fixP->fx_addsy) | |
12573 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 12574 | { |
c19d1205 | 12575 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 12576 | } |
c19d1205 ZW |
12577 | } |
12578 | #endif | |
6c43fab6 | 12579 | |
c19d1205 ZW |
12580 | int |
12581 | arm_force_relocation (struct fix * fixp) | |
12582 | { | |
12583 | #if defined (OBJ_COFF) && defined (TE_PE) | |
12584 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
12585 | return 1; | |
12586 | #endif | |
6c43fab6 | 12587 | |
c19d1205 ZW |
12588 | /* Resolve these relocations even if the symbol is extern or weak. */ |
12589 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
12590 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 PB |
12591 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
12592 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
12593 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
12594 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 12595 | return 0; |
a737bd4d | 12596 | |
c19d1205 | 12597 | return generic_force_reloc (fixp); |
404ff6b5 AH |
12598 | } |
12599 | ||
c19d1205 ZW |
12600 | #ifdef OBJ_COFF |
12601 | /* This is a little hack to help the gas/arm/adrl.s test. It prevents | |
12602 | local labels from being added to the output symbol table when they | |
12603 | are used with the ADRL pseudo op. The ADRL relocation should always | |
12604 | be resolved before the binbary is emitted, so it is safe to say that | |
12605 | it is adjustable. */ | |
404ff6b5 | 12606 | |
c19d1205 ZW |
12607 | bfd_boolean |
12608 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 12609 | { |
c19d1205 ZW |
12610 | if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE) |
12611 | return 1; | |
12612 | return 0; | |
404ff6b5 | 12613 | } |
c19d1205 | 12614 | #endif |
404ff6b5 | 12615 | |
c19d1205 ZW |
12616 | #ifdef OBJ_ELF |
12617 | /* Relocations against Thumb function names must be left unadjusted, | |
12618 | so that the linker can use this information to correctly set the | |
12619 | bottom bit of their addresses. The MIPS version of this function | |
12620 | also prevents relocations that are mips-16 specific, but I do not | |
12621 | know why it does this. | |
404ff6b5 | 12622 | |
c19d1205 ZW |
12623 | FIXME: |
12624 | There is one other problem that ought to be addressed here, but | |
12625 | which currently is not: Taking the address of a label (rather | |
12626 | than a function) and then later jumping to that address. Such | |
12627 | addresses also ought to have their bottom bit set (assuming that | |
12628 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 12629 | |
c19d1205 ZW |
12630 | bfd_boolean |
12631 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 12632 | { |
c19d1205 ZW |
12633 | if (fixP->fx_addsy == NULL) |
12634 | return 1; | |
404ff6b5 | 12635 | |
c19d1205 ZW |
12636 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
12637 | && fixP->fx_subsy == NULL) | |
12638 | return 0; | |
a737bd4d | 12639 | |
c19d1205 ZW |
12640 | /* We need the symbol name for the VTABLE entries. */ |
12641 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
12642 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12643 | return 0; | |
404ff6b5 | 12644 | |
c19d1205 ZW |
12645 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
12646 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
12647 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
12648 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
12649 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
12650 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
12651 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
12652 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
12653 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
12654 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
12655 | return 0; | |
a737bd4d | 12656 | |
c19d1205 | 12657 | return 1; |
a737bd4d | 12658 | } |
404ff6b5 | 12659 | |
c19d1205 ZW |
12660 | const char * |
12661 | elf32_arm_target_format (void) | |
404ff6b5 | 12662 | { |
c19d1205 ZW |
12663 | #ifdef TE_SYMBIAN |
12664 | return (target_big_endian | |
12665 | ? "elf32-bigarm-symbian" | |
12666 | : "elf32-littlearm-symbian"); | |
12667 | #elif defined (TE_VXWORKS) | |
12668 | return (target_big_endian | |
12669 | ? "elf32-bigarm-vxworks" | |
12670 | : "elf32-littlearm-vxworks"); | |
12671 | #else | |
12672 | if (target_big_endian) | |
12673 | return "elf32-bigarm"; | |
12674 | else | |
12675 | return "elf32-littlearm"; | |
12676 | #endif | |
404ff6b5 AH |
12677 | } |
12678 | ||
c19d1205 ZW |
12679 | void |
12680 | armelf_frob_symbol (symbolS * symp, | |
12681 | int * puntp) | |
404ff6b5 | 12682 | { |
c19d1205 ZW |
12683 | elf_frob_symbol (symp, puntp); |
12684 | } | |
12685 | #endif | |
404ff6b5 | 12686 | |
c19d1205 | 12687 | /* MD interface: Finalization. */ |
a737bd4d | 12688 | |
c19d1205 ZW |
12689 | /* A good place to do this, although this was probably not intended |
12690 | for this kind of use. We need to dump the literal pool before | |
12691 | references are made to a null symbol pointer. */ | |
a737bd4d | 12692 | |
c19d1205 ZW |
12693 | void |
12694 | arm_cleanup (void) | |
12695 | { | |
12696 | literal_pool * pool; | |
a737bd4d | 12697 | |
c19d1205 ZW |
12698 | for (pool = list_of_pools; pool; pool = pool->next) |
12699 | { | |
12700 | /* Put it at the end of the relevent section. */ | |
12701 | subseg_set (pool->section, pool->sub_section); | |
12702 | #ifdef OBJ_ELF | |
12703 | arm_elf_change_section (); | |
12704 | #endif | |
12705 | s_ltorg (0); | |
12706 | } | |
404ff6b5 AH |
12707 | } |
12708 | ||
c19d1205 ZW |
12709 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
12710 | ARM ones. */ | |
404ff6b5 | 12711 | |
c19d1205 ZW |
12712 | void |
12713 | arm_adjust_symtab (void) | |
404ff6b5 | 12714 | { |
c19d1205 ZW |
12715 | #ifdef OBJ_COFF |
12716 | symbolS * sym; | |
404ff6b5 | 12717 | |
c19d1205 ZW |
12718 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
12719 | { | |
12720 | if (ARM_IS_THUMB (sym)) | |
12721 | { | |
12722 | if (THUMB_IS_FUNC (sym)) | |
12723 | { | |
12724 | /* Mark the symbol as a Thumb function. */ | |
12725 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
12726 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
12727 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 12728 | |
c19d1205 ZW |
12729 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
12730 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
12731 | else | |
12732 | as_bad (_("%s: unexpected function type: %d"), | |
12733 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
12734 | } | |
12735 | else switch (S_GET_STORAGE_CLASS (sym)) | |
12736 | { | |
12737 | case C_EXT: | |
12738 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
12739 | break; | |
12740 | case C_STAT: | |
12741 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
12742 | break; | |
12743 | case C_LABEL: | |
12744 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
12745 | break; | |
12746 | default: | |
12747 | /* Do nothing. */ | |
12748 | break; | |
12749 | } | |
12750 | } | |
a737bd4d | 12751 | |
c19d1205 ZW |
12752 | if (ARM_IS_INTERWORK (sym)) |
12753 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 12754 | } |
c19d1205 ZW |
12755 | #endif |
12756 | #ifdef OBJ_ELF | |
12757 | symbolS * sym; | |
12758 | char bind; | |
404ff6b5 | 12759 | |
c19d1205 | 12760 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 12761 | { |
c19d1205 ZW |
12762 | if (ARM_IS_THUMB (sym)) |
12763 | { | |
12764 | elf_symbol_type * elf_sym; | |
404ff6b5 | 12765 | |
c19d1205 ZW |
12766 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
12767 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 12768 | |
c19d1205 ZW |
12769 | if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name)) |
12770 | { | |
12771 | /* If it's a .thumb_func, declare it as so, | |
12772 | otherwise tag label as .code 16. */ | |
12773 | if (THUMB_IS_FUNC (sym)) | |
12774 | elf_sym->internal_elf_sym.st_info = | |
12775 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
12776 | else | |
12777 | elf_sym->internal_elf_sym.st_info = | |
12778 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
12779 | } | |
12780 | } | |
12781 | } | |
12782 | #endif | |
404ff6b5 AH |
12783 | } |
12784 | ||
c19d1205 | 12785 | /* MD interface: Initialization. */ |
404ff6b5 | 12786 | |
a737bd4d | 12787 | static void |
c19d1205 | 12788 | set_constant_flonums (void) |
a737bd4d | 12789 | { |
c19d1205 | 12790 | int i; |
404ff6b5 | 12791 | |
c19d1205 ZW |
12792 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
12793 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
12794 | abort (); | |
a737bd4d | 12795 | } |
404ff6b5 | 12796 | |
c19d1205 ZW |
12797 | void |
12798 | md_begin (void) | |
a737bd4d | 12799 | { |
c19d1205 ZW |
12800 | unsigned mach; |
12801 | unsigned int i; | |
404ff6b5 | 12802 | |
c19d1205 ZW |
12803 | if ( (arm_ops_hsh = hash_new ()) == NULL |
12804 | || (arm_cond_hsh = hash_new ()) == NULL | |
12805 | || (arm_shift_hsh = hash_new ()) == NULL | |
12806 | || (arm_psr_hsh = hash_new ()) == NULL | |
62b3e311 | 12807 | || (arm_v7m_psr_hsh = hash_new ()) == NULL |
c19d1205 | 12808 | || (arm_reg_hsh = hash_new ()) == NULL |
62b3e311 PB |
12809 | || (arm_reloc_hsh = hash_new ()) == NULL |
12810 | || (arm_barrier_opt_hsh = hash_new ()) == NULL) | |
c19d1205 ZW |
12811 | as_fatal (_("virtual memory exhausted")); |
12812 | ||
12813 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
12814 | hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i)); | |
12815 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) | |
12816 | hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i)); | |
12817 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) | |
12818 | hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i)); | |
12819 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) | |
12820 | hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i)); | |
62b3e311 PB |
12821 | for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++) |
12822 | hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i)); | |
c19d1205 ZW |
12823 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) |
12824 | hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i)); | |
62b3e311 PB |
12825 | for (i = 0; |
12826 | i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt); | |
12827 | i++) | |
12828 | hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template, | |
12829 | (PTR) (barrier_opt_names + i)); | |
c19d1205 ZW |
12830 | #ifdef OBJ_ELF |
12831 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
12832 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i)); | |
12833 | #endif | |
12834 | ||
12835 | set_constant_flonums (); | |
404ff6b5 | 12836 | |
c19d1205 ZW |
12837 | /* Set the cpu variant based on the command-line options. We prefer |
12838 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
12839 | -mfpu= over any other way of setting the floating point unit. | |
12840 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 12841 | if (legacy_cpu) |
404ff6b5 | 12842 | { |
e74cfd16 | 12843 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
12844 | as_bad (_("use of old and new-style options to set CPU type")); |
12845 | ||
12846 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 12847 | } |
e74cfd16 | 12848 | else if (!mcpu_cpu_opt) |
c19d1205 | 12849 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 12850 | |
e74cfd16 | 12851 | if (legacy_fpu) |
c19d1205 | 12852 | { |
e74cfd16 | 12853 | if (mfpu_opt) |
c19d1205 | 12854 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
12855 | |
12856 | mfpu_opt = legacy_fpu; | |
12857 | } | |
e74cfd16 | 12858 | else if (!mfpu_opt) |
03b1477f | 12859 | { |
c19d1205 | 12860 | #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS)) |
39c2da32 RE |
12861 | /* Some environments specify a default FPU. If they don't, infer it |
12862 | from the processor. */ | |
e74cfd16 | 12863 | if (mcpu_fpu_opt) |
03b1477f RE |
12864 | mfpu_opt = mcpu_fpu_opt; |
12865 | else | |
12866 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 12867 | #else |
e74cfd16 | 12868 | mfpu_opt = &fpu_default; |
39c2da32 | 12869 | #endif |
03b1477f RE |
12870 | } |
12871 | ||
e74cfd16 | 12872 | if (!mfpu_opt) |
03b1477f | 12873 | { |
e74cfd16 PB |
12874 | if (!mcpu_cpu_opt) |
12875 | mfpu_opt = &fpu_default; | |
12876 | else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) | |
12877 | mfpu_opt = &fpu_arch_vfp_v2; | |
03b1477f | 12878 | else |
e74cfd16 | 12879 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
12880 | } |
12881 | ||
ee065d83 | 12882 | #ifdef CPU_DEFAULT |
e74cfd16 | 12883 | if (!mcpu_cpu_opt) |
ee065d83 | 12884 | { |
e74cfd16 PB |
12885 | mcpu_cpu_opt = &cpu_default; |
12886 | selected_cpu = cpu_default; | |
ee065d83 | 12887 | } |
e74cfd16 PB |
12888 | #else |
12889 | if (mcpu_cpu_opt) | |
12890 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 12891 | else |
e74cfd16 | 12892 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 12893 | #endif |
03b1477f | 12894 | |
e74cfd16 | 12895 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 12896 | |
e74cfd16 | 12897 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 12898 | |
f17c130b | 12899 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 12900 | { |
7cc69913 NC |
12901 | unsigned int flags = 0; |
12902 | ||
12903 | #if defined OBJ_ELF | |
12904 | flags = meabi_flags; | |
d507cf36 PB |
12905 | |
12906 | switch (meabi_flags) | |
33a392fb | 12907 | { |
d507cf36 | 12908 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 12909 | #endif |
d507cf36 PB |
12910 | /* Set the flags in the private structure. */ |
12911 | if (uses_apcs_26) flags |= F_APCS26; | |
12912 | if (support_interwork) flags |= F_INTERWORK; | |
12913 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 12914 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 12915 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
12916 | flags |= F_SOFT_FLOAT; |
12917 | ||
d507cf36 PB |
12918 | switch (mfloat_abi_opt) |
12919 | { | |
12920 | case ARM_FLOAT_ABI_SOFT: | |
12921 | case ARM_FLOAT_ABI_SOFTFP: | |
12922 | flags |= F_SOFT_FLOAT; | |
12923 | break; | |
33a392fb | 12924 | |
d507cf36 PB |
12925 | case ARM_FLOAT_ABI_HARD: |
12926 | if (flags & F_SOFT_FLOAT) | |
12927 | as_bad (_("hard-float conflicts with specified fpu")); | |
12928 | break; | |
12929 | } | |
03b1477f | 12930 | |
e74cfd16 PB |
12931 | /* Using pure-endian doubles (even if soft-float). */ |
12932 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 12933 | flags |= F_VFP_FLOAT; |
f17c130b | 12934 | |
fde78edd | 12935 | #if defined OBJ_ELF |
e74cfd16 | 12936 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 12937 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
12938 | break; |
12939 | ||
8cb51566 | 12940 | case EF_ARM_EABI_VER4: |
3a4a14e9 | 12941 | case EF_ARM_EABI_VER5: |
c19d1205 | 12942 | /* No additional flags to set. */ |
d507cf36 PB |
12943 | break; |
12944 | ||
12945 | default: | |
12946 | abort (); | |
12947 | } | |
7cc69913 | 12948 | #endif |
b99bd4ef NC |
12949 | bfd_set_private_flags (stdoutput, flags); |
12950 | ||
12951 | /* We have run out flags in the COFF header to encode the | |
12952 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 12953 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
12954 | if (atpcs) |
12955 | { | |
12956 | asection * sec; | |
12957 | ||
12958 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
12959 | ||
12960 | if (sec != NULL) | |
12961 | { | |
12962 | bfd_set_section_flags | |
12963 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
12964 | bfd_set_section_size (stdoutput, sec, 0); | |
12965 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
12966 | } | |
12967 | } | |
7cc69913 | 12968 | } |
f17c130b | 12969 | #endif |
b99bd4ef NC |
12970 | |
12971 | /* Record the CPU type as well. */ | |
e74cfd16 | 12972 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) |
e16bb312 | 12973 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 12974 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 12975 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 12976 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 12977 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 12978 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 12979 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 12980 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 12981 | { |
e74cfd16 | 12982 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
12983 | mach = bfd_mach_arm_5T; |
12984 | else | |
12985 | mach = bfd_mach_arm_5; | |
12986 | } | |
e74cfd16 | 12987 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 12988 | { |
e74cfd16 | 12989 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
12990 | mach = bfd_mach_arm_4T; |
12991 | else | |
12992 | mach = bfd_mach_arm_4; | |
12993 | } | |
e74cfd16 | 12994 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 12995 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
12996 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
12997 | mach = bfd_mach_arm_3; | |
12998 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
12999 | mach = bfd_mach_arm_2a; | |
13000 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
13001 | mach = bfd_mach_arm_2; | |
13002 | else | |
13003 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
13004 | |
13005 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
13006 | } | |
13007 | ||
c19d1205 | 13008 | /* Command line processing. */ |
b99bd4ef | 13009 | |
c19d1205 ZW |
13010 | /* md_parse_option |
13011 | Invocation line includes a switch not recognized by the base assembler. | |
13012 | See if it's a processor-specific option. | |
b99bd4ef | 13013 | |
c19d1205 ZW |
13014 | This routine is somewhat complicated by the need for backwards |
13015 | compatibility (since older releases of gcc can't be changed). | |
13016 | The new options try to make the interface as compatible as | |
13017 | possible with GCC. | |
b99bd4ef | 13018 | |
c19d1205 | 13019 | New options (supported) are: |
b99bd4ef | 13020 | |
c19d1205 ZW |
13021 | -mcpu=<cpu name> Assemble for selected processor |
13022 | -march=<architecture name> Assemble for selected architecture | |
13023 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
13024 | -EB/-mbig-endian Big-endian | |
13025 | -EL/-mlittle-endian Little-endian | |
13026 | -k Generate PIC code | |
13027 | -mthumb Start in Thumb mode | |
13028 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 13029 | |
c19d1205 | 13030 | For now we will also provide support for: |
b99bd4ef | 13031 | |
c19d1205 ZW |
13032 | -mapcs-32 32-bit Program counter |
13033 | -mapcs-26 26-bit Program counter | |
13034 | -macps-float Floats passed in FP registers | |
13035 | -mapcs-reentrant Reentrant code | |
13036 | -matpcs | |
13037 | (sometime these will probably be replaced with -mapcs=<list of options> | |
13038 | and -matpcs=<list of options>) | |
b99bd4ef | 13039 | |
c19d1205 ZW |
13040 | The remaining options are only supported for back-wards compatibility. |
13041 | Cpu variants, the arm part is optional: | |
13042 | -m[arm]1 Currently not supported. | |
13043 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
13044 | -m[arm]3 Arm 3 processor | |
13045 | -m[arm]6[xx], Arm 6 processors | |
13046 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
13047 | -m[arm]8[10] Arm 8 processors | |
13048 | -m[arm]9[20][tdmi] Arm 9 processors | |
13049 | -mstrongarm[110[0]] StrongARM processors | |
13050 | -mxscale XScale processors | |
13051 | -m[arm]v[2345[t[e]]] Arm architectures | |
13052 | -mall All (except the ARM1) | |
13053 | FP variants: | |
13054 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
13055 | -mfpe-old (No float load/store multiples) | |
13056 | -mvfpxd VFP Single precision | |
13057 | -mvfp All VFP | |
13058 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 13059 | |
c19d1205 ZW |
13060 | The following CPU names are recognized: |
13061 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
13062 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
13063 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
13064 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
13065 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
13066 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
13067 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 13068 | |
c19d1205 | 13069 | */ |
b99bd4ef | 13070 | |
c19d1205 | 13071 | const char * md_shortopts = "m:k"; |
b99bd4ef | 13072 | |
c19d1205 ZW |
13073 | #ifdef ARM_BI_ENDIAN |
13074 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
13075 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 13076 | #else |
c19d1205 ZW |
13077 | #if TARGET_BYTES_BIG_ENDIAN |
13078 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 13079 | #else |
c19d1205 ZW |
13080 | #define OPTION_EL (OPTION_MD_BASE + 1) |
13081 | #endif | |
b99bd4ef | 13082 | #endif |
b99bd4ef | 13083 | |
c19d1205 | 13084 | struct option md_longopts[] = |
b99bd4ef | 13085 | { |
c19d1205 ZW |
13086 | #ifdef OPTION_EB |
13087 | {"EB", no_argument, NULL, OPTION_EB}, | |
13088 | #endif | |
13089 | #ifdef OPTION_EL | |
13090 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 13091 | #endif |
c19d1205 ZW |
13092 | {NULL, no_argument, NULL, 0} |
13093 | }; | |
b99bd4ef | 13094 | |
c19d1205 | 13095 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 13096 | |
c19d1205 | 13097 | struct arm_option_table |
b99bd4ef | 13098 | { |
c19d1205 ZW |
13099 | char *option; /* Option name to match. */ |
13100 | char *help; /* Help information. */ | |
13101 | int *var; /* Variable to change. */ | |
13102 | int value; /* What to change it to. */ | |
13103 | char *deprecated; /* If non-null, print this message. */ | |
13104 | }; | |
b99bd4ef | 13105 | |
c19d1205 ZW |
13106 | struct arm_option_table arm_opts[] = |
13107 | { | |
13108 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
13109 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
13110 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
13111 | &support_interwork, 1, NULL}, | |
13112 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
13113 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
13114 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
13115 | 1, NULL}, | |
13116 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
13117 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
13118 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
13119 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
13120 | NULL}, | |
b99bd4ef | 13121 | |
c19d1205 ZW |
13122 | /* These are recognized by the assembler, but have no affect on code. */ |
13123 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
13124 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
e74cfd16 PB |
13125 | {NULL, NULL, NULL, 0, NULL} |
13126 | }; | |
13127 | ||
13128 | struct arm_legacy_option_table | |
13129 | { | |
13130 | char *option; /* Option name to match. */ | |
13131 | const arm_feature_set **var; /* Variable to change. */ | |
13132 | const arm_feature_set value; /* What to change it to. */ | |
13133 | char *deprecated; /* If non-null, print this message. */ | |
13134 | }; | |
b99bd4ef | 13135 | |
e74cfd16 PB |
13136 | const struct arm_legacy_option_table arm_legacy_opts[] = |
13137 | { | |
c19d1205 ZW |
13138 | /* DON'T add any new processors to this list -- we want the whole list |
13139 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
13140 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
13141 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
13142 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
13143 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
13144 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
13145 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
13146 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
13147 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
13148 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
13149 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
13150 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
13151 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
13152 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
13153 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
13154 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
13155 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
13156 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
13157 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
13158 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
13159 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
13160 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
13161 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
13162 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
13163 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
13164 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
13165 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
13166 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
13167 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
13168 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
13169 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
13170 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
13171 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
13172 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
13173 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
13174 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
13175 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
13176 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
13177 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
13178 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
13179 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
13180 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
13181 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
13182 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
13183 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
13184 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
13185 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
13186 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
13187 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
13188 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
13189 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
13190 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
13191 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
13192 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
13193 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
13194 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
13195 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
13196 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
13197 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
13198 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
13199 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
13200 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
13201 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
13202 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
13203 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
13204 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
13205 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
13206 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
13207 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
13208 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
13209 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 13210 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 13211 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 13212 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 13213 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 13214 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
13215 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
13216 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
13217 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 13218 | |
c19d1205 | 13219 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
13220 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
13221 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
13222 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
13223 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
13224 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
13225 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
13226 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
13227 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
13228 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
13229 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
13230 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
13231 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
13232 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
13233 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
13234 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
13235 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
13236 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
13237 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 13238 | |
c19d1205 | 13239 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
13240 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
13241 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
13242 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
13243 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 13244 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 13245 | |
e74cfd16 | 13246 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 13247 | }; |
7ed4c4c5 | 13248 | |
c19d1205 | 13249 | struct arm_cpu_option_table |
7ed4c4c5 | 13250 | { |
c19d1205 | 13251 | char *name; |
e74cfd16 | 13252 | const arm_feature_set value; |
c19d1205 ZW |
13253 | /* For some CPUs we assume an FPU unless the user explicitly sets |
13254 | -mfpu=... */ | |
e74cfd16 | 13255 | const arm_feature_set default_fpu; |
ee065d83 PB |
13256 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
13257 | case. */ | |
13258 | const char *canonical_name; | |
c19d1205 | 13259 | }; |
7ed4c4c5 | 13260 | |
c19d1205 ZW |
13261 | /* This list should, at a minimum, contain all the cpu names |
13262 | recognized by GCC. */ | |
e74cfd16 | 13263 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 13264 | { |
ee065d83 PB |
13265 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
13266 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
13267 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
13268 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
13269 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
13270 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13271 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13272 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13273 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13274 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13275 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13276 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
13277 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13278 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
13279 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13280 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
13281 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13282 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13283 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13284 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13285 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13286 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13287 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13288 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13289 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13290 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13291 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13292 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
13293 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13294 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13295 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13296 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13297 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13298 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13299 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13300 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13301 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13302 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
13303 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13304 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
13305 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13306 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13307 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
13308 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
13309 | /* For V5 or later processors we default to using VFP; but the user |
13310 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
13311 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
13312 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13313 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
13314 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
13315 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
13316 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
13317 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
13318 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13319 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
13320 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
13321 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13322 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13323 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
13324 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
13325 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13326 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
13327 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
13328 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13329 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13330 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
13331 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
13332 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, | |
13333 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
13334 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
13335 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
13336 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
13337 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
13338 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
13339 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
13340 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
13341 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
62b3e311 PB |
13342 | {"cortex-a8", ARM_ARCH_V7A, FPU_ARCH_VFP_V2, NULL}, |
13343 | {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL}, | |
13344 | {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL}, | |
c19d1205 | 13345 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 13346 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 13347 | /* ??? iwmmxt is not a processor. */ |
ee065d83 PB |
13348 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
13349 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, | |
c19d1205 | 13350 | /* Maverick */ |
e74cfd16 PB |
13351 | {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
13352 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} | |
c19d1205 | 13353 | }; |
7ed4c4c5 | 13354 | |
c19d1205 | 13355 | struct arm_arch_option_table |
7ed4c4c5 | 13356 | { |
c19d1205 | 13357 | char *name; |
e74cfd16 PB |
13358 | const arm_feature_set value; |
13359 | const arm_feature_set default_fpu; | |
c19d1205 | 13360 | }; |
7ed4c4c5 | 13361 | |
c19d1205 ZW |
13362 | /* This list should, at a minimum, contain all the architecture names |
13363 | recognized by GCC. */ | |
e74cfd16 | 13364 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
13365 | { |
13366 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
13367 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
13368 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
13369 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
13370 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
13371 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
13372 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
13373 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
13374 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
13375 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
13376 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
13377 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
13378 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
13379 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
13380 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
13381 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
13382 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
13383 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
13384 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
13385 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
13386 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
13387 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
13388 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
13389 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
13390 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
13391 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
62b3e311 PB |
13392 | {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP}, |
13393 | {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP}, | |
13394 | {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP}, | |
13395 | {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP}, | |
c19d1205 ZW |
13396 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, |
13397 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
e74cfd16 | 13398 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 13399 | }; |
7ed4c4c5 | 13400 | |
c19d1205 | 13401 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 13402 | struct arm_option_cpu_value_table |
c19d1205 ZW |
13403 | { |
13404 | char *name; | |
e74cfd16 | 13405 | const arm_feature_set value; |
c19d1205 | 13406 | }; |
7ed4c4c5 | 13407 | |
e74cfd16 | 13408 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 13409 | { |
e74cfd16 PB |
13410 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
13411 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
13412 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
13413 | {NULL, ARM_ARCH_NONE} | |
c19d1205 | 13414 | }; |
7ed4c4c5 | 13415 | |
c19d1205 ZW |
13416 | /* This list should, at a minimum, contain all the fpu names |
13417 | recognized by GCC. */ | |
e74cfd16 | 13418 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
13419 | { |
13420 | {"softfpa", FPU_NONE}, | |
13421 | {"fpe", FPU_ARCH_FPE}, | |
13422 | {"fpe2", FPU_ARCH_FPE}, | |
13423 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
13424 | {"fpa", FPU_ARCH_FPA}, | |
13425 | {"fpa10", FPU_ARCH_FPA}, | |
13426 | {"fpa11", FPU_ARCH_FPA}, | |
13427 | {"arm7500fe", FPU_ARCH_FPA}, | |
13428 | {"softvfp", FPU_ARCH_VFP}, | |
13429 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
13430 | {"vfp", FPU_ARCH_VFP_V2}, | |
13431 | {"vfp9", FPU_ARCH_VFP_V2}, | |
13432 | {"vfp10", FPU_ARCH_VFP_V2}, | |
13433 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
13434 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
13435 | {"arm1020t", FPU_ARCH_VFP_V1}, | |
13436 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
13437 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
13438 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
13439 | {"maverick", FPU_ARCH_MAVERICK}, | |
e74cfd16 PB |
13440 | {NULL, ARM_ARCH_NONE} |
13441 | }; | |
13442 | ||
13443 | struct arm_option_value_table | |
13444 | { | |
13445 | char *name; | |
13446 | long value; | |
c19d1205 | 13447 | }; |
7ed4c4c5 | 13448 | |
e74cfd16 | 13449 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
13450 | { |
13451 | {"hard", ARM_FLOAT_ABI_HARD}, | |
13452 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
13453 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 13454 | {NULL, 0} |
c19d1205 | 13455 | }; |
7ed4c4c5 | 13456 | |
c19d1205 | 13457 | #ifdef OBJ_ELF |
3a4a14e9 | 13458 | /* We only know how to output GNU and ver 4/5 (AAELF) formats. */ |
e74cfd16 | 13459 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
13460 | { |
13461 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
13462 | {"4", EF_ARM_EABI_VER4}, | |
3a4a14e9 | 13463 | {"5", EF_ARM_EABI_VER5}, |
e74cfd16 | 13464 | {NULL, 0} |
c19d1205 ZW |
13465 | }; |
13466 | #endif | |
7ed4c4c5 | 13467 | |
c19d1205 ZW |
13468 | struct arm_long_option_table |
13469 | { | |
13470 | char * option; /* Substring to match. */ | |
13471 | char * help; /* Help information. */ | |
13472 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
13473 | char * deprecated; /* If non-null, print this message. */ | |
13474 | }; | |
7ed4c4c5 NC |
13475 | |
13476 | static int | |
e74cfd16 | 13477 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 13478 | { |
e74cfd16 PB |
13479 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
13480 | ||
13481 | /* Copy the feature set, so that we can modify it. */ | |
13482 | *ext_set = **opt_p; | |
13483 | *opt_p = ext_set; | |
13484 | ||
c19d1205 | 13485 | while (str != NULL && *str != 0) |
7ed4c4c5 | 13486 | { |
e74cfd16 | 13487 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
13488 | char * ext; |
13489 | int optlen; | |
7ed4c4c5 | 13490 | |
c19d1205 ZW |
13491 | if (*str != '+') |
13492 | { | |
13493 | as_bad (_("invalid architectural extension")); | |
13494 | return 0; | |
13495 | } | |
7ed4c4c5 | 13496 | |
c19d1205 ZW |
13497 | str++; |
13498 | ext = strchr (str, '+'); | |
7ed4c4c5 | 13499 | |
c19d1205 ZW |
13500 | if (ext != NULL) |
13501 | optlen = ext - str; | |
13502 | else | |
13503 | optlen = strlen (str); | |
7ed4c4c5 | 13504 | |
c19d1205 ZW |
13505 | if (optlen == 0) |
13506 | { | |
13507 | as_bad (_("missing architectural extension")); | |
13508 | return 0; | |
13509 | } | |
7ed4c4c5 | 13510 | |
c19d1205 ZW |
13511 | for (opt = arm_extensions; opt->name != NULL; opt++) |
13512 | if (strncmp (opt->name, str, optlen) == 0) | |
13513 | { | |
e74cfd16 | 13514 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
13515 | break; |
13516 | } | |
7ed4c4c5 | 13517 | |
c19d1205 ZW |
13518 | if (opt->name == NULL) |
13519 | { | |
13520 | as_bad (_("unknown architectural extnsion `%s'"), str); | |
13521 | return 0; | |
13522 | } | |
7ed4c4c5 | 13523 | |
c19d1205 ZW |
13524 | str = ext; |
13525 | }; | |
7ed4c4c5 | 13526 | |
c19d1205 ZW |
13527 | return 1; |
13528 | } | |
7ed4c4c5 | 13529 | |
c19d1205 ZW |
13530 | static int |
13531 | arm_parse_cpu (char * str) | |
7ed4c4c5 | 13532 | { |
e74cfd16 | 13533 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
13534 | char * ext = strchr (str, '+'); |
13535 | int optlen; | |
7ed4c4c5 | 13536 | |
c19d1205 ZW |
13537 | if (ext != NULL) |
13538 | optlen = ext - str; | |
7ed4c4c5 | 13539 | else |
c19d1205 | 13540 | optlen = strlen (str); |
7ed4c4c5 | 13541 | |
c19d1205 | 13542 | if (optlen == 0) |
7ed4c4c5 | 13543 | { |
c19d1205 ZW |
13544 | as_bad (_("missing cpu name `%s'"), str); |
13545 | return 0; | |
7ed4c4c5 NC |
13546 | } |
13547 | ||
c19d1205 ZW |
13548 | for (opt = arm_cpus; opt->name != NULL; opt++) |
13549 | if (strncmp (opt->name, str, optlen) == 0) | |
13550 | { | |
e74cfd16 PB |
13551 | mcpu_cpu_opt = &opt->value; |
13552 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 PB |
13553 | if (opt->canonical_name) |
13554 | strcpy(selected_cpu_name, opt->canonical_name); | |
13555 | else | |
13556 | { | |
13557 | int i; | |
13558 | for (i = 0; i < optlen; i++) | |
13559 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
13560 | selected_cpu_name[i] = 0; | |
13561 | } | |
7ed4c4c5 | 13562 | |
c19d1205 ZW |
13563 | if (ext != NULL) |
13564 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 13565 | |
c19d1205 ZW |
13566 | return 1; |
13567 | } | |
7ed4c4c5 | 13568 | |
c19d1205 ZW |
13569 | as_bad (_("unknown cpu `%s'"), str); |
13570 | return 0; | |
7ed4c4c5 NC |
13571 | } |
13572 | ||
c19d1205 ZW |
13573 | static int |
13574 | arm_parse_arch (char * str) | |
7ed4c4c5 | 13575 | { |
e74cfd16 | 13576 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
13577 | char *ext = strchr (str, '+'); |
13578 | int optlen; | |
7ed4c4c5 | 13579 | |
c19d1205 ZW |
13580 | if (ext != NULL) |
13581 | optlen = ext - str; | |
7ed4c4c5 | 13582 | else |
c19d1205 | 13583 | optlen = strlen (str); |
7ed4c4c5 | 13584 | |
c19d1205 | 13585 | if (optlen == 0) |
7ed4c4c5 | 13586 | { |
c19d1205 ZW |
13587 | as_bad (_("missing architecture name `%s'"), str); |
13588 | return 0; | |
7ed4c4c5 NC |
13589 | } |
13590 | ||
c19d1205 ZW |
13591 | for (opt = arm_archs; opt->name != NULL; opt++) |
13592 | if (streq (opt->name, str)) | |
13593 | { | |
e74cfd16 PB |
13594 | march_cpu_opt = &opt->value; |
13595 | march_fpu_opt = &opt->default_fpu; | |
ee065d83 | 13596 | strcpy(selected_cpu_name, opt->name); |
7ed4c4c5 | 13597 | |
c19d1205 ZW |
13598 | if (ext != NULL) |
13599 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 13600 | |
c19d1205 ZW |
13601 | return 1; |
13602 | } | |
13603 | ||
13604 | as_bad (_("unknown architecture `%s'\n"), str); | |
13605 | return 0; | |
7ed4c4c5 | 13606 | } |
eb043451 | 13607 | |
c19d1205 ZW |
13608 | static int |
13609 | arm_parse_fpu (char * str) | |
13610 | { | |
e74cfd16 | 13611 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 13612 | |
c19d1205 ZW |
13613 | for (opt = arm_fpus; opt->name != NULL; opt++) |
13614 | if (streq (opt->name, str)) | |
13615 | { | |
e74cfd16 | 13616 | mfpu_opt = &opt->value; |
c19d1205 ZW |
13617 | return 1; |
13618 | } | |
b99bd4ef | 13619 | |
c19d1205 ZW |
13620 | as_bad (_("unknown floating point format `%s'\n"), str); |
13621 | return 0; | |
13622 | } | |
13623 | ||
13624 | static int | |
13625 | arm_parse_float_abi (char * str) | |
b99bd4ef | 13626 | { |
e74cfd16 | 13627 | const struct arm_option_value_table * opt; |
b99bd4ef | 13628 | |
c19d1205 ZW |
13629 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
13630 | if (streq (opt->name, str)) | |
13631 | { | |
13632 | mfloat_abi_opt = opt->value; | |
13633 | return 1; | |
13634 | } | |
cc8a6dd0 | 13635 | |
c19d1205 ZW |
13636 | as_bad (_("unknown floating point abi `%s'\n"), str); |
13637 | return 0; | |
13638 | } | |
b99bd4ef | 13639 | |
c19d1205 ZW |
13640 | #ifdef OBJ_ELF |
13641 | static int | |
13642 | arm_parse_eabi (char * str) | |
13643 | { | |
e74cfd16 | 13644 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 13645 | |
c19d1205 ZW |
13646 | for (opt = arm_eabis; opt->name != NULL; opt++) |
13647 | if (streq (opt->name, str)) | |
13648 | { | |
13649 | meabi_flags = opt->value; | |
13650 | return 1; | |
13651 | } | |
13652 | as_bad (_("unknown EABI `%s'\n"), str); | |
13653 | return 0; | |
13654 | } | |
13655 | #endif | |
cc8a6dd0 | 13656 | |
c19d1205 ZW |
13657 | struct arm_long_option_table arm_long_opts[] = |
13658 | { | |
13659 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
13660 | arm_parse_cpu, NULL}, | |
13661 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
13662 | arm_parse_arch, NULL}, | |
13663 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
13664 | arm_parse_fpu, NULL}, | |
13665 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
13666 | arm_parse_float_abi, NULL}, | |
13667 | #ifdef OBJ_ELF | |
13668 | {"meabi=", N_("<ver>\t assemble for eabi version <ver>"), | |
13669 | arm_parse_eabi, NULL}, | |
13670 | #endif | |
13671 | {NULL, NULL, 0, NULL} | |
13672 | }; | |
cc8a6dd0 | 13673 | |
c19d1205 ZW |
13674 | int |
13675 | md_parse_option (int c, char * arg) | |
13676 | { | |
13677 | struct arm_option_table *opt; | |
e74cfd16 | 13678 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 13679 | struct arm_long_option_table *lopt; |
b99bd4ef | 13680 | |
c19d1205 | 13681 | switch (c) |
b99bd4ef | 13682 | { |
c19d1205 ZW |
13683 | #ifdef OPTION_EB |
13684 | case OPTION_EB: | |
13685 | target_big_endian = 1; | |
13686 | break; | |
13687 | #endif | |
cc8a6dd0 | 13688 | |
c19d1205 ZW |
13689 | #ifdef OPTION_EL |
13690 | case OPTION_EL: | |
13691 | target_big_endian = 0; | |
13692 | break; | |
13693 | #endif | |
b99bd4ef | 13694 | |
c19d1205 ZW |
13695 | case 'a': |
13696 | /* Listing option. Just ignore these, we don't support additional | |
13697 | ones. */ | |
13698 | return 0; | |
b99bd4ef | 13699 | |
c19d1205 ZW |
13700 | default: |
13701 | for (opt = arm_opts; opt->option != NULL; opt++) | |
13702 | { | |
13703 | if (c == opt->option[0] | |
13704 | && ((arg == NULL && opt->option[1] == 0) | |
13705 | || streq (arg, opt->option + 1))) | |
13706 | { | |
13707 | #if WARN_DEPRECATED | |
13708 | /* If the option is deprecated, tell the user. */ | |
13709 | if (opt->deprecated != NULL) | |
13710 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
13711 | arg ? arg : "", _(opt->deprecated)); | |
13712 | #endif | |
b99bd4ef | 13713 | |
c19d1205 ZW |
13714 | if (opt->var != NULL) |
13715 | *opt->var = opt->value; | |
cc8a6dd0 | 13716 | |
c19d1205 ZW |
13717 | return 1; |
13718 | } | |
13719 | } | |
b99bd4ef | 13720 | |
e74cfd16 PB |
13721 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
13722 | { | |
13723 | if (c == fopt->option[0] | |
13724 | && ((arg == NULL && fopt->option[1] == 0) | |
13725 | || streq (arg, fopt->option + 1))) | |
13726 | { | |
13727 | #if WARN_DEPRECATED | |
13728 | /* If the option is deprecated, tell the user. */ | |
13729 | if (fopt->deprecated != NULL) | |
13730 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
13731 | arg ? arg : "", _(fopt->deprecated)); | |
13732 | #endif | |
13733 | ||
13734 | if (fopt->var != NULL) | |
13735 | *fopt->var = &fopt->value; | |
13736 | ||
13737 | return 1; | |
13738 | } | |
13739 | } | |
13740 | ||
c19d1205 ZW |
13741 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
13742 | { | |
13743 | /* These options are expected to have an argument. */ | |
13744 | if (c == lopt->option[0] | |
13745 | && arg != NULL | |
13746 | && strncmp (arg, lopt->option + 1, | |
13747 | strlen (lopt->option + 1)) == 0) | |
13748 | { | |
13749 | #if WARN_DEPRECATED | |
13750 | /* If the option is deprecated, tell the user. */ | |
13751 | if (lopt->deprecated != NULL) | |
13752 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, | |
13753 | _(lopt->deprecated)); | |
13754 | #endif | |
b99bd4ef | 13755 | |
c19d1205 ZW |
13756 | /* Call the sup-option parser. */ |
13757 | return lopt->func (arg + strlen (lopt->option) - 1); | |
13758 | } | |
13759 | } | |
a737bd4d | 13760 | |
c19d1205 ZW |
13761 | return 0; |
13762 | } | |
a394c00f | 13763 | |
c19d1205 ZW |
13764 | return 1; |
13765 | } | |
a394c00f | 13766 | |
c19d1205 ZW |
13767 | void |
13768 | md_show_usage (FILE * fp) | |
a394c00f | 13769 | { |
c19d1205 ZW |
13770 | struct arm_option_table *opt; |
13771 | struct arm_long_option_table *lopt; | |
a394c00f | 13772 | |
c19d1205 | 13773 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 13774 | |
c19d1205 ZW |
13775 | for (opt = arm_opts; opt->option != NULL; opt++) |
13776 | if (opt->help != NULL) | |
13777 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 13778 | |
c19d1205 ZW |
13779 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
13780 | if (lopt->help != NULL) | |
13781 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 13782 | |
c19d1205 ZW |
13783 | #ifdef OPTION_EB |
13784 | fprintf (fp, _("\ | |
13785 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
13786 | #endif |
13787 | ||
c19d1205 ZW |
13788 | #ifdef OPTION_EL |
13789 | fprintf (fp, _("\ | |
13790 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 13791 | #endif |
c19d1205 | 13792 | } |
ee065d83 PB |
13793 | |
13794 | ||
13795 | #ifdef OBJ_ELF | |
62b3e311 PB |
13796 | typedef struct |
13797 | { | |
13798 | int val; | |
13799 | arm_feature_set flags; | |
13800 | } cpu_arch_ver_table; | |
13801 | ||
13802 | /* Mapping from CPU features to EABI CPU arch values. Table must be sorted | |
13803 | least features first. */ | |
13804 | static const cpu_arch_ver_table cpu_arch_ver[] = | |
13805 | { | |
13806 | {1, ARM_ARCH_V4}, | |
13807 | {2, ARM_ARCH_V4T}, | |
13808 | {3, ARM_ARCH_V5}, | |
13809 | {4, ARM_ARCH_V5TE}, | |
13810 | {5, ARM_ARCH_V5TEJ}, | |
13811 | {6, ARM_ARCH_V6}, | |
13812 | {7, ARM_ARCH_V6Z}, | |
13813 | {8, ARM_ARCH_V6K}, | |
13814 | {9, ARM_ARCH_V6T2}, | |
13815 | {10, ARM_ARCH_V7A}, | |
13816 | {10, ARM_ARCH_V7R}, | |
13817 | {10, ARM_ARCH_V7M}, | |
13818 | {0, ARM_ARCH_NONE} | |
13819 | }; | |
13820 | ||
ee065d83 PB |
13821 | /* Set the public EABI object attributes. */ |
13822 | static void | |
13823 | aeabi_set_public_attributes (void) | |
13824 | { | |
13825 | int arch; | |
e74cfd16 | 13826 | arm_feature_set flags; |
62b3e311 PB |
13827 | arm_feature_set tmp; |
13828 | const cpu_arch_ver_table *p; | |
ee065d83 PB |
13829 | |
13830 | /* Choose the architecture based on the capabilities of the requested cpu | |
13831 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
13832 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
13833 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
13834 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
62b3e311 PB |
13835 | |
13836 | tmp = flags; | |
13837 | arch = 0; | |
13838 | for (p = cpu_arch_ver; p->val; p++) | |
13839 | { | |
13840 | if (ARM_CPU_HAS_FEATURE (tmp, p->flags)) | |
13841 | { | |
13842 | arch = p->val; | |
13843 | ARM_CLEAR_FEATURE (tmp, tmp, p->flags); | |
13844 | } | |
13845 | } | |
ee065d83 PB |
13846 | |
13847 | /* Tag_CPU_name. */ | |
13848 | if (selected_cpu_name[0]) | |
13849 | { | |
13850 | char *p; | |
13851 | ||
13852 | p = selected_cpu_name; | |
13853 | if (strncmp(p, "armv", 4) == 0) | |
13854 | { | |
13855 | int i; | |
13856 | ||
13857 | p += 4; | |
13858 | for (i = 0; p[i]; i++) | |
13859 | p[i] = TOUPPER (p[i]); | |
13860 | } | |
13861 | elf32_arm_add_eabi_attr_string (stdoutput, 5, p); | |
13862 | } | |
13863 | /* Tag_CPU_arch. */ | |
13864 | elf32_arm_add_eabi_attr_int (stdoutput, 6, arch); | |
62b3e311 PB |
13865 | /* Tag_CPU_arch_profile. */ |
13866 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)) | |
13867 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A'); | |
13868 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r)) | |
13869 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R'); | |
13870 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)) | |
13871 | elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M'); | |
ee065d83 | 13872 | /* Tag_ARM_ISA_use. */ |
e74cfd16 | 13873 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full)) |
ee065d83 PB |
13874 | elf32_arm_add_eabi_attr_int (stdoutput, 8, 1); |
13875 | /* Tag_THUMB_ISA_use. */ | |
e74cfd16 | 13876 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full)) |
ee065d83 | 13877 | elf32_arm_add_eabi_attr_int (stdoutput, 9, |
e74cfd16 | 13878 | ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1); |
ee065d83 | 13879 | /* Tag_VFP_arch. */ |
e74cfd16 PB |
13880 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v2) |
13881 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v2)) | |
ee065d83 | 13882 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 2); |
e74cfd16 PB |
13883 | else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v1) |
13884 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v1)) | |
ee065d83 PB |
13885 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 1); |
13886 | /* Tag_WMMX_arch. */ | |
e74cfd16 PB |
13887 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt) |
13888 | || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt)) | |
ee065d83 PB |
13889 | elf32_arm_add_eabi_attr_int (stdoutput, 11, 1); |
13890 | } | |
13891 | ||
13892 | /* Add the .ARM.attributes section. */ | |
13893 | void | |
13894 | arm_md_end (void) | |
13895 | { | |
13896 | segT s; | |
13897 | char *p; | |
13898 | addressT addr; | |
13899 | offsetT size; | |
13900 | ||
13901 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) | |
13902 | return; | |
13903 | ||
13904 | aeabi_set_public_attributes (); | |
13905 | size = elf32_arm_eabi_attr_size (stdoutput); | |
13906 | s = subseg_new (".ARM.attributes", 0); | |
13907 | bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA); | |
13908 | addr = frag_now_fix (); | |
13909 | p = frag_more (size); | |
13910 | elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size); | |
13911 | } | |
8463be01 | 13912 | #endif /* OBJ_ELF */ |
ee065d83 PB |
13913 | |
13914 | ||
13915 | /* Parse a .cpu directive. */ | |
13916 | ||
13917 | static void | |
13918 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
13919 | { | |
e74cfd16 | 13920 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
13921 | char *name; |
13922 | char saved_char; | |
13923 | ||
13924 | name = input_line_pointer; | |
13925 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
13926 | input_line_pointer++; | |
13927 | saved_char = *input_line_pointer; | |
13928 | *input_line_pointer = 0; | |
13929 | ||
13930 | /* Skip the first "all" entry. */ | |
13931 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
13932 | if (streq (opt->name, name)) | |
13933 | { | |
e74cfd16 PB |
13934 | mcpu_cpu_opt = &opt->value; |
13935 | selected_cpu = opt->value; | |
ee065d83 PB |
13936 | if (opt->canonical_name) |
13937 | strcpy(selected_cpu_name, opt->canonical_name); | |
13938 | else | |
13939 | { | |
13940 | int i; | |
13941 | for (i = 0; opt->name[i]; i++) | |
13942 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
13943 | selected_cpu_name[i] = 0; | |
13944 | } | |
e74cfd16 | 13945 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
13946 | *input_line_pointer = saved_char; |
13947 | demand_empty_rest_of_line (); | |
13948 | return; | |
13949 | } | |
13950 | as_bad (_("unknown cpu `%s'"), name); | |
13951 | *input_line_pointer = saved_char; | |
13952 | ignore_rest_of_line (); | |
13953 | } | |
13954 | ||
13955 | ||
13956 | /* Parse a .arch directive. */ | |
13957 | ||
13958 | static void | |
13959 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
13960 | { | |
e74cfd16 | 13961 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
13962 | char saved_char; |
13963 | char *name; | |
13964 | ||
13965 | name = input_line_pointer; | |
13966 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
13967 | input_line_pointer++; | |
13968 | saved_char = *input_line_pointer; | |
13969 | *input_line_pointer = 0; | |
13970 | ||
13971 | /* Skip the first "all" entry. */ | |
13972 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
13973 | if (streq (opt->name, name)) | |
13974 | { | |
e74cfd16 PB |
13975 | mcpu_cpu_opt = &opt->value; |
13976 | selected_cpu = opt->value; | |
ee065d83 | 13977 | strcpy(selected_cpu_name, opt->name); |
e74cfd16 | 13978 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
13979 | *input_line_pointer = saved_char; |
13980 | demand_empty_rest_of_line (); | |
13981 | return; | |
13982 | } | |
13983 | ||
13984 | as_bad (_("unknown architecture `%s'\n"), name); | |
13985 | *input_line_pointer = saved_char; | |
13986 | ignore_rest_of_line (); | |
13987 | } | |
13988 | ||
13989 | ||
13990 | /* Parse a .fpu directive. */ | |
13991 | ||
13992 | static void | |
13993 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
13994 | { | |
e74cfd16 | 13995 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
13996 | char saved_char; |
13997 | char *name; | |
13998 | ||
13999 | name = input_line_pointer; | |
14000 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
14001 | input_line_pointer++; | |
14002 | saved_char = *input_line_pointer; | |
14003 | *input_line_pointer = 0; | |
14004 | ||
14005 | for (opt = arm_fpus; opt->name != NULL; opt++) | |
14006 | if (streq (opt->name, name)) | |
14007 | { | |
e74cfd16 PB |
14008 | mfpu_opt = &opt->value; |
14009 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
14010 | *input_line_pointer = saved_char; |
14011 | demand_empty_rest_of_line (); | |
14012 | return; | |
14013 | } | |
14014 | ||
14015 | as_bad (_("unknown floating point format `%s'\n"), name); | |
14016 | *input_line_pointer = saved_char; | |
14017 | ignore_rest_of_line (); | |
14018 | } | |
ee065d83 | 14019 |