]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
2006-03-20 Paul Brook <paul@codesourcery.com>
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
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
57static 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. */
89static unsigned int marked_pr_dependency = 0;
90
7ed4c4c5
NC
91#endif /* OBJ_ELF */
92
33a392fb
PB
93enum 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
131static arm_feature_set cpu_variant;
132static arm_feature_set arm_arch_used;
133static arm_feature_set thumb_arch_used;
b99bd4ef 134
b99bd4ef 135/* Flags stored in private area of BFD structure. */
c19d1205
ZW
136static int uses_apcs_26 = FALSE;
137static int atpcs = FALSE;
b34976b6
AM
138static int support_interwork = FALSE;
139static int uses_apcs_float = FALSE;
c19d1205 140static 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
145static const arm_feature_set *legacy_cpu = NULL;
146static const arm_feature_set *legacy_fpu = NULL;
147
148static const arm_feature_set *mcpu_cpu_opt = NULL;
149static const arm_feature_set *mcpu_fpu_opt = NULL;
150static const arm_feature_set *march_cpu_opt = NULL;
151static const arm_feature_set *march_fpu_opt = NULL;
152static const arm_feature_set *mfpu_opt = NULL;
153
154/* Constants for known architecture features. */
155static const arm_feature_set fpu_default = FPU_DEFAULT;
156static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
157static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
158static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
159static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
160static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
161static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
162
163#ifdef CPU_DEFAULT
164static const arm_feature_set cpu_default = CPU_DEFAULT;
165#endif
166
167static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
168static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
169static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
170static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
171static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
172static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
173static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
174static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
175static const arm_feature_set arm_ext_v4t_5 =
176 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
177static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
178static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
179static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
180static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
181static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
182static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
183static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
184static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311
PB
185static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
186static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
187static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
188static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
189static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
190static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
e74cfd16
PB
191
192static const arm_feature_set arm_arch_any = ARM_ANY;
193static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
194static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
195static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
196
197static const arm_feature_set arm_cext_iwmmxt =
198 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
199static const arm_feature_set arm_cext_xscale =
200 ARM_FEATURE (0, ARM_CEXT_XSCALE);
201static const arm_feature_set arm_cext_maverick =
202 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
203static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
204static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
205static const arm_feature_set fpu_vfp_ext_v1xd =
206 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
207static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
208static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
209
33a392fb 210static int mfloat_abi_opt = -1;
e74cfd16
PB
211/* Record user cpu selection for object attributes. */
212static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
213/* Must be long enough to hold any of the names in arm_cpus. */
214static char selected_cpu_name[16];
7cc69913 215#ifdef OBJ_ELF
deeaaff8
DJ
216# ifdef EABI_DEFAULT
217static int meabi_flags = EABI_DEFAULT;
218# else
d507cf36 219static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 220# endif
7cc69913 221#endif
b99bd4ef 222
b99bd4ef 223#ifdef OBJ_ELF
c19d1205 224/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
225symbolS * GOT_symbol;
226#endif
227
b99bd4ef
NC
228/* 0: assemble for ARM,
229 1: assemble for Thumb,
230 2: assemble for Thumb even though target CPU does not support thumb
231 instructions. */
232static int thumb_mode = 0;
233
c19d1205
ZW
234/* If unified_syntax is true, we are processing the new unified
235 ARM/Thumb syntax. Important differences from the old ARM mode:
236
237 - Immediate operands do not require a # prefix.
238 - Conditional affixes always appear at the end of the
239 instruction. (For backward compatibility, those instructions
240 that formerly had them in the middle, continue to accept them
241 there.)
242 - The IT instruction may appear, and if it does is validated
243 against subsequent conditional affixes. It does not generate
244 machine code.
245
246 Important differences from the old Thumb mode:
247
248 - Immediate operands do not require a # prefix.
249 - Most of the V6T2 instructions are only available in unified mode.
250 - The .N and .W suffixes are recognized and honored (it is an error
251 if they cannot be honored).
252 - All instructions set the flags if and only if they have an 's' affix.
253 - Conditional affixes may be used. They are validated against
254 preceding IT instructions. Unlike ARM mode, you cannot use a
255 conditional affix except in the scope of an IT instruction. */
256
257static bfd_boolean unified_syntax = FALSE;
b99bd4ef
NC
258
259struct arm_it
260{
c19d1205 261 const char * error;
b99bd4ef 262 unsigned long instruction;
c19d1205
ZW
263 int size;
264 int size_req;
265 int cond;
0110f2b8
PB
266 /* Set to the opcode if the instruction needs relaxation.
267 Zero if the instruction is not relaxed. */
268 unsigned long relax;
b99bd4ef
NC
269 struct
270 {
271 bfd_reloc_code_real_type type;
c19d1205
ZW
272 expressionS exp;
273 int pc_rel;
b99bd4ef 274 } reloc;
b99bd4ef 275
c19d1205
ZW
276 struct
277 {
278 unsigned reg;
ca3f61f7
NC
279 signed int imm;
280 unsigned present : 1; /* Operand present. */
281 unsigned isreg : 1; /* Operand was a register. */
282 unsigned immisreg : 1; /* .imm field is a second register. */
283 unsigned hasreloc : 1; /* Operand has relocation suffix. */
284 unsigned writeback : 1; /* Operand has trailing ! */
285 unsigned preind : 1; /* Preindexed address. */
286 unsigned postind : 1; /* Postindexed address. */
287 unsigned negative : 1; /* Index register was negated. */
288 unsigned shifted : 1; /* Shift applied to operation. */
289 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 290 } operands[6];
b99bd4ef
NC
291};
292
c19d1205 293static struct arm_it inst;
b99bd4ef
NC
294
295#define NUM_FLOAT_VALS 8
296
05d2d07e 297const char * fp_const[] =
b99bd4ef
NC
298{
299 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
300};
301
c19d1205 302/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
303#define MAX_LITTLENUMS 6
304
305LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
306
307#define FAIL (-1)
308#define SUCCESS (0)
309
310#define SUFF_S 1
311#define SUFF_D 2
312#define SUFF_E 3
313#define SUFF_P 4
314
c19d1205
ZW
315#define CP_T_X 0x00008000
316#define CP_T_Y 0x00400000
b99bd4ef 317
c19d1205
ZW
318#define CONDS_BIT 0x00100000
319#define LOAD_BIT 0x00100000
b99bd4ef
NC
320
321#define DOUBLE_LOAD_FLAG 0x00000001
322
323struct asm_cond
324{
c19d1205 325 const char * template;
b99bd4ef
NC
326 unsigned long value;
327};
328
c19d1205 329#define COND_ALWAYS 0xE
b99bd4ef 330
b99bd4ef
NC
331struct asm_psr
332{
b34976b6 333 const char *template;
b99bd4ef
NC
334 unsigned long field;
335};
336
62b3e311
PB
337struct asm_barrier_opt
338{
339 const char *template;
340 unsigned long value;
341};
342
2d2255b5 343/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
344#define SPSR_BIT (1 << 22)
345
c19d1205
ZW
346/* The individual PSR flag bits. */
347#define PSR_c (1 << 16)
348#define PSR_x (1 << 17)
349#define PSR_s (1 << 18)
350#define PSR_f (1 << 19)
b99bd4ef 351
c19d1205 352struct reloc_entry
bfae80f2 353{
c19d1205
ZW
354 char *name;
355 bfd_reloc_code_real_type reloc;
bfae80f2
RE
356};
357
358enum vfp_sp_reg_pos
359{
360 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn
361};
362
363enum vfp_ldstm_type
364{
365 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
366};
367
c19d1205
ZW
368/* ARM register categories. This includes coprocessor numbers and various
369 architecture extensions' registers. */
370enum arm_reg_type
bfae80f2 371{
c19d1205
ZW
372 REG_TYPE_RN,
373 REG_TYPE_CP,
374 REG_TYPE_CN,
375 REG_TYPE_FN,
376 REG_TYPE_VFS,
377 REG_TYPE_VFD,
378 REG_TYPE_VFC,
379 REG_TYPE_MVF,
380 REG_TYPE_MVD,
381 REG_TYPE_MVFX,
382 REG_TYPE_MVDX,
383 REG_TYPE_MVAX,
384 REG_TYPE_DSPSC,
385 REG_TYPE_MMXWR,
386 REG_TYPE_MMXWC,
387 REG_TYPE_MMXWCG,
388 REG_TYPE_XSCALE,
bfae80f2
RE
389};
390
6c43fab6
RE
391/* Structure for a hash table entry for a register. */
392struct reg_entry
393{
c19d1205
ZW
394 const char *name;
395 unsigned char number;
396 unsigned char type;
397 unsigned char builtin;
6c43fab6
RE
398};
399
c19d1205
ZW
400/* Diagnostics used when we don't get a register of the expected type. */
401const char *const reg_expected_msgs[] =
402{
403 N_("ARM register expected"),
404 N_("bad or missing co-processor number"),
405 N_("co-processor register expected"),
406 N_("FPA register expected"),
407 N_("VFP single precision register expected"),
408 N_("VFP double precision register expected"),
409 N_("VFP system register expected"),
410 N_("Maverick MVF register expected"),
411 N_("Maverick MVD register expected"),
412 N_("Maverick MVFX register expected"),
413 N_("Maverick MVDX register expected"),
414 N_("Maverick MVAX register expected"),
415 N_("Maverick DSPSC register expected"),
416 N_("iWMMXt data register expected"),
417 N_("iWMMXt control register expected"),
418 N_("iWMMXt scalar register expected"),
419 N_("XScale accumulator register expected"),
6c43fab6
RE
420};
421
c19d1205
ZW
422/* Some well known registers that we refer to directly elsewhere. */
423#define REG_SP 13
424#define REG_LR 14
425#define REG_PC 15
404ff6b5 426
b99bd4ef
NC
427/* ARM instructions take 4bytes in the object file, Thumb instructions
428 take 2: */
c19d1205 429#define INSN_SIZE 4
b99bd4ef
NC
430
431struct asm_opcode
432{
433 /* Basic string to match. */
c19d1205
ZW
434 const char *template;
435
436 /* Parameters to instruction. */
437 unsigned char operands[8];
438
439 /* Conditional tag - see opcode_lookup. */
440 unsigned int tag : 4;
b99bd4ef
NC
441
442 /* Basic instruction code. */
c19d1205 443 unsigned int avalue : 28;
b99bd4ef 444
c19d1205
ZW
445 /* Thumb-format instruction code. */
446 unsigned int tvalue;
b99bd4ef 447
90e4755a 448 /* Which architecture variant provides this instruction. */
e74cfd16
PB
449 const arm_feature_set *avariant;
450 const arm_feature_set *tvariant;
c19d1205
ZW
451
452 /* Function to call to encode instruction in ARM format. */
453 void (* aencode) (void);
b99bd4ef 454
c19d1205
ZW
455 /* Function to call to encode instruction in Thumb format. */
456 void (* tencode) (void);
b99bd4ef
NC
457};
458
a737bd4d
NC
459/* Defines for various bits that we will want to toggle. */
460#define INST_IMMEDIATE 0x02000000
461#define OFFSET_REG 0x02000000
c19d1205 462#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
463#define SHIFT_BY_REG 0x00000010
464#define PRE_INDEX 0x01000000
465#define INDEX_UP 0x00800000
466#define WRITE_BACK 0x00200000
467#define LDM_TYPE_2_OR_3 0x00400000
90e4755a 468
a737bd4d
NC
469#define LITERAL_MASK 0xf000f000
470#define OPCODE_MASK 0xfe1fffff
471#define V4_STR_BIT 0x00000020
90e4755a 472
a737bd4d 473#define DATA_OP_SHIFT 21
90e4755a 474
ef8d22e6
PB
475#define T2_OPCODE_MASK 0xfe1fffff
476#define T2_DATA_OP_SHIFT 21
477
a737bd4d
NC
478/* Codes to distinguish the arithmetic instructions. */
479#define OPCODE_AND 0
480#define OPCODE_EOR 1
481#define OPCODE_SUB 2
482#define OPCODE_RSB 3
483#define OPCODE_ADD 4
484#define OPCODE_ADC 5
485#define OPCODE_SBC 6
486#define OPCODE_RSC 7
487#define OPCODE_TST 8
488#define OPCODE_TEQ 9
489#define OPCODE_CMP 10
490#define OPCODE_CMN 11
491#define OPCODE_ORR 12
492#define OPCODE_MOV 13
493#define OPCODE_BIC 14
494#define OPCODE_MVN 15
90e4755a 495
ef8d22e6
PB
496#define T2_OPCODE_AND 0
497#define T2_OPCODE_BIC 1
498#define T2_OPCODE_ORR 2
499#define T2_OPCODE_ORN 3
500#define T2_OPCODE_EOR 4
501#define T2_OPCODE_ADD 8
502#define T2_OPCODE_ADC 10
503#define T2_OPCODE_SBC 11
504#define T2_OPCODE_SUB 13
505#define T2_OPCODE_RSB 14
506
a737bd4d
NC
507#define T_OPCODE_MUL 0x4340
508#define T_OPCODE_TST 0x4200
509#define T_OPCODE_CMN 0x42c0
510#define T_OPCODE_NEG 0x4240
511#define T_OPCODE_MVN 0x43c0
90e4755a 512
a737bd4d
NC
513#define T_OPCODE_ADD_R3 0x1800
514#define T_OPCODE_SUB_R3 0x1a00
515#define T_OPCODE_ADD_HI 0x4400
516#define T_OPCODE_ADD_ST 0xb000
517#define T_OPCODE_SUB_ST 0xb080
518#define T_OPCODE_ADD_SP 0xa800
519#define T_OPCODE_ADD_PC 0xa000
520#define T_OPCODE_ADD_I8 0x3000
521#define T_OPCODE_SUB_I8 0x3800
522#define T_OPCODE_ADD_I3 0x1c00
523#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 524
a737bd4d
NC
525#define T_OPCODE_ASR_R 0x4100
526#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
527#define T_OPCODE_LSR_R 0x40c0
528#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
529#define T_OPCODE_ASR_I 0x1000
530#define T_OPCODE_LSL_I 0x0000
531#define T_OPCODE_LSR_I 0x0800
b99bd4ef 532
a737bd4d
NC
533#define T_OPCODE_MOV_I8 0x2000
534#define T_OPCODE_CMP_I8 0x2800
535#define T_OPCODE_CMP_LR 0x4280
536#define T_OPCODE_MOV_HR 0x4600
537#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 538
a737bd4d
NC
539#define T_OPCODE_LDR_PC 0x4800
540#define T_OPCODE_LDR_SP 0x9800
541#define T_OPCODE_STR_SP 0x9000
542#define T_OPCODE_LDR_IW 0x6800
543#define T_OPCODE_STR_IW 0x6000
544#define T_OPCODE_LDR_IH 0x8800
545#define T_OPCODE_STR_IH 0x8000
546#define T_OPCODE_LDR_IB 0x7800
547#define T_OPCODE_STR_IB 0x7000
548#define T_OPCODE_LDR_RW 0x5800
549#define T_OPCODE_STR_RW 0x5000
550#define T_OPCODE_LDR_RH 0x5a00
551#define T_OPCODE_STR_RH 0x5200
552#define T_OPCODE_LDR_RB 0x5c00
553#define T_OPCODE_STR_RB 0x5400
c9b604bd 554
a737bd4d
NC
555#define T_OPCODE_PUSH 0xb400
556#define T_OPCODE_POP 0xbc00
b99bd4ef 557
2fc8bdac 558#define T_OPCODE_BRANCH 0xe000
b99bd4ef 559
a737bd4d 560#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 561#define THUMB_PP_PC_LR 0x0100
c19d1205
ZW
562#define THUMB_LOAD_BIT 0x0800
563
564#define BAD_ARGS _("bad arguments to instruction")
565#define BAD_PC _("r15 not allowed here")
566#define BAD_COND _("instruction cannot be conditional")
567#define BAD_OVERLAP _("registers may not be the same")
568#define BAD_HIREG _("lo register required")
569#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 570#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
c19d1205
ZW
571
572static struct hash_control *arm_ops_hsh;
573static struct hash_control *arm_cond_hsh;
574static struct hash_control *arm_shift_hsh;
575static struct hash_control *arm_psr_hsh;
62b3e311 576static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
577static struct hash_control *arm_reg_hsh;
578static struct hash_control *arm_reloc_hsh;
62b3e311 579static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 580
b99bd4ef
NC
581/* Stuff needed to resolve the label ambiguity
582 As:
583 ...
584 label: <insn>
585 may differ from:
586 ...
587 label:
c19d1205 588 <insn>
b99bd4ef
NC
589*/
590
591symbolS * last_label_seen;
b34976b6 592static int label_is_thumb_function_name = FALSE;
a737bd4d 593\f
3d0c9500
NC
594/* Literal pool structure. Held on a per-section
595 and per-sub-section basis. */
a737bd4d 596
c19d1205 597#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 598typedef struct literal_pool
b99bd4ef 599{
c19d1205
ZW
600 expressionS literals [MAX_LITERAL_POOL_SIZE];
601 unsigned int next_free_entry;
602 unsigned int id;
603 symbolS * symbol;
604 segT section;
605 subsegT sub_section;
61b5f74b 606 struct literal_pool * next;
3d0c9500 607} literal_pool;
b99bd4ef 608
3d0c9500
NC
609/* Pointer to a linked list of literal pools. */
610literal_pool * list_of_pools = NULL;
e27ec89e
PB
611
612/* State variables for IT block handling. */
613static bfd_boolean current_it_mask = 0;
614static int current_cc;
615
c19d1205
ZW
616\f
617/* Pure syntax. */
b99bd4ef 618
c19d1205
ZW
619/* This array holds the chars that always start a comment. If the
620 pre-processor is disabled, these aren't very useful. */
621const char comment_chars[] = "@";
3d0c9500 622
c19d1205
ZW
623/* This array holds the chars that only start a comment at the beginning of
624 a line. If the line seems to have the form '# 123 filename'
625 .line and .file directives will appear in the pre-processed output. */
626/* Note that input_file.c hand checks for '#' at the beginning of the
627 first line of the input file. This is because the compiler outputs
628 #NO_APP at the beginning of its output. */
629/* Also note that comments like this one will always work. */
630const char line_comment_chars[] = "#";
3d0c9500 631
c19d1205 632const char line_separator_chars[] = ";";
b99bd4ef 633
c19d1205
ZW
634/* Chars that can be used to separate mant
635 from exp in floating point numbers. */
636const char EXP_CHARS[] = "eE";
3d0c9500 637
c19d1205
ZW
638/* Chars that mean this number is a floating point constant. */
639/* As in 0f12.456 */
640/* or 0d1.2345e12 */
b99bd4ef 641
c19d1205 642const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 643
c19d1205
ZW
644/* Prefix characters that indicate the start of an immediate
645 value. */
646#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 647
c19d1205
ZW
648/* Separator character handling. */
649
650#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
651
652static inline int
653skip_past_char (char ** str, char c)
654{
655 if (**str == c)
656 {
657 (*str)++;
658 return SUCCESS;
3d0c9500 659 }
c19d1205
ZW
660 else
661 return FAIL;
662}
663#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 664
c19d1205
ZW
665/* Arithmetic expressions (possibly involving symbols). */
666
667/* Return TRUE if anything in the expression is a bignum. */
668
669static int
670walk_no_bignums (symbolS * sp)
671{
672 if (symbol_get_value_expression (sp)->X_op == O_big)
673 return 1;
674
675 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 676 {
c19d1205
ZW
677 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
678 || (symbol_get_value_expression (sp)->X_op_symbol
679 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
680 }
681
c19d1205 682 return 0;
3d0c9500
NC
683}
684
c19d1205
ZW
685static int in_my_get_expression = 0;
686
687/* Third argument to my_get_expression. */
688#define GE_NO_PREFIX 0
689#define GE_IMM_PREFIX 1
690#define GE_OPT_PREFIX 2
a737bd4d 691
b99bd4ef 692static int
c19d1205 693my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 694{
c19d1205
ZW
695 char * save_in;
696 segT seg;
b99bd4ef 697
c19d1205
ZW
698 /* In unified syntax, all prefixes are optional. */
699 if (unified_syntax)
700 prefix_mode = GE_OPT_PREFIX;
b99bd4ef 701
c19d1205 702 switch (prefix_mode)
b99bd4ef 703 {
c19d1205
ZW
704 case GE_NO_PREFIX: break;
705 case GE_IMM_PREFIX:
706 if (!is_immediate_prefix (**str))
707 {
708 inst.error = _("immediate expression requires a # prefix");
709 return FAIL;
710 }
711 (*str)++;
712 break;
713 case GE_OPT_PREFIX:
714 if (is_immediate_prefix (**str))
715 (*str)++;
716 break;
717 default: abort ();
718 }
b99bd4ef 719
c19d1205 720 memset (ep, 0, sizeof (expressionS));
b99bd4ef 721
c19d1205
ZW
722 save_in = input_line_pointer;
723 input_line_pointer = *str;
724 in_my_get_expression = 1;
725 seg = expression (ep);
726 in_my_get_expression = 0;
727
728 if (ep->X_op == O_illegal)
b99bd4ef 729 {
c19d1205
ZW
730 /* We found a bad expression in md_operand(). */
731 *str = input_line_pointer;
732 input_line_pointer = save_in;
733 if (inst.error == NULL)
734 inst.error = _("bad expression");
735 return 1;
736 }
b99bd4ef 737
c19d1205
ZW
738#ifdef OBJ_AOUT
739 if (seg != absolute_section
740 && seg != text_section
741 && seg != data_section
742 && seg != bss_section
743 && seg != undefined_section)
744 {
745 inst.error = _("bad segment");
746 *str = input_line_pointer;
747 input_line_pointer = save_in;
748 return 1;
b99bd4ef 749 }
c19d1205 750#endif
b99bd4ef 751
c19d1205
ZW
752 /* Get rid of any bignums now, so that we don't generate an error for which
753 we can't establish a line number later on. Big numbers are never valid
754 in instructions, which is where this routine is always called. */
755 if (ep->X_op == O_big
756 || (ep->X_add_symbol
757 && (walk_no_bignums (ep->X_add_symbol)
758 || (ep->X_op_symbol
759 && walk_no_bignums (ep->X_op_symbol)))))
760 {
761 inst.error = _("invalid constant");
762 *str = input_line_pointer;
763 input_line_pointer = save_in;
764 return 1;
765 }
b99bd4ef 766
c19d1205
ZW
767 *str = input_line_pointer;
768 input_line_pointer = save_in;
769 return 0;
b99bd4ef
NC
770}
771
c19d1205
ZW
772/* Turn a string in input_line_pointer into a floating point constant
773 of type TYPE, and store the appropriate bytes in *LITP. The number
774 of LITTLENUMS emitted is stored in *SIZEP. An error message is
775 returned, or NULL on OK.
b99bd4ef 776
c19d1205
ZW
777 Note that fp constants aren't represent in the normal way on the ARM.
778 In big endian mode, things are as expected. However, in little endian
779 mode fp constants are big-endian word-wise, and little-endian byte-wise
780 within the words. For example, (double) 1.1 in big endian mode is
781 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
782 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 783
c19d1205 784 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 785
c19d1205
ZW
786char *
787md_atof (int type, char * litP, int * sizeP)
788{
789 int prec;
790 LITTLENUM_TYPE words[MAX_LITTLENUMS];
791 char *t;
792 int i;
b99bd4ef 793
c19d1205
ZW
794 switch (type)
795 {
796 case 'f':
797 case 'F':
798 case 's':
799 case 'S':
800 prec = 2;
801 break;
b99bd4ef 802
c19d1205
ZW
803 case 'd':
804 case 'D':
805 case 'r':
806 case 'R':
807 prec = 4;
808 break;
b99bd4ef 809
c19d1205
ZW
810 case 'x':
811 case 'X':
812 prec = 6;
813 break;
b99bd4ef 814
c19d1205
ZW
815 case 'p':
816 case 'P':
817 prec = 6;
818 break;
a737bd4d 819
c19d1205
ZW
820 default:
821 *sizeP = 0;
822 return _("bad call to MD_ATOF()");
823 }
b99bd4ef 824
c19d1205
ZW
825 t = atof_ieee (input_line_pointer, type, words);
826 if (t)
827 input_line_pointer = t;
828 *sizeP = prec * 2;
b99bd4ef 829
c19d1205
ZW
830 if (target_big_endian)
831 {
832 for (i = 0; i < prec; i++)
833 {
834 md_number_to_chars (litP, (valueT) words[i], 2);
835 litP += 2;
836 }
837 }
838 else
839 {
e74cfd16 840 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
841 for (i = prec - 1; i >= 0; i--)
842 {
843 md_number_to_chars (litP, (valueT) words[i], 2);
844 litP += 2;
845 }
846 else
847 /* For a 4 byte float the order of elements in `words' is 1 0.
848 For an 8 byte float the order is 1 0 3 2. */
849 for (i = 0; i < prec; i += 2)
850 {
851 md_number_to_chars (litP, (valueT) words[i + 1], 2);
852 md_number_to_chars (litP + 2, (valueT) words[i], 2);
853 litP += 4;
854 }
855 }
b99bd4ef 856
c19d1205
ZW
857 return 0;
858}
b99bd4ef 859
c19d1205
ZW
860/* We handle all bad expressions here, so that we can report the faulty
861 instruction in the error message. */
862void
863md_operand (expressionS * expr)
864{
865 if (in_my_get_expression)
866 expr->X_op = O_illegal;
b99bd4ef
NC
867}
868
c19d1205 869/* Immediate values. */
b99bd4ef 870
c19d1205
ZW
871/* Generic immediate-value read function for use in directives.
872 Accepts anything that 'expression' can fold to a constant.
873 *val receives the number. */
874#ifdef OBJ_ELF
875static int
876immediate_for_directive (int *val)
b99bd4ef 877{
c19d1205
ZW
878 expressionS exp;
879 exp.X_op = O_illegal;
b99bd4ef 880
c19d1205
ZW
881 if (is_immediate_prefix (*input_line_pointer))
882 {
883 input_line_pointer++;
884 expression (&exp);
885 }
b99bd4ef 886
c19d1205
ZW
887 if (exp.X_op != O_constant)
888 {
889 as_bad (_("expected #constant"));
890 ignore_rest_of_line ();
891 return FAIL;
892 }
893 *val = exp.X_add_number;
894 return SUCCESS;
b99bd4ef 895}
c19d1205 896#endif
b99bd4ef 897
c19d1205 898/* Register parsing. */
b99bd4ef 899
c19d1205
ZW
900/* Generic register parser. CCP points to what should be the
901 beginning of a register name. If it is indeed a valid register
902 name, advance CCP over it and return the reg_entry structure;
903 otherwise return NULL. Does not issue diagnostics. */
904
905static struct reg_entry *
906arm_reg_parse_multi (char **ccp)
b99bd4ef 907{
c19d1205
ZW
908 char *start = *ccp;
909 char *p;
910 struct reg_entry *reg;
b99bd4ef 911
c19d1205
ZW
912#ifdef REGISTER_PREFIX
913 if (*start != REGISTER_PREFIX)
01cfc07f 914 return NULL;
c19d1205
ZW
915 start++;
916#endif
917#ifdef OPTIONAL_REGISTER_PREFIX
918 if (*start == OPTIONAL_REGISTER_PREFIX)
919 start++;
920#endif
b99bd4ef 921
c19d1205
ZW
922 p = start;
923 if (!ISALPHA (*p) || !is_name_beginner (*p))
924 return NULL;
b99bd4ef 925
c19d1205
ZW
926 do
927 p++;
928 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
929
930 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
931
932 if (!reg)
933 return NULL;
934
935 *ccp = p;
936 return reg;
b99bd4ef
NC
937}
938
c19d1205 939/* As above, but the register must be of type TYPE, and the return
01cfc07f 940 value is the register number or FAIL. */
c19d1205 941
b99bd4ef 942static int
c19d1205 943arm_reg_parse (char **ccp, enum arm_reg_type type)
b99bd4ef 944{
c19d1205
ZW
945 char *start = *ccp;
946 struct reg_entry *reg = arm_reg_parse_multi (ccp);
b99bd4ef 947
c19d1205
ZW
948 if (reg && reg->type == type)
949 return reg->number;
6057a28f 950
c19d1205
ZW
951 /* Alternative syntaxes are accepted for a few register classes. */
952 switch (type)
953 {
954 case REG_TYPE_MVF:
955 case REG_TYPE_MVD:
956 case REG_TYPE_MVFX:
957 case REG_TYPE_MVDX:
958 /* Generic coprocessor register names are allowed for these. */
79134647 959 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
960 return reg->number;
961 break;
69b97547 962
c19d1205
ZW
963 case REG_TYPE_CP:
964 /* For backward compatibility, a bare number is valid here. */
965 {
966 unsigned long processor = strtoul (start, ccp, 10);
967 if (*ccp != start && processor <= 15)
968 return processor;
969 }
6057a28f 970
c19d1205
ZW
971 case REG_TYPE_MMXWC:
972 /* WC includes WCG. ??? I'm not sure this is true for all
973 instructions that take WC registers. */
79134647 974 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 975 return reg->number;
6057a28f 976 break;
c19d1205 977
6057a28f 978 default:
c19d1205 979 break;
6057a28f
NC
980 }
981
c19d1205
ZW
982 *ccp = start;
983 return FAIL;
984}
69b97547 985
c19d1205
ZW
986/* Parse an ARM register list. Returns the bitmask, or FAIL. */
987static long
988parse_reg_list (char ** strp)
989{
990 char * str = * strp;
991 long range = 0;
992 int another_range;
a737bd4d 993
c19d1205
ZW
994 /* We come back here if we get ranges concatenated by '+' or '|'. */
995 do
6057a28f 996 {
c19d1205 997 another_range = 0;
a737bd4d 998
c19d1205
ZW
999 if (*str == '{')
1000 {
1001 int in_range = 0;
1002 int cur_reg = -1;
a737bd4d 1003
c19d1205
ZW
1004 str++;
1005 do
1006 {
1007 int reg;
6057a28f 1008
c19d1205
ZW
1009 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1010 {
1011 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
1012 return FAIL;
1013 }
a737bd4d 1014
c19d1205
ZW
1015 if (in_range)
1016 {
1017 int i;
a737bd4d 1018
c19d1205
ZW
1019 if (reg <= cur_reg)
1020 {
1021 inst.error = _("bad range in register list");
1022 return FAIL;
1023 }
40a18ebd 1024
c19d1205
ZW
1025 for (i = cur_reg + 1; i < reg; i++)
1026 {
1027 if (range & (1 << i))
1028 as_tsktsk
1029 (_("Warning: duplicated register (r%d) in register list"),
1030 i);
1031 else
1032 range |= 1 << i;
1033 }
1034 in_range = 0;
1035 }
a737bd4d 1036
c19d1205
ZW
1037 if (range & (1 << reg))
1038 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1039 reg);
1040 else if (reg <= cur_reg)
1041 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1042
c19d1205
ZW
1043 range |= 1 << reg;
1044 cur_reg = reg;
1045 }
1046 while (skip_past_comma (&str) != FAIL
1047 || (in_range = 1, *str++ == '-'));
1048 str--;
a737bd4d 1049
c19d1205
ZW
1050 if (*str++ != '}')
1051 {
1052 inst.error = _("missing `}'");
1053 return FAIL;
1054 }
1055 }
1056 else
1057 {
1058 expressionS expr;
40a18ebd 1059
c19d1205
ZW
1060 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1061 return FAIL;
40a18ebd 1062
c19d1205
ZW
1063 if (expr.X_op == O_constant)
1064 {
1065 if (expr.X_add_number
1066 != (expr.X_add_number & 0x0000ffff))
1067 {
1068 inst.error = _("invalid register mask");
1069 return FAIL;
1070 }
a737bd4d 1071
c19d1205
ZW
1072 if ((range & expr.X_add_number) != 0)
1073 {
1074 int regno = range & expr.X_add_number;
a737bd4d 1075
c19d1205
ZW
1076 regno &= -regno;
1077 regno = (1 << regno) - 1;
1078 as_tsktsk
1079 (_("Warning: duplicated register (r%d) in register list"),
1080 regno);
1081 }
a737bd4d 1082
c19d1205
ZW
1083 range |= expr.X_add_number;
1084 }
1085 else
1086 {
1087 if (inst.reloc.type != 0)
1088 {
1089 inst.error = _("expression too complex");
1090 return FAIL;
1091 }
a737bd4d 1092
c19d1205
ZW
1093 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1094 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1095 inst.reloc.pc_rel = 0;
1096 }
1097 }
a737bd4d 1098
c19d1205
ZW
1099 if (*str == '|' || *str == '+')
1100 {
1101 str++;
1102 another_range = 1;
1103 }
a737bd4d 1104 }
c19d1205 1105 while (another_range);
a737bd4d 1106
c19d1205
ZW
1107 *strp = str;
1108 return range;
a737bd4d
NC
1109}
1110
c19d1205
ZW
1111/* Parse a VFP register list. If the string is invalid return FAIL.
1112 Otherwise return the number of registers, and set PBASE to the first
1113 register. Double precision registers are matched if DP is nonzero. */
6057a28f 1114
c19d1205 1115static int
ca3f61f7 1116parse_vfp_reg_list (char **str, unsigned int *pbase, int dp)
6057a28f 1117{
c19d1205
ZW
1118 int base_reg;
1119 int new_base;
1120 int regtype;
1121 int max_regs;
1122 int count = 0;
1123 int warned = 0;
1124 unsigned long mask = 0;
a737bd4d 1125 int i;
6057a28f 1126
c19d1205
ZW
1127 if (**str != '{')
1128 return FAIL;
6057a28f 1129
c19d1205 1130 (*str)++;
6057a28f 1131
c19d1205 1132 if (dp)
a737bd4d 1133 {
c19d1205
ZW
1134 regtype = REG_TYPE_VFD;
1135 max_regs = 16;
1136 }
1137 else
1138 {
1139 regtype = REG_TYPE_VFS;
1140 max_regs = 32;
1141 }
6057a28f 1142
c19d1205 1143 base_reg = max_regs;
a737bd4d 1144
c19d1205
ZW
1145 do
1146 {
1147 new_base = arm_reg_parse (str, regtype);
1148 if (new_base == FAIL)
a737bd4d 1149 {
c19d1205
ZW
1150 inst.error = gettext (reg_expected_msgs[regtype]);
1151 return FAIL;
1152 }
a737bd4d 1153
c19d1205
ZW
1154 if (new_base < base_reg)
1155 base_reg = new_base;
a737bd4d 1156
c19d1205
ZW
1157 if (mask & (1 << new_base))
1158 {
1159 inst.error = _("invalid register list");
1160 return FAIL;
a737bd4d 1161 }
a737bd4d 1162
c19d1205
ZW
1163 if ((mask >> new_base) != 0 && ! warned)
1164 {
1165 as_tsktsk (_("register list not in ascending order"));
1166 warned = 1;
1167 }
0bbf2aa4 1168
c19d1205
ZW
1169 mask |= 1 << new_base;
1170 count++;
0bbf2aa4 1171
c19d1205
ZW
1172 if (**str == '-') /* We have the start of a range expression */
1173 {
1174 int high_range;
0bbf2aa4 1175
c19d1205 1176 (*str)++;
0bbf2aa4 1177
c19d1205
ZW
1178 if ((high_range = arm_reg_parse (str, regtype)) == FAIL)
1179 {
1180 inst.error = gettext (reg_expected_msgs[regtype]);
1181 return FAIL;
1182 }
0bbf2aa4 1183
c19d1205
ZW
1184 if (high_range <= new_base)
1185 {
1186 inst.error = _("register range not in ascending order");
1187 return FAIL;
1188 }
0bbf2aa4 1189
c19d1205 1190 for (new_base++; new_base <= high_range; new_base++)
0bbf2aa4 1191 {
c19d1205 1192 if (mask & (1 << new_base))
0bbf2aa4 1193 {
c19d1205
ZW
1194 inst.error = _("invalid register list");
1195 return FAIL;
0bbf2aa4 1196 }
c19d1205
ZW
1197
1198 mask |= 1 << new_base;
1199 count++;
0bbf2aa4 1200 }
0bbf2aa4 1201 }
0bbf2aa4 1202 }
c19d1205 1203 while (skip_past_comma (str) != FAIL);
0bbf2aa4 1204
c19d1205 1205 (*str)++;
0bbf2aa4 1206
c19d1205
ZW
1207 /* Sanity check -- should have raised a parse error above. */
1208 if (count == 0 || count > max_regs)
1209 abort ();
1210
1211 *pbase = base_reg;
1212
1213 /* Final test -- the registers must be consecutive. */
1214 mask >>= base_reg;
1215 for (i = 0; i < count; i++)
1216 {
1217 if ((mask & (1u << i)) == 0)
1218 {
1219 inst.error = _("non-contiguous register range");
1220 return FAIL;
1221 }
1222 }
1223
1224 return count;
b99bd4ef
NC
1225}
1226
c19d1205
ZW
1227/* Parse an explicit relocation suffix on an expression. This is
1228 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1229 arm_reloc_hsh contains no entries, so this function can only
1230 succeed if there is no () after the word. Returns -1 on error,
1231 BFD_RELOC_UNUSED if there wasn't any suffix. */
1232static int
1233parse_reloc (char **str)
b99bd4ef 1234{
c19d1205
ZW
1235 struct reloc_entry *r;
1236 char *p, *q;
b99bd4ef 1237
c19d1205
ZW
1238 if (**str != '(')
1239 return BFD_RELOC_UNUSED;
b99bd4ef 1240
c19d1205
ZW
1241 p = *str + 1;
1242 q = p;
1243
1244 while (*q && *q != ')' && *q != ',')
1245 q++;
1246 if (*q != ')')
1247 return -1;
1248
1249 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1250 return -1;
1251
1252 *str = q + 1;
1253 return r->reloc;
b99bd4ef
NC
1254}
1255
c19d1205
ZW
1256/* Directives: register aliases. */
1257
b99bd4ef 1258static void
c19d1205 1259insert_reg_alias (char *str, int number, int type)
b99bd4ef 1260{
c19d1205
ZW
1261 struct reg_entry *new;
1262 const char *name;
b99bd4ef 1263
c19d1205
ZW
1264 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1265 {
1266 if (new->builtin)
1267 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1268
c19d1205
ZW
1269 /* Only warn about a redefinition if it's not defined as the
1270 same register. */
1271 else if (new->number != number || new->type != type)
1272 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1273
c19d1205
ZW
1274 return;
1275 }
b99bd4ef 1276
c19d1205
ZW
1277 name = xstrdup (str);
1278 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1279
c19d1205
ZW
1280 new->name = name;
1281 new->number = number;
1282 new->type = type;
1283 new->builtin = FALSE;
b99bd4ef 1284
c19d1205
ZW
1285 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1286 abort ();
1287}
b99bd4ef 1288
c19d1205 1289/* Look for the .req directive. This is of the form:
b99bd4ef 1290
c19d1205 1291 new_register_name .req existing_register_name
b99bd4ef 1292
c19d1205
ZW
1293 If we find one, or if it looks sufficiently like one that we want to
1294 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 1295
c19d1205
ZW
1296static int
1297create_register_alias (char * newname, char *p)
1298{
1299 struct reg_entry *old;
1300 char *oldname, *nbuf;
1301 size_t nlen;
b99bd4ef 1302
c19d1205
ZW
1303 /* The input scrubber ensures that whitespace after the mnemonic is
1304 collapsed to single spaces. */
1305 oldname = p;
1306 if (strncmp (oldname, " .req ", 6) != 0)
1307 return 0;
b99bd4ef 1308
c19d1205
ZW
1309 oldname += 6;
1310 if (*oldname == '\0')
1311 return 0;
b99bd4ef 1312
c19d1205
ZW
1313 old = hash_find (arm_reg_hsh, oldname);
1314 if (!old)
b99bd4ef 1315 {
c19d1205
ZW
1316 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
1317 return 1;
b99bd4ef
NC
1318 }
1319
c19d1205
ZW
1320 /* If TC_CASE_SENSITIVE is defined, then newname already points to
1321 the desired alias name, and p points to its end. If not, then
1322 the desired alias name is in the global original_case_string. */
1323#ifdef TC_CASE_SENSITIVE
1324 nlen = p - newname;
1325#else
1326 newname = original_case_string;
1327 nlen = strlen (newname);
1328#endif
b99bd4ef 1329
c19d1205
ZW
1330 nbuf = alloca (nlen + 1);
1331 memcpy (nbuf, newname, nlen);
1332 nbuf[nlen] = '\0';
b99bd4ef 1333
c19d1205
ZW
1334 /* Create aliases under the new name as stated; an all-lowercase
1335 version of the new name; and an all-uppercase version of the new
1336 name. */
1337 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 1338
c19d1205
ZW
1339 for (p = nbuf; *p; p++)
1340 *p = TOUPPER (*p);
1341
1342 if (strncmp (nbuf, newname, nlen))
1343 insert_reg_alias (nbuf, old->number, old->type);
1344
1345 for (p = nbuf; *p; p++)
1346 *p = TOLOWER (*p);
1347
1348 if (strncmp (nbuf, newname, nlen))
1349 insert_reg_alias (nbuf, old->number, old->type);
1350
1351 return 1;
b99bd4ef
NC
1352}
1353
c19d1205
ZW
1354/* Should never be called, as .req goes between the alias and the
1355 register name, not at the beginning of the line. */
b99bd4ef 1356static void
c19d1205 1357s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 1358{
c19d1205
ZW
1359 as_bad (_("invalid syntax for .req directive"));
1360}
b99bd4ef 1361
c19d1205
ZW
1362/* The .unreq directive deletes an alias which was previously defined
1363 by .req. For example:
b99bd4ef 1364
c19d1205
ZW
1365 my_alias .req r11
1366 .unreq my_alias */
b99bd4ef
NC
1367
1368static void
c19d1205 1369s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 1370{
c19d1205
ZW
1371 char * name;
1372 char saved_char;
b99bd4ef 1373
c19d1205
ZW
1374 name = input_line_pointer;
1375
1376 while (*input_line_pointer != 0
1377 && *input_line_pointer != ' '
1378 && *input_line_pointer != '\n')
1379 ++input_line_pointer;
1380
1381 saved_char = *input_line_pointer;
1382 *input_line_pointer = 0;
1383
1384 if (!*name)
1385 as_bad (_("invalid syntax for .unreq directive"));
1386 else
1387 {
1388 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
1389
1390 if (!reg)
1391 as_bad (_("unknown register alias '%s'"), name);
1392 else if (reg->builtin)
1393 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
1394 name);
1395 else
1396 {
1397 hash_delete (arm_reg_hsh, name);
1398 free ((char *) reg->name);
1399 free (reg);
1400 }
1401 }
b99bd4ef 1402
c19d1205 1403 *input_line_pointer = saved_char;
b99bd4ef
NC
1404 demand_empty_rest_of_line ();
1405}
1406
c19d1205
ZW
1407/* Directives: Instruction set selection. */
1408
1409#ifdef OBJ_ELF
1410/* This code is to handle mapping symbols as defined in the ARM ELF spec.
1411 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
1412 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
1413 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
1414
1415static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef
NC
1416
1417static void
c19d1205 1418mapping_state (enum mstate state)
b99bd4ef 1419{
a737bd4d 1420 symbolS * symbolP;
c19d1205
ZW
1421 const char * symname;
1422 int type;
b99bd4ef 1423
c19d1205
ZW
1424 if (mapstate == state)
1425 /* The mapping symbol has already been emitted.
1426 There is nothing else to do. */
1427 return;
b99bd4ef 1428
c19d1205 1429 mapstate = state;
b99bd4ef 1430
c19d1205 1431 switch (state)
b99bd4ef 1432 {
c19d1205
ZW
1433 case MAP_DATA:
1434 symname = "$d";
1435 type = BSF_NO_FLAGS;
1436 break;
1437 case MAP_ARM:
1438 symname = "$a";
1439 type = BSF_NO_FLAGS;
1440 break;
1441 case MAP_THUMB:
1442 symname = "$t";
1443 type = BSF_NO_FLAGS;
1444 break;
1445 case MAP_UNDEFINED:
1446 return;
1447 default:
1448 abort ();
1449 }
1450
1451 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
1452
1453 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
1454 symbol_table_insert (symbolP);
1455 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
1456
1457 switch (state)
1458 {
1459 case MAP_ARM:
1460 THUMB_SET_FUNC (symbolP, 0);
1461 ARM_SET_THUMB (symbolP, 0);
1462 ARM_SET_INTERWORK (symbolP, support_interwork);
1463 break;
1464
1465 case MAP_THUMB:
1466 THUMB_SET_FUNC (symbolP, 1);
1467 ARM_SET_THUMB (symbolP, 1);
1468 ARM_SET_INTERWORK (symbolP, support_interwork);
1469 break;
1470
1471 case MAP_DATA:
1472 default:
1473 return;
1474 }
1475}
1476#else
1477#define mapping_state(x) /* nothing */
1478#endif
1479
1480/* Find the real, Thumb encoded start of a Thumb function. */
1481
1482static symbolS *
1483find_real_start (symbolS * symbolP)
1484{
1485 char * real_start;
1486 const char * name = S_GET_NAME (symbolP);
1487 symbolS * new_target;
1488
1489 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
1490#define STUB_NAME ".real_start_of"
1491
1492 if (name == NULL)
1493 abort ();
1494
37f6032b
ZW
1495 /* The compiler may generate BL instructions to local labels because
1496 it needs to perform a branch to a far away location. These labels
1497 do not have a corresponding ".real_start_of" label. We check
1498 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
1499 the ".real_start_of" convention for nonlocal branches. */
1500 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
1501 return symbolP;
1502
37f6032b 1503 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
1504 new_target = symbol_find (real_start);
1505
1506 if (new_target == NULL)
1507 {
1508 as_warn ("Failed to find real start of function: %s\n", name);
1509 new_target = symbolP;
1510 }
1511
c19d1205
ZW
1512 return new_target;
1513}
1514
1515static void
1516opcode_select (int width)
1517{
1518 switch (width)
1519 {
1520 case 16:
1521 if (! thumb_mode)
1522 {
e74cfd16 1523 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
1524 as_bad (_("selected processor does not support THUMB opcodes"));
1525
1526 thumb_mode = 1;
1527 /* No need to force the alignment, since we will have been
1528 coming from ARM mode, which is word-aligned. */
1529 record_alignment (now_seg, 1);
1530 }
1531 mapping_state (MAP_THUMB);
1532 break;
1533
1534 case 32:
1535 if (thumb_mode)
1536 {
e74cfd16 1537 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
1538 as_bad (_("selected processor does not support ARM opcodes"));
1539
1540 thumb_mode = 0;
1541
1542 if (!need_pass_2)
1543 frag_align (2, 0, 0);
1544
1545 record_alignment (now_seg, 1);
1546 }
1547 mapping_state (MAP_ARM);
1548 break;
1549
1550 default:
1551 as_bad (_("invalid instruction size selected (%d)"), width);
1552 }
1553}
1554
1555static void
1556s_arm (int ignore ATTRIBUTE_UNUSED)
1557{
1558 opcode_select (32);
1559 demand_empty_rest_of_line ();
1560}
1561
1562static void
1563s_thumb (int ignore ATTRIBUTE_UNUSED)
1564{
1565 opcode_select (16);
1566 demand_empty_rest_of_line ();
1567}
1568
1569static void
1570s_code (int unused ATTRIBUTE_UNUSED)
1571{
1572 int temp;
1573
1574 temp = get_absolute_expression ();
1575 switch (temp)
1576 {
1577 case 16:
1578 case 32:
1579 opcode_select (temp);
1580 break;
1581
1582 default:
1583 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
1584 }
1585}
1586
1587static void
1588s_force_thumb (int ignore ATTRIBUTE_UNUSED)
1589{
1590 /* If we are not already in thumb mode go into it, EVEN if
1591 the target processor does not support thumb instructions.
1592 This is used by gcc/config/arm/lib1funcs.asm for example
1593 to compile interworking support functions even if the
1594 target processor should not support interworking. */
1595 if (! thumb_mode)
1596 {
1597 thumb_mode = 2;
1598 record_alignment (now_seg, 1);
1599 }
1600
1601 demand_empty_rest_of_line ();
1602}
1603
1604static void
1605s_thumb_func (int ignore ATTRIBUTE_UNUSED)
1606{
1607 s_thumb (0);
1608
1609 /* The following label is the name/address of the start of a Thumb function.
1610 We need to know this for the interworking support. */
1611 label_is_thumb_function_name = TRUE;
1612}
1613
1614/* Perform a .set directive, but also mark the alias as
1615 being a thumb function. */
1616
1617static void
1618s_thumb_set (int equiv)
1619{
1620 /* XXX the following is a duplicate of the code for s_set() in read.c
1621 We cannot just call that code as we need to get at the symbol that
1622 is created. */
1623 char * name;
1624 char delim;
1625 char * end_name;
1626 symbolS * symbolP;
1627
1628 /* Especial apologies for the random logic:
1629 This just grew, and could be parsed much more simply!
1630 Dean - in haste. */
1631 name = input_line_pointer;
1632 delim = get_symbol_end ();
1633 end_name = input_line_pointer;
1634 *end_name = delim;
1635
1636 if (*input_line_pointer != ',')
1637 {
1638 *end_name = 0;
1639 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
1640 *end_name = delim;
1641 ignore_rest_of_line ();
1642 return;
1643 }
1644
1645 input_line_pointer++;
1646 *end_name = 0;
1647
1648 if (name[0] == '.' && name[1] == '\0')
1649 {
1650 /* XXX - this should not happen to .thumb_set. */
1651 abort ();
1652 }
1653
1654 if ((symbolP = symbol_find (name)) == NULL
1655 && (symbolP = md_undefined_symbol (name)) == NULL)
1656 {
1657#ifndef NO_LISTING
1658 /* When doing symbol listings, play games with dummy fragments living
1659 outside the normal fragment chain to record the file and line info
c19d1205 1660 for this symbol. */
b99bd4ef
NC
1661 if (listing & LISTING_SYMBOLS)
1662 {
1663 extern struct list_info_struct * listing_tail;
a737bd4d 1664 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
1665
1666 memset (dummy_frag, 0, sizeof (fragS));
1667 dummy_frag->fr_type = rs_fill;
1668 dummy_frag->line = listing_tail;
1669 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
1670 dummy_frag->fr_symbol = symbolP;
1671 }
1672 else
1673#endif
1674 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1675
1676#ifdef OBJ_COFF
1677 /* "set" symbols are local unless otherwise specified. */
1678 SF_SET_LOCAL (symbolP);
1679#endif /* OBJ_COFF */
1680 } /* Make a new symbol. */
1681
1682 symbol_table_insert (symbolP);
1683
1684 * end_name = delim;
1685
1686 if (equiv
1687 && S_IS_DEFINED (symbolP)
1688 && S_GET_SEGMENT (symbolP) != reg_section)
1689 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
1690
1691 pseudo_set (symbolP);
1692
1693 demand_empty_rest_of_line ();
1694
c19d1205 1695 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
1696
1697 THUMB_SET_FUNC (symbolP, 1);
1698 ARM_SET_THUMB (symbolP, 1);
1699#if defined OBJ_ELF || defined OBJ_COFF
1700 ARM_SET_INTERWORK (symbolP, support_interwork);
1701#endif
1702}
1703
c19d1205 1704/* Directives: Mode selection. */
b99bd4ef 1705
c19d1205
ZW
1706/* .syntax [unified|divided] - choose the new unified syntax
1707 (same for Arm and Thumb encoding, modulo slight differences in what
1708 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 1709static void
c19d1205 1710s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1711{
c19d1205
ZW
1712 char *name, delim;
1713
1714 name = input_line_pointer;
1715 delim = get_symbol_end ();
1716
1717 if (!strcasecmp (name, "unified"))
1718 unified_syntax = TRUE;
1719 else if (!strcasecmp (name, "divided"))
1720 unified_syntax = FALSE;
1721 else
1722 {
1723 as_bad (_("unrecognized syntax mode \"%s\""), name);
1724 return;
1725 }
1726 *input_line_pointer = delim;
b99bd4ef
NC
1727 demand_empty_rest_of_line ();
1728}
1729
c19d1205
ZW
1730/* Directives: sectioning and alignment. */
1731
1732/* Same as s_align_ptwo but align 0 => align 2. */
1733
b99bd4ef 1734static void
c19d1205 1735s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 1736{
a737bd4d 1737 int temp;
c19d1205
ZW
1738 long temp_fill;
1739 long max_alignment = 15;
b99bd4ef
NC
1740
1741 temp = get_absolute_expression ();
c19d1205
ZW
1742 if (temp > max_alignment)
1743 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
1744 else if (temp < 0)
b99bd4ef 1745 {
c19d1205
ZW
1746 as_bad (_("alignment negative. 0 assumed."));
1747 temp = 0;
1748 }
b99bd4ef 1749
c19d1205
ZW
1750 if (*input_line_pointer == ',')
1751 {
1752 input_line_pointer++;
1753 temp_fill = get_absolute_expression ();
b99bd4ef 1754 }
c19d1205
ZW
1755 else
1756 temp_fill = 0;
b99bd4ef 1757
c19d1205
ZW
1758 if (!temp)
1759 temp = 2;
b99bd4ef 1760
c19d1205
ZW
1761 /* Only make a frag if we HAVE to. */
1762 if (temp && !need_pass_2)
1763 frag_align (temp, (int) temp_fill, 0);
1764 demand_empty_rest_of_line ();
1765
1766 record_alignment (now_seg, temp);
b99bd4ef
NC
1767}
1768
c19d1205
ZW
1769static void
1770s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 1771{
c19d1205
ZW
1772 /* We don't support putting frags in the BSS segment, we fake it by
1773 marking in_bss, then looking at s_skip for clues. */
1774 subseg_set (bss_section, 0);
1775 demand_empty_rest_of_line ();
1776 mapping_state (MAP_DATA);
1777}
b99bd4ef 1778
c19d1205
ZW
1779static void
1780s_even (int ignore ATTRIBUTE_UNUSED)
1781{
1782 /* Never make frag if expect extra pass. */
1783 if (!need_pass_2)
1784 frag_align (1, 0, 0);
b99bd4ef 1785
c19d1205 1786 record_alignment (now_seg, 1);
b99bd4ef 1787
c19d1205 1788 demand_empty_rest_of_line ();
b99bd4ef
NC
1789}
1790
c19d1205 1791/* Directives: Literal pools. */
a737bd4d 1792
c19d1205
ZW
1793static literal_pool *
1794find_literal_pool (void)
a737bd4d 1795{
c19d1205 1796 literal_pool * pool;
a737bd4d 1797
c19d1205 1798 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 1799 {
c19d1205
ZW
1800 if (pool->section == now_seg
1801 && pool->sub_section == now_subseg)
1802 break;
a737bd4d
NC
1803 }
1804
c19d1205 1805 return pool;
a737bd4d
NC
1806}
1807
c19d1205
ZW
1808static literal_pool *
1809find_or_make_literal_pool (void)
a737bd4d 1810{
c19d1205
ZW
1811 /* Next literal pool ID number. */
1812 static unsigned int latest_pool_num = 1;
1813 literal_pool * pool;
a737bd4d 1814
c19d1205 1815 pool = find_literal_pool ();
a737bd4d 1816
c19d1205 1817 if (pool == NULL)
a737bd4d 1818 {
c19d1205
ZW
1819 /* Create a new pool. */
1820 pool = xmalloc (sizeof (* pool));
1821 if (! pool)
1822 return NULL;
a737bd4d 1823
c19d1205
ZW
1824 pool->next_free_entry = 0;
1825 pool->section = now_seg;
1826 pool->sub_section = now_subseg;
1827 pool->next = list_of_pools;
1828 pool->symbol = NULL;
1829
1830 /* Add it to the list. */
1831 list_of_pools = pool;
a737bd4d 1832 }
a737bd4d 1833
c19d1205
ZW
1834 /* New pools, and emptied pools, will have a NULL symbol. */
1835 if (pool->symbol == NULL)
a737bd4d 1836 {
c19d1205
ZW
1837 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
1838 (valueT) 0, &zero_address_frag);
1839 pool->id = latest_pool_num ++;
a737bd4d
NC
1840 }
1841
c19d1205
ZW
1842 /* Done. */
1843 return pool;
a737bd4d
NC
1844}
1845
c19d1205
ZW
1846/* Add the literal in the global 'inst'
1847 structure to the relevent literal pool. */
b99bd4ef
NC
1848
1849static int
c19d1205 1850add_to_lit_pool (void)
b99bd4ef 1851{
c19d1205
ZW
1852 literal_pool * pool;
1853 unsigned int entry;
b99bd4ef 1854
c19d1205
ZW
1855 pool = find_or_make_literal_pool ();
1856
1857 /* Check if this literal value is already in the pool. */
1858 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 1859 {
c19d1205
ZW
1860 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1861 && (inst.reloc.exp.X_op == O_constant)
1862 && (pool->literals[entry].X_add_number
1863 == inst.reloc.exp.X_add_number)
1864 && (pool->literals[entry].X_unsigned
1865 == inst.reloc.exp.X_unsigned))
1866 break;
1867
1868 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
1869 && (inst.reloc.exp.X_op == O_symbol)
1870 && (pool->literals[entry].X_add_number
1871 == inst.reloc.exp.X_add_number)
1872 && (pool->literals[entry].X_add_symbol
1873 == inst.reloc.exp.X_add_symbol)
1874 && (pool->literals[entry].X_op_symbol
1875 == inst.reloc.exp.X_op_symbol))
1876 break;
b99bd4ef
NC
1877 }
1878
c19d1205
ZW
1879 /* Do we need to create a new entry? */
1880 if (entry == pool->next_free_entry)
1881 {
1882 if (entry >= MAX_LITERAL_POOL_SIZE)
1883 {
1884 inst.error = _("literal pool overflow");
1885 return FAIL;
1886 }
1887
1888 pool->literals[entry] = inst.reloc.exp;
1889 pool->next_free_entry += 1;
1890 }
b99bd4ef 1891
c19d1205
ZW
1892 inst.reloc.exp.X_op = O_symbol;
1893 inst.reloc.exp.X_add_number = ((int) entry) * 4;
1894 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 1895
c19d1205 1896 return SUCCESS;
b99bd4ef
NC
1897}
1898
c19d1205
ZW
1899/* Can't use symbol_new here, so have to create a symbol and then at
1900 a later date assign it a value. Thats what these functions do. */
e16bb312 1901
c19d1205
ZW
1902static void
1903symbol_locate (symbolS * symbolP,
1904 const char * name, /* It is copied, the caller can modify. */
1905 segT segment, /* Segment identifier (SEG_<something>). */
1906 valueT valu, /* Symbol value. */
1907 fragS * frag) /* Associated fragment. */
1908{
1909 unsigned int name_length;
1910 char * preserved_copy_of_name;
e16bb312 1911
c19d1205
ZW
1912 name_length = strlen (name) + 1; /* +1 for \0. */
1913 obstack_grow (&notes, name, name_length);
1914 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 1915
c19d1205
ZW
1916#ifdef tc_canonicalize_symbol_name
1917 preserved_copy_of_name =
1918 tc_canonicalize_symbol_name (preserved_copy_of_name);
1919#endif
b99bd4ef 1920
c19d1205 1921 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 1922
c19d1205
ZW
1923 S_SET_SEGMENT (symbolP, segment);
1924 S_SET_VALUE (symbolP, valu);
1925 symbol_clear_list_pointers (symbolP);
b99bd4ef 1926
c19d1205 1927 symbol_set_frag (symbolP, frag);
b99bd4ef 1928
c19d1205
ZW
1929 /* Link to end of symbol chain. */
1930 {
1931 extern int symbol_table_frozen;
b99bd4ef 1932
c19d1205
ZW
1933 if (symbol_table_frozen)
1934 abort ();
1935 }
b99bd4ef 1936
c19d1205 1937 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 1938
c19d1205 1939 obj_symbol_new_hook (symbolP);
b99bd4ef 1940
c19d1205
ZW
1941#ifdef tc_symbol_new_hook
1942 tc_symbol_new_hook (symbolP);
1943#endif
1944
1945#ifdef DEBUG_SYMS
1946 verify_symbol_chain (symbol_rootP, symbol_lastP);
1947#endif /* DEBUG_SYMS */
b99bd4ef
NC
1948}
1949
b99bd4ef 1950
c19d1205
ZW
1951static void
1952s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 1953{
c19d1205
ZW
1954 unsigned int entry;
1955 literal_pool * pool;
1956 char sym_name[20];
b99bd4ef 1957
c19d1205
ZW
1958 pool = find_literal_pool ();
1959 if (pool == NULL
1960 || pool->symbol == NULL
1961 || pool->next_free_entry == 0)
1962 return;
b99bd4ef 1963
c19d1205 1964 mapping_state (MAP_DATA);
b99bd4ef 1965
c19d1205
ZW
1966 /* Align pool as you have word accesses.
1967 Only make a frag if we have to. */
1968 if (!need_pass_2)
1969 frag_align (2, 0, 0);
b99bd4ef 1970
c19d1205 1971 record_alignment (now_seg, 2);
b99bd4ef 1972
c19d1205 1973 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 1974
c19d1205
ZW
1975 symbol_locate (pool->symbol, sym_name, now_seg,
1976 (valueT) frag_now_fix (), frag_now);
1977 symbol_table_insert (pool->symbol);
b99bd4ef 1978
c19d1205 1979 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 1980
c19d1205
ZW
1981#if defined OBJ_COFF || defined OBJ_ELF
1982 ARM_SET_INTERWORK (pool->symbol, support_interwork);
1983#endif
6c43fab6 1984
c19d1205
ZW
1985 for (entry = 0; entry < pool->next_free_entry; entry ++)
1986 /* First output the expression in the instruction to the pool. */
1987 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 1988
c19d1205
ZW
1989 /* Mark the pool as empty. */
1990 pool->next_free_entry = 0;
1991 pool->symbol = NULL;
b99bd4ef
NC
1992}
1993
c19d1205
ZW
1994#ifdef OBJ_ELF
1995/* Forward declarations for functions below, in the MD interface
1996 section. */
1997static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
1998static valueT create_unwind_entry (int);
1999static void start_unwind_section (const segT, int);
2000static void add_unwind_opcode (valueT, int);
2001static void flush_pending_unwind (void);
b99bd4ef 2002
c19d1205 2003/* Directives: Data. */
b99bd4ef 2004
c19d1205
ZW
2005static void
2006s_arm_elf_cons (int nbytes)
2007{
2008 expressionS exp;
b99bd4ef 2009
c19d1205
ZW
2010#ifdef md_flush_pending_output
2011 md_flush_pending_output ();
2012#endif
b99bd4ef 2013
c19d1205 2014 if (is_it_end_of_statement ())
b99bd4ef 2015 {
c19d1205
ZW
2016 demand_empty_rest_of_line ();
2017 return;
b99bd4ef
NC
2018 }
2019
c19d1205
ZW
2020#ifdef md_cons_align
2021 md_cons_align (nbytes);
2022#endif
b99bd4ef 2023
c19d1205
ZW
2024 mapping_state (MAP_DATA);
2025 do
b99bd4ef 2026 {
c19d1205
ZW
2027 int reloc;
2028 char *base = input_line_pointer;
b99bd4ef 2029
c19d1205 2030 expression (& exp);
b99bd4ef 2031
c19d1205
ZW
2032 if (exp.X_op != O_symbol)
2033 emit_expr (&exp, (unsigned int) nbytes);
2034 else
2035 {
2036 char *before_reloc = input_line_pointer;
2037 reloc = parse_reloc (&input_line_pointer);
2038 if (reloc == -1)
2039 {
2040 as_bad (_("unrecognized relocation suffix"));
2041 ignore_rest_of_line ();
2042 return;
2043 }
2044 else if (reloc == BFD_RELOC_UNUSED)
2045 emit_expr (&exp, (unsigned int) nbytes);
2046 else
2047 {
2048 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2049 int size = bfd_get_reloc_size (howto);
b99bd4ef 2050
2fc8bdac
ZW
2051 if (reloc == BFD_RELOC_ARM_PLT32)
2052 {
2053 as_bad (_("(plt) is only valid on branch targets"));
2054 reloc = BFD_RELOC_UNUSED;
2055 size = 0;
2056 }
2057
c19d1205 2058 if (size > nbytes)
2fc8bdac 2059 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2060 howto->name, nbytes);
2061 else
2062 {
2063 /* We've parsed an expression stopping at O_symbol.
2064 But there may be more expression left now that we
2065 have parsed the relocation marker. Parse it again.
2066 XXX Surely there is a cleaner way to do this. */
2067 char *p = input_line_pointer;
2068 int offset;
2069 char *save_buf = alloca (input_line_pointer - base);
2070 memcpy (save_buf, base, input_line_pointer - base);
2071 memmove (base + (input_line_pointer - before_reloc),
2072 base, before_reloc - base);
2073
2074 input_line_pointer = base + (input_line_pointer-before_reloc);
2075 expression (&exp);
2076 memcpy (base, save_buf, p - base);
2077
2078 offset = nbytes - size;
2079 p = frag_more ((int) nbytes);
2080 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2081 size, &exp, 0, reloc);
2082 }
2083 }
2084 }
b99bd4ef 2085 }
c19d1205 2086 while (*input_line_pointer++ == ',');
b99bd4ef 2087
c19d1205
ZW
2088 /* Put terminator back into stream. */
2089 input_line_pointer --;
2090 demand_empty_rest_of_line ();
b99bd4ef
NC
2091}
2092
b99bd4ef 2093
c19d1205 2094/* Parse a .rel31 directive. */
b99bd4ef 2095
c19d1205
ZW
2096static void
2097s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2098{
2099 expressionS exp;
2100 char *p;
2101 valueT highbit;
b99bd4ef 2102
c19d1205
ZW
2103 highbit = 0;
2104 if (*input_line_pointer == '1')
2105 highbit = 0x80000000;
2106 else if (*input_line_pointer != '0')
2107 as_bad (_("expected 0 or 1"));
b99bd4ef 2108
c19d1205
ZW
2109 input_line_pointer++;
2110 if (*input_line_pointer != ',')
2111 as_bad (_("missing comma"));
2112 input_line_pointer++;
b99bd4ef 2113
c19d1205
ZW
2114#ifdef md_flush_pending_output
2115 md_flush_pending_output ();
2116#endif
b99bd4ef 2117
c19d1205
ZW
2118#ifdef md_cons_align
2119 md_cons_align (4);
2120#endif
b99bd4ef 2121
c19d1205 2122 mapping_state (MAP_DATA);
b99bd4ef 2123
c19d1205 2124 expression (&exp);
b99bd4ef 2125
c19d1205
ZW
2126 p = frag_more (4);
2127 md_number_to_chars (p, highbit, 4);
2128 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2129 BFD_RELOC_ARM_PREL31);
b99bd4ef 2130
c19d1205 2131 demand_empty_rest_of_line ();
b99bd4ef
NC
2132}
2133
c19d1205 2134/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2135
c19d1205 2136/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 2137
c19d1205
ZW
2138static void
2139s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
2140{
2141 demand_empty_rest_of_line ();
2142 /* Mark the start of the function. */
2143 unwind.proc_start = expr_build_dot ();
b99bd4ef 2144
c19d1205
ZW
2145 /* Reset the rest of the unwind info. */
2146 unwind.opcode_count = 0;
2147 unwind.table_entry = NULL;
2148 unwind.personality_routine = NULL;
2149 unwind.personality_index = -1;
2150 unwind.frame_size = 0;
2151 unwind.fp_offset = 0;
2152 unwind.fp_reg = 13;
2153 unwind.fp_used = 0;
2154 unwind.sp_restored = 0;
2155}
b99bd4ef 2156
b99bd4ef 2157
c19d1205
ZW
2158/* Parse a handlerdata directive. Creates the exception handling table entry
2159 for the function. */
b99bd4ef 2160
c19d1205
ZW
2161static void
2162s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
2163{
2164 demand_empty_rest_of_line ();
2165 if (unwind.table_entry)
2166 as_bad (_("dupicate .handlerdata directive"));
f02232aa 2167
c19d1205
ZW
2168 create_unwind_entry (1);
2169}
a737bd4d 2170
c19d1205 2171/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 2172
c19d1205
ZW
2173static void
2174s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
2175{
2176 long where;
2177 char *ptr;
2178 valueT val;
f02232aa 2179
c19d1205 2180 demand_empty_rest_of_line ();
f02232aa 2181
c19d1205
ZW
2182 /* Add eh table entry. */
2183 if (unwind.table_entry == NULL)
2184 val = create_unwind_entry (0);
2185 else
2186 val = 0;
f02232aa 2187
c19d1205
ZW
2188 /* Add index table entry. This is two words. */
2189 start_unwind_section (unwind.saved_seg, 1);
2190 frag_align (2, 0, 0);
2191 record_alignment (now_seg, 2);
b99bd4ef 2192
c19d1205
ZW
2193 ptr = frag_more (8);
2194 where = frag_now_fix () - 8;
f02232aa 2195
c19d1205
ZW
2196 /* Self relative offset of the function start. */
2197 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
2198 BFD_RELOC_ARM_PREL31);
f02232aa 2199
c19d1205
ZW
2200 /* Indicate dependency on EHABI-defined personality routines to the
2201 linker, if it hasn't been done already. */
2202 if (unwind.personality_index >= 0 && unwind.personality_index < 3
2203 && !(marked_pr_dependency & (1 << unwind.personality_index)))
2204 {
2205 static const char *const name[] = {
2206 "__aeabi_unwind_cpp_pr0",
2207 "__aeabi_unwind_cpp_pr1",
2208 "__aeabi_unwind_cpp_pr2"
2209 };
2210 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
2211 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
2212 marked_pr_dependency |= 1 << unwind.personality_index;
2213 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
2214 = marked_pr_dependency;
2215 }
f02232aa 2216
c19d1205
ZW
2217 if (val)
2218 /* Inline exception table entry. */
2219 md_number_to_chars (ptr + 4, val, 4);
2220 else
2221 /* Self relative offset of the table entry. */
2222 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
2223 BFD_RELOC_ARM_PREL31);
f02232aa 2224
c19d1205
ZW
2225 /* Restore the original section. */
2226 subseg_set (unwind.saved_seg, unwind.saved_subseg);
2227}
f02232aa 2228
f02232aa 2229
c19d1205 2230/* Parse an unwind_cantunwind directive. */
b99bd4ef 2231
c19d1205
ZW
2232static void
2233s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
2234{
2235 demand_empty_rest_of_line ();
2236 if (unwind.personality_routine || unwind.personality_index != -1)
2237 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 2238
c19d1205
ZW
2239 unwind.personality_index = -2;
2240}
b99bd4ef 2241
b99bd4ef 2242
c19d1205 2243/* Parse a personalityindex directive. */
b99bd4ef 2244
c19d1205
ZW
2245static void
2246s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
2247{
2248 expressionS exp;
b99bd4ef 2249
c19d1205
ZW
2250 if (unwind.personality_routine || unwind.personality_index != -1)
2251 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 2252
c19d1205 2253 expression (&exp);
b99bd4ef 2254
c19d1205
ZW
2255 if (exp.X_op != O_constant
2256 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 2257 {
c19d1205
ZW
2258 as_bad (_("bad personality routine number"));
2259 ignore_rest_of_line ();
2260 return;
b99bd4ef
NC
2261 }
2262
c19d1205 2263 unwind.personality_index = exp.X_add_number;
b99bd4ef 2264
c19d1205
ZW
2265 demand_empty_rest_of_line ();
2266}
e16bb312 2267
e16bb312 2268
c19d1205 2269/* Parse a personality directive. */
e16bb312 2270
c19d1205
ZW
2271static void
2272s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
2273{
2274 char *name, *p, c;
a737bd4d 2275
c19d1205
ZW
2276 if (unwind.personality_routine || unwind.personality_index != -1)
2277 as_bad (_("duplicate .personality directive"));
a737bd4d 2278
c19d1205
ZW
2279 name = input_line_pointer;
2280 c = get_symbol_end ();
2281 p = input_line_pointer;
2282 unwind.personality_routine = symbol_find_or_make (name);
2283 *p = c;
2284 demand_empty_rest_of_line ();
2285}
e16bb312 2286
e16bb312 2287
c19d1205 2288/* Parse a directive saving core registers. */
e16bb312 2289
c19d1205
ZW
2290static void
2291s_arm_unwind_save_core (void)
e16bb312 2292{
c19d1205
ZW
2293 valueT op;
2294 long range;
2295 int n;
e16bb312 2296
c19d1205
ZW
2297 range = parse_reg_list (&input_line_pointer);
2298 if (range == FAIL)
e16bb312 2299 {
c19d1205
ZW
2300 as_bad (_("expected register list"));
2301 ignore_rest_of_line ();
2302 return;
2303 }
e16bb312 2304
c19d1205 2305 demand_empty_rest_of_line ();
e16bb312 2306
c19d1205
ZW
2307 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
2308 into .unwind_save {..., sp...}. We aren't bothered about the value of
2309 ip because it is clobbered by calls. */
2310 if (unwind.sp_restored && unwind.fp_reg == 12
2311 && (range & 0x3000) == 0x1000)
2312 {
2313 unwind.opcode_count--;
2314 unwind.sp_restored = 0;
2315 range = (range | 0x2000) & ~0x1000;
2316 unwind.pending_offset = 0;
2317 }
e16bb312 2318
01ae4198
DJ
2319 /* Pop r4-r15. */
2320 if (range & 0xfff0)
c19d1205 2321 {
01ae4198
DJ
2322 /* See if we can use the short opcodes. These pop a block of up to 8
2323 registers starting with r4, plus maybe r14. */
2324 for (n = 0; n < 8; n++)
2325 {
2326 /* Break at the first non-saved register. */
2327 if ((range & (1 << (n + 4))) == 0)
2328 break;
2329 }
2330 /* See if there are any other bits set. */
2331 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
2332 {
2333 /* Use the long form. */
2334 op = 0x8000 | ((range >> 4) & 0xfff);
2335 add_unwind_opcode (op, 2);
2336 }
0dd132b6 2337 else
01ae4198
DJ
2338 {
2339 /* Use the short form. */
2340 if (range & 0x4000)
2341 op = 0xa8; /* Pop r14. */
2342 else
2343 op = 0xa0; /* Do not pop r14. */
2344 op |= (n - 1);
2345 add_unwind_opcode (op, 1);
2346 }
c19d1205 2347 }
0dd132b6 2348
c19d1205
ZW
2349 /* Pop r0-r3. */
2350 if (range & 0xf)
2351 {
2352 op = 0xb100 | (range & 0xf);
2353 add_unwind_opcode (op, 2);
0dd132b6
NC
2354 }
2355
c19d1205
ZW
2356 /* Record the number of bytes pushed. */
2357 for (n = 0; n < 16; n++)
2358 {
2359 if (range & (1 << n))
2360 unwind.frame_size += 4;
2361 }
0dd132b6
NC
2362}
2363
c19d1205
ZW
2364
2365/* Parse a directive saving FPA registers. */
b99bd4ef
NC
2366
2367static void
c19d1205 2368s_arm_unwind_save_fpa (int reg)
b99bd4ef 2369{
c19d1205
ZW
2370 expressionS exp;
2371 int num_regs;
2372 valueT op;
b99bd4ef 2373
c19d1205
ZW
2374 /* Get Number of registers to transfer. */
2375 if (skip_past_comma (&input_line_pointer) != FAIL)
2376 expression (&exp);
2377 else
2378 exp.X_op = O_illegal;
b99bd4ef 2379
c19d1205 2380 if (exp.X_op != O_constant)
b99bd4ef 2381 {
c19d1205
ZW
2382 as_bad (_("expected , <constant>"));
2383 ignore_rest_of_line ();
b99bd4ef
NC
2384 return;
2385 }
2386
c19d1205
ZW
2387 num_regs = exp.X_add_number;
2388
2389 if (num_regs < 1 || num_regs > 4)
b99bd4ef 2390 {
c19d1205
ZW
2391 as_bad (_("number of registers must be in the range [1:4]"));
2392 ignore_rest_of_line ();
b99bd4ef
NC
2393 return;
2394 }
2395
c19d1205 2396 demand_empty_rest_of_line ();
b99bd4ef 2397
c19d1205
ZW
2398 if (reg == 4)
2399 {
2400 /* Short form. */
2401 op = 0xb4 | (num_regs - 1);
2402 add_unwind_opcode (op, 1);
2403 }
b99bd4ef
NC
2404 else
2405 {
c19d1205
ZW
2406 /* Long form. */
2407 op = 0xc800 | (reg << 4) | (num_regs - 1);
2408 add_unwind_opcode (op, 2);
b99bd4ef 2409 }
c19d1205 2410 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
2411}
2412
c19d1205
ZW
2413
2414/* Parse a directive saving VFP registers. */
b99bd4ef
NC
2415
2416static void
c19d1205 2417s_arm_unwind_save_vfp (void)
b99bd4ef 2418{
c19d1205 2419 int count;
ca3f61f7 2420 unsigned int reg;
c19d1205 2421 valueT op;
b99bd4ef 2422
c19d1205
ZW
2423 count = parse_vfp_reg_list (&input_line_pointer, &reg, 1);
2424 if (count == FAIL)
b99bd4ef 2425 {
c19d1205
ZW
2426 as_bad (_("expected register list"));
2427 ignore_rest_of_line ();
b99bd4ef
NC
2428 return;
2429 }
2430
c19d1205 2431 demand_empty_rest_of_line ();
b99bd4ef 2432
c19d1205 2433 if (reg == 8)
b99bd4ef 2434 {
c19d1205
ZW
2435 /* Short form. */
2436 op = 0xb8 | (count - 1);
2437 add_unwind_opcode (op, 1);
b99bd4ef 2438 }
c19d1205 2439 else
b99bd4ef 2440 {
c19d1205
ZW
2441 /* Long form. */
2442 op = 0xb300 | (reg << 4) | (count - 1);
2443 add_unwind_opcode (op, 2);
b99bd4ef 2444 }
c19d1205
ZW
2445 unwind.frame_size += count * 8 + 4;
2446}
b99bd4ef 2447
b99bd4ef 2448
c19d1205
ZW
2449/* Parse a directive saving iWMMXt data registers. */
2450
2451static void
2452s_arm_unwind_save_mmxwr (void)
2453{
2454 int reg;
2455 int hi_reg;
2456 int i;
2457 unsigned mask = 0;
2458 valueT op;
b99bd4ef 2459
c19d1205
ZW
2460 if (*input_line_pointer == '{')
2461 input_line_pointer++;
b99bd4ef 2462
c19d1205 2463 do
b99bd4ef 2464 {
c19d1205 2465 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 2466
c19d1205 2467 if (reg == FAIL)
b99bd4ef 2468 {
c19d1205
ZW
2469 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2470 goto error;
b99bd4ef
NC
2471 }
2472
c19d1205
ZW
2473 if (mask >> reg)
2474 as_tsktsk (_("register list not in ascending order"));
2475 mask |= 1 << reg;
b99bd4ef 2476
c19d1205
ZW
2477 if (*input_line_pointer == '-')
2478 {
2479 input_line_pointer++;
2480 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
2481 if (hi_reg == FAIL)
2482 {
2483 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
2484 goto error;
2485 }
2486 else if (reg >= hi_reg)
2487 {
2488 as_bad (_("bad register range"));
2489 goto error;
2490 }
2491 for (; reg < hi_reg; reg++)
2492 mask |= 1 << reg;
2493 }
2494 }
2495 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2496
c19d1205
ZW
2497 if (*input_line_pointer == '}')
2498 input_line_pointer++;
b99bd4ef 2499
c19d1205 2500 demand_empty_rest_of_line ();
b99bd4ef 2501
c19d1205
ZW
2502 /* Generate any deferred opcodes becuuse we're going to be looking at
2503 the list. */
2504 flush_pending_unwind ();
b99bd4ef 2505
c19d1205 2506 for (i = 0; i < 16; i++)
b99bd4ef 2507 {
c19d1205
ZW
2508 if (mask & (1 << i))
2509 unwind.frame_size += 8;
b99bd4ef
NC
2510 }
2511
c19d1205
ZW
2512 /* Attempt to combine with a previous opcode. We do this because gcc
2513 likes to output separate unwind directives for a single block of
2514 registers. */
2515 if (unwind.opcode_count > 0)
b99bd4ef 2516 {
c19d1205
ZW
2517 i = unwind.opcodes[unwind.opcode_count - 1];
2518 if ((i & 0xf8) == 0xc0)
2519 {
2520 i &= 7;
2521 /* Only merge if the blocks are contiguous. */
2522 if (i < 6)
2523 {
2524 if ((mask & 0xfe00) == (1 << 9))
2525 {
2526 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
2527 unwind.opcode_count--;
2528 }
2529 }
2530 else if (i == 6 && unwind.opcode_count >= 2)
2531 {
2532 i = unwind.opcodes[unwind.opcode_count - 2];
2533 reg = i >> 4;
2534 i &= 0xf;
b99bd4ef 2535
c19d1205
ZW
2536 op = 0xffff << (reg - 1);
2537 if (reg > 0
2538 || ((mask & op) == (1u << (reg - 1))))
2539 {
2540 op = (1 << (reg + i + 1)) - 1;
2541 op &= ~((1 << reg) - 1);
2542 mask |= op;
2543 unwind.opcode_count -= 2;
2544 }
2545 }
2546 }
b99bd4ef
NC
2547 }
2548
c19d1205
ZW
2549 hi_reg = 15;
2550 /* We want to generate opcodes in the order the registers have been
2551 saved, ie. descending order. */
2552 for (reg = 15; reg >= -1; reg--)
b99bd4ef 2553 {
c19d1205
ZW
2554 /* Save registers in blocks. */
2555 if (reg < 0
2556 || !(mask & (1 << reg)))
2557 {
2558 /* We found an unsaved reg. Generate opcodes to save the
2559 preceeding block. */
2560 if (reg != hi_reg)
2561 {
2562 if (reg == 9)
2563 {
2564 /* Short form. */
2565 op = 0xc0 | (hi_reg - 10);
2566 add_unwind_opcode (op, 1);
2567 }
2568 else
2569 {
2570 /* Long form. */
2571 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
2572 add_unwind_opcode (op, 2);
2573 }
2574 }
2575 hi_reg = reg - 1;
2576 }
b99bd4ef
NC
2577 }
2578
c19d1205
ZW
2579 return;
2580error:
2581 ignore_rest_of_line ();
b99bd4ef
NC
2582}
2583
2584static void
c19d1205 2585s_arm_unwind_save_mmxwcg (void)
b99bd4ef 2586{
c19d1205
ZW
2587 int reg;
2588 int hi_reg;
2589 unsigned mask = 0;
2590 valueT op;
b99bd4ef 2591
c19d1205
ZW
2592 if (*input_line_pointer == '{')
2593 input_line_pointer++;
b99bd4ef 2594
c19d1205 2595 do
b99bd4ef 2596 {
c19d1205 2597 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 2598
c19d1205
ZW
2599 if (reg == FAIL)
2600 {
2601 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2602 goto error;
2603 }
b99bd4ef 2604
c19d1205
ZW
2605 reg -= 8;
2606 if (mask >> reg)
2607 as_tsktsk (_("register list not in ascending order"));
2608 mask |= 1 << reg;
b99bd4ef 2609
c19d1205
ZW
2610 if (*input_line_pointer == '-')
2611 {
2612 input_line_pointer++;
2613 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
2614 if (hi_reg == FAIL)
2615 {
2616 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
2617 goto error;
2618 }
2619 else if (reg >= hi_reg)
2620 {
2621 as_bad (_("bad register range"));
2622 goto error;
2623 }
2624 for (; reg < hi_reg; reg++)
2625 mask |= 1 << reg;
2626 }
b99bd4ef 2627 }
c19d1205 2628 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 2629
c19d1205
ZW
2630 if (*input_line_pointer == '}')
2631 input_line_pointer++;
b99bd4ef 2632
c19d1205
ZW
2633 demand_empty_rest_of_line ();
2634
2635 /* Generate any deferred opcodes becuuse we're going to be looking at
2636 the list. */
2637 flush_pending_unwind ();
b99bd4ef 2638
c19d1205 2639 for (reg = 0; reg < 16; reg++)
b99bd4ef 2640 {
c19d1205
ZW
2641 if (mask & (1 << reg))
2642 unwind.frame_size += 4;
b99bd4ef 2643 }
c19d1205
ZW
2644 op = 0xc700 | mask;
2645 add_unwind_opcode (op, 2);
2646 return;
2647error:
2648 ignore_rest_of_line ();
b99bd4ef
NC
2649}
2650
c19d1205
ZW
2651
2652/* Parse an unwind_save directive. */
2653
b99bd4ef 2654static void
c19d1205 2655s_arm_unwind_save (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2656{
c19d1205
ZW
2657 char *peek;
2658 struct reg_entry *reg;
2659 bfd_boolean had_brace = FALSE;
b99bd4ef 2660
c19d1205
ZW
2661 /* Figure out what sort of save we have. */
2662 peek = input_line_pointer;
b99bd4ef 2663
c19d1205 2664 if (*peek == '{')
b99bd4ef 2665 {
c19d1205
ZW
2666 had_brace = TRUE;
2667 peek++;
b99bd4ef
NC
2668 }
2669
c19d1205 2670 reg = arm_reg_parse_multi (&peek);
b99bd4ef 2671
c19d1205 2672 if (!reg)
b99bd4ef 2673 {
c19d1205
ZW
2674 as_bad (_("register expected"));
2675 ignore_rest_of_line ();
b99bd4ef
NC
2676 return;
2677 }
2678
c19d1205 2679 switch (reg->type)
b99bd4ef 2680 {
c19d1205
ZW
2681 case REG_TYPE_FN:
2682 if (had_brace)
2683 {
2684 as_bad (_("FPA .unwind_save does not take a register list"));
2685 ignore_rest_of_line ();
2686 return;
2687 }
2688 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 2689 return;
c19d1205
ZW
2690
2691 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
2692 case REG_TYPE_VFD: s_arm_unwind_save_vfp (); return;
2693 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
2694 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
2695
2696 default:
2697 as_bad (_(".unwind_save does not support this kind of register"));
2698 ignore_rest_of_line ();
b99bd4ef 2699 }
c19d1205 2700}
b99bd4ef 2701
b99bd4ef 2702
c19d1205
ZW
2703/* Parse an unwind_movsp directive. */
2704
2705static void
2706s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
2707{
2708 int reg;
2709 valueT op;
2710
2711 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2712 if (reg == FAIL)
b99bd4ef 2713 {
c19d1205
ZW
2714 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
2715 ignore_rest_of_line ();
b99bd4ef
NC
2716 return;
2717 }
c19d1205 2718 demand_empty_rest_of_line ();
b99bd4ef 2719
c19d1205 2720 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 2721 {
c19d1205 2722 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
2723 return;
2724 }
2725
c19d1205
ZW
2726 if (unwind.fp_reg != REG_SP)
2727 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 2728
c19d1205
ZW
2729 /* Generate opcode to restore the value. */
2730 op = 0x90 | reg;
2731 add_unwind_opcode (op, 1);
2732
2733 /* Record the information for later. */
2734 unwind.fp_reg = reg;
2735 unwind.fp_offset = unwind.frame_size;
2736 unwind.sp_restored = 1;
b05fe5cf
ZW
2737}
2738
c19d1205
ZW
2739/* Parse an unwind_pad directive. */
2740
b05fe5cf 2741static void
c19d1205 2742s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 2743{
c19d1205 2744 int offset;
b05fe5cf 2745
c19d1205
ZW
2746 if (immediate_for_directive (&offset) == FAIL)
2747 return;
b99bd4ef 2748
c19d1205
ZW
2749 if (offset & 3)
2750 {
2751 as_bad (_("stack increment must be multiple of 4"));
2752 ignore_rest_of_line ();
2753 return;
2754 }
b99bd4ef 2755
c19d1205
ZW
2756 /* Don't generate any opcodes, just record the details for later. */
2757 unwind.frame_size += offset;
2758 unwind.pending_offset += offset;
2759
2760 demand_empty_rest_of_line ();
2761}
2762
2763/* Parse an unwind_setfp directive. */
2764
2765static void
2766s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2767{
c19d1205
ZW
2768 int sp_reg;
2769 int fp_reg;
2770 int offset;
2771
2772 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
2773 if (skip_past_comma (&input_line_pointer) == FAIL)
2774 sp_reg = FAIL;
2775 else
2776 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 2777
c19d1205
ZW
2778 if (fp_reg == FAIL || sp_reg == FAIL)
2779 {
2780 as_bad (_("expected <reg>, <reg>"));
2781 ignore_rest_of_line ();
2782 return;
2783 }
b99bd4ef 2784
c19d1205
ZW
2785 /* Optional constant. */
2786 if (skip_past_comma (&input_line_pointer) != FAIL)
2787 {
2788 if (immediate_for_directive (&offset) == FAIL)
2789 return;
2790 }
2791 else
2792 offset = 0;
a737bd4d 2793
c19d1205 2794 demand_empty_rest_of_line ();
a737bd4d 2795
c19d1205 2796 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 2797 {
c19d1205
ZW
2798 as_bad (_("register must be either sp or set by a previous"
2799 "unwind_movsp directive"));
2800 return;
a737bd4d
NC
2801 }
2802
c19d1205
ZW
2803 /* Don't generate any opcodes, just record the information for later. */
2804 unwind.fp_reg = fp_reg;
2805 unwind.fp_used = 1;
2806 if (sp_reg == 13)
2807 unwind.fp_offset = unwind.frame_size - offset;
2808 else
2809 unwind.fp_offset -= offset;
a737bd4d
NC
2810}
2811
c19d1205
ZW
2812/* Parse an unwind_raw directive. */
2813
2814static void
2815s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 2816{
c19d1205
ZW
2817 expressionS exp;
2818 /* This is an arbitary limit. */
2819 unsigned char op[16];
2820 int count;
a737bd4d 2821
c19d1205
ZW
2822 expression (&exp);
2823 if (exp.X_op == O_constant
2824 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 2825 {
c19d1205
ZW
2826 unwind.frame_size += exp.X_add_number;
2827 expression (&exp);
2828 }
2829 else
2830 exp.X_op = O_illegal;
a737bd4d 2831
c19d1205
ZW
2832 if (exp.X_op != O_constant)
2833 {
2834 as_bad (_("expected <offset>, <opcode>"));
2835 ignore_rest_of_line ();
2836 return;
2837 }
a737bd4d 2838
c19d1205 2839 count = 0;
a737bd4d 2840
c19d1205
ZW
2841 /* Parse the opcode. */
2842 for (;;)
2843 {
2844 if (count >= 16)
2845 {
2846 as_bad (_("unwind opcode too long"));
2847 ignore_rest_of_line ();
a737bd4d 2848 }
c19d1205 2849 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 2850 {
c19d1205
ZW
2851 as_bad (_("invalid unwind opcode"));
2852 ignore_rest_of_line ();
2853 return;
a737bd4d 2854 }
c19d1205 2855 op[count++] = exp.X_add_number;
a737bd4d 2856
c19d1205
ZW
2857 /* Parse the next byte. */
2858 if (skip_past_comma (&input_line_pointer) == FAIL)
2859 break;
a737bd4d 2860
c19d1205
ZW
2861 expression (&exp);
2862 }
b99bd4ef 2863
c19d1205
ZW
2864 /* Add the opcode bytes in reverse order. */
2865 while (count--)
2866 add_unwind_opcode (op[count], 1);
b99bd4ef 2867
c19d1205 2868 demand_empty_rest_of_line ();
b99bd4ef 2869}
ee065d83
PB
2870
2871
2872/* Parse a .eabi_attribute directive. */
2873
2874static void
2875s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
2876{
2877 expressionS exp;
2878 bfd_boolean is_string;
2879 int tag;
2880 unsigned int i = 0;
2881 char *s = NULL;
2882 char saved_char;
2883
2884 expression (& exp);
2885 if (exp.X_op != O_constant)
2886 goto bad;
2887
2888 tag = exp.X_add_number;
2889 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
2890 is_string = 1;
2891 else
2892 is_string = 0;
2893
2894 if (skip_past_comma (&input_line_pointer) == FAIL)
2895 goto bad;
2896 if (tag == 32 || !is_string)
2897 {
2898 expression (& exp);
2899 if (exp.X_op != O_constant)
2900 {
2901 as_bad (_("expected numeric constant"));
2902 ignore_rest_of_line ();
2903 return;
2904 }
2905 i = exp.X_add_number;
2906 }
2907 if (tag == Tag_compatibility
2908 && skip_past_comma (&input_line_pointer) == FAIL)
2909 {
2910 as_bad (_("expected comma"));
2911 ignore_rest_of_line ();
2912 return;
2913 }
2914 if (is_string)
2915 {
2916 skip_whitespace(input_line_pointer);
2917 if (*input_line_pointer != '"')
2918 goto bad_string;
2919 input_line_pointer++;
2920 s = input_line_pointer;
2921 while (*input_line_pointer && *input_line_pointer != '"')
2922 input_line_pointer++;
2923 if (*input_line_pointer != '"')
2924 goto bad_string;
2925 saved_char = *input_line_pointer;
2926 *input_line_pointer = 0;
2927 }
2928 else
2929 {
2930 s = NULL;
2931 saved_char = 0;
2932 }
2933
2934 if (tag == Tag_compatibility)
2935 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
2936 else if (is_string)
2937 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
2938 else
2939 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
2940
2941 if (s)
2942 {
2943 *input_line_pointer = saved_char;
2944 input_line_pointer++;
2945 }
2946 demand_empty_rest_of_line ();
2947 return;
2948bad_string:
2949 as_bad (_("bad string constant"));
2950 ignore_rest_of_line ();
2951 return;
2952bad:
2953 as_bad (_("expected <tag> , <value>"));
2954 ignore_rest_of_line ();
2955}
2956
2957static void s_arm_arch (int);
2958static void s_arm_cpu (int);
2959static void s_arm_fpu (int);
c19d1205 2960#endif /* OBJ_ELF */
b99bd4ef 2961
c19d1205
ZW
2962/* This table describes all the machine specific pseudo-ops the assembler
2963 has to support. The fields are:
2964 pseudo-op name without dot
2965 function to call to execute this pseudo-op
2966 Integer arg to pass to the function. */
b99bd4ef 2967
c19d1205 2968const pseudo_typeS md_pseudo_table[] =
b99bd4ef 2969{
c19d1205
ZW
2970 /* Never called because '.req' does not start a line. */
2971 { "req", s_req, 0 },
2972 { "unreq", s_unreq, 0 },
2973 { "bss", s_bss, 0 },
2974 { "align", s_align, 0 },
2975 { "arm", s_arm, 0 },
2976 { "thumb", s_thumb, 0 },
2977 { "code", s_code, 0 },
2978 { "force_thumb", s_force_thumb, 0 },
2979 { "thumb_func", s_thumb_func, 0 },
2980 { "thumb_set", s_thumb_set, 0 },
2981 { "even", s_even, 0 },
2982 { "ltorg", s_ltorg, 0 },
2983 { "pool", s_ltorg, 0 },
2984 { "syntax", s_syntax, 0 },
2985#ifdef OBJ_ELF
2986 { "word", s_arm_elf_cons, 4 },
2987 { "long", s_arm_elf_cons, 4 },
2988 { "rel31", s_arm_rel31, 0 },
2989 { "fnstart", s_arm_unwind_fnstart, 0 },
2990 { "fnend", s_arm_unwind_fnend, 0 },
2991 { "cantunwind", s_arm_unwind_cantunwind, 0 },
2992 { "personality", s_arm_unwind_personality, 0 },
2993 { "personalityindex", s_arm_unwind_personalityindex, 0 },
2994 { "handlerdata", s_arm_unwind_handlerdata, 0 },
2995 { "save", s_arm_unwind_save, 0 },
2996 { "movsp", s_arm_unwind_movsp, 0 },
2997 { "pad", s_arm_unwind_pad, 0 },
2998 { "setfp", s_arm_unwind_setfp, 0 },
2999 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83
PB
3000 { "cpu", s_arm_cpu, 0 },
3001 { "arch", s_arm_arch, 0 },
3002 { "fpu", s_arm_fpu, 0 },
3003 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3004#else
3005 { "word", cons, 4},
3006#endif
3007 { "extend", float_cons, 'x' },
3008 { "ldouble", float_cons, 'x' },
3009 { "packed", float_cons, 'p' },
3010 { 0, 0, 0 }
3011};
3012\f
3013/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3014
c19d1205
ZW
3015/* Generic immediate-value read function for use in insn parsing.
3016 STR points to the beginning of the immediate (the leading #);
3017 VAL receives the value; if the value is outside [MIN, MAX]
3018 issue an error. PREFIX_OPT is true if the immediate prefix is
3019 optional. */
b99bd4ef 3020
c19d1205
ZW
3021static int
3022parse_immediate (char **str, int *val, int min, int max,
3023 bfd_boolean prefix_opt)
3024{
3025 expressionS exp;
3026 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3027 if (exp.X_op != O_constant)
b99bd4ef 3028 {
c19d1205
ZW
3029 inst.error = _("constant expression required");
3030 return FAIL;
3031 }
b99bd4ef 3032
c19d1205
ZW
3033 if (exp.X_add_number < min || exp.X_add_number > max)
3034 {
3035 inst.error = _("immediate value out of range");
3036 return FAIL;
3037 }
b99bd4ef 3038
c19d1205
ZW
3039 *val = exp.X_add_number;
3040 return SUCCESS;
3041}
b99bd4ef 3042
c19d1205
ZW
3043/* Returns the pseudo-register number of an FPA immediate constant,
3044 or FAIL if there isn't a valid constant here. */
b99bd4ef 3045
c19d1205
ZW
3046static int
3047parse_fpa_immediate (char ** str)
3048{
3049 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3050 char * save_in;
3051 expressionS exp;
3052 int i;
3053 int j;
b99bd4ef 3054
c19d1205
ZW
3055 /* First try and match exact strings, this is to guarantee
3056 that some formats will work even for cross assembly. */
b99bd4ef 3057
c19d1205
ZW
3058 for (i = 0; fp_const[i]; i++)
3059 {
3060 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 3061 {
c19d1205 3062 char *start = *str;
b99bd4ef 3063
c19d1205
ZW
3064 *str += strlen (fp_const[i]);
3065 if (is_end_of_line[(unsigned char) **str])
3066 return i + 8;
3067 *str = start;
3068 }
3069 }
b99bd4ef 3070
c19d1205
ZW
3071 /* Just because we didn't get a match doesn't mean that the constant
3072 isn't valid, just that it is in a format that we don't
3073 automatically recognize. Try parsing it with the standard
3074 expression routines. */
b99bd4ef 3075
c19d1205 3076 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 3077
c19d1205
ZW
3078 /* Look for a raw floating point number. */
3079 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
3080 && is_end_of_line[(unsigned char) *save_in])
3081 {
3082 for (i = 0; i < NUM_FLOAT_VALS; i++)
3083 {
3084 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 3085 {
c19d1205
ZW
3086 if (words[j] != fp_values[i][j])
3087 break;
b99bd4ef
NC
3088 }
3089
c19d1205 3090 if (j == MAX_LITTLENUMS)
b99bd4ef 3091 {
c19d1205
ZW
3092 *str = save_in;
3093 return i + 8;
b99bd4ef
NC
3094 }
3095 }
3096 }
b99bd4ef 3097
c19d1205
ZW
3098 /* Try and parse a more complex expression, this will probably fail
3099 unless the code uses a floating point prefix (eg "0f"). */
3100 save_in = input_line_pointer;
3101 input_line_pointer = *str;
3102 if (expression (&exp) == absolute_section
3103 && exp.X_op == O_big
3104 && exp.X_add_number < 0)
3105 {
3106 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
3107 Ditto for 15. */
3108 if (gen_to_words (words, 5, (long) 15) == 0)
3109 {
3110 for (i = 0; i < NUM_FLOAT_VALS; i++)
3111 {
3112 for (j = 0; j < MAX_LITTLENUMS; j++)
3113 {
3114 if (words[j] != fp_values[i][j])
3115 break;
3116 }
b99bd4ef 3117
c19d1205
ZW
3118 if (j == MAX_LITTLENUMS)
3119 {
3120 *str = input_line_pointer;
3121 input_line_pointer = save_in;
3122 return i + 8;
3123 }
3124 }
3125 }
b99bd4ef
NC
3126 }
3127
c19d1205
ZW
3128 *str = input_line_pointer;
3129 input_line_pointer = save_in;
3130 inst.error = _("invalid FPA immediate expression");
3131 return FAIL;
b99bd4ef
NC
3132}
3133
c19d1205
ZW
3134/* Shift operands. */
3135enum shift_kind
b99bd4ef 3136{
c19d1205
ZW
3137 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
3138};
b99bd4ef 3139
c19d1205
ZW
3140struct asm_shift_name
3141{
3142 const char *name;
3143 enum shift_kind kind;
3144};
b99bd4ef 3145
c19d1205
ZW
3146/* Third argument to parse_shift. */
3147enum parse_shift_mode
3148{
3149 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
3150 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
3151 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
3152 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
3153 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
3154};
b99bd4ef 3155
c19d1205
ZW
3156/* Parse a <shift> specifier on an ARM data processing instruction.
3157 This has three forms:
b99bd4ef 3158
c19d1205
ZW
3159 (LSL|LSR|ASL|ASR|ROR) Rs
3160 (LSL|LSR|ASL|ASR|ROR) #imm
3161 RRX
b99bd4ef 3162
c19d1205
ZW
3163 Note that ASL is assimilated to LSL in the instruction encoding, and
3164 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 3165
c19d1205
ZW
3166static int
3167parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 3168{
c19d1205
ZW
3169 const struct asm_shift_name *shift_name;
3170 enum shift_kind shift;
3171 char *s = *str;
3172 char *p = s;
3173 int reg;
b99bd4ef 3174
c19d1205
ZW
3175 for (p = *str; ISALPHA (*p); p++)
3176 ;
b99bd4ef 3177
c19d1205 3178 if (p == *str)
b99bd4ef 3179 {
c19d1205
ZW
3180 inst.error = _("shift expression expected");
3181 return FAIL;
b99bd4ef
NC
3182 }
3183
c19d1205
ZW
3184 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
3185
3186 if (shift_name == NULL)
b99bd4ef 3187 {
c19d1205
ZW
3188 inst.error = _("shift expression expected");
3189 return FAIL;
b99bd4ef
NC
3190 }
3191
c19d1205 3192 shift = shift_name->kind;
b99bd4ef 3193
c19d1205
ZW
3194 switch (mode)
3195 {
3196 case NO_SHIFT_RESTRICT:
3197 case SHIFT_IMMEDIATE: break;
b99bd4ef 3198
c19d1205
ZW
3199 case SHIFT_LSL_OR_ASR_IMMEDIATE:
3200 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
3201 {
3202 inst.error = _("'LSL' or 'ASR' required");
3203 return FAIL;
3204 }
3205 break;
b99bd4ef 3206
c19d1205
ZW
3207 case SHIFT_LSL_IMMEDIATE:
3208 if (shift != SHIFT_LSL)
3209 {
3210 inst.error = _("'LSL' required");
3211 return FAIL;
3212 }
3213 break;
b99bd4ef 3214
c19d1205
ZW
3215 case SHIFT_ASR_IMMEDIATE:
3216 if (shift != SHIFT_ASR)
3217 {
3218 inst.error = _("'ASR' required");
3219 return FAIL;
3220 }
3221 break;
b99bd4ef 3222
c19d1205
ZW
3223 default: abort ();
3224 }
b99bd4ef 3225
c19d1205
ZW
3226 if (shift != SHIFT_RRX)
3227 {
3228 /* Whitespace can appear here if the next thing is a bare digit. */
3229 skip_whitespace (p);
b99bd4ef 3230
c19d1205
ZW
3231 if (mode == NO_SHIFT_RESTRICT
3232 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3233 {
3234 inst.operands[i].imm = reg;
3235 inst.operands[i].immisreg = 1;
3236 }
3237 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3238 return FAIL;
3239 }
3240 inst.operands[i].shift_kind = shift;
3241 inst.operands[i].shifted = 1;
3242 *str = p;
3243 return SUCCESS;
b99bd4ef
NC
3244}
3245
c19d1205 3246/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 3247
c19d1205
ZW
3248 #<immediate>
3249 #<immediate>, <rotate>
3250 <Rm>
3251 <Rm>, <shift>
b99bd4ef 3252
c19d1205
ZW
3253 where <shift> is defined by parse_shift above, and <rotate> is a
3254 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 3255 is deferred to md_apply_fix. */
b99bd4ef 3256
c19d1205
ZW
3257static int
3258parse_shifter_operand (char **str, int i)
3259{
3260 int value;
3261 expressionS expr;
b99bd4ef 3262
c19d1205
ZW
3263 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
3264 {
3265 inst.operands[i].reg = value;
3266 inst.operands[i].isreg = 1;
b99bd4ef 3267
c19d1205
ZW
3268 /* parse_shift will override this if appropriate */
3269 inst.reloc.exp.X_op = O_constant;
3270 inst.reloc.exp.X_add_number = 0;
b99bd4ef 3271
c19d1205
ZW
3272 if (skip_past_comma (str) == FAIL)
3273 return SUCCESS;
b99bd4ef 3274
c19d1205
ZW
3275 /* Shift operation on register. */
3276 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
3277 }
3278
c19d1205
ZW
3279 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
3280 return FAIL;
b99bd4ef 3281
c19d1205 3282 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 3283 {
c19d1205
ZW
3284 /* #x, y -- ie explicit rotation by Y. */
3285 if (my_get_expression (&expr, str, GE_NO_PREFIX))
3286 return FAIL;
b99bd4ef 3287
c19d1205
ZW
3288 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
3289 {
3290 inst.error = _("constant expression expected");
3291 return FAIL;
3292 }
b99bd4ef 3293
c19d1205
ZW
3294 value = expr.X_add_number;
3295 if (value < 0 || value > 30 || value % 2 != 0)
3296 {
3297 inst.error = _("invalid rotation");
3298 return FAIL;
3299 }
3300 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
3301 {
3302 inst.error = _("invalid constant");
3303 return FAIL;
3304 }
09d92015 3305
55cf6793 3306 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
3307 inst.reloc.exp.X_add_number
3308 = (((inst.reloc.exp.X_add_number << (32 - value))
3309 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
3310 }
3311
c19d1205
ZW
3312 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
3313 inst.reloc.pc_rel = 0;
3314 return SUCCESS;
09d92015
MM
3315}
3316
c19d1205
ZW
3317/* Parse all forms of an ARM address expression. Information is written
3318 to inst.operands[i] and/or inst.reloc.
09d92015 3319
c19d1205 3320 Preindexed addressing (.preind=1):
09d92015 3321
c19d1205
ZW
3322 [Rn, #offset] .reg=Rn .reloc.exp=offset
3323 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3324 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3325 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3326
c19d1205 3327 These three may have a trailing ! which causes .writeback to be set also.
09d92015 3328
c19d1205 3329 Postindexed addressing (.postind=1, .writeback=1):
09d92015 3330
c19d1205
ZW
3331 [Rn], #offset .reg=Rn .reloc.exp=offset
3332 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3333 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
3334 .shift_kind=shift .reloc.exp=shift_imm
09d92015 3335
c19d1205 3336 Unindexed addressing (.preind=0, .postind=0):
09d92015 3337
c19d1205 3338 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 3339
c19d1205 3340 Other:
09d92015 3341
c19d1205
ZW
3342 [Rn]{!} shorthand for [Rn,#0]{!}
3343 =immediate .isreg=0 .reloc.exp=immediate
3344 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 3345
c19d1205
ZW
3346 It is the caller's responsibility to check for addressing modes not
3347 supported by the instruction, and to set inst.reloc.type. */
3348
3349static int
3350parse_address (char **str, int i)
09d92015 3351{
c19d1205
ZW
3352 char *p = *str;
3353 int reg;
09d92015 3354
c19d1205 3355 if (skip_past_char (&p, '[') == FAIL)
09d92015 3356 {
c19d1205
ZW
3357 if (skip_past_char (&p, '=') == FAIL)
3358 {
3359 /* bare address - translate to PC-relative offset */
3360 inst.reloc.pc_rel = 1;
3361 inst.operands[i].reg = REG_PC;
3362 inst.operands[i].isreg = 1;
3363 inst.operands[i].preind = 1;
3364 }
3365 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 3366
c19d1205
ZW
3367 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
3368 return FAIL;
09d92015 3369
c19d1205
ZW
3370 *str = p;
3371 return SUCCESS;
09d92015
MM
3372 }
3373
c19d1205 3374 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 3375 {
c19d1205
ZW
3376 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3377 return FAIL;
09d92015 3378 }
c19d1205
ZW
3379 inst.operands[i].reg = reg;
3380 inst.operands[i].isreg = 1;
09d92015 3381
c19d1205 3382 if (skip_past_comma (&p) == SUCCESS)
09d92015 3383 {
c19d1205 3384 inst.operands[i].preind = 1;
09d92015 3385
c19d1205
ZW
3386 if (*p == '+') p++;
3387 else if (*p == '-') p++, inst.operands[i].negative = 1;
3388
3389 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 3390 {
c19d1205
ZW
3391 inst.operands[i].imm = reg;
3392 inst.operands[i].immisreg = 1;
3393
3394 if (skip_past_comma (&p) == SUCCESS)
3395 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3396 return FAIL;
3397 }
3398 else
3399 {
3400 if (inst.operands[i].negative)
3401 {
3402 inst.operands[i].negative = 0;
3403 p--;
3404 }
3405 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3406 return FAIL;
09d92015
MM
3407 }
3408 }
3409
c19d1205 3410 if (skip_past_char (&p, ']') == FAIL)
09d92015 3411 {
c19d1205
ZW
3412 inst.error = _("']' expected");
3413 return FAIL;
09d92015
MM
3414 }
3415
c19d1205
ZW
3416 if (skip_past_char (&p, '!') == SUCCESS)
3417 inst.operands[i].writeback = 1;
09d92015 3418
c19d1205 3419 else if (skip_past_comma (&p) == SUCCESS)
09d92015 3420 {
c19d1205
ZW
3421 if (skip_past_char (&p, '{') == SUCCESS)
3422 {
3423 /* [Rn], {expr} - unindexed, with option */
3424 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 3425 0, 255, TRUE) == FAIL)
c19d1205 3426 return FAIL;
09d92015 3427
c19d1205
ZW
3428 if (skip_past_char (&p, '}') == FAIL)
3429 {
3430 inst.error = _("'}' expected at end of 'option' field");
3431 return FAIL;
3432 }
3433 if (inst.operands[i].preind)
3434 {
3435 inst.error = _("cannot combine index with option");
3436 return FAIL;
3437 }
3438 *str = p;
3439 return SUCCESS;
09d92015 3440 }
c19d1205
ZW
3441 else
3442 {
3443 inst.operands[i].postind = 1;
3444 inst.operands[i].writeback = 1;
09d92015 3445
c19d1205
ZW
3446 if (inst.operands[i].preind)
3447 {
3448 inst.error = _("cannot combine pre- and post-indexing");
3449 return FAIL;
3450 }
09d92015 3451
c19d1205
ZW
3452 if (*p == '+') p++;
3453 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 3454
c19d1205
ZW
3455 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
3456 {
3457 inst.operands[i].imm = reg;
3458 inst.operands[i].immisreg = 1;
a737bd4d 3459
c19d1205
ZW
3460 if (skip_past_comma (&p) == SUCCESS)
3461 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
3462 return FAIL;
3463 }
3464 else
3465 {
3466 if (inst.operands[i].negative)
3467 {
3468 inst.operands[i].negative = 0;
3469 p--;
3470 }
3471 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
3472 return FAIL;
3473 }
3474 }
a737bd4d
NC
3475 }
3476
c19d1205
ZW
3477 /* If at this point neither .preind nor .postind is set, we have a
3478 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
3479 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
3480 {
3481 inst.operands[i].preind = 1;
3482 inst.reloc.exp.X_op = O_constant;
3483 inst.reloc.exp.X_add_number = 0;
3484 }
3485 *str = p;
3486 return SUCCESS;
a737bd4d
NC
3487}
3488
c19d1205 3489/* Miscellaneous. */
a737bd4d 3490
c19d1205
ZW
3491/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
3492 or a bitmask suitable to be or-ed into the ARM msr instruction. */
3493static int
3494parse_psr (char **str)
09d92015 3495{
c19d1205
ZW
3496 char *p;
3497 unsigned long psr_field;
62b3e311
PB
3498 const struct asm_psr *psr;
3499 char *start;
09d92015 3500
c19d1205
ZW
3501 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
3502 feature for ease of use and backwards compatibility. */
3503 p = *str;
62b3e311 3504 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 3505 psr_field = SPSR_BIT;
62b3e311 3506 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
3507 psr_field = 0;
3508 else
62b3e311
PB
3509 {
3510 start = p;
3511 do
3512 p++;
3513 while (ISALNUM (*p) || *p == '_');
3514
3515 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
3516 if (!psr)
3517 return FAIL;
09d92015 3518
62b3e311
PB
3519 *str = p;
3520 return psr->field;
3521 }
09d92015 3522
62b3e311 3523 p += 4;
c19d1205
ZW
3524 if (*p == '_')
3525 {
3526 /* A suffix follows. */
c19d1205
ZW
3527 p++;
3528 start = p;
a737bd4d 3529
c19d1205
ZW
3530 do
3531 p++;
3532 while (ISALNUM (*p) || *p == '_');
a737bd4d 3533
c19d1205
ZW
3534 psr = hash_find_n (arm_psr_hsh, start, p - start);
3535 if (!psr)
3536 goto error;
a737bd4d 3537
c19d1205 3538 psr_field |= psr->field;
a737bd4d 3539 }
c19d1205 3540 else
a737bd4d 3541 {
c19d1205
ZW
3542 if (ISALNUM (*p))
3543 goto error; /* Garbage after "[CS]PSR". */
3544
3545 psr_field |= (PSR_c | PSR_f);
a737bd4d 3546 }
c19d1205
ZW
3547 *str = p;
3548 return psr_field;
a737bd4d 3549
c19d1205
ZW
3550 error:
3551 inst.error = _("flag for {c}psr instruction expected");
3552 return FAIL;
a737bd4d
NC
3553}
3554
c19d1205
ZW
3555/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
3556 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 3557
c19d1205
ZW
3558static int
3559parse_cps_flags (char **str)
a737bd4d 3560{
c19d1205
ZW
3561 int val = 0;
3562 int saw_a_flag = 0;
3563 char *s = *str;
a737bd4d 3564
c19d1205
ZW
3565 for (;;)
3566 switch (*s++)
3567 {
3568 case '\0': case ',':
3569 goto done;
a737bd4d 3570
c19d1205
ZW
3571 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
3572 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
3573 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 3574
c19d1205
ZW
3575 default:
3576 inst.error = _("unrecognized CPS flag");
3577 return FAIL;
3578 }
a737bd4d 3579
c19d1205
ZW
3580 done:
3581 if (saw_a_flag == 0)
a737bd4d 3582 {
c19d1205
ZW
3583 inst.error = _("missing CPS flags");
3584 return FAIL;
a737bd4d 3585 }
a737bd4d 3586
c19d1205
ZW
3587 *str = s - 1;
3588 return val;
a737bd4d
NC
3589}
3590
c19d1205
ZW
3591/* Parse an endian specifier ("BE" or "LE", case insensitive);
3592 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
3593
3594static int
c19d1205 3595parse_endian_specifier (char **str)
a737bd4d 3596{
c19d1205
ZW
3597 int little_endian;
3598 char *s = *str;
a737bd4d 3599
c19d1205
ZW
3600 if (strncasecmp (s, "BE", 2))
3601 little_endian = 0;
3602 else if (strncasecmp (s, "LE", 2))
3603 little_endian = 1;
3604 else
a737bd4d 3605 {
c19d1205 3606 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3607 return FAIL;
3608 }
3609
c19d1205 3610 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 3611 {
c19d1205 3612 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
3613 return FAIL;
3614 }
3615
c19d1205
ZW
3616 *str = s + 2;
3617 return little_endian;
3618}
a737bd4d 3619
c19d1205
ZW
3620/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
3621 value suitable for poking into the rotate field of an sxt or sxta
3622 instruction, or FAIL on error. */
3623
3624static int
3625parse_ror (char **str)
3626{
3627 int rot;
3628 char *s = *str;
3629
3630 if (strncasecmp (s, "ROR", 3) == 0)
3631 s += 3;
3632 else
a737bd4d 3633 {
c19d1205 3634 inst.error = _("missing rotation field after comma");
a737bd4d
NC
3635 return FAIL;
3636 }
c19d1205
ZW
3637
3638 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
3639 return FAIL;
3640
3641 switch (rot)
a737bd4d 3642 {
c19d1205
ZW
3643 case 0: *str = s; return 0x0;
3644 case 8: *str = s; return 0x1;
3645 case 16: *str = s; return 0x2;
3646 case 24: *str = s; return 0x3;
3647
3648 default:
3649 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
3650 return FAIL;
3651 }
c19d1205 3652}
a737bd4d 3653
c19d1205
ZW
3654/* Parse a conditional code (from conds[] below). The value returned is in the
3655 range 0 .. 14, or FAIL. */
3656static int
3657parse_cond (char **str)
3658{
3659 char *p, *q;
3660 const struct asm_cond *c;
a737bd4d 3661
c19d1205
ZW
3662 p = q = *str;
3663 while (ISALPHA (*q))
3664 q++;
a737bd4d 3665
c19d1205
ZW
3666 c = hash_find_n (arm_cond_hsh, p, q - p);
3667 if (!c)
a737bd4d 3668 {
c19d1205 3669 inst.error = _("condition required");
a737bd4d
NC
3670 return FAIL;
3671 }
3672
c19d1205
ZW
3673 *str = q;
3674 return c->value;
3675}
3676
62b3e311
PB
3677/* Parse an option for a barrier instruction. Returns the encoding for the
3678 option, or FAIL. */
3679static int
3680parse_barrier (char **str)
3681{
3682 char *p, *q;
3683 const struct asm_barrier_opt *o;
3684
3685 p = q = *str;
3686 while (ISALPHA (*q))
3687 q++;
3688
3689 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
3690 if (!o)
3691 return FAIL;
3692
3693 *str = q;
3694 return o->value;
3695}
3696
92e90b6e
PB
3697/* Parse the operands of a table branch instruction. Similar to a memory
3698 operand. */
3699static int
3700parse_tb (char **str)
3701{
3702 char * p = *str;
3703 int reg;
3704
3705 if (skip_past_char (&p, '[') == FAIL)
3706 return FAIL;
3707
3708 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3709 {
3710 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3711 return FAIL;
3712 }
3713 inst.operands[0].reg = reg;
3714
3715 if (skip_past_comma (&p) == FAIL)
3716 return FAIL;
3717
3718 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
3719 {
3720 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
3721 return FAIL;
3722 }
3723 inst.operands[0].imm = reg;
3724
3725 if (skip_past_comma (&p) == SUCCESS)
3726 {
3727 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
3728 return FAIL;
3729 if (inst.reloc.exp.X_add_number != 1)
3730 {
3731 inst.error = _("invalid shift");
3732 return FAIL;
3733 }
3734 inst.operands[0].shifted = 1;
3735 }
3736
3737 if (skip_past_char (&p, ']') == FAIL)
3738 {
3739 inst.error = _("']' expected");
3740 return FAIL;
3741 }
3742 *str = p;
3743 return SUCCESS;
3744}
3745
c19d1205
ZW
3746/* Matcher codes for parse_operands. */
3747enum operand_parse_code
3748{
3749 OP_stop, /* end of line */
3750
3751 OP_RR, /* ARM register */
3752 OP_RRnpc, /* ARM register, not r15 */
3753 OP_RRnpcb, /* ARM register, not r15, in square brackets */
3754 OP_RRw, /* ARM register, not r15, optional trailing ! */
3755 OP_RCP, /* Coprocessor number */
3756 OP_RCN, /* Coprocessor register */
3757 OP_RF, /* FPA register */
3758 OP_RVS, /* VFP single precision register */
3759 OP_RVD, /* VFP double precision register */
3760 OP_RVC, /* VFP control register */
3761 OP_RMF, /* Maverick F register */
3762 OP_RMD, /* Maverick D register */
3763 OP_RMFX, /* Maverick FX register */
3764 OP_RMDX, /* Maverick DX register */
3765 OP_RMAX, /* Maverick AX register */
3766 OP_RMDS, /* Maverick DSPSC register */
3767 OP_RIWR, /* iWMMXt wR register */
3768 OP_RIWC, /* iWMMXt wC register */
3769 OP_RIWG, /* iWMMXt wCG register */
3770 OP_RXA, /* XScale accumulator register */
3771
3772 OP_REGLST, /* ARM register list */
3773 OP_VRSLST, /* VFP single-precision register list */
3774 OP_VRDLST, /* VFP double-precision register list */
3775
3776 OP_I7, /* immediate value 0 .. 7 */
3777 OP_I15, /* 0 .. 15 */
3778 OP_I16, /* 1 .. 16 */
3779 OP_I31, /* 0 .. 31 */
3780 OP_I31w, /* 0 .. 31, optional trailing ! */
3781 OP_I32, /* 1 .. 32 */
3782 OP_I63s, /* -64 .. 63 */
3783 OP_I255, /* 0 .. 255 */
3784 OP_Iffff, /* 0 .. 65535 */
3785
3786 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
3787 OP_I7b, /* 0 .. 7 */
3788 OP_I15b, /* 0 .. 15 */
3789 OP_I31b, /* 0 .. 31 */
3790
3791 OP_SH, /* shifter operand */
3792 OP_ADDR, /* Memory address expression (any mode) */
3793 OP_EXP, /* arbitrary expression */
3794 OP_EXPi, /* same, with optional immediate prefix */
3795 OP_EXPr, /* same, with optional relocation suffix */
3796
3797 OP_CPSF, /* CPS flags */
3798 OP_ENDI, /* Endianness specifier */
3799 OP_PSR, /* CPSR/SPSR mask for msr */
3800 OP_COND, /* conditional code */
92e90b6e 3801 OP_TB, /* Table branch. */
c19d1205
ZW
3802
3803 OP_RRnpc_I0, /* ARM register or literal 0 */
3804 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
3805 OP_RR_EXi, /* ARM register or expression with imm prefix */
3806 OP_RF_IF, /* FPA register or immediate */
3807 OP_RIWR_RIWC, /* iWMMXt R or C reg */
3808
3809 /* Optional operands. */
3810 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
3811 OP_oI31b, /* 0 .. 31 */
3812 OP_oIffffb, /* 0 .. 65535 */
3813 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
3814
3815 OP_oRR, /* ARM register */
3816 OP_oRRnpc, /* ARM register, not the PC */
3817 OP_oSHll, /* LSL immediate */
3818 OP_oSHar, /* ASR immediate */
3819 OP_oSHllar, /* LSL or ASR immediate */
3820 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 3821 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
3822
3823 OP_FIRST_OPTIONAL = OP_oI7b
3824};
a737bd4d 3825
c19d1205
ZW
3826/* Generic instruction operand parser. This does no encoding and no
3827 semantic validation; it merely squirrels values away in the inst
3828 structure. Returns SUCCESS or FAIL depending on whether the
3829 specified grammar matched. */
3830static int
ca3f61f7 3831parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
3832{
3833 unsigned const char *upat = pattern;
3834 char *backtrack_pos = 0;
3835 const char *backtrack_error = 0;
3836 int i, val, backtrack_index = 0;
3837
3838#define po_char_or_fail(chr) do { \
3839 if (skip_past_char (&str, chr) == FAIL) \
3840 goto bad_args; \
3841} while (0)
3842
3843#define po_reg_or_fail(regtype) do { \
3844 val = arm_reg_parse (&str, regtype); \
3845 if (val == FAIL) \
3846 { \
3847 inst.error = _(reg_expected_msgs[regtype]); \
3848 goto failure; \
3849 } \
3850 inst.operands[i].reg = val; \
3851 inst.operands[i].isreg = 1; \
3852} while (0)
3853
3854#define po_reg_or_goto(regtype, label) do { \
3855 val = arm_reg_parse (&str, regtype); \
3856 if (val == FAIL) \
3857 goto label; \
3858 \
3859 inst.operands[i].reg = val; \
3860 inst.operands[i].isreg = 1; \
3861} while (0)
3862
3863#define po_imm_or_fail(min, max, popt) do { \
3864 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
3865 goto failure; \
3866 inst.operands[i].imm = val; \
3867} while (0)
3868
3869#define po_misc_or_fail(expr) do { \
3870 if (expr) \
3871 goto failure; \
3872} while (0)
3873
3874 skip_whitespace (str);
3875
3876 for (i = 0; upat[i] != OP_stop; i++)
3877 {
3878 if (upat[i] >= OP_FIRST_OPTIONAL)
3879 {
3880 /* Remember where we are in case we need to backtrack. */
3881 assert (!backtrack_pos);
3882 backtrack_pos = str;
3883 backtrack_error = inst.error;
3884 backtrack_index = i;
3885 }
3886
3887 if (i > 0)
3888 po_char_or_fail (',');
3889
3890 switch (upat[i])
3891 {
3892 /* Registers */
3893 case OP_oRRnpc:
3894 case OP_RRnpc:
3895 case OP_oRR:
3896 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
3897 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
3898 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
3899 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
3900 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
3901 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
3902 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
3903 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
3904 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
3905 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
3906 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
3907 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
3908 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
3909 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
3910 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
3911 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
3912 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
3913
3914 case OP_RRnpcb:
3915 po_char_or_fail ('[');
3916 po_reg_or_fail (REG_TYPE_RN);
3917 po_char_or_fail (']');
3918 break;
a737bd4d 3919
c19d1205
ZW
3920 case OP_RRw:
3921 po_reg_or_fail (REG_TYPE_RN);
3922 if (skip_past_char (&str, '!') == SUCCESS)
3923 inst.operands[i].writeback = 1;
3924 break;
3925
3926 /* Immediates */
3927 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
3928 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
3929 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
3930 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
3931 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
3932 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
3933 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
3934 case OP_Iffff: po_imm_or_fail ( 0, 0xffff, FALSE); break;
3935
3936 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
3937 case OP_oI7b:
3938 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
3939 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
3940 case OP_oI31b:
3941 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
3942 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
3943
3944 /* Immediate variants */
3945 case OP_oI255c:
3946 po_char_or_fail ('{');
3947 po_imm_or_fail (0, 255, TRUE);
3948 po_char_or_fail ('}');
3949 break;
3950
3951 case OP_I31w:
3952 /* The expression parser chokes on a trailing !, so we have
3953 to find it first and zap it. */
3954 {
3955 char *s = str;
3956 while (*s && *s != ',')
3957 s++;
3958 if (s[-1] == '!')
3959 {
3960 s[-1] = '\0';
3961 inst.operands[i].writeback = 1;
3962 }
3963 po_imm_or_fail (0, 31, TRUE);
3964 if (str == s - 1)
3965 str = s;
3966 }
3967 break;
3968
3969 /* Expressions */
3970 case OP_EXPi: EXPi:
3971 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3972 GE_OPT_PREFIX));
3973 break;
3974
3975 case OP_EXP:
3976 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3977 GE_NO_PREFIX));
3978 break;
3979
3980 case OP_EXPr: EXPr:
3981 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
3982 GE_NO_PREFIX));
3983 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 3984 {
c19d1205
ZW
3985 val = parse_reloc (&str);
3986 if (val == -1)
3987 {
3988 inst.error = _("unrecognized relocation suffix");
3989 goto failure;
3990 }
3991 else if (val != BFD_RELOC_UNUSED)
3992 {
3993 inst.operands[i].imm = val;
3994 inst.operands[i].hasreloc = 1;
3995 }
a737bd4d 3996 }
c19d1205 3997 break;
a737bd4d 3998
c19d1205
ZW
3999 /* Register or expression */
4000 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
4001 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 4002
c19d1205
ZW
4003 /* Register or immediate */
4004 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
4005 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 4006
c19d1205
ZW
4007 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
4008 IF:
4009 if (!is_immediate_prefix (*str))
4010 goto bad_args;
4011 str++;
4012 val = parse_fpa_immediate (&str);
4013 if (val == FAIL)
4014 goto failure;
4015 /* FPA immediates are encoded as registers 8-15.
4016 parse_fpa_immediate has already applied the offset. */
4017 inst.operands[i].reg = val;
4018 inst.operands[i].isreg = 1;
4019 break;
09d92015 4020
c19d1205
ZW
4021 /* Two kinds of register */
4022 case OP_RIWR_RIWC:
4023 {
4024 struct reg_entry *rege = arm_reg_parse_multi (&str);
4025 if (rege->type != REG_TYPE_MMXWR
4026 && rege->type != REG_TYPE_MMXWC
4027 && rege->type != REG_TYPE_MMXWCG)
4028 {
4029 inst.error = _("iWMMXt data or control register expected");
4030 goto failure;
4031 }
4032 inst.operands[i].reg = rege->number;
4033 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
4034 }
4035 break;
09d92015 4036
c19d1205
ZW
4037 /* Misc */
4038 case OP_CPSF: val = parse_cps_flags (&str); break;
4039 case OP_ENDI: val = parse_endian_specifier (&str); break;
4040 case OP_oROR: val = parse_ror (&str); break;
4041 case OP_PSR: val = parse_psr (&str); break;
4042 case OP_COND: val = parse_cond (&str); break;
62b3e311 4043 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 4044
92e90b6e
PB
4045 case OP_TB:
4046 po_misc_or_fail (parse_tb (&str));
4047 break;
4048
c19d1205
ZW
4049 /* Register lists */
4050 case OP_REGLST:
4051 val = parse_reg_list (&str);
4052 if (*str == '^')
4053 {
4054 inst.operands[1].writeback = 1;
4055 str++;
4056 }
4057 break;
09d92015 4058
c19d1205
ZW
4059 case OP_VRSLST:
4060 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 0);
4061 break;
09d92015 4062
c19d1205
ZW
4063 case OP_VRDLST:
4064 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, 1);
4065 break;
a737bd4d 4066
c19d1205
ZW
4067 /* Addressing modes */
4068 case OP_ADDR:
4069 po_misc_or_fail (parse_address (&str, i));
4070 break;
09d92015 4071
c19d1205
ZW
4072 case OP_SH:
4073 po_misc_or_fail (parse_shifter_operand (&str, i));
4074 break;
09d92015 4075
c19d1205
ZW
4076 case OP_oSHll:
4077 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
4078 break;
09d92015 4079
c19d1205
ZW
4080 case OP_oSHar:
4081 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
4082 break;
09d92015 4083
c19d1205
ZW
4084 case OP_oSHllar:
4085 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
4086 break;
09d92015 4087
c19d1205
ZW
4088 default:
4089 as_fatal ("unhandled operand code %d", upat[i]);
4090 }
09d92015 4091
c19d1205
ZW
4092 /* Various value-based sanity checks and shared operations. We
4093 do not signal immediate failures for the register constraints;
4094 this allows a syntax error to take precedence. */
4095 switch (upat[i])
4096 {
4097 case OP_oRRnpc:
4098 case OP_RRnpc:
4099 case OP_RRnpcb:
4100 case OP_RRw:
4101 case OP_RRnpc_I0:
4102 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
4103 inst.error = BAD_PC;
4104 break;
09d92015 4105
c19d1205
ZW
4106 case OP_CPSF:
4107 case OP_ENDI:
4108 case OP_oROR:
4109 case OP_PSR:
4110 case OP_COND:
62b3e311 4111 case OP_oBARRIER:
c19d1205
ZW
4112 case OP_REGLST:
4113 case OP_VRSLST:
4114 case OP_VRDLST:
4115 if (val == FAIL)
4116 goto failure;
4117 inst.operands[i].imm = val;
4118 break;
a737bd4d 4119
c19d1205
ZW
4120 default:
4121 break;
4122 }
09d92015 4123
c19d1205
ZW
4124 /* If we get here, this operand was successfully parsed. */
4125 inst.operands[i].present = 1;
4126 continue;
09d92015 4127
c19d1205 4128 bad_args:
09d92015 4129 inst.error = BAD_ARGS;
c19d1205
ZW
4130
4131 failure:
4132 if (!backtrack_pos)
4133 return FAIL;
4134
4135 /* Do not backtrack over a trailing optional argument that
4136 absorbed some text. We will only fail again, with the
4137 'garbage following instruction' error message, which is
4138 probably less helpful than the current one. */
4139 if (backtrack_index == i && backtrack_pos != str
4140 && upat[i+1] == OP_stop)
4141 return FAIL;
4142
4143 /* Try again, skipping the optional argument at backtrack_pos. */
4144 str = backtrack_pos;
4145 inst.error = backtrack_error;
4146 inst.operands[backtrack_index].present = 0;
4147 i = backtrack_index;
4148 backtrack_pos = 0;
09d92015 4149 }
09d92015 4150
c19d1205
ZW
4151 /* Check that we have parsed all the arguments. */
4152 if (*str != '\0' && !inst.error)
4153 inst.error = _("garbage following instruction");
09d92015 4154
c19d1205 4155 return inst.error ? FAIL : SUCCESS;
09d92015
MM
4156}
4157
c19d1205
ZW
4158#undef po_char_or_fail
4159#undef po_reg_or_fail
4160#undef po_reg_or_goto
4161#undef po_imm_or_fail
4162\f
4163/* Shorthand macro for instruction encoding functions issuing errors. */
4164#define constraint(expr, err) do { \
4165 if (expr) \
4166 { \
4167 inst.error = err; \
4168 return; \
4169 } \
4170} while (0)
4171
4172/* Functions for operand encoding. ARM, then Thumb. */
4173
4174#define rotate_left(v, n) (v << n | v >> (32 - n))
4175
4176/* If VAL can be encoded in the immediate field of an ARM instruction,
4177 return the encoded form. Otherwise, return FAIL. */
4178
4179static unsigned int
4180encode_arm_immediate (unsigned int val)
09d92015 4181{
c19d1205
ZW
4182 unsigned int a, i;
4183
4184 for (i = 0; i < 32; i += 2)
4185 if ((a = rotate_left (val, i)) <= 0xff)
4186 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
4187
4188 return FAIL;
09d92015
MM
4189}
4190
c19d1205
ZW
4191/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
4192 return the encoded form. Otherwise, return FAIL. */
4193static unsigned int
4194encode_thumb32_immediate (unsigned int val)
09d92015 4195{
c19d1205 4196 unsigned int a, i;
09d92015 4197
9c3c69f2 4198 if (val <= 0xff)
c19d1205 4199 return val;
a737bd4d 4200
9c3c69f2 4201 for (i = 1; i <= 24; i++)
09d92015 4202 {
9c3c69f2
PB
4203 a = val >> i;
4204 if ((val & ~(0xff << i)) == 0)
4205 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 4206 }
a737bd4d 4207
c19d1205
ZW
4208 a = val & 0xff;
4209 if (val == ((a << 16) | a))
4210 return 0x100 | a;
4211 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
4212 return 0x300 | a;
09d92015 4213
c19d1205
ZW
4214 a = val & 0xff00;
4215 if (val == ((a << 16) | a))
4216 return 0x200 | (a >> 8);
a737bd4d 4217
c19d1205 4218 return FAIL;
09d92015 4219}
c19d1205 4220/* Encode a VFP SP register number into inst.instruction. */
09d92015
MM
4221
4222static void
c19d1205 4223encode_arm_vfp_sp_reg (int reg, enum vfp_sp_reg_pos pos)
09d92015 4224{
c19d1205 4225 switch (pos)
09d92015 4226 {
c19d1205
ZW
4227 case VFP_REG_Sd:
4228 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
4229 break;
4230
4231 case VFP_REG_Sn:
4232 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
4233 break;
4234
4235 case VFP_REG_Sm:
4236 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
4237 break;
4238
4239 default:
4240 abort ();
09d92015 4241 }
09d92015
MM
4242}
4243
c19d1205 4244/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 4245 if any, is handled by md_apply_fix. */
09d92015 4246static void
c19d1205 4247encode_arm_shift (int i)
09d92015 4248{
c19d1205
ZW
4249 if (inst.operands[i].shift_kind == SHIFT_RRX)
4250 inst.instruction |= SHIFT_ROR << 5;
4251 else
09d92015 4252 {
c19d1205
ZW
4253 inst.instruction |= inst.operands[i].shift_kind << 5;
4254 if (inst.operands[i].immisreg)
4255 {
4256 inst.instruction |= SHIFT_BY_REG;
4257 inst.instruction |= inst.operands[i].imm << 8;
4258 }
4259 else
4260 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 4261 }
c19d1205 4262}
09d92015 4263
c19d1205
ZW
4264static void
4265encode_arm_shifter_operand (int i)
4266{
4267 if (inst.operands[i].isreg)
09d92015 4268 {
c19d1205
ZW
4269 inst.instruction |= inst.operands[i].reg;
4270 encode_arm_shift (i);
09d92015 4271 }
c19d1205
ZW
4272 else
4273 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
4274}
4275
c19d1205 4276/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 4277static void
c19d1205 4278encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 4279{
c19d1205
ZW
4280 assert (inst.operands[i].isreg);
4281 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4282
c19d1205 4283 if (inst.operands[i].preind)
09d92015 4284 {
c19d1205
ZW
4285 if (is_t)
4286 {
4287 inst.error = _("instruction does not accept preindexed addressing");
4288 return;
4289 }
4290 inst.instruction |= PRE_INDEX;
4291 if (inst.operands[i].writeback)
4292 inst.instruction |= WRITE_BACK;
09d92015 4293
c19d1205
ZW
4294 }
4295 else if (inst.operands[i].postind)
4296 {
4297 assert (inst.operands[i].writeback);
4298 if (is_t)
4299 inst.instruction |= WRITE_BACK;
4300 }
4301 else /* unindexed - only for coprocessor */
09d92015 4302 {
c19d1205 4303 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
4304 return;
4305 }
4306
c19d1205
ZW
4307 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
4308 && (((inst.instruction & 0x000f0000) >> 16)
4309 == ((inst.instruction & 0x0000f000) >> 12)))
4310 as_warn ((inst.instruction & LOAD_BIT)
4311 ? _("destination register same as write-back base")
4312 : _("source register same as write-back base"));
09d92015
MM
4313}
4314
c19d1205
ZW
4315/* inst.operands[i] was set up by parse_address. Encode it into an
4316 ARM-format mode 2 load or store instruction. If is_t is true,
4317 reject forms that cannot be used with a T instruction (i.e. not
4318 post-indexed). */
a737bd4d 4319static void
c19d1205 4320encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 4321{
c19d1205 4322 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4323
c19d1205 4324 if (inst.operands[i].immisreg)
09d92015 4325 {
c19d1205
ZW
4326 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
4327 inst.instruction |= inst.operands[i].imm;
4328 if (!inst.operands[i].negative)
4329 inst.instruction |= INDEX_UP;
4330 if (inst.operands[i].shifted)
4331 {
4332 if (inst.operands[i].shift_kind == SHIFT_RRX)
4333 inst.instruction |= SHIFT_ROR << 5;
4334 else
4335 {
4336 inst.instruction |= inst.operands[i].shift_kind << 5;
4337 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
4338 }
4339 }
09d92015 4340 }
c19d1205 4341 else /* immediate offset in inst.reloc */
09d92015 4342 {
c19d1205
ZW
4343 if (inst.reloc.type == BFD_RELOC_UNUSED)
4344 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 4345 }
09d92015
MM
4346}
4347
c19d1205
ZW
4348/* inst.operands[i] was set up by parse_address. Encode it into an
4349 ARM-format mode 3 load or store instruction. Reject forms that
4350 cannot be used with such instructions. If is_t is true, reject
4351 forms that cannot be used with a T instruction (i.e. not
4352 post-indexed). */
4353static void
4354encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 4355{
c19d1205 4356 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 4357 {
c19d1205
ZW
4358 inst.error = _("instruction does not accept scaled register index");
4359 return;
09d92015 4360 }
a737bd4d 4361
c19d1205 4362 encode_arm_addr_mode_common (i, is_t);
a737bd4d 4363
c19d1205
ZW
4364 if (inst.operands[i].immisreg)
4365 {
4366 inst.instruction |= inst.operands[i].imm;
4367 if (!inst.operands[i].negative)
4368 inst.instruction |= INDEX_UP;
4369 }
4370 else /* immediate offset in inst.reloc */
4371 {
4372 inst.instruction |= HWOFFSET_IMM;
4373 if (inst.reloc.type == BFD_RELOC_UNUSED)
4374 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 4375 }
a737bd4d
NC
4376}
4377
c19d1205
ZW
4378/* inst.operands[i] was set up by parse_address. Encode it into an
4379 ARM-format instruction. Reject all forms which cannot be encoded
4380 into a coprocessor load/store instruction. If wb_ok is false,
4381 reject use of writeback; if unind_ok is false, reject use of
4382 unindexed addressing. If reloc_override is not 0, use it instead
4383 of BFD_ARM_CP_OFF_IMM. */
09d92015 4384
c19d1205
ZW
4385static int
4386encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 4387{
c19d1205 4388 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 4389
c19d1205 4390 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 4391
c19d1205 4392 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 4393 {
c19d1205
ZW
4394 assert (!inst.operands[i].writeback);
4395 if (!unind_ok)
4396 {
4397 inst.error = _("instruction does not support unindexed addressing");
4398 return FAIL;
4399 }
4400 inst.instruction |= inst.operands[i].imm;
4401 inst.instruction |= INDEX_UP;
4402 return SUCCESS;
09d92015 4403 }
a737bd4d 4404
c19d1205
ZW
4405 if (inst.operands[i].preind)
4406 inst.instruction |= PRE_INDEX;
a737bd4d 4407
c19d1205 4408 if (inst.operands[i].writeback)
09d92015 4409 {
c19d1205
ZW
4410 if (inst.operands[i].reg == REG_PC)
4411 {
4412 inst.error = _("pc may not be used with write-back");
4413 return FAIL;
4414 }
4415 if (!wb_ok)
4416 {
4417 inst.error = _("instruction does not support writeback");
4418 return FAIL;
4419 }
4420 inst.instruction |= WRITE_BACK;
09d92015 4421 }
a737bd4d 4422
c19d1205
ZW
4423 if (reloc_override)
4424 inst.reloc.type = reloc_override;
8f06b2d8
PB
4425 else if (thumb_mode)
4426 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
09d92015 4427 else
c19d1205 4428 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205
ZW
4429 return SUCCESS;
4430}
a737bd4d 4431
c19d1205
ZW
4432/* inst.reloc.exp describes an "=expr" load pseudo-operation.
4433 Determine whether it can be performed with a move instruction; if
4434 it can, convert inst.instruction to that move instruction and
4435 return 1; if it can't, convert inst.instruction to a literal-pool
4436 load and return 0. If this is not a valid thing to do in the
4437 current context, set inst.error and return 1.
a737bd4d 4438
c19d1205
ZW
4439 inst.operands[i] describes the destination register. */
4440
4441static int
4442move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
4443{
4444 if ((inst.instruction & (thumb_p ? THUMB_LOAD_BIT : LOAD_BIT)) == 0)
09d92015 4445 {
c19d1205
ZW
4446 inst.error = _("invalid pseudo operation");
4447 return 1;
09d92015 4448 }
c19d1205 4449 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
4450 {
4451 inst.error = _("constant expression expected");
c19d1205 4452 return 1;
09d92015 4453 }
c19d1205 4454 if (inst.reloc.exp.X_op == O_constant)
09d92015 4455 {
c19d1205
ZW
4456 if (thumb_p)
4457 {
4458 if ((inst.reloc.exp.X_add_number & ~0xFF) == 0)
4459 {
4460 /* This can be done with a mov(1) instruction. */
4461 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
4462 inst.instruction |= inst.reloc.exp.X_add_number;
4463 return 1;
4464 }
4465 }
4466 else
4467 {
4468 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
4469 if (value != FAIL)
4470 {
4471 /* This can be done with a mov instruction. */
4472 inst.instruction &= LITERAL_MASK;
4473 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
4474 inst.instruction |= value & 0xfff;
4475 return 1;
4476 }
09d92015 4477
c19d1205
ZW
4478 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
4479 if (value != FAIL)
4480 {
4481 /* This can be done with a mvn instruction. */
4482 inst.instruction &= LITERAL_MASK;
4483 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
4484 inst.instruction |= value & 0xfff;
4485 return 1;
4486 }
4487 }
09d92015
MM
4488 }
4489
c19d1205
ZW
4490 if (add_to_lit_pool () == FAIL)
4491 {
4492 inst.error = _("literal pool insertion failed");
4493 return 1;
4494 }
4495 inst.operands[1].reg = REG_PC;
4496 inst.operands[1].isreg = 1;
4497 inst.operands[1].preind = 1;
4498 inst.reloc.pc_rel = 1;
4499 inst.reloc.type = (thumb_p
4500 ? BFD_RELOC_ARM_THUMB_OFFSET
4501 : (mode_3
4502 ? BFD_RELOC_ARM_HWLITERAL
4503 : BFD_RELOC_ARM_LITERAL));
4504 return 0;
09d92015
MM
4505}
4506
c19d1205
ZW
4507/* Functions for instruction encoding, sorted by subarchitecture.
4508 First some generics; their names are taken from the conventional
4509 bit positions for register arguments in ARM format instructions. */
09d92015 4510
a737bd4d 4511static void
c19d1205 4512do_noargs (void)
09d92015 4513{
c19d1205 4514}
a737bd4d 4515
c19d1205
ZW
4516static void
4517do_rd (void)
4518{
4519 inst.instruction |= inst.operands[0].reg << 12;
4520}
a737bd4d 4521
c19d1205
ZW
4522static void
4523do_rd_rm (void)
4524{
4525 inst.instruction |= inst.operands[0].reg << 12;
4526 inst.instruction |= inst.operands[1].reg;
4527}
09d92015 4528
c19d1205
ZW
4529static void
4530do_rd_rn (void)
4531{
4532 inst.instruction |= inst.operands[0].reg << 12;
4533 inst.instruction |= inst.operands[1].reg << 16;
4534}
a737bd4d 4535
c19d1205
ZW
4536static void
4537do_rn_rd (void)
4538{
4539 inst.instruction |= inst.operands[0].reg << 16;
4540 inst.instruction |= inst.operands[1].reg << 12;
4541}
09d92015 4542
c19d1205
ZW
4543static void
4544do_rd_rm_rn (void)
4545{
9a64e435
PB
4546 unsigned Rn = inst.operands[2].reg;
4547 /* Enforce resutrictions on SWP instruction. */
4548 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
4549 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
4550 _("Rn must not overlap other operands"));
c19d1205
ZW
4551 inst.instruction |= inst.operands[0].reg << 12;
4552 inst.instruction |= inst.operands[1].reg;
9a64e435 4553 inst.instruction |= Rn << 16;
c19d1205 4554}
09d92015 4555
c19d1205
ZW
4556static void
4557do_rd_rn_rm (void)
4558{
4559 inst.instruction |= inst.operands[0].reg << 12;
4560 inst.instruction |= inst.operands[1].reg << 16;
4561 inst.instruction |= inst.operands[2].reg;
4562}
a737bd4d 4563
c19d1205
ZW
4564static void
4565do_rm_rd_rn (void)
4566{
4567 inst.instruction |= inst.operands[0].reg;
4568 inst.instruction |= inst.operands[1].reg << 12;
4569 inst.instruction |= inst.operands[2].reg << 16;
4570}
09d92015 4571
c19d1205
ZW
4572static void
4573do_imm0 (void)
4574{
4575 inst.instruction |= inst.operands[0].imm;
4576}
09d92015 4577
c19d1205
ZW
4578static void
4579do_rd_cpaddr (void)
4580{
4581 inst.instruction |= inst.operands[0].reg << 12;
4582 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 4583}
a737bd4d 4584
c19d1205
ZW
4585/* ARM instructions, in alphabetical order by function name (except
4586 that wrapper functions appear immediately after the function they
4587 wrap). */
09d92015 4588
c19d1205
ZW
4589/* This is a pseudo-op of the form "adr rd, label" to be converted
4590 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
4591
4592static void
c19d1205 4593do_adr (void)
09d92015 4594{
c19d1205 4595 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4596
c19d1205
ZW
4597 /* Frag hacking will turn this into a sub instruction if the offset turns
4598 out to be negative. */
4599 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 4600 inst.reloc.pc_rel = 1;
2fc8bdac 4601 inst.reloc.exp.X_add_number -= 8;
c19d1205 4602}
b99bd4ef 4603
c19d1205
ZW
4604/* This is a pseudo-op of the form "adrl rd, label" to be converted
4605 into a relative address of the form:
4606 add rd, pc, #low(label-.-8)"
4607 add rd, rd, #high(label-.-8)" */
b99bd4ef 4608
c19d1205
ZW
4609static void
4610do_adrl (void)
4611{
4612 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 4613
c19d1205
ZW
4614 /* Frag hacking will turn this into a sub instruction if the offset turns
4615 out to be negative. */
4616 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
4617 inst.reloc.pc_rel = 1;
4618 inst.size = INSN_SIZE * 2;
2fc8bdac 4619 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
4620}
4621
b99bd4ef 4622static void
c19d1205 4623do_arit (void)
b99bd4ef 4624{
c19d1205
ZW
4625 if (!inst.operands[1].present)
4626 inst.operands[1].reg = inst.operands[0].reg;
4627 inst.instruction |= inst.operands[0].reg << 12;
4628 inst.instruction |= inst.operands[1].reg << 16;
4629 encode_arm_shifter_operand (2);
4630}
b99bd4ef 4631
62b3e311
PB
4632static void
4633do_barrier (void)
4634{
4635 if (inst.operands[0].present)
4636 {
4637 constraint ((inst.instruction & 0xf0) != 0x40
4638 && inst.operands[0].imm != 0xf,
4639 "bad barrier type");
4640 inst.instruction |= inst.operands[0].imm;
4641 }
4642 else
4643 inst.instruction |= 0xf;
4644}
4645
c19d1205
ZW
4646static void
4647do_bfc (void)
4648{
4649 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
4650 constraint (msb > 32, _("bit-field extends past end of register"));
4651 /* The instruction encoding stores the LSB and MSB,
4652 not the LSB and width. */
4653 inst.instruction |= inst.operands[0].reg << 12;
4654 inst.instruction |= inst.operands[1].imm << 7;
4655 inst.instruction |= (msb - 1) << 16;
4656}
b99bd4ef 4657
c19d1205
ZW
4658static void
4659do_bfi (void)
4660{
4661 unsigned int msb;
b99bd4ef 4662
c19d1205
ZW
4663 /* #0 in second position is alternative syntax for bfc, which is
4664 the same instruction but with REG_PC in the Rm field. */
4665 if (!inst.operands[1].isreg)
4666 inst.operands[1].reg = REG_PC;
b99bd4ef 4667
c19d1205
ZW
4668 msb = inst.operands[2].imm + inst.operands[3].imm;
4669 constraint (msb > 32, _("bit-field extends past end of register"));
4670 /* The instruction encoding stores the LSB and MSB,
4671 not the LSB and width. */
4672 inst.instruction |= inst.operands[0].reg << 12;
4673 inst.instruction |= inst.operands[1].reg;
4674 inst.instruction |= inst.operands[2].imm << 7;
4675 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
4676}
4677
b99bd4ef 4678static void
c19d1205 4679do_bfx (void)
b99bd4ef 4680{
c19d1205
ZW
4681 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
4682 _("bit-field extends past end of register"));
4683 inst.instruction |= inst.operands[0].reg << 12;
4684 inst.instruction |= inst.operands[1].reg;
4685 inst.instruction |= inst.operands[2].imm << 7;
4686 inst.instruction |= (inst.operands[3].imm - 1) << 16;
4687}
09d92015 4688
c19d1205
ZW
4689/* ARM V5 breakpoint instruction (argument parse)
4690 BKPT <16 bit unsigned immediate>
4691 Instruction is not conditional.
4692 The bit pattern given in insns[] has the COND_ALWAYS condition,
4693 and it is an error if the caller tried to override that. */
b99bd4ef 4694
c19d1205
ZW
4695static void
4696do_bkpt (void)
4697{
4698 /* Top 12 of 16 bits to bits 19:8. */
4699 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 4700
c19d1205
ZW
4701 /* Bottom 4 of 16 bits to bits 3:0. */
4702 inst.instruction |= inst.operands[0].imm & 0xf;
4703}
09d92015 4704
c19d1205
ZW
4705static void
4706encode_branch (int default_reloc)
4707{
4708 if (inst.operands[0].hasreloc)
4709 {
4710 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
4711 _("the only suffix valid here is '(plt)'"));
4712 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 4713 }
b99bd4ef 4714 else
c19d1205
ZW
4715 {
4716 inst.reloc.type = default_reloc;
c19d1205 4717 }
2fc8bdac 4718 inst.reloc.pc_rel = 1;
b99bd4ef
NC
4719}
4720
b99bd4ef 4721static void
c19d1205 4722do_branch (void)
b99bd4ef 4723{
39b41c9c
PB
4724#ifdef OBJ_ELF
4725 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4726 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
4727 else
4728#endif
4729 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
4730}
4731
4732static void
4733do_bl (void)
4734{
4735#ifdef OBJ_ELF
4736 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4737 {
4738 if (inst.cond == COND_ALWAYS)
4739 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
4740 else
4741 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
4742 }
4743 else
4744#endif
4745 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 4746}
b99bd4ef 4747
c19d1205
ZW
4748/* ARM V5 branch-link-exchange instruction (argument parse)
4749 BLX <target_addr> ie BLX(1)
4750 BLX{<condition>} <Rm> ie BLX(2)
4751 Unfortunately, there are two different opcodes for this mnemonic.
4752 So, the insns[].value is not used, and the code here zaps values
4753 into inst.instruction.
4754 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 4755
c19d1205
ZW
4756static void
4757do_blx (void)
4758{
4759 if (inst.operands[0].isreg)
b99bd4ef 4760 {
c19d1205
ZW
4761 /* Arg is a register; the opcode provided by insns[] is correct.
4762 It is not illegal to do "blx pc", just useless. */
4763 if (inst.operands[0].reg == REG_PC)
4764 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 4765
c19d1205
ZW
4766 inst.instruction |= inst.operands[0].reg;
4767 }
4768 else
b99bd4ef 4769 {
c19d1205
ZW
4770 /* Arg is an address; this instruction cannot be executed
4771 conditionally, and the opcode must be adjusted. */
4772 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 4773 inst.instruction = 0xfa000000;
39b41c9c
PB
4774#ifdef OBJ_ELF
4775 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
4776 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
4777 else
4778#endif
4779 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 4780 }
c19d1205
ZW
4781}
4782
4783static void
4784do_bx (void)
4785{
4786 if (inst.operands[0].reg == REG_PC)
4787 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 4788
c19d1205 4789 inst.instruction |= inst.operands[0].reg;
09d92015
MM
4790}
4791
c19d1205
ZW
4792
4793/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
4794
4795static void
c19d1205 4796do_bxj (void)
a737bd4d 4797{
c19d1205
ZW
4798 if (inst.operands[0].reg == REG_PC)
4799 as_tsktsk (_("use of r15 in bxj is not really useful"));
4800
4801 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
4802}
4803
c19d1205
ZW
4804/* Co-processor data operation:
4805 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
4806 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
4807static void
4808do_cdp (void)
4809{
4810 inst.instruction |= inst.operands[0].reg << 8;
4811 inst.instruction |= inst.operands[1].imm << 20;
4812 inst.instruction |= inst.operands[2].reg << 12;
4813 inst.instruction |= inst.operands[3].reg << 16;
4814 inst.instruction |= inst.operands[4].reg;
4815 inst.instruction |= inst.operands[5].imm << 5;
4816}
a737bd4d
NC
4817
4818static void
c19d1205 4819do_cmp (void)
a737bd4d 4820{
c19d1205
ZW
4821 inst.instruction |= inst.operands[0].reg << 16;
4822 encode_arm_shifter_operand (1);
a737bd4d
NC
4823}
4824
c19d1205
ZW
4825/* Transfer between coprocessor and ARM registers.
4826 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
4827 MRC2
4828 MCR{cond}
4829 MCR2
4830
4831 No special properties. */
09d92015
MM
4832
4833static void
c19d1205 4834do_co_reg (void)
09d92015 4835{
c19d1205
ZW
4836 inst.instruction |= inst.operands[0].reg << 8;
4837 inst.instruction |= inst.operands[1].imm << 21;
4838 inst.instruction |= inst.operands[2].reg << 12;
4839 inst.instruction |= inst.operands[3].reg << 16;
4840 inst.instruction |= inst.operands[4].reg;
4841 inst.instruction |= inst.operands[5].imm << 5;
4842}
09d92015 4843
c19d1205
ZW
4844/* Transfer between coprocessor register and pair of ARM registers.
4845 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
4846 MCRR2
4847 MRRC{cond}
4848 MRRC2
b99bd4ef 4849
c19d1205 4850 Two XScale instructions are special cases of these:
09d92015 4851
c19d1205
ZW
4852 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
4853 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 4854
c19d1205 4855 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 4856
c19d1205
ZW
4857static void
4858do_co_reg2c (void)
4859{
4860 inst.instruction |= inst.operands[0].reg << 8;
4861 inst.instruction |= inst.operands[1].imm << 4;
4862 inst.instruction |= inst.operands[2].reg << 12;
4863 inst.instruction |= inst.operands[3].reg << 16;
4864 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
4865}
4866
c19d1205
ZW
4867static void
4868do_cpsi (void)
4869{
4870 inst.instruction |= inst.operands[0].imm << 6;
4871 inst.instruction |= inst.operands[1].imm;
4872}
b99bd4ef 4873
62b3e311
PB
4874static void
4875do_dbg (void)
4876{
4877 inst.instruction |= inst.operands[0].imm;
4878}
4879
b99bd4ef 4880static void
c19d1205 4881do_it (void)
b99bd4ef 4882{
c19d1205
ZW
4883 /* There is no IT instruction in ARM mode. We
4884 process it but do not generate code for it. */
4885 inst.size = 0;
09d92015 4886}
b99bd4ef 4887
09d92015 4888static void
c19d1205 4889do_ldmstm (void)
ea6ef066 4890{
c19d1205
ZW
4891 int base_reg = inst.operands[0].reg;
4892 int range = inst.operands[1].imm;
ea6ef066 4893
c19d1205
ZW
4894 inst.instruction |= base_reg << 16;
4895 inst.instruction |= range;
ea6ef066 4896
c19d1205
ZW
4897 if (inst.operands[1].writeback)
4898 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 4899
c19d1205 4900 if (inst.operands[0].writeback)
ea6ef066 4901 {
c19d1205
ZW
4902 inst.instruction |= WRITE_BACK;
4903 /* Check for unpredictable uses of writeback. */
4904 if (inst.instruction & LOAD_BIT)
09d92015 4905 {
c19d1205
ZW
4906 /* Not allowed in LDM type 2. */
4907 if ((inst.instruction & LDM_TYPE_2_OR_3)
4908 && ((range & (1 << REG_PC)) == 0))
4909 as_warn (_("writeback of base register is UNPREDICTABLE"));
4910 /* Only allowed if base reg not in list for other types. */
4911 else if (range & (1 << base_reg))
4912 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
4913 }
4914 else /* STM. */
4915 {
4916 /* Not allowed for type 2. */
4917 if (inst.instruction & LDM_TYPE_2_OR_3)
4918 as_warn (_("writeback of base register is UNPREDICTABLE"));
4919 /* Only allowed if base reg not in list, or first in list. */
4920 else if ((range & (1 << base_reg))
4921 && (range & ((1 << base_reg) - 1)))
4922 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 4923 }
ea6ef066 4924 }
a737bd4d
NC
4925}
4926
c19d1205
ZW
4927/* ARMv5TE load-consecutive (argument parse)
4928 Mode is like LDRH.
4929
4930 LDRccD R, mode
4931 STRccD R, mode. */
4932
a737bd4d 4933static void
c19d1205 4934do_ldrd (void)
a737bd4d 4935{
c19d1205
ZW
4936 constraint (inst.operands[0].reg % 2 != 0,
4937 _("first destination register must be even"));
4938 constraint (inst.operands[1].present
4939 && inst.operands[1].reg != inst.operands[0].reg + 1,
4940 _("can only load two consecutive registers"));
4941 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
4942 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 4943
c19d1205
ZW
4944 if (!inst.operands[1].present)
4945 inst.operands[1].reg = inst.operands[0].reg + 1;
4946
4947 if (inst.instruction & LOAD_BIT)
a737bd4d 4948 {
c19d1205
ZW
4949 /* encode_arm_addr_mode_3 will diagnose overlap between the base
4950 register and the first register written; we have to diagnose
4951 overlap between the base and the second register written here. */
ea6ef066 4952
c19d1205
ZW
4953 if (inst.operands[2].reg == inst.operands[1].reg
4954 && (inst.operands[2].writeback || inst.operands[2].postind))
4955 as_warn (_("base register written back, and overlaps "
4956 "second destination register"));
b05fe5cf 4957
c19d1205
ZW
4958 /* For an index-register load, the index register must not overlap the
4959 destination (even if not write-back). */
4960 else if (inst.operands[2].immisreg
ca3f61f7
NC
4961 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
4962 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 4963 as_warn (_("index register overlaps destination register"));
b05fe5cf 4964 }
c19d1205
ZW
4965
4966 inst.instruction |= inst.operands[0].reg << 12;
4967 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
4968}
4969
4970static void
c19d1205 4971do_ldrex (void)
b05fe5cf 4972{
c19d1205
ZW
4973 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
4974 || inst.operands[1].postind || inst.operands[1].writeback
4975 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
4976 || inst.operands[1].negative
4977 /* This can arise if the programmer has written
4978 strex rN, rM, foo
4979 or if they have mistakenly used a register name as the last
4980 operand, eg:
4981 strex rN, rM, rX
4982 It is very difficult to distinguish between these two cases
4983 because "rX" might actually be a label. ie the register
4984 name has been occluded by a symbol of the same name. So we
4985 just generate a general 'bad addressing mode' type error
4986 message and leave it up to the programmer to discover the
4987 true cause and fix their mistake. */
4988 || (inst.operands[1].reg == REG_PC),
4989 BAD_ADDR_MODE);
b05fe5cf 4990
c19d1205
ZW
4991 constraint (inst.reloc.exp.X_op != O_constant
4992 || inst.reloc.exp.X_add_number != 0,
4993 _("offset must be zero in ARM encoding"));
b05fe5cf 4994
c19d1205
ZW
4995 inst.instruction |= inst.operands[0].reg << 12;
4996 inst.instruction |= inst.operands[1].reg << 16;
4997 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
4998}
4999
5000static void
c19d1205 5001do_ldrexd (void)
b05fe5cf 5002{
c19d1205
ZW
5003 constraint (inst.operands[0].reg % 2 != 0,
5004 _("even register required"));
5005 constraint (inst.operands[1].present
5006 && inst.operands[1].reg != inst.operands[0].reg + 1,
5007 _("can only load two consecutive registers"));
5008 /* If op 1 were present and equal to PC, this function wouldn't
5009 have been called in the first place. */
5010 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 5011
c19d1205
ZW
5012 inst.instruction |= inst.operands[0].reg << 12;
5013 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
5014}
5015
5016static void
c19d1205 5017do_ldst (void)
b05fe5cf 5018{
c19d1205
ZW
5019 inst.instruction |= inst.operands[0].reg << 12;
5020 if (!inst.operands[1].isreg)
5021 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 5022 return;
c19d1205 5023 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
5024}
5025
5026static void
c19d1205 5027do_ldstt (void)
b05fe5cf 5028{
c19d1205
ZW
5029 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
5030 reject [Rn,...]. */
5031 if (inst.operands[1].preind)
b05fe5cf 5032 {
c19d1205
ZW
5033 constraint (inst.reloc.exp.X_op != O_constant ||
5034 inst.reloc.exp.X_add_number != 0,
5035 _("this instruction requires a post-indexed address"));
b05fe5cf 5036
c19d1205
ZW
5037 inst.operands[1].preind = 0;
5038 inst.operands[1].postind = 1;
5039 inst.operands[1].writeback = 1;
b05fe5cf 5040 }
c19d1205
ZW
5041 inst.instruction |= inst.operands[0].reg << 12;
5042 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
5043}
b05fe5cf 5044
c19d1205 5045/* Halfword and signed-byte load/store operations. */
b05fe5cf 5046
c19d1205
ZW
5047static void
5048do_ldstv4 (void)
5049{
5050 inst.instruction |= inst.operands[0].reg << 12;
5051 if (!inst.operands[1].isreg)
5052 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 5053 return;
c19d1205 5054 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
5055}
5056
5057static void
c19d1205 5058do_ldsttv4 (void)
b05fe5cf 5059{
c19d1205
ZW
5060 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
5061 reject [Rn,...]. */
5062 if (inst.operands[1].preind)
b05fe5cf 5063 {
c19d1205
ZW
5064 constraint (inst.reloc.exp.X_op != O_constant ||
5065 inst.reloc.exp.X_add_number != 0,
5066 _("this instruction requires a post-indexed address"));
b05fe5cf 5067
c19d1205
ZW
5068 inst.operands[1].preind = 0;
5069 inst.operands[1].postind = 1;
5070 inst.operands[1].writeback = 1;
b05fe5cf 5071 }
c19d1205
ZW
5072 inst.instruction |= inst.operands[0].reg << 12;
5073 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
5074}
b05fe5cf 5075
c19d1205
ZW
5076/* Co-processor register load/store.
5077 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
5078static void
5079do_lstc (void)
5080{
5081 inst.instruction |= inst.operands[0].reg << 8;
5082 inst.instruction |= inst.operands[1].reg << 12;
5083 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
5084}
5085
b05fe5cf 5086static void
c19d1205 5087do_mlas (void)
b05fe5cf 5088{
c19d1205
ZW
5089 /* This restriction does not apply to mls (nor to mla in v6, but
5090 that's hard to detect at present). */
5091 if (inst.operands[0].reg == inst.operands[1].reg
5092 && !(inst.instruction & 0x00400000))
5093 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 5094
c19d1205
ZW
5095 inst.instruction |= inst.operands[0].reg << 16;
5096 inst.instruction |= inst.operands[1].reg;
5097 inst.instruction |= inst.operands[2].reg << 8;
5098 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 5099
c19d1205 5100}
b05fe5cf 5101
c19d1205
ZW
5102static void
5103do_mov (void)
5104{
5105 inst.instruction |= inst.operands[0].reg << 12;
5106 encode_arm_shifter_operand (1);
5107}
b05fe5cf 5108
c19d1205
ZW
5109/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
5110static void
5111do_mov16 (void)
5112{
5113 inst.instruction |= inst.operands[0].reg << 12;
b05fe5cf 5114 /* The value is in two pieces: 0:11, 16:19. */
c19d1205
ZW
5115 inst.instruction |= (inst.operands[1].imm & 0x00000fff);
5116 inst.instruction |= (inst.operands[1].imm & 0x0000f000) << 4;
b05fe5cf 5117}
b99bd4ef
NC
5118
5119static void
c19d1205 5120do_mrs (void)
b99bd4ef 5121{
c19d1205
ZW
5122 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
5123 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
5124 != (PSR_c|PSR_f),
5125 _("'CPSR' or 'SPSR' expected"));
5126 inst.instruction |= inst.operands[0].reg << 12;
5127 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
5128}
b99bd4ef 5129
c19d1205
ZW
5130/* Two possible forms:
5131 "{C|S}PSR_<field>, Rm",
5132 "{C|S}PSR_f, #expression". */
b99bd4ef 5133
c19d1205
ZW
5134static void
5135do_msr (void)
5136{
5137 inst.instruction |= inst.operands[0].imm;
5138 if (inst.operands[1].isreg)
5139 inst.instruction |= inst.operands[1].reg;
5140 else
b99bd4ef 5141 {
c19d1205
ZW
5142 inst.instruction |= INST_IMMEDIATE;
5143 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5144 inst.reloc.pc_rel = 0;
b99bd4ef 5145 }
b99bd4ef
NC
5146}
5147
c19d1205
ZW
5148static void
5149do_mul (void)
a737bd4d 5150{
c19d1205
ZW
5151 if (!inst.operands[2].present)
5152 inst.operands[2].reg = inst.operands[0].reg;
5153 inst.instruction |= inst.operands[0].reg << 16;
5154 inst.instruction |= inst.operands[1].reg;
5155 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 5156
c19d1205
ZW
5157 if (inst.operands[0].reg == inst.operands[1].reg)
5158 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
5159}
5160
c19d1205
ZW
5161/* Long Multiply Parser
5162 UMULL RdLo, RdHi, Rm, Rs
5163 SMULL RdLo, RdHi, Rm, Rs
5164 UMLAL RdLo, RdHi, Rm, Rs
5165 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
5166
5167static void
c19d1205 5168do_mull (void)
b99bd4ef 5169{
c19d1205
ZW
5170 inst.instruction |= inst.operands[0].reg << 12;
5171 inst.instruction |= inst.operands[1].reg << 16;
5172 inst.instruction |= inst.operands[2].reg;
5173 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 5174
c19d1205
ZW
5175 /* rdhi, rdlo and rm must all be different. */
5176 if (inst.operands[0].reg == inst.operands[1].reg
5177 || inst.operands[0].reg == inst.operands[2].reg
5178 || inst.operands[1].reg == inst.operands[2].reg)
5179 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
5180}
b99bd4ef 5181
c19d1205
ZW
5182static void
5183do_nop (void)
5184{
5185 if (inst.operands[0].present)
5186 {
5187 /* Architectural NOP hints are CPSR sets with no bits selected. */
5188 inst.instruction &= 0xf0000000;
5189 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
5190 }
b99bd4ef
NC
5191}
5192
c19d1205
ZW
5193/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
5194 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
5195 Condition defaults to COND_ALWAYS.
5196 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
5197
5198static void
c19d1205 5199do_pkhbt (void)
b99bd4ef 5200{
c19d1205
ZW
5201 inst.instruction |= inst.operands[0].reg << 12;
5202 inst.instruction |= inst.operands[1].reg << 16;
5203 inst.instruction |= inst.operands[2].reg;
5204 if (inst.operands[3].present)
5205 encode_arm_shift (3);
5206}
b99bd4ef 5207
c19d1205 5208/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 5209
c19d1205
ZW
5210static void
5211do_pkhtb (void)
5212{
5213 if (!inst.operands[3].present)
b99bd4ef 5214 {
c19d1205
ZW
5215 /* If the shift specifier is omitted, turn the instruction
5216 into pkhbt rd, rm, rn. */
5217 inst.instruction &= 0xfff00010;
5218 inst.instruction |= inst.operands[0].reg << 12;
5219 inst.instruction |= inst.operands[1].reg;
5220 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5221 }
5222 else
5223 {
c19d1205
ZW
5224 inst.instruction |= inst.operands[0].reg << 12;
5225 inst.instruction |= inst.operands[1].reg << 16;
5226 inst.instruction |= inst.operands[2].reg;
5227 encode_arm_shift (3);
b99bd4ef
NC
5228 }
5229}
5230
c19d1205
ZW
5231/* ARMv5TE: Preload-Cache
5232
5233 PLD <addr_mode>
5234
5235 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
5236
5237static void
c19d1205 5238do_pld (void)
b99bd4ef 5239{
c19d1205
ZW
5240 constraint (!inst.operands[0].isreg,
5241 _("'[' expected after PLD mnemonic"));
5242 constraint (inst.operands[0].postind,
5243 _("post-indexed expression used in preload instruction"));
5244 constraint (inst.operands[0].writeback,
5245 _("writeback used in preload instruction"));
5246 constraint (!inst.operands[0].preind,
5247 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
5248 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5249}
b99bd4ef 5250
62b3e311
PB
5251/* ARMv7: PLI <addr_mode> */
5252static void
5253do_pli (void)
5254{
5255 constraint (!inst.operands[0].isreg,
5256 _("'[' expected after PLI mnemonic"));
5257 constraint (inst.operands[0].postind,
5258 _("post-indexed expression used in preload instruction"));
5259 constraint (inst.operands[0].writeback,
5260 _("writeback used in preload instruction"));
5261 constraint (!inst.operands[0].preind,
5262 _("unindexed addressing used in preload instruction"));
5263 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
5264 inst.instruction &= ~PRE_INDEX;
5265}
5266
c19d1205
ZW
5267static void
5268do_push_pop (void)
5269{
5270 inst.operands[1] = inst.operands[0];
5271 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
5272 inst.operands[0].isreg = 1;
5273 inst.operands[0].writeback = 1;
5274 inst.operands[0].reg = REG_SP;
5275 do_ldmstm ();
5276}
b99bd4ef 5277
c19d1205
ZW
5278/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
5279 word at the specified address and the following word
5280 respectively.
5281 Unconditionally executed.
5282 Error if Rn is R15. */
b99bd4ef 5283
c19d1205
ZW
5284static void
5285do_rfe (void)
5286{
5287 inst.instruction |= inst.operands[0].reg << 16;
5288 if (inst.operands[0].writeback)
5289 inst.instruction |= WRITE_BACK;
5290}
b99bd4ef 5291
c19d1205 5292/* ARM V6 ssat (argument parse). */
b99bd4ef 5293
c19d1205
ZW
5294static void
5295do_ssat (void)
5296{
5297 inst.instruction |= inst.operands[0].reg << 12;
5298 inst.instruction |= (inst.operands[1].imm - 1) << 16;
5299 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5300
c19d1205
ZW
5301 if (inst.operands[3].present)
5302 encode_arm_shift (3);
b99bd4ef
NC
5303}
5304
c19d1205 5305/* ARM V6 usat (argument parse). */
b99bd4ef
NC
5306
5307static void
c19d1205 5308do_usat (void)
b99bd4ef 5309{
c19d1205
ZW
5310 inst.instruction |= inst.operands[0].reg << 12;
5311 inst.instruction |= inst.operands[1].imm << 16;
5312 inst.instruction |= inst.operands[2].reg;
b99bd4ef 5313
c19d1205
ZW
5314 if (inst.operands[3].present)
5315 encode_arm_shift (3);
b99bd4ef
NC
5316}
5317
c19d1205 5318/* ARM V6 ssat16 (argument parse). */
09d92015
MM
5319
5320static void
c19d1205 5321do_ssat16 (void)
09d92015 5322{
c19d1205
ZW
5323 inst.instruction |= inst.operands[0].reg << 12;
5324 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
5325 inst.instruction |= inst.operands[2].reg;
09d92015
MM
5326}
5327
c19d1205
ZW
5328static void
5329do_usat16 (void)
a737bd4d 5330{
c19d1205
ZW
5331 inst.instruction |= inst.operands[0].reg << 12;
5332 inst.instruction |= inst.operands[1].imm << 16;
5333 inst.instruction |= inst.operands[2].reg;
5334}
a737bd4d 5335
c19d1205
ZW
5336/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
5337 preserving the other bits.
a737bd4d 5338
c19d1205
ZW
5339 setend <endian_specifier>, where <endian_specifier> is either
5340 BE or LE. */
a737bd4d 5341
c19d1205
ZW
5342static void
5343do_setend (void)
5344{
5345 if (inst.operands[0].imm)
5346 inst.instruction |= 0x200;
a737bd4d
NC
5347}
5348
5349static void
c19d1205 5350do_shift (void)
a737bd4d 5351{
c19d1205
ZW
5352 unsigned int Rm = (inst.operands[1].present
5353 ? inst.operands[1].reg
5354 : inst.operands[0].reg);
a737bd4d 5355
c19d1205
ZW
5356 inst.instruction |= inst.operands[0].reg << 12;
5357 inst.instruction |= Rm;
5358 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 5359 {
c19d1205
ZW
5360 inst.instruction |= inst.operands[2].reg << 8;
5361 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
5362 }
5363 else
c19d1205 5364 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
5365}
5366
09d92015 5367static void
3eb17e6b 5368do_smc (void)
09d92015 5369{
3eb17e6b 5370 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 5371 inst.reloc.pc_rel = 0;
09d92015
MM
5372}
5373
09d92015 5374static void
c19d1205 5375do_swi (void)
09d92015 5376{
c19d1205
ZW
5377 inst.reloc.type = BFD_RELOC_ARM_SWI;
5378 inst.reloc.pc_rel = 0;
09d92015
MM
5379}
5380
c19d1205
ZW
5381/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
5382 SMLAxy{cond} Rd,Rm,Rs,Rn
5383 SMLAWy{cond} Rd,Rm,Rs,Rn
5384 Error if any register is R15. */
e16bb312 5385
c19d1205
ZW
5386static void
5387do_smla (void)
e16bb312 5388{
c19d1205
ZW
5389 inst.instruction |= inst.operands[0].reg << 16;
5390 inst.instruction |= inst.operands[1].reg;
5391 inst.instruction |= inst.operands[2].reg << 8;
5392 inst.instruction |= inst.operands[3].reg << 12;
5393}
a737bd4d 5394
c19d1205
ZW
5395/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
5396 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
5397 Error if any register is R15.
5398 Warning if Rdlo == Rdhi. */
a737bd4d 5399
c19d1205
ZW
5400static void
5401do_smlal (void)
5402{
5403 inst.instruction |= inst.operands[0].reg << 12;
5404 inst.instruction |= inst.operands[1].reg << 16;
5405 inst.instruction |= inst.operands[2].reg;
5406 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 5407
c19d1205
ZW
5408 if (inst.operands[0].reg == inst.operands[1].reg)
5409 as_tsktsk (_("rdhi and rdlo must be different"));
5410}
a737bd4d 5411
c19d1205
ZW
5412/* ARM V5E (El Segundo) signed-multiply (argument parse)
5413 SMULxy{cond} Rd,Rm,Rs
5414 Error if any register is R15. */
a737bd4d 5415
c19d1205
ZW
5416static void
5417do_smul (void)
5418{
5419 inst.instruction |= inst.operands[0].reg << 16;
5420 inst.instruction |= inst.operands[1].reg;
5421 inst.instruction |= inst.operands[2].reg << 8;
5422}
a737bd4d 5423
c19d1205 5424/* ARM V6 srs (argument parse). */
a737bd4d 5425
c19d1205
ZW
5426static void
5427do_srs (void)
5428{
5429 inst.instruction |= inst.operands[0].imm;
5430 if (inst.operands[0].writeback)
5431 inst.instruction |= WRITE_BACK;
5432}
a737bd4d 5433
c19d1205 5434/* ARM V6 strex (argument parse). */
a737bd4d 5435
c19d1205
ZW
5436static void
5437do_strex (void)
5438{
5439 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
5440 || inst.operands[2].postind || inst.operands[2].writeback
5441 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
5442 || inst.operands[2].negative
5443 /* See comment in do_ldrex(). */
5444 || (inst.operands[2].reg == REG_PC),
5445 BAD_ADDR_MODE);
a737bd4d 5446
c19d1205
ZW
5447 constraint (inst.operands[0].reg == inst.operands[1].reg
5448 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 5449
c19d1205
ZW
5450 constraint (inst.reloc.exp.X_op != O_constant
5451 || inst.reloc.exp.X_add_number != 0,
5452 _("offset must be zero in ARM encoding"));
a737bd4d 5453
c19d1205
ZW
5454 inst.instruction |= inst.operands[0].reg << 12;
5455 inst.instruction |= inst.operands[1].reg;
5456 inst.instruction |= inst.operands[2].reg << 16;
5457 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
5458}
5459
5460static void
c19d1205 5461do_strexd (void)
e16bb312 5462{
c19d1205
ZW
5463 constraint (inst.operands[1].reg % 2 != 0,
5464 _("even register required"));
5465 constraint (inst.operands[2].present
5466 && inst.operands[2].reg != inst.operands[1].reg + 1,
5467 _("can only store two consecutive registers"));
5468 /* If op 2 were present and equal to PC, this function wouldn't
5469 have been called in the first place. */
5470 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 5471
c19d1205
ZW
5472 constraint (inst.operands[0].reg == inst.operands[1].reg
5473 || inst.operands[0].reg == inst.operands[1].reg + 1
5474 || inst.operands[0].reg == inst.operands[3].reg,
5475 BAD_OVERLAP);
e16bb312 5476
c19d1205
ZW
5477 inst.instruction |= inst.operands[0].reg << 12;
5478 inst.instruction |= inst.operands[1].reg;
5479 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
5480}
5481
c19d1205
ZW
5482/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
5483 extends it to 32-bits, and adds the result to a value in another
5484 register. You can specify a rotation by 0, 8, 16, or 24 bits
5485 before extracting the 16-bit value.
5486 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
5487 Condition defaults to COND_ALWAYS.
5488 Error if any register uses R15. */
5489
e16bb312 5490static void
c19d1205 5491do_sxtah (void)
e16bb312 5492{
c19d1205
ZW
5493 inst.instruction |= inst.operands[0].reg << 12;
5494 inst.instruction |= inst.operands[1].reg << 16;
5495 inst.instruction |= inst.operands[2].reg;
5496 inst.instruction |= inst.operands[3].imm << 10;
5497}
e16bb312 5498
c19d1205 5499/* ARM V6 SXTH.
e16bb312 5500
c19d1205
ZW
5501 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
5502 Condition defaults to COND_ALWAYS.
5503 Error if any register uses R15. */
e16bb312
NC
5504
5505static void
c19d1205 5506do_sxth (void)
e16bb312 5507{
c19d1205
ZW
5508 inst.instruction |= inst.operands[0].reg << 12;
5509 inst.instruction |= inst.operands[1].reg;
5510 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 5511}
c19d1205
ZW
5512\f
5513/* VFP instructions. In a logical order: SP variant first, monad
5514 before dyad, arithmetic then move then load/store. */
e16bb312
NC
5515
5516static void
c19d1205 5517do_vfp_sp_monadic (void)
e16bb312 5518{
c19d1205
ZW
5519 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5520 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5521}
5522
5523static void
c19d1205 5524do_vfp_sp_dyadic (void)
e16bb312 5525{
c19d1205
ZW
5526 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5527 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
5528 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5529}
5530
5531static void
c19d1205 5532do_vfp_sp_compare_z (void)
e16bb312 5533{
c19d1205 5534 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
5535}
5536
5537static void
c19d1205 5538do_vfp_dp_sp_cvt (void)
e16bb312 5539{
c19d1205
ZW
5540 inst.instruction |= inst.operands[0].reg << 12;
5541 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
5542}
5543
5544static void
c19d1205 5545do_vfp_sp_dp_cvt (void)
e16bb312 5546{
c19d1205
ZW
5547 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5548 inst.instruction |= inst.operands[1].reg;
e16bb312
NC
5549}
5550
5551static void
c19d1205 5552do_vfp_reg_from_sp (void)
e16bb312 5553{
c19d1205
ZW
5554 inst.instruction |= inst.operands[0].reg << 12;
5555 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
5556}
5557
5558static void
c19d1205 5559do_vfp_reg2_from_sp2 (void)
e16bb312 5560{
c19d1205
ZW
5561 constraint (inst.operands[2].imm != 2,
5562 _("only two consecutive VFP SP registers allowed here"));
5563 inst.instruction |= inst.operands[0].reg << 12;
5564 inst.instruction |= inst.operands[1].reg << 16;
5565 encode_arm_vfp_sp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
5566}
5567
5568static void
c19d1205 5569do_vfp_sp_from_reg (void)
e16bb312 5570{
c19d1205
ZW
5571 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sn);
5572 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
5573}
5574
5575static void
c19d1205 5576do_vfp_sp2_from_reg2 (void)
e16bb312 5577{
c19d1205
ZW
5578 constraint (inst.operands[0].imm != 2,
5579 _("only two consecutive VFP SP registers allowed here"));
5580 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sm);
5581 inst.instruction |= inst.operands[1].reg << 12;
5582 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
5583}
5584
5585static void
c19d1205 5586do_vfp_sp_ldst (void)
e16bb312 5587{
c19d1205
ZW
5588 encode_arm_vfp_sp_reg (inst.operands[0].reg, VFP_REG_Sd);
5589 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5590}
5591
5592static void
c19d1205 5593do_vfp_dp_ldst (void)
e16bb312 5594{
c19d1205
ZW
5595 inst.instruction |= inst.operands[0].reg << 12;
5596 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
5597}
5598
c19d1205 5599
e16bb312 5600static void
c19d1205 5601vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5602{
c19d1205
ZW
5603 if (inst.operands[0].writeback)
5604 inst.instruction |= WRITE_BACK;
5605 else
5606 constraint (ldstm_type != VFP_LDSTMIA,
5607 _("this addressing mode requires base-register writeback"));
5608 inst.instruction |= inst.operands[0].reg << 16;
5609 encode_arm_vfp_sp_reg (inst.operands[1].reg, VFP_REG_Sd);
5610 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
5611}
5612
5613static void
c19d1205 5614vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 5615{
c19d1205 5616 int count;
e16bb312 5617
c19d1205
ZW
5618 if (inst.operands[0].writeback)
5619 inst.instruction |= WRITE_BACK;
5620 else
5621 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
5622 _("this addressing mode requires base-register writeback"));
e16bb312 5623
c19d1205
ZW
5624 inst.instruction |= inst.operands[0].reg << 16;
5625 inst.instruction |= inst.operands[1].reg << 12;
e16bb312 5626
c19d1205
ZW
5627 count = inst.operands[1].imm << 1;
5628 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
5629 count += 1;
e16bb312 5630
c19d1205 5631 inst.instruction |= count;
e16bb312
NC
5632}
5633
5634static void
c19d1205 5635do_vfp_sp_ldstmia (void)
e16bb312 5636{
c19d1205 5637 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5638}
5639
5640static void
c19d1205 5641do_vfp_sp_ldstmdb (void)
e16bb312 5642{
c19d1205 5643 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5644}
5645
5646static void
c19d1205 5647do_vfp_dp_ldstmia (void)
e16bb312 5648{
c19d1205 5649 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
5650}
5651
5652static void
c19d1205 5653do_vfp_dp_ldstmdb (void)
e16bb312 5654{
c19d1205 5655 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
5656}
5657
5658static void
c19d1205 5659do_vfp_xp_ldstmia (void)
e16bb312 5660{
c19d1205
ZW
5661 vfp_dp_ldstm (VFP_LDSTMIAX);
5662}
e16bb312 5663
c19d1205
ZW
5664static void
5665do_vfp_xp_ldstmdb (void)
5666{
5667 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 5668}
c19d1205
ZW
5669\f
5670/* FPA instructions. Also in a logical order. */
e16bb312 5671
c19d1205
ZW
5672static void
5673do_fpa_cmp (void)
5674{
5675 inst.instruction |= inst.operands[0].reg << 16;
5676 inst.instruction |= inst.operands[1].reg;
5677}
b99bd4ef
NC
5678
5679static void
c19d1205 5680do_fpa_ldmstm (void)
b99bd4ef 5681{
c19d1205
ZW
5682 inst.instruction |= inst.operands[0].reg << 12;
5683 switch (inst.operands[1].imm)
5684 {
5685 case 1: inst.instruction |= CP_T_X; break;
5686 case 2: inst.instruction |= CP_T_Y; break;
5687 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
5688 case 4: break;
5689 default: abort ();
5690 }
b99bd4ef 5691
c19d1205
ZW
5692 if (inst.instruction & (PRE_INDEX | INDEX_UP))
5693 {
5694 /* The instruction specified "ea" or "fd", so we can only accept
5695 [Rn]{!}. The instruction does not really support stacking or
5696 unstacking, so we have to emulate these by setting appropriate
5697 bits and offsets. */
5698 constraint (inst.reloc.exp.X_op != O_constant
5699 || inst.reloc.exp.X_add_number != 0,
5700 _("this instruction does not support indexing"));
b99bd4ef 5701
c19d1205
ZW
5702 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
5703 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 5704
c19d1205
ZW
5705 if (!(inst.instruction & INDEX_UP))
5706 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 5707
c19d1205
ZW
5708 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
5709 {
5710 inst.operands[2].preind = 0;
5711 inst.operands[2].postind = 1;
5712 }
5713 }
b99bd4ef 5714
c19d1205 5715 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 5716}
c19d1205
ZW
5717\f
5718/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 5719
c19d1205
ZW
5720static void
5721do_iwmmxt_tandorc (void)
5722{
5723 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
5724}
b99bd4ef 5725
c19d1205
ZW
5726static void
5727do_iwmmxt_textrc (void)
5728{
5729 inst.instruction |= inst.operands[0].reg << 12;
5730 inst.instruction |= inst.operands[1].imm;
5731}
b99bd4ef
NC
5732
5733static void
c19d1205 5734do_iwmmxt_textrm (void)
b99bd4ef 5735{
c19d1205
ZW
5736 inst.instruction |= inst.operands[0].reg << 12;
5737 inst.instruction |= inst.operands[1].reg << 16;
5738 inst.instruction |= inst.operands[2].imm;
5739}
b99bd4ef 5740
c19d1205
ZW
5741static void
5742do_iwmmxt_tinsr (void)
5743{
5744 inst.instruction |= inst.operands[0].reg << 16;
5745 inst.instruction |= inst.operands[1].reg << 12;
5746 inst.instruction |= inst.operands[2].imm;
5747}
b99bd4ef 5748
c19d1205
ZW
5749static void
5750do_iwmmxt_tmia (void)
5751{
5752 inst.instruction |= inst.operands[0].reg << 5;
5753 inst.instruction |= inst.operands[1].reg;
5754 inst.instruction |= inst.operands[2].reg << 12;
5755}
b99bd4ef 5756
c19d1205
ZW
5757static void
5758do_iwmmxt_waligni (void)
5759{
5760 inst.instruction |= inst.operands[0].reg << 12;
5761 inst.instruction |= inst.operands[1].reg << 16;
5762 inst.instruction |= inst.operands[2].reg;
5763 inst.instruction |= inst.operands[3].imm << 20;
5764}
b99bd4ef 5765
c19d1205
ZW
5766static void
5767do_iwmmxt_wmov (void)
5768{
5769 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
5770 inst.instruction |= inst.operands[0].reg << 12;
5771 inst.instruction |= inst.operands[1].reg << 16;
5772 inst.instruction |= inst.operands[1].reg;
5773}
b99bd4ef 5774
c19d1205
ZW
5775static void
5776do_iwmmxt_wldstbh (void)
5777{
8f06b2d8 5778 int reloc;
c19d1205
ZW
5779 inst.instruction |= inst.operands[0].reg << 12;
5780 inst.reloc.exp.X_add_number *= 4;
8f06b2d8
PB
5781 if (thumb_mode)
5782 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
5783 else
5784 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
5785 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
5786}
5787
c19d1205
ZW
5788static void
5789do_iwmmxt_wldstw (void)
5790{
5791 /* RIWR_RIWC clears .isreg for a control register. */
5792 if (!inst.operands[0].isreg)
5793 {
5794 constraint (inst.cond != COND_ALWAYS, BAD_COND);
5795 inst.instruction |= 0xf0000000;
5796 }
b99bd4ef 5797
c19d1205
ZW
5798 inst.instruction |= inst.operands[0].reg << 12;
5799 encode_arm_cp_address (1, TRUE, TRUE, 0);
5800}
b99bd4ef
NC
5801
5802static void
c19d1205 5803do_iwmmxt_wldstd (void)
b99bd4ef 5804{
c19d1205 5805 inst.instruction |= inst.operands[0].reg << 12;
f2184508 5806 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 5807}
b99bd4ef 5808
c19d1205
ZW
5809static void
5810do_iwmmxt_wshufh (void)
5811{
5812 inst.instruction |= inst.operands[0].reg << 12;
5813 inst.instruction |= inst.operands[1].reg << 16;
5814 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
5815 inst.instruction |= (inst.operands[2].imm & 0x0f);
5816}
b99bd4ef 5817
c19d1205
ZW
5818static void
5819do_iwmmxt_wzero (void)
5820{
5821 /* WZERO reg is an alias for WANDN reg, reg, reg. */
5822 inst.instruction |= inst.operands[0].reg;
5823 inst.instruction |= inst.operands[0].reg << 12;
5824 inst.instruction |= inst.operands[0].reg << 16;
5825}
5826\f
5827/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
5828 operations first, then control, shift, and load/store. */
b99bd4ef 5829
c19d1205 5830/* Insns like "foo X,Y,Z". */
b99bd4ef 5831
c19d1205
ZW
5832static void
5833do_mav_triple (void)
5834{
5835 inst.instruction |= inst.operands[0].reg << 16;
5836 inst.instruction |= inst.operands[1].reg;
5837 inst.instruction |= inst.operands[2].reg << 12;
5838}
b99bd4ef 5839
c19d1205
ZW
5840/* Insns like "foo W,X,Y,Z".
5841 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 5842
c19d1205
ZW
5843static void
5844do_mav_quad (void)
5845{
5846 inst.instruction |= inst.operands[0].reg << 5;
5847 inst.instruction |= inst.operands[1].reg << 12;
5848 inst.instruction |= inst.operands[2].reg << 16;
5849 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
5850}
5851
c19d1205
ZW
5852/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
5853static void
5854do_mav_dspsc (void)
a737bd4d 5855{
c19d1205
ZW
5856 inst.instruction |= inst.operands[1].reg << 12;
5857}
a737bd4d 5858
c19d1205
ZW
5859/* Maverick shift immediate instructions.
5860 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
5861 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 5862
c19d1205
ZW
5863static void
5864do_mav_shift (void)
5865{
5866 int imm = inst.operands[2].imm;
a737bd4d 5867
c19d1205
ZW
5868 inst.instruction |= inst.operands[0].reg << 12;
5869 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 5870
c19d1205
ZW
5871 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
5872 Bits 5-7 of the insn should have bits 4-6 of the immediate.
5873 Bit 4 should be 0. */
5874 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 5875
c19d1205
ZW
5876 inst.instruction |= imm;
5877}
5878\f
5879/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 5880
c19d1205
ZW
5881/* Xscale multiply-accumulate (argument parse)
5882 MIAcc acc0,Rm,Rs
5883 MIAPHcc acc0,Rm,Rs
5884 MIAxycc acc0,Rm,Rs. */
a737bd4d 5885
c19d1205
ZW
5886static void
5887do_xsc_mia (void)
5888{
5889 inst.instruction |= inst.operands[1].reg;
5890 inst.instruction |= inst.operands[2].reg << 12;
5891}
a737bd4d 5892
c19d1205 5893/* Xscale move-accumulator-register (argument parse)
a737bd4d 5894
c19d1205 5895 MARcc acc0,RdLo,RdHi. */
b99bd4ef 5896
c19d1205
ZW
5897static void
5898do_xsc_mar (void)
5899{
5900 inst.instruction |= inst.operands[1].reg << 12;
5901 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
5902}
5903
c19d1205 5904/* Xscale move-register-accumulator (argument parse)
b99bd4ef 5905
c19d1205 5906 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
5907
5908static void
c19d1205 5909do_xsc_mra (void)
b99bd4ef 5910{
c19d1205
ZW
5911 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
5912 inst.instruction |= inst.operands[0].reg << 12;
5913 inst.instruction |= inst.operands[1].reg << 16;
5914}
5915\f
5916/* Encoding functions relevant only to Thumb. */
b99bd4ef 5917
c19d1205
ZW
5918/* inst.operands[i] is a shifted-register operand; encode
5919 it into inst.instruction in the format used by Thumb32. */
5920
5921static void
5922encode_thumb32_shifted_operand (int i)
5923{
5924 unsigned int value = inst.reloc.exp.X_add_number;
5925 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 5926
9c3c69f2
PB
5927 constraint (inst.operands[i].immisreg,
5928 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
5929 inst.instruction |= inst.operands[i].reg;
5930 if (shift == SHIFT_RRX)
5931 inst.instruction |= SHIFT_ROR << 4;
5932 else
b99bd4ef 5933 {
c19d1205
ZW
5934 constraint (inst.reloc.exp.X_op != O_constant,
5935 _("expression too complex"));
5936
5937 constraint (value > 32
5938 || (value == 32 && (shift == SHIFT_LSL
5939 || shift == SHIFT_ROR)),
5940 _("shift expression is too large"));
5941
5942 if (value == 0)
5943 shift = SHIFT_LSL;
5944 else if (value == 32)
5945 value = 0;
5946
5947 inst.instruction |= shift << 4;
5948 inst.instruction |= (value & 0x1c) << 10;
5949 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 5950 }
c19d1205 5951}
b99bd4ef 5952
b99bd4ef 5953
c19d1205
ZW
5954/* inst.operands[i] was set up by parse_address. Encode it into a
5955 Thumb32 format load or store instruction. Reject forms that cannot
5956 be used with such instructions. If is_t is true, reject forms that
5957 cannot be used with a T instruction; if is_d is true, reject forms
5958 that cannot be used with a D instruction. */
b99bd4ef 5959
c19d1205
ZW
5960static void
5961encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
5962{
5963 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
5964
5965 constraint (!inst.operands[i].isreg,
5966 _("Thumb does not support the ldr =N pseudo-operation"));
b99bd4ef 5967
c19d1205
ZW
5968 inst.instruction |= inst.operands[i].reg << 16;
5969 if (inst.operands[i].immisreg)
b99bd4ef 5970 {
c19d1205
ZW
5971 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
5972 constraint (is_t || is_d, _("cannot use register index with this instruction"));
5973 constraint (inst.operands[i].negative,
5974 _("Thumb does not support negative register indexing"));
5975 constraint (inst.operands[i].postind,
5976 _("Thumb does not support register post-indexing"));
5977 constraint (inst.operands[i].writeback,
5978 _("Thumb does not support register indexing with writeback"));
5979 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
5980 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 5981
f40d1643 5982 inst.instruction |= inst.operands[i].imm;
c19d1205 5983 if (inst.operands[i].shifted)
b99bd4ef 5984 {
c19d1205
ZW
5985 constraint (inst.reloc.exp.X_op != O_constant,
5986 _("expression too complex"));
9c3c69f2
PB
5987 constraint (inst.reloc.exp.X_add_number < 0
5988 || inst.reloc.exp.X_add_number > 3,
c19d1205 5989 _("shift out of range"));
9c3c69f2 5990 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
5991 }
5992 inst.reloc.type = BFD_RELOC_UNUSED;
5993 }
5994 else if (inst.operands[i].preind)
5995 {
5996 constraint (is_pc && inst.operands[i].writeback,
5997 _("cannot use writeback with PC-relative addressing"));
f40d1643 5998 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
5999 _("cannot use writeback with this instruction"));
6000
6001 if (is_d)
6002 {
6003 inst.instruction |= 0x01000000;
6004 if (inst.operands[i].writeback)
6005 inst.instruction |= 0x00200000;
b99bd4ef 6006 }
c19d1205 6007 else
b99bd4ef 6008 {
c19d1205
ZW
6009 inst.instruction |= 0x00000c00;
6010 if (inst.operands[i].writeback)
6011 inst.instruction |= 0x00000100;
b99bd4ef 6012 }
c19d1205 6013 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 6014 }
c19d1205 6015 else if (inst.operands[i].postind)
b99bd4ef 6016 {
c19d1205
ZW
6017 assert (inst.operands[i].writeback);
6018 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
6019 constraint (is_t, _("cannot use post-indexing with this instruction"));
6020
6021 if (is_d)
6022 inst.instruction |= 0x00200000;
6023 else
6024 inst.instruction |= 0x00000900;
6025 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
6026 }
6027 else /* unindexed - only for coprocessor */
6028 inst.error = _("instruction does not accept unindexed addressing");
6029}
6030
6031/* Table of Thumb instructions which exist in both 16- and 32-bit
6032 encodings (the latter only in post-V6T2 cores). The index is the
6033 value used in the insns table below. When there is more than one
6034 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
6035 holds variant (1).
6036 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
6037#define T16_32_TAB \
6038 X(adc, 4140, eb400000), \
6039 X(adcs, 4140, eb500000), \
6040 X(add, 1c00, eb000000), \
6041 X(adds, 1c00, eb100000), \
0110f2b8
PB
6042 X(addi, 0000, f1000000), \
6043 X(addis, 0000, f1100000), \
6044 X(add_pc,000f, f20f0000), \
6045 X(add_sp,000d, f10d0000), \
e9f89963 6046 X(adr, 000f, f20f0000), \
c19d1205
ZW
6047 X(and, 4000, ea000000), \
6048 X(ands, 4000, ea100000), \
6049 X(asr, 1000, fa40f000), \
6050 X(asrs, 1000, fa50f000), \
0110f2b8
PB
6051 X(b, e000, f000b000), \
6052 X(bcond, d000, f0008000), \
c19d1205
ZW
6053 X(bic, 4380, ea200000), \
6054 X(bics, 4380, ea300000), \
6055 X(cmn, 42c0, eb100f00), \
6056 X(cmp, 2800, ebb00f00), \
6057 X(cpsie, b660, f3af8400), \
6058 X(cpsid, b670, f3af8600), \
6059 X(cpy, 4600, ea4f0000), \
0110f2b8 6060 X(dec_sp,80dd, f1bd0d00), \
c19d1205
ZW
6061 X(eor, 4040, ea800000), \
6062 X(eors, 4040, ea900000), \
0110f2b8 6063 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
6064 X(ldmia, c800, e8900000), \
6065 X(ldr, 6800, f8500000), \
6066 X(ldrb, 7800, f8100000), \
6067 X(ldrh, 8800, f8300000), \
6068 X(ldrsb, 5600, f9100000), \
6069 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
6070 X(ldr_pc,4800, f85f0000), \
6071 X(ldr_pc2,4800, f85f0000), \
6072 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
6073 X(lsl, 0000, fa00f000), \
6074 X(lsls, 0000, fa10f000), \
6075 X(lsr, 0800, fa20f000), \
6076 X(lsrs, 0800, fa30f000), \
6077 X(mov, 2000, ea4f0000), \
6078 X(movs, 2000, ea5f0000), \
6079 X(mul, 4340, fb00f000), \
6080 X(muls, 4340, ffffffff), /* no 32b muls */ \
6081 X(mvn, 43c0, ea6f0000), \
6082 X(mvns, 43c0, ea7f0000), \
6083 X(neg, 4240, f1c00000), /* rsb #0 */ \
6084 X(negs, 4240, f1d00000), /* rsbs #0 */ \
6085 X(orr, 4300, ea400000), \
6086 X(orrs, 4300, ea500000), \
e9f89963
PB
6087 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
6088 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
6089 X(rev, ba00, fa90f080), \
6090 X(rev16, ba40, fa90f090), \
6091 X(revsh, bac0, fa90f0b0), \
6092 X(ror, 41c0, fa60f000), \
6093 X(rors, 41c0, fa70f000), \
6094 X(sbc, 4180, eb600000), \
6095 X(sbcs, 4180, eb700000), \
6096 X(stmia, c000, e8800000), \
6097 X(str, 6000, f8400000), \
6098 X(strb, 7000, f8000000), \
6099 X(strh, 8000, f8200000), \
0110f2b8 6100 X(str_sp,9000, f84d0000), \
c19d1205
ZW
6101 X(sub, 1e00, eba00000), \
6102 X(subs, 1e00, ebb00000), \
0110f2b8
PB
6103 X(subi, 8000, f1a00000), \
6104 X(subis, 8000, f1b00000), \
c19d1205
ZW
6105 X(sxtb, b240, fa4ff080), \
6106 X(sxth, b200, fa0ff080), \
6107 X(tst, 4200, ea100f00), \
6108 X(uxtb, b2c0, fa5ff080), \
6109 X(uxth, b280, fa1ff080), \
6110 X(nop, bf00, f3af8000), \
6111 X(yield, bf10, f3af8001), \
6112 X(wfe, bf20, f3af8002), \
6113 X(wfi, bf30, f3af8003), \
6114 X(sev, bf40, f3af9004), /* typo, 8004? */
6115
6116/* To catch errors in encoding functions, the codes are all offset by
6117 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
6118 as 16-bit instructions. */
6119#define X(a,b,c) T_MNEM_##a
6120enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
6121#undef X
6122
6123#define X(a,b,c) 0x##b
6124static const unsigned short thumb_op16[] = { T16_32_TAB };
6125#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
6126#undef X
6127
6128#define X(a,b,c) 0x##c
6129static const unsigned int thumb_op32[] = { T16_32_TAB };
6130#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
6131#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
6132#undef X
6133#undef T16_32_TAB
6134
6135/* Thumb instruction encoders, in alphabetical order. */
6136
92e90b6e
PB
6137/* ADDW or SUBW. */
6138static void
6139do_t_add_sub_w (void)
6140{
6141 int Rd, Rn;
6142
6143 Rd = inst.operands[0].reg;
6144 Rn = inst.operands[1].reg;
6145
6146 constraint (Rd == 15, _("PC not allowed as destination"));
6147 inst.instruction |= (Rn << 16) | (Rd << 8);
6148 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
6149}
6150
c19d1205
ZW
6151/* Parse an add or subtract instruction. We get here with inst.instruction
6152 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
6153
6154static void
6155do_t_add_sub (void)
6156{
6157 int Rd, Rs, Rn;
6158
6159 Rd = inst.operands[0].reg;
6160 Rs = (inst.operands[1].present
6161 ? inst.operands[1].reg /* Rd, Rs, foo */
6162 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6163
6164 if (unified_syntax)
6165 {
0110f2b8
PB
6166 bfd_boolean flags;
6167 bfd_boolean narrow;
6168 int opcode;
6169
6170 flags = (inst.instruction == T_MNEM_adds
6171 || inst.instruction == T_MNEM_subs);
6172 if (flags)
6173 narrow = (current_it_mask == 0);
6174 else
6175 narrow = (current_it_mask != 0);
c19d1205 6176 if (!inst.operands[2].isreg)
b99bd4ef 6177 {
0110f2b8
PB
6178 opcode = 0;
6179 if (inst.size_req != 4)
6180 {
6181 int add;
6182
6183 add = (inst.instruction == T_MNEM_add
6184 || inst.instruction == T_MNEM_adds);
6185 /* Attempt to use a narrow opcode, with relaxation if
6186 appropriate. */
6187 if (Rd == REG_SP && Rs == REG_SP && !flags)
6188 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
6189 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
6190 opcode = T_MNEM_add_sp;
6191 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
6192 opcode = T_MNEM_add_pc;
6193 else if (Rd <= 7 && Rs <= 7 && narrow)
6194 {
6195 if (flags)
6196 opcode = add ? T_MNEM_addis : T_MNEM_subis;
6197 else
6198 opcode = add ? T_MNEM_addi : T_MNEM_subi;
6199 }
6200 if (opcode)
6201 {
6202 inst.instruction = THUMB_OP16(opcode);
6203 inst.instruction |= (Rd << 4) | Rs;
6204 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6205 if (inst.size_req != 2)
6206 inst.relax = opcode;
6207 }
6208 else
6209 constraint (inst.size_req == 2, BAD_HIREG);
6210 }
6211 if (inst.size_req == 4
6212 || (inst.size_req != 2 && !opcode))
6213 {
6214 /* ??? Convert large immediates to addw/subw. */
6215 inst.instruction = THUMB_OP32 (inst.instruction);
6216 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6217 inst.instruction |= inst.operands[0].reg << 8;
6218 inst.instruction |= inst.operands[1].reg << 16;
6219 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6220 }
b99bd4ef 6221 }
c19d1205
ZW
6222 else
6223 {
6224 Rn = inst.operands[2].reg;
6225 /* See if we can do this with a 16-bit instruction. */
6226 if (!inst.operands[2].shifted && inst.size_req != 4)
6227 {
e27ec89e
PB
6228 if (Rd > 7 || Rs > 7 || Rn > 7)
6229 narrow = FALSE;
6230
6231 if (narrow)
c19d1205 6232 {
e27ec89e
PB
6233 inst.instruction = ((inst.instruction == T_MNEM_adds
6234 || inst.instruction == T_MNEM_add)
c19d1205
ZW
6235 ? T_OPCODE_ADD_R3
6236 : T_OPCODE_SUB_R3);
6237 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
6238 return;
6239 }
b99bd4ef 6240
c19d1205
ZW
6241 if (inst.instruction == T_MNEM_add)
6242 {
6243 if (Rd == Rs)
6244 {
6245 inst.instruction = T_OPCODE_ADD_HI;
6246 inst.instruction |= (Rd & 8) << 4;
6247 inst.instruction |= (Rd & 7);
6248 inst.instruction |= Rn << 3;
6249 return;
6250 }
6251 /* ... because addition is commutative! */
6252 else if (Rd == Rn)
6253 {
6254 inst.instruction = T_OPCODE_ADD_HI;
6255 inst.instruction |= (Rd & 8) << 4;
6256 inst.instruction |= (Rd & 7);
6257 inst.instruction |= Rs << 3;
6258 return;
6259 }
6260 }
6261 }
6262 /* If we get here, it can't be done in 16 bits. */
6263 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
6264 _("shift must be constant"));
6265 inst.instruction = THUMB_OP32 (inst.instruction);
6266 inst.instruction |= Rd << 8;
6267 inst.instruction |= Rs << 16;
6268 encode_thumb32_shifted_operand (2);
6269 }
6270 }
6271 else
6272 {
6273 constraint (inst.instruction == T_MNEM_adds
6274 || inst.instruction == T_MNEM_subs,
6275 BAD_THUMB32);
b99bd4ef 6276
c19d1205 6277 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 6278 {
c19d1205
ZW
6279 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
6280 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
6281 BAD_HIREG);
6282
6283 inst.instruction = (inst.instruction == T_MNEM_add
6284 ? 0x0000 : 0x8000);
6285 inst.instruction |= (Rd << 4) | Rs;
6286 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
6287 return;
6288 }
6289
c19d1205
ZW
6290 Rn = inst.operands[2].reg;
6291 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 6292
c19d1205
ZW
6293 /* We now have Rd, Rs, and Rn set to registers. */
6294 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 6295 {
c19d1205
ZW
6296 /* Can't do this for SUB. */
6297 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
6298 inst.instruction = T_OPCODE_ADD_HI;
6299 inst.instruction |= (Rd & 8) << 4;
6300 inst.instruction |= (Rd & 7);
6301 if (Rs == Rd)
6302 inst.instruction |= Rn << 3;
6303 else if (Rn == Rd)
6304 inst.instruction |= Rs << 3;
6305 else
6306 constraint (1, _("dest must overlap one source register"));
6307 }
6308 else
6309 {
6310 inst.instruction = (inst.instruction == T_MNEM_add
6311 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
6312 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 6313 }
b99bd4ef 6314 }
b99bd4ef
NC
6315}
6316
c19d1205
ZW
6317static void
6318do_t_adr (void)
6319{
0110f2b8
PB
6320 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
6321 {
6322 /* Defer to section relaxation. */
6323 inst.relax = inst.instruction;
6324 inst.instruction = THUMB_OP16 (inst.instruction);
6325 inst.instruction |= inst.operands[0].reg << 4;
6326 }
6327 else if (unified_syntax && inst.size_req != 2)
e9f89963 6328 {
0110f2b8 6329 /* Generate a 32-bit opcode. */
e9f89963
PB
6330 inst.instruction = THUMB_OP32 (inst.instruction);
6331 inst.instruction |= inst.operands[0].reg << 8;
6332 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
6333 inst.reloc.pc_rel = 1;
6334 }
6335 else
6336 {
0110f2b8 6337 /* Generate a 16-bit opcode. */
e9f89963
PB
6338 inst.instruction = THUMB_OP16 (inst.instruction);
6339 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
6340 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
6341 inst.reloc.pc_rel = 1;
b99bd4ef 6342
e9f89963
PB
6343 inst.instruction |= inst.operands[0].reg << 4;
6344 }
c19d1205 6345}
b99bd4ef 6346
c19d1205
ZW
6347/* Arithmetic instructions for which there is just one 16-bit
6348 instruction encoding, and it allows only two low registers.
6349 For maximal compatibility with ARM syntax, we allow three register
6350 operands even when Thumb-32 instructions are not available, as long
6351 as the first two are identical. For instance, both "sbc r0,r1" and
6352 "sbc r0,r0,r1" are allowed. */
b99bd4ef 6353static void
c19d1205 6354do_t_arit3 (void)
b99bd4ef 6355{
c19d1205 6356 int Rd, Rs, Rn;
b99bd4ef 6357
c19d1205
ZW
6358 Rd = inst.operands[0].reg;
6359 Rs = (inst.operands[1].present
6360 ? inst.operands[1].reg /* Rd, Rs, foo */
6361 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6362 Rn = inst.operands[2].reg;
b99bd4ef 6363
c19d1205 6364 if (unified_syntax)
b99bd4ef 6365 {
c19d1205
ZW
6366 if (!inst.operands[2].isreg)
6367 {
6368 /* For an immediate, we always generate a 32-bit opcode;
6369 section relaxation will shrink it later if possible. */
6370 inst.instruction = THUMB_OP32 (inst.instruction);
6371 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6372 inst.instruction |= Rd << 8;
6373 inst.instruction |= Rs << 16;
6374 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
6375 }
6376 else
6377 {
e27ec89e
PB
6378 bfd_boolean narrow;
6379
c19d1205 6380 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6381 if (THUMB_SETS_FLAGS (inst.instruction))
6382 narrow = current_it_mask == 0;
6383 else
6384 narrow = current_it_mask != 0;
6385
6386 if (Rd > 7 || Rn > 7 || Rs > 7)
6387 narrow = FALSE;
6388 if (inst.operands[2].shifted)
6389 narrow = FALSE;
6390 if (inst.size_req == 4)
6391 narrow = FALSE;
6392
6393 if (narrow
c19d1205
ZW
6394 && Rd == Rs)
6395 {
6396 inst.instruction = THUMB_OP16 (inst.instruction);
6397 inst.instruction |= Rd;
6398 inst.instruction |= Rn << 3;
6399 return;
6400 }
b99bd4ef 6401
c19d1205
ZW
6402 /* If we get here, it can't be done in 16 bits. */
6403 constraint (inst.operands[2].shifted
6404 && inst.operands[2].immisreg,
6405 _("shift must be constant"));
6406 inst.instruction = THUMB_OP32 (inst.instruction);
6407 inst.instruction |= Rd << 8;
6408 inst.instruction |= Rs << 16;
6409 encode_thumb32_shifted_operand (2);
6410 }
a737bd4d 6411 }
c19d1205 6412 else
b99bd4ef 6413 {
c19d1205
ZW
6414 /* On its face this is a lie - the instruction does set the
6415 flags. However, the only supported mnemonic in this mode
6416 says it doesn't. */
6417 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6418
c19d1205
ZW
6419 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6420 _("unshifted register required"));
6421 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6422 constraint (Rd != Rs,
6423 _("dest and source1 must be the same register"));
a737bd4d 6424
c19d1205
ZW
6425 inst.instruction = THUMB_OP16 (inst.instruction);
6426 inst.instruction |= Rd;
6427 inst.instruction |= Rn << 3;
b99bd4ef 6428 }
a737bd4d 6429}
b99bd4ef 6430
c19d1205
ZW
6431/* Similarly, but for instructions where the arithmetic operation is
6432 commutative, so we can allow either of them to be different from
6433 the destination operand in a 16-bit instruction. For instance, all
6434 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
6435 accepted. */
6436static void
6437do_t_arit3c (void)
a737bd4d 6438{
c19d1205 6439 int Rd, Rs, Rn;
b99bd4ef 6440
c19d1205
ZW
6441 Rd = inst.operands[0].reg;
6442 Rs = (inst.operands[1].present
6443 ? inst.operands[1].reg /* Rd, Rs, foo */
6444 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
6445 Rn = inst.operands[2].reg;
a737bd4d 6446
c19d1205 6447 if (unified_syntax)
a737bd4d 6448 {
c19d1205 6449 if (!inst.operands[2].isreg)
b99bd4ef 6450 {
c19d1205
ZW
6451 /* For an immediate, we always generate a 32-bit opcode;
6452 section relaxation will shrink it later if possible. */
6453 inst.instruction = THUMB_OP32 (inst.instruction);
6454 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
6455 inst.instruction |= Rd << 8;
6456 inst.instruction |= Rs << 16;
6457 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 6458 }
c19d1205 6459 else
a737bd4d 6460 {
e27ec89e
PB
6461 bfd_boolean narrow;
6462
c19d1205 6463 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
6464 if (THUMB_SETS_FLAGS (inst.instruction))
6465 narrow = current_it_mask == 0;
6466 else
6467 narrow = current_it_mask != 0;
6468
6469 if (Rd > 7 || Rn > 7 || Rs > 7)
6470 narrow = FALSE;
6471 if (inst.operands[2].shifted)
6472 narrow = FALSE;
6473 if (inst.size_req == 4)
6474 narrow = FALSE;
6475
6476 if (narrow)
a737bd4d 6477 {
c19d1205 6478 if (Rd == Rs)
a737bd4d 6479 {
c19d1205
ZW
6480 inst.instruction = THUMB_OP16 (inst.instruction);
6481 inst.instruction |= Rd;
6482 inst.instruction |= Rn << 3;
6483 return;
a737bd4d 6484 }
c19d1205 6485 if (Rd == Rn)
a737bd4d 6486 {
c19d1205
ZW
6487 inst.instruction = THUMB_OP16 (inst.instruction);
6488 inst.instruction |= Rd;
6489 inst.instruction |= Rs << 3;
6490 return;
a737bd4d
NC
6491 }
6492 }
c19d1205
ZW
6493
6494 /* If we get here, it can't be done in 16 bits. */
6495 constraint (inst.operands[2].shifted
6496 && inst.operands[2].immisreg,
6497 _("shift must be constant"));
6498 inst.instruction = THUMB_OP32 (inst.instruction);
6499 inst.instruction |= Rd << 8;
6500 inst.instruction |= Rs << 16;
6501 encode_thumb32_shifted_operand (2);
a737bd4d 6502 }
b99bd4ef 6503 }
c19d1205
ZW
6504 else
6505 {
6506 /* On its face this is a lie - the instruction does set the
6507 flags. However, the only supported mnemonic in this mode
6508 says it doesn't. */
6509 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 6510
c19d1205
ZW
6511 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
6512 _("unshifted register required"));
6513 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
6514
6515 inst.instruction = THUMB_OP16 (inst.instruction);
6516 inst.instruction |= Rd;
6517
6518 if (Rd == Rs)
6519 inst.instruction |= Rn << 3;
6520 else if (Rd == Rn)
6521 inst.instruction |= Rs << 3;
6522 else
6523 constraint (1, _("dest must overlap one source register"));
6524 }
a737bd4d
NC
6525}
6526
62b3e311
PB
6527static void
6528do_t_barrier (void)
6529{
6530 if (inst.operands[0].present)
6531 {
6532 constraint ((inst.instruction & 0xf0) != 0x40
6533 && inst.operands[0].imm != 0xf,
6534 "bad barrier type");
6535 inst.instruction |= inst.operands[0].imm;
6536 }
6537 else
6538 inst.instruction |= 0xf;
6539}
6540
c19d1205
ZW
6541static void
6542do_t_bfc (void)
a737bd4d 6543{
c19d1205
ZW
6544 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6545 constraint (msb > 32, _("bit-field extends past end of register"));
6546 /* The instruction encoding stores the LSB and MSB,
6547 not the LSB and width. */
6548 inst.instruction |= inst.operands[0].reg << 8;
6549 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
6550 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
6551 inst.instruction |= msb - 1;
b99bd4ef
NC
6552}
6553
c19d1205
ZW
6554static void
6555do_t_bfi (void)
b99bd4ef 6556{
c19d1205 6557 unsigned int msb;
b99bd4ef 6558
c19d1205
ZW
6559 /* #0 in second position is alternative syntax for bfc, which is
6560 the same instruction but with REG_PC in the Rm field. */
6561 if (!inst.operands[1].isreg)
6562 inst.operands[1].reg = REG_PC;
b99bd4ef 6563
c19d1205
ZW
6564 msb = inst.operands[2].imm + inst.operands[3].imm;
6565 constraint (msb > 32, _("bit-field extends past end of register"));
6566 /* The instruction encoding stores the LSB and MSB,
6567 not the LSB and width. */
6568 inst.instruction |= inst.operands[0].reg << 8;
6569 inst.instruction |= inst.operands[1].reg << 16;
6570 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6571 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6572 inst.instruction |= msb - 1;
b99bd4ef
NC
6573}
6574
c19d1205
ZW
6575static void
6576do_t_bfx (void)
b99bd4ef 6577{
c19d1205
ZW
6578 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6579 _("bit-field extends past end of register"));
6580 inst.instruction |= inst.operands[0].reg << 8;
6581 inst.instruction |= inst.operands[1].reg << 16;
6582 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
6583 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
6584 inst.instruction |= inst.operands[3].imm - 1;
6585}
b99bd4ef 6586
c19d1205
ZW
6587/* ARM V5 Thumb BLX (argument parse)
6588 BLX <target_addr> which is BLX(1)
6589 BLX <Rm> which is BLX(2)
6590 Unfortunately, there are two different opcodes for this mnemonic.
6591 So, the insns[].value is not used, and the code here zaps values
6592 into inst.instruction.
b99bd4ef 6593
c19d1205
ZW
6594 ??? How to take advantage of the additional two bits of displacement
6595 available in Thumb32 mode? Need new relocation? */
b99bd4ef 6596
c19d1205
ZW
6597static void
6598do_t_blx (void)
6599{
6600 if (inst.operands[0].isreg)
6601 /* We have a register, so this is BLX(2). */
6602 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
6603 else
6604 {
c19d1205 6605 /* No register. This must be BLX(1). */
2fc8bdac 6606 inst.instruction = 0xf000e800;
39b41c9c
PB
6607#ifdef OBJ_ELF
6608 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6609 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
6610 else
6611#endif
6612 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 6613 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6614 }
6615}
6616
c19d1205
ZW
6617static void
6618do_t_branch (void)
b99bd4ef 6619{
0110f2b8
PB
6620 int opcode;
6621 if (inst.cond != COND_ALWAYS)
6622 opcode = T_MNEM_bcond;
6623 else
6624 opcode = inst.instruction;
6625
6626 if (unified_syntax && inst.size_req == 4)
c19d1205 6627 {
0110f2b8 6628 inst.instruction = THUMB_OP32(opcode);
c19d1205 6629 if (inst.cond == COND_ALWAYS)
0110f2b8 6630 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
6631 else
6632 {
6633 assert (inst.cond != 0xF);
0110f2b8 6634 inst.instruction |= inst.cond << 22;
c19d1205
ZW
6635 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
6636 }
6637 }
b99bd4ef
NC
6638 else
6639 {
0110f2b8 6640 inst.instruction = THUMB_OP16(opcode);
c19d1205
ZW
6641 if (inst.cond == COND_ALWAYS)
6642 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
6643 else
b99bd4ef 6644 {
0110f2b8 6645 inst.instruction |= inst.cond << 8;
c19d1205 6646 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 6647 }
0110f2b8
PB
6648 /* Allow section relaxation. */
6649 if (unified_syntax && inst.size_req != 2)
6650 inst.relax = opcode;
b99bd4ef 6651 }
c19d1205
ZW
6652
6653 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6654}
6655
6656static void
c19d1205 6657do_t_bkpt (void)
b99bd4ef 6658{
c19d1205 6659 if (inst.operands[0].present)
b99bd4ef 6660 {
c19d1205
ZW
6661 constraint (inst.operands[0].imm > 255,
6662 _("immediate value out of range"));
6663 inst.instruction |= inst.operands[0].imm;
b99bd4ef 6664 }
b99bd4ef
NC
6665}
6666
6667static void
c19d1205 6668do_t_branch23 (void)
b99bd4ef 6669{
c19d1205 6670 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
6671 inst.reloc.pc_rel = 1;
6672
c19d1205
ZW
6673 /* If the destination of the branch is a defined symbol which does not have
6674 the THUMB_FUNC attribute, then we must be calling a function which has
6675 the (interfacearm) attribute. We look for the Thumb entry point to that
6676 function and change the branch to refer to that function instead. */
6677 if ( inst.reloc.exp.X_op == O_symbol
6678 && inst.reloc.exp.X_add_symbol != NULL
6679 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
6680 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
6681 inst.reloc.exp.X_add_symbol =
6682 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
6683}
6684
6685static void
c19d1205 6686do_t_bx (void)
90e4755a 6687{
c19d1205
ZW
6688 inst.instruction |= inst.operands[0].reg << 3;
6689 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
6690 should cause the alignment to be checked once it is known. This is
6691 because BX PC only works if the instruction is word aligned. */
6692}
90e4755a 6693
c19d1205
ZW
6694static void
6695do_t_bxj (void)
6696{
6697 if (inst.operands[0].reg == REG_PC)
6698 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 6699
c19d1205 6700 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
6701}
6702
6703static void
c19d1205 6704do_t_clz (void)
90e4755a 6705{
c19d1205
ZW
6706 inst.instruction |= inst.operands[0].reg << 8;
6707 inst.instruction |= inst.operands[1].reg << 16;
6708 inst.instruction |= inst.operands[1].reg;
6709}
90e4755a 6710
c19d1205
ZW
6711static void
6712do_t_cpsi (void)
6713{
6714 if (unified_syntax
62b3e311
PB
6715 && (inst.operands[1].present || inst.size_req == 4)
6716 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 6717 {
c19d1205
ZW
6718 unsigned int imod = (inst.instruction & 0x0030) >> 4;
6719 inst.instruction = 0xf3af8000;
6720 inst.instruction |= imod << 9;
6721 inst.instruction |= inst.operands[0].imm << 5;
6722 if (inst.operands[1].present)
6723 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 6724 }
c19d1205 6725 else
90e4755a 6726 {
62b3e311
PB
6727 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
6728 && (inst.operands[0].imm & 4),
6729 _("selected processor does not support 'A' form "
6730 "of this instruction"));
6731 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
6732 _("Thumb does not support the 2-argument "
6733 "form of this instruction"));
6734 inst.instruction |= inst.operands[0].imm;
90e4755a 6735 }
90e4755a
RE
6736}
6737
c19d1205
ZW
6738/* THUMB CPY instruction (argument parse). */
6739
90e4755a 6740static void
c19d1205 6741do_t_cpy (void)
90e4755a 6742{
c19d1205 6743 if (inst.size_req == 4)
90e4755a 6744 {
c19d1205
ZW
6745 inst.instruction = THUMB_OP32 (T_MNEM_mov);
6746 inst.instruction |= inst.operands[0].reg << 8;
6747 inst.instruction |= inst.operands[1].reg;
90e4755a 6748 }
c19d1205 6749 else
90e4755a 6750 {
c19d1205
ZW
6751 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
6752 inst.instruction |= (inst.operands[0].reg & 0x7);
6753 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 6754 }
90e4755a
RE
6755}
6756
90e4755a 6757static void
c19d1205 6758do_t_czb (void)
90e4755a 6759{
c19d1205
ZW
6760 constraint (inst.operands[0].reg > 7, BAD_HIREG);
6761 inst.instruction |= inst.operands[0].reg;
6762 inst.reloc.pc_rel = 1;
6763 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
6764}
90e4755a 6765
62b3e311
PB
6766static void
6767do_t_dbg (void)
6768{
6769 inst.instruction |= inst.operands[0].imm;
6770}
6771
6772static void
6773do_t_div (void)
6774{
6775 if (!inst.operands[1].present)
6776 inst.operands[1].reg = inst.operands[0].reg;
6777 inst.instruction |= inst.operands[0].reg << 8;
6778 inst.instruction |= inst.operands[1].reg << 16;
6779 inst.instruction |= inst.operands[2].reg;
6780}
6781
c19d1205
ZW
6782static void
6783do_t_hint (void)
6784{
6785 if (unified_syntax && inst.size_req == 4)
6786 inst.instruction = THUMB_OP32 (inst.instruction);
6787 else
6788 inst.instruction = THUMB_OP16 (inst.instruction);
6789}
90e4755a 6790
c19d1205
ZW
6791static void
6792do_t_it (void)
6793{
6794 unsigned int cond = inst.operands[0].imm;
e27ec89e
PB
6795
6796 current_it_mask = (inst.instruction & 0xf) | 0x10;
6797 current_cc = cond;
6798
6799 /* If the condition is a negative condition, invert the mask. */
c19d1205 6800 if ((cond & 0x1) == 0x0)
90e4755a 6801 {
c19d1205 6802 unsigned int mask = inst.instruction & 0x000f;
90e4755a 6803
c19d1205
ZW
6804 if ((mask & 0x7) == 0)
6805 /* no conversion needed */;
6806 else if ((mask & 0x3) == 0)
e27ec89e
PB
6807 mask ^= 0x8;
6808 else if ((mask & 0x1) == 0)
6809 mask ^= 0xC;
c19d1205 6810 else
e27ec89e 6811 mask ^= 0xE;
90e4755a 6812
e27ec89e
PB
6813 inst.instruction &= 0xfff0;
6814 inst.instruction |= mask;
c19d1205 6815 }
90e4755a 6816
c19d1205
ZW
6817 inst.instruction |= cond << 4;
6818}
90e4755a 6819
c19d1205
ZW
6820static void
6821do_t_ldmstm (void)
6822{
6823 /* This really doesn't seem worth it. */
6824 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
6825 _("expression too complex"));
6826 constraint (inst.operands[1].writeback,
6827 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 6828
c19d1205
ZW
6829 if (unified_syntax)
6830 {
6831 /* See if we can use a 16-bit instruction. */
6832 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
6833 && inst.size_req != 4
6834 && inst.operands[0].reg <= 7
6835 && !(inst.operands[1].imm & ~0xff)
6836 && (inst.instruction == T_MNEM_stmia
6837 ? inst.operands[0].writeback
6838 : (inst.operands[0].writeback
6839 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 6840 {
c19d1205
ZW
6841 if (inst.instruction == T_MNEM_stmia
6842 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
6843 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6844 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6845 inst.operands[0].reg);
90e4755a 6846
c19d1205
ZW
6847 inst.instruction = THUMB_OP16 (inst.instruction);
6848 inst.instruction |= inst.operands[0].reg << 8;
6849 inst.instruction |= inst.operands[1].imm;
6850 }
6851 else
6852 {
6853 if (inst.operands[1].imm & (1 << 13))
6854 as_warn (_("SP should not be in register list"));
6855 if (inst.instruction == T_MNEM_stmia)
90e4755a 6856 {
c19d1205
ZW
6857 if (inst.operands[1].imm & (1 << 15))
6858 as_warn (_("PC should not be in register list"));
6859 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
6860 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6861 inst.operands[0].reg);
90e4755a
RE
6862 }
6863 else
6864 {
c19d1205
ZW
6865 if (inst.operands[1].imm & (1 << 14)
6866 && inst.operands[1].imm & (1 << 15))
6867 as_warn (_("LR and PC should not both be in register list"));
6868 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6869 && inst.operands[0].writeback)
6870 as_warn (_("base register should not be in register list "
6871 "when written back"));
90e4755a 6872 }
c19d1205
ZW
6873 if (inst.instruction < 0xffff)
6874 inst.instruction = THUMB_OP32 (inst.instruction);
6875 inst.instruction |= inst.operands[0].reg << 16;
6876 inst.instruction |= inst.operands[1].imm;
6877 if (inst.operands[0].writeback)
6878 inst.instruction |= WRITE_BACK;
90e4755a
RE
6879 }
6880 }
c19d1205 6881 else
90e4755a 6882 {
c19d1205
ZW
6883 constraint (inst.operands[0].reg > 7
6884 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
6885 if (inst.instruction == T_MNEM_stmia)
f03698e6 6886 {
c19d1205
ZW
6887 if (!inst.operands[0].writeback)
6888 as_warn (_("this instruction will write back the base register"));
6889 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
6890 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
6891 as_warn (_("value stored for r%d is UNPREDICTABLE"),
6892 inst.operands[0].reg);
f03698e6 6893 }
c19d1205 6894 else
90e4755a 6895 {
c19d1205
ZW
6896 if (!inst.operands[0].writeback
6897 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
6898 as_warn (_("this instruction will write back the base register"));
6899 else if (inst.operands[0].writeback
6900 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
6901 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
6902 }
6903
c19d1205
ZW
6904 inst.instruction = THUMB_OP16 (inst.instruction);
6905 inst.instruction |= inst.operands[0].reg << 8;
6906 inst.instruction |= inst.operands[1].imm;
6907 }
6908}
e28cd48c 6909
c19d1205
ZW
6910static void
6911do_t_ldrex (void)
6912{
6913 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6914 || inst.operands[1].postind || inst.operands[1].writeback
6915 || inst.operands[1].immisreg || inst.operands[1].shifted
6916 || inst.operands[1].negative,
01cfc07f 6917 BAD_ADDR_MODE);
e28cd48c 6918
c19d1205
ZW
6919 inst.instruction |= inst.operands[0].reg << 12;
6920 inst.instruction |= inst.operands[1].reg << 16;
6921 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
6922}
e28cd48c 6923
c19d1205
ZW
6924static void
6925do_t_ldrexd (void)
6926{
6927 if (!inst.operands[1].present)
1cac9012 6928 {
c19d1205
ZW
6929 constraint (inst.operands[0].reg == REG_LR,
6930 _("r14 not allowed as first register "
6931 "when second register is omitted"));
6932 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 6933 }
c19d1205
ZW
6934 constraint (inst.operands[0].reg == inst.operands[1].reg,
6935 BAD_OVERLAP);
b99bd4ef 6936
c19d1205
ZW
6937 inst.instruction |= inst.operands[0].reg << 12;
6938 inst.instruction |= inst.operands[1].reg << 8;
6939 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
6940}
6941
6942static void
c19d1205 6943do_t_ldst (void)
b99bd4ef 6944{
0110f2b8
PB
6945 unsigned long opcode;
6946 int Rn;
6947
6948 opcode = inst.instruction;
c19d1205 6949 if (unified_syntax)
b99bd4ef 6950 {
0110f2b8
PB
6951 if (inst.operands[1].isreg
6952 && !inst.operands[1].writeback
c19d1205
ZW
6953 && !inst.operands[1].shifted && !inst.operands[1].postind
6954 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
6955 && opcode <= 0xffff
6956 && inst.size_req != 4)
c19d1205 6957 {
0110f2b8
PB
6958 /* Insn may have a 16-bit form. */
6959 Rn = inst.operands[1].reg;
6960 if (inst.operands[1].immisreg)
6961 {
6962 inst.instruction = THUMB_OP16 (opcode);
6963 /* [Rn, Ri] */
6964 if (Rn <= 7 && inst.operands[1].imm <= 7)
6965 goto op16;
6966 }
6967 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
6968 && opcode != T_MNEM_ldrsb)
6969 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
6970 || (Rn == REG_SP && opcode == T_MNEM_str))
6971 {
6972 /* [Rn, #const] */
6973 if (Rn > 7)
6974 {
6975 if (Rn == REG_PC)
6976 {
6977 if (inst.reloc.pc_rel)
6978 opcode = T_MNEM_ldr_pc2;
6979 else
6980 opcode = T_MNEM_ldr_pc;
6981 }
6982 else
6983 {
6984 if (opcode == T_MNEM_ldr)
6985 opcode = T_MNEM_ldr_sp;
6986 else
6987 opcode = T_MNEM_str_sp;
6988 }
6989 inst.instruction = inst.operands[0].reg << 8;
6990 }
6991 else
6992 {
6993 inst.instruction = inst.operands[0].reg;
6994 inst.instruction |= inst.operands[1].reg << 3;
6995 }
6996 inst.instruction |= THUMB_OP16 (opcode);
6997 if (inst.size_req == 2)
6998 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
6999 else
7000 inst.relax = opcode;
7001 return;
7002 }
c19d1205 7003 }
0110f2b8
PB
7004 /* Definitely a 32-bit variant. */
7005 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
7006 inst.instruction |= inst.operands[0].reg << 12;
7007 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
7008 return;
7009 }
7010
c19d1205
ZW
7011 constraint (inst.operands[0].reg > 7, BAD_HIREG);
7012
7013 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 7014 {
c19d1205
ZW
7015 /* Only [Rn,Rm] is acceptable. */
7016 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
7017 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
7018 || inst.operands[1].postind || inst.operands[1].shifted
7019 || inst.operands[1].negative,
7020 _("Thumb does not support this addressing mode"));
7021 inst.instruction = THUMB_OP16 (inst.instruction);
7022 goto op16;
b99bd4ef 7023 }
c19d1205
ZW
7024
7025 inst.instruction = THUMB_OP16 (inst.instruction);
7026 if (!inst.operands[1].isreg)
7027 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
7028 return;
b99bd4ef 7029
c19d1205
ZW
7030 constraint (!inst.operands[1].preind
7031 || inst.operands[1].shifted
7032 || inst.operands[1].writeback,
7033 _("Thumb does not support this addressing mode"));
7034 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 7035 {
c19d1205
ZW
7036 constraint (inst.instruction & 0x0600,
7037 _("byte or halfword not valid for base register"));
7038 constraint (inst.operands[1].reg == REG_PC
7039 && !(inst.instruction & THUMB_LOAD_BIT),
7040 _("r15 based store not allowed"));
7041 constraint (inst.operands[1].immisreg,
7042 _("invalid base register for register offset"));
b99bd4ef 7043
c19d1205
ZW
7044 if (inst.operands[1].reg == REG_PC)
7045 inst.instruction = T_OPCODE_LDR_PC;
7046 else if (inst.instruction & THUMB_LOAD_BIT)
7047 inst.instruction = T_OPCODE_LDR_SP;
7048 else
7049 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 7050
c19d1205
ZW
7051 inst.instruction |= inst.operands[0].reg << 8;
7052 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7053 return;
7054 }
90e4755a 7055
c19d1205
ZW
7056 constraint (inst.operands[1].reg > 7, BAD_HIREG);
7057 if (!inst.operands[1].immisreg)
7058 {
7059 /* Immediate offset. */
7060 inst.instruction |= inst.operands[0].reg;
7061 inst.instruction |= inst.operands[1].reg << 3;
7062 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
7063 return;
7064 }
90e4755a 7065
c19d1205
ZW
7066 /* Register offset. */
7067 constraint (inst.operands[1].imm > 7, BAD_HIREG);
7068 constraint (inst.operands[1].negative,
7069 _("Thumb does not support this addressing mode"));
90e4755a 7070
c19d1205
ZW
7071 op16:
7072 switch (inst.instruction)
7073 {
7074 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
7075 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
7076 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
7077 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
7078 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
7079 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
7080 case 0x5600 /* ldrsb */:
7081 case 0x5e00 /* ldrsh */: break;
7082 default: abort ();
7083 }
90e4755a 7084
c19d1205
ZW
7085 inst.instruction |= inst.operands[0].reg;
7086 inst.instruction |= inst.operands[1].reg << 3;
7087 inst.instruction |= inst.operands[1].imm << 6;
7088}
90e4755a 7089
c19d1205
ZW
7090static void
7091do_t_ldstd (void)
7092{
7093 if (!inst.operands[1].present)
b99bd4ef 7094 {
c19d1205
ZW
7095 inst.operands[1].reg = inst.operands[0].reg + 1;
7096 constraint (inst.operands[0].reg == REG_LR,
7097 _("r14 not allowed here"));
b99bd4ef 7098 }
c19d1205
ZW
7099 inst.instruction |= inst.operands[0].reg << 12;
7100 inst.instruction |= inst.operands[1].reg << 8;
7101 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
7102
b99bd4ef
NC
7103}
7104
c19d1205
ZW
7105static void
7106do_t_ldstt (void)
7107{
7108 inst.instruction |= inst.operands[0].reg << 12;
7109 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
7110}
a737bd4d 7111
b99bd4ef 7112static void
c19d1205 7113do_t_mla (void)
b99bd4ef 7114{
c19d1205
ZW
7115 inst.instruction |= inst.operands[0].reg << 8;
7116 inst.instruction |= inst.operands[1].reg << 16;
7117 inst.instruction |= inst.operands[2].reg;
7118 inst.instruction |= inst.operands[3].reg << 12;
7119}
b99bd4ef 7120
c19d1205
ZW
7121static void
7122do_t_mlal (void)
7123{
7124 inst.instruction |= inst.operands[0].reg << 12;
7125 inst.instruction |= inst.operands[1].reg << 8;
7126 inst.instruction |= inst.operands[2].reg << 16;
7127 inst.instruction |= inst.operands[3].reg;
7128}
b99bd4ef 7129
c19d1205
ZW
7130static void
7131do_t_mov_cmp (void)
7132{
7133 if (unified_syntax)
b99bd4ef 7134 {
c19d1205
ZW
7135 int r0off = (inst.instruction == T_MNEM_mov
7136 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 7137 unsigned long opcode;
3d388997
PB
7138 bfd_boolean narrow;
7139 bfd_boolean low_regs;
7140
7141 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 7142 opcode = inst.instruction;
3d388997 7143 if (current_it_mask)
0110f2b8 7144 narrow = opcode != T_MNEM_movs;
3d388997 7145 else
0110f2b8 7146 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
7147 if (inst.size_req == 4
7148 || inst.operands[1].shifted)
7149 narrow = FALSE;
7150
c19d1205
ZW
7151 if (!inst.operands[1].isreg)
7152 {
0110f2b8
PB
7153 /* Immediate operand. */
7154 if (current_it_mask == 0 && opcode == T_MNEM_mov)
7155 narrow = 0;
7156 if (low_regs && narrow)
7157 {
7158 inst.instruction = THUMB_OP16 (opcode);
7159 inst.instruction |= inst.operands[0].reg << 8;
7160 if (inst.size_req == 2)
7161 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7162 else
7163 inst.relax = opcode;
7164 }
7165 else
7166 {
7167 inst.instruction = THUMB_OP32 (inst.instruction);
7168 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7169 inst.instruction |= inst.operands[0].reg << r0off;
7170 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7171 }
c19d1205 7172 }
3d388997 7173 else if (!narrow)
c19d1205
ZW
7174 {
7175 inst.instruction = THUMB_OP32 (inst.instruction);
7176 inst.instruction |= inst.operands[0].reg << r0off;
7177 encode_thumb32_shifted_operand (1);
7178 }
7179 else
7180 switch (inst.instruction)
7181 {
7182 case T_MNEM_mov:
7183 inst.instruction = T_OPCODE_MOV_HR;
7184 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
7185 inst.instruction |= (inst.operands[0].reg & 0x7);
7186 inst.instruction |= inst.operands[1].reg << 3;
7187 break;
b99bd4ef 7188
c19d1205
ZW
7189 case T_MNEM_movs:
7190 /* We know we have low registers at this point.
7191 Generate ADD Rd, Rs, #0. */
7192 inst.instruction = T_OPCODE_ADD_I3;
7193 inst.instruction |= inst.operands[0].reg;
7194 inst.instruction |= inst.operands[1].reg << 3;
7195 break;
7196
7197 case T_MNEM_cmp:
3d388997 7198 if (low_regs)
c19d1205
ZW
7199 {
7200 inst.instruction = T_OPCODE_CMP_LR;
7201 inst.instruction |= inst.operands[0].reg;
7202 inst.instruction |= inst.operands[1].reg << 3;
7203 }
7204 else
7205 {
7206 inst.instruction = T_OPCODE_CMP_HR;
7207 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
7208 inst.instruction |= (inst.operands[0].reg & 0x7);
7209 inst.instruction |= inst.operands[1].reg << 3;
7210 }
7211 break;
7212 }
b99bd4ef
NC
7213 return;
7214 }
7215
c19d1205
ZW
7216 inst.instruction = THUMB_OP16 (inst.instruction);
7217 if (inst.operands[1].isreg)
b99bd4ef 7218 {
c19d1205 7219 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 7220 {
c19d1205
ZW
7221 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
7222 since a MOV instruction produces unpredictable results. */
7223 if (inst.instruction == T_OPCODE_MOV_I8)
7224 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 7225 else
c19d1205 7226 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 7227
c19d1205
ZW
7228 inst.instruction |= inst.operands[0].reg;
7229 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7230 }
7231 else
7232 {
c19d1205
ZW
7233 if (inst.instruction == T_OPCODE_MOV_I8)
7234 inst.instruction = T_OPCODE_MOV_HR;
7235 else
7236 inst.instruction = T_OPCODE_CMP_HR;
7237 do_t_cpy ();
b99bd4ef
NC
7238 }
7239 }
c19d1205 7240 else
b99bd4ef 7241 {
c19d1205
ZW
7242 constraint (inst.operands[0].reg > 7,
7243 _("only lo regs allowed with immediate"));
7244 inst.instruction |= inst.operands[0].reg << 8;
7245 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
7246 }
7247}
b99bd4ef 7248
c19d1205
ZW
7249static void
7250do_t_mov16 (void)
7251{
7252 inst.instruction |= inst.operands[0].reg << 8;
7253 inst.instruction |= (inst.operands[1].imm & 0xf000) << 4;
7254 inst.instruction |= (inst.operands[1].imm & 0x0800) << 15;
7255 inst.instruction |= (inst.operands[1].imm & 0x0700) << 4;
7256 inst.instruction |= (inst.operands[1].imm & 0x00ff);
7257}
b99bd4ef 7258
c19d1205
ZW
7259static void
7260do_t_mvn_tst (void)
7261{
7262 if (unified_syntax)
7263 {
7264 int r0off = (inst.instruction == T_MNEM_mvn
7265 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
7266 bfd_boolean narrow;
7267
7268 if (inst.size_req == 4
7269 || inst.instruction > 0xffff
7270 || inst.operands[1].shifted
7271 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7272 narrow = FALSE;
7273 else if (inst.instruction == T_MNEM_cmn)
7274 narrow = TRUE;
7275 else if (THUMB_SETS_FLAGS (inst.instruction))
7276 narrow = (current_it_mask == 0);
7277 else
7278 narrow = (current_it_mask != 0);
7279
c19d1205 7280 if (!inst.operands[1].isreg)
b99bd4ef 7281 {
c19d1205
ZW
7282 /* For an immediate, we always generate a 32-bit opcode;
7283 section relaxation will shrink it later if possible. */
7284 if (inst.instruction < 0xffff)
7285 inst.instruction = THUMB_OP32 (inst.instruction);
7286 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7287 inst.instruction |= inst.operands[0].reg << r0off;
7288 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 7289 }
c19d1205 7290 else
b99bd4ef 7291 {
c19d1205 7292 /* See if we can do this with a 16-bit instruction. */
3d388997 7293 if (narrow)
b99bd4ef 7294 {
c19d1205
ZW
7295 inst.instruction = THUMB_OP16 (inst.instruction);
7296 inst.instruction |= inst.operands[0].reg;
7297 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7298 }
c19d1205 7299 else
b99bd4ef 7300 {
c19d1205
ZW
7301 constraint (inst.operands[1].shifted
7302 && inst.operands[1].immisreg,
7303 _("shift must be constant"));
7304 if (inst.instruction < 0xffff)
7305 inst.instruction = THUMB_OP32 (inst.instruction);
7306 inst.instruction |= inst.operands[0].reg << r0off;
7307 encode_thumb32_shifted_operand (1);
b99bd4ef 7308 }
b99bd4ef
NC
7309 }
7310 }
7311 else
7312 {
c19d1205
ZW
7313 constraint (inst.instruction > 0xffff
7314 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
7315 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
7316 _("unshifted register required"));
7317 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7318 BAD_HIREG);
b99bd4ef 7319
c19d1205
ZW
7320 inst.instruction = THUMB_OP16 (inst.instruction);
7321 inst.instruction |= inst.operands[0].reg;
7322 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7323 }
b99bd4ef
NC
7324}
7325
b05fe5cf 7326static void
c19d1205 7327do_t_mrs (void)
b05fe5cf 7328{
62b3e311
PB
7329 int flags;
7330 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
7331 if (flags == 0)
7332 {
7333 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
7334 _("selected processor does not support "
7335 "requested special purpose register"));
7336 }
7337 else
7338 {
7339 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
7340 _("selected processor does not support "
7341 "requested special purpose register %x"));
7342 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7343 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
7344 _("'CPSR' or 'SPSR' expected"));
7345 }
7346
c19d1205 7347 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
7348 inst.instruction |= (flags & SPSR_BIT) >> 2;
7349 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 7350}
b05fe5cf 7351
c19d1205
ZW
7352static void
7353do_t_msr (void)
7354{
62b3e311
PB
7355 int flags;
7356
c19d1205
ZW
7357 constraint (!inst.operands[1].isreg,
7358 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
7359 flags = inst.operands[0].imm;
7360 if (flags & ~0xff)
7361 {
7362 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
7363 _("selected processor does not support "
7364 "requested special purpose register"));
7365 }
7366 else
7367 {
7368 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
7369 _("selected processor does not support "
7370 "requested special purpose register"));
7371 flags |= PSR_f;
7372 }
7373 inst.instruction |= (flags & SPSR_BIT) >> 2;
7374 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
7375 inst.instruction |= (flags & 0xff);
c19d1205
ZW
7376 inst.instruction |= inst.operands[1].reg << 16;
7377}
b05fe5cf 7378
c19d1205
ZW
7379static void
7380do_t_mul (void)
7381{
7382 if (!inst.operands[2].present)
7383 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 7384
c19d1205
ZW
7385 /* There is no 32-bit MULS and no 16-bit MUL. */
7386 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 7387 {
c19d1205
ZW
7388 inst.instruction = THUMB_OP32 (inst.instruction);
7389 inst.instruction |= inst.operands[0].reg << 8;
7390 inst.instruction |= inst.operands[1].reg << 16;
7391 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 7392 }
c19d1205 7393 else
b05fe5cf 7394 {
c19d1205
ZW
7395 constraint (!unified_syntax
7396 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
7397 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7398 BAD_HIREG);
b05fe5cf 7399
c19d1205
ZW
7400 inst.instruction = THUMB_OP16 (inst.instruction);
7401 inst.instruction |= inst.operands[0].reg;
b05fe5cf 7402
c19d1205
ZW
7403 if (inst.operands[0].reg == inst.operands[1].reg)
7404 inst.instruction |= inst.operands[2].reg << 3;
7405 else if (inst.operands[0].reg == inst.operands[2].reg)
7406 inst.instruction |= inst.operands[1].reg << 3;
7407 else
7408 constraint (1, _("dest must overlap one source register"));
7409 }
7410}
b05fe5cf 7411
c19d1205
ZW
7412static void
7413do_t_mull (void)
7414{
7415 inst.instruction |= inst.operands[0].reg << 12;
7416 inst.instruction |= inst.operands[1].reg << 8;
7417 inst.instruction |= inst.operands[2].reg << 16;
7418 inst.instruction |= inst.operands[3].reg;
b05fe5cf 7419
c19d1205
ZW
7420 if (inst.operands[0].reg == inst.operands[1].reg)
7421 as_tsktsk (_("rdhi and rdlo must be different"));
7422}
b05fe5cf 7423
c19d1205
ZW
7424static void
7425do_t_nop (void)
7426{
7427 if (unified_syntax)
7428 {
7429 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 7430 {
c19d1205
ZW
7431 inst.instruction = THUMB_OP32 (inst.instruction);
7432 inst.instruction |= inst.operands[0].imm;
7433 }
7434 else
7435 {
7436 inst.instruction = THUMB_OP16 (inst.instruction);
7437 inst.instruction |= inst.operands[0].imm << 4;
7438 }
7439 }
7440 else
7441 {
7442 constraint (inst.operands[0].present,
7443 _("Thumb does not support NOP with hints"));
7444 inst.instruction = 0x46c0;
7445 }
7446}
b05fe5cf 7447
c19d1205
ZW
7448static void
7449do_t_neg (void)
7450{
7451 if (unified_syntax)
7452 {
3d388997
PB
7453 bfd_boolean narrow;
7454
7455 if (THUMB_SETS_FLAGS (inst.instruction))
7456 narrow = (current_it_mask == 0);
7457 else
7458 narrow = (current_it_mask != 0);
7459 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7460 narrow = FALSE;
7461 if (inst.size_req == 4)
7462 narrow = FALSE;
7463
7464 if (!narrow)
c19d1205
ZW
7465 {
7466 inst.instruction = THUMB_OP32 (inst.instruction);
7467 inst.instruction |= inst.operands[0].reg << 8;
7468 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
7469 }
7470 else
7471 {
c19d1205
ZW
7472 inst.instruction = THUMB_OP16 (inst.instruction);
7473 inst.instruction |= inst.operands[0].reg;
7474 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
7475 }
7476 }
7477 else
7478 {
c19d1205
ZW
7479 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
7480 BAD_HIREG);
7481 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
7482
7483 inst.instruction = THUMB_OP16 (inst.instruction);
7484 inst.instruction |= inst.operands[0].reg;
7485 inst.instruction |= inst.operands[1].reg << 3;
7486 }
7487}
7488
7489static void
7490do_t_pkhbt (void)
7491{
7492 inst.instruction |= inst.operands[0].reg << 8;
7493 inst.instruction |= inst.operands[1].reg << 16;
7494 inst.instruction |= inst.operands[2].reg;
7495 if (inst.operands[3].present)
7496 {
7497 unsigned int val = inst.reloc.exp.X_add_number;
7498 constraint (inst.reloc.exp.X_op != O_constant,
7499 _("expression too complex"));
7500 inst.instruction |= (val & 0x1c) << 10;
7501 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 7502 }
c19d1205 7503}
b05fe5cf 7504
c19d1205
ZW
7505static void
7506do_t_pkhtb (void)
7507{
7508 if (!inst.operands[3].present)
7509 inst.instruction &= ~0x00000020;
7510 do_t_pkhbt ();
b05fe5cf
ZW
7511}
7512
c19d1205
ZW
7513static void
7514do_t_pld (void)
7515{
7516 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
7517}
b05fe5cf 7518
c19d1205
ZW
7519static void
7520do_t_push_pop (void)
b99bd4ef 7521{
e9f89963
PB
7522 unsigned mask;
7523
c19d1205
ZW
7524 constraint (inst.operands[0].writeback,
7525 _("push/pop do not support {reglist}^"));
7526 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
7527 _("expression too complex"));
b99bd4ef 7528
e9f89963
PB
7529 mask = inst.operands[0].imm;
7530 if ((mask & ~0xff) == 0)
c19d1205
ZW
7531 inst.instruction = THUMB_OP16 (inst.instruction);
7532 else if ((inst.instruction == T_MNEM_push
e9f89963 7533 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 7534 || (inst.instruction == T_MNEM_pop
e9f89963 7535 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 7536 {
c19d1205
ZW
7537 inst.instruction = THUMB_OP16 (inst.instruction);
7538 inst.instruction |= THUMB_PP_PC_LR;
e9f89963 7539 mask &= 0xff;
c19d1205
ZW
7540 }
7541 else if (unified_syntax)
7542 {
e9f89963
PB
7543 if (mask & (1 << 13))
7544 inst.error = _("SP not allowed in register list");
c19d1205 7545 if (inst.instruction == T_MNEM_push)
b99bd4ef 7546 {
e9f89963
PB
7547 if (mask & (1 << 15))
7548 inst.error = _("PC not allowed in register list");
c19d1205
ZW
7549 }
7550 else
7551 {
e9f89963
PB
7552 if (mask & (1 << 14)
7553 && mask & (1 << 15))
7554 inst.error = _("LR and PC should not both be in register list");
c19d1205 7555 }
e9f89963
PB
7556 if ((mask & (mask - 1)) == 0)
7557 {
7558 /* Single register push/pop implemented as str/ldr. */
7559 if (inst.instruction == T_MNEM_push)
7560 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
7561 else
7562 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
7563 mask = ffs(mask) - 1;
7564 mask <<= 12;
7565 }
7566 else
7567 inst.instruction = THUMB_OP32 (inst.instruction);
c19d1205
ZW
7568 }
7569 else
7570 {
7571 inst.error = _("invalid register list to push/pop instruction");
7572 return;
7573 }
b99bd4ef 7574
e9f89963 7575 inst.instruction |= mask;
c19d1205 7576}
b99bd4ef 7577
c19d1205
ZW
7578static void
7579do_t_rbit (void)
7580{
7581 inst.instruction |= inst.operands[0].reg << 8;
7582 inst.instruction |= inst.operands[1].reg << 16;
7583}
b99bd4ef 7584
c19d1205
ZW
7585static void
7586do_t_rev (void)
7587{
7588 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7589 && inst.size_req != 4)
7590 {
7591 inst.instruction = THUMB_OP16 (inst.instruction);
7592 inst.instruction |= inst.operands[0].reg;
7593 inst.instruction |= inst.operands[1].reg << 3;
7594 }
7595 else if (unified_syntax)
7596 {
7597 inst.instruction = THUMB_OP32 (inst.instruction);
7598 inst.instruction |= inst.operands[0].reg << 8;
7599 inst.instruction |= inst.operands[1].reg << 16;
7600 inst.instruction |= inst.operands[1].reg;
7601 }
7602 else
7603 inst.error = BAD_HIREG;
7604}
b99bd4ef 7605
c19d1205
ZW
7606static void
7607do_t_rsb (void)
7608{
7609 int Rd, Rs;
b99bd4ef 7610
c19d1205
ZW
7611 Rd = inst.operands[0].reg;
7612 Rs = (inst.operands[1].present
7613 ? inst.operands[1].reg /* Rd, Rs, foo */
7614 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 7615
c19d1205
ZW
7616 inst.instruction |= Rd << 8;
7617 inst.instruction |= Rs << 16;
7618 if (!inst.operands[2].isreg)
7619 {
7620 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
7621 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
7622 }
7623 else
7624 encode_thumb32_shifted_operand (2);
7625}
b99bd4ef 7626
c19d1205
ZW
7627static void
7628do_t_setend (void)
7629{
7630 if (inst.operands[0].imm)
7631 inst.instruction |= 0x8;
7632}
b99bd4ef 7633
c19d1205
ZW
7634static void
7635do_t_shift (void)
7636{
7637 if (!inst.operands[1].present)
7638 inst.operands[1].reg = inst.operands[0].reg;
7639
7640 if (unified_syntax)
7641 {
3d388997
PB
7642 bfd_boolean narrow;
7643 int shift_kind;
7644
7645 switch (inst.instruction)
7646 {
7647 case T_MNEM_asr:
7648 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
7649 case T_MNEM_lsl:
7650 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
7651 case T_MNEM_lsr:
7652 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
7653 case T_MNEM_ror:
7654 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
7655 default: abort ();
7656 }
7657
7658 if (THUMB_SETS_FLAGS (inst.instruction))
7659 narrow = (current_it_mask == 0);
7660 else
7661 narrow = (current_it_mask != 0);
7662 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
7663 narrow = FALSE;
7664 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
7665 narrow = FALSE;
7666 if (inst.operands[2].isreg
7667 && (inst.operands[1].reg != inst.operands[0].reg
7668 || inst.operands[2].reg > 7))
7669 narrow = FALSE;
7670 if (inst.size_req == 4)
7671 narrow = FALSE;
7672
7673 if (!narrow)
c19d1205
ZW
7674 {
7675 if (inst.operands[2].isreg)
b99bd4ef 7676 {
c19d1205
ZW
7677 inst.instruction = THUMB_OP32 (inst.instruction);
7678 inst.instruction |= inst.operands[0].reg << 8;
7679 inst.instruction |= inst.operands[1].reg << 16;
7680 inst.instruction |= inst.operands[2].reg;
7681 }
7682 else
7683 {
7684 inst.operands[1].shifted = 1;
3d388997 7685 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
7686 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
7687 ? T_MNEM_movs : T_MNEM_mov);
7688 inst.instruction |= inst.operands[0].reg << 8;
7689 encode_thumb32_shifted_operand (1);
7690 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
7691 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
7692 }
7693 }
7694 else
7695 {
c19d1205 7696 if (inst.operands[2].isreg)
b99bd4ef 7697 {
3d388997 7698 switch (shift_kind)
b99bd4ef 7699 {
3d388997
PB
7700 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
7701 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
7702 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
7703 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 7704 default: abort ();
b99bd4ef 7705 }
c19d1205
ZW
7706
7707 inst.instruction |= inst.operands[0].reg;
7708 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
7709 }
7710 else
7711 {
3d388997 7712 switch (shift_kind)
b99bd4ef 7713 {
3d388997
PB
7714 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
7715 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
7716 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 7717 default: abort ();
b99bd4ef 7718 }
c19d1205
ZW
7719 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7720 inst.instruction |= inst.operands[0].reg;
7721 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7722 }
7723 }
c19d1205
ZW
7724 }
7725 else
7726 {
7727 constraint (inst.operands[0].reg > 7
7728 || inst.operands[1].reg > 7, BAD_HIREG);
7729 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 7730
c19d1205
ZW
7731 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
7732 {
7733 constraint (inst.operands[2].reg > 7, BAD_HIREG);
7734 constraint (inst.operands[0].reg != inst.operands[1].reg,
7735 _("source1 and dest must be same register"));
b99bd4ef 7736
c19d1205
ZW
7737 switch (inst.instruction)
7738 {
7739 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
7740 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
7741 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
7742 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
7743 default: abort ();
7744 }
7745
7746 inst.instruction |= inst.operands[0].reg;
7747 inst.instruction |= inst.operands[2].reg << 3;
7748 }
7749 else
b99bd4ef 7750 {
c19d1205
ZW
7751 switch (inst.instruction)
7752 {
7753 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
7754 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
7755 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
7756 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
7757 default: abort ();
7758 }
7759 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
7760 inst.instruction |= inst.operands[0].reg;
7761 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
7762 }
7763 }
b99bd4ef
NC
7764}
7765
7766static void
c19d1205 7767do_t_simd (void)
b99bd4ef 7768{
c19d1205
ZW
7769 inst.instruction |= inst.operands[0].reg << 8;
7770 inst.instruction |= inst.operands[1].reg << 16;
7771 inst.instruction |= inst.operands[2].reg;
7772}
b99bd4ef 7773
c19d1205 7774static void
3eb17e6b 7775do_t_smc (void)
c19d1205
ZW
7776{
7777 unsigned int value = inst.reloc.exp.X_add_number;
7778 constraint (inst.reloc.exp.X_op != O_constant,
7779 _("expression too complex"));
7780 inst.reloc.type = BFD_RELOC_UNUSED;
7781 inst.instruction |= (value & 0xf000) >> 12;
7782 inst.instruction |= (value & 0x0ff0);
7783 inst.instruction |= (value & 0x000f) << 16;
7784}
b99bd4ef 7785
c19d1205
ZW
7786static void
7787do_t_ssat (void)
7788{
7789 inst.instruction |= inst.operands[0].reg << 8;
7790 inst.instruction |= inst.operands[1].imm - 1;
7791 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7792
c19d1205 7793 if (inst.operands[3].present)
b99bd4ef 7794 {
c19d1205
ZW
7795 constraint (inst.reloc.exp.X_op != O_constant,
7796 _("expression too complex"));
b99bd4ef 7797
c19d1205 7798 if (inst.reloc.exp.X_add_number != 0)
6189168b 7799 {
c19d1205
ZW
7800 if (inst.operands[3].shift_kind == SHIFT_ASR)
7801 inst.instruction |= 0x00200000; /* sh bit */
7802 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7803 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 7804 }
c19d1205 7805 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 7806 }
b99bd4ef
NC
7807}
7808
0dd132b6 7809static void
c19d1205 7810do_t_ssat16 (void)
0dd132b6 7811{
c19d1205
ZW
7812 inst.instruction |= inst.operands[0].reg << 8;
7813 inst.instruction |= inst.operands[1].imm - 1;
7814 inst.instruction |= inst.operands[2].reg << 16;
7815}
0dd132b6 7816
c19d1205
ZW
7817static void
7818do_t_strex (void)
7819{
7820 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7821 || inst.operands[2].postind || inst.operands[2].writeback
7822 || inst.operands[2].immisreg || inst.operands[2].shifted
7823 || inst.operands[2].negative,
01cfc07f 7824 BAD_ADDR_MODE);
0dd132b6 7825
c19d1205
ZW
7826 inst.instruction |= inst.operands[0].reg << 8;
7827 inst.instruction |= inst.operands[1].reg << 12;
7828 inst.instruction |= inst.operands[2].reg << 16;
7829 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
7830}
7831
b99bd4ef 7832static void
c19d1205 7833do_t_strexd (void)
b99bd4ef 7834{
c19d1205
ZW
7835 if (!inst.operands[2].present)
7836 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 7837
c19d1205
ZW
7838 constraint (inst.operands[0].reg == inst.operands[1].reg
7839 || inst.operands[0].reg == inst.operands[2].reg
7840 || inst.operands[0].reg == inst.operands[3].reg
7841 || inst.operands[1].reg == inst.operands[2].reg,
7842 BAD_OVERLAP);
b99bd4ef 7843
c19d1205
ZW
7844 inst.instruction |= inst.operands[0].reg;
7845 inst.instruction |= inst.operands[1].reg << 12;
7846 inst.instruction |= inst.operands[2].reg << 8;
7847 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
7848}
7849
7850static void
c19d1205 7851do_t_sxtah (void)
b99bd4ef 7852{
c19d1205
ZW
7853 inst.instruction |= inst.operands[0].reg << 8;
7854 inst.instruction |= inst.operands[1].reg << 16;
7855 inst.instruction |= inst.operands[2].reg;
7856 inst.instruction |= inst.operands[3].imm << 4;
7857}
b99bd4ef 7858
c19d1205
ZW
7859static void
7860do_t_sxth (void)
7861{
7862 if (inst.instruction <= 0xffff && inst.size_req != 4
7863 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
7864 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 7865 {
c19d1205
ZW
7866 inst.instruction = THUMB_OP16 (inst.instruction);
7867 inst.instruction |= inst.operands[0].reg;
7868 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 7869 }
c19d1205 7870 else if (unified_syntax)
b99bd4ef 7871 {
c19d1205
ZW
7872 if (inst.instruction <= 0xffff)
7873 inst.instruction = THUMB_OP32 (inst.instruction);
7874 inst.instruction |= inst.operands[0].reg << 8;
7875 inst.instruction |= inst.operands[1].reg;
7876 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 7877 }
c19d1205 7878 else
b99bd4ef 7879 {
c19d1205
ZW
7880 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
7881 _("Thumb encoding does not support rotation"));
7882 constraint (1, BAD_HIREG);
b99bd4ef 7883 }
c19d1205 7884}
b99bd4ef 7885
c19d1205
ZW
7886static void
7887do_t_swi (void)
7888{
7889 inst.reloc.type = BFD_RELOC_ARM_SWI;
7890}
b99bd4ef 7891
92e90b6e
PB
7892static void
7893do_t_tb (void)
7894{
7895 int half;
7896
7897 half = (inst.instruction & 0x10) != 0;
7898 constraint (inst.operands[0].imm == 15,
7899 _("PC is not a valid index register"));
7900 constraint (!half && inst.operands[0].shifted,
7901 _("instruction does not allow shifted index"));
7902 constraint (half && !inst.operands[0].shifted,
7903 _("instruction requires shifted index"));
7904 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
7905}
7906
c19d1205
ZW
7907static void
7908do_t_usat (void)
7909{
7910 inst.instruction |= inst.operands[0].reg << 8;
7911 inst.instruction |= inst.operands[1].imm;
7912 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7913
c19d1205 7914 if (inst.operands[3].present)
b99bd4ef 7915 {
c19d1205
ZW
7916 constraint (inst.reloc.exp.X_op != O_constant,
7917 _("expression too complex"));
7918 if (inst.reloc.exp.X_add_number != 0)
7919 {
7920 if (inst.operands[3].shift_kind == SHIFT_ASR)
7921 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 7922
c19d1205
ZW
7923 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
7924 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
7925 }
7926 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 7927 }
b99bd4ef
NC
7928}
7929
7930static void
c19d1205 7931do_t_usat16 (void)
b99bd4ef 7932{
c19d1205
ZW
7933 inst.instruction |= inst.operands[0].reg << 8;
7934 inst.instruction |= inst.operands[1].imm;
7935 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 7936}
c19d1205
ZW
7937\f
7938/* Overall per-instruction processing. */
7939
7940/* We need to be able to fix up arbitrary expressions in some statements.
7941 This is so that we can handle symbols that are an arbitrary distance from
7942 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
7943 which returns part of an address in a form which will be valid for
7944 a data instruction. We do this by pushing the expression into a symbol
7945 in the expr_section, and creating a fix for that. */
b99bd4ef
NC
7946
7947static void
c19d1205
ZW
7948fix_new_arm (fragS * frag,
7949 int where,
7950 short int size,
7951 expressionS * exp,
7952 int pc_rel,
7953 int reloc)
b99bd4ef 7954{
c19d1205 7955 fixS * new_fix;
b99bd4ef 7956
c19d1205 7957 switch (exp->X_op)
b99bd4ef 7958 {
c19d1205
ZW
7959 case O_constant:
7960 case O_symbol:
7961 case O_add:
7962 case O_subtract:
7963 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
7964 break;
b99bd4ef 7965
c19d1205
ZW
7966 default:
7967 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
7968 pc_rel, reloc);
7969 break;
b99bd4ef
NC
7970 }
7971
c19d1205
ZW
7972 /* Mark whether the fix is to a THUMB instruction, or an ARM
7973 instruction. */
adbaf948 7974 new_fix->tc_fix_data = thumb_mode;
b99bd4ef
NC
7975}
7976
0110f2b8
PB
7977/* Create a frg for an instruction requiring relaxation. */
7978static void
7979output_relax_insn (void)
7980{
7981 char * to;
7982 symbolS *sym;
7983 int offset;
7984
6e1cb1a6
PB
7985#ifdef OBJ_ELF
7986 /* The size of the instruction is unknown, so tie the debug info to the
7987 start of the instruction. */
7988 dwarf2_emit_insn (0);
7989#endif
7990
0110f2b8
PB
7991 switch (inst.reloc.exp.X_op)
7992 {
7993 case O_symbol:
7994 sym = inst.reloc.exp.X_add_symbol;
7995 offset = inst.reloc.exp.X_add_number;
7996 break;
7997 case O_constant:
7998 sym = NULL;
7999 offset = inst.reloc.exp.X_add_number;
8000 break;
8001 default:
8002 sym = make_expr_symbol (&inst.reloc.exp);
8003 offset = 0;
8004 break;
8005 }
8006 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
8007 inst.relax, sym, offset, NULL/*offset, opcode*/);
8008 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
8009}
8010
8011/* Write a 32-bit thumb instruction to buf. */
8012static void
8013put_thumb32_insn (char * buf, unsigned long insn)
8014{
8015 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
8016 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
8017}
8018
b99bd4ef 8019static void
c19d1205 8020output_inst (const char * str)
b99bd4ef 8021{
c19d1205 8022 char * to = NULL;
b99bd4ef 8023
c19d1205 8024 if (inst.error)
b99bd4ef 8025 {
c19d1205 8026 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
8027 return;
8028 }
0110f2b8
PB
8029 if (inst.relax) {
8030 output_relax_insn();
8031 return;
8032 }
c19d1205
ZW
8033 if (inst.size == 0)
8034 return;
b99bd4ef 8035
c19d1205
ZW
8036 to = frag_more (inst.size);
8037
8038 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 8039 {
c19d1205 8040 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 8041 put_thumb32_insn (to, inst.instruction);
b99bd4ef 8042 }
c19d1205 8043 else if (inst.size > INSN_SIZE)
b99bd4ef 8044 {
c19d1205
ZW
8045 assert (inst.size == (2 * INSN_SIZE));
8046 md_number_to_chars (to, inst.instruction, INSN_SIZE);
8047 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 8048 }
c19d1205
ZW
8049 else
8050 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 8051
c19d1205
ZW
8052 if (inst.reloc.type != BFD_RELOC_UNUSED)
8053 fix_new_arm (frag_now, to - frag_now->fr_literal,
8054 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
8055 inst.reloc.type);
b99bd4ef 8056
c19d1205
ZW
8057#ifdef OBJ_ELF
8058 dwarf2_emit_insn (inst.size);
8059#endif
8060}
b99bd4ef 8061
c19d1205
ZW
8062/* Tag values used in struct asm_opcode's tag field. */
8063enum opcode_tag
8064{
8065 OT_unconditional, /* Instruction cannot be conditionalized.
8066 The ARM condition field is still 0xE. */
8067 OT_unconditionalF, /* Instruction cannot be conditionalized
8068 and carries 0xF in its ARM condition field. */
8069 OT_csuffix, /* Instruction takes a conditional suffix. */
8070 OT_cinfix3, /* Instruction takes a conditional infix,
8071 beginning at character index 3. (In
8072 unified mode, it becomes a suffix.) */
e3cb604e
PB
8073 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
8074 character index 3, even in unified mode. Used for
8075 legacy instructions where suffix and infix forms
8076 may be ambiguous. */
c19d1205 8077 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 8078 suffix or an infix at character index 3. */
c19d1205
ZW
8079 OT_odd_infix_unc, /* This is the unconditional variant of an
8080 instruction that takes a conditional infix
8081 at an unusual position. In unified mode,
8082 this variant will accept a suffix. */
8083 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
8084 are the conditional variants of instructions that
8085 take conditional infixes in unusual positions.
8086 The infix appears at character index
8087 (tag - OT_odd_infix_0). These are not accepted
8088 in unified mode. */
8089};
b99bd4ef 8090
c19d1205
ZW
8091/* Subroutine of md_assemble, responsible for looking up the primary
8092 opcode from the mnemonic the user wrote. STR points to the
8093 beginning of the mnemonic.
8094
8095 This is not simply a hash table lookup, because of conditional
8096 variants. Most instructions have conditional variants, which are
8097 expressed with a _conditional affix_ to the mnemonic. If we were
8098 to encode each conditional variant as a literal string in the opcode
8099 table, it would have approximately 20,000 entries.
8100
8101 Most mnemonics take this affix as a suffix, and in unified syntax,
8102 'most' is upgraded to 'all'. However, in the divided syntax, some
8103 instructions take the affix as an infix, notably the s-variants of
8104 the arithmetic instructions. Of those instructions, all but six
8105 have the infix appear after the third character of the mnemonic.
8106
8107 Accordingly, the algorithm for looking up primary opcodes given
8108 an identifier is:
8109
8110 1. Look up the identifier in the opcode table.
8111 If we find a match, go to step U.
8112
8113 2. Look up the last two characters of the identifier in the
8114 conditions table. If we find a match, look up the first N-2
8115 characters of the identifier in the opcode table. If we
8116 find a match, go to step CE.
8117
8118 3. Look up the fourth and fifth characters of the identifier in
8119 the conditions table. If we find a match, extract those
8120 characters from the identifier, and look up the remaining
8121 characters in the opcode table. If we find a match, go
8122 to step CM.
8123
8124 4. Fail.
8125
8126 U. Examine the tag field of the opcode structure, in case this is
8127 one of the six instructions with its conditional infix in an
8128 unusual place. If it is, the tag tells us where to find the
8129 infix; look it up in the conditions table and set inst.cond
8130 accordingly. Otherwise, this is an unconditional instruction.
8131 Again set inst.cond accordingly. Return the opcode structure.
8132
8133 CE. Examine the tag field to make sure this is an instruction that
8134 should receive a conditional suffix. If it is not, fail.
8135 Otherwise, set inst.cond from the suffix we already looked up,
8136 and return the opcode structure.
8137
8138 CM. Examine the tag field to make sure this is an instruction that
8139 should receive a conditional infix after the third character.
8140 If it is not, fail. Otherwise, undo the edits to the current
8141 line of input and proceed as for case CE. */
8142
8143static const struct asm_opcode *
8144opcode_lookup (char **str)
8145{
8146 char *end, *base;
8147 char *affix;
8148 const struct asm_opcode *opcode;
8149 const struct asm_cond *cond;
e3cb604e 8150 char save[2];
c19d1205
ZW
8151
8152 /* Scan up to the end of the mnemonic, which must end in white space,
8153 '.' (in unified mode only), or end of string. */
8154 for (base = end = *str; *end != '\0'; end++)
8155 if (*end == ' ' || (unified_syntax && *end == '.'))
8156 break;
b99bd4ef 8157
c19d1205
ZW
8158 if (end == base)
8159 return 0;
b99bd4ef 8160
c19d1205
ZW
8161 /* Handle a possible width suffix. */
8162 if (end[0] == '.')
b99bd4ef 8163 {
c19d1205
ZW
8164 if (end[1] == 'w' && (end[2] == ' ' || end[2] == '\0'))
8165 inst.size_req = 4;
8166 else if (end[1] == 'n' && (end[2] == ' ' || end[2] == '\0'))
8167 inst.size_req = 2;
8168 else
8169 return 0;
b99bd4ef 8170
c19d1205 8171 *str = end + 2;
b99bd4ef 8172 }
c19d1205
ZW
8173 else
8174 *str = end;
b99bd4ef 8175
c19d1205
ZW
8176 /* Look for unaffixed or special-case affixed mnemonic. */
8177 opcode = hash_find_n (arm_ops_hsh, base, end - base);
8178 if (opcode)
b99bd4ef 8179 {
c19d1205
ZW
8180 /* step U */
8181 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 8182 {
c19d1205
ZW
8183 inst.cond = COND_ALWAYS;
8184 return opcode;
b99bd4ef 8185 }
b99bd4ef 8186
c19d1205
ZW
8187 if (unified_syntax)
8188 as_warn (_("conditional infixes are deprecated in unified syntax"));
8189 affix = base + (opcode->tag - OT_odd_infix_0);
8190 cond = hash_find_n (arm_cond_hsh, affix, 2);
8191 assert (cond);
b99bd4ef 8192
c19d1205
ZW
8193 inst.cond = cond->value;
8194 return opcode;
8195 }
b99bd4ef 8196
c19d1205
ZW
8197 /* Cannot have a conditional suffix on a mnemonic of less than two
8198 characters. */
8199 if (end - base < 3)
8200 return 0;
b99bd4ef 8201
c19d1205
ZW
8202 /* Look for suffixed mnemonic. */
8203 affix = end - 2;
8204 cond = hash_find_n (arm_cond_hsh, affix, 2);
8205 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
8206 if (opcode && cond)
8207 {
8208 /* step CE */
8209 switch (opcode->tag)
8210 {
e3cb604e
PB
8211 case OT_cinfix3_legacy:
8212 /* Ignore conditional suffixes matched on infix only mnemonics. */
8213 break;
8214
c19d1205
ZW
8215 case OT_cinfix3:
8216 case OT_odd_infix_unc:
8217 if (!unified_syntax)
e3cb604e 8218 return 0;
c19d1205
ZW
8219 /* else fall through */
8220
8221 case OT_csuffix:
8222 case OT_csuf_or_in3:
8223 inst.cond = cond->value;
8224 return opcode;
8225
8226 case OT_unconditional:
8227 case OT_unconditionalF:
8228 /* delayed diagnostic */
8229 inst.error = BAD_COND;
8230 inst.cond = COND_ALWAYS;
8231 return opcode;
b99bd4ef 8232
c19d1205
ZW
8233 default:
8234 return 0;
8235 }
8236 }
b99bd4ef 8237
c19d1205
ZW
8238 /* Cannot have a usual-position infix on a mnemonic of less than
8239 six characters (five would be a suffix). */
8240 if (end - base < 6)
8241 return 0;
b99bd4ef 8242
c19d1205
ZW
8243 /* Look for infixed mnemonic in the usual position. */
8244 affix = base + 3;
8245 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
8246 if (!cond)
8247 return 0;
8248
8249 memcpy (save, affix, 2);
8250 memmove (affix, affix + 2, (end - affix) - 2);
8251 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
8252 memmove (affix + 2, affix, (end - affix) - 2);
8253 memcpy (affix, save, 2);
8254
8255 if (opcode && (opcode->tag == OT_cinfix3 || opcode->tag == OT_csuf_or_in3
8256 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 8257 {
c19d1205 8258 /* step CM */
e3cb604e 8259 if (unified_syntax && opcode->tag == OT_cinfix3)
c19d1205
ZW
8260 as_warn (_("conditional infixes are deprecated in unified syntax"));
8261
8262 inst.cond = cond->value;
8263 return opcode;
b99bd4ef
NC
8264 }
8265
c19d1205 8266 return 0;
b99bd4ef
NC
8267}
8268
c19d1205
ZW
8269void
8270md_assemble (char *str)
b99bd4ef 8271{
c19d1205
ZW
8272 char *p = str;
8273 const struct asm_opcode * opcode;
b99bd4ef 8274
c19d1205
ZW
8275 /* Align the previous label if needed. */
8276 if (last_label_seen != NULL)
b99bd4ef 8277 {
c19d1205
ZW
8278 symbol_set_frag (last_label_seen, frag_now);
8279 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
8280 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
8281 }
8282
c19d1205
ZW
8283 memset (&inst, '\0', sizeof (inst));
8284 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 8285
c19d1205
ZW
8286 opcode = opcode_lookup (&p);
8287 if (!opcode)
b99bd4ef 8288 {
c19d1205
ZW
8289 /* It wasn't an instruction, but it might be a register alias of
8290 the form alias .req reg. */
8291 if (!create_register_alias (str, p))
8292 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 8293
b99bd4ef
NC
8294 return;
8295 }
8296
c19d1205 8297 if (thumb_mode)
b99bd4ef 8298 {
e74cfd16 8299 arm_feature_set variant;
8f06b2d8
PB
8300
8301 variant = cpu_variant;
8302 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
8303 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
8304 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 8305 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
8306 if (!opcode->tvariant
8307 || (thumb_mode == 1
8308 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 8309 {
c19d1205 8310 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
8311 return;
8312 }
c19d1205
ZW
8313 if (inst.cond != COND_ALWAYS && !unified_syntax
8314 && opcode->tencode != do_t_branch)
b99bd4ef 8315 {
c19d1205 8316 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
8317 return;
8318 }
8319
e27ec89e
PB
8320 /* Check conditional suffixes. */
8321 if (current_it_mask)
8322 {
8323 int cond;
8324 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
8325 if (cond != inst.cond)
8326 {
8327 as_bad (_("incorrect condition in IT block"));
8328 return;
8329 }
8330 current_it_mask <<= 1;
8331 current_it_mask &= 0x1f;
8332 }
8333 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
8334 {
8335 as_bad (_("thumb conditional instrunction not in IT block"));
8336 return;
8337 }
8338
c19d1205
ZW
8339 mapping_state (MAP_THUMB);
8340 inst.instruction = opcode->tvalue;
8341
8342 if (!parse_operands (p, opcode->operands))
8343 opcode->tencode ();
8344
e27ec89e
PB
8345 /* Clear current_it_mask at the end of an IT block. */
8346 if (current_it_mask == 0x10)
8347 current_it_mask = 0;
8348
0110f2b8 8349 if (!(inst.error || inst.relax))
b99bd4ef 8350 {
c19d1205
ZW
8351 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
8352 inst.size = (inst.instruction > 0xffff ? 4 : 2);
8353 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 8354 {
c19d1205 8355 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
8356 return;
8357 }
8358 }
e74cfd16
PB
8359 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8360 *opcode->tvariant);
ee065d83 8361 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
e74cfd16 8362 set those bits when Thumb-2 32-bit instuctions are seen. ie.
ee065d83
PB
8363 anything other than bl/blx.
8364 This is overly pessimistic for relaxable instructions. */
8365 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
8366 || inst.relax)
e74cfd16
PB
8367 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8368 arm_ext_v6t2);
c19d1205
ZW
8369 }
8370 else
8371 {
8372 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
8373 if (!opcode->avariant ||
8374 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
b99bd4ef 8375 {
c19d1205
ZW
8376 as_bad (_("selected processor does not support `%s'"), str);
8377 return;
b99bd4ef 8378 }
c19d1205 8379 if (inst.size_req)
b99bd4ef 8380 {
c19d1205
ZW
8381 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
8382 return;
b99bd4ef
NC
8383 }
8384
c19d1205
ZW
8385 mapping_state (MAP_ARM);
8386 inst.instruction = opcode->avalue;
8387 if (opcode->tag == OT_unconditionalF)
8388 inst.instruction |= 0xF << 28;
8389 else
8390 inst.instruction |= inst.cond << 28;
8391 inst.size = INSN_SIZE;
8392 if (!parse_operands (p, opcode->operands))
8393 opcode->aencode ();
ee065d83
PB
8394 /* Arm mode bx is marked as both v4T and v5 because it's still required
8395 on a hypothetical non-thumb v5 core. */
e74cfd16
PB
8396 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
8397 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
8398 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 8399 else
e74cfd16
PB
8400 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8401 *opcode->avariant);
b99bd4ef 8402 }
c19d1205
ZW
8403 output_inst (str);
8404}
b99bd4ef 8405
c19d1205
ZW
8406/* Various frobbings of labels and their addresses. */
8407
8408void
8409arm_start_line_hook (void)
8410{
8411 last_label_seen = NULL;
b99bd4ef
NC
8412}
8413
c19d1205
ZW
8414void
8415arm_frob_label (symbolS * sym)
b99bd4ef 8416{
c19d1205 8417 last_label_seen = sym;
b99bd4ef 8418
c19d1205 8419 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 8420
c19d1205
ZW
8421#if defined OBJ_COFF || defined OBJ_ELF
8422 ARM_SET_INTERWORK (sym, support_interwork);
8423#endif
b99bd4ef 8424
c19d1205
ZW
8425 /* Note - do not allow local symbols (.Lxxx) to be labeled
8426 as Thumb functions. This is because these labels, whilst
8427 they exist inside Thumb code, are not the entry points for
8428 possible ARM->Thumb calls. Also, these labels can be used
8429 as part of a computed goto or switch statement. eg gcc
8430 can generate code that looks like this:
b99bd4ef 8431
c19d1205
ZW
8432 ldr r2, [pc, .Laaa]
8433 lsl r3, r3, #2
8434 ldr r2, [r3, r2]
8435 mov pc, r2
b99bd4ef 8436
c19d1205
ZW
8437 .Lbbb: .word .Lxxx
8438 .Lccc: .word .Lyyy
8439 ..etc...
8440 .Laaa: .word Lbbb
b99bd4ef 8441
c19d1205
ZW
8442 The first instruction loads the address of the jump table.
8443 The second instruction converts a table index into a byte offset.
8444 The third instruction gets the jump address out of the table.
8445 The fourth instruction performs the jump.
b99bd4ef 8446
c19d1205
ZW
8447 If the address stored at .Laaa is that of a symbol which has the
8448 Thumb_Func bit set, then the linker will arrange for this address
8449 to have the bottom bit set, which in turn would mean that the
8450 address computation performed by the third instruction would end
8451 up with the bottom bit set. Since the ARM is capable of unaligned
8452 word loads, the instruction would then load the incorrect address
8453 out of the jump table, and chaos would ensue. */
8454 if (label_is_thumb_function_name
8455 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
8456 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 8457 {
c19d1205
ZW
8458 /* When the address of a Thumb function is taken the bottom
8459 bit of that address should be set. This will allow
8460 interworking between Arm and Thumb functions to work
8461 correctly. */
b99bd4ef 8462
c19d1205 8463 THUMB_SET_FUNC (sym, 1);
b99bd4ef 8464
c19d1205 8465 label_is_thumb_function_name = FALSE;
b99bd4ef 8466 }
07a53e5c
RH
8467
8468#ifdef OBJ_ELF
8469 dwarf2_emit_label (sym);
8470#endif
b99bd4ef
NC
8471}
8472
c19d1205
ZW
8473int
8474arm_data_in_code (void)
b99bd4ef 8475{
c19d1205 8476 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 8477 {
c19d1205
ZW
8478 *input_line_pointer = '/';
8479 input_line_pointer += 5;
8480 *input_line_pointer = 0;
8481 return 1;
b99bd4ef
NC
8482 }
8483
c19d1205 8484 return 0;
b99bd4ef
NC
8485}
8486
c19d1205
ZW
8487char *
8488arm_canonicalize_symbol_name (char * name)
b99bd4ef 8489{
c19d1205 8490 int len;
b99bd4ef 8491
c19d1205
ZW
8492 if (thumb_mode && (len = strlen (name)) > 5
8493 && streq (name + len - 5, "/data"))
8494 *(name + len - 5) = 0;
b99bd4ef 8495
c19d1205 8496 return name;
b99bd4ef 8497}
c19d1205
ZW
8498\f
8499/* Table of all register names defined by default. The user can
8500 define additional names with .req. Note that all register names
8501 should appear in both upper and lowercase variants. Some registers
8502 also have mixed-case names. */
b99bd4ef 8503
c19d1205
ZW
8504#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE }
8505#define REGNUM(p,n,t) REGDEF(p##n, n, t)
8506#define REGSET(p,t) \
8507 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
8508 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
8509 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
8510 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
7ed4c4c5 8511
c19d1205 8512static const struct reg_entry reg_names[] =
7ed4c4c5 8513{
c19d1205
ZW
8514 /* ARM integer registers. */
8515 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 8516
c19d1205
ZW
8517 /* ATPCS synonyms. */
8518 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
8519 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
8520 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 8521
c19d1205
ZW
8522 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
8523 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
8524 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 8525
c19d1205
ZW
8526 /* Well-known aliases. */
8527 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
8528 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
8529
8530 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
8531 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
8532
8533 /* Coprocessor numbers. */
8534 REGSET(p, CP), REGSET(P, CP),
8535
8536 /* Coprocessor register numbers. The "cr" variants are for backward
8537 compatibility. */
8538 REGSET(c, CN), REGSET(C, CN),
8539 REGSET(cr, CN), REGSET(CR, CN),
8540
8541 /* FPA registers. */
8542 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
8543 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
8544
8545 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
8546 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
8547
8548 /* VFP SP registers. */
8549 REGSET(s,VFS),
8550 REGNUM(s,16,VFS), REGNUM(s,17,VFS), REGNUM(s,18,VFS), REGNUM(s,19,VFS),
8551 REGNUM(s,20,VFS), REGNUM(s,21,VFS), REGNUM(s,22,VFS), REGNUM(s,23,VFS),
8552 REGNUM(s,24,VFS), REGNUM(s,25,VFS), REGNUM(s,26,VFS), REGNUM(s,27,VFS),
8553 REGNUM(s,28,VFS), REGNUM(s,29,VFS), REGNUM(s,30,VFS), REGNUM(s,31,VFS),
8554
8555 REGSET(S,VFS),
8556 REGNUM(S,16,VFS), REGNUM(S,17,VFS), REGNUM(S,18,VFS), REGNUM(S,19,VFS),
8557 REGNUM(S,20,VFS), REGNUM(S,21,VFS), REGNUM(S,22,VFS), REGNUM(S,23,VFS),
8558 REGNUM(S,24,VFS), REGNUM(S,25,VFS), REGNUM(S,26,VFS), REGNUM(S,27,VFS),
8559 REGNUM(S,28,VFS), REGNUM(S,29,VFS), REGNUM(S,30,VFS), REGNUM(S,31,VFS),
8560
8561 /* VFP DP Registers. */
8562 REGSET(d,VFD), REGSET(D,VFS),
8563
8564 /* VFP control registers. */
8565 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
8566 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
8567
8568 /* Maverick DSP coprocessor registers. */
8569 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
8570 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
8571
8572 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
8573 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
8574 REGDEF(dspsc,0,DSPSC),
8575
8576 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
8577 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
8578 REGDEF(DSPSC,0,DSPSC),
8579
8580 /* iWMMXt data registers - p0, c0-15. */
8581 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
8582
8583 /* iWMMXt control registers - p1, c0-3. */
8584 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
8585 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
8586 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
8587 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
8588
8589 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
8590 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
8591 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
8592 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
8593 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
8594
8595 /* XScale accumulator registers. */
8596 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
8597};
8598#undef REGDEF
8599#undef REGNUM
8600#undef REGSET
7ed4c4c5 8601
c19d1205
ZW
8602/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
8603 within psr_required_here. */
8604static const struct asm_psr psrs[] =
8605{
8606 /* Backward compatibility notation. Note that "all" is no longer
8607 truly all possible PSR bits. */
8608 {"all", PSR_c | PSR_f},
8609 {"flg", PSR_f},
8610 {"ctl", PSR_c},
8611
8612 /* Individual flags. */
8613 {"f", PSR_f},
8614 {"c", PSR_c},
8615 {"x", PSR_x},
8616 {"s", PSR_s},
8617 /* Combinations of flags. */
8618 {"fs", PSR_f | PSR_s},
8619 {"fx", PSR_f | PSR_x},
8620 {"fc", PSR_f | PSR_c},
8621 {"sf", PSR_s | PSR_f},
8622 {"sx", PSR_s | PSR_x},
8623 {"sc", PSR_s | PSR_c},
8624 {"xf", PSR_x | PSR_f},
8625 {"xs", PSR_x | PSR_s},
8626 {"xc", PSR_x | PSR_c},
8627 {"cf", PSR_c | PSR_f},
8628 {"cs", PSR_c | PSR_s},
8629 {"cx", PSR_c | PSR_x},
8630 {"fsx", PSR_f | PSR_s | PSR_x},
8631 {"fsc", PSR_f | PSR_s | PSR_c},
8632 {"fxs", PSR_f | PSR_x | PSR_s},
8633 {"fxc", PSR_f | PSR_x | PSR_c},
8634 {"fcs", PSR_f | PSR_c | PSR_s},
8635 {"fcx", PSR_f | PSR_c | PSR_x},
8636 {"sfx", PSR_s | PSR_f | PSR_x},
8637 {"sfc", PSR_s | PSR_f | PSR_c},
8638 {"sxf", PSR_s | PSR_x | PSR_f},
8639 {"sxc", PSR_s | PSR_x | PSR_c},
8640 {"scf", PSR_s | PSR_c | PSR_f},
8641 {"scx", PSR_s | PSR_c | PSR_x},
8642 {"xfs", PSR_x | PSR_f | PSR_s},
8643 {"xfc", PSR_x | PSR_f | PSR_c},
8644 {"xsf", PSR_x | PSR_s | PSR_f},
8645 {"xsc", PSR_x | PSR_s | PSR_c},
8646 {"xcf", PSR_x | PSR_c | PSR_f},
8647 {"xcs", PSR_x | PSR_c | PSR_s},
8648 {"cfs", PSR_c | PSR_f | PSR_s},
8649 {"cfx", PSR_c | PSR_f | PSR_x},
8650 {"csf", PSR_c | PSR_s | PSR_f},
8651 {"csx", PSR_c | PSR_s | PSR_x},
8652 {"cxf", PSR_c | PSR_x | PSR_f},
8653 {"cxs", PSR_c | PSR_x | PSR_s},
8654 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
8655 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
8656 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
8657 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
8658 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
8659 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
8660 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
8661 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
8662 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
8663 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
8664 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
8665 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
8666 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
8667 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
8668 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
8669 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
8670 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
8671 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
8672 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
8673 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
8674 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
8675 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
8676 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
8677 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
8678};
8679
62b3e311
PB
8680/* Table of V7M psr names. */
8681static const struct asm_psr v7m_psrs[] =
8682{
8683 {"apsr", 0 },
8684 {"iapsr", 1 },
8685 {"eapsr", 2 },
8686 {"psr", 3 },
8687 {"ipsr", 5 },
8688 {"epsr", 6 },
8689 {"iepsr", 7 },
8690 {"msp", 8 },
8691 {"psp", 9 },
8692 {"primask", 16},
8693 {"basepri", 17},
8694 {"basepri_max", 18},
8695 {"faultmask", 19},
8696 {"control", 20}
8697};
8698
c19d1205
ZW
8699/* Table of all shift-in-operand names. */
8700static const struct asm_shift_name shift_names [] =
b99bd4ef 8701{
c19d1205
ZW
8702 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
8703 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
8704 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
8705 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
8706 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
8707 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
8708};
b99bd4ef 8709
c19d1205
ZW
8710/* Table of all explicit relocation names. */
8711#ifdef OBJ_ELF
8712static struct reloc_entry reloc_names[] =
8713{
8714 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
8715 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
8716 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
8717 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
8718 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
8719 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
8720 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
8721 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
8722 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
8723 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
8724 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
8725};
8726#endif
b99bd4ef 8727
c19d1205
ZW
8728/* Table of all conditional affixes. 0xF is not defined as a condition code. */
8729static const struct asm_cond conds[] =
8730{
8731 {"eq", 0x0},
8732 {"ne", 0x1},
8733 {"cs", 0x2}, {"hs", 0x2},
8734 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
8735 {"mi", 0x4},
8736 {"pl", 0x5},
8737 {"vs", 0x6},
8738 {"vc", 0x7},
8739 {"hi", 0x8},
8740 {"ls", 0x9},
8741 {"ge", 0xa},
8742 {"lt", 0xb},
8743 {"gt", 0xc},
8744 {"le", 0xd},
8745 {"al", 0xe}
8746};
bfae80f2 8747
62b3e311
PB
8748static struct asm_barrier_opt barrier_opt_names[] =
8749{
8750 { "sy", 0xf },
8751 { "un", 0x7 },
8752 { "st", 0xe },
8753 { "unst", 0x6 }
8754};
8755
c19d1205
ZW
8756/* Table of ARM-format instructions. */
8757
8758/* Macros for gluing together operand strings. N.B. In all cases
8759 other than OPS0, the trailing OP_stop comes from default
8760 zero-initialization of the unspecified elements of the array. */
8761#define OPS0() { OP_stop, }
8762#define OPS1(a) { OP_##a, }
8763#define OPS2(a,b) { OP_##a,OP_##b, }
8764#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
8765#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
8766#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
8767#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
8768
8769/* These macros abstract out the exact format of the mnemonic table and
8770 save some repeated characters. */
8771
8772/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
8773#define TxCE(mnem, op, top, nops, ops, ae, te) \
8774 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 8775 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8776
8777/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
8778 a T_MNEM_xyz enumerator. */
8779#define TCE(mnem, aop, top, nops, ops, ae, te) \
8780 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
8781#define tCE(mnem, aop, top, nops, ops, ae, te) \
8782 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8783
8784/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
8785 infix after the third character. */
8786#define TxC3(mnem, op, top, nops, ops, ae, te) \
8787 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 8788 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8789#define TC3(mnem, aop, top, nops, ops, ae, te) \
8790 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
8791#define tC3(mnem, aop, top, nops, ops, ae, te) \
8792 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
8793
8794/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
8795 appear in the condition table. */
8796#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
8797 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 8798 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8799
8800#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
8801 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
8802 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
8803 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
8804 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
8805 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
8806 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
8807 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
8808 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
8809 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
8810 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
8811 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
8812 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
8813 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
8814 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
8815 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
8816 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
8817 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
8818 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
8819 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
8820
8821#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
8822 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
8823#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
8824 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
8825
8826/* Mnemonic that cannot be conditionalized. The ARM condition-code
8827 field is still 0xE. */
8828#define TUE(mnem, op, top, nops, ops, ae, te) \
8829 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8830 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8831
8832/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
8833 condition code field. */
8834#define TUF(mnem, op, top, nops, ops, ae, te) \
8835 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 8836 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
8837
8838/* ARM-only variants of all the above. */
6a86118a
NC
8839#define CE(mnem, op, nops, ops, ae) \
8840 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8841
8842#define C3(mnem, op, nops, ops, ae) \
8843 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8844
e3cb604e
PB
8845/* Legacy mnemonics that always have conditional infix after the third
8846 character. */
8847#define CL(mnem, op, nops, ops, ae) \
8848 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8849 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8850
8f06b2d8
PB
8851/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
8852#define cCE(mnem, op, nops, ops, ae) \
8853 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8854
e3cb604e
PB
8855/* Legacy coprocessor instructions where conditional infix and conditional
8856 suffix are ambiguous. For consistency this includes all FPA instructions,
8857 not just the potentially ambiguous ones. */
8858#define cCL(mnem, op, nops, ops, ae) \
8859 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
8860 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8861
8862/* Coprocessor, takes either a suffix or a position-3 infix
8863 (for an FPA corner case). */
8864#define C3E(mnem, op, nops, ops, ae) \
8865 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
8866 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 8867
6a86118a
NC
8868#define xCM_(m1, m2, m3, op, nops, ops, ae) \
8869 { #m1 #m2 #m3, OPS##nops ops, \
8870 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
8871 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
8872
8873#define CM(m1, m2, op, nops, ops, ae) \
8874 xCM_(m1, , m2, op, nops, ops, ae), \
8875 xCM_(m1, eq, m2, op, nops, ops, ae), \
8876 xCM_(m1, ne, m2, op, nops, ops, ae), \
8877 xCM_(m1, cs, m2, op, nops, ops, ae), \
8878 xCM_(m1, hs, m2, op, nops, ops, ae), \
8879 xCM_(m1, cc, m2, op, nops, ops, ae), \
8880 xCM_(m1, ul, m2, op, nops, ops, ae), \
8881 xCM_(m1, lo, m2, op, nops, ops, ae), \
8882 xCM_(m1, mi, m2, op, nops, ops, ae), \
8883 xCM_(m1, pl, m2, op, nops, ops, ae), \
8884 xCM_(m1, vs, m2, op, nops, ops, ae), \
8885 xCM_(m1, vc, m2, op, nops, ops, ae), \
8886 xCM_(m1, hi, m2, op, nops, ops, ae), \
8887 xCM_(m1, ls, m2, op, nops, ops, ae), \
8888 xCM_(m1, ge, m2, op, nops, ops, ae), \
8889 xCM_(m1, lt, m2, op, nops, ops, ae), \
8890 xCM_(m1, gt, m2, op, nops, ops, ae), \
8891 xCM_(m1, le, m2, op, nops, ops, ae), \
8892 xCM_(m1, al, m2, op, nops, ops, ae)
8893
8894#define UE(mnem, op, nops, ops, ae) \
8895 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8896
8897#define UF(mnem, op, nops, ops, ae) \
8898 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
8899
c19d1205
ZW
8900#define do_0 0
8901
8902/* Thumb-only, unconditional. */
8903#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
8904
c19d1205 8905static const struct asm_opcode insns[] =
bfae80f2 8906{
e74cfd16
PB
8907#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
8908#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
8909 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
8910 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
8911 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
8912 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
8913 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
8914 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
8915 tCE(add, 0800000, add, 3, (RR, oRR, SH), arit, t_add_sub),
8916 tC3(adds, 0900000, adds, 3, (RR, oRR, SH), arit, t_add_sub),
8917 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
8918 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
8919 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
8920 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
8921 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
8922 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
8923 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
8924 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
8925
8926 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
8927 for setting PSR flag bits. They are obsolete in V6 and do not
8928 have Thumb equivalents. */
8929 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
8930 tC3(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8931 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205
ZW
8932 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
8933 tC3(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 8934 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205
ZW
8935 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
8936 tC3(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8937 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
8938
8939 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
8940 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
8941 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
8942 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
8943
8944 tCE(ldr, 4100000, ldr, 2, (RR, ADDR), ldst, t_ldst),
8945 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDR), ldst, t_ldst),
8946 tCE(str, 4000000, str, 2, (RR, ADDR), ldst, t_ldst),
8947 tC3(strb, 4400000, strb, 2, (RR, ADDR), ldst, t_ldst),
8948
f5208ef2 8949 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8950 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8951 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 8952 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
8953 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8954 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8955
8956 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 8957 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 8958 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 8959 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 8960
c19d1205 8961 /* Pseudo ops. */
e9f89963 8962 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
8963 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
8964 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
8965
8966 /* Thumb-compatibility pseudo ops. */
8967 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
8968 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
8969 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
8970 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
8971 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 8972 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
8973 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
8974 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
8975 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
8976 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
8977 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
8978 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
8979
8980#undef THUMB_VARIANT
e74cfd16 8981#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 8982 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
8983
8984 /* V1 instructions with no Thumb analogue prior to V6T2. */
8985#undef THUMB_VARIANT
e74cfd16 8986#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
8987 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
8988 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
8989 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
8990 TC3(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 8991 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
8992
8993 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
8994 TC3(ldrbt, 4700000, f8300e00, 2, (RR, ADDR), ldstt, t_ldstt),
8995 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
8996 TC3(strbt, 4600000, f8200e00, 2, (RR, ADDR), ldstt, t_ldstt),
8997
9c3c69f2
PB
8998 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
8999 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 9000
9c3c69f2
PB
9001 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
9002 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
9003
9004 /* V1 instructions with no Thumb analogue at all. */
9005 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
9006 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
9007
9008 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
9009 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
9010 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
9011 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
9012 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
9013 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
9014 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
9015 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
9016
9017#undef ARM_VARIANT
e74cfd16 9018#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 9019#undef THUMB_VARIANT
e74cfd16 9020#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
9021 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
9022 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
9023
9024#undef THUMB_VARIANT
e74cfd16 9025#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9026 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
9027 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
9028
9029 /* Generic coprocessor instructions. */
9030 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
9031 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDR), lstc, lstc),
9032 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDR), lstc, lstc),
9033 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDR), lstc, lstc),
9034 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDR), lstc, lstc),
9035 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9036 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9037
9038#undef ARM_VARIANT
e74cfd16 9039#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
9040 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
9041 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
9042
9043#undef ARM_VARIANT
e74cfd16 9044#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
c19d1205
ZW
9045 TCE(mrs, 10f0000, f3ef8000, 2, (RR, PSR), mrs, t_mrs),
9046 TCE(msr, 120f000, f3808000, 2, (PSR, RR_EXi), msr, t_msr),
9047
9048#undef ARM_VARIANT
e74cfd16 9049#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
c19d1205
ZW
9050 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9051 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9052 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9053 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9054 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9055 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9056 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
9057 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
9058
9059#undef ARM_VARIANT
e74cfd16 9060#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 9061#undef THUMB_VARIANT
e74cfd16 9062#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
9063 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDR), ldstv4, t_ldst),
9064 tC3(strh, 00000b0, strh, 2, (RR, ADDR), ldstv4, t_ldst),
9065 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
9066 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
9067 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDR), ldstv4, t_ldst),
9068 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDR), ldstv4, t_ldst),
9069
9070#undef ARM_VARIANT
e74cfd16 9071#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
9072 /* ARM Architecture 4T. */
9073 /* Note: bx (and blx) are required on V5, even if the processor does
9074 not support Thumb. */
9075 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
9076
9077#undef ARM_VARIANT
e74cfd16 9078#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 9079#undef THUMB_VARIANT
e74cfd16 9080#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
9081 /* Note: blx has 2 variants; the .value coded here is for
9082 BLX(2). Only this variant has conditional execution. */
9083 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
9084 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
9085
9086#undef THUMB_VARIANT
e74cfd16 9087#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9088 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
9089 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDR), lstc, lstc),
9090 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDR), lstc, lstc),
9091 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDR), lstc, lstc),
9092 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDR), lstc, lstc),
9093 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
9094 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9095 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
9096
9097#undef ARM_VARIANT
e74cfd16 9098#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
9099 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9100 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9101 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9102 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9103
9104 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9105 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
9106
9107 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9108 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9109 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9110 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
9111
9112 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9113 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9114 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9115 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9116
9117 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9118 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9119
9120 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9121 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9122 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9123 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
9124
9125#undef ARM_VARIANT
e74cfd16 9126#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205
ZW
9127 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
9128 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
9129 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDR), ldrd, t_ldstd),
9130
9131 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9132 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9133
9134#undef ARM_VARIANT
e74cfd16 9135#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
9136 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
9137
9138#undef ARM_VARIANT
e74cfd16 9139#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 9140#undef THUMB_VARIANT
e74cfd16 9141#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
9142 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
9143 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
9144 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9145 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9146 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
9147 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9148 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9149 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9150 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9151 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
9152
9153#undef THUMB_VARIANT
e74cfd16 9154#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9155 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
9156 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
9157 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
9158
9159 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
9160 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
9161
9162/* ARM V6 not included in V7M (eg. integer SIMD). */
9163#undef THUMB_VARIANT
9164#define THUMB_VARIANT &arm_ext_v6_notm
9165 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, imm0),
c19d1205
ZW
9166 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
9167 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
9168 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9169 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9170 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9171 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9172 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9173 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9174 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9175 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9176 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9177 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9178 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9179 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9180 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9181 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9182 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9183 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9184 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9185 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9186 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9187 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9188 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9189 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9190 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9191 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9192 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9193 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9194 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9195 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9196 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9197 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9198 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9199 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9200 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9201 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9202 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9203 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
9204 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
9205 UF(rfeib, 9900a00, 1, (RRw), rfe),
9206 UF(rfeda, 8100a00, 1, (RRw), rfe),
9207 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
9208 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
9209 UF(rfefa, 9900a00, 1, (RRw), rfe),
9210 UF(rfeea, 8100a00, 1, (RRw), rfe),
9211 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
9212 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9213 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9214 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9215 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
9216 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9217 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9218 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
9219 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 9220 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
9221 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9222 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9223 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9224 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9225 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9226 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9227 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9228 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
9229 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9230 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9231 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9232 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
9233 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9234 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9235 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9236 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9237 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9238 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9239 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
9240 UF(srsib, 9cd0500, 1, (I31w), srs),
9241 UF(srsda, 84d0500, 1, (I31w), srs),
9242 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
c19d1205
ZW
9243 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
9244 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
9245 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
9246 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
9247 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
9248 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
9249
9250#undef ARM_VARIANT
e74cfd16 9251#define ARM_VARIANT &arm_ext_v6k
c19d1205 9252#undef THUMB_VARIANT
e74cfd16 9253#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
9254 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
9255 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
9256 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
9257 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
9258
ebdca51a
PB
9259#undef THUMB_VARIANT
9260#define THUMB_VARIANT &arm_ext_v6_notm
9261 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
9262 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
9263
c19d1205 9264#undef THUMB_VARIANT
e74cfd16 9265#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
9266 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
9267 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
9268 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
9269 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
9270 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
9271
9272#undef ARM_VARIANT
e74cfd16 9273#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 9274 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
9275
9276#undef ARM_VARIANT
e74cfd16 9277#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
9278 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
9279 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
9280 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
9281 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
9282
9283 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
9284 TCE(movw, 3000000, f2400000, 2, (RRnpc, Iffff), mov16, t_mov16),
9285 TCE(movt, 3400000, f2c00000, 2, (RRnpc, Iffff), mov16, t_mov16),
9286 TCE(rbit, 3ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
9287
9288 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9289 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9290 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9291 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
9292
9293 UT(cbnz, b900, 2, (RR, EXP), t_czb),
9294 UT(cbz, b100, 2, (RR, EXP), t_czb),
9295 /* ARM does not really have an IT instruction. */
9296 TUE(it, 0, bf08, 1, (COND), it, t_it),
9297 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
9298 TUE(ite, 0, bf04, 1, (COND), it, t_it),
9299 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
9300 TUE(itet, 0, bf06, 1, (COND), it, t_it),
9301 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
9302 TUE(itee, 0, bf02, 1, (COND), it, t_it),
9303 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
9304 TUE(itett, 0, bf07, 1, (COND), it, t_it),
9305 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
9306 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
9307 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
9308 TUE(itete, 0, bf05, 1, (COND), it, t_it),
9309 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
9310 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
9311
92e90b6e
PB
9312 /* Thumb2 only instructions. */
9313#undef ARM_VARIANT
e74cfd16 9314#define ARM_VARIANT NULL
92e90b6e
PB
9315
9316 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9317 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
9318 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
9319 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
9320
62b3e311
PB
9321 /* Thumb-2 hardware division instructions (R and M profiles only). */
9322#undef THUMB_VARIANT
9323#define THUMB_VARIANT &arm_ext_div
9324 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
9325 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
9326
9327 /* ARM V7 instructions. */
9328#undef ARM_VARIANT
9329#define ARM_VARIANT &arm_ext_v7
9330#undef THUMB_VARIANT
9331#define THUMB_VARIANT &arm_ext_v7
9332 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
9333 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
9334 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
9335 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
9336 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
9337
c19d1205 9338#undef ARM_VARIANT
e74cfd16 9339#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
9340 cCE(wfs, e200110, 1, (RR), rd),
9341 cCE(rfs, e300110, 1, (RR), rd),
9342 cCE(wfc, e400110, 1, (RR), rd),
9343 cCE(rfc, e500110, 1, (RR), rd),
9344
e3cb604e
PB
9345 cCL(ldfs, c100100, 2, (RF, ADDR), rd_cpaddr),
9346 cCL(ldfd, c108100, 2, (RF, ADDR), rd_cpaddr),
9347 cCL(ldfe, c500100, 2, (RF, ADDR), rd_cpaddr),
9348 cCL(ldfp, c508100, 2, (RF, ADDR), rd_cpaddr),
9349
9350 cCL(stfs, c000100, 2, (RF, ADDR), rd_cpaddr),
9351 cCL(stfd, c008100, 2, (RF, ADDR), rd_cpaddr),
9352 cCL(stfe, c400100, 2, (RF, ADDR), rd_cpaddr),
9353 cCL(stfp, c408100, 2, (RF, ADDR), rd_cpaddr),
9354
9355 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
9356 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
9357 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
9358 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
9359 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
9360 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
9361 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
9362 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
9363 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
9364 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
9365 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
9366 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
9367
9368 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
9369 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
9370 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
9371 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
9372 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
9373 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
9374 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
9375 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
9376 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
9377 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
9378 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
9379 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
9380
9381 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
9382 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
9383 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
9384 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
9385 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
9386 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
9387 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
9388 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
9389 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
9390 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
9391 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
9392 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
9393
9394 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
9395 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
9396 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
9397 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
9398 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
9399 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
9400 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
9401 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
9402 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
9403 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
9404 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
9405 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
9406
9407 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
9408 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
9409 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
9410 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
9411 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
9412 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
9413 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
9414 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
9415 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
9416 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
9417 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
9418 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
9419
9420 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
9421 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
9422 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
9423 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
9424 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
9425 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
9426 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
9427 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
9428 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
9429 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
9430 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
9431 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
9432
9433 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
9434 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
9435 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
9436 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
9437 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
9438 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
9439 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
9440 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
9441 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
9442 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
9443 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
9444 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
9445
9446 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
9447 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
9448 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
9449 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
9450 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
9451 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
9452 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
9453 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
9454 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
9455 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
9456 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
9457 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
9458
9459 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
9460 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
9461 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
9462 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
9463 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
9464 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
9465 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
9466 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
9467 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
9468 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
9469 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
9470 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
9471
9472 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
9473 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
9474 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
9475 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
9476 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
9477 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
9478 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
9479 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
9480 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
9481 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
9482 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
9483 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
9484
9485 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
9486 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
9487 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
9488 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
9489 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
9490 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
9491 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
9492 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
9493 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
9494 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
9495 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
9496 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
9497
9498 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
9499 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
9500 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
9501 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
9502 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
9503 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
9504 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
9505 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
9506 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
9507 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
9508 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
9509 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
9510
9511 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
9512 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
9513 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
9514 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
9515 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
9516 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
9517 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
9518 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
9519 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
9520 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
9521 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
9522 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
9523
9524 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
9525 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
9526 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
9527 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
9528 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
9529 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
9530 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
9531 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
9532 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
9533 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
9534 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
9535 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
9536
9537 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
9538 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
9539 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
9540 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
9541 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
9542 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
9543 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
9544 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
9545 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
9546 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
9547 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
9548 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
9549
9550 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
9551 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
9552 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
9553 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
9554 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
9555 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
9556 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
9557 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
9558 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
9559 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
9560 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
9561 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
9562
9563 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
9564 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
9565 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
9566 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
9567 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
9568 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9569 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9570 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9571 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
9572 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
9573 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
9574 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
9575
9576 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
9577 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
9578 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
9579 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
9580 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
9581 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9582 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9583 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9584 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
9585 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
9586 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
9587 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
9588
9589 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
9590 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
9591 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
9592 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
9593 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
9594 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9595 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9596 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9597 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
9598 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
9599 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
9600 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
9601
9602 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
9603 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
9604 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
9605 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
9606 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
9607 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9608 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9609 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9610 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
9611 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
9612 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
9613 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
9614
9615 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
9616 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
9617 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
9618 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
9619 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
9620 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9621 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9622 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9623 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
9624 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
9625 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
9626 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
9627
9628 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
9629 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
9630 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
9631 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
9632 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
9633 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9634 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9635 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9636 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
9637 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
9638 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
9639 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
9640
9641 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
9642 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
9643 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
9644 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
9645 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
9646 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9647 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9648 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9649 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
9650 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
9651 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
9652 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
9653
9654 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
9655 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
9656 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
9657 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
9658 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
9659 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9660 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9661 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9662 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
9663 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
9664 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
9665 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
9666
9667 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
9668 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
9669 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
9670 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
9671 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
9672 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9673 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9674 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9675 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
9676 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
9677 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
9678 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
9679
9680 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
9681 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
9682 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
9683 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
9684 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
9685 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9686 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9687 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9688 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
9689 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
9690 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
9691 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
9692
9693 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9694 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9695 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9696 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9697 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9698 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9699 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9700 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9701 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9702 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9703 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9704 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9705
9706 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9707 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9708 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9709 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9710 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9711 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9712 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9713 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9714 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9715 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9716 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9717 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
9718
9719 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
9720 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
9721 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
9722 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
9723 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
9724 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
9725 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
9726 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
9727 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
9728 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
9729 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
9730 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
9731
9732 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 9733 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 9734 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
9735 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
9736
e3cb604e
PB
9737 cCL(flts, e000110, 2, (RF, RR), rn_rd),
9738 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
9739 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
9740 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
9741 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
9742 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
9743 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
9744 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
9745 cCL(flte, e080110, 2, (RF, RR), rn_rd),
9746 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
9747 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
9748 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 9749
c19d1205
ZW
9750 /* The implementation of the FIX instruction is broken on some
9751 assemblers, in that it accepts a precision specifier as well as a
9752 rounding specifier, despite the fact that this is meaningless.
9753 To be more compatible, we accept it as well, though of course it
9754 does not set any bits. */
8f06b2d8 9755 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
9756 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
9757 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
9758 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
9759 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
9760 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
9761 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
9762 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
9763 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
9764 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
9765 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
9766 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
9767 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 9768
c19d1205
ZW
9769 /* Instructions that were new with the real FPA, call them V2. */
9770#undef ARM_VARIANT
e74cfd16 9771#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 9772 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
9773 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9774 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 9775 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
9776 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
9777 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
9778
9779#undef ARM_VARIANT
e74cfd16 9780#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 9781 /* Moves and type conversions. */
8f06b2d8
PB
9782 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
9783 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
9784 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
9785 cCE(fmstat, ef1fa10, 0, (), noargs),
9786 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
9787 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
9788 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
9789 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9790 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
9791 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
9792 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
9793 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
9794
9795 /* Memory operations. */
8f06b2d8
PB
9796 cCE(flds, d100a00, 2, (RVS, ADDR), vfp_sp_ldst),
9797 cCE(fsts, d000a00, 2, (RVS, ADDR), vfp_sp_ldst),
9798 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9799 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9800 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9801 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9802 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9803 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9804 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9805 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9806 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9807 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
9808 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9809 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
9810 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9811 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
9812 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
9813 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 9814
c19d1205 9815 /* Monadic operations. */
8f06b2d8
PB
9816 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
9817 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
9818 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
9819
9820 /* Dyadic operations. */
8f06b2d8
PB
9821 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9822 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9823 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9824 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9825 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9826 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9827 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9828 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
9829 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 9830
c19d1205 9831 /* Comparisons. */
8f06b2d8
PB
9832 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
9833 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
9834 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
9835 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 9836
c19d1205 9837#undef ARM_VARIANT
e74cfd16 9838#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 9839 /* Moves and type conversions. */
8f06b2d8
PB
9840 cCE(fcpyd, eb00b40, 2, (RVD, RVD), rd_rm),
9841 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9842 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9843 cCE(fmdhr, e200b10, 2, (RVD, RR), rn_rd),
9844 cCE(fmdlr, e000b10, 2, (RVD, RR), rn_rd),
9845 cCE(fmrdh, e300b10, 2, (RR, RVD), rd_rn),
9846 cCE(fmrdl, e100b10, 2, (RR, RVD), rd_rn),
9847 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
9848 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
9849 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9850 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
9851 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
9852 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
9853
9854 /* Memory operations. */
8f06b2d8
PB
9855 cCE(fldd, d100b00, 2, (RVD, ADDR), vfp_dp_ldst),
9856 cCE(fstd, d000b00, 2, (RVD, ADDR), vfp_dp_ldst),
9857 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9858 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9859 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9860 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9861 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9862 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
9863 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
9864 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 9865
c19d1205 9866 /* Monadic operations. */
8f06b2d8
PB
9867 cCE(fabsd, eb00bc0, 2, (RVD, RVD), rd_rm),
9868 cCE(fnegd, eb10b40, 2, (RVD, RVD), rd_rm),
9869 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), rd_rm),
c19d1205
ZW
9870
9871 /* Dyadic operations. */
8f06b2d8
PB
9872 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9873 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9874 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9875 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9876 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9877 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), rd_rn_rm),
9878 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9879 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), rd_rn_rm),
9880 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), rd_rn_rm),
b99bd4ef 9881
c19d1205 9882 /* Comparisons. */
8f06b2d8
PB
9883 cCE(fcmpd, eb40b40, 2, (RVD, RVD), rd_rm),
9884 cCE(fcmpzd, eb50b40, 1, (RVD), rd),
9885 cCE(fcmped, eb40bc0, 2, (RVD, RVD), rd_rm),
9886 cCE(fcmpezd, eb50bc0, 1, (RVD), rd),
c19d1205
ZW
9887
9888#undef ARM_VARIANT
e74cfd16 9889#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
9890 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
9891 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
9892 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), rm_rd_rn),
9893 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), rd_rn_rm),
c19d1205
ZW
9894
9895#undef ARM_VARIANT
e74cfd16 9896#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
9897 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9898 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9899 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9900 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9901 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9902 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
9903 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
9904 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
9905
9906#undef ARM_VARIANT
e74cfd16 9907#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
9908 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
9909 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
9910 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
9911 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
9912 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
9913 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
9914 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
9915 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
9916 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
9917 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9918 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9919 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
9920 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9921 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9922 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
9923 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9924 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9925 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
9926 cCE(tmcr, e000110, 2, (RIWC, RR), rn_rd),
9927 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
9928 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9929 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9930 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9931 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9932 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9933 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
9934 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
9935 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
9936 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
9937 cCE(tmrc, e100110, 2, (RR, RIWC), rd_rn),
9938 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
9939 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
9940 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
9941 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
9942 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
9943 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
9944 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
9945 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9946 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9947 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9948 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9949 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9950 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9951 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9952 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9953 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9954 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
9955 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9956 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9957 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9958 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9959 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9960 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9961 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9962 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9963 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9964 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9965 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9966 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9967 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9968 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9969 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9970 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9971 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9972 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9973 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9974 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9975 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
9976 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
9977 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
9978 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9979 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9980 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9981 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9982 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9983 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9984 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9985 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9986 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9987 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9988 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9989 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9990 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9991 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9992 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9993 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9994 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9995 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9996 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
9997 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9998 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
9999 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10000 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10001 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10002 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10003 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10004 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10005 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10006 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10007 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10008 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10009 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10010 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10011 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10012 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10013 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10014 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10015 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10016 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10017 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10018 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
10019 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10020 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10021 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10022 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10023 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10024 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10025 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10026 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10027 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10028 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10029 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10030 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10031 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10032 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10033 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10034 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10035 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10036 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
10037 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10038 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
10039 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
10040 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
10041 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10042 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10043 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10044 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10045 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10046 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10047 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10048 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10049 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10050 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
10051 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
10052 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
10053 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
10054 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
10055 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
10056 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10057 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10058 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10059 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
10060 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
10061 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
10062 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
10063 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
10064 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
10065 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10066 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10067 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10068 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
10069 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205
ZW
10070
10071#undef ARM_VARIANT
e74cfd16 10072#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
8f06b2d8
PB
10073 cCE(cfldrs, c100400, 2, (RMF, ADDR), rd_cpaddr),
10074 cCE(cfldrd, c500400, 2, (RMD, ADDR), rd_cpaddr),
10075 cCE(cfldr32, c100500, 2, (RMFX, ADDR), rd_cpaddr),
10076 cCE(cfldr64, c500500, 2, (RMDX, ADDR), rd_cpaddr),
10077 cCE(cfstrs, c000400, 2, (RMF, ADDR), rd_cpaddr),
10078 cCE(cfstrd, c400400, 2, (RMD, ADDR), rd_cpaddr),
10079 cCE(cfstr32, c000500, 2, (RMFX, ADDR), rd_cpaddr),
10080 cCE(cfstr64, c400500, 2, (RMDX, ADDR), rd_cpaddr),
10081 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
10082 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
10083 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
10084 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
10085 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
10086 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
10087 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
10088 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
10089 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
10090 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
10091 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
10092 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
10093 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
10094 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
10095 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
10096 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
10097 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
10098 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
10099 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
10100 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
10101 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
10102 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
10103 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
10104 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
10105 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
10106 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
10107 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
10108 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
10109 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
10110 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
10111 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
10112 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
10113 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
10114 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
10115 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
10116 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
10117 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
10118 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
10119 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
10120 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
10121 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
10122 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
10123 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
10124 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
10125 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
10126 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
10127 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
10128 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
10129 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
10130 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
10131 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
10132 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
10133 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
10134 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
10135 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
10136 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
10137 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10138 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10139 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10140 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10141 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10142 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
10143 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10144 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
10145 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
10146 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
10147 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
10148 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
10149};
10150#undef ARM_VARIANT
10151#undef THUMB_VARIANT
10152#undef TCE
10153#undef TCM
10154#undef TUE
10155#undef TUF
10156#undef TCC
8f06b2d8 10157#undef cCE
e3cb604e
PB
10158#undef cCL
10159#undef C3E
c19d1205
ZW
10160#undef CE
10161#undef CM
10162#undef UE
10163#undef UF
10164#undef UT
10165#undef OPS0
10166#undef OPS1
10167#undef OPS2
10168#undef OPS3
10169#undef OPS4
10170#undef OPS5
10171#undef OPS6
10172#undef do_0
10173\f
10174/* MD interface: bits in the object file. */
bfae80f2 10175
c19d1205
ZW
10176/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
10177 for use in the a.out file, and stores them in the array pointed to by buf.
10178 This knows about the endian-ness of the target machine and does
10179 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
10180 2 (short) and 4 (long) Floating numbers are put out as a series of
10181 LITTLENUMS (shorts, here at least). */
b99bd4ef 10182
c19d1205
ZW
10183void
10184md_number_to_chars (char * buf, valueT val, int n)
10185{
10186 if (target_big_endian)
10187 number_to_chars_bigendian (buf, val, n);
10188 else
10189 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
10190}
10191
c19d1205
ZW
10192static valueT
10193md_chars_to_number (char * buf, int n)
bfae80f2 10194{
c19d1205
ZW
10195 valueT result = 0;
10196 unsigned char * where = (unsigned char *) buf;
bfae80f2 10197
c19d1205 10198 if (target_big_endian)
b99bd4ef 10199 {
c19d1205
ZW
10200 while (n--)
10201 {
10202 result <<= 8;
10203 result |= (*where++ & 255);
10204 }
b99bd4ef 10205 }
c19d1205 10206 else
b99bd4ef 10207 {
c19d1205
ZW
10208 while (n--)
10209 {
10210 result <<= 8;
10211 result |= (where[n] & 255);
10212 }
bfae80f2 10213 }
b99bd4ef 10214
c19d1205 10215 return result;
bfae80f2 10216}
b99bd4ef 10217
c19d1205 10218/* MD interface: Sections. */
b99bd4ef 10219
0110f2b8
PB
10220/* Estimate the size of a frag before relaxing. Assume everything fits in
10221 2 bytes. */
10222
c19d1205 10223int
0110f2b8 10224md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
10225 segT segtype ATTRIBUTE_UNUSED)
10226{
0110f2b8
PB
10227 fragp->fr_var = 2;
10228 return 2;
10229}
10230
10231/* Convert a machine dependent frag. */
10232
10233void
10234md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
10235{
10236 unsigned long insn;
10237 unsigned long old_op;
10238 char *buf;
10239 expressionS exp;
10240 fixS *fixp;
10241 int reloc_type;
10242 int pc_rel;
10243 int opcode;
10244
10245 buf = fragp->fr_literal + fragp->fr_fix;
10246
10247 old_op = bfd_get_16(abfd, buf);
10248 if (fragp->fr_symbol) {
10249 exp.X_op = O_symbol;
10250 exp.X_add_symbol = fragp->fr_symbol;
10251 } else {
10252 exp.X_op = O_constant;
10253 }
10254 exp.X_add_number = fragp->fr_offset;
10255 opcode = fragp->fr_subtype;
10256 switch (opcode)
10257 {
10258 case T_MNEM_ldr_pc:
10259 case T_MNEM_ldr_pc2:
10260 case T_MNEM_ldr_sp:
10261 case T_MNEM_str_sp:
10262 case T_MNEM_ldr:
10263 case T_MNEM_ldrb:
10264 case T_MNEM_ldrh:
10265 case T_MNEM_str:
10266 case T_MNEM_strb:
10267 case T_MNEM_strh:
10268 if (fragp->fr_var == 4)
10269 {
10270 insn = THUMB_OP32(opcode);
10271 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
10272 {
10273 insn |= (old_op & 0x700) << 4;
10274 }
10275 else
10276 {
10277 insn |= (old_op & 7) << 12;
10278 insn |= (old_op & 0x38) << 13;
10279 }
10280 insn |= 0x00000c00;
10281 put_thumb32_insn (buf, insn);
10282 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10283 }
10284 else
10285 {
10286 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
10287 }
10288 pc_rel = (opcode == T_MNEM_ldr_pc2);
10289 break;
10290 case T_MNEM_adr:
10291 if (fragp->fr_var == 4)
10292 {
10293 insn = THUMB_OP32 (opcode);
10294 insn |= (old_op & 0xf0) << 4;
10295 put_thumb32_insn (buf, insn);
10296 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
10297 }
10298 else
10299 {
10300 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10301 exp.X_add_number -= 4;
10302 }
10303 pc_rel = 1;
10304 break;
10305 case T_MNEM_mov:
10306 case T_MNEM_movs:
10307 case T_MNEM_cmp:
10308 case T_MNEM_cmn:
10309 if (fragp->fr_var == 4)
10310 {
10311 int r0off = (opcode == T_MNEM_mov
10312 || opcode == T_MNEM_movs) ? 0 : 8;
10313 insn = THUMB_OP32 (opcode);
10314 insn = (insn & 0xe1ffffff) | 0x10000000;
10315 insn |= (old_op & 0x700) << r0off;
10316 put_thumb32_insn (buf, insn);
10317 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10318 }
10319 else
10320 {
10321 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
10322 }
10323 pc_rel = 0;
10324 break;
10325 case T_MNEM_b:
10326 if (fragp->fr_var == 4)
10327 {
10328 insn = THUMB_OP32(opcode);
10329 put_thumb32_insn (buf, insn);
10330 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
10331 }
10332 else
10333 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
10334 pc_rel = 1;
10335 break;
10336 case T_MNEM_bcond:
10337 if (fragp->fr_var == 4)
10338 {
10339 insn = THUMB_OP32(opcode);
10340 insn |= (old_op & 0xf00) << 14;
10341 put_thumb32_insn (buf, insn);
10342 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
10343 }
10344 else
10345 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
10346 pc_rel = 1;
10347 break;
10348 case T_MNEM_add_sp:
10349 case T_MNEM_add_pc:
10350 case T_MNEM_inc_sp:
10351 case T_MNEM_dec_sp:
10352 if (fragp->fr_var == 4)
10353 {
10354 /* ??? Choose between add and addw. */
10355 insn = THUMB_OP32 (opcode);
10356 insn |= (old_op & 0xf0) << 4;
10357 put_thumb32_insn (buf, insn);
10358 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10359 }
10360 else
10361 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10362 pc_rel = 0;
10363 break;
10364
10365 case T_MNEM_addi:
10366 case T_MNEM_addis:
10367 case T_MNEM_subi:
10368 case T_MNEM_subis:
10369 if (fragp->fr_var == 4)
10370 {
10371 insn = THUMB_OP32 (opcode);
10372 insn |= (old_op & 0xf0) << 4;
10373 insn |= (old_op & 0xf) << 16;
10374 put_thumb32_insn (buf, insn);
10375 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
10376 }
10377 else
10378 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
10379 pc_rel = 0;
10380 break;
10381 default:
10382 abort();
10383 }
10384 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
10385 reloc_type);
10386 fixp->fx_file = fragp->fr_file;
10387 fixp->fx_line = fragp->fr_line;
10388 fragp->fr_fix += fragp->fr_var;
10389}
10390
10391/* Return the size of a relaxable immediate operand instruction.
10392 SHIFT and SIZE specify the form of the allowable immediate. */
10393static int
10394relax_immediate (fragS *fragp, int size, int shift)
10395{
10396 offsetT offset;
10397 offsetT mask;
10398 offsetT low;
10399
10400 /* ??? Should be able to do better than this. */
10401 if (fragp->fr_symbol)
10402 return 4;
10403
10404 low = (1 << shift) - 1;
10405 mask = (1 << (shift + size)) - (1 << shift);
10406 offset = fragp->fr_offset;
10407 /* Force misaligned offsets to 32-bit variant. */
10408 if (offset & low)
10409 return -4;
10410 if (offset & ~mask)
10411 return 4;
10412 return 2;
10413}
10414
10415/* Return the size of a relaxable adr pseudo-instruction or PC-relative
10416 load. */
10417static int
10418relax_adr (fragS *fragp, asection *sec)
10419{
10420 addressT addr;
10421 offsetT val;
10422
10423 /* Assume worst case for symbols not known to be in the same section. */
10424 if (!S_IS_DEFINED(fragp->fr_symbol)
10425 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10426 return 4;
10427
10428 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10429 addr = fragp->fr_address + fragp->fr_fix;
10430 addr = (addr + 4) & ~3;
10431 /* Fix the insn as the 4-byte version if the target address is not
10432 sufficiently aligned. This is prevents an infinite loop when two
10433 instructions have contradictory range/alignment requirements. */
10434 if (val & 3)
10435 return -4;
10436 val -= addr;
10437 if (val < 0 || val > 1020)
10438 return 4;
10439 return 2;
10440}
10441
10442/* Return the size of a relaxable add/sub immediate instruction. */
10443static int
10444relax_addsub (fragS *fragp, asection *sec)
10445{
10446 char *buf;
10447 int op;
10448
10449 buf = fragp->fr_literal + fragp->fr_fix;
10450 op = bfd_get_16(sec->owner, buf);
10451 if ((op & 0xf) == ((op >> 4) & 0xf))
10452 return relax_immediate (fragp, 8, 0);
10453 else
10454 return relax_immediate (fragp, 3, 0);
10455}
10456
10457
10458/* Return the size of a relaxable branch instruction. BITS is the
10459 size of the offset field in the narrow instruction. */
10460
10461static int
10462relax_branch (fragS *fragp, asection *sec, int bits)
10463{
10464 addressT addr;
10465 offsetT val;
10466 offsetT limit;
10467
10468 /* Assume worst case for symbols not known to be in the same section. */
10469 if (!S_IS_DEFINED(fragp->fr_symbol)
10470 || sec != S_GET_SEGMENT (fragp->fr_symbol))
10471 return 4;
10472
10473 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
10474 addr = fragp->fr_address + fragp->fr_fix + 4;
10475 val -= addr;
10476
10477 /* Offset is a signed value *2 */
10478 limit = 1 << bits;
10479 if (val >= limit || val < -limit)
10480 return 4;
10481 return 2;
10482}
10483
10484
10485/* Relax a machine dependent frag. This returns the amount by which
10486 the current size of the frag should change. */
10487
10488int
10489arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
10490{
10491 int oldsize;
10492 int newsize;
10493
10494 oldsize = fragp->fr_var;
10495 switch (fragp->fr_subtype)
10496 {
10497 case T_MNEM_ldr_pc2:
10498 newsize = relax_adr(fragp, sec);
10499 break;
10500 case T_MNEM_ldr_pc:
10501 case T_MNEM_ldr_sp:
10502 case T_MNEM_str_sp:
10503 newsize = relax_immediate(fragp, 8, 2);
10504 break;
10505 case T_MNEM_ldr:
10506 case T_MNEM_str:
10507 newsize = relax_immediate(fragp, 5, 2);
10508 break;
10509 case T_MNEM_ldrh:
10510 case T_MNEM_strh:
10511 newsize = relax_immediate(fragp, 5, 1);
10512 break;
10513 case T_MNEM_ldrb:
10514 case T_MNEM_strb:
10515 newsize = relax_immediate(fragp, 5, 0);
10516 break;
10517 case T_MNEM_adr:
10518 newsize = relax_adr(fragp, sec);
10519 break;
10520 case T_MNEM_mov:
10521 case T_MNEM_movs:
10522 case T_MNEM_cmp:
10523 case T_MNEM_cmn:
10524 newsize = relax_immediate(fragp, 8, 0);
10525 break;
10526 case T_MNEM_b:
10527 newsize = relax_branch(fragp, sec, 11);
10528 break;
10529 case T_MNEM_bcond:
10530 newsize = relax_branch(fragp, sec, 8);
10531 break;
10532 case T_MNEM_add_sp:
10533 case T_MNEM_add_pc:
10534 newsize = relax_immediate (fragp, 8, 2);
10535 break;
10536 case T_MNEM_inc_sp:
10537 case T_MNEM_dec_sp:
10538 newsize = relax_immediate (fragp, 7, 2);
10539 break;
10540 case T_MNEM_addi:
10541 case T_MNEM_addis:
10542 case T_MNEM_subi:
10543 case T_MNEM_subis:
10544 newsize = relax_addsub (fragp, sec);
10545 break;
10546 default:
10547 abort();
10548 }
10549 if (newsize < 0)
10550 {
10551 fragp->fr_var = -newsize;
10552 md_convert_frag (sec->owner, sec, fragp);
10553 frag_wane(fragp);
10554 return -(newsize + oldsize);
10555 }
10556 fragp->fr_var = newsize;
10557 return newsize - oldsize;
c19d1205 10558}
b99bd4ef 10559
c19d1205 10560/* Round up a section size to the appropriate boundary. */
b99bd4ef 10561
c19d1205
ZW
10562valueT
10563md_section_align (segT segment ATTRIBUTE_UNUSED,
10564 valueT size)
10565{
10566#ifdef OBJ_ELF
10567 return size;
10568#else
10569 /* Round all sects to multiple of 4. */
10570 return (size + 3) & ~3;
10571#endif
bfae80f2 10572}
b99bd4ef 10573
c19d1205
ZW
10574/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10575 of an rs_align_code fragment. */
10576
10577void
10578arm_handle_align (fragS * fragP)
bfae80f2 10579{
c19d1205
ZW
10580 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
10581 static char const thumb_noop[2] = { 0xc0, 0x46 };
10582 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
10583 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
10584
10585 int bytes, fix, noop_size;
10586 char * p;
10587 const char * noop;
bfae80f2 10588
c19d1205 10589 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
10590 return;
10591
c19d1205
ZW
10592 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
10593 p = fragP->fr_literal + fragP->fr_fix;
10594 fix = 0;
bfae80f2 10595
c19d1205
ZW
10596 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
10597 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 10598
c19d1205 10599 if (fragP->tc_frag_data)
a737bd4d 10600 {
c19d1205
ZW
10601 if (target_big_endian)
10602 noop = thumb_bigend_noop;
10603 else
10604 noop = thumb_noop;
10605 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
10606 }
10607 else
10608 {
c19d1205
ZW
10609 if (target_big_endian)
10610 noop = arm_bigend_noop;
10611 else
10612 noop = arm_noop;
10613 noop_size = sizeof (arm_noop);
7ed4c4c5 10614 }
a737bd4d 10615
c19d1205 10616 if (bytes & (noop_size - 1))
7ed4c4c5 10617 {
c19d1205
ZW
10618 fix = bytes & (noop_size - 1);
10619 memset (p, 0, fix);
10620 p += fix;
10621 bytes -= fix;
a737bd4d 10622 }
a737bd4d 10623
c19d1205 10624 while (bytes >= noop_size)
a737bd4d 10625 {
c19d1205
ZW
10626 memcpy (p, noop, noop_size);
10627 p += noop_size;
10628 bytes -= noop_size;
10629 fix += noop_size;
a737bd4d
NC
10630 }
10631
c19d1205
ZW
10632 fragP->fr_fix += fix;
10633 fragP->fr_var = noop_size;
a737bd4d
NC
10634}
10635
c19d1205
ZW
10636/* Called from md_do_align. Used to create an alignment
10637 frag in a code section. */
10638
10639void
10640arm_frag_align_code (int n, int max)
bfae80f2 10641{
c19d1205 10642 char * p;
7ed4c4c5 10643
c19d1205
ZW
10644 /* We assume that there will never be a requirement
10645 to support alignments greater than 32 bytes. */
10646 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
10647 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 10648
c19d1205
ZW
10649 p = frag_var (rs_align_code,
10650 MAX_MEM_FOR_RS_ALIGN_CODE,
10651 1,
10652 (relax_substateT) max,
10653 (symbolS *) NULL,
10654 (offsetT) n,
10655 (char *) NULL);
10656 *p = 0;
10657}
bfae80f2 10658
c19d1205 10659/* Perform target specific initialisation of a frag. */
bfae80f2 10660
c19d1205
ZW
10661void
10662arm_init_frag (fragS * fragP)
10663{
10664 /* Record whether this frag is in an ARM or a THUMB area. */
10665 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
10666}
10667
c19d1205
ZW
10668#ifdef OBJ_ELF
10669/* When we change sections we need to issue a new mapping symbol. */
10670
10671void
10672arm_elf_change_section (void)
bfae80f2 10673{
c19d1205
ZW
10674 flagword flags;
10675 segment_info_type *seginfo;
bfae80f2 10676
c19d1205
ZW
10677 /* Link an unlinked unwind index table section to the .text section. */
10678 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
10679 && elf_linked_to_section (now_seg) == NULL)
10680 elf_linked_to_section (now_seg) = text_section;
10681
10682 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
10683 return;
10684
c19d1205
ZW
10685 flags = bfd_get_section_flags (stdoutput, now_seg);
10686
10687 /* We can ignore sections that only contain debug info. */
10688 if ((flags & SEC_ALLOC) == 0)
10689 return;
bfae80f2 10690
c19d1205
ZW
10691 seginfo = seg_info (now_seg);
10692 mapstate = seginfo->tc_segment_info_data.mapstate;
10693 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
10694}
10695
c19d1205
ZW
10696int
10697arm_elf_section_type (const char * str, size_t len)
e45d0630 10698{
c19d1205
ZW
10699 if (len == 5 && strncmp (str, "exidx", 5) == 0)
10700 return SHT_ARM_EXIDX;
e45d0630 10701
c19d1205
ZW
10702 return -1;
10703}
10704\f
10705/* Code to deal with unwinding tables. */
e45d0630 10706
c19d1205 10707static void add_unwind_adjustsp (offsetT);
e45d0630 10708
c19d1205 10709/* Cenerate and deferred unwind frame offset. */
e45d0630 10710
bfae80f2 10711static void
c19d1205 10712flush_pending_unwind (void)
bfae80f2 10713{
c19d1205 10714 offsetT offset;
bfae80f2 10715
c19d1205
ZW
10716 offset = unwind.pending_offset;
10717 unwind.pending_offset = 0;
10718 if (offset != 0)
10719 add_unwind_adjustsp (offset);
bfae80f2
RE
10720}
10721
c19d1205
ZW
10722/* Add an opcode to this list for this function. Two-byte opcodes should
10723 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
10724 order. */
10725
bfae80f2 10726static void
c19d1205 10727add_unwind_opcode (valueT op, int length)
bfae80f2 10728{
c19d1205
ZW
10729 /* Add any deferred stack adjustment. */
10730 if (unwind.pending_offset)
10731 flush_pending_unwind ();
bfae80f2 10732
c19d1205 10733 unwind.sp_restored = 0;
bfae80f2 10734
c19d1205 10735 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 10736 {
c19d1205
ZW
10737 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
10738 if (unwind.opcodes)
10739 unwind.opcodes = xrealloc (unwind.opcodes,
10740 unwind.opcode_alloc);
10741 else
10742 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 10743 }
c19d1205 10744 while (length > 0)
bfae80f2 10745 {
c19d1205
ZW
10746 length--;
10747 unwind.opcodes[unwind.opcode_count] = op & 0xff;
10748 op >>= 8;
10749 unwind.opcode_count++;
bfae80f2 10750 }
bfae80f2
RE
10751}
10752
c19d1205
ZW
10753/* Add unwind opcodes to adjust the stack pointer. */
10754
bfae80f2 10755static void
c19d1205 10756add_unwind_adjustsp (offsetT offset)
bfae80f2 10757{
c19d1205 10758 valueT op;
bfae80f2 10759
c19d1205 10760 if (offset > 0x200)
bfae80f2 10761 {
c19d1205
ZW
10762 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
10763 char bytes[5];
10764 int n;
10765 valueT o;
bfae80f2 10766
c19d1205
ZW
10767 /* Long form: 0xb2, uleb128. */
10768 /* This might not fit in a word so add the individual bytes,
10769 remembering the list is built in reverse order. */
10770 o = (valueT) ((offset - 0x204) >> 2);
10771 if (o == 0)
10772 add_unwind_opcode (0, 1);
bfae80f2 10773
c19d1205
ZW
10774 /* Calculate the uleb128 encoding of the offset. */
10775 n = 0;
10776 while (o)
10777 {
10778 bytes[n] = o & 0x7f;
10779 o >>= 7;
10780 if (o)
10781 bytes[n] |= 0x80;
10782 n++;
10783 }
10784 /* Add the insn. */
10785 for (; n; n--)
10786 add_unwind_opcode (bytes[n - 1], 1);
10787 add_unwind_opcode (0xb2, 1);
10788 }
10789 else if (offset > 0x100)
bfae80f2 10790 {
c19d1205
ZW
10791 /* Two short opcodes. */
10792 add_unwind_opcode (0x3f, 1);
10793 op = (offset - 0x104) >> 2;
10794 add_unwind_opcode (op, 1);
bfae80f2 10795 }
c19d1205
ZW
10796 else if (offset > 0)
10797 {
10798 /* Short opcode. */
10799 op = (offset - 4) >> 2;
10800 add_unwind_opcode (op, 1);
10801 }
10802 else if (offset < 0)
bfae80f2 10803 {
c19d1205
ZW
10804 offset = -offset;
10805 while (offset > 0x100)
bfae80f2 10806 {
c19d1205
ZW
10807 add_unwind_opcode (0x7f, 1);
10808 offset -= 0x100;
bfae80f2 10809 }
c19d1205
ZW
10810 op = ((offset - 4) >> 2) | 0x40;
10811 add_unwind_opcode (op, 1);
bfae80f2 10812 }
bfae80f2
RE
10813}
10814
c19d1205
ZW
10815/* Finish the list of unwind opcodes for this function. */
10816static void
10817finish_unwind_opcodes (void)
bfae80f2 10818{
c19d1205 10819 valueT op;
bfae80f2 10820
c19d1205 10821 if (unwind.fp_used)
bfae80f2 10822 {
c19d1205
ZW
10823 /* Adjust sp as neccessary. */
10824 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
10825 flush_pending_unwind ();
bfae80f2 10826
c19d1205
ZW
10827 /* After restoring sp from the frame pointer. */
10828 op = 0x90 | unwind.fp_reg;
10829 add_unwind_opcode (op, 1);
10830 }
10831 else
10832 flush_pending_unwind ();
bfae80f2
RE
10833}
10834
bfae80f2 10835
c19d1205
ZW
10836/* Start an exception table entry. If idx is nonzero this is an index table
10837 entry. */
bfae80f2
RE
10838
10839static void
c19d1205 10840start_unwind_section (const segT text_seg, int idx)
bfae80f2 10841{
c19d1205
ZW
10842 const char * text_name;
10843 const char * prefix;
10844 const char * prefix_once;
10845 const char * group_name;
10846 size_t prefix_len;
10847 size_t text_len;
10848 char * sec_name;
10849 size_t sec_name_len;
10850 int type;
10851 int flags;
10852 int linkonce;
bfae80f2 10853
c19d1205 10854 if (idx)
bfae80f2 10855 {
c19d1205
ZW
10856 prefix = ELF_STRING_ARM_unwind;
10857 prefix_once = ELF_STRING_ARM_unwind_once;
10858 type = SHT_ARM_EXIDX;
bfae80f2 10859 }
c19d1205 10860 else
bfae80f2 10861 {
c19d1205
ZW
10862 prefix = ELF_STRING_ARM_unwind_info;
10863 prefix_once = ELF_STRING_ARM_unwind_info_once;
10864 type = SHT_PROGBITS;
bfae80f2
RE
10865 }
10866
c19d1205
ZW
10867 text_name = segment_name (text_seg);
10868 if (streq (text_name, ".text"))
10869 text_name = "";
10870
10871 if (strncmp (text_name, ".gnu.linkonce.t.",
10872 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 10873 {
c19d1205
ZW
10874 prefix = prefix_once;
10875 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
10876 }
10877
c19d1205
ZW
10878 prefix_len = strlen (prefix);
10879 text_len = strlen (text_name);
10880 sec_name_len = prefix_len + text_len;
10881 sec_name = xmalloc (sec_name_len + 1);
10882 memcpy (sec_name, prefix, prefix_len);
10883 memcpy (sec_name + prefix_len, text_name, text_len);
10884 sec_name[prefix_len + text_len] = '\0';
bfae80f2 10885
c19d1205
ZW
10886 flags = SHF_ALLOC;
10887 linkonce = 0;
10888 group_name = 0;
bfae80f2 10889
c19d1205
ZW
10890 /* Handle COMDAT group. */
10891 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 10892 {
c19d1205
ZW
10893 group_name = elf_group_name (text_seg);
10894 if (group_name == NULL)
10895 {
10896 as_bad ("Group section `%s' has no group signature",
10897 segment_name (text_seg));
10898 ignore_rest_of_line ();
10899 return;
10900 }
10901 flags |= SHF_GROUP;
10902 linkonce = 1;
bfae80f2
RE
10903 }
10904
c19d1205 10905 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 10906
c19d1205
ZW
10907 /* Set the setion link for index tables. */
10908 if (idx)
10909 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
10910}
10911
bfae80f2 10912
c19d1205
ZW
10913/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
10914 personality routine data. Returns zero, or the index table value for
10915 and inline entry. */
10916
10917static valueT
10918create_unwind_entry (int have_data)
bfae80f2 10919{
c19d1205
ZW
10920 int size;
10921 addressT where;
10922 char *ptr;
10923 /* The current word of data. */
10924 valueT data;
10925 /* The number of bytes left in this word. */
10926 int n;
bfae80f2 10927
c19d1205 10928 finish_unwind_opcodes ();
bfae80f2 10929
c19d1205
ZW
10930 /* Remember the current text section. */
10931 unwind.saved_seg = now_seg;
10932 unwind.saved_subseg = now_subseg;
bfae80f2 10933
c19d1205 10934 start_unwind_section (now_seg, 0);
bfae80f2 10935
c19d1205 10936 if (unwind.personality_routine == NULL)
bfae80f2 10937 {
c19d1205
ZW
10938 if (unwind.personality_index == -2)
10939 {
10940 if (have_data)
10941 as_bad (_("handerdata in cantunwind frame"));
10942 return 1; /* EXIDX_CANTUNWIND. */
10943 }
bfae80f2 10944
c19d1205
ZW
10945 /* Use a default personality routine if none is specified. */
10946 if (unwind.personality_index == -1)
10947 {
10948 if (unwind.opcode_count > 3)
10949 unwind.personality_index = 1;
10950 else
10951 unwind.personality_index = 0;
10952 }
bfae80f2 10953
c19d1205
ZW
10954 /* Space for the personality routine entry. */
10955 if (unwind.personality_index == 0)
10956 {
10957 if (unwind.opcode_count > 3)
10958 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 10959
c19d1205
ZW
10960 if (!have_data)
10961 {
10962 /* All the data is inline in the index table. */
10963 data = 0x80;
10964 n = 3;
10965 while (unwind.opcode_count > 0)
10966 {
10967 unwind.opcode_count--;
10968 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
10969 n--;
10970 }
bfae80f2 10971
c19d1205
ZW
10972 /* Pad with "finish" opcodes. */
10973 while (n--)
10974 data = (data << 8) | 0xb0;
bfae80f2 10975
c19d1205
ZW
10976 return data;
10977 }
10978 size = 0;
10979 }
10980 else
10981 /* We get two opcodes "free" in the first word. */
10982 size = unwind.opcode_count - 2;
10983 }
10984 else
10985 /* An extra byte is required for the opcode count. */
10986 size = unwind.opcode_count + 1;
bfae80f2 10987
c19d1205
ZW
10988 size = (size + 3) >> 2;
10989 if (size > 0xff)
10990 as_bad (_("too many unwind opcodes"));
bfae80f2 10991
c19d1205
ZW
10992 frag_align (2, 0, 0);
10993 record_alignment (now_seg, 2);
10994 unwind.table_entry = expr_build_dot ();
10995
10996 /* Allocate the table entry. */
10997 ptr = frag_more ((size << 2) + 4);
10998 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 10999
c19d1205 11000 switch (unwind.personality_index)
bfae80f2 11001 {
c19d1205
ZW
11002 case -1:
11003 /* ??? Should this be a PLT generating relocation? */
11004 /* Custom personality routine. */
11005 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
11006 BFD_RELOC_ARM_PREL31);
bfae80f2 11007
c19d1205
ZW
11008 where += 4;
11009 ptr += 4;
bfae80f2 11010
c19d1205
ZW
11011 /* Set the first byte to the number of additional words. */
11012 data = size - 1;
11013 n = 3;
11014 break;
bfae80f2 11015
c19d1205
ZW
11016 /* ABI defined personality routines. */
11017 case 0:
11018 /* Three opcodes bytes are packed into the first word. */
11019 data = 0x80;
11020 n = 3;
11021 break;
bfae80f2 11022
c19d1205
ZW
11023 case 1:
11024 case 2:
11025 /* The size and first two opcode bytes go in the first word. */
11026 data = ((0x80 + unwind.personality_index) << 8) | size;
11027 n = 2;
11028 break;
bfae80f2 11029
c19d1205
ZW
11030 default:
11031 /* Should never happen. */
11032 abort ();
11033 }
bfae80f2 11034
c19d1205
ZW
11035 /* Pack the opcodes into words (MSB first), reversing the list at the same
11036 time. */
11037 while (unwind.opcode_count > 0)
11038 {
11039 if (n == 0)
11040 {
11041 md_number_to_chars (ptr, data, 4);
11042 ptr += 4;
11043 n = 4;
11044 data = 0;
11045 }
11046 unwind.opcode_count--;
11047 n--;
11048 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
11049 }
11050
11051 /* Finish off the last word. */
11052 if (n < 4)
11053 {
11054 /* Pad with "finish" opcodes. */
11055 while (n--)
11056 data = (data << 8) | 0xb0;
11057
11058 md_number_to_chars (ptr, data, 4);
11059 }
11060
11061 if (!have_data)
11062 {
11063 /* Add an empty descriptor if there is no user-specified data. */
11064 ptr = frag_more (4);
11065 md_number_to_chars (ptr, 0, 4);
11066 }
11067
11068 return 0;
bfae80f2
RE
11069}
11070
c19d1205
ZW
11071/* Convert REGNAME to a DWARF-2 register number. */
11072
11073int
11074tc_arm_regname_to_dw2regnum (const char *regname)
bfae80f2 11075{
c19d1205
ZW
11076 int reg = arm_reg_parse ((char **) &regname, REG_TYPE_RN);
11077
11078 if (reg == FAIL)
11079 return -1;
11080
11081 return reg;
bfae80f2
RE
11082}
11083
c19d1205
ZW
11084/* Initialize the DWARF-2 unwind information for this procedure. */
11085
11086void
11087tc_arm_frame_initial_instructions (void)
bfae80f2 11088{
c19d1205 11089 cfi_add_CFA_def_cfa (REG_SP, 0);
bfae80f2 11090}
c19d1205 11091#endif /* OBJ_ELF */
bfae80f2 11092
bfae80f2 11093
c19d1205 11094/* MD interface: Symbol and relocation handling. */
bfae80f2 11095
2fc8bdac
ZW
11096/* Return the address within the segment that a PC-relative fixup is
11097 relative to. For ARM, PC-relative fixups applied to instructions
11098 are generally relative to the location of the fixup plus 8 bytes.
11099 Thumb branches are offset by 4, and Thumb loads relative to PC
11100 require special handling. */
bfae80f2 11101
c19d1205 11102long
2fc8bdac 11103md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 11104{
2fc8bdac
ZW
11105 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
11106
11107 /* If this is pc-relative and we are going to emit a relocation
11108 then we just want to put out any pipeline compensation that the linker
11109 will need. Otherwise we want to use the calculated base. */
11110 if (fixP->fx_pcrel
11111 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
11112 || arm_force_relocation (fixP)))
11113 base = 0;
bfae80f2 11114
c19d1205 11115 switch (fixP->fx_r_type)
bfae80f2 11116 {
2fc8bdac
ZW
11117 /* PC relative addressing on the Thumb is slightly odd as the
11118 bottom two bits of the PC are forced to zero for the
11119 calculation. This happens *after* application of the
11120 pipeline offset. However, Thumb adrl already adjusts for
11121 this, so we need not do it again. */
c19d1205 11122 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 11123 return base & ~3;
c19d1205
ZW
11124
11125 case BFD_RELOC_ARM_THUMB_OFFSET:
11126 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 11127 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 11128 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 11129 return (base + 4) & ~3;
c19d1205 11130
2fc8bdac
ZW
11131 /* Thumb branches are simply offset by +4. */
11132 case BFD_RELOC_THUMB_PCREL_BRANCH7:
11133 case BFD_RELOC_THUMB_PCREL_BRANCH9:
11134 case BFD_RELOC_THUMB_PCREL_BRANCH12:
11135 case BFD_RELOC_THUMB_PCREL_BRANCH20:
11136 case BFD_RELOC_THUMB_PCREL_BRANCH23:
11137 case BFD_RELOC_THUMB_PCREL_BRANCH25:
11138 case BFD_RELOC_THUMB_PCREL_BLX:
11139 return base + 4;
bfae80f2 11140
2fc8bdac
ZW
11141 /* ARM mode branches are offset by +8. However, the Windows CE
11142 loader expects the relocation not to take this into account. */
11143 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
11144 case BFD_RELOC_ARM_PCREL_CALL:
11145 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
11146 case BFD_RELOC_ARM_PCREL_BLX:
11147 case BFD_RELOC_ARM_PLT32:
c19d1205 11148#ifdef TE_WINCE
2fc8bdac 11149 return base;
c19d1205 11150#else
2fc8bdac 11151 return base + 8;
c19d1205 11152#endif
2fc8bdac
ZW
11153
11154 /* ARM mode loads relative to PC are also offset by +8. Unlike
11155 branches, the Windows CE loader *does* expect the relocation
11156 to take this into account. */
11157 case BFD_RELOC_ARM_OFFSET_IMM:
11158 case BFD_RELOC_ARM_OFFSET_IMM8:
11159 case BFD_RELOC_ARM_HWLITERAL:
11160 case BFD_RELOC_ARM_LITERAL:
11161 case BFD_RELOC_ARM_CP_OFF_IMM:
11162 return base + 8;
11163
11164
11165 /* Other PC-relative relocations are un-offset. */
11166 default:
11167 return base;
11168 }
bfae80f2
RE
11169}
11170
c19d1205
ZW
11171/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
11172 Otherwise we have no need to default values of symbols. */
11173
11174symbolS *
11175md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 11176{
c19d1205
ZW
11177#ifdef OBJ_ELF
11178 if (name[0] == '_' && name[1] == 'G'
11179 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
11180 {
11181 if (!GOT_symbol)
11182 {
11183 if (symbol_find (name))
11184 as_bad ("GOT already in the symbol table");
bfae80f2 11185
c19d1205
ZW
11186 GOT_symbol = symbol_new (name, undefined_section,
11187 (valueT) 0, & zero_address_frag);
11188 }
bfae80f2 11189
c19d1205 11190 return GOT_symbol;
bfae80f2 11191 }
c19d1205 11192#endif
bfae80f2 11193
c19d1205 11194 return 0;
bfae80f2
RE
11195}
11196
55cf6793 11197/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
11198 computed as two separate immediate values, added together. We
11199 already know that this value cannot be computed by just one ARM
11200 instruction. */
11201
11202static unsigned int
11203validate_immediate_twopart (unsigned int val,
11204 unsigned int * highpart)
bfae80f2 11205{
c19d1205
ZW
11206 unsigned int a;
11207 unsigned int i;
bfae80f2 11208
c19d1205
ZW
11209 for (i = 0; i < 32; i += 2)
11210 if (((a = rotate_left (val, i)) & 0xff) != 0)
11211 {
11212 if (a & 0xff00)
11213 {
11214 if (a & ~ 0xffff)
11215 continue;
11216 * highpart = (a >> 8) | ((i + 24) << 7);
11217 }
11218 else if (a & 0xff0000)
11219 {
11220 if (a & 0xff000000)
11221 continue;
11222 * highpart = (a >> 16) | ((i + 16) << 7);
11223 }
11224 else
11225 {
11226 assert (a & 0xff000000);
11227 * highpart = (a >> 24) | ((i + 8) << 7);
11228 }
bfae80f2 11229
c19d1205
ZW
11230 return (a & 0xff) | (i << 7);
11231 }
bfae80f2 11232
c19d1205 11233 return FAIL;
bfae80f2
RE
11234}
11235
c19d1205
ZW
11236static int
11237validate_offset_imm (unsigned int val, int hwse)
11238{
11239 if ((hwse && val > 255) || val > 4095)
11240 return FAIL;
11241 return val;
11242}
bfae80f2 11243
55cf6793 11244/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
11245 negative immediate constant by altering the instruction. A bit of
11246 a hack really.
11247 MOV <-> MVN
11248 AND <-> BIC
11249 ADC <-> SBC
11250 by inverting the second operand, and
11251 ADD <-> SUB
11252 CMP <-> CMN
11253 by negating the second operand. */
bfae80f2 11254
c19d1205
ZW
11255static int
11256negate_data_op (unsigned long * instruction,
11257 unsigned long value)
bfae80f2 11258{
c19d1205
ZW
11259 int op, new_inst;
11260 unsigned long negated, inverted;
bfae80f2 11261
c19d1205
ZW
11262 negated = encode_arm_immediate (-value);
11263 inverted = encode_arm_immediate (~value);
bfae80f2 11264
c19d1205
ZW
11265 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
11266 switch (op)
bfae80f2 11267 {
c19d1205
ZW
11268 /* First negates. */
11269 case OPCODE_SUB: /* ADD <-> SUB */
11270 new_inst = OPCODE_ADD;
11271 value = negated;
11272 break;
bfae80f2 11273
c19d1205
ZW
11274 case OPCODE_ADD:
11275 new_inst = OPCODE_SUB;
11276 value = negated;
11277 break;
bfae80f2 11278
c19d1205
ZW
11279 case OPCODE_CMP: /* CMP <-> CMN */
11280 new_inst = OPCODE_CMN;
11281 value = negated;
11282 break;
bfae80f2 11283
c19d1205
ZW
11284 case OPCODE_CMN:
11285 new_inst = OPCODE_CMP;
11286 value = negated;
11287 break;
bfae80f2 11288
c19d1205
ZW
11289 /* Now Inverted ops. */
11290 case OPCODE_MOV: /* MOV <-> MVN */
11291 new_inst = OPCODE_MVN;
11292 value = inverted;
11293 break;
bfae80f2 11294
c19d1205
ZW
11295 case OPCODE_MVN:
11296 new_inst = OPCODE_MOV;
11297 value = inverted;
11298 break;
bfae80f2 11299
c19d1205
ZW
11300 case OPCODE_AND: /* AND <-> BIC */
11301 new_inst = OPCODE_BIC;
11302 value = inverted;
11303 break;
bfae80f2 11304
c19d1205
ZW
11305 case OPCODE_BIC:
11306 new_inst = OPCODE_AND;
11307 value = inverted;
11308 break;
bfae80f2 11309
c19d1205
ZW
11310 case OPCODE_ADC: /* ADC <-> SBC */
11311 new_inst = OPCODE_SBC;
11312 value = inverted;
11313 break;
bfae80f2 11314
c19d1205
ZW
11315 case OPCODE_SBC:
11316 new_inst = OPCODE_ADC;
11317 value = inverted;
11318 break;
bfae80f2 11319
c19d1205
ZW
11320 /* We cannot do anything. */
11321 default:
11322 return FAIL;
b99bd4ef
NC
11323 }
11324
c19d1205
ZW
11325 if (value == (unsigned) FAIL)
11326 return FAIL;
11327
11328 *instruction &= OPCODE_MASK;
11329 *instruction |= new_inst << DATA_OP_SHIFT;
11330 return value;
b99bd4ef
NC
11331}
11332
ef8d22e6
PB
11333/* Like negate_data_op, but for Thumb-2. */
11334
11335static unsigned int
11336thumb32_negate_data_op (offsetT *instruction, offsetT value)
11337{
11338 int op, new_inst;
11339 int rd;
11340 offsetT negated, inverted;
11341
11342 negated = encode_thumb32_immediate (-value);
11343 inverted = encode_thumb32_immediate (~value);
11344
11345 rd = (*instruction >> 8) & 0xf;
11346 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
11347 switch (op)
11348 {
11349 /* ADD <-> SUB. Includes CMP <-> CMN. */
11350 case T2_OPCODE_SUB:
11351 new_inst = T2_OPCODE_ADD;
11352 value = negated;
11353 break;
11354
11355 case T2_OPCODE_ADD:
11356 new_inst = T2_OPCODE_SUB;
11357 value = negated;
11358 break;
11359
11360 /* ORR <-> ORN. Includes MOV <-> MVN. */
11361 case T2_OPCODE_ORR:
11362 new_inst = T2_OPCODE_ORN;
11363 value = inverted;
11364 break;
11365
11366 case T2_OPCODE_ORN:
11367 new_inst = T2_OPCODE_ORR;
11368 value = inverted;
11369 break;
11370
11371 /* AND <-> BIC. TST has no inverted equivalent. */
11372 case T2_OPCODE_AND:
11373 new_inst = T2_OPCODE_BIC;
11374 if (rd == 15)
11375 value = FAIL;
11376 else
11377 value = inverted;
11378 break;
11379
11380 case T2_OPCODE_BIC:
11381 new_inst = T2_OPCODE_AND;
11382 value = inverted;
11383 break;
11384
11385 /* ADC <-> SBC */
11386 case T2_OPCODE_ADC:
11387 new_inst = T2_OPCODE_SBC;
11388 value = inverted;
11389 break;
11390
11391 case T2_OPCODE_SBC:
11392 new_inst = T2_OPCODE_ADC;
11393 value = inverted;
11394 break;
11395
11396 /* We cannot do anything. */
11397 default:
11398 return FAIL;
11399 }
11400
11401 if (value == FAIL)
11402 return FAIL;
11403
11404 *instruction &= T2_OPCODE_MASK;
11405 *instruction |= new_inst << T2_DATA_OP_SHIFT;
11406 return value;
11407}
11408
8f06b2d8
PB
11409/* Read a 32-bit thumb instruction from buf. */
11410static unsigned long
11411get_thumb32_insn (char * buf)
11412{
11413 unsigned long insn;
11414 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
11415 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11416
11417 return insn;
11418}
11419
c19d1205 11420void
55cf6793 11421md_apply_fix (fixS * fixP,
c19d1205
ZW
11422 valueT * valP,
11423 segT seg)
11424{
11425 offsetT value = * valP;
11426 offsetT newval;
11427 unsigned int newimm;
11428 unsigned long temp;
11429 int sign;
11430 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 11431
c19d1205 11432 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 11433
c19d1205
ZW
11434 /* Note whether this will delete the relocation. */
11435 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
11436 fixP->fx_done = 1;
b99bd4ef 11437
adbaf948
ZW
11438 /* On a 64-bit host, silently truncate 'value' to 32 bits for
11439 consistency with the behavior on 32-bit hosts. Remember value
11440 for emit_reloc. */
11441 value &= 0xffffffff;
11442 value ^= 0x80000000;
11443 value -= 0x80000000;
11444
11445 *valP = value;
c19d1205 11446 fixP->fx_addnumber = value;
b99bd4ef 11447
adbaf948
ZW
11448 /* Same treatment for fixP->fx_offset. */
11449 fixP->fx_offset &= 0xffffffff;
11450 fixP->fx_offset ^= 0x80000000;
11451 fixP->fx_offset -= 0x80000000;
11452
c19d1205 11453 switch (fixP->fx_r_type)
b99bd4ef 11454 {
c19d1205
ZW
11455 case BFD_RELOC_NONE:
11456 /* This will need to go in the object file. */
11457 fixP->fx_done = 0;
11458 break;
b99bd4ef 11459
c19d1205
ZW
11460 case BFD_RELOC_ARM_IMMEDIATE:
11461 /* We claim that this fixup has been processed here,
11462 even if in fact we generate an error because we do
11463 not have a reloc for it, so tc_gen_reloc will reject it. */
11464 fixP->fx_done = 1;
b99bd4ef 11465
c19d1205
ZW
11466 if (fixP->fx_addsy
11467 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 11468 {
c19d1205
ZW
11469 as_bad_where (fixP->fx_file, fixP->fx_line,
11470 _("undefined symbol %s used as an immediate value"),
11471 S_GET_NAME (fixP->fx_addsy));
11472 break;
b99bd4ef
NC
11473 }
11474
c19d1205
ZW
11475 newimm = encode_arm_immediate (value);
11476 temp = md_chars_to_number (buf, INSN_SIZE);
11477
11478 /* If the instruction will fail, see if we can fix things up by
11479 changing the opcode. */
11480 if (newimm == (unsigned int) FAIL
11481 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 11482 {
c19d1205
ZW
11483 as_bad_where (fixP->fx_file, fixP->fx_line,
11484 _("invalid constant (%lx) after fixup"),
11485 (unsigned long) value);
11486 break;
b99bd4ef 11487 }
b99bd4ef 11488
c19d1205
ZW
11489 newimm |= (temp & 0xfffff000);
11490 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
11491 break;
b99bd4ef 11492
c19d1205
ZW
11493 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
11494 {
11495 unsigned int highpart = 0;
11496 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 11497
c19d1205
ZW
11498 newimm = encode_arm_immediate (value);
11499 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 11500
c19d1205
ZW
11501 /* If the instruction will fail, see if we can fix things up by
11502 changing the opcode. */
11503 if (newimm == (unsigned int) FAIL
11504 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
11505 {
11506 /* No ? OK - try using two ADD instructions to generate
11507 the value. */
11508 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 11509
c19d1205
ZW
11510 /* Yes - then make sure that the second instruction is
11511 also an add. */
11512 if (newimm != (unsigned int) FAIL)
11513 newinsn = temp;
11514 /* Still No ? Try using a negated value. */
11515 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
11516 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
11517 /* Otherwise - give up. */
11518 else
11519 {
11520 as_bad_where (fixP->fx_file, fixP->fx_line,
11521 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
11522 (long) value);
11523 break;
11524 }
b99bd4ef 11525
c19d1205
ZW
11526 /* Replace the first operand in the 2nd instruction (which
11527 is the PC) with the destination register. We have
11528 already added in the PC in the first instruction and we
11529 do not want to do it again. */
11530 newinsn &= ~ 0xf0000;
11531 newinsn |= ((newinsn & 0x0f000) << 4);
11532 }
b99bd4ef 11533
c19d1205
ZW
11534 newimm |= (temp & 0xfffff000);
11535 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 11536
c19d1205
ZW
11537 highpart |= (newinsn & 0xfffff000);
11538 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
11539 }
11540 break;
b99bd4ef 11541
c19d1205 11542 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
11543 if (!fixP->fx_done && seg->use_rela_p)
11544 value = 0;
11545
c19d1205
ZW
11546 case BFD_RELOC_ARM_LITERAL:
11547 sign = value >= 0;
b99bd4ef 11548
c19d1205
ZW
11549 if (value < 0)
11550 value = - value;
b99bd4ef 11551
c19d1205 11552 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 11553 {
c19d1205
ZW
11554 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
11555 as_bad_where (fixP->fx_file, fixP->fx_line,
11556 _("invalid literal constant: pool needs to be closer"));
11557 else
11558 as_bad_where (fixP->fx_file, fixP->fx_line,
11559 _("bad immediate value for offset (%ld)"),
11560 (long) value);
11561 break;
f03698e6
RE
11562 }
11563
c19d1205
ZW
11564 newval = md_chars_to_number (buf, INSN_SIZE);
11565 newval &= 0xff7ff000;
11566 newval |= value | (sign ? INDEX_UP : 0);
11567 md_number_to_chars (buf, newval, INSN_SIZE);
11568 break;
b99bd4ef 11569
c19d1205
ZW
11570 case BFD_RELOC_ARM_OFFSET_IMM8:
11571 case BFD_RELOC_ARM_HWLITERAL:
11572 sign = value >= 0;
b99bd4ef 11573
c19d1205
ZW
11574 if (value < 0)
11575 value = - value;
b99bd4ef 11576
c19d1205 11577 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 11578 {
c19d1205
ZW
11579 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
11580 as_bad_where (fixP->fx_file, fixP->fx_line,
11581 _("invalid literal constant: pool needs to be closer"));
11582 else
11583 as_bad (_("bad immediate value for half-word offset (%ld)"),
11584 (long) value);
11585 break;
b99bd4ef
NC
11586 }
11587
c19d1205
ZW
11588 newval = md_chars_to_number (buf, INSN_SIZE);
11589 newval &= 0xff7ff0f0;
11590 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
11591 md_number_to_chars (buf, newval, INSN_SIZE);
11592 break;
b99bd4ef 11593
c19d1205
ZW
11594 case BFD_RELOC_ARM_T32_OFFSET_U8:
11595 if (value < 0 || value > 1020 || value % 4 != 0)
11596 as_bad_where (fixP->fx_file, fixP->fx_line,
11597 _("bad immediate value for offset (%ld)"), (long) value);
11598 value /= 4;
b99bd4ef 11599
c19d1205 11600 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
11601 newval |= value;
11602 md_number_to_chars (buf+2, newval, THUMB_SIZE);
11603 break;
b99bd4ef 11604
c19d1205
ZW
11605 case BFD_RELOC_ARM_T32_OFFSET_IMM:
11606 /* This is a complicated relocation used for all varieties of Thumb32
11607 load/store instruction with immediate offset:
11608
11609 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
11610 *4, optional writeback(W)
11611 (doubleword load/store)
11612
11613 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
11614 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
11615 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
11616 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
11617 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
11618
11619 Uppercase letters indicate bits that are already encoded at
11620 this point. Lowercase letters are our problem. For the
11621 second block of instructions, the secondary opcode nybble
11622 (bits 8..11) is present, and bit 23 is zero, even if this is
11623 a PC-relative operation. */
11624 newval = md_chars_to_number (buf, THUMB_SIZE);
11625 newval <<= 16;
11626 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 11627
c19d1205 11628 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 11629 {
c19d1205
ZW
11630 /* Doubleword load/store: 8-bit offset, scaled by 4. */
11631 if (value >= 0)
11632 newval |= (1 << 23);
11633 else
11634 value = -value;
11635 if (value % 4 != 0)
11636 {
11637 as_bad_where (fixP->fx_file, fixP->fx_line,
11638 _("offset not a multiple of 4"));
11639 break;
11640 }
11641 value /= 4;
216d22bc 11642 if (value > 0xff)
c19d1205
ZW
11643 {
11644 as_bad_where (fixP->fx_file, fixP->fx_line,
11645 _("offset out of range"));
11646 break;
11647 }
11648 newval &= ~0xff;
b99bd4ef 11649 }
c19d1205 11650 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 11651 {
c19d1205
ZW
11652 /* PC-relative, 12-bit offset. */
11653 if (value >= 0)
11654 newval |= (1 << 23);
11655 else
11656 value = -value;
216d22bc 11657 if (value > 0xfff)
c19d1205
ZW
11658 {
11659 as_bad_where (fixP->fx_file, fixP->fx_line,
11660 _("offset out of range"));
11661 break;
11662 }
11663 newval &= ~0xfff;
b99bd4ef 11664 }
c19d1205 11665 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 11666 {
c19d1205
ZW
11667 /* Writeback: 8-bit, +/- offset. */
11668 if (value >= 0)
11669 newval |= (1 << 9);
11670 else
11671 value = -value;
216d22bc 11672 if (value > 0xff)
c19d1205
ZW
11673 {
11674 as_bad_where (fixP->fx_file, fixP->fx_line,
11675 _("offset out of range"));
11676 break;
11677 }
11678 newval &= ~0xff;
b99bd4ef 11679 }
c19d1205 11680 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 11681 {
c19d1205 11682 /* T-instruction: positive 8-bit offset. */
216d22bc 11683 if (value < 0 || value > 0xff)
b99bd4ef 11684 {
c19d1205
ZW
11685 as_bad_where (fixP->fx_file, fixP->fx_line,
11686 _("offset out of range"));
11687 break;
b99bd4ef 11688 }
c19d1205
ZW
11689 newval &= ~0xff;
11690 newval |= value;
b99bd4ef
NC
11691 }
11692 else
b99bd4ef 11693 {
c19d1205
ZW
11694 /* Positive 12-bit or negative 8-bit offset. */
11695 int limit;
11696 if (value >= 0)
b99bd4ef 11697 {
c19d1205
ZW
11698 newval |= (1 << 23);
11699 limit = 0xfff;
11700 }
11701 else
11702 {
11703 value = -value;
11704 limit = 0xff;
11705 }
11706 if (value > limit)
11707 {
11708 as_bad_where (fixP->fx_file, fixP->fx_line,
11709 _("offset out of range"));
11710 break;
b99bd4ef 11711 }
c19d1205 11712 newval &= ~limit;
b99bd4ef 11713 }
b99bd4ef 11714
c19d1205
ZW
11715 newval |= value;
11716 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
11717 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
11718 break;
404ff6b5 11719
c19d1205
ZW
11720 case BFD_RELOC_ARM_SHIFT_IMM:
11721 newval = md_chars_to_number (buf, INSN_SIZE);
11722 if (((unsigned long) value) > 32
11723 || (value == 32
11724 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
11725 {
11726 as_bad_where (fixP->fx_file, fixP->fx_line,
11727 _("shift expression is too large"));
11728 break;
11729 }
404ff6b5 11730
c19d1205
ZW
11731 if (value == 0)
11732 /* Shifts of zero must be done as lsl. */
11733 newval &= ~0x60;
11734 else if (value == 32)
11735 value = 0;
11736 newval &= 0xfffff07f;
11737 newval |= (value & 0x1f) << 7;
11738 md_number_to_chars (buf, newval, INSN_SIZE);
11739 break;
404ff6b5 11740
c19d1205 11741 case BFD_RELOC_ARM_T32_IMMEDIATE:
92e90b6e 11742 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 11743 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
11744 /* We claim that this fixup has been processed here,
11745 even if in fact we generate an error because we do
11746 not have a reloc for it, so tc_gen_reloc will reject it. */
11747 fixP->fx_done = 1;
404ff6b5 11748
c19d1205
ZW
11749 if (fixP->fx_addsy
11750 && ! S_IS_DEFINED (fixP->fx_addsy))
11751 {
11752 as_bad_where (fixP->fx_file, fixP->fx_line,
11753 _("undefined symbol %s used as an immediate value"),
11754 S_GET_NAME (fixP->fx_addsy));
11755 break;
11756 }
404ff6b5 11757
c19d1205
ZW
11758 newval = md_chars_to_number (buf, THUMB_SIZE);
11759 newval <<= 16;
11760 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 11761
e9f89963
PB
11762 /* FUTURE: Implement analogue of negate_data_op for T32. */
11763 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE)
ef8d22e6
PB
11764 {
11765 newimm = encode_thumb32_immediate (value);
11766 if (newimm == (unsigned int) FAIL)
11767 newimm = thumb32_negate_data_op (&newval, value);
11768 }
e9f89963 11769 else
92e90b6e 11770 {
e9f89963
PB
11771 /* 12 bit immediate for addw/subw. */
11772 if (value < 0)
11773 {
11774 value = -value;
11775 newval ^= 0x00a00000;
11776 }
92e90b6e
PB
11777 if (value > 0xfff)
11778 newimm = (unsigned int) FAIL;
11779 else
11780 newimm = value;
11781 }
cc8a6dd0 11782
c19d1205 11783 if (newimm == (unsigned int)FAIL)
3631a3c8 11784 {
c19d1205
ZW
11785 as_bad_where (fixP->fx_file, fixP->fx_line,
11786 _("invalid constant (%lx) after fixup"),
11787 (unsigned long) value);
11788 break;
3631a3c8
NC
11789 }
11790
c19d1205
ZW
11791 newval |= (newimm & 0x800) << 15;
11792 newval |= (newimm & 0x700) << 4;
11793 newval |= (newimm & 0x0ff);
cc8a6dd0 11794
c19d1205
ZW
11795 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
11796 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
11797 break;
a737bd4d 11798
3eb17e6b 11799 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
11800 if (((unsigned long) value) > 0xffff)
11801 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 11802 _("invalid smc expression"));
2fc8bdac 11803 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
11804 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
11805 md_number_to_chars (buf, newval, INSN_SIZE);
11806 break;
a737bd4d 11807
c19d1205 11808 case BFD_RELOC_ARM_SWI:
adbaf948 11809 if (fixP->tc_fix_data != 0)
c19d1205
ZW
11810 {
11811 if (((unsigned long) value) > 0xff)
11812 as_bad_where (fixP->fx_file, fixP->fx_line,
11813 _("invalid swi expression"));
2fc8bdac 11814 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
11815 newval |= value;
11816 md_number_to_chars (buf, newval, THUMB_SIZE);
11817 }
11818 else
11819 {
11820 if (((unsigned long) value) > 0x00ffffff)
11821 as_bad_where (fixP->fx_file, fixP->fx_line,
11822 _("invalid swi expression"));
2fc8bdac 11823 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
11824 newval |= value;
11825 md_number_to_chars (buf, newval, INSN_SIZE);
11826 }
11827 break;
a737bd4d 11828
c19d1205
ZW
11829 case BFD_RELOC_ARM_MULTI:
11830 if (((unsigned long) value) > 0xffff)
11831 as_bad_where (fixP->fx_file, fixP->fx_line,
11832 _("invalid expression in load/store multiple"));
11833 newval = value | md_chars_to_number (buf, INSN_SIZE);
11834 md_number_to_chars (buf, newval, INSN_SIZE);
11835 break;
a737bd4d 11836
c19d1205 11837#ifdef OBJ_ELF
39b41c9c
PB
11838 case BFD_RELOC_ARM_PCREL_CALL:
11839 newval = md_chars_to_number (buf, INSN_SIZE);
11840 if ((newval & 0xf0000000) == 0xf0000000)
11841 temp = 1;
11842 else
11843 temp = 3;
11844 goto arm_branch_common;
11845
11846 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 11847 case BFD_RELOC_ARM_PLT32:
c19d1205 11848#endif
39b41c9c
PB
11849 case BFD_RELOC_ARM_PCREL_BRANCH:
11850 temp = 3;
11851 goto arm_branch_common;
a737bd4d 11852
39b41c9c
PB
11853 case BFD_RELOC_ARM_PCREL_BLX:
11854 temp = 1;
11855 arm_branch_common:
c19d1205 11856 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
11857 instruction, in a 24 bit, signed field. Bits 26 through 32 either
11858 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
11859 also be be clear. */
11860 if (value & temp)
c19d1205 11861 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
11862 _("misaligned branch destination"));
11863 if ((value & (offsetT)0xfe000000) != (offsetT)0
11864 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
11865 as_bad_where (fixP->fx_file, fixP->fx_line,
11866 _("branch out of range"));
a737bd4d 11867
2fc8bdac 11868 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11869 {
2fc8bdac
ZW
11870 newval = md_chars_to_number (buf, INSN_SIZE);
11871 newval |= (value >> 2) & 0x00ffffff;
11872 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 11873 }
c19d1205 11874 break;
a737bd4d 11875
c19d1205 11876 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
2fc8bdac
ZW
11877 /* CZB can only branch forward. */
11878 if (value & ~0x7e)
11879 as_bad_where (fixP->fx_file, fixP->fx_line,
11880 _("branch out of range"));
a737bd4d 11881
2fc8bdac
ZW
11882 if (fixP->fx_done || !seg->use_rela_p)
11883 {
11884 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205 11885 newval |= ((value & 0x2e) << 2) | ((value & 0x40) << 3);
2fc8bdac
ZW
11886 md_number_to_chars (buf, newval, THUMB_SIZE);
11887 }
c19d1205 11888 break;
a737bd4d 11889
c19d1205 11890 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
11891 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
11892 as_bad_where (fixP->fx_file, fixP->fx_line,
11893 _("branch out of range"));
a737bd4d 11894
2fc8bdac
ZW
11895 if (fixP->fx_done || !seg->use_rela_p)
11896 {
11897 newval = md_chars_to_number (buf, THUMB_SIZE);
11898 newval |= (value & 0x1ff) >> 1;
11899 md_number_to_chars (buf, newval, THUMB_SIZE);
11900 }
c19d1205 11901 break;
a737bd4d 11902
c19d1205 11903 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
11904 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
11905 as_bad_where (fixP->fx_file, fixP->fx_line,
11906 _("branch out of range"));
a737bd4d 11907
2fc8bdac
ZW
11908 if (fixP->fx_done || !seg->use_rela_p)
11909 {
11910 newval = md_chars_to_number (buf, THUMB_SIZE);
11911 newval |= (value & 0xfff) >> 1;
11912 md_number_to_chars (buf, newval, THUMB_SIZE);
11913 }
c19d1205 11914 break;
a737bd4d 11915
c19d1205 11916 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
11917 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
11918 as_bad_where (fixP->fx_file, fixP->fx_line,
11919 _("conditional branch out of range"));
404ff6b5 11920
2fc8bdac
ZW
11921 if (fixP->fx_done || !seg->use_rela_p)
11922 {
11923 offsetT newval2;
11924 addressT S, J1, J2, lo, hi;
404ff6b5 11925
2fc8bdac
ZW
11926 S = (value & 0x00100000) >> 20;
11927 J2 = (value & 0x00080000) >> 19;
11928 J1 = (value & 0x00040000) >> 18;
11929 hi = (value & 0x0003f000) >> 12;
11930 lo = (value & 0x00000ffe) >> 1;
6c43fab6 11931
2fc8bdac
ZW
11932 newval = md_chars_to_number (buf, THUMB_SIZE);
11933 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11934 newval |= (S << 10) | hi;
11935 newval2 |= (J1 << 13) | (J2 << 11) | lo;
11936 md_number_to_chars (buf, newval, THUMB_SIZE);
11937 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11938 }
c19d1205 11939 break;
6c43fab6 11940
c19d1205
ZW
11941 case BFD_RELOC_THUMB_PCREL_BLX:
11942 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
11943 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
11944 as_bad_where (fixP->fx_file, fixP->fx_line,
11945 _("branch out of range"));
404ff6b5 11946
2fc8bdac
ZW
11947 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
11948 /* For a BLX instruction, make sure that the relocation is rounded up
11949 to a word boundary. This follows the semantics of the instruction
11950 which specifies that bit 1 of the target address will come from bit
11951 1 of the base address. */
11952 value = (value + 1) & ~ 1;
404ff6b5 11953
2fc8bdac 11954 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 11955 {
2fc8bdac
ZW
11956 offsetT newval2;
11957
11958 newval = md_chars_to_number (buf, THUMB_SIZE);
11959 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11960 newval |= (value & 0x7fffff) >> 12;
11961 newval2 |= (value & 0xfff) >> 1;
11962 md_number_to_chars (buf, newval, THUMB_SIZE);
11963 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 11964 }
c19d1205 11965 break;
404ff6b5 11966
c19d1205 11967 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
11968 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
11969 as_bad_where (fixP->fx_file, fixP->fx_line,
11970 _("branch out of range"));
6c43fab6 11971
2fc8bdac
ZW
11972 if (fixP->fx_done || !seg->use_rela_p)
11973 {
11974 offsetT newval2;
11975 addressT S, I1, I2, lo, hi;
6c43fab6 11976
2fc8bdac
ZW
11977 S = (value & 0x01000000) >> 24;
11978 I1 = (value & 0x00800000) >> 23;
11979 I2 = (value & 0x00400000) >> 22;
11980 hi = (value & 0x003ff000) >> 12;
11981 lo = (value & 0x00000ffe) >> 1;
6c43fab6 11982
2fc8bdac
ZW
11983 I1 = !(I1 ^ S);
11984 I2 = !(I2 ^ S);
a737bd4d 11985
2fc8bdac
ZW
11986 newval = md_chars_to_number (buf, THUMB_SIZE);
11987 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
11988 newval |= (S << 10) | hi;
11989 newval2 |= (I1 << 13) | (I2 << 11) | lo;
11990 md_number_to_chars (buf, newval, THUMB_SIZE);
11991 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
11992 }
11993 break;
a737bd4d 11994
2fc8bdac
ZW
11995 case BFD_RELOC_8:
11996 if (fixP->fx_done || !seg->use_rela_p)
11997 md_number_to_chars (buf, value, 1);
c19d1205 11998 break;
a737bd4d 11999
c19d1205 12000 case BFD_RELOC_16:
2fc8bdac 12001 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 12002 md_number_to_chars (buf, value, 2);
c19d1205 12003 break;
a737bd4d 12004
c19d1205
ZW
12005#ifdef OBJ_ELF
12006 case BFD_RELOC_ARM_TLS_GD32:
12007 case BFD_RELOC_ARM_TLS_LE32:
12008 case BFD_RELOC_ARM_TLS_IE32:
12009 case BFD_RELOC_ARM_TLS_LDM32:
12010 case BFD_RELOC_ARM_TLS_LDO32:
12011 S_SET_THREAD_LOCAL (fixP->fx_addsy);
12012 /* fall through */
6c43fab6 12013
c19d1205
ZW
12014 case BFD_RELOC_ARM_GOT32:
12015 case BFD_RELOC_ARM_GOTOFF:
12016 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
12017 if (fixP->fx_done || !seg->use_rela_p)
12018 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
12019 break;
12020#endif
6c43fab6 12021
c19d1205
ZW
12022 case BFD_RELOC_RVA:
12023 case BFD_RELOC_32:
12024 case BFD_RELOC_ARM_TARGET1:
12025 case BFD_RELOC_ARM_ROSEGREL32:
12026 case BFD_RELOC_ARM_SBREL32:
12027 case BFD_RELOC_32_PCREL:
2fc8bdac 12028 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 12029 md_number_to_chars (buf, value, 4);
c19d1205 12030 break;
6c43fab6 12031
c19d1205
ZW
12032#ifdef OBJ_ELF
12033 case BFD_RELOC_ARM_PREL31:
2fc8bdac 12034 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
12035 {
12036 newval = md_chars_to_number (buf, 4) & 0x80000000;
12037 if ((value ^ (value >> 1)) & 0x40000000)
12038 {
12039 as_bad_where (fixP->fx_file, fixP->fx_line,
12040 _("rel31 relocation overflow"));
12041 }
12042 newval |= value & 0x7fffffff;
12043 md_number_to_chars (buf, newval, 4);
12044 }
12045 break;
c19d1205 12046#endif
a737bd4d 12047
c19d1205 12048 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 12049 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
12050 if (value < -1023 || value > 1023 || (value & 3))
12051 as_bad_where (fixP->fx_file, fixP->fx_line,
12052 _("co-processor offset out of range"));
12053 cp_off_common:
12054 sign = value >= 0;
12055 if (value < 0)
12056 value = -value;
8f06b2d8
PB
12057 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
12058 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
12059 newval = md_chars_to_number (buf, INSN_SIZE);
12060 else
12061 newval = get_thumb32_insn (buf);
12062 newval &= 0xff7fff00;
c19d1205
ZW
12063 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
12064 if (value == 0)
12065 newval &= ~WRITE_BACK;
8f06b2d8
PB
12066 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
12067 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
12068 md_number_to_chars (buf, newval, INSN_SIZE);
12069 else
12070 put_thumb32_insn (buf, newval);
c19d1205 12071 break;
a737bd4d 12072
c19d1205 12073 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 12074 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
12075 if (value < -255 || value > 255)
12076 as_bad_where (fixP->fx_file, fixP->fx_line,
12077 _("co-processor offset out of range"));
12078 goto cp_off_common;
6c43fab6 12079
c19d1205
ZW
12080 case BFD_RELOC_ARM_THUMB_OFFSET:
12081 newval = md_chars_to_number (buf, THUMB_SIZE);
12082 /* Exactly what ranges, and where the offset is inserted depends
12083 on the type of instruction, we can establish this from the
12084 top 4 bits. */
12085 switch (newval >> 12)
12086 {
12087 case 4: /* PC load. */
12088 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
12089 forced to zero for these loads; md_pcrel_from has already
12090 compensated for this. */
12091 if (value & 3)
12092 as_bad_where (fixP->fx_file, fixP->fx_line,
12093 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
12094 (((unsigned long) fixP->fx_frag->fr_address
12095 + (unsigned long) fixP->fx_where) & ~3)
12096 + (unsigned long) value);
a737bd4d 12097
c19d1205
ZW
12098 if (value & ~0x3fc)
12099 as_bad_where (fixP->fx_file, fixP->fx_line,
12100 _("invalid offset, value too big (0x%08lX)"),
12101 (long) value);
a737bd4d 12102
c19d1205
ZW
12103 newval |= value >> 2;
12104 break;
a737bd4d 12105
c19d1205
ZW
12106 case 9: /* SP load/store. */
12107 if (value & ~0x3fc)
12108 as_bad_where (fixP->fx_file, fixP->fx_line,
12109 _("invalid offset, value too big (0x%08lX)"),
12110 (long) value);
12111 newval |= value >> 2;
12112 break;
6c43fab6 12113
c19d1205
ZW
12114 case 6: /* Word load/store. */
12115 if (value & ~0x7c)
12116 as_bad_where (fixP->fx_file, fixP->fx_line,
12117 _("invalid offset, value too big (0x%08lX)"),
12118 (long) value);
12119 newval |= value << 4; /* 6 - 2. */
12120 break;
a737bd4d 12121
c19d1205
ZW
12122 case 7: /* Byte load/store. */
12123 if (value & ~0x1f)
12124 as_bad_where (fixP->fx_file, fixP->fx_line,
12125 _("invalid offset, value too big (0x%08lX)"),
12126 (long) value);
12127 newval |= value << 6;
12128 break;
a737bd4d 12129
c19d1205
ZW
12130 case 8: /* Halfword load/store. */
12131 if (value & ~0x3e)
12132 as_bad_where (fixP->fx_file, fixP->fx_line,
12133 _("invalid offset, value too big (0x%08lX)"),
12134 (long) value);
12135 newval |= value << 5; /* 6 - 1. */
12136 break;
a737bd4d 12137
c19d1205
ZW
12138 default:
12139 as_bad_where (fixP->fx_file, fixP->fx_line,
12140 "Unable to process relocation for thumb opcode: %lx",
12141 (unsigned long) newval);
12142 break;
12143 }
12144 md_number_to_chars (buf, newval, THUMB_SIZE);
12145 break;
a737bd4d 12146
c19d1205
ZW
12147 case BFD_RELOC_ARM_THUMB_ADD:
12148 /* This is a complicated relocation, since we use it for all of
12149 the following immediate relocations:
a737bd4d 12150
c19d1205
ZW
12151 3bit ADD/SUB
12152 8bit ADD/SUB
12153 9bit ADD/SUB SP word-aligned
12154 10bit ADD PC/SP word-aligned
a737bd4d 12155
c19d1205
ZW
12156 The type of instruction being processed is encoded in the
12157 instruction field:
a737bd4d 12158
c19d1205
ZW
12159 0x8000 SUB
12160 0x00F0 Rd
12161 0x000F Rs
12162 */
12163 newval = md_chars_to_number (buf, THUMB_SIZE);
12164 {
12165 int rd = (newval >> 4) & 0xf;
12166 int rs = newval & 0xf;
12167 int subtract = !!(newval & 0x8000);
a737bd4d 12168
c19d1205
ZW
12169 /* Check for HI regs, only very restricted cases allowed:
12170 Adjusting SP, and using PC or SP to get an address. */
12171 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
12172 || (rs > 7 && rs != REG_SP && rs != REG_PC))
12173 as_bad_where (fixP->fx_file, fixP->fx_line,
12174 _("invalid Hi register with immediate"));
a737bd4d 12175
c19d1205
ZW
12176 /* If value is negative, choose the opposite instruction. */
12177 if (value < 0)
12178 {
12179 value = -value;
12180 subtract = !subtract;
12181 if (value < 0)
12182 as_bad_where (fixP->fx_file, fixP->fx_line,
12183 _("immediate value out of range"));
12184 }
a737bd4d 12185
c19d1205
ZW
12186 if (rd == REG_SP)
12187 {
12188 if (value & ~0x1fc)
12189 as_bad_where (fixP->fx_file, fixP->fx_line,
12190 _("invalid immediate for stack address calculation"));
12191 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
12192 newval |= value >> 2;
12193 }
12194 else if (rs == REG_PC || rs == REG_SP)
12195 {
12196 if (subtract || value & ~0x3fc)
12197 as_bad_where (fixP->fx_file, fixP->fx_line,
12198 _("invalid immediate for address calculation (value = 0x%08lX)"),
12199 (unsigned long) value);
12200 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
12201 newval |= rd << 8;
12202 newval |= value >> 2;
12203 }
12204 else if (rs == rd)
12205 {
12206 if (value & ~0xff)
12207 as_bad_where (fixP->fx_file, fixP->fx_line,
12208 _("immediate value out of range"));
12209 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
12210 newval |= (rd << 8) | value;
12211 }
12212 else
12213 {
12214 if (value & ~0x7)
12215 as_bad_where (fixP->fx_file, fixP->fx_line,
12216 _("immediate value out of range"));
12217 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
12218 newval |= rd | (rs << 3) | (value << 6);
12219 }
12220 }
12221 md_number_to_chars (buf, newval, THUMB_SIZE);
12222 break;
a737bd4d 12223
c19d1205
ZW
12224 case BFD_RELOC_ARM_THUMB_IMM:
12225 newval = md_chars_to_number (buf, THUMB_SIZE);
12226 if (value < 0 || value > 255)
12227 as_bad_where (fixP->fx_file, fixP->fx_line,
12228 _("invalid immediate: %ld is too large"),
12229 (long) value);
12230 newval |= value;
12231 md_number_to_chars (buf, newval, THUMB_SIZE);
12232 break;
a737bd4d 12233
c19d1205
ZW
12234 case BFD_RELOC_ARM_THUMB_SHIFT:
12235 /* 5bit shift value (0..32). LSL cannot take 32. */
12236 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
12237 temp = newval & 0xf800;
12238 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
12239 as_bad_where (fixP->fx_file, fixP->fx_line,
12240 _("invalid shift value: %ld"), (long) value);
12241 /* Shifts of zero must be encoded as LSL. */
12242 if (value == 0)
12243 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
12244 /* Shifts of 32 are encoded as zero. */
12245 else if (value == 32)
12246 value = 0;
12247 newval |= value << 6;
12248 md_number_to_chars (buf, newval, THUMB_SIZE);
12249 break;
a737bd4d 12250
c19d1205
ZW
12251 case BFD_RELOC_VTABLE_INHERIT:
12252 case BFD_RELOC_VTABLE_ENTRY:
12253 fixP->fx_done = 0;
12254 return;
6c43fab6 12255
c19d1205
ZW
12256 case BFD_RELOC_UNUSED:
12257 default:
12258 as_bad_where (fixP->fx_file, fixP->fx_line,
12259 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
12260 }
6c43fab6
RE
12261}
12262
c19d1205
ZW
12263/* Translate internal representation of relocation info to BFD target
12264 format. */
a737bd4d 12265
c19d1205 12266arelent *
00a97672 12267tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 12268{
c19d1205
ZW
12269 arelent * reloc;
12270 bfd_reloc_code_real_type code;
a737bd4d 12271
c19d1205 12272 reloc = xmalloc (sizeof (arelent));
a737bd4d 12273
c19d1205
ZW
12274 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
12275 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
12276 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 12277
2fc8bdac 12278 if (fixp->fx_pcrel)
00a97672
RS
12279 {
12280 if (section->use_rela_p)
12281 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
12282 else
12283 fixp->fx_offset = reloc->address;
12284 }
c19d1205 12285 reloc->addend = fixp->fx_offset;
a737bd4d 12286
c19d1205 12287 switch (fixp->fx_r_type)
a737bd4d 12288 {
c19d1205
ZW
12289 case BFD_RELOC_8:
12290 if (fixp->fx_pcrel)
12291 {
12292 code = BFD_RELOC_8_PCREL;
12293 break;
12294 }
a737bd4d 12295
c19d1205
ZW
12296 case BFD_RELOC_16:
12297 if (fixp->fx_pcrel)
12298 {
12299 code = BFD_RELOC_16_PCREL;
12300 break;
12301 }
6c43fab6 12302
c19d1205
ZW
12303 case BFD_RELOC_32:
12304 if (fixp->fx_pcrel)
12305 {
12306 code = BFD_RELOC_32_PCREL;
12307 break;
12308 }
a737bd4d 12309
c19d1205
ZW
12310 case BFD_RELOC_NONE:
12311 case BFD_RELOC_ARM_PCREL_BRANCH:
12312 case BFD_RELOC_ARM_PCREL_BLX:
12313 case BFD_RELOC_RVA:
12314 case BFD_RELOC_THUMB_PCREL_BRANCH7:
12315 case BFD_RELOC_THUMB_PCREL_BRANCH9:
12316 case BFD_RELOC_THUMB_PCREL_BRANCH12:
12317 case BFD_RELOC_THUMB_PCREL_BRANCH20:
12318 case BFD_RELOC_THUMB_PCREL_BRANCH23:
12319 case BFD_RELOC_THUMB_PCREL_BRANCH25:
12320 case BFD_RELOC_THUMB_PCREL_BLX:
12321 case BFD_RELOC_VTABLE_ENTRY:
12322 case BFD_RELOC_VTABLE_INHERIT:
12323 code = fixp->fx_r_type;
12324 break;
a737bd4d 12325
c19d1205
ZW
12326 case BFD_RELOC_ARM_LITERAL:
12327 case BFD_RELOC_ARM_HWLITERAL:
12328 /* If this is called then the a literal has
12329 been referenced across a section boundary. */
12330 as_bad_where (fixp->fx_file, fixp->fx_line,
12331 _("literal referenced across section boundary"));
12332 return NULL;
a737bd4d 12333
c19d1205
ZW
12334#ifdef OBJ_ELF
12335 case BFD_RELOC_ARM_GOT32:
12336 case BFD_RELOC_ARM_GOTOFF:
12337 case BFD_RELOC_ARM_PLT32:
12338 case BFD_RELOC_ARM_TARGET1:
12339 case BFD_RELOC_ARM_ROSEGREL32:
12340 case BFD_RELOC_ARM_SBREL32:
12341 case BFD_RELOC_ARM_PREL31:
12342 case BFD_RELOC_ARM_TARGET2:
12343 case BFD_RELOC_ARM_TLS_LE32:
12344 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
12345 case BFD_RELOC_ARM_PCREL_CALL:
12346 case BFD_RELOC_ARM_PCREL_JUMP:
c19d1205
ZW
12347 code = fixp->fx_r_type;
12348 break;
a737bd4d 12349
c19d1205
ZW
12350 case BFD_RELOC_ARM_TLS_GD32:
12351 case BFD_RELOC_ARM_TLS_IE32:
12352 case BFD_RELOC_ARM_TLS_LDM32:
12353 /* BFD will include the symbol's address in the addend.
12354 But we don't want that, so subtract it out again here. */
12355 if (!S_IS_COMMON (fixp->fx_addsy))
12356 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
12357 code = fixp->fx_r_type;
12358 break;
12359#endif
a737bd4d 12360
c19d1205
ZW
12361 case BFD_RELOC_ARM_IMMEDIATE:
12362 as_bad_where (fixp->fx_file, fixp->fx_line,
12363 _("internal relocation (type: IMMEDIATE) not fixed up"));
12364 return NULL;
a737bd4d 12365
c19d1205
ZW
12366 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
12367 as_bad_where (fixp->fx_file, fixp->fx_line,
12368 _("ADRL used for a symbol not defined in the same file"));
12369 return NULL;
a737bd4d 12370
c19d1205 12371 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
12372 if (section->use_rela_p)
12373 {
12374 code = fixp->fx_r_type;
12375 break;
12376 }
12377
c19d1205
ZW
12378 if (fixp->fx_addsy != NULL
12379 && !S_IS_DEFINED (fixp->fx_addsy)
12380 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 12381 {
c19d1205
ZW
12382 as_bad_where (fixp->fx_file, fixp->fx_line,
12383 _("undefined local label `%s'"),
12384 S_GET_NAME (fixp->fx_addsy));
12385 return NULL;
a737bd4d
NC
12386 }
12387
c19d1205
ZW
12388 as_bad_where (fixp->fx_file, fixp->fx_line,
12389 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
12390 return NULL;
a737bd4d 12391
c19d1205
ZW
12392 default:
12393 {
12394 char * type;
6c43fab6 12395
c19d1205
ZW
12396 switch (fixp->fx_r_type)
12397 {
12398 case BFD_RELOC_NONE: type = "NONE"; break;
12399 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
12400 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 12401 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
12402 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
12403 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
12404 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 12405 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
12406 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
12407 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
12408 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
12409 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
12410 default: type = _("<unknown>"); break;
12411 }
12412 as_bad_where (fixp->fx_file, fixp->fx_line,
12413 _("cannot represent %s relocation in this object file format"),
12414 type);
12415 return NULL;
12416 }
a737bd4d 12417 }
6c43fab6 12418
c19d1205
ZW
12419#ifdef OBJ_ELF
12420 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
12421 && GOT_symbol
12422 && fixp->fx_addsy == GOT_symbol)
12423 {
12424 code = BFD_RELOC_ARM_GOTPC;
12425 reloc->addend = fixp->fx_offset = reloc->address;
12426 }
12427#endif
6c43fab6 12428
c19d1205 12429 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 12430
c19d1205
ZW
12431 if (reloc->howto == NULL)
12432 {
12433 as_bad_where (fixp->fx_file, fixp->fx_line,
12434 _("cannot represent %s relocation in this object file format"),
12435 bfd_get_reloc_code_name (code));
12436 return NULL;
12437 }
6c43fab6 12438
c19d1205
ZW
12439 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
12440 vtable entry to be used in the relocation's section offset. */
12441 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12442 reloc->address = fixp->fx_offset;
6c43fab6 12443
c19d1205 12444 return reloc;
6c43fab6
RE
12445}
12446
c19d1205 12447/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 12448
c19d1205
ZW
12449void
12450cons_fix_new_arm (fragS * frag,
12451 int where,
12452 int size,
12453 expressionS * exp)
6c43fab6 12454{
c19d1205
ZW
12455 bfd_reloc_code_real_type type;
12456 int pcrel = 0;
6c43fab6 12457
c19d1205
ZW
12458 /* Pick a reloc.
12459 FIXME: @@ Should look at CPU word size. */
12460 switch (size)
12461 {
12462 case 1:
12463 type = BFD_RELOC_8;
12464 break;
12465 case 2:
12466 type = BFD_RELOC_16;
12467 break;
12468 case 4:
12469 default:
12470 type = BFD_RELOC_32;
12471 break;
12472 case 8:
12473 type = BFD_RELOC_64;
12474 break;
12475 }
6c43fab6 12476
c19d1205
ZW
12477 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
12478}
6c43fab6 12479
c19d1205
ZW
12480#if defined OBJ_COFF || defined OBJ_ELF
12481void
12482arm_validate_fix (fixS * fixP)
6c43fab6 12483{
c19d1205
ZW
12484 /* If the destination of the branch is a defined symbol which does not have
12485 the THUMB_FUNC attribute, then we must be calling a function which has
12486 the (interfacearm) attribute. We look for the Thumb entry point to that
12487 function and change the branch to refer to that function instead. */
12488 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
12489 && fixP->fx_addsy != NULL
12490 && S_IS_DEFINED (fixP->fx_addsy)
12491 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 12492 {
c19d1205 12493 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 12494 }
c19d1205
ZW
12495}
12496#endif
6c43fab6 12497
c19d1205
ZW
12498int
12499arm_force_relocation (struct fix * fixp)
12500{
12501#if defined (OBJ_COFF) && defined (TE_PE)
12502 if (fixp->fx_r_type == BFD_RELOC_RVA)
12503 return 1;
12504#endif
6c43fab6 12505
c19d1205
ZW
12506 /* Resolve these relocations even if the symbol is extern or weak. */
12507 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
12508 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8
PB
12509 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
12510 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
12511 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
12512 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 12513 return 0;
a737bd4d 12514
c19d1205 12515 return generic_force_reloc (fixp);
404ff6b5
AH
12516}
12517
c19d1205
ZW
12518#ifdef OBJ_COFF
12519/* This is a little hack to help the gas/arm/adrl.s test. It prevents
12520 local labels from being added to the output symbol table when they
12521 are used with the ADRL pseudo op. The ADRL relocation should always
12522 be resolved before the binbary is emitted, so it is safe to say that
12523 it is adjustable. */
404ff6b5 12524
c19d1205
ZW
12525bfd_boolean
12526arm_fix_adjustable (fixS * fixP)
404ff6b5 12527{
c19d1205
ZW
12528 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
12529 return 1;
12530 return 0;
404ff6b5 12531}
c19d1205 12532#endif
404ff6b5 12533
c19d1205
ZW
12534#ifdef OBJ_ELF
12535/* Relocations against Thumb function names must be left unadjusted,
12536 so that the linker can use this information to correctly set the
12537 bottom bit of their addresses. The MIPS version of this function
12538 also prevents relocations that are mips-16 specific, but I do not
12539 know why it does this.
404ff6b5 12540
c19d1205
ZW
12541 FIXME:
12542 There is one other problem that ought to be addressed here, but
12543 which currently is not: Taking the address of a label (rather
12544 than a function) and then later jumping to that address. Such
12545 addresses also ought to have their bottom bit set (assuming that
12546 they reside in Thumb code), but at the moment they will not. */
404ff6b5 12547
c19d1205
ZW
12548bfd_boolean
12549arm_fix_adjustable (fixS * fixP)
404ff6b5 12550{
c19d1205
ZW
12551 if (fixP->fx_addsy == NULL)
12552 return 1;
404ff6b5 12553
c19d1205
ZW
12554 if (THUMB_IS_FUNC (fixP->fx_addsy)
12555 && fixP->fx_subsy == NULL)
12556 return 0;
a737bd4d 12557
c19d1205
ZW
12558 /* We need the symbol name for the VTABLE entries. */
12559 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
12560 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
12561 return 0;
404ff6b5 12562
c19d1205
ZW
12563 /* Don't allow symbols to be discarded on GOT related relocs. */
12564 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
12565 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
12566 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
12567 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
12568 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
12569 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
12570 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
12571 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
12572 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
12573 return 0;
a737bd4d 12574
c19d1205 12575 return 1;
a737bd4d 12576}
404ff6b5 12577
c19d1205
ZW
12578const char *
12579elf32_arm_target_format (void)
404ff6b5 12580{
c19d1205
ZW
12581#ifdef TE_SYMBIAN
12582 return (target_big_endian
12583 ? "elf32-bigarm-symbian"
12584 : "elf32-littlearm-symbian");
12585#elif defined (TE_VXWORKS)
12586 return (target_big_endian
12587 ? "elf32-bigarm-vxworks"
12588 : "elf32-littlearm-vxworks");
12589#else
12590 if (target_big_endian)
12591 return "elf32-bigarm";
12592 else
12593 return "elf32-littlearm";
12594#endif
404ff6b5
AH
12595}
12596
c19d1205
ZW
12597void
12598armelf_frob_symbol (symbolS * symp,
12599 int * puntp)
404ff6b5 12600{
c19d1205
ZW
12601 elf_frob_symbol (symp, puntp);
12602}
12603#endif
404ff6b5 12604
c19d1205 12605/* MD interface: Finalization. */
a737bd4d 12606
c19d1205
ZW
12607/* A good place to do this, although this was probably not intended
12608 for this kind of use. We need to dump the literal pool before
12609 references are made to a null symbol pointer. */
a737bd4d 12610
c19d1205
ZW
12611void
12612arm_cleanup (void)
12613{
12614 literal_pool * pool;
a737bd4d 12615
c19d1205
ZW
12616 for (pool = list_of_pools; pool; pool = pool->next)
12617 {
12618 /* Put it at the end of the relevent section. */
12619 subseg_set (pool->section, pool->sub_section);
12620#ifdef OBJ_ELF
12621 arm_elf_change_section ();
12622#endif
12623 s_ltorg (0);
12624 }
404ff6b5
AH
12625}
12626
c19d1205
ZW
12627/* Adjust the symbol table. This marks Thumb symbols as distinct from
12628 ARM ones. */
404ff6b5 12629
c19d1205
ZW
12630void
12631arm_adjust_symtab (void)
404ff6b5 12632{
c19d1205
ZW
12633#ifdef OBJ_COFF
12634 symbolS * sym;
404ff6b5 12635
c19d1205
ZW
12636 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
12637 {
12638 if (ARM_IS_THUMB (sym))
12639 {
12640 if (THUMB_IS_FUNC (sym))
12641 {
12642 /* Mark the symbol as a Thumb function. */
12643 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
12644 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
12645 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 12646
c19d1205
ZW
12647 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
12648 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
12649 else
12650 as_bad (_("%s: unexpected function type: %d"),
12651 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
12652 }
12653 else switch (S_GET_STORAGE_CLASS (sym))
12654 {
12655 case C_EXT:
12656 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
12657 break;
12658 case C_STAT:
12659 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
12660 break;
12661 case C_LABEL:
12662 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
12663 break;
12664 default:
12665 /* Do nothing. */
12666 break;
12667 }
12668 }
a737bd4d 12669
c19d1205
ZW
12670 if (ARM_IS_INTERWORK (sym))
12671 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 12672 }
c19d1205
ZW
12673#endif
12674#ifdef OBJ_ELF
12675 symbolS * sym;
12676 char bind;
404ff6b5 12677
c19d1205 12678 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 12679 {
c19d1205
ZW
12680 if (ARM_IS_THUMB (sym))
12681 {
12682 elf_symbol_type * elf_sym;
404ff6b5 12683
c19d1205
ZW
12684 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
12685 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 12686
c19d1205
ZW
12687 if (! bfd_is_arm_mapping_symbol_name (elf_sym->symbol.name))
12688 {
12689 /* If it's a .thumb_func, declare it as so,
12690 otherwise tag label as .code 16. */
12691 if (THUMB_IS_FUNC (sym))
12692 elf_sym->internal_elf_sym.st_info =
12693 ELF_ST_INFO (bind, STT_ARM_TFUNC);
12694 else
12695 elf_sym->internal_elf_sym.st_info =
12696 ELF_ST_INFO (bind, STT_ARM_16BIT);
12697 }
12698 }
12699 }
12700#endif
404ff6b5
AH
12701}
12702
c19d1205 12703/* MD interface: Initialization. */
404ff6b5 12704
a737bd4d 12705static void
c19d1205 12706set_constant_flonums (void)
a737bd4d 12707{
c19d1205 12708 int i;
404ff6b5 12709
c19d1205
ZW
12710 for (i = 0; i < NUM_FLOAT_VALS; i++)
12711 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
12712 abort ();
a737bd4d 12713}
404ff6b5 12714
c19d1205
ZW
12715void
12716md_begin (void)
a737bd4d 12717{
c19d1205
ZW
12718 unsigned mach;
12719 unsigned int i;
404ff6b5 12720
c19d1205
ZW
12721 if ( (arm_ops_hsh = hash_new ()) == NULL
12722 || (arm_cond_hsh = hash_new ()) == NULL
12723 || (arm_shift_hsh = hash_new ()) == NULL
12724 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 12725 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 12726 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
12727 || (arm_reloc_hsh = hash_new ()) == NULL
12728 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
12729 as_fatal (_("virtual memory exhausted"));
12730
12731 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
12732 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
12733 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
12734 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
12735 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
12736 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
12737 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
12738 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
12739 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
12740 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
12741 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
12742 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
12743 for (i = 0;
12744 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
12745 i++)
12746 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
12747 (PTR) (barrier_opt_names + i));
c19d1205
ZW
12748#ifdef OBJ_ELF
12749 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
12750 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
12751#endif
12752
12753 set_constant_flonums ();
404ff6b5 12754
c19d1205
ZW
12755 /* Set the cpu variant based on the command-line options. We prefer
12756 -mcpu= over -march= if both are set (as for GCC); and we prefer
12757 -mfpu= over any other way of setting the floating point unit.
12758 Use of legacy options with new options are faulted. */
e74cfd16 12759 if (legacy_cpu)
404ff6b5 12760 {
e74cfd16 12761 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
12762 as_bad (_("use of old and new-style options to set CPU type"));
12763
12764 mcpu_cpu_opt = legacy_cpu;
404ff6b5 12765 }
e74cfd16 12766 else if (!mcpu_cpu_opt)
c19d1205 12767 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 12768
e74cfd16 12769 if (legacy_fpu)
c19d1205 12770 {
e74cfd16 12771 if (mfpu_opt)
c19d1205 12772 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
12773
12774 mfpu_opt = legacy_fpu;
12775 }
e74cfd16 12776 else if (!mfpu_opt)
03b1477f 12777 {
c19d1205 12778#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
12779 /* Some environments specify a default FPU. If they don't, infer it
12780 from the processor. */
e74cfd16 12781 if (mcpu_fpu_opt)
03b1477f
RE
12782 mfpu_opt = mcpu_fpu_opt;
12783 else
12784 mfpu_opt = march_fpu_opt;
39c2da32 12785#else
e74cfd16 12786 mfpu_opt = &fpu_default;
39c2da32 12787#endif
03b1477f
RE
12788 }
12789
e74cfd16 12790 if (!mfpu_opt)
03b1477f 12791 {
e74cfd16
PB
12792 if (!mcpu_cpu_opt)
12793 mfpu_opt = &fpu_default;
12794 else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
12795 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 12796 else
e74cfd16 12797 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
12798 }
12799
ee065d83 12800#ifdef CPU_DEFAULT
e74cfd16 12801 if (!mcpu_cpu_opt)
ee065d83 12802 {
e74cfd16
PB
12803 mcpu_cpu_opt = &cpu_default;
12804 selected_cpu = cpu_default;
ee065d83 12805 }
e74cfd16
PB
12806#else
12807 if (mcpu_cpu_opt)
12808 selected_cpu = *mcpu_cpu_opt;
ee065d83 12809 else
e74cfd16 12810 mcpu_cpu_opt = &arm_arch_any;
ee065d83 12811#endif
03b1477f 12812
e74cfd16 12813 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 12814
e74cfd16 12815 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 12816
f17c130b 12817#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 12818 {
7cc69913
NC
12819 unsigned int flags = 0;
12820
12821#if defined OBJ_ELF
12822 flags = meabi_flags;
d507cf36
PB
12823
12824 switch (meabi_flags)
33a392fb 12825 {
d507cf36 12826 case EF_ARM_EABI_UNKNOWN:
7cc69913 12827#endif
d507cf36
PB
12828 /* Set the flags in the private structure. */
12829 if (uses_apcs_26) flags |= F_APCS26;
12830 if (support_interwork) flags |= F_INTERWORK;
12831 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 12832 if (pic_code) flags |= F_PIC;
e74cfd16 12833 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
12834 flags |= F_SOFT_FLOAT;
12835
d507cf36
PB
12836 switch (mfloat_abi_opt)
12837 {
12838 case ARM_FLOAT_ABI_SOFT:
12839 case ARM_FLOAT_ABI_SOFTFP:
12840 flags |= F_SOFT_FLOAT;
12841 break;
33a392fb 12842
d507cf36
PB
12843 case ARM_FLOAT_ABI_HARD:
12844 if (flags & F_SOFT_FLOAT)
12845 as_bad (_("hard-float conflicts with specified fpu"));
12846 break;
12847 }
03b1477f 12848
e74cfd16
PB
12849 /* Using pure-endian doubles (even if soft-float). */
12850 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 12851 flags |= F_VFP_FLOAT;
f17c130b 12852
fde78edd 12853#if defined OBJ_ELF
e74cfd16 12854 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 12855 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
12856 break;
12857
8cb51566 12858 case EF_ARM_EABI_VER4:
3a4a14e9 12859 case EF_ARM_EABI_VER5:
c19d1205 12860 /* No additional flags to set. */
d507cf36
PB
12861 break;
12862
12863 default:
12864 abort ();
12865 }
7cc69913 12866#endif
b99bd4ef
NC
12867 bfd_set_private_flags (stdoutput, flags);
12868
12869 /* We have run out flags in the COFF header to encode the
12870 status of ATPCS support, so instead we create a dummy,
c19d1205 12871 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
12872 if (atpcs)
12873 {
12874 asection * sec;
12875
12876 sec = bfd_make_section (stdoutput, ".arm.atpcs");
12877
12878 if (sec != NULL)
12879 {
12880 bfd_set_section_flags
12881 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
12882 bfd_set_section_size (stdoutput, sec, 0);
12883 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
12884 }
12885 }
7cc69913 12886 }
f17c130b 12887#endif
b99bd4ef
NC
12888
12889 /* Record the CPU type as well. */
e74cfd16 12890 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 12891 mach = bfd_mach_arm_iWMMXt;
e74cfd16 12892 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 12893 mach = bfd_mach_arm_XScale;
e74cfd16 12894 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 12895 mach = bfd_mach_arm_ep9312;
e74cfd16 12896 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 12897 mach = bfd_mach_arm_5TE;
e74cfd16 12898 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 12899 {
e74cfd16 12900 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
12901 mach = bfd_mach_arm_5T;
12902 else
12903 mach = bfd_mach_arm_5;
12904 }
e74cfd16 12905 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 12906 {
e74cfd16 12907 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
12908 mach = bfd_mach_arm_4T;
12909 else
12910 mach = bfd_mach_arm_4;
12911 }
e74cfd16 12912 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 12913 mach = bfd_mach_arm_3M;
e74cfd16
PB
12914 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
12915 mach = bfd_mach_arm_3;
12916 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
12917 mach = bfd_mach_arm_2a;
12918 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
12919 mach = bfd_mach_arm_2;
12920 else
12921 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
12922
12923 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
12924}
12925
c19d1205 12926/* Command line processing. */
b99bd4ef 12927
c19d1205
ZW
12928/* md_parse_option
12929 Invocation line includes a switch not recognized by the base assembler.
12930 See if it's a processor-specific option.
b99bd4ef 12931
c19d1205
ZW
12932 This routine is somewhat complicated by the need for backwards
12933 compatibility (since older releases of gcc can't be changed).
12934 The new options try to make the interface as compatible as
12935 possible with GCC.
b99bd4ef 12936
c19d1205 12937 New options (supported) are:
b99bd4ef 12938
c19d1205
ZW
12939 -mcpu=<cpu name> Assemble for selected processor
12940 -march=<architecture name> Assemble for selected architecture
12941 -mfpu=<fpu architecture> Assemble for selected FPU.
12942 -EB/-mbig-endian Big-endian
12943 -EL/-mlittle-endian Little-endian
12944 -k Generate PIC code
12945 -mthumb Start in Thumb mode
12946 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 12947
c19d1205 12948 For now we will also provide support for:
b99bd4ef 12949
c19d1205
ZW
12950 -mapcs-32 32-bit Program counter
12951 -mapcs-26 26-bit Program counter
12952 -macps-float Floats passed in FP registers
12953 -mapcs-reentrant Reentrant code
12954 -matpcs
12955 (sometime these will probably be replaced with -mapcs=<list of options>
12956 and -matpcs=<list of options>)
b99bd4ef 12957
c19d1205
ZW
12958 The remaining options are only supported for back-wards compatibility.
12959 Cpu variants, the arm part is optional:
12960 -m[arm]1 Currently not supported.
12961 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
12962 -m[arm]3 Arm 3 processor
12963 -m[arm]6[xx], Arm 6 processors
12964 -m[arm]7[xx][t][[d]m] Arm 7 processors
12965 -m[arm]8[10] Arm 8 processors
12966 -m[arm]9[20][tdmi] Arm 9 processors
12967 -mstrongarm[110[0]] StrongARM processors
12968 -mxscale XScale processors
12969 -m[arm]v[2345[t[e]]] Arm architectures
12970 -mall All (except the ARM1)
12971 FP variants:
12972 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
12973 -mfpe-old (No float load/store multiples)
12974 -mvfpxd VFP Single precision
12975 -mvfp All VFP
12976 -mno-fpu Disable all floating point instructions
b99bd4ef 12977
c19d1205
ZW
12978 The following CPU names are recognized:
12979 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
12980 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
12981 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
12982 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
12983 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
12984 arm10t arm10e, arm1020t, arm1020e, arm10200e,
12985 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 12986
c19d1205 12987 */
b99bd4ef 12988
c19d1205 12989const char * md_shortopts = "m:k";
b99bd4ef 12990
c19d1205
ZW
12991#ifdef ARM_BI_ENDIAN
12992#define OPTION_EB (OPTION_MD_BASE + 0)
12993#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 12994#else
c19d1205
ZW
12995#if TARGET_BYTES_BIG_ENDIAN
12996#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 12997#else
c19d1205
ZW
12998#define OPTION_EL (OPTION_MD_BASE + 1)
12999#endif
b99bd4ef 13000#endif
b99bd4ef 13001
c19d1205 13002struct option md_longopts[] =
b99bd4ef 13003{
c19d1205
ZW
13004#ifdef OPTION_EB
13005 {"EB", no_argument, NULL, OPTION_EB},
13006#endif
13007#ifdef OPTION_EL
13008 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 13009#endif
c19d1205
ZW
13010 {NULL, no_argument, NULL, 0}
13011};
b99bd4ef 13012
c19d1205 13013size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 13014
c19d1205 13015struct arm_option_table
b99bd4ef 13016{
c19d1205
ZW
13017 char *option; /* Option name to match. */
13018 char *help; /* Help information. */
13019 int *var; /* Variable to change. */
13020 int value; /* What to change it to. */
13021 char *deprecated; /* If non-null, print this message. */
13022};
b99bd4ef 13023
c19d1205
ZW
13024struct arm_option_table arm_opts[] =
13025{
13026 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
13027 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
13028 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
13029 &support_interwork, 1, NULL},
13030 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
13031 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
13032 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
13033 1, NULL},
13034 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
13035 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
13036 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
13037 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
13038 NULL},
b99bd4ef 13039
c19d1205
ZW
13040 /* These are recognized by the assembler, but have no affect on code. */
13041 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
13042 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
13043 {NULL, NULL, NULL, 0, NULL}
13044};
13045
13046struct arm_legacy_option_table
13047{
13048 char *option; /* Option name to match. */
13049 const arm_feature_set **var; /* Variable to change. */
13050 const arm_feature_set value; /* What to change it to. */
13051 char *deprecated; /* If non-null, print this message. */
13052};
b99bd4ef 13053
e74cfd16
PB
13054const struct arm_legacy_option_table arm_legacy_opts[] =
13055{
c19d1205
ZW
13056 /* DON'T add any new processors to this list -- we want the whole list
13057 to go away... Add them to the processors table instead. */
e74cfd16
PB
13058 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
13059 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
13060 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
13061 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
13062 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
13063 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
13064 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
13065 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
13066 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
13067 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
13068 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
13069 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
13070 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
13071 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
13072 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
13073 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
13074 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
13075 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
13076 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
13077 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
13078 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
13079 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
13080 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
13081 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
13082 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
13083 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
13084 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
13085 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
13086 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
13087 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
13088 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
13089 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
13090 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
13091 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
13092 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
13093 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
13094 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
13095 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
13096 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
13097 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
13098 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
13099 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
13100 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
13101 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
13102 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
13103 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
13104 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13105 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13106 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13107 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
13108 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
13109 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
13110 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
13111 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
13112 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
13113 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
13114 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
13115 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
13116 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
13117 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
13118 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
13119 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
13120 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
13121 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
13122 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
13123 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
13124 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
13125 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
13126 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
13127 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 13128 N_("use -mcpu=strongarm110")},
e74cfd16 13129 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 13130 N_("use -mcpu=strongarm1100")},
e74cfd16 13131 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 13132 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
13133 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
13134 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
13135 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 13136
c19d1205 13137 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
13138 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
13139 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
13140 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
13141 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
13142 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
13143 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
13144 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
13145 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
13146 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
13147 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
13148 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
13149 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
13150 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
13151 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
13152 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
13153 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
13154 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
13155 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 13156
c19d1205 13157 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
13158 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
13159 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
13160 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
13161 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 13162 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 13163
e74cfd16 13164 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 13165};
7ed4c4c5 13166
c19d1205 13167struct arm_cpu_option_table
7ed4c4c5 13168{
c19d1205 13169 char *name;
e74cfd16 13170 const arm_feature_set value;
c19d1205
ZW
13171 /* For some CPUs we assume an FPU unless the user explicitly sets
13172 -mfpu=... */
e74cfd16 13173 const arm_feature_set default_fpu;
ee065d83
PB
13174 /* The canonical name of the CPU, or NULL to use NAME converted to upper
13175 case. */
13176 const char *canonical_name;
c19d1205 13177};
7ed4c4c5 13178
c19d1205
ZW
13179/* This list should, at a minimum, contain all the cpu names
13180 recognized by GCC. */
e74cfd16 13181static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 13182{
ee065d83
PB
13183 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
13184 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
13185 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
13186 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
13187 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
13188 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13189 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13190 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13191 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13192 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13193 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13194 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13195 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13196 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13197 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13198 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
13199 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13200 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13201 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13202 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13203 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13204 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13205 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13206 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13207 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13208 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13209 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13210 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
13211 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13212 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13213 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13214 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13215 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13216 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13217 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13218 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13219 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13220 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
13221 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13222 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
13223 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13224 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13225 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
13226 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
13227 /* For V5 or later processors we default to using VFP; but the user
13228 should really set the FPU type explicitly. */
ee065d83
PB
13229 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13230 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13231 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
13232 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
13233 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
13234 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13235 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
13236 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13237 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
13238 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
13239 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13240 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13241 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13242 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13243 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13244 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
13245 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
13246 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13247 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
13248 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
13249 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
13250 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
13251 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
13252 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
13253 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
13254 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
13255 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
13256 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
13257 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
13258 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
13259 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
62b3e311
PB
13260 {"cortex-a8", ARM_ARCH_V7A, FPU_ARCH_VFP_V2, NULL},
13261 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
13262 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
c19d1205 13263 /* ??? XSCALE is really an architecture. */
ee065d83 13264 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 13265 /* ??? iwmmxt is not a processor. */
ee065d83
PB
13266 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
13267 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 13268 /* Maverick */
e74cfd16
PB
13269 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
13270 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 13271};
7ed4c4c5 13272
c19d1205 13273struct arm_arch_option_table
7ed4c4c5 13274{
c19d1205 13275 char *name;
e74cfd16
PB
13276 const arm_feature_set value;
13277 const arm_feature_set default_fpu;
c19d1205 13278};
7ed4c4c5 13279
c19d1205
ZW
13280/* This list should, at a minimum, contain all the architecture names
13281 recognized by GCC. */
e74cfd16 13282static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
13283{
13284 {"all", ARM_ANY, FPU_ARCH_FPA},
13285 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
13286 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
13287 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
13288 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
13289 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
13290 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
13291 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
13292 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
13293 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
13294 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
13295 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
13296 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
13297 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
13298 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
13299 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
13300 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
13301 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
13302 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
13303 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
13304 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
13305 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
13306 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
13307 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
13308 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
13309 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
62b3e311
PB
13310 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
13311 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
13312 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
13313 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
13314 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
13315 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
e74cfd16 13316 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 13317};
7ed4c4c5 13318
c19d1205 13319/* ISA extensions in the co-processor space. */
e74cfd16 13320struct arm_option_cpu_value_table
c19d1205
ZW
13321{
13322 char *name;
e74cfd16 13323 const arm_feature_set value;
c19d1205 13324};
7ed4c4c5 13325
e74cfd16 13326static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 13327{
e74cfd16
PB
13328 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
13329 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
13330 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
13331 {NULL, ARM_ARCH_NONE}
c19d1205 13332};
7ed4c4c5 13333
c19d1205
ZW
13334/* This list should, at a minimum, contain all the fpu names
13335 recognized by GCC. */
e74cfd16 13336static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
13337{
13338 {"softfpa", FPU_NONE},
13339 {"fpe", FPU_ARCH_FPE},
13340 {"fpe2", FPU_ARCH_FPE},
13341 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
13342 {"fpa", FPU_ARCH_FPA},
13343 {"fpa10", FPU_ARCH_FPA},
13344 {"fpa11", FPU_ARCH_FPA},
13345 {"arm7500fe", FPU_ARCH_FPA},
13346 {"softvfp", FPU_ARCH_VFP},
13347 {"softvfp+vfp", FPU_ARCH_VFP_V2},
13348 {"vfp", FPU_ARCH_VFP_V2},
13349 {"vfp9", FPU_ARCH_VFP_V2},
13350 {"vfp10", FPU_ARCH_VFP_V2},
13351 {"vfp10-r0", FPU_ARCH_VFP_V1},
13352 {"vfpxd", FPU_ARCH_VFP_V1xD},
13353 {"arm1020t", FPU_ARCH_VFP_V1},
13354 {"arm1020e", FPU_ARCH_VFP_V2},
13355 {"arm1136jfs", FPU_ARCH_VFP_V2},
13356 {"arm1136jf-s", FPU_ARCH_VFP_V2},
13357 {"maverick", FPU_ARCH_MAVERICK},
e74cfd16
PB
13358 {NULL, ARM_ARCH_NONE}
13359};
13360
13361struct arm_option_value_table
13362{
13363 char *name;
13364 long value;
c19d1205 13365};
7ed4c4c5 13366
e74cfd16 13367static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
13368{
13369 {"hard", ARM_FLOAT_ABI_HARD},
13370 {"softfp", ARM_FLOAT_ABI_SOFTFP},
13371 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 13372 {NULL, 0}
c19d1205 13373};
7ed4c4c5 13374
c19d1205 13375#ifdef OBJ_ELF
3a4a14e9 13376/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 13377static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
13378{
13379 {"gnu", EF_ARM_EABI_UNKNOWN},
13380 {"4", EF_ARM_EABI_VER4},
3a4a14e9 13381 {"5", EF_ARM_EABI_VER5},
e74cfd16 13382 {NULL, 0}
c19d1205
ZW
13383};
13384#endif
7ed4c4c5 13385
c19d1205
ZW
13386struct arm_long_option_table
13387{
13388 char * option; /* Substring to match. */
13389 char * help; /* Help information. */
13390 int (* func) (char * subopt); /* Function to decode sub-option. */
13391 char * deprecated; /* If non-null, print this message. */
13392};
7ed4c4c5
NC
13393
13394static int
e74cfd16 13395arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 13396{
e74cfd16
PB
13397 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
13398
13399 /* Copy the feature set, so that we can modify it. */
13400 *ext_set = **opt_p;
13401 *opt_p = ext_set;
13402
c19d1205 13403 while (str != NULL && *str != 0)
7ed4c4c5 13404 {
e74cfd16 13405 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
13406 char * ext;
13407 int optlen;
7ed4c4c5 13408
c19d1205
ZW
13409 if (*str != '+')
13410 {
13411 as_bad (_("invalid architectural extension"));
13412 return 0;
13413 }
7ed4c4c5 13414
c19d1205
ZW
13415 str++;
13416 ext = strchr (str, '+');
7ed4c4c5 13417
c19d1205
ZW
13418 if (ext != NULL)
13419 optlen = ext - str;
13420 else
13421 optlen = strlen (str);
7ed4c4c5 13422
c19d1205
ZW
13423 if (optlen == 0)
13424 {
13425 as_bad (_("missing architectural extension"));
13426 return 0;
13427 }
7ed4c4c5 13428
c19d1205
ZW
13429 for (opt = arm_extensions; opt->name != NULL; opt++)
13430 if (strncmp (opt->name, str, optlen) == 0)
13431 {
e74cfd16 13432 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
13433 break;
13434 }
7ed4c4c5 13435
c19d1205
ZW
13436 if (opt->name == NULL)
13437 {
13438 as_bad (_("unknown architectural extnsion `%s'"), str);
13439 return 0;
13440 }
7ed4c4c5 13441
c19d1205
ZW
13442 str = ext;
13443 };
7ed4c4c5 13444
c19d1205
ZW
13445 return 1;
13446}
7ed4c4c5 13447
c19d1205
ZW
13448static int
13449arm_parse_cpu (char * str)
7ed4c4c5 13450{
e74cfd16 13451 const struct arm_cpu_option_table * opt;
c19d1205
ZW
13452 char * ext = strchr (str, '+');
13453 int optlen;
7ed4c4c5 13454
c19d1205
ZW
13455 if (ext != NULL)
13456 optlen = ext - str;
7ed4c4c5 13457 else
c19d1205 13458 optlen = strlen (str);
7ed4c4c5 13459
c19d1205 13460 if (optlen == 0)
7ed4c4c5 13461 {
c19d1205
ZW
13462 as_bad (_("missing cpu name `%s'"), str);
13463 return 0;
7ed4c4c5
NC
13464 }
13465
c19d1205
ZW
13466 for (opt = arm_cpus; opt->name != NULL; opt++)
13467 if (strncmp (opt->name, str, optlen) == 0)
13468 {
e74cfd16
PB
13469 mcpu_cpu_opt = &opt->value;
13470 mcpu_fpu_opt = &opt->default_fpu;
ee065d83
PB
13471 if (opt->canonical_name)
13472 strcpy(selected_cpu_name, opt->canonical_name);
13473 else
13474 {
13475 int i;
13476 for (i = 0; i < optlen; i++)
13477 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13478 selected_cpu_name[i] = 0;
13479 }
7ed4c4c5 13480
c19d1205
ZW
13481 if (ext != NULL)
13482 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 13483
c19d1205
ZW
13484 return 1;
13485 }
7ed4c4c5 13486
c19d1205
ZW
13487 as_bad (_("unknown cpu `%s'"), str);
13488 return 0;
7ed4c4c5
NC
13489}
13490
c19d1205
ZW
13491static int
13492arm_parse_arch (char * str)
7ed4c4c5 13493{
e74cfd16 13494 const struct arm_arch_option_table *opt;
c19d1205
ZW
13495 char *ext = strchr (str, '+');
13496 int optlen;
7ed4c4c5 13497
c19d1205
ZW
13498 if (ext != NULL)
13499 optlen = ext - str;
7ed4c4c5 13500 else
c19d1205 13501 optlen = strlen (str);
7ed4c4c5 13502
c19d1205 13503 if (optlen == 0)
7ed4c4c5 13504 {
c19d1205
ZW
13505 as_bad (_("missing architecture name `%s'"), str);
13506 return 0;
7ed4c4c5
NC
13507 }
13508
c19d1205
ZW
13509 for (opt = arm_archs; opt->name != NULL; opt++)
13510 if (streq (opt->name, str))
13511 {
e74cfd16
PB
13512 march_cpu_opt = &opt->value;
13513 march_fpu_opt = &opt->default_fpu;
ee065d83 13514 strcpy(selected_cpu_name, opt->name);
7ed4c4c5 13515
c19d1205
ZW
13516 if (ext != NULL)
13517 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 13518
c19d1205
ZW
13519 return 1;
13520 }
13521
13522 as_bad (_("unknown architecture `%s'\n"), str);
13523 return 0;
7ed4c4c5 13524}
eb043451 13525
c19d1205
ZW
13526static int
13527arm_parse_fpu (char * str)
13528{
e74cfd16 13529 const struct arm_option_cpu_value_table * opt;
b99bd4ef 13530
c19d1205
ZW
13531 for (opt = arm_fpus; opt->name != NULL; opt++)
13532 if (streq (opt->name, str))
13533 {
e74cfd16 13534 mfpu_opt = &opt->value;
c19d1205
ZW
13535 return 1;
13536 }
b99bd4ef 13537
c19d1205
ZW
13538 as_bad (_("unknown floating point format `%s'\n"), str);
13539 return 0;
13540}
13541
13542static int
13543arm_parse_float_abi (char * str)
b99bd4ef 13544{
e74cfd16 13545 const struct arm_option_value_table * opt;
b99bd4ef 13546
c19d1205
ZW
13547 for (opt = arm_float_abis; opt->name != NULL; opt++)
13548 if (streq (opt->name, str))
13549 {
13550 mfloat_abi_opt = opt->value;
13551 return 1;
13552 }
cc8a6dd0 13553
c19d1205
ZW
13554 as_bad (_("unknown floating point abi `%s'\n"), str);
13555 return 0;
13556}
b99bd4ef 13557
c19d1205
ZW
13558#ifdef OBJ_ELF
13559static int
13560arm_parse_eabi (char * str)
13561{
e74cfd16 13562 const struct arm_option_value_table *opt;
cc8a6dd0 13563
c19d1205
ZW
13564 for (opt = arm_eabis; opt->name != NULL; opt++)
13565 if (streq (opt->name, str))
13566 {
13567 meabi_flags = opt->value;
13568 return 1;
13569 }
13570 as_bad (_("unknown EABI `%s'\n"), str);
13571 return 0;
13572}
13573#endif
cc8a6dd0 13574
c19d1205
ZW
13575struct arm_long_option_table arm_long_opts[] =
13576{
13577 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
13578 arm_parse_cpu, NULL},
13579 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
13580 arm_parse_arch, NULL},
13581 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
13582 arm_parse_fpu, NULL},
13583 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
13584 arm_parse_float_abi, NULL},
13585#ifdef OBJ_ELF
13586 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
13587 arm_parse_eabi, NULL},
13588#endif
13589 {NULL, NULL, 0, NULL}
13590};
cc8a6dd0 13591
c19d1205
ZW
13592int
13593md_parse_option (int c, char * arg)
13594{
13595 struct arm_option_table *opt;
e74cfd16 13596 const struct arm_legacy_option_table *fopt;
c19d1205 13597 struct arm_long_option_table *lopt;
b99bd4ef 13598
c19d1205 13599 switch (c)
b99bd4ef 13600 {
c19d1205
ZW
13601#ifdef OPTION_EB
13602 case OPTION_EB:
13603 target_big_endian = 1;
13604 break;
13605#endif
cc8a6dd0 13606
c19d1205
ZW
13607#ifdef OPTION_EL
13608 case OPTION_EL:
13609 target_big_endian = 0;
13610 break;
13611#endif
b99bd4ef 13612
c19d1205
ZW
13613 case 'a':
13614 /* Listing option. Just ignore these, we don't support additional
13615 ones. */
13616 return 0;
b99bd4ef 13617
c19d1205
ZW
13618 default:
13619 for (opt = arm_opts; opt->option != NULL; opt++)
13620 {
13621 if (c == opt->option[0]
13622 && ((arg == NULL && opt->option[1] == 0)
13623 || streq (arg, opt->option + 1)))
13624 {
13625#if WARN_DEPRECATED
13626 /* If the option is deprecated, tell the user. */
13627 if (opt->deprecated != NULL)
13628 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13629 arg ? arg : "", _(opt->deprecated));
13630#endif
b99bd4ef 13631
c19d1205
ZW
13632 if (opt->var != NULL)
13633 *opt->var = opt->value;
cc8a6dd0 13634
c19d1205
ZW
13635 return 1;
13636 }
13637 }
b99bd4ef 13638
e74cfd16
PB
13639 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
13640 {
13641 if (c == fopt->option[0]
13642 && ((arg == NULL && fopt->option[1] == 0)
13643 || streq (arg, fopt->option + 1)))
13644 {
13645#if WARN_DEPRECATED
13646 /* If the option is deprecated, tell the user. */
13647 if (fopt->deprecated != NULL)
13648 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
13649 arg ? arg : "", _(fopt->deprecated));
13650#endif
13651
13652 if (fopt->var != NULL)
13653 *fopt->var = &fopt->value;
13654
13655 return 1;
13656 }
13657 }
13658
c19d1205
ZW
13659 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13660 {
13661 /* These options are expected to have an argument. */
13662 if (c == lopt->option[0]
13663 && arg != NULL
13664 && strncmp (arg, lopt->option + 1,
13665 strlen (lopt->option + 1)) == 0)
13666 {
13667#if WARN_DEPRECATED
13668 /* If the option is deprecated, tell the user. */
13669 if (lopt->deprecated != NULL)
13670 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
13671 _(lopt->deprecated));
13672#endif
b99bd4ef 13673
c19d1205
ZW
13674 /* Call the sup-option parser. */
13675 return lopt->func (arg + strlen (lopt->option) - 1);
13676 }
13677 }
a737bd4d 13678
c19d1205
ZW
13679 return 0;
13680 }
a394c00f 13681
c19d1205
ZW
13682 return 1;
13683}
a394c00f 13684
c19d1205
ZW
13685void
13686md_show_usage (FILE * fp)
a394c00f 13687{
c19d1205
ZW
13688 struct arm_option_table *opt;
13689 struct arm_long_option_table *lopt;
a394c00f 13690
c19d1205 13691 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 13692
c19d1205
ZW
13693 for (opt = arm_opts; opt->option != NULL; opt++)
13694 if (opt->help != NULL)
13695 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 13696
c19d1205
ZW
13697 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
13698 if (lopt->help != NULL)
13699 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 13700
c19d1205
ZW
13701#ifdef OPTION_EB
13702 fprintf (fp, _("\
13703 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
13704#endif
13705
c19d1205
ZW
13706#ifdef OPTION_EL
13707 fprintf (fp, _("\
13708 -EL assemble code for a little-endian cpu\n"));
a737bd4d 13709#endif
c19d1205 13710}
ee065d83
PB
13711
13712
13713#ifdef OBJ_ELF
62b3e311
PB
13714typedef struct
13715{
13716 int val;
13717 arm_feature_set flags;
13718} cpu_arch_ver_table;
13719
13720/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
13721 least features first. */
13722static const cpu_arch_ver_table cpu_arch_ver[] =
13723{
13724 {1, ARM_ARCH_V4},
13725 {2, ARM_ARCH_V4T},
13726 {3, ARM_ARCH_V5},
13727 {4, ARM_ARCH_V5TE},
13728 {5, ARM_ARCH_V5TEJ},
13729 {6, ARM_ARCH_V6},
13730 {7, ARM_ARCH_V6Z},
13731 {8, ARM_ARCH_V6K},
13732 {9, ARM_ARCH_V6T2},
13733 {10, ARM_ARCH_V7A},
13734 {10, ARM_ARCH_V7R},
13735 {10, ARM_ARCH_V7M},
13736 {0, ARM_ARCH_NONE}
13737};
13738
ee065d83
PB
13739/* Set the public EABI object attributes. */
13740static void
13741aeabi_set_public_attributes (void)
13742{
13743 int arch;
e74cfd16 13744 arm_feature_set flags;
62b3e311
PB
13745 arm_feature_set tmp;
13746 const cpu_arch_ver_table *p;
ee065d83
PB
13747
13748 /* Choose the architecture based on the capabilities of the requested cpu
13749 (if any) and/or the instructions actually used. */
e74cfd16
PB
13750 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
13751 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
13752 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
62b3e311
PB
13753
13754 tmp = flags;
13755 arch = 0;
13756 for (p = cpu_arch_ver; p->val; p++)
13757 {
13758 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
13759 {
13760 arch = p->val;
13761 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
13762 }
13763 }
ee065d83
PB
13764
13765 /* Tag_CPU_name. */
13766 if (selected_cpu_name[0])
13767 {
13768 char *p;
13769
13770 p = selected_cpu_name;
13771 if (strncmp(p, "armv", 4) == 0)
13772 {
13773 int i;
13774
13775 p += 4;
13776 for (i = 0; p[i]; i++)
13777 p[i] = TOUPPER (p[i]);
13778 }
13779 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
13780 }
13781 /* Tag_CPU_arch. */
13782 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
62b3e311
PB
13783 /* Tag_CPU_arch_profile. */
13784 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
13785 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
13786 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
13787 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
13788 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
13789 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
ee065d83 13790 /* Tag_ARM_ISA_use. */
e74cfd16 13791 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
ee065d83
PB
13792 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
13793 /* Tag_THUMB_ISA_use. */
e74cfd16 13794 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
ee065d83 13795 elf32_arm_add_eabi_attr_int (stdoutput, 9,
e74cfd16 13796 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 13797 /* Tag_VFP_arch. */
e74cfd16
PB
13798 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v2)
13799 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v2))
ee065d83 13800 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
e74cfd16
PB
13801 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_arch_vfp_v1)
13802 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_arch_vfp_v1))
ee065d83
PB
13803 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
13804 /* Tag_WMMX_arch. */
e74cfd16
PB
13805 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
13806 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
ee065d83
PB
13807 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
13808}
13809
13810/* Add the .ARM.attributes section. */
13811void
13812arm_md_end (void)
13813{
13814 segT s;
13815 char *p;
13816 addressT addr;
13817 offsetT size;
13818
13819 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
13820 return;
13821
13822 aeabi_set_public_attributes ();
13823 size = elf32_arm_eabi_attr_size (stdoutput);
13824 s = subseg_new (".ARM.attributes", 0);
13825 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
13826 addr = frag_now_fix ();
13827 p = frag_more (size);
13828 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
13829}
13830
13831
13832/* Parse a .cpu directive. */
13833
13834static void
13835s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
13836{
e74cfd16 13837 const struct arm_cpu_option_table *opt;
ee065d83
PB
13838 char *name;
13839 char saved_char;
13840
13841 name = input_line_pointer;
13842 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13843 input_line_pointer++;
13844 saved_char = *input_line_pointer;
13845 *input_line_pointer = 0;
13846
13847 /* Skip the first "all" entry. */
13848 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
13849 if (streq (opt->name, name))
13850 {
e74cfd16
PB
13851 mcpu_cpu_opt = &opt->value;
13852 selected_cpu = opt->value;
ee065d83
PB
13853 if (opt->canonical_name)
13854 strcpy(selected_cpu_name, opt->canonical_name);
13855 else
13856 {
13857 int i;
13858 for (i = 0; opt->name[i]; i++)
13859 selected_cpu_name[i] = TOUPPER (opt->name[i]);
13860 selected_cpu_name[i] = 0;
13861 }
e74cfd16 13862 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
13863 *input_line_pointer = saved_char;
13864 demand_empty_rest_of_line ();
13865 return;
13866 }
13867 as_bad (_("unknown cpu `%s'"), name);
13868 *input_line_pointer = saved_char;
13869 ignore_rest_of_line ();
13870}
13871
13872
13873/* Parse a .arch directive. */
13874
13875static void
13876s_arm_arch (int ignored ATTRIBUTE_UNUSED)
13877{
e74cfd16 13878 const struct arm_arch_option_table *opt;
ee065d83
PB
13879 char saved_char;
13880 char *name;
13881
13882 name = input_line_pointer;
13883 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13884 input_line_pointer++;
13885 saved_char = *input_line_pointer;
13886 *input_line_pointer = 0;
13887
13888 /* Skip the first "all" entry. */
13889 for (opt = arm_archs + 1; opt->name != NULL; opt++)
13890 if (streq (opt->name, name))
13891 {
e74cfd16
PB
13892 mcpu_cpu_opt = &opt->value;
13893 selected_cpu = opt->value;
ee065d83 13894 strcpy(selected_cpu_name, opt->name);
e74cfd16 13895 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
13896 *input_line_pointer = saved_char;
13897 demand_empty_rest_of_line ();
13898 return;
13899 }
13900
13901 as_bad (_("unknown architecture `%s'\n"), name);
13902 *input_line_pointer = saved_char;
13903 ignore_rest_of_line ();
13904}
13905
13906
13907/* Parse a .fpu directive. */
13908
13909static void
13910s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
13911{
e74cfd16 13912 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
13913 char saved_char;
13914 char *name;
13915
13916 name = input_line_pointer;
13917 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
13918 input_line_pointer++;
13919 saved_char = *input_line_pointer;
13920 *input_line_pointer = 0;
13921
13922 for (opt = arm_fpus; opt->name != NULL; opt++)
13923 if (streq (opt->name, name))
13924 {
e74cfd16
PB
13925 mfpu_opt = &opt->value;
13926 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
13927 *input_line_pointer = saved_char;
13928 demand_empty_rest_of_line ();
13929 return;
13930 }
13931
13932 as_bad (_("unknown floating point format `%s'\n"), name);
13933 *input_line_pointer = saved_char;
13934 ignore_rest_of_line ();
13935}
13936#endif /* OBJ_ELF */
13937