]>
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); | |
185 | ||
186 | static const arm_feature_set arm_arch_any = ARM_ANY; | |
187 | static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1); | |
188 | static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2; | |
189 | static const arm_feature_set arm_arch_none = ARM_ARCH_NONE; | |
190 | ||
191 | static const arm_feature_set arm_cext_iwmmxt = | |
192 | ARM_FEATURE (0, ARM_CEXT_IWMMXT); | |
193 | static const arm_feature_set arm_cext_xscale = | |
194 | ARM_FEATURE (0, ARM_CEXT_XSCALE); | |
195 | static const arm_feature_set arm_cext_maverick = | |
196 | ARM_FEATURE (0, ARM_CEXT_MAVERICK); | |
197 | static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1); | |
198 | static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2); | |
199 | static const arm_feature_set fpu_vfp_ext_v1xd = | |
200 | ARM_FEATURE (0, FPU_VFP_EXT_V1xD); | |
201 | static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1); | |
202 | static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2); | |
203 | ||
33a392fb | 204 | static int mfloat_abi_opt = -1; |
e74cfd16 PB |
205 | /* Record user cpu selection for object attributes. */ |
206 | static arm_feature_set selected_cpu = ARM_ARCH_NONE; | |
ee065d83 PB |
207 | /* Must be long enough to hold any of the names in arm_cpus. */ |
208 | static char selected_cpu_name[16]; | |
7cc69913 | 209 | #ifdef OBJ_ELF |
deeaaff8 DJ |
210 | # ifdef EABI_DEFAULT |
211 | static int meabi_flags = EABI_DEFAULT; | |
212 | # else | |
d507cf36 | 213 | static int meabi_flags = EF_ARM_EABI_UNKNOWN; |
deeaaff8 | 214 | # endif |
7cc69913 | 215 | #endif |
b99bd4ef | 216 | |
b99bd4ef | 217 | #ifdef OBJ_ELF |
c19d1205 | 218 | /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ |
b99bd4ef NC |
219 | symbolS * GOT_symbol; |
220 | #endif | |
221 | ||
b99bd4ef NC |
222 | /* 0: assemble for ARM, |
223 | 1: assemble for Thumb, | |
224 | 2: assemble for Thumb even though target CPU does not support thumb | |
225 | instructions. */ | |
226 | static int thumb_mode = 0; | |
227 | ||
c19d1205 ZW |
228 | /* If unified_syntax is true, we are processing the new unified |
229 | ARM/Thumb syntax. Important differences from the old ARM mode: | |
230 | ||
231 | - Immediate operands do not require a # prefix. | |
232 | - Conditional affixes always appear at the end of the | |
233 | instruction. (For backward compatibility, those instructions | |
234 | that formerly had them in the middle, continue to accept them | |
235 | there.) | |
236 | - The IT instruction may appear, and if it does is validated | |
237 | against subsequent conditional affixes. It does not generate | |
238 | machine code. | |
239 | ||
240 | Important differences from the old Thumb mode: | |
241 | ||
242 | - Immediate operands do not require a # prefix. | |
243 | - Most of the V6T2 instructions are only available in unified mode. | |
244 | - The .N and .W suffixes are recognized and honored (it is an error | |
245 | if they cannot be honored). | |
246 | - All instructions set the flags if and only if they have an 's' affix. | |
247 | - Conditional affixes may be used. They are validated against | |
248 | preceding IT instructions. Unlike ARM mode, you cannot use a | |
249 | conditional affix except in the scope of an IT instruction. */ | |
250 | ||
251 | static bfd_boolean unified_syntax = FALSE; | |
b99bd4ef NC |
252 | |
253 | struct arm_it | |
254 | { | |
c19d1205 | 255 | const char * error; |
b99bd4ef | 256 | unsigned long instruction; |
c19d1205 ZW |
257 | int size; |
258 | int size_req; | |
259 | int cond; | |
0110f2b8 PB |
260 | /* Set to the opcode if the instruction needs relaxation. |
261 | Zero if the instruction is not relaxed. */ | |
262 | unsigned long relax; | |
b99bd4ef NC |
263 | struct |
264 | { | |
265 | bfd_reloc_code_real_type type; | |
c19d1205 ZW |
266 | expressionS exp; |
267 | int pc_rel; | |
b99bd4ef | 268 | } reloc; |
b99bd4ef | 269 | |
c19d1205 ZW |
270 | struct |
271 | { | |
272 | unsigned reg; | |
ca3f61f7 NC |
273 | signed int imm; |
274 | unsigned present : 1; /* Operand present. */ | |
275 | unsigned isreg : 1; /* Operand was a register. */ | |
276 | unsigned immisreg : 1; /* .imm field is a second register. */ | |
277 | unsigned hasreloc : 1; /* Operand has relocation suffix. */ | |
278 | unsigned writeback : 1; /* Operand has trailing ! */ | |
279 | unsigned preind : 1; /* Preindexed address. */ | |
280 | unsigned postind : 1; /* Postindexed address. */ | |
281 | unsigned negative : 1; /* Index register was negated. */ | |
282 | unsigned shifted : 1; /* Shift applied to operation. */ | |
283 | unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */ | |
c19d1205 | 284 | } operands[6]; |
b99bd4ef NC |
285 | }; |
286 | ||
c19d1205 | 287 | static struct arm_it inst; |
b99bd4ef NC |
288 | |
289 | #define NUM_FLOAT_VALS 8 | |
290 | ||
05d2d07e | 291 | const char * fp_const[] = |
b99bd4ef NC |
292 | { |
293 | "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0 | |
294 | }; | |
295 | ||
c19d1205 | 296 | /* Number of littlenums required to hold an extended precision number. */ |
b99bd4ef NC |
297 | #define MAX_LITTLENUMS 6 |
298 | ||
299 | LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS]; | |
300 | ||
301 | #define FAIL (-1) | |
302 | #define SUCCESS (0) | |
303 | ||
304 | #define SUFF_S 1 | |
305 | #define SUFF_D 2 | |
306 | #define SUFF_E 3 | |
307 | #define SUFF_P 4 | |
308 | ||
c19d1205 ZW |
309 | #define CP_T_X 0x00008000 |
310 | #define CP_T_Y 0x00400000 | |
b99bd4ef | 311 | |
c19d1205 ZW |
312 | #define CONDS_BIT 0x00100000 |
313 | #define LOAD_BIT 0x00100000 | |
b99bd4ef NC |
314 | |
315 | #define DOUBLE_LOAD_FLAG 0x00000001 | |
316 | ||
317 | struct asm_cond | |
318 | { | |
c19d1205 | 319 | const char * template; |
b99bd4ef NC |
320 | unsigned long value; |
321 | }; | |
322 | ||
c19d1205 | 323 | #define COND_ALWAYS 0xE |
b99bd4ef | 324 | |
b99bd4ef NC |
325 | struct asm_psr |
326 | { | |
b34976b6 | 327 | const char *template; |
b99bd4ef NC |
328 | unsigned long field; |
329 | }; | |
330 | ||
2d2255b5 | 331 | /* The bit that distinguishes CPSR and SPSR. */ |
b99bd4ef NC |
332 | #define SPSR_BIT (1 << 22) |
333 | ||
c19d1205 ZW |
334 | /* The individual PSR flag bits. */ |
335 | #define PSR_c (1 << 16) | |
336 | #define PSR_x (1 << 17) | |
337 | #define PSR_s (1 << 18) | |
338 | #define PSR_f (1 << 19) | |
b99bd4ef | 339 | |
c19d1205 | 340 | struct reloc_entry |
bfae80f2 | 341 | { |
c19d1205 ZW |
342 | char *name; |
343 | bfd_reloc_code_real_type reloc; | |
bfae80f2 RE |
344 | }; |
345 | ||
346 | enum vfp_sp_reg_pos | |
347 | { | |
348 | VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn | |
349 | }; | |
350 | ||
351 | enum vfp_ldstm_type | |
352 | { | |
353 | VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX | |
354 | }; | |
355 | ||
c19d1205 ZW |
356 | /* ARM register categories. This includes coprocessor numbers and various |
357 | architecture extensions' registers. */ | |
358 | enum arm_reg_type | |
bfae80f2 | 359 | { |
c19d1205 ZW |
360 | REG_TYPE_RN, |
361 | REG_TYPE_CP, | |
362 | REG_TYPE_CN, | |
363 | REG_TYPE_FN, | |
364 | REG_TYPE_VFS, | |
365 | REG_TYPE_VFD, | |
366 | REG_TYPE_VFC, | |
367 | REG_TYPE_MVF, | |
368 | REG_TYPE_MVD, | |
369 | REG_TYPE_MVFX, | |
370 | REG_TYPE_MVDX, | |
371 | REG_TYPE_MVAX, | |
372 | REG_TYPE_DSPSC, | |
373 | REG_TYPE_MMXWR, | |
374 | REG_TYPE_MMXWC, | |
375 | REG_TYPE_MMXWCG, | |
376 | REG_TYPE_XSCALE, | |
bfae80f2 RE |
377 | }; |
378 | ||
6c43fab6 RE |
379 | /* Structure for a hash table entry for a register. */ |
380 | struct reg_entry | |
381 | { | |
c19d1205 ZW |
382 | const char *name; |
383 | unsigned char number; | |
384 | unsigned char type; | |
385 | unsigned char builtin; | |
6c43fab6 RE |
386 | }; |
387 | ||
c19d1205 ZW |
388 | /* Diagnostics used when we don't get a register of the expected type. */ |
389 | const char *const reg_expected_msgs[] = | |
390 | { | |
391 | N_("ARM register expected"), | |
392 | N_("bad or missing co-processor number"), | |
393 | N_("co-processor register expected"), | |
394 | N_("FPA register expected"), | |
395 | N_("VFP single precision register expected"), | |
396 | N_("VFP double precision register expected"), | |
397 | N_("VFP system register expected"), | |
398 | N_("Maverick MVF register expected"), | |
399 | N_("Maverick MVD register expected"), | |
400 | N_("Maverick MVFX register expected"), | |
401 | N_("Maverick MVDX register expected"), | |
402 | N_("Maverick MVAX register expected"), | |
403 | N_("Maverick DSPSC register expected"), | |
404 | N_("iWMMXt data register expected"), | |
405 | N_("iWMMXt control register expected"), | |
406 | N_("iWMMXt scalar register expected"), | |
407 | N_("XScale accumulator register expected"), | |
6c43fab6 RE |
408 | }; |
409 | ||
c19d1205 ZW |
410 | /* Some well known registers that we refer to directly elsewhere. */ |
411 | #define REG_SP 13 | |
412 | #define REG_LR 14 | |
413 | #define REG_PC 15 | |
404ff6b5 | 414 | |
b99bd4ef NC |
415 | /* ARM instructions take 4bytes in the object file, Thumb instructions |
416 | take 2: */ | |
c19d1205 | 417 | #define INSN_SIZE 4 |
b99bd4ef NC |
418 | |
419 | struct asm_opcode | |
420 | { | |
421 | /* Basic string to match. */ | |
c19d1205 ZW |
422 | const char *template; |
423 | ||
424 | /* Parameters to instruction. */ | |
425 | unsigned char operands[8]; | |
426 | ||
427 | /* Conditional tag - see opcode_lookup. */ | |
428 | unsigned int tag : 4; | |
b99bd4ef NC |
429 | |
430 | /* Basic instruction code. */ | |
c19d1205 | 431 | unsigned int avalue : 28; |
b99bd4ef | 432 | |
c19d1205 ZW |
433 | /* Thumb-format instruction code. */ |
434 | unsigned int tvalue; | |
b99bd4ef | 435 | |
90e4755a | 436 | /* Which architecture variant provides this instruction. */ |
e74cfd16 PB |
437 | const arm_feature_set *avariant; |
438 | const arm_feature_set *tvariant; | |
c19d1205 ZW |
439 | |
440 | /* Function to call to encode instruction in ARM format. */ | |
441 | void (* aencode) (void); | |
b99bd4ef | 442 | |
c19d1205 ZW |
443 | /* Function to call to encode instruction in Thumb format. */ |
444 | void (* tencode) (void); | |
b99bd4ef NC |
445 | }; |
446 | ||
a737bd4d NC |
447 | /* Defines for various bits that we will want to toggle. */ |
448 | #define INST_IMMEDIATE 0x02000000 | |
449 | #define OFFSET_REG 0x02000000 | |
c19d1205 | 450 | #define HWOFFSET_IMM 0x00400000 |
a737bd4d NC |
451 | #define SHIFT_BY_REG 0x00000010 |
452 | #define PRE_INDEX 0x01000000 | |
453 | #define INDEX_UP 0x00800000 | |
454 | #define WRITE_BACK 0x00200000 | |
455 | #define LDM_TYPE_2_OR_3 0x00400000 | |
90e4755a | 456 | |
a737bd4d NC |
457 | #define LITERAL_MASK 0xf000f000 |
458 | #define OPCODE_MASK 0xfe1fffff | |
459 | #define V4_STR_BIT 0x00000020 | |
90e4755a | 460 | |
a737bd4d | 461 | #define DATA_OP_SHIFT 21 |
90e4755a | 462 | |
ef8d22e6 PB |
463 | #define T2_OPCODE_MASK 0xfe1fffff |
464 | #define T2_DATA_OP_SHIFT 21 | |
465 | ||
a737bd4d NC |
466 | /* Codes to distinguish the arithmetic instructions. */ |
467 | #define OPCODE_AND 0 | |
468 | #define OPCODE_EOR 1 | |
469 | #define OPCODE_SUB 2 | |
470 | #define OPCODE_RSB 3 | |
471 | #define OPCODE_ADD 4 | |
472 | #define OPCODE_ADC 5 | |
473 | #define OPCODE_SBC 6 | |
474 | #define OPCODE_RSC 7 | |
475 | #define OPCODE_TST 8 | |
476 | #define OPCODE_TEQ 9 | |
477 | #define OPCODE_CMP 10 | |
478 | #define OPCODE_CMN 11 | |
479 | #define OPCODE_ORR 12 | |
480 | #define OPCODE_MOV 13 | |
481 | #define OPCODE_BIC 14 | |
482 | #define OPCODE_MVN 15 | |
90e4755a | 483 | |
ef8d22e6 PB |
484 | #define T2_OPCODE_AND 0 |
485 | #define T2_OPCODE_BIC 1 | |
486 | #define T2_OPCODE_ORR 2 | |
487 | #define T2_OPCODE_ORN 3 | |
488 | #define T2_OPCODE_EOR 4 | |
489 | #define T2_OPCODE_ADD 8 | |
490 | #define T2_OPCODE_ADC 10 | |
491 | #define T2_OPCODE_SBC 11 | |
492 | #define T2_OPCODE_SUB 13 | |
493 | #define T2_OPCODE_RSB 14 | |
494 | ||
a737bd4d NC |
495 | #define T_OPCODE_MUL 0x4340 |
496 | #define T_OPCODE_TST 0x4200 | |
497 | #define T_OPCODE_CMN 0x42c0 | |
498 | #define T_OPCODE_NEG 0x4240 | |
499 | #define T_OPCODE_MVN 0x43c0 | |
90e4755a | 500 | |
a737bd4d NC |
501 | #define T_OPCODE_ADD_R3 0x1800 |
502 | #define T_OPCODE_SUB_R3 0x1a00 | |
503 | #define T_OPCODE_ADD_HI 0x4400 | |
504 | #define T_OPCODE_ADD_ST 0xb000 | |
505 | #define T_OPCODE_SUB_ST 0xb080 | |
506 | #define T_OPCODE_ADD_SP 0xa800 | |
507 | #define T_OPCODE_ADD_PC 0xa000 | |
508 | #define T_OPCODE_ADD_I8 0x3000 | |
509 | #define T_OPCODE_SUB_I8 0x3800 | |
510 | #define T_OPCODE_ADD_I3 0x1c00 | |
511 | #define T_OPCODE_SUB_I3 0x1e00 | |
b99bd4ef | 512 | |
a737bd4d NC |
513 | #define T_OPCODE_ASR_R 0x4100 |
514 | #define T_OPCODE_LSL_R 0x4080 | |
c19d1205 ZW |
515 | #define T_OPCODE_LSR_R 0x40c0 |
516 | #define T_OPCODE_ROR_R 0x41c0 | |
a737bd4d NC |
517 | #define T_OPCODE_ASR_I 0x1000 |
518 | #define T_OPCODE_LSL_I 0x0000 | |
519 | #define T_OPCODE_LSR_I 0x0800 | |
b99bd4ef | 520 | |
a737bd4d NC |
521 | #define T_OPCODE_MOV_I8 0x2000 |
522 | #define T_OPCODE_CMP_I8 0x2800 | |
523 | #define T_OPCODE_CMP_LR 0x4280 | |
524 | #define T_OPCODE_MOV_HR 0x4600 | |
525 | #define T_OPCODE_CMP_HR 0x4500 | |
b99bd4ef | 526 | |
a737bd4d NC |
527 | #define T_OPCODE_LDR_PC 0x4800 |
528 | #define T_OPCODE_LDR_SP 0x9800 | |
529 | #define T_OPCODE_STR_SP 0x9000 | |
530 | #define T_OPCODE_LDR_IW 0x6800 | |
531 | #define T_OPCODE_STR_IW 0x6000 | |
532 | #define T_OPCODE_LDR_IH 0x8800 | |
533 | #define T_OPCODE_STR_IH 0x8000 | |
534 | #define T_OPCODE_LDR_IB 0x7800 | |
535 | #define T_OPCODE_STR_IB 0x7000 | |
536 | #define T_OPCODE_LDR_RW 0x5800 | |
537 | #define T_OPCODE_STR_RW 0x5000 | |
538 | #define T_OPCODE_LDR_RH 0x5a00 | |
539 | #define T_OPCODE_STR_RH 0x5200 | |
540 | #define T_OPCODE_LDR_RB 0x5c00 | |
541 | #define T_OPCODE_STR_RB 0x5400 | |
c9b604bd | 542 | |
a737bd4d NC |
543 | #define T_OPCODE_PUSH 0xb400 |
544 | #define T_OPCODE_POP 0xbc00 | |
b99bd4ef | 545 | |
2fc8bdac | 546 | #define T_OPCODE_BRANCH 0xe000 |
b99bd4ef | 547 | |
a737bd4d | 548 | #define THUMB_SIZE 2 /* Size of thumb instruction. */ |
a737bd4d | 549 | #define THUMB_PP_PC_LR 0x0100 |
c19d1205 ZW |
550 | #define THUMB_LOAD_BIT 0x0800 |
551 | ||
552 | #define BAD_ARGS _("bad arguments to instruction") | |
553 | #define BAD_PC _("r15 not allowed here") | |
554 | #define BAD_COND _("instruction cannot be conditional") | |
555 | #define BAD_OVERLAP _("registers may not be the same") | |
556 | #define BAD_HIREG _("lo register required") | |
557 | #define BAD_THUMB32 _("instruction not supported in Thumb16 mode") | |
01cfc07f | 558 | #define BAD_ADDR_MODE _("instruction does not accept this addressing mode"); |
c19d1205 ZW |
559 | |
560 | static struct hash_control *arm_ops_hsh; | |
561 | static struct hash_control *arm_cond_hsh; | |
562 | static struct hash_control *arm_shift_hsh; | |
563 | static struct hash_control *arm_psr_hsh; | |
564 | static struct hash_control *arm_reg_hsh; | |
565 | static struct hash_control *arm_reloc_hsh; | |
b99bd4ef | 566 | |
b99bd4ef NC |
567 | /* Stuff needed to resolve the label ambiguity |
568 | As: | |
569 | ... | |
570 | label: <insn> | |
571 | may differ from: | |
572 | ... | |
573 | label: | |
c19d1205 | 574 | <insn> |
b99bd4ef NC |
575 | */ |
576 | ||
577 | symbolS * last_label_seen; | |
b34976b6 | 578 | static int label_is_thumb_function_name = FALSE; |
a737bd4d | 579 | \f |
3d0c9500 NC |
580 | /* Literal pool structure. Held on a per-section |
581 | and per-sub-section basis. */ | |
a737bd4d | 582 | |
c19d1205 | 583 | #define MAX_LITERAL_POOL_SIZE 1024 |
3d0c9500 | 584 | typedef struct literal_pool |
b99bd4ef | 585 | { |
c19d1205 ZW |
586 | expressionS literals [MAX_LITERAL_POOL_SIZE]; |
587 | unsigned int next_free_entry; | |
588 | unsigned int id; | |
589 | symbolS * symbol; | |
590 | segT section; | |
591 | subsegT sub_section; | |
61b5f74b | 592 | struct literal_pool * next; |
3d0c9500 | 593 | } literal_pool; |
b99bd4ef | 594 | |
3d0c9500 NC |
595 | /* Pointer to a linked list of literal pools. */ |
596 | literal_pool * list_of_pools = NULL; | |
e27ec89e PB |
597 | |
598 | /* State variables for IT block handling. */ | |
599 | static bfd_boolean current_it_mask = 0; | |
600 | static int current_cc; | |
601 | ||
c19d1205 ZW |
602 | \f |
603 | /* Pure syntax. */ | |
b99bd4ef | 604 | |
c19d1205 ZW |
605 | /* This array holds the chars that always start a comment. If the |
606 | pre-processor is disabled, these aren't very useful. */ | |
607 | const char comment_chars[] = "@"; | |
3d0c9500 | 608 | |
c19d1205 ZW |
609 | /* This array holds the chars that only start a comment at the beginning of |
610 | a line. If the line seems to have the form '# 123 filename' | |
611 | .line and .file directives will appear in the pre-processed output. */ | |
612 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
613 | first line of the input file. This is because the compiler outputs | |
614 | #NO_APP at the beginning of its output. */ | |
615 | /* Also note that comments like this one will always work. */ | |
616 | const char line_comment_chars[] = "#"; | |
3d0c9500 | 617 | |
c19d1205 | 618 | const char line_separator_chars[] = ";"; |
b99bd4ef | 619 | |
c19d1205 ZW |
620 | /* Chars that can be used to separate mant |
621 | from exp in floating point numbers. */ | |
622 | const char EXP_CHARS[] = "eE"; | |
3d0c9500 | 623 | |
c19d1205 ZW |
624 | /* Chars that mean this number is a floating point constant. */ |
625 | /* As in 0f12.456 */ | |
626 | /* or 0d1.2345e12 */ | |
b99bd4ef | 627 | |
c19d1205 | 628 | const char FLT_CHARS[] = "rRsSfFdDxXeEpP"; |
3d0c9500 | 629 | |
c19d1205 ZW |
630 | /* Prefix characters that indicate the start of an immediate |
631 | value. */ | |
632 | #define is_immediate_prefix(C) ((C) == '#' || (C) == '$') | |
3d0c9500 | 633 | |
c19d1205 ZW |
634 | /* Separator character handling. */ |
635 | ||
636 | #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0) | |
637 | ||
638 | static inline int | |
639 | skip_past_char (char ** str, char c) | |
640 | { | |
641 | if (**str == c) | |
642 | { | |
643 | (*str)++; | |
644 | return SUCCESS; | |
3d0c9500 | 645 | } |
c19d1205 ZW |
646 | else |
647 | return FAIL; | |
648 | } | |
649 | #define skip_past_comma(str) skip_past_char (str, ',') | |
3d0c9500 | 650 | |
c19d1205 ZW |
651 | /* Arithmetic expressions (possibly involving symbols). */ |
652 | ||
653 | /* Return TRUE if anything in the expression is a bignum. */ | |
654 | ||
655 | static int | |
656 | walk_no_bignums (symbolS * sp) | |
657 | { | |
658 | if (symbol_get_value_expression (sp)->X_op == O_big) | |
659 | return 1; | |
660 | ||
661 | if (symbol_get_value_expression (sp)->X_add_symbol) | |
3d0c9500 | 662 | { |
c19d1205 ZW |
663 | return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol) |
664 | || (symbol_get_value_expression (sp)->X_op_symbol | |
665 | && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol))); | |
3d0c9500 NC |
666 | } |
667 | ||
c19d1205 | 668 | return 0; |
3d0c9500 NC |
669 | } |
670 | ||
c19d1205 ZW |
671 | static int in_my_get_expression = 0; |
672 | ||
673 | /* Third argument to my_get_expression. */ | |
674 | #define GE_NO_PREFIX 0 | |
675 | #define GE_IMM_PREFIX 1 | |
676 | #define GE_OPT_PREFIX 2 | |
a737bd4d | 677 | |
b99bd4ef | 678 | static int |
c19d1205 | 679 | my_get_expression (expressionS * ep, char ** str, int prefix_mode) |
b99bd4ef | 680 | { |
c19d1205 ZW |
681 | char * save_in; |
682 | segT seg; | |
b99bd4ef | 683 | |
c19d1205 ZW |
684 | /* In unified syntax, all prefixes are optional. */ |
685 | if (unified_syntax) | |
686 | prefix_mode = GE_OPT_PREFIX; | |
b99bd4ef | 687 | |
c19d1205 | 688 | switch (prefix_mode) |
b99bd4ef | 689 | { |
c19d1205 ZW |
690 | case GE_NO_PREFIX: break; |
691 | case GE_IMM_PREFIX: | |
692 | if (!is_immediate_prefix (**str)) | |
693 | { | |
694 | inst.error = _("immediate expression requires a # prefix"); | |
695 | return FAIL; | |
696 | } | |
697 | (*str)++; | |
698 | break; | |
699 | case GE_OPT_PREFIX: | |
700 | if (is_immediate_prefix (**str)) | |
701 | (*str)++; | |
702 | break; | |
703 | default: abort (); | |
704 | } | |
b99bd4ef | 705 | |
c19d1205 | 706 | memset (ep, 0, sizeof (expressionS)); |
b99bd4ef | 707 | |
c19d1205 ZW |
708 | save_in = input_line_pointer; |
709 | input_line_pointer = *str; | |
710 | in_my_get_expression = 1; | |
711 | seg = expression (ep); | |
712 | in_my_get_expression = 0; | |
713 | ||
714 | if (ep->X_op == O_illegal) | |
b99bd4ef | 715 | { |
c19d1205 ZW |
716 | /* We found a bad expression in md_operand(). */ |
717 | *str = input_line_pointer; | |
718 | input_line_pointer = save_in; | |
719 | if (inst.error == NULL) | |
720 | inst.error = _("bad expression"); | |
721 | return 1; | |
722 | } | |
b99bd4ef | 723 | |
c19d1205 ZW |
724 | #ifdef OBJ_AOUT |
725 | if (seg != absolute_section | |
726 | && seg != text_section | |
727 | && seg != data_section | |
728 | && seg != bss_section | |
729 | && seg != undefined_section) | |
730 | { | |
731 | inst.error = _("bad segment"); | |
732 | *str = input_line_pointer; | |
733 | input_line_pointer = save_in; | |
734 | return 1; | |
b99bd4ef | 735 | } |
c19d1205 | 736 | #endif |
b99bd4ef | 737 | |
c19d1205 ZW |
738 | /* Get rid of any bignums now, so that we don't generate an error for which |
739 | we can't establish a line number later on. Big numbers are never valid | |
740 | in instructions, which is where this routine is always called. */ | |
741 | if (ep->X_op == O_big | |
742 | || (ep->X_add_symbol | |
743 | && (walk_no_bignums (ep->X_add_symbol) | |
744 | || (ep->X_op_symbol | |
745 | && walk_no_bignums (ep->X_op_symbol))))) | |
746 | { | |
747 | inst.error = _("invalid constant"); | |
748 | *str = input_line_pointer; | |
749 | input_line_pointer = save_in; | |
750 | return 1; | |
751 | } | |
b99bd4ef | 752 | |
c19d1205 ZW |
753 | *str = input_line_pointer; |
754 | input_line_pointer = save_in; | |
755 | return 0; | |
b99bd4ef NC |
756 | } |
757 | ||
c19d1205 ZW |
758 | /* Turn a string in input_line_pointer into a floating point constant |
759 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
760 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
761 | returned, or NULL on OK. | |
b99bd4ef | 762 | |
c19d1205 ZW |
763 | Note that fp constants aren't represent in the normal way on the ARM. |
764 | In big endian mode, things are as expected. However, in little endian | |
765 | mode fp constants are big-endian word-wise, and little-endian byte-wise | |
766 | within the words. For example, (double) 1.1 in big endian mode is | |
767 | the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is | |
768 | the byte sequence 99 99 f1 3f 9a 99 99 99. | |
b99bd4ef | 769 | |
c19d1205 | 770 | ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */ |
b99bd4ef | 771 | |
c19d1205 ZW |
772 | char * |
773 | md_atof (int type, char * litP, int * sizeP) | |
774 | { | |
775 | int prec; | |
776 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
777 | char *t; | |
778 | int i; | |
b99bd4ef | 779 | |
c19d1205 ZW |
780 | switch (type) |
781 | { | |
782 | case 'f': | |
783 | case 'F': | |
784 | case 's': | |
785 | case 'S': | |
786 | prec = 2; | |
787 | break; | |
b99bd4ef | 788 | |
c19d1205 ZW |
789 | case 'd': |
790 | case 'D': | |
791 | case 'r': | |
792 | case 'R': | |
793 | prec = 4; | |
794 | break; | |
b99bd4ef | 795 | |
c19d1205 ZW |
796 | case 'x': |
797 | case 'X': | |
798 | prec = 6; | |
799 | break; | |
b99bd4ef | 800 | |
c19d1205 ZW |
801 | case 'p': |
802 | case 'P': | |
803 | prec = 6; | |
804 | break; | |
a737bd4d | 805 | |
c19d1205 ZW |
806 | default: |
807 | *sizeP = 0; | |
808 | return _("bad call to MD_ATOF()"); | |
809 | } | |
b99bd4ef | 810 | |
c19d1205 ZW |
811 | t = atof_ieee (input_line_pointer, type, words); |
812 | if (t) | |
813 | input_line_pointer = t; | |
814 | *sizeP = prec * 2; | |
b99bd4ef | 815 | |
c19d1205 ZW |
816 | if (target_big_endian) |
817 | { | |
818 | for (i = 0; i < prec; i++) | |
819 | { | |
820 | md_number_to_chars (litP, (valueT) words[i], 2); | |
821 | litP += 2; | |
822 | } | |
823 | } | |
824 | else | |
825 | { | |
e74cfd16 | 826 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) |
c19d1205 ZW |
827 | for (i = prec - 1; i >= 0; i--) |
828 | { | |
829 | md_number_to_chars (litP, (valueT) words[i], 2); | |
830 | litP += 2; | |
831 | } | |
832 | else | |
833 | /* For a 4 byte float the order of elements in `words' is 1 0. | |
834 | For an 8 byte float the order is 1 0 3 2. */ | |
835 | for (i = 0; i < prec; i += 2) | |
836 | { | |
837 | md_number_to_chars (litP, (valueT) words[i + 1], 2); | |
838 | md_number_to_chars (litP + 2, (valueT) words[i], 2); | |
839 | litP += 4; | |
840 | } | |
841 | } | |
b99bd4ef | 842 | |
c19d1205 ZW |
843 | return 0; |
844 | } | |
b99bd4ef | 845 | |
c19d1205 ZW |
846 | /* We handle all bad expressions here, so that we can report the faulty |
847 | instruction in the error message. */ | |
848 | void | |
849 | md_operand (expressionS * expr) | |
850 | { | |
851 | if (in_my_get_expression) | |
852 | expr->X_op = O_illegal; | |
b99bd4ef NC |
853 | } |
854 | ||
c19d1205 | 855 | /* Immediate values. */ |
b99bd4ef | 856 | |
c19d1205 ZW |
857 | /* Generic immediate-value read function for use in directives. |
858 | Accepts anything that 'expression' can fold to a constant. | |
859 | *val receives the number. */ | |
860 | #ifdef OBJ_ELF | |
861 | static int | |
862 | immediate_for_directive (int *val) | |
b99bd4ef | 863 | { |
c19d1205 ZW |
864 | expressionS exp; |
865 | exp.X_op = O_illegal; | |
b99bd4ef | 866 | |
c19d1205 ZW |
867 | if (is_immediate_prefix (*input_line_pointer)) |
868 | { | |
869 | input_line_pointer++; | |
870 | expression (&exp); | |
871 | } | |
b99bd4ef | 872 | |
c19d1205 ZW |
873 | if (exp.X_op != O_constant) |
874 | { | |
875 | as_bad (_("expected #constant")); | |
876 | ignore_rest_of_line (); | |
877 | return FAIL; | |
878 | } | |
879 | *val = exp.X_add_number; | |
880 | return SUCCESS; | |
b99bd4ef | 881 | } |
c19d1205 | 882 | #endif |
b99bd4ef | 883 | |
c19d1205 | 884 | /* Register parsing. */ |
b99bd4ef | 885 | |
c19d1205 ZW |
886 | /* Generic register parser. CCP points to what should be the |
887 | beginning of a register name. If it is indeed a valid register | |
888 | name, advance CCP over it and return the reg_entry structure; | |
889 | otherwise return NULL. Does not issue diagnostics. */ | |
890 | ||
891 | static struct reg_entry * | |
892 | arm_reg_parse_multi (char **ccp) | |
b99bd4ef | 893 | { |
c19d1205 ZW |
894 | char *start = *ccp; |
895 | char *p; | |
896 | struct reg_entry *reg; | |
b99bd4ef | 897 | |
c19d1205 ZW |
898 | #ifdef REGISTER_PREFIX |
899 | if (*start != REGISTER_PREFIX) | |
01cfc07f | 900 | return NULL; |
c19d1205 ZW |
901 | start++; |
902 | #endif | |
903 | #ifdef OPTIONAL_REGISTER_PREFIX | |
904 | if (*start == OPTIONAL_REGISTER_PREFIX) | |
905 | start++; | |
906 | #endif | |
b99bd4ef | 907 | |
c19d1205 ZW |
908 | p = start; |
909 | if (!ISALPHA (*p) || !is_name_beginner (*p)) | |
910 | return NULL; | |
b99bd4ef | 911 | |
c19d1205 ZW |
912 | do |
913 | p++; | |
914 | while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_'); | |
915 | ||
916 | reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start); | |
917 | ||
918 | if (!reg) | |
919 | return NULL; | |
920 | ||
921 | *ccp = p; | |
922 | return reg; | |
b99bd4ef NC |
923 | } |
924 | ||
c19d1205 | 925 | /* As above, but the register must be of type TYPE, and the return |
01cfc07f | 926 | value is the register number or FAIL. */ |
c19d1205 | 927 | |
b99bd4ef | 928 | static int |
c19d1205 | 929 | arm_reg_parse (char **ccp, enum arm_reg_type type) |
b99bd4ef | 930 | { |
c19d1205 ZW |
931 | char *start = *ccp; |
932 | struct reg_entry *reg = arm_reg_parse_multi (ccp); | |
b99bd4ef | 933 | |
c19d1205 ZW |
934 | if (reg && reg->type == type) |
935 | return reg->number; | |
6057a28f | 936 | |
c19d1205 ZW |
937 | /* Alternative syntaxes are accepted for a few register classes. */ |
938 | switch (type) | |
939 | { | |
940 | case REG_TYPE_MVF: | |
941 | case REG_TYPE_MVD: | |
942 | case REG_TYPE_MVFX: | |
943 | case REG_TYPE_MVDX: | |
944 | /* Generic coprocessor register names are allowed for these. */ | |
79134647 | 945 | if (reg && reg->type == REG_TYPE_CN) |
c19d1205 ZW |
946 | return reg->number; |
947 | break; | |
69b97547 | 948 | |
c19d1205 ZW |
949 | case REG_TYPE_CP: |
950 | /* For backward compatibility, a bare number is valid here. */ | |
951 | { | |
952 | unsigned long processor = strtoul (start, ccp, 10); | |
953 | if (*ccp != start && processor <= 15) | |
954 | return processor; | |
955 | } | |
6057a28f | 956 | |
c19d1205 ZW |
957 | case REG_TYPE_MMXWC: |
958 | /* WC includes WCG. ??? I'm not sure this is true for all | |
959 | instructions that take WC registers. */ | |
79134647 | 960 | if (reg && reg->type == REG_TYPE_MMXWCG) |
c19d1205 | 961 | return reg->number; |
6057a28f | 962 | break; |
c19d1205 | 963 | |
6057a28f | 964 | default: |
c19d1205 | 965 | break; |
6057a28f NC |
966 | } |
967 | ||
c19d1205 ZW |
968 | *ccp = start; |
969 | return FAIL; | |
970 | } | |
69b97547 | 971 | |
c19d1205 ZW |
972 | /* Parse an ARM register list. Returns the bitmask, or FAIL. */ |
973 | static long | |
974 | parse_reg_list (char ** strp) | |
975 | { | |
976 | char * str = * strp; | |
977 | long range = 0; | |
978 | int another_range; | |
a737bd4d | 979 | |
c19d1205 ZW |
980 | /* We come back here if we get ranges concatenated by '+' or '|'. */ |
981 | do | |
6057a28f | 982 | { |
c19d1205 | 983 | another_range = 0; |
a737bd4d | 984 | |
c19d1205 ZW |
985 | if (*str == '{') |
986 | { | |
987 | int in_range = 0; | |
988 | int cur_reg = -1; | |
a737bd4d | 989 | |
c19d1205 ZW |
990 | str++; |
991 | do | |
992 | { | |
993 | int reg; | |
6057a28f | 994 | |
c19d1205 ZW |
995 | if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL) |
996 | { | |
997 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
998 | return FAIL; | |
999 | } | |
a737bd4d | 1000 | |
c19d1205 ZW |
1001 | if (in_range) |
1002 | { | |
1003 | int i; | |
a737bd4d | 1004 | |
c19d1205 ZW |
1005 | if (reg <= cur_reg) |
1006 | { | |
1007 | inst.error = _("bad range in register list"); | |
1008 | return FAIL; | |
1009 | } | |
40a18ebd | 1010 | |
c19d1205 ZW |
1011 | for (i = cur_reg + 1; i < reg; i++) |
1012 | { | |
1013 | if (range & (1 << i)) | |
1014 | as_tsktsk | |
1015 | (_("Warning: duplicated register (r%d) in register list"), | |
1016 | i); | |
1017 | else | |
1018 | range |= 1 << i; | |
1019 | } | |
1020 | in_range = 0; | |
1021 | } | |
a737bd4d | 1022 | |
c19d1205 ZW |
1023 | if (range & (1 << reg)) |
1024 | as_tsktsk (_("Warning: duplicated register (r%d) in register list"), | |
1025 | reg); | |
1026 | else if (reg <= cur_reg) | |
1027 | as_tsktsk (_("Warning: register range not in ascending order")); | |
a737bd4d | 1028 | |
c19d1205 ZW |
1029 | range |= 1 << reg; |
1030 | cur_reg = reg; | |
1031 | } | |
1032 | while (skip_past_comma (&str) != FAIL | |
1033 | || (in_range = 1, *str++ == '-')); | |
1034 | str--; | |
a737bd4d | 1035 | |
c19d1205 ZW |
1036 | if (*str++ != '}') |
1037 | { | |
1038 | inst.error = _("missing `}'"); | |
1039 | return FAIL; | |
1040 | } | |
1041 | } | |
1042 | else | |
1043 | { | |
1044 | expressionS expr; | |
40a18ebd | 1045 | |
c19d1205 ZW |
1046 | if (my_get_expression (&expr, &str, GE_NO_PREFIX)) |
1047 | return FAIL; | |
40a18ebd | 1048 | |
c19d1205 ZW |
1049 | if (expr.X_op == O_constant) |
1050 | { | |
1051 | if (expr.X_add_number | |
1052 | != (expr.X_add_number & 0x0000ffff)) | |
1053 | { | |
1054 | inst.error = _("invalid register mask"); | |
1055 | return FAIL; | |
1056 | } | |
a737bd4d | 1057 | |
c19d1205 ZW |
1058 | if ((range & expr.X_add_number) != 0) |
1059 | { | |
1060 | int regno = range & expr.X_add_number; | |
a737bd4d | 1061 | |
c19d1205 ZW |
1062 | regno &= -regno; |
1063 | regno = (1 << regno) - 1; | |
1064 | as_tsktsk | |
1065 | (_("Warning: duplicated register (r%d) in register list"), | |
1066 | regno); | |
1067 | } | |
a737bd4d | 1068 | |
c19d1205 ZW |
1069 | range |= expr.X_add_number; |
1070 | } | |
1071 | else | |
1072 | { | |
1073 | if (inst.reloc.type != 0) | |
1074 | { | |
1075 | inst.error = _("expression too complex"); | |
1076 | return FAIL; | |
1077 | } | |
a737bd4d | 1078 | |
c19d1205 ZW |
1079 | memcpy (&inst.reloc.exp, &expr, sizeof (expressionS)); |
1080 | inst.reloc.type = BFD_RELOC_ARM_MULTI; | |
1081 | inst.reloc.pc_rel = 0; | |
1082 | } | |
1083 | } | |
a737bd4d | 1084 | |
c19d1205 ZW |
1085 | if (*str == '|' || *str == '+') |
1086 | { | |
1087 | str++; | |
1088 | another_range = 1; | |
1089 | } | |
a737bd4d | 1090 | } |
c19d1205 | 1091 | while (another_range); |
a737bd4d | 1092 | |
c19d1205 ZW |
1093 | *strp = str; |
1094 | return range; | |
a737bd4d NC |
1095 | } |
1096 | ||
c19d1205 ZW |
1097 | /* Parse a VFP register list. If the string is invalid return FAIL. |
1098 | Otherwise return the number of registers, and set PBASE to the first | |
1099 | register. Double precision registers are matched if DP is nonzero. */ | |
6057a28f | 1100 | |
c19d1205 | 1101 | static int |
ca3f61f7 | 1102 | parse_vfp_reg_list (char **str, unsigned int *pbase, int dp) |
6057a28f | 1103 | { |
c19d1205 ZW |
1104 | int base_reg; |
1105 | int new_base; | |
1106 | int regtype; | |
1107 | int max_regs; | |
1108 | int count = 0; | |
1109 | int warned = 0; | |
1110 | unsigned long mask = 0; | |
a737bd4d | 1111 | int i; |
6057a28f | 1112 | |
c19d1205 ZW |
1113 | if (**str != '{') |
1114 | return FAIL; | |
6057a28f | 1115 | |
c19d1205 | 1116 | (*str)++; |
6057a28f | 1117 | |
c19d1205 | 1118 | if (dp) |
a737bd4d | 1119 | { |
c19d1205 ZW |
1120 | regtype = REG_TYPE_VFD; |
1121 | max_regs = 16; | |
1122 | } | |
1123 | else | |
1124 | { | |
1125 | regtype = REG_TYPE_VFS; | |
1126 | max_regs = 32; | |
1127 | } | |
6057a28f | 1128 | |
c19d1205 | 1129 | base_reg = max_regs; |
a737bd4d | 1130 | |
c19d1205 ZW |
1131 | do |
1132 | { | |
1133 | new_base = arm_reg_parse (str, regtype); | |
1134 | if (new_base == FAIL) | |
a737bd4d | 1135 | { |
c19d1205 ZW |
1136 | inst.error = gettext (reg_expected_msgs[regtype]); |
1137 | return FAIL; | |
1138 | } | |
a737bd4d | 1139 | |
c19d1205 ZW |
1140 | if (new_base < base_reg) |
1141 | base_reg = new_base; | |
a737bd4d | 1142 | |
c19d1205 ZW |
1143 | if (mask & (1 << new_base)) |
1144 | { | |
1145 | inst.error = _("invalid register list"); | |
1146 | return FAIL; | |
a737bd4d | 1147 | } |
a737bd4d | 1148 | |
c19d1205 ZW |
1149 | if ((mask >> new_base) != 0 && ! warned) |
1150 | { | |
1151 | as_tsktsk (_("register list not in ascending order")); | |
1152 | warned = 1; | |
1153 | } | |
0bbf2aa4 | 1154 | |
c19d1205 ZW |
1155 | mask |= 1 << new_base; |
1156 | count++; | |
0bbf2aa4 | 1157 | |
c19d1205 ZW |
1158 | if (**str == '-') /* We have the start of a range expression */ |
1159 | { | |
1160 | int high_range; | |
0bbf2aa4 | 1161 | |
c19d1205 | 1162 | (*str)++; |
0bbf2aa4 | 1163 | |
c19d1205 ZW |
1164 | if ((high_range = arm_reg_parse (str, regtype)) == FAIL) |
1165 | { | |
1166 | inst.error = gettext (reg_expected_msgs[regtype]); | |
1167 | return FAIL; | |
1168 | } | |
0bbf2aa4 | 1169 | |
c19d1205 ZW |
1170 | if (high_range <= new_base) |
1171 | { | |
1172 | inst.error = _("register range not in ascending order"); | |
1173 | return FAIL; | |
1174 | } | |
0bbf2aa4 | 1175 | |
c19d1205 | 1176 | for (new_base++; new_base <= high_range; new_base++) |
0bbf2aa4 | 1177 | { |
c19d1205 | 1178 | if (mask & (1 << new_base)) |
0bbf2aa4 | 1179 | { |
c19d1205 ZW |
1180 | inst.error = _("invalid register list"); |
1181 | return FAIL; | |
0bbf2aa4 | 1182 | } |
c19d1205 ZW |
1183 | |
1184 | mask |= 1 << new_base; | |
1185 | count++; | |
0bbf2aa4 | 1186 | } |
0bbf2aa4 | 1187 | } |
0bbf2aa4 | 1188 | } |
c19d1205 | 1189 | while (skip_past_comma (str) != FAIL); |
0bbf2aa4 | 1190 | |
c19d1205 | 1191 | (*str)++; |
0bbf2aa4 | 1192 | |
c19d1205 ZW |
1193 | /* Sanity check -- should have raised a parse error above. */ |
1194 | if (count == 0 || count > max_regs) | |
1195 | abort (); | |
1196 | ||
1197 | *pbase = base_reg; | |
1198 | ||
1199 | /* Final test -- the registers must be consecutive. */ | |
1200 | mask >>= base_reg; | |
1201 | for (i = 0; i < count; i++) | |
1202 | { | |
1203 | if ((mask & (1u << i)) == 0) | |
1204 | { | |
1205 | inst.error = _("non-contiguous register range"); | |
1206 | return FAIL; | |
1207 | } | |
1208 | } | |
1209 | ||
1210 | return count; | |
b99bd4ef NC |
1211 | } |
1212 | ||
c19d1205 ZW |
1213 | /* Parse an explicit relocation suffix on an expression. This is |
1214 | either nothing, or a word in parentheses. Note that if !OBJ_ELF, | |
1215 | arm_reloc_hsh contains no entries, so this function can only | |
1216 | succeed if there is no () after the word. Returns -1 on error, | |
1217 | BFD_RELOC_UNUSED if there wasn't any suffix. */ | |
1218 | static int | |
1219 | parse_reloc (char **str) | |
b99bd4ef | 1220 | { |
c19d1205 ZW |
1221 | struct reloc_entry *r; |
1222 | char *p, *q; | |
b99bd4ef | 1223 | |
c19d1205 ZW |
1224 | if (**str != '(') |
1225 | return BFD_RELOC_UNUSED; | |
b99bd4ef | 1226 | |
c19d1205 ZW |
1227 | p = *str + 1; |
1228 | q = p; | |
1229 | ||
1230 | while (*q && *q != ')' && *q != ',') | |
1231 | q++; | |
1232 | if (*q != ')') | |
1233 | return -1; | |
1234 | ||
1235 | if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL) | |
1236 | return -1; | |
1237 | ||
1238 | *str = q + 1; | |
1239 | return r->reloc; | |
b99bd4ef NC |
1240 | } |
1241 | ||
c19d1205 ZW |
1242 | /* Directives: register aliases. */ |
1243 | ||
b99bd4ef | 1244 | static void |
c19d1205 | 1245 | insert_reg_alias (char *str, int number, int type) |
b99bd4ef | 1246 | { |
c19d1205 ZW |
1247 | struct reg_entry *new; |
1248 | const char *name; | |
b99bd4ef | 1249 | |
c19d1205 ZW |
1250 | if ((new = hash_find (arm_reg_hsh, str)) != 0) |
1251 | { | |
1252 | if (new->builtin) | |
1253 | as_warn (_("ignoring attempt to redefine built-in register '%s'"), str); | |
b99bd4ef | 1254 | |
c19d1205 ZW |
1255 | /* Only warn about a redefinition if it's not defined as the |
1256 | same register. */ | |
1257 | else if (new->number != number || new->type != type) | |
1258 | as_warn (_("ignoring redefinition of register alias '%s'"), str); | |
69b97547 | 1259 | |
c19d1205 ZW |
1260 | return; |
1261 | } | |
b99bd4ef | 1262 | |
c19d1205 ZW |
1263 | name = xstrdup (str); |
1264 | new = xmalloc (sizeof (struct reg_entry)); | |
b99bd4ef | 1265 | |
c19d1205 ZW |
1266 | new->name = name; |
1267 | new->number = number; | |
1268 | new->type = type; | |
1269 | new->builtin = FALSE; | |
b99bd4ef | 1270 | |
c19d1205 ZW |
1271 | if (hash_insert (arm_reg_hsh, name, (PTR) new)) |
1272 | abort (); | |
1273 | } | |
b99bd4ef | 1274 | |
c19d1205 | 1275 | /* Look for the .req directive. This is of the form: |
b99bd4ef | 1276 | |
c19d1205 | 1277 | new_register_name .req existing_register_name |
b99bd4ef | 1278 | |
c19d1205 ZW |
1279 | If we find one, or if it looks sufficiently like one that we want to |
1280 | handle any error here, return non-zero. Otherwise return zero. */ | |
b99bd4ef | 1281 | |
c19d1205 ZW |
1282 | static int |
1283 | create_register_alias (char * newname, char *p) | |
1284 | { | |
1285 | struct reg_entry *old; | |
1286 | char *oldname, *nbuf; | |
1287 | size_t nlen; | |
b99bd4ef | 1288 | |
c19d1205 ZW |
1289 | /* The input scrubber ensures that whitespace after the mnemonic is |
1290 | collapsed to single spaces. */ | |
1291 | oldname = p; | |
1292 | if (strncmp (oldname, " .req ", 6) != 0) | |
1293 | return 0; | |
b99bd4ef | 1294 | |
c19d1205 ZW |
1295 | oldname += 6; |
1296 | if (*oldname == '\0') | |
1297 | return 0; | |
b99bd4ef | 1298 | |
c19d1205 ZW |
1299 | old = hash_find (arm_reg_hsh, oldname); |
1300 | if (!old) | |
b99bd4ef | 1301 | { |
c19d1205 ZW |
1302 | as_warn (_("unknown register '%s' -- .req ignored"), oldname); |
1303 | return 1; | |
b99bd4ef NC |
1304 | } |
1305 | ||
c19d1205 ZW |
1306 | /* If TC_CASE_SENSITIVE is defined, then newname already points to |
1307 | the desired alias name, and p points to its end. If not, then | |
1308 | the desired alias name is in the global original_case_string. */ | |
1309 | #ifdef TC_CASE_SENSITIVE | |
1310 | nlen = p - newname; | |
1311 | #else | |
1312 | newname = original_case_string; | |
1313 | nlen = strlen (newname); | |
1314 | #endif | |
b99bd4ef | 1315 | |
c19d1205 ZW |
1316 | nbuf = alloca (nlen + 1); |
1317 | memcpy (nbuf, newname, nlen); | |
1318 | nbuf[nlen] = '\0'; | |
b99bd4ef | 1319 | |
c19d1205 ZW |
1320 | /* Create aliases under the new name as stated; an all-lowercase |
1321 | version of the new name; and an all-uppercase version of the new | |
1322 | name. */ | |
1323 | insert_reg_alias (nbuf, old->number, old->type); | |
b99bd4ef | 1324 | |
c19d1205 ZW |
1325 | for (p = nbuf; *p; p++) |
1326 | *p = TOUPPER (*p); | |
1327 | ||
1328 | if (strncmp (nbuf, newname, nlen)) | |
1329 | insert_reg_alias (nbuf, old->number, old->type); | |
1330 | ||
1331 | for (p = nbuf; *p; p++) | |
1332 | *p = TOLOWER (*p); | |
1333 | ||
1334 | if (strncmp (nbuf, newname, nlen)) | |
1335 | insert_reg_alias (nbuf, old->number, old->type); | |
1336 | ||
1337 | return 1; | |
b99bd4ef NC |
1338 | } |
1339 | ||
c19d1205 ZW |
1340 | /* Should never be called, as .req goes between the alias and the |
1341 | register name, not at the beginning of the line. */ | |
b99bd4ef | 1342 | static void |
c19d1205 | 1343 | s_req (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 1344 | { |
c19d1205 ZW |
1345 | as_bad (_("invalid syntax for .req directive")); |
1346 | } | |
b99bd4ef | 1347 | |
c19d1205 ZW |
1348 | /* The .unreq directive deletes an alias which was previously defined |
1349 | by .req. For example: | |
b99bd4ef | 1350 | |
c19d1205 ZW |
1351 | my_alias .req r11 |
1352 | .unreq my_alias */ | |
b99bd4ef NC |
1353 | |
1354 | static void | |
c19d1205 | 1355 | s_unreq (int a ATTRIBUTE_UNUSED) |
b99bd4ef | 1356 | { |
c19d1205 ZW |
1357 | char * name; |
1358 | char saved_char; | |
b99bd4ef | 1359 | |
c19d1205 ZW |
1360 | name = input_line_pointer; |
1361 | ||
1362 | while (*input_line_pointer != 0 | |
1363 | && *input_line_pointer != ' ' | |
1364 | && *input_line_pointer != '\n') | |
1365 | ++input_line_pointer; | |
1366 | ||
1367 | saved_char = *input_line_pointer; | |
1368 | *input_line_pointer = 0; | |
1369 | ||
1370 | if (!*name) | |
1371 | as_bad (_("invalid syntax for .unreq directive")); | |
1372 | else | |
1373 | { | |
1374 | struct reg_entry *reg = hash_find (arm_reg_hsh, name); | |
1375 | ||
1376 | if (!reg) | |
1377 | as_bad (_("unknown register alias '%s'"), name); | |
1378 | else if (reg->builtin) | |
1379 | as_warn (_("ignoring attempt to undefine built-in register '%s'"), | |
1380 | name); | |
1381 | else | |
1382 | { | |
1383 | hash_delete (arm_reg_hsh, name); | |
1384 | free ((char *) reg->name); | |
1385 | free (reg); | |
1386 | } | |
1387 | } | |
b99bd4ef | 1388 | |
c19d1205 | 1389 | *input_line_pointer = saved_char; |
b99bd4ef NC |
1390 | demand_empty_rest_of_line (); |
1391 | } | |
1392 | ||
c19d1205 ZW |
1393 | /* Directives: Instruction set selection. */ |
1394 | ||
1395 | #ifdef OBJ_ELF | |
1396 | /* This code is to handle mapping symbols as defined in the ARM ELF spec. | |
1397 | (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0). | |
1398 | Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag), | |
1399 | and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */ | |
1400 | ||
1401 | static enum mstate mapstate = MAP_UNDEFINED; | |
b99bd4ef NC |
1402 | |
1403 | static void | |
c19d1205 | 1404 | mapping_state (enum mstate state) |
b99bd4ef | 1405 | { |
a737bd4d | 1406 | symbolS * symbolP; |
c19d1205 ZW |
1407 | const char * symname; |
1408 | int type; | |
b99bd4ef | 1409 | |
c19d1205 ZW |
1410 | if (mapstate == state) |
1411 | /* The mapping symbol has already been emitted. | |
1412 | There is nothing else to do. */ | |
1413 | return; | |
b99bd4ef | 1414 | |
c19d1205 | 1415 | mapstate = state; |
b99bd4ef | 1416 | |
c19d1205 | 1417 | switch (state) |
b99bd4ef | 1418 | { |
c19d1205 ZW |
1419 | case MAP_DATA: |
1420 | symname = "$d"; | |
1421 | type = BSF_NO_FLAGS; | |
1422 | break; | |
1423 | case MAP_ARM: | |
1424 | symname = "$a"; | |
1425 | type = BSF_NO_FLAGS; | |
1426 | break; | |
1427 | case MAP_THUMB: | |
1428 | symname = "$t"; | |
1429 | type = BSF_NO_FLAGS; | |
1430 | break; | |
1431 | case MAP_UNDEFINED: | |
1432 | return; | |
1433 | default: | |
1434 | abort (); | |
1435 | } | |
1436 | ||
1437 | seg_info (now_seg)->tc_segment_info_data.mapstate = state; | |
1438 | ||
1439 | symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now); | |
1440 | symbol_table_insert (symbolP); | |
1441 | symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL; | |
1442 | ||
1443 | switch (state) | |
1444 | { | |
1445 | case MAP_ARM: | |
1446 | THUMB_SET_FUNC (symbolP, 0); | |
1447 | ARM_SET_THUMB (symbolP, 0); | |
1448 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
1449 | break; | |
1450 | ||
1451 | case MAP_THUMB: | |
1452 | THUMB_SET_FUNC (symbolP, 1); | |
1453 | ARM_SET_THUMB (symbolP, 1); | |
1454 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
1455 | break; | |
1456 | ||
1457 | case MAP_DATA: | |
1458 | default: | |
1459 | return; | |
1460 | } | |
1461 | } | |
1462 | #else | |
1463 | #define mapping_state(x) /* nothing */ | |
1464 | #endif | |
1465 | ||
1466 | /* Find the real, Thumb encoded start of a Thumb function. */ | |
1467 | ||
1468 | static symbolS * | |
1469 | find_real_start (symbolS * symbolP) | |
1470 | { | |
1471 | char * real_start; | |
1472 | const char * name = S_GET_NAME (symbolP); | |
1473 | symbolS * new_target; | |
1474 | ||
1475 | /* This definition must agree with the one in gcc/config/arm/thumb.c. */ | |
1476 | #define STUB_NAME ".real_start_of" | |
1477 | ||
1478 | if (name == NULL) | |
1479 | abort (); | |
1480 | ||
37f6032b ZW |
1481 | /* The compiler may generate BL instructions to local labels because |
1482 | it needs to perform a branch to a far away location. These labels | |
1483 | do not have a corresponding ".real_start_of" label. We check | |
1484 | both for S_IS_LOCAL and for a leading dot, to give a way to bypass | |
1485 | the ".real_start_of" convention for nonlocal branches. */ | |
1486 | if (S_IS_LOCAL (symbolP) || name[0] == '.') | |
c19d1205 ZW |
1487 | return symbolP; |
1488 | ||
37f6032b | 1489 | real_start = ACONCAT ((STUB_NAME, name, NULL)); |
c19d1205 ZW |
1490 | new_target = symbol_find (real_start); |
1491 | ||
1492 | if (new_target == NULL) | |
1493 | { | |
1494 | as_warn ("Failed to find real start of function: %s\n", name); | |
1495 | new_target = symbolP; | |
1496 | } | |
1497 | ||
c19d1205 ZW |
1498 | return new_target; |
1499 | } | |
1500 | ||
1501 | static void | |
1502 | opcode_select (int width) | |
1503 | { | |
1504 | switch (width) | |
1505 | { | |
1506 | case 16: | |
1507 | if (! thumb_mode) | |
1508 | { | |
e74cfd16 | 1509 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
c19d1205 ZW |
1510 | as_bad (_("selected processor does not support THUMB opcodes")); |
1511 | ||
1512 | thumb_mode = 1; | |
1513 | /* No need to force the alignment, since we will have been | |
1514 | coming from ARM mode, which is word-aligned. */ | |
1515 | record_alignment (now_seg, 1); | |
1516 | } | |
1517 | mapping_state (MAP_THUMB); | |
1518 | break; | |
1519 | ||
1520 | case 32: | |
1521 | if (thumb_mode) | |
1522 | { | |
e74cfd16 | 1523 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)) |
c19d1205 ZW |
1524 | as_bad (_("selected processor does not support ARM opcodes")); |
1525 | ||
1526 | thumb_mode = 0; | |
1527 | ||
1528 | if (!need_pass_2) | |
1529 | frag_align (2, 0, 0); | |
1530 | ||
1531 | record_alignment (now_seg, 1); | |
1532 | } | |
1533 | mapping_state (MAP_ARM); | |
1534 | break; | |
1535 | ||
1536 | default: | |
1537 | as_bad (_("invalid instruction size selected (%d)"), width); | |
1538 | } | |
1539 | } | |
1540 | ||
1541 | static void | |
1542 | s_arm (int ignore ATTRIBUTE_UNUSED) | |
1543 | { | |
1544 | opcode_select (32); | |
1545 | demand_empty_rest_of_line (); | |
1546 | } | |
1547 | ||
1548 | static void | |
1549 | s_thumb (int ignore ATTRIBUTE_UNUSED) | |
1550 | { | |
1551 | opcode_select (16); | |
1552 | demand_empty_rest_of_line (); | |
1553 | } | |
1554 | ||
1555 | static void | |
1556 | s_code (int unused ATTRIBUTE_UNUSED) | |
1557 | { | |
1558 | int temp; | |
1559 | ||
1560 | temp = get_absolute_expression (); | |
1561 | switch (temp) | |
1562 | { | |
1563 | case 16: | |
1564 | case 32: | |
1565 | opcode_select (temp); | |
1566 | break; | |
1567 | ||
1568 | default: | |
1569 | as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp); | |
1570 | } | |
1571 | } | |
1572 | ||
1573 | static void | |
1574 | s_force_thumb (int ignore ATTRIBUTE_UNUSED) | |
1575 | { | |
1576 | /* If we are not already in thumb mode go into it, EVEN if | |
1577 | the target processor does not support thumb instructions. | |
1578 | This is used by gcc/config/arm/lib1funcs.asm for example | |
1579 | to compile interworking support functions even if the | |
1580 | target processor should not support interworking. */ | |
1581 | if (! thumb_mode) | |
1582 | { | |
1583 | thumb_mode = 2; | |
1584 | record_alignment (now_seg, 1); | |
1585 | } | |
1586 | ||
1587 | demand_empty_rest_of_line (); | |
1588 | } | |
1589 | ||
1590 | static void | |
1591 | s_thumb_func (int ignore ATTRIBUTE_UNUSED) | |
1592 | { | |
1593 | s_thumb (0); | |
1594 | ||
1595 | /* The following label is the name/address of the start of a Thumb function. | |
1596 | We need to know this for the interworking support. */ | |
1597 | label_is_thumb_function_name = TRUE; | |
1598 | } | |
1599 | ||
1600 | /* Perform a .set directive, but also mark the alias as | |
1601 | being a thumb function. */ | |
1602 | ||
1603 | static void | |
1604 | s_thumb_set (int equiv) | |
1605 | { | |
1606 | /* XXX the following is a duplicate of the code for s_set() in read.c | |
1607 | We cannot just call that code as we need to get at the symbol that | |
1608 | is created. */ | |
1609 | char * name; | |
1610 | char delim; | |
1611 | char * end_name; | |
1612 | symbolS * symbolP; | |
1613 | ||
1614 | /* Especial apologies for the random logic: | |
1615 | This just grew, and could be parsed much more simply! | |
1616 | Dean - in haste. */ | |
1617 | name = input_line_pointer; | |
1618 | delim = get_symbol_end (); | |
1619 | end_name = input_line_pointer; | |
1620 | *end_name = delim; | |
1621 | ||
1622 | if (*input_line_pointer != ',') | |
1623 | { | |
1624 | *end_name = 0; | |
1625 | as_bad (_("expected comma after name \"%s\""), name); | |
b99bd4ef NC |
1626 | *end_name = delim; |
1627 | ignore_rest_of_line (); | |
1628 | return; | |
1629 | } | |
1630 | ||
1631 | input_line_pointer++; | |
1632 | *end_name = 0; | |
1633 | ||
1634 | if (name[0] == '.' && name[1] == '\0') | |
1635 | { | |
1636 | /* XXX - this should not happen to .thumb_set. */ | |
1637 | abort (); | |
1638 | } | |
1639 | ||
1640 | if ((symbolP = symbol_find (name)) == NULL | |
1641 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
1642 | { | |
1643 | #ifndef NO_LISTING | |
1644 | /* When doing symbol listings, play games with dummy fragments living | |
1645 | outside the normal fragment chain to record the file and line info | |
c19d1205 | 1646 | for this symbol. */ |
b99bd4ef NC |
1647 | if (listing & LISTING_SYMBOLS) |
1648 | { | |
1649 | extern struct list_info_struct * listing_tail; | |
a737bd4d | 1650 | fragS * dummy_frag = xmalloc (sizeof (fragS)); |
b99bd4ef NC |
1651 | |
1652 | memset (dummy_frag, 0, sizeof (fragS)); | |
1653 | dummy_frag->fr_type = rs_fill; | |
1654 | dummy_frag->line = listing_tail; | |
1655 | symbolP = symbol_new (name, undefined_section, 0, dummy_frag); | |
1656 | dummy_frag->fr_symbol = symbolP; | |
1657 | } | |
1658 | else | |
1659 | #endif | |
1660 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); | |
1661 | ||
1662 | #ifdef OBJ_COFF | |
1663 | /* "set" symbols are local unless otherwise specified. */ | |
1664 | SF_SET_LOCAL (symbolP); | |
1665 | #endif /* OBJ_COFF */ | |
1666 | } /* Make a new symbol. */ | |
1667 | ||
1668 | symbol_table_insert (symbolP); | |
1669 | ||
1670 | * end_name = delim; | |
1671 | ||
1672 | if (equiv | |
1673 | && S_IS_DEFINED (symbolP) | |
1674 | && S_GET_SEGMENT (symbolP) != reg_section) | |
1675 | as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); | |
1676 | ||
1677 | pseudo_set (symbolP); | |
1678 | ||
1679 | demand_empty_rest_of_line (); | |
1680 | ||
c19d1205 | 1681 | /* XXX Now we come to the Thumb specific bit of code. */ |
b99bd4ef NC |
1682 | |
1683 | THUMB_SET_FUNC (symbolP, 1); | |
1684 | ARM_SET_THUMB (symbolP, 1); | |
1685 | #if defined OBJ_ELF || defined OBJ_COFF | |
1686 | ARM_SET_INTERWORK (symbolP, support_interwork); | |
1687 | #endif | |
1688 | } | |
1689 | ||
c19d1205 | 1690 | /* Directives: Mode selection. */ |
b99bd4ef | 1691 | |
c19d1205 ZW |
1692 | /* .syntax [unified|divided] - choose the new unified syntax |
1693 | (same for Arm and Thumb encoding, modulo slight differences in what | |
1694 | can be represented) or the old divergent syntax for each mode. */ | |
b99bd4ef | 1695 | static void |
c19d1205 | 1696 | s_syntax (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 1697 | { |
c19d1205 ZW |
1698 | char *name, delim; |
1699 | ||
1700 | name = input_line_pointer; | |
1701 | delim = get_symbol_end (); | |
1702 | ||
1703 | if (!strcasecmp (name, "unified")) | |
1704 | unified_syntax = TRUE; | |
1705 | else if (!strcasecmp (name, "divided")) | |
1706 | unified_syntax = FALSE; | |
1707 | else | |
1708 | { | |
1709 | as_bad (_("unrecognized syntax mode \"%s\""), name); | |
1710 | return; | |
1711 | } | |
1712 | *input_line_pointer = delim; | |
b99bd4ef NC |
1713 | demand_empty_rest_of_line (); |
1714 | } | |
1715 | ||
c19d1205 ZW |
1716 | /* Directives: sectioning and alignment. */ |
1717 | ||
1718 | /* Same as s_align_ptwo but align 0 => align 2. */ | |
1719 | ||
b99bd4ef | 1720 | static void |
c19d1205 | 1721 | s_align (int unused ATTRIBUTE_UNUSED) |
b99bd4ef | 1722 | { |
a737bd4d | 1723 | int temp; |
c19d1205 ZW |
1724 | long temp_fill; |
1725 | long max_alignment = 15; | |
b99bd4ef NC |
1726 | |
1727 | temp = get_absolute_expression (); | |
c19d1205 ZW |
1728 | if (temp > max_alignment) |
1729 | as_bad (_("alignment too large: %d assumed"), temp = max_alignment); | |
1730 | else if (temp < 0) | |
b99bd4ef | 1731 | { |
c19d1205 ZW |
1732 | as_bad (_("alignment negative. 0 assumed.")); |
1733 | temp = 0; | |
1734 | } | |
b99bd4ef | 1735 | |
c19d1205 ZW |
1736 | if (*input_line_pointer == ',') |
1737 | { | |
1738 | input_line_pointer++; | |
1739 | temp_fill = get_absolute_expression (); | |
b99bd4ef | 1740 | } |
c19d1205 ZW |
1741 | else |
1742 | temp_fill = 0; | |
b99bd4ef | 1743 | |
c19d1205 ZW |
1744 | if (!temp) |
1745 | temp = 2; | |
b99bd4ef | 1746 | |
c19d1205 ZW |
1747 | /* Only make a frag if we HAVE to. */ |
1748 | if (temp && !need_pass_2) | |
1749 | frag_align (temp, (int) temp_fill, 0); | |
1750 | demand_empty_rest_of_line (); | |
1751 | ||
1752 | record_alignment (now_seg, temp); | |
b99bd4ef NC |
1753 | } |
1754 | ||
c19d1205 ZW |
1755 | static void |
1756 | s_bss (int ignore ATTRIBUTE_UNUSED) | |
b99bd4ef | 1757 | { |
c19d1205 ZW |
1758 | /* We don't support putting frags in the BSS segment, we fake it by |
1759 | marking in_bss, then looking at s_skip for clues. */ | |
1760 | subseg_set (bss_section, 0); | |
1761 | demand_empty_rest_of_line (); | |
1762 | mapping_state (MAP_DATA); | |
1763 | } | |
b99bd4ef | 1764 | |
c19d1205 ZW |
1765 | static void |
1766 | s_even (int ignore ATTRIBUTE_UNUSED) | |
1767 | { | |
1768 | /* Never make frag if expect extra pass. */ | |
1769 | if (!need_pass_2) | |
1770 | frag_align (1, 0, 0); | |
b99bd4ef | 1771 | |
c19d1205 | 1772 | record_alignment (now_seg, 1); |
b99bd4ef | 1773 | |
c19d1205 | 1774 | demand_empty_rest_of_line (); |
b99bd4ef NC |
1775 | } |
1776 | ||
c19d1205 | 1777 | /* Directives: Literal pools. */ |
a737bd4d | 1778 | |
c19d1205 ZW |
1779 | static literal_pool * |
1780 | find_literal_pool (void) | |
a737bd4d | 1781 | { |
c19d1205 | 1782 | literal_pool * pool; |
a737bd4d | 1783 | |
c19d1205 | 1784 | for (pool = list_of_pools; pool != NULL; pool = pool->next) |
a737bd4d | 1785 | { |
c19d1205 ZW |
1786 | if (pool->section == now_seg |
1787 | && pool->sub_section == now_subseg) | |
1788 | break; | |
a737bd4d NC |
1789 | } |
1790 | ||
c19d1205 | 1791 | return pool; |
a737bd4d NC |
1792 | } |
1793 | ||
c19d1205 ZW |
1794 | static literal_pool * |
1795 | find_or_make_literal_pool (void) | |
a737bd4d | 1796 | { |
c19d1205 ZW |
1797 | /* Next literal pool ID number. */ |
1798 | static unsigned int latest_pool_num = 1; | |
1799 | literal_pool * pool; | |
a737bd4d | 1800 | |
c19d1205 | 1801 | pool = find_literal_pool (); |
a737bd4d | 1802 | |
c19d1205 | 1803 | if (pool == NULL) |
a737bd4d | 1804 | { |
c19d1205 ZW |
1805 | /* Create a new pool. */ |
1806 | pool = xmalloc (sizeof (* pool)); | |
1807 | if (! pool) | |
1808 | return NULL; | |
a737bd4d | 1809 | |
c19d1205 ZW |
1810 | pool->next_free_entry = 0; |
1811 | pool->section = now_seg; | |
1812 | pool->sub_section = now_subseg; | |
1813 | pool->next = list_of_pools; | |
1814 | pool->symbol = NULL; | |
1815 | ||
1816 | /* Add it to the list. */ | |
1817 | list_of_pools = pool; | |
a737bd4d | 1818 | } |
a737bd4d | 1819 | |
c19d1205 ZW |
1820 | /* New pools, and emptied pools, will have a NULL symbol. */ |
1821 | if (pool->symbol == NULL) | |
a737bd4d | 1822 | { |
c19d1205 ZW |
1823 | pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section, |
1824 | (valueT) 0, &zero_address_frag); | |
1825 | pool->id = latest_pool_num ++; | |
a737bd4d NC |
1826 | } |
1827 | ||
c19d1205 ZW |
1828 | /* Done. */ |
1829 | return pool; | |
a737bd4d NC |
1830 | } |
1831 | ||
c19d1205 ZW |
1832 | /* Add the literal in the global 'inst' |
1833 | structure to the relevent literal pool. */ | |
b99bd4ef NC |
1834 | |
1835 | static int | |
c19d1205 | 1836 | add_to_lit_pool (void) |
b99bd4ef | 1837 | { |
c19d1205 ZW |
1838 | literal_pool * pool; |
1839 | unsigned int entry; | |
b99bd4ef | 1840 | |
c19d1205 ZW |
1841 | pool = find_or_make_literal_pool (); |
1842 | ||
1843 | /* Check if this literal value is already in the pool. */ | |
1844 | for (entry = 0; entry < pool->next_free_entry; entry ++) | |
b99bd4ef | 1845 | { |
c19d1205 ZW |
1846 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) |
1847 | && (inst.reloc.exp.X_op == O_constant) | |
1848 | && (pool->literals[entry].X_add_number | |
1849 | == inst.reloc.exp.X_add_number) | |
1850 | && (pool->literals[entry].X_unsigned | |
1851 | == inst.reloc.exp.X_unsigned)) | |
1852 | break; | |
1853 | ||
1854 | if ((pool->literals[entry].X_op == inst.reloc.exp.X_op) | |
1855 | && (inst.reloc.exp.X_op == O_symbol) | |
1856 | && (pool->literals[entry].X_add_number | |
1857 | == inst.reloc.exp.X_add_number) | |
1858 | && (pool->literals[entry].X_add_symbol | |
1859 | == inst.reloc.exp.X_add_symbol) | |
1860 | && (pool->literals[entry].X_op_symbol | |
1861 | == inst.reloc.exp.X_op_symbol)) | |
1862 | break; | |
b99bd4ef NC |
1863 | } |
1864 | ||
c19d1205 ZW |
1865 | /* Do we need to create a new entry? */ |
1866 | if (entry == pool->next_free_entry) | |
1867 | { | |
1868 | if (entry >= MAX_LITERAL_POOL_SIZE) | |
1869 | { | |
1870 | inst.error = _("literal pool overflow"); | |
1871 | return FAIL; | |
1872 | } | |
1873 | ||
1874 | pool->literals[entry] = inst.reloc.exp; | |
1875 | pool->next_free_entry += 1; | |
1876 | } | |
b99bd4ef | 1877 | |
c19d1205 ZW |
1878 | inst.reloc.exp.X_op = O_symbol; |
1879 | inst.reloc.exp.X_add_number = ((int) entry) * 4; | |
1880 | inst.reloc.exp.X_add_symbol = pool->symbol; | |
b99bd4ef | 1881 | |
c19d1205 | 1882 | return SUCCESS; |
b99bd4ef NC |
1883 | } |
1884 | ||
c19d1205 ZW |
1885 | /* Can't use symbol_new here, so have to create a symbol and then at |
1886 | a later date assign it a value. Thats what these functions do. */ | |
e16bb312 | 1887 | |
c19d1205 ZW |
1888 | static void |
1889 | symbol_locate (symbolS * symbolP, | |
1890 | const char * name, /* It is copied, the caller can modify. */ | |
1891 | segT segment, /* Segment identifier (SEG_<something>). */ | |
1892 | valueT valu, /* Symbol value. */ | |
1893 | fragS * frag) /* Associated fragment. */ | |
1894 | { | |
1895 | unsigned int name_length; | |
1896 | char * preserved_copy_of_name; | |
e16bb312 | 1897 | |
c19d1205 ZW |
1898 | name_length = strlen (name) + 1; /* +1 for \0. */ |
1899 | obstack_grow (¬es, name, name_length); | |
1900 | preserved_copy_of_name = obstack_finish (¬es); | |
e16bb312 | 1901 | |
c19d1205 ZW |
1902 | #ifdef tc_canonicalize_symbol_name |
1903 | preserved_copy_of_name = | |
1904 | tc_canonicalize_symbol_name (preserved_copy_of_name); | |
1905 | #endif | |
b99bd4ef | 1906 | |
c19d1205 | 1907 | S_SET_NAME (symbolP, preserved_copy_of_name); |
b99bd4ef | 1908 | |
c19d1205 ZW |
1909 | S_SET_SEGMENT (symbolP, segment); |
1910 | S_SET_VALUE (symbolP, valu); | |
1911 | symbol_clear_list_pointers (symbolP); | |
b99bd4ef | 1912 | |
c19d1205 | 1913 | symbol_set_frag (symbolP, frag); |
b99bd4ef | 1914 | |
c19d1205 ZW |
1915 | /* Link to end of symbol chain. */ |
1916 | { | |
1917 | extern int symbol_table_frozen; | |
b99bd4ef | 1918 | |
c19d1205 ZW |
1919 | if (symbol_table_frozen) |
1920 | abort (); | |
1921 | } | |
b99bd4ef | 1922 | |
c19d1205 | 1923 | symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP); |
b99bd4ef | 1924 | |
c19d1205 | 1925 | obj_symbol_new_hook (symbolP); |
b99bd4ef | 1926 | |
c19d1205 ZW |
1927 | #ifdef tc_symbol_new_hook |
1928 | tc_symbol_new_hook (symbolP); | |
1929 | #endif | |
1930 | ||
1931 | #ifdef DEBUG_SYMS | |
1932 | verify_symbol_chain (symbol_rootP, symbol_lastP); | |
1933 | #endif /* DEBUG_SYMS */ | |
b99bd4ef NC |
1934 | } |
1935 | ||
b99bd4ef | 1936 | |
c19d1205 ZW |
1937 | static void |
1938 | s_ltorg (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 1939 | { |
c19d1205 ZW |
1940 | unsigned int entry; |
1941 | literal_pool * pool; | |
1942 | char sym_name[20]; | |
b99bd4ef | 1943 | |
c19d1205 ZW |
1944 | pool = find_literal_pool (); |
1945 | if (pool == NULL | |
1946 | || pool->symbol == NULL | |
1947 | || pool->next_free_entry == 0) | |
1948 | return; | |
b99bd4ef | 1949 | |
c19d1205 | 1950 | mapping_state (MAP_DATA); |
b99bd4ef | 1951 | |
c19d1205 ZW |
1952 | /* Align pool as you have word accesses. |
1953 | Only make a frag if we have to. */ | |
1954 | if (!need_pass_2) | |
1955 | frag_align (2, 0, 0); | |
b99bd4ef | 1956 | |
c19d1205 | 1957 | record_alignment (now_seg, 2); |
b99bd4ef | 1958 | |
c19d1205 | 1959 | sprintf (sym_name, "$$lit_\002%x", pool->id); |
b99bd4ef | 1960 | |
c19d1205 ZW |
1961 | symbol_locate (pool->symbol, sym_name, now_seg, |
1962 | (valueT) frag_now_fix (), frag_now); | |
1963 | symbol_table_insert (pool->symbol); | |
b99bd4ef | 1964 | |
c19d1205 | 1965 | ARM_SET_THUMB (pool->symbol, thumb_mode); |
b99bd4ef | 1966 | |
c19d1205 ZW |
1967 | #if defined OBJ_COFF || defined OBJ_ELF |
1968 | ARM_SET_INTERWORK (pool->symbol, support_interwork); | |
1969 | #endif | |
6c43fab6 | 1970 | |
c19d1205 ZW |
1971 | for (entry = 0; entry < pool->next_free_entry; entry ++) |
1972 | /* First output the expression in the instruction to the pool. */ | |
1973 | emit_expr (&(pool->literals[entry]), 4); /* .word */ | |
b99bd4ef | 1974 | |
c19d1205 ZW |
1975 | /* Mark the pool as empty. */ |
1976 | pool->next_free_entry = 0; | |
1977 | pool->symbol = NULL; | |
b99bd4ef NC |
1978 | } |
1979 | ||
c19d1205 ZW |
1980 | #ifdef OBJ_ELF |
1981 | /* Forward declarations for functions below, in the MD interface | |
1982 | section. */ | |
1983 | static void fix_new_arm (fragS *, int, short, expressionS *, int, int); | |
1984 | static valueT create_unwind_entry (int); | |
1985 | static void start_unwind_section (const segT, int); | |
1986 | static void add_unwind_opcode (valueT, int); | |
1987 | static void flush_pending_unwind (void); | |
b99bd4ef | 1988 | |
c19d1205 | 1989 | /* Directives: Data. */ |
b99bd4ef | 1990 | |
c19d1205 ZW |
1991 | static void |
1992 | s_arm_elf_cons (int nbytes) | |
1993 | { | |
1994 | expressionS exp; | |
b99bd4ef | 1995 | |
c19d1205 ZW |
1996 | #ifdef md_flush_pending_output |
1997 | md_flush_pending_output (); | |
1998 | #endif | |
b99bd4ef | 1999 | |
c19d1205 | 2000 | if (is_it_end_of_statement ()) |
b99bd4ef | 2001 | { |
c19d1205 ZW |
2002 | demand_empty_rest_of_line (); |
2003 | return; | |
b99bd4ef NC |
2004 | } |
2005 | ||
c19d1205 ZW |
2006 | #ifdef md_cons_align |
2007 | md_cons_align (nbytes); | |
2008 | #endif | |
b99bd4ef | 2009 | |
c19d1205 ZW |
2010 | mapping_state (MAP_DATA); |
2011 | do | |
b99bd4ef | 2012 | { |
c19d1205 ZW |
2013 | int reloc; |
2014 | char *base = input_line_pointer; | |
b99bd4ef | 2015 | |
c19d1205 | 2016 | expression (& exp); |
b99bd4ef | 2017 | |
c19d1205 ZW |
2018 | if (exp.X_op != O_symbol) |
2019 | emit_expr (&exp, (unsigned int) nbytes); | |
2020 | else | |
2021 | { | |
2022 | char *before_reloc = input_line_pointer; | |
2023 | reloc = parse_reloc (&input_line_pointer); | |
2024 | if (reloc == -1) | |
2025 | { | |
2026 | as_bad (_("unrecognized relocation suffix")); | |
2027 | ignore_rest_of_line (); | |
2028 | return; | |
2029 | } | |
2030 | else if (reloc == BFD_RELOC_UNUSED) | |
2031 | emit_expr (&exp, (unsigned int) nbytes); | |
2032 | else | |
2033 | { | |
2034 | reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
2035 | int size = bfd_get_reloc_size (howto); | |
b99bd4ef | 2036 | |
2fc8bdac ZW |
2037 | if (reloc == BFD_RELOC_ARM_PLT32) |
2038 | { | |
2039 | as_bad (_("(plt) is only valid on branch targets")); | |
2040 | reloc = BFD_RELOC_UNUSED; | |
2041 | size = 0; | |
2042 | } | |
2043 | ||
c19d1205 | 2044 | if (size > nbytes) |
2fc8bdac | 2045 | as_bad (_("%s relocations do not fit in %d bytes"), |
c19d1205 ZW |
2046 | howto->name, nbytes); |
2047 | else | |
2048 | { | |
2049 | /* We've parsed an expression stopping at O_symbol. | |
2050 | But there may be more expression left now that we | |
2051 | have parsed the relocation marker. Parse it again. | |
2052 | XXX Surely there is a cleaner way to do this. */ | |
2053 | char *p = input_line_pointer; | |
2054 | int offset; | |
2055 | char *save_buf = alloca (input_line_pointer - base); | |
2056 | memcpy (save_buf, base, input_line_pointer - base); | |
2057 | memmove (base + (input_line_pointer - before_reloc), | |
2058 | base, before_reloc - base); | |
2059 | ||
2060 | input_line_pointer = base + (input_line_pointer-before_reloc); | |
2061 | expression (&exp); | |
2062 | memcpy (base, save_buf, p - base); | |
2063 | ||
2064 | offset = nbytes - size; | |
2065 | p = frag_more ((int) nbytes); | |
2066 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, | |
2067 | size, &exp, 0, reloc); | |
2068 | } | |
2069 | } | |
2070 | } | |
b99bd4ef | 2071 | } |
c19d1205 | 2072 | while (*input_line_pointer++ == ','); |
b99bd4ef | 2073 | |
c19d1205 ZW |
2074 | /* Put terminator back into stream. */ |
2075 | input_line_pointer --; | |
2076 | demand_empty_rest_of_line (); | |
b99bd4ef NC |
2077 | } |
2078 | ||
b99bd4ef | 2079 | |
c19d1205 | 2080 | /* Parse a .rel31 directive. */ |
b99bd4ef | 2081 | |
c19d1205 ZW |
2082 | static void |
2083 | s_arm_rel31 (int ignored ATTRIBUTE_UNUSED) | |
2084 | { | |
2085 | expressionS exp; | |
2086 | char *p; | |
2087 | valueT highbit; | |
b99bd4ef | 2088 | |
c19d1205 ZW |
2089 | highbit = 0; |
2090 | if (*input_line_pointer == '1') | |
2091 | highbit = 0x80000000; | |
2092 | else if (*input_line_pointer != '0') | |
2093 | as_bad (_("expected 0 or 1")); | |
b99bd4ef | 2094 | |
c19d1205 ZW |
2095 | input_line_pointer++; |
2096 | if (*input_line_pointer != ',') | |
2097 | as_bad (_("missing comma")); | |
2098 | input_line_pointer++; | |
b99bd4ef | 2099 | |
c19d1205 ZW |
2100 | #ifdef md_flush_pending_output |
2101 | md_flush_pending_output (); | |
2102 | #endif | |
b99bd4ef | 2103 | |
c19d1205 ZW |
2104 | #ifdef md_cons_align |
2105 | md_cons_align (4); | |
2106 | #endif | |
b99bd4ef | 2107 | |
c19d1205 | 2108 | mapping_state (MAP_DATA); |
b99bd4ef | 2109 | |
c19d1205 | 2110 | expression (&exp); |
b99bd4ef | 2111 | |
c19d1205 ZW |
2112 | p = frag_more (4); |
2113 | md_number_to_chars (p, highbit, 4); | |
2114 | fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1, | |
2115 | BFD_RELOC_ARM_PREL31); | |
b99bd4ef | 2116 | |
c19d1205 | 2117 | demand_empty_rest_of_line (); |
b99bd4ef NC |
2118 | } |
2119 | ||
c19d1205 | 2120 | /* Directives: AEABI stack-unwind tables. */ |
b99bd4ef | 2121 | |
c19d1205 | 2122 | /* Parse an unwind_fnstart directive. Simply records the current location. */ |
b99bd4ef | 2123 | |
c19d1205 ZW |
2124 | static void |
2125 | s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED) | |
2126 | { | |
2127 | demand_empty_rest_of_line (); | |
2128 | /* Mark the start of the function. */ | |
2129 | unwind.proc_start = expr_build_dot (); | |
b99bd4ef | 2130 | |
c19d1205 ZW |
2131 | /* Reset the rest of the unwind info. */ |
2132 | unwind.opcode_count = 0; | |
2133 | unwind.table_entry = NULL; | |
2134 | unwind.personality_routine = NULL; | |
2135 | unwind.personality_index = -1; | |
2136 | unwind.frame_size = 0; | |
2137 | unwind.fp_offset = 0; | |
2138 | unwind.fp_reg = 13; | |
2139 | unwind.fp_used = 0; | |
2140 | unwind.sp_restored = 0; | |
2141 | } | |
b99bd4ef | 2142 | |
b99bd4ef | 2143 | |
c19d1205 ZW |
2144 | /* Parse a handlerdata directive. Creates the exception handling table entry |
2145 | for the function. */ | |
b99bd4ef | 2146 | |
c19d1205 ZW |
2147 | static void |
2148 | s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED) | |
2149 | { | |
2150 | demand_empty_rest_of_line (); | |
2151 | if (unwind.table_entry) | |
2152 | as_bad (_("dupicate .handlerdata directive")); | |
f02232aa | 2153 | |
c19d1205 ZW |
2154 | create_unwind_entry (1); |
2155 | } | |
a737bd4d | 2156 | |
c19d1205 | 2157 | /* Parse an unwind_fnend directive. Generates the index table entry. */ |
b99bd4ef | 2158 | |
c19d1205 ZW |
2159 | static void |
2160 | s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED) | |
2161 | { | |
2162 | long where; | |
2163 | char *ptr; | |
2164 | valueT val; | |
f02232aa | 2165 | |
c19d1205 | 2166 | demand_empty_rest_of_line (); |
f02232aa | 2167 | |
c19d1205 ZW |
2168 | /* Add eh table entry. */ |
2169 | if (unwind.table_entry == NULL) | |
2170 | val = create_unwind_entry (0); | |
2171 | else | |
2172 | val = 0; | |
f02232aa | 2173 | |
c19d1205 ZW |
2174 | /* Add index table entry. This is two words. */ |
2175 | start_unwind_section (unwind.saved_seg, 1); | |
2176 | frag_align (2, 0, 0); | |
2177 | record_alignment (now_seg, 2); | |
b99bd4ef | 2178 | |
c19d1205 ZW |
2179 | ptr = frag_more (8); |
2180 | where = frag_now_fix () - 8; | |
f02232aa | 2181 | |
c19d1205 ZW |
2182 | /* Self relative offset of the function start. */ |
2183 | fix_new (frag_now, where, 4, unwind.proc_start, 0, 1, | |
2184 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 2185 | |
c19d1205 ZW |
2186 | /* Indicate dependency on EHABI-defined personality routines to the |
2187 | linker, if it hasn't been done already. */ | |
2188 | if (unwind.personality_index >= 0 && unwind.personality_index < 3 | |
2189 | && !(marked_pr_dependency & (1 << unwind.personality_index))) | |
2190 | { | |
2191 | static const char *const name[] = { | |
2192 | "__aeabi_unwind_cpp_pr0", | |
2193 | "__aeabi_unwind_cpp_pr1", | |
2194 | "__aeabi_unwind_cpp_pr2" | |
2195 | }; | |
2196 | symbolS *pr = symbol_find_or_make (name[unwind.personality_index]); | |
2197 | fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE); | |
2198 | marked_pr_dependency |= 1 << unwind.personality_index; | |
2199 | seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency | |
2200 | = marked_pr_dependency; | |
2201 | } | |
f02232aa | 2202 | |
c19d1205 ZW |
2203 | if (val) |
2204 | /* Inline exception table entry. */ | |
2205 | md_number_to_chars (ptr + 4, val, 4); | |
2206 | else | |
2207 | /* Self relative offset of the table entry. */ | |
2208 | fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1, | |
2209 | BFD_RELOC_ARM_PREL31); | |
f02232aa | 2210 | |
c19d1205 ZW |
2211 | /* Restore the original section. */ |
2212 | subseg_set (unwind.saved_seg, unwind.saved_subseg); | |
2213 | } | |
f02232aa | 2214 | |
f02232aa | 2215 | |
c19d1205 | 2216 | /* Parse an unwind_cantunwind directive. */ |
b99bd4ef | 2217 | |
c19d1205 ZW |
2218 | static void |
2219 | s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED) | |
2220 | { | |
2221 | demand_empty_rest_of_line (); | |
2222 | if (unwind.personality_routine || unwind.personality_index != -1) | |
2223 | as_bad (_("personality routine specified for cantunwind frame")); | |
b99bd4ef | 2224 | |
c19d1205 ZW |
2225 | unwind.personality_index = -2; |
2226 | } | |
b99bd4ef | 2227 | |
b99bd4ef | 2228 | |
c19d1205 | 2229 | /* Parse a personalityindex directive. */ |
b99bd4ef | 2230 | |
c19d1205 ZW |
2231 | static void |
2232 | s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED) | |
2233 | { | |
2234 | expressionS exp; | |
b99bd4ef | 2235 | |
c19d1205 ZW |
2236 | if (unwind.personality_routine || unwind.personality_index != -1) |
2237 | as_bad (_("duplicate .personalityindex directive")); | |
b99bd4ef | 2238 | |
c19d1205 | 2239 | expression (&exp); |
b99bd4ef | 2240 | |
c19d1205 ZW |
2241 | if (exp.X_op != O_constant |
2242 | || exp.X_add_number < 0 || exp.X_add_number > 15) | |
b99bd4ef | 2243 | { |
c19d1205 ZW |
2244 | as_bad (_("bad personality routine number")); |
2245 | ignore_rest_of_line (); | |
2246 | return; | |
b99bd4ef NC |
2247 | } |
2248 | ||
c19d1205 | 2249 | unwind.personality_index = exp.X_add_number; |
b99bd4ef | 2250 | |
c19d1205 ZW |
2251 | demand_empty_rest_of_line (); |
2252 | } | |
e16bb312 | 2253 | |
e16bb312 | 2254 | |
c19d1205 | 2255 | /* Parse a personality directive. */ |
e16bb312 | 2256 | |
c19d1205 ZW |
2257 | static void |
2258 | s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED) | |
2259 | { | |
2260 | char *name, *p, c; | |
a737bd4d | 2261 | |
c19d1205 ZW |
2262 | if (unwind.personality_routine || unwind.personality_index != -1) |
2263 | as_bad (_("duplicate .personality directive")); | |
a737bd4d | 2264 | |
c19d1205 ZW |
2265 | name = input_line_pointer; |
2266 | c = get_symbol_end (); | |
2267 | p = input_line_pointer; | |
2268 | unwind.personality_routine = symbol_find_or_make (name); | |
2269 | *p = c; | |
2270 | demand_empty_rest_of_line (); | |
2271 | } | |
e16bb312 | 2272 | |
e16bb312 | 2273 | |
c19d1205 | 2274 | /* Parse a directive saving core registers. */ |
e16bb312 | 2275 | |
c19d1205 ZW |
2276 | static void |
2277 | s_arm_unwind_save_core (void) | |
e16bb312 | 2278 | { |
c19d1205 ZW |
2279 | valueT op; |
2280 | long range; | |
2281 | int n; | |
e16bb312 | 2282 | |
c19d1205 ZW |
2283 | range = parse_reg_list (&input_line_pointer); |
2284 | if (range == FAIL) | |
e16bb312 | 2285 | { |
c19d1205 ZW |
2286 | as_bad (_("expected register list")); |
2287 | ignore_rest_of_line (); | |
2288 | return; | |
2289 | } | |
e16bb312 | 2290 | |
c19d1205 | 2291 | demand_empty_rest_of_line (); |
e16bb312 | 2292 | |
c19d1205 ZW |
2293 | /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...} |
2294 | into .unwind_save {..., sp...}. We aren't bothered about the value of | |
2295 | ip because it is clobbered by calls. */ | |
2296 | if (unwind.sp_restored && unwind.fp_reg == 12 | |
2297 | && (range & 0x3000) == 0x1000) | |
2298 | { | |
2299 | unwind.opcode_count--; | |
2300 | unwind.sp_restored = 0; | |
2301 | range = (range | 0x2000) & ~0x1000; | |
2302 | unwind.pending_offset = 0; | |
2303 | } | |
e16bb312 | 2304 | |
01ae4198 DJ |
2305 | /* Pop r4-r15. */ |
2306 | if (range & 0xfff0) | |
c19d1205 | 2307 | { |
01ae4198 DJ |
2308 | /* See if we can use the short opcodes. These pop a block of up to 8 |
2309 | registers starting with r4, plus maybe r14. */ | |
2310 | for (n = 0; n < 8; n++) | |
2311 | { | |
2312 | /* Break at the first non-saved register. */ | |
2313 | if ((range & (1 << (n + 4))) == 0) | |
2314 | break; | |
2315 | } | |
2316 | /* See if there are any other bits set. */ | |
2317 | if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0) | |
2318 | { | |
2319 | /* Use the long form. */ | |
2320 | op = 0x8000 | ((range >> 4) & 0xfff); | |
2321 | add_unwind_opcode (op, 2); | |
2322 | } | |
0dd132b6 | 2323 | else |
01ae4198 DJ |
2324 | { |
2325 | /* Use the short form. */ | |
2326 | if (range & 0x4000) | |
2327 | op = 0xa8; /* Pop r14. */ | |
2328 | else | |
2329 | op = 0xa0; /* Do not pop r14. */ | |
2330 | op |= (n - 1); | |
2331 | add_unwind_opcode (op, 1); | |
2332 | } | |
c19d1205 | 2333 | } |
0dd132b6 | 2334 | |
c19d1205 ZW |
2335 | /* Pop r0-r3. */ |
2336 | if (range & 0xf) | |
2337 | { | |
2338 | op = 0xb100 | (range & 0xf); | |
2339 | add_unwind_opcode (op, 2); | |
0dd132b6 NC |
2340 | } |
2341 | ||
c19d1205 ZW |
2342 | /* Record the number of bytes pushed. */ |
2343 | for (n = 0; n < 16; n++) | |
2344 | { | |
2345 | if (range & (1 << n)) | |
2346 | unwind.frame_size += 4; | |
2347 | } | |
0dd132b6 NC |
2348 | } |
2349 | ||
c19d1205 ZW |
2350 | |
2351 | /* Parse a directive saving FPA registers. */ | |
b99bd4ef NC |
2352 | |
2353 | static void | |
c19d1205 | 2354 | s_arm_unwind_save_fpa (int reg) |
b99bd4ef | 2355 | { |
c19d1205 ZW |
2356 | expressionS exp; |
2357 | int num_regs; | |
2358 | valueT op; | |
b99bd4ef | 2359 | |
c19d1205 ZW |
2360 | /* Get Number of registers to transfer. */ |
2361 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
2362 | expression (&exp); | |
2363 | else | |
2364 | exp.X_op = O_illegal; | |
b99bd4ef | 2365 | |
c19d1205 | 2366 | if (exp.X_op != O_constant) |
b99bd4ef | 2367 | { |
c19d1205 ZW |
2368 | as_bad (_("expected , <constant>")); |
2369 | ignore_rest_of_line (); | |
b99bd4ef NC |
2370 | return; |
2371 | } | |
2372 | ||
c19d1205 ZW |
2373 | num_regs = exp.X_add_number; |
2374 | ||
2375 | if (num_regs < 1 || num_regs > 4) | |
b99bd4ef | 2376 | { |
c19d1205 ZW |
2377 | as_bad (_("number of registers must be in the range [1:4]")); |
2378 | ignore_rest_of_line (); | |
b99bd4ef NC |
2379 | return; |
2380 | } | |
2381 | ||
c19d1205 | 2382 | demand_empty_rest_of_line (); |
b99bd4ef | 2383 | |
c19d1205 ZW |
2384 | if (reg == 4) |
2385 | { | |
2386 | /* Short form. */ | |
2387 | op = 0xb4 | (num_regs - 1); | |
2388 | add_unwind_opcode (op, 1); | |
2389 | } | |
b99bd4ef NC |
2390 | else |
2391 | { | |
c19d1205 ZW |
2392 | /* Long form. */ |
2393 | op = 0xc800 | (reg << 4) | (num_regs - 1); | |
2394 | add_unwind_opcode (op, 2); | |
b99bd4ef | 2395 | } |
c19d1205 | 2396 | unwind.frame_size += num_regs * 12; |
b99bd4ef NC |
2397 | } |
2398 | ||
c19d1205 ZW |
2399 | |
2400 | /* Parse a directive saving VFP registers. */ | |
b99bd4ef NC |
2401 | |
2402 | static void | |
c19d1205 | 2403 | s_arm_unwind_save_vfp (void) |
b99bd4ef | 2404 | { |
c19d1205 | 2405 | int count; |
ca3f61f7 | 2406 | unsigned int reg; |
c19d1205 | 2407 | valueT op; |
b99bd4ef | 2408 | |
c19d1205 ZW |
2409 | count = parse_vfp_reg_list (&input_line_pointer, ®, 1); |
2410 | if (count == FAIL) | |
b99bd4ef | 2411 | { |
c19d1205 ZW |
2412 | as_bad (_("expected register list")); |
2413 | ignore_rest_of_line (); | |
b99bd4ef NC |
2414 | return; |
2415 | } | |
2416 | ||
c19d1205 | 2417 | demand_empty_rest_of_line (); |
b99bd4ef | 2418 | |
c19d1205 | 2419 | if (reg == 8) |
b99bd4ef | 2420 | { |
c19d1205 ZW |
2421 | /* Short form. */ |
2422 | op = 0xb8 | (count - 1); | |
2423 | add_unwind_opcode (op, 1); | |
b99bd4ef | 2424 | } |
c19d1205 | 2425 | else |
b99bd4ef | 2426 | { |
c19d1205 ZW |
2427 | /* Long form. */ |
2428 | op = 0xb300 | (reg << 4) | (count - 1); | |
2429 | add_unwind_opcode (op, 2); | |
b99bd4ef | 2430 | } |
c19d1205 ZW |
2431 | unwind.frame_size += count * 8 + 4; |
2432 | } | |
b99bd4ef | 2433 | |
b99bd4ef | 2434 | |
c19d1205 ZW |
2435 | /* Parse a directive saving iWMMXt data registers. */ |
2436 | ||
2437 | static void | |
2438 | s_arm_unwind_save_mmxwr (void) | |
2439 | { | |
2440 | int reg; | |
2441 | int hi_reg; | |
2442 | int i; | |
2443 | unsigned mask = 0; | |
2444 | valueT op; | |
b99bd4ef | 2445 | |
c19d1205 ZW |
2446 | if (*input_line_pointer == '{') |
2447 | input_line_pointer++; | |
b99bd4ef | 2448 | |
c19d1205 | 2449 | do |
b99bd4ef | 2450 | { |
c19d1205 | 2451 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); |
b99bd4ef | 2452 | |
c19d1205 | 2453 | if (reg == FAIL) |
b99bd4ef | 2454 | { |
c19d1205 ZW |
2455 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); |
2456 | goto error; | |
b99bd4ef NC |
2457 | } |
2458 | ||
c19d1205 ZW |
2459 | if (mask >> reg) |
2460 | as_tsktsk (_("register list not in ascending order")); | |
2461 | mask |= 1 << reg; | |
b99bd4ef | 2462 | |
c19d1205 ZW |
2463 | if (*input_line_pointer == '-') |
2464 | { | |
2465 | input_line_pointer++; | |
2466 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR); | |
2467 | if (hi_reg == FAIL) | |
2468 | { | |
2469 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR])); | |
2470 | goto error; | |
2471 | } | |
2472 | else if (reg >= hi_reg) | |
2473 | { | |
2474 | as_bad (_("bad register range")); | |
2475 | goto error; | |
2476 | } | |
2477 | for (; reg < hi_reg; reg++) | |
2478 | mask |= 1 << reg; | |
2479 | } | |
2480 | } | |
2481 | while (skip_past_comma (&input_line_pointer) != FAIL); | |
b99bd4ef | 2482 | |
c19d1205 ZW |
2483 | if (*input_line_pointer == '}') |
2484 | input_line_pointer++; | |
b99bd4ef | 2485 | |
c19d1205 | 2486 | demand_empty_rest_of_line (); |
b99bd4ef | 2487 | |
c19d1205 ZW |
2488 | /* Generate any deferred opcodes becuuse we're going to be looking at |
2489 | the list. */ | |
2490 | flush_pending_unwind (); | |
b99bd4ef | 2491 | |
c19d1205 | 2492 | for (i = 0; i < 16; i++) |
b99bd4ef | 2493 | { |
c19d1205 ZW |
2494 | if (mask & (1 << i)) |
2495 | unwind.frame_size += 8; | |
b99bd4ef NC |
2496 | } |
2497 | ||
c19d1205 ZW |
2498 | /* Attempt to combine with a previous opcode. We do this because gcc |
2499 | likes to output separate unwind directives for a single block of | |
2500 | registers. */ | |
2501 | if (unwind.opcode_count > 0) | |
b99bd4ef | 2502 | { |
c19d1205 ZW |
2503 | i = unwind.opcodes[unwind.opcode_count - 1]; |
2504 | if ((i & 0xf8) == 0xc0) | |
2505 | { | |
2506 | i &= 7; | |
2507 | /* Only merge if the blocks are contiguous. */ | |
2508 | if (i < 6) | |
2509 | { | |
2510 | if ((mask & 0xfe00) == (1 << 9)) | |
2511 | { | |
2512 | mask |= ((1 << (i + 11)) - 1) & 0xfc00; | |
2513 | unwind.opcode_count--; | |
2514 | } | |
2515 | } | |
2516 | else if (i == 6 && unwind.opcode_count >= 2) | |
2517 | { | |
2518 | i = unwind.opcodes[unwind.opcode_count - 2]; | |
2519 | reg = i >> 4; | |
2520 | i &= 0xf; | |
b99bd4ef | 2521 | |
c19d1205 ZW |
2522 | op = 0xffff << (reg - 1); |
2523 | if (reg > 0 | |
2524 | || ((mask & op) == (1u << (reg - 1)))) | |
2525 | { | |
2526 | op = (1 << (reg + i + 1)) - 1; | |
2527 | op &= ~((1 << reg) - 1); | |
2528 | mask |= op; | |
2529 | unwind.opcode_count -= 2; | |
2530 | } | |
2531 | } | |
2532 | } | |
b99bd4ef NC |
2533 | } |
2534 | ||
c19d1205 ZW |
2535 | hi_reg = 15; |
2536 | /* We want to generate opcodes in the order the registers have been | |
2537 | saved, ie. descending order. */ | |
2538 | for (reg = 15; reg >= -1; reg--) | |
b99bd4ef | 2539 | { |
c19d1205 ZW |
2540 | /* Save registers in blocks. */ |
2541 | if (reg < 0 | |
2542 | || !(mask & (1 << reg))) | |
2543 | { | |
2544 | /* We found an unsaved reg. Generate opcodes to save the | |
2545 | preceeding block. */ | |
2546 | if (reg != hi_reg) | |
2547 | { | |
2548 | if (reg == 9) | |
2549 | { | |
2550 | /* Short form. */ | |
2551 | op = 0xc0 | (hi_reg - 10); | |
2552 | add_unwind_opcode (op, 1); | |
2553 | } | |
2554 | else | |
2555 | { | |
2556 | /* Long form. */ | |
2557 | op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1); | |
2558 | add_unwind_opcode (op, 2); | |
2559 | } | |
2560 | } | |
2561 | hi_reg = reg - 1; | |
2562 | } | |
b99bd4ef NC |
2563 | } |
2564 | ||
c19d1205 ZW |
2565 | return; |
2566 | error: | |
2567 | ignore_rest_of_line (); | |
b99bd4ef NC |
2568 | } |
2569 | ||
2570 | static void | |
c19d1205 | 2571 | s_arm_unwind_save_mmxwcg (void) |
b99bd4ef | 2572 | { |
c19d1205 ZW |
2573 | int reg; |
2574 | int hi_reg; | |
2575 | unsigned mask = 0; | |
2576 | valueT op; | |
b99bd4ef | 2577 | |
c19d1205 ZW |
2578 | if (*input_line_pointer == '{') |
2579 | input_line_pointer++; | |
b99bd4ef | 2580 | |
c19d1205 | 2581 | do |
b99bd4ef | 2582 | { |
c19d1205 | 2583 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); |
b99bd4ef | 2584 | |
c19d1205 ZW |
2585 | if (reg == FAIL) |
2586 | { | |
2587 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
2588 | goto error; | |
2589 | } | |
b99bd4ef | 2590 | |
c19d1205 ZW |
2591 | reg -= 8; |
2592 | if (mask >> reg) | |
2593 | as_tsktsk (_("register list not in ascending order")); | |
2594 | mask |= 1 << reg; | |
b99bd4ef | 2595 | |
c19d1205 ZW |
2596 | if (*input_line_pointer == '-') |
2597 | { | |
2598 | input_line_pointer++; | |
2599 | hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG); | |
2600 | if (hi_reg == FAIL) | |
2601 | { | |
2602 | as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG])); | |
2603 | goto error; | |
2604 | } | |
2605 | else if (reg >= hi_reg) | |
2606 | { | |
2607 | as_bad (_("bad register range")); | |
2608 | goto error; | |
2609 | } | |
2610 | for (; reg < hi_reg; reg++) | |
2611 | mask |= 1 << reg; | |
2612 | } | |
b99bd4ef | 2613 | } |
c19d1205 | 2614 | while (skip_past_comma (&input_line_pointer) != FAIL); |
b99bd4ef | 2615 | |
c19d1205 ZW |
2616 | if (*input_line_pointer == '}') |
2617 | input_line_pointer++; | |
b99bd4ef | 2618 | |
c19d1205 ZW |
2619 | demand_empty_rest_of_line (); |
2620 | ||
2621 | /* Generate any deferred opcodes becuuse we're going to be looking at | |
2622 | the list. */ | |
2623 | flush_pending_unwind (); | |
b99bd4ef | 2624 | |
c19d1205 | 2625 | for (reg = 0; reg < 16; reg++) |
b99bd4ef | 2626 | { |
c19d1205 ZW |
2627 | if (mask & (1 << reg)) |
2628 | unwind.frame_size += 4; | |
b99bd4ef | 2629 | } |
c19d1205 ZW |
2630 | op = 0xc700 | mask; |
2631 | add_unwind_opcode (op, 2); | |
2632 | return; | |
2633 | error: | |
2634 | ignore_rest_of_line (); | |
b99bd4ef NC |
2635 | } |
2636 | ||
c19d1205 ZW |
2637 | |
2638 | /* Parse an unwind_save directive. */ | |
2639 | ||
b99bd4ef | 2640 | static void |
c19d1205 | 2641 | s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED) |
b99bd4ef | 2642 | { |
c19d1205 ZW |
2643 | char *peek; |
2644 | struct reg_entry *reg; | |
2645 | bfd_boolean had_brace = FALSE; | |
b99bd4ef | 2646 | |
c19d1205 ZW |
2647 | /* Figure out what sort of save we have. */ |
2648 | peek = input_line_pointer; | |
b99bd4ef | 2649 | |
c19d1205 | 2650 | if (*peek == '{') |
b99bd4ef | 2651 | { |
c19d1205 ZW |
2652 | had_brace = TRUE; |
2653 | peek++; | |
b99bd4ef NC |
2654 | } |
2655 | ||
c19d1205 | 2656 | reg = arm_reg_parse_multi (&peek); |
b99bd4ef | 2657 | |
c19d1205 | 2658 | if (!reg) |
b99bd4ef | 2659 | { |
c19d1205 ZW |
2660 | as_bad (_("register expected")); |
2661 | ignore_rest_of_line (); | |
b99bd4ef NC |
2662 | return; |
2663 | } | |
2664 | ||
c19d1205 | 2665 | switch (reg->type) |
b99bd4ef | 2666 | { |
c19d1205 ZW |
2667 | case REG_TYPE_FN: |
2668 | if (had_brace) | |
2669 | { | |
2670 | as_bad (_("FPA .unwind_save does not take a register list")); | |
2671 | ignore_rest_of_line (); | |
2672 | return; | |
2673 | } | |
2674 | s_arm_unwind_save_fpa (reg->number); | |
b99bd4ef | 2675 | return; |
c19d1205 ZW |
2676 | |
2677 | case REG_TYPE_RN: s_arm_unwind_save_core (); return; | |
2678 | case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return; | |
2679 | case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return; | |
2680 | case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return; | |
2681 | ||
2682 | default: | |
2683 | as_bad (_(".unwind_save does not support this kind of register")); | |
2684 | ignore_rest_of_line (); | |
b99bd4ef | 2685 | } |
c19d1205 | 2686 | } |
b99bd4ef | 2687 | |
b99bd4ef | 2688 | |
c19d1205 ZW |
2689 | /* Parse an unwind_movsp directive. */ |
2690 | ||
2691 | static void | |
2692 | s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED) | |
2693 | { | |
2694 | int reg; | |
2695 | valueT op; | |
2696 | ||
2697 | reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); | |
2698 | if (reg == FAIL) | |
b99bd4ef | 2699 | { |
c19d1205 ZW |
2700 | as_bad (_(reg_expected_msgs[REG_TYPE_RN])); |
2701 | ignore_rest_of_line (); | |
b99bd4ef NC |
2702 | return; |
2703 | } | |
c19d1205 | 2704 | demand_empty_rest_of_line (); |
b99bd4ef | 2705 | |
c19d1205 | 2706 | if (reg == REG_SP || reg == REG_PC) |
b99bd4ef | 2707 | { |
c19d1205 | 2708 | as_bad (_("SP and PC not permitted in .unwind_movsp directive")); |
b99bd4ef NC |
2709 | return; |
2710 | } | |
2711 | ||
c19d1205 ZW |
2712 | if (unwind.fp_reg != REG_SP) |
2713 | as_bad (_("unexpected .unwind_movsp directive")); | |
b99bd4ef | 2714 | |
c19d1205 ZW |
2715 | /* Generate opcode to restore the value. */ |
2716 | op = 0x90 | reg; | |
2717 | add_unwind_opcode (op, 1); | |
2718 | ||
2719 | /* Record the information for later. */ | |
2720 | unwind.fp_reg = reg; | |
2721 | unwind.fp_offset = unwind.frame_size; | |
2722 | unwind.sp_restored = 1; | |
b05fe5cf ZW |
2723 | } |
2724 | ||
c19d1205 ZW |
2725 | /* Parse an unwind_pad directive. */ |
2726 | ||
b05fe5cf | 2727 | static void |
c19d1205 | 2728 | s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED) |
b05fe5cf | 2729 | { |
c19d1205 | 2730 | int offset; |
b05fe5cf | 2731 | |
c19d1205 ZW |
2732 | if (immediate_for_directive (&offset) == FAIL) |
2733 | return; | |
b99bd4ef | 2734 | |
c19d1205 ZW |
2735 | if (offset & 3) |
2736 | { | |
2737 | as_bad (_("stack increment must be multiple of 4")); | |
2738 | ignore_rest_of_line (); | |
2739 | return; | |
2740 | } | |
b99bd4ef | 2741 | |
c19d1205 ZW |
2742 | /* Don't generate any opcodes, just record the details for later. */ |
2743 | unwind.frame_size += offset; | |
2744 | unwind.pending_offset += offset; | |
2745 | ||
2746 | demand_empty_rest_of_line (); | |
2747 | } | |
2748 | ||
2749 | /* Parse an unwind_setfp directive. */ | |
2750 | ||
2751 | static void | |
2752 | s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED) | |
b99bd4ef | 2753 | { |
c19d1205 ZW |
2754 | int sp_reg; |
2755 | int fp_reg; | |
2756 | int offset; | |
2757 | ||
2758 | fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); | |
2759 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
2760 | sp_reg = FAIL; | |
2761 | else | |
2762 | sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN); | |
b99bd4ef | 2763 | |
c19d1205 ZW |
2764 | if (fp_reg == FAIL || sp_reg == FAIL) |
2765 | { | |
2766 | as_bad (_("expected <reg>, <reg>")); | |
2767 | ignore_rest_of_line (); | |
2768 | return; | |
2769 | } | |
b99bd4ef | 2770 | |
c19d1205 ZW |
2771 | /* Optional constant. */ |
2772 | if (skip_past_comma (&input_line_pointer) != FAIL) | |
2773 | { | |
2774 | if (immediate_for_directive (&offset) == FAIL) | |
2775 | return; | |
2776 | } | |
2777 | else | |
2778 | offset = 0; | |
a737bd4d | 2779 | |
c19d1205 | 2780 | demand_empty_rest_of_line (); |
a737bd4d | 2781 | |
c19d1205 | 2782 | if (sp_reg != 13 && sp_reg != unwind.fp_reg) |
a737bd4d | 2783 | { |
c19d1205 ZW |
2784 | as_bad (_("register must be either sp or set by a previous" |
2785 | "unwind_movsp directive")); | |
2786 | return; | |
a737bd4d NC |
2787 | } |
2788 | ||
c19d1205 ZW |
2789 | /* Don't generate any opcodes, just record the information for later. */ |
2790 | unwind.fp_reg = fp_reg; | |
2791 | unwind.fp_used = 1; | |
2792 | if (sp_reg == 13) | |
2793 | unwind.fp_offset = unwind.frame_size - offset; | |
2794 | else | |
2795 | unwind.fp_offset -= offset; | |
a737bd4d NC |
2796 | } |
2797 | ||
c19d1205 ZW |
2798 | /* Parse an unwind_raw directive. */ |
2799 | ||
2800 | static void | |
2801 | s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED) | |
a737bd4d | 2802 | { |
c19d1205 ZW |
2803 | expressionS exp; |
2804 | /* This is an arbitary limit. */ | |
2805 | unsigned char op[16]; | |
2806 | int count; | |
a737bd4d | 2807 | |
c19d1205 ZW |
2808 | expression (&exp); |
2809 | if (exp.X_op == O_constant | |
2810 | && skip_past_comma (&input_line_pointer) != FAIL) | |
a737bd4d | 2811 | { |
c19d1205 ZW |
2812 | unwind.frame_size += exp.X_add_number; |
2813 | expression (&exp); | |
2814 | } | |
2815 | else | |
2816 | exp.X_op = O_illegal; | |
a737bd4d | 2817 | |
c19d1205 ZW |
2818 | if (exp.X_op != O_constant) |
2819 | { | |
2820 | as_bad (_("expected <offset>, <opcode>")); | |
2821 | ignore_rest_of_line (); | |
2822 | return; | |
2823 | } | |
a737bd4d | 2824 | |
c19d1205 | 2825 | count = 0; |
a737bd4d | 2826 | |
c19d1205 ZW |
2827 | /* Parse the opcode. */ |
2828 | for (;;) | |
2829 | { | |
2830 | if (count >= 16) | |
2831 | { | |
2832 | as_bad (_("unwind opcode too long")); | |
2833 | ignore_rest_of_line (); | |
a737bd4d | 2834 | } |
c19d1205 | 2835 | if (exp.X_op != O_constant || exp.X_add_number & ~0xff) |
a737bd4d | 2836 | { |
c19d1205 ZW |
2837 | as_bad (_("invalid unwind opcode")); |
2838 | ignore_rest_of_line (); | |
2839 | return; | |
a737bd4d | 2840 | } |
c19d1205 | 2841 | op[count++] = exp.X_add_number; |
a737bd4d | 2842 | |
c19d1205 ZW |
2843 | /* Parse the next byte. */ |
2844 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
2845 | break; | |
a737bd4d | 2846 | |
c19d1205 ZW |
2847 | expression (&exp); |
2848 | } | |
b99bd4ef | 2849 | |
c19d1205 ZW |
2850 | /* Add the opcode bytes in reverse order. */ |
2851 | while (count--) | |
2852 | add_unwind_opcode (op[count], 1); | |
b99bd4ef | 2853 | |
c19d1205 | 2854 | demand_empty_rest_of_line (); |
b99bd4ef | 2855 | } |
ee065d83 PB |
2856 | |
2857 | ||
2858 | /* Parse a .eabi_attribute directive. */ | |
2859 | ||
2860 | static void | |
2861 | s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED) | |
2862 | { | |
2863 | expressionS exp; | |
2864 | bfd_boolean is_string; | |
2865 | int tag; | |
2866 | unsigned int i = 0; | |
2867 | char *s = NULL; | |
2868 | char saved_char; | |
2869 | ||
2870 | expression (& exp); | |
2871 | if (exp.X_op != O_constant) | |
2872 | goto bad; | |
2873 | ||
2874 | tag = exp.X_add_number; | |
2875 | if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0)) | |
2876 | is_string = 1; | |
2877 | else | |
2878 | is_string = 0; | |
2879 | ||
2880 | if (skip_past_comma (&input_line_pointer) == FAIL) | |
2881 | goto bad; | |
2882 | if (tag == 32 || !is_string) | |
2883 | { | |
2884 | expression (& exp); | |
2885 | if (exp.X_op != O_constant) | |
2886 | { | |
2887 | as_bad (_("expected numeric constant")); | |
2888 | ignore_rest_of_line (); | |
2889 | return; | |
2890 | } | |
2891 | i = exp.X_add_number; | |
2892 | } | |
2893 | if (tag == Tag_compatibility | |
2894 | && skip_past_comma (&input_line_pointer) == FAIL) | |
2895 | { | |
2896 | as_bad (_("expected comma")); | |
2897 | ignore_rest_of_line (); | |
2898 | return; | |
2899 | } | |
2900 | if (is_string) | |
2901 | { | |
2902 | skip_whitespace(input_line_pointer); | |
2903 | if (*input_line_pointer != '"') | |
2904 | goto bad_string; | |
2905 | input_line_pointer++; | |
2906 | s = input_line_pointer; | |
2907 | while (*input_line_pointer && *input_line_pointer != '"') | |
2908 | input_line_pointer++; | |
2909 | if (*input_line_pointer != '"') | |
2910 | goto bad_string; | |
2911 | saved_char = *input_line_pointer; | |
2912 | *input_line_pointer = 0; | |
2913 | } | |
2914 | else | |
2915 | { | |
2916 | s = NULL; | |
2917 | saved_char = 0; | |
2918 | } | |
2919 | ||
2920 | if (tag == Tag_compatibility) | |
2921 | elf32_arm_add_eabi_attr_compat (stdoutput, i, s); | |
2922 | else if (is_string) | |
2923 | elf32_arm_add_eabi_attr_string (stdoutput, tag, s); | |
2924 | else | |
2925 | elf32_arm_add_eabi_attr_int (stdoutput, tag, i); | |
2926 | ||
2927 | if (s) | |
2928 | { | |
2929 | *input_line_pointer = saved_char; | |
2930 | input_line_pointer++; | |
2931 | } | |
2932 | demand_empty_rest_of_line (); | |
2933 | return; | |
2934 | bad_string: | |
2935 | as_bad (_("bad string constant")); | |
2936 | ignore_rest_of_line (); | |
2937 | return; | |
2938 | bad: | |
2939 | as_bad (_("expected <tag> , <value>")); | |
2940 | ignore_rest_of_line (); | |
2941 | } | |
2942 | ||
2943 | static void s_arm_arch (int); | |
2944 | static void s_arm_cpu (int); | |
2945 | static void s_arm_fpu (int); | |
c19d1205 | 2946 | #endif /* OBJ_ELF */ |
b99bd4ef | 2947 | |
c19d1205 ZW |
2948 | /* This table describes all the machine specific pseudo-ops the assembler |
2949 | has to support. The fields are: | |
2950 | pseudo-op name without dot | |
2951 | function to call to execute this pseudo-op | |
2952 | Integer arg to pass to the function. */ | |
b99bd4ef | 2953 | |
c19d1205 | 2954 | const pseudo_typeS md_pseudo_table[] = |
b99bd4ef | 2955 | { |
c19d1205 ZW |
2956 | /* Never called because '.req' does not start a line. */ |
2957 | { "req", s_req, 0 }, | |
2958 | { "unreq", s_unreq, 0 }, | |
2959 | { "bss", s_bss, 0 }, | |
2960 | { "align", s_align, 0 }, | |
2961 | { "arm", s_arm, 0 }, | |
2962 | { "thumb", s_thumb, 0 }, | |
2963 | { "code", s_code, 0 }, | |
2964 | { "force_thumb", s_force_thumb, 0 }, | |
2965 | { "thumb_func", s_thumb_func, 0 }, | |
2966 | { "thumb_set", s_thumb_set, 0 }, | |
2967 | { "even", s_even, 0 }, | |
2968 | { "ltorg", s_ltorg, 0 }, | |
2969 | { "pool", s_ltorg, 0 }, | |
2970 | { "syntax", s_syntax, 0 }, | |
2971 | #ifdef OBJ_ELF | |
2972 | { "word", s_arm_elf_cons, 4 }, | |
2973 | { "long", s_arm_elf_cons, 4 }, | |
2974 | { "rel31", s_arm_rel31, 0 }, | |
2975 | { "fnstart", s_arm_unwind_fnstart, 0 }, | |
2976 | { "fnend", s_arm_unwind_fnend, 0 }, | |
2977 | { "cantunwind", s_arm_unwind_cantunwind, 0 }, | |
2978 | { "personality", s_arm_unwind_personality, 0 }, | |
2979 | { "personalityindex", s_arm_unwind_personalityindex, 0 }, | |
2980 | { "handlerdata", s_arm_unwind_handlerdata, 0 }, | |
2981 | { "save", s_arm_unwind_save, 0 }, | |
2982 | { "movsp", s_arm_unwind_movsp, 0 }, | |
2983 | { "pad", s_arm_unwind_pad, 0 }, | |
2984 | { "setfp", s_arm_unwind_setfp, 0 }, | |
2985 | { "unwind_raw", s_arm_unwind_raw, 0 }, | |
ee065d83 PB |
2986 | { "cpu", s_arm_cpu, 0 }, |
2987 | { "arch", s_arm_arch, 0 }, | |
2988 | { "fpu", s_arm_fpu, 0 }, | |
2989 | { "eabi_attribute", s_arm_eabi_attribute, 0 }, | |
c19d1205 ZW |
2990 | #else |
2991 | { "word", cons, 4}, | |
2992 | #endif | |
2993 | { "extend", float_cons, 'x' }, | |
2994 | { "ldouble", float_cons, 'x' }, | |
2995 | { "packed", float_cons, 'p' }, | |
2996 | { 0, 0, 0 } | |
2997 | }; | |
2998 | \f | |
2999 | /* Parser functions used exclusively in instruction operands. */ | |
b99bd4ef | 3000 | |
c19d1205 ZW |
3001 | /* Generic immediate-value read function for use in insn parsing. |
3002 | STR points to the beginning of the immediate (the leading #); | |
3003 | VAL receives the value; if the value is outside [MIN, MAX] | |
3004 | issue an error. PREFIX_OPT is true if the immediate prefix is | |
3005 | optional. */ | |
b99bd4ef | 3006 | |
c19d1205 ZW |
3007 | static int |
3008 | parse_immediate (char **str, int *val, int min, int max, | |
3009 | bfd_boolean prefix_opt) | |
3010 | { | |
3011 | expressionS exp; | |
3012 | my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX); | |
3013 | if (exp.X_op != O_constant) | |
b99bd4ef | 3014 | { |
c19d1205 ZW |
3015 | inst.error = _("constant expression required"); |
3016 | return FAIL; | |
3017 | } | |
b99bd4ef | 3018 | |
c19d1205 ZW |
3019 | if (exp.X_add_number < min || exp.X_add_number > max) |
3020 | { | |
3021 | inst.error = _("immediate value out of range"); | |
3022 | return FAIL; | |
3023 | } | |
b99bd4ef | 3024 | |
c19d1205 ZW |
3025 | *val = exp.X_add_number; |
3026 | return SUCCESS; | |
3027 | } | |
b99bd4ef | 3028 | |
c19d1205 ZW |
3029 | /* Returns the pseudo-register number of an FPA immediate constant, |
3030 | or FAIL if there isn't a valid constant here. */ | |
b99bd4ef | 3031 | |
c19d1205 ZW |
3032 | static int |
3033 | parse_fpa_immediate (char ** str) | |
3034 | { | |
3035 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
3036 | char * save_in; | |
3037 | expressionS exp; | |
3038 | int i; | |
3039 | int j; | |
b99bd4ef | 3040 | |
c19d1205 ZW |
3041 | /* First try and match exact strings, this is to guarantee |
3042 | that some formats will work even for cross assembly. */ | |
b99bd4ef | 3043 | |
c19d1205 ZW |
3044 | for (i = 0; fp_const[i]; i++) |
3045 | { | |
3046 | if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0) | |
b99bd4ef | 3047 | { |
c19d1205 | 3048 | char *start = *str; |
b99bd4ef | 3049 | |
c19d1205 ZW |
3050 | *str += strlen (fp_const[i]); |
3051 | if (is_end_of_line[(unsigned char) **str]) | |
3052 | return i + 8; | |
3053 | *str = start; | |
3054 | } | |
3055 | } | |
b99bd4ef | 3056 | |
c19d1205 ZW |
3057 | /* Just because we didn't get a match doesn't mean that the constant |
3058 | isn't valid, just that it is in a format that we don't | |
3059 | automatically recognize. Try parsing it with the standard | |
3060 | expression routines. */ | |
b99bd4ef | 3061 | |
c19d1205 | 3062 | memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE)); |
b99bd4ef | 3063 | |
c19d1205 ZW |
3064 | /* Look for a raw floating point number. */ |
3065 | if ((save_in = atof_ieee (*str, 'x', words)) != NULL | |
3066 | && is_end_of_line[(unsigned char) *save_in]) | |
3067 | { | |
3068 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
3069 | { | |
3070 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
b99bd4ef | 3071 | { |
c19d1205 ZW |
3072 | if (words[j] != fp_values[i][j]) |
3073 | break; | |
b99bd4ef NC |
3074 | } |
3075 | ||
c19d1205 | 3076 | if (j == MAX_LITTLENUMS) |
b99bd4ef | 3077 | { |
c19d1205 ZW |
3078 | *str = save_in; |
3079 | return i + 8; | |
b99bd4ef NC |
3080 | } |
3081 | } | |
3082 | } | |
b99bd4ef | 3083 | |
c19d1205 ZW |
3084 | /* Try and parse a more complex expression, this will probably fail |
3085 | unless the code uses a floating point prefix (eg "0f"). */ | |
3086 | save_in = input_line_pointer; | |
3087 | input_line_pointer = *str; | |
3088 | if (expression (&exp) == absolute_section | |
3089 | && exp.X_op == O_big | |
3090 | && exp.X_add_number < 0) | |
3091 | { | |
3092 | /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it. | |
3093 | Ditto for 15. */ | |
3094 | if (gen_to_words (words, 5, (long) 15) == 0) | |
3095 | { | |
3096 | for (i = 0; i < NUM_FLOAT_VALS; i++) | |
3097 | { | |
3098 | for (j = 0; j < MAX_LITTLENUMS; j++) | |
3099 | { | |
3100 | if (words[j] != fp_values[i][j]) | |
3101 | break; | |
3102 | } | |
b99bd4ef | 3103 | |
c19d1205 ZW |
3104 | if (j == MAX_LITTLENUMS) |
3105 | { | |
3106 | *str = input_line_pointer; | |
3107 | input_line_pointer = save_in; | |
3108 | return i + 8; | |
3109 | } | |
3110 | } | |
3111 | } | |
b99bd4ef NC |
3112 | } |
3113 | ||
c19d1205 ZW |
3114 | *str = input_line_pointer; |
3115 | input_line_pointer = save_in; | |
3116 | inst.error = _("invalid FPA immediate expression"); | |
3117 | return FAIL; | |
b99bd4ef NC |
3118 | } |
3119 | ||
c19d1205 ZW |
3120 | /* Shift operands. */ |
3121 | enum shift_kind | |
b99bd4ef | 3122 | { |
c19d1205 ZW |
3123 | SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX |
3124 | }; | |
b99bd4ef | 3125 | |
c19d1205 ZW |
3126 | struct asm_shift_name |
3127 | { | |
3128 | const char *name; | |
3129 | enum shift_kind kind; | |
3130 | }; | |
b99bd4ef | 3131 | |
c19d1205 ZW |
3132 | /* Third argument to parse_shift. */ |
3133 | enum parse_shift_mode | |
3134 | { | |
3135 | NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */ | |
3136 | SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */ | |
3137 | SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */ | |
3138 | SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */ | |
3139 | SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */ | |
3140 | }; | |
b99bd4ef | 3141 | |
c19d1205 ZW |
3142 | /* Parse a <shift> specifier on an ARM data processing instruction. |
3143 | This has three forms: | |
b99bd4ef | 3144 | |
c19d1205 ZW |
3145 | (LSL|LSR|ASL|ASR|ROR) Rs |
3146 | (LSL|LSR|ASL|ASR|ROR) #imm | |
3147 | RRX | |
b99bd4ef | 3148 | |
c19d1205 ZW |
3149 | Note that ASL is assimilated to LSL in the instruction encoding, and |
3150 | RRX to ROR #0 (which cannot be written as such). */ | |
b99bd4ef | 3151 | |
c19d1205 ZW |
3152 | static int |
3153 | parse_shift (char **str, int i, enum parse_shift_mode mode) | |
b99bd4ef | 3154 | { |
c19d1205 ZW |
3155 | const struct asm_shift_name *shift_name; |
3156 | enum shift_kind shift; | |
3157 | char *s = *str; | |
3158 | char *p = s; | |
3159 | int reg; | |
b99bd4ef | 3160 | |
c19d1205 ZW |
3161 | for (p = *str; ISALPHA (*p); p++) |
3162 | ; | |
b99bd4ef | 3163 | |
c19d1205 | 3164 | if (p == *str) |
b99bd4ef | 3165 | { |
c19d1205 ZW |
3166 | inst.error = _("shift expression expected"); |
3167 | return FAIL; | |
b99bd4ef NC |
3168 | } |
3169 | ||
c19d1205 ZW |
3170 | shift_name = hash_find_n (arm_shift_hsh, *str, p - *str); |
3171 | ||
3172 | if (shift_name == NULL) | |
b99bd4ef | 3173 | { |
c19d1205 ZW |
3174 | inst.error = _("shift expression expected"); |
3175 | return FAIL; | |
b99bd4ef NC |
3176 | } |
3177 | ||
c19d1205 | 3178 | shift = shift_name->kind; |
b99bd4ef | 3179 | |
c19d1205 ZW |
3180 | switch (mode) |
3181 | { | |
3182 | case NO_SHIFT_RESTRICT: | |
3183 | case SHIFT_IMMEDIATE: break; | |
b99bd4ef | 3184 | |
c19d1205 ZW |
3185 | case SHIFT_LSL_OR_ASR_IMMEDIATE: |
3186 | if (shift != SHIFT_LSL && shift != SHIFT_ASR) | |
3187 | { | |
3188 | inst.error = _("'LSL' or 'ASR' required"); | |
3189 | return FAIL; | |
3190 | } | |
3191 | break; | |
b99bd4ef | 3192 | |
c19d1205 ZW |
3193 | case SHIFT_LSL_IMMEDIATE: |
3194 | if (shift != SHIFT_LSL) | |
3195 | { | |
3196 | inst.error = _("'LSL' required"); | |
3197 | return FAIL; | |
3198 | } | |
3199 | break; | |
b99bd4ef | 3200 | |
c19d1205 ZW |
3201 | case SHIFT_ASR_IMMEDIATE: |
3202 | if (shift != SHIFT_ASR) | |
3203 | { | |
3204 | inst.error = _("'ASR' required"); | |
3205 | return FAIL; | |
3206 | } | |
3207 | break; | |
b99bd4ef | 3208 | |
c19d1205 ZW |
3209 | default: abort (); |
3210 | } | |
b99bd4ef | 3211 | |
c19d1205 ZW |
3212 | if (shift != SHIFT_RRX) |
3213 | { | |
3214 | /* Whitespace can appear here if the next thing is a bare digit. */ | |
3215 | skip_whitespace (p); | |
b99bd4ef | 3216 | |
c19d1205 ZW |
3217 | if (mode == NO_SHIFT_RESTRICT |
3218 | && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) | |
3219 | { | |
3220 | inst.operands[i].imm = reg; | |
3221 | inst.operands[i].immisreg = 1; | |
3222 | } | |
3223 | else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
3224 | return FAIL; | |
3225 | } | |
3226 | inst.operands[i].shift_kind = shift; | |
3227 | inst.operands[i].shifted = 1; | |
3228 | *str = p; | |
3229 | return SUCCESS; | |
b99bd4ef NC |
3230 | } |
3231 | ||
c19d1205 | 3232 | /* Parse a <shifter_operand> for an ARM data processing instruction: |
b99bd4ef | 3233 | |
c19d1205 ZW |
3234 | #<immediate> |
3235 | #<immediate>, <rotate> | |
3236 | <Rm> | |
3237 | <Rm>, <shift> | |
b99bd4ef | 3238 | |
c19d1205 ZW |
3239 | where <shift> is defined by parse_shift above, and <rotate> is a |
3240 | multiple of 2 between 0 and 30. Validation of immediate operands | |
55cf6793 | 3241 | is deferred to md_apply_fix. */ |
b99bd4ef | 3242 | |
c19d1205 ZW |
3243 | static int |
3244 | parse_shifter_operand (char **str, int i) | |
3245 | { | |
3246 | int value; | |
3247 | expressionS expr; | |
b99bd4ef | 3248 | |
c19d1205 ZW |
3249 | if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL) |
3250 | { | |
3251 | inst.operands[i].reg = value; | |
3252 | inst.operands[i].isreg = 1; | |
b99bd4ef | 3253 | |
c19d1205 ZW |
3254 | /* parse_shift will override this if appropriate */ |
3255 | inst.reloc.exp.X_op = O_constant; | |
3256 | inst.reloc.exp.X_add_number = 0; | |
b99bd4ef | 3257 | |
c19d1205 ZW |
3258 | if (skip_past_comma (str) == FAIL) |
3259 | return SUCCESS; | |
b99bd4ef | 3260 | |
c19d1205 ZW |
3261 | /* Shift operation on register. */ |
3262 | return parse_shift (str, i, NO_SHIFT_RESTRICT); | |
b99bd4ef NC |
3263 | } |
3264 | ||
c19d1205 ZW |
3265 | if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX)) |
3266 | return FAIL; | |
b99bd4ef | 3267 | |
c19d1205 | 3268 | if (skip_past_comma (str) == SUCCESS) |
b99bd4ef | 3269 | { |
c19d1205 ZW |
3270 | /* #x, y -- ie explicit rotation by Y. */ |
3271 | if (my_get_expression (&expr, str, GE_NO_PREFIX)) | |
3272 | return FAIL; | |
b99bd4ef | 3273 | |
c19d1205 ZW |
3274 | if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant) |
3275 | { | |
3276 | inst.error = _("constant expression expected"); | |
3277 | return FAIL; | |
3278 | } | |
b99bd4ef | 3279 | |
c19d1205 ZW |
3280 | value = expr.X_add_number; |
3281 | if (value < 0 || value > 30 || value % 2 != 0) | |
3282 | { | |
3283 | inst.error = _("invalid rotation"); | |
3284 | return FAIL; | |
3285 | } | |
3286 | if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255) | |
3287 | { | |
3288 | inst.error = _("invalid constant"); | |
3289 | return FAIL; | |
3290 | } | |
09d92015 | 3291 | |
55cf6793 | 3292 | /* Convert to decoded value. md_apply_fix will put it back. */ |
c19d1205 ZW |
3293 | inst.reloc.exp.X_add_number |
3294 | = (((inst.reloc.exp.X_add_number << (32 - value)) | |
3295 | | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff); | |
09d92015 MM |
3296 | } |
3297 | ||
c19d1205 ZW |
3298 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; |
3299 | inst.reloc.pc_rel = 0; | |
3300 | return SUCCESS; | |
09d92015 MM |
3301 | } |
3302 | ||
c19d1205 ZW |
3303 | /* Parse all forms of an ARM address expression. Information is written |
3304 | to inst.operands[i] and/or inst.reloc. | |
09d92015 | 3305 | |
c19d1205 | 3306 | Preindexed addressing (.preind=1): |
09d92015 | 3307 | |
c19d1205 ZW |
3308 | [Rn, #offset] .reg=Rn .reloc.exp=offset |
3309 | [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3310 | [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3311 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 3312 | |
c19d1205 | 3313 | These three may have a trailing ! which causes .writeback to be set also. |
09d92015 | 3314 | |
c19d1205 | 3315 | Postindexed addressing (.postind=1, .writeback=1): |
09d92015 | 3316 | |
c19d1205 ZW |
3317 | [Rn], #offset .reg=Rn .reloc.exp=offset |
3318 | [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3319 | [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1 | |
3320 | .shift_kind=shift .reloc.exp=shift_imm | |
09d92015 | 3321 | |
c19d1205 | 3322 | Unindexed addressing (.preind=0, .postind=0): |
09d92015 | 3323 | |
c19d1205 | 3324 | [Rn], {option} .reg=Rn .imm=option .immisreg=0 |
09d92015 | 3325 | |
c19d1205 | 3326 | Other: |
09d92015 | 3327 | |
c19d1205 ZW |
3328 | [Rn]{!} shorthand for [Rn,#0]{!} |
3329 | =immediate .isreg=0 .reloc.exp=immediate | |
3330 | label .reg=PC .reloc.pc_rel=1 .reloc.exp=label | |
09d92015 | 3331 | |
c19d1205 ZW |
3332 | It is the caller's responsibility to check for addressing modes not |
3333 | supported by the instruction, and to set inst.reloc.type. */ | |
3334 | ||
3335 | static int | |
3336 | parse_address (char **str, int i) | |
09d92015 | 3337 | { |
c19d1205 ZW |
3338 | char *p = *str; |
3339 | int reg; | |
09d92015 | 3340 | |
c19d1205 | 3341 | if (skip_past_char (&p, '[') == FAIL) |
09d92015 | 3342 | { |
c19d1205 ZW |
3343 | if (skip_past_char (&p, '=') == FAIL) |
3344 | { | |
3345 | /* bare address - translate to PC-relative offset */ | |
3346 | inst.reloc.pc_rel = 1; | |
3347 | inst.operands[i].reg = REG_PC; | |
3348 | inst.operands[i].isreg = 1; | |
3349 | inst.operands[i].preind = 1; | |
3350 | } | |
3351 | /* else a load-constant pseudo op, no special treatment needed here */ | |
09d92015 | 3352 | |
c19d1205 ZW |
3353 | if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX)) |
3354 | return FAIL; | |
09d92015 | 3355 | |
c19d1205 ZW |
3356 | *str = p; |
3357 | return SUCCESS; | |
09d92015 MM |
3358 | } |
3359 | ||
c19d1205 | 3360 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) |
09d92015 | 3361 | { |
c19d1205 ZW |
3362 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); |
3363 | return FAIL; | |
09d92015 | 3364 | } |
c19d1205 ZW |
3365 | inst.operands[i].reg = reg; |
3366 | inst.operands[i].isreg = 1; | |
09d92015 | 3367 | |
c19d1205 | 3368 | if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 3369 | { |
c19d1205 | 3370 | inst.operands[i].preind = 1; |
09d92015 | 3371 | |
c19d1205 ZW |
3372 | if (*p == '+') p++; |
3373 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
3374 | ||
3375 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) | |
09d92015 | 3376 | { |
c19d1205 ZW |
3377 | inst.operands[i].imm = reg; |
3378 | inst.operands[i].immisreg = 1; | |
3379 | ||
3380 | if (skip_past_comma (&p) == SUCCESS) | |
3381 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
3382 | return FAIL; | |
3383 | } | |
3384 | else | |
3385 | { | |
3386 | if (inst.operands[i].negative) | |
3387 | { | |
3388 | inst.operands[i].negative = 0; | |
3389 | p--; | |
3390 | } | |
3391 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
3392 | return FAIL; | |
09d92015 MM |
3393 | } |
3394 | } | |
3395 | ||
c19d1205 | 3396 | if (skip_past_char (&p, ']') == FAIL) |
09d92015 | 3397 | { |
c19d1205 ZW |
3398 | inst.error = _("']' expected"); |
3399 | return FAIL; | |
09d92015 MM |
3400 | } |
3401 | ||
c19d1205 ZW |
3402 | if (skip_past_char (&p, '!') == SUCCESS) |
3403 | inst.operands[i].writeback = 1; | |
09d92015 | 3404 | |
c19d1205 | 3405 | else if (skip_past_comma (&p) == SUCCESS) |
09d92015 | 3406 | { |
c19d1205 ZW |
3407 | if (skip_past_char (&p, '{') == SUCCESS) |
3408 | { | |
3409 | /* [Rn], {expr} - unindexed, with option */ | |
3410 | if (parse_immediate (&p, &inst.operands[i].imm, | |
ca3f61f7 | 3411 | 0, 255, TRUE) == FAIL) |
c19d1205 | 3412 | return FAIL; |
09d92015 | 3413 | |
c19d1205 ZW |
3414 | if (skip_past_char (&p, '}') == FAIL) |
3415 | { | |
3416 | inst.error = _("'}' expected at end of 'option' field"); | |
3417 | return FAIL; | |
3418 | } | |
3419 | if (inst.operands[i].preind) | |
3420 | { | |
3421 | inst.error = _("cannot combine index with option"); | |
3422 | return FAIL; | |
3423 | } | |
3424 | *str = p; | |
3425 | return SUCCESS; | |
09d92015 | 3426 | } |
c19d1205 ZW |
3427 | else |
3428 | { | |
3429 | inst.operands[i].postind = 1; | |
3430 | inst.operands[i].writeback = 1; | |
09d92015 | 3431 | |
c19d1205 ZW |
3432 | if (inst.operands[i].preind) |
3433 | { | |
3434 | inst.error = _("cannot combine pre- and post-indexing"); | |
3435 | return FAIL; | |
3436 | } | |
09d92015 | 3437 | |
c19d1205 ZW |
3438 | if (*p == '+') p++; |
3439 | else if (*p == '-') p++, inst.operands[i].negative = 1; | |
a737bd4d | 3440 | |
c19d1205 ZW |
3441 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL) |
3442 | { | |
3443 | inst.operands[i].imm = reg; | |
3444 | inst.operands[i].immisreg = 1; | |
a737bd4d | 3445 | |
c19d1205 ZW |
3446 | if (skip_past_comma (&p) == SUCCESS) |
3447 | if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL) | |
3448 | return FAIL; | |
3449 | } | |
3450 | else | |
3451 | { | |
3452 | if (inst.operands[i].negative) | |
3453 | { | |
3454 | inst.operands[i].negative = 0; | |
3455 | p--; | |
3456 | } | |
3457 | if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX)) | |
3458 | return FAIL; | |
3459 | } | |
3460 | } | |
a737bd4d NC |
3461 | } |
3462 | ||
c19d1205 ZW |
3463 | /* If at this point neither .preind nor .postind is set, we have a |
3464 | bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */ | |
3465 | if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0) | |
3466 | { | |
3467 | inst.operands[i].preind = 1; | |
3468 | inst.reloc.exp.X_op = O_constant; | |
3469 | inst.reloc.exp.X_add_number = 0; | |
3470 | } | |
3471 | *str = p; | |
3472 | return SUCCESS; | |
a737bd4d NC |
3473 | } |
3474 | ||
c19d1205 | 3475 | /* Miscellaneous. */ |
a737bd4d | 3476 | |
c19d1205 ZW |
3477 | /* Parse a PSR flag operand. The value returned is FAIL on syntax error, |
3478 | or a bitmask suitable to be or-ed into the ARM msr instruction. */ | |
3479 | static int | |
3480 | parse_psr (char **str) | |
09d92015 | 3481 | { |
c19d1205 ZW |
3482 | char *p; |
3483 | unsigned long psr_field; | |
09d92015 | 3484 | |
c19d1205 ZW |
3485 | /* CPSR's and SPSR's can now be lowercase. This is just a convenience |
3486 | feature for ease of use and backwards compatibility. */ | |
3487 | p = *str; | |
3488 | if (*p == 's' || *p == 'S') | |
3489 | psr_field = SPSR_BIT; | |
3490 | else if (*p == 'c' || *p == 'C') | |
3491 | psr_field = 0; | |
3492 | else | |
3493 | goto error; | |
09d92015 | 3494 | |
c19d1205 ZW |
3495 | p++; |
3496 | if (strncasecmp (p, "PSR", 3) != 0) | |
3497 | goto error; | |
3498 | p += 3; | |
09d92015 | 3499 | |
c19d1205 ZW |
3500 | if (*p == '_') |
3501 | { | |
3502 | /* A suffix follows. */ | |
3503 | const struct asm_psr *psr; | |
3504 | char *start; | |
a737bd4d | 3505 | |
c19d1205 ZW |
3506 | p++; |
3507 | start = p; | |
a737bd4d | 3508 | |
c19d1205 ZW |
3509 | do |
3510 | p++; | |
3511 | while (ISALNUM (*p) || *p == '_'); | |
a737bd4d | 3512 | |
c19d1205 ZW |
3513 | psr = hash_find_n (arm_psr_hsh, start, p - start); |
3514 | if (!psr) | |
3515 | goto error; | |
a737bd4d | 3516 | |
c19d1205 | 3517 | psr_field |= psr->field; |
a737bd4d | 3518 | } |
c19d1205 | 3519 | else |
a737bd4d | 3520 | { |
c19d1205 ZW |
3521 | if (ISALNUM (*p)) |
3522 | goto error; /* Garbage after "[CS]PSR". */ | |
3523 | ||
3524 | psr_field |= (PSR_c | PSR_f); | |
a737bd4d | 3525 | } |
c19d1205 ZW |
3526 | *str = p; |
3527 | return psr_field; | |
a737bd4d | 3528 | |
c19d1205 ZW |
3529 | error: |
3530 | inst.error = _("flag for {c}psr instruction expected"); | |
3531 | return FAIL; | |
a737bd4d NC |
3532 | } |
3533 | ||
c19d1205 ZW |
3534 | /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a |
3535 | value suitable for splatting into the AIF field of the instruction. */ | |
a737bd4d | 3536 | |
c19d1205 ZW |
3537 | static int |
3538 | parse_cps_flags (char **str) | |
a737bd4d | 3539 | { |
c19d1205 ZW |
3540 | int val = 0; |
3541 | int saw_a_flag = 0; | |
3542 | char *s = *str; | |
a737bd4d | 3543 | |
c19d1205 ZW |
3544 | for (;;) |
3545 | switch (*s++) | |
3546 | { | |
3547 | case '\0': case ',': | |
3548 | goto done; | |
a737bd4d | 3549 | |
c19d1205 ZW |
3550 | case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break; |
3551 | case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break; | |
3552 | case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break; | |
a737bd4d | 3553 | |
c19d1205 ZW |
3554 | default: |
3555 | inst.error = _("unrecognized CPS flag"); | |
3556 | return FAIL; | |
3557 | } | |
a737bd4d | 3558 | |
c19d1205 ZW |
3559 | done: |
3560 | if (saw_a_flag == 0) | |
a737bd4d | 3561 | { |
c19d1205 ZW |
3562 | inst.error = _("missing CPS flags"); |
3563 | return FAIL; | |
a737bd4d | 3564 | } |
a737bd4d | 3565 | |
c19d1205 ZW |
3566 | *str = s - 1; |
3567 | return val; | |
a737bd4d NC |
3568 | } |
3569 | ||
c19d1205 ZW |
3570 | /* Parse an endian specifier ("BE" or "LE", case insensitive); |
3571 | returns 0 for big-endian, 1 for little-endian, FAIL for an error. */ | |
a737bd4d NC |
3572 | |
3573 | static int | |
c19d1205 | 3574 | parse_endian_specifier (char **str) |
a737bd4d | 3575 | { |
c19d1205 ZW |
3576 | int little_endian; |
3577 | char *s = *str; | |
a737bd4d | 3578 | |
c19d1205 ZW |
3579 | if (strncasecmp (s, "BE", 2)) |
3580 | little_endian = 0; | |
3581 | else if (strncasecmp (s, "LE", 2)) | |
3582 | little_endian = 1; | |
3583 | else | |
a737bd4d | 3584 | { |
c19d1205 | 3585 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
3586 | return FAIL; |
3587 | } | |
3588 | ||
c19d1205 | 3589 | if (ISALNUM (s[2]) || s[2] == '_') |
a737bd4d | 3590 | { |
c19d1205 | 3591 | inst.error = _("valid endian specifiers are be or le"); |
a737bd4d NC |
3592 | return FAIL; |
3593 | } | |
3594 | ||
c19d1205 ZW |
3595 | *str = s + 2; |
3596 | return little_endian; | |
3597 | } | |
a737bd4d | 3598 | |
c19d1205 ZW |
3599 | /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a |
3600 | value suitable for poking into the rotate field of an sxt or sxta | |
3601 | instruction, or FAIL on error. */ | |
3602 | ||
3603 | static int | |
3604 | parse_ror (char **str) | |
3605 | { | |
3606 | int rot; | |
3607 | char *s = *str; | |
3608 | ||
3609 | if (strncasecmp (s, "ROR", 3) == 0) | |
3610 | s += 3; | |
3611 | else | |
a737bd4d | 3612 | { |
c19d1205 | 3613 | inst.error = _("missing rotation field after comma"); |
a737bd4d NC |
3614 | return FAIL; |
3615 | } | |
c19d1205 ZW |
3616 | |
3617 | if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL) | |
3618 | return FAIL; | |
3619 | ||
3620 | switch (rot) | |
a737bd4d | 3621 | { |
c19d1205 ZW |
3622 | case 0: *str = s; return 0x0; |
3623 | case 8: *str = s; return 0x1; | |
3624 | case 16: *str = s; return 0x2; | |
3625 | case 24: *str = s; return 0x3; | |
3626 | ||
3627 | default: | |
3628 | inst.error = _("rotation can only be 0, 8, 16, or 24"); | |
a737bd4d NC |
3629 | return FAIL; |
3630 | } | |
c19d1205 | 3631 | } |
a737bd4d | 3632 | |
c19d1205 ZW |
3633 | /* Parse a conditional code (from conds[] below). The value returned is in the |
3634 | range 0 .. 14, or FAIL. */ | |
3635 | static int | |
3636 | parse_cond (char **str) | |
3637 | { | |
3638 | char *p, *q; | |
3639 | const struct asm_cond *c; | |
a737bd4d | 3640 | |
c19d1205 ZW |
3641 | p = q = *str; |
3642 | while (ISALPHA (*q)) | |
3643 | q++; | |
a737bd4d | 3644 | |
c19d1205 ZW |
3645 | c = hash_find_n (arm_cond_hsh, p, q - p); |
3646 | if (!c) | |
a737bd4d | 3647 | { |
c19d1205 | 3648 | inst.error = _("condition required"); |
a737bd4d NC |
3649 | return FAIL; |
3650 | } | |
3651 | ||
c19d1205 ZW |
3652 | *str = q; |
3653 | return c->value; | |
3654 | } | |
3655 | ||
92e90b6e PB |
3656 | /* Parse the operands of a table branch instruction. Similar to a memory |
3657 | operand. */ | |
3658 | static int | |
3659 | parse_tb (char **str) | |
3660 | { | |
3661 | char * p = *str; | |
3662 | int reg; | |
3663 | ||
3664 | if (skip_past_char (&p, '[') == FAIL) | |
3665 | return FAIL; | |
3666 | ||
3667 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) | |
3668 | { | |
3669 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
3670 | return FAIL; | |
3671 | } | |
3672 | inst.operands[0].reg = reg; | |
3673 | ||
3674 | if (skip_past_comma (&p) == FAIL) | |
3675 | return FAIL; | |
3676 | ||
3677 | if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL) | |
3678 | { | |
3679 | inst.error = _(reg_expected_msgs[REG_TYPE_RN]); | |
3680 | return FAIL; | |
3681 | } | |
3682 | inst.operands[0].imm = reg; | |
3683 | ||
3684 | if (skip_past_comma (&p) == SUCCESS) | |
3685 | { | |
3686 | if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL) | |
3687 | return FAIL; | |
3688 | if (inst.reloc.exp.X_add_number != 1) | |
3689 | { | |
3690 | inst.error = _("invalid shift"); | |
3691 | return FAIL; | |
3692 | } | |
3693 | inst.operands[0].shifted = 1; | |
3694 | } | |
3695 | ||
3696 | if (skip_past_char (&p, ']') == FAIL) | |
3697 | { | |
3698 | inst.error = _("']' expected"); | |
3699 | return FAIL; | |
3700 | } | |
3701 | *str = p; | |
3702 | return SUCCESS; | |
3703 | } | |
3704 | ||
c19d1205 ZW |
3705 | /* Matcher codes for parse_operands. */ |
3706 | enum operand_parse_code | |
3707 | { | |
3708 | OP_stop, /* end of line */ | |
3709 | ||
3710 | OP_RR, /* ARM register */ | |
3711 | OP_RRnpc, /* ARM register, not r15 */ | |
3712 | OP_RRnpcb, /* ARM register, not r15, in square brackets */ | |
3713 | OP_RRw, /* ARM register, not r15, optional trailing ! */ | |
3714 | OP_RCP, /* Coprocessor number */ | |
3715 | OP_RCN, /* Coprocessor register */ | |
3716 | OP_RF, /* FPA register */ | |
3717 | OP_RVS, /* VFP single precision register */ | |
3718 | OP_RVD, /* VFP double precision register */ | |
3719 | OP_RVC, /* VFP control register */ | |
3720 | OP_RMF, /* Maverick F register */ | |
3721 | OP_RMD, /* Maverick D register */ | |
3722 | OP_RMFX, /* Maverick FX register */ | |
3723 | OP_RMDX, /* Maverick DX register */ | |
3724 | OP_RMAX, /* Maverick AX register */ | |
3725 | OP_RMDS, /* Maverick DSPSC register */ | |
3726 | OP_RIWR, /* iWMMXt wR register */ | |
3727 | OP_RIWC, /* iWMMXt wC register */ | |
3728 | OP_RIWG, /* iWMMXt wCG register */ | |
3729 | OP_RXA, /* XScale accumulator register */ | |
3730 | ||
3731 | OP_REGLST, /* ARM register list */ | |
3732 | OP_VRSLST, /* VFP single-precision register list */ | |
3733 | OP_VRDLST, /* VFP double-precision register list */ | |
3734 | ||
3735 | OP_I7, /* immediate value 0 .. 7 */ | |
3736 | OP_I15, /* 0 .. 15 */ | |
3737 | OP_I16, /* 1 .. 16 */ | |
3738 | OP_I31, /* 0 .. 31 */ | |
3739 | OP_I31w, /* 0 .. 31, optional trailing ! */ | |
3740 | OP_I32, /* 1 .. 32 */ | |
3741 | OP_I63s, /* -64 .. 63 */ | |
3742 | OP_I255, /* 0 .. 255 */ | |
3743 | OP_Iffff, /* 0 .. 65535 */ | |
3744 | ||
3745 | OP_I4b, /* immediate, prefix optional, 1 .. 4 */ | |
3746 | OP_I7b, /* 0 .. 7 */ | |
3747 | OP_I15b, /* 0 .. 15 */ | |
3748 | OP_I31b, /* 0 .. 31 */ | |
3749 | ||
3750 | OP_SH, /* shifter operand */ | |
3751 | OP_ADDR, /* Memory address expression (any mode) */ | |
3752 | OP_EXP, /* arbitrary expression */ | |
3753 | OP_EXPi, /* same, with optional immediate prefix */ | |
3754 | OP_EXPr, /* same, with optional relocation suffix */ | |
3755 | ||
3756 | OP_CPSF, /* CPS flags */ | |
3757 | OP_ENDI, /* Endianness specifier */ | |
3758 | OP_PSR, /* CPSR/SPSR mask for msr */ | |
3759 | OP_COND, /* conditional code */ | |
92e90b6e | 3760 | OP_TB, /* Table branch. */ |
c19d1205 ZW |
3761 | |
3762 | OP_RRnpc_I0, /* ARM register or literal 0 */ | |
3763 | OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */ | |
3764 | OP_RR_EXi, /* ARM register or expression with imm prefix */ | |
3765 | OP_RF_IF, /* FPA register or immediate */ | |
3766 | OP_RIWR_RIWC, /* iWMMXt R or C reg */ | |
3767 | ||
3768 | /* Optional operands. */ | |
3769 | OP_oI7b, /* immediate, prefix optional, 0 .. 7 */ | |
3770 | OP_oI31b, /* 0 .. 31 */ | |
3771 | OP_oIffffb, /* 0 .. 65535 */ | |
3772 | OP_oI255c, /* curly-brace enclosed, 0 .. 255 */ | |
3773 | ||
3774 | OP_oRR, /* ARM register */ | |
3775 | OP_oRRnpc, /* ARM register, not the PC */ | |
3776 | OP_oSHll, /* LSL immediate */ | |
3777 | OP_oSHar, /* ASR immediate */ | |
3778 | OP_oSHllar, /* LSL or ASR immediate */ | |
3779 | OP_oROR, /* ROR 0/8/16/24 */ | |
3780 | ||
3781 | OP_FIRST_OPTIONAL = OP_oI7b | |
3782 | }; | |
a737bd4d | 3783 | |
c19d1205 ZW |
3784 | /* Generic instruction operand parser. This does no encoding and no |
3785 | semantic validation; it merely squirrels values away in the inst | |
3786 | structure. Returns SUCCESS or FAIL depending on whether the | |
3787 | specified grammar matched. */ | |
3788 | static int | |
ca3f61f7 | 3789 | parse_operands (char *str, const unsigned char *pattern) |
c19d1205 ZW |
3790 | { |
3791 | unsigned const char *upat = pattern; | |
3792 | char *backtrack_pos = 0; | |
3793 | const char *backtrack_error = 0; | |
3794 | int i, val, backtrack_index = 0; | |
3795 | ||
3796 | #define po_char_or_fail(chr) do { \ | |
3797 | if (skip_past_char (&str, chr) == FAIL) \ | |
3798 | goto bad_args; \ | |
3799 | } while (0) | |
3800 | ||
3801 | #define po_reg_or_fail(regtype) do { \ | |
3802 | val = arm_reg_parse (&str, regtype); \ | |
3803 | if (val == FAIL) \ | |
3804 | { \ | |
3805 | inst.error = _(reg_expected_msgs[regtype]); \ | |
3806 | goto failure; \ | |
3807 | } \ | |
3808 | inst.operands[i].reg = val; \ | |
3809 | inst.operands[i].isreg = 1; \ | |
3810 | } while (0) | |
3811 | ||
3812 | #define po_reg_or_goto(regtype, label) do { \ | |
3813 | val = arm_reg_parse (&str, regtype); \ | |
3814 | if (val == FAIL) \ | |
3815 | goto label; \ | |
3816 | \ | |
3817 | inst.operands[i].reg = val; \ | |
3818 | inst.operands[i].isreg = 1; \ | |
3819 | } while (0) | |
3820 | ||
3821 | #define po_imm_or_fail(min, max, popt) do { \ | |
3822 | if (parse_immediate (&str, &val, min, max, popt) == FAIL) \ | |
3823 | goto failure; \ | |
3824 | inst.operands[i].imm = val; \ | |
3825 | } while (0) | |
3826 | ||
3827 | #define po_misc_or_fail(expr) do { \ | |
3828 | if (expr) \ | |
3829 | goto failure; \ | |
3830 | } while (0) | |
3831 | ||
3832 | skip_whitespace (str); | |
3833 | ||
3834 | for (i = 0; upat[i] != OP_stop; i++) | |
3835 | { | |
3836 | if (upat[i] >= OP_FIRST_OPTIONAL) | |
3837 | { | |
3838 | /* Remember where we are in case we need to backtrack. */ | |
3839 | assert (!backtrack_pos); | |
3840 | backtrack_pos = str; | |
3841 | backtrack_error = inst.error; | |
3842 | backtrack_index = i; | |
3843 | } | |
3844 | ||
3845 | if (i > 0) | |
3846 | po_char_or_fail (','); | |
3847 | ||
3848 | switch (upat[i]) | |
3849 | { | |
3850 | /* Registers */ | |
3851 | case OP_oRRnpc: | |
3852 | case OP_RRnpc: | |
3853 | case OP_oRR: | |
3854 | case OP_RR: po_reg_or_fail (REG_TYPE_RN); break; | |
3855 | case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break; | |
3856 | case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break; | |
3857 | case OP_RF: po_reg_or_fail (REG_TYPE_FN); break; | |
3858 | case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break; | |
3859 | case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break; | |
3860 | case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break; | |
3861 | case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break; | |
3862 | case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break; | |
3863 | case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break; | |
3864 | case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break; | |
3865 | case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break; | |
3866 | case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break; | |
3867 | case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break; | |
3868 | case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break; | |
3869 | case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break; | |
3870 | case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break; | |
3871 | ||
3872 | case OP_RRnpcb: | |
3873 | po_char_or_fail ('['); | |
3874 | po_reg_or_fail (REG_TYPE_RN); | |
3875 | po_char_or_fail (']'); | |
3876 | break; | |
a737bd4d | 3877 | |
c19d1205 ZW |
3878 | case OP_RRw: |
3879 | po_reg_or_fail (REG_TYPE_RN); | |
3880 | if (skip_past_char (&str, '!') == SUCCESS) | |
3881 | inst.operands[i].writeback = 1; | |
3882 | break; | |
3883 | ||
3884 | /* Immediates */ | |
3885 | case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break; | |
3886 | case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break; | |
3887 | case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break; | |
3888 | case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break; | |
3889 | case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break; | |
3890 | case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break; | |
3891 | case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break; | |
3892 | case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break; | |
3893 | ||
3894 | case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break; | |
3895 | case OP_oI7b: | |
3896 | case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break; | |
3897 | case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break; | |
3898 | case OP_oI31b: | |
3899 | case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break; | |
3900 | case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break; | |
3901 | ||
3902 | /* Immediate variants */ | |
3903 | case OP_oI255c: | |
3904 | po_char_or_fail ('{'); | |
3905 | po_imm_or_fail (0, 255, TRUE); | |
3906 | po_char_or_fail ('}'); | |
3907 | break; | |
3908 | ||
3909 | case OP_I31w: | |
3910 | /* The expression parser chokes on a trailing !, so we have | |
3911 | to find it first and zap it. */ | |
3912 | { | |
3913 | char *s = str; | |
3914 | while (*s && *s != ',') | |
3915 | s++; | |
3916 | if (s[-1] == '!') | |
3917 | { | |
3918 | s[-1] = '\0'; | |
3919 | inst.operands[i].writeback = 1; | |
3920 | } | |
3921 | po_imm_or_fail (0, 31, TRUE); | |
3922 | if (str == s - 1) | |
3923 | str = s; | |
3924 | } | |
3925 | break; | |
3926 | ||
3927 | /* Expressions */ | |
3928 | case OP_EXPi: EXPi: | |
3929 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
3930 | GE_OPT_PREFIX)); | |
3931 | break; | |
3932 | ||
3933 | case OP_EXP: | |
3934 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
3935 | GE_NO_PREFIX)); | |
3936 | break; | |
3937 | ||
3938 | case OP_EXPr: EXPr: | |
3939 | po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str, | |
3940 | GE_NO_PREFIX)); | |
3941 | if (inst.reloc.exp.X_op == O_symbol) | |
a737bd4d | 3942 | { |
c19d1205 ZW |
3943 | val = parse_reloc (&str); |
3944 | if (val == -1) | |
3945 | { | |
3946 | inst.error = _("unrecognized relocation suffix"); | |
3947 | goto failure; | |
3948 | } | |
3949 | else if (val != BFD_RELOC_UNUSED) | |
3950 | { | |
3951 | inst.operands[i].imm = val; | |
3952 | inst.operands[i].hasreloc = 1; | |
3953 | } | |
a737bd4d | 3954 | } |
c19d1205 | 3955 | break; |
a737bd4d | 3956 | |
c19d1205 ZW |
3957 | /* Register or expression */ |
3958 | case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break; | |
3959 | case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break; | |
a737bd4d | 3960 | |
c19d1205 ZW |
3961 | /* Register or immediate */ |
3962 | case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break; | |
3963 | I0: po_imm_or_fail (0, 0, FALSE); break; | |
a737bd4d | 3964 | |
c19d1205 ZW |
3965 | case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break; |
3966 | IF: | |
3967 | if (!is_immediate_prefix (*str)) | |
3968 | goto bad_args; | |
3969 | str++; | |
3970 | val = parse_fpa_immediate (&str); | |
3971 | if (val == FAIL) | |
3972 | goto failure; | |
3973 | /* FPA immediates are encoded as registers 8-15. | |
3974 | parse_fpa_immediate has already applied the offset. */ | |
3975 | inst.operands[i].reg = val; | |
3976 | inst.operands[i].isreg = 1; | |
3977 | break; | |
09d92015 | 3978 | |
c19d1205 ZW |
3979 | /* Two kinds of register */ |
3980 | case OP_RIWR_RIWC: | |
3981 | { | |
3982 | struct reg_entry *rege = arm_reg_parse_multi (&str); | |
3983 | if (rege->type != REG_TYPE_MMXWR | |
3984 | && rege->type != REG_TYPE_MMXWC | |
3985 | && rege->type != REG_TYPE_MMXWCG) | |
3986 | { | |
3987 | inst.error = _("iWMMXt data or control register expected"); | |
3988 | goto failure; | |
3989 | } | |
3990 | inst.operands[i].reg = rege->number; | |
3991 | inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR); | |
3992 | } | |
3993 | break; | |
09d92015 | 3994 | |
c19d1205 ZW |
3995 | /* Misc */ |
3996 | case OP_CPSF: val = parse_cps_flags (&str); break; | |
3997 | case OP_ENDI: val = parse_endian_specifier (&str); break; | |
3998 | case OP_oROR: val = parse_ror (&str); break; | |
3999 | case OP_PSR: val = parse_psr (&str); break; | |
4000 | case OP_COND: val = parse_cond (&str); break; | |
4001 | ||
92e90b6e PB |
4002 | case OP_TB: |
4003 | po_misc_or_fail (parse_tb (&str)); | |
4004 | break; | |
4005 | ||
c19d1205 ZW |
4006 | /* Register lists */ |
4007 | case OP_REGLST: | |
4008 | val = parse_reg_list (&str); | |
4009 | if (*str == '^') | |
4010 | { | |
4011 | inst.operands[1].writeback = 1; | |
4012 | str++; | |
4013 | } | |
4014 | break; | |
09d92015 | 4015 | |
c19d1205 ZW |
4016 | case OP_VRSLST: |
4017 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0); | |
4018 | break; | |
09d92015 | 4019 | |
c19d1205 ZW |
4020 | case OP_VRDLST: |
4021 | val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1); | |
4022 | break; | |
a737bd4d | 4023 | |
c19d1205 ZW |
4024 | /* Addressing modes */ |
4025 | case OP_ADDR: | |
4026 | po_misc_or_fail (parse_address (&str, i)); | |
4027 | break; | |
09d92015 | 4028 | |
c19d1205 ZW |
4029 | case OP_SH: |
4030 | po_misc_or_fail (parse_shifter_operand (&str, i)); | |
4031 | break; | |
09d92015 | 4032 | |
c19d1205 ZW |
4033 | case OP_oSHll: |
4034 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE)); | |
4035 | break; | |
09d92015 | 4036 | |
c19d1205 ZW |
4037 | case OP_oSHar: |
4038 | po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE)); | |
4039 | break; | |
09d92015 | 4040 | |
c19d1205 ZW |
4041 | case OP_oSHllar: |
4042 | po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE)); | |
4043 | break; | |
09d92015 | 4044 | |
c19d1205 ZW |
4045 | default: |
4046 | as_fatal ("unhandled operand code %d", upat[i]); | |
4047 | } | |
09d92015 | 4048 | |
c19d1205 ZW |
4049 | /* Various value-based sanity checks and shared operations. We |
4050 | do not signal immediate failures for the register constraints; | |
4051 | this allows a syntax error to take precedence. */ | |
4052 | switch (upat[i]) | |
4053 | { | |
4054 | case OP_oRRnpc: | |
4055 | case OP_RRnpc: | |
4056 | case OP_RRnpcb: | |
4057 | case OP_RRw: | |
4058 | case OP_RRnpc_I0: | |
4059 | if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC) | |
4060 | inst.error = BAD_PC; | |
4061 | break; | |
09d92015 | 4062 | |
c19d1205 ZW |
4063 | case OP_CPSF: |
4064 | case OP_ENDI: | |
4065 | case OP_oROR: | |
4066 | case OP_PSR: | |
4067 | case OP_COND: | |
4068 | case OP_REGLST: | |
4069 | case OP_VRSLST: | |
4070 | case OP_VRDLST: | |
4071 | if (val == FAIL) | |
4072 | goto failure; | |
4073 | inst.operands[i].imm = val; | |
4074 | break; | |
a737bd4d | 4075 | |
c19d1205 ZW |
4076 | default: |
4077 | break; | |
4078 | } | |
09d92015 | 4079 | |
c19d1205 ZW |
4080 | /* If we get here, this operand was successfully parsed. */ |
4081 | inst.operands[i].present = 1; | |
4082 | continue; | |
09d92015 | 4083 | |
c19d1205 | 4084 | bad_args: |
09d92015 | 4085 | inst.error = BAD_ARGS; |
c19d1205 ZW |
4086 | |
4087 | failure: | |
4088 | if (!backtrack_pos) | |
4089 | return FAIL; | |
4090 | ||
4091 | /* Do not backtrack over a trailing optional argument that | |
4092 | absorbed some text. We will only fail again, with the | |
4093 | 'garbage following instruction' error message, which is | |
4094 | probably less helpful than the current one. */ | |
4095 | if (backtrack_index == i && backtrack_pos != str | |
4096 | && upat[i+1] == OP_stop) | |
4097 | return FAIL; | |
4098 | ||
4099 | /* Try again, skipping the optional argument at backtrack_pos. */ | |
4100 | str = backtrack_pos; | |
4101 | inst.error = backtrack_error; | |
4102 | inst.operands[backtrack_index].present = 0; | |
4103 | i = backtrack_index; | |
4104 | backtrack_pos = 0; | |
09d92015 | 4105 | } |
09d92015 | 4106 | |
c19d1205 ZW |
4107 | /* Check that we have parsed all the arguments. */ |
4108 | if (*str != '\0' && !inst.error) | |
4109 | inst.error = _("garbage following instruction"); | |
09d92015 | 4110 | |
c19d1205 | 4111 | return inst.error ? FAIL : SUCCESS; |
09d92015 MM |
4112 | } |
4113 | ||
c19d1205 ZW |
4114 | #undef po_char_or_fail |
4115 | #undef po_reg_or_fail | |
4116 | #undef po_reg_or_goto | |
4117 | #undef po_imm_or_fail | |
4118 | \f | |
4119 | /* Shorthand macro for instruction encoding functions issuing errors. */ | |
4120 | #define constraint(expr, err) do { \ | |
4121 | if (expr) \ | |
4122 | { \ | |
4123 | inst.error = err; \ | |
4124 | return; \ | |
4125 | } \ | |
4126 | } while (0) | |
4127 | ||
4128 | /* Functions for operand encoding. ARM, then Thumb. */ | |
4129 | ||
4130 | #define rotate_left(v, n) (v << n | v >> (32 - n)) | |
4131 | ||
4132 | /* If VAL can be encoded in the immediate field of an ARM instruction, | |
4133 | return the encoded form. Otherwise, return FAIL. */ | |
4134 | ||
4135 | static unsigned int | |
4136 | encode_arm_immediate (unsigned int val) | |
09d92015 | 4137 | { |
c19d1205 ZW |
4138 | unsigned int a, i; |
4139 | ||
4140 | for (i = 0; i < 32; i += 2) | |
4141 | if ((a = rotate_left (val, i)) <= 0xff) | |
4142 | return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */ | |
4143 | ||
4144 | return FAIL; | |
09d92015 MM |
4145 | } |
4146 | ||
c19d1205 ZW |
4147 | /* If VAL can be encoded in the immediate field of a Thumb32 instruction, |
4148 | return the encoded form. Otherwise, return FAIL. */ | |
4149 | static unsigned int | |
4150 | encode_thumb32_immediate (unsigned int val) | |
09d92015 | 4151 | { |
c19d1205 | 4152 | unsigned int a, i; |
09d92015 | 4153 | |
9c3c69f2 | 4154 | if (val <= 0xff) |
c19d1205 | 4155 | return val; |
a737bd4d | 4156 | |
9c3c69f2 | 4157 | for (i = 1; i <= 24; i++) |
09d92015 | 4158 | { |
9c3c69f2 PB |
4159 | a = val >> i; |
4160 | if ((val & ~(0xff << i)) == 0) | |
4161 | return ((val >> i) & 0x7f) | ((32 - i) << 7); | |
09d92015 | 4162 | } |
a737bd4d | 4163 | |
c19d1205 ZW |
4164 | a = val & 0xff; |
4165 | if (val == ((a << 16) | a)) | |
4166 | return 0x100 | a; | |
4167 | if (val == ((a << 24) | (a << 16) | (a << 8) | a)) | |
4168 | return 0x300 | a; | |
09d92015 | 4169 | |
c19d1205 ZW |
4170 | a = val & 0xff00; |
4171 | if (val == ((a << 16) | a)) | |
4172 | return 0x200 | (a >> 8); | |
a737bd4d | 4173 | |
c19d1205 | 4174 | return FAIL; |
09d92015 | 4175 | } |
c19d1205 | 4176 | /* Encode a VFP SP register number into inst.instruction. */ |
09d92015 MM |
4177 | |
4178 | static void | |
c19d1205 | 4179 | encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos) |
09d92015 | 4180 | { |
c19d1205 | 4181 | switch (pos) |
09d92015 | 4182 | { |
c19d1205 ZW |
4183 | case VFP_REG_Sd: |
4184 | inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22); | |
4185 | break; | |
4186 | ||
4187 | case VFP_REG_Sn: | |
4188 | inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7); | |
4189 | break; | |
4190 | ||
4191 | case VFP_REG_Sm: | |
4192 | inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5); | |
4193 | break; | |
4194 | ||
4195 | default: | |
4196 | abort (); | |
09d92015 | 4197 | } |
09d92015 MM |
4198 | } |
4199 | ||
c19d1205 | 4200 | /* Encode a <shift> in an ARM-format instruction. The immediate, |
55cf6793 | 4201 | if any, is handled by md_apply_fix. */ |
09d92015 | 4202 | static void |
c19d1205 | 4203 | encode_arm_shift (int i) |
09d92015 | 4204 | { |
c19d1205 ZW |
4205 | if (inst.operands[i].shift_kind == SHIFT_RRX) |
4206 | inst.instruction |= SHIFT_ROR << 5; | |
4207 | else | |
09d92015 | 4208 | { |
c19d1205 ZW |
4209 | inst.instruction |= inst.operands[i].shift_kind << 5; |
4210 | if (inst.operands[i].immisreg) | |
4211 | { | |
4212 | inst.instruction |= SHIFT_BY_REG; | |
4213 | inst.instruction |= inst.operands[i].imm << 8; | |
4214 | } | |
4215 | else | |
4216 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
09d92015 | 4217 | } |
c19d1205 | 4218 | } |
09d92015 | 4219 | |
c19d1205 ZW |
4220 | static void |
4221 | encode_arm_shifter_operand (int i) | |
4222 | { | |
4223 | if (inst.operands[i].isreg) | |
09d92015 | 4224 | { |
c19d1205 ZW |
4225 | inst.instruction |= inst.operands[i].reg; |
4226 | encode_arm_shift (i); | |
09d92015 | 4227 | } |
c19d1205 ZW |
4228 | else |
4229 | inst.instruction |= INST_IMMEDIATE; | |
09d92015 MM |
4230 | } |
4231 | ||
c19d1205 | 4232 | /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */ |
09d92015 | 4233 | static void |
c19d1205 | 4234 | encode_arm_addr_mode_common (int i, bfd_boolean is_t) |
09d92015 | 4235 | { |
c19d1205 ZW |
4236 | assert (inst.operands[i].isreg); |
4237 | inst.instruction |= inst.operands[i].reg << 16; | |
a737bd4d | 4238 | |
c19d1205 | 4239 | if (inst.operands[i].preind) |
09d92015 | 4240 | { |
c19d1205 ZW |
4241 | if (is_t) |
4242 | { | |
4243 | inst.error = _("instruction does not accept preindexed addressing"); | |
4244 | return; | |
4245 | } | |
4246 | inst.instruction |= PRE_INDEX; | |
4247 | if (inst.operands[i].writeback) | |
4248 | inst.instruction |= WRITE_BACK; | |
09d92015 | 4249 | |
c19d1205 ZW |
4250 | } |
4251 | else if (inst.operands[i].postind) | |
4252 | { | |
4253 | assert (inst.operands[i].writeback); | |
4254 | if (is_t) | |
4255 | inst.instruction |= WRITE_BACK; | |
4256 | } | |
4257 | else /* unindexed - only for coprocessor */ | |
09d92015 | 4258 | { |
c19d1205 | 4259 | inst.error = _("instruction does not accept unindexed addressing"); |
09d92015 MM |
4260 | return; |
4261 | } | |
4262 | ||
c19d1205 ZW |
4263 | if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX)) |
4264 | && (((inst.instruction & 0x000f0000) >> 16) | |
4265 | == ((inst.instruction & 0x0000f000) >> 12))) | |
4266 | as_warn ((inst.instruction & LOAD_BIT) | |
4267 | ? _("destination register same as write-back base") | |
4268 | : _("source register same as write-back base")); | |
09d92015 MM |
4269 | } |
4270 | ||
c19d1205 ZW |
4271 | /* inst.operands[i] was set up by parse_address. Encode it into an |
4272 | ARM-format mode 2 load or store instruction. If is_t is true, | |
4273 | reject forms that cannot be used with a T instruction (i.e. not | |
4274 | post-indexed). */ | |
a737bd4d | 4275 | static void |
c19d1205 | 4276 | encode_arm_addr_mode_2 (int i, bfd_boolean is_t) |
09d92015 | 4277 | { |
c19d1205 | 4278 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 4279 | |
c19d1205 | 4280 | if (inst.operands[i].immisreg) |
09d92015 | 4281 | { |
c19d1205 ZW |
4282 | inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */ |
4283 | inst.instruction |= inst.operands[i].imm; | |
4284 | if (!inst.operands[i].negative) | |
4285 | inst.instruction |= INDEX_UP; | |
4286 | if (inst.operands[i].shifted) | |
4287 | { | |
4288 | if (inst.operands[i].shift_kind == SHIFT_RRX) | |
4289 | inst.instruction |= SHIFT_ROR << 5; | |
4290 | else | |
4291 | { | |
4292 | inst.instruction |= inst.operands[i].shift_kind << 5; | |
4293 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; | |
4294 | } | |
4295 | } | |
09d92015 | 4296 | } |
c19d1205 | 4297 | else /* immediate offset in inst.reloc */ |
09d92015 | 4298 | { |
c19d1205 ZW |
4299 | if (inst.reloc.type == BFD_RELOC_UNUSED) |
4300 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM; | |
09d92015 | 4301 | } |
09d92015 MM |
4302 | } |
4303 | ||
c19d1205 ZW |
4304 | /* inst.operands[i] was set up by parse_address. Encode it into an |
4305 | ARM-format mode 3 load or store instruction. Reject forms that | |
4306 | cannot be used with such instructions. If is_t is true, reject | |
4307 | forms that cannot be used with a T instruction (i.e. not | |
4308 | post-indexed). */ | |
4309 | static void | |
4310 | encode_arm_addr_mode_3 (int i, bfd_boolean is_t) | |
09d92015 | 4311 | { |
c19d1205 | 4312 | if (inst.operands[i].immisreg && inst.operands[i].shifted) |
09d92015 | 4313 | { |
c19d1205 ZW |
4314 | inst.error = _("instruction does not accept scaled register index"); |
4315 | return; | |
09d92015 | 4316 | } |
a737bd4d | 4317 | |
c19d1205 | 4318 | encode_arm_addr_mode_common (i, is_t); |
a737bd4d | 4319 | |
c19d1205 ZW |
4320 | if (inst.operands[i].immisreg) |
4321 | { | |
4322 | inst.instruction |= inst.operands[i].imm; | |
4323 | if (!inst.operands[i].negative) | |
4324 | inst.instruction |= INDEX_UP; | |
4325 | } | |
4326 | else /* immediate offset in inst.reloc */ | |
4327 | { | |
4328 | inst.instruction |= HWOFFSET_IMM; | |
4329 | if (inst.reloc.type == BFD_RELOC_UNUSED) | |
4330 | inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8; | |
c19d1205 | 4331 | } |
a737bd4d NC |
4332 | } |
4333 | ||
c19d1205 ZW |
4334 | /* inst.operands[i] was set up by parse_address. Encode it into an |
4335 | ARM-format instruction. Reject all forms which cannot be encoded | |
4336 | into a coprocessor load/store instruction. If wb_ok is false, | |
4337 | reject use of writeback; if unind_ok is false, reject use of | |
4338 | unindexed addressing. If reloc_override is not 0, use it instead | |
4339 | of BFD_ARM_CP_OFF_IMM. */ | |
09d92015 | 4340 | |
c19d1205 ZW |
4341 | static int |
4342 | encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override) | |
09d92015 | 4343 | { |
c19d1205 | 4344 | inst.instruction |= inst.operands[i].reg << 16; |
a737bd4d | 4345 | |
c19d1205 | 4346 | assert (!(inst.operands[i].preind && inst.operands[i].postind)); |
09d92015 | 4347 | |
c19d1205 | 4348 | if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */ |
09d92015 | 4349 | { |
c19d1205 ZW |
4350 | assert (!inst.operands[i].writeback); |
4351 | if (!unind_ok) | |
4352 | { | |
4353 | inst.error = _("instruction does not support unindexed addressing"); | |
4354 | return FAIL; | |
4355 | } | |
4356 | inst.instruction |= inst.operands[i].imm; | |
4357 | inst.instruction |= INDEX_UP; | |
4358 | return SUCCESS; | |
09d92015 | 4359 | } |
a737bd4d | 4360 | |
c19d1205 ZW |
4361 | if (inst.operands[i].preind) |
4362 | inst.instruction |= PRE_INDEX; | |
a737bd4d | 4363 | |
c19d1205 | 4364 | if (inst.operands[i].writeback) |
09d92015 | 4365 | { |
c19d1205 ZW |
4366 | if (inst.operands[i].reg == REG_PC) |
4367 | { | |
4368 | inst.error = _("pc may not be used with write-back"); | |
4369 | return FAIL; | |
4370 | } | |
4371 | if (!wb_ok) | |
4372 | { | |
4373 | inst.error = _("instruction does not support writeback"); | |
4374 | return FAIL; | |
4375 | } | |
4376 | inst.instruction |= WRITE_BACK; | |
09d92015 | 4377 | } |
a737bd4d | 4378 | |
c19d1205 ZW |
4379 | if (reloc_override) |
4380 | inst.reloc.type = reloc_override; | |
8f06b2d8 PB |
4381 | else if (thumb_mode) |
4382 | inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM; | |
09d92015 | 4383 | else |
c19d1205 | 4384 | inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM; |
c19d1205 ZW |
4385 | return SUCCESS; |
4386 | } | |
a737bd4d | 4387 | |
c19d1205 ZW |
4388 | /* inst.reloc.exp describes an "=expr" load pseudo-operation. |
4389 | Determine whether it can be performed with a move instruction; if | |
4390 | it can, convert inst.instruction to that move instruction and | |
4391 | return 1; if it can't, convert inst.instruction to a literal-pool | |
4392 | load and return 0. If this is not a valid thing to do in the | |
4393 | current context, set inst.error and return 1. | |
a737bd4d | 4394 | |
c19d1205 ZW |
4395 | inst.operands[i] describes the destination register. */ |
4396 | ||
4397 | static int | |
4398 | move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3) | |
4399 | { | |
4400 | if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0) | |
09d92015 | 4401 | { |
c19d1205 ZW |
4402 | inst.error = _("invalid pseudo operation"); |
4403 | return 1; | |
09d92015 | 4404 | } |
c19d1205 | 4405 | if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol) |
09d92015 MM |
4406 | { |
4407 | inst.error = _("constant expression expected"); | |
c19d1205 | 4408 | return 1; |
09d92015 | 4409 | } |
c19d1205 | 4410 | if (inst.reloc.exp.X_op == O_constant) |
09d92015 | 4411 | { |
c19d1205 ZW |
4412 | if (thumb_p) |
4413 | { | |
4414 | if ((inst.reloc.exp.X_add_number & ~0xFF) == 0) | |
4415 | { | |
4416 | /* This can be done with a mov(1) instruction. */ | |
4417 | inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8); | |
4418 | inst.instruction |= inst.reloc.exp.X_add_number; | |
4419 | return 1; | |
4420 | } | |
4421 | } | |
4422 | else | |
4423 | { | |
4424 | int value = encode_arm_immediate (inst.reloc.exp.X_add_number); | |
4425 | if (value != FAIL) | |
4426 | { | |
4427 | /* This can be done with a mov instruction. */ | |
4428 | inst.instruction &= LITERAL_MASK; | |
4429 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT); | |
4430 | inst.instruction |= value & 0xfff; | |
4431 | return 1; | |
4432 | } | |
09d92015 | 4433 | |
c19d1205 ZW |
4434 | value = encode_arm_immediate (~inst.reloc.exp.X_add_number); |
4435 | if (value != FAIL) | |
4436 | { | |
4437 | /* This can be done with a mvn instruction. */ | |
4438 | inst.instruction &= LITERAL_MASK; | |
4439 | inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT); | |
4440 | inst.instruction |= value & 0xfff; | |
4441 | return 1; | |
4442 | } | |
4443 | } | |
09d92015 MM |
4444 | } |
4445 | ||
c19d1205 ZW |
4446 | if (add_to_lit_pool () == FAIL) |
4447 | { | |
4448 | inst.error = _("literal pool insertion failed"); | |
4449 | return 1; | |
4450 | } | |
4451 | inst.operands[1].reg = REG_PC; | |
4452 | inst.operands[1].isreg = 1; | |
4453 | inst.operands[1].preind = 1; | |
4454 | inst.reloc.pc_rel = 1; | |
4455 | inst.reloc.type = (thumb_p | |
4456 | ? BFD_RELOC_ARM_THUMB_OFFSET | |
4457 | : (mode_3 | |
4458 | ? BFD_RELOC_ARM_HWLITERAL | |
4459 | : BFD_RELOC_ARM_LITERAL)); | |
4460 | return 0; | |
09d92015 MM |
4461 | } |
4462 | ||
c19d1205 ZW |
4463 | /* Functions for instruction encoding, sorted by subarchitecture. |
4464 | First some generics; their names are taken from the conventional | |
4465 | bit positions for register arguments in ARM format instructions. */ | |
09d92015 | 4466 | |
a737bd4d | 4467 | static void |
c19d1205 | 4468 | do_noargs (void) |
09d92015 | 4469 | { |
c19d1205 | 4470 | } |
a737bd4d | 4471 | |
c19d1205 ZW |
4472 | static void |
4473 | do_rd (void) | |
4474 | { | |
4475 | inst.instruction |= inst.operands[0].reg << 12; | |
4476 | } | |
a737bd4d | 4477 | |
c19d1205 ZW |
4478 | static void |
4479 | do_rd_rm (void) | |
4480 | { | |
4481 | inst.instruction |= inst.operands[0].reg << 12; | |
4482 | inst.instruction |= inst.operands[1].reg; | |
4483 | } | |
09d92015 | 4484 | |
c19d1205 ZW |
4485 | static void |
4486 | do_rd_rn (void) | |
4487 | { | |
4488 | inst.instruction |= inst.operands[0].reg << 12; | |
4489 | inst.instruction |= inst.operands[1].reg << 16; | |
4490 | } | |
a737bd4d | 4491 | |
c19d1205 ZW |
4492 | static void |
4493 | do_rn_rd (void) | |
4494 | { | |
4495 | inst.instruction |= inst.operands[0].reg << 16; | |
4496 | inst.instruction |= inst.operands[1].reg << 12; | |
4497 | } | |
09d92015 | 4498 | |
c19d1205 ZW |
4499 | static void |
4500 | do_rd_rm_rn (void) | |
4501 | { | |
9a64e435 PB |
4502 | unsigned Rn = inst.operands[2].reg; |
4503 | /* Enforce resutrictions on SWP instruction. */ | |
4504 | if ((inst.instruction & 0x0fbfffff) == 0x01000090) | |
4505 | constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg, | |
4506 | _("Rn must not overlap other operands")); | |
c19d1205 ZW |
4507 | inst.instruction |= inst.operands[0].reg << 12; |
4508 | inst.instruction |= inst.operands[1].reg; | |
9a64e435 | 4509 | inst.instruction |= Rn << 16; |
c19d1205 | 4510 | } |
09d92015 | 4511 | |
c19d1205 ZW |
4512 | static void |
4513 | do_rd_rn_rm (void) | |
4514 | { | |
4515 | inst.instruction |= inst.operands[0].reg << 12; | |
4516 | inst.instruction |= inst.operands[1].reg << 16; | |
4517 | inst.instruction |= inst.operands[2].reg; | |
4518 | } | |
a737bd4d | 4519 | |
c19d1205 ZW |
4520 | static void |
4521 | do_rm_rd_rn (void) | |
4522 | { | |
4523 | inst.instruction |= inst.operands[0].reg; | |
4524 | inst.instruction |= inst.operands[1].reg << 12; | |
4525 | inst.instruction |= inst.operands[2].reg << 16; | |
4526 | } | |
09d92015 | 4527 | |
c19d1205 ZW |
4528 | static void |
4529 | do_imm0 (void) | |
4530 | { | |
4531 | inst.instruction |= inst.operands[0].imm; | |
4532 | } | |
09d92015 | 4533 | |
c19d1205 ZW |
4534 | static void |
4535 | do_rd_cpaddr (void) | |
4536 | { | |
4537 | inst.instruction |= inst.operands[0].reg << 12; | |
4538 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
09d92015 | 4539 | } |
a737bd4d | 4540 | |
c19d1205 ZW |
4541 | /* ARM instructions, in alphabetical order by function name (except |
4542 | that wrapper functions appear immediately after the function they | |
4543 | wrap). */ | |
09d92015 | 4544 | |
c19d1205 ZW |
4545 | /* This is a pseudo-op of the form "adr rd, label" to be converted |
4546 | into a relative address of the form "add rd, pc, #label-.-8". */ | |
09d92015 MM |
4547 | |
4548 | static void | |
c19d1205 | 4549 | do_adr (void) |
09d92015 | 4550 | { |
c19d1205 | 4551 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ |
a737bd4d | 4552 | |
c19d1205 ZW |
4553 | /* Frag hacking will turn this into a sub instruction if the offset turns |
4554 | out to be negative. */ | |
4555 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
c19d1205 | 4556 | inst.reloc.pc_rel = 1; |
2fc8bdac | 4557 | inst.reloc.exp.X_add_number -= 8; |
c19d1205 | 4558 | } |
b99bd4ef | 4559 | |
c19d1205 ZW |
4560 | /* This is a pseudo-op of the form "adrl rd, label" to be converted |
4561 | into a relative address of the form: | |
4562 | add rd, pc, #low(label-.-8)" | |
4563 | add rd, rd, #high(label-.-8)" */ | |
b99bd4ef | 4564 | |
c19d1205 ZW |
4565 | static void |
4566 | do_adrl (void) | |
4567 | { | |
4568 | inst.instruction |= (inst.operands[0].reg << 12); /* Rd */ | |
a737bd4d | 4569 | |
c19d1205 ZW |
4570 | /* Frag hacking will turn this into a sub instruction if the offset turns |
4571 | out to be negative. */ | |
4572 | inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE; | |
c19d1205 ZW |
4573 | inst.reloc.pc_rel = 1; |
4574 | inst.size = INSN_SIZE * 2; | |
2fc8bdac | 4575 | inst.reloc.exp.X_add_number -= 8; |
b99bd4ef NC |
4576 | } |
4577 | ||
b99bd4ef | 4578 | static void |
c19d1205 | 4579 | do_arit (void) |
b99bd4ef | 4580 | { |
c19d1205 ZW |
4581 | if (!inst.operands[1].present) |
4582 | inst.operands[1].reg = inst.operands[0].reg; | |
4583 | inst.instruction |= inst.operands[0].reg << 12; | |
4584 | inst.instruction |= inst.operands[1].reg << 16; | |
4585 | encode_arm_shifter_operand (2); | |
4586 | } | |
b99bd4ef | 4587 | |
c19d1205 ZW |
4588 | static void |
4589 | do_bfc (void) | |
4590 | { | |
4591 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; | |
4592 | constraint (msb > 32, _("bit-field extends past end of register")); | |
4593 | /* The instruction encoding stores the LSB and MSB, | |
4594 | not the LSB and width. */ | |
4595 | inst.instruction |= inst.operands[0].reg << 12; | |
4596 | inst.instruction |= inst.operands[1].imm << 7; | |
4597 | inst.instruction |= (msb - 1) << 16; | |
4598 | } | |
b99bd4ef | 4599 | |
c19d1205 ZW |
4600 | static void |
4601 | do_bfi (void) | |
4602 | { | |
4603 | unsigned int msb; | |
b99bd4ef | 4604 | |
c19d1205 ZW |
4605 | /* #0 in second position is alternative syntax for bfc, which is |
4606 | the same instruction but with REG_PC in the Rm field. */ | |
4607 | if (!inst.operands[1].isreg) | |
4608 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 4609 | |
c19d1205 ZW |
4610 | msb = inst.operands[2].imm + inst.operands[3].imm; |
4611 | constraint (msb > 32, _("bit-field extends past end of register")); | |
4612 | /* The instruction encoding stores the LSB and MSB, | |
4613 | not the LSB and width. */ | |
4614 | inst.instruction |= inst.operands[0].reg << 12; | |
4615 | inst.instruction |= inst.operands[1].reg; | |
4616 | inst.instruction |= inst.operands[2].imm << 7; | |
4617 | inst.instruction |= (msb - 1) << 16; | |
b99bd4ef NC |
4618 | } |
4619 | ||
b99bd4ef | 4620 | static void |
c19d1205 | 4621 | do_bfx (void) |
b99bd4ef | 4622 | { |
c19d1205 ZW |
4623 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
4624 | _("bit-field extends past end of register")); | |
4625 | inst.instruction |= inst.operands[0].reg << 12; | |
4626 | inst.instruction |= inst.operands[1].reg; | |
4627 | inst.instruction |= inst.operands[2].imm << 7; | |
4628 | inst.instruction |= (inst.operands[3].imm - 1) << 16; | |
4629 | } | |
09d92015 | 4630 | |
c19d1205 ZW |
4631 | /* ARM V5 breakpoint instruction (argument parse) |
4632 | BKPT <16 bit unsigned immediate> | |
4633 | Instruction is not conditional. | |
4634 | The bit pattern given in insns[] has the COND_ALWAYS condition, | |
4635 | and it is an error if the caller tried to override that. */ | |
b99bd4ef | 4636 | |
c19d1205 ZW |
4637 | static void |
4638 | do_bkpt (void) | |
4639 | { | |
4640 | /* Top 12 of 16 bits to bits 19:8. */ | |
4641 | inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4; | |
09d92015 | 4642 | |
c19d1205 ZW |
4643 | /* Bottom 4 of 16 bits to bits 3:0. */ |
4644 | inst.instruction |= inst.operands[0].imm & 0xf; | |
4645 | } | |
09d92015 | 4646 | |
c19d1205 ZW |
4647 | static void |
4648 | encode_branch (int default_reloc) | |
4649 | { | |
4650 | if (inst.operands[0].hasreloc) | |
4651 | { | |
4652 | constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32, | |
4653 | _("the only suffix valid here is '(plt)'")); | |
4654 | inst.reloc.type = BFD_RELOC_ARM_PLT32; | |
c19d1205 | 4655 | } |
b99bd4ef | 4656 | else |
c19d1205 ZW |
4657 | { |
4658 | inst.reloc.type = default_reloc; | |
c19d1205 | 4659 | } |
2fc8bdac | 4660 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
4661 | } |
4662 | ||
b99bd4ef | 4663 | static void |
c19d1205 | 4664 | do_branch (void) |
b99bd4ef | 4665 | { |
39b41c9c PB |
4666 | #ifdef OBJ_ELF |
4667 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
4668 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
4669 | else | |
4670 | #endif | |
4671 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
4672 | } | |
4673 | ||
4674 | static void | |
4675 | do_bl (void) | |
4676 | { | |
4677 | #ifdef OBJ_ELF | |
4678 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
4679 | { | |
4680 | if (inst.cond == COND_ALWAYS) | |
4681 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
4682 | else | |
4683 | encode_branch (BFD_RELOC_ARM_PCREL_JUMP); | |
4684 | } | |
4685 | else | |
4686 | #endif | |
4687 | encode_branch (BFD_RELOC_ARM_PCREL_BRANCH); | |
c19d1205 | 4688 | } |
b99bd4ef | 4689 | |
c19d1205 ZW |
4690 | /* ARM V5 branch-link-exchange instruction (argument parse) |
4691 | BLX <target_addr> ie BLX(1) | |
4692 | BLX{<condition>} <Rm> ie BLX(2) | |
4693 | Unfortunately, there are two different opcodes for this mnemonic. | |
4694 | So, the insns[].value is not used, and the code here zaps values | |
4695 | into inst.instruction. | |
4696 | Also, the <target_addr> can be 25 bits, hence has its own reloc. */ | |
b99bd4ef | 4697 | |
c19d1205 ZW |
4698 | static void |
4699 | do_blx (void) | |
4700 | { | |
4701 | if (inst.operands[0].isreg) | |
b99bd4ef | 4702 | { |
c19d1205 ZW |
4703 | /* Arg is a register; the opcode provided by insns[] is correct. |
4704 | It is not illegal to do "blx pc", just useless. */ | |
4705 | if (inst.operands[0].reg == REG_PC) | |
4706 | as_tsktsk (_("use of r15 in blx in ARM mode is not really useful")); | |
b99bd4ef | 4707 | |
c19d1205 ZW |
4708 | inst.instruction |= inst.operands[0].reg; |
4709 | } | |
4710 | else | |
b99bd4ef | 4711 | { |
c19d1205 ZW |
4712 | /* Arg is an address; this instruction cannot be executed |
4713 | conditionally, and the opcode must be adjusted. */ | |
4714 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
2fc8bdac | 4715 | inst.instruction = 0xfa000000; |
39b41c9c PB |
4716 | #ifdef OBJ_ELF |
4717 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
4718 | encode_branch (BFD_RELOC_ARM_PCREL_CALL); | |
4719 | else | |
4720 | #endif | |
4721 | encode_branch (BFD_RELOC_ARM_PCREL_BLX); | |
b99bd4ef | 4722 | } |
c19d1205 ZW |
4723 | } |
4724 | ||
4725 | static void | |
4726 | do_bx (void) | |
4727 | { | |
4728 | if (inst.operands[0].reg == REG_PC) | |
4729 | as_tsktsk (_("use of r15 in bx in ARM mode is not really useful")); | |
b99bd4ef | 4730 | |
c19d1205 | 4731 | inst.instruction |= inst.operands[0].reg; |
09d92015 MM |
4732 | } |
4733 | ||
c19d1205 ZW |
4734 | |
4735 | /* ARM v5TEJ. Jump to Jazelle code. */ | |
a737bd4d NC |
4736 | |
4737 | static void | |
c19d1205 | 4738 | do_bxj (void) |
a737bd4d | 4739 | { |
c19d1205 ZW |
4740 | if (inst.operands[0].reg == REG_PC) |
4741 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
4742 | ||
4743 | inst.instruction |= inst.operands[0].reg; | |
a737bd4d NC |
4744 | } |
4745 | ||
c19d1205 ZW |
4746 | /* Co-processor data operation: |
4747 | CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} | |
4748 | CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */ | |
4749 | static void | |
4750 | do_cdp (void) | |
4751 | { | |
4752 | inst.instruction |= inst.operands[0].reg << 8; | |
4753 | inst.instruction |= inst.operands[1].imm << 20; | |
4754 | inst.instruction |= inst.operands[2].reg << 12; | |
4755 | inst.instruction |= inst.operands[3].reg << 16; | |
4756 | inst.instruction |= inst.operands[4].reg; | |
4757 | inst.instruction |= inst.operands[5].imm << 5; | |
4758 | } | |
a737bd4d NC |
4759 | |
4760 | static void | |
c19d1205 | 4761 | do_cmp (void) |
a737bd4d | 4762 | { |
c19d1205 ZW |
4763 | inst.instruction |= inst.operands[0].reg << 16; |
4764 | encode_arm_shifter_operand (1); | |
a737bd4d NC |
4765 | } |
4766 | ||
c19d1205 ZW |
4767 | /* Transfer between coprocessor and ARM registers. |
4768 | MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>} | |
4769 | MRC2 | |
4770 | MCR{cond} | |
4771 | MCR2 | |
4772 | ||
4773 | No special properties. */ | |
09d92015 MM |
4774 | |
4775 | static void | |
c19d1205 | 4776 | do_co_reg (void) |
09d92015 | 4777 | { |
c19d1205 ZW |
4778 | inst.instruction |= inst.operands[0].reg << 8; |
4779 | inst.instruction |= inst.operands[1].imm << 21; | |
4780 | inst.instruction |= inst.operands[2].reg << 12; | |
4781 | inst.instruction |= inst.operands[3].reg << 16; | |
4782 | inst.instruction |= inst.operands[4].reg; | |
4783 | inst.instruction |= inst.operands[5].imm << 5; | |
4784 | } | |
09d92015 | 4785 | |
c19d1205 ZW |
4786 | /* Transfer between coprocessor register and pair of ARM registers. |
4787 | MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>. | |
4788 | MCRR2 | |
4789 | MRRC{cond} | |
4790 | MRRC2 | |
b99bd4ef | 4791 | |
c19d1205 | 4792 | Two XScale instructions are special cases of these: |
09d92015 | 4793 | |
c19d1205 ZW |
4794 | MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0 |
4795 | MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0 | |
b99bd4ef | 4796 | |
c19d1205 | 4797 | Result unpredicatable if Rd or Rn is R15. */ |
a737bd4d | 4798 | |
c19d1205 ZW |
4799 | static void |
4800 | do_co_reg2c (void) | |
4801 | { | |
4802 | inst.instruction |= inst.operands[0].reg << 8; | |
4803 | inst.instruction |= inst.operands[1].imm << 4; | |
4804 | inst.instruction |= inst.operands[2].reg << 12; | |
4805 | inst.instruction |= inst.operands[3].reg << 16; | |
4806 | inst.instruction |= inst.operands[4].reg; | |
b99bd4ef NC |
4807 | } |
4808 | ||
c19d1205 ZW |
4809 | static void |
4810 | do_cpsi (void) | |
4811 | { | |
4812 | inst.instruction |= inst.operands[0].imm << 6; | |
4813 | inst.instruction |= inst.operands[1].imm; | |
4814 | } | |
b99bd4ef NC |
4815 | |
4816 | static void | |
c19d1205 | 4817 | do_it (void) |
b99bd4ef | 4818 | { |
c19d1205 ZW |
4819 | /* There is no IT instruction in ARM mode. We |
4820 | process it but do not generate code for it. */ | |
4821 | inst.size = 0; | |
09d92015 | 4822 | } |
b99bd4ef | 4823 | |
09d92015 | 4824 | static void |
c19d1205 | 4825 | do_ldmstm (void) |
ea6ef066 | 4826 | { |
c19d1205 ZW |
4827 | int base_reg = inst.operands[0].reg; |
4828 | int range = inst.operands[1].imm; | |
ea6ef066 | 4829 | |
c19d1205 ZW |
4830 | inst.instruction |= base_reg << 16; |
4831 | inst.instruction |= range; | |
ea6ef066 | 4832 | |
c19d1205 ZW |
4833 | if (inst.operands[1].writeback) |
4834 | inst.instruction |= LDM_TYPE_2_OR_3; | |
09d92015 | 4835 | |
c19d1205 | 4836 | if (inst.operands[0].writeback) |
ea6ef066 | 4837 | { |
c19d1205 ZW |
4838 | inst.instruction |= WRITE_BACK; |
4839 | /* Check for unpredictable uses of writeback. */ | |
4840 | if (inst.instruction & LOAD_BIT) | |
09d92015 | 4841 | { |
c19d1205 ZW |
4842 | /* Not allowed in LDM type 2. */ |
4843 | if ((inst.instruction & LDM_TYPE_2_OR_3) | |
4844 | && ((range & (1 << REG_PC)) == 0)) | |
4845 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
4846 | /* Only allowed if base reg not in list for other types. */ | |
4847 | else if (range & (1 << base_reg)) | |
4848 | as_warn (_("writeback of base register when in register list is UNPREDICTABLE")); | |
4849 | } | |
4850 | else /* STM. */ | |
4851 | { | |
4852 | /* Not allowed for type 2. */ | |
4853 | if (inst.instruction & LDM_TYPE_2_OR_3) | |
4854 | as_warn (_("writeback of base register is UNPREDICTABLE")); | |
4855 | /* Only allowed if base reg not in list, or first in list. */ | |
4856 | else if ((range & (1 << base_reg)) | |
4857 | && (range & ((1 << base_reg) - 1))) | |
4858 | as_warn (_("if writeback register is in list, it must be the lowest reg in the list")); | |
09d92015 | 4859 | } |
ea6ef066 | 4860 | } |
a737bd4d NC |
4861 | } |
4862 | ||
c19d1205 ZW |
4863 | /* ARMv5TE load-consecutive (argument parse) |
4864 | Mode is like LDRH. | |
4865 | ||
4866 | LDRccD R, mode | |
4867 | STRccD R, mode. */ | |
4868 | ||
a737bd4d | 4869 | static void |
c19d1205 | 4870 | do_ldrd (void) |
a737bd4d | 4871 | { |
c19d1205 ZW |
4872 | constraint (inst.operands[0].reg % 2 != 0, |
4873 | _("first destination register must be even")); | |
4874 | constraint (inst.operands[1].present | |
4875 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
4876 | _("can only load two consecutive registers")); | |
4877 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
4878 | constraint (!inst.operands[2].isreg, _("'[' expected")); | |
a737bd4d | 4879 | |
c19d1205 ZW |
4880 | if (!inst.operands[1].present) |
4881 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
4882 | ||
4883 | if (inst.instruction & LOAD_BIT) | |
a737bd4d | 4884 | { |
c19d1205 ZW |
4885 | /* encode_arm_addr_mode_3 will diagnose overlap between the base |
4886 | register and the first register written; we have to diagnose | |
4887 | overlap between the base and the second register written here. */ | |
ea6ef066 | 4888 | |
c19d1205 ZW |
4889 | if (inst.operands[2].reg == inst.operands[1].reg |
4890 | && (inst.operands[2].writeback || inst.operands[2].postind)) | |
4891 | as_warn (_("base register written back, and overlaps " | |
4892 | "second destination register")); | |
b05fe5cf | 4893 | |
c19d1205 ZW |
4894 | /* For an index-register load, the index register must not overlap the |
4895 | destination (even if not write-back). */ | |
4896 | else if (inst.operands[2].immisreg | |
ca3f61f7 NC |
4897 | && ((unsigned) inst.operands[2].imm == inst.operands[0].reg |
4898 | || (unsigned) inst.operands[2].imm == inst.operands[1].reg)) | |
c19d1205 | 4899 | as_warn (_("index register overlaps destination register")); |
b05fe5cf | 4900 | } |
c19d1205 ZW |
4901 | |
4902 | inst.instruction |= inst.operands[0].reg << 12; | |
4903 | encode_arm_addr_mode_3 (2, /*is_t=*/FALSE); | |
b05fe5cf ZW |
4904 | } |
4905 | ||
4906 | static void | |
c19d1205 | 4907 | do_ldrex (void) |
b05fe5cf | 4908 | { |
c19d1205 ZW |
4909 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind |
4910 | || inst.operands[1].postind || inst.operands[1].writeback | |
4911 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
01cfc07f NC |
4912 | || inst.operands[1].negative |
4913 | /* This can arise if the programmer has written | |
4914 | strex rN, rM, foo | |
4915 | or if they have mistakenly used a register name as the last | |
4916 | operand, eg: | |
4917 | strex rN, rM, rX | |
4918 | It is very difficult to distinguish between these two cases | |
4919 | because "rX" might actually be a label. ie the register | |
4920 | name has been occluded by a symbol of the same name. So we | |
4921 | just generate a general 'bad addressing mode' type error | |
4922 | message and leave it up to the programmer to discover the | |
4923 | true cause and fix their mistake. */ | |
4924 | || (inst.operands[1].reg == REG_PC), | |
4925 | BAD_ADDR_MODE); | |
b05fe5cf | 4926 | |
c19d1205 ZW |
4927 | constraint (inst.reloc.exp.X_op != O_constant |
4928 | || inst.reloc.exp.X_add_number != 0, | |
4929 | _("offset must be zero in ARM encoding")); | |
b05fe5cf | 4930 | |
c19d1205 ZW |
4931 | inst.instruction |= inst.operands[0].reg << 12; |
4932 | inst.instruction |= inst.operands[1].reg << 16; | |
4933 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b05fe5cf ZW |
4934 | } |
4935 | ||
4936 | static void | |
c19d1205 | 4937 | do_ldrexd (void) |
b05fe5cf | 4938 | { |
c19d1205 ZW |
4939 | constraint (inst.operands[0].reg % 2 != 0, |
4940 | _("even register required")); | |
4941 | constraint (inst.operands[1].present | |
4942 | && inst.operands[1].reg != inst.operands[0].reg + 1, | |
4943 | _("can only load two consecutive registers")); | |
4944 | /* If op 1 were present and equal to PC, this function wouldn't | |
4945 | have been called in the first place. */ | |
4946 | constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here")); | |
b05fe5cf | 4947 | |
c19d1205 ZW |
4948 | inst.instruction |= inst.operands[0].reg << 12; |
4949 | inst.instruction |= inst.operands[2].reg << 16; | |
b05fe5cf ZW |
4950 | } |
4951 | ||
4952 | static void | |
c19d1205 | 4953 | do_ldst (void) |
b05fe5cf | 4954 | { |
c19d1205 ZW |
4955 | inst.instruction |= inst.operands[0].reg << 12; |
4956 | if (!inst.operands[1].isreg) | |
4957 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE)) | |
b05fe5cf | 4958 | return; |
c19d1205 | 4959 | encode_arm_addr_mode_2 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
4960 | } |
4961 | ||
4962 | static void | |
c19d1205 | 4963 | do_ldstt (void) |
b05fe5cf | 4964 | { |
c19d1205 ZW |
4965 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
4966 | reject [Rn,...]. */ | |
4967 | if (inst.operands[1].preind) | |
b05fe5cf | 4968 | { |
c19d1205 ZW |
4969 | constraint (inst.reloc.exp.X_op != O_constant || |
4970 | inst.reloc.exp.X_add_number != 0, | |
4971 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 4972 | |
c19d1205 ZW |
4973 | inst.operands[1].preind = 0; |
4974 | inst.operands[1].postind = 1; | |
4975 | inst.operands[1].writeback = 1; | |
b05fe5cf | 4976 | } |
c19d1205 ZW |
4977 | inst.instruction |= inst.operands[0].reg << 12; |
4978 | encode_arm_addr_mode_2 (1, /*is_t=*/TRUE); | |
4979 | } | |
b05fe5cf | 4980 | |
c19d1205 | 4981 | /* Halfword and signed-byte load/store operations. */ |
b05fe5cf | 4982 | |
c19d1205 ZW |
4983 | static void |
4984 | do_ldstv4 (void) | |
4985 | { | |
4986 | inst.instruction |= inst.operands[0].reg << 12; | |
4987 | if (!inst.operands[1].isreg) | |
4988 | if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE)) | |
b05fe5cf | 4989 | return; |
c19d1205 | 4990 | encode_arm_addr_mode_3 (1, /*is_t=*/FALSE); |
b05fe5cf ZW |
4991 | } |
4992 | ||
4993 | static void | |
c19d1205 | 4994 | do_ldsttv4 (void) |
b05fe5cf | 4995 | { |
c19d1205 ZW |
4996 | /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and |
4997 | reject [Rn,...]. */ | |
4998 | if (inst.operands[1].preind) | |
b05fe5cf | 4999 | { |
c19d1205 ZW |
5000 | constraint (inst.reloc.exp.X_op != O_constant || |
5001 | inst.reloc.exp.X_add_number != 0, | |
5002 | _("this instruction requires a post-indexed address")); | |
b05fe5cf | 5003 | |
c19d1205 ZW |
5004 | inst.operands[1].preind = 0; |
5005 | inst.operands[1].postind = 1; | |
5006 | inst.operands[1].writeback = 1; | |
b05fe5cf | 5007 | } |
c19d1205 ZW |
5008 | inst.instruction |= inst.operands[0].reg << 12; |
5009 | encode_arm_addr_mode_3 (1, /*is_t=*/TRUE); | |
5010 | } | |
b05fe5cf | 5011 | |
c19d1205 ZW |
5012 | /* Co-processor register load/store. |
5013 | Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */ | |
5014 | static void | |
5015 | do_lstc (void) | |
5016 | { | |
5017 | inst.instruction |= inst.operands[0].reg << 8; | |
5018 | inst.instruction |= inst.operands[1].reg << 12; | |
5019 | encode_arm_cp_address (2, TRUE, TRUE, 0); | |
b05fe5cf ZW |
5020 | } |
5021 | ||
b05fe5cf | 5022 | static void |
c19d1205 | 5023 | do_mlas (void) |
b05fe5cf | 5024 | { |
c19d1205 ZW |
5025 | /* This restriction does not apply to mls (nor to mla in v6, but |
5026 | that's hard to detect at present). */ | |
5027 | if (inst.operands[0].reg == inst.operands[1].reg | |
5028 | && !(inst.instruction & 0x00400000)) | |
5029 | as_tsktsk (_("rd and rm should be different in mla")); | |
b05fe5cf | 5030 | |
c19d1205 ZW |
5031 | inst.instruction |= inst.operands[0].reg << 16; |
5032 | inst.instruction |= inst.operands[1].reg; | |
5033 | inst.instruction |= inst.operands[2].reg << 8; | |
5034 | inst.instruction |= inst.operands[3].reg << 12; | |
b05fe5cf | 5035 | |
c19d1205 | 5036 | } |
b05fe5cf | 5037 | |
c19d1205 ZW |
5038 | static void |
5039 | do_mov (void) | |
5040 | { | |
5041 | inst.instruction |= inst.operands[0].reg << 12; | |
5042 | encode_arm_shifter_operand (1); | |
5043 | } | |
b05fe5cf | 5044 | |
c19d1205 ZW |
5045 | /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */ |
5046 | static void | |
5047 | do_mov16 (void) | |
5048 | { | |
5049 | inst.instruction |= inst.operands[0].reg << 12; | |
b05fe5cf | 5050 | /* The value is in two pieces: 0:11, 16:19. */ |
c19d1205 ZW |
5051 | inst.instruction |= (inst.operands[1].imm & 0x00000fff); |
5052 | inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4; | |
b05fe5cf | 5053 | } |
b99bd4ef NC |
5054 | |
5055 | static void | |
c19d1205 | 5056 | do_mrs (void) |
b99bd4ef | 5057 | { |
c19d1205 ZW |
5058 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
5059 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
5060 | != (PSR_c|PSR_f), | |
5061 | _("'CPSR' or 'SPSR' expected")); | |
5062 | inst.instruction |= inst.operands[0].reg << 12; | |
5063 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT); | |
5064 | } | |
b99bd4ef | 5065 | |
c19d1205 ZW |
5066 | /* Two possible forms: |
5067 | "{C|S}PSR_<field>, Rm", | |
5068 | "{C|S}PSR_f, #expression". */ | |
b99bd4ef | 5069 | |
c19d1205 ZW |
5070 | static void |
5071 | do_msr (void) | |
5072 | { | |
5073 | inst.instruction |= inst.operands[0].imm; | |
5074 | if (inst.operands[1].isreg) | |
5075 | inst.instruction |= inst.operands[1].reg; | |
5076 | else | |
b99bd4ef | 5077 | { |
c19d1205 ZW |
5078 | inst.instruction |= INST_IMMEDIATE; |
5079 | inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE; | |
5080 | inst.reloc.pc_rel = 0; | |
b99bd4ef | 5081 | } |
b99bd4ef NC |
5082 | } |
5083 | ||
c19d1205 ZW |
5084 | static void |
5085 | do_mul (void) | |
a737bd4d | 5086 | { |
c19d1205 ZW |
5087 | if (!inst.operands[2].present) |
5088 | inst.operands[2].reg = inst.operands[0].reg; | |
5089 | inst.instruction |= inst.operands[0].reg << 16; | |
5090 | inst.instruction |= inst.operands[1].reg; | |
5091 | inst.instruction |= inst.operands[2].reg << 8; | |
a737bd4d | 5092 | |
c19d1205 ZW |
5093 | if (inst.operands[0].reg == inst.operands[1].reg) |
5094 | as_tsktsk (_("rd and rm should be different in mul")); | |
a737bd4d NC |
5095 | } |
5096 | ||
c19d1205 ZW |
5097 | /* Long Multiply Parser |
5098 | UMULL RdLo, RdHi, Rm, Rs | |
5099 | SMULL RdLo, RdHi, Rm, Rs | |
5100 | UMLAL RdLo, RdHi, Rm, Rs | |
5101 | SMLAL RdLo, RdHi, Rm, Rs. */ | |
b99bd4ef NC |
5102 | |
5103 | static void | |
c19d1205 | 5104 | do_mull (void) |
b99bd4ef | 5105 | { |
c19d1205 ZW |
5106 | inst.instruction |= inst.operands[0].reg << 12; |
5107 | inst.instruction |= inst.operands[1].reg << 16; | |
5108 | inst.instruction |= inst.operands[2].reg; | |
5109 | inst.instruction |= inst.operands[3].reg << 8; | |
b99bd4ef | 5110 | |
c19d1205 ZW |
5111 | /* rdhi, rdlo and rm must all be different. */ |
5112 | if (inst.operands[0].reg == inst.operands[1].reg | |
5113 | || inst.operands[0].reg == inst.operands[2].reg | |
5114 | || inst.operands[1].reg == inst.operands[2].reg) | |
5115 | as_tsktsk (_("rdhi, rdlo and rm must all be different")); | |
5116 | } | |
b99bd4ef | 5117 | |
c19d1205 ZW |
5118 | static void |
5119 | do_nop (void) | |
5120 | { | |
5121 | if (inst.operands[0].present) | |
5122 | { | |
5123 | /* Architectural NOP hints are CPSR sets with no bits selected. */ | |
5124 | inst.instruction &= 0xf0000000; | |
5125 | inst.instruction |= 0x0320f000 + inst.operands[0].imm; | |
5126 | } | |
b99bd4ef NC |
5127 | } |
5128 | ||
c19d1205 ZW |
5129 | /* ARM V6 Pack Halfword Bottom Top instruction (argument parse). |
5130 | PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>} | |
5131 | Condition defaults to COND_ALWAYS. | |
5132 | Error if Rd, Rn or Rm are R15. */ | |
b99bd4ef NC |
5133 | |
5134 | static void | |
c19d1205 | 5135 | do_pkhbt (void) |
b99bd4ef | 5136 | { |
c19d1205 ZW |
5137 | inst.instruction |= inst.operands[0].reg << 12; |
5138 | inst.instruction |= inst.operands[1].reg << 16; | |
5139 | inst.instruction |= inst.operands[2].reg; | |
5140 | if (inst.operands[3].present) | |
5141 | encode_arm_shift (3); | |
5142 | } | |
b99bd4ef | 5143 | |
c19d1205 | 5144 | /* ARM V6 PKHTB (Argument Parse). */ |
b99bd4ef | 5145 | |
c19d1205 ZW |
5146 | static void |
5147 | do_pkhtb (void) | |
5148 | { | |
5149 | if (!inst.operands[3].present) | |
b99bd4ef | 5150 | { |
c19d1205 ZW |
5151 | /* If the shift specifier is omitted, turn the instruction |
5152 | into pkhbt rd, rm, rn. */ | |
5153 | inst.instruction &= 0xfff00010; | |
5154 | inst.instruction |= inst.operands[0].reg << 12; | |
5155 | inst.instruction |= inst.operands[1].reg; | |
5156 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
5157 | } |
5158 | else | |
5159 | { | |
c19d1205 ZW |
5160 | inst.instruction |= inst.operands[0].reg << 12; |
5161 | inst.instruction |= inst.operands[1].reg << 16; | |
5162 | inst.instruction |= inst.operands[2].reg; | |
5163 | encode_arm_shift (3); | |
b99bd4ef NC |
5164 | } |
5165 | } | |
5166 | ||
c19d1205 ZW |
5167 | /* ARMv5TE: Preload-Cache |
5168 | ||
5169 | PLD <addr_mode> | |
5170 | ||
5171 | Syntactically, like LDR with B=1, W=0, L=1. */ | |
b99bd4ef NC |
5172 | |
5173 | static void | |
c19d1205 | 5174 | do_pld (void) |
b99bd4ef | 5175 | { |
c19d1205 ZW |
5176 | constraint (!inst.operands[0].isreg, |
5177 | _("'[' expected after PLD mnemonic")); | |
5178 | constraint (inst.operands[0].postind, | |
5179 | _("post-indexed expression used in preload instruction")); | |
5180 | constraint (inst.operands[0].writeback, | |
5181 | _("writeback used in preload instruction")); | |
5182 | constraint (!inst.operands[0].preind, | |
5183 | _("unindexed addressing used in preload instruction")); | |
c19d1205 ZW |
5184 | encode_arm_addr_mode_2 (0, /*is_t=*/FALSE); |
5185 | } | |
b99bd4ef | 5186 | |
c19d1205 ZW |
5187 | static void |
5188 | do_push_pop (void) | |
5189 | { | |
5190 | inst.operands[1] = inst.operands[0]; | |
5191 | memset (&inst.operands[0], 0, sizeof inst.operands[0]); | |
5192 | inst.operands[0].isreg = 1; | |
5193 | inst.operands[0].writeback = 1; | |
5194 | inst.operands[0].reg = REG_SP; | |
5195 | do_ldmstm (); | |
5196 | } | |
b99bd4ef | 5197 | |
c19d1205 ZW |
5198 | /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the |
5199 | word at the specified address and the following word | |
5200 | respectively. | |
5201 | Unconditionally executed. | |
5202 | Error if Rn is R15. */ | |
b99bd4ef | 5203 | |
c19d1205 ZW |
5204 | static void |
5205 | do_rfe (void) | |
5206 | { | |
5207 | inst.instruction |= inst.operands[0].reg << 16; | |
5208 | if (inst.operands[0].writeback) | |
5209 | inst.instruction |= WRITE_BACK; | |
5210 | } | |
b99bd4ef | 5211 | |
c19d1205 | 5212 | /* ARM V6 ssat (argument parse). */ |
b99bd4ef | 5213 | |
c19d1205 ZW |
5214 | static void |
5215 | do_ssat (void) | |
5216 | { | |
5217 | inst.instruction |= inst.operands[0].reg << 12; | |
5218 | inst.instruction |= (inst.operands[1].imm - 1) << 16; | |
5219 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 5220 | |
c19d1205 ZW |
5221 | if (inst.operands[3].present) |
5222 | encode_arm_shift (3); | |
b99bd4ef NC |
5223 | } |
5224 | ||
c19d1205 | 5225 | /* ARM V6 usat (argument parse). */ |
b99bd4ef NC |
5226 | |
5227 | static void | |
c19d1205 | 5228 | do_usat (void) |
b99bd4ef | 5229 | { |
c19d1205 ZW |
5230 | inst.instruction |= inst.operands[0].reg << 12; |
5231 | inst.instruction |= inst.operands[1].imm << 16; | |
5232 | inst.instruction |= inst.operands[2].reg; | |
b99bd4ef | 5233 | |
c19d1205 ZW |
5234 | if (inst.operands[3].present) |
5235 | encode_arm_shift (3); | |
b99bd4ef NC |
5236 | } |
5237 | ||
c19d1205 | 5238 | /* ARM V6 ssat16 (argument parse). */ |
09d92015 MM |
5239 | |
5240 | static void | |
c19d1205 | 5241 | do_ssat16 (void) |
09d92015 | 5242 | { |
c19d1205 ZW |
5243 | inst.instruction |= inst.operands[0].reg << 12; |
5244 | inst.instruction |= ((inst.operands[1].imm - 1) << 16); | |
5245 | inst.instruction |= inst.operands[2].reg; | |
09d92015 MM |
5246 | } |
5247 | ||
c19d1205 ZW |
5248 | static void |
5249 | do_usat16 (void) | |
a737bd4d | 5250 | { |
c19d1205 ZW |
5251 | inst.instruction |= inst.operands[0].reg << 12; |
5252 | inst.instruction |= inst.operands[1].imm << 16; | |
5253 | inst.instruction |= inst.operands[2].reg; | |
5254 | } | |
a737bd4d | 5255 | |
c19d1205 ZW |
5256 | /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while |
5257 | preserving the other bits. | |
a737bd4d | 5258 | |
c19d1205 ZW |
5259 | setend <endian_specifier>, where <endian_specifier> is either |
5260 | BE or LE. */ | |
a737bd4d | 5261 | |
c19d1205 ZW |
5262 | static void |
5263 | do_setend (void) | |
5264 | { | |
5265 | if (inst.operands[0].imm) | |
5266 | inst.instruction |= 0x200; | |
a737bd4d NC |
5267 | } |
5268 | ||
5269 | static void | |
c19d1205 | 5270 | do_shift (void) |
a737bd4d | 5271 | { |
c19d1205 ZW |
5272 | unsigned int Rm = (inst.operands[1].present |
5273 | ? inst.operands[1].reg | |
5274 | : inst.operands[0].reg); | |
a737bd4d | 5275 | |
c19d1205 ZW |
5276 | inst.instruction |= inst.operands[0].reg << 12; |
5277 | inst.instruction |= Rm; | |
5278 | if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */ | |
a737bd4d | 5279 | { |
c19d1205 ZW |
5280 | inst.instruction |= inst.operands[2].reg << 8; |
5281 | inst.instruction |= SHIFT_BY_REG; | |
a737bd4d NC |
5282 | } |
5283 | else | |
c19d1205 | 5284 | inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM; |
a737bd4d NC |
5285 | } |
5286 | ||
09d92015 | 5287 | static void |
3eb17e6b | 5288 | do_smc (void) |
09d92015 | 5289 | { |
3eb17e6b | 5290 | inst.reloc.type = BFD_RELOC_ARM_SMC; |
c19d1205 | 5291 | inst.reloc.pc_rel = 0; |
09d92015 MM |
5292 | } |
5293 | ||
09d92015 | 5294 | static void |
c19d1205 | 5295 | do_swi (void) |
09d92015 | 5296 | { |
c19d1205 ZW |
5297 | inst.reloc.type = BFD_RELOC_ARM_SWI; |
5298 | inst.reloc.pc_rel = 0; | |
09d92015 MM |
5299 | } |
5300 | ||
c19d1205 ZW |
5301 | /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse) |
5302 | SMLAxy{cond} Rd,Rm,Rs,Rn | |
5303 | SMLAWy{cond} Rd,Rm,Rs,Rn | |
5304 | Error if any register is R15. */ | |
e16bb312 | 5305 | |
c19d1205 ZW |
5306 | static void |
5307 | do_smla (void) | |
e16bb312 | 5308 | { |
c19d1205 ZW |
5309 | inst.instruction |= inst.operands[0].reg << 16; |
5310 | inst.instruction |= inst.operands[1].reg; | |
5311 | inst.instruction |= inst.operands[2].reg << 8; | |
5312 | inst.instruction |= inst.operands[3].reg << 12; | |
5313 | } | |
a737bd4d | 5314 | |
c19d1205 ZW |
5315 | /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse) |
5316 | SMLALxy{cond} Rdlo,Rdhi,Rm,Rs | |
5317 | Error if any register is R15. | |
5318 | Warning if Rdlo == Rdhi. */ | |
a737bd4d | 5319 | |
c19d1205 ZW |
5320 | static void |
5321 | do_smlal (void) | |
5322 | { | |
5323 | inst.instruction |= inst.operands[0].reg << 12; | |
5324 | inst.instruction |= inst.operands[1].reg << 16; | |
5325 | inst.instruction |= inst.operands[2].reg; | |
5326 | inst.instruction |= inst.operands[3].reg << 8; | |
a737bd4d | 5327 | |
c19d1205 ZW |
5328 | if (inst.operands[0].reg == inst.operands[1].reg) |
5329 | as_tsktsk (_("rdhi and rdlo must be different")); | |
5330 | } | |
a737bd4d | 5331 | |
c19d1205 ZW |
5332 | /* ARM V5E (El Segundo) signed-multiply (argument parse) |
5333 | SMULxy{cond} Rd,Rm,Rs | |
5334 | Error if any register is R15. */ | |
a737bd4d | 5335 | |
c19d1205 ZW |
5336 | static void |
5337 | do_smul (void) | |
5338 | { | |
5339 | inst.instruction |= inst.operands[0].reg << 16; | |
5340 | inst.instruction |= inst.operands[1].reg; | |
5341 | inst.instruction |= inst.operands[2].reg << 8; | |
5342 | } | |
a737bd4d | 5343 | |
c19d1205 | 5344 | /* ARM V6 srs (argument parse). */ |
a737bd4d | 5345 | |
c19d1205 ZW |
5346 | static void |
5347 | do_srs (void) | |
5348 | { | |
5349 | inst.instruction |= inst.operands[0].imm; | |
5350 | if (inst.operands[0].writeback) | |
5351 | inst.instruction |= WRITE_BACK; | |
5352 | } | |
a737bd4d | 5353 | |
c19d1205 | 5354 | /* ARM V6 strex (argument parse). */ |
a737bd4d | 5355 | |
c19d1205 ZW |
5356 | static void |
5357 | do_strex (void) | |
5358 | { | |
5359 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
5360 | || inst.operands[2].postind || inst.operands[2].writeback | |
5361 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
01cfc07f NC |
5362 | || inst.operands[2].negative |
5363 | /* See comment in do_ldrex(). */ | |
5364 | || (inst.operands[2].reg == REG_PC), | |
5365 | BAD_ADDR_MODE); | |
a737bd4d | 5366 | |
c19d1205 ZW |
5367 | constraint (inst.operands[0].reg == inst.operands[1].reg |
5368 | || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP); | |
a737bd4d | 5369 | |
c19d1205 ZW |
5370 | constraint (inst.reloc.exp.X_op != O_constant |
5371 | || inst.reloc.exp.X_add_number != 0, | |
5372 | _("offset must be zero in ARM encoding")); | |
a737bd4d | 5373 | |
c19d1205 ZW |
5374 | inst.instruction |= inst.operands[0].reg << 12; |
5375 | inst.instruction |= inst.operands[1].reg; | |
5376 | inst.instruction |= inst.operands[2].reg << 16; | |
5377 | inst.reloc.type = BFD_RELOC_UNUSED; | |
e16bb312 NC |
5378 | } |
5379 | ||
5380 | static void | |
c19d1205 | 5381 | do_strexd (void) |
e16bb312 | 5382 | { |
c19d1205 ZW |
5383 | constraint (inst.operands[1].reg % 2 != 0, |
5384 | _("even register required")); | |
5385 | constraint (inst.operands[2].present | |
5386 | && inst.operands[2].reg != inst.operands[1].reg + 1, | |
5387 | _("can only store two consecutive registers")); | |
5388 | /* If op 2 were present and equal to PC, this function wouldn't | |
5389 | have been called in the first place. */ | |
5390 | constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here")); | |
e16bb312 | 5391 | |
c19d1205 ZW |
5392 | constraint (inst.operands[0].reg == inst.operands[1].reg |
5393 | || inst.operands[0].reg == inst.operands[1].reg + 1 | |
5394 | || inst.operands[0].reg == inst.operands[3].reg, | |
5395 | BAD_OVERLAP); | |
e16bb312 | 5396 | |
c19d1205 ZW |
5397 | inst.instruction |= inst.operands[0].reg << 12; |
5398 | inst.instruction |= inst.operands[1].reg; | |
5399 | inst.instruction |= inst.operands[3].reg << 16; | |
e16bb312 NC |
5400 | } |
5401 | ||
c19d1205 ZW |
5402 | /* ARM V6 SXTAH extracts a 16-bit value from a register, sign |
5403 | extends it to 32-bits, and adds the result to a value in another | |
5404 | register. You can specify a rotation by 0, 8, 16, or 24 bits | |
5405 | before extracting the 16-bit value. | |
5406 | SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>} | |
5407 | Condition defaults to COND_ALWAYS. | |
5408 | Error if any register uses R15. */ | |
5409 | ||
e16bb312 | 5410 | static void |
c19d1205 | 5411 | do_sxtah (void) |
e16bb312 | 5412 | { |
c19d1205 ZW |
5413 | inst.instruction |= inst.operands[0].reg << 12; |
5414 | inst.instruction |= inst.operands[1].reg << 16; | |
5415 | inst.instruction |= inst.operands[2].reg; | |
5416 | inst.instruction |= inst.operands[3].imm << 10; | |
5417 | } | |
e16bb312 | 5418 | |
c19d1205 | 5419 | /* ARM V6 SXTH. |
e16bb312 | 5420 | |
c19d1205 ZW |
5421 | SXTH {<cond>} <Rd>, <Rm>{, <rotation>} |
5422 | Condition defaults to COND_ALWAYS. | |
5423 | Error if any register uses R15. */ | |
e16bb312 NC |
5424 | |
5425 | static void | |
c19d1205 | 5426 | do_sxth (void) |
e16bb312 | 5427 | { |
c19d1205 ZW |
5428 | inst.instruction |= inst.operands[0].reg << 12; |
5429 | inst.instruction |= inst.operands[1].reg; | |
5430 | inst.instruction |= inst.operands[2].imm << 10; | |
e16bb312 | 5431 | } |
c19d1205 ZW |
5432 | \f |
5433 | /* VFP instructions. In a logical order: SP variant first, monad | |
5434 | before dyad, arithmetic then move then load/store. */ | |
e16bb312 NC |
5435 | |
5436 | static void | |
c19d1205 | 5437 | do_vfp_sp_monadic (void) |
e16bb312 | 5438 | { |
c19d1205 ZW |
5439 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5440 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
5441 | } |
5442 | ||
5443 | static void | |
c19d1205 | 5444 | do_vfp_sp_dyadic (void) |
e16bb312 | 5445 | { |
c19d1205 ZW |
5446 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5447 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
5448 | encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
5449 | } |
5450 | ||
5451 | static void | |
c19d1205 | 5452 | do_vfp_sp_compare_z (void) |
e16bb312 | 5453 | { |
c19d1205 | 5454 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
e16bb312 NC |
5455 | } |
5456 | ||
5457 | static void | |
c19d1205 | 5458 | do_vfp_dp_sp_cvt (void) |
e16bb312 | 5459 | { |
c19d1205 ZW |
5460 | inst.instruction |= inst.operands[0].reg << 12; |
5461 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm); | |
e16bb312 NC |
5462 | } |
5463 | ||
5464 | static void | |
c19d1205 | 5465 | do_vfp_sp_dp_cvt (void) |
e16bb312 | 5466 | { |
c19d1205 ZW |
5467 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5468 | inst.instruction |= inst.operands[1].reg; | |
e16bb312 NC |
5469 | } |
5470 | ||
5471 | static void | |
c19d1205 | 5472 | do_vfp_reg_from_sp (void) |
e16bb312 | 5473 | { |
c19d1205 ZW |
5474 | inst.instruction |= inst.operands[0].reg << 12; |
5475 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn); | |
e16bb312 NC |
5476 | } |
5477 | ||
5478 | static void | |
c19d1205 | 5479 | do_vfp_reg2_from_sp2 (void) |
e16bb312 | 5480 | { |
c19d1205 ZW |
5481 | constraint (inst.operands[2].imm != 2, |
5482 | _("only two consecutive VFP SP registers allowed here")); | |
5483 | inst.instruction |= inst.operands[0].reg << 12; | |
5484 | inst.instruction |= inst.operands[1].reg << 16; | |
5485 | encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm); | |
e16bb312 NC |
5486 | } |
5487 | ||
5488 | static void | |
c19d1205 | 5489 | do_vfp_sp_from_reg (void) |
e16bb312 | 5490 | { |
c19d1205 ZW |
5491 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn); |
5492 | inst.instruction |= inst.operands[1].reg << 12; | |
e16bb312 NC |
5493 | } |
5494 | ||
5495 | static void | |
c19d1205 | 5496 | do_vfp_sp2_from_reg2 (void) |
e16bb312 | 5497 | { |
c19d1205 ZW |
5498 | constraint (inst.operands[0].imm != 2, |
5499 | _("only two consecutive VFP SP registers allowed here")); | |
5500 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm); | |
5501 | inst.instruction |= inst.operands[1].reg << 12; | |
5502 | inst.instruction |= inst.operands[2].reg << 16; | |
e16bb312 NC |
5503 | } |
5504 | ||
5505 | static void | |
c19d1205 | 5506 | do_vfp_sp_ldst (void) |
e16bb312 | 5507 | { |
c19d1205 ZW |
5508 | encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd); |
5509 | encode_arm_cp_address (1, FALSE, TRUE, 0); | |
e16bb312 NC |
5510 | } |
5511 | ||
5512 | static void | |
c19d1205 | 5513 | do_vfp_dp_ldst (void) |
e16bb312 | 5514 | { |
c19d1205 ZW |
5515 | inst.instruction |= inst.operands[0].reg << 12; |
5516 | encode_arm_cp_address (1, FALSE, TRUE, 0); | |
e16bb312 NC |
5517 | } |
5518 | ||
c19d1205 | 5519 | |
e16bb312 | 5520 | static void |
c19d1205 | 5521 | vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 5522 | { |
c19d1205 ZW |
5523 | if (inst.operands[0].writeback) |
5524 | inst.instruction |= WRITE_BACK; | |
5525 | else | |
5526 | constraint (ldstm_type != VFP_LDSTMIA, | |
5527 | _("this addressing mode requires base-register writeback")); | |
5528 | inst.instruction |= inst.operands[0].reg << 16; | |
5529 | encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd); | |
5530 | inst.instruction |= inst.operands[1].imm; | |
e16bb312 NC |
5531 | } |
5532 | ||
5533 | static void | |
c19d1205 | 5534 | vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type) |
e16bb312 | 5535 | { |
c19d1205 | 5536 | int count; |
e16bb312 | 5537 | |
c19d1205 ZW |
5538 | if (inst.operands[0].writeback) |
5539 | inst.instruction |= WRITE_BACK; | |
5540 | else | |
5541 | constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX, | |
5542 | _("this addressing mode requires base-register writeback")); | |
e16bb312 | 5543 | |
c19d1205 ZW |
5544 | inst.instruction |= inst.operands[0].reg << 16; |
5545 | inst.instruction |= inst.operands[1].reg << 12; | |
e16bb312 | 5546 | |
c19d1205 ZW |
5547 | count = inst.operands[1].imm << 1; |
5548 | if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX) | |
5549 | count += 1; | |
e16bb312 | 5550 | |
c19d1205 | 5551 | inst.instruction |= count; |
e16bb312 NC |
5552 | } |
5553 | ||
5554 | static void | |
c19d1205 | 5555 | do_vfp_sp_ldstmia (void) |
e16bb312 | 5556 | { |
c19d1205 | 5557 | vfp_sp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
5558 | } |
5559 | ||
5560 | static void | |
c19d1205 | 5561 | do_vfp_sp_ldstmdb (void) |
e16bb312 | 5562 | { |
c19d1205 | 5563 | vfp_sp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
5564 | } |
5565 | ||
5566 | static void | |
c19d1205 | 5567 | do_vfp_dp_ldstmia (void) |
e16bb312 | 5568 | { |
c19d1205 | 5569 | vfp_dp_ldstm (VFP_LDSTMIA); |
e16bb312 NC |
5570 | } |
5571 | ||
5572 | static void | |
c19d1205 | 5573 | do_vfp_dp_ldstmdb (void) |
e16bb312 | 5574 | { |
c19d1205 | 5575 | vfp_dp_ldstm (VFP_LDSTMDB); |
e16bb312 NC |
5576 | } |
5577 | ||
5578 | static void | |
c19d1205 | 5579 | do_vfp_xp_ldstmia (void) |
e16bb312 | 5580 | { |
c19d1205 ZW |
5581 | vfp_dp_ldstm (VFP_LDSTMIAX); |
5582 | } | |
e16bb312 | 5583 | |
c19d1205 ZW |
5584 | static void |
5585 | do_vfp_xp_ldstmdb (void) | |
5586 | { | |
5587 | vfp_dp_ldstm (VFP_LDSTMDBX); | |
e16bb312 | 5588 | } |
c19d1205 ZW |
5589 | \f |
5590 | /* FPA instructions. Also in a logical order. */ | |
e16bb312 | 5591 | |
c19d1205 ZW |
5592 | static void |
5593 | do_fpa_cmp (void) | |
5594 | { | |
5595 | inst.instruction |= inst.operands[0].reg << 16; | |
5596 | inst.instruction |= inst.operands[1].reg; | |
5597 | } | |
b99bd4ef NC |
5598 | |
5599 | static void | |
c19d1205 | 5600 | do_fpa_ldmstm (void) |
b99bd4ef | 5601 | { |
c19d1205 ZW |
5602 | inst.instruction |= inst.operands[0].reg << 12; |
5603 | switch (inst.operands[1].imm) | |
5604 | { | |
5605 | case 1: inst.instruction |= CP_T_X; break; | |
5606 | case 2: inst.instruction |= CP_T_Y; break; | |
5607 | case 3: inst.instruction |= CP_T_Y | CP_T_X; break; | |
5608 | case 4: break; | |
5609 | default: abort (); | |
5610 | } | |
b99bd4ef | 5611 | |
c19d1205 ZW |
5612 | if (inst.instruction & (PRE_INDEX | INDEX_UP)) |
5613 | { | |
5614 | /* The instruction specified "ea" or "fd", so we can only accept | |
5615 | [Rn]{!}. The instruction does not really support stacking or | |
5616 | unstacking, so we have to emulate these by setting appropriate | |
5617 | bits and offsets. */ | |
5618 | constraint (inst.reloc.exp.X_op != O_constant | |
5619 | || inst.reloc.exp.X_add_number != 0, | |
5620 | _("this instruction does not support indexing")); | |
b99bd4ef | 5621 | |
c19d1205 ZW |
5622 | if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback) |
5623 | inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm; | |
b99bd4ef | 5624 | |
c19d1205 ZW |
5625 | if (!(inst.instruction & INDEX_UP)) |
5626 | inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number; | |
b99bd4ef | 5627 | |
c19d1205 ZW |
5628 | if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback) |
5629 | { | |
5630 | inst.operands[2].preind = 0; | |
5631 | inst.operands[2].postind = 1; | |
5632 | } | |
5633 | } | |
b99bd4ef | 5634 | |
c19d1205 | 5635 | encode_arm_cp_address (2, TRUE, TRUE, 0); |
b99bd4ef | 5636 | } |
c19d1205 ZW |
5637 | \f |
5638 | /* iWMMXt instructions: strictly in alphabetical order. */ | |
b99bd4ef | 5639 | |
c19d1205 ZW |
5640 | static void |
5641 | do_iwmmxt_tandorc (void) | |
5642 | { | |
5643 | constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here")); | |
5644 | } | |
b99bd4ef | 5645 | |
c19d1205 ZW |
5646 | static void |
5647 | do_iwmmxt_textrc (void) | |
5648 | { | |
5649 | inst.instruction |= inst.operands[0].reg << 12; | |
5650 | inst.instruction |= inst.operands[1].imm; | |
5651 | } | |
b99bd4ef NC |
5652 | |
5653 | static void | |
c19d1205 | 5654 | do_iwmmxt_textrm (void) |
b99bd4ef | 5655 | { |
c19d1205 ZW |
5656 | inst.instruction |= inst.operands[0].reg << 12; |
5657 | inst.instruction |= inst.operands[1].reg << 16; | |
5658 | inst.instruction |= inst.operands[2].imm; | |
5659 | } | |
b99bd4ef | 5660 | |
c19d1205 ZW |
5661 | static void |
5662 | do_iwmmxt_tinsr (void) | |
5663 | { | |
5664 | inst.instruction |= inst.operands[0].reg << 16; | |
5665 | inst.instruction |= inst.operands[1].reg << 12; | |
5666 | inst.instruction |= inst.operands[2].imm; | |
5667 | } | |
b99bd4ef | 5668 | |
c19d1205 ZW |
5669 | static void |
5670 | do_iwmmxt_tmia (void) | |
5671 | { | |
5672 | inst.instruction |= inst.operands[0].reg << 5; | |
5673 | inst.instruction |= inst.operands[1].reg; | |
5674 | inst.instruction |= inst.operands[2].reg << 12; | |
5675 | } | |
b99bd4ef | 5676 | |
c19d1205 ZW |
5677 | static void |
5678 | do_iwmmxt_waligni (void) | |
5679 | { | |
5680 | inst.instruction |= inst.operands[0].reg << 12; | |
5681 | inst.instruction |= inst.operands[1].reg << 16; | |
5682 | inst.instruction |= inst.operands[2].reg; | |
5683 | inst.instruction |= inst.operands[3].imm << 20; | |
5684 | } | |
b99bd4ef | 5685 | |
c19d1205 ZW |
5686 | static void |
5687 | do_iwmmxt_wmov (void) | |
5688 | { | |
5689 | /* WMOV rD, rN is an alias for WOR rD, rN, rN. */ | |
5690 | inst.instruction |= inst.operands[0].reg << 12; | |
5691 | inst.instruction |= inst.operands[1].reg << 16; | |
5692 | inst.instruction |= inst.operands[1].reg; | |
5693 | } | |
b99bd4ef | 5694 | |
c19d1205 ZW |
5695 | static void |
5696 | do_iwmmxt_wldstbh (void) | |
5697 | { | |
8f06b2d8 | 5698 | int reloc; |
c19d1205 ZW |
5699 | inst.instruction |= inst.operands[0].reg << 12; |
5700 | inst.reloc.exp.X_add_number *= 4; | |
8f06b2d8 PB |
5701 | if (thumb_mode) |
5702 | reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2; | |
5703 | else | |
5704 | reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2; | |
5705 | encode_arm_cp_address (1, TRUE, FALSE, reloc); | |
b99bd4ef NC |
5706 | } |
5707 | ||
c19d1205 ZW |
5708 | static void |
5709 | do_iwmmxt_wldstw (void) | |
5710 | { | |
5711 | /* RIWR_RIWC clears .isreg for a control register. */ | |
5712 | if (!inst.operands[0].isreg) | |
5713 | { | |
5714 | constraint (inst.cond != COND_ALWAYS, BAD_COND); | |
5715 | inst.instruction |= 0xf0000000; | |
5716 | } | |
b99bd4ef | 5717 | |
c19d1205 ZW |
5718 | inst.instruction |= inst.operands[0].reg << 12; |
5719 | encode_arm_cp_address (1, TRUE, TRUE, 0); | |
5720 | } | |
b99bd4ef NC |
5721 | |
5722 | static void | |
c19d1205 | 5723 | do_iwmmxt_wldstd (void) |
b99bd4ef | 5724 | { |
c19d1205 | 5725 | inst.instruction |= inst.operands[0].reg << 12; |
f2184508 | 5726 | encode_arm_cp_address (1, TRUE, FALSE, 0); |
c19d1205 | 5727 | } |
b99bd4ef | 5728 | |
c19d1205 ZW |
5729 | static void |
5730 | do_iwmmxt_wshufh (void) | |
5731 | { | |
5732 | inst.instruction |= inst.operands[0].reg << 12; | |
5733 | inst.instruction |= inst.operands[1].reg << 16; | |
5734 | inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16); | |
5735 | inst.instruction |= (inst.operands[2].imm & 0x0f); | |
5736 | } | |
b99bd4ef | 5737 | |
c19d1205 ZW |
5738 | static void |
5739 | do_iwmmxt_wzero (void) | |
5740 | { | |
5741 | /* WZERO reg is an alias for WANDN reg, reg, reg. */ | |
5742 | inst.instruction |= inst.operands[0].reg; | |
5743 | inst.instruction |= inst.operands[0].reg << 12; | |
5744 | inst.instruction |= inst.operands[0].reg << 16; | |
5745 | } | |
5746 | \f | |
5747 | /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register | |
5748 | operations first, then control, shift, and load/store. */ | |
b99bd4ef | 5749 | |
c19d1205 | 5750 | /* Insns like "foo X,Y,Z". */ |
b99bd4ef | 5751 | |
c19d1205 ZW |
5752 | static void |
5753 | do_mav_triple (void) | |
5754 | { | |
5755 | inst.instruction |= inst.operands[0].reg << 16; | |
5756 | inst.instruction |= inst.operands[1].reg; | |
5757 | inst.instruction |= inst.operands[2].reg << 12; | |
5758 | } | |
b99bd4ef | 5759 | |
c19d1205 ZW |
5760 | /* Insns like "foo W,X,Y,Z". |
5761 | where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */ | |
a737bd4d | 5762 | |
c19d1205 ZW |
5763 | static void |
5764 | do_mav_quad (void) | |
5765 | { | |
5766 | inst.instruction |= inst.operands[0].reg << 5; | |
5767 | inst.instruction |= inst.operands[1].reg << 12; | |
5768 | inst.instruction |= inst.operands[2].reg << 16; | |
5769 | inst.instruction |= inst.operands[3].reg; | |
a737bd4d NC |
5770 | } |
5771 | ||
c19d1205 ZW |
5772 | /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */ |
5773 | static void | |
5774 | do_mav_dspsc (void) | |
a737bd4d | 5775 | { |
c19d1205 ZW |
5776 | inst.instruction |= inst.operands[1].reg << 12; |
5777 | } | |
a737bd4d | 5778 | |
c19d1205 ZW |
5779 | /* Maverick shift immediate instructions. |
5780 | cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0]. | |
5781 | cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */ | |
a737bd4d | 5782 | |
c19d1205 ZW |
5783 | static void |
5784 | do_mav_shift (void) | |
5785 | { | |
5786 | int imm = inst.operands[2].imm; | |
a737bd4d | 5787 | |
c19d1205 ZW |
5788 | inst.instruction |= inst.operands[0].reg << 12; |
5789 | inst.instruction |= inst.operands[1].reg << 16; | |
a737bd4d | 5790 | |
c19d1205 ZW |
5791 | /* Bits 0-3 of the insn should have bits 0-3 of the immediate. |
5792 | Bits 5-7 of the insn should have bits 4-6 of the immediate. | |
5793 | Bit 4 should be 0. */ | |
5794 | imm = (imm & 0xf) | ((imm & 0x70) << 1); | |
a737bd4d | 5795 | |
c19d1205 ZW |
5796 | inst.instruction |= imm; |
5797 | } | |
5798 | \f | |
5799 | /* XScale instructions. Also sorted arithmetic before move. */ | |
a737bd4d | 5800 | |
c19d1205 ZW |
5801 | /* Xscale multiply-accumulate (argument parse) |
5802 | MIAcc acc0,Rm,Rs | |
5803 | MIAPHcc acc0,Rm,Rs | |
5804 | MIAxycc acc0,Rm,Rs. */ | |
a737bd4d | 5805 | |
c19d1205 ZW |
5806 | static void |
5807 | do_xsc_mia (void) | |
5808 | { | |
5809 | inst.instruction |= inst.operands[1].reg; | |
5810 | inst.instruction |= inst.operands[2].reg << 12; | |
5811 | } | |
a737bd4d | 5812 | |
c19d1205 | 5813 | /* Xscale move-accumulator-register (argument parse) |
a737bd4d | 5814 | |
c19d1205 | 5815 | MARcc acc0,RdLo,RdHi. */ |
b99bd4ef | 5816 | |
c19d1205 ZW |
5817 | static void |
5818 | do_xsc_mar (void) | |
5819 | { | |
5820 | inst.instruction |= inst.operands[1].reg << 12; | |
5821 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
5822 | } |
5823 | ||
c19d1205 | 5824 | /* Xscale move-register-accumulator (argument parse) |
b99bd4ef | 5825 | |
c19d1205 | 5826 | MRAcc RdLo,RdHi,acc0. */ |
b99bd4ef NC |
5827 | |
5828 | static void | |
c19d1205 | 5829 | do_xsc_mra (void) |
b99bd4ef | 5830 | { |
c19d1205 ZW |
5831 | constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP); |
5832 | inst.instruction |= inst.operands[0].reg << 12; | |
5833 | inst.instruction |= inst.operands[1].reg << 16; | |
5834 | } | |
5835 | \f | |
5836 | /* Encoding functions relevant only to Thumb. */ | |
b99bd4ef | 5837 | |
c19d1205 ZW |
5838 | /* inst.operands[i] is a shifted-register operand; encode |
5839 | it into inst.instruction in the format used by Thumb32. */ | |
5840 | ||
5841 | static void | |
5842 | encode_thumb32_shifted_operand (int i) | |
5843 | { | |
5844 | unsigned int value = inst.reloc.exp.X_add_number; | |
5845 | unsigned int shift = inst.operands[i].shift_kind; | |
b99bd4ef | 5846 | |
9c3c69f2 PB |
5847 | constraint (inst.operands[i].immisreg, |
5848 | _("shift by register not allowed in thumb mode")); | |
c19d1205 ZW |
5849 | inst.instruction |= inst.operands[i].reg; |
5850 | if (shift == SHIFT_RRX) | |
5851 | inst.instruction |= SHIFT_ROR << 4; | |
5852 | else | |
b99bd4ef | 5853 | { |
c19d1205 ZW |
5854 | constraint (inst.reloc.exp.X_op != O_constant, |
5855 | _("expression too complex")); | |
5856 | ||
5857 | constraint (value > 32 | |
5858 | || (value == 32 && (shift == SHIFT_LSL | |
5859 | || shift == SHIFT_ROR)), | |
5860 | _("shift expression is too large")); | |
5861 | ||
5862 | if (value == 0) | |
5863 | shift = SHIFT_LSL; | |
5864 | else if (value == 32) | |
5865 | value = 0; | |
5866 | ||
5867 | inst.instruction |= shift << 4; | |
5868 | inst.instruction |= (value & 0x1c) << 10; | |
5869 | inst.instruction |= (value & 0x03) << 6; | |
b99bd4ef | 5870 | } |
c19d1205 | 5871 | } |
b99bd4ef | 5872 | |
b99bd4ef | 5873 | |
c19d1205 ZW |
5874 | /* inst.operands[i] was set up by parse_address. Encode it into a |
5875 | Thumb32 format load or store instruction. Reject forms that cannot | |
5876 | be used with such instructions. If is_t is true, reject forms that | |
5877 | cannot be used with a T instruction; if is_d is true, reject forms | |
5878 | that cannot be used with a D instruction. */ | |
b99bd4ef | 5879 | |
c19d1205 ZW |
5880 | static void |
5881 | encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d) | |
5882 | { | |
5883 | bfd_boolean is_pc = (inst.operands[i].reg == REG_PC); | |
5884 | ||
5885 | constraint (!inst.operands[i].isreg, | |
5886 | _("Thumb does not support the ldr =N pseudo-operation")); | |
b99bd4ef | 5887 | |
c19d1205 ZW |
5888 | inst.instruction |= inst.operands[i].reg << 16; |
5889 | if (inst.operands[i].immisreg) | |
b99bd4ef | 5890 | { |
c19d1205 ZW |
5891 | constraint (is_pc, _("cannot use register index with PC-relative addressing")); |
5892 | constraint (is_t || is_d, _("cannot use register index with this instruction")); | |
5893 | constraint (inst.operands[i].negative, | |
5894 | _("Thumb does not support negative register indexing")); | |
5895 | constraint (inst.operands[i].postind, | |
5896 | _("Thumb does not support register post-indexing")); | |
5897 | constraint (inst.operands[i].writeback, | |
5898 | _("Thumb does not support register indexing with writeback")); | |
5899 | constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL, | |
5900 | _("Thumb supports only LSL in shifted register indexing")); | |
b99bd4ef | 5901 | |
f40d1643 | 5902 | inst.instruction |= inst.operands[i].imm; |
c19d1205 | 5903 | if (inst.operands[i].shifted) |
b99bd4ef | 5904 | { |
c19d1205 ZW |
5905 | constraint (inst.reloc.exp.X_op != O_constant, |
5906 | _("expression too complex")); | |
9c3c69f2 PB |
5907 | constraint (inst.reloc.exp.X_add_number < 0 |
5908 | || inst.reloc.exp.X_add_number > 3, | |
c19d1205 | 5909 | _("shift out of range")); |
9c3c69f2 | 5910 | inst.instruction |= inst.reloc.exp.X_add_number << 4; |
c19d1205 ZW |
5911 | } |
5912 | inst.reloc.type = BFD_RELOC_UNUSED; | |
5913 | } | |
5914 | else if (inst.operands[i].preind) | |
5915 | { | |
5916 | constraint (is_pc && inst.operands[i].writeback, | |
5917 | _("cannot use writeback with PC-relative addressing")); | |
f40d1643 | 5918 | constraint (is_t && inst.operands[i].writeback, |
c19d1205 ZW |
5919 | _("cannot use writeback with this instruction")); |
5920 | ||
5921 | if (is_d) | |
5922 | { | |
5923 | inst.instruction |= 0x01000000; | |
5924 | if (inst.operands[i].writeback) | |
5925 | inst.instruction |= 0x00200000; | |
b99bd4ef | 5926 | } |
c19d1205 | 5927 | else |
b99bd4ef | 5928 | { |
c19d1205 ZW |
5929 | inst.instruction |= 0x00000c00; |
5930 | if (inst.operands[i].writeback) | |
5931 | inst.instruction |= 0x00000100; | |
b99bd4ef | 5932 | } |
c19d1205 | 5933 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; |
b99bd4ef | 5934 | } |
c19d1205 | 5935 | else if (inst.operands[i].postind) |
b99bd4ef | 5936 | { |
c19d1205 ZW |
5937 | assert (inst.operands[i].writeback); |
5938 | constraint (is_pc, _("cannot use post-indexing with PC-relative addressing")); | |
5939 | constraint (is_t, _("cannot use post-indexing with this instruction")); | |
5940 | ||
5941 | if (is_d) | |
5942 | inst.instruction |= 0x00200000; | |
5943 | else | |
5944 | inst.instruction |= 0x00000900; | |
5945 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
5946 | } | |
5947 | else /* unindexed - only for coprocessor */ | |
5948 | inst.error = _("instruction does not accept unindexed addressing"); | |
5949 | } | |
5950 | ||
5951 | /* Table of Thumb instructions which exist in both 16- and 32-bit | |
5952 | encodings (the latter only in post-V6T2 cores). The index is the | |
5953 | value used in the insns table below. When there is more than one | |
5954 | possible 16-bit encoding for the instruction, this table always | |
0110f2b8 PB |
5955 | holds variant (1). |
5956 | Also contains several pseudo-instructions used during relaxation. */ | |
c19d1205 ZW |
5957 | #define T16_32_TAB \ |
5958 | X(adc, 4140, eb400000), \ | |
5959 | X(adcs, 4140, eb500000), \ | |
5960 | X(add, 1c00, eb000000), \ | |
5961 | X(adds, 1c00, eb100000), \ | |
0110f2b8 PB |
5962 | X(addi, 0000, f1000000), \ |
5963 | X(addis, 0000, f1100000), \ | |
5964 | X(add_pc,000f, f20f0000), \ | |
5965 | X(add_sp,000d, f10d0000), \ | |
e9f89963 | 5966 | X(adr, 000f, f20f0000), \ |
c19d1205 ZW |
5967 | X(and, 4000, ea000000), \ |
5968 | X(ands, 4000, ea100000), \ | |
5969 | X(asr, 1000, fa40f000), \ | |
5970 | X(asrs, 1000, fa50f000), \ | |
0110f2b8 PB |
5971 | X(b, e000, f000b000), \ |
5972 | X(bcond, d000, f0008000), \ | |
c19d1205 ZW |
5973 | X(bic, 4380, ea200000), \ |
5974 | X(bics, 4380, ea300000), \ | |
5975 | X(cmn, 42c0, eb100f00), \ | |
5976 | X(cmp, 2800, ebb00f00), \ | |
5977 | X(cpsie, b660, f3af8400), \ | |
5978 | X(cpsid, b670, f3af8600), \ | |
5979 | X(cpy, 4600, ea4f0000), \ | |
0110f2b8 | 5980 | X(dec_sp,80dd, f1bd0d00), \ |
c19d1205 ZW |
5981 | X(eor, 4040, ea800000), \ |
5982 | X(eors, 4040, ea900000), \ | |
0110f2b8 | 5983 | X(inc_sp,00dd, f10d0d00), \ |
c19d1205 ZW |
5984 | X(ldmia, c800, e8900000), \ |
5985 | X(ldr, 6800, f8500000), \ | |
5986 | X(ldrb, 7800, f8100000), \ | |
5987 | X(ldrh, 8800, f8300000), \ | |
5988 | X(ldrsb, 5600, f9100000), \ | |
5989 | X(ldrsh, 5e00, f9300000), \ | |
0110f2b8 PB |
5990 | X(ldr_pc,4800, f85f0000), \ |
5991 | X(ldr_pc2,4800, f85f0000), \ | |
5992 | X(ldr_sp,9800, f85d0000), \ | |
c19d1205 ZW |
5993 | X(lsl, 0000, fa00f000), \ |
5994 | X(lsls, 0000, fa10f000), \ | |
5995 | X(lsr, 0800, fa20f000), \ | |
5996 | X(lsrs, 0800, fa30f000), \ | |
5997 | X(mov, 2000, ea4f0000), \ | |
5998 | X(movs, 2000, ea5f0000), \ | |
5999 | X(mul, 4340, fb00f000), \ | |
6000 | X(muls, 4340, ffffffff), /* no 32b muls */ \ | |
6001 | X(mvn, 43c0, ea6f0000), \ | |
6002 | X(mvns, 43c0, ea7f0000), \ | |
6003 | X(neg, 4240, f1c00000), /* rsb #0 */ \ | |
6004 | X(negs, 4240, f1d00000), /* rsbs #0 */ \ | |
6005 | X(orr, 4300, ea400000), \ | |
6006 | X(orrs, 4300, ea500000), \ | |
e9f89963 PB |
6007 | X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \ |
6008 | X(push, b400, e92d0000), /* stmdb sp!,... */ \ | |
c19d1205 ZW |
6009 | X(rev, ba00, fa90f080), \ |
6010 | X(rev16, ba40, fa90f090), \ | |
6011 | X(revsh, bac0, fa90f0b0), \ | |
6012 | X(ror, 41c0, fa60f000), \ | |
6013 | X(rors, 41c0, fa70f000), \ | |
6014 | X(sbc, 4180, eb600000), \ | |
6015 | X(sbcs, 4180, eb700000), \ | |
6016 | X(stmia, c000, e8800000), \ | |
6017 | X(str, 6000, f8400000), \ | |
6018 | X(strb, 7000, f8000000), \ | |
6019 | X(strh, 8000, f8200000), \ | |
0110f2b8 | 6020 | X(str_sp,9000, f84d0000), \ |
c19d1205 ZW |
6021 | X(sub, 1e00, eba00000), \ |
6022 | X(subs, 1e00, ebb00000), \ | |
0110f2b8 PB |
6023 | X(subi, 8000, f1a00000), \ |
6024 | X(subis, 8000, f1b00000), \ | |
c19d1205 ZW |
6025 | X(sxtb, b240, fa4ff080), \ |
6026 | X(sxth, b200, fa0ff080), \ | |
6027 | X(tst, 4200, ea100f00), \ | |
6028 | X(uxtb, b2c0, fa5ff080), \ | |
6029 | X(uxth, b280, fa1ff080), \ | |
6030 | X(nop, bf00, f3af8000), \ | |
6031 | X(yield, bf10, f3af8001), \ | |
6032 | X(wfe, bf20, f3af8002), \ | |
6033 | X(wfi, bf30, f3af8003), \ | |
6034 | X(sev, bf40, f3af9004), /* typo, 8004? */ | |
6035 | ||
6036 | /* To catch errors in encoding functions, the codes are all offset by | |
6037 | 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined | |
6038 | as 16-bit instructions. */ | |
6039 | #define X(a,b,c) T_MNEM_##a | |
6040 | enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB }; | |
6041 | #undef X | |
6042 | ||
6043 | #define X(a,b,c) 0x##b | |
6044 | static const unsigned short thumb_op16[] = { T16_32_TAB }; | |
6045 | #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)]) | |
6046 | #undef X | |
6047 | ||
6048 | #define X(a,b,c) 0x##c | |
6049 | static const unsigned int thumb_op32[] = { T16_32_TAB }; | |
6050 | #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)]) | |
6051 | #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000) | |
6052 | #undef X | |
6053 | #undef T16_32_TAB | |
6054 | ||
6055 | /* Thumb instruction encoders, in alphabetical order. */ | |
6056 | ||
92e90b6e PB |
6057 | /* ADDW or SUBW. */ |
6058 | static void | |
6059 | do_t_add_sub_w (void) | |
6060 | { | |
6061 | int Rd, Rn; | |
6062 | ||
6063 | Rd = inst.operands[0].reg; | |
6064 | Rn = inst.operands[1].reg; | |
6065 | ||
6066 | constraint (Rd == 15, _("PC not allowed as destination")); | |
6067 | inst.instruction |= (Rn << 16) | (Rd << 8); | |
6068 | inst.reloc.type = BFD_RELOC_ARM_T32_IMM12; | |
6069 | } | |
6070 | ||
c19d1205 ZW |
6071 | /* Parse an add or subtract instruction. We get here with inst.instruction |
6072 | equalling any of THUMB_OPCODE_add, adds, sub, or subs. */ | |
6073 | ||
6074 | static void | |
6075 | do_t_add_sub (void) | |
6076 | { | |
6077 | int Rd, Rs, Rn; | |
6078 | ||
6079 | Rd = inst.operands[0].reg; | |
6080 | Rs = (inst.operands[1].present | |
6081 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
6082 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
6083 | ||
6084 | if (unified_syntax) | |
6085 | { | |
0110f2b8 PB |
6086 | bfd_boolean flags; |
6087 | bfd_boolean narrow; | |
6088 | int opcode; | |
6089 | ||
6090 | flags = (inst.instruction == T_MNEM_adds | |
6091 | || inst.instruction == T_MNEM_subs); | |
6092 | if (flags) | |
6093 | narrow = (current_it_mask == 0); | |
6094 | else | |
6095 | narrow = (current_it_mask != 0); | |
c19d1205 | 6096 | if (!inst.operands[2].isreg) |
b99bd4ef | 6097 | { |
0110f2b8 PB |
6098 | opcode = 0; |
6099 | if (inst.size_req != 4) | |
6100 | { | |
6101 | int add; | |
6102 | ||
6103 | add = (inst.instruction == T_MNEM_add | |
6104 | || inst.instruction == T_MNEM_adds); | |
6105 | /* Attempt to use a narrow opcode, with relaxation if | |
6106 | appropriate. */ | |
6107 | if (Rd == REG_SP && Rs == REG_SP && !flags) | |
6108 | opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp; | |
6109 | else if (Rd <= 7 && Rs == REG_SP && add && !flags) | |
6110 | opcode = T_MNEM_add_sp; | |
6111 | else if (Rd <= 7 && Rs == REG_PC && add && !flags) | |
6112 | opcode = T_MNEM_add_pc; | |
6113 | else if (Rd <= 7 && Rs <= 7 && narrow) | |
6114 | { | |
6115 | if (flags) | |
6116 | opcode = add ? T_MNEM_addis : T_MNEM_subis; | |
6117 | else | |
6118 | opcode = add ? T_MNEM_addi : T_MNEM_subi; | |
6119 | } | |
6120 | if (opcode) | |
6121 | { | |
6122 | inst.instruction = THUMB_OP16(opcode); | |
6123 | inst.instruction |= (Rd << 4) | Rs; | |
6124 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
6125 | if (inst.size_req != 2) | |
6126 | inst.relax = opcode; | |
6127 | } | |
6128 | else | |
6129 | constraint (inst.size_req == 2, BAD_HIREG); | |
6130 | } | |
6131 | if (inst.size_req == 4 | |
6132 | || (inst.size_req != 2 && !opcode)) | |
6133 | { | |
6134 | /* ??? Convert large immediates to addw/subw. */ | |
6135 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6136 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
6137 | inst.instruction |= inst.operands[0].reg << 8; | |
6138 | inst.instruction |= inst.operands[1].reg << 16; | |
6139 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
6140 | } | |
b99bd4ef | 6141 | } |
c19d1205 ZW |
6142 | else |
6143 | { | |
6144 | Rn = inst.operands[2].reg; | |
6145 | /* See if we can do this with a 16-bit instruction. */ | |
6146 | if (!inst.operands[2].shifted && inst.size_req != 4) | |
6147 | { | |
e27ec89e PB |
6148 | if (Rd > 7 || Rs > 7 || Rn > 7) |
6149 | narrow = FALSE; | |
6150 | ||
6151 | if (narrow) | |
c19d1205 | 6152 | { |
e27ec89e PB |
6153 | inst.instruction = ((inst.instruction == T_MNEM_adds |
6154 | || inst.instruction == T_MNEM_add) | |
c19d1205 ZW |
6155 | ? T_OPCODE_ADD_R3 |
6156 | : T_OPCODE_SUB_R3); | |
6157 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
6158 | return; | |
6159 | } | |
b99bd4ef | 6160 | |
c19d1205 ZW |
6161 | if (inst.instruction == T_MNEM_add) |
6162 | { | |
6163 | if (Rd == Rs) | |
6164 | { | |
6165 | inst.instruction = T_OPCODE_ADD_HI; | |
6166 | inst.instruction |= (Rd & 8) << 4; | |
6167 | inst.instruction |= (Rd & 7); | |
6168 | inst.instruction |= Rn << 3; | |
6169 | return; | |
6170 | } | |
6171 | /* ... because addition is commutative! */ | |
6172 | else if (Rd == Rn) | |
6173 | { | |
6174 | inst.instruction = T_OPCODE_ADD_HI; | |
6175 | inst.instruction |= (Rd & 8) << 4; | |
6176 | inst.instruction |= (Rd & 7); | |
6177 | inst.instruction |= Rs << 3; | |
6178 | return; | |
6179 | } | |
6180 | } | |
6181 | } | |
6182 | /* If we get here, it can't be done in 16 bits. */ | |
6183 | constraint (inst.operands[2].shifted && inst.operands[2].immisreg, | |
6184 | _("shift must be constant")); | |
6185 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6186 | inst.instruction |= Rd << 8; | |
6187 | inst.instruction |= Rs << 16; | |
6188 | encode_thumb32_shifted_operand (2); | |
6189 | } | |
6190 | } | |
6191 | else | |
6192 | { | |
6193 | constraint (inst.instruction == T_MNEM_adds | |
6194 | || inst.instruction == T_MNEM_subs, | |
6195 | BAD_THUMB32); | |
b99bd4ef | 6196 | |
c19d1205 | 6197 | if (!inst.operands[2].isreg) /* Rd, Rs, #imm */ |
b99bd4ef | 6198 | { |
c19d1205 ZW |
6199 | constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP)) |
6200 | || (Rs > 7 && Rs != REG_SP && Rs != REG_PC), | |
6201 | BAD_HIREG); | |
6202 | ||
6203 | inst.instruction = (inst.instruction == T_MNEM_add | |
6204 | ? 0x0000 : 0x8000); | |
6205 | inst.instruction |= (Rd << 4) | Rs; | |
6206 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
b99bd4ef NC |
6207 | return; |
6208 | } | |
6209 | ||
c19d1205 ZW |
6210 | Rn = inst.operands[2].reg; |
6211 | constraint (inst.operands[2].shifted, _("unshifted register required")); | |
b99bd4ef | 6212 | |
c19d1205 ZW |
6213 | /* We now have Rd, Rs, and Rn set to registers. */ |
6214 | if (Rd > 7 || Rs > 7 || Rn > 7) | |
b99bd4ef | 6215 | { |
c19d1205 ZW |
6216 | /* Can't do this for SUB. */ |
6217 | constraint (inst.instruction == T_MNEM_sub, BAD_HIREG); | |
6218 | inst.instruction = T_OPCODE_ADD_HI; | |
6219 | inst.instruction |= (Rd & 8) << 4; | |
6220 | inst.instruction |= (Rd & 7); | |
6221 | if (Rs == Rd) | |
6222 | inst.instruction |= Rn << 3; | |
6223 | else if (Rn == Rd) | |
6224 | inst.instruction |= Rs << 3; | |
6225 | else | |
6226 | constraint (1, _("dest must overlap one source register")); | |
6227 | } | |
6228 | else | |
6229 | { | |
6230 | inst.instruction = (inst.instruction == T_MNEM_add | |
6231 | ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3); | |
6232 | inst.instruction |= Rd | (Rs << 3) | (Rn << 6); | |
b99bd4ef | 6233 | } |
b99bd4ef | 6234 | } |
b99bd4ef NC |
6235 | } |
6236 | ||
c19d1205 ZW |
6237 | static void |
6238 | do_t_adr (void) | |
6239 | { | |
0110f2b8 PB |
6240 | if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7) |
6241 | { | |
6242 | /* Defer to section relaxation. */ | |
6243 | inst.relax = inst.instruction; | |
6244 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6245 | inst.instruction |= inst.operands[0].reg << 4; | |
6246 | } | |
6247 | else if (unified_syntax && inst.size_req != 2) | |
e9f89963 | 6248 | { |
0110f2b8 | 6249 | /* Generate a 32-bit opcode. */ |
e9f89963 PB |
6250 | inst.instruction = THUMB_OP32 (inst.instruction); |
6251 | inst.instruction |= inst.operands[0].reg << 8; | |
6252 | inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12; | |
6253 | inst.reloc.pc_rel = 1; | |
6254 | } | |
6255 | else | |
6256 | { | |
0110f2b8 | 6257 | /* Generate a 16-bit opcode. */ |
e9f89963 PB |
6258 | inst.instruction = THUMB_OP16 (inst.instruction); |
6259 | inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD; | |
6260 | inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */ | |
6261 | inst.reloc.pc_rel = 1; | |
b99bd4ef | 6262 | |
e9f89963 PB |
6263 | inst.instruction |= inst.operands[0].reg << 4; |
6264 | } | |
c19d1205 | 6265 | } |
b99bd4ef | 6266 | |
c19d1205 ZW |
6267 | /* Arithmetic instructions for which there is just one 16-bit |
6268 | instruction encoding, and it allows only two low registers. | |
6269 | For maximal compatibility with ARM syntax, we allow three register | |
6270 | operands even when Thumb-32 instructions are not available, as long | |
6271 | as the first two are identical. For instance, both "sbc r0,r1" and | |
6272 | "sbc r0,r0,r1" are allowed. */ | |
b99bd4ef | 6273 | static void |
c19d1205 | 6274 | do_t_arit3 (void) |
b99bd4ef | 6275 | { |
c19d1205 | 6276 | int Rd, Rs, Rn; |
b99bd4ef | 6277 | |
c19d1205 ZW |
6278 | Rd = inst.operands[0].reg; |
6279 | Rs = (inst.operands[1].present | |
6280 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
6281 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
6282 | Rn = inst.operands[2].reg; | |
b99bd4ef | 6283 | |
c19d1205 | 6284 | if (unified_syntax) |
b99bd4ef | 6285 | { |
c19d1205 ZW |
6286 | if (!inst.operands[2].isreg) |
6287 | { | |
6288 | /* For an immediate, we always generate a 32-bit opcode; | |
6289 | section relaxation will shrink it later if possible. */ | |
6290 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6291 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
6292 | inst.instruction |= Rd << 8; | |
6293 | inst.instruction |= Rs << 16; | |
6294 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
6295 | } | |
6296 | else | |
6297 | { | |
e27ec89e PB |
6298 | bfd_boolean narrow; |
6299 | ||
c19d1205 | 6300 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
6301 | if (THUMB_SETS_FLAGS (inst.instruction)) |
6302 | narrow = current_it_mask == 0; | |
6303 | else | |
6304 | narrow = current_it_mask != 0; | |
6305 | ||
6306 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
6307 | narrow = FALSE; | |
6308 | if (inst.operands[2].shifted) | |
6309 | narrow = FALSE; | |
6310 | if (inst.size_req == 4) | |
6311 | narrow = FALSE; | |
6312 | ||
6313 | if (narrow | |
c19d1205 ZW |
6314 | && Rd == Rs) |
6315 | { | |
6316 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6317 | inst.instruction |= Rd; | |
6318 | inst.instruction |= Rn << 3; | |
6319 | return; | |
6320 | } | |
b99bd4ef | 6321 | |
c19d1205 ZW |
6322 | /* If we get here, it can't be done in 16 bits. */ |
6323 | constraint (inst.operands[2].shifted | |
6324 | && inst.operands[2].immisreg, | |
6325 | _("shift must be constant")); | |
6326 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6327 | inst.instruction |= Rd << 8; | |
6328 | inst.instruction |= Rs << 16; | |
6329 | encode_thumb32_shifted_operand (2); | |
6330 | } | |
a737bd4d | 6331 | } |
c19d1205 | 6332 | else |
b99bd4ef | 6333 | { |
c19d1205 ZW |
6334 | /* On its face this is a lie - the instruction does set the |
6335 | flags. However, the only supported mnemonic in this mode | |
6336 | says it doesn't. */ | |
6337 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 6338 | |
c19d1205 ZW |
6339 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
6340 | _("unshifted register required")); | |
6341 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
6342 | constraint (Rd != Rs, | |
6343 | _("dest and source1 must be the same register")); | |
a737bd4d | 6344 | |
c19d1205 ZW |
6345 | inst.instruction = THUMB_OP16 (inst.instruction); |
6346 | inst.instruction |= Rd; | |
6347 | inst.instruction |= Rn << 3; | |
b99bd4ef | 6348 | } |
a737bd4d | 6349 | } |
b99bd4ef | 6350 | |
c19d1205 ZW |
6351 | /* Similarly, but for instructions where the arithmetic operation is |
6352 | commutative, so we can allow either of them to be different from | |
6353 | the destination operand in a 16-bit instruction. For instance, all | |
6354 | three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are | |
6355 | accepted. */ | |
6356 | static void | |
6357 | do_t_arit3c (void) | |
a737bd4d | 6358 | { |
c19d1205 | 6359 | int Rd, Rs, Rn; |
b99bd4ef | 6360 | |
c19d1205 ZW |
6361 | Rd = inst.operands[0].reg; |
6362 | Rs = (inst.operands[1].present | |
6363 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
6364 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
6365 | Rn = inst.operands[2].reg; | |
a737bd4d | 6366 | |
c19d1205 | 6367 | if (unified_syntax) |
a737bd4d | 6368 | { |
c19d1205 | 6369 | if (!inst.operands[2].isreg) |
b99bd4ef | 6370 | { |
c19d1205 ZW |
6371 | /* For an immediate, we always generate a 32-bit opcode; |
6372 | section relaxation will shrink it later if possible. */ | |
6373 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6374 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
6375 | inst.instruction |= Rd << 8; | |
6376 | inst.instruction |= Rs << 16; | |
6377 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 6378 | } |
c19d1205 | 6379 | else |
a737bd4d | 6380 | { |
e27ec89e PB |
6381 | bfd_boolean narrow; |
6382 | ||
c19d1205 | 6383 | /* See if we can do this with a 16-bit instruction. */ |
e27ec89e PB |
6384 | if (THUMB_SETS_FLAGS (inst.instruction)) |
6385 | narrow = current_it_mask == 0; | |
6386 | else | |
6387 | narrow = current_it_mask != 0; | |
6388 | ||
6389 | if (Rd > 7 || Rn > 7 || Rs > 7) | |
6390 | narrow = FALSE; | |
6391 | if (inst.operands[2].shifted) | |
6392 | narrow = FALSE; | |
6393 | if (inst.size_req == 4) | |
6394 | narrow = FALSE; | |
6395 | ||
6396 | if (narrow) | |
a737bd4d | 6397 | { |
c19d1205 | 6398 | if (Rd == Rs) |
a737bd4d | 6399 | { |
c19d1205 ZW |
6400 | inst.instruction = THUMB_OP16 (inst.instruction); |
6401 | inst.instruction |= Rd; | |
6402 | inst.instruction |= Rn << 3; | |
6403 | return; | |
a737bd4d | 6404 | } |
c19d1205 | 6405 | if (Rd == Rn) |
a737bd4d | 6406 | { |
c19d1205 ZW |
6407 | inst.instruction = THUMB_OP16 (inst.instruction); |
6408 | inst.instruction |= Rd; | |
6409 | inst.instruction |= Rs << 3; | |
6410 | return; | |
a737bd4d NC |
6411 | } |
6412 | } | |
c19d1205 ZW |
6413 | |
6414 | /* If we get here, it can't be done in 16 bits. */ | |
6415 | constraint (inst.operands[2].shifted | |
6416 | && inst.operands[2].immisreg, | |
6417 | _("shift must be constant")); | |
6418 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6419 | inst.instruction |= Rd << 8; | |
6420 | inst.instruction |= Rs << 16; | |
6421 | encode_thumb32_shifted_operand (2); | |
a737bd4d | 6422 | } |
b99bd4ef | 6423 | } |
c19d1205 ZW |
6424 | else |
6425 | { | |
6426 | /* On its face this is a lie - the instruction does set the | |
6427 | flags. However, the only supported mnemonic in this mode | |
6428 | says it doesn't. */ | |
6429 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
a737bd4d | 6430 | |
c19d1205 ZW |
6431 | constraint (!inst.operands[2].isreg || inst.operands[2].shifted, |
6432 | _("unshifted register required")); | |
6433 | constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG); | |
6434 | ||
6435 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6436 | inst.instruction |= Rd; | |
6437 | ||
6438 | if (Rd == Rs) | |
6439 | inst.instruction |= Rn << 3; | |
6440 | else if (Rd == Rn) | |
6441 | inst.instruction |= Rs << 3; | |
6442 | else | |
6443 | constraint (1, _("dest must overlap one source register")); | |
6444 | } | |
a737bd4d NC |
6445 | } |
6446 | ||
c19d1205 ZW |
6447 | static void |
6448 | do_t_bfc (void) | |
a737bd4d | 6449 | { |
c19d1205 ZW |
6450 | unsigned int msb = inst.operands[1].imm + inst.operands[2].imm; |
6451 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6452 | /* The instruction encoding stores the LSB and MSB, | |
6453 | not the LSB and width. */ | |
6454 | inst.instruction |= inst.operands[0].reg << 8; | |
6455 | inst.instruction |= (inst.operands[1].imm & 0x1c) << 10; | |
6456 | inst.instruction |= (inst.operands[1].imm & 0x03) << 6; | |
6457 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
6458 | } |
6459 | ||
c19d1205 ZW |
6460 | static void |
6461 | do_t_bfi (void) | |
b99bd4ef | 6462 | { |
c19d1205 | 6463 | unsigned int msb; |
b99bd4ef | 6464 | |
c19d1205 ZW |
6465 | /* #0 in second position is alternative syntax for bfc, which is |
6466 | the same instruction but with REG_PC in the Rm field. */ | |
6467 | if (!inst.operands[1].isreg) | |
6468 | inst.operands[1].reg = REG_PC; | |
b99bd4ef | 6469 | |
c19d1205 ZW |
6470 | msb = inst.operands[2].imm + inst.operands[3].imm; |
6471 | constraint (msb > 32, _("bit-field extends past end of register")); | |
6472 | /* The instruction encoding stores the LSB and MSB, | |
6473 | not the LSB and width. */ | |
6474 | inst.instruction |= inst.operands[0].reg << 8; | |
6475 | inst.instruction |= inst.operands[1].reg << 16; | |
6476 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
6477 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
6478 | inst.instruction |= msb - 1; | |
b99bd4ef NC |
6479 | } |
6480 | ||
c19d1205 ZW |
6481 | static void |
6482 | do_t_bfx (void) | |
b99bd4ef | 6483 | { |
c19d1205 ZW |
6484 | constraint (inst.operands[2].imm + inst.operands[3].imm > 32, |
6485 | _("bit-field extends past end of register")); | |
6486 | inst.instruction |= inst.operands[0].reg << 8; | |
6487 | inst.instruction |= inst.operands[1].reg << 16; | |
6488 | inst.instruction |= (inst.operands[2].imm & 0x1c) << 10; | |
6489 | inst.instruction |= (inst.operands[2].imm & 0x03) << 6; | |
6490 | inst.instruction |= inst.operands[3].imm - 1; | |
6491 | } | |
b99bd4ef | 6492 | |
c19d1205 ZW |
6493 | /* ARM V5 Thumb BLX (argument parse) |
6494 | BLX <target_addr> which is BLX(1) | |
6495 | BLX <Rm> which is BLX(2) | |
6496 | Unfortunately, there are two different opcodes for this mnemonic. | |
6497 | So, the insns[].value is not used, and the code here zaps values | |
6498 | into inst.instruction. | |
b99bd4ef | 6499 | |
c19d1205 ZW |
6500 | ??? How to take advantage of the additional two bits of displacement |
6501 | available in Thumb32 mode? Need new relocation? */ | |
b99bd4ef | 6502 | |
c19d1205 ZW |
6503 | static void |
6504 | do_t_blx (void) | |
6505 | { | |
6506 | if (inst.operands[0].isreg) | |
6507 | /* We have a register, so this is BLX(2). */ | |
6508 | inst.instruction |= inst.operands[0].reg << 3; | |
b99bd4ef NC |
6509 | else |
6510 | { | |
c19d1205 | 6511 | /* No register. This must be BLX(1). */ |
2fc8bdac | 6512 | inst.instruction = 0xf000e800; |
39b41c9c PB |
6513 | #ifdef OBJ_ELF |
6514 | if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4) | |
6515 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; | |
6516 | else | |
6517 | #endif | |
6518 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX; | |
c19d1205 | 6519 | inst.reloc.pc_rel = 1; |
b99bd4ef NC |
6520 | } |
6521 | } | |
6522 | ||
c19d1205 ZW |
6523 | static void |
6524 | do_t_branch (void) | |
b99bd4ef | 6525 | { |
0110f2b8 PB |
6526 | int opcode; |
6527 | if (inst.cond != COND_ALWAYS) | |
6528 | opcode = T_MNEM_bcond; | |
6529 | else | |
6530 | opcode = inst.instruction; | |
6531 | ||
6532 | if (unified_syntax && inst.size_req == 4) | |
c19d1205 | 6533 | { |
0110f2b8 | 6534 | inst.instruction = THUMB_OP32(opcode); |
c19d1205 | 6535 | if (inst.cond == COND_ALWAYS) |
0110f2b8 | 6536 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25; |
c19d1205 ZW |
6537 | else |
6538 | { | |
6539 | assert (inst.cond != 0xF); | |
0110f2b8 | 6540 | inst.instruction |= inst.cond << 22; |
c19d1205 ZW |
6541 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20; |
6542 | } | |
6543 | } | |
b99bd4ef NC |
6544 | else |
6545 | { | |
0110f2b8 | 6546 | inst.instruction = THUMB_OP16(opcode); |
c19d1205 ZW |
6547 | if (inst.cond == COND_ALWAYS) |
6548 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
6549 | else | |
b99bd4ef | 6550 | { |
0110f2b8 | 6551 | inst.instruction |= inst.cond << 8; |
c19d1205 | 6552 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9; |
b99bd4ef | 6553 | } |
0110f2b8 PB |
6554 | /* Allow section relaxation. */ |
6555 | if (unified_syntax && inst.size_req != 2) | |
6556 | inst.relax = opcode; | |
b99bd4ef | 6557 | } |
c19d1205 ZW |
6558 | |
6559 | inst.reloc.pc_rel = 1; | |
b99bd4ef NC |
6560 | } |
6561 | ||
6562 | static void | |
c19d1205 | 6563 | do_t_bkpt (void) |
b99bd4ef | 6564 | { |
c19d1205 | 6565 | if (inst.operands[0].present) |
b99bd4ef | 6566 | { |
c19d1205 ZW |
6567 | constraint (inst.operands[0].imm > 255, |
6568 | _("immediate value out of range")); | |
6569 | inst.instruction |= inst.operands[0].imm; | |
b99bd4ef | 6570 | } |
b99bd4ef NC |
6571 | } |
6572 | ||
6573 | static void | |
c19d1205 | 6574 | do_t_branch23 (void) |
b99bd4ef | 6575 | { |
c19d1205 | 6576 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23; |
90e4755a RE |
6577 | inst.reloc.pc_rel = 1; |
6578 | ||
c19d1205 ZW |
6579 | /* If the destination of the branch is a defined symbol which does not have |
6580 | the THUMB_FUNC attribute, then we must be calling a function which has | |
6581 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
6582 | function and change the branch to refer to that function instead. */ | |
6583 | if ( inst.reloc.exp.X_op == O_symbol | |
6584 | && inst.reloc.exp.X_add_symbol != NULL | |
6585 | && S_IS_DEFINED (inst.reloc.exp.X_add_symbol) | |
6586 | && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol)) | |
6587 | inst.reloc.exp.X_add_symbol = | |
6588 | find_real_start (inst.reloc.exp.X_add_symbol); | |
90e4755a RE |
6589 | } |
6590 | ||
6591 | static void | |
c19d1205 | 6592 | do_t_bx (void) |
90e4755a | 6593 | { |
c19d1205 ZW |
6594 | inst.instruction |= inst.operands[0].reg << 3; |
6595 | /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc | |
6596 | should cause the alignment to be checked once it is known. This is | |
6597 | because BX PC only works if the instruction is word aligned. */ | |
6598 | } | |
90e4755a | 6599 | |
c19d1205 ZW |
6600 | static void |
6601 | do_t_bxj (void) | |
6602 | { | |
6603 | if (inst.operands[0].reg == REG_PC) | |
6604 | as_tsktsk (_("use of r15 in bxj is not really useful")); | |
90e4755a | 6605 | |
c19d1205 | 6606 | inst.instruction |= inst.operands[0].reg << 16; |
90e4755a RE |
6607 | } |
6608 | ||
6609 | static void | |
c19d1205 | 6610 | do_t_clz (void) |
90e4755a | 6611 | { |
c19d1205 ZW |
6612 | inst.instruction |= inst.operands[0].reg << 8; |
6613 | inst.instruction |= inst.operands[1].reg << 16; | |
6614 | inst.instruction |= inst.operands[1].reg; | |
6615 | } | |
90e4755a | 6616 | |
c19d1205 ZW |
6617 | static void |
6618 | do_t_cpsi (void) | |
6619 | { | |
6620 | if (unified_syntax | |
6621 | && (inst.operands[1].present || inst.size_req == 4)) | |
90e4755a | 6622 | { |
c19d1205 ZW |
6623 | unsigned int imod = (inst.instruction & 0x0030) >> 4; |
6624 | inst.instruction = 0xf3af8000; | |
6625 | inst.instruction |= imod << 9; | |
6626 | inst.instruction |= inst.operands[0].imm << 5; | |
6627 | if (inst.operands[1].present) | |
6628 | inst.instruction |= 0x100 | inst.operands[1].imm; | |
90e4755a | 6629 | } |
c19d1205 | 6630 | else |
90e4755a | 6631 | { |
c19d1205 ZW |
6632 | constraint (inst.operands[1].present, |
6633 | _("Thumb does not support the 2-argument " | |
6634 | "form of this instruction")); | |
6635 | inst.instruction |= inst.operands[0].imm; | |
90e4755a | 6636 | } |
90e4755a RE |
6637 | } |
6638 | ||
c19d1205 ZW |
6639 | /* THUMB CPY instruction (argument parse). */ |
6640 | ||
90e4755a | 6641 | static void |
c19d1205 | 6642 | do_t_cpy (void) |
90e4755a | 6643 | { |
c19d1205 | 6644 | if (inst.size_req == 4) |
90e4755a | 6645 | { |
c19d1205 ZW |
6646 | inst.instruction = THUMB_OP32 (T_MNEM_mov); |
6647 | inst.instruction |= inst.operands[0].reg << 8; | |
6648 | inst.instruction |= inst.operands[1].reg; | |
90e4755a | 6649 | } |
c19d1205 | 6650 | else |
90e4755a | 6651 | { |
c19d1205 ZW |
6652 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; |
6653 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
6654 | inst.instruction |= inst.operands[1].reg << 3; | |
90e4755a | 6655 | } |
90e4755a RE |
6656 | } |
6657 | ||
90e4755a | 6658 | static void |
c19d1205 | 6659 | do_t_czb (void) |
90e4755a | 6660 | { |
c19d1205 ZW |
6661 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
6662 | inst.instruction |= inst.operands[0].reg; | |
6663 | inst.reloc.pc_rel = 1; | |
6664 | inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7; | |
6665 | } | |
90e4755a | 6666 | |
c19d1205 ZW |
6667 | static void |
6668 | do_t_hint (void) | |
6669 | { | |
6670 | if (unified_syntax && inst.size_req == 4) | |
6671 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6672 | else | |
6673 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6674 | } | |
90e4755a | 6675 | |
c19d1205 ZW |
6676 | static void |
6677 | do_t_it (void) | |
6678 | { | |
6679 | unsigned int cond = inst.operands[0].imm; | |
e27ec89e PB |
6680 | |
6681 | current_it_mask = (inst.instruction & 0xf) | 0x10; | |
6682 | current_cc = cond; | |
6683 | ||
6684 | /* If the condition is a negative condition, invert the mask. */ | |
c19d1205 | 6685 | if ((cond & 0x1) == 0x0) |
90e4755a | 6686 | { |
c19d1205 | 6687 | unsigned int mask = inst.instruction & 0x000f; |
90e4755a | 6688 | |
c19d1205 ZW |
6689 | if ((mask & 0x7) == 0) |
6690 | /* no conversion needed */; | |
6691 | else if ((mask & 0x3) == 0) | |
e27ec89e PB |
6692 | mask ^= 0x8; |
6693 | else if ((mask & 0x1) == 0) | |
6694 | mask ^= 0xC; | |
c19d1205 | 6695 | else |
e27ec89e | 6696 | mask ^= 0xE; |
90e4755a | 6697 | |
e27ec89e PB |
6698 | inst.instruction &= 0xfff0; |
6699 | inst.instruction |= mask; | |
c19d1205 | 6700 | } |
90e4755a | 6701 | |
c19d1205 ZW |
6702 | inst.instruction |= cond << 4; |
6703 | } | |
90e4755a | 6704 | |
c19d1205 ZW |
6705 | static void |
6706 | do_t_ldmstm (void) | |
6707 | { | |
6708 | /* This really doesn't seem worth it. */ | |
6709 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
6710 | _("expression too complex")); | |
6711 | constraint (inst.operands[1].writeback, | |
6712 | _("Thumb load/store multiple does not support {reglist}^")); | |
90e4755a | 6713 | |
c19d1205 ZW |
6714 | if (unified_syntax) |
6715 | { | |
6716 | /* See if we can use a 16-bit instruction. */ | |
6717 | if (inst.instruction < 0xffff /* not ldmdb/stmdb */ | |
6718 | && inst.size_req != 4 | |
6719 | && inst.operands[0].reg <= 7 | |
6720 | && !(inst.operands[1].imm & ~0xff) | |
6721 | && (inst.instruction == T_MNEM_stmia | |
6722 | ? inst.operands[0].writeback | |
6723 | : (inst.operands[0].writeback | |
6724 | == !(inst.operands[1].imm & (1 << inst.operands[0].reg))))) | |
90e4755a | 6725 | { |
c19d1205 ZW |
6726 | if (inst.instruction == T_MNEM_stmia |
6727 | && (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6728 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
6729 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
6730 | inst.operands[0].reg); | |
90e4755a | 6731 | |
c19d1205 ZW |
6732 | inst.instruction = THUMB_OP16 (inst.instruction); |
6733 | inst.instruction |= inst.operands[0].reg << 8; | |
6734 | inst.instruction |= inst.operands[1].imm; | |
6735 | } | |
6736 | else | |
6737 | { | |
6738 | if (inst.operands[1].imm & (1 << 13)) | |
6739 | as_warn (_("SP should not be in register list")); | |
6740 | if (inst.instruction == T_MNEM_stmia) | |
90e4755a | 6741 | { |
c19d1205 ZW |
6742 | if (inst.operands[1].imm & (1 << 15)) |
6743 | as_warn (_("PC should not be in register list")); | |
6744 | if (inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6745 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
6746 | inst.operands[0].reg); | |
90e4755a RE |
6747 | } |
6748 | else | |
6749 | { | |
c19d1205 ZW |
6750 | if (inst.operands[1].imm & (1 << 14) |
6751 | && inst.operands[1].imm & (1 << 15)) | |
6752 | as_warn (_("LR and PC should not both be in register list")); | |
6753 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6754 | && inst.operands[0].writeback) | |
6755 | as_warn (_("base register should not be in register list " | |
6756 | "when written back")); | |
90e4755a | 6757 | } |
c19d1205 ZW |
6758 | if (inst.instruction < 0xffff) |
6759 | inst.instruction = THUMB_OP32 (inst.instruction); | |
6760 | inst.instruction |= inst.operands[0].reg << 16; | |
6761 | inst.instruction |= inst.operands[1].imm; | |
6762 | if (inst.operands[0].writeback) | |
6763 | inst.instruction |= WRITE_BACK; | |
90e4755a RE |
6764 | } |
6765 | } | |
c19d1205 | 6766 | else |
90e4755a | 6767 | { |
c19d1205 ZW |
6768 | constraint (inst.operands[0].reg > 7 |
6769 | || (inst.operands[1].imm & ~0xff), BAD_HIREG); | |
6770 | if (inst.instruction == T_MNEM_stmia) | |
f03698e6 | 6771 | { |
c19d1205 ZW |
6772 | if (!inst.operands[0].writeback) |
6773 | as_warn (_("this instruction will write back the base register")); | |
6774 | if ((inst.operands[1].imm & (1 << inst.operands[0].reg)) | |
6775 | && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1))) | |
6776 | as_warn (_("value stored for r%d is UNPREDICTABLE"), | |
6777 | inst.operands[0].reg); | |
f03698e6 | 6778 | } |
c19d1205 | 6779 | else |
90e4755a | 6780 | { |
c19d1205 ZW |
6781 | if (!inst.operands[0].writeback |
6782 | && !(inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
6783 | as_warn (_("this instruction will write back the base register")); | |
6784 | else if (inst.operands[0].writeback | |
6785 | && (inst.operands[1].imm & (1 << inst.operands[0].reg))) | |
6786 | as_warn (_("this instruction will not write back the base register")); | |
90e4755a RE |
6787 | } |
6788 | ||
c19d1205 ZW |
6789 | inst.instruction = THUMB_OP16 (inst.instruction); |
6790 | inst.instruction |= inst.operands[0].reg << 8; | |
6791 | inst.instruction |= inst.operands[1].imm; | |
6792 | } | |
6793 | } | |
e28cd48c | 6794 | |
c19d1205 ZW |
6795 | static void |
6796 | do_t_ldrex (void) | |
6797 | { | |
6798 | constraint (!inst.operands[1].isreg || !inst.operands[1].preind | |
6799 | || inst.operands[1].postind || inst.operands[1].writeback | |
6800 | || inst.operands[1].immisreg || inst.operands[1].shifted | |
6801 | || inst.operands[1].negative, | |
01cfc07f | 6802 | BAD_ADDR_MODE); |
e28cd48c | 6803 | |
c19d1205 ZW |
6804 | inst.instruction |= inst.operands[0].reg << 12; |
6805 | inst.instruction |= inst.operands[1].reg << 16; | |
6806 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
6807 | } | |
e28cd48c | 6808 | |
c19d1205 ZW |
6809 | static void |
6810 | do_t_ldrexd (void) | |
6811 | { | |
6812 | if (!inst.operands[1].present) | |
1cac9012 | 6813 | { |
c19d1205 ZW |
6814 | constraint (inst.operands[0].reg == REG_LR, |
6815 | _("r14 not allowed as first register " | |
6816 | "when second register is omitted")); | |
6817 | inst.operands[1].reg = inst.operands[0].reg + 1; | |
b99bd4ef | 6818 | } |
c19d1205 ZW |
6819 | constraint (inst.operands[0].reg == inst.operands[1].reg, |
6820 | BAD_OVERLAP); | |
b99bd4ef | 6821 | |
c19d1205 ZW |
6822 | inst.instruction |= inst.operands[0].reg << 12; |
6823 | inst.instruction |= inst.operands[1].reg << 8; | |
6824 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef NC |
6825 | } |
6826 | ||
6827 | static void | |
c19d1205 | 6828 | do_t_ldst (void) |
b99bd4ef | 6829 | { |
0110f2b8 PB |
6830 | unsigned long opcode; |
6831 | int Rn; | |
6832 | ||
6833 | opcode = inst.instruction; | |
c19d1205 | 6834 | if (unified_syntax) |
b99bd4ef | 6835 | { |
0110f2b8 PB |
6836 | if (inst.operands[1].isreg |
6837 | && !inst.operands[1].writeback | |
c19d1205 ZW |
6838 | && !inst.operands[1].shifted && !inst.operands[1].postind |
6839 | && !inst.operands[1].negative && inst.operands[0].reg <= 7 | |
0110f2b8 PB |
6840 | && opcode <= 0xffff |
6841 | && inst.size_req != 4) | |
c19d1205 | 6842 | { |
0110f2b8 PB |
6843 | /* Insn may have a 16-bit form. */ |
6844 | Rn = inst.operands[1].reg; | |
6845 | if (inst.operands[1].immisreg) | |
6846 | { | |
6847 | inst.instruction = THUMB_OP16 (opcode); | |
6848 | /* [Rn, Ri] */ | |
6849 | if (Rn <= 7 && inst.operands[1].imm <= 7) | |
6850 | goto op16; | |
6851 | } | |
6852 | else if ((Rn <= 7 && opcode != T_MNEM_ldrsh | |
6853 | && opcode != T_MNEM_ldrsb) | |
6854 | || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr) | |
6855 | || (Rn == REG_SP && opcode == T_MNEM_str)) | |
6856 | { | |
6857 | /* [Rn, #const] */ | |
6858 | if (Rn > 7) | |
6859 | { | |
6860 | if (Rn == REG_PC) | |
6861 | { | |
6862 | if (inst.reloc.pc_rel) | |
6863 | opcode = T_MNEM_ldr_pc2; | |
6864 | else | |
6865 | opcode = T_MNEM_ldr_pc; | |
6866 | } | |
6867 | else | |
6868 | { | |
6869 | if (opcode == T_MNEM_ldr) | |
6870 | opcode = T_MNEM_ldr_sp; | |
6871 | else | |
6872 | opcode = T_MNEM_str_sp; | |
6873 | } | |
6874 | inst.instruction = inst.operands[0].reg << 8; | |
6875 | } | |
6876 | else | |
6877 | { | |
6878 | inst.instruction = inst.operands[0].reg; | |
6879 | inst.instruction |= inst.operands[1].reg << 3; | |
6880 | } | |
6881 | inst.instruction |= THUMB_OP16 (opcode); | |
6882 | if (inst.size_req == 2) | |
6883 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
6884 | else | |
6885 | inst.relax = opcode; | |
6886 | return; | |
6887 | } | |
c19d1205 | 6888 | } |
0110f2b8 PB |
6889 | /* Definitely a 32-bit variant. */ |
6890 | inst.instruction = THUMB_OP32 (opcode); | |
c19d1205 ZW |
6891 | inst.instruction |= inst.operands[0].reg << 12; |
6892 | encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
b99bd4ef NC |
6893 | return; |
6894 | } | |
6895 | ||
c19d1205 ZW |
6896 | constraint (inst.operands[0].reg > 7, BAD_HIREG); |
6897 | ||
6898 | if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb) | |
b99bd4ef | 6899 | { |
c19d1205 ZW |
6900 | /* Only [Rn,Rm] is acceptable. */ |
6901 | constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG); | |
6902 | constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg | |
6903 | || inst.operands[1].postind || inst.operands[1].shifted | |
6904 | || inst.operands[1].negative, | |
6905 | _("Thumb does not support this addressing mode")); | |
6906 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6907 | goto op16; | |
b99bd4ef | 6908 | } |
c19d1205 ZW |
6909 | |
6910 | inst.instruction = THUMB_OP16 (inst.instruction); | |
6911 | if (!inst.operands[1].isreg) | |
6912 | if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE)) | |
6913 | return; | |
b99bd4ef | 6914 | |
c19d1205 ZW |
6915 | constraint (!inst.operands[1].preind |
6916 | || inst.operands[1].shifted | |
6917 | || inst.operands[1].writeback, | |
6918 | _("Thumb does not support this addressing mode")); | |
6919 | if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP) | |
90e4755a | 6920 | { |
c19d1205 ZW |
6921 | constraint (inst.instruction & 0x0600, |
6922 | _("byte or halfword not valid for base register")); | |
6923 | constraint (inst.operands[1].reg == REG_PC | |
6924 | && !(inst.instruction & THUMB_LOAD_BIT), | |
6925 | _("r15 based store not allowed")); | |
6926 | constraint (inst.operands[1].immisreg, | |
6927 | _("invalid base register for register offset")); | |
b99bd4ef | 6928 | |
c19d1205 ZW |
6929 | if (inst.operands[1].reg == REG_PC) |
6930 | inst.instruction = T_OPCODE_LDR_PC; | |
6931 | else if (inst.instruction & THUMB_LOAD_BIT) | |
6932 | inst.instruction = T_OPCODE_LDR_SP; | |
6933 | else | |
6934 | inst.instruction = T_OPCODE_STR_SP; | |
b99bd4ef | 6935 | |
c19d1205 ZW |
6936 | inst.instruction |= inst.operands[0].reg << 8; |
6937 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
6938 | return; | |
6939 | } | |
90e4755a | 6940 | |
c19d1205 ZW |
6941 | constraint (inst.operands[1].reg > 7, BAD_HIREG); |
6942 | if (!inst.operands[1].immisreg) | |
6943 | { | |
6944 | /* Immediate offset. */ | |
6945 | inst.instruction |= inst.operands[0].reg; | |
6946 | inst.instruction |= inst.operands[1].reg << 3; | |
6947 | inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET; | |
6948 | return; | |
6949 | } | |
90e4755a | 6950 | |
c19d1205 ZW |
6951 | /* Register offset. */ |
6952 | constraint (inst.operands[1].imm > 7, BAD_HIREG); | |
6953 | constraint (inst.operands[1].negative, | |
6954 | _("Thumb does not support this addressing mode")); | |
90e4755a | 6955 | |
c19d1205 ZW |
6956 | op16: |
6957 | switch (inst.instruction) | |
6958 | { | |
6959 | case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break; | |
6960 | case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break; | |
6961 | case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break; | |
6962 | case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break; | |
6963 | case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break; | |
6964 | case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break; | |
6965 | case 0x5600 /* ldrsb */: | |
6966 | case 0x5e00 /* ldrsh */: break; | |
6967 | default: abort (); | |
6968 | } | |
90e4755a | 6969 | |
c19d1205 ZW |
6970 | inst.instruction |= inst.operands[0].reg; |
6971 | inst.instruction |= inst.operands[1].reg << 3; | |
6972 | inst.instruction |= inst.operands[1].imm << 6; | |
6973 | } | |
90e4755a | 6974 | |
c19d1205 ZW |
6975 | static void |
6976 | do_t_ldstd (void) | |
6977 | { | |
6978 | if (!inst.operands[1].present) | |
b99bd4ef | 6979 | { |
c19d1205 ZW |
6980 | inst.operands[1].reg = inst.operands[0].reg + 1; |
6981 | constraint (inst.operands[0].reg == REG_LR, | |
6982 | _("r14 not allowed here")); | |
b99bd4ef | 6983 | } |
c19d1205 ZW |
6984 | inst.instruction |= inst.operands[0].reg << 12; |
6985 | inst.instruction |= inst.operands[1].reg << 8; | |
6986 | encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE); | |
6987 | ||
b99bd4ef NC |
6988 | } |
6989 | ||
c19d1205 ZW |
6990 | static void |
6991 | do_t_ldstt (void) | |
6992 | { | |
6993 | inst.instruction |= inst.operands[0].reg << 12; | |
6994 | encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE); | |
6995 | } | |
a737bd4d | 6996 | |
b99bd4ef | 6997 | static void |
c19d1205 | 6998 | do_t_mla (void) |
b99bd4ef | 6999 | { |
c19d1205 ZW |
7000 | inst.instruction |= inst.operands[0].reg << 8; |
7001 | inst.instruction |= inst.operands[1].reg << 16; | |
7002 | inst.instruction |= inst.operands[2].reg; | |
7003 | inst.instruction |= inst.operands[3].reg << 12; | |
7004 | } | |
b99bd4ef | 7005 | |
c19d1205 ZW |
7006 | static void |
7007 | do_t_mlal (void) | |
7008 | { | |
7009 | inst.instruction |= inst.operands[0].reg << 12; | |
7010 | inst.instruction |= inst.operands[1].reg << 8; | |
7011 | inst.instruction |= inst.operands[2].reg << 16; | |
7012 | inst.instruction |= inst.operands[3].reg; | |
7013 | } | |
b99bd4ef | 7014 | |
c19d1205 ZW |
7015 | static void |
7016 | do_t_mov_cmp (void) | |
7017 | { | |
7018 | if (unified_syntax) | |
b99bd4ef | 7019 | { |
c19d1205 ZW |
7020 | int r0off = (inst.instruction == T_MNEM_mov |
7021 | || inst.instruction == T_MNEM_movs) ? 8 : 16; | |
0110f2b8 | 7022 | unsigned long opcode; |
3d388997 PB |
7023 | bfd_boolean narrow; |
7024 | bfd_boolean low_regs; | |
7025 | ||
7026 | low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7); | |
0110f2b8 | 7027 | opcode = inst.instruction; |
3d388997 | 7028 | if (current_it_mask) |
0110f2b8 | 7029 | narrow = opcode != T_MNEM_movs; |
3d388997 | 7030 | else |
0110f2b8 | 7031 | narrow = opcode != T_MNEM_movs || low_regs; |
3d388997 PB |
7032 | if (inst.size_req == 4 |
7033 | || inst.operands[1].shifted) | |
7034 | narrow = FALSE; | |
7035 | ||
c19d1205 ZW |
7036 | if (!inst.operands[1].isreg) |
7037 | { | |
0110f2b8 PB |
7038 | /* Immediate operand. */ |
7039 | if (current_it_mask == 0 && opcode == T_MNEM_mov) | |
7040 | narrow = 0; | |
7041 | if (low_regs && narrow) | |
7042 | { | |
7043 | inst.instruction = THUMB_OP16 (opcode); | |
7044 | inst.instruction |= inst.operands[0].reg << 8; | |
7045 | if (inst.size_req == 2) | |
7046 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
7047 | else | |
7048 | inst.relax = opcode; | |
7049 | } | |
7050 | else | |
7051 | { | |
7052 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7053 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
7054 | inst.instruction |= inst.operands[0].reg << r0off; | |
7055 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
7056 | } | |
c19d1205 | 7057 | } |
3d388997 | 7058 | else if (!narrow) |
c19d1205 ZW |
7059 | { |
7060 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7061 | inst.instruction |= inst.operands[0].reg << r0off; | |
7062 | encode_thumb32_shifted_operand (1); | |
7063 | } | |
7064 | else | |
7065 | switch (inst.instruction) | |
7066 | { | |
7067 | case T_MNEM_mov: | |
7068 | inst.instruction = T_OPCODE_MOV_HR; | |
7069 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
7070 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
7071 | inst.instruction |= inst.operands[1].reg << 3; | |
7072 | break; | |
b99bd4ef | 7073 | |
c19d1205 ZW |
7074 | case T_MNEM_movs: |
7075 | /* We know we have low registers at this point. | |
7076 | Generate ADD Rd, Rs, #0. */ | |
7077 | inst.instruction = T_OPCODE_ADD_I3; | |
7078 | inst.instruction |= inst.operands[0].reg; | |
7079 | inst.instruction |= inst.operands[1].reg << 3; | |
7080 | break; | |
7081 | ||
7082 | case T_MNEM_cmp: | |
3d388997 | 7083 | if (low_regs) |
c19d1205 ZW |
7084 | { |
7085 | inst.instruction = T_OPCODE_CMP_LR; | |
7086 | inst.instruction |= inst.operands[0].reg; | |
7087 | inst.instruction |= inst.operands[1].reg << 3; | |
7088 | } | |
7089 | else | |
7090 | { | |
7091 | inst.instruction = T_OPCODE_CMP_HR; | |
7092 | inst.instruction |= (inst.operands[0].reg & 0x8) << 4; | |
7093 | inst.instruction |= (inst.operands[0].reg & 0x7); | |
7094 | inst.instruction |= inst.operands[1].reg << 3; | |
7095 | } | |
7096 | break; | |
7097 | } | |
b99bd4ef NC |
7098 | return; |
7099 | } | |
7100 | ||
c19d1205 ZW |
7101 | inst.instruction = THUMB_OP16 (inst.instruction); |
7102 | if (inst.operands[1].isreg) | |
b99bd4ef | 7103 | { |
c19d1205 | 7104 | if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8) |
b99bd4ef | 7105 | { |
c19d1205 ZW |
7106 | /* A move of two lowregs is encoded as ADD Rd, Rs, #0 |
7107 | since a MOV instruction produces unpredictable results. */ | |
7108 | if (inst.instruction == T_OPCODE_MOV_I8) | |
7109 | inst.instruction = T_OPCODE_ADD_I3; | |
b99bd4ef | 7110 | else |
c19d1205 | 7111 | inst.instruction = T_OPCODE_CMP_LR; |
b99bd4ef | 7112 | |
c19d1205 ZW |
7113 | inst.instruction |= inst.operands[0].reg; |
7114 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
7115 | } |
7116 | else | |
7117 | { | |
c19d1205 ZW |
7118 | if (inst.instruction == T_OPCODE_MOV_I8) |
7119 | inst.instruction = T_OPCODE_MOV_HR; | |
7120 | else | |
7121 | inst.instruction = T_OPCODE_CMP_HR; | |
7122 | do_t_cpy (); | |
b99bd4ef NC |
7123 | } |
7124 | } | |
c19d1205 | 7125 | else |
b99bd4ef | 7126 | { |
c19d1205 ZW |
7127 | constraint (inst.operands[0].reg > 7, |
7128 | _("only lo regs allowed with immediate")); | |
7129 | inst.instruction |= inst.operands[0].reg << 8; | |
7130 | inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM; | |
7131 | } | |
7132 | } | |
b99bd4ef | 7133 | |
c19d1205 ZW |
7134 | static void |
7135 | do_t_mov16 (void) | |
7136 | { | |
7137 | inst.instruction |= inst.operands[0].reg << 8; | |
7138 | inst.instruction |= (inst.operands[1].imm & 0xf000) << 4; | |
7139 | inst.instruction |= (inst.operands[1].imm & 0x0800) << 15; | |
7140 | inst.instruction |= (inst.operands[1].imm & 0x0700) << 4; | |
7141 | inst.instruction |= (inst.operands[1].imm & 0x00ff); | |
7142 | } | |
b99bd4ef | 7143 | |
c19d1205 ZW |
7144 | static void |
7145 | do_t_mvn_tst (void) | |
7146 | { | |
7147 | if (unified_syntax) | |
7148 | { | |
7149 | int r0off = (inst.instruction == T_MNEM_mvn | |
7150 | || inst.instruction == T_MNEM_mvns) ? 8 : 16; | |
3d388997 PB |
7151 | bfd_boolean narrow; |
7152 | ||
7153 | if (inst.size_req == 4 | |
7154 | || inst.instruction > 0xffff | |
7155 | || inst.operands[1].shifted | |
7156 | || inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
7157 | narrow = FALSE; | |
7158 | else if (inst.instruction == T_MNEM_cmn) | |
7159 | narrow = TRUE; | |
7160 | else if (THUMB_SETS_FLAGS (inst.instruction)) | |
7161 | narrow = (current_it_mask == 0); | |
7162 | else | |
7163 | narrow = (current_it_mask != 0); | |
7164 | ||
c19d1205 | 7165 | if (!inst.operands[1].isreg) |
b99bd4ef | 7166 | { |
c19d1205 ZW |
7167 | /* For an immediate, we always generate a 32-bit opcode; |
7168 | section relaxation will shrink it later if possible. */ | |
7169 | if (inst.instruction < 0xffff) | |
7170 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7171 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
7172 | inst.instruction |= inst.operands[0].reg << r0off; | |
7173 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
b99bd4ef | 7174 | } |
c19d1205 | 7175 | else |
b99bd4ef | 7176 | { |
c19d1205 | 7177 | /* See if we can do this with a 16-bit instruction. */ |
3d388997 | 7178 | if (narrow) |
b99bd4ef | 7179 | { |
c19d1205 ZW |
7180 | inst.instruction = THUMB_OP16 (inst.instruction); |
7181 | inst.instruction |= inst.operands[0].reg; | |
7182 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 7183 | } |
c19d1205 | 7184 | else |
b99bd4ef | 7185 | { |
c19d1205 ZW |
7186 | constraint (inst.operands[1].shifted |
7187 | && inst.operands[1].immisreg, | |
7188 | _("shift must be constant")); | |
7189 | if (inst.instruction < 0xffff) | |
7190 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7191 | inst.instruction |= inst.operands[0].reg << r0off; | |
7192 | encode_thumb32_shifted_operand (1); | |
b99bd4ef | 7193 | } |
b99bd4ef NC |
7194 | } |
7195 | } | |
7196 | else | |
7197 | { | |
c19d1205 ZW |
7198 | constraint (inst.instruction > 0xffff |
7199 | || inst.instruction == T_MNEM_mvns, BAD_THUMB32); | |
7200 | constraint (!inst.operands[1].isreg || inst.operands[1].shifted, | |
7201 | _("unshifted register required")); | |
7202 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
7203 | BAD_HIREG); | |
b99bd4ef | 7204 | |
c19d1205 ZW |
7205 | inst.instruction = THUMB_OP16 (inst.instruction); |
7206 | inst.instruction |= inst.operands[0].reg; | |
7207 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 7208 | } |
b99bd4ef NC |
7209 | } |
7210 | ||
b05fe5cf | 7211 | static void |
c19d1205 | 7212 | do_t_mrs (void) |
b05fe5cf | 7213 | { |
c19d1205 ZW |
7214 | /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */ |
7215 | constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f)) | |
7216 | != (PSR_c|PSR_f), | |
7217 | _("'CPSR' or 'SPSR' expected")); | |
7218 | inst.instruction |= inst.operands[0].reg << 8; | |
7219 | inst.instruction |= (inst.operands[1].imm & SPSR_BIT) >> 2; | |
7220 | } | |
b05fe5cf | 7221 | |
c19d1205 ZW |
7222 | static void |
7223 | do_t_msr (void) | |
7224 | { | |
7225 | constraint (!inst.operands[1].isreg, | |
7226 | _("Thumb encoding does not support an immediate here")); | |
7227 | inst.instruction |= (inst.operands[0].imm & SPSR_BIT) >> 2; | |
7228 | inst.instruction |= (inst.operands[0].imm & ~SPSR_BIT) >> 8; | |
7229 | inst.instruction |= inst.operands[1].reg << 16; | |
7230 | } | |
b05fe5cf | 7231 | |
c19d1205 ZW |
7232 | static void |
7233 | do_t_mul (void) | |
7234 | { | |
7235 | if (!inst.operands[2].present) | |
7236 | inst.operands[2].reg = inst.operands[0].reg; | |
b05fe5cf | 7237 | |
c19d1205 ZW |
7238 | /* There is no 32-bit MULS and no 16-bit MUL. */ |
7239 | if (unified_syntax && inst.instruction == T_MNEM_mul) | |
b05fe5cf | 7240 | { |
c19d1205 ZW |
7241 | inst.instruction = THUMB_OP32 (inst.instruction); |
7242 | inst.instruction |= inst.operands[0].reg << 8; | |
7243 | inst.instruction |= inst.operands[1].reg << 16; | |
7244 | inst.instruction |= inst.operands[2].reg << 0; | |
b05fe5cf | 7245 | } |
c19d1205 | 7246 | else |
b05fe5cf | 7247 | { |
c19d1205 ZW |
7248 | constraint (!unified_syntax |
7249 | && inst.instruction == T_MNEM_muls, BAD_THUMB32); | |
7250 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, | |
7251 | BAD_HIREG); | |
b05fe5cf | 7252 | |
c19d1205 ZW |
7253 | inst.instruction = THUMB_OP16 (inst.instruction); |
7254 | inst.instruction |= inst.operands[0].reg; | |
b05fe5cf | 7255 | |
c19d1205 ZW |
7256 | if (inst.operands[0].reg == inst.operands[1].reg) |
7257 | inst.instruction |= inst.operands[2].reg << 3; | |
7258 | else if (inst.operands[0].reg == inst.operands[2].reg) | |
7259 | inst.instruction |= inst.operands[1].reg << 3; | |
7260 | else | |
7261 | constraint (1, _("dest must overlap one source register")); | |
7262 | } | |
7263 | } | |
b05fe5cf | 7264 | |
c19d1205 ZW |
7265 | static void |
7266 | do_t_mull (void) | |
7267 | { | |
7268 | inst.instruction |= inst.operands[0].reg << 12; | |
7269 | inst.instruction |= inst.operands[1].reg << 8; | |
7270 | inst.instruction |= inst.operands[2].reg << 16; | |
7271 | inst.instruction |= inst.operands[3].reg; | |
b05fe5cf | 7272 | |
c19d1205 ZW |
7273 | if (inst.operands[0].reg == inst.operands[1].reg) |
7274 | as_tsktsk (_("rdhi and rdlo must be different")); | |
7275 | } | |
b05fe5cf | 7276 | |
c19d1205 ZW |
7277 | static void |
7278 | do_t_nop (void) | |
7279 | { | |
7280 | if (unified_syntax) | |
7281 | { | |
7282 | if (inst.size_req == 4 || inst.operands[0].imm > 15) | |
b05fe5cf | 7283 | { |
c19d1205 ZW |
7284 | inst.instruction = THUMB_OP32 (inst.instruction); |
7285 | inst.instruction |= inst.operands[0].imm; | |
7286 | } | |
7287 | else | |
7288 | { | |
7289 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7290 | inst.instruction |= inst.operands[0].imm << 4; | |
7291 | } | |
7292 | } | |
7293 | else | |
7294 | { | |
7295 | constraint (inst.operands[0].present, | |
7296 | _("Thumb does not support NOP with hints")); | |
7297 | inst.instruction = 0x46c0; | |
7298 | } | |
7299 | } | |
b05fe5cf | 7300 | |
c19d1205 ZW |
7301 | static void |
7302 | do_t_neg (void) | |
7303 | { | |
7304 | if (unified_syntax) | |
7305 | { | |
3d388997 PB |
7306 | bfd_boolean narrow; |
7307 | ||
7308 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
7309 | narrow = (current_it_mask == 0); | |
7310 | else | |
7311 | narrow = (current_it_mask != 0); | |
7312 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
7313 | narrow = FALSE; | |
7314 | if (inst.size_req == 4) | |
7315 | narrow = FALSE; | |
7316 | ||
7317 | if (!narrow) | |
c19d1205 ZW |
7318 | { |
7319 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7320 | inst.instruction |= inst.operands[0].reg << 8; | |
7321 | inst.instruction |= inst.operands[1].reg << 16; | |
b05fe5cf ZW |
7322 | } |
7323 | else | |
7324 | { | |
c19d1205 ZW |
7325 | inst.instruction = THUMB_OP16 (inst.instruction); |
7326 | inst.instruction |= inst.operands[0].reg; | |
7327 | inst.instruction |= inst.operands[1].reg << 3; | |
b05fe5cf ZW |
7328 | } |
7329 | } | |
7330 | else | |
7331 | { | |
c19d1205 ZW |
7332 | constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7, |
7333 | BAD_HIREG); | |
7334 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
7335 | ||
7336 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7337 | inst.instruction |= inst.operands[0].reg; | |
7338 | inst.instruction |= inst.operands[1].reg << 3; | |
7339 | } | |
7340 | } | |
7341 | ||
7342 | static void | |
7343 | do_t_pkhbt (void) | |
7344 | { | |
7345 | inst.instruction |= inst.operands[0].reg << 8; | |
7346 | inst.instruction |= inst.operands[1].reg << 16; | |
7347 | inst.instruction |= inst.operands[2].reg; | |
7348 | if (inst.operands[3].present) | |
7349 | { | |
7350 | unsigned int val = inst.reloc.exp.X_add_number; | |
7351 | constraint (inst.reloc.exp.X_op != O_constant, | |
7352 | _("expression too complex")); | |
7353 | inst.instruction |= (val & 0x1c) << 10; | |
7354 | inst.instruction |= (val & 0x03) << 6; | |
b05fe5cf | 7355 | } |
c19d1205 | 7356 | } |
b05fe5cf | 7357 | |
c19d1205 ZW |
7358 | static void |
7359 | do_t_pkhtb (void) | |
7360 | { | |
7361 | if (!inst.operands[3].present) | |
7362 | inst.instruction &= ~0x00000020; | |
7363 | do_t_pkhbt (); | |
b05fe5cf ZW |
7364 | } |
7365 | ||
c19d1205 ZW |
7366 | static void |
7367 | do_t_pld (void) | |
7368 | { | |
7369 | encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE); | |
7370 | } | |
b05fe5cf | 7371 | |
c19d1205 ZW |
7372 | static void |
7373 | do_t_push_pop (void) | |
b99bd4ef | 7374 | { |
e9f89963 PB |
7375 | unsigned mask; |
7376 | ||
c19d1205 ZW |
7377 | constraint (inst.operands[0].writeback, |
7378 | _("push/pop do not support {reglist}^")); | |
7379 | constraint (inst.reloc.type != BFD_RELOC_UNUSED, | |
7380 | _("expression too complex")); | |
b99bd4ef | 7381 | |
e9f89963 PB |
7382 | mask = inst.operands[0].imm; |
7383 | if ((mask & ~0xff) == 0) | |
c19d1205 ZW |
7384 | inst.instruction = THUMB_OP16 (inst.instruction); |
7385 | else if ((inst.instruction == T_MNEM_push | |
e9f89963 | 7386 | && (mask & ~0xff) == 1 << REG_LR) |
c19d1205 | 7387 | || (inst.instruction == T_MNEM_pop |
e9f89963 | 7388 | && (mask & ~0xff) == 1 << REG_PC)) |
b99bd4ef | 7389 | { |
c19d1205 ZW |
7390 | inst.instruction = THUMB_OP16 (inst.instruction); |
7391 | inst.instruction |= THUMB_PP_PC_LR; | |
e9f89963 | 7392 | mask &= 0xff; |
c19d1205 ZW |
7393 | } |
7394 | else if (unified_syntax) | |
7395 | { | |
e9f89963 PB |
7396 | if (mask & (1 << 13)) |
7397 | inst.error = _("SP not allowed in register list"); | |
c19d1205 | 7398 | if (inst.instruction == T_MNEM_push) |
b99bd4ef | 7399 | { |
e9f89963 PB |
7400 | if (mask & (1 << 15)) |
7401 | inst.error = _("PC not allowed in register list"); | |
c19d1205 ZW |
7402 | } |
7403 | else | |
7404 | { | |
e9f89963 PB |
7405 | if (mask & (1 << 14) |
7406 | && mask & (1 << 15)) | |
7407 | inst.error = _("LR and PC should not both be in register list"); | |
c19d1205 | 7408 | } |
e9f89963 PB |
7409 | if ((mask & (mask - 1)) == 0) |
7410 | { | |
7411 | /* Single register push/pop implemented as str/ldr. */ | |
7412 | if (inst.instruction == T_MNEM_push) | |
7413 | inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */ | |
7414 | else | |
7415 | inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */ | |
7416 | mask = ffs(mask) - 1; | |
7417 | mask <<= 12; | |
7418 | } | |
7419 | else | |
7420 | inst.instruction = THUMB_OP32 (inst.instruction); | |
c19d1205 ZW |
7421 | } |
7422 | else | |
7423 | { | |
7424 | inst.error = _("invalid register list to push/pop instruction"); | |
7425 | return; | |
7426 | } | |
b99bd4ef | 7427 | |
e9f89963 | 7428 | inst.instruction |= mask; |
c19d1205 | 7429 | } |
b99bd4ef | 7430 | |
c19d1205 ZW |
7431 | static void |
7432 | do_t_rbit (void) | |
7433 | { | |
7434 | inst.instruction |= inst.operands[0].reg << 8; | |
7435 | inst.instruction |= inst.operands[1].reg << 16; | |
7436 | } | |
b99bd4ef | 7437 | |
c19d1205 ZW |
7438 | static void |
7439 | do_t_rev (void) | |
7440 | { | |
7441 | if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
7442 | && inst.size_req != 4) | |
7443 | { | |
7444 | inst.instruction = THUMB_OP16 (inst.instruction); | |
7445 | inst.instruction |= inst.operands[0].reg; | |
7446 | inst.instruction |= inst.operands[1].reg << 3; | |
7447 | } | |
7448 | else if (unified_syntax) | |
7449 | { | |
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[1].reg; | |
7454 | } | |
7455 | else | |
7456 | inst.error = BAD_HIREG; | |
7457 | } | |
b99bd4ef | 7458 | |
c19d1205 ZW |
7459 | static void |
7460 | do_t_rsb (void) | |
7461 | { | |
7462 | int Rd, Rs; | |
b99bd4ef | 7463 | |
c19d1205 ZW |
7464 | Rd = inst.operands[0].reg; |
7465 | Rs = (inst.operands[1].present | |
7466 | ? inst.operands[1].reg /* Rd, Rs, foo */ | |
7467 | : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */ | |
b99bd4ef | 7468 | |
c19d1205 ZW |
7469 | inst.instruction |= Rd << 8; |
7470 | inst.instruction |= Rs << 16; | |
7471 | if (!inst.operands[2].isreg) | |
7472 | { | |
7473 | inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000; | |
7474 | inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
7475 | } | |
7476 | else | |
7477 | encode_thumb32_shifted_operand (2); | |
7478 | } | |
b99bd4ef | 7479 | |
c19d1205 ZW |
7480 | static void |
7481 | do_t_setend (void) | |
7482 | { | |
7483 | if (inst.operands[0].imm) | |
7484 | inst.instruction |= 0x8; | |
7485 | } | |
b99bd4ef | 7486 | |
c19d1205 ZW |
7487 | static void |
7488 | do_t_shift (void) | |
7489 | { | |
7490 | if (!inst.operands[1].present) | |
7491 | inst.operands[1].reg = inst.operands[0].reg; | |
7492 | ||
7493 | if (unified_syntax) | |
7494 | { | |
3d388997 PB |
7495 | bfd_boolean narrow; |
7496 | int shift_kind; | |
7497 | ||
7498 | switch (inst.instruction) | |
7499 | { | |
7500 | case T_MNEM_asr: | |
7501 | case T_MNEM_asrs: shift_kind = SHIFT_ASR; break; | |
7502 | case T_MNEM_lsl: | |
7503 | case T_MNEM_lsls: shift_kind = SHIFT_LSL; break; | |
7504 | case T_MNEM_lsr: | |
7505 | case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break; | |
7506 | case T_MNEM_ror: | |
7507 | case T_MNEM_rors: shift_kind = SHIFT_ROR; break; | |
7508 | default: abort (); | |
7509 | } | |
7510 | ||
7511 | if (THUMB_SETS_FLAGS (inst.instruction)) | |
7512 | narrow = (current_it_mask == 0); | |
7513 | else | |
7514 | narrow = (current_it_mask != 0); | |
7515 | if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7) | |
7516 | narrow = FALSE; | |
7517 | if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR) | |
7518 | narrow = FALSE; | |
7519 | if (inst.operands[2].isreg | |
7520 | && (inst.operands[1].reg != inst.operands[0].reg | |
7521 | || inst.operands[2].reg > 7)) | |
7522 | narrow = FALSE; | |
7523 | if (inst.size_req == 4) | |
7524 | narrow = FALSE; | |
7525 | ||
7526 | if (!narrow) | |
c19d1205 ZW |
7527 | { |
7528 | if (inst.operands[2].isreg) | |
b99bd4ef | 7529 | { |
c19d1205 ZW |
7530 | inst.instruction = THUMB_OP32 (inst.instruction); |
7531 | inst.instruction |= inst.operands[0].reg << 8; | |
7532 | inst.instruction |= inst.operands[1].reg << 16; | |
7533 | inst.instruction |= inst.operands[2].reg; | |
7534 | } | |
7535 | else | |
7536 | { | |
7537 | inst.operands[1].shifted = 1; | |
3d388997 | 7538 | inst.operands[1].shift_kind = shift_kind; |
c19d1205 ZW |
7539 | inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction) |
7540 | ? T_MNEM_movs : T_MNEM_mov); | |
7541 | inst.instruction |= inst.operands[0].reg << 8; | |
7542 | encode_thumb32_shifted_operand (1); | |
7543 | /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */ | |
7544 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef NC |
7545 | } |
7546 | } | |
7547 | else | |
7548 | { | |
c19d1205 | 7549 | if (inst.operands[2].isreg) |
b99bd4ef | 7550 | { |
3d388997 | 7551 | switch (shift_kind) |
b99bd4ef | 7552 | { |
3d388997 PB |
7553 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break; |
7554 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break; | |
7555 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break; | |
7556 | case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break; | |
c19d1205 | 7557 | default: abort (); |
b99bd4ef | 7558 | } |
c19d1205 ZW |
7559 | |
7560 | inst.instruction |= inst.operands[0].reg; | |
7561 | inst.instruction |= inst.operands[2].reg << 3; | |
b99bd4ef NC |
7562 | } |
7563 | else | |
7564 | { | |
3d388997 | 7565 | switch (shift_kind) |
b99bd4ef | 7566 | { |
3d388997 PB |
7567 | case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break; |
7568 | case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break; | |
7569 | case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break; | |
c19d1205 | 7570 | default: abort (); |
b99bd4ef | 7571 | } |
c19d1205 ZW |
7572 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; |
7573 | inst.instruction |= inst.operands[0].reg; | |
7574 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
7575 | } |
7576 | } | |
c19d1205 ZW |
7577 | } |
7578 | else | |
7579 | { | |
7580 | constraint (inst.operands[0].reg > 7 | |
7581 | || inst.operands[1].reg > 7, BAD_HIREG); | |
7582 | constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32); | |
b99bd4ef | 7583 | |
c19d1205 ZW |
7584 | if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */ |
7585 | { | |
7586 | constraint (inst.operands[2].reg > 7, BAD_HIREG); | |
7587 | constraint (inst.operands[0].reg != inst.operands[1].reg, | |
7588 | _("source1 and dest must be same register")); | |
b99bd4ef | 7589 | |
c19d1205 ZW |
7590 | switch (inst.instruction) |
7591 | { | |
7592 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break; | |
7593 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break; | |
7594 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break; | |
7595 | case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break; | |
7596 | default: abort (); | |
7597 | } | |
7598 | ||
7599 | inst.instruction |= inst.operands[0].reg; | |
7600 | inst.instruction |= inst.operands[2].reg << 3; | |
7601 | } | |
7602 | else | |
b99bd4ef | 7603 | { |
c19d1205 ZW |
7604 | switch (inst.instruction) |
7605 | { | |
7606 | case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break; | |
7607 | case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break; | |
7608 | case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break; | |
7609 | case T_MNEM_ror: inst.error = _("ror #imm not supported"); return; | |
7610 | default: abort (); | |
7611 | } | |
7612 | inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT; | |
7613 | inst.instruction |= inst.operands[0].reg; | |
7614 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef NC |
7615 | } |
7616 | } | |
b99bd4ef NC |
7617 | } |
7618 | ||
7619 | static void | |
c19d1205 | 7620 | do_t_simd (void) |
b99bd4ef | 7621 | { |
c19d1205 ZW |
7622 | inst.instruction |= inst.operands[0].reg << 8; |
7623 | inst.instruction |= inst.operands[1].reg << 16; | |
7624 | inst.instruction |= inst.operands[2].reg; | |
7625 | } | |
b99bd4ef | 7626 | |
c19d1205 | 7627 | static void |
3eb17e6b | 7628 | do_t_smc (void) |
c19d1205 ZW |
7629 | { |
7630 | unsigned int value = inst.reloc.exp.X_add_number; | |
7631 | constraint (inst.reloc.exp.X_op != O_constant, | |
7632 | _("expression too complex")); | |
7633 | inst.reloc.type = BFD_RELOC_UNUSED; | |
7634 | inst.instruction |= (value & 0xf000) >> 12; | |
7635 | inst.instruction |= (value & 0x0ff0); | |
7636 | inst.instruction |= (value & 0x000f) << 16; | |
7637 | } | |
b99bd4ef | 7638 | |
c19d1205 ZW |
7639 | static void |
7640 | do_t_ssat (void) | |
7641 | { | |
7642 | inst.instruction |= inst.operands[0].reg << 8; | |
7643 | inst.instruction |= inst.operands[1].imm - 1; | |
7644 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 7645 | |
c19d1205 | 7646 | if (inst.operands[3].present) |
b99bd4ef | 7647 | { |
c19d1205 ZW |
7648 | constraint (inst.reloc.exp.X_op != O_constant, |
7649 | _("expression too complex")); | |
b99bd4ef | 7650 | |
c19d1205 | 7651 | if (inst.reloc.exp.X_add_number != 0) |
6189168b | 7652 | { |
c19d1205 ZW |
7653 | if (inst.operands[3].shift_kind == SHIFT_ASR) |
7654 | inst.instruction |= 0x00200000; /* sh bit */ | |
7655 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; | |
7656 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
6189168b | 7657 | } |
c19d1205 | 7658 | inst.reloc.type = BFD_RELOC_UNUSED; |
6189168b | 7659 | } |
b99bd4ef NC |
7660 | } |
7661 | ||
0dd132b6 | 7662 | static void |
c19d1205 | 7663 | do_t_ssat16 (void) |
0dd132b6 | 7664 | { |
c19d1205 ZW |
7665 | inst.instruction |= inst.operands[0].reg << 8; |
7666 | inst.instruction |= inst.operands[1].imm - 1; | |
7667 | inst.instruction |= inst.operands[2].reg << 16; | |
7668 | } | |
0dd132b6 | 7669 | |
c19d1205 ZW |
7670 | static void |
7671 | do_t_strex (void) | |
7672 | { | |
7673 | constraint (!inst.operands[2].isreg || !inst.operands[2].preind | |
7674 | || inst.operands[2].postind || inst.operands[2].writeback | |
7675 | || inst.operands[2].immisreg || inst.operands[2].shifted | |
7676 | || inst.operands[2].negative, | |
01cfc07f | 7677 | BAD_ADDR_MODE); |
0dd132b6 | 7678 | |
c19d1205 ZW |
7679 | inst.instruction |= inst.operands[0].reg << 8; |
7680 | inst.instruction |= inst.operands[1].reg << 12; | |
7681 | inst.instruction |= inst.operands[2].reg << 16; | |
7682 | inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8; | |
0dd132b6 NC |
7683 | } |
7684 | ||
b99bd4ef | 7685 | static void |
c19d1205 | 7686 | do_t_strexd (void) |
b99bd4ef | 7687 | { |
c19d1205 ZW |
7688 | if (!inst.operands[2].present) |
7689 | inst.operands[2].reg = inst.operands[1].reg + 1; | |
b99bd4ef | 7690 | |
c19d1205 ZW |
7691 | constraint (inst.operands[0].reg == inst.operands[1].reg |
7692 | || inst.operands[0].reg == inst.operands[2].reg | |
7693 | || inst.operands[0].reg == inst.operands[3].reg | |
7694 | || inst.operands[1].reg == inst.operands[2].reg, | |
7695 | BAD_OVERLAP); | |
b99bd4ef | 7696 | |
c19d1205 ZW |
7697 | inst.instruction |= inst.operands[0].reg; |
7698 | inst.instruction |= inst.operands[1].reg << 12; | |
7699 | inst.instruction |= inst.operands[2].reg << 8; | |
7700 | inst.instruction |= inst.operands[3].reg << 16; | |
b99bd4ef NC |
7701 | } |
7702 | ||
7703 | static void | |
c19d1205 | 7704 | do_t_sxtah (void) |
b99bd4ef | 7705 | { |
c19d1205 ZW |
7706 | inst.instruction |= inst.operands[0].reg << 8; |
7707 | inst.instruction |= inst.operands[1].reg << 16; | |
7708 | inst.instruction |= inst.operands[2].reg; | |
7709 | inst.instruction |= inst.operands[3].imm << 4; | |
7710 | } | |
b99bd4ef | 7711 | |
c19d1205 ZW |
7712 | static void |
7713 | do_t_sxth (void) | |
7714 | { | |
7715 | if (inst.instruction <= 0xffff && inst.size_req != 4 | |
7716 | && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7 | |
7717 | && (!inst.operands[2].present || inst.operands[2].imm == 0)) | |
b99bd4ef | 7718 | { |
c19d1205 ZW |
7719 | inst.instruction = THUMB_OP16 (inst.instruction); |
7720 | inst.instruction |= inst.operands[0].reg; | |
7721 | inst.instruction |= inst.operands[1].reg << 3; | |
b99bd4ef | 7722 | } |
c19d1205 | 7723 | else if (unified_syntax) |
b99bd4ef | 7724 | { |
c19d1205 ZW |
7725 | if (inst.instruction <= 0xffff) |
7726 | inst.instruction = THUMB_OP32 (inst.instruction); | |
7727 | inst.instruction |= inst.operands[0].reg << 8; | |
7728 | inst.instruction |= inst.operands[1].reg; | |
7729 | inst.instruction |= inst.operands[2].imm << 4; | |
b99bd4ef | 7730 | } |
c19d1205 | 7731 | else |
b99bd4ef | 7732 | { |
c19d1205 ZW |
7733 | constraint (inst.operands[2].present && inst.operands[2].imm != 0, |
7734 | _("Thumb encoding does not support rotation")); | |
7735 | constraint (1, BAD_HIREG); | |
b99bd4ef | 7736 | } |
c19d1205 | 7737 | } |
b99bd4ef | 7738 | |
c19d1205 ZW |
7739 | static void |
7740 | do_t_swi (void) | |
7741 | { | |
7742 | inst.reloc.type = BFD_RELOC_ARM_SWI; | |
7743 | } | |
b99bd4ef | 7744 | |
92e90b6e PB |
7745 | static void |
7746 | do_t_tb (void) | |
7747 | { | |
7748 | int half; | |
7749 | ||
7750 | half = (inst.instruction & 0x10) != 0; | |
7751 | constraint (inst.operands[0].imm == 15, | |
7752 | _("PC is not a valid index register")); | |
7753 | constraint (!half && inst.operands[0].shifted, | |
7754 | _("instruction does not allow shifted index")); | |
7755 | constraint (half && !inst.operands[0].shifted, | |
7756 | _("instruction requires shifted index")); | |
7757 | inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm; | |
7758 | } | |
7759 | ||
c19d1205 ZW |
7760 | static void |
7761 | do_t_usat (void) | |
7762 | { | |
7763 | inst.instruction |= inst.operands[0].reg << 8; | |
7764 | inst.instruction |= inst.operands[1].imm; | |
7765 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 7766 | |
c19d1205 | 7767 | if (inst.operands[3].present) |
b99bd4ef | 7768 | { |
c19d1205 ZW |
7769 | constraint (inst.reloc.exp.X_op != O_constant, |
7770 | _("expression too complex")); | |
7771 | if (inst.reloc.exp.X_add_number != 0) | |
7772 | { | |
7773 | if (inst.operands[3].shift_kind == SHIFT_ASR) | |
7774 | inst.instruction |= 0x00200000; /* sh bit */ | |
b99bd4ef | 7775 | |
c19d1205 ZW |
7776 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10; |
7777 | inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6; | |
7778 | } | |
7779 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 7780 | } |
b99bd4ef NC |
7781 | } |
7782 | ||
7783 | static void | |
c19d1205 | 7784 | do_t_usat16 (void) |
b99bd4ef | 7785 | { |
c19d1205 ZW |
7786 | inst.instruction |= inst.operands[0].reg << 8; |
7787 | inst.instruction |= inst.operands[1].imm; | |
7788 | inst.instruction |= inst.operands[2].reg << 16; | |
b99bd4ef | 7789 | } |
c19d1205 ZW |
7790 | \f |
7791 | /* Overall per-instruction processing. */ | |
7792 | ||
7793 | /* We need to be able to fix up arbitrary expressions in some statements. | |
7794 | This is so that we can handle symbols that are an arbitrary distance from | |
7795 | the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask), | |
7796 | which returns part of an address in a form which will be valid for | |
7797 | a data instruction. We do this by pushing the expression into a symbol | |
7798 | in the expr_section, and creating a fix for that. */ | |
b99bd4ef NC |
7799 | |
7800 | static void | |
c19d1205 ZW |
7801 | fix_new_arm (fragS * frag, |
7802 | int where, | |
7803 | short int size, | |
7804 | expressionS * exp, | |
7805 | int pc_rel, | |
7806 | int reloc) | |
b99bd4ef | 7807 | { |
c19d1205 | 7808 | fixS * new_fix; |
b99bd4ef | 7809 | |
c19d1205 | 7810 | switch (exp->X_op) |
b99bd4ef | 7811 | { |
c19d1205 ZW |
7812 | case O_constant: |
7813 | case O_symbol: | |
7814 | case O_add: | |
7815 | case O_subtract: | |
7816 | new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc); | |
7817 | break; | |
b99bd4ef | 7818 | |
c19d1205 ZW |
7819 | default: |
7820 | new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0, | |
7821 | pc_rel, reloc); | |
7822 | break; | |
b99bd4ef NC |
7823 | } |
7824 | ||
c19d1205 ZW |
7825 | /* Mark whether the fix is to a THUMB instruction, or an ARM |
7826 | instruction. */ | |
adbaf948 | 7827 | new_fix->tc_fix_data = thumb_mode; |
b99bd4ef NC |
7828 | } |
7829 | ||
0110f2b8 PB |
7830 | /* Create a frg for an instruction requiring relaxation. */ |
7831 | static void | |
7832 | output_relax_insn (void) | |
7833 | { | |
7834 | char * to; | |
7835 | symbolS *sym; | |
7836 | int offset; | |
7837 | ||
7838 | switch (inst.reloc.exp.X_op) | |
7839 | { | |
7840 | case O_symbol: | |
7841 | sym = inst.reloc.exp.X_add_symbol; | |
7842 | offset = inst.reloc.exp.X_add_number; | |
7843 | break; | |
7844 | case O_constant: | |
7845 | sym = NULL; | |
7846 | offset = inst.reloc.exp.X_add_number; | |
7847 | break; | |
7848 | default: | |
7849 | sym = make_expr_symbol (&inst.reloc.exp); | |
7850 | offset = 0; | |
7851 | break; | |
7852 | } | |
7853 | to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE, | |
7854 | inst.relax, sym, offset, NULL/*offset, opcode*/); | |
7855 | md_number_to_chars (to, inst.instruction, THUMB_SIZE); | |
7856 | ||
7857 | #ifdef OBJ_ELF | |
7858 | dwarf2_emit_insn (INSN_SIZE); | |
7859 | #endif | |
7860 | } | |
7861 | ||
7862 | /* Write a 32-bit thumb instruction to buf. */ | |
7863 | static void | |
7864 | put_thumb32_insn (char * buf, unsigned long insn) | |
7865 | { | |
7866 | md_number_to_chars (buf, insn >> 16, THUMB_SIZE); | |
7867 | md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE); | |
7868 | } | |
7869 | ||
b99bd4ef | 7870 | static void |
c19d1205 | 7871 | output_inst (const char * str) |
b99bd4ef | 7872 | { |
c19d1205 | 7873 | char * to = NULL; |
b99bd4ef | 7874 | |
c19d1205 | 7875 | if (inst.error) |
b99bd4ef | 7876 | { |
c19d1205 | 7877 | as_bad ("%s -- `%s'", inst.error, str); |
b99bd4ef NC |
7878 | return; |
7879 | } | |
0110f2b8 PB |
7880 | if (inst.relax) { |
7881 | output_relax_insn(); | |
7882 | return; | |
7883 | } | |
c19d1205 ZW |
7884 | if (inst.size == 0) |
7885 | return; | |
b99bd4ef | 7886 | |
c19d1205 ZW |
7887 | to = frag_more (inst.size); |
7888 | ||
7889 | if (thumb_mode && (inst.size > THUMB_SIZE)) | |
b99bd4ef | 7890 | { |
c19d1205 | 7891 | assert (inst.size == (2 * THUMB_SIZE)); |
0110f2b8 | 7892 | put_thumb32_insn (to, inst.instruction); |
b99bd4ef | 7893 | } |
c19d1205 | 7894 | else if (inst.size > INSN_SIZE) |
b99bd4ef | 7895 | { |
c19d1205 ZW |
7896 | assert (inst.size == (2 * INSN_SIZE)); |
7897 | md_number_to_chars (to, inst.instruction, INSN_SIZE); | |
7898 | md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE); | |
b99bd4ef | 7899 | } |
c19d1205 ZW |
7900 | else |
7901 | md_number_to_chars (to, inst.instruction, inst.size); | |
b99bd4ef | 7902 | |
c19d1205 ZW |
7903 | if (inst.reloc.type != BFD_RELOC_UNUSED) |
7904 | fix_new_arm (frag_now, to - frag_now->fr_literal, | |
7905 | inst.size, & inst.reloc.exp, inst.reloc.pc_rel, | |
7906 | inst.reloc.type); | |
b99bd4ef | 7907 | |
c19d1205 ZW |
7908 | #ifdef OBJ_ELF |
7909 | dwarf2_emit_insn (inst.size); | |
7910 | #endif | |
7911 | } | |
b99bd4ef | 7912 | |
c19d1205 ZW |
7913 | /* Tag values used in struct asm_opcode's tag field. */ |
7914 | enum opcode_tag | |
7915 | { | |
7916 | OT_unconditional, /* Instruction cannot be conditionalized. | |
7917 | The ARM condition field is still 0xE. */ | |
7918 | OT_unconditionalF, /* Instruction cannot be conditionalized | |
7919 | and carries 0xF in its ARM condition field. */ | |
7920 | OT_csuffix, /* Instruction takes a conditional suffix. */ | |
7921 | OT_cinfix3, /* Instruction takes a conditional infix, | |
7922 | beginning at character index 3. (In | |
7923 | unified mode, it becomes a suffix.) */ | |
e3cb604e PB |
7924 | OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at |
7925 | character index 3, even in unified mode. Used for | |
7926 | legacy instructions where suffix and infix forms | |
7927 | may be ambiguous. */ | |
c19d1205 | 7928 | OT_csuf_or_in3, /* Instruction takes either a conditional |
e3cb604e | 7929 | suffix or an infix at character index 3. */ |
c19d1205 ZW |
7930 | OT_odd_infix_unc, /* This is the unconditional variant of an |
7931 | instruction that takes a conditional infix | |
7932 | at an unusual position. In unified mode, | |
7933 | this variant will accept a suffix. */ | |
7934 | OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0 | |
7935 | are the conditional variants of instructions that | |
7936 | take conditional infixes in unusual positions. | |
7937 | The infix appears at character index | |
7938 | (tag - OT_odd_infix_0). These are not accepted | |
7939 | in unified mode. */ | |
7940 | }; | |
b99bd4ef | 7941 | |
c19d1205 ZW |
7942 | /* Subroutine of md_assemble, responsible for looking up the primary |
7943 | opcode from the mnemonic the user wrote. STR points to the | |
7944 | beginning of the mnemonic. | |
7945 | ||
7946 | This is not simply a hash table lookup, because of conditional | |
7947 | variants. Most instructions have conditional variants, which are | |
7948 | expressed with a _conditional affix_ to the mnemonic. If we were | |
7949 | to encode each conditional variant as a literal string in the opcode | |
7950 | table, it would have approximately 20,000 entries. | |
7951 | ||
7952 | Most mnemonics take this affix as a suffix, and in unified syntax, | |
7953 | 'most' is upgraded to 'all'. However, in the divided syntax, some | |
7954 | instructions take the affix as an infix, notably the s-variants of | |
7955 | the arithmetic instructions. Of those instructions, all but six | |
7956 | have the infix appear after the third character of the mnemonic. | |
7957 | ||
7958 | Accordingly, the algorithm for looking up primary opcodes given | |
7959 | an identifier is: | |
7960 | ||
7961 | 1. Look up the identifier in the opcode table. | |
7962 | If we find a match, go to step U. | |
7963 | ||
7964 | 2. Look up the last two characters of the identifier in the | |
7965 | conditions table. If we find a match, look up the first N-2 | |
7966 | characters of the identifier in the opcode table. If we | |
7967 | find a match, go to step CE. | |
7968 | ||
7969 | 3. Look up the fourth and fifth characters of the identifier in | |
7970 | the conditions table. If we find a match, extract those | |
7971 | characters from the identifier, and look up the remaining | |
7972 | characters in the opcode table. If we find a match, go | |
7973 | to step CM. | |
7974 | ||
7975 | 4. Fail. | |
7976 | ||
7977 | U. Examine the tag field of the opcode structure, in case this is | |
7978 | one of the six instructions with its conditional infix in an | |
7979 | unusual place. If it is, the tag tells us where to find the | |
7980 | infix; look it up in the conditions table and set inst.cond | |
7981 | accordingly. Otherwise, this is an unconditional instruction. | |
7982 | Again set inst.cond accordingly. Return the opcode structure. | |
7983 | ||
7984 | CE. Examine the tag field to make sure this is an instruction that | |
7985 | should receive a conditional suffix. If it is not, fail. | |
7986 | Otherwise, set inst.cond from the suffix we already looked up, | |
7987 | and return the opcode structure. | |
7988 | ||
7989 | CM. Examine the tag field to make sure this is an instruction that | |
7990 | should receive a conditional infix after the third character. | |
7991 | If it is not, fail. Otherwise, undo the edits to the current | |
7992 | line of input and proceed as for case CE. */ | |
7993 | ||
7994 | static const struct asm_opcode * | |
7995 | opcode_lookup (char **str) | |
7996 | { | |
7997 | char *end, *base; | |
7998 | char *affix; | |
7999 | const struct asm_opcode *opcode; | |
8000 | const struct asm_cond *cond; | |
e3cb604e | 8001 | char save[2]; |
c19d1205 ZW |
8002 | |
8003 | /* Scan up to the end of the mnemonic, which must end in white space, | |
8004 | '.' (in unified mode only), or end of string. */ | |
8005 | for (base = end = *str; *end != '\0'; end++) | |
8006 | if (*end == ' ' || (unified_syntax && *end == '.')) | |
8007 | break; | |
b99bd4ef | 8008 | |
c19d1205 ZW |
8009 | if (end == base) |
8010 | return 0; | |
b99bd4ef | 8011 | |
c19d1205 ZW |
8012 | /* Handle a possible width suffix. */ |
8013 | if (end[0] == '.') | |
b99bd4ef | 8014 | { |
c19d1205 ZW |
8015 | if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0')) |
8016 | inst.size_req = 4; | |
8017 | else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0')) | |
8018 | inst.size_req = 2; | |
8019 | else | |
8020 | return 0; | |
b99bd4ef | 8021 | |
c19d1205 | 8022 | *str = end + 2; |
b99bd4ef | 8023 | } |
c19d1205 ZW |
8024 | else |
8025 | *str = end; | |
b99bd4ef | 8026 | |
c19d1205 ZW |
8027 | /* Look for unaffixed or special-case affixed mnemonic. */ |
8028 | opcode = hash_find_n (arm_ops_hsh, base, end - base); | |
8029 | if (opcode) | |
b99bd4ef | 8030 | { |
c19d1205 ZW |
8031 | /* step U */ |
8032 | if (opcode->tag < OT_odd_infix_0) | |
b99bd4ef | 8033 | { |
c19d1205 ZW |
8034 | inst.cond = COND_ALWAYS; |
8035 | return opcode; | |
b99bd4ef | 8036 | } |
b99bd4ef | 8037 | |
c19d1205 ZW |
8038 | if (unified_syntax) |
8039 | as_warn (_("conditional infixes are deprecated in unified syntax")); | |
8040 | affix = base + (opcode->tag - OT_odd_infix_0); | |
8041 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
8042 | assert (cond); | |
b99bd4ef | 8043 | |
c19d1205 ZW |
8044 | inst.cond = cond->value; |
8045 | return opcode; | |
8046 | } | |
b99bd4ef | 8047 | |
c19d1205 ZW |
8048 | /* Cannot have a conditional suffix on a mnemonic of less than two |
8049 | characters. */ | |
8050 | if (end - base < 3) | |
8051 | return 0; | |
b99bd4ef | 8052 | |
c19d1205 ZW |
8053 | /* Look for suffixed mnemonic. */ |
8054 | affix = end - 2; | |
8055 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
8056 | opcode = hash_find_n (arm_ops_hsh, base, affix - base); | |
8057 | if (opcode && cond) | |
8058 | { | |
8059 | /* step CE */ | |
8060 | switch (opcode->tag) | |
8061 | { | |
e3cb604e PB |
8062 | case OT_cinfix3_legacy: |
8063 | /* Ignore conditional suffixes matched on infix only mnemonics. */ | |
8064 | break; | |
8065 | ||
c19d1205 ZW |
8066 | case OT_cinfix3: |
8067 | case OT_odd_infix_unc: | |
8068 | if (!unified_syntax) | |
e3cb604e | 8069 | return 0; |
c19d1205 ZW |
8070 | /* else fall through */ |
8071 | ||
8072 | case OT_csuffix: | |
8073 | case OT_csuf_or_in3: | |
8074 | inst.cond = cond->value; | |
8075 | return opcode; | |
8076 | ||
8077 | case OT_unconditional: | |
8078 | case OT_unconditionalF: | |
8079 | /* delayed diagnostic */ | |
8080 | inst.error = BAD_COND; | |
8081 | inst.cond = COND_ALWAYS; | |
8082 | return opcode; | |
b99bd4ef | 8083 | |
c19d1205 ZW |
8084 | default: |
8085 | return 0; | |
8086 | } | |
8087 | } | |
b99bd4ef | 8088 | |
c19d1205 ZW |
8089 | /* Cannot have a usual-position infix on a mnemonic of less than |
8090 | six characters (five would be a suffix). */ | |
8091 | if (end - base < 6) | |
8092 | return 0; | |
b99bd4ef | 8093 | |
c19d1205 ZW |
8094 | /* Look for infixed mnemonic in the usual position. */ |
8095 | affix = base + 3; | |
8096 | cond = hash_find_n (arm_cond_hsh, affix, 2); | |
e3cb604e PB |
8097 | if (!cond) |
8098 | return 0; | |
8099 | ||
8100 | memcpy (save, affix, 2); | |
8101 | memmove (affix, affix + 2, (end - affix) - 2); | |
8102 | opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2); | |
8103 | memmove (affix + 2, affix, (end - affix) - 2); | |
8104 | memcpy (affix, save, 2); | |
8105 | ||
8106 | if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3 | |
8107 | || opcode->tag == OT_cinfix3_legacy)) | |
b99bd4ef | 8108 | { |
c19d1205 | 8109 | /* step CM */ |
e3cb604e | 8110 | if (unified_syntax && opcode->tag == OT_cinfix3) |
c19d1205 ZW |
8111 | as_warn (_("conditional infixes are deprecated in unified syntax")); |
8112 | ||
8113 | inst.cond = cond->value; | |
8114 | return opcode; | |
b99bd4ef NC |
8115 | } |
8116 | ||
c19d1205 | 8117 | return 0; |
b99bd4ef NC |
8118 | } |
8119 | ||
c19d1205 ZW |
8120 | void |
8121 | md_assemble (char *str) | |
b99bd4ef | 8122 | { |
c19d1205 ZW |
8123 | char *p = str; |
8124 | const struct asm_opcode * opcode; | |
b99bd4ef | 8125 | |
c19d1205 ZW |
8126 | /* Align the previous label if needed. */ |
8127 | if (last_label_seen != NULL) | |
b99bd4ef | 8128 | { |
c19d1205 ZW |
8129 | symbol_set_frag (last_label_seen, frag_now); |
8130 | S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ()); | |
8131 | S_SET_SEGMENT (last_label_seen, now_seg); | |
b99bd4ef NC |
8132 | } |
8133 | ||
c19d1205 ZW |
8134 | memset (&inst, '\0', sizeof (inst)); |
8135 | inst.reloc.type = BFD_RELOC_UNUSED; | |
b99bd4ef | 8136 | |
c19d1205 ZW |
8137 | opcode = opcode_lookup (&p); |
8138 | if (!opcode) | |
b99bd4ef | 8139 | { |
c19d1205 ZW |
8140 | /* It wasn't an instruction, but it might be a register alias of |
8141 | the form alias .req reg. */ | |
8142 | if (!create_register_alias (str, p)) | |
8143 | as_bad (_("bad instruction `%s'"), str); | |
b99bd4ef | 8144 | |
b99bd4ef NC |
8145 | return; |
8146 | } | |
8147 | ||
c19d1205 | 8148 | if (thumb_mode) |
b99bd4ef | 8149 | { |
e74cfd16 | 8150 | arm_feature_set variant; |
8f06b2d8 PB |
8151 | |
8152 | variant = cpu_variant; | |
8153 | /* Only allow coprocessor instructions on Thumb-2 capable devices. */ | |
e74cfd16 PB |
8154 | if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2)) |
8155 | ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard); | |
c19d1205 | 8156 | /* Check that this instruction is supported for this CPU. */ |
e74cfd16 PB |
8157 | if (thumb_mode == 1 |
8158 | && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)) | |
b99bd4ef | 8159 | { |
c19d1205 | 8160 | as_bad (_("selected processor does not support `%s'"), str); |
b99bd4ef NC |
8161 | return; |
8162 | } | |
c19d1205 ZW |
8163 | if (inst.cond != COND_ALWAYS && !unified_syntax |
8164 | && opcode->tencode != do_t_branch) | |
b99bd4ef | 8165 | { |
c19d1205 | 8166 | as_bad (_("Thumb does not support conditional execution")); |
b99bd4ef NC |
8167 | return; |
8168 | } | |
8169 | ||
e27ec89e PB |
8170 | /* Check conditional suffixes. */ |
8171 | if (current_it_mask) | |
8172 | { | |
8173 | int cond; | |
8174 | cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1; | |
8175 | if (cond != inst.cond) | |
8176 | { | |
8177 | as_bad (_("incorrect condition in IT block")); | |
8178 | return; | |
8179 | } | |
8180 | current_it_mask <<= 1; | |
8181 | current_it_mask &= 0x1f; | |
8182 | } | |
8183 | else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch) | |
8184 | { | |
8185 | as_bad (_("thumb conditional instrunction not in IT block")); | |
8186 | return; | |
8187 | } | |
8188 | ||
c19d1205 ZW |
8189 | mapping_state (MAP_THUMB); |
8190 | inst.instruction = opcode->tvalue; | |
8191 | ||
8192 | if (!parse_operands (p, opcode->operands)) | |
8193 | opcode->tencode (); | |
8194 | ||
e27ec89e PB |
8195 | /* Clear current_it_mask at the end of an IT block. */ |
8196 | if (current_it_mask == 0x10) | |
8197 | current_it_mask = 0; | |
8198 | ||
0110f2b8 | 8199 | if (!(inst.error || inst.relax)) |
b99bd4ef | 8200 | { |
c19d1205 ZW |
8201 | assert (inst.instruction < 0xe800 || inst.instruction > 0xffff); |
8202 | inst.size = (inst.instruction > 0xffff ? 4 : 2); | |
8203 | if (inst.size_req && inst.size_req != inst.size) | |
b99bd4ef | 8204 | { |
c19d1205 | 8205 | as_bad (_("cannot honor width suffix -- `%s'"), str); |
b99bd4ef NC |
8206 | return; |
8207 | } | |
8208 | } | |
e74cfd16 PB |
8209 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
8210 | *opcode->tvariant); | |
ee065d83 | 8211 | /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly |
e74cfd16 | 8212 | set those bits when Thumb-2 32-bit instuctions are seen. ie. |
ee065d83 PB |
8213 | anything other than bl/blx. |
8214 | This is overly pessimistic for relaxable instructions. */ | |
8215 | if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800) | |
8216 | || inst.relax) | |
e74cfd16 PB |
8217 | ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, |
8218 | arm_ext_v6t2); | |
c19d1205 ZW |
8219 | } |
8220 | else | |
8221 | { | |
8222 | /* Check that this instruction is supported for this CPU. */ | |
e74cfd16 | 8223 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)) |
b99bd4ef | 8224 | { |
c19d1205 ZW |
8225 | as_bad (_("selected processor does not support `%s'"), str); |
8226 | return; | |
b99bd4ef | 8227 | } |
c19d1205 | 8228 | if (inst.size_req) |
b99bd4ef | 8229 | { |
c19d1205 ZW |
8230 | as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str); |
8231 | return; | |
b99bd4ef NC |
8232 | } |
8233 | ||
c19d1205 ZW |
8234 | mapping_state (MAP_ARM); |
8235 | inst.instruction = opcode->avalue; | |
8236 | if (opcode->tag == OT_unconditionalF) | |
8237 | inst.instruction |= 0xF << 28; | |
8238 | else | |
8239 | inst.instruction |= inst.cond << 28; | |
8240 | inst.size = INSN_SIZE; | |
8241 | if (!parse_operands (p, opcode->operands)) | |
8242 | opcode->aencode (); | |
ee065d83 PB |
8243 | /* Arm mode bx is marked as both v4T and v5 because it's still required |
8244 | on a hypothetical non-thumb v5 core. */ | |
e74cfd16 PB |
8245 | if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t) |
8246 | || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5)) | |
8247 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t); | |
ee065d83 | 8248 | else |
e74cfd16 PB |
8249 | ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, |
8250 | *opcode->avariant); | |
b99bd4ef | 8251 | } |
c19d1205 ZW |
8252 | output_inst (str); |
8253 | } | |
b99bd4ef | 8254 | |
c19d1205 ZW |
8255 | /* Various frobbings of labels and their addresses. */ |
8256 | ||
8257 | void | |
8258 | arm_start_line_hook (void) | |
8259 | { | |
8260 | last_label_seen = NULL; | |
b99bd4ef NC |
8261 | } |
8262 | ||
c19d1205 ZW |
8263 | void |
8264 | arm_frob_label (symbolS * sym) | |
b99bd4ef | 8265 | { |
c19d1205 | 8266 | last_label_seen = sym; |
b99bd4ef | 8267 | |
c19d1205 | 8268 | ARM_SET_THUMB (sym, thumb_mode); |
b99bd4ef | 8269 | |
c19d1205 ZW |
8270 | #if defined OBJ_COFF || defined OBJ_ELF |
8271 | ARM_SET_INTERWORK (sym, support_interwork); | |
8272 | #endif | |
b99bd4ef | 8273 | |
c19d1205 ZW |
8274 | /* Note - do not allow local symbols (.Lxxx) to be labeled |
8275 | as Thumb functions. This is because these labels, whilst | |
8276 | they exist inside Thumb code, are not the entry points for | |
8277 | possible ARM->Thumb calls. Also, these labels can be used | |
8278 | as part of a computed goto or switch statement. eg gcc | |
8279 | can generate code that looks like this: | |
b99bd4ef | 8280 | |
c19d1205 ZW |
8281 | ldr r2, [pc, .Laaa] |
8282 | lsl r3, r3, #2 | |
8283 | ldr r2, [r3, r2] | |
8284 | mov pc, r2 | |
b99bd4ef | 8285 | |
c19d1205 ZW |
8286 | .Lbbb: .word .Lxxx |
8287 | .Lccc: .word .Lyyy | |
8288 | ..etc... | |
8289 | .Laaa: .word Lbbb | |
b99bd4ef | 8290 | |
c19d1205 ZW |
8291 | The first instruction loads the address of the jump table. |
8292 | The second instruction converts a table index into a byte offset. | |
8293 | The third instruction gets the jump address out of the table. | |
8294 | The fourth instruction performs the jump. | |
b99bd4ef | 8295 | |
c19d1205 ZW |
8296 | If the address stored at .Laaa is that of a symbol which has the |
8297 | Thumb_Func bit set, then the linker will arrange for this address | |
8298 | to have the bottom bit set, which in turn would mean that the | |
8299 | address computation performed by the third instruction would end | |
8300 | up with the bottom bit set. Since the ARM is capable of unaligned | |
8301 | word loads, the instruction would then load the incorrect address | |
8302 | out of the jump table, and chaos would ensue. */ | |
8303 | if (label_is_thumb_function_name | |
8304 | && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L') | |
8305 | && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) | |
b99bd4ef | 8306 | { |
c19d1205 ZW |
8307 | /* When the address of a Thumb function is taken the bottom |
8308 | bit of that address should be set. This will allow | |
8309 | interworking between Arm and Thumb functions to work | |
8310 | correctly. */ | |
b99bd4ef | 8311 | |
c19d1205 | 8312 | THUMB_SET_FUNC (sym, 1); |
b99bd4ef | 8313 | |
c19d1205 | 8314 | label_is_thumb_function_name = FALSE; |
b99bd4ef | 8315 | } |
07a53e5c RH |
8316 | |
8317 | #ifdef OBJ_ELF | |
8318 | dwarf2_emit_label (sym); | |
8319 | #endif | |
b99bd4ef NC |
8320 | } |
8321 | ||
c19d1205 ZW |
8322 | int |
8323 | arm_data_in_code (void) | |
b99bd4ef | 8324 | { |
c19d1205 | 8325 | if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5)) |
b99bd4ef | 8326 | { |
c19d1205 ZW |
8327 | *input_line_pointer = '/'; |
8328 | input_line_pointer += 5; | |
8329 | *input_line_pointer = 0; | |
8330 | return 1; | |
b99bd4ef NC |
8331 | } |
8332 | ||
c19d1205 | 8333 | return 0; |
b99bd4ef NC |
8334 | } |
8335 | ||
c19d1205 ZW |
8336 | char * |
8337 | arm_canonicalize_symbol_name (char * name) | |
b99bd4ef | 8338 | { |
c19d1205 | 8339 | int len; |
b99bd4ef | 8340 | |
c19d1205 ZW |
8341 | if (thumb_mode && (len = strlen (name)) > 5 |
8342 | && streq (name + len - 5, "/data")) | |
8343 | *(name + len - 5) = 0; | |
b99bd4ef | 8344 | |
c19d1205 | 8345 | return name; |
b99bd4ef | 8346 | } |
c19d1205 ZW |
8347 | \f |
8348 | /* Table of all register names defined by default. The user can | |
8349 | define additional names with .req. Note that all register names | |
8350 | should appear in both upper and lowercase variants. Some registers | |
8351 | also have mixed-case names. */ | |
b99bd4ef | 8352 | |
c19d1205 ZW |
8353 | #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE } |
8354 | #define REGNUM(p,n,t) REGDEF(p##n, n, t) | |
8355 | #define REGSET(p,t) \ | |
8356 | REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \ | |
8357 | REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \ | |
8358 | REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \ | |
8359 | REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t) | |
7ed4c4c5 | 8360 | |
c19d1205 | 8361 | static const struct reg_entry reg_names[] = |
7ed4c4c5 | 8362 | { |
c19d1205 ZW |
8363 | /* ARM integer registers. */ |
8364 | REGSET(r, RN), REGSET(R, RN), | |
7ed4c4c5 | 8365 | |
c19d1205 ZW |
8366 | /* ATPCS synonyms. */ |
8367 | REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN), | |
8368 | REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN), | |
8369 | REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN), | |
7ed4c4c5 | 8370 | |
c19d1205 ZW |
8371 | REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN), |
8372 | REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN), | |
8373 | REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN), | |
7ed4c4c5 | 8374 | |
c19d1205 ZW |
8375 | /* Well-known aliases. */ |
8376 | REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN), | |
8377 | REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN), | |
8378 | ||
8379 | REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN), | |
8380 | REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN), | |
8381 | ||
8382 | /* Coprocessor numbers. */ | |
8383 | REGSET(p, CP), REGSET(P, CP), | |
8384 | ||
8385 | /* Coprocessor register numbers. The "cr" variants are for backward | |
8386 | compatibility. */ | |
8387 | REGSET(c, CN), REGSET(C, CN), | |
8388 | REGSET(cr, CN), REGSET(CR, CN), | |
8389 | ||
8390 | /* FPA registers. */ | |
8391 | REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN), | |
8392 | REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN), | |
8393 | ||
8394 | REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN), | |
8395 | REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN), | |
8396 | ||
8397 | /* VFP SP registers. */ | |
8398 | REGSET(s,VFS), | |
8399 | REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS), | |
8400 | REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS), | |
8401 | REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS), | |
8402 | REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS), | |
8403 | ||
8404 | REGSET(S,VFS), | |
8405 | REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS), | |
8406 | REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS), | |
8407 | REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS), | |
8408 | REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS), | |
8409 | ||
8410 | /* VFP DP Registers. */ | |
8411 | REGSET(d,VFD), REGSET(D,VFS), | |
8412 | ||
8413 | /* VFP control registers. */ | |
8414 | REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC), | |
8415 | REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC), | |
8416 | ||
8417 | /* Maverick DSP coprocessor registers. */ | |
8418 | REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX), | |
8419 | REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX), | |
8420 | ||
8421 | REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX), | |
8422 | REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX), | |
8423 | REGDEF(dspsc,0,DSPSC), | |
8424 | ||
8425 | REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX), | |
8426 | REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX), | |
8427 | REGDEF(DSPSC,0,DSPSC), | |
8428 | ||
8429 | /* iWMMXt data registers - p0, c0-15. */ | |
8430 | REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR), | |
8431 | ||
8432 | /* iWMMXt control registers - p1, c0-3. */ | |
8433 | REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC), | |
8434 | REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC), | |
8435 | REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC), | |
8436 | REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC), | |
8437 | ||
8438 | /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */ | |
8439 | REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG), | |
8440 | REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG), | |
8441 | REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG), | |
8442 | REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG), | |
8443 | ||
8444 | /* XScale accumulator registers. */ | |
8445 | REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE), | |
8446 | }; | |
8447 | #undef REGDEF | |
8448 | #undef REGNUM | |
8449 | #undef REGSET | |
7ed4c4c5 | 8450 | |
c19d1205 ZW |
8451 | /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled |
8452 | within psr_required_here. */ | |
8453 | static const struct asm_psr psrs[] = | |
8454 | { | |
8455 | /* Backward compatibility notation. Note that "all" is no longer | |
8456 | truly all possible PSR bits. */ | |
8457 | {"all", PSR_c | PSR_f}, | |
8458 | {"flg", PSR_f}, | |
8459 | {"ctl", PSR_c}, | |
8460 | ||
8461 | /* Individual flags. */ | |
8462 | {"f", PSR_f}, | |
8463 | {"c", PSR_c}, | |
8464 | {"x", PSR_x}, | |
8465 | {"s", PSR_s}, | |
8466 | /* Combinations of flags. */ | |
8467 | {"fs", PSR_f | PSR_s}, | |
8468 | {"fx", PSR_f | PSR_x}, | |
8469 | {"fc", PSR_f | PSR_c}, | |
8470 | {"sf", PSR_s | PSR_f}, | |
8471 | {"sx", PSR_s | PSR_x}, | |
8472 | {"sc", PSR_s | PSR_c}, | |
8473 | {"xf", PSR_x | PSR_f}, | |
8474 | {"xs", PSR_x | PSR_s}, | |
8475 | {"xc", PSR_x | PSR_c}, | |
8476 | {"cf", PSR_c | PSR_f}, | |
8477 | {"cs", PSR_c | PSR_s}, | |
8478 | {"cx", PSR_c | PSR_x}, | |
8479 | {"fsx", PSR_f | PSR_s | PSR_x}, | |
8480 | {"fsc", PSR_f | PSR_s | PSR_c}, | |
8481 | {"fxs", PSR_f | PSR_x | PSR_s}, | |
8482 | {"fxc", PSR_f | PSR_x | PSR_c}, | |
8483 | {"fcs", PSR_f | PSR_c | PSR_s}, | |
8484 | {"fcx", PSR_f | PSR_c | PSR_x}, | |
8485 | {"sfx", PSR_s | PSR_f | PSR_x}, | |
8486 | {"sfc", PSR_s | PSR_f | PSR_c}, | |
8487 | {"sxf", PSR_s | PSR_x | PSR_f}, | |
8488 | {"sxc", PSR_s | PSR_x | PSR_c}, | |
8489 | {"scf", PSR_s | PSR_c | PSR_f}, | |
8490 | {"scx", PSR_s | PSR_c | PSR_x}, | |
8491 | {"xfs", PSR_x | PSR_f | PSR_s}, | |
8492 | {"xfc", PSR_x | PSR_f | PSR_c}, | |
8493 | {"xsf", PSR_x | PSR_s | PSR_f}, | |
8494 | {"xsc", PSR_x | PSR_s | PSR_c}, | |
8495 | {"xcf", PSR_x | PSR_c | PSR_f}, | |
8496 | {"xcs", PSR_x | PSR_c | PSR_s}, | |
8497 | {"cfs", PSR_c | PSR_f | PSR_s}, | |
8498 | {"cfx", PSR_c | PSR_f | PSR_x}, | |
8499 | {"csf", PSR_c | PSR_s | PSR_f}, | |
8500 | {"csx", PSR_c | PSR_s | PSR_x}, | |
8501 | {"cxf", PSR_c | PSR_x | PSR_f}, | |
8502 | {"cxs", PSR_c | PSR_x | PSR_s}, | |
8503 | {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c}, | |
8504 | {"fscx", PSR_f | PSR_s | PSR_c | PSR_x}, | |
8505 | {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c}, | |
8506 | {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s}, | |
8507 | {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x}, | |
8508 | {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s}, | |
8509 | {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c}, | |
8510 | {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x}, | |
8511 | {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c}, | |
8512 | {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f}, | |
8513 | {"scfx", PSR_s | PSR_c | PSR_f | PSR_x}, | |
8514 | {"scxf", PSR_s | PSR_c | PSR_x | PSR_f}, | |
8515 | {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c}, | |
8516 | {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s}, | |
8517 | {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c}, | |
8518 | {"xscf", PSR_x | PSR_s | PSR_c | PSR_f}, | |
8519 | {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s}, | |
8520 | {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f}, | |
8521 | {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x}, | |
8522 | {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s}, | |
8523 | {"csfx", PSR_c | PSR_s | PSR_f | PSR_x}, | |
8524 | {"csxf", PSR_c | PSR_s | PSR_x | PSR_f}, | |
8525 | {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s}, | |
8526 | {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f}, | |
8527 | }; | |
8528 | ||
8529 | /* Table of all shift-in-operand names. */ | |
8530 | static const struct asm_shift_name shift_names [] = | |
b99bd4ef | 8531 | { |
c19d1205 ZW |
8532 | { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL }, |
8533 | { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL }, | |
8534 | { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR }, | |
8535 | { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR }, | |
8536 | { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR }, | |
8537 | { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX } | |
8538 | }; | |
b99bd4ef | 8539 | |
c19d1205 ZW |
8540 | /* Table of all explicit relocation names. */ |
8541 | #ifdef OBJ_ELF | |
8542 | static struct reloc_entry reloc_names[] = | |
8543 | { | |
8544 | { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 }, | |
8545 | { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF }, | |
8546 | { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 }, | |
8547 | { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 }, | |
8548 | { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 }, | |
8549 | { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 }, | |
8550 | { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32}, | |
8551 | { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32}, | |
8552 | { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32}, | |
8553 | { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32}, | |
8554 | { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32} | |
8555 | }; | |
8556 | #endif | |
b99bd4ef | 8557 | |
c19d1205 ZW |
8558 | /* Table of all conditional affixes. 0xF is not defined as a condition code. */ |
8559 | static const struct asm_cond conds[] = | |
8560 | { | |
8561 | {"eq", 0x0}, | |
8562 | {"ne", 0x1}, | |
8563 | {"cs", 0x2}, {"hs", 0x2}, | |
8564 | {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3}, | |
8565 | {"mi", 0x4}, | |
8566 | {"pl", 0x5}, | |
8567 | {"vs", 0x6}, | |
8568 | {"vc", 0x7}, | |
8569 | {"hi", 0x8}, | |
8570 | {"ls", 0x9}, | |
8571 | {"ge", 0xa}, | |
8572 | {"lt", 0xb}, | |
8573 | {"gt", 0xc}, | |
8574 | {"le", 0xd}, | |
8575 | {"al", 0xe} | |
8576 | }; | |
bfae80f2 | 8577 | |
c19d1205 ZW |
8578 | /* Table of ARM-format instructions. */ |
8579 | ||
8580 | /* Macros for gluing together operand strings. N.B. In all cases | |
8581 | other than OPS0, the trailing OP_stop comes from default | |
8582 | zero-initialization of the unspecified elements of the array. */ | |
8583 | #define OPS0() { OP_stop, } | |
8584 | #define OPS1(a) { OP_##a, } | |
8585 | #define OPS2(a,b) { OP_##a,OP_##b, } | |
8586 | #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, } | |
8587 | #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, } | |
8588 | #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, } | |
8589 | #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, } | |
8590 | ||
8591 | /* These macros abstract out the exact format of the mnemonic table and | |
8592 | save some repeated characters. */ | |
8593 | ||
8594 | /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */ | |
8595 | #define TxCE(mnem, op, top, nops, ops, ae, te) \ | |
8596 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 8597 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8598 | |
8599 | /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for | |
8600 | a T_MNEM_xyz enumerator. */ | |
8601 | #define TCE(mnem, aop, top, nops, ops, ae, te) \ | |
8602 | TxCE(mnem, aop, 0x##top, nops, ops, ae, te) | |
8603 | #define tCE(mnem, aop, top, nops, ops, ae, te) \ | |
8604 | TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
8605 | ||
8606 | /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional | |
8607 | infix after the third character. */ | |
8608 | #define TxC3(mnem, op, top, nops, ops, ae, te) \ | |
8609 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \ | |
1887dd22 | 8610 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8611 | #define TC3(mnem, aop, top, nops, ops, ae, te) \ |
8612 | TxC3(mnem, aop, 0x##top, nops, ops, ae, te) | |
8613 | #define tC3(mnem, aop, top, nops, ops, ae, te) \ | |
8614 | TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te) | |
8615 | ||
8616 | /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to | |
8617 | appear in the condition table. */ | |
8618 | #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \ | |
8619 | { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
1887dd22 | 8620 | 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8621 | |
8622 | #define TxCM(m1, m2, op, top, nops, ops, ae, te) \ | |
8623 | TxCM_(m1, , m2, op, top, nops, ops, ae, te), \ | |
8624 | TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \ | |
8625 | TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \ | |
8626 | TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \ | |
8627 | TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \ | |
8628 | TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \ | |
8629 | TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \ | |
8630 | TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \ | |
8631 | TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \ | |
8632 | TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \ | |
8633 | TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \ | |
8634 | TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \ | |
8635 | TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \ | |
8636 | TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \ | |
8637 | TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \ | |
8638 | TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \ | |
8639 | TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \ | |
8640 | TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \ | |
8641 | TxCM_(m1, al, m2, op, top, nops, ops, ae, te) | |
8642 | ||
8643 | #define TCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
8644 | TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te) | |
8645 | #define tCM(m1,m2, aop, top, nops, ops, ae, te) \ | |
8646 | TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te) | |
8647 | ||
8648 | /* Mnemonic that cannot be conditionalized. The ARM condition-code | |
8649 | field is still 0xE. */ | |
8650 | #define TUE(mnem, op, top, nops, ops, ae, te) \ | |
8651 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 8652 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8653 | |
8654 | /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM | |
8655 | condition code field. */ | |
8656 | #define TUF(mnem, op, top, nops, ops, ae, te) \ | |
8657 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \ | |
1887dd22 | 8658 | THUMB_VARIANT, do_##ae, do_##te } |
c19d1205 ZW |
8659 | |
8660 | /* ARM-only variants of all the above. */ | |
6a86118a NC |
8661 | #define CE(mnem, op, nops, ops, ae) \ |
8662 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8663 | ||
8664 | #define C3(mnem, op, nops, ops, ae) \ | |
8665 | { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8666 | ||
e3cb604e PB |
8667 | /* Legacy mnemonics that always have conditional infix after the third |
8668 | character. */ | |
8669 | #define CL(mnem, op, nops, ops, ae) \ | |
8670 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
8671 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8672 | ||
8f06b2d8 PB |
8673 | /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */ |
8674 | #define cCE(mnem, op, nops, ops, ae) \ | |
8675 | { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8676 | ||
e3cb604e PB |
8677 | /* Legacy coprocessor instructions where conditional infix and conditional |
8678 | suffix are ambiguous. For consistency this includes all FPA instructions, | |
8679 | not just the potentially ambiguous ones. */ | |
8680 | #define cCL(mnem, op, nops, ops, ae) \ | |
8681 | { #mnem, OPS##nops ops, OT_cinfix3_legacy, \ | |
8682 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8683 | ||
8684 | /* Coprocessor, takes either a suffix or a position-3 infix | |
8685 | (for an FPA corner case). */ | |
8686 | #define C3E(mnem, op, nops, ops, ae) \ | |
8687 | { #mnem, OPS##nops ops, OT_csuf_or_in3, \ | |
8688 | 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae } | |
8f06b2d8 | 8689 | |
6a86118a NC |
8690 | #define xCM_(m1, m2, m3, op, nops, ops, ae) \ |
8691 | { #m1 #m2 #m3, OPS##nops ops, \ | |
8692 | sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \ | |
8693 | 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL } | |
8694 | ||
8695 | #define CM(m1, m2, op, nops, ops, ae) \ | |
8696 | xCM_(m1, , m2, op, nops, ops, ae), \ | |
8697 | xCM_(m1, eq, m2, op, nops, ops, ae), \ | |
8698 | xCM_(m1, ne, m2, op, nops, ops, ae), \ | |
8699 | xCM_(m1, cs, m2, op, nops, ops, ae), \ | |
8700 | xCM_(m1, hs, m2, op, nops, ops, ae), \ | |
8701 | xCM_(m1, cc, m2, op, nops, ops, ae), \ | |
8702 | xCM_(m1, ul, m2, op, nops, ops, ae), \ | |
8703 | xCM_(m1, lo, m2, op, nops, ops, ae), \ | |
8704 | xCM_(m1, mi, m2, op, nops, ops, ae), \ | |
8705 | xCM_(m1, pl, m2, op, nops, ops, ae), \ | |
8706 | xCM_(m1, vs, m2, op, nops, ops, ae), \ | |
8707 | xCM_(m1, vc, m2, op, nops, ops, ae), \ | |
8708 | xCM_(m1, hi, m2, op, nops, ops, ae), \ | |
8709 | xCM_(m1, ls, m2, op, nops, ops, ae), \ | |
8710 | xCM_(m1, ge, m2, op, nops, ops, ae), \ | |
8711 | xCM_(m1, lt, m2, op, nops, ops, ae), \ | |
8712 | xCM_(m1, gt, m2, op, nops, ops, ae), \ | |
8713 | xCM_(m1, le, m2, op, nops, ops, ae), \ | |
8714 | xCM_(m1, al, m2, op, nops, ops, ae) | |
8715 | ||
8716 | #define UE(mnem, op, nops, ops, ae) \ | |
8717 | { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
8718 | ||
8719 | #define UF(mnem, op, nops, ops, ae) \ | |
8720 | { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL } | |
8721 | ||
c19d1205 ZW |
8722 | #define do_0 0 |
8723 | ||
8724 | /* Thumb-only, unconditional. */ | |
8725 | #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te) | |
8726 | ||
c19d1205 | 8727 | static const struct asm_opcode insns[] = |
bfae80f2 | 8728 | { |
e74cfd16 PB |
8729 | #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */ |
8730 | #define THUMB_VARIANT &arm_ext_v4t | |
c19d1205 ZW |
8731 | tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c), |
8732 | tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c), | |
8733 | tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c), | |
8734 | tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c), | |
8735 | tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub), | |
8736 | tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub), | |
8737 | tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub), | |
8738 | tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub), | |
8739 | tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c), | |
8740 | tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c), | |
8741 | tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3), | |
8742 | tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3), | |
8743 | tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c), | |
8744 | tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c), | |
8745 | tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3), | |
8746 | tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3), | |
8747 | ||
8748 | /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism | |
8749 | for setting PSR flag bits. They are obsolete in V6 and do not | |
8750 | have Thumb equivalents. */ | |
8751 | tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
8752 | tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst), | |
e3cb604e | 8753 | CL(tstp, 110f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
8754 | tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), |
8755 | tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp), | |
e3cb604e | 8756 | CL(cmpp, 150f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
8757 | tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), |
8758 | tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst), | |
e3cb604e | 8759 | CL(cmnp, 170f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
8760 | |
8761 | tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp), | |
8762 | tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp), | |
8763 | tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst), | |
8764 | tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst), | |
8765 | ||
8766 | tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst), | |
8767 | tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst), | |
8768 | tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst), | |
8769 | tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst), | |
8770 | ||
8771 | tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
8772 | tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
8773 | tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
8774 | tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
8775 | ||
8776 | TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi), | |
0110f2b8 | 8777 | tCE(b, a000000, b, 1, (EXPr), branch, t_branch), |
39b41c9c | 8778 | TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23), |
bfae80f2 | 8779 | |
c19d1205 | 8780 | /* Pseudo ops. */ |
e9f89963 | 8781 | tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr), |
2fc8bdac ZW |
8782 | C3(adrl, 28f0000, 2, (RR, EXP), adrl), |
8783 | tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop), | |
c19d1205 ZW |
8784 | |
8785 | /* Thumb-compatibility pseudo ops. */ | |
8786 | tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift), | |
8787 | tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift), | |
8788 | tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift), | |
8789 | tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift), | |
8790 | tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift), | |
2fc8bdac | 8791 | tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift), |
c19d1205 ZW |
8792 | tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift), |
8793 | tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift), | |
8794 | tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg), | |
8795 | tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg), | |
8796 | tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop), | |
8797 | tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop), | |
8798 | ||
8799 | #undef THUMB_VARIANT | |
e74cfd16 | 8800 | #define THUMB_VARIANT &arm_ext_v6 |
2fc8bdac | 8801 | TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy), |
c19d1205 ZW |
8802 | |
8803 | /* V1 instructions with no Thumb analogue prior to V6T2. */ | |
8804 | #undef THUMB_VARIANT | |
e74cfd16 | 8805 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
8806 | TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb), |
8807 | TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb), | |
8808 | TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
8809 | TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst), | |
e3cb604e | 8810 | CL(teqp, 130f000, 2, (RR, SH), cmp), |
c19d1205 ZW |
8811 | |
8812 | TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
8813 | TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
8814 | TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
8815 | TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt), | |
8816 | ||
9c3c69f2 PB |
8817 | TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
8818 | TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 | 8819 | |
9c3c69f2 PB |
8820 | TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), |
8821 | TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm), | |
c19d1205 ZW |
8822 | |
8823 | /* V1 instructions with no Thumb analogue at all. */ | |
8824 | CE(rsc, 0e00000, 3, (RR, oRR, SH), arit), | |
8825 | C3(rscs, 0f00000, 3, (RR, oRR, SH), arit), | |
8826 | ||
8827 | C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm), | |
8828 | C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm), | |
8829 | C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm), | |
8830 | C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm), | |
8831 | C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm), | |
8832 | C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm), | |
8833 | C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm), | |
8834 | C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm), | |
8835 | ||
8836 | #undef ARM_VARIANT | |
e74cfd16 | 8837 | #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */ |
c19d1205 | 8838 | #undef THUMB_VARIANT |
e74cfd16 | 8839 | #define THUMB_VARIANT &arm_ext_v4t |
c19d1205 ZW |
8840 | tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul), |
8841 | tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul), | |
8842 | ||
8843 | #undef THUMB_VARIANT | |
e74cfd16 | 8844 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
8845 | TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), |
8846 | C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas), | |
8847 | ||
8848 | /* Generic coprocessor instructions. */ | |
8849 | TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
8850 | TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8851 | TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8852 | TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8853 | TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8854 | TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
8855 | TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
8856 | ||
8857 | #undef ARM_VARIANT | |
e74cfd16 | 8858 | #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */ |
c19d1205 ZW |
8859 | CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), |
8860 | C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn), | |
8861 | ||
8862 | #undef ARM_VARIANT | |
e74cfd16 | 8863 | #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */ |
c19d1205 ZW |
8864 | TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs), |
8865 | TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr), | |
8866 | ||
8867 | #undef ARM_VARIANT | |
e74cfd16 | 8868 | #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */ |
c19d1205 ZW |
8869 | TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), |
8870 | CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
8871 | TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
8872 | CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
8873 | TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
8874 | CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
8875 | TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull), | |
8876 | CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull), | |
8877 | ||
8878 | #undef ARM_VARIANT | |
e74cfd16 | 8879 | #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */ |
c19d1205 | 8880 | #undef THUMB_VARIANT |
e74cfd16 | 8881 | #define THUMB_VARIANT &arm_ext_v4t |
c19d1205 ZW |
8882 | tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst), |
8883 | tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst), | |
8884 | tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst), | |
8885 | tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst), | |
8886 | tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst), | |
8887 | tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst), | |
8888 | ||
8889 | #undef ARM_VARIANT | |
e74cfd16 | 8890 | #define ARM_VARIANT &arm_ext_v4t_5 |
c19d1205 ZW |
8891 | /* ARM Architecture 4T. */ |
8892 | /* Note: bx (and blx) are required on V5, even if the processor does | |
8893 | not support Thumb. */ | |
8894 | TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx), | |
8895 | ||
8896 | #undef ARM_VARIANT | |
e74cfd16 | 8897 | #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */ |
c19d1205 | 8898 | #undef THUMB_VARIANT |
e74cfd16 | 8899 | #define THUMB_VARIANT &arm_ext_v5t |
c19d1205 ZW |
8900 | /* Note: blx has 2 variants; the .value coded here is for |
8901 | BLX(2). Only this variant has conditional execution. */ | |
8902 | TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx), | |
8903 | TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt), | |
8904 | ||
8905 | #undef THUMB_VARIANT | |
e74cfd16 | 8906 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
8907 | TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz), |
8908 | TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8909 | TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8910 | TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8911 | TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc), | |
8912 | TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp), | |
8913 | TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
8914 | TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg), | |
8915 | ||
8916 | #undef ARM_VARIANT | |
e74cfd16 | 8917 | #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */ |
c19d1205 ZW |
8918 | TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), |
8919 | TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
8920 | TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
8921 | TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
8922 | ||
8923 | TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
8924 | TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla), | |
8925 | ||
8926 | TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
8927 | TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
8928 | TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
8929 | TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal), | |
8930 | ||
8931 | TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
8932 | TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
8933 | TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
8934 | TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
8935 | ||
8936 | TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
8937 | TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
8938 | ||
8939 | TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
8940 | TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
8941 | TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
8942 | TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn), | |
8943 | ||
8944 | #undef ARM_VARIANT | |
e74cfd16 | 8945 | #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */ |
c19d1205 ZW |
8946 | TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld), |
8947 | TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd), | |
8948 | TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd), | |
8949 | ||
8950 | TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
8951 | TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
8952 | ||
8953 | #undef ARM_VARIANT | |
e74cfd16 | 8954 | #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */ |
c19d1205 ZW |
8955 | TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj), |
8956 | ||
8957 | #undef ARM_VARIANT | |
e74cfd16 | 8958 | #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */ |
c19d1205 | 8959 | #undef THUMB_VARIANT |
e74cfd16 | 8960 | #define THUMB_VARIANT &arm_ext_v6 |
c19d1205 ZW |
8961 | TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi), |
8962 | TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi), | |
8963 | tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
8964 | tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
8965 | tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev), | |
8966 | tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
8967 | tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
8968 | tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
8969 | tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
8970 | TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend), | |
8971 | ||
8972 | #undef THUMB_VARIANT | |
e74cfd16 | 8973 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
8974 | TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0), |
8975 | TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex), | |
8976 | TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
8977 | TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c), | |
8978 | TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt), | |
8979 | TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb), | |
8980 | TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8981 | TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8982 | TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8983 | TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8984 | TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8985 | TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8986 | TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8987 | TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8988 | TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8989 | TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8990 | TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8991 | TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8992 | TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8993 | TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8994 | TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8995 | TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8996 | TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8997 | TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8998 | TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
8999 | TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9000 | TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9001 | TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9002 | TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9003 | TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9004 | TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9005 | TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9006 | TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9007 | TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9008 | TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9009 | TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9010 | TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9011 | TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9012 | TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9013 | TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9014 | TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9015 | TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), | |
9016 | TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
9017 | UF(rfeib, 9900a00, 1, (RRw), rfe), | |
9018 | UF(rfeda, 8100a00, 1, (RRw), rfe), | |
9019 | TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
9020 | TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe), | |
9021 | UF(rfefa, 9900a00, 1, (RRw), rfe), | |
9022 | UF(rfeea, 8100a00, 1, (RRw), rfe), | |
9023 | TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe), | |
9024 | TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9025 | TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9026 | TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9027 | TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
9028 | TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9029 | TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9030 | TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah), | |
9031 | TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth), | |
f1022c90 | 9032 | TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd), |
c19d1205 ZW |
9033 | TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), |
9034 | TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9035 | TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9036 | TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9037 | TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9038 | TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9039 | TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9040 | TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal), | |
9041 | TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9042 | TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9043 | TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9044 | TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9045 | TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9046 | TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9047 | TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9048 | TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9049 | TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9050 | TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9051 | TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs), | |
9052 | UF(srsib, 9cd0500, 1, (I31w), srs), | |
9053 | UF(srsda, 84d0500, 1, (I31w), srs), | |
9054 | TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs), | |
9055 | TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat), | |
9056 | TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16), | |
9057 | TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex), | |
9058 | TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal), | |
9059 | TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd), | |
9060 | TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla), | |
9061 | TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat), | |
9062 | TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16), | |
9063 | ||
9064 | #undef ARM_VARIANT | |
e74cfd16 | 9065 | #define ARM_VARIANT &arm_ext_v6k |
c19d1205 | 9066 | #undef THUMB_VARIANT |
e74cfd16 | 9067 | #define THUMB_VARIANT &arm_ext_v6k |
c19d1205 ZW |
9068 | tCE(yield, 320f001, yield, 0, (), noargs, t_hint), |
9069 | tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint), | |
9070 | tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint), | |
9071 | tCE(sev, 320f004, sev, 0, (), noargs, t_hint), | |
9072 | ||
9073 | #undef THUMB_VARIANT | |
e74cfd16 | 9074 | #define THUMB_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9075 | TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), |
9076 | TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn), | |
9077 | TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd), | |
9078 | TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
9079 | TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn), | |
9080 | TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd), | |
9081 | TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs), | |
9082 | ||
9083 | #undef ARM_VARIANT | |
e74cfd16 | 9084 | #define ARM_VARIANT &arm_ext_v6z |
3eb17e6b | 9085 | TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc), |
c19d1205 ZW |
9086 | |
9087 | #undef ARM_VARIANT | |
e74cfd16 | 9088 | #define ARM_VARIANT &arm_ext_v6t2 |
c19d1205 ZW |
9089 | TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc), |
9090 | TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi), | |
9091 | TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
9092 | TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx), | |
9093 | ||
9094 | TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla), | |
9095 | TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16), | |
9096 | TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16), | |
9097 | TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit), | |
9098 | ||
9099 | TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9100 | TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9101 | TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9102 | TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt), | |
9103 | ||
9104 | UT(cbnz, b900, 2, (RR, EXP), t_czb), | |
9105 | UT(cbz, b100, 2, (RR, EXP), t_czb), | |
9106 | /* ARM does not really have an IT instruction. */ | |
9107 | TUE(it, 0, bf08, 1, (COND), it, t_it), | |
9108 | TUE(itt, 0, bf0c, 1, (COND), it, t_it), | |
9109 | TUE(ite, 0, bf04, 1, (COND), it, t_it), | |
9110 | TUE(ittt, 0, bf0e, 1, (COND), it, t_it), | |
9111 | TUE(itet, 0, bf06, 1, (COND), it, t_it), | |
9112 | TUE(itte, 0, bf0a, 1, (COND), it, t_it), | |
9113 | TUE(itee, 0, bf02, 1, (COND), it, t_it), | |
9114 | TUE(itttt, 0, bf0f, 1, (COND), it, t_it), | |
9115 | TUE(itett, 0, bf07, 1, (COND), it, t_it), | |
9116 | TUE(ittet, 0, bf0b, 1, (COND), it, t_it), | |
9117 | TUE(iteet, 0, bf03, 1, (COND), it, t_it), | |
9118 | TUE(ittte, 0, bf0d, 1, (COND), it, t_it), | |
9119 | TUE(itete, 0, bf05, 1, (COND), it, t_it), | |
9120 | TUE(ittee, 0, bf09, 1, (COND), it, t_it), | |
9121 | TUE(iteee, 0, bf01, 1, (COND), it, t_it), | |
9122 | ||
92e90b6e PB |
9123 | /* Thumb2 only instructions. */ |
9124 | #undef ARM_VARIANT | |
e74cfd16 | 9125 | #define ARM_VARIANT NULL |
92e90b6e PB |
9126 | |
9127 | TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
9128 | TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w), | |
9129 | TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb), | |
9130 | TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb), | |
9131 | ||
c19d1205 | 9132 | #undef ARM_VARIANT |
e74cfd16 | 9133 | #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */ |
8f06b2d8 PB |
9134 | cCE(wfs, e200110, 1, (RR), rd), |
9135 | cCE(rfs, e300110, 1, (RR), rd), | |
9136 | cCE(wfc, e400110, 1, (RR), rd), | |
9137 | cCE(rfc, e500110, 1, (RR), rd), | |
9138 | ||
e3cb604e PB |
9139 | cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr), |
9140 | cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr), | |
9141 | cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr), | |
9142 | cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr), | |
9143 | ||
9144 | cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr), | |
9145 | cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr), | |
9146 | cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr), | |
9147 | cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr), | |
9148 | ||
9149 | cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm), | |
9150 | cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm), | |
9151 | cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm), | |
9152 | cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm), | |
9153 | cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm), | |
9154 | cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm), | |
9155 | cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm), | |
9156 | cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm), | |
9157 | cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm), | |
9158 | cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm), | |
9159 | cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm), | |
9160 | cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm), | |
9161 | ||
9162 | cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm), | |
9163 | cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm), | |
9164 | cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm), | |
9165 | cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm), | |
9166 | cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm), | |
9167 | cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm), | |
9168 | cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm), | |
9169 | cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm), | |
9170 | cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm), | |
9171 | cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm), | |
9172 | cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm), | |
9173 | cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm), | |
9174 | ||
9175 | cCL(abss, e208100, 2, (RF, RF_IF), rd_rm), | |
9176 | cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm), | |
9177 | cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm), | |
9178 | cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm), | |
9179 | cCL(absd, e208180, 2, (RF, RF_IF), rd_rm), | |
9180 | cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm), | |
9181 | cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm), | |
9182 | cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm), | |
9183 | cCL(abse, e288100, 2, (RF, RF_IF), rd_rm), | |
9184 | cCL(absep, e288120, 2, (RF, RF_IF), rd_rm), | |
9185 | cCL(absem, e288140, 2, (RF, RF_IF), rd_rm), | |
9186 | cCL(absez, e288160, 2, (RF, RF_IF), rd_rm), | |
9187 | ||
9188 | cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm), | |
9189 | cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm), | |
9190 | cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm), | |
9191 | cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm), | |
9192 | cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm), | |
9193 | cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm), | |
9194 | cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm), | |
9195 | cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm), | |
9196 | cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm), | |
9197 | cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm), | |
9198 | cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm), | |
9199 | cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm), | |
9200 | ||
9201 | cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm), | |
9202 | cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm), | |
9203 | cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm), | |
9204 | cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm), | |
9205 | cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm), | |
9206 | cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm), | |
9207 | cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm), | |
9208 | cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm), | |
9209 | cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm), | |
9210 | cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm), | |
9211 | cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm), | |
9212 | cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm), | |
9213 | ||
9214 | cCL(logs, e508100, 2, (RF, RF_IF), rd_rm), | |
9215 | cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm), | |
9216 | cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm), | |
9217 | cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm), | |
9218 | cCL(logd, e508180, 2, (RF, RF_IF), rd_rm), | |
9219 | cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm), | |
9220 | cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm), | |
9221 | cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm), | |
9222 | cCL(loge, e588100, 2, (RF, RF_IF), rd_rm), | |
9223 | cCL(logep, e588120, 2, (RF, RF_IF), rd_rm), | |
9224 | cCL(logem, e588140, 2, (RF, RF_IF), rd_rm), | |
9225 | cCL(logez, e588160, 2, (RF, RF_IF), rd_rm), | |
9226 | ||
9227 | cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm), | |
9228 | cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm), | |
9229 | cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm), | |
9230 | cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm), | |
9231 | cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm), | |
9232 | cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm), | |
9233 | cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm), | |
9234 | cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm), | |
9235 | cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm), | |
9236 | cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm), | |
9237 | cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm), | |
9238 | cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm), | |
9239 | ||
9240 | cCL(exps, e708100, 2, (RF, RF_IF), rd_rm), | |
9241 | cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm), | |
9242 | cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm), | |
9243 | cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm), | |
9244 | cCL(expd, e708180, 2, (RF, RF_IF), rd_rm), | |
9245 | cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm), | |
9246 | cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm), | |
9247 | cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm), | |
9248 | cCL(expe, e788100, 2, (RF, RF_IF), rd_rm), | |
9249 | cCL(expep, e788120, 2, (RF, RF_IF), rd_rm), | |
9250 | cCL(expem, e788140, 2, (RF, RF_IF), rd_rm), | |
9251 | cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm), | |
9252 | ||
9253 | cCL(sins, e808100, 2, (RF, RF_IF), rd_rm), | |
9254 | cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm), | |
9255 | cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm), | |
9256 | cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm), | |
9257 | cCL(sind, e808180, 2, (RF, RF_IF), rd_rm), | |
9258 | cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm), | |
9259 | cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm), | |
9260 | cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm), | |
9261 | cCL(sine, e888100, 2, (RF, RF_IF), rd_rm), | |
9262 | cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm), | |
9263 | cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm), | |
9264 | cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm), | |
9265 | ||
9266 | cCL(coss, e908100, 2, (RF, RF_IF), rd_rm), | |
9267 | cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm), | |
9268 | cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm), | |
9269 | cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm), | |
9270 | cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm), | |
9271 | cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm), | |
9272 | cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm), | |
9273 | cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm), | |
9274 | cCL(cose, e988100, 2, (RF, RF_IF), rd_rm), | |
9275 | cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm), | |
9276 | cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm), | |
9277 | cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm), | |
9278 | ||
9279 | cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm), | |
9280 | cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm), | |
9281 | cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm), | |
9282 | cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm), | |
9283 | cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm), | |
9284 | cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm), | |
9285 | cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm), | |
9286 | cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm), | |
9287 | cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm), | |
9288 | cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm), | |
9289 | cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm), | |
9290 | cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm), | |
9291 | ||
9292 | cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm), | |
9293 | cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm), | |
9294 | cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm), | |
9295 | cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm), | |
9296 | cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm), | |
9297 | cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm), | |
9298 | cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm), | |
9299 | cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm), | |
9300 | cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm), | |
9301 | cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm), | |
9302 | cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm), | |
9303 | cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm), | |
9304 | ||
9305 | cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm), | |
9306 | cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm), | |
9307 | cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm), | |
9308 | cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm), | |
9309 | cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm), | |
9310 | cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm), | |
9311 | cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm), | |
9312 | cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm), | |
9313 | cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm), | |
9314 | cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm), | |
9315 | cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm), | |
9316 | cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm), | |
9317 | ||
9318 | cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm), | |
9319 | cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm), | |
9320 | cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm), | |
9321 | cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm), | |
9322 | cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm), | |
9323 | cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm), | |
9324 | cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm), | |
9325 | cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm), | |
9326 | cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm), | |
9327 | cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm), | |
9328 | cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm), | |
9329 | cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm), | |
9330 | ||
9331 | cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm), | |
9332 | cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm), | |
9333 | cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm), | |
9334 | cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm), | |
9335 | cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm), | |
9336 | cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm), | |
9337 | cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm), | |
9338 | cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm), | |
9339 | cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm), | |
9340 | cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm), | |
9341 | cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm), | |
9342 | cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm), | |
9343 | ||
9344 | cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm), | |
9345 | cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm), | |
9346 | cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm), | |
9347 | cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm), | |
9348 | cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm), | |
9349 | cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm), | |
9350 | cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm), | |
9351 | cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm), | |
9352 | cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm), | |
9353 | cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm), | |
9354 | cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm), | |
9355 | cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm), | |
9356 | ||
9357 | cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9358 | cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9359 | cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9360 | cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9361 | cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9362 | cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9363 | cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9364 | cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9365 | cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9366 | cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9367 | cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9368 | cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9369 | ||
9370 | cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9371 | cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9372 | cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9373 | cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9374 | cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9375 | cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9376 | cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9377 | cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9378 | cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9379 | cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9380 | cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9381 | cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9382 | ||
9383 | cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9384 | cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9385 | cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9386 | cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9387 | cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9388 | cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9389 | cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9390 | cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9391 | cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9392 | cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9393 | cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9394 | cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9395 | ||
9396 | cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9397 | cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9398 | cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9399 | cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9400 | cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9401 | cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9402 | cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9403 | cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9404 | cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9405 | cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9406 | cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9407 | cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9408 | ||
9409 | cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9410 | cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9411 | cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9412 | cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9413 | cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9414 | cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9415 | cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9416 | cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9417 | cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9418 | cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9419 | cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9420 | cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9421 | ||
9422 | cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9423 | cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9424 | cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9425 | cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9426 | cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9427 | cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9428 | cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9429 | cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9430 | cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9431 | cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9432 | cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9433 | cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9434 | ||
9435 | cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9436 | cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9437 | cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9438 | cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9439 | cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9440 | cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9441 | cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9442 | cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9443 | cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9444 | cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9445 | cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9446 | cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9447 | ||
9448 | cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9449 | cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9450 | cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9451 | cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9452 | cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9453 | cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9454 | cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9455 | cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9456 | cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9457 | cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9458 | cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9459 | cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9460 | ||
9461 | cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9462 | cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9463 | cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9464 | cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9465 | cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9466 | cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9467 | cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9468 | cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9469 | cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9470 | cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9471 | cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9472 | cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9473 | ||
9474 | cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9475 | cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9476 | cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9477 | cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9478 | cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9479 | cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9480 | cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9481 | cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9482 | cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9483 | cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9484 | cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9485 | cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9486 | ||
9487 | cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9488 | cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9489 | cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9490 | cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9491 | cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9492 | cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9493 | cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9494 | cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9495 | cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9496 | cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9497 | cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9498 | cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9499 | ||
9500 | cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9501 | cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9502 | cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9503 | cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9504 | cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9505 | cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9506 | cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9507 | cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9508 | cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9509 | cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9510 | cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9511 | cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9512 | ||
9513 | cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9514 | cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9515 | cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9516 | cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9517 | cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9518 | cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9519 | cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9520 | cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9521 | cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9522 | cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9523 | cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm), | |
9524 | cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm), | |
8f06b2d8 PB |
9525 | |
9526 | cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp), | |
c19d1205 | 9527 | C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp), |
8f06b2d8 | 9528 | cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp), |
c19d1205 ZW |
9529 | C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp), |
9530 | ||
e3cb604e PB |
9531 | cCL(flts, e000110, 2, (RF, RR), rn_rd), |
9532 | cCL(fltsp, e000130, 2, (RF, RR), rn_rd), | |
9533 | cCL(fltsm, e000150, 2, (RF, RR), rn_rd), | |
9534 | cCL(fltsz, e000170, 2, (RF, RR), rn_rd), | |
9535 | cCL(fltd, e000190, 2, (RF, RR), rn_rd), | |
9536 | cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd), | |
9537 | cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd), | |
9538 | cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd), | |
9539 | cCL(flte, e080110, 2, (RF, RR), rn_rd), | |
9540 | cCL(fltep, e080130, 2, (RF, RR), rn_rd), | |
9541 | cCL(fltem, e080150, 2, (RF, RR), rn_rd), | |
9542 | cCL(fltez, e080170, 2, (RF, RR), rn_rd), | |
b99bd4ef | 9543 | |
c19d1205 ZW |
9544 | /* The implementation of the FIX instruction is broken on some |
9545 | assemblers, in that it accepts a precision specifier as well as a | |
9546 | rounding specifier, despite the fact that this is meaningless. | |
9547 | To be more compatible, we accept it as well, though of course it | |
9548 | does not set any bits. */ | |
8f06b2d8 | 9549 | cCE(fix, e100110, 2, (RR, RF), rd_rm), |
e3cb604e PB |
9550 | cCL(fixp, e100130, 2, (RR, RF), rd_rm), |
9551 | cCL(fixm, e100150, 2, (RR, RF), rd_rm), | |
9552 | cCL(fixz, e100170, 2, (RR, RF), rd_rm), | |
9553 | cCL(fixsp, e100130, 2, (RR, RF), rd_rm), | |
9554 | cCL(fixsm, e100150, 2, (RR, RF), rd_rm), | |
9555 | cCL(fixsz, e100170, 2, (RR, RF), rd_rm), | |
9556 | cCL(fixdp, e100130, 2, (RR, RF), rd_rm), | |
9557 | cCL(fixdm, e100150, 2, (RR, RF), rd_rm), | |
9558 | cCL(fixdz, e100170, 2, (RR, RF), rd_rm), | |
9559 | cCL(fixep, e100130, 2, (RR, RF), rd_rm), | |
9560 | cCL(fixem, e100150, 2, (RR, RF), rd_rm), | |
9561 | cCL(fixez, e100170, 2, (RR, RF), rd_rm), | |
bfae80f2 | 9562 | |
c19d1205 ZW |
9563 | /* Instructions that were new with the real FPA, call them V2. */ |
9564 | #undef ARM_VARIANT | |
e74cfd16 | 9565 | #define ARM_VARIANT &fpu_fpa_ext_v2 |
8f06b2d8 | 9566 | cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
9567 | cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
9568 | cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
8f06b2d8 | 9569 | cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
e3cb604e PB |
9570 | cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm), |
9571 | cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm), | |
c19d1205 ZW |
9572 | |
9573 | #undef ARM_VARIANT | |
e74cfd16 | 9574 | #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */ |
c19d1205 | 9575 | /* Moves and type conversions. */ |
8f06b2d8 PB |
9576 | cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic), |
9577 | cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp), | |
9578 | cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg), | |
9579 | cCE(fmstat, ef1fa10, 0, (), noargs), | |
9580 | cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9581 | cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9582 | cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9583 | cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9584 | cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9585 | cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9586 | cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn), | |
9587 | cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd), | |
c19d1205 ZW |
9588 | |
9589 | /* Memory operations. */ | |
8f06b2d8 PB |
9590 | cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst), |
9591 | cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst), | |
9592 | cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9593 | cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9594 | cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9595 | cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9596 | cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9597 | cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9598 | cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
9599 | cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
9600 | cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9601 | cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia), | |
9602 | cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9603 | cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb), | |
9604 | cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9605 | cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia), | |
9606 | cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
9607 | cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb), | |
bfae80f2 | 9608 | |
c19d1205 | 9609 | /* Monadic operations. */ |
8f06b2d8 PB |
9610 | cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic), |
9611 | cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic), | |
9612 | cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
c19d1205 ZW |
9613 | |
9614 | /* Dyadic operations. */ | |
8f06b2d8 PB |
9615 | cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), |
9616 | cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9617 | cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9618 | cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9619 | cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9620 | cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9621 | cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9622 | cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
9623 | cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic), | |
b99bd4ef | 9624 | |
c19d1205 | 9625 | /* Comparisons. */ |
8f06b2d8 PB |
9626 | cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic), |
9627 | cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z), | |
9628 | cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic), | |
9629 | cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z), | |
b99bd4ef | 9630 | |
c19d1205 | 9631 | #undef ARM_VARIANT |
e74cfd16 | 9632 | #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */ |
c19d1205 | 9633 | /* Moves and type conversions. */ |
8f06b2d8 PB |
9634 | cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm), |
9635 | cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
9636 | cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9637 | cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd), | |
9638 | cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd), | |
9639 | cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn), | |
9640 | cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn), | |
9641 | cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
9642 | cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt), | |
9643 | cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9644 | cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9645 | cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
9646 | cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt), | |
c19d1205 ZW |
9647 | |
9648 | /* Memory operations. */ | |
8f06b2d8 PB |
9649 | cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst), |
9650 | cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst), | |
9651 | cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9652 | cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9653 | cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
9654 | cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
9655 | cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9656 | cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia), | |
9657 | cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
9658 | cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb), | |
b99bd4ef | 9659 | |
c19d1205 | 9660 | /* Monadic operations. */ |
8f06b2d8 PB |
9661 | cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm), |
9662 | cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm), | |
9663 | cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm), | |
c19d1205 ZW |
9664 | |
9665 | /* Dyadic operations. */ | |
8f06b2d8 PB |
9666 | cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm), |
9667 | cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9668 | cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9669 | cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9670 | cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9671 | cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9672 | cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9673 | cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
9674 | cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm), | |
b99bd4ef | 9675 | |
c19d1205 | 9676 | /* Comparisons. */ |
8f06b2d8 PB |
9677 | cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm), |
9678 | cCE(fcmpzd, eb50b40, 1, (RVD), rd), | |
9679 | cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm), | |
9680 | cCE(fcmpezd, eb50bc0, 1, (RVD), rd), | |
c19d1205 ZW |
9681 | |
9682 | #undef ARM_VARIANT | |
e74cfd16 | 9683 | #define ARM_VARIANT &fpu_vfp_ext_v2 |
8f06b2d8 PB |
9684 | cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2), |
9685 | cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2), | |
9686 | cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn), | |
9687 | cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm), | |
c19d1205 ZW |
9688 | |
9689 | #undef ARM_VARIANT | |
e74cfd16 | 9690 | #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */ |
8f06b2d8 PB |
9691 | cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia), |
9692 | cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9693 | cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9694 | cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9695 | cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9696 | cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia), | |
9697 | cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar), | |
9698 | cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra), | |
c19d1205 ZW |
9699 | |
9700 | #undef ARM_VARIANT | |
e74cfd16 | 9701 | #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */ |
8f06b2d8 PB |
9702 | cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc), |
9703 | cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc), | |
9704 | cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc), | |
9705 | cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd), | |
9706 | cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd), | |
9707 | cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd), | |
9708 | cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc), | |
9709 | cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc), | |
9710 | cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc), | |
9711 | cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9712 | cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9713 | cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9714 | cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9715 | cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9716 | cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm), | |
9717 | cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
9718 | cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
9719 | cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr), | |
9720 | cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd), | |
9721 | cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn), | |
9722 | cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
9723 | cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
9724 | cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
9725 | cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
9726 | cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
9727 | cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia), | |
9728 | cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn), | |
9729 | cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn), | |
9730 | cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn), | |
9731 | cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn), | |
9732 | cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm), | |
9733 | cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc), | |
9734 | cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc), | |
9735 | cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc), | |
9736 | cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn), | |
9737 | cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn), | |
9738 | cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn), | |
9739 | cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9740 | cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9741 | cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9742 | cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9743 | cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9744 | cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9745 | cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9746 | cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9747 | cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9748 | cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni), | |
9749 | cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9750 | cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9751 | cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9752 | cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9753 | cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9754 | cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9755 | cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9756 | cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9757 | cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9758 | cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9759 | cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9760 | cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9761 | cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9762 | cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9763 | cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9764 | cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9765 | cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9766 | cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9767 | cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9768 | cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
9769 | cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
9770 | cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
9771 | cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
9772 | cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9773 | cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9774 | cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9775 | cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9776 | cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9777 | cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9778 | cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9779 | cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9780 | cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9781 | cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9782 | cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9783 | cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9784 | cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9785 | cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9786 | cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9787 | cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9788 | cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9789 | cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9790 | cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov), | |
9791 | cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9792 | cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9793 | cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9794 | cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9795 | cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9796 | cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9797 | cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9798 | cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9799 | cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9800 | cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9801 | cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9802 | cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9803 | cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9804 | cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9805 | cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9806 | cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9807 | cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9808 | cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9809 | cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9810 | cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9811 | cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9812 | cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh), | |
9813 | cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9814 | cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9815 | cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9816 | cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9817 | cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9818 | cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9819 | cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9820 | cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9821 | cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9822 | cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9823 | cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9824 | cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9825 | cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9826 | cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9827 | cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9828 | cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9829 | cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9830 | cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm), | |
9831 | cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
9832 | cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh), | |
9833 | cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw), | |
9834 | cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd), | |
9835 | cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9836 | cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9837 | cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9838 | cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9839 | cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9840 | cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9841 | cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9842 | cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9843 | cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9844 | cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn), | |
9845 | cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn), | |
9846 | cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn), | |
9847 | cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn), | |
9848 | cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn), | |
9849 | cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn), | |
9850 | cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9851 | cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9852 | cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9853 | cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn), | |
9854 | cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn), | |
9855 | cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn), | |
9856 | cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn), | |
9857 | cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn), | |
9858 | cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn), | |
9859 | cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9860 | cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9861 | cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9862 | cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm), | |
9863 | cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero), | |
c19d1205 ZW |
9864 | |
9865 | #undef ARM_VARIANT | |
e74cfd16 | 9866 | #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */ |
8f06b2d8 PB |
9867 | cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr), |
9868 | cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr), | |
9869 | cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr), | |
9870 | cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr), | |
9871 | cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr), | |
9872 | cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr), | |
9873 | cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr), | |
9874 | cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr), | |
9875 | cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd), | |
9876 | cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn), | |
9877 | cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd), | |
9878 | cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn), | |
9879 | cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd), | |
9880 | cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn), | |
9881 | cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd), | |
9882 | cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn), | |
9883 | cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd), | |
9884 | cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn), | |
9885 | cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn), | |
9886 | cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn), | |
9887 | cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn), | |
9888 | cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn), | |
9889 | cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn), | |
9890 | cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn), | |
9891 | cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn), | |
9892 | cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn), | |
9893 | cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn), | |
9894 | cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn), | |
9895 | cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc), | |
9896 | cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd), | |
9897 | cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn), | |
9898 | cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn), | |
9899 | cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn), | |
9900 | cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn), | |
9901 | cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn), | |
9902 | cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn), | |
9903 | cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn), | |
9904 | cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn), | |
9905 | cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn), | |
9906 | cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn), | |
9907 | cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn), | |
9908 | cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn), | |
9909 | cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple), | |
9910 | cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple), | |
9911 | cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift), | |
9912 | cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift), | |
9913 | cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm), | |
9914 | cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm), | |
9915 | cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm), | |
9916 | cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm), | |
9917 | cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn), | |
9918 | cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn), | |
9919 | cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn), | |
9920 | cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn), | |
9921 | cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm), | |
9922 | cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
9923 | cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm), | |
9924 | cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm), | |
9925 | cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm), | |
9926 | cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm), | |
9927 | cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn), | |
9928 | cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn), | |
9929 | cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn), | |
9930 | cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn), | |
9931 | cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
9932 | cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
9933 | cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
9934 | cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
9935 | cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
9936 | cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm), | |
9937 | cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
9938 | cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm), | |
9939 | cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
9940 | cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad), | |
9941 | cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
9942 | cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad), | |
c19d1205 ZW |
9943 | }; |
9944 | #undef ARM_VARIANT | |
9945 | #undef THUMB_VARIANT | |
9946 | #undef TCE | |
9947 | #undef TCM | |
9948 | #undef TUE | |
9949 | #undef TUF | |
9950 | #undef TCC | |
8f06b2d8 | 9951 | #undef cCE |
e3cb604e PB |
9952 | #undef cCL |
9953 | #undef C3E | |
c19d1205 ZW |
9954 | #undef CE |
9955 | #undef CM | |
9956 | #undef UE | |
9957 | #undef UF | |
9958 | #undef UT | |
9959 | #undef OPS0 | |
9960 | #undef OPS1 | |
9961 | #undef OPS2 | |
9962 | #undef OPS3 | |
9963 | #undef OPS4 | |
9964 | #undef OPS5 | |
9965 | #undef OPS6 | |
9966 | #undef do_0 | |
9967 | \f | |
9968 | /* MD interface: bits in the object file. */ | |
bfae80f2 | 9969 | |
c19d1205 ZW |
9970 | /* Turn an integer of n bytes (in val) into a stream of bytes appropriate |
9971 | for use in the a.out file, and stores them in the array pointed to by buf. | |
9972 | This knows about the endian-ness of the target machine and does | |
9973 | THE RIGHT THING, whatever it is. Possible values for n are 1 (byte) | |
9974 | 2 (short) and 4 (long) Floating numbers are put out as a series of | |
9975 | LITTLENUMS (shorts, here at least). */ | |
b99bd4ef | 9976 | |
c19d1205 ZW |
9977 | void |
9978 | md_number_to_chars (char * buf, valueT val, int n) | |
9979 | { | |
9980 | if (target_big_endian) | |
9981 | number_to_chars_bigendian (buf, val, n); | |
9982 | else | |
9983 | number_to_chars_littleendian (buf, val, n); | |
bfae80f2 RE |
9984 | } |
9985 | ||
c19d1205 ZW |
9986 | static valueT |
9987 | md_chars_to_number (char * buf, int n) | |
bfae80f2 | 9988 | { |
c19d1205 ZW |
9989 | valueT result = 0; |
9990 | unsigned char * where = (unsigned char *) buf; | |
bfae80f2 | 9991 | |
c19d1205 | 9992 | if (target_big_endian) |
b99bd4ef | 9993 | { |
c19d1205 ZW |
9994 | while (n--) |
9995 | { | |
9996 | result <<= 8; | |
9997 | result |= (*where++ & 255); | |
9998 | } | |
b99bd4ef | 9999 | } |
c19d1205 | 10000 | else |
b99bd4ef | 10001 | { |
c19d1205 ZW |
10002 | while (n--) |
10003 | { | |
10004 | result <<= 8; | |
10005 | result |= (where[n] & 255); | |
10006 | } | |
bfae80f2 | 10007 | } |
b99bd4ef | 10008 | |
c19d1205 | 10009 | return result; |
bfae80f2 | 10010 | } |
b99bd4ef | 10011 | |
c19d1205 | 10012 | /* MD interface: Sections. */ |
b99bd4ef | 10013 | |
0110f2b8 PB |
10014 | /* Estimate the size of a frag before relaxing. Assume everything fits in |
10015 | 2 bytes. */ | |
10016 | ||
c19d1205 | 10017 | int |
0110f2b8 | 10018 | md_estimate_size_before_relax (fragS * fragp, |
c19d1205 ZW |
10019 | segT segtype ATTRIBUTE_UNUSED) |
10020 | { | |
0110f2b8 PB |
10021 | fragp->fr_var = 2; |
10022 | return 2; | |
10023 | } | |
10024 | ||
10025 | /* Convert a machine dependent frag. */ | |
10026 | ||
10027 | void | |
10028 | md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp) | |
10029 | { | |
10030 | unsigned long insn; | |
10031 | unsigned long old_op; | |
10032 | char *buf; | |
10033 | expressionS exp; | |
10034 | fixS *fixp; | |
10035 | int reloc_type; | |
10036 | int pc_rel; | |
10037 | int opcode; | |
10038 | ||
10039 | buf = fragp->fr_literal + fragp->fr_fix; | |
10040 | ||
10041 | old_op = bfd_get_16(abfd, buf); | |
10042 | if (fragp->fr_symbol) { | |
10043 | exp.X_op = O_symbol; | |
10044 | exp.X_add_symbol = fragp->fr_symbol; | |
10045 | } else { | |
10046 | exp.X_op = O_constant; | |
10047 | } | |
10048 | exp.X_add_number = fragp->fr_offset; | |
10049 | opcode = fragp->fr_subtype; | |
10050 | switch (opcode) | |
10051 | { | |
10052 | case T_MNEM_ldr_pc: | |
10053 | case T_MNEM_ldr_pc2: | |
10054 | case T_MNEM_ldr_sp: | |
10055 | case T_MNEM_str_sp: | |
10056 | case T_MNEM_ldr: | |
10057 | case T_MNEM_ldrb: | |
10058 | case T_MNEM_ldrh: | |
10059 | case T_MNEM_str: | |
10060 | case T_MNEM_strb: | |
10061 | case T_MNEM_strh: | |
10062 | if (fragp->fr_var == 4) | |
10063 | { | |
10064 | insn = THUMB_OP32(opcode); | |
10065 | if ((old_op >> 12) == 4 || (old_op >> 12) == 9) | |
10066 | { | |
10067 | insn |= (old_op & 0x700) << 4; | |
10068 | } | |
10069 | else | |
10070 | { | |
10071 | insn |= (old_op & 7) << 12; | |
10072 | insn |= (old_op & 0x38) << 13; | |
10073 | } | |
10074 | insn |= 0x00000c00; | |
10075 | put_thumb32_insn (buf, insn); | |
10076 | reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM; | |
10077 | } | |
10078 | else | |
10079 | { | |
10080 | reloc_type = BFD_RELOC_ARM_THUMB_OFFSET; | |
10081 | } | |
10082 | pc_rel = (opcode == T_MNEM_ldr_pc2); | |
10083 | break; | |
10084 | case T_MNEM_adr: | |
10085 | if (fragp->fr_var == 4) | |
10086 | { | |
10087 | insn = THUMB_OP32 (opcode); | |
10088 | insn |= (old_op & 0xf0) << 4; | |
10089 | put_thumb32_insn (buf, insn); | |
10090 | reloc_type = BFD_RELOC_ARM_T32_ADD_PC12; | |
10091 | } | |
10092 | else | |
10093 | { | |
10094 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
10095 | exp.X_add_number -= 4; | |
10096 | } | |
10097 | pc_rel = 1; | |
10098 | break; | |
10099 | case T_MNEM_mov: | |
10100 | case T_MNEM_movs: | |
10101 | case T_MNEM_cmp: | |
10102 | case T_MNEM_cmn: | |
10103 | if (fragp->fr_var == 4) | |
10104 | { | |
10105 | int r0off = (opcode == T_MNEM_mov | |
10106 | || opcode == T_MNEM_movs) ? 0 : 8; | |
10107 | insn = THUMB_OP32 (opcode); | |
10108 | insn = (insn & 0xe1ffffff) | 0x10000000; | |
10109 | insn |= (old_op & 0x700) << r0off; | |
10110 | put_thumb32_insn (buf, insn); | |
10111 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10112 | } | |
10113 | else | |
10114 | { | |
10115 | reloc_type = BFD_RELOC_ARM_THUMB_IMM; | |
10116 | } | |
10117 | pc_rel = 0; | |
10118 | break; | |
10119 | case T_MNEM_b: | |
10120 | if (fragp->fr_var == 4) | |
10121 | { | |
10122 | insn = THUMB_OP32(opcode); | |
10123 | put_thumb32_insn (buf, insn); | |
10124 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25; | |
10125 | } | |
10126 | else | |
10127 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12; | |
10128 | pc_rel = 1; | |
10129 | break; | |
10130 | case T_MNEM_bcond: | |
10131 | if (fragp->fr_var == 4) | |
10132 | { | |
10133 | insn = THUMB_OP32(opcode); | |
10134 | insn |= (old_op & 0xf00) << 14; | |
10135 | put_thumb32_insn (buf, insn); | |
10136 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20; | |
10137 | } | |
10138 | else | |
10139 | reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9; | |
10140 | pc_rel = 1; | |
10141 | break; | |
10142 | case T_MNEM_add_sp: | |
10143 | case T_MNEM_add_pc: | |
10144 | case T_MNEM_inc_sp: | |
10145 | case T_MNEM_dec_sp: | |
10146 | if (fragp->fr_var == 4) | |
10147 | { | |
10148 | /* ??? Choose between add and addw. */ | |
10149 | insn = THUMB_OP32 (opcode); | |
10150 | insn |= (old_op & 0xf0) << 4; | |
10151 | put_thumb32_insn (buf, insn); | |
10152 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10153 | } | |
10154 | else | |
10155 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
10156 | pc_rel = 0; | |
10157 | break; | |
10158 | ||
10159 | case T_MNEM_addi: | |
10160 | case T_MNEM_addis: | |
10161 | case T_MNEM_subi: | |
10162 | case T_MNEM_subis: | |
10163 | if (fragp->fr_var == 4) | |
10164 | { | |
10165 | insn = THUMB_OP32 (opcode); | |
10166 | insn |= (old_op & 0xf0) << 4; | |
10167 | insn |= (old_op & 0xf) << 16; | |
10168 | put_thumb32_insn (buf, insn); | |
10169 | reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE; | |
10170 | } | |
10171 | else | |
10172 | reloc_type = BFD_RELOC_ARM_THUMB_ADD; | |
10173 | pc_rel = 0; | |
10174 | break; | |
10175 | default: | |
10176 | abort(); | |
10177 | } | |
10178 | fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel, | |
10179 | reloc_type); | |
10180 | fixp->fx_file = fragp->fr_file; | |
10181 | fixp->fx_line = fragp->fr_line; | |
10182 | fragp->fr_fix += fragp->fr_var; | |
10183 | } | |
10184 | ||
10185 | /* Return the size of a relaxable immediate operand instruction. | |
10186 | SHIFT and SIZE specify the form of the allowable immediate. */ | |
10187 | static int | |
10188 | relax_immediate (fragS *fragp, int size, int shift) | |
10189 | { | |
10190 | offsetT offset; | |
10191 | offsetT mask; | |
10192 | offsetT low; | |
10193 | ||
10194 | /* ??? Should be able to do better than this. */ | |
10195 | if (fragp->fr_symbol) | |
10196 | return 4; | |
10197 | ||
10198 | low = (1 << shift) - 1; | |
10199 | mask = (1 << (shift + size)) - (1 << shift); | |
10200 | offset = fragp->fr_offset; | |
10201 | /* Force misaligned offsets to 32-bit variant. */ | |
10202 | if (offset & low) | |
10203 | return -4; | |
10204 | if (offset & ~mask) | |
10205 | return 4; | |
10206 | return 2; | |
10207 | } | |
10208 | ||
10209 | /* Return the size of a relaxable adr pseudo-instruction or PC-relative | |
10210 | load. */ | |
10211 | static int | |
10212 | relax_adr (fragS *fragp, asection *sec) | |
10213 | { | |
10214 | addressT addr; | |
10215 | offsetT val; | |
10216 | ||
10217 | /* Assume worst case for symbols not known to be in the same section. */ | |
10218 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
10219 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
10220 | return 4; | |
10221 | ||
10222 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
10223 | addr = fragp->fr_address + fragp->fr_fix; | |
10224 | addr = (addr + 4) & ~3; | |
10225 | /* Fix the insn as the 4-byte version if the target address is not | |
10226 | sufficiently aligned. This is prevents an infinite loop when two | |
10227 | instructions have contradictory range/alignment requirements. */ | |
10228 | if (val & 3) | |
10229 | return -4; | |
10230 | val -= addr; | |
10231 | if (val < 0 || val > 1020) | |
10232 | return 4; | |
10233 | return 2; | |
10234 | } | |
10235 | ||
10236 | /* Return the size of a relaxable add/sub immediate instruction. */ | |
10237 | static int | |
10238 | relax_addsub (fragS *fragp, asection *sec) | |
10239 | { | |
10240 | char *buf; | |
10241 | int op; | |
10242 | ||
10243 | buf = fragp->fr_literal + fragp->fr_fix; | |
10244 | op = bfd_get_16(sec->owner, buf); | |
10245 | if ((op & 0xf) == ((op >> 4) & 0xf)) | |
10246 | return relax_immediate (fragp, 8, 0); | |
10247 | else | |
10248 | return relax_immediate (fragp, 3, 0); | |
10249 | } | |
10250 | ||
10251 | ||
10252 | /* Return the size of a relaxable branch instruction. BITS is the | |
10253 | size of the offset field in the narrow instruction. */ | |
10254 | ||
10255 | static int | |
10256 | relax_branch (fragS *fragp, asection *sec, int bits) | |
10257 | { | |
10258 | addressT addr; | |
10259 | offsetT val; | |
10260 | offsetT limit; | |
10261 | ||
10262 | /* Assume worst case for symbols not known to be in the same section. */ | |
10263 | if (!S_IS_DEFINED(fragp->fr_symbol) | |
10264 | || sec != S_GET_SEGMENT (fragp->fr_symbol)) | |
10265 | return 4; | |
10266 | ||
10267 | val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset; | |
10268 | addr = fragp->fr_address + fragp->fr_fix + 4; | |
10269 | val -= addr; | |
10270 | ||
10271 | /* Offset is a signed value *2 */ | |
10272 | limit = 1 << bits; | |
10273 | if (val >= limit || val < -limit) | |
10274 | return 4; | |
10275 | return 2; | |
10276 | } | |
10277 | ||
10278 | ||
10279 | /* Relax a machine dependent frag. This returns the amount by which | |
10280 | the current size of the frag should change. */ | |
10281 | ||
10282 | int | |
10283 | arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED) | |
10284 | { | |
10285 | int oldsize; | |
10286 | int newsize; | |
10287 | ||
10288 | oldsize = fragp->fr_var; | |
10289 | switch (fragp->fr_subtype) | |
10290 | { | |
10291 | case T_MNEM_ldr_pc2: | |
10292 | newsize = relax_adr(fragp, sec); | |
10293 | break; | |
10294 | case T_MNEM_ldr_pc: | |
10295 | case T_MNEM_ldr_sp: | |
10296 | case T_MNEM_str_sp: | |
10297 | newsize = relax_immediate(fragp, 8, 2); | |
10298 | break; | |
10299 | case T_MNEM_ldr: | |
10300 | case T_MNEM_str: | |
10301 | newsize = relax_immediate(fragp, 5, 2); | |
10302 | break; | |
10303 | case T_MNEM_ldrh: | |
10304 | case T_MNEM_strh: | |
10305 | newsize = relax_immediate(fragp, 5, 1); | |
10306 | break; | |
10307 | case T_MNEM_ldrb: | |
10308 | case T_MNEM_strb: | |
10309 | newsize = relax_immediate(fragp, 5, 0); | |
10310 | break; | |
10311 | case T_MNEM_adr: | |
10312 | newsize = relax_adr(fragp, sec); | |
10313 | break; | |
10314 | case T_MNEM_mov: | |
10315 | case T_MNEM_movs: | |
10316 | case T_MNEM_cmp: | |
10317 | case T_MNEM_cmn: | |
10318 | newsize = relax_immediate(fragp, 8, 0); | |
10319 | break; | |
10320 | case T_MNEM_b: | |
10321 | newsize = relax_branch(fragp, sec, 11); | |
10322 | break; | |
10323 | case T_MNEM_bcond: | |
10324 | newsize = relax_branch(fragp, sec, 8); | |
10325 | break; | |
10326 | case T_MNEM_add_sp: | |
10327 | case T_MNEM_add_pc: | |
10328 | newsize = relax_immediate (fragp, 8, 2); | |
10329 | break; | |
10330 | case T_MNEM_inc_sp: | |
10331 | case T_MNEM_dec_sp: | |
10332 | newsize = relax_immediate (fragp, 7, 2); | |
10333 | break; | |
10334 | case T_MNEM_addi: | |
10335 | case T_MNEM_addis: | |
10336 | case T_MNEM_subi: | |
10337 | case T_MNEM_subis: | |
10338 | newsize = relax_addsub (fragp, sec); | |
10339 | break; | |
10340 | default: | |
10341 | abort(); | |
10342 | } | |
10343 | if (newsize < 0) | |
10344 | { | |
10345 | fragp->fr_var = -newsize; | |
10346 | md_convert_frag (sec->owner, sec, fragp); | |
10347 | frag_wane(fragp); | |
10348 | return -(newsize + oldsize); | |
10349 | } | |
10350 | fragp->fr_var = newsize; | |
10351 | return newsize - oldsize; | |
c19d1205 | 10352 | } |
b99bd4ef | 10353 | |
c19d1205 | 10354 | /* Round up a section size to the appropriate boundary. */ |
b99bd4ef | 10355 | |
c19d1205 ZW |
10356 | valueT |
10357 | md_section_align (segT segment ATTRIBUTE_UNUSED, | |
10358 | valueT size) | |
10359 | { | |
10360 | #ifdef OBJ_ELF | |
10361 | return size; | |
10362 | #else | |
10363 | /* Round all sects to multiple of 4. */ | |
10364 | return (size + 3) & ~3; | |
10365 | #endif | |
bfae80f2 | 10366 | } |
b99bd4ef | 10367 | |
c19d1205 ZW |
10368 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
10369 | of an rs_align_code fragment. */ | |
10370 | ||
10371 | void | |
10372 | arm_handle_align (fragS * fragP) | |
bfae80f2 | 10373 | { |
c19d1205 ZW |
10374 | static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 }; |
10375 | static char const thumb_noop[2] = { 0xc0, 0x46 }; | |
10376 | static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 }; | |
10377 | static char const thumb_bigend_noop[2] = { 0x46, 0xc0 }; | |
10378 | ||
10379 | int bytes, fix, noop_size; | |
10380 | char * p; | |
10381 | const char * noop; | |
bfae80f2 | 10382 | |
c19d1205 | 10383 | if (fragP->fr_type != rs_align_code) |
bfae80f2 RE |
10384 | return; |
10385 | ||
c19d1205 ZW |
10386 | bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix; |
10387 | p = fragP->fr_literal + fragP->fr_fix; | |
10388 | fix = 0; | |
bfae80f2 | 10389 | |
c19d1205 ZW |
10390 | if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE) |
10391 | bytes &= MAX_MEM_FOR_RS_ALIGN_CODE; | |
bfae80f2 | 10392 | |
c19d1205 | 10393 | if (fragP->tc_frag_data) |
a737bd4d | 10394 | { |
c19d1205 ZW |
10395 | if (target_big_endian) |
10396 | noop = thumb_bigend_noop; | |
10397 | else | |
10398 | noop = thumb_noop; | |
10399 | noop_size = sizeof (thumb_noop); | |
7ed4c4c5 NC |
10400 | } |
10401 | else | |
10402 | { | |
c19d1205 ZW |
10403 | if (target_big_endian) |
10404 | noop = arm_bigend_noop; | |
10405 | else | |
10406 | noop = arm_noop; | |
10407 | noop_size = sizeof (arm_noop); | |
7ed4c4c5 | 10408 | } |
a737bd4d | 10409 | |
c19d1205 | 10410 | if (bytes & (noop_size - 1)) |
7ed4c4c5 | 10411 | { |
c19d1205 ZW |
10412 | fix = bytes & (noop_size - 1); |
10413 | memset (p, 0, fix); | |
10414 | p += fix; | |
10415 | bytes -= fix; | |
a737bd4d | 10416 | } |
a737bd4d | 10417 | |
c19d1205 | 10418 | while (bytes >= noop_size) |
a737bd4d | 10419 | { |
c19d1205 ZW |
10420 | memcpy (p, noop, noop_size); |
10421 | p += noop_size; | |
10422 | bytes -= noop_size; | |
10423 | fix += noop_size; | |
a737bd4d NC |
10424 | } |
10425 | ||
c19d1205 ZW |
10426 | fragP->fr_fix += fix; |
10427 | fragP->fr_var = noop_size; | |
a737bd4d NC |
10428 | } |
10429 | ||
c19d1205 ZW |
10430 | /* Called from md_do_align. Used to create an alignment |
10431 | frag in a code section. */ | |
10432 | ||
10433 | void | |
10434 | arm_frag_align_code (int n, int max) | |
bfae80f2 | 10435 | { |
c19d1205 | 10436 | char * p; |
7ed4c4c5 | 10437 | |
c19d1205 ZW |
10438 | /* We assume that there will never be a requirement |
10439 | to support alignments greater than 32 bytes. */ | |
10440 | if (max > MAX_MEM_FOR_RS_ALIGN_CODE) | |
10441 | as_fatal (_("alignments greater than 32 bytes not supported in .text sections.")); | |
bfae80f2 | 10442 | |
c19d1205 ZW |
10443 | p = frag_var (rs_align_code, |
10444 | MAX_MEM_FOR_RS_ALIGN_CODE, | |
10445 | 1, | |
10446 | (relax_substateT) max, | |
10447 | (symbolS *) NULL, | |
10448 | (offsetT) n, | |
10449 | (char *) NULL); | |
10450 | *p = 0; | |
10451 | } | |
bfae80f2 | 10452 | |
c19d1205 | 10453 | /* Perform target specific initialisation of a frag. */ |
bfae80f2 | 10454 | |
c19d1205 ZW |
10455 | void |
10456 | arm_init_frag (fragS * fragP) | |
10457 | { | |
10458 | /* Record whether this frag is in an ARM or a THUMB area. */ | |
10459 | fragP->tc_frag_data = thumb_mode; | |
bfae80f2 RE |
10460 | } |
10461 | ||
c19d1205 ZW |
10462 | #ifdef OBJ_ELF |
10463 | /* When we change sections we need to issue a new mapping symbol. */ | |
10464 | ||
10465 | void | |
10466 | arm_elf_change_section (void) | |
bfae80f2 | 10467 | { |
c19d1205 ZW |
10468 | flagword flags; |
10469 | segment_info_type *seginfo; | |
bfae80f2 | 10470 | |
c19d1205 ZW |
10471 | /* Link an unlinked unwind index table section to the .text section. */ |
10472 | if (elf_section_type (now_seg) == SHT_ARM_EXIDX | |
10473 | && elf_linked_to_section (now_seg) == NULL) | |
10474 | elf_linked_to_section (now_seg) = text_section; | |
10475 | ||
10476 | if (!SEG_NORMAL (now_seg)) | |
bfae80f2 RE |
10477 | return; |
10478 | ||
c19d1205 ZW |
10479 | flags = bfd_get_section_flags (stdoutput, now_seg); |
10480 | ||
10481 | /* We can ignore sections that only contain debug info. */ | |
10482 | if ((flags & SEC_ALLOC) == 0) | |
10483 | return; | |
bfae80f2 | 10484 | |
c19d1205 ZW |
10485 | seginfo = seg_info (now_seg); |
10486 | mapstate = seginfo->tc_segment_info_data.mapstate; | |
10487 | marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency; | |
bfae80f2 RE |
10488 | } |
10489 | ||
c19d1205 ZW |
10490 | int |
10491 | arm_elf_section_type (const char * str, size_t len) | |
e45d0630 | 10492 | { |
c19d1205 ZW |
10493 | if (len == 5 && strncmp (str, "exidx", 5) == 0) |
10494 | return SHT_ARM_EXIDX; | |
e45d0630 | 10495 | |
c19d1205 ZW |
10496 | return -1; |
10497 | } | |
10498 | \f | |
10499 | /* Code to deal with unwinding tables. */ | |
e45d0630 | 10500 | |
c19d1205 | 10501 | static void add_unwind_adjustsp (offsetT); |
e45d0630 | 10502 | |
c19d1205 | 10503 | /* Cenerate and deferred unwind frame offset. */ |
e45d0630 | 10504 | |
bfae80f2 | 10505 | static void |
c19d1205 | 10506 | flush_pending_unwind (void) |
bfae80f2 | 10507 | { |
c19d1205 | 10508 | offsetT offset; |
bfae80f2 | 10509 | |
c19d1205 ZW |
10510 | offset = unwind.pending_offset; |
10511 | unwind.pending_offset = 0; | |
10512 | if (offset != 0) | |
10513 | add_unwind_adjustsp (offset); | |
bfae80f2 RE |
10514 | } |
10515 | ||
c19d1205 ZW |
10516 | /* Add an opcode to this list for this function. Two-byte opcodes should |
10517 | be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse | |
10518 | order. */ | |
10519 | ||
bfae80f2 | 10520 | static void |
c19d1205 | 10521 | add_unwind_opcode (valueT op, int length) |
bfae80f2 | 10522 | { |
c19d1205 ZW |
10523 | /* Add any deferred stack adjustment. */ |
10524 | if (unwind.pending_offset) | |
10525 | flush_pending_unwind (); | |
bfae80f2 | 10526 | |
c19d1205 | 10527 | unwind.sp_restored = 0; |
bfae80f2 | 10528 | |
c19d1205 | 10529 | if (unwind.opcode_count + length > unwind.opcode_alloc) |
bfae80f2 | 10530 | { |
c19d1205 ZW |
10531 | unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE; |
10532 | if (unwind.opcodes) | |
10533 | unwind.opcodes = xrealloc (unwind.opcodes, | |
10534 | unwind.opcode_alloc); | |
10535 | else | |
10536 | unwind.opcodes = xmalloc (unwind.opcode_alloc); | |
bfae80f2 | 10537 | } |
c19d1205 | 10538 | while (length > 0) |
bfae80f2 | 10539 | { |
c19d1205 ZW |
10540 | length--; |
10541 | unwind.opcodes[unwind.opcode_count] = op & 0xff; | |
10542 | op >>= 8; | |
10543 | unwind.opcode_count++; | |
bfae80f2 | 10544 | } |
bfae80f2 RE |
10545 | } |
10546 | ||
c19d1205 ZW |
10547 | /* Add unwind opcodes to adjust the stack pointer. */ |
10548 | ||
bfae80f2 | 10549 | static void |
c19d1205 | 10550 | add_unwind_adjustsp (offsetT offset) |
bfae80f2 | 10551 | { |
c19d1205 | 10552 | valueT op; |
bfae80f2 | 10553 | |
c19d1205 | 10554 | if (offset > 0x200) |
bfae80f2 | 10555 | { |
c19d1205 ZW |
10556 | /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */ |
10557 | char bytes[5]; | |
10558 | int n; | |
10559 | valueT o; | |
bfae80f2 | 10560 | |
c19d1205 ZW |
10561 | /* Long form: 0xb2, uleb128. */ |
10562 | /* This might not fit in a word so add the individual bytes, | |
10563 | remembering the list is built in reverse order. */ | |
10564 | o = (valueT) ((offset - 0x204) >> 2); | |
10565 | if (o == 0) | |
10566 | add_unwind_opcode (0, 1); | |
bfae80f2 | 10567 | |
c19d1205 ZW |
10568 | /* Calculate the uleb128 encoding of the offset. */ |
10569 | n = 0; | |
10570 | while (o) | |
10571 | { | |
10572 | bytes[n] = o & 0x7f; | |
10573 | o >>= 7; | |
10574 | if (o) | |
10575 | bytes[n] |= 0x80; | |
10576 | n++; | |
10577 | } | |
10578 | /* Add the insn. */ | |
10579 | for (; n; n--) | |
10580 | add_unwind_opcode (bytes[n - 1], 1); | |
10581 | add_unwind_opcode (0xb2, 1); | |
10582 | } | |
10583 | else if (offset > 0x100) | |
bfae80f2 | 10584 | { |
c19d1205 ZW |
10585 | /* Two short opcodes. */ |
10586 | add_unwind_opcode (0x3f, 1); | |
10587 | op = (offset - 0x104) >> 2; | |
10588 | add_unwind_opcode (op, 1); | |
bfae80f2 | 10589 | } |
c19d1205 ZW |
10590 | else if (offset > 0) |
10591 | { | |
10592 | /* Short opcode. */ | |
10593 | op = (offset - 4) >> 2; | |
10594 | add_unwind_opcode (op, 1); | |
10595 | } | |
10596 | else if (offset < 0) | |
bfae80f2 | 10597 | { |
c19d1205 ZW |
10598 | offset = -offset; |
10599 | while (offset > 0x100) | |
bfae80f2 | 10600 | { |
c19d1205 ZW |
10601 | add_unwind_opcode (0x7f, 1); |
10602 | offset -= 0x100; | |
bfae80f2 | 10603 | } |
c19d1205 ZW |
10604 | op = ((offset - 4) >> 2) | 0x40; |
10605 | add_unwind_opcode (op, 1); | |
bfae80f2 | 10606 | } |
bfae80f2 RE |
10607 | } |
10608 | ||
c19d1205 ZW |
10609 | /* Finish the list of unwind opcodes for this function. */ |
10610 | static void | |
10611 | finish_unwind_opcodes (void) | |
bfae80f2 | 10612 | { |
c19d1205 | 10613 | valueT op; |
bfae80f2 | 10614 | |
c19d1205 | 10615 | if (unwind.fp_used) |
bfae80f2 | 10616 | { |
c19d1205 ZW |
10617 | /* Adjust sp as neccessary. */ |
10618 | unwind.pending_offset += unwind.fp_offset - unwind.frame_size; | |
10619 | flush_pending_unwind (); | |
bfae80f2 | 10620 | |
c19d1205 ZW |
10621 | /* After restoring sp from the frame pointer. */ |
10622 | op = 0x90 | unwind.fp_reg; | |
10623 | add_unwind_opcode (op, 1); | |
10624 | } | |
10625 | else | |
10626 | flush_pending_unwind (); | |
bfae80f2 RE |
10627 | } |
10628 | ||
bfae80f2 | 10629 | |
c19d1205 ZW |
10630 | /* Start an exception table entry. If idx is nonzero this is an index table |
10631 | entry. */ | |
bfae80f2 RE |
10632 | |
10633 | static void | |
c19d1205 | 10634 | start_unwind_section (const segT text_seg, int idx) |
bfae80f2 | 10635 | { |
c19d1205 ZW |
10636 | const char * text_name; |
10637 | const char * prefix; | |
10638 | const char * prefix_once; | |
10639 | const char * group_name; | |
10640 | size_t prefix_len; | |
10641 | size_t text_len; | |
10642 | char * sec_name; | |
10643 | size_t sec_name_len; | |
10644 | int type; | |
10645 | int flags; | |
10646 | int linkonce; | |
bfae80f2 | 10647 | |
c19d1205 | 10648 | if (idx) |
bfae80f2 | 10649 | { |
c19d1205 ZW |
10650 | prefix = ELF_STRING_ARM_unwind; |
10651 | prefix_once = ELF_STRING_ARM_unwind_once; | |
10652 | type = SHT_ARM_EXIDX; | |
bfae80f2 | 10653 | } |
c19d1205 | 10654 | else |
bfae80f2 | 10655 | { |
c19d1205 ZW |
10656 | prefix = ELF_STRING_ARM_unwind_info; |
10657 | prefix_once = ELF_STRING_ARM_unwind_info_once; | |
10658 | type = SHT_PROGBITS; | |
bfae80f2 RE |
10659 | } |
10660 | ||
c19d1205 ZW |
10661 | text_name = segment_name (text_seg); |
10662 | if (streq (text_name, ".text")) | |
10663 | text_name = ""; | |
10664 | ||
10665 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
10666 | strlen (".gnu.linkonce.t.")) == 0) | |
bfae80f2 | 10667 | { |
c19d1205 ZW |
10668 | prefix = prefix_once; |
10669 | text_name += strlen (".gnu.linkonce.t."); | |
bfae80f2 RE |
10670 | } |
10671 | ||
c19d1205 ZW |
10672 | prefix_len = strlen (prefix); |
10673 | text_len = strlen (text_name); | |
10674 | sec_name_len = prefix_len + text_len; | |
10675 | sec_name = xmalloc (sec_name_len + 1); | |
10676 | memcpy (sec_name, prefix, prefix_len); | |
10677 | memcpy (sec_name + prefix_len, text_name, text_len); | |
10678 | sec_name[prefix_len + text_len] = '\0'; | |
bfae80f2 | 10679 | |
c19d1205 ZW |
10680 | flags = SHF_ALLOC; |
10681 | linkonce = 0; | |
10682 | group_name = 0; | |
bfae80f2 | 10683 | |
c19d1205 ZW |
10684 | /* Handle COMDAT group. */ |
10685 | if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0) | |
bfae80f2 | 10686 | { |
c19d1205 ZW |
10687 | group_name = elf_group_name (text_seg); |
10688 | if (group_name == NULL) | |
10689 | { | |
10690 | as_bad ("Group section `%s' has no group signature", | |
10691 | segment_name (text_seg)); | |
10692 | ignore_rest_of_line (); | |
10693 | return; | |
10694 | } | |
10695 | flags |= SHF_GROUP; | |
10696 | linkonce = 1; | |
bfae80f2 RE |
10697 | } |
10698 | ||
c19d1205 | 10699 | obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0); |
bfae80f2 | 10700 | |
c19d1205 ZW |
10701 | /* Set the setion link for index tables. */ |
10702 | if (idx) | |
10703 | elf_linked_to_section (now_seg) = text_seg; | |
bfae80f2 RE |
10704 | } |
10705 | ||
bfae80f2 | 10706 | |
c19d1205 ZW |
10707 | /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional |
10708 | personality routine data. Returns zero, or the index table value for | |
10709 | and inline entry. */ | |
10710 | ||
10711 | static valueT | |
10712 | create_unwind_entry (int have_data) | |
bfae80f2 | 10713 | { |
c19d1205 ZW |
10714 | int size; |
10715 | addressT where; | |
10716 | char *ptr; | |
10717 | /* The current word of data. */ | |
10718 | valueT data; | |
10719 | /* The number of bytes left in this word. */ | |
10720 | int n; | |
bfae80f2 | 10721 | |
c19d1205 | 10722 | finish_unwind_opcodes (); |
bfae80f2 | 10723 | |
c19d1205 ZW |
10724 | /* Remember the current text section. */ |
10725 | unwind.saved_seg = now_seg; | |
10726 | unwind.saved_subseg = now_subseg; | |
bfae80f2 | 10727 | |
c19d1205 | 10728 | start_unwind_section (now_seg, 0); |
bfae80f2 | 10729 | |
c19d1205 | 10730 | if (unwind.personality_routine == NULL) |
bfae80f2 | 10731 | { |
c19d1205 ZW |
10732 | if (unwind.personality_index == -2) |
10733 | { | |
10734 | if (have_data) | |
10735 | as_bad (_("handerdata in cantunwind frame")); | |
10736 | return 1; /* EXIDX_CANTUNWIND. */ | |
10737 | } | |
bfae80f2 | 10738 | |
c19d1205 ZW |
10739 | /* Use a default personality routine if none is specified. */ |
10740 | if (unwind.personality_index == -1) | |
10741 | { | |
10742 | if (unwind.opcode_count > 3) | |
10743 | unwind.personality_index = 1; | |
10744 | else | |
10745 | unwind.personality_index = 0; | |
10746 | } | |
bfae80f2 | 10747 | |
c19d1205 ZW |
10748 | /* Space for the personality routine entry. */ |
10749 | if (unwind.personality_index == 0) | |
10750 | { | |
10751 | if (unwind.opcode_count > 3) | |
10752 | as_bad (_("too many unwind opcodes for personality routine 0")); | |
bfae80f2 | 10753 | |
c19d1205 ZW |
10754 | if (!have_data) |
10755 | { | |
10756 | /* All the data is inline in the index table. */ | |
10757 | data = 0x80; | |
10758 | n = 3; | |
10759 | while (unwind.opcode_count > 0) | |
10760 | { | |
10761 | unwind.opcode_count--; | |
10762 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
10763 | n--; | |
10764 | } | |
bfae80f2 | 10765 | |
c19d1205 ZW |
10766 | /* Pad with "finish" opcodes. */ |
10767 | while (n--) | |
10768 | data = (data << 8) | 0xb0; | |
bfae80f2 | 10769 | |
c19d1205 ZW |
10770 | return data; |
10771 | } | |
10772 | size = 0; | |
10773 | } | |
10774 | else | |
10775 | /* We get two opcodes "free" in the first word. */ | |
10776 | size = unwind.opcode_count - 2; | |
10777 | } | |
10778 | else | |
10779 | /* An extra byte is required for the opcode count. */ | |
10780 | size = unwind.opcode_count + 1; | |
bfae80f2 | 10781 | |
c19d1205 ZW |
10782 | size = (size + 3) >> 2; |
10783 | if (size > 0xff) | |
10784 | as_bad (_("too many unwind opcodes")); | |
bfae80f2 | 10785 | |
c19d1205 ZW |
10786 | frag_align (2, 0, 0); |
10787 | record_alignment (now_seg, 2); | |
10788 | unwind.table_entry = expr_build_dot (); | |
10789 | ||
10790 | /* Allocate the table entry. */ | |
10791 | ptr = frag_more ((size << 2) + 4); | |
10792 | where = frag_now_fix () - ((size << 2) + 4); | |
bfae80f2 | 10793 | |
c19d1205 | 10794 | switch (unwind.personality_index) |
bfae80f2 | 10795 | { |
c19d1205 ZW |
10796 | case -1: |
10797 | /* ??? Should this be a PLT generating relocation? */ | |
10798 | /* Custom personality routine. */ | |
10799 | fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1, | |
10800 | BFD_RELOC_ARM_PREL31); | |
bfae80f2 | 10801 | |
c19d1205 ZW |
10802 | where += 4; |
10803 | ptr += 4; | |
bfae80f2 | 10804 | |
c19d1205 ZW |
10805 | /* Set the first byte to the number of additional words. */ |
10806 | data = size - 1; | |
10807 | n = 3; | |
10808 | break; | |
bfae80f2 | 10809 | |
c19d1205 ZW |
10810 | /* ABI defined personality routines. */ |
10811 | case 0: | |
10812 | /* Three opcodes bytes are packed into the first word. */ | |
10813 | data = 0x80; | |
10814 | n = 3; | |
10815 | break; | |
bfae80f2 | 10816 | |
c19d1205 ZW |
10817 | case 1: |
10818 | case 2: | |
10819 | /* The size and first two opcode bytes go in the first word. */ | |
10820 | data = ((0x80 + unwind.personality_index) << 8) | size; | |
10821 | n = 2; | |
10822 | break; | |
bfae80f2 | 10823 | |
c19d1205 ZW |
10824 | default: |
10825 | /* Should never happen. */ | |
10826 | abort (); | |
10827 | } | |
bfae80f2 | 10828 | |
c19d1205 ZW |
10829 | /* Pack the opcodes into words (MSB first), reversing the list at the same |
10830 | time. */ | |
10831 | while (unwind.opcode_count > 0) | |
10832 | { | |
10833 | if (n == 0) | |
10834 | { | |
10835 | md_number_to_chars (ptr, data, 4); | |
10836 | ptr += 4; | |
10837 | n = 4; | |
10838 | data = 0; | |
10839 | } | |
10840 | unwind.opcode_count--; | |
10841 | n--; | |
10842 | data = (data << 8) | unwind.opcodes[unwind.opcode_count]; | |
10843 | } | |
10844 | ||
10845 | /* Finish off the last word. */ | |
10846 | if (n < 4) | |
10847 | { | |
10848 | /* Pad with "finish" opcodes. */ | |
10849 | while (n--) | |
10850 | data = (data << 8) | 0xb0; | |
10851 | ||
10852 | md_number_to_chars (ptr, data, 4); | |
10853 | } | |
10854 | ||
10855 | if (!have_data) | |
10856 | { | |
10857 | /* Add an empty descriptor if there is no user-specified data. */ | |
10858 | ptr = frag_more (4); | |
10859 | md_number_to_chars (ptr, 0, 4); | |
10860 | } | |
10861 | ||
10862 | return 0; | |
bfae80f2 RE |
10863 | } |
10864 | ||
c19d1205 ZW |
10865 | /* Convert REGNAME to a DWARF-2 register number. */ |
10866 | ||
10867 | int | |
10868 | tc_arm_regname_to_dw2regnum (const char *regname) | |
bfae80f2 | 10869 | { |
c19d1205 ZW |
10870 | int reg = arm_reg_parse ((char **) ®name, REG_TYPE_RN); |
10871 | ||
10872 | if (reg == FAIL) | |
10873 | return -1; | |
10874 | ||
10875 | return reg; | |
bfae80f2 RE |
10876 | } |
10877 | ||
c19d1205 ZW |
10878 | /* Initialize the DWARF-2 unwind information for this procedure. */ |
10879 | ||
10880 | void | |
10881 | tc_arm_frame_initial_instructions (void) | |
bfae80f2 | 10882 | { |
c19d1205 | 10883 | cfi_add_CFA_def_cfa (REG_SP, 0); |
bfae80f2 | 10884 | } |
c19d1205 | 10885 | #endif /* OBJ_ELF */ |
bfae80f2 | 10886 | |
bfae80f2 | 10887 | |
c19d1205 | 10888 | /* MD interface: Symbol and relocation handling. */ |
bfae80f2 | 10889 | |
2fc8bdac ZW |
10890 | /* Return the address within the segment that a PC-relative fixup is |
10891 | relative to. For ARM, PC-relative fixups applied to instructions | |
10892 | are generally relative to the location of the fixup plus 8 bytes. | |
10893 | Thumb branches are offset by 4, and Thumb loads relative to PC | |
10894 | require special handling. */ | |
bfae80f2 | 10895 | |
c19d1205 | 10896 | long |
2fc8bdac | 10897 | md_pcrel_from_section (fixS * fixP, segT seg) |
bfae80f2 | 10898 | { |
2fc8bdac ZW |
10899 | offsetT base = fixP->fx_where + fixP->fx_frag->fr_address; |
10900 | ||
10901 | /* If this is pc-relative and we are going to emit a relocation | |
10902 | then we just want to put out any pipeline compensation that the linker | |
10903 | will need. Otherwise we want to use the calculated base. */ | |
10904 | if (fixP->fx_pcrel | |
10905 | && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg) | |
10906 | || arm_force_relocation (fixP))) | |
10907 | base = 0; | |
bfae80f2 | 10908 | |
c19d1205 | 10909 | switch (fixP->fx_r_type) |
bfae80f2 | 10910 | { |
2fc8bdac ZW |
10911 | /* PC relative addressing on the Thumb is slightly odd as the |
10912 | bottom two bits of the PC are forced to zero for the | |
10913 | calculation. This happens *after* application of the | |
10914 | pipeline offset. However, Thumb adrl already adjusts for | |
10915 | this, so we need not do it again. */ | |
c19d1205 | 10916 | case BFD_RELOC_ARM_THUMB_ADD: |
2fc8bdac | 10917 | return base & ~3; |
c19d1205 ZW |
10918 | |
10919 | case BFD_RELOC_ARM_THUMB_OFFSET: | |
10920 | case BFD_RELOC_ARM_T32_OFFSET_IMM: | |
e9f89963 | 10921 | case BFD_RELOC_ARM_T32_ADD_PC12: |
8f06b2d8 | 10922 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
2fc8bdac | 10923 | return (base + 4) & ~3; |
c19d1205 | 10924 | |
2fc8bdac ZW |
10925 | /* Thumb branches are simply offset by +4. */ |
10926 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
10927 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
10928 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
10929 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
10930 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
10931 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
10932 | case BFD_RELOC_THUMB_PCREL_BLX: | |
10933 | return base + 4; | |
bfae80f2 | 10934 | |
2fc8bdac ZW |
10935 | /* ARM mode branches are offset by +8. However, the Windows CE |
10936 | loader expects the relocation not to take this into account. */ | |
10937 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
39b41c9c PB |
10938 | case BFD_RELOC_ARM_PCREL_CALL: |
10939 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac ZW |
10940 | case BFD_RELOC_ARM_PCREL_BLX: |
10941 | case BFD_RELOC_ARM_PLT32: | |
c19d1205 | 10942 | #ifdef TE_WINCE |
2fc8bdac | 10943 | return base; |
c19d1205 | 10944 | #else |
2fc8bdac | 10945 | return base + 8; |
c19d1205 | 10946 | #endif |
2fc8bdac ZW |
10947 | |
10948 | /* ARM mode loads relative to PC are also offset by +8. Unlike | |
10949 | branches, the Windows CE loader *does* expect the relocation | |
10950 | to take this into account. */ | |
10951 | case BFD_RELOC_ARM_OFFSET_IMM: | |
10952 | case BFD_RELOC_ARM_OFFSET_IMM8: | |
10953 | case BFD_RELOC_ARM_HWLITERAL: | |
10954 | case BFD_RELOC_ARM_LITERAL: | |
10955 | case BFD_RELOC_ARM_CP_OFF_IMM: | |
10956 | return base + 8; | |
10957 | ||
10958 | ||
10959 | /* Other PC-relative relocations are un-offset. */ | |
10960 | default: | |
10961 | return base; | |
10962 | } | |
bfae80f2 RE |
10963 | } |
10964 | ||
c19d1205 ZW |
10965 | /* Under ELF we need to default _GLOBAL_OFFSET_TABLE. |
10966 | Otherwise we have no need to default values of symbols. */ | |
10967 | ||
10968 | symbolS * | |
10969 | md_undefined_symbol (char * name ATTRIBUTE_UNUSED) | |
bfae80f2 | 10970 | { |
c19d1205 ZW |
10971 | #ifdef OBJ_ELF |
10972 | if (name[0] == '_' && name[1] == 'G' | |
10973 | && streq (name, GLOBAL_OFFSET_TABLE_NAME)) | |
10974 | { | |
10975 | if (!GOT_symbol) | |
10976 | { | |
10977 | if (symbol_find (name)) | |
10978 | as_bad ("GOT already in the symbol table"); | |
bfae80f2 | 10979 | |
c19d1205 ZW |
10980 | GOT_symbol = symbol_new (name, undefined_section, |
10981 | (valueT) 0, & zero_address_frag); | |
10982 | } | |
bfae80f2 | 10983 | |
c19d1205 | 10984 | return GOT_symbol; |
bfae80f2 | 10985 | } |
c19d1205 | 10986 | #endif |
bfae80f2 | 10987 | |
c19d1205 | 10988 | return 0; |
bfae80f2 RE |
10989 | } |
10990 | ||
55cf6793 | 10991 | /* Subroutine of md_apply_fix. Check to see if an immediate can be |
c19d1205 ZW |
10992 | computed as two separate immediate values, added together. We |
10993 | already know that this value cannot be computed by just one ARM | |
10994 | instruction. */ | |
10995 | ||
10996 | static unsigned int | |
10997 | validate_immediate_twopart (unsigned int val, | |
10998 | unsigned int * highpart) | |
bfae80f2 | 10999 | { |
c19d1205 ZW |
11000 | unsigned int a; |
11001 | unsigned int i; | |
bfae80f2 | 11002 | |
c19d1205 ZW |
11003 | for (i = 0; i < 32; i += 2) |
11004 | if (((a = rotate_left (val, i)) & 0xff) != 0) | |
11005 | { | |
11006 | if (a & 0xff00) | |
11007 | { | |
11008 | if (a & ~ 0xffff) | |
11009 | continue; | |
11010 | * highpart = (a >> 8) | ((i + 24) << 7); | |
11011 | } | |
11012 | else if (a & 0xff0000) | |
11013 | { | |
11014 | if (a & 0xff000000) | |
11015 | continue; | |
11016 | * highpart = (a >> 16) | ((i + 16) << 7); | |
11017 | } | |
11018 | else | |
11019 | { | |
11020 | assert (a & 0xff000000); | |
11021 | * highpart = (a >> 24) | ((i + 8) << 7); | |
11022 | } | |
bfae80f2 | 11023 | |
c19d1205 ZW |
11024 | return (a & 0xff) | (i << 7); |
11025 | } | |
bfae80f2 | 11026 | |
c19d1205 | 11027 | return FAIL; |
bfae80f2 RE |
11028 | } |
11029 | ||
c19d1205 ZW |
11030 | static int |
11031 | validate_offset_imm (unsigned int val, int hwse) | |
11032 | { | |
11033 | if ((hwse && val > 255) || val > 4095) | |
11034 | return FAIL; | |
11035 | return val; | |
11036 | } | |
bfae80f2 | 11037 | |
55cf6793 | 11038 | /* Subroutine of md_apply_fix. Do those data_ops which can take a |
c19d1205 ZW |
11039 | negative immediate constant by altering the instruction. A bit of |
11040 | a hack really. | |
11041 | MOV <-> MVN | |
11042 | AND <-> BIC | |
11043 | ADC <-> SBC | |
11044 | by inverting the second operand, and | |
11045 | ADD <-> SUB | |
11046 | CMP <-> CMN | |
11047 | by negating the second operand. */ | |
bfae80f2 | 11048 | |
c19d1205 ZW |
11049 | static int |
11050 | negate_data_op (unsigned long * instruction, | |
11051 | unsigned long value) | |
bfae80f2 | 11052 | { |
c19d1205 ZW |
11053 | int op, new_inst; |
11054 | unsigned long negated, inverted; | |
bfae80f2 | 11055 | |
c19d1205 ZW |
11056 | negated = encode_arm_immediate (-value); |
11057 | inverted = encode_arm_immediate (~value); | |
bfae80f2 | 11058 | |
c19d1205 ZW |
11059 | op = (*instruction >> DATA_OP_SHIFT) & 0xf; |
11060 | switch (op) | |
bfae80f2 | 11061 | { |
c19d1205 ZW |
11062 | /* First negates. */ |
11063 | case OPCODE_SUB: /* ADD <-> SUB */ | |
11064 | new_inst = OPCODE_ADD; | |
11065 | value = negated; | |
11066 | break; | |
bfae80f2 | 11067 | |
c19d1205 ZW |
11068 | case OPCODE_ADD: |
11069 | new_inst = OPCODE_SUB; | |
11070 | value = negated; | |
11071 | break; | |
bfae80f2 | 11072 | |
c19d1205 ZW |
11073 | case OPCODE_CMP: /* CMP <-> CMN */ |
11074 | new_inst = OPCODE_CMN; | |
11075 | value = negated; | |
11076 | break; | |
bfae80f2 | 11077 | |
c19d1205 ZW |
11078 | case OPCODE_CMN: |
11079 | new_inst = OPCODE_CMP; | |
11080 | value = negated; | |
11081 | break; | |
bfae80f2 | 11082 | |
c19d1205 ZW |
11083 | /* Now Inverted ops. */ |
11084 | case OPCODE_MOV: /* MOV <-> MVN */ | |
11085 | new_inst = OPCODE_MVN; | |
11086 | value = inverted; | |
11087 | break; | |
bfae80f2 | 11088 | |
c19d1205 ZW |
11089 | case OPCODE_MVN: |
11090 | new_inst = OPCODE_MOV; | |
11091 | value = inverted; | |
11092 | break; | |
bfae80f2 | 11093 | |
c19d1205 ZW |
11094 | case OPCODE_AND: /* AND <-> BIC */ |
11095 | new_inst = OPCODE_BIC; | |
11096 | value = inverted; | |
11097 | break; | |
bfae80f2 | 11098 | |
c19d1205 ZW |
11099 | case OPCODE_BIC: |
11100 | new_inst = OPCODE_AND; | |
11101 | value = inverted; | |
11102 | break; | |
bfae80f2 | 11103 | |
c19d1205 ZW |
11104 | case OPCODE_ADC: /* ADC <-> SBC */ |
11105 | new_inst = OPCODE_SBC; | |
11106 | value = inverted; | |
11107 | break; | |
bfae80f2 | 11108 | |
c19d1205 ZW |
11109 | case OPCODE_SBC: |
11110 | new_inst = OPCODE_ADC; | |
11111 | value = inverted; | |
11112 | break; | |
bfae80f2 | 11113 | |
c19d1205 ZW |
11114 | /* We cannot do anything. */ |
11115 | default: | |
11116 | return FAIL; | |
b99bd4ef NC |
11117 | } |
11118 | ||
c19d1205 ZW |
11119 | if (value == (unsigned) FAIL) |
11120 | return FAIL; | |
11121 | ||
11122 | *instruction &= OPCODE_MASK; | |
11123 | *instruction |= new_inst << DATA_OP_SHIFT; | |
11124 | return value; | |
b99bd4ef NC |
11125 | } |
11126 | ||
ef8d22e6 PB |
11127 | /* Like negate_data_op, but for Thumb-2. */ |
11128 | ||
11129 | static unsigned int | |
11130 | thumb32_negate_data_op (offsetT *instruction, offsetT value) | |
11131 | { | |
11132 | int op, new_inst; | |
11133 | int rd; | |
11134 | offsetT negated, inverted; | |
11135 | ||
11136 | negated = encode_thumb32_immediate (-value); | |
11137 | inverted = encode_thumb32_immediate (~value); | |
11138 | ||
11139 | rd = (*instruction >> 8) & 0xf; | |
11140 | op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf; | |
11141 | switch (op) | |
11142 | { | |
11143 | /* ADD <-> SUB. Includes CMP <-> CMN. */ | |
11144 | case T2_OPCODE_SUB: | |
11145 | new_inst = T2_OPCODE_ADD; | |
11146 | value = negated; | |
11147 | break; | |
11148 | ||
11149 | case T2_OPCODE_ADD: | |
11150 | new_inst = T2_OPCODE_SUB; | |
11151 | value = negated; | |
11152 | break; | |
11153 | ||
11154 | /* ORR <-> ORN. Includes MOV <-> MVN. */ | |
11155 | case T2_OPCODE_ORR: | |
11156 | new_inst = T2_OPCODE_ORN; | |
11157 | value = inverted; | |
11158 | break; | |
11159 | ||
11160 | case T2_OPCODE_ORN: | |
11161 | new_inst = T2_OPCODE_ORR; | |
11162 | value = inverted; | |
11163 | break; | |
11164 | ||
11165 | /* AND <-> BIC. TST has no inverted equivalent. */ | |
11166 | case T2_OPCODE_AND: | |
11167 | new_inst = T2_OPCODE_BIC; | |
11168 | if (rd == 15) | |
11169 | value = FAIL; | |
11170 | else | |
11171 | value = inverted; | |
11172 | break; | |
11173 | ||
11174 | case T2_OPCODE_BIC: | |
11175 | new_inst = T2_OPCODE_AND; | |
11176 | value = inverted; | |
11177 | break; | |
11178 | ||
11179 | /* ADC <-> SBC */ | |
11180 | case T2_OPCODE_ADC: | |
11181 | new_inst = T2_OPCODE_SBC; | |
11182 | value = inverted; | |
11183 | break; | |
11184 | ||
11185 | case T2_OPCODE_SBC: | |
11186 | new_inst = T2_OPCODE_ADC; | |
11187 | value = inverted; | |
11188 | break; | |
11189 | ||
11190 | /* We cannot do anything. */ | |
11191 | default: | |
11192 | return FAIL; | |
11193 | } | |
11194 | ||
11195 | if (value == FAIL) | |
11196 | return FAIL; | |
11197 | ||
11198 | *instruction &= T2_OPCODE_MASK; | |
11199 | *instruction |= new_inst << T2_DATA_OP_SHIFT; | |
11200 | return value; | |
11201 | } | |
11202 | ||
8f06b2d8 PB |
11203 | /* Read a 32-bit thumb instruction from buf. */ |
11204 | static unsigned long | |
11205 | get_thumb32_insn (char * buf) | |
11206 | { | |
11207 | unsigned long insn; | |
11208 | insn = md_chars_to_number (buf, THUMB_SIZE) << 16; | |
11209 | insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
11210 | ||
11211 | return insn; | |
11212 | } | |
11213 | ||
c19d1205 | 11214 | void |
55cf6793 | 11215 | md_apply_fix (fixS * fixP, |
c19d1205 ZW |
11216 | valueT * valP, |
11217 | segT seg) | |
11218 | { | |
11219 | offsetT value = * valP; | |
11220 | offsetT newval; | |
11221 | unsigned int newimm; | |
11222 | unsigned long temp; | |
11223 | int sign; | |
11224 | char * buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
b99bd4ef | 11225 | |
c19d1205 | 11226 | assert (fixP->fx_r_type <= BFD_RELOC_UNUSED); |
b99bd4ef | 11227 | |
c19d1205 ZW |
11228 | /* Note whether this will delete the relocation. */ |
11229 | if (fixP->fx_addsy == 0 && !fixP->fx_pcrel) | |
11230 | fixP->fx_done = 1; | |
b99bd4ef | 11231 | |
adbaf948 ZW |
11232 | /* On a 64-bit host, silently truncate 'value' to 32 bits for |
11233 | consistency with the behavior on 32-bit hosts. Remember value | |
11234 | for emit_reloc. */ | |
11235 | value &= 0xffffffff; | |
11236 | value ^= 0x80000000; | |
11237 | value -= 0x80000000; | |
11238 | ||
11239 | *valP = value; | |
c19d1205 | 11240 | fixP->fx_addnumber = value; |
b99bd4ef | 11241 | |
adbaf948 ZW |
11242 | /* Same treatment for fixP->fx_offset. */ |
11243 | fixP->fx_offset &= 0xffffffff; | |
11244 | fixP->fx_offset ^= 0x80000000; | |
11245 | fixP->fx_offset -= 0x80000000; | |
11246 | ||
c19d1205 | 11247 | switch (fixP->fx_r_type) |
b99bd4ef | 11248 | { |
c19d1205 ZW |
11249 | case BFD_RELOC_NONE: |
11250 | /* This will need to go in the object file. */ | |
11251 | fixP->fx_done = 0; | |
11252 | break; | |
b99bd4ef | 11253 | |
c19d1205 ZW |
11254 | case BFD_RELOC_ARM_IMMEDIATE: |
11255 | /* We claim that this fixup has been processed here, | |
11256 | even if in fact we generate an error because we do | |
11257 | not have a reloc for it, so tc_gen_reloc will reject it. */ | |
11258 | fixP->fx_done = 1; | |
b99bd4ef | 11259 | |
c19d1205 ZW |
11260 | if (fixP->fx_addsy |
11261 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
b99bd4ef | 11262 | { |
c19d1205 ZW |
11263 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11264 | _("undefined symbol %s used as an immediate value"), | |
11265 | S_GET_NAME (fixP->fx_addsy)); | |
11266 | break; | |
b99bd4ef NC |
11267 | } |
11268 | ||
c19d1205 ZW |
11269 | newimm = encode_arm_immediate (value); |
11270 | temp = md_chars_to_number (buf, INSN_SIZE); | |
11271 | ||
11272 | /* If the instruction will fail, see if we can fix things up by | |
11273 | changing the opcode. */ | |
11274 | if (newimm == (unsigned int) FAIL | |
11275 | && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL) | |
b99bd4ef | 11276 | { |
c19d1205 ZW |
11277 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11278 | _("invalid constant (%lx) after fixup"), | |
11279 | (unsigned long) value); | |
11280 | break; | |
b99bd4ef | 11281 | } |
b99bd4ef | 11282 | |
c19d1205 ZW |
11283 | newimm |= (temp & 0xfffff000); |
11284 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
11285 | break; | |
b99bd4ef | 11286 | |
c19d1205 ZW |
11287 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
11288 | { | |
11289 | unsigned int highpart = 0; | |
11290 | unsigned int newinsn = 0xe1a00000; /* nop. */ | |
b99bd4ef | 11291 | |
c19d1205 ZW |
11292 | newimm = encode_arm_immediate (value); |
11293 | temp = md_chars_to_number (buf, INSN_SIZE); | |
b99bd4ef | 11294 | |
c19d1205 ZW |
11295 | /* If the instruction will fail, see if we can fix things up by |
11296 | changing the opcode. */ | |
11297 | if (newimm == (unsigned int) FAIL | |
11298 | && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL) | |
11299 | { | |
11300 | /* No ? OK - try using two ADD instructions to generate | |
11301 | the value. */ | |
11302 | newimm = validate_immediate_twopart (value, & highpart); | |
b99bd4ef | 11303 | |
c19d1205 ZW |
11304 | /* Yes - then make sure that the second instruction is |
11305 | also an add. */ | |
11306 | if (newimm != (unsigned int) FAIL) | |
11307 | newinsn = temp; | |
11308 | /* Still No ? Try using a negated value. */ | |
11309 | else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL) | |
11310 | temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT; | |
11311 | /* Otherwise - give up. */ | |
11312 | else | |
11313 | { | |
11314 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11315 | _("unable to compute ADRL instructions for PC offset of 0x%lx"), | |
11316 | (long) value); | |
11317 | break; | |
11318 | } | |
b99bd4ef | 11319 | |
c19d1205 ZW |
11320 | /* Replace the first operand in the 2nd instruction (which |
11321 | is the PC) with the destination register. We have | |
11322 | already added in the PC in the first instruction and we | |
11323 | do not want to do it again. */ | |
11324 | newinsn &= ~ 0xf0000; | |
11325 | newinsn |= ((newinsn & 0x0f000) << 4); | |
11326 | } | |
b99bd4ef | 11327 | |
c19d1205 ZW |
11328 | newimm |= (temp & 0xfffff000); |
11329 | md_number_to_chars (buf, (valueT) newimm, INSN_SIZE); | |
b99bd4ef | 11330 | |
c19d1205 ZW |
11331 | highpart |= (newinsn & 0xfffff000); |
11332 | md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE); | |
11333 | } | |
11334 | break; | |
b99bd4ef | 11335 | |
c19d1205 ZW |
11336 | case BFD_RELOC_ARM_OFFSET_IMM: |
11337 | case BFD_RELOC_ARM_LITERAL: | |
11338 | sign = value >= 0; | |
b99bd4ef | 11339 | |
c19d1205 ZW |
11340 | if (value < 0) |
11341 | value = - value; | |
b99bd4ef | 11342 | |
c19d1205 | 11343 | if (validate_offset_imm (value, 0) == FAIL) |
f03698e6 | 11344 | { |
c19d1205 ZW |
11345 | if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL) |
11346 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11347 | _("invalid literal constant: pool needs to be closer")); | |
11348 | else | |
11349 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11350 | _("bad immediate value for offset (%ld)"), | |
11351 | (long) value); | |
11352 | break; | |
f03698e6 RE |
11353 | } |
11354 | ||
c19d1205 ZW |
11355 | newval = md_chars_to_number (buf, INSN_SIZE); |
11356 | newval &= 0xff7ff000; | |
11357 | newval |= value | (sign ? INDEX_UP : 0); | |
11358 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11359 | break; | |
b99bd4ef | 11360 | |
c19d1205 ZW |
11361 | case BFD_RELOC_ARM_OFFSET_IMM8: |
11362 | case BFD_RELOC_ARM_HWLITERAL: | |
11363 | sign = value >= 0; | |
b99bd4ef | 11364 | |
c19d1205 ZW |
11365 | if (value < 0) |
11366 | value = - value; | |
b99bd4ef | 11367 | |
c19d1205 | 11368 | if (validate_offset_imm (value, 1) == FAIL) |
b99bd4ef | 11369 | { |
c19d1205 ZW |
11370 | if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL) |
11371 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11372 | _("invalid literal constant: pool needs to be closer")); | |
11373 | else | |
11374 | as_bad (_("bad immediate value for half-word offset (%ld)"), | |
11375 | (long) value); | |
11376 | break; | |
b99bd4ef NC |
11377 | } |
11378 | ||
c19d1205 ZW |
11379 | newval = md_chars_to_number (buf, INSN_SIZE); |
11380 | newval &= 0xff7ff0f0; | |
11381 | newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0); | |
11382 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11383 | break; | |
b99bd4ef | 11384 | |
c19d1205 ZW |
11385 | case BFD_RELOC_ARM_T32_OFFSET_U8: |
11386 | if (value < 0 || value > 1020 || value % 4 != 0) | |
11387 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11388 | _("bad immediate value for offset (%ld)"), (long) value); | |
11389 | value /= 4; | |
b99bd4ef | 11390 | |
c19d1205 | 11391 | newval = md_chars_to_number (buf+2, THUMB_SIZE); |
c19d1205 ZW |
11392 | newval |= value; |
11393 | md_number_to_chars (buf+2, newval, THUMB_SIZE); | |
11394 | break; | |
b99bd4ef | 11395 | |
c19d1205 ZW |
11396 | case BFD_RELOC_ARM_T32_OFFSET_IMM: |
11397 | /* This is a complicated relocation used for all varieties of Thumb32 | |
11398 | load/store instruction with immediate offset: | |
11399 | ||
11400 | 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit, | |
11401 | *4, optional writeback(W) | |
11402 | (doubleword load/store) | |
11403 | ||
11404 | 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel | |
11405 | 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit | |
11406 | 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction) | |
11407 | 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit | |
11408 | 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit | |
11409 | ||
11410 | Uppercase letters indicate bits that are already encoded at | |
11411 | this point. Lowercase letters are our problem. For the | |
11412 | second block of instructions, the secondary opcode nybble | |
11413 | (bits 8..11) is present, and bit 23 is zero, even if this is | |
11414 | a PC-relative operation. */ | |
11415 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11416 | newval <<= 16; | |
11417 | newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE); | |
b99bd4ef | 11418 | |
c19d1205 | 11419 | if ((newval & 0xf0000000) == 0xe0000000) |
b99bd4ef | 11420 | { |
c19d1205 ZW |
11421 | /* Doubleword load/store: 8-bit offset, scaled by 4. */ |
11422 | if (value >= 0) | |
11423 | newval |= (1 << 23); | |
11424 | else | |
11425 | value = -value; | |
11426 | if (value % 4 != 0) | |
11427 | { | |
11428 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11429 | _("offset not a multiple of 4")); | |
11430 | break; | |
11431 | } | |
11432 | value /= 4; | |
216d22bc | 11433 | if (value > 0xff) |
c19d1205 ZW |
11434 | { |
11435 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11436 | _("offset out of range")); | |
11437 | break; | |
11438 | } | |
11439 | newval &= ~0xff; | |
b99bd4ef | 11440 | } |
c19d1205 | 11441 | else if ((newval & 0x000f0000) == 0x000f0000) |
b99bd4ef | 11442 | { |
c19d1205 ZW |
11443 | /* PC-relative, 12-bit offset. */ |
11444 | if (value >= 0) | |
11445 | newval |= (1 << 23); | |
11446 | else | |
11447 | value = -value; | |
216d22bc | 11448 | if (value > 0xfff) |
c19d1205 ZW |
11449 | { |
11450 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11451 | _("offset out of range")); | |
11452 | break; | |
11453 | } | |
11454 | newval &= ~0xfff; | |
b99bd4ef | 11455 | } |
c19d1205 | 11456 | else if ((newval & 0x00000100) == 0x00000100) |
b99bd4ef | 11457 | { |
c19d1205 ZW |
11458 | /* Writeback: 8-bit, +/- offset. */ |
11459 | if (value >= 0) | |
11460 | newval |= (1 << 9); | |
11461 | else | |
11462 | value = -value; | |
216d22bc | 11463 | if (value > 0xff) |
c19d1205 ZW |
11464 | { |
11465 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11466 | _("offset out of range")); | |
11467 | break; | |
11468 | } | |
11469 | newval &= ~0xff; | |
b99bd4ef | 11470 | } |
c19d1205 | 11471 | else if ((newval & 0x00000f00) == 0x00000e00) |
b99bd4ef | 11472 | { |
c19d1205 | 11473 | /* T-instruction: positive 8-bit offset. */ |
216d22bc | 11474 | if (value < 0 || value > 0xff) |
b99bd4ef | 11475 | { |
c19d1205 ZW |
11476 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11477 | _("offset out of range")); | |
11478 | break; | |
b99bd4ef | 11479 | } |
c19d1205 ZW |
11480 | newval &= ~0xff; |
11481 | newval |= value; | |
b99bd4ef NC |
11482 | } |
11483 | else | |
b99bd4ef | 11484 | { |
c19d1205 ZW |
11485 | /* Positive 12-bit or negative 8-bit offset. */ |
11486 | int limit; | |
11487 | if (value >= 0) | |
b99bd4ef | 11488 | { |
c19d1205 ZW |
11489 | newval |= (1 << 23); |
11490 | limit = 0xfff; | |
11491 | } | |
11492 | else | |
11493 | { | |
11494 | value = -value; | |
11495 | limit = 0xff; | |
11496 | } | |
11497 | if (value > limit) | |
11498 | { | |
11499 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11500 | _("offset out of range")); | |
11501 | break; | |
b99bd4ef | 11502 | } |
c19d1205 | 11503 | newval &= ~limit; |
b99bd4ef | 11504 | } |
b99bd4ef | 11505 | |
c19d1205 ZW |
11506 | newval |= value; |
11507 | md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE); | |
11508 | md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE); | |
11509 | break; | |
404ff6b5 | 11510 | |
c19d1205 ZW |
11511 | case BFD_RELOC_ARM_SHIFT_IMM: |
11512 | newval = md_chars_to_number (buf, INSN_SIZE); | |
11513 | if (((unsigned long) value) > 32 | |
11514 | || (value == 32 | |
11515 | && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60))) | |
11516 | { | |
11517 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11518 | _("shift expression is too large")); | |
11519 | break; | |
11520 | } | |
404ff6b5 | 11521 | |
c19d1205 ZW |
11522 | if (value == 0) |
11523 | /* Shifts of zero must be done as lsl. */ | |
11524 | newval &= ~0x60; | |
11525 | else if (value == 32) | |
11526 | value = 0; | |
11527 | newval &= 0xfffff07f; | |
11528 | newval |= (value & 0x1f) << 7; | |
11529 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11530 | break; | |
404ff6b5 | 11531 | |
c19d1205 | 11532 | case BFD_RELOC_ARM_T32_IMMEDIATE: |
92e90b6e | 11533 | case BFD_RELOC_ARM_T32_IMM12: |
e9f89963 | 11534 | case BFD_RELOC_ARM_T32_ADD_PC12: |
c19d1205 ZW |
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; | |
404ff6b5 | 11539 | |
c19d1205 ZW |
11540 | if (fixP->fx_addsy |
11541 | && ! S_IS_DEFINED (fixP->fx_addsy)) | |
11542 | { | |
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; | |
11547 | } | |
404ff6b5 | 11548 | |
c19d1205 ZW |
11549 | newval = md_chars_to_number (buf, THUMB_SIZE); |
11550 | newval <<= 16; | |
11551 | newval |= md_chars_to_number (buf+2, THUMB_SIZE); | |
404ff6b5 | 11552 | |
e9f89963 PB |
11553 | /* FUTURE: Implement analogue of negate_data_op for T32. */ |
11554 | if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE) | |
ef8d22e6 PB |
11555 | { |
11556 | newimm = encode_thumb32_immediate (value); | |
11557 | if (newimm == (unsigned int) FAIL) | |
11558 | newimm = thumb32_negate_data_op (&newval, value); | |
11559 | } | |
e9f89963 | 11560 | else |
92e90b6e | 11561 | { |
e9f89963 PB |
11562 | /* 12 bit immediate for addw/subw. */ |
11563 | if (value < 0) | |
11564 | { | |
11565 | value = -value; | |
11566 | newval ^= 0x00a00000; | |
11567 | } | |
92e90b6e PB |
11568 | if (value > 0xfff) |
11569 | newimm = (unsigned int) FAIL; | |
11570 | else | |
11571 | newimm = value; | |
11572 | } | |
cc8a6dd0 | 11573 | |
c19d1205 | 11574 | if (newimm == (unsigned int)FAIL) |
3631a3c8 | 11575 | { |
c19d1205 ZW |
11576 | as_bad_where (fixP->fx_file, fixP->fx_line, |
11577 | _("invalid constant (%lx) after fixup"), | |
11578 | (unsigned long) value); | |
11579 | break; | |
3631a3c8 NC |
11580 | } |
11581 | ||
c19d1205 ZW |
11582 | newval |= (newimm & 0x800) << 15; |
11583 | newval |= (newimm & 0x700) << 4; | |
11584 | newval |= (newimm & 0x0ff); | |
cc8a6dd0 | 11585 | |
c19d1205 ZW |
11586 | md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE); |
11587 | md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE); | |
11588 | break; | |
a737bd4d | 11589 | |
3eb17e6b | 11590 | case BFD_RELOC_ARM_SMC: |
c19d1205 ZW |
11591 | if (((unsigned long) value) > 0xffff) |
11592 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3eb17e6b | 11593 | _("invalid smc expression")); |
2fc8bdac | 11594 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
11595 | newval |= (value & 0xf) | ((value & 0xfff0) << 4); |
11596 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11597 | break; | |
a737bd4d | 11598 | |
c19d1205 | 11599 | case BFD_RELOC_ARM_SWI: |
adbaf948 | 11600 | if (fixP->tc_fix_data != 0) |
c19d1205 ZW |
11601 | { |
11602 | if (((unsigned long) value) > 0xff) | |
11603 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11604 | _("invalid swi expression")); | |
2fc8bdac | 11605 | newval = md_chars_to_number (buf, THUMB_SIZE); |
c19d1205 ZW |
11606 | newval |= value; |
11607 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11608 | } | |
11609 | else | |
11610 | { | |
11611 | if (((unsigned long) value) > 0x00ffffff) | |
11612 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11613 | _("invalid swi expression")); | |
2fc8bdac | 11614 | newval = md_chars_to_number (buf, INSN_SIZE); |
c19d1205 ZW |
11615 | newval |= value; |
11616 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11617 | } | |
11618 | break; | |
a737bd4d | 11619 | |
c19d1205 ZW |
11620 | case BFD_RELOC_ARM_MULTI: |
11621 | if (((unsigned long) value) > 0xffff) | |
11622 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11623 | _("invalid expression in load/store multiple")); | |
11624 | newval = value | md_chars_to_number (buf, INSN_SIZE); | |
11625 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11626 | break; | |
a737bd4d | 11627 | |
c19d1205 | 11628 | #ifdef OBJ_ELF |
39b41c9c PB |
11629 | case BFD_RELOC_ARM_PCREL_CALL: |
11630 | newval = md_chars_to_number (buf, INSN_SIZE); | |
11631 | if ((newval & 0xf0000000) == 0xf0000000) | |
11632 | temp = 1; | |
11633 | else | |
11634 | temp = 3; | |
11635 | goto arm_branch_common; | |
11636 | ||
11637 | case BFD_RELOC_ARM_PCREL_JUMP: | |
2fc8bdac | 11638 | case BFD_RELOC_ARM_PLT32: |
c19d1205 | 11639 | #endif |
39b41c9c PB |
11640 | case BFD_RELOC_ARM_PCREL_BRANCH: |
11641 | temp = 3; | |
11642 | goto arm_branch_common; | |
a737bd4d | 11643 | |
39b41c9c PB |
11644 | case BFD_RELOC_ARM_PCREL_BLX: |
11645 | temp = 1; | |
11646 | arm_branch_common: | |
c19d1205 | 11647 | /* We are going to store value (shifted right by two) in the |
39b41c9c PB |
11648 | instruction, in a 24 bit, signed field. Bits 26 through 32 either |
11649 | all clear or all set and bit 0 must be clear. For B/BL bit 1 must | |
11650 | also be be clear. */ | |
11651 | if (value & temp) | |
c19d1205 | 11652 | as_bad_where (fixP->fx_file, fixP->fx_line, |
2fc8bdac ZW |
11653 | _("misaligned branch destination")); |
11654 | if ((value & (offsetT)0xfe000000) != (offsetT)0 | |
11655 | && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000) | |
11656 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11657 | _("branch out of range")); | |
a737bd4d | 11658 | |
2fc8bdac | 11659 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 11660 | { |
2fc8bdac ZW |
11661 | newval = md_chars_to_number (buf, INSN_SIZE); |
11662 | newval |= (value >> 2) & 0x00ffffff; | |
11663 | md_number_to_chars (buf, newval, INSN_SIZE); | |
c19d1205 | 11664 | } |
c19d1205 | 11665 | break; |
a737bd4d | 11666 | |
c19d1205 | 11667 | case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */ |
2fc8bdac ZW |
11668 | /* CZB can only branch forward. */ |
11669 | if (value & ~0x7e) | |
11670 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11671 | _("branch out of range")); | |
a737bd4d | 11672 | |
2fc8bdac ZW |
11673 | if (fixP->fx_done || !seg->use_rela_p) |
11674 | { | |
11675 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
c19d1205 | 11676 | newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3); |
2fc8bdac ZW |
11677 | md_number_to_chars (buf, newval, THUMB_SIZE); |
11678 | } | |
c19d1205 | 11679 | break; |
a737bd4d | 11680 | |
c19d1205 | 11681 | case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */ |
2fc8bdac ZW |
11682 | if ((value & ~0xff) && ((value & ~0xff) != ~0xff)) |
11683 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11684 | _("branch out of range")); | |
a737bd4d | 11685 | |
2fc8bdac ZW |
11686 | if (fixP->fx_done || !seg->use_rela_p) |
11687 | { | |
11688 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11689 | newval |= (value & 0x1ff) >> 1; | |
11690 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11691 | } | |
c19d1205 | 11692 | break; |
a737bd4d | 11693 | |
c19d1205 | 11694 | case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */ |
2fc8bdac ZW |
11695 | if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff)) |
11696 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11697 | _("branch out of range")); | |
a737bd4d | 11698 | |
2fc8bdac ZW |
11699 | if (fixP->fx_done || !seg->use_rela_p) |
11700 | { | |
11701 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11702 | newval |= (value & 0xfff) >> 1; | |
11703 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11704 | } | |
c19d1205 | 11705 | break; |
a737bd4d | 11706 | |
c19d1205 | 11707 | case BFD_RELOC_THUMB_PCREL_BRANCH20: |
2fc8bdac ZW |
11708 | if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff)) |
11709 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11710 | _("conditional branch out of range")); | |
404ff6b5 | 11711 | |
2fc8bdac ZW |
11712 | if (fixP->fx_done || !seg->use_rela_p) |
11713 | { | |
11714 | offsetT newval2; | |
11715 | addressT S, J1, J2, lo, hi; | |
404ff6b5 | 11716 | |
2fc8bdac ZW |
11717 | S = (value & 0x00100000) >> 20; |
11718 | J2 = (value & 0x00080000) >> 19; | |
11719 | J1 = (value & 0x00040000) >> 18; | |
11720 | hi = (value & 0x0003f000) >> 12; | |
11721 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 11722 | |
2fc8bdac ZW |
11723 | newval = md_chars_to_number (buf, THUMB_SIZE); |
11724 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
11725 | newval |= (S << 10) | hi; | |
11726 | newval2 |= (J1 << 13) | (J2 << 11) | lo; | |
11727 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11728 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
11729 | } | |
c19d1205 | 11730 | break; |
6c43fab6 | 11731 | |
c19d1205 ZW |
11732 | case BFD_RELOC_THUMB_PCREL_BLX: |
11733 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
2fc8bdac ZW |
11734 | if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff)) |
11735 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11736 | _("branch out of range")); | |
404ff6b5 | 11737 | |
2fc8bdac ZW |
11738 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX) |
11739 | /* For a BLX instruction, make sure that the relocation is rounded up | |
11740 | to a word boundary. This follows the semantics of the instruction | |
11741 | which specifies that bit 1 of the target address will come from bit | |
11742 | 1 of the base address. */ | |
11743 | value = (value + 1) & ~ 1; | |
404ff6b5 | 11744 | |
2fc8bdac | 11745 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 11746 | { |
2fc8bdac ZW |
11747 | offsetT newval2; |
11748 | ||
11749 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11750 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
11751 | newval |= (value & 0x7fffff) >> 12; | |
11752 | newval2 |= (value & 0xfff) >> 1; | |
11753 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11754 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
c19d1205 | 11755 | } |
c19d1205 | 11756 | break; |
404ff6b5 | 11757 | |
c19d1205 | 11758 | case BFD_RELOC_THUMB_PCREL_BRANCH25: |
2fc8bdac ZW |
11759 | if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff)) |
11760 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11761 | _("branch out of range")); | |
6c43fab6 | 11762 | |
2fc8bdac ZW |
11763 | if (fixP->fx_done || !seg->use_rela_p) |
11764 | { | |
11765 | offsetT newval2; | |
11766 | addressT S, I1, I2, lo, hi; | |
6c43fab6 | 11767 | |
2fc8bdac ZW |
11768 | S = (value & 0x01000000) >> 24; |
11769 | I1 = (value & 0x00800000) >> 23; | |
11770 | I2 = (value & 0x00400000) >> 22; | |
11771 | hi = (value & 0x003ff000) >> 12; | |
11772 | lo = (value & 0x00000ffe) >> 1; | |
6c43fab6 | 11773 | |
2fc8bdac ZW |
11774 | I1 = !(I1 ^ S); |
11775 | I2 = !(I2 ^ S); | |
a737bd4d | 11776 | |
2fc8bdac ZW |
11777 | newval = md_chars_to_number (buf, THUMB_SIZE); |
11778 | newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE); | |
11779 | newval |= (S << 10) | hi; | |
11780 | newval2 |= (I1 << 13) | (I2 << 11) | lo; | |
11781 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11782 | md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE); | |
11783 | } | |
11784 | break; | |
a737bd4d | 11785 | |
2fc8bdac ZW |
11786 | case BFD_RELOC_8: |
11787 | if (fixP->fx_done || !seg->use_rela_p) | |
11788 | md_number_to_chars (buf, value, 1); | |
c19d1205 | 11789 | break; |
a737bd4d | 11790 | |
c19d1205 | 11791 | case BFD_RELOC_16: |
2fc8bdac | 11792 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 11793 | md_number_to_chars (buf, value, 2); |
c19d1205 | 11794 | break; |
a737bd4d | 11795 | |
c19d1205 ZW |
11796 | #ifdef OBJ_ELF |
11797 | case BFD_RELOC_ARM_TLS_GD32: | |
11798 | case BFD_RELOC_ARM_TLS_LE32: | |
11799 | case BFD_RELOC_ARM_TLS_IE32: | |
11800 | case BFD_RELOC_ARM_TLS_LDM32: | |
11801 | case BFD_RELOC_ARM_TLS_LDO32: | |
11802 | S_SET_THREAD_LOCAL (fixP->fx_addsy); | |
11803 | /* fall through */ | |
6c43fab6 | 11804 | |
c19d1205 ZW |
11805 | case BFD_RELOC_ARM_GOT32: |
11806 | case BFD_RELOC_ARM_GOTOFF: | |
11807 | case BFD_RELOC_ARM_TARGET2: | |
2fc8bdac ZW |
11808 | if (fixP->fx_done || !seg->use_rela_p) |
11809 | md_number_to_chars (buf, 0, 4); | |
c19d1205 ZW |
11810 | break; |
11811 | #endif | |
6c43fab6 | 11812 | |
c19d1205 ZW |
11813 | case BFD_RELOC_RVA: |
11814 | case BFD_RELOC_32: | |
11815 | case BFD_RELOC_ARM_TARGET1: | |
11816 | case BFD_RELOC_ARM_ROSEGREL32: | |
11817 | case BFD_RELOC_ARM_SBREL32: | |
11818 | case BFD_RELOC_32_PCREL: | |
2fc8bdac | 11819 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 | 11820 | md_number_to_chars (buf, value, 4); |
c19d1205 | 11821 | break; |
6c43fab6 | 11822 | |
c19d1205 ZW |
11823 | #ifdef OBJ_ELF |
11824 | case BFD_RELOC_ARM_PREL31: | |
2fc8bdac | 11825 | if (fixP->fx_done || !seg->use_rela_p) |
c19d1205 ZW |
11826 | { |
11827 | newval = md_chars_to_number (buf, 4) & 0x80000000; | |
11828 | if ((value ^ (value >> 1)) & 0x40000000) | |
11829 | { | |
11830 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11831 | _("rel31 relocation overflow")); | |
11832 | } | |
11833 | newval |= value & 0x7fffffff; | |
11834 | md_number_to_chars (buf, newval, 4); | |
11835 | } | |
11836 | break; | |
c19d1205 | 11837 | #endif |
a737bd4d | 11838 | |
c19d1205 | 11839 | case BFD_RELOC_ARM_CP_OFF_IMM: |
8f06b2d8 | 11840 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: |
c19d1205 ZW |
11841 | if (value < -1023 || value > 1023 || (value & 3)) |
11842 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11843 | _("co-processor offset out of range")); | |
11844 | cp_off_common: | |
11845 | sign = value >= 0; | |
11846 | if (value < 0) | |
11847 | value = -value; | |
8f06b2d8 PB |
11848 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
11849 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
11850 | newval = md_chars_to_number (buf, INSN_SIZE); | |
11851 | else | |
11852 | newval = get_thumb32_insn (buf); | |
11853 | newval &= 0xff7fff00; | |
c19d1205 ZW |
11854 | newval |= (value >> 2) | (sign ? INDEX_UP : 0); |
11855 | if (value == 0) | |
11856 | newval &= ~WRITE_BACK; | |
8f06b2d8 PB |
11857 | if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM |
11858 | || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2) | |
11859 | md_number_to_chars (buf, newval, INSN_SIZE); | |
11860 | else | |
11861 | put_thumb32_insn (buf, newval); | |
c19d1205 | 11862 | break; |
a737bd4d | 11863 | |
c19d1205 | 11864 | case BFD_RELOC_ARM_CP_OFF_IMM_S2: |
8f06b2d8 | 11865 | case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2: |
c19d1205 ZW |
11866 | if (value < -255 || value > 255) |
11867 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11868 | _("co-processor offset out of range")); | |
11869 | goto cp_off_common; | |
6c43fab6 | 11870 | |
c19d1205 ZW |
11871 | case BFD_RELOC_ARM_THUMB_OFFSET: |
11872 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11873 | /* Exactly what ranges, and where the offset is inserted depends | |
11874 | on the type of instruction, we can establish this from the | |
11875 | top 4 bits. */ | |
11876 | switch (newval >> 12) | |
11877 | { | |
11878 | case 4: /* PC load. */ | |
11879 | /* Thumb PC loads are somewhat odd, bit 1 of the PC is | |
11880 | forced to zero for these loads; md_pcrel_from has already | |
11881 | compensated for this. */ | |
11882 | if (value & 3) | |
11883 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11884 | _("invalid offset, target not word aligned (0x%08lX)"), | |
0359e808 NC |
11885 | (((unsigned long) fixP->fx_frag->fr_address |
11886 | + (unsigned long) fixP->fx_where) & ~3) | |
11887 | + (unsigned long) value); | |
a737bd4d | 11888 | |
c19d1205 ZW |
11889 | if (value & ~0x3fc) |
11890 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11891 | _("invalid offset, value too big (0x%08lX)"), | |
11892 | (long) value); | |
a737bd4d | 11893 | |
c19d1205 ZW |
11894 | newval |= value >> 2; |
11895 | break; | |
a737bd4d | 11896 | |
c19d1205 ZW |
11897 | case 9: /* SP load/store. */ |
11898 | if (value & ~0x3fc) | |
11899 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11900 | _("invalid offset, value too big (0x%08lX)"), | |
11901 | (long) value); | |
11902 | newval |= value >> 2; | |
11903 | break; | |
6c43fab6 | 11904 | |
c19d1205 ZW |
11905 | case 6: /* Word load/store. */ |
11906 | if (value & ~0x7c) | |
11907 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11908 | _("invalid offset, value too big (0x%08lX)"), | |
11909 | (long) value); | |
11910 | newval |= value << 4; /* 6 - 2. */ | |
11911 | break; | |
a737bd4d | 11912 | |
c19d1205 ZW |
11913 | case 7: /* Byte load/store. */ |
11914 | if (value & ~0x1f) | |
11915 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11916 | _("invalid offset, value too big (0x%08lX)"), | |
11917 | (long) value); | |
11918 | newval |= value << 6; | |
11919 | break; | |
a737bd4d | 11920 | |
c19d1205 ZW |
11921 | case 8: /* Halfword load/store. */ |
11922 | if (value & ~0x3e) | |
11923 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11924 | _("invalid offset, value too big (0x%08lX)"), | |
11925 | (long) value); | |
11926 | newval |= value << 5; /* 6 - 1. */ | |
11927 | break; | |
a737bd4d | 11928 | |
c19d1205 ZW |
11929 | default: |
11930 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11931 | "Unable to process relocation for thumb opcode: %lx", | |
11932 | (unsigned long) newval); | |
11933 | break; | |
11934 | } | |
11935 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
11936 | break; | |
a737bd4d | 11937 | |
c19d1205 ZW |
11938 | case BFD_RELOC_ARM_THUMB_ADD: |
11939 | /* This is a complicated relocation, since we use it for all of | |
11940 | the following immediate relocations: | |
a737bd4d | 11941 | |
c19d1205 ZW |
11942 | 3bit ADD/SUB |
11943 | 8bit ADD/SUB | |
11944 | 9bit ADD/SUB SP word-aligned | |
11945 | 10bit ADD PC/SP word-aligned | |
a737bd4d | 11946 | |
c19d1205 ZW |
11947 | The type of instruction being processed is encoded in the |
11948 | instruction field: | |
a737bd4d | 11949 | |
c19d1205 ZW |
11950 | 0x8000 SUB |
11951 | 0x00F0 Rd | |
11952 | 0x000F Rs | |
11953 | */ | |
11954 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
11955 | { | |
11956 | int rd = (newval >> 4) & 0xf; | |
11957 | int rs = newval & 0xf; | |
11958 | int subtract = !!(newval & 0x8000); | |
a737bd4d | 11959 | |
c19d1205 ZW |
11960 | /* Check for HI regs, only very restricted cases allowed: |
11961 | Adjusting SP, and using PC or SP to get an address. */ | |
11962 | if ((rd > 7 && (rd != REG_SP || rs != REG_SP)) | |
11963 | || (rs > 7 && rs != REG_SP && rs != REG_PC)) | |
11964 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11965 | _("invalid Hi register with immediate")); | |
a737bd4d | 11966 | |
c19d1205 ZW |
11967 | /* If value is negative, choose the opposite instruction. */ |
11968 | if (value < 0) | |
11969 | { | |
11970 | value = -value; | |
11971 | subtract = !subtract; | |
11972 | if (value < 0) | |
11973 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11974 | _("immediate value out of range")); | |
11975 | } | |
a737bd4d | 11976 | |
c19d1205 ZW |
11977 | if (rd == REG_SP) |
11978 | { | |
11979 | if (value & ~0x1fc) | |
11980 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11981 | _("invalid immediate for stack address calculation")); | |
11982 | newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST; | |
11983 | newval |= value >> 2; | |
11984 | } | |
11985 | else if (rs == REG_PC || rs == REG_SP) | |
11986 | { | |
11987 | if (subtract || value & ~0x3fc) | |
11988 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11989 | _("invalid immediate for address calculation (value = 0x%08lX)"), | |
11990 | (unsigned long) value); | |
11991 | newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP); | |
11992 | newval |= rd << 8; | |
11993 | newval |= value >> 2; | |
11994 | } | |
11995 | else if (rs == rd) | |
11996 | { | |
11997 | if (value & ~0xff) | |
11998 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
11999 | _("immediate value out of range")); | |
12000 | newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8; | |
12001 | newval |= (rd << 8) | value; | |
12002 | } | |
12003 | else | |
12004 | { | |
12005 | if (value & ~0x7) | |
12006 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12007 | _("immediate value out of range")); | |
12008 | newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3; | |
12009 | newval |= rd | (rs << 3) | (value << 6); | |
12010 | } | |
12011 | } | |
12012 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12013 | break; | |
a737bd4d | 12014 | |
c19d1205 ZW |
12015 | case BFD_RELOC_ARM_THUMB_IMM: |
12016 | newval = md_chars_to_number (buf, THUMB_SIZE); | |
12017 | if (value < 0 || value > 255) | |
12018 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12019 | _("invalid immediate: %ld is too large"), | |
12020 | (long) value); | |
12021 | newval |= value; | |
12022 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12023 | break; | |
a737bd4d | 12024 | |
c19d1205 ZW |
12025 | case BFD_RELOC_ARM_THUMB_SHIFT: |
12026 | /* 5bit shift value (0..32). LSL cannot take 32. */ | |
12027 | newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f; | |
12028 | temp = newval & 0xf800; | |
12029 | if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I)) | |
12030 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12031 | _("invalid shift value: %ld"), (long) value); | |
12032 | /* Shifts of zero must be encoded as LSL. */ | |
12033 | if (value == 0) | |
12034 | newval = (newval & 0x003f) | T_OPCODE_LSL_I; | |
12035 | /* Shifts of 32 are encoded as zero. */ | |
12036 | else if (value == 32) | |
12037 | value = 0; | |
12038 | newval |= value << 6; | |
12039 | md_number_to_chars (buf, newval, THUMB_SIZE); | |
12040 | break; | |
a737bd4d | 12041 | |
c19d1205 ZW |
12042 | case BFD_RELOC_VTABLE_INHERIT: |
12043 | case BFD_RELOC_VTABLE_ENTRY: | |
12044 | fixP->fx_done = 0; | |
12045 | return; | |
6c43fab6 | 12046 | |
c19d1205 ZW |
12047 | case BFD_RELOC_UNUSED: |
12048 | default: | |
12049 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
12050 | _("bad relocation fixup type (%d)"), fixP->fx_r_type); | |
12051 | } | |
6c43fab6 RE |
12052 | } |
12053 | ||
c19d1205 ZW |
12054 | /* Translate internal representation of relocation info to BFD target |
12055 | format. */ | |
a737bd4d | 12056 | |
c19d1205 ZW |
12057 | arelent * |
12058 | tc_gen_reloc (asection * section ATTRIBUTE_UNUSED, | |
12059 | fixS * fixp) | |
a737bd4d | 12060 | { |
c19d1205 ZW |
12061 | arelent * reloc; |
12062 | bfd_reloc_code_real_type code; | |
a737bd4d | 12063 | |
c19d1205 | 12064 | reloc = xmalloc (sizeof (arelent)); |
a737bd4d | 12065 | |
c19d1205 ZW |
12066 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
12067 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
12068 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
a737bd4d | 12069 | |
2fc8bdac ZW |
12070 | if (fixp->fx_pcrel) |
12071 | fixp->fx_offset = reloc->address; | |
c19d1205 | 12072 | reloc->addend = fixp->fx_offset; |
a737bd4d | 12073 | |
c19d1205 | 12074 | switch (fixp->fx_r_type) |
a737bd4d | 12075 | { |
c19d1205 ZW |
12076 | case BFD_RELOC_8: |
12077 | if (fixp->fx_pcrel) | |
12078 | { | |
12079 | code = BFD_RELOC_8_PCREL; | |
12080 | break; | |
12081 | } | |
a737bd4d | 12082 | |
c19d1205 ZW |
12083 | case BFD_RELOC_16: |
12084 | if (fixp->fx_pcrel) | |
12085 | { | |
12086 | code = BFD_RELOC_16_PCREL; | |
12087 | break; | |
12088 | } | |
6c43fab6 | 12089 | |
c19d1205 ZW |
12090 | case BFD_RELOC_32: |
12091 | if (fixp->fx_pcrel) | |
12092 | { | |
12093 | code = BFD_RELOC_32_PCREL; | |
12094 | break; | |
12095 | } | |
a737bd4d | 12096 | |
c19d1205 ZW |
12097 | case BFD_RELOC_NONE: |
12098 | case BFD_RELOC_ARM_PCREL_BRANCH: | |
12099 | case BFD_RELOC_ARM_PCREL_BLX: | |
12100 | case BFD_RELOC_RVA: | |
12101 | case BFD_RELOC_THUMB_PCREL_BRANCH7: | |
12102 | case BFD_RELOC_THUMB_PCREL_BRANCH9: | |
12103 | case BFD_RELOC_THUMB_PCREL_BRANCH12: | |
12104 | case BFD_RELOC_THUMB_PCREL_BRANCH20: | |
12105 | case BFD_RELOC_THUMB_PCREL_BRANCH23: | |
12106 | case BFD_RELOC_THUMB_PCREL_BRANCH25: | |
12107 | case BFD_RELOC_THUMB_PCREL_BLX: | |
12108 | case BFD_RELOC_VTABLE_ENTRY: | |
12109 | case BFD_RELOC_VTABLE_INHERIT: | |
12110 | code = fixp->fx_r_type; | |
12111 | break; | |
a737bd4d | 12112 | |
c19d1205 ZW |
12113 | case BFD_RELOC_ARM_LITERAL: |
12114 | case BFD_RELOC_ARM_HWLITERAL: | |
12115 | /* If this is called then the a literal has | |
12116 | been referenced across a section boundary. */ | |
12117 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12118 | _("literal referenced across section boundary")); | |
12119 | return NULL; | |
a737bd4d | 12120 | |
c19d1205 ZW |
12121 | #ifdef OBJ_ELF |
12122 | case BFD_RELOC_ARM_GOT32: | |
12123 | case BFD_RELOC_ARM_GOTOFF: | |
12124 | case BFD_RELOC_ARM_PLT32: | |
12125 | case BFD_RELOC_ARM_TARGET1: | |
12126 | case BFD_RELOC_ARM_ROSEGREL32: | |
12127 | case BFD_RELOC_ARM_SBREL32: | |
12128 | case BFD_RELOC_ARM_PREL31: | |
12129 | case BFD_RELOC_ARM_TARGET2: | |
12130 | case BFD_RELOC_ARM_TLS_LE32: | |
12131 | case BFD_RELOC_ARM_TLS_LDO32: | |
39b41c9c PB |
12132 | case BFD_RELOC_ARM_PCREL_CALL: |
12133 | case BFD_RELOC_ARM_PCREL_JUMP: | |
c19d1205 ZW |
12134 | code = fixp->fx_r_type; |
12135 | break; | |
a737bd4d | 12136 | |
c19d1205 ZW |
12137 | case BFD_RELOC_ARM_TLS_GD32: |
12138 | case BFD_RELOC_ARM_TLS_IE32: | |
12139 | case BFD_RELOC_ARM_TLS_LDM32: | |
12140 | /* BFD will include the symbol's address in the addend. | |
12141 | But we don't want that, so subtract it out again here. */ | |
12142 | if (!S_IS_COMMON (fixp->fx_addsy)) | |
12143 | reloc->addend -= (*reloc->sym_ptr_ptr)->value; | |
12144 | code = fixp->fx_r_type; | |
12145 | break; | |
12146 | #endif | |
a737bd4d | 12147 | |
c19d1205 ZW |
12148 | case BFD_RELOC_ARM_IMMEDIATE: |
12149 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12150 | _("internal relocation (type: IMMEDIATE) not fixed up")); | |
12151 | return NULL; | |
a737bd4d | 12152 | |
c19d1205 ZW |
12153 | case BFD_RELOC_ARM_ADRL_IMMEDIATE: |
12154 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12155 | _("ADRL used for a symbol not defined in the same file")); | |
12156 | return NULL; | |
a737bd4d | 12157 | |
c19d1205 ZW |
12158 | case BFD_RELOC_ARM_OFFSET_IMM: |
12159 | if (fixp->fx_addsy != NULL | |
12160 | && !S_IS_DEFINED (fixp->fx_addsy) | |
12161 | && S_IS_LOCAL (fixp->fx_addsy)) | |
a737bd4d | 12162 | { |
c19d1205 ZW |
12163 | as_bad_where (fixp->fx_file, fixp->fx_line, |
12164 | _("undefined local label `%s'"), | |
12165 | S_GET_NAME (fixp->fx_addsy)); | |
12166 | return NULL; | |
a737bd4d NC |
12167 | } |
12168 | ||
c19d1205 ZW |
12169 | as_bad_where (fixp->fx_file, fixp->fx_line, |
12170 | _("internal_relocation (type: OFFSET_IMM) not fixed up")); | |
12171 | return NULL; | |
a737bd4d | 12172 | |
c19d1205 ZW |
12173 | default: |
12174 | { | |
12175 | char * type; | |
6c43fab6 | 12176 | |
c19d1205 ZW |
12177 | switch (fixp->fx_r_type) |
12178 | { | |
12179 | case BFD_RELOC_NONE: type = "NONE"; break; | |
12180 | case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break; | |
12181 | case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break; | |
3eb17e6b | 12182 | case BFD_RELOC_ARM_SMC: type = "SMC"; break; |
c19d1205 ZW |
12183 | case BFD_RELOC_ARM_SWI: type = "SWI"; break; |
12184 | case BFD_RELOC_ARM_MULTI: type = "MULTI"; break; | |
12185 | case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break; | |
8f06b2d8 | 12186 | case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break; |
c19d1205 ZW |
12187 | case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break; |
12188 | case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break; | |
12189 | case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break; | |
12190 | case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break; | |
12191 | default: type = _("<unknown>"); break; | |
12192 | } | |
12193 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12194 | _("cannot represent %s relocation in this object file format"), | |
12195 | type); | |
12196 | return NULL; | |
12197 | } | |
a737bd4d | 12198 | } |
6c43fab6 | 12199 | |
c19d1205 ZW |
12200 | #ifdef OBJ_ELF |
12201 | if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32) | |
12202 | && GOT_symbol | |
12203 | && fixp->fx_addsy == GOT_symbol) | |
12204 | { | |
12205 | code = BFD_RELOC_ARM_GOTPC; | |
12206 | reloc->addend = fixp->fx_offset = reloc->address; | |
12207 | } | |
12208 | #endif | |
6c43fab6 | 12209 | |
c19d1205 | 12210 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
6c43fab6 | 12211 | |
c19d1205 ZW |
12212 | if (reloc->howto == NULL) |
12213 | { | |
12214 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
12215 | _("cannot represent %s relocation in this object file format"), | |
12216 | bfd_get_reloc_code_name (code)); | |
12217 | return NULL; | |
12218 | } | |
6c43fab6 | 12219 | |
c19d1205 ZW |
12220 | /* HACK: Since arm ELF uses Rel instead of Rela, encode the |
12221 | vtable entry to be used in the relocation's section offset. */ | |
12222 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12223 | reloc->address = fixp->fx_offset; | |
6c43fab6 | 12224 | |
c19d1205 | 12225 | return reloc; |
6c43fab6 RE |
12226 | } |
12227 | ||
c19d1205 | 12228 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. */ |
6c43fab6 | 12229 | |
c19d1205 ZW |
12230 | void |
12231 | cons_fix_new_arm (fragS * frag, | |
12232 | int where, | |
12233 | int size, | |
12234 | expressionS * exp) | |
6c43fab6 | 12235 | { |
c19d1205 ZW |
12236 | bfd_reloc_code_real_type type; |
12237 | int pcrel = 0; | |
6c43fab6 | 12238 | |
c19d1205 ZW |
12239 | /* Pick a reloc. |
12240 | FIXME: @@ Should look at CPU word size. */ | |
12241 | switch (size) | |
12242 | { | |
12243 | case 1: | |
12244 | type = BFD_RELOC_8; | |
12245 | break; | |
12246 | case 2: | |
12247 | type = BFD_RELOC_16; | |
12248 | break; | |
12249 | case 4: | |
12250 | default: | |
12251 | type = BFD_RELOC_32; | |
12252 | break; | |
12253 | case 8: | |
12254 | type = BFD_RELOC_64; | |
12255 | break; | |
12256 | } | |
6c43fab6 | 12257 | |
c19d1205 ZW |
12258 | fix_new_exp (frag, where, (int) size, exp, pcrel, type); |
12259 | } | |
6c43fab6 | 12260 | |
c19d1205 ZW |
12261 | #if defined OBJ_COFF || defined OBJ_ELF |
12262 | void | |
12263 | arm_validate_fix (fixS * fixP) | |
6c43fab6 | 12264 | { |
c19d1205 ZW |
12265 | /* If the destination of the branch is a defined symbol which does not have |
12266 | the THUMB_FUNC attribute, then we must be calling a function which has | |
12267 | the (interfacearm) attribute. We look for the Thumb entry point to that | |
12268 | function and change the branch to refer to that function instead. */ | |
12269 | if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23 | |
12270 | && fixP->fx_addsy != NULL | |
12271 | && S_IS_DEFINED (fixP->fx_addsy) | |
12272 | && ! THUMB_IS_FUNC (fixP->fx_addsy)) | |
6c43fab6 | 12273 | { |
c19d1205 | 12274 | fixP->fx_addsy = find_real_start (fixP->fx_addsy); |
6c43fab6 | 12275 | } |
c19d1205 ZW |
12276 | } |
12277 | #endif | |
6c43fab6 | 12278 | |
c19d1205 ZW |
12279 | int |
12280 | arm_force_relocation (struct fix * fixp) | |
12281 | { | |
12282 | #if defined (OBJ_COFF) && defined (TE_PE) | |
12283 | if (fixp->fx_r_type == BFD_RELOC_RVA) | |
12284 | return 1; | |
12285 | #endif | |
6c43fab6 | 12286 | |
c19d1205 ZW |
12287 | /* Resolve these relocations even if the symbol is extern or weak. */ |
12288 | if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE | |
12289 | || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM | |
0110f2b8 PB |
12290 | || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE |
12291 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE | |
12292 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12 | |
12293 | || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12) | |
c19d1205 | 12294 | return 0; |
a737bd4d | 12295 | |
c19d1205 | 12296 | return generic_force_reloc (fixp); |
404ff6b5 AH |
12297 | } |
12298 | ||
c19d1205 ZW |
12299 | #ifdef OBJ_COFF |
12300 | /* This is a little hack to help the gas/arm/adrl.s test. It prevents | |
12301 | local labels from being added to the output symbol table when they | |
12302 | are used with the ADRL pseudo op. The ADRL relocation should always | |
12303 | be resolved before the binbary is emitted, so it is safe to say that | |
12304 | it is adjustable. */ | |
404ff6b5 | 12305 | |
c19d1205 ZW |
12306 | bfd_boolean |
12307 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 12308 | { |
c19d1205 ZW |
12309 | if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE) |
12310 | return 1; | |
12311 | return 0; | |
404ff6b5 | 12312 | } |
c19d1205 | 12313 | #endif |
404ff6b5 | 12314 | |
c19d1205 ZW |
12315 | #ifdef OBJ_ELF |
12316 | /* Relocations against Thumb function names must be left unadjusted, | |
12317 | so that the linker can use this information to correctly set the | |
12318 | bottom bit of their addresses. The MIPS version of this function | |
12319 | also prevents relocations that are mips-16 specific, but I do not | |
12320 | know why it does this. | |
404ff6b5 | 12321 | |
c19d1205 ZW |
12322 | FIXME: |
12323 | There is one other problem that ought to be addressed here, but | |
12324 | which currently is not: Taking the address of a label (rather | |
12325 | than a function) and then later jumping to that address. Such | |
12326 | addresses also ought to have their bottom bit set (assuming that | |
12327 | they reside in Thumb code), but at the moment they will not. */ | |
404ff6b5 | 12328 | |
c19d1205 ZW |
12329 | bfd_boolean |
12330 | arm_fix_adjustable (fixS * fixP) | |
404ff6b5 | 12331 | { |
c19d1205 ZW |
12332 | if (fixP->fx_addsy == NULL) |
12333 | return 1; | |
404ff6b5 | 12334 | |
c19d1205 ZW |
12335 | if (THUMB_IS_FUNC (fixP->fx_addsy) |
12336 | && fixP->fx_subsy == NULL) | |
12337 | return 0; | |
a737bd4d | 12338 | |
c19d1205 ZW |
12339 | /* We need the symbol name for the VTABLE entries. */ |
12340 | if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
12341 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
12342 | return 0; | |
404ff6b5 | 12343 | |
c19d1205 ZW |
12344 | /* Don't allow symbols to be discarded on GOT related relocs. */ |
12345 | if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32 | |
12346 | || fixP->fx_r_type == BFD_RELOC_ARM_GOT32 | |
12347 | || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF | |
12348 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32 | |
12349 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32 | |
12350 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32 | |
12351 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32 | |
12352 | || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32 | |
12353 | || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2) | |
12354 | return 0; | |
a737bd4d | 12355 | |
c19d1205 | 12356 | return 1; |
a737bd4d | 12357 | } |
404ff6b5 | 12358 | |
c19d1205 ZW |
12359 | const char * |
12360 | elf32_arm_target_format (void) | |
404ff6b5 | 12361 | { |
c19d1205 ZW |
12362 | #ifdef TE_SYMBIAN |
12363 | return (target_big_endian | |
12364 | ? "elf32-bigarm-symbian" | |
12365 | : "elf32-littlearm-symbian"); | |
12366 | #elif defined (TE_VXWORKS) | |
12367 | return (target_big_endian | |
12368 | ? "elf32-bigarm-vxworks" | |
12369 | : "elf32-littlearm-vxworks"); | |
12370 | #else | |
12371 | if (target_big_endian) | |
12372 | return "elf32-bigarm"; | |
12373 | else | |
12374 | return "elf32-littlearm"; | |
12375 | #endif | |
404ff6b5 AH |
12376 | } |
12377 | ||
c19d1205 ZW |
12378 | void |
12379 | armelf_frob_symbol (symbolS * symp, | |
12380 | int * puntp) | |
404ff6b5 | 12381 | { |
c19d1205 ZW |
12382 | elf_frob_symbol (symp, puntp); |
12383 | } | |
12384 | #endif | |
404ff6b5 | 12385 | |
c19d1205 | 12386 | /* MD interface: Finalization. */ |
a737bd4d | 12387 | |
c19d1205 ZW |
12388 | /* A good place to do this, although this was probably not intended |
12389 | for this kind of use. We need to dump the literal pool before | |
12390 | references are made to a null symbol pointer. */ | |
a737bd4d | 12391 | |
c19d1205 ZW |
12392 | void |
12393 | arm_cleanup (void) | |
12394 | { | |
12395 | literal_pool * pool; | |
a737bd4d | 12396 | |
c19d1205 ZW |
12397 | for (pool = list_of_pools; pool; pool = pool->next) |
12398 | { | |
12399 | /* Put it at the end of the relevent section. */ | |
12400 | subseg_set (pool->section, pool->sub_section); | |
12401 | #ifdef OBJ_ELF | |
12402 | arm_elf_change_section (); | |
12403 | #endif | |
12404 | s_ltorg (0); | |
12405 | } | |
404ff6b5 AH |
12406 | } |
12407 | ||
c19d1205 ZW |
12408 | /* Adjust the symbol table. This marks Thumb symbols as distinct from |
12409 | ARM ones. */ | |
404ff6b5 | 12410 | |
c19d1205 ZW |
12411 | void |
12412 | arm_adjust_symtab (void) | |
404ff6b5 | 12413 | { |
c19d1205 ZW |
12414 | #ifdef OBJ_COFF |
12415 | symbolS * sym; | |
404ff6b5 | 12416 | |
c19d1205 ZW |
12417 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
12418 | { | |
12419 | if (ARM_IS_THUMB (sym)) | |
12420 | { | |
12421 | if (THUMB_IS_FUNC (sym)) | |
12422 | { | |
12423 | /* Mark the symbol as a Thumb function. */ | |
12424 | if ( S_GET_STORAGE_CLASS (sym) == C_STAT | |
12425 | || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */ | |
12426 | S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC); | |
404ff6b5 | 12427 | |
c19d1205 ZW |
12428 | else if (S_GET_STORAGE_CLASS (sym) == C_EXT) |
12429 | S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC); | |
12430 | else | |
12431 | as_bad (_("%s: unexpected function type: %d"), | |
12432 | S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym)); | |
12433 | } | |
12434 | else switch (S_GET_STORAGE_CLASS (sym)) | |
12435 | { | |
12436 | case C_EXT: | |
12437 | S_SET_STORAGE_CLASS (sym, C_THUMBEXT); | |
12438 | break; | |
12439 | case C_STAT: | |
12440 | S_SET_STORAGE_CLASS (sym, C_THUMBSTAT); | |
12441 | break; | |
12442 | case C_LABEL: | |
12443 | S_SET_STORAGE_CLASS (sym, C_THUMBLABEL); | |
12444 | break; | |
12445 | default: | |
12446 | /* Do nothing. */ | |
12447 | break; | |
12448 | } | |
12449 | } | |
a737bd4d | 12450 | |
c19d1205 ZW |
12451 | if (ARM_IS_INTERWORK (sym)) |
12452 | coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF; | |
404ff6b5 | 12453 | } |
c19d1205 ZW |
12454 | #endif |
12455 | #ifdef OBJ_ELF | |
12456 | symbolS * sym; | |
12457 | char bind; | |
404ff6b5 | 12458 | |
c19d1205 | 12459 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
404ff6b5 | 12460 | { |
c19d1205 ZW |
12461 | if (ARM_IS_THUMB (sym)) |
12462 | { | |
12463 | elf_symbol_type * elf_sym; | |
404ff6b5 | 12464 | |
c19d1205 ZW |
12465 | elf_sym = elf_symbol (symbol_get_bfdsym (sym)); |
12466 | bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info); | |
404ff6b5 | 12467 | |
c19d1205 ZW |
12468 | if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name)) |
12469 | { | |
12470 | /* If it's a .thumb_func, declare it as so, | |
12471 | otherwise tag label as .code 16. */ | |
12472 | if (THUMB_IS_FUNC (sym)) | |
12473 | elf_sym->internal_elf_sym.st_info = | |
12474 | ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
12475 | else | |
12476 | elf_sym->internal_elf_sym.st_info = | |
12477 | ELF_ST_INFO (bind, STT_ARM_16BIT); | |
12478 | } | |
12479 | } | |
12480 | } | |
12481 | #endif | |
404ff6b5 AH |
12482 | } |
12483 | ||
c19d1205 | 12484 | /* MD interface: Initialization. */ |
404ff6b5 | 12485 | |
a737bd4d | 12486 | static void |
c19d1205 | 12487 | set_constant_flonums (void) |
a737bd4d | 12488 | { |
c19d1205 | 12489 | int i; |
404ff6b5 | 12490 | |
c19d1205 ZW |
12491 | for (i = 0; i < NUM_FLOAT_VALS; i++) |
12492 | if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL) | |
12493 | abort (); | |
a737bd4d | 12494 | } |
404ff6b5 | 12495 | |
c19d1205 ZW |
12496 | void |
12497 | md_begin (void) | |
a737bd4d | 12498 | { |
c19d1205 ZW |
12499 | unsigned mach; |
12500 | unsigned int i; | |
404ff6b5 | 12501 | |
c19d1205 ZW |
12502 | if ( (arm_ops_hsh = hash_new ()) == NULL |
12503 | || (arm_cond_hsh = hash_new ()) == NULL | |
12504 | || (arm_shift_hsh = hash_new ()) == NULL | |
12505 | || (arm_psr_hsh = hash_new ()) == NULL | |
12506 | || (arm_reg_hsh = hash_new ()) == NULL | |
12507 | || (arm_reloc_hsh = hash_new ()) == NULL) | |
12508 | as_fatal (_("virtual memory exhausted")); | |
12509 | ||
12510 | for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++) | |
12511 | hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i)); | |
12512 | for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++) | |
12513 | hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i)); | |
12514 | for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++) | |
12515 | hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i)); | |
12516 | for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++) | |
12517 | hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i)); | |
12518 | for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++) | |
12519 | hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i)); | |
12520 | #ifdef OBJ_ELF | |
12521 | for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++) | |
12522 | hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i)); | |
12523 | #endif | |
12524 | ||
12525 | set_constant_flonums (); | |
404ff6b5 | 12526 | |
c19d1205 ZW |
12527 | /* Set the cpu variant based on the command-line options. We prefer |
12528 | -mcpu= over -march= if both are set (as for GCC); and we prefer | |
12529 | -mfpu= over any other way of setting the floating point unit. | |
12530 | Use of legacy options with new options are faulted. */ | |
e74cfd16 | 12531 | if (legacy_cpu) |
404ff6b5 | 12532 | { |
e74cfd16 | 12533 | if (mcpu_cpu_opt || march_cpu_opt) |
c19d1205 ZW |
12534 | as_bad (_("use of old and new-style options to set CPU type")); |
12535 | ||
12536 | mcpu_cpu_opt = legacy_cpu; | |
404ff6b5 | 12537 | } |
e74cfd16 | 12538 | else if (!mcpu_cpu_opt) |
c19d1205 | 12539 | mcpu_cpu_opt = march_cpu_opt; |
404ff6b5 | 12540 | |
e74cfd16 | 12541 | if (legacy_fpu) |
c19d1205 | 12542 | { |
e74cfd16 | 12543 | if (mfpu_opt) |
c19d1205 | 12544 | as_bad (_("use of old and new-style options to set FPU type")); |
03b1477f RE |
12545 | |
12546 | mfpu_opt = legacy_fpu; | |
12547 | } | |
e74cfd16 | 12548 | else if (!mfpu_opt) |
03b1477f | 12549 | { |
c19d1205 | 12550 | #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS)) |
39c2da32 RE |
12551 | /* Some environments specify a default FPU. If they don't, infer it |
12552 | from the processor. */ | |
e74cfd16 | 12553 | if (mcpu_fpu_opt) |
03b1477f RE |
12554 | mfpu_opt = mcpu_fpu_opt; |
12555 | else | |
12556 | mfpu_opt = march_fpu_opt; | |
39c2da32 | 12557 | #else |
e74cfd16 | 12558 | mfpu_opt = &fpu_default; |
39c2da32 | 12559 | #endif |
03b1477f RE |
12560 | } |
12561 | ||
e74cfd16 | 12562 | if (!mfpu_opt) |
03b1477f | 12563 | { |
e74cfd16 PB |
12564 | if (!mcpu_cpu_opt) |
12565 | mfpu_opt = &fpu_default; | |
12566 | else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5)) | |
12567 | mfpu_opt = &fpu_arch_vfp_v2; | |
03b1477f | 12568 | else |
e74cfd16 | 12569 | mfpu_opt = &fpu_arch_fpa; |
03b1477f RE |
12570 | } |
12571 | ||
ee065d83 | 12572 | #ifdef CPU_DEFAULT |
e74cfd16 | 12573 | if (!mcpu_cpu_opt) |
ee065d83 | 12574 | { |
e74cfd16 PB |
12575 | mcpu_cpu_opt = &cpu_default; |
12576 | selected_cpu = cpu_default; | |
ee065d83 | 12577 | } |
e74cfd16 PB |
12578 | #else |
12579 | if (mcpu_cpu_opt) | |
12580 | selected_cpu = *mcpu_cpu_opt; | |
ee065d83 | 12581 | else |
e74cfd16 | 12582 | mcpu_cpu_opt = &arm_arch_any; |
ee065d83 | 12583 | #endif |
03b1477f | 12584 | |
e74cfd16 | 12585 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
03b1477f | 12586 | |
e74cfd16 | 12587 | arm_arch_used = thumb_arch_used = arm_arch_none; |
ee065d83 | 12588 | |
f17c130b | 12589 | #if defined OBJ_COFF || defined OBJ_ELF |
b99bd4ef | 12590 | { |
7cc69913 NC |
12591 | unsigned int flags = 0; |
12592 | ||
12593 | #if defined OBJ_ELF | |
12594 | flags = meabi_flags; | |
d507cf36 PB |
12595 | |
12596 | switch (meabi_flags) | |
33a392fb | 12597 | { |
d507cf36 | 12598 | case EF_ARM_EABI_UNKNOWN: |
7cc69913 | 12599 | #endif |
d507cf36 PB |
12600 | /* Set the flags in the private structure. */ |
12601 | if (uses_apcs_26) flags |= F_APCS26; | |
12602 | if (support_interwork) flags |= F_INTERWORK; | |
12603 | if (uses_apcs_float) flags |= F_APCS_FLOAT; | |
c19d1205 | 12604 | if (pic_code) flags |= F_PIC; |
e74cfd16 | 12605 | if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard)) |
7cc69913 NC |
12606 | flags |= F_SOFT_FLOAT; |
12607 | ||
d507cf36 PB |
12608 | switch (mfloat_abi_opt) |
12609 | { | |
12610 | case ARM_FLOAT_ABI_SOFT: | |
12611 | case ARM_FLOAT_ABI_SOFTFP: | |
12612 | flags |= F_SOFT_FLOAT; | |
12613 | break; | |
33a392fb | 12614 | |
d507cf36 PB |
12615 | case ARM_FLOAT_ABI_HARD: |
12616 | if (flags & F_SOFT_FLOAT) | |
12617 | as_bad (_("hard-float conflicts with specified fpu")); | |
12618 | break; | |
12619 | } | |
03b1477f | 12620 | |
e74cfd16 PB |
12621 | /* Using pure-endian doubles (even if soft-float). */ |
12622 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure)) | |
7cc69913 | 12623 | flags |= F_VFP_FLOAT; |
f17c130b | 12624 | |
fde78edd | 12625 | #if defined OBJ_ELF |
e74cfd16 | 12626 | if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick)) |
d507cf36 | 12627 | flags |= EF_ARM_MAVERICK_FLOAT; |
d507cf36 PB |
12628 | break; |
12629 | ||
8cb51566 | 12630 | case EF_ARM_EABI_VER4: |
c19d1205 | 12631 | /* No additional flags to set. */ |
d507cf36 PB |
12632 | break; |
12633 | ||
12634 | default: | |
12635 | abort (); | |
12636 | } | |
7cc69913 | 12637 | #endif |
b99bd4ef NC |
12638 | bfd_set_private_flags (stdoutput, flags); |
12639 | ||
12640 | /* We have run out flags in the COFF header to encode the | |
12641 | status of ATPCS support, so instead we create a dummy, | |
c19d1205 | 12642 | empty, debug section called .arm.atpcs. */ |
b99bd4ef NC |
12643 | if (atpcs) |
12644 | { | |
12645 | asection * sec; | |
12646 | ||
12647 | sec = bfd_make_section (stdoutput, ".arm.atpcs"); | |
12648 | ||
12649 | if (sec != NULL) | |
12650 | { | |
12651 | bfd_set_section_flags | |
12652 | (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */); | |
12653 | bfd_set_section_size (stdoutput, sec, 0); | |
12654 | bfd_set_section_contents (stdoutput, sec, NULL, 0, 0); | |
12655 | } | |
12656 | } | |
7cc69913 | 12657 | } |
f17c130b | 12658 | #endif |
b99bd4ef NC |
12659 | |
12660 | /* Record the CPU type as well. */ | |
e74cfd16 | 12661 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt)) |
e16bb312 | 12662 | mach = bfd_mach_arm_iWMMXt; |
e74cfd16 | 12663 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale)) |
b99bd4ef | 12664 | mach = bfd_mach_arm_XScale; |
e74cfd16 | 12665 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick)) |
fde78edd | 12666 | mach = bfd_mach_arm_ep9312; |
e74cfd16 | 12667 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e)) |
b99bd4ef | 12668 | mach = bfd_mach_arm_5TE; |
e74cfd16 | 12669 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5)) |
b99bd4ef | 12670 | { |
e74cfd16 | 12671 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
12672 | mach = bfd_mach_arm_5T; |
12673 | else | |
12674 | mach = bfd_mach_arm_5; | |
12675 | } | |
e74cfd16 | 12676 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4)) |
b99bd4ef | 12677 | { |
e74cfd16 | 12678 | if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t)) |
b99bd4ef NC |
12679 | mach = bfd_mach_arm_4T; |
12680 | else | |
12681 | mach = bfd_mach_arm_4; | |
12682 | } | |
e74cfd16 | 12683 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m)) |
b99bd4ef | 12684 | mach = bfd_mach_arm_3M; |
e74cfd16 PB |
12685 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3)) |
12686 | mach = bfd_mach_arm_3; | |
12687 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s)) | |
12688 | mach = bfd_mach_arm_2a; | |
12689 | else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2)) | |
12690 | mach = bfd_mach_arm_2; | |
12691 | else | |
12692 | mach = bfd_mach_arm_unknown; | |
b99bd4ef NC |
12693 | |
12694 | bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach); | |
12695 | } | |
12696 | ||
c19d1205 | 12697 | /* Command line processing. */ |
b99bd4ef | 12698 | |
c19d1205 ZW |
12699 | /* md_parse_option |
12700 | Invocation line includes a switch not recognized by the base assembler. | |
12701 | See if it's a processor-specific option. | |
b99bd4ef | 12702 | |
c19d1205 ZW |
12703 | This routine is somewhat complicated by the need for backwards |
12704 | compatibility (since older releases of gcc can't be changed). | |
12705 | The new options try to make the interface as compatible as | |
12706 | possible with GCC. | |
b99bd4ef | 12707 | |
c19d1205 | 12708 | New options (supported) are: |
b99bd4ef | 12709 | |
c19d1205 ZW |
12710 | -mcpu=<cpu name> Assemble for selected processor |
12711 | -march=<architecture name> Assemble for selected architecture | |
12712 | -mfpu=<fpu architecture> Assemble for selected FPU. | |
12713 | -EB/-mbig-endian Big-endian | |
12714 | -EL/-mlittle-endian Little-endian | |
12715 | -k Generate PIC code | |
12716 | -mthumb Start in Thumb mode | |
12717 | -mthumb-interwork Code supports ARM/Thumb interworking | |
b99bd4ef | 12718 | |
c19d1205 | 12719 | For now we will also provide support for: |
b99bd4ef | 12720 | |
c19d1205 ZW |
12721 | -mapcs-32 32-bit Program counter |
12722 | -mapcs-26 26-bit Program counter | |
12723 | -macps-float Floats passed in FP registers | |
12724 | -mapcs-reentrant Reentrant code | |
12725 | -matpcs | |
12726 | (sometime these will probably be replaced with -mapcs=<list of options> | |
12727 | and -matpcs=<list of options>) | |
b99bd4ef | 12728 | |
c19d1205 ZW |
12729 | The remaining options are only supported for back-wards compatibility. |
12730 | Cpu variants, the arm part is optional: | |
12731 | -m[arm]1 Currently not supported. | |
12732 | -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor | |
12733 | -m[arm]3 Arm 3 processor | |
12734 | -m[arm]6[xx], Arm 6 processors | |
12735 | -m[arm]7[xx][t][[d]m] Arm 7 processors | |
12736 | -m[arm]8[10] Arm 8 processors | |
12737 | -m[arm]9[20][tdmi] Arm 9 processors | |
12738 | -mstrongarm[110[0]] StrongARM processors | |
12739 | -mxscale XScale processors | |
12740 | -m[arm]v[2345[t[e]]] Arm architectures | |
12741 | -mall All (except the ARM1) | |
12742 | FP variants: | |
12743 | -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions | |
12744 | -mfpe-old (No float load/store multiples) | |
12745 | -mvfpxd VFP Single precision | |
12746 | -mvfp All VFP | |
12747 | -mno-fpu Disable all floating point instructions | |
b99bd4ef | 12748 | |
c19d1205 ZW |
12749 | The following CPU names are recognized: |
12750 | arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620, | |
12751 | arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700, | |
12752 | arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c, | |
12753 | arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9, | |
12754 | arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e, | |
12755 | arm10t arm10e, arm1020t, arm1020e, arm10200e, | |
12756 | strongarm, strongarm110, strongarm1100, strongarm1110, xscale. | |
b99bd4ef | 12757 | |
c19d1205 | 12758 | */ |
b99bd4ef | 12759 | |
c19d1205 | 12760 | const char * md_shortopts = "m:k"; |
b99bd4ef | 12761 | |
c19d1205 ZW |
12762 | #ifdef ARM_BI_ENDIAN |
12763 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
12764 | #define OPTION_EL (OPTION_MD_BASE + 1) | |
b99bd4ef | 12765 | #else |
c19d1205 ZW |
12766 | #if TARGET_BYTES_BIG_ENDIAN |
12767 | #define OPTION_EB (OPTION_MD_BASE + 0) | |
b99bd4ef | 12768 | #else |
c19d1205 ZW |
12769 | #define OPTION_EL (OPTION_MD_BASE + 1) |
12770 | #endif | |
b99bd4ef | 12771 | #endif |
b99bd4ef | 12772 | |
c19d1205 | 12773 | struct option md_longopts[] = |
b99bd4ef | 12774 | { |
c19d1205 ZW |
12775 | #ifdef OPTION_EB |
12776 | {"EB", no_argument, NULL, OPTION_EB}, | |
12777 | #endif | |
12778 | #ifdef OPTION_EL | |
12779 | {"EL", no_argument, NULL, OPTION_EL}, | |
b99bd4ef | 12780 | #endif |
c19d1205 ZW |
12781 | {NULL, no_argument, NULL, 0} |
12782 | }; | |
b99bd4ef | 12783 | |
c19d1205 | 12784 | size_t md_longopts_size = sizeof (md_longopts); |
b99bd4ef | 12785 | |
c19d1205 | 12786 | struct arm_option_table |
b99bd4ef | 12787 | { |
c19d1205 ZW |
12788 | char *option; /* Option name to match. */ |
12789 | char *help; /* Help information. */ | |
12790 | int *var; /* Variable to change. */ | |
12791 | int value; /* What to change it to. */ | |
12792 | char *deprecated; /* If non-null, print this message. */ | |
12793 | }; | |
b99bd4ef | 12794 | |
c19d1205 ZW |
12795 | struct arm_option_table arm_opts[] = |
12796 | { | |
12797 | {"k", N_("generate PIC code"), &pic_code, 1, NULL}, | |
12798 | {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL}, | |
12799 | {"mthumb-interwork", N_("support ARM/Thumb interworking"), | |
12800 | &support_interwork, 1, NULL}, | |
12801 | {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL}, | |
12802 | {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL}, | |
12803 | {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float, | |
12804 | 1, NULL}, | |
12805 | {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL}, | |
12806 | {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL}, | |
12807 | {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL}, | |
12808 | {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0, | |
12809 | NULL}, | |
b99bd4ef | 12810 | |
c19d1205 ZW |
12811 | /* These are recognized by the assembler, but have no affect on code. */ |
12812 | {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL}, | |
12813 | {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL}, | |
e74cfd16 PB |
12814 | {NULL, NULL, NULL, 0, NULL} |
12815 | }; | |
12816 | ||
12817 | struct arm_legacy_option_table | |
12818 | { | |
12819 | char *option; /* Option name to match. */ | |
12820 | const arm_feature_set **var; /* Variable to change. */ | |
12821 | const arm_feature_set value; /* What to change it to. */ | |
12822 | char *deprecated; /* If non-null, print this message. */ | |
12823 | }; | |
b99bd4ef | 12824 | |
e74cfd16 PB |
12825 | const struct arm_legacy_option_table arm_legacy_opts[] = |
12826 | { | |
c19d1205 ZW |
12827 | /* DON'T add any new processors to this list -- we want the whole list |
12828 | to go away... Add them to the processors table instead. */ | |
e74cfd16 PB |
12829 | {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, |
12830 | {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")}, | |
12831 | {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
12832 | {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")}, | |
12833 | {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
12834 | {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")}, | |
12835 | {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
12836 | {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")}, | |
12837 | {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
12838 | {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")}, | |
12839 | {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
12840 | {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")}, | |
12841 | {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
12842 | {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")}, | |
12843 | {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
12844 | {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")}, | |
12845 | {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
12846 | {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")}, | |
12847 | {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
12848 | {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")}, | |
12849 | {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
12850 | {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")}, | |
12851 | {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
12852 | {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")}, | |
12853 | {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
12854 | {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")}, | |
12855 | {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
12856 | {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")}, | |
12857 | {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
12858 | {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")}, | |
12859 | {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
12860 | {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")}, | |
12861 | {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
12862 | {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")}, | |
12863 | {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
12864 | {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")}, | |
12865 | {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
12866 | {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")}, | |
12867 | {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
12868 | {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")}, | |
12869 | {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
12870 | {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")}, | |
12871 | {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
12872 | {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")}, | |
12873 | {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
12874 | {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")}, | |
12875 | {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
12876 | {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
12877 | {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
12878 | {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")}, | |
12879 | {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
12880 | {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")}, | |
12881 | {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
12882 | {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")}, | |
12883 | {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
12884 | {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")}, | |
12885 | {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
12886 | {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")}, | |
12887 | {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
12888 | {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")}, | |
12889 | {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
12890 | {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")}, | |
12891 | {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
12892 | {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")}, | |
12893 | {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
12894 | {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")}, | |
12895 | {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
12896 | {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")}, | |
12897 | {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")}, | |
12898 | {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4, | |
c19d1205 | 12899 | N_("use -mcpu=strongarm110")}, |
e74cfd16 | 12900 | {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 12901 | N_("use -mcpu=strongarm1100")}, |
e74cfd16 | 12902 | {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4, |
c19d1205 | 12903 | N_("use -mcpu=strongarm1110")}, |
e74cfd16 PB |
12904 | {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")}, |
12905 | {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")}, | |
12906 | {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")}, | |
7ed4c4c5 | 12907 | |
c19d1205 | 12908 | /* Architecture variants -- don't add any more to this list either. */ |
e74cfd16 PB |
12909 | {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, |
12910 | {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")}, | |
12911 | {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
12912 | {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")}, | |
12913 | {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
12914 | {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")}, | |
12915 | {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
12916 | {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")}, | |
12917 | {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
12918 | {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")}, | |
12919 | {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
12920 | {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")}, | |
12921 | {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
12922 | {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")}, | |
12923 | {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
12924 | {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")}, | |
12925 | {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
12926 | {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")}, | |
7ed4c4c5 | 12927 | |
c19d1205 | 12928 | /* Floating point variants -- don't add any more to this list either. */ |
e74cfd16 PB |
12929 | {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")}, |
12930 | {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")}, | |
12931 | {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")}, | |
12932 | {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE, | |
c19d1205 | 12933 | N_("use either -mfpu=softfpa or -mfpu=softvfp")}, |
7ed4c4c5 | 12934 | |
e74cfd16 | 12935 | {NULL, NULL, ARM_ARCH_NONE, NULL} |
c19d1205 | 12936 | }; |
7ed4c4c5 | 12937 | |
c19d1205 | 12938 | struct arm_cpu_option_table |
7ed4c4c5 | 12939 | { |
c19d1205 | 12940 | char *name; |
e74cfd16 | 12941 | const arm_feature_set value; |
c19d1205 ZW |
12942 | /* For some CPUs we assume an FPU unless the user explicitly sets |
12943 | -mfpu=... */ | |
e74cfd16 | 12944 | const arm_feature_set default_fpu; |
ee065d83 PB |
12945 | /* The canonical name of the CPU, or NULL to use NAME converted to upper |
12946 | case. */ | |
12947 | const char *canonical_name; | |
c19d1205 | 12948 | }; |
7ed4c4c5 | 12949 | |
c19d1205 ZW |
12950 | /* This list should, at a minimum, contain all the cpu names |
12951 | recognized by GCC. */ | |
e74cfd16 | 12952 | static const struct arm_cpu_option_table arm_cpus[] = |
c19d1205 | 12953 | { |
ee065d83 PB |
12954 | {"all", ARM_ANY, FPU_ARCH_FPA, NULL}, |
12955 | {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL}, | |
12956 | {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL}, | |
12957 | {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
12958 | {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL}, | |
12959 | {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12960 | {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12961 | {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12962 | {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12963 | {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12964 | {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12965 | {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
12966 | {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12967 | {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
12968 | {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12969 | {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL}, | |
12970 | {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12971 | {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12972 | {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12973 | {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12974 | {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12975 | {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12976 | {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12977 | {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12978 | {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12979 | {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12980 | {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12981 | {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL}, | |
12982 | {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12983 | {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12984 | {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12985 | {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12986 | {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12987 | {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12988 | {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12989 | {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12990 | {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12991 | {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL}, | |
12992 | {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12993 | {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"}, | |
12994 | {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12995 | {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12996 | {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
12997 | {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL}, | |
c19d1205 ZW |
12998 | /* For V5 or later processors we default to using VFP; but the user |
12999 | should really set the FPU type explicitly. */ | |
ee065d83 PB |
13000 | {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, |
13001 | {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13002 | {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
13003 | {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"}, | |
13004 | {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
13005 | {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
13006 | {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"}, | |
13007 | {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13008 | {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL}, | |
13009 | {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"}, | |
13010 | {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13011 | {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13012 | {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
13013 | {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
13014 | {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13015 | {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"}, | |
13016 | {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, | |
13017 | {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13018 | {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, | |
13019 | {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"}, | |
13020 | {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL}, | |
13021 | {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"}, | |
13022 | {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL}, | |
13023 | {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"}, | |
13024 | {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL}, | |
13025 | {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL}, | |
13026 | {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL}, | |
13027 | {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL}, | |
13028 | {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL}, | |
13029 | {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL}, | |
13030 | {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL}, | |
c19d1205 | 13031 | /* ??? XSCALE is really an architecture. */ |
ee065d83 | 13032 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, |
c19d1205 | 13033 | /* ??? iwmmxt is not a processor. */ |
ee065d83 PB |
13034 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL}, |
13035 | {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL}, | |
c19d1205 | 13036 | /* Maverick */ |
e74cfd16 PB |
13037 | {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"}, |
13038 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL} | |
c19d1205 | 13039 | }; |
7ed4c4c5 | 13040 | |
c19d1205 | 13041 | struct arm_arch_option_table |
7ed4c4c5 | 13042 | { |
c19d1205 | 13043 | char *name; |
e74cfd16 PB |
13044 | const arm_feature_set value; |
13045 | const arm_feature_set default_fpu; | |
c19d1205 | 13046 | }; |
7ed4c4c5 | 13047 | |
c19d1205 ZW |
13048 | /* This list should, at a minimum, contain all the architecture names |
13049 | recognized by GCC. */ | |
e74cfd16 | 13050 | static const struct arm_arch_option_table arm_archs[] = |
c19d1205 ZW |
13051 | { |
13052 | {"all", ARM_ANY, FPU_ARCH_FPA}, | |
13053 | {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA}, | |
13054 | {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA}, | |
13055 | {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
13056 | {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA}, | |
13057 | {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA}, | |
13058 | {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA}, | |
13059 | {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA}, | |
13060 | {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA}, | |
13061 | {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA}, | |
13062 | {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA}, | |
13063 | {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP}, | |
13064 | {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP}, | |
13065 | {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP}, | |
13066 | {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP}, | |
13067 | {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP}, | |
13068 | {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP}, | |
13069 | {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
13070 | {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP}, | |
13071 | {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP}, | |
13072 | {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP}, | |
13073 | {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP}, | |
13074 | {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP}, | |
13075 | {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP}, | |
13076 | {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP}, | |
13077 | {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP}, | |
13078 | {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP}, | |
13079 | {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP}, | |
e74cfd16 | 13080 | {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE} |
c19d1205 | 13081 | }; |
7ed4c4c5 | 13082 | |
c19d1205 | 13083 | /* ISA extensions in the co-processor space. */ |
e74cfd16 | 13084 | struct arm_option_cpu_value_table |
c19d1205 ZW |
13085 | { |
13086 | char *name; | |
e74cfd16 | 13087 | const arm_feature_set value; |
c19d1205 | 13088 | }; |
7ed4c4c5 | 13089 | |
e74cfd16 | 13090 | static const struct arm_option_cpu_value_table arm_extensions[] = |
c19d1205 | 13091 | { |
e74cfd16 PB |
13092 | {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)}, |
13093 | {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)}, | |
13094 | {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)}, | |
13095 | {NULL, ARM_ARCH_NONE} | |
c19d1205 | 13096 | }; |
7ed4c4c5 | 13097 | |
c19d1205 ZW |
13098 | /* This list should, at a minimum, contain all the fpu names |
13099 | recognized by GCC. */ | |
e74cfd16 | 13100 | static const struct arm_option_cpu_value_table arm_fpus[] = |
c19d1205 ZW |
13101 | { |
13102 | {"softfpa", FPU_NONE}, | |
13103 | {"fpe", FPU_ARCH_FPE}, | |
13104 | {"fpe2", FPU_ARCH_FPE}, | |
13105 | {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */ | |
13106 | {"fpa", FPU_ARCH_FPA}, | |
13107 | {"fpa10", FPU_ARCH_FPA}, | |
13108 | {"fpa11", FPU_ARCH_FPA}, | |
13109 | {"arm7500fe", FPU_ARCH_FPA}, | |
13110 | {"softvfp", FPU_ARCH_VFP}, | |
13111 | {"softvfp+vfp", FPU_ARCH_VFP_V2}, | |
13112 | {"vfp", FPU_ARCH_VFP_V2}, | |
13113 | {"vfp9", FPU_ARCH_VFP_V2}, | |
13114 | {"vfp10", FPU_ARCH_VFP_V2}, | |
13115 | {"vfp10-r0", FPU_ARCH_VFP_V1}, | |
13116 | {"vfpxd", FPU_ARCH_VFP_V1xD}, | |
13117 | {"arm1020t", FPU_ARCH_VFP_V1}, | |
13118 | {"arm1020e", FPU_ARCH_VFP_V2}, | |
13119 | {"arm1136jfs", FPU_ARCH_VFP_V2}, | |
13120 | {"arm1136jf-s", FPU_ARCH_VFP_V2}, | |
13121 | {"maverick", FPU_ARCH_MAVERICK}, | |
e74cfd16 PB |
13122 | {NULL, ARM_ARCH_NONE} |
13123 | }; | |
13124 | ||
13125 | struct arm_option_value_table | |
13126 | { | |
13127 | char *name; | |
13128 | long value; | |
c19d1205 | 13129 | }; |
7ed4c4c5 | 13130 | |
e74cfd16 | 13131 | static const struct arm_option_value_table arm_float_abis[] = |
c19d1205 ZW |
13132 | { |
13133 | {"hard", ARM_FLOAT_ABI_HARD}, | |
13134 | {"softfp", ARM_FLOAT_ABI_SOFTFP}, | |
13135 | {"soft", ARM_FLOAT_ABI_SOFT}, | |
e74cfd16 | 13136 | {NULL, 0} |
c19d1205 | 13137 | }; |
7ed4c4c5 | 13138 | |
c19d1205 ZW |
13139 | #ifdef OBJ_ELF |
13140 | /* We only know how to output GNU and ver 4 (AAELF) formats. */ | |
e74cfd16 | 13141 | static const struct arm_option_value_table arm_eabis[] = |
c19d1205 ZW |
13142 | { |
13143 | {"gnu", EF_ARM_EABI_UNKNOWN}, | |
13144 | {"4", EF_ARM_EABI_VER4}, | |
e74cfd16 | 13145 | {NULL, 0} |
c19d1205 ZW |
13146 | }; |
13147 | #endif | |
7ed4c4c5 | 13148 | |
c19d1205 ZW |
13149 | struct arm_long_option_table |
13150 | { | |
13151 | char * option; /* Substring to match. */ | |
13152 | char * help; /* Help information. */ | |
13153 | int (* func) (char * subopt); /* Function to decode sub-option. */ | |
13154 | char * deprecated; /* If non-null, print this message. */ | |
13155 | }; | |
7ed4c4c5 NC |
13156 | |
13157 | static int | |
e74cfd16 | 13158 | arm_parse_extension (char * str, const arm_feature_set **opt_p) |
7ed4c4c5 | 13159 | { |
e74cfd16 PB |
13160 | arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set)); |
13161 | ||
13162 | /* Copy the feature set, so that we can modify it. */ | |
13163 | *ext_set = **opt_p; | |
13164 | *opt_p = ext_set; | |
13165 | ||
c19d1205 | 13166 | while (str != NULL && *str != 0) |
7ed4c4c5 | 13167 | { |
e74cfd16 | 13168 | const struct arm_option_cpu_value_table * opt; |
c19d1205 ZW |
13169 | char * ext; |
13170 | int optlen; | |
7ed4c4c5 | 13171 | |
c19d1205 ZW |
13172 | if (*str != '+') |
13173 | { | |
13174 | as_bad (_("invalid architectural extension")); | |
13175 | return 0; | |
13176 | } | |
7ed4c4c5 | 13177 | |
c19d1205 ZW |
13178 | str++; |
13179 | ext = strchr (str, '+'); | |
7ed4c4c5 | 13180 | |
c19d1205 ZW |
13181 | if (ext != NULL) |
13182 | optlen = ext - str; | |
13183 | else | |
13184 | optlen = strlen (str); | |
7ed4c4c5 | 13185 | |
c19d1205 ZW |
13186 | if (optlen == 0) |
13187 | { | |
13188 | as_bad (_("missing architectural extension")); | |
13189 | return 0; | |
13190 | } | |
7ed4c4c5 | 13191 | |
c19d1205 ZW |
13192 | for (opt = arm_extensions; opt->name != NULL; opt++) |
13193 | if (strncmp (opt->name, str, optlen) == 0) | |
13194 | { | |
e74cfd16 | 13195 | ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value); |
c19d1205 ZW |
13196 | break; |
13197 | } | |
7ed4c4c5 | 13198 | |
c19d1205 ZW |
13199 | if (opt->name == NULL) |
13200 | { | |
13201 | as_bad (_("unknown architectural extnsion `%s'"), str); | |
13202 | return 0; | |
13203 | } | |
7ed4c4c5 | 13204 | |
c19d1205 ZW |
13205 | str = ext; |
13206 | }; | |
7ed4c4c5 | 13207 | |
c19d1205 ZW |
13208 | return 1; |
13209 | } | |
7ed4c4c5 | 13210 | |
c19d1205 ZW |
13211 | static int |
13212 | arm_parse_cpu (char * str) | |
7ed4c4c5 | 13213 | { |
e74cfd16 | 13214 | const struct arm_cpu_option_table * opt; |
c19d1205 ZW |
13215 | char * ext = strchr (str, '+'); |
13216 | int optlen; | |
7ed4c4c5 | 13217 | |
c19d1205 ZW |
13218 | if (ext != NULL) |
13219 | optlen = ext - str; | |
7ed4c4c5 | 13220 | else |
c19d1205 | 13221 | optlen = strlen (str); |
7ed4c4c5 | 13222 | |
c19d1205 | 13223 | if (optlen == 0) |
7ed4c4c5 | 13224 | { |
c19d1205 ZW |
13225 | as_bad (_("missing cpu name `%s'"), str); |
13226 | return 0; | |
7ed4c4c5 NC |
13227 | } |
13228 | ||
c19d1205 ZW |
13229 | for (opt = arm_cpus; opt->name != NULL; opt++) |
13230 | if (strncmp (opt->name, str, optlen) == 0) | |
13231 | { | |
e74cfd16 PB |
13232 | mcpu_cpu_opt = &opt->value; |
13233 | mcpu_fpu_opt = &opt->default_fpu; | |
ee065d83 PB |
13234 | if (opt->canonical_name) |
13235 | strcpy(selected_cpu_name, opt->canonical_name); | |
13236 | else | |
13237 | { | |
13238 | int i; | |
13239 | for (i = 0; i < optlen; i++) | |
13240 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
13241 | selected_cpu_name[i] = 0; | |
13242 | } | |
7ed4c4c5 | 13243 | |
c19d1205 ZW |
13244 | if (ext != NULL) |
13245 | return arm_parse_extension (ext, &mcpu_cpu_opt); | |
7ed4c4c5 | 13246 | |
c19d1205 ZW |
13247 | return 1; |
13248 | } | |
7ed4c4c5 | 13249 | |
c19d1205 ZW |
13250 | as_bad (_("unknown cpu `%s'"), str); |
13251 | return 0; | |
7ed4c4c5 NC |
13252 | } |
13253 | ||
c19d1205 ZW |
13254 | static int |
13255 | arm_parse_arch (char * str) | |
7ed4c4c5 | 13256 | { |
e74cfd16 | 13257 | const struct arm_arch_option_table *opt; |
c19d1205 ZW |
13258 | char *ext = strchr (str, '+'); |
13259 | int optlen; | |
7ed4c4c5 | 13260 | |
c19d1205 ZW |
13261 | if (ext != NULL) |
13262 | optlen = ext - str; | |
7ed4c4c5 | 13263 | else |
c19d1205 | 13264 | optlen = strlen (str); |
7ed4c4c5 | 13265 | |
c19d1205 | 13266 | if (optlen == 0) |
7ed4c4c5 | 13267 | { |
c19d1205 ZW |
13268 | as_bad (_("missing architecture name `%s'"), str); |
13269 | return 0; | |
7ed4c4c5 NC |
13270 | } |
13271 | ||
c19d1205 ZW |
13272 | for (opt = arm_archs; opt->name != NULL; opt++) |
13273 | if (streq (opt->name, str)) | |
13274 | { | |
e74cfd16 PB |
13275 | march_cpu_opt = &opt->value; |
13276 | march_fpu_opt = &opt->default_fpu; | |
ee065d83 | 13277 | strcpy(selected_cpu_name, opt->name); |
7ed4c4c5 | 13278 | |
c19d1205 ZW |
13279 | if (ext != NULL) |
13280 | return arm_parse_extension (ext, &march_cpu_opt); | |
7ed4c4c5 | 13281 | |
c19d1205 ZW |
13282 | return 1; |
13283 | } | |
13284 | ||
13285 | as_bad (_("unknown architecture `%s'\n"), str); | |
13286 | return 0; | |
7ed4c4c5 | 13287 | } |
eb043451 | 13288 | |
c19d1205 ZW |
13289 | static int |
13290 | arm_parse_fpu (char * str) | |
13291 | { | |
e74cfd16 | 13292 | const struct arm_option_cpu_value_table * opt; |
b99bd4ef | 13293 | |
c19d1205 ZW |
13294 | for (opt = arm_fpus; opt->name != NULL; opt++) |
13295 | if (streq (opt->name, str)) | |
13296 | { | |
e74cfd16 | 13297 | mfpu_opt = &opt->value; |
c19d1205 ZW |
13298 | return 1; |
13299 | } | |
b99bd4ef | 13300 | |
c19d1205 ZW |
13301 | as_bad (_("unknown floating point format `%s'\n"), str); |
13302 | return 0; | |
13303 | } | |
13304 | ||
13305 | static int | |
13306 | arm_parse_float_abi (char * str) | |
b99bd4ef | 13307 | { |
e74cfd16 | 13308 | const struct arm_option_value_table * opt; |
b99bd4ef | 13309 | |
c19d1205 ZW |
13310 | for (opt = arm_float_abis; opt->name != NULL; opt++) |
13311 | if (streq (opt->name, str)) | |
13312 | { | |
13313 | mfloat_abi_opt = opt->value; | |
13314 | return 1; | |
13315 | } | |
cc8a6dd0 | 13316 | |
c19d1205 ZW |
13317 | as_bad (_("unknown floating point abi `%s'\n"), str); |
13318 | return 0; | |
13319 | } | |
b99bd4ef | 13320 | |
c19d1205 ZW |
13321 | #ifdef OBJ_ELF |
13322 | static int | |
13323 | arm_parse_eabi (char * str) | |
13324 | { | |
e74cfd16 | 13325 | const struct arm_option_value_table *opt; |
cc8a6dd0 | 13326 | |
c19d1205 ZW |
13327 | for (opt = arm_eabis; opt->name != NULL; opt++) |
13328 | if (streq (opt->name, str)) | |
13329 | { | |
13330 | meabi_flags = opt->value; | |
13331 | return 1; | |
13332 | } | |
13333 | as_bad (_("unknown EABI `%s'\n"), str); | |
13334 | return 0; | |
13335 | } | |
13336 | #endif | |
cc8a6dd0 | 13337 | |
c19d1205 ZW |
13338 | struct arm_long_option_table arm_long_opts[] = |
13339 | { | |
13340 | {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"), | |
13341 | arm_parse_cpu, NULL}, | |
13342 | {"march=", N_("<arch name>\t assemble for architecture <arch name>"), | |
13343 | arm_parse_arch, NULL}, | |
13344 | {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"), | |
13345 | arm_parse_fpu, NULL}, | |
13346 | {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"), | |
13347 | arm_parse_float_abi, NULL}, | |
13348 | #ifdef OBJ_ELF | |
13349 | {"meabi=", N_("<ver>\t assemble for eabi version <ver>"), | |
13350 | arm_parse_eabi, NULL}, | |
13351 | #endif | |
13352 | {NULL, NULL, 0, NULL} | |
13353 | }; | |
cc8a6dd0 | 13354 | |
c19d1205 ZW |
13355 | int |
13356 | md_parse_option (int c, char * arg) | |
13357 | { | |
13358 | struct arm_option_table *opt; | |
e74cfd16 | 13359 | const struct arm_legacy_option_table *fopt; |
c19d1205 | 13360 | struct arm_long_option_table *lopt; |
b99bd4ef | 13361 | |
c19d1205 | 13362 | switch (c) |
b99bd4ef | 13363 | { |
c19d1205 ZW |
13364 | #ifdef OPTION_EB |
13365 | case OPTION_EB: | |
13366 | target_big_endian = 1; | |
13367 | break; | |
13368 | #endif | |
cc8a6dd0 | 13369 | |
c19d1205 ZW |
13370 | #ifdef OPTION_EL |
13371 | case OPTION_EL: | |
13372 | target_big_endian = 0; | |
13373 | break; | |
13374 | #endif | |
b99bd4ef | 13375 | |
c19d1205 ZW |
13376 | case 'a': |
13377 | /* Listing option. Just ignore these, we don't support additional | |
13378 | ones. */ | |
13379 | return 0; | |
b99bd4ef | 13380 | |
c19d1205 ZW |
13381 | default: |
13382 | for (opt = arm_opts; opt->option != NULL; opt++) | |
13383 | { | |
13384 | if (c == opt->option[0] | |
13385 | && ((arg == NULL && opt->option[1] == 0) | |
13386 | || streq (arg, opt->option + 1))) | |
13387 | { | |
13388 | #if WARN_DEPRECATED | |
13389 | /* If the option is deprecated, tell the user. */ | |
13390 | if (opt->deprecated != NULL) | |
13391 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
13392 | arg ? arg : "", _(opt->deprecated)); | |
13393 | #endif | |
b99bd4ef | 13394 | |
c19d1205 ZW |
13395 | if (opt->var != NULL) |
13396 | *opt->var = opt->value; | |
cc8a6dd0 | 13397 | |
c19d1205 ZW |
13398 | return 1; |
13399 | } | |
13400 | } | |
b99bd4ef | 13401 | |
e74cfd16 PB |
13402 | for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++) |
13403 | { | |
13404 | if (c == fopt->option[0] | |
13405 | && ((arg == NULL && fopt->option[1] == 0) | |
13406 | || streq (arg, fopt->option + 1))) | |
13407 | { | |
13408 | #if WARN_DEPRECATED | |
13409 | /* If the option is deprecated, tell the user. */ | |
13410 | if (fopt->deprecated != NULL) | |
13411 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, | |
13412 | arg ? arg : "", _(fopt->deprecated)); | |
13413 | #endif | |
13414 | ||
13415 | if (fopt->var != NULL) | |
13416 | *fopt->var = &fopt->value; | |
13417 | ||
13418 | return 1; | |
13419 | } | |
13420 | } | |
13421 | ||
c19d1205 ZW |
13422 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
13423 | { | |
13424 | /* These options are expected to have an argument. */ | |
13425 | if (c == lopt->option[0] | |
13426 | && arg != NULL | |
13427 | && strncmp (arg, lopt->option + 1, | |
13428 | strlen (lopt->option + 1)) == 0) | |
13429 | { | |
13430 | #if WARN_DEPRECATED | |
13431 | /* If the option is deprecated, tell the user. */ | |
13432 | if (lopt->deprecated != NULL) | |
13433 | as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg, | |
13434 | _(lopt->deprecated)); | |
13435 | #endif | |
b99bd4ef | 13436 | |
c19d1205 ZW |
13437 | /* Call the sup-option parser. */ |
13438 | return lopt->func (arg + strlen (lopt->option) - 1); | |
13439 | } | |
13440 | } | |
a737bd4d | 13441 | |
c19d1205 ZW |
13442 | return 0; |
13443 | } | |
a394c00f | 13444 | |
c19d1205 ZW |
13445 | return 1; |
13446 | } | |
a394c00f | 13447 | |
c19d1205 ZW |
13448 | void |
13449 | md_show_usage (FILE * fp) | |
a394c00f | 13450 | { |
c19d1205 ZW |
13451 | struct arm_option_table *opt; |
13452 | struct arm_long_option_table *lopt; | |
a394c00f | 13453 | |
c19d1205 | 13454 | fprintf (fp, _(" ARM-specific assembler options:\n")); |
a394c00f | 13455 | |
c19d1205 ZW |
13456 | for (opt = arm_opts; opt->option != NULL; opt++) |
13457 | if (opt->help != NULL) | |
13458 | fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help)); | |
a394c00f | 13459 | |
c19d1205 ZW |
13460 | for (lopt = arm_long_opts; lopt->option != NULL; lopt++) |
13461 | if (lopt->help != NULL) | |
13462 | fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help)); | |
a394c00f | 13463 | |
c19d1205 ZW |
13464 | #ifdef OPTION_EB |
13465 | fprintf (fp, _("\ | |
13466 | -EB assemble code for a big-endian cpu\n")); | |
a394c00f NC |
13467 | #endif |
13468 | ||
c19d1205 ZW |
13469 | #ifdef OPTION_EL |
13470 | fprintf (fp, _("\ | |
13471 | -EL assemble code for a little-endian cpu\n")); | |
a737bd4d | 13472 | #endif |
c19d1205 | 13473 | } |
ee065d83 PB |
13474 | |
13475 | ||
13476 | #ifdef OBJ_ELF | |
13477 | /* Set the public EABI object attributes. */ | |
13478 | static void | |
13479 | aeabi_set_public_attributes (void) | |
13480 | { | |
13481 | int arch; | |
e74cfd16 | 13482 | arm_feature_set flags; |
ee065d83 PB |
13483 | |
13484 | /* Choose the architecture based on the capabilities of the requested cpu | |
13485 | (if any) and/or the instructions actually used. */ | |
e74cfd16 PB |
13486 | ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used); |
13487 | ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt); | |
13488 | ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu); | |
13489 | if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v6t2)) | |
ee065d83 | 13490 | arch = 8; |
e74cfd16 | 13491 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v6z)) |
ee065d83 | 13492 | arch = 7; |
e74cfd16 | 13493 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v6k)) |
ee065d83 | 13494 | arch = 9; |
e74cfd16 | 13495 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v6)) |
ee065d83 | 13496 | arch = 6; |
e74cfd16 | 13497 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v5e)) |
ee065d83 | 13498 | arch = 4; |
e74cfd16 PB |
13499 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v5) |
13500 | || ARM_CPU_HAS_FEATURE (flags, arm_ext_v5t)) | |
ee065d83 | 13501 | arch = 3; |
e74cfd16 | 13502 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)) |
ee065d83 | 13503 | arch = 2; |
e74cfd16 | 13504 | else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4)) |
ee065d83 PB |
13505 | arch = 1; |
13506 | else | |
13507 | arch = 0; | |
13508 | ||
13509 | /* Tag_CPU_name. */ | |
13510 | if (selected_cpu_name[0]) | |
13511 | { | |
13512 | char *p; | |
13513 | ||
13514 | p = selected_cpu_name; | |
13515 | if (strncmp(p, "armv", 4) == 0) | |
13516 | { | |
13517 | int i; | |
13518 | ||
13519 | p += 4; | |
13520 | for (i = 0; p[i]; i++) | |
13521 | p[i] = TOUPPER (p[i]); | |
13522 | } | |
13523 | elf32_arm_add_eabi_attr_string (stdoutput, 5, p); | |
13524 | } | |
13525 | /* Tag_CPU_arch. */ | |
13526 | elf32_arm_add_eabi_attr_int (stdoutput, 6, arch); | |
13527 | /* Tag_ARM_ISA_use. */ | |
e74cfd16 | 13528 | if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full)) |
ee065d83 PB |
13529 | elf32_arm_add_eabi_attr_int (stdoutput, 8, 1); |
13530 | /* Tag_THUMB_ISA_use. */ | |
e74cfd16 | 13531 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full)) |
ee065d83 | 13532 | elf32_arm_add_eabi_attr_int (stdoutput, 9, |
e74cfd16 | 13533 | ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1); |
ee065d83 | 13534 | /* Tag_VFP_arch. */ |
e74cfd16 PB |
13535 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v2) |
13536 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v2)) | |
ee065d83 | 13537 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 2); |
e74cfd16 PB |
13538 | else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v1) |
13539 | || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v1)) | |
ee065d83 PB |
13540 | elf32_arm_add_eabi_attr_int (stdoutput, 10, 1); |
13541 | /* Tag_WMMX_arch. */ | |
e74cfd16 PB |
13542 | if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt) |
13543 | || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt)) | |
ee065d83 PB |
13544 | elf32_arm_add_eabi_attr_int (stdoutput, 11, 1); |
13545 | } | |
13546 | ||
13547 | /* Add the .ARM.attributes section. */ | |
13548 | void | |
13549 | arm_md_end (void) | |
13550 | { | |
13551 | segT s; | |
13552 | char *p; | |
13553 | addressT addr; | |
13554 | offsetT size; | |
13555 | ||
13556 | if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4) | |
13557 | return; | |
13558 | ||
13559 | aeabi_set_public_attributes (); | |
13560 | size = elf32_arm_eabi_attr_size (stdoutput); | |
13561 | s = subseg_new (".ARM.attributes", 0); | |
13562 | bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA); | |
13563 | addr = frag_now_fix (); | |
13564 | p = frag_more (size); | |
13565 | elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size); | |
13566 | } | |
13567 | ||
13568 | ||
13569 | /* Parse a .cpu directive. */ | |
13570 | ||
13571 | static void | |
13572 | s_arm_cpu (int ignored ATTRIBUTE_UNUSED) | |
13573 | { | |
e74cfd16 | 13574 | const struct arm_cpu_option_table *opt; |
ee065d83 PB |
13575 | char *name; |
13576 | char saved_char; | |
13577 | ||
13578 | name = input_line_pointer; | |
13579 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
13580 | input_line_pointer++; | |
13581 | saved_char = *input_line_pointer; | |
13582 | *input_line_pointer = 0; | |
13583 | ||
13584 | /* Skip the first "all" entry. */ | |
13585 | for (opt = arm_cpus + 1; opt->name != NULL; opt++) | |
13586 | if (streq (opt->name, name)) | |
13587 | { | |
e74cfd16 PB |
13588 | mcpu_cpu_opt = &opt->value; |
13589 | selected_cpu = opt->value; | |
ee065d83 PB |
13590 | if (opt->canonical_name) |
13591 | strcpy(selected_cpu_name, opt->canonical_name); | |
13592 | else | |
13593 | { | |
13594 | int i; | |
13595 | for (i = 0; opt->name[i]; i++) | |
13596 | selected_cpu_name[i] = TOUPPER (opt->name[i]); | |
13597 | selected_cpu_name[i] = 0; | |
13598 | } | |
e74cfd16 | 13599 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
13600 | *input_line_pointer = saved_char; |
13601 | demand_empty_rest_of_line (); | |
13602 | return; | |
13603 | } | |
13604 | as_bad (_("unknown cpu `%s'"), name); | |
13605 | *input_line_pointer = saved_char; | |
13606 | ignore_rest_of_line (); | |
13607 | } | |
13608 | ||
13609 | ||
13610 | /* Parse a .arch directive. */ | |
13611 | ||
13612 | static void | |
13613 | s_arm_arch (int ignored ATTRIBUTE_UNUSED) | |
13614 | { | |
e74cfd16 | 13615 | const struct arm_arch_option_table *opt; |
ee065d83 PB |
13616 | char saved_char; |
13617 | char *name; | |
13618 | ||
13619 | name = input_line_pointer; | |
13620 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
13621 | input_line_pointer++; | |
13622 | saved_char = *input_line_pointer; | |
13623 | *input_line_pointer = 0; | |
13624 | ||
13625 | /* Skip the first "all" entry. */ | |
13626 | for (opt = arm_archs + 1; opt->name != NULL; opt++) | |
13627 | if (streq (opt->name, name)) | |
13628 | { | |
e74cfd16 PB |
13629 | mcpu_cpu_opt = &opt->value; |
13630 | selected_cpu = opt->value; | |
ee065d83 | 13631 | strcpy(selected_cpu_name, opt->name); |
e74cfd16 | 13632 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); |
ee065d83 PB |
13633 | *input_line_pointer = saved_char; |
13634 | demand_empty_rest_of_line (); | |
13635 | return; | |
13636 | } | |
13637 | ||
13638 | as_bad (_("unknown architecture `%s'\n"), name); | |
13639 | *input_line_pointer = saved_char; | |
13640 | ignore_rest_of_line (); | |
13641 | } | |
13642 | ||
13643 | ||
13644 | /* Parse a .fpu directive. */ | |
13645 | ||
13646 | static void | |
13647 | s_arm_fpu (int ignored ATTRIBUTE_UNUSED) | |
13648 | { | |
e74cfd16 | 13649 | const struct arm_option_cpu_value_table *opt; |
ee065d83 PB |
13650 | char saved_char; |
13651 | char *name; | |
13652 | ||
13653 | name = input_line_pointer; | |
13654 | while (*input_line_pointer && !ISSPACE(*input_line_pointer)) | |
13655 | input_line_pointer++; | |
13656 | saved_char = *input_line_pointer; | |
13657 | *input_line_pointer = 0; | |
13658 | ||
13659 | for (opt = arm_fpus; opt->name != NULL; opt++) | |
13660 | if (streq (opt->name, name)) | |
13661 | { | |
e74cfd16 PB |
13662 | mfpu_opt = &opt->value; |
13663 | ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt); | |
ee065d83 PB |
13664 | *input_line_pointer = saved_char; |
13665 | demand_empty_rest_of_line (); | |
13666 | return; | |
13667 | } | |
13668 | ||
13669 | as_bad (_("unknown floating point format `%s'\n"), name); | |
13670 | *input_line_pointer = saved_char; | |
13671 | ignore_rest_of_line (); | |
13672 | } | |
13673 | #endif /* OBJ_ELF */ | |
13674 |